Passing vector data

Anything that doesn't fit elsewhere.
Post Reply
JimH
Posts: 54
Joined: Tue Apr 10, 2007 3:36 pm
Location: Duke University

Passing vector data

Post by JimH »

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
hines
Site Admin
Posts: 1692
Joined: Wed May 18, 2005 3:32 pm

Re: Passing vector data

Post by hines »

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

Code: Select all

objref vec
vec = new Vector(4)
for i=0, vec.size-1 {vec.x[i] = fscan()}
JimH
Posts: 54
Joined: Tue Apr 10, 2007 3:36 pm
Location: Duke University

Re: Passing vector data

Post by JimH »

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.
hines
Site Admin
Posts: 1692
Joined: Wed May 18, 2005 3:32 pm

Re: Passing vector data

Post by hines »

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.

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")
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.
Post Reply