1 |
C $Header: /u/gcmpack/MITgcm/pkg/ecco/cost_theta.F,v 1.12 2012/08/10 19:45:27 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "ECCO_OPTIONS.h" |
5 |
|
6 |
subroutine cost_theta( myiter, mytime, mythid ) |
7 |
|
8 |
c ================================================================== |
9 |
c SUBROUTINE cost_theta |
10 |
c ================================================================== |
11 |
c |
12 |
c o Evaluate cost function contribution of temperature. |
13 |
c |
14 |
c started: Christian Eckert eckert@mit.edu 30-Jun-1999 |
15 |
c |
16 |
c changed: Christian Eckert eckert@mit.edu 25-Feb-2000 |
17 |
c |
18 |
c - Restructured the code in order to create a package |
19 |
c for the MITgcmUV. |
20 |
c |
21 |
c changed: Patrick Heimbach heimbach@mit.edu 27-May-2000 |
22 |
c |
23 |
c - set ladinit to .true. to initialise adtbar file |
24 |
c |
25 |
c ================================================================== |
26 |
c SUBROUTINE cost_theta |
27 |
c ================================================================== |
28 |
|
29 |
implicit none |
30 |
|
31 |
c == global variables == |
32 |
|
33 |
#include "EEPARAMS.h" |
34 |
#include "SIZE.h" |
35 |
#include "PARAMS.h" |
36 |
#include "GRID.h" |
37 |
#include "DYNVARS.h" |
38 |
|
39 |
#include "cal.h" |
40 |
#include "ecco_cost.h" |
41 |
#include "CTRL_SIZE.h" |
42 |
#include "ctrl.h" |
43 |
#include "ctrl_dummy.h" |
44 |
#include "optim.h" |
45 |
|
46 |
c == routine arguments == |
47 |
|
48 |
integer myiter |
49 |
_RL mytime |
50 |
integer mythid |
51 |
|
52 |
#ifdef ALLOW_THETA_COST_CONTRIBUTION |
53 |
c == external functions == |
54 |
integer ilnblnk |
55 |
external ilnblnk |
56 |
|
57 |
c == local variables == |
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, irectmp |
66 |
integer levmon |
67 |
integer levoff |
68 |
integer iltheta |
69 |
|
70 |
_RL fctile |
71 |
_RL fcthread |
72 |
|
73 |
_RL cmask (1-olx:snx+olx,1-oly:sny+oly) |
74 |
_RL spval |
75 |
_RL spmax |
76 |
|
77 |
character*(80) fnametheta |
78 |
|
79 |
logical doglobalread |
80 |
logical ladinit |
81 |
|
82 |
character*(MAX_LEN_MBUF) msgbuf |
83 |
#ifdef GENERIC_BAR_MONTH |
84 |
integer mrec, nyears, iyear |
85 |
#endif |
86 |
|
87 |
_RL diagnosfld3d(1-olx:snx+olx,1-oly:sny+oly,nr,nsx,nsy) |
88 |
|
89 |
c == end of interface == |
90 |
|
91 |
jtlo = mybylo(mythid) |
92 |
jthi = mybyhi(mythid) |
93 |
itlo = mybxlo(mythid) |
94 |
ithi = mybxhi(mythid) |
95 |
jmin = 1 |
96 |
jmax = sny |
97 |
imin = 1 |
98 |
imax = snx |
99 |
|
100 |
spval = -1.8 |
101 |
spmax = 40. |
102 |
|
103 |
c-- Read tiled data. |
104 |
doglobalread = .false. |
105 |
ladinit = .false. |
106 |
|
107 |
if (optimcycle .ge. 0) then |
108 |
iltheta = ilnblnk( tbarfile ) |
109 |
write(fnametheta(1:80),'(2a,i10.10)') |
110 |
& tbarfile(1:iltheta),'.',optimcycle |
111 |
endif |
112 |
|
113 |
fcthread = 0. _d 0 |
114 |
|
115 |
#ifdef GENERIC_BAR_MONTH |
116 |
c-- Loop over month |
117 |
do irec = 1,min(nmonsrec,12) |
118 |
nyears=int((nmonsrec-irec)/12)+1 |
119 |
do bj = jtlo,jthi |
120 |
do bi = itlo,ithi |
121 |
do k = 1,nr |
122 |
do j = jmin,jmax |
123 |
do i = imin,imax |
124 |
tbar_gen(i,j,k,bi,bj) = 0. _d 0 |
125 |
enddo |
126 |
enddo |
127 |
enddo |
128 |
enddo |
129 |
enddo |
130 |
do iyear=1,nyears |
131 |
mrec=irec+(iyear-1)*12 |
132 |
irectmp=mrec |
133 |
c-- Read time averages and the monthly mean data. |
134 |
call active_read_xyz( fnametheta, tbar, mrec, |
135 |
& doglobalread, ladinit, |
136 |
& optimcycle, mythid, |
137 |
& xx_tbar_mean_dummy ) |
138 |
do bj = jtlo,jthi |
139 |
do bi = itlo,ithi |
140 |
do k = 1,nr |
141 |
do j = jmin,jmax |
142 |
do i = imin,imax |
143 |
tbar_gen(i,j,k,bi,bj) =tbar_gen(i,j,k,bi,bj) |
144 |
$ +tbar(i,j,k,bi,bj)/float(nyears) |
145 |
enddo |
146 |
enddo |
147 |
enddo |
148 |
enddo |
149 |
enddo |
150 |
enddo |
151 |
#else |
152 |
c-- Loop over records. |
153 |
do irec = 1,nmonsrec |
154 |
|
155 |
irectmp = irec |
156 |
c-- Read time averages and the monthly mean data. |
157 |
call active_read_xyz( fnametheta, tbar, irec, |
158 |
& doglobalread, ladinit, |
159 |
& optimcycle, mythid, |
160 |
& xx_tbar_mean_dummy ) |
161 |
#endif |
162 |
c-- Determine the month to be read. |
163 |
levoff = mod(modelstartdate(1)/100,100) |
164 |
levmon = (irectmp-1) + levoff |
165 |
levmon = mod(levmon-1,12)+1 |
166 |
|
167 |
call mdsreadfield( tdatfile, cost_iprec, cost_yftype, |
168 |
& nr, tdat, levmon, mythid) |
169 |
|
170 |
do bj = jtlo,jthi |
171 |
do bi = itlo,ithi |
172 |
|
173 |
c-- Loop over the model layers |
174 |
fctile = 0. _d 0 |
175 |
do k = 1,nr |
176 |
|
177 |
c-- Determine the mask on weights |
178 |
do j = jmin,jmax |
179 |
do i = imin,imax |
180 |
cmask(i,j) = cosphi(i,j,bi,bj) |
181 |
if (tdat(i,j,k,bi,bj) .eq. 0.) then |
182 |
cmask(i,j) = 0. _d 0 |
183 |
else if (tdat(i,j,k,bi,bj) .lt. spval) then |
184 |
cmask(i,j) = 0. _d 0 |
185 |
else if (tdat(i,j,k,bi,bj) .gt. spmax) then |
186 |
cmask(i,j) = 0. _d 0 |
187 |
endif |
188 |
enddo |
189 |
enddo |
190 |
|
191 |
c-- Compute model data misfit and cost function term for |
192 |
c the temperature field. |
193 |
do j = jmin,jmax |
194 |
do i = imin,imax |
195 |
if ( _hFacC(i,j,k,bi,bj) .ne. 0. ) then |
196 |
fctile = fctile + |
197 |
& (wthetaLev(i,j,k,bi,bj)*cmask(i,j)* |
198 |
& (tbar(i,j,k,bi,bj) - tdat(i,j,k,bi,bj))* |
199 |
& (tbar(i,j,k,bi,bj) - tdat(i,j,k,bi,bj)) ) |
200 |
if ( wthetaLev(i,j,k,bi,bj)*cmask(i,j) .ne. 0. ) |
201 |
& num_temp(bi,bj) = num_temp(bi,bj) + 1. _d 0 |
202 |
diagnosfld3d(i,j,k,bi,bj) = |
203 |
& (wthetaLev(i,j,k,bi,bj)*cmask(i,j)* |
204 |
& (tbar(i,j,k,bi,bj) - tdat(i,j,k,bi,bj))* |
205 |
& (tbar(i,j,k,bi,bj) - tdat(i,j,k,bi,bj)) ) |
206 |
else |
207 |
diagnosfld3d(i,j,k,bi,bj) = 0. |
208 |
endif |
209 |
enddo |
210 |
enddo |
211 |
|
212 |
enddo |
213 |
c-- End of loop over layers. |
214 |
|
215 |
fcthread = fcthread + fctile |
216 |
objf_temp(bi,bj) = objf_temp(bi,bj) + fctile |
217 |
|
218 |
enddo |
219 |
enddo |
220 |
CALL WRITE_REC_XYZ_RL( 'DiagnosCost_ClimTheta', |
221 |
& diagnosfld3d, irec, optimcycle, mythid ) |
222 |
|
223 |
enddo |
224 |
c-- End of loop over records. |
225 |
|
226 |
#endif /* ALLOW_THETA_COST_CONTRIBUTION */ |
227 |
|
228 |
RETURN |
229 |
END |