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

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

start to modify headers of Interpolation *.pro files for better idldoc output

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