Skip to main content

Come analyze HEASARC, IRSA, and MAST data in the cloud! The Fornax Initiative is now welcoming all interested beta users.

Xspec Home Page

Scripting commands that prompt the user

The commands model, editmod, addcomp, newpar, and fakeit may prompt the user for more information when used interactively. In order to write scripts that use these commands, one must know how to force XSPEC to enter the information that would be prompted for. The technique is exemplified as follows. Suppose we defined a procedure xmodel that makes a model with certain predefined parameter values:

set p1  {1.5 0.001 0 0 1.E05 1.E06}
set p2  {1 0.001 0 0 1.E05 1.E06}
proc xmodel {modelString param1 param2 args} {
  model $modelString & $param1 & param2 & /*
}
Here the & character is taken by XSPEC as a carriage return, delimiting the model string and parameter arguments into separate input lines.

The procedure xmodel may be compiled with the command

XSPEC> source xmodel.tcl
This creates xmodel as a command with two arguments which sets subsequent parameters to their default values. It can be invoked e.g. by
XSPEC>xmodel {wa(po + peg)} $p1 $p2
Note that the model string, which contains spaces, needs to be entered within {} or double quotes. Note also that tcl understands a single string argument, args, as in
proc  tclscript { args } {
...
}
to mean a variable number of arguments to a procedure (it is supplied as a tcl list, which can be split within the procedure into separate strings for digestion by xspec if present).