\hypertarget{namespacemom__state__initialization}{}\section{mom\+\_\+state\+\_\+initialization Module Reference}
\label{namespacemom__state__initialization}\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}


\subsection{Detailed Description}
Initialization functions for state variables, u, v, h, T and S. \subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \hyperlink{namespacemom__state__initialization_a81503d4f1855cb185f122d6314e4f06c}{mom\+\_\+initialize\+\_\+state} (u, v, h, tv, Time, G, GV, US, PF, dirs, restart\+\_\+\+CS, A\+L\+E\+\_\+\+C\+Sp, tracer\+\_\+\+Reg, sponge\+\_\+\+C\+Sp, A\+L\+E\+\_\+sponge\+\_\+\+C\+Sp, O\+BC, Time\+\_\+in)
\begin{DoxyCompactList}\small\item\em Initialize temporally evolving fields, either as initial conditions or by reading them from a restart (or saves) file. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_a847ac374f69c4777e3e49a5ebdcebf43}{initialize\+\_\+thickness\+\_\+from\+\_\+file} (h, G, GV, US, param\+\_\+file, file\+\_\+has\+\_\+thickness, just\+\_\+read\+\_\+params)
\begin{DoxyCompactList}\small\item\em Reads the layer thicknesses or interface heights from a file. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_a59cb36440a4ef993c4c98170e52a775f}{adjustetatofitbathymetry} (G, GV, US, eta, h)
\begin{DoxyCompactList}\small\item\em Adjust interface heights to fit the bathymetry and diagnose layer thickness. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_a06f7a21e110b80140439dedccaf4fa1c}{initialize\+\_\+thickness\+\_\+uniform} (h, G, GV, param\+\_\+file, just\+\_\+read\+\_\+params)
\begin{DoxyCompactList}\small\item\em Initializes thickness to be uniform. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_ade07252728855ac18a50b547f0cb16f7}{initialize\+\_\+thickness\+\_\+list} (h, G, GV, US, param\+\_\+file, just\+\_\+read\+\_\+params)
\begin{DoxyCompactList}\small\item\em Initialize thickness from a 1D list. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__state__initialization_a1752fe7b4c2a9878165f5ae77201cd30}\label{namespacemom__state__initialization_a1752fe7b4c2a9878165f5ae77201cd30}} 
subroutine \hyperlink{namespacemom__state__initialization_a1752fe7b4c2a9878165f5ae77201cd30}{initialize\+\_\+thickness\+\_\+search}
\begin{DoxyCompactList}\small\item\em Search density space for location of layers (not implemented!) \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_a9b4e1b8c587fb11f1ec78e7e30215913}{convert\+\_\+thickness} (h, G, GV, US, tv)
\begin{DoxyCompactList}\small\item\em Converts thickness from geometric to pressure units. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_aad295781ac5adccf3a80e2323ce77905}{depress\+\_\+surface} (h, G, GV, US, param\+\_\+file, tv, just\+\_\+read\+\_\+params)
\begin{DoxyCompactList}\small\item\em Depress the sea-\/surface based on an initial condition file. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_abbe8ee99793eae86251739a8a1bf572f}{trim\+\_\+for\+\_\+ice} (PF, G, GV, US, A\+L\+E\+\_\+\+C\+Sp, tv, h, just\+\_\+read\+\_\+params)
\begin{DoxyCompactList}\small\item\em Adjust the layer thicknesses by cutting away the top of each model column at the depth where the hydrostatic pressure matches an imposed surface pressure read from file. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_a214d4aa46f0374e29369282389f40de7}{cut\+\_\+off\+\_\+column\+\_\+top} (nk, tv, GV, US, G\+\_\+earth, depth, min\+\_\+thickness, T, T\+\_\+t, T\+\_\+b, S, S\+\_\+t, S\+\_\+b, p\+\_\+surf, h, remap\+\_\+\+CS, z\+\_\+tol, remap\+\_\+answers\+\_\+2018)
\begin{DoxyCompactList}\small\item\em Adjust the layer thicknesses by removing the top of the water column above the depth where the hydrostatic pressure matches p\+\_\+surf. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_adcedb30eb6f940cef3fbdd4328aedef8}{initialize\+\_\+velocity\+\_\+from\+\_\+file} (u, v, G, US, param\+\_\+file, just\+\_\+read\+\_\+params)
\begin{DoxyCompactList}\small\item\em Initialize horizontal velocity components from file. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_a1de6eb1d89deb76196b2876c8982a956}{initialize\+\_\+velocity\+\_\+zero} (u, v, G, param\+\_\+file, just\+\_\+read\+\_\+params)
\begin{DoxyCompactList}\small\item\em Initialize horizontal velocity components to zero. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_ac10655a7937f2239ff8ae9b899f4bc4b}{initialize\+\_\+velocity\+\_\+uniform} (u, v, G, US, param\+\_\+file, just\+\_\+read\+\_\+params)
\begin{DoxyCompactList}\small\item\em Sets the initial velocity components to uniform. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_af4ebdba67fde58a9aa7633bca4c117ba}{initialize\+\_\+velocity\+\_\+circular} (u, v, G, US, param\+\_\+file, just\+\_\+read\+\_\+params)
\begin{DoxyCompactList}\small\item\em Sets the initial velocity components to be circular with no flow at edges of domain and center. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_a706c24ba7b8a344152ea0d3da051ceb5}{initialize\+\_\+temp\+\_\+salt\+\_\+from\+\_\+file} (T, S, G, param\+\_\+file, just\+\_\+read\+\_\+params)
\begin{DoxyCompactList}\small\item\em Initializes temperature and salinity from file. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_a7d627f0ef1dc66acc764a40fd662a758}{initialize\+\_\+temp\+\_\+salt\+\_\+from\+\_\+profile} (T, S, G, param\+\_\+file, just\+\_\+read\+\_\+params)
\begin{DoxyCompactList}\small\item\em Initializes temperature and salinity from a 1D profile. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_a964fba68510337bdde7636a18f783fc9}{initialize\+\_\+temp\+\_\+salt\+\_\+fit} (T, S, G, GV, US, param\+\_\+file, eqn\+\_\+of\+\_\+state, P\+\_\+\+Ref, just\+\_\+read\+\_\+params)
\begin{DoxyCompactList}\small\item\em Initializes temperature and salinity by fitting to density. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_a0793ab167463a3bb45114f57cf018a40}{initialize\+\_\+temp\+\_\+salt\+\_\+linear} (T, S, G, param\+\_\+file, just\+\_\+read\+\_\+params)
\begin{DoxyCompactList}\small\item\em Initializes T and S with linear profiles according to reference surface layer salinity and temperature and a specified range. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_ac672706eef5c8d6c07333f5e46e4cdff}{initialize\+\_\+sponges\+\_\+file} (G, GV, US, use\+\_\+temperature, tv, param\+\_\+file, Layer\+\_\+\+C\+Sp, A\+L\+E\+\_\+\+C\+Sp, Time)
\begin{DoxyCompactList}\small\item\em This subroutine sets the inverse restoration time (Idamp), and the values towards which the interface heights and an arbitrary number of tracers should be restored within each sponge. The interface height is always subject to damping, and must always be the first registered field. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_ace20e4d29e01307fc37911d9ce4df2e3}{set\+\_\+velocity\+\_\+depth\+\_\+max} (G)
\begin{DoxyCompactList}\small\item\em This subroutine sets the 4 bottom depths at velocity points to be the maximum of the adjacent depths. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_aebc1c5c12c684e398074f2f56bc61d97}{compute\+\_\+global\+\_\+grid\+\_\+integrals} (G, US)
\begin{DoxyCompactList}\small\item\em Subroutine to pre-\/compute global integrals of grid quantities for later use in reporting diagnostics. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_a9eda11f130fa39ea833f7b1e4d099c58}{set\+\_\+velocity\+\_\+depth\+\_\+min} (G)
\begin{DoxyCompactList}\small\item\em This subroutine sets the 4 bottom depths at velocity points to be the minimum of the adjacent depths. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_a4b1a2ab2ba01da2b898f5e65ebc30c9d}{mom\+\_\+temp\+\_\+salt\+\_\+initialize\+\_\+from\+\_\+z} (h, tv, G, GV, US, PF, just\+\_\+read\+\_\+params)
\begin{DoxyCompactList}\small\item\em This subroutine determines the isopycnal or other coordinate interfaces and layer potential temperatures and salinities directly from a z-\/space file on a latitude-\/longitude grid. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_a526e4ed5e2543f0d7bec8bc0dde37ae2}{find\+\_\+interfaces} (rho, zin, nk\+\_\+data, Rb, depth, zi, G, US, nlevs, nkml, hml, eps\+\_\+z, eps\+\_\+rho)
\begin{DoxyCompactList}\small\item\em Find interface positions corresponding to interpolated depths in a density profile. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__state__initialization_a807c1c2bb13f172945c7c25f3af7abd1}{mom\+\_\+state\+\_\+init\+\_\+tests} (G, GV, US, tv)
\begin{DoxyCompactList}\small\item\em Run simple unit tests. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__state__initialization_a0d04f34a0f7ba9ce38686ca2ce005508}\label{namespacemom__state__initialization_a0d04f34a0f7ba9ce38686ca2ce005508}} 
character(len=40) \hyperlink{namespacemom__state__initialization_a0d04f34a0f7ba9ce38686ca2ce005508}{mdl} = \char`\"{}M\+O\+M\+\_\+state\+\_\+initialization\char`\"{}
\begin{DoxyCompactList}\small\item\em This module\textquotesingle{}s name. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__state__initialization_a59cb36440a4ef993c4c98170e52a775f}\label{namespacemom__state__initialization_a59cb36440a4ef993c4c98170e52a775f}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!adjustetatofitbathymetry@{adjustetatofitbathymetry}}
\index{adjustetatofitbathymetry@{adjustetatofitbathymetry}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{adjustetatofitbathymetry()}{adjustetatofitbathymetry()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::adjustetatofitbathymetry (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke+1), intent(inout)}]{eta,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{h }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Adjust interface heights to fit the bathymetry and diagnose layer thickness. 

If the bottom most interface is below the topography then the bottom-\/most layers are contracted to GVAngstrom\+\_\+m. If the bottom most interface is above the topography then the entire column is dilated (expanded) to fill the void. \begin{DoxyRemark}{Remarks}
\{There is a (hard-\/wired) \char`\"{}tolerance\char`\"{} parameter such that the criteria for adjustment must equal or exceed 10cm.\}
\end{DoxyRemark}

\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in,out}  & {\em eta} & Interface heights \mbox{[}Z $\sim$$>$ m\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 713 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
713   \textcolor{keywordtype}{type}(ocean\_grid\_type),                      \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{   !< The ocean's grid structure}
714   \textcolor{keywordtype}{type}(verticalgrid\_type),                    \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{  !< The ocean's vertical grid structure}
715   \textcolor{keywordtype}{type}(unit\_scale\_type),                      \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{  !< A dimensional unit scaling type}
716   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{intent(inout)} :: eta\textcolor{comment}{ !< Interface heights [Z ~> m].}
717   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{   !< Layer thicknesses [H ~> m or kg m-2]}
718   \textcolor{comment}{! Local variables}
719   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz, contractions, dilations
720   \textcolor{keywordtype}{real} :: htolerance = 0.1\textcolor{comment}{ !<  Tolerance to exceed adjustment criteria [Z ~> m]}
721   \textcolor{keywordtype}{real} :: htmp, etmp, dilate
722   \textcolor{keywordtype}{character(len=100)} :: mesg
723 
724   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
725   htolerance = 0.1*us%m\_to\_Z
726 
727   contractions = 0
728   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
729     \textcolor{keywordflow}{if} (-eta(i,j,nz+1) > g%bathyT(i,j) + htolerance) \textcolor{keywordflow}{then}
730       eta(i,j,nz+1) = -g%bathyT(i,j)
731       contractions = contractions + 1
732 \textcolor{keywordflow}{    endif}
733 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
734   \textcolor{keyword}{call }sum\_across\_pes(contractions)
735   \textcolor{keywordflow}{if} ((contractions > 0) .and. (is\_root\_pe())) \textcolor{keywordflow}{then}
736     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("Thickness initial conditions were contracted ",'}// &
737                \textcolor{stringliteral}{'"to fit topography in ",I8," places.")'}) contractions
738     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{'adjustEtaToFitBathymetry: '}//mesg)
739 \textcolor{keywordflow}{  endif}
740 
741   \textcolor{comment}{!   To preserve previous answers in non-Boussinesq cases, delay converting}
742   \textcolor{comment}{! thicknesses to units of H until the end of this routine.}
743   \textcolor{keywordflow}{do} k=nz,1,-1 ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
744     \textcolor{comment}{! Collapse layers to thinnest possible if the thickness less than}
745     \textcolor{comment}{! the thinnest possible (or negative).}
746     \textcolor{keywordflow}{if} (eta(i,j,k) < (eta(i,j,k+1) + gv%Angstrom\_Z)) \textcolor{keywordflow}{then}
747       eta(i,j,k) = eta(i,j,k+1) + gv%Angstrom\_Z
748       h(i,j,k) = gv%Angstrom\_Z
749     \textcolor{keywordflow}{else}
750       h(i,j,k) = (eta(i,j,k) - eta(i,j,k+1))
751 \textcolor{keywordflow}{    endif}
752 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
753 
754   dilations = 0
755   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
756     \textcolor{comment}{!   The whole column is dilated to accommodate deeper topography than}
757     \textcolor{comment}{! the bathymetry would indicate.}
758     \textcolor{comment}{! This should be...  if ((G%mask2dt(i,j)*(eta(i,j,1)-eta(i,j,nz+1)) > 0.0) .and. &}
759     \textcolor{keywordflow}{if} (-eta(i,j,nz+1) < g%bathyT(i,j) - htolerance) \textcolor{keywordflow}{then}
760       dilations = dilations + 1
761       \textcolor{keywordflow}{if} (eta(i,j,1) <= eta(i,j,nz+1)) \textcolor{keywordflow}{then}
762         \textcolor{keywordflow}{do} k=1,nz ; h(i,j,k) = (eta(i,j,1) + g%bathyT(i,j)) / \textcolor{keywordtype}{real(nz)} ; enddo
763       \textcolor{keywordflow}{else}
764         dilate = (eta(i,j,1) + g%bathyT(i,j)) / (eta(i,j,1) - eta(i,j,nz+1))
765         \textcolor{keywordflow}{do} k=1,nz ; h(i,j,k) = h(i,j,k) * dilate ;\textcolor{keywordflow}{ enddo}
766 \textcolor{keywordflow}{      endif}
767       \textcolor{keywordflow}{do} k=nz,2,-1 ; eta(i,j,k) = eta(i,j,k+1) + h(i,j,k) ;\textcolor{keywordflow}{ enddo}
768 \textcolor{keywordflow}{    endif}
769 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
770 
771   \textcolor{comment}{! Now convert thicknesses to units of H.}
772   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
773     h(i,j,k) = h(i,j,k)*gv%Z\_to\_H
774 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
775 
776   \textcolor{keyword}{call }sum\_across\_pes(dilations)
777   \textcolor{keywordflow}{if} ((dilations > 0) .and. (is\_root\_pe())) \textcolor{keywordflow}{then}
778     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("Thickness initial conditions were dilated ",'}// &
779                \textcolor{stringliteral}{'"to fit topography in ",I8," places.")'}) dilations
780     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{'adjustEtaToFitBathymetry: '}//mesg)
781 \textcolor{keywordflow}{  endif}
782 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_aebc1c5c12c684e398074f2f56bc61d97}\label{namespacemom__state__initialization_aebc1c5c12c684e398074f2f56bc61d97}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!compute\+\_\+global\+\_\+grid\+\_\+integrals@{compute\+\_\+global\+\_\+grid\+\_\+integrals}}
\index{compute\+\_\+global\+\_\+grid\+\_\+integrals@{compute\+\_\+global\+\_\+grid\+\_\+integrals}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{compute\+\_\+global\+\_\+grid\+\_\+integrals()}{compute\_global\_grid\_integrals()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::compute\+\_\+global\+\_\+grid\+\_\+integrals (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Subroutine to pre-\/compute global integrals of grid quantities for later use in reporting diagnostics. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type \\
\hline
\end{DoxyParams}


Definition at line 1933 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
1933   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{ !< The ocean's grid structure}
1934   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{ !< A dimensional unit scaling type}
1935   \textcolor{comment}{! Local variables}
1936   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isc:G%iec, G%jsc:G%jec)} :: tmpforsumming
1937   \textcolor{keywordtype}{real} :: area\_scale
1938   \textcolor{keywordtype}{integer} :: i,j
1939 
1940   area\_scale = us%L\_to\_m**2
1941   tmpforsumming(:,:) = 0.
1942   g%areaT\_global = 0.0 ; g%IareaT\_global = 0.0
1943   \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
1944     tmpforsumming(i,j) = area\_scale*g%areaT(i,j) * g%mask2dT(i,j)
1945 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1946   g%areaT\_global = \hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}(tmpforsumming)
1947   g%IareaT\_global = 1. / (g%areaT\_global)
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_a9b4e1b8c587fb11f1ec78e7e30215913}\label{namespacemom__state__initialization_a9b4e1b8c587fb11f1ec78e7e30215913}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!convert\+\_\+thickness@{convert\+\_\+thickness}}
\index{convert\+\_\+thickness@{convert\+\_\+thickness}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{convert\+\_\+thickness()}{convert\_thickness()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::convert\+\_\+thickness (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{h,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Converts thickness from geometric to pressure units. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in,out}  & {\em h} & Input geometric layer thicknesses being converted\\
\hline
\mbox{\tt in}  & {\em tv} & A structure pointing to various thermodynamic variables \\
\hline
\end{DoxyParams}


Definition at line 923 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
923   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{  !< The ocean's grid structure}
924   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{ !< The ocean's vertical grid structure}
925   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{ !< A dimensional unit scaling type}
926   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
927                            \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{  !< Input geometric layer thicknesses being converted}
928 \textcolor{comment}{                                               !! to layer pressure [H ~> m or kg m-2].}
929   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{ !< A structure pointing to various}
930 \textcolor{comment}{                                               !! thermodynamic variables}
931   \textcolor{comment}{! Local variables}
932   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: &
933     p\_top, p\_bot                  \textcolor{comment}{! Pressure at the interfaces above and below a layer [R L2 T-2 ~> Pa]}
934   \textcolor{keywordtype}{real} :: dz\_geo(szi\_(g),szj\_(g)) \textcolor{comment}{! The change in geopotential height across a layer [L2 T-2 ~> m2 s-2]}
935   \textcolor{keywordtype}{real} :: rho(szi\_(g))            \textcolor{comment}{! The in situ density [R ~> kg m-3]}
936   \textcolor{keywordtype}{real} :: i\_gearth      \textcolor{comment}{! Unit conversion factors divided by the gravitational acceleration}
937                         \textcolor{comment}{! [H T2 R-1 L-2 ~> s2 m2 kg-1 or s2 m-1]}
938   \textcolor{keywordtype}{real} :: hr\_to\_pres    \textcolor{comment}{! A conversion factor from the input geometric thicknesses times the layer}
939                         \textcolor{comment}{! densities into pressure units [L2 T-2 H-1 ~> m s-2 or m4 kg-1 s-2].}
940   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: eosdom \textcolor{comment}{! The i-computational domain for the equation of state}
941   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, isq, ieq, jsq, jeq, nz
942   \textcolor{keywordtype}{integer} :: itt, max\_itt
943 
944   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
945   isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
946   max\_itt = 10
947 
948   \textcolor{keywordflow}{if} (gv%Boussinesq) \textcolor{keywordflow}{then}
949     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"Not yet converting thickness with Boussinesq approx."})
950   \textcolor{keywordflow}{else}
951     i\_gearth = gv%RZ\_to\_H / gv%g\_Earth
952     hr\_to\_pres = gv%g\_Earth * gv%H\_to\_Z
953 
954     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%eqn\_of\_state)) \textcolor{keywordflow}{then}
955       \textcolor{keywordflow}{do} j=jsq,jeq+1 ; \textcolor{keywordflow}{do} i=isq,ieq+1
956         p\_bot(i,j) = 0.0 ; p\_top(i,j) = 0.0
957 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
958       eosdom(:) = eos\_domain(g%HI)
959       \textcolor{keywordflow}{do} k=1,nz
960         \textcolor{keywordflow}{do} j=js,je
961           \textcolor{keywordflow}{do} i=is,ie ; p\_top(i,j) = p\_bot(i,j) ;\textcolor{keywordflow}{ enddo}
962           \textcolor{keyword}{call }calculate\_density(tv%T(:,j,k), tv%S(:,j,k), p\_top(:,j), rho, &
963                                  tv%eqn\_of\_state, eosdom)
964           \textcolor{keywordflow}{do} i=is,ie
965             p\_bot(i,j) = p\_top(i,j) + hr\_to\_pres * (h(i,j,k) * rho(i))
966 \textcolor{keywordflow}{          enddo}
967 \textcolor{keywordflow}{        enddo}
968 
969         \textcolor{keywordflow}{do} itt=1,max\_itt
970           \textcolor{keyword}{call }int\_specific\_vol\_dp(tv%T(:,:,k), tv%S(:,:,k), p\_top, p\_bot, 0.0, g%HI, &
971                                    tv%eqn\_of\_state, us, dz\_geo)
972           \textcolor{keywordflow}{if} (itt < max\_itt) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js,je
973             \textcolor{keyword}{call }calculate\_density(tv%T(:,j,k), tv%S(:,j,k), p\_bot(:,j), rho, &
974                                    tv%eqn\_of\_state, eosdom)
975             \textcolor{comment}{! Use Newton's method to correct the bottom value.}
976             \textcolor{comment}{! The hydrostatic equation is sufficiently linear that no bounds-checking is needed.}
977             \textcolor{keywordflow}{do} i=is,ie
978               p\_bot(i,j) = p\_bot(i,j) + rho(i) * (hr\_to\_pres*h(i,j,k) - dz\_geo(i,j))
979 \textcolor{keywordflow}{            enddo}
980 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ endif}
981 \textcolor{keywordflow}{        enddo}
982 
983         \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
984           h(i,j,k) = (p\_bot(i,j) - p\_top(i,j)) * i\_gearth
985 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
986 \textcolor{keywordflow}{      enddo}
987     \textcolor{keywordflow}{else}
988       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
989         h(i,j,k) = h(i,j,k) * (gv%Rlay(k) / gv%Rho0)
990 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
991 \textcolor{keywordflow}{    endif}
992 \textcolor{keywordflow}{  endif}
993 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_a214d4aa46f0374e29369282389f40de7}\label{namespacemom__state__initialization_a214d4aa46f0374e29369282389f40de7}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!cut\+\_\+off\+\_\+column\+\_\+top@{cut\+\_\+off\+\_\+column\+\_\+top}}
\index{cut\+\_\+off\+\_\+column\+\_\+top@{cut\+\_\+off\+\_\+column\+\_\+top}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{cut\+\_\+off\+\_\+column\+\_\+top()}{cut\_off\_column\_top()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::cut\+\_\+off\+\_\+column\+\_\+top (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{nk,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, intent(in)}]{G\+\_\+earth,  }\item[{real, intent(in)}]{depth,  }\item[{real, intent(in)}]{min\+\_\+thickness,  }\item[{real, dimension(nk), intent(inout)}]{T,  }\item[{real, dimension(nk), intent(in)}]{T\+\_\+t,  }\item[{real, dimension(nk), intent(in)}]{T\+\_\+b,  }\item[{real, dimension(nk), intent(inout)}]{S,  }\item[{real, dimension(nk), intent(in)}]{S\+\_\+t,  }\item[{real, dimension(nk), intent(in)}]{S\+\_\+b,  }\item[{real, intent(in)}]{p\+\_\+surf,  }\item[{real, dimension(nk), intent(inout)}]{h,  }\item[{type(remapping\+\_\+cs), pointer}]{remap\+\_\+\+CS,  }\item[{real, intent(in), optional}]{z\+\_\+tol,  }\item[{logical, intent(in), optional}]{remap\+\_\+answers\+\_\+2018 }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Adjust the layer thicknesses by removing the top of the water column above the depth where the hydrostatic pressure matches p\+\_\+surf. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em nk} & Number of layers\\
\hline
\mbox{\tt in}  & {\em tv} & Thermodynamics structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em g\+\_\+earth} & Gravitational acceleration \mbox{[}L2 Z-\/1 T-\/2 $\sim$$>$ m s-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em depth} & Depth of ocean column \mbox{[}Z $\sim$$>$ m\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em min\+\_\+thickness} & Smallest thickness allowed \mbox{[}Z $\sim$$>$ m\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em t} & Layer mean temperature \mbox{[}degC\mbox{]}\\
\hline
\mbox{\tt in}  & {\em t\+\_\+t} & Temperature at top of layer \mbox{[}degC\mbox{]}\\
\hline
\mbox{\tt in}  & {\em t\+\_\+b} & Temperature at bottom of layer \mbox{[}degC\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em s} & Layer mean salinity \mbox{[}ppt\mbox{]}\\
\hline
\mbox{\tt in}  & {\em s\+\_\+t} & Salinity at top of layer \mbox{[}ppt\mbox{]}\\
\hline
\mbox{\tt in}  & {\em s\+\_\+b} & Salinity at bottom of layer \mbox{[}ppt\mbox{]}\\
\hline
\mbox{\tt in}  & {\em p\+\_\+surf} & Imposed pressure on ocean at surface \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
 & {\em remap\+\_\+cs} & Remapping structure for remapping T and S, if associated\\
\hline
\mbox{\tt in}  & {\em z\+\_\+tol} & The tolerance with which to find the depth matching the specified pressure \mbox{[}Z $\sim$$>$ m\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em remap\+\_\+answers\+\_\+2018} & If true, use the order of arithmetic and expressions that recover the answers for remapping from the end of 2018. Otherwise, use more robust forms of the same expressions. \\
\hline
\end{DoxyParams}


Definition at line 1173 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
1173   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: nk\textcolor{comment}{  !< Number of layers}
1174   \textcolor{keywordtype}{type}(thermo\_var\_ptrs), \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{  !< Thermodynamics structure}
1175   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}  :: gv\textcolor{comment}{  !< The ocean's vertical grid structure.}
1176   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}  :: us\textcolor{comment}{  !< A dimensional unit scaling type}
1177   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(in)}    :: g\_earth\textcolor{comment}{ !< Gravitational acceleration [L2 Z-1 T-2 ~> m s-2]}
1178   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(in)}    :: depth\textcolor{comment}{ !< Depth of ocean column [Z ~> m].}
1179   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(in)}    :: min\_thickness\textcolor{comment}{ !< Smallest thickness allowed [Z ~> m].}
1180   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)},   \textcolor{keywordtype}{intent(inout)} :: t\textcolor{comment}{   !< Layer mean temperature [degC]}
1181   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)},   \textcolor{keywordtype}{intent(in)}    :: t\_t\textcolor{comment}{ !< Temperature at top of layer [degC]}
1182   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)},   \textcolor{keywordtype}{intent(in)}    :: t\_b\textcolor{comment}{ !< Temperature at bottom of layer [degC]}
1183   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)},   \textcolor{keywordtype}{intent(inout)} :: s\textcolor{comment}{   !< Layer mean salinity [ppt]}
1184   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)},   \textcolor{keywordtype}{intent(in)}    :: s\_t\textcolor{comment}{ !< Salinity at top of layer [ppt]}
1185   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)},   \textcolor{keywordtype}{intent(in)}    :: s\_b\textcolor{comment}{ !< Salinity at bottom of layer [ppt]}
1186   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(in)}    :: p\_surf\textcolor{comment}{ !< Imposed pressure on ocean at surface [R L2 T-2 ~> Pa]}
1187   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)},   \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{   !< Layer thickness [H ~> m or kg m-2]}
1188   \textcolor{keywordtype}{type}(remapping\_cs),    \textcolor{keywordtype}{pointer}       :: remap\_cs\textcolor{comment}{ !< Remapping structure for remapping T and S,}
1189 \textcolor{comment}{                                                   !! if associated}
1190   \textcolor{keywordtype}{real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: z\_tol\textcolor{comment}{ !< The tolerance with which to find the depth}
1191 \textcolor{comment}{                                                !! matching the specified pressure [Z ~> m].}
1192   \textcolor{keywordtype}{logical},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: remap\_answers\_2018\textcolor{comment}{ !< If true, use the order of arithmetic}
1193 \textcolor{comment}{                                                !! and expressions that recover the answers for remapping}
1194 \textcolor{comment}{                                                !! from the end of 2018. Otherwise, use more robust}
1195 \textcolor{comment}{                                                !! forms of the same expressions.}
1196 
1197   \textcolor{comment}{! Local variables}
1198   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk+1)} :: e \textcolor{comment}{! Top and bottom edge values for reconstructions [Z ~> m]}
1199   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)} :: h0, s0, t0, h1, s1, t1
1200   \textcolor{keywordtype}{real} :: p\_t, p\_b  \textcolor{comment}{! Top and bottom pressures [R L2 T-2 ~> Pa]}
1201   \textcolor{keywordtype}{real} :: z\_out, e\_top
1202   \textcolor{keywordtype}{logical} :: answers\_2018
1203   \textcolor{keywordtype}{integer} :: k
1204 
1205   answers\_2018 = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(remap\_answers\_2018)) answers\_2018 = remap\_answers\_2018
1206 
1207   \textcolor{comment}{! Calculate original interface positions}
1208   e(nk+1) = -depth
1209   \textcolor{keywordflow}{do} k=nk,1,-1
1210     e(k) = e(k+1) + gv%H\_to\_Z*h(k)
1211     h0(k) = h(nk+1-k) \textcolor{comment}{! Keep a copy to use in remapping}
1212 \textcolor{keywordflow}{  enddo}
1213 
1214   p\_t = 0.
1215   e\_top = e(1)
1216   \textcolor{keywordflow}{do} k=1,nk
1217     \textcolor{keyword}{call }find\_depth\_of\_pressure\_in\_cell(t\_t(k), t\_b(k), s\_t(k), s\_b(k), e(k), e(k+1), &
1218                                         p\_t, p\_surf, gv%Rho0, g\_earth, tv%eqn\_of\_state, &
1219                                         us, p\_b, z\_out, z\_tol=z\_tol)
1220     \textcolor{keywordflow}{if} (z\_out>=e(k)) \textcolor{keywordflow}{then}
1221       \textcolor{comment}{! Imposed pressure was less that pressure at top of cell}
1222       \textcolor{keywordflow}{exit}
1223     \textcolor{keywordflow}{elseif} (z\_out<=e(k+1)) \textcolor{keywordflow}{then}
1224       \textcolor{comment}{! Imposed pressure was greater than pressure at bottom of cell}
1225       e\_top = e(k+1)
1226     \textcolor{keywordflow}{else}
1227       \textcolor{comment}{! Imposed pressure was fell between pressures at top and bottom of cell}
1228       e\_top = z\_out
1229       \textcolor{keywordflow}{exit}
1230 \textcolor{keywordflow}{    endif}
1231     p\_t = p\_b
1232 \textcolor{keywordflow}{  enddo}
1233   \textcolor{keywordflow}{if} (e\_top<e(1)) \textcolor{keywordflow}{then}
1234     \textcolor{comment}{! Clip layers from the top down, if at all}
1235     \textcolor{keywordflow}{do} k=1,nk
1236       \textcolor{keywordflow}{if} (e(k) > e\_top) \textcolor{keywordflow}{then}
1237         \textcolor{comment}{! Original e(K) is too high}
1238         e(k) = e\_top
1239         e\_top = e\_top - min\_thickness \textcolor{comment}{! Next interface must be at least this deep}
1240 \textcolor{keywordflow}{      endif}
1241       \textcolor{comment}{! This layer needs trimming}
1242       h(k) = gv%Z\_to\_H * max( min\_thickness, e(k) - e(k+1) )
1243       \textcolor{keywordflow}{if} (e(k) < e\_top) \textcolor{keywordflow}{exit} \textcolor{comment}{! No need to go further}
1244 \textcolor{keywordflow}{    enddo}
1245 \textcolor{keywordflow}{  endif}
1246 
1247   \textcolor{comment}{! Now we need to remap but remapping assumes the surface is at the}
1248   \textcolor{comment}{! same place in the two columns so we turn the column upside down.}
1249   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(remap\_cs)) \textcolor{keywordflow}{then}
1250     \textcolor{keywordflow}{do} k=1,nk
1251       s0(k) = s(nk+1-k)
1252       t0(k) = t(nk+1-k)
1253       h1(k) = h(nk+1-k)
1254 \textcolor{keywordflow}{    enddo}
1255     \textcolor{keywordflow}{if} (answers\_2018) \textcolor{keywordflow}{then}
1256       \textcolor{keyword}{call }remapping\_core\_h(remap\_cs, nk, h0, t0, nk, h1, t1, 1.0e-30*gv%m\_to\_H, 1.0e-10*gv%m\_to\_H)
1257       \textcolor{keyword}{call }remapping\_core\_h(remap\_cs, nk, h0, s0, nk, h1, s1, 1.0e-30*gv%m\_to\_H, 1.0e-10*gv%m\_to\_H)
1258     \textcolor{keywordflow}{else}
1259       \textcolor{keyword}{call }remapping\_core\_h(remap\_cs, nk, h0, t0, nk, h1, t1, gv%H\_subroundoff, gv%H\_subroundoff)
1260       \textcolor{keyword}{call }remapping\_core\_h(remap\_cs, nk, h0, s0, nk, h1, s1, gv%H\_subroundoff, gv%H\_subroundoff)
1261 \textcolor{keywordflow}{    endif}
1262     \textcolor{keywordflow}{do} k=1,nk
1263       s(k) = s1(nk+1-k)
1264       t(k) = t1(nk+1-k)
1265 \textcolor{keywordflow}{    enddo}
1266 \textcolor{keywordflow}{  endif}
1267 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_aad295781ac5adccf3a80e2323ce77905}\label{namespacemom__state__initialization_aad295781ac5adccf3a80e2323ce77905}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!depress\+\_\+surface@{depress\+\_\+surface}}
\index{depress\+\_\+surface@{depress\+\_\+surface}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{depress\+\_\+surface()}{depress\_surface()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::depress\+\_\+surface (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{h,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{logical, intent(in), optional}]{just\+\_\+read\+\_\+params }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Depress the sea-\/surface based on an initial condition file. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in,out}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters\\
\hline
\mbox{\tt in}  & {\em tv} & A structure pointing to various thermodynamic variables\\
\hline
\mbox{\tt in}  & {\em just\+\_\+read\+\_\+params} & If present and true, this call will only read parameters without changing h. \\
\hline
\end{DoxyParams}


Definition at line 998 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
998   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{    !< The ocean's grid structure}
999   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !< The ocean's vertical grid structure}
1000   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
1001   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
1002                            \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-2]}
1003   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< A structure to parse for run-time parameters}
1004   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{   !< A structure pointing to various thermodynamic variables}
1005   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: just\_read\_params\textcolor{comment}{ !< If present and true, this call will}
1006 \textcolor{comment}{                                                      !! only read parameters without changing h.}
1007   \textcolor{comment}{! Local variables}
1008   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: &
1009     eta\_sfc  \textcolor{comment}{! The free surface height that the model should use [Z ~> m].}
1010   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)} :: &
1011     eta  \textcolor{comment}{! The free surface height that the model should use [Z ~> m].}
1012   \textcolor{keywordtype}{real} :: dilate  \textcolor{comment}{! A ratio by which layers are dilated [nondim].}
1013   \textcolor{keywordtype}{real} :: scale\_factor \textcolor{comment}{! A scaling factor for the eta\_sfc values that are read}
1014                        \textcolor{comment}{! in, which can be used to change units, for example.}
1015   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"depress\_surface"} \textcolor{comment}{! This subroutine's name.}
1016   \textcolor{keywordtype}{character(len=200)} :: inputdir, eta\_srf\_file \textcolor{comment}{! Strings for file/path}
1017   \textcolor{keywordtype}{character(len=200)} :: filename, eta\_srf\_var  \textcolor{comment}{! Strings for file/path}
1018   \textcolor{keywordtype}{logical} :: just\_read    \textcolor{comment}{! If true, just read parameters but set nothing.}
1019   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz
1020   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
1021 
1022   just\_read = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(just\_read\_params)) just\_read = just\_read\_params
1023 
1024   \textcolor{comment}{! Read the surface height (or pressure) from a file.}
1025 
1026   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."})
1027   inputdir = slasher(inputdir)
1028   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SURFACE\_HEIGHT\_IC\_FILE"}, eta\_srf\_file,&
1029                  \textcolor{stringliteral}{"The initial condition file for the surface height."}, &
1030                  fail\_if\_missing=.not.just\_read, do\_not\_log=just\_read)
1031   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SURFACE\_HEIGHT\_IC\_VAR"}, eta\_srf\_var, &
1032                  \textcolor{stringliteral}{"The initial condition variable for the surface height."},&
1033                  default=\textcolor{stringliteral}{"SSH"}, do\_not\_log=just\_read)
1034   filename = trim(inputdir)//trim(eta\_srf\_file)
1035   \textcolor{keywordflow}{if} (.not.just\_read) &
1036     \textcolor{keyword}{call }log\_param(param\_file,  mdl, \textcolor{stringliteral}{"INPUTDIR/SURFACE\_HEIGHT\_IC\_FILE"}, filename)
1037 
1038   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SURFACE\_HEIGHT\_IC\_SCALE"}, scale\_factor, &
1039                  \textcolor{stringliteral}{"A scaling factor to convert SURFACE\_HEIGHT\_IC\_VAR into units of m"}, &
1040                  units=\textcolor{stringliteral}{"variable"}, default=1.0, scale=us%m\_to\_Z, do\_not\_log=just\_read)
1041 
1042   \textcolor{keywordflow}{if} (just\_read) \textcolor{keywordflow}{return} \textcolor{comment}{! All run-time parameters have been read, so return.}
1043 
1044   \textcolor{keyword}{call }mom\_read\_data(filename, eta\_srf\_var, eta\_sfc, g%Domain, scale=scale\_factor)
1045 
1046   \textcolor{comment}{! Convert thicknesses to interface heights.}
1047   \textcolor{keyword}{call }find\_eta(h, tv, g, gv, us, eta)
1048 
1049   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (g%mask2dT(i,j) > 0.0) \textcolor{keywordflow}{then}
1050 \textcolor{comment}{!    if (eta\_sfc(i,j) < eta(i,j,nz+1)) then}
1051       \textcolor{comment}{! Issue a warning?}
1052 \textcolor{comment}{!    endif}
1053     \textcolor{keywordflow}{if} (eta\_sfc(i,j) > eta(i,j,1)) \textcolor{keywordflow}{then}
1054       \textcolor{comment}{! Dilate the water column to agree, but only up to 10-fold.}
1055       \textcolor{keywordflow}{if} (eta\_sfc(i,j) - eta(i,j,nz+1) > 10.0*(eta(i,j,1) - eta(i,j,nz+1))) \textcolor{keywordflow}{then}
1056         dilate = 10.0
1057         \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"Free surface height dilation attempted "}//&
1058                \textcolor{stringliteral}{"to exceed 10-fold."}, all\_print=.true.)
1059       \textcolor{keywordflow}{else}
1060         dilate = (eta\_sfc(i,j) - eta(i,j,nz+1)) / (eta(i,j,1) - eta(i,j,nz+1))
1061 \textcolor{keywordflow}{      endif}
1062       \textcolor{keywordflow}{do} k=1,nz ; h(i,j,k) = h(i,j,k) * dilate ;\textcolor{keywordflow}{ enddo}
1063     \textcolor{keywordflow}{elseif} (eta(i,j,1) > eta\_sfc(i,j)) \textcolor{keywordflow}{then}
1064       \textcolor{comment}{! Remove any mass that is above the target free surface.}
1065       \textcolor{keywordflow}{do} k=1,nz
1066         \textcolor{keywordflow}{if} (eta(i,j,k) <= eta\_sfc(i,j)) \textcolor{keywordflow}{exit}
1067         \textcolor{keywordflow}{if} (eta(i,j,k+1) >= eta\_sfc(i,j)) \textcolor{keywordflow}{then}
1068           h(i,j,k) = gv%Angstrom\_H
1069         \textcolor{keywordflow}{else}
1070           h(i,j,k) = max(gv%Angstrom\_H, h(i,j,k) * &
1071               (eta\_sfc(i,j) - eta(i,j,k+1)) / (eta(i,j,k) - eta(i,j,k+1)) )
1072 \textcolor{keywordflow}{        endif}
1073 \textcolor{keywordflow}{      enddo}
1074 \textcolor{keywordflow}{    endif}
1075 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1076 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_a526e4ed5e2543f0d7bec8bc0dde37ae2}\label{namespacemom__state__initialization_a526e4ed5e2543f0d7bec8bc0dde37ae2}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!find\+\_\+interfaces@{find\+\_\+interfaces}}
\index{find\+\_\+interfaces@{find\+\_\+interfaces}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{find\+\_\+interfaces()}{find\_interfaces()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::find\+\_\+interfaces (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed,nk\+\_\+data), intent(in)}]{rho,  }\item[{real, dimension(nk\+\_\+data), intent(in)}]{zin,  }\item[{integer, intent(in)}]{nk\+\_\+data,  }\item[{real, dimension( g \%ke+1), intent(in)}]{Rb,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{depth,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke+1), intent(out)}]{zi,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{integer, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{nlevs,  }\item[{integer, intent(in)}]{nkml,  }\item[{real, intent(in)}]{hml,  }\item[{real, intent(in)}]{eps\+\_\+z,  }\item[{real, intent(in)}]{eps\+\_\+rho }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Find interface positions corresponding to interpolated depths in a density profile. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em nk\+\_\+data} & The number of levels in the input data\\
\hline
\mbox{\tt in}  & {\em rho} & Potential density in z-\/space \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]}\\
\hline
\mbox{\tt in}  & {\em zin} & Input data levels \mbox{[}Z $\sim$$>$ m\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em rb} & target interface densities \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]}\\
\hline
\mbox{\tt in}  & {\em depth} & ocean depth \mbox{[}Z $\sim$$>$ m\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em zi} & The returned interface heights \mbox{[}Z $\sim$$>$ m\mbox{]}\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em nlevs} & number of valid points in each column\\
\hline
\mbox{\tt in}  & {\em nkml} & number of mixed layer pieces to distribute over a depth of hml.\\
\hline
\mbox{\tt in}  & {\em hml} & mixed layer depth \mbox{[}Z $\sim$$>$ m\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em eps\+\_\+z} & A negligibly small layer thickness \mbox{[}Z $\sim$$>$ m\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em eps\+\_\+rho} & A negligibly small density difference \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 2454 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
2454   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{     !< The ocean's grid structure}
2455   \textcolor{keywordtype}{integer},                    \textcolor{keywordtype}{intent(in)}  :: nk\_data\textcolor{comment}{ !< The number of levels in the input data}
2456   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),nk\_data)}, &
2457                               \textcolor{keywordtype}{intent(in)}  :: rho\textcolor{comment}{   !< Potential density in z-space [R ~> kg m-3]}
2458   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk\_data)},   \textcolor{keywordtype}{intent(in)}  :: zin\textcolor{comment}{   !< Input data levels [Z ~> m].}
2459   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(G)+1)}, \textcolor{keywordtype}{intent(in)}  :: rb\textcolor{comment}{    !< target interface densities [R ~> kg m-3]}
2460   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
2461                               \textcolor{keywordtype}{intent(in)}  :: depth\textcolor{comment}{ !< ocean depth [Z ~> m].}
2462   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, &
2463                               \textcolor{keywordtype}{intent(out)} :: zi\textcolor{comment}{    !< The returned interface heights [Z ~> m]}
2464   \textcolor{keywordtype}{type}(unit\_scale\_type),      \textcolor{keywordtype}{intent(in)}  :: us\textcolor{comment}{    !< A dimensional unit scaling type}
2465   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
2466                               \textcolor{keywordtype}{intent(in)}  :: nlevs\textcolor{comment}{ !< number of valid points in each column}
2467   \textcolor{keywordtype}{integer},                    \textcolor{keywordtype}{intent(in)}  :: nkml\textcolor{comment}{  !< number of mixed layer pieces to distribute over}
2468 \textcolor{comment}{                                                   !! a depth of hml.}
2469   \textcolor{keywordtype}{real},                       \textcolor{keywordtype}{intent(in)}  :: hml\textcolor{comment}{   !< mixed layer depth [Z ~> m].}
2470   \textcolor{keywordtype}{real},                       \textcolor{keywordtype}{intent(in)}  :: eps\_z\textcolor{comment}{ !< A negligibly small layer thickness [Z ~> m].}
2471   \textcolor{keywordtype}{real},                       \textcolor{keywordtype}{intent(in)}  :: eps\_rho\textcolor{comment}{ !< A negligibly small density difference [R ~> kg
       m-3].}
