1 |
C $Header: /u/gcmpack/MITgcm/pkg/cost/Attic/cost_ctdtclim.F,v 1.1.2.1 2003/06/19 15:21:16 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 |
else |
129 |
print* |
130 |
print*,' cost_Ctdtclim: optimcycle has a wrong value.' |
131 |
print*,' optimcycle = ',optimcycle |
132 |
print* |
133 |
stop ' ... stopped in cost_Ctdtclim.' |
134 |
endif |
135 |
|
136 |
fcthread = 0. _d 0 |
137 |
|
138 |
#ifdef GENERIC_BAR_MONTH |
139 |
c-- Loop over month |
140 |
do irec = 1,12 |
141 |
nyears=int((nmonsrec-irec)/12)+1 |
142 |
if(nyears.gt.0) then |
143 |
do iyear=1,nyears |
144 |
mrec=irec+(iyear-1)*12 |
145 |
c-- Read time averages and the monthly mean data. |
146 |
call active_read_xyz( fnametheta, tbar, mrec, |
147 |
& doglobalread, ladinit, |
148 |
& optimcycle, mythid, |
149 |
& xx_tbar_mean_dummy ) |
150 |
do bj = jtlo,jthi |
151 |
do bi = itlo,ithi |
152 |
do k = 1,nr |
153 |
do j = jmin,jmax |
154 |
do i = imin,imax |
155 |
if(iyear.eq.1) then |
156 |
tbar_gen(i,j,k,bi,bj) =tbar(i,j,k,bi,bj) |
157 |
elseif(iyear.eq.nyears) then |
158 |
tbar(i,j,k,bi,bj) =(tbar_gen(i,j,k,bi,bj) |
159 |
$ +tbar(i,j,k,bi,bj))/float(nyears) |
160 |
else |
161 |
tbar_gen(i,j,k,bi,bj) =tbar_gen(i,j,k,bi,bj) |
162 |
$ +tbar(i,j,k,bi,bj) |
163 |
endif |
164 |
enddo |
165 |
enddo |
166 |
enddo |
167 |
enddo |
168 |
enddo |
169 |
enddo |
170 |
#else |
171 |
c-- Loop over records. |
172 |
do irec = 1,nmonsrec |
173 |
|
174 |
c-- Read time averages and the monthly mean data. |
175 |
call active_read_xyz( fnametheta, tbar, irec, |
176 |
& doglobalread, ladinit, |
177 |
& optimcycle, mythid, |
178 |
& xx_tbar_mean_dummy ) |
179 |
#endif |
180 |
c-- Determine the month to be read. |
181 |
levoff = mod(modelstartdate(1)/100,100) |
182 |
levmon = (irec-1) + levoff |
183 |
levmon = mod(levmon-1,12)+1 |
184 |
|
185 |
call mdsreadfield( ctdtclimfile, cost_iprec, cost_yftype, |
186 |
& nr, tdat, levmon, mythid) |
187 |
|
188 |
do bj = jtlo,jthi |
189 |
do bi = itlo,ithi |
190 |
|
191 |
c-- Loop over the model layers |
192 |
fctile = 0. _d 0 |
193 |
do k = 1,nr |
194 |
|
195 |
c-- Determine the mask on weights |
196 |
do j = jmin,jmax |
197 |
do i = imin,imax |
198 |
cmask(i,j) = 1. _d 0 |
199 |
if (tdat(i,j,k,bi,bj) .eq. 0.) then |
200 |
cmask(i,j) = 0. _d 0 |
201 |
endif |
202 |
|
203 |
if (tdat(i,j,k,bi,bj) .lt. spval) then |
204 |
cmask(i,j) = 0. _d 0 |
205 |
endif |
206 |
|
207 |
cph( |
208 |
cph print *, 'WARNING: SPECIFIC SETUP FOR ECCO' |
209 |
cph below statement could be replaced by following |
210 |
cph to make it independnet of Nr: |
211 |
cph |
212 |
cph if ( rC(K) .GT. -1000. ) then |
213 |
cph) |
214 |
c set cmask=0 in areas shallower than 1000m |
215 |
if (_hFacC(i,j,13,bi,bj) .eq. 0.) then |
216 |
cmask(i,j) = 0. _d 0 |
217 |
endif |
218 |
enddo |
219 |
enddo |
220 |
|
221 |
c-- Compute model data misfit and cost function term for |
222 |
c the temperature field. |
223 |
do j = jmin,jmax |
224 |
do i = imin,imax |
225 |
if (_hFacC(i,j,k,bi,bj) .ne. 0.) then |
226 |
fctile = fctile + |
227 |
& (wtheta2(i,j,k,bi,bj)*cosphi(i,j,bi,bj)* |
228 |
& cmask(i,j)* |
229 |
& (tbar(i,j,k,bi,bj) - tdat(i,j,k,bi,bj))* |
230 |
& (tbar(i,j,k,bi,bj) - tdat(i,j,k,bi,bj)) ) |
231 |
endif |
232 |
enddo |
233 |
enddo |
234 |
|
235 |
enddo |
236 |
c-- End of loop over layers. |
237 |
|
238 |
fcthread = fcthread + fctile |
239 |
objf_ctdtclim(bi,bj) = objf_ctdtclim(bi,bj) + fctile |
240 |
|
241 |
#ifdef ECCO_VERBOSE |
242 |
c-- Print cost function for each tile in each thread. |
243 |
write(msgbuf,'(a)') ' ' |
244 |
call print_message( msgbuf, standardmessageunit, |
245 |
& SQUEEZE_RIGHT , mythid) |
246 |
write(msgbuf,'(a,i8.8,1x,i3.3,1x,i3.3)') |
247 |
& ' cost_Ctdtclim: irec,bi,bj = ',irec,bi,bj |
248 |
call print_message( msgbuf, standardmessageunit, |
249 |
& SQUEEZE_RIGHT , mythid) |
250 |
write(msgbuf,'(a,d22.15)') |
251 |
& ' cost function (temperature) = ', |
252 |
& fctile |
253 |
call print_message( msgbuf, standardmessageunit, |
254 |
& SQUEEZE_RIGHT , mythid) |
255 |
write(msgbuf,'(a)') ' ' |
256 |
call print_message( msgbuf, standardmessageunit, |
257 |
& SQUEEZE_RIGHT , mythid) |
258 |
#endif |
259 |
|
260 |
enddo |
261 |
enddo |
262 |
|
263 |
#ifdef ECCO_VERBOSE |
264 |
c-- Print cost function for all tiles. |
265 |
_GLOBAL_SUM_R8( fcthread , myThid ) |
266 |
write(msgbuf,'(a)') ' ' |
267 |
call print_message( msgbuf, standardmessageunit, |
268 |
& SQUEEZE_RIGHT , mythid) |
269 |
write(msgbuf,'(a,i8.8)') |
270 |
& ' cost_Ctdtclim: irec = ',irec |
271 |
call print_message( msgbuf, standardmessageunit, |
272 |
& SQUEEZE_RIGHT , mythid) |
273 |
write(msgbuf,'(a,a,d22.15)') |
274 |
& ' global cost function value', |
275 |
& ' (temperature) = ',fcthread |
276 |
call print_message( msgbuf, standardmessageunit, |
277 |
& SQUEEZE_RIGHT , mythid) |
278 |
write(msgbuf,'(a)') ' ' |
279 |
call print_message( msgbuf, standardmessageunit, |
280 |
& SQUEEZE_RIGHT , mythid) |
281 |
#endif |
282 |
|
283 |
#ifdef GENERIC_BAR_MONTH |
284 |
endif |
285 |
#endif |
286 |
enddo |
287 |
c-- End of loop over records. |
288 |
|
289 |
#else |
290 |
c-- Do not enter the calculation of the temperature contribution to |
291 |
c-- the final cost function. |
292 |
|
293 |
#ifdef ECCO_VERBOSE |
294 |
_BEGIN_MASTER( mythid ) |
295 |
write(msgbuf,'(a)') ' ' |
296 |
call print_message( msgbuf, standardmessageunit, |
297 |
& SQUEEZE_RIGHT , mythid) |
298 |
write(msgbuf,'(a,a)') |
299 |
& ' cost_Ctdtclim: no contribution of temperature field ', |
300 |
& 'to cost function.' |
301 |
call print_message( msgbuf, standardmessageunit, |
302 |
& SQUEEZE_RIGHT , mythid) |
303 |
write(msgbuf,'(a,a,i9.8)') |
304 |
& ' cost_Ctdtclim: number of records that would have', |
305 |
& ' been processed: ',nmonsrec |
306 |
call print_message( msgbuf, standardmessageunit, |
307 |
& SQUEEZE_RIGHT , mythid) |
308 |
write(msgbuf,'(a)') ' ' |
309 |
call print_message( msgbuf, standardmessageunit, |
310 |
& SQUEEZE_RIGHT , mythid) |
311 |
_END_MASTER( mythid ) |
312 |
#endif |
313 |
|
314 |
#endif |
315 |
|
316 |
return |
317 |
end |
318 |
|