
pro gettime, timestr, start, stop, range, type, msod, day
;
;+
; NAME: gettime
; PURPOSE:
;       Convert time string to range, msod, day etc.
; CALLING SEQUENCE:
;       gettime, timestr, start, stop, range, type, msod, day
; INPUTS:
;       timestr = character string of starting and stopping time.
;                (10:20:34 1-jan-92 // 2:35:36 2-jan-92)
;       must use '//' to separate starting and topping time.
;       can input only starting time or only stopping time.
;       If the stopping time does not include day-month-year, then use
;       day-month-year of starting time.
;       If input only starting time, then STOP=START.
;       If input only stopping time, then START=0 0 0 0 0 0 0 
; OUTPUTS:
;       start   = starting time in INT array(7)
;       stop    = stopping time in INT array(7)
;       range   = [[start], [stop]], Int array(7,2)
;       msod    = h:m:s in msec, Long array(2)
;       day     = day, int array(2)
;       type    = To indicate type of input timestr
;                 if type=0 have both startng and stopping time
;                    type=1 starting time only
;                    type=2 stopping time only
;                    type=3 error, stoppinr time only without d-m-y
; COMMON BLOCKS:
;       None
; RESTRICTIONS:
;       Input string must be in "h:m:s day-month-year // h:m:s
;       day-month-year".
;       For example:
;       timestr='10:20:30 1-jan-92 // 1:3:49 2-feb-92'
;       Stopping time can supply h:m:s only, if supply the starting
;       time. (Input stopping time only must have d-m-y)
; PROCEDURE:
;       Use str2arr function to convert time string to TIMES array.
;       Use timstr2ex function to convert TIMES to int START and STOP.
;       Get RANGE from START and STOP.(RANGE=[[START],[STOP]])
;       Use ex2int procedure to get MSOD and DAY from RANGE.
;       Also determine the type of input string.
;       If no "day-month-year" in stopping time, then use
;       "day-month-year" of starting time. But if input only stopping
;       time must have day-month-year. (Can not use starting d-m-y)
;       if type=0 have both startng and stopping time
;          type=1 starting time only
;          type=2 stopping time only
;          type=3 input error, stopping time only must have d-m-y
; PROCEDURE CALLED:
;       str2arr, timstr2ex, ex2int 
; MODIFICATION HISTORY:
;       Written by Fei-Mei chou Jan, 92
;-
;
; if no parameters are present, assume information mode
;
if (n_params() eq 0) then print,     $
  'gettime, timestr, start, stop, range, type, msod, day' $
else begin
  times=str2arr(timestr, delimit='//')
  start=timstr2ex(times(0))
  if (n_elements(times) eq 1) then begin   ;startint time only, type=1
    type = 1
    stop = start
  endif else begin        ;stopping time only or have both(type=2 or 0)
    stop = timstr2ex(times(1))
    type = 0
    if (total(start) eq 0.0) then type = 2   ;stopping time only
    if (strlen(strcompress(times(1))) lt 11) then begin   ;no d-m-y
      stop(4:6) = start(4:6)
      if (type eq 2) then type = 3   ;input error flag, need d-m-y
    endif
  endelse
;
  range=[[start],[stop]]
  ex2int, range,msod,day
endelse
return
end
