source: trunk/SRC/Grid/changemsk.pro @ 230

Last change on this file since 230 was 230, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;
5; @file_comments
6; add land points on a 2D land-sea mask
7;
8; @categories
9; Grid
10;
11; @param TAB {in}{required}
12; a 2D land-sea mask, with 1 on sea and 0 on land
13;
14; @keyword CELLSIZE
15; size (in pixel) of the square
16; representing one point of the mask
17;
18; @returns
19; newmsk the new 2D land-sea mask
20;
21; @examples
22; IDL> a = changemsk(tmask[*,*,0])
23;  to add ocean points
24; IDL> a = 1 - changemsk(1 - tmask[*,*,0])
25;
26; @history
27;      Sebastien Masson (smasson\@lodyc.jussieu.fr)
28;      June 2006
29;
30; @version
31; $Id$
32;
33;------------------------------------------------------------
34;------------------------------------------------------------
35;------------------------------------------------------------
36function changemsk,tab, CELLSIZE = cellsize
37;
38  compile_opt idl2, strictarrsubs
39;
40   newmsk = -1
41   taille = size(tab)
42   if taille[0] NE 2 then return, newmsk
43   newmsk=byte(tab)
44   if keyword_set(cellsize) THEN cellsize = long(cellsize) $
45   ELSE cellsize = long(2)
46   window,xsize=taille[1]*cellsize,ysize=taille[2]*cellsize
47   tvscl, congrid(newmsk, taille[1]*cellsize, taille[2]*cellsize)
48
49   if NOT keyword_set(nouseinfos) then begin
50    print, 'left button  : use it twice to define the diagonal of the rectangle to be set to 0 (land)'
51    print, 'middle button: put 0 (land) on the clicked point'
52    print, 'right button : quit'
53  endif
54
55  cursor,x1,y1,/device, /up
56   while (!mouse.button ne 4) do begin
57      case !mouse.button of
58         0:return, newmsk
59         1:BEGIN
60            cursor,x2,y2,/device, /up
61            x = [x1, x2]
62            x = x[sort(x)]
63            x = round(x/cellsize)
64            y = [y1, y2]
65            y = y[sort(y)]
66            y = round(y/cellsize)
67            newmsk[x[0]:x[1], y[0]:y[1] ] = 0
68            tvscl, replicate(0,(x[1]-x[0]+1)*cellsize $
69                             ,(y[1]-y[0]+1)*cellsize) $
70             ,x[0]*cellsize,y[0]*cellsize
71         end
72         2:BEGIN
73            x1 = round(x1/cellsize)
74            y1 = round(y1/cellsize)
75            newmsk[x1, y1] = 0
76            tvscl,replicate(0,cellsize,cellsize) $
77             ,x1*cellsize,y1*cellsize
78
79          END
80         ELSE:
81      endcase
82      cursor,x1,y1,/device, /up
83   endwhile
84
85   return, newmsk
86end
87
Note: See TracBrowser for help on using the repository browser.