2472 
2473   \textcolor{comment}{! Local variables}
2474   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk\_data)} :: rho\_ \textcolor{comment}{! A column of densities [R ~> kg m-3]}
2475   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(G)+1)} :: zi\_ \textcolor{comment}{! A column interface heights (negative downward) [Z ~> m].}
2476   \textcolor{keywordtype}{real}    :: slope      \textcolor{comment}{! The rate of change of height with density [Z R-1 ~> m4 kg-1]}
2477   \textcolor{keywordtype}{real}    :: drhodz     \textcolor{comment}{! A local vertical density gradient [R Z-1 ~> kg m-4]}
2478   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter} :: zoff=0.999
2479   \textcolor{keywordtype}{logical} :: unstable   \textcolor{comment}{! True if the column is statically unstable anywhere.}
2480   \textcolor{keywordtype}{integer} :: nlevs\_data \textcolor{comment}{! The number of data values in a column.}
2481   \textcolor{keywordtype}{logical} :: work\_down  \textcolor{comment}{! This indicates whether this pass goes up or down the water column.}
2482   \textcolor{keywordtype}{integer} :: k\_int, lo\_int, hi\_int, mid
2483   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz
2484 
2485   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
2486 
2487   zi(:,:,:) = 0.0
2488 
2489   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
2490     nlevs\_data = nlevs(i,j)
2491     \textcolor{keywordflow}{do} k=1,nlevs\_data ; rho\_(k) = rho(i,j,k) ;\textcolor{keywordflow}{ enddo}
2492 
2493     unstable=.true.
2494     work\_down = .true.
2495     \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (unstable)
2496       \textcolor{comment}{! Modifiy the input profile until it no longer has densities that decrease with depth.}
2497       unstable=.false.
2498       \textcolor{keywordflow}{if} (work\_down) \textcolor{keywordflow}{then}
2499         \textcolor{keywordflow}{do} k=2,nlevs\_data-1 ; \textcolor{keywordflow}{if} (rho\_(k) - rho\_(k-1) < 0.0 ) \textcolor{keywordflow}{then}
2500           \textcolor{keywordflow}{if} (k == 2) \textcolor{keywordflow}{then}
2501             rho\_(k-1) = rho\_(k) - eps\_rho
2502           \textcolor{keywordflow}{else}
2503             drhodz = (rho\_(k+1)-rho\_(k-1)) / (zin(k+1)-zin(k-1))
2504             \textcolor{keywordflow}{if} (drhodz < 0.0) unstable=.true.
2505             rho\_(k) = rho\_(k-1) + drhodz*zoff*(zin(k)-zin(k-1))
2506 \textcolor{keywordflow}{          endif}
2507 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo}
2508         work\_down = .false.
2509       \textcolor{keywordflow}{else}
2510         \textcolor{keywordflow}{do} k=nlevs\_data-1,2,-1 ;  \textcolor{keywordflow}{if} (rho\_(k+1) - rho\_(k) < 0.0) \textcolor{keywordflow}{then}
2511           \textcolor{keywordflow}{if} (k == nlevs\_data-1) \textcolor{keywordflow}{then}
2512             rho\_(k+1) = rho\_(k-1) + eps\_rho \textcolor{comment}{!### This should be rho\_(k) + eps\_rho}
2513           \textcolor{keywordflow}{else}
2514             drhodz = (rho\_(k+1)-rho\_(k-1)) / (zin(k+1)-zin(k-1))
2515             \textcolor{keywordflow}{if} (drhodz  < 0.0) unstable=.true.
2516             rho\_(k) = rho\_(k+1) - drhodz*(zin(k+1)-zin(k))
2517 \textcolor{keywordflow}{          endif}
2518 \textcolor{keywordflow}{        endif} ;\textcolor{keywordflow}{ enddo}
2519         work\_down = .true.
2520 \textcolor{keywordflow}{      endif}
2521 \textcolor{keywordflow}{    enddo}
2522 
2523     \textcolor{comment}{! Find and store the interface depths.}
2524     zi\_(1) = 0.0
2525     \textcolor{keywordflow}{do} k=2,nz
2526       \textcolor{comment}{! Find the value of k\_int in the list of rho\_ where rho\_(k\_int) <= Rb(K) < rho\_(k\_int+1).}
2527       \textcolor{comment}{! This might be made a little faster by exploiting the fact that Rb is}
2528       \textcolor{comment}{! monotonically increasing and not resetting lo\_int back to 1 inside the K loop.}
2529       lo\_int = 1 ; hi\_int = nlevs\_data
2530       \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (lo\_int < hi\_int)
2531         mid = (lo\_int+hi\_int) / 2
2532         \textcolor{keywordflow}{if} (rb(k) < rho\_(mid)) \textcolor{keywordflow}{then} ; hi\_int = mid
2533         \textcolor{keywordflow}{else} ; lo\_int = mid+1 ;\textcolor{keywordflow}{ endif}
2534 \textcolor{keywordflow}{      enddo}
2535       k\_int = max(1, lo\_int-1)
2536 
2537       \textcolor{comment}{! Linearly interpolate to find the depth, zi\_, where Rb would be found.}
2538       slope = (zin(k\_int+1) - zin(k\_int)) / max(rho\_(k\_int+1) - rho\_(k\_int), eps\_rho)
2539       zi\_(k) = -1.0*(zin(k\_int) + slope*(rb(k)-rho\_(k\_int)))
2540       zi\_(k) = min(max(zi\_(k), -depth(i,j)), -1.0*hml)
2541 \textcolor{keywordflow}{    enddo}
2542     zi\_(nz+1) = -depth(i,j)
2543     \textcolor{keywordflow}{if} (nkml > 0) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=2,nkml+1
2544       zi\_(k) = max(hml*((1.0-\textcolor{keywordtype}{real}(k))/\textcolor{keywordtype}{real}(nkml)), -depth(i,j))
2545 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}
2546     \textcolor{keywordflow}{do} k=nz,max(nkml+2,2),-1
2547       \textcolor{keywordflow}{if} (zi\_(k) < zi\_(k+1) + eps\_z) zi\_(k) = zi\_(k+1) + eps\_z
2548       \textcolor{keywordflow}{if} (zi\_(k) > -1.0*hml)  zi\_(k) = max(-1.0*hml, -depth(i,j))
2549 \textcolor{keywordflow}{    enddo}
2550 
2551     \textcolor{keywordflow}{do} k=1,nz+1
2552       zi(i,j,k) = zi\_(k)
2553 \textcolor{keywordflow}{    enddo}
2554 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} \textcolor{comment}{! i- and j- loops}
2555 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_ac672706eef5c8d6c07333f5e46e4cdff}\label{namespacemom__state__initialization_ac672706eef5c8d6c07333f5e46e4cdff}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!initialize\+\_\+sponges\+\_\+file@{initialize\+\_\+sponges\+\_\+file}}
\index{initialize\+\_\+sponges\+\_\+file@{initialize\+\_\+sponges\+\_\+file}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{initialize\+\_\+sponges\+\_\+file()}{initialize\_sponges\_file()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::initialize\+\_\+sponges\+\_\+file (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{logical, intent(in)}]{use\+\_\+temperature,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(sponge\+\_\+cs), pointer}]{Layer\+\_\+\+C\+Sp,  }\item[{type(ale\+\_\+sponge\+\_\+cs), pointer}]{A\+L\+E\+\_\+\+C\+Sp,  }\item[{type(time\+\_\+type), intent(in)}]{Time }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine sets the inverse restoration time (Idamp), and the values towards which the interface heights and an arbitrary number of tracers should be restored within each sponge. The interface height is always subject to damping, and must always be the first registered field. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em use\+\_\+temperature} & If true, T \& S are state variables.\\
\hline
\mbox{\tt in}  & {\em tv} & A structure pointing to various thermodynamic variables.\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters.\\
\hline
 & {\em layer\+\_\+csp} & A pointer that is set to point to the control structure for this module (in layered mode).\\
\hline
 & {\em ale\+\_\+csp} & A pointer that is set to point to the control structure for this module (in A\+LE mode).\\
\hline
\mbox{\tt in}  & {\em time} & Time at the start of the run segment. Time\+\_\+in overrides any value set for Time. \\
\hline
\end{DoxyParams}


