array variable in template

Anything that doesn't fit elsewhere.
Post Reply
neuromau
Posts: 97
Joined: Mon Apr 20, 2009 7:02 pm

array variable in template

Post 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?
ted
Site Admin
Posts: 5784
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: array variable in template

Post 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.
Post Reply