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

Last change on this file since 378 was 369, checked in by pinsard, 16 years ago

improvements of some headers

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