Back to home page

MITgcm

 
 

    


File indexing completed on 2024-05-25 05:10:20 UTC

view on githubraw file Latest commit 00f81e67 on 2024-05-24 21:00:12 UTC
6d54cf9ca1 Ed H*0001 #include "PACKAGES_CONFIG.h"
2846da876f Alis*0002 #include "CPP_OPTIONS.h"
c10ffac493 Jean*0003 #ifdef ALLOW_AUTODIFF
                0004 # include "AUTODIFF_OPTIONS.h"
                0005 #endif
83df00bce7 Patr*0006 #ifdef ALLOW_GENERIC_ADVDIFF
                0007 # include "GAD_OPTIONS.h"
                0008 #endif
1dc3e353c5 Jean*0009 #ifdef ALLOW_GGL90
                0010 # include "GGL90_OPTIONS.h"
                0011 #endif
7ef85e240a Mart*0012 #ifdef ALLOW_GMREDI
                0013 # include "GMREDI_OPTIONS.h"
                0014 #endif
1dc3e353c5 Jean*0015 #ifdef ALLOW_OBCS
                0016 # include "OBCS_OPTIONS.h"
58c557b4ea Patr*0017 #endif
1dc3e353c5 Jean*0018 #ifdef ALLOW_SEAICE
                0019 # include "SEAICE_OPTIONS.h"
                0020 #endif
                0021 #ifdef ALLOW_GCHEM
                0022 # include "GCHEM_OPTIONS.h"
                0023 #endif
                0024 #ifdef ALLOW_DIC
                0025 # include "DIC_OPTIONS.h"
9a00d4fc17 Gael*0026 #endif
2b118f1270 Matt*0027 #ifdef ALLOW_BLING
                0028 # include "BLING_OPTIONS.h"
                0029 #endif
9a00d4fc17 Gael*0030 #ifdef ALLOW_EXF
                0031 # include "EXF_OPTIONS.h"
                0032 #endif
1dc3e353c5 Jean*0033 #ifdef ALLOW_STREAMICE
                0034 # include "STREAMICE_OPTIONS.h"
                0035 #endif
c10ffac493 Jean*0036 #ifdef ALLOW_COST
                0037 # include "COST_OPTIONS.h"
                0038 #endif
c1fca7389f Gael*0039 #ifdef ALLOW_CTRL
                0040 # include "CTRL_OPTIONS.h"
                0041 #endif
30c7aa4d63 Gael*0042 #ifdef ALLOW_ECCO
                0043 # include "ECCO_OPTIONS.h"
                0044 #endif
9cfac49d8b Gael*0045 #ifdef ALLOW_PROFILES
                0046 # include "PROFILES_OPTIONS.h"
                0047 #endif
2cfc9d59a2 Patr*0048 
9366854e02 Chri*0049 CBOP
                0050 C     !ROUTINE: THE_MAIN_LOOP
                0051 C     !INTERFACE:
b31265ed88 Jean*0052       SUBROUTINE THE_MAIN_LOOP( myTime, myIter, myThid )
9366854e02 Chri*0053 
                0054 C     !DESCRIPTION: \bv
                0055 C     *================================================================*
                0056 C     | SUBROUTINE the_main_loop
                0057 C     | o Run the ocean model and evaluate the specified cost function.
                0058 C     *================================================================*
                0059 C     |
                0060 C     | THE_MAIN_LOOP is the toplevel routine for the Tangent Linear and
88794ad36d Jean*0061 C     | Adjoint Model Compiler (TAMC).
ded033bbc1 Patr*0062 C     | For this purpose the initialization
9366854e02 Chri*0063 C     | of the model was split into two parts. Those parameters that do
                0064 C     | not depend on a specific model run are set in INITIALISE_FIXED,
                0065 C     | whereas those that do depend on the specific realization are
88794ad36d Jean*0066 C     | initialized in INITIALISE_VARIA.
                0067 C     | This routine is to be used in conjuction with the MITgcmuv
9366854e02 Chri*0068 C     | checkpoint 37.
                0069 C     *================================================================*
                0070 C     \ev
                0071 
                0072 C     !USES:
                0073       IMPLICIT NONE
                0074 C     == Global variables ==
2846da876f Alis*0075 #include "SIZE.h"
                0076 #include "EEPARAMS.h"
                0077 #include "PARAMS.h"
39154404ca Patr*0078 
                0079 c**************************************
6528621149 Patr*0080 #ifdef ALLOW_AUTODIFF
c10ffac493 Jean*0081 # ifndef ALLOW_OPENAD
39154404ca Patr*0082 
88794ad36d Jean*0083 c These includes are needed for
                0084 c AD-checkpointing.
39154404ca Patr*0085 c They provide the fields to be stored.
                0086 
7f4c5015d5 Patr*0087 #  include "AUTODIFF_MYFIELDS.h"
71d68194c9 Patr*0088 #  include "GRID.h"
                0089 #  include "DYNVARS.h"
bef5cbe0ec Patr*0090 #  include "SURFACE.h"
71d68194c9 Patr*0091 #  include "FFIELDS.h"
                0092 #  include "EOS.h"
bef5cbe0ec Patr*0093 #  include "AUTODIFF.h"
5728d4a98b Patr*0094 
c633f73536 Patr*0095 #  ifdef ALLOW_GENERIC_ADVDIFF
                0096 #   include "GAD.h"
83df00bce7 Patr*0097 #   include "GAD_SOM_VARS.h"
c633f73536 Patr*0098 #  endif
                0099 #  ifdef ALLOW_MOM_FLUXFORM
                0100 #   include "MOM_FLUXFORM.h"
                0101 #  endif
71d68194c9 Patr*0102 #  ifdef ALLOW_CD_CODE
                0103 #   include "CD_CODE_VARS.h"
                0104 #  endif
65b69c6b17 Patr*0105 #  ifdef ALLOW_PTRACERS
71d68194c9 Patr*0106 #   include "PTRACERS_SIZE.h"
85f77391e5 Jean*0107 #   include "PTRACERS_FIELDS.h"
5463551803 Patr*0108 #   include "PTRACERS_START.h"
65b69c6b17 Patr*0109 #  endif
f09d2da379 Jean*0110 #  ifdef ALLOW_GCHEM
1dc3e353c5 Jean*0111 #   include "GCHEM_SIZE.h"
f09d2da379 Jean*0112 #   include "GCHEM_FIELDS.h"
                0113 #  endif
                0114 #  ifdef ALLOW_CFC
                0115 #   include "CFC.h"
                0116 #  endif
                0117 #  ifdef ALLOW_DIC
                0118 #   include "DIC_VARS.h"
                0119 #   include "DIC_LOAD.h"
                0120 #   include "DIC_ATMOS.h"
                0121 #   include "DIC_CTRL.h"
                0122 #   include "DIC_COST.h"
                0123 #  endif
