function CSREADFITS, Filename, FITS=FITS, _EXTRA=E ;+ ; NAME: ; CSREADFITS ; ; PURPOSE: ; This function reads a CRISP FITS file or FITS structure, ; interprets/decodes all CRISP header keywords, applies any ; BSCALE and BZERO in the header, and undoes the CRISP bit ; embedding. ; ; CATEGORY: ; Comet Nucleus Tour CRISP IR Spectrometer calibration pipeline. ; ; CALLING SEQUENCE: ; ; fitsstruct = CSREADFITS(Filename) ; ; INPUTS: ; Filename: Name of FITS data file to read. ; ; KEYWORD PARAMETERS: ; FITS: FITS data structure as from csreadfits(), to ; bypass file read. Allows Brian's raw data ; processing pipeline to call this routine ; without writing files to disk. ; ; OUTPUTS: ; This function returns an anonymous structure containing FITS data: ; header 1D FITS header string array ; data 2D processed data array ; rawdat 2D original data array ; ; EXAMPLE: ; ; im = csreadfits('356_CSBML_WS2_02_0030.fit') ; header = im.header ; data = im.data ; rawdat = im.rawdat ; tvscl, data[*,*] ; ; MODIFICATION HISTORY: ; Written by: Joseph Harrington, Cornell. 2002 Apr 28 ; jh@oobleck.astro.cornell.edu ;- encodingkey = 'CRS20083' ; read the image, could be any of: ; raw FITS from the SDC ; an IDL raw FITS structure from the SDC pipeline ; a FITS file or structure in the form of the output of this pipeline if keyword_defined(fits) then begin ; from an anonymous FITS structure header = fits.header ; like out of the SDC pipeline rawdat = fits.data ; FINDME: check for the ; existence of a rawdat ; frame and use it if defined endif else begin ; ELSE from file rawdat = mrdfits(filename, 0, header, /silent) ; could use a unique ID endelse ; add our stuff to the header if it's not there yet, and decode data if sxpar(header, 'CSISCAL') eq 0 then begin ; T or F means we've done this header = cskeys(header, _extra=e) ; scale according to FITS encoding data = float(rawdat) * sxpar(header, 'BSCALE') + sxpar(header, 'BZERO') ; shift bits. Since the data are written to FITS *after* being ; embedded, they must first be deFITSed and then decoded. data = data * 2^sxpar(header, encodingkey) endif else begin ; if the data have been through once before, don't fix header = fits.header data = fits.data rawdat = fits.rawdat endelse return, {header:header, data:data, rawdat:rawdat} end