Back to home page

MITgcm

 
 

    


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

view on githubraw file Latest commit 5cf43646 on 2024-03-01 18:50:49 UTC
4c563c2ee9 Chri*0001 CBOI
                0002 C
                0003 C !TITLE: MITGCM KERNEL CODE SYNOPSIS
                0004 C !AUTHORS: mitgcm developers ( support@mitgcm.org )
                0005 C !AFFILIATION: Massachussetts Institute of Technology
                0006 C !DATE:
cfdc763dc5 Alis*0007 C !INTRODUCTION: Kernel dynamical routines
9366854e02 Chri*0008 C This document summarises MITgcm code under the model/ subdirectory.
                0009 C The code under model/ ( src/ and inc/ ) contains most of
                0010 C the driver routines for the baseline forms of the kernel equations in the
                0011 C MITgcm algorithm. Numerical code for much of the baseline forms of
                0012 C these equations is also under the model/ directory. Other numerical code
                0013 C used for the kernel equations is contained in packages in the pkg/
                0014 C directory tree.
c493e58557 Jean*0015 C Code for auxiliary equations and alternate discretizations of the kernel
9366854e02 Chri*0016 C equations and algorithm can also be found in the pkg/ directory tree.
                0017 C
                0018 C \subsection{Getting Help and Reporting Errors and Problems}
c493e58557 Jean*0019 C If you have questions please subscribe and e-mail support@mitgcm.org.
                0020 C We also welcome reports of errors and inconsistencies in the code or
                0021 C in the accompanying documentation. Please feel free to send these
9366854e02 Chri*0022 C to support@mitgcm.org. For further information and to review
                0023 C problems reported to support@mitgcm.org please visit http://mitgcm.org.
                0024 C
                0025 C \subsection{MITgcm Kernel Code Calling Sequence}
                0026 C \bv
                0027 C
                0028 C Invocation from WRAPPER level...
c493e58557 Jean*0029 C
9366854e02 Chri*0030 C  |
                0031 C  |-THE_MODEL_MAIN :: Primary driver for the MITgcm algorithm
                0032 C    |              :: Called from WRAPPER level numerical
639dc32746 Ed H*0033 C    |              :: code invocation routine. On entry
9366854e02 Chri*0034 C    |              :: to THE_MODEL_MAIN separate thread and
                0035 C    |              :: separate processes will have been established.
                0036 C    |              :: Each thread and process will have a unique ID
                0037 C    |              :: but as yet it will not be associated with a
                0038 C    |              :: specific region in decomposed discrete space.
                0039 C    |
b75fe8c753 Jean*0040 C    |-INITIALISE_FIXED :: Set fixed model arrays such as topography,
9366854e02 Chri*0041 C    | |                :: grid, solver matrices etc..
455a90837c Jean*0042 C    | |
9366854e02 Chri*0043 C    | |-INI_PARMS :: Routine to set kernel model parameters.
c493e58557 Jean*0044 C    | |           :: Kernel parameters are read from file "data"
                0045 C    | |           :: in directory in which code executes.
9366854e02 Chri*0046 C    | |
eb9df00f2b Jean*0047 C    | |-PACKAGES_BOOT       :: Start up the optional package environment.
                0048 C    | |                     :: Runtime selection of active packages.
72b199b510 timo*0049 C    | |-CPL_IMPORT_CPLPARMS :: Import coupling parameters from/to
                0050 C    | |                     :: the coupler layer
eb9df00f2b Jean*0051 C    | |-PACKAGES_READPARMS  :: Read each package input parameter file
c493e58557 Jean*0052 C    | | |- ${PKG}_READPARMS
9366854e02 Chri*0053 C    | |
f2f1601bce Jean*0054 C    | |-SET_PARMS :: Finalise model parameter setting (if fct of pkg usage)
9366854e02 Chri*0055 C    | |
f2f1601bce Jean*0056 C    | |-INI_MODEL_IO   :: Initialise Input/Output setting
                0057 C    | |  |-MNC_INIT    :: Initialise MITgcm NetCDF interface (MNC)(see pkg/mnc)
                0058 C    | |  |-MNC_CW_INIT :: Initialise MNC grid and variable types  (see pkg/mnc)
                0059 C    | |  |-MON_INIT    :: Initialises monitor package ( see pkg/monitor )
                0060 C    | |
                0061 C    | |-INI_GRID       :: Control grid array (vert. and horiz.) initialisation.
                0062 C    | | |              :: Grid arrays are held and described in GRID.h.
                0063 C    | | |-LOAD_GRID_SPACING    :: Load grid spacing (vector) from files
                0064 C    | | |-INI_VERTICAL_GRID    :: Set up vertical grid and coordinate
                0065 C    | | |-INI_CARTESIAN_GRID   :: Cartesian horiz. grid initialisation
                0066 C    | | |                      :: (calculate grid from kernel parameters).
                0067 C    | | |-INI_SPHERICAL_POLAR_GRID :: Spherical polar horiz. grid setting
                0068 C    | | |                          :: (calculate grid from kernel parameters).
                0069 C    | | |-INI_CURVILINEAR_GRID :: General orthogonal, structured horiz. grid
                0070 C    | | |                      :: initialisation; input from raw grid files
                0071 C    | | |                      :: (LONC.bin, LATC.bin, DXF.bin, ... ) or per
                0072 C    | | |                      :: face file: horizGridFile(.faceXXX.bin)
                0073 C    | | |-INI_CYLINDER_GRID    :: Cylindrical horiz. grid setting
                0074 C    | |
                0075 C    | |-LOAD_REF_FILES   :: Read-in reference vertical profiles (T,S,Rho)
                0076 C    | |-INI_EOS          :: Initialise Equation Of State (EOS) coefficients
                0077 C    | |-SET_REF_STATE    :: Set reference pressure/geopotential, reference
                0078 C    | |                  :: stratification (for implicit IGW), vertical
                0079 C    | |                  :: velocity scaling factor and anelastic ref. density
                0080 C    | |-SET_GRID_FACTORS :: Set grid factors (fct of k) for deep-atmosphere
9366854e02 Chri*0081 C    | |
c493e58557 Jean*0082 C    | |-INI_DEPTHS    :: Read (from "bathyFile") or set bathymetry/orography.
                0083 C    | |-INI_MASKS_ETC :: Derive horizontal and vertical cell fractions and
                0084 C    | |               :: land masking for solid-fluid boundaries.
9366854e02 Chri*0085 C    | |
c493e58557 Jean*0086 C    | |-PACKAGES_INIT_FIXED  :: do all packages fixed-initialisation setting
                0087 C    | | |- ${PKG}_INIT_FIXED
9366854e02 Chri*0088 C    | |
f2f1601bce Jean*0089 C    | |-INI_GLOBAL_DOMAIN :: Initialise domain related (global) quantities.
                0090 C    | |-INI_LINEAR_PHISURF :: Set ref. surface Bo_surf
                0091 C    | |
                0092 C    | |-INI_CORI          :: Set coriolis term. zero, f-plane, beta-plane,
                0093 C    | |                   :: sphere options are coded.
                0094 C    | |-INI_CG2D          :: 2D conjugate grad solver initialisation.
                0095 C    | |-INI_CG3D          :: 3D conjugate grad solver initialisation.
                0096 C    | |
                0097 C    | |-CONFIG_SUMMARY    :: Provide synopsis of kernel setup. Includes
                0098 C    | |                   :: annotated table of kernel parameter settings.
9366854e02 Chri*0099 C    | |
f2f1601bce Jean*0100 C    | |-PACKAGES_CHECK    :: call each package configuration checking S/R
c493e58557 Jean*0101 C    | | |- ${PKG}_CHECK
9366854e02 Chri*0102 C    | |
f2f1601bce Jean*0103 C    | |-CONFIG_CHECK      :: Check config and parameter consistency.
                0104 C    | |
                0105 C    | |-WRITE_GRID        :: write grid fields to output files
                0106 C    | |-CPL_EXCH_CONFIGS  :: exchange config with coupler-interface
9366854e02 Chri*0107 C    |
f2f1601bce Jean*0108 C    |-CTRL_UNPACK         :: Control vector support package. see pkg/ctrl
                0109 C    |-COST_DEPENDENT_INIT :: ( see pkg/cost )
