Is it possible to pass vector data via stdin? I can do simple assignments or even create a decently sized string, but it is unclear if it is possible to just create a block of memory which can then be read from to create something like an instantiation of a vector class.
Thanks,
Jim
Passing vector data
Re: Passing vector data
If you are using Python, then if you can get the data into a Python list or numpy 1-d array then you can use that as the arg to a hoc Vector constructor.
If you are using the HOC interpreter, then you can read stdin with
If you are using the HOC interpreter, then you can read stdin with
Code: Select all
objref vec
vec = new Vector(4)
for i=0, vec.size-1 {vec.x[i] = fscan()}
Re: Passing vector data
Is it possible to use stdin with a byte stream instead of a string representation of a number? I.e. I would like to be able to say, read the next eight bytes as a double.
Re: Passing vector data
If you are running linux, /dev/stdin, should do the trick. Possibly also mac and cygwin.
Perhaps a python function is more generic and someone could weigh in on that.
and launch with
nrniv test.hoc -
It should print the lines you type in stdin until you type a (control)d as end of file and then
continue accepting interpreter input until the second (ctrl)d.
Perhaps a python function is more generic and someone could weigh in on that.
Code: Select all
hines@hines-laptop:~/tmp$ cat test.hoc
objref f
f = new File()
f.ropen("/dev/stdin")
strdef s
while (f.gets(s) != -1) {
printf("line=|%s|\n", s)
}
printf("done\n")
nrniv test.hoc -
It should print the lines you type in stdin until you type a (control)d as end of file and then
continue accepting interpreter input until the second (ctrl)d.