IRAF CL Script Notes

The following are some notes on the syntax for IRAF scripts and some notes on imexpr.

1. Create a new 512x512 image with zeros in it:
imexpr "repl(0,512)" imagename dim=512,512

2. Create a mask file identifying all pixels greater than 800:
imexpr "a > 800." a=imagename

3. Create a new image from image1 and image2 depending on the value of the mask
imexpr "c ? a : b" newimage a=image1 b=image2

4. Example of a script to take the three pieces of a HIRES image and put them into
a single file separated by 10 pixels, oriented so red is up and to the right.
The 'else' command gave me a syntax error for some reason.

imdel k*.fits
for (i=1;i<70;i=i+1) {
 imdel junk.fits
 mkimage junk.fits make 1. 2 "3230 4096" pixtype="real"
 chpixtype junk.fits junk.fits ushort
 if(i<10) {
 if(i>9) {
 imcopy (s1//"[1][-*,*]", "junk.fits[1:1070,4096:1]")
 imcopy (s1//"[2][-*,*]", "junk.fits[1081:2150,4096:1]")
 imcopy (s1//"[3][-*,*]", "junk.fits[2161:3230,4096:1]")
 imtranspose ("junk.fits[*,-*]", s2)

A good IRAF script reference

Here's an example that operates on a list of images and does some looping, uses prompts and photometry output. The '*' files indicate a list-directed variable that works with fscan. The '*' files don't have {prompt=""} capabilities, but you can make them behave as such by asking for a string and setting the * variable to the string as below. Note // concatenates strings. You can grab variables from hidden parameters, as with the tstat.median command shown. It's not exactly R, but it works.

string flist {prompt="Input the name of the list of fits files: "} #prompt for the list of files
struct *nlist  #to scan the list it must be a '*' file. But you can't use prompt with a * file...
while (fscan (nlist, s1) != EOF) {   #s1 and s2 are predefined string variables
                                     #x, y, z are predefined reals, and i,j,k are predefined integers
                                     #list is a predefined struct

# find the stars
 daofind (s1//"["//a//"]",output="try1.coo",verify-,verbose-)

#extract a few of the bright ones
 pdump try1.coo XCENTER,YCENTER,MAG expr="MAG<-3.9 && MAG>-4.1 && XCENTER>25 && XCENTER<3950 && YCENTER>25 && YCENTER<1900" headers=yes > try2.coo

# radial profiles
  radius=15,step=1,datamin=0,datamax=50000)     #It's ok to break lines like this

#store the FWHM, get statistics and print the median
 pdump try2.mag PFWHM expr="yes" >
 tstat >& /tmp/null
 print (s1,"  ",0.27*tstat.median)