1 |
heimbach |
1.2 |
|
2 |
gforget |
1.11 |
#include "CTRL_OPTIONS.h" |
3 |
|
|
|
4 |
heimbach |
1.2 |
cph #ifdef TARGET_CRAY_VECTOR |
5 |
|
|
cph # define NML_OPTIM ECCO_OPTIM |
6 |
|
|
cph # define NML_ECCO ECCO_PARMS |
7 |
|
|
cph #else |
8 |
|
|
cph # define NML_OPTIM NML=ECCO_OPTIM |
9 |
|
|
cph # define NML_ECCO NML=ECCO_PARMS |
10 |
|
|
cph #endif |
11 |
|
|
|
12 |
|
|
c ================================================================== |
13 |
|
|
c |
14 |
|
|
c optim.F: Routines for doing an off-line optimization after the |
15 |
|
|
c ECCO forward and adjoint model have been run. |
16 |
|
|
c |
17 |
|
|
c numbmod - Returns number of variables. |
18 |
|
|
c simul - Mid-level routine that calls the model and its |
19 |
|
|
c adjoint |
20 |
|
|
c model - Forward model. |
21 |
|
|
c admodel - Modified forward model and adjoint model. |
22 |
|
|
c initmod - Initialisation routine. |
23 |
|
|
c postmod - Final routine that prints results. |
24 |
|
|
c |
25 |
|
|
c |
26 |
|
|
c Documentation: |
27 |
|
|
c |
28 |
|
|
c The collection of these routines originated mainly from Ralf |
29 |
|
|
c Giering. Patrick Heimbach improved and corrected some parts of |
30 |
|
|
c the original code. Christian Eckert contributed the interface |
31 |
|
|
c to the ECCO release of the MITgcmUV in order to get the off- |
32 |
|
|
c line version going. The on-line optimisation uses a simple |
33 |
|
|
c example, whereas the off-line version deals with the ECCO |
34 |
heimbach |
1.3 |
c release output. The off-line version can, of course, only |
35 |
heimbach |
1.2 |
c do one optimization step at a time. |
36 |
|
|
c |
37 |
|
|
c started: Christian Eckert eckert@mit.edu 15-Feb-2000 |
38 |
|
|
c |
39 |
|
|
c - On-line and off-line capability and some cosmetic |
40 |
|
|
c changes. |
41 |
|
|
c |
42 |
|
|
c changed: Patrick Heimbach heimbach@mit.edu 19-Jun-2000 |
43 |
|
|
c - finished, revised and debugged |
44 |
|
|
c |
45 |
|
|
c ================================================================== |
46 |
|
|
|
47 |
|
|
|
48 |
|
|
subroutine optim_numbmod( |
49 |
|
|
O nn |
50 |
|
|
& ) |
51 |
|
|
|
52 |
|
|
c ================================================================== |
53 |
|
|
c SUBROUTINE optim_numbmod |
54 |
|
|
c ================================================================== |
55 |
|
|
c |
56 |
|
|
c o Set the number of control variables. |
57 |
|
|
c |
58 |
|
|
c started: Christian Eckert eckert@mit.edu 15-Feb-2000 |
59 |
|
|
c |
60 |
|
|
c changed: Christian Eckert eckert@mit.edu 09-Mar-2000 |
61 |
|
|
c |
62 |
|
|
c - Added ECCO layout. |
63 |
|
|
c |
64 |
|
|
c changed: Patrick Heimbach heimbach@mit.edu 19-Jun-2000 |
65 |
|
|
c - finished, revised and debugged |
66 |
|
|
c |
67 |
|
|
c ================================================================== |
68 |
|
|
c SUBROUTINE optim_numbmod |
69 |
|
|
c ================================================================== |
70 |
|
|
|
71 |
|
|
IMPLICIT NONE |
72 |
|
|
|
73 |
|
|
c == global variables == |
74 |
|
|
|
75 |
|
|
#include "EEPARAMS.h" |
76 |
|
|
#include "SIZE.h" |
77 |
|
|
|
78 |
dfer |
1.8 |
cdfer#include "ecco.h" |
79 |
heimbach |
1.2 |
#include "ctrl.h" |
80 |
|
|
#include "optim.h" |
81 |
|
|
#include "minimization.h" |
82 |
heimbach |
1.10 |
#ifndef ECCO_CTRL_DEPRECATED |
83 |
|
|
# include "ctrl_local_params.h" |
84 |
|
|
# include "CTRL_OBCS.h" |
85 |
|
|
#endif |
86 |
heimbach |
1.2 |
|
87 |
|
|
c == routine arguments == |
88 |
|
|
|
89 |
|
|
integer nn |
90 |
|
|
|
91 |
|
|
c == local variables == |
92 |
|
|
|
93 |
|
|
integer il |
94 |
|
|
integer errio |
95 |
|
|
|
96 |
|
|
_RL ff |
97 |
|
|
|
98 |
|
|
#if defined (DYNAMIC) |
99 |
|
|
_RL vv(nn) |
100 |
|
|
#elif defined (USE_POINTER) || (MAX_INDEPEND == 0) |
101 |
|
|
_RL vv |
102 |
|
|
pointer (pvv,vv(1)) |
103 |
|
|
#else |
104 |
|
|
integer nmax |
105 |
|
|
parameter( nmax = MAX_INDEPEND ) |
106 |
|
|
_RL vv(nmax) |
107 |
|
|
#endif |
108 |
|
|
|
109 |
|
|
character*(max_len_prec) record |
110 |
|
|
|
111 |
|
|
logical lheaderonly |
112 |
|
|
|
113 |
|
|
c == external == |
114 |
|
|
|
115 |
|
|
integer ilnblnk |
116 |
|
|
|
117 |
|
|
c == end of interface == |
118 |
|
|
|
119 |
|
|
namelist /CTRL_NML/ |
120 |
heimbach |
1.7 |
& xx_theta_file, xx_salt_file, |
121 |
|
|
& xx_hflux_file, xx_hflux_remo_intercept, xx_hflux_remo_slope, |
122 |
heimbach |
1.2 |
& xx_hfluxstartdate1, xx_hfluxstartdate2, xx_hfluxperiod, |
123 |
heimbach |
1.7 |
& xx_sflux_file, xx_sflux_remo_intercept, xx_sflux_remo_slope, |
124 |
heimbach |
1.2 |
& xx_sfluxstartdate1, xx_sfluxstartdate2, xx_sfluxperiod, |
125 |
heimbach |
1.7 |
& xx_tauu_file, xx_tauu_remo_intercept, xx_tauu_remo_slope, |
126 |
heimbach |
1.2 |
& xx_tauustartdate1, xx_tauustartdate2, xx_tauuperiod, |
127 |
heimbach |
1.7 |
& xx_tauv_file, xx_tauv_remo_intercept, xx_tauv_remo_slope, |
128 |
mlosch |
1.4 |
& xx_tauvstartdate1, xx_tauvstartdate2, xx_tauvperiod, |
129 |
heimbach |
1.7 |
& xx_atemp_file, xx_atemp_remo_intercept, xx_atemp_remo_slope, |
130 |
mlosch |
1.4 |
& xx_atempstartdate1, xx_atempstartdate2, xx_atempperiod, |
131 |
heimbach |
1.7 |
& xx_aqh_file, xx_aqh_remo_intercept, xx_aqh_remo_slope, |
132 |
mlosch |
1.4 |
& xx_aqhstartdate1, xx_aqhstartdate2, xx_aqhperiod, |
133 |
heimbach |
1.7 |
& xx_precip_file, xx_precip_remo_intercept, xx_precip_remo_slope, |
134 |
heimbach |
1.6 |
& xx_precipstartdate1, xx_precipstartdate2, xx_precipperiod, |
135 |
heimbach |
1.7 |
& xx_swflux_file, xx_swflux_remo_intercept, xx_swflux_remo_slope, |
136 |
heimbach |
1.6 |
& xx_swfluxstartdate1, xx_swfluxstartdate2, xx_swfluxperiod, |
137 |
heimbach |
1.7 |
& xx_swdown_file, xx_swdown_remo_intercept, xx_swdown_remo_slope, |
138 |
heimbach |
1.6 |
& xx_swdownstartdate1, xx_swdownstartdate2, xx_swdownperiod, |
139 |
heimbach |
1.7 |
& xx_lwflux_file, xx_lwflux_remo_intercept, xx_lwflux_remo_slope, |
140 |
|
|
& xx_lwfluxstartdate1, xx_lwfluxstartdate2, xx_lwfluxperiod, |
141 |
|
|
& xx_lwdown_file, xx_lwdown_remo_intercept, xx_lwdown_remo_slope, |
142 |
|
|
& xx_lwdownstartdate1, xx_lwdownstartdate2, xx_lwdownperiod, |
143 |
|
|
& xx_evap_file, xx_evap_remo_intercept, xx_evap_remo_slope, |
144 |
|
|
& xx_evapstartdate1, xx_evapstartdate2, xx_evapperiod, |
145 |
|
|
& xx_snowprecip_file, xx_snowprecip_remo_intercept, |
146 |
|
|
& xx_snowprecip_remo_slope, xx_snowprecipperiod, |
147 |
|
|
& xx_snowprecipstartdate1, xx_snowprecipstartdate2, |
148 |
|
|
& xx_apressure_file, xx_apressure_remo_intercept, |
149 |
|
|
& xx_apressure_remo_slope, xx_apressureperiod, |
150 |
|
|
& xx_apressurestartdate1, xx_apressurestartdate2, |
151 |
|
|
& xx_runoff_file, xx_runoff_remo_intercept, xx_runoff_remo_slope, |
152 |
|
|
& xx_runoffstartdate1, xx_runoffstartdate2, xx_runoffperiod, |
153 |
|
|
& xx_uwind_file, xx_uwind_remo_intercept, xx_uwind_remo_slope, |
154 |
mlosch |
1.4 |
& xx_uwindstartdate1, xx_uwindstartdate2, xx_uwindperiod, |
155 |
heimbach |
1.7 |
& xx_vwind_file, xx_vwind_remo_intercept, xx_vwind_remo_slope, |
156 |
mlosch |
1.4 |
& xx_vwindstartdate1, xx_vwindstartdate2, xx_vwindperiod, |
157 |
heimbach |
1.7 |
& xx_obcsn_file, xx_obcss_file, xx_obcsw_file, xx_obcse_file, |
158 |
mlosch |
1.4 |
& xx_obcsnstartdate1, xx_obcsnstartdate2, xx_obcsnperiod, |
159 |
|
|
& xx_obcssstartdate1, xx_obcssstartdate2, xx_obcssperiod, |
160 |
|
|
& xx_obcswstartdate1, xx_obcswstartdate2, xx_obcswperiod, |
161 |
|
|
& xx_obcsestartdate1, xx_obcsestartdate2, xx_obcseperiod, |
162 |
heimbach |
1.7 |
& xx_diffkr_file, xx_kapgm_file, xx_tr1_file, |
163 |
|
|
& xx_sst_file, xx_sss_file, |
164 |
dfer |
1.8 |
& xx_sststartdate1, xx_sststartdate2, xx_sstperiod, |
165 |
|
|
& xx_sssstartdate1, xx_sssstartdate2, xx_sssperiod, |
166 |
heimbach |
1.7 |
& xx_depth_file, xx_efluxy_file, xx_efluxp_file, |
167 |
|
|
& xx_bottomdrag_file, xx_edtaux_file, xx_edtauy_file, |
168 |
|
|
& xx_uvel_file, xx_vvel_file, xx_etan_file, |
169 |
mlosch |
1.9 |
& xx_shifwflx_file, |
170 |
|
|
& xx_shifwflx_remo_intercept, xx_shifwflx_remo_slope, |
171 |
|
|
& xx_shifwflxstartdate1, xx_shifwflxstartdate2, xx_shifwflxperiod, |
172 |
heimbach |
1.7 |
& doInitXX, doPackDiag, doZscaleUnpack, doZscalePack, |
173 |
|
|
& doMainUnpack, doMainPack, doAdmtlmBypassAD, delZexp |
174 |
dfer |
1.8 |
cdfer |
175 |
|
|
& ,xx_hfluxm_file |
176 |
|
|
cdfer |
177 |
heimbach |
1.2 |
|
178 |
|
|
namelist /CTRL_PACKNAMES/ |
179 |
heimbach |
1.5 |
& yadmark, yctrlid, yctrlposunpack, yctrlpospack, |
180 |
heimbach |
1.2 |
& ctrlname, costname, scalname, maskname, metaname |
181 |
|
|
|
182 |
heimbach |
1.5 |
namelist /OPTIM/ |
183 |
heimbach |
1.2 |
& optimcycle, |
184 |
|
|
& numiter, nfunc, fmin, iprint, |
185 |
|
|
& epsf, epsx, epsg, |
186 |
|
|
& nupdate, eps |
187 |
|
|
|
188 |
|
|
c-- Preset the optimization parameters. |
189 |
|
|
optimcycle = 0 |
190 |
|
|
nvars = 0 |
191 |
|
|
numiter = 1 |
192 |
|
|
nfunc = 1 |
193 |
|
|
fmin = 0.0 |
194 |
|
|
iprint = 10 |
195 |
|
|
epsx = 1.e-6 |
196 |
|
|
epsg = 1.e-6 |
197 |
|
|
eps = -1.e-6 |
198 |
|
|
nupdate = 1 |
199 |
|
|
ff = 0. |
200 |
dfer |
1.8 |
cdfer expId = 'MIT_CE_000' |
201 |
|
|
yctrlid = 'MIT_CE_000' |
202 |
heimbach |
1.2 |
|
203 |
|
|
modeldataunit = 14 |
204 |
|
|
scrunit1 = 11 |
205 |
|
|
|
206 |
|
|
c-- Read control parameters from file. |
207 |
|
|
open(unit=scrunit1,status='scratch') |
208 |
|
|
|
209 |
|
|
open(unit = modeldataunit,file = 'data.ctrl', |
210 |
|
|
& status = 'old', iostat = errio) |
211 |
|
|
if ( errio .lt. 0 ) then |
212 |
|
|
stop ' stopped in optim_numbmod' |
213 |
|
|
endif |
214 |
|
|
|
215 |
|
|
do while ( .true. ) |
216 |
|
|
read(modeldataunit, fmt='(a)', end=21) record |
217 |
|
|
il = max(ilnblnk(record),1) |
218 |
|
|
if ( record(1:1) .ne. commentcharacter ) |
219 |
|
|
& write(unit=scrunit1, fmt='(a)') record(:il) |
220 |
|
|
enddo |
221 |
|
|
21 continue |
222 |
|
|
close( modeldataunit ) |
223 |
|
|
|
224 |
|
|
rewind( scrunit1 ) |
225 |
|
|
read(unit = scrunit1, nml = ctrl_nml) |
226 |
|
|
read(unit = scrunit1, nml = ctrl_packnames) |
227 |
|
|
close( scrunit1 ) |
228 |
|
|
print*, ' OPTIM_NUMBMOD: Control options have been read.' |
229 |
|
|
|
230 |
heimbach |
1.5 |
cph( |
231 |
dfer |
1.8 |
cdfer expId = yctrlid |
232 |
heimbach |
1.5 |
cph) |
233 |
|
|
|
234 |
heimbach |
1.2 |
c-- Read optimization parameters from file. |
235 |
|
|
open(unit=scrunit1,status='scratch') |
236 |
|
|
|
237 |
|
|
open(unit = modeldataunit,file = 'data.optim', |
238 |
|
|
& status = 'old', iostat = errio) |
239 |
|
|
if ( errio .lt. 0 ) then |
240 |
|
|
stop ' stopped in optim_numbmod' |
241 |
|
|
endif |
242 |
|
|
|
243 |
|
|
do while ( .true. ) |
244 |
|
|
read(modeldataunit, fmt='(a)', end=22) record |
245 |
|
|
il = max(ilnblnk(record),1) |
246 |
|
|
if ( record(1:1) .ne. commentcharacter ) |
247 |
|
|
& write(unit=scrunit1, fmt='(a)') record(:il) |
248 |
|
|
enddo |
249 |
|
|
22 continue |
250 |
|
|
close( modeldataunit ) |
251 |
|
|
|
252 |
|
|
rewind( scrunit1 ) |
253 |
heimbach |
1.5 |
read(unit = scrunit1, nml = optim) |
254 |
heimbach |
1.2 |
close( scrunit1 ) |
255 |
|
|
print*, ' OPTIM_NUMBMOD: Minimization options have been read.' |
256 |
|
|
|
257 |
|
|
if (eps .gt. 0.0) then |
258 |
|
|
epsf = eps |
259 |
|
|
epsx = eps |
260 |
|
|
epsg = eps |
261 |
|
|
endif |
262 |
|
|
|
263 |
|
|
lheaderonly = .true. |
264 |
|
|
call optim_readdata ( nn, ctrlname, lheaderonly, ff, vv) |
265 |
|
|
|
266 |
|
|
c-- Do some final printout. |
267 |
|
|
print* |
268 |
|
|
print*, ' OPTIM_NUMBMOD: Iteration number = ', optimcycle |
269 |
|
|
print*, ' number of control variables = ', nn |
270 |
|
|
print*, ' Data will be read from the following files:' |
271 |
|
|
print* |
272 |
|
|
|
273 |
|
|
ce --> data.err file in case dimensional i/o is used. |
274 |
|
|
ce --> scaling file in case dimensional i/o is used. |
275 |
|
|
|
276 |
|
|
return |
277 |
|
|
end |