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

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

modification of some headers (+some corrections) to prepare usage of the new idldoc

  • 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;-
61FUNCTION clickincell, CELLTYPE = celltype, DRAWCELL = drawcell, COLOR = color, ORIGINAL = original, IJ = ij, _EXTRA = extra
62;
63  compile_opt idl2, strictarrsubs
64;
65@common
66;
67; initialization
68  cellnum = -1L
69  selected = 0
70;
71; Cell list
72; get the grid parameter according to celltype
73  oldgrid = vargrid
74  IF NOT keyword_set(celltype) THEN celltype = 'T'
75  CASE strupcase(celltype) OF
76    'T':vargrid = 'F'
77    'W':vargrid = 'F'
78    'U':vargrid = 'V'
79    'V':vargrid = 'U'
80    'F':vargrid = 'T'
81  ENDCASE
82  grille, -1, glam, gphi, -1, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz
83  vargrid = oldgrid
84; define the corner of the cells in the clockwise direction
85  IF keyword_set(key_periodic) AND nx EQ jpi THEN BEGIN
86    x1 = glam[*, 0:ny-2]
87    y1 = gphi[*, 0:ny-2]
88    x2 = glam[*, 1:ny-1]
89    y2 = gphi[*, 1:ny-1]
90    x3 = shift(glam[*, 1:ny-1], -1, 0)
91    y3 = shift(gphi[*, 1:ny-1], -1, 0)
92    x4 = shift(glam[*, 0:ny-2], -1, 0)
93    y4 = shift(gphi[*, 0:ny-2], -1, 0)
94  ENDIF ELSE BEGIN
95    x1 = glam[0:nx-2, 0:ny-2]
96    y1 = gphi[0:nx-2, 0:ny-2]
97    x2 = glam[0:nx-2, 1:ny-1]
98    y2 = gphi[0:nx-2, 1:ny-1]
99    x3 = glam[1:nx-1, 1:ny-1]
100    y3 = gphi[1:nx-1, 1:ny-1]
101    x4 = glam[1:nx-1, 0:ny-2]
102    y4 = gphi[1:nx-1, 0:ny-2]
103  ENDELSE
104  glam = -1 ; free memory
105  gphi = -1 ; free memory
106;
107; get mousse position on the reference map
108  cursor, x, y, /data, /up
109;
110  while (!mouse.button ne 4) do BEGIN
111    IF finite(x)*finite(x) EQ 0 THEN GOTO, outwhile
112;
113    case !mouse.button of
114      1:BEGIN
115; What is the longitude?
116        WHILE x GT !x.range[1] DO x = x-360
117        WHILE x LT !x.range[0] DO x = x+360
118        IF x GT !x.range[1] THEN GOTO, outwhile
119        IF y GT !y.range[1] THEN GOTO, outwhile
120        IF y LT !y.range[0] THEN GOTO, outwhile
121;
122        cell = inquad(x, y, x1, y1, x2, y2, x3, y3, x4, y4 $
123                      , /onsphere, _extra = extra)
124;
125        IF cell[0] EQ -1 OR n_elements(cell) GT 1 THEN GOTO, outwhile
126        cell = cell[0]
127        already = (where(cellnum EQ cell))[0]
128        IF already EQ -1 THEN BEGIN
129          cellnum = [cellnum, cell]
130          selected = [selected, 1]
131          already = n_elements(selected)-1
132        ENDIF ELSE selected[already] = 1-selected[already]
133        IF keyword_set(drawcell) THEN BEGIN
134          oplot, [x1[cell], x2[cell], x3[cell], x4[cell], x1[cell]] $
135            , [y1[cell], y2[cell], y3[cell], y4[cell], y1[cell]] $
136            , color = color*selected[already] $
137            + (!d.n_colors < 255)*(1-selected[already]) $
138            , _extra = extra
139        ENDIF
140      END
141      2:                        ; middle button
142      ELSE:
143    ENDCASE
144; get mousse position on the reference map
145outwhile:
146    cursor, x, y, /data, /up
147  ENDWHILE
148;
149  good = where(selected NE 0)
150  IF good[0] EQ -1 THEN RETURN, -1
151;
152  cellnum = cellnum[good]
153;
154  yy = cellnum/(nx-1+key_periodic*(nx EQ jpi))
155  xx = cellnum MOD (nx-1+key_periodic*(nx EQ jpi))
156;
157  CASE strupcase(celltype) OF
158    'T':BEGIN
159      xx = xx+firstx+1
160      yy = yy+firsty+1
161    END
162    'W':BEGIN
163      xx = xx+firstx+1
164      yy = yy+firsty+1
165    END
166    'U':BEGIN
167      xx = xx+firstx
168      yy = yy+firsty+1
169    END
170    'V':BEGIN
171      xx = xx+firstx+1
172      yy = yy+firsty
173    END
174    'F':BEGIN
175      xx = xx+firstx
176      yy = yy+firsty
177    END
178  ENDCASE
179;
180  bad = where(xx GE jpi)
181  IF bad[0] NE -1 THEN BEGIN
182    xx[bad] = xx[bad]-jpi
183    yy[bad] = yy[bad]+1
184  ENDIF
185  bad = where(yy GE jpj)
186  IF bad[0] NE -1 THEN stop
187;
188  IF keyword_set(original) THEN BEGIN
189    xx = xx-key_shift
190    bad = where(xx LT 0)
191    IF bad[0] NE -1 THEN xx[bad] = xx[bad]+jpi
192    xx = xx MOD jpi
193    xx = xx +ixminmesh
194    yy = yy+iyminmesh
195  ENDIF
196;
197  ncell = n_elements(xx)
198  IF keyword_set(ij) THEN $
199    RETURN, [reform(xx, 1, ncell, /over) $
200             , reform(yy, 1, ncell, /over)]
201;
202  IF keyword_set(original) THEN RETURN, xx+jpiglo*yy $
203  ELSE RETURN, xx+jpi*yy
204END
Note: See TracBrowser for help on using the repository browser.