13 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

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. For a list of the available operators see Section 10.1 or the man pages.

       % man csh

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 in Section 10.1. 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.