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

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

typo

  • 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;-
41;
42PRO tracemask, maskentree, xin, yin, COAST_COLOR = coast_color, COAST_THICK = coast_thick, OVERPLOT = overplot, _EXTRA = ex
43;
44  compile_opt idl2, strictarrsubs
45;
46   if keyword_set(overplot) then return
47;---------------------------------------------------------
48@cm_general
49  IF NOT keyword_set(key_forgetold) THEN BEGIN
50@updatekwd
51  ENDIF
52;---------------------------------------------------------
53   tempsun = systime(1)         ; For key_performance
54; We avoid edging problems:
55   tempdeux = systime(1)        ; For key_performance =2
56   tailleentree = size(maskentree)
57   nx = tailleentree[1]+1
58   ny = tailleentree[2]+1
59; we check the input axis
60  IF n_elements(xin) EQ 0 THEN xentree = findgen(nx-1) ELSE xentree = xin
61  IF (size(xentree))[0] EQ 1 THEN xentree = xentree#replicate(1,ny-1)
62  IF n_elements(yin) EQ 0 THEN yentree = findgen(ny-1) ELSE yentree = yin
63  IF (size(yentree))[0] EQ 1 THEN yentree = replicate(1,nx-1)#yentree
64; We enlarge the mask by 1 column to the left an d1 line to the bottom
65   mask = intarr(tailleentree[1]+1, tailleentree[2]+1)
66   mask[1:tailleentree[1], 1:tailleentree[2]] = maskentree
67; The 2 first columns are identical.
68   mask[0, 1:tailleentree[2]] = maskentree[0, *]
69; The 2 first lines are identical.
70   mask[1:tailleentree[1], 0] = maskentree[*, 0]
71; 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).
72   xrange = !x.range[sort(!x.range)] ; if REVERSE_X is used
73   xentree = .5*(xentree+shift(xentree, -1, 0))
74   IF not keyword_set(overplot) THEN xentree[nx-2, *] = xrange[1] $
75   ELSE xentree[nx-2, *] = xentree[nx-3, *]
76; we sill
77   xentree = xrange[0] > xentree < xrange[1]
78; we enlarge the array
79   xf = fltarr(nx, ny)
80   xf[1:nx-1, 1:ny-1] = xentree
81   IF not keyword_set(overplot) THEN xf[0, *] = xrange[0] $
82   ELSE xf[0, *] = xf[1, *]
83   xf[1:nx-1, 0] = xentree[*, 0]
84;
85   yinverse = yentree[0, 0] GT yentree[0, ny-2]
86   yrange = !y.range[sort(!y.range)]
87   yentree = .5*(yentree+shift(yentree, 0, -1))
88   IF not keyword_set(overplot) THEN BEGIN
89      if yinverse then yentree[*, ny-2] = yrange[0] ELSE yentree[*, ny-2] = yrange[1]
90   ENDIF ELSE yentree[*, ny-2] = yentree[*, ny-3]
91   yentree = yrange[0] > yentree < yrange[1]
92   yf = fltarr(nx, ny)
93   yf[1:nx-1, 1:ny-1] = yentree
94   yf[0, 1:ny-1] = yentree[0, *]
95   IF not keyword_set(overplot) THEN BEGIN
96      if yinverse then yf[*, 0] = yrange[1] ELSE yf[*, 0] = yrange[0]
97   ENDIF ELSE yentree[*, 0] = yentree[*, 1]
98;
99   IF testvar(var = key_performance) EQ 2 THEN $
100    print, 'temps tracemask: determination du mask et de ses coordonnees', systime(1)-tempdeux
101;
102; We trace vertical segments:
103;
104   tempdeux = systime(1)        ; For key_performance =2
105   liste = where(mask+shift(mask, -1, 0) EQ 1)
106   IF liste[0] NE -1 THEN BEGIN
107; We recuperate lx and ly which are indexes in a 2d array of points given by list
108      ly = liste/nx & lx = temporary(liste)-nx*ly
109      indice = where(ly NE 0) ; We do not take points concerning
110; the first line because in this case, the point j-1 is not defined
111      if indice[0] NE -1 then begin
112         lx = lx[indice] & ly = ly[temporary(indice)]
113         IF testvar(var = key_performance) EQ 2 THEN $
114          print, 'temps tracemask: liste traits verticaux', systime(1)-tempdeux
115         tempdeux = systime(1)  ; For key_performance =2
116; loop on concerned points and drawing of the segment.
117; comments: we use plots instead of plot because plots is faster.
118         for pt = 0L, n_elements(lx)-1 do BEGIN
119            i = lx[pt] & j = ly[pt]
120            plots, [xf[i, j-1], xf[i, j]], [yf[i, j-1], yf[i, j]] $
121              , color = coast_color, thick = coast_thick, _extra = ex
122            if pt LT 5 then begin
123            endif
124         endfor
125         IF testvar(var = key_performance) EQ 2 THEN $
126          print, 'temps tracemask: trace traits verticaux', systime(1)-tempdeux
127      endif
128   ENDIF
129;
130; We trace horizontal segments:
131;
132   tempdeux = systime(1)        ; For key_performance =2
133   liste = where(mask+shift(mask, 0, -1) EQ 1)
134   IF liste[0] NE -1 THEN BEGIN
135      ly = liste/nx & lx = temporary(liste)-nx*ly
136      indice = where(lx NE 0)   ; We do not take point sof the first column.
137      if indice[0] EQ -1 then return
138      lx = lx[indice] & ly = ly[temporary(indice)]
139      IF testvar(var = key_performance) EQ 2 THEN $
140       print, 'temps tracemask: liste traits horizontaux', systime(1)-tempdeux
141      tempdeux = systime(1)     ; For key_performance =2
142      for pt = 0L, n_elements(lx)-1 do BEGIN
143         i = lx[pt] & j = ly[pt]
144         plots, [xf[i-1, j], xf[i, j]], [yf[i-1, j], yf[i, j]] $
145           , color = coast_color, thick = coast_thick, _extra = ex
146      endfor
147      IF testvar(var = key_performance) EQ 2 THEN $
148       print, 'temps tracemask: trace traits horizontaux', systime(1)-tempdeux
149   endif
150;
151;
152   if keyword_set(key_performance) THEN print, 'temps tracemask', systime(1)-tempsun
153
154   return
155end
156
157
158
159
160
Note: See TracBrowser for help on using the repository browser.