###################### tdf2iraf.cl ##################################### # #.LANGAGES CL - IRAF #.IDENTIFICATION tdf2iraf.cl #.AUTHORS Michael Drinkwater #.KEYWORDS fibres, spectroscopy #.ENVIRONMENT #.COMMENTS #.VERSION 2.0 2004 April 14 # #+++++++++++++++++++++ Explanation for the function +++++++++++++++++++++++ # #.PURPOSE Converts AAT/2dF 2dfdr output fits files to # IRAF format with a third dimension for error arrays # also puts object names and beams into image header # #.INPUTS # 1. SPEC.fibres -text file listing fibre identifications # unix> 2dfinfo SPEC.sdf fibres > SPEC.fibres # 2. SPEC.fits -reduced 2dF fits file (made with "") # unix> ndf2fits SPEC.sdf SPEC.fits # #.RETURNS # 1. SPECiraf.fits -reduced data(1) and errors(2) with details in header # #.ALGORITHM Straightforward, uses IRAF cl language. Macro. # #.REMARKS To use this script in IRAF you should copy this # file to your directory and then within IRAF type: # task tdf2iraf = PATH/tdf2iraf.cl # where PATH/ is the full directory path to the file. # #-------------------------------------------------------------------------- procedure tdf2iraf (infile) string infile {prompt="input image(s)"} string outfile = "iraf" {prompt="extra output name string"} bool clobber = no {prompt="clobber output files?"} bool verbose = yes {prompt="verbose output?"} struct *s_fibres struct *imglist begin bool images real r1,r2,r3,d1,d2,d3,m1,mag[404] int nred,nsel,iccd,iplt,ipiv,ispc,i,i2,nfile int ntarg,nsky,nfid,nbroke,pfib,nbeam,pivot[404] int f_plate,flag[404],f_ccd,isav,f_field,f_set int nsava,nsavo,tmp4 string img,imgfile,flg,name[404],data[404],tmp2 string f_infile,f_outfile,f_fibres,hname,hvalue struct line # get parameters f_infile = infile ################################################################### # Expand the image template into a text file list imgfile = mktemp ("tmp$dbs") sections (f_infile, option="fullname", > imgfile) # Open the list of images and scan through it imglist = imgfile while (fscan (imglist, img) != EOF) { # Get rid of the ".fits" extension; test if image exists i = strlen (img) if (substr (img, i-4, i) == ".fits") img = substr (img, 1, i-5) if (!(access (img // ".fits"))) { print("No file found, ignored: ",img) } else { ################################################################### # Read allocations file (ap, ID, P, no, RA, Dec, mag) f_fibres = img // ".fibres" if (verbose) print("Reading ",f_fibres) if (! access (f_fibres)) { print(f_fibres," file not found.") bye } s_fibres = f_fibres if (fscan(s_fibres,line) != EOF) { if (fscan(s_fibres,line) != EOF) { if (verbose) print("Read 2 comment lines") } else { print("*** Error reading comment lines") bye } } else { print("*** Error reading comment lines") bye } nred = 0 ntarg = 0 nsky = 0 nfid = 0 nbroke= 0 while (fscan(s_fibres,line) != EOF){ if (fscan(line,pfib,tmp2,flg,tmp4,r1,r2,r3,d1,d2,d3,m1)==11){ nred += 1 if(nred!=pfib){ print(" error in aperture number",nred,pfib) bye } name[pfib]=substr(tmp2,1,18) data[pfib]=substr(line,42,68) flag[pfib] = -9 mag[pfib] = m1 pivot[pfib] = tmp4 if (flg=="F") { flag[pfib] = -1 nfid += 1 } if (flg=="U" || flg=="N") { flag[pfib] = -1 nbroke += 1 } if (flg=="S") { flag[pfib] = 0 nsky += 1 } if (flg=="P" || flg=="2") { flag[pfib] = 1 ntarg += 1 } #if (verbose) print("n,a,f,ff",nred,pfib,flg,flag[pfib]) } else { #if (verbose) print(line) #print(" error reading line") #print(line) #print(nscan()) #bye } } print("Read assignments: n = ",nred) print("#fibres,skys,guides,broken= ",ntarg,nsky,nfid,nbroke) ################################################################### # Write output image f_outfile = img // "iraf.fits" if (access (f_outfile)) { if (clobber) { imdelete(f_outfile, ver-, >& "dev$null") } else { print("output file exists: ",f_outfile) bye }} if (verbose) print("Reading ",img," to ",f_outfile) imstack(img//"[0],"//img//"[1]",f_outfile) hedit(f_outfile,"WAT0_001","system=equispec",add+,ver-,update+) nfile = 0 nsava = 0 nsavo = 0 ntarg = 0 nsky = 0 nbroke= 0 for (i=1; i <= 200; i += 1) { nbeam = flag[i] nfile =nfile+1 hname="APID"//str(i) hvalue=name[i]//" "//str(mag[i]) hedit(f_outfile,hname,hvalue,add+,ver-,update+,show-) hname="APNUM"//str(i) hvalue=str(i)//" "//str(nbeam)//" 1 1024" hedit(f_outfile,hname,hvalue,add+,ver-,update+,show-) if (nbeam==-1) nbroke =nbroke+1 if (nbeam==0) nsky=nsky+1 if (nbeam==1) ntarg=ntarg+1 } print(" #fibres,skys,broken = ",ntarg,nsky,nbroke) print(" saved ",nfile," identifications") } } # Clean up delete (imgfile, ver-, >& "dev$null") end