pro nis_c_write,seq_out,cal_mode,dark_mode,noise_mode, $ rad_mode ,filename,header, vid,append, sourcedir, $ verbose, satflag,flag2, flag3, polflag,solflag, $ dark1=dark1,dark2=dark2,dir=dir ; SUB-PROGRAM of nis_proc ; ; ABSTRACT ; Writes calibrated NIS spectra to specified name. Updates header to ; account for processing steps. ; INPUTS ; seq_out - sequence of acalibrated spectra from nis_proc processes ; ****_mode - see documentation in niscal or nis_proc ; filename - input file name. ???Should it contain the directory ; structure for saving??? ; header - header from input FITS file. to be modified and saved ; with calibrated data as its own FITS file. ; version_id - Nis_cal version number ; append - suffix to add to filename indicating level of calibration. ; xxx.rfd = uncalibrated spectra file with darks removed. ; Spectra divided by exposure time, (DN). ; xxx.dks = spectra with darks subtracted, (DN). ; xxx.cdn = Calibrated DN (corrected for xtalk, mirror position. ; Cal target obs. include the photometric correction. ; xxx.rad = Radiance. takes .cdn data and applies DN to ; radiance conversion ; xxx.iof = Converts radiance to I over F. ; vid - Version ID of niscal ; sourcedir - source directory for NISCAL programs and data ; verbose - Toggle description of events std output. ; dir - Toggle default directory. If not toggled, it is assumed ; that output file is to be saved in directory hosting the ; IDL process. ; dark1,2 - Filenames for the bracketing darks for dark_mode=3 ; OUTPUTS ; output file.xxx which is 259 columns long, one row for each spectrum in ; sequence. Per-detector noise for spectra make up the last 64 columns ; ; USES ; sxaddpar - changes header for spectra ; fxaddpar - changes header for spectra ; writefits - save dark data in dark library ; ; HISTORY ; Created 12/05/97 by N. R. Izenberg ; Modified 01/19/98 (NRI) v1.2 directory structure ; 01/22/98 (NRI) v1.3 fix comment/history ; 02/05/98 (NRI) v1.4 slit_mode, rad units, dark_mode 3 ; 07/16/98 (NRI) v2.0 CNFF compliant. Include flag statements ; 08/31/99 (NRI) v3.5 modify for Cal modes in header ; 05/04/00 (NRI) v4.1 add saturated data flag and DARK_MODE 5 info ; 05/22/01 (NRI) v5.0 CNISF 5.0, remove spicekill, slit_mode ; NOTES ; Pre-CNISF 5.0 sequence data is 44:107 ; CNISF 5.0 Data is 67:130 for Raw ; CNISF 5.0 Data is 131:194 for Calibration ; CNISF 5.0 Data is 195:258 for Noise ;------------------------------------------------------------------------------ ; Main ; Establish default output directory for saved file ;-------------------------------------------------- if dir eq 'test' then def_dir=sourcedir+'test/' else def_dir=dir if n_elements(satflag) eq 0 then satflag = 0 ; Establish needed parameters ;---------------------------- sz1=size(seq_out) ; Find Sequence size total_spec=sz1(2) ; Find total # spectra ; Create output array for save file. This file will have the original 109 ; columns of the initial FITS file, and an additional 64 columns for the ; error or noise values of each channel. Fill the output array with spectra ; and noise values ;------------------------------------------------------------------------ sz2=size(seq_out) ; Change the Header ;------------------ sxaddpar, header, 'AUTHOR', 'N. R. Izenberg' sxaddpar, header, 'NAXIS1', sz2(1) sxaddpar, header, 'NAXIS2', sz2(2) date1=sstrr(bin_date(systime(0))) date_now=date1(1)+'/'+date1(2)+'/'+strmid(date1(0),2,2) sl=strlen(filename) if strmid(filename,sl-3,3) eq '000' then fname=strmid(filename,0,sl-4) else $ fname=filename sxaddpar, header, 'NEAR-003', fname+append,'Name of this file'; Name of output sxaddpar, header, 'NEAR-004', date_now ; date of file sxaddpar, header, 'NEAR-006', 'nis_c_write.pro' ; creator program sxaddpar, header, 'NEAR-007', vid ; Version # ;Create Cal mode header values ;----------------------------- m1=strcompress(string(cal_mode),/remove_all) m2=strcompress(string(dark_mode),/remove_all) m3=strcompress(string(noise_mode),/remove_all) m4=strcompress(string(rad_mode),/remove_all) calmodes=m1+' '+m2+' '+m3+' '+m4+' 00' sxaddpar, header, 'NIS-025 ', calmodes fxaddpar, header, 'HISTORY', ' '+date_now+ $ ' This is a file of calibrated spectra' fxaddpar, header, 'HISTORY', ' '+date_now+' and associated per-channel noise' fxaddpar, header, 'HISTORY', ' '+date_now+' Created by nis_c_write.pro' fxaddpar, header, 'HISTORY', ' '+date_now+' Sub-process of nis_proc.pro' fxaddpar, header, 'HISTORY', ' '+date_now+' Sub-process of niscal.pro' fxaddpar, header, 'HISTORY', ' '+date_now+ $ ' Raw Spectra DN separated from dark spectra' case noise_mode of 0: fxaddpar, header, 'HISTORY', $ ' noise_mode 0: Noise gen from dark current per-channel stdevs' 1: fxaddpar, header, 'HISTORY',' noise_mode 1: Noise from library file' endcase if total(seq_out(51,*)) ne (-1)*sz2(2) then begin fxaddpar, header, 'HISTORY',' FLAG - NIS heater event influences some spectra' fxaddpar, header, 'HISTORY',' in this sequence' endif if satflag ne 0 then begin sflgtxt=strcompress(string(satflag),/remove_all) fxaddpar, header, 'HISTORY',' FLAG - Saturated/rollover data found.' fxaddpar, header, 'HISTORY',' '+ sstrr(satflag)+' obs. contain saturated channels' endif if append ne '.rfd' then begin fxaddpar, header, 'HISTORY', ' '+date_now+' Dark current DN subtracted' case dark_mode of 0: fxaddpar, header, 'HISTORY',' dark_mode 0: Linear interp from data' 1: begin fxaddpar, header, 'HISTORY',' dark_mode 1: Shutter closed Dark' fxaddpar, header, 'HISTORY',' Bracketting dark seqs' fxaddpar, header, 'HISTORY',' preceding dark = '+dark1 fxaddpar, header, 'HISTORY',' following dark = '+dark2 end 2: begin fxaddpar, header, 'HISTORY',' dark_mode 2: SPACE Dark' fxaddpar, header, 'HISTORY',' Bracketting dark seqs' fxaddpar, header, 'HISTORY',' preceding dark = '+dark1 fxaddpar, header, 'HISTORY',' following dark = '+dark2 end 3: begin fxaddpar, header, 'HISTORY',' dark_mode 3: No dark subtraction' fxaddpar, header, 'HISTORY',' Most likely darks previously' fxaddpar, header, 'HISTORY',' removed. Also no division.' fxaddpar, header, 'HISTORY',' Observations still coadded' end 4: begin fxaddpar, header, 'HISTORY',' dark_mode 4: Subtract dark from' fxaddpar, header, 'HISTORY',' Library file. File is' fxaddpar, header, 'HISTORY',' lib_tables/nis_default_dark.dat' fxaddpar, header, 'HISTORY',' Used mainly for reference only' end 5: begin fxaddpar, header, 'HISTORY',' dark_mode 5: Bounding Space Dark' fxaddpar, header, 'HISTORY',' Darks interpolated from space' fxaddpar, header, 'HISTORY',' to either side of asteroid' end 6: begin fxaddpar, header, 'HISTORY',' dark_mode 6: Bounding Space Dark' fxaddpar, header, 'HISTORY',' Darks interpolated from space' fxaddpar, header, 'HISTORY',' to either side of asteroid' fxaddpar, header, 'HISTORY',' Tight version (no data dropped)' end 7: begin fxaddpar, header, 'HISTORY',' dark_mode 7: Bounding Space Dark' fxaddpar, header, 'HISTORY',' Darks interpolated from space' fxaddpar, header, 'HISTORY',' to either side of asteroid' fxaddpar, header, 'HISTORY',' AND shutter-closed darks' end 8: begin fxaddpar, header, 'HISTORY',' dark_mode 8: Bounding Space Dark' fxaddpar, header, 'HISTORY',' Darks interpolated from space' fxaddpar, header, 'HISTORY',' to either side of asteroid' fxaddpar, header, 'HISTORY',' AND shutter-closed darks' fxaddpar, header, 'HISTORY',' Tight version (no data dropped)' end endcase endif else goto, skip if append ne '.dks' then begin fxaddpar, header, 'HISTORY', ' '+date_now+ $ ' DN calibrated from instrument corrections' sxaddpar,header, 'BUNIT', 'Calibrated DN' flag2tot=total(flag2) if flag2tot ne 0 then begin flgtxt=sstrr(flag2tot) fxaddpar, header, 'HISTORY',' FLAG - Commanded mirror position differed' fxaddpar, header, 'HISTORY',' from actual '+flgtxt+' times' endif endif else goto, skip if append ne '.cdn' then begin fxaddpar, header, 'HISTORY', ' '+date_now+ $ ' DN converted to radiance' fxaddpar,header, 'BUNIT', 'W/(m^2 sr um)' case rad_mode of 0: fxaddpar, header, 'HISTORY',' rad_mode 0: Cal Lab derived conversion' 1: fxaddpar, header, 'HISTORY',' rad_mode 1: Use defined conversion' endcase endif else goto, skip if append ne '.rad' then begin fxaddpar, header, 'HISTORY', ' '+date_now+ $ ' Radiance converted to I over F' sxaddpar,header, 'BUNIT', 'Radiance Factor (I/F)' fxaddpar, header, 'HISTORY', ' Systematic ch.-to-ch. noise removed' if flag3 ne 0 then begin fxaddpar, header, 'HISTORY', ' slit conversion may contain' fxaddpar, header, 'HISTORY', ' mirror pos. dependent error' endif if polflag ne 0 then begin fxaddpar, header, 'HISTORY',' FLAG - '+sstrr(polflag)+ 'spectra have mirror' fxaddpar, header, 'HISTORY',' pos. dependent polarization correction' endif if solflag ne 0 then begin fxaddpar, header, 'HISTORY',' FLAG - No spice data available for sequence.' fxaddpar, header, 'HISTORY',' Solar distance of 1 au assumed for I/F' endif endif else goto, skip skip: writefits,def_dir+fname+append, seq_out, header if verbose eq 1 then begin print,' >>>> Output file name:' print,' >>>> '+def_dir+fname+append print,' STEP 11: output file saved' endif end