source: trunk/SRC/ToBeReviewed/CALCULS/remplit.pro @ 226

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

corrections of some misspellings in some *.pro

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.2 KB
Line 
1;+
2; @file_comments
3;
4;
5; @categories
6;
7;
8; @param ZINPUT
9;
10;
11; @keyword NAN
12;
13;
14; @keyword NITER
15;
16;
17; @keyword BASIQUE
18;
19;
20; @keyword MASK
21;
22;
23; @keyword FILLXDIR
24;
25;
26; @keyword FILLYDIR
27;
28;
29; @keyword FILLVAL
30;
31;
32; @keyword _EXTRA
33; Used to pass your keywords
34;
35; @returns
36;
37;
38; @uses
39;
40;
41; @restrictions
42;
43;
44; @examples
45;
46;
47; @history
48;
49;
50; @version
51; $Id$
52;
53;;
54;; Extrapole zinout[jpi,jpj] sur les continents en utilisant les 4
55;; plus proches voisins masques oceaniquement et construit un nouveau masque
56;; contenant l'ancien masque oceanique PLUS les points extrapoles.
57;; Reitere le processus niter fois.
58;; C'est pas clair, essayez !
59;;
60;;
61;
62;    /Nan: to fill the point which have the value
63;    !values.f_nan. Without this keyword, these point are not filling
64;    and stays at !values.f_nan.
65;
66;
67; @todo seb
68;
69;-
70FUNCTION remplit, zinput, NAN = nan, NITER = niter, BASIQUE = basique, mask = mask, FILLXDIR = fillxdir, FILLYDIR = fillydir, FILLVAL = fillval, _extra = ex
71;
72  compile_opt idl2, strictarrsubs
73;
74@common
75  tempsun = systime(1)          ; pour key_performance
76; les points non remplis sont masques a valmask
77  IF n_elements(niter) EQ 0 THEN niter = 1
78  IF niter EQ 0 THEN return, zinput
79  z = zinput
80  if n_elements(key_gridtype) EQ 0 then key_gridtype = 'c'
81  oldkey_gridtype = key_gridtype
82; keep only the first letter of the grid type
83  key_gridtype = strmid(key_gridtype, 0, 1)
84  if keyword_set(basique) then begin
85    key_gridtype = 'c'
86    nx = (size(zinput))[1]
87    ny = (size(zinput))[2]
88    if NOT keyword_set(mask) then mmmask = basique ELSE mmmask = mask
89  ENDIF ELSE grille, mmmask, glam, gphi, gdep, nx, ny, nz, _extra = ex
90  if keyword_set(mask) then mmmask = mask
91;---------------------------------------------------------------
92  if (size(mmmask))[0] EQ 3 THEN mmmask = mmmask[*, *, 0]
93;
94  if n_elements(mmmask) EQ 1 then mmmask = replicate(1b, nx, ny)
95  if keyword_set(nan) then begin
96    nanpoint = where(finite(z) EQ 0)
97    if nanpoint[0] NE -1 then begin
98      mmmask[nanpoint] = 0b
99      z[nanpoint] = 0
100    endif
101  ENDIF
102  mmmask = byte(mmmask)
103;---------------------------------------------------------------
104; on ajoute un cadre de zero a z, mask, e1, e2
105; comme ca apres on peut faire des shifts ds tous les sens sans se
106; soucier des bords du domaine!
107;---------------------------------------------------------------
108  tempdeux = systime(1)         ; pour key_performance =2
109  nx2 = nx+2
110  case key_gridtype of
111    'c':BEGIN
112      ztmp = bytarr(nx+2, ny+2)
113      ztmp[1:nx, 1:ny] = mmmask
114      mmmask = temporary(ztmp)
115      ztmp = fltarr(nx+2, ny+2)
116      ztmp[1:nx, 1:ny] = z
117      if keyword_set(key_periodic) AND nx EQ jpi then begin
118        ztmp[0, 1:ny] = z[jpi-1, *]
119        ztmp[nx+1, 1:ny] = z[0, *]
120      endif
121      z = temporary(ztmp)
122    END
123    'e':BEGIN
124      ztmp = bytarr(nx+2, ny+4)
125      ztmp[1:nx, 2:ny+1] = mmmask
126      mmmask = temporary(ztmp)
127      ztmp = fltarr(nx+2, ny+4)
128      ztmp[1:nx, 2:ny+1] = z
129      if keyword_set(key_periodic) AND nx EQ jpi then begin
130        ztmp[0, 2:ny+1] = z[jpi-1, *]
131        ztmp[nx+1, 2:ny+1] = z[0, *]
132      endif
133      z = temporary(ztmp)
134    END
135  endcase
136  IF testvar(var = key_performance) EQ 2 THEN $
137    print, 'temps remplit: on ajoute un cadre de zero ', systime(1)-tempdeux
138;---------------------------------------------------------------
139;---------------------------------------------------------------
140; iteration
141;---------------------------------------------------------------
142;---------------------------------------------------------------
143  FOR n = 1, niter DO BEGIN
144; on trouve les points coast
145    tempdeux = systime(1)       ; pour key_performance =2
146; les points du bord du cadre ne doivent pas etre selectionnes comme
147; la coast
148    case key_gridtype of
149      'c':BEGIN
150        mmmask[0, *] = 1b
151        mmmask[nx+1, *] = 1b
152        mmmask[*, 0] = 1b
153        mmmask[*, ny+1] = 1b
154      END
155      'e':BEGIN
156        mmmask[0, *] = 1b
157        mmmask[nx+1, *] = 1b
158        mmmask[*, 0:1] = 1b
159        mmmask[*, ny+2:ny+3] = 1b
160      END
161    endcase
162; liste des points terre restant
163    IF keyword_set(fillxdir) THEN BEGIN
164; we stop if all the lines, that contains data, have been filled
165      test = total(mmmask[1:nx, *], 1)
166      IF total((test EQ 0)+(test EQ nx)) EQ ny+2 THEN GOTO, fini
167    ENDIF
168    IF keyword_set(fillydir) THEN BEGIN
169; we stop if all the columns, that contains data, have been filled
170      test = total(mmmask[*, 1:ny], 2)
171      IF total((test EQ 0)+(test EQ ny)) EQ nx+2 THEN GOTO, fini
172    ENDIF
173    land = where(mmmask EQ 0)
174    if land[0] EQ -1 then GOTO, fini
175; les points du bord du cadre doivent maintenant etre dans la terre
176    case key_gridtype of
177      'c':BEGIN
178        mmmask[0, *] = 0b
179        mmmask[nx+1, *] = 0b
180        mmmask[*, 0] = 0b
181        mmmask[*, ny+1] = 0b
182      END
183      'e':BEGIN
184        mmmask[0, *] = 0b
185        mmmask[nx+1, *] = 0b
186        mmmask[*, 0:1] = 0b
187        mmmask[*, ny+2:ny+3] = 0b
188      END
189    endcase
190    if keyword_set(key_periodic) AND nx EQ jpi then begin
191      mmmask[0, *] = mmmask[nx, *]
192      mmmask[nx+1, *] = mmmask[1, *]
193    endif
194; liste des voisins mer
195    case key_gridtype of
196      'c':BEGIN
197        CASE 1 OF
198          keyword_set(fillxdir):weight = mmmask[1+land]+mmmask[-1+land]
199          keyword_set(fillydir):weight = mmmask[nx2+land]+mmmask[-nx2+land]
200          ELSE:weight = mmmask[1+land]+mmmask[-1+land]+mmmask[nx2+land]+mmmask[-nx2+land] $
201            +1./sqrt(2)*(mmmask[nx2+1+land]+mmmask[nx2-1+land] $
202                         +mmmask[-nx2+1+land]+mmmask[-nx2-1+land])
203        ENDCASE
204      END
205      'e':BEGIN
206        shifted = glam[0, 0] LT glam[0, 1]
207        oddeven = (land/nx2+1-shifted) MOD 2
208        weight = mmmask[1+land]+mmmask[-1+land] $
209          +mmmask[2*nx2+land]+mmmask[-2*nx2+land] $
210          +sqrt(2)*(mmmask[-nx2+oddeven+land]+mmmask[-nx2-1+oddeven+land] $
211                    +mmmask[nx2+oddeven+land]+mmmask[nx2-1+oddeven+land])
212      END
213    endcase
214
215    ok = where(weight GT 0)
216    weight = weight[ok]
217    coast = land[temporary(ok)]
218;
219    IF testvar(var = key_performance) EQ 2 THEN $
220      print, 'temps remplit: trouver la coast ', systime(1)-tempdeux
221;---------------------------------------------------------------
222; remplissage des points coast
223;---------------------------------------------------------------
224    tempdeux = systime(1)       ; pour key_performance =2
225; on masque z
226    z = temporary(z)*mmmask
227;
228    case key_gridtype of
229      'c':BEGIN
230        CASE 1 OF
231          keyword_set(fillxdir):zcoast = z[1+coast]+z[-1+coast]
232          keyword_set(fillydir):zcoast = z[nx2+coast]+z[-nx2+coast]
233          ELSE:zcoast = z[1+coast]+z[-1+coast]+z[nx2+coast]+z[-nx2+coast] $
234            +1./sqrt(2)*(z[nx2+1+coast]+z[nx2-1+coast] $
235                         +z[-nx2+1+coast]+z[-nx2-1+coast])
236        ENDCASE
237      END
238      'e':BEGIN
239        oddeven = (coast/nx2+1-shifted) MOD 2
240        zcoast = z[1+coast]+z[-1+coast]+z[2*nx2+coast]+z[-2*nx2+coast] $
241          +sqrt(2)*(z[-nx2+oddeven+coast]+z[-nx2-1+oddeven+coast] $
242                    +z[nx2+oddeven+coast]+z[nx2-1+oddeven+coast])
243      END
244    endcase
245;
246    z[coast] =  temporary(zcoast)/ temporary(weight)
247; we update the the boundary conditions of z
248    if keyword_set(key_periodic) AND nx EQ jpi then begin
249      z[0, *] = z[nx, *]
250      z[nx+1, *] = z[1, *]
251    endif
252;---------------------------------------------------------------
253; IV) on reduit le masque
254;---------------------------------------------------------------
255    mmmask[ temporary(coast)] = 1
256;
257    IF testvar(var = key_performance) EQ 2 THEN $
258      print, 'temps remplit: une iteration ', systime(1)-tempdeux
259  ENDFOR
260fini:
261;
262; on masque les valeurs sur les lands restantes
263;
264  IF n_elements(valmask) EQ 0 then valmask = 1e20
265  IF n_elements(fillval) EQ 0 THEN fillval = valmask
266  z = temporary(z)*mmmask + fillval*(1b-mmmask)
267;---------------------------------------------------------------
268; on redecoupe le tableau pour retirer le cadre!
269;---------------------------------------------------------------
270  case key_gridtype of
271    'c':BEGIN
272      z = z[1:nx, 1:ny]
273    END
274    'e':BEGIN
275      z = z[1:nx, 2:ny+1]
276    END
277  endcase
278;
279  key_gridtype = oldkey_gridtype
280;---------------------------------------------------------------
281  if keyword_set(key_performance) THEN print, 'temps remplit', systime(1)-tempsun
282  return, z
283END
284
Note: See TracBrowser for help on using the repository browser.