/[MITgcm]/MITgcm_contrib/mlosch/optim_m1qn3/optim_readparms.F
ViewVC logotype

Annotation of /MITgcm_contrib/mlosch/optim_m1qn3/optim_readparms.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download)
Thu Apr 26 11:10:06 2012 UTC (11 years, 11 months ago) by mlosch
Branch: MAIN
First working version of a new optimization package that uses a slightly
modified version of m1qn3, v3.3
(https://who.rocq.inria.fr/Jean-Charles.Gilbert/modulopt/optimization-routines/m1qn3/m1qn3.html)
to work as an offline optimizer. The advantage of m1qn3_offline is, that
it is run in reverse communication control mode, so that it gives back
control to the call routine (here a script) to provide a new estimate of the
cost function and the gradient based on the control vector. This way we can
do complete line searches that are meaningful.

1 mlosch 1.1 C $Header: $
2     C $Name: $
3    
4     c Include ECCO_CPPOPTIONS because the ecco_ctrl,cost files
5     c have headers with options for OBCS masks.
6     #include "ECCO_CPPOPTIONS.h"
7    
8     subroutine optim_readparms(
9     O nn, ff
10     & )
11    
12     c ==================================================================
13     c subroutine optim_readparms
14     c ==================================================================
15     c
16     c o Read namelist files and
17     c o read the number of control variables and return it as nn
18     c o read the cost function value from ctrlname and return as ff,
19     c note that this value is only meaning full in the first iteration
20     c
21     c ==================================================================
22    
23     implicit none
24    
25     c == global variables ==
26    
27     #include "EEPARAMS.h"
28     #include "SIZE.h"
29     #include "ctrl.h"
30     #include "optim.h"
31    
32     c == routine arguments ==
33    
34     integer nn
35    
36     c == local variables ==
37    
38     integer il
39     integer errio
40    
41     _RL ff
42     _RL dfminFrac
43    
44     #if defined (DYNAMIC)
45     _RL vv(nn)
46     #elif defined (USE_POINTER) || (MAX_INDEPEND == 0)
47     _RL vv
48     pointer (pvv,vv(1))
49     #else
50     integer nmax
51     parameter( nmax = MAX_INDEPEND )
52     _RL vv(nmax)
53     #endif
54    
55     character*(max_len_prec) record
56    
57     c == external ==
58    
59     integer ilnblnk
60    
61     c == end of interface ==
62    
63     namelist /CTRL_PACKNAMES/
64     & yadmark, ctrlname, costname, scalname, maskname, metaname,
65     & yctrlid, yctrlposunpack, yctrlpospack
66    
67     namelist /OPTIM/
68     & optimcycle,
69     & numiter, nfunc, fmin, dfminFrac, iprint,
70     & epsf, epsx, epsg,
71     & nupdate, eps
72    
73     c-- Preset the optimization parameters.
74     optimcycle = 0
75     nvars = 0
76     numiter = 1
77     nfunc = 1
78     fmin = UNSET_RL
79     dfminFrac = 0.0
80     iprint = 10
81     epsx = 1.e-6
82     epsg = 1.e-6
83     eps = -1.e-6
84     nupdate = 1
85     ff = 0.
86     cdfer expId = 'MIT_CE_000'
87     yctrlid = 'MIT_CE_000'
88    
89     modeldataunit = 14
90     scrunit1 = 11
91    
92     c-- Read control parameters from file.
93     open(unit=scrunit1,status='scratch')
94    
95     open(unit = modeldataunit,file = 'data.ctrl',
96     & status = 'old', iostat = errio)
97     if ( errio .lt. 0 ) then
98     stop ' stopped in optim_numbmod while opening data.ctrl'
99     endif
100    
101     do while ( .true. )
102     read(modeldataunit, fmt='(a)', end=21) record
103     il = max(ilnblnk(record),1)
104     if ( record(1:1) .ne. commentcharacter )
105     & write(unit=scrunit1, fmt='(a)') record(:il)
106     enddo
107     21 continue
108     close( modeldataunit )
109    
110     rewind( scrunit1 )
111     read(unit = scrunit1, nml = ctrl_packnames)
112     close( scrunit1 )
113     print*, ' OPTIM_READPARMS: Control options have been read.'
114    
115     c-- Read optimization parameters from file.
116     open(unit=scrunit1,status='scratch')
117    
118     open(unit = modeldataunit,file = 'data.optim',
119     & status = 'old', iostat = errio)
120     if ( errio .lt. 0 ) then
121     stop ' stopped in optim_numbmod while opening data.optim'
122     endif
123    
124     do while ( .true. )
125     read(modeldataunit, fmt='(a)', end=22) record
126     il = max(ilnblnk(record),1)
127     if ( record(1:1) .ne. commentcharacter )
128     & write(unit=scrunit1, fmt='(a)') record(:il)
129     enddo
130     22 continue
131     close( modeldataunit )
132    
133     rewind( scrunit1 )
134     read(unit = scrunit1, nml = optim)
135     close( scrunit1 )
136     print*, ' OPTIM_READPARMS: Minimization options have been read.'
137    
138     if (eps .gt. 0.0) then
139     epsf = eps
140     epsx = eps
141     epsg = eps
142     endif
143    
144     call optim_readdata ( nn, ctrlname, .true., ff, vv)
145    
146     if ( dfminFrac.lt.0.0 .or. dfminFrac.ge.1.0) then
147     print*, ' OPTIM_READPARMS: dfminFrac = ', dfminFrac,
148     & ' should be > 0 and < 1'
149     stop 'S/R OPTIM_READPARMS: ABNORMAL END'
150     endif
151     if ( dfminFrac.ne.0.0 ) dfminFrac = 1.0 - dfminFrac
152     if ( fmin.eq.UNSET_RL ) then
153     if ( optimcycle .eq. 0 ) then
154     c only in this case does ff contain the actual cost function value
155     fmin = dfminFrac*ff
156     else
157     c otherwise we (ab-)use the file ctrlname for storing fmin
158     fmin = ff
159     endif
160     endif
161     if ( fmin.le.0.0 .and. optimcycle.eq.0 ) then
162     print*, ' OPTIM_READPARMS: fmin = ', fmin, ' should be > 0'
163     stop 'S/R OPTIM_READPARMS: ABNORMAL END'
164     endif
165    
166     c-- Do some final printout.
167     print*
168     print*, ' OPTIM_READPARMS: Iteration number = ', optimcycle
169     print*, ' number of control variables = ', nn
170     print*, ' cost function value in ', ctrlname, ' = ', ff
171     print '(a,4a,i4.4)',
172     & ' Data will be read from the following file: ',
173     & ctrlname,'_',yctrlid(1:10),'.opt', optimcycle
174     print*
175    
176     return
177     end
178    
179     CStartOfInterface
180     INTEGER FUNCTION ILNBLNK( string )
181     C /==========================================================\
182     C | FUNCTION ILNBLNK |
183     C | o Find last non-blank in character string. |
184     C \==========================================================/
185     IMPLICIT NONE
186     CHARACTER*(*) string
187     CEndOfInterface
188     INTEGER L, LS
189     C
190     LS = LEN(string)
191     ILNBLNK = LS
192     DO 10 L = LS, 1, -1
193     IF ( string(L:L) .EQ. ' ' ) GOTO 10
194     ILNBLNK = L
195     GOTO 11
196     10 CONTINUE
197     11 CONTINUE
198     C
199     RETURN
200     END
201    

  ViewVC Help
Powered by ViewVC 1.1.22