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

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

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


Revision 1.9 - (hide annotations) (download)
Mon Oct 20 03:20:57 2014 UTC (10 years, 8 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65j, checkpoint65h, checkpoint65i, checkpoint65g
Changes since 1.8: +13 -5 lines
- ECCO_OPTIONS.h is needed when including ecco_cost.h, ecco.h
- AUTODIFF_OPTIONS.h is needed when including tamc.h, tamc_keys.h
- CTRL_OPTIONS.h is needed when including ctrl.h, etc

- pkg/seaice/seaice_cost*.F : clean up CPP brackets
- SEAICE_SIZE.h : replace ALLOW_AUTODIFF_TAMC with ALLOW_AUTODIFF to
  avoid needing AUTODIFF_OPTIONS.h anytime SEAICE_SIZE.h is included
  (it seems that THSICE_SIZE.h, PTRACERS_SIZE.h have the same issue...)

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

  ViewVC Help
Powered by ViewVC 1.1.22