is vector length determined by input file?

Anything that doesn't fit elsewhere.
Post Reply
aolypher
Posts: 2
Joined: Tue Sep 15, 2009 2:18 pm

is vector length determined by input file?

Post 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

*/
ted
Site Admin
Posts: 6394
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: is vector length determined by input file?

Post 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.
aolypher
Posts: 2
Joined: Tue Sep 15, 2009 2:18 pm

Re: is vector length determined by input file?

Post by aolypher »

Ted, thank you.
ted
Site Admin
Posts: 6394
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: is vector length determined by input file?

Post by ted »

Glad to be of help.
Post Reply