71d68194c9 Patr*0124 #  ifdef ALLOW_OBCS
6f4cf52d27 Dimi*0125 #   include "OBCS_PARAMS.h"
a9eb030de2 Jean*0126 #   include "OBCS_FIELDS.h"
                0127 #   include "OBCS_SEAICE.h"
71d68194c9 Patr*0128 #   ifdef ALLOW_PTRACERS
                0129 #    include "OBCS_PTRACERS.h"
                0130 #   endif
                0131 #  endif
                0132 #  ifdef ALLOW_EXF
                0133 #   ifdef ALLOW_BULKFORMULAE
                0134 #    include "EXF_CONSTANTS.h"
                0135 #   endif
67647493ca Jean*0136 #   include "EXF_INTERP_SIZE.h"
                0137 #   include "EXF_FIELDS.h"
71d68194c9 Patr*0138 #  endif /* ALLOW_EXF */
f7286c3b8b Matt*0139 #  ifdef ALLOW_BLING
                0140 #   include "BLING_VARS.h"
                0141 #   include "BLING_LOAD.h"
                0142 #  endif
71d68194c9 Patr*0143 #  ifdef ALLOW_SEAICE
ccaa3c61f4 Patr*0144 #   include "SEAICE_SIZE.h"
71d68194c9 Patr*0145 #   include "SEAICE.h"
8a37a22def Patr*0146 #   include "SEAICE_PARAMS.h"
1e22f5fc71 Patr*0147 #   include "SEAICE_COST.h"
13c01105ad Patr*0148 #   include "SEAICE_TRACER.h"
71d68194c9 Patr*0149 #  endif
56b3a0d0fa Patr*0150 #  ifdef ALLOW_SALT_PLUME
                0151 #   include "SALT_PLUME.h"
                0152 #  endif
71d68194c9 Patr*0153 #  ifdef ALLOW_THSICE
                0154 #   include "THSICE_SIZE.h"
                0155 #   include "THSICE_VARS.h"
2d30aeeef0 Patr*0156 #   include "THSICE_COST.h"
71d68194c9 Patr*0157 #  endif
3e86393e2c Patr*0158 #  ifdef ALLOW_SHELFICE
                0159 #   include "SHELFICE.h"
                0160 #   include "SHELFICE_COST.h"
                0161 #  endif
58c557b4ea Patr*0162 #  ifdef ALLOW_STREAMICE
                0163 #   include "STREAMICE.h"
                0164 #   include "STREAMICE_ADV.h"
                0165 #   include "STREAMICE_BDRY.h"
                0166 #   include "STREAMICE_CG.h"
                0167 #  endif
71d68194c9 Patr*0168 #  ifdef ALLOW_EBM
                0169 #   include "EBM.h"
                0170 #  endif
                0171 #  ifdef ALLOW_RBCS
de7a0e15d8 Jean*0172 #   include "RBCS_SIZE.h"
                0173 #   include "RBCS_FIELDS.h"
71d68194c9 Patr*0174 #  endif
9683f9bbcc Patr*0175 #  ifdef ALLOW_OFFLINE
                0176 #   include "OFFLINE.h"
                0177 #  endif
aecc8b0f47 Mart*0178 # if (defined ALLOW_CG2D_NSA || defined NONLIN_FRSURF || \
                0179       defined ALLOW_DEPTH_CONTROL)
55d9234027 Patr*0180 #   include "CG2D.h"
                0181 #  endif
22b72941c7 Jean*0182 #  ifdef ALLOW_DIVIDED_ADJOINT
                0183 #   ifdef ALLOW_USE_MPI
                0184 #    include "mpif.h"
                0185 #   endif
71d68194c9 Patr*0186 #  endif
                0187 
b4daa24319 Shre*0188 C-- keep tamc.h here without ALLOW_AUTODIFF_TAMC for ALLOW_TAMC_CHECKPOINTING
71d68194c9 Patr*0189 #  include "tamc.h"
9a00d4fc17 Gael*0190 
56a89d1ef6 Mart*0191 #  ifdef ALLOW_GGL90
                0192 #   include "GGL90.h"
                0193 #  endif
                0194 #  ifdef ALLOW_PROFILES
                0195 #   include "PROFILES_SIZE.h"
                0196 #   include "profiles.h"
                0197 #  endif
                0198 #  ifdef ALLOW_ECCO
                0199 #   include "ecco_cost.h"
                0200 #  endif
                0201 C     it is important that this file is included after SEAICE_SIZE.h
                0202 #  include "AUTODIFF_STORE.h"
c10ffac493 Jean*0203 # endif /* undef ALLOW_OPENAD */
39154404ca Patr*0204 
0513668de6 Gael*0205 # ifdef ALLOW_CTRL
                0206 # include "CTRL_SIZE.h"
4d72283393 Mart*0207 # include "CTRL.h"
edcd27be69 Mart*0208 # include "CTRL_DUMMY.h"
c1fca7389f Gael*0209 # include "CTRL_GENARR.h"
4948b10fac Gael*0210 # include "CTRL_OBCS.h"
0513668de6 Gael*0211 # endif
                0212 # ifdef ALLOW_COST
                0213 #  include "cost.h"
                0214 # endif
39154404ca Patr*0215 
6528621149 Patr*0216 #endif /* ALLOW_AUTODIFF */
b4daa24319 Shre*0217 
                0218 #ifdef ALLOW_TAPENADE
                0219 # ifdef ALLOW_GMREDI
                0220 #  include "GMREDI.h"
                0221 #  include "GMREDI_TAVE.h"
                0222 # endif
                0223 # ifdef ALLOW_KPP
                0224 #  include "KPP.h"
                0225 c#  include "KPP_PARAMS.h"
                0226 # endif
                0227 # ifdef ALLOW_TIMEAVE
                0228 #  include "TIMEAVE_STATV.h"
                0229 # endif
                0230 # ifdef ALLOW_EXF
                0231 #  include "EXF_PARAM.h"
                0232 #  include "EXF_INTERP_PARAM.h"
                0233 # endif
                0234 # ifdef ALLOW_DOWN_SLOPE
                0235 #  include "DWNSLP_SIZE.h"
                0236 #  include "DWNSLP_VARS.h"
                0237 # endif
                0238 # ifdef ALLOW_PTRACERS
                0239 #  include "PTRACERS_PARAMS.h"
                0240 # endif
                0241 #endif /* ALLOW_TAPENADE */
                0242 
