Passing parameters to a hoc file

The basics of how to develop, test, and use models.
Post Reply
miller

Passing parameters to a hoc file

Post by miller » Thu Nov 10, 2005 7:36 am

Hi.

Can I pass a parameter to a hoc file when executing it from the shell? Something like

Code: Select all

sparc/special myFile.hoc num=3
? It doesn't have to be an l-value, read only constant would be enough!

Thanks

Raj
Posts: 219
Joined: Thu Jun 09, 2005 1:09 pm
Location: Hanze University of Applied Sciences
Contact:

Post by Raj » Sun Nov 13, 2005 3:21 pm

You might want to have a look at this post by Michael Hines:
https://www.neuron.yale.edu/phpBB2/viewtopic.php?t=46

miller

Post by miller » Tue Nov 22, 2005 5:03 am

But with here documents I only can execute statements after the code in the hoc file. What I need is to set a value of a variable that I would be able to use in the code in the hoc file, so the statement has to be executed before the hoc file!

Raj
Posts: 219
Joined: Thu Jun 09, 2005 1:09 pm
Location: Hanze University of Applied Sciences
Contact:

Passing Parameters

Post by Raj » Tue Nov 22, 2005 7:37 am

If you don't mind working in batch mode, that is do away with the GUI you can do the initialization without problems, using the here construction.

Simply put the code you want to execute in a function and then you can first set your extra variable (commandline options) and then call your hoc-code.

Unfortunateluy using neuron.exe in these script is misleading it seems to give you the GUI but you'll find that the functions executed in the context of the here redirection had no effect on the parameters, although the hoc-file is loaded (Intriguing behavior).

Anyway here an example, just save the hoc-code to a convenient place and adjust the here command to match your needs.

Code: Select all

// Working with here for parameters passing


// Create some sections
create soma
access soma


create dend[3]
objref myClamp
// Define a few defaults

myDiam=1.25
myL=20
myAmp=0.1
myDel=100
myDur=500
tstop=1000



proc build_cell(){
	printf("Building Cell: With myDiam=%g myL=%g myAmp=%g myDel=%g myDur=%g",myDiam,myL,myAmp,myDel,myDur)
	connect dend[0](0), soma(1)
	connect dend[1](0), dend[0](1)
	connect dend[2](0), dend[1](1)
	soma {
		insert hh
		diam=myDiam
		L=myL
	}
	
	forsec "dend" {
		insert hh
		diam=myDiam
		L=myL
	}
	soma myClamp=new IClamp(0.5)
	myClamp.amp=myAmp
	myClamp.del=myDel
	myClamp.dur=myDur
	
	
}

proc set_buildpars(){
	myDiam=$1
	myL=$2
	myAmp=$3
	myDel=$4
	myDur=$5
}

Now using the here construction from the commandline:

Code: Select all

$ /cygdrive/D/ProgramFiles/nrn58/bin/nrniv.exe here_ex.hoc - << here
> build_cell()
> set_buildpars(5,20,0.2,150,200)
>  build_cell()
> here
Building Cell: With myDiam=0 myL=0 myAmp=0 myDel=0 myDur=0
Building Cell: With myDiam=5 myL=20 myAmp=0.2 myDel=150 myDur=200
Notice: dend[0](0) had previously been connected to parent soma(1)
Notice: dend[1](0) had previously been connected to parent dend[0](1)
Notice: dend[2](0) had previously been connected to parent dend[1](1)
I used a function to set the extra parameters, but simply using something like myL=1030 instead would work also.

(The whole example was executed under Cygwin)

miller

Post by miller » Tue Nov 22, 2005 8:43 am

I'll do it the way you suggest.
Thanks!

Raj
Posts: 219
Joined: Thu Jun 09, 2005 1:09 pm
Location: Hanze University of Applied Sciences
Contact:

By the way

Post by Raj » Tue Nov 22, 2005 9:13 am

The here document is a bash shell property, you can find more info on this shell and here documents on this webpage:

http://www.tldp.org/LDP/abs/html/

ted
Site Admin
Posts: 5752
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

here document usage under MSWin

Post by ted » Tue Nov 22, 2005 11:21 am

Thanks, Raj, that was helpful information.

I was discussing the use of here documents with Michael Hines; he made the following
additional comments:

Under MSWin, the proper launch is

Code: Select all

/cygdrive/c/nrn58/bin/nrniv file.hoc << here
 . . . 
(although it might not be necessary to specify the complete path--try it and see).

If you want NEURON to exit automatically upon completion, make the first line of the hoc file
load_file("nrngui.hoc")
Otherwise you will need to include
quit()
as part of the here document.

Raj
Posts: 219
Joined: Thu Jun 09, 2005 1:09 pm
Location: Hanze University of Applied Sciences
Contact:

Re:here document usage under MSWin

Post by Raj » Tue Nov 22, 2005 1:02 pm

If you want NEURON to exit automatically upon completion, make the first line of the hoc file
load_file("nrngui.hoc")
Otherwise you will need to include
quit()
as part of the here document.
As far as I can see these steps are unnecessary. Under cygwin using nrniv.exe neuron exits automatically. If you use neuron.exe you get the neuron GUI but not the one belonging to the context/scope/process (haven't figured that out yet) in which you executed the here script.

To see this start neuron.exe with a here script and then ask for the values just set in the here script. You'll obtain the defaults and not those just set.

So starting up with the GUI (using neuron.exe) seems to have little if any added value.

A method to keep the GUI alive and in the right context would be nice. Although if you want the GUI and the NEURON commandline why would you want to pass parameters at startup?

hines
Site Admin
Posts: 1596
Joined: Wed May 18, 2005 3:32 pm

Post by hines » Sat May 05, 2007 11:17 am

"here" documents as stdin often work well but I admit things would be a lot simpler with a -c argument that executes the next arg as a hoc statement. And https://www.neuron.yale.edu/phpBB2/view ... hlight=mpi exhibited a case that was particularly arcane for use with a "here" script.

So for any version on or after VERSION 6.0.860 (1730) 2007-05-05 you can add any number of -c "statement" argument pairs to the command line interspersed with filename args and the hoc statements will be executed in that order. Note that if you also have -python, then there can be only one -c pair and that will be interpreted as a python statement.

Post Reply