Back to home page

MITgcm

 
 

    


File indexing completed on 2024-03-02 06:10:01 UTC

view on githubraw file Latest commit 5cf43646 on 2024-03-01 18:50:49 UTC
1b116cf4a9 Gael*0001 #include "CTRL_OPTIONS.h"
                0002 
4cee17c1be Patr*0003 cph #ifdef TARGET_CRAY_VECTOR
                0004 cph #  define NML_OPTIM ECCO_OPTIM
                0005 cph #  define NML_ECCO  ECCO_PARMS
                0006 cph #else
                0007 cph #  define NML_OPTIM NML=ECCO_OPTIM
                0008 cph #  define NML_ECCO  NML=ECCO_PARMS
                0009 cph #endif
                0010 
                0011 c     ==================================================================
                0012 c
                0013 c     optim.F: Routines for doing an off-line optimization after the
                0014 c              ECCO forward and adjoint model have been run.
                0015 c
                0016 c     numbmod       - Returns number of variables.
                0017 c     simul         - Mid-level routine that calls the model and its
                0018 c                     adjoint
                0019 c     model         - Forward model.
                0020 c     admodel       - Modified forward model and adjoint model.
                0021 c     initmod       - Initialisation routine.
                0022 c     postmod       - Final routine that prints results.
                0023 c
                0024 c
                0025 c     Documentation:
                0026 c
                0027 c     The collection of these routines originated mainly from Ralf
                0028 c     Giering. Patrick Heimbach improved and corrected some parts of
                0029 c     the original code. Christian Eckert contributed the interface
                0030 c     to the ECCO release of the MITgcmUV in order to get the off-
                0031 c     line version going. The on-line optimisation uses a simple
                0032 c     example, whereas the off-line version deals with the ECCO
851b1c1340 Patr*0033 c     release output. The off-line version can, of course, only
4cee17c1be Patr*0034 c     do one optimization step at a time.
                0035 c
                0036 c     started:  Christian Eckert  eckert@mit.edu  15-Feb-2000
                0037 c
                0038 c               - On-line and off-line capability and some cosmetic
                0039 c                 changes.
                0040 c
                0041 c     changed:  Patrick Heimbach heimbach@mit.edu 19-Jun-2000
                0042 c               - finished, revised and debugged
                0043 c
                0044 c     ==================================================================
                0045 
                0046       subroutine optim_numbmod(
                0047      O                    nn
                0048      &                  )
                0049 
                0050 c     ==================================================================
                0051 c     SUBROUTINE optim_numbmod
                0052 c     ==================================================================
                0053 c
                0054 c     o Set the number of control variables.
                0055 c
                0056 c     started: Christian Eckert eckert@mit.edu 15-Feb-2000
                0057 c
                0058 c     changed: Christian Eckert eckert@mit.edu 09-Mar-2000
                0059 c
                0060 c              - Added ECCO layout.
                0061 c
                0062 c     changed:  Patrick Heimbach heimbach@mit.edu 19-Jun-2000
                0063 c               - finished, revised and debugged
                0064 c
                0065 c     ==================================================================
                0066 c     SUBROUTINE optim_numbmod
                0067 c     ==================================================================
                0068 
                0069       IMPLICIT NONE
                0070 
                0071 c     == global variables ==
                0072 
                0073 #include "EEPARAMS.h"
                0074 #include "SIZE.h"
                0075 
5cf4364659 Mart*0076 #include "CTRL_SIZE.h"
65754df434 Mart*0077 #include "CTRL.h"
4cee17c1be Patr*0078 #include "optim.h"
                0079 #include "minimization.h"
6ec844236d Patr*0080 #include "CTRL_OBCS.h"
269edaaf5e Patr*0081 #ifndef ECCO_CTRL_DEPRECATED
                0082 # include "ctrl_local_params.h"
                0083 #endif
4cee17c1be Patr*0084 
                0085 c     == routine arguments ==
                0086 
                0087       integer nn
                0088 
                0089 c     == local variables ==
                0090 