39154404ca Patr*0243 c**************************************
2cfc9d59a2 Patr*0244 
9366854e02 Chri*0245 C     !INPUT/OUTPUT PARAMETERS:
                0246 C     == Routine arguments ==
22b72941c7 Jean*0247 C     note: under the multi-threaded model myIter and
                0248 C           myTime are local variables passed around as routine
88794ad36d Jean*0249 C           arguments. Although this is fiddly it saves the need to
                0250 C           impose additional synchronisation points when they are
9366854e02 Chri*0251 C           updated.
8440e8ae5d Jean*0252 C     myTime :: time counter for this thread
                0253 C     myIter :: iteration counter for this thread
                0254 C     myThid :: thread number for this instance of the routine.
9366854e02 Chri*0255       _RL     myTime
8440e8ae5d Jean*0256       INTEGER myIter
88794ad36d Jean*0257       INTEGER myThid
9366854e02 Chri*0258 
1eeb28fe07 Alis*0259 C     !FUNCTIONS:
                0260 C     == Functions ==
                0261 
9366854e02 Chri*0262 C     !LOCAL VARIABLES:
                0263 C     == Local variables ==
e5d0e61ee8 Patr*0264       INTEGER iloop
d5885b3057 Jean*0265 #ifdef STORE_LOADEDREC_TEST
                0266       INTEGER bi,bj
                0267 #endif /* STORE_LOADEDREC_TEST */
cda1c18f72 Jean*0268 #ifdef ALLOW_AUTODIFF
                0269 # ifdef ALLOW_TAMC_CHECKPOINTING
7c50f07931 Mart*0270       INTEGER ilev_1
20dee61641 Mart*0271       INTEGER ilev_2, max_lev2
cda1c18f72 Jean*0272 #  ifndef AUTODIFF_2_LEVEL_CHECKPOINT
20dee61641 Mart*0273       INTEGER ilev_3, max_lev3
7c50f07931 Mart*0274 #  endif
cda1c18f72 Jean*0275 #  ifdef AUTODIFF_4_LEVEL_CHECKPOINT
20dee61641 Mart*0276       INTEGER ilev_4, max_lev4
cda1c18f72 Jean*0277 #  endif
                0278 # endif /* ALLOW_TAMC_CHECKPOINTING */
                0279 #endif /* ALLOW_AUTODIFF */
9366854e02 Chri*0280 CEOP
2846da876f Alis*0281 
49e3578e36 Ed H*0282 #ifdef ALLOW_DEBUG
73ead277e0 Alis*0283       IF (debugMode) CALL DEBUG_ENTER('THE_MAIN_LOOP',myThid)
                0284 #endif
                0285 
2cfc9d59a2 Patr*0286 #ifdef ALLOW_AUTODIFF_TAMC
                0287 c--   Initialize storage for the cost function evaluation.
7855a13227 Mart*0288 c---------------------------------------------------------
                0289 c--   Initialize storage for the initialisation phase.
910e5c3e29 Mart*0290 # if ( defined ALLOW_AUTODIFF_WHTAPEIO && !defined ALLOW_DIVIDED_ADJOINT )
7855a13227 Mart*0291 CADJ INIT tapelev_init       = COMMON, 1
31dc1201f0 Jean*0292 # else
7855a13227 Mart*0293 CADJ INIT tapelev_init       = USER
31dc1201f0 Jean*0294 # endif
7855a13227 Mart*0295 c--   this tape is never used
                0296 cCADJ INIT tapelev_ini_bibj   = USER
51575f66de Mart*0297 # ifdef INCLUDE_CONVECT_INI_CALL
7855a13227 Mart*0298 c--   currently only used in convective_adjustement_ini.F
910e5c3e29 Mart*0299 #  if ( defined ALLOW_AUTODIFF_WHTAPEIO && !defined ALLOW_DIVIDED_ADJOINT )
20dee61641 Mart*0300 CADJ INIT tapelev_ini_bibj_k = COMMON, nSx*nSy*Nr
910e5c3e29 Mart*0301 #  else
                0302 CADJ INIT tapelev_ini_bibj_k = USER
                0303 #  endif
51575f66de Mart*0304 # endif
7448700841 Mart*0305 # ifdef ALLOW_GENTIM2D_CONTROL
7855a13227 Mart*0306 c--   exclusive tape for variables with suffix "_dummy"
                0307 CADJ INIT dummytape          = COMMON, 1
e1de04fee5 Patr*0308 # endif
31dc1201f0 Jean*0309 
7855a13227 Mart*0310 c--   Initialize storage for the outermost loop.
e1de04fee5 Patr*0311 # ifdef ALLOW_TAMC_CHECKPOINTING
                0312 #  if (defined (AUTODIFF_2_LEVEL_CHECKPOINT))
3b6c79e4de Mart*0313 CADJ  INIT tapelev2 = USER
                0314 CADJ  INIT tapelvi2 = USER,'adi'
e1de04fee5 Patr*0315 #  elif (defined (AUTODIFF_4_LEVEL_CHECKPOINT))
3b6c79e4de Mart*0316 CADJ  INIT tapelev4 = USER
                0317 CADJ  INIT tapelvi4 = USER,'adi'
e1de04fee5 Patr*0318 #  else
3b6c79e4de Mart*0319 CADJ  INIT tapelev3 = USER
                0320 CADJ  INIT tapelvi3 = USER,'adi'
e1de04fee5 Patr*0321 #  endif
ded033bbc1 Patr*0322 # endif
31dc1201f0 Jean*0323 #endif /* ALLOW_AUTODIFF_TAMC */
620589f74d Patr*0324 
71d68194c9 Patr*0325 #ifdef ALLOW_AUTODIFF
51d88069bf Jean*0326       nIter0 = NINT( (startTime-baseTime)/deltaTClock )
0097108a55 Alis*0327 #endif
2846da876f Alis*0328 
cdc9f269ae Patr*0329 #ifdef ALLOW_AUTODIFF_TAMC
7c50f07931 Mart*0330       ikey_dynamics = 1
910e5c3e29 Mart*0331 # if ( defined ALLOW_AUTODIFF_WHTAPEIO && defined ALLOW_DIVIDED_ADJOINT )
                0332 C     this needs to happen before any store directive to taplev_init
                0333       CALL AUTODIFF_WHTAPEIO_SYNC( 1 , 0, myThid )
                0334 # endif
