;+ ; NAME: ; spe_head ; ; PURPOSE: (one line) ; return an SPE FITS header given a filename, spe head structure, or FITS header ; ; DESCRIPTION: ; return an SPE FITS header given a filename, spe head structure, or FITS header ; ; CALLING SEQUENCE: ; head = spe_head(info, valid, speh, exptime=exptime, /justspe) ; ; INPUTS: ; info: a filename (SPE or FITS), spe head structure, or FITS header ; ; INPUT KEYWORDS : ; justspe : if set, just return the lines between FIRSTSPE and LASTSPE ; ; OUTPUTS: ; valid : set to 1 if info is valid (filename, spe structure, or ; FITS header), 0 otherwise ; speh : the spe structure ; Returns FITS header with the SPE information ; ; OUTPUT KEYWORDS : ; exptime : EXPTIME (if it exists in the header) of exp_sec ; ; EXAMPLES : ; ; MODIFICATION HISTORY: ; Written 14 Sep 2007 Leslie Ann Young SwRI ;- function spe_head, info, valid, spehead, justspe=justspe, exptime=exptime valid = 0b fitshead = '' exptime = 0. spehead = -1 ; array of strings - presumably a FITS header if size(info, /type) eq 7 and size(info,/n_dim) eq 1 then begin fitshead = info spehead = spe_fitshead2struct(fitshead) valid = 1b endif ; structure - presumably a princeton header if size(info, /type) eq 8 then begin spehead = info fitshead = spe_head2fits(spehead) valid = 1b endif ; one string, presumably a filename if size(info, /type) eq 7 and size(info,/n_dim) eq 0 then begin if isfile(info) then begin case (1) of ; FITS FILE strmatch(info, '*.fits', /fold) $ or strmatch(info, '*.fits.gz', /fold) $ or strmatch(info, '*.fits.Z', /fold) : begin fitshead = headfits(info) spehead = spe_fitshead2struct(fitshead) valid = 1b end ; SPE FILE strmatch(info, '*.spe', /fold) $ or strmatch(info, '*.spe.gz', /fold) : begin read_princeton_gz,info, /nodata, header = spehead fitshead = spe_head2fits(spehead) valid = 1b end endcase endif endif ; Get the exposure time if valid then begin exptime = float(sxpar(fitshead,'EXPTIME', count=count)) if count ne 1 then begin exptime = spehead.exp_sec endif endif ; extract the SPE keywords if keyword_set(justspe) and valid then begin first = where(strmid(fitshead,0,8) eq 'FIRSTSPE', nfirst) last = where(strmid(fitshead,0,8) eq 'LASTSPE ', nlast) if nfirst ne 1 or nlast ne 1 then begin valid = 0b endif else begin fitshead = fitshead[first[0] : last[0] ] endelse endif return, fitshead end