/[MITgcm]/MITgcm/pkg/ecco/cost_generic.F
ViewVC logotype

Contents of /MITgcm/pkg/ecco/cost_generic.F

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


Revision 1.9 - (show annotations) (download)
Sat Feb 6 02:43:03 2010 UTC (14 years, 3 months ago) by heimbach
Branch: MAIN
Changes since 1.8: +10 -3 lines
Preparing usage of generic cost function terms.
Enable with CPP option
#ifdef ALLOW_GENCOST_CONTRIBUTION
First usage is adding air-sea flux constraints when using bulk controls.
---> NOT YET READY FOR PRIME TIME <---

1 C $Header: /u/gcmpack/MITgcm/pkg/ecco/cost_generic.F,v 1.8 2007/10/09 00:02:50 jmc Exp $
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, 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 localweight(1-olx:snx+olx,1-oly:sny+oly,nnzobs,nsx,nsy)
56 _RL localmask (1-olx:snx+olx,1-oly:sny+oly,nr,nsx,nsy)
57 _RL xx_localbar_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) localbarfile
68 character*(MAX_LEN_FNAM) localobsfile
69
70 #ifdef ALLOW_COST
71 c == local variables ==
72
73 integer bi,bj
74 integer i,j,k
75 integer itlo,ithi
76 integer jtlo,jthi
77 integer jmin,jmax
78 integer imin,imax
79 integer irec
80 integer il
81 integer localrec
82 integer obsrec
83
84 logical doglobalread
85 logical ladinit
86
87 _RL spval
88 parameter (spval = -9999. )
89 _RL localwww
90 _RL localcost
91 _RL junk
92
93 _RL localobs (1-olx:snx+olx,1-oly:sny+oly,nnzobs,nsx,nsy)
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 do k = 1,nnzobs
138 do j = jmin,jmax
139 do i = imin,imax
140 localobs(i,j,k,bi,bj) = 0. _d 0
141 enddo
142 enddo
143 enddo
144 enddo
145 enddo
146
147 c-- First, read tiled data.
148 doglobalread = .false.
149 ladinit = .false.
150
151 write(fname1(1:128),'(80a)') ' '
152 il=ilnblnk( localbarfile )
153 write(fname1(1:128),'(2a,i10.10)')
154 & localbarfile(1:il),'.',optimcycle
155
156 cph if ( .NOT. ( mult_local.EQ.0. .OR. localobsfile.EQ.' ' ) ) then
157 if ( .NOT. ( localobsfile.EQ.' ' ) ) then
158
159 c-- Loop over records for the second time.
160 do irec = 1, nrecloc
161
162 if ( nnzbar .EQ. 1 ) then
163 call active_read_xy( fname1, localbar, irec, doglobalread,
164 & ladinit, optimcycle, mythid,
165 & xx_localbar_mean_dummy )
166 else
167 call active_read_xyz( fname1, localbar, irec, doglobalread,
168 & ladinit, optimcycle, mythid,
169 & xx_localbar_mean_dummy )
170 endif
171
172 cnew(
173 if ( localperiod .EQ. 86400. ) then
174 c-- assume daily fields
175 obsrec = irec
176 daytime = FLOAT(secondsperday*(irec-1))
177 dayiter = hoursperday*(irec-1)
178 call cal_getdate( dayiter, daytime, daydate, mythid )
179 call cal_convdate( daydate,yday,md,dd,sd,ld,wd,mythid )
180 ymod = localstartdate(1)/10000
181 if ( ymod .EQ. yday ) then
182 middate(1) = modelstartdate(1)
183 else
184 middate(1) = yday*10000+100+1
185 endif
186 middate(2) = 0
187 middate(3) = modelstartdate(3)
188 middate(4) = modelstartdate(4)
189 call cal_TimePassed( middate, daydate, difftime, mythid )
190 call cal_ToSeconds( difftime, diffsecs, mythid )
191 localrec = int(diffsecs/localperiod) + 1
192 else
193 c-- assume monthly fields
194 beginlocal = localstartdate(1)/10000
195 beginmodel = modelstartdate(1)/10000
196 obsrec =
197 & ( beginmodel - beginlocal )*nmonthyear
198 & + ( mod(modelstartdate(1)/100,100)
199 & -mod(localstartdate(1)/100,100) )
200 & + irec
201 mody = modelstartdate(1)/10000
202 modm = modelstartdate(1)/100 - mody*100
203 yday = mody + INT((modm-1+irec-1)/12)
204 localrec = 1 + MOD(modm-1+irec-1,12)
205 endif
206
207 il=ilnblnk(localobsfile)
208 write(fname2(1:128),'(2a,i4)')
209 & localobsfile(1:il), '_', yday
210 inquire( file=fname2, exist=exst )
211 if (.NOT. exst) then
212 write(fname2(1:128),'(a)') localobsfile(1:il)
213 localrec = obsrec
214 endif
215
216 if ( localrec .GT. 0 ) then
217 call mdsreadfield( fname2, cost_iprec, cost_yftype, nnzobs,
218 & localobs, localrec, mythid )
219 else
220 do bj = jtlo,jthi
221 do bi = itlo,ithi
222 do k = 1,nnzobs
223 do j = jmin,jmax
224 do i = imin,imax
225 localobs(i,j,k,bi,bj) = spval
226 enddo
227 enddo
228 enddo
229 enddo
230 enddo
231 endif
232 cnew)
233
234 do bj = jtlo,jthi
235 do bi = itlo,ithi
236
237 localcost = 0. _d 0
238
239 c-- Determine the mask on weights
240 do k = 1,nnzobs
241 do j = jmin,jmax
242 do i = imin,imax
243 cmask(i,j,k) = cosphi(i,j,bi,bj)*localmask(i,j,k,bi,bj)
244 if ( localobs(i,j,k,bi,bj) .lt. spminloc .or.
245 & localobs(i,j,k,bi,bj) .gt. spmaxloc .or.
246 & localobs(i,j,k,bi,bj) .eq. spzeroloc ) then
247 cmask(i,j,k) = 0. _d 0
248 endif
249 enddo
250 enddo
251 enddo
252 c--
253 do k = 1,nnzobs
254 do j = jmin,jmax
255 do i = imin,imax
256 localwww = localweight(i,j,k,bi,bj)*cmask(i,j,k)
257 junk = ( localbar(i,j,k,bi,bj) -
258 & localobs(i,j,k,bi,bj) )
259 localcost = localcost + junk*junk*localwww
260 if ( localwww .ne. 0. )
261 & num_local(bi,bj) = num_local(bi,bj) + 1. _d 0
262 enddo
263 enddo
264 enddo
265
266 objf_local(bi,bj) = objf_local(bi,bj) + localcost
267
268 enddo
269 enddo
270
271 enddo
272 c-- End of second loop over records.
273
274 c-- End of mult_local or localobsfile
275 endif
276
277 #endif /* ifdef ALLOW_COST */
278
279 end

  ViewVC Help
Powered by ViewVC 1.1.22