FUNCTION compute_time, timeave, date1, date2, NEXT = next @common @com_eg ; ; compute number + array of time intervals in units of timeave between date1 and date2 ; if /NEXT, compute next date after date1, using date2 units of timeave ; date code [yy..yyy][mm][dd]-[sssss] if s ; [yy..yyy][mm][dd] if d ; [yy..yyy][mm] if m ; [yy..yyy] if y len1 = strlen(date1) IF NOT keyword_set(NEXT) THEN BEGIN len2 = strlen(date2) mean_type = strmid(timeave, strlen(timeave)-1,1) CASE mean_type OF 'y':BEGIN ; year case delta_time = long(strmid(timeave, 0, strlen(timeave)-1)) year1 = long(date1) year2 = long(date2) count = (year2-year1+1)*delta_time IF calendar_type LE 1 THEN BEGIN time = findgen(count)*360*delta_time+julday(1,1,year1) ENDIF ELSE BEGIN time = findgen(count)*360*delta_time+ $ julday(1,1,year1, ndayspm = calendar_type) ENDELSE END 'm': BEGIN ; month case CASE strmid(timeave, strlen(timeave)-2,1) OF 'm': BEGIN ; mean month delta_time = long(strmid(timeave, 0, strlen(timeave)-2)) month1 = long(strmid(date1, 0, 2)) month2 = long(strmid(date2, 0, 2)) count = (month2-month1+1) ; count = (month2-month1+1)/delta_time ; time scale for hov IF calendar_type LE 1 THEN BEGIN time = lindgen(nb_cycles*count)*30*delta_time+ $ julday(month1,1,01) ENDIF ELSE BEGIN time = lindgen(nb_cycles*count)*30*delta_time+ $ julday(month1,1,01, ndayspm = calendar_type) ENDELSE END ELSE: BEGIN ; month / year delta_time = long(strmid(timeave, 0, strlen(timeave)-1)) month1 = long(strmid(date1, len1-2, 2)) year1 = long(strmid(date1, 0, len1-2)) month2 = long(strmid(date2, len2-2, 2)) year2 = long(strmid(date2, 0, len2-2)) count = 0 im = month1 iy = year1 idate = long(month1+100*year1) WHILE idate LE date2 DO BEGIN idate = long(im+100*iy) count = count + 1 im = im + delta_time IF im EQ 13 THEN BEGIN iy = iy+1 im = 1 ENDIF ENDWHILE count = count - 1 ; time scale for hov IF calendar_type LE 1 THEN BEGIN time = lindgen(count)*30*delta_time+ $ julday(month1,1,year1) ENDIF ELSE BEGIN time = lindgen(count)*30*delta_time+ $ julday(month1,1,year1, ndayspm = calendar_type) ENDELSE END ENDCASE END 'd': BEGIN ; day case delta_time = long(strmid(timeave, 0, strlen(timeave)-1)) day1 = long(strmid(date1, len1-2, 2)) month1 = long(strmid(date1, len1-4, 2)) year1 = long(strmid(date1, 0, len1-4)) day2 = long(strmid(date2, len1-2, 2)) month2 = long(strmid(date2, len2-4, 2)) year2 = long(strmid(date2, 0, len2-4)) count = 0 id = day1 im = month1 iy = year1 idate = long(day1+100*month1+10000*year1) WHILE idate LE date2 DO BEGIN idate = long(id+100*im+10000*iy) count = count + 1 id = id + delta_time idmax = daypm(im, iy) IF id GT idmax THEN BEGIN im = im + 1 id = id - idmax ENDIF IF im EQ 13 THEN BEGIN iy = iy+1 im = 1 ENDIF ENDWHILE count = count - 1 ; time scale for hov IF calendar_type LE 1 THEN BEGIN time = lindgen(count)*1*delta_time+ $ julday(month1,1,year1) ENDIF ELSE BEGIN time = lindgen(count)*1*delta_time+ $ julday(month1,1,year1, ndayspm = calendar_type) ENDELSE END 's': BEGIN ; seconds case delta_time = long(strmid(timeave, 0, strlen(timeave)-1)) sec1 = long(strmid(date1, len1-5, 5)) day1 = long(strmid(date1, len1-8, 2)) month1 = long(strmid(date1, len1-10, 2)) year1 = long(strmid(date1, 0, len1-10)) sec2 = long(strmid(date2, len1-5, 5)) day2 = long(strmid(date2, len1-8, 2)) month2 = long(strmid(date2, len2-10, 2)) year2 = long(strmid(date2, 0, len2-10)) count = 0 is = sec1 id = day1 im = month1 iy = year1 WHILE is LE sec2 AND id LE day2 AND im LE month2 $ AND iy LE year2 DO BEGIN count = count + 1 is = is + delta_time IF is GT 86400 THEN BEGIN id = id + 1 is = is - 86400 ENDIF idmax = daypm(im, iy) IF id EQ idmax THEN BEGIN im = im + 1 id = 1 ENDIF IF im EQ 13 THEN BEGIN iy = iy+1 im = 1 ENDIF ENDWHILE ; time scale for hov IF calendar_type LE 1 THEN BEGIN time = sec1/86400.+lindgen(count)*1/86400.*delta_time+ $ julday(month1,1,year1) ENDIF ELSE BEGIN time = sec1/86400.+lindgen(count)*1/86400.*delta_time+ $ julday(month1,1,year1, ndayspm = calendar_type) ENDELSE END ELSE: BEGIN print, ' **** compute_time not ready for timeave = ', timeave count = -1 time = 0 END ENDCASE IF date1 EQ date2 THEN count = 1 timearr = {count: count, scale: time} return, timearr ENDIF ELSE BEGIN ; next date after date1, using date2 units of timeave dmax = 30 print, ' **** ASSUMES DMAX = 30' CASE strmid(timeave, strlen(timeave)-1, 1) OF 'd': BEGIN ndays = long(strmid(timeave, 0, strlen(timeave)-1)) day1 = long(strmid(date1, len1-2, 2)) month1 = long(strmid(date1, len1-4, 2)) year1 = long(strmid(date1, 0, len1-4)) iadd = 1 day2 = day1 month2 = month1 year2 = year1 WHILE iadd LE date2 DO BEGIN day2 = day2+1 IF day2 GT dmax THEN BEGIN month2 = month2 + 1 day2 = 1 IF month2 GT 12 THEN BEGIN year2 = year2+1 month2 = 1 ENDIF ENDIF iadd = iadd + 1 ENDWHILE IF year2 GE 10 THEN BEGIN nextdate = string(year2) ENDIF ELSE BEGIN nextdate = string(format = '(I2.2)',year2) ENDELSE nextdate = nextdate+string(format = '(I2.2)', month2)+string(format = '(I2.2)', day2) END ELSE: BEGIN print, ' **** next time not ready for timeave = ', timeave nextdate = -1 END ENDCASE return, nextdate ENDELSE END