Identifier arithm Purpose Shell for the call to the subroutines which perform spectrum arithmetics or functions on the fluxes/photocurrents in ISAP (LWS/SWS) structures. Invoked by the Widget User Interface or from the ISAP command line. Synopsis struc_out=arithm( algo, in1, [in2] [,band=band] [,det=det] [,/sloppy] [,/weight] [,/stat ) Arguments Name I/O Type Description ----------------------------------------------------- algo I string Operation to be performed in1 I AAR/SPD input structure (first argument) in2 I AAR/SPD/ scalar/ array input (second argument) band I scalar/ Detetctor band(s) to which operation intarr is limited (SWS specific) det I scalar/ Detector(s) to which operation is intarr limited SWS: 1...52 LWS: 0...9 !!!!!!! sloppy I keyword if set, suppress comparison of wavelengths in in1 and in2. Operation is done blindly item by item, ignoring possible fatal consequences weight I keyword if set, mean is weighted with 1./stdev^2 stat I/O int error status, 0 if ok, 1 if fatal Returns structure of kind in1 (see comment) 0 if a fatal error occurs (currently only in GUI mode) Description Does arithmetics on either two similar ISAP structures, or on a structure and a number (applicable to all detectors) or on a structure and an array (LWS: 10 elements, SWS: 52 elements according to the number of detectors in each case). Alternatively, applies a function to an IA structure. Checks if in1 is SWS SPD or LWS/SWS AAR/YAAAR. Checks in2 as well and in addition if scalar or array. If two structures are processed they are checked for same type, same number of data points, and identical reference scale (i.e wavelengths or grating positions). "Identical" means scale1 - scale2 .lt. epsilon with epsilon=1.E-5. Checks also flux and wavelength units (which are defined in the header) and issues a warning if they do not agree. /sloppy relaxes the wavelentgh match, but should be used with care only. If the switch /weight is set "mean" is performed with the inverse of the square of the standard deviations as weights. Weighting with constants (like "(3.*arr1 + 2.*arr2)/5.") can be performed step by step - calling sap_mult, sap_add, and sap_div. After the checks the desired routines (e.g. add) are called with the appropriate parameters. Finally the output structures are constructed. - possible values for algo: 'add', 'sub', 'mult', 'div', 'mean', 'exp', 'exp10', 'log', 'log10', 'sqrt', 'abs', 'min', 'max' . Case insensitve. - possible range for band: 1...6. Vectors (e.g. [1,2,4]) are allowed - possible range for det: 1...52(SWS) or 0...9 (LWS)!!. Vectors are allowed. In case of two input structures the bad data masks (bit 2^30 of flag - set with mask.pro) are simply combined. I.e. if one or both of the two structures contains bad points the opereation is performed normally but the result is flagged as 'bad'. (At the moment only implemented for AARs, not SPDs). Comment 1)The operations are performed automatically on fluxes or photocurrents with wavelengths as reference scale. For the processing of other tags than these arithm would need some additional information. 2)If in2 is an array and you do not specify det or band, data of unused detectors should be 0 for 'add' and 'sub' and 1 for 'mult' and 'div' E.g. in2_array=fltarr(52) in2_array(0:1)=10. out=arithm('add',in1,in2_array) if you specify det or band values in in2_array may be ignorred. E.g. in2_array=fltarr(52) in2_array(0:1)=10. out=arithm('add',in1,in2_array,det=[3,4]) This will do nothing to the data, because in2_array specifies detector 1 and 2 to be modified, but this is overwritten by det=[3,4]. For these two detectors the adding constant is given as 0. 3)Weighting is only meaningful for mean. Therefore SAP_ADD, SAP_SUB, SAP_MULT etc. do not provide for weighting. 4)For SWS SPDs the flux offsets of the several parts of a ramp are currently (first version) NOT taken into account. Hence, spectrum arithmetics in case of SWS SPDs can only be used after RESUM (an SWS IA routine). 5)Rules for the output structure: - if just a constant is added, subtracted etc. then the output structure is the same as the input structure. Only the array on which the operation was performed is replaced. - if two spectra are involved (coaddition, mean etc.) then the contents of the resulting structure are taken from the first spectrum (given through struc_in). The data arrays which were changed (e.g flux and stdev) are replaced. - The processing of the structures is indicated via update_history. 6)If in1 is of type YAAAR it MUST NOT contain other tags than .wave, .flux, .stdev and .flag. In particular this routine expects no .det tags in YAAAR, because the detector counting is different for SWS and LWS. The routine can't know by itself, which kind of counting is necessary. If you want to have an AAR with .det tag, the routine can be modified: if tpye eq 'YAAAR' then type eq 'SAAR'. YAAAR can then be treated like a normal SAAR. But than the user has to make sure that the detector counting is correct! 7)If errors get very small, they are round of to zero !! It may be better in this case to set the error to a minimum value (e.g. 1e-30) and print a warning Example 1) Add the constant 5. to all fluxes of band 4 in aar1: aar1 = arithm( 'add', aar1, stat, 5., band=4, stat=stat ) 2) Addition of two spectra: coadd = arithm( 'add', aar1, aar2, stat=stat) performs addition of the fluxes of arr1 and arr2 (the result is not renormalized. This is done by 'mean'). The wavelength scales of aar1 and aar2 have to be identical. The errors are propagated. 3) outspd = arithm( 'div', spd1, spd2, /sloppy ) divides the fluxes of two spectra. The spectra are NOT checked for identical reference scales. The error is propagated. 4) average = arithm( 'mean' , aar1, aar2, /weight ) computes weighted mean of two spectra (fluxes). The weights are taken from the uncertainties (stdev^2). The spectra are checked for identical reference scale. The errors are propagated. The tags "flux" and "stdev" of the output are given by the mean of flx1 and flx2 and the propagated errors. All other entries in the output structure ("average") are taken from aar1 (see comment). 5) subtract a zodiacal light model: aar2 = zodi_spec(aar1) aar2 = arithm( 'sub', aar1, aar2) Dependencies CALLS: chk_tag, chk_det, get_unit, is_struct, make52, make_detmask, sap_error, sap_keyword_set, update_history CALLED FROM: GUI, IA Category ISAP Filename arithm.pro Author E. Sturm (--> ES) A. Fiedler (--> AF) D. Lutz Version 1.1 History def of requirements E. Sturm / D. Lutz 26.7.95 0.1 14-09-95 ES based on ia_ari (D. Lutz) 0.2 27-09-95 AF modified detector counting and call to subroutines (call_procedure) 0.3 04-10-95 AF if in2 is an array and keywords det or band not pressend, all detectors are selected. Check if selected ones pressent. tests if algo should have 2 or 1 argument 0.4 10-10-95 ES added part for SPDs. Modified call to chk_det (not applicable for SPDs). Tests. ASAP integration 1.0 15-11-95 ES check bad data masks 1.1 29-01-96 ES new call to is_sruct 29-02-96 ES stat added ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Copyright (C) 1995, Max-Planck-Institut fuer extraterrestrische Physik (MPE); Garching, Germany ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;