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

Last change on this file since 372 was 372, checked in by pinsard, 16 years ago

improvements of headers (alignments)

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