1 |
gforget |
1.8 |
C $Header: /u/gcmpack/MITgcm/pkg/seaice/seaice_cost_sss.F,v 1.7 2012/11/09 22:15:18 heimbach Exp $ |
2 |
heimbach |
1.2 |
C $Name: $ |
3 |
|
|
|
4 |
|
|
#include "SEAICE_OPTIONS.h" |
5 |
heimbach |
1.1 |
|
6 |
|
|
c read the area dat file and compare against the averaged salinity file |
7 |
|
|
|
8 |
jmc |
1.3 |
subroutine seaice_cost_sss( |
9 |
heimbach |
1.1 |
& nnzbar, localbarfile, localbar, xx_localbar_mean_dummy, |
10 |
|
|
& areabarfile, areabar, xx_areabar_mean_dummy, |
11 |
|
|
& nnzobs, localobsfile, localobs, mult_local, |
12 |
|
|
& nrecloc, localstartdate, localperiod, |
13 |
|
|
& localmask, localweight, |
14 |
|
|
& spminloc, spmaxloc, spzeroloc, |
15 |
|
|
& objf_local, num_local, |
16 |
|
|
& myiter, mytime, mythid ) |
17 |
|
|
|
18 |
|
|
implicit none |
19 |
|
|
|
20 |
heimbach |
1.2 |
c ian fenty |
21 |
heimbach |
1.1 |
c == global variables == |
22 |
|
|
|
23 |
|
|
#include "EEPARAMS.h" |
24 |
|
|
#include "SIZE.h" |
25 |
|
|
#include "PARAMS.h" |
26 |
|
|
#ifdef ALLOW_CAL |
27 |
|
|
# include "cal.h" |
28 |
|
|
#endif |
29 |
|
|
#ifdef ALLOW_COST |
30 |
|
|
# include "optim.h" |
31 |
heimbach |
1.4 |
# ifdef ALLOW_ECCO |
32 |
gforget |
1.8 |
# include "ecco.h" |
33 |
heimbach |
1.4 |
# endif |
34 |
heimbach |
1.1 |
# ifdef ALLOW_SEAICE |
35 |
|
|
# include "SEAICE_COST.h" |
36 |
heimbach |
1.7 |
# include "SEAICE_SIZE.h" |
37 |
heimbach |
1.1 |
# include "SEAICE_PARAMS.h" |
38 |
|
|
# endif |
39 |
|
|
#endif |
40 |
|
|
|
41 |
|
|
c == routine arguments == |
42 |
|
|
|
43 |
|
|
integer nnzbar |
44 |
|
|
integer nnzobs |
45 |
|
|
integer nrecloc |
46 |
|
|
integer myiter |
47 |
|
|
integer mythid |
48 |
|
|
integer localstartdate(4) |
49 |
|
|
|
50 |
|
|
_RL localbar (1-olx:snx+olx,1-oly:sny+oly,nnzbar,nsx,nsy) |
51 |
|
|
_RL areabar (1-olx:snx+olx,1-oly:sny+oly,nnzbar,nsx,nsy) |
52 |
|
|
|
53 |
|
|
_RL localobs (1-olx:snx+olx,1-oly:sny+oly,nnzobs,nsx,nsy) |
54 |
|
|
_RL localweight(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy) |
55 |
jmc |
1.6 |
_RS localmask (1-olx:snx+olx,1-oly:sny+oly,nr,nsx,nsy) |
56 |
heimbach |
1.1 |
_RL xx_localbar_mean_dummy |
57 |
|
|
_RL xx_areabar_mean_dummy |
58 |
|
|
_RL mult_local |
59 |
|
|
_RL mytime |
60 |
|
|
_RL localperiod |
61 |
|
|
_RL spminloc |
62 |
|
|
_RL spmaxloc |
63 |
|
|
_RL spzeroloc |
64 |
|
|
_RL objf_local(nsx,nsy) |
65 |
|
|
_RL num_local(nsx,nsy) |
66 |
|
|
|
67 |
|
|
character*(MAX_LEN_FNAM) areabarfile |
68 |
|
|
character*(MAX_LEN_FNAM) localbarfile |
69 |
|
|
character*(MAX_LEN_FNAM) localobsfile |
70 |
|
|
|
71 |
heimbach |
1.5 |
#if (defined (ALLOW_ECCO) && defined (ALLOW_COST)) |
72 |
heimbach |
1.1 |
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 |
jmc |
1.3 |
_RL cmask (1-olx:snx+olx,1-oly:sny+oly,nnzobs) |
95 |
heimbach |
1.1 |
|
96 |
|
|
character*(128) fname1, fname2,fname3 |
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 |
|
|
|
145 |
|
|
write(fname1(1:128),'(80a)') ' ' |
146 |
|
|
csss |
147 |
|
|
write(fname3(1:128),'(80a)') ' ' |
148 |
|
|
|
149 |
|
|
il=ilnblnk( localbarfile ) |
150 |
jmc |
1.3 |
write(fname1(1:128),'(2a,i10.10)') |
151 |
heimbach |
1.1 |
& localbarfile(1:il),'.',optimcycle |
152 |
|
|
|
153 |
|
|
csss |
154 |
|
|
il=ilnblnk( areabarfile ) |
155 |
jmc |
1.3 |
write(fname3(1:128),'(2a,i10.10)') |
156 |
heimbach |
1.1 |
& areabarfile(1:il),'.',optimcycle |
157 |
|
|
|
158 |
|
|
if ( .NOT. ( localobsfile.EQ.' ' ) ) then |
159 |
|
|
|
160 |
|
|
c-- Loop over records for the second time. |
161 |
|
|
do irec = 1, nrecloc |
162 |
|
|
|
163 |
|
|
if ( nnzbar .EQ. 1 ) then |
164 |
|
|
call active_read_xy( fname1, localbar, irec, doglobalread, |
165 |
jmc |
1.3 |
& ladinit, optimcycle, mythid, |
166 |
heimbach |
1.1 |
& xx_localbar_mean_dummy ) |
167 |
|
|
else |
168 |
|
|
call active_read_xyz( fname1, localbar, irec, doglobalread, |
169 |
jmc |
1.3 |
& ladinit, optimcycle, mythid, |
170 |
heimbach |
1.1 |
& xx_localbar_mean_dummy ) |
171 |
|
|
endif |
172 |
|
|
|
173 |
|
|
csss |
174 |
|
|
if ( nnzbar .EQ. 1 ) then |
175 |
|
|
call active_read_xy( fname3, areabar, irec, doglobalread, |
176 |
jmc |
1.3 |
& ladinit, optimcycle, mythid, |
177 |
heimbach |
1.1 |
& xx_areabar_mean_dummy ) |
178 |
|
|
else |
179 |
|
|
call active_read_xyz( fname3, areabar, irec, doglobalread, |
180 |
jmc |
1.3 |
& ladinit, optimcycle, mythid, |
181 |
heimbach |
1.1 |
& xx_areabar_mean_dummy ) |
182 |
|
|
endif |
183 |
|
|
|
184 |
|
|
cnew( |
185 |
|
|
obsrec = irec |
186 |
|
|
|
187 |
|
|
daytime = FLOAT(secondsperday*(irec-1)) + modelstart |
188 |
|
|
dayiter = hoursperday*(irec-1)+modeliter0 |
189 |
|
|
|
190 |
|
|
call cal_getdate( dayiter, daytime, daydate, mythid ) |
191 |
|
|
call cal_convdate( daydate,yday,md,dd,sd,ld,wd,mythid ) |
192 |
|
|
ymod = smrareastartdate(1)/10000 |
193 |
|
|
|
194 |
|
|
#ifdef SEAICE_DEBUG |
195 |
|
|
print *,'cost_seaice_sss' |
196 |
|
|
print *,'daydate ', daydate |
197 |
|
|
print *,'areaobsfile: ', localobsfile |
198 |
|
|
print *,'nrecloc ', nrecloc |
199 |
|
|
print *,'obsrec,daytime ', obsrec,daytime |
200 |
|
|
print *,'dayiter ', dayiter |
201 |
|
|
print *,'yday : ', yday |
202 |
|
|
print *,'md,dd,sd ', md,dd,sd |
203 |
|
|
print *,'ld,wd ', ld,wd |
204 |
|
|
print *,'loclstrtdte(1) ', localstartdate(1) |
205 |
|
|
print *,'ymod, yday ', ymod,yday |
206 |
|
|
print *,'smrarstrtdt(1) ', smrareastartdate(1) |
207 |
|
|
print *,'smrarstartdate ', smrareastartdate |
208 |
jmc |
1.3 |
#endif /* SEAICE_DEBUG */ |
209 |
heimbach |
1.1 |
|
210 |
|
|
if ( ymod .EQ. yday ) then |
211 |
jmc |
1.3 |
middate(1) = smrareastartdate(1) |
212 |
heimbach |
1.1 |
else |
213 |
|
|
middate(1) = yday*10000+100+1 |
214 |
|
|
endif |
215 |
|
|
middate(2) = 0 |
216 |
|
|
middate(3) = modelstartdate(3) |
217 |
|
|
middate(4) = modelstartdate(4) |
218 |
|
|
|
219 |
|
|
|
220 |
|
|
call cal_TimePassed( middate, daydate, difftime, mythid ) |
221 |
|
|
call cal_ToSeconds( difftime, diffsecs, mythid ) |
222 |
|
|
|
223 |
|
|
localrec = int(diffsecs/localperiod) + 1 |
224 |
|
|
|
225 |
|
|
#ifdef SEAICE_DEBUG |
226 |
|
|
print *,'middate(1,2) ',middate(1),middate(2) |
227 |
|
|
print *,'middate(3,4) ', middate(3),middate(4) |
228 |
|
|
print *,'difftime,diffsecs',difftime,diffsecs |
229 |
|
|
print *,'localrec ',localrec |
230 |
jmc |
1.3 |
#endif |
231 |
heimbach |
1.1 |
|
232 |
|
|
il=ilnblnk(localobsfile) |
233 |
|
|
write(fname2(1:128),'(2a,i4)') |
234 |
|
|
& localobsfile(1:il), '_', yday |
235 |
|
|
inquire( file=fname2, exist=exst ) |
236 |
|
|
|
237 |
|
|
#ifdef SEAICE_DEBUG |
238 |
|
|
print *,'fname2',fname2 |
239 |
|
|
#endif |
240 |
|
|
if (.NOT. exst) then |
241 |
|
|
write(fname2(1:128),'(a)') localobsfile(1:il) |
242 |
|
|
localrec = obsrec |
243 |
|
|
#ifdef SEAICE_DEBUG |
244 |
|
|
print *,'localrec ', localrec |
245 |
|
|
print *,'not exist' |
246 |
|
|
#endif |
247 |
|
|
endif |
248 |
|
|
|
249 |
jmc |
1.3 |
if ( localrec .GT. 0 ) then |
250 |
heimbach |
1.1 |
|
251 |
|
|
#ifdef SEAICE_DEBUG |
252 |
|
|
print *,'calling mdsreadfile',fname2,localrec |
253 |
|
|
#endif |
254 |
|
|
|
255 |
jmc |
1.3 |
call mdsreadfield( fname2, cost_iprec, cost_yftype, nnzobs, |
256 |
heimbach |
1.1 |
& localobs, localrec, mythid ) |
257 |
|
|
else |
258 |
|
|
do bj = jtlo,jthi |
259 |
|
|
do bi = itlo,ithi |
260 |
|
|
do k = 1,nnzobs |
261 |
|
|
do j = jmin,jmax |
262 |
|
|
do i = imin,imax |
263 |
|
|
localobs(i,j,k,bi,bj) = spval |
264 |
|
|
enddo |
265 |
|
|
enddo |
266 |
|
|
enddo |
267 |
|
|
enddo |
268 |
|
|
enddo |
269 |
|
|
endif |
270 |
|
|
cnew) |
271 |
|
|
|
272 |
|
|
#ifdef SEAICE_DEBUG |
273 |
|
|
do bj = jtlo,jthi |
274 |
|
|
do bi = itlo,ithi |
275 |
|
|
do k = 1,nnzobs |
276 |
|
|
do i = imin,imax |
277 |
|
|
do j = jmin,jmax |
278 |
|
|
if (localobs(i,j,k,bi,bj) .LT. -1) THEN |
279 |
|
|
print *,'obs rec date: ', -localobs(i,j,1,bi,bj) |
280 |
|
|
endif |
281 |
|
|
enddo |
282 |
|
|
enddo |
283 |
|
|
enddo |
284 |
|
|
enddo |
285 |
|
|
enddo |
286 |
|
|
#endif |
287 |
|
|
|
288 |
|
|
do bj = jtlo,jthi |
289 |
|
|
do bi = itlo,ithi |
290 |
|
|
|
291 |
|
|
localcost = 0. _d 0 |
292 |
|
|
|
293 |
|
|
c-- Determine the mask on weights |
294 |
|
|
do k = 1,nnzobs |
295 |
|
|
do j = jmin,jmax |
296 |
|
|
do i = imin,imax |
297 |
|
|
cmask(i,j,k) = cosphi(i,j,bi,bj)*localmask(i,j,k,bi,bj) |
298 |
|
|
if ( localobs(i,j,k,bi,bj) .lt. spminloc .or. |
299 |
|
|
& localobs(i,j,k,bi,bj) .gt. spmaxloc .or. |
300 |
|
|
& localobs(i,j,k,bi,bj) .eq. spzeroloc ) then |
301 |
|
|
cmask(i,j,k) = 0. _d 0 |
302 |
|
|
endif |
303 |
|
|
enddo |
304 |
|
|
enddo |
305 |
|
|
enddo |
306 |
|
|
c-- |
307 |
|
|
do k = 1,nnzobs |
308 |
|
|
do j = jmin,jmax |
309 |
|
|
do i = imin,imax |
310 |
|
|
localwww = localweight(i,j,bi,bj)*cmask(i,j,k) |
311 |
|
|
|
312 |
|
|
c only accumulate cost if there is ice observed but not simulated.. |
313 |
jmc |
1.3 |
if ( localobs(i,j,k,bi,bj) .GT. 0.0 .AND. |
314 |
heimbach |
1.1 |
& areabar(i,j,1,bi,bj) .LE. 0.0) then |
315 |
|
|
|
316 |
jmc |
1.3 |
c if ( localobs(i,j,k,bi,bj) .GT. |
317 |
heimbach |
1.1 |
c & areabar(i,j,1,bi,bj)) then |
318 |
|
|
|
319 |
|
|
junk = ( localbar(i,j,k,bi,bj) - SEAICE_clamp_salt ) |
320 |
|
|
|
321 |
|
|
c junk = localbar(i,j,k,bi,bj) - |
322 |
|
|
c & ( localbar(i,j,k,bi,bj) - 1.0) |
323 |
|
|
else |
324 |
|
|
junk = 0.0 |
325 |
|
|
endif |
326 |
|
|
|
327 |
|
|
localcost = localcost + junk*junk*localwww |
328 |
|
|
|
329 |
|
|
#ifdef SEAICE_DEBUG |
330 |
|
|
if ((i == SEAICE_debugPointX) .and. |
331 |
|
|
& (j == SEAICE_debugPointY)) then |
332 |
|
|
|
333 |
|
|
print '(A,2i4,3(1x,1P2E15.3))', |
334 |
|
|
& 'costg i j sbar, abar,obs ',i,j, |
335 |
|
|
& localbar(i,j,k,bi,bj), |
336 |
|
|
& areabar(i,j,k,bi,bj), |
337 |
|
|
& localobs(i,j,k,bi,bj) |
338 |
|
|
|
339 |
|
|
print '(A,2i4,2(1x,1P2E15.3))', |
340 |
|
|
& 'costg i j bar-obs,wgt,loCost ',i,j, |
341 |
jmc |
1.3 |
& junk, |
342 |
|
|
& localwww, |
343 |
heimbach |
1.1 |
& localcost |
344 |
|
|
endif |
345 |
|
|
#endif |
346 |
|
|
|
347 |
|
|
if ( localwww .ne. 0. ) |
348 |
|
|
& num_local(bi,bj) = num_local(bi,bj) + 1. _d 0 |
349 |
|
|
enddo |
350 |
|
|
enddo |
351 |
|
|
enddo |
352 |
|
|
|
353 |
|
|
objf_local(bi,bj) = objf_local(bi,bj) + localcost |
354 |
|
|
|
355 |
|
|
enddo !/bj |
356 |
|
|
enddo !/ bi |
357 |
|
|
|
358 |
|
|
enddo |
359 |
|
|
c-- End of second loop over records. |
360 |
|
|
|
361 |
|
|
c-- End of mult_local or localobsfile |
362 |
|
|
endif |
363 |
|
|
#endif /* ifdef ALLOW_COST */ |
364 |
|
|
|
365 |
|
|
end |