1 |
C $Header: /u/gcmpack/MITgcm/pkg/ecco/cost_ssh.F,v 1.20 2012/08/10 19:45:26 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "ECCO_OPTIONS.h" |
5 |
|
6 |
|
7 |
subroutine cost_ssh( |
8 |
I myiter, |
9 |
I mytime, |
10 |
I mythid |
11 |
& ) |
12 |
|
13 |
c ================================================================== |
14 |
c SUBROUTINE cost_ssh |
15 |
c ================================================================== |
16 |
c |
17 |
c o Evaluate cost function contribution of sea surface height. |
18 |
c using of geoid error covariances requires regular model grid |
19 |
c |
20 |
c started: Detlef Stammer, Ralf Giering Jul-1996 |
21 |
c |
22 |
c changed: Christian Eckert eckert@mit.edu 25-Feb-2000 |
23 |
c |
24 |
c - Restructured the code in order to create a package |
25 |
c for the MITgcmUV. |
26 |
c |
27 |
c changed: Ralf Giering Ralf.Giering@FastOpt.de 12-Jun-2001 |
28 |
c |
29 |
c - totally rewrite for parallel processing |
30 |
c |
31 |
c ================================================================== |
32 |
c SUBROUTINE cost_ssh |
33 |
c ================================================================== |
34 |
|
35 |
implicit none |
36 |
|
37 |
c == global variables == |
38 |
|
39 |
#include "EEPARAMS.h" |
40 |
#include "SIZE.h" |
41 |
#include "PARAMS.h" |
42 |
|
43 |
#include "ecco_cost.h" |
44 |
#include "CTRL_SIZE.h" |
45 |
#include "ctrl.h" |
46 |
#include "ctrl_dummy.h" |
47 |
#include "optim.h" |
48 |
#include "DYNVARS.h" |
49 |
#ifdef ALLOW_PROFILES |
50 |
#include "profiles.h" |
51 |
#endif |
52 |
|
53 |
c == routine arguments == |
54 |
|
55 |
integer myiter |
56 |
_RL mytime |
57 |
integer mythid |
58 |
|
59 |
#ifdef ALLOW_SSH_COST_CONTRIBUTION |
60 |
c == local variables == |
61 |
|
62 |
integer bi,bj |
63 |
integer i,j |
64 |
integer itlo,ithi |
65 |
integer jtlo,jthi |
66 |
integer jmin,jmax |
67 |
integer imin,imax |
68 |
integer irec |
69 |
integer ilps |
70 |
|
71 |
logical doglobalread |
72 |
logical ladinit |
73 |
|
74 |
_RL offset |
75 |
_RL costmean |
76 |
_RL offset_sum |
77 |
_RL psmean ( 1-olx:snx+olx, 1-oly:sny+oly, nsx, nsy ) |
78 |
_RL wwwtp ( 1-olx:snx+olx, 1-oly:sny+oly ) |
79 |
_RL wwwers ( 1-olx:snx+olx, 1-oly:sny+oly ) |
80 |
_RL wwwgfo ( 1-olx:snx+olx, 1-oly:sny+oly ) |
81 |
_RL junk |
82 |
|
83 |
character*(80) fname |
84 |
character*(MAX_LEN_MBUF) msgbuf |
85 |
|
86 |
c == external functions == |
87 |
|
88 |
integer ilnblnk |
89 |
external ilnblnk |
90 |
|
91 |
c == end of interface == |
92 |
|
93 |
jtlo = mybylo(mythid) |
94 |
jthi = mybyhi(mythid) |
95 |
itlo = mybxlo(mythid) |
96 |
ithi = mybxhi(mythid) |
97 |
jmin = 1 |
98 |
jmax = sny |
99 |
imin = 1 |
100 |
imax = snx |
101 |
|
102 |
c-- Initialise local variables. |
103 |
costmean = 0. _d 0 |
104 |
|
105 |
do j = jmin, jmax |
106 |
do i = imin, imax |
107 |
wwwtp(i,j) = 0. _d 0 |
108 |
wwwers(i,j) = 0. _d 0 |
109 |
wwwgfo(i,j) = 0. _d 0 |
110 |
enddo |
111 |
enddo |
112 |
|
113 |
c-- First, read tiled data. |
114 |
doglobalread = .false. |
115 |
ladinit = .false. |
116 |
|
117 |
write(fname(1:80),'(80a)') ' ' |
118 |
ilps=ilnblnk( psbarfile ) |
119 |
write(fname(1:80),'(2a,i10.10)') |
120 |
& psbarfile(1:ilps),'.',optimcycle |
121 |
|
122 |
c-- ============ |
123 |
c-- Mean values. |
124 |
c-- ============ |
125 |
|
126 |
do bj = jtlo,jthi |
127 |
do bi = itlo,ithi |
128 |
do j = jmin,jmax |
129 |
do i = imin,imax |
130 |
psmean(i,j,bi,bj) = 0. _d 0 |
131 |
enddo |
132 |
enddo |
133 |
enddo |
134 |
enddo |
135 |
|
136 |
c-- Read mean field and generate mask |
137 |
call cost_ReadTopexMean( mythid ) |
138 |
|
139 |
c-- Loop over records for the first time. |
140 |
do irec = 1, ndaysrec |
141 |
|
142 |
c-- Compute the mean over all psbar records. |
143 |
call active_read_xy( fname, psbar, irec, doglobalread, |
144 |
& ladinit, optimcycle, mythid, |
145 |
& xx_psbar_mean_dummy ) |
146 |
|
147 |
do bj = jtlo,jthi |
148 |
do bi = itlo,ithi |
149 |
do j = jmin,jmax |
150 |
do i = imin,imax |
151 |
psmean(i,j,bi,bj) = psmean(i,j,bi,bj) + |
152 |
& psbar(i,j,bi,bj)/ |
153 |
& float(ndaysrec) |
154 |
enddo |
155 |
enddo |
156 |
enddo |
157 |
enddo |
158 |
|
159 |
enddo |
160 |
|
161 |
c-- Compute and remove offset for current tile and sum over all |
162 |
c-- tiles of this instance. |
163 |
offset = 0. _d 0 |
164 |
offset_sum = 0. _d 0 |
165 |
|
166 |
c-- Sum over this thread tiles. |
167 |
do bj = jtlo,jthi |
168 |
do bi = itlo,ithi |
169 |
do j = 1,sny |
170 |
do i = 1,snx |
171 |
offset = offset + |
172 |
& mdtmask(i,j,bi,bj)*cosphi(i,j,bi,bj)* |
173 |
& (mdt(i,j,bi,bj) - psmean(i,j,bi,bj)) |
174 |
offset_sum = offset_sum + |
175 |
& mdtmask(i,j,bi,bj)*cosphi(i,j,bi,bj) |
176 |
enddo |
177 |
enddo |
178 |
enddo |
179 |
enddo |
180 |
|
181 |
c-- Do a global summation. |
182 |
_GLOBAL_SUM_RL( offset , mythid ) |
183 |
_GLOBAL_SUM_RL( offset_sum , mythid ) |
184 |
|
185 |
if (offset_sum .eq. 0.0) then |
186 |
_BEGIN_MASTER( mythid ) |
187 |
write(msgbuf,'(a)') ' cost_ssh: offset_sum = zero!' |
188 |
call print_message( msgbuf, standardmessageunit, |
189 |
& SQUEEZE_RIGHT , mythid) |
190 |
_END_MASTER( mythid ) |
191 |
cph stop ' ... stopped in cost_ssh.' |
192 |
else |
193 |
_BEGIN_MASTER( mythid ) |
194 |
write(msgbuf,'(a,d22.15)') |
195 |
& ' cost_ssh: offset_sum = ',offset_sum |
196 |
call print_message( msgbuf, standardmessageunit, |
197 |
& SQUEEZE_RIGHT , mythid) |
198 |
_END_MASTER( mythid ) |
199 |
endif |
200 |
|
201 |
offset = offset / offset_sum |
202 |
|
203 |
#ifdef ALLOW_PROFILES |
204 |
if ( usePROFILES ) then |
205 |
do bj = jtlo,jthi |
206 |
do bi = itlo,ithi |
207 |
do j = 1,sny |
208 |
do i = 1,snx |
209 |
prof_etan_mean(i,j,bi,bj)=offset+psmean(i,j,bi,bj) |
210 |
enddo |
211 |
enddo |
212 |
enddo |
213 |
enddo |
214 |
_EXCH_XY_RL( prof_etan_mean, mythid ) |
215 |
endif |
216 |
#endif |
217 |
|
218 |
#ifdef ALLOW_SSH_MEAN_COST_CONTRIBUTION |
219 |
#ifndef ALLOW_SSH_TOT |
220 |
c-- ========== |
221 |
c-- Mean |
222 |
c-- ========== |
223 |
c-- compute mean ssh difference cost contribution |
224 |
call cost_ssh_mean( |
225 |
I psmean, offset |
226 |
O , costmean |
227 |
I , mythid |
228 |
& ) |
229 |
|
230 |
|
231 |
objf_hmean = costmean |
232 |
#endif /* ALLOW_SSH_TOT */ |
233 |
#endif /* ALLOW_SSH_MEAN_COST_CONTRIBUTION */ |
234 |
|
235 |
c-- ========== |
236 |
c-- Anomalies. |
237 |
c-- ========== |
238 |
|
239 |
c-- Loop over records for the second time. |
240 |
do irec = 1, ndaysrec |
241 |
|
242 |
call active_read_xy( fname, psbar, irec, doglobalread, |
243 |
& ladinit, optimcycle, mythid, |
244 |
& xx_psbar_mean_dummy ) |
245 |
|
246 |
#ifdef ALLOW_SSH_TPANOM_COST_CONTRIBUTION |
247 |
call cost_readtopex( irec, mythid ) |
248 |
#endif |
249 |
|
250 |
#ifdef ALLOW_SSH_ERSANOM_COST_CONTRIBUTION |
251 |
call cost_readers( irec, mythid ) |
252 |
#endif |
253 |
|
254 |
#ifdef ALLOW_SSH_GFOANOM_COST_CONTRIBUTION |
255 |
call cost_readgfo( irec, mythid ) |
256 |
#endif |
257 |
|
258 |
do bj = jtlo,jthi |
259 |
do bi = itlo,ithi |
260 |
|
261 |
#ifdef ALLOW_SSH_TPANOM_COST_CONTRIBUTION |
262 |
do j = jmin,jmax |
263 |
do i = imin,imax |
264 |
c-- The array psobs contains SSH anomalies. |
265 |
wwwtp(i,j) = wtp(i,j,bi,bj) *cosphi(i,j,bi,bj) |
266 |
#ifndef ALLOW_SSH_TOT |
267 |
junk = ((psbar(i,j,bi,bj) - psmean(i,j,bi,bj)) - |
268 |
& tpobs(i,j,bi,bj)) |
269 |
& *tpmask(i,j,bi,bj) |
270 |
objf_tp(bi,bj) = objf_tp(bi,bj) |
271 |
& + junk*junk*wwwtp(i,j) |
272 |
if ( wwwtp(i,j)*junk .ne. 0. ) |
273 |
& num_tp(bi,bj) = num_tp(bi,bj) + 1. _d 0 |
274 |
#else |
275 |
if (mdtmask(i,j,bi,bj)*tpmask(i,j,bi,bj) |
276 |
& *wp(i,j,bi,bj)*wwwtp(i,j) .ne.0.) then |
277 |
junk = ( psbar(i,j,bi,bj) - |
278 |
& (tpobs(i,j,bi,bj)+mdt(i,j,bi,bj)-offset) ) |
279 |
objf_tp(bi,bj) = objf_tp(bi,bj) |
280 |
& +junk*junk/( 1/wp(i,j,bi,bj)+1/wwwtp(i,j) ) |
281 |
num_tp(bi,bj) = num_tp(bi,bj) + 1. _d 0 |
282 |
endif |
283 |
#endif /* ALLOW_SSH_TOT */ |
284 |
enddo |
285 |
enddo |
286 |
#endif |
287 |
|
288 |
#ifdef ALLOW_SSH_ERSANOM_COST_CONTRIBUTION |
289 |
do j = jmin,jmax |
290 |
do i = imin,imax |
291 |
c-- The array ersobs contains SSH anomalies. |
292 |
wwwers(i,j) = wers(i,j,bi,bj)*cosphi(i,j,bi,bj) |
293 |
#ifndef ALLOW_SSH_TOT |
294 |
junk = ((psbar(i,j,bi,bj) - psmean(i,j,bi,bj)) - |
295 |
& ersobs(i,j,bi,bj)) |
296 |
& *ersmask(i,j,bi,bj) |
297 |
objf_ers(bi,bj) = objf_ers(bi,bj) |
298 |
& + junk*junk*wwwers(i,j) |
299 |
if ( wwwers(i,j)*junk .ne. 0. ) |
300 |
& num_ers(bi,bj) = num_ers(bi,bj) + 1. _d 0 |
301 |
#else |
302 |
if (mdtmask(i,j,bi,bj)*ersmask(i,j,bi,bj) |
303 |
& *wp(i,j,bi,bj)*wwwers(i,j) .ne.0.) then |
304 |
junk = ( psbar(i,j,bi,bj) - |
305 |
& (ersobs(i,j,bi,bj)+mdt(i,j,bi,bj)-offset) ) |
306 |
objf_ers(bi,bj) = objf_ers(bi,bj) |
307 |
& +junk*junk/( 1/wp(i,j,bi,bj)+1/wwwers(i,j) ) |
308 |
num_ers(bi,bj) = num_ers(bi,bj) + 1. _d 0 |
309 |
endif |
310 |
#endif /* ALLOW_SSH_TOT */ |
311 |
enddo |
312 |
enddo |
313 |
#endif |
314 |
|
315 |
#ifdef ALLOW_SSH_GFOANOM_COST_CONTRIBUTION |
316 |
do j = jmin,jmax |
317 |
do i = imin,imax |
318 |
c-- The array gfoobs contains SSH anomalies. |
319 |
wwwgfo(i,j) = wgfo(i,j,bi,bj)*cosphi(i,j,bi,bj) |
320 |
#ifndef ALLOW_SSH_TOT |
321 |
junk = ((psbar(i,j,bi,bj) - psmean(i,j,bi,bj)) - |
322 |
& gfoobs(i,j,bi,bj)) |
323 |
& *gfomask(i,j,bi,bj) |
324 |
objf_gfo(bi,bj) = objf_gfo(bi,bj) |
325 |
& + junk*junk*wwwgfo(i,j) |
326 |
if ( wwwgfo(i,j)*junk .ne. 0. ) |
327 |
& num_gfo(bi,bj) = num_gfo(bi,bj) + 1. _d 0 |
328 |
#else |
329 |
if (mdtmask(i,j,bi,bj)*gfomask(i,j,bi,bj) |
330 |
& *wp(i,j,bi,bj)*wwwgfo(i,j) .ne.0.) then |
331 |
junk = ( psbar(i,j,bi,bj) - |
332 |
& (gfoobs(i,j,bi,bj)+mdt(i,j,bi,bj)-offset) ) |
333 |
objf_gfo(bi,bj) = objf_gfo(bi,bj) |
334 |
& +junk*junk/( 1/wp(i,j,bi,bj)+1/wwwgfo(i,j) ) |
335 |
num_gfo(bi,bj) = num_gfo(bi,bj) + 1. _d 0 |
336 |
endif |
337 |
#endif /* ALLOW_SSH_TOT */ |
338 |
enddo |
339 |
enddo |
340 |
#endif |
341 |
|
342 |
enddo |
343 |
enddo |
344 |
|
345 |
enddo |
346 |
c-- End of second loop over records. |
347 |
|
348 |
do bj = jtlo,jthi |
349 |
do bi = itlo,ithi |
350 |
objf_h(bi,bj) = objf_h(bi,bj) + |
351 |
& objf_tp(bi,bj) + objf_ers(bi,bj) + objf_gfo(bi,bj) |
352 |
num_h(bi,bj) = num_h(bi,bj) + |
353 |
& num_tp(bi,bj) + num_ers(bi,bj) + num_gfo(bi,bj) |
354 |
enddo |
355 |
enddo |
356 |
|
357 |
|
358 |
#endif /* ifdef ALLOW_SSH_COST_CONTRIBUTION */ |
359 |
|
360 |
end |