Definition at line 1713 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
1713   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{    !< The ocean's grid structure.}
1714   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)} :: gv\textcolor{comment}{   !< The ocean's vertical grid structure.}
1715   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)} :: us\textcolor{comment}{  !< A dimensional unit scaling type}
1716   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(in)} :: use\_temperature\textcolor{comment}{ !< If true, T & S are state variables.}
1717   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(in)} :: tv\textcolor{comment}{   !< A structure pointing to various thermodynamic}
1718 \textcolor{comment}{                                              !! variables.}
1719   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< A structure to parse for run-time parameters.}
1720   \textcolor{keywordtype}{type}(sponge\_cs),         \textcolor{keywordtype}{pointer}    :: layer\_csp\textcolor{comment}{  !< A pointer that is set to point to the control}
1721 \textcolor{comment}{                                              !! structure for this module (in layered mode).}
1722   \textcolor{keywordtype}{type}(ale\_sponge\_cs),     \textcolor{keywordtype}{pointer}    :: ale\_csp\textcolor{comment}{  !< A pointer that is set to point to the control}
1723 \textcolor{comment}{                                                  !! structure for this module (in ALE mode).}
1724   \textcolor{keywordtype}{type}(time\_type),         \textcolor{keywordtype}{intent(in)} :: time\textcolor{comment}{ !< Time at the start of the run segment. Time\_in}
1725 \textcolor{comment}{                                              !! overrides any value set for Time.}
1726   \textcolor{comment}{! Local variables}
1727   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: eta \textcolor{comment}{! The target interface heights [Z ~> m].}
1728   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: h   \textcolor{comment}{! The target interface thicknesses [H ~> m or kg m-2].}
1729 
1730   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension (SZI\_(G),SZJ\_(G),SZK\_(G))} :: &
1731     tmp, tmp2 \textcolor{comment}{! A temporary array for tracers.}
1732   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension (SZI\_(G),SZJ\_(G))} :: &
1733     tmp\_2d \textcolor{comment}{! A temporary array for tracers.}
1734   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: tmp\_tr \textcolor{comment}{! A temporary array for reading sponge fields}
1735 
1736   \textcolor{keywordtype}{real} :: idamp(szi\_(g),szj\_(g))    \textcolor{comment}{! The inverse damping rate [T-1 ~> s-1].}
1737   \textcolor{keywordtype}{real} :: pres(szi\_(g))     \textcolor{comment}{! An array of the reference pressure [R L2 T-2 ~> Pa].}
1738 
1739   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: eosdom \textcolor{comment}{! The i-computational domain for the equation of state}
1740   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz
1741   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed
1742   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(4)} :: siz
1743   \textcolor{keywordtype}{integer} :: nz\_data  \textcolor{comment}{! The size of the sponge source grid}
1744   \textcolor{keywordtype}{character(len=40)} :: potemp\_var, salin\_var, idamp\_var, eta\_var
1745   \textcolor{keywordtype}{character(len=40)} :: mdl = \textcolor{stringliteral}{"initialize\_sponges\_file"}
1746   \textcolor{keywordtype}{character(len=200)} :: damping\_file, state\_file  \textcolor{comment}{! Strings for filenames}
1747   \textcolor{keywordtype}{character(len=200)} :: filename, inputdir \textcolor{comment}{! Strings for file/path and path.}
1748 
1749   \textcolor{keywordtype}{logical} :: use\_ale \textcolor{comment}{! True if ALE is being used, False if in layered mode}
1750   \textcolor{keywordtype}{logical} :: time\_space\_interp\_sponge \textcolor{comment}{! True if using sponge data which}
1751   \textcolor{comment}{! need to be interpolated from in both the horizontal dimension and in}
1752   \textcolor{comment}{! time prior to vertical remapping.}
1753 
1754 
1755   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
1756   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
1757 
1758   pres(:) = 0.0 ; tmp(:,:,:) = 0.0 ; idamp(:,:) = 0.0
1759 
1760   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."})
1761   inputdir = slasher(inputdir)
1762   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SPONGE\_DAMPING\_FILE"}, damping\_file, &
1763                  \textcolor{stringliteral}{"The name of the file with the sponge damping rates."}, &
1764                  fail\_if\_missing=.true.)
1765   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SPONGE\_STATE\_FILE"}, state\_file, &
1766                  \textcolor{stringliteral}{"The name of the file with the state to damp toward."}, &
1767                  default=damping\_file)
1768   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SPONGE\_PTEMP\_VAR"}, potemp\_var, &
1769                  \textcolor{stringliteral}{"The name of the potential temperature variable in "}//&
1770                  \textcolor{stringliteral}{"SPONGE\_STATE\_FILE."}, default=\textcolor{stringliteral}{"PTEMP"})
1771   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SPONGE\_SALT\_VAR"}, salin\_var, &
1772                  \textcolor{stringliteral}{"The name of the salinity variable in "}//&
1773                  \textcolor{stringliteral}{"SPONGE\_STATE\_FILE."}, default=\textcolor{stringliteral}{"SALT"})
1774   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SPONGE\_ETA\_VAR"}, eta\_var, &
1775                  \textcolor{stringliteral}{"The name of the interface height variable in "}//&
1776                  \textcolor{stringliteral}{"SPONGE\_STATE\_FILE."}, default=\textcolor{stringliteral}{"ETA"})
1777   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SPONGE\_IDAMP\_VAR"}, idamp\_var, &
1778                  \textcolor{stringliteral}{"The name of the inverse damping rate variable in "}//&
1779                  \textcolor{stringliteral}{"SPONGE\_DAMPING\_FILE."}, default=\textcolor{stringliteral}{"Idamp"})
1780   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_REGRIDDING"}, use\_ale, do\_not\_log = .true.)
1781   time\_space\_interp\_sponge = .false.
1782   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"NEW\_SPONGES"}, time\_space\_interp\_sponge, &
1783                  \textcolor{stringliteral}{"Set True if using the newer sponging code which "}//&
1784                  \textcolor{stringliteral}{"performs on-the-fly regridding in lat-lon-time."},&
1785                  \textcolor{stringliteral}{"of sponge restoring data."}, default=.false.)
1786   \textcolor{keywordflow}{if} (time\_space\_interp\_sponge) \textcolor{keywordflow}{then}
1787      \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{" initialize\_sponges:  NEW\_SPONGES has been deprecated. "}//&
1788           \textcolor{stringliteral}{"Please use INTERPOLATE\_SPONGE\_TIME\_SPACE instead. Setting "}//&
1789           \textcolor{stringliteral}{"INTERPOLATE\_SPONGE\_TIME\_SPACE = True."})
1790 \textcolor{keywordflow}{  endif}
1791   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERPOLATE\_SPONGE\_TIME\_SPACE"}, time\_space\_interp\_sponge, &
1792                  \textcolor{stringliteral}{"Set True if using the newer sponging code which "}//&
1793                  \textcolor{stringliteral}{"performs on-the-fly regridding in lat-lon-time."},&
1794                  \textcolor{stringliteral}{"of sponge restoring data."}, default=time\_space\_interp\_sponge)
1795 
1796   filename = trim(inputdir)//trim(damping\_file)
1797   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/SPONGE\_DAMPING\_FILE"}, filename)
1798   \textcolor{keywordflow}{if} (.not.file\_exists(filename, g%Domain)) &
1799     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{" initialize\_sponges: Unable to open "}//trim(filename))
1800 
1801   \textcolor{keywordflow}{if} (time\_space\_interp\_sponge .and. .not. use\_ale) &
1802     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{" initialize\_sponges: Time-varying sponges are currently unavailable in layered
       mode "})
1803 
1804   \textcolor{keyword}{call }mom\_read\_data(filename, idamp\_var, idamp(:,:), g%Domain, scale=us%T\_to\_s)
1805 
1806   \textcolor{comment}{! Now register all of the fields which are damped in the sponge.}
1807   \textcolor{comment}{! By default, momentum is advected vertically within the sponge, but}
1808   \textcolor{comment}{! momentum is typically not damped within the sponge.}
1809 
1810   filename = trim(inputdir)//trim(state\_file)
1811   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/SPONGE\_STATE\_FILE"}, filename)
1812   \textcolor{keywordflow}{if} (.not.file\_exists(filename, g%Domain)) &
1813     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{" initialize\_sponges: Unable to open "}//trim(filename))
1814 
1815 
1816   \textcolor{keywordflow}{if} (.not. use\_ale) \textcolor{keywordflow}{then}
1817     \textcolor{comment}{! The first call to set\_up\_sponge\_field is for the interface heights if in layered mode.}
1818     \textcolor{keyword}{allocate}(eta(isd:ied,jsd:jed,nz+1)); eta(:,:,:) = 0.0
1819     \textcolor{keyword}{call }mom\_read\_data(filename, eta\_var, eta(:,:,:), g%Domain, scale=us%m\_to\_Z)
1820 
1821     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1822       eta(i,j,nz+1) = -g%bathyT(i,j)
1823 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
1824     \textcolor{keywordflow}{do} k=nz,1,-1 ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1825       \textcolor{keywordflow}{if} (eta(i,j,k) < (eta(i,j,k+1) + gv%Angstrom\_Z)) &
1826         eta(i,j,k) = eta(i,j,k+1) + gv%Angstrom\_Z
1827 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1828     \textcolor{comment}{! Set the inverse damping rates so that the model will know where to}
1829     \textcolor{comment}{! apply the sponges, along with the interface heights.}
1830     \textcolor{keyword}{call }initialize\_sponge(idamp, eta, g, param\_file, layer\_csp, gv)
1831     \textcolor{keyword}{deallocate}(eta)
1832 
1833     \textcolor{keywordflow}{if} ( gv%nkml>0) \textcolor{keywordflow}{then}
1834       \textcolor{comment}{! This call to set\_up\_sponge\_ML\_density registers the target values of the}
1835       \textcolor{comment}{! mixed layer density, which is used in determining which layers can be}
1836       \textcolor{comment}{! inflated without causing static instabilities.}
1837       \textcolor{keywordflow}{do} i=is-1,ie ; pres(i) = tv%P\_Ref ;\textcolor{keywordflow}{ enddo}
1838       eosdom(:) = eos\_domain(g%HI)
1839 
1840       \textcolor{keyword}{call }mom\_read\_data(filename, potemp\_var, tmp(:,:,:), g%Domain)
1841       \textcolor{keyword}{call }mom\_read\_data(filename, salin\_var, tmp2(:,:,:), g%Domain)
1842 
1843       \textcolor{keywordflow}{do} j=js,je
1844         \textcolor{keyword}{call }calculate\_density(tmp(:,j,1), tmp2(:,j,1), pres, tmp\_2d(:,j), tv%eqn\_of\_state, eosdom)
1845 \textcolor{keywordflow}{      enddo}
1846 
1847       \textcolor{keyword}{call }set\_up\_sponge\_ml\_density(tmp\_2d, g, layer\_csp)
1848 \textcolor{keywordflow}{    endif}
1849 
1850    \textcolor{comment}{! Now register all of the tracer fields which are damped in the}
1851    \textcolor{comment}{! sponge. By default, momentum is advected vertically within the}
1852    \textcolor{comment}{! sponge, but momentum is typically not damped within the sponge.}
1853 
1854 
1855     \textcolor{comment}{! The remaining calls to set\_up\_sponge\_field can be in any order.}
1856     \textcolor{keywordflow}{if} ( use\_temperature) \textcolor{keywordflow}{then}
1857       \textcolor{keyword}{call }mom\_read\_data(filename, potemp\_var, tmp(:,:,:), g%Domain)
1858       \textcolor{keyword}{call }set\_up\_sponge\_field(tmp, tv%T, g, nz, layer\_csp)
1859       \textcolor{keyword}{call }mom\_read\_data(filename, salin\_var, tmp(:,:,:), g%Domain)
1860       \textcolor{keyword}{call }set\_up\_sponge\_field(tmp, tv%S, g, nz, layer\_csp)
1861 \textcolor{keywordflow}{    endif}
1862 
1863 \textcolor{keywordflow}{  endif}
1864 
1865 
1866   \textcolor{keywordflow}{if}  (use\_ale) \textcolor{keywordflow}{then}
1867     \textcolor{keywordflow}{if} (.not. time\_space\_interp\_sponge) \textcolor{keywordflow}{then} \textcolor{comment}{! ALE mode}
1868       \textcolor{keyword}{call }field\_size(filename,eta\_var,siz,no\_domain=.true.)
1869       \textcolor{keywordflow}{if} (siz(1) /= g%ieg-g%isg+1 .or. siz(2) /= g%jeg-g%jsg+1) &
1870         \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"initialize\_sponge\_file: Array size mismatch for sponge data."})
1871       nz\_data = siz(3)-1
1872       \textcolor{keyword}{allocate}(eta(isd:ied,jsd:jed,nz\_data+1))
1873       \textcolor{keyword}{allocate}(h(isd:ied,jsd:jed,nz\_data))
1874       \textcolor{keyword}{call }mom\_read\_data(filename, eta\_var, eta(:,:,:), g%Domain, scale=us%m\_to\_Z)
1875       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1876         eta(i,j,nz+1) = -g%bathyT(i,j)
1877 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
1878       \textcolor{keywordflow}{do} k=nz,1,-1 ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1879         \textcolor{keywordflow}{if} (eta(i,j,k) < (eta(i,j,k+1) + gv%Angstrom\_Z)) &
1880           eta(i,j,k) = eta(i,j,k+1) + gv%Angstrom\_Z
1881 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1882       \textcolor{keywordflow}{do} k=1,nz; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
1883         h(i,j,k) = gv%Z\_to\_H*(eta(i,j,k)-eta(i,j,k+1))
1884 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1885       \textcolor{keyword}{call }initialize\_ale\_sponge(idamp, g, param\_file, ale\_csp, h, nz\_data)
1886       \textcolor{keyword}{deallocate}(eta)
1887       \textcolor{keyword}{deallocate}(h)
1888       \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
1889         \textcolor{keyword}{allocate}(tmp\_tr(isd:ied,jsd:jed,nz\_data))
1890         \textcolor{keyword}{call }mom\_read\_data(filename, potemp\_var, tmp\_tr(:,:,:), g%Domain)
1891         \textcolor{keyword}{call }set\_up\_ale\_sponge\_field(tmp\_tr, g, tv%T, ale\_csp)
1892         \textcolor{keyword}{call }mom\_read\_data(filename, salin\_var, tmp\_tr(:,:,:), g%Domain)
1893         \textcolor{keyword}{call }set\_up\_ale\_sponge\_field(tmp\_tr, g, tv%S, ale\_csp)
1894         \textcolor{keyword}{deallocate}(tmp\_tr)
1895 \textcolor{keywordflow}{      endif}
1896     \textcolor{keywordflow}{else}
1897       \textcolor{comment}{! Initialize sponges without supplying sponge grid}
1898       \textcolor{keyword}{call }initialize\_ale\_sponge(idamp, g, param\_file, ale\_csp)
1899       \textcolor{comment}{! The remaining calls to set\_up\_sponge\_field can be in any order.}
1900       \textcolor{keywordflow}{if} ( use\_temperature) \textcolor{keywordflow}{then}
1901         \textcolor{keyword}{call }set\_up\_ale\_sponge\_field(filename, potemp\_var, time, g, gv, us, tv%T, ale\_csp)
1902         \textcolor{keyword}{call }set\_up\_ale\_sponge\_field(filename, salin\_var, time, g, gv, us, tv%S, ale\_csp)
1903 \textcolor{keywordflow}{      endif}
1904 \textcolor{keywordflow}{    endif}
1905 
1906 
1907 
1908 \textcolor{keywordflow}{  endif}
1909 
1910 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_a964fba68510337bdde7636a18f783fc9}\label{namespacemom__state__initialization_a964fba68510337bdde7636a18f783fc9}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!initialize\+\_\+temp\+\_\+salt\+\_\+fit@{initialize\+\_\+temp\+\_\+salt\+\_\+fit}}
\index{initialize\+\_\+temp\+\_\+salt\+\_\+fit@{initialize\+\_\+temp\+\_\+salt\+\_\+fit}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{initialize\+\_\+temp\+\_\+salt\+\_\+fit()}{initialize\_temp\_salt\_fit()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::initialize\+\_\+temp\+\_\+salt\+\_\+fit (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{T,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{S,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(eos\+\_\+type), pointer}]{eqn\+\_\+of\+\_\+state,  }\item[{real, intent(in)}]{P\+\_\+\+Ref,  }\item[{logical, intent(in), optional}]{just\+\_\+read\+\_\+params }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Initializes temperature and salinity by fitting to density. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt out}  & {\em t} & The potential temperature that is being initialized \mbox{[}degC\mbox{]}.\\
\hline
\mbox{\tt out}  & {\em s} & The salinity that is being initialized \mbox{[}ppt\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters.\\
\hline
 & {\em eqn\+\_\+of\+\_\+state} & Equation of state structure\\
\hline
\mbox{\tt in}  & {\em p\+\_\+ref} & The coordinate-\/density reference pressure \mbox{[}R L2 T-\/2 $\sim$$>$ Pa\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em just\+\_\+read\+\_\+params} & If present and true, this call will only read parameters without changing h. \\
\hline
\end{DoxyParams}


Definition at line 1552 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
1552   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{            !< The ocean's grid structure.}
1553   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}  :: gv\textcolor{comment}{           !< The ocean's vertical grid structure.}
1554   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)} :: t\textcolor{comment}{ !< The potential temperature that is}
1555 \textcolor{comment}{                                                       !! being initialized [degC].}
1556   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)} :: s\textcolor{comment}{ !< The salinity that is being}
1557 \textcolor{comment}{                                                       !! initialized [ppt].}
1558   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}  :: us\textcolor{comment}{           !< A dimensional unit scaling type}
1559   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}  :: param\_file\textcolor{comment}{   !< A structure to parse for run-time}
1560 \textcolor{comment}{                                                       !! parameters.}
1561   \textcolor{keywordtype}{type}(eos\_type),          \textcolor{keywordtype}{pointer}     :: eqn\_of\_state\textcolor{comment}{ !< Equation of state structure}
1562   \textcolor{keywordtype}{real},                    \textcolor{keywordtype}{intent(in)}  :: p\_ref\textcolor{comment}{        !< The coordinate-density reference pressure}
1563 \textcolor{comment}{                                                       !! [R L2 T-2 ~> Pa].}
1564   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: just\_read\_params\textcolor{comment}{ !< If present and true, this call will}
1565 \textcolor{comment}{                                                       !! only read parameters without changing h.}
1566   \textcolor{comment}{! Local variables}
1567   \textcolor{keywordtype}{real} :: t0(szk\_(g))   \textcolor{comment}{! Layer potential temperatures [degC]}
1568   \textcolor{keywordtype}{real} :: s0(szk\_(g))   \textcolor{comment}{! Layer salinities [degC]}
1569   \textcolor{keywordtype}{real} :: t\_ref         \textcolor{comment}{! Reference Temperature [degC]}
1570   \textcolor{keywordtype}{real} :: s\_ref         \textcolor{comment}{! Reference Salinity [ppt]}
1571   \textcolor{keywordtype}{real} :: pres(szk\_(g))      \textcolor{comment}{! An array of the reference pressure [R L2 T-2 ~> Pa].}
1572   \textcolor{keywordtype}{real} :: drho\_dt(szk\_(g))   \textcolor{comment}{! Derivative of density with temperature [R degC-1 ~> kg m-3 degC-1].}
1573   \textcolor{keywordtype}{real} :: drho\_ds(szk\_(g))   \textcolor{comment}{! Derivative of density with salinity [R ppt-1 ~> kg m-3 ppt-1].}
1574   \textcolor{keywordtype}{real} :: rho\_guess(szk\_(g)) \textcolor{comment}{! Potential density at T0 & S0 [R ~> kg m-3].}
1575   \textcolor{keywordtype}{logical} :: fit\_salin       \textcolor{comment}{! If true, accept the prescribed temperature and fit the salinity.}
1576   \textcolor{keywordtype}{logical} :: just\_read    \textcolor{comment}{! If true, just read parameters but set nothing.}
1577   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"initialize\_temp\_salt\_fit"} \textcolor{comment}{! This subroutine's name.}
1578   \textcolor{keywordtype}{integer} :: i, j, k, itt, nz
1579   nz = g%ke
1580 
1581   just\_read = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(just\_read\_params)) just\_read = just\_read\_params
1582 
1583   \textcolor{keywordflow}{if} (.not.just\_read) \textcolor{keyword}{call }calltree\_enter(trim(mdl)//\textcolor{stringliteral}{"(), MOM\_state\_initialization.F90"})
1584 
1585   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"T\_REF"}, t\_ref, &
1586                  \textcolor{stringliteral}{"A reference temperature used in initialization."}, &
1587                  units=\textcolor{stringliteral}{"degC"}, fail\_if\_missing=.not.just\_read, do\_not\_log=just\_read)
1588   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"S\_REF"}, s\_ref, &
1589                  \textcolor{stringliteral}{"A reference salinity used in initialization."}, units=\textcolor{stringliteral}{"PSU"}, &
1590                  default=35.0, do\_not\_log=just\_read)
1591   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"FIT\_SALINITY"}, fit\_salin, &
1592                  \textcolor{stringliteral}{"If true, accept the prescribed temperature and fit the "}//&
1593                  \textcolor{stringliteral}{"salinity; otherwise take salinity and fit temperature."}, &
1594                  default=.false., do\_not\_log=just\_read)
1595 
1596   \textcolor{keywordflow}{if} (just\_read) \textcolor{keywordflow}{return} \textcolor{comment}{! All run-time parameters have been read, so return.}
1597 
1598   \textcolor{keywordflow}{do} k=1,nz
1599     pres(k) = p\_ref ; s0(k) = s\_ref
1600     t0(k) = t\_ref
1601 \textcolor{keywordflow}{  enddo}
1602 
1603   \textcolor{keyword}{call }calculate\_density(t0(1), s0(1), pres(1), rho\_guess(1), eqn\_of\_state)
1604   \textcolor{keyword}{call }calculate\_density\_derivs(t0, s0, pres, drho\_dt, drho\_ds, eqn\_of\_state, (/1,1/) )
1605 
1606   \textcolor{keywordflow}{if} (fit\_salin) \textcolor{keywordflow}{then}
1607     \textcolor{comment}{! A first guess of the layers' temperatures.}
1608     \textcolor{keywordflow}{do} k=nz,1,-1
1609       s0(k) = max(0.0, s0(1) + (gv%Rlay(k) - rho\_guess(1)) / drho\_ds(1))
1610 \textcolor{keywordflow}{    enddo}
1611     \textcolor{comment}{! Refine the guesses for each layer.}
1612     \textcolor{keywordflow}{do} itt=1,6
1613       \textcolor{keyword}{call }calculate\_density(t0, s0, pres, rho\_guess, eqn\_of\_state)
1614       \textcolor{keyword}{call }calculate\_density\_derivs(t0, s0, pres, drho\_dt, drho\_ds, eqn\_of\_state)
1615       \textcolor{keywordflow}{do} k=1,nz
1616         s0(k) = max(0.0, s0(k) + (gv%Rlay(k) - rho\_guess(k)) / drho\_ds(k))
1617 \textcolor{keywordflow}{      enddo}
1618 \textcolor{keywordflow}{    enddo}
1619   \textcolor{keywordflow}{else}
1620     \textcolor{comment}{! A first guess of the layers' temperatures.}
1621     \textcolor{keywordflow}{do} k=nz,1,-1
1622       t0(k) = t0(1) + (gv%Rlay(k) - rho\_guess(1)) / drho\_dt(1)
1623 \textcolor{keywordflow}{    enddo}
1624     \textcolor{keywordflow}{do} itt=1,6
1625       \textcolor{keyword}{call }calculate\_density(t0, s0, pres, rho\_guess, eqn\_of\_state)
1626       \textcolor{keyword}{call }calculate\_density\_derivs(t0, s0, pres, drho\_dt, drho\_ds, eqn\_of\_state)
1627       \textcolor{keywordflow}{do} k=1,nz
1628         t0(k) = t0(k) + (gv%Rlay(k) - rho\_guess(k)) / drho\_dt(k)
1629 \textcolor{keywordflow}{      enddo}
1630 \textcolor{keywordflow}{    enddo}
1631 \textcolor{keywordflow}{  endif}
1632 
1633   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=g%jsd,g%jed ; \textcolor{keywordflow}{do} i=g%isd,g%ied
1634     t(i,j,k) = t0(k) ; s(i,j,k) = s0(k)
1635 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1636 
1637   \textcolor{keyword}{call }calltree\_leave(trim(mdl)//\textcolor{stringliteral}{'()'})
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_a706c24ba7b8a344152ea0d3da051ceb5}\label{namespacemom__state__initialization_a706c24ba7b8a344152ea0d3da051ceb5}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!initialize\+\_\+temp\+\_\+salt\+\_\+from\+\_\+file@{initialize\+\_\+temp\+\_\+salt\+\_\+from\+\_\+file}}
\index{initialize\+\_\+temp\+\_\+salt\+\_\+from\+\_\+file@{initialize\+\_\+temp\+\_\+salt\+\_\+from\+\_\+file}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{initialize\+\_\+temp\+\_\+salt\+\_\+from\+\_\+file()}{initialize\_temp\_salt\_from\_file()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::initialize\+\_\+temp\+\_\+salt\+\_\+from\+\_\+file (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(out)}]{T,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(out)}]{S,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{logical, intent(in), optional}]{just\+\_\+read\+\_\+params }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Initializes temperature and salinity from file. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt out}  & {\em t} & The potential temperature that is being initialized \mbox{[}degC\mbox{]}\\
\hline
\mbox{\tt out}  & {\em s} & The salinity that is being initialized \mbox{[}ppt\mbox{]}\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters\\
\hline
\mbox{\tt in}  & {\em just\+\_\+read\+\_\+params} & If present and true, this call will only read parameters without changing h. \\
\hline
\end{DoxyParams}


Definition at line 1451 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
1451   \textcolor{keywordtype}{type}(ocean\_grid\_type),                  \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{    !< The ocean's grid structure}
1452   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)} :: t\textcolor{comment}{ !< The potential temperature that is}
1453 \textcolor{comment}{                                                             !! being initialized [degC]}
1454   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)} :: s\textcolor{comment}{ !< The salinity that is}
1455 \textcolor{comment}{                                                             !! being initialized [ppt]}
1456   \textcolor{keywordtype}{type}(param\_file\_type),                  \textcolor{keywordtype}{intent(in)}  :: param\_file\textcolor{comment}{ !< A structure to parse for run-time
       parameters}
1457   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: just\_read\_params\textcolor{comment}{ !< If present and true, this call will}
1458 \textcolor{comment}{                                                           !! only read parameters without changing h.}
1459   \textcolor{comment}{! Local variables}
1460   \textcolor{keywordtype}{logical} :: just\_read    \textcolor{comment}{! If true, just read parameters but set nothing.}
1461   \textcolor{keywordtype}{character(len=200)} :: filename, salt\_filename \textcolor{comment}{! Full paths to input files}
1462   \textcolor{keywordtype}{character(len=200)} :: ts\_file, salt\_file, inputdir \textcolor{comment}{! Strings for file/path}
1463   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"initialize\_temp\_salt\_from\_file"}
1464   \textcolor{keywordtype}{character(len=64)}  :: temp\_var, salt\_var \textcolor{comment}{! Temperature and salinity names in files}
1465 
1466   just\_read = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(just\_read\_params)) just\_read = just\_read\_params
1467 
1468   \textcolor{keywordflow}{if} (.not.just\_read) \textcolor{keyword}{call }calltree\_enter(trim(mdl)//\textcolor{stringliteral}{"(), MOM\_state\_initialization.F90"})
1469 
1470   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TS\_FILE"}, ts\_file, &
1471                  \textcolor{stringliteral}{"The initial condition file for temperature."}, &
1472                  fail\_if\_missing=.not.just\_read, do\_not\_log=just\_read)
1473   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."})
1474   inputdir = slasher(inputdir)
1475 
1476   filename = trim(inputdir)//trim(ts\_file)
1477   \textcolor{keywordflow}{if} (.not.just\_read) \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/TS\_FILE"}, filename)
1478   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TEMP\_IC\_VAR"}, temp\_var, &
1479                  \textcolor{stringliteral}{"The initial condition variable for potential temperature."}, &
1480                  default=\textcolor{stringliteral}{"PTEMP"}, do\_not\_log=just\_read)
1481   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SALT\_IC\_VAR"}, salt\_var, &
1482                  \textcolor{stringliteral}{"The initial condition variable for salinity."}, &
1483                  default=\textcolor{stringliteral}{"SALT"}, do\_not\_log=just\_read)
1484   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SALT\_FILE"}, salt\_file, &
1485                  \textcolor{stringliteral}{"The initial condition file for salinity."}, &
1486                  default=trim(ts\_file), do\_not\_log=just\_read)
1487 
1488   \textcolor{keywordflow}{if} (just\_read) \textcolor{keywordflow}{return} \textcolor{comment}{! All run-time parameters have been read, so return.}
1489 
1490   \textcolor{keywordflow}{if} (.not.file\_exists(filename, g%Domain)) \textcolor{keyword}{call }mom\_error(fatal, &
1491      \textcolor{stringliteral}{" initialize\_temp\_salt\_from\_file: Unable to open "}//trim(filename))
1492 
1493   \textcolor{comment}{! Read the temperatures and salinities from netcdf files.}
1494   \textcolor{keyword}{call }mom\_read\_data(filename, temp\_var, t(:,:,:), g%Domain)
1495 
1496   salt\_filename = trim(inputdir)//trim(salt\_file)
1497   \textcolor{keywordflow}{if} (.not.file\_exists(salt\_filename, g%Domain)) \textcolor{keyword}{call }mom\_error(fatal, &
1498      \textcolor{stringliteral}{" initialize\_temp\_salt\_from\_file: Unable to open "}//trim(salt\_filename))
1499 
1500   \textcolor{keyword}{call }mom\_read\_data(salt\_filename, salt\_var, s(:,:,:), g%Domain)
1501 
1502   \textcolor{keyword}{call }calltree\_leave(trim(mdl)//\textcolor{stringliteral}{'()'})
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_a7d627f0ef1dc66acc764a40fd662a758}\label{namespacemom__state__initialization_a7d627f0ef1dc66acc764a40fd662a758}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!initialize\+\_\+temp\+\_\+salt\+\_\+from\+\_\+profile@{initialize\+\_\+temp\+\_\+salt\+\_\+from\+\_\+profile}}
\index{initialize\+\_\+temp\+\_\+salt\+\_\+from\+\_\+profile@{initialize\+\_\+temp\+\_\+salt\+\_\+from\+\_\+profile}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{initialize\+\_\+temp\+\_\+salt\+\_\+from\+\_\+profile()}{initialize\_temp\_salt\_from\_profile()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::initialize\+\_\+temp\+\_\+salt\+\_\+from\+\_\+profile (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{T,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{S,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{logical, intent(in), optional}]{just\+\_\+read\+\_\+params }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Initializes temperature and salinity from a 1D profile. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt out}  & {\em t} & The potential temperature that is being initialized \mbox{[}degC\mbox{]}\\
\hline
\mbox{\tt out}  & {\em s} & The salinity that is being initialized \mbox{[}ppt\mbox{]}\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters\\
\hline
\mbox{\tt in}  & {\em just\+\_\+read\+\_\+params} & If present and true, this call will only read parameters without changing h. \\
\hline
\end{DoxyParams}


Definition at line 1507 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
1507   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{ !< The ocean's grid structure}
1508   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)} :: t\textcolor{comment}{ !< The potential temperature that is}
1509 \textcolor{comment}{                                                             !! being initialized [degC]}
1510   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)} :: s\textcolor{comment}{ !< The salinity that is}
1511 \textcolor{comment}{                                                             !! being initialized [ppt]}
1512   \textcolor{keywordtype}{type}(param\_file\_type),                    \textcolor{keywordtype}{intent(in)}  :: param\_file\textcolor{comment}{ !< A structure to parse for run-time
       parameters}
1513   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: just\_read\_params\textcolor{comment}{ !< If present and true, this call will}
1514 \textcolor{comment}{                                                           !! only read parameters without changing h.}
1515   \textcolor{comment}{! Local variables}
1516   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(G))} :: t0, s0
1517   \textcolor{keywordtype}{integer} :: i, j, k
1518   \textcolor{keywordtype}{logical} :: just\_read    \textcolor{comment}{! If true, just read parameters but set nothing.}
1519   \textcolor{keywordtype}{character(len=200)} :: filename, ts\_file, inputdir \textcolor{comment}{! Strings for file/path}
1520   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"initialize\_temp\_salt\_from\_profile"}
1521 
1522   just\_read = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(just\_read\_params)) just\_read = just\_read\_params
1523 
1524   \textcolor{keywordflow}{if} (.not.just\_read) \textcolor{keyword}{call }calltree\_enter(trim(mdl)//\textcolor{stringliteral}{"(), MOM\_state\_initialization.F90"})
1525 
1526   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TS\_FILE"}, ts\_file, &
1527                  \textcolor{stringliteral}{"The file with the reference profiles for temperature "}//&
1528                  \textcolor{stringliteral}{"and salinity."}, fail\_if\_missing=.not.just\_read, do\_not\_log=just\_read)
1529 
1530   \textcolor{keywordflow}{if} (just\_read) \textcolor{keywordflow}{return} \textcolor{comment}{! All run-time parameters have been read, so return.}
1531 
1532   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."})
1533   inputdir = slasher(inputdir)
1534   filename = trim(inputdir)//trim(ts\_file)
1535   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/TS\_FILE"}, filename)
1536   \textcolor{keywordflow}{if} (.not.file\_exists(filename)) \textcolor{keyword}{call }mom\_error(fatal, &
1537      \textcolor{stringliteral}{" initialize\_temp\_salt\_from\_profile: Unable to open "}//trim(filename))
1538 
1539   \textcolor{comment}{! Read the temperatures and salinities from a netcdf file.}
1540   \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{"PTEMP"}, t0(:))
1541   \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{"SALT"},  s0(:))
1542 
1543   \textcolor{keywordflow}{do} k=1,g%ke ; \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
1544     t(i,j,k) = t0(k) ; s(i,j,k) = s0(k)
1545 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1546 
1547   \textcolor{keyword}{call }calltree\_leave(trim(mdl)//\textcolor{stringliteral}{'()'})
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_a0793ab167463a3bb45114f57cf018a40}\label{namespacemom__state__initialization_a0793ab167463a3bb45114f57cf018a40}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!initialize\+\_\+temp\+\_\+salt\+\_\+linear@{initialize\+\_\+temp\+\_\+salt\+\_\+linear}}
\index{initialize\+\_\+temp\+\_\+salt\+\_\+linear@{initialize\+\_\+temp\+\_\+salt\+\_\+linear}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{initialize\+\_\+temp\+\_\+salt\+\_\+linear()}{initialize\_temp\_salt\_linear()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::initialize\+\_\+temp\+\_\+salt\+\_\+linear (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{T,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{S,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{logical, intent(in), optional}]{just\+\_\+read\+\_\+params }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Initializes T and S with linear profiles according to reference surface layer salinity and temperature and a specified range. 

\begin{DoxyRemark}{Remarks}
Note that the linear distribution is set up with respect to the layer number, not the physical position).
\end{DoxyRemark}

\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt out}  & {\em t} & The potential temperature that is being initialized \mbox{[}degC\mbox{]}\\
\hline
\mbox{\tt out}  & {\em s} & The salinity that is being initialized \mbox{[}ppt\mbox{]}\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure to parse for run-\/time parameters\\
\hline
\mbox{\tt in}  & {\em just\+\_\+read\+\_\+params} & If present and true, this call will only read parameters without changing h. \\
\hline
\end{DoxyParams}


Definition at line 1646 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
1646   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{          !< The ocean's grid structure}
1647   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)} :: t\textcolor{comment}{ !< The potential temperature that is}
1648 \textcolor{comment}{                                                             !! being initialized [degC]}
1649   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(out)} :: s\textcolor{comment}{ !< The salinity that is}
1650 \textcolor{comment}{                                                             !! being initialized [ppt]}
1651   \textcolor{keywordtype}{type}(param\_file\_type),                    \textcolor{keywordtype}{intent(in)}  :: param\_file\textcolor{comment}{ !< A structure to parse for}
1652 \textcolor{comment}{                                                                     !! run-time parameters}
1653   \textcolor{keywordtype}{logical},                        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: just\_read\_params\textcolor{comment}{ !< If present and true,}
1654 \textcolor{comment}{                                                                      !! this call will only read}
1655 \textcolor{comment}{                                                                      !! parameters without}
1656 \textcolor{comment}{                                                                      !! changing h.}
1657 
1658   \textcolor{keywordtype}{integer} :: k
1659   \textcolor{keywordtype}{real}  :: delta\_s, delta\_t
1660   \textcolor{keywordtype}{real}  :: s\_top, t\_top \textcolor{comment}{! Reference salinity and temerature within surface layer}
1661   \textcolor{keywordtype}{real}  :: s\_range, t\_range \textcolor{comment}{! Range of salinities and temperatures over the vertical}
1662   \textcolor{keywordtype}{real}  :: delta
1663   \textcolor{keywordtype}{logical} :: just\_read    \textcolor{comment}{! If true, just read parameters but set nothing.}
1664   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"initialize\_temp\_salt\_linear"} \textcolor{comment}{! This subroutine's name.}
1665 
1666   just\_read = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(just\_read\_params)) just\_read = just\_read\_params
1667 
1668   \textcolor{keywordflow}{if} (.not.just\_read) \textcolor{keyword}{call }calltree\_enter(trim(mdl)//\textcolor{stringliteral}{"(), MOM\_state\_initialization.F90"})
1669   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"T\_TOP"}, t\_top, &
1670                  \textcolor{stringliteral}{"Initial temperature of the top surface."}, &
1671                  units=\textcolor{stringliteral}{"degC"}, fail\_if\_missing=.not.just\_read, do\_not\_log=just\_read)
1672   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"T\_RANGE"}, t\_range, &
1673                  \textcolor{stringliteral}{"Initial temperature difference (top-bottom)."}, &
1674                  units=\textcolor{stringliteral}{"degC"}, fail\_if\_missing=.not.just\_read, do\_not\_log=just\_read)
1675   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"S\_TOP"}, s\_top, &
1676                  \textcolor{stringliteral}{"Initial salinity of the top surface."}, &
1677                  units=\textcolor{stringliteral}{"PSU"}, fail\_if\_missing=.not.just\_read, do\_not\_log=just\_read)
1678   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"S\_RANGE"}, s\_range, &
1679                  \textcolor{stringliteral}{"Initial salinity difference (top-bottom)."}, &
1680                  units=\textcolor{stringliteral}{"PSU"}, fail\_if\_missing=.not.just\_read, do\_not\_log=just\_read)
1681 
1682   \textcolor{keywordflow}{if} (just\_read) \textcolor{keywordflow}{return} \textcolor{comment}{! All run-time parameters have been read, so return.}
1683 
1684   \textcolor{comment}{! Prescribe salinity}
1685 \textcolor{comment}{! delta\_S = S\_range / ( G%ke - 1.0 )}
1686 \textcolor{comment}{! S(:,:,1) = S\_top}
1687 \textcolor{comment}{! do k = 2,G%ke}
1688 \textcolor{comment}{!   S(:,:,k) = S(:,:,k-1) + delta\_S}
1689 \textcolor{comment}{! enddo}
1690   \textcolor{keywordflow}{do} k = 1,g%ke
1691     s(:,:,k) = s\_top - s\_range*((\textcolor{keywordtype}{real}(k)-0.5)/\textcolor{keywordtype}{real}(g%ke))
1692     t(:,:,k) = t\_top - t\_range*((\textcolor{keywordtype}{real}(k)-0.5)/\textcolor{keywordtype}{real}(g%ke))
1693 \textcolor{keywordflow}{  enddo}
1694 
1695   \textcolor{comment}{! Prescribe temperature}
1696 \textcolor{comment}{! delta\_T = T\_range / ( G%ke - 1.0 )}
1697 \textcolor{comment}{! T(:,:,1) = T\_top}
1698 \textcolor{comment}{! do k = 2,G%ke}
1699 \textcolor{comment}{!   T(:,:,k) = T(:,:,k-1) + delta\_T}
1700 \textcolor{comment}{! enddo}
1701 \textcolor{comment}{! delta = 1}
1702 \textcolor{comment}{! T(:,:,G%ke/2 - (delta-1):G%ke/2 + delta) = 1.0}
1703 
1704   \textcolor{keyword}{call }calltree\_leave(trim(mdl)//\textcolor{stringliteral}{'()'})
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_a847ac374f69c4777e3e49a5ebdcebf43}\label{namespacemom__state__initialization_a847ac374f69c4777e3e49a5ebdcebf43}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!initialize\+\_\+thickness\+\_\+from\+\_\+file@{initialize\+\_\+thickness\+\_\+from\+\_\+file}}
\index{initialize\+\_\+thickness\+\_\+from\+\_\+file@{initialize\+\_\+thickness\+\_\+from\+\_\+file}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{initialize\+\_\+thickness\+\_\+from\+\_\+file()}{initialize\_thickness\_from\_file()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::initialize\+\_\+thickness\+\_\+from\+\_\+file (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(gv)), intent(out)}]{h,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{logical, intent(in)}]{file\+\_\+has\+\_\+thickness,  }\item[{logical, intent(in), optional}]{just\+\_\+read\+\_\+params }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Reads the layer thicknesses or interface heights from a file. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt out}  & {\em h} & The thickness that is being initialized \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure indicating the open file to parse for model parameter values.\\
\hline
\mbox{\tt in}  & {\em file\+\_\+has\+\_\+thickness} & If true, this file contains layer thicknesses; otherwise it contains interface heights.\\
\hline
\mbox{\tt in}  & {\em just\+\_\+read\+\_\+params} & If present and true, this call will only read parameters without changing h. \\
\hline
\end{DoxyParams}


