1 |
zhc |
1.1 |
C $Header: /u/gcmpack/MITgcm/pkg/ecco/cost_bp.F,v 1.7 2012/09/04 15:04:51 gforget Exp $ |
2 |
|
|
C $Name: checkpoint64x $ |
3 |
|
|
|
4 |
|
|
#include "ECCO_OPTIONS.h" |
5 |
|
|
|
6 |
|
|
|
7 |
|
|
subroutine cost_bp( |
8 |
|
|
I myiter, |
9 |
|
|
I mytime, |
10 |
|
|
I mythid |
11 |
|
|
& ) |
12 |
|
|
|
13 |
|
|
c ================================================================== |
14 |
|
|
c SUBROUTINE cost_bp |
15 |
|
|
c ================================================================== |
16 |
|
|
c |
17 |
|
|
c o Evaluate cost function contribution of bottom pressure anoamlies |
18 |
|
|
c => GRACE data |
19 |
|
|
c |
20 |
|
|
c started: Gael Forget Oct-2009 |
21 |
|
|
c |
22 |
|
|
c ================================================================== |
23 |
|
|
c SUBROUTINE cost_bp |
24 |
|
|
c ================================================================== |
25 |
|
|
|
26 |
|
|
implicit none |
27 |
|
|
|
28 |
|
|
c == global variables == |
29 |
|
|
|
30 |
|
|
#include "EEPARAMS.h" |
31 |
|
|
#include "SIZE.h" |
32 |
|
|
#include "PARAMS.h" |
33 |
|
|
#include "GRID.h" |
34 |
|
|
|
35 |
|
|
#include "ecco_cost.h" |
36 |
|
|
#include "CTRL_SIZE.h" |
37 |
|
|
#include "ctrl.h" |
38 |
|
|
#include "ctrl_dummy.h" |
39 |
|
|
#include "optim.h" |
40 |
|
|
#include "DYNVARS.h" |
41 |
|
|
#ifdef ALLOW_PROFILES |
42 |
|
|
#include "profiles.h" |
43 |
|
|
#endif |
44 |
|
|
|
45 |
|
|
c == routine arguments == |
46 |
|
|
|
47 |
|
|
integer myiter |
48 |
|
|
_RL mytime |
49 |
|
|
integer mythid |
50 |
|
|
|
51 |
|
|
#ifdef ALLOW_BP_COST_CONTRIBUTION |
52 |
|
|
|
53 |
|
|
c == local variables == |
54 |
|
|
|
55 |
|
|
integer bi,bj |
56 |
|
|
integer i,j |
57 |
|
|
integer itlo,ithi |
58 |
|
|
integer jtlo,jthi |
59 |
|
|
integer irec |
60 |
|
|
integer ilps |
61 |
|
|
|
62 |
|
|
logical doglobalread |
63 |
|
|
logical ladinit |
64 |
|
|
|
65 |
|
|
_RL bpdifmean ( 1-olx:snx+olx, 1-oly:sny+oly, nsx, nsy ) |
66 |
|
|
_RL bpdifanom ( 1-olx:snx+olx, 1-oly:sny+oly, nsx, nsy ) |
67 |
|
|
_RL bpdatmean ( 1-olx:snx+olx, 1-oly:sny+oly, nsx, nsy ) |
68 |
|
|
_RL bpdatanom ( 1-olx:snx+olx, 1-oly:sny+oly, nsx, nsy ) |
69 |
|
|
_RL bpcount ( 1-olx:snx+olx, 1-oly:sny+oly, nsx, nsy ) |
70 |
|
|
_RL junk,junkweight |
71 |
|
|
|
72 |
|
|
character*(80) fname |
73 |
|
|
character*(80) fname4test |
74 |
|
|
character*(MAX_LEN_MBUF) msgbuf |
75 |
|
|
_RL fac |
76 |
|
|
|
77 |
|
|
_RL offset |
78 |
|
|
_RL offset_sum |
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 |
|
|
|
92 |
|
|
c-- Initialise local variables. |
93 |
|
|
cgf convert phibot from m2/s2 to cm |
94 |
|
|
fac = 1. _d 2 / 9.81 _d 0 |
95 |
|
|
|
96 |
|
|
do bj = jtlo,jthi |
97 |
|
|
do bi = itlo,ithi |
98 |
|
|
do j = 1,sny |
99 |
|
|
do i = 1,snx |
100 |
|
|
bpdifmean(i,j,bi,bj) = 0. _d 0 |
101 |
|
|
bpdifanom(i,j,bi,bj) = 0. _d 0 |
102 |
|
|
bpdatmean(i,j,bi,bj) = 0. _d 0 |
103 |
|
|
bpdatanom(i,j,bi,bj) = 0. _d 0 |
104 |
|
|
bpcount(i,j,bi,bj) = 0. _d 0 |
105 |
|
|
enddo |
106 |
|
|
enddo |
107 |
|
|
enddo |
108 |
|
|
enddo |
109 |
|
|
|
110 |
|
|
doglobalread = .false. |
111 |
|
|
ladinit = .false. |
112 |
|
|
|
113 |
|
|
write(fname(1:80),'(80a)') ' ' |
114 |
|
|
ilps=ilnblnk( bpbarfile ) |
115 |
|
|
write(fname(1:80),'(2a,i10.10)') |
116 |
|
|
& bpbarfile(1:ilps),'.',optimcycle |
117 |
|
|
|
118 |
|
|
c-- ============ |
119 |
|
|
c-- Mean values. |
120 |
|
|
c-- ============ |
121 |
|
|
|
122 |
|
|
do irec = 1, nmonsrec |
123 |
|
|
|
124 |
|
|
c-- Compute the mean over all bpdat records. |
125 |
|
|
call active_read_xy( fname, bpbar, irec, doglobalread, |
126 |
|
|
& ladinit, optimcycle, mythid, |
127 |
|
|
& xx_bpbar_mean_dummy ) |
128 |
|
|
|
129 |
|
|
call cost_bp_read( irec, mythid ) |
130 |
|
|
|
131 |
|
|
do bj = jtlo,jthi |
132 |
|
|
do bi = itlo,ithi |
133 |
|
|
do j = 1,sny |
134 |
|
|
do i = 1,snx |
135 |
|
|
if ( (bpmask(i,j,bi,bj).NE. 0. _d 0).AND. |
136 |
|
|
& (maskc(i,j,1,bi,bj).NE. 0. _d 0) ) then |
137 |
|
|
bpdifmean(i,j,bi,bj) = bpdifmean(i,j,bi,bj) + |
138 |
|
|
& ( fac*bpbar(i,j,bi,bj) - bpdat(i,j,bi,bj) ) |
139 |
|
|
bpdatmean(i,j,bi,bj) = bpdatmean(i,j,bi,bj) + |
140 |
|
|
& bpdat(i,j,bi,bj) |
141 |
|
|
bpcount(i,j,bi,bj) = bpcount(i,j,bi,bj) + 1. _d 0 |
142 |
|
|
endif |
143 |
|
|
enddo |
144 |
|
|
enddo |
145 |
|
|
enddo |
146 |
|
|
enddo |
147 |
|
|
|
148 |
|
|
enddo |
149 |
|
|
|
150 |
|
|
do bj = jtlo,jthi |
151 |
|
|
do bi = itlo,ithi |
152 |
|
|
do j = 1,sny |
153 |
|
|
do i = 1,snx |
154 |
|
|
if (bpcount(i,j,bi,bj).GT. 0. _d 0) then |
155 |
|
|
bpdifmean(i,j,bi,bj) = |
156 |
|
|
& bpdifmean(i,j,bi,bj)/bpcount(i,j,bi,bj) |
157 |
|
|
bpdatmean(i,j,bi,bj) = |
158 |
|
|
& bpdatmean(i,j,bi,bj)/bpcount(i,j,bi,bj) |
159 |
|
|
endif |
160 |
|
|
enddo |
161 |
|
|
enddo |
162 |
|
|
enddo |
163 |
|
|
enddo |
164 |
|
|
|
165 |
|
|
c-- ========== |
166 |
|
|
c-- Anomalies. |
167 |
|
|
c-- ========== |
168 |
|
|
|
169 |
|
|
c-- Loop over records for the second time. |
170 |
|
|
do irec = 1, nmonsrec |
171 |
|
|
|
172 |
|
|
call active_read_xy( fname, bpbar, irec, doglobalread, |
173 |
|
|
& ladinit, optimcycle, mythid, |
174 |
|
|
& xx_bpbar_mean_dummy ) |
175 |
|
|
|
176 |
|
|
call cost_bp_read( irec, mythid ) |
177 |
|
|
|
178 |
|
|
c-- Compute field of anomalies |
179 |
|
|
do bj = jtlo,jthi |
180 |
|
|
do bi = itlo,ithi |
181 |
|
|
do j = 1,sny |
182 |
|
|
do i = 1,snx |
183 |
|
|
if ( (bpmask(i,j,bi,bj).NE. 0. _d 0).AND. |
184 |
|
|
& (maskc(i,j,1,bi,bj).NE. 0. _d 0) ) then |
185 |
|
|
bpdifanom(i,j,bi,bj) = |
186 |
|
|
& ( fac*bpbar(i,j,bi,bj) - bpdat(i,j,bi,bj) ) |
187 |
|
|
& - bpdifmean(i,j,bi,bj) |
188 |
|
|
bpdatanom(i,j,bi,bj) = |
189 |
|
|
& bpdat(i,j,bi,bj) - bpdatmean(i,j,bi,bj) |
190 |
|
|
else |
191 |
|
|
bpdifanom(i,j,bi,bj) = 0. _d 0 |
192 |
|
|
bpdatanom(i,j,bi,bj) = 0. _d 0 |
193 |
|
|
endif |
194 |
|
|
enddo |
195 |
|
|
enddo |
196 |
|
|
enddo |
197 |
|
|
enddo |
198 |
|
|
|
199 |
|
|
c-- Remove global mean value |
200 |
|
|
offset = 0. _d 0 |
201 |
|
|
offset_sum = 0. _d 0 |
202 |
|
|
|
203 |
|
|
do bj = jtlo,jthi |
204 |
|
|
do bi = itlo,ithi |
205 |
|
|
do j = 1,sny |
206 |
|
|
do i = 1,snx |
207 |
|
|
if ( (bpmask(i,j,bi,bj).NE. 0. _d 0).AND. |
208 |
|
|
& (maskc(i,j,1,bi,bj).NE. 0. _d 0) ) then |
209 |
|
|
offset = offset + RA(i,j,bi,bj)*bpdifanom(i,j,bi,bj) |
210 |
|
|
offset_sum = offset_sum + RA(i,j,bi,bj) |
211 |
|
|
endif |
212 |
|
|
enddo |
213 |
|
|
enddo |
214 |
|
|
enddo |
215 |
|
|
enddo |
216 |
|
|
|
217 |
|
|
_GLOBAL_SUM_RL( offset , mythid ) |
218 |
|
|
_GLOBAL_SUM_RL( offset_sum , mythid ) |
219 |
|
|
|
220 |
|
|
do bj = jtlo,jthi |
221 |
|
|
do bi = itlo,ithi |
222 |
|
|
do j = 1,sny |
223 |
|
|
do i = 1,snx |
224 |
|
|
if ((offset_sum.GT. 0. _d 0).AND. |
225 |
|
|
& (bpmask(i,j,bi,bj).NE. 0. _d 0).AND. |
226 |
|
|
& (maskc(i,j,1,bi,bj).NE. 0. _d 0)) then |
227 |
|
|
bpdifanom(i,j,bi,bj) = bpdifanom(i,j,bi,bj) |
228 |
|
|
& - offset/offset_sum |
229 |
|
|
endif |
230 |
|
|
enddo |
231 |
|
|
enddo |
232 |
|
|
enddo |
233 |
|
|
enddo |
234 |
|
|
|
235 |
|
|
c-- Smooth field of anomalies |
236 |
|
|
#ifdef ALLOW_BP_COST_OUTPUT |
237 |
|
|
write(fname4test(1:80),'(1a)') 'bpdifanom_raw' |
238 |
|
|
call mdswritefield(fname4test,32,.false.,'RL', |
239 |
|
|
& 1,bpdifanom,irec,1,mythid) |
240 |
|
|
write(fname4test(1:80),'(1a)') 'bpdatanom_raw' |
241 |
|
|
call mdswritefield(fname4test,32,.false.,'RL', |
242 |
|
|
& 1,bpdatanom,irec,1,mythid) |
243 |
|
|
#endif |
244 |
|
|
|
245 |
|
|
#ifdef ALLOW_SMOOTH |
246 |
|
|
if ( useSMOOTH ) |
247 |
|
|
chzh & call smooth_basic2D(bpdifanom,maskc,750000. _d 0,5000,mythid) |
248 |
|
|
chzh & call smooth_basic2D(bpdifanom,maskc,300000. _d 0,3000,mythid) |
249 |
|
|
chzh2 & call smooth_basic2D(bpdifanom,maskc,300000. _d 0,30000,mythid) |
250 |
|
|
chzh3 & call smooth_basic2D(bpdifanom,maskc,300000. _d 0,9000,mythid) |
251 |
|
|
& call smooth_basic2D(bpdifanom,maskc,300000. _d 0,5000,mythid) |
252 |
|
|
#endif |
253 |
|
|
|
254 |
|
|
#ifdef ALLOW_BP_COST_OUTPUT |
255 |
|
|
#ifdef ALLOW_SMOOTH |
256 |
|
|
if ( useSMOOTH ) |
257 |
|
|
chzh & call smooth_basic2D(bpdatanom,maskc,750000. _d 0,5000,mythid) |
258 |
|
|
chzh & call smooth_basic2D(bpdatanom,maskc,300000. _d 0,3000,mythid) |
259 |
|
|
chzh2 & call smooth_basic2D(bpdatanom,maskc,300000. _d 0,30000,mythid) |
260 |
|
|
chzh3 & call smooth_basic2D(bpdatanom,maskc,300000. _d 0,9000,mythid) |
261 |
|
|
& call smooth_basic2D(bpdatanom,maskc,300000. _d 0,5000,mythid) |
262 |
|
|
#endif |
263 |
|
|
|
264 |
|
|
write(fname4test(1:80),'(1a)') 'bpdifanom_smooth' |
265 |
|
|
call mdswritefield(fname4test,32,.false.,'RL', |
266 |
|
|
& 1,bpdifanom,irec,1,mythid) |
267 |
|
|
write(fname4test(1:80),'(1a)') 'bpdatanom_smooth' |
268 |
|
|
call mdswritefield(fname4test,32,.false.,'RL', |
269 |
|
|
& 1,bpdatanom,irec,1,mythid) |
270 |
|
|
#endif |
271 |
|
|
|
272 |
|
|
c-- Compute cost function |
273 |
|
|
do bj = jtlo,jthi |
274 |
|
|
do bi = itlo,ithi |
275 |
|
|
do j = 1,sny |
276 |
|
|
do i = 1,snx |
277 |
|
|
if ( (wbp(i,j,bi,bj).NE. 0. _d 0).AND. |
278 |
|
|
& (bpmask(i,j,bi,bj).NE. 0. _d 0).AND. |
279 |
|
|
& (maskc(i,j,1,bi,bj).NE. 0. _d 0) ) then |
280 |
|
|
junk = bpdifanom(i,j,bi,bj) |
281 |
|
|
objf_bp(bi,bj) = objf_bp(bi,bj) |
282 |
|
|
& + junk*junk*wbp(i,j,bi,bj) |
283 |
|
|
num_bp(bi,bj) = num_bp(bi,bj) + 1. _d 0 |
284 |
|
|
endif |
285 |
|
|
enddo |
286 |
|
|
enddo |
287 |
|
|
enddo |
288 |
|
|
enddo |
289 |
|
|
|
290 |
|
|
enddo |
291 |
|
|
|
292 |
|
|
#endif /* ifdef ALLOW_BP_COST_CONTRIBUTION */ |
293 |
|
|
|
294 |
|
|
end |