source: trunk/SRC/ToBeReviewed/PLOTS/DESSINE/tvplus.pro @ 327

Last change on this file since 327 was 327, checked in by pinsard, 17 years ago

modification of headers : mainly blanks around = sign for keywords in declaration of function and pro

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 12.0 KB
Line 
1;+
2;
3; @file_comments
4; Enhanced version of <proidl>TVSCL</proidl>
5;
6; @categories
7; quick exploration of 2D arrays
8;
9; @param Z2D {in}{required}
10; 2D array to visualize
11;
12; @param CELLSIZE {in}{optional}
13; This is the size (in pixel) of the square
14; representing 1 array element. By default, this size is computed
15; automatically in order that the size of the plotting window do
16; not exceed the screen size. If the user specify a large value
17; of cellsize that forces tvplus to create a window larger than
18; the screen, a "scrolling window" will be displayed instead of a
19; regular window. Unfortunately the nice functionalities of tvplus
20; are not coded for "scrolling window" case...
21;
22; @keyword BOTTOM {default=1}
23; The lowest color index of the colors to be used
24;
25; @keyword C_NAN {default=!d.n_colors < 255}
26; The color number that should be used for the NaN values.
27;
28; @keyword C_MASK {default=0}
29; The color number that should be used for the mask values.
30;
31; @keyword OFFSET
32; 2 elements vector used by tvplus itself when showing zoom.
33; It is used to shift the ranges of xaxis and yaxis.
34; For example: tvplus,sst[x1:x2,y1:y2],offset=[x1,y1]
35;
36; @keyword MASK
37; The mask value. Note that if abs(mask) < 1.e6, then the
38; exact value of the mask is used to find the maskwd point.
39; if abs(mask) > 1.e6, the test to find the masked value is ge
40; abs(mask)/10. This is necessary to avoid the rounding errors
41;
42; @keyword MIN
43; Scalar used to specify the min value to be drawn.
44;
45; @keyword MAX
46; Scalar used to specify the max value to be drawn.
47;
48; @keyword NCOLORS {default=(d.n_colors < 256) - 1 - bottom}
49; number of colors to be used.
50;
51; @keyword NOINTERP
52; Used this keyword if you don't want that the values
53; are interpolated from BOTTOM using NCOLORS colors.
54; This can be for example useful when working on byte type arrays.
55;
56; @keyword NOUSEINFOS
57; Activate to suppress the printed message explaining how to use tvplus
58;
59; @keyword WINDOW
60; Number of the window used to display the array values.
61; default is window number 0.
62;
63; @keyword _EXTRA
64; Used to pass keywords to <proidl>TV</proidl>,
65; <proidl>PLOT</proidl>,
66; <pro>colorbar</pro>
67;
68; @restrictions
69; use your mouse to scan the array values...
70;     left button  : mouse position and associated array value
71;     middle button: use it twice to define a zoom box
72;     right button : quit
73;
74; the nice functionalities of tvplus are not coded
75; for "scrolling window" case...
76;
77; @examples
78; IDL> tvplus, dist(100)
79;
80; @history
81; Sebastien Masson (smasson\@lodyc.jussieu.fr)
82;                       18/12/98
83; Aug 2005: quick cleaning + english
84;
85; @version
86; $Id$
87;
88;-
89PRO tvplus, z2d, cellsize $
90          , BOTTOM=bottom, C_MASK=c_mask, C_NAN=c_nan, WINDOW=window $
91          , MIN=min, MAX=max, MASK=mask, OFFSET=offset $
92          , NOUSEINFOS=NOUSEINFOS $
93          , NCOLORS=ncolors, NOINTERP=nointerp, _EXTRA=ex
94;
95  compile_opt idl2, strictarrsubs
96;
97  IF n_elements(z2d) EQ 0 THEN return
98  arr = reform(float(z2d))
99;------------------------------------------------------------
100; check the size of the input array
101;------------------------------------------------------------
102  if (size(arr))[0] NE 2 then begin
103    ras = report('Input array must have only 2 dimensions and not '+ strtrim(size(arr, /n_dimensions), 1))
104    return
105  endif
106;------------------------------------------------------------
107; def of ncolmax, bottom, topcol and ncolors
108;------------------------------------------------------------
109  ncolmax = !d.n_colors < 256
110  IF N_ELEMENTS(bottom) EQ 0 THEN bottom = 1
111  if NOT keyword_set(ncolors) then ncolors = ncolmax - 1 - bottom
112  topcol = (bottom+ncolors-1) < (ncolmax-1)
113;------------------------------------------------------------
114; get default values of !x, !y, !z
115;------------------------------------------------------------
116;   xenvsauve = !x & yenvsauve = !y & penvsauve = !p
117  reinitplt, /z, /invert
118;------------------------------------------------------------
119; Do we have NaN values in arr???
120;------------------------------------------------------------
121  nan = total(finite(z2d, /nan)) < 1
122  if keyword_set(nan) then begin
123    nanindex = where(finite(z2d, /nan) EQ 1)
124    arr[nanindex] = min(arr, /nan)
125  endif
126;------------------------------------------------------------
127; Compute the size (in pixel) of the square representing 1
128; point of the input array
129;------------------------------------------------------------
130  dimensions = GET_SCREEN_SIZE()
131  if n_elements(cellsize) EQ 0 then BEGIN
132    cellsize = min(floor(dimensions/(size(z2d))[1: 2]*.75))
133  ENDIF ELSE $
134; we need to use a scrolling bar window
135  if cellsize GE min(floor(dimensions/(size(z2d))[1: 2]*.75)) then scrolling = 1
136  if cellsize LT 1 then begin
137    cellsize = 1
138    scrolling = 1
139  endif
140;------------------------------------------------------------
141; Change the value of the masked value for the min of the non-masked values
142;------------------------------------------------------------
143  if n_elements(mask) then BEGIN
144    if abs(mask) LT 1e6 then BEGIN
145      masked = where(arr EQ mask)
146      if masked[0] NE -1 then arr[masked] = min(arr[where(arr NE mask)])
147    ENDIF ELSE BEGIN
148      masked = where(abs(arr) GE abs(mask)/10.)
149      if masked[0] NE -1 then arr[masked] = min(arr[where(abs(arr) LT abs(mask)/10.)])
150    ENDELSE
151  ENDIF ELSE masked = -1
152;------------------------------------------------------------
153; apply min/max keywords
154;------------------------------------------------------------
155  if n_elements(min) NE 0 then BEGIN
156    arr = min > arr
157    truemin = min
158  ENDIF ELSE truemin = min(arr)
159  if n_elements(max) NE 0 then BEGIN
160    arr = arr < max
161    truemax = max
162  ENDIF ELSE truemax = max(arr)
163;
164  IF truemin EQ truemax THEN BEGIN
165    dummy = report('constant value everywhere: '+ strtrim(truemin, 1))
166    return
167  ENDIF
168;------------------------------------------------------------
169; apply other keywords (nointerp, c_nan, c_mask)
170;------------------------------------------------------------
171  if NOT keyword_set(nointerp) then BEGIN
172; interpolation between bottom and bottom+ncolors-1
173    m = 1.*(ncolors-1)/(truemax-truemin)
174    p = bottom-1.*truemin*m
175    arr = round(m*temporary(arr)+p)
176  endif
177; set c_nan for NaN values
178  if keyword_set(nan) then begin
179    if n_elements(c_nan) NE 0 THEN arr[nanindex] = c_nan <  (ncolmax -1) $
180    ELSE arr[nanindex] = topcol
181  endif
182; c_mask for masked values
183  if n_elements(c_mask) NE 0 AND masked[0] NE -1 THEN $
184    arr[masked] = c_mask < (ncolmax -1)
185; use byte type to save memory
186  arr = byte(temporary(arr))
187; increase the size of the array in order to be displayed
188; with the suitable size
189  szarr = size(arr, /dimensions)
190  arr = congrid(temporary(arr), szarr[0]*cellsize, szarr[1]*cellsize)
191;------------------------------------------------------------
192; open a window with the correct size
193;------------------------------------------------------------
194  nx = (size(arr))[1]
195  ny = (size(arr))[2]
196; margin size (in pixel)
197  xyaspect = 1.*nx/ny
198  if xyaspect GE 1 THEN marginpix = 1.*[25, 25, 75, 25] ELSE marginpix = 1.*[25, 100, 25, 25]
199;
200  if n_elements(scrolling) EQ 0 then BEGIN ; open the regular window
201    if NOT keyword_set(window) then window = 0
202    window, window, xsize = nx+marginpix[0]+marginpix[1] $
203            , ysize = ny+marginpix[2]+marginpix[3]
204; for 24 bits colors, make sure that the background color is the good one...
205    if !d.n_colors gt 256 then BEGIN
206      device, decomposed = 1
207      !p.background = 'ffffff'x
208      plot, [0], [0], xstyle = 5, ystyle = 5
209      device, decomposed = 0
210    endif
211    tv, arr, marginpix[0], marginpix[2], _EXTRA = ex
212;
213; axis and plot frame
214;
215; get the normalized position of the tv (we just done above)
216; to know where the frame should be drawn
217    poscadre = fltarr(4)
218    poscadre[0] = marginpix[0]/!d.x_size
219    poscadre[2] = 1.-marginpix[1]/!d.x_size
220    poscadre[1] = marginpix[2]/!d.y_size
221    poscadre[3] = 1-marginpix[3]/!d.y_size
222; Use plot to draw the frame
223    if NOT keyword_set(offset) then offset = [0, 0]
224    !p.position = poscadre
225    plot, [0], [0], /nodata, /noerase, position = poscadre, color = 0 $
226          , xstyle = 1, ystyle = 1, xticklen = 1, yticklen = 1 $
227          , xrange = 1.*[0, nx]/cellsize-.5+offset[0] $
228          , yrange = 1.*[0, ny]/cellsize-.5+offset[1], _extra = ex
229    xenvsauve = !x & yenvsauve = !y & penvsauve = !p
230;
231; draw the colorbar
232;
233    IF truemin ne truemax THEN BEGIN
234      if xyaspect ge 1 then $
235        posbar = [25./!d.x_size, 25./!d.y_size, 1-25./!d.x_size, 50./!d.y_size] $
236        ELSE posbar = [1-75./!d.x_size, 25./!d.y_size, 1-50./!d.x_size, 1-25./!d.y_size]
237    if keyword_set(nointerp) then BEGIN & truemin = 0 & truemax = ncolmax & endif
238      colorbar, min = truemin, max = truemax, division = 10, cb_color = 0, position = posbar $
239                , vertical = xyaspect lt 1, /right, BOTTOM = bottom, NCOLORS = ncolors, _EXTRA = ex
240    ENDIF
241;      !p.position = poscadre
242  ENDIF ELSE BEGIN
243;------------------------------------------------------------
244; scrolling bar window case...
245;------------------------------------------------------------
246; for 24 bits colors, make sure that the background color is the good one...
247    if !d.n_colors gt 256 then begin
248      window, /pixmap
249      device, decomposed = 1
250      !p.background = 'ffffff'x
251      plot, [0], [0]
252      device, decomposed = 0
253    endif
254    slide_image, arr $          ; We draw it in a window with a scrolling bar
255                 , xsize = nx, ysize = ny $
256                 , xvisible = round(.7*dimensions[0]) < (size(arr))[1] $
257                 , yvisible = round(.7*dimensions[1]) < (size(arr))[2], /register, congrid = 0, show_full = 0
258    return
259  ENDELSE
260;------------------------------------------------------------
261; Use the mouse to get nice functionalities
262;------------------------------------------------------------
263; format to print the mouse position
264  CASE 1 OF
265    nx LT 10:fmt1 = '(i1)'
266    nx LT 100:fmt1 = '(i2)'
267    nx LT 1000:fmt1 = '(i3)'
268    nx LT 10000:fmt1 = '(i4)'
269    ELSE:fmt1 = ''
270  ENDCASE
271  CASE 1 OF
272    ny LT 10:fmt2 = '(i1)'
273    ny LT 100:fmt2 = '(i2)'
274    ny LT 1000:fmt2 = '(i3)'
275    ny LT 10000:fmt2 = '(i4)'
276    ELSE:fmt2 = ''
277  ENDCASE
278;
279  if NOT keyword_set(nouseinfos) then begin
280    print, 'left button  : mouse position and associated array value'
281    print, 'middle button: use it twice to define a zoom box'
282    print, 'right button : quit'
283  endif
284  cursor, x, y, /device, /down
285  x = x-marginpix[0] & x = 0 > floor(x/cellsize) < ((size(arr))[1]/cellsize-1)
286  y = y-marginpix[2] & y = 0 > floor(y/cellsize) < ((size(arr))[2]/cellsize-1)
287  while (!mouse.button ne 4) do BEGIN
288    case !mouse.button of
289      0:return
290      1:BEGIN                   ; get value
291        if x LE nx/cellsize AND y LE ny/cellsize then begin
292          print, '(x, y) = (' + string(x+offset[0], format = fmt1) $
293                 + ', ' + string(y+offset[1], format = fmt2) $
294                 + '), value = '+strtrim(float((reform(z2d))[x, y]), 1)
295        ENDIF
296        cursor, x, y, /device, /down
297        x = x-marginpix[0] & x = 0 > floor(x/cellsize) < ((size(arr))[1]/cellsize-1)
298        y = y-marginpix[2] & y = 0 > floor(y/cellsize) < ((size(arr))[2]/cellsize-1)
299      END
300      2:BEGIN                   ; zoom
301        cursor, x2, y2, /device, /down
302        x2 = x2-marginpix[0] & x2 =  0 > floor(x2/cellsize) < ((size(arr))[1]/cellsize-1)
303        y2 = y2-marginpix[2] & y2 =  0 > floor(y2/cellsize) < ((size(arr))[2]/cellsize-1)
304        x =  [x, x2] & x =  x[sort(x)]
305        y =  [y, y2] & y =  y[sort(y)]
306        IF keyword_set(OFFSET) THEN offset = [x[0], y[0]]+offset ELSE offset = [x[0], y[0]]
307        tvplus, z2d[x[0]:x[1], y[0]:y[1] ], WINDOW = window, MIN = min, MAX = max $
308                , MASK = mask, C_MASK = c_mask, C_NAN = c_nan, /NOUSEINFOS, OFFSET = OFFSET $
309                , NCOLORS = ncolors, NOINTERP = nointerp, BOTTOM = bottom, _EXTRA = ex
310        return
311      END
312      ELSE:
313    endcase
314  ENDWHILE
315;------------------------------------------------------------
316  !x = xenvsauve & !y = yenvsauve & !p = penvsauve
317  !x.range = 1.*[0, nx]/cellsize-.5+offset[0]
318  !y.range = 1.*[0, ny]/cellsize-.5+offset[1]
319;------------------------------------------------------------
320  return
321end
Note: See TracBrowser for help on using the repository browser.