9366854e02 Chri*0110 C    |
                0111 C    |-ADTHE_MAIN_LOOP :: Derivative evaluating form of main time stepping loop
c493e58557 Jean*0112 C    !                 :: Automatically generated by TAMC/TAF.
9366854e02 Chri*0113 C    |
c493e58557 Jean*0114 C    |-THE_MAIN_LOOP   :: Main timestepping loop routine.
9366854e02 Chri*0115 C    | |
f2f1601bce Jean*0116 C    | |-INITIALISE_VARIA :: Set the initial conditions for time evolving fields
                0117 C    | | |
                0118 C #ifdef ALLOW_AUTODIFF
                0119 C    | | |-INI_DEPTHS         \
                0120 C    | | |-CTRL_DEPTH_INI      \
                0121 C    | | |-UPDATE_MASKS_ETC     } ALLOW_DEPTH_CONTROL case
                0122 C    | | |-UPDATE_CG2D         /
                0123 C #endif
                0124 C    | | |-INI_NLFS_VARS :: Initialise all Non-Lin Free-Surf arrays (SURFACE.h)
                0125 C    | | |-INI_DYNVARS   :: Initialise to zero all DYNVARS.h arrays
                0126 C    | | |-INI_NH_VARS   :: Initialise to zero all NH_VARS.h arrays
72b199b510 timo*0127 C    | | |-INI_FFIELDS   :: Initialise forcing fields in FFIELDS.h to zero
                0128 C    | | |
f2f1601bce Jean*0129 C    | | |-INI_FIELDS    :: Control initialising model fields to non-zero
                0130 C    | | | |-INI_VEL     :: Initialize 3D flow field.
                0131 C    | | | |-INI_THETA   :: Set model initial temperature field.
                0132 C    | | | |-INI_SALT    :: Set model initial salinity field.
                0133 C    | | | |-INI_PSURF   :: Set model initial free-surface height/pressure.
                0134 C    | | | |-READ_PICKUP :: Read in main model pickup files to restart a run.
                0135 C    | | |
                0136 C    | | |-INI_MIXING   :: Initialise diapycnal diffusivity.
9366854e02 Chri*0137 C    | | |
eb9df00f2b Jean*0138 C    | | |-TAUEDDY_INIT_VARIA :: Initialise eddy (bolus) streamfunction
72b199b510 timo*0139 C    | | |
f2f1601bce Jean*0140 C    | | |-INI_FORCING  :: Set model initial forcing fields, either
                0141 C    | | |   |          :: set in-line or from file as shown here:
                0142 C    | | |   |-READ_FLD_XY_RS(zonalWindFile)
                0143 C    | | |   |-READ_FLD_XY_RS(meridWindFile)
                0144 C    | | |   |-READ_FLD_XY_RS(surfQnetFile)
                0145 C    | | |   |-READ_FLD_XY_RS(EmPmRfile)
                0146 C    | | |   |-READ_FLD_XY_RS(thetaClimFile)
                0147 C    | | |   |-READ_FLD_XY_RS(saltClimFile)
                0148 C    | | |   |-READ_FLD_XY_RS(surfQswFile)
9366854e02 Chri*0149 C    | | |
f2f1601bce Jean*0150 C    | | |-AUTODIFF_INIT_VARIA :: (see pkg/autodiff )
455a90837c Jean*0151 C    | | |
c493e58557 Jean*0152 C    | | |-PACKAGES_INIT_VARIABLES :: Does initialisation of time evolving
                0153 C    | | | | ${PKG}_INIT_VARIA     :: package data.
9366854e02 Chri*0154 C    | | |
f2f1601bce Jean*0155 C    | | |-COST_INIT_VARIA     :: ( see pkg/cost )
                0156 C    | | |-CONVECTIVE_ADJUSTMENT_INI :: Apply conv. adjustment to initial state
                0157 C    | | |
                0158 C    | | |-CALC_R_STAR    :: Calculate the new level thickness factor (r* coord)
                0159 C    | | |-UPDATE_R_STAR  :: Update the level thickness fraction (r* coord).
                0160 C    | | |-UPDATE_SIGMA   :: Update the level thickness fraction (sigma-coord).
                0161 C    | | |-CALC_SURF_DR   :: Calculate the new surface level thickness.
                0162 C    | | |-UPDATE_SURF_DR :: Update the surface-level thickness fraction.
                0163 C    | | |
                0164 C    | | |-UPDATE_CG2D    :: Update 2D conjugate grad. for Free-Surf.
                0165 C    | | |
                0166 C    | | |-INTEGR_CONTINUITY :: Integrate the continuity Equation
                0167 C    | | | |-INTEGRATE_FOR_W :: Integrate for vertical velocity
                0168 C    | | | |-OBCS_APPLY_W    :: Open boundary package (see pkg/obcs).
52dd931a85 Timo*0169 C    | | | |-DUMMY_FOR_ETAN  :: For printing adEtaN (see pkg/autodiff).
f2f1601bce Jean*0170 C    | | | |-UPDATE_ETAH     :: Update Surface height/pressure
                0171 C    | | |
                0172 C    | | |-CALC_R_STAR    :: Calculate the new level thickness factor (r* coord)
                0173 C    | | |-CALC_SURF_DR   :: Calculate the new surface level thickness.
                0174 C    | | |
c493e58557 Jean*0175 C    | | |-STATE_SUMMARY    :: Summarise model prognostic variables.
f2f1601bce Jean*0176 C    | | |
                0177 C    | | |-MONITOR          :: Monitor state (see pkg/monitor)
                0178 C    | | |
                0179 C    | | |-DO_STATEVARS_TAVE :: Time averaging package ( see pkg/timeave ).
                0180 C    | | |  |-TIMEAVE_STATVARS :: Accumulate main model state variables
                0181 C    | | |  |-PTRACERS_TIMEAVE :: Accumulate passive tracers variables
                0182 C    | | |
                0183 C    | | |-DO_THE_MODEL_IO  :: Controlling routine for IO
                0184 C    | | | |-WRITE_STATE    ::  Write model state variables.
                0185 C    | | | |-TIMEAVE_STATV_WRITE :: Write Time averaged output (see pkg/timeave)
                0186 C    | | | |-FIZHI_WRITE_STATE :: Write Fizhi pkg output (see pkg/fizhi)
                0187 C    | | | |-AIM_WRITE_TAVE    :: Write AIM  pkg output (see pkg/aim_v23)
                0188 C    | | | |-LAND_OUTPUT       :: Write Land pkg output (see pkg/land)
                0189 C    | | | |-OBCS_OUTPUT       :: Write OBCS pkg output (see pkg/obcs)
                0190 C    | | | |-GMREDI_OUTPUT     :: Write GM-Redi pkg output (see pkg/gmredi)
                0191 C    | | | |-KPP_OUTPUT        :: Write KPP  pkg output (see pkg/kpp)
                0192 C    | | | |-PP81_OUTPUT       :: Write PP81 pkg output (see pkg/pp81)
                0193 C    | | | |-KL10_OUTPUT       :: Write KL10 pkg output (see pkg/kl10)
                0194 C    | | | |-MY82_OUTPUT       :: Write MY82 pkg output (see pkg/my82)
                0195 C    | | | |-OPPS_OUTPUT       :: Write OPPS pkg output (see pkg/opps)
                0196 C    | | | |-GGL90_OUTPUT      :: Write GGL90 pkg output (see pkg/ggl90)
                0197 C    | | | |-SBO_CALC          :: Compute SBO diagnostics (see pkg/sbo)
                0198 C    | | | |-SBO_OUTPUT        :: Write SBO  pkg output   (see pkg/sbo)
                0199 C    | | | |-SEAICE_OUTPUT     :: Write SeaIce pkg output (see pkg/seaice)
                0200 C    | | | |-SHELFICE_OUTPUT   :: Write ShelfIce pkg output (see pkg/shelfice)
                0201 C    | | | |-BULKF_OUTPUT      :: Write Bulk-Force output (see pkg/bulK_force)
                0202 C    | | | |-THSICE_OUTPUT     :: Write ThSIce pkg output (see pkg/thsice)
                0203 C    | | | |-PTRACERS_OUTPUT   :: Write pTracers pkg output (see pkg/ptracers)
                0204 C    | | | |-MATRIX_OUTPUT     :: Write Matrix pkg output (see pkg/matrix)
                0205 C    | | | |-GCHEM_OUTPUT      :: Write Geochemistry pkg output (see pkg/gchem)
                0206 C    | | | |-CPL_OUTPUT        :: Write Coupler-Interface output (see
                0207 C    | | | |                   :: pkg/atm_compon_interf, pkg/ocn_compon_interf)
                0208 C    | | | |-LAYERS_CALC       :: Calculate layers diagnostics (see pkg/layers)
                0209 C    | | | |-LAYERS_OUTPUT     :: Write Layers pkg output (see pkg/layers)
                0210 C    | | | |-DIAGNOSTICS_WRITE :: Write pkg/diagnostics output
                0211 C    | | |
