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

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