/[MITgcm]/MITgcm/pkg/exf/exf_interp.F
ViewVC logotype

Contents of /MITgcm/pkg/exf/exf_interp.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.15 - (show annotations) (download)
Fri Jun 30 12:05:42 2006 UTC (17 years, 11 months ago) by dimitri
Branch: MAIN
Changes since 1.14: +51 -14 lines
o pkg/exf modifications to interpolation and rotation routines for more
   reasonable treatment of North Pole singularity: for tracers North Pole
   value is set to northernmost zonal-mean value, for zonal velocity it is
   set to zero, and for meridional velocity it is set to northernmost value.

1 #include "EXF_OPTIONS.h"
2 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
3 C Flux Coupler using C
4 C Bilinear interpolation of forcing fields C
5 C C
6 C B. Cheng (12/2002) C
7 C C
8 C added Bicubic (bnc 1/2003) C
9 C C
10 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
11
12 real*8 function lagran(i,x,a,sp)
13
14 INTEGER i,k,sp
15 _RS x
16 real*8 a(4)
17 real*8 numer,denom
18
19 numer = 1.D0
20 denom = 1.D0
21
22 do k=1,sp
23 if ( k .ne. i) then
24 denom = denom*(a(i) - a(k))
25 numer = numer*(x - a(k))
26 endif
27 enddo
28
29 lagran = numer/denom
30
31 return
32 end
33
34
35 SUBROUTINE exf_interp(
36 I infile,
37 I filePrec,
38 O arrayout,
39 I irecord, xG_in, yG,
40 I lon_0, lon_inc,
41 I lat_0, lat_inc,
42 I nx_in, ny_in, method, mythid)
43
44 implicit none
45
46 C infile = name of the input file (direct access binary)
47 C filePrec = file precicision (currently not used, assumes real*4)
48 C arrout = output arrays (different for each processor)
49 C irecord = record number in global file
50 C xG,yG = coordinates for output grid
51 C lon_0, lat_0 = lon and lat of sw corner of global input grid
52 C lon_inc = scalar x-grid increment
53 C lat_inc = vector y-grid increments
54 C nx_in, ny_in = input x-grid and y-grid size
55 C method = 1,11,21 for bilinear; 2,12,22 for bicubic
56 C 1,2 for tracer; 11,12 for U; 21,22 for V
57 C mythid = thread id
58 C
59
60 #include "SIZE.h"
61 #include "EEPARAMS.h"
62 #include "PARAMS.h"
63
64 C subroutine variables
65 character*(*) infile
66 integer filePrec, irecord, nx_in, ny_in
67 _RL arrayout(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
68 _RS xG_in (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
69 _RS yG (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
70 _RL lon_0, lon_inc
71 _RL lat_0, lat_inc(ny_in-1)
72 integer method, mythid
73
74 C local variables
75 integer e_ind(snx,sny),w_ind(snx,sny)
76 integer n_ind(snx,sny),s_ind(snx,sny)
77 real*8 px_ind(4), py_ind(4), ew_val(4)
78 external lagran
79 real*8 lagran
80 real*4 arrayin(-1:nx_in+2 , -1:ny_in+2)
81 real*8 x_in (-1:nx_in+2), y_in(-1:ny_in+2)
82 integer i, j, k, l, js, bi, bj, sp, interp_unit
83 _RS xG(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
84 _RS threeSixtyRS, NorthValue
85 PARAMETER ( threeSixtyRS = 360. )
86
87 C put xG in interval [ lon_0 , lon_0+360 [
88 do bj=myByLo(myThid),myByHi(myThid)
89 do bi=myBxLo(myThid),myBxHi(myThid)
90 do j=1-OLy,sNy+OLy
91 do i=1-OLx,sNx+OLx
92 xG(i,j,bi,bj) = xG_in(i,j,bi,bj)-lon_0
93 & + threeSixtyRS*2.
94 xG(i,j,bi,bj) = lon_0+mod(xG(i,j,bi,bj),threeSixtyRS)
95 enddo
96 enddo
97 enddo
98 enddo
99
100 call exf_interp_read(
101 I infile, filePrec,
102 O arrayin,
103 I irecord, nx_in, ny_in, mythid)
104 _BARRIER
105
106 C _BEGIN_MASTER( myThid )
107
108 C setup input grid
109 do i=-1,nx_in+2
110 x_in(i) = lon_0 + (i-1)*lon_inc
111 enddo
112
113 y_in(0) = lat_0 - lat_inc(1)
114 y_in(-1)= lat_0 - 2.*lat_inc(1)
115 y_in(1) = lat_0
116 do j=2,ny_in
117 y_in(j) = y_in(j-1) + lat_inc(j-1)
118 enddo
119 c y_in(ny_in+1) = y_in(ny_in) + lat_inc(ny_in-1)
120 c y_in(ny_in+2) = y_in(ny_in) + 2.*lat_inc(ny_in-1)
121 y_in(ny_in+1) = min( y_in(ny_in) + lat_inc(ny_in-1), 90 )
122 y_in(ny_in+2) = min( y_in(ny_in) + 2.*lat_inc(ny_in-1), 90)
123
124 C enlarge boundary
125 do j=1,ny_in
126 arrayin(0,j) = arrayin(nx_in,j)
127 arrayin(-1,j) = arrayin(nx_in-1,j)
128 arrayin(nx_in+1,j) = arrayin(1,j)
129 arrayin(nx_in+2,j) = arrayin(2,j)
130 enddo
131 do i=-1,nx_in+2
132 arrayin(i,0) = arrayin(i,1)
133 arrayin(i,-1) = arrayin(i,1)
134 arrayin(i,ny_in+1) = arrayin(i,ny_in)
135 arrayin(i,ny_in+2) = arrayin(i,ny_in)
136 enddo
137
138 C For tracer (method=1,2) set to northernmost zonal-mean value
139 C at 90N to avoid sharp zonal gradients near the Pole.
140 C For U (method=11,12) set to zero at 90N to minimize velocity
141 C gradient at North Pole
142 C For V (method=11,12) set to northernmost zonal value at 90N,
143 C as is already done above in order to allow cross-PoleArctic flow
144 if (y_in(ny_in+1).eq.90) then
145 if (method.eq.1 .or. method.eq.2) then
146 NorthValue = 0
147 do i=1,nx_in
148 NorthValue = NorthValue + arrayin(i,ny_in)
149 enddo
150 NorthValue = NorthValue / nx_in
151 do i=-1,nx_in+2
152 arrayin(i,ny_in+1) = NorthValue
153 enddo
154 elseif (method.eq.11 .or. method.eq.12) then
155 do i=-1,nx_in+2
156 arrayin(i,ny_in+1) = 0
157 enddo
158 endif
159 endif
160 if (y_in(ny_in+2).eq.90) then
161 if (method.eq.1 .or. method.eq.2) then
162 NorthValue = 0
163 do i=1,nx_in
164 NorthValue = NorthValue + arrayin(i,ny_in)
165 enddo
166 NorthValue = NorthValue / nx_in
167 do i=-1,nx_in+2
168 arrayin(i,ny_in+2) = NorthValue
169 enddo
170 elseif (method.eq.11 .or. method.eq.12) then
171 do i=-1,nx_in+2
172 arrayin(i,ny_in+2) = 0
173 enddo
174 endif
175 endif
176
177 C _END_MASTER( myThid )
178
179 do bj = mybylo(mythid), mybyhi(mythid)
180 do bi = mybxlo(mythid), mybxhi(mythid)
181
182 C check validity of input/output coordinates
183 #ifdef ALLOW_DEBUG
184 if ( debugLevel .ge. debLevB ) then
185 do i=1,snx
186 do j=1,sny
187 if ( xG(i,j,bi,bj) .lt. x_in(0) .or.
188 & xG(i,j,bi,bj) .ge. x_in(nx_in+1) .or.
189 & yG(i,j,bi,bj) .lt. y_in(0) .or.
190 & yG(i,j,bi,bj) .ge. y_in(ny_in+1) ) then
191 print*,'ERROR in S/R EXF_INTERP:'
192 print*,' input grid must encompass output grid.'
193 print*,'i,j,bi,bj' ,i,j,bi,bj
194 print*,'xG,yG' ,xG(i,j,bi,bj),yG(i,j,bi,bj)
195 print*,'nx_in,ny_in' ,nx_in ,ny_in
196 print*,'x_in(0,nx_in+1)',x_in(0) ,x_in(nx_in+1)
197 print*,'y_in(0,ny_in+1)',y_in(0) ,y_in(ny_in+1)
198 STOP ' ABNORMAL END: S/R EXF_INTERP'
199 endif
200 enddo
201 enddo
202 endif
203 #endif /* ALLOW_DEBUG */
204
205 C compute interpolation indices
206 do i=1,snx
207 do j=1,sny
208 if (xG(i,j,bi,bj)-x_in(1) .ge. 0.) then
209 w_ind(i,j) = int((xG(i,j,bi,bj)-x_in(1))/lon_inc) + 1
210 else
211 w_ind(i,j) = int((xG(i,j,bi,bj)-x_in(1))/lon_inc)
212 endif
213 e_ind(i,j) = w_ind(i,j) + 1
214 js = ny_in*.5
215 do while (yG(i,j,bi,bj) .lt. y_in(js))
216 js = (js - 1)*.5
217 enddo
218 do while (yG(i,j,bi,bj) .ge. y_in(js+1))
219 js = js + 1
220 enddo
221 s_ind(i,j) = js
222 n_ind(i,j) = js + 1
223 enddo
224 enddo
225
226 if (method.eq.1 .or. method.eq.11 .or. method.eq.21) then
227
228 C bilinear interpolation
229 sp = 2
230 do j=1,sny
231 do i=1,snx
232 arrayout(i,j,bi,bj) = 0.
233 do l=0,1
234 px_ind(l+1) = x_in(w_ind(i,j)+l)
235 py_ind(l+1) = y_in(s_ind(i,j)+l)
236 enddo
237 do k=1,2
238 ew_val(k) = arrayin(w_ind(i,j),s_ind(i,j)+k-1)
239 & *lagran(1,xG(i,j,bi,bj),px_ind,sp)
240 & +arrayin(e_ind(i,j),s_ind(i,j)+k-1)
241 & *lagran(2,xG(i,j,bi,bj),px_ind,sp)
242 arrayout(i,j,bi,bj)=arrayout(i,j,bi,bj)
243 & +ew_val(k)*lagran(k,yG(i,j,bi,bj),py_ind,sp)
244 enddo
245 enddo
246 enddo
247 elseif (method .eq. 2 .or. method.eq.12 .or. method.eq.22) then
248
249 C bicubic interpolation
250 sp = 4
251 do j=1,sny
252 do i=1,snx
253 arrayout(i,j,bi,bj) = 0.
254 do l=-1,2
255 px_ind(l+2) = x_in(w_ind(i,j)+l)
256 py_ind(l+2) = y_in(s_ind(i,j)+l)
257 enddo
258 do k=1,4
259 ew_val(k) =
260 & arrayin(w_ind(i,j)-1,s_ind(i,j)+k-2)
261 & *lagran(1,xG(i,j,bi,bj),px_ind,sp)
262 & +arrayin(w_ind(i,j) ,s_ind(i,j)+k-2)
263 & *lagran(2,xG(i,j,bi,bj),px_ind,sp)
264 & +arrayin(e_ind(i,j) ,s_ind(i,j)+k-2)
265 & *lagran(3,xG(i,j,bi,bj),px_ind,sp)
266 & +arrayin(e_ind(i,j)+1,s_ind(i,j)+k-2)
267 & *lagran(4,xG(i,j,bi,bj),px_ind,sp)
268 arrayout(i,j,bi,bj)=arrayout(i,j,bi,bj)
269 & +ew_val(k)*lagran(k,yG(i,j,bi,bj),py_ind,sp)
270 enddo
271 enddo
272 enddo
273 else
274 stop 'stop in exf_interp.F: interpolation method not supported'
275 endif
276 enddo
277 enddo
278
279 END

  ViewVC Help
Powered by ViewVC 1.1.22