return double array

The basics of how to develop, test, and use models.
Post Reply
oren
Posts: 55
Joined: Fri Mar 22, 2013 1:03 am

return double array

Post by oren »

Hello,
I can not mange to return a double array.
My code is :

Code: Select all

double CC[2]
double cc1[2]
    func go(){
    CC[0]=1
    CC[1]=2
    return(CC)
}

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.
ted
Site Admin
Posts: 5784
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: return double array

Post 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 }
foo(&bla)
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)
}
setvec(cvec)
cvec.printf()
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.
http://www.neuron.yale.edu/neuron/stati ... tml#syntax
http://www.neuron.yale.edu/neuron/stati ... rogramming
http://www.neuron.yale.edu/neuron/stati ... n/obj.html
Post Reply