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

Diff of /MITgcm_contrib/mlosch/optim_m1qn3/optim_sub.F

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

revision 1.1 by mlosch, Thu Apr 26 11:10:06 2012 UTC revision 1.6 by mlosch, Mon Jun 4 12:23:34 2012 UTC
# Line 48  c     == local variables == Line 48  c     == local variables ==
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 )
# Line 63  c     == local variables == Line 57  c     == local variables ==
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
# Line 90  c     == end of interface == Line 85  c     == end of interface ==
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
# Line 146  c     initialise the dummy arguments tha Line 138  c     initialise the dummy arguments tha
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          if ( coldStart ) then
159  c--   cold start  c--   cold start
160         print *, ' OPTIM_SUB: cold start, optimcycle =', optimcycle         print *, ' OPTIM_SUB: cold start, optimcycle =', optimcycle
161         imode(2) = 0         imode(2) = 0
# Line 154  c     this variable is the only one of t Line 163  c     this variable is the only one of t
163  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
164  c     clean start  c     clean start
165         reentry  = 0         reentry  = 0
166  c     ff has be read in optim_readparms, so we do not read it here again  c     compute expected decrease of cost function from objf and fmin;
167         objf = ff  c     this value is only used for a cold start of m1qn3_offline, for a
168         df1  = objf-fmin  c     warm start df1 is overwritten with data from a restart file
169           df1=objf-fmin
170           if ( df1 .le. 0. ) then
171            print *, ' OPTIM_SUB: df1 = objf-fmin = ', df1,
172         &       ' but should be > 0.'
173            stop 'ABNORMAL in S/R OPTIM_SUB'
174           endif
175    
176  c     open output file for m1qn3  c     open output file for m1qn3
177         open(io,file=fname_m1qn3,status='unknown')         open(io,file=fname_m1qn3,status='unknown')
178        else        else
# Line 170  c     requires restoring the state of m1 Line 186  c     requires restoring the state of m1
186  c     re-open output file for m1qn3  c     re-open output file for m1qn3
187         open(io,file=fname_m1qn3,status='old',position='append')         open(io,file=fname_m1qn3,status='old',position='append')
188        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  
189    
190  c--   call the minimizer, a slightly modified version of m1qn3 v3.3  c--   call the minimizer, a slightly modified version of m1qn3 v3.3
191  c     (Gilbert & Lemarechal, 1989), downloaded in April 2012.  c     (Gilbert & Lemarechal, 1989), downloaded in April 2012.
# Line 193  c     simul_rc,euclid,ctonbe,ctcabe are Line 193  c     simul_rc,euclid,ctonbe,ctcabe are
193  c     are provided within m1qn3. euclid, ctonbe, ctcabe can be replaced  c     are provided within m1qn3. euclid, ctonbe, ctcabe can be replaced
194  c     by something more efficient, simul_rc is a dummy routine for  c     by something more efficient, simul_rc is a dummy routine for
195  c     the reverse communication mode and should not be changed.  c     the reverse communication mode and should not be changed.
196        print *, ' OPTIM_SUB: call m1qn3_offline'        print *, ' OPTIM_SUB: call m1qn3_offline ........'
197        call m1qn3_offline (simul_rc,euclid,ctonbe,ctcabe,        call m1qn3_offline (simul_rc,euclid,ctonbe,ctcabe,
198       &     nn,xx,objf,adxx,dxmin,df1,       &     nn,xx,objf,adxx,dxmin,df1,
199       &     epsg,normtype,impres,io,imode,omode,niter,nsim,       &     epsg,normtype,impres,io,imode,omode,niter,nsim,
200       &     iz,dz,ndz,reverse,indic,izs,rzs,dzs)       &     iz,dz,ndz,reverse,indic,izs,rzs,dzs)
201        close(io)        close(io)
202          print *, ' OPTIM_SUB: ...........................'
203        print *, ' OPTIM_SUB: returned from m1qn3_offline'        print *, ' OPTIM_SUB: returned from m1qn3_offline'
204          print *, ' OPTIM_SUB:      nn = ', nn
205          print *, ' OPTIM_SUB:   xx(1) = ', xx(1), xx(2)
206          print *, ' OPTIM_SUB: adxx(1) = ', adxx(1), adxx(2)
207          print *, ' OPTIM_SUB: omode   = ', omode
208          print *, ' OPTIM_SUB: niter   = ', niter
209          print *, ' OPTIM_SUB: nsim    = ', nsim
210          print *, ' OPTIM_SUB: reverse = ', reverse
211    
212  c     write state of m1qn3 into pickup file for warm restart  c     write state of m1qn3 into pickup file for warm restart
213        call optim_store_m1qn3(ndz,iz,dz,niter,nsim,epsg,df1,        call optim_store_m1qn3(ndz,iz,dz,niter,nsim,epsg,df1,
# Line 213  c     mistakes it for the real one Line 221  c     mistakes it for the real one
221        call optim_writedata( nn, ctrlname, .false., -9999., xx )        call optim_writedata( nn, ctrlname, .false., -9999., xx )
222    
223  c     clean up  c     clean up
224    #ifdef DYNAMIC
225          deallocate(xx, adxx)
226    #endif /* DYNAMIC */
227        deallocate(dz)        deallocate(dz)
228    
229  c     stopping criterion  c     stopping criterion

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.22