9366854e02 Chri*0212 C====|>| ****************************
                0213 C====|>| BEGIN MAIN TIMESTEPPING LOOP
                0214 C====|>| ****************************
c493e58557 Jean*0215 C    | |-COST_AVERAGESFIELDS :: time-averaged Cost function terms (see pkg/cost)
f2f1601bce Jean*0216 C    | |-PROFILES_INLOOP     :: ( see pkg/profiles )
                0217 C    | /
                0218 C    | |-MAIN_DO_LOOP    :: Open-AD case: Main timestepping loop routine
                0219 C    | \                    otherwise: just call FORWARD_STEP
c493e58557 Jean*0220 C    | |
                0221 C/\  | |-FORWARD_STEP        :: Step forward a time-step ( AT LAST !!! )
9366854e02 Chri*0222 C/\  | | |
f2f1601bce Jean*0223 C/\  | | |-AUTODIFF_INADMODE_UNSET :: Set/reset some adjoint flags
                0224 C/\  | | |-RESET_NLFS_VARS   :: Reset some Non-Lin Free-Surf vars (Adjoint)
                0225 C/\  | | |-UPDATE_R_STAR     :: Reset r-star factor variables     (Adjoint)
                0226 C/\  | | |-UPDATE_SURF_DR    :: Reset NLFS surface thickness vars (Adjoint)
                0227 C/\  | | |
                0228 C/\  | | |-PTRACERS_SWITCH_ONOFF    :: Set/reset pTracers time-stepping switch
                0229 C/\  | | |-DIAGNOSTICS_SWITCH_ONOFF :: Activate/de-activate diagnostics
                0230 C/\  | | |-DO_STATEVARS_DIAGS ( 0 ) :: fill-up state variable diagnostics
                0231 C/\  | | |
                0232 C/\  | | |-NEST_CHILD_SETMEMO :: Nesting interface
                0233 C/\  | | |-NEST_PARENT_IO_1   :: Nesting interface
                0234 C/\  | | |
                0235 C/\  | | |-LOAD_FIELDS_DRIVER :: Control loading of input fields from files
                0236 C/\  | | |
                0237 C/\  | | |-BULKF_FORCING      :: Calculate surface forcing (see pkg/bulk_force)
                0238 C/\  | | |-CHEAPAML           :: Cheap AML driver ( see pkg/cheapaml )
                0239 C/\  | | |-CTRL_MAP_FORCING   :: Control vector support package. (see pkg/ctrl)
                0240 C/\  | | |-DUMMY_IN_STEPPING  :: Autodiff package ( pkg/autodiff ).
9366854e02 Chri*0241 C/\  | | |
c493e58557 Jean*0242 C/\  | | |-CPL_EXPORT_MY_DATA :: Send coupling fields to coupler
                0243 C/\  | | |-CPL_IMPORT_EXTERNAL_DATA :: Receive coupling fields from coupler
                0244 C/\  | | |
f2f1601bce Jean*0245 C/\  | | |-OASIS_PUT     :: Oasis coupler interface
                0246 C/\  | | |-OASIS_GET     :: Oasis coupler interface
                0247 C/\  | | |
                0248 C/\  | | |-EBM_DRIVER    :: Calculate EBM type atmospheric forcing (see pkg/ebm)
                0249 C/\  | | |
c493e58557 Jean*0250 C/\  | | |-DO_ATMOSPHERIC_PHYS :: Atmospheric physics computation
f2f1601bce Jean*0251 C/\  | | | |
                0252 C/\  | | | |-UPDATE_OCEAN_EXPORTS     :: ( see pkg/fizhi )
                0253 C/\  | | | |-UPDATE_EARTH_EXPORTS     :: ( see pkg/fizhi )
                0254 C/\  | | | |-UPDATE_CHEMISTRY_EXPORTS :: ( see pkg/fizhi )
                0255 C/\  | | | |-FIZHI_WRAPPER            :: ( see pkg/fizhi )
                0256 C/\  | | | |-STEP_FIZHI_FG            :: ( see pkg/fizhi )
                0257 C/\  | | | |-FIZHI_UPDATE_TIME        :: ( see pkg/fizhi )
                0258 C/\  | | | |
                0259 C/\  | | | |-ATM_PHYS_DRIVER          :: ( see pkg/atm_phys )
                0260 C/\  | | | |
                0261 C/\  | | | |-AIM_DO_PHYSICS           :: ( see pkg/aim_v23 )
c493e58557 Jean*0262 C/\  | | |
                0263 C/\  | | |-DO_OCEANIC_PHYS     :: Oceanic (& seaice) physics computation
f2f1601bce Jean*0264 C/\  | | | |
c493e58557 Jean*0265 C/\  | | | |-OBCS_CALC         :: Open boundary. package (see pkg/obcs).
f2f1601bce Jean*0266 C/\  | | | |
                0267 C/\  | | | |-FRAZIL_CALC_RHS   :: Compute FRAZIL tendencies ( see pkg/frazil )
                0268 C/\  | | | |-THSICE_MAIN       :: Thermodynamic sea-ice driver (see pkg/thsice)
                0269 C/\  | | | |-SEAICE_MODEL      :: Sea-ice model driver (see pkg/seaice )
                0270 C/\  | | | |-SEAICE_COST_SENSI   :: Sea-ice cost-function (see pkg/seaice )
                0271 C/\  | | | |-SHELFICE_THERMODYNAMICS :: Compute ShelfIce thermo (pkg/shelfice)
                0272 C/\  | | | |-ICEFRONT_THERMODYNAMICS :: Compute IceFront thermo (pkg/icefront)
                0273 C/\  | | | |
                0274 C/\  | | | |-SALT_PLUME_DO_EXCH   :: (see pkg/salt_plume )
                0275 C/\  | | | |-FREEZE_SURFACE       :: Prevent SST to fall below TFreeze
                0276 C/\  | | | |-OCN_APPLY_IMPORT     :: Apply imported fields from coupler
                0277 C/\  | | | |-EXTERNAL_FORCING_SURF:: Compute appropriately dimensioned
                0278 C/\  | | | |                      :: surface forcing terms.
                0279 C/\  | | | |-FIND_RHO_2D @ p(k)   :: Calculate [rho(T,S,p)-Rho_0] of a slice
                0280 C/\  | | | |-FIND_RHO_2D @ p(k-1) :: Calculate [rho(T,S,p)-Rho_0] of a slice
                0281 C/\  | | | |-GRAD_SIGMA           :: Calculate isoneutral gradients
                0282 C/\  | | | |-CALC_IVDC       :: Set Implicit Vertical Diffusivity for Convection
                0283 C/\  | | | |-CALC_OCE_MXLAYER        :: Diagnose Oceanic Mixed Layer depth
                0284 C/\  | | | |
                0285 C/\  | | | |-SALT_PLUME_CALC_DEPTH   :: (see pkg/salt_plume )
                0286 C/\  | | | |-SALT_PLUME_VOLFRAC      :: (see pkg/salt_plume )
                0287 C/\  | | | |-SALT_PLUME_APPLY (Temp) :: (see pkg/salt_plume )
                0288 C/\  | | | |-SALT_PLUME_APPLY (Salt) :: (see pkg/salt_plume )
                0289 C/\  | | | |-SALT_PLUME_FORCING_SURF :: (see pkg/salt_plume )
                0290 C/\  | | | |-KPP_CALC           :: Compute KPP  vertical mixing ( see pkg/kpp )
                0291 C/\  | | | |-PP81_CALC          :: Compute PP81 vertical mixing ( see pkg/pp81 )
                0292 C/\  | | | |-KL10_CALC          :: Compute KL10 vertical mixing ( see pkg/kl10 )
                0293 C/\  | | | |-MY82_CALC          :: Compute MY82 vertical mixing ( see pkg/kl10 )
                0294 C/\  | | | |-GGL90_CALC         :: Compute GGL90 vertical mixing (see pkg/ggl10)
                0295 C/\  | | | |-GMREDI_CALC_TENSOR :: Compute GM-Redi tensor ( see pkg/gmredi )
                0296 C/\  | | | |-DWNSLP_CALC_FLOW   :: Compute Down-Slope flow  (see pkg/down_slope)
                0297 C/\  | | | |-BBL_CALC_RHS       :: Compute BBL tendencies ( see pkg/bbl )
                0298 C/\  | | | |-MYPACKAGE_CALC_RHS :: Compute mypackage tendencies (pkg/mypackage)
                0299 C/\  | | | |
                0300 C/\  | | | |-GMREDI_DO_EXCH     :: ( see pkg/gmredi )
                0301 C/\  | | | |-KPP_DO_EXCH        :: ( see pkg/kpp )
                0302 C/\  | | | |-DIAGS_RHO_G        :: Compute some density related diagnostics
                0303 C/\  | | | |-DIAGS_OCEANIC_SURF_FLUX :: Diagnose oceanic surface fluxes
                0304 C/\  | | | |-SALT_PLUME_DIAGNOSTICS_FILL :: (see pkg/salt_plume )
                0305 C/\  | | | |-ECCO_PHYS          :: ( see pkg/ecco )
                0306 C/\  | | |
