pro nspecrect, infile, biasfile = biasfile, flatfile = flatfile, $ outlist = outlist ;+ ; given a file with a list of raw NIRSPEC images, ; bias subtract (optional), flat field (optional), ; CR zap, and rectify them using the rectification maps ; already generated by REDSPEC package. ; ; 'spec.map' and 'spat.map' are assumed to reside in the ; current directory. ; ; will write list of output images to 'outlist' file ; ; based on RECTIFY_ML.PRO, but fixed some bugs ; 1. didn't work right if no flat field passed ; 2. if flat field passed, wasn't using it!! ; ; Written by M. Liu (IfA/UH): 11/14/01 ;- if not(keyword_set(biasfile)) then biasfile = '' if not(keyword_set(flatfile)) then flatfile = '' if n_params() ne 1 then begin print, 'pro nspecrect, infile, [biasfile=], [flatfile=], [outlist=]' return endif ; read list of files readcol, infile, filelist, form = 'a' nn = n_elements(filelist) ; get bias frame if strlen(biasfile) ne 0 then begin bias = readfits(biasfile, /silent) if n_elements(bias) eq 1 then stop bflag = 1 endif else begin bias = bytarr(1024, 1024)+1B bflag = 0 endelse ; open output list if keyword_set(outlist) then begin openw, unit0, outlist, /get_lun printf, unit0, '# NSPECRECT.PRO: ', systime(), userid() endif ; get flat frame, normalize it if strlen(flatfile) ne 0 then begin flat = readfits(flatfile, /silent) if n_elements(flat) eq 1 then stop flat = flat/median(flat(600:800, *)) wflatgood = where(flat gt 0.1) wflatbad = where(flat le 0.1) fflag = 1 endif else begin flat = bytarr(1024, 1024)+1B fflag = 0 endelse ; loop over images for i = 0, nn-1 do begin ; get filenames file = filelist(i) fdecomp, file, disk, dir, name, qual outfile = name+'.' ; get image print, '--------------------------------------------------' print, 'processing "', file, '" ...' print, '--------------------------------------------------' im = readfits(file, head, /silent) sxaddhist, 'NSPECRECT.IDL: '+userid()+systime(), head ; subtract bias if (bflag) then begin im = im-bias message, 'subtracting bias frame "'+biasfile+'"', /info sxaddhist, ' subtracting bias frame "'+biasfile+'"', head outfile = outfile+'b' endif else $ sxaddhist, ' not subtracting bias frame', head ; flatten image if (fflag) then begin im(wflatgood) = im(wflatgood)/flat(wflatgood) im(wflatbad) = 0.0 message, 'flat-fielding with "'+flatfile+'"', /info sxaddhist, ' flattening with flat "'+flatfile+'"', head outfile = outfile+'f' endif else $ sxaddhist, ' no flat fielding', head ; if original image has been changed, write to temp file if (fflag) or (bflag) then begin file = mktemp() writefits, file, im, head endif ; rectify, fixing CRs first ; (faster to use /fixpix option b/c runs on the trimmed image) rectify_ml, file, outim, vert = 1, /fixpix, iter = 5 sxaddhist, ' cleaning bad pixels using FIXPIX_RS.PRO', head sxaddhist, ' rectifying image with RECTIFY.PRO', head outfile = outfile+'zr.fits' ; write output file if filecheck(outfile, /over) then begin writefits, outfile, outim, head if keyword_set(outlist) then $ printf, unit0, outfile endif ; clean up if (bflag) or (fflag) then spawn, '\rm '+file endfor if keyword_set(outlist) then $ free_lun, unit0 end