5cf4364659 Mart*0091       integer ivar
4cee17c1be Patr*0092       integer il
                0093       integer errio
                0094 
                0095       _RL            ff
                0096 
                0097 #if defined (DYNAMIC)
                0098       _RL            vv(nn)
                0099 #elif defined (USE_POINTER) || (MAX_INDEPEND == 0)
                0100       _RL            vv
                0101       pointer (pvv,vv(1))
                0102 #else
                0103       integer nmax
                0104       parameter( nmax = MAX_INDEPEND )
                0105       _RL   vv(nmax)
                0106 #endif
                0107 
                0108       character*(max_len_prec) record
                0109 
                0110       logical lheaderonly
                0111 
                0112 c     == external ==
                0113 
                0114       integer  ilnblnk
                0115 
                0116 c     == end of interface ==
                0117 
                0118       namelist /CTRL_NML/
c204fd9ffc Patr*0119      &  xx_theta_file, xx_salt_file,
                0120      &  xx_hflux_file, xx_hflux_remo_intercept, xx_hflux_remo_slope,
4cee17c1be Patr*0121      &  xx_hfluxstartdate1, xx_hfluxstartdate2, xx_hfluxperiod,
c204fd9ffc Patr*0122      &  xx_sflux_file, xx_sflux_remo_intercept, xx_sflux_remo_slope,
4cee17c1be Patr*0123      &  xx_sfluxstartdate1, xx_sfluxstartdate2, xx_sfluxperiod,
c204fd9ffc Patr*0124      &  xx_tauu_file, xx_tauu_remo_intercept, xx_tauu_remo_slope,
4cee17c1be Patr*0125      &  xx_tauustartdate1,  xx_tauustartdate2,  xx_tauuperiod,
c204fd9ffc Patr*0126      &  xx_tauv_file, xx_tauv_remo_intercept, xx_tauv_remo_slope,
acff328b8b Mart*0127      &  xx_tauvstartdate1,  xx_tauvstartdate2,  xx_tauvperiod,
c204fd9ffc Patr*0128      &  xx_atemp_file, xx_atemp_remo_intercept, xx_atemp_remo_slope,
acff328b8b Mart*0129      &  xx_atempstartdate1, xx_atempstartdate2, xx_atempperiod,
c204fd9ffc Patr*0130      &  xx_aqh_file, xx_aqh_remo_intercept, xx_aqh_remo_slope,
acff328b8b Mart*0131      &  xx_aqhstartdate1, xx_aqhstartdate2, xx_aqhperiod,
c204fd9ffc Patr*0132      &  xx_precip_file, xx_precip_remo_intercept, xx_precip_remo_slope,
9ba82a4741 Patr*0133      &  xx_precipstartdate1, xx_precipstartdate2, xx_precipperiod,
c204fd9ffc Patr*0134      &  xx_swflux_file, xx_swflux_remo_intercept, xx_swflux_remo_slope,
9ba82a4741 Patr*0135      &  xx_swfluxstartdate1, xx_swfluxstartdate2, xx_swfluxperiod,
c204fd9ffc Patr*0136      &  xx_swdown_file, xx_swdown_remo_intercept, xx_swdown_remo_slope,
9ba82a4741 Patr*0137      &  xx_swdownstartdate1, xx_swdownstartdate2, xx_swdownperiod,
c204fd9ffc Patr*0138      &  xx_lwflux_file, xx_lwflux_remo_intercept, xx_lwflux_remo_slope,
                0139      &  xx_lwfluxstartdate1, xx_lwfluxstartdate2, xx_lwfluxperiod,
                0140      &  xx_lwdown_file, xx_lwdown_remo_intercept, xx_lwdown_remo_slope,
                0141      &  xx_lwdownstartdate1, xx_lwdownstartdate2, xx_lwdownperiod,
                0142      &  xx_evap_file, xx_evap_remo_intercept, xx_evap_remo_slope,
                0143      &  xx_evapstartdate1, xx_evapstartdate2, xx_evapperiod,
d5b8fa0522 Mart*0144      &  xx_snowprecip_file, xx_snowprecip_remo_intercept,
c204fd9ffc Patr*0145      &  xx_snowprecip_remo_slope,  xx_snowprecipperiod,
                0146      &  xx_snowprecipstartdate1, xx_snowprecipstartdate2,
