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

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

slight improve of pltv

  • Property svn:keywords set to Id
File size: 8.0 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=1}
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
34; <pro>domdef</pro> !
35;
36; @keyword C_NAN {default=!d.n_colors < 255}
37; The color number that should be used for the NaN values.
38;
39; @keyword C_MASK {default=0}
40; The color number that should be used for the mask values.
41;
42; @keyword INV
43; Reverse the color order
44;
45; @keyword MASKVAL {default=1.e+20}
46; The mask value. Note that if abs(mask) < 1.e6, then the
47; exact value of the mask is used to find the maskwd point.
48; if abs(mask) > 1.e6, the test to find the masked value is ge
49; abs(mask)/10. This is necessary to avoid the rounding errors
50;
51; @keyword NCOLORS {default=(d.n_colors < 256) - 1 - BOTTOM}
52; number of colors to be used.
53;
54; @keyword NOINTERP
55; Used this keyword if you don't want that the values
56; are interpolated from BOTTOM using NCOLORS colors.
57; This can be for example useful when working on byte type arrays.
58;
59; @keyword _EXTRA
60; Used to pass keywords to <pro>placedessin</pro>, <proidl>TV</proidl>,
61; <pro>axe</pro>, <pro>legende</pro>, <pro>barrecouleur</pro>,
62; <pro>terminedessin</pro>
63;
64; @examples
65; IDL> tvplus, dist(100)
66;
67; @history
68; Aug 2006: Sebastien Masson (smasson\@lodyc.jussieu.fr)
69;
70; @version
71; $Id$
72;
73;-
74;
75PRO pltv, data, min, max, BOTTOM = bottom, BOXZOOM = boxzoom $
76          , C_MASK = c_mask, C_NAN = c_nan, INV = inv,  MININ = minin, MAXIN = maxin $
77          , MASKVAL = maskval, NCOLORS = ncolors, NOINTERP = nointerp $
78          , _EXTRA = ex
79;
80  compile_opt idl2, strictarrsubs
81;
82  @cm_general ; for key_performance
83;--------------------------------------------------------------
84  tempsun = systime(1)          ; for key_performance
85;--------------------------------------------------------------
86;--------------------------------------------------------------
87; I2) Reading of the field and checkup.
88;--------------------------------------------------------------
89  IF n_elements(minin) NE 0 THEN min = minin
90  IF n_elements(maxin) NE 0 THEN max = maxin
91  IF size(data, /type) NE 8 THEN z2d = reform(float(data)) ELSE z2d = data
92  IF size(z2d, /n_dimensions) NE 2 then BEGIN
93    if keyword_set(boxzoom) then BEGIN
94      savedbox = 1b
95      saveboxparam, 'boxparam4pltv.dat'
96    ENDIF
97    z2d = checkfield(temporary(z2d), 'plt', TYPE = 'xy', direc = direc, BOXZOOM = boxzoom)
98    if n_elements(z2d) EQ 1 AND z2d[0] EQ -1 then BEGIN
99      IF keyword_set(savedbox) THEN restoreboxparam, 'boxparam4pltv.dat'
100      return
101    ENDIF
102  ENDIF
103  dtasize = size(z2d, /dimensions)
104;------------------------------------------------------------
105; def of ncolmax, bottom, topcol et ncolors
106;------------------------------------------------------------
107  ncolmax = !d.n_colors < 256
108  IF n_elements(bottom) EQ 0 THEN bottom = 1 ELSE bottom = 0 > bottom
109  IF NOT keyword_set(ncolors) then topcol = ncolmax - 2 ELSE topcol = (bottom + ncolors - 1) < (ncolmax - 1)
110  ncolors = topcol - bottom + 1
111;------------------------------------------------------------
112; Do we have NaN values in z2d???
113;------------------------------------------------------------
114  msknan = finite(z2d, /nan)
115  nan = total(msknan)
116  IF keyword_set(nan) THEN nanind = where(temporary(msknan) EQ 1)
117;------------------------------------------------------------
118; get the mask
119;------------------------------------------------------------
120  IF n_elements(maskval) EQ 0 THEN maskval = 1.e20
121  IF abs(maskval) LT 1e6 THEN BEGIN
122    IF keyword_set(nan) THEN z2d[nanind] = 1.e20
123    msk = z2d NE maskval
124  ENDIF ELSE BEGIN
125    IF keyword_set(nan) THEN z2d[nanind] = 0
126    msk = abs(z2d) LT abs(maskval)/10.
127  ENDELSE
128  maskind = where(msk EQ 0, masked)
129  IF keyword_set(nan) THEN z2d[nanind] = !values.f_nan
130;------------------------------------------------------------
131; get the real min/max and the user defined min/max of the array
132;------------------------------------------------------------
133  determineminmax, z2d, msk, truemin, truemax, MININ = min, MAXIN = max, NAN = nan
134  if n_elements(z2d) EQ 1 AND z2d[0] EQ -1 then BEGIN
135    IF keyword_set(savedbox) THEN restoreboxparam, 'boxparam4pltv.dat'
136    return
137  ENDIF
138  z2d = min > temporary(z2d) < max
139;------------------------------------------------------------
140; apply other keywords (nointerp, c_nan, c_mask)
141;------------------------------------------------------------
142  IF NOT keyword_set(nointerp) THEN BEGIN
143; interpolation between bottom and bottom+ncolors-1
144    m = 1.*(ncolors-1)/(max-min)
145    p = bottom - 1.*min*m
146    z2d = m * temporary(z2d) + p
147  ENDIF
148; set c_nan for NaN values
149  IF keyword_set(nan) THEN BEGIN
150    IF n_elements(c_nan) NE 0 THEN cnan = 0 > c_nan < (ncolmax -1) ELSE cnan = (ncolmax -1)
151    z2d[nanind] = cnan
152  ENDIF
153; c_mask for masked values
154  IF keyword_set(masked) THEN BEGIN
155    IF n_elements(c_mask) NE 0 THEN cmask = 0 > c_mask < (ncolmax - 1) ELSE cmask = (ncolmax -1)
156    z2d[maskind] = cmask
157  ENDIF
158; reverse colors (from topcol to bottom instead of bottom to topcol)
159  IF keyword_set(inv) THEN BEGIN
160    m = float(topcol   - bottom  )/float(bottom - topcol)
161    p = float(bottom^2 - topcol^2)/float(bottom - topcol)
162    z2d = m * temporary(z2d) + p
163  ENDIF
164; avoid rounding errors
165  z2d = round(temporary(z2d))
166; use byte type to save memory
167  z2d = byte(temporary(z2d))
168;--------------------------------------------------------------
169; .
170;--------------------------------------------------------------
171  if NOT keyword_set(overplot) then reinitplt, /z, /invert
172  placedessin, 'pltv', posplot, posbar, dtasize, _extra = ex
173;--------------------------------------------------------------
174; 3) Drawing
175;--------------------------------------------------------------
176
177   xsize = !p.position[2] - !p.position[0]
178   ysize = !p.position[3] - !p.position[1]
179   IF !d.name EQ 'X' THEN BEGIN
180     xsize = ceil(xsize * !d.x_size)
181     ysize = ceil(ysize * !d.y_size)
182     z2d = congrid(z2d, xsize, ysize)
183   ENDIF
184
185   tv, z2d, !p.position[0], !p.position[1] $
186       , xsize = xsize, ysize = ysize $
187       , /normal, _EXTRA = ex
188
189;------------------------------------------------------------
190;  caption + display of these.
191;------------------------------------------------------------
192   axe, 'pltv', dtasize, _EXTRA = ex
193   legende, truemin, truemax, 'plt', DIREC = direc $
194            , INTERVALLE = float(max-min)/(topcol-bottom) $
195            , _extra = ex
196   plot, [0], [0], /noerase, /nodata, xstyle = 1, ystyle = 1, _extra = ex
197
198   IF keyword_set(masked) THEN tracemask, msk, indgen(dtasize[0]), indgen(dtasize[1])
199;------------------------------------------------------------
200; color bar
201;------------------------------------------------------------
202   IF keyword_set(inv) THEN colors = topcol - bindgen(ncolors) ELSE colors = bottom + bindgen(ncolors)
203   barrecouleur, colors, min,  max, 10, position = posbar,  _extra = ex
204; 4) End of drawing
205   terminedessin, _extra=ex
206;
207  if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4pltv.dat'
208  if keyword_set(key_performance) NE 0 THEN print, 'time pltv', systime(1)-tempsun
209;
210   return
211end
Note: See TracBrowser for help on using the repository browser.