1 |
C $Header: /u/gcmpack/MITgcm/pkg/cost/Attic/cost_heatflux.F,v 1.1.2.3 2003/07/16 16:38:58 heimbach Exp $ |
2 |
|
3 |
#include "COST_CPPOPTIONS.h" |
4 |
|
5 |
|
6 |
subroutine cost_heatflux( |
7 |
I myiter, |
8 |
I mytime, |
9 |
I startrec, |
10 |
I endrec, |
11 |
I mythid |
12 |
& ) |
13 |
|
14 |
c ================================================================== |
15 |
c SUBROUTINE cost_heatflux |
16 |
c ================================================================== |
17 |
c |
18 |
c o Calculate the heat flux contribution to the cost function. |
19 |
c |
20 |
c started: Christian Eckert eckert@mit.edu 30-Jun-1999 |
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 ================================================================== |
28 |
c SUBROUTINE cost_heatflux |
29 |
c ================================================================== |
30 |
|
31 |
implicit none |
32 |
|
33 |
c == global variables == |
34 |
|
35 |
#include "EEPARAMS.h" |
36 |
#include "SIZE.h" |
37 |
#include "GRID.h" |
38 |
|
39 |
#include "ecco_cost.h" |
40 |
#include "ctrl.h" |
41 |
#include "ctrl_dummy.h" |
42 |
#include "optim.h" |
43 |
|
44 |
c == routine arguments == |
45 |
|
46 |
integer myiter |
47 |
_RL mytime |
48 |
integer startrec |
49 |
integer endrec |
50 |
integer mythid |
51 |
|
52 |
c == local variables == |
53 |
|
54 |
integer bi,bj |
55 |
integer i,j,kk |
56 |
integer itlo,ithi |
57 |
integer jtlo,jthi |
58 |
integer jmin,jmax |
59 |
integer imin,imax |
60 |
integer nrec |
61 |
integer irec |
62 |
integer ilfld |
63 |
|
64 |
_RL fctile |
65 |
_RL fctilem |
66 |
_RL fctilemm |
67 |
_RL fcthread |
68 |
_RL tmpx |
69 |
_RL sumcos |
70 |
|
71 |
_RL xx_hflux_mean (1-olx:snx+olx,1-oly:sny+oly, nsx,nsy) |
72 |
|
73 |
logical doglobalread |
74 |
logical ladinit |
75 |
|
76 |
character*(80) fnamefld |
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 |
c-- Read state record from global file. |
97 |
doglobalread = .false. |
98 |
ladinit = .false. |
99 |
|
100 |
c Number of records to be used. |
101 |
nrec = endrec-startrec+1 |
102 |
|
103 |
#ifdef ALLOW_HFLUX_COST_CONTRIBUTION |
104 |
|
105 |
#ifdef ECCO_VERBOSE |
106 |
_BEGIN_MASTER( mythid ) |
107 |
write(msgbuf,'(a)') ' ' |
108 |
call print_message( msgbuf, standardmessageunit, |
109 |
& SQUEEZE_RIGHT , mythid) |
110 |
write(msgbuf,'(a)') ' ' |
111 |
call print_message( msgbuf, standardmessageunit, |
112 |
& SQUEEZE_RIGHT , mythid) |
113 |
write(msgbuf,'(a,i9.8)') |
114 |
& ' cost_heatflux: number of records to process: ',nrec |
115 |
call print_message( msgbuf, standardmessageunit, |
116 |
& SQUEEZE_RIGHT , mythid) |
117 |
write(msgbuf,'(a)') ' ' |
118 |
call print_message( msgbuf, standardmessageunit, |
119 |
& SQUEEZE_RIGHT , mythid) |
120 |
_END_MASTER( mythid ) |
121 |
#endif |
122 |
|
123 |
if (optimcycle .ge. 0) then |
124 |
ilfld=ilnblnk( xx_hflux_file ) |
125 |
write(fnamefld(1:80),'(2a,i10.10)') |
126 |
& xx_hflux_file(1:ilfld),'.',optimcycle |
127 |
endif |
128 |
|
129 |
fcthread = 0. _d 0 |
130 |
|
131 |
c-- >>> Loop 1 to compute mean forcing: |
132 |
do bj = jtlo,jthi |
133 |
do bi = itlo,ithi |
134 |
do j = jmin,jmax |
135 |
do i = imin,imax |
136 |
xx_hflux_mean(i,j,bi,bj) = 0. _d 0 |
137 |
enddo |
138 |
enddo |
139 |
enddo |
140 |
enddo |
141 |
|
142 |
do irec = 1,nrec |
143 |
|
144 |
call active_read_xy_loc( fnamefld, tmpfld2d, irec, doglobalread, |
145 |
& ladinit, optimcycle, mythid |
146 |
& , xx_hflux_dummy ) |
147 |
|
148 |
c-- Loop over this thread's tiles. |
149 |
do bj = jtlo,jthi |
150 |
do bi = itlo,ithi |
151 |
do j = jmin,jmax |
152 |
do i = imin,imax |
153 |
xx_hflux_mean(i,j,bi,bj) = xx_hflux_mean(i,j,bi,bj) |
154 |
& + tmpfld2d(i,j,bi,bj) |
155 |
enddo |
156 |
enddo |
157 |
enddo |
158 |
enddo |
159 |
|
160 |
enddo |
161 |
|
162 |
do bj = jtlo,jthi |
163 |
do bi = itlo,ithi |
164 |
|
165 |
c-- Determine the weights to be used. |
166 |
kk = 1 |
167 |
fctilem = 0. _d 0 |
168 |
do j = jmin,jmax |
169 |
do i = imin,imax |
170 |
xx_hflux_mean(i,j,bi,bj) |
171 |
& = xx_hflux_mean(i,j,bi,bj)/float(nrec) |
172 |
tmpx = xx_hflux_mean(i,j,bi,bj)/30.0 |
173 |
if (maskw(i,j,kk,bi,bj) .ne. 0.) then |
174 |
fctilem = fctilem |
175 |
& +cosphi(i,j,bi,bj) |
176 |
& *tmpx*tmpx |
177 |
endif |
178 |
enddo |
179 |
enddo |
180 |
|
181 |
objf_hfluxm(bi,bj) = objf_hfluxm(bi,bj) + fctilem |
182 |
fcthread = fcthread + fctilem |
183 |
|
184 |
#ifdef ECCO_VERBOSE |
185 |
c-- Print cost function for each tile in each thread. |
186 |
write(msgbuf,'(a)') ' ' |
187 |
call print_message( msgbuf, standardmessageunit, |
188 |
& SQUEEZE_RIGHT , mythid) |
189 |
write(msgbuf,'(a,i8.8,1x,i3.3,1x,i3.3)') |
190 |
& ' cost_zonstress: irec,bi,bj = ',irec,bi,bj |
191 |
call print_message( msgbuf, standardmessageunit, |
192 |
& SQUEEZE_RIGHT , mythid) |
193 |
write(msgbuf,'(a,d22.15)') |
194 |
& ' cost function (zonal) = ', |
195 |
& fctilem |
196 |
call print_message( msgbuf, standardmessageunit, |
197 |
& SQUEEZE_RIGHT , mythid) |
198 |
#endif |
199 |
|
200 |
enddo |
201 |
enddo |
202 |
|
203 |
fcthread = 0. _d 0 |
204 |
|
205 |
c-- >>> Loop 2 over records. |
206 |
do irec = 1,nrec |
207 |
|
208 |
call active_read_xy_loc( fnamefld, tmpfld2d, irec, doglobalread, |
209 |
& ladinit, optimcycle, mythid |
210 |
& , xx_hflux_dummy ) |
211 |
|
212 |
c-- Loop over this thread's tiles. |
213 |
do bj = jtlo,jthi |
214 |
do bi = itlo,ithi |
215 |
|
216 |
c-- Determine the weights to be used. |
217 |
kk = 1 |
218 |
fctile = 0. _d 0 |
219 |
do j = jmin,jmax |
220 |
do i = imin,imax |
221 |
if (_hFacC(i,j,kk,bi,bj) .ne. 0.) then |
222 |
tmpx = tmpfld2d(i,j,bi,bj)-xx_hflux_mean(i,j,bi,bj) |
223 |
fctile = fctile |
224 |
& + whflux(i,j,bi,bj)*cosphi(i,j,bi,bj) |
225 |
& *tmpx*tmpx |
226 |
endif |
227 |
enddo |
228 |
enddo |
229 |
|
230 |
objf_hflux(bi,bj) = objf_hflux(bi,bj) + fctile |
231 |
fcthread = fcthread + fctile |
232 |
|
233 |
#ifdef ECCO_VERBOSE |
234 |
c-- Print cost function for each tile in each thread. |
235 |
write(msgbuf,'(a)') ' ' |
236 |
call print_message( msgbuf, standardmessageunit, |
237 |
& SQUEEZE_RIGHT , mythid) |
238 |
write(msgbuf,'(a,i8.8,1x,i3.3,1x,i3.3)') |
239 |
& ' cost_heatflux: irec,bi,bj = ',irec,bi,bj |
240 |
call print_message( msgbuf, standardmessageunit, |
241 |
& SQUEEZE_RIGHT , mythid) |
242 |
write(msgbuf,'(a,d22.15)') |
243 |
& ' cost function (hflux) = ', |
244 |
& fctile |
245 |
call print_message( msgbuf, standardmessageunit, |
246 |
& SQUEEZE_RIGHT , mythid) |
247 |
#endif |
248 |
enddo |
249 |
enddo |
250 |
|
251 |
#ifdef ECCO_VERBOSE |
252 |
c-- Print cost function for all tiles. |
253 |
_GLOBAL_SUM_R8( fcthread , myThid ) |
254 |
write(msgbuf,'(a)') ' ' |
255 |
call print_message( msgbuf, standardmessageunit, |
256 |
& SQUEEZE_RIGHT , mythid) |
257 |
write(msgbuf,'(a,i8.8)') |
258 |
& ' cost_heatflux: irec = ',irec |
259 |
call print_message( msgbuf, standardmessageunit, |
260 |
& SQUEEZE_RIGHT , mythid) |
261 |
write(msgbuf,'(a,d22.15)') |
262 |
& ' global cost function value = ', |
263 |
& fcthread |
264 |
call print_message( msgbuf, standardmessageunit, |
265 |
& SQUEEZE_RIGHT , mythid) |
266 |
write(msgbuf,'(a)') ' ' |
267 |
call print_message( msgbuf, standardmessageunit, |
268 |
& SQUEEZE_RIGHT , mythid) |
269 |
#endif |
270 |
c-- End of loop over records. |
271 |
enddo |
272 |
#else |
273 |
c-- Do not enter the calculation of the heat flux contribution |
274 |
c-- to the final cost function. |
275 |
|
276 |
fctile = 0. _d 0 |
277 |
fcthread = 0. _d 0 |
278 |
|
279 |
_BEGIN_MASTER( mythid ) |
280 |
write(msgbuf,'(a)') ' ' |
281 |
call print_message( msgbuf, standardmessageunit, |
282 |
& SQUEEZE_RIGHT , mythid) |
283 |
write(msgbuf,'(a,a)') |
284 |
& ' cost_heatflux: no contribution of heat flux ', |
285 |
& ' to cost function.' |
286 |
call print_message( msgbuf, standardmessageunit, |
287 |
& SQUEEZE_RIGHT , mythid) |
288 |
write(msgbuf,'(a,a,i9.8)') |
289 |
& ' cost_heatflux: number of records that would have', |
290 |
& ' been processed: ',nrec |
291 |
call print_message( msgbuf, standardmessageunit, |
292 |
& SQUEEZE_RIGHT , mythid) |
293 |
write(msgbuf,'(a)') ' ' |
294 |
call print_message( msgbuf, standardmessageunit, |
295 |
& SQUEEZE_RIGHT , mythid) |
296 |
_END_MASTER( mythid ) |
297 |
#endif |
298 |
|
299 |
return |
300 |
end |
301 |
|