/[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.5 by mlosch, Thu May 10 10:25:14 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 213  c     mistakes it for the real one Line 213  c     mistakes it for the real one
213        call optim_writedata( nn, ctrlname, .false., -9999., xx )        call optim_writedata( nn, ctrlname, .false., -9999., xx )
214    
215  c     clean up  c     clean up
216    #ifdef DYNAMIC
217          deallocate(xx, adxx)
218    #endif /* DYNAMIC */
219        deallocate(dz)        deallocate(dz)
220    
221  c     stopping criterion  c     stopping criterion

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

  ViewVC Help
Powered by ViewVC 1.1.22