/[MITgcm]/MITgcm/pkg/profiles/profiles_interp.F
ViewVC logotype

Contents of /MITgcm/pkg/profiles/profiles_interp.F

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


Revision 1.3 - (show annotations) (download)
Sat May 6 14:33:53 2006 UTC (18 years, 1 month ago) by heimbach
Branch: MAIN
Changes since 1.2: +10 -5 lines
Make pkg/profile fully independent of ecco,cost, etc. stuff
to be able to use it in pure forward.

1 C $Header: $
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(
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 myThid
21 & )
22
23 implicit none
24
25 C ==================== Global Variables ===========================
26 #include "EEPARAMS.h"
27 #include "SIZE.h"
28 #include "GRID.h"
29 #include "DYNVARS.h"
30 #include "PARAMS.h"
31 #ifdef ALLOW_CAL
32 #include "cal.h"
33 #endif
34 cph#include "ecco_cost.h"
35 cph#include "ctrl.h"
36 cph#include "ctrl_dummy.h"
37 cph#include "optim.h"
38 #ifdef ALLOW_PROFILES_CONTRIBUTION
39 # include "profiles.h"
40 #else
41 integer NLEVELMAX
42 parameter (NLEVELMAX=1)
43 #endif
44 C ==================== Routine Variables ==========================
45 _RL mytime
46 integer mythid
47 integer type_cur,file_cur
48 _RL traj_cur_out(NLEVELMAX)
49 _RL lon_cur,lat_cur
50
51 #ifdef ALLOW_PROFILES_CONTRIBUTION
52
53 C ==================== Local Variables ==========================
54 _RL tab_coeffs1(2,2),tab_coeffs2(2,2),tab_coeffs3(2,2)
55 _RL ponderations(2,2),pondsSUM,distance1,distance2
56 integer i,j,k,kk,kcur,iG,jG,bi,bj
57 _RL traj_cur(nR),mask_cur(nR)
58 integer prof_i,prof_j
59 _RL lon_tmp1,lon_tmp2,lon_1,lon_2,lat_1,lat_2,tmp_coeff
60 c-- == end of interface ==
61
62 DO bi = myBxLo(myThid), myBxHi(myThid)
63 DO bj = myByLo(myThid), myByHi(myThid)
64
65 prof_i=-10
66 prof_j=-10
67 lon_1=-10
68 lon_2=-10
69 lat_1=-10
70 lat_2=-10
71
72 DO j=1,sNy+1
73 DO i=1,sNx+1
74
75 cgf value of j, south of the data point:
76 if (type_cur.NE.4) then
77 if ((yC(i,j,bi,bj).LE.lat_cur).AND.
78 & (yC(i,j+1,bi,bj).GT.lat_cur)) then
79 prof_j=j
80 lat_1=yC(i,j,bi,bj)
81 lat_2=yC(i,j+1,bi,bj)
82 else
83 prof_j=prof_j
84 lat_1=lat_1
85 lat_2=lat_2
86 endif
87 else
88 if ((yG(i,j,bi,bj).LE.lat_cur).AND.
89 & (yG(i,j+1,bi,bj).GT.lat_cur)) then
90 prof_j=j
91 lat_1=yG(i,j,bi,bj)
92 lat_2=yG(i,j+1,bi,bj)
93 else
94 prof_j=prof_j
95 lat_1=lat_1
96 lat_2=lat_2
97 endif
98 endif
99
100 cgf value of i, west of the data point:
101 if (type_cur.NE.3) then
102 if (xC(i+1,j,bi,bj).LT.xC(1,j,bi,bj)) then
103 lon_tmp2=xC(i+1,j,bi,bj)+360
104 else
105 lon_tmp2=xC(i+1,j,bi,bj)
106 endif
107 if (xC(i,j,bi,bj).LT.xC(1,j,bi,bj)) then
108 lon_tmp1=xC(i,j,bi,bj)+360
109 else
110 lon_tmp1=xC(i,j,bi,bj)
111 endif
112 else
113 if (xG(i+1,j,bi,bj).LT.xG(1,j,bi,bj)) then
114 lon_tmp2=xG(i+1,j,bi,bj)+360
115 else
116 lon_tmp2=xG(i+1,j,bi,bj)
117 endif
118 if (xG(i,j,bi,bj).LT.xG(1,j,bi,bj)) then
119 lon_tmp1=xG(i,j,bi,bj)+360
120 else
121 lon_tmp1=xG(i,j,bi,bj)
122 endif
123 endif
124 if ((lon_tmp1.LE.lon_cur).AND.
125 &(lon_tmp2.GT.lon_cur)) then
126 prof_i=i
127 lon_1=lon_tmp1
128 lon_2=lon_tmp2
129 else
130 prof_i=prof_i
131 lon_1=lon_1
132 lon_2=lon_2
133 endif
134
135 ENDDO
136 ENDDO
137
138
139 if ((prof_i.NE.-10).AND.(prof_j.NE.-10)) then
140 cgf) spatial interpolation
141
142 distance1=(lat_cur-lat_1)/(lat_2-lat_1)
143 distance2=(lon_cur-lon_1)/(lon_2-lon_1)
144 tab_coeffs2(1,1)=(1-distance2)*(1-distance1)
145 tab_coeffs2(1,2)=distance2*(1-distance1)
146 tab_coeffs2(2,1)=(1-distance2)*distance1
147 tab_coeffs2(2,2)=distance2*distance1
148
149 do k=1,nr
150 if (type_cur.EQ.1) then
151 tab_coeffs1(1,1)=theta(prof_i,prof_j,k,bi,bj) !SO
152 tab_coeffs1(1,2)=theta(prof_i+1,prof_j,k,bi,bj) !SE
153 tab_coeffs1(2,1)=theta(prof_i,prof_j+1,k,bi,bj) !NO
154 tab_coeffs1(2,2)=theta(prof_i+1,prof_j+1,k,bi,bj) !NZ
155 tab_coeffs3(1,1)=maskC(prof_i,prof_j,k,bi,bj) !SO
156 tab_coeffs3(1,2)=maskC(prof_i+1,prof_j,k,bi,bj) !SE
157 tab_coeffs3(2,1)=maskC(prof_i,prof_j+1,k,bi,bj) !NO
158 tab_coeffs3(2,2)=maskC(prof_i+1,prof_j+1,k,bi,bj) !NZ
159 elseif (type_cur.EQ.2) then
160 tab_coeffs1(1,1)=salt(prof_i,prof_j,k,bi,bj) !SO
161 tab_coeffs1(1,2)=salt(prof_i+1,prof_j,k,bi,bj) !SE
162 tab_coeffs1(2,1)=salt(prof_i,prof_j+1,k,bi,bj) !NO
163 tab_coeffs1(2,2)=salt(prof_i+1,prof_j+1,k,bi,bj) !NZ
164 tab_coeffs3(1,1)=maskC(prof_i,prof_j,k,bi,bj) !SO
165 tab_coeffs3(1,2)=maskC(prof_i+1,prof_j,k,bi,bj) !SE
166 tab_coeffs3(2,1)=maskC(prof_i,prof_j+1,k,bi,bj) !NO
167 tab_coeffs3(2,2)=maskC(prof_i+1,prof_j+1,k,bi,bj) !NZ
168 elseif (type_cur.EQ.3) then
169 tab_coeffs1(1,1)=uVel(prof_i,prof_j,k,bi,bj) !SO
170 tab_coeffs1(1,2)=uVel(prof_i+1,prof_j,k,bi,bj) !SE
171 tab_coeffs1(2,1)=uVel(prof_i,prof_j+1,k,bi,bj) !NO
172 tab_coeffs1(2,2)=uVel(prof_i+1,prof_j+1,k,bi,bj) !NZ
173 tab_coeffs3(1,1)=maskW(prof_i,prof_j,k,bi,bj) !SO
174 tab_coeffs3(1,2)=maskW(prof_i+1,prof_j,k,bi,bj) !SE
175 tab_coeffs3(2,1)=maskW(prof_i,prof_j+1,k,bi,bj) !NO
176 tab_coeffs3(2,2)=maskW(prof_i+1,prof_j+1,k,bi,bj) !NZ
177 elseif (type_cur.EQ.4) then
178 tab_coeffs1(1,1)=vVel(prof_i,prof_j,k,bi,bj) !SO
179 tab_coeffs1(1,2)=vVel(prof_i+1,prof_j,k,bi,bj) !SE
180 tab_coeffs1(2,1)=vVel(prof_i,prof_j+1,k,bi,bj) !NO
181 tab_coeffs1(2,2)=vVel(prof_i+1,prof_j+1,k,bi,bj) !NZ
182 tab_coeffs3(1,1)=maskS(prof_i,prof_j,k,bi,bj) !SO
183 tab_coeffs3(1,2)=maskS(prof_i+1,prof_j,k,bi,bj) !SE
184 tab_coeffs3(2,1)=maskS(prof_i,prof_j+1,k,bi,bj) !NO
185 tab_coeffs3(2,2)=maskS(prof_i+1,prof_j+1,k,bi,bj) !NZ
186 else
187 tab_coeffs1(1,1)=0.
188 tab_coeffs1(2,1)=0.
189 tab_coeffs1(1,2)=0.
190 tab_coeffs1(2,2)=0.
191 tab_coeffs3(1,1)=0.
192 tab_coeffs3(2,1)=0.
193 tab_coeffs3(1,2)=0.
194 tab_coeffs3(2,2)=0.
195 endif
196
197 ponderations(1,1)=tab_coeffs3(1,1)*tab_coeffs2(1,1)
198 ponderations(1,2)=tab_coeffs3(1,2)*tab_coeffs2(1,2)
199 ponderations(2,1)=tab_coeffs3(2,1)*tab_coeffs2(2,1)
200 ponderations(2,2)=tab_coeffs3(2,2)*tab_coeffs2(2,2)
201 pondsSUM=ponderations(1,1)+ponderations(2,1)+ponderations(1,2)+
202 & ponderations(2,2)
203
204 if (pondsSUM.GT.0) then
205 tab_coeffs1(1,1)=tab_coeffs1(1,1)*ponderations(1,1)/pondsSUM
206 tab_coeffs1(1,2)=tab_coeffs1(1,2)*ponderations(1,2)/pondsSUM
207 tab_coeffs1(2,1)=tab_coeffs1(2,1)*ponderations(2,1)/pondsSUM
208 tab_coeffs1(2,2)=tab_coeffs1(2,2)*ponderations(2,2)/pondsSUM
209 traj_cur(k)=tab_coeffs1(1,1)+tab_coeffs1(2,1)+
210 & tab_coeffs1(1,2)+tab_coeffs1(2,2)
211 mask_cur(k)=1
212 else
213 traj_cur(k)=0
214 mask_cur(k)=0
215 endif
216 enddo
217
218 else
219 do k=1,nr
220 traj_cur(k)=0
221 mask_cur(k)=0
222 enddo
223 endif
224
225 cgf vertical interpolation:
226 do kk=1,NLEVELMAX
227 traj_cur_out(kk)=0
228 prof_mask1D_cur(kk)=0
229 enddo
230 do kk=1,profdepthno(file_cur)
231 c case 1: above first grid center=> first grid center value
232 if (prof_depth(file_cur,kk).LT.-rC(1)) then
233 traj_cur_out(kk)=traj_cur(1)
234 prof_mask1D_cur(kk)=mask_cur(1)
235 c case 2: just below last grid center=> last cell value
236 elseif (prof_depth(file_cur,kk).GE.-rC(nr)) then
237 if ( prof_depth(file_cur,kk) .LT.
238 & (-rC(nr)+drC(nr)/2) ) then
239 traj_cur_out(kk)=traj_cur(nr)
240 prof_mask1D_cur(kk)=mask_cur(nr)
241 endif
242 c case 3: between two grid centers
243 else
244 kcur=0
245 do k=1,nr-1
246 if ((prof_depth(file_cur,kk).GE.-rC(k)).AND.
247 & (prof_depth(file_cur,kk).LT.-rC(k+1))) then
248 kcur=k
249 endif
250 enddo
251 if (kcur.EQ.0) then
252 print*,"profiles_interp unexpected case: stop 1"
253 stop
254 endif
255 if (mask_cur(kcur+1).EQ.1.) then
256 c subcase 1: 2 wet points=>linear interpolation
257 tmp_coeff=(prof_depth(file_cur,kk)+rC(kcur))/
258 & (-rC(kcur+1)+rC(kcur))
259 traj_cur_out(kk)=(1-tmp_coeff)*traj_cur(kcur)
260 & +tmp_coeff*traj_cur(kcur+1)
261 prof_mask1D_cur(kk)=1
262 if (mask_cur(kcur).EQ.0.) then
263 print*,"profiles_interp unexpected case: stop 2"
264 stop
265 endif
266 elseif (prof_depth(file_cur,kk).LT.-rF(kcur+1)) then
267 c subcase 2: only 1 wet point just above=>upper cell value
268 traj_cur_out(kk)=traj_cur(kcur)
269 prof_mask1D_cur(kk)=mask_cur(kcur)
270 endif
271 endif
272 enddo
273
274 ENDDO
275 ENDDO
276
277 #endif
278
279 end
280

  ViewVC Help
Powered by ViewVC 1.1.22