Page 1 of 1

is vector length determined by input file?

Posted: Thu Feb 24, 2011 2:23 pm
by aolypher
In the code below I specify a new vector of length 3. However, when I initialize vector components from a file, the length of the vector becomes determined by the file length. If, for example, a file has 5 numbers (as below), the vector length becomes equal to 5. If a file has 2 numbers in it (not shown), the length becomes equal to 2. I wonder if it always works like this? In other words, is it a part of NEURON implementation that an input file determines the vector length?

Thanks,
Andrey

-----------------------------------------------
load_file("nrngui.hoc")
objref a, f
a = new Vector(3)
f = new File()
f.ropen("test_vector.dat")
a.scanf(f)
f.close()

print "a:"
a.printf()

/* test_vector.dat:
1
2
3
4
5
*/

/* Output:
NEURON -- Release 7.0 (281:80827e3cd201) 2009-01-16
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2008
See http://www.neuron.yale.edu/credits.html

1
1
5
0
a:
1 2 3 4 5

5

*/

Re: is vector length determined by input file?

Posted: Thu Feb 24, 2011 10:05 pm
by ted
The documentation of the Vector class's scanf method
http://www.neuron.yale.edu/neuron/stati ... html#scanf
contains this key statement:
"the vector is resized to the actual number of elements scanned"
vec.scanf(fileobj) will scan all elements in the file. Note the existence of alternative syntactical forms that allow you to specify the maximum number of elements that will be scanned, and, if the data are in multicolumn format, which column to scan.

Re: is vector length determined by input file?

Posted: Fri Feb 25, 2011 11:25 am
by aolypher
Ted, thank you.

Re: is vector length determined by input file?

Posted: Fri Feb 25, 2011 1:29 pm
by ted
Glad to be of help.