1 |
C $Header: $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "COST_CPPOPTIONS.h" |
5 |
|
6 |
|
7 |
subroutine cost_generic( |
8 |
& nnzbar, localbarfile, localbar, xx_localbar_mean_dummy, |
9 |
& nnzobs, localobsfile, localobs, mult_local, |
10 |
& nrecloc, localstartdate, localperiod, |
11 |
& localmask, localweight, |
12 |
& spminloc, spmaxloc, spzeroloc, |
13 |
& objf_local, num_local, |
14 |
& myiter, mytime, mythid ) |
15 |
|
16 |
c ================================================================== |
17 |
c SUBROUTINE cost_generic |
18 |
c ================================================================== |
19 |
c |
20 |
c o Generic routine for evaluating time-dependent |
21 |
c cost function contribution |
22 |
c |
23 |
c ================================================================== |
24 |
c SUBROUTINE cost_generic |
25 |
c ================================================================== |
26 |
|
27 |
implicit none |
28 |
|
29 |
c == global variables == |
30 |
|
31 |
#include "EEPARAMS.h" |
32 |
#include "SIZE.h" |
33 |
#include "PARAMS.h" |
34 |
#ifdef ALLOW_CAL |
35 |
# include "cal.h" |
36 |
#endif |
37 |
#ifdef ALLOW_COST |
38 |
# include "ecco_cost.h" |
39 |
# include "optim.h" |
40 |
# ifdef ALLOW_SEAICE |
41 |
# include "SEAICE_COST.h" |
42 |
# endif |
43 |
#endif |
44 |
|
45 |
c == routine arguments == |
46 |
|
47 |
integer nnzbar |
48 |
integer nnzobs |
49 |
integer nrecloc |
50 |
integer myiter |
51 |
integer mythid |
52 |
integer localstartdate(4) |
53 |
|
54 |
_RL localbar (1-olx:snx+olx,1-oly:sny+oly,nnzbar,nsx,nsy) |
55 |
_RL localobs (1-olx:snx+olx,1-oly:sny+oly,nnzobs,nsx,nsy) |
56 |
_RL localweight(1-olx:snx+olx,1-oly:sny+oly,nnzobs,nsx,nsy) |
57 |
_RL localmask (1-olx:snx+olx,1-oly:sny+oly,nr,nsx,nsy) |
58 |
_RL xx_localbar_mean_dummy |
59 |
_RL mult_local |
60 |
_RL mytime |
61 |
_RL localperiod |
62 |
_RL spminloc |
63 |
_RL spmaxloc |
64 |
_RL spzeroloc |
65 |
_RL objf_local(nsx,nsy) |
66 |
_RL num_local(nsx,nsy) |
67 |
|
68 |
character*(MAX_LEN_FNAM) localbarfile |
69 |
character*(MAX_LEN_FNAM) localobsfile |
70 |
|
71 |
#ifdef ALLOW_COST |
72 |
c == local variables == |
73 |
|
74 |
integer bi,bj |
75 |
integer i,j,k |
76 |
integer itlo,ithi |
77 |
integer jtlo,jthi |
78 |
integer jmin,jmax |
79 |
integer imin,imax |
80 |
integer irec |
81 |
integer il |
82 |
integer localrec |
83 |
integer obsrec |
84 |
|
85 |
logical doglobalread |
86 |
logical ladinit |
87 |
|
88 |
_RL spval |
89 |
parameter (spval = -9999. ) |
90 |
_RL localwww |
91 |
_RL localcost |
92 |
_RL junk |
93 |
|
94 |
_RL cmask (1-olx:snx+olx,1-oly:sny+oly,nnzobs) |
95 |
|
96 |
character*(128) fname1, fname2 |
97 |
character*(MAX_LEN_MBUF) msgbuf |
98 |
|
99 |
cnew( |
100 |
_RL daytime |
101 |
_RL diffsecs |
102 |
integer dayiter |
103 |
integer daydate(4) |
104 |
integer difftime(4) |
105 |
integer middate(4) |
106 |
integer yday, ymod |
107 |
integer md, dd, sd, ld, wd |
108 |
integer mody, modm |
109 |
integer beginmodel, beginlocal |
110 |
logical exst |
111 |
cnew) |
112 |
|
113 |
c == external functions == |
114 |
|
115 |
integer ilnblnk |
116 |
external ilnblnk |
117 |
|
118 |
c == end of interface == |
119 |
|
120 |
jtlo = mybylo(mythid) |
121 |
jthi = mybyhi(mythid) |
122 |
itlo = mybxlo(mythid) |
123 |
ithi = mybxhi(mythid) |
124 |
jmin = 1 |
125 |
jmax = sny |
126 |
imin = 1 |
127 |
imax = snx |
128 |
|
129 |
c-- Initialise local variables. |
130 |
|
131 |
localwww = 0. _d 0 |
132 |
|
133 |
do bj = jtlo,jthi |
134 |
do bi = itlo,ithi |
135 |
objf_local(bi,bj) = 0. _d 0 |
136 |
num_local(bi,bj) = 0. _d 0 |
137 |
enddo |
138 |
enddo |
139 |
|
140 |
c-- First, read tiled data. |
141 |
doglobalread = .false. |
142 |
ladinit = .false. |
143 |
|
144 |
write(fname1(1:128),'(80a)') ' ' |
145 |
il=ilnblnk( localbarfile ) |
146 |
write(fname1(1:128),'(2a,i10.10)') |
147 |
& localbarfile(1:il),'.',optimcycle |
148 |
|
149 |
cph if ( .NOT. ( mult_local.EQ.0. .OR. localobsfile.EQ.' ' ) ) then |
150 |
if ( .NOT. ( localobsfile.EQ.' ' ) ) then |
151 |
|
152 |
c-- Loop over records for the second time. |
153 |
do irec = 1, nrecloc |
154 |
|
155 |
if ( nnzbar .EQ. 1 ) then |
156 |
call active_read_xy( fname1, localbar, irec, doglobalread, |
157 |
& ladinit, optimcycle, mythid, |
158 |
& xx_localbar_mean_dummy ) |
159 |
else |
160 |
call active_read_xyz( fname1, localbar, irec, doglobalread, |
161 |
& ladinit, optimcycle, mythid, |
162 |
& xx_localbar_mean_dummy ) |
163 |
endif |
164 |
|
165 |
cnew( |
166 |
if ( localperiod .EQ. 86400. ) then |
167 |
c-- assume daily fields |
168 |
obsrec = irec |
169 |
daytime = FLOAT(secondsperday*(irec-1)) |
170 |
dayiter = hoursperday*(irec-1) |
171 |
call cal_getdate( dayiter, daytime, daydate, mythid ) |
172 |
call cal_convdate( daydate,yday,md,dd,sd,ld,wd,mythid ) |
173 |
ymod = localstartdate(1)/10000 |
174 |
if ( ymod .EQ. yday ) then |
175 |
middate(1) = modelstartdate(1) |
176 |
else |
177 |
middate(1) = yday*10000+100+1 |
178 |
endif |
179 |
middate(2) = 0 |
180 |
middate(3) = modelstartdate(3) |
181 |
middate(4) = modelstartdate(4) |
182 |
call cal_TimePassed( middate, daydate, difftime, mythid ) |
183 |
call cal_ToSeconds( difftime, diffsecs, mythid ) |
184 |
localrec = int(diffsecs/localperiod) + 1 |
185 |
else |
186 |
c-- assume monthly fields |
187 |
beginlocal = localstartdate(1)/10000 |
188 |
beginmodel = modelstartdate(1)/10000 |
189 |
obsrec = |
190 |
& ( beginmodel - beginlocal )*nmonthyear |
191 |
& + ( mod(modelstartdate(1)/100,100) |
192 |
& -mod(localstartdate(1)/100,100) ) |
193 |
& + irec |
194 |
mody = modelstartdate(1)/10000 |
195 |
modm = modelstartdate(1)/100 - mody*100 |
196 |
yday = mody + INT((modm-1+irec-1)/12) |
197 |
localrec = 1 + MOD(modm-1+irec-1,12) |
198 |
endif |
199 |
|
200 |
il=ilnblnk(localobsfile) |
201 |
write(fname2(1:128),'(2a,i4)') |
202 |
& localobsfile(1:il), '_', yday |
203 |
inquire( file=fname2, exist=exst ) |
204 |
if (.NOT. exst) then |
205 |
write(fname2(1:128),'(a)') localobsfile(1:il) |
206 |
localrec = obsrec |
207 |
endif |
208 |
|
209 |
if ( localrec .GT. 0 ) then |
210 |
call mdsreadfield( fname2, cost_iprec, cost_yftype, nnzobs, |
211 |
& localobs, localrec, mythid ) |
212 |
else |
213 |
do bj = jtlo,jthi |
214 |
do bi = itlo,ithi |
215 |
do k = 1,nnzobs |
216 |
do j = jmin,jmax |
217 |
do i = imin,imax |
218 |
localobs(i,j,k,bi,bj) = spval |
219 |
enddo |
220 |
enddo |
221 |
enddo |
222 |
enddo |
223 |
enddo |
224 |
endif |
225 |
cnew) |
226 |
|
227 |
do bj = jtlo,jthi |
228 |
do bi = itlo,ithi |
229 |
|
230 |
localcost = 0. _d 0 |
231 |
|
232 |
c-- Determine the mask on weights |
233 |
do k = 1,nnzobs |
234 |
do j = jmin,jmax |
235 |
do i = imin,imax |
236 |
cmask(i,j,k) = cosphi(i,j,bi,bj)*localmask(i,j,k,bi,bj) |
237 |
if ( localobs(i,j,k,bi,bj) .lt. spminloc .or. |
238 |
& localobs(i,j,k,bi,bj) .gt. spmaxloc .or. |
239 |
& localobs(i,j,k,bi,bj) .eq. spzeroloc ) then |
240 |
cmask(i,j,k) = 0. _d 0 |
241 |
endif |
242 |
enddo |
243 |
enddo |
244 |
enddo |
245 |
c-- |
246 |
do k = 1,nnzobs |
247 |
do j = jmin,jmax |
248 |
do i = imin,imax |
249 |
localwww = localweight(i,j,k,bi,bj)*cmask(i,j,k) |
250 |
junk = ( localbar(i,j,k,bi,bj) - |
251 |
& localobs(i,j,k,bi,bj) ) |
252 |
localcost = localcost + junk*junk*localwww |
253 |
if ( localwww .ne. 0. ) |
254 |
& num_local(bi,bj) = num_local(bi,bj) + 1. _d 0 |
255 |
enddo |
256 |
enddo |
257 |
enddo |
258 |
|
259 |
objf_local(bi,bj) = objf_local(bi,bj) + localcost |
260 |
|
261 |
enddo |
262 |
enddo |
263 |
|
264 |
enddo |
265 |
c-- End of second loop over records. |
266 |
|
267 |
c-- End of mult_local or localobsfile |
268 |
endif |
269 |
|
270 |
#endif /* ifdef ALLOW_COST */ |
271 |
|
272 |
end |