;+ ; NAME: ; ; HSI_BUILD_OBS_TIME ; ; PURPOSE: ; ; Build the HESSI observation times from the saa/eclpise files. ; This will normally be called as a batch process from cron. The ; output is meant to be used by co-investigators to find HESSI ; observation times for colaborative studies. ; ; CATEGORY: ; ; Utility ; ; CALLING SEQUENCE: ; ; hsi_build_obs_time, input_file, output_file ; ; INPUTS: ; ; The saa/eclipes file ; ; KEYWORD PARAMETERS: ; ; LOUD print times info as it's found ; ; OUTPUTS: ; ; Observation time file ; ; MODIFICATION HISTORY: ; ; Writen by J M Loran, Feb. 8, 2002 ;- FUNCTION hsi_build_obs_time_gettime, line ;; extract the two times and orbit numbers per line pos1 = STRPOS (line, ',"') pos2 = STRPOS (line, '",') pos3 = STRPOS (line, ',"', /REVERSE_SEARCH) pos4 = STRPOS (line, '",', /REVERSE_SEARCH) time1 = STRMID (line, 0, pos1) time2 = STRMID (line, pos2 + 2, pos3 - pos2 - 2) orbit1 = FIX (STRMID (line, pos1 + 2, pos2 - pos1 - 2)) orbit2 = FIX (STRMID (line, pos3 + 2, pos4 - pos3 - 2)) ;; extract components of time1 doy1 = STRMID (time1, 0, 3) yr1 = '20' + STRMID (time1, 4, 2) t1 = STRMID (time1, 7, 12) ;; get mjd-1979 for this time mjd1 = anytim (yr1 + '-' + doy1 + 'T' + t1) ;; same for time2 doy2 = STRMID (time2, 0, 3) yr2 = '20' + STRMID (time2, 4, 2) t2 = STRMID (time2, 7, 12) ;; and get mjd-1979 for this time mjd2 = anytim (yr2 + '-' + doy2 + 'T' + t2) ret ={mjd1:mjd1, orbit1: orbit1, mjd2:mjd2, orbit2: orbit2} RETURN , ret END PRO hsi_build_obs_time, input_file, output_file, LOUD=loud ;; read the input file: OPENR, inlun, input_file, /GET_LUN WHILE NOT EOF(inlun) DO BEGIN line = STRING(0) READF, inlun, line IF ( STRLEN(line) EQ 0 ) THEN CONTINUE CASE STRMID ( line, 0, 7) OF 'Sunligh': type = 'Sunlight' 'Eclipse': type = 'Do-Nothing' 'South-A': type = 'SAA' 'Atmosph': type = 'Do-Nothing' 'Norther': type = 'Do-Nothing' 'Souther': type = 'Do-Nothing' '"Start ': junk = 0 ; do nothing ELSE : BEGIN CASE type OF 'Sunlight': BEGIN IF ( N_ELEMENTS (sunlight) EQ 0 ) THEN $ sunlight = {mjd1:1D, orbit1: 0, mjd2:1D, orbit2: 0} $ ELSE sunlight = [sunlight, $ {mjd1:1D, orbit1: 0, mjd2:1D, orbit2: 0}] sunlight[(size(sunlight, /DIM))[0]-1, *] = $ hsi_build_obs_time_gettime(line) END 'SAA' : BEGIN IF ( N_ELEMENTS ( saa) EQ 0 ) THEN $ saa = {mjd1:1D, orbit1: 0, mjd2:1D, orbit2: 0} $ ELSE saa = [saa,{mjd1:1D, orbit1: 0, mjd2:1D, orbit2: 0}] saa[(size(saa, /DIM))[0]-1, *] = $ hsi_build_obs_time_gettime(line) END 'Do-Nothing' : junk = 0 ; do nothing ENDCASE ENDELSE ENDCASE ENDWHILE CLOSE, inlun ;; filter and write output OPENW, outlun, output_file, /GET_LUN PRINTF, outlun, "Start End Duration (min)" ;; The way this works is saa start time is obs end time, and vise ;; versa, where sunlight start is obs start and vise versa. ;; Therefore, we can say any time we have an obs end time after an obs ;; start time, we can save it. This works :) time_str = {time:1.D, tbegin: 1b} ; holds time squence, and start/end flag ; tbegin = 1b means time is start time FOR i=0, N_ELEMENTS (sunlight)- 1 DO BEGIN this_saa = WHERE ((saa.mjd2 GT sunlight[i].mjd1) AND $ (saa.mjd1 LT sunlight[i].mjd2)) IF ( KEYWORD_SET (loud) ) THEN BEGIN PRINT, "sunlight array index: ", i PRINT, "sunlight start: ", anytim(sunlight[i].mjd1,/ECS), $ " sunlight end: ", anytim(sunlight[i].mjd2,/ECS) ENDIF IF ( this_saa[0] NE -1 ) THEN BEGIN ; we have an saa in sunlight time_arr = REPLICATE (time_str, 2 + 2*N_ELEMENTS(this_saa)) time_arr[0].time = sunlight[i].mjd1 time_arr[0].tbegin = 1b ; save sunlight start time_arr[1].time = sunlight[i].mjd2 time_arr[1].tbegin = 0b ; .. and end times t_arr_idx = 2 FOR j=0, N_ELEMENTS(this_saa) - 1 DO BEGIN IF ( KEYWORD_SET (loud) ) THEN BEGIN PRINT, "found saa array index: ", this_saa[j] PRINT, "saa start: ", anytim(saa[this_saa[j]].mjd1,/ECS), $ " saa end: ", anytim(saa[this_saa[j]].mjd2,/ECS) ENDIF ;; save saa times for this sunlight pass time_arr[t_arr_idx].time = saa[this_saa[j]].mjd1 time_arr[t_arr_idx].tbegin = 0b time_arr[t_arr_idx+1].time = saa[this_saa[j]].mjd2 time_arr[t_arr_idx+1].tbegin = 1b t_arr_idx = t_arr_idx + 2 ENDFOR ;; now output new observation times sorted_time_arr = time_arr[SORT(time_arr.time)] FOR k=1, t_arr_idx - 1 DO BEGIN IF ( ( sorted_time_arr[k-1].tbegin EQ 1b AND $ sorted_time_arr[k].tbegin EQ 0b ) AND $ (sorted_time_arr[k].time - sorted_time_arr[k-1].time GT 60) ) $ THEN BEGIN ;; Found observing time IF ( KEYWORD_SET (loud) ) THEN $ PRINT, "obs start: ", anytim(sorted_time_arr[k-1].time,/ECS),$ " obs end: ", anytim(sorted_time_arr[k].time,/ECS) PRINTF, outlun, FORMAT='(%"%19sZ, %19sZ, %5.1f")', $ anytim(sorted_time_arr[k-1].time,/ECS), $ anytim(sorted_time_arr[k].time,/ECS), $ (sorted_time_arr[k].time - sorted_time_arr[k-1].time)/60. ENDIF ENDFOR ENDIF ELSE BEGIN ; no saa, just write out sunlight times IF ( KEYWORD_SET (loud) ) THEN $ PRINT, "obs start: ", anytim(sunlight[i].mjd1,/ECS), $ " obs end: ", anytim(sunlight[i].mjd2,/ECS) PRINTF, outlun, FORMAT='(%"%19sZ, %19sZ, %5.1f")', $ anytim(sunlight[i].mjd1,/ECS), $ anytim(sunlight[i].mjd2,/ECS), $ (sunlight[i].mjd2 - sunlight[i].mjd1)/60. ENDELSE ENDFOR CLOSE, outlun RETURN END