next up previous 405
Next: Via Parameters
Up: Passing information between Starlink applications
Previous: Passing information between Starlink applications


Parsing text output

If the first task prints the required value, it is possible to use one or more of grep, sed, and awk to locate and isolate the value. For example, to obtain the mean value of a data array you could have the following lines in your script.

     set dummy = `stats accept | grep "Pixel mean"`
     set mean = $dummy[4]

The accept keyword tells stats to use the current values for any parameters for which it would otherwise prompt you. The back quotes (` ` are important. They tell the shell to execute the expression they enclose, in this case stats accept | grep "Pixel mean", and assign the result to variable dummy. So the KAPPA stats task is run on the current dataset, and the output is passed to grep which searches for the line containing the string Pixel mean, and the mean value. When you equate a variable to a multi-word string not enclosed in quotes--words being separated by spaces--the variable becomes an array, whose elements are each assigned to a word. So in this case the fourth word or element is the mean value.

Besides being inelegant, this method demands that the format and text of the output be fixed. So it should be avoided where the first task writes results to output parameters.


next up previous 405
Next: Via Parameters
Up: Passing information between Starlink applications
Previous: Passing information between Starlink applications

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