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