source: trunk/Interpolation/clickincell.pro @ 59

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

upgrade of Interpolation according to cerbere.lodyc.jussieu.fr: /usr/home/smasson/SAXO_RD/

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