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

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

header improvements + xxx doc

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