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

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

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

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