Page 1 of 1

array variable in template

Posted: Fri Aug 26, 2011 10:45 pm
by neuromau
I made a template that creates a soma as an array variable:

Code: Select all

begintemplate grr
	proc init() {	
		 load_file("mytest.hoc")
	}
endtemplate grr

objref mycell
mycell = new grr()

quit()
where mytest.hoc contains:

Code: Select all

create soma[5]
for i = 0, 4 soma[i] {
	print i
} 
print soma[0].L
This code works just fine, printing out:

Code: Select all

0 
1 
2 
3 
4 
100 
However, if I now move the contents of mytest.hoc into the main file to get the following:

Code: Select all

begintemplate grr
	proc init() {
		create soma[5]
		for i = 0, 4 soma[i] {
			print i
		} 
		print soma[0].L
	}
endtemplate grr

objref mycell
mycell = new grr()

quit()
I get an error:

Code: Select all

/home/casem/neuron/nrn/x86_64/bin/nrniv: soma not an array variable
 in testy.hoc near line 6
 		for i = 0, 4 soma[i] {
                        ^
How can I make the code work directly in the template file?

Re: array variable in template

Posted: Sat Aug 27, 2011 4:14 pm
by ted
The parser issues this message. A similar error message would have occurred if the parser had encountered an identical proc outside of a template. A nonscalar variable must first be declared outside of any proc or func before it can be used inside a proc or func. Just insert the line
create soma[1]
before the proc (i.e. still inside the template, but outside any proc or func).

If you're looking for a template pattern that may suggest ways to do useful stuff, just create a toy cell with the CellBuilder (give it a couple of dendrites at least), then use the Management page to export a hoc file that defines a cell class.