Batch Mode

Gsharp scripts can be run from the command line in batch mode. Gsharp will start without creating an interface, will run the specified script and will then execute. Batch mode is useful for regular processing of standard scripts e.g. to produce a daily plot.

A full list of command line options including "-batch " can be found in the Reference Manual.

An Example

Gsharp -batch daily.gsl

The above command shows how to run the script daily.gsl in batch mode.

Producing Output

It would be pointless running a script in batch mode unless it did something like print the output or make an image file.

Both of these tasks can be achieved using the GSL command print. The output format and print command can also be specified e.g.

set hardcopy
 ( XuNdevice = 'hcposta4',
   XuNplotFileName = "bob.ps",
   XuNplotCommand = "lpr -laser bob.ps"
 );
print;

The routine make_image() can also be used to make an imagefile of a specific width and height. This routine is included in the library $UNIDIR/lib/libio.gsl and so should be used like this:

include "$UNIDIR/lib/libio.gsl";
...
make_image(400, 300, "bob.jpg");

Configuring the behaviour of a batch script

The behavior of the batch script can be modified in a number of ways.

Firstly the script could use environment variables. e.g.

if (getenv("USER")="bob") then
  exec("bobstemplate.gsl");
else
  exec("standardtemplate.gsl");
endif

Alternatively you could read some input variables from a file e.g.

  import_ascii(filename,,,,,,"InputStrings","text");
  if (InputStrings[1]="1")  reset;

Gsharp could also work through a list of files in a directory e.g.

for filename in filelist("*.dat")
  if (filename=undef)  continue;
  reset all;
  import_report(filename);
  MakePlot();
  remove(filename);
endfor

Gsharp could also check other command line parameters. Any command line options that Gsharp does not understand are ignored, but they are still stored in the dataset WORK.argv and can be evaluated by a script e.g. a start line like this:

Gsharp -batch daily.gsl -notitles -addclock -addreference

Could be used by GSL code like this:

if sum(WORK.argv="-addclock")  AddClock();
if sum(WORK.argv="-notitles")  addTitles = false;
if sum(WORK.argv="-addreference")  AddReference();

Functions like input_string work in batch mode. Execution will stop and the user must type in the requested value to the command line and press enter. You could even use this method to pass parameters to your script e.g.

Gsharp -batch daily.gsl < input.txt

Each line in input.txt will then then be passed to each input_string command in your script.