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

Last change on this file since 163 was 163, checked in by navarro, 18 years ago

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

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