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

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

change *.pro file properties (del eof-style, del executable, set keywords Id

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