Page 1 of 1

How to read numerical values from a file

Posted: Thu May 29, 2008 11:15 am
by ted
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
minfvec = hoc_obj_[0]
vvec = hoc_obj_[1]