1 |
C $Header: /u/gcmpack/MITgcm/pkg/ecco/ecco_cost_init_fixed.F,v 1.27 2012/07/06 23:03:40 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "ECCO_OPTIONS.h" |
5 |
#include "AD_CONFIG.h" |
6 |
|
7 |
subroutine ecco_cost_init_fixed( mythid ) |
8 |
|
9 |
c ================================================================== |
10 |
c SUBROUTINE ecco_cost_init_fixed |
11 |
c ================================================================== |
12 |
c |
13 |
c o Set contributions to the cost function and the cost function |
14 |
c itself to zero. The cost function and the individual contribu- |
15 |
c tions are defined in the header file "ecco_cost.h". |
16 |
c |
17 |
c started: Christian Eckert eckert@mit.edu 30-Jun-1999 |
18 |
c |
19 |
c changed: Christian Eckert eckert@mit.edu 25-Feb-2000 |
20 |
c |
21 |
c - Restructured the code in order to create a package |
22 |
c for the MITgcmUV. |
23 |
c |
24 |
c changed: Ralf Giering 18-Jan-2001 |
25 |
c |
26 |
c - move namelist reading to cost_readparms.F |
27 |
c |
28 |
c ================================================================== |
29 |
c SUBROUTINE ecco_cost_init_fixed |
30 |
c ================================================================== |
31 |
|
32 |
implicit none |
33 |
|
34 |
c == global variables == |
35 |
|
36 |
#include "EEPARAMS.h" |
37 |
#include "SIZE.h" |
38 |
#include "GRID.h" |
39 |
#include "PARAMS.h" |
40 |
|
41 |
#ifdef ALLOW_CAL |
42 |
#include "cal.h" |
43 |
#endif |
44 |
#include "ecco_cost.h" |
45 |
|
46 |
c == routine arguments == |
47 |
|
48 |
integer mythid |
49 |
|
50 |
c == local variables == |
51 |
|
52 |
integer tempDate1(4) |
53 |
integer tempDate2(4) |
54 |
integer gwunit |
55 |
integer ilo,ihi |
56 |
integer irec,k |
57 |
logical exst |
58 |
_RL dummy |
59 |
_RL missingObsFlag |
60 |
PARAMETER ( missingObsFlag = 1. _d 23 ) |
61 |
character*(max_len_mbuf) msgbuf |
62 |
|
63 |
c == external functions == |
64 |
|
65 |
integer cal_IntYears |
66 |
external cal_IntYears |
67 |
integer cal_IntMonths |
68 |
external cal_IntMonths |
69 |
integer cal_IntDays |
70 |
external cal_IntDays |
71 |
integer ifnblnk |
72 |
external ifnblnk |
73 |
integer ilnblnk |
74 |
external ilnblnk |
75 |
|
76 |
c == end of interface == |
77 |
|
78 |
#ifdef ALLOW_CAL |
79 |
|
80 |
c-- The number of monthly and daily averages generated by the |
81 |
c-- current model integration. |
82 |
nyearsrec = cal_IntYears( mythid ) |
83 |
nmonsrec = cal_IntMonths( mythid ) |
84 |
ndaysrec = cal_IntDays( mythid ) |
85 |
|
86 |
_BEGIN_MASTER( myThid ) |
87 |
|
88 |
c-- Get the complete dates of the ... |
89 |
c-- ... TMI data. |
90 |
if ( tmidatfile .ne. ' ' ) |
91 |
& call cal_FullDate( tmistartdate1, tmistartdate2, |
92 |
& tmistartdate, mythid ) |
93 |
c-- ... SST data. |
94 |
if ( sstdatfile .ne. ' ' ) |
95 |
& call cal_FullDate( sststartdate1, sststartdate2, |
96 |
& sststartdate, mythid ) |
97 |
c-- ... SSS data. |
98 |
if ( sssdatfile .ne. ' ' ) |
99 |
& call cal_FullDate( sssstartdate1, sssstartdate2, |
100 |
& sssstartdate, mythid ) |
101 |
c-- ... BP data. |
102 |
if ( bpdatfile .ne. ' ' ) |
103 |
& call cal_FullDate( bpstartdate1, bpstartdate2, |
104 |
& bpstartdate, mythid ) |
105 |
c-- ... IES data. |
106 |
if ( iesdatfile .ne. ' ' ) |
107 |
& call cal_FullDate( iesstartdate1, iesstartdate2, |
108 |
& iesstartdate, mythid ) |
109 |
c-- ... T/P data. |
110 |
if ( topexfile .ne. ' ' ) |
111 |
& call cal_FullDate( topexstartdate1, topexstartdate2, |
112 |
& topexstartdate, mythid ) |
113 |
c-- ... ERS data. |
114 |
if ( ersfile .ne. ' ' ) |
115 |
& call cal_FullDate( ersstartdate1, ersstartdate2, |
116 |
& ersstartdate, mythid ) |
117 |
c-- ... GFO data. |
118 |
if ( gfofile .ne. ' ' ) |
119 |
& call cal_FullDate( gfostartdate1, gfostartdate2, |
120 |
& gfostartdate, mythid ) |
121 |
c-- ... SCAT data. |
122 |
if ( scatxdatfile .ne. ' ' ) |
123 |
& call cal_FullDate( scatstartdate1, scatstartdate2, |
124 |
& scatxstartdate, mythid ) |
125 |
if ( scatydatfile .ne. ' ' ) |
126 |
& call cal_FullDate( scatstartdate1, scatstartdate2, |
127 |
& scatystartdate, mythid ) |
128 |
c-- ... ARGO data. |
129 |
if ( argotfile .ne. ' ' ) |
130 |
& call cal_FullDate( argotstartdate1, argotstartdate2, |
131 |
& argotstartdate, mythid ) |
132 |
if ( argosfile .ne. ' ' ) |
133 |
& call cal_FullDate( argosstartdate1, argotstartdate2, |
134 |
& argosstartdate, mythid ) |
135 |
|
136 |
#ifdef ALLOW_GENCOST_CONTRIBUTION |
137 |
do k = 1, NGENCOST |
138 |
#ifndef ALLOW_GENCOST_FREEFORM |
139 |
if ( gencost_datafile(k) .ne. ' ' ) then |
140 |
#endif |
141 |
if ( gencost_avgperiod(k) .EQ. 'day' .OR. |
142 |
& gencost_avgperiod(k) .EQ. 'DAY' ) then |
143 |
gencost_nrec(k) = ndaysrec |
144 |
gencost_period(k) = 86400. |
145 |
else if ( gencost_avgperiod(k) .EQ. 'month' .OR. |
146 |
& gencost_avgperiod(k) .EQ. 'MONTH' ) then |
147 |
gencost_nrec(k) =nmonsrec |
148 |
gencost_period(k) = 0. |
149 |
else if ( gencost_avgperiod(k) .EQ. 'year' .OR. |
150 |
& gencost_avgperiod(k) .EQ. 'YEAR' ) then |
151 |
STOP |
152 |
& 'ecco_cost_init_fixed: yearly data not yet implemented' |
153 |
#ifndef ALLOW_GENCOST_FREEFORM |
154 |
else |
155 |
STOP |
156 |
& 'ecco_cost_init_fixed: gencost_avgperiod wrongly specified' |
157 |
#endif |
158 |
endif |
159 |
#ifndef ALLOW_GENCOST_FREEFORM |
160 |
endif |
161 |
#endif |
162 |
enddo |
163 |
#endif /* ALLOW_GENCOST_CONTRIBUTION */ |
164 |
|
165 |
_END_MASTER( mythid ) |
166 |
|
167 |
#endif /* ALLOW_CAL */ |
168 |
|
169 |
call ecco_check( myThid ) |
170 |
|
171 |
c-- Get the weights that are to be used for the individual cost |
172 |
c-- function contributions. |
173 |
call ecco_cost_weights( mythid ) |
174 |
|
175 |
c-- Initialise adjoint of monthly mean files calculated |
176 |
c-- in cost_averagesfields (and their ad...). |
177 |
cph( |
178 |
cph The following init. shoud not be applied if in the middle |
179 |
cph of a divided adjoint run |
180 |
cph) |
181 |
#ifndef ALLOW_TANGENTLINEAR_RUN |
182 |
cph!!! and I think it needs to be seen by TAF |
183 |
cph!!! for repeated TLM runs |
184 |
cph!!! |
185 |
inquire( file='costfinal', exist=exst ) |
186 |
if ( .NOT. exst) then |
187 |
call ecco_cost_init_barfiles( mythid ) |
188 |
endif |
189 |
#endif |
190 |
|
191 |
#ifdef ALLOW_TRANSPORT_COST_CONTRIBUTION |
192 |
do irec = 1, ndaysrec |
193 |
wtransp(irec) = 0. _d 0 |
194 |
transpobs(irec) = 0. _d 0 |
195 |
enddo |
196 |
|
197 |
if ( costTranspDataFile .NE. ' ' ) then |
198 |
_BEGIN_MASTER(myThid) |
199 |
ilo = ifnblnk(costTranspDataFile) |
200 |
ihi = ilnblnk(costTranspDataFile) |
201 |
CALL OPEN_COPY_DATA_FILE( |
202 |
I costTranspDataFile(ilo:ihi), |
203 |
I 'ECCO_COST_INIT_FIXED', |
204 |
O gwunit, |
205 |
I myThid ) |
206 |
do irec = 1, ndaysrec |
207 |
c-- read daily transport time series |
208 |
c-- 1st: transport in m/s |
209 |
c-- 2nd: date in YYYYMMDD |
210 |
c-- 3rd: uncertainty in m/s |
211 |
read(gwunit,*) transpobs(irec), dummy, wtransp(irec) |
212 |
c-- convert std.dev. to weight |
213 |
if ( wtransp(irec) .NE. 0. ) |
214 |
& wtransp(irec) =1.0/(wtransp(irec)*wtransp(irec)) |
215 |
c-- set weight to zero for missing values |
216 |
if ( transpobs(irec) .EQ. missingObsFlag ) |
217 |
& wtransp(irec) = 0. _d 0 |
218 |
enddo |
219 |
_END_MASTER(myThid) |
220 |
_BARRIER |
221 |
endif |
222 |
#endif /* ALLOW_TRANSPORT_COST_CONTRIBUTION */ |
223 |
|
224 |
#ifdef ALLOW_SSH_COST_CONTRIBUTION |
225 |
|
226 |
c-- Read flags for picking SSH time averages |
227 |
do irec = 1, ndaysrec |
228 |
tpTimeMask(irec) = 1. _d 0 |
229 |
ersTimeMask(irec) = 1. _d 0 |
230 |
gfoTimeMask(irec) = 1. _d 0 |
231 |
enddo |
232 |
c |
233 |
_BEGIN_MASTER(myThid) |
234 |
c |
235 |
#ifdef ALLOW_SSH_TPANOM_COST_CONTRIBUTION |
236 |
if ( tpTimeMaskFile .NE. ' ' ) then |
237 |
ilo = ifnblnk(tpTimeMaskFile) |
238 |
ihi = ilnblnk(tpTimeMaskFile) |
239 |
CALL OPEN_COPY_DATA_FILE( |
240 |
I tpTimeMaskFile(ilo:ihi), |
241 |
I 'cost_ssh tp', |
242 |
O gwunit, |
243 |
I myThid ) |
244 |
do irec = 1, ndaysrec |
245 |
read(gwunit,*) tpTimeMask(irec) |
246 |
enddo |
247 |
endif |
248 |
#endif |
249 |
c |
250 |
#ifdef ALLOW_SSH_ERSANOM_COST_CONTRIBUTION |
251 |
if ( ersTimeMaskFile .NE. ' ' ) then |
252 |
ilo = ifnblnk(ersTimeMaskFile) |
253 |
ihi = ilnblnk(ersTimeMaskFile) |
254 |
CALL OPEN_COPY_DATA_FILE( |
255 |
I ersTimeMaskFile(ilo:ihi), |
256 |
I 'cost_ssh ers', |
257 |
O gwunit, |
258 |
I myThid ) |
259 |
do irec = 1, ndaysrec |
260 |
read(gwunit,*) ersTimeMask(irec) |
261 |
enddo |
262 |
endif |
263 |
#endif |
264 |
c |
265 |
#ifdef ALLOW_SSH_GFOANOM_COST_CONTRIBUTION |
266 |
if ( gfoTimeMaskFile .NE. ' ' ) then |
267 |
ilo = ifnblnk(gfoTimeMaskFile) |
268 |
ihi = ilnblnk(gfoTimeMaskFile) |
269 |
CALL OPEN_COPY_DATA_FILE( |
270 |
I gfoTimeMaskFile(ilo:ihi), |
271 |
I 'cost_ssh gfo', |
272 |
O gwunit, |
273 |
I myThid ) |
274 |
do irec = 1, ndaysrec |
275 |
read(gwunit,*) gfoTimeMask(irec) |
276 |
enddo |
277 |
endif |
278 |
#endif |
279 |
c |
280 |
do irec = 1, ndaysrec |
281 |
if ( |
282 |
& ( tpTimeMask(irec).NE.0. .AND. tpTimeMask(irec).NE.1. ) .OR. |
283 |
& ( ersTimeMask(irec).NE.0. .AND. ersTimeMask(irec).NE.1. ) .OR. |
284 |
& ( ersTimeMask(irec).NE.0. .AND. ersTimeMask(irec).NE.1. ) ) |
285 |
& then |
286 |
WRITE(msgBuf,'(2A,I10)') |
287 |
& 'ecco_cost_init_fixed: (SSH)TimeMask not 0. or 1. ', |
288 |
& 'for irec (=day) ', irec |
289 |
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, |
290 |
& SQUEEZE_RIGHT , myThid ) |
291 |
CALL PRINT_ERROR( msgBuf , myThid ) |
292 |
STOP 'ABNORMAL END: S/R ECCO_COST_INIT_FIXED' |
293 |
endif |
294 |
enddo |
295 |
c |
296 |
_END_MASTER(myThid) |
297 |
_BARRIER |
298 |
#endif |
299 |
|
300 |
c-- Summarize the cost function setup. |
301 |
_BEGIN_MASTER( mythid ) |
302 |
call ecco_cost_summary( mythid ) |
303 |
_END_MASTER( mythid ) |
304 |
|
305 |
_BARRIER |
306 |
|
307 |
end |