To obtain the value of a variable, you prefix the variable's name with the dollar sign.
set count = 333
echo Number of runs is $count
would write Number of runs is 333 to standard
output.
set caption = "The most distant quasar observed is at redshift "
set z = 5.1
echo $caption$z
This will echo The most distant quasar observed is at redshift 5.1.
if ( $n > 10 ) then
mem2d niter=$n out=deconv
display style="'title=Result of deconvolution after $n iterations'" accept
endif
This tests whether the value of variable n is greater than ten, and
if it is, executes the statement within the if...endif
structure. The value is also passed into an integer parameter of the
application mem2d; and a string parameter of application
display, so if n were forty, the resultant value would
be "Result of deconvolution after 40 iterations".
Arithmetic, logical and string operations are presented in Arithmetic and String Processing.
The values of array elements are selected by appending the element index in brackets. This would echo to standard output the string Starting search at co-ordinates x=300, y=256.
set coords = (300 256)
echo "Starting search at co-ordinates x=$coords[1], y=$coords[2]."
The following illustrates use of a text array to specify the annotations of a plot created with application linplot.
set labels = ("Elapsed time" Flux "Light curve of 3C273")
linplot style="'title=$labels[3],Label(1)=$labels[1],Label(2)=$labels[2]'"
There are some shorthands for specifying subsets of an array. The best
way to describe them is through some examples.
All the values assume set prime = (2 3 5 7 11 13 17 19 23).
| Syntax | Meaning | Value |
| $#prime | Number of elements of variable prime | 9 |
| $prime[*] | All elements of variable prime | 2 3 5 7 11 13 17 19 23 |
| $prime[$] | The last element of variable prime | 23 |
| $prime[3-5] | The third to fifth elements of variable prime | 5 7 11 |
| $prime[8-] | The eighth to last elements of variable prime | 21 23 |
Here we bring some of these ingredients together. Suppose we are experimenting trying to find the most suitable reddish background (palnum=0) colour for image display using the palentry command from KAPPA. The script below loops using a while...end construct: all the commands inside the construct are repeated until the condition following the while is satisfied. That might seem a little odd here as we appear to repeat the same commands ad infinitum because the number of colours is fixed. That doesn't happen because of the C-shell shift command. It discards the first element of an array and reduces the indices of the remaining elements by one, so the original $colours[2] becomes $colours[1] and so on. This means that the chosen background colour is always $colours[1]. The shift also decrements the number of colours by one. So the script changes the background colour and pauses for five seconds for you to consider the aesthetics.
set colours = (red coral hotpink salmon brown sienna tan)
while ( $#colours > 0 )
echo "Trying $colours[1]"
palentry palnum=0 colour=$colours[1]
sleep 5
shift colours
end
C-shell Cookbook