How to read numerical values from a file

A collection of noteworthy items selected by our moderators from discussions about making and using models with NEURON.

Moderators: wwlytton, tom_morse

Post Reply
ted
Site Admin
Posts: 5529
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

How to read numerical values from a file

Post by ted » Thu May 29, 2008 11:15 am

There are many ways to do this. You could use the File class's scanvar() method, or you
could combine the gets() method with the sscanf() function. Or, to get a sequence of values,
you could use the Vector class's scanf() or scantil() methods. These are all documented in
the Programmer's Reference.

A very convenient way to get a sequence of (x,y) data pairs into two Vectors is with the
standard run system's clipboard_retrieve(). This is not something that is built into hoc, so it
is not documented in the Programmer's Reference. So here's an example of usage,
which assumes that you have a plain text file called na_m.inf, in which each line contains a
pair of numerical values in the format
vvalue minfvalue

Code: Select all

objref minfvec, vvec
clipboard_retrieve("na_m.inf")
minfvec = hoc_obj_[0]
vvec = hoc_obj_[1]

Post Reply