There are lots of ways to accomplish the same end result. Any solution must address
two problems:
1. it must overcome the fact (limitation) that a SectionList does not have an "index" that
would allow retrieval of a particular item
2. it also has to manage the selection and execution of the appropriate statement, in a
way that remains easy for the programmer to manage
First think about problem 1. One approach to dealing with this is to use an auxiliary
variable that keeps track of where you are in the SectionList. A crude example:
Code: Select all
ii = 0
forsec seclist {
if (ii < 10) {
statement1
}
if ((ii >= 10) && (ii < 20) {
statement2
}
ii+=1
}
So the auxiliary variable ii solves the problem of how to select sections in groups of 10,
but all those "if" statements make this code hard to manage. So now the focus shifts to
problem 2.
What is needed is a better way to select and execute the desired statement. It would be
much nicer if the statements were numbered 0, 1, . . . Then you could write
Code: Select all
ii = 0
forsec seclist {
dostmt( int(ii/10) ) // argument will be 0, 1, 2 . . .
ii += 1
}
where dostmt() is a procedure that uses its numeric argument to specify which
statement is executed
Code: Select all
proc dostmt() { // expects the argument to be 0, 1, 2 . . .
execute( a string specified by the argument )
}
Since NEURON's strdefs don't have indexes, this doesn't look like much help. But the
standard run library defines a String class that is just a strdef inside of a template, so
as long as you are using the standard run library (which you are, if your hoc code begins
with
load_file("nrngui.hoc")
or if you are starting NEURON from the command line by typing
nrngui yourprogramname.hoc
), you can define a collection of String objects, initialize their strdefs to contain the
command strings you want, and then access the strings via the indexed String objects.
A toy example of the basic idea:
Code: Select all
NUMCMDS = 3
objref command[NUMCMDS]
for ii = 0,NUMCMDS-1 command[ii] = new String()
command[0].s = "x = PI"
command[1].s = "x = sqrt(2)"
command[2].s = "x = exp(-1)"
proc docmd() {
execute(command[$1].s)
}
for ii=0,NUMCMDS-1 {
docmd(ii)
print "command ", ii, " makes x equal to ", x
}
So now you have all the pieces of the complete solution.