source: trunk/SRC/Interpolation/extrapolate.pro @ 118

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

add $ in Calendar, Grid, Interpolation, Obsolete and Postscript *.pro files, add svn:keywords Id to all these files, some improvements in header

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1;+
2; @file_comments extrapolate data (zinput) where maskinput eq 0 by filling
3; step by step the coastline points with the mean value of the 8 neighbourgs.
4;
5; @param zinput {in}{required}
6; data to be extrapolate
7;
8; @param maskinput {in}{required}
9;
10; @param nb_iteration {in}{optional}
11; number of iteration
12;
13; @keyword x_periodic
14; @keyword MINVAL
15; @keyword MAXVAL
16;
17; @version $Id$
18;
19;-
20FUNCTION extrapolate, zinput, maskinput, nb_iteration, x_periodic = x_periodic, MINVAL = minval, MAXVAL = maxval
21;
22  compile_opt idl2, strictarrsubs
23;
24; check the number of iteration used in the extrapolation.
25  IF n_elements(nb_iteration) EQ 0 THEN nb_iteration = 10.E20
26  IF nb_iteration EQ 0 THEN return, zinput
27  nx = (size(zinput))[1]
28  ny = (size(zinput))[2]
29; take care of the boundary conditions...
30;
31; for the x direction, we put 2 additional columns at the left and
32; right side of the array.
33; for the y direction, we put 2 additional lines at the bottom and
34; top side of the array.
35; These changes allow us to use shift function without taking care of
36; the x and y periodicity.
37;
38  ztmp = bytarr(nx+2, ny+2)
39  ztmp[1:nx, 1:ny] = byte(maskinput)
40  msk = temporary(ztmp)
41;
42  ztmp = replicate(1.e20, nx+2, ny+2)
43  ztmp[1:nx, 1:ny] = zinput
44  if keyword_set(x_periodic) then begin
45    ztmp[0, 1:ny] = zinput[nx-1, *]
46    ztmp[nx+1, 1:ny] = zinput[0, *]
47  ENDIF
48; remove NaN points if there is some...
49  nan = where(finite(ztmp) EQ 0, cnt_nan)
50  IF cnt_nan NE 0 THEN ztmp[temporary(nan)] = 1.e20
51  z = temporary(ztmp)
52  nx2 = nx+2
53  ny2 = ny+2
54;---------------------------------------------------------------
55;---------------------------------------------------------------
56; extrapolation
57;---------------------------------------------------------------
58  sqrtinv = 1./sqrt(2)
59;
60  cnt = 1
61; When we look for the coast line, we don't whant to select the
62; borderlines of the array. -> we force the value of the mask for
63; those lines.
64  msk[0, *] = 1b
65  msk[nx+1, *] = 1b
66  msk[*, 0] = 1b
67  msk[*, ny+1] = 1b
68; find the land points
69  land = where(msk EQ 0, cnt_land)
70;---------------------------------------------------------------
71  WHILE cnt LE nb_iteration AND cnt_land NE 0 DO BEGIN
72;---------------------------------------------------------------
73; find the coast line points...
74;---------------------------------------------------------------
75; Once the land points list has been found, we change back the the
76; mask values for the boundary conditions.
77    msk[0, *] = 0b
78    msk[nx+1, *] = 0b
79    msk[*, 0] = 0b
80    msk[*, ny+1] = 0b
81    if keyword_set(x_periodic) then begin
82      msk[0, *] = msk[nx, *]
83      msk[nx+1, *] = msk[1, *]
84    endif
85;
86; we compute the weighted number of sea neighbourgs.
87; those 4 neighbours have a weight of 1:
88;    *   
89;   *+*       
90;    *     
91;
92; those 4 neighbours have a weight of 1/sqrt(2):
93;
94;    * *
95;     +       
96;    * *
97;
98; As we make sure that none of the land points are located on the
99; border of the array, we can compute the weight without shift
100; (faster).
101;
102    weight = msk[land+1]+msk[land-1]+msk[land+nx2]+msk[land-nx2] $
103             +sqrtinv*(msk[land+nx2+1]+msk[land+nx2-1] $
104                       +msk[land-nx2+1]+msk[land-nx2-1])
105; list all the points that have sea neighbourgs
106    ok = where(weight GT 0)
107; the coastline points
108    coast = land[ok]
109; their weighted number of sea neighbourgs.
110    weight = weight[temporary(ok)]
111;---------------------------------------------------------------
112; fill the coastine points
113;---------------------------------------------------------------
114    z = temporary(z)*msk
115;
116    zcoast = z[1+coast]+z[-1+coast]+z[nx2+coast]+z[-nx2+coast] $
117             +1./sqrt(2)*(z[nx2+1+coast]+z[nx2-1+coast] $
118                          +z[-nx2+1+coast]+z[-nx2-1+coast])
119;   
120    IF n_elements(minval) NE 0 THEN zcoast = minval > temporary(zcoast)
121    IF n_elements(maxval) NE 0 THEN zcoast = temporary(zcoast) < maxval
122    z[coast] = temporary(zcoast)/temporary(weight)
123; we update the the boundary conditions of z
124    if keyword_set(x_periodic) then begin
125      z[0, *] = z[nx, *]
126      z[nx+1, *] = z[1, *]
127    endif
128;---------------------------------------------------------------
129; we update the mask
130;---------------------------------------------------------------
131    msk[temporary(coast)] = 1
132;
133    cnt = cnt + 1
134; When we look for the coast line, we don't whant to select the
135; borderlines of the array. -> we force the value of the mask for
136; those lines.
137    msk[0, *] = 1b
138    msk[nx+1, *] = 1b
139    msk[*, 0] = 1b
140    msk[*, ny+1] = 1b
141; find the land points
142    land = where(msk EQ 0, cnt_land)
143;
144  ENDWHILE
145;---------------------------------------------------------------
146; we return the original size of the array
147;---------------------------------------------------------------
148 
149  return, z[1:nx, 1:ny]
150END
151
Note: See TracBrowser for help on using the repository browser.