0490ad34e0 Jean*0307 C/\  | | |-STREAMICE_TIMESTEP   :: ( see pkg/streamice )
c493e58557 Jean*0308 C/\  | | |
f2f1601bce Jean*0309 C/\  | | |-GCHEM_CALC_TENDENCY  :: geochemistry driver routine (see pkg/gchem)
c493e58557 Jean*0310 C/\  | | |
f2f1601bce Jean*0311 C/\  | | |-LONGSTEP_AVERAGE        :: Averaging state vars ( see pkg/longstep )
                0312 C/\  | | |-LONGSTEP_THERMODYNAMICS :: Step forward tracers ( see pkg/longstep )
                0313 C/\  | | |
                0314 C/\  | | |-THERMODYNAMICS       :: theta, salt + tracer equations driver.
                0315 C/\  | | | |                         (synchronous time-stepping case)
                0316 C/\  | | | |-CALC_WSURF_TR          :: Compute T & S Linear-Free-Surf correction
                0317 C/\  | | | |-PTRACERS_CALC_WSURF_TR :: Compute Tracers Linear-Free-Surf correct.
                0318 C/\  | | | |
                0319 C/\  | | | |-GMREDI_RESIDUAL_FLOW :: Get the flow field used to advect tracers
adcc4b1a0c Jean*0320 C/\  | | | |
f2f1601bce Jean*0321 C/\  | | | |-TEMP_INTEGRATE       :: Step forward Prognostic Eq for Temperature.
                0322 C/\  | | | | |
                0323 C/\  | | | | |-ADAMS_BASHFORTH3   :: Extrapolate tracer forward in time (AB-3)
                0324 C/\  | | | | |-ADAMS_BASHFORTH2   :: Extrapolate tracer forward in time (AB-2)
                0325 C/\  | | | | |-CALC_3D_DIFFUSIVITY :: set vertical diffusivity
                0326 C/\  | | | | |
                0327 C/\  | | | | |-GAD_SOM_ADVECT     :: Second Order Moment (SOM) advection
adcc4b1a0c Jean*0328 C/\  | | | | |-GAD_ADVECTION      :: Generalised advection driver (multi-dim
                0329 C/\  | | | | |                         advection case) (see pkg/gad).
f2f1601bce Jean*0330 C/\  | | | | |-CALC_ADV_FLOW      :: set 3-D flow field to advect tracer
                0331 C/\  | | | | |-APPLY_FORCING_T    :: Problem specific forcing for temperature.
adcc4b1a0c Jean*0332 C/\  | | | | |-GAD_CALC_RHS       :: Calculate Advection-Diffusion tendency terms
f2f1601bce Jean*0333 C/\  | | | | |
                0334 C/\  | | | | |-ADAMS_BASHFORTH3   :: Extrapolate tendency forward in time (AB-3)
                0335 C/\  | | | | |-ADAMS_BASHFORTH2   :: Extrapolate tendency forward in time (AB-2)
                0336 C/\  | | | | |-FREESURF_RESCALE_G :: Re-scale Gt for free-surface height.
                0337 C/\  | | | | |-DWNSLP_APPLY       :: Add pkg/down_slope tendency
                0338 C/\  | | | | |
adcc4b1a0c Jean*0339 C/\  | | | | |-TIMESTEP_TRACER    :: Step tracer field forward in time
f2f1601bce Jean*0340 C/\  | | | | |
                0341 C/\  | | | | |-GAD_IMPLICIT_R     :: Solve vertical implicit Advect-Diffus. eqn.
adcc4b1a0c Jean*0342 C/\  | | | | |-IMPLDIFF           :: Solve vertical implicit diffusion equation.
                0343 C/\  | | | | |-CYCLE_AB_TRACER    :: Cycle time-stepping arrays for tracer field
f2f1601bce Jean*0344 C/\  | | | | |-CYCLE_TRACER       :: Cycle time-stepping arrays for tracer field
adcc4b1a0c Jean*0345 C/\  | | | |
f2f1601bce Jean*0346 C/\  | | | |-SALT_INTEGRATE       :: Step forward Prognostic Eq for Salinity.
                0347 C/\  | | | | |                       same sequence of calls as in TEMP_INTEGRATE
adcc4b1a0c Jean*0348 C/\  | | | |
639dc32746 Ed H*0349 C/\  | | | |-PTRACERS_INTEGRATE   :: Integrate other tracer(s) (see pkg/ptracers).
f2f1601bce Jean*0350 C/\  | | | | |                       same sequence of calls as in TEMP_INTEGRATE
                0351 C/\  | | | | |-OBCS_APPLY_PTRACER :: Open boundary package for pTracers
adcc4b1a0c Jean*0352 C/\  | | | |
c493e58557 Jean*0353 C/\  | | | |-OBCS_APPLY_TS        :: Open boundary package (see pkg/obcs ).
9366854e02 Chri*0354 C/\  | | |
f2f1601bce Jean*0355 C/\  | | |-LONGSTEP_AVERAGE        :: Averaging state vars ( see pkg/longstep )
                0356 C/\  | | |-LONGSTEP_THERMODYNAMICS :: Step forward tracers ( see pkg/longstep )
                0357 C/\  | | |
                0358 C/\  | | |-DO_STAGGER_FIELDS_EXCHANGES :: Update overlap regions of arrays
                0359 C/\  | | |                                 Theta & Salt (implicit IGW case)
                0360 C/\  | | |
51701379d8 Ed H*0361 C/\  | | |-DYNAMICS       :: Momentum equations driver.
9366854e02 Chri*0362 C/\  | | | |
b75fe8c753 Jean*0363 C/\  | | | |-CALC_GRAD_PHI_SURF :: Calculate the gradient of the surface
9366854e02 Chri*0364 C/\  | | | |                       Potential anomaly.
c493e58557 Jean*0365 C/\  | | | |-CALC_VISCOSITY   :: Calculate net vertical viscosity
f2f1601bce Jean*0366 C/\  | | | |-MOM_CALC_3D_STRAIN :: Calculates the strain tensor of 3D flow field
                0367 C/\  | | | |-OBCS_COPY_UV_N   :: for Stevens bndary Conditions (see pkg/obcs)
                0368 C/\  | | | |
