source: trunk/SRC/ToBeReviewed/TRIANGULATION/tracemask.pro @ 327

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

modification of headers : mainly blanks around = sign for keywords in declaration of function and pro

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.6 KB
Line 
1;+
2;
3; @file_comments
4; Draw contours of a mask
5;
6; @categories
7; Utilities
8;
9; @param MASKENTREE {in}{required}
10; 2d array specifying the mask
11;
12; @param XIN {in}{required}
13; 2d array specifying longitude coordinates.
14;
15; @param YIN {in}{required}
16; 2d array specifying latitude coordinates.
17;
18; @keyword COAST_COLOR {default=0}
19; The color of the coastline.
20; Default is black (0).
21;
22; @keyword COAST_THICK {default=1}
23; The thick of the trait to trace continents
24;
25; @keyword OVERPLOT
26; To do a plot over an other one.
27;
28; @keyword _EXTRA
29; Used to pass keywords
30;
31; @uses
32; common.pro
33;
34; @history
35; Sebastien Masson (smasson\@lodyc.jussieu.fr)
36;
37; @version
38; $Id$
39;
40;-
41PRO tracemask, maskentree, xin, yin $
42             , COAST_COLOR=coast_color, COAST_THICK=coast_thick $
43             , OVERPLOT=overplot, _EXTRA=ex
44;
45  compile_opt idl2, strictarrsubs
46;
47   if keyword_set(overplot) then return
48;---------------------------------------------------------
49@cm_general
50  IF NOT keyword_set(key_forgetold) THEN BEGIN
51@updatekwd
52  ENDIF
53;---------------------------------------------------------
54   tempsun = systime(1)         ; For key_performance
55; We avoid edging problems:
56   tempdeux = systime(1)        ; For key_performance =2
57   tailleentree = size(maskentree)
58   nx = tailleentree[1]+1
59   ny = tailleentree[2]+1
60; we check the input axis
61  IF n_elements(xin) EQ 0 THEN xentree = findgen(nx-1) ELSE xentree = xin
62  IF (size(xentree))[0] EQ 1 THEN xentree = xentree#replicate(1,ny-1)
63  IF n_elements(yin) EQ 0 THEN yentree = findgen(ny-1) ELSE yentree = yin
64  IF (size(yentree))[0] EQ 1 THEN yentree = replicate(1,nx-1)#yentree
65; We enlarge the mask by 1 column to the left an d1 line to the bottom
66   mask = intarr(tailleentree[1]+1, tailleentree[2]+1)
67   mask[1:tailleentree[1], 1:tailleentree[2]] = maskentree
68; The 2 first columns are identical.
69   mask[0, 1:tailleentree[2]] = maskentree[0, *]
70; The 2 first lines are identical.
71   mask[1:tailleentree[1], 0] = maskentree[*, 0]
72; We calculate the position following x of points which will serve to trace the mask. They are situated between each points of the mask, exept for the last column we can not calculate and so we put at max (!x.range).
73   xrange = !x.range[sort(!x.range)] ; if REVERSE_X is used
74   xentree = .5*(xentree+shift(xentree, -1, 0))
75   IF not keyword_set(overplot) THEN xentree[nx-2, *] = xrange[1] $
76   ELSE xentree[nx-2, *] = xentree[nx-3, *]
77; we sill
78   xentree = xrange[0] > xentree < xrange[1]
79; we enlarge the array
80   xf = fltarr(nx, ny)
81   xf[1:nx-1, 1:ny-1] = xentree
82   IF not keyword_set(overplot) THEN xf[0, *] = xrange[0] $
83   ELSE xf[0, *] = xf[1, *]
84   xf[1:nx-1, 0] = xentree[*, 0]
85;
86   yinverse = yentree[0, 0] GT yentree[0, ny-2]
87   yrange = !y.range[sort(!y.range)]
88   yentree = .5*(yentree+shift(yentree, 0, -1))
89   IF not keyword_set(overplot) THEN BEGIN
90      if yinverse then yentree[*, ny-2] = yrange[0] ELSE yentree[*, ny-2] = yrange[1]
91   ENDIF ELSE yentree[*, ny-2] = yentree[*, ny-3]
92   yentree = yrange[0] > yentree < yrange[1]
93   yf = fltarr(nx, ny)
94   yf[1:nx-1, 1:ny-1] = yentree
95   yf[0, 1:ny-1] = yentree[0, *]
96   IF not keyword_set(overplot) THEN BEGIN
97      if yinverse then yf[*, 0] = yrange[1] ELSE yf[*, 0] = yrange[0]
98   ENDIF ELSE yentree[*, 0] = yentree[*, 1]
99;
100   IF testvar(var = key_performance) EQ 2 THEN $
101    print, 'temps tracemask: determination du mask et de ses coordonnees', systime(1)-tempdeux
102;
103; We trace vertical segments:
104;
105   tempdeux = systime(1)        ; For key_performance =2
106   liste = where(mask+shift(mask, -1, 0) EQ 1)
107   IF liste[0] NE -1 THEN BEGIN
108; We recuperate lx and ly which are indexes in a 2d array of points given by list
109      ly = liste/nx & lx = temporary(liste)-nx*ly
110      indice = where(ly NE 0) ; We do not take points concerning
111; the first line because in this case, the point j-1 is not defined
112      if indice[0] NE -1 then begin
113         lx = lx[indice] & ly = ly[temporary(indice)]
114         IF testvar(var = key_performance) EQ 2 THEN $
115          print, 'temps tracemask: liste traits verticaux', systime(1)-tempdeux
116         tempdeux = systime(1)  ; For key_performance =2
117; loop on concerned points and drawing of the segment.
118; comments: we use plots instead of plot because plots is faster.
119         for pt = 0L, n_elements(lx)-1 do BEGIN
120            i = lx[pt] & j = ly[pt]
121            plots, [xf[i, j-1], xf[i, j]], [yf[i, j-1], yf[i, j]] $
122              , color = coast_color, thick = coast_thick, _extra = ex
123            if pt LT 5 then begin
124            endif
125         endfor
126         IF testvar(var = key_performance) EQ 2 THEN $
127          print, 'temps tracemask: trace traits verticaux', systime(1)-tempdeux
128      endif
129   ENDIF
130;
131; We trace horizontal segments:
132;
133   tempdeux = systime(1)        ; For key_performance =2
134   liste = where(mask+shift(mask, 0, -1) EQ 1)
135   IF liste[0] NE -1 THEN BEGIN
136      ly = liste/nx & lx = temporary(liste)-nx*ly
137      indice = where(lx NE 0)   ; We do not take point sof the first column.
138      if indice[0] EQ -1 then return
139      lx = lx[indice] & ly = ly[temporary(indice)]
140      IF testvar(var = key_performance) EQ 2 THEN $
141       print, 'temps tracemask: liste traits horizontaux', systime(1)-tempdeux
142      tempdeux = systime(1)     ; For key_performance =2
143      for pt = 0L, n_elements(lx)-1 do BEGIN
144         i = lx[pt] & j = ly[pt]
145         plots, [xf[i-1, j], xf[i, j]], [yf[i-1, j], yf[i, j]] $
146           , color = coast_color, thick = coast_thick, _extra = ex
147      endfor
148      IF testvar(var = key_performance) EQ 2 THEN $
149       print, 'temps tracemask: trace traits horizontaux', systime(1)-tempdeux
150   endif
151;
152;
153   if keyword_set(key_performance) THEN print, 'temps tracemask', systime(1)-tempsun
154
155   return
156end
157
158
159
160
161
Note: See TracBrowser for help on using the repository browser.