next up previous
Next: Modifying the Velocity and Frequency Axes
Up: Writing Your Own Command Files
Previous: Automatic Repetitive Operations

In-line do-loops

 A useful variant of command procedures is an in-line do loop; that is, a set of repetitive operations performed once only without making a command file. To make such a file one begins with a simple do loop statement. Then one is prompted to type in commands, ending with Control-d(EOF). For example, say I want to move a sequence of spectra from a map file and write then to an open file. I might do it this way:
>> do i 1 8
 Enter commands to do, line at a time, EOF to finish
 insert >> g-s-f-m i
 insert >> wr-sp 1
 insert >>  
 Filed as scan  31 of junk                    
 Filed as scan  32 of junk                       
 Filed as scan  33 of junk                       
 Filed as scan  34 of junk                       
 Filed as scan  35 of junk                       
 Filed as scan  36 of junk                       
 Filed as scan  37 of junk                       
 Filed as scan  38 of junk                       
 >>
Using the variable i as a simple counter, I read the series of spectra from the map and write then to file number 1. Because there are already spectra in this file, the scan numbers increment from the previous last number.

I mentioned that the in-line do loop is used only once. However, that's not necessarily true. Such a command file leaves a record of itself in a file called temp.spx. Naturally Unix overwrites this file every time a new version is created, so if you wanted to keep such a file you would have to rename it. The version of temp.spx created by the preceding simple do loop looks like:

 do i                   1   10    1
 g-s-f-m i
 wr-sp 1
 enddo
 return
 >>
This routine could be re-used by simply typing

>> @temp

In-line do-loops are really quite useful. It's up to your imagination what you use them for.



next up previous
Next: Modifying the Velocity and Frequency Axes
Up: Writing Your Own Command Files
Previous: Automatic Repetitive Operations

Specx Cookbook Reduction of millimetre wave data
Starlink Cookbook 8
Henry Matthews, Tim Jenness
1st March 1997
E-mail:ussc@star.rl.ac.uk

Copyright © 2005 Council for the Central Laboratory of the Research Councils