c493e58557 Jean*0369 C/\  | | | |-CALC_PHI_HYD     :: Integrate the hydrostatic relation.
f2f1601bce Jean*0370 C/\  | | | |-MOM_FLUXFORM     :: Flux Form momentum eqn. (pkg/mom_fluxform)
                0371 C/\  | | | |-MOM_VECINV       :: Vector Invariant momentum eqn (pkg/mom_vecinv)
                0372 C/\  | | | |-MOM_CALC_SMAG_3D :: Calculate Smagorinsky 3D (harmonic) viscosities
                0373 C/\  | | | |-MOM_UV_SMAG_3D   :: Calculate U,V mom. tendency due to Smag 3D Visc
                0374 C/\  | | | |-TIMESTEP         :: Step horizontal momentum fields forward in time
                0375 C/\  | | | |
                0376 C/\  | | | |-MOM_U_IMPLICIT_R :: Solve implicitly vertical Adv-Diffus equation.
c493e58557 Jean*0377 C/\  | | | |-IMPLDIFF         :: Solve vertical implicit diffusion equation.
f2f1601bce Jean*0378 C/\  | | | |-OBCS_SAVE_UV_N   :: for Stevens bndary Conditions (see pkg/obcs)
                0379 C/\  | | | |-OBCS_APPLY_UV    :: Apply Open bndary Conditions to provisional U,V
                0380 C/\  | | | |-IMPLDIFF         :: (CD-Scheme) Solve vertical impl. diffus. eqn
                0381 C/\  | | | |
                0382 C/\  | | | |-CALC_GW          :: Vert. momentum tendency terms (Non-Hydrostatic)
                0383 C/\  | | | | |-MOM_W_SMAG_3D  :: Calculate W mom. tendency due to Smag 3D Visc
                0384 C/\  | | | |-TIMESTEP_WVEL    :: Step vert mom forward in time (Non-Hydrostatic)
9366854e02 Chri*0385 C/\  | | |
f2f1601bce Jean*0386 C/\  | | |-MNC_UPDATE_TIME    :: Update MNC time record (see pkg/mnc)
                0387 C/\  | | |
                0388 C/\  | | |-UPDATE_R_STAR  :: Update the level thickness fraction (r* coord).
                0389 C/\  | | |-UPDATE_SIGMA   :: Update the level thickness fraction (sigma-coord).
c493e58557 Jean*0390 C/\  | | |-UPDATE_R_STAR  :: Update the level thickness fraction.
f2f1601bce Jean*0391 C/\  | | |-UPDATE_SURF_DR :: Update the surface-level thickness fraction.
                0392 C/\  | | |-UPDATE_CG2D    :: Update 2D conjugate grad. for Free-Surf.
                0393 C/\  | | |
                0394 C/\  | | |-SHAP_FILT_APPLY_UV  :: Apply Shapiro Filter to provisional velocity
                0395 C/\  | | |-ZONAL_FILT_APPLY_UV :: Apply  Zonal  Filter to provisional velocity
9366854e02 Chri*0396 C/\  | | |
c493e58557 Jean*0397 C/\  | | |-SOLVE_FOR_PRESSURE  :: Find surface pressure.
f2f1601bce Jean*0398 C/\  | | | |-CALC_DIV_GHAT     :: Form the RHS of the surface pressure eqn.
9366854e02 Chri*0399 C/\  | | | |-CG2D              :: Two-dim pre-con. conjugate-gradient.
f2f1601bce Jean*0400 C/\  | | | |-PRE_CG3D          :: Finish to set the RHS of the 3-D pressure eqn.
9366854e02 Chri*0401 C/\  | | | |-CG3D              :: Three-dim pre-con. conjugate-gradient solver.
f2f1601bce Jean*0402 C/\  | | | |-POST_CG3D         :: finalise solution of NH and Free-Surf pressure
9366854e02 Chri*0403 C/\  | | |
c493e58557 Jean*0404 C/\  | | |-MOMENTUM_CORRECTION_STEP :: Finalise momentum stepping
f2f1601bce Jean*0405 C/\  | | | |-CALC_GRAD_PHI_SURF  :: Return DDx and DDy of surface pressure
                0406 C/\  | | | |-CORRECTION_STEP     :: Pressure correction to momentum
                0407 C/\  | | | |-OBCS_APPLY_UV       :: Open boundary package (see pkg/obcs).
                0408 C/\  | | | |-SHAP_FILT_APPLY_UV  :: Apply Shapiro Filter to latest velocity
                0409 C/\  | | | |-ZONAL_FILT_APPLY_UV :: Apply  Zonal  Filter to latest velocity
9366854e02 Chri*0410 C/\  | | |
f2f1601bce Jean*0411 C/\  | | |-INTEGR_CONTINUITY   :: Integrate continuity equation (see above)
c493e58557 Jean*0412 C/\  | | |
f2f1601bce Jean*0413 C/\  | | |-CALC_R_STAR    :: Calculate the new level thickness factor (r* coord)
                0414 C/\  | | |-CALC_SURF_DR   :: Calculate the new surface level thickness.
9366854e02 Chri*0415 C/\  | | |
f2f1601bce Jean*0416 C/\  | | |-DO_STAGGER_FIELDS_EXCHANGES :: Update overlap regions of arrays
                0417 C/\  | | |                             uVel,vVel & wVel (stagger-time-step case)
61d8734a9f Step*0418 C/\  | | |
f2f1601bce Jean*0419 C/\  | | |-DO_STATEVARS_DIAGS ( 1 ) :: fill-up state variable diagnostics
                0420 C/\  | | |
                0421 C/\  | | |-THERMODYNAMICS       :: theta, salt + tracer Eq. driver (see above).
                0422 C/\  | | |                         (staggered time-stepping case)
                0423 C/\  | | |
                0424 C/\  | | |-TRACERS_CORRECTION_STEP :: Finalise tracer stepping:
                0425 C/\  | | | |                       ::  apply filter, conv.adjustment
                0426 C/\  | | | |-TRACERS_IIGW_CORRECTION :: apply Implicit IGW adjustment to T & S
                0427 C/\  | | | |-SHAP_FILT_APPLY_TS        :: Apply Shapiro Filter to latest T & S
                0428 C/\  | | | |-ZONAL_FILT_APPLY_TS       :: Apply  Zonal  Filter to latest T & S
                0429 C/\  | | | |-PTRACERS_ZONAL_FILT_APPLY :: Apply  Zonal Filter to pTracers
                0430 C/\  | | | |-SALT_FILL                 :: Fill up negative Salt
                0431 C/\  | | | |-OPPS_INTERFACE            :: ( see pkg/opps )
                0432 C/\  | | | |-CONVECTIVE_ADJUSTMENT     :: Apply convective adjustment
                0433 C/\  | | | |-MATRIX_STORE_TENDENCY_IMP :: ( see pkg/matrix )
                0434 C/\  | | |
                0435 C/\  | | |-LONGSTEP_AVERAGE        :: Averaging state vars ( see pkg/longstep )
                0436 C/\  | | |-LONGSTEP_THERMODYNAMICS :: Step forward tracers ( see pkg/longstep )
                0437 C/\  | | |
                0438 C/\  | | |-GCHEM_FORCING_SEP :: Tracer forcing for gchem pkg (if tracer
                0439 C/\  | | |                   :: dependent tendencies calculated separately)
9366854e02 Chri*0440 C/\  | | |
c493e58557 Jean*0441 C/\  | | |-DO_FIELDS_BLOCKING_EXCHANGES :: Sync up overlap regions.
9366854e02 Chri*0442 C/\  | | |
f2f1601bce Jean*0443 C/\  | | |-DO_STATEVARS_DIAGS ( 2 ) :: fill-up state variable diagnostics
                0444 C/\  | | |
                0445 C/\  | | |-GRIDALT_UPDATE    :: ( see pkg/gridalt )
                0446 C/\  | | |-STEP_FIZHI_CORR   :: ( see pkg/fizhi )
                0447 C/\  | | |
                0448 C/\  | | |-FLT_MAIN          :: Step forward Floats (see pkg/flt)
                0449 C/\  | | |
                0450 C/\  | | |-DO_STATEVARS_TAVE :: Time averaging package (see above)
                0451 C/\  | | |
                0452 C/\  | | |-NEST_PARENT_IO_2  :: Nesting interface
                0453 C/\  | | |-NEST_CHILD_TRANSP :: Nesting interface
                0454 C/\  | | |
