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

Last change on this file since 209 was 209, checked in by smasson, 17 years ago

bugfix + introduce C grid based on F, U and V points

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