next up previous 405
Next: Passing information between Starlink applications
Up: Executing a Starlink Application
Previous: Parameter files and the graphics database


How to test whether or not a Starlink task has failed

In a typical script involving Starlink software, you will invoke several applications. Should any of them fail, you normally do not want the script to continue, unless an error is sometimes expected and your shell script can take appropriate action. Either way you want a test that the application has succeeded.

If you set the ADAM_EXIT environment variable to 1 in your script before calling Starlink applications then the status variable after each task, will indicate whether or not the task has failed, where 1 means failure and 0 success.

     setenv ADAM_EXIT 1
         .    .    .
         .    .    .
         .    .    .
     stats allsky > /dev/null
     echo $status
     1
     stats $KAPPA_DIR/comwest > /dev/null
     echo $status
     0

The NDF allsky is absent from the current directory, so stats fails, reflected in the value of status, whereas $KAPPA_DIR/comwest does exist.

Here's an example in action.

     setenv ADAM_EXIT 1
         .    .    .
         .    .    .
         .    .    .
     normalize in1=$ndfgen in2=$ndfin out=! device=! > /dev/null
     if ( $status == 1 ) then
        echo "normalize failed comparing $ndf1 and $ndf2."
        goto tidy
     else
        set offset = `parget offset normalize`
        set scale = `parget slope normalize`
     endif
         .    .    .
         .    .    .
         .    .    .
     tidy:
     \rm ${ndfgen}.sdf

The script first switches on the ADAM_EXIT facility. A little later you create an NDF represented by $ndfgen and then compare it with the input NDF $ndfin using normalize. If the task fails, you issue an error message and move to a block of code, normally near the end of the script, where various cleaning operations occur. In this case it removes the generated NDF.

When normalize terminates successfully, the script accesses the output parameters for later processing with parget. This is explained in Passing information between Starlink applications.



next up previous 405
Next: Passing information between Starlink applications
Up: Executing a Starlink Application
Previous: Parameter files and the graphics database

C-shell Cookbook
Starlink Cookbook 4
Malcolm J. Currie
2006 November 26
E-mail:ussc@star.rl.ac.uk

Copyright © 2009 Science and Technology Facilities Council