\hypertarget{MOM_8F90_source}{}\section{M\+O\+M.\+F90}
\label{MOM_8F90_source}\index{/home/cermak/src/\+M\+O\+M6/src/core/\+M\+O\+M.\+F90@{/home/cermak/src/\+M\+O\+M6/src/core/\+M\+O\+M.\+F90}}

\begin{DoxyCode}
00001 \textcolor{comment}{!> The central module of the MOM6 ocean model}
\Hypertarget{MOM_8F90_source_l00002}\hyperlink{namespacemom}{00002} \textcolor{keyword}{module} \hyperlink{namespacemom}{mom}
00003 
00004 \textcolor{comment}{! This file is part of MOM6. See LICENSE.md for the license.}
00005 
00006 \textcolor{comment}{! Infrastructure modules}
00007 \textcolor{keywordtype}{use }mom\_array\_transform\textcolor{keywordtype}{,      only} : rotate\_array, rotate\_vector
00008 \textcolor{keywordtype}{use }mom\_debugging\textcolor{keywordtype}{,            only} : mom\_debugging\_init, hchksum, uvchksum
00009 \textcolor{keywordtype}{use }mom\_debugging\textcolor{keywordtype}{,            only} : check\_redundant
00010 \textcolor{keywordtype}{use }mom\_checksum\_packages\textcolor{keywordtype}{,    only} : mom\_thermo\_chksum, mom\_state\_chksum
00011 \textcolor{keywordtype}{use }mom\_checksum\_packages\textcolor{keywordtype}{,    only} : mom\_accel\_chksum, mom\_surface\_chksum
00012 \textcolor{keywordtype}{use }mom\_coms\textcolor{keywordtype}{,                 only} : num\_pes
00013 \textcolor{keywordtype}{use }mom\_cpu\_clock\textcolor{keywordtype}{,            only} : cpu\_clock\_id, cpu\_clock\_begin, cpu\_clock\_end
00014 \textcolor{keywordtype}{use }mom\_cpu\_clock\textcolor{keywordtype}{,            only} : clock\_component, clock\_subcomponent
00015 \textcolor{keywordtype}{use }mom\_cpu\_clock\textcolor{keywordtype}{,            only} : clock\_module\_driver, clock\_module, clock\_routine
00016 \textcolor{keywordtype}{use }mom\_diag\_mediator\textcolor{keywordtype}{,        only} : diag\_mediator\_init, enable\_averaging, enable\_averages
00017 \textcolor{keywordtype}{use }mom\_diag\_mediator\textcolor{keywordtype}{,        only} : diag\_mediator\_infrastructure\_init
00018 \textcolor{keywordtype}{use }mom\_diag\_mediator\textcolor{keywordtype}{,        only} : diag\_set\_state\_ptrs, diag\_update\_remap\_grids
00019 \textcolor{keywordtype}{use }mom\_diag\_mediator\textcolor{keywordtype}{,        only} : disable\_averaging, post\_data, safe\_alloc\_ptr
00020 \textcolor{keywordtype}{use }mom\_diag\_mediator\textcolor{keywordtype}{,        only} : register\_diag\_field, register\_cell\_measure
00021 \textcolor{keywordtype}{use }mom\_diag\_mediator\textcolor{keywordtype}{,        only} : set\_axes\_info, diag\_ctrl, diag\_masks\_set
00022 \textcolor{keywordtype}{use }mom\_diag\_mediator\textcolor{keywordtype}{,        only} : set\_masks\_for\_axes
00023 \textcolor{keywordtype}{use }mom\_diag\_mediator\textcolor{keywordtype}{,        only} : diag\_grid\_storage, diag\_grid\_storage\_init
00024 \textcolor{keywordtype}{use }mom\_diag\_mediator\textcolor{keywordtype}{,        only} : diag\_save\_grids, diag\_restore\_grids
00025 \textcolor{keywordtype}{use }mom\_diag\_mediator\textcolor{keywordtype}{,        only} : diag\_copy\_storage\_to\_diag, diag\_copy\_diag\_to\_storage
00026 \textcolor{keywordtype}{use }mom\_domains\textcolor{keywordtype}{,              only} : mom\_domains\_init, clone\_mom\_domain
00027 \textcolor{keywordtype}{use }mom\_domains\textcolor{keywordtype}{,              only} : sum\_across\_pes, pass\_var, pass\_vector
00028 \textcolor{keywordtype}{use }mom\_domains\textcolor{keywordtype}{,              only} : to\_north, to\_east, to\_south, to\_west
00029 \textcolor{keywordtype}{use }mom\_domains\textcolor{keywordtype}{,              only} : to\_all, omit\_corners, cgrid\_ne, scalar\_pair
00030 \textcolor{keywordtype}{use }mom\_domains\textcolor{keywordtype}{,              only} : create\_group\_pass, do\_group\_pass, group\_pass\_type
00031 \textcolor{keywordtype}{use }mom\_domains\textcolor{keywordtype}{,              only} : start\_group\_pass, complete\_group\_pass, omit\_corners
00032 \textcolor{keywordtype}{use }mom\_error\_handler\textcolor{keywordtype}{,        only} : mom\_error, mom\_mesg, fatal, warning, is\_root\_pe
00033 \textcolor{keywordtype}{use }mom\_error\_handler\textcolor{keywordtype}{,        only} : mom\_set\_verbosity, calltree\_showquery
00034 \textcolor{keywordtype}{use }mom\_error\_handler\textcolor{keywordtype}{,        only} : calltree\_enter, calltree\_leave, calltree\_waypoint
00035 \textcolor{keywordtype}{use }mom\_file\_parser\textcolor{keywordtype}{,          only} : read\_param, get\_param, log\_version, param\_file\_type
00036 \textcolor{keywordtype}{use }mom\_forcing\_type\textcolor{keywordtype}{,         only} : forcing, mech\_forcing
00037 \textcolor{keywordtype}{use }mom\_forcing\_type\textcolor{keywordtype}{,         only} : mom\_forcing\_chksum, mom\_mech\_forcing\_chksum
00038 \textcolor{keywordtype}{use }mom\_get\_input\textcolor{keywordtype}{,            only} : get\_mom\_input, directories
00039 \textcolor{keywordtype}{use }mom\_io\textcolor{keywordtype}{,                   only} : mom\_io\_init, vardesc, var\_desc
00040 \textcolor{keywordtype}{use }mom\_io\textcolor{keywordtype}{,                   only} : slasher, file\_exists, mom\_read\_data
00041 \textcolor{keywordtype}{use }mom\_obsolete\_params\textcolor{keywordtype}{,      only} : find\_obsolete\_params
00042 \textcolor{keywordtype}{use }mom\_restart\textcolor{keywordtype}{,              only} : register\_restart\_field, register\_restart\_pair
00043 \textcolor{keywordtype}{use }mom\_restart\textcolor{keywordtype}{,              only} : query\_initialized, save\_restart
00044 \textcolor{keywordtype}{use }mom\_restart\textcolor{keywordtype}{,              only} : restart\_init, is\_new\_run, mom\_restart\_cs
00045 \textcolor{keywordtype}{use }mom\_spatial\_means\textcolor{keywordtype}{,        only} : global\_mass\_integral
00046 \textcolor{keywordtype}{use }mom\_time\_manager\textcolor{keywordtype}{,         only} : time\_type, real\_to\_time, time\_type\_to\_real, \textcolor{keyword}{operator}(+)
00047 \textcolor{keywordtype}{use }mom\_time\_manager\textcolor{keywordtype}{,         only} : \textcolor{keyword}{operator}(-), \textcolor{keyword}{operator}(>), \textcolor{keyword}{operator}(*), \textcolor{keyword}{operator}(/)
00048 \textcolor{keywordtype}{use }mom\_time\_manager\textcolor{keywordtype}{,         only} : \textcolor{keyword}{operator}(>=), \textcolor{keyword}{operator}(==), increment\_date
00049 \textcolor{keywordtype}{use }mom\_unit\_tests\textcolor{keywordtype}{,           only} : unit\_tests
00050 \textcolor{keywordtype}{use }coupler\_types\_mod\textcolor{keywordtype}{,        only} : coupler\_type\_send\_data, coupler\_1d\_bc\_type, coupler\_type\_spawn
00051 
00052 \textcolor{comment}{! MOM core modules}
00053 \textcolor{keywordtype}{use }\hyperlink{namespacemom__ale}{mom\_ale}\textcolor{keywordtype}{,                   only} : \hyperlink{namespacemom__ale_a7e9593dbe4be5138cb83327df05e1d7b}{ale\_init}, \hyperlink{namespacemom__ale_a807a4412504e91df4f21e33afe9779f3}{ale\_end}, 
      \hyperlink{namespacemom__ale_ac56eac14cd9b8909082c1d4fe4e98152}{ale\_main}, \hyperlink{structmom__ale_1_1ale__cs}{ale\_cs}, \hyperlink{namespacemom__ale_a870a226e28a2cdafad0537d3365d85af}{adjustgridforintegrity}
00054 \textcolor{keywordtype}{use }\hyperlink{namespacemom__ale}{mom\_ale}\textcolor{keywordtype}{,                   only} : \hyperlink{namespacemom__ale_a761eeb0993d81b0cb168aaebbbb2bc07}{ale\_getcoordinate}, 
      \hyperlink{namespacemom__ale_a8c448db5dde525b0571809132bf5e075}{ale\_getcoordinateunits}, \hyperlink{namespacemom__ale_a8a784e56b0acbcda92f7af471d2c980d}{ale\_writecoordinatefile}
00055 \textcolor{keywordtype}{use }\hyperlink{namespacemom__ale}{mom\_ale}\textcolor{keywordtype}{,                   only} : \hyperlink{namespacemom__ale_a86cb18b00e146a754f09ef6a46cd7878}{ale\_updateverticalgridtype}, 
      \hyperlink{namespacemom__ale_a9e4ec7771d6291fc72884796b23922b3}{ale\_remap\_init\_conds}, \hyperlink{namespacemom__ale_ac9b603b29f630dc8498e35a0e5c16a53}{ale\_register\_diags}
00056 \textcolor{keywordtype}{use }mom\_ale\_sponge\textcolor{keywordtype}{,            only} : rotate\_ale\_sponge, update\_ale\_sponge\_field
00057 \textcolor{keywordtype}{use }mom\_barotropic\textcolor{keywordtype}{,            only} : barotropic\_cs
00058 \textcolor{keywordtype}{use }mom\_boundary\_update\textcolor{keywordtype}{,       only} : call\_obc\_register, obc\_register\_end, update\_obc\_cs
00059 \textcolor{keywordtype}{use }mom\_coord\_initialization\textcolor{keywordtype}{,  only} : mom\_initialize\_coord
00060 \textcolor{keywordtype}{use }mom\_diabatic\_driver\textcolor{keywordtype}{,       only} : diabatic, diabatic\_driver\_init, diabatic\_cs, extract\_diabatic\_member
00061 \textcolor{keywordtype}{use }mom\_diabatic\_driver\textcolor{keywordtype}{,       only} : adiabatic, adiabatic\_driver\_init, diabatic\_driver\_end
00062 \textcolor{keywordtype}{use }mom\_diagnostics\textcolor{keywordtype}{,           only} : calculate\_diagnostic\_fields, mom\_diagnostics\_init
00063 \textcolor{keywordtype}{use }mom\_diagnostics\textcolor{keywordtype}{,           only} : register\_transport\_diags, post\_transport\_diagnostics
00064 \textcolor{keywordtype}{use }mom\_diagnostics\textcolor{keywordtype}{,           only} : register\_surface\_diags, write\_static\_fields
00065 \textcolor{keywordtype}{use }mom\_diagnostics\textcolor{keywordtype}{,           only} : post\_surface\_dyn\_diags, post\_surface\_thermo\_diags
00066 \textcolor{keywordtype}{use }mom\_diagnostics\textcolor{keywordtype}{,           only} : diagnostics\_cs, surface\_diag\_ids, transport\_diag\_ids
00067 \textcolor{keywordtype}{use }mom\_dynamics\_unsplit\textcolor{keywordtype}{,      only} : step\_mom\_dyn\_unsplit, register\_restarts\_dyn\_unsplit
00068 \textcolor{keywordtype}{use }mom\_dynamics\_unsplit\textcolor{keywordtype}{,      only} : initialize\_dyn\_unsplit, end\_dyn\_unsplit
00069 \textcolor{keywordtype}{use }mom\_dynamics\_unsplit\textcolor{keywordtype}{,      only} : mom\_dyn\_unsplit\_cs
00070 \textcolor{keywordtype}{use }mom\_dynamics\_split\_rk2\textcolor{keywordtype}{,    only} : step\_mom\_dyn\_split\_rk2, register\_restarts\_dyn\_split\_rk2
00071 \textcolor{keywordtype}{use }mom\_dynamics\_split\_rk2\textcolor{keywordtype}{,    only} : initialize\_dyn\_split\_rk2, end\_dyn\_split\_rk2
00072 \textcolor{keywordtype}{use }mom\_dynamics\_split\_rk2\textcolor{keywordtype}{,    only} : mom\_dyn\_split\_rk2\_cs
00073 \textcolor{keywordtype}{use }mom\_dynamics\_unsplit\_rk2\textcolor{keywordtype}{,  only} : step\_mom\_dyn\_unsplit\_rk2, register\_restarts\_dyn\_unsplit\_rk2
00074 \textcolor{keywordtype}{use }mom\_dynamics\_unsplit\_rk2\textcolor{keywordtype}{,  only} : initialize\_dyn\_unsplit\_rk2, end\_dyn\_unsplit\_rk2
00075 \textcolor{keywordtype}{use }mom\_dynamics\_unsplit\_rk2\textcolor{keywordtype}{,  only} : mom\_dyn\_unsplit\_rk2\_cs
00076 \textcolor{keywordtype}{use }mom\_dyn\_horgrid\textcolor{keywordtype}{,           only} : dyn\_horgrid\_type, create\_dyn\_horgrid, destroy\_dyn\_horgrid
00077 \textcolor{keywordtype}{use }\hyperlink{namespacemom__eos}{mom\_eos}\textcolor{keywordtype}{,                   only} : \hyperlink{namespacemom__eos_a3ab220b9c98dac3b8f6b7c1606b811cf}{eos\_init}, \hyperlink{interfacemom__eos_1_1calculate__density}{calculate\_density}, 
      \hyperlink{interfacemom__eos_1_1calculate__tfreeze}{calculate\_tfreeze}, \hyperlink{namespacemom__eos_a782d326108e390902e520efc078e8296}{eos\_domain}
00078 \textcolor{keywordtype}{use }mom\_fixed\_initialization\textcolor{keywordtype}{,  only} : mom\_initialize\_fixed
00079 \textcolor{keywordtype}{use }mom\_forcing\_type\textcolor{keywordtype}{,          only} : allocate\_forcing\_type, allocate\_mech\_forcing
00080 \textcolor{keywordtype}{use }mom\_forcing\_type\textcolor{keywordtype}{,          only} : deallocate\_mech\_forcing, deallocate\_forcing\_type
00081 \textcolor{keywordtype}{use }mom\_forcing\_type\textcolor{keywordtype}{,          only} : rotate\_forcing, rotate\_mech\_forcing
00082 \textcolor{keywordtype}{use }mom\_grid\textcolor{keywordtype}{,                  only} : ocean\_grid\_type, mom\_grid\_init, mom\_grid\_end
00083 \textcolor{keywordtype}{use }mom\_grid\textcolor{keywordtype}{,                  only} : set\_first\_direction, rescale\_grid\_bathymetry
00084 \textcolor{keywordtype}{use }mom\_hor\_index\textcolor{keywordtype}{,             only} : hor\_index\_type, hor\_index\_init
00085 \textcolor{keywordtype}{use }mom\_hor\_index\textcolor{keywordtype}{,             only} : rotate\_hor\_index
00086 \textcolor{keywordtype}{use }mom\_interface\_heights\textcolor{keywordtype}{,     only} : find\_eta
00087 \textcolor{keywordtype}{use }mom\_lateral\_mixing\_coeffs\textcolor{keywordtype}{, only} : calc\_slope\_functions, varmix\_init
00088 \textcolor{keywordtype}{use }mom\_lateral\_mixing\_coeffs\textcolor{keywordtype}{, only} : calc\_resoln\_function, calc\_depth\_function, varmix\_cs
00089 \textcolor{keywordtype}{use }\hyperlink{namespacemom__meke}{mom\_meke}\textcolor{keywordtype}{,                  only} : \hyperlink{namespacemom__meke_a099f1cfad37430ef1bd60972a92b1be4}{meke\_init}, 
      \hyperlink{namespacemom__meke_a1900316331157e48f1a6029bac63fbd0}{meke\_alloc\_register\_restart}, \hyperlink{namespacemom__meke_a5f752f097ddeba7071e1703110e51bc2}{step\_forward\_meke}, 
      \hyperlink{structmom__meke_1_1meke__cs}{meke\_cs}
00090 \textcolor{keywordtype}{use }mom\_meke\_types\textcolor{keywordtype}{,            only} : meke\_type
00091 \textcolor{keywordtype}{use }mom\_mixed\_layer\_restrat\textcolor{keywordtype}{,   only} : mixedlayer\_restrat, mixedlayer\_restrat\_init, mixedlayer\_restrat\_cs
00092 \textcolor{keywordtype}{use }mom\_mixed\_layer\_restrat\textcolor{keywordtype}{,   only} : mixedlayer\_restrat\_register\_restarts
00093 \textcolor{keywordtype}{use }mom\_obsolete\_diagnostics\textcolor{keywordtype}{,  only} : register\_obsolete\_diagnostics
00094 \textcolor{keywordtype}{use }mom\_open\_boundary\textcolor{keywordtype}{,         only} : ocean\_obc\_type, obc\_registry\_type
00095 \textcolor{keywordtype}{use }mom\_open\_boundary\textcolor{keywordtype}{,         only} : register\_temp\_salt\_segments
00096 \textcolor{keywordtype}{use }mom\_open\_boundary\textcolor{keywordtype}{,         only} : open\_boundary\_register\_restarts
00097 \textcolor{keywordtype}{use }mom\_open\_boundary\textcolor{keywordtype}{,         only} : update\_segment\_tracer\_reservoirs
00098 \textcolor{keywordtype}{use }mom\_open\_boundary\textcolor{keywordtype}{,         only} : rotate\_obc\_config, rotate\_obc\_init
00099 \textcolor{keywordtype}{use }mom\_set\_visc\textcolor{keywordtype}{,              only} : set\_viscous\_bbl, set\_viscous\_ml, set\_visc\_init
00100 \textcolor{keywordtype}{use }mom\_set\_visc\textcolor{keywordtype}{,              only} : set\_visc\_register\_restarts, set\_visc\_cs
00101 \textcolor{keywordtype}{use }mom\_sponge\textcolor{keywordtype}{,                only} : init\_sponge\_diags, sponge\_cs
00102 \textcolor{keywordtype}{use }mom\_state\_initialization\textcolor{keywordtype}{,  only} : mom\_initialize\_state
00103 \textcolor{keywordtype}{use }mom\_sum\_output\textcolor{keywordtype}{,            only} : write\_energy, accumulate\_net\_input
00104 \textcolor{keywordtype}{use }mom\_sum\_output\textcolor{keywordtype}{,            only} : mom\_sum\_output\_init, sum\_output\_cs
00105 \textcolor{keywordtype}{use }mom\_ale\_sponge\textcolor{keywordtype}{,            only} : init\_ale\_sponge\_diags, ale\_sponge\_cs
00106 \textcolor{keywordtype}{use }mom\_thickness\_diffuse\textcolor{keywordtype}{,     only} : thickness\_diffuse, thickness\_diffuse\_init, thickness\_diffuse\_cs
00107 \textcolor{keywordtype}{use }mom\_tracer\_advect\textcolor{keywordtype}{,         only} : advect\_tracer, tracer\_advect\_init
00108 \textcolor{keywordtype}{use }mom\_tracer\_advect\textcolor{keywordtype}{,         only} : tracer\_advect\_end, tracer\_advect\_cs
00109 \textcolor{keywordtype}{use }mom\_tracer\_hor\_diff\textcolor{keywordtype}{,       only} : tracer\_hordiff, tracer\_hor\_diff\_init
00110 \textcolor{keywordtype}{use }mom\_tracer\_hor\_diff\textcolor{keywordtype}{,       only} : tracer\_hor\_diff\_end, tracer\_hor\_diff\_cs
00111 \textcolor{keywordtype}{use }mom\_tracer\_registry\textcolor{keywordtype}{,       only} : tracer\_registry\_type, register\_tracer, tracer\_registry\_init
00112 \textcolor{keywordtype}{use }mom\_tracer\_registry\textcolor{keywordtype}{,       only} : register\_tracer\_diagnostics, post\_tracer\_diagnostics\_at\_sync
00113 \textcolor{keywordtype}{use }mom\_tracer\_registry\textcolor{keywordtype}{,       only} : post\_tracer\_transport\_diagnostics
00114 \textcolor{keywordtype}{use }mom\_tracer\_registry\textcolor{keywordtype}{,       only} : preale\_tracer\_diagnostics, postale\_tracer\_diagnostics
00115 \textcolor{keywordtype}{use }mom\_tracer\_registry\textcolor{keywordtype}{,       only} : lock\_tracer\_registry, tracer\_registry\_end
00116 \textcolor{keywordtype}{use }mom\_tracer\_flow\_control\textcolor{keywordtype}{,   only} : call\_tracer\_register, tracer\_flow\_control\_cs
00117 \textcolor{keywordtype}{use }mom\_tracer\_flow\_control\textcolor{keywordtype}{,   only} : tracer\_flow\_control\_init, call\_tracer\_surface\_state
00118 \textcolor{keywordtype}{use }mom\_tracer\_flow\_control\textcolor{keywordtype}{,   only} : tracer\_flow\_control\_end
00119 \textcolor{keywordtype}{use }mom\_transcribe\_grid\textcolor{keywordtype}{,       only} : copy\_dyngrid\_to\_mom\_grid, copy\_mom\_grid\_to\_dyngrid
00120 \textcolor{keywordtype}{use }mom\_transcribe\_grid\textcolor{keywordtype}{,       only} : rotate\_dyngrid
00121 \textcolor{keywordtype}{use }\hyperlink{namespacemom__unit__scaling}{mom\_unit\_scaling}\textcolor{keywordtype}{,          only} : \hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\_scale\_type}, 
      \hyperlink{namespacemom__unit__scaling_a74867ddf628f93dcee854980e08bbe21}{unit\_scaling\_init}
00122 \textcolor{keywordtype}{use }\hyperlink{namespacemom__unit__scaling}{mom\_unit\_scaling}\textcolor{keywordtype}{,          only} : \hyperlink{namespacemom__unit__scaling_a6b58ce1b6a08d07a84da1257cd8e8694}{unit\_scaling\_end}, 
      \hyperlink{namespacemom__unit__scaling_a0d99ae286970838e8f4cd534e3a2744c}{fix\_restart\_unit\_scaling}
00123 \textcolor{keywordtype}{use }mom\_variables\textcolor{keywordtype}{,             only} : surface, allocate\_surface\_state, deallocate\_surface\_state
00124 \textcolor{keywordtype}{use }mom\_variables\textcolor{keywordtype}{,             only} : thermo\_var\_ptrs, vertvisc\_type
00125 \textcolor{keywordtype}{use }mom\_variables\textcolor{keywordtype}{,             only} : accel\_diag\_ptrs, cont\_diag\_ptrs, ocean\_internal\_state
00126 \textcolor{keywordtype}{use }mom\_variables\textcolor{keywordtype}{,             only} : rotate\_surface\_state
00127 \textcolor{keywordtype}{use }mom\_verticalgrid\textcolor{keywordtype}{,          only} : verticalgrid\_type, verticalgridinit, verticalgridend
00128 \textcolor{keywordtype}{use }mom\_verticalgrid\textcolor{keywordtype}{,          only} : fix\_restart\_scaling
00129 \textcolor{keywordtype}{use }mom\_verticalgrid\textcolor{keywordtype}{,          only} : get\_thickness\_units, get\_flux\_units, get\_tr\_flux\_units
00130 \textcolor{keywordtype}{use }mom\_wave\_interface\textcolor{keywordtype}{,        only} : wave\_parameters\_cs, waves\_end
00131 \textcolor{keywordtype}{use }mom\_wave\_interface\textcolor{keywordtype}{,        only} : update\_stokes\_drift
00132 
00133 \textcolor{comment}{! ODA modules}
00134 \textcolor{keywordtype}{use }mom\_oda\_driver\_mod\textcolor{keywordtype}{,        only} : oda\_cs, oda, init\_oda, oda\_end
00135 \textcolor{keywordtype}{use }mom\_oda\_driver\_mod\textcolor{keywordtype}{,        only} : set\_prior\_tracer, set\_analysis\_time, apply\_oda\_tracer\_increments
00136 \textcolor{comment}{! Offline modules}
00137 \textcolor{keywordtype}{use }mom\_offline\_main\textcolor{keywordtype}{,          only} : offline\_transport\_cs, offline\_transport\_init, update\_offline\_fields
00138 \textcolor{keywordtype}{use }mom\_offline\_main\textcolor{keywordtype}{,          only} : insert\_offline\_main, extract\_offline\_main, 
      post\_offline\_convergence\_diags
00139 \textcolor{keywordtype}{use }mom\_offline\_main\textcolor{keywordtype}{,          only} : register\_diags\_offline\_transport, offline\_advection\_ale
00140 \textcolor{keywordtype}{use }mom\_offline\_main\textcolor{keywordtype}{,          only} : offline\_redistribute\_residual, offline\_diabatic\_ale
00141 \textcolor{keywordtype}{use }mom\_offline\_main\textcolor{keywordtype}{,          only} : offline\_fw\_fluxes\_into\_ocean, offline\_fw\_fluxes\_out\_ocean
00142 \textcolor{keywordtype}{use }mom\_offline\_main\textcolor{keywordtype}{,          only} : offline\_advection\_layer, offline\_transport\_end
00143 \textcolor{keywordtype}{use }\hyperlink{namespacemom__ale}{mom\_ale}\textcolor{keywordtype}{,                   only} : \hyperlink{namespacemom__ale_aa7a1311028c2cd514b4b5224c5c7fe17}{ale\_offline\_tracer\_final}, 
      \hyperlink{namespacemom__ale_a666f48c8fa163fe717e60bd6ed749a75}{ale\_main\_offline}
00144 
00145 \textcolor{keywordtype}{implicit none} ; \textcolor{keywordtype}{private}
00146 
00147 \textcolor{preprocessor}{#include <MOM\_memory.h>}
00148 \textcolor{preprocessor}{}
00149 \textcolor{comment}{! A note on unit descriptions in comments: MOM6 uses units that can be rescaled for dimensional}
00150 \textcolor{comment}{! consistency testing. These are noted in comments with units like Z, H, L, and T, along with}
00151 \textcolor{comment}{! their mks counterparts with notation like "a velocity [Z T-1 ~> m s-1]".  If the units}
00152 \textcolor{comment}{! vary with the Boussinesq approximation, the Boussinesq variant is given first.}
00153 \textcolor{comment}{}
00154 \textcolor{comment}{!> A structure with diagnostic IDs of the state variables}
\Hypertarget{MOM_8F90_source_l00155}\hyperlink{structmom_1_1mom__diag__ids}{00155} \textcolor{keyword}{type} \hyperlink{structmom_1_1mom__diag__ids}{mom\_diag\_ids}\textcolor{comment}{}
00156 \textcolor{comment}{  !>@\{ 3-d state field diagnostic IDs}
\Hypertarget{MOM_8F90_source_l00157}\hyperlink{structmom_1_1mom__diag__ids_a802103ec652217b7a275b3e07f53a4bd}{00157}   \textcolor{keywordtype}{integer} :: id\_u  = -1, id\_v  = -1, id\_h  = -1\textcolor{comment}{}
00158 \textcolor{comment}{  !>@\}}
00159 \textcolor{comment}{  !> 2-d state field diagnotic ID}
\Hypertarget{MOM_8F90_source_l00160}\hyperlink{structmom_1_1mom__diag__ids_aad05a1eea9309ea226eb88df2ee994e8}{00160}   \textcolor{keywordtype}{integer} :: id\_ssh\_inst = -1
00161 \textcolor{keyword}{end type }\hyperlink{structmom_1_1mom__diag__ids}{mom\_diag\_ids}
00162 \textcolor{comment}{}
00163 \textcolor{comment}{!> Control structure for the MOM module, including the variables that describe}
00164 \textcolor{comment}{!! the state of the ocean.}
\Hypertarget{MOM_8F90_source_l00165}\hyperlink{structmom_1_1mom__control__struct}{00165} \textcolor{keyword}{type}, \textcolor{keyword}{public} :: \hyperlink{structmom_1_1mom__control__struct}{mom\_control\_struct} ; \textcolor{keywordtype}{private}
\Hypertarget{MOM_8F90_source_l00166}\hyperlink{structmom_1_1mom__control__struct_a413f451f58de77fad58c1684f7219575}{00166}   \textcolor{keywordtype}{real} allocable\_, \textcolor{keywordtype}{dimension(NIMEM\_,NJMEM\_,NKMEM\_)} :: &
00167     h, &            !< layer thickness [H ~> m or kg m-2]
00168     t, &            !< potential temperature [degC]
00169     s\textcolor{comment}{               !< salinity [ppt]}
\Hypertarget{MOM_8F90_source_l00170}\hyperlink{structmom_1_1mom__control__struct_a7b39d7e621c4859c87d7d81fa68b9534}{00170}   \textcolor{keywordtype}{real} allocable\_, \textcolor{keywordtype}{dimension(NIMEMB\_PTR\_,NJMEM\_,NKMEM\_)} :: &
00171     u,  &           !< zonal velocity component [L T-1 ~> m s-1]
00172     uh, &           !< uh = u * h * dy at u grid points [H L2 T-1 ~> m3 s-1 or kg s-1]
00173     uhtr\textcolor{comment}{            !< accumulated zonal thickness fluxes to advect tracers [H L2 ~> m3 or kg]}
\Hypertarget{MOM_8F90_source_l00174}\hyperlink{structmom_1_1mom__control__struct_aa7c0a799de59e9cb4b5802033c74da35}{00174}   \textcolor{keywordtype}{real} allocable\_, \textcolor{keywordtype}{dimension(NIMEM\_,NJMEMB\_PTR\_,NKMEM\_)} :: &
00175     v,  &           !< meridional velocity [L T-1 ~> m s-1]
00176     vh, &           !< vh = v * h * dx at v grid points [H L2 T-1 ~> m3 s-1 or kg s-1]
00177     vhtr\textcolor{comment}{            !< accumulated meridional thickness fluxes to advect tracers [H L2 ~> m3 or kg]}
\Hypertarget{MOM_8F90_source_l00178}\hyperlink{structmom_1_1mom__control__struct_aa436a1001e0aa8dfb091f6398c444452}{00178}   \textcolor{keywordtype}{real} allocable\_, \textcolor{keywordtype}{dimension(NIMEM\_,NJMEM\_)} :: ssh\_rint
00179                     \textcolor{comment}{!< A running time integral of the sea surface height [T m ~> s m].}
\Hypertarget{MOM_8F90_source_l00180}\hyperlink{structmom_1_1mom__control__struct_a4814ada2b387f4449709b825ce56f8e4}{00180}   \textcolor{keywordtype}{real} allocable\_, \textcolor{keywordtype}{dimension(NIMEM\_,NJMEM\_)} :: ave\_ssh\_ibc
00181                     \textcolor{comment}{!< time-averaged (over a forcing time step) sea surface height}
00182 \textcolor{comment}{                    !! with a correction for the inverse barometer [m]}
\Hypertarget{MOM_8F90_source_l00183}\hyperlink{structmom_1_1mom__control__struct_ae6201f764166d1e7fb5bc5a01ab6cd36}{00183}   \textcolor{keywordtype}{real} allocable\_, \textcolor{keywordtype}{dimension(NIMEM\_,NJMEM\_)} :: eta\_av\_bc
00184                     \textcolor{comment}{!< free surface height or column mass time averaged over the last}
00185 \textcolor{comment}{                    !! baroclinic dynamics time step [H ~> m or kg m-2]}
\Hypertarget{MOM_8F90_source_l00186}\hyperlink{structmom_1_1mom__control__struct_a4a54cf3cefeab1fcaee5ed33bd7d38ee}{00186}   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer} :: &
00187     hml => null()   \textcolor{comment}{!< active mixed layer depth [Z ~> m]}
\Hypertarget{MOM_8F90_source_l00188}\hyperlink{structmom_1_1mom__control__struct_a8d2568366dbc4e291463a9e85887fc45}{00188}   \textcolor{keywordtype}{real} :: time\_in\_cycle\textcolor{comment}{ !< The running time of the current time-stepping cycle}
00189 \textcolor{comment}{                    !! in calls that step the dynamics, and also the length of}
00190 \textcolor{comment}{                    !! the time integral of ssh\_rint [T ~> s].}
\Hypertarget{MOM_8F90_source_l00191}\hyperlink{structmom_1_1mom__control__struct_a9b15fb018eb1d35d2b91235388d95f8a}{00191}   \textcolor{keywordtype}{real} :: time\_in\_thermo\_cycle\textcolor{comment}{ !< The running time of the current time-stepping}
00192 \textcolor{comment}{                    !! cycle in calls that step the thermodynamics [T ~> s].}
00193 
\Hypertarget{MOM_8F90_source_l00194}\hyperlink{structmom_1_1mom__control__struct_ab5ddc1c09b08d967824c8a7ae8e8acdf}{00194}   \textcolor{keywordtype}{type}(ocean\_grid\_type) :: g\_in\textcolor{comment}{                   !< Input grid metric}
\Hypertarget{MOM_8F90_source_l00195}\hyperlink{structmom_1_1mom__control__struct_a6dd5a43deff76a7c05cdfc68a9176910}{00195}   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{pointer} :: g => null()   \textcolor{comment}{!< Model grid metric}
\Hypertarget{MOM_8F90_source_l00196}\hyperlink{structmom_1_1mom__control__struct_ae5558224098abfaf731d63cfc9f33e6e}{00196}   \textcolor{keywordtype}{logical} :: rotate\_index = .false.   \textcolor{comment}{!< True if index map is rotated}
00197 
\Hypertarget{MOM_8F90_source_l00198}\hyperlink{structmom_1_1mom__control__struct_ab205c7b3f059710df49901a13d297d92}{00198}   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{pointer} :: &
00199     gv => null()    \textcolor{comment}{!< structure containing vertical grid info}
\Hypertarget{MOM_8F90_source_l00200}\hyperlink{structmom_1_1mom__control__struct_a49d85380cefccee147f10996ac288b4c}{00200}   \textcolor{keywordtype}{type}(\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\_scale\_type}), \textcolor{keywordtype}{pointer} :: &
00201     us => null()    \textcolor{comment}{!< structure containing various unit conversion factors}
\Hypertarget{MOM_8F90_source_l00202}\hyperlink{structmom_1_1mom__control__struct_ab3fc3759e2063c33100069eae737b0a0}{00202}   \textcolor{keywordtype}{type}(thermo\_var\_ptrs) :: tv\textcolor{comment}{ !< structure containing pointers to available thermodynamic fields}
\Hypertarget{MOM_8F90_source_l00203}\hyperlink{structmom_1_1mom__control__struct_a7873e23a6f09e8cc5dcda4af06b0d37c}{00203}   \textcolor{keywordtype}{real} :: t\_dyn\_rel\_adv\textcolor{comment}{ !< The time of the dynamics relative to tracer advection and lateral mixing}
00204 \textcolor{comment}{                    !! [T ~> s], or equivalently the elapsed time since advectively updating the}
00205 \textcolor{comment}{                    !! tracers.  t\_dyn\_rel\_adv is invariably positive and may span multiple coupling
       timesteps.}
\Hypertarget{MOM_8F90_source_l00206}\hyperlink{structmom_1_1mom__control__struct_a6157bdea12cdce1a886c41ff5862624d}{00206}   \textcolor{keywordtype}{real} :: t\_dyn\_rel\_thermo\textcolor{comment}{  !< The time of the dynamics relative to diabatic  processes and remapping}
00207 \textcolor{comment}{                    !! [T ~> s].  t\_dyn\_rel\_thermo can be negative or positive depending on whether}
00208 \textcolor{comment}{                    !! the diabatic processes are applied before or after the dynamics and may span}
00209 \textcolor{comment}{                    !! multiple coupling timesteps.}
\Hypertarget{MOM_8F90_source_l00210}\hyperlink{structmom_1_1mom__control__struct_afc1b65ca9eeed960dc98034e5a5100fc}{00210}   \textcolor{keywordtype}{real} :: t\_dyn\_rel\_diag\textcolor{comment}{ !< The time of the diagnostics relative to diabatic processes and remapping}
00211 \textcolor{comment}{                    !!  [T ~> s].  t\_dyn\_rel\_diag is always positive, since the diagnostics must lag.}
\Hypertarget{MOM_8F90_source_l00212}\hyperlink{structmom_1_1mom__control__struct_a5096c261cb23ef8d3287bc13e588e190}{00212}   \textcolor{keywordtype}{logical} :: preadv\_h\_stored = .false. \textcolor{comment}{!< If true, the thicknesses from before the advective cycle}
00213 \textcolor{comment}{                    !! have been stored for use in diagnostics.}
00214 
\Hypertarget{MOM_8F90_source_l00215}\hyperlink{structmom_1_1mom__control__struct_aec5da80b0ebe462abb2f46072077a677}{00215}   \textcolor{keywordtype}{type}(diag\_ctrl)     :: diag\textcolor{comment}{ !< structure to regulate diagnostic output timing}
\Hypertarget{MOM_8F90_source_l00216}\hyperlink{structmom_1_1mom__control__struct_a805132adc40078fd89ff9cafcc5be9d4}{00216}   \textcolor{keywordtype}{type}(vertvisc\_type) :: visc\textcolor{comment}{ !< structure containing vertical viscosities,}
00217 \textcolor{comment}{                    !! bottom drag viscosities, and related fields}
\Hypertarget{MOM_8F90_source_l00218}\hyperlink{structmom_1_1mom__control__struct_a1cf898780b418f2f6e8c1e020df13101}{00218}   \textcolor{keywordtype}{type}(meke\_type), \textcolor{keywordtype}{pointer} :: meke => null() \textcolor{comment}{!<  structure containing fields}
00219 \textcolor{comment}{                    !! related to the Mesoscale Eddy Kinetic Energy}
\Hypertarget{MOM_8F90_source_l00220}\hyperlink{structmom_1_1mom__control__struct_acbd630d2c637e8a9b1c589ffd8a21a4c}{00220}   \textcolor{keywordtype}{logical} :: adiabatic\textcolor{comment}{ !< If true, there are no diapycnal mass fluxes, and no calls}
00221 \textcolor{comment}{                    !! to routines to calculate or apply diapycnal fluxes.}
\Hypertarget{MOM_8F90_source_l00222}\hyperlink{structmom_1_1mom__control__struct_ab946757ec7ac61cc5e8b86db28f75b71}{00222}   \textcolor{keywordtype}{logical} :: diabatic\_first\textcolor{comment}{ !< If true, apply diabatic and thermodynamic processes before time}
00223 \textcolor{comment}{                    !! stepping the dynamics.}
\Hypertarget{MOM_8F90_source_l00224}\hyperlink{structmom_1_1mom__control__struct_a3da458f68d8939c9f3a99726b8a7cd3c}{00224}   \textcolor{keywordtype}{logical} :: use\_ale\_algorithm\textcolor{comment}{  !< If true, use the ALE algorithm rather than layered}
00225 \textcolor{comment}{                    !! isopycnal/stacked shallow water mode. This logical is set by calling the}
00226 \textcolor{comment}{                    !! function useRegridding() from the MOM\_regridding module.}
\Hypertarget{MOM_8F90_source_l00227}\hyperlink{structmom_1_1mom__control__struct_ac4d6f003dee79f4aae0bcf3559fed974}{00227}   \textcolor{keywordtype}{logical} :: offline\_tracer\_mode = .false.
00228                     \textcolor{comment}{!< If true, step\_offline() is called instead of step\_MOM().}
00229 \textcolor{comment}{                    !! This is intended for running MOM6 in offline tracer mode}
00230 
\Hypertarget{MOM_8F90_source_l00231}\hyperlink{structmom_1_1mom__control__struct_abbd22c4b35df9fa53a98803a5e9733e4}{00231}   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{pointer} :: time\textcolor{comment}{   !< pointer to the ocean clock}
\Hypertarget{MOM_8F90_source_l00232}\hyperlink{structmom_1_1mom__control__struct_aa0ffc40dfa1896668a7f6a4ef184d23b}{00232}   \textcolor{keywordtype}{real}    :: dt\textcolor{comment}{                      !< (baroclinic) dynamics time step [T ~> s]}
\Hypertarget{MOM_8F90_source_l00233}\hyperlink{structmom_1_1mom__control__struct_a2ab46a5df0a650fd8f06f46a3d6245a5}{00233}   \textcolor{keywordtype}{real}    :: dt\_therm\textcolor{comment}{                !< thermodynamics time step [T ~> s]}
\Hypertarget{MOM_8F90_source_l00234}\hyperlink{structmom_1_1mom__control__struct_aac9d8ffe86c453a7fe640d49de48f26d}{00234}   \textcolor{keywordtype}{logical} :: thermo\_spans\_coupling\textcolor{comment}{   !< If true, thermodynamic and tracer time}
00235 \textcolor{comment}{                                     !! steps can span multiple coupled time steps.}
\Hypertarget{MOM_8F90_source_l00236}\hyperlink{structmom_1_1mom__control__struct_a04860c2f18792e2a9d758381209475f7}{00236}   \textcolor{keywordtype}{integer} :: nstep\_tot = 0\textcolor{comment}{           !< The total number of dynamic timesteps tcaaken}
00237 \textcolor{comment}{                                     !! so far in this run segment}
\Hypertarget{MOM_8F90_source_l00238}\hyperlink{structmom_1_1mom__control__struct_aeeb688df731886090ba880ab77546b86}{00238}   \textcolor{keywordtype}{logical} :: count\_calls = .false.   \textcolor{comment}{!< If true, count the calls to step\_MOM, rather than the}
00239 \textcolor{comment}{                                     !! number of dynamics steps in nstep\_tot}
\Hypertarget{MOM_8F90_source_l00240}\hyperlink{structmom_1_1mom__control__struct_a2546b5ef81e24446eedaab7471775cc5}{00240}   \textcolor{keywordtype}{logical} :: debug\textcolor{comment}{                   !< If true, write verbose checksums for debugging purposes.}
\Hypertarget{MOM_8F90_source_l00241}\hyperlink{structmom_1_1mom__control__struct_aecb7bf1c6aa3a76b7a9ef4ad9fc21600}{00241}   \textcolor{keywordtype}{integer} :: ntrunc\textcolor{comment}{                  !< number u,v truncations since last call to write\_energy}
00242 
\Hypertarget{MOM_8F90_source_l00243}\hyperlink{structmom_1_1mom__control__struct_aae0a66af192bca27a55e10f78936df8f}{00243}   \textcolor{keywordtype}{integer} :: cont\_stencil\textcolor{comment}{            !< The stencil for thickness from the continuity solver.}
00244   \textcolor{comment}{! These elements are used to control the dynamics updates.}
\Hypertarget{MOM_8F90_source_l00245}\hyperlink{structmom_1_1mom__control__struct_a8b78ad039d8accc587e1632db96f8c50}{00245}   \textcolor{keywordtype}{logical} :: do\_dynamics\textcolor{comment}{             !< If false, does not call step\_MOM\_dyn\_*. This is an}
00246 \textcolor{comment}{                                     !! undocumented run-time flag that is fragile.}
\Hypertarget{MOM_8F90_source_l00247}\hyperlink{structmom_1_1mom__control__struct_aeb79044bc3941fe1be7c0612227f931f}{00247}   \textcolor{keywordtype}{logical} :: split\textcolor{comment}{                   !< If true, use the split time stepping scheme.}
\Hypertarget{MOM_8F90_source_l00248}\hyperlink{structmom_1_1mom__control__struct_a73e0ffc2be4b504f7126a2e256140b79}{00248}   \textcolor{keywordtype}{logical} :: use\_rk2\textcolor{comment}{                 !< If true, use RK2 instead of RK3 in unsplit mode}
00249 \textcolor{comment}{                                     !! (i.e., no split between barotropic and baroclinic).}
\Hypertarget{MOM_8F90_source_l00250}\hyperlink{structmom_1_1mom__control__struct_a4ea3807b7193541b13fb9e698a375991}{00250}   \textcolor{keywordtype}{logical} :: thickness\_diffuse\textcolor{comment}{       !< If true, diffuse interface height w/ a diffusivity KHTH.}
\Hypertarget{MOM_8F90_source_l00251}\hyperlink{structmom_1_1mom__control__struct_ae656df189815ae80df88b5c3bd9af903}{00251}   \textcolor{keywordtype}{logical} :: thickness\_diffuse\_first\textcolor{comment}{ !< If true, diffuse thickness before dynamics.}
\Hypertarget{MOM_8F90_source_l00252}\hyperlink{structmom_1_1mom__control__struct_a32562ff6712350e219ce59fdb54f635d}{00252}   \textcolor{keywordtype}{logical} :: mixedlayer\_restrat\textcolor{comment}{      !< If true, use submesoscale mixed layer restratifying scheme.}
\Hypertarget{MOM_8F90_source_l00253}\hyperlink{structmom_1_1mom__control__struct_a7a5574f401322901f56a30f01c9a659e}{00253}   \textcolor{keywordtype}{logical} :: usemeke\textcolor{comment}{                 !< If true, call the MEKE parameterization.}
\Hypertarget{MOM_8F90_source_l00254}\hyperlink{structmom_1_1mom__control__struct_aba5ba389f5025b7b04df1cef7df6cf85}{00254}   \textcolor{keywordtype}{logical} :: usewaves\textcolor{comment}{                !< If true, update Stokes drift}
\Hypertarget{MOM_8F90_source_l00255}\hyperlink{structmom_1_1mom__control__struct_ae3c22fd3c4073450204ab1ed3025075a}{00255}   \textcolor{keywordtype}{logical} :: use\_p\_surf\_in\_eos\textcolor{comment}{       !< If true, always include the surface pressure contributions}
00256 \textcolor{comment}{                                     !! in equation of state calculations.}
\Hypertarget{MOM_8F90_source_l00257}\hyperlink{structmom_1_1mom__control__struct_ae6167f203a12605da528d11efee9d884}{00257}   \textcolor{keywordtype}{real} :: dtbt\_reset\_period\textcolor{comment}{          !< The time interval between dynamic recalculation of the}
00258 \textcolor{comment}{                                     !! barotropic time step [s]. If this is negative dtbt is never}
00259 \textcolor{comment}{                                     !! calculated, and if it is 0, dtbt is calculated every step.}
\Hypertarget{MOM_8F90_source_l00260}\hyperlink{structmom_1_1mom__control__struct_aee537bba989ecdcf2bbe653c0cfff25d}{00260}   \textcolor{keywordtype}{type}(time\_type) :: dtbt\_reset\_interval\textcolor{comment}{ !< A time\_time representation of dtbt\_reset\_period.}
\Hypertarget{MOM_8F90_source_l00261}\hyperlink{structmom_1_1mom__control__struct_afacaed7a0bd96e00d85b4910a903092c}{00261}   \textcolor{keywordtype}{type}(time\_type) :: dtbt\_reset\_time\textcolor{comment}{ !< The next time DTBT should be calculated.}
00262 
00263 
\Hypertarget{MOM_8F90_source_l00264}\hyperlink{structmom_1_1mom__control__struct_a79686d17b3078b97cadc5e86feedf66c}{00264}   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{pointer} :: &
00265     h\_pre\_dyn => null(), &      \textcolor{comment}{!< The thickness before the transports [H ~> m or kg m-2].}
00266     t\_pre\_dyn => null(), &      \textcolor{comment}{!< Temperature before the transports [degC].}
00267     s\_pre\_dyn => null()         \textcolor{comment}{!< Salinity before the transports [ppt].}
\Hypertarget{MOM_8F90_source_l00268}\hyperlink{structmom_1_1mom__control__struct_aedfeaf76e50745e9c9b2b83123a23f82}{00268}   \textcolor{keywordtype}{type}(accel\_diag\_ptrs) :: adp\textcolor{comment}{  !< structure containing pointers to accelerations,}
00269 \textcolor{comment}{                                !! for derived diagnostics (e.g., energy budgets)}
\Hypertarget{MOM_8F90_source_l00270}\hyperlink{structmom_1_1mom__control__struct_a4afeec8c4b37a043d92aade401ff9f9c}{00270}   \textcolor{keywordtype}{type}(cont\_diag\_ptrs)  :: cdp\textcolor{comment}{  !< structure containing pointers to continuity equation}
00271 \textcolor{comment}{                                !! terms, for derived diagnostics (e.g., energy budgets)}
\Hypertarget{MOM_8F90_source_l00272}\hyperlink{structmom_1_1mom__control__struct_abbfa0c8349eb72d4dddfb316a451acbf}{00272}   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{pointer} :: &
00273     u\_prev => null(), &         \textcolor{comment}{!< previous value of u stored for diagnostics [L T-1 ~> m s-1]}
00274     v\_prev => null()            \textcolor{comment}{!< previous value of v stored for diagnostics [L T-1 ~> m s-1]}
00275 
\Hypertarget{MOM_8F90_source_l00276}\hyperlink{structmom_1_1mom__control__struct_aa846ef099ea4520d282c70ece10e2ac8}{00276}   \textcolor{keywordtype}{logical} :: interp\_p\_surf\textcolor{comment}{      !< If true, linearly interpolate surface pressure}
00277 \textcolor{comment}{                                !! over the coupling time step, using specified value}
00278 \textcolor{comment}{                                !! at the end of the coupling step. False by default.}
\Hypertarget{MOM_8F90_source_l00279}\hyperlink{structmom_1_1mom__control__struct_a8ae9343f18bba2d1e5c67762cc7ae21e}{00279}   \textcolor{keywordtype}{logical} :: p\_surf\_prev\_set\textcolor{comment}{    !< If true, p\_surf\_prev has been properly set from}
00280 \textcolor{comment}{                                !! a previous time-step or the ocean restart file.}
00281 \textcolor{comment}{                                !! This is only valid when interp\_p\_surf is true.}
\Hypertarget{MOM_8F90_source_l00282}\hyperlink{structmom_1_1mom__control__struct_a54c96a0a4178f50e04984b2938c6c673}{00282}   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer} :: &
00283     p\_surf\_prev  => null(), &   \textcolor{comment}{!< surface pressure [R L2 T-2 ~> Pa] at end  previous call to step\_MOM}
00284     p\_surf\_begin => null(), &   \textcolor{comment}{!< surface pressure [R L2 T-2 ~> Pa] at start of step\_MOM\_dyn\_...}
00285     p\_surf\_end   => null()      \textcolor{comment}{!< surface pressure [R L2 T-2 ~> Pa] at end   of step\_MOM\_dyn\_...}
00286 
00287   \textcolor{comment}{! Variables needed to reach between start and finish phases of initialization}
\Hypertarget{MOM_8F90_source_l00288}\hyperlink{structmom_1_1mom__control__struct_ad499608d5706eeba8f48c7405e6da2a4}{00288}   \textcolor{keywordtype}{logical} :: write\_ic\textcolor{comment}{           !< If true, then the initial conditions will be written to file}
\Hypertarget{MOM_8F90_source_l00289}\hyperlink{structmom_1_1mom__control__struct_ad5fbeeb6e0ba13c72125bd1a3c0fc7e1}{00289}   \textcolor{keywordtype}{character(len=120)} :: ic\_file\textcolor{comment}{ !< A file into which the initial conditions are}
00290 \textcolor{comment}{                                !! written in a new run if SAVE\_INITIAL\_CONDS is true.}
00291 
\Hypertarget{MOM_8F90_source_l00292}\hyperlink{structmom_1_1mom__control__struct_a8b479a1786b90290e77ddf43ae15d5db}{00292}   \textcolor{keywordtype}{logical} :: calc\_rho\_for\_sea\_lev\textcolor{comment}{ !< If true, calculate rho to convert pressure to sea level}
00293 
00294   \textcolor{comment}{! These elements are used to control the calculation and error checking of the surface state}
\Hypertarget{MOM_8F90_source_l00295}\hyperlink{structmom_1_1mom__control__struct_a89cc8335447212d841f70adb6d053ed7}{00295}   \textcolor{keywordtype}{real} :: hmix\textcolor{comment}{                  !< Diagnostic mixed layer thickness over which to}
00296 \textcolor{comment}{                                !! average surface tracer properties when a bulk}
00297 \textcolor{comment}{                                !! mixed layer is not used [Z ~> m], or a negative value}
00298 \textcolor{comment}{                                !! if a bulk mixed layer is being used.}
\Hypertarget{MOM_8F90_source_l00299}\hyperlink{structmom_1_1mom__control__struct_a2048415f0007407a9c22ceef74e3ef36}{00299}   \textcolor{keywordtype}{real} :: hfrz\textcolor{comment}{                  !< If HFrz > 0, the nominal depth over which melt potential is}
00300 \textcolor{comment}{                                !! computed [Z ~> m]. The actual depth over which melt potential is}
00301 \textcolor{comment}{                                !! computed is min(HFrz, OBLD), where OBLD is the boundary layer depth.}
00302 \textcolor{comment}{                                !! If HFrz <= 0 (default), melt potential will not be computed.}
\Hypertarget{MOM_8F90_source_l00303}\hyperlink{structmom_1_1mom__control__struct_ae5a4f1d3c24bfe971530a1dc5db89a0d}{00303}   \textcolor{keywordtype}{real} :: hmix\_uv\textcolor{comment}{               !< Depth scale over which to average surface flow to}
00304 \textcolor{comment}{                                !! feedback to the coupler/driver [Z ~> m] when}
00305 \textcolor{comment}{                                !! bulk mixed layer is not used, or a negative value}
00306 \textcolor{comment}{                                !! if a bulk mixed layer is being used.}
\Hypertarget{MOM_8F90_source_l00307}\hyperlink{structmom_1_1mom__control__struct_a6599c0ff775ab86ebfbb2903328de4d4}{00307}   \textcolor{keywordtype}{logical} :: check\_bad\_sfc\_vals\textcolor{comment}{ !< If true, scan surface state for ridiculous values.}
\Hypertarget{MOM_8F90_source_l00308}\hyperlink{structmom_1_1mom__control__struct_ade2ba755a077383c8ac76291fb34113c}{00308}   \textcolor{keywordtype}{real}    :: bad\_val\_ssh\_max\textcolor{comment}{    !< Maximum SSH before triggering bad value message [Z ~> m]}
\Hypertarget{MOM_8F90_source_l00309}\hyperlink{structmom_1_1mom__control__struct_a679e6c1a7d2c6a618440980d26ce8dce}{00309}   \textcolor{keywordtype}{real}    :: bad\_val\_sst\_max\textcolor{comment}{    !< Maximum SST before triggering bad value message [degC]}
\Hypertarget{MOM_8F90_source_l00310}\hyperlink{structmom_1_1mom__control__struct_a7492ac306c080e3233cc155e7d3f905b}{00310}   \textcolor{keywordtype}{real}    :: bad\_val\_sst\_min\textcolor{comment}{    !< Minimum SST before triggering bad value message [degC]}
\Hypertarget{MOM_8F90_source_l00311}\hyperlink{structmom_1_1mom__control__struct_a014435f3d7febde23643937f8c854a20}{00311}   \textcolor{keywordtype}{real}    :: bad\_val\_sss\_max\textcolor{comment}{    !< Maximum SSS before triggering bad value message [ppt]}
\Hypertarget{MOM_8F90_source_l00312}\hyperlink{structmom_1_1mom__control__struct_a124046446815cd0f11bf062b37b3cf46}{00312}   \textcolor{keywordtype}{real}    :: bad\_val\_col\_thick\textcolor{comment}{  !< Minimum column thickness before triggering bad value message [Z ~> m]}
\Hypertarget{MOM_8F90_source_l00313}\hyperlink{structmom_1_1mom__control__struct_a0c2845f20d7ddcd5098f0448fd1ef570}{00313}   \textcolor{keywordtype}{logical} :: answers\_2018\textcolor{comment}{       !< If true, use expressions for the surface properties that recover}
00314 \textcolor{comment}{                                !! the answers from the end of 2018. Otherwise, use more appropriate}
00315 \textcolor{comment}{                                !! expressions that differ at roundoff for non-Boussinsq cases.}
00316 
\Hypertarget{MOM_8F90_source_l00317}\hyperlink{structmom_1_1mom__control__struct_a165fdb422372e95b3ddf4a6728b3f300}{00317}   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__diag__ids}{mom\_diag\_ids})       :: ids\textcolor{comment}{      !<  Handles used for diagnostics.}
\Hypertarget{MOM_8F90_source_l00318}\hyperlink{structmom_1_1mom__control__struct_a06b14fc2dcb3976aa3a93c9df7c3721a}{00318}   \textcolor{keywordtype}{type}(transport\_diag\_ids) :: transport\_ids\textcolor{comment}{  !< Handles used for transport diagnostics.}
\Hypertarget{MOM_8F90_source_l00319}\hyperlink{structmom_1_1mom__control__struct_a95591a65cb9e7a0fdc75c1e2abed6301}{00319}   \textcolor{keywordtype}{type}(surface\_diag\_ids)   :: sfc\_ids\textcolor{comment}{  !< Handles used for surface diagnostics.}
\Hypertarget{MOM_8F90_source_l00320}\hyperlink{structmom_1_1mom__control__struct_abe34cc87bee937c550ba08c63e01b936}{00320}   \textcolor{keywordtype}{type}(diag\_grid\_storage)  :: diag\_pre\_sync\textcolor{comment}{ !< The grid (thicknesses) before remapping}
\Hypertarget{MOM_8F90_source_l00321}\hyperlink{structmom_1_1mom__control__struct_a7d5f3f992a70f3d7f916b0f0e54256a3}{00321}   \textcolor{keywordtype}{type}(diag\_grid\_storage)  :: diag\_pre\_dyn\textcolor{comment}{  !< The grid (thicknesses) before dynamics}
00322 
00323   \textcolor{comment}{! The remainder of this type provides pointers to child module control structures.}
00324 
\Hypertarget{MOM_8F90_source_l00325}\hyperlink{structmom_1_1mom__control__struct_a3d0af6a54d5556053172230c22d3a3a9}{00325}   \textcolor{keywordtype}{type}(mom\_dyn\_unsplit\_cs),      \textcolor{keywordtype}{pointer} :: dyn\_unsplit\_csp => null()
00326     \textcolor{comment}{!< Pointer to the control structure used for the unsplit dynamics}
\Hypertarget{MOM_8F90_source_l00327}\hyperlink{structmom_1_1mom__control__struct_aeca38d3d757e76a33e3fc24eeaa9e912}{00327}   \textcolor{keywordtype}{type}(mom\_dyn\_unsplit\_rk2\_cs),  \textcolor{keywordtype}{pointer} :: dyn\_unsplit\_rk2\_csp => null()
00328     \textcolor{comment}{!< Pointer to the control structure used for the unsplit RK2 dynamics}
\Hypertarget{MOM_8F90_source_l00329}\hyperlink{structmom_1_1mom__control__struct_ac43561daef3db4d43ec7799647072094}{00329}   \textcolor{keywordtype}{type}(mom\_dyn\_split\_rk2\_cs),    \textcolor{keywordtype}{pointer} :: dyn\_split\_rk2\_csp => null()
00330     \textcolor{comment}{!< Pointer to the control structure used for the mode-split RK2 dynamics}
\Hypertarget{MOM_8F90_source_l00331}\hyperlink{structmom_1_1mom__control__struct_aa3c5973e28710cc4db2e90f192651752}{00331}   \textcolor{keywordtype}{type}(thickness\_diffuse\_cs),    \textcolor{keywordtype}{pointer} :: thickness\_diffuse\_csp => null()
00332     \textcolor{comment}{!< Pointer to the control structure used for the isopycnal height diffusive transport.}
00333 \textcolor{comment}{    !! This is also common referred to as Gent-McWilliams diffusion}
\Hypertarget{MOM_8F90_source_l00334}\hyperlink{structmom_1_1mom__control__struct_abad22a3f431bfb96a1e3826a080c4543}{00334}   \textcolor{keywordtype}{type}(mixedlayer\_restrat\_cs),   \textcolor{keywordtype}{pointer} :: mixedlayer\_restrat\_csp => null()
00335     \textcolor{comment}{!< Pointer to the control structure used for the mixed layer restratification}
\Hypertarget{MOM_8F90_source_l00336}\hyperlink{structmom_1_1mom__control__struct_a4420875a7644b0ac4aaa331f3eb828cf}{00336}   \textcolor{keywordtype}{type}(set\_visc\_cs),             \textcolor{keywordtype}{pointer} :: set\_visc\_csp => null()
00337     \textcolor{comment}{!< Pointer to the control structure used to set viscosities}
\Hypertarget{MOM_8F90_source_l00338}\hyperlink{structmom_1_1mom__control__struct_abe48a9cf3ef6e92d4ee2088ea680a165}{00338}   \textcolor{keywordtype}{type}(diabatic\_cs),             \textcolor{keywordtype}{pointer} :: diabatic\_csp => null()
00339     \textcolor{comment}{!< Pointer to the control structure for the diabatic driver}
\Hypertarget{MOM_8F90_source_l00340}\hyperlink{structmom_1_1mom__control__struct_ab40d39a5b4446372246cb055514db969}{00340}   \textcolor{keywordtype}{type}(\hyperlink{structmom__meke_1_1meke__cs}{meke\_cs}),                 \textcolor{keywordtype}{pointer} :: meke\_csp => null()
00341     \textcolor{comment}{!< Pointer to the control structure for the MEKE updates}
\Hypertarget{MOM_8F90_source_l00342}\hyperlink{structmom_1_1mom__control__struct_a6ac3fdd39f7b29ccc1e388f6d8b18b41}{00342}   \textcolor{keywordtype}{type}(varmix\_cs),               \textcolor{keywordtype}{pointer} :: varmix => null()
00343     \textcolor{comment}{!< Pointer to the control structure for the variable mixing module}
\Hypertarget{MOM_8F90_source_l00344}\hyperlink{structmom_1_1mom__control__struct_a5147086002c714b56a8edb35bd032319}{00344}   \textcolor{keywordtype}{type}(barotropic\_cs),           \textcolor{keywordtype}{pointer} :: barotropic\_csp => null()
00345     \textcolor{comment}{!< Pointer to the control structure for the barotropic module}
\Hypertarget{MOM_8F90_source_l00346}\hyperlink{structmom_1_1mom__control__struct_aa93ae415aa3c314d8972efe135a703f8}{00346}   \textcolor{keywordtype}{type}(tracer\_registry\_type),    \textcolor{keywordtype}{pointer} :: tracer\_reg => null()
00347     \textcolor{comment}{!< Pointer to the MOM tracer registry}
\Hypertarget{MOM_8F90_source_l00348}\hyperlink{structmom_1_1mom__control__struct_a80073431d0fefcfdd02f4b3b027c2ccc}{00348}   \textcolor{keywordtype}{type}(tracer\_advect\_cs),        \textcolor{keywordtype}{pointer} :: tracer\_adv\_csp => null()
00349     \textcolor{comment}{!< Pointer to the MOM tracer advection control structure}
\Hypertarget{MOM_8F90_source_l00350}\hyperlink{structmom_1_1mom__control__struct_ab96ad70ebf5b49f04ccbe838250fd5a9}{00350}   \textcolor{keywordtype}{type}(tracer\_hor\_diff\_cs),      \textcolor{keywordtype}{pointer} :: tracer\_diff\_csp => null()
00351     \textcolor{comment}{!< Pointer to the MOM along-isopycnal tracer diffusion control structure}
\Hypertarget{MOM_8F90_source_l00352}\hyperlink{structmom_1_1mom__control__struct_ac54468719fa025b11defe09a4d4aadaa}{00352}   \textcolor{keywordtype}{type}(tracer\_flow\_control\_cs),  \textcolor{keywordtype}{pointer} :: tracer\_flow\_csp => null()
00353     \textcolor{comment}{!< Pointer to the control structure that orchestrates the calling of tracer packages}
00354     \textcolor{comment}{! Although update\_OBC\_CS is not used directly outside of initialization, other modules}
00355     \textcolor{comment}{! set pointers to this type, so it should be kept for the duration of the run.}
\Hypertarget{MOM_8F90_source_l00356}\hyperlink{structmom_1_1mom__control__struct_a133556146aca486aa24e33d12772b404}{00356}   \textcolor{keywordtype}{type}(update\_obc\_cs),           \textcolor{keywordtype}{pointer} :: update\_obc\_csp => null()
00357     \textcolor{comment}{!< Pointer to the control structure for updating open boundary condition properties}
\Hypertarget{MOM_8F90_source_l00358}\hyperlink{structmom_1_1mom__control__struct_a1b73745290b8a8ce3fa292da754f2ddf}{00358}   \textcolor{keywordtype}{type}(ocean\_obc\_type),          \textcolor{keywordtype}{pointer} :: obc => null()
00359     \textcolor{comment}{!< Pointer to the MOM open boundary condition type}
\Hypertarget{MOM_8F90_source_l00360}\hyperlink{structmom_1_1mom__control__struct_a621d3e8a368d22ce4f8f154d8cc39dda}{00360}   \textcolor{keywordtype}{type}(sponge\_cs),               \textcolor{keywordtype}{pointer} :: sponge\_csp => null()
00361     \textcolor{comment}{!< Pointer to the layered-mode sponge control structure}
\Hypertarget{MOM_8F90_source_l00362}\hyperlink{structmom_1_1mom__control__struct_a2d5a6c9d7de318fba0b755ae35afc325}{00362}   \textcolor{keywordtype}{type}(ale\_sponge\_cs),           \textcolor{keywordtype}{pointer} :: ale\_sponge\_csp => null()
00363     \textcolor{comment}{!< Pointer to the ALE-mode sponge control structure}
\Hypertarget{MOM_8F90_source_l00364}\hyperlink{structmom_1_1mom__control__struct_aa8bfca4726c8b3762f449bd3c01db8cb}{00364}   \textcolor{keywordtype}{type}(\hyperlink{structmom__ale_1_1ale__cs}{ale\_cs}),                  \textcolor{keywordtype}{pointer} :: ale\_csp => null()
00365     \textcolor{comment}{!< Pointer to the Arbitrary Lagrangian Eulerian (ALE) vertical coordinate control structure}
00366 
00367   \textcolor{comment}{! Pointers to control structures used for diagnostics}
\Hypertarget{MOM_8F90_source_l00368}\hyperlink{structmom_1_1mom__control__struct_ae3d681f0e5ced2371c04a34c32bcef82}{00368}   \textcolor{keywordtype}{type}(sum\_output\_cs),           \textcolor{keywordtype}{pointer} :: sum\_output\_csp => null()
00369     \textcolor{comment}{!< Pointer to the globally summed output control structure}
\Hypertarget{MOM_8F90_source_l00370}\hyperlink{structmom_1_1mom__control__struct_a8bd90c3a06349959f8cae27a450ae434}{00370}   \textcolor{keywordtype}{type}(diagnostics\_cs),          \textcolor{keywordtype}{pointer} :: diagnostics\_csp => null()
00371     \textcolor{comment}{!< Pointer to the MOM diagnostics control structure}
\Hypertarget{MOM_8F90_source_l00372}\hyperlink{structmom_1_1mom__control__struct_a87e8a4f63c309aef316b80272b9c75e1}{00372}   \textcolor{keywordtype}{type}(offline\_transport\_cs),    \textcolor{keywordtype}{pointer} :: offline\_csp => null()
00373     \textcolor{comment}{!< Pointer to the offline tracer transport control structure}
00374 
\Hypertarget{MOM_8F90_source_l00375}\hyperlink{structmom_1_1mom__control__struct_a364a3b8bb72a28991320b2c104dac43b}{00375}   \textcolor{keywordtype}{logical}               :: ensemble\_ocean\textcolor{comment}{ !< if true, this run is part of a}
00376 \textcolor{comment}{                                !! larger ensemble for the purpose of data assimilation}
00377 \textcolor{comment}{                                !! or statistical analysis.}
\Hypertarget{MOM_8F90_source_l00378}\hyperlink{structmom_1_1mom__control__struct_a12bd01d4d3a314a5df5a7b098ac1ed1b}{00378}   \textcolor{keywordtype}{type}(oda\_cs), \textcolor{keywordtype}{pointer} :: odacs => null() \textcolor{comment}{!< a pointer to the control structure for handling}
00379 \textcolor{comment}{                                !! ensemble model state vectors and data assimilation}
00380 \textcolor{comment}{                                !! increments and priors}
00381 \textcolor{keyword}{end type }\hyperlink{structmom_1_1mom__control__struct}{mom\_control\_struct}
00382 
00383 \textcolor{keywordtype}{public} \hyperlink{namespacemom_a96708b16215666edbfa5b46228f3a200}{initialize\_mom}, \hyperlink{namespacemom_a2269d5cd79625cbf16cb916346379207}{finish\_mom\_initialization}, 
      \hyperlink{namespacemom_ae6dad976fb4be1c7ba7fc1aff809616b}{mom\_end}
00384 \textcolor{keywordtype}{public} \hyperlink{namespacemom_adf54a4e3a72611aa2088f46076e56e53}{step\_mom}, \hyperlink{namespacemom_ade4f7557fcda73ffc12284d3cecf4182}{step\_offline}
00385 \textcolor{keywordtype}{public} \hyperlink{namespacemom_a699d6c5bfb5b9dcdaa03c18806fa824e}{extract\_surface\_state}, \hyperlink{namespacemom_a462293ed92e99927ef9939747d633080}{get\_ocean\_stocks}
00386 \textcolor{keywordtype}{public} \hyperlink{namespacemom_aece0dd1e2c9498844befd8ba71986b96}{get\_mom\_state\_elements}, \hyperlink{namespacemom_ada38a8329b76f9fa1685a230869a7647}{mom\_state\_is\_synchronized}
00387 \textcolor{keywordtype}{public} allocate\_surface\_state, deallocate\_surface\_state
00388 \textcolor{comment}{}
00389 \textcolor{comment}{!>@\{ CPU time clock IDs}
\Hypertarget{MOM_8F90_source_l00390}\hyperlink{namespacemom_a2e9f4b71ee77ba5bcb3f03a863948db3}{00390} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_a2e9f4b71ee77ba5bcb3f03a863948db3}{id\_clock\_ocean}
\Hypertarget{MOM_8F90_source_l00391}\hyperlink{namespacemom_ae1cf2d523679b925a5e5baa9d974968c}{00391} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_ae1cf2d523679b925a5e5baa9d974968c}{id\_clock\_dynamics}
\Hypertarget{MOM_8F90_source_l00392}\hyperlink{namespacemom_a052256dfa3e56390f62ef3a826d62617}{00392} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_a052256dfa3e56390f62ef3a826d62617}{id\_clock\_thermo}
\Hypertarget{MOM_8F90_source_l00393}\hyperlink{namespacemom_a0fa4debacd02de6fcd066066c232adf3}{00393} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_a0fa4debacd02de6fcd066066c232adf3}{id\_clock\_tracer}
\Hypertarget{MOM_8F90_source_l00394}\hyperlink{namespacemom_a50edf00aa5998073d2db0360949253ba}{00394} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_a50edf00aa5998073d2db0360949253ba}{id\_clock\_diabatic}
\Hypertarget{MOM_8F90_source_l00395}\hyperlink{namespacemom_af865d838388a05163e8de8d266316d5f}{00395} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_af865d838388a05163e8de8d266316d5f}{id\_clock\_adiabatic}
\Hypertarget{MOM_8F90_source_l00396}\hyperlink{namespacemom_aa512b2d8dd73b02634e772701be07a87}{00396} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_aa512b2d8dd73b02634e772701be07a87}{id\_clock\_continuity}  \textcolor{comment}{! also in dynamics s/r}
\Hypertarget{MOM_8F90_source_l00397}\hyperlink{namespacemom_a8f5feb87a0cb40d9fcee00456e982b8a}{00397} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_a8f5feb87a0cb40d9fcee00456e982b8a}{id\_clock\_thick\_diff}
\Hypertarget{MOM_8F90_source_l00398}\hyperlink{namespacemom_aa69e79e4c51e1c24c474b84311322251}{00398} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_aa69e79e4c51e1c24c474b84311322251}{id\_clock\_bbl\_visc}
\Hypertarget{MOM_8F90_source_l00399}\hyperlink{namespacemom_a41b67fabfc13e52cf3a5d1c337c780eb}{00399} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_a41b67fabfc13e52cf3a5d1c337c780eb}{id\_clock\_ml\_restrat}
\Hypertarget{MOM_8F90_source_l00400}\hyperlink{namespacemom_aa773fddb51f99098d75304eb271270d4}{00400} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_aa773fddb51f99098d75304eb271270d4}{id\_clock\_diagnostics}
\Hypertarget{MOM_8F90_source_l00401}\hyperlink{namespacemom_a09f2ac3470372b9ee233f4cc5a7a0da1}{00401} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_a09f2ac3470372b9ee233f4cc5a7a0da1}{id\_clock\_z\_diag}
\Hypertarget{MOM_8F90_source_l00402}\hyperlink{namespacemom_a7cf03c18244d0630616e925bab1841a2}{00402} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_a7cf03c18244d0630616e925bab1841a2}{id\_clock\_init}
\Hypertarget{MOM_8F90_source_l00403}\hyperlink{namespacemom_a4180eb85bab39df7cbb72bb8e5b19fd4}{00403} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_a4180eb85bab39df7cbb72bb8e5b19fd4}{id\_clock\_mom\_init}
\Hypertarget{MOM_8F90_source_l00404}\hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{00404} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass}       \textcolor{comment}{! also in dynamics d/r}
\Hypertarget{MOM_8F90_source_l00405}\hyperlink{namespacemom_ac4d20612cad32d412dae492fedc2e971}{00405} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_ac4d20612cad32d412dae492fedc2e971}{id\_clock\_pass\_init}  \textcolor{comment}{! also in dynamics d/r}
\Hypertarget{MOM_8F90_source_l00406}\hyperlink{namespacemom_a722ed13d0e6d76852e680054a0e3c964}{00406} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_a722ed13d0e6d76852e680054a0e3c964}{id\_clock\_ale}
\Hypertarget{MOM_8F90_source_l00407}\hyperlink{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}{00407} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}{id\_clock\_other}
\Hypertarget{MOM_8F90_source_l00408}\hyperlink{namespacemom_a2ab767469f0d918b9e479d8e0fde44b0}{00408} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_a2ab767469f0d918b9e479d8e0fde44b0}{id\_clock\_offline\_tracer}
\Hypertarget{MOM_8F90_source_l00409}\hyperlink{namespacemom_a785851181d2a3db5a938322d2ff9498a}{00409} \textcolor{keywordtype}{integer} :: \hyperlink{namespacemom_a785851181d2a3db5a938322d2ff9498a}{id\_clock\_unit\_tests}\textcolor{comment}{}
00410 \textcolor{comment}{!>@\}}
00411 
00412 \textcolor{keyword}{contains}
00413 \textcolor{comment}{}
00414 \textcolor{comment}{!> This subroutine orchestrates the time stepping of MOM.  The adiabatic}
00415 \textcolor{comment}{!! dynamics are stepped by calls to one of the step\_MOM\_dyn\_...routines.}
00416 \textcolor{comment}{!! The action of lateral processes on tracers occur in calls to}
00417 \textcolor{comment}{!! advect\_tracer and tracer\_hordiff.  Vertical mixing and possibly remapping}
00418 \textcolor{comment}{!! occur inside of diabatic.}
00419 \textcolor{keyword}{subroutine }\hyperlink{namespacemom_adf54a4e3a72611aa2088f46076e56e53}{step\_mom}(forces\_in, fluxes\_in, sfc\_state, Time\_start, time\_int\_in, CS, &
00420                     Waves, do\_dynamics, do\_thermodynamics, start\_cycle, &
00421                     end\_cycle, cycle\_length, reset\_therm)
\Hypertarget{MOM_8F90_source_l00422}\hyperlink{namespacemom_adf54a4e3a72611aa2088f46076e56e53}{00422}   \textcolor{keywordtype}{type}(mech\_forcing), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: forces\_in\textcolor{comment}{ !< A structure with the driving mechanical forces}
00423   \textcolor{keywordtype}{type}(forcing), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: fluxes\_in\textcolor{comment}{  !< A structure with pointers to themodynamic,}
00424 \textcolor{comment}{                                                     !! tracer and mass exchange forcing fields}
00425   \textcolor{keywordtype}{type}(surface), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: sfc\_state\textcolor{comment}{  !< surface ocean state}
00426   \textcolor{keywordtype}{type}(time\_type),    \textcolor{keywordtype}{intent(in)}    :: Time\_start\textcolor{comment}{    !< starting time of a segment, as a time type}
00427   \textcolor{keywordtype}{real},               \textcolor{keywordtype}{intent(in)}    :: time\_int\_in\textcolor{comment}{   !< time interval covered by this run segment [s].}
00428   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__control__struct}{mom\_control\_struct}), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{            !< control structure from
       initialize\_MOM}
00429   \textcolor{keywordtype}{type}(wave\_parameters\_cs), &
00430             \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: Waves\textcolor{comment}{         !< An optional pointer to a wave property CS}
00431   \textcolor{keywordtype}{logical},  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: do\_dynamics\textcolor{comment}{   !< Present and false, do not do updates due}
00432 \textcolor{comment}{                                                     !! to the dynamics.}
00433   \textcolor{keywordtype}{logical},  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: do\_thermodynamics\textcolor{comment}{  !< Present and false, do not do updates due}
00434 \textcolor{comment}{                                                     !! to the thermodynamics or remapping.}
00435   \textcolor{keywordtype}{logical},  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: start\_cycle\textcolor{comment}{   !< This indicates whether this call is to be}
00436 \textcolor{comment}{                                                     !! treated as the first call to step\_MOM in a}
00437 \textcolor{comment}{                                                     !! time-stepping cycle; missing is like true.}
00438   \textcolor{keywordtype}{logical},  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: end\_cycle\textcolor{comment}{     !< This indicates whether this call is to be}
00439 \textcolor{comment}{                                                     !! treated as the last call to step\_MOM in a}
00440 \textcolor{comment}{                                                     !! time-stepping cycle; missing is like true.}
00441   \textcolor{keywordtype}{real},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: cycle\_length\textcolor{comment}{  !< The amount of time in a coupled time}
00442 \textcolor{comment}{                                                     !! stepping cycle [s].}
00443   \textcolor{keywordtype}{logical},  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: reset\_therm\textcolor{comment}{   !< This indicates whether the running sums of}
00444 \textcolor{comment}{                                                     !! thermodynamic quantities should be reset.}
00445 \textcolor{comment}{                                                     !! If missing, this is like start\_cycle.}
00446 
00447   \textcolor{comment}{! local variables}
00448   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer} :: G => null()  \textcolor{comment}{! pointer to a structure containing}
00449                                                    \textcolor{comment}{! metrics and related information}
00450   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer} :: G\_in => null()  \textcolor{comment}{! Input grid metric}
00451   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{pointer} :: GV => null() \textcolor{comment}{! Pointer to the vertical grid structure}
00452   \textcolor{keywordtype}{type}(\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\_scale\_type}),   \textcolor{keywordtype}{pointer} :: US => null() \textcolor{comment}{! Pointer to a structure containing}
00453                                                    \textcolor{comment}{! various unit conversion factors}
00454   \textcolor{keywordtype}{integer}       :: ntstep \textcolor{comment}{! time steps between tracer updates or diabatic forcing}
00455   \textcolor{keywordtype}{integer}       :: n\_max  \textcolor{comment}{! number of steps to take in this call}
00456 
00457   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz, n
00458   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB
00459 
00460   \textcolor{keywordtype}{real} :: time\_interval   \textcolor{comment}{! time interval covered by this run segment [T ~> s].}
00461   \textcolor{keywordtype}{real} :: dt              \textcolor{comment}{! baroclinic time step [T ~> s]}
00462   \textcolor{keywordtype}{real} :: dtdia           \textcolor{comment}{! time step for diabatic processes [T ~> s]}
00463   \textcolor{keywordtype}{real} :: dt\_therm        \textcolor{comment}{! a limited and quantized version of CS%dt\_therm [T ~> s]}
00464   \textcolor{keywordtype}{real} :: dt\_therm\_here   \textcolor{comment}{! a further limited value of dt\_therm [T ~> s]}
00465 
00466   \textcolor{keywordtype}{real} :: wt\_end, wt\_beg
00467   \textcolor{keywordtype}{real} :: bbl\_time\_int    \textcolor{comment}{! The amount of time over which the calculated BBL}
00468                           \textcolor{comment}{! properties will apply, for use in diagnostics, or 0}
00469                           \textcolor{comment}{! if it is not to be calculated anew [T ~> s].}
00470   \textcolor{keywordtype}{real} :: rel\_time = 0.0  \textcolor{comment}{! relative time since start of this call [T ~> s].}
00471 
00472   \textcolor{keywordtype}{logical} :: calc\_dtbt                 \textcolor{comment}{! Indicates whether the dynamically adjusted}
00473                                        \textcolor{comment}{! barotropic time step needs to be updated.}
00474   \textcolor{keywordtype}{logical} :: do\_advection              \textcolor{comment}{! If true, it is time to advect tracers.}
00475   \textcolor{keywordtype}{logical} :: do\_calc\_bbl               \textcolor{comment}{! If true, calculate the boundary layer properties.}
00476   \textcolor{keywordtype}{logical} :: thermo\_does\_span\_coupling \textcolor{comment}{! If true, thermodynamic forcing spans}
00477                                        \textcolor{comment}{! multiple dynamic timesteps.}
00478   \textcolor{keywordtype}{logical} :: do\_dyn     \textcolor{comment}{! If true, dynamics are updated with this call.}
00479   \textcolor{keywordtype}{logical} :: do\_thermo  \textcolor{comment}{! If true, thermodynamics and remapping may be applied with this call.}
00480   \textcolor{keywordtype}{logical} :: cycle\_start \textcolor{comment}{! If true, do calculations that are only done at the start of}
00481                         \textcolor{comment}{! a stepping cycle (whatever that may mean).}
00482   \textcolor{keywordtype}{logical} :: cycle\_end  \textcolor{comment}{! If true, do calculations and diagnostics that are only done at}
00483                         \textcolor{comment}{! the end of a stepping cycle (whatever that may mean).}
00484   \textcolor{keywordtype}{logical} :: therm\_reset \textcolor{comment}{! If true, reset running sums of thermodynamic quantities.}
00485   \textcolor{keywordtype}{real} :: cycle\_time    \textcolor{comment}{! The length of the coupled time-stepping cycle [T ~> s].}
00486   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJ\_(CS%G))} :: &
00487     ssh         \textcolor{comment}{! sea surface height, which may be based on eta\_av [m]}
00488 
00489   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{pointer} :: &
00490     u => null(), & \textcolor{comment}{! u : zonal velocity component [L T-1 ~> m s-1]}
00491     v => null(), & \textcolor{comment}{! v : meridional velocity component [L T-1 ~> m s-1]}
00492     h => null()    \textcolor{comment}{! h : layer thickness [H ~> m or kg m-2]}
00493   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer} :: &
00494     p\_surf => null() \textcolor{comment}{! A pointer to the ocean surface pressure [R L2 T-2 ~> Pa].}
00495   \textcolor{keywordtype}{real} :: I\_wt\_ssh  \textcolor{comment}{! The inverse of the time weights [T-1 ~> s-1]}
00496 
00497   \textcolor{keywordtype}{type}(time\_type) :: Time\_local, end\_time\_thermo, Time\_temp
00498   \textcolor{keywordtype}{type}(group\_pass\_type) :: pass\_tau\_ustar\_psurf
00499   \textcolor{keywordtype}{logical} :: showCallTree
00500 
00501   \textcolor{comment}{! External forcing fields on the model index map}
00502   \textcolor{keywordtype}{type}(mech\_forcing), \textcolor{keywordtype}{pointer} :: forces     \textcolor{comment}{! Mechanical forcing}
00503   \textcolor{keywordtype}{type}(forcing), \textcolor{keywordtype}{pointer} :: fluxes          \textcolor{comment}{! Boundary fluxes}
00504   \textcolor{keywordtype}{type}(surface), \textcolor{keywordtype}{pointer} :: sfc\_state\_diag  \textcolor{comment}{! Surface boundary fields}
00505   \textcolor{keywordtype}{integer} :: turns  \textcolor{comment}{! Number of quarter turns from input to model indexing}
00506 
00507   g => cs%G ; g\_in => cs%G\_in ; gv => cs%GV ; us => cs%US
00508   is   = g%isc  ; ie   = g%iec  ; js   = g%jsc  ; je   = g%jec ; nz = g%ke
00509   isq  = g%IscB ; ieq  = g%IecB ; jsq  = g%JscB ; jeq  = g%JecB
00510   isd  = g%isd  ; ied  = g%ied  ; jsd  = g%jsd  ; jed  = g%jed
00511   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
00512   u => cs%u ; v => cs%v ; h => cs%h
00513 
00514   time\_interval = us%s\_to\_T*time\_int\_in
00515   do\_dyn = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(do\_dynamics)) do\_dyn = do\_dynamics
00516   do\_thermo = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(do\_thermodynamics)) do\_thermo = do\_thermodynamics
00517   \textcolor{keywordflow}{if} (.not.(do\_dyn .or. do\_thermo)) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"Step\_MOM: "}//&
00518     \textcolor{stringliteral}{"Both do\_dynamics and do\_thermodynamics are false, which makes no sense."})
00519   cycle\_start = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(start\_cycle)) cycle\_start = start\_cycle
00520   cycle\_end = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(end\_cycle)) cycle\_end = end\_cycle
00521   cycle\_time = time\_interval ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(cycle\_length)) cycle\_time = us%s\_to\_T*cycle\_length
00522   therm\_reset = cycle\_start ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(reset\_therm)) therm\_reset = reset\_therm
00523 
00524   \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a2e9f4b71ee77ba5bcb3f03a863948db3}{id\_clock\_ocean})
00525   \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}{id\_clock\_other})
00526 
00527   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
00528     \textcolor{keyword}{call }mom\_state\_chksum(\textcolor{stringliteral}{"Beginning of step\_MOM "}, u, v, h, cs%uh, cs%vh, g, gv, us)
00529 \textcolor{keywordflow}{  endif}
00530 
00531   showcalltree = calltree\_showquery()
00532   \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"step\_MOM(), MOM.F90"})
00533 
00534   \textcolor{comment}{! Rotate the forces from G\_in to G}
00535   \textcolor{keywordflow}{if} (cs%rotate\_index) \textcolor{keywordflow}{then}
00536     turns = g%HI%turns
00537     \textcolor{keyword}{allocate}(forces)
00538     \textcolor{keyword}{call }allocate\_mech\_forcing(forces\_in, g, forces)
00539     \textcolor{keyword}{call }rotate\_mech\_forcing(forces\_in, turns, forces)
00540 
00541     \textcolor{keyword}{allocate}(fluxes)
00542     \textcolor{keyword}{call }allocate\_forcing\_type(fluxes\_in, g, fluxes)
00543     \textcolor{keyword}{call }rotate\_forcing(fluxes\_in, fluxes, turns)
00544   \textcolor{keywordflow}{else}
00545     forces => forces\_in
00546     fluxes => fluxes\_in
00547 \textcolor{keywordflow}{  endif}
00548 
00549   \textcolor{comment}{! First determine the time step that is consistent with this call and an}
00550   \textcolor{comment}{! integer fraction of time\_interval.}
00551   \textcolor{keywordflow}{if} (do\_dyn) \textcolor{keywordflow}{then}
00552     n\_max = 1
00553     \textcolor{keywordflow}{if} (time\_interval > cs%dt) n\_max = ceiling(time\_interval/cs%dt - 0.001)
00554     dt = time\_interval / \textcolor{keywordtype}{real}(n\_max)
00555     thermo\_does\_span\_coupling = (cs%thermo\_spans\_coupling .and. &
00556                                 (cs%dt\_therm > 1.5*cycle\_time))
00557     \textcolor{keywordflow}{if} (thermo\_does\_span\_coupling) \textcolor{keywordflow}{then}
00558       \textcolor{comment}{! Set dt\_therm to be an integer multiple of the coupling time step.}
00559       dt\_therm = cycle\_time * floor(cs%dt\_therm / cycle\_time + 0.001)
00560       ntstep = floor(dt\_therm/dt + 0.001)
00561     \textcolor{keywordflow}{elseif} (.not.do\_thermo) \textcolor{keywordflow}{then}
00562       dt\_therm = cs%dt\_therm
00563       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(cycle\_length)) dt\_therm = min(cs%dt\_therm, us%s\_to\_T*cycle\_length)
00564       \textcolor{comment}{! ntstep is not used.}
00565     \textcolor{keywordflow}{else}
00566       ntstep = max(1, min(n\_max, floor(cs%dt\_therm/dt + 0.001)))
00567       dt\_therm = dt*ntstep
00568 \textcolor{keywordflow}{    endif}
00569 
00570     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(forces%p\_surf)) p\_surf => forces%p\_surf
00571     \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(forces%p\_surf)) cs%interp\_p\_surf = .false.
00572     cs%tv%p\_surf => null()
00573     \textcolor{keywordflow}{if} (cs%use\_p\_surf\_in\_EOS .and. \textcolor{keyword}{associated}(forces%p\_surf)) cs%tv%p\_surf => forces%p\_surf
00574 
00575     \textcolor{comment}{!---------- Initiate group halo pass of the forcing fields}
00576     \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass})
00577     \textcolor{keyword}{call }create\_group\_pass(pass\_tau\_ustar\_psurf, forces%taux, forces%tauy, g%Domain)
00578     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(forces%ustar)) &
00579       \textcolor{keyword}{call }create\_group\_pass(pass\_tau\_ustar\_psurf, forces%ustar, g%Domain)
00580     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(forces%p\_surf)) &
00581       \textcolor{keyword}{call }create\_group\_pass(pass\_tau\_ustar\_psurf, forces%p\_surf, g%Domain)
00582     \textcolor{keywordflow}{if} (g%nonblocking\_updates) \textcolor{keywordflow}{then}
00583       \textcolor{keyword}{call }start\_group\_pass(pass\_tau\_ustar\_psurf, g%Domain)
00584     \textcolor{keywordflow}{else}
00585       \textcolor{keyword}{call }do\_group\_pass(pass\_tau\_ustar\_psurf, g%Domain)
00586 \textcolor{keywordflow}{    endif}
00587     \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass})
00588   \textcolor{keywordflow}{else}
00589     \textcolor{comment}{! This step only updates the thermodynamics so setting timesteps is simpler.}
00590     n\_max = 1
00591     \textcolor{keywordflow}{if} ((time\_interval > cs%dt\_therm) .and. (cs%dt\_therm > 0.0)) &
00592       n\_max = ceiling(time\_interval/cs%dt\_therm - 0.001)
00593 
00594     dt = time\_interval / \textcolor{keywordtype}{real}(n\_max)
00595     dt\_therm = dt ; ntstep = 1
00596     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes%p\_surf)) p\_surf => fluxes%p\_surf
00597     cs%tv%p\_surf => null()
00598     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes%p\_surf)) \textcolor{keywordflow}{then}
00599       \textcolor{keywordflow}{if} (cs%use\_p\_surf\_in\_EOS) cs%tv%p\_surf => fluxes%p\_surf
00600 \textcolor{keywordflow}{    endif}
00601     \textcolor{keywordflow}{if} (cs%UseWaves) \textcolor{keyword}{call }pass\_var(fluxes%ustar, g%Domain, clock=\hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass})
00602 \textcolor{keywordflow}{  endif}
00603 
00604   \textcolor{keywordflow}{if} (therm\_reset) \textcolor{keywordflow}{then}
00605     cs%time\_in\_thermo\_cycle = 0.0
00606     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tv%frazil))        cs%tv%frazil(:,:)        = 0.0
00607     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tv%salt\_deficit))  cs%tv%salt\_deficit(:,:)  = 0.0
00608     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tv%TempxPmE))      cs%tv%TempxPmE(:,:)      = 0.0
00609     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tv%internal\_heat)) cs%tv%internal\_heat(:,:) = 0.0
00610 \textcolor{keywordflow}{  endif}
00611 
00612   \textcolor{keywordflow}{if} (cycle\_start) \textcolor{keywordflow}{then}
00613     cs%time\_in\_cycle = 0.0
00614     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; cs%ssh\_rint(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
00615 
00616     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%VarMix)) \textcolor{keywordflow}{then}
00617       \textcolor{keyword}{call }enable\_averages(cycle\_time, time\_start + real\_to\_time(us%T\_to\_s*cycle\_time), cs%diag)
00618       \textcolor{keyword}{call }calc\_resoln\_function(h, cs%tv, g, gv, us, cs%VarMix)
00619       \textcolor{keyword}{call }calc\_depth\_function(g, cs%VarMix)
00620       \textcolor{keyword}{call }disable\_averaging(cs%diag)
00621 \textcolor{keywordflow}{    endif}
00622 \textcolor{keywordflow}{  endif}
00623 
00624   \textcolor{keywordflow}{if} (do\_dyn) \textcolor{keywordflow}{then}
00625     \textcolor{keywordflow}{if} (g%nonblocking\_updates) &
00626       \textcolor{keyword}{call }complete\_group\_pass(pass\_tau\_ustar\_psurf, g%Domain, clock=
      \hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass})
00627 
00628     \textcolor{keywordflow}{if} (cs%interp\_p\_surf) \textcolor{keywordflow}{then}
00629       \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs%p\_surf\_end))   \textcolor{keyword}{allocate}(cs%p\_surf\_end(isd:ied,jsd:jed))
00630       \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs%p\_surf\_begin)) \textcolor{keyword}{allocate}(cs%p\_surf\_begin(isd:ied,jsd:jed))
00631       \textcolor{keywordflow}{if} (.not.cs%p\_surf\_prev\_set) \textcolor{keywordflow}{then}
00632         \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
00633           cs%p\_surf\_prev(i,j) = forces%p\_surf(i,j)
00634 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
00635         cs%p\_surf\_prev\_set = .true.
00636 \textcolor{keywordflow}{      endif}
00637     \textcolor{keywordflow}{else}
00638       cs%p\_surf\_end  => forces%p\_surf
00639 \textcolor{keywordflow}{    endif}
00640 
00641     \textcolor{keywordflow}{if} (cs%UseWaves) \textcolor{keywordflow}{then}
00642       \textcolor{comment}{! Update wave information, which is presently kept static over each call to step\_mom}
00643       \textcolor{keyword}{call }enable\_averages(time\_interval, time\_start + real\_to\_time(us%T\_to\_s*time\_interval), cs%diag)
00644       \textcolor{keyword}{call }update\_stokes\_drift(g, gv, us, waves, h, forces%ustar)
00645       \textcolor{keyword}{call }disable\_averaging(cs%diag)
00646 \textcolor{keywordflow}{    endif}
00647   \textcolor{keywordflow}{else} \textcolor{comment}{! not do\_dyn.}
00648     \textcolor{keywordflow}{if} (cs%UseWaves) & \textcolor{comment}{! Diagnostics are not enabled in this call.}
00649       \textcolor{keyword}{call }update\_stokes\_drift(g, gv, us, waves, h, fluxes%ustar)
00650 \textcolor{keywordflow}{  endif}
00651 
00652   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
00653     \textcolor{keywordflow}{if} (cycle\_start) &
00654       \textcolor{keyword}{call }mom\_state\_chksum(\textcolor{stringliteral}{"Before steps "}, u, v, h, cs%uh, cs%vh, g, gv, us)
00655     \textcolor{keywordflow}{if} (cycle\_start) \textcolor{keyword}{call }check\_redundant(\textcolor{stringliteral}{"Before steps "}, u, v, g)
00656     \textcolor{keywordflow}{if} (do\_dyn) \textcolor{keyword}{call }mom\_mech\_forcing\_chksum(\textcolor{stringliteral}{"Before steps"}, forces, g, us, haloshift=0)
00657     \textcolor{keywordflow}{if} (do\_dyn) \textcolor{keyword}{call }check\_redundant(\textcolor{stringliteral}{"Before steps "}, forces%taux, forces%tauy, g)
00658 \textcolor{keywordflow}{  endif}
00659   \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}{id\_clock\_other})
00660 
00661   rel\_time = 0.0
00662   \textcolor{keywordflow}{do} n=1,n\_max
00663     rel\_time = rel\_time + dt \textcolor{comment}{! The relative time at the end of the step.}
00664     \textcolor{comment}{! Set the universally visible time to the middle of the time step.}
00665     cs%Time = time\_start + real\_to\_time(us%T\_to\_s*(rel\_time - 0.5*dt))
00666     \textcolor{comment}{! Set the local time to the end of the time step.}
00667     time\_local = time\_start + real\_to\_time(us%T\_to\_s*rel\_time)
00668 
00669     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"DT cycles (step\_MOM) n="},n)
00670 
00671     \textcolor{comment}{! Update the vertically extensive diagnostic grids so that they are}
00672     \textcolor{comment}{! referenced to the beginning timestep}
00673     \textcolor{keyword}{call }diag\_update\_remap\_grids(cs%diag, update\_intensive = .false., update\_extensive = .true. )
00674 
00675     \textcolor{comment}{!===========================================================================}
00676     \textcolor{comment}{! This is the first place where the diabatic processes and remapping could occur.}
00677     \textcolor{keywordflow}{if} (cs%diabatic\_first .and. (cs%t\_dyn\_rel\_adv==0.0) .and. do\_thermo) \textcolor{keywordflow}{then} \textcolor{comment}{! do thermodynamics.}
00678 
00679       \textcolor{keywordflow}{if} (.not.do\_dyn) \textcolor{keywordflow}{then}
00680         dtdia = dt
00681       \textcolor{keywordflow}{elseif} (thermo\_does\_span\_coupling) \textcolor{keywordflow}{then}
00682         dtdia = dt\_therm
00683         \textcolor{keywordflow}{if} ((fluxes%dt\_buoy\_accum > 0.0) .and. (dtdia > time\_interval) .and. &
00684             (abs(fluxes%dt\_buoy\_accum - dtdia) > 1e-6*dtdia)) \textcolor{keywordflow}{then}
00685           \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"step\_MOM: Mismatch between long thermodynamic "}//&
00686             \textcolor{stringliteral}{"timestep and time over which buoyancy fluxes have been accumulated."})
00687 \textcolor{keywordflow}{        endif}
00688         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM is not yet set up to have restarts that work "}//&
00689           \textcolor{stringliteral}{"with THERMO\_SPANS\_COUPLING and DIABATIC\_FIRST."})
00690       \textcolor{keywordflow}{else}
00691         dtdia = dt*min(ntstep,n\_max-(n-1))
00692 \textcolor{keywordflow}{      endif}
00693 
00694 \textcolor{keyword}{      end}\_time\_thermo = time\_local
00695       \textcolor{keywordflow}{if} (dtdia > dt) \textcolor{keywordflow}{then}
00696         \textcolor{comment}{! If necessary, temporarily reset CS%Time to the center of the period covered}
00697         \textcolor{comment}{! by the call to step\_MOM\_thermo, noting that they begin at the same time.}
00698         cs%Time = cs%Time + real\_to\_time(0.5*us%T\_to\_s*(dtdia-dt))
00699         \textcolor{comment}{! The end-time of the diagnostic interval needs to be set ahead if there}
00700         \textcolor{comment}{! are multiple dynamic time steps worth of thermodynamics applied here.}
00701 \textcolor{keyword}{        end}\_time\_thermo = Time\_local + real\_to\_time(US%T\_to\_s*(dtdia-dt))
00702 \textcolor{keywordflow}{      endif}
00703 
00704       \textcolor{comment}{! Apply diabatic forcing, do mixing, and regrid.}
00705       \textcolor{keyword}{call }\hyperlink{namespacemom_a1a81ea749a309f10f5c3c7a17efa3606}{step\_mom\_thermo}(cs, g, gv, us, u, v, h, cs%tv, fluxes, dtdia, &
00706 \textcolor{keyword}{                           end}\_time\_thermo, .true., Waves=Waves)
00707       cs%time\_in\_thermo\_cycle = cs%time\_in\_thermo\_cycle + dtdia
00708 
00709       \textcolor{comment}{! The diabatic processes are now ahead of the dynamics by dtdia.}
00710       cs%t\_dyn\_rel\_thermo = -dtdia
00711       \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished diabatic\_first (step\_MOM)"})
00712 
00713       \textcolor{keywordflow}{if} (dtdia > dt) & \textcolor{comment}{! Reset CS%Time to its previous value.}
00714         cs%Time = time\_start + real\_to\_time(us%T\_to\_s*(rel\_time - 0.5*dt))
00715 \textcolor{keywordflow}{    endif} \textcolor{comment}{! end of block "(CS%diabatic\_first .and. (CS%t\_dyn\_rel\_adv==0.0))"}
00716 
00717     \textcolor{keywordflow}{if} (do\_dyn) \textcolor{keywordflow}{then}
00718       \textcolor{comment}{! Store pre-dynamics thicknesses for proper diagnostic remapping for transports or}
00719       \textcolor{comment}{! advective tendencies.  If there are more than one dynamics steps per advective}
00720       \textcolor{comment}{! step (i.e DT\_THERM > DT), this needs to be stored at the first dynamics call.}
00721       \textcolor{keywordflow}{if} (.not.cs%preadv\_h\_stored .and. (cs%t\_dyn\_rel\_adv == 0.)) \textcolor{keywordflow}{then}
00722         \textcolor{keyword}{call }diag\_copy\_diag\_to\_storage(cs%diag\_pre\_dyn, h, cs%diag)
00723         cs%preadv\_h\_stored = .true.
00724 \textcolor{keywordflow}{      endif}
00725 
00726       \textcolor{comment}{! The pre-dynamics velocities might be stored for debugging truncations.}
00727       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%u\_prev) .and. \textcolor{keyword}{associated}(cs%v\_prev)) \textcolor{keywordflow}{then}
00728         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb
00729           cs%u\_prev(i,j,k) = u(i,j,k)
00730 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
00731         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied
00732           cs%v\_prev(i,j,k) = v(i,j,k)
00733 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
00734 \textcolor{keywordflow}{      endif}
00735 
00736       dt\_therm\_here = dt\_therm
00737       \textcolor{keywordflow}{if} (do\_thermo .and. do\_dyn .and. .not.thermo\_does\_span\_coupling) &
00738         dt\_therm\_here = dt*min(ntstep, n\_max-n+1)
00739 
00740       \textcolor{comment}{! Indicate whether the bottom boundary layer properties need to be}
00741       \textcolor{comment}{! recalculated, and if so for how long an interval they are valid.}
00742       bbl\_time\_int = 0.0
00743       \textcolor{keywordflow}{if} (do\_thermo) \textcolor{keywordflow}{then}
00744         \textcolor{keywordflow}{if} ((cs%t\_dyn\_rel\_adv == 0.0) .or. (n==1)) &
00745           bbl\_time\_int = max(dt, min(dt\_therm - cs%t\_dyn\_rel\_adv, dt*(1+n\_max-n)) )
00746       \textcolor{keywordflow}{else}
00747         \textcolor{keywordflow}{if} ((cs%t\_dyn\_rel\_adv == 0.0) .or. ((n==1) .and. cycle\_start)) &
00748           bbl\_time\_int = min(dt\_therm, cycle\_time)
00749 \textcolor{keywordflow}{      endif}
00750 
00751       \textcolor{keywordflow}{if} (cs%interp\_p\_surf) \textcolor{keywordflow}{then}
00752         wt\_end = \textcolor{keywordtype}{real(n)} / \textcolor{keywordtype}{real}(n\_max)
00753         wt\_beg = \textcolor{keywordtype}{real(n-1)} / \textcolor{keywordtype}{real}(n\_max)
00754         \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
00755           cs%p\_surf\_end(i,j) = wt\_end * forces%p\_surf(i,j) + &
00756                           (1.0-wt\_end) * cs%p\_surf\_prev(i,j)
00757           cs%p\_surf\_begin(i,j) = wt\_beg * forces%p\_surf(i,j) + &
00758                           (1.0-wt\_beg) * cs%p\_surf\_prev(i,j)
00759 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
00760 \textcolor{keywordflow}{      endif}
00761 
00762       \textcolor{keyword}{call }\hyperlink{namespacemom_a42ee7e91ffcf1340679e29ab28d9b41d}{step\_mom\_dynamics}(forces, cs%p\_surf\_begin, cs%p\_surf\_end, dt, &
00763                              dt\_therm\_here, bbl\_time\_int, cs, &
00764                              time\_local, waves=waves)
00765 
00766       \textcolor{comment}{!===========================================================================}
00767       \textcolor{comment}{! This is the start of the tracer advection part of the algorithm.}
00768 
00769       \textcolor{keywordflow}{if} (thermo\_does\_span\_coupling .or. .not.do\_thermo) \textcolor{keywordflow}{then}
00770         do\_advection = (cs%t\_dyn\_rel\_adv + 0.5*dt > dt\_therm)
00771       \textcolor{keywordflow}{else}
00772         do\_advection = ((mod(n,ntstep) == 0) .or. (n==n\_max))
00773 \textcolor{keywordflow}{      endif}
00774 
00775       \textcolor{keywordflow}{if} (do\_advection) \textcolor{keywordflow}{then} \textcolor{comment}{! Do advective transport and lateral tracer mixing.}
00776         \textcolor{keyword}{call }\hyperlink{namespacemom_a0a07938ed3127b70bab5d466967aec80}{step\_mom\_tracer\_dyn}(cs, g, gv, us, h, time\_local)
00777         \textcolor{keywordflow}{if} (cs%diabatic\_first .and. abs(cs%t\_dyn\_rel\_thermo) > 1e-6*dt) \textcolor{keyword}{call }mom\_error(fatal, &
00778                 \textcolor{stringliteral}{"step\_MOM: Mismatch between the dynamics and diabatic times "}//&
00779                 \textcolor{stringliteral}{"with DIABATIC\_FIRST."})
00780 \textcolor{keywordflow}{      endif}
00781 \textcolor{keywordflow}{    endif} \textcolor{comment}{! end of (do\_dyn)}
00782 
00783     \textcolor{comment}{!===========================================================================}
00784     \textcolor{comment}{! This is the second place where the diabatic processes and remapping could occur.}
00785     \textcolor{keywordflow}{if} ((cs%t\_dyn\_rel\_adv==0.0) .and. do\_thermo .and. (.not.cs%diabatic\_first)) \textcolor{keywordflow}{then}
00786 
00787       dtdia = cs%t\_dyn\_rel\_thermo
00788       \textcolor{comment}{! If the MOM6 dynamic and thermodynamic time stepping is being orchestrated}
00789       \textcolor{comment}{! by the coupler, the value of diabatic\_first does not matter.}
00790       \textcolor{keywordflow}{if} ((cs%t\_dyn\_rel\_thermo==0.0) .and. .not.do\_dyn) dtdia = dt
00791 
00792       \textcolor{keywordflow}{if} (cs%thermo\_spans\_coupling .and. (cs%dt\_therm > 1.5*cycle\_time) .and. &
00793           (abs(dt\_therm - dtdia) > 1e-6*dt\_therm)) \textcolor{keywordflow}{then}
00794         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"step\_MOM: Mismatch between dt\_therm and dtdia "}//&
00795                        \textcolor{stringliteral}{"before call to diabatic."})
00796 \textcolor{keywordflow}{      endif}
00797 
00798       \textcolor{comment}{! If necessary, temporarily reset CS%Time to the center of the period covered}
00799       \textcolor{comment}{! by the call to step\_MOM\_thermo, noting that they end at the same time.}
00800       \textcolor{keywordflow}{if} (dtdia > dt) cs%Time = cs%Time - real\_to\_time(0.5*us%T\_to\_s*(dtdia-dt))
00801 
00802       \textcolor{comment}{! Apply diabatic forcing, do mixing, and regrid.}
00803       \textcolor{keyword}{call }\hyperlink{namespacemom_a1a81ea749a309f10f5c3c7a17efa3606}{step\_mom\_thermo}(cs, g, gv, us, u, v, h, cs%tv, fluxes, dtdia, &
00804                            time\_local, .false., waves=waves)
00805       cs%time\_in\_thermo\_cycle = cs%time\_in\_thermo\_cycle + dtdia
00806 
00807       \textcolor{keywordflow}{if} ((cs%t\_dyn\_rel\_thermo==0.0) .and. .not.do\_dyn) \textcolor{keywordflow}{then}
00808         \textcolor{comment}{! The diabatic processes are now ahead of the dynamics by dtdia.}
00809         cs%t\_dyn\_rel\_thermo = -dtdia
00810       \textcolor{keywordflow}{else} \textcolor{comment}{! The diabatic processes and the dynamics are synchronized.}
00811         cs%t\_dyn\_rel\_thermo = 0.0
00812 \textcolor{keywordflow}{      endif}
00813 
00814       \textcolor{keywordflow}{if} (dtdia > dt) & \textcolor{comment}{! Reset CS%Time to its previous value.}
00815         cs%Time = time\_start + real\_to\_time(us%T\_to\_s*(rel\_time - 0.5*dt))
00816 \textcolor{keywordflow}{    endif}
00817 
00818     \textcolor{keywordflow}{if} (do\_dyn) \textcolor{keywordflow}{then}
00819       \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_ae1cf2d523679b925a5e5baa9d974968c}{id\_clock\_dynamics})
00820       \textcolor{comment}{! Determining the time-average sea surface height is part of the algorithm.}
00821       \textcolor{comment}{! This may be eta\_av if Boussinesq, or need to be diagnosed if not.}
00822       cs%time\_in\_cycle = cs%time\_in\_cycle + dt
00823       \textcolor{keyword}{call }find\_eta(h, cs%tv, g, gv, us, ssh, cs%eta\_av\_bc, eta\_to\_m=1.0)
00824       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00825         cs%ssh\_rint(i,j) = cs%ssh\_rint(i,j) + dt*ssh(i,j)
00826 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
00827       \textcolor{keywordflow}{if} (cs%IDs%id\_ssh\_inst > 0) \textcolor{keyword}{call }post\_data(cs%IDs%id\_ssh\_inst, ssh, cs%diag)
00828       \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_ae1cf2d523679b925a5e5baa9d974968c}{id\_clock\_dynamics})
00829 \textcolor{keywordflow}{    endif}
00830 
00831     \textcolor{comment}{!===========================================================================}
00832     \textcolor{comment}{! Calculate diagnostics at the end of the time step if the state is self-consistent.}
00833     \textcolor{keywordflow}{if} (\hyperlink{namespacemom_ada38a8329b76f9fa1685a230869a7647}{mom\_state\_is\_synchronized}(cs)) \textcolor{keywordflow}{then}
00834     \textcolor{comment}{!### Perhaps this should be if (CS%t\_dyn\_rel\_thermo == 0.0)}
00835       \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}{id\_clock\_other}) ; \textcolor{keyword}{call }cpu\_clock\_begin(
      \hyperlink{namespacemom_aa773fddb51f99098d75304eb271270d4}{id\_clock\_diagnostics})
00836       \textcolor{comment}{! Diagnostics that require the complete state to be up-to-date can be calculated.}
00837 
00838       \textcolor{keyword}{call }enable\_averages(cs%t\_dyn\_rel\_diag, time\_local, cs%diag)
00839       \textcolor{keyword}{call }calculate\_diagnostic\_fields(u, v, h, cs%uh, cs%vh, cs%tv, cs%ADp,  &
00840                           cs%CDp, p\_surf, cs%t\_dyn\_rel\_diag, cs%diag\_pre\_sync,&
00841                           g, gv, us, cs%diagnostics\_CSp)
00842       \textcolor{keyword}{call }post\_tracer\_diagnostics\_at\_sync(cs%Tracer\_reg, h, cs%diag\_pre\_sync, cs%diag, g, gv, cs
      %t\_dyn\_rel\_diag)
00843       \textcolor{keyword}{call }diag\_copy\_diag\_to\_storage(cs%diag\_pre\_sync, h, cs%diag)
00844       \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished calculate\_diagnostic\_fields (step\_MOM)"})
00845       \textcolor{keyword}{call }disable\_averaging(cs%diag)
00846       cs%t\_dyn\_rel\_diag = 0.0
00847 
00848       \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_aa773fddb51f99098d75304eb271270d4}{id\_clock\_diagnostics}) ; \textcolor{keyword}{call }cpu\_clock\_end(
      \hyperlink{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}{id\_clock\_other})
00849 \textcolor{keywordflow}{    endif}
00850 
00851     \textcolor{keywordflow}{if} (do\_dyn .and. .not.cs%count\_calls) cs%nstep\_tot = cs%nstep\_tot + 1
00852     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"DT cycles (step\_MOM)"})
00853 
00854 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! complete the n loop}
00855 
00856   \textcolor{keywordflow}{if} (cs%count\_calls .and. cycle\_start) cs%nstep\_tot = cs%nstep\_tot + 1
00857 
00858   \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}{id\_clock\_other})
00859 
00860   \textcolor{keywordflow}{if} (cs%time\_in\_cycle > 0.0) \textcolor{keywordflow}{then}
00861     i\_wt\_ssh = 1.0/cs%time\_in\_cycle
00862     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
00863       ssh(i,j) = cs%ssh\_rint(i,j)*i\_wt\_ssh
00864       cs%ave\_ssh\_ibc(i,j) = ssh(i,j)
00865 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
00866     \textcolor{keywordflow}{if} (do\_dyn) \textcolor{keywordflow}{then}
00867       \textcolor{keyword}{call }\hyperlink{namespacemom_a16f7cc52cef3eb7a99687bf3d0694285}{adjust\_ssh\_for\_p\_atm}(cs%tv, g, gv, us, cs%ave\_ssh\_ibc, forces%p\_surf\_SSH, &
00868                                 cs%calc\_rho\_for\_sea\_lev)
00869     \textcolor{keywordflow}{elseif} (do\_thermo) \textcolor{keywordflow}{then}
00870       \textcolor{keyword}{call }\hyperlink{namespacemom_a16f7cc52cef3eb7a99687bf3d0694285}{adjust\_ssh\_for\_p\_atm}(cs%tv, g, gv, us, cs%ave\_ssh\_ibc, fluxes%p\_surf\_SSH, &
00871                                 cs%calc\_rho\_for\_sea\_lev)
00872 \textcolor{keywordflow}{    endif}
00873 \textcolor{keywordflow}{  endif}
00874 
00875   \textcolor{keywordflow}{if} (do\_dyn .and. cs%interp\_p\_surf) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
00876     cs%p\_surf\_prev(i,j) = forces%p\_surf(i,j)
00877 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
00878 
00879   \textcolor{keywordflow}{if} (cs%ensemble\_ocean) \textcolor{keywordflow}{then}
00880     \textcolor{comment}{! update the time for the next analysis step if needed}
00881     \textcolor{keyword}{call }set\_analysis\_time(cs%Time,cs%odaCS)
00882     \textcolor{comment}{! store ensemble vector in odaCS}
00883     \textcolor{keyword}{call }set\_prior\_tracer(cs%Time, g, gv, cs%h, cs%tv, cs%odaCS)
00884     \textcolor{comment}{! call DA interface}
00885     \textcolor{keyword}{call }oda(cs%Time,cs%odaCS)
00886 \textcolor{keywordflow}{  endif}
00887 
00888   \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"calling extract\_surface\_state (step\_MOM)"})
00889   \textcolor{comment}{! NOTE: sfc\_state uses input indexing, since it is also used by drivers.}
00890   \textcolor{keyword}{call }\hyperlink{namespacemom_a699d6c5bfb5b9dcdaa03c18806fa824e}{extract\_surface\_state}(cs, sfc\_state)
00891 
00892   \textcolor{comment}{! Do diagnostics that only occur at the end of a complete forcing step.}
00893   \textcolor{keywordflow}{if} (cycle\_end) \textcolor{keywordflow}{then}
00894     \textcolor{keywordflow}{if} (cs%rotate\_index) \textcolor{keywordflow}{then}
00895       \textcolor{keyword}{allocate}(sfc\_state\_diag)
00896       \textcolor{keyword}{call }rotate\_surface\_state(sfc\_state, g\_in, sfc\_state\_diag, g, turns)
00897     \textcolor{keywordflow}{else}
00898       sfc\_state\_diag => sfc\_state
00899 \textcolor{keywordflow}{    endif}
00900 
00901     \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_aa773fddb51f99098d75304eb271270d4}{id\_clock\_diagnostics})
00902     \textcolor{keywordflow}{if} (cs%time\_in\_cycle > 0.0) \textcolor{keywordflow}{then}
00903       \textcolor{keyword}{call }enable\_averages(cs%time\_in\_cycle, time\_local, cs%diag)
00904       \textcolor{keyword}{call }post\_surface\_dyn\_diags(cs%sfc\_IDs, g, cs%diag, sfc\_state\_diag, ssh)
00905 \textcolor{keywordflow}{    endif}
00906     \textcolor{keywordflow}{if} (cs%time\_in\_thermo\_cycle > 0.0) \textcolor{keywordflow}{then}
00907       \textcolor{keyword}{call }enable\_averages(cs%time\_in\_thermo\_cycle, time\_local, cs%diag)
00908       \textcolor{keyword}{call }post\_surface\_thermo\_diags(cs%sfc\_IDs, g, gv, us, cs%diag, cs%time\_in\_thermo\_cycle, &
00909                                      sfc\_state\_diag, cs%tv, ssh, cs%ave\_ssh\_ibc)
00910 \textcolor{keywordflow}{    endif}
00911     \textcolor{keyword}{call }disable\_averaging(cs%diag)
00912     \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_aa773fddb51f99098d75304eb271270d4}{id\_clock\_diagnostics})
00913 \textcolor{keywordflow}{  endif}
00914 
00915   \textcolor{comment}{! Accumulate the surface fluxes for assessing conservation}
00916   \textcolor{keywordflow}{if} (do\_thermo .and. fluxes%fluxes\_used) &
00917     \textcolor{keyword}{call }accumulate\_net\_input(fluxes, sfc\_state, cs%tv, fluxes%dt\_buoy\_accum, &
00918                               g, us, cs%sum\_output\_CSp)
00919 
00920   \textcolor{keywordflow}{if} (\hyperlink{namespacemom_ada38a8329b76f9fa1685a230869a7647}{mom\_state\_is\_synchronized}(cs)) &
00921     \textcolor{keyword}{call }write\_energy(cs%u, cs%v, cs%h, cs%tv, time\_local, cs%nstep\_tot, &
00922                       g, gv, us, cs%sum\_output\_CSp, cs%tracer\_flow\_CSp, &
00923                       dt\_forcing=real\_to\_time(us%T\_to\_s*time\_interval) )
00924 
00925   \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}{id\_clock\_other})
00926 
00927   \textcolor{comment}{! De-rotate fluxes and copy back to the input, since they can be changed.}
00928   \textcolor{keywordflow}{if} (cs%rotate\_index) \textcolor{keywordflow}{then}
00929     \textcolor{keyword}{call }rotate\_forcing(fluxes, fluxes\_in, -turns)
00930 
00931     \textcolor{keyword}{call }deallocate\_mech\_forcing(forces)
00932     \textcolor{keyword}{deallocate}(forces)
00933 
00934     \textcolor{keyword}{call }deallocate\_forcing\_type(fluxes)
00935     \textcolor{keyword}{deallocate}(fluxes)
00936 \textcolor{keywordflow}{  endif}
00937 
00938   \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"step\_MOM()"})
00939   \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a2e9f4b71ee77ba5bcb3f03a863948db3}{id\_clock\_ocean})
00940 
00941 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom_adf54a4e3a72611aa2088f46076e56e53}{step\_mom}
00942 \textcolor{comment}{}
00943 \textcolor{comment}{!> Time step the ocean dynamics, including the momentum and continuity equations}
00944 \textcolor{keyword}{subroutine }\hyperlink{namespacemom_a42ee7e91ffcf1340679e29ab28d9b41d}{step\_mom\_dynamics}(forces, p\_surf\_begin, p\_surf\_end, dt, dt\_thermo, &
00945                              bbl\_time\_int, CS, Time\_local, Waves)
\Hypertarget{MOM_8F90_source_l00946}\hyperlink{namespacemom_a42ee7e91ffcf1340679e29ab28d9b41d}{00946}   \textcolor{keywordtype}{type}(mech\_forcing), \textcolor{keywordtype}{intent(in)}    :: forces\textcolor{comment}{     !< A structure with the driving mechanical forces}
00947   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer}     :: p\_surf\_begin\textcolor{comment}{ !< A pointer (perhaps NULL) to the surface}
00948 \textcolor{comment}{                                                  !! pressure at the beginning of this dynamic}
00949 \textcolor{comment}{                                                  !! step, intent in [R L2 T-2 ~> Pa].}
00950   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer}     :: p\_surf\_end\textcolor{comment}{ !< A pointer (perhaps NULL) to the surface}
00951 \textcolor{comment}{                                                  !! pressure at the end of this dynamic step,}
00952 \textcolor{comment}{                                                  !! intent in [R L2 T-2 ~> Pa].}
00953   \textcolor{keywordtype}{real},               \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{         !< time interval covered by this call [T ~> s].}
00954   \textcolor{keywordtype}{real},               \textcolor{keywordtype}{intent(in)}    :: dt\_thermo\textcolor{comment}{  !< time interval covered by any updates that may}
00955 \textcolor{comment}{                                                  !! span multiple dynamics steps [T ~> s].}
00956   \textcolor{keywordtype}{real},               \textcolor{keywordtype}{intent(in)}    :: bbl\_time\_int\textcolor{comment}{ !< time interval over which updates to the}
00957 \textcolor{comment}{                                                  !! bottom boundary layer properties will apply [T ~> s],}
00958 \textcolor{comment}{                                                  !! or zero not to update the properties.}
00959   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__control__struct}{mom\_control\_struct}), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{         !< control structure from
       initialize\_MOM}
00960   \textcolor{keywordtype}{type}(time\_type),    \textcolor{keywordtype}{intent(in)}    :: Time\_local\textcolor{comment}{ !< End time of a segment, as a time type}
00961   \textcolor{keywordtype}{type}(wave\_parameters\_cs), &
00962             \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: Waves\textcolor{comment}{      !< Container for wave related parameters; the}
00963 \textcolor{comment}{                                                  !! fields in Waves are intent in here.}
00964 
00965   \textcolor{comment}{! local variables}
00966   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer} :: G => null()  \textcolor{comment}{! pointer to a structure containing}
00967                                                    \textcolor{comment}{! metrics and related information}
00968   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{pointer} :: GV => null() \textcolor{comment}{! Pointer to the vertical grid structure}
00969   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{pointer} :: US => null() \textcolor{comment}{! Pointer to a structure containing}
00970                                                    \textcolor{comment}{! various unit conversion factors}
00971   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__diag__ids}{mom\_diag\_ids}), \textcolor{keywordtype}{pointer} :: IDs => null() \textcolor{comment}{! A structure with the diagnostic IDs.}
00972   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{pointer} :: &
00973     u => null(), & \textcolor{comment}{! u : zonal velocity component [L T-1 ~> m s-1]}
00974     v => null(), & \textcolor{comment}{! v : meridional velocity component [L T-1 ~> m s-1]}
00975     h => null()    \textcolor{comment}{! h : layer thickness [H ~> m or kg m-2]}
00976 
00977   \textcolor{keywordtype}{logical} :: calc\_dtbt  \textcolor{comment}{! Indicates whether the dynamically adjusted}
00978                         \textcolor{comment}{! barotropic time step needs to be updated.}
00979   \textcolor{keywordtype}{logical} :: showCallTree
00980 
00981   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, Isq, Ieq, Jsq, Jeq, nz
00982   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB
00983 
00984   g => cs%G ; gv => cs%GV ; us => cs%US ; ids => cs%IDs
00985   is   = g%isc  ; ie   = g%iec  ; js   = g%jsc  ; je   = g%jec ; nz = g%ke
00986   isq  = g%IscB ; ieq  = g%IecB ; jsq  = g%JscB ; jeq  = g%JecB
00987   isd  = g%isd  ; ied  = g%ied  ; jsd  = g%jsd  ; jed  = g%jed
00988   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
00989   u => cs%u ; v => cs%v ; h => cs%h
00990   showcalltree = calltree\_showquery()
00991 
00992   \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_ae1cf2d523679b925a5e5baa9d974968c}{id\_clock\_dynamics})
00993 
00994   \textcolor{keywordflow}{if} ((cs%t\_dyn\_rel\_adv == 0.0) .and. cs%thickness\_diffuse .and. cs%thickness\_diffuse\_first) \textcolor{keywordflow}{then}
00995 
00996     \textcolor{keyword}{call }enable\_averages(dt\_thermo, time\_local+real\_to\_time(us%T\_to\_s*(dt\_thermo-dt)), cs%diag)
00997     \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a8f5feb87a0cb40d9fcee00456e982b8a}{id\_clock\_thick\_diff})
00998     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%VarMix)) &
00999       \textcolor{keyword}{call }calc\_slope\_functions(h, cs%tv, dt, g, gv, us, cs%VarMix, obc=cs%OBC)
01000     \textcolor{keyword}{call }thickness\_diffuse(h, cs%uhtr, cs%vhtr, cs%tv, dt\_thermo, g, gv, us, &
01001                            cs%MEKE, cs%VarMix, cs%CDp, cs%thickness\_diffuse\_CSp)
01002     \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a8f5feb87a0cb40d9fcee00456e982b8a}{id\_clock\_thick\_diff})
01003     \textcolor{keyword}{call }pass\_var(h, g%Domain, clock=\hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass}, halo=max(2,cs%cont\_stencil))
01004     \textcolor{keyword}{call }disable\_averaging(cs%diag)
01005     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished thickness\_diffuse\_first (step\_MOM)"})
01006 
01007     \textcolor{comment}{! Whenever thickness changes let the diag manager know, target grids}
01008     \textcolor{comment}{! for vertical remapping may need to be regenerated.}
01009     \textcolor{keyword}{call }diag\_update\_remap\_grids(cs%diag)
01010 \textcolor{keywordflow}{  endif}
01011 
01012   \textcolor{comment}{! The bottom boundary layer properties need to be recalculated.}
01013   \textcolor{keywordflow}{if} (bbl\_time\_int > 0.0) \textcolor{keywordflow}{then}
01014     \textcolor{keyword}{call }enable\_averages(bbl\_time\_int, &
01015               time\_local + real\_to\_time(us%T\_to\_s*(bbl\_time\_int-dt)), cs%diag)
01016     \textcolor{comment}{! Calculate the BBL properties and store them inside visc (u,h).}
01017     \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_aa69e79e4c51e1c24c474b84311322251}{id\_clock\_bbl\_visc})
01018     \textcolor{keyword}{call }set\_viscous\_bbl(cs%u, cs%v, cs%h, cs%tv, cs%visc, g, gv, us, &
01019                          cs%set\_visc\_CSp, symmetrize=.true.)
01020     \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_aa69e79e4c51e1c24c474b84311322251}{id\_clock\_bbl\_visc})
01021     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"done with set\_viscous\_BBL (step\_MOM)"})
01022     \textcolor{keyword}{call }disable\_averaging(cs%diag)
01023 \textcolor{keywordflow}{  endif}
01024 
01025 
01026   \textcolor{keywordflow}{if} (cs%do\_dynamics .and. cs%split) \textcolor{keywordflow}{then} \textcolor{comment}{!--------------------------- start SPLIT}
01027     \textcolor{comment}{! This section uses a split time stepping scheme for the dynamic equations,}
01028     \textcolor{comment}{! basically the stacked shallow water equations with viscosity.}
01029 
01030     calc\_dtbt = .false.
01031     \textcolor{keywordflow}{if} (cs%dtbt\_reset\_period == 0.0) calc\_dtbt = .true.
01032     \textcolor{keywordflow}{if} (cs%dtbt\_reset\_period > 0.0) \textcolor{keywordflow}{then}
01033       \textcolor{keywordflow}{if} (time\_local >= cs%dtbt\_reset\_time) \textcolor{keywordflow}{then}  \textcolor{comment}{!### Change >= to > here.}
01034         calc\_dtbt = .true.
01035         cs%dtbt\_reset\_time = cs%dtbt\_reset\_time + cs%dtbt\_reset\_interval
01036 \textcolor{keywordflow}{      endif}
01037 \textcolor{keywordflow}{    endif}
01038 
01039     \textcolor{keyword}{call }step\_mom\_dyn\_split\_rk2(u, v, h, cs%tv, cs%visc, time\_local, dt, forces, &
01040                 p\_surf\_begin, p\_surf\_end, cs%uh, cs%vh, cs%uhtr, cs%vhtr, &
01041                 cs%eta\_av\_bc, g, gv, us, cs%dyn\_split\_RK2\_CSp, calc\_dtbt, cs%VarMix, &
01042                 cs%MEKE, cs%thickness\_diffuse\_CSp, waves=waves)
01043     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished step\_MOM\_dyn\_split (step\_MOM)"})
01044 
01045   \textcolor{keywordflow}{elseif} (cs%do\_dynamics) \textcolor{keywordflow}{then} \textcolor{comment}{! ------------------------------------ not SPLIT}
01046     \textcolor{comment}{!   This section uses an unsplit stepping scheme for the dynamic}
01047     \textcolor{comment}{! equations; basically the stacked shallow water equations with viscosity.}
01048     \textcolor{comment}{! Because the time step is limited by CFL restrictions on the external}
01049     \textcolor{comment}{! gravity waves, the unsplit is usually much less efficient that the split}
01050     \textcolor{comment}{! approaches. But because of its simplicity, the unsplit method is very}
01051     \textcolor{comment}{! useful for debugging purposes.}
01052 
01053     \textcolor{keywordflow}{if} (cs%use\_RK2) \textcolor{keywordflow}{then}
01054       \textcolor{keyword}{call }step\_mom\_dyn\_unsplit\_rk2(u, v, h, cs%tv, cs%visc, time\_local, dt, forces, &
01055                p\_surf\_begin, p\_surf\_end, cs%uh, cs%vh, cs%uhtr, cs%vhtr, &
01056                cs%eta\_av\_bc, g, gv, us, cs%dyn\_unsplit\_RK2\_CSp, cs%VarMix, cs%MEKE)
01057     \textcolor{keywordflow}{else}
01058       \textcolor{keyword}{call }step\_mom\_dyn\_unsplit(u, v, h, cs%tv, cs%visc, time\_local, dt, forces, &
01059                p\_surf\_begin, p\_surf\_end, cs%uh, cs%vh, cs%uhtr, cs%vhtr, &
01060                cs%eta\_av\_bc, g, gv, us, cs%dyn\_unsplit\_CSp, cs%VarMix, cs%MEKE, waves=waves)
01061 \textcolor{keywordflow}{    endif}
01062     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished step\_MOM\_dyn\_unsplit (step\_MOM)"})
01063 
01064 \textcolor{keywordflow}{  endif} \textcolor{comment}{! -------------------------------------------------- end SPLIT}
01065 
01066   \textcolor{keywordflow}{if} (cs%thickness\_diffuse .and. .not.cs%thickness\_diffuse\_first) \textcolor{keywordflow}{then}
01067     \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a8f5feb87a0cb40d9fcee00456e982b8a}{id\_clock\_thick\_diff})
01068 
01069     \textcolor{keywordflow}{if} (cs%debug) \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"Pre-thickness\_diffuse h"}, g%HI, haloshift=0, scale=gv%H\_to\_m)
01070 
01071     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%VarMix)) &
01072       \textcolor{keyword}{call }calc\_slope\_functions(h, cs%tv, dt, g, gv, us, cs%VarMix, obc=cs%OBC)
01073     \textcolor{keyword}{call }thickness\_diffuse(h, cs%uhtr, cs%vhtr, cs%tv, dt, g, gv, us, &
01074                            cs%MEKE, cs%VarMix, cs%CDp, cs%thickness\_diffuse\_CSp)
01075 
01076     \textcolor{keywordflow}{if} (cs%debug) \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"Post-thickness\_diffuse h"}, g%HI, haloshift=1, scale=gv%H\_to\_m)
01077     \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a8f5feb87a0cb40d9fcee00456e982b8a}{id\_clock\_thick\_diff})
01078     \textcolor{keyword}{call }pass\_var(h, g%Domain, clock=\hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass}, halo=max(2,cs%cont\_stencil))
01079     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished thickness\_diffuse (step\_MOM)"})
01080 \textcolor{keywordflow}{  endif}
01081 
01082   \textcolor{comment}{! apply the submesoscale mixed layer restratification parameterization}
01083   \textcolor{keywordflow}{if} (cs%mixedlayer\_restrat) \textcolor{keywordflow}{then}
01084     \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
01085       \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"Pre-mixedlayer\_restrat h"}, g%HI, haloshift=1, scale=gv%H\_to\_m)
01086       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Pre-mixedlayer\_restrat uhtr"}, &
01087                     cs%uhtr, cs%vhtr, g%HI, haloshift=0, scale=gv%H\_to\_m*us%L\_to\_m**2)
01088 \textcolor{keywordflow}{    endif}
01089     \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a41b67fabfc13e52cf3a5d1c337c780eb}{id\_clock\_ml\_restrat})
01090     \textcolor{keyword}{call }mixedlayer\_restrat(h, cs%uhtr, cs%vhtr, cs%tv, forces, dt, cs%visc%MLD, &
01091                             cs%VarMix, g, gv, us, cs%mixedlayer\_restrat\_CSp)
01092     \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a41b67fabfc13e52cf3a5d1c337c780eb}{id\_clock\_ml\_restrat})
01093     \textcolor{keyword}{call }pass\_var(h, g%Domain, clock=\hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass}, halo=max(2,cs%cont\_stencil))
01094     \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
01095       \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"Post-mixedlayer\_restrat h"}, g%HI, haloshift=1, scale=gv%H\_to\_m)
01096       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Post-mixedlayer\_restrat [uv]htr"}, &
01097                     cs%uhtr, cs%vhtr, g%HI, haloshift=0, scale=gv%H\_to\_m*us%L\_to\_m**2)
01098 \textcolor{keywordflow}{    endif}
01099 \textcolor{keywordflow}{  endif}
01100 
01101   \textcolor{comment}{! Whenever thickness changes let the diag manager know, target grids}
01102   \textcolor{comment}{! for vertical remapping may need to be regenerated.}
01103   \textcolor{keyword}{call }diag\_update\_remap\_grids(cs%diag)
01104 
01105   \textcolor{keywordflow}{if} (cs%useMEKE) \textcolor{keyword}{call }step\_forward\_meke(cs%MEKE, h, cs%VarMix%SN\_u, cs%VarMix%SN\_v, &
01106                                          cs%visc, dt, g, gv, us, cs%MEKE\_CSp, cs%uhtr, cs%vhtr)
01107   \textcolor{keyword}{call }disable\_averaging(cs%diag)
01108 
01109   \textcolor{comment}{! Advance the dynamics time by dt.}
01110   cs%t\_dyn\_rel\_adv = cs%t\_dyn\_rel\_adv + dt
01111   cs%t\_dyn\_rel\_thermo = cs%t\_dyn\_rel\_thermo + dt
01112   \textcolor{keywordflow}{if} (abs(cs%t\_dyn\_rel\_thermo) < 1e-6*dt) cs%t\_dyn\_rel\_thermo = 0.0
01113   cs%t\_dyn\_rel\_diag = cs%t\_dyn\_rel\_diag + dt
01114 
01115   \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_ae1cf2d523679b925a5e5baa9d974968c}{id\_clock\_dynamics})
01116 
01117   \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}{id\_clock\_other}) ; \textcolor{keyword}{call }cpu\_clock\_begin(
      \hyperlink{namespacemom_aa773fddb51f99098d75304eb271270d4}{id\_clock\_diagnostics})
01118   \textcolor{keyword}{call }enable\_averages(dt, time\_local, cs%diag)
01119   \textcolor{comment}{! These diagnostics are available after every time dynamics step.}
01120   \textcolor{keywordflow}{if} (ids%id\_u > 0) \textcolor{keyword}{call }post\_data(ids%id\_u, u, cs%diag)
01121   \textcolor{keywordflow}{if} (ids%id\_v > 0) \textcolor{keyword}{call }post\_data(ids%id\_v, v, cs%diag)
01122   \textcolor{keywordflow}{if} (ids%id\_h > 0) \textcolor{keyword}{call }post\_data(ids%id\_h, h, cs%diag)
01123   \textcolor{keyword}{call }disable\_averaging(cs%diag)
01124   \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_aa773fddb51f99098d75304eb271270d4}{id\_clock\_diagnostics}) ; \textcolor{keyword}{call }cpu\_clock\_end(
      \hyperlink{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}{id\_clock\_other})
01125 
01126 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom_a42ee7e91ffcf1340679e29ab28d9b41d}{step\_mom\_dynamics}
01127 \textcolor{comment}{}
01128 \textcolor{comment}{!> step\_MOM\_tracer\_dyn does tracer advection and lateral diffusion, bringing the}
01129 \textcolor{comment}{!! tracers up to date with the changes in state due to the dynamics.  Surface}
01130 \textcolor{comment}{!! sources and sinks and remapping are handled via step\_MOM\_thermo.}
01131 \textcolor{keyword}{subroutine }\hyperlink{namespacemom_a0a07938ed3127b70bab5d466967aec80}{step\_mom\_tracer\_dyn}(CS, G, GV, US, h, Time\_local)
\Hypertarget{MOM_8F90_source_l01132}\hyperlink{namespacemom_a0a07938ed3127b70bab5d466967aec80}{01132}   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__control__struct}{mom\_control\_struct}), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{     !< control structure}
01133   \textcolor{keywordtype}{type}(ocean\_grid\_type),    \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{      !< ocean grid structure}
01134   \textcolor{keywordtype}{type}(verticalgrid\_type),  \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{     !< ocean vertical grid structure}
01135   \textcolor{keywordtype}{type}(unit\_scale\_type),    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}
01136   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  &
01137                             \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{      !< layer thicknesses after the transports [H ~> m or kg
       m-2]}
01138   \textcolor{keywordtype}{type}(time\_type),          \textcolor{keywordtype}{intent(in)}    :: Time\_local\textcolor{comment}{ !< The model time at the end}
01139 \textcolor{comment}{                                                    !! of the time step.}
01140   \textcolor{keywordtype}{type}(group\_pass\_type) :: pass\_T\_S
01141   \textcolor{keywordtype}{integer} :: halo\_sz \textcolor{comment}{! The size of a halo where data must be valid.}
01142   \textcolor{keywordtype}{logical} :: showCallTree
01143   showcalltree = calltree\_showquery()
01144 
01145   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
01146     \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}{id\_clock\_other})
01147     \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"Pre-advection h"}, g%HI, haloshift=1, scale=gv%H\_to\_m)
01148     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Pre-advection uhtr"}, cs%uhtr, cs%vhtr, g%HI, &
01149                   haloshift=0, scale=gv%H\_to\_m*us%L\_to\_m**2)
01150     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tv%T)) \textcolor{keyword}{call }hchksum(cs%tv%T, \textcolor{stringliteral}{"Pre-advection T"}, g%HI, haloshift=1)
01151     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tv%S)) \textcolor{keyword}{call }hchksum(cs%tv%S, \textcolor{stringliteral}{"Pre-advection S"}, g%HI, haloshift=1)
01152     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tv%frazil)) \textcolor{keyword}{call }hchksum(cs%tv%frazil, \textcolor{stringliteral}{"Pre-advection frazil"}, g%HI, haloshift=0, &
01153                                                scale=g%US%Q\_to\_J\_kg*g%US%RZ\_to\_kg\_m2)
01154     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tv%salt\_deficit)) \textcolor{keyword}{call }hchksum(cs%tv%salt\_deficit, &
01155                    \textcolor{stringliteral}{"Pre-advection salt deficit"}, g%HI, haloshift=0, scale=us%RZ\_to\_kg\_m2)
01156   \textcolor{comment}{! call MOM\_thermo\_chksum("Pre-advection ", CS%tv, G, US)}
01157     \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}{id\_clock\_other})
01158 \textcolor{keywordflow}{  endif}
01159 
01160   \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a052256dfa3e56390f62ef3a826d62617}{id\_clock\_thermo}) ; \textcolor{keyword}{call }cpu\_clock\_begin(
      \hyperlink{namespacemom_a0fa4debacd02de6fcd066066c232adf3}{id\_clock\_tracer})
01161   \textcolor{keyword}{call }enable\_averages(cs%t\_dyn\_rel\_adv, time\_local, cs%diag)
01162 
01163   \textcolor{keyword}{call }advect\_tracer(h, cs%uhtr, cs%vhtr, cs%OBC, cs%t\_dyn\_rel\_adv, g, gv, us, &
01164                      cs%tracer\_adv\_CSp, cs%tracer\_Reg)
01165   \textcolor{keyword}{call }tracer\_hordiff(h, cs%t\_dyn\_rel\_adv, cs%MEKE, cs%VarMix, g, gv, us, &
01166                       cs%tracer\_diff\_CSp, cs%tracer\_Reg, cs%tv)
01167   \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished tracer advection/diffusion (step\_MOM)"})
01168   \textcolor{keyword}{call }update\_segment\_tracer\_reservoirs(g, gv, cs%uhtr, cs%vhtr, h, cs%OBC, &
01169                      cs%t\_dyn\_rel\_adv, cs%tracer\_Reg)
01170   \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a0fa4debacd02de6fcd066066c232adf3}{id\_clock\_tracer}) ; \textcolor{keyword}{call }cpu\_clock\_end(
      \hyperlink{namespacemom_a052256dfa3e56390f62ef3a826d62617}{id\_clock\_thermo})
01171 
01172   \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}{id\_clock\_other}) ; \textcolor{keyword}{call }cpu\_clock\_begin(
      \hyperlink{namespacemom_aa773fddb51f99098d75304eb271270d4}{id\_clock\_diagnostics})
01173   \textcolor{keyword}{call }post\_transport\_diagnostics(g, gv, us, cs%uhtr, cs%vhtr, h, cs%transport\_IDs, &
01174            cs%diag\_pre\_dyn, cs%diag, cs%t\_dyn\_rel\_adv, cs%tracer\_reg)
01175   \textcolor{comment}{! Rebuild the remap grids now that we've posted the fields which rely on thicknesses}
01176   \textcolor{comment}{! from before the dynamics calls}
01177   \textcolor{keyword}{call }diag\_update\_remap\_grids(cs%diag)
01178 
01179   \textcolor{keyword}{call }disable\_averaging(cs%diag)
01180   \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_aa773fddb51f99098d75304eb271270d4}{id\_clock\_diagnostics}) ; \textcolor{keyword}{call }cpu\_clock\_end(
      \hyperlink{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}{id\_clock\_other})
01181 
01182   \textcolor{comment}{! Reset the accumulated transports to 0 and record that the dynamics}
01183   \textcolor{comment}{! and advective times now agree.}
01184   \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a052256dfa3e56390f62ef3a826d62617}{id\_clock\_thermo}) ; \textcolor{keyword}{call }cpu\_clock\_begin(
      \hyperlink{namespacemom_a0fa4debacd02de6fcd066066c232adf3}{id\_clock\_tracer})
01185   cs%uhtr(:,:,:) = 0.0
01186   cs%vhtr(:,:,:) = 0.0
01187   cs%t\_dyn\_rel\_adv = 0.0
01188   \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a0fa4debacd02de6fcd066066c232adf3}{id\_clock\_tracer}) ; \textcolor{keyword}{call }cpu\_clock\_end(
      \hyperlink{namespacemom_a052256dfa3e56390f62ef3a826d62617}{id\_clock\_thermo})
01189 
01190   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tv%T)) \textcolor{keywordflow}{then}
01191     \textcolor{keyword}{call }extract\_diabatic\_member(cs%diabatic\_CSp, diabatic\_halo=halo\_sz)
01192     \textcolor{keywordflow}{if} (halo\_sz > 0) \textcolor{keywordflow}{then}
01193       \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s, cs%tv%T, g%Domain, to\_all, halo=halo\_sz)
01194       \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s, cs%tv%S, g%Domain, to\_all, halo=halo\_sz)
01195       \textcolor{keyword}{call }do\_group\_pass(pass\_t\_s, g%Domain, clock=\hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass})
01196     \textcolor{keywordflow}{elseif} (cs%diabatic\_first) \textcolor{keywordflow}{then}
01197       \textcolor{comment}{! Temperature and salinity need halo updates because they will be used}
01198       \textcolor{comment}{! in the dynamics before they are changed again.}
01199       \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s, cs%tv%T, g%Domain, to\_all+omit\_corners, halo=1)
01200       \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s, cs%tv%S, g%Domain, to\_all+omit\_corners, halo=1)
01201       \textcolor{keyword}{call }do\_group\_pass(pass\_t\_s, g%Domain, clock=\hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass})
01202 \textcolor{keywordflow}{    endif}
01203 \textcolor{keywordflow}{  endif}
01204 
01205   cs%preadv\_h\_stored = .false.
01206 
01207 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom_a0a07938ed3127b70bab5d466967aec80}{step\_mom\_tracer\_dyn}
01208 \textcolor{comment}{}
01209 \textcolor{comment}{!> MOM\_step\_thermo orchestrates the thermodynamic time stepping and vertical}
01210 \textcolor{comment}{!! remapping, via calls to diabatic (or adiabatic) and ALE\_main.}
01211 \textcolor{keyword}{subroutine }\hyperlink{namespacemom_a1a81ea749a309f10f5c3c7a17efa3606}{step\_mom\_thermo}(CS, G, GV, US, u, v, h, tv, fluxes, dtdia, &
01212                            Time\_end\_thermo, update\_BBL, Waves)
\Hypertarget{MOM_8F90_source_l01213}\hyperlink{namespacemom_a1a81ea749a309f10f5c3c7a17efa3606}{01213}   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__control__struct}{mom\_control\_struct}), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{     !< Master MOM control structure}
01214   \textcolor{keywordtype}{type}(ocean\_grid\_type),    \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{      !< ocean grid structure}
01215   \textcolor{keywordtype}{type}(verticalgrid\_type),  \textcolor{keywordtype}{intent(inout)} :: GV\textcolor{comment}{     !< ocean vertical grid structure}
01216   \textcolor{keywordtype}{type}(unit\_scale\_type),    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{     !< A dimensional unit scaling type}
01217   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
01218                             \textcolor{keywordtype}{intent(inout)} :: u\textcolor{comment}{      !< zonal velocity [L T-1 ~> m s-1]}
01219   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
01220                             \textcolor{keywordtype}{intent(inout)} :: v\textcolor{comment}{      !< meridional velocity [L T-1 ~> m s-1]}
01221   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  &
01222                             \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{      !< layer thickness [H ~> m or kg m-2]}
01223   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),    \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{     !< A structure pointing to various thermodynamic
       variables}
01224   \textcolor{keywordtype}{type}(forcing),            \textcolor{keywordtype}{intent(inout)} :: fluxes\textcolor{comment}{ !< pointers to forcing fields}
01225   \textcolor{keywordtype}{real},                     \textcolor{keywordtype}{intent(in)}    :: dtdia\textcolor{comment}{  !< The time interval over which to advance [T ~> s]}
01226   \textcolor{keywordtype}{type}(time\_type),          \textcolor{keywordtype}{intent(in)}    :: Time\_end\_thermo\textcolor{comment}{ !< End of averaging interval for thermo diags}
01227   \textcolor{keywordtype}{logical},                  \textcolor{keywordtype}{intent(in)}    :: update\_BBL\textcolor{comment}{ !< If true, calculate the bottom boundary layer
       properties.}
01228   \textcolor{keywordtype}{type}(wave\_parameters\_cs), &
01229                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: Waves\textcolor{comment}{  !< Container for wave related parameters}
01230 \textcolor{comment}{                                                    !! the fields in Waves are intent in here.}
01231 
01232   \textcolor{keywordtype}{logical} :: use\_ice\_shelf \textcolor{comment}{! Needed for selecting the right ALE interface.}
01233   \textcolor{keywordtype}{logical} :: showCallTree
01234   \textcolor{keywordtype}{type}(group\_pass\_type) :: pass\_T\_S, pass\_T\_S\_h, pass\_uv\_T\_S\_h
01235   \textcolor{keywordtype}{integer} :: dynamics\_stencil  \textcolor{comment}{! The computational stencil for the calculations}
01236                                \textcolor{comment}{! in the dynamic core.}
01237   \textcolor{keywordtype}{integer} :: halo\_sz \textcolor{comment}{! The size of a halo where data must be valid.}
01238   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz
01239 
01240   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
01241   showcalltree = calltree\_showquery()
01242   \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"step\_MOM\_thermo(), MOM.F90"})
01243 
01244   use\_ice\_shelf = .false.
01245   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes%frac\_shelf\_h)) use\_ice\_shelf = .true.
01246 
01247   \textcolor{keyword}{call }enable\_averages(dtdia, time\_end\_thermo, cs%diag)
01248 
01249   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%odaCS)) \textcolor{keywordflow}{then}
01250     \textcolor{keyword}{call }apply\_oda\_tracer\_increments(us%T\_to\_s*dtdia,g,tv,h,cs%odaCS)
01251 \textcolor{keywordflow}{  endif}
01252 
01253   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes%p\_surf) .or. \textcolor{keyword}{associated}(fluxes%p\_surf\_full)) \textcolor{keywordflow}{then}
01254     \textcolor{keyword}{call }extract\_diabatic\_member(cs%diabatic\_CSp, diabatic\_halo=halo\_sz)
01255     \textcolor{keywordflow}{if} (halo\_sz > 0) \textcolor{keywordflow}{then}
01256       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(fluxes%p\_surf\_full)) &
01257         \textcolor{keyword}{call }pass\_var(fluxes%p\_surf\_full, g%Domain, &
01258                       clock=\hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass}, halo=halo\_sz, complete=.not.\textcolor{keyword}{associated}(fluxes
      %p\_surf))
01259       \textcolor{keyword}{call }pass\_var(fluxes%p\_surf, g%Domain, clock=\hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass}, halo=halo\_sz, complete=.true
      .)
01260 \textcolor{keywordflow}{    endif}
01261 \textcolor{keywordflow}{  endif}
01262 
01263   \textcolor{keywordflow}{if} (update\_bbl) \textcolor{keywordflow}{then}
01264     \textcolor{comment}{!   Calculate the BBL properties and store them inside visc (u,h).}
01265     \textcolor{comment}{! This is here so that CS%visc is updated before diabatic() when}
01266     \textcolor{comment}{! DIABATIC\_FIRST=True. Otherwise diabatic() is called after the dynamics}
01267     \textcolor{comment}{! and set\_viscous\_BBL is called as a part of the dynamic stepping.}
01268     \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_aa69e79e4c51e1c24c474b84311322251}{id\_clock\_bbl\_visc})
01269     \textcolor{keyword}{call }set\_viscous\_bbl(u, v, h, tv, cs%visc, g, gv, us, cs%set\_visc\_CSp, symmetrize=.true.)
01270     \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_aa69e79e4c51e1c24c474b84311322251}{id\_clock\_bbl\_visc})
01271     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"done with set\_viscous\_BBL (step\_MOM\_thermo)"})
01272 \textcolor{keywordflow}{  endif}
01273 
01274   \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a052256dfa3e56390f62ef3a826d62617}{id\_clock\_thermo})
01275   \textcolor{keywordflow}{if} (.not.cs%adiabatic) \textcolor{keywordflow}{then}
01276     \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
01277       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Pre-diabatic [uv]"}, u, v, g%HI, haloshift=2, scale=us%L\_T\_to\_m\_s)
01278       \textcolor{keyword}{call }hchksum(h,\textcolor{stringliteral}{"Pre-diabatic h"}, g%HI, haloshift=1, scale=gv%H\_to\_m)
01279       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Pre-diabatic [uv]h"}, cs%uhtr, cs%vhtr, g%HI, &
01280                     haloshift=0, scale=gv%H\_to\_m*us%L\_to\_m**2)
01281     \textcolor{comment}{! call MOM\_state\_chksum("Pre-diabatic ", u, v, h, CS%uhtr, CS%vhtr, G, GV, vel\_scale=1.0)}
01282       \textcolor{keyword}{call }mom\_thermo\_chksum(\textcolor{stringliteral}{"Pre-diabatic "}, tv, g, us, haloshift=0)
01283       \textcolor{keyword}{call }check\_redundant(\textcolor{stringliteral}{"Pre-diabatic "}, u, v, g)
01284       \textcolor{keyword}{call }mom\_forcing\_chksum(\textcolor{stringliteral}{"Pre-diabatic"}, fluxes, g, us, haloshift=0)
01285 \textcolor{keywordflow}{    endif}
01286 
01287     \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a50edf00aa5998073d2db0360949253ba}{id\_clock\_diabatic})
01288 
01289     \textcolor{keyword}{call }diabatic(u, v, h, tv, cs%Hml, fluxes, cs%visc, cs%ADp, cs%CDp, dtdia, &
01290                   time\_end\_thermo, g, gv, us, cs%diabatic\_CSp, obc=cs%OBC, waves=waves)
01291     fluxes%fluxes\_used = .true.
01292 
01293     \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished diabatic (step\_MOM\_thermo)"})
01294 
01295     \textcolor{comment}{! Regridding/remapping is done here, at end of thermodynamics time step}
01296     \textcolor{comment}{! (that may comprise several dynamical time steps)}
01297     \textcolor{comment}{! The routine 'ALE\_main' can be found in 'MOM\_ALE.F90'.}
01298     \textcolor{keywordflow}{if} ( cs%use\_ALE\_algorithm ) \textcolor{keywordflow}{then}
01299       \textcolor{keyword}{call }enable\_averages(dtdia, time\_end\_thermo, cs%diag)
01300 \textcolor{comment}{!         call pass\_vector(u, v, G%Domain)}
01301       \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass})
01302       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%T)) &
01303         \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s\_h, tv%T, g%Domain, to\_all+omit\_corners, halo=1)
01304       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%S)) &
01305         \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s\_h, tv%S, g%Domain, to\_all+omit\_corners, halo=1)
01306       \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s\_h, h, g%Domain, to\_all+omit\_corners, halo=1)
01307       \textcolor{keyword}{call }do\_group\_pass(pass\_t\_s\_h, g%Domain)
01308       \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass})
01309 
01310       \textcolor{keyword}{call }preale\_tracer\_diagnostics(cs%tracer\_Reg, g, gv)
01311 
01312       \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
01313         \textcolor{keyword}{call }mom\_state\_chksum(\textcolor{stringliteral}{"Pre-ALE "}, u, v, h, cs%uh, cs%vh, g, gv, us)
01314         \textcolor{keyword}{call }hchksum(tv%T,\textcolor{stringliteral}{"Pre-ALE T"}, g%HI, haloshift=1)
01315         \textcolor{keyword}{call }hchksum(tv%S,\textcolor{stringliteral}{"Pre-ALE S"}, g%HI, haloshift=1)
01316         \textcolor{keyword}{call }check\_redundant(\textcolor{stringliteral}{"Pre-ALE "}, u, v, g)
01317 \textcolor{keywordflow}{      endif}
01318       \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a722ed13d0e6d76852e680054a0e3c964}{id\_clock\_ale})
01319       \textcolor{keywordflow}{if} (use\_ice\_shelf) \textcolor{keywordflow}{then}
01320         \textcolor{keyword}{call }ale\_main(g, gv, us, h, u, v, tv, cs%tracer\_Reg, cs%ALE\_CSp, cs%OBC, &
01321                       dtdia, fluxes%frac\_shelf\_h)
01322       \textcolor{keywordflow}{else}
01323         \textcolor{keyword}{call }ale\_main(g, gv, us, h, u, v, tv, cs%tracer\_Reg, cs%ALE\_CSp, cs%OBC, dtdia)
01324 \textcolor{keywordflow}{      endif}
01325 
01326       \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"finished ALE\_main (step\_MOM\_thermo)"})
01327       \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a722ed13d0e6d76852e680054a0e3c964}{id\_clock\_ale})
01328 \textcolor{keywordflow}{    endif}   \textcolor{comment}{! endif for the block "if ( CS%use\_ALE\_algorithm )"}
01329 
01330     dynamics\_stencil = min(3, g%Domain%nihalo, g%Domain%njhalo)
01331     \textcolor{keyword}{call }create\_group\_pass(pass\_uv\_t\_s\_h, u, v, g%Domain, halo=dynamics\_stencil)
01332     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%T)) &
01333       \textcolor{keyword}{call }create\_group\_pass(pass\_uv\_t\_s\_h, tv%T, g%Domain, halo=dynamics\_stencil)
01334     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%S)) &
01335       \textcolor{keyword}{call }create\_group\_pass(pass\_uv\_t\_s\_h, tv%S, g%Domain, halo=dynamics\_stencil)
01336     \textcolor{keyword}{call }create\_group\_pass(pass\_uv\_t\_s\_h, h, g%Domain, halo=dynamics\_stencil)
01337     \textcolor{keyword}{call }do\_group\_pass(pass\_uv\_t\_s\_h, g%Domain, clock=\hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass})
01338 
01339     \textcolor{keywordflow}{if} (cs%debug .and. cs%use\_ALE\_algorithm) \textcolor{keywordflow}{then}
01340       \textcolor{keyword}{call }mom\_state\_chksum(\textcolor{stringliteral}{"Post-ALE "}, u, v, h, cs%uh, cs%vh, g, gv, us)
01341       \textcolor{keyword}{call }hchksum(tv%T, \textcolor{stringliteral}{"Post-ALE T"}, g%HI, haloshift=1)
01342       \textcolor{keyword}{call }hchksum(tv%S, \textcolor{stringliteral}{"Post-ALE S"}, g%HI, haloshift=1)
01343       \textcolor{keyword}{call }check\_redundant(\textcolor{stringliteral}{"Post-ALE "}, u, v, g)
01344 \textcolor{keywordflow}{    endif}
01345 
01346     \textcolor{comment}{! Whenever thickness changes let the diag manager know, target grids}
01347     \textcolor{comment}{! for vertical remapping may need to be regenerated. This needs to}
01348     \textcolor{comment}{! happen after the H update and before the next post\_data.}
01349     \textcolor{keyword}{call }diag\_update\_remap\_grids(cs%diag)
01350 
01351     \textcolor{comment}{!### Consider moving this up into the if ALE block.}
01352     \textcolor{keyword}{call }postale\_tracer\_diagnostics(cs%tracer\_Reg, g, gv, cs%diag, dtdia)
01353 
01354     \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
01355       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Post-diabatic u"}, u, v, g%HI, haloshift=2, scale=us%L\_T\_to\_m\_s)
01356       \textcolor{keyword}{call }hchksum(h, \textcolor{stringliteral}{"Post-diabatic h"}, g%HI, haloshift=1, scale=gv%H\_to\_m)
01357       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Post-diabatic [uv]h"}, cs%uhtr, cs%vhtr, g%HI, &
01358                     haloshift=0, scale=gv%H\_to\_m*us%L\_to\_m**2)
01359     \textcolor{comment}{! call MOM\_state\_chksum("Post-diabatic ", u, v, &}
01360     \textcolor{comment}{!                       h, CS%uhtr, CS%vhtr, G, GV, haloshift=1)}
01361       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%T)) \textcolor{keyword}{call }hchksum(tv%T, \textcolor{stringliteral}{"Post-diabatic T"}, g%HI, haloshift=1)
01362       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%S)) \textcolor{keyword}{call }hchksum(tv%S, \textcolor{stringliteral}{"Post-diabatic S"}, g%HI, haloshift=1)
01363       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%frazil)) \textcolor{keyword}{call }hchksum(tv%frazil, \textcolor{stringliteral}{"Post-diabatic frazil"}, g%HI, haloshift=0, &
01364                                               scale=g%US%Q\_to\_J\_kg*g%US%RZ\_to\_kg\_m2)
01365       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%salt\_deficit)) \textcolor{keyword}{call }hchksum(tv%salt\_deficit, &
01366                                \textcolor{stringliteral}{"Post-diabatic salt deficit"}, g%HI, haloshift=0, scale=us%RZ\_to\_kg\_m2)
01367     \textcolor{comment}{! call MOM\_thermo\_chksum("Post-diabatic ", tv, G, US)}
01368       \textcolor{keyword}{call }check\_redundant(\textcolor{stringliteral}{"Post-diabatic "}, u, v, g)
01369 \textcolor{keywordflow}{    endif}
01370     \textcolor{keyword}{call }disable\_averaging(cs%diag)
01371 
01372     \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a50edf00aa5998073d2db0360949253ba}{id\_clock\_diabatic})
01373   \textcolor{keywordflow}{else}   \textcolor{comment}{! complement of "if (.not.CS%adiabatic)"}
01374 
01375     \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_af865d838388a05163e8de8d266316d5f}{id\_clock\_adiabatic})
01376     \textcolor{keyword}{call }adiabatic(h, tv, fluxes, dtdia, g, gv, us, cs%diabatic\_CSp)
01377     fluxes%fluxes\_used = .true.
01378     \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_af865d838388a05163e8de8d266316d5f}{id\_clock\_adiabatic})
01379 
01380     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%T)) \textcolor{keywordflow}{then}
01381       \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s, tv%T, g%Domain, to\_all+omit\_corners, halo=1)
01382       \textcolor{keyword}{call }create\_group\_pass(pass\_t\_s, tv%S, g%Domain, to\_all+omit\_corners, halo=1)
01383       \textcolor{keyword}{call }do\_group\_pass(pass\_t\_s, g%Domain, clock=\hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass})
01384       \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
01385         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%T)) \textcolor{keyword}{call }hchksum(tv%T, \textcolor{stringliteral}{"Post-diabatic T"}, g%HI, haloshift=1)
01386         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%S)) \textcolor{keyword}{call }hchksum(tv%S, \textcolor{stringliteral}{"Post-diabatic S"}, g%HI, haloshift=1)
01387 \textcolor{keywordflow}{      endif}
01388 \textcolor{keywordflow}{    endif}
01389 
01390 \textcolor{keywordflow}{  endif}   \textcolor{comment}{! endif for the block "if (.not.CS%adiabatic)"}
01391   \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a052256dfa3e56390f62ef3a826d62617}{id\_clock\_thermo})
01392 
01393   \textcolor{keyword}{call }disable\_averaging(cs%diag)
01394 
01395   \textcolor{keywordflow}{if} (showcalltree) \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"step\_MOM\_thermo(), MOM.F90"})
01396 
01397 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom_a1a81ea749a309f10f5c3c7a17efa3606}{step\_mom\_thermo}
01398 
01399 \textcolor{comment}{}
01400 \textcolor{comment}{!> step\_offline is the main driver for running tracers offline in MOM6. This has been primarily}
01401 \textcolor{comment}{!! developed with ALE configurations in mind. Some work has been done in isopycnal configuration, but}
01402 \textcolor{comment}{!! the work is very preliminary. Some more detail about this capability along with some of the subroutines}
01403 \textcolor{comment}{!! called here can be found in tracers/MOM\_offline\_control.F90}
01404 \textcolor{keyword}{subroutine }\hyperlink{namespacemom_ade4f7557fcda73ffc12284d3cecf4182}{step\_offline}(forces, fluxes, sfc\_state, Time\_start, time\_interval, CS)
\Hypertarget{MOM_8F90_source_l01405}\hyperlink{namespacemom_ade4f7557fcda73ffc12284d3cecf4182}{01405}   \textcolor{keywordtype}{type}(mech\_forcing), \textcolor{keywordtype}{intent(in)}    :: forces\textcolor{comment}{        !< A structure with the driving mechanical forces}
01406   \textcolor{keywordtype}{type}(forcing),      \textcolor{keywordtype}{intent(inout)} :: fluxes\textcolor{comment}{        !< pointers to forcing fields}
01407   \textcolor{keywordtype}{type}(surface),      \textcolor{keywordtype}{intent(inout)} :: sfc\_state\textcolor{comment}{     !< surface ocean state}
01408   \textcolor{keywordtype}{type}(time\_type),    \textcolor{keywordtype}{intent(in)}    :: Time\_start\textcolor{comment}{    !< starting time of a segment, as a time type}
01409   \textcolor{keywordtype}{real},               \textcolor{keywordtype}{intent(in)}    :: time\_interval\textcolor{comment}{ !< time interval}
01410   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__control__struct}{mom\_control\_struct}), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{            !< control structure from
       initialize\_MOM}
01411 
01412   \textcolor{comment}{! Local pointers}
01413   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{pointer} :: G  => null() \textcolor{comment}{! Pointer to a structure containing}
01414                                                       \textcolor{comment}{! metrics and related information}
01415   \textcolor{keywordtype}{type}(verticalgrid\_type),    \textcolor{keywordtype}{pointer} :: GV => null() \textcolor{comment}{! Pointer to structure containing information}
01416                                                       \textcolor{comment}{! about the vertical grid}
01417   \textcolor{keywordtype}{type}(unit\_scale\_type),      \textcolor{keywordtype}{pointer} :: US => null() \textcolor{comment}{! Pointer to a structure containing}
01418                                                       \textcolor{comment}{! various unit conversion factors}
01419 
01420   \textcolor{keywordtype}{logical} :: first\_iter\textcolor{comment}{    !< True if this is the first time step\_offline has been called in a given
       interval}
01421   \textcolor{keywordtype}{logical} :: last\_iter\textcolor{comment}{     !< True if this is the last time step\_tracer is to be called in an offline
       interval}
01422   \textcolor{keywordtype}{logical} :: do\_vertical\textcolor{comment}{   !< If enough time has elapsed, do the diabatic tracer sources/sinks}
01423   \textcolor{keywordtype}{logical} :: adv\_converged\textcolor{comment}{ !< True if all the horizontal fluxes have been used}
01424 
01425   \textcolor{keywordtype}{real} :: dt\_offline          \textcolor{comment}{! The offline timestep for advection [T ~> s]}
01426   \textcolor{keywordtype}{real} :: dt\_offline\_vertical \textcolor{comment}{! The offline timestep for vertical fluxes and remapping [T ~> s]}
01427   \textcolor{keywordtype}{logical} :: skip\_diffusion
01428   \textcolor{keywordtype}{integer} :: id\_eta\_diff\_end
01429 
01430   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{pointer} :: accumulated\_time => null()
01431   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{pointer} :: vertical\_time => null()
01432   \textcolor{keywordtype}{integer} :: i,j,k
01433   \textcolor{keywordtype}{integer} :: is, ie, js, je, isd, ied, jsd, jed
01434 
01435   \textcolor{comment}{! 3D pointers}
01436   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{pointer} :: &
01437     uhtr => null(), vhtr => null(), &
01438     eatr => null(), ebtr => null(), &
01439     h\_end => null()
01440 
01441   \textcolor{comment}{! 2D Array for diagnostics}
01442   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(CS%G),SZJ\_(CS%G))} :: eta\_pre, eta\_end
01443   \textcolor{keywordtype}{type}(time\_type) :: Time\_end    \textcolor{comment}{! End time of a segment, as a time type}
01444 
01445   \textcolor{comment}{! Grid-related pointer assignments}
01446   g => cs%G ; gv => cs%GV ; us => cs%US
01447 
01448   is  = g%isc  ; ie  = g%iec  ; js  = g%jsc  ; je  = g%jec
01449   isd = g%isd  ; ied = g%ied  ; jsd = g%jsd  ; jed = g%jed
01450 
01451   \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a2ab767469f0d918b9e479d8e0fde44b0}{id\_clock\_offline\_tracer})
01452   \textcolor{keyword}{call }extract\_offline\_main(cs%offline\_CSp, uhtr, vhtr, eatr, ebtr, h\_end, accumulated\_time, &
01453                             vertical\_time, dt\_offline, dt\_offline\_vertical, skip\_diffusion)
01454   time\_end = increment\_date(time\_start, seconds=floor(time\_interval+0.001))
01455 
01456   \textcolor{keyword}{call }enable\_averaging(time\_interval, time\_end, cs%diag)
01457 
01458   \textcolor{comment}{! Check to see if this is the first iteration of the offline interval}
01459   \textcolor{keywordflow}{if} (accumulated\_time == real\_to\_time(0.0)) \textcolor{keywordflow}{then}
01460     first\_iter = .true.
01461   \textcolor{keywordflow}{else} \textcolor{comment}{! This is probably unnecessary but is used to guard against unwanted behavior}
01462     first\_iter = .false.
01463 \textcolor{keywordflow}{  endif}
01464 
01465   \textcolor{comment}{! Check to see if vertical tracer functions should be done}
01466   \textcolor{keywordflow}{if} (first\_iter .or. (accumulated\_time >= vertical\_time)) \textcolor{keywordflow}{then}
01467     do\_vertical = .true.
01468     vertical\_time = accumulated\_time + real\_to\_time(us%T\_to\_s*dt\_offline\_vertical)
01469   \textcolor{keywordflow}{else}
01470     do\_vertical = .false.
01471 \textcolor{keywordflow}{  endif}
01472 
01473   \textcolor{comment}{! Increment the amount of time elapsed since last read and check if it's time to roll around}
01474   accumulated\_time = accumulated\_time + real\_to\_time(time\_interval)
01475 
01476   last\_iter = (accumulated\_time >= real\_to\_time(us%T\_to\_s*dt\_offline))
01477 
01478   \textcolor{keywordflow}{if} (cs%use\_ALE\_algorithm) \textcolor{keywordflow}{then}
01479     \textcolor{comment}{! If this is the first iteration in the offline timestep, then we need to read in fields and}
01480     \textcolor{comment}{! perform the main advection.}
01481     \textcolor{keywordflow}{if} (first\_iter) \textcolor{keywordflow}{then}
01482       \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Reading in new offline fields"})
01483       \textcolor{comment}{! Read in new transport and other fields}
01484       \textcolor{comment}{! call update\_transport\_from\_files(G, GV, CS%offline\_CSp, h\_end, eatr, ebtr, uhtr, vhtr, &}
01485       \textcolor{comment}{!     CS%tv%T, CS%tv%S, fluxes, CS%use\_ALE\_algorithm)}
01486       \textcolor{comment}{! call update\_transport\_from\_arrays(CS%offline\_CSp)}
01487       \textcolor{keyword}{call }update\_offline\_fields(cs%offline\_CSp, cs%h, fluxes, cs%use\_ALE\_algorithm)
01488 
01489       \textcolor{comment}{! Apply any fluxes into the ocean}
01490       \textcolor{keyword}{call }offline\_fw\_fluxes\_into\_ocean(g, gv, cs%offline\_CSp, fluxes, cs%h)
01491 
01492       \textcolor{keywordflow}{if} (.not.cs%diabatic\_first) \textcolor{keywordflow}{then}
01493         \textcolor{keyword}{call }offline\_advection\_ale(fluxes, time\_start, time\_interval, cs%offline\_CSp, 
      \hyperlink{namespacemom_a722ed13d0e6d76852e680054a0e3c964}{id\_clock\_ale}, &
01494             cs%h, uhtr, vhtr, converged=adv\_converged)
01495 
01496         \textcolor{comment}{! Redistribute any remaining transport}
01497         \textcolor{keyword}{call }offline\_redistribute\_residual(cs%offline\_CSp, cs%h, uhtr, vhtr, adv\_converged)
01498 
01499         \textcolor{comment}{! Perform offline diffusion if requested}
01500         \textcolor{keywordflow}{if} (.not. skip\_diffusion) \textcolor{keywordflow}{then}
01501           \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%VarMix)) \textcolor{keywordflow}{then}
01502             \textcolor{keyword}{call }pass\_var(cs%h, g%Domain)
01503             \textcolor{keyword}{call }calc\_resoln\_function(cs%h, cs%tv, g, gv, us, cs%VarMix)
01504             \textcolor{keyword}{call }calc\_depth\_function(g, cs%VarMix)
01505             \textcolor{keyword}{call }calc\_slope\_functions(cs%h, cs%tv, dt\_offline, g, gv, us, cs%VarMix, obc=cs%OBC)
01506 \textcolor{keywordflow}{          endif}
01507           \textcolor{keyword}{call }tracer\_hordiff(cs%h, dt\_offline, cs%MEKE, cs%VarMix, g, gv, us, &
01508               cs%tracer\_diff\_CSp, cs%tracer\_Reg, cs%tv)
01509 \textcolor{keywordflow}{        endif}
01510 \textcolor{keywordflow}{      endif}
01511 \textcolor{keywordflow}{    endif}
01512     \textcolor{comment}{! The functions related to column physics of tracers is performed separately in ALE mode}
01513     \textcolor{keywordflow}{if} (do\_vertical) \textcolor{keywordflow}{then}
01514       \textcolor{keyword}{call }offline\_diabatic\_ale(fluxes, time\_start, time\_end, cs%offline\_CSp, cs%h, eatr, ebtr)
01515 \textcolor{keywordflow}{    endif}
01516 
01517     \textcolor{comment}{! Last thing that needs to be done is the final ALE remapping}
01518     \textcolor{keywordflow}{if} (last\_iter) \textcolor{keywordflow}{then}
01519       \textcolor{keywordflow}{if} (cs%diabatic\_first) \textcolor{keywordflow}{then}
01520         \textcolor{keyword}{call }offline\_advection\_ale(fluxes, time\_start, time\_interval, cs%offline\_CSp, 
      \hyperlink{namespacemom_a722ed13d0e6d76852e680054a0e3c964}{id\_clock\_ale}, &
01521             cs%h, uhtr, vhtr, converged=adv\_converged)
01522 
01523         \textcolor{comment}{! Redistribute any remaining transport and perform the remaining advection}
01524         \textcolor{keyword}{call }offline\_redistribute\_residual(cs%offline\_CSp, cs%h, uhtr, vhtr, adv\_converged)
01525                 \textcolor{comment}{! Perform offline diffusion if requested}
01526         \textcolor{keywordflow}{if} (.not. skip\_diffusion) \textcolor{keywordflow}{then}
01527           \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%VarMix)) \textcolor{keywordflow}{then}
01528             \textcolor{keyword}{call }pass\_var(cs%h, g%Domain)
01529             \textcolor{keyword}{call }calc\_resoln\_function(cs%h, cs%tv, g, gv, us, cs%VarMix)
01530             \textcolor{keyword}{call }calc\_depth\_function(g, cs%VarMix)
01531             \textcolor{keyword}{call }calc\_slope\_functions(cs%h, cs%tv, dt\_offline, g, gv, us, cs%VarMix, obc=cs%OBC)
01532 \textcolor{keywordflow}{          endif}
01533           \textcolor{keyword}{call }tracer\_hordiff(cs%h, dt\_offline, cs%MEKE, cs%VarMix, g, gv, us, &
01534               cs%tracer\_diff\_CSp, cs%tracer\_Reg, cs%tv)
01535 \textcolor{keywordflow}{        endif}
01536 \textcolor{keywordflow}{      endif}
01537 
01538       \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Last iteration of offline interval"})
01539 
01540       \textcolor{comment}{! Apply freshwater fluxes out of the ocean}
01541       \textcolor{keyword}{call }offline\_fw\_fluxes\_out\_ocean(g, gv, cs%offline\_CSp, fluxes, cs%h)
01542       \textcolor{comment}{! These diagnostic can be used to identify which grid points did not converge within}
01543       \textcolor{comment}{! the specified number of advection sub iterations}
01544       \textcolor{keyword}{call }post\_offline\_convergence\_diags(cs%offline\_CSp, cs%h, h\_end, uhtr, vhtr)
01545 
01546       \textcolor{comment}{! Call ALE one last time to make sure that tracers are remapped onto the layer thicknesses}
01547       \textcolor{comment}{! stored from the forward run}
01548       \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a722ed13d0e6d76852e680054a0e3c964}{id\_clock\_ale})
01549       \textcolor{keyword}{call }ale\_offline\_tracer\_final( g, gv, cs%h, cs%tv, h\_end, cs%tracer\_Reg, cs%ALE\_CSp, cs%OBC)
01550       \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a722ed13d0e6d76852e680054a0e3c964}{id\_clock\_ale})
01551       \textcolor{keyword}{call }pass\_var(cs%h, g%Domain)
01552 \textcolor{keywordflow}{    endif}
01553   \textcolor{keywordflow}{else} \textcolor{comment}{! NON-ALE MODE...NOT WELL TESTED}
01554     \textcolor{keyword}{call }mom\_error(warning, &
01555         \textcolor{stringliteral}{"Offline tracer mode in non-ALE configuration has not been thoroughly tested"})
01556     \textcolor{comment}{! Note that for the layer mode case, the calls to tracer sources and sinks is embedded in}
01557     \textcolor{comment}{! main\_offline\_advection\_layer. Warning: this may not be appropriate for tracers that}
01558     \textcolor{comment}{! exchange with the atmosphere}
01559     \textcolor{keywordflow}{if} (abs(time\_interval - us%T\_to\_s*dt\_offline) > 1.0e-6) \textcolor{keywordflow}{then}
01560       \textcolor{keyword}{call }mom\_error(fatal, &
01561           \textcolor{stringliteral}{"For offline tracer mode in a non-ALE configuration, dt\_offline must equal time\_interval"})
01562 \textcolor{keywordflow}{    endif}
01563     \textcolor{keyword}{call }update\_offline\_fields(cs%offline\_CSp, cs%h, fluxes, cs%use\_ALE\_algorithm)
01564     \textcolor{keyword}{call }offline\_advection\_layer(fluxes, time\_start, time\_interval, cs%offline\_CSp, &
01565         cs%h, eatr, ebtr, uhtr, vhtr)
01566     \textcolor{comment}{! Perform offline diffusion if requested}
01567     \textcolor{keywordflow}{if} (.not. skip\_diffusion) \textcolor{keywordflow}{then}
01568       \textcolor{keyword}{call }tracer\_hordiff(h\_end, dt\_offline, cs%MEKE, cs%VarMix, g, gv, us, &
01569                           cs%tracer\_diff\_CSp, cs%tracer\_Reg, cs%tv)
01570 \textcolor{keywordflow}{    endif}
01571 
01572     cs%h = h\_end
01573 
01574     \textcolor{keyword}{call }pass\_var(cs%tv%T, g%Domain)
01575     \textcolor{keyword}{call }pass\_var(cs%tv%S, g%Domain)
01576     \textcolor{keyword}{call }pass\_var(cs%h, g%Domain)
01577 
01578 \textcolor{keywordflow}{  endif}
01579 
01580   \textcolor{keyword}{call }\hyperlink{namespacemom_a16f7cc52cef3eb7a99687bf3d0694285}{adjust\_ssh\_for\_p\_atm}(cs%tv, g, gv, us, cs%ave\_ssh\_ibc, forces%p\_surf\_SSH, &
01581                             cs%calc\_rho\_for\_sea\_lev)
01582   \textcolor{keyword}{call }\hyperlink{namespacemom_a699d6c5bfb5b9dcdaa03c18806fa824e}{extract\_surface\_state}(cs, sfc\_state)
01583 
01584   \textcolor{keyword}{call }disable\_averaging(cs%diag)
01585   \textcolor{keyword}{call }pass\_var(cs%tv%T, g%Domain)
01586   \textcolor{keyword}{call }pass\_var(cs%tv%S, g%Domain)
01587   \textcolor{keyword}{call }pass\_var(cs%h, g%Domain)
01588 
01589   fluxes%fluxes\_used = .true.
01590 
01591   \textcolor{keywordflow}{if} (last\_iter) \textcolor{keywordflow}{then}
01592     accumulated\_time = real\_to\_time(0.0)
01593 \textcolor{keywordflow}{  endif}
01594 
01595   \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a2ab767469f0d918b9e479d8e0fde44b0}{id\_clock\_offline\_tracer})
01596 
01597 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom_ade4f7557fcda73ffc12284d3cecf4182}{step\_offline}
01598 \textcolor{comment}{}
01599 \textcolor{comment}{!> Initialize MOM, including memory allocation, setting up parameters and diagnostics,}
01600 \textcolor{comment}{!! initializing the ocean state variables, and initializing subsidiary modules}
01601 \textcolor{keyword}{subroutine }\hyperlink{namespacemom_a96708b16215666edbfa5b46228f3a200}{initialize\_mom}(Time, Time\_init, param\_file, dirs, CS, restart\_CSp, &
01602                           Time\_in, offline\_tracer\_mode, input\_restart\_file, diag\_ptr, &
01603                           count\_calls, tracer\_flow\_CSp)
\Hypertarget{MOM_8F90_source_l01604}\hyperlink{namespacemom_a96708b16215666edbfa5b46228f3a200}{01604}   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target},   \textcolor{keywordtype}{intent(inout)} :: Time\textcolor{comment}{        !< model time, set in this routine}
01605   \textcolor{keywordtype}{type}(time\_type),           \textcolor{keywordtype}{intent(in)}    :: Time\_init\textcolor{comment}{   !< The start time for the coupled model's
       calendar}
01606   \textcolor{keywordtype}{type}(param\_file\_type),     \textcolor{keywordtype}{intent(out)}   :: param\_file\textcolor{comment}{  !< structure indicating parameter file to parse}
01607   \textcolor{keywordtype}{type}(directories),         \textcolor{keywordtype}{intent(out)}   :: dirs\textcolor{comment}{        !< structure with directory paths}
01608   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__control__struct}{mom\_control\_struct}),  \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{          !< pointer set in this routine
       to MOM control structure}
01609   \textcolor{keywordtype}{type}(mom\_restart\_cs),      \textcolor{keywordtype}{pointer}       :: restart\_CSp\textcolor{comment}{ !< pointer set in this routine to the}
01610 \textcolor{comment}{                                                          !! restart control structure that will}
01611 \textcolor{comment}{                                                          !! be used for MOM.}
01612   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: Time\_in\textcolor{comment}{     !< time passed to MOM\_initialize\_state when}
01613 \textcolor{comment}{                                                          !! model is not being started from a restart file}
01614   \textcolor{keywordtype}{logical},         \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: offline\_tracer\_mode\textcolor{comment}{ !< True is returned if tracers are being
       run offline}
01615   \textcolor{keywordtype}{character(len=*)},\textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: input\_restart\_file\textcolor{comment}{ !< If present, name of restart file to
       read}
01616   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: diag\_ptr\textcolor{comment}{    !< A pointer set in this routine to the
       diagnostic}
01617 \textcolor{comment}{                                                          !! regulatory structure}
01618   \textcolor{keywordtype}{type}(tracer\_flow\_control\_cs), &
01619                    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: tracer\_flow\_CSp\textcolor{comment}{ !< A pointer set in this routine to}
01620 \textcolor{comment}{                                                          !! the tracer flow control structure.}
01621   \textcolor{keywordtype}{logical},         \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: count\_calls\textcolor{comment}{ !< If true, nstep\_tot counts the number of}
01622 \textcolor{comment}{                                                          !! calls to step\_MOM instead of the number of}
01623 \textcolor{comment}{                                                          !! dynamics timesteps.}
01624   \textcolor{comment}{! local variables}
01625   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{pointer} :: G => null()    \textcolor{comment}{! A pointer to the metric grid use for the run}
01626   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{pointer} :: G\_in => null() \textcolor{comment}{! Pointer to the input grid}
01627   \textcolor{keywordtype}{type}(hor\_index\_type),   \textcolor{keywordtype}{pointer} :: HI => null()   \textcolor{comment}{! A hor\_index\_type for array extents}
01628   \textcolor{keywordtype}{type}(hor\_index\_type),   \textcolor{keywordtype}{target}  :: HI\_in          \textcolor{comment}{! HI on the input grid}
01629   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{pointer} :: GV => null()
01630   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{pointer} :: dG => null()
01631   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{pointer} :: dG\_in => null()
01632   \textcolor{keywordtype}{type}(diag\_ctrl),        \textcolor{keywordtype}{pointer} :: diag => null()
01633   \textcolor{keywordtype}{type}(unit\_scale\_type),  \textcolor{keywordtype}{pointer} :: US => null()
01634   \textcolor{keywordtype}{character(len=4)}, \textcolor{keywordtype}{parameter} :: vers\_num = \textcolor{stringliteral}{'v2.0'}
01635   \textcolor{keywordtype}{integer} :: turns   \textcolor{comment}{! Number of grid quarter-turns}
01636 
01637   \textcolor{comment}{! Initial state on the input index map}
01638   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: u\_in, v\_in, h\_in
01639   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{target} :: T\_in, S\_in
01640   \textcolor{keywordtype}{type}(ocean\_obc\_type), \textcolor{keywordtype}{pointer} :: OBC\_in => null()
01641   \textcolor{keywordtype}{type}(sponge\_cs), \textcolor{keywordtype}{pointer} :: sponge\_in\_CSp => null()
01642   \textcolor{keywordtype}{type}(ale\_sponge\_cs), \textcolor{keywordtype}{pointer} :: ALE\_sponge\_in\_CSp => null()
01643 
01644   \textcolor{comment}{! This include declares and sets the variable "version".}
01645 \textcolor{preprocessor}{# include "version\_variable.h"}
01646 \textcolor{preprocessor}{}
01647   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, isd, ied, jsd, jed, nz
01648   \textcolor{keywordtype}{integer} :: IsdB, IedB, JsdB, JedB
01649   \textcolor{keywordtype}{real}    :: dtbt        \textcolor{comment}{! The barotropic timestep [s]}
01650 
01651   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)}   :: eta \textcolor{comment}{! free surface height or column mass [H ~> m or kg m-2]}
01652   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)}   :: area\_shelf\_h \textcolor{comment}{! area occupied by ice shelf [L2 ~> m2]}
01653   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{target}  :: frac\_shelf\_h \textcolor{comment}{! fraction of total area occupied by ice shelf
       [nondim]}
01654   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer} :: shelf\_area => null()
01655   \textcolor{keywordtype}{type}(mom\_restart\_cs),  \textcolor{keywordtype}{pointer}      :: restart\_CSp\_tmp => null()
01656   \textcolor{keywordtype}{type}(group\_pass\_type) :: tmp\_pass\_uv\_T\_S\_h, pass\_uv\_T\_S\_h
01657 
01658   \textcolor{keywordtype}{real}    :: default\_val       \textcolor{comment}{! default value for a parameter}
01659   \textcolor{keywordtype}{logical} :: write\_geom\_files  \textcolor{comment}{! If true, write out the grid geometry files.}
01660   \textcolor{keywordtype}{logical} :: ensemble\_ocean    \textcolor{comment}{! If true, perform an ensemble gather at the end of step\_MOM}
01661   \textcolor{keywordtype}{logical} :: new\_sim
01662   \textcolor{keywordtype}{logical} :: use\_geothermal    \textcolor{comment}{! If true, apply geothermal heating.}
01663   \textcolor{keywordtype}{logical} :: use\_EOS           \textcolor{comment}{! If true, density calculated from T & S using an equation of state.}
01664   \textcolor{keywordtype}{logical} :: symmetric         \textcolor{comment}{! If true, use symmetric memory allocation.}
01665   \textcolor{keywordtype}{logical} :: save\_IC           \textcolor{comment}{! If true, save the initial conditions.}
01666   \textcolor{keywordtype}{logical} :: do\_unit\_tests     \textcolor{comment}{! If true, call unit tests.}
01667   \textcolor{keywordtype}{logical} :: test\_grid\_copy = .false.
01668 
01669   \textcolor{keywordtype}{logical} :: bulkmixedlayer    \textcolor{comment}{! If true, a refined bulk mixed layer scheme is used}
01670                                \textcolor{comment}{! with nkml sublayers and nkbl buffer layer.}
01671   \textcolor{keywordtype}{logical} :: use\_temperature   \textcolor{comment}{! If true, temp and saln used as state variables.}
01672   \textcolor{keywordtype}{logical} :: use\_frazil        \textcolor{comment}{! If true, liquid seawater freezes if temp below freezing,}
01673                                \textcolor{comment}{! with accumulated heat deficit returned to surface ocean.}
01674   \textcolor{keywordtype}{logical} :: bound\_salinity    \textcolor{comment}{! If true, salt is added to keep salinity above}
01675                                \textcolor{comment}{! a minimum value, and the deficit is reported.}
01676   \textcolor{keywordtype}{logical} :: default\_2018\_answers \textcolor{comment}{! The default setting for the various 2018\_ANSWERS flags.}
01677   \textcolor{keywordtype}{logical} :: use\_conT\_absS     \textcolor{comment}{! If true, the prognostics T & S are conservative temperature}
01678                                \textcolor{comment}{! and absolute salinity. Care should be taken to convert them}
01679                                \textcolor{comment}{! to potential temperature and practical salinity before}
01680                                \textcolor{comment}{! exchanging them with the coupler and/or reporting T&S diagnostics.}
01681   \textcolor{keywordtype}{logical} :: advect\_TS         \textcolor{comment}{! If false, then no horizontal advection of temperature}
01682                                \textcolor{comment}{! and salnity is performed}
01683   \textcolor{keywordtype}{logical} :: use\_ice\_shelf     \textcolor{comment}{! Needed for ALE}
01684   \textcolor{keywordtype}{logical} :: global\_indexing   \textcolor{comment}{! If true use global horizontal index values instead}
01685                                \textcolor{comment}{! of having the data domain on each processor start at 1.}
01686   \textcolor{keywordtype}{logical} :: bathy\_at\_vel      \textcolor{comment}{! If true, also define bathymetric fields at the}
01687                                \textcolor{comment}{! the velocity points.}
01688   \textcolor{keywordtype}{logical} :: calc\_dtbt         \textcolor{comment}{! Indicates whether the dynamically adjusted barotropic}
01689                                \textcolor{comment}{! time step needs to be updated before it is used.}
01690   \textcolor{keywordtype}{logical} :: debug\_truncations \textcolor{comment}{! If true, turn on diagnostics useful for debugging truncations.}
01691   \textcolor{keywordtype}{integer} :: first\_direction   \textcolor{comment}{! An integer that indicates which direction is to be}
01692                                \textcolor{comment}{! updated first in directionally split parts of the}
01693                                \textcolor{comment}{! calculation.  This can be altered during the course}
01694                                \textcolor{comment}{! of the run via calls to set\_first\_direction.}
01695   \textcolor{keywordtype}{integer} :: nkml, nkbl, verbosity, write\_geom
01696   \textcolor{keywordtype}{integer} :: dynamics\_stencil  \textcolor{comment}{! The computational stencil for the calculations}
01697                                \textcolor{comment}{! in the dynamic core.}
01698   \textcolor{keywordtype}{real} :: conv2watt, conv2salt
01699   \textcolor{keywordtype}{real} :: RL2\_T2\_rescale, Z\_rescale, QRZ\_rescale \textcolor{comment}{! Unit conversion factors}
01700   \textcolor{keywordtype}{character(len=48)} :: flux\_units, S\_flux\_units
01701 
01702   \textcolor{keywordtype}{type}(vardesc) :: vd\_T, vd\_S  \textcolor{comment}{! Structures describing temperature and salinity variables.}
01703   \textcolor{keywordtype}{type}(time\_type)                 :: Start\_time
01704   \textcolor{keywordtype}{type}(ocean\_internal\_state)      :: MOM\_internal\_state
01705   \textcolor{keywordtype}{character(len=200)} :: area\_varname, ice\_shelf\_file, inputdir, filename
01706 
01707   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
01708     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"initialize\_MOM called with an associated "}// &
01709                             \textcolor{stringliteral}{"control structure."})
01710     \textcolor{keywordflow}{return}
01711 \textcolor{keywordflow}{  endif}
01712   \textcolor{keyword}{allocate}(cs)
01713 
01714   cs%Time => time
01715 
01716   \hyperlink{namespacemom_a7cf03c18244d0630616e925bab1841a2}{id\_clock\_init} = cpu\_clock\_id(\textcolor{stringliteral}{'Ocean Initialization'}, grain=clock\_subcomponent)
01717   \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a7cf03c18244d0630616e925bab1841a2}{id\_clock\_init})
01718 
01719   start\_time = time ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(time\_in)) start\_time = time\_in
01720 
01721   \textcolor{comment}{! Read paths and filenames from namelist and store in "dirs".}
01722   \textcolor{comment}{! Also open the parsed input parameter file(s) and setup param\_file.}
01723   \textcolor{keyword}{call }get\_mom\_input(param\_file, dirs, default\_input\_filename=input\_restart\_file)
01724 
01725   verbosity = 2 ; \textcolor{keyword}{call }read\_param(param\_file, \textcolor{stringliteral}{"VERBOSITY"}, verbosity)
01726   \textcolor{keyword}{call }mom\_set\_verbosity(verbosity)
01727   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"initialize\_MOM(), MOM.F90"})
01728 
01729   \textcolor{keyword}{call }find\_obsolete\_params(param\_file)
01730 
01731   \textcolor{comment}{! Determining the internal unit scaling factors for this run.}
01732   \textcolor{keyword}{call }unit\_scaling\_init(param\_file, cs%US)
01733   us => cs%US
01734 
01735   \textcolor{comment}{! Read relevant parameters and write them to the model log.}
01736   \textcolor{keyword}{call }log\_version(param\_file, \textcolor{stringliteral}{"MOM"}, version, \textcolor{stringliteral}{""}, log\_to\_all=.true., layout=.true., debugging=.true.)
01737   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"VERBOSITY"}, verbosity,  &
01738                  \textcolor{stringliteral}{"Integer controlling level of messaging\(\backslash\)n"} // &
01739                  \textcolor{stringliteral}{"\(\backslash\)t0 = Only FATAL messages\(\backslash\)n"} // &
01740                  \textcolor{stringliteral}{"\(\backslash\)t2 = Only FATAL, WARNING, NOTE [default]\(\backslash\)n"} // &
01741                  \textcolor{stringliteral}{"\(\backslash\)t9 = All)"}, default=2, debuggingparam=.true.)
01742   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DO\_UNIT\_TESTS"}, do\_unit\_tests, &
01743                  \textcolor{stringliteral}{"If True, exercises unit tests at model start up."}, &
01744                  default=.false., debuggingparam=.true.)
01745   \textcolor{keywordflow}{if} (do\_unit\_tests) \textcolor{keywordflow}{then}
01746     \hyperlink{namespacemom_a785851181d2a3db5a938322d2ff9498a}{id\_clock\_unit\_tests} = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean unit tests)'}, grain=clock\_module)
01747     \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a785851181d2a3db5a938322d2ff9498a}{id\_clock\_unit\_tests})
01748     \textcolor{keyword}{call }unit\_tests(verbosity)
01749     \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a785851181d2a3db5a938322d2ff9498a}{id\_clock\_unit\_tests})
01750 \textcolor{keywordflow}{  endif}
01751 
01752   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"SPLIT"}, cs%split, &
01753                  \textcolor{stringliteral}{"Use the split time stepping if true."}, default=.true.)
01754   \textcolor{keywordflow}{if} (cs%split) \textcolor{keywordflow}{then}
01755     cs%use\_RK2 = .false.
01756   \textcolor{keywordflow}{else}
01757     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"USE\_RK2"}, cs%use\_RK2, &
01758                  \textcolor{stringliteral}{"If true, use RK2 instead of RK3 in the unsplit time stepping."}, &
01759                  default=.false.)
01760 \textcolor{keywordflow}{  endif}
01761 
01762   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"CALC\_RHO\_FOR\_SEA\_LEVEL"}, cs%calc\_rho\_for\_sea\_lev, &
01763                  \textcolor{stringliteral}{"If true, the in-situ density is used to calculate the "}//&
01764                  \textcolor{stringliteral}{"effective sea level that is returned to the coupler. If false, "}//&
01765                  \textcolor{stringliteral}{"the Boussinesq parameter RHO\_0 is used."}, default=.false.)
01766   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"ENABLE\_THERMODYNAMICS"}, use\_temperature, &
01767                  \textcolor{stringliteral}{"If true, Temperature and salinity are used as state "}//&
01768                  \textcolor{stringliteral}{"variables."}, default=.true.)
01769   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"USE\_EOS"}, use\_eos, &
01770                  \textcolor{stringliteral}{"If true,  density is calculated from temperature and "}//&
01771                  \textcolor{stringliteral}{"salinity with an equation of state.  If USE\_EOS is "}//&
01772                  \textcolor{stringliteral}{"true, ENABLE\_THERMODYNAMICS must be true as well."}, &
01773                  default=use\_temperature)
01774   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DIABATIC\_FIRST"}, cs%diabatic\_first, &
01775                  \textcolor{stringliteral}{"If true, apply diabatic and thermodynamic processes, "}//&
01776                  \textcolor{stringliteral}{"including buoyancy forcing and mass gain or loss, "}//&
01777                  \textcolor{stringliteral}{"before stepping the dynamics forward."}, default=.false.)
01778   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"USE\_CONTEMP\_ABSSAL"}, use\_cont\_abss, &
01779                  \textcolor{stringliteral}{"If true, the prognostics T&S are the conservative temperature "}//&
01780                  \textcolor{stringliteral}{"and absolute salinity. Care should be taken to convert them "}//&
01781                  \textcolor{stringliteral}{"to potential temperature and practical salinity before "}//&
01782                  \textcolor{stringliteral}{"exchanging them with the coupler and/or reporting T&S diagnostics."}, &
01783                  default=.false.)
01784   cs%tv%T\_is\_conT = use\_cont\_abss ; cs%tv%S\_is\_absS = use\_cont\_abss
01785   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"ADIABATIC"}, cs%adiabatic, &
01786                  \textcolor{stringliteral}{"There are no diapycnal mass fluxes if ADIABATIC is "}//&
01787                  \textcolor{stringliteral}{"true. This assumes that KD = KDML = 0.0 and that "}//&
01788                  \textcolor{stringliteral}{"there is no buoyancy forcing, but makes the model "}//&
01789                  \textcolor{stringliteral}{"faster by eliminating subroutine calls."}, default=.false.)
01790   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DO\_DYNAMICS"}, cs%do\_dynamics, &
01791                  \textcolor{stringliteral}{"If False, skips the dynamics calls that update u & v, as well as "}//&
01792                  \textcolor{stringliteral}{"the gravity wave adjustment to h. This may be a fragile feature, "}//&
01793                  \textcolor{stringliteral}{"but can be useful during development"}, default=.true.)
01794   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"ADVECT\_TS"}, advect\_ts, &
01795                  \textcolor{stringliteral}{"If True, advect temperature and salinity horizontally "}//&
01796                  \textcolor{stringliteral}{"If False, T/S are registered for advection. "}//&
01797                  \textcolor{stringliteral}{"This is intended only to be used in offline tracer mode "}//&
01798                  \textcolor{stringliteral}{"and is by default false in that case."}, &
01799                  do\_not\_log = .true., default=.true. )
01800   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(offline\_tracer\_mode)) \textcolor{keywordflow}{then} \textcolor{comment}{! Only read this parameter in enabled modes}
01801     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"OFFLINE\_TRACER\_MODE"}, cs%offline\_tracer\_mode, &
01802                  \textcolor{stringliteral}{"If true, barotropic and baroclinic dynamics, thermodynamics "}//&
01803                  \textcolor{stringliteral}{"are all bypassed with all the fields necessary to integrate "}//&
01804                  \textcolor{stringliteral}{"the tracer advection and diffusion equation are read in from "}//&
01805                  \textcolor{stringliteral}{"files stored from a previous integration of the prognostic model. "}//&
01806                  \textcolor{stringliteral}{"NOTE: This option only used in the ocean\_solo\_driver."}, default=.false.)
01807     \textcolor{keywordflow}{if} (cs%offline\_tracer\_mode) \textcolor{keywordflow}{then}
01808       \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"ADVECT\_TS"}, advect\_ts, &
01809                    \textcolor{stringliteral}{"If True, advect temperature and salinity horizontally "}//&
01810                    \textcolor{stringliteral}{"If False, T/S are registered for advection. "}//&
01811                    \textcolor{stringliteral}{"This is intended only to be used in offline tracer mode."}//&
01812                    \textcolor{stringliteral}{"and is by default false in that case"}, &
01813                    default=.false. )
01814 \textcolor{keywordflow}{    endif}
01815 \textcolor{keywordflow}{  endif}
01816   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"USE\_REGRIDDING"}, cs%use\_ALE\_algorithm, &
01817                  \textcolor{stringliteral}{"If True, use the ALE algorithm (regridding/remapping). "}//&
01818                  \textcolor{stringliteral}{"If False, use the layered isopycnal algorithm."}, default=.false. )
01819   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"BULKMIXEDLAYER"}, bulkmixedlayer, &
01820                  \textcolor{stringliteral}{"If true, use a Kraus-Turner-like bulk mixed layer "}//&
01821                  \textcolor{stringliteral}{"with transitional buffer layers.  Layers 1 through "}//&
01822                  \textcolor{stringliteral}{"NKML+NKBL have variable densities. There must be at "}//&
01823                  \textcolor{stringliteral}{"least NKML+NKBL+1 layers if BULKMIXEDLAYER is true. "}//&
01824                  \textcolor{stringliteral}{"BULKMIXEDLAYER can not be used with USE\_REGRIDDING. "}//&
01825                  \textcolor{stringliteral}{"The default is influenced by ENABLE\_THERMODYNAMICS."}, &
01826                  default=use\_temperature .and. .not.cs%use\_ALE\_algorithm)
01827   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"THICKNESSDIFFUSE"}, cs%thickness\_diffuse, &
01828                  \textcolor{stringliteral}{"If true, interface heights are diffused with a "}//&
01829                  \textcolor{stringliteral}{"coefficient of KHTH."}, default=.false.)
01830   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"},  \textcolor{stringliteral}{"THICKNESSDIFFUSE\_FIRST"}, &
01831                                       cs%thickness\_diffuse\_first, &
01832                  \textcolor{stringliteral}{"If true, do thickness diffusion before dynamics. "}//&
01833                  \textcolor{stringliteral}{"This is only used if THICKNESSDIFFUSE is true."}, &
01834                  default=.false.)
01835   \textcolor{keywordflow}{if} (.not.cs%thickness\_diffuse) cs%thickness\_diffuse\_first = .false.
01836   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"BATHYMETRY\_AT\_VEL"}, bathy\_at\_vel, &
01837                  \textcolor{stringliteral}{"If true, there are separate values for the basin depths "}//&
01838                  \textcolor{stringliteral}{"at velocity points.  Otherwise the effects of topography "}//&
01839                  \textcolor{stringliteral}{"are entirely determined from thickness points."}, &
01840                  default=.false.)
01841   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"USE\_WAVES"}, cs%UseWaves, default=.false., &
01842                  do\_not\_log=.true.)
01843 
01844   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DEBUG"}, cs%debug, &
01845                  \textcolor{stringliteral}{"If true, write out verbose debugging data."}, &
01846                  default=.false., debuggingparam=.true.)
01847   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DEBUG\_TRUNCATIONS"}, debug\_truncations, &
01848                  \textcolor{stringliteral}{"If true, calculate all diagnostics that are useful for "}//&
01849                  \textcolor{stringliteral}{"debugging truncations."}, default=.false., debuggingparam=.true.)
01850 
01851   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DT"}, cs%dt, &
01852                  \textcolor{stringliteral}{"The (baroclinic) dynamics time step.  The time-step that "}//&
01853                  \textcolor{stringliteral}{"is actually used will be an integer fraction of the "}//&
01854                  \textcolor{stringliteral}{"forcing time-step (DT\_FORCING in ocean-only mode or the "}//&
01855                  \textcolor{stringliteral}{"coupling timestep in coupled mode.)"}, units=\textcolor{stringliteral}{"s"}, scale=us%s\_to\_T, &
01856                  fail\_if\_missing=.true.)
01857   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DT\_THERM"}, cs%dt\_therm, &
01858                  \textcolor{stringliteral}{"The thermodynamic and tracer advection time step. "}//&
01859                  \textcolor{stringliteral}{"Ideally DT\_THERM should be an integer multiple of DT "}//&
01860                  \textcolor{stringliteral}{"and less than the forcing or coupling time-step, unless "}//&
01861                  \textcolor{stringliteral}{"THERMO\_SPANS\_COUPLING is true, in which case DT\_THERM "}//&
01862                  \textcolor{stringliteral}{"can be an integer multiple of the coupling timestep.  By "}//&
01863                  \textcolor{stringliteral}{"default DT\_THERM is set to DT."}, &
01864                  units=\textcolor{stringliteral}{"s"}, scale=us%s\_to\_T, default=us%T\_to\_s*cs%dt)
01865   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"THERMO\_SPANS\_COUPLING"}, cs%thermo\_spans\_coupling, &
01866                  \textcolor{stringliteral}{"If true, the MOM will take thermodynamic and tracer "}//&
01867                  \textcolor{stringliteral}{"timesteps that can be longer than the coupling timestep. "}//&
01868                  \textcolor{stringliteral}{"The actual thermodynamic timestep that is used in this "}//&
01869                  \textcolor{stringliteral}{"case is the largest integer multiple of the coupling "}//&
01870                  \textcolor{stringliteral}{"timestep that is less than or equal to DT\_THERM."}, default=.false.)
01871 
01872   \textcolor{keywordflow}{if} (bulkmixedlayer) \textcolor{keywordflow}{then}
01873     cs%Hmix = -1.0 ; cs%Hmix\_UV = -1.0
01874   \textcolor{keywordflow}{else}
01875     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"HMIX\_SFC\_PROP"}, cs%Hmix, &
01876                  \textcolor{stringliteral}{"If BULKMIXEDLAYER is false, HMIX\_SFC\_PROP is the depth "}//&
01877                  \textcolor{stringliteral}{"over which to average to find surface properties like "}//&
01878                  \textcolor{stringliteral}{"SST and SSS or density (but not surface velocities)."}, &
01879                  units=\textcolor{stringliteral}{"m"}, default=1.0, scale=us%m\_to\_Z)
01880     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"HMIX\_UV\_SFC\_PROP"}, cs%Hmix\_UV, &
01881                  \textcolor{stringliteral}{"If BULKMIXEDLAYER is false, HMIX\_UV\_SFC\_PROP is the depth "}//&
01882                  \textcolor{stringliteral}{"over which to average to find surface flow properties, "}//&
01883                  \textcolor{stringliteral}{"SSU, SSV. A non-positive value indicates no averaging."}, &
01884                  units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us%m\_to\_Z)
01885 \textcolor{keywordflow}{  endif}
01886   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"HFREEZE"}, cs%HFrz, &
01887                  \textcolor{stringliteral}{"If HFREEZE > 0, melt potential will be computed. The actual depth "}//&
01888                  \textcolor{stringliteral}{"over which melt potential is computed will be min(HFREEZE, OBLD), "}//&
01889                  \textcolor{stringliteral}{"where OBLD is the boundary layer depth. If HFREEZE <= 0 (default), "}//&
01890                  \textcolor{stringliteral}{"melt potential will not be computed."}, units=\textcolor{stringliteral}{"m"}, default=-1.0, scale=us%m\_to\_Z)
01891   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"INTERPOLATE\_P\_SURF"}, cs%interp\_p\_surf, &
01892                  \textcolor{stringliteral}{"If true, linearly interpolate the surface pressure "}//&
01893                  \textcolor{stringliteral}{"over the coupling time step, using the specified value "}//&
01894                  \textcolor{stringliteral}{"at the end of the step."}, default=.false.)
01895 
01896   \textcolor{keywordflow}{if} (cs%split) \textcolor{keywordflow}{then}
01897     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DTBT"}, dtbt, default=-0.98)
01898     default\_val = us%T\_to\_s*cs%dt\_therm ; \textcolor{keywordflow}{if} (dtbt > 0.0) default\_val = -1.0
01899     cs%dtbt\_reset\_period = -1.0
01900     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DTBT\_RESET\_PERIOD"}, cs%dtbt\_reset\_period, &
01901                  \textcolor{stringliteral}{"The period between recalculations of DTBT (if DTBT <= 0). "}//&
01902                  \textcolor{stringliteral}{"If DTBT\_RESET\_PERIOD is negative, DTBT is set based "}//&
01903                  \textcolor{stringliteral}{"only on information available at initialization.  If 0, "}//&
01904                  \textcolor{stringliteral}{"DTBT will be set every dynamics time step. The default "}//&
01905                  \textcolor{stringliteral}{"is set by DT\_THERM.  This is only used if SPLIT is true."}, &
01906                  units=\textcolor{stringliteral}{"s"}, default=default\_val, do\_not\_read=(dtbt > 0.0))
01907 \textcolor{keywordflow}{  endif}
01908 
01909   \textcolor{comment}{! This is here in case these values are used inappropriately.}
01910   use\_frazil = .false. ; bound\_salinity = .false.
01911   cs%tv%P\_Ref = 2.0e7*us%kg\_m3\_to\_R*us%m\_s\_to\_L\_T**2
01912   \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
01913     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"FRAZIL"}, use\_frazil, &
01914                  \textcolor{stringliteral}{"If true, water freezes if it gets too cold, and the "}//&
01915                  \textcolor{stringliteral}{"accumulated heat deficit is returned in the "}//&
01916                  \textcolor{stringliteral}{"surface state.  FRAZIL is only used if "}//&
01917                  \textcolor{stringliteral}{"ENABLE\_THERMODYNAMICS is true."}, default=.false.)
01918     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DO\_GEOTHERMAL"}, use\_geothermal, &
01919                  \textcolor{stringliteral}{"If true, apply geothermal heating."}, default=.false.)
01920     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"BOUND\_SALINITY"}, bound\_salinity, &
01921                  \textcolor{stringliteral}{"If true, limit salinity to being positive. (The sea-ice "}//&
01922                  \textcolor{stringliteral}{"model may ask for more salt than is available and "}//&
01923                  \textcolor{stringliteral}{"drive the salinity negative otherwise.)"}, default=.false.)
01924     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"MIN\_SALINITY"}, cs%tv%min\_salinity, &
01925                  \textcolor{stringliteral}{"The minimum value of salinity when BOUND\_SALINITY=True."}, &
01926                  units=\textcolor{stringliteral}{"PPT"}, default=0.0, do\_not\_log=.not.bound\_salinity)
01927     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"C\_P"}, cs%tv%C\_p, &
01928                  \textcolor{stringliteral}{"The heat capacity of sea water, approximated as a "}//&
01929                  \textcolor{stringliteral}{"constant. This is only used if ENABLE\_THERMODYNAMICS is "}//&
01930                  \textcolor{stringliteral}{"true. The default value is from the TEOS-10 definition "}//&
01931                  \textcolor{stringliteral}{"of conservative temperature."}, units=\textcolor{stringliteral}{"J kg-1 K-1"}, &
01932                  default=3991.86795711963, scale=us%J\_kg\_to\_Q)
01933     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"USE\_PSURF\_IN\_EOS"}, cs%use\_p\_surf\_in\_EOS, &
01934                  \textcolor{stringliteral}{"If true, always include the surface pressure contributions "}//&
01935                  \textcolor{stringliteral}{"in equation of state calculations."}, default=.true.)
01936 \textcolor{keywordflow}{  endif}
01937   \textcolor{keywordflow}{if} (use\_eos) \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"P\_REF"}, cs%tv%P\_Ref, &
01938                  \textcolor{stringliteral}{"The pressure that is used for calculating the coordinate "}//&
01939                  \textcolor{stringliteral}{"density.  (1 Pa = 1e4 dbar, so 2e7 is commonly used.) "}//&
01940                  \textcolor{stringliteral}{"This is only used if USE\_EOS and ENABLE\_THERMODYNAMICS are true."}, &
01941                  units=\textcolor{stringliteral}{"Pa"}, default=2.0e7, scale=us%kg\_m3\_to\_R*us%m\_s\_to\_L\_T**2)
01942 
01943   \textcolor{keywordflow}{if} (bulkmixedlayer) \textcolor{keywordflow}{then}
01944     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"NKML"}, nkml, &
01945                  \textcolor{stringliteral}{"The number of sublayers within the mixed layer if "}//&
01946                  \textcolor{stringliteral}{"BULKMIXEDLAYER is true."}, units=\textcolor{stringliteral}{"nondim"}, default=2)
01947     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"NKBL"}, nkbl, &
01948                  \textcolor{stringliteral}{"The number of layers that are used as variable density "}//&
01949                  \textcolor{stringliteral}{"buffer layers if BULKMIXEDLAYER is true."}, units=\textcolor{stringliteral}{"nondim"}, &
01950                  default=2)
01951 \textcolor{keywordflow}{  endif}
01952 
01953   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"GLOBAL\_INDEXING"}, global\_indexing, &
01954                  \textcolor{stringliteral}{"If true, use a global lateral indexing convention, so "}//&
01955                  \textcolor{stringliteral}{"that corresponding points on different processors have "}//&
01956                  \textcolor{stringliteral}{"the same index. This does not work with static memory."}, &
01957                  default=.false., layoutparam=.true.)
01958 \textcolor{preprocessor}{#ifdef STATIC\_MEMORY\_}
01959 \textcolor{preprocessor}{}  \textcolor{keywordflow}{if} (global\_indexing) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"initialize\_MOM: "}//&
01960        \textcolor{stringliteral}{"GLOBAL\_INDEXING can not be true with STATIC\_MEMORY."})
01961 \textcolor{preprocessor}{#endif}
01962 \textcolor{preprocessor}{}  \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"FIRST\_DIRECTION"}, first\_direction, &
01963                  \textcolor{stringliteral}{"An integer that indicates which direction goes first "}//&
01964                  \textcolor{stringliteral}{"in parts of the code that use directionally split "}//&
01965                  \textcolor{stringliteral}{"updates, with even numbers (or 0) used for x- first "}//&
01966                  \textcolor{stringliteral}{"and odd numbers used for y-first."}, default=0)
01967 
01968   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"CHECK\_BAD\_SURFACE\_VALS"}, cs%check\_bad\_sfc\_vals, &
01969                  \textcolor{stringliteral}{"If true, check the surface state for ridiculous values."}, &
01970                  default=.false.)
01971   \textcolor{keywordflow}{if} (cs%check\_bad\_sfc\_vals) \textcolor{keywordflow}{then}
01972     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"BAD\_VAL\_SSH\_MAX"}, cs%bad\_val\_ssh\_max, &
01973                  \textcolor{stringliteral}{"The value of SSH above which a bad value message is "}//&
01974                  \textcolor{stringliteral}{"triggered, if CHECK\_BAD\_SURFACE\_VALS is true."}, &
01975                  units=\textcolor{stringliteral}{"m"}, default=20.0, scale=us%m\_to\_Z)
01976     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"BAD\_VAL\_SSS\_MAX"}, cs%bad\_val\_sss\_max, &
01977                  \textcolor{stringliteral}{"The value of SSS above which a bad value message is "}//&
01978                  \textcolor{stringliteral}{"triggered, if CHECK\_BAD\_SURFACE\_VALS is true."}, units=\textcolor{stringliteral}{"PPT"}, &
01979                  default=45.0)
01980     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"BAD\_VAL\_SST\_MAX"}, cs%bad\_val\_sst\_max, &
01981                  \textcolor{stringliteral}{"The value of SST above which a bad value message is "}//&
01982                  \textcolor{stringliteral}{"triggered, if CHECK\_BAD\_SURFACE\_VALS is true."}, &
01983                  units=\textcolor{stringliteral}{"deg C"}, default=45.0)
01984     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"BAD\_VAL\_SST\_MIN"}, cs%bad\_val\_sst\_min, &
01985                  \textcolor{stringliteral}{"The value of SST below which a bad value message is "}//&
01986                  \textcolor{stringliteral}{"triggered, if CHECK\_BAD\_SURFACE\_VALS is true."}, &
01987                  units=\textcolor{stringliteral}{"deg C"}, default=-2.1)
01988     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"BAD\_VAL\_COLUMN\_THICKNESS"}, cs%bad\_val\_col\_thick, &
01989                  \textcolor{stringliteral}{"The value of column thickness below which a bad value message is "}//&
01990                  \textcolor{stringliteral}{"triggered, if CHECK\_BAD\_SURFACE\_VALS is true."}, &
01991                  units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us%m\_to\_Z)
01992 \textcolor{keywordflow}{  endif}
01993   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"DEFAULT\_2018\_ANSWERS"}, default\_2018\_answers, &
01994                  \textcolor{stringliteral}{"This sets the default value for the various \_2018\_ANSWERS parameters."}, &
01995                  default=.false.)
01996   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"SURFACE\_2018\_ANSWERS"}, cs%answers\_2018, &
01997                  \textcolor{stringliteral}{"If true, use expressions for the surface properties that recover the answers "}//&
01998                  \textcolor{stringliteral}{"from the end of 2018. Otherwise, use more appropriate expressions that differ "}//&
01999                  \textcolor{stringliteral}{"at roundoff for non-Boussinesq cases."}, default=default\_2018\_answers)
02000 
02001   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"SAVE\_INITIAL\_CONDS"}, save\_ic, &
02002                  \textcolor{stringliteral}{"If true, write the initial conditions to a file given "}//&
02003                  \textcolor{stringliteral}{"by IC\_OUTPUT\_FILE."}, default=.false.)
02004   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"IC\_OUTPUT\_FILE"}, cs%IC\_file, &
02005                  \textcolor{stringliteral}{"The file into which to write the initial conditions."}, &
02006                  default=\textcolor{stringliteral}{"MOM\_IC"})
02007   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"WRITE\_GEOM"}, write\_geom, &
02008                  \textcolor{stringliteral}{"If =0, never write the geometry and vertical grid files. "}//&
02009                  \textcolor{stringliteral}{"If =1, write the geometry and vertical grid files only for "}//&
02010                  \textcolor{stringliteral}{"a new simulation. If =2, always write the geometry and "}//&
02011                  \textcolor{stringliteral}{"vertical grid files. Other values are invalid."}, default=1)
02012   \textcolor{keywordflow}{if} (write\_geom<0 .or. write\_geom>2) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"MOM: "}//&
02013          \textcolor{stringliteral}{"WRITE\_GEOM must be equal to 0, 1 or 2."})
02014   write\_geom\_files = ((write\_geom==2) .or. ((write\_geom==1) .and. &
02015      ((dirs%input\_filename(1:1)==\textcolor{stringliteral}{'n'}) .and. (len\_trim(dirs%input\_filename)==1))))
02016 \textcolor{comment}{! If the restart file type had been initialized, this could become:}
02017 \textcolor{comment}{!  write\_geom\_files = ((write\_geom==2) .or. &}
02018 \textcolor{comment}{!                      ((write\_geom==1) .and. is\_new\_run(restart\_CSp)))}
02019 
02020   \textcolor{comment}{! Check for inconsistent parameter settings.}
02021   \textcolor{keywordflow}{if} (cs%use\_ALE\_algorithm .and. bulkmixedlayer) \textcolor{keyword}{call }mom\_error(fatal, &
02022     \textcolor{stringliteral}{"MOM: BULKMIXEDLAYER can not currently be used with the ALE algorithm."})
02023   \textcolor{keywordflow}{if} (cs%use\_ALE\_algorithm .and. .not.use\_temperature) \textcolor{keyword}{call }mom\_error(fatal, &
02024      \textcolor{stringliteral}{"MOM: At this time, USE\_EOS should be True when using the ALE algorithm."})
02025   \textcolor{keywordflow}{if} (cs%adiabatic .and. use\_temperature) \textcolor{keyword}{call }mom\_error(warning, &
02026     \textcolor{stringliteral}{"MOM: ADIABATIC and ENABLE\_THERMODYNAMICS both defined is usually unwise."})
02027   \textcolor{keywordflow}{if} (use\_eos .and. .not.use\_temperature) \textcolor{keyword}{call }mom\_error(fatal, &
02028     \textcolor{stringliteral}{"MOM: ENABLE\_THERMODYNAMICS must be defined to use USE\_EOS."})
02029   \textcolor{keywordflow}{if} (cs%adiabatic .and. bulkmixedlayer) \textcolor{keyword}{call }mom\_error(fatal, &
02030     \textcolor{stringliteral}{"MOM: ADIABATIC and BULKMIXEDLAYER can not both be defined."})
02031   \textcolor{keywordflow}{if} (bulkmixedlayer .and. .not.use\_eos) \textcolor{keyword}{call }mom\_error(fatal, &
02032       \textcolor{stringliteral}{"initialize\_MOM: A bulk mixed layer can only be used with T & S as "}//&
02033       \textcolor{stringliteral}{"state variables. Add USE\_EOS = True to MOM\_input."})
02034 
02035   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{'MOM'}, \textcolor{stringliteral}{"ICE\_SHELF"}, use\_ice\_shelf, default=.false., do\_not\_log=.true.)
02036   \textcolor{keywordflow}{if} (use\_ice\_shelf) \textcolor{keywordflow}{then}
02037      inputdir = \textcolor{stringliteral}{"."} ;  \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{'MOM'}, \textcolor{stringliteral}{"INPUTDIR"}, inputdir)
02038      inputdir = slasher(inputdir)
02039      \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{'MOM'}, \textcolor{stringliteral}{"ICE\_THICKNESS\_FILE"}, ice\_shelf\_file, &
02040                     \textcolor{stringliteral}{"The file from which the ice bathymetry and area are read."}, &
02041                     fail\_if\_missing=.true.)
02042      \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{'MOM'}, \textcolor{stringliteral}{"ICE\_AREA\_VARNAME"}, area\_varname, &
02043                     \textcolor{stringliteral}{"The name of the area variable in ICE\_THICKNESS\_FILE."}, &
02044                     fail\_if\_missing=.true.)
02045 \textcolor{keywordflow}{  endif}
02046 
02047 
02048   cs%ensemble\_ocean=.false.
02049   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"ENSEMBLE\_OCEAN"}, cs%ensemble\_ocean, &
02050                  \textcolor{stringliteral}{"If False, The model is being run in serial mode as a single realization. "}//&
02051                  \textcolor{stringliteral}{"If True, The current model realization is part of a larger ensemble "}//&
02052                  \textcolor{stringliteral}{"and at the end of step MOM, we will perform a gather of the ensemble "}//&
02053                  \textcolor{stringliteral}{"members for statistical evaluation and/or data assimilation."}, default=.false.)
02054 
02055   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"MOM parameters read (initialize\_MOM)"})
02056 
02057   \textcolor{comment}{! Grid rotation test}
02058   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"ROTATE\_INDEX"}, cs%rotate\_index, &
02059       \textcolor{stringliteral}{"Enable rotation of the horizontal indices."}, default=.false., &
02060       debuggingparam=.true.)
02061   \textcolor{keywordflow}{if} (cs%rotate\_index) \textcolor{keywordflow}{then}
02062     \textcolor{comment}{! TODO: Index rotation currently only works when index rotation does not}
02063     \textcolor{comment}{!   change the MPI rank of each domain.  Resolving this will require a}
02064     \textcolor{comment}{!   modification to FMS PE assignment.}
02065     \textcolor{comment}{!   For now, we only permit single-core runs.}
02066 
02067     \textcolor{keywordflow}{if} (num\_pes() /= 1) &
02068       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Index rotation is only supported on one PE."})
02069 
02070     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"INDEX\_TURNS"}, turns, &
02071         \textcolor{stringliteral}{"Number of counterclockwise quarter-turn index rotations."}, &
02072         default=1, debuggingparam=.true.)
02073 \textcolor{keywordflow}{  endif}
02074 
02075   \textcolor{comment}{! Set up the model domain and grids.}
02076 \textcolor{preprocessor}{#ifdef SYMMETRIC\_MEMORY\_}
02077 \textcolor{preprocessor}{}  symmetric = .true.
02078 \textcolor{preprocessor}{#else}
02079 \textcolor{preprocessor}{}  symmetric = .false.
02080 \textcolor{preprocessor}{#endif}
02081 \textcolor{preprocessor}{}  g\_in => cs%G\_in
02082 \textcolor{preprocessor}{#ifdef STATIC\_MEMORY\_}
02083 \textcolor{preprocessor}{}  \textcolor{keyword}{call }mom\_domains\_init(g\_in%domain, param\_file, symmetric=symmetric, &
02084             static\_memory=.true., nihalo=nihalo\_, njhalo=njhalo\_, &
02085             niglobal=niglobal\_, njglobal=njglobal\_, niproc=niproc\_, &
02086             njproc=njproc\_)
02087 \textcolor{preprocessor}{#else}
02088 \textcolor{preprocessor}{}  \textcolor{keyword}{call }mom\_domains\_init(g\_in%domain, param\_file, symmetric=symmetric, &
02089                         domain\_name=\textcolor{stringliteral}{"MOM\_in"})
02090 \textcolor{preprocessor}{#endif}
02091 \textcolor{preprocessor}{}
02092   \textcolor{comment}{! Copy input grid (G\_in) domain to active grid G}
02093   \textcolor{comment}{! Swap axes for quarter and 3-quarter turns}
02094   \textcolor{keywordflow}{if} (cs%rotate\_index) \textcolor{keywordflow}{then}
02095     \textcolor{keyword}{allocate}(cs%G)
02096     \textcolor{keyword}{call }clone\_mom\_domain(g\_in%Domain, cs%G%Domain, turns=turns)
02097     first\_direction = modulo(first\_direction + turns, 2)
02098   \textcolor{keywordflow}{else}
02099     cs%G => g\_in
02100 \textcolor{keywordflow}{  endif}
02101 
02102   \textcolor{comment}{! TODO: It is unlikey that test\_grid\_copy and rotate\_index would work at the}
02103   \textcolor{comment}{!   same time.  It may be possible to enable both but for now we prevent it.}
02104   \textcolor{keywordflow}{if} (test\_grid\_copy .and. cs%rotate\_index) &
02105     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Grid cannot be copied during index rotation."})
02106 
02107   \textcolor{keywordflow}{if} (test\_grid\_copy) \textcolor{keywordflow}{then} ; \textcolor{keyword}{allocate}(g)
02108   \textcolor{keywordflow}{else} ; g => cs%G ;\textcolor{keywordflow}{ endif}
02109 
02110   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"domains initialized (initialize\_MOM)"})
02111 
02112   \textcolor{keyword}{call }mom\_debugging\_init(param\_file)
02113   \textcolor{keyword}{call }diag\_mediator\_infrastructure\_init()
02114   \textcolor{keyword}{call }mom\_io\_init(param\_file)
02115 
02116   \textcolor{comment}{! Create HI and dG on the input index map.}
02117   \textcolor{keyword}{call }hor\_index\_init(g\_in%Domain, hi\_in, param\_file, &
02118                       local\_indexing=.not.global\_indexing)
02119   \textcolor{keyword}{call }create\_dyn\_horgrid(dg\_in, hi\_in, bathymetry\_at\_vel=bathy\_at\_vel)
02120   \textcolor{keyword}{call }clone\_mom\_domain(g\_in%Domain, dg\_in%Domain)
02121 
02122   \textcolor{comment}{! Allocate initialize time-invariant MOM variables.}
02123   \textcolor{keyword}{call }mom\_initialize\_fixed(dg\_in, us, obc\_in, param\_file, write\_geom\_files, &
02124                             dirs%output\_directory)
02125 
02126   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"returned from MOM\_initialize\_fixed() (initialize\_MOM)"})
02127 
02128   \textcolor{comment}{! Determine HI and dG for the model index map.}
02129   \textcolor{keywordflow}{if} (cs%rotate\_index) \textcolor{keywordflow}{then}
02130     \textcolor{keyword}{allocate}(hi)
02131     \textcolor{keyword}{call }rotate\_hor\_index(hi\_in, turns, hi)
02132     \textcolor{keyword}{call }create\_dyn\_horgrid(dg, hi, bathymetry\_at\_vel=bathy\_at\_vel)
02133     \textcolor{keyword}{call }clone\_mom\_domain(g%Domain, dg%Domain)
02134     \textcolor{keyword}{call }rotate\_dyngrid(dg\_in, dg, us, turns)
02135     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc\_in)) \textcolor{keywordflow}{then}
02136       \textcolor{comment}{! TODO: General OBC index rotations is not yet supported.}
02137       \textcolor{keywordflow}{if} (modulo(turns, 4) /= 1) &
02138         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"OBC index rotation of 180 and 270 degrees is "} &
02139           // \textcolor{stringliteral}{"not yet unsupported."})
02140       \textcolor{keyword}{allocate}(cs%OBC)
02141       \textcolor{keyword}{call }rotate\_obc\_config(obc\_in, dg\_in, cs%OBC, dg, turns)
02142 \textcolor{keywordflow}{    endif}
02143   \textcolor{keywordflow}{else}
02144     hi => hi\_in
02145     dg => dg\_in
02146     cs%OBC => obc\_in
02147 \textcolor{keywordflow}{  endif}
02148 
02149   \textcolor{keyword}{call }verticalgridinit( param\_file, cs%GV, us )
02150   gv => cs%GV
02151 
02152   \textcolor{comment}{! Allocate the auxiliary non-symmetric domain for debugging or I/O purposes.}
02153   \textcolor{keywordflow}{if} (cs%debug .or. dg%symmetric) &
02154     \textcolor{keyword}{call }clone\_mom\_domain(dg%Domain, dg%Domain\_aux, symmetric=.false.)
02155 
02156   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"grids initialized (initialize\_MOM)"})
02157 
02158   \textcolor{keyword}{call }\hyperlink{namespacemom_ab57e47834591c651339770f7e51efe57}{mom\_timing\_init}(cs)
02159 
02160   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%OBC)) \textcolor{keyword}{call }call\_obc\_register(param\_file, cs%update\_OBC\_CSp, cs%OBC)
02161 
02162   \textcolor{keyword}{call }tracer\_registry\_init(param\_file, cs%tracer\_Reg)
02163 
02164   \textcolor{comment}{! Allocate and initialize space for the primary time-varying MOM variables.}
02165   is   = dg%isc   ; ie   = dg%iec  ; js   = dg%jsc  ; je   = dg%jec ; nz = gv%ke
02166   isd  = dg%isd   ; ied  = dg%ied  ; jsd  = dg%jsd  ; jed  = dg%jed
02167   isdb = dg%IsdB  ; iedb = dg%IedB ; jsdb = dg%JsdB ; jedb = dg%JedB
02168   alloc\_(cs%u(isdb:iedb,jsd:jed,nz))   ; cs%u(:,:,:) = 0.0
02169   alloc\_(cs%v(isd:ied,jsdb:jedb,nz))   ; cs%v(:,:,:) = 0.0
02170   alloc\_(cs%h(isd:ied,jsd:jed,nz))     ; cs%h(:,:,:) = gv%Angstrom\_H
02171   alloc\_(cs%uh(isdb:iedb,jsd:jed,nz))  ; cs%uh(:,:,:) = 0.0
02172   alloc\_(cs%vh(isd:ied,jsdb:jedb,nz))  ; cs%vh(:,:,:) = 0.0
02173   \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
02174     alloc\_(cs%T(isd:ied,jsd:jed,nz))   ; cs%T(:,:,:) = 0.0
02175     alloc\_(cs%S(isd:ied,jsd:jed,nz))   ; cs%S(:,:,:) = 0.0
02176     cs%tv%T => cs%T ; cs%tv%S => cs%S
02177     \textcolor{keywordflow}{if} (cs%tv%T\_is\_conT) \textcolor{keywordflow}{then}
02178       vd\_t = var\_desc(name=\textcolor{stringliteral}{"contemp"}, units=\textcolor{stringliteral}{"Celsius"}, longname=\textcolor{stringliteral}{"Conservative Temperature"}, &
02179                       cmor\_field\_name=\textcolor{stringliteral}{"thetao"}, cmor\_longname=\textcolor{stringliteral}{"Sea Water Potential Temperature"}, &
02180                       conversion=us%Q\_to\_J\_kg*cs%tv%C\_p)
02181     \textcolor{keywordflow}{else}
02182       vd\_t = var\_desc(name=\textcolor{stringliteral}{"temp"}, units=\textcolor{stringliteral}{"degC"}, longname=\textcolor{stringliteral}{"Potential Temperature"}, &
02183                       cmor\_field\_name=\textcolor{stringliteral}{"thetao"}, cmor\_longname=\textcolor{stringliteral}{"Sea Water Potential Temperature"}, &
02184                       conversion=us%Q\_to\_J\_kg*cs%tv%C\_p)
02185 \textcolor{keywordflow}{    endif}
02186     \textcolor{keywordflow}{if} (cs%tv%S\_is\_absS) \textcolor{keywordflow}{then}
02187       vd\_s = var\_desc(name=\textcolor{stringliteral}{"abssalt"},units=\textcolor{stringliteral}{"g kg-1"},longname=\textcolor{stringliteral}{"Absolute Salinity"}, &
02188                       cmor\_field\_name=\textcolor{stringliteral}{"so"}, cmor\_longname=\textcolor{stringliteral}{"Sea Water Salinity"}, &
02189                       conversion=0.001)
02190     \textcolor{keywordflow}{else}
02191       vd\_s = var\_desc(name=\textcolor{stringliteral}{"salt"},units=\textcolor{stringliteral}{"psu"},longname=\textcolor{stringliteral}{"Salinity"}, &
02192                       cmor\_field\_name=\textcolor{stringliteral}{"so"}, cmor\_longname=\textcolor{stringliteral}{"Sea Water Salinity"}, &
02193                       conversion=0.001)
02194 \textcolor{keywordflow}{    endif}
02195 
02196     \textcolor{keywordflow}{if} (advect\_ts) \textcolor{keywordflow}{then}
02197       s\_flux\_units = get\_tr\_flux\_units(gv, \textcolor{stringliteral}{"psu"}) \textcolor{comment}{! Could change to "kg m-2 s-1"?}
02198       conv2watt    = gv%H\_to\_kg\_m2 * us%Q\_to\_J\_kg*cs%tv%C\_p
02199       \textcolor{keywordflow}{if} (gv%Boussinesq) \textcolor{keywordflow}{then}
02200         conv2salt = gv%H\_to\_m \textcolor{comment}{! Could change to GV%H\_to\_kg\_m2 * 0.001?}
02201       \textcolor{keywordflow}{else}
02202         conv2salt = gv%H\_to\_kg\_m2
02203 \textcolor{keywordflow}{      endif}
02204       \textcolor{keyword}{call }register\_tracer(cs%tv%T, cs%tracer\_Reg, param\_file, dg%HI, gv, &
02205                            tr\_desc=vd\_t, registry\_diags=.true., flux\_nameroot=\textcolor{stringliteral}{'T'}, &
02206                            flux\_units=\textcolor{stringliteral}{'W'}, flux\_longname=\textcolor{stringliteral}{'Heat'}, &
02207                            flux\_scale=conv2watt, convergence\_units=\textcolor{stringliteral}{'W m-2'}, &
02208                            convergence\_scale=conv2watt, cmor\_tendprefix=\textcolor{stringliteral}{"opottemp"}, diag\_form=2)
02209       \textcolor{keyword}{call }register\_tracer(cs%tv%S, cs%tracer\_Reg, param\_file, dg%HI, gv, &
02210                            tr\_desc=vd\_s, registry\_diags=.true., flux\_nameroot=\textcolor{stringliteral}{'S'}, &
02211                            flux\_units=s\_flux\_units, flux\_longname=\textcolor{stringliteral}{'Salt'}, &
02212                            flux\_scale=conv2salt, convergence\_units=\textcolor{stringliteral}{'kg m-2 s-1'}, &
02213                            convergence\_scale=0.001*gv%H\_to\_kg\_m2, cmor\_tendprefix=\textcolor{stringliteral}{"osalt"}, diag\_form=2)
02214 \textcolor{keywordflow}{    endif}
02215     \textcolor{comment}{! NOTE: register\_temp\_salt\_segments includes allocation of tracer fields}
02216     \textcolor{comment}{!   along segments.  Bit reproducibility requires that MOM\_initialize\_state}
02217     \textcolor{comment}{!   be called on the input index map, so we must setup both OBC and OBC\_in.}
02218     \textcolor{comment}{!}
02219     \textcolor{comment}{! XXX: This call on OBC\_in allocates the tracer fields on the unrotated}
02220     \textcolor{comment}{!   grid, but also incorrectly stores a pointer to a tracer\_type for the}
02221     \textcolor{comment}{!   rotated registry (e.g. segment%tr\_reg%Tr(n)%Tr) from CS%tracer\_reg.}
02222     \textcolor{comment}{!}
02223     \textcolor{comment}{!   While incorrect and potentially dangerous, it does not seem that this}
02224     \textcolor{comment}{!   pointer is used during initialization, so we leave it for now.}
02225     \textcolor{keywordflow}{if} (cs%rotate\_index .and. \textcolor{keyword}{associated}(obc\_in)) &
02226       \textcolor{keyword}{call }register\_temp\_salt\_segments(gv, obc\_in, cs%tracer\_Reg, param\_file)
02227     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%OBC)) &
02228       \textcolor{keyword}{call }register\_temp\_salt\_segments(gv, cs%OBC, cs%tracer\_Reg, param\_file)
02229 \textcolor{keywordflow}{  endif}
02230   \textcolor{keywordflow}{if} (use\_frazil) \textcolor{keywordflow}{then}
02231     \textcolor{keyword}{allocate}(cs%tv%frazil(isd:ied,jsd:jed)) ; cs%tv%frazil(:,:) = 0.0
02232 \textcolor{keywordflow}{  endif}
02233   \textcolor{keywordflow}{if} (bound\_salinity) \textcolor{keywordflow}{then}
02234     \textcolor{keyword}{allocate}(cs%tv%salt\_deficit(isd:ied,jsd:jed)) ; cs%tv%salt\_deficit(:,:) = 0.0
02235 \textcolor{keywordflow}{  endif}
02236 
02237   \textcolor{keywordflow}{if} (bulkmixedlayer .or. use\_temperature) \textcolor{keywordflow}{then}
02238     \textcolor{keyword}{allocate}(cs%Hml(isd:ied,jsd:jed)) ; cs%Hml(:,:) = 0.0
02239 \textcolor{keywordflow}{  endif}
02240 
02241   \textcolor{keywordflow}{if} (bulkmixedlayer) \textcolor{keywordflow}{then}
02242     gv%nkml = nkml ; gv%nk\_rho\_varies = nkml + nkbl
02243   \textcolor{keywordflow}{else}
02244     gv%nkml = 0 ; gv%nk\_rho\_varies = 0
02245 \textcolor{keywordflow}{  endif}
02246   \textcolor{keywordflow}{if} (cs%use\_ALE\_algorithm) \textcolor{keywordflow}{then}
02247     \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"NK\_RHO\_VARIES"}, gv%nk\_rho\_varies, default=0) \textcolor{comment}{! Will default to nz
       later... -AJA}
02248 \textcolor{keywordflow}{  endif}
02249 
02250   alloc\_(cs%uhtr(isdb:iedb,jsd:jed,nz)) ; cs%uhtr(:,:,:) = 0.0
02251   alloc\_(cs%vhtr(isd:ied,jsdb:jedb,nz)) ; cs%vhtr(:,:,:) = 0.0
02252   cs%t\_dyn\_rel\_adv = 0.0 ; cs%t\_dyn\_rel\_thermo = 0.0 ; cs%t\_dyn\_rel\_diag = 0.0
02253 
02254   \textcolor{keywordflow}{if} (debug\_truncations) \textcolor{keywordflow}{then}
02255     \textcolor{keyword}{allocate}(cs%u\_prev(isdb:iedb,jsd:jed,nz)) ; cs%u\_prev(:,:,:) = 0.0
02256     \textcolor{keyword}{allocate}(cs%v\_prev(isd:ied,jsdb:jedb,nz)) ; cs%v\_prev(:,:,:) = 0.0
02257     mom\_internal\_state%u\_prev => cs%u\_prev
02258     mom\_internal\_state%v\_prev => cs%v\_prev
02259     \textcolor{keyword}{call }safe\_alloc\_ptr(cs%ADp%du\_dt\_visc,isdb,iedb,jsd,jed,nz)
02260     \textcolor{keyword}{call }safe\_alloc\_ptr(cs%ADp%dv\_dt\_visc,isd,ied,jsdb,jedb,nz)
02261     \textcolor{keywordflow}{if} (.not.cs%adiabatic) \textcolor{keywordflow}{then}
02262       \textcolor{keyword}{call }safe\_alloc\_ptr(cs%ADp%du\_dt\_dia,isdb,iedb,jsd,jed,nz)
02263       \textcolor{keyword}{call }safe\_alloc\_ptr(cs%ADp%dv\_dt\_dia,isd,ied,jsdb,jedb,nz)
02264 \textcolor{keywordflow}{    endif}
02265 \textcolor{keywordflow}{  endif}
02266 
02267   mom\_internal\_state%u => cs%u ; mom\_internal\_state%v => cs%v
02268   mom\_internal\_state%h => cs%h
02269   mom\_internal\_state%uh => cs%uh ; mom\_internal\_state%vh => cs%vh
02270   \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
02271     mom\_internal\_state%T => cs%T ; mom\_internal\_state%S => cs%S
02272 \textcolor{keywordflow}{  endif}
02273 
02274   cs%CDp%uh => cs%uh ; cs%CDp%vh => cs%vh
02275 
02276   \textcolor{keywordflow}{if} (cs%interp\_p\_surf) \textcolor{keywordflow}{then}
02277     \textcolor{keyword}{allocate}(cs%p\_surf\_prev(isd:ied,jsd:jed)) ; cs%p\_surf\_prev(:,:) = 0.0
02278 \textcolor{keywordflow}{  endif}
02279 
02280   alloc\_(cs%ssh\_rint(isd:ied,jsd:jed)) ; cs%ssh\_rint(:,:) = 0.0
02281   alloc\_(cs%ave\_ssh\_ibc(isd:ied,jsd:jed)) ; cs%ave\_ssh\_ibc(:,:) = 0.0
02282   alloc\_(cs%eta\_av\_bc(isd:ied,jsd:jed)) ; cs%eta\_av\_bc(:,:) = 0.0
02283   cs%time\_in\_cycle = 0.0 ; cs%time\_in\_thermo\_cycle = 0.0
02284 
02285   \textcolor{comment}{! Use the Wright equation of state by default, unless otherwise specified}
02286   \textcolor{comment}{! Note: this line and the following block ought to be in a separate}
02287   \textcolor{comment}{! initialization routine for tv.}
02288   \textcolor{keywordflow}{if} (use\_eos) \textcolor{keyword}{call }eos\_init(param\_file, cs%tv%eqn\_of\_state, us)
02289   \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
02290     \textcolor{keyword}{allocate}(cs%tv%TempxPmE(isd:ied,jsd:jed)) ; cs%tv%TempxPmE(:,:) = 0.0
02291     \textcolor{keywordflow}{if} (use\_geothermal) \textcolor{keywordflow}{then}
02292       \textcolor{keyword}{allocate}(cs%tv%internal\_heat(isd:ied,jsd:jed)) ; cs%tv%internal\_heat(:,:) = 0.0
02293 \textcolor{keywordflow}{    endif}
02294 \textcolor{keywordflow}{  endif}
02295   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"state variables allocated (initialize\_MOM)"})
02296 
02297   \textcolor{comment}{! Set the fields that are needed for bitwise identical restarting}
02298   \textcolor{comment}{! the time stepping scheme.}
02299   \textcolor{keyword}{call }restart\_init(param\_file, restart\_csp)
02300   \textcolor{keyword}{call }\hyperlink{namespacemom_a76cb0af280a5c9e877dc206a6849b46b}{set\_restart\_fields}(gv, us, param\_file, cs, restart\_csp)
02301   \textcolor{keywordflow}{if} (cs%split) \textcolor{keywordflow}{then}
02302     \textcolor{keyword}{call }register\_restarts\_dyn\_split\_rk2(dg%HI, gv, param\_file, &
02303              cs%dyn\_split\_RK2\_CSp, restart\_csp, cs%uh, cs%vh)
02304   \textcolor{keywordflow}{elseif} (cs%use\_RK2) \textcolor{keywordflow}{then}
02305     \textcolor{keyword}{call }register\_restarts\_dyn\_unsplit\_rk2(dg%HI, gv, param\_file, &
02306            cs%dyn\_unsplit\_RK2\_CSp, restart\_csp)
02307   \textcolor{keywordflow}{else}
02308     \textcolor{keyword}{call }register\_restarts\_dyn\_unsplit(dg%HI, gv, param\_file, &
02309            cs%dyn\_unsplit\_CSp, restart\_csp)
02310 \textcolor{keywordflow}{  endif}
02311 
02312   \textcolor{comment}{! This subroutine calls user-specified tracer registration routines.}
02313   \textcolor{comment}{! Additional calls can be added to MOM\_tracer\_flow\_control.F90.}
02314   \textcolor{keyword}{call }call\_tracer\_register(dg%HI, gv, us, param\_file, cs%tracer\_flow\_CSp, &
02315                             cs%tracer\_Reg, restart\_csp)
02316 
02317   \textcolor{keyword}{call }meke\_alloc\_register\_restart(dg%HI, param\_file, cs%MEKE, restart\_csp)
02318   \textcolor{keyword}{call }set\_visc\_register\_restarts(dg%HI, gv, param\_file, cs%visc, restart\_csp)
02319   \textcolor{keyword}{call }mixedlayer\_restrat\_register\_restarts(dg%HI, param\_file, &
02320            cs%mixedlayer\_restrat\_CSp, restart\_csp)
02321 
02322   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%OBC)) &
02323     \textcolor{keyword}{call }open\_boundary\_register\_restarts(dg%HI, gv, cs%OBC, cs%tracer\_Reg, &
02324                           param\_file, restart\_csp, use\_temperature)
02325 
02326   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"restart registration complete (initialize\_MOM)"})
02327 
02328   \textcolor{comment}{! Initialize dynamically evolving fields, perhaps from restart files.}
02329   \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a4180eb85bab39df7cbb72bb8e5b19fd4}{id\_clock\_mom\_init})
02330   \textcolor{keyword}{call }mom\_initialize\_coord(gv, us, param\_file, write\_geom\_files, &
02331                             dirs%output\_directory, cs%tv, dg%max\_depth)
02332   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"returned from MOM\_initialize\_coord() (initialize\_MOM)"})
02333 
02334   \textcolor{keywordflow}{if} (cs%use\_ALE\_algorithm) \textcolor{keywordflow}{then}
02335     \textcolor{keyword}{call }ale\_init(param\_file, gv, us, dg%max\_depth, cs%ALE\_CSp)
02336     \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"returned from ALE\_init() (initialize\_MOM)"})
02337 \textcolor{keywordflow}{  endif}
02338 
02339   \textcolor{comment}{!   Shift from using the temporary dynamic grid type to using the final}
02340   \textcolor{comment}{! (potentially static) ocean-specific grid type.}
02341   \textcolor{comment}{!   The next line would be needed if G%Domain had not already been init'd above:}
02342   \textcolor{comment}{!     call clone\_MOM\_domain(dG%Domain, G%Domain)}
02343 
02344   \textcolor{comment}{! NOTE: If indices are rotated, then G and G\_in must both be initialized.}
02345   \textcolor{comment}{!   If not rotated, then G\_in and G are the same grid.}
02346   \textcolor{keywordflow}{if} (cs%rotate\_index) \textcolor{keywordflow}{then}
02347     \textcolor{keyword}{call }mom\_grid\_init(g, param\_file, us, hi, bathymetry\_at\_vel=bathy\_at\_vel)
02348     \textcolor{keyword}{call }copy\_dyngrid\_to\_mom\_grid(dg, g, us)
02349     \textcolor{keyword}{call }destroy\_dyn\_horgrid(dg)
02350 \textcolor{keywordflow}{  endif}
02351   \textcolor{keyword}{call }mom\_grid\_init(g\_in, param\_file, us, hi\_in, bathymetry\_at\_vel=bathy\_at\_vel)
02352   \textcolor{keyword}{call }copy\_dyngrid\_to\_mom\_grid(dg\_in, g\_in, us)
02353   \textcolor{keyword}{call }destroy\_dyn\_horgrid(dg\_in)
02354 
02355   \textcolor{comment}{! Set a few remaining fields that are specific to the ocean grid type.}
02356   \textcolor{keyword}{call }set\_first\_direction(g, first\_direction)
02357   \textcolor{comment}{! Allocate the auxiliary non-symmetric domain for debugging or I/O purposes.}
02358   \textcolor{keywordflow}{if} (cs%debug .or. g%symmetric) \textcolor{keywordflow}{then}
02359     \textcolor{keyword}{call }clone\_mom\_domain(g%Domain, g%Domain\_aux, symmetric=.false.)
02360   \textcolor{keywordflow}{else} ; g%Domain\_aux => g%Domain ;\textcolor{keywordflow}{ endif}
02361   \textcolor{comment}{! Copy common variables from the vertical grid to the horizontal grid.}
02362   \textcolor{comment}{! Consider removing this later?}
02363   g%ke = gv%ke
02364 
02365   \textcolor{keywordflow}{if} (cs%rotate\_index) \textcolor{keywordflow}{then}
02366     g\_in%ke = gv%ke
02367 
02368     \textcolor{keyword}{allocate}(u\_in(g\_in%IsdB:g\_in%IedB, g\_in%jsd:g\_in%jed, nz))
02369     \textcolor{keyword}{allocate}(v\_in(g\_in%isd:g\_in%ied, g\_in%JsdB:g\_in%JedB, nz))
02370     \textcolor{keyword}{allocate}(h\_in(g\_in%isd:g\_in%ied, g\_in%jsd:g\_in%jed, nz))
02371     u\_in(:,:,:) = 0.0
02372     v\_in(:,:,:) = 0.0
02373     h\_in(:,:,:) = gv%Angstrom\_H
02374 
02375     \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
02376       \textcolor{keyword}{allocate}(t\_in(g\_in%isd:g\_in%ied, g\_in%jsd:g\_in%jed, nz))
02377       \textcolor{keyword}{allocate}(s\_in(g\_in%isd:g\_in%ied, g\_in%jsd:g\_in%jed, nz))
02378       t\_in(:,:,:) = 0.0
02379       s\_in(:,:,:) = 0.0
02380 
02381       cs%tv%T => t\_in
02382       cs%tv%S => s\_in
02383 \textcolor{keywordflow}{    endif}
02384 
02385     \textcolor{keyword}{call }mom\_initialize\_state(u\_in, v\_in, h\_in, cs%tv, time, g\_in, gv, us, &
02386         param\_file, dirs, restart\_csp, cs%ALE\_CSp, cs%tracer\_Reg, &
02387         sponge\_in\_csp, ale\_sponge\_in\_csp, obc\_in, time\_in)
02388 
02389     \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
02390       cs%tv%T => cs%T
02391       cs%tv%S => cs%S
02392 \textcolor{keywordflow}{    endif}
02393 
02394     \textcolor{keyword}{call }\hyperlink{namespacemom_a8f5160e583b599050515b8fe5575aa15}{rotate\_initial\_state}(u\_in, v\_in, h\_in, t\_in, s\_in, use\_temperature, &
02395         turns, cs%u, cs%v, cs%h, cs%T, cs%S)
02396 
02397     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(sponge\_in\_csp)) \textcolor{keywordflow}{then}
02398       \textcolor{comment}{! TODO: Implementation and testing of non-ALE spong rotation}
02399       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"Index rotation of non-ALE sponge is not yet implemented."})
02400 \textcolor{keywordflow}{    endif}
02401 
02402     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(ale\_sponge\_in\_csp)) \textcolor{keywordflow}{then}
02403       \textcolor{keyword}{call }rotate\_ale\_sponge(ale\_sponge\_in\_csp, g\_in, cs%ALE\_sponge\_CSp, g, turns, param\_file)
02404       \textcolor{keyword}{call }update\_ale\_sponge\_field(cs%ALE\_sponge\_CSp, t\_in, g, gv, cs%T)
02405       \textcolor{keyword}{call }update\_ale\_sponge\_field(cs%ALE\_sponge\_CSp, s\_in, g, gv, cs%S)
02406 \textcolor{keywordflow}{    endif}
02407 
02408     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc\_in)) &
02409       \textcolor{keyword}{call }rotate\_obc\_init(obc\_in, g, gv, us, param\_file, cs%tv, restart\_csp, cs%OBC)
02410 
02411     \textcolor{keyword}{deallocate}(u\_in)
02412     \textcolor{keyword}{deallocate}(v\_in)
02413     \textcolor{keyword}{deallocate}(h\_in)
02414     \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
02415       \textcolor{keyword}{deallocate}(t\_in)
02416       \textcolor{keyword}{deallocate}(s\_in)
02417 \textcolor{keywordflow}{    endif}
02418   \textcolor{keywordflow}{else}
02419     \textcolor{keyword}{call }mom\_initialize\_state(cs%u, cs%v, cs%h, cs%tv, time, g, gv, us, &
02420         param\_file, dirs, restart\_csp, cs%ALE\_CSp, cs%tracer\_Reg, &
02421         cs%sponge\_CSp, cs%ALE\_sponge\_CSp, cs%OBC, time\_in)
02422 \textcolor{keywordflow}{  endif}
02423 
02424   \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a4180eb85bab39df7cbb72bb8e5b19fd4}{id\_clock\_mom\_init})
02425   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"returned from MOM\_initialize\_state() (initialize\_MOM)"})
02426 
02427 \textcolor{comment}{! ! Need this after MOM\_initialize\_state for DOME OBC stuff.}
02428 \textcolor{comment}{! if (associated(CS%OBC)) &}
02429 \textcolor{comment}{!   call open\_boundary\_register\_restarts(G%HI, GV, CS%OBC, CS%tracer\_Reg, &}
02430 \textcolor{comment}{!                         param\_file, restart\_CSp, use\_temperature)}
02431 
02432 \textcolor{comment}{! call callTree\_waypoint("restart registration complete (initialize\_MOM)")}
02433 
02434   \textcolor{comment}{! From this point, there may be pointers being set, so the final grid type}
02435   \textcolor{comment}{! that will persist throughout the run has to be used.}
02436 
02437   \textcolor{keywordflow}{if} (test\_grid\_copy) \textcolor{keywordflow}{then}
02438     \textcolor{comment}{!  Copy the data from the temporary grid to the dyn\_hor\_grid to CS%G.}
02439     \textcolor{keyword}{call }create\_dyn\_horgrid(dg, g%HI)
02440     \textcolor{keyword}{call }clone\_mom\_domain(g%Domain, dg%Domain)
02441 
02442     \textcolor{keyword}{call }clone\_mom\_domain(g%Domain, cs%G%Domain)
02443     \textcolor{keyword}{call }mom\_grid\_init(cs%G, param\_file, us)
02444 
02445     \textcolor{keyword}{call }copy\_mom\_grid\_to\_dyngrid(g, dg, us)
02446     \textcolor{keyword}{call }copy\_dyngrid\_to\_mom\_grid(dg, cs%G, us)
02447 
02448     \textcolor{keyword}{call }destroy\_dyn\_horgrid(dg)
02449     \textcolor{keyword}{call }mom\_grid\_end(g) ; \textcolor{keyword}{deallocate}(g)
02450 
02451     g => cs%G
02452     \textcolor{keywordflow}{if} (cs%debug .or. cs%G%symmetric) \textcolor{keywordflow}{then}
02453       \textcolor{keyword}{call }clone\_mom\_domain(cs%G%Domain, cs%G%Domain\_aux, symmetric=.false.)
02454     \textcolor{keywordflow}{else} ; cs%G%Domain\_aux => cs%G%Domain ;\textcolor{keywordflow}{ endif}
02455     g%ke = gv%ke
02456 \textcolor{keywordflow}{  endif}
02457 
02458   \textcolor{comment}{! At this point, all user-modified initialization code has been called.  The}
02459   \textcolor{comment}{! remainder of this subroutine is controlled by the parameters that have}
02460   \textcolor{comment}{! have already been set.}
02461 
02462   \textcolor{keywordflow}{if} (ale\_remap\_init\_conds(cs%ALE\_CSp) .and. .not. query\_initialized(cs%h,\textcolor{stringliteral}{"h"},restart\_csp)) \textcolor{keywordflow}{then}
02463     \textcolor{comment}{! This block is controlled by the ALE parameter REMAP\_AFTER\_INITIALIZATION.}
02464     \textcolor{comment}{! \(\backslash\)todo This block exists for legacy reasons and we should phase it out of}
02465     \textcolor{comment}{! all examples. !###}
02466     \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
02467       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Pre ALE adjust init cond [uv]"}, &
02468                     cs%u, cs%v, g%HI, haloshift=1)
02469       \textcolor{keyword}{call }hchksum(cs%h,\textcolor{stringliteral}{"Pre ALE adjust init cond h"}, g%HI, haloshift=1, scale=gv%H\_to\_m)
02470 \textcolor{keywordflow}{    endif}
02471     \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"Calling adjustGridForIntegrity() to remap initial conditions (initialize\_MOM)"})
02472     \textcolor{keyword}{call }adjustgridforintegrity(cs%ALE\_CSp, g, gv, cs%h )
02473     \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"Calling ALE\_main() to remap initial conditions (initialize\_MOM)"})
02474     \textcolor{keywordflow}{if} (use\_ice\_shelf) \textcolor{keywordflow}{then}
02475       filename = trim(inputdir)//trim(ice\_shelf\_file)
02476       \textcolor{keywordflow}{if} (.not.file\_exists(filename, g%Domain)) \textcolor{keyword}{call }mom\_error(fatal, &
02477         \textcolor{stringliteral}{"MOM: Unable to open "}//trim(filename))
02478 
02479       \textcolor{keyword}{allocate}(area\_shelf\_h(isd:ied,jsd:jed))
02480       \textcolor{keyword}{allocate}(frac\_shelf\_h(isd:ied,jsd:jed))
02481       \textcolor{keyword}{call }mom\_read\_data(filename, trim(area\_varname), area\_shelf\_h, g%Domain, scale=us%m\_to\_L**2)
02482       \textcolor{comment}{! initialize frac\_shelf\_h with zeros (open water everywhere)}
02483       frac\_shelf\_h(:,:) = 0.0
02484       \textcolor{comment}{! compute fractional ice shelf coverage of h}
02485       \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
02486         \textcolor{keywordflow}{if} (g%areaT(i,j) > 0.0) &
02487           frac\_shelf\_h(i,j) = area\_shelf\_h(i,j) / g%areaT(i,j)
02488 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
02489       \textcolor{comment}{! pass to the pointer}
02490       shelf\_area => frac\_shelf\_h
02491       \textcolor{keyword}{call }ale\_main(g, gv, us, cs%h, cs%u, cs%v, cs%tv, cs%tracer\_Reg, cs%ALE\_CSp, &
02492                     cs%OBC, frac\_shelf\_h=shelf\_area)
02493     \textcolor{keywordflow}{else}
02494       \textcolor{keyword}{call }ale\_main( g, gv, us, cs%h, cs%u, cs%v, cs%tv, cs%tracer\_Reg, cs%ALE\_CSp, cs%OBC)
02495 \textcolor{keywordflow}{    endif}
02496 
02497     \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_ac4d20612cad32d412dae492fedc2e971}{id\_clock\_pass\_init})
02498     \textcolor{keyword}{call }create\_group\_pass(tmp\_pass\_uv\_t\_s\_h, cs%u, cs%v, g%Domain)
02499     \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
02500       \textcolor{keyword}{call }create\_group\_pass(tmp\_pass\_uv\_t\_s\_h, cs%tv%T, g%Domain, halo=1)
02501       \textcolor{keyword}{call }create\_group\_pass(tmp\_pass\_uv\_t\_s\_h, cs%tv%S, g%Domain, halo=1)
02502 \textcolor{keywordflow}{    endif}
02503     \textcolor{keyword}{call }create\_group\_pass(tmp\_pass\_uv\_t\_s\_h, cs%h, g%Domain, halo=1)
02504     \textcolor{keyword}{call }do\_group\_pass(tmp\_pass\_uv\_t\_s\_h, g%Domain)
02505     \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_ac4d20612cad32d412dae492fedc2e971}{id\_clock\_pass\_init})
02506 
02507     \textcolor{keywordflow}{if} (cs%debug) \textcolor{keywordflow}{then}
02508       \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"Post ALE adjust init cond [uv]"}, cs%u, cs%v, g%HI, haloshift=1)
02509       \textcolor{keyword}{call }hchksum(cs%h, \textcolor{stringliteral}{"Post ALE adjust init cond h"}, g%HI, haloshift=1, scale=gv%H\_to\_m)
02510 \textcolor{keywordflow}{    endif}
02511 \textcolor{keywordflow}{  endif}
02512   \textcolor{keywordflow}{if} ( cs%use\_ALE\_algorithm ) \textcolor{keyword}{call }ale\_updateverticalgridtype( cs%ALE\_CSp, gv )
02513 
02514   diag => cs%diag
02515   \textcolor{comment}{! Initialize the diag mediator.}
02516   \textcolor{keyword}{call }diag\_mediator\_init(g, gv, us, gv%ke, param\_file, diag, doc\_file\_dir=dirs%output\_directory)
02517   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(diag\_ptr)) diag\_ptr => cs%diag
02518 
02519   \textcolor{comment}{! Initialize the diagnostics masks for native arrays.}
02520   \textcolor{comment}{! This step has to be done after call to MOM\_initialize\_state}
02521   \textcolor{comment}{! and before MOM\_diagnostics\_init}
02522   \textcolor{keyword}{call }diag\_masks\_set(g, gv%ke, diag)
02523 
02524   \textcolor{comment}{! Set up pointers within diag mediator control structure,}
02525   \textcolor{comment}{! this needs to occur \_after\_ CS%h etc. have been allocated.}
02526   \textcolor{keyword}{call }diag\_set\_state\_ptrs(cs%h, cs%T, cs%S, cs%tv%eqn\_of\_state, diag)
02527 
02528   \textcolor{comment}{! This call sets up the diagnostic axes. These are needed,}
02529   \textcolor{comment}{! e.g. to generate the target grids below.}
02530   \textcolor{keyword}{call }set\_axes\_info(g, gv, us, param\_file, diag)
02531 
02532   \textcolor{comment}{! Whenever thickness/T/S changes let the diag manager know, target grids}
02533   \textcolor{comment}{! for vertical remapping may need to be regenerated.}
02534   \textcolor{comment}{! FIXME: are h, T, S updated at the same time? Review these for T, S updates.}
02535   \textcolor{keyword}{call }diag\_update\_remap\_grids(diag)
02536 
02537   \textcolor{comment}{! Setup the diagnostic grid storage types}
02538   \textcolor{keyword}{call }diag\_grid\_storage\_init(cs%diag\_pre\_sync, g, diag)
02539   \textcolor{keyword}{call }diag\_grid\_storage\_init(cs%diag\_pre\_dyn, g, diag)
02540 
02541   \textcolor{comment}{! Calculate masks for diagnostics arrays in non-native coordinates}
02542   \textcolor{comment}{! This step has to be done after set\_axes\_info() because the axes needed}
02543   \textcolor{comment}{! to be configured, and after diag\_update\_remap\_grids() because the grids}
02544   \textcolor{comment}{! must be defined.}
02545   \textcolor{keyword}{call }set\_masks\_for\_axes(g, diag)
02546 
02547   \textcolor{comment}{! Diagnose static fields AND associate areas/volumes with axes}
02548   \textcolor{keyword}{call }write\_static\_fields(g, gv, us, cs%tv, cs%diag)
02549   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"static fields written (initialize\_MOM)"})
02550 
02551   \textcolor{comment}{! Register the volume cell measure (must be one of first diagnostics)}
02552   \textcolor{keyword}{call }register\_cell\_measure(g, cs%diag, time)
02553 
02554   \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a4180eb85bab39df7cbb72bb8e5b19fd4}{id\_clock\_mom\_init})
02555   \textcolor{keywordflow}{if} (cs%use\_ALE\_algorithm) \textcolor{keywordflow}{then}
02556     \textcolor{keyword}{call }ale\_writecoordinatefile( cs%ALE\_CSp, gv, dirs%output\_directory )
02557 \textcolor{keywordflow}{  endif}
02558   \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a4180eb85bab39df7cbb72bb8e5b19fd4}{id\_clock\_mom\_init})
02559   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"ALE initialized (initialize\_MOM)"})
02560 
02561   cs%useMEKE = meke\_init(time, g, us, param\_file, diag, cs%MEKE\_CSp, cs%MEKE, restart\_csp)
02562 
02563   \textcolor{keyword}{call }varmix\_init(time, g, gv, us, param\_file, diag, cs%VarMix)
02564   \textcolor{keyword}{call }set\_visc\_init(time, g, gv, us, param\_file, diag, cs%visc, cs%set\_visc\_CSp, restart\_csp, cs%OBC)
02565   \textcolor{keyword}{call }thickness\_diffuse\_init(time, g, gv, us, param\_file, diag, cs%CDp, cs%thickness\_diffuse\_CSp)
02566 
02567   \textcolor{keywordflow}{if} (cs%split) \textcolor{keywordflow}{then}
02568     \textcolor{keyword}{allocate}(eta(szi\_(g),szj\_(g))) ; eta(:,:) = 0.0
02569     \textcolor{keyword}{call }initialize\_dyn\_split\_rk2(cs%u, cs%v, cs%h, cs%uh, cs%vh, eta, time, &
02570               g, gv, us, param\_file, diag, cs%dyn\_split\_RK2\_CSp, restart\_csp, &
02571               cs%dt, cs%ADp, cs%CDp, mom\_internal\_state, cs%VarMix, cs%MEKE, &
02572               cs%thickness\_diffuse\_CSp,                                      &
02573               cs%OBC, cs%update\_OBC\_CSp, cs%ALE\_CSp, cs%set\_visc\_CSp,        &
02574               cs%visc, dirs, cs%ntrunc, calc\_dtbt=calc\_dtbt, cont\_stencil=cs%cont\_stencil)
02575     \textcolor{keywordflow}{if} (cs%dtbt\_reset\_period > 0.0) \textcolor{keywordflow}{then}
02576       cs%dtbt\_reset\_interval = real\_to\_time(cs%dtbt\_reset\_period)
02577       \textcolor{comment}{! Set dtbt\_reset\_time to be the next even multiple of dtbt\_reset\_interval.}
02578       cs%dtbt\_reset\_time = time\_init + cs%dtbt\_reset\_interval * &
02579                                  ((time - time\_init) / cs%dtbt\_reset\_interval)
02580       \textcolor{keywordflow}{if} ((cs%dtbt\_reset\_time > time) .and. calc\_dtbt) \textcolor{keywordflow}{then}
02581         \textcolor{comment}{! Back up dtbt\_reset\_time one interval to force dtbt to be calculated,}
02582         \textcolor{comment}{! because the restart was not aligned with the interval to recalculate}
02583         \textcolor{comment}{! dtbt, and dtbt was not read from a restart file.}
02584         cs%dtbt\_reset\_time = cs%dtbt\_reset\_time - cs%dtbt\_reset\_interval
02585 \textcolor{keywordflow}{      endif}
02586 \textcolor{keywordflow}{    endif}
02587   \textcolor{keywordflow}{elseif} (cs%use\_RK2) \textcolor{keywordflow}{then}
02588     \textcolor{keyword}{call }initialize\_dyn\_unsplit\_rk2(cs%u, cs%v, cs%h, time, g, gv, us,     &
02589             param\_file, diag, cs%dyn\_unsplit\_RK2\_CSp, restart\_csp,         &
02590             cs%ADp, cs%CDp, mom\_internal\_state, cs%MEKE, cs%OBC,           &
02591             cs%update\_OBC\_CSp, cs%ALE\_CSp, cs%set\_visc\_CSp, cs%visc, dirs, &
02592             cs%ntrunc, cont\_stencil=cs%cont\_stencil)
02593   \textcolor{keywordflow}{else}
02594     \textcolor{keyword}{call }initialize\_dyn\_unsplit(cs%u, cs%v, cs%h, time, g, gv, us,         &
02595             param\_file, diag, cs%dyn\_unsplit\_CSp, restart\_csp,             &
02596             cs%ADp, cs%CDp, mom\_internal\_state, cs%MEKE, cs%OBC,           &
02597             cs%update\_OBC\_CSp, cs%ALE\_CSp, cs%set\_visc\_CSp, cs%visc, dirs, &
02598             cs%ntrunc, cont\_stencil=cs%cont\_stencil)
02599 \textcolor{keywordflow}{  endif}
02600 
02601   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"dynamics initialized (initialize\_MOM)"})
02602 
02603   cs%mixedlayer\_restrat = mixedlayer\_restrat\_init(time, g, gv, us, param\_file, diag, &
02604                                                   cs%mixedlayer\_restrat\_CSp, restart\_csp)
02605   \textcolor{keywordflow}{if} (cs%mixedlayer\_restrat) \textcolor{keywordflow}{then}
02606     \textcolor{keywordflow}{if} (.not.(bulkmixedlayer .or. cs%use\_ALE\_algorithm)) &
02607       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM: MIXEDLAYER\_RESTRAT true requires a boundary layer scheme."})
02608     \textcolor{comment}{! When DIABATIC\_FIRST=False and using CS%visc%ML in mixedlayer\_restrat we need to update after a
       restart}
02609     \textcolor{keywordflow}{if} (.not. cs%diabatic\_first .and. \textcolor{keyword}{associated}(cs%visc%MLD)) &
02610       \textcolor{keyword}{call }pass\_var(cs%visc%MLD, g%domain, halo=1)
02611 \textcolor{keywordflow}{  endif}
02612 
02613   \textcolor{keyword}{call }mom\_diagnostics\_init(mom\_internal\_state, cs%ADp, cs%CDp, time, g, gv, us, &
02614                             param\_file, diag, cs%diagnostics\_CSp, cs%tv)
02615   \textcolor{keyword}{call }diag\_copy\_diag\_to\_storage(cs%diag\_pre\_sync, cs%h, cs%diag)
02616 
02617   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%sponge\_CSp)) &
02618     \textcolor{keyword}{call }init\_sponge\_diags(time, g, gv, us, diag, cs%sponge\_CSp)
02619 
02620   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%ALE\_sponge\_CSp)) &
02621     \textcolor{keyword}{call }init\_ale\_sponge\_diags(time, g, diag, cs%ALE\_sponge\_CSp)
02622 
02623   \textcolor{keywordflow}{if} (cs%adiabatic) \textcolor{keywordflow}{then}
02624     \textcolor{keyword}{call }adiabatic\_driver\_init(time, g, param\_file, diag, cs%diabatic\_CSp, &
02625                                cs%tracer\_flow\_CSp)
02626   \textcolor{keywordflow}{else}
02627     \textcolor{keyword}{call }diabatic\_driver\_init(time, g, gv, us, param\_file, cs%use\_ALE\_algorithm, diag, &
02628                               cs%ADp, cs%CDp, cs%diabatic\_CSp, cs%tracer\_flow\_CSp, &
02629                               cs%sponge\_CSp, cs%ALE\_sponge\_CSp)
02630 \textcolor{keywordflow}{  endif}
02631 
02632   \textcolor{keyword}{call }tracer\_advect\_init(time, g, us, param\_file, diag, cs%tracer\_adv\_CSp)
02633   \textcolor{keyword}{call }tracer\_hor\_diff\_init(time, g, us, param\_file, diag, cs%tv%eqn\_of\_state, cs%diabatic\_CSp, &
02634                             cs%tracer\_diff\_CSp)
02635 
02636   \textcolor{keyword}{call }lock\_tracer\_registry(cs%tracer\_Reg)
02637   \textcolor{keyword}{call }calltree\_waypoint(\textcolor{stringliteral}{"tracer registry now locked (initialize\_MOM)"})
02638 
02639   \textcolor{comment}{! now register some diagnostics since the tracer registry is now locked}
02640   \textcolor{keyword}{call }register\_surface\_diags(time, g, us, cs%sfc\_IDs, cs%diag, cs%tv)
02641   \textcolor{keyword}{call }\hyperlink{namespacemom_af0f791729b0ccb6cb8ae2f4d28edee21}{register\_diags}(time, g, gv, us, cs%IDs, cs%diag)
02642   \textcolor{keyword}{call }register\_transport\_diags(time, g, gv, us, cs%transport\_IDs, cs%diag)
02643   \textcolor{keyword}{call }register\_tracer\_diagnostics(cs%tracer\_Reg, cs%h, time, diag, g, gv, us, &
02644                                    cs%use\_ALE\_algorithm)
02645   \textcolor{keywordflow}{if} (cs%use\_ALE\_algorithm) \textcolor{keywordflow}{then}
02646     \textcolor{keyword}{call }ale\_register\_diags(time, g, gv, us, diag, cs%ALE\_CSp)
02647 \textcolor{keywordflow}{  endif}
02648 
02649   \textcolor{comment}{! This subroutine initializes any tracer packages.}
02650   new\_sim = is\_new\_run(restart\_csp)
02651   \textcolor{keyword}{call }tracer\_flow\_control\_init(.not.new\_sim, time, g, gv, us, cs%h, param\_file, &
02652              cs%diag, cs%OBC, cs%tracer\_flow\_CSp, cs%sponge\_CSp, &
02653              cs%ALE\_sponge\_CSp, cs%tv)
02654   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(tracer\_flow\_csp)) tracer\_flow\_csp => cs%tracer\_flow\_CSp
02655 
02656   \textcolor{comment}{! If running in offline tracer mode, initialize the necessary control structure and}
02657   \textcolor{comment}{! parameters}
02658   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(offline\_tracer\_mode)) offline\_tracer\_mode=cs%offline\_tracer\_mode
02659 
02660   \textcolor{keywordflow}{if} (cs%offline\_tracer\_mode) \textcolor{keywordflow}{then}
02661     \textcolor{comment}{! Setup some initial parameterizations and also assign some of the subtypes}
02662     \textcolor{keyword}{call }offline\_transport\_init(param\_file, cs%offline\_CSp, cs%diabatic\_CSp, g, gv, us)
02663     \textcolor{keyword}{call }insert\_offline\_main( cs=cs%offline\_CSp, ale\_csp=cs%ALE\_CSp, diabatic\_csp=cs%diabatic\_CSp, &
02664                               diag=cs%diag, obc=cs%OBC, tracer\_adv\_csp=cs%tracer\_adv\_CSp,              &
02665                               tracer\_flow\_csp=cs%tracer\_flow\_CSp, tracer\_reg=cs%tracer\_Reg,            &
02666                               tv=cs%tv, x\_before\_y = (mod(first\_direction,2)==0), debug=cs%debug )
02667     \textcolor{keyword}{call }register\_diags\_offline\_transport(time, cs%diag, cs%offline\_CSp)
02668 \textcolor{keywordflow}{  endif}
02669 
02670   \textcolor{comment}{!--- set up group pass for u,v,T,S and h. pass\_uv\_T\_S\_h also is used in step\_MOM}
02671   \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_ac4d20612cad32d412dae492fedc2e971}{id\_clock\_pass\_init})
02672   dynamics\_stencil = min(3, g%Domain%nihalo, g%Domain%njhalo)
02673   \textcolor{keyword}{call }create\_group\_pass(pass\_uv\_t\_s\_h, cs%u, cs%v, g%Domain, halo=dynamics\_stencil)
02674   \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
02675     \textcolor{keyword}{call }create\_group\_pass(pass\_uv\_t\_s\_h, cs%tv%T, g%Domain, halo=dynamics\_stencil)
02676     \textcolor{keyword}{call }create\_group\_pass(pass\_uv\_t\_s\_h, cs%tv%S, g%Domain, halo=dynamics\_stencil)
02677 \textcolor{keywordflow}{  endif}
02678   \textcolor{keyword}{call }create\_group\_pass(pass\_uv\_t\_s\_h, cs%h, g%Domain, halo=dynamics\_stencil)
02679 
02680   \textcolor{keyword}{call }do\_group\_pass(pass\_uv\_t\_s\_h, g%Domain)
02681 
02682   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%visc%Kv\_shear)) &
02683     \textcolor{keyword}{call }pass\_var(cs%visc%Kv\_shear, g%Domain, to\_all+omit\_corners, halo=1)
02684 
02685   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%visc%Kv\_slow)) &
02686     \textcolor{keyword}{call }pass\_var(cs%visc%Kv\_slow, g%Domain, to\_all+omit\_corners, halo=1)
02687 
02688   \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_ac4d20612cad32d412dae492fedc2e971}{id\_clock\_pass\_init})
02689 
02690   \textcolor{keyword}{call }register\_obsolete\_diagnostics(param\_file, cs%diag)
02691 
02692   \textcolor{keywordflow}{if} (use\_frazil) \textcolor{keywordflow}{then}
02693     \textcolor{keywordflow}{if} (query\_initialized(cs%tv%frazil, \textcolor{stringliteral}{"frazil"}, restart\_csp)) \textcolor{keywordflow}{then}
02694       \textcolor{comment}{! Test whether the dimensional rescaling has changed for heat content.}
02695       \textcolor{keywordflow}{if} ((us%kg\_m3\_to\_R\_restart*us%m\_to\_Z\_restart*us%J\_kg\_to\_Q\_restart /= 0.0) .and. &
02696           ((us%J\_kg\_to\_Q*us%kg\_m3\_to\_R*us%m\_to\_Z) /= &
02697            (us%J\_kg\_to\_Q\_restart*us%kg\_m3\_to\_R\_restart*us%m\_to\_Z\_restart)) ) \textcolor{keywordflow}{then}
02698         qrz\_rescale = (us%J\_kg\_to\_Q*us%kg\_m3\_to\_R*us%m\_to\_Z) / &
02699                       (us%J\_kg\_to\_Q\_restart*us%kg\_m3\_to\_R\_restart*us%m\_to\_Z\_restart)
02700         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
02701           cs%tv%frazil(i,j) = qrz\_rescale * cs%tv%frazil(i,j)
02702 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
02703 \textcolor{keywordflow}{      endif}
02704     \textcolor{keywordflow}{else}
02705       cs%tv%frazil(:,:) = 0.0
02706 \textcolor{keywordflow}{    endif}
02707 \textcolor{keywordflow}{  endif}
02708 
02709   \textcolor{keywordflow}{if} (cs%interp\_p\_surf) \textcolor{keywordflow}{then}
02710     cs%p\_surf\_prev\_set = query\_initialized(cs%p\_surf\_prev,\textcolor{stringliteral}{"p\_surf\_prev"},restart\_csp)
02711 
02712     \textcolor{keywordflow}{if} (cs%p\_surf\_prev\_set) \textcolor{keywordflow}{then}
02713       \textcolor{comment}{! Test whether the dimensional rescaling has changed for pressure.}
02714       \textcolor{keywordflow}{if} ((us%kg\_m3\_to\_R\_restart*us%s\_to\_T\_restart*us%m\_to\_L\_restart /= 0.0) .and. &
02715           ((us%kg\_m3\_to\_R*(us%m\_to\_L*us%s\_to\_T\_restart)**2) /= &
02716            (us%kg\_m3\_to\_R\_restart*(us%m\_to\_L\_restart*us%s\_to\_T)**2)) ) \textcolor{keywordflow}{then}
02717         rl2\_t2\_rescale = (us%kg\_m3\_to\_R*(us%m\_to\_L*us%s\_to\_T\_restart)**2) / &
02718                          (us%kg\_m3\_to\_R\_restart*(us%m\_to\_L\_restart*us%s\_to\_T)**2)
02719         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
02720           cs%p\_surf\_prev(i,j) = rl2\_t2\_rescale * cs%p\_surf\_prev(i,j)
02721 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
02722 \textcolor{keywordflow}{      endif}
02723 
02724       \textcolor{keyword}{call }pass\_var(cs%p\_surf\_prev, g%domain)
02725 \textcolor{keywordflow}{    endif}
02726 \textcolor{keywordflow}{  endif}
02727 
02728   \textcolor{keywordflow}{if} (use\_ice\_shelf .and. \textcolor{keyword}{associated}(cs%Hml)) \textcolor{keywordflow}{then}
02729     \textcolor{keywordflow}{if} (query\_initialized(cs%Hml, \textcolor{stringliteral}{"hML"}, restart\_csp)) \textcolor{keywordflow}{then}
02730       \textcolor{comment}{! Test whether the dimensional rescaling has changed for depths.}
02731       \textcolor{keywordflow}{if} ((us%m\_to\_Z\_restart /= 0.0) .and. (us%m\_to\_Z /= us%m\_to\_Z\_restart) ) \textcolor{keywordflow}{then}
02732         z\_rescale = us%m\_to\_Z / us%m\_to\_Z\_restart
02733         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
02734           cs%Hml(i,j) = z\_rescale * cs%Hml(i,j)
02735 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
02736 \textcolor{keywordflow}{      endif}
02737 \textcolor{keywordflow}{    endif}
02738 \textcolor{keywordflow}{  endif}
02739 
02740   \textcolor{keywordflow}{if} (.not.query\_initialized(cs%ave\_ssh\_ibc,\textcolor{stringliteral}{"ave\_ssh"},restart\_csp)) \textcolor{keywordflow}{then}
02741     \textcolor{keywordflow}{if} (cs%split) \textcolor{keywordflow}{then}
02742       \textcolor{keyword}{call }find\_eta(cs%h, cs%tv, g, gv, us, cs%ave\_ssh\_ibc, eta, eta\_to\_m=1.0)
02743     \textcolor{keywordflow}{else}
02744       \textcolor{keyword}{call }find\_eta(cs%h, cs%tv, g, gv, us, cs%ave\_ssh\_ibc, eta\_to\_m=1.0)
02745 \textcolor{keywordflow}{    endif}
02746 \textcolor{keywordflow}{  endif}
02747   \textcolor{keywordflow}{if} (cs%split) \textcolor{keyword}{deallocate}(eta)
02748 
02749   cs%nstep\_tot = 0
02750   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(count\_calls)) cs%count\_calls = count\_calls
02751   \textcolor{keyword}{call }mom\_sum\_output\_init(g\_in, us, param\_file, dirs%output\_directory, &
02752                            cs%ntrunc, time\_init, cs%sum\_output\_CSp)
02753 
02754   \textcolor{comment}{! Flag whether to save initial conditions in finish\_MOM\_initialization() or not.}
02755   cs%write\_IC = save\_ic .and. &
02756                 .not.((dirs%input\_filename(1:1) == \textcolor{stringliteral}{'r'}) .and. &
02757                       (len\_trim(dirs%input\_filename) == 1))
02758 
02759   \textcolor{keywordflow}{if} (cs%ensemble\_ocean) \textcolor{keywordflow}{then}
02760     \textcolor{keyword}{call }init\_oda(time, g, gv, cs%odaCS)
02761 \textcolor{keywordflow}{  endif}
02762 
02763   \textcolor{comment}{!### This could perhaps go here instead of in finish\_MOM\_initialization?}
02764   \textcolor{comment}{! call fix\_restart\_scaling(GV)}
02765   \textcolor{comment}{! call fix\_restart\_unit\_scaling(US)}
02766 
02767   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"initialize\_MOM()"})
02768   \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a7cf03c18244d0630616e925bab1841a2}{id\_clock\_init})
02769 
02770 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom_a96708b16215666edbfa5b46228f3a200}{initialize\_mom}
02771 \textcolor{comment}{}
02772 \textcolor{comment}{!> Finishes initializing MOM and writes out the initial conditions.}
02773 \textcolor{keyword}{subroutine }\hyperlink{namespacemom_a2269d5cd79625cbf16cb916346379207}{finish\_mom\_initialization}(Time, dirs, CS, restart\_CSp)
\Hypertarget{MOM_8F90_source_l02774}\hyperlink{namespacemom_a2269d5cd79625cbf16cb916346379207}{02774}   \textcolor{keywordtype}{type}(time\_type),          \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{        !< model time, used in this routine}
02775   \textcolor{keywordtype}{type}(directories),        \textcolor{keywordtype}{intent(in)}    :: dirs\textcolor{comment}{        !< structure with directory paths}
02776   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__control__struct}{mom\_control\_struct}), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{          !< pointer to MOM control
       structure}
02777   \textcolor{keywordtype}{type}(mom\_restart\_cs),     \textcolor{keywordtype}{pointer}       :: restart\_CSp\textcolor{comment}{ !< pointer to the restart control}
02778 \textcolor{comment}{                                                         !! structure that will be used for MOM.}
02779   \textcolor{comment}{! Local variables}
02780   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer} :: G => null()  \textcolor{comment}{! pointer to a structure containing}
02781                                                    \textcolor{comment}{! metrics and related information}
02782   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{pointer} :: GV => null() \textcolor{comment}{! Pointer to the vertical grid structure}
02783   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{pointer} :: US => null() \textcolor{comment}{! Pointer to a structure containing}
02784                                                    \textcolor{comment}{! various unit conversion factors}
02785   \textcolor{keywordtype}{type}(mom\_restart\_cs),    \textcolor{keywordtype}{pointer} :: restart\_CSp\_tmp => null()
02786   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable} :: z\_interface(:,:,:) \textcolor{comment}{! Interface heights [m]}
02787   \textcolor{keywordtype}{type}(vardesc) :: vd
02788 
02789   \textcolor{keyword}{call }cpu\_clock\_begin(\hyperlink{namespacemom_a7cf03c18244d0630616e925bab1841a2}{id\_clock\_init})
02790   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"finish\_MOM\_initialization()"})
02791 
02792   \textcolor{comment}{! Pointers for convenience}
02793   g => cs%G ; gv => cs%GV ; us => cs%US
02794 
02795   \textcolor{comment}{!### Move to initialize\_MOM?}
02796   \textcolor{keyword}{call }fix\_restart\_scaling(gv)
02797   \textcolor{keyword}{call }fix\_restart\_unit\_scaling(us)
02798 
02799   \textcolor{comment}{! Write initial conditions}
02800   \textcolor{keywordflow}{if} (cs%write\_IC) \textcolor{keywordflow}{then}
02801     \textcolor{keyword}{allocate}(restart\_csp\_tmp)
02802     restart\_csp\_tmp = restart\_csp
02803     \textcolor{keyword}{allocate}(z\_interface(szi\_(g),szj\_(g),szk\_(g)+1))
02804     \textcolor{keyword}{call }find\_eta(cs%h, cs%tv, g, gv, us, z\_interface, eta\_to\_m=1.0)
02805     \textcolor{keyword}{call }register\_restart\_field(z\_interface, \textcolor{stringliteral}{"eta"}, .true., restart\_csp\_tmp, &
02806                                 \textcolor{stringliteral}{"Interface heights"}, \textcolor{stringliteral}{"meter"}, z\_grid=\textcolor{stringliteral}{'i'})
02807 
02808     \textcolor{keyword}{call }save\_restart(dirs%output\_directory, time, cs%G\_in, &
02809                       restart\_csp\_tmp, filename=cs%IC\_file, gv=gv)
02810     \textcolor{keyword}{deallocate}(z\_interface)
02811     \textcolor{keyword}{deallocate}(restart\_csp\_tmp)
02812 \textcolor{keywordflow}{  endif}
02813 
02814   \textcolor{keyword}{call }write\_energy(cs%u, cs%v, cs%h, cs%tv, time, 0, g, gv, us, &
02815                     cs%sum\_output\_CSp, cs%tracer\_flow\_CSp)
02816 
02817   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"finish\_MOM\_initialization()"})
02818   \textcolor{keyword}{call }cpu\_clock\_end(\hyperlink{namespacemom_a7cf03c18244d0630616e925bab1841a2}{id\_clock\_init})
02819 
02820 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom_a2269d5cd79625cbf16cb916346379207}{finish\_mom\_initialization}
02821 \textcolor{comment}{}
02822 \textcolor{comment}{!> Register certain diagnostics}
02823 \textcolor{keyword}{subroutine }\hyperlink{namespacemom_af0f791729b0ccb6cb8ae2f4d28edee21}{register\_diags}(Time, G, GV, US, IDs, diag)
\Hypertarget{MOM_8F90_source_l02824}\hyperlink{namespacemom_af0f791729b0ccb6cb8ae2f4d28edee21}{02824}   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{  !< current model time}
02825   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{     !< ocean grid structure}
02826   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{    !< ocean vertical grid structure}
02827   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(inout)} :: US\textcolor{comment}{    !< A dimensional unit scaling type}
02828   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__diag__ids}{mom\_diag\_ids}),      \textcolor{keywordtype}{intent(inout)} :: IDs\textcolor{comment}{   !< A structure with the diagnostic IDs.}
02829   \textcolor{keywordtype}{type}(diag\_ctrl),         \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{  !< regulates diagnostic output}
02830 
02831   \textcolor{keywordtype}{real} :: H\_convert
02832   \textcolor{keywordtype}{character(len=48)} :: thickness\_units
02833 
02834   thickness\_units = get\_thickness\_units(gv)
02835   \textcolor{keywordflow}{if} (gv%Boussinesq) \textcolor{keywordflow}{then}
02836     h\_convert = gv%H\_to\_m
02837   \textcolor{keywordflow}{else}
02838     h\_convert = gv%H\_to\_kg\_m2
02839 \textcolor{keywordflow}{  endif}
02840 
02841   \textcolor{comment}{! Diagnostics of the rapidly varying dynamic state}
02842   ids%id\_u = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'u\_dyn'}, diag%axesCuL, time, &
02843       \textcolor{stringliteral}{'Zonal velocity after the dynamics update'}, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
02844   ids%id\_v = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'v\_dyn'}, diag%axesCvL, time, &
02845       \textcolor{stringliteral}{'Meridional velocity after the dynamics update'}, \textcolor{stringliteral}{'m s-1'}, conversion=us%L\_T\_to\_m\_s)
02846   ids%id\_h = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'h\_dyn'}, diag%axesTL, time, &
02847       \textcolor{stringliteral}{'Layer Thickness after the dynamics update'}, thickness\_units, &
02848       v\_extensive=.true., conversion=h\_convert)
02849   ids%id\_ssh\_inst = register\_diag\_field(\textcolor{stringliteral}{'ocean\_model'}, \textcolor{stringliteral}{'SSH\_inst'}, diag%axesT1, &
02850       time, \textcolor{stringliteral}{'Instantaneous Sea Surface Height'}, \textcolor{stringliteral}{'m'})
02851 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom_af0f791729b0ccb6cb8ae2f4d28edee21}{register\_diags}
02852 \textcolor{comment}{}
02853 \textcolor{comment}{!> Set up CPU clock IDs for timing various subroutines.}
02854 \textcolor{keyword}{subroutine }\hyperlink{namespacemom_ab57e47834591c651339770f7e51efe57}{mom\_timing\_init}(CS)
\Hypertarget{MOM_8F90_source_l02855}\hyperlink{namespacemom_ab57e47834591c651339770f7e51efe57}{02855}   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__control__struct}{mom\_control\_struct}), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{  !< control structure set up by
       initialize\_MOM.}
02856 
02857  \hyperlink{namespacemom_a2e9f4b71ee77ba5bcb3f03a863948db3}{id\_clock\_ocean}    = cpu\_clock\_id(\textcolor{stringliteral}{'Ocean'}, grain=clock\_component)
02858  \hyperlink{namespacemom_ae1cf2d523679b925a5e5baa9d974968c}{id\_clock\_dynamics} = cpu\_clock\_id(\textcolor{stringliteral}{'Ocean dynamics'}, grain=clock\_subcomponent)
02859  \hyperlink{namespacemom_a052256dfa3e56390f62ef3a826d62617}{id\_clock\_thermo}   = cpu\_clock\_id(\textcolor{stringliteral}{'Ocean thermodynamics and tracers'}, grain=
      clock\_subcomponent)
02860  \hyperlink{namespacemom_a283a5d32d799a3cd11113a05dcae2d56}{id\_clock\_other}    = cpu\_clock\_id(\textcolor{stringliteral}{'Ocean Other'}, grain=clock\_subcomponent)
02861  \hyperlink{namespacemom_a0fa4debacd02de6fcd066066c232adf3}{id\_clock\_tracer}   = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean tracer advection)'}, grain=clock\_module\_driver)
02862  \textcolor{keywordflow}{if} (.not.cs%adiabatic) \textcolor{keywordflow}{then}
02863    \hyperlink{namespacemom_a50edf00aa5998073d2db0360949253ba}{id\_clock\_diabatic} = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean diabatic driver)'}, grain=clock\_module\_driver)
02864  \textcolor{keywordflow}{else}
02865    \hyperlink{namespacemom_af865d838388a05163e8de8d266316d5f}{id\_clock\_adiabatic} = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean adiabatic driver)'}, grain=
      clock\_module\_driver)
02866 \textcolor{keywordflow}{ endif}
02867 
02868  \hyperlink{namespacemom_aa512b2d8dd73b02634e772701be07a87}{id\_clock\_continuity} = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean continuity equation *)'}, grain=clock\_module)
02869  \hyperlink{namespacemom_aa69e79e4c51e1c24c474b84311322251}{id\_clock\_bbl\_visc}   = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean set BBL viscosity)'}, grain=clock\_module)
02870  \hyperlink{namespacemom_a7af2f783166f32739569e4ed6ed6a98f}{id\_clock\_pass}       = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean message passing *)'}, grain=clock\_module)
02871  \hyperlink{namespacemom_a4180eb85bab39df7cbb72bb8e5b19fd4}{id\_clock\_mom\_init}   = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean MOM\_initialize\_state)'}, grain=clock\_module)
02872  \hyperlink{namespacemom_ac4d20612cad32d412dae492fedc2e971}{id\_clock\_pass\_init}  = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean init message passing *)'}, grain=clock\_routine
      )
02873  \textcolor{keywordflow}{if} (cs%thickness\_diffuse) &
02874    \hyperlink{namespacemom_a8f5feb87a0cb40d9fcee00456e982b8a}{id\_clock\_thick\_diff} = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean thickness diffusion *)'}, grain=
      clock\_module)
02875 \textcolor{comment}{!if (CS%mixedlayer\_restrat) &}
02876    \hyperlink{namespacemom_a41b67fabfc13e52cf3a5d1c337c780eb}{id\_clock\_ml\_restrat} = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean mixed layer restrat)'}, grain=clock\_module)
02877  \hyperlink{namespacemom_aa773fddb51f99098d75304eb271270d4}{id\_clock\_diagnostics}  = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean collective diagnostics)'}, grain=
      clock\_module)
02878  \hyperlink{namespacemom_a09f2ac3470372b9ee233f4cc5a7a0da1}{id\_clock\_z\_diag}       = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean Z-space diagnostics)'}, grain=clock\_module)
02879  \hyperlink{namespacemom_a722ed13d0e6d76852e680054a0e3c964}{id\_clock\_ale}          = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean ALE)'}, grain=clock\_module)
02880  \textcolor{keywordflow}{if} (cs%offline\_tracer\_mode) \textcolor{keywordflow}{then}
02881   \hyperlink{namespacemom_a2ab767469f0d918b9e479d8e0fde44b0}{id\_clock\_offline\_tracer} = cpu\_clock\_id(\textcolor{stringliteral}{'Ocean offline tracers'}, grain=
      clock\_subcomponent)
02882 \textcolor{keywordflow}{ endif}
02883 
02884 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom_ab57e47834591c651339770f7e51efe57}{mom\_timing\_init}
02885 \textcolor{comment}{}
02886 \textcolor{comment}{!> Set the fields that are needed for bitwise identical restarting}
02887 \textcolor{comment}{!! the time stepping scheme.  In addition to those specified here}
02888 \textcolor{comment}{!! directly, there may be fields related to the forcing or to the}
02889 \textcolor{comment}{!! barotropic solver that are needed; these are specified in sub-}
02890 \textcolor{comment}{!! routines that are called from this one.}
02891 \textcolor{comment}{!!}
02892 \textcolor{comment}{!! This routine should be altered if there are any changes to the}
02893 \textcolor{comment}{!! time stepping scheme.  The CHECK\_RESTART facility may be used to}
02894 \textcolor{comment}{!! confirm that all needed restart fields have been included.}
02895 \textcolor{keyword}{subroutine }\hyperlink{namespacemom_a76cb0af280a5c9e877dc206a6849b46b}{set\_restart\_fields}(GV, US, param\_file, CS, restart\_CSp)
\Hypertarget{MOM_8F90_source_l02896}\hyperlink{namespacemom_a76cb0af280a5c9e877dc206a6849b46b}{02896}   \textcolor{keywordtype}{type}(verticalgrid\_type),  \textcolor{keywordtype}{intent(inout)} :: GV\textcolor{comment}{         !< ocean vertical grid structure}
02897   \textcolor{keywordtype}{type}(unit\_scale\_type),    \textcolor{keywordtype}{intent(inout)} :: US\textcolor{comment}{         !< A dimensional unit scaling type}
02898   \textcolor{keywordtype}{type}(param\_file\_type),    \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{    !< opened file for parsing to get parameters}
02899   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__control__struct}{mom\_control\_struct}), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{            !< control structure set up by
       initialize\_MOM}
02900   \textcolor{keywordtype}{type}(mom\_restart\_cs),     \textcolor{keywordtype}{pointer}    :: restart\_CSp\textcolor{comment}{   !< pointer to the restart control}
02901 \textcolor{comment}{                                                        !! structure that will be used for MOM.}
02902   \textcolor{comment}{! Local variables}
02903   \textcolor{keywordtype}{logical} :: use\_ice\_shelf \textcolor{comment}{! Needed to determine whether to add CS%Hml to restarts}
02904   \textcolor{keywordtype}{character(len=48)} :: thickness\_units, flux\_units
02905   \textcolor{keywordtype}{type}(vardesc) :: u\_desc, v\_desc
02906 
02907   thickness\_units = get\_thickness\_units(gv)
02908   flux\_units = get\_flux\_units(gv)
02909 
02910   u\_desc = var\_desc(\textcolor{stringliteral}{"u"}, \textcolor{stringliteral}{"m s-1"}, \textcolor{stringliteral}{"Zonal velocity"}, hor\_grid=\textcolor{stringliteral}{'Cu'})
02911   v\_desc = var\_desc(\textcolor{stringliteral}{"v"}, \textcolor{stringliteral}{"m s-1"}, \textcolor{stringliteral}{"Meridional velocity"}, hor\_grid=\textcolor{stringliteral}{'Cv'})
02912 
02913   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tv%T)) &
02914     \textcolor{keyword}{call }register\_restart\_field(cs%tv%T, \textcolor{stringliteral}{"Temp"}, .true., restart\_csp, &
02915                                 \textcolor{stringliteral}{"Potential Temperature"}, \textcolor{stringliteral}{"degC"})
02916   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tv%S)) &
02917     \textcolor{keyword}{call }register\_restart\_field(cs%tv%S, \textcolor{stringliteral}{"Salt"}, .true., restart\_csp, &
02918                                 \textcolor{stringliteral}{"Salinity"}, \textcolor{stringliteral}{"PPT"})
02919 
02920   \textcolor{keyword}{call }register\_restart\_field(cs%h, \textcolor{stringliteral}{"h"}, .true., restart\_csp, &
02921                               \textcolor{stringliteral}{"Layer Thickness"}, thickness\_units)
02922 
02923   \textcolor{keyword}{call }register\_restart\_pair(cs%u, cs%v, u\_desc, v\_desc, .true., restart\_csp)
02924 
02925   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tv%frazil)) &
02926     \textcolor{keyword}{call }register\_restart\_field(cs%tv%frazil, \textcolor{stringliteral}{"frazil"}, .false., restart\_csp, &
02927                                 \textcolor{stringliteral}{"Frazil heat flux into ocean"}, \textcolor{stringliteral}{"J m-2"})
02928 
02929   \textcolor{keywordflow}{if} (cs%interp\_p\_surf) \textcolor{keywordflow}{then}
02930     \textcolor{keyword}{call }register\_restart\_field(cs%p\_surf\_prev, \textcolor{stringliteral}{"p\_surf\_prev"}, .false., restart\_csp, &
02931                                 \textcolor{stringliteral}{"Previous ocean surface pressure"}, \textcolor{stringliteral}{"Pa"})
02932 \textcolor{keywordflow}{  endif}
02933 
02934   \textcolor{keyword}{call }register\_restart\_field(cs%ave\_ssh\_ibc, \textcolor{stringliteral}{"ave\_ssh"}, .false., restart\_csp, &
02935                               \textcolor{stringliteral}{"Time average sea surface height"}, \textcolor{stringliteral}{"meter"})
02936 
02937   \textcolor{comment}{! hML is needed when using the ice shelf module}
02938   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{''}, \textcolor{stringliteral}{"ICE\_SHELF"}, use\_ice\_shelf, default=.false., &
02939                  do\_not\_log=.true.)
02940   \textcolor{keywordflow}{if} (use\_ice\_shelf .and. \textcolor{keyword}{associated}(cs%Hml)) \textcolor{keywordflow}{then}
02941     \textcolor{keyword}{call }register\_restart\_field(cs%Hml, \textcolor{stringliteral}{"hML"}, .false., restart\_csp, &
02942                                 \textcolor{stringliteral}{"Mixed layer thickness"}, \textcolor{stringliteral}{"meter"})
02943 \textcolor{keywordflow}{  endif}
02944 
02945   \textcolor{comment}{! Register scalar unit conversion factors.}
02946   \textcolor{keyword}{call }register\_restart\_field(us%m\_to\_Z\_restart, \textcolor{stringliteral}{"m\_to\_Z"}, .false., restart\_csp, &
02947                               \textcolor{stringliteral}{"Height unit conversion factor"}, \textcolor{stringliteral}{"Z meter-1"})
02948   \textcolor{keyword}{call }register\_restart\_field(gv%m\_to\_H\_restart, \textcolor{stringliteral}{"m\_to\_H"}, .false., restart\_csp, &
02949                               \textcolor{stringliteral}{"Thickness unit conversion factor"}, \textcolor{stringliteral}{"H meter-1"})
02950   \textcolor{keyword}{call }register\_restart\_field(us%m\_to\_L\_restart, \textcolor{stringliteral}{"m\_to\_L"}, .false., restart\_csp, &
02951                               \textcolor{stringliteral}{"Length unit conversion factor"}, \textcolor{stringliteral}{"L meter-1"})
02952   \textcolor{keyword}{call }register\_restart\_field(us%s\_to\_T\_restart, \textcolor{stringliteral}{"s\_to\_T"}, .false., restart\_csp, &
02953                               \textcolor{stringliteral}{"Time unit conversion factor"}, \textcolor{stringliteral}{"T second-1"})
02954   \textcolor{keyword}{call }register\_restart\_field(us%kg\_m3\_to\_R\_restart, \textcolor{stringliteral}{"kg\_m3\_to\_R"}, .false., restart\_csp, &
02955                               \textcolor{stringliteral}{"Density unit conversion factor"}, \textcolor{stringliteral}{"R m3 kg-1"})
02956   \textcolor{keyword}{call }register\_restart\_field(us%J\_kg\_to\_Q\_restart, \textcolor{stringliteral}{"J\_kg\_to\_Q"}, .false., restart\_csp, &
02957                               \textcolor{stringliteral}{"Heat content unit conversion factor."}, units=\textcolor{stringliteral}{"Q kg J-1"})
02958 
02959 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom_a76cb0af280a5c9e877dc206a6849b46b}{set\_restart\_fields}
02960 \textcolor{comment}{}
02961 \textcolor{comment}{!> Apply a correction to the sea surface height to compensate}
02962 \textcolor{comment}{!! for the atmospheric pressure (the inverse barometer).}
02963 \textcolor{keyword}{subroutine }\hyperlink{namespacemom_a16f7cc52cef3eb7a99687bf3d0694285}{adjust\_ssh\_for\_p\_atm}(tv, G, GV, US, ssh, p\_atm, use\_EOS)
\Hypertarget{MOM_8F90_source_l02964}\hyperlink{namespacemom_a16f7cc52cef3eb7a99687bf3d0694285}{02964}   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),             \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{  !< A structure pointing to various thermodynamic
       variables}
02965   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{   !< ocean grid structure}
02966   \textcolor{keywordtype}{type}(verticalgrid\_type),           \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{  !< ocean vertical grid structure}
02967   \textcolor{keywordtype}{type}(unit\_scale\_type),             \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}
02968   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))},  \textcolor{keywordtype}{intent(inout)} :: ssh\textcolor{comment}{ !< time mean surface height [m]}
02969   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: p\_atm\textcolor{comment}{ !< Ocean surface pressure [R L2 T-2 ~> Pa]}
02970   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: use\_EOS\textcolor{comment}{ !< If true, calculate the density for}
02971 \textcolor{comment}{                                                       !! the SSH correction using the equation of state.}
02972 
02973   \textcolor{keywordtype}{real} :: Rho\_conv(szi\_(g))  \textcolor{comment}{! The density used to convert surface pressure to}
02974                       \textcolor{comment}{! a corrected effective SSH [R ~> kg m-3].}
02975   \textcolor{keywordtype}{real} :: IgR0        \textcolor{comment}{! The SSH conversion factor from R L2 T-2 to m [m T2 R-1 L-2 ~> m Pa-1].}
02976   \textcolor{keywordtype}{logical} :: calc\_rho
02977   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: EOSdom \textcolor{comment}{! The i-computational domain for the equation of state}
02978   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je
02979 
02980   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
02981   eosdom(:) = eos\_domain(g%HI)
02982   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(p\_atm)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(p\_atm)) \textcolor{keywordflow}{then}
02983     calc\_rho = \textcolor{keyword}{associated}(tv%eqn\_of\_state)
02984     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(use\_eos) .and. calc\_rho) calc\_rho = use\_eos
02985     \textcolor{comment}{! Correct the output sea surface height for the contribution from the ice pressure.}
02986     \textcolor{keywordflow}{do} j=js,je
02987       \textcolor{keywordflow}{if} (calc\_rho) \textcolor{keywordflow}{then}
02988         \textcolor{keyword}{call }calculate\_density(tv%T(:,j,1), tv%S(:,j,1), 0.5*p\_atm(:,j), rho\_conv, &
02989                                tv%eqn\_of\_state, eosdom)
02990         \textcolor{keywordflow}{do} i=is,ie
02991           igr0 = us%Z\_to\_m / (rho\_conv(i) * gv%g\_Earth)
02992           ssh(i,j) = ssh(i,j) + p\_atm(i,j) * igr0
02993 \textcolor{keywordflow}{        enddo}
02994       \textcolor{keywordflow}{else}
02995         \textcolor{keywordflow}{do} i=is,ie
02996           ssh(i,j) = ssh(i,j) + p\_atm(i,j) * (us%Z\_to\_m / (gv%Rho0 * gv%g\_Earth))
02997 \textcolor{keywordflow}{        enddo}
02998 \textcolor{keywordflow}{      endif}
02999 \textcolor{keywordflow}{    enddo}
03000 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
03001 
03002 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom_a16f7cc52cef3eb7a99687bf3d0694285}{adjust\_ssh\_for\_p\_atm}
03003 \textcolor{comment}{}
03004 \textcolor{comment}{!> Set the surface (return) properties of the ocean model by}
03005 \textcolor{comment}{!! setting the appropriate fields in sfc\_state.  Unused fields}
03006 \textcolor{comment}{!! are set to NULL or are unallocated.}
03007 \textcolor{keyword}{subroutine }\hyperlink{namespacemom_a699d6c5bfb5b9dcdaa03c18806fa824e}{extract\_surface\_state}(CS, sfc\_state\_in)
\Hypertarget{MOM_8F90_source_l03008}\hyperlink{namespacemom_a699d6c5bfb5b9dcdaa03c18806fa824e}{03008}   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__control__struct}{mom\_control\_struct}), \textcolor{keywordtype}{pointer}    :: CS\textcolor{comment}{ !< Master MOM control structure}
03009   \textcolor{keywordtype}{type}(surface), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(inout)} :: sfc\_state\_in\textcolor{comment}{ !< transparent ocean surface state}
03010 \textcolor{comment}{                                             !! structure shared with the calling routine}
03011 \textcolor{comment}{                                             !! data in this structure is intent out.}
03012 
03013   \textcolor{comment}{! Local variables}
03014   \textcolor{keywordtype}{real} :: hu, hv  \textcolor{comment}{! Thicknesses interpolated to velocity points [H ~> m or kg m-2]}
03015   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer} :: G => null() \textcolor{comment}{!< pointer to a structure containing}
03016 \textcolor{comment}{                                                  !! metrics and related information}
03017   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer} :: G\_in => null() \textcolor{comment}{!< Input grid metric}
03018   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{pointer} :: GV => null() \textcolor{comment}{!< structure containing vertical grid info}
03019   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{pointer} :: US => null() \textcolor{comment}{!< structure containing various unit conversion factors}
03020   \textcolor{keywordtype}{type}(surface),           \textcolor{keywordtype}{pointer} :: sfc\_state => null()  \textcolor{comment}{! surface state on the model grid}
03021   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)},  \textcolor{keywordtype}{pointer} :: &
03022     h => null()    \textcolor{comment}{!< h : layer thickness [H ~> m or kg m-2]}
03023   \textcolor{keywordtype}{real} :: depth(szi\_(cs%g))\textcolor{comment}{  !< Distance from the surface in depth units [Z ~> m] or [H ~> m or kg m-2]}
03024   \textcolor{keywordtype}{real} :: depth\_ml\textcolor{comment}{           !< Depth over which to average to determine mixed}
03025 \textcolor{comment}{                             !! layer properties [Z ~> m] or [H ~> m or kg m-2]}
03026   \textcolor{keywordtype}{real} :: dh\textcolor{comment}{                 !< Thickness of a layer within the mixed layer [Z ~> m] or [H ~> m or kg m-2]}
03027   \textcolor{keywordtype}{real} :: mass\textcolor{comment}{               !< Mass per unit area of a layer [R Z ~> kg m-2]}
03028   \textcolor{keywordtype}{real} :: T\_freeze\textcolor{comment}{           !< freezing temperature [degC]}
03029   \textcolor{keywordtype}{real} :: I\_depth\textcolor{comment}{            !< The inverse of depth [Z-1 ~> m-1] or [H-1 ~> m-1 or m2 kg-1]}
03030   \textcolor{keywordtype}{real} :: missing\_depth\textcolor{comment}{      !< The portion of depth\_ml that can not be found in a column [H ~> m or kg
       m-2]}
03031   \textcolor{keywordtype}{real} :: H\_rescale\textcolor{comment}{          !< A conversion factor from thickness units to the units used in the}
03032 \textcolor{comment}{                             !! calculation of properties of the uppermost ocean [nondim] or [Z H-1 ~> 1 or
       m3 kg-1]}
03033                              \textcolor{comment}{!  After the ANSWERS\_2018 flag has been obsoleted, H\_rescale will be 1.}
03034   \textcolor{keywordtype}{real} :: delT(szi\_(cs%g))\textcolor{comment}{   !< Depth integral of T-T\_freeze [Z degC ~> m degC]}
03035   \textcolor{keywordtype}{logical} :: use\_temperature\textcolor{comment}{ !< If true, temp and saln used as state variables.}
03036   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz, numberOfErrors, ig, jg
03037   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed
03038   \textcolor{keywordtype}{integer} :: iscB, iecB, jscB, jecB, isdB, iedB, jsdB, jedB
03039   \textcolor{keywordtype}{logical} :: localError
03040   \textcolor{keywordtype}{character(240)} :: msg
03041   \textcolor{keywordtype}{integer} :: turns    \textcolor{comment}{! Number of quarter turns}
03042 
03043   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"extract\_surface\_state(), MOM.F90"})
03044   g => cs%G ; g\_in => cs%G\_in ; gv => cs%GV ; us => cs%US
03045   is  = g%isc ; ie  = g%iec ; js  = g%jsc ; je  = g%jec ; nz = gv%ke
03046   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
03047   iscb = g%iscB ; iecb = g%iecB; jscb = g%jscB ; jecb = g%jecB
03048   isdb = g%isdB ; iedb = g%iedB; jsdb = g%jsdB ; jedb = g%jedB
03049   h => cs%h
03050 
03051   use\_temperature = \textcolor{keyword}{associated}(cs%tv%T)
03052 
03053   turns = 0
03054   \textcolor{keywordflow}{if} (cs%rotate\_index) &
03055     turns = g%HI%turns
03056 
03057   \textcolor{keywordflow}{if} (.not.sfc\_state\_in%arrays\_allocated) &
03058     \textcolor{comment}{!  Consider using a run-time flag to determine whether to do the vertical}
03059     \textcolor{comment}{! integrals, since the 3-d sums are not negligible in cost.}
03060     \textcolor{keyword}{call }allocate\_surface\_state(sfc\_state\_in, g\_in, use\_temperature, &
03061         do\_integrals=.true., omit\_frazil=.not.\textcolor{keyword}{associated}(cs%tv%frazil))
03062 
03063   \textcolor{keywordflow}{if} (cs%rotate\_index) \textcolor{keywordflow}{then}
03064     \textcolor{keyword}{allocate}(sfc\_state)
03065     \textcolor{keyword}{call }allocate\_surface\_state(sfc\_state, g, use\_temperature, &
03066         do\_integrals=.true., omit\_frazil=.not.\textcolor{keyword}{associated}(cs%tv%frazil))
03067   \textcolor{keywordflow}{else}
03068     sfc\_state => sfc\_state\_in
03069 \textcolor{keywordflow}{  endif}
03070 
03071   sfc\_state%T\_is\_conT = cs%tv%T\_is\_conT
03072   sfc\_state%S\_is\_absS = cs%tv%S\_is\_absS
03073 
03074   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
03075     sfc\_state%sea\_lev(i,j) = us%m\_to\_Z*cs%ave\_ssh\_ibc(i,j)
03076 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
03077 
03078   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state%frazil) .and. \textcolor{keyword}{associated}(cs%tv%frazil)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
03079     sfc\_state%frazil(i,j) = cs%tv%frazil(i,j)
03080 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
03081 
03082   \textcolor{comment}{! copy Hml into sfc\_state, so that caps can access it}
03083   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%Hml)) \textcolor{keywordflow}{then}
03084     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
03085       sfc\_state%Hml(i,j) = cs%Hml(i,j)
03086 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
03087 \textcolor{keywordflow}{  endif}
03088 
03089   \textcolor{keywordflow}{if} (cs%Hmix < 0.0) \textcolor{keywordflow}{then}  \textcolor{comment}{! A bulk mixed layer is in use, so layer 1 has the properties}
03090     \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
03091       sfc\_state%SST(i,j) = cs%tv%T(i,j,1)
03092       sfc\_state%SSS(i,j) = cs%tv%S(i,j,1)
03093 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}
03094     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
03095       sfc\_state%u(i,j) = cs%u(i,j,1)
03096 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
03097     \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
03098       sfc\_state%v(i,j) = cs%v(i,j,1)
03099 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
03100 
03101   \textcolor{keywordflow}{else}  \textcolor{comment}{! (CS%Hmix >= 0.0)}
03102     h\_rescale = 1.0 ; \textcolor{keywordflow}{if} (cs%answers\_2018) h\_rescale = gv%H\_to\_Z
03103     depth\_ml = cs%Hmix
03104     \textcolor{keywordflow}{if} (.not.cs%answers\_2018) depth\_ml = cs%Hmix*gv%Z\_to\_H
03105     \textcolor{comment}{! Determine the mean tracer properties of the uppermost depth\_ml fluid.}
03106 
03107     \textcolor{comment}{!$OMP parallel do default(shared) private(depth,dh)}
03108     \textcolor{keywordflow}{do} j=js,je
03109       \textcolor{keywordflow}{do} i=is,ie
03110         depth(i) = 0.0
03111         \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
03112           sfc\_state%SST(i,j) = 0.0 ; sfc\_state%SSS(i,j) = 0.0
03113         \textcolor{keywordflow}{else}
03114           sfc\_state%sfc\_density(i,j) = 0.0
03115 \textcolor{keywordflow}{        endif}
03116 \textcolor{keywordflow}{      enddo}
03117 
03118       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie
03119         \textcolor{keywordflow}{if} (depth(i) + h(i,j,k)*h\_rescale < depth\_ml) \textcolor{keywordflow}{then}
03120           dh = h(i,j,k)*h\_rescale
03121         \textcolor{keywordflow}{elseif} (depth(i) < depth\_ml) \textcolor{keywordflow}{then}
03122           dh = depth\_ml - depth(i)
03123         \textcolor{keywordflow}{else}
03124           dh = 0.0
03125 \textcolor{keywordflow}{        endif}
03126         \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
03127           sfc\_state%SST(i,j) = sfc\_state%SST(i,j) + dh * cs%tv%T(i,j,k)
03128           sfc\_state%SSS(i,j) = sfc\_state%SSS(i,j) + dh * cs%tv%S(i,j,k)
03129         \textcolor{keywordflow}{else}
03130           sfc\_state%sfc\_density(i,j) = sfc\_state%sfc\_density(i,j) + dh * gv%Rlay(k)
03131 \textcolor{keywordflow}{        endif}
03132         depth(i) = depth(i) + dh
03133 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
03134   \textcolor{comment}{! Calculate the average properties of the mixed layer depth.}
03135       \textcolor{keywordflow}{do} i=is,ie
03136         \textcolor{keywordflow}{if} (cs%answers\_2018) \textcolor{keywordflow}{then}
03137           \textcolor{keywordflow}{if} (depth(i) < gv%H\_subroundoff*h\_rescale) &
03138               depth(i) = gv%H\_subroundoff*h\_rescale
03139           \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
03140             sfc\_state%SST(i,j) = sfc\_state%SST(i,j) / depth(i)
03141             sfc\_state%SSS(i,j) = sfc\_state%SSS(i,j) / depth(i)
03142           \textcolor{keywordflow}{else}
03143             sfc\_state%sfc\_density(i,j) = sfc\_state%sfc\_density(i,j) / depth(i)
03144 \textcolor{keywordflow}{          endif}
03145         \textcolor{keywordflow}{else}
03146           \textcolor{keywordflow}{if} (depth(i) < gv%H\_subroundoff*h\_rescale) \textcolor{keywordflow}{then}
03147             i\_depth = 1.0 / (gv%H\_subroundoff*h\_rescale)
03148             missing\_depth = gv%H\_subroundoff*h\_rescale - depth(i)
03149             \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
03150               sfc\_state%SST(i,j) = (sfc\_state%SST(i,j) + missing\_depth*cs%tv%T(i,j,1)) * i\_depth
03151               sfc\_state%SSS(i,j) = (sfc\_state%SSS(i,j) + missing\_depth*cs%tv%S(i,j,1)) * i\_depth
03152             \textcolor{keywordflow}{else}
03153               sfc\_state%sfc\_density(i,j) = (sfc\_state%sfc\_density(i,j) + &
03154                                             missing\_depth*gv%Rlay(1)) * i\_depth
03155 \textcolor{keywordflow}{            endif}
03156           \textcolor{keywordflow}{else}
03157             i\_depth = 1.0 / depth(i)
03158             \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
03159               sfc\_state%SST(i,j) = sfc\_state%SST(i,j) * i\_depth
03160               sfc\_state%SSS(i,j) = sfc\_state%SSS(i,j) * i\_depth
03161             \textcolor{keywordflow}{else}
03162               sfc\_state%sfc\_density(i,j) = sfc\_state%sfc\_density(i,j) * i\_depth
03163 \textcolor{keywordflow}{            endif}
03164 \textcolor{keywordflow}{          endif}
03165 \textcolor{keywordflow}{        endif}
03166 \textcolor{keywordflow}{      enddo}
03167 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! end of j loop}
03168 
03169 \textcolor{comment}{!   Determine the mean velocities in the uppermost depth\_ml fluid.}
03170     \textcolor{comment}{! NOTE: Velocity loops start on `[ij]s-1` in order to update halo values}
03171     \textcolor{comment}{!       required by the speed diagnostic on the non-symmetric grid.}
03172     \textcolor{comment}{!       This assumes that u and v halos have already been updated.}
03173     \textcolor{keywordflow}{if} (cs%Hmix\_UV>0.) \textcolor{keywordflow}{then}
03174       depth\_ml = cs%Hmix\_UV
03175       \textcolor{keywordflow}{if} (.not.cs%answers\_2018) depth\_ml = cs%Hmix\_UV*gv%Z\_to\_H
03176       \textcolor{comment}{!$OMP parallel do default(shared) private(depth,dh,hv)}
03177       \textcolor{keywordflow}{do} j=js-1,ie
03178         \textcolor{keywordflow}{do} i=is,ie
03179           depth(i) = 0.0
03180           sfc\_state%v(i,j) = 0.0
03181 \textcolor{keywordflow}{        enddo}
03182         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie
03183           hv = 0.5 * (h(i,j,k) + h(i,j+1,k)) * h\_rescale
03184           \textcolor{keywordflow}{if} (depth(i) + hv < depth\_ml) \textcolor{keywordflow}{then}
03185             dh = hv
03186           \textcolor{keywordflow}{elseif} (depth(i) < depth\_ml) \textcolor{keywordflow}{then}
03187             dh = depth\_ml - depth(i)
03188           \textcolor{keywordflow}{else}
03189             dh = 0.0
03190 \textcolor{keywordflow}{          endif}
03191           sfc\_state%v(i,j) = sfc\_state%v(i,j) + dh * cs%v(i,j,k)
03192           depth(i) = depth(i) + dh
03193 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
03194         \textcolor{comment}{! Calculate the average properties of the mixed layer depth.}
03195         \textcolor{keywordflow}{do} i=is,ie
03196           sfc\_state%v(i,j) = sfc\_state%v(i,j) / max(depth(i), gv%H\_subroundoff*h\_rescale)
03197 \textcolor{keywordflow}{        enddo}
03198 \textcolor{keywordflow}{      enddo} \textcolor{comment}{! end of j loop}
03199 
03200       \textcolor{comment}{!$OMP parallel do default(shared) private(depth,dh,hu)}
03201       \textcolor{keywordflow}{do} j=js,je
03202         \textcolor{keywordflow}{do} i=is-1,ie
03203           depth(i) = 0.0
03204           sfc\_state%u(i,j) = 0.0
03205 \textcolor{keywordflow}{        enddo}
03206         \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is-1,ie
03207           hu = 0.5 * (h(i,j,k) + h(i+1,j,k)) * h\_rescale
03208           \textcolor{keywordflow}{if} (depth(i) + hu < depth\_ml) \textcolor{keywordflow}{then}
03209             dh = hu
03210           \textcolor{keywordflow}{elseif} (depth(i) < depth\_ml) \textcolor{keywordflow}{then}
03211             dh = depth\_ml - depth(i)
03212           \textcolor{keywordflow}{else}
03213             dh = 0.0
03214 \textcolor{keywordflow}{          endif}
03215           sfc\_state%u(i,j) = sfc\_state%u(i,j) + dh * cs%u(i,j,k)
03216           depth(i) = depth(i) + dh
03217 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
03218         \textcolor{comment}{! Calculate the average properties of the mixed layer depth.}
03219         \textcolor{keywordflow}{do} i=is-1,ie
03220           sfc\_state%u(i,j) = sfc\_state%u(i,j) / max(depth(i), gv%H\_subroundoff*h\_rescale)
03221 \textcolor{keywordflow}{        enddo}
03222 \textcolor{keywordflow}{      enddo} \textcolor{comment}{! end of j loop}
03223     \textcolor{keywordflow}{else} \textcolor{comment}{! Hmix\_UV<=0.}
03224       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
03225         sfc\_state%u(i,j) = cs%u(i,j,1)
03226 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
03227       \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
03228         sfc\_state%v(i,j) = cs%v(i,j,1)
03229 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
03230 \textcolor{keywordflow}{    endif}
03231 \textcolor{keywordflow}{  endif}  \textcolor{comment}{! (CS%Hmix >= 0.0)}
03232 
03233 
03234   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state%melt\_potential)) \textcolor{keywordflow}{then}
03235     \textcolor{comment}{!$OMP parallel do default(shared) private(depth\_ml, dh, T\_freeze, depth, delT)}
03236     \textcolor{keywordflow}{do} j=js,je
03237       \textcolor{keywordflow}{do} i=is,ie
03238         depth(i) = 0.0
03239         delt(i) = 0.0
03240 \textcolor{keywordflow}{      enddo}
03241 
03242       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie
03243         depth\_ml = min(cs%HFrz, cs%visc%MLD(i,j))
03244         \textcolor{keywordflow}{if} (depth(i) + h(i,j,k)*gv%H\_to\_Z < depth\_ml) \textcolor{keywordflow}{then}
03245           dh = h(i,j,k)*gv%H\_to\_Z
03246         \textcolor{keywordflow}{elseif} (depth(i) < depth\_ml) \textcolor{keywordflow}{then}
03247           dh = depth\_ml - depth(i)
03248         \textcolor{keywordflow}{else}
03249           dh = 0.0
03250 \textcolor{keywordflow}{        endif}
03251 
03252         \textcolor{comment}{! p=0 OK, HFrz ~ 10 to 20m}
03253         \textcolor{keyword}{call }calculate\_tfreeze(cs%tv%S(i,j,k), 0.0, t\_freeze, cs%tv%eqn\_of\_state)
03254         depth(i) = depth(i) + dh
03255         delt(i) =  delt(i) + dh * (cs%tv%T(i,j,k) - t\_freeze)
03256 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
03257 
03258       \textcolor{keywordflow}{do} i=is,ie
03259        \textcolor{comment}{! set melt\_potential to zero to avoid passing previous values}
03260        sfc\_state%melt\_potential(i,j) = 0.0
03261 
03262        \textcolor{keywordflow}{if} (g%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}
03263          \textcolor{comment}{! instantaneous melt\_potential [Q R Z ~> J m-2]}
03264          sfc\_state%melt\_potential(i,j) = cs%tv%C\_p * gv%Rho0 * delt(i)
03265 \textcolor{keywordflow}{       endif}
03266 \textcolor{keywordflow}{      enddo}
03267 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! end of j loop}
03268 \textcolor{keywordflow}{  endif}   \textcolor{comment}{! melt\_potential}
03269 
03270   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state%salt\_deficit) .and. \textcolor{keyword}{associated}(cs%tv%salt\_deficit)) \textcolor{keywordflow}{then}
03271     \textcolor{comment}{!$OMP parallel do default(shared)}
03272     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
03273       \textcolor{comment}{! Convert from gSalt to kgSalt}
03274       sfc\_state%salt\_deficit(i,j) = 0.001 * cs%tv%salt\_deficit(i,j)
03275 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
03276 \textcolor{keywordflow}{  endif}
03277   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state%TempxPmE) .and. \textcolor{keyword}{associated}(cs%tv%TempxPmE)) \textcolor{keywordflow}{then}
03278     \textcolor{comment}{!$OMP parallel do default(shared)}
03279     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
03280       sfc\_state%TempxPmE(i,j) = cs%tv%TempxPmE(i,j)
03281 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
03282 \textcolor{keywordflow}{  endif}
03283   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state%internal\_heat) .and. \textcolor{keyword}{associated}(cs%tv%internal\_heat)) \textcolor{keywordflow}{then}
03284     \textcolor{comment}{!$OMP parallel do default(shared)}
03285     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
03286       sfc\_state%internal\_heat(i,j) = cs%tv%internal\_heat(i,j)
03287 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
03288 \textcolor{keywordflow}{  endif}
03289   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state%taux\_shelf) .and. \textcolor{keyword}{associated}(cs%visc%taux\_shelf)) \textcolor{keywordflow}{then}
03290     \textcolor{comment}{!$OMP parallel do default(shared)}
03291     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is-1,ie
03292       sfc\_state%taux\_shelf(i,j) = cs%visc%taux\_shelf(i,j)
03293 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
03294 \textcolor{keywordflow}{  endif}
03295   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state%tauy\_shelf) .and. \textcolor{keyword}{associated}(cs%visc%tauy\_shelf)) \textcolor{keywordflow}{then}
03296     \textcolor{comment}{!$OMP parallel do default(shared)}
03297     \textcolor{keywordflow}{do} j=js-1,je ; \textcolor{keywordflow}{do} i=is,ie
03298       sfc\_state%tauy\_shelf(i,j) = cs%visc%tauy\_shelf(i,j)
03299 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
03300 \textcolor{keywordflow}{  endif}
03301 
03302   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state%ocean\_mass) .and. \textcolor{keyword}{allocated}(sfc\_state%ocean\_heat) .and. &
03303       \textcolor{keyword}{allocated}(sfc\_state%ocean\_salt)) \textcolor{keywordflow}{then}
03304     \textcolor{comment}{!$OMP parallel do default(shared)}
03305     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
03306       sfc\_state%ocean\_mass(i,j) = 0.0
03307       sfc\_state%ocean\_heat(i,j) = 0.0 ; sfc\_state%ocean\_salt(i,j) = 0.0
03308 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
03309     \textcolor{comment}{!$OMP parallel do default(shared) private(mass)}
03310     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nz; \textcolor{keywordflow}{do} i=is,ie
03311       mass = gv%H\_to\_RZ*h(i,j,k)
03312       sfc\_state%ocean\_mass(i,j) = sfc\_state%ocean\_mass(i,j) + mass
03313       sfc\_state%ocean\_heat(i,j) = sfc\_state%ocean\_heat(i,j) + mass * cs%tv%T(i,j,k)
03314       sfc\_state%ocean\_salt(i,j) = sfc\_state%ocean\_salt(i,j) + mass * (1.0e-3*cs%tv%S(i,j,k))
03315 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
03316   \textcolor{keywordflow}{else}
03317     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state%ocean\_mass)) \textcolor{keywordflow}{then}
03318       \textcolor{comment}{!$OMP parallel do default(shared)}
03319       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; sfc\_state%ocean\_mass(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
03320       \textcolor{comment}{!$OMP parallel do default(shared)}
03321       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie
03322         sfc\_state%ocean\_mass(i,j) = sfc\_state%ocean\_mass(i,j) + gv%H\_to\_RZ*h(i,j,k)
03323 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
03324 \textcolor{keywordflow}{    endif}
03325     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state%ocean\_heat)) \textcolor{keywordflow}{then}
03326       \textcolor{comment}{!$OMP parallel do default(shared)}
03327       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; sfc\_state%ocean\_heat(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
03328       \textcolor{comment}{!$OMP parallel do default(shared) private(mass)}
03329       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie
03330         mass = gv%H\_to\_RZ*h(i,j,k)
03331         sfc\_state%ocean\_heat(i,j) = sfc\_state%ocean\_heat(i,j) + mass*cs%tv%T(i,j,k)
03332 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
03333 \textcolor{keywordflow}{    endif}
03334     \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(sfc\_state%ocean\_salt)) \textcolor{keywordflow}{then}
03335       \textcolor{comment}{!$OMP parallel do default(shared)}
03336       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; sfc\_state%ocean\_salt(i,j) = 0.0 ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
03337       \textcolor{comment}{!$OMP parallel do default(shared) private(mass)}
03338       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie
03339         mass = gv%H\_to\_RZ*h(i,j,k)
03340         sfc\_state%ocean\_salt(i,j) = sfc\_state%ocean\_salt(i,j) + mass * (1.0e-3*cs%tv%S(i,j,k))
03341 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
03342 \textcolor{keywordflow}{    endif}
03343 \textcolor{keywordflow}{  endif}
03344 
03345   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tracer\_flow\_CSp)) \textcolor{keywordflow}{then}
03346     \textcolor{keyword}{call }call\_tracer\_surface\_state(sfc\_state, h, g, cs%tracer\_flow\_CSp)
03347 \textcolor{keywordflow}{  endif}
03348 
03349   \textcolor{keywordflow}{if} (cs%check\_bad\_sfc\_vals) \textcolor{keywordflow}{then}
03350     numberoferrors=0 \textcolor{comment}{! count number of errors}
03351     \textcolor{keywordflow}{do} j=js,je; \textcolor{keywordflow}{do} i=is,ie
03352       \textcolor{keywordflow}{if} (g%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}
03353         localerror = sfc\_state%sea\_lev(i,j) <= -g%bathyT(i,j) &
03354                 .or. sfc\_state%sea\_lev(i,j) >=  cs%bad\_val\_ssh\_max  &
03355                 .or. sfc\_state%sea\_lev(i,j) <= -cs%bad\_val\_ssh\_max  &
03356                 .or. sfc\_state%sea\_lev(i,j) + g%bathyT(i,j) < cs%bad\_val\_col\_thick
03357         \textcolor{keywordflow}{if} (use\_temperature) localerror = localerror &
03358                 .or. sfc\_state%SSS(i,j)<0.                        &
03359                 .or. sfc\_state%SSS(i,j)>=cs%bad\_val\_sss\_max       &
03360                 .or. sfc\_state%SST(i,j)< cs%bad\_val\_sst\_min       &
03361                 .or. sfc\_state%SST(i,j)>=cs%bad\_val\_sst\_max
03362         \textcolor{keywordflow}{if} (localerror) \textcolor{keywordflow}{then}
03363           numberoferrors=numberoferrors+1
03364           \textcolor{keywordflow}{if} (numberoferrors<9) \textcolor{keywordflow}{then} \textcolor{comment}{! Only report details for the first few errors}
03365             ig = i + g%HI%idg\_offset \textcolor{comment}{! Global i-index}
03366             jg = j + g%HI%jdg\_offset \textcolor{comment}{! Global j-index}
03367             \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
03368               \textcolor{keyword}{write}(msg(1:240),\textcolor{stringliteral}{'(2(a,i4,x),4(a,f8.3,x),8(a,es11.4,x))'}) &
03369                 \textcolor{stringliteral}{'Extreme surface sfc\_state detected: i='},ig,\textcolor{stringliteral}{'j='},jg, &
03370                 \textcolor{stringliteral}{'lon='},g%geoLonT(i,j), \textcolor{stringliteral}{'lat='},g%geoLatT(i,j), &
03371                 \textcolor{stringliteral}{'x='},g%gridLonT(ig), \textcolor{stringliteral}{'y='},g%gridLatT(jg), &
03372                 \textcolor{stringliteral}{'D='},cs%US%Z\_to\_m*g%bathyT(i,j),  \textcolor{stringliteral}{'SSH='},cs%US%Z\_to\_m*sfc\_state%sea\_lev(i,j), &
03373                 \textcolor{stringliteral}{'SST='},sfc\_state%SST(i,j), \textcolor{stringliteral}{'SSS='},sfc\_state%SSS(i,j), &
03374                 \textcolor{stringliteral}{'U-='},us%L\_T\_to\_m\_s*sfc\_state%u(i-1,j), \textcolor{stringliteral}{'U+='},us%L\_T\_to\_m\_s*sfc\_state%u(i,j), &
03375                 \textcolor{stringliteral}{'V-='},us%L\_T\_to\_m\_s*sfc\_state%v(i,j-1), \textcolor{stringliteral}{'V+='},us%L\_T\_to\_m\_s*sfc\_state%v(i,j)
03376             \textcolor{keywordflow}{else}
03377               \textcolor{keyword}{write}(msg(1:240),\textcolor{stringliteral}{'(2(a,i4,x),4(a,f8.3,x),6(a,es11.4))'}) &
03378                 \textcolor{stringliteral}{'Extreme surface sfc\_state detected: i='},ig,\textcolor{stringliteral}{'j='},jg, &
03379                 \textcolor{stringliteral}{'lon='},g%geoLonT(i,j), \textcolor{stringliteral}{'lat='},g%geoLatT(i,j), &
03380                 \textcolor{stringliteral}{'x='},g%gridLonT(i), \textcolor{stringliteral}{'y='},g%gridLatT(j), &
03381                 \textcolor{stringliteral}{'D='},cs%US%Z\_to\_m*g%bathyT(i,j),  \textcolor{stringliteral}{'SSH='},cs%US%Z\_to\_m*sfc\_state%sea\_lev(i,j), &
03382                 \textcolor{stringliteral}{'U-='},us%L\_T\_to\_m\_s*sfc\_state%u(i-1,j), \textcolor{stringliteral}{'U+='},us%L\_T\_to\_m\_s*sfc\_state%u(i,j), &
03383                 \textcolor{stringliteral}{'V-='},us%L\_T\_to\_m\_s*sfc\_state%v(i,j-1), \textcolor{stringliteral}{'V+='},us%L\_T\_to\_m\_s*sfc\_state%v(i,j)
03384 \textcolor{keywordflow}{            endif}
03385             \textcolor{keyword}{call }mom\_error(warning, trim(msg), all\_print=.true.)
03386           \textcolor{keywordflow}{elseif} (numberoferrors==9) \textcolor{keywordflow}{then} \textcolor{comment}{! Indicate once that there are more errors}
03387             \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{'There were more unreported extreme events!'}, all\_print=.true.)
03388 \textcolor{keywordflow}{          endif} \textcolor{comment}{! numberOfErrors}
03389 \textcolor{keywordflow}{        endif} \textcolor{comment}{! localError}
03390 \textcolor{keywordflow}{      endif} \textcolor{comment}{! mask2dT}
03391 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
03392     \textcolor{keyword}{call }sum\_across\_pes(numberoferrors)
03393     \textcolor{keywordflow}{if} (numberoferrors>0) \textcolor{keywordflow}{then}
03394       \textcolor{keyword}{write}(msg(1:240),\textcolor{stringliteral}{'(3(a,i9,x))'}) \textcolor{stringliteral}{'There were a total of '},numberoferrors, &
03395           \textcolor{stringliteral}{'locations detected with extreme surface values!'}
03396       \textcolor{keyword}{call }mom\_error(fatal, trim(msg))
03397 \textcolor{keywordflow}{    endif}
03398 \textcolor{keywordflow}{  endif}
03399 
03400   \textcolor{keywordflow}{if} (cs%debug) \textcolor{keyword}{call }mom\_surface\_chksum(\textcolor{stringliteral}{"Post extract\_sfc"}, sfc\_state, g, us, haloshift=0)
03401 
03402   \textcolor{comment}{! Rotate sfc\_state back onto the input grid, sfc\_state\_in}
03403   \textcolor{keywordflow}{if} (cs%rotate\_index) \textcolor{keywordflow}{then}
03404     \textcolor{keyword}{call }rotate\_surface\_state(sfc\_state, g, sfc\_state\_in, g\_in, -turns)
03405     \textcolor{keyword}{call }deallocate\_surface\_state(sfc\_state)
03406 \textcolor{keywordflow}{  endif}
03407 
03408   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"extract\_surface\_sfc\_state()"})
03409 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom_a699d6c5bfb5b9dcdaa03c18806fa824e}{extract\_surface\_state}
03410 \textcolor{comment}{}
03411 \textcolor{comment}{!> Rotate initialization fields from input to rotated arrays.}
03412 \textcolor{keyword}{subroutine }\hyperlink{namespacemom_a8f5160e583b599050515b8fe5575aa15}{rotate\_initial\_state}(u\_in, v\_in, h\_in, T\_in, S\_in, &
03413     use\_temperature, turns, u, v, h, T, S)
\Hypertarget{MOM_8F90_source_l03414}\hyperlink{namespacemom_a8f5160e583b599050515b8fe5575aa15}{03414}   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{intent(in)} :: u\_in, v\_in, h\_in, T\_in, S\_in
03415   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{intent(in)} :: use\_temperature
03416   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: turns
03417   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{intent(out)} :: u, v, h, T, S
03418 
03419   \textcolor{keyword}{call }rotate\_vector(u\_in, v\_in, turns, u, v)
03420   \textcolor{keyword}{call }rotate\_array(h\_in, turns, h)
03421   \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
03422     \textcolor{keyword}{call }rotate\_array(t\_in, turns, t)
03423     \textcolor{keyword}{call }rotate\_array(s\_in, turns, s)
03424 \textcolor{keywordflow}{  endif}
03425 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom_a8f5160e583b599050515b8fe5575aa15}{rotate\_initial\_state}
03426 \textcolor{comment}{}
03427 \textcolor{comment}{!> Return true if all phases of step\_MOM are at the same point in time.}
03428 \textcolor{keyword}{function }\hyperlink{namespacemom_ada38a8329b76f9fa1685a230869a7647}{mom\_state\_is\_synchronized}(CS, adv\_dyn) \textcolor{keyword}{result}(in\_synch)
\Hypertarget{MOM_8F90_source_l03429}\hyperlink{namespacemom_ada38a8329b76f9fa1685a230869a7647}{03429}   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__control__struct}{mom\_control\_struct}), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< MOM control structure}
03430   \textcolor{keywordtype}{logical},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: adv\_dyn\textcolor{comment}{  !< If present and true, only check}
03431 \textcolor{comment}{                                          !! whether the advection is up-to-date with}
03432 \textcolor{comment}{                                          !! the dynamics.}
03433   \textcolor{keywordtype}{logical} :: in\_synch\textcolor{comment}{ !< True if all phases of the update are synchronized.}
03434 
03435   \textcolor{keywordtype}{logical} :: adv\_only
03436 
03437   adv\_only = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(adv\_dyn)) adv\_only = adv\_dyn
03438 
03439   \textcolor{keywordflow}{if} (adv\_only) \textcolor{keywordflow}{then}
03440     in\_synch = (cs%t\_dyn\_rel\_adv == 0.0)
03441   \textcolor{keywordflow}{else}
03442     in\_synch = ((cs%t\_dyn\_rel\_adv == 0.0) .and. (cs%t\_dyn\_rel\_thermo == 0.0))
03443 \textcolor{keywordflow}{  endif}
03444 
03445 \textcolor{keyword}{end function }\hyperlink{namespacemom_ada38a8329b76f9fa1685a230869a7647}{mom\_state\_is\_synchronized}
03446 \textcolor{comment}{}
03447 \textcolor{comment}{!> This subroutine offers access to values or pointers to other types from within}
03448 \textcolor{comment}{!! the MOM\_control\_struct, allowing the MOM\_control\_struct to be opaque.}
03449 \textcolor{keyword}{subroutine }\hyperlink{namespacemom_aece0dd1e2c9498844befd8ba71986b96}{get\_mom\_state\_elements}(CS, G, GV, US, C\_p, C\_p\_scaled, use\_temp)
\Hypertarget{MOM_8F90_source_l03450}\hyperlink{namespacemom_aece0dd1e2c9498844befd8ba71986b96}{03450}   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__control__struct}{mom\_control\_struct}),          \textcolor{keywordtype}{pointer}     :: CS\textcolor{comment}{ !< MOM control structure}
03451   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}     :: G\textcolor{comment}{    !< structure containing metrics and grid info}
03452   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}     :: GV\textcolor{comment}{   !< structure containing vertical grid info}
03453   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}     :: US\textcolor{comment}{   !< A dimensional unit scaling type}
03454   \textcolor{keywordtype}{real},                    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: C\_p\textcolor{comment}{  !< The heat capacity [J kg degC-1]}
03455   \textcolor{keywordtype}{real},                    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: C\_p\_scaled\textcolor{comment}{ !< The heat capacity in scaled}
03456 \textcolor{comment}{                                                         !! units [Q degC-1 ~> J kg degC-1]}
03457   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: use\_temp\textcolor{comment}{ !< True if temperature is a state variable}
03458 
03459   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(g)) g => cs%G\_in
03460   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(gv)) gv => cs%GV
03461   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) us => cs%US
03462   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(c\_p)) c\_p = cs%US%Q\_to\_J\_kg * cs%tv%C\_p
03463   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(c\_p\_scaled)) c\_p\_scaled = cs%tv%C\_p
03464   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(use\_temp)) use\_temp = \textcolor{keyword}{associated}(cs%tv%T)
03465 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom_aece0dd1e2c9498844befd8ba71986b96}{get\_mom\_state\_elements}
03466 \textcolor{comment}{}
03467 \textcolor{comment}{!> Find the global integrals of various quantities.}
03468 \textcolor{keyword}{subroutine }\hyperlink{namespacemom_a462293ed92e99927ef9939747d633080}{get\_ocean\_stocks}(CS, mass, heat, salt, on\_PE\_only)
\Hypertarget{MOM_8F90_source_l03469}\hyperlink{namespacemom_a462293ed92e99927ef9939747d633080}{03469}   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__control__struct}{mom\_control\_struct}), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< MOM control structure}
03470   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: heat\textcolor{comment}{  !< The globally integrated integrated ocean heat [J].}
03471   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: salt\textcolor{comment}{  !< The globally integrated integrated ocean salt [kg].}
03472   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: mass\textcolor{comment}{  !< The globally integrated integrated ocean mass [kg].}
03473   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: on\_PE\_only\textcolor{comment}{ !< If present and true, only sum on the local PE.}
03474 
03475   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(mass)) &
03476     mass = global\_mass\_integral(cs%h, cs%G, cs%GV, on\_pe\_only=on\_pe\_only)
03477   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(heat)) &
03478     heat = cs%US%Q\_to\_J\_kg*cs%tv%C\_p * global\_mass\_integral(cs%h, cs%G, cs%GV, cs%tv%T, on\_pe\_only=
      on\_pe\_only)
03479   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(salt)) &
03480     salt = 1.0e-3 * global\_mass\_integral(cs%h, cs%G, cs%GV, cs%tv%S, on\_pe\_only=on\_pe\_only)
03481 
03482 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom_a462293ed92e99927ef9939747d633080}{get\_ocean\_stocks}
03483 \textcolor{comment}{}
03484 \textcolor{comment}{!> End of ocean model, including memory deallocation}
03485 \textcolor{keyword}{subroutine }\hyperlink{namespacemom_ae6dad976fb4be1c7ba7fc1aff809616b}{mom\_end}(CS)
\Hypertarget{MOM_8F90_source_l03486}\hyperlink{namespacemom_ae6dad976fb4be1c7ba7fc1aff809616b}{03486}   \textcolor{keywordtype}{type}(\hyperlink{structmom_1_1mom__control__struct}{mom\_control\_struct}), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{   !< MOM control structure}
03487 
03488   \textcolor{keywordflow}{if} (cs%use\_ALE\_algorithm) \textcolor{keyword}{call }ale\_end(cs%ALE\_CSp)
03489 
03490   dealloc\_(cs%u) ; dealloc\_(cs%v) ; dealloc\_(cs%h)
03491   dealloc\_(cs%uh) ; dealloc\_(cs%vh)
03492 
03493   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tv%T)) \textcolor{keywordflow}{then}
03494     dealloc\_(cs%T) ; cs%tv%T => null() ; dealloc\_(cs%S) ; cs%tv%S => null()
03495 \textcolor{keywordflow}{  endif}
03496   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tv%frazil)) \textcolor{keyword}{deallocate}(cs%tv%frazil)
03497   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%tv%salt\_deficit)) \textcolor{keyword}{deallocate}(cs%tv%salt\_deficit)
03498   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%Hml)) \textcolor{keyword}{deallocate}(cs%Hml)
03499 
03500   \textcolor{keyword}{call }tracer\_advect\_end(cs%tracer\_adv\_CSp)
03501   \textcolor{keyword}{call }tracer\_hor\_diff\_end(cs%tracer\_diff\_CSp)
03502   \textcolor{keyword}{call }tracer\_registry\_end(cs%tracer\_Reg)
03503   \textcolor{keyword}{call }tracer\_flow\_control\_end(cs%tracer\_flow\_CSp)
03504 
03505   \textcolor{keyword}{call }diabatic\_driver\_end(cs%diabatic\_CSp)
03506 
03507   \textcolor{keywordflow}{if} (cs%offline\_tracer\_mode) \textcolor{keyword}{call }offline\_transport\_end(cs%offline\_CSp)
03508 
03509   dealloc\_(cs%uhtr) ; dealloc\_(cs%vhtr)
03510   \textcolor{keywordflow}{if} (cs%split) \textcolor{keywordflow}{then}
03511     \textcolor{keyword}{call }end\_dyn\_split\_rk2(cs%dyn\_split\_RK2\_CSp)
03512   \textcolor{keywordflow}{elseif} (cs%use\_RK2) \textcolor{keywordflow}{then}
03513     \textcolor{keyword}{call }end\_dyn\_unsplit\_rk2(cs%dyn\_unsplit\_RK2\_CSp)
03514   \textcolor{keywordflow}{else}
03515     \textcolor{keyword}{call }end\_dyn\_unsplit(cs%dyn\_unsplit\_CSp)
03516 \textcolor{keywordflow}{  endif}
03517   dealloc\_(cs%ave\_ssh\_ibc) ; dealloc\_(cs%ssh\_rint)
03518   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs%update\_OBC\_CSp)) \textcolor{keyword}{call }obc\_register\_end(cs%update\_OBC\_CSp)
03519 
03520   \textcolor{keyword}{call }verticalgridend(cs%GV)
03521   \textcolor{keyword}{call }unit\_scaling\_end(cs%US)
03522   \textcolor{keyword}{call }mom\_grid\_end(cs%G)
03523 
03524   \textcolor{keyword}{deallocate}(cs)
03525 
03526 \textcolor{keyword}{end subroutine }\hyperlink{namespacemom_ae6dad976fb4be1c7ba7fc1aff809616b}{mom\_end}
03527 \textcolor{comment}{}
03528 \textcolor{comment}{!> \(\backslash\)namespace mom}
03529 \textcolor{comment}{!!}
03530 \textcolor{comment}{!! Modular Ocean Model (MOM) Version 6.0 (MOM6)}
03531 \textcolor{comment}{!!}
03532 \textcolor{comment}{!! \(\backslash\)authors Alistair Adcroft, Robert Hallberg, and Stephen Griffies}
03533 \textcolor{comment}{!!}
03534 \textcolor{comment}{!!  Additional contributions from:}
03535 \textcolor{comment}{!!    * Whit Anderson}
03536 \textcolor{comment}{!!    * Brian Arbic}
03537 \textcolor{comment}{!!    * Will Cooke}
03538 \textcolor{comment}{!!    * Anand Gnanadesikan}
03539 \textcolor{comment}{!!    * Matthew Harrison}
03540 \textcolor{comment}{!!    * Mehmet Ilicak}
03541 \textcolor{comment}{!!    * Laura Jackson}
03542 \textcolor{comment}{!!    * Jasmine John}
03543 \textcolor{comment}{!!    * John Krasting}
03544 \textcolor{comment}{!!    * Zhi Liang}
03545 \textcolor{comment}{!!    * Bonnie Samuels}
03546 \textcolor{comment}{!!    * Harper Simmons}
03547 \textcolor{comment}{!!    * Laurent White}
03548 \textcolor{comment}{!!    * Niki Zadeh}
03549 \textcolor{comment}{!!}
03550 \textcolor{comment}{!!  MOM ice-shelf code was developed by}
03551 \textcolor{comment}{!!  * Daniel Goldberg}
03552 \textcolor{comment}{!!  * Robert Hallberg}
03553 \textcolor{comment}{!!  * Chris Little}
03554 \textcolor{comment}{!!  * Olga Sergienko}
03555 \textcolor{comment}{!!}
03556 \textcolor{comment}{!!  \(\backslash\)section section\_overview Overview of MOM}
03557 \textcolor{comment}{!!}
03558 \textcolor{comment}{!!  This program (MOM) simulates the ocean by numerically solving}
03559 \textcolor{comment}{!!  the hydrostatic primitive equations in generalized Lagrangian}
03560 \textcolor{comment}{!!  vertical coordinates, typically tracking stretched pressure (p*)}
03561 \textcolor{comment}{!!  surfaces or following isopycnals in the ocean's interior, and}
03562 \textcolor{comment}{!!  general orthogonal horizontal coordinates. Unlike earlier versions}
03563 \textcolor{comment}{!!  of MOM, in MOM6 these equations are horizontally discretized on an}
03564 \textcolor{comment}{!!  Arakawa C-grid.  (It remains to be seen whether a B-grid dynamic}
03565 \textcolor{comment}{!!  core will be revived in MOM6 at a later date; for now applications}
03566 \textcolor{comment}{!!  requiring a B-grid discretization should use MOM5.1.)  MOM6 offers}
03567 \textcolor{comment}{!!  a range of options for the physical parameterizations, from those}
03568 \textcolor{comment}{!!  most appropriate to highly idealized models for geophysical fluid}
03569 \textcolor{comment}{!!  dynamics studies to a rich suite of processes appropriate for}
03570 \textcolor{comment}{!!  realistic ocean simulations.  The thermodynamic options typically}
03571 \textcolor{comment}{!!  use conservative temperature and preformed salinity as conservative}
03572 \textcolor{comment}{!!  state variables and a full nonlinear equation of state, but there}
03573 \textcolor{comment}{!!  are also idealized adiabatic configurations of the model that use}
03574 \textcolor{comment}{!!  fixed density layers.  Version 6.0 of MOM continues in the long}
03575 \textcolor{comment}{!!  tradition of a commitment to climate-quality ocean simulations}
03576 \textcolor{comment}{!!  embodied in previous versions of MOM, even as it draws extensively}
03577 \textcolor{comment}{!!  on the lessons learned in the development of the Generalized Ocean}
03578 \textcolor{comment}{!!  Layered Dynamics (GOLD) ocean model, which was also primarily}
03579 \textcolor{comment}{!!  developed at NOAA/GFDL.  MOM has also benefited tremendously from}
03580 \textcolor{comment}{!!  the FMS infrastructure, which it utilizes and shares with other}
03581 \textcolor{comment}{!!  component models developed at NOAA/GFDL.}
03582 \textcolor{comment}{!!}
03583 \textcolor{comment}{!!    When run is isopycnal-coordinate mode, the uppermost few layers}
03584 \textcolor{comment}{!!  are often used to describe a bulk mixed layer, including the}
03585 \textcolor{comment}{!!  effects of penetrating shortwave radiation.  Either a split-}
03586 \textcolor{comment}{!!  explicit time stepping scheme or a non-split scheme may be used}
03587 \textcolor{comment}{!!  for the dynamics, while the time stepping may be split (and use}
03588 \textcolor{comment}{!!  different numbers of steps to cover the same interval) for the}
03589 \textcolor{comment}{!!  forcing, the thermodynamics, and for the dynamics.  Most of the}
03590 \textcolor{comment}{!!  numerics are second order accurate in space.  MOM can run with an}
03591 \textcolor{comment}{!!  absurdly thin minimum layer thickness. A variety of non-isopycnal}
03592 \textcolor{comment}{!!  vertical coordinate options are under development, but all exploit}
03593 \textcolor{comment}{!!  the advantages of a Lagrangian vertical coordinate, as discussed}
03594 \textcolor{comment}{!!  in detail by Adcroft and Hallberg (Ocean Modelling, 2006).}
03595 \textcolor{comment}{!!}
03596 \textcolor{comment}{!!    Details of the numerics and physical parameterizations are}
03597 \textcolor{comment}{!!  provided in the appropriate source files.  All of the available}
03598 \textcolor{comment}{!!  options are selected at run-time by parsing the input files,}
03599 \textcolor{comment}{!!  usually MOM\_input and MOM\_override, and the options choices are}
03600 \textcolor{comment}{!!  then documented for each run in MOM\_param\_docs.}
03601 \textcolor{comment}{!!}
03602 \textcolor{comment}{!!    MOM6 integrates the equations forward in time in three distinct}
03603 \textcolor{comment}{!!  phases.  In one phase, the dynamic equations for the velocities}
03604 \textcolor{comment}{!!  and layer thicknesses are advanced, capturing the propagation of}
03605 \textcolor{comment}{!!  external and internal inertia-gravity waves, Rossby waves, and}
03606 \textcolor{comment}{!!  other strictly adiabatic processes, including lateral stresses,}
03607 \textcolor{comment}{!!  vertical viscosity and momentum forcing, and interface height}
03608 \textcolor{comment}{!!  diffusion (commonly called Gent-McWilliams diffusion in depth-}
03609 \textcolor{comment}{!!  coordinate models).  In the second phase, all tracers are advected}
03610 \textcolor{comment}{!!  and diffused along the layers.  The third phase applies diabatic}
03611 \textcolor{comment}{!!  processes, vertical mixing of water properties, and perhaps}
03612 \textcolor{comment}{!!  vertical remapping to cause the layers to track the desired}
03613 \textcolor{comment}{!!  vertical coordinate.}
03614 \textcolor{comment}{!!}
03615 \textcolor{comment}{!!    The present file (MOM.F90) orchestrates the main time stepping}
03616 \textcolor{comment}{!!  loops. One time integration option for the dynamics uses a split}
03617 \textcolor{comment}{!!  explicit time stepping scheme to rapidly step the barotropic}
03618 \textcolor{comment}{!!  pressure and velocity fields. The barotropic velocities are}
03619 \textcolor{comment}{!!  averaged over the baroclinic time step before they are used to}
03620 \textcolor{comment}{!!  advect thickness and determine the baroclinic accelerations.  As}
03621 \textcolor{comment}{!!  described in Hallberg and Adcroft (2009), a barotropic correction}
03622 \textcolor{comment}{!!  is applied to the time-mean layer velocities to ensure that the}
03623 \textcolor{comment}{!!  sum of the layer transports agrees with the time-mean barotropic}
03624 \textcolor{comment}{!!  transport, thereby ensuring that the estimates of the free surface}
03625 \textcolor{comment}{!!  from the sum of the layer thicknesses agrees with the final free}
03626 \textcolor{comment}{!!  surface height as calculated by the barotropic solver.  The}
03627 \textcolor{comment}{!!  barotropic and baroclinic velocities are kept consistent by}
03628 \textcolor{comment}{!!  recalculating the barotropic velocities from the baroclinic}
03629 \textcolor{comment}{!!  transports each time step. This scheme is described in Hallberg,}
03630 \textcolor{comment}{!!  1997, J. Comp. Phys. 135, 54-65 and in Hallberg and Adcroft, 2009,}
03631 \textcolor{comment}{!!  Ocean Modelling, 29, 15-26.}
03632 \textcolor{comment}{!!}
03633 \textcolor{comment}{!!    The other time integration options use non-split time stepping}
03634 \textcolor{comment}{!!  schemes based on the 3-step third order Runge-Kutta scheme}
03635 \textcolor{comment}{!!  described in Matsuno, 1966, J. Met. Soc. Japan, 44, 85-88, or on}
03636 \textcolor{comment}{!!  a two-step quasi-2nd order Runge-Kutta scheme.  These are much}
03637 \textcolor{comment}{!!  slower than the split time-stepping scheme, but they are useful}
03638 \textcolor{comment}{!!  for providing a more robust solution for debugging cases where the}
03639 \textcolor{comment}{!!  more complicated split time-stepping scheme may be giving suspect}
03640 \textcolor{comment}{!!  solutions.}
03641 \textcolor{comment}{!!}
03642 \textcolor{comment}{!!    There are a range of closure options available.  Horizontal}
03643 \textcolor{comment}{!!  velocities are subject to a combination of horizontal biharmonic}
03644 \textcolor{comment}{!!  and Laplacian friction (based on a stress tensor formalism) and a}
03645 \textcolor{comment}{!!  vertical Fickian viscosity (perhaps using the kinematic viscosity}
03646 \textcolor{comment}{!!  of water).  The horizontal viscosities may be constant, spatially}
03647 \textcolor{comment}{!!  varying or may be dynamically calculated using Smagorinsky's}
03648 \textcolor{comment}{!!  approach.  A diapycnal diffusion of density and thermodynamic}
03649 \textcolor{comment}{!!  quantities is also allowed, but not required, as is horizontal}
03650 \textcolor{comment}{!!  diffusion of interface heights (akin to the Gent-McWilliams}
03651 \textcolor{comment}{!!  closure of geopotential coordinate models).  The diapycnal mixing}
03652 \textcolor{comment}{!!  may use a fixed diffusivity or it may use the shear Richardson}
03653 \textcolor{comment}{!!  number dependent closure, like that described in Jackson et al.}
03654 \textcolor{comment}{!!  (JPO, 2008).  When there is diapycnal diffusion, it applies to}
03655 \textcolor{comment}{!!  momentum as well. As this is in addition to the vertical viscosity,}
03656 \textcolor{comment}{!!  the vertical Prandtl always exceeds 1.  A refined bulk-mixed layer}
03657 \textcolor{comment}{!!  is often used to describe the planetary boundary layer in realistic}
03658 \textcolor{comment}{!!  ocean simulations.}
03659 \textcolor{comment}{!!}
03660 \textcolor{comment}{!!    MOM has a number of noteworthy debugging capabilities.}
03661 \textcolor{comment}{!!  Excessively large velocities are truncated and MOM will stop}
03662 \textcolor{comment}{!!  itself after a number of such instances to keep the model from}
03663 \textcolor{comment}{!!  crashing altogether.  This is useful in diagnosing failures,}
03664 \textcolor{comment}{!!  or (by accepting some truncations) it may be useful for getting}
03665 \textcolor{comment}{!!  the model past the adjustment from an ill-balanced initial}
03666 \textcolor{comment}{!!  condition.  In addition, all of the accelerations in the columns}
03667 \textcolor{comment}{!!  with excessively large velocities may be directed to a text file.}
03668 \textcolor{comment}{!!  Parallelization errors may be diagnosed using the DEBUG option,}
03669 \textcolor{comment}{!!  which causes extensive checksums to be written out along with}
03670 \textcolor{comment}{!!  comments indicating where in the algorithm the sums originate and}
03671 \textcolor{comment}{!!  what variable is being summed.  The point where these checksums}
03672 \textcolor{comment}{!!  differ between runs is usually a good indication of where in the}
03673 \textcolor{comment}{!!  code the problem lies.  All of the test cases provided with MOM}
03674 \textcolor{comment}{!!  are routinely tested to ensure that they give bitwise identical}
03675 \textcolor{comment}{!!  results regardless of the domain decomposition, or whether they}
03676 \textcolor{comment}{!!  use static or dynamic memory allocation.}
03677 \textcolor{comment}{!!}
03678 \textcolor{comment}{!!  \(\backslash\)section section\_structure Structure of MOM}
03679 \textcolor{comment}{!!}
03680 \textcolor{comment}{!!  About 115 other files of source code and 4 header files comprise}
03681 \textcolor{comment}{!!  the MOM code, although there are several hundred more files that}
03682 \textcolor{comment}{!!  make up the FMS infrastructure upon which MOM is built.  Each of}
03683 \textcolor{comment}{!!  the MOM files contains comments documenting what it does, and}
03684 \textcolor{comment}{!!  most of the file names are fairly self-evident. In addition, all}
03685 \textcolor{comment}{!!  subroutines and data types are referenced via a module use, only}
03686 \textcolor{comment}{!!  statement, and the module names are consistent with the file names,}
03687 \textcolor{comment}{!!  so it is not too hard to find the source file for a subroutine.}
03688 \textcolor{comment}{!!}
03689 \textcolor{comment}{!!    The typical MOM directory tree is as follows:}
03690 \textcolor{comment}{!!}
03691 \textcolor{comment}{!! \(\backslash\)verbatim}
03692 \textcolor{comment}{!!        ../MOM}
03693 \textcolor{comment}{!!        |-- config\_src}
03694 \textcolor{comment}{!!        |   |-- coupled\_driver}
03695 \textcolor{comment}{!!        |   |-- dynamic}
03696 \textcolor{comment}{!!        |   `-- solo\_driver}
03697 \textcolor{comment}{!!        |-- examples}
03698 \textcolor{comment}{!!        |   |-- CM2G}
03699 \textcolor{comment}{!!        |   |-- ...}
03700 \textcolor{comment}{!!        |   `-- torus\_advection\_test}
03701 \textcolor{comment}{!!        `-- src}
03702 \textcolor{comment}{!!            |-- core}
03703 \textcolor{comment}{!!            |-- diagnostics}
03704 \textcolor{comment}{!!            |-- equation\_of\_state}
03705 \textcolor{comment}{!!            |-- framework}
03706 \textcolor{comment}{!!            |-- ice\_shelf}
03707 \textcolor{comment}{!!            |-- initialization}
03708 \textcolor{comment}{!!            |-- parameterizations}
03709 \textcolor{comment}{!!            |   |-- lateral}
03710 \textcolor{comment}{!!            |   `-- vertical}
03711 \textcolor{comment}{!!            |-- tracer}
03712 \textcolor{comment}{!!            `-- user}
03713 \textcolor{comment}{!! \(\backslash\)endverbatim}
03714 \textcolor{comment}{!!}
03715 \textcolor{comment}{!!  Rather than describing each file here, each directory contents}
03716 \textcolor{comment}{!!  will be described to give a broad overview of the MOM code}
03717 \textcolor{comment}{!!  structure.}
03718 \textcolor{comment}{!!}
03719 \textcolor{comment}{!!    The directories under config\_src contain files that are used for}
03720 \textcolor{comment}{!!  configuring the code, for instance for coupled or ocean-only runs.}
03721 \textcolor{comment}{!!  Only one or two of these directories are used in compiling any,}
03722 \textcolor{comment}{!!  particular run.}
03723 \textcolor{comment}{!!}
03724 \textcolor{comment}{!!  * config\_src/coupled\_driver:}
03725 \textcolor{comment}{!!    The files here are used to couple MOM as a component in a larger}
03726 \textcolor{comment}{!!    run driven by the FMS coupler.  This includes code that converts}
03727 \textcolor{comment}{!!    various forcing fields into the code structures and flux and unit}
03728 \textcolor{comment}{!!    conventions used by MOM, and converts the MOM surface fields}
03729 \textcolor{comment}{!!    back to the forms used by other FMS components.}
03730 \textcolor{comment}{!!}
03731 \textcolor{comment}{!!  * config\_src/dynamic:}
03732 \textcolor{comment}{!!    The only file here is the version of MOM\_memory.h that is used}
03733 \textcolor{comment}{!!    for dynamic memory configurations of MOM.}
03734 \textcolor{comment}{!!}
03735 \textcolor{comment}{!!  * config\_src/solo\_driver:}
03736 \textcolor{comment}{!!    The files here are include the \_main driver that is used when}
03737 \textcolor{comment}{!!    MOM is configured as an ocean-only model, as well as the files}
03738 \textcolor{comment}{!!    that specify the surface forcing in this configuration.}
03739 \textcolor{comment}{!!}
03740 \textcolor{comment}{!!    The directories under examples provide a large number of working}
03741 \textcolor{comment}{!!  configurations of MOM, along with reference solutions for several}
03742 \textcolor{comment}{!!  different compilers on GFDL's latest large computer.  The versions}
03743 \textcolor{comment}{!!  of MOM\_memory.h in these directories need not be used if dynamic}
03744 \textcolor{comment}{!!  memory allocation is desired, and the answers should be unchanged.}
03745 \textcolor{comment}{!!}
03746 \textcolor{comment}{!!    The directories under src contain most of the MOM files.  These}
03747 \textcolor{comment}{!!  files are used in every configuration using MOM.}
03748 \textcolor{comment}{!!}
03749 \textcolor{comment}{!!  * src/core:}
03750 \textcolor{comment}{!!    The files here constitute the MOM dynamic core.  This directory}
03751 \textcolor{comment}{!!    also includes files with the types that describe the model's}
03752 \textcolor{comment}{!!    lateral grid and have defined types that are shared across}
03753 \textcolor{comment}{!!    various MOM modules to allow for more succinct and flexible}
03754 \textcolor{comment}{!!    subroutine argument lists.}
03755 \textcolor{comment}{!!}
03756 \textcolor{comment}{!!  * src/diagnostics:}
03757 \textcolor{comment}{!!    The files here calculate various diagnostics that are anciliary}
03758 \textcolor{comment}{!!    to the model itself.  While most of these diagnostics do not}
03759 \textcolor{comment}{!!    directly affect the model's solution, there are some, like the}
03760 \textcolor{comment}{!!    calculation of the deformation radius, that are used in some}
03761 \textcolor{comment}{!!    of the process parameterizations.}
03762 \textcolor{comment}{!!}
03763 \textcolor{comment}{!!  * src/equation\_of\_state:}
03764 \textcolor{comment}{!!    These files describe the physical properties of sea-water,}
03765 \textcolor{comment}{!!    including both the equation of state and when it freezes.}
03766 \textcolor{comment}{!!}
03767 \textcolor{comment}{!!  * src/framework:}
03768 \textcolor{comment}{!!    These files provide infrastructure utilities for MOM.  Many are}
03769 \textcolor{comment}{!!    simply wrappers for capabilities provided by FMS, although others}
03770 \textcolor{comment}{!!    provide capabilities (like the file\_parser) that are unique to}
03771 \textcolor{comment}{!!    MOM. When MOM is adapted to use a modeling infrastructure}
03772 \textcolor{comment}{!!    distinct from FMS, most of the required changes are in this}
03773 \textcolor{comment}{!!    directory.}
03774 \textcolor{comment}{!!}
03775 \textcolor{comment}{!!  * src/initialization:}
03776 \textcolor{comment}{!!    These are the files that are used to initialize the MOM grid}
03777 \textcolor{comment}{!!    or provide the initial physical state for MOM.  These files are}
03778 \textcolor{comment}{!!    not intended to be modified, but provide a means for calling}
03779 \textcolor{comment}{!!    user-specific initialization code like the examples in src/user.}
03780 \textcolor{comment}{!!}
03781 \textcolor{comment}{!!  * src/parameterizations/lateral:}
03782 \textcolor{comment}{!!    These files implement a number of quasi-lateral (along-layer)}
03783 \textcolor{comment}{!!    process parameterizations, including lateral viscosities,}
03784 \textcolor{comment}{!!    parameterizations of eddy effects, and the calculation of tidal}
03785 \textcolor{comment}{!!    forcing.}
03786 \textcolor{comment}{!!}
03787 \textcolor{comment}{!!  * src/parameterizations/vertical:}
03788 \textcolor{comment}{!!    These files implement a number of vertical mixing or diabatic}
03789 \textcolor{comment}{!!    processes, including the effects of vertical viscosity and}
03790 \textcolor{comment}{!!    code to parameterize the planetary boundary layer.  There is a}
03791 \textcolor{comment}{!!    separate driver that orchestrates this portion of the algorithm,}
03792 \textcolor{comment}{!!    and there is a diversity of parameterizations to be found here.}
03793 \textcolor{comment}{!!}
03794 \textcolor{comment}{!!  * src/tracer:}
03795 \textcolor{comment}{!!    These files handle the lateral transport and diffusion of}
03796 \textcolor{comment}{!!    tracers, or are the code to implement various passive tracer}
03797 \textcolor{comment}{!!    packages.  Additional tracer packages are readily accommodated.}
03798 \textcolor{comment}{!!}
03799 \textcolor{comment}{!!  * src/user:}
03800 \textcolor{comment}{!!    These are either stub routines that a user could use to change}
03801 \textcolor{comment}{!!    the model's initial conditions or forcing, or are examples that}
03802 \textcolor{comment}{!!    implement specific test cases.  These files can easily  be hand}
03803 \textcolor{comment}{!!    edited to create new analytically specified configurations.}
03804 \textcolor{comment}{!!}
03805 \textcolor{comment}{!!}
03806 \textcolor{comment}{!!  Most simulations can be set up by modifying only the files}
03807 \textcolor{comment}{!!  MOM\_input, and possibly one or two of the files in src/user.}
03808 \textcolor{comment}{!!  In addition, the diag\_table (MOM\_diag\_table) will commonly be}
03809 \textcolor{comment}{!!  modified to tailor the output to the needs of the question at}
03810 \textcolor{comment}{!!  hand.  The FMS utility mkmf works with a file called path\_names}
03811 \textcolor{comment}{!!  to build an appropriate makefile, and path\_names should be edited}
03812 \textcolor{comment}{!!  to reflect the actual location of the desired source code.}
03813 \textcolor{comment}{!!}
03814 \textcolor{comment}{!!}
03815 \textcolor{comment}{!!  There are 3 publicly visible subroutines in this file (MOM.F90).}
03816 \textcolor{comment}{!!  * step\_MOM steps MOM over a specified interval of time.}
03817 \textcolor{comment}{!!  * MOM\_initialize calls initialize and does other initialization}
03818 \textcolor{comment}{!!    that does not warrant user modification.}
03819 \textcolor{comment}{!!  * extract\_surface\_state determines the surface (bulk mixed layer}
03820 \textcolor{comment}{!!    if traditional isoycnal vertical coordinate) properties of the}
03821 \textcolor{comment}{!!    current model state and packages pointers to these fields into an}
03822 \textcolor{comment}{!!    exported structure.}
03823 \textcolor{comment}{!!}
03824 \textcolor{comment}{!!    The remaining subroutines in this file (src/core/MOM.F90) are:}
03825 \textcolor{comment}{!!  * find\_total\_transport determines the barotropic mass transport.}
03826 \textcolor{comment}{!!  * register\_diags registers many diagnostic fields for the dynamic}
03827 \textcolor{comment}{!!    solver, or of the main model variables.}
03828 \textcolor{comment}{!!  * MOM\_timing\_init initializes various CPU time clocks.}
03829 \textcolor{comment}{!!  * write\_static\_fields writes out various time-invariant fields.}
03830 \textcolor{comment}{!!  * set\_restart\_fields is used to specify those fields that are}
03831 \textcolor{comment}{!!    written to and read from the restart file.}
03832 \textcolor{comment}{!!}
03833 \textcolor{comment}{!!  \(\backslash\)section section\_heat\_budget Diagnosing MOM heat budget}
03834 \textcolor{comment}{!!}
03835 \textcolor{comment}{!!  Here are some example heat budgets for the ALE version of MOM6.}
03836 \textcolor{comment}{!!}
03837 \textcolor{comment}{!!  \(\backslash\)subsection subsection\_2d\_heat\_budget Depth integrated heat budget}
03838 \textcolor{comment}{!!}
03839 \textcolor{comment}{!!  Depth integrated heat budget diagnostic for MOM.}
03840 \textcolor{comment}{!!}
03841 \textcolor{comment}{!! * OPOTTEMPTEND\_2d = T\_ADVECTION\_XY\_2d + OPOTTEMPPMDIFF\_2d + HFDS + HFGEOU}
03842 \textcolor{comment}{!!}
03843 \textcolor{comment}{!! * T\_ADVECTION\_XY\_2d = horizontal advection}
03844 \textcolor{comment}{!! * OPOTTEMPPMDIFF\_2d = neutral diffusion}
03845 \textcolor{comment}{!! * HFDS              = net surface boundary heat flux}
03846 \textcolor{comment}{!! * HFGEOU            = geothermal heat flux}
03847 \textcolor{comment}{!!}
03848 \textcolor{comment}{!! * HFDS = net surface boundary heat flux entering the ocean}
03849 \textcolor{comment}{!!        = rsntds + rlntds + hfls + hfss + heat\_pme + hfsifrazil}
03850 \textcolor{comment}{!!}
03851 \textcolor{comment}{!! * More heat flux cross-checks}
03852 \textcolor{comment}{!!   * hfds     = net\_heat\_coupler + hfsifrazil + heat\_pme}
03853 \textcolor{comment}{!!   * heat\_pme = heat\_content\_surfwater}
03854 \textcolor{comment}{!!              = heat\_content\_massin + heat\_content\_massout}
03855 \textcolor{comment}{!!              = heat\_content\_fprec + heat\_content\_cond + heat\_content\_vprec}
03856 \textcolor{comment}{!!               + hfrunoffds + hfevapds + hfrainds}
03857 \textcolor{comment}{!!}
03858 \textcolor{comment}{!!  \(\backslash\)subsection subsection\_3d\_heat\_budget Depth integrated heat budget}
03859 \textcolor{comment}{!!}
03860 \textcolor{comment}{!!  Here is an example 3d heat budget diagnostic for MOM.}
03861 \textcolor{comment}{!!}
03862 \textcolor{comment}{!! * OPOTTEMPTEND = T\_ADVECTION\_XY + TH\_TENDENCY\_VERT\_REMAP + OPOTTEMPDIFF + OPOTTEMPPMDIFF}
03863 \textcolor{comment}{!!                + BOUNDARY\_FORCING\_HEAT\_TENDENCY + FRAZIL\_HEAT\_TENDENCY}
03864 \textcolor{comment}{!!}
03865 \textcolor{comment}{!! * OPOTTEMPTEND                   = net tendency of heat as diagnosed in MOM.F90}
03866 \textcolor{comment}{!! * T\_ADVECTION\_XY                 = heating of a cell from lateral advection}
03867 \textcolor{comment}{!! * TH\_TENDENCY\_VERT\_REMAP         = heating of a cell from vertical remapping}
03868 \textcolor{comment}{!! * OPOTTEMPDIFF                   = heating of a cell from diabatic diffusion}
03869 \textcolor{comment}{!! * OPOTTEMPPMDIFF                 = heating of a cell from neutral diffusion}
03870 \textcolor{comment}{!! * BOUNDARY\_FORCING\_HEAT\_TENDENCY = heating of cell from boundary fluxes}
03871 \textcolor{comment}{!! * FRAZIL\_HEAT\_TENDENCY           = heating of cell from frazil}
03872 \textcolor{comment}{!!}
03873 \textcolor{comment}{!! * TH\_TENDENCY\_VERT\_REMAP has zero vertical sum, as it redistributes heat in vertical.}
03874 \textcolor{comment}{!!}
03875 \textcolor{comment}{!! * OPOTTEMPDIFF has zero vertical sum, as it redistributes heat in the vertical.}
03876 \textcolor{comment}{!!}
03877 \textcolor{comment}{!! * BOUNDARY\_FORCING\_HEAT\_TENDENCY generally has 3d structure, with k > 1 contributions from}
03878 \textcolor{comment}{!!   penetrative shortwave, and from other fluxes for the case when layers are tiny, in which}
03879 \textcolor{comment}{!!   case MOM6 partitions tendencies into k > 1 layers.}
03880 \textcolor{comment}{!!}
03881 \textcolor{comment}{!! * FRAZIL\_HEAT\_TENDENCY generally has 3d structure, since MOM6 frazil calculation checks the}
03882 \textcolor{comment}{!!   full ocean column.}
03883 \textcolor{comment}{!!}
03884 \textcolor{comment}{!! * FRAZIL\_HEAT\_TENDENCY[k=\(\backslash\)@sum] = HFSIFRAZIL = column integrated frazil heating.}
03885 \textcolor{comment}{!!}
03886 \textcolor{comment}{!! * HFDS = FRAZIL\_HEAT\_TENDENCY[k=\(\backslash\)@sum] + BOUNDARY\_FORCING\_HEAT\_TENDENCY[k=\(\backslash\)@sum]}
03887 \textcolor{comment}{!!}
03888 \textcolor{comment}{!!  Here is an example 2d heat budget (depth summed) diagnostic for MOM.}
03889 \textcolor{comment}{!!}
03890 \textcolor{comment}{!! * OPOTTEMPTEND\_2d = T\_ADVECTION\_XY\_2d + OPOTTEMPPMDIFF\_2d + HFDS}
03891 \textcolor{comment}{!!}
03892 \textcolor{comment}{!!}
03893 \textcolor{comment}{!!  Here is an example 3d salt budget diagnostic for MOM.}
03894 \textcolor{comment}{!!}
03895 \textcolor{comment}{!! * OSALTTEND = S\_ADVECTION\_XY + SH\_TENDENCY\_VERT\_REMAP + OSALTDIFF + OSALTPMDIFF}
03896 \textcolor{comment}{!!                + BOUNDARY\_FORCING\_SALT\_TENDENCY}
03897 \textcolor{comment}{!!}
03898 \textcolor{comment}{!! * OSALTTEND                      = net tendency of salt as diagnosed in MOM.F90}
03899 \textcolor{comment}{!! * S\_ADVECTION\_XY                 = salt convergence to cell from lateral advection}
03900 \textcolor{comment}{!! * SH\_TENDENCY\_VERT\_REMAP         = salt convergence to cell from vertical remapping}
03901 \textcolor{comment}{!! * OSALTDIFF                      = salt convergence to cell from diabatic diffusion}
03902 \textcolor{comment}{!! * OSALTPMDIFF                    = salt convergence to cell from neutral diffusion}
03903 \textcolor{comment}{!! * BOUNDARY\_FORCING\_SALT\_TENDENCY = salt convergence to cell from boundary fluxes}
03904 \textcolor{comment}{!!}
03905 \textcolor{comment}{!! * SH\_TENDENCY\_VERT\_REMAP has zero vertical sum, as it redistributes salt in vertical.}
03906 \textcolor{comment}{!!}
03907 \textcolor{comment}{!! * OSALTDIFF has zero vertical sum, as it redistributes salt in the vertical.}
03908 \textcolor{comment}{!!}
03909 \textcolor{comment}{!! * BOUNDARY\_FORCING\_SALT\_TENDENCY generally has 3d structure, with k > 1 contributions from}
03910 \textcolor{comment}{!!   the case when layers are tiny, in which case MOM6 partitions tendencies into k > 1 layers.}
03911 \textcolor{comment}{!!}
03912 \textcolor{comment}{!! * SFDSI = BOUNDARY\_FORCING\_SALT\_TENDENCY[k=\(\backslash\)@sum]}
03913 \textcolor{comment}{!!}
03914 \textcolor{comment}{!!  Here is an example 2d salt budget (depth summed) diagnostic for MOM.}
03915 \textcolor{comment}{!!}
03916 \textcolor{comment}{!! * OSALTTEND\_2d = S\_ADVECTION\_XY\_2d + OSALTPMDIFF\_2d + SFDSI (+ SALT\_FLUX\_RESTORE)}
03917 \textcolor{comment}{!!}
03918 \textcolor{comment}{!!}
03919 \textcolor{comment}{!!}
03920 \textcolor{keyword}{end module }\hyperlink{namespacemom}{mom}
\end{DoxyCode}
