48 |
|
|
49 |
_RL objf |
_RL objf |
50 |
|
|
51 |
#if defined (DYNAMIC) |
#ifdef DYNAMIC |
52 |
_RL xx(nn) |
_RL, dimension(:), allocatable :: xx, adxx |
|
_RL adxx(nn) |
|
|
#elif defined (USE_POINTER) || (MAX_INDEPEND == 0) |
|
|
_RL xx |
|
|
_RL adxx |
|
|
pointer (pxx,xx(1)) |
|
|
pointer (padxx,adxx(1)) |
|
53 |
#else |
#else |
54 |
integer nmax |
integer nmax |
55 |
parameter( nmax = MAX_INDEPEND ) |
parameter( nmax = MAX_INDEPEND ) |
57 |
_RL adxx(nmax) |
_RL adxx(nmax) |
58 |
#endif |
#endif |
59 |
|
|
60 |
|
CML logical coldStart |
61 |
c formal parameters of m1qn3 |
c formal parameters of m1qn3 |
62 |
integer reverse |
integer reverse |
63 |
integer impres,imode(3),omode,niter,nsim,iz(5),indic |
integer impres,imode(3),omode,niter,nsim,iz(5),indic |
64 |
_RL dxmin,df1 |
_RL dxmin,df1 |
65 |
character*3 normtype |
character*3 normtype |
66 |
c work arrays |
c work arrays |
67 |
integer ndz, mupdate |
integer ndz |
68 |
CML _RL dz(ndz) |
CML _RL dz(ndz) |
69 |
double precision, dimension(:), allocatable :: dz |
double precision, dimension(:), allocatable :: dz |
70 |
c extra dummy variables |
c extra dummy variables |
85 |
|
|
86 |
c-- Allocate memory for the control variables and the gradient vector. |
c-- Allocate memory for the control variables and the gradient vector. |
87 |
#if defined(DYNAMIC) |
#if defined(DYNAMIC) |
88 |
#elif defined(USE_POINTER) || (MAX_INDEPEND == 0) |
allocate( xx(nn) ) |
89 |
call myalloc( pxx , nn*REAL_BYTE ) |
allocate( adxx(nn) ) |
|
call myalloc( padxx, nn*REAL_BYTE ) |
|
90 |
#endif |
#endif |
91 |
|
|
92 |
#if defined (DYNAMIC) |
#ifndef DYNAMIC |
|
#elif defined(USE_POINTER) || (MAX_INDEPEND == 0) |
|
|
#else |
|
93 |
if (nn .gt. nmax) then |
if (nn .gt. nmax) then |
94 |
print*,' OPTIMUM: Not enough space.' |
print*,' OPTIMUM: Not enough space.' |
95 |
print*,' nmax = ',nmax |
print*,' nmax = ',nmax |
138 |
rzs(1)=UNSET_RS |
rzs(1)=UNSET_RS |
139 |
dzs(1)=UNSET_RL |
dzs(1)=UNSET_RL |
140 |
|
|
141 |
if ( optimcycle .eq. 0 ) then |
c-- first read the model output into xx, adxx, and cost function |
142 |
|
c value into objf |
143 |
|
do i = 1,nn |
144 |
|
xx(i) = 0. |
145 |
|
adxx(i) = 0. |
146 |
|
enddo |
147 |
|
c |
148 |
|
print *, ' OPTIM_SUB: read model state' |
149 |
|
call optim_readdata( nn, ctrlname, .false., objf, xx ) |
150 |
|
call optim_readdata( nn, costname, .false., objf, adxx ) |
151 |
|
print *, ' OPTIM_SUB after reading ', |
152 |
|
& ctrlname, ' and ', costname, ':' |
153 |
|
print *, ' OPTIM_SUB nn = ', nn |
154 |
|
print *, ' OPTIM_SUB objf = ', objf |
155 |
|
print *, ' OPTIM_SUB xx(1) = ', xx(1) |
156 |
|
print *, ' OPTIM_SUB adxx(1) = ', adxx(1) |
157 |
|
|
158 |
|
c compute expected decrease of cost function from objf and fmin; |
159 |
|
c this value is only used for a cold start of m1qn3_offline, for a |
160 |
|
c warm start df1 is overwritten with data from a restart file |
161 |
|
df1=objf-fmin |
162 |
|
if ( df1 .le. 0. ) then |
163 |
|
print *, ' OPTIM_SUB: df1 = objf-fmin = ', df1, ' should be > 0.' |
164 |
|
stop 'ABNORMAL in S/R OPTIM_SUB' |
165 |
|
endif |
166 |
|
|
167 |
|
c global variable coldStart is set in s/r optim_readparms |
168 |
|
c the default is false, always set it to true for the 0th cycle |
169 |
|
if ( optimcycle .eq. 0 ) coldStart=.true. |
170 |
|
if ( coldStart ) then |
171 |
c-- cold start |
c-- cold start |
172 |
print *, ' OPTIM_SUB: cold start, optimcycle =', optimcycle |
print *, ' OPTIM_SUB: cold start, optimcycle =', optimcycle |
173 |
imode(2) = 0 |
imode(2) = 0 |
175 |
c that needs to be initialized here to make sure that we have a |
c that needs to be initialized here to make sure that we have a |
176 |
c clean start |
c clean start |
177 |
reentry = 0 |
reentry = 0 |
|
c ff has be read in optim_readparms, so we do not read it here again |
|
|
objf = ff |
|
|
df1 = objf-fmin |
|
178 |
c open output file for m1qn3 |
c open output file for m1qn3 |
179 |
open(io,file=fname_m1qn3,status='unknown') |
open(io,file=fname_m1qn3,status='unknown') |
180 |
else |
else |
188 |
c re-open output file for m1qn3 |
c re-open output file for m1qn3 |
189 |
open(io,file=fname_m1qn3,status='old',position='append') |
open(io,file=fname_m1qn3,status='old',position='append') |
190 |
endif |
endif |
|
c-- read the model output into xx,adxx |
|
|
if ( indic .eq. 4 ) then |
|
|
do i = 1,nn |
|
|
xx(i) = 0. |
|
|
adxx(i) = 0. |
|
|
enddo |
|
|
c |
|
|
print *, ' OPTIM_SUB: read model state' |
|
|
call optim_readdata( nn, ctrlname, .false., objf, xx ) |
|
|
call optim_readdata( nn, costname, .false., objf, adxx ) |
|
|
print *, ' OPTIM_SUB after reading nn, objf = ', nn, objf, |
|
|
& xx(1), adxx(1) |
|
|
else |
|
|
print *, ' OPTIM_SUB: indic = ', indic, ' is not possible' |
|
|
stop 'ABNORMAL in S/R OPTIM_SUB' |
|
|
endif |
|
191 |
|
|
192 |
c-- call the minimizer, a slightly modified version of m1qn3 v3.3 |
c-- call the minimizer, a slightly modified version of m1qn3 v3.3 |
193 |
c (Gilbert & Lemarechal, 1989), downloaded in April 2012. |
c (Gilbert & Lemarechal, 1989), downloaded in April 2012. |
215 |
call optim_writedata( nn, ctrlname, .false., -9999., xx ) |
call optim_writedata( nn, ctrlname, .false., -9999., xx ) |
216 |
|
|
217 |
c clean up |
c clean up |
218 |
|
#ifdef DYNAMIC |
219 |
|
deallocate(xx, adxx) |
220 |
|
#endif /* DYNAMIC */ |
221 |
deallocate(dz) |
deallocate(dz) |
222 |
|
|
223 |
c stopping criterion |
c stopping criterion |