/[MITgcm]/MITgcm/pkg/seaice/seaice_cost_sss.F
ViewVC logotype

Contents of /MITgcm/pkg/seaice/seaice_cost_sss.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Mon Mar 15 18:31:11 2010 UTC (15 years, 3 months ago) by heimbach
Branch: MAIN
Merge/update IF seaice_cost routines.

1 c ian fenty
2 #include "COST_CPPOPTIONS.h"
3
4 c read the area dat file and compare against the averaged salinity file
5
6 subroutine seaice_cost_sss(
7 & nnzbar, localbarfile, localbar, xx_localbar_mean_dummy,
8 & areabarfile, areabar, xx_areabar_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 implicit none
17
18 c == global variables ==
19
20 #include "EEPARAMS.h"
21 #include "SIZE.h"
22 #include "PARAMS.h"
23 #ifdef ALLOW_CAL
24 # include "cal.h"
25 #endif
26 #ifdef ALLOW_COST
27 # include "ecco_cost.h"
28 # include "optim.h"
29 # ifdef ALLOW_SEAICE
30 # include "SEAICE_COST.h"
31 # include "SEAICE_PARAMS.h"
32 # endif
33 #endif
34
35 c == routine arguments ==
36
37 integer nnzbar
38 integer nnzobs
39 integer nrecloc
40 integer myiter
41 integer mythid
42 integer localstartdate(4)
43
44 _RL localbar (1-olx:snx+olx,1-oly:sny+oly,nnzbar,nsx,nsy)
45 _RL areabar (1-olx:snx+olx,1-oly:sny+oly,nnzbar,nsx,nsy)
46
47 _RL localobs (1-olx:snx+olx,1-oly:sny+oly,nnzobs,nsx,nsy)
48 _RL localweight(1-olx:snx+olx,1-oly:sny+oly,nsx,nsy)
49 _RL localmask (1-olx:snx+olx,1-oly:sny+oly,nr,nsx,nsy)
50 _RL xx_localbar_mean_dummy
51 _RL xx_areabar_mean_dummy
52 _RL mult_local
53 _RL mytime
54 _RL localperiod
55 _RL spminloc
56 _RL spmaxloc
57 _RL spzeroloc
58 _RL objf_local(nsx,nsy)
59 _RL num_local(nsx,nsy)
60
61 character*(MAX_LEN_FNAM) areabarfile
62 character*(MAX_LEN_FNAM) localbarfile
63 character*(MAX_LEN_FNAM) localobsfile
64
65 #ifdef ALLOW_COST
66 c == local variables ==
67
68 integer bi,bj
69 integer i,j,k
70 integer itlo,ithi
71 integer jtlo,jthi
72 integer jmin,jmax
73 integer imin,imax
74 integer irec
75 integer il
76 integer localrec
77 integer obsrec
78
79 logical doglobalread
80 logical ladinit
81
82 _RL spval
83 parameter (spval = -9999. )
84 _RL localwww
85 _RL localcost
86 _RL junk
87
88 _RL cmask (1-olx:snx+olx,1-oly:sny+oly,nnzobs)
89
90 character*(128) fname1, fname2,fname3
91 character*(MAX_LEN_MBUF) msgbuf
92
93 cnew(
94 _RL daytime
95 _RL diffsecs
96 integer dayiter
97 integer daydate(4)
98 integer difftime(4)
99 integer middate(4)
100 integer yday, ymod
101 integer md, dd, sd, ld, wd
102 integer mody, modm
103 integer beginmodel, beginlocal
104 logical exst
105 cnew)
106
107 c == external functions ==
108
109 integer ilnblnk
110 external ilnblnk
111
112 c == end of interface ==
113
114 jtlo = mybylo(mythid)
115 jthi = mybyhi(mythid)
116 itlo = mybxlo(mythid)
117 ithi = mybxhi(mythid)
118 jmin = 1
119 jmax = sny
120 imin = 1
121 imax = snx
122
123 c-- Initialise local variables.
124
125 localwww = 0. _d 0
126
127 do bj = jtlo,jthi
128 do bi = itlo,ithi
129 objf_local(bi,bj) = 0. _d 0
130 num_local(bi,bj) = 0. _d 0
131 enddo
132 enddo
133
134 c-- First, read tiled data.
135 doglobalread = .false.
136 ladinit = .false.
137
138
139 write(fname1(1:128),'(80a)') ' '
140 csss
141 write(fname3(1:128),'(80a)') ' '
142
143 il=ilnblnk( localbarfile )
144 write(fname1(1:128),'(2a,i10.10)')
145 & localbarfile(1:il),'.',optimcycle
146
147 csss
148 il=ilnblnk( areabarfile )
149 write(fname3(1:128),'(2a,i10.10)')
150 & areabarfile(1:il),'.',optimcycle
151
152 if ( .NOT. ( localobsfile.EQ.' ' ) ) then
153
154 c-- Loop over records for the second time.
155 do irec = 1, nrecloc
156
157 if ( nnzbar .EQ. 1 ) then
158 call active_read_xy( fname1, localbar, irec, doglobalread,
159 & ladinit, optimcycle, mythid,
160 & xx_localbar_mean_dummy )
161 else
162 call active_read_xyz( fname1, localbar, irec, doglobalread,
163 & ladinit, optimcycle, mythid,
164 & xx_localbar_mean_dummy )
165 endif
166
167 csss
168 if ( nnzbar .EQ. 1 ) then
169 call active_read_xy( fname3, areabar, irec, doglobalread,
170 & ladinit, optimcycle, mythid,
171 & xx_areabar_mean_dummy )
172 else
173 call active_read_xyz( fname3, areabar, irec, doglobalread,
174 & ladinit, optimcycle, mythid,
175 & xx_areabar_mean_dummy )
176 endif
177
178 cnew(
179 obsrec = irec
180
181 daytime = FLOAT(secondsperday*(irec-1)) + modelstart
182 dayiter = hoursperday*(irec-1)+modeliter0
183
184 call cal_getdate( dayiter, daytime, daydate, mythid )
185 call cal_convdate( daydate,yday,md,dd,sd,ld,wd,mythid )
186 ymod = smrareastartdate(1)/10000
187
188 #ifdef SEAICE_DEBUG
189 print *,'cost_seaice_sss'
190 print *,'daydate ', daydate
191 print *,'areaobsfile: ', localobsfile
192 print *,'nrecloc ', nrecloc
193 print *,'obsrec,daytime ', obsrec,daytime
194 print *,'dayiter ', dayiter
195 print *,'yday : ', yday
196 print *,'md,dd,sd ', md,dd,sd
197 print *,'ld,wd ', ld,wd
198 print *,'loclstrtdte(1) ', localstartdate(1)
199 print *,'ymod, yday ', ymod,yday
200 print *,'smrarstrtdt(1) ', smrareastartdate(1)
201 print *,'smrarstartdate ', smrareastartdate
202 #endif SEAICE_DEBUG
203
204 if ( ymod .EQ. yday ) then
205 middate(1) = smrareastartdate(1)
206 else
207 middate(1) = yday*10000+100+1
208 endif
209 middate(2) = 0
210 middate(3) = modelstartdate(3)
211 middate(4) = modelstartdate(4)
212
213
214 call cal_TimePassed( middate, daydate, difftime, mythid )
215 call cal_ToSeconds( difftime, diffsecs, mythid )
216
217 localrec = int(diffsecs/localperiod) + 1
218
219 #ifdef SEAICE_DEBUG
220 print *,'middate(1,2) ',middate(1),middate(2)
221 print *,'middate(3,4) ', middate(3),middate(4)
222 print *,'difftime,diffsecs',difftime,diffsecs
223 print *,'localrec ',localrec
224 #endif
225
226 il=ilnblnk(localobsfile)
227 write(fname2(1:128),'(2a,i4)')
228 & localobsfile(1:il), '_', yday
229 inquire( file=fname2, exist=exst )
230
231 #ifdef SEAICE_DEBUG
232 print *,'fname2',fname2
233 #endif
234 if (.NOT. exst) then
235 write(fname2(1:128),'(a)') localobsfile(1:il)
236 localrec = obsrec
237 #ifdef SEAICE_DEBUG
238 print *,'localrec ', localrec
239 print *,'not exist'
240 #endif
241 endif
242
243 if ( localrec .GT. 0 ) then
244
245 #ifdef SEAICE_DEBUG
246 print *,'calling mdsreadfile',fname2,localrec
247 #endif
248
249 call mdsreadfield( fname2, cost_iprec, cost_yftype, nnzobs,
250 & localobs, localrec, mythid )
251 else
252 do bj = jtlo,jthi
253 do bi = itlo,ithi
254 do k = 1,nnzobs
255 do j = jmin,jmax
256 do i = imin,imax
257 localobs(i,j,k,bi,bj) = spval
258 enddo
259 enddo
260 enddo
261 enddo
262 enddo
263 endif
264 cnew)
265
266 #ifdef SEAICE_DEBUG
267 do bj = jtlo,jthi
268 do bi = itlo,ithi
269 do k = 1,nnzobs
270 do i = imin,imax
271 do j = jmin,jmax
272 if (localobs(i,j,k,bi,bj) .LT. -1) THEN
273 print *,'obs rec date: ', -localobs(i,j,1,bi,bj)
274 endif
275 enddo
276 enddo
277 enddo
278 enddo
279 enddo
280 #endif
281
282 do bj = jtlo,jthi
283 do bi = itlo,ithi
284
285 localcost = 0. _d 0
286
287 c-- Determine the mask on weights
288 do k = 1,nnzobs
289 do j = jmin,jmax
290 do i = imin,imax
291 cmask(i,j,k) = cosphi(i,j,bi,bj)*localmask(i,j,k,bi,bj)
292 if ( localobs(i,j,k,bi,bj) .lt. spminloc .or.
293 & localobs(i,j,k,bi,bj) .gt. spmaxloc .or.
294 & localobs(i,j,k,bi,bj) .eq. spzeroloc ) then
295 cmask(i,j,k) = 0. _d 0
296 endif
297 enddo
298 enddo
299 enddo
300 c--
301 do k = 1,nnzobs
302 do j = jmin,jmax
303 do i = imin,imax
304 localwww = localweight(i,j,bi,bj)*cmask(i,j,k)
305
306 c only accumulate cost if there is ice observed but not simulated..
307 if ( localobs(i,j,k,bi,bj) .GT. 0.0 .AND.
308 & areabar(i,j,1,bi,bj) .LE. 0.0) then
309
310 c if ( localobs(i,j,k,bi,bj) .GT.
311 c & areabar(i,j,1,bi,bj)) then
312
313 junk = ( localbar(i,j,k,bi,bj) - SEAICE_clamp_salt )
314
315 c junk = localbar(i,j,k,bi,bj) -
316 c & ( localbar(i,j,k,bi,bj) - 1.0)
317 else
318 junk = 0.0
319 endif
320
321 localcost = localcost + junk*junk*localwww
322
323 #ifdef SEAICE_DEBUG
324 if ((i == SEAICE_debugPointX) .and.
325 & (j == SEAICE_debugPointY)) then
326
327 print '(A,2i4,3(1x,1P2E15.3))',
328 & 'costg i j sbar, abar,obs ',i,j,
329 & localbar(i,j,k,bi,bj),
330 & areabar(i,j,k,bi,bj),
331 & localobs(i,j,k,bi,bj)
332
333 print '(A,2i4,2(1x,1P2E15.3))',
334 & 'costg i j bar-obs,wgt,loCost ',i,j,
335 & junk,
336 & localwww,
337 & localcost
338 endif
339 #endif
340
341 if ( localwww .ne. 0. )
342 & num_local(bi,bj) = num_local(bi,bj) + 1. _d 0
343 enddo
344 enddo
345 enddo
346
347 objf_local(bi,bj) = objf_local(bi,bj) + localcost
348
349 enddo !/bj
350 enddo !/ bi
351
352 enddo
353 c-- End of second loop over records.
354
355 c-- End of mult_local or localobsfile
356 endif
357 #endif /* ifdef ALLOW_COST */
358
359 end

  ViewVC Help
Powered by ViewVC 1.1.22