next up previous contents
Next: Command symbols Up: TERMINAL INPUT Previous: Parameter input and defaults   Contents


Script files

Script files are ordinary ASCII files from which command input can be taken. They are invoked by typing `@filename' in response to the >> prompt. Command files always have the extension `.SPX', and this should not be specified in the command line. Thus a command file called M17.SPX is invoked by typing `@M17'. Script files are created and modified using the VAX editor, either from outside SPECX or as invoked using a command line such as $EDIT M17.SPX. If you do it the latter way you will return to SPECX on exit from EDIT. The lines of a .SPX file look exactly like those you would type at the terminal, except that ^Z must be used where you would otherwise like CTRL(Z), and you can't use CTRL(C).

Consider first the simple command file TEST.SPX

    print 'TEST'
    read-spectrum 1 \?
which is invoked by typing @TEST in response to the >> prompt. After printing the identifying message (TEST) SPECX goes on to execute the READ-SPECTRUM command. In response to the ``File number?'' prompt it finds a value (1), and accepts this. However your response to the ``Scan number?'' prompt was a query (?). This is taken to mean ``Refer to the calling level for resolution''. As this command file is only a depth of 1 (i.e.called directly from the interactive top level), SPECX then prints the appropriate prompt, and accepts input directly. Thus by embedding a sequence of commands in a script file you can avoid having to respond to prompts for data which do not change.

Command files may be nested to a depth of 8, that is, it is permissable to include lines such as `@filename' in a script file. A `?' encountered in response to a prompt is referred to the calling file for resolution, and this process may be repeated. Suppose you had two command files TEST1.SPX and TEST2.SPX:

    print 'TEST1.SPX'
    @TEST2\1\?
    print 'end TEST1'

    print 'TEST2.SPX'
    !Command file requires two parameters - File number and scan number
    read-spectrum\?\?
    print 'end TEST2'

Then at the terminal you would have the following dialogue:

    >> @TEST1
    TEST1.SPX
    TEST2.SPX
    TEST2> Scan number? 27
    end TEST2
    end TEST1

The command interpreter encounters the first `?' in TEST2 and consults TEST1. It finds the value 1, which it accepts. On encountering the second `?' and consulting TEST1 it finds a further `?', so it moves up to the next level (the terminal), finds that it is the terminal, puts out a prompt and accepts the reply (27). Note that all input directed to a script file at a lower level must be included in the line that calls the file. Thus in the example above, it would not be correct to define TEST1.SPX as follows:

    print 'INCORRECT TEST1.SPX'
    @TEST2
    1
    ?
    print 'end TEST1'

The request for input in TEST2 will be redirected only to the calling line (@TEST2); once nothing is found there it will be assumed that input ``falls through'' to the next level (the terminal). In the example above an error will result when TEST2 is completed, and SPECX then tries to execute the command ``1''. Also note that the prompt is modified when it is the result of a command from within a command file: the prompt is prefixed by the name of the calling file, to indicate just who it is that you are talking to.


next up previous contents
Next: Command symbols Up: TERMINAL INPUT Previous: Parameter input and defaults   Contents
Jamie Leech 2004-08-16