1 |
C $Header: /u/gcmpack/MITgcm/pkg/profiles/profiles_interp_mean.F,v 1.2 2007/06/15 04:49:31 gforget Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "PROFILES_OPTIONS.h" |
5 |
|
6 |
C o==========================================================o |
7 |
C | subroutine profiles_interp | |
8 |
C | o 3D interpolation of model counterparts | |
9 |
C | for netcdf profiles data | |
10 |
C | started: Gael Forget 15-March-2006 | |
11 |
C o==========================================================o |
12 |
|
13 |
SUBROUTINE profiles_interp_mean( |
14 |
O traj_cur_out, |
15 |
I lon_cur, |
16 |
I lat_cur, |
17 |
I type_cur, |
18 |
I file_cur, |
19 |
I mytime, |
20 |
I bi, |
21 |
I bj, |
22 |
I myThid |
23 |
& ) |
24 |
|
25 |
implicit none |
26 |
|
27 |
C ==================== Global Variables =========================== |
28 |
#include "EEPARAMS.h" |
29 |
#include "SIZE.h" |
30 |
#include "GRID.h" |
31 |
c#include "DYNVARS.h" |
32 |
#include "PARAMS.h" |
33 |
#ifdef ALLOW_CAL |
34 |
#include "cal.h" |
35 |
#endif |
36 |
#ifdef ALLOW_PROFILES |
37 |
# include "profiles.h" |
38 |
#else |
39 |
integer NLEVELMAX |
40 |
parameter (NLEVELMAX=1) |
41 |
#endif |
42 |
c#ifdef ALLOW_PTRACERS |
43 |
c#include "PTRACERS_SIZE.h" |
44 |
c#include "PTRACERS_FIELDS.h" |
45 |
c#endif |
46 |
C ==================== Routine Variables ========================== |
47 |
_RL mytime |
48 |
integer mythid |
49 |
integer type_cur,file_cur |
50 |
_RL traj_cur_out(NLEVELMAX) |
51 |
_RL lon_cur,lat_cur |
52 |
|
53 |
#ifdef ALLOW_PROFILES |
54 |
|
55 |
C ==================== Local Variables ========================== |
56 |
_RL tab_coeffs1(2,2),tab_coeffs2(2,2),tab_coeffs3(2,2) |
57 |
_RL ponderations(2,2),pondsSUM,distance1,distance2 |
58 |
integer i,j,k,kk,kcur,iG,jG,bi,bj |
59 |
_RL traj_cur(nR),mask_cur(nR) |
60 |
integer prof_i,prof_j |
61 |
_RL lon_tmp1,lon_tmp2,lon_1,lon_2,lat_1,lat_2,tmp_coeff |
62 |
c-- == end of interface == |
63 |
|
64 |
prof_i=-10 |
65 |
prof_j=-10 |
66 |
lon_1=-10 |
67 |
lon_2=-10 |
68 |
lat_1=-10 |
69 |
lat_2=-10 |
70 |
|
71 |
DO j=1,sNy+1 |
72 |
DO i=1,sNx+1 |
73 |
|
74 |
cgf value of j, south of the data point: |
75 |
if (type_cur.NE.4) then |
76 |
if ((yC(i,j,bi,bj).LE.lat_cur).AND. |
77 |
& (yC(i,j+1,bi,bj).GT.lat_cur)) then |
78 |
prof_j=j |
79 |
lat_1=yC(i,j,bi,bj) |
80 |
lat_2=yC(i,j+1,bi,bj) |
81 |
else |
82 |
prof_j=prof_j |
83 |
lat_1=lat_1 |
84 |
lat_2=lat_2 |
85 |
endif |
86 |
else |
87 |
if ((yG(i,j,bi,bj).LE.lat_cur).AND. |
88 |
& (yG(i,j+1,bi,bj).GT.lat_cur)) then |
89 |
prof_j=j |
90 |
lat_1=yG(i,j,bi,bj) |
91 |
lat_2=yG(i,j+1,bi,bj) |
92 |
else |
93 |
prof_j=prof_j |
94 |
lat_1=lat_1 |
95 |
lat_2=lat_2 |
96 |
endif |
97 |
endif |
98 |
|
99 |
cgf value of i, west of the data point: |
100 |
if (type_cur.NE.3) then |
101 |
if (xC(i+1,j,bi,bj).LT.xC(1,j,bi,bj)) then |
102 |
lon_tmp2=xC(i+1,j,bi,bj)+360 |
103 |
else |
104 |
lon_tmp2=xC(i+1,j,bi,bj) |
105 |
endif |
106 |
if (xC(i,j,bi,bj).LT.xC(1,j,bi,bj)) then |
107 |
lon_tmp1=xC(i,j,bi,bj)+360 |
108 |
else |
109 |
lon_tmp1=xC(i,j,bi,bj) |
110 |
endif |
111 |
else |
112 |
if (xG(i+1,j,bi,bj).LT.xG(1,j,bi,bj)) then |
113 |
lon_tmp2=xG(i+1,j,bi,bj)+360 |
114 |
else |
115 |
lon_tmp2=xG(i+1,j,bi,bj) |
116 |
endif |
117 |
if (xG(i,j,bi,bj).LT.xG(1,j,bi,bj)) then |
118 |
lon_tmp1=xG(i,j,bi,bj)+360 |
119 |
else |
120 |
lon_tmp1=xG(i,j,bi,bj) |
121 |
endif |
122 |
endif |
123 |
if ((lon_tmp1.LE.lon_cur).AND. |
124 |
&(lon_tmp2.GT.lon_cur)) then |
125 |
prof_i=i |
126 |
lon_1=lon_tmp1 |
127 |
lon_2=lon_tmp2 |
128 |
else |
129 |
prof_i=prof_i |
130 |
lon_1=lon_1 |
131 |
lon_2=lon_2 |
132 |
endif |
133 |
|
134 |
ENDDO |
135 |
ENDDO |
136 |
|
137 |
|
138 |
if ((prof_i.NE.-10).AND.(prof_j.NE.-10)) then |
139 |
cgf) spatial interpolation |
140 |
|
141 |
distance1=(lat_cur-lat_1)/(lat_2-lat_1) |
142 |
distance2=(lon_cur-lon_1)/(lon_2-lon_1) |
143 |
tab_coeffs2(1,1)=(1-distance2)*(1-distance1) |
144 |
tab_coeffs2(1,2)=distance2*(1-distance1) |
145 |
tab_coeffs2(2,1)=(1-distance2)*distance1 |
146 |
tab_coeffs2(2,2)=distance2*distance1 |
147 |
|
148 |
do k=1,nr |
149 |
if (type_cur.EQ.6) then |
150 |
tab_coeffs1(1,1)=prof_etan_mean(prof_i,prof_j,bi,bj) !SO |
151 |
tab_coeffs1(1,2)=prof_etan_mean(prof_i+1,prof_j,bi,bj) !SE |
152 |
tab_coeffs1(2,1)=prof_etan_mean(prof_i,prof_j+1,bi,bj) !NO |
153 |
tab_coeffs1(2,2)=prof_etan_mean(prof_i+1,prof_j+1,bi,bj) !NZ |
154 |
tab_coeffs3(1,1)=maskC(prof_i,prof_j,1,bi,bj) !SO |
155 |
tab_coeffs3(1,2)=maskC(prof_i+1,prof_j,1,bi,bj) !SE |
156 |
tab_coeffs3(2,1)=maskC(prof_i,prof_j+1,1,bi,bj) !NO |
157 |
tab_coeffs3(2,2)=maskC(prof_i+1,prof_j+1,1,bi,bj) !NZ |
158 |
else |
159 |
tab_coeffs1(1,1)=0. |
160 |
tab_coeffs1(2,1)=0. |
161 |
tab_coeffs1(1,2)=0. |
162 |
tab_coeffs1(2,2)=0. |
163 |
tab_coeffs3(1,1)=0. |
164 |
tab_coeffs3(2,1)=0. |
165 |
tab_coeffs3(1,2)=0. |
166 |
tab_coeffs3(2,2)=0. |
167 |
endif |
168 |
|
169 |
ponderations(1,1)=tab_coeffs3(1,1)*tab_coeffs2(1,1) |
170 |
ponderations(1,2)=tab_coeffs3(1,2)*tab_coeffs2(1,2) |
171 |
ponderations(2,1)=tab_coeffs3(2,1)*tab_coeffs2(2,1) |
172 |
ponderations(2,2)=tab_coeffs3(2,2)*tab_coeffs2(2,2) |
173 |
pondsSUM=ponderations(1,1)+ponderations(2,1)+ponderations(1,2)+ |
174 |
& ponderations(2,2) |
175 |
|
176 |
if (pondsSUM.GT.0) then |
177 |
tab_coeffs1(1,1)=tab_coeffs1(1,1)*ponderations(1,1)/pondsSUM |
178 |
tab_coeffs1(1,2)=tab_coeffs1(1,2)*ponderations(1,2)/pondsSUM |
179 |
tab_coeffs1(2,1)=tab_coeffs1(2,1)*ponderations(2,1)/pondsSUM |
180 |
tab_coeffs1(2,2)=tab_coeffs1(2,2)*ponderations(2,2)/pondsSUM |
181 |
traj_cur(k)=tab_coeffs1(1,1)+tab_coeffs1(2,1)+ |
182 |
& tab_coeffs1(1,2)+tab_coeffs1(2,2) |
183 |
mask_cur(k)=1 |
184 |
else |
185 |
traj_cur(k)=0 |
186 |
mask_cur(k)=0 |
187 |
endif |
188 |
enddo |
189 |
|
190 |
else |
191 |
do k=1,nr |
192 |
traj_cur(k)=0 |
193 |
mask_cur(k)=0 |
194 |
enddo |
195 |
endif |
196 |
|
197 |
cgf vertical interpolation: |
198 |
do kk=1,NLEVELMAX |
199 |
traj_cur_out(kk)=0 |
200 |
prof_mask1D_cur(kk,bi,bj)=0 |
201 |
enddo |
202 |
do kk=1,ProfDepthNo(file_cur,bi,bj) |
203 |
c case 1: above first grid center=> first grid center value |
204 |
if (prof_depth(file_cur,kk,bi,bj).LT.-rC(1)) then |
205 |
traj_cur_out(kk)=traj_cur(1) |
206 |
prof_mask1D_cur(kk,bi,bj)=mask_cur(1) |
207 |
c case 2: just below last grid center=> last cell value |
208 |
elseif (prof_depth(file_cur,kk,bi,bj).GE.-rC(nr)) then |
209 |
if ( prof_depth(file_cur,kk,bi,bj) .LT. |
210 |
& (-rC(nr)+drC(nr)/2) ) then |
211 |
traj_cur_out(kk)=traj_cur(nr) |
212 |
prof_mask1D_cur(kk,bi,bj)=mask_cur(nr) |
213 |
endif |
214 |
c case 3: between two grid centers |
215 |
else |
216 |
kcur=0 |
217 |
do k=1,nr-1 |
218 |
if ((prof_depth(file_cur,kk,bi,bj).GE.-rC(k)).AND. |
219 |
& (prof_depth(file_cur,kk,bi,bj).LT.-rC(k+1))) then |
220 |
kcur=k |
221 |
endif |
222 |
enddo |
223 |
if (kcur.EQ.0) then |
224 |
WRITE(errorMessageUnit,'(A)') |
225 |
& 'ERROR in PROFILES_INTERP: unexpected case 1' |
226 |
STOP 'ABNORMAL END: S/R PROFILES_INTERP' |
227 |
endif |
228 |
if (mask_cur(kcur+1).EQ.1.) then |
229 |
c subcase 1: 2 wet points=>linear interpolation |
230 |
tmp_coeff=(prof_depth(file_cur,kk,bi,bj)+rC(kcur))/ |
231 |
& (-rC(kcur+1)+rC(kcur)) |
232 |
traj_cur_out(kk)=(1-tmp_coeff)*traj_cur(kcur) |
233 |
& +tmp_coeff*traj_cur(kcur+1) |
234 |
prof_mask1D_cur(kk,bi,bj)=1 |
235 |
if (mask_cur(kcur).EQ.0.) then |
236 |
WRITE(errorMessageUnit,'(A)') |
237 |
& 'ERROR in PROFILES_INTERP: unexpected case 2' |
238 |
STOP 'ABNORMAL END: S/R PROFILES_INTERP' |
239 |
endif |
240 |
elseif (prof_depth(file_cur,kk,bi,bj).LT.-rF(kcur+1)) then |
241 |
c subcase 2: only 1 wet point just above=>upper cell value |
242 |
traj_cur_out(kk)=traj_cur(kcur) |
243 |
prof_mask1D_cur(kk,bi,bj)=mask_cur(kcur) |
244 |
endif |
245 |
endif |
246 |
enddo |
247 |
|
248 |
|
249 |
#endif |
250 |
|
251 |
end |
252 |
|