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

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

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

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