next up previous 405
Next: UNIX-style options
Up: C-shell Cookbook
Previous: Defining NDF sections with variables


Loop a specified number of times

Suppose that you want to loop a specified number of times. For this you need a while statement, as in this example.

     set count = 1
     set tempin = myndf
     set box = 23
     while ($count < 5)
        @ box = $box - $count * 2
        block in=$tempin out=tempndf box=$box
        mv tempndf.sdf myndf_sm4.sdf
        set tempin = myndf_sm4
        @ count = $count + 1
     end
This performs four block smoothing operations, with a decreasing box size, on a NDF called myndf, the final result being stored in the NDF called myndf_sm4. The while statement tests a conditional statement and loops if it is true. So here it loops whenever the value of count is less than 5. Click here to see examples of other operators.

     % man csh
     /Expressions

The box size for the smoothing is evaluated in an expression @ box = $box - $count * 2. Note the space between the @ and the variable, and the spaces around the =. Thus the box sizes will be 21, 17, 11, 3. Further details are here. You should also give the variable a value with set before assigning it an expression. Another expression increments the counter count. The NDF called tempndf is overwritten for each smooth using the standard UNIX command mv.



next up previous 405
Next: UNIX-style options
Up: C-shell Cookbook
Previous: Defining NDF sections with variables

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