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

Last change on this file since 142 was 142, checked in by navarro, 18 years ago

english and nicer header (2a)

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