Command File Control and Branching

 

During command file execution, you may want the command file to take different processing steps based upon user input, or call other command files because the processing of the command file has met certain conditions. Methods to provide command file control and branching, include the special command file functions, @LOAD and @CALL, which can branch into 'child' command files from the main or 'parent' command file, as well as the conditional functions, IF and WHILE.

The @LOAD and @CALL functions allow you to load and execute another command file from within a command file which is executing. After the 'child' command file completes execution, control is returned to the 'parent' command file. The @CALL function is useful for creating loops in a command file.

 

The IF and WHILE functions can be used in a command file to provide branching to other command files based upon specific conditions. The IF and WHILE statements will not accept the special command file @CALL or @LOAD functions, but they will accept the CALL and LOAD functions (which are available from the command line in an interactive session). When you use the IF or WHILE function in conjunction with a CALL or LOAD statement to branch from a 'parent' command file into a 'child' command file, control is not returned to the 'parent' command file once the 'child' command file has completed execution.

 

Finally, you may decide to display a picklist type menu of choices which call a variety of command files. Simply use MENUFILE to display the picklist menu, and @SUSPEND until an @CR or an @OK is pressed.

 

The following command files demonstrate various methods of command file branching. The command file branch.dsp uses the MESSAGE function and the IF function to let the user decide whether they want to execute Option 1 or Option 2. If the user selects "Yes" in the message box, then the command file, opt1.dsp, is executed. If the user answers "No", then the command file continues, and the @CALL statement calls opt2.dsp. When opt2.dsp completes execution, control is returned to the parent command file, branch.dsp.

 

! Branch.dsp

!

REMOVEWIN(-1) @CR

ADDWIN(4) @CR

MOVETO(W1) @CR

MESSAGE("Choices for Analysis:","Choose either Option1 or Option2",3) @CR

IF(MESSAGE("What kind of Analysis","Do you want to select Option 1?",5), LOAD("opt1.dsp")) @CR

@CALL("opt2.dsp",1)

MOVETO(W1) @CR

@POP("p1",-1,-1,

" Notice that after opt2.dsp completed

execution, the 'parent' command file  

resumed execution. ") 

@PAUSE(5)

@UNPOP("p1")

MESSAGE("Complete","This completes the Branching Demo.",3) @CR

@RETURN

 

Here is the command file, opt1.dsp, which is called by branch.dsp:

 

! opt1.dsp

!

@POP("p1",-1,-1,

"

This is the command file for  

Option 1 of the analysis.  

")

@PAUSE(5)

@UNPOP("p1")

MOVETO(W1) @CR

GRAND(100,.01)*0.1 @CR

SETWF(W2,"GSIN(100,.01,3)") @CR

MOVETO(W3) @CR

W1 + W2 @CR

LABEL("Noisy Sine Wave") @CR

SETWF(W4,"SPECTRUM(W3)") @CR

@RETURN

 

Here is the command file, opt2.dsp, which is called by branch.dsp:

 

! opt2.dsp

!

@POP("p1",-1,-1,

"

This is the command file for  

 

Option 2 of the analysis.  

")

@PAUSE(5)

@UNPOP("p1")

MOVETO(W1) @CR

GSIN(100,.01) + (GSIN(100,.01,3)/3) @CR

SETWF(W2,"GSIN(100,.01,5)/5") @CR

MOVETO(W3) @CR

W1 + W2 @CR

LABEL("Summation of 3 Sine Waves") @CR

SETWF(W4,"SPECTRUM(W3);STICKS") @CR

@RETURN