3bafcf6020 Timo*0335 # ifdef ALLOW_GENTIM2D_CONTROL
                0336 CADJ STORE xx_gentim2d_dummy = dummytape, key = 1 , kind = isbyte
                0337 # endif
                0338 # ifdef ALLOW_SHELFICE
c69ccc91fb antn*0339 CADJ STORE shelficeLoadAnomaly = tapelev_init, key=1, kind=isbyte
7b8b86ab99 Timo*0340 # endif
3bafcf6020 Timo*0341 # ifdef ALLOW_STREAMICE
96b006450c dngo*0342 CADJ STORE H_streamice              = tapelev_init, key=1
                0343 CADJ STORE B_glen                   = tapelev_init, key=1
                0344 CADJ STORE bdot_streamice           = tapelev_init, key=1
                0345 CADJ STORE c_basal_friction         = tapelev_init, key=1
                0346 CADJ STORE streamice_bdot_maxmelt_v = tapelev_init, key=1
                0347 #  ifdef USE_ALT_RLOW
                0348 CADJ STORE r_low_si                 = tapelev_init, key=1
                0349 #  endif
a78204c019 Mart*0350 # endif
11c3150c71 Mart*0351 # ifdef ALLOW_DIC
                0352 CADJ STORE co2atmos = tapelev_init, key = 1
                0353 CADJ STORE alpha    = tapelev_init, key = 1
                0354 # endif
cdc9f269ae Patr*0355 #endif
                0356 
c10ffac493 Jean*0357 #ifdef ALLOW_OPENAD
707ab205a2 Patr*0358 # ifdef ALLOW_GENARR2D_CONTROL
57b21c88e4 Patr*0359 cphc$openad INDEPENDENT(xx_genarr2d)
fffd070878 Patr*0360 c$openad INDEPENDENT(xx_genarr2d_dummy)
707ab205a2 Patr*0361 # endif
                0362 # ifdef ALLOW_GENARR3D_CONTROL
57b21c88e4 Patr*0363 cphc$openad INDEPENDENT(xx_genarr3d)
                0364 c$openad INDEPENDENT(xx_genarr3d_dummy)
707ab205a2 Patr*0365 # endif
81a1cb3057 Patr*0366 # ifdef ALLOW_GENTIM2D_CONTROL
57b21c88e4 Patr*0367 cphc$openad INDEPENDENT(xx_gentim2d)
1a5e3fa960 Patr*0368 c$openad INDEPENDENT(xx_gentim2d_dummy)
81a1cb3057 Patr*0369 # endif
c10ffac493 Jean*0370 #endif /* ALLOW_OPENAD */
71d68194c9 Patr*0371 
49e3578e36 Ed H*0372 #ifdef ALLOW_DEBUG
73ead277e0 Alis*0373       IF (debugMode) CALL DEBUG_CALL('INITIALISE_VARIA',myThid)
                0374 #endif
2846da876f Alis*0375 C--   Set initial conditions (variable arrays)
22b72941c7 Jean*0376       CALL TIMER_START('INITIALISE_VARIA    [THE_MAIN_LOOP]', myThid)
                0377       CALL INITIALISE_VARIA( myThid )
                0378       CALL TIMER_STOP ('INITIALISE_VARIA    [THE_MAIN_LOOP]', myThid)
2cfc9d59a2 Patr*0379 
12dfc08227 Patr*0380 #ifdef ALLOW_SHOWFLOPS
22b72941c7 Jean*0381       CALL TIMER_START('SHOWFLOPS_INIT      [THE_MAIN_LOOP]', myThid)
ded033bbc1 Patr*0382       CALL SHOWFLOPS_INIT( myThid )
22b72941c7 Jean*0383       CALL TIMER_STOP ('SHOWFLOPS_INIT      [THE_MAIN_LOOP]', myThid)
008ba3ca0d Cons*0384 #endif
ce86d9b87b Cons*0385 
2cfc9d59a2 Patr*0386 c--   Do the model integration.
22b72941c7 Jean*0387       CALL TIMER_START('MAIN LOOP           [THE_MAIN_LOOP]', myThid)
2cfc9d59a2 Patr*0388 
                0389 c     >>>>>>>>>>>>>>>>>>>>>>>>>>>   LOOP   <<<<<<<<<<<<<<<<<<<<<<<<<<<<
                0390 c     >>>>>>>>>>>>>>>>>>>>>>>>>>>  STARTS  <<<<<<<<<<<<<<<<<<<<<<<<<<<<
                0391 
5586314dc5 Mart*0392 #ifdef USE_PDAF
                0393 c     Initialize PDAF
                0394       CALL TIMER_START('INIT_PDAF           [THE_MAIN_LOOP]', myThid)
                0395       CALL INIT_PDAF( nIter0, myTime, myIter, myThid )
                0396       CALL TIMER_STOP ('INIT_PDAF           [THE_MAIN_LOOP]', myThid)
                0397 #endif
                0398 
910e5c3e29 Mart*0399 #if ( defined ALLOW_AUTODIFF_WHTAPEIO && defined ALLOW_DIVIDED_ADJOINT )
                0400 C     end of initialisation and use of tapelev_init: write buffer to disk
                0401       CALL AUTODIFF_WHTAPEIO_SYNC( 1 , 1, myThid )
                0402 #endif
                0403 
e5d0e61ee8 Patr*0404 c++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
c10ffac493 Jean*0405 #ifndef ALLOW_OPENAD
e5d0e61ee8 Patr*0406 # ifdef ALLOW_AUTODIFF
                0407 #  ifdef ALLOW_TAMC_CHECKPOINTING
                0408 c++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                0409 
20dee61641 Mart*0410 #   ifdef AUTODIFF_4_LEVEL_CHECKPOINT
e5d0e61ee8 Patr*0411       max_lev4=nTimeSteps/(nchklev_1*nchklev_2*nchklev_3)+1
20dee61641 Mart*0412 #   endif
                0413 #   ifndef AUTODIFF_2_LEVEL_CHECKPOINT
e5d0e61ee8 Patr*0414       max_lev3=nTimeSteps/(nchklev_1*nchklev_2)+1
20dee61641 Mart*0415 #   endif
e5d0e61ee8 Patr*0416       max_lev2=nTimeSteps/nchklev_1+1
                0417 
                0418 c**************************************
                0419 #   ifdef ALLOW_DIVIDED_ADJOINT
                0420 CADJ loop = divided
                0421 #   endif
                0422 c**************************************
                0423 
                0424 #   ifdef AUTODIFF_4_LEVEL_CHECKPOINT
                0425       do ilev_4 = 1,nchklev_4
                0426          if(ilev_4.le.max_lev4) then
                0427 c**************************************
