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

Last change on this file since 157 was 157, checked in by navarro, 18 years ago

header improvements + xxx doc

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