1 |
C $Header: /u/gcmpack/MITgcm/pkg/ecco/cost_ctdtclim.F,v 1.1 2003/11/06 22:10:07 heimbach Exp $ |
2 |
|
3 |
#include "COST_CPPOPTIONS.h" |
4 |
|
5 |
|
6 |
subroutine cost_Ctdtclim( |
7 |
I myiter, |
8 |
I mytime, |
9 |
I mythid |
10 |
& ) |
11 |
|
12 |
c ================================================================== |
13 |
c SUBROUTINE cost_Ctdtclim |
14 |
c ================================================================== |
15 |
c |
16 |
c o Evaluate cost function contribution of temperature. |
17 |
c |
18 |
c started: Christian Eckert eckert@mit.edu 30-Jun-1999 |
19 |
c |
20 |
c changed: Christian Eckert eckert@mit.edu 25-Feb-2000 |
21 |
c |
22 |
c - Restructured the code in order to create a package |
23 |
c for the MITgcmUV. |
24 |
c |
25 |
c changed: Patrick Heimbach heimbach@mit.edu 27-May-2000 |
26 |
c |
27 |
c - set ladinit to .true. to initialise adtbar file |
28 |
c |
29 |
c ================================================================== |
30 |
c SUBROUTINE cost_Ctdtclim |
31 |
c ================================================================== |
32 |
|
33 |
implicit none |
34 |
|
35 |
c == global variables == |
36 |
|
37 |
#include "EEPARAMS.h" |
38 |
#include "SIZE.h" |
39 |
#include "GRID.h" |
40 |
#include "DYNVARS.h" |
41 |
|
42 |
#include "cal.h" |
43 |
#include "ecco_cost.h" |
44 |
#include "ctrl.h" |
45 |
#include "ctrl_dummy.h" |
46 |
#include "optim.h" |
47 |
|
48 |
c == routine arguments == |
49 |
|
50 |
integer myiter |
51 |
_RL mytime |
52 |
integer mythid |
53 |
|
54 |
c == local variables == |
55 |
|
56 |
_RS one_rs |
57 |
parameter( one_rs = 1. ) |
58 |
|
59 |
integer bi,bj |
60 |
integer i,j,k |
61 |
integer itlo,ithi |
62 |
integer jtlo,jthi |
63 |
integer jmin,jmax |
64 |
integer imin,imax |
65 |
integer irec |
66 |
integer levmon |
67 |
integer levoff |
68 |
integer ilctdtclim |
69 |
|
70 |
_RL fctile |
71 |
_RL fcthread |
72 |
|
73 |
_RL cmask (1-olx:snx+olx,1-oly:sny+oly) |
74 |
_RL spval |
75 |
|
76 |
character*(80) fnametheta |
77 |
|
78 |
logical doglobalread |
79 |
logical ladinit |
80 |
|
81 |
character*(MAX_LEN_MBUF) msgbuf |
82 |
#ifdef GENERIC_BAR_MONTH |
83 |
integer mrec, nyears, iyear |
84 |
#endif |
85 |
c == external functions == |
86 |
|
87 |
integer ilnblnk |
88 |
external ilnblnk |
89 |
|
90 |
c == end of interface == |
91 |
|
92 |
jtlo = mybylo(mythid) |
93 |
jthi = mybyhi(mythid) |
94 |
itlo = mybxlo(mythid) |
95 |
ithi = mybxhi(mythid) |
96 |
jmin = 1 |
97 |
jmax = sny |
98 |
imin = 1 |
99 |
imax = snx |
100 |
|
101 |
spval = -9990. |
102 |
|
103 |
c-- Read tiled data. |
104 |
doglobalread = .false. |
105 |
ladinit = .false. |
106 |
|
107 |
#ifdef ALLOW_CTDTCLIM_COST_CONTRIBUTION |
108 |
|
109 |
#ifdef ECCO_VERBOSE |
110 |
_BEGIN_MASTER( mythid ) |
111 |
write(msgbuf,'(a)') ' ' |
112 |
call print_message( msgbuf, standardmessageunit, |
113 |
& SQUEEZE_RIGHT , mythid) |
114 |
write(msgbuf,'(a,i8.8)') |
115 |
& ' cost_Ctdtclim: number of records to process = ',nmonsrec |
116 |
call print_message( msgbuf, standardmessageunit, |
117 |
& SQUEEZE_RIGHT , mythid) |
118 |
write(msgbuf,'(a)') ' ' |
119 |
call print_message( msgbuf, standardmessageunit, |
120 |
& SQUEEZE_RIGHT , mythid) |
121 |
_END_MASTER( mythid ) |
122 |
#endif |
123 |
|
124 |
if (optimcycle .ge. 0) then |
125 |
ilctdtclim = ilnblnk( tbarfile ) |
126 |
write(fnametheta(1:80),'(2a,i10.10)') |
127 |
& tbarfile(1:ilctdtclim),'.',optimcycle |
128 |
endif |
129 |
|
130 |
fcthread = 0. _d 0 |
131 |
|
132 |
#ifdef GENERIC_BAR_MONTH |
133 |
c-- Loop over month |
134 |
do irec = 1,12 |
135 |
nyears=int((nmonsrec-irec)/12)+1 |
136 |
if(nyears.gt.0) then |
137 |
do iyear=1,nyears |
138 |
mrec=irec+(iyear-1)*12 |
139 |
c-- Read time averages and the monthly mean data. |
140 |
call active_read_xyz( fnametheta, tbar, mrec, |
141 |
& doglobalread, ladinit, |
142 |
& optimcycle, mythid, |
143 |
& xx_tbar_mean_dummy ) |
144 |
do bj = jtlo,jthi |
145 |
do bi = itlo,ithi |
146 |
do k = 1,nr |
147 |
do j = jmin,jmax |
148 |
do i = imin,imax |
149 |
if(iyear.eq.1) then |
150 |
tbar_gen(i,j,k,bi,bj) =tbar(i,j,k,bi,bj) |
151 |
elseif(iyear.eq.nyears) then |
152 |
tbar(i,j,k,bi,bj) =(tbar_gen(i,j,k,bi,bj) |
153 |
$ +tbar(i,j,k,bi,bj))/float(nyears) |
154 |
else |
155 |
tbar_gen(i,j,k,bi,bj) =tbar_gen(i,j,k,bi,bj) |
156 |
$ +tbar(i,j,k,bi,bj) |
157 |
endif |
158 |
enddo |
159 |
enddo |
160 |
enddo |
161 |
enddo |
162 |
enddo |
163 |
enddo |
164 |
#else |
165 |
c-- Loop over records. |
166 |
do irec = 1,nmonsrec |
167 |
|
168 |
c-- Read time averages and the monthly mean data. |
169 |
call active_read_xyz( fnametheta, tbar, irec, |
170 |
& doglobalread, ladinit, |
171 |
& optimcycle, mythid, |
172 |
& xx_tbar_mean_dummy ) |
173 |
#endif |
174 |
c-- Determine the month to be read. |
175 |
levoff = mod(modelstartdate(1)/100,100) |
176 |
levmon = (irec-1) + levoff |
177 |
levmon = mod(levmon-1,12)+1 |
178 |
|
179 |
call mdsreadfield( ctdtclimfile, cost_iprec, cost_yftype, |
180 |
& nr, tdat, levmon, mythid) |
181 |
|
182 |
do bj = jtlo,jthi |
183 |
do bi = itlo,ithi |
184 |
|
185 |
c-- Loop over the model layers |
186 |
fctile = 0. _d 0 |
187 |
do k = 1,nr |
188 |
|
189 |
c-- Determine the mask on weights |
190 |
do j = jmin,jmax |
191 |
do i = imin,imax |
192 |
cmask(i,j) = 1. _d 0 |
193 |
if (tdat(i,j,k,bi,bj) .eq. 0.) then |
194 |
cmask(i,j) = 0. _d 0 |
195 |
endif |
196 |
|
197 |
if (tdat(i,j,k,bi,bj) .lt. spval) then |
198 |
cmask(i,j) = 0. _d 0 |
199 |
endif |
200 |
|
201 |
cph( |
202 |
cph print *, 'WARNING: SPECIFIC SETUP FOR ECCO' |
203 |
cph below statement could be replaced by following |
204 |
cph to make it independnet of Nr: |
205 |
cph |
206 |
cph if ( rC(K) .GT. -1000. ) then |
207 |
cph) |
208 |
c set cmask=0 in areas shallower than 1000m |
209 |
if (_hFacC(i,j,13,bi,bj) .eq. 0.) then |
210 |
cmask(i,j) = 0. _d 0 |
211 |
endif |
212 |
enddo |
213 |
enddo |
214 |
|
215 |
c-- Compute model data misfit and cost function term for |
216 |
c the temperature field. |
217 |
do j = jmin,jmax |
218 |
do i = imin,imax |
219 |
if (_hFacC(i,j,k,bi,bj) .ne. 0.) then |
220 |
fctile = fctile + |
221 |
& (wtheta2(i,j,k,bi,bj)*cosphi(i,j,bi,bj)* |
222 |
& cmask(i,j)* |
223 |
& (tbar(i,j,k,bi,bj) - tdat(i,j,k,bi,bj))* |
224 |
& (tbar(i,j,k,bi,bj) - tdat(i,j,k,bi,bj)) ) |
225 |
endif |
226 |
enddo |
227 |
enddo |
228 |
|
229 |
enddo |
230 |
c-- End of loop over layers. |
231 |
|
232 |
fcthread = fcthread + fctile |
233 |
objf_ctdtclim(bi,bj) = objf_ctdtclim(bi,bj) + fctile |
234 |
|
235 |
#ifdef ECCO_VERBOSE |
236 |
c-- Print cost function for each tile in each thread. |
237 |
write(msgbuf,'(a)') ' ' |
238 |
call print_message( msgbuf, standardmessageunit, |
239 |
& SQUEEZE_RIGHT , mythid) |
240 |
write(msgbuf,'(a,i8.8,1x,i3.3,1x,i3.3)') |
241 |
& ' cost_Ctdtclim: irec,bi,bj = ',irec,bi,bj |
242 |
call print_message( msgbuf, standardmessageunit, |
243 |
& SQUEEZE_RIGHT , mythid) |
244 |
write(msgbuf,'(a,d22.15)') |
245 |
& ' cost function (temperature) = ', |
246 |
& fctile |
247 |
call print_message( msgbuf, standardmessageunit, |
248 |
& SQUEEZE_RIGHT , mythid) |
249 |
write(msgbuf,'(a)') ' ' |
250 |
call print_message( msgbuf, standardmessageunit, |
251 |
& SQUEEZE_RIGHT , mythid) |
252 |
#endif |
253 |
|
254 |
enddo |
255 |
enddo |
256 |
|
257 |
#ifdef ECCO_VERBOSE |
258 |
c-- Print cost function for all tiles. |
259 |
_GLOBAL_SUM_R8( fcthread , myThid ) |
260 |
write(msgbuf,'(a)') ' ' |
261 |
call print_message( msgbuf, standardmessageunit, |
262 |
& SQUEEZE_RIGHT , mythid) |
263 |
write(msgbuf,'(a,i8.8)') |
264 |
& ' cost_Ctdtclim: irec = ',irec |
265 |
call print_message( msgbuf, standardmessageunit, |
266 |
& SQUEEZE_RIGHT , mythid) |
267 |
write(msgbuf,'(a,a,d22.15)') |
268 |
& ' global cost function value', |
269 |
& ' (temperature) = ',fcthread |
270 |
call print_message( msgbuf, standardmessageunit, |
271 |
& SQUEEZE_RIGHT , mythid) |
272 |
write(msgbuf,'(a)') ' ' |
273 |
call print_message( msgbuf, standardmessageunit, |
274 |
& SQUEEZE_RIGHT , mythid) |
275 |
#endif |
276 |
|
277 |
#ifdef GENERIC_BAR_MONTH |
278 |
endif |
279 |
#endif |
280 |
enddo |
281 |
c-- End of loop over records. |
282 |
|
283 |
#else |
284 |
c-- Do not enter the calculation of the temperature contribution to |
285 |
c-- the final cost function. |
286 |
|
287 |
#ifdef ECCO_VERBOSE |
288 |
_BEGIN_MASTER( mythid ) |
289 |
write(msgbuf,'(a)') ' ' |
290 |
call print_message( msgbuf, standardmessageunit, |
291 |
& SQUEEZE_RIGHT , mythid) |
292 |
write(msgbuf,'(a,a)') |
293 |
& ' cost_Ctdtclim: no contribution of temperature field ', |
294 |
& 'to cost function.' |
295 |
call print_message( msgbuf, standardmessageunit, |
296 |
& SQUEEZE_RIGHT , mythid) |
297 |
write(msgbuf,'(a,a,i9.8)') |
298 |
& ' cost_Ctdtclim: number of records that would have', |
299 |
& ' been processed: ',nmonsrec |
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 |
_END_MASTER( mythid ) |
306 |
#endif |
307 |
|
308 |
#endif |
309 |
|
310 |
return |
311 |
end |
312 |
|