forked from altMITgcm/MITgcm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecco_cost_init_fixed.F
382 lines (342 loc) · 11.7 KB
/
ecco_cost_init_fixed.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
C $Header: /u/gcmpack/MITgcm/pkg/ecco/ecco_cost_init_fixed.F,v 1.46 2016/09/20 17:15:13 gforget Exp $
C $Name: $
#include "ECCO_OPTIONS.h"
#include "AD_CONFIG.h"
subroutine ecco_cost_init_fixed( mythid )
c ==================================================================
c SUBROUTINE ecco_cost_init_fixed
c ==================================================================
c
c o Set contributions to the cost function and the cost function
c itself to zero. The cost function and the individual contribu-
c tions are defined in the header file "ecco_cost.h".
c
c started: Christian Eckert eckert@mit.edu 30-Jun-1999
c
c changed: Christian Eckert eckert@mit.edu 25-Feb-2000
c
c - Restructured the code in order to create a package
c for the MITgcmUV.
c
c changed: Ralf Giering 18-Jan-2001
c
c - move namelist reading to cost_readparms.F
c
c ==================================================================
c SUBROUTINE ecco_cost_init_fixed
c ==================================================================
implicit none
c == global variables ==
#include "EEPARAMS.h"
#include "SIZE.h"
#include "GRID.h"
#include "PARAMS.h"
#ifdef ALLOW_CAL
#include "cal.h"
#endif
#ifdef ALLOW_ECCO
# ifdef ECCO_CTRL_DEPRECATED
# include "ecco_cost.h"
# else
# include "ecco.h"
# endif
#endif
#ifdef ALLOW_CTRL
# include "optim.h"
#endif
c == routine arguments ==
integer mythid
c == local variables ==
integer k
logical exst
_RL dummy
integer tempDate1(4)
integer tempDate2(4)
integer gwunit
integer il, ilo,ihi
character*(max_len_mbuf) msgbuf
integer irec
_RL missingObsFlag
PARAMETER ( missingObsFlag = 1. _d 23 )
#ifdef ALLOW_GENCOST_CONTRIBUTION
integer bi,bj
integer i,j,kk,k2
#endif
c == external functions ==
integer cal_IntYears
external cal_IntYears
integer cal_IntMonths
external cal_IntMonths
integer cal_IntDays
external cal_IntDays
integer ifnblnk
external ifnblnk
integer ilnblnk
external ilnblnk
c == end of interface ==
#ifdef ALLOW_CTRL
eccoiter=optimcycle
#else
eccoiter=0
#endif
#ifdef ALLOW_CAL
c-- The number of monthly and daily averages generated by the
c-- current model integration.
nyearsrec = cal_IntYears( mythid )
nmonsrec = cal_IntMonths( mythid )
ndaysrec = cal_IntDays( mythid )
_BEGIN_MASTER( myThid )
#ifdef ECCO_CTRL_DEPRECATED
c-- Get the complete dates of the ...
c-- ... TMI data.
if ( tmidatfile .ne. ' ' )
& call cal_FullDate( tmistartdate1, tmistartdate2,
& tmistartdate, mythid )
c-- ... SST data.
if ( sstdatfile .ne. ' ' )
& call cal_FullDate( sststartdate1, sststartdate2,
& sststartdate, mythid )
c-- ... SSS data.
if ( sssdatfile .ne. ' ' )
& call cal_FullDate( sssstartdate1, sssstartdate2,
& sssstartdate, mythid )
c-- ... BP data.
if ( bpdatfile .ne. ' ' )
& call cal_FullDate( bpstartdate1, bpstartdate2,
& bpstartdate, mythid )
c-- ... IES data.
if ( iesdatfile .ne. ' ' )
& call cal_FullDate( iesstartdate1, iesstartdate2,
& iesstartdate, mythid )
#ifdef ALLOW_SSH_MEAN_COST_CONTRIBUTION
c-- ... mdt data.
if ( mdtdatfile .ne. ' ' )
& call cal_FullDate( mdtstartdate1, mdtstartdate2,
& mdtstartdate, mythid )
c-- ... mdt data.
if ( mdtdatfile .ne. ' ' )
& call cal_FullDate( mdtenddate1, mdtenddate2,
& mdtenddate, mythid )
#endif /* ALLOW_SSH_MEAN_COST_CONTRIBUTION */
c-- ... T/P data.
if ( topexfile .ne. ' ' )
& call cal_FullDate( topexstartdate1, topexstartdate2,
& topexstartdate, mythid )
c-- ... ERS data.
if ( ersfile .ne. ' ' )
& call cal_FullDate( ersstartdate1, ersstartdate2,
& ersstartdate, mythid )
c-- ... GFO data.
if ( gfofile .ne. ' ' )
& call cal_FullDate( gfostartdate1, gfostartdate2,
& gfostartdate, mythid )
c-- ... SCAT data.
if ( scatxdatfile .ne. ' ' )
& call cal_FullDate( scatstartdate1, scatstartdate2,
& scatxstartdate, mythid )
if ( scatydatfile .ne. ' ' )
& call cal_FullDate( scatstartdate1, scatstartdate2,
& scatystartdate, mythid )
c-- ... ARGO data.
if ( argotfile .ne. ' ' )
& call cal_FullDate( argotstartdate1, argotstartdate2,
& argotstartdate, mythid )
if ( argosfile .ne. ' ' )
& call cal_FullDate( argosstartdate1, argotstartdate2,
& argosstartdate, mythid )
#endif /* ECCO_CTRL_DEPRECATED */
#ifdef ALLOW_GENCOST_CONTRIBUTION
do k = 1, NGENCOST
c-- skip averaging when several cost terms use the
c same barfile or when barfile is undefined
gencost_barskip(k)=.FALSE.
if ( gencost_barfile(k).EQ.' ' )
& gencost_barskip(k)=.TRUE.
do k2 = 1,k-1
if ( gencost_barfile(k2).EQ.gencost_barfile(k) )
& gencost_barskip(k)=.TRUE.
enddo
c-- set time averaging parameters
if ( (using_gencost(k)).AND.( (gencost_flag(k).GE.1).OR.
& (gencost_avgperiod(k).NE.' ') ) ) then
if ( gencost_avgperiod(k) .EQ. 'day' .OR.
& gencost_avgperiod(k) .EQ. 'DAY' ) then
gencost_nrec(k) = ndaysrec
gencost_period(k) = 86400.
else if ( gencost_avgperiod(k) .EQ. 'month' .OR.
& gencost_avgperiod(k) .EQ. 'MONTH' ) then
gencost_nrec(k) =nmonsrec
gencost_period(k) = 0.
else if ( gencost_avgperiod(k) .EQ. 'step' .OR.
& gencost_avgperiod(k) .EQ. 'STEP' ) then
gencost_nrec(k) =nTimeSteps+1
gencost_period(k) = dTtracerLev(1)
else if ( gencost_avgperiod(k) .EQ. 'const' .OR.
& gencost_avgperiod(k) .EQ. 'CONST' ) then
gencost_nrec(k) =1
gencost_period(k) = dTtracerLev(1)
else if ( gencost_avgperiod(k) .EQ. 'year' .OR.
& gencost_avgperiod(k) .EQ. 'YEAR' ) then
STOP
& 'ecco_cost_init_fixed: yearly data not yet implemented'
else
STOP
& 'ecco_cost_init_fixed: gencost_avgperiod wrongly specified'
endif
endif
c-- set observation start/enddate
if (gencost_startdate1(k).GT.0) then
call cal_FullDate(
& gencost_startdate1(k), gencost_startdate2(k),
& gencost_startdate(1,k), mythid )
else
call cal_CopyDate(modelStartDate,
& gencost_startdate(1,k),mythid)
gencost_startdate1(k)=startdate_1
gencost_startdate2(k)=startdate_2
endif
if (gencost_enddate1(k).GT.0) then
call cal_FullDate(
& gencost_enddate1(k), gencost_enddate2(k),
& gencost_enddate(1,k), mythid )
else
call cal_CopyDate(modelEndDate,
& gencost_enddate(1,k),mythid)
endif
enddo !do k = 1, NGENCOST
#endif /* ALLOW_GENCOST_CONTRIBUTION */
_END_MASTER( mythid )
#endif /* ALLOW_CAL */
call ecco_check( myThid )
c-- Get the weights that are to be used for the individual cost
c-- function contributions.
call ecco_cost_weights( mythid )
c-- Initialise adjoint of monthly mean files calculated
c-- in cost_averagesfields (and their ad...).
cph(
cph The following init. shoud not be applied if in the middle
cph of a divided adjoint run
cph)
#ifndef ALLOW_TANGENTLINEAR_RUN
cph!!! and I think it needs to be seen by TAF
cph!!! for repeated TLM runs
cph!!!
inquire( file='costfinal', exist=exst )
if ( .NOT. exst) then
call ecco_cost_init_barfiles( mythid )
endif
#endif
#ifdef ECCO_CTRL_DEPRECATED
#ifdef ALLOW_TRANSPORT_COST_CONTRIBUTION
do irec = 1, ndaysrec
wtransp(irec) = 0. _d 0
transpobs(irec) = 0. _d 0
enddo
if ( costTranspDataFile .NE. ' ' ) then
_BEGIN_MASTER(myThid)
ilo = ifnblnk(costTranspDataFile)
ihi = ilnblnk(costTranspDataFile)
CALL OPEN_COPY_DATA_FILE(
I costTranspDataFile(ilo:ihi),
I 'ECCO_COST_INIT_FIXED',
O gwunit,
I myThid )
do irec = 1, ndaysrec
c-- read daily transport time series
c-- 1st: transport in m/s
c-- 2nd: date in YYYYMMDD
c-- 3rd: uncertainty in m/s
read(gwunit,*) transpobs(irec), dummy, wtransp(irec)
c-- convert std.dev. to weight
if ( wtransp(irec) .NE. 0. )
& wtransp(irec) =1.0/(wtransp(irec)*wtransp(irec))
c-- set weight to zero for missing values
if ( transpobs(irec) .EQ. missingObsFlag )
& wtransp(irec) = 0. _d 0
enddo
_END_MASTER(myThid)
_BARRIER
endif
#endif /* ALLOW_TRANSPORT_COST_CONTRIBUTION */
#ifdef ALLOW_NEW_SSH_COST
c-- Read flags for picking SSH time averages
do irec = 1, ndaysrec
tpTimeMask(irec) = 1. _d 0
ersTimeMask(irec) = 1. _d 0
gfoTimeMask(irec) = 1. _d 0
enddo
c
_BEGIN_MASTER(myThid)
c
#ifdef ALLOW_SSH_TPANOM_COST_CONTRIBUTION
if ( tpTimeMaskFile .NE. ' ' ) then
ilo = ifnblnk(tpTimeMaskFile)
ihi = ilnblnk(tpTimeMaskFile)
CALL OPEN_COPY_DATA_FILE(
I tpTimeMaskFile(ilo:ihi),
I 'cost_ssh tp',
O gwunit,
I myThid )
do irec = 1, ndaysrec
read(gwunit,*) tpTimeMask(irec)
enddo
endif
#endif
c
#ifdef ALLOW_SSH_ERSANOM_COST_CONTRIBUTION
if ( ersTimeMaskFile .NE. ' ' ) then
ilo = ifnblnk(ersTimeMaskFile)
ihi = ilnblnk(ersTimeMaskFile)
CALL OPEN_COPY_DATA_FILE(
I ersTimeMaskFile(ilo:ihi),
I 'cost_ssh ers',
O gwunit,
I myThid )
do irec = 1, ndaysrec
read(gwunit,*) ersTimeMask(irec)
enddo
endif
#endif
c
#ifdef ALLOW_SSH_GFOANOM_COST_CONTRIBUTION
if ( gfoTimeMaskFile .NE. ' ' ) then
ilo = ifnblnk(gfoTimeMaskFile)
ihi = ilnblnk(gfoTimeMaskFile)
CALL OPEN_COPY_DATA_FILE(
I gfoTimeMaskFile(ilo:ihi),
I 'cost_ssh gfo',
O gwunit,
I myThid )
do irec = 1, ndaysrec
read(gwunit,*) gfoTimeMask(irec)
enddo
endif
#endif
c
do irec = 1, ndaysrec
if (
& ( tpTimeMask(irec).NE.0. .AND. tpTimeMask(irec).NE.1. ) .OR.
& ( ersTimeMask(irec).NE.0. .AND. ersTimeMask(irec).NE.1. ) .OR.
& ( ersTimeMask(irec).NE.0. .AND. ersTimeMask(irec).NE.1. ) )
& then
WRITE(msgBuf,'(2A,I10)')
& 'ecco_cost_init_fixed: (SSH)TimeMask not 0. or 1. ',
& 'for irec (=day) ', irec
CALL PRINT_MESSAGE( msgBuf, errorMessageUnit,
& SQUEEZE_RIGHT , myThid )
CALL PRINT_ERROR( msgBuf , myThid )
STOP 'ABNORMAL END: S/R ECCO_COST_INIT_FIXED'
endif
enddo
c
_END_MASTER(myThid)
_BARRIER
#endif /* ALLOW_NEW_SSH_COST */
#endif /* ECCO_CTRL_DEPRECATED */
c-- Summarize the cost function setup.
_BEGIN_MASTER( mythid )
call ecco_summary( mythid )
call ecco_cost_summary( mythid )
_END_MASTER( mythid )
_BARRIER
end