;; File Version: 7.0 ;; Last Modified: September 9, 2017 ;; By: JEC PRO HSP_CONCAT, hspdata, etvec, NOBIN = NOBIN, ip, lastfile, BIN = BIN, $ nfiles, DATAFILES = DATAFILES ;; Bin and concatenate HSP data from several sequential ;; files retrieved from DAPS. ;; Must have compiled hsp_reader.pro and hsp_binner.pro. ;; Joshua Colwell 29 September 2000 LASP ;; Version 2.0 JC 30 May 2001 ;; Update to work with Version 2.0 HSP_BINNER. ;; ;; Version 3.0 6 May 2003, JEC: ;; Update to work with new DAPS file naming convention. ;; Version 4.0 10 June 2003 JEC: ;; Computes etvec that corresponds to data vector to ;; be fed into geometer_wrapper routine to get pointing ;; information at the same time as the data values. ;; Version 4.1 30 July 2003 JEC: ;; Move bin input to a widget instead of command line. ;; Version 4.2 6 August 2003 JEC: ;; Add NOBIN keyword and optional parameter ip (output = integration ;; period in seconds). ;; Version 4.3 12 September 2003 JEC: ;; Add lastfile output parameter and BIN keyword. ;; Version 5.0 7 November 2003 JEC: ;; change to handle time vector from HSP_BINNER is ET rather than ;; fractional days. Don't load any kernels: assume already loaded. ;; Fix weird file ordering done by dialog_pickfile so files are loaded ;; in the correct order. Eliminate timevec output. Just output ET time. ;; Version 5.1 4 January 2004 JEC: ;; allow for only a single file to be selected. ;; October 13, 2004: use dialog_pickfile file ordering. version 6.1 of ;; IDL at least does not seem to be doing the re-ordering that I saw ;; earlier. ;; February 2, 2005: add filter to dialog_pickfile. ;; October 10, 2005: work with the new hsp_binner to use the auxiliary ;; time file for a higher accuracy time output vector. ;; September 24, 2006: force ip to be double precision. ;; January 1, 2009: allow selection of dummy auxiliary time file. ;; January 16, 2009: Make dummy aux_time variable a structure to fix ;; bug. ;; February 6, 2010: Allow file list to be passed in. Automatically ;; find the auxilliary time file. ;; July 12, 2010: Fix bug when getting last auxilliary time file in list. ;; September 5, 2012: Fix bug when manually selecting an aux time file. ;; June 6, 2014: Change test on auxilliary time file from "GT" to "GE". ;; June 26, 2017: Fix searching of auxilliary time file to work with two-digit and ;; three-digit sequence numbers. ;; September 9, 2017: another fix to handle sorting of S100 and S101 timing files. IF NOT KEYWORD_SET(datafiles) THEN $ files = DIALOG_PICKFILE(TITLE ='Select all the HSP data files in the series.',$ /MULTIPLE_FILES, PATH = '/users/colwell/documents/cassini/uvis/data/RingStellarOccsHSP/',$ FILTER = 'HSP*') ELSE files = datafiles nfiles = N_ELEMENTS(files) file1 = files[0] ;; The time_temp_file contains the template for reading the auxilliary ;; time file. The template is called time_template and is to be used with ;; READ_ASCII. ;time_temp_file = FILE_SEARCH('$HOME', 'hsp_time_template.sav', /FULLY_QUALIFY) time_temp_file = $ '/users/colwell/documents/cassini/uvis/Tools/hsp_time_template.sav' RESTORE, time_temp_file ;; Read the auxilliary time file to pass it to hsp_binner. ;; Use the first data file to identify the auxilliary time file to ;; load. lastslashpos = STRPOS(files[0], '/', /REVERSE_SEARCH) firstdatafile = STRMID(files[0], lastslashpos+1, STRLEN(files[0])-$ lastslashpos-1) year = FLOAT(STRMID(firstdatafile, 3, 4)) day = FLOAT(STRMID(firstdatafile, 8, 3)) hour = FLOAT(STRMID(firstdatafile, 12, 2)) IF year EQ 2004 OR year EQ 2008 OR year EQ 2012 OR year EQ 2016 THEN $ ndays = 366. ELSE ndays = 365. tdat = year+day/ndays+hour/24D0/ndays auxfiles = FILE_SEARCH('/users/colwell/documents/cassini/uvis/data/HSP Timing Files/science*.hsp_timing.txt', COUNT = nauxfiles) auxtimes = DBLARR(N_ELEMENTS(auxfiles)) findex = -1 foundaux = 0 REPEAT BEGIN findex++ lastslashpos = STRPOS(auxfiles[findex], '/', /REVERSE_SEARCH) firstdashpos = STRPOS(auxfiles[findex], '-') seconddashpos = STRPOS(STRMID(auxfiles[findex], firstdashpos+1, 6),'-') datepos = firstdashpos+1+seconddashpos auxyear = FLOAT(STRMID(auxfiles[findex], datepos+1, 4)) auxday = FLOAT(STRMID(auxfiles[findex], datepos+5, 3)) auxhour = FLOAT(STRMID(auxfiles[findex], datepos+8, 2)) IF auxyear EQ 2004 OR auxyear EQ 2008 OR auxyear EQ 2012 OR $ auxyear EQ 2016 THEN ndays = 366. ELSE ndays = 365. auxt1 = auxyear+auxday/ndays+auxhour/24./ndays auxtimes[findex] = auxt1 ENDREP UNTIL findex EQ nauxfiles-1 timeorder = SORT(auxtimes) findex = -1 REPEAT BEGIN findex++ IF tdat GE auxtimes[timeorder[findex]] AND $ tdat LT auxtimes[timeorder[findex+1]] THEN foundaux = 1 ENDREP UNTIL findex EQ nauxfiles-1 OR foundaux IF findex EQ nauxfiles-2 AND NOT foundaux THEN BEGIN PRINT, 'Could not find aux file.' aux_time_file = DIALOG_PICKFILE(TITLE = 'Select auxilliary time file', $ PATH = '/users/colwell/documents/cassini/uvis/data', $ FILTER = '*.hsp_timing.txt') ENDIF ELSE aux_time_file = auxfiles[timeorder[findex]] ;PRINT,'Verify auxilliary time file. Use .c to continue.' ;STOP,'Auxilliary time file: ',aux_time_file IF STRMID(aux_time_file,STRLEN(aux_time_file)-28,28) NE $ 'DummyTimeFile.hsp_timing.txt' THEN $ aux_time = READ_ASCII(aux_time_file, TEMPLATE = time_template) ELSE $ aux_time = {ticks:[-1000.]} IF NOT KEYWORD_SET(NOBIN) THEN BEGIN IF NOT KEYWORD_SET(BIN) THEN BEGIN base = WIDGET_BASE(/ROW, /ALIGN_CENTER) label = WIDGET_LABEL(base, VALUE = 'Enter bin size (in seconds): ') text = WIDGET_TEXT(base, /EDITABLE) WIDGET_CONTROL, base, /REALIZE gotbinsize = 0 WHILE NOT gotbinsize DO BEGIN event = WIDGET_EVENT(base, BAD_ID = bad_id) IF event.id EQ text THEN BEGIN WIDGET_CONTROL, text, GET_VALUE = value nbin = FLOAT(value[0]) WIDGET_CONTROL, base, /DESTROY gotbinsize = 1 ENDIF ENDWHILE ENDIF ELSE nbin = bin ;;use keyword-supplied value. ENDIF ;;Read the first file: HSP_READER, pinfo, desc, data, file = file1 ip = DOUBLE(desc.integration/1000D0) IF KEYWORD_SET(NOBIN) THEN $ dbin = HSP_BINNER(data, 1, desc, et0, aux_time) $ ELSE $ dbin = HSP_BINNER(data, nbin, desc, et0, aux_time, /SEC) etvec = et0 IF nfiles GT 1 THEN BEGIN FOR fileindex = 1, nfiles - 1 DO BEGIN file1 = files[fileindex] HSP_READER, pinfo, desc, data, file = file1 IF KEYWORD_SET(NOBIN) THEN $ dtemp = HSP_BINNER(data, 1, desc, et, aux_time) $ ELSE $ dtemp = HSP_BINNER(data, nbin, desc, et, aux_time, /SEC) dbin = [dbin, dtemp] etvec = [etvec, et] ENDFOR ENDIF hspdata = dbin lastfile = file1 PRINT,'HSP_CONCAT all done. Normal Completion.' END