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

Last change on this file since 378 was 378, checked in by pinsard, 16 years ago

improvements of headers (typo, links, paragraphes, etc)

  • Property svn:keywords set to Id
File size: 7.9 KB
Line 
1;+
2;
3; @file_comments
4; Draw 2d plots with TV procedure
5;
6; @categories
7; find a file
8; graphic
9;
10; @param DATA {in}{required}
11; The field we want to display can be:
12;    1) an array. If the array is not a 2D array, its mean along
13;       the z and t direction will be automatically performed
14;       (as it is done in plt).
15;    2) a structure respecting all criterions specified by
16;       <pro>litchamp</pro>
17;
18; @param MIN {in}{optional}{default=min of DATA (on non-masked points)}
19;
20; @param MAX {in}{optional}{default=max of DATA (on non-masked points)}
21;
22; @keyword BOTTOM {default=1}
23; The lowest color index of the colors to be used.
24;
25; @keyword BOXZOOM
26; Vector indicating the geographic zone on which we want to cut the map.
27;  If BOXZOOM has :
28; 1 element : The extraction is made on [lon1, lon2, lat1, lat2, 0.,boxzoom[0]]
29; 2 elements: The extraction is made on [lon1, lon2, lat1, lat2, boxzoom[0],boxzoom[1]]
30; 4 elements: The extraction is made on [Boxzoom, 0, max([gdept, gdepw])]
31; 5 elements: The extraction is made on [Boxzoom[0:3], 0, Boxzoom[4]]
32; 6 elements: The extraction is made on Boxzoom
33;
34; Where lon1, lon2, lat1, lat2 are global variables defined at the last
35; <pro>domdef</pro> !
36;
37; @keyword C_NAN {default=!d.n_colors < 255}
38; The color number that should be used for the NaN values.
39;
40; @keyword C_MASK {default=0}
41; The color number that should be used for the mask values.
42;
43; @keyword INV
44; Reverse the color order
45;
46; @keyword MASKVAL {default=1.e+20}
47; The mask value. Note that if abs(mask) < 1.e6, then the
48; exact value of the mask is used to find the maskwd point.
49; if abs(mask) > 1.e6, the test to find the masked value is ge
50; abs(mask)/10. This is necessary to avoid the rounding errors
51;
52; @keyword NCOLORS {default=(d.n_colors < 256) - 1 - BOTTOM}
53; number of colors to be used.
54;
55; @keyword NOINTERP
56; Used this keyword if you don't want that the values
57; are interpolated from BOTTOM using NCOLORS colors.
58; This can be for example useful when working on byte type arrays.
59;
60; @keyword _EXTRA
61; Used to pass keywords to <pro>placedessin</pro>, <proidl>TV</proidl>,
62; <pro>axe</pro>, <pro>legende</pro>, <pro>barrecouleur</pro>,
63; <pro>terminedessin</pro>
64;
65; @examples
66;   IDL> tvplus, dist(100)
67;
68; @history
69; Aug 2006: Sebastien Masson (smasson\@lodyc.jussieu.fr)
70;
71; @version
72; $Id$
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.