source: trunk/SRC/ToBeReviewed/PLOTS/axe.pro @ 325

Last change on this file since 325 was 325, checked in by pinsard, 17 years ago

modification of some headers (+some corrections) to prepare usage of the new idldoc

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 15.2 KB
Line 
1;+
2;
3; @file_comments
4; Manage axes for the different drawings created by
5; <pro>plt</pro>, <pro>pltz</pro> and <pro>pltt</pro>
6;
7; @categories
8; Graphics
9;
10; @param COUPE {type=string}
11; It designate the type of cut to which the axes we create
12; must report. For example: 'xy','xt'...
13;
14; @param TEMPSMIN {in}{required}
15; In the case where we do cut containing the time dimension, we have
16; to specify the beginning of the time's axis in julian days.
17;
18; @param TEMPSMAX {in}{required}
19; In the case where we do cut containing the time dimension, we have
20; to specify the end of the time's axis in julian days.
21;
22; @keyword SIN
23; activated when we trace in sinus of the latitude
24;
25; @keyword SEPDATE {type=string}
26; It separate the different constituents of the date. By default,
27; it is a return to the line when we do a 'yt', 'zt' or a 't'.
28; In the other cases, it is a blank.
29;
30; @keyword DIGITSYEAR
31; =2 to use %Z format (2 digits) to code years instead of %Y format.
32; See <pro>label_date</pro> for more information on %Z and %Y.
33;
34; @keyword _EXTRA
35; Used to pass keywords
36;
37; @uses
38; common.pro
39;
40; @restrictions
41; It modify !x. and !y.
42;
43; @history
44; Sebastien Masson (smasson\@lodyc.jussieu.fr)
45;                       11/12/98
46;                       Eric Guilyardi types x,y,z + amelioration de
47;                       l''axe temporel
48;
49; @version
50; $Id$
51;
52;-
53PRO axe, coupe, tempsmin, tempsmax, REVERSE_X = reverse_x, REVERSE_Y = reverse_y, SIN = sin, SEPDATE = sepdate, DIGITSYEAR = digitsyear, _EXTRA = ex
54;
55  compile_opt idl2, strictarrsubs
56;
57@common
58   tempsun = systime(1)         ; pour key_performance
59;--------------------------------------------------------------
60; Management of ticks of the time axis in the case of TEMPSMIN
61; and TEMPSMAX are defined
62;--------------------------------------------------------------
63   divday = 0
64   if n_params() EQ 3 then BEGIN
65;
66      if keyword_set(sepdate) then sep = sepdate ELSE $
67       if coupe EQ 'yt' OR coupe EQ 'zt' OR coupe EQ 't' then sep = '!C' ELSE sep = ' '
68;
69      caldat, tempsmin, mmin, dmin, ymin, hmin, mnmin, smin, _EXTRA = ex
70      caldat, tempsmax, mmax, dmax, ymax, hmax, mnmax, smax, _EXTRA = ex
71; format used for the year (2 or 4/5 digits).
72      IF NOT keyword_set(digitsyear) THEN digitsyear = 4
73      IF digitsyear EQ 2 THEN fmtyr = '%Z' ELSE fmtyr = '%Y'
74;
75      CASE 1 OF
76; yearly base
77        ymin NE 0 AND tempsmax GT julday(mmin, dmin, ymin + 3, hmin, mnmin, smin):BEGIN ; more than 3 years
78          CASE 1 OF
79          ymax-ymin+1 GT 5000: BEGIN & freq = 500. & tminor = 5 & datfmt = fmtyr & end
80          ymax-ymin+1 GT 2000: BEGIN & freq = 200. & tminor = 4 & datfmt = fmtyr & end
81          ymax-ymin+1 GT 1000: BEGIN & freq = 100. & tminor = 5 & datfmt = fmtyr & end
82          ymax-ymin+1 GT 500: BEGIN & freq = 50. & tminor = 5 & datfmt = fmtyr & end
83          ymax-ymin+1 GT 200: BEGIN & freq = 20. & tminor = 4 & datfmt = fmtyr & end
84          ymax-ymin+1 GT 100: BEGIN & freq = 10. & tminor = 5 & datfmt = fmtyr & end
85          ymax-ymin+1 GT 50: BEGIN & freq = 5. & tminor = 5 & datfmt = '%M'+sep+fmtyr & end
86          ymax-ymin+1 GT 20: BEGIN & freq = 4. & tminor = 4 & datfmt = '%M'+sep+fmtyr & end
87          ymax-ymin+1 GT 10: BEGIN & freq = 2. & tminor = 4 & datfmt = '%M'+sep+fmtyr & end
88          ELSE: BEGIN & freq = 1. & tminor = 4 & datfmt = '%M'+sep+fmtyr & end
89          ENDCASE
90          nticks = ceil((ymax-ymin)/freq) + 2
91          yminf = (floor(ymin/freq))*freq
92          ticknom = lonarr(nticks)
93          for y = 0, nticks-1 do ticknom[y] = julday(1, 1, yminf + y*freq, _EXTRA = ex)
94          ticknom = ticknom[where(ticknom GE tempsmin AND ticknom LE tempsmax, nticks)]
95        END
96; monthly base
97        tempsmax GT julday(mmin + 3, dmin, ymin, hmin, mnmin, smin):BEGIN ; more than 3 months
98          CASE 1 OF
99            tempsmax GT julday(mmin + 30, dmin, ymin, hmin, mnmin, smin):BEGIN ; more than 30 months -> ticks every 3 months
100            freq = 3. & tminor = 3 & END
101            tempsmax GT julday(mmin + 16, dmin, ymin, hmin, mnmin, smin):BEGIN ; more than 16 months -> ticks every 2 months
102            freq = 2. & tminor = 2 & END
103            else:BEGIN          ; monthly ticks
104            freq = 1. & tminor = 6 & END
105          ENDCASE
106          nticks = ceil((mmax + 12*(ymax - ymin) - mmin)/freq) + 2
107          mminf = 1 > ((floor(mmin/freq))*freq)
108          ticknom = lonarr(nticks)
109          for m = 0, nticks-1 do ticknom[m] = julday(mminf + freq*m, 1, ymin, _EXTRA = ex)
110          datfmt = '%M'+sep+fmtyr
111          ticknom = ticknom[where(ticknom GE tempsmin AND ticknom LE tempsmax, nticks)]
112        END
113; daily base
114        tempsmax GT julday(mmin, dmin + 3, ymin, hmin, mnmin, smin):BEGIN ; more than 3 days
115          CASE 1 OF
116            tempsmax GT julday(mmin, dmin + 60, ymin, hmin, mnmin, smin):BEGIN ; more than 60 days -> ticks every 7 days
117            freq = 7. & tminor = 2 & END
118            tempsmax GT julday(mmin, dmin + 30, ymin, hmin, mnmin, smin):BEGIN ; more than 30 days -> ticks every 5 days
119            freq = 5. & tminor = 5 & END
120            tempsmax GT julday(mmin, dmin + 16, ymin, hmin, mnmin, smin):BEGIN ; more than 16 days -> ticks every 2 days
121            freq = 2. & tminor = 2 & END
122            ELSE:BEGIN   ; daily ticks
123            freq = 1. & tminor = 2 & END
124          ENDCASE
125          nticks = ceil((tempsmax - tempsmin)/freq) + 2
126          dminf = 1 > ((floor(dmin/freq))*freq)
127          ticknom = lonarr(nticks)
128          for d = 0, nticks-1 do ticknom[d] = julday(mmin, dminf + freq*d, ymin, _EXTRA = ex)
129          datfmt = '%D'+sep+'%M'
130          ticknom = ticknom[where(ticknom GE tempsmin AND ticknom LE tempsmax, nticks)]
131        END
132; hourly base
133        tempsmax GT julday(mmin, dmin, ymin, hmin + 3, mnmin, smin):BEGIN ; more than 3 hours
134          CASE 1 OF
135            tempsmax GT julday(mmin, dmin, ymin, hmin + 48, mnmin, smin):BEGIN ; more than 48 hours -> ticks every 6 hours
136            freq = 6. & tminor = 3 & datfmt = '%D'+sep+'%H:00' & END
137            tempsmax GT julday(mmin, dmin, ymin, hmin + 30, mnmin, smin):BEGIN ; more than 30 hours -> ticks every 4 hours
138            freq = 4. & tminor = 2 & datfmt = '%D'+sep+'%H:00' & END
139            tempsmax GT julday(mmin, dmin, ymin, hmin + 16, mnmin, smin):BEGIN ; more than 16 hours -> ticks every 2 hours
140            freq = 2. & tminor = 2 & datfmt = '%H:00' & END
141            ELSE:BEGIN   ; ticks every hour
142            freq = 1. & tminor = 2 & datfmt = '%H:00' & END
143          ENDCASE
144          nticks = ceil((hmax + 24*(dmax - dmin) - hmin)/freq) + 2
145          hminf = (floor(hmin/freq))*freq
146          ticknom = dblarr(nticks)
147          for h = 0, nticks-1 do ticknom[h] = julday(mmin, dmin, ymin, hminf + freq*h, 0, 0, _EXTRA = ex)
148          ticknom = ticknom[where(ticknom GE tempsmin AND ticknom LE tempsmax, nticks)]
149        END
150; minute base
151        tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin + 3, smin):BEGIN ; more than 3 minutes
152          CASE 1 OF
153            tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin + 120, smin):BEGIN ; more than 120 minutes -> ticks every 10 minutes
154            freq = 10. & tminor = 2 & END
155            tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin + 60, smin):BEGIN ; more than 60 minutes -> ticks every 6 minutes
156            freq = 6. & tminor = 3 & END
157            tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin + 30, smin):BEGIN ; more than 30 minutes -> ticks every 4 minutes
158            freq = 4. & tminor = 2 & END
159            tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin + 15, smin):BEGIN ; more than 15 minutes -> ticks every 2 minutes
160            freq = 2. & tminor = 2 & END
161            ELSE:BEGIN   ; ticks every minutes
162            freq = 1. & tminor = 2 & END
163          ENDCASE
164          nticks = ceil((mnmax + 60*(hmax - hmin) - mnmin)/freq) + 2
165          mnminf = (floor(mnmin/freq))*freq
166          ticknom = dblarr(nticks)
167          for mn = 0, nticks-1 do ticknom[mn] = julday(mmin, dmin, ymin, hmin, mnminf + freq*mn, 0, _EXTRA = ex)
168          ticknom = ticknom[where(ticknom GE tempsmin AND ticknom LE tempsmax, nticks)]
169          datfmt = '%H:%I'
170        END
171; second base
172        ELSE:BEGIN ; less than 3 minutes
173          CASE 1 OF
174            tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin, smin + 120):BEGIN ; more than 120 seconds -> ticks every 20 seconds
175            freq = 20. & tminor = 2 & datfmt = '%H:%I:%S' & END
176            tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin, smin + 60):BEGIN ; more than 60 seconds -> ticks every 15 seconds
177            freq = 15. & tminor = 3 & datfmt = '%H:%I:%S' & END
178            tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin, smin + 30):BEGIN ; more than 30 seconds -> ticks every 10 seconds
179            freq = 10. & tminor = 2 & datfmt = '%H:%I:%S' & END
180            tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin, smin + 15):BEGIN ; more than 15 seconds -> ticks every 4 seconds
181            freq = 4. & tminor = 4 & datfmt = '%H:%I:%S' & END
182            tempsmax GT julday(mmin, dmin, ymin, hmin, mnmin, smin + 7):BEGIN ; more than 7 seconds -> ticks every 2 seconds
183            freq = 2. & tminor = 2 & datfmt = '%H:%I:%S' & END
184            ELSE:BEGIN   ; ticks every minutes
185            freq = 1. & tminor = 2 & datfmt = '%H:%I:%S' & END
186          ENDCASE
187          nticks = ceil((smax + 60*(mnmax - mnmin) - smin)/freq) + 2
188          sminf = (floor(smin/freq))*freq
189          ticknom = dblarr(nticks)
190          for s = 0, nticks-1 do ticknom[s] = julday(mmin, dmin, ymin, hmin, mnmin, sminf + freq*s, _EXTRA = ex)
191          ticknom = ticknom[where(ticknom GE tempsmin AND ticknom LE tempsmax, nticks)]
192        END
193      ENDCASE
194      dummy = label_date(0, 0, 0, DATE_FORMAT = datfmt, _EXTRA = ex)
195      if chkstru(ex, 'DATE_FORMAT') then ex.DATE_FORMAT = ''
196   ENDIF
197;--------------------------------------------------------------
198; Definition of axes parameters case by case
199;--------------------------------------------------------------
200   case coupe of
201      'pltv':BEGIN
202        dtasize = tempsmin
203         !x.range = [-0.5, dtasize[0] - 0.5]
204         !y.range = [-0.5, dtasize[1] - 0.5]
205         if keyword_set(reverse_x) then !x.range=reverse(!x.range)
206         if keyword_set(reverse_y) then !y.range=reverse(!y.range)
207         !x.title = 'nx'
208         !y.title = 'ny'
209      END
210      'xy':BEGIN
211         if keyword_set(reverse_x) then !x.range=[lon2,lon1] ELSE !x.range=[lon1,lon2]
212         if keyword_set(reverse_y) then !y.range=[lat2,lat1] ELSE !y.range=[lat1,lat2]
213         IF key_onearth THEN !x.tickformat='lonaxe'
214         IF key_onearth THEN !y.tickformat='lataxe'
215      END
216      'yz':BEGIN
217         if keyword_set(reverse_x) then !x.range=[lat2,lat1] ELSE !x.range=[lat1,lat2]
218         if keyword_set(reverse_y) then !y.range=[0, -1] ELSE !y.range = [-1, 0]
219         if keyword_set(sin) then BEGIN
220; number of ticks by default
221            plot, [0], [0], /noerase, /nodata, xtick_get = xaxe
222; We increase this number to it be around 10
223            ticks = n_elements(xaxe)-1
224            ticks = ticks*[1, 2, 4, 8]
225            ticks = ticks[(sort(abs(ticks-10)))[0]]
226; We recuperate the x axis for this new number of ticks
227            plot, [0], [0],xticks = ticks, /noerase, /nodata, xtick_get = xaxe
228            !x.ticks = ticks
229            !x.tickv = sin(!pi/180.*xaxe)
230            tickname = strarr(ticks+1)
231            for i = 0,ticks do tickname[i] = lataxe(0, 0, xaxe[i])
232            !x.tickname = tickname
233            !x.range = sin(!pi/180.*!x.range)
234         endif
235      end
236      'xz':BEGIN
237         if keyword_set(reverse_x) then !x.range=[lon2,lon1] ELSE !x.range=[lon1,lon2]
238         if keyword_set(reverse_y) then !y.range=[0, -1] ELSE !y.range = [-1, 0]
239      end
240      'xt' : begin
241         if keyword_set(reverse_x) then !x.range = [lon2,lon1] ELSE !x.range=[lon1,lon2]
242         if keyword_set(reverse_y) then !y.range=[tempsmax, tempsmin]-tempsmin $
243         ELSE !y.range=[tempsmin,tempsmax]-tempsmin
244         IF key_onearth THEN !x.tickformat='lonaxe'
245;          result = LABEL_DATE(DATE_FORMAT = '%M'+sep+fmtyr)
246;          !y.tickformat='LABEL_DATE'
247         !y.tickname = LABEL_DATE(1, 0,ticknom,_EXTRA = ex)
248         !y.ticklen=1.
249         !y.gridstyle=2
250         !y.ticks=nticks-1
251         !y.tickv=ticknom-tempsmin
252         !y.minor=tminor
253         IF divday GT 0 THEN !y.title = 'Time from '+strtrim(dmin,1)+' ' $
254          +def_month('1m', strtrim(mmin, 1))+' '+strtrim(ymin,1)
255      end
256      'yt' : begin
257         if keyword_set(reverse_x) then !x.range = [tempsmax,tempsmin]-tempsmin $
258         ELSE !x.range=[tempsmin,tempsmax]-tempsmin
259         if keyword_set(reverse_y) then !y.range=[lat2, lat1] ELSE !y.range=[lat1,lat2]
260         IF key_onearth THEN !y.tickformat='lataxe'
261         !x.tickname = LABEL_DATE(0, 0,ticknom,_EXTRA = ex)
262         !x.ticklen=1.
263         !x.gridstyle=2
264         !x.ticks=nticks-1
265         !x.tickv=ticknom-tempsmin
266         !x.minor=tminor
267         IF divday GT 0 THEN !y.title = 'Time from '+strtrim(dmin,1)+' ' $
268          +def_month('1m', strtrim(mmin, 1))+' '+strtrim(ymin,1)
269      end
270      'zt' : begin
271         if keyword_set(reverse_x) then !x.range = [tempsmax,tempsmin]-tempsmin $
272         ELSE !x.range=[tempsmin,tempsmax]-tempsmin
273         if vargrid EQ 'W' then gdep=gdepw[0:nzw-1] ELSE gdep=gdept[0:nzt-1]
274         !x.tickname = LABEL_DATE(0, 0,ticknom,_EXTRA = ex)
275         !x.ticklen=1.
276         !x.gridstyle=2
277         !x.ticks=nticks-1
278         !x.tickv=ticknom-tempsmin
279         !x.minor=tminor
280         IF divday GT 0 THEN !y.title = 'Time from '+strtrim(dmin,1)+' ' $
281          +def_month('1m', strtrim(mmin, 1))+' '+strtrim(ymin,1)
282      end
283      't' : BEGIN
284         if keyword_set(reverse_x) then !x.range = [tempsmax,tempsmin]-tempsmin $
285         ELSE !x.range=[tempsmin,tempsmax]-tempsmin
286         !x.tickname = LABEL_DATE(0, 0,ticknom,_EXTRA = ex)
287         !x.ticklen=1.
288         !x.gridstyle=2
289         !x.ticks=nticks-1
290         !x.tickv=ticknom-tempsmin
291         !x.minor=tminor
292         IF divday GT 0 THEN !y.title = 'Time from '+strtrim(dmin,1)+' ' $
293          +def_month('1m', strtrim(mmin, 1))+' '+strtrim(ymin,1)
294      end
295      'x' : begin
296         !x.range=[lon1,lon2]
297         IF key_onearth THEN !x.tickformat='lonaxe'
298      END
299      'y' : begin
300         if keyword_set(sin) then BEGIN
301; Number of ticks by default
302            plot, [0], [0], /nodata, /noerase, xstyle = 5, ystyle = 5, xtick_get = xaxe
303; We increase this number to it be around 10
304            ticks = n_elements(xaxe)-1
305            ticks = ticks*[1, 2, 4, 8]
306            ticks = ticks[(sort(abs(ticks-10)))[0]]
307; We recuperate the x axis for this new number of ticks
308            plot, [0], [0],xticks = ticks,/nodata,/noerase,xstyle=5,ystyle=5,xtick_get=xaxe
309            !x.ticks = ticks
310            !x.tickv = sin(!pi/180.*xaxe)
311            tickname = strarr(ticks+1)
312            for i = 0,ticks do tickname[i] = lataxe(0, 0, xaxe[i])
313            !x.tickname = tickname
314            !x.range = sin(!pi/180.*!x.range)
315         ENDIF ELSE !x.range=[lat1,lat2]
316         IF key_onearth THEN !x.tickformat='lataxe'
317      END
318      'z' : begin
319;          if vargrid EQ 'W' then gdep=gdepw[0:nzw-1] ELSE gdep=gdept[0:nzt-1]
320;          if keyword_set(reverse_y) then !y.range=[gdep[0], gdep[n_elements(gdep)-1]] $
321;          ELSE !y.range=[gdep[n_elements(gdep)-1], gdep[0]]
322      END
323   endcase
324   if keyword_set(key_performance) THEN print, 'temps axe', systime(1)-tempsun
325   return
326end
Note: See TracBrowser for help on using the repository browser.