Passing vector data

Anything that doesn't fit elsewhere.

Passing vector data

Postby JimH » Sat Jun 09, 2012 5:39 pm

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
JimH
 
Posts: 48
Joined: Tue Apr 10, 2007 3:36 pm
Location: University of Pittsburgh

Re: Passing vector data

Postby hines » Sun Jun 10, 2012 9:22 am

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

Re: Passing vector data

Postby JimH » Thu Jun 21, 2012 9:36 pm

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.
JimH
 
Posts: 48
Joined: Tue Apr 10, 2007 3:36 pm
Location: University of Pittsburgh

Re: Passing vector data

Postby hines » Tue Jun 26, 2012 11:45 am

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


Return to Other questions

Who is online

Users browsing this forum: No registered users and 1 guest

cron