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

Last change on this file since 138 was 136, checked in by pinsard, 18 years ago

some improvements and corrections in some .pro file according to
aspell and idldoc log file

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