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

Last change on this file since 97 was 97, checked in by pinsard, 18 years ago

start to modify headers of Obsolete *.pro files for better idldoc output

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