Definition at line 621 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
621   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{    !< The ocean's grid structure}
622   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}  :: gv\textcolor{comment}{   !< The ocean's vertical grid structure}
623   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}  :: us\textcolor{comment}{   !< A dimensional unit scaling type}
624   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, &
625                            \textcolor{keywordtype}{intent(out)} :: h\textcolor{comment}{    !< The thickness that is being initialized [H ~> m or kg
       m-2].}
626   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}  :: param\_file\textcolor{comment}{  !< A structure indicating the open file}
627 \textcolor{comment}{                                               !! to parse for model parameter values.}
628   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(in)}  :: file\_has\_thickness\textcolor{comment}{ !< If true, this file contains layer}
629 \textcolor{comment}{                                               !! thicknesses; otherwise it contains}
630 \textcolor{comment}{                                               !! interface heights.}
631   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: just\_read\_params\textcolor{comment}{ !< If present and true, this call will}
632 \textcolor{comment}{                                               !! only read parameters without changing h.}
633 
634   \textcolor{comment}{! Local variables}
635   \textcolor{keywordtype}{real} :: eta(szi\_(g),szj\_(g),szk\_(g)+1)  \textcolor{comment}{! Interface heights, in depth units.}
636   \textcolor{keywordtype}{integer} :: inconsistent = 0
637   \textcolor{keywordtype}{logical} :: correct\_thickness
638   \textcolor{keywordtype}{logical} :: just\_read    \textcolor{comment}{! If true, just read parameters but set nothing.}
639   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"initialize\_thickness\_from\_file"} \textcolor{comment}{! This subroutine's name.}
640   \textcolor{keywordtype}{character(len=200)} :: filename, thickness\_file, inputdir, mesg \textcolor{comment}{! Strings for file/path}
641   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz
642 
643   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
644 
645   just\_read = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(just\_read\_params)) just\_read = just\_read\_params
646 
647   \textcolor{keywordflow}{if} (.not.just\_read) &
648     \textcolor{keyword}{call }calltree\_enter(trim(mdl)//\textcolor{stringliteral}{"(), MOM\_state\_initialization.F90"})
649 
650   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."}, do\_not\_log=just\_read)
651   inputdir = slasher(inputdir)
652   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"THICKNESS\_FILE"}, thickness\_file, &
653                  \textcolor{stringliteral}{"The name of the thickness file."}, &
654                  fail\_if\_missing=.not.just\_read, do\_not\_log=just\_read)
655 
656   filename = trim(inputdir)//trim(thickness\_file)
657   \textcolor{keywordflow}{if} (.not.just\_read) \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/THICKNESS\_FILE"}, filename)
658 
659   \textcolor{keywordflow}{if} ((.not.just\_read) .and. (.not.file\_exists(filename, g%Domain))) \textcolor{keyword}{call }mom\_error(fatal, &
660          \textcolor{stringliteral}{" initialize\_thickness\_from\_file: Unable to open "}//trim(filename))
661 
662   \textcolor{keywordflow}{if} (file\_has\_thickness) \textcolor{keywordflow}{then}
663     \textcolor{comment}{!### Consider adding a parameter to use to rescale h.}
664     \textcolor{keywordflow}{if} (just\_read) \textcolor{keywordflow}{return} \textcolor{comment}{! All run-time parameters have been read, so return.}
665     \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{"h"}, h(:,:,:), g%Domain, scale=gv%m\_to\_H)
666   \textcolor{keywordflow}{else}
667     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ADJUST\_THICKNESS"}, correct\_thickness, &
668                  \textcolor{stringliteral}{"If true, all mass below the bottom removed if the "}//&
669                  \textcolor{stringliteral}{"topography is shallower than the thickness input file "}//&
670                  \textcolor{stringliteral}{"would indicate."}, default=.false., do\_not\_log=just\_read)
671     \textcolor{keywordflow}{if} (just\_read) \textcolor{keywordflow}{return} \textcolor{comment}{! All run-time parameters have been read, so return.}
672 
673     \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{"eta"}, eta(:,:,:), g%Domain, scale=us%m\_to\_Z)
674 
675     \textcolor{keywordflow}{if} (correct\_thickness) \textcolor{keywordflow}{then}
676       \textcolor{keyword}{call }adjustetatofitbathymetry(g, gv, us, eta, h)
677     \textcolor{keywordflow}{else}
678       \textcolor{keywordflow}{do} k=nz,1,-1 ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
679         \textcolor{keywordflow}{if} (eta(i,j,k) < (eta(i,j,k+1) + gv%Angstrom\_Z)) \textcolor{keywordflow}{then}
680           eta(i,j,k) = eta(i,j,k+1) + gv%Angstrom\_Z
681           h(i,j,k) = gv%Angstrom\_H
682         \textcolor{keywordflow}{else}
683           h(i,j,k) = gv%Z\_to\_H * (eta(i,j,k) - eta(i,j,k+1))
684 \textcolor{keywordflow}{        endif}
685 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
686 
687       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
688         \textcolor{keywordflow}{if} (abs(eta(i,j,nz+1) + g%bathyT(i,j)) > 1.0*us%m\_to\_Z) &
689           inconsistent = inconsistent + 1
690 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
691       \textcolor{keyword}{call }sum\_across\_pes(inconsistent)
692 
693       \textcolor{keywordflow}{if} ((inconsistent > 0) .and. (is\_root\_pe())) \textcolor{keywordflow}{then}
694         \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("Thickness initial conditions are inconsistent ",'}// &
695                  \textcolor{stringliteral}{'"with topography in ",I8," places.")'}) inconsistent
696         \textcolor{keyword}{call }mom\_error(warning, mesg)
697 \textcolor{keywordflow}{      endif}
698 \textcolor{keywordflow}{    endif}
699 
700 \textcolor{keywordflow}{  endif}
701   \textcolor{keyword}{call }calltree\_leave(trim(mdl)//\textcolor{stringliteral}{'()'})
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_ade07252728855ac18a50b547f0cb16f7}\label{namespacemom__state__initialization_ade07252728855ac18a50b547f0cb16f7}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!initialize\+\_\+thickness\+\_\+list@{initialize\+\_\+thickness\+\_\+list}}
\index{initialize\+\_\+thickness\+\_\+list@{initialize\+\_\+thickness\+\_\+list}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{initialize\+\_\+thickness\+\_\+list()}{initialize\_thickness\_list()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::initialize\+\_\+thickness\+\_\+list (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(out)}]{h,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{logical, intent(in), optional}]{just\+\_\+read\+\_\+params }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Initialize thickness from a 1D list. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt out}  & {\em h} & The thickness that is being initialized \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure indicating the open file to parse for model parameter values.\\
\hline
\mbox{\tt in}  & {\em just\+\_\+read\+\_\+params} & If present and true, this call will only read parameters without changing h. \\
\hline
\end{DoxyParams}


Definition at line 842 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
842   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{           !< The ocean's grid structure.}
843   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}  :: gv\textcolor{comment}{          !< The ocean's vertical grid structure.}
844   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}  :: us\textcolor{comment}{  !< A dimensional unit scaling type}
845   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, &
846                            \textcolor{keywordtype}{intent(out)} :: h\textcolor{comment}{           !< The thickness that is being initialized [H ~> m or
       kg m-2].}
847   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}  :: param\_file\textcolor{comment}{  !< A structure indicating the open file}
848 \textcolor{comment}{                                                      !! to parse for model parameter values.}
849   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: just\_read\_params\textcolor{comment}{ !< If present and true, this call will}
850 \textcolor{comment}{                                                      !! only read parameters without changing h.}
851   \textcolor{comment}{! Local variables}
852   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"initialize\_thickness\_list"} \textcolor{comment}{! This subroutine's name.}
853   \textcolor{keywordtype}{real} :: e0(szk\_(g)+1)   \textcolor{comment}{! The resting interface heights, in depth units [Z ~> m],}
854                           \textcolor{comment}{! usually negative because it is positive upward.}
855   \textcolor{keywordtype}{real} :: eta1d(szk\_(g)+1)\textcolor{comment}{! Interface height relative to the sea surface}
856                           \textcolor{comment}{! positive upward, in depth units [Z ~> m].}
857   \textcolor{keywordtype}{logical} :: just\_read    \textcolor{comment}{! If true, just read parameters but set nothing.}
858   \textcolor{keywordtype}{character(len=200)} :: filename, eta\_file, inputdir \textcolor{comment}{! Strings for file/path}
859   \textcolor{keywordtype}{character(len=72)}  :: eta\_var
860   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz
861 
862   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
863 
864   just\_read = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(just\_read\_params)) just\_read = just\_read\_params
865 
866   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERFACE\_IC\_FILE"}, eta\_file, &
867                  \textcolor{stringliteral}{"The file from which horizontal mean initial conditions "}//&
868                  \textcolor{stringliteral}{"for interface depths can be read."}, fail\_if\_missing=.true.)
869   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INTERFACE\_IC\_VAR"}, eta\_var, &
870                  \textcolor{stringliteral}{"The variable name for horizontal mean initial conditions "}//&
871                  \textcolor{stringliteral}{"for interface depths relative to mean sea level."}, &
872                  default=\textcolor{stringliteral}{"eta"})
873 
874   \textcolor{keywordflow}{if} (just\_read) \textcolor{keywordflow}{return}
875 
876   \textcolor{keyword}{call }calltree\_enter(trim(mdl)//\textcolor{stringliteral}{"(), MOM\_state\_initialization.F90"})
877 
878   \textcolor{keyword}{call }get\_param(param\_file,  mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."})
879   filename = trim(slasher(inputdir))//trim(eta\_file)
880   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/INTERFACE\_IC\_FILE"}, filename)
881 
882   e0(:) = 0.0
883   \textcolor{keyword}{call }mom\_read\_data(filename, eta\_var, e0(:), scale=us%m\_to\_Z)
884 
885   \textcolor{keywordflow}{if} ((abs(e0(1)) - 0.0) > 0.001) \textcolor{keywordflow}{then}
886     \textcolor{comment}{! This list probably starts with the interior interface, so shift it up.}
887     \textcolor{keywordflow}{do} k=nz+1,2,-1 ; e0(k) = e0(k-1) ;\textcolor{keywordflow}{ enddo}
888     e0(1) = 0.0
889 \textcolor{keywordflow}{  endif}
890 
891   \textcolor{keywordflow}{if} (e0(2) > e0(1)) \textcolor{keywordflow}{then} \textcolor{comment}{! Switch to the convention for interface heights increasing upward.}
892     \textcolor{keywordflow}{do} k=1,nz ; e0(k) = -e0(k) ;\textcolor{keywordflow}{ enddo}
893 \textcolor{keywordflow}{  endif}
894 
895   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
896     \textcolor{comment}{! This sets the initial thickness (in m) of the layers.  The}
897     \textcolor{comment}{! thicknesses are set to insure that: 1.  each layer is at least an}
898     \textcolor{comment}{! Angstrom thick, and 2.  the interfaces are where they should be}
899     \textcolor{comment}{! based on the resting depths and interface height perturbations,}
900     \textcolor{comment}{! as long at this doesn't interfere with 1.}
901     eta1d(nz+1) = -g%bathyT(i,j)
902     \textcolor{keywordflow}{do} k=nz,1,-1
903       eta1d(k) = e0(k)
904       \textcolor{keywordflow}{if} (eta1d(k) < (eta1d(k+1) + gv%Angstrom\_Z)) \textcolor{keywordflow}{then}
905         eta1d(k) = eta1d(k+1) + gv%Angstrom\_Z
906         h(i,j,k) = gv%Angstrom\_H
907       \textcolor{keywordflow}{else}
908         h(i,j,k) = gv%Z\_to\_H * (eta1d(k) - eta1d(k+1))
909 \textcolor{keywordflow}{      endif}
910 \textcolor{keywordflow}{    enddo}
911 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
912 
913   \textcolor{keyword}{call }calltree\_leave(trim(mdl)//\textcolor{stringliteral}{'()'})
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_a06f7a21e110b80140439dedccaf4fa1c}\label{namespacemom__state__initialization_a06f7a21e110b80140439dedccaf4fa1c}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!initialize\+\_\+thickness\+\_\+uniform@{initialize\+\_\+thickness\+\_\+uniform}}
\index{initialize\+\_\+thickness\+\_\+uniform@{initialize\+\_\+thickness\+\_\+uniform}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{initialize\+\_\+thickness\+\_\+uniform()}{initialize\_thickness\_uniform()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::initialize\+\_\+thickness\+\_\+uniform (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(out)}]{h,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{logical, intent(in), optional}]{just\+\_\+read\+\_\+params }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Initializes thickness to be uniform. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt out}  & {\em h} & The thickness that is being initialized \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure indicating the open file to parse for model parameter values.\\
\hline
\mbox{\tt in}  & {\em just\+\_\+read\+\_\+params} & If present and true, this call will only read parameters without changing h. \\
\hline
\end{DoxyParams}


Definition at line 787 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
787   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{           !< The ocean's grid structure.}
788   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}  :: gv\textcolor{comment}{          !< The ocean's vertical grid structure.}
789   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, &
790                            \textcolor{keywordtype}{intent(out)} :: h\textcolor{comment}{           !< The thickness that is being initialized [H ~> m or
       kg m-2].}
791   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}  :: param\_file\textcolor{comment}{  !< A structure indicating the open file}
792 \textcolor{comment}{                                                      !! to parse for model parameter values.}
793   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: just\_read\_params\textcolor{comment}{ !< If present and true, this call will}
794 \textcolor{comment}{                                                      !! only read parameters without changing h.}
795   \textcolor{comment}{! Local variables}
796   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"initialize\_thickness\_uniform"} \textcolor{comment}{! This subroutine's name.}
797   \textcolor{keywordtype}{real} :: e0(szk\_(g)+1)   \textcolor{comment}{! The resting interface heights, in depth units, usually}
798                           \textcolor{comment}{! negative because it is positive upward.}
799   \textcolor{keywordtype}{real} :: eta1d(szk\_(g)+1)\textcolor{comment}{! Interface height relative to the sea surface}
800                           \textcolor{comment}{! positive upward, in depth units.}
801   \textcolor{keywordtype}{logical} :: just\_read    \textcolor{comment}{! If true, just read parameters but set nothing.}
802   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz
803 
804   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
805 
806   just\_read = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(just\_read\_params)) just\_read = just\_read\_params
807 
808   \textcolor{keywordflow}{if} (just\_read) \textcolor{keywordflow}{return} \textcolor{comment}{! This subroutine has no run-time parameters.}
809 
810   \textcolor{keyword}{call }calltree\_enter(trim(mdl)//\textcolor{stringliteral}{"(), MOM\_state\_initialization.F90"})
811 
812   \textcolor{keywordflow}{if} (g%max\_depth<=0.) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"initialize\_thickness\_uniform: "}// &
813       \textcolor{stringliteral}{"MAXIMUM\_DEPTH has a non-sensical value! Was it set?"})
814 
815   \textcolor{keywordflow}{do} k=1,nz
816     e0(k) = -g%max\_depth * \textcolor{keywordtype}{real(k-1)} / \textcolor{keywordtype}{real}(nz)
817 \textcolor{keywordflow}{  enddo}
818 
819   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
820     \textcolor{comment}{! This sets the initial thickness (in m) of the layers.  The}
821     \textcolor{comment}{! thicknesses are set to insure that: 1.  each layer is at least an}
822     \textcolor{comment}{! Angstrom thick, and 2.  the interfaces are where they should be}
823     \textcolor{comment}{! based on the resting depths and interface height perturbations,}
824     \textcolor{comment}{! as long at this doesn't interfere with 1.}
825     eta1d(nz+1) = -g%bathyT(i,j)
826     \textcolor{keywordflow}{do} k=nz,1,-1
827       eta1d(k) = e0(k)
828       \textcolor{keywordflow}{if} (eta1d(k) < (eta1d(k+1) + gv%Angstrom\_Z)) \textcolor{keywordflow}{then}
829         eta1d(k) = eta1d(k+1) + gv%Angstrom\_Z
830         h(i,j,k) = gv%Angstrom\_H
831       \textcolor{keywordflow}{else}
832         h(i,j,k) = gv%Z\_to\_H * (eta1d(k) - eta1d(k+1))
833 \textcolor{keywordflow}{      endif}
834 \textcolor{keywordflow}{    enddo}
835 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
836 
837   \textcolor{keyword}{call }calltree\_leave(trim(mdl)//\textcolor{stringliteral}{'()'})
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_af4ebdba67fde58a9aa7633bca4c117ba}\label{namespacemom__state__initialization_af4ebdba67fde58a9aa7633bca4c117ba}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!initialize\+\_\+velocity\+\_\+circular@{initialize\+\_\+velocity\+\_\+circular}}
\index{initialize\+\_\+velocity\+\_\+circular@{initialize\+\_\+velocity\+\_\+circular}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{initialize\+\_\+velocity\+\_\+circular()}{initialize\_velocity\_circular()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::initialize\+\_\+velocity\+\_\+circular (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(out)}]{v,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{logical, intent(in), optional}]{just\+\_\+read\+\_\+params }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Sets the initial velocity components to be circular with no flow at edges of domain and center. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt out}  & {\em u} & The zonal velocity that is being initialized \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt out}  & {\em v} & The meridional velocity that is being initialized \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure indicating the open file to parse for model parameter values.\\
\hline
\mbox{\tt in}  & {\em just\+\_\+read\+\_\+params} & If present and true, this call will only read parameters without changing h. \\
\hline
\end{DoxyParams}


Definition at line 1388 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
1388   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{  !< The ocean's grid structure}
1389   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
1390                            \textcolor{keywordtype}{intent(out)} :: u\textcolor{comment}{  !< The zonal velocity that is being initialized [L T-1 ~> m
       s-1]}
1391   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
1392                            \textcolor{keywordtype}{intent(out)} :: v\textcolor{comment}{  !< The meridional velocity that is being initialized [L T-1 ~>
       m s-1]}
1393   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}  :: us\textcolor{comment}{ !< A dimensional unit scaling type}
1394   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}  :: param\_file\textcolor{comment}{  !< A structure indicating the open file to}
1395 \textcolor{comment}{                                                      !! parse for model parameter values.}
1396   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: just\_read\_params\textcolor{comment}{ !< If present and true, this call will}
1397 \textcolor{comment}{                                                      !! only read parameters without changing h.}
1398   \textcolor{comment}{! Local variables}
1399   \textcolor{keywordtype}{character(len=200)} :: mdl = \textcolor{stringliteral}{"initialize\_velocity\_circular"}
1400   \textcolor{keywordtype}{real} :: circular\_max\_u \textcolor{comment}{! The amplitude of the zonal flow [L T-1 ~> m s-1]}
1401   \textcolor{keywordtype}{real} :: dpi        \textcolor{comment}{! A local variable storing pi = 3.14159265358979...}
1402   \textcolor{keywordtype}{real} :: psi1, psi2 \textcolor{comment}{! Values of the streamfunction at two points [L2 T-1 ~> m2 s-1]}
1403   \textcolor{keywordtype}{logical} :: just\_read    \textcolor{comment}{! If true, just read parameters but set nothing.}
1404   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, isq, ieq, jsq, jeq, nz
1405   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
1406   isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
1407 
1408   just\_read = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(just\_read\_params)) just\_read = just\_read\_params
1409 
1410   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"CIRCULAR\_MAX\_U"}, circular\_max\_u, &
1411                  \textcolor{stringliteral}{"The amplitude of zonal flow from which to scale the "}// &
1412                  \textcolor{stringliteral}{"circular stream function [m s-1]."}, &
1413                  units=\textcolor{stringliteral}{"m s-1"}, default=0., scale=us%m\_s\_to\_L\_T, do\_not\_log=just\_read)
1414 
1415   \textcolor{keywordflow}{if} (just\_read) \textcolor{keywordflow}{return} \textcolor{comment}{! All run-time parameters have been read, so return.}
1416 
1417   dpi=acos(0.0)*2.0 \textcolor{comment}{! pi}
1418 
1419   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq
1420     psi1 = my\_psi(i,j)
1421     psi2 = my\_psi(i,j-1)
1422     u(i,j,k) = (psi1 - psi2) / g%dy\_Cu(i,j) \textcolor{comment}{! *(circular\_max\_u*G%len\_lon/(2.0*dpi))}
1423 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1424   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie
1425     psi1 = my\_psi(i,j)
1426     psi2 = my\_psi(i-1,j)
1427     v(i,j,k) = (psi2 - psi1) / g%dx\_Cv(i,j) \textcolor{comment}{! *(circular\_max\_u*G%len\_lon/(2.0*dpi))}
1428 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1429 
1430   \textcolor{keyword}{contains}
1431 \textcolor{comment}{}
1432 \textcolor{comment}{  !> Returns the value of a circular stream function at (ig,jg) in [L2 T-1 ~> m2 s-1]}
1433 \textcolor{keyword}{  real }\textcolor{keyword}{function }my\_psi(ig,jg)
1434     \textcolor{keywordtype}{integer} :: ig\textcolor{comment}{ !< Global i-index}
1435     \textcolor{keywordtype}{integer} :: jg\textcolor{comment}{ !< Global j-index}
1436     \textcolor{comment}{! Local variables}
1437     \textcolor{keywordtype}{real} :: x, y, r \textcolor{comment}{! [nondim]}
1438 
1439     x = 2.0*(g%geoLonBu(ig,jg)-g%west\_lon) / g%len\_lon - 1.0  \textcolor{comment}{! -1<x<1}
1440     y = 2.0*(g%geoLatBu(ig,jg)-g%south\_lat) / g%len\_lat - 1.0 \textcolor{comment}{! -1<y<1}
1441     r = sqrt( x**2 + y**2 ) \textcolor{comment}{! Circular stream function is a function of radius only}
1442     r = min(1.0, r) \textcolor{comment}{! Flatten stream function in corners of box}
1443     my\_psi = 0.5*(1.0 - cos(dpi*r))
1444     my\_psi = my\_psi * (circular\_max\_u * g%US%m\_to\_L*g%len\_lon*1e3 / dpi) \textcolor{comment}{! len\_lon is in km}
1445 \textcolor{keyword}{  end function }my\_psi
1446 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_adcedb30eb6f940cef3fbdd4328aedef8}\label{namespacemom__state__initialization_adcedb30eb6f940cef3fbdd4328aedef8}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!initialize\+\_\+velocity\+\_\+from\+\_\+file@{initialize\+\_\+velocity\+\_\+from\+\_\+file}}
\index{initialize\+\_\+velocity\+\_\+from\+\_\+file@{initialize\+\_\+velocity\+\_\+from\+\_\+file}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{initialize\+\_\+velocity\+\_\+from\+\_\+file()}{initialize\_velocity\_from\_file()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::initialize\+\_\+velocity\+\_\+from\+\_\+file (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(out)}]{v,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{logical, intent(in), optional}]{just\+\_\+read\+\_\+params }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Initialize horizontal velocity components from file. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt out}  & {\em u} & The zonal velocity that is being initialized \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt out}  & {\em v} & The meridional velocity that is being initialized \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure indicating the open file to parse for modelparameter values.\\
\hline
\mbox{\tt in}  & {\em just\+\_\+read\+\_\+params} & If present and true, this call will only read parameters without changing h. \\
\hline
\end{DoxyParams}


