pro milsec_axis, milsecs, tickv, tickl, ticks

;+
; NAME:
;        milsec__axis
; PURPOSE:
;	 gives necessary information for plotting a time axis 
;	 labeled with civil time.
; CATEGORY:
;        plot utility
; CALLING SEQUENCE:
;        milsec__axis, milsecs, tickv, tickl, ticks
; INPUTS:
;	 milsecs = 1 dim array of any type except string and complex; 
; 	 contains the times in milliseconds.
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
;	 None.
; OUTPUTS:
;        tickv = dblarr containing the values of the major ticks.
;	 tickl = string array containing labels for major ticks.
;	 ticks = lonarr(2) containing number of major and minor ticks.
; COMMON BLOCKS:
;        None.
; SIDE EFFECTS:
;	 None.
; RESTRICTIONS:
;	 None.
; MODIFICATION HISTORY:
;	Created from mil_time_axis below J Bonmartin 13/08/98 (obspm.fr) 
;        AM, Sep, 1990. Modified by MG, Feb, 1991, KLK, Nov, 1995
;-

tickv = make_array(30,/long  ,value=0)
tickl = make_array(30,/string,value=" ")
ticks = make_array(2,/long)

im   = n_elements(milsecs)-1
tb   = long(milsecs(0))  &  te = long(milsecs(im))
tlen = te-tb            

case 1 of 
  tlen ge 7200000L : begin & incr=3600000L & nt= 6 & nc= 2 & end  ; hour ticks
  tlen ge 1200000L : begin & incr= 600000L & nt=10 & nc= 5 & end  ; 10 m ticks
  tlen ge  600000L : begin & incr= 300000L & nt= 5 & nc= 5 & end  ;  5 m ticks
  tlen ge  120000L : begin & incr=  60000L & nt= 6 & nc= 5 & end  ;  1 m ticks
  tlen ge   60000L : begin & incr=  20000L & nt= 4 & nc= 8 & end  ; 20 s ticks
  tlen ge   20000L : begin & incr=  10000L & nt=10 & nc= 8 & end  ; 10 s ticks
  tlen ge   10000L : begin & incr=   5000L & nt= 5 & nc= 8 & end  ;  5 s ticks
  tlen ge    5000L : begin & incr=   2000L & nt= 4 & nc= 8 & end  ;  2 s ticks
  tlen ge    2000L : begin & incr=   1000L & nt=10 & nc= 8 & end  ;  1 s ticks
  tlen ge    1000L : begin & incr=    500L & nt= 5 & nc=12 & end  ; .5 s ticks
  tlen ge     200L : begin & incr=    100L & nt=10 & nc=12 & end  ; .1 s ticks
  else :          message, 'time axis too short'
endcase

;
; construct labels
;
it    = tb/incr * incr
nlbl  = tlen/incr +1 
nskip = nlbl/6 +1
i = 0
while (it le te) do begin
   th = it/incr * incr 
   ctme = mil_time(th)
   case nc of 
      2 :  str=string(format='(i2.2)',ctme(0))   
      5 :  str=string(format='(i2.2,":",i2.2)',ctme(0), ctme(1))
      8 :  str=string(format='(2(i2.2,":"),i2.2)', ctme(0),ctme(1),ctme(2))
     12 :  str=string(format='(2(i2.2,":"),i2.2,",",i2.2)', $
                      ctme(0),ctme(1),ctme(2),fix(ctme(3)/10))
   endcase
   if (it ge tb) then begin
     tickv(i) = th
     tickl(i) = str
     if (i mod nskip eq 0) then tickl(i) = str else tickl(i) = " "
     i=i+1
   endif
   it = it + incr
endwhile

ticks(0) = i-1
ticks(1) = nt
while (tickv(ticks(0)) gt te) do begin 
   ticks(0)=ticks(0)-1
   tickv(ticks(0)+1)=0.
endwhile



end

