1 |
C $Header: /u/gcmpack/MITgcm/pkg/ecco/cost_ctdsclim.F,v 1.1 2003/11/06 22:10:07 heimbach Exp $ |
2 |
|
3 |
#include "COST_CPPOPTIONS.h" |
4 |
|
5 |
|
6 |
subroutine cost_ctdsclim( |
7 |
I myiter, |
8 |
I mytime, |
9 |
I mythid |
10 |
& ) |
11 |
|
12 |
c ================================================================== |
13 |
c SUBROUTINE cost_Ctdsclim |
14 |
c ================================================================== |
15 |
c |
16 |
c o Evaluate cost function contribution of salinity. |
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 adsbar file |
28 |
c |
29 |
c ================================================================== |
30 |
c SUBROUTINE cost_Ctdsclim |
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 ilctdsclim |
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) fnamesalt |
77 |
|
78 |
logical doglobalread |
79 |
logical ladinit |
80 |
|
81 |
character*(MAX_LEN_MBUF) msgbuf |
82 |
|
83 |
#ifdef GENERIC_BAR_MONTH |
84 |
integer mrec, nyears, iyear |
85 |
#endif |
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 |
spval = -9990. |
103 |
|
104 |
c-- Read tiled data. |
105 |
doglobalread = .false. |
106 |
ladinit = .false. |
107 |
|
108 |
#ifdef ALLOW_CTDSCLIM_COST_CONTRIBUTION |
109 |
|
110 |
#ifdef ECCO_VERBOSE |
111 |
_BEGIN_MASTER( mythid ) |
112 |
write(msgbuf,'(a)') ' ' |
113 |
call print_message( msgbuf, standardmessageunit, |
114 |
& SQUEEZE_RIGHT , mythid) |
115 |
write(msgbuf,'(a,i8.8)') |
116 |
& ' cost_Ctdsclim: number of records to process = ',nmonsrec |
117 |
call print_message( msgbuf, standardmessageunit, |
118 |
& SQUEEZE_RIGHT , mythid) |
119 |
write(msgbuf,'(a)') ' ' |
120 |
call print_message( msgbuf, standardmessageunit, |
121 |
& SQUEEZE_RIGHT , mythid) |
122 |
_END_MASTER( mythid ) |
123 |
#endif |
124 |
|
125 |
if (optimcycle .ge. 0) then |
126 |
ilctdsclim = ilnblnk( sbarfile ) |
127 |
write(fnamesalt(1:80),'(2a,i10.10)') |
128 |
& sbarfile(1:ilctdsclim),'.',optimcycle |
129 |
endif |
130 |
|
131 |
fcthread = 0. _d 0 |
132 |
|
133 |
#ifdef GENERIC_BAR_MONTH |
134 |
c-- Loop over month |
135 |
do irec = 1,12 |
136 |
nyears=int((nmonsrec-irec)/12)+1 |
137 |
if(nyears.gt.0) then |
138 |
do iyear=1,nyears |
139 |
mrec=irec+(iyear-1)*12 |
140 |
c-- Read time averages and the monthly mean data. |
141 |
call active_read_xyz( fnamesalt, sbar, mrec, |
142 |
& doglobalread, ladinit, |
143 |
& optimcycle, mythid, |
144 |
& xx_sbar_mean_dummy ) |
145 |
do bj = jtlo,jthi |
146 |
do bi = itlo,ithi |
147 |
do k = 1,nr |
148 |
do j = jmin,jmax |
149 |
do i = imin,imax |
150 |
if(iyear.eq.1) then |
151 |
sbar_gen(i,j,k,bi,bj) =sbar(i,j,k,bi,bj) |
152 |
elseif(iyear.eq.nyears) then |
153 |
sbar(i,j,k,bi,bj) =(sbar_gen(i,j,k,bi,bj) |
154 |
$ +sbar(i,j,k,bi,bj))/float(nyears) |
155 |
else |
156 |
sbar_gen(i,j,k,bi,bj) =sbar_gen(i,j,k,bi,bj) |
157 |
$ +sbar(i,j,k,bi,bj) |
158 |
endif |
159 |
enddo |
160 |
enddo |
161 |
enddo |
162 |
enddo |
163 |
enddo |
164 |
enddo |
165 |
#else |
166 |
c-- Loop over records. |
167 |
do irec = 1,nmonsrec |
168 |
|
169 |
c-- Read time averages and the monthly mean data. |
170 |
call active_read_xyz( fnamesalt, sbar, irec, |
171 |
& doglobalread, ladinit, |
172 |
& optimcycle, mythid, |
173 |
& xx_sbar_mean_dummy ) |
174 |
#endif |
175 |
c-- Determine the month to be read. |
176 |
levoff = mod(modelstartdate(1)/100,100) |
177 |
levmon = (irec-1) + levoff |
178 |
levmon = mod(levmon-1,12)+1 |
179 |
|
180 |
call mdsreadfield( ctdsclimfile, cost_iprec, cost_yftype, |
181 |
& nr, sdat, levmon, mythid) |
182 |
|
183 |
do bj = jtlo,jthi |
184 |
do bi = itlo,ithi |
185 |
|
186 |
c-- Loop over the model layers |
187 |
fctile = 0. _d 0 |
188 |
do k = 1,nr |
189 |
|
190 |
c-- Determine the mask or weights |
191 |
do j = jmin,jmax |
192 |
do i = imin,imax |
193 |
cmask(i,j) = 1. _d 0 |
194 |
if (sdat(i,j,k,bi,bj) .eq. 0.) then |
195 |
cmask(i,j) = 0. _d 0 |
196 |
endif |
197 |
if (sdat(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 |
|
213 |
enddo |
214 |
enddo |
215 |
|
216 |
c-- Compute model data misfit and cost function term for |
217 |
c the salinity field. |
218 |
do j = jmin,jmax |
219 |
do i = imin,imax |
220 |
if (_hFacC(i,j,k,bi,bj) .ne. 0.) then |
221 |
fctile = fctile + |
222 |
& (wsalt2(i,j,k,bi,bj)*cosphi(i,j,bi,bj)* |
223 |
& cmask(i,j)* |
224 |
& (sbar(i,j,k,bi,bj) - sdat(i,j,k,bi,bj))* |
225 |
& (sbar(i,j,k,bi,bj) - sdat(i,j,k,bi,bj)) ) |
226 |
endif |
227 |
enddo |
228 |
enddo |
229 |
|
230 |
enddo |
231 |
c-- End of loop over layers. |
232 |
|
233 |
fcthread = fcthread + fctile |
234 |
objf_ctdsclim(bi,bj) = objf_ctdsclim(bi,bj) + fctile |
235 |
|
236 |
#ifdef ECCO_VERBOSE |
237 |
c-- Print cost function for each tile in each thread. |
238 |
write(msgbuf,'(a)') ' ' |
239 |
call print_message( msgbuf, standardmessageunit, |
240 |
& SQUEEZE_RIGHT , mythid) |
241 |
write(msgbuf,'(a,i8.8,1x,i3.3,1x,i3.3)') |
242 |
& ' cost_Ctdsclim: irec,bi,bj = ',irec,bi,bj |
243 |
call print_message( msgbuf, standardmessageunit, |
244 |
& SQUEEZE_RIGHT , mythid) |
245 |
write(msgbuf,'(a,d22.15)') |
246 |
& ' cost function (salinity) = ', |
247 |
& fctile |
248 |
call print_message( msgbuf, standardmessageunit, |
249 |
& SQUEEZE_RIGHT , mythid) |
250 |
write(msgbuf,'(a)') ' ' |
251 |
call print_message( msgbuf, standardmessageunit, |
252 |
& SQUEEZE_RIGHT , mythid) |
253 |
#endif |
254 |
|
255 |
enddo |
256 |
enddo |
257 |
|
258 |
#ifdef ECCO_VERBOSE |
259 |
c-- Print cost function for all tiles. |
260 |
_GLOBAL_SUM_R8( fcthread , myThid ) |
261 |
write(msgbuf,'(a)') ' ' |
262 |
call print_message( msgbuf, standardmessageunit, |
263 |
& SQUEEZE_RIGHT , mythid) |
264 |
write(msgbuf,'(a,i8.8)') |
265 |
& ' cost_Ctdsclim: irec = ',irec |
266 |
call print_message( msgbuf, standardmessageunit, |
267 |
& SQUEEZE_RIGHT , mythid) |
268 |
write(msgbuf,'(a,a,d22.15)') |
269 |
& ' global cost function value', |
270 |
& ' (salinity) = ',fcthread |
271 |
call print_message( msgbuf, standardmessageunit, |
272 |
& SQUEEZE_RIGHT , mythid) |
273 |
write(msgbuf,'(a)') ' ' |
274 |
call print_message( msgbuf, standardmessageunit, |
275 |
& SQUEEZE_RIGHT , mythid) |
276 |
#endif |
277 |
|
278 |
#ifdef GENERIC_BAR_MONTH |
279 |
endif |
280 |
#endif |
281 |
enddo |
282 |
c-- End of loop over records. |
283 |
|
284 |
#else |
285 |
c-- Do not enter the calculation of the salinity contribution to |
286 |
c-- the final cost function. |
287 |
|
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_Ctdsclim: no contribution of salinity field ', |
294 |
& 'to cost function.' |
295 |
call print_message( msgbuf, standardmessageunit, |
296 |
& SQUEEZE_RIGHT , mythid) |
297 |
write(msgbuf,'(a,a,i9.8)') |
298 |
& ' cost_Ctdsclim: 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 |
return |
309 |
end |
310 |
|