Definition at line 1272 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
1272   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{  !< The ocean's grid structure}
1273   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
1274                            \textcolor{keywordtype}{intent(out)} :: u\textcolor{comment}{  !< The zonal velocity that is being initialized [L T-1 ~> m
       s-1]}
1275   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
1276                            \textcolor{keywordtype}{intent(out)} :: v\textcolor{comment}{  !< The meridional velocity that is being initialized [L T-1 ~>
       m s-1]}
1277   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}  :: us\textcolor{comment}{ !< A dimensional unit scaling type}
1278   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}  :: param\_file\textcolor{comment}{  !< A structure indicating the open file to}
1279 \textcolor{comment}{                                                      !! parse for modelparameter values.}
1280   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: just\_read\_params\textcolor{comment}{ !< If present and true, this call will}
1281 \textcolor{comment}{                                                      !! only read parameters without changing h.}
1282   \textcolor{comment}{! Local variables}
1283   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"initialize\_velocity\_from\_file"} \textcolor{comment}{! This subroutine's name.}
1284   \textcolor{keywordtype}{character(len=200)} :: filename,velocity\_file,inputdir \textcolor{comment}{! Strings for file/path}
1285   \textcolor{keywordtype}{logical} :: just\_read    \textcolor{comment}{! If true, just read parameters but set nothing.}
1286 
1287   just\_read = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(just\_read\_params)) just\_read = just\_read\_params
1288 
1289   \textcolor{keywordflow}{if} (.not.just\_read) \textcolor{keyword}{call }calltree\_enter(trim(mdl)//\textcolor{stringliteral}{"(), MOM\_state\_initialization.F90"})
1290 
1291   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"VELOCITY\_FILE"}, velocity\_file, &
1292                  \textcolor{stringliteral}{"The name of the velocity initial condition file."}, &
1293                  fail\_if\_missing=.not.just\_read, do\_not\_log=just\_read)
1294   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."})
1295   inputdir = slasher(inputdir)
1296 
1297   \textcolor{keywordflow}{if} (just\_read) \textcolor{keywordflow}{return} \textcolor{comment}{! All run-time parameters have been read, so return.}
1298 
1299   filename = trim(inputdir)//trim(velocity\_file)
1300   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/VELOCITY\_FILE"}, filename)
1301 
1302   \textcolor{keywordflow}{if} (.not.file\_exists(filename, g%Domain)) \textcolor{keyword}{call }mom\_error(fatal, &
1303          \textcolor{stringliteral}{" initialize\_velocity\_from\_file: Unable to open "}//trim(filename))
1304 
1305   \textcolor{comment}{!  Read the velocities from a netcdf file.}
1306   \textcolor{keyword}{call }mom\_read\_vector(filename, \textcolor{stringliteral}{"u"}, \textcolor{stringliteral}{"v"}, u(:,:,:), v(:,:,:), g%Domain, scale=us%m\_s\_to\_L\_T)
1307 
1308   \textcolor{keyword}{call }calltree\_leave(trim(mdl)//\textcolor{stringliteral}{'()'})
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_ac10655a7937f2239ff8ae9b899f4bc4b}\label{namespacemom__state__initialization_ac10655a7937f2239ff8ae9b899f4bc4b}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!initialize\+\_\+velocity\+\_\+uniform@{initialize\+\_\+velocity\+\_\+uniform}}
\index{initialize\+\_\+velocity\+\_\+uniform@{initialize\+\_\+velocity\+\_\+uniform}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{initialize\+\_\+velocity\+\_\+uniform()}{initialize\_velocity\_uniform()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::initialize\+\_\+velocity\+\_\+uniform (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(out)}]{v,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{logical, intent(in), optional}]{just\+\_\+read\+\_\+params }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Sets the initial velocity components to uniform. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt out}  & {\em u} & The zonal velocity that is being initialized \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt out}  & {\em v} & The meridional velocity that is being initialized \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure indicating the open file to parse for modelparameter values.\\
\hline
\mbox{\tt in}  & {\em just\+\_\+read\+\_\+params} & If present and true, this call will only read parameters without changing h. \\
\hline
\end{DoxyParams}


Definition at line 1347 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
1347   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{  !< The ocean's grid structure}
1348   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
1349                            \textcolor{keywordtype}{intent(out)} :: u\textcolor{comment}{  !< The zonal velocity that is being initialized [L T-1 ~> m
       s-1]}
1350   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
1351                            \textcolor{keywordtype}{intent(out)} :: v\textcolor{comment}{  !< The meridional velocity that is being initialized [L T-1 ~>
       m s-1]}
1352   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}  :: us\textcolor{comment}{ !< A dimensional unit scaling type}
1353   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}  :: param\_file\textcolor{comment}{  !< A structure indicating the open file to}
1354 \textcolor{comment}{                                                      !! parse for modelparameter values.}
1355   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: just\_read\_params\textcolor{comment}{ !< If present and true, this call will}
1356 \textcolor{comment}{                                                      !! only read parameters without changing h.}
1357   \textcolor{comment}{! Local variables}
1358   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, isq, ieq, jsq, jeq, nz
1359   \textcolor{keywordtype}{real}    :: initial\_u\_const, initial\_v\_const
1360   \textcolor{keywordtype}{logical} :: just\_read    \textcolor{comment}{! If true, just read parameters but set nothing.}
1361   \textcolor{keywordtype}{character(len=200)} :: mdl = \textcolor{stringliteral}{"initialize\_velocity\_uniform"} \textcolor{comment}{! This subroutine's name.}
1362   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
1363   isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
1364 
1365   just\_read = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(just\_read\_params)) just\_read = just\_read\_params
1366 
1367   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INITIAL\_U\_CONST"}, initial\_u\_const, &
1368                  \textcolor{stringliteral}{"A initial uniform value for the zonal flow."}, &
1369                  default=0.0, units=\textcolor{stringliteral}{"m s-1"}, scale=us%m\_s\_to\_L\_T, do\_not\_log=just\_read)
1370   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"INITIAL\_V\_CONST"}, initial\_v\_const, &
1371                  \textcolor{stringliteral}{"A initial uniform value for the meridional flow."}, &
1372                  default=0.0, units=\textcolor{stringliteral}{"m s-1"}, scale=us%m\_s\_to\_L\_T, do\_not\_log=just\_read)
1373 
1374   \textcolor{keywordflow}{if} (just\_read) \textcolor{keywordflow}{return} \textcolor{comment}{! All run-time parameters have been read, so return.}
1375 
1376   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq
1377     u(i,j,k) = initial\_u\_const
1378 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1379   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie
1380     v(i,j,k) = initial\_v\_const
1381 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1382 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_a1de6eb1d89deb76196b2876c8982a956}\label{namespacemom__state__initialization_a1de6eb1d89deb76196b2876c8982a956}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!initialize\+\_\+velocity\+\_\+zero@{initialize\+\_\+velocity\+\_\+zero}}
\index{initialize\+\_\+velocity\+\_\+zero@{initialize\+\_\+velocity\+\_\+zero}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{initialize\+\_\+velocity\+\_\+zero()}{initialize\_velocity\_zero()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::initialize\+\_\+velocity\+\_\+zero (\begin{DoxyParamCaption}\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed, g \%ke), intent(out)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb, g \%ke), intent(out)}]{v,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{logical, intent(in), optional}]{just\+\_\+read\+\_\+params }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Initialize horizontal velocity components to zero. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt out}  & {\em u} & The zonal velocity that is being initialized \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt out}  & {\em v} & The meridional velocity that is being initialized \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure indicating the open file to parse for modelparameter values.\\
\hline
\mbox{\tt in}  & {\em just\+\_\+read\+\_\+params} & If present and true, this call will only read parameters without changing h. \\
\hline
\end{DoxyParams}


Definition at line 1313 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
1313   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{  !< The ocean's grid structure}
1314   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
1315                            \textcolor{keywordtype}{intent(out)} :: u\textcolor{comment}{  !< The zonal velocity that is being initialized [L T-1 ~> m
       s-1]}
1316   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
1317                            \textcolor{keywordtype}{intent(out)} :: v\textcolor{comment}{  !< The meridional velocity that is being initialized [L T-1 ~>
       m s-1]}
1318   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}  :: param\_file\textcolor{comment}{  !< A structure indicating the open file to}
1319 \textcolor{comment}{                                                      !! parse for modelparameter values.}
1320   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: just\_read\_params\textcolor{comment}{ !< If present and true, this call will}
1321 \textcolor{comment}{                                                      !! only read parameters without changing h.}
1322   \textcolor{comment}{! Local variables}
1323   \textcolor{keywordtype}{character(len=200)} :: mdl = \textcolor{stringliteral}{"initialize\_velocity\_zero"} \textcolor{comment}{! This subroutine's name.}
1324   \textcolor{keywordtype}{logical} :: just\_read    \textcolor{comment}{! If true, just read parameters but set nothing.}
1325   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, isq, ieq, jsq, jeq, nz
1326   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
1327   isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
1328 
1329   just\_read = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(just\_read\_params)) just\_read = just\_read\_params
1330 
1331   \textcolor{keywordflow}{if} (.not.just\_read) \textcolor{keyword}{call }calltree\_enter(trim(mdl)//\textcolor{stringliteral}{"(), MOM\_state\_initialization.F90"})
1332 
1333   \textcolor{keywordflow}{if} (just\_read) \textcolor{keywordflow}{return} \textcolor{comment}{! All run-time parameters have been read, so return.}
1334 
1335   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=isq,ieq
1336     u(i,j,k) = 0.0
1337 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1338   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsq,jeq ; \textcolor{keywordflow}{do} i=is,ie
1339     v(i,j,k) = 0.0
1340 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1341 
1342   \textcolor{keyword}{call }calltree\_leave(trim(mdl)//\textcolor{stringliteral}{'()'})
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_a81503d4f1855cb185f122d6314e4f06c}\label{namespacemom__state__initialization_a81503d4f1855cb185f122d6314e4f06c}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!mom\+\_\+initialize\+\_\+state@{mom\+\_\+initialize\+\_\+state}}
\index{mom\+\_\+initialize\+\_\+state@{mom\+\_\+initialize\+\_\+state}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{mom\+\_\+initialize\+\_\+state()}{mom\_initialize\_state()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+state\+\_\+initialization\+::mom\+\_\+initialize\+\_\+state (\begin{DoxyParamCaption}\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(out)}]{u,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(out)}]{v,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(out)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(inout)}]{tv,  }\item[{type(time\+\_\+type), intent(inout)}]{Time,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{PF,  }\item[{type(directories), intent(in)}]{dirs,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+CS,  }\item[{type(ale\+\_\+cs), pointer}]{A\+L\+E\+\_\+\+C\+Sp,  }\item[{type(tracer\+\_\+registry\+\_\+type), pointer}]{tracer\+\_\+\+Reg,  }\item[{type(sponge\+\_\+cs), pointer}]{sponge\+\_\+\+C\+Sp,  }\item[{type(ale\+\_\+sponge\+\_\+cs), pointer}]{A\+L\+E\+\_\+sponge\+\_\+\+C\+Sp,  }\item[{type(ocean\+\_\+obc\+\_\+type), pointer}]{O\+BC,  }\item[{type(time\+\_\+type), intent(in), optional}]{Time\+\_\+in }\end{DoxyParamCaption})}



Initialize temporally evolving fields, either as initial conditions or by reading them from a restart (or saves) file. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt out}  & {\em u} & The zonal velocity that is being\\
\hline
\mbox{\tt out}  & {\em v} & The meridional velocity that is being\\
\hline
\mbox{\tt out}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em tv} & A structure pointing to various thermodynamic variables\\
\hline
\mbox{\tt in,out}  & {\em time} & Time at the start of the run segment.\\
\hline
\mbox{\tt in}  & {\em pf} & A structure indicating the open file to parse for model parameter values.\\
\hline
\mbox{\tt in}  & {\em dirs} & A structure containing several relevant directory paths.\\
\hline
 & {\em restart\+\_\+cs} & A pointer to the restart control structure.\\
\hline
 & {\em ale\+\_\+csp} & The A\+LE control structure for remapping\\
\hline
 & {\em tracer\+\_\+reg} & A pointer to the tracer registry\\
\hline
 & {\em sponge\+\_\+csp} & The layerwise sponge control structure.\\
\hline
 & {\em ale\+\_\+sponge\+\_\+csp} & The A\+LE sponge control structure.\\
\hline
 & {\em obc} & The open boundary condition control structure.\\
\hline
\mbox{\tt in}  & {\em time\+\_\+in} & Time at the start of the run segment. Time\+\_\+in overrides any value set for Time. \\
\hline
\end{DoxyParams}


