PRO ns_linear, data, lincoeff, cordata, DATAQUALITY=dataquality, LINQUALITY=linquality, HISTORY=history, CALNAME=calname ; ;+ ; NAME: ; ns_linear ; PURPOSE: ; Perform linearization correction on IR data ; CALLING SEQUENCE: ; ns_linear, data, lincoeff, cordata[, quality, HISTORY=history, ; CALNAME=calname] ; INPUTS: ; data -- data array to correct ; lincoeff -- array of correction coefficients ; quality -- optional array of data quality ; OPTIONAL KEYWORD PARAMETERS: ; dataquality -- data quality array ; linquality -- linearity correction quality array ; history -- output string array of reduction history ; calname -- disk file name of correction coefficients ; OUTPUTS: ; cordata -- corrected data ; COMMON BLOCKS: ; none ; NOTES: ; If lincoeff is a 2-D array, only the 1st-order correction is ; applied, i.e. DATA' = DATA(1+coeff*DATA). If lincoeff is a ; 3-D array, it must contain coefficients for _all_ orders, ; including 0. ; EXAMPLE: ; ; PROCEDURES CALLED: ; none ; MODIFICATION HISTORY: ; 1998/06/11 NAL/UCB created ;- msg = n_elements(msgwid) GE 1 szd = size(data) szl = size(lincoeff) same = (szd(0:2) EQ szm(0:2)) IF (same(1) AND same(2)) THEN BEGIN ;same size data and coeff array IF szl(0) EQ 2 THEN BEGIN ; only 1st-order corrections in coeff array lz = where(lincoeff EQ 0.0, nlz) IF nlz EQ szl(1)*szl(2) THEN BEGIN message, 'No non-zero coefficients. No correction done.', /con IF msg THEN widget_control, msgwid, $ set_value='No non-zero coefficients. No correction done.' cordata = data return ENDIF dcor = double(data)+double(lincoeff)*double(data) ENDIF ELSE BEGIN ; multi-order corrections in coeff array order = szl(0) dcor = dblarr(szd(1), szd(2)) linarr = double(lincoeff) FOR i=1, order DO $ dcor = temporary(dcor)+linarr(*, *, i-1)*data^i ENDELSE cordata = dcor IF keyword_set(dataquality) THEN BEGIN ; if quality array is defined IF keyword_set(linquality) THEN badlin = where(linquality GT 1, ibl) $ ELSE badlin = where(lincoeff(*, *, 0) LT 0, ibl) IF ibl GT 0 THEN dataquality(badlin) = dataquality(badlin)+16 ENDIF IF NOT keyword_set(calname) THEN calname = ' ' $ ELSE calname = 'with coefficient file ' + calname IF n_elements(history) GT 0 THEN $ history = [history, 'Linearization correction applied' + calname] $ ELSE history = 'Linearization correction applied' + calname ENDIF ELSE BEGIN errmsg = 'Linearization coefficient array not same size as data array. No correction done.' message, errmsg, /con IF msg THEN widget_control, msgwid, set_value=errmsg cordata = data ENDELSE return END