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

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

modification of some headers (+some corrections) to prepare usage of the new idldoc

  • 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, BASIQUE = basique, MASK = mask, FILLXDIR = fillxdir, FILLYDIR = fillydir, FILLVAL = fillval, _EXTRA = ex
56;
57  compile_opt idl2, strictarrsubs
58;
59@common
60  tempsun = systime(1)          ; pour key_performance
61; les points non remplis sont masques a valmask
62  IF n_elements(niter) EQ 0 THEN niter = 1
63  IF niter EQ 0 THEN return, zinput
64  z = zinput
65  if n_elements(key_gridtype) EQ 0 then key_gridtype = 'c'
66  oldkey_gridtype = key_gridtype
67; keep only the first letter of the grid type
68  key_gridtype = strmid(key_gridtype, 0, 1)
69  if keyword_set(basique) then begin
70    key_gridtype = 'c'
71    nx = (size(zinput))[1]
72    ny = (size(zinput))[2]
73    if NOT keyword_set(mask) then mmmask = basique ELSE mmmask = mask
74  ENDIF ELSE grille, mmmask, glam, gphi, gdep, nx, ny, nz, _extra = ex
75  if keyword_set(mask) then mmmask = mask
76;---------------------------------------------------------------
77  if (size(mmmask))[0] EQ 3 THEN mmmask = mmmask[*, *, 0]
78;
79  if n_elements(mmmask) EQ 1 then mmmask = replicate(1b, nx, ny)
80  if keyword_set(nan) then begin
81    nanpoint = where(finite(z) EQ 0)
82    if nanpoint[0] NE -1 then begin
83      mmmask[nanpoint] = 0b
84      z[nanpoint] = 0
85    endif
86  ENDIF
87  mmmask = byte(mmmask)
88;---------------------------------------------------------------
89; on ajoute un cadre de zero a z, mask, e1, e2
90; comme ca apres on peut faire des shifts ds tous les sens sans se
91; soucier des bords du domaine!
92;---------------------------------------------------------------
93  tempdeux = systime(1)         ; pour key_performance =2
94  nx2 = nx+2
95  case key_gridtype of
96    'c':BEGIN
97      ztmp = bytarr(nx+2, ny+2)
98      ztmp[1:nx, 1:ny] = mmmask
99      mmmask = temporary(ztmp)
100      ztmp = fltarr(nx+2, ny+2)
101      ztmp[1:nx, 1:ny] = z
102      if keyword_set(key_periodic) AND nx EQ jpi then begin
103        ztmp[0, 1:ny] = z[jpi-1, *]
104        ztmp[nx+1, 1:ny] = z[0, *]
105      endif
106      z = temporary(ztmp)
107    END
108    'e':BEGIN
109      ztmp = bytarr(nx+2, ny+4)
110      ztmp[1:nx, 2:ny+1] = mmmask
111      mmmask = temporary(ztmp)
112      ztmp = fltarr(nx+2, ny+4)
113      ztmp[1:nx, 2:ny+1] = z
114      if keyword_set(key_periodic) AND nx EQ jpi then begin
115        ztmp[0, 2:ny+1] = z[jpi-1, *]
116        ztmp[nx+1, 2:ny+1] = z[0, *]
117      endif
118      z = temporary(ztmp)
119    END
120  endcase
121  IF testvar(var = key_performance) EQ 2 THEN $
122    print, 'temps remplit: on ajoute un cadre de zero ', systime(1)-tempdeux
123;---------------------------------------------------------------
124;---------------------------------------------------------------
125; iteration
126;---------------------------------------------------------------
127;---------------------------------------------------------------
128  FOR n = 1, niter DO BEGIN
129; on trouve les points coast
130    tempdeux = systime(1)       ; pour key_performance =2
131; les points du bord du cadre ne doivent pas etre selectionnes comme
132; la coast
133    case key_gridtype of
134      'c':BEGIN
135        mmmask[0, *] = 1b
136        mmmask[nx+1, *] = 1b
137        mmmask[*, 0] = 1b
138        mmmask[*, ny+1] = 1b
139      END
140      'e':BEGIN
141        mmmask[0, *] = 1b
142        mmmask[nx+1, *] = 1b
143        mmmask[*, 0:1] = 1b
144        mmmask[*, ny+2:ny+3] = 1b
145      END
146    endcase
147; liste des points terre restant
148    IF keyword_set(fillxdir) THEN BEGIN
149; we stop if all the lines, that contains data, have been filled
150      test = total(mmmask[1:nx, *], 1)
151      IF total((test EQ 0)+(test EQ nx)) EQ ny+2 THEN GOTO, fini
152    ENDIF
153    IF keyword_set(fillydir) THEN BEGIN
154; we stop if all the columns, that contains data, have been filled
155      test = total(mmmask[*, 1:ny], 2)
156      IF total((test EQ 0)+(test EQ ny)) EQ nx+2 THEN GOTO, fini
157    ENDIF
158    land = where(mmmask EQ 0)
159    if land[0] EQ -1 then GOTO, fini
160; les points du bord du cadre doivent maintenant etre dans la terre
161    case key_gridtype of
162      'c':BEGIN
163        mmmask[0, *] = 0b
164        mmmask[nx+1, *] = 0b
165        mmmask[*, 0] = 0b
166        mmmask[*, ny+1] = 0b
167      END
168      'e':BEGIN
169        mmmask[0, *] = 0b
170        mmmask[nx+1, *] = 0b
171        mmmask[*, 0:1] = 0b
172        mmmask[*, ny+2:ny+3] = 0b
173      END
174    endcase
175    if keyword_set(key_periodic) AND nx EQ jpi then begin
176      mmmask[0, *] = mmmask[nx, *]
177      mmmask[nx+1, *] = mmmask[1, *]
178    endif
179; liste des voisins mer
180    case key_gridtype of
181      'c':BEGIN
182        CASE 1 OF
183          keyword_set(fillxdir):weight = mmmask[1+land]+mmmask[-1+land]
184          keyword_set(fillydir):weight = mmmask[nx2+land]+mmmask[-nx2+land]
185          ELSE:weight = mmmask[1+land]+mmmask[-1+land]+mmmask[nx2+land]+mmmask[-nx2+land] $
186            +1./sqrt(2)*(mmmask[nx2+1+land]+mmmask[nx2-1+land] $
187                         +mmmask[-nx2+1+land]+mmmask[-nx2-1+land])
188        ENDCASE
189      END
190      'e':BEGIN
191        shifted = glam[0, 0] LT glam[0, 1]
192        oddeven = (land/nx2+1-shifted) MOD 2
193        weight = mmmask[1+land]+mmmask[-1+land] $
194          +mmmask[2*nx2+land]+mmmask[-2*nx2+land] $
195          +sqrt(2)*(mmmask[-nx2+oddeven+land]+mmmask[-nx2-1+oddeven+land] $
196                    +mmmask[nx2+oddeven+land]+mmmask[nx2-1+oddeven+land])
197      END
198    endcase
199
200    ok = where(weight GT 0)
201    weight = weight[ok]
202    coast = land[temporary(ok)]
203;
204    IF testvar(var = key_performance) EQ 2 THEN $
205      print, 'temps remplit: trouver la coast ', systime(1)-tempdeux
206;---------------------------------------------------------------
207; remplissage des points coast
208;---------------------------------------------------------------
209    tempdeux = systime(1)       ; pour key_performance =2
210; on masque z
211    z = temporary(z)*mmmask
212;
213    case key_gridtype of
214      'c':BEGIN
215        CASE 1 OF
216          keyword_set(fillxdir):zcoast = z[1+coast]+z[-1+coast]
217          keyword_set(fillydir):zcoast = z[nx2+coast]+z[-nx2+coast]
218          ELSE:zcoast = z[1+coast]+z[-1+coast]+z[nx2+coast]+z[-nx2+coast] $
219            +1./sqrt(2)*(z[nx2+1+coast]+z[nx2-1+coast] $
220                         +z[-nx2+1+coast]+z[-nx2-1+coast])
221        ENDCASE
222      END
223      'e':BEGIN
224        oddeven = (coast/nx2+1-shifted) MOD 2
225        zcoast = z[1+coast]+z[-1+coast]+z[2*nx2+coast]+z[-2*nx2+coast] $
226          +sqrt(2)*(z[-nx2+oddeven+coast]+z[-nx2-1+oddeven+coast] $
227                    +z[nx2+oddeven+coast]+z[nx2-1+oddeven+coast])
228      END
229    endcase
230;
231    z[coast] =  temporary(zcoast)/ temporary(weight)
232; we update the boundary conditions of z
233    if keyword_set(key_periodic) AND nx EQ jpi then begin
234      z[0, *] = z[nx, *]
235      z[nx+1, *] = z[1, *]
236    endif
237;---------------------------------------------------------------
238; IV) on reduit le masque
239;---------------------------------------------------------------
240    mmmask[ temporary(coast)] = 1
241;
242    IF testvar(var = key_performance) EQ 2 THEN $
243      print, 'temps remplit: une iteration ', systime(1)-tempdeux
244  ENDFOR
245fini:
246;
247; on masque les valeurs sur les lands restantes
248;
249  IF n_elements(valmask) EQ 0 then valmask = 1e20
250  IF n_elements(fillval) EQ 0 THEN fillval = valmask
251  z = temporary(z)*mmmask + fillval*(1b-mmmask)
252;---------------------------------------------------------------
253; on redecoupe le tableau pour retirer le cadre!
254;---------------------------------------------------------------
255  case key_gridtype of
256    'c':BEGIN
257      z = z[1:nx, 1:ny]
258    END
259    'e':BEGIN
260      z = z[1:nx, 2:ny+1]
261    END
262  endcase
263;
264  key_gridtype = oldkey_gridtype
265;---------------------------------------------------------------
266  if keyword_set(key_performance) THEN print, 'temps remplit', systime(1)-tempsun
267  return, z
268END
269
Note: See TracBrowser for help on using the repository browser.