cda1c18f72 Jean*0428 #    ifdef ALLOW_AUTODIFF_WHTAPEIO
22b72941c7 Jean*0429             CALL AUTODIFF_WHTAPEIO_SYNC( 4 , 0, myThid )
cda1c18f72 Jean*0430 #    endif
e5d0e61ee8 Patr*0431             CALL AUTODIFF_STORE( myThid )
                0432 #include "checkpoint_lev4_directives.h"
                0433             CALL AUTODIFF_RESTORE( myThid )
cda1c18f72 Jean*0434 #    ifdef ALLOW_AUTODIFF_WHTAPEIO
22b72941c7 Jean*0435             CALL AUTODIFF_WHTAPEIO_SYNC( 4 , 1, myThid )
cda1c18f72 Jean*0436 #    endif
e5d0e61ee8 Patr*0437 c**************************************
                0438 c--     Initialise storage for the middle loop.
                0439 CADJ    INIT tapelev3 = USER
3b6c79e4de Mart*0440 CADJ    INIT tapelvi3 = USER,'adi'
e5d0e61ee8 Patr*0441 #   endif /* AUTODIFF_4_LEVEL_CHECKPOINT */
                0442 
                0443 #   ifndef AUTODIFF_2_LEVEL_CHECKPOINT
                0444       do ilev_3 = 1,nchklev_3
                0445          if(ilev_3.le.max_lev3) then
                0446 c**************************************
cda1c18f72 Jean*0447 #    ifdef ALLOW_AUTODIFF_WHTAPEIO
22b72941c7 Jean*0448             CALL AUTODIFF_WHTAPEIO_SYNC( 3 , 0, myThid )
cda1c18f72 Jean*0449 #    endif
e5d0e61ee8 Patr*0450             CALL AUTODIFF_STORE( myThid )
                0451 #include "checkpoint_lev3_directives.h"
                0452             CALL AUTODIFF_RESTORE( myThid )
cda1c18f72 Jean*0453 #    ifdef ALLOW_AUTODIFF_WHTAPEIO
22b72941c7 Jean*0454             CALL AUTODIFF_WHTAPEIO_SYNC( 3 , 1, myThid )
cda1c18f72 Jean*0455 #    endif
e5d0e61ee8 Patr*0456 c**************************************
                0457 c--     Initialise storage for the middle loop.
                0458 CADJ    INIT tapelev2 = USER
3b6c79e4de Mart*0459 CADJ    INIT tapelvi2 = USER,'adi'
e5d0e61ee8 Patr*0460 #   endif /* AUTODIFF_2_LEVEL_CHECKPOINT */
                0461 
                0462         do ilev_2 = 1,nchklev_2
                0463          if(ilev_2.le.max_lev2) then
                0464 c**************************************
cda1c18f72 Jean*0465 #   ifdef ALLOW_AUTODIFF_WHTAPEIO
22b72941c7 Jean*0466             CALL AUTODIFF_WHTAPEIO_SYNC( 2 , 0, myThid )
cda1c18f72 Jean*0467 #   endif
e5d0e61ee8 Patr*0468             CALL AUTODIFF_STORE( myThid )
                0469 #include "checkpoint_lev2_directives.h"
                0470             CALL AUTODIFF_RESTORE( myThid )
cda1c18f72 Jean*0471 #   ifdef ALLOW_AUTODIFF_WHTAPEIO
22b72941c7 Jean*0472             CALL AUTODIFF_WHTAPEIO_SYNC( 2 , 1, myThid )
cda1c18f72 Jean*0473 #   endif
e5d0e61ee8 Patr*0474 c**************************************
                0475 
cda1c18f72 Jean*0476 #  endif /* ALLOW_TAMC_CHECKPOINTING */
e5d0e61ee8 Patr*0477 
cda1c18f72 Jean*0478 #  ifdef ALLOW_AUTODIFF_TAMC
e5d0e61ee8 Patr*0479 c**************************************
                0480 c--       Initialize storage for the innermost loop.
                0481 c--       Always check common block sizes for the checkpointing!
                0482 c--
                0483 CADJ INIT comlev1        = COMMON,nchklev_1
20dee61641 Mart*0484 CADJ INIT comlev1_bibj   = COMMON,nchklev_1*nSx*nSy
                0485 CADJ INIT comlev1_bibj_k = COMMON,nchklev_1*nSx*nSy*Nr
fe1862e69b Mart*0486 #   ifdef ALLOW_BLING
                0487 CADJ INIT comlev1_bibj_ijk = COMMON,
20dee61641 Mart*0488 CADJ &    nchklev_1*nSx*nSy*Nr*(2*OLy+sNy)*(2*OLx+sNx)
fe1862e69b Mart*0489 #   endif
e5d0e61ee8 Patr*0490 c--
                0491 #   ifdef ALLOW_KPP
31dc1201f0 Jean*0492 CADJ INIT comlev1_kpp    = COMMON,nchklev_1*nSx*nSy
                0493 CADJ INIT comlev1_kpp_k  = COMMON,nchklev_1*nSx*nSy*Nr
e5d0e61ee8 Patr*0494 #   endif /* ALLOW_KPP */
                0495 c--
                0496 #   ifdef ALLOW_GMREDI
20dee61641 Mart*0497 CADJ INIT comlev1_gmredi_k_gad = COMMON,nchklev_1*nSx*nSy*Nr*maxpass
5a6997640b Mart*0498 cCADJ INIT comlev1_gmredi_slope = COMMON,nchklev_1*nSx*nSy*Nr*3
e5d0e61ee8 Patr*0499 #   endif /* ALLOW_GMREDI */
                0500 c--
                0501 #   ifdef ALLOW_PTRACERS
                0502 CADJ INIT comlev1_bibj_ptracers = COMMON,
20dee61641 Mart*0503 CADJ &    nchklev_1*nSx*nSy*PTRACERS_num
e5d0e61ee8 Patr*0504 CADJ INIT comlev1_bibj_k_ptracers = COMMON,
20dee61641 Mart*0505 CADJ &    nchklev_1*nSx*nSy*PTRACERS_num*Nr
e5d0e61ee8 Patr*0506 #   endif /* ALLOW_PTRACERS */
                0507 c--
                0508 #   ifdef ALLOW_MOM_COMMON
                0509 #   ifndef AUTODIFF_DISABLE_LEITH
                0510 CADJ INIT comlev1_mom_ijk_loop
