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

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

improvements of headers (alignments of IDL prompt in examples)

  • Property svn:keywords set to Id
File size: 2.0 KB
RevLine 
[231]1;+
[232]2;
[230]3; @file_comments
4; add land points on a 2D land-sea mask
[119]5;
[231]6; @categories
[157]7; Grid
[119]8;
[231]9; @param TAB {in}{required}
[230]10; a 2D land-sea mask, with 1 on sea and 0 on land
[119]11;
[231]12; @keyword CELLSIZE
[163]13; size (in pixel) of the square
14; representing one point of the mask
[119]15;
[231]16; @returns
[238]17; the new 2D land-sea mask
[119]18;
[124]19; @examples
[371]20;
21;   IDL> a = changemsk(tmask[*,*,0])
22;
[119]23;  to add ocean points
[371]24;   IDL> a = 1 - changemsk(1 - tmask[*,*,0])
[119]25;
26; @history
27;      Sebastien Masson (smasson\@lodyc.jussieu.fr)
28;      June 2006
29;
[231]30; @version
[157]31; $Id$
[119]32;
[231]33;-
[327]34FUNCTION changemsk,tab, CELLSIZE=cellsize
[119]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
[152]45   tvscl, congrid(newmsk, taille[1]*cellsize, taille[2]*cellsize)
[119]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
Note: See TracBrowser for help on using the repository browser.