/[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.2 - (show annotations) (download)
Wed Mar 29 21:57:15 2006 UTC (18 years, 2 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint58d_post
Changes since 1.1: +124 -119 lines
clean routines and fix details

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

  ViewVC Help
Powered by ViewVC 1.1.22