source: trunk/SRC/Interpolation/clickincell.pro @ 242

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

improvements/corrections of some *.pro headers + replace some message by some report

  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1;+
2;
3; @file_comments
4; click on a map and find in which cell the click was
5;
6; @categories
7; Grid
8;
9; @keyword CELLTYPE
10; = 'T', 'W', 'U', 'V' or 'F'
11; the type of point
12;     that is located in the center of the cell which the click is
13;     located. default is T type of cell (with corner defined by F
14;     points).
15;
16; @keyword DRAWCELL
17; to draw the cell in which we clicked
18;
19; @keyword COLOR
20; the color used to draw the cells (Clicking one more
21; time in the same cell will draw the cell with the white color)
22;
23; @keyword ORIGINAL
24; to get the position of the cell regarding the original
25; grid (with no key_shift, ixminmesh, iyminmesh...)
26;
27; @keyword IJ
28; see returns
29;
30; @keyword _EXTRA
31; Used to pass extra keywords to <pro>inquad</pro> and
32; <proidl>plot</proidl>
33; (when /drawcell)
34;
35; @returns
36; the index of the selected cells regarding to the grid which
37; is in memory in the variable of the common. If /ij keyword is
38; activated give 2D array (2, n) which are the i,j position of the
39; n selected cells.
40;
41; @uses
42; common.pro
43;
44; @examples
45; IDL> res = clickincell()
46;     Click with the left button to select a cell. Clicking one more
47;     time in the same cell remove the cell from the selection.
48;     Click on the right button to quit.
49;
50; IDL> plt, findgen(jpi,jpj),/nodata,map=[90,0,0],/ortho
51; IDL> print, clickincell(/draw,color=150,/xy)
52;
53; @history
54;      Sebastien Masson (smasson\@lodyc.jussieu.fr)
55;      August 2003
56;
57; @version
58; $Id$
59;
60;-
61;
62FUNCTION clickincell, CELLTYPE = celltype, DRAWCELL = drawcell, COLOR = color, ORIGINAL = original, IJ = ij, _EXTRA = extra
63;
64  compile_opt idl2, strictarrsubs
65;
66@common
67;
68; initialization
69  cellnum = -1L
70  selected = 0
71;
72; Cell list
73; get the grid parameter according to celltype
74  oldgrid = vargrid
75  IF NOT keyword_set(celltype) THEN celltype = 'T'
76  CASE strupcase(celltype) OF
77    'T':vargrid = 'F'
78    'W':vargrid = 'F'
79    'U':vargrid = 'V'
80    'V':vargrid = 'U'
81    'F':vargrid = 'T'
82  ENDCASE
83  grille, -1, glam, gphi, -1, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz
84  vargrid = oldgrid
85; define the corner of the cells in the clockwise direction
86  IF keyword_set(key_periodic) AND nx EQ jpi THEN BEGIN
87    x1 = glam[*, 0:ny-2]
88    y1 = gphi[*, 0:ny-2]
89    x2 = glam[*, 1:ny-1]
90    y2 = gphi[*, 1:ny-1]
91    x3 = shift(glam[*, 1:ny-1], -1, 0)
92    y3 = shift(gphi[*, 1:ny-1], -1, 0)
93    x4 = shift(glam[*, 0:ny-2], -1, 0)
94    y4 = shift(gphi[*, 0:ny-2], -1, 0)
95  ENDIF ELSE BEGIN
96    x1 = glam[0:nx-2, 0:ny-2]
97    y1 = gphi[0:nx-2, 0:ny-2]
98    x2 = glam[0:nx-2, 1:ny-1]
99    y2 = gphi[0:nx-2, 1:ny-1]
100    x3 = glam[1:nx-1, 1:ny-1]
101    y3 = gphi[1:nx-1, 1:ny-1]
102    x4 = glam[1:nx-1, 0:ny-2]
103    y4 = gphi[1:nx-1, 0:ny-2]
104  ENDELSE
105  glam = -1 ; free memory
106  gphi = -1 ; free memory
107;
108; get mousse position on the reference map
109  cursor, x, y, /data, /up
110;
111  while (!mouse.button ne 4) do BEGIN
112    IF finite(x)*finite(x) EQ 0 THEN GOTO, outwhile
113;
114    case !mouse.button of
115      1:BEGIN
116; What is the longitude?
117        WHILE x GT !x.range[1] DO x = x-360
118        WHILE x LT !x.range[0] DO x = x+360
119        IF x GT !x.range[1] THEN GOTO, outwhile
120        IF y GT !y.range[1] THEN GOTO, outwhile
121        IF y LT !y.range[0] THEN GOTO, outwhile
122;
123        cell = inquad(x, y, x1, y1, x2, y2, x3, y3, x4, y4 $
124                      , /onsphere, _extra = extra)
125;
126        IF cell[0] EQ -1 OR n_elements(cell) GT 1 THEN GOTO, outwhile
127        cell = cell[0]
128        already = (where(cellnum EQ cell))[0]
129        IF already EQ -1 THEN BEGIN
130          cellnum = [cellnum, cell]
131          selected = [selected, 1]
132          already = n_elements(selected)-1
133        ENDIF ELSE selected[already] = 1-selected[already]
134        IF keyword_set(drawcell) THEN BEGIN
135          oplot, [x1[cell], x2[cell], x3[cell], x4[cell], x1[cell]] $
136            , [y1[cell], y2[cell], y3[cell], y4[cell], y1[cell]] $
137            , color = color*selected[already] $
138            + (!d.n_colors < 255)*(1-selected[already]) $
139            , _extra = extra
140        ENDIF
141      END
142      2:                        ; middle button
143      ELSE:
144    ENDCASE
145; get mousse position on the reference map
146outwhile:
147    cursor, x, y, /data, /up
148  ENDWHILE
149;
150  good = where(selected NE 0)
151  IF good[0] EQ -1 THEN RETURN, -1
152;
153  cellnum = cellnum[good]
154;
155  yy = cellnum/(nx-1+key_periodic*(nx EQ jpi))
156  xx = cellnum MOD (nx-1+key_periodic*(nx EQ jpi))
157;
158  CASE strupcase(celltype) OF
159    'T':BEGIN
160      xx = xx+firstx+1
161      yy = yy+firsty+1
162    END
163    'W':BEGIN
164      xx = xx+firstx+1
165      yy = yy+firsty+1
166    END
167    'U':BEGIN
168      xx = xx+firstx
169      yy = yy+firsty+1
170    END
171    'V':BEGIN
172      xx = xx+firstx+1
173      yy = yy+firsty
174    END
175    'F':BEGIN
176      xx = xx+firstx
177      yy = yy+firsty
178    END
179  ENDCASE
180;
181  bad = where(xx GE jpi)
182  IF bad[0] NE -1 THEN BEGIN
183    xx[bad] = xx[bad]-jpi
184    yy[bad] = yy[bad]+1
185  ENDIF
186  bad = where(yy GE jpj)
187  IF bad[0] NE -1 THEN stop
188;
189  IF keyword_set(original) THEN BEGIN
190    xx = xx-key_shift
191    bad = where(xx LT 0)
192    IF bad[0] NE -1 THEN xx[bad] = xx[bad]+jpi
193    xx = xx MOD jpi
194    xx = xx +ixminmesh
195    yy = yy+iyminmesh
196  ENDIF
197;
198  ncell = n_elements(xx)
199  IF keyword_set(ij) THEN $
200    RETURN, [reform(xx, 1, ncell, /over) $
201             , reform(yy, 1, ncell, /over)]
202;
203  IF keyword_set(original) THEN RETURN, xx+jpiglo*yy $
204  ELSE RETURN, xx+jpi*yy
205END
Note: See TracBrowser for help on using the repository browser.