Come analyze HEASARC, IRSA, and MAST data in the cloud! The Fornax Initiative is now welcoming all interested beta users.
Script Files
XSPEC/tcl script files can be executed in three different ways, as follows:
xspec - <script>executing script on initialization
XSPEC>@ <script>executing script from within the program
XSPEC>source tclscriptuse tcl's source command from within the program.
Each of these usages does something slightly different. In the first form, XSPEC will execute a file called <script>. One may execute a series of script files at startup with the following command syntax:
unix> xspec - file1 file2 file3 ...Note that the space following the “-” is required.
The second form is @<name>, where <name> is the name of the script file to be executed. Here the default extension of .xcm is assumed. Scripts containing valid tcl or XSPEC commands will be executed using this form, and (unless the script ends in quit or exit) will return to the interactive prompt after completion.
The final form, using tcl's source command, is intended for the special case where the script contains the implementation of a new command written in tcl/tk. See the section on writing custom commands for more details. In current tcl versions it compiles the script into bytecode representation for more efficient execution, and adds any procedures defined in the script to the set of commands understood by the interpreter. It will not work for general scripts containing XSPEC/tcl commands, for example those produced by XSPEC's save command. These should rather be executed using the @ form.
Note that only in the second case (@) is there a default filename suffix (i.e. .xcm), for both the other methods of script execution the filename must be given in full.
tcl internally switches off the mechanism that expands command abbreviations when scripts are executed. If this were not done, the user could specify command abbreviations that change the behavior of the tcl command set (e.g. set for the setplot command would redefine tcl's command for setting variables). This behavior can be overridden with the statement
set tcl_interactive 1near the beginning of the script, but it is not recommended to do so. Instead, we strongly recommend spelling out command names in full within XSPEC scripts.
By default, when XSPEC is executing a script file, it echoes each command to the terminal before it is executed. This can be controlled using the tcl variable xs_echo_script, whose default value is 1. If this variable is set to 0, the commands from the script file will not be echoed to the terminal.
In summary, we suggest the following convention:
- Running an xspec script from the unix command prompt is intended to be used for background processing or overnight batch jobs. Using the unix at command, one can arrange to receive the log file by e-mail.
- The @ usage is intended for processing previously run xspec command sequences, such as are produced by the save command.
- The source usage, as well as executing the commands in the script, performs the equivalent of pre-compiling the script for later invocation. Its most appropriate use is in preparing new custom XSPEC command procedures. Once the script is working correctly, it can be placed in the user script directory and become part of the user's standard command set. For examples, see the scripts addline.tcl and modid.tcl in the directory $HEADAS/../spectral/scripts that implement the commands addline and modid. These also show how to make commands self-documenting.