20dee61641 Mart*0511 CADJ &     = COMMON,nchklev_1*(sNx+2*OLx)*nSx*(sNy+2*OLy)*nSy*Nr
e5d0e61ee8 Patr*0512 #   endif /* AUTODIFF_DISABLE_LEITH */
                0513 #   endif /* ALLOW_MOM_COMMON */
                0514 c--
9c41af81f6 Timo*0515 #   if (defined ALLOW_EXF && defined ALLOW_BULKFORMULAE)
20dee61641 Mart*0516 CADJ INIT comlev1_exf_1 = COMMON,nchklev_1*sNx*nSx*sNy*nSy
                0517 CADJ INIT comlev1_exf_2 = COMMON,niter_bulk*nchklev_1*sNx*nSx*sNy*nSy
e5d0e61ee8 Patr*0518 #   endif /* ALLOW_BULKFORMULAE */
                0519 c--
                0520 #   ifdef ALLOW_SEAICE
45315406aa Mart*0521 #    ifdef SEAICE_CGRID
e5d0e61ee8 Patr*0522 CADJ INIT comlev1_dynsol = COMMON,nchklev_1*MPSEUDOTIMESTEPS
5c9256813c Mart*0523 #     ifdef SEAICE_LSR_ADJOINT_ITER
                0524 CADJ INIT comlev1_lsr = COMMON,nchklev_1*MPSEUDOTIMESTEPS*SOLV_MAX_FIXED
                0525 CADJ INIT comlev1_bibj_lsr = COMMON,
20dee61641 Mart*0526 CADJ &  nchklev_1*nSx*nSy*MPSEUDOTIMESTEPS*SOLV_MAX_FIXED
5c9256813c Mart*0527 #     else /* make the common blocks smaller to reduce memory footprint */
20dee61641 Mart*0528 CADJ INIT comlev1_lsr      = COMMON,        nchklev_1*MPSEUDOTIMESTEPS
                0529 CADJ INIT comlev1_bibj_lsr = COMMON,nSx*nSy*nchklev_1*MPSEUDOTIMESTEPS
5c9256813c Mart*0530 #     endif
7448700841 Mart*0531 #     ifdef SEAICE_ALLOW_EVP
20dee61641 Mart*0532 CADJ INIT comlev1_evp      = COMMON,        nEVPstepMax*nchklev_1
                0533 CADJ INIT comlev1_bibj_evp = COMMON,nSx*nSy*nEVPstepMax*nchklev_1
7448700841 Mart*0534 #     endif
5c9256813c Mart*0535 #    endif
dacfc8921c Mart*0536 CML#   ifdef SEAICE_MULTICATEGORY
20dee61641 Mart*0537 CMLCADJ INIT comlev1_multdim = COMMON,nchklev_1*nSx*nSy*nitd
dacfc8921c Mart*0538 CML#   endif
e5d0e61ee8 Patr*0539 #    ifndef DISABLE_MULTIDIM_ADVECTION
                0540 CADJ INIT comlev1_bibj_k_gadice = COMMON,
20dee61641 Mart*0541 CADJ &    nchklev_1*nSx*nSy*maxpass
e5d0e61ee8 Patr*0542 CADJ INIT comlev1_bibj_k_gadice_pass = COMMON,
20dee61641 Mart*0543 CADJ &    nchklev_1*nSx*nSy*maxpass*maxcube
e5d0e61ee8 Patr*0544 #    endif /* DISABLE_MULTIDIM_ADVECTION */
cda1c18f72 Jean*0545 #   endif /* ALLOW_SEAICE */
e5d0e61ee8 Patr*0546 c--
                0547 #   ifdef ALLOW_THSICE
a85293d087 Mart*0548 C     Tape for thsice_advection, which is called for thSIce_nAdv (=5)
                0549 C     different variables (thSIce_nAdv is set in THSICE_SIZE.h)
edb6656069 Mart*0550 CADJ INIT comlev1_thsice_adv  = COMMON,
20dee61641 Mart*0551 CADJ &    nchklev_1*nSx*nSy*maxcube*thSIce_nAdv
                0552 CADJ INIT comlev1_thsice_nlyr = COMMON,nchklev_1*nSx*nSy*nlyr
edb6656069 Mart*0553 CADJ INIT comlev1_thsice_s4t  = COMMON,nchklev_1*nSx*nSy*MaxTsf
cda1c18f72 Jean*0554 #    if (defined ALLOW_EXF && defined ALLOW_BULKFORMULAE)
edb6656069 Mart*0555 C     These tapes are only used within thsice_get_exf.F
                0556 CADJ INIT comlev1_thsice_exf       = COMMON,
                0557 CADJ &    nchklev_1*nSx*nSy*(MaxTsf+1)
a85293d087 Mart*0558 CADJ INIT comlev1_thsice_exf_niter = COMMON,
edb6656069 Mart*0559 CADJ &    nchklev_1*nSx*nSy*(MaxTsf+1)*niter_bulk
                0560 CADJ INIT comlev1_thsice_exf_ij    = COMMON,
                0561 CADJ &    nchklev_1*nSx*nSy*(MaxTsf+1)*niter_bulk*sNx*sNy
cda1c18f72 Jean*0562 #    endif
e5d0e61ee8 Patr*0563 #   endif /* ALLOW_THSICE */
                0564 c--
00f81e6785 Ou W*0565 #   ifdef ALLOW_STEEP_ICECAVITY
                0566 CADJ INIT comlev1_stic_bibj_ijk = COMMON,
                0567 CADJ &    nchklev_1*nSx*nSy*Nr*(2*OLy+sNy)*(2*OLx+sNx)
                0568 #   endif
                0569 c--
e5d0e61ee8 Patr*0570 #   ifdef ALLOW_STREAMICE
20dee61641 Mart*0571 CADJ INIT comlev1_stream_nl    = COMMON,nchklev_1*streamice_max_nl
e5d0e61ee8 Patr*0572 CADJ INIT comlev1_stream_front = COMMON,nchklev_1*4
                0573 CADJ INIT comlev1_stream_ij
31dc1201f0 Jean*0574 CADJ &     = COMMON,nchklev_1*4*(sNx+2)*nSx*(sNy+2)*nSy
20dee61641 Mart*0575 CADJ INIT comlev1_stream_hybrid = COMMON,nchklev_1*sNx*nSx*sNy*nSy*Nr
e5d0e61ee8 Patr*0576 #   endif
                0577 c--
                0578 #   ifdef ALLOW_CG2D_NSA