c493e58557 Jean*0455 C/\  | | |-MONITOR          :: Monitor package (pkg/monitor).
9366854e02 Chri*0456 C/\  | | |
f2f1601bce Jean*0457 C/\  | | |-COST_TILE        :: ( see pkg/cost )
                0458 C/\  | | |
                0459 C/\  | | |-DO_THE_MODEL_IO  :: Controlling routine for IO (see above)
                0460 C/\  | | |
                0461 C/\  | | |-PTRACERS_RESET   :: Re-initialize PTRACERS ( see pkg/ptracers )
                0462 C/\  | | |
                0463 C/\  | | |-DO_WRITE_PICKUP  :: Controlling routine for writing files to restart
                0464 C/\  | | | |-PACKAGES_WRITE_PICKUP :: Write pickup files for each package
                0465 C/\  | | | | |                     ::  which needs it to restart
                0466 C/\  | | | | |-GAD_WRITE_PICKUP       :: Write Generic AdvDiff pickups for SOM
                0467 C/\  | | | | |                        :: advection scheme (pkg/generic_advdiff)
                0468 C/\  | | | | |-CD_CODE_WRITE_PICKUP   :: Write CD-code pickups (see pkg/cd_code)
                0469 C/\  | | | | |-OBCS_WRITE_PICKUP      :: Write OBCS pickups    (see pkg/obcs)
                0470 C/\  | | | | |-GGL90_WRITE_PICKUP     :: Write GGL90 pickups   (see pkg/ggl90)
b0b45f2373 Ou W*0471 C/\  | | | | |-GMREDI_WRITE_PICKUP    :: Write GMREDI pickups  (see pkg/gmredi)
f2f1601bce Jean*0472 C/\  | | | | |-BBL_WRITE_PICKUP       :: Write BBL pickups     (see pkg/bbl)
                0473 C/\  | | | | |-CHEAPAML_WRITE_PICKUP  :: Write CheapAML pickups (pkg/cheapaml)
                0474 C/\  | | | | |-FLT_WRITE_PICKUP       :: Write Floats pickups  (see pkg/flt)
                0475 C/\  | | | | |-PTRACERS_WRITE_PICKUP  :: Write pTracers pickups (pkg/ptracers)
                0476 C/\  | | | | |-GCHEM_WRITE_PICKUP     :: Write Geo-Chem pickups (see pkg/gchem)
                0477 C/\  | | | | |-SEAICE_WRITE_PICKUP    :: Write SeaIce pickups  (see pkg/seaice)
                0478 C/\  | | | | |-STREAMICE_WRITE_PICKUP :: Write StreamIce pickups (pkg/streamice)
b0b45f2373 Ou W*0479 C/\  | | | | |-SHELFICE_WRITE_PICKUP  :: Write ShelfIce pickups (pkg/shelfice)
f2f1601bce Jean*0480 C/\  | | | | |-THSICE_WRITE_PICKUP    :: Write ThSIce pickups  (see pkg/thsice)
                0481 C/\  | | | | |-LAND_WRITE_PICKUP      :: Write Land   pickups  (see pkg/land)
                0482 C/\  | | | | |-ATM_PHYS_WRITE_PICKUP  :: Write Atm-Phys pickups (pkg/atm_phys)
                0483 C/\  | | | | |-FIZHI_WRITE_PICKUP     :: Write Fizhi pickups   (see pkg/fizhi)
                0484 C/\  | | | | |-FIZHI_WRITE_VEGTILES   :: Write Fizhi VegTiles  (see pkg/fizhi)
                0485 C/\  | | | | |-FIZHI_WRITE_DATETIME   :: Write Fizhi DateTime  (see pkg/fizhi)
                0486 C/\  | | | | |-CPL_WRITE_PICKUP       :: Write Coupling-Interface pickups
b0b45f2373 Ou W*0487 C/\  | | | | |-ECCO_WRITE_PICKUP      :: Write ECCO pickups    (see pkg/ecco)
f2f1601bce Jean*0488 C/\  | | | | |-MYPACKAGE_WRITE_PICKUP :: Write pkg/mypackage pickups
                0489 C/\  | | | |
                0490 C/\  | | | |-WRITE_PICKUP          :: Write main model pickup files.
                0491 C/\  | | |
                0492 C/\  | | |-AUTODIFF_INADMODE_SET   :: Set/reset some adjoint flags
c493e58557 Jean*0493 C    | |
9366854e02 Chri*0494 C<===|=| **************************
                0495 C<===|=| END MAIN TIMESTEPPING LOOP
                0496 C<===|=| **************************
c493e58557 Jean*0497 C    | |
f2f1601bce Jean*0498 C    | |-COST_AVERAGESFIELDS :: Time-averaged Cost function terms (see pkg/cost)
                0499 C    | |-PROFILES_INLOOP     :: ( see pkg/profiles )
                0500 C    | |-COST_FINAL          :: Cost function package (see pkg/cost)
9366854e02 Chri*0501 C    |
f2f1601bce Jean*0502 C    |-CTRL_PACK       :: Control vector support package (see pkg/ctrl)
9366854e02 Chri*0503 C    |
f2f1601bce Jean*0504 C    |-GRDCHK_MAIN     :: Gradient check package (see pkg/grdchk)
9366854e02 Chri*0505 C    |
c493e58557 Jean*0506 C    |-TIMER_PRINTALL  :: Computational timing summary
                0507 C    |
                0508 C    |-COMM_STATS      :: Summarise inter-proc and inter-thread communication
f2f1601bce Jean*0509 C    |                 :: events.
9366854e02 Chri*0510 C \ev
                0511 C
4c563c2ee9 Chri*0512 CEOI
                0513 
6d54cf9ca1 Ed H*0514 #include "PACKAGES_CONFIG.h"
b9377e56be Alis*0515 #include "CPP_OPTIONS.h"
341366d590 Jean*0516 #include "AD_CONFIG.h"
c10ffac493 Jean*0517 #ifdef ALLOW_AUTODIFF
                0518 # include "AUTODIFF_OPTIONS.h"
                0519 #endif
                0520 #ifdef ALLOW_CTRL
                0521 # include "CTRL_OPTIONS.h"
                0522 #endif
6fc4c6c58c Dani*0523 
4c563c2ee9 Chri*0524 CBOP
                0525 C     !ROUTINE: THE_MODEL_MAIN
                0526 
                0527 C     !INTERFACE:
924557e60a Chri*0528       SUBROUTINE THE_MODEL_MAIN(myThid)
4c563c2ee9 Chri*0529 
                0530 C     !DESCRIPTION: \bv
                0531 C     *==========================================================*
455a90837c Jean*0532 C     | SUBROUTINE THE_MODEL_MAIN
                0533 C     | o Master controlling routine for model using the MITgcm
                0534 C     |   UV parallel wrapper.
4c563c2ee9 Chri*0535 C     *==========================================================*
455a90837c Jean*0536 C     | THE_MODEL_MAIN is invoked by the MITgcm UV parallel
                0537 C     | wrapper with a single integer argument "myThid". This
                0538 C     | variable identifies the thread number of an instance of
                0539 C     | THE_MODEL_MAIN. Each instance of THE_MODEL_MAIN works
                0540 C     | on a particular region of the models domain and
                0541 C     | synchronises with other instances as necessary. The
                0542 C     | routine has to "understand" the MITgcm parallel
                0543 C     | environment and the numerical algorithm. Editing this
                0544 C     | routine is best done with some knowledge of both aspects.
                0545 C     | Notes
                0546 C     | =====
                0547 C     | C*P* comments indicating place holders for which code is
                0548 C     |      presently being developed.
4c563c2ee9 Chri*0549 C     *==========================================================*
                0550 C     \ev
                0551 
                0552 C     !CALLING SEQUENCE:
                0553 C     THE_MODEL_MAIN()
                0554 C       |
                0555 C       |
