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
*/
is vector length determined by input file?
-
- 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?
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.
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?
Ted, thank you.
-
- 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?
Glad to be of help.