source: trunk/SRC/ToBeReviewed/PLOTS/DESSINE/pltv.pro @ 251

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

small bugfix: z2d[0] = -1 and z2d has more than 1 element

  • Property svn:keywords set to Id
File size: 7.4 KB
Line 
1;+
2;
3; @file_comments
4; Draw 2d plots with TV procedure
5;
6; @categories find a file
7; graphic
8;
9; @param DATA {in}{required}
10; The field we want to display can be:
11;    1) an array. If the array is not a 2D array, its mean along
12;       the z and t direction will be automatically performed
13;       (as it is done in plt).
14;    2) a structure respecting all criterions specified by
15;       <pro>litchamp</pro> cf. IDL> xhelp,'litchamp'
16;
17; @param MIN {in}{optional}{default=min of DATA (on non-masked points)}
18;
19; @param MAX {in}{optional}{default=max of DATA (on non-masked points)}
20;
21; @keyword BOTTOM {default=0}
22; The lowest color index of the colors to be used
23;
24; @keyword BOXZOOM
25; Vector indicating the geographic zone on which we want to cut the map.
26;  If BOXZOOM has :
27; 1 element : The extraction is made on [lon1, lon2, lat1, lat2, 0.,boxzoom[0]]
28; 2 elements: The extraction is made on [lon1, lon2, lat1, lat2, boxzoom[0],boxzoom[1]]
29; 4 elements: The extraction is made on [Boxzoom, 0, max([gdept, gdepw])]
30; 5 elements: The extraction is made on [Boxzoom[0:3], 0, Boxzoom[4]]
31; 6 elements: The extraction is made on Boxzoom
32;
33; Where lon1, lon2, lat1, lat2 are global variables defined at the last domdef!
34;
35; @keyword C_NAN {default=!d.n_colors < 255}
36; The color number that should be used for the NaN values.
37;
38; @keyword C_MASK {default=0}
39; The color number that should be used for the mask values.
40;
41; @keyword MASKVAL {default=1.e+20}
42; The mask value. Note that if abs(mask) < 1.e6, then the
43; exact value of the mask is used to find the maskwd point.
44; if abs(mask) > 1.e6, the test to find the masked value is ge
45; abs(mask)/10. This is necessary to avoid the rounding errors
46;
47; @keyword NCOLORS {default=(d.n_colors < 256) - 1 - BOTTOM}
48; number of colors to be used.
49;
50; @keyword NOINTERP
51; Used this keyword if you don't want that the values
52; are interpolated from BOTTOM using NCOLORS colors.
53; This can be for example useful when working on byte type arrays.
54;
55; @keyword _EXTRA
56; Used to pass keywords to <pro>PLACEDESSIN</pro>, <pro>TV</pro>, <pro>AXE</pro>, <pro>LEGENDE</pro>, <pro>BARRECOULEUR</pro>, <pro>TERMINEDESSIN</pro>
57;
58; @examples
59; IDL> tvplus, dist(100)
60;
61; @history
62; Aug 2006: Sebastien Masson (smasson\@lodyc.jussieu.fr)
63;
64; @version
65; $Id$
66;
67;-
68;
69PRO pltv, data, min, max, BOTTOM = bottom, BOXZOOM = boxzoom $
70          , C_MASK = c_mask, C_NAN = c_nan, MININ = minin, MAXIN = maxin $
71          , MASKVAL = maskval, NCOLORS = ncolors, NOINTERP = nointerp $
72          , _EXTRA = ex
73;
74  compile_opt idl2, strictarrsubs
75;
76  @cm_general ; for key_performance
77;--------------------------------------------------------------
78  tempsun = systime(1)          ; for key_performance
79;--------------------------------------------------------------
80;--------------------------------------------------------------
81; I2) Reading of the field and checkup.
82;--------------------------------------------------------------
83  IF n_elements(minin) NE 0 THEN min = minin
84  IF n_elements(maxin) NE 0 THEN max = maxin
85  IF size(data, /type) NE 8 THEN z2d = reform(float(data)) ELSE z2d = data
86  IF size(z2d, /n_dimensions) NE 2 then BEGIN
87    if keyword_set(boxzoom) then BEGIN
88      savedbox = 1b
89      saveboxparam, 'boxparam4pltv.dat'
90    ENDIF
91    z2d = checkfield(temporary(z2d), 'plt', TYPE = 'xy', direc = direc, BOXZOOM = boxzoom)
92    if n_elements(z2d) EQ 1 AND z2d[0] EQ -1 then BEGIN
93      IF keyword_set(savedbox) THEN restoreboxparam, 'boxparam4pltv.dat'
94      return
95    ENDIF
96  ENDIF
97  dtasize = size(z2d, /dimensions)
98;------------------------------------------------------------
99; def of ncolmax, bottom, topcol et ncolors
100;------------------------------------------------------------
101  ncolmax = !d.n_colors < 256
102  IF n_elements(bottom) EQ 0 THEN bottom = 1
103  IF NOT keyword_set(ncolors) then ncolors = ncolmax - 1 - bottom
104  topcol = (bottom + ncolors - 1) < (ncolmax - 1)
105;------------------------------------------------------------
106; Do we have NaN values in z2d???
107;------------------------------------------------------------
108  msknan = finite(z2d, /nan)
109  nan = total(msknan)
110  IF keyword_set(nan) THEN nanind = where(temporary(msknan) EQ 1)
111;------------------------------------------------------------
112; get the mask
113;------------------------------------------------------------
114  IF n_elements(maskval) EQ 0 THEN maskval = 1.e20
115  IF abs(maskval) LT 1e6 THEN BEGIN
116    IF keyword_set(nan) THEN z2d[nanind] = 1.e20
117    msk = z2d NE maskval
118  ENDIF ELSE BEGIN
119    IF keyword_set(nan) THEN z2d[nanind] = 0
120    msk = abs(z2d) LT abs(maskval)/10.
121  ENDELSE
122  maskind = where(msk EQ 0, masked)
123  IF keyword_set(nan) THEN z2d[nanind] = !values.f_nan
124;------------------------------------------------------------
125; get the real min/max and the user defined min/max of the array
126;------------------------------------------------------------
127  determineminmax, z2d, msk, truemin, truemax, MININ = min, MAXIN = max, NAN = nan
128  z2d = min > temporary(z2d) < max
129;------------------------------------------------------------
130; apply other keywords (nointerp, c_nan, c_mask)
131;------------------------------------------------------------
132  IF NOT keyword_set(nointerp) THEN BEGIN
133; interpolation between bottom and bottom+ncolors-1
134    m = 1.*(ncolors-1)/(max-min)
135    p = bottom - 1.*min*m
136    z2d = m * temporary(z2d) + p
137  ENDIF
138; set c_nan for NaN values
139  IF keyword_set(nan) THEN BEGIN
140    IF n_elements(c_nan) NE 0 THEN cnan = 0 > c_nan < (ncolmax -1) ELSE cnan = (ncolmax -1)
141    z2d[nanind] = cnan
142  ENDIF
143; c_mask for masked values
144  IF keyword_set(masked) THEN BEGIN
145    IF n_elements(c_mask) NE 0 THEN cmask = 0 > c_mask < (ncolmax - 1) ELSE cmask = (ncolmax -1)
146    z2d[maskind] = cmask
147  ENDIF
148  z2d = round(temporary(z2d))
149; use byte type to save memory
150  z2d = byte(temporary(z2d))
151;--------------------------------------------------------------
152; .
153;--------------------------------------------------------------
154  if NOT keyword_set(overplot) then reinitplt, /z, /invert
155  placedessin, 'plt', posplot, posbar, _extra = ex
156;--------------------------------------------------------------
157; 3) Drawing
158;--------------------------------------------------------------
159
160   xsize = !p.position[2] - !p.position[0]
161   ysize = !p.position[3] - !p.position[1]
162   IF !d.name EQ 'X' THEN BEGIN
163     xsize = ceil(xsize * !d.x_size)
164     ysize = ceil(ysize * !d.y_size)
165     z2d = congrid(z2d, xsize, ysize)
166   ENDIF
167
168   tv, z2d, !p.position[0], !p.position[1] $
169       , xsize = xsize, ysize = ysize $
170       , /normal, _EXTRA = ex
171
172;------------------------------------------------------------
173;  caption + display of these.
174;------------------------------------------------------------
175   axe, 'pltv', dtasize, _EXTRA = ex
176   legende, truemin, truemax, 'plt', DIREC = direc $
177            , INTERVALLE = float(max-min)/(topcol-bottom) $
178            , _extra = ex
179   plot, [0], [0], /noerase, /nodata, xstyle = 1, ystyle = 1
180
181   IF keyword_set(masked) THEN tracemask, msk, indgen(dtasize[0]), indgen(dtasize[1])
182;------------------------------------------------------------
183; color bar
184;------------------------------------------------------------
185   barrecouleur, 0, min,  max, 10, bottom = bottom, position = posbar, ncolors = (topcol-bottom+1), _extra = ex
186; 4) End of drawing
187   terminedessin, _extra=ex
188;
189  if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4pltv.dat'
190  if keyword_set(key_performance) NE 0 THEN print, 'time pltv', systime(1)-tempsun
191;
192   return
193end
Note: See TracBrowser for help on using the repository browser.