Automating tasks: -c "statement" and batch runs

A collection of noteworthy items selected by our moderators from discussions about making and using models with NEURON.

Moderators: wwlytton, tom_morse

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

Automating tasks: -c "statement" and batch runs

Post by ted » Wed Aug 19, 2009 12:54 pm

One way to make NEURON execute a series of simulations is with a shell script that takes advantage of the command line to pass a statement to hoc. For example, consider this program

Code: Select all

// clodemo.hoc
// demonstrates use of the command line to pass a parameter to NEURON
num = -999
if (name_declared("x")==5) { // x has been assigned a numerical value
  num = x
}
print "num is ", num
quit()
Run it from the command line (MSWin users must do this in an rxvt shell--see notes at the end of this post before going any further!) and this is what you get:

Code: Select all

[ted@loki batchdemo]$ nrniv clodemo.hoc 
 . . . (banner omitted for clarity) . . .
num is -999
Now run it with the command line options
-nobanner -c "x=3"
and you get this:

Code: Select all

[ted@loki batchdemo]$ nrniv -nobanner -c "x=3" clodemo.hoc
num is 3
(-nobanner prevents printing of NEURON's startup banner)

The following shell script, which I will call clodemojob, runs clodemo.hoc three times, each time with a different value of num:

Code: Select all

#!/bin/sh
nrniv -nobanner -c "x=1" clodemo.hoc
nrniv -nobanner -c "x=PI" clodemo.hoc
nrniv -nobanner -c "x=exp(1.41)" clodemo.hoc
Here's the output generated by executing this script:

Code: Select all

[ted@loki batch]$ ./clodemojob
num is 1 
num is 3.1415927 
num is 4.0959554
Notes for MSWin users

Start an rxvt window by clicking on the rxvt item in the NEURON program group.

Use the following commands as needed to find out where you are and navigate to the directory that contains your shell script and hoc file:

Code: Select all

pwd  prints the path to the current directory.
     An rxvt window starts in /cygwin/c, which is the same location as c:\
     Hint: save keystrokes by using "tab completion" (see http://en.wikipedia.org/wiki/Command_line_completion)
ls   shows the contents of the current directory
cd   works just like MSWin's cd, but paths use the forward slash /, not the backward slash \
If typing ./clodemojob gives you an error message like
./clodemojob: /bin/sh: bad interpreter: No such file or directory
then you need to type
sh ./clodemojob
instead.

For more examples of how to use the rxvt shell, see
rxvt sh under MSWin
viewtopic.php?f=28&t=1391

Post Reply