;+ ; Project : STEREO - SSC ; ; Name : SSC_AH_REDUCE ; ; Purpose : Create reduced attitude history file ; ; Category : STEREO, Orbit ; ; Explanation : This procedure takes a full resolution attitude history file, ; and creates a reduced resolution version, with "_sm" appended ; to the file name. Part of the MOC data products ingestion ; procedure. ; ; Two external programs are used to process the CK files. The ; first, cksmooth, applies a 5 minute boxcar smoothing function ; to the data. The intermediate result is then passed to CKSMRG ; to downsample the data. ; ; Syntax : SSC_AH_REDUCE, FILENAME ; ; Examples : ssc_ah_reduce, 'ahead_2006_304_01.ah.bc' ; ; Creates file ahead_2006_304_01_sm.ah.bc in the appropriate ; directory. ; ; Inputs : FILENAME = Name of the full resolution attitude history file. ; ; Opt. Inputs : None. ; ; Outputs : The procedure creates a reduced resolution file in the ; appropriate directory. ; ; Opt. Outputs: None. ; ; Keywords : NSMOOTH= A parameter related to the size of the boxcar average ; smoothing function. The box will run between ; I-NSMOOTH to I+NSMOOTH, so that the total size of the ; box is 2*NSMOOTH+1. The default is NSMOOTH=150, which ; for STEREO is equivalent to a box 5 minutes wide. ; ; NARCSEC= The pointing tolerance used by CKSMRG, in arcseconds. ; The default is 2 arcseconds ; ; ERRMSG = If defined and passed, then any error messages will be ; returned to the user in this parameter rather than ; depending on the MESSAGE routine in IDL. If no errors ; are encountered, then a null string is returned. In ; order to use this feature, ERRMSG must be defined ; first, e.g. ; ; ERRMSG = '' ; SSC_AH_REDUCE, ERRMSG=ERRMSG ; IF ERRMSG NE '' THEN ... ; ; Calls : CONCAT_DIR, GET_STEREO_SPICE_RANGE, BREAK_FILE, FILE_EXIST ; ; Common : None. ; ; Env. Vars. : CKSMOOTH = Path to cksmooth program ; CKSMRG = Path to cksmrg program ; STEREO_SPICE_GEN = Generic STEREO SPICE kernel tree ; STEREO_SPICE_SCLK = Spacecraft clock files ; STEREO_SPICE_ATTIT_SM_W = Output tree ; ; Restrictions: Must have write privilege to output directory ; ; Side effects: None. ; ; Prev. Hist. : None. ; ; History : Version 1, 05-Jul-2006, William Thompson, GSFC ; Version 2, 25-Jul-2006, William Thompson, GSFC ; Added call to cksmooth, keywords NSMOOTH, NARCSEC. ; ; Contact : WTHOMPSON ;- ; pro ssc_ah_reduce, filename, nsmooth=nsmooth, narcsec=k_narcsec, errmsg=errmsg on_error, 2 ; ; Check the input parameter. Make sure that the file actually exists. ; if n_params() eq 0 then begin message = 'Syntax: SSC_AH_REDUCE, FILENAME' goto, handle_error endif if n_elements(filename) ne 1 then begin message = 'FILENAME must be a scalar string' goto, handle_error endif if not file_exist(filename) then begin message = 'File ' + filename + ' does not exist' goto, handle_error endif ; ; Get the paths to the cksmooth and cksmrg programs. ; cksmooth = getenv('CKSMOOTH') if cksmooth eq '' then begin message = 'CKSMOOTH not defined' goto, handle_error endif cksmrg = getenv('CKSMRG') if cksmrg eq '' then begin message = 'CKSMRG not defined' goto, handle_error endif ; ; Form a list of the generic kernels which are needed. ; stereo_spice_gen = getenv('STEREO_SPICE_GEN') if !version.os_family eq 'Windows' then $ stereo_spice_gen = concat_dir(stereo_spice_gen, 'dos') files = file_search( concat_dir(stereo_spice_gen, 'naif*.tls'), count=count) if count eq 0 then begin message = 'Unable to find leap-seconds file' goto, handle_error endif kernels = max(files) ; stereo_spice_sclk = getenv('STEREO_SPICE_SCLK') ahead = concat_dir(stereo_spice_sclk, 'ahead') if !version.os_family eq 'Windows' then ahead = concat_dir(ahead, 'dos') files = file_search( concat_dir(ahead, 'ahead_science_*.sclk'), count=count) if count eq 0 then begin message = 'Unable to find spacecraft clock file' goto, handle_error endif kernels = kernels + ' ' + max(files) ; behind = concat_dir(stereo_spice_sclk, 'behind') if !version.os_family eq 'Windows' then behind = concat_dir(behind, 'dos') files = file_search( concat_dir(behind, 'behind_science_*.sclk'), count=count) if count eq 0 then begin message = 'Unable to find spacecraft clock file' goto, handle_error endif kernels = kernels + ' ' + max(files) ; ; Get the spacecraft ID, and translate it into a string name. ; get_stereo_spice_range, filename, date0, date1, scid case scid of -234000: sc = 'Ahead' -235000: sc = 'Behind' else: begin message = 'Unrecognized Spacecraft ID ' + ntrim(scid) goto, handle_error endelse endcase ; ; Get the path to write the file. Append the spacecraft name. ; path = getenv('STEREO_SPICE_ATTIT_SM_W') if path eq '' then begin message = 'STEREO_SPICE_ATTIT_SM_W not defined' goto, handle_error endif path = concat_dir(path, strlowcase(sc)) ; ; Form the names of the intermediate and output files. ; break_file, filename, disk, dir, name, ext intname = concat_dir(path, name + '_temp' + ext) outname = concat_dir(path, name + '_sm' + ext) ; ; If the intermediate file already exists, then delete it. ; if file_exist(intname) then file_delete, intname ; ; Form the CKSMOOTH command, and execute it. ; command = cksmooth + ' ' + filename + ' ' + intname if n_elements(nsmooth) eq 1 then command = command + ' ' + ntrim(nsmooth) print, command spawn, command ; ; If the output file already exists, then append ".save" to the end. ; if file_exist(outname) then begin tempname = outname + '.save' file_move, outname, tempname end else tempname = '' ; ; Form the CKSMRG command, and execute it. ; if n_elements(k_narcsec) eq 1 then narcsec = k_narcsec else narcsec = 2 command = cksmrg + ' -K ' + kernels + ' -I ' + intname + ' -O ' + outname + $ ' -S "STEREO ' + sc + ' spacecraft bus - reduced"' + $ ' -F "Downsampled attitude history" -B ' + ntrim(scid) + $ ' -R J2000 -A KEEP -T 5 minutes -D ' + ntrim(narcsec) + ' arcseconds' print, command spawn, command ; ; If a file was created, then delete the temporary file. Otherwise, move it ; back to where it was. Also delete the intermediate file. ; file_delete, intname if tempname ne '' then begin if file_exist(outname) then file_delete, tempname else $ file_move, tempname, outname endif ; ; Return to the calling routine. ; return ; ; Error handling point. ; handle_error: if n_elements(errmsg) eq 0 then message, message, /continue else $ errmsg = 'SSC_AH_REDUCE: ' + message ; end