;+
;
; @file_comments
; Manage axes for the different drawings created by
; plt, pltz and pltt
;
; @categories
; Graphics
;
; @param COUPE {type=string}
; It designate the type of cut to which the axes we create
; must report. For example: 'xy','xt'...
;
; @param TEMPSMIN {in}{required}
; In the case where we do cut containing the time dimension, we have
; to specify the beginning of the time's axis in julian days.
;
; @param TEMPSMAX {in}{required}
; In the case where we do cut containing the time dimension, we have
; to specify the end of the time's axis in julian days.
;
; @keyword SIN
; activated when we trace in sinus of the latitude
;
; @keyword SEPDATE {type=string}
; It separate the different constituents of the date. By default,
; it is a return to the line when we do a 'yt', 'zt' or a 't'.
; In the other cases, it is a blank.
;
; @keyword DIGITSYEAR
; =2 to use %Z format (2 digits) to code years
; instead of %Y format. See help of label_date for more
; information on %Z and %Y.
;
; @keyword _EXTRA
; Used to pass keywords
;
; @uses
; common.pro
;
; @restrictions
; It modify !x. and !y.
;
; @history
; Sebastien Masson (smasson\@lodyc.jussieu.fr)
; 11/12/98
; Eric Guilyardi types x,y,z + amelioration de
; l''axe temporel
;
; @version
; $Id$
;
;-
;
PRO axe, coupe, tempsmin, tempsmax, REVERSE_X = reverse_x, REVERSE_Y = reverse_y, SIN = sin, SEPDATE = sepdate, DIGITSYEAR = digitsyear, _EXTRA = ex
;
compile_opt idl2, strictarrsubs
;
@common
tempsun = systime(1) ; pour key_performance
;--------------------------------------------------------------
; Management of ticks of the time axis in the case of TEMPSMIN
; and TEMPSMAX are defined
;--------------------------------------------------------------
divday = 0
if n_params() EQ 3 then BEGIN
;
if keyword_set(sepdate) then sep = sepdate ELSE $
if coupe EQ 'yt' OR coupe EQ 'zt' OR coupe EQ 't' then sep = '!C' ELSE sep = ' '
;
caldat, tempsmin, mmin, dmin, ymin, hmin, mnmin, smin, _EXTRA = ex
caldat, tempsmax, mmax, dmax, ymax, hmax, mnmax, smax, _EXTRA = ex
; format used for the year (2 or 4/5 digits).
IF NOT keyword_set(digitsyear) THEN digitsyear = 4
IF digitsyear EQ 2 THEN fmtyr = '%Z' ELSE fmtyr = '%Y'
;
CASE 1 OF
; yearly base
ymin NE 0 AND tempsmax GT julday(mmin, dmin, ymin + 3, hmin, mnmin, smin):BEGIN ; more than 3 years
CASE 1 OF
ymax-ymin+1 GT 5000: BEGIN & freq = 500. & tminor = 5 & datfmt = fmtyr & end
ymax-ymin+1 GT 2000: BEGIN & freq = 200. & tminor = 4 & datfmt = fmtyr & end
ymax-ymin+1 GT 1000: BEGIN & freq = 100. & tminor = 5 & datfmt = fmtyr & end
ymax-ymin+1 GT 500: BEGIN & freq = 50. & tminor = 5 & datfmt = fmtyr & end
ymax-ymin+1 GT 200: BEGIN & freq = 20. & tminor = 4 & datfmt = fmtyr & end
ymax-ymin+1 GT 100: BEGIN & freq = 10. & tminor = 5 & datfmt = fmtyr & end
ymax-ymin+1 GT 50: BEGIN & freq = 5. & tminor = 5 & datfmt = '%M'+sep+fmtyr & end
ymax-ymin+1 GT 20: BEGIN & freq = 4. & tminor = 4 & datfmt = '%M'+sep+fmtyr & end
ymax-ymin+1 GT 10: BEGIN & freq = 2. & tminor = 4 & datfmt = '%M'+sep+fmtyr & end
ELSE: BEGIN & freq = 1. & tminor = 4 & datfmt = '%M'+sep+fmtyr & end
ENDCASE
nticks = ceil((ymax-ymin)/freq) + 2
yminf = (floor(ymin/freq))*freq
ticknom = lonarr(nticks)
for y = 0, nticks-1 do ticknom[y] = julday(1, 1, yminf + y*freq, _EXTRA = ex)
ticknom = ticknom[where(ticknom GE tempsmin AND ticknom LE tempsmax, nticks)]
END
; monthly base
tempsmax GT julday(mmin + 3, dmin, ymin, hmin, mnmin, smin):BEGIN ; more than 3 months
CASE 1 OF
tempsmax GT julday(mmin + 30, dmin, ymin, hmin, mnmin, smin):BEGIN ; more than 30 months -> ticks every 3 months
freq = 3. & tminor = 3 & END
tempsmax GT julday(mmin + 16, dmin, ymin, hmin, mnmin, smin):BEGIN ; more than 16 months -> ticks every 2 months
freq = 2. & tminor = 2 & END
else:BEGIN ; monthly ticks
freq = 1. & tminor = 6 & END
ENDCASE
nticks = ceil((mmax + 12*(ymax - ymin) - mmin)/freq) + 2
mminf = 1 > ((floor(mmin/freq))*freq)
ticknom = lonarr(nticks)
for m = 0, nticks-1 do ticknom[m] = julday(mminf + freq*m, 1, ymin, _EXTRA = ex)
datfmt = '%M'+sep+fmtyr
ticknom = ticknom[where(ticknom GE tempsmin AND ticknom LE tempsmax, nticks)]
END
; daily base
tempsmax GT julday(mmin, dmin + 3, ymin, hmin, mnmin, smin):BEGIN ; more than 3 days
CASE 1 OF
tempsmax GT julday(mmin, dmin + 60, ymin, hmin, mnmin, smin):BEGIN ; more than 60 days -> ticks every 7 days
freq = 7. & tminor = 2 & END
tempsmax GT julday(mmin, dmin + 30, ymin, hmin, mnmin, smin):BEGIN ; more than 30 days -> ticks every 5 days
freq = 5. & tminor = 5 & END
tempsmax GT julday(mmin, dmin + 16, ymin, hmin, mnmin, smin):BEGIN ; more than 16 days -> ticks every 2 days
freq = 2. & tminor = 2 & END
ELSE:BEGIN ; daily ticks
freq = 1. & tminor = 2 & END
ENDCASE
nticks = ceil((tempsmax - tempsmin)/freq) + 2
dminf = 1 > ((floor(dmin/freq))*freq)
ticknom = lonarr(nticks)
for d = 0, nticks-1 do ticknom[d] = julday(mmin, dminf + freq*d, ymin, _EXTRA = ex)
datfmt = '%D'+sep+'%M'
ticknom = ticknom[where(ticknom GE tempsmin AND ticknom LE tempsmax, nticks)]
END
; hourly base
tempsmax GT julday(mmin, dmin, ymin, hmin + 3, mnmin, smin):BEGIN ; more than 3 hours
CASE 1 OF
tempsmax GT julday(mmin, dmin, ymin, hmin + 48, mnmin, smin):BEGIN ; more than 48 hours -> ticks every 6 hours
freq = 6. & tminor = 3 & datfmt = '%D'+sep+'%H:00' & END
tempsmax GT julday(mmin, dmin, ymin, hmin + 30, mnmin, smin):BEGIN ; more than 30 hours -> ticks every 4 hours
freq = 4. & tminor = 2 & datfmt = '%D'+sep+'%H:00' & END
tempsmax GT julday(mmin, dmin, ymin, hmin + 16, mnmin, smin):BEGIN ; more than 16 hours -> ticks every 2 hours
freq = 2. & tminor = 2 & datfmt = '%H:00' & END
ELSE:BEGIN ; ticks every hour
freq = 1. & tminor = 2 & datfmt = '%H:00' & END
ENDCASE
nticks = ceil((hmax + 24*(dmax - dmin) - hmin)/freq) + 2
hminf = (floor(hmin/freq))*freq
ticknom = dblarr(nticks)
for h = 0, nticks-1 do ticknom[h] = julday(mmin, dmin, ymin, hminf + freq*h, 0, 0, _EXTRA = ex)
ticknom = ticknom[where(ticknom GE tempsmin AND ticknom LE tempsmax, nticks)]
END
; minute base
tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin + 3, smin):BEGIN ; more than 3 minutes
CASE 1 OF
tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin + 120, smin):BEGIN ; more than 120 minutes -> ticks every 10 minutes
freq = 10. & tminor = 2 & END
tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin + 60, smin):BEGIN ; more than 60 minutes -> ticks every 6 minutes
freq = 6. & tminor = 3 & END
tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin + 30, smin):BEGIN ; more than 30 minutes -> ticks every 4 minutes
freq = 4. & tminor = 2 & END
tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin + 15, smin):BEGIN ; more than 15 minutes -> ticks every 2 minutes
freq = 2. & tminor = 2 & END
ELSE:BEGIN ; ticks every minutes
freq = 1. & tminor = 2 & END
ENDCASE
nticks = ceil((mnmax + 60*(hmax - hmin) - mnmin)/freq) + 2
mnminf = (floor(mnmin/freq))*freq
ticknom = dblarr(nticks)
for mn = 0, nticks-1 do ticknom[mn] = julday(mmin, dmin, ymin, hmin, mnminf + freq*mn, 0, _EXTRA = ex)
ticknom = ticknom[where(ticknom GE tempsmin AND ticknom LE tempsmax, nticks)]
datfmt = '%H:%I'
END
; second base
ELSE:BEGIN ; less than 3 minutes
CASE 1 OF
tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin, smin + 120):BEGIN ; more than 120 seconds -> ticks every 20 seconds
freq = 20. & tminor = 2 & datfmt = '%H:%I:%S' & END
tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin, smin + 60):BEGIN ; more than 60 seconds -> ticks every 15 seconds
freq = 15. & tminor = 3 & datfmt = '%H:%I:%S' & END
tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin, smin + 30):BEGIN ; more than 30 seconds -> ticks every 10 seconds
freq = 10. & tminor = 2 & datfmt = '%H:%I:%S' & END
tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin, smin + 15):BEGIN ; more than 15 seconds -> ticks every 4 seconds
freq = 4. & tminor = 4 & datfmt = '%H:%I:%S' & END
tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin, smin + 7):BEGIN ; more than 7 seconds -> ticks every 2 seconds
freq = 2. & tminor = 2 & datfmt = '%H:%I:%S' & END
ELSE:BEGIN ; ticks every minutes
freq = 1. & tminor = 2 & datfmt = '%H:%I:%S' & END
ENDCASE
nticks = ceil((smax + 60*(mnmax - mnmin) - smin)/freq) + 2
sminf = (floor(smin/freq))*freq
ticknom = dblarr(nticks)
for s = 0, nticks-1 do ticknom[s] = julday(mmin, dmin, ymin, hmin, mnmin, sminf + freq*s, _EXTRA = ex)
ticknom = ticknom[where(ticknom GE tempsmin AND ticknom LE tempsmax, nticks)]
END
ENDCASE
dummy = label_date(0, 0, 0, DATE_FORMAT = datfmt, _EXTRA = ex)
if chkstru(ex, 'DATE_FORMAT') then ex.DATE_FORMAT = ''
ENDIF
;--------------------------------------------------------------
; Definition of axes parameters case by case
;--------------------------------------------------------------
case coupe of
'pltv':BEGIN
dtasize = tempsmin
!x.range = [-0.5, dtasize[0] - 0.5]
!y.range = [-0.5, dtasize[1] - 0.5]
if keyword_set(reverse_x) then !x.range=reverse(!x.range)
if keyword_set(reverse_y) then !y.range=reverse(!y.range)
!x.title = 'nx'
!y.title = 'ny'
END
'xy':BEGIN
if keyword_set(reverse_x) then !x.range=[lon2,lon1] ELSE !x.range=[lon1,lon2]
if keyword_set(reverse_y) then !y.range=[lat2,lat1] ELSE !y.range=[lat1,lat2]
IF key_onearth THEN !x.tickformat='lonaxe'
IF key_onearth THEN !y.tickformat='lataxe'
END
'yz':BEGIN
if keyword_set(reverse_x) then !x.range=[lat2,lat1] ELSE !x.range=[lat1,lat2]
if keyword_set(reverse_y) then !y.range=[0, -1] ELSE !y.range = [-1, 0]
if keyword_set(sin) then BEGIN
; number of ticks by default
plot, [0], [0], /noerase, /nodata, xtick_get = xaxe
; We increase this number to it be around 10
ticks = n_elements(xaxe)-1
ticks = ticks*[1, 2, 4, 8]
ticks = ticks[(sort(abs(ticks-10)))[0]]
; We recuperate the x axis for this new number of ticks
plot, [0], [0],xticks = ticks, /noerase, /nodata, xtick_get = xaxe
!x.ticks = ticks
!x.tickv = sin(!pi/180.*xaxe)
tickname = strarr(ticks+1)
for i = 0,ticks do tickname[i] = lataxe(0, 0, xaxe[i])
!x.tickname = tickname
!x.range = sin(!pi/180.*!x.range)
endif
end
'xz':BEGIN
if keyword_set(reverse_x) then !x.range=[lon2,lon1] ELSE !x.range=[lon1,lon2]
if keyword_set(reverse_y) then !y.range=[0, -1] ELSE !y.range = [-1, 0]
end
'xt' : begin
if keyword_set(reverse_x) then !x.range = [lon2,lon1] ELSE !x.range=[lon1,lon2]
if keyword_set(reverse_y) then !y.range=[tempsmax, tempsmin]-tempsmin $
ELSE !y.range=[tempsmin,tempsmax]-tempsmin
IF key_onearth THEN !x.tickformat='lonaxe'
; result = LABEL_DATE(DATE_FORMAT = '%M'+sep+fmtyr)
; !y.tickformat='LABEL_DATE'
!y.tickname = LABEL_DATE(1, 0,ticknom,_EXTRA = ex)
!y.ticklen=1.
!y.gridstyle=2
!y.ticks=nticks-1
!y.tickv=ticknom-tempsmin
!y.minor=tminor
IF divday GT 0 THEN !y.title = 'Time from '+strtrim(dmin,1)+' ' $
+def_month('1m', strtrim(mmin, 1))+' '+strtrim(ymin,1)
end
'yt' : begin
if keyword_set(reverse_x) then !x.range = [tempsmax,tempsmin]-tempsmin $
ELSE !x.range=[tempsmin,tempsmax]-tempsmin
if keyword_set(reverse_y) then !y.range=[lat2, lat1] ELSE !y.range=[lat1,lat2]
IF key_onearth THEN !y.tickformat='lataxe'
!x.tickname = LABEL_DATE(0, 0,ticknom,_EXTRA = ex)
!x.ticklen=1.
!x.gridstyle=2
!x.ticks=nticks-1
!x.tickv=ticknom-tempsmin
!x.minor=tminor
IF divday GT 0 THEN !y.title = 'Time from '+strtrim(dmin,1)+' ' $
+def_month('1m', strtrim(mmin, 1))+' '+strtrim(ymin,1)
end
'zt' : begin
if keyword_set(reverse_x) then !x.range = [tempsmax,tempsmin]-tempsmin $
ELSE !x.range=[tempsmin,tempsmax]-tempsmin
if vargrid EQ 'W' then gdep=gdepw[0:nzw-1] ELSE gdep=gdept[0:nzt-1]
!x.tickname = LABEL_DATE(0, 0,ticknom,_EXTRA = ex)
!x.ticklen=1.
!x.gridstyle=2
!x.ticks=nticks-1
!x.tickv=ticknom-tempsmin
!x.minor=tminor
IF divday GT 0 THEN !y.title = 'Time from '+strtrim(dmin,1)+' ' $
+def_month('1m', strtrim(mmin, 1))+' '+strtrim(ymin,1)
end
't' : BEGIN
if keyword_set(reverse_x) then !x.range = [tempsmax,tempsmin]-tempsmin $
ELSE !x.range=[tempsmin,tempsmax]-tempsmin
!x.tickname = LABEL_DATE(0, 0,ticknom,_EXTRA = ex)
!x.ticklen=1.
!x.gridstyle=2
!x.ticks=nticks-1
!x.tickv=ticknom-tempsmin
!x.minor=tminor
IF divday GT 0 THEN !y.title = 'Time from '+strtrim(dmin,1)+' ' $
+def_month('1m', strtrim(mmin, 1))+' '+strtrim(ymin,1)
end
'x' : begin
!x.range=[lon1,lon2]
IF key_onearth THEN !x.tickformat='lonaxe'
END
'y' : begin
if keyword_set(sin) then BEGIN
; Number of ticks by default
plot, [0], [0], /nodata, /noerase, xstyle = 5, ystyle = 5, xtick_get = xaxe
; We increase this number to it be around 10
ticks = n_elements(xaxe)-1
ticks = ticks*[1, 2, 4, 8]
ticks = ticks[(sort(abs(ticks-10)))[0]]
; We recuperate the x axis for this new number of ticks
plot, [0], [0],xticks = ticks,/nodata,/noerase,xstyle=5,ystyle=5,xtick_get=xaxe
!x.ticks = ticks
!x.tickv = sin(!pi/180.*xaxe)
tickname = strarr(ticks+1)
for i = 0,ticks do tickname[i] = lataxe(0, 0, xaxe[i])
!x.tickname = tickname
!x.range = sin(!pi/180.*!x.range)
ENDIF ELSE !x.range=[lat1,lat2]
IF key_onearth THEN !x.tickformat='lataxe'
END
'z' : begin
; if vargrid EQ 'W' then gdep=gdepw[0:nzw-1] ELSE gdep=gdept[0:nzt-1]
; if keyword_set(reverse_y) then !y.range=[gdep[0], gdep[n_elements(gdep)-1]] $
; ELSE !y.range=[gdep[n_elements(gdep)-1], gdep[0]]
END
endcase
if keyword_set(key_performance) THEN print, 'temps axe', systime(1)-tempsun
return
end