I have a couple of questions about the following hoc code and a modified version of it:
objectvar f, randx
f = new File()
f.ropen("randnums/rsx0.dat")
irand = f.scanvar()
randx = f.scanvar()
The code above, extracted from a larger program based on demofig1.hoc from patdemo.zip, gives the following error when I run the simulation from mosinit.hoc within a nrnzip file:
bad stack access: expecting (Object **); really (double)
nrniv: interpreter stack type error
The modified version of it below, however, does not give this error:
objectvar f
f = new File()
f.ropen("randnums/rsx0.dat")
irand = f.scanvar()
irandx = f.scanvar()
So it looks like randx is automatically declared as a double, whereas irandx is not. Is this correct?
I haven't been able to find information in the documentation about the rules concerning variable names and data types. Is there some documentation where really basic things like this are covered?
Thanks for your help...
ja
variable names and data types
-
- Posts: 8
- Joined: Sun Jun 12, 2005 10:41 am
- Location: University of North Florida
-
- Site Admin
- Posts: 6305
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: variable names and data types
No. There are two differences between the code examples. In the first example randx is declared to be an objrefit looks like randx is automatically declared as a double, whereas irandx is not. Is this correct?
objectvar f, randx
then (mis)used in an assignment statement
randx = f.scanvar()
whose RHS returns a scalar instead of an objref. In the second example irandx is _not_ declared to be an objref, therefore is treated as a scalar when it first appears in the assignment statement
irandx = f.scanvar()
and no error results.
The basic types are scalars, arrays of scalars, and objrefs. A scalar can be redefined as an array of scalars, e.g.rules concerning variable names and data types
Code: Select all
oc>x = 3 // creates scalar x and assigns a value to it
first instance of x
oc>print x
3
oc>double x[2] // produces no error msg, but x now means x[0] and old value is discarded
oc>print x, x[0]
0 0
Chapters 12 and 13 of The NEURON Book go into much more detail about hoc syntax and object oriented programming in hoc, but much of this information is also in the Programmer's Reference. A good place to start is the hierarchical index of topics
http://www.neuron.yale.edu/neuron/stati ... /hier.html
especially the items in this part of the table:
Code: Select all
neuron.exe
general
ObjectOrientedProgramming functions syntax
button-menu-panel keywords
classes predeclared-variables
neuron
CompileTimeOptions functions keywords
Section globals mechanisms
classes ion pointprocesses