1 |
|
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 |
c release output. The off-line version can, of course, only |
33 |
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 |
external ilnblnk |
111 |
|
112 |
c == end of interface == |
113 |
|
114 |
namelist /CTRL_NML/ |
115 |
& xx_theta_file, |
116 |
& xx_salt_file, |
117 |
& xx_hflux_file, |
118 |
& xx_hfluxstartdate1, xx_hfluxstartdate2, xx_hfluxperiod, |
119 |
& xx_sflux_file, |
120 |
& xx_sfluxstartdate1, xx_sfluxstartdate2, xx_sfluxperiod, |
121 |
& xx_tauu_file, |
122 |
& xx_tauustartdate1, xx_tauustartdate2, xx_tauuperiod, |
123 |
& xx_tauv_file, |
124 |
& xx_tauvstartdate1, xx_tauvstartdate2, xx_tauvperiod, |
125 |
& xx_atemp_file, |
126 |
& xx_atempstartdate1, xx_atempstartdate2, xx_atempperiod, |
127 |
& xx_aqh_file, |
128 |
& xx_aqhstartdate1, xx_aqhstartdate2, xx_aqhperiod, |
129 |
& xx_uwind_file, |
130 |
& xx_uwindstartdate1, xx_uwindstartdate2, xx_uwindperiod, |
131 |
& xx_vwind_file, |
132 |
& xx_vwindstartdate1, xx_vwindstartdate2, xx_vwindperiod, |
133 |
& xx_obcsn_file, |
134 |
& xx_obcsnstartdate1, xx_obcsnstartdate2, xx_obcsnperiod, |
135 |
& xx_obcss_file, |
136 |
& xx_obcssstartdate1, xx_obcssstartdate2, xx_obcssperiod, |
137 |
& xx_obcsw_file, |
138 |
& xx_obcswstartdate1, xx_obcswstartdate2, xx_obcswperiod, |
139 |
& xx_obcse_file, |
140 |
& xx_obcsestartdate1, xx_obcsestartdate2, xx_obcseperiod, |
141 |
& xx_diffkr_file, |
142 |
& xx_kapgm_file, |
143 |
& xx_tr1_file, |
144 |
& xx_sst_file, |
145 |
& xx_sss_file, |
146 |
& xx_hfacc_file, |
147 |
& xx_efluxy_file, |
148 |
& xx_efluxp_file, |
149 |
& xx_bottomdrag_file, |
150 |
& doInitXX |
151 |
|
152 |
namelist /CTRL_PACKNAMES/ |
153 |
& yadmark, |
154 |
& ctrlname, costname, scalname, maskname, metaname |
155 |
|
156 |
namelist /ECCO_PARMS/ |
157 |
& expId |
158 |
|
159 |
namelist /ECCO_OPTIM/ |
160 |
& optimcycle, |
161 |
& numiter, nfunc, fmin, iprint, |
162 |
& epsf, epsx, epsg, |
163 |
& nupdate, eps |
164 |
|
165 |
c-- Preset the optimization parameters. |
166 |
optimcycle = 0 |
167 |
nvars = 0 |
168 |
numiter = 1 |
169 |
nfunc = 1 |
170 |
fmin = 0.0 |
171 |
iprint = 10 |
172 |
epsx = 1.e-6 |
173 |
epsg = 1.e-6 |
174 |
eps = -1.e-6 |
175 |
nupdate = 1 |
176 |
ff = 0. |
177 |
expId = 'MIT_CE_000' |
178 |
|
179 |
modeldataunit = 14 |
180 |
scrunit1 = 11 |
181 |
|
182 |
c-- Read ecco parameters from file. |
183 |
open(unit=scrunit1,status='scratch') |
184 |
|
185 |
open(unit = modeldataunit,file = 'data.ecco', |
186 |
& status = 'old', iostat = errio) |
187 |
if ( errio .lt. 0 ) then |
188 |
stop ' stopped in optim_numbmod' |
189 |
endif |
190 |
|
191 |
do while ( .true. ) |
192 |
read(modeldataunit, fmt='(a)', end=20) record |
193 |
il = max(ilnblnk(record),1) |
194 |
if ( record(1:1) .ne. commentcharacter ) |
195 |
& write(unit=scrunit1, fmt='(a)') record(:il) |
196 |
enddo |
197 |
20 continue |
198 |
close( modeldataunit ) |
199 |
|
200 |
rewind( scrunit1 ) |
201 |
read(unit = scrunit1, nml = ecco_parms) |
202 |
close( scrunit1 ) |
203 |
print*, ' OPTIM_NUMBMOD: ECCO options have been read.' |
204 |
|
205 |
c-- Read control parameters from file. |
206 |
open(unit=scrunit1,status='scratch') |
207 |
|
208 |
open(unit = modeldataunit,file = 'data.ctrl', |
209 |
& status = 'old', iostat = errio) |
210 |
if ( errio .lt. 0 ) then |
211 |
stop ' stopped in optim_numbmod' |
212 |
endif |
213 |
|
214 |
do while ( .true. ) |
215 |
read(modeldataunit, fmt='(a)', end=21) record |
216 |
il = max(ilnblnk(record),1) |
217 |
if ( record(1:1) .ne. commentcharacter ) |
218 |
& write(unit=scrunit1, fmt='(a)') record(:il) |
219 |
enddo |
220 |
21 continue |
221 |
close( modeldataunit ) |
222 |
|
223 |
rewind( scrunit1 ) |
224 |
read(unit = scrunit1, nml = ctrl_nml) |
225 |
read(unit = scrunit1, nml = ctrl_packnames) |
226 |
close( scrunit1 ) |
227 |
print*, ' OPTIM_NUMBMOD: Control options have been read.' |
228 |
|
229 |
c-- Read optimization parameters from file. |
230 |
open(unit=scrunit1,status='scratch') |
231 |
|
232 |
open(unit = modeldataunit,file = 'data.optim', |
233 |
& status = 'old', iostat = errio) |
234 |
if ( errio .lt. 0 ) then |
235 |
stop ' stopped in optim_numbmod' |
236 |
endif |
237 |
|
238 |
do while ( .true. ) |
239 |
read(modeldataunit, fmt='(a)', end=22) record |
240 |
il = max(ilnblnk(record),1) |
241 |
if ( record(1:1) .ne. commentcharacter ) |
242 |
& write(unit=scrunit1, fmt='(a)') record(:il) |
243 |
enddo |
244 |
22 continue |
245 |
close( modeldataunit ) |
246 |
|
247 |
rewind( scrunit1 ) |
248 |
read(unit = scrunit1, nml = ecco_optim) |
249 |
close( scrunit1 ) |
250 |
print*, ' OPTIM_NUMBMOD: Minimization options have been read.' |
251 |
|
252 |
if (eps .gt. 0.0) then |
253 |
epsf = eps |
254 |
epsx = eps |
255 |
epsg = eps |
256 |
endif |
257 |
|
258 |
lheaderonly = .true. |
259 |
call optim_readdata ( nn, ctrlname, lheaderonly, ff, vv) |
260 |
|
261 |
c-- Do some final printout. |
262 |
print* |
263 |
print*, ' OPTIM_NUMBMOD: Iteration number = ', optimcycle |
264 |
print*, ' number of control variables = ', nn |
265 |
print*, ' Data will be read from the following files:' |
266 |
print* |
267 |
|
268 |
ce --> data.err file in case dimensional i/o is used. |
269 |
ce --> scaling file in case dimensional i/o is used. |
270 |
|
271 |
return |
272 |
end |