1 |
C $Header: /u/gcmpack/MITgcm/pkg/ecco/cost_curmtr.F,v 1.1 2003/11/06 22:10:07 heimbach Exp $ |
2 |
|
3 |
#include "COST_CPPOPTIONS.h" |
4 |
|
5 |
subroutine cost_CurMtr( |
6 |
I myiter, |
7 |
I mytime, |
8 |
I mythid |
9 |
& ) |
10 |
|
11 |
c ================================================================== |
12 |
c SUBROUTINE cost_CurMtr |
13 |
c ================================================================== |
14 |
c |
15 |
c o Evaluate cost function contribution of Vector-Measuring |
16 |
c Current Meters. |
17 |
c |
18 |
c started: Elisabeth Remy eremy@ucsd.edu 30-Aug-2000 |
19 |
c modified: G. Gebbie, gebbie@mit.edu, 3- May- 2002. |
20 |
c |
21 |
c ================================================================== |
22 |
c SUBROUTINE cost_CurMtr |
23 |
c ================================================================== |
24 |
|
25 |
implicit none |
26 |
|
27 |
c == global variables == |
28 |
|
29 |
#include "EEPARAMS.h" |
30 |
#include "SIZE.h" |
31 |
#include "GRID.h" |
32 |
#include "DYNVARS.h" |
33 |
|
34 |
#include "cal.h" |
35 |
#include "ecco_cost.h" |
36 |
#include "ctrl.h" |
37 |
#include "ctrl_dummy.h" |
38 |
#include "optim.h" |
39 |
|
40 |
c == routine arguments == |
41 |
|
42 |
integer myiter |
43 |
_RL mytime |
44 |
integer mythid |
45 |
|
46 |
c == local variables == |
47 |
|
48 |
integer bi,bj |
49 |
integer i,j,k |
50 |
integer itlo,ithi |
51 |
integer jtlo,jthi |
52 |
integer jmin,jmax |
53 |
integer imin,imax |
54 |
integer nrec |
55 |
integer irec |
56 |
integer ilu |
57 |
|
58 |
_RL fctile_curmtr |
59 |
_RL fcthread_curmtr |
60 |
_RL wwwu (1-olx:snx+olx,1-oly:sny+oly) |
61 |
_RL wwwv (1-olx:snx+olx,1-oly:sny+oly) |
62 |
_RL wu (1-olx:snx+olx,1-oly:sny+oly) |
63 |
_RL wv (1-olx:snx+olx,1-oly:sny+oly) |
64 |
_RL umask (1-olx:snx+olx,1-oly:sny+oly) |
65 |
_RL vmask (1-olx:snx+olx,1-oly:sny+oly) |
66 |
_RL tmpuobs (1-olx:snx+olx,1-oly:sny+oly) |
67 |
_RL tmpubar (1-olx:snx+olx,1-oly:sny+oly) |
68 |
_RL tmpvobs (1-olx:snx+olx,1-oly:sny+oly) |
69 |
_RL tmpvbar (1-olx:snx+olx,1-oly:sny+oly) |
70 |
_RL spval |
71 |
|
72 |
character*(80) fnameuvel |
73 |
character*(80) fnamevvel |
74 |
|
75 |
logical doglobalread |
76 |
logical ladinit |
77 |
|
78 |
character*(MAX_LEN_MBUF) msgbuf |
79 |
|
80 |
c == external functions == |
81 |
|
82 |
integer ilnblnk |
83 |
external ilnblnk |
84 |
|
85 |
c == end of interface == |
86 |
|
87 |
jtlo = mybylo(mythid) |
88 |
jthi = mybyhi(mythid) |
89 |
itlo = mybxlo(mythid) |
90 |
ithi = mybxhi(mythid) |
91 |
jmin = 1 |
92 |
jmax = sny |
93 |
imin = 1 |
94 |
imax = snx |
95 |
|
96 |
spval = -9990. |
97 |
|
98 |
c-- Read state record from global file. |
99 |
doglobalread = .false. |
100 |
ladinit = .false. |
101 |
|
102 |
#ifdef ALLOW_CURMTR_COST_CONTRIBUTION |
103 |
|
104 |
#ifdef ECCO_VERBOSE |
105 |
write(msgbuf,'(a)') ' ' |
106 |
call print_message( msgbuf, standardmessageunit, |
107 |
& SQUEEZE_RIGHT , mythid) |
108 |
write(msgbuf,'(a,i8.8)') |
109 |
& ' cost_Curmtr: number of records to process =', nmonsrec |
110 |
call print_message( msgbuf, standardmessageunit, |
111 |
& SQUEEZE_RIGHT , mythid) |
112 |
write(msgbuf,'(a)') ' ' |
113 |
call print_message( msgbuf, standardmessageunit, |
114 |
& SQUEEZE_RIGHT , mythid) |
115 |
#endif |
116 |
|
117 |
if (optimcycle .ge. 0) then |
118 |
ilu=ilnblnk( ubarfile ) |
119 |
write(fnameuvel(1:80),'(2a,i10.10)') |
120 |
& ubarfile(1:ilu), '.', optimcycle |
121 |
endif |
122 |
|
123 |
if (optimcycle .ge. 0) then |
124 |
ilu=ilnblnk( vbarfile ) |
125 |
write(fnamevvel(1:80),'(2a,i10.10)') |
126 |
& vbarfile(1:ilu), '.', optimcycle |
127 |
endif |
128 |
|
129 |
fcthread_curmtr = 0. _d 0 |
130 |
|
131 |
c-- Loop over records. |
132 |
do irec = 1,nmonsrec |
133 |
|
134 |
cgg First do the Zonal Velocity. |
135 |
c-- Read time averages and the monthly mean data. |
136 |
call active_read_xyz( fnameuvel, ubar, irec, |
137 |
& doglobalread, ladinit, |
138 |
& optimcycle, mythid, xx_ubar_mean_dummy ) |
139 |
|
140 |
|
141 |
cgg Then meridional velocity. |
142 |
call active_read_xyz( fnamevvel, vbar, irec, |
143 |
& doglobalread, ladinit, |
144 |
& optimcycle, mythid, xx_vbar_mean_dummy ) |
145 |
|
146 |
cgg( fixed precision of file.) |
147 |
call mdsreadfield( curmtrufile,cost_iprec, 'RL', nr, curmtruobs, |
148 |
& irec, mythid) |
149 |
|
150 |
call mdsreadfield( curmtrvfile,cost_iprec, 'RL', nr, curmtrvobs, |
151 |
& irec, mythid) |
152 |
|
153 |
|
154 |
c-- Loop over this thread's tiles. |
155 |
do bj = jtlo,jthi |
156 |
do bi = itlo,ithi |
157 |
c-- Loop over the model layers |
158 |
|
159 |
fctile_curmtr = 0. _d 0 |
160 |
|
161 |
do k = 1,nr |
162 |
|
163 |
c-- Determine the weights to be used. |
164 |
do j = jmin,jmax |
165 |
do i = imin,imax |
166 |
umask(i,j) = 1. _d 0 |
167 |
vmask(i,j) = 1. _d 0 |
168 |
if (curmtruobs(i,j,k,bi,bj) .eq. 0.) then |
169 |
umask(i,j) = 0. _d 0 |
170 |
endif |
171 |
|
172 |
if (curmtrvobs(i,j,k,bi,bj) .eq. 0.) then |
173 |
vmask(i,j) = 0. _d 0 |
174 |
endif |
175 |
|
176 |
if (curmtruobs(i,j,k,bi,bj) .lt. spval) then |
177 |
umask(i,j) = 0. _d 0 |
178 |
endif |
179 |
|
180 |
if (curmtrvobs(i,j,k,bi,bj) .lt. spval) then |
181 |
vmask(i,j) = 0. _d 0 |
182 |
endif |
183 |
|
184 |
cph( |
185 |
cph print *, 'WARNING: SPECIFIC SETUP FOR ECCO' |
186 |
cph below statement could be replaced by following |
187 |
cph to make it independnet of Nr: |
188 |
cph |
189 |
cph if ( rC(K) .GT. -1000. ) then |
190 |
cph) |
191 |
c set cmask=0 in areas shallower than 1000m |
192 |
cgg if (_hFacC(i,j,13,bi,bj) .eq. 0.) then |
193 |
cgg cmask(i,j) = 0. _d 0 |
194 |
cgg endif |
195 |
|
196 |
if (_hFacW(i,j,k,bi,bj) .eq. 0.) then |
197 |
umask(i,j) = 0. _d 0 |
198 |
endif |
199 |
|
200 |
if (_hFacS(i,j,k,bi,bj) .eq. 0.) then |
201 |
vmask(i,j) = 0. _d 0 |
202 |
endif |
203 |
|
204 |
enddo |
205 |
enddo |
206 |
|
207 |
do j = jmin,jmax |
208 |
do i = imin,imax |
209 |
wwwu(i,j) = cosphi(i,j,bi,bj)*umask(i,j) |
210 |
wwwv(i,j) = cosphi(i,j,bi,bj)*vmask(i,j) |
211 |
|
212 |
tmpuobs(i,j) = curmtruobs(i,j,k,bi,bj) |
213 |
tmpubar(i,j) = ubar(i,j,k,bi,bj) |
214 |
|
215 |
tmpvobs(i,j) = curmtrvobs(i,j,k,bi,bj) |
216 |
tmpvbar(i,j) = vbar(i,j,k,bi,bj) |
217 |
|
218 |
#ifdef SUBEX_2DEG |
219 |
cgg( Perform the comparison in observation space. |
220 |
if ( (i.eq.5) .and. (j.eq.13)) then |
221 |
tmpubar(i,j) = ubar(5,12,k,bi,bj) |
222 |
tmpvbar(i,j) = (vbar(4,12,k,bi,bj) + vbar(5,12,k,bi,bj) |
223 |
& +vbar(4,13,k,bi,bj) + vbar(5,13,k,bi,bj))/4. |
224 |
endif |
225 |
if ( (i .eq. 11) .and. (j .eq. 13)) then |
226 |
tmpubar(i,j) = ubar(11,12,k,bi,bj) |
227 |
tmpvbar(i,j) = (vbar(10,12,k,bi,bj) + vbar(11,12,k,bi,bj) |
228 |
& +vbar(10,13,k,bi,bj) + vbar(11,13,k,bi,bj))/4. |
229 |
endif |
230 |
if ( (i .eq. 8) .and. (j .eq. 9)) then |
231 |
tmpubar(i,j) = (ubar(7,8,k,bi,bj) + ubar(8,8,k,bi,bj) |
232 |
& +ubar(7,9,k,bi,bj) + ubar(8,9,k,bi,bj))/4. |
233 |
tmpvbar(i,j) = vbar(7,9,k,bi,bj) |
234 |
endif |
235 |
if ( (i .eq. 5) .and. (j .eq. 5)) then |
236 |
tmpubar(i,j) = (ubar(5,4,k,bi,bj) + ubar(5,5,k,bi,bj))/2. |
237 |
tmpvbar(i,j) = (vbar(4,5,k,bi,bj) + vbar(5,5,k,bi,bj))/2. |
238 |
endif |
239 |
if ( (i .eq. 11) .and. (j .eq. 5)) then |
240 |
tmpubar(i,j) = (ubar(11,4,k,bi,bj)+ubar(11,5,k,bi,bj))/2. |
241 |
tmpvbar(i,j) = (vbar(10,5,k,bi,bj)+vbar(11,5,k,bi,bj))/2. |
242 |
endif |
243 |
#endif |
244 |
|
245 |
cgg( Weights are subject to individual's preference. |
246 |
wu(i,j) = wcurrent2(i,j,k,bi,bj) |
247 |
wv(i,j) = wcurrent2(i,j,k,bi,bj) |
248 |
cgg wtmp(i,j) = wtheta2(i,j,k,bi,bj) |
249 |
enddo |
250 |
enddo |
251 |
|
252 |
do j = jmin,jmax |
253 |
do i = imin,imax |
254 |
c-- The array tmpuobs contains current meter velocities. |
255 |
cgg if(umask(i,j).eq.1.0 .and.tmpubar(i,j) .ne. 0. ) then |
256 |
cgg print *,'cost_curmtr U',i,j,tmpubar(i,j),tmpuobs(i,j) |
257 |
cgg endif |
258 |
|
259 |
cgg if(vmask(i,j).eq.1.0.and.tmpvbar(i,j) .ne. 0.) then |
260 |
cgg print *,'cost_curmtr V',i,j,tmpvbar(i,j),tmpvobs(i,j) |
261 |
cgg endif |
262 |
|
263 |
cgg( Add one more zero check. |
264 |
if (tmpubar(i,j) .ne. 0.) then |
265 |
fctile_curmtr = fctile_curmtr + |
266 |
& (wu(i,j)*wwwu(i,j))* |
267 |
& (tmpubar(i,j)-tmpuobs(i,j))* |
268 |
& (tmpubar(i,j)-tmpuobs(i,j)) |
269 |
if ( wu(i,j)*wwwu(i,j)) .ne. 0. ) |
270 |
& num_curmtr(bi,bj) = num_curmtr(bi,bj) + 1. _d 0 |
271 |
endif |
272 |
|
273 |
cgg( Add one more zero check. |
274 |
if (tmpvbar(i,j) .ne. 0.) then |
275 |
fctile_curmtr = fctile_curmtr + |
276 |
& (wv(i,j)*wwwv(i,j))* |
277 |
& (tmpvbar(i,j)-tmpvobs(i,j))* |
278 |
& (tmpvbar(i,j)-tmpvobs(i,j)) |
279 |
if ( wv(i,j)*wwwv(i,j)) .ne. 0. ) |
280 |
& num_curmtr(bi,bj) = num_curmtr(bi,bj) + 1. _d 0 |
281 |
endif |
282 |
enddo |
283 |
enddo |
284 |
enddo |
285 |
c-- End of loop over layers. |
286 |
|
287 |
fcthread_curmtr = fcthread_curmtr + fctile_curmtr |
288 |
objf_curmtr(bi,bj) = objf_curmtr(bi,bj) + fctile_curmtr |
289 |
|
290 |
#ifdef ECCO_VERBOSE |
291 |
write(msgbuf,'(a)') ' ' |
292 |
call print_message( msgbuf, standardmessageunit, |
293 |
& SQUEEZE_RIGHT , mythid) |
294 |
write(msgbuf,'(a,i8.8,1x,i3.3,1x,i3.3)') |
295 |
& ' COST_curmtr: irec,bi,bj = ',irec,bi,bj |
296 |
call print_message( msgbuf, standardmessageunit, |
297 |
& SQUEEZE_RIGHT , mythid) |
298 |
write(msgbuf,'(a,d22.15)') |
299 |
& ' COST_Curmtr: cost function = ', fctile_curmtr |
300 |
call print_message( msgbuf, standardmessageunit, |
301 |
& SQUEEZE_RIGHT , mythid) |
302 |
write(msgbuf,'(a)') ' ' |
303 |
call print_message( msgbuf, standardmessageunit, |
304 |
& SQUEEZE_RIGHT , mythid) |
305 |
#endif |
306 |
|
307 |
enddo |
308 |
enddo |
309 |
|
310 |
#ifdef ECCO_VERBOSE |
311 |
c-- Print cost function for all tiles. |
312 |
_GLOBAL_SUM_R8( fcthread_curmtr , myThid ) |
313 |
write(msgbuf,'(a)') ' ' |
314 |
call print_message( msgbuf, standardmessageunit, |
315 |
& SQUEEZE_RIGHT , mythid) |
316 |
write(msgbuf,'(a,i8.8)') |
317 |
& ' cost_Curmtr: irec = ',irec |
318 |
call print_message( msgbuf, standardmessageunit, |
319 |
& SQUEEZE_RIGHT , mythid) |
320 |
write(msgbuf,'(a,a,d22.15)') |
321 |
& ' global cost function value', |
322 |
& ' ( CurMtr ) = ',fcthread_curmtr |
323 |
call print_message( msgbuf, standardmessageunit, |
324 |
& SQUEEZE_RIGHT , mythid) |
325 |
write(msgbuf,'(a)') ' ' |
326 |
call print_message( msgbuf, standardmessageunit, |
327 |
& SQUEEZE_RIGHT , mythid) |
328 |
#endif |
329 |
|
330 |
enddo |
331 |
c-- End of second loop over records. |
332 |
|
333 |
#else |
334 |
c-- Do not enter the calculation of the CTD temperature contribution |
335 |
c-- to the final cost function. |
336 |
|
337 |
fctile_curmtr = 0. _d 0 |
338 |
fcthread_curmtr = 0. _d 0 |
339 |
|
340 |
crg |
341 |
nrec = 1 |
342 |
crg |
343 |
|
344 |
_BEGIN_MASTER( mythid ) |
345 |
write(msgbuf,'(a)') ' ' |
346 |
call print_message( msgbuf, standardmessageunit, |
347 |
& SQUEEZE_RIGHT , mythid) |
348 |
write(msgbuf,'(a,a)') |
349 |
& ' cost_Curmtr: no contribution of CTD temperature ', |
350 |
& ' to cost function.' |
351 |
call print_message( msgbuf, standardmessageunit, |
352 |
& SQUEEZE_RIGHT , mythid) |
353 |
write(msgbuf,'(a,a,i9.8)') |
354 |
& ' cost_Curmtr: number of records that would have', |
355 |
& ' been processed: ',nrec |
356 |
call print_message( msgbuf, standardmessageunit, |
357 |
& SQUEEZE_RIGHT , mythid) |
358 |
write(msgbuf,'(a)') ' ' |
359 |
call print_message( msgbuf, standardmessageunit, |
360 |
& SQUEEZE_RIGHT , mythid) |
361 |
_END_MASTER( mythid ) |
362 |
#endif |
363 |
|
364 |
return |
365 |
end |
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|