source: trunk/SRC/ToBeReviewed/PLOTS/DESSINE/pltbase.pro @ 171

Last change on this file since 171 was 171, checked in by smasson, 18 years ago

fix critical bug in plt and pltz when plotting zoom area on other grid than T, introduced in r67

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 14.4 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
6; @file_comments
7; Overlayer contour to trace a field which can be mask.
8; Elementary brick of plt, pltz et pltt.
9;
10; @categories
11; Graphics
12;
13; @param Z2D {in}{required}
14; The table to trace
15;
16; @param X {in}{required}
17; Axis. Vector or array of the same size that z2d. This is the coordinate of z2d on x.
18;
19; @param Y {in}{required}
20; Axis. Vector or array of the same size that z2d. This is the coordinate of z2d on y.
21;
22; @param MASK {in}{required}{type=array}
23; It is the array who mask z2d (with 0s on points we want to mask and 1s on others).
24; If z2d is not masked, put this argument equal to 1.
25;
26; @param XM {in}{required}
27; Axis of the mask. Vector or array of the same size that mask.
28; This is the coordinate of mask on x.
29;
30; @param YM {in}{required}
31; Axis of the mask. Vector or array of the same size that mask.
32; This is the coordinate of mask on y.
33;
34; @param LEVELS {in}{optional}{type=vector}
35; Vectors which contain levels needed at the contour.
36; If it is not given, we take 20 levels between the min and the max.
37
38; @param COLORS {in}{optional}{type=vector}
39; Vectors which contain colors needed at the contour.
40; If it is not given, we take 20 levels between the min and the max.
41;
42; @keyword COLORTRICHAMP
43; The color we want to use to draw the triangulation which is used to make contours of the field.
44;
45; @keyword COLORTRIMASK
46; The color we want to use to draw the triangulation which is used to make contours of the mask.
47;
48; @keyword COLOR_C
49; To draw the contour in color instead of in black
50; with filling in color
51;
52; @keyword CONT_NOFILL
53; Activate it not to fill the point mask to let them transparent!
54; Comment: Nevertheless, we trace mask's contour.
55;
56; @keyword CONT_COLOR {default= (!d.n_colors - 1) < 255 =>white}
57; The color of the continent.
58;
59; @keyword DESSTRICHAMP
60; To draw the triangulation which is used to make field's contours.
61;
62; @keyword DESSTRIMASK
63; To draw the triangulation which is used to make mask's contours.
64;
65; @keyword FORPLT
66; To activate if we want that the drawing of coast be realized by tracecote rather than tracemask.
67;
68; @keyword I_COLORS {type=vector}
69; It is a vector specifying the colors to use to trace contours.
70; It is the same thing that c_colors which act on contours.
71;
72; @keyword MORE {default=10}
73; Number to give to avoid style's bugs:
74;  % Out of range subscript encountered: <LONG      Array[38911]>.
75;  % Execution halted at:  PLTBASE           151
76;             If the bug still exist, increase the value of more!
77; (The explanation and the justification of this method do not have scientific bases yet...).
78;
79; @keyword NOFILL
80; To make just isolines.
81;
82; @keyword NOCONTOUR
83; To make just colors.
84;
85; @keyword UNSUR2
86; To trace one isoline on two.
87;
88; @keyword UNLABSUR {type=integer}
89; I specify we only label one contour on two.
90;
91; @keyword CONTOUR
92; To be used since plt, pltz or pltt. (Have a look on these routines).
93;
94; @keyword _EXTRA
95; Used to pass your keywords
96;
97; @uses
98; common.pro
99;
100; @restrictions
101; In the case of z2d, x and y are arrays of same size, we hate to put them as vectors: z2d[*], x[*], y[*].
102;
103; @history
104;  Sebastien Masson (smasson\@lodyc.jussieu.fr)
105; ????
106; 8/2/2000 check if the tri array is not equal to
107; -1. allow contour with out using a triangulation.
108;
109; @version
110; $Id$
111;
112; @todo seb L.172 à 173
113;
114;-
115;------------------------------------------------------------
116;------------------------------------------------------------
117;------------------------------------------------------------
118PRO pltbase, z2d, x, y, mask, xm, ym, levels, colors, UNSUR2 = unsur2, CONTOUR = contour $
119             , NOCONTOUR = nocontour, NOFILL = nofill $
120             , TRICHAMP = trichamp, TRIMSK = trimsk $
121             , REALCONT = realcont, NAN = nan, usetri = usetri $
122             , COLORTRICHAMP = colortrichamp, COLORTRIMASK = colortrimask $
123             , COLORTRINAN = colortrinan $
124             , COLORPOINTS = colorpoints, DRAWPOINTS = drawpoints $
125             , TH_TRICHAMP = th_trichamp, TH_TRIMASK = th_trimask $
126             , DESSTRICHAMP = desstrichamp, DESSTRIMASK = desstrimask $
127             , DESSTRINAN = desstrinan, COLOR_C = color_c $
128             , I_COLORS = i_colors,  CONT_COLOR = CONT_COLOR $
129             , CONT_NOFILL = cont_nofill, UNLABSUR = unlabsur $
130             , COINMONTEMASK = coinmontemask, COINDESCENDMASK = coindescendmask $
131             , COINMONTENAN = coinmontenan, COINDESCENDNAN = coindescendnan $
132             , INDICEZOOMMASK = indicezoommask, INDICEZOOMNAN = indicezoomnan $
133             , MASKORG = maskorg, MASKNAN = masknan, TRINAN = trinan $
134             , FORPLT = forplt, REALSECTION = realsection $
135             , MORE = more, EXCHANGE_XY = exchange_xy $
136             , _EXTRA = ex
137;---------------------------------------------------------
138;
139  compile_opt idl2, strictarrsubs
140;
141@cm_4mesh
142  IF NOT keyword_set(key_forgetold) THEN BEGIN
143@updatenew
144@updatekwd
145  ENDIF
146;---------------------------------------------------------
147;
148; Explanation concerning contour. This keyword is activated when we trace a
149; colored contour different from the one with black trait.
150; If it is activated (case n_elements(contour) NE 0), we pass 2 time in pltbase:
151;   1) We trace colors then we leave, it is the case:
152;         n_elements(contour) NE 0 AND n_elements(contour) NE 4)
153;   2) We trace contours in traits then continents, it is the case:
154;         n_elements(contour) NE 0 AND n_elements(contour) EQ 4)
155;
156;------------------------------------------------------------
157  tempsun = systime(1)          ; To key_performance
158  if n_elements(mask) EQ 0 then mask = 1b
159  if n_elements(masknan) EQ 0 then masknan = 1b
160  IF total(mask) EQ n_elements(z2d) THEN mask = 1b
161;----------------------------------------------------------------------
162; If levels and colors aren't given
163;----------------------------------------------------------------------
164  if n_params() EQ 4 then $
165    label, 0, min(z2d*mask), max(z2d*mask), ncontour, levels, colors
166; attention bidouille inexplicable pour que tout se passe bien avec les
167; postcript ds pltz!!!
168  if n_elements(contour) LE 4 AND !x.type EQ 0 THEN $
169    plot, [0], [0], xstyle = 5, ystyle = 5, /nodata, /noerase, title = '', subtitle = ''
170;----------------------------------------------------------------------
171; Is cell_fill is a part of _extra, we desactive it if it is nt equal to 2
172;----------------------------------------------------------------------
173  IF chkstru(ex, 'CELL_FILL') THEN BEGIN
174    cell_fill = ex.CELL_FILL
175    if ex.CELL_FILL NE 2 then ex.CELL_FILL = 0
176  ENDIF ELSE cell_fill = 0      ;
177;----------------------------------------------------------------------
178; I) Filling of contours in palette colors
179;----------------------------------------------------------------------
180  if NOT keyword_set(more) then more = 10
181  if NOT keyword_set(nofill) AND NOT keyword_set(color_c) then begin
182    if n_elements(contour) NE 4 THEN BEGIN
183      if usetri EQ 2 then BEGIN
184        IF size(x, /n_dimensions) EQ 1 THEN x = x#replicate(1, (size(z2d))[2])
185        IF size(y, /n_dimensions) EQ 1 THEN y = replicate(1, (size(z2d))[1])#y
186        contour, [z2d[*], fltarr(more)], [x[*], fltarr(more)] $
187          , [y[*], fltarr(more)], levels = levels, c_color = colors $
188          , /noerase, /fill, TRIANGULATION = trichamp, _extra = ex
189        ENDIF ELSE BEGIN
190        IF size(x, /n_dimensions) EQ 2 THEN x = x[*, 0]
191        IF size(y, /n_dimensions) EQ 2 THEN y = reform(y[0, *])
192        contour, z2d, x, y, levels = levels, c_color = colors, /noerase $
193          , /fill, _extra = ex
194      ENDELSE
195    ENDIF
196  ENDIF
197  if n_elements(contour) NE 0 AND n_elements(contour) NE 4 THEN GOTO, fini
198  IF chkstru(ex, 'C_ORIENTATION') THEN ex = extractstru(ex, 'C_ORIENTATION')
199  IF chkstru(ex, 'C_SPACING') THEN ex = extractstru(ex, 'C_SPACING')
200  IF chkstru(ex, 'C_COLORS') THEN ex = extractstru(ex, 'C_COLORS')
201;------------------------------------------------------------
202; II) Drawing of contours in traits
203;------------------------------------------------------------
204  if n_elements(contour) EQ 4 OR n_elements(contour) EQ 0 THEN BEGIN
205;
206; we put the masked values to NaN
207;
208    IF (n_elements(mask) GT 1 OR n_elements(masknan) GT 1) $
209      AND NOT keyword_set(cont_nofill) THEN BEGIN
210      IF keyword_set(maskorg) THEN tonan = maskorg*masknan ELSE tonan = mask*masknan
211      tonan = where(remplit(tonan, nite = 1, mask = tonan $
212                            , /basique, fillval = 0 $
213                            , fillxdir = keyword_set(realsection)) EQ 0, count)
214      IF count NE 0 THEN z2d[temporary(tonan)] = !values.f_nan
215    ENDIF   
216;
217; We do not pass if we have to make differents contours...
218; In the case of unsur2 is activated, we reduce levels
219    if NOT keyword_set(nocontour) then begin
220      IF keyword_set(unsur2) THEN levels = levels[where(zeroun(n_elements(levels) ) eq 1)]
221; Is unlabsur activated?  Does C_LABEL passed via _EXTRA?
222      if keyword_set(unlabsur) THEN IF chkstru(ex, 'C_LABELS') THEN $
223        ex.C_LABELS = 1-((indgen(n_elements(ex.C_LABELS)) MOD unlabsur) < 1)
224;
225; Not to fill when cell_fill is imposed...
226      IF chkstru(ex, 'CELL_FILL') THEN ex.CELL_FILL = 0
227;
228      CASE 1 OF
229        keyword_set(color_c):c_colors = colors
230        keyword_set(i_colors):c_colors = i_colors
231        ELSE:
232      ENDCASE
233;
234      IF usetri EQ 2 THEN BEGIN
235        IF size(x, /n_dimensions) EQ 1 THEN x = x#replicate(1, (size(z2d))[2])
236        IF size(y, /n_dimensions) EQ 1 THEN y = replicate(1, (size(z2d))[1])#y
237        contour, [z2d[*], fltarr(more)], [x[*], fltarr(more)] $
238          , [y[*], fltarr(more)], levels = levels $
239          , overplot = 1-keyword_set(nofill), noerase = keyword_set(nofill) $
240          , c_colors = c_colors, TRIANGULATION = trichamp, _extra = ex
241      ENDIF ELSE BEGIN
242        IF size(x, /n_dimensions) EQ 2 THEN x = x[*, 0]
243        IF size(y, /n_dimensions) EQ 2 THEN y = reform(y[0, *])
244        contour, z2d, x, y, levels = levels $
245          , overplot = 1-keyword_set(nofill), noerase = keyword_set(nofill) $
246          , c_colors = c_colors, _extra = ex
247      ENDELSE
248    ENDIF
249;----------------------------------------------------------------------
250; III) Filling of colored continents.
251;----------------------------------------------------------------------
252    IF chkstru(ex, 'CELL_FILL') THEN ex.CELL_FILL = cell_fill < 1
253    IF chkstru(ex, 'LEVELS') THEN ex = extractstru(ex, 'LEVELS')
254    IF chkstru(ex, 'NODATA') THEN ex = extractstru(ex, 'NODATA')
255    IF NOT keyword_set(cont_color) THEN cont_color = (!d.n_colors-1) <  255   
256;
257; If there is points at NaN
258; We trace points in white at NaN bafore drawing coasts with a trait.
259;
260    if keyword_set(trinan) THEN BEGIN
261      IF size(x, /n_dimensions) EQ 1 THEN x = x#replicate(1, (size(masknan))[2])
262      IF size(y, /n_dimensions) EQ 1 THEN y = replicate(1, (size(masknan))[1])#y
263      contour, [1b-masknan[*], fltarr(more)], [x[*], fltarr(more)] $
264        , [y[*], fltarr(more)], levels = 0.5, /overplot, /fill $
265        , c_colors = cont_color, TRIANGULATION = trinan, _extra = ex
266      IF keyword_set(forplt) THEN $
267        completecointerre, COINMONTE = coinmontenan $
268        , COINDESCEND = coindescendnan, INDICEZOOM = indicezoomnan $
269        , CONT_COLOR = cont_color, _EXTRA = ex $
270      ELSE fillcornermask, x[*, 0], y[0, *], COINMONTE = coinmontenan $
271        , COINDESCEND = coindescendnan, CONT_COLOR = cont_color, _extra = ex
272    ENDIF
273;
274; Filling of continents
275;
276    if keyword_set(realcont) then if realcont EQ 1 then mask = 1b
277    if n_elements(mask) NE 1 then BEGIN ; If mask=1 we gap it.
278;
279      if NOT keyword_set(cont_nofill) then BEGIN
280;
281; mask filling
282;
283        case 1 of
284          keyword_set(realsection):drawsectionbottom, mask, xm, ym $
285            , CONT_NOFILL = cont_nofill, CONT_COLOR = cont_color, _EXTRA = ex
286          usetri GE 1:BEGIN
287            if n_elements(trimsk) eq 0 then trimsk = trichamp
288            IF size(xm, /N_DIMENSIONS) EQ 1 THEN xm = xm#replicate(1, (size(mask))[2])
289            IF size(ym, /N_DIMENSIONS) EQ 1 THEN ym = replicate(1, (size(mask))[1])#ym
290            contour, [1b-mask[*], fltarr(more)], [xm[*], fltarr(more)] $
291              , [ym[*], fltarr(more)], LEVELS = 0.5, /OVERPLOT, /FILL $
292              , C_COLORS = cont_color, TRIANGULATION = trimsk, _extra = ex
293            IF keyword_set(forplt) THEN $
294              completecointerre, COINMONTE = coinmontemask $
295              , COINDESCEND = coindescendmask, INDICEZOOM = indicezoommask $
296              , CONT_COLOR = cont_color, _EXTRA = ex $
297            ELSE fillcornermask, xm[*, 0], ym[0, *], COINMONTE = coinmontemask $
298              , COINDESCEND = coindescendmask, CONT_COLOR = cont_color, _extra = ex
299          END
300          ELSE:BEGIN
301            IF size(xm, /n_dimensions) EQ 2 THEN xm = xm[*, 0]
302            IF size(ym, /n_dimensions) EQ 2 THEN ym = reform(ym[0, *])
303            contour, 1b-mask, xm, ym, LEVELS = 0.5, /OVERPLOT $
304              , /FILL, C_COLORS = cont_color, _EXTRA = ex
305          END
306        ENDCASE
307      ENDIF                     ; NOT keyword_set(cont_nofill)
308;------------------------------------------------------------
309; IV) Trace coast in traits
310;------------------------------------------------------------
311      case 1 of
312        keyword_set(realsection) AND NOT keyword_set(cont_nofill):     
313        keyword_set(realsection) AND keyword_set(cont_nofill): $
314          drawsectionbottom, mask, xm, ym $
315          , CONT_NOFILL = cont_nofill, _extra = ex
316        (keyword_set(forplt) AND (!map.projection GT 0 OR key_irregular)) $
317          OR keyword_set(nan):tracecote, _extra = ex
318        ELSE:tracemask, mask, xm, ym, _extra = ex
319      endcase                   ;
320    ENDIF                       ; n_elements(mask) NE 1
321  ENDIF
322;------------------------------------------------------------
323; draw the triangulations
324;------------------------------------------------------------
325  if keyword_set(desstrichamp) then $
326    dessinetri, trichamp, x, y, color = colortrichamp, thick = th_trichamp
327  if keyword_set(desstrimask) then $
328    dessinetri, trimsk, xm, ym, color = colortrimask, thick = th_trimask
329  if keyword_set(desstrinan) then $
330    dessinetri, trinan, x, y, color = colortrinan
331  if keyword_set(drawpoints) then $
332    tracegrille, x, y, color = colorpoints
333;------------------------------------------------------------
334;
335fini:
336  IF keyword_set(key_performance) THEN print, 'temps pltbase', systime(1)-tempsun
337
338  return
339end
Note: See TracBrowser for help on using the repository browser.