pro spe2fits self='SPE2FITS: ' fnlist = file_search('*.spe',count=nfiles) print,'Found ',strn(nfiles),' files to process.' ; Load the toc file if not exists('header.toc') then begin print,self,' Header information file could not be found.' return endif readcol,'header.toc',num,object,date,time,ra,dec,epoch,filter, $ format='i,a,a,a,a,a,f,a' ; Load the site information file if not exists('site.dat') then begin print,self,' Site information file could not be found.' return endif openr,lun,'site.dat',/get_lun obsname='' lats='' lons='' alt='' readf,lun,obsname,format='(a)' readf,lun,lats,format='(a)' lat = decparse(lats) decstr,lat,2,lats readf,lun,lons,format='(a)' lon = decparse(lons) decstr,lon,2,lons,/nolimit readf,lun,alt,format='(a)' alt = float(alt) free_lun,lun print,obsname,' ',lats,' ',lons,' ',alt for i=0,nfiles-1 do begin words=strsplit(fnlist[i],'.',/extract) words=strsplit(words[0],'_',/extract) if n_elements(words) ne 2 then begin print,self,fnlist[i],' file name is not in standard form. Skipping.' continue endif root = words[0] fno = fix(words[1]) outname = root+'.'+string(fno,format='(i3.3)') if exists(outname) then continue print,fnlist[i],'-->',outname ; need to provide the following keywords for the new FITS header ; DATE-OBS (YYYY-MM-DD) - from toc or spe header ; UT - from toc or spe header ; OBJECT - from toc ; RA - from toc ; DEC - from toc ; EPOCH - from toc ; FILTER - from toc ; EXPTIME - from spe header ; EXPDELTA - from spe header? ; FILENAME - internal ; AIRMASS - Calculated z=where(fno eq num,count) if count ne 1 then begin print,self,'No header information found for ',fnlist[i] continue endif z=z[0] jd = jdparse(date[z]+' '+time[z]) if ra[z] eq 'calculate' or dec[z] eq 'calculate' then begin ephem,jd,500,2,object[z],eph rastr,eph[0],1,rah decstr,eph[1],0,dech endif else begin rah = ra[z] dech = dec[z] endelse ; compute the airmass era = raparse(rah) edec = decparse(dech) am=airmass(jd,era,edec,lat,lon) am=am[0] ; Read the data file read_princeton,fnlist[i],data,header=header exptime = header.exp_sec expdelta = exptime + header.delaytime mkhdr,hdr,data sxaddpar,hdr,'DATE-OBS',date[z],before='DATE' sxaddpar,hdr,'UT',time[z],before='DATE' sxaddpar,hdr,'OBJECT',object[z],before='DATE' sxaddpar,hdr,'RA',rah,before='DATE' sxaddpar,hdr,'DEC',dech,before='DATE' sxaddpar,hdr,'EPOCH',epoch[z],before='DATE' sxaddpar,hdr,'FILTER',filter[z],before='DATE' sxaddpar,hdr,'EXPTIME',exptime,before='DATE' if size(data,/n_dimensions) eq 3 then $ sxaddpar,hdr,'EXPDELTA',exptime,before='DATE' sxaddpar,hdr,'FILENAME',outname,before='DATE' sxaddpar,hdr,'AIRMASS',am,before='DATE' sxaddpar,hdr,'OBSLAT',lats,before='DATE' sxaddpar,hdr,'OBSLON',lons,before='DATE',' West is positive' sxaddpar,hdr,'OBSALT',alt,before='DATE' writefits,outname,data,hdr endfor end