d5b8fa0522 Mart*0147      &  xx_apressure_file, xx_apressure_remo_intercept,
c204fd9ffc Patr*0148      &  xx_apressure_remo_slope, xx_apressureperiod,
                0149      &  xx_apressurestartdate1, xx_apressurestartdate2,
                0150      &  xx_runoff_file, xx_runoff_remo_intercept, xx_runoff_remo_slope,
                0151      &  xx_runoffstartdate1, xx_runoffstartdate2, xx_runoffperiod,
                0152      &  xx_uwind_file, xx_uwind_remo_intercept, xx_uwind_remo_slope,
acff328b8b Mart*0153      &  xx_uwindstartdate1, xx_uwindstartdate2, xx_uwindperiod,
c204fd9ffc Patr*0154      &  xx_vwind_file, xx_vwind_remo_intercept, xx_vwind_remo_slope,
acff328b8b Mart*0155      &  xx_vwindstartdate1, xx_vwindstartdate2, xx_vwindperiod,
c204fd9ffc Patr*0156      &  xx_obcsn_file, xx_obcss_file, xx_obcsw_file, xx_obcse_file,
acff328b8b Mart*0157      &  xx_obcsnstartdate1,  xx_obcsnstartdate2,  xx_obcsnperiod,
                0158      &  xx_obcssstartdate1,  xx_obcssstartdate2,  xx_obcssperiod,
                0159      &  xx_obcswstartdate1,  xx_obcswstartdate2,  xx_obcswperiod,
                0160      &  xx_obcsestartdate1,  xx_obcsestartdate2,  xx_obcseperiod,
c204fd9ffc Patr*0161      &  xx_diffkr_file, xx_kapgm_file, xx_tr1_file,
                0162      &  xx_sst_file, xx_sss_file,
91d99130a0 Davi*0163      &  xx_sststartdate1, xx_sststartdate2, xx_sstperiod,
                0164      &  xx_sssstartdate1, xx_sssstartdate2, xx_sssperiod,
c204fd9ffc Patr*0165      &  xx_depth_file, xx_efluxy_file, xx_efluxp_file,
                0166      &  xx_bottomdrag_file, xx_edtaux_file, xx_edtauy_file,
                0167      &  xx_uvel_file, xx_vvel_file, xx_etan_file,
d5b8fa0522 Mart*0168      &  xx_shifwflx_file,
                0169      &  xx_shifwflx_remo_intercept, xx_shifwflx_remo_slope,
e189f4121c Mart*0170      &  xx_shifwflxstartdate1, xx_shifwflxstartdate2, xx_shifwflxperiod,
c204fd9ffc Patr*0171      &  doInitXX, doPackDiag, doZscaleUnpack, doZscalePack,
93558ef104 Gael*0172      &  doMainUnpack, doMainPack, doAdmtlmBypassAD, delZexp,
                0173      &  xx_hfluxm_file, doSinglePrecTapelev
4cee17c1be Patr*0174 
                0175       namelist /CTRL_PACKNAMES/
1f82d30822 Patr*0176      &  yadmark, yctrlid, yctrlposunpack, yctrlpospack,
4cee17c1be Patr*0177      &  ctrlname, costname, scalname, maskname, metaname
                0178 
1f82d30822 Patr*0179       namelist /OPTIM/
4cee17c1be Patr*0180      &                      optimcycle,
                0181      &                      numiter, nfunc, fmin, iprint,
                0182      &                      epsf, epsx, epsg,
                0183      &                      nupdate, eps
                0184 
d5b8fa0522 Mart*0185 c--   Initialise myx/ygloballo to one. In the MITgcm they are set in
                0186 c     ini_procs.F according to the current mpi-process, but here we
                0187 c     can just set them to 1 because we do not anticipate to ever run
                0188 c     this program in a multprocessor environment.
                0189       myygloballo = 1
                0190       myxgloballo = 1
                0191 
