1 |
jmc |
1.1 |
C $Header: /u/gcmpack/MITgcm/pkg/flt/flt_bilinear.F,v 1.4 2009/01/04 00:58:23 jmc Exp $ |
2 |
|
|
C $Name: $ |
3 |
|
|
|
4 |
|
|
#include "FLT_OPTIONS.h" |
5 |
|
|
|
6 |
|
|
C-- Contents |
7 |
|
|
C-- o FLT_BILINEAR |
8 |
|
|
C-- o FLT_TRILINEAR |
9 |
|
|
C-- o FLT_BILINEAR2D |
10 |
|
|
|
11 |
|
|
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
12 |
|
|
|
13 |
|
|
SUBROUTINE FLT_BILINEAR( |
14 |
|
|
I ix, jy, |
15 |
|
|
O uu, |
16 |
|
|
I var, |
17 |
|
|
I kl, nu, bi, bj, myThid ) |
18 |
|
|
|
19 |
|
|
C ================================================================== |
20 |
|
|
C SUBROUTINE FLT_BILINEAR |
21 |
|
|
C ================================================================== |
22 |
|
|
C o Bilinear scheme to interpolate variable to particle position |
23 |
|
|
C given by its fractional (real) index ix,jy location |
24 |
|
|
C ================================================================== |
25 |
|
|
|
26 |
|
|
C !USES: |
27 |
|
|
IMPLICIT NONE |
28 |
|
|
|
29 |
|
|
C == global variables == |
30 |
|
|
#include "SIZE.h" |
31 |
|
|
|
32 |
|
|
C == routine arguments == |
33 |
|
|
_RL ix, jy |
34 |
|
|
_RL uu |
35 |
|
|
_RL var(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
36 |
|
|
INTEGER kl, nu, bi, bj, myThid |
37 |
|
|
|
38 |
|
|
C == local variables == |
39 |
|
|
INTEGER i1, j1, i2, j2, klp |
40 |
|
|
_RL ddx, ddy |
41 |
|
|
_RL u11, u12, u22, u21 |
42 |
|
|
|
43 |
|
|
C == end of interface == |
44 |
|
|
|
45 |
|
|
C-- to choose the u box in which the particle is found |
46 |
|
|
C nu=0 for T, S |
47 |
|
|
C nu=1 for u |
48 |
|
|
C nu=2 for v |
49 |
|
|
C nu=3 for Vorticity |
50 |
|
|
C nu=4 for w |
51 |
|
|
|
52 |
|
|
IF ( kl.LT.1 .OR. kl.GT.Nr ) THEN |
53 |
|
|
c WRITE(msgbuf,'(A,I8)') |
54 |
|
|
c & ' FLT_BILINEAR: illegal value for kl=',kl |
55 |
|
|
c CALL PRINT_ERROR( msgbuf, myThid ) |
56 |
|
|
STOP 'ABNORMAL END: S/R FLT_BILINEAR' |
57 |
|
|
ENDIF |
58 |
|
|
|
59 |
|
|
C-- find x-index according to grid-location of variable |
60 |
|
|
IF ( MOD(nu,2).EQ.0 ) THEN |
61 |
|
|
i1 = INT(ix) |
62 |
|
|
ddx = ix - DFLOAT(i1) |
63 |
|
|
ELSE |
64 |
|
|
i1 = NINT(ix) |
65 |
|
|
ddx = 0.5 _d 0 + ix - DFLOAT(i1) |
66 |
|
|
ENDIF |
67 |
|
|
C-- find y-index according to grid-location of variable |
68 |
|
|
IF ( MOD(nu,4).LE.1 ) THEN |
69 |
|
|
j1 = INT(jy) |
70 |
|
|
ddy = jy - DFLOAT(j1) |
71 |
|
|
ELSE |
72 |
|
|
j1 = NINT(jy) |
73 |
|
|
ddy = 0.5 _d 0 + jy - DFLOAT(j1) |
74 |
|
|
ENDIF |
75 |
|
|
|
76 |
|
|
C-- Set the higher index for interpolation |
77 |
|
|
i2 = i1 + 1 |
78 |
|
|
j2 = j1 + 1 |
79 |
|
|
|
80 |
|
|
C-- No need to change start/end index : use array overlap if needed |
81 |
|
|
|
82 |
|
|
C-- bilinear interpolation (from numerical recipes) |
83 |
|
|
IF (nu.LE.3) THEN |
84 |
|
|
uu = ( (1.-ddx)*(1.-ddy)*var(i1,j1,kl,bi,bj) |
85 |
|
|
& + ddx * ddy *var(i2,j2,kl,bi,bj) ) |
86 |
|
|
& + ( ddx *(1.-ddy)*var(i2,j1,kl,bi,bj) |
87 |
|
|
& + (1.-ddx)* ddy *var(i1,j2,kl,bi,bj) ) |
88 |
|
|
ELSE |
89 |
|
|
klp = MIN(kl+1,Nr) |
90 |
|
|
u11 = ( var(i1,j1,kl,bi,bj)+var(i1,j1,klp,bi,bj) )*0.5 _d 0 |
91 |
|
|
u21 = ( var(i2,j1,kl,bi,bj)+var(i2,j1,klp,bi,bj) )*0.5 _d 0 |
92 |
|
|
u22 = ( var(i2,j2,kl,bi,bj)+var(i2,j2,klp,bi,bj) )*0.5 _d 0 |
93 |
|
|
u12 = ( var(i1,j2,kl,bi,bj)+var(i1,j2,klp,bi,bj) )*0.5 _d 0 |
94 |
|
|
uu = ( (1.-ddx)*(1.-ddy)*u11 |
95 |
|
|
& + ddx * ddy *u22 ) |
96 |
|
|
& + ( ddx *(1.-ddy)*u21 |
97 |
|
|
& + (1.-ddx)* ddy *u12 ) |
98 |
|
|
ENDIF |
99 |
|
|
|
100 |
|
|
|
101 |
|
|
RETURN |
102 |
|
|
END |
103 |
|
|
|
104 |
|
|
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
105 |
|
|
|
106 |
|
|
SUBROUTINE FLT_TRILINEAR( |
107 |
|
|
I ix, jy, kz, |
108 |
|
|
O uu, |
109 |
|
|
I var, |
110 |
|
|
I nu, bi, bj, myThid ) |
111 |
|
|
|
112 |
|
|
C ================================================================== |
113 |
|
|
C SUBROUTINE FLT_TRILINEAR |
114 |
|
|
C ================================================================== |
115 |
|
|
C o Trilinear scheme to interpolate variable to particle position |
116 |
|
|
C given by its fractional (real) index ix,jy,kz location |
117 |
|
|
C This routine is a straight forward generalization of the |
118 |
|
|
C bilinear interpolation scheme. |
119 |
|
|
C |
120 |
|
|
C started: 2004.05.28 Antti Westerlund (antti.westerlund@fimr.fi) |
121 |
|
|
C and Sergio Jaramillo (sju@eos.ubc.ca). |
122 |
|
|
C (adopted from SUBROUTINE bilinear by Arne Biastoch) |
123 |
|
|
C ================================================================== |
124 |
|
|
|
125 |
|
|
C !USES: |
126 |
|
|
IMPLICIT NONE |
127 |
|
|
|
128 |
|
|
C == global variables == |
129 |
|
|
#include "SIZE.h" |
130 |
|
|
|
131 |
|
|
C == routine arguments == |
132 |
|
|
_RL ix, jy, kz |
133 |
|
|
_RL uu |
134 |
|
|
_RL var(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
135 |
|
|
INTEGER nu, bi, bj, myThid |
136 |
|
|
|
137 |
|
|
C == local variables == |
138 |
|
|
INTEGER i1, j1, k1, i2, j2, k2 |
139 |
|
|
_RL ddx, ddy, ddz |
140 |
|
|
|
141 |
|
|
C == end of interface == |
142 |
|
|
|
143 |
|
|
C to choose the u box in which the particle is found |
144 |
|
|
C nu=0 for T, S |
145 |
|
|
C nu=1 for u |
146 |
|
|
C nu=2 for v |
147 |
|
|
C nu=3 for Vorticity |
148 |
|
|
C nu=4 for w |
149 |
|
|
|
150 |
|
|
C-- find x-index according to grid-location of variable |
151 |
|
|
IF ( MOD(nu,2).EQ.0 ) THEN |
152 |
|
|
i1 = INT(ix) |
153 |
|
|
ddx = ix - DFLOAT(i1) |
154 |
|
|
ELSE |
155 |
|
|
i1 = NINT(ix) |
156 |
|
|
ddx = 0.5 _d 0 + ix - DFLOAT(i1) |
157 |
|
|
ENDIF |
158 |
|
|
C-- find y-index according to grid-location of variable |
159 |
|
|
IF ( MOD(nu,4).LE.1 ) THEN |
160 |
|
|
j1 = INT(jy) |
161 |
|
|
ddy = jy - DFLOAT(j1) |
162 |
|
|
ELSE |
163 |
|
|
j1 = NINT(jy) |
164 |
|
|
ddy = 0.5 _d 0 + jy - DFLOAT(j1) |
165 |
|
|
ENDIF |
166 |
|
|
C-- find z-index according to grid-location of variable |
167 |
|
|
IF ( nu.LE.3 ) THEN |
168 |
|
|
k1 = INT(kz) |
169 |
|
|
ddz = kz - DFLOAT(k1) |
170 |
|
|
ELSE |
171 |
|
|
k1 = NINT(kz) |
172 |
|
|
ddz = 0.5 _d 0 + kz - DFLOAT(k1) |
173 |
|
|
ENDIF |
174 |
|
|
|
175 |
|
|
C-- Set the higher index for interpolation |
176 |
|
|
i2 = i1 + 1 |
177 |
|
|
j2 = j1 + 1 |
178 |
|
|
k2 = k1 + 1 |
179 |
|
|
|
180 |
|
|
C-- No need to change start/end horizontal index : use array overlap if needed |
181 |
|
|
C-- Need to adjust start/end vertical index : |
182 |
|
|
k1 = MIN( MAX( k1, 1 ), Nr ) |
183 |
|
|
k2 = MIN( MAX( k2, 1 ), Nr ) |
184 |
|
|
|
185 |
|
|
C Trilinear interpolation, a straight forward generalization |
186 |
|
|
C of the bilinear interpolation scheme. |
187 |
|
|
uu = (1.-ddz)*( ( (1.-ddx)*(1.-ddy)*var(i1,j1,k1,bi,bj) |
188 |
|
|
& + ddx * ddy *var(i2,j2,k1,bi,bj) ) |
189 |
|
|
& + ( ddx *(1.-ddy)*var(i2,j1,k1,bi,bj) |
190 |
|
|
& + (1.-ddx)* ddy *var(i1,j2,k1,bi,bj) ) ) |
191 |
|
|
& + ddz *( ( (1.-ddx)*(1.-ddy)*var(i1,j1,k2,bi,bj) |
192 |
|
|
& + ddx * ddy *var(i2,j2,k2,bi,bj) ) |
193 |
|
|
& + ( ddx*(1.-ddy) *var(i2,j1,k2,bi,bj) |
194 |
|
|
& + (1.-ddx)* ddy *var(i1,j2,k2,bi,bj) ) ) |
195 |
|
|
|
196 |
|
|
RETURN |
197 |
|
|
END |
198 |
|
|
|
199 |
|
|
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
200 |
|
|
|
201 |
|
|
SUBROUTINE FLT_BILINEAR2D( |
202 |
|
|
I ix, jy, |
203 |
|
|
O uu, |
204 |
|
|
I var, |
205 |
|
|
I nu, bi, bj, myThid ) |
206 |
|
|
|
207 |
|
|
C ================================================================== |
208 |
|
|
C SUBROUTINE FLT_BILINEAR2D |
209 |
|
|
C ================================================================== |
210 |
|
|
C o Bilinear scheme to interpolate 2-D variable to particle position |
211 |
|
|
C given by its fractional (real) index ix,jy location |
212 |
|
|
C |
213 |
|
|
C started: Arne Biastoch abiastoch@ucsd.edu 13-Jan-2000 |
214 |
|
|
C (adopted from SUBROUTINE bilinear) |
215 |
|
|
C ================================================================== |
216 |
|
|
|
217 |
|
|
C !USES: |
218 |
|
|
IMPLICIT NONE |
219 |
|
|
|
220 |
|
|
C == global variables == |
221 |
|
|
#include "SIZE.h" |
222 |
|
|
|
223 |
|
|
C == routine arguments == |
224 |
|
|
_RL ix, jy |
225 |
|
|
_RL uu |
226 |
|
|
_RL var(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
227 |
|
|
INTEGER nu, bi, bj, myThid |
228 |
|
|
|
229 |
|
|
C == local variables == |
230 |
|
|
INTEGER i1, j1, i2, j2 |
231 |
|
|
_RL ddx, ddy |
232 |
|
|
|
233 |
|
|
C == end of interface == |
234 |
|
|
|
235 |
|
|
C to choose the u box in which the particle is found |
236 |
|
|
C nu=0 for T, S |
237 |
|
|
C nu=1 for u |
238 |
|
|
C nu=2 for v |
239 |
|
|
C nu=3 for Vorticity |
240 |
|
|
C nu=4 for w |
241 |
|
|
|
242 |
|
|
C-- find x-index according to grid-location of variable |
243 |
|
|
IF ( MOD(nu,2).EQ.0 ) THEN |
244 |
|
|
i1 = INT(ix) |
245 |
|
|
ddx = ix - DFLOAT(i1) |
246 |
|
|
ELSE |
247 |
|
|
i1 = NINT(ix) |
248 |
|
|
ddx = 0.5 _d 0 + ix - DFLOAT(i1) |
249 |
|
|
ENDIF |
250 |
|
|
C-- find y-index according to grid-location of variable |
251 |
|
|
IF ( MOD(nu,4).LE.1 ) THEN |
252 |
|
|
j1 = INT(jy) |
253 |
|
|
ddy = jy - DFLOAT(j1) |
254 |
|
|
ELSE |
255 |
|
|
j1 = NINT(jy) |
256 |
|
|
ddy = 0.5 _d 0 + jy - DFLOAT(j1) |
257 |
|
|
ENDIF |
258 |
|
|
|
259 |
|
|
C-- Set the higher index for interpolation |
260 |
|
|
i2 = i1 + 1 |
261 |
|
|
j2 = j1 + 1 |
262 |
|
|
|
263 |
|
|
C-- No need to change start/end index : use array overlap if needed |
264 |
|
|
|
265 |
|
|
C bilinear interpolation (from numerical recipes) |
266 |
|
|
uu = ( (1.-ddx)*(1.-ddy)*var(i1,j1,bi,bj) |
267 |
|
|
& + ddx * ddy *var(i2,j2,bi,bj) ) |
268 |
|
|
& + ( ddx *(1.-ddy)*var(i2,j1,bi,bj) |
269 |
|
|
& + (1.-ddx)* ddy *var(i1,j2,bi,bj) ) |
270 |
|
|
|
271 |
|
|
RETURN |
272 |
|
|
END |