IRAF paso a paso: 3 - The CL command language
File and image templates
- File templates
can be used in IRAF; the syntax is equivalent to UNIX's. Example:
cl> imhead noche1*.fits
cl> imstat noche?_001.fits
"*" means: whatever string you find, irrespective of length; "?"
means: whatever character you find (but just one character).
- @files:
text files containing a list of images (called "at-files"). Many IRAF tasks
can operate on single images as well as on @files. They can be used both
in input and output. Ex.:
cl> files noche1*.fits> n1.txt
cl> imstat @n1.txt
Dumps list of files matching template noche1*.imh in n1.txt; use n1.txt
as input for imstat task.
Being plain text files, @files can be edited with any editor.
Be careful not to include other columns or extra characters in a @file,
as it can confuse IRAF and produce sometimes cryptic error messages.
- String replacement
is performed using the "%" character. Ex:
cl> imarith noche1*.fits
/ flat1.fits %noche1%ff_night1%*.fits
All images matching noche1*.fits are divided by flat1.fits; output
images are called ff_night1*.fits.
The more intuitive command:
cl> imarith noche1*.fits
/ flat1.fits ff_night1*.fits
will not work.
Alternatively, the "//" operator can be used to append a string. Ex:
cl> imarith noche1*.fits
/ flat1.fits ff_//noche1*.fits
IRAF usually stores commands you typed in a memory stack, and allow to
go back through it and use/edit previous command. Also, a permanent record
of commands can be kept.
| Command |
Description |
| history 40 |
Displays the last 40 commands |
| e |
Go back to previous command |
| ^ |
Go back and execute previous command |
| e imst |
Go back to previous command starting with "imst" |
| keeplog = yes |
All commands are stored in a file |
| logfile = "home$cllogfile.cl" |
Name of file where to keep cl commands |
Keeplog and logfile are cl parameters
(do: cl> lparam cl).
I never use this capability, as I prefer to write all commands I use (together
with relevant output and comments) in my own logfiles. Also, ecl
now allows to go through the history just using the up and down arrows.
Unix-like commands
- IRAF has a set of commands that perform the same things as the analogous UNIX
commands (ex: copy, delete, head, directory). Most of these commands
are grouped in the "system" package (type: help
system).
Some useful ones are:
| cd subdirectory |
goes to subdirectory |
| lprint file |
prints file |
| path |
shows current directory |
| rename |
renames file |
| page file |
displays file using page capabilities |
- To use directly UNIX commands, escape them with a "!". Ex:
cl> !rmdir oldfiles
remove directory "oldfiles" (there is no IRAF command to do that).
CL as a pocket calculator
Not all people know that IRAF provides a simple yes powerful calculator.
It may compute simple expressions, or use predefined variables
and built-in functions to do more complex operations.
- Examples of built-in functions are: sin, cos,
exp, log, sqrt,
max
etc. See help mathfcns.
- Computations are preceeded by a "=" sign, ex:
cl> =tan(1.5)/sin(20)*log10(11.5)
cl> =12:27:14 (convert sexigesimal to decimal
notation)
cl> x=12.5 ; y=log(x)*24.2/sqrt(3.0) ; print ("x=",x," y=",
y)
cl> x=3838198 ; y=0.22 ; z=x*(1-y)/12. ; print (z,"ptas per month")
(compute after-tax monthly salary of a post-doc, in pesetas, maaany years
ago).
An expanded set of capabilities, such as compute the julian day, work on
image keywords, etc. is provided by the task astcalc.
- The predefined variables of cl are:
b1, b2, b3: boolean
i, j, k: integer
x, y, z: real
s1, s2, s3: string
line: struct
list: list-directed struct
- New variables may be defined; their type must be declared, ex.:
cl> real w=1.5
cl> real madrid
cl> string filename="data.txt"
Something like cl> i1 = 0 won't work.
Do cl> lpar cl to see CL's own parameters and variables
Some useful tricks
- Sometimes, it's useful to have the output from a command read into a CL
variable. For instance, a header keyword contains the logarithm of
the starting wavelenght. To get the wavelenght in Angstroem, we might do:
cl> hedit spectrum.fits CRVAL1 . | scan(s1,s2,x)
; print(10**x)
scan is
a useful function that parses its input (typically from a pipe, as in the
above example) and fills in the variables with the corresponding values. Another
example:
cl> imstat dev$pìx
fields="npix,mean,stddev" format=no | scan(x,y,z)
cl> print ("npix=",x,"
mean=",y," standard deviation=",z)
- A task parameter can be changed from hidden to required or viceversa,
with the command:
cl> display.zs.p_mode = "a"
cl> display.frame.p_mode = "h"
- There is a way to debug script, using the "d_trace" toggle.
Type it once to enable debugging, type it again to switch debugging off.
- Converting numbers to/from decimal to sexagesimal value is quite simple.
In the first case, just type, for instance:
cl> =14:12:25
To do it the other way around, that is to print the decimal number with the appropriate
format:
cl> printf('%16h \n',123.567875) convert to degrees
cl> printf('%16H \n',123.567875) convert to hours