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

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

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


Revision 1.2 - (show annotations) (download)
Fri Apr 27 08:07:47 2012 UTC (11 years, 11 months ago) by mlosch
Branch: MAIN
Changes since 1.1: +9 -3 lines
catch the case of fmin > ff

1 C $Header: /u/gcmpack/MITgcm_contrib/mlosch/optim_m1qn3/optim_readparms.F,v 1.1 2012/04/26 11:10:06 mlosch Exp $
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 ( optimcycle.eq.0 ) then
162 if ( fmin.le.0.0 ) then
163 print*, ' OPTIM_READPARMS: fmin = ', fmin, ' should be > 0'
164 stop 'S/R OPTIM_READPARMS: ABNORMAL END'
165 endif
166 if ( fmin.lt.ff ) then
167 print*, ' OPTIM_READPARMS: fmin = ', fmin,
168 & ' should be < ff = ', ff
169 stop 'S/R OPTIM_READPARMS: ABNORMAL END'
170 endif
171
172 c-- Do some final printout.
173 print*
174 print*, ' OPTIM_READPARMS: Iteration number = ', optimcycle
175 print*, ' number of control variables = ', nn
176 print*, ' cost function value in ', ctrlname, ' = ', ff
177 print '(a,4a,i4.4)',
178 & ' Data will be read from the following file: ',
179 & ctrlname,'_',yctrlid(1:10),'.opt', optimcycle
180 print*
181
182 return
183 end
184
185 CStartOfInterface
186 INTEGER FUNCTION ILNBLNK( string )
187 C /==========================================================\
188 C | FUNCTION ILNBLNK |
189 C | o Find last non-blank in character string. |
190 C \==========================================================/
191 IMPLICIT NONE
192 CHARACTER*(*) string
193 CEndOfInterface
194 INTEGER L, LS
195 C
196 LS = LEN(string)
197 ILNBLNK = LS
198 DO 10 L = LS, 1, -1
199 IF ( string(L:L) .EQ. ' ' ) GOTO 10
200 ILNBLNK = L
201 GOTO 11
202 10 CONTINUE
203 11 CONTINUE
204 C
205 RETURN
206 END
207

  ViewVC Help
Powered by ViewVC 1.1.22