20dee61641 Mart*0579 CADJ INIT comlev1_cg2d      = COMMON,nchklev_1
                0580 CADJ INIT comlev1_cg2d_iter = COMMON,nchklev_1*numItersMax
e5d0e61ee8 Patr*0581 #   endif
cda1c18f72 Jean*0582 #  endif /* ALLOW_AUTODIFF_TAMC */
e5d0e61ee8 Patr*0583 c--
35c4fdc74b Emma*0584 #  ifdef ALLOW_GENCOST_CONTRIBUTION
                0585 CADJ INIT comlev1_ngencost = COMMON,nchklev_1*NGENCOST
                0586 #  endif
e5d0e61ee8 Patr*0587 c**************************************
                0588 
cda1c18f72 Jean*0589 #  ifdef STORE_LOADEDREC_TEST
d5885b3057 Jean*0590           DO bj = myByLo(myThid), myByHi(myThid)
                0591            DO bi = myBxLo(myThid), myBxHi(myThid)
                0592             loadedRec(bi,bj) = 0
                0593            ENDDO
                0594           ENDDO
cda1c18f72 Jean*0595 #  endif /* STORE_LOADEDREC_TEST */
d5885b3057 Jean*0596 
cda1c18f72 Jean*0597 #  if ( defined ALLOW_AUTODIFF_TAMC && defined ALLOW_OFFLINE )
3c775cbf98 Mart*0598 C     The following statement forces TAF to store wVel correctly in some
                0599 C     outer checkpoint levels in some cases when it does not do it
                0600 C     automatically (similar to TICES in seaice_reg_ridge.F). This is a
                0601 C     TAF bug and this statement can probably be removed again, once
                0602 C     this bug is fixed (but it does not hurt, either).
cda1c18f72 Jean*0603 #   ifndef AUTODIFF_USE_STORE_RESTORE
3c775cbf98 Mart*0604 CADJ INCOMPLETE wVel
cda1c18f72 Jean*0605 #   endif
                0606 #  endif
                0607 #  ifdef ALLOW_TAMC_CHECKPOINTING
e5d0e61ee8 Patr*0608 
                0609           do ilev_1 = 1,nchklev_1
                0610 
                0611 c--         The if-statement below introduces a some flexibility in the
                0612 c--         choice of the 3-tupel ( nchklev_1, nchklev_2, nchklev_3 ).
                0613 
                0614             iloop = (ilev_2 - 1)*nchklev_1 + ilev_1
cda1c18f72 Jean*0615 #   ifndef AUTODIFF_2_LEVEL_CHECKPOINT
e5d0e61ee8 Patr*0616      &            + (ilev_3 - 1)*nchklev_2*nchklev_1
cda1c18f72 Jean*0617 #   endif
                0618 #   ifdef AUTODIFF_4_LEVEL_CHECKPOINT
e5d0e61ee8 Patr*0619      &            + (ilev_4 - 1)*nchklev_3*nchklev_2*nchklev_1
cda1c18f72 Jean*0620 #   endif
e5d0e61ee8 Patr*0621 
                0622             if ( iloop .le. nTimeSteps ) then
                0623 
                0624 #  else /* ALLOW_TAMC_CHECKPOINTING  undefined */
                0625 
                0626       DO iloop = 1, nTimeSteps
                0627 
                0628 c++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                0629 #  endif /* ALLOW_TAMC_CHECKPOINTING */
                0630 # endif /* ALLOW_AUTODIFF */
c10ffac493 Jean*0631 #endif /* undef ALLOW_OPENAD */
e5d0e61ee8 Patr*0632 c++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                0633 
                0634 #ifndef ALLOW_AUTODIFF
                0635       DO iloop = 1, nTimeSteps
                0636 #endif /* ALLOW_AUTODIFF */
                0637 
                0638 c--     >>> Loop body start <<<
                0639 
c10ffac493 Jean*0640 #ifdef ALLOW_AUTODIFF
e5d0e61ee8 Patr*0641       nIter0 = NINT( (startTime-baseTime)/deltaTClock )
                0642 C--   Reset the model iteration counter and the model time.
                0643       myIter = nIter0 + (iloop-1)
7c3b863339 Jean*0644       myTime = startTime + deltaTClock*(iloop-1)
7c50f07931 Mart*0645 # ifdef ALLOW_AUTODIFF_TAMC
20dee61641 Mart*0646 #  ifdef ALLOW_TAMC_CHECKPOINTING
e5d0e61ee8 Patr*0647       ikey_dynamics = ilev_1
20dee61641 Mart*0648 #  else
                0649       ikey_dynamics = iloop
                0650 #  endif
e5d0e61ee8 Patr*0651 # endif
20dee61641 Mart*0652 #endif /* ALLOW_AUTODIFF */
e5d0e61ee8 Patr*0653 
ac03b700cb Gael*0654 #ifdef ALLOW_ECCO
a424c359ed Gael*0655       IF ( useECCO ) then
e5d0e61ee8 Patr*0656 # ifdef ALLOW_DEBUG
a424c359ed Gael*0657         IF (debugMode) CALL DEBUG_CALL('cost_averagesfields',myThid)
e5d0e61ee8 Patr*0658 # endif
                0659 c--   Accumulate time averages of temperature, salinity
a424c359ed Gael*0660         CALL TIMER_START('COST_AVERAGESFIELDS [MAIN_DO_LOOP]',myThid)
                0661         CALL COST_AVERAGESFIELDS( myTime, myThid )
                0662         CALL TIMER_STOP ('COST_AVERAGESFIELDS [MAIN_DO_LOOP]',myThid)
                0663       ENDIF
ac03b700cb Gael*0664 #endif /* ALLOW_ECCO */
e5d0e61ee8 Patr*0665 
                0666 #ifdef ALLOW_PROFILES
                0667       IF (usePROFILES) THEN
                0668 #ifdef ALLOW_DEBUG
                0669         IF (debugMode) CALL DEBUG_CALL('profiles_inloop',myThid)
                0670 #endif
                0671 c--     Accumulate in-situ time averages of theta, salt, and SSH.
                0672 #ifdef ALLOW_AUTODIFF
                0673 C--   Reset the model iteration counter and the model time.
                0674         myIter = nIter0 + (iloop-1)
7c3b863339 Jean*0675         myTime = startTime + deltaTClock*(iloop-1)
e5d0e61ee8 Patr*0676 #endif
22b72941c7 Jean*0677         CALL TIMER_START('PROFILES_INLOOP    [MAIN_DO_LOOP]', myThid)
                0678         CALL PROFILES_INLOOP( myTime, myThid )
                0679         CALL TIMER_STOP ('PROFILES_INLOOP    [MAIN_DO_LOOP]', myThid)