b75fe8c753 Jean*0556 C       |--INITIALISE_FIXED
4c563c2ee9 Chri*0557 C       |   o Set model configuration (fixed arrays)
                0558 C       |     Topography, hydrography, timestep, grid, etc..
                0559 C       |
                0560 C       |--CTRL_UNPACK      o Derivative mode. Unpack control vector.
                0561 C       |
                0562 C       |--ADTHE_MAIN_LOOP  o Main timestepping loop for combined
                0563 C       |                     prognostic and reverse mode integration.
                0564 C       |
                0565 C       |--THE_MAIN_LOOP    o Main timestepping loop for pure prognostic
                0566 C       |                     integration.
                0567 C       |
c493e58557 Jean*0568 C       |--CTRL_PACK        o Derivative mode. Unpack control vector.
                0569 C       |
                0570 C       |--GRDCHK_MAIN      o Gradient check control routine.
4c563c2ee9 Chri*0571 C       |
                0572 C       |--TIMER_PRINTALL   o Print out timing statistics.
                0573 C       |
                0574 C       |--COMM_STATS       o Print out communication statistics.
                0575 
                0576 C     !USES:
c493e58557 Jean*0577       IMPLICIT NONE
                0578 
924557e60a Chri*0579 C     == Global variables ===
                0580 #include "SIZE.h"
                0581 #include "EEPARAMS.h"
                0582 #include "PARAMS.h"
                0583 #include "DYNVARS.h"
                0584 
7c50f07931 Mart*0585 #ifdef ALLOW_AUTODIFF_TAMC
4c6316f049 Patr*0586 # include "tamc.h"
f891280854 Patr*0587 #endif
                0588 #ifdef ALLOW_CTRL
5cf4364659 Mart*0589 # include "CTRL_SIZE.h"
4d72283393 Mart*0590 # include "CTRL.h"
65754df434 Mart*0591 # include "OPTIMCYCLE.h"
2dcaa8b9a5 Patr*0592 #endif
                0593 
4c563c2ee9 Chri*0594 C     !INPUT/OUTPUT PARAMETERS:
924557e60a Chri*0595 C     == Routine arguments ==
c493e58557 Jean*0596 C     myThid :: Thread number for this instance of the routine.
455a90837c Jean*0597       INTEGER myThid
924557e60a Chri*0598 
4c563c2ee9 Chri*0599 C     !LOCAL VARIABLES:
924557e60a Chri*0600 C     == Local variables ==
c493e58557 Jean*0601 C     Note: Under the multi-threaded model myIter and myTime are local
                0602 C           variables passed around as routine arguments.
                0603 C           Although this is fiddly it saves the need to impose
                0604 C           additional synchronisation points when they are updated.
                0605 C     myTime :: Time counter for this thread
                0606 C     myIter :: Iteration counter for this thread
                0607       INTEGER myIter
                0608       _RL     myTime
39f5b178fe Jean*0609       LOGICAL exst
                0610       LOGICAL lastdiva
4c563c2ee9 Chri*0611 CEOP
39f5b178fe Jean*0612 
                0613 C--   set default:
c493e58557 Jean*0614       exst     = .TRUE.
d0f9afb496 Patr*0615       lastdiva = .TRUE.
924557e60a Chri*0616 
49e3578e36 Ed H*0617 #ifdef ALLOW_DEBUG
b75fe8c753 Jean*0618       IF (debugMode) CALL DEBUG_ENTER('THE_MODEL_MAIN',myThid)
73ead277e0 Alis*0619 #endif
                0620 
008ba3ca0d Cons*0621 #if defined(USE_PAPI) || defined(USE_PCL_FLOPS_SFP) || defined(USE_PCL_FLOPS) || defined(USE_PCL)
95c84ca63e Cons*0622       CALL TIMER_CONTROL('','INIT','THE_MODEL_MAIN',myThid)
                0623 #endif
9c997a3be5 Alis*0624 C--   This timer encompasses the whole code
22f0d78f5f Patr*0625       CALL TIMER_START('ALL                    [THE_MODEL_MAIN]',myThid)
9c997a3be5 Alis*0626 
49e3578e36 Ed H*0627 #ifdef ALLOW_DEBUG
b75fe8c753 Jean*0628       IF (debugMode) CALL DEBUG_CALL('INITIALISE_FIXED',myThid)
73ead277e0 Alis*0629 #endif
2846da876f Alis*0630 C--   Set model configuration (fixed arrays)
22f0d78f5f Patr*0631       CALL TIMER_START('INITIALISE_FIXED       [THE_MODEL_MAIN]',myThid)
2846da876f Alis*0632       CALL INITIALISE_FIXED( myThid )
22f0d78f5f Patr*0633       CALL TIMER_STOP ('INITIALISE_FIXED       [THE_MODEL_MAIN]',myThid)
924557e60a Chri*0634 
c493e58557 Jean*0635       myTime = startTime
                0636       myIter = nIter0
45e66f2c69 Jean*0637 
edd57506ae Patr*0638 #if ( defined (ALLOW_ADMTLM) )
39f5b178fe Jean*0639 
8f0b59c61c Patr*0640       STOP 'should never get here; ADMTLM_DSVD calls ADMTLM_DRIVER'
39f5b178fe Jean*0641 
edd57506ae Patr*0642 #elif ( defined (ALLOW_AUTODIFF))
2dcaa8b9a5 Patr*0643 
cfdbfa0351 Gael*0644 # ifdef ALLOW_CTRL
4c6316f049 Patr*0645 # ifndef EXCLUDE_CTRL_PACK
a424c359ed Gael*0646       IF ( useCTRL ) THEN
39154404ca Patr*0647          inquire( file='costfinal', exist=exst )
ad933537f6 Patr*0648          IF ( .NOT. exst ) THEN
31b221ddf5 Gael*0649             IF ( (optimcycle.NE.0 .OR. .NOT.doinitxx)
                0650      &           .AND. doMainUnpack ) THEN
c493e58557 Jean*0651                CALL TIMER_START('CTRL_UNPACK   [THE_MODEL_MAIN]',myThid)
                0652                CALL CTRL_UNPACK( .TRUE. , myThid )
                0653                CALL TIMER_STOP ('CTRL_UNPACK   [THE_MODEL_MAIN]',myThid)
7dab2b24d1 Patr*0654             ENDIF
158ba1800d Patr*0655          ENDIF
a424c359ed Gael*0656        ENDIF
4c6316f049 Patr*0657 # endif /* EXCLUDE_CTRL_PACK */
cfdbfa0351 Gael*0658 # endif
2dcaa8b9a5 Patr*0659 
170b439592 Patr*0660 # ifdef ALLOW_COST
c493e58557 Jean*0661       CALL COST_DEPENDENT_INIT ( myThid )
170b439592 Patr*0662 # endif
084c120559 Patr*0663 
37e373688b Mart*0664 # if defined( ALLOW_TANGENTLINEAR_RUN )
39f5b178fe Jean*0665 
b4daa24319 Shre*0666 # ifndef ALLOW_TAPENADE
                0667 
c493e58557 Jean*0668 #  ifdef ALLOW_DEBUG
643a66b10d Patr*0669       IF (debugMode) CALL DEBUG_CALL('G_THE_MAIN_LOOP',myThid)
c493e58557 Jean*0670 #  endif
                0671       CALL TIMER_START('G_THE_MAIN_LOOP           [TANGENT RUN]',myThid)
                0672       CALL G_THE_MAIN_LOOP ( myTime, myIter, myThid )
                0673       CALL TIMER_STOP ('G_THE_MAIN_LOOP           [TANGENT RUN]',myThid)
39f5b178fe Jean*0674 
b4daa24319 Shre*0675 # endif /* ndef ALLOW_TAPENADE */
                0676 
37e373688b Mart*0677 # elif defined( ALLOW_ADJOINT_RUN )
39f5b178fe Jean*0678 
b4daa24319 Shre*0679 # ifdef ALLOW_TAPENADE
                0680         CALL THE_MAIN_LOOP_B( myTime, myIter, myThid )
                0681 # else /* ALLOW_TAPENADE */
                0682 
6e06d0f445 Patr*0683 #  ifdef ALLOW_DIVIDED_ADJOINT
39f5b178fe Jean*0684 C-- The following assumes the TAF option '-pure'
39154404ca Patr*0685       inquire( file='costfinal', exist=exst )
                0686       IF ( .NOT. exst) THEN
