Page 1 of 1

return double array

Posted: Wed May 29, 2013 7:17 am
by oren
I can not mange to return a double array.
My code is :

Code: Select all

double CC[2]
double cc1[2]
    func go(){

cc1 = go()
print cc1[0]
print cc1[1]
But all I get is that cc1[0] = 1 and cc1[1]=0

How can I pass all of the array with the return?

Thank You.

Re: return double array

Posted: Wed May 29, 2013 12:15 pm
by ted
In hoc a function returns a double precision value, not an array of double precision values. One can pass a double by reference, e.g.

Code: Select all

double bla[3]
for i=0,2 bla[i]=i
for i=0,2 print bla[i]
proc foo() { $&1[1]=PI }
for i=0,2 print bla[i]
but that's almost deprecated.

Much better is to use Vectors.

Code: Select all

objref cvec
cvec = new Vector(2)
proc setvec() { local i
  for i=0, $o1.size()-1 $o1.x[i] = sqrt(1+i)
It would be good to review the elements of hoc syntax, which are detailed in chapters 12 and 13 of The NEURON Book and documented at various places in the Programmer's Reference e.g. ... tml#syntax ... rogramming ... n/obj.html