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

Last change on this file since 72 was 69, checked in by smasson, 18 years ago

debug + new xxx

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