Definition at line 117 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
117   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< The ocean's grid structure.}
118   \textcolor{keywordtype}{type}(verticalgrid\_type),    \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !< The ocean's vertical grid structure.}
119   \textcolor{keywordtype}{type}(unit\_scale\_type),      \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
120   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, &
121                               \textcolor{keywordtype}{intent(out)}   :: u\textcolor{comment}{    !< The zonal velocity that is being}
122 \textcolor{comment}{                                                    !! initialized [L T-1 ~> m s-1]}
123   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, &
124                               \textcolor{keywordtype}{intent(out)}   :: v\textcolor{comment}{    !< The meridional velocity that is being}
125 \textcolor{comment}{                                                    !! initialized [L T-1 ~> m s-1]}
126   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  &
127                               \textcolor{keywordtype}{intent(out)}   :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-2]}
128   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),      \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{   !< A structure pointing to various thermodynamic}
129 \textcolor{comment}{                                                    !! variables}
130   \textcolor{keywordtype}{type}(time\_type),            \textcolor{keywordtype}{intent(inout)} :: time\textcolor{comment}{ !< Time at the start of the run segment.}
131   \textcolor{keywordtype}{type}(param\_file\_type),      \textcolor{keywordtype}{intent(in)}    :: pf\textcolor{comment}{   !< A structure indicating the open file to parse}
132 \textcolor{comment}{                                                    !! for model parameter values.}
133   \textcolor{keywordtype}{type}(directories),          \textcolor{keywordtype}{intent(in)}    :: dirs\textcolor{comment}{ !< A structure containing several relevant}
134 \textcolor{comment}{                                                    !! directory paths.}
135   \textcolor{keywordtype}{type}(mom\_restart\_cs),       \textcolor{keywordtype}{pointer}       :: restart\_cs\textcolor{comment}{ !< A pointer to the restart control}
136 \textcolor{comment}{                                                    !! structure.}
137   \textcolor{keywordtype}{type}(ale\_cs),               \textcolor{keywordtype}{pointer}       :: ale\_csp\textcolor{comment}{ !< The ALE control structure for remapping}
138   \textcolor{keywordtype}{type}(tracer\_registry\_type), \textcolor{keywordtype}{pointer}       :: tracer\_reg\textcolor{comment}{ !< A pointer to the tracer registry}
139   \textcolor{keywordtype}{type}(sponge\_cs),            \textcolor{keywordtype}{pointer}       :: sponge\_csp\textcolor{comment}{ !< The layerwise sponge control structure.}
140   \textcolor{keywordtype}{type}(ale\_sponge\_cs),        \textcolor{keywordtype}{pointer}       :: ale\_sponge\_csp\textcolor{comment}{ !< The ALE sponge control structure.}
141   \textcolor{keywordtype}{type}(ocean\_obc\_type),       \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{   !< The open boundary condition control structure.}
142   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{optional},  \textcolor{keywordtype}{intent(in)}    :: time\_in\textcolor{comment}{ !< Time at the start of the run segment.}
143 \textcolor{comment}{                                                     !! Time\_in overrides any value set for Time.}
144   \textcolor{comment}{! Local variables}
145   \textcolor{keywordtype}{character(len=200)} :: filename   \textcolor{comment}{! The name of an input file.}
146   \textcolor{keywordtype}{character(len=200)} :: filename2  \textcolor{comment}{! The name of an input files.}
147   \textcolor{keywordtype}{character(len=200)} :: inputdir   \textcolor{comment}{! The directory where NetCDF input files are.}
148   \textcolor{keywordtype}{character(len=200)} :: config
149   \textcolor{keywordtype}{real} :: h\_rescale   \textcolor{comment}{! A rescaling factor for thicknesses from the representation in}
150                       \textcolor{comment}{! a restart file to the internal representation in this run.}
151   \textcolor{keywordtype}{real} :: vel\_rescale \textcolor{comment}{! A rescaling factor for velocities from the representation in}
152                       \textcolor{comment}{! a restart file to the internal representation in this run.}
153   \textcolor{keywordtype}{real} :: dt          \textcolor{comment}{! The baroclinic dynamics timestep for this run [T ~> s].}
154   \textcolor{keywordtype}{logical} :: from\_z\_file, useale
155   \textcolor{keywordtype}{logical} :: new\_sim
156   \textcolor{keywordtype}{integer} :: write\_geom
157   \textcolor{keywordtype}{logical} :: use\_temperature, use\_sponge, use\_obc
158   \textcolor{keywordtype}{logical} :: use\_eos     \textcolor{comment}{! If true, density is calculated from T & S using an equation of state.}
159   \textcolor{keywordtype}{logical} :: depress\_sfc \textcolor{comment}{! If true, remove the mass that would be displaced}
160                          \textcolor{comment}{! by a large surface pressure by squeezing the column.}
161   \textcolor{keywordtype}{logical} :: trim\_ic\_for\_p\_surf \textcolor{comment}{! If true, remove the mass that would be displaced}
162                          \textcolor{comment}{! by a large surface pressure, such as with an ice sheet.}
163   \textcolor{keywordtype}{logical} :: regrid\_accelerate
164   \textcolor{keywordtype}{integer} :: regrid\_iterations
165 \textcolor{comment}{!  logical :: Analytic\_FV\_PGF, obsol\_test}
166   \textcolor{keywordtype}{logical} :: convert
167   \textcolor{keywordtype}{logical} :: just\_read  \textcolor{comment}{! If true, only read the parameters because this}
168                         \textcolor{comment}{! is a run from a restart file; this option}
169                         \textcolor{comment}{! allows the use of Fatal unused parameters.}
170   \textcolor{keywordtype}{type}(eos\_type), \textcolor{keywordtype}{pointer} :: eos => null()
171   \textcolor{keywordtype}{logical} :: debug      \textcolor{comment}{! If true, write debugging output.}
172   \textcolor{keywordtype}{logical} :: debug\_obc  \textcolor{comment}{! If true, do debugging calls related to OBCs.}
173   \textcolor{keywordtype}{logical} :: debug\_layers = .false.
174   \textcolor{keywordtype}{character(len=80)} :: mesg
175 \textcolor{comment}{! This include declares and sets the variable "version".}
176 \textcolor{preprocessor}{#include "version\_variable.h"}
177 \textcolor{preprocessor}{}  \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, isq, ieq, jsq, jeq, nz
178   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, isdb, iedb, jsdb, jedb
179 
180   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
181   isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
182   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
183   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
184 
185   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"MOM\_initialize\_state(), MOM\_state\_initialization.F90"})
186   \textcolor{keyword}{call }log\_version(pf, mdl, version, \textcolor{stringliteral}{""})
187   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"DEBUG"}, debug, default=.false.)
188   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"DEBUG\_OBC"}, debug\_obc, default=.false.)
189 
190   new\_sim = determine\_is\_new\_run(dirs%input\_filename, dirs%restart\_input\_dir, &
191                                  g, restart\_cs)
192   just\_read = .not.new\_sim
193 
194   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, &
195          \textcolor{stringliteral}{"The directory in which input files are found."}, default=\textcolor{stringliteral}{"."})
196   inputdir = slasher(inputdir)
197 
198   use\_temperature = \textcolor{keyword}{associated}(tv%T)
199   useale = \textcolor{keyword}{associated}(ale\_csp)
200   use\_eos = \textcolor{keyword}{associated}(tv%eqn\_of\_state)
201   use\_obc = \textcolor{keyword}{associated}(obc)
202   \textcolor{keywordflow}{if} (use\_eos) eos => tv%eqn\_of\_state
203 
204   \textcolor{comment}{!====================================================================}
205   \textcolor{comment}{!    Initialize temporally evolving fields, either as initial}
206   \textcolor{comment}{!  conditions or by reading them from a restart (or saves) file.}
207   \textcolor{comment}{!====================================================================}
208 
209   \textcolor{keywordflow}{if} (new\_sim) \textcolor{keywordflow}{then}
210     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"Run initialized internally."}, 3)
211 
212     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(time\_in)) time = time\_in
213     \textcolor{comment}{! Otherwise leave Time at its input value.}
214 
215     \textcolor{comment}{! This initialization should not be needed. Certainly restricting it}
216     \textcolor{comment}{! to the computational domain helps detect possible uninitialized}
217     \textcolor{comment}{! data in halos which should be covered by the pass\_var(h) later.}
218     \textcolor{comment}{!do k = 1, nz; do j = js, je; do i = is, ie}
219     \textcolor{comment}{!  h(i,j,k) = 0.}
220     \textcolor{comment}{!enddo}
221 \textcolor{keywordflow}{  endif}
222 
223   \textcolor{comment}{! The remaining initialization calls are done, regardless of whether the}
224   \textcolor{comment}{! fields are actually initialized here (if just\_read=.false.) or whether it}
225   \textcolor{comment}{! is just to make sure that all valid parameters are read to enable the}
226   \textcolor{comment}{! detection of unused parameters.}
227   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"INIT\_LAYERS\_FROM\_Z\_FILE"}, from\_z\_file, &
228              \textcolor{stringliteral}{"If true, initialize the layer thicknesses, temperatures, "}//&
229              \textcolor{stringliteral}{"and salinities from a Z-space file on a latitude-longitude "}//&
230              \textcolor{stringliteral}{"grid."}, default=.false., do\_not\_log=just\_read)
231 
232   \textcolor{keywordflow}{if} (from\_z\_file) \textcolor{keywordflow}{then}
233     \textcolor{comment}{! Initialize thickness and T/S from z-coordinate data in a file.}
234     \textcolor{keywordflow}{if} (.NOT.use\_temperature) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"MOM\_initialize\_state : "}//&
235        \textcolor{stringliteral}{"use\_temperature must be true if INIT\_LAYERS\_FROM\_Z\_FILE is true"})
236 
237     \textcolor{keyword}{call }mom\_temp\_salt\_initialize\_from\_z(h, tv, g, gv, us, pf, just\_read\_params=just\_read)
238 
239   \textcolor{keywordflow}{else}
240     \textcolor{comment}{! Initialize thickness, h.}
241     \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"THICKNESS\_CONFIG"}, config, &
242              \textcolor{stringliteral}{"A string that determines how the initial layer "}//&
243              \textcolor{stringliteral}{"thicknesses are specified for a new run: \(\backslash\)n"}//&
244              \textcolor{stringliteral}{" \(\backslash\)t file - read interface heights from the file specified \(\backslash\)n"}//&
245              \textcolor{stringliteral}{" \(\backslash\)t thickness\_file - read thicknesses from the file specified \(\backslash\)n"}//&
246              \textcolor{stringliteral}{" \(\backslash\)t\(\backslash\)t by (THICKNESS\_FILE).\(\backslash\)n"}//&
247              \textcolor{stringliteral}{" \(\backslash\)t coord - determined by ALE coordinate.\(\backslash\)n"}//&
248              \textcolor{stringliteral}{" \(\backslash\)t uniform - uniform thickness layers evenly distributed \(\backslash\)n"}//&
249              \textcolor{stringliteral}{" \(\backslash\)t\(\backslash\)t between the surface and MAXIMUM\_DEPTH. \(\backslash\)n"}//&
250              \textcolor{stringliteral}{" \(\backslash\)t list - read a list of positive interface depths. \(\backslash\)n"}//&
251              \textcolor{stringliteral}{" \(\backslash\)t DOME - use a slope and channel configuration for the \(\backslash\)n"}//&
252              \textcolor{stringliteral}{" \(\backslash\)t\(\backslash\)t DOME sill-overflow test case. \(\backslash\)n"}//&
253              \textcolor{stringliteral}{" \(\backslash\)t ISOMIP - use a configuration for the \(\backslash\)n"}//&
254              \textcolor{stringliteral}{" \(\backslash\)t\(\backslash\)t ISOMIP test case. \(\backslash\)n"}//&
255              \textcolor{stringliteral}{" \(\backslash\)t benchmark - use the benchmark test case thicknesses. \(\backslash\)n"}//&
256              \textcolor{stringliteral}{" \(\backslash\)t Neverworld - use the Neverworld test case thicknesses. \(\backslash\)n"}//&
257              \textcolor{stringliteral}{" \(\backslash\)t search - search a density profile for the interface \(\backslash\)n"}//&
258              \textcolor{stringliteral}{" \(\backslash\)t\(\backslash\)t densities. This is not yet implemented. \(\backslash\)n"}//&
259              \textcolor{stringliteral}{" \(\backslash\)t circle\_obcs - the circle\_obcs test case is used. \(\backslash\)n"}//&
260              \textcolor{stringliteral}{" \(\backslash\)t DOME2D - 2D version of DOME initialization. \(\backslash\)n"}//&
261              \textcolor{stringliteral}{" \(\backslash\)t adjustment2d - 2D lock exchange thickness ICs. \(\backslash\)n"}//&
262              \textcolor{stringliteral}{" \(\backslash\)t sloshing - sloshing gravity thickness ICs. \(\backslash\)n"}//&
263              \textcolor{stringliteral}{" \(\backslash\)t seamount - no motion test with seamount ICs. \(\backslash\)n"}//&
264              \textcolor{stringliteral}{" \(\backslash\)t dumbbell - sloshing channel ICs. \(\backslash\)n"}//&
265              \textcolor{stringliteral}{" \(\backslash\)t soliton - Equatorial Rossby soliton. \(\backslash\)n"}//&
266              \textcolor{stringliteral}{" \(\backslash\)t rossby\_front - a mixed layer front in thermal wind balance.\(\backslash\)n"}//&
267              \textcolor{stringliteral}{" \(\backslash\)t USER - call a user modified routine."}, &
268              default=\textcolor{stringliteral}{"uniform"}, do\_not\_log=just\_read)
269     \textcolor{keywordflow}{select case} (trim(config))
270        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"file"})
271          \textcolor{keyword}{call }initialize\_thickness\_from\_file(h, g, gv, us, pf, .false., just\_read\_params=just\_read)
272        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"thickness\_file"})
273          \textcolor{keyword}{call }initialize\_thickness\_from\_file(h, g, gv, us, pf, .true., just\_read\_params=just\_read)
274        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"coord"})
275          \textcolor{keywordflow}{if} (new\_sim .and. useale) \textcolor{keywordflow}{then}
276            \textcolor{keyword}{call }ale\_initthicknesstocoord( ale\_csp, g, gv, h )
277          \textcolor{keywordflow}{elseif} (new\_sim) \textcolor{keywordflow}{then}
278            \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_initialize\_state: USE\_REGRIDDING must be True "}//&
279                                  \textcolor{stringliteral}{"for THICKNESS\_CONFIG of 'coord'"})
280 \textcolor{keywordflow}{         endif}
281        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"uniform"}); \textcolor{keyword}{call }initialize\_thickness\_uniform(h, g, gv, pf, &
282                                   just\_read\_params=just\_read)
283        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"list"}); \textcolor{keyword}{call }initialize\_thickness\_list(h, g, gv, us, pf, &
284                                   just\_read\_params=just\_read)
285        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"DOME"}); \textcolor{keyword}{call }dome\_initialize\_thickness(h, g, gv, pf, &
286                                just\_read\_params=just\_read)
287        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"ISOMIP"}); \textcolor{keyword}{call }isomip\_initialize\_thickness(h, g, gv, us, pf, tv, &
288                                  just\_read\_params=just\_read)
289        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"benchmark"}); \textcolor{keyword}{call }benchmark\_initialize\_thickness(h, g, gv, us, pf, &
290                                     tv%eqn\_of\_state, tv%P\_Ref, just\_read\_params=just\_read)
291        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"Neverwoorld"},\textcolor{stringliteral}{"Neverland"}); \textcolor{keyword}{call }neverworld\_initialize\_thickness(h, g, gv, us, pf, &
292                                  tv%eqn\_of\_state, tv%P\_Ref)
293        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"search"}); \textcolor{keyword}{call }initialize\_thickness\_search
294        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"circle\_obcs"}); \textcolor{keyword}{call }circle\_obcs\_initialize\_thickness(h, g, gv, pf, &
295                                       just\_read\_params=just\_read)
296        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"lock\_exchange"}); \textcolor{keyword}{call }lock\_exchange\_initialize\_thickness(h, g, gv, us, &
297                                         pf, just\_read\_params=just\_read)
298        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"external\_gwave"}); \textcolor{keyword}{call }external\_gwave\_initialize\_thickness(h, g, gv, us, &
299                                          pf, just\_read\_params=just\_read)
300        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"DOME2D"}); \textcolor{keyword}{call }dome2d\_initialize\_thickness(h, g, gv, us, pf, &
301                                  just\_read\_params=just\_read)
302        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"adjustment2d"}); \textcolor{keyword}{call }adjustment\_initialize\_thickness(h, g, gv, us, &
303                                        pf, just\_read\_params=just\_read)
304        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"sloshing"}); \textcolor{keyword}{call }sloshing\_initialize\_thickness(h, g, gv, us, pf, &
305                                    just\_read\_params=just\_read)
306        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"seamount"}); \textcolor{keyword}{call }seamount\_initialize\_thickness(h, g, gv, us, pf, &
307                                    just\_read\_params=just\_read)
308        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"dumbbell"}); \textcolor{keyword}{call }dumbbell\_initialize\_thickness(h, g, gv, us, pf, &
309                                    just\_read\_params=just\_read)
310        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"soliton"}); \textcolor{keyword}{call }soliton\_initialize\_thickness(h, g, gv, us)
311        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"phillips"}); \textcolor{keyword}{call }phillips\_initialize\_thickness(h, g, gv, us, pf, &
312                                    just\_read\_params=just\_read)
313        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"rossby\_front"}); \textcolor{keyword}{call }rossby\_front\_initialize\_thickness(h, g, gv, us, &
314                                        pf, just\_read\_params=just\_read)
315        \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"USER"}); \textcolor{keyword}{call }user\_initialize\_thickness(h, g, gv, pf, &
316                                just\_read\_params=just\_read)
317 \textcolor{keywordflow}{       case default} ; \textcolor{keyword}{call }mom\_error(fatal,  \textcolor{stringliteral}{"MOM\_initialize\_state: "}//&
318             \textcolor{stringliteral}{"Unrecognized layer thickness configuration "}//trim(config))
319 \textcolor{keywordflow}{    end select}
320 
321     \textcolor{comment}{! Initialize temperature and salinity (T and S).}
322     \textcolor{keywordflow}{if} ( use\_temperature ) \textcolor{keywordflow}{then}
323       \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"TS\_CONFIG"}, config, &
324              \textcolor{stringliteral}{"A string that determines how the initial tempertures "}//&
325              \textcolor{stringliteral}{"and salinities are specified for a new run: \(\backslash\)n"}//&
326              \textcolor{stringliteral}{" \(\backslash\)t file - read velocities from the file specified \(\backslash\)n"}//&
327              \textcolor{stringliteral}{" \(\backslash\)t\(\backslash\)t by (TS\_FILE). \(\backslash\)n"}//&
328              \textcolor{stringliteral}{" \(\backslash\)t fit - find the temperatures that are consistent with \(\backslash\)n"}//&
329              \textcolor{stringliteral}{" \(\backslash\)t\(\backslash\)t the layer densities and salinity S\_REF. \(\backslash\)n"}//&
330              \textcolor{stringliteral}{" \(\backslash\)t TS\_profile - use temperature and salinity profiles \(\backslash\)n"}//&
331              \textcolor{stringliteral}{" \(\backslash\)t\(\backslash\)t (read from TS\_FILE) to set layer densities. \(\backslash\)n"}//&
332              \textcolor{stringliteral}{" \(\backslash\)t benchmark - use the benchmark test case T & S. \(\backslash\)n"}//&
333              \textcolor{stringliteral}{" \(\backslash\)t linear - linear in logical layer space. \(\backslash\)n"}//&
334              \textcolor{stringliteral}{" \(\backslash\)t DOME2D - 2D DOME initialization. \(\backslash\)n"}//&
335              \textcolor{stringliteral}{" \(\backslash\)t ISOMIP - ISOMIP initialization. \(\backslash\)n"}//&
336              \textcolor{stringliteral}{" \(\backslash\)t adjustment2d - 2d lock exchange T/S ICs. \(\backslash\)n"}//&
337              \textcolor{stringliteral}{" \(\backslash\)t sloshing - sloshing mode T/S ICs. \(\backslash\)n"}//&
338              \textcolor{stringliteral}{" \(\backslash\)t seamount - no motion test with seamount ICs. \(\backslash\)n"}//&
339              \textcolor{stringliteral}{" \(\backslash\)t dumbbell - sloshing channel ICs. \(\backslash\)n"}//&
340              \textcolor{stringliteral}{" \(\backslash\)t rossby\_front - a mixed layer front in thermal wind balance.\(\backslash\)n"}//&
341              \textcolor{stringliteral}{" \(\backslash\)t SCM\_CVMix\_tests - used in the SCM CVMix tests.\(\backslash\)n"}//&
342              \textcolor{stringliteral}{" \(\backslash\)t USER - call a user modified routine."}, &
343              fail\_if\_missing=new\_sim, do\_not\_log=just\_read)
344 \textcolor{comment}{!            " \(\backslash\)t baroclinic\_zone - an analytic baroclinic zone. \(\backslash\)n"//&}
345       \textcolor{keywordflow}{select case} (trim(config))
346         \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"fit"}); \textcolor{keyword}{call }initialize\_temp\_salt\_fit(tv%T, tv%S, g, gv, us, pf, &
347                                eos, tv%P\_Ref, just\_read\_params=just\_read)
348         \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"file"}); \textcolor{keyword}{call }initialize\_temp\_salt\_from\_file(tv%T, tv%S, g, &
349                                 pf, just\_read\_params=just\_read)
350         \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"benchmark"}); \textcolor{keyword}{call }benchmark\_init\_temperature\_salinity(tv%T, tv%S, &
351                                      g, gv, us, pf, eos, tv%P\_Ref, just\_read\_params=just\_read)
352         \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"TS\_profile"}) ; \textcolor{keyword}{call }initialize\_temp\_salt\_from\_profile(tv%T, tv%S, &
353                                        g, pf, just\_read\_params=just\_read)
354         \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"linear"}); \textcolor{keyword}{call }initialize\_temp\_salt\_linear(tv%T, tv%S, g, pf, &
355                                   just\_read\_params=just\_read)
356         \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"DOME2D"}); \textcolor{keyword}{call }dome2d\_initialize\_temperature\_salinity ( tv%T, &
357                                   tv%S, h, g, gv, pf, eos, just\_read\_params=just\_read)
358         \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"ISOMIP"}); \textcolor{keyword}{call }isomip\_initialize\_temperature\_salinity ( tv%T, &
359                                   tv%S, h, g, gv, us, pf, eos, just\_read\_params=just\_read)
360         \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"adjustment2d"}); \textcolor{keyword}{call }adjustment\_initialize\_temperature\_salinity ( tv%T, &
361                                         tv%S, h, g, gv, pf, eos, just\_read\_params=just\_read)
362         \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"baroclinic\_zone"}); \textcolor{keyword}{call }baroclinic\_zone\_init\_temperature\_salinity( tv%T, &
363                                            tv%S, h, g, gv, us, pf, just\_read\_params=just\_read)
364         \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"sloshing"}); \textcolor{keyword}{call }sloshing\_initialize\_temperature\_salinity(tv%T, &
365                                     tv%S, h, g, gv, pf, eos, just\_read\_params=just\_read)
366         \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"seamount"}); \textcolor{keyword}{call }seamount\_initialize\_temperature\_salinity(tv%T, &
367                                     tv%S, h, g, gv, pf, eos, just\_read\_params=just\_read)
368         \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"dumbbell"}); \textcolor{keyword}{call }dumbbell\_initialize\_temperature\_salinity(tv%T, &
369                                     tv%S, h, g, gv, pf, eos, just\_read\_params=just\_read)
370         \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"rossby\_front"}); \textcolor{keyword}{call }rossby\_front\_initialize\_temperature\_salinity ( tv%T, &
371                                         tv%S, h, g, gv, pf, eos, just\_read\_params=just\_read)
372         \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"SCM\_CVMix\_tests"}); \textcolor{keyword}{call }scm\_cvmix\_tests\_ts\_init(tv%T, tv%S, h, &
373                                            g, gv, us, pf, just\_read\_params=just\_read)
374         \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"dense"}); \textcolor{keyword}{call }dense\_water\_initialize\_ts(g, gv, pf, eos, tv%T, tv%S, &
375                                  h, just\_read\_params=just\_read)
376         \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"USER"}); \textcolor{keyword}{call }user\_init\_temperature\_salinity(tv%T, tv%S, g, pf, eos, &
377                                 just\_read\_params=just\_read)
378 \textcolor{keywordflow}{        case default} ; \textcolor{keyword}{call }mom\_error(fatal,  \textcolor{stringliteral}{"MOM\_initialize\_state: "}//&
379                \textcolor{stringliteral}{"Unrecognized Temp & salt configuration "}//trim(config))
380 \textcolor{keywordflow}{      end select}
381 \textcolor{keywordflow}{    endif}
382 \textcolor{keywordflow}{  endif}  \textcolor{comment}{! not from\_Z\_file.}
383   \textcolor{keywordflow}{if} (use\_temperature .and. use\_obc) &
384     \textcolor{keyword}{call }fill\_temp\_salt\_segments(g, obc, tv)
385 
386   \textcolor{comment}{! The thicknesses in halo points might be needed to initialize the velocities.}
387   \textcolor{keywordflow}{if} (new\_sim) \textcolor{keyword}{call }pass\_var(h, g%Domain)
388 
389   \textcolor{comment}{! Initialize velocity components, u and v}
390   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"VELOCITY\_CONFIG"}, config, &
391        \textcolor{stringliteral}{"A string that determines how the initial velocities "}//&
392        \textcolor{stringliteral}{"are specified for a new run: \(\backslash\)n"}//&
393        \textcolor{stringliteral}{" \(\backslash\)t file - read velocities from the file specified \(\backslash\)n"}//&
394        \textcolor{stringliteral}{" \(\backslash\)t\(\backslash\)t by (VELOCITY\_FILE). \(\backslash\)n"}//&
395        \textcolor{stringliteral}{" \(\backslash\)t zero - the fluid is initially at rest. \(\backslash\)n"}//&
396        \textcolor{stringliteral}{" \(\backslash\)t uniform - the flow is uniform (determined by\(\backslash\)n"}//&
397        \textcolor{stringliteral}{" \(\backslash\)t\(\backslash\)t parameters INITIAL\_U\_CONST and INITIAL\_V\_CONST).\(\backslash\)n"}//&
398        \textcolor{stringliteral}{" \(\backslash\)t rossby\_front - a mixed layer front in thermal wind balance.\(\backslash\)n"}//&
399        \textcolor{stringliteral}{" \(\backslash\)t soliton - Equatorial Rossby soliton.\(\backslash\)n"}//&
400        \textcolor{stringliteral}{" \(\backslash\)t USER - call a user modified routine."}, default=\textcolor{stringliteral}{"zero"}, &
401        do\_not\_log=just\_read)
402   \textcolor{keywordflow}{select case} (trim(config))
403      \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"file"}); \textcolor{keyword}{call }initialize\_velocity\_from\_file(u, v, g, us, pf, &
404                              just\_read\_params=just\_read)
405      \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"zero"}); \textcolor{keyword}{call }initialize\_velocity\_zero(u, v, g, pf, &
406                              just\_read\_params=just\_read)
407      \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"uniform"}); \textcolor{keyword}{call }initialize\_velocity\_uniform(u, v, g, us, pf, &
408                                 just\_read\_params=just\_read)
409      \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"circular"}); \textcolor{keyword}{call }initialize\_velocity\_circular(u, v, g, us, pf, &
410                                  just\_read\_params=just\_read)
411      \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"phillips"}); \textcolor{keyword}{call }phillips\_initialize\_velocity(u, v, g, gv, us, pf, &
412                                  just\_read\_params=just\_read)
413      \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"rossby\_front"}); \textcolor{keyword}{call }rossby\_front\_initialize\_velocity(u, v, h, &
414                                      g, gv, us, pf, just\_read\_params=just\_read)
415      \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"soliton"}); \textcolor{keyword}{call }soliton\_initialize\_velocity(u, v, h, g, us)
416      \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"USER"}); \textcolor{keyword}{call }user\_initialize\_velocity(u, v, g, us, pf, &
417                              just\_read\_params=just\_read)
418 \textcolor{keywordflow}{     case default} ; \textcolor{keyword}{call }mom\_error(fatal,  \textcolor{stringliteral}{"MOM\_initialize\_state: "}//&
419           \textcolor{stringliteral}{"Unrecognized velocity configuration "}//trim(config))
420 \textcolor{keywordflow}{  end select}
421 
422   \textcolor{keywordflow}{if} (new\_sim) \textcolor{keyword}{call }pass\_vector(u, v, g%Domain)
423   \textcolor{keywordflow}{if} (debug .and. new\_sim) \textcolor{keywordflow}{then}
424     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{"MOM\_initialize\_state [uv]"}, u, v, g%HI, haloshift=1, scale=us%m\_s\_to\_L\_T)
425 \textcolor{keywordflow}{  endif}
426 
427   \textcolor{comment}{! Optionally convert the thicknesses from m to kg m-2.  This is particularly}
428   \textcolor{comment}{! useful in a non-Boussinesq model.}
429   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"CONVERT\_THICKNESS\_UNITS"}, convert, &
430                \textcolor{stringliteral}{"If true,  convert the thickness initial conditions from "}//&
431                \textcolor{stringliteral}{"units of m to kg m-2 or vice versa, depending on whether "}//&
432                \textcolor{stringliteral}{"BOUSSINESQ is defined. This does not apply if a restart "}//&
433                \textcolor{stringliteral}{"file is read."}, default=.not.gv%Boussinesq, do\_not\_log=just\_read)
434 
435   \textcolor{keywordflow}{if} (new\_sim .and. convert .and. .not.gv%Boussinesq) &
436     \textcolor{comment}{! Convert thicknesses from geomtric distances to mass-per-unit-area.}
437     \textcolor{keyword}{call }convert\_thickness(h, g, gv, us, tv)
438 
439   \textcolor{comment}{! Remove the mass that would be displaced by an ice shelf or inverse barometer.}
440   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"DEPRESS\_INITIAL\_SURFACE"}, depress\_sfc, &
441                \textcolor{stringliteral}{"If true,  depress the initial surface to avoid huge "}//&
442                \textcolor{stringliteral}{"tsunamis when a large surface pressure is applied."}, &
443                default=.false., do\_not\_log=just\_read)
444   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"TRIM\_IC\_FOR\_P\_SURF"}, trim\_ic\_for\_p\_surf, &
445                \textcolor{stringliteral}{"If true, cuts way the top of the column for initial conditions "}//&
446                \textcolor{stringliteral}{"at the depth where the hydrostatic pressure matches the imposed "}//&
447                \textcolor{stringliteral}{"surface pressure which is read from file."}, default=.false., &
448                do\_not\_log=just\_read)
449   \textcolor{keywordflow}{if} (depress\_sfc .and. trim\_ic\_for\_p\_surf) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_initialize\_state: "}//&
450            \textcolor{stringliteral}{"DEPRESS\_INITIAL\_SURFACE and TRIM\_IC\_FOR\_P\_SURF are exclusive and cannot both be True"})
451   \textcolor{keywordflow}{if} (new\_sim .and. debug .and. (depress\_sfc .or. trim\_ic\_for\_p\_surf)) &
452     \textcolor{keyword}{call }hchksum(h, \textcolor{stringliteral}{"Pre-depress: h "}, g%HI, haloshift=1, scale=gv%H\_to\_m)
453   \textcolor{keywordflow}{if} (depress\_sfc) \textcolor{keyword}{call }depress\_surface(h, g, gv, us, pf, tv, just\_read\_params=just\_read)
454   \textcolor{keywordflow}{if} (trim\_ic\_for\_p\_surf) \textcolor{keyword}{call }trim\_for\_ice(pf, g, gv, us, ale\_csp, tv, h, just\_read\_params=just\_read)
455 
456   \textcolor{comment}{! Perhaps we want to run the regridding coordinate generator for multiple}
457   \textcolor{comment}{! iterations here so the initial grid is consistent with the coordinate}
458   \textcolor{keywordflow}{if} (useale) \textcolor{keywordflow}{then}
459     \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"REGRID\_ACCELERATE\_INIT"}, regrid\_accelerate, &
460          \textcolor{stringliteral}{"If true, runs REGRID\_ACCELERATE\_ITERATIONS iterations of the regridding "}//&
461          \textcolor{stringliteral}{"algorithm to push the initial grid to be consistent with the initial "}//&
462          \textcolor{stringliteral}{"condition. Useful only for state-based and iterative coordinates."}, &
463          default=.false., do\_not\_log=just\_read)
464     \textcolor{keywordflow}{if} (regrid\_accelerate) \textcolor{keywordflow}{then}
465       \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"REGRID\_ACCELERATE\_ITERATIONS"}, regrid\_iterations, &
466            \textcolor{stringliteral}{"The number of regridding iterations to perform to generate "}//&
467            \textcolor{stringliteral}{"an initial grid that is consistent with the initial conditions."}, &
468            default=1, do\_not\_log=just\_read)
469 
470       \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"DT"}, dt, \textcolor{stringliteral}{"Timestep"}, fail\_if\_missing=.true., scale=us%s\_to\_T)
471 
472       \textcolor{keywordflow}{if} (new\_sim .and. debug) &
473         \textcolor{keyword}{call }hchksum(h, \textcolor{stringliteral}{"Pre-ALE\_regrid: h "}, g%HI, haloshift=1, scale=gv%H\_to\_m)
474       \textcolor{keyword}{call }ale\_regrid\_accelerated(ale\_csp, g, gv, h, tv, regrid\_iterations, u, v, obc, tracer\_reg, &
475                                   dt=dt, initial=.true.)
476 \textcolor{keywordflow}{    endif}
477 \textcolor{keywordflow}{  endif}
478   \textcolor{comment}{! This is the end of the block of code that might have initialized fields}
479   \textcolor{comment}{! internally at the start of a new run.}
480 
481   \textcolor{keywordflow}{if} (.not.new\_sim) \textcolor{keywordflow}{then} \textcolor{comment}{! This block restores the state from a restart file.}
482     \textcolor{comment}{!    This line calls a subroutine that reads the initial conditions}
483     \textcolor{comment}{!  from a previously generated file.}
484     \textcolor{keyword}{call }restore\_state(dirs%input\_filename, dirs%restart\_input\_dir, time, &
485                        g, restart\_cs)
486     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(time\_in)) time = time\_in
487     \textcolor{keywordflow}{if} ((gv%m\_to\_H\_restart /= 0.0) .and. (gv%m\_to\_H\_restart /= gv%m\_to\_H)) \textcolor{keywordflow}{then}
488       h\_rescale = gv%m\_to\_H / gv%m\_to\_H\_restart
489       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; h(i,j,k) = h\_rescale * h(i,j,k) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
490 \textcolor{keywordflow}{    endif}
491     \textcolor{keywordflow}{if} ( (us%s\_to\_T\_restart * us%m\_to\_L\_restart /= 0.0) .and. &
492          ((us%m\_to\_L * us%s\_to\_T\_restart) /= (us%m\_to\_L\_restart * us%s\_to\_T)) ) \textcolor{keywordflow}{then}
493       vel\_rescale = (us%m\_to\_L * us%s\_to\_T\_restart) /  (us%m\_to\_L\_restart * us%s\_to\_T)
494       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb ; u(i,j,k) = vel\_rescale * u(i,j,k) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
495       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied ; v(i,j,k) = vel\_rescale * v(i,j,k) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
496 \textcolor{keywordflow}{    endif}
497 \textcolor{keywordflow}{  endif}
498 
499   \textcolor{keywordflow}{if} ( use\_temperature ) \textcolor{keywordflow}{then}
500     \textcolor{keyword}{call }pass\_var(tv%T, g%Domain, complete=.false.)
501     \textcolor{keyword}{call }pass\_var(tv%S, g%Domain, complete=.false.)
502 \textcolor{keywordflow}{  endif}
503   \textcolor{keyword}{call }pass\_var(h, g%Domain)
504 
505   \textcolor{keywordflow}{if} (debug) \textcolor{keywordflow}{then}
506     \textcolor{keyword}{call }hchksum(h, \textcolor{stringliteral}{"MOM\_initialize\_state: h "}, g%HI, haloshift=1, scale=gv%H\_to\_m)
507     \textcolor{keywordflow}{if} ( use\_temperature ) \textcolor{keyword}{call }hchksum(tv%T, \textcolor{stringliteral}{"MOM\_initialize\_state: T "}, g%HI, haloshift=1)
508     \textcolor{keywordflow}{if} ( use\_temperature ) \textcolor{keyword}{call }hchksum(tv%S, \textcolor{stringliteral}{"MOM\_initialize\_state: S "}, g%HI, haloshift=1)
509     \textcolor{keywordflow}{if} ( use\_temperature .and. debug\_layers) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz
510       \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("MOM\_IS: T[",I2,"]")'}) k
511       \textcolor{keyword}{call }hchksum(tv%T(:,:,k), mesg, g%HI, haloshift=1)
512       \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("MOM\_IS: S[",I2,"]")'}) k
513       \textcolor{keyword}{call }hchksum(tv%S(:,:,k), mesg, g%HI, haloshift=1)
514 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ endif}
515 \textcolor{keywordflow}{  endif}
516 
517   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"SPONGE"}, use\_sponge, &
518                  \textcolor{stringliteral}{"If true, sponges may be applied anywhere in the domain. "}//&
519                  \textcolor{stringliteral}{"The exact location and properties of those sponges are "}//&
520                  \textcolor{stringliteral}{"specified via SPONGE\_CONFIG."}, default=.false.)
521   \textcolor{keywordflow}{if} ( use\_sponge ) \textcolor{keywordflow}{then}
522     \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"SPONGE\_CONFIG"}, config, &
523                  \textcolor{stringliteral}{"A string that sets how the sponges are configured: \(\backslash\)n"}//&
524                  \textcolor{stringliteral}{" \(\backslash\)t file - read sponge properties from the file \(\backslash\)n"}//&
525                  \textcolor{stringliteral}{" \(\backslash\)t\(\backslash\)t specified by (SPONGE\_FILE).\(\backslash\)n"}//&
526                  \textcolor{stringliteral}{" \(\backslash\)t ISOMIP - apply ale sponge in the ISOMIP case \(\backslash\)n"}//&
527                  \textcolor{stringliteral}{" \(\backslash\)t RGC - apply sponge in the rotating\_gravity\_current case \(\backslash\)n"}//&
528                  \textcolor{stringliteral}{" \(\backslash\)t DOME - use a slope and channel configuration for the \(\backslash\)n"}//&
529                  \textcolor{stringliteral}{" \(\backslash\)t\(\backslash\)t DOME sill-overflow test case. \(\backslash\)n"}//&
530                  \textcolor{stringliteral}{" \(\backslash\)t BFB - Sponge at the southern boundary of the domain\(\backslash\)n"}//&
531                  \textcolor{stringliteral}{" \(\backslash\)t\(\backslash\)t for buoyancy-forced basin case.\(\backslash\)n"}//&
532                  \textcolor{stringliteral}{" \(\backslash\)t USER - call a user modified routine."}, default=\textcolor{stringliteral}{"file"})
533     \textcolor{keywordflow}{select case} (trim(config))
534       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"DOME"}); \textcolor{keyword}{call }dome\_initialize\_sponges(g, gv, us, tv, pf, sponge\_csp)
535       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"DOME2D"}); \textcolor{keyword}{call }dome2d\_initialize\_sponges(g, gv, us, tv, pf, useale, &
536                                                       sponge\_csp, ale\_sponge\_csp)
537       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"ISOMIP"}); \textcolor{keyword}{call }isomip\_initialize\_sponges(g, gv, us, tv, pf, useale, &
538                                                       sponge\_csp, ale\_sponge\_csp)
539       \textcolor{keywordflow}{case}(\textcolor{stringliteral}{"RGC"}); \textcolor{keyword}{call }rgc\_initialize\_sponges(g, gv, us, tv, u, v, pf, useale, &
540                                                      sponge\_csp, ale\_sponge\_csp)
541       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"USER"}); \textcolor{keyword}{call }user\_initialize\_sponges(g, gv, use\_temperature, tv, pf, sponge\_csp, h)
542       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"BFB"}); \textcolor{keyword}{call }bfb\_initialize\_sponges\_southonly(g, gv, us, use\_temperature, tv, pf, &
543                                                           sponge\_csp, h)
544       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"DUMBBELL"}); \textcolor{keyword}{call }dumbbell\_initialize\_sponges(g, gv, us, tv, pf, useale, &
545                                                           sponge\_csp, ale\_sponge\_csp)
546       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"phillips"}); \textcolor{keyword}{call }phillips\_initialize\_sponges(g, gv, us, tv, pf, sponge\_csp, h)
547       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"dense"}); \textcolor{keyword}{call }dense\_water\_initialize\_sponges(g, gv, us, tv, pf, useale, &
548                                                           sponge\_csp, ale\_sponge\_csp)
549       \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"file"}); \textcolor{keyword}{call }initialize\_sponges\_file(g, gv, us, use\_temperature, tv, pf, &
550                                                   sponge\_csp, ale\_sponge\_csp, time)
551 \textcolor{keywordflow}{      case default} ; \textcolor{keyword}{call }mom\_error(fatal,  \textcolor{stringliteral}{"MOM\_initialize\_state: "}//&
552              \textcolor{stringliteral}{"Unrecognized sponge configuration "}//trim(config))
553 \textcolor{keywordflow}{    end select}
554 \textcolor{keywordflow}{  endif}
555 
556   \textcolor{comment}{! Reads OBC parameters not pertaining to the location of the boundaries}
557   \textcolor{keyword}{call }open\_boundary\_init(g, gv, us, pf, obc, restart\_cs)
558 
559   \textcolor{comment}{! This controls user code for setting open boundary data}
560   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}
561      \textcolor{keyword}{call }initialize\_segment\_data(g, obc, pf) \textcolor{comment}{!   call initialize\_segment\_data(G, OBC, param\_file)}
562 \textcolor{comment}{!     call open\_boundary\_config(G, US, PF, OBC)}
563     \textcolor{comment}{! Call this once to fill boundary arrays from fixed values}
564     \textcolor{keywordflow}{if} (.not. obc%needs\_IO\_for\_data)  &
565       \textcolor{keyword}{call }update\_obc\_segment\_data(g, gv, us, obc, tv, h, time)
566 
567     \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"OBC\_USER\_CONFIG"}, config, &
568                  \textcolor{stringliteral}{"A string that sets how the user code is invoked to set open boundary data: \(\backslash\)n"}//&
569                  \textcolor{stringliteral}{"   DOME - specified inflow on northern boundary\(\backslash\)n"}//&
570                  \textcolor{stringliteral}{"   dyed\_channel - supercritical with dye on the inflow boundary\(\backslash\)n"}//&
571                  \textcolor{stringliteral}{"   dyed\_obcs - circle\_obcs with dyes on the open boundaries\(\backslash\)n"}//&
572                  \textcolor{stringliteral}{"   Kelvin - barotropic Kelvin wave forcing on the western boundary\(\backslash\)n"}//&
573                  \textcolor{stringliteral}{"   shelfwave - Flather with shelf wave forcing on western boundary\(\backslash\)n"}//&
574                  \textcolor{stringliteral}{"   supercritical - now only needed here for the allocations\(\backslash\)n"}//&
575                  \textcolor{stringliteral}{"   tidal\_bay - Flather with tidal forcing on eastern boundary\(\backslash\)n"}//&
576                  \textcolor{stringliteral}{"   USER - user specified"}, default=\textcolor{stringliteral}{"none"})
577     \textcolor{keywordflow}{if} (trim(config) == \textcolor{stringliteral}{"DOME"}) \textcolor{keywordflow}{then}
578       \textcolor{keyword}{call }dome\_set\_obc\_data(obc, tv, g, gv, us, pf, tracer\_reg)
579     \textcolor{keywordflow}{elseif} (trim(config) == \textcolor{stringliteral}{"dyed\_channel"}) \textcolor{keywordflow}{then}
580       \textcolor{keyword}{call }dyed\_channel\_set\_obc\_tracer\_data(obc, g, gv, pf, tracer\_reg)
581       obc%update\_OBC = .true.
582     \textcolor{keywordflow}{elseif} (trim(config) == \textcolor{stringliteral}{"dyed\_obcs"}) \textcolor{keywordflow}{then}
583       \textcolor{keyword}{call }dyed\_obcs\_set\_obc\_data(obc, g, gv, pf, tracer\_reg)
584     \textcolor{keywordflow}{elseif} (trim(config) == \textcolor{stringliteral}{"Kelvin"}) \textcolor{keywordflow}{then}
585       obc%update\_OBC = .true.
586     \textcolor{keywordflow}{elseif} (trim(config) == \textcolor{stringliteral}{"shelfwave"}) \textcolor{keywordflow}{then}
587       obc%update\_OBC = .true.
588     \textcolor{keywordflow}{elseif} (lowercase(trim(config)) == \textcolor{stringliteral}{"supercritical"}) \textcolor{keywordflow}{then}
589       \textcolor{keyword}{call }supercritical\_set\_obc\_data(obc, g, pf)
590     \textcolor{keywordflow}{elseif} (trim(config) == \textcolor{stringliteral}{"tidal\_bay"}) \textcolor{keywordflow}{then}
591       obc%update\_OBC = .true.
592     \textcolor{keywordflow}{elseif} (trim(config) == \textcolor{stringliteral}{"USER"}) \textcolor{keywordflow}{then}
593       \textcolor{keyword}{call }user\_set\_obc\_data(obc, tv, g, pf, tracer\_reg)
594     \textcolor{keywordflow}{elseif} (.not. trim(config) == \textcolor{stringliteral}{"none"}) \textcolor{keywordflow}{then}
595       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"The open boundary conditions specified by "}//&
596               \textcolor{stringliteral}{"OBC\_USER\_CONFIG = "}//trim(config)//\textcolor{stringliteral}{" have not been fully implemented."})
597 \textcolor{keywordflow}{    endif}
598     \textcolor{keywordflow}{if} (open\_boundary\_query(obc, apply\_open\_obc=.true.)) \textcolor{keywordflow}{then}
599       \textcolor{keyword}{call }set\_tracer\_data(obc, tv, h, g, pf, tracer\_reg)
600 \textcolor{keywordflow}{    endif}
601 \textcolor{keywordflow}{  endif}
602 \textcolor{comment}{! if (open\_boundary\_query(OBC, apply\_nudged\_OBC=.true.)) then}
603 \textcolor{comment}{!   call set\_3D\_OBC\_data(OBC, tv, h, G, PF, tracer\_Reg)}
604 \textcolor{comment}{! endif}
605   \textcolor{comment}{! Still need a way to specify the boundary values}
606   \textcolor{keywordflow}{if} (debug.and.\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then}
607     \textcolor{keyword}{call }hchksum(g%mask2dT, \textcolor{stringliteral}{'MOM\_initialize\_state: mask2dT '}, g%HI)
608     \textcolor{keyword}{call }uvchksum(\textcolor{stringliteral}{'MOM\_initialize\_state: mask2dC[uv]'}, g%mask2dCu,  &
609                   g%mask2dCv, g%HI)
610     \textcolor{keyword}{call }qchksum(g%mask2dBu, \textcolor{stringliteral}{'MOM\_initialize\_state: mask2dBu '}, g%HI)
611 \textcolor{keywordflow}{  endif}
612 
613   \textcolor{keywordflow}{if} (debug\_obc) \textcolor{keyword}{call }open\_boundary\_test\_extern\_h(g, gv, obc, h)
614   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{'MOM\_initialize\_state()'})
615 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_a807c1c2bb13f172945c7c25f3af7abd1}\label{namespacemom__state__initialization_a807c1c2bb13f172945c7c25f3af7abd1}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!mom\+\_\+state\+\_\+init\+\_\+tests@{mom\+\_\+state\+\_\+init\+\_\+tests}}
\index{mom\+\_\+state\+\_\+init\+\_\+tests@{mom\+\_\+state\+\_\+init\+\_\+tests}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{mom\+\_\+state\+\_\+init\+\_\+tests()}{mom\_state\_init\_tests()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::mom\+\_\+state\+\_\+init\+\_\+tests (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Run simple unit tests. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em tv} & Thermodynamics structure. \\
\hline
\end{DoxyParams}


Definition at line 2560 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
2560   \textcolor{keywordtype}{type}(ocean\_grid\_type),     \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< The ocean's grid structure.}
2561   \textcolor{keywordtype}{type}(verticalgrid\_type),   \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !< The ocean's vertical grid structure.}
2562   \textcolor{keywordtype}{type}(unit\_scale\_type),     \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
2563   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),     \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{   !< Thermodynamics structure.}
2564 
2565   \textcolor{comment}{! Local variables}
2566   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: nk=5
2567   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)} :: t, t\_t, t\_b \textcolor{comment}{! Temperatures [degC]}
2568   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)} :: s, s\_t, s\_b \textcolor{comment}{! Salinities [ppt]}
2569   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)} :: rho \textcolor{comment}{! Layer density [R ~> kg m-3]}
2570   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)} :: h   \textcolor{comment}{! Layer thicknesses [H ~> m or kg m-2]}
2571   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk)} :: z   \textcolor{comment}{! Height of layer center [Z ~> m]}
2572   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nk+1)} :: e \textcolor{comment}{! Interface heights [Z ~> m]}
2573   \textcolor{keywordtype}{integer} :: k
2574   \textcolor{keywordtype}{real} :: p\_tot, p\_t, p\_b    \textcolor{comment}{! Pressures [R L2 T-2 ~> Pa]}
2575   \textcolor{keywordtype}{real} :: z\_out              \textcolor{comment}{! Output height [Z ~> m]}
2576   \textcolor{keywordtype}{real} :: i\_z\_scale          \textcolor{comment}{! The inverse of the height scale for prescribed gradients [Z-1 ~> m-1]}
2577   \textcolor{keywordtype}{type}(remapping\_cs), \textcolor{keywordtype}{pointer} :: remap\_cs => null()
2578 
2579   i\_z\_scale = 1.0 / (500.0*us%m\_to\_Z)
2580   \textcolor{keywordflow}{do} k = 1, nk
2581     h(k) = 100.0*gv%m\_to\_H
2582 \textcolor{keywordflow}{  enddo}
2583   e(1) = 0.
2584   \textcolor{keywordflow}{do} k = 1, nk
2585     e(k+1) = e(k) - gv%H\_to\_Z * h(k)
2586 \textcolor{keywordflow}{  enddo}
2587   p\_tot = 0.
2588   \textcolor{keywordflow}{do} k = 1, nk
2589     z(k) = 0.5 * ( e(k) + e(k+1) )
2590     t\_t(k) = 20. + (0. * i\_z\_scale) * e(k)
2591     t(k)   = 20. + (0. * i\_z\_scale)*z(k)
2592     t\_b(k) = 20. + (0. * i\_z\_scale)*e(k+1)
2593     s\_t(k) = 35. - (0. * i\_z\_scale)*e(k)
2594     s(k)   = 35. + (0. * i\_z\_scale)*z(k)
2595     s\_b(k) = 35. - (0. * i\_z\_scale)*e(k+1)
2596     \textcolor{keyword}{call }calculate\_density(0.5*(t\_t(k)+t\_b(k)), 0.5*(s\_t(k)+s\_b(k)), -gv%Rho0*gv%g\_Earth*us%m\_to\_Z*z(k), &
2597                            rho(k), tv%eqn\_of\_state)
2598     p\_tot = p\_tot + gv%g\_Earth * rho(k) * gv%H\_to\_Z*h(k)
2599 \textcolor{keywordflow}{  enddo}
2600 
2601   p\_t = 0.
2602   \textcolor{keywordflow}{do} k = 1, nk
2603     \textcolor{keyword}{call }find\_depth\_of\_pressure\_in\_cell(t\_t(k), t\_b(k), s\_t(k), s\_b(k), e(k), e(k+1), p\_t, 0.5*p\_tot, &
2604                                         gv%Rho0, gv%g\_Earth, tv%eqn\_of\_state, us, p\_b, z\_out)
2605     \textcolor{keyword}{write}(0,*) k, us%RL2\_T2\_to\_Pa*p\_t, us%RL2\_T2\_to\_Pa*p\_b, 0.5*us%RL2\_T2\_to\_Pa*p\_tot, &
2606                us%Z\_to\_m*e(k), us%Z\_to\_m*e(k+1), us%Z\_to\_m*z\_out
2607     p\_t = p\_b
2608 \textcolor{keywordflow}{  enddo}
2609   \textcolor{keyword}{write}(0,*) us%RL2\_T2\_to\_Pa*p\_b, us%RL2\_T2\_to\_Pa*p\_tot
2610 
2611   \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{''}
2612   \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{' ==================================================================== '}
2613   \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{''}
2614   \textcolor{keyword}{write}(0,*) gv%H\_to\_m*h
2615   \textcolor{keyword}{call }cut\_off\_column\_top(nk, tv, gv, us, gv%g\_Earth, -e(nk+1), gv%Angstrom\_Z, &
2616                           t, t\_t, t\_b, s, s\_t, s\_b, 0.5*p\_tot, h, remap\_cs)
2617   \textcolor{keyword}{write}(0,*) gv%H\_to\_m*h
2618 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_a4b1a2ab2ba01da2b898f5e65ebc30c9d}\label{namespacemom__state__initialization_a4b1a2ab2ba01da2b898f5e65ebc30c9d}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!mom\+\_\+temp\+\_\+salt\+\_\+initialize\+\_\+from\+\_\+z@{mom\+\_\+temp\+\_\+salt\+\_\+initialize\+\_\+from\+\_\+z}}
\index{mom\+\_\+temp\+\_\+salt\+\_\+initialize\+\_\+from\+\_\+z@{mom\+\_\+temp\+\_\+salt\+\_\+initialize\+\_\+from\+\_\+z}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{mom\+\_\+temp\+\_\+salt\+\_\+initialize\+\_\+from\+\_\+z()}{mom\_temp\_salt\_initialize\_from\_z()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::mom\+\_\+temp\+\_\+salt\+\_\+initialize\+\_\+from\+\_\+z (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(out)}]{h,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(inout)}]{tv,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{PF,  }\item[{logical, intent(in), optional}]{just\+\_\+read\+\_\+params }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine determines the isopycnal or other coordinate interfaces and layer potential temperatures and salinities directly from a z-\/space file on a latitude-\/longitude grid. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt out}  & {\em h} & Layer thicknesses being initialized \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em tv} & A structure pointing to various thermodynamic variables including temperature and salinity\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em pf} & A structure indicating the open file to parse for model parameter values.\\
\hline
\mbox{\tt in}  & {\em just\+\_\+read\+\_\+params} & If present and true, this call will only read parameters without changing h. \\
\hline
\end{DoxyParams}


