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