This is a "good" example of abuse of the access keyword, even if the code works.
NEURON has a "section stack," and the currently accessed section is governed
by what is on the top of that stack. So far so good. The problem is that some actions
can have side-effects on the stack, the result being that the default section becomes
something other than what you think it should be. No error message is issued--you
just get very incorrect results, and can waste a lot of time grinding out incorrect
results and then trying to discover the source of the error (assuming you're lucky
enough to recognize the error before someone else does . . . ).
The best practice is:
1. Use access
only once in your entire program.
2. Use
sectionname statement
or
sectionname { statement(s) }
extensively. It is almost always the best way to specify the currenly accessed
section. Avoid errors like this
soma diam=1 L=10
(missing curly brackets), which sets soma.L, then pops the stack and sets diam
for whatever section remains at the top of the stack. Also, when using
sectionname { statement1 statement2 . . . statementN }
make sure that execution reaches the last statement, so that the section stack
will be popped. That is, don't
break,
continue, or
return inside
the curly brackets.
3. Statements that involve more than one section should use dot notation, e.g.
secname1.varname1 = secname2.varname2
Following these guidelines, and assuming that the solitary access statement
appears elsewhere in your program (probably associated with the dummy
section that will host your artificial spiking cell(s)--guessing that this is a
network model, and you have one or more of those to supply afferent drive?--
the code excerpt becomes
Code: Select all
for i=0, 0 {
cells[i]= new pc1()
cells[i].soma stim[i] = new IClamp(.5)
stim[i].del=200
stim[i].dur=500
stim[i].amp=0.8
cells[i].soma[0] distance()
for k=0, len-1{
cells[i].apic[k] dist.x[k]=distance(.5)
print dist.x[k]
for j=0, n-1{T[k].x[j]=j*deltat}
cvode.record(&cells[i].apic[k].v(.5),V[k],T[k],1)
}
}
i.e. minor changes indeed.