c493e58557 Jean*0687 #   ifdef ALLOW_DEBUG
643a66b10d Patr*0688          IF (debugMode) CALL DEBUG_CALL('MDTHE_MAIN_LOOP',myThid)
c493e58557 Jean*0689 #   endif
                0690          CALL TIMER_START('MDTHE_MAIN_LOOP            [MD RUN]', myThid)
                0691          CALL MDTHE_MAIN_LOOP ( myTime, myIter, myThid )
                0692          CALL TIMER_STOP ('MDTHE_MAIN_LOOP            [MD RUN]', myThid)
                0693          CALL COST_FINAL_STORE ( myThid, lastdiva )
39154404ca Patr*0694       ELSE
c493e58557 Jean*0695 #   ifdef ALLOW_DEBUG
643a66b10d Patr*0696          IF (debugMode) CALL DEBUG_CALL('ADTHE_MAIN_LOOP',myThid)
c493e58557 Jean*0697 #   endif
                0698          CALL TIMER_START('ADTHE_MAIN_LOOP       [ADJOINT RUN]', myThid)
                0699          CALL ADTHE_MAIN_LOOP (  myThid )
                0700          CALL TIMER_STOP ('ADTHE_MAIN_LOOP       [ADJOINT RUN]', myThid)
                0701          CALL COST_FINAL_RESTORE ( myThid, lastdiva )
39154404ca Patr*0702       ENDIF
39f5b178fe Jean*0703 
6e06d0f445 Patr*0704 #  else /* ALLOW_DIVIDED_ADJOINT undef */
c493e58557 Jean*0705 #   ifdef ALLOW_DEBUG
643a66b10d Patr*0706       IF (debugMode) CALL DEBUG_CALL('ADTHE_MAIN_LOOP',myThid)
c493e58557 Jean*0707 #   endif
                0708       CALL TIMER_START('ADTHE_MAIN_LOOP          [ADJOINT RUN]', myThid)
                0709       CALL ADTHE_MAIN_LOOP ( myThid )
                0710       CALL TIMER_STOP ('ADTHE_MAIN_LOOP          [ADJOINT RUN]', myThid)
6e06d0f445 Patr*0711 #  endif /* ALLOW_DIVIDED_ADJOINT */
b4daa24319 Shre*0712 # endif /* ALLOW_TAPENADE */
39f5b178fe Jean*0713 
f891280854 Patr*0714 # else /* forward run only within AD setting */
                0715 
c493e58557 Jean*0716 #  ifdef ALLOW_DEBUG
f891280854 Patr*0717       IF (debugMode) CALL DEBUG_CALL('THE_MAIN_LOOP',myThid)
c493e58557 Jean*0718 #  endif
f891280854 Patr*0719 C--   Call time stepping loop of full model
                0720       CALL TIMER_START('THE_MAIN_LOOP          [THE_MODEL_MAIN]',myThid)
c493e58557 Jean*0721       CALL THE_MAIN_LOOP( myTime, myIter, myThid )
f891280854 Patr*0722       CALL TIMER_STOP ('THE_MAIN_LOOP          [THE_MODEL_MAIN]',myThid)
                0723 
c493e58557 Jean*0724 # endif /* forward run only within AD setting */
084c120559 Patr*0725 
cfdbfa0351 Gael*0726 # ifdef ALLOW_CTRL
b4daa24319 Shre*0727 #  ifndef EXCLUDE_CTRL_PACK
a424c359ed Gael*0728       IF ( useCTRL ) THEN
7807741270 Gael*0729       IF ( lastdiva .AND. doMainPack ) THEN
c493e58557 Jean*0730          CALL TIMER_START('CTRL_PACK           [THE_MODEL_MAIN]',myThid)
                0731          CALL CTRL_PACK( .FALSE. , myThid )
                0732          CALL TIMER_STOP ('CTRL_PACK           [THE_MODEL_MAIN]',myThid)
8276b82da5 Patr*0733          IF ( ( optimcycle.EQ.0 .OR. (.NOT. doMainUnpack) )
c493e58557 Jean*0734      &        .AND. myIter.EQ.nIter0 ) THEN
                0735             CALL TIMER_START('CTRL_PACK     [THE_MODEL_MAIN]',myThid)
                0736             CALL CTRL_PACK( .TRUE. , myThid )
                0737             CALL TIMER_STOP ('CTRL_PACK     [THE_MODEL_MAIN]',myThid)
051651c583 Patr*0738          ENDIF
084c120559 Patr*0739       ENDIF
a424c359ed Gael*0740       ENDIF
b4daa24319 Shre*0741 #  endif /* EXCLUDE_CTRL_PACK */
                0742 # endif /* ALLOW_CTRL */
4c6316f049 Patr*0743 
edd57506ae Patr*0744 # ifdef ALLOW_GRDCHK
39154404ca Patr*0745       IF ( useGrdchk .AND. lastdiva ) THEN
c493e58557 Jean*0746          CALL TIMER_START('GRDCHK_MAIN         [THE_MODEL_MAIN]',myThid)
                0747          CALL GRDCHK_MAIN( myThid )
                0748          CALL TIMER_STOP ('GRDCHK_MAIN         [THE_MODEL_MAIN]',myThid)
39154404ca Patr*0749       ENDIF
edc3e287c7 Patr*0750 # endif
39154404ca Patr*0751 
edc3e287c7 Patr*0752 #else /* ALL AD-related undef */
2dcaa8b9a5 Patr*0753 
c493e58557 Jean*0754 # ifdef ALLOW_DEBUG
73ead277e0 Alis*0755       IF (debugMode) CALL DEBUG_CALL('THE_MAIN_LOOP',myThid)
c493e58557 Jean*0756 # endif
2846da876f Alis*0757 C--   Call time stepping loop of full model
22f0d78f5f Patr*0758       CALL TIMER_START('THE_MAIN_LOOP          [THE_MODEL_MAIN]',myThid)
c493e58557 Jean*0759       CALL THE_MAIN_LOOP( myTime, myIter, myThid )
22f0d78f5f Patr*0760       CALL TIMER_STOP ('THE_MAIN_LOOP          [THE_MODEL_MAIN]',myThid)
5e81fe432e Alis*0761 
0b5e42db1b Patr*0762 #endif /* ALLOW_TANGENTLINEAR_RUN ALLOW_ADJOINT_RUN ALLOW_ADMTLM */
cfb68e7b57 Chri*0763 
55cfdd6eeb Jean*0764 #ifdef ALLOW_STREAMICE
                0765       IF (useStreamIce) THEN
                0766         CALL STREAMICE_FINALIZE_PETSC
                0767       ENDIF
6fc4c6c58c Dani*0768 #endif
                0769 
251b9a88c9 Ed H*0770 #ifdef ALLOW_MNC
5ba1ba83f0 Ed H*0771       IF (useMNC) THEN
                0772 C       Close all open NetCDF files
c493e58557 Jean*0773         _BEGIN_MASTER( myThid )
5ba1ba83f0 Ed H*0774         CALL MNC_FILE_CLOSE_ALL( myThid )
c493e58557 Jean*0775         _END_MASTER( myThid )
5ba1ba83f0 Ed H*0776       ENDIF
251b9a88c9 Ed H*0777 #endif
                0778 
455a90837c Jean*0779 C--   This timer encompasses the whole code
                0780       CALL TIMER_STOP ('ALL                    [THE_MODEL_MAIN]',myThid)
                0781 
9c997a3be5 Alis*0782 C--   Write timer statistics
a85d6ab24e Chri*0783       IF ( myThid .EQ. 1 ) THEN
                0784        CALL TIMER_PRINTALL( myThid )
                0785        CALL COMM_STATS
                0786       ENDIF
66dc79a095 Chri*0787 
36d9303bf2 Jean*0788 C--   Check threads synchronization :
                0789       CALL BAR_CHECK( 9, myThid )
                0790 
49e3578e36 Ed H*0791 #ifdef ALLOW_DEBUG
73ead277e0 Alis*0792       IF (debugMode) CALL DEBUG_LEAVE('THE_MODEL_MAIN',myThid)
                0793 #endif
                0794 
924557e60a Chri*0795       RETURN
                0796       END