e5d0e61ee8 Patr*0680       ENDIF
                0681 #endif
                0682 
22b72941c7 Jean*0683       CALL TIMER_START('MAIN_DO_LOOP        [THE_MAIN_LOOP]', myThid)
e5d0e61ee8 Patr*0684       CALL MAIN_DO_LOOP( iloop, myTime, myIter, myThid )
22b72941c7 Jean*0685       CALL TIMER_STOP ('MAIN_DO_LOOP        [THE_MAIN_LOOP]', myThid)
2cfc9d59a2 Patr*0686 
5586314dc5 Mart*0687 #ifdef USE_PDAF
                0688 C     PDAF analysis step
                0689       CALL TIMER_START('ASSIMILATE_PDAF     [THE_MAIN_LOOP]', myThid)
                0690       CALL ASSIMILATE_PDAF( myTime, myIter, myThid )
                0691       CALL TIMER_STOP ('ASSIMILATE_PDAF     [THE_MAIN_LOOP]', myThid)
                0692 #endif
                0693 
e5d0e61ee8 Patr*0694 c--     >>> Loop body end <<<
c10ffac493 Jean*0695 #ifndef ALLOW_OPENAD
e5d0e61ee8 Patr*0696 # ifdef ALLOW_AUTODIFF
                0697 #   ifdef ALLOW_TAMC_CHECKPOINTING
                0698             endif
                0699           enddo
                0700           endif
                0701         enddo
                0702 #    ifndef AUTODIFF_2_LEVEL_CHECKPOINT
                0703         endif
                0704       enddo
                0705 #    endif
                0706 #    ifdef AUTODIFF_4_LEVEL_CHECKPOINT
                0707        endif
                0708       enddo
                0709 #    endif
                0710 #   else /* ndef ALLOW_TAMC_CHECKPOINTING */
                0711       ENDDO
                0712 #   endif /* ALLOW_TAMC_CHECKPOINTING */
                0713 # else /* ALLOW_AUTODIFF */
                0714       ENDDO
                0715 # endif /* ALLOW_AUTODIFF */
c10ffac493 Jean*0716 #endif /* undef ALLOW_OPENAD */
e5d0e61ee8 Patr*0717 
01070dbc48 Patr*0718 c     >>>>>>>>>>>>>>>>>>>>>>>>>>>   LOOP   <<<<<<<<<<<<<<<<<<<<<<<<<<<<
                0719 c     >>>>>>>>>>>>>>>>>>>>>>>>>>>  STOPS   <<<<<<<<<<<<<<<<<<<<<<<<<<<<
2cfc9d59a2 Patr*0720 
19f2597004 Gael*0721 #ifdef ALLOW_ECCO
345f7357c1 Gael*0722 c--     Accumulate time averages of temperature, salinity
22b72941c7 Jean*0723       CALL TIMER_START('COST_AVERAGESFIELDS [THE_MAIN_LOOP]',myThid)
                0724       CALL COST_AVERAGESFIELDS( endtime, myThid )
                0725       CALL TIMER_STOP ('COST_AVERAGESFIELDS [THE_MAIN_LOOP]',myThid)
19f2597004 Gael*0726 #endif /* ALLOW_ECCO */
345f7357c1 Gael*0727 
24462d2fa8 Patr*0728 #ifdef ALLOW_PROFILES
e994210c2e Gael*0729       IF (usePROFILES) THEN
ded033bbc1 Patr*0730 c--   Accumulate in-situ time averages of temperature, salinity, SSH.
22b72941c7 Jean*0731         CALL TIMER_START('PROFILES_INLOOP    [THE_MAIN_LOOP]', myThid)
                0732         CALL PROFILES_INLOOP( endtime, myThid )
                0733         CALL TIMER_STOP ('PROFILES_INLOOP    [THE_MAIN_LOOP]', myThid)
f29c9a8cb9 Gael*0734 c--   Compute all profiles cost function contributions.
7c3b863339 Jean*0735         CALL COST_PROFILES( myIter, myTime, myThid )
e994210c2e Gael*0736       ENDIF
24462d2fa8 Patr*0737 #endif
                0738 
19f2597004 Gael*0739 #ifdef ALLOW_ECCO
a424c359ed Gael*0740       IF ( useECCO ) then
345f7357c1 Gael*0741 c--   Compute all ecco cost function contributions.
a424c359ed Gael*0742         CALL TIMER_START('ECCO_COST_DRIVER   [THE_MAIN_LOOP]', myThid)
                0743         CALL ECCO_COST_DRIVER ( endTime, myIter, myThid )
                0744         CALL TIMER_STOP ('ECCO_COST_DRIVER   [THE_MAIN_LOOP]', myThid)
                0745       ENDIF
19f2597004 Gael*0746 #endif /* ALLOW_ECCO */
345f7357c1 Gael*0747 
ad9b3080a0 Patr*0748 #ifdef ALLOW_COST
                0749 c--   Sum all cost function contributions.
22b72941c7 Jean*0750       CALL TIMER_START('COST_FINAL         [ADJOINT SPIN-DOWN]', myThid)
                0751       CALL COST_FINAL ( myThid )
                0752       CALL TIMER_STOP ('COST_FINAL         [ADJOINT SPIN-DOWN]', myThid)
ad9b3080a0 Patr*0753 
c10ffac493 Jean*0754 # ifdef ALLOW_OPENAD
ded033bbc1 Patr*0755 c$openad DEPENDENT(fc)
c10ffac493 Jean*0756 # endif /* ALLOW_OPENAD */
71d68194c9 Patr*0757 
                0758 #endif /* ALLOW_COST */
ded033bbc1 Patr*0759 
16367ff26d Mart*0760 #ifdef USE_PDAF
                0761 C     PDAF finalization
                0762       CALL FINALIZE_PDAF( )
                0763 #endif
                0764 
2cfc9d59a2 Patr*0765       _BARRIER
22b72941c7 Jean*0766       CALL TIMER_STOP ('MAIN LOOP           [THE_MAIN_LOOP]', myThid)
2cfc9d59a2 Patr*0767 
49e3578e36 Ed H*0768 #ifdef ALLOW_DEBUG
73ead277e0 Alis*0769       IF (debugMode) CALL DEBUG_LEAVE('THE_MAIN_LOOP',myThid)
                0770 #endif
                0771 
8440e8ae5d Jean*0772       RETURN
0097108a55 Alis*0773       END