/[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.7 - (hide annotations) (download)
Wed May 9 18:33:38 2012 UTC (11 years, 11 months ago) by mlosch
Branch: MAIN
Changes since 1.6: +6 -1 lines
make coldStart a global variable

1 mlosch 1.7 C $Header: /u/gcmpack/MITgcm_contrib/mlosch/optim_m1qn3/optim_readparms.F,v 1.6 2012/04/27 13:58:14 mlosch Exp $
2 mlosch 1.2 C $Name: $
3 mlosch 1.1
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 mlosch 1.5 #ifdef DYNAMIC
45 mlosch 1.1 _RL vv(nn)
46     #else
47     integer nmax
48     parameter( nmax = MAX_INDEPEND )
49     _RL vv(nmax)
50     #endif
51    
52     character*(max_len_prec) record
53    
54     c == external ==
55    
56     integer ilnblnk
57    
58     c == end of interface ==
59    
60     namelist /CTRL_PACKNAMES/
61     & yadmark, ctrlname, costname, scalname, maskname, metaname,
62     & yctrlid, yctrlposunpack, yctrlpospack
63    
64     namelist /OPTIM/
65     & optimcycle,
66     & numiter, nfunc, fmin, dfminFrac, iprint,
67     & epsf, epsx, epsg,
68     & nupdate, eps
69    
70 mlosch 1.7 namelist /M1QN3/
71     & coldStart
72    
73 mlosch 1.1 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 mlosch 1.7 coldStart = .false.
89 mlosch 1.1
90     modeldataunit = 14
91     scrunit1 = 11
92    
93     c-- Read control parameters from file.
94     open(unit=scrunit1,status='scratch')
95    
96     open(unit = modeldataunit,file = 'data.ctrl',
97     & status = 'old', iostat = errio)
98     if ( errio .lt. 0 ) then
99 mlosch 1.3 stop ' stopped in optim_readparms while opening data.ctrl'
100 mlosch 1.1 endif
101    
102     do while ( .true. )
103     read(modeldataunit, fmt='(a)', end=21) record
104     il = max(ilnblnk(record),1)
105     if ( record(1:1) .ne. commentcharacter )
106     & write(unit=scrunit1, fmt='(a)') record(:il)
107     enddo
108     21 continue
109     close( modeldataunit )
110    
111     rewind( scrunit1 )
112     read(unit = scrunit1, nml = ctrl_packnames)
113     close( scrunit1 )
114     print*, ' OPTIM_READPARMS: Control options have been read.'
115    
116     c-- Read optimization parameters from file.
117     open(unit=scrunit1,status='scratch')
118    
119     open(unit = modeldataunit,file = 'data.optim',
120     & status = 'old', iostat = errio)
121     if ( errio .lt. 0 ) then
122 mlosch 1.3 stop ' stopped in optim_readparms while opening data.optim'
123 mlosch 1.1 endif
124    
125     do while ( .true. )
126     read(modeldataunit, fmt='(a)', end=22) record
127     il = max(ilnblnk(record),1)
128     if ( record(1:1) .ne. commentcharacter )
129     & write(unit=scrunit1, fmt='(a)') record(:il)
130     enddo
131     22 continue
132     close( modeldataunit )
133    
134     rewind( scrunit1 )
135     read(unit = scrunit1, nml = optim)
136 mlosch 1.7 read(unit = scrunit1, nml = m1qn3)
137 mlosch 1.1 close( scrunit1 )
138     print*, ' OPTIM_READPARMS: Minimization options have been read.'
139    
140     if (eps .gt. 0.0) then
141     epsf = eps
142     epsx = eps
143     epsg = eps
144     endif
145    
146     call optim_readdata ( nn, ctrlname, .true., ff, vv)
147    
148     if ( dfminFrac.lt.0.0 .or. dfminFrac.ge.1.0) then
149     print*, ' OPTIM_READPARMS: dfminFrac = ', dfminFrac,
150     & ' should be > 0 and < 1'
151     stop 'S/R OPTIM_READPARMS: ABNORMAL END'
152     endif
153     if ( dfminFrac.ne.0.0 ) dfminFrac = 1.0 - dfminFrac
154     if ( fmin.eq.UNSET_RL ) then
155     if ( optimcycle .eq. 0 ) then
156     c only in this case does ff contain the actual cost function value
157     fmin = dfminFrac*ff
158     else
159     c otherwise we (ab-)use the file ctrlname for storing fmin
160     fmin = ff
161     endif
162     endif
163 mlosch 1.2 if ( optimcycle.eq.0 ) then
164 mlosch 1.4 if ( fmin.le.0.0 ) then
165 mlosch 1.6 print '(A,E12.6,A)', ' OPTIM_READPARMS: fmin = ', fmin,
166     & ' should be > 0'
167 mlosch 1.4 stop 'S/R OPTIM_READPARMS: ABNORMAL END'
168     endif
169 mlosch 1.6 if ( fmin.gt.ff ) then
170     print '(A,E12.6,A,E12.6)', ' OPTIM_READPARMS: fmin = ', fmin,
171 mlosch 1.4 & ' should be < ff = ', ff
172     stop 'S/R OPTIM_READPARMS: ABNORMAL END'
173     endif
174 mlosch 1.2 endif
175 mlosch 1.1
176     c-- Do some final printout.
177     print*
178     print*, ' OPTIM_READPARMS: Iteration number = ', optimcycle
179     print*, ' number of control variables = ', nn
180     print*, ' cost function value in ', ctrlname, ' = ', ff
181     print '(a,4a,i4.4)',
182     & ' Data will be read from the following file: ',
183     & ctrlname,'_',yctrlid(1:10),'.opt', optimcycle
184     print*
185    
186     return
187     end
188    
189     CStartOfInterface
190     INTEGER FUNCTION ILNBLNK( string )
191     C /==========================================================\
192     C | FUNCTION ILNBLNK |
193     C | o Find last non-blank in character string. |
194     C \==========================================================/
195     IMPLICIT NONE
196     CHARACTER*(*) string
197     CEndOfInterface
198     INTEGER L, LS
199     C
200     LS = LEN(string)
201     ILNBLNK = LS
202     DO 10 L = LS, 1, -1
203     IF ( string(L:L) .EQ. ' ' ) GOTO 10
204     ILNBLNK = L
205     GOTO 11
206     10 CONTINUE
207     11 CONTINUE
208     C
209     RETURN
210     END
211    

  ViewVC Help
Powered by ViewVC 1.1.22