9 Passing information between Starlink applications

 9.1 Parsing text output
 9.2 Via Parameters

In scripts you will often want to take some result produced or calculated by one application, and to pass that information to another. Two techniques are available: piping or output parameters.

9.1 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 (SUN/95) 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.

9.2 Via Parameters

There is a more-robust technique for passing information between Starlink applications; it does not rely on the formatting of the output. Where an application writes output parameters (otherwise called results parameters), you may use the parget command of (SUN/95) to write to standard output the value or values associated with a parameter for a named application. In a script we want to assign the value to a shell variable. Let’s see how that compares with obtaining the same mean value as before.

       stats accept > /dev/null
       set average = ‘parget mean stats‘

This runs stats, but redirects the output to the null device as the output is not wanted. However, this does not prevent the output parameter called MEAN from being assigned the mean value. parget retrieves this value, which is then assigned to variable average. Note that parget retrieves parameter values for the last invocation of the task. Thus if you wanted the standard deviation too, you would only need to issue the stats command once (as shown below).

       stats \\ > /dev/null
       histpeak use=a sfact=0 device=! accept > /dev/null
       set mean = ‘parget mean stats‘
       set stdev = ‘parget sigma‘
       set kurtosis = ‘parget kurt histpeak‘

The kurtosis is obtained via the KURT output parameter of the histpeak command of ESP.