4cee17c1be Patr*0192 c--   Preset the optimization parameters.
                0193       optimcycle =  0
                0194       nvars      =  0
                0195       numiter    =  1
                0196       nfunc      =  1
                0197       fmin       =  0.0
                0198       iprint     =  10
                0199       epsx       =  1.e-6
                0200       epsg       =  1.e-6
                0201       eps        = -1.e-6
                0202       nupdate    =  1
                0203       ff         = 0.
91d99130a0 Davi*0204 cdfer      expId      = 'MIT_CE_000'
                0205       yctrlid    = 'MIT_CE_000'
4cee17c1be Patr*0206 
                0207       modeldataunit = 14
                0208       scrunit1      = 11
                0209 
                0210 c--   Read control parameters from file.
                0211       open(unit=scrunit1,status='scratch')
                0212 
                0213       open(unit = modeldataunit,file = 'data.ctrl',
                0214      &     status = 'old', iostat = errio)
                0215       if ( errio .lt. 0 ) then
                0216          stop ' stopped in optim_numbmod'
                0217       endif
                0218 
                0219       do while ( .true. )
                0220          read(modeldataunit, fmt='(a)', end=21) record
                0221          il = max(ilnblnk(record),1)
                0222          if ( record(1:1) .ne. commentcharacter )
                0223      &        write(unit=scrunit1, fmt='(a)') record(:il)
                0224       enddo
                0225    21 continue
                0226       close( modeldataunit )
                0227 
                0228       rewind( scrunit1 )
                0229       read(unit = scrunit1, nml = ctrl_nml)
                0230       read(unit = scrunit1, nml = ctrl_packnames)
                0231       close( scrunit1 )
                0232       print*, ' OPTIM_NUMBMOD: Control options have been read.'
                0233 
1f82d30822 Patr*0234 cph(
91d99130a0 Davi*0235 cdfer      expId = yctrlid
1f82d30822 Patr*0236 cph)
                0237 
4cee17c1be Patr*0238 c--   Read optimization parameters from file.
                0239       open(unit=scrunit1,status='scratch')
                0240 
                0241       open(unit = modeldataunit,file = 'data.optim',
                0242      &     status = 'old', iostat = errio)
                0243       if ( errio .lt. 0 ) then
                0244          stop ' stopped in optim_numbmod'
                0245       endif
                0246 
                0247       do while ( .true. )
                0248          read(modeldataunit, fmt='(a)', end=22) record
                0249          il = max(ilnblnk(record),1)
                0250          if ( record(1:1) .ne. commentcharacter )
                0251      &        write(unit=scrunit1, fmt='(a)') record(:il)
                0252       enddo
                0253    22 continue
                0254       close( modeldataunit )
                0255 
                0256       rewind( scrunit1 )
1f82d30822 Patr*0257       read(unit = scrunit1, nml = optim)
4cee17c1be Patr*0258       close( scrunit1 )
                0259       print*, ' OPTIM_NUMBMOD: Minimization options have been read.'
                0260 
                0261       if (eps .gt. 0.0) then
                0262         epsf = eps
                0263         epsx = eps
                0264         epsg = eps
                0265       endif
                0266 
5cf4364659 Mart*0267 c     Initialise some global variables before calling optim_readdata, so
                0268 c     that they contain sensible values.
                0269       do ivar=1,maxcvars
                0270        ncvarindex(ivar) = -1
                0271        ncvarrecs(ivar)  = -1
                0272        ncvarxmax(ivar)  = -1
                0273        ncvarymax(ivar)  = -1
                0274        ncvarnrmax(ivar) = -1
                0275        ncvargrd(ivar)   = 'X'
                0276        ncvartype(ivar)  = 'UNSET'
                0277       enddo
                0278 
4cee17c1be Patr*0279       lheaderonly = .true.
                0280       call optim_readdata ( nn, ctrlname, lheaderonly, ff, vv)
                0281 
                0282 c--   Do some final printout.
                0283       print*
                0284       print*, ' OPTIM_NUMBMOD: Iteration number = ', optimcycle
                0285       print*, ' number of control variables     = ', nn
                0286       print*, ' Data will be read from the following files:'
                0287       print*
                0288 
                0289 ce    --> data.err file in case dimensional i/o is used.
                0290 ce    --> scaling  file in case dimensional i/o is used.
                0291 
                0292       return
                0293       end