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

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

english and nicer header (2a)

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