I'm trying to stimulate a nerve bundle, so I thought an easy way to do this is with a template. I made the template in a file called MRGaxon.hoc
the file looks the following way:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
begin template AxonTemplate
...
proc numberOfNodes(){
totalLength = nodelength + 2*paralength1 + 2*paralength2 + 6*interlength
print totalLength
numberOfNodes = nerveSpacingSource2 * (nodesCountSource2-1) / totalLength2
//topological parameters//
axonnodes = nodesCount //21
paranodes1= (nodesCount-1)*2 //40
paranodes2= (nodesCount-1)*2 //40
axoninter= (nodesCount-1)*6 //120
axontotal= axonnodes + paranodes1 + paranodes2 + axoninter *///221
}
...
proc init(){
...
numberOfNodes()
...
}
endtemplate AxonTemplate
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
nerveSpacingSource2 and nodesCountSource2 are external variables that are computed in another file. Somehow I'm not able to use them inside the template. I also tried to declare them as externals but it still didnt work. Can anyone please help me. Thx in advance
How to Import External Variables Into a Template
If you use the external keyword inside a template these variables should be available, if they are not there are several common errors:
- The template is defined and used before the variables are defined.
- The variables are not global but reside inside an object
- You made a typo: lowercase instead of uppercase, an l instead of an I
If this is the case the following simple test should fail: add a print statement to your init procedure to see whether the right values are communicated to the template.
Guessing from the names in your code snippet I find it likely that you are trying to create sections from a procedure. This is something that will not work, unless you created sections with the same names outside of the procedure first.
If I remember correctly
will give a usable procedure, whereas
will not work.
- The template is defined and used before the variables are defined.
- The variables are not global but reside inside an object
- You made a typo: lowercase instead of uppercase, an l instead of an I
If this is the case the following simple test should fail: add a print statement to your init procedure to see whether the right values are communicated to the template.
Guessing from the names in your code snippet I find it likely that you are trying to create sections from a procedure. This is something that will not work, unless you created sections with the same names outside of the procedure first.
If I remember correctly
Code: Select all
begintemplate
create dend[2]
...
proc create_many_sections(){
create dend[1000]
}
...
endtemplate
Code: Select all
begintemplate
...
proc create_many_sections(){
create dend[1000]
}
...
endtemplate
Thx very much for replying.
My code looks the following way:
I've done the print test twice. Once I inserted "print nerveSpacingSource" right above the line "proc numberOfNodes(){", in this case the correct value of nerveSpacingSource was displayed. In my second test I inserted "print nerveSpacingSource" right below "proc numberOfNodes(){", in this case the value was not printed.
It seems to me that nerveSpacingSource is known inside the template but not inside a procedure of a template.
To your second point: You are right that I'm creating sections from a procedure and I did it the way you told me to.
Then I have another question: Is there an easy way to round a floating variable to the floor? numberOfNodes should in my case be an integer.
Thx very much for your help again.
My code looks the following way:
Code: Select all
begintemplate AxonTemplate
external nerveSpacingSource, nodesCountSource
...
proc numberOfNodes(){
totalLength = nodelength + 2*paralength1 + 2*paralength2 + 6*interlength
print totalLength
numberOfNodes = nerveSpacingSource * (nodesCountSource-1) / totalLength
print numberOfNodes
/*nodesCount = numberOfNodes
//topological parameters//
axonnodes = nodesCount //21
paranodes1= (nodesCount-1)*2 //40
paranodes2= (nodesCount-1)*2 //40
axoninter= (nodesCount-1)*6 //120
axontotal= axonnodes + paranodes1 + paranodes2 + axoninter *//221
}
...
endtemplate AxonTemplate
It seems to me that nerveSpacingSource is known inside the template but not inside a procedure of a template.
To your second point: You are right that I'm creating sections from a procedure and I did it the way you told me to.
Then I have another question: Is there an easy way to round a floating variable to the floor? numberOfNodes should in my case be an integer.
Thx very much for your help again.
Templates have a special procedure for initialization of the variables in the template, this is the init procedure, that is where you should do the test on whether or not the global variables are imported.
All the code outside of procedures that do not define object references, strings or sections will probably only be executed when the hoc-file containing your template is loaded. But not when you instantiate a new template.
Here a working example:
Regarding your second question have a look at the int function.
All the code outside of procedures that do not define object references, strings or sections will probably only be executed when the hoc-file containing your template is loaded. But not when you instantiate a new template.
Here a working example:
Code: Select all
nerveSpacingSource=10
nodesCountSource=20
begintemplate AxonTemplate
external nerveSpacingSource, nodesCountSource
public numberOfNodes
objref this
proc init(){
//Defining all the local variables, here in the init function
paralength1=10
paralength2=20
nodelength=3
interlength = 1
totalLength=0
NoOfNodes=0 // Not numberOfNodes to avoid clash with function name
printf("%s, %d, %s\n", "nerveSpacingSource",nerveSpacingSource,this)
printf("%s, %d, %s\n", "nodesCountSource:", nodesCountSource,this)
}
proc numberOfNodes(){
totalLength = nodelength + 2*paralength1 + 2*paralength2 + 6*interlength
printf("totalLength:%d\n",totalLength)
NoOfNodes = int(nerveSpacingSource * (nodesCountSource-1) / totalLength)+1
// +1 to always have at least one node or
// 0 if uyou don't mind there being nonodes
printf("numberOfNodes: %d\n",NoOfNodes)
}
endtemplate AxonTemplate
objref myAxon
myAxon= new AxonTemplate()
myAxon.numberOfNodes()
Regarding your second question have a look at the int function.