Definition at line 1971 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
1971   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< The ocean's grid structure}
1972   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
1973                            \textcolor{keywordtype}{intent(out)}   :: h\textcolor{comment}{    !< Layer thicknesses being initialized [H ~> m or kg m-2]}
1974   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{   !< A structure pointing to various thermodynamic}
1975 \textcolor{comment}{                                                 !! variables including temperature and salinity}
1976   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !< The ocean's vertical grid structure}
1977   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
1978   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: pf\textcolor{comment}{   !< A structure indicating the open file}
1979 \textcolor{comment}{                                                 !! to parse for model parameter values.}
1980   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: just\_read\_params\textcolor{comment}{ !< If present and true, this call will}
1981 \textcolor{comment}{                                                      !! only read parameters without changing h.}
1982 
1983   \textcolor{comment}{! Local variables}
1984   \textcolor{keywordtype}{character(len=200)} :: filename\textcolor{comment}{   !< The name of an input file containing temperature}
1985 \textcolor{comment}{                                   !! and salinity in z-space; also used for  ice shelf area.}
1986   \textcolor{keywordtype}{character(len=200)} :: tfilename\textcolor{comment}{  !< The name of an input file containing only temperature}
1987 \textcolor{comment}{                                   !! in z-space.}
1988   \textcolor{keywordtype}{character(len=200)} :: sfilename\textcolor{comment}{  !< The name of an input file containing only salinity}
1989 \textcolor{comment}{                                   !! in z-space.}
1990   \textcolor{keywordtype}{character(len=200)} :: shelf\_file\textcolor{comment}{ !< The name of an input file used for  ice shelf area.}
1991   \textcolor{keywordtype}{character(len=200)} :: inputdir   \textcolor{comment}{!! The directory where NetCDF input filesare.}
1992   \textcolor{keywordtype}{character(len=200)} :: mesg, area\_varname, ice\_shelf\_file
1993 
1994   \textcolor{keywordtype}{type}(eos\_type), \textcolor{keywordtype}{pointer} :: eos => null()
1995   \textcolor{keywordtype}{type}(thermo\_var\_ptrs) :: tv\_loc   \textcolor{comment}{! A temporary thermo\_var container}
1996   \textcolor{keywordtype}{type}(verticalgrid\_type) :: gv\_loc \textcolor{comment}{! A temporary vertical grid structure}
1997   \textcolor{comment}{! This include declares and sets the variable "version".}
1998 \textcolor{preprocessor}{# include "version\_variable.h"}
1999 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_initialize\_layers\_from\_Z"} \textcolor{comment}{! This module's name.}
2000 
2001   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: eosdom \textcolor{comment}{! The i-computational domain for the equation of state}
2002   \textcolor{keywordtype}{integer} :: is, ie, js, je, nz \textcolor{comment}{! compute domain indices}
2003   \textcolor{keywordtype}{integer} :: isc,iec,jsc,jec    \textcolor{comment}{! global compute domain indices}
2004   \textcolor{keywordtype}{integer} :: isg, ieg, jsg, jeg \textcolor{comment}{! global extent}
2005   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed \textcolor{comment}{! data domain indices}
2006 
2007   \textcolor{keywordtype}{integer} :: i, j, k, ks, np, ni, nj
2008   \textcolor{keywordtype}{integer} :: nkml     \textcolor{comment}{! The number of layers in the mixed layer.}
2009 
2010   \textcolor{keywordtype}{integer} :: kd, inconsistent
2011   \textcolor{keywordtype}{integer} :: nkd      \textcolor{comment}{! number of levels to use for regridding input arrays}
2012   \textcolor{keywordtype}{real}    :: eps\_z    \textcolor{comment}{! A negligibly thin layer thickness [Z ~> m].}
2013   \textcolor{keywordtype}{real}    :: eps\_rho  \textcolor{comment}{! A negligibly small density difference [R ~> kg m-3].}
2014   \textcolor{keywordtype}{real}    :: pi\_180   \textcolor{comment}{! for conversion from degrees to radians}
2015 
2016   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer} :: shelf\_area => null()
2017   \textcolor{keywordtype}{real}    :: hmix\_default \textcolor{comment}{! The default initial mixed layer depth [m].}
2018   \textcolor{keywordtype}{real}    :: hmix\_depth   \textcolor{comment}{! The mixed layer depth in the initial condition [Z ~> m].}
2019   \textcolor{keywordtype}{real}    :: dilate       \textcolor{comment}{! A dilation factor to match topography [nondim]}
2020   \textcolor{keywordtype}{real}    :: missing\_value\_temp, missing\_value\_salt
2021   \textcolor{keywordtype}{logical} :: correct\_thickness
2022   \textcolor{keywordtype}{character(len=40)} :: potemp\_var, salin\_var
2023   \textcolor{keywordtype}{character(len=8)}  :: laynum
2024 
2025   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: niter=10   \textcolor{comment}{! number of iterations for t/s adjustment to layer density}
2026   \textcolor{keywordtype}{logical} :: just\_read    \textcolor{comment}{! If true, just read parameters but set nothing.}
2027   \textcolor{keywordtype}{logical}            :: adjust\_temperature = .true.  \textcolor{comment}{! fit t/s to target densities}
2028   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter}    :: missing\_value = -1.e20
2029   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter}    :: temp\_land\_fill = 0.0, salt\_land\_fill = 35.0
2030   \textcolor{keywordtype}{logical} :: reentrant\_x, tripolar\_n,dbg
2031   \textcolor{keywordtype}{logical} :: debug = .false.  \textcolor{comment}{! manually set this to true for verbose output}
2032 
2033   \textcolor{comment}{! data arrays}
2034   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable} :: z\_edges\_in, z\_in \textcolor{comment}{! Interface heights [Z ~> m]}
2035   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable} :: rb  \textcolor{comment}{! Interface densities [R ~> kg m-3]}
2036   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{target} :: temp\_z, salt\_z, mask\_z
2037   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{allocatable} :: rho\_z \textcolor{comment}{! Densities in Z-space [R ~> kg m-3]}
2038   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)} :: zi   \textcolor{comment}{! Interface heights [Z ~> m].}
2039   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}  :: nlevs
2040   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G))}   :: press  \textcolor{comment}{! Pressures [R L2 T-2 ~> Pa].}
2041 
2042   \textcolor{comment}{! Local variables for ALE remapping}
2043   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable} :: htarget \textcolor{comment}{! Target thicknesses [Z ~> m].}
2044   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{allocatable} :: area\_shelf\_h \textcolor{comment}{! Shelf-covered area per grid cell [L2 ~> m2]}
2045   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{target} :: frac\_shelf\_h \textcolor{comment}{! Fractional shelf area per grid cell [nondim]}
2046   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{target} :: tmpt1din, tmps1din
2047   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{allocatable} :: tmp\_mask\_in
2048   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{allocatable} :: h1 \textcolor{comment}{! Thicknesses [H ~> m or kg m-2].}
2049   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{allocatable} :: dz\_interface \textcolor{comment}{! Change in position of interface due to regridding}
2050   \textcolor{keywordtype}{real} :: ztopofcell, zbottomofcell \textcolor{comment}{! Heights in Z units [Z ~> m].}
2051   \textcolor{keywordtype}{type}(regridding\_cs) :: regridcs \textcolor{comment}{! Regridding parameters and work arrays}
2052   \textcolor{keywordtype}{type}(remapping\_cs) :: remapcs \textcolor{comment}{! Remapping parameters and work arrays}
2053 
2054   \textcolor{keywordtype}{logical} :: homogenize, usealeremapping, remap\_full\_column, remap\_general, remap\_old\_alg
2055   \textcolor{keywordtype}{logical} :: answers\_2018, default\_2018\_answers, hor\_regrid\_answers\_2018
2056   \textcolor{keywordtype}{logical} :: use\_ice\_shelf
2057   \textcolor{keywordtype}{logical} :: pre\_gridded
2058   \textcolor{keywordtype}{logical} :: separate\_mixed\_layer  \textcolor{comment}{! If true, handle the mixed layers differently.}
2059   \textcolor{keywordtype}{character(len=10)} :: remappingscheme
2060   \textcolor{keywordtype}{real} :: tempavg, saltavg
2061   \textcolor{keywordtype}{integer} :: npoints, ans
2062   \textcolor{keywordtype}{integer} :: id\_clock\_routine, id\_clock\_read, id\_clock\_interp, id\_clock\_fill, id\_clock\_ale
2063 
2064   id\_clock\_routine = cpu\_clock\_id(\textcolor{stringliteral}{'(Initialize from Z)'}, grain=clock\_routine)
2065   id\_clock\_ale = cpu\_clock\_id(\textcolor{stringliteral}{'(Initialize from Z) ALE'}, grain=clock\_loop)
2066 
2067   \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_routine)
2068 
2069   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
2070   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
2071   isg = g%isg ; ieg = g%ieg ; jsg = g%jsg ; jeg = g%jeg
2072 
2073   pi\_180=atan(1.0)/45.
2074 
2075   just\_read = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(just\_read\_params)) just\_read = just\_read\_params
2076 
2077   \textcolor{keywordflow}{if} (.not.just\_read) \textcolor{keyword}{call }calltree\_enter(trim(mdl)//\textcolor{stringliteral}{"(), MOM\_state\_initialization.F90"})
2078   \textcolor{keywordflow}{if} (.not.just\_read) \textcolor{keyword}{call }log\_version(pf, mdl, version, \textcolor{stringliteral}{""})
2079 
2080   inputdir = \textcolor{stringliteral}{"."} ;  \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir)
2081   inputdir = slasher(inputdir)
2082 
2083   eos => tv%eqn\_of\_state
2084 
2085   reentrant\_x = .false. ; \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"REENTRANT\_X"}, reentrant\_x, default=.true.)
2086   tripolar\_n = .false. ;  \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"TRIPOLAR\_N"}, tripolar\_n, default=.false.)
2087 
2088   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"TEMP\_SALT\_Z\_INIT\_FILE"},filename, &
2089                  \textcolor{stringliteral}{"The name of the z-space input file used to initialize "}//&
2090                  \textcolor{stringliteral}{"temperatures (T) and salinities (S). If T and S are not "}//&
2091                  \textcolor{stringliteral}{"in the same file, TEMP\_Z\_INIT\_FILE and SALT\_Z\_INIT\_FILE "}//&
2092                  \textcolor{stringliteral}{"must be set."},default=\textcolor{stringliteral}{"temp\_salt\_z.nc"},do\_not\_log=just\_read)
2093   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"TEMP\_Z\_INIT\_FILE"},tfilename, &
2094                  \textcolor{stringliteral}{"The name of the z-space input file used to initialize "}//&
2095                  \textcolor{stringliteral}{"temperatures, only."}, default=trim(filename),do\_not\_log=just\_read)
2096   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"SALT\_Z\_INIT\_FILE"},sfilename, &
2097                  \textcolor{stringliteral}{"The name of the z-space input file used to initialize "}//&
2098                  \textcolor{stringliteral}{"temperatures, only."}, default=trim(filename),do\_not\_log=just\_read)
2099   filename = trim(inputdir)//trim(filename)
2100   tfilename = trim(inputdir)//trim(tfilename)
2101   sfilename = trim(inputdir)//trim(sfilename)
2102   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"Z\_INIT\_FILE\_PTEMP\_VAR"}, potemp\_var, &
2103                  \textcolor{stringliteral}{"The name of the potential temperature variable in "}//&
2104                  \textcolor{stringliteral}{"TEMP\_Z\_INIT\_FILE."}, default=\textcolor{stringliteral}{"ptemp"},do\_not\_log=just\_read)
2105   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"Z\_INIT\_FILE\_SALT\_VAR"}, salin\_var, &
2106                  \textcolor{stringliteral}{"The name of the salinity variable in "}//&
2107                  \textcolor{stringliteral}{"SALT\_Z\_INIT\_FILE."}, default=\textcolor{stringliteral}{"salt"},do\_not\_log=just\_read)
2108   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"Z\_INIT\_HOMOGENIZE"}, homogenize, &
2109                  \textcolor{stringliteral}{"If True, then horizontally homogenize the interpolated "}//&
2110                  \textcolor{stringliteral}{"initial conditions."}, default=.false., do\_not\_log=just\_read)
2111   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"Z\_INIT\_ALE\_REMAPPING"}, usealeremapping, &
2112                  \textcolor{stringliteral}{"If True, then remap straight to model coordinate from file."}, &
2113                  default=.false., do\_not\_log=just\_read)
2114   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"Z\_INIT\_REMAPPING\_SCHEME"}, remappingscheme, &
2115                  \textcolor{stringliteral}{"The remapping scheme to use if using Z\_INIT\_ALE\_REMAPPING "}//&
2116                  \textcolor{stringliteral}{"is True."}, default=\textcolor{stringliteral}{"PPM\_IH4"}, do\_not\_log=just\_read)
2117   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"Z\_INIT\_REMAP\_GENERAL"}, remap\_general, &
2118                  \textcolor{stringliteral}{"If false, only initializes to z* coordinates. "}//&
2119                  \textcolor{stringliteral}{"If true, allows initialization directly to general coordinates."},&
2120                  default=.false., do\_not\_log=just\_read)
2121   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"Z\_INIT\_REMAP\_FULL\_COLUMN"}, remap\_full\_column, &
2122                  \textcolor{stringliteral}{"If false, only reconstructs profiles for valid data points. "}//&
2123                  \textcolor{stringliteral}{"If true, inserts vanished layers below the valid data."}, &
2124                  default=remap\_general, do\_not\_log=just\_read)
2125   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"Z\_INIT\_REMAP\_OLD\_ALG"}, remap\_old\_alg, &
2126                  \textcolor{stringliteral}{"If false, uses the preferred remapping algorithm for initialization. "}//&
2127                  \textcolor{stringliteral}{"If true, use an older, less robust algorithm for remapping."}, &
2128                  default=.false., do\_not\_log=just\_read)
2129   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"DEFAULT\_2018\_ANSWERS"}, default\_2018\_answers, &
2130                  \textcolor{stringliteral}{"This sets the default value for the various \_2018\_ANSWERS parameters."}, &
2131                  default=.false.)
2132   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"TEMP\_SALT\_INIT\_VERTICAL\_REMAP\_ONLY"}, pre\_gridded, &
2133                  \textcolor{stringliteral}{"If true, initial conditions are on the model horizontal grid. "} //&
2134                  \textcolor{stringliteral}{"Extrapolation over missing ocean values is done using an ICE-9 "}//&
2135                  \textcolor{stringliteral}{"procedure with vertical ALE remapping ."}, &
2136                  default=.false.)
2137   \textcolor{keywordflow}{if} (usealeremapping) \textcolor{keywordflow}{then}
2138     \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"REMAPPING\_2018\_ANSWERS"}, answers\_2018, &
2139                  \textcolor{stringliteral}{"If true, use the order of arithmetic and expressions that recover the "}//&
2140                  \textcolor{stringliteral}{"answers from the end of 2018.  Otherwise, use updated and more robust "}//&
2141                  \textcolor{stringliteral}{"forms of the same expressions."}, default=default\_2018\_answers)
2142 \textcolor{keywordflow}{  endif}
2143   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"HOR\_REGRID\_2018\_ANSWERS"}, hor\_regrid\_answers\_2018, &
2144                  \textcolor{stringliteral}{"If true, use the order of arithmetic for horizonal regridding that recovers "}//&
2145                  \textcolor{stringliteral}{"the answers from the end of 2018.  Otherwise, use rotationally symmetric "}//&
2146                  \textcolor{stringliteral}{"forms of the same expressions."}, default=default\_2018\_answers)
2147   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"ICE\_SHELF"}, use\_ice\_shelf, default=.false.)
2148   \textcolor{keywordflow}{if} (use\_ice\_shelf) \textcolor{keywordflow}{then}
2149     \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"ICE\_THICKNESS\_FILE"}, ice\_shelf\_file, &
2150                  \textcolor{stringliteral}{"The file from which the ice bathymetry and area are read."}, &
2151                  fail\_if\_missing=.not.just\_read, do\_not\_log=just\_read)
2152     shelf\_file = trim(inputdir)//trim(ice\_shelf\_file)
2153     \textcolor{keywordflow}{if} (.not.just\_read) \textcolor{keyword}{call }log\_param(pf, mdl, \textcolor{stringliteral}{"INPUTDIR/THICKNESS\_FILE"}, shelf\_file)
2154     \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"ICE\_AREA\_VARNAME"}, area\_varname, &
2155                  \textcolor{stringliteral}{"The name of the area variable in ICE\_THICKNESS\_FILE."}, &
2156                  fail\_if\_missing=.not.just\_read, do\_not\_log=just\_read)
2157 \textcolor{keywordflow}{  endif}
2158   \textcolor{keywordflow}{if} (.not.usealeremapping) \textcolor{keywordflow}{then}
2159     \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"ADJUST\_THICKNESS"}, correct\_thickness, &
2160                  \textcolor{stringliteral}{"If true, all mass below the bottom removed if the "}//&
2161                  \textcolor{stringliteral}{"topography is shallower than the thickness input file "}//&
2162                  \textcolor{stringliteral}{"would indicate."}, default=.false., do\_not\_log=just\_read)
2163 
2164     \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"FIT\_TO\_TARGET\_DENSITY\_IC"}, adjust\_temperature, &
2165                  \textcolor{stringliteral}{"If true, all the interior layers are adjusted to "}//&
2166                  \textcolor{stringliteral}{"their target densities using mostly temperature "}//&
2167                  \textcolor{stringliteral}{"This approach can be problematic, particularly in the "}//&
2168                  \textcolor{stringliteral}{"high latitudes."}, default=.true., do\_not\_log=just\_read)
2169     \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"Z\_INIT\_SEPARATE\_MIXED\_LAYER"}, separate\_mixed\_layer, &
2170                  \textcolor{stringliteral}{"If true, distribute the topmost Z\_INIT\_HMIX\_DEPTH of water over NKML layers, "}//&
2171                  \textcolor{stringliteral}{"and do not correct the density of the topmost NKML+NKBL layers.  Otherwise "}//&
2172                  \textcolor{stringliteral}{"all layers are initialized based on the depths of their target densities."}, &
2173                  default=.false., do\_not\_log=just\_read.or.(gv%nkml==0))
2174     \textcolor{keywordflow}{if} (gv%nkml == 0) separate\_mixed\_layer = .false.
2175     \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"MINIMUM\_DEPTH"}, hmix\_default, default=0.0)
2176     \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"Z\_INIT\_HMIX\_DEPTH"}, hmix\_depth, &
2177                  \textcolor{stringliteral}{"The mixed layer depth in the initial conditions when Z\_INIT\_SEPARATE\_MIXED\_LAYER "}//&
2178                  \textcolor{stringliteral}{"is set to true."}, default=hmix\_default, units=\textcolor{stringliteral}{"m"}, scale=us%m\_to\_Z, &
2179                  do\_not\_log=(just\_read .or. .not.separate\_mixed\_layer))
2180     \textcolor{comment}{! Reusing MINIMUM\_DEPTH for the default mixed layer depth may be a strange choice, but}
2181     \textcolor{comment}{! it reproduces previous answers.}
2182 \textcolor{keywordflow}{  endif}
2183   \textcolor{keywordflow}{if} (just\_read) \textcolor{keywordflow}{then}
2184     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_routine)
2185     \textcolor{keywordflow}{return} \textcolor{comment}{! All run-time parameters have been read, so return.}
2186 \textcolor{keywordflow}{  endif}
2187 
2188   eps\_z = gv%Angstrom\_Z
2189   eps\_rho = 1.0e-10*us%kg\_m3\_to\_R
2190 
2191   \textcolor{comment}{! Read input grid coordinates for temperature and salinity field}
2192   \textcolor{comment}{! in z-coordinate dataset. The file is REQUIRED to contain the}
2193   \textcolor{comment}{! following:}
2194   \textcolor{comment}{!}
2195   \textcolor{comment}{! dimension variables:}
2196   \textcolor{comment}{!          lon (degrees\_E), lat (degrees\_N), depth(meters)}
2197   \textcolor{comment}{! variables:}
2198   \textcolor{comment}{!          ptemp(lon,lat,depth) : degC, potential temperature}
2199   \textcolor{comment}{!          salt (lon,lat,depth) : ppt, salinity}
2200   \textcolor{comment}{!}
2201   \textcolor{comment}{! The first record will be read if there are multiple time levels.}
2202   \textcolor{comment}{! The observation grid MUST tile the model grid. If the model grid extends}
2203   \textcolor{comment}{! to the North/South Pole past the limits of the input data, they are extrapolated using the average}
2204   \textcolor{comment}{! value at the northernmost/southernmost latitude.}
2205 
2206   \textcolor{keyword}{call }horiz\_interp\_and\_extrap\_tracer(tfilename, potemp\_var, 1.0, 1, &
2207        g, temp\_z, mask\_z, z\_in, z\_edges\_in, missing\_value\_temp, reentrant\_x, &
2208        tripolar\_n, homogenize, m\_to\_z=us%m\_to\_Z, answers\_2018=hor\_regrid\_answers\_2018, ongrid=pre\_gridded)
2209 
2210   \textcolor{keyword}{call }horiz\_interp\_and\_extrap\_tracer(sfilename, salin\_var, 1.0, 1, &
2211        g, salt\_z, mask\_z, z\_in, z\_edges\_in, missing\_value\_salt, reentrant\_x, &
2212        tripolar\_n, homogenize, m\_to\_z=us%m\_to\_Z, answers\_2018=hor\_regrid\_answers\_2018, ongrid=pre\_gridded)
2213 
2214   kd = \textcolor{keyword}{size}(z\_in,1)
2215 
2216   \textcolor{comment}{! Convert the sign convention of Z\_edges\_in.}
2217   \textcolor{keywordflow}{do} k=1,\textcolor{keyword}{size}(z\_edges\_in,1) ; z\_edges\_in(k) = -z\_edges\_in(k) ;\textcolor{keywordflow}{ enddo}
2218 
2219   \textcolor{keyword}{allocate}(rho\_z(isd:ied,jsd:jed,kd))
2220   \textcolor{keyword}{allocate}(area\_shelf\_h(isd:ied,jsd:jed))
2221   \textcolor{keyword}{allocate}(frac\_shelf\_h(isd:ied,jsd:jed))
2222 
2223   \textcolor{comment}{! Convert T&S to Absolute Salinity and Conservative Temperature if using TEOS10 or NEMO}
2224   \textcolor{keyword}{call }convert\_temp\_salt\_for\_teos10(temp\_z, salt\_z, g%HI, kd, mask\_z, eos)
2225 
2226   press(:) = tv%P\_Ref
2227   eosdom(:) = eos\_domain(g%HI)
2228   \textcolor{keywordflow}{do} k=1,kd ; \textcolor{keywordflow}{do} j=js,je
2229     \textcolor{keyword}{call }calculate\_density(temp\_z(:,j,k), salt\_z(:,j,k), press, rho\_z(:,j,k), eos, eosdom)
2230 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
2231 
2232   \textcolor{keyword}{call }pass\_var(temp\_z,g%Domain)
2233   \textcolor{keyword}{call }pass\_var(salt\_z,g%Domain)
2234   \textcolor{keyword}{call }pass\_var(mask\_z,g%Domain)
2235   \textcolor{keyword}{call }pass\_var(rho\_z,g%Domain)
2236 
2237   \textcolor{comment}{! This is needed for building an ALE grid under ice shelves}
2238   \textcolor{keywordflow}{if} (use\_ice\_shelf) \textcolor{keywordflow}{then}
2239     \textcolor{keywordflow}{if} (.not.file\_exists(shelf\_file, g%Domain)) \textcolor{keyword}{call }mom\_error(fatal, &
2240       \textcolor{stringliteral}{"MOM\_temp\_salt\_initialize\_from\_Z: Unable to open shelf file "}//trim(shelf\_file))
2241 
2242     \textcolor{keyword}{call }mom\_read\_data(shelf\_file, trim(area\_varname), area\_shelf\_h, g%Domain, scale=us%m\_to\_L**2)
2243 
2244     \textcolor{comment}{! Initialize frac\_shelf\_h with zeros (open water everywhere)}
2245     frac\_shelf\_h(:,:) = 0.0
2246     \textcolor{comment}{! Compute fractional ice shelf coverage of h}
2247     \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
2248       \textcolor{keywordflow}{if} (g%areaT(i,j) > 0.0) &
2249         frac\_shelf\_h(i,j) = area\_shelf\_h(i,j) / g%areaT(i,j)
2250 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
2251     \textcolor{comment}{! Pass to the pointer for use as an argument to regridding\_main}
2252     shelf\_area => frac\_shelf\_h
2253 
2254 \textcolor{keywordflow}{  endif}
2255 
2256   \textcolor{comment}{! Done with horizontal interpolation.}
2257   \textcolor{comment}{! Now remap to model coordinates}
2258   \textcolor{keywordflow}{if} (usealeremapping) \textcolor{keywordflow}{then}
2259     \textcolor{keyword}{call }cpu\_clock\_begin(id\_clock\_ale)
2260     nkd = max(gv%ke, kd)
2261 
2262     \textcolor{comment}{! Build the source grid and copy data onto model-shaped arrays with vanished layers}
2263     \textcolor{keyword}{allocate}( tmp\_mask\_in(isd:ied,jsd:jed,nkd) ) ; tmp\_mask\_in(:,:,:) = 0.
2264     \textcolor{keyword}{allocate}( h1(isd:ied,jsd:jed,nkd) ) ; h1(:,:,:) = 0.
2265     \textcolor{keyword}{allocate}( tmpt1din(isd:ied,jsd:jed,nkd) ) ; tmpt1din(:,:,:) = 0.
2266     \textcolor{keyword}{allocate}( tmps1din(isd:ied,jsd:jed,nkd) ) ; tmps1din(:,:,:) = 0.
2267     \textcolor{keywordflow}{do} j = js, je ; \textcolor{keywordflow}{do} i = is, ie
2268       \textcolor{keywordflow}{if} (g%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}
2269         ztopofcell = 0. ; zbottomofcell = 0.
2270         tmp\_mask\_in(i,j,1:kd) = mask\_z(i,j,:)
2271         \textcolor{keywordflow}{do} k = 1, nkd
2272           \textcolor{keywordflow}{if} (tmp\_mask\_in(i,j,k)>0. .and. k<=kd) \textcolor{keywordflow}{then}
2273             zbottomofcell = max( z\_edges\_in(k+1), -g%bathyT(i,j) )
2274             tmpt1din(i,j,k) = temp\_z(i,j,k)
2275             tmps1din(i,j,k) = salt\_z(i,j,k)
2276           \textcolor{keywordflow}{elseif} (k>1) \textcolor{keywordflow}{then}
2277             zbottomofcell = -g%bathyT(i,j)
2278             tmpt1din(i,j,k) = tmpt1din(i,j,k-1)
2279             tmps1din(i,j,k) = tmps1din(i,j,k-1)
2280           \textcolor{keywordflow}{else} \textcolor{comment}{! This next block should only ever be reached over land}
2281             tmpt1din(i,j,k) = -99.9
2282             tmps1din(i,j,k) = -99.9
2283 \textcolor{keywordflow}{          endif}
2284           h1(i,j,k) = gv%Z\_to\_H * (ztopofcell - zbottomofcell)
2285           ztopofcell = zbottomofcell \textcolor{comment}{! Bottom becomes top for next value of k}
2286 \textcolor{keywordflow}{        enddo}
2287         h1(i,j,kd) = h1(i,j,kd) + gv%Z\_to\_H * max(0., ztopofcell + g%bathyT(i,j) )
2288         \textcolor{comment}{! The max here is in case the data data is shallower than model}
2289 \textcolor{keywordflow}{      endif} \textcolor{comment}{! mask2dT}
2290 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
2291     \textcolor{keyword}{deallocate}( tmp\_mask\_in )
2292     \textcolor{keyword}{call }pass\_var(h1, g%Domain)
2293     \textcolor{keyword}{call }pass\_var(tmpt1din, g%Domain)
2294     \textcolor{keyword}{call }pass\_var(tmps1din, g%Domain)
2295 
2296     \textcolor{comment}{! Build the target grid (and set the model thickness to it)}
2297     \textcolor{comment}{! This call can be more general but is hard-coded for z* coordinates...  ????}
2298     \textcolor{keyword}{call }ale\_initregridding( gv, us, g%max\_depth, pf, mdl, regridcs ) \textcolor{comment}{! sets regridCS}
2299 
2300     \textcolor{keywordflow}{if} (.not. remap\_general) \textcolor{keywordflow}{then}
2301       \textcolor{comment}{! This is the old way of initializing to z* coordinates only}
2302       \textcolor{keyword}{allocate}( htarget(nz) )
2303       htarget = getcoordinateresolution( regridcs )
2304       \textcolor{keywordflow}{do} j = js, je ; \textcolor{keywordflow}{do} i = is, ie
2305         h(i,j,:) = 0.
2306         \textcolor{keywordflow}{if} (g%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}
2307           \textcolor{comment}{! Build the target grid combining hTarget and topography}
2308           ztopofcell = 0. ; zbottomofcell = 0.
2309           \textcolor{keywordflow}{do} k = 1, nz
2310             zbottomofcell = max( ztopofcell - htarget(k), -g%bathyT(i,j) )
2311             h(i,j,k) = gv%Z\_to\_H * (ztopofcell - zbottomofcell)
2312             ztopofcell = zbottomofcell \textcolor{comment}{! Bottom becomes top for next value of k}
2313 \textcolor{keywordflow}{          enddo}
2314         \textcolor{keywordflow}{else}
2315           h(i,j,:) = 0.
2316 \textcolor{keywordflow}{        endif} \textcolor{comment}{! mask2dT}
2317 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
2318       \textcolor{keyword}{call }pass\_var(h, g%Domain)
2319       \textcolor{keyword}{deallocate}( htarget )
2320 \textcolor{keywordflow}{    endif}
2321 
2322     \textcolor{comment}{! Now remap from source grid to target grid, first setting reconstruction parameters}
2323     \textcolor{keyword}{call }initialize\_remapping( remapcs, remappingscheme, boundary\_extrapolation=.false., answers\_2018=
      answers\_2018 )
2324     \textcolor{keywordflow}{if} (remap\_general) \textcolor{keywordflow}{then}
2325       \textcolor{keyword}{call }set\_regrid\_params( regridcs, min\_thickness=0. )
2326       tv\_loc = tv
2327       tv\_loc%T => tmpt1din
2328       tv\_loc%S => tmps1din
2329       gv\_loc = gv
2330       gv\_loc%ke = nkd
2331       \textcolor{keyword}{allocate}( dz\_interface(isd:ied,jsd:jed,nkd+1) ) \textcolor{comment}{! Need for argument to regridding\_main() but is not
       used}
2332       \textcolor{keywordflow}{if} (use\_ice\_shelf) \textcolor{keywordflow}{then}
2333         \textcolor{keyword}{call }regridding\_main( remapcs, regridcs, g, gv\_loc, h1, tv\_loc, h, dz\_interface, shelf\_area )
2334       \textcolor{keywordflow}{else}
2335         \textcolor{keyword}{call }regridding\_main( remapcs, regridcs, g, gv\_loc, h1, tv\_loc, h, dz\_interface )
2336 \textcolor{keywordflow}{      endif}
2337       \textcolor{keyword}{deallocate}( dz\_interface )
2338 \textcolor{keywordflow}{    endif}
2339     \textcolor{keyword}{call }ale\_remap\_scalar(remapcs, g, gv, nkd, h1, tmpt1din, h, tv%T, all\_cells=remap\_full\_column, &
2340                           old\_remap=remap\_old\_alg, answers\_2018=answers\_2018 )
2341     \textcolor{keyword}{call }ale\_remap\_scalar(remapcs, g, gv, nkd, h1, tmps1din, h, tv%S, all\_cells=remap\_full\_column, &
2342                           old\_remap=remap\_old\_alg, answers\_2018=answers\_2018 )
2343     \textcolor{keyword}{deallocate}( h1 )
2344     \textcolor{keyword}{deallocate}( tmpt1din )
2345     \textcolor{keyword}{deallocate}( tmps1din )
2346 
2347     \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_ale)
2348 
2349   \textcolor{keywordflow}{else} \textcolor{comment}{! remap to isopycnal layer space}
2350 
2351     \textcolor{comment}{! Next find interface positions using local arrays}
2352     \textcolor{comment}{! nlevs contains the number of valid data points in each column}
2353     nlevs = int(sum(mask\_z,dim=3))
2354 
2355     \textcolor{comment}{! Rb contains the layer interface densities}
2356     \textcolor{keyword}{allocate}(rb(nz+1))
2357     \textcolor{keywordflow}{do} k=2,nz ; rb(k) = 0.5*(gv%Rlay(k-1)+gv%Rlay(k)) ;\textcolor{keywordflow}{ enddo}
2358     rb(1) = 0.0
2359     \textcolor{keywordflow}{if} (nz>1) \textcolor{keywordflow}{then}
2360       rb(nz+1) = 2.0*gv%Rlay(nz) - gv%Rlay(nz-1)
2361     \textcolor{keywordflow}{else}
2362       rb(nz+1) = 2.0 * gv%Rlay(1)
2363 \textcolor{keywordflow}{    endif}
2364 
2365     nkml = 0 ; \textcolor{keywordflow}{if} (separate\_mixed\_layer) nkml = gv%nkml
2366 
2367     \textcolor{keyword}{call }find\_interfaces(rho\_z, z\_in, kd, rb, g%bathyT, zi, g, us, &
2368                          nlevs, nkml, hml=hmix\_depth, eps\_z=eps\_z, eps\_rho=eps\_rho)
2369 
2370     \textcolor{keywordflow}{if} (correct\_thickness) \textcolor{keywordflow}{then}
2371       \textcolor{keyword}{call }adjustetatofitbathymetry(g, gv, us, zi, h)
2372     \textcolor{keywordflow}{else}
2373       \textcolor{keywordflow}{do} k=nz,1,-1 ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
2374         \textcolor{keywordflow}{if} (zi(i,j,k) < (zi(i,j,k+1) + gv%Angstrom\_Z)) \textcolor{keywordflow}{then}
2375           zi(i,j,k) = zi(i,j,k+1) + gv%Angstrom\_Z
2376           h(i,j,k) = gv%Angstrom\_H
2377         \textcolor{keywordflow}{else}
2378           h(i,j,k) = gv%Z\_to\_H * (zi(i,j,k) - zi(i,j,k+1))
2379 \textcolor{keywordflow}{        endif}
2380 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
2381       inconsistent=0
2382       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
2383         \textcolor{keywordflow}{if} (abs(zi(i,j,nz+1) + g%bathyT(i,j)) > 1.0*us%m\_to\_Z) &
2384           inconsistent = inconsistent + 1
2385 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
2386       \textcolor{keyword}{call }sum\_across\_pes(inconsistent)
2387 
2388       \textcolor{keywordflow}{if} ((inconsistent > 0) .and. (is\_root\_pe())) \textcolor{keywordflow}{then}
2389         \textcolor{keyword}{write}(mesg, \textcolor{stringliteral}{'("Thickness initial conditions are inconsistent ",'}// &
2390                     \textcolor{stringliteral}{'"with topography in ",I5," places.")'}) inconsistent
2391         \textcolor{keyword}{call }mom\_error(warning, mesg)
2392 \textcolor{keywordflow}{      endif}
2393 \textcolor{keywordflow}{    endif}
2394 
2395     \textcolor{keyword}{call }tracer\_z\_init\_array(temp\_z, z\_edges\_in, kd, zi, missing\_value, g, nz, nlevs, eps\_z, tv%T)
2396     \textcolor{keyword}{call }tracer\_z\_init\_array(salt\_z, z\_edges\_in, kd, zi, missing\_value, g, nz, nlevs, eps\_z, tv%S)
2397 
2398     \textcolor{keywordflow}{do} k=1,nz
2399       npoints = 0 ; tempavg = 0. ; saltavg = 0.
2400       \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{if} (g%mask2dT(i,j) >= 1.0) \textcolor{keywordflow}{then}
2401         npoints = npoints + 1
2402         tempavg = tempavg + tv%T(i,j,k)
2403         saltavg = saltavg + tv%S(i,j,k)
2404 \textcolor{keywordflow}{      endif} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
2405 
2406       \textcolor{comment}{! Horizontally homogenize data to produce perfectly "flat" initial conditions}
2407       \textcolor{keywordflow}{if} (homogenize) \textcolor{keywordflow}{then}
2408         \textcolor{keyword}{call }sum\_across\_pes(npoints)
2409         \textcolor{keyword}{call }sum\_across\_pes(tempavg)
2410         \textcolor{keyword}{call }sum\_across\_pes(saltavg)
2411         \textcolor{keywordflow}{if} (npoints>0) \textcolor{keywordflow}{then}
2412           tempavg = tempavg / \textcolor{keywordtype}{real}(npoints)
2413           saltavg = saltavg / \textcolor{keywordtype}{real}(npoints)
2414 \textcolor{keywordflow}{        endif}
2415         tv%T(:,:,k) = tempavg
2416         tv%S(:,:,k) = saltavg
2417 \textcolor{keywordflow}{      endif}
2418 \textcolor{keywordflow}{    enddo}
2419 
2420 \textcolor{keywordflow}{  endif} \textcolor{comment}{! useALEremapping}
2421 
2422   \textcolor{comment}{! Fill land values}
2423   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
2424     \textcolor{keywordflow}{if} (tv%T(i,j,k) == missing\_value) \textcolor{keywordflow}{then}
2425       tv%T(i,j,k) = temp\_land\_fill
2426       tv%S(i,j,k) = salt\_land\_fill
2427 \textcolor{keywordflow}{    endif}
2428 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
2429 
2430 
2431   \textcolor{keywordflow}{if} (adjust\_temperature .and. .not. usealeremapping) \textcolor{keywordflow}{then}
2432     \textcolor{comment}{! Finally adjust to target density}
2433     ks = 1 ; \textcolor{keywordflow}{if} (separate\_mixed\_layer) ks = gv%nk\_rho\_varies + 1
2434     \textcolor{keyword}{call }determine\_temperature(tv%T, tv%S, gv%Rlay(1:nz), tv%P\_Ref, niter, &
2435                                missing\_value, h, ks, g, us, eos)
2436 \textcolor{keywordflow}{  endif}
2437 
2438   \textcolor{keyword}{deallocate}(z\_in, z\_edges\_in, temp\_z, salt\_z, mask\_z)
2439   \textcolor{keyword}{deallocate}(rho\_z, area\_shelf\_h, frac\_shelf\_h)
2440 
2441   \textcolor{keyword}{call }pass\_var(h, g%Domain)
2442   \textcolor{keyword}{call }pass\_var(tv%T, g%Domain)
2443   \textcolor{keyword}{call }pass\_var(tv%S, g%Domain)
2444 
2445   \textcolor{keyword}{call }calltree\_leave(trim(mdl)//\textcolor{stringliteral}{'()'})
2446   \textcolor{keyword}{call }cpu\_clock\_end(id\_clock\_routine)
2447 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_ace20e4d29e01307fc37911d9ce4df2e3}\label{namespacemom__state__initialization_ace20e4d29e01307fc37911d9ce4df2e3}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!set\+\_\+velocity\+\_\+depth\+\_\+max@{set\+\_\+velocity\+\_\+depth\+\_\+max}}
\index{set\+\_\+velocity\+\_\+depth\+\_\+max@{set\+\_\+velocity\+\_\+depth\+\_\+max}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{set\+\_\+velocity\+\_\+depth\+\_\+max()}{set\_velocity\_depth\_max()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::set\+\_\+velocity\+\_\+depth\+\_\+max (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine sets the 4 bottom depths at velocity points to be the maximum of the adjacent depths. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\end{DoxyParams}


Definition at line 1916 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
1916   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{ !< The ocean's grid structure}
1917   \textcolor{comment}{! Local variables}
1918   \textcolor{keywordtype}{integer} :: i, j
1919 
1920   \textcolor{keywordflow}{do} i=g%isd,g%ied-1 ; \textcolor{keywordflow}{do} j=g%jsd,g%jed
1921     g%Dblock\_u(i,j) = g%mask2dCu(i,j) * max(g%bathyT(i,j), g%bathyT(i+1,j))
1922     g%Dopen\_u(i,j) = g%Dblock\_u(i,j)
1923 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1924   \textcolor{keywordflow}{do} i=g%isd,g%ied ; \textcolor{keywordflow}{do} j=g%jsd,g%jed-1
1925     g%Dblock\_v(i,j) = g%mask2dCv(i,j) * max(g%bathyT(i,j), g%bathyT(i,j+1))
1926     g%Dopen\_v(i,j) = g%Dblock\_v(i,j)
1927 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_a9eda11f130fa39ea833f7b1e4d099c58}\label{namespacemom__state__initialization_a9eda11f130fa39ea833f7b1e4d099c58}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!set\+\_\+velocity\+\_\+depth\+\_\+min@{set\+\_\+velocity\+\_\+depth\+\_\+min}}
\index{set\+\_\+velocity\+\_\+depth\+\_\+min@{set\+\_\+velocity\+\_\+depth\+\_\+min}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{set\+\_\+velocity\+\_\+depth\+\_\+min()}{set\_velocity\_depth\_min()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::set\+\_\+velocity\+\_\+depth\+\_\+min (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine sets the 4 bottom depths at velocity points to be the minimum of the adjacent depths. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\end{DoxyParams}


Definition at line 1953 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
1953   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< The ocean's grid structure}
1954   \textcolor{comment}{! Local variables}
1955   \textcolor{keywordtype}{integer} :: i, j
1956 
1957   \textcolor{keywordflow}{do} i=g%isd,g%ied-1 ; \textcolor{keywordflow}{do} j=g%jsd,g%jed
1958     g%Dblock\_u(i,j) = g%mask2dCu(i,j) * min(g%bathyT(i,j), g%bathyT(i+1,j))
1959     g%Dopen\_u(i,j) = g%Dblock\_u(i,j)
1960 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1961   \textcolor{keywordflow}{do} i=g%isd,g%ied ; \textcolor{keywordflow}{do} j=g%jsd,g%jed-1
1962     g%Dblock\_v(i,j) = g%mask2dCv(i,j) * min(g%bathyT(i,j), g%bathyT(i,j+1))
1963     g%Dopen\_v(i,j) = g%Dblock\_v(i,j)
1964 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__state__initialization_abbe8ee99793eae86251739a8a1bf572f}\label{namespacemom__state__initialization_abbe8ee99793eae86251739a8a1bf572f}} 
\index{mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}!trim\+\_\+for\+\_\+ice@{trim\+\_\+for\+\_\+ice}}
\index{trim\+\_\+for\+\_\+ice@{trim\+\_\+for\+\_\+ice}!mom\+\_\+state\+\_\+initialization@{mom\+\_\+state\+\_\+initialization}}
\subsubsection{\texorpdfstring{trim\+\_\+for\+\_\+ice()}{trim\_for\_ice()}}
{\footnotesize\ttfamily subroutine mom\+\_\+state\+\_\+initialization\+::trim\+\_\+for\+\_\+ice (\begin{DoxyParamCaption}\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{PF,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(ale\+\_\+cs), pointer}]{A\+L\+E\+\_\+\+C\+Sp,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(inout)}]{tv,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(inout)}]{h,  }\item[{logical, intent(in), optional}]{just\+\_\+read\+\_\+params }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Adjust the layer thicknesses by cutting away the top of each model column at the depth where the hydrostatic pressure matches an imposed surface pressure read from file. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em pf} & Parameter file structure\\
\hline
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & Vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em ale\+\_\+csp} & A\+LE control structure\\
\hline
\mbox{\tt in,out}  & {\em tv} & Thermodynamics structure\\
\hline
\mbox{\tt in,out}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em just\+\_\+read\+\_\+params} & If present and true, this call will only read parameters without changing h. \\
\hline
\end{DoxyParams}


Definition at line 1082 of file M\+O\+M\+\_\+state\+\_\+initialization.\+F90.


\begin{DoxyCode}
1082   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: pf\textcolor{comment}{ !< Parameter file structure}
1083   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{  !< Ocean grid structure}
1084   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{ !< Vertical grid structure}
1085   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{ !< A dimensional unit scaling type}
1086   \textcolor{keywordtype}{type}(ale\_cs),            \textcolor{keywordtype}{pointer}       :: ale\_csp\textcolor{comment}{ !< ALE control structure}
1087   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),   \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{ !< Thermodynamics structure}
1088   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, &
1089                            \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{  !< Layer thickness [H ~> m or kg m-2]}
1090   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: just\_read\_params\textcolor{comment}{ !< If present and true, this call will}
1091 \textcolor{comment}{                                                      !! only read parameters without changing h.}
1092   \textcolor{comment}{! Local variables}
1093   \textcolor{keywordtype}{character(len=200)} :: mdl = \textcolor{stringliteral}{"trim\_for\_ice"}
1094   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: p\_surf \textcolor{comment}{! Imposed pressure on ocean at surface [R L2 T-2 ~> Pa]}
1095   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: s\_t, s\_b \textcolor{comment}{! Top and bottom edge values for reconstructions}
1096   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))} :: t\_t, t\_b \textcolor{comment}{! of salinity [ppt] and temperature [degC] within
       each layer.}
1097   \textcolor{keywordtype}{character(len=200)} :: inputdir, filename, p\_surf\_file, p\_surf\_var \textcolor{comment}{! Strings for file/path}
1098   \textcolor{keywordtype}{real} :: scale\_factor   \textcolor{comment}{! A file-dependent scaling factor for the input pressure.}
1099   \textcolor{keywordtype}{real} :: min\_thickness  \textcolor{comment}{! The minimum layer thickness, recast into Z units [Z ~> m].}
1100   \textcolor{keywordtype}{integer} :: i, j, k
1101   \textcolor{keywordtype}{logical} :: default\_2018\_answers, remap\_answers\_2018
1102   \textcolor{keywordtype}{logical} :: just\_read    \textcolor{comment}{! If true, just read parameters but set nothing.}
1103   \textcolor{keywordtype}{logical} :: use\_remapping \textcolor{comment}{! If true, remap the initial conditions.}
1104   \textcolor{keywordtype}{type}(remapping\_cs), \textcolor{keywordtype}{pointer} :: remap\_cs => null()
1105 
1106   just\_read = .false. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(just\_read\_params)) just\_read = just\_read\_params
1107 
1108   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"SURFACE\_PRESSURE\_FILE"}, p\_surf\_file, &
1109                  \textcolor{stringliteral}{"The initial condition file for the surface pressure exerted by ice."}, &
1110                  fail\_if\_missing=.not.just\_read, do\_not\_log=just\_read)
1111   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"SURFACE\_PRESSURE\_VAR"}, p\_surf\_var, &
1112                  \textcolor{stringliteral}{"The initial condition variable for the surface pressure exerted by ice."}, &
1113                  units=\textcolor{stringliteral}{"Pa"}, default=\textcolor{stringliteral}{""}, do\_not\_log=just\_read)
1114   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."}, do\_not\_log=.true.)
1115   filename = trim(slasher(inputdir))//trim(p\_surf\_file)
1116   \textcolor{keywordflow}{if} (.not.just\_read) \textcolor{keyword}{call }log\_param(pf,  mdl, \textcolor{stringliteral}{"!INPUTDIR/SURFACE\_HEIGHT\_IC\_FILE"}, filename)
1117 
1118   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"SURFACE\_PRESSURE\_SCALE"}, scale\_factor, &
1119                  \textcolor{stringliteral}{"A scaling factor to convert SURFACE\_PRESSURE\_VAR from "}//&
1120                  \textcolor{stringliteral}{"file SURFACE\_PRESSURE\_FILE into a surface pressure."}, &
1121                  units=\textcolor{stringliteral}{"file dependent"}, default=1., do\_not\_log=just\_read)
1122   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"MIN\_THICKNESS"}, min\_thickness, \textcolor{stringliteral}{'Minimum layer thickness'}, &
1123                  units=\textcolor{stringliteral}{'m'}, default=1.e-3, do\_not\_log=just\_read, scale=us%m\_to\_Z)
1124   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"TRIMMING\_USES\_REMAPPING"}, use\_remapping, &
1125                  \textcolor{stringliteral}{'When trimming the column, also remap T and S.'}, &
1126                  default=.false., do\_not\_log=just\_read)
1127   remap\_answers\_2018 = .true.
1128   \textcolor{keywordflow}{if} (use\_remapping) \textcolor{keywordflow}{then}
1129     \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"DEFAULT\_2018\_ANSWERS"}, default\_2018\_answers, &
1130                  \textcolor{stringliteral}{"This sets the default value for the various \_2018\_ANSWERS parameters."}, &
1131                  default=.false.)
1132     \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"REMAPPING\_2018\_ANSWERS"}, remap\_answers\_2018, &
1133                  \textcolor{stringliteral}{"If true, use the order of arithmetic and expressions that recover the "}//&
1134                  \textcolor{stringliteral}{"answers from the end of 2018.  Otherwise, use updated and more robust "}//&
1135                  \textcolor{stringliteral}{"forms of the same expressions."}, default=default\_2018\_answers)
1136 \textcolor{keywordflow}{  endif}
1137 
1138   \textcolor{keywordflow}{if} (just\_read) \textcolor{keywordflow}{return} \textcolor{comment}{! All run-time parameters have been read, so return.}
1139 
1140   \textcolor{keyword}{call }mom\_read\_data(filename, p\_surf\_var, p\_surf, g%Domain, &
1141                      scale=scale\_factor*us%kg\_m3\_to\_R*us%m\_s\_to\_L\_T**2)
1142 
1143   \textcolor{keywordflow}{if} (use\_remapping) \textcolor{keywordflow}{then}
1144     \textcolor{keyword}{allocate}(remap\_cs)
1145     \textcolor{keyword}{call }initialize\_remapping(remap\_cs, \textcolor{stringliteral}{'PLM'}, boundary\_extrapolation=.true.)
1146 \textcolor{keywordflow}{  endif}
1147 
1148   \textcolor{comment}{! Find edge values of T and S used in reconstructions}
1149   \textcolor{keywordflow}{if} ( \textcolor{keyword}{associated}(ale\_csp) ) \textcolor{keywordflow}{then} \textcolor{comment}{! This should only be associated if we are in ALE mode}
1150     \textcolor{keyword}{call }ts\_plm\_edge\_values(ale\_csp, s\_t, s\_b, t\_t, t\_b, g, gv, tv, h, .true.)
1151   \textcolor{keywordflow}{else}
1152 \textcolor{comment}{!    call MOM\_error(FATAL, "trim\_for\_ice: Does not work without ALE mode")}
1153     \textcolor{keywordflow}{do} k=1,g%ke ; \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
1154       t\_t(i,j,k) = tv%T(i,j,k) ; t\_b(i,j,k) = tv%T(i,j,k)
1155       s\_t(i,j,k) = tv%S(i,j,k) ; s\_b(i,j,k) = tv%S(i,j,k)
1156 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1157 \textcolor{keywordflow}{  endif}
1158 
1159   \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
1160     \textcolor{keyword}{call }cut\_off\_column\_top(gv%ke, tv, gv, us, gv%g\_Earth, g%bathyT(i,j), &
1161                min\_thickness, tv%T(i,j,:), t\_t(i,j,:), t\_b(i,j,:), &
1162                tv%S(i,j,:), s\_t(i,j,:), s\_b(i,j,:), p\_surf(i,j), h(i,j,:), remap\_cs, &
1163                z\_tol=1.0e-5*us%m\_to\_Z, remap\_answers\_2018=remap\_answers\_2018)
1164 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1165 
\end{DoxyCode}
