\hypertarget{namespacemom__grid__initialize}{}\section{mom\+\_\+grid\+\_\+initialize Module Reference}
\label{namespacemom__grid__initialize}\index{mom\_grid\_initialize@{mom\_grid\_initialize}}


\subsection{Detailed Description}
Initializes horizontal grid. 

The metric terms have the form Dzp, I\+Dzp, or D\+X\+D\+Yp, where z can be X or Y, and p can be q, u, v, or h. z describes the direction of the metric, while p describes the location. I\+Dzp is the inverse of Dzp, while D\+X\+D\+Yp is the product of D\+Xp and D\+Yp except that areaT is calculated analytically from the latitudes and longitudes of the surrounding q points.

On a sphere, a variety of grids can be implemented by defining analytic expressions for dx\+\_\+di, dy\+\_\+dj (where x and y are latitude and longitude, and i and j are grid indices) and the expressions for the integrals of their inverses in the four subroutines dy\+\_\+dj, Int\+\_\+dj\+\_\+dy, dx\+\_\+di, and Int\+\_\+di\+\_\+dx.

initialize\+\_\+masks sets up land masks based on the depth field. The one argument is the minimum ocean depth. Depths that are less than this are interpreted as land points. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__grid__initialize_1_1gps}{gps}}
\begin{DoxyCompactList}\small\item\em Global positioning system (aka container for information to describe the grid) \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__grid__initialize_a80ff9ab4bfca58b9858abc4ce95b06e9}{set\+\_\+grid\+\_\+metrics}} (G, param\+\_\+file, US)
\begin{DoxyCompactList}\small\item\em set\+\_\+grid\+\_\+metrics is used to set the primary values in the model\textquotesingle{}s horizontal grid. The bathymetry, land-\/sea mask and any restricted channel widths are not known yet, so these are set later. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__grid__initialize_acdb2092abe8112d381c54c2aec398c6d}{grid\+\_\+metrics\+\_\+chksum}} (parent, G, US)
\begin{DoxyCompactList}\small\item\em grid\+\_\+metrics\+\_\+chksum performs a set of checksums on metrics on the grid for debugging. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__grid__initialize_a93edcd084a84a50c6aef6053a2cc64f3}{set\+\_\+grid\+\_\+metrics\+\_\+from\+\_\+mosaic}} (G, param\+\_\+file, US)
\begin{DoxyCompactList}\small\item\em Sets the grid metrics from a mosaic file. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__grid__initialize_a0b05a77813a4ca80172f3855e688d19f}{set\+\_\+grid\+\_\+metrics\+\_\+cartesian}} (G, param\+\_\+file, US)
\begin{DoxyCompactList}\small\item\em Calculate the values of the metric terms for a Cartesian grid that might be used and save them in arrays. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__grid__initialize_a7c37b75811701cbca250a34359e44a4a}{set\+\_\+grid\+\_\+metrics\+\_\+spherical}} (G, param\+\_\+file, US)
\begin{DoxyCompactList}\small\item\em Calculate the values of the metric terms that might be used and save them in arrays. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__grid__initialize_a3cc0b92a8624fbd5246576b4e5cf6f6f}{set\+\_\+grid\+\_\+metrics\+\_\+mercator}} (G, param\+\_\+file, US)
\begin{DoxyCompactList}\small\item\em Calculate the values of the metric terms that might be used and save them in arrays. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__grid__initialize_a5a50815c6d1d0948dfbae076da654b94}{ds\+\_\+di}} (x, y, GP)
\begin{DoxyCompactList}\small\item\em This function returns the grid spacing in the logical x direction. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__grid__initialize_aaa3a376606d5067107c3a43beb6f8032}{ds\+\_\+dj}} (x, y, GP)
\begin{DoxyCompactList}\small\item\em This function returns the grid spacing in the logical y direction. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__grid__initialize_aac9e8e21e95ba01e853569e3060ee8d3}{dl}} (x1, x2, y1, y2)
\begin{DoxyCompactList}\small\item\em This function returns the contribution from the line integral along one of the four sides of a cell face to the area of a cell, assuming that the sides follow a linear path in latitude and longitude (i.\+e., on a Mercator grid). \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__grid__initialize_a25cb0001f061ef10b90e637f98ed9fcc}{find\+\_\+root}} (fn, dy\+\_\+df, GP, fnval, y1, ymin, ymax, ittmax)
\begin{DoxyCompactList}\small\item\em This subroutine finds and returns the value of y at which the monotonically increasing function fn takes the value fnval, also returning in ittmax the number of iterations of Newton\textquotesingle{}s method that were used to polish the root. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__grid__initialize_afa76ec84052508b78fde53cd6ed70161}{dx\+\_\+di}} (x, GP)
\begin{DoxyCompactList}\small\item\em This function calculates and returns the value of dx/di, where x is the longitude in Radians, and i is the integral north-\/south grid index. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__grid__initialize_aee53e3cf4937fa86949aa376d5f3d82a}{int\+\_\+di\+\_\+dx}} (x, GP)
\begin{DoxyCompactList}\small\item\em This function calculates and returns the integral of the inverse of dx/di to the point x, in radians. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__grid__initialize_aff493c70cca560bfefcdbfabdf778656}{dy\+\_\+dj}} (y, GP)
\begin{DoxyCompactList}\small\item\em This subroutine calculates and returns the value of dy/dj, where y is the latitude in Radians, and j is the integral north-\/south grid index. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__grid__initialize_a8ed056787130f21f4b9c1bc81bd60c50}{int\+\_\+dj\+\_\+dy}} (y, GP)
\begin{DoxyCompactList}\small\item\em This subroutine calculates and returns the integral of the inverse of dy/dj to the point y, in radians. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__grid__initialize_ac78daa312636b0ef9a93694901b5c705}{extrapolate\+\_\+metric}} (var, jh, missing)
\begin{DoxyCompactList}\small\item\em Extrapolates missing metric data into all the halo regions. \end{DoxyCompactList}\item 
real function, public \mbox{\hyperlink{namespacemom__grid__initialize_ac5445d58b86d259f4c352255849d7fe0}{adcroft\+\_\+reciprocal}} (val)
\begin{DoxyCompactList}\small\item\em This function implements Adcroft\textquotesingle{}s rule for reciprocals, namely that Adcroft\+\_\+\+Inv(x) = 1/x for $\vert$x$\vert$$>$0 or 0 for x=0. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__grid__initialize_a003da6e1301224ac3d211262b03ced3a}{initialize\+\_\+masks}} (G, PF, US)
\begin{DoxyCompactList}\small\item\em Initializes the grid masks and any metrics that come with masks already applied. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__grid__initialize_ac5445d58b86d259f4c352255849d7fe0}\label{namespacemom__grid__initialize_ac5445d58b86d259f4c352255849d7fe0}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!adcroft\_reciprocal@{adcroft\_reciprocal}}
\index{adcroft\_reciprocal@{adcroft\_reciprocal}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{adcroft\_reciprocal()}{adcroft\_reciprocal()}}
{\footnotesize\ttfamily real function, public mom\+\_\+grid\+\_\+initialize\+::adcroft\+\_\+reciprocal (\begin{DoxyParamCaption}\item[{real, intent(in)}]{val }\end{DoxyParamCaption})}



This function implements Adcroft\textquotesingle{}s rule for reciprocals, namely that Adcroft\+\_\+\+Inv(x) = 1/x for $\vert$x$\vert$$>$0 or 0 for x=0. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em val} & The value being inverted. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The Adcroft reciprocal of val. 
\end{DoxyReturn}


Definition at line 1221 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1221 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: val\textcolor{comment}{  !< The value being inverted.}}
\DoxyCodeLine{1222 \textcolor{keywordtype}{  real} :: I\_val\textcolor{comment}{            !< The Adcroft reciprocal of val.}}
\DoxyCodeLine{1223 }
\DoxyCodeLine{1224   i\_val = 0.0}
\DoxyCodeLine{1225   \textcolor{keywordflow}{if} (val /= 0.0) i\_val = 1.0/val}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid__initialize_aac9e8e21e95ba01e853569e3060ee8d3}\label{namespacemom__grid__initialize_aac9e8e21e95ba01e853569e3060ee8d3}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!dl@{dl}}
\index{dl@{dl}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{dl()}{dl()}}
{\footnotesize\ttfamily real function mom\+\_\+grid\+\_\+initialize\+::dl (\begin{DoxyParamCaption}\item[{real, intent(in)}]{x1,  }\item[{real, intent(in)}]{x2,  }\item[{real, intent(in)}]{y1,  }\item[{real, intent(in)}]{y2 }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This function returns the contribution from the line integral along one of the four sides of a cell face to the area of a cell, assuming that the sides follow a linear path in latitude and longitude (i.\+e., on a Mercator grid). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em x1} & Segment starting longitude, in degrees E. \\
\hline
\mbox{\texttt{ in}}  & {\em x2} & Segment ending longitude, in degrees E. \\
\hline
\mbox{\texttt{ in}}  & {\em y1} & Segment ending latitude, in degrees N. \\
\hline
\mbox{\texttt{ in}}  & {\em y2} & Segment ending latitude, in degrees N. \\
\hline
\end{DoxyParams}


Definition at line 958 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{958 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: x1\textcolor{comment}{ !< Segment starting longitude, in degrees E.}}
\DoxyCodeLine{959 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: x2\textcolor{comment}{ !< Segment ending longitude, in degrees E.}}
\DoxyCodeLine{960 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: y1\textcolor{comment}{ !< Segment ending latitude, in degrees N.}}
\DoxyCodeLine{961 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: y2\textcolor{comment}{ !< Segment ending latitude, in degrees N.}}
\DoxyCodeLine{962   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{963 \textcolor{keywordtype}{  real} :: dL}
\DoxyCodeLine{964 \textcolor{keywordtype}{  real} :: r, dy}
\DoxyCodeLine{965 }
\DoxyCodeLine{966   dy = y2 - y1}
\DoxyCodeLine{967 }
\DoxyCodeLine{968   \textcolor{keywordflow}{if} (abs(dy) > 2.5e-8) \textcolor{keywordflow}{then}}
\DoxyCodeLine{969     r = ((1.0 - cos(dy))*cos(y1) + sin(dy)*sin(y1)) / dy}
\DoxyCodeLine{970   \textcolor{keywordflow}{else}}
\DoxyCodeLine{971     r = (0.5*dy*cos(y1) + sin(y1))}
\DoxyCodeLine{972 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{973   dl = r * (x2 - x1)}
\DoxyCodeLine{974 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid__initialize_a5a50815c6d1d0948dfbae076da654b94}\label{namespacemom__grid__initialize_a5a50815c6d1d0948dfbae076da654b94}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!ds\_di@{ds\_di}}
\index{ds\_di@{ds\_di}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{ds\_di()}{ds\_di()}}
{\footnotesize\ttfamily real function mom\+\_\+grid\+\_\+initialize\+::ds\+\_\+di (\begin{DoxyParamCaption}\item[{real, intent(in)}]{x,  }\item[{real, intent(in)}]{y,  }\item[{type(\mbox{\hyperlink{structmom__grid__initialize_1_1gps}{gps}}), intent(in)}]{GP }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This function returns the grid spacing in the logical x direction. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em x} & The longitude in question \\
\hline
\mbox{\texttt{ in}}  & {\em y} & The latitude in question \\
\hline
\mbox{\texttt{ in}}  & {\em gp} & A structure of grid parameters \\
\hline
\end{DoxyParams}


Definition at line 928 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{928 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: x\textcolor{comment}{  !< The longitude in question}}
\DoxyCodeLine{929 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: y\textcolor{comment}{  !< The latitude in question}}
\DoxyCodeLine{930   \textcolor{keywordtype}{type}(GPS), \textcolor{keywordtype}{intent(in)} :: GP\textcolor{comment}{  !< A structure of grid parameters}}
\DoxyCodeLine{931 \textcolor{keywordtype}{  real} :: ds\_di}
\DoxyCodeLine{932   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{933 }
\DoxyCodeLine{934   ds\_di = gp\%Rad\_Earth * cos(y) * dx\_di(x,gp)}
\DoxyCodeLine{935   \textcolor{comment}{! In general, this might be...}}
\DoxyCodeLine{936   \textcolor{comment}{! ds\_di = GP\%Rad\_Earth * sqrt( cos(y)*cos(y) * dx\_di(x,y,GP)*dx\_di(x,y,GP) + \&}}
\DoxyCodeLine{937   \textcolor{comment}{!                           dy\_di(x,y,GP)*dy\_di(x,y,GP))}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid__initialize_aaa3a376606d5067107c3a43beb6f8032}\label{namespacemom__grid__initialize_aaa3a376606d5067107c3a43beb6f8032}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!ds\_dj@{ds\_dj}}
\index{ds\_dj@{ds\_dj}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{ds\_dj()}{ds\_dj()}}
{\footnotesize\ttfamily real function mom\+\_\+grid\+\_\+initialize\+::ds\+\_\+dj (\begin{DoxyParamCaption}\item[{real, intent(in)}]{x,  }\item[{real, intent(in)}]{y,  }\item[{type(\mbox{\hyperlink{structmom__grid__initialize_1_1gps}{gps}}), intent(in)}]{GP }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This function returns the grid spacing in the logical y direction. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em x} & The longitude in question \\
\hline
\mbox{\texttt{ in}}  & {\em y} & The latitude in question \\
\hline
\mbox{\texttt{ in}}  & {\em gp} & A structure of grid parameters \\
\hline
\end{DoxyParams}


Definition at line 942 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{942 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: x\textcolor{comment}{  !< The longitude in question}}
\DoxyCodeLine{943 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: y\textcolor{comment}{  !< The latitude in question}}
\DoxyCodeLine{944   \textcolor{keywordtype}{type}(GPS), \textcolor{keywordtype}{intent(in)} :: GP\textcolor{comment}{  !< A structure of grid parameters}}
\DoxyCodeLine{945   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{946 \textcolor{keywordtype}{  real} :: ds\_dj}
\DoxyCodeLine{947 }
\DoxyCodeLine{948   ds\_dj = gp\%Rad\_Earth * dy\_dj(y,gp)}
\DoxyCodeLine{949   \textcolor{comment}{! In general, this might be...}}
\DoxyCodeLine{950   \textcolor{comment}{! ds\_dj = GP\%Rad\_Earth * sqrt( cos(y)*cos(y) * dx\_dj(x,y,GP)*dx\_dj(x,y,GP) + \&}}
\DoxyCodeLine{951   \textcolor{comment}{!                           dy\_dj(x,y,GP)*dy\_dj(x,y,GP))}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid__initialize_afa76ec84052508b78fde53cd6ed70161}\label{namespacemom__grid__initialize_afa76ec84052508b78fde53cd6ed70161}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!dx\_di@{dx\_di}}
\index{dx\_di@{dx\_di}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{dx\_di()}{dx\_di()}}
{\footnotesize\ttfamily real function mom\+\_\+grid\+\_\+initialize\+::dx\+\_\+di (\begin{DoxyParamCaption}\item[{real, intent(in)}]{x,  }\item[{type(\mbox{\hyperlink{structmom__grid__initialize_1_1gps}{gps}}), intent(in)}]{GP }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This function calculates and returns the value of dx/di, where x is the longitude in Radians, and i is the integral north-\/south grid index. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em x} & The longitude in question \\
\hline
\mbox{\texttt{ in}}  & {\em gp} & A structure of grid parameters \\
\hline
\end{DoxyParams}


Definition at line 1093 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1093 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: x\textcolor{comment}{  !< The longitude in question}}
\DoxyCodeLine{1094   \textcolor{keywordtype}{type}(GPS), \textcolor{keywordtype}{intent(in)} :: GP\textcolor{comment}{  !< A structure of grid parameters}}
\DoxyCodeLine{1095 \textcolor{keywordtype}{  real} :: dx\_di}
\DoxyCodeLine{1096 }
\DoxyCodeLine{1097   dx\_di = (gp\%len\_lon * 4.0*atan(1.0)) / (180.0 * gp\%niglobal)}
\DoxyCodeLine{1098 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid__initialize_aff493c70cca560bfefcdbfabdf778656}\label{namespacemom__grid__initialize_aff493c70cca560bfefcdbfabdf778656}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!dy\_dj@{dy\_dj}}
\index{dy\_dj@{dy\_dj}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{dy\_dj()}{dy\_dj()}}
{\footnotesize\ttfamily real function mom\+\_\+grid\+\_\+initialize\+::dy\+\_\+dj (\begin{DoxyParamCaption}\item[{real, intent(in)}]{y,  }\item[{type(\mbox{\hyperlink{structmom__grid__initialize_1_1gps}{gps}}), intent(in)}]{GP }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine calculates and returns the value of dy/dj, where y is the latitude in Radians, and j is the integral north-\/south grid index. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em y} & The latitude in question \\
\hline
\mbox{\texttt{ in}}  & {\em gp} & A structure of grid parameters \\
\hline
\end{DoxyParams}


Definition at line 1115 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1115 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: y\textcolor{comment}{  !< The latitude in question}}
\DoxyCodeLine{1116   \textcolor{keywordtype}{type}(GPS), \textcolor{keywordtype}{intent(in)} :: GP\textcolor{comment}{  !< A structure of grid parameters}}
\DoxyCodeLine{1117 \textcolor{keywordtype}{  real} :: dy\_dj}
\DoxyCodeLine{1118   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1119 \textcolor{keywordtype}{  real} :: PI            \textcolor{comment}{! 3.1415926... calculated as 4*atan(1)}}
\DoxyCodeLine{1120 \textcolor{keywordtype}{  real} :: C0            \textcolor{comment}{! The constant that converts the nominal y-spacing in}}
\DoxyCodeLine{1121                         \textcolor{comment}{! gridpoints to the nominal spacing in Radians.}}
\DoxyCodeLine{1122 \textcolor{keywordtype}{  real} :: y\_eq\_enhance  \textcolor{comment}{! The latitude in radians within which the resolution}}
\DoxyCodeLine{1123                         \textcolor{comment}{! is enhanced.}}
\DoxyCodeLine{1124   pi = 4.0*atan(1.0)}
\DoxyCodeLine{1125   \textcolor{keywordflow}{if} (gp\%isotropic) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1126     c0 = (gp\%len\_lon * pi) / (180.0 * gp\%niglobal)}
\DoxyCodeLine{1127     y\_eq\_enhance = pi*abs(gp\%lat\_eq\_enhance)/180.0}
\DoxyCodeLine{1128     \textcolor{keywordflow}{if} (abs(y) < y\_eq\_enhance) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1129       dy\_dj = c0 * (cos(y) / (1.0 + 0.5*cos(y) * (gp\%lat\_enhance\_factor - 1.0) * \&}
\DoxyCodeLine{1130                          (1.0+cos(pi*y/y\_eq\_enhance)) ))}
\DoxyCodeLine{1131     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1132       dy\_dj = c0 * cos(y)}
\DoxyCodeLine{1133 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1134   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1135     c0 = (gp\%len\_lat * pi) / (180.0 * gp\%njglobal)}
\DoxyCodeLine{1136     dy\_dj = c0}
\DoxyCodeLine{1137 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1138 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid__initialize_ac78daa312636b0ef9a93694901b5c705}\label{namespacemom__grid__initialize_ac78daa312636b0ef9a93694901b5c705}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!extrapolate\_metric@{extrapolate\_metric}}
\index{extrapolate\_metric@{extrapolate\_metric}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{extrapolate\_metric()}{extrapolate\_metric()}}
{\footnotesize\ttfamily subroutine mom\+\_\+grid\+\_\+initialize\+::extrapolate\+\_\+metric (\begin{DoxyParamCaption}\item[{real, dimension(\+:,\+:), intent(inout)}]{var,  }\item[{integer, intent(in)}]{jh,  }\item[{real, intent(in), optional}]{missing }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Extrapolates missing metric data into all the halo regions. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em var} & The array in which to fill in halos \\
\hline
\mbox{\texttt{ in}}  & {\em jh} & The size of the halos to be filled \\
\hline
\mbox{\texttt{ in}}  & {\em missing} & The missing data fill value, 0 by default. \\
\hline
\end{DoxyParams}


Definition at line 1187 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1187 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: var\textcolor{comment}{     !< The array in which to fill in halos}}
\DoxyCodeLine{1188   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}    :: jh\textcolor{comment}{      !< The size of the halos to be filled}}
\DoxyCodeLine{1189 \textcolor{keywordtype}{  real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: missing\textcolor{comment}{ !< The missing data fill value, 0 by default.}}
\DoxyCodeLine{1190   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1191 \textcolor{keywordtype}{  real} :: badval}
\DoxyCodeLine{1192   \textcolor{keywordtype}{integer} :: i,j}
\DoxyCodeLine{1193 }
\DoxyCodeLine{1194   badval = 0.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(missing)) badval = missing}
\DoxyCodeLine{1195 }
\DoxyCodeLine{1196   \textcolor{comment}{! Fill in southern halo by extrapolating from the computational domain}}
\DoxyCodeLine{1197   \textcolor{keywordflow}{do} j=lbound(var,2)+jh,lbound(var,2),-1 ; \textcolor{keywordflow}{do} i=lbound(var,1),ubound(var,1)}
\DoxyCodeLine{1198     \textcolor{keywordflow}{if} (var(i,j)==badval) var(i,j) = 2.0*var(i,j+1)-var(i,j+2)}
\DoxyCodeLine{1199 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1200 }
\DoxyCodeLine{1201   \textcolor{comment}{! Fill in northern halo by extrapolating from the computational domain}}
\DoxyCodeLine{1202   \textcolor{keywordflow}{do} j=ubound(var,2)-jh,ubound(var,2) ; \textcolor{keywordflow}{do} i=lbound(var,1),ubound(var,1)}
\DoxyCodeLine{1203     \textcolor{keywordflow}{if} (var(i,j)==badval) var(i,j) = 2.0*var(i,j-1)-var(i,j-2)}
\DoxyCodeLine{1204 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1205 }
\DoxyCodeLine{1206   \textcolor{comment}{! Fill in western halo by extrapolating from the computational domain}}
\DoxyCodeLine{1207   \textcolor{keywordflow}{do} j=lbound(var,2),ubound(var,2) ; \textcolor{keywordflow}{do} i=lbound(var,1)+jh,lbound(var,1),-1}
\DoxyCodeLine{1208     \textcolor{keywordflow}{if} (var(i,j)==badval) var(i,j) = 2.0*var(i+1,j)-var(i+2,j)}
\DoxyCodeLine{1209 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1210 }
\DoxyCodeLine{1211   \textcolor{comment}{! Fill in eastern halo by extrapolating from the computational domain}}
\DoxyCodeLine{1212   \textcolor{keywordflow}{do} j=lbound(var,2),ubound(var,2) ; \textcolor{keywordflow}{do} i=ubound(var,1)-jh,ubound(var,1)}
\DoxyCodeLine{1213     \textcolor{keywordflow}{if} (var(i,j)==badval) var(i,j) = 2.0*var(i-1,j)-var(i-2,j)}
\DoxyCodeLine{1214 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1215 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid__initialize_a25cb0001f061ef10b90e637f98ed9fcc}\label{namespacemom__grid__initialize_a25cb0001f061ef10b90e637f98ed9fcc}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!find\_root@{find\_root}}
\index{find\_root@{find\_root}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{find\_root()}{find\_root()}}
{\footnotesize\ttfamily real function mom\+\_\+grid\+\_\+initialize\+::find\+\_\+root (\begin{DoxyParamCaption}\item[{real, external}]{fn,  }\item[{real, external}]{dy\+\_\+df,  }\item[{type(\mbox{\hyperlink{structmom__grid__initialize_1_1gps}{gps}}), intent(in)}]{GP,  }\item[{real, intent(in)}]{fnval,  }\item[{real, intent(in)}]{y1,  }\item[{real, intent(in)}]{ymin,  }\item[{real, intent(in)}]{ymax,  }\item[{integer, intent(out)}]{ittmax }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine finds and returns the value of y at which the monotonically increasing function fn takes the value fnval, also returning in ittmax the number of iterations of Newton\textquotesingle{}s method that were used to polish the root. 

\begin{DoxyReturn}{Returns}
The value of y where fn(y) = fnval that will be returned 
\end{DoxyReturn}

\begin{DoxyParams}[1]{Parameters}
 & {\em fn} & The external function whose root is being sought \\
\hline
 & {\em dy\+\_\+df} & The inverse of the derivative of that function \\
\hline
\mbox{\texttt{ in}}  & {\em gp} & A structure of grid parameters \\
\hline
\mbox{\texttt{ in}}  & {\em fnval} & The value of fn being sought \\
\hline
\mbox{\texttt{ in}}  & {\em y1} & A first guess for y \\
\hline
\mbox{\texttt{ in}}  & {\em ymin} & The minimum permitted value of y \\
\hline
\mbox{\texttt{ in}}  & {\em ymax} & The maximum permitted value of y \\
\hline
\mbox{\texttt{ out}}  & {\em ittmax} & The number of iterations used to polish the root \\
\hline
\end{DoxyParams}


Definition at line 981 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{981 \textcolor{keywordtype}{  real} :: find\_root\textcolor{comment}{ !< The value of y where fn(y) = fnval that will be returned}}
\DoxyCodeLine{982 \textcolor{keywordtype}{  real},      \textcolor{keywordtype}{external}    :: fn\textcolor{comment}{    !< The external function whose root is being sought}}
\DoxyCodeLine{983 \textcolor{keywordtype}{  real},      \textcolor{keywordtype}{external}    :: dy\_df\textcolor{comment}{ !< The inverse of the derivative of that function}}
\DoxyCodeLine{984   \textcolor{keywordtype}{type}(GPS), \textcolor{keywordtype}{intent(in)}  :: GP\textcolor{comment}{  !< A structure of grid parameters}}
\DoxyCodeLine{985 \textcolor{keywordtype}{  real},      \textcolor{keywordtype}{intent(in)}  :: fnval\textcolor{comment}{ !< The value of fn being sought}}
\DoxyCodeLine{986 \textcolor{keywordtype}{  real},      \textcolor{keywordtype}{intent(in)}  :: y1\textcolor{comment}{    !< A first guess for y}}
\DoxyCodeLine{987 \textcolor{keywordtype}{  real},      \textcolor{keywordtype}{intent(in)}  :: ymin\textcolor{comment}{  !< The minimum permitted value of y}}
\DoxyCodeLine{988 \textcolor{keywordtype}{  real},      \textcolor{keywordtype}{intent(in)}  :: ymax\textcolor{comment}{  !< The maximum permitted value of y}}
\DoxyCodeLine{989   \textcolor{keywordtype}{integer},   \textcolor{keywordtype}{intent(out)} :: ittmax\textcolor{comment}{ !< The number of iterations used to polish the root}}
\DoxyCodeLine{990   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{991 \textcolor{keywordtype}{  real} :: y, y\_next}
\DoxyCodeLine{992 \textcolor{keywordtype}{  real} :: ybot, ytop, fnbot, fntop}
\DoxyCodeLine{993   \textcolor{keywordtype}{integer} :: itt}
\DoxyCodeLine{994   \textcolor{keywordtype}{character(len=256)} :: warnmesg}
\DoxyCodeLine{995 }
\DoxyCodeLine{996 \textcolor{keywordtype}{  real} :: dy\_dfn, dy, fny}
\DoxyCodeLine{997 }
\DoxyCodeLine{998 \textcolor{comment}{!  Bracket the root.  Do not use the bounding values because the value at the}}
\DoxyCodeLine{999 \textcolor{comment}{! function at the bounds could be infinite, as is the case for the Mercator}}
\DoxyCodeLine{1000 \textcolor{comment}{! grid recursion relation. (I.e., this is a search on an open interval.)}}
\DoxyCodeLine{1001   ybot = y1}
\DoxyCodeLine{1002   fnbot = fn(ybot,gp) - fnval ; itt = 0}
\DoxyCodeLine{1003   \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (fnbot > 0.0)}
\DoxyCodeLine{1004     \textcolor{keywordflow}{if} ((ybot - 2.0*dy\_df(ybot,gp)) < (0.5*(ybot+ymin))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1005       \textcolor{comment}{! Go twice as far as the secant method would normally go.}}
\DoxyCodeLine{1006       ybot = ybot - 2.0*dy\_df(ybot,gp)}
\DoxyCodeLine{1007     \textcolor{keywordflow}{else}  \textcolor{comment}{! But stay within the open interval!}}
\DoxyCodeLine{1008       ybot = 0.5*(ybot+ymin) ; itt = itt + 1}
\DoxyCodeLine{1009 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1010     fnbot = fn(ybot,gp) - fnval}
\DoxyCodeLine{1011 }
\DoxyCodeLine{1012     \textcolor{keywordflow}{if} ((itt > 50) .and. (fnbot > 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1013       \textcolor{keyword}{write}(warnmesg, \textcolor{stringliteral}{'("PE ",I2," unable to find bottom bound for grid function. \&}}
\DoxyCodeLine{1014 \textcolor{stringliteral}{}\textcolor{stringliteral}{        \&x = ",ES10.4,", xmax = ",ES10.4,", fn = ",ES10.4,", dfn\_dx = ",ES10.4,\&}}
\DoxyCodeLine{1015 \textcolor{stringliteral}{}\textcolor{stringliteral}{        \&", seeking fn = ",ES10.4," - fn = ",ES10.4,".")'}) \&}
\DoxyCodeLine{1016           pe\_here(),ybot,ymin,fn(ybot,gp),dy\_df(ybot,gp),fnval, fnbot}
\DoxyCodeLine{1017       \textcolor{keyword}{call }mom\_error(fatal,warnmesg)}
\DoxyCodeLine{1018 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1019 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1020 }
\DoxyCodeLine{1021   ytop = y1}
\DoxyCodeLine{1022   fntop = fn(ytop,gp) - fnval ; itt = 0}
\DoxyCodeLine{1023   \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (fntop < 0.0)}
\DoxyCodeLine{1024     \textcolor{keywordflow}{if} ((ytop + 2.0*dy\_df(ytop,gp)) < (0.5*(ytop+ymax))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1025       \textcolor{comment}{! Go twice as far as the secant method would normally go.}}
\DoxyCodeLine{1026       ytop = ytop + 2.0*dy\_df(ytop,gp)}
\DoxyCodeLine{1027     \textcolor{keywordflow}{else} \textcolor{comment}{! But stay within the open interval!}}
\DoxyCodeLine{1028       ytop = 0.5*(ytop+ymax) ; itt = itt + 1}
\DoxyCodeLine{1029 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1030     fntop = fn(ytop,gp) - fnval}
\DoxyCodeLine{1031 }
\DoxyCodeLine{1032     \textcolor{keywordflow}{if} ((itt > 50) .and. (fntop < 0.0)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1033       \textcolor{keyword}{write}(warnmesg, \textcolor{stringliteral}{'("PE ",I2," unable to find top bound for grid function. \&}}
\DoxyCodeLine{1034 \textcolor{stringliteral}{}\textcolor{stringliteral}{        \&x = ",ES10.4,", xmax = ",ES10.4,", fn = ",ES10.4,", dfn\_dx = ",ES10.4, \&}}
\DoxyCodeLine{1035 \textcolor{stringliteral}{}\textcolor{stringliteral}{        \&", seeking fn = ",ES10.4," - fn = ",ES10.4,".")'}) \&}
\DoxyCodeLine{1036           pe\_here(),ytop,ymax,fn(ytop,gp),dy\_df(ytop,gp),fnval,fntop}
\DoxyCodeLine{1037       \textcolor{keyword}{call }mom\_error(fatal,warnmesg)}
\DoxyCodeLine{1038 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1039 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1040 }
\DoxyCodeLine{1041   \textcolor{comment}{! Find the root using a bracketed variant of Newton's method, starting}}
\DoxyCodeLine{1042   \textcolor{comment}{! with a false-positon method first guess.}}
\DoxyCodeLine{1043   \textcolor{keywordflow}{if} ((fntop < 0.0) .or. (fnbot > 0.0) .or. (ytop < ybot)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1044     \textcolor{keyword}{write}(warnmesg, \textcolor{stringliteral}{'("PE ",I2," find\_root failed to bracket function. y = ",\&}}
\DoxyCodeLine{1045 \textcolor{stringliteral}{}\textcolor{stringliteral}{              \&2ES10.4,", fn = ",2ES10.4,".")'}) pe\_here(),ybot,ytop,fnbot,fntop}
\DoxyCodeLine{1046     \textcolor{keyword}{call }mom\_error(fatal, warnmesg)}
\DoxyCodeLine{1047 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1048 }
\DoxyCodeLine{1049   \textcolor{keywordflow}{if} (fntop == 0.0) \textcolor{keywordflow}{then} ; y = ytop ; fny = fntop}
\DoxyCodeLine{1050   \textcolor{keywordflow}{elseif} (fnbot == 0.0) \textcolor{keywordflow}{then} ; y = ybot ; fny = fnbot}
\DoxyCodeLine{1051   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1052     y = (ybot*fntop - ytop*fnbot) / (fntop - fnbot)}
\DoxyCodeLine{1053     fny = fn(y,gp) - fnval}
\DoxyCodeLine{1054     \textcolor{keywordflow}{if} (fny < 0.0) \textcolor{keywordflow}{then} ; fnbot = fny ; ybot = y}
\DoxyCodeLine{1055     \textcolor{keywordflow}{else} ; fntop = fny ; ytop = y ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1056 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1057 }
\DoxyCodeLine{1058   \textcolor{keywordflow}{do} itt=1,50}
\DoxyCodeLine{1059     dy\_dfn = dy\_df(y,gp)}
\DoxyCodeLine{1060 }
\DoxyCodeLine{1061     dy = -1.0* fny * dy\_dfn}
\DoxyCodeLine{1062     y\_next = y + dy}
\DoxyCodeLine{1063     \textcolor{keywordflow}{if} ((y\_next >= ytop) .or. (y\_next <= ybot)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1064       \textcolor{comment}{! The Newton's method estimate has escaped bracketing, so use the}}
\DoxyCodeLine{1065       \textcolor{comment}{! false-position method instead.  The complicated test is to properly}}
\DoxyCodeLine{1066       \textcolor{comment}{! handle the case where the iteration is down to roundoff level differences.}}
\DoxyCodeLine{1067       y\_next = y}
\DoxyCodeLine{1068       \textcolor{keywordflow}{if} (abs(fntop - fnbot) > epsilon(y) * (abs(fntop) + abs(fnbot))) \&}
\DoxyCodeLine{1069         y\_next = (ybot*fntop - ytop*fnbot) / (fntop - fnbot)}
\DoxyCodeLine{1070 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1071 }
\DoxyCodeLine{1072     dy = y\_next - y}
\DoxyCodeLine{1073     \textcolor{keywordflow}{if} (abs(dy) < (2.0*epsilon(y)*(abs(y) + abs(y\_next)) + 1.0e-20)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1074       y = y\_next ; \textcolor{keywordflow}{exit}}
\DoxyCodeLine{1075 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1076     y = y\_next}
\DoxyCodeLine{1077 }
\DoxyCodeLine{1078     fny = fn(y,gp) - fnval}
\DoxyCodeLine{1079     \textcolor{keywordflow}{if} (fny > 0.0) \textcolor{keywordflow}{then} ; ytop = y ; fntop = fny}
\DoxyCodeLine{1080     \textcolor{keywordflow}{elseif} (fny < 0.0) \textcolor{keywordflow}{then} ; ybot = y ; fnbot = fny}
\DoxyCodeLine{1081     \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{exit} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{1082 }
\DoxyCodeLine{1083 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{1084   \textcolor{keywordflow}{if} (abs(y) < 1e-12) y = 0.0}
\DoxyCodeLine{1085 }
\DoxyCodeLine{1086   ittmax = itt}
\DoxyCodeLine{1087   find\_root = y}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid__initialize_acdb2092abe8112d381c54c2aec398c6d}\label{namespacemom__grid__initialize_acdb2092abe8112d381c54c2aec398c6d}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!grid\_metrics\_chksum@{grid\_metrics\_chksum}}
\index{grid\_metrics\_chksum@{grid\_metrics\_chksum}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{grid\_metrics\_chksum()}{grid\_metrics\_chksum()}}
{\footnotesize\ttfamily subroutine mom\+\_\+grid\+\_\+initialize\+::grid\+\_\+metrics\+\_\+chksum (\begin{DoxyParamCaption}\item[{character(len=$\ast$), intent(in)}]{parent,  }\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in), optional}]{US }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



grid\+\_\+metrics\+\_\+chksum performs a set of checksums on metrics on the grid for debugging. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em parent} & A string identifying the caller \\
\hline
\mbox{\texttt{ in}}  & {\em g} & The dynamic horizontal grid type \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\end{DoxyParams}


Definition at line 116 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{116   \textcolor{keywordtype}{character(len=*)},       \textcolor{keywordtype}{intent(in)} :: parent\textcolor{comment}{ !< A string identifying the caller}}
\DoxyCodeLine{117   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{      !< The dynamic horizontal grid type}}
\DoxyCodeLine{118   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{119 }
\DoxyCodeLine{120 \textcolor{keywordtype}{  real} :: m\_to\_L  \textcolor{comment}{! A unit conversion factor [L m-1 ~> nondim]}}
\DoxyCodeLine{121 \textcolor{keywordtype}{  real} :: L\_to\_m  \textcolor{comment}{! A unit conversion factor [m L-1 ~> nondim]}}
\DoxyCodeLine{122   \textcolor{keywordtype}{integer} :: halo}
\DoxyCodeLine{123   m\_to\_l = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) m\_to\_l = us\%m\_to\_L}
\DoxyCodeLine{124   l\_to\_m = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) l\_to\_m = us\%L\_to\_m}
\DoxyCodeLine{125 }
\DoxyCodeLine{126   halo = min(g\%ied-g\%iec, g\%jed-g\%jec, 1)}
\DoxyCodeLine{127 }
\DoxyCodeLine{128   \textcolor{keyword}{call }hchksum\_pair(trim(parent)//\textcolor{stringliteral}{': d[xy]T'}, g\%dxT, g\%dyT, g\%HI, \&}
\DoxyCodeLine{129                     haloshift=halo, scale=l\_to\_m, scalar\_pair=.true.)}
\DoxyCodeLine{130 }
\DoxyCodeLine{131   \textcolor{keyword}{call }uvchksum(trim(parent)//\textcolor{stringliteral}{': dxC[uv]'}, g\%dxCu, g\%dyCv, g\%HI, haloshift=halo, scale=l\_to\_m)}
\DoxyCodeLine{132 }
\DoxyCodeLine{133   \textcolor{keyword}{call }uvchksum(trim(parent)//\textcolor{stringliteral}{': dxC[uv]'}, g\%dyCu, g\%dxCv, g\%HI, haloshift=halo, scale=l\_to\_m)}
\DoxyCodeLine{134 }
\DoxyCodeLine{135   \textcolor{keyword}{call }bchksum\_pair(trim(parent)//\textcolor{stringliteral}{': dxB[uv]'}, g\%dxBu, g\%dyBu, g\%HI, haloshift=halo, scale=l\_to\_m)}
\DoxyCodeLine{136 }
\DoxyCodeLine{137   \textcolor{keyword}{call }hchksum\_pair(trim(parent)//\textcolor{stringliteral}{': Id[xy]T'}, g\%IdxT, g\%IdyT, g\%HI, \&}
\DoxyCodeLine{138                     haloshift=halo, scale=m\_to\_l, scalar\_pair=.true.)}
\DoxyCodeLine{139 }
\DoxyCodeLine{140   \textcolor{keyword}{call }uvchksum(trim(parent)//\textcolor{stringliteral}{': Id[xy]C[uv]'}, g\%IdxCu, g\%IdyCv, g\%HI, haloshift=halo, scale=m\_to\_l)}
\DoxyCodeLine{141 }
\DoxyCodeLine{142   \textcolor{keyword}{call }uvchksum(trim(parent)//\textcolor{stringliteral}{': Id[xy]C[uv]'}, g\%IdyCu, g\%IdxCv, g\%HI, haloshift=halo, scale=m\_to\_l)}
\DoxyCodeLine{143 }
\DoxyCodeLine{144   \textcolor{keyword}{call }bchksum\_pair(trim(parent)//\textcolor{stringliteral}{': Id[xy]B[uv]'}, g\%IdxBu, g\%IdyBu, g\%HI, haloshift=halo, scale=m\_to\_l)}
\DoxyCodeLine{145 }
\DoxyCodeLine{146   \textcolor{keyword}{call }hchksum(g\%areaT, trim(parent)//\textcolor{stringliteral}{': areaT'},g\%HI, haloshift=halo, scale=l\_to\_m**2)}
\DoxyCodeLine{147   \textcolor{keyword}{call }bchksum(g\%areaBu, trim(parent)//\textcolor{stringliteral}{': areaBu'},g\%HI, haloshift=halo, scale=l\_to\_m**2)}
\DoxyCodeLine{148 }
\DoxyCodeLine{149   \textcolor{keyword}{call }hchksum(g\%IareaT, trim(parent)//\textcolor{stringliteral}{': IareaT'},g\%HI, haloshift=halo, scale=m\_to\_l**2)}
\DoxyCodeLine{150   \textcolor{keyword}{call }bchksum(g\%IareaBu, trim(parent)//\textcolor{stringliteral}{': IareaBu'},g\%HI, haloshift=halo, scale=m\_to\_l**2)}
\DoxyCodeLine{151 }
\DoxyCodeLine{152   \textcolor{keyword}{call }hchksum(g\%geoLonT,trim(parent)//\textcolor{stringliteral}{': geoLonT'},g\%HI, haloshift=halo)}
\DoxyCodeLine{153   \textcolor{keyword}{call }hchksum(g\%geoLatT,trim(parent)//\textcolor{stringliteral}{': geoLatT'},g\%HI, haloshift=halo)}
\DoxyCodeLine{154 }
\DoxyCodeLine{155   \textcolor{keyword}{call }bchksum(g\%geoLonBu, trim(parent)//\textcolor{stringliteral}{': geoLonBu'},g\%HI, haloshift=halo)}
\DoxyCodeLine{156   \textcolor{keyword}{call }bchksum(g\%geoLatBu, trim(parent)//\textcolor{stringliteral}{': geoLatBu'},g\%HI, haloshift=halo)}
\DoxyCodeLine{157 }
\DoxyCodeLine{158   \textcolor{keyword}{call }uvchksum(trim(parent)//\textcolor{stringliteral}{': geoLonC[uv]'}, g\%geoLonCu, g\%geoLonCv, g\%HI, haloshift=halo)}
\DoxyCodeLine{159 }
\DoxyCodeLine{160   \textcolor{keyword}{call }uvchksum(trim(parent)//\textcolor{stringliteral}{': geoLatC[uv]'}, g\%geoLatCu, g\%geoLatCv, g\%HI, haloshift=halo)}
\DoxyCodeLine{161 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid__initialize_a003da6e1301224ac3d211262b03ced3a}\label{namespacemom__grid__initialize_a003da6e1301224ac3d211262b03ced3a}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!initialize\_masks@{initialize\_masks}}
\index{initialize\_masks@{initialize\_masks}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{initialize\_masks()}{initialize\_masks()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+grid\+\_\+initialize\+::initialize\+\_\+masks (\begin{DoxyParamCaption}\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(inout)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{PF,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in), optional}]{US }\end{DoxyParamCaption})}



Initializes the grid masks and any metrics that come with masks already applied. 

Initialize\+\_\+masks sets mask2dT, mask2d\+Cu, mask2d\+Cv, and mask2d\+Bu to mask out flow over any points which are shallower than Dmin and permit an appropriate treatment of the boundary conditions. mask2d\+Cu and mask2d\+Cv are 0.\+0 at any points adjacent to a land point. mask2d\+Bu is 0.\+0 at any land or boundary point. For points in the interior, mask2d\+Cu, mask2d\+Cv, and mask2d\+Bu are all 1.\+0. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The dynamic horizontal grid type \\
\hline
\mbox{\texttt{ in}}  & {\em pf} & Parameter file structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\end{DoxyParams}


Definition at line 1237 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1237   \textcolor{keywordtype}{type}(dyn\_horgrid\_type),          \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{  !< The dynamic horizontal grid type}}
\DoxyCodeLine{1238   \textcolor{keywordtype}{type}(param\_file\_type),           \textcolor{keywordtype}{intent(in)}    :: PF\textcolor{comment}{ !< Parameter file structure}}
\DoxyCodeLine{1239   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{1240   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1241 \textcolor{keywordtype}{  real} :: m\_to\_Z\_scale \textcolor{comment}{! A unit conversion factor from m to Z.}}
\DoxyCodeLine{1242 \textcolor{keywordtype}{  real} :: m\_to\_L  \textcolor{comment}{! A unit conversion factor [L m-1 ~> nondim]}}
\DoxyCodeLine{1243 \textcolor{keywordtype}{  real} :: Dmin       \textcolor{comment}{! The depth for masking in the same units as G\%bathyT [Z ~> m].}}
\DoxyCodeLine{1244 \textcolor{keywordtype}{  real} :: min\_depth  \textcolor{comment}{! The minimum ocean depth in the same units as G\%bathyT [Z ~> m].}}
\DoxyCodeLine{1245 \textcolor{keywordtype}{  real} :: mask\_depth \textcolor{comment}{! The depth shallower than which to mask a point as land [Z ~> m].}}
\DoxyCodeLine{1246   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_grid\_init initialize\_masks"}}
\DoxyCodeLine{1247   \textcolor{keywordtype}{integer} :: i, j}
\DoxyCodeLine{1248 }
\DoxyCodeLine{1249   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"initialize\_masks(), MOM\_grid\_initialize.F90"})}
\DoxyCodeLine{1250   m\_to\_z\_scale = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) m\_to\_z\_scale = us\%m\_to\_Z}
\DoxyCodeLine{1251   m\_to\_l = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) m\_to\_l = us\%m\_to\_L}
\DoxyCodeLine{1252 }
\DoxyCodeLine{1253   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"MINIMUM\_DEPTH"}, min\_depth, \&}
\DoxyCodeLine{1254                  \textcolor{stringliteral}{"If MASKING\_DEPTH is unspecified, then anything shallower than "}//\&}
\DoxyCodeLine{1255                  \textcolor{stringliteral}{"MINIMUM\_DEPTH is assumed to be land and all fluxes are masked out. "}//\&}
\DoxyCodeLine{1256                  \textcolor{stringliteral}{"If MASKING\_DEPTH is specified, then all depths shallower than "}//\&}
\DoxyCodeLine{1257                  \textcolor{stringliteral}{"MINIMUM\_DEPTH but deeper than MASKING\_DEPTH are rounded to MINIMUM\_DEPTH."}, \&}
\DoxyCodeLine{1258                  units=\textcolor{stringliteral}{"m"}, default=0.0, scale=m\_to\_z\_scale)}
\DoxyCodeLine{1259   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"MASKING\_DEPTH"}, mask\_depth, \&}
\DoxyCodeLine{1260                  \textcolor{stringliteral}{"The depth below which to mask points as land points, for which all "}//\&}
\DoxyCodeLine{1261                  \textcolor{stringliteral}{"fluxes are zeroed out. MASKING\_DEPTH is ignored if negative."}, \&}
\DoxyCodeLine{1262                  units=\textcolor{stringliteral}{"m"}, default=-9999.0, scale=m\_to\_z\_scale)}
\DoxyCodeLine{1263 }
\DoxyCodeLine{1264   dmin = min\_depth}
\DoxyCodeLine{1265   \textcolor{keywordflow}{if} (mask\_depth>=0.) dmin = mask\_depth}
\DoxyCodeLine{1266 }
\DoxyCodeLine{1267   g\%mask2dCu(:,:) = 0.0 ; g\%mask2dCv(:,:) = 0.0 ; g\%mask2dBu(:,:) = 0.0}
\DoxyCodeLine{1268 }
\DoxyCodeLine{1269   \textcolor{comment}{! Construct the h-point or T-point mask}}
\DoxyCodeLine{1270   \textcolor{keywordflow}{do} j=g\%jsd,g\%jed ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied}
\DoxyCodeLine{1271     \textcolor{keywordflow}{if} (g\%bathyT(i,j) <= dmin) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1272       g\%mask2dT(i,j) = 0.0}
\DoxyCodeLine{1273     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1274       g\%mask2dT(i,j) = 1.0}
\DoxyCodeLine{1275 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1276 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1277 }
\DoxyCodeLine{1278   \textcolor{keywordflow}{do} j=g\%jsd,g\%jed ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied-1}
\DoxyCodeLine{1279     \textcolor{keywordflow}{if} ((g\%bathyT(i,j) <= dmin) .or. (g\%bathyT(i+1,j) <= dmin)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1280       g\%mask2dCu(i,j) = 0.0}
\DoxyCodeLine{1281     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1282       g\%mask2dCu(i,j) = 1.0}
\DoxyCodeLine{1283 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1284 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1285 }
\DoxyCodeLine{1286   \textcolor{keywordflow}{do} j=g\%jsd,g\%jed-1 ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied}
\DoxyCodeLine{1287     \textcolor{keywordflow}{if} ((g\%bathyT(i,j) <= dmin) .or. (g\%bathyT(i,j+1) <= dmin)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1288       g\%mask2dCv(i,j) = 0.0}
\DoxyCodeLine{1289     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1290       g\%mask2dCv(i,j) = 1.0}
\DoxyCodeLine{1291 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1292 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1293 }
\DoxyCodeLine{1294   \textcolor{keywordflow}{do} j=g\%jsd,g\%jed-1 ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied-1}
\DoxyCodeLine{1295     \textcolor{keywordflow}{if} ((g\%bathyT(i+1,j) <= dmin) .or. (g\%bathyT(i+1,j+1) <= dmin) .or. \&}
\DoxyCodeLine{1296         (g\%bathyT(i,j) <= dmin) .or. (g\%bathyT(i,j+1) <= dmin)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1297       g\%mask2dBu(i,j) = 0.0}
\DoxyCodeLine{1298     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1299       g\%mask2dBu(i,j) = 1.0}
\DoxyCodeLine{1300 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1301 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1302 }
\DoxyCodeLine{1303   \textcolor{keyword}{call }pass\_var(g\%mask2dBu, g\%Domain, position=corner)}
\DoxyCodeLine{1304   \textcolor{keyword}{call }pass\_vector(g\%mask2dCu, g\%mask2dCv, g\%Domain, to\_all+scalar\_pair, cgrid\_ne)}
\DoxyCodeLine{1305 }
\DoxyCodeLine{1306   \textcolor{keywordflow}{do} j=g\%jsd,g\%jed ; \textcolor{keywordflow}{do} i=g\%IsdB,g\%IedB}
\DoxyCodeLine{1307     g\%dy\_Cu(i,j) = g\%mask2dCu(i,j) * g\%dyCu(i,j)}
\DoxyCodeLine{1308     g\%areaCu(i,j) = g\%dxCu(i,j) * g\%dy\_Cu(i,j)}
\DoxyCodeLine{1309     g\%IareaCu(i,j) = g\%mask2dCu(i,j) * adcroft\_reciprocal(g\%areaCu(i,j))}
\DoxyCodeLine{1310 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1311 }
\DoxyCodeLine{1312   \textcolor{keywordflow}{do} j=g\%JsdB,g\%JedB ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied}
\DoxyCodeLine{1313     g\%dx\_Cv(i,j) = g\%mask2dCv(i,j) * g\%dxCv(i,j)}
\DoxyCodeLine{1314     g\%areaCv(i,j) = g\%dyCv(i,j) * g\%dx\_Cv(i,j)}
\DoxyCodeLine{1315     g\%IareaCv(i,j) = g\%mask2dCv(i,j) * adcroft\_reciprocal(g\%areaCv(i,j))}
\DoxyCodeLine{1316 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{1317 }
\DoxyCodeLine{1318   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"initialize\_masks()"})}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid__initialize_aee53e3cf4937fa86949aa376d5f3d82a}\label{namespacemom__grid__initialize_aee53e3cf4937fa86949aa376d5f3d82a}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!int\_di\_dx@{int\_di\_dx}}
\index{int\_di\_dx@{int\_di\_dx}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{int\_di\_dx()}{int\_di\_dx()}}
{\footnotesize\ttfamily real function mom\+\_\+grid\+\_\+initialize\+::int\+\_\+di\+\_\+dx (\begin{DoxyParamCaption}\item[{real, intent(in)}]{x,  }\item[{type(\mbox{\hyperlink{structmom__grid__initialize_1_1gps}{gps}}), intent(in)}]{GP }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This function calculates and returns the integral of the inverse of dx/di to the point x, in radians. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em x} & The longitude in question \\
\hline
\mbox{\texttt{ in}}  & {\em gp} & A structure of grid parameters \\
\hline
\end{DoxyParams}


Definition at line 1104 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1104 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: x\textcolor{comment}{  !< The longitude in question}}
\DoxyCodeLine{1105   \textcolor{keywordtype}{type}(GPS), \textcolor{keywordtype}{intent(in)} :: GP\textcolor{comment}{  !< A structure of grid parameters}}
\DoxyCodeLine{1106 \textcolor{keywordtype}{  real} :: Int\_di\_dx}
\DoxyCodeLine{1107 }
\DoxyCodeLine{1108   int\_di\_dx = x * ((180.0 * gp\%niglobal) / (gp\%len\_lon * 4.0*atan(1.0)))}
\DoxyCodeLine{1109 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid__initialize_a8ed056787130f21f4b9c1bc81bd60c50}\label{namespacemom__grid__initialize_a8ed056787130f21f4b9c1bc81bd60c50}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!int\_dj\_dy@{int\_dj\_dy}}
\index{int\_dj\_dy@{int\_dj\_dy}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{int\_dj\_dy()}{int\_dj\_dy()}}
{\footnotesize\ttfamily real function mom\+\_\+grid\+\_\+initialize\+::int\+\_\+dj\+\_\+dy (\begin{DoxyParamCaption}\item[{real, intent(in)}]{y,  }\item[{type(\mbox{\hyperlink{structmom__grid__initialize_1_1gps}{gps}}), intent(in)}]{GP }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine calculates and returns the integral of the inverse of dy/dj to the point y, in radians. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em y} & The latitude in question \\
\hline
\mbox{\texttt{ in}}  & {\em gp} & A structure of grid parameters \\
\hline
\end{DoxyParams}


Definition at line 1144 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{1144 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: y\textcolor{comment}{  !< The latitude in question}}
\DoxyCodeLine{1145   \textcolor{keywordtype}{type}(GPS), \textcolor{keywordtype}{intent(in)} :: GP\textcolor{comment}{  !< A structure of grid parameters}}
\DoxyCodeLine{1146 \textcolor{keywordtype}{  real} :: Int\_dj\_dy}
\DoxyCodeLine{1147   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{1148 \textcolor{keywordtype}{  real} :: I\_C0 = 0.0       \textcolor{comment}{!   The inverse of the constant that converts the}}
\DoxyCodeLine{1149                            \textcolor{comment}{! nominal spacing in gridpoints to the nominal}}
\DoxyCodeLine{1150                            \textcolor{comment}{! spacing in Radians.}}
\DoxyCodeLine{1151 \textcolor{keywordtype}{  real} :: PI               \textcolor{comment}{! 3.1415926... calculated as 4*atan(1)}}
\DoxyCodeLine{1152 \textcolor{keywordtype}{  real} :: y\_eq\_enhance     \textcolor{comment}{! The latitude in radians from}}
\DoxyCodeLine{1153                            \textcolor{comment}{! from the equator within which the}}
\DoxyCodeLine{1154                            \textcolor{comment}{! meridional grid spacing is enhanced by}}
\DoxyCodeLine{1155                            \textcolor{comment}{! a factor of GP\%lat\_enhance\_factor.}}
\DoxyCodeLine{1156 \textcolor{keywordtype}{  real} :: r}
\DoxyCodeLine{1157 }
\DoxyCodeLine{1158   pi = 4.0*atan(1.0)}
\DoxyCodeLine{1159   \textcolor{keywordflow}{if} (gp\%isotropic) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1160     i\_c0 = (180.0 * gp\%niglobal) / (gp\%len\_lon * pi)}
\DoxyCodeLine{1161     y\_eq\_enhance = pi*abs(gp\%lat\_eq\_enhance)/180.0}
\DoxyCodeLine{1162 }
\DoxyCodeLine{1163     \textcolor{keywordflow}{if} (y >= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1164       r = i\_c0 * log((1.0 + sin(y))/cos(y))}
\DoxyCodeLine{1165     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1166       r = -1.0 * i\_c0 * log((1.0 - sin(y))/cos(y))}
\DoxyCodeLine{1167 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1168 }
\DoxyCodeLine{1169     \textcolor{keywordflow}{if} (y >= y\_eq\_enhance) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1170       r = r + i\_c0*0.5*(gp\%lat\_enhance\_factor - 1.0)*y\_eq\_enhance}
\DoxyCodeLine{1171     \textcolor{keywordflow}{elseif} (y <= -y\_eq\_enhance) \textcolor{keywordflow}{then}}
\DoxyCodeLine{1172       r = r - i\_c0*0.5*(gp\%lat\_enhance\_factor - 1.0)*y\_eq\_enhance}
\DoxyCodeLine{1173     \textcolor{keywordflow}{else}}
\DoxyCodeLine{1174       r = r + i\_c0*0.5*(gp\%lat\_enhance\_factor - 1.0) * \&}
\DoxyCodeLine{1175               (y + (y\_eq\_enhance/pi)*sin(pi*y/y\_eq\_enhance))}
\DoxyCodeLine{1176 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{1177   \textcolor{keywordflow}{else}}
\DoxyCodeLine{1178     i\_c0 = (180.0 * gp\%njglobal) / (gp\%len\_lat * pi)}
\DoxyCodeLine{1179     r = i\_c0 * y}
\DoxyCodeLine{1180 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{1181 }
\DoxyCodeLine{1182   int\_dj\_dy = r}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid__initialize_a80ff9ab4bfca58b9858abc4ce95b06e9}\label{namespacemom__grid__initialize_a80ff9ab4bfca58b9858abc4ce95b06e9}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!set\_grid\_metrics@{set\_grid\_metrics}}
\index{set\_grid\_metrics@{set\_grid\_metrics}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{set\_grid\_metrics()}{set\_grid\_metrics()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+grid\+\_\+initialize\+::set\+\_\+grid\+\_\+metrics (\begin{DoxyParamCaption}\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(inout)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in), optional}]{US }\end{DoxyParamCaption})}



set\+\_\+grid\+\_\+metrics is used to set the primary values in the model\textquotesingle{}s horizontal grid. The bathymetry, land-\/sea mask and any restricted channel widths are not known yet, so these are set later. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The dynamic horizontal grid type \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & Parameter file structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\end{DoxyParams}


Definition at line 63 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{63   \textcolor{keywordtype}{type}(dyn\_horgrid\_type),          \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{  !< The dynamic horizontal grid type}}
\DoxyCodeLine{64   \textcolor{keywordtype}{type}(param\_file\_type),           \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file structure}}
\DoxyCodeLine{65   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{66   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{67 \textcolor{comment}{! This include declares and sets the variable "version".}}
\DoxyCodeLine{68 \textcolor{preprocessor}{\#include "version\_variable.h"}}
\DoxyCodeLine{69 \textcolor{preprocessor}{}  \textcolor{keywordtype}{logical} :: debug}
\DoxyCodeLine{70   \textcolor{keywordtype}{character(len=256)} :: config}
\DoxyCodeLine{71 }
\DoxyCodeLine{72   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"set\_grid\_metrics(), MOM\_grid\_initialize.F90"})}
\DoxyCodeLine{73   \textcolor{keyword}{call }log\_version(param\_file, \textcolor{stringliteral}{"MOM\_grid\_init"}, version, \textcolor{stringliteral}{""})}
\DoxyCodeLine{74   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM\_grid\_init"}, \textcolor{stringliteral}{"GRID\_CONFIG"}, config, \&}
\DoxyCodeLine{75                  \textcolor{stringliteral}{"A character string that determines the method for "}//\&}
\DoxyCodeLine{76                  \textcolor{stringliteral}{"defining the horizontal grid.  Current options are: \(\backslash\)n"}//\&}
\DoxyCodeLine{77                  \textcolor{stringliteral}{" \(\backslash\)t mosaic - read the grid from a mosaic (supergrid) \(\backslash\)n"}//\&}
\DoxyCodeLine{78                  \textcolor{stringliteral}{" \(\backslash\)t          file set by GRID\_FILE.\(\backslash\)n"}//\&}
\DoxyCodeLine{79                  \textcolor{stringliteral}{" \(\backslash\)t cartesian - use a (flat) Cartesian grid.\(\backslash\)n"}//\&}
\DoxyCodeLine{80                  \textcolor{stringliteral}{" \(\backslash\)t spherical - use a simple spherical grid.\(\backslash\)n"}//\&}
\DoxyCodeLine{81                  \textcolor{stringliteral}{" \(\backslash\)t mercator - use a Mercator spherical grid."}, \&}
\DoxyCodeLine{82                  fail\_if\_missing=.true.)}
\DoxyCodeLine{83   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM\_grid\_init"}, \textcolor{stringliteral}{"DEBUG"}, debug, \&}
\DoxyCodeLine{84                  \textcolor{stringliteral}{"If true, write out verbose debugging data."}, \&}
\DoxyCodeLine{85                  default=.false., debuggingparam=.true.)}
\DoxyCodeLine{86 }
\DoxyCodeLine{87   \textcolor{comment}{! These are defaults that may be changed in the next select block.}}
\DoxyCodeLine{88   g\%x\_axis\_units = \textcolor{stringliteral}{"degrees\_east"} ; g\%y\_axis\_units = \textcolor{stringliteral}{"degrees\_north"}}
\DoxyCodeLine{89   \textcolor{keywordflow}{select case} (trim(config))}
\DoxyCodeLine{90     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"mosaic"});    \textcolor{keyword}{call }set\_grid\_metrics\_from\_mosaic(g, param\_file, us)}
\DoxyCodeLine{91     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"cartesian"}); \textcolor{keyword}{call }set\_grid\_metrics\_cartesian(g, param\_file, us)}
\DoxyCodeLine{92     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"spherical"}); \textcolor{keyword}{call }set\_grid\_metrics\_spherical(g, param\_file, us)}
\DoxyCodeLine{93     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"mercator"});  \textcolor{keyword}{call }set\_grid\_metrics\_mercator(g, param\_file, us)}
\DoxyCodeLine{94     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"file"}); \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_grid\_init: set\_grid\_metrics "}//\&}
\DoxyCodeLine{95            \textcolor{stringliteral}{'GRID\_CONFIG "file" is no longer a supported option.  Use a '}//\&}
\DoxyCodeLine{96            \textcolor{stringliteral}{'mosaic file ("mosaic") or one of the analytic forms instead.'})}
\DoxyCodeLine{97 \textcolor{keywordflow}{    case default} ; \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_grid\_init: set\_grid\_metrics "}//\&}
\DoxyCodeLine{98            \textcolor{stringliteral}{"Unrecognized grid configuration "}//trim(config))}
\DoxyCodeLine{99 \textcolor{keywordflow}{  end select}}
\DoxyCodeLine{100 }
\DoxyCodeLine{101   \textcolor{comment}{! Calculate derived metrics (i.e. reciprocals and products)}}
\DoxyCodeLine{102   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"set\_derived\_metrics(), MOM\_grid\_initialize.F90"})}
\DoxyCodeLine{103   \textcolor{keyword}{call }set\_derived\_dyn\_horgrid(g, us)}
\DoxyCodeLine{104   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"set\_derived\_metrics()"})}
\DoxyCodeLine{105 }
\DoxyCodeLine{106   \textcolor{keywordflow}{if} (debug) \textcolor{keyword}{call }grid\_metrics\_chksum(\textcolor{stringliteral}{'MOM\_grid\_init/set\_grid\_metrics'}, g, us)}
\DoxyCodeLine{107 }
\DoxyCodeLine{108   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"set\_grid\_metrics()"})}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid__initialize_a0b05a77813a4ca80172f3855e688d19f}\label{namespacemom__grid__initialize_a0b05a77813a4ca80172f3855e688d19f}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!set\_grid\_metrics\_cartesian@{set\_grid\_metrics\_cartesian}}
\index{set\_grid\_metrics\_cartesian@{set\_grid\_metrics\_cartesian}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{set\_grid\_metrics\_cartesian()}{set\_grid\_metrics\_cartesian()}}
{\footnotesize\ttfamily subroutine mom\+\_\+grid\+\_\+initialize\+::set\+\_\+grid\+\_\+metrics\+\_\+cartesian (\begin{DoxyParamCaption}\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(inout)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in), optional}]{US }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculate the values of the metric terms for a Cartesian grid that might be used and save them in arrays. 

Within this subroutine, the x-\/ and y-\/ grid spacings and their inverses and the cell areas centered on h, q, u, and v points are calculated, as are the geographic locations of each of these 4 sets of points. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The dynamic horizontal grid type \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & Parameter file structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\end{DoxyParams}


Definition at line 420 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{420   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{           !< The dynamic horizontal grid type}}
\DoxyCodeLine{421   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)}     :: param\_file\textcolor{comment}{  !< Parameter file structure}}
\DoxyCodeLine{422   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{    !< A dimensional unit scaling type}}
\DoxyCodeLine{423   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{424   \textcolor{keywordtype}{integer} :: i, j, isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB, I1off, J1off}
\DoxyCodeLine{425   \textcolor{keywordtype}{integer} :: niglobal, njglobal}
\DoxyCodeLine{426 \textcolor{keywordtype}{  real} :: grid\_latT(G\%jsd:G\%jed), grid\_latB(G\%JsdB:G\%JedB)}
\DoxyCodeLine{427 \textcolor{keywordtype}{  real} :: grid\_lonT(G\%isd:G\%ied), grid\_lonB(G\%IsdB:G\%IedB)}
\DoxyCodeLine{428 \textcolor{keywordtype}{  real} :: dx\_everywhere, dy\_everywhere \textcolor{comment}{! Grid spacings [m].}}
\DoxyCodeLine{429 \textcolor{keywordtype}{  real} :: I\_dx, I\_dy                   \textcolor{comment}{! Inverse grid spacings [m-1].}}
\DoxyCodeLine{430 \textcolor{keywordtype}{  real} :: PI}
\DoxyCodeLine{431 \textcolor{keywordtype}{  real} :: m\_to\_L  \textcolor{comment}{! A unit conversion factor [L m-1 ~> nondim]}}
\DoxyCodeLine{432 \textcolor{keywordtype}{  real} :: L\_to\_m  \textcolor{comment}{! A unit conversion factor [m L-1 ~> nondim]}}
\DoxyCodeLine{433   \textcolor{keywordtype}{character(len=80)} :: units\_temp}
\DoxyCodeLine{434   \textcolor{keywordtype}{character(len=48)} :: mdl  = \textcolor{stringliteral}{"MOM\_grid\_init set\_grid\_metrics\_cartesian"}}
\DoxyCodeLine{435 }
\DoxyCodeLine{436   niglobal = g\%Domain\%niglobal ; njglobal = g\%Domain\%njglobal}
\DoxyCodeLine{437   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{438   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{439   i1off = g\%idg\_offset ; j1off = g\%jdg\_offset}
\DoxyCodeLine{440 }
\DoxyCodeLine{441   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"set\_grid\_metrics\_cartesian(), MOM\_grid\_initialize.F90"})}
\DoxyCodeLine{442 }
\DoxyCodeLine{443   m\_to\_l = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) m\_to\_l = us\%m\_to\_L}
\DoxyCodeLine{444   l\_to\_m = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) l\_to\_m = us\%L\_to\_m}
\DoxyCodeLine{445   pi = 4.0*atan(1.0)}
\DoxyCodeLine{446 }
\DoxyCodeLine{447   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"AXIS\_UNITS"}, units\_temp, \&}
\DoxyCodeLine{448                  \textcolor{stringliteral}{"The units for the Cartesian axes. Valid entries are: \(\backslash\)n"}//\&}
\DoxyCodeLine{449                  \textcolor{stringliteral}{" \(\backslash\)t degrees - degrees of latitude and longitude \(\backslash\)n"}//\&}
\DoxyCodeLine{450                  \textcolor{stringliteral}{" \(\backslash\)t m - meters \(\backslash\)n \(\backslash\)t k - kilometers"}, default=\textcolor{stringliteral}{"degrees"})}
\DoxyCodeLine{451   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SOUTHLAT"}, g\%south\_lat, \&}
\DoxyCodeLine{452                  \textcolor{stringliteral}{"The southern latitude of the domain or the equivalent "}//\&}
\DoxyCodeLine{453                  \textcolor{stringliteral}{"starting value for the y-axis."}, units=units\_temp, \&}
\DoxyCodeLine{454                  fail\_if\_missing=.true.)}
\DoxyCodeLine{455   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LENLAT"}, g\%len\_lat, \&}
\DoxyCodeLine{456                  \textcolor{stringliteral}{"The latitudinal or y-direction length of the domain."}, \&}
\DoxyCodeLine{457                  units=units\_temp, fail\_if\_missing=.true.)}
\DoxyCodeLine{458   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"WESTLON"}, g\%west\_lon, \&}
\DoxyCodeLine{459                  \textcolor{stringliteral}{"The western longitude of the domain or the equivalent "}//\&}
\DoxyCodeLine{460                  \textcolor{stringliteral}{"starting value for the x-axis."}, units=units\_temp, \&}
\DoxyCodeLine{461                  default=0.0)}
\DoxyCodeLine{462   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LENLON"}, g\%len\_lon, \&}
\DoxyCodeLine{463                  \textcolor{stringliteral}{"The longitudinal or x-direction length of the domain."}, \&}
\DoxyCodeLine{464                  units=units\_temp, fail\_if\_missing=.true.)}
\DoxyCodeLine{465   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RAD\_EARTH"}, g\%Rad\_Earth, \&}
\DoxyCodeLine{466                  \textcolor{stringliteral}{"The radius of the Earth."}, units=\textcolor{stringliteral}{"m"}, default=6.378e6)}
\DoxyCodeLine{467 }
\DoxyCodeLine{468   \textcolor{keywordflow}{if} (units\_temp(1:1) == \textcolor{stringliteral}{'k'}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{469     g\%x\_axis\_units = \textcolor{stringliteral}{"kilometers"} ; g\%y\_axis\_units = \textcolor{stringliteral}{"kilometers"}}
\DoxyCodeLine{470   \textcolor{keywordflow}{elseif} (units\_temp(1:1) == \textcolor{stringliteral}{'m'}) \textcolor{keywordflow}{then}}
\DoxyCodeLine{471     g\%x\_axis\_units = \textcolor{stringliteral}{"meters"} ; g\%y\_axis\_units = \textcolor{stringliteral}{"meters"}}
\DoxyCodeLine{472 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{473   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"explicit AXIS\_UNITS"}, g\%x\_axis\_units)}
\DoxyCodeLine{474 }
\DoxyCodeLine{475   \textcolor{comment}{! Note that the dynamic grid always uses symmetric memory for the global}}
\DoxyCodeLine{476   \textcolor{comment}{! arrays G\%gridLatB and G\%gridLonB.}}
\DoxyCodeLine{477   \textcolor{keywordflow}{do} j=g\%jsg-1,g\%jeg}
\DoxyCodeLine{478     g\%gridLatB(j) = g\%south\_lat + g\%len\_lat*real(j-(g\%jsg-1))/real(njglobal)}
\DoxyCodeLine{479 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{480   \textcolor{keywordflow}{do} j=g\%jsg,g\%jeg}
\DoxyCodeLine{481     g\%gridLatT(j) = g\%south\_lat + g\%len\_lat*(real(j-g\%jsg)+0.5)/real(njglobal)}
\DoxyCodeLine{482 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{483   \textcolor{keywordflow}{do} i=g\%isg-1,g\%ieg}
\DoxyCodeLine{484     g\%gridLonB(i) = g\%west\_lon + g\%len\_lon*real(i-(g\%isg-1))/real(niglobal)}
\DoxyCodeLine{485 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{486   \textcolor{keywordflow}{do} i=g\%isg,g\%ieg}
\DoxyCodeLine{487     g\%gridLonT(i) = g\%west\_lon + g\%len\_lon*(real(i-g\%isg)+0.5)/real(niglobal)}
\DoxyCodeLine{488 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{489 }
\DoxyCodeLine{490   \textcolor{keywordflow}{do} j=jsdb,jedb}
\DoxyCodeLine{491     grid\_latb(j) = g\%south\_lat + g\%len\_lat*real(j+j1off-(g\%jsg-1))/real(njglobal)}
\DoxyCodeLine{492 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{493   \textcolor{keywordflow}{do} j=jsd,jed}
\DoxyCodeLine{494     grid\_latt(j) = g\%south\_lat + g\%len\_lat*(real(j+j1off-g\%jsg)+0.5)/real(njglobal)}
\DoxyCodeLine{495 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{496   \textcolor{keywordflow}{do} i=isdb,iedb}
\DoxyCodeLine{497     grid\_lonb(i) = g\%west\_lon + g\%len\_lon*real(i+i1off-(g\%isg-1))/real(niglobal)}
\DoxyCodeLine{498 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{499   \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{500     grid\_lont(i) = g\%west\_lon + g\%len\_lon*(real(i+i1off-g\%isg)+0.5)/real(niglobal)}
\DoxyCodeLine{501 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{502 }
\DoxyCodeLine{503   \textcolor{keywordflow}{if} (units\_temp(1:1) == \textcolor{stringliteral}{'k'}) \textcolor{keywordflow}{then} \textcolor{comment}{! Axes are measured in km.}}
\DoxyCodeLine{504     dx\_everywhere = 1000.0 * g\%len\_lon / (real(niglobal))}
\DoxyCodeLine{505     dy\_everywhere = 1000.0 * g\%len\_lat / (real(njglobal))}
\DoxyCodeLine{506   \textcolor{keywordflow}{elseif} (units\_temp(1:1) == \textcolor{stringliteral}{'m'}) \textcolor{keywordflow}{then} \textcolor{comment}{! Axes are measured in m.}}
\DoxyCodeLine{507     dx\_everywhere = g\%len\_lon / (real(niglobal))}
\DoxyCodeLine{508     dy\_everywhere = g\%len\_lat / (real(njglobal))}
\DoxyCodeLine{509   \textcolor{keywordflow}{else} \textcolor{comment}{! Axes are measured in degrees of latitude and longitude.}}
\DoxyCodeLine{510     dx\_everywhere = g\%Rad\_Earth * g\%len\_lon * pi / (180.0 * niglobal)}
\DoxyCodeLine{511     dy\_everywhere = g\%Rad\_Earth * g\%len\_lat * pi / (180.0 * njglobal)}
\DoxyCodeLine{512 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{513 }
\DoxyCodeLine{514   i\_dx = 1.0 / dx\_everywhere ; i\_dy = 1.0 / dy\_everywhere}
\DoxyCodeLine{515 }
\DoxyCodeLine{516   \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isdb,iedb}
\DoxyCodeLine{517     g\%geoLonBu(i,j) = grid\_lonb(i) ; g\%geoLatBu(i,j) = grid\_latb(j)}
\DoxyCodeLine{518 }
\DoxyCodeLine{519     g\%dxBu(i,j) = m\_to\_l*dx\_everywhere ; g\%IdxBu(i,j) = l\_to\_m*i\_dx}
\DoxyCodeLine{520     g\%dyBu(i,j) = m\_to\_l*dy\_everywhere ; g\%IdyBu(i,j) = l\_to\_m*i\_dy}
\DoxyCodeLine{521     g\%areaBu(i,j) = m\_to\_l**2*dx\_everywhere * dy\_everywhere ; g\%IareaBu(i,j) = l\_to\_m**2*i\_dx * i\_dy}
\DoxyCodeLine{522 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{523 }
\DoxyCodeLine{524   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{525     g\%geoLonT(i,j) = grid\_lont(i) ; g\%geoLatT(i,j) = grid\_latt(j)}
\DoxyCodeLine{526     g\%dxT(i,j) = m\_to\_l*dx\_everywhere ; g\%IdxT(i,j) = l\_to\_m*i\_dx}
\DoxyCodeLine{527     g\%dyT(i,j) = m\_to\_l*dy\_everywhere ; g\%IdyT(i,j) = l\_to\_m*i\_dy}
\DoxyCodeLine{528     g\%areaT(i,j) = m\_to\_l**2*dx\_everywhere * dy\_everywhere ; g\%IareaT(i,j) = l\_to\_m**2*i\_dx * i\_dy}
\DoxyCodeLine{529 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{530 }
\DoxyCodeLine{531   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb}
\DoxyCodeLine{532     g\%geoLonCu(i,j) = grid\_lonb(i) ; g\%geoLatCu(i,j) = grid\_latt(j)}
\DoxyCodeLine{533 }
\DoxyCodeLine{534     g\%dxCu(i,j) = m\_to\_l*dx\_everywhere ; g\%IdxCu(i,j) = l\_to\_m*i\_dx}
\DoxyCodeLine{535     g\%dyCu(i,j) = m\_to\_l*dy\_everywhere ; g\%IdyCu(i,j) = l\_to\_m*i\_dy}
\DoxyCodeLine{536 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{537 }
\DoxyCodeLine{538   \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{539     g\%geoLonCv(i,j) = grid\_lont(i) ; g\%geoLatCv(i,j) = grid\_latb(j)}
\DoxyCodeLine{540 }
\DoxyCodeLine{541     g\%dxCv(i,j) = m\_to\_l*dx\_everywhere ; g\%IdxCv(i,j) = l\_to\_m*i\_dx}
\DoxyCodeLine{542     g\%dyCv(i,j) = m\_to\_l*dy\_everywhere ; g\%IdyCv(i,j) = l\_to\_m*i\_dy}
\DoxyCodeLine{543 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{544 }
\DoxyCodeLine{545   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"set\_grid\_metrics\_cartesian()"})}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid__initialize_a93edcd084a84a50c6aef6053a2cc64f3}\label{namespacemom__grid__initialize_a93edcd084a84a50c6aef6053a2cc64f3}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!set\_grid\_metrics\_from\_mosaic@{set\_grid\_metrics\_from\_mosaic}}
\index{set\_grid\_metrics\_from\_mosaic@{set\_grid\_metrics\_from\_mosaic}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{set\_grid\_metrics\_from\_mosaic()}{set\_grid\_metrics\_from\_mosaic()}}
{\footnotesize\ttfamily subroutine mom\+\_\+grid\+\_\+initialize\+::set\+\_\+grid\+\_\+metrics\+\_\+from\+\_\+mosaic (\begin{DoxyParamCaption}\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(inout)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in), optional}]{US }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Sets the grid metrics from a mosaic file. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The dynamic horizontal grid type \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & Parameter file structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\end{DoxyParams}


Definition at line 168 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{168   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{           !< The dynamic horizontal grid type}}
\DoxyCodeLine{169   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)}     :: param\_file\textcolor{comment}{  !< Parameter file structure}}
\DoxyCodeLine{170   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{    !< A dimensional unit scaling type}}
\DoxyCodeLine{171   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{172 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd :G\%ied ,G\%jsd :G\%jed )} :: tempH1, tempH2, tempH3, tempH4}
\DoxyCodeLine{173 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%IsdB:G\%IedB,G\%JsdB:G\%JedB)} :: tempQ1, tempQ2, tempQ3, tempQ4}
\DoxyCodeLine{174 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%IsdB:G\%IedB,G\%jsd :G\%jed )} :: tempE1, tempE2}
\DoxyCodeLine{175 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd :G\%ied ,G\%JsdB:G\%JedB)} :: tempN1, tempN2}
\DoxyCodeLine{176   \textcolor{comment}{! These arrays are a holdover from earlier code in which the arrays in G were}}
\DoxyCodeLine{177   \textcolor{comment}{! macros and may have had reduced dimensions.}}
\DoxyCodeLine{178 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd :G\%ied ,G\%jsd :G\%jed )} :: dxT, dyT, areaT}
\DoxyCodeLine{179 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%IsdB:G\%IedB,G\%jsd :G\%jed )} :: dxCu, dyCu}
\DoxyCodeLine{180 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd :G\%ied ,G\%JsdB:G\%JedB)} :: dxCv, dyCv}
\DoxyCodeLine{181 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%IsdB:G\%IedB,G\%JsdB:G\%JedB)} :: dxBu, dyBu, areaBu}
\DoxyCodeLine{182   \textcolor{comment}{! This are symmetric arrays, corresponding to the data in the mosaic file}}
\DoxyCodeLine{183 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(2*G\%isd-2:2*G\%ied+1,2*G\%jsd-2:2*G\%jed+1)} :: tmpT}
\DoxyCodeLine{184 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(2*G\%isd-3:2*G\%ied+1,2*G\%jsd-2:2*G\%jed+1)} :: tmpU}
\DoxyCodeLine{185 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(2*G\%isd-2:2*G\%ied+1,2*G\%jsd-3:2*G\%jed+1)} :: tmpV}
\DoxyCodeLine{186 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(2*G\%isd-3:2*G\%ied+1,2*G\%jsd-3:2*G\%jed+1)} :: tmpZ}
\DoxyCodeLine{187 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{allocatable} :: tmpGlbl}
\DoxyCodeLine{188 \textcolor{keywordtype}{  real} :: m\_to\_L  \textcolor{comment}{! A unit conversion factor [L m-1 ~> nondim]}}
\DoxyCodeLine{189   \textcolor{keywordtype}{character(len=200)} :: filename, grid\_file, inputdir}
\DoxyCodeLine{190   \textcolor{keywordtype}{character(len=64)}  :: mdl = \textcolor{stringliteral}{"MOM\_grid\_init set\_grid\_metrics\_from\_mosaic"}}
\DoxyCodeLine{191   \textcolor{keywordtype}{integer} :: err=0, ni, nj, global\_indices(4)}
\DoxyCodeLine{192   \textcolor{keywordtype}{type}(MOM\_domain\_type) :: SGdom \textcolor{comment}{! Supergrid domain}}
\DoxyCodeLine{193   \textcolor{keywordtype}{logical} :: lon\_bug  \textcolor{comment}{! If true use an older buggy answer in the tripolar longitude.}}
\DoxyCodeLine{194   \textcolor{keywordtype}{integer} :: i, j, i2, j2}
\DoxyCodeLine{195   \textcolor{keywordtype}{integer} :: npei,npej}
\DoxyCodeLine{196   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable} :: exni,exnj}
\DoxyCodeLine{197   \textcolor{keywordtype}{integer}        :: start(4), nread(4)}
\DoxyCodeLine{198 }
\DoxyCodeLine{199   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"set\_grid\_metrics\_from\_mosaic(), MOM\_grid\_initialize.F90"})}
\DoxyCodeLine{200 }
\DoxyCodeLine{201   m\_to\_l = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) m\_to\_l = us\%m\_to\_L}
\DoxyCodeLine{202   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GRID\_FILE"}, grid\_file, \&}
\DoxyCodeLine{203                  \textcolor{stringliteral}{"Name of the file from which to read horizontal grid data."}, \&}
\DoxyCodeLine{204                  fail\_if\_missing=.true.)}
\DoxyCodeLine{205   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_TRIPOLAR\_GEOLONB\_BUG"}, lon\_bug, \&}
\DoxyCodeLine{206                  \textcolor{stringliteral}{"If true, use older code that incorrectly sets the longitude "}//\&}
\DoxyCodeLine{207                  \textcolor{stringliteral}{"in some points along the tripolar fold to be off by 360 degrees."}, \&}
\DoxyCodeLine{208                  default=.false.)}
\DoxyCodeLine{209   \textcolor{keyword}{call }get\_param(param\_file,  mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."})}
\DoxyCodeLine{210   inputdir = slasher(inputdir)}
\DoxyCodeLine{211   filename = trim(adjustl(inputdir)) // trim(adjustl(grid\_file))}
\DoxyCodeLine{212   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/GRID\_FILE"}, filename)}
\DoxyCodeLine{213   \textcolor{keywordflow}{if} (.not.file\_exists(filename)) \&}
\DoxyCodeLine{214     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{" set\_grid\_metrics\_from\_mosaic: Unable to open "}//\&}
\DoxyCodeLine{215                            trim(filename))}
\DoxyCodeLine{216 }
\DoxyCodeLine{217   \textcolor{comment}{! Initialize everything to 0.}}
\DoxyCodeLine{218   dxcu(:,:) = 0.0 ; dycu(:,:) = 0.0}
\DoxyCodeLine{219   dxcv(:,:) = 0.0 ; dycv(:,:) = 0.0}
\DoxyCodeLine{220   dxbu(:,:) = 0.0 ; dybu(:,:) = 0.0 ; areabu(:,:) = 0.0}
\DoxyCodeLine{221 }
\DoxyCodeLine{222   \textcolor{comment}{!<MISSING CODE TO READ REFINEMENT LEVEL>}}
\DoxyCodeLine{223   ni = 2*(g\%iec-g\%isc+1) \textcolor{comment}{! i size of supergrid}}
\DoxyCodeLine{224   nj = 2*(g\%jec-g\%jsc+1) \textcolor{comment}{! j size of supergrid}}
\DoxyCodeLine{225 }
\DoxyCodeLine{226   \textcolor{comment}{! Define a domain for the supergrid (SGdom)}}
\DoxyCodeLine{227   npei = g\%domain\%layout(1) ; npej = g\%domain\%layout(2)}
\DoxyCodeLine{228   \textcolor{keyword}{allocate}(exni(npei)) ; \textcolor{keyword}{allocate}(exnj(npej))}
\DoxyCodeLine{229   \textcolor{keyword}{call }mpp\_get\_domain\_extents(g\%domain\%mpp\_domain, exni, exnj)}
\DoxyCodeLine{230   \textcolor{keyword}{allocate}(sgdom\%mpp\_domain)}
\DoxyCodeLine{231   sgdom\%nihalo = 2*g\%domain\%nihalo+1}
\DoxyCodeLine{232   sgdom\%njhalo = 2*g\%domain\%njhalo+1}
\DoxyCodeLine{233   sgdom\%niglobal = 2*g\%domain\%niglobal}
\DoxyCodeLine{234   sgdom\%njglobal = 2*g\%domain\%njglobal}
\DoxyCodeLine{235   sgdom\%layout(:) = g\%domain\%layout(:)}
\DoxyCodeLine{236   sgdom\%io\_layout(:) = g\%domain\%io\_layout(:)}
\DoxyCodeLine{237   global\_indices(1) = 1+sgdom\%nihalo}
\DoxyCodeLine{238   global\_indices(2) = sgdom\%niglobal+sgdom\%nihalo}
\DoxyCodeLine{239   global\_indices(3) = 1+sgdom\%njhalo}
\DoxyCodeLine{240   global\_indices(4) = sgdom\%njglobal+sgdom\%njhalo}
\DoxyCodeLine{241   exni(:) = 2*exni(:) ; exnj(:) = 2*exnj(:)}
\DoxyCodeLine{242   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(g\%domain\%maskmap)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{243      \textcolor{keyword}{call }mom\_define\_domain(global\_indices, sgdom\%layout, sgdom\%mpp\_domain, \&}
\DoxyCodeLine{244             xflags=g\%domain\%X\_FLAGS, yflags=g\%domain\%Y\_FLAGS, \&}
\DoxyCodeLine{245             xhalo=sgdom\%nihalo, yhalo=sgdom\%njhalo, \&}
\DoxyCodeLine{246             xextent=exni,yextent=exnj, \&}
\DoxyCodeLine{247             symmetry=.true., name=\textcolor{stringliteral}{"MOM\_MOSAIC"}, maskmap=g\%domain\%maskmap)}
\DoxyCodeLine{248   \textcolor{keywordflow}{else}}
\DoxyCodeLine{249      \textcolor{keyword}{call }mom\_define\_domain(global\_indices, sgdom\%layout, sgdom\%mpp\_domain, \&}
\DoxyCodeLine{250             xflags=g\%domain\%X\_FLAGS, yflags=g\%domain\%Y\_FLAGS, \&}
\DoxyCodeLine{251             xhalo=sgdom\%nihalo, yhalo=sgdom\%njhalo, \&}
\DoxyCodeLine{252             xextent=exni,yextent=exnj, \&}
\DoxyCodeLine{253             symmetry=.true., name=\textcolor{stringliteral}{"MOM\_MOSAIC"})}
\DoxyCodeLine{254 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{255 }
\DoxyCodeLine{256   \textcolor{keyword}{call }mom\_define\_io\_domain(sgdom\%mpp\_domain, sgdom\%io\_layout)}
\DoxyCodeLine{257   \textcolor{keyword}{deallocate}(exni)}
\DoxyCodeLine{258   \textcolor{keyword}{deallocate}(exnj)}
\DoxyCodeLine{259 }
\DoxyCodeLine{260   \textcolor{comment}{! Read X from the supergrid}}
\DoxyCodeLine{261   tmpz(:,:) = 999.}
\DoxyCodeLine{262   \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'x'}, tmpz, sgdom, position=corner)}
\DoxyCodeLine{263 }
\DoxyCodeLine{264   \textcolor{keywordflow}{if} (lon\_bug) \textcolor{keywordflow}{then}}
\DoxyCodeLine{265     \textcolor{keyword}{call }pass\_var(tmpz, sgdom, position=corner)}
\DoxyCodeLine{266   \textcolor{keywordflow}{else}}
\DoxyCodeLine{267     \textcolor{keyword}{call }pass\_var(tmpz, sgdom, position=corner, inner\_halo=0)}
\DoxyCodeLine{268 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{269   \textcolor{keyword}{call }extrapolate\_metric(tmpz, 2*(g\%jsc-g\%jsd)+2, missing=999.)}
\DoxyCodeLine{270   \textcolor{keywordflow}{do} j=g\%jsd,g\%jed ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied ; i2 = 2*i ; j2 = 2*j}
\DoxyCodeLine{271     g\%geoLonT(i,j) = tmpz(i2-1,j2-1)}
\DoxyCodeLine{272 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{273   \textcolor{keywordflow}{do} j=g\%JsdB,g\%JedB ; \textcolor{keywordflow}{do} i=g\%IsdB,g\%IedB ; i2 = 2*i ; j2 = 2*j}
\DoxyCodeLine{274     g\%geoLonBu(i,j) = tmpz(i2,j2)}
\DoxyCodeLine{275 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{276   \textcolor{keywordflow}{do} j=g\%jsd,g\%jed ; \textcolor{keywordflow}{do} i=g\%IsdB,g\%IedB ; i2 = 2*i ; j2 = 2*j}
\DoxyCodeLine{277     g\%geoLonCu(i,j) = tmpz(i2,j2-1)}
\DoxyCodeLine{278 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{279   \textcolor{keywordflow}{do} j=g\%JsdB,g\%JedB ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied ; i2 = 2*i ; j2 = 2*j}
\DoxyCodeLine{280     g\%geoLonCv(i,j) = tmpz(i2-1,j2)}
\DoxyCodeLine{281 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{282   \textcolor{comment}{! For some reason, this messes up the solution...}}
\DoxyCodeLine{283   \textcolor{comment}{!   call pass\_var(G\%geoLonBu, G\%domain, position=CORNER)}}
\DoxyCodeLine{284 }
\DoxyCodeLine{285   \textcolor{comment}{! Read Y from the supergrid}}
\DoxyCodeLine{286   tmpz(:,:) = 999.}
\DoxyCodeLine{287   \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'y'}, tmpz, sgdom, position=corner)}
\DoxyCodeLine{288 }
\DoxyCodeLine{289   \textcolor{keyword}{call }pass\_var(tmpz, sgdom, position=corner)}
\DoxyCodeLine{290   \textcolor{keyword}{call }extrapolate\_metric(tmpz, 2*(g\%jsc-g\%jsd)+2, missing=999.)}
\DoxyCodeLine{291   \textcolor{keywordflow}{do} j=g\%jsd,g\%jed ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied ; i2 = 2*i ; j2 = 2*j}
\DoxyCodeLine{292     g\%geoLatT(i,j) = tmpz(i2-1,j2-1)}
\DoxyCodeLine{293 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{294   \textcolor{keywordflow}{do} j=g\%JsdB,g\%JedB ; \textcolor{keywordflow}{do} i=g\%IsdB,g\%IedB ; i2 = 2*i ; j2 = 2*j}
\DoxyCodeLine{295     g\%geoLatBu(i,j) = tmpz(i2,j2)}
\DoxyCodeLine{296 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{297   \textcolor{keywordflow}{do} j=g\%jsd,g\%jed ; \textcolor{keywordflow}{do} i=g\%IsdB,g\%IedB ; i2 = 2*i ; j2 = 2*j}
\DoxyCodeLine{298     g\%geoLatCu(i,j) = tmpz(i2,j2-1)}
\DoxyCodeLine{299 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{300   \textcolor{keywordflow}{do} j=g\%JsdB,g\%JedB ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied ; i2 = 2*i ; j2 = 2*j}
\DoxyCodeLine{301     g\%geoLatCv(i,j) = tmpz(i2-1,j2)}
\DoxyCodeLine{302 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{303 }
\DoxyCodeLine{304   \textcolor{comment}{! Read DX,DY from the supergrid}}
\DoxyCodeLine{305   tmpu(:,:) = 0. ; tmpv(:,:) = 0.}
\DoxyCodeLine{306   \textcolor{keyword}{call }mom\_read\_data(filename,\textcolor{stringliteral}{'dx'},tmpv,sgdom,position=north\_face)}
\DoxyCodeLine{307   \textcolor{keyword}{call }mom\_read\_data(filename,\textcolor{stringliteral}{'dy'},tmpu,sgdom,position=east\_face)}
\DoxyCodeLine{308   \textcolor{keyword}{call }pass\_vector(tmpu, tmpv, sgdom, to\_all+scalar\_pair, cgrid\_ne)}
\DoxyCodeLine{309   \textcolor{keyword}{call }extrapolate\_metric(tmpv, 2*(g\%jsc-g\%jsd)+2, missing=0.)}
\DoxyCodeLine{310   \textcolor{keyword}{call }extrapolate\_metric(tmpu, 2*(g\%jsc-g\%jsd)+2, missing=0.)}
\DoxyCodeLine{311 }
\DoxyCodeLine{312   \textcolor{keywordflow}{do} j=g\%jsd,g\%jed ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied ; i2 = 2*i ; j2 = 2*j}
\DoxyCodeLine{313     dxt(i,j) = tmpv(i2-1,j2-1) + tmpv(i2,j2-1)}
\DoxyCodeLine{314     dyt(i,j) = tmpu(i2-1,j2-1) + tmpu(i2-1,j2)}
\DoxyCodeLine{315 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{316 }
\DoxyCodeLine{317   \textcolor{keywordflow}{do} j=g\%jsd,g\%jed ; \textcolor{keywordflow}{do} i=g\%IsdB,g\%IedB ; i2 = 2*i ; j2 = 2*j}
\DoxyCodeLine{318     dxcu(i,j) = tmpv(i2,j2-1) + tmpv(i2+1,j2-1)}
\DoxyCodeLine{319     dycu(i,j) = tmpu(i2,j2-1) + tmpu(i2,j2)}
\DoxyCodeLine{320 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{321 }
\DoxyCodeLine{322   \textcolor{keywordflow}{do} j=g\%JsdB,g\%JedB ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied ; i2 = 2*i ; j2 = 2*j}
\DoxyCodeLine{323     dxcv(i,j) = tmpv(i2-1,j2) + tmpv(i2,j2)}
\DoxyCodeLine{324     dycv(i,j) = tmpu(i2-1,j2) + tmpu(i2-1,j2+1)}
\DoxyCodeLine{325 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{326 }
\DoxyCodeLine{327   \textcolor{keywordflow}{do} j=g\%JsdB,g\%JedB ; \textcolor{keywordflow}{do} i=g\%IsdB,g\%IedB ; i2 = 2*i ; j2 = 2*j}
\DoxyCodeLine{328     dxbu(i,j) = tmpv(i2,j2) + tmpv(i2+1,j2)}
\DoxyCodeLine{329     dybu(i,j) = tmpu(i2,j2) + tmpu(i2,j2+1)}
\DoxyCodeLine{330 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{331 }
\DoxyCodeLine{332   \textcolor{comment}{! Read AREA from the supergrid}}
\DoxyCodeLine{333   tmpt(:,:) = 0.}
\DoxyCodeLine{334   \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'area'}, tmpt, sgdom)}
\DoxyCodeLine{335   \textcolor{keyword}{call }pass\_var(tmpt, sgdom)}
\DoxyCodeLine{336   \textcolor{keyword}{call }extrapolate\_metric(tmpt, 2*(g\%jsc-g\%jsd)+2, missing=0.)}
\DoxyCodeLine{337 }
\DoxyCodeLine{338   \textcolor{keywordflow}{do} j=g\%jsd,g\%jed ; \textcolor{keywordflow}{do} i=g\%isd,g\%ied ; i2 = 2*i ; j2 = 2*j}
\DoxyCodeLine{339     areat(i,j) = (tmpt(i2-1,j2-1) + tmpt(i2,j2)) + \&}
\DoxyCodeLine{340                  (tmpt(i2-1,j2) + tmpt(i2,j2-1))}
\DoxyCodeLine{341 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{342   \textcolor{keywordflow}{do} j=g\%JsdB,g\%JedB ; \textcolor{keywordflow}{do} i=g\%IsdB,g\%IedB ; i2 = 2*i ; j2 = 2*j}
\DoxyCodeLine{343     areabu(i,j) = (tmpt(i2,j2) + tmpt(i2+1,j2+1)) + \&}
\DoxyCodeLine{344                   (tmpt(i2,j2+1) + tmpt(i2+1,j2))}
\DoxyCodeLine{345 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{346 }
\DoxyCodeLine{347   ni=sgdom\%niglobal}
\DoxyCodeLine{348   nj=sgdom\%njglobal}
\DoxyCodeLine{349   \textcolor{keyword}{call }mpp\_deallocate\_domain(sgdom\%mpp\_domain)}
\DoxyCodeLine{350   \textcolor{keyword}{deallocate}(sgdom\%mpp\_domain)}
\DoxyCodeLine{351 }
\DoxyCodeLine{352   \textcolor{keyword}{call }pass\_vector(dycu, dxcv, g\%Domain, to\_all+scalar\_pair, cgrid\_ne)}
\DoxyCodeLine{353   \textcolor{keyword}{call }pass\_vector(dxcu, dycv, g\%Domain, to\_all+scalar\_pair, cgrid\_ne)}
\DoxyCodeLine{354   \textcolor{keyword}{call }pass\_vector(dxbu, dybu, g\%Domain, to\_all+scalar\_pair, bgrid\_ne)}
\DoxyCodeLine{355   \textcolor{keyword}{call }pass\_var(areat, g\%Domain)}
\DoxyCodeLine{356   \textcolor{keyword}{call }pass\_var(areabu, g\%Domain, position=corner)}
\DoxyCodeLine{357 }
\DoxyCodeLine{358   \textcolor{keywordflow}{do} i=g\%isd,g\%ied ; \textcolor{keywordflow}{do} j=g\%jsd,g\%jed}
\DoxyCodeLine{359     g\%dxT(i,j) = m\_to\_l*dxt(i,j) ; g\%dyT(i,j) = m\_to\_l*dyt(i,j) ; g\%areaT(i,j) = m\_to\_l**2*areat(i,j)}
\DoxyCodeLine{360 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{361   \textcolor{keywordflow}{do} i=g\%IsdB,g\%IedB ; \textcolor{keywordflow}{do} j=g\%jsd,g\%jed}
\DoxyCodeLine{362     g\%dxCu(i,j) = m\_to\_l*dxcu(i,j) ; g\%dyCu(i,j) = m\_to\_l*dycu(i,j)}
\DoxyCodeLine{363 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{364   \textcolor{keywordflow}{do} i=g\%isd,g\%ied ; \textcolor{keywordflow}{do} j=g\%JsdB,g\%JedB}
\DoxyCodeLine{365     g\%dxCv(i,j) = m\_to\_l*dxcv(i,j) ; g\%dyCv(i,j) = m\_to\_l*dycv(i,j)}
\DoxyCodeLine{366 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{367   \textcolor{keywordflow}{do} i=g\%IsdB,g\%IedB ; \textcolor{keywordflow}{do} j=g\%JsdB,g\%JedB}
\DoxyCodeLine{368     g\%dxBu(i,j) = m\_to\_l*dxbu(i,j) ; g\%dyBu(i,j) = m\_to\_l*dybu(i,j) ; g\%areaBu(i,j) = m\_to\_l**2*areabu(i,j)}
\DoxyCodeLine{369 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{370 }
\DoxyCodeLine{371   \textcolor{comment}{! Construct axes for diagnostic output (only necessary because "ferret" uses}}
\DoxyCodeLine{372   \textcolor{comment}{! broken convention for interpretting netCDF files).}}
\DoxyCodeLine{373   start(:) = 1 ; nread(:) = 1}
\DoxyCodeLine{374   start(2) = 2 ; nread(1) = ni+1 ; nread(2) = 2}
\DoxyCodeLine{375   \textcolor{keyword}{allocate}( tmpglbl(ni+1,2) )}
\DoxyCodeLine{376   \textcolor{keywordflow}{if} (is\_root\_pe()) \&}
\DoxyCodeLine{377     \textcolor{keyword}{call }read\_data(filename, \textcolor{stringliteral}{"x"}, tmpglbl, start, nread, no\_domain=.true.)}
\DoxyCodeLine{378   \textcolor{keyword}{call }broadcast(tmpglbl, 2*(ni+1), root\_pe())}
\DoxyCodeLine{379 }
\DoxyCodeLine{380   \textcolor{comment}{! I don't know why the second axis is 1 or 2 here. -RWH}}
\DoxyCodeLine{381   \textcolor{keywordflow}{do} i=g\%isg,g\%ieg}
\DoxyCodeLine{382     g\%gridLonT(i) = tmpglbl(2*(i-g\%isg)+2,2)}
\DoxyCodeLine{383 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{384   \textcolor{comment}{! Note that the dynamic grid always uses symmetric memory for the global}}
\DoxyCodeLine{385   \textcolor{comment}{! arrays G\%gridLatB and G\%gridLonB.}}
\DoxyCodeLine{386   \textcolor{keywordflow}{do} i=g\%isg-1,g\%ieg}
\DoxyCodeLine{387     g\%gridLonB(i) = tmpglbl(2*(i-g\%isg)+3,1)}
\DoxyCodeLine{388 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{389   \textcolor{keyword}{deallocate}( tmpglbl )}
\DoxyCodeLine{390 }
\DoxyCodeLine{391   \textcolor{keyword}{allocate}( tmpglbl(1, nj+1) )}
\DoxyCodeLine{392   start(:) = 1 ; nread(:) = 1}
\DoxyCodeLine{393   start(1) = int(ni/4)+1 ; nread(2) = nj+1}
\DoxyCodeLine{394   \textcolor{keywordflow}{if} (is\_root\_pe()) \&}
\DoxyCodeLine{395     \textcolor{keyword}{call }read\_data(filename, \textcolor{stringliteral}{"y"}, tmpglbl, start, nread, no\_domain=.true.)}
\DoxyCodeLine{396   \textcolor{keyword}{call }broadcast(tmpglbl, nj+1, root\_pe())}
\DoxyCodeLine{397 }
\DoxyCodeLine{398   \textcolor{keywordflow}{do} j=g\%jsg,g\%jeg}
\DoxyCodeLine{399     g\%gridLatT(j) = tmpglbl(1,2*(j-g\%jsg)+2)}
\DoxyCodeLine{400 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{401   \textcolor{keywordflow}{do} j=g\%jsg-1,g\%jeg}
\DoxyCodeLine{402     g\%gridLatB(j) = tmpglbl(1,2*(j-g\%jsg)+3)}
\DoxyCodeLine{403 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{404   \textcolor{keyword}{deallocate}( tmpglbl )}
\DoxyCodeLine{405 }
\DoxyCodeLine{406   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"set\_grid\_metrics\_from\_mosaic()"})}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid__initialize_a3cc0b92a8624fbd5246576b4e5cf6f6f}\label{namespacemom__grid__initialize_a3cc0b92a8624fbd5246576b4e5cf6f6f}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!set\_grid\_metrics\_mercator@{set\_grid\_metrics\_mercator}}
\index{set\_grid\_metrics\_mercator@{set\_grid\_metrics\_mercator}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{set\_grid\_metrics\_mercator()}{set\_grid\_metrics\_mercator()}}
{\footnotesize\ttfamily subroutine mom\+\_\+grid\+\_\+initialize\+::set\+\_\+grid\+\_\+metrics\+\_\+mercator (\begin{DoxyParamCaption}\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(inout)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in), optional}]{US }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculate the values of the metric terms that might be used and save them in arrays. 

Within this subroutine, the x-\/ and y-\/ grid spacings and their inverses and the cell areas centered on h, q, u, and v points are calculated, as are the geographic locations of each of these 4 sets of points. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The dynamic horizontal grid type \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & Parameter file structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\end{DoxyParams}


Definition at line 697 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{697   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{           !< The dynamic horizontal grid type}}
\DoxyCodeLine{698   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)}     :: param\_file\textcolor{comment}{  !< Parameter file structure}}
\DoxyCodeLine{699   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{    !< A dimensional unit scaling type}}
\DoxyCodeLine{700   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{701   \textcolor{keywordtype}{integer} :: i, j, isd, ied, jsd, jed}
\DoxyCodeLine{702   \textcolor{keywordtype}{integer} :: I\_off, J\_off}
\DoxyCodeLine{703   \textcolor{keywordtype}{type}(GPS) :: GP}
\DoxyCodeLine{704   \textcolor{keywordtype}{character(len=128)} :: warnmesg}
\DoxyCodeLine{705   \textcolor{keywordtype}{character(len=48)}  :: mdl = \textcolor{stringliteral}{"MOM\_grid\_init set\_grid\_metrics\_mercator"}}
\DoxyCodeLine{706 \textcolor{keywordtype}{  real} :: PI, PI\_2\textcolor{comment}{! PI = 3.1415926... as 4*atan(1), PI\_2 = (PI) /2.0}}
\DoxyCodeLine{707 \textcolor{keywordtype}{  real} :: y\_q, y\_h, jd, x\_q, x\_h, id}
\DoxyCodeLine{708 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%jsd:G\%jed)} :: \&}
\DoxyCodeLine{709     xh, yh \textcolor{comment}{! Latitude and longitude of h points in radians.}}
\DoxyCodeLine{710 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%IsdB:G\%IedB,G\%jsd:G\%jed)} :: \&}
\DoxyCodeLine{711     xu, yu \textcolor{comment}{! Latitude and longitude of u points in radians.}}
\DoxyCodeLine{712 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isd:G\%ied,G\%JsdB:G\%JedB)} :: \&}
\DoxyCodeLine{713     xv, yv \textcolor{comment}{! Latitude and longitude of v points in radians.}}
\DoxyCodeLine{714 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%IsdB:G\%IedB,G\%JsdB:G\%JedB)} :: \&}
\DoxyCodeLine{715     xq, yq \textcolor{comment}{! Latitude and longitude of q points in radians.}}
\DoxyCodeLine{716 \textcolor{keywordtype}{  real} :: fnRef           \textcolor{comment}{! fnRef is the value of Int\_dj\_dy or}}
\DoxyCodeLine{717                           \textcolor{comment}{! Int\_dj\_dy at a latitude or longitude that is}}
\DoxyCodeLine{718 \textcolor{keywordtype}{  real} :: jRef, iRef      \textcolor{comment}{! being set to be at grid index jRef or iRef.}}
\DoxyCodeLine{719 \textcolor{keywordtype}{  real} :: m\_to\_L  \textcolor{comment}{! A unit conversion factor [L m-1 ~> nondim]}}
\DoxyCodeLine{720   \textcolor{keywordtype}{integer} :: itt1, itt2}
\DoxyCodeLine{721   \textcolor{keywordtype}{logical} :: debug = .false., simple\_area = .true.}
\DoxyCodeLine{722   \textcolor{keywordtype}{integer} :: is, ie, js, je, Isq, Ieq, Jsq, Jeq, IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{723 }
\DoxyCodeLine{724   \textcolor{comment}{!   All of the metric terms should be defined over the domain from}}
\DoxyCodeLine{725   \textcolor{comment}{! isd to ied.  Outside of the physical domain, both the metrics}}
\DoxyCodeLine{726   \textcolor{comment}{! and their inverses may be set to zero.}}
\DoxyCodeLine{727   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{728   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{729   isq = g\%IscB ; ieq = g\%IecB ; jsq = g\%JscB ; jeq = g\%JecB}
\DoxyCodeLine{730   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{731   i\_off = g\%idg\_offset ; j\_off = g\%jdg\_offset}
\DoxyCodeLine{732 }
\DoxyCodeLine{733   gp\%niglobal = g\%Domain\%niglobal}
\DoxyCodeLine{734   gp\%njglobal = g\%Domain\%njglobal}
\DoxyCodeLine{735 }
\DoxyCodeLine{736   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"set\_grid\_metrics\_mercator(), MOM\_grid\_initialize.F90"})}
\DoxyCodeLine{737 }
\DoxyCodeLine{738   m\_to\_l = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) m\_to\_l = us\%m\_to\_L}
\DoxyCodeLine{739   \textcolor{comment}{!   Calculate the values of the metric terms that might be used}}
\DoxyCodeLine{740   \textcolor{comment}{! and save them in arrays.}}
\DoxyCodeLine{741   pi = 4.0*atan(1.0) ; pi\_2 = 0.5*pi}
\DoxyCodeLine{742 }
\DoxyCodeLine{743   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SOUTHLAT"}, gp\%south\_lat, \&}
\DoxyCodeLine{744                  \textcolor{stringliteral}{"The southern latitude of the domain."}, units=\textcolor{stringliteral}{"degrees"}, \&}
\DoxyCodeLine{745                  fail\_if\_missing=.true.)}
\DoxyCodeLine{746   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LENLAT"}, gp\%len\_lat, \&}
\DoxyCodeLine{747                  \textcolor{stringliteral}{"The latitudinal length of the domain."}, units=\textcolor{stringliteral}{"degrees"}, \&}
\DoxyCodeLine{748                  fail\_if\_missing=.true.)}
\DoxyCodeLine{749   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"WESTLON"}, gp\%west\_lon, \&}
\DoxyCodeLine{750                  \textcolor{stringliteral}{"The western longitude of the domain."}, units=\textcolor{stringliteral}{"degrees"}, \&}
\DoxyCodeLine{751                  default=0.0)}
\DoxyCodeLine{752   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LENLON"}, gp\%len\_lon, \&}
\DoxyCodeLine{753                  \textcolor{stringliteral}{"The longitudinal length of the domain."}, units=\textcolor{stringliteral}{"degrees"}, \&}
\DoxyCodeLine{754                  fail\_if\_missing=.true.)}
\DoxyCodeLine{755   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RAD\_EARTH"}, gp\%Rad\_Earth, \&}
\DoxyCodeLine{756                  \textcolor{stringliteral}{"The radius of the Earth."}, units=\textcolor{stringliteral}{"m"}, default=6.378e6)}
\DoxyCodeLine{757   g\%south\_lat = gp\%south\_lat ; g\%len\_lat = gp\%len\_lat}
\DoxyCodeLine{758   g\%west\_lon = gp\%west\_lon ; g\%len\_lon = gp\%len\_lon}
\DoxyCodeLine{759   g\%Rad\_Earth = gp\%Rad\_Earth}
\DoxyCodeLine{760   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ISOTROPIC"}, gp\%isotropic, \&}
\DoxyCodeLine{761                  \textcolor{stringliteral}{"If true, an isotropic grid on a sphere (also known as "}//\&}
\DoxyCodeLine{762                  \textcolor{stringliteral}{"a Mercator grid) is used. With an isotropic grid, the "}//\&}
\DoxyCodeLine{763                  \textcolor{stringliteral}{"meridional extent of the domain (LENLAT), the zonal "}//\&}
\DoxyCodeLine{764                  \textcolor{stringliteral}{"extent (LENLON), and the number of grid points in each "}//\&}
\DoxyCodeLine{765                  \textcolor{stringliteral}{"direction are \_not\_ independent. In MOM the meridional "}//\&}
\DoxyCodeLine{766                  \textcolor{stringliteral}{"extent is determined to fit the zonal extent and the "}//\&}
\DoxyCodeLine{767                  \textcolor{stringliteral}{"number of grid points, while grid is perfectly isotropic."}, \&}
\DoxyCodeLine{768                  default=.false.)}
\DoxyCodeLine{769   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"EQUATOR\_REFERENCE"}, gp\%equator\_reference, \&}
\DoxyCodeLine{770                  \textcolor{stringliteral}{"If true, the grid is defined to have the equator at the "}//\&}
\DoxyCodeLine{771                  \textcolor{stringliteral}{"nearest q- or h- grid point to (-LOWLAT*NJGLOBAL/LENLAT)."}, \&}
\DoxyCodeLine{772                  default=.true.)}
\DoxyCodeLine{773   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LAT\_ENHANCE\_FACTOR"}, gp\%Lat\_enhance\_factor, \&}
\DoxyCodeLine{774                  \textcolor{stringliteral}{"The amount by which the meridional resolution is "}//\&}
\DoxyCodeLine{775                  \textcolor{stringliteral}{"enhanced within LAT\_EQ\_ENHANCE of the equator."}, \&}
\DoxyCodeLine{776                  units=\textcolor{stringliteral}{"nondim"}, default=1.0)}
\DoxyCodeLine{777   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LAT\_EQ\_ENHANCE"}, gp\%Lat\_eq\_enhance, \&}
\DoxyCodeLine{778                  \textcolor{stringliteral}{"The latitude range to the north and south of the equator "}//\&}
\DoxyCodeLine{779                  \textcolor{stringliteral}{"over which the resolution is enhanced."}, units=\textcolor{stringliteral}{"degrees"}, \&}
\DoxyCodeLine{780                  default=0.0)}
\DoxyCodeLine{781 }
\DoxyCodeLine{782   \textcolor{comment}{!   With an isotropic grid, the north-south extent of the domain,}}
\DoxyCodeLine{783   \textcolor{comment}{! the east-west extent, and the number of grid points in each}}
\DoxyCodeLine{784   \textcolor{comment}{! direction are \_not\_ independent.  Here the north-south extent}}
\DoxyCodeLine{785   \textcolor{comment}{! will be determined to fit the east-west extent and the number of}}
\DoxyCodeLine{786   \textcolor{comment}{! grid points.  The grid is perfectly isotropic.}}
\DoxyCodeLine{787   \textcolor{keywordflow}{if} (gp\%equator\_reference) \textcolor{keywordflow}{then}}
\DoxyCodeLine{788     \textcolor{comment}{! With the following expression, the equator will always be placed}}
\DoxyCodeLine{789     \textcolor{comment}{! on either h or q points, in a position consistent with the ratio}}
\DoxyCodeLine{790     \textcolor{comment}{! GP\%south\_lat to GP\%len\_lat.}}
\DoxyCodeLine{791     jref =  (g\%jsg-1) + 0.5*floor(gp\%njglobal*((-1.0*gp\%south\_lat*2.0)/gp\%len\_lat)+0.5)}
\DoxyCodeLine{792     fnref = int\_dj\_dy(0.0, gp)}
\DoxyCodeLine{793   \textcolor{keywordflow}{else}}
\DoxyCodeLine{794     \textcolor{comment}{! The following line sets the reference latitude GP\%south\_lat at j=js-1 (or -2?)}}
\DoxyCodeLine{795     jref = (g\%jsg-1)}
\DoxyCodeLine{796     fnref = int\_dj\_dy((gp\%south\_lat*pi/180.0), gp)}
\DoxyCodeLine{797 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{798 }
\DoxyCodeLine{799   \textcolor{comment}{! These calculations no longer depend on the the order in which they}}
\DoxyCodeLine{800   \textcolor{comment}{! are performed because they all use the same (poor) starting guess and}}
\DoxyCodeLine{801   \textcolor{comment}{! iterate to convergence.}}
\DoxyCodeLine{802   \textcolor{comment}{! Note that the dynamic grid always uses symmetric memory for the global}}
\DoxyCodeLine{803   \textcolor{comment}{! arrays G\%gridLatB and G\%gridLonB.}}
\DoxyCodeLine{804   \textcolor{keywordflow}{do} j=g\%jsg-1,g\%jeg}
\DoxyCodeLine{805     jd = fnref + (j - jref)}
\DoxyCodeLine{806     y\_q = find\_root(int\_dj\_dy, dy\_dj, gp, jd, 0.0, -1.0*pi\_2, pi\_2, itt2)}
\DoxyCodeLine{807     g\%gridLatB(j) = y\_q*180.0/pi}
\DoxyCodeLine{808     \textcolor{comment}{! if (is\_root\_pe()) \&}}
\DoxyCodeLine{809     \textcolor{comment}{!   write(*, '("J, y\_q = ",I4,ES14.4," itts = ",I4)')  j, y\_q, itt2}}
\DoxyCodeLine{810 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{811   \textcolor{keywordflow}{do} j=g\%jsg,g\%jeg}
\DoxyCodeLine{812     jd = fnref + (j - jref) - 0.5}
\DoxyCodeLine{813     y\_h = find\_root(int\_dj\_dy, dy\_dj, gp, jd, 0.0, -1.0*pi\_2, pi\_2, itt1)}
\DoxyCodeLine{814     g\%gridLatT(j) = y\_h*180.0/pi}
\DoxyCodeLine{815     \textcolor{comment}{! if (is\_root\_pe()) \&}}
\DoxyCodeLine{816     \textcolor{comment}{!   write(*, '("j, y\_h = ",I4,ES14.4," itts = ",I4)')  j, y\_h, itt1}}
\DoxyCodeLine{817 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{818   \textcolor{keywordflow}{do} j=jsdb+j\_off,jedb+j\_off}
\DoxyCodeLine{819     jd = fnref + (j - jref)}
\DoxyCodeLine{820     y\_q = find\_root(int\_dj\_dy, dy\_dj, gp, jd, 0.0, -1.0*pi\_2, pi\_2, itt2)}
\DoxyCodeLine{821     \textcolor{keywordflow}{do} i=isdb,iedb ; yq(i,j-j\_off) = y\_q ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{822     \textcolor{keywordflow}{do} i=isd,ied ; yv(i,j-j\_off) = y\_q ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{823 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{824   \textcolor{keywordflow}{do} j=jsd+j\_off,jed+j\_off}
\DoxyCodeLine{825     jd = fnref + (j - jref) - 0.5}
\DoxyCodeLine{826     y\_h = find\_root(int\_dj\_dy, dy\_dj, gp, jd, 0.0, -1.0*pi\_2, pi\_2, itt1)}
\DoxyCodeLine{827     \textcolor{keywordflow}{if} ((j >= jsd+j\_off) .and. (j <= jed+j\_off)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{828       \textcolor{keywordflow}{do} i=isd,ied ; yh(i,j-j\_off) = y\_h ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{829       \textcolor{keywordflow}{do} i=isdb,iedb ; yu(i,j-j\_off) = y\_h ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{830 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{831 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{832 }
\DoxyCodeLine{833   \textcolor{comment}{! Determine the longitudes of the various points.}}
\DoxyCodeLine{834 }
\DoxyCodeLine{835   \textcolor{comment}{! These two lines place the western edge of the domain at GP\%west\_lon.}}
\DoxyCodeLine{836   iref = (g\%isg-1) + gp\%niglobal}
\DoxyCodeLine{837   fnref = int\_di\_dx(((gp\%west\_lon+gp\%len\_lon)*pi/180.0), gp)}
\DoxyCodeLine{838 }
\DoxyCodeLine{839   \textcolor{comment}{! These calculations no longer depend on the the order in which they}}
\DoxyCodeLine{840   \textcolor{comment}{! are performed because they all use the same (poor) starting guess and}}
\DoxyCodeLine{841   \textcolor{comment}{! iterate to convergence.}}
\DoxyCodeLine{842   \textcolor{keywordflow}{do} i=g\%isg-1,g\%ieg}
\DoxyCodeLine{843     id = fnref + (i - iref)}
\DoxyCodeLine{844     x\_q = find\_root(int\_di\_dx, dx\_di, gp, id, 0.0, -4.0*pi, 4.0*pi, itt2)}
\DoxyCodeLine{845     g\%gridLonB(i) = x\_q*180.0/pi}
\DoxyCodeLine{846 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{847   \textcolor{keywordflow}{do} i=g\%isg,g\%ieg}
\DoxyCodeLine{848     id = fnref + (i - iref) - 0.5}
\DoxyCodeLine{849     x\_h = find\_root(int\_di\_dx, dx\_di, gp, id, 0.0, -4.0*pi, 4.0*pi, itt1)}
\DoxyCodeLine{850     g\%gridLonT(i) = x\_h*180.0/pi}
\DoxyCodeLine{851 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{852   \textcolor{keywordflow}{do} i=isdb+i\_off,iedb+i\_off}
\DoxyCodeLine{853     id = fnref + (i - iref)}
\DoxyCodeLine{854     x\_q = find\_root(int\_di\_dx, dx\_di, gp, id, 0.0, -4.0*pi, 4.0*pi, itt2)}
\DoxyCodeLine{855     \textcolor{keywordflow}{do} j=jsdb,jedb ; xq(i-i\_off,j) = x\_q ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{856     \textcolor{keywordflow}{do} j=jsd,jed ; xu(i-i\_off,j) = x\_q ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{857 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{858   \textcolor{keywordflow}{do} i=isd+i\_off,ied+i\_off}
\DoxyCodeLine{859     id = fnref + (i - iref) - 0.5}
\DoxyCodeLine{860     x\_h = find\_root(int\_di\_dx, dx\_di, gp, id, 0.0, -4.0*pi, 4.0*pi, itt1)}
\DoxyCodeLine{861     \textcolor{keywordflow}{do} j=jsd,jed ; xh(i-i\_off,j) = x\_h ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{862     \textcolor{keywordflow}{do} j=jsdb,jedb ; xv(i-i\_off,j) = x\_h ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{863 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{864 }
\DoxyCodeLine{865   \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isdb,iedb}
\DoxyCodeLine{866     g\%geoLonBu(i,j) = xq(i,j)*180.0/pi}
\DoxyCodeLine{867     g\%geoLatBu(i,j) = yq(i,j)*180.0/pi}
\DoxyCodeLine{868     g\%dxBu(i,j) = m\_to\_l*ds\_di(xq(i,j), yq(i,j), gp)}
\DoxyCodeLine{869     g\%dyBu(i,j) = m\_to\_l*ds\_dj(xq(i,j), yq(i,j), gp)}
\DoxyCodeLine{870 }
\DoxyCodeLine{871     g\%areaBu(i,j) = g\%dxBu(i,j) * g\%dyBu(i,j)}
\DoxyCodeLine{872     g\%IareaBu(i,j) = 1.0 / (g\%areaBu(i,j))}
\DoxyCodeLine{873 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{874 }
\DoxyCodeLine{875   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{876     g\%geoLonT(i,j) = xh(i,j)*180.0/pi}
\DoxyCodeLine{877     g\%geoLatT(i,j) = yh(i,j)*180.0/pi}
\DoxyCodeLine{878     g\%dxT(i,j) = m\_to\_l*ds\_di(xh(i,j), yh(i,j), gp)}
\DoxyCodeLine{879     g\%dyT(i,j) = m\_to\_l*ds\_dj(xh(i,j), yh(i,j), gp)}
\DoxyCodeLine{880 }
\DoxyCodeLine{881     g\%areaT(i,j) = g\%dxT(i,j)*g\%dyT(i,j)}
\DoxyCodeLine{882     g\%IareaT(i,j) = 1.0 / (g\%areaT(i,j))}
\DoxyCodeLine{883 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{884 }
\DoxyCodeLine{885   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb}
\DoxyCodeLine{886     g\%geoLonCu(i,j) = xu(i,j)*180.0/pi}
\DoxyCodeLine{887     g\%geoLatCu(i,j) = yu(i,j)*180.0/pi}
\DoxyCodeLine{888     g\%dxCu(i,j) = m\_to\_l*ds\_di(xu(i,j), yu(i,j), gp)}
\DoxyCodeLine{889     g\%dyCu(i,j) = m\_to\_l*ds\_dj(xu(i,j), yu(i,j), gp)}
\DoxyCodeLine{890 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{891 }
\DoxyCodeLine{892   \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{893     g\%geoLonCv(i,j) = xv(i,j)*180.0/pi}
\DoxyCodeLine{894     g\%geoLatCv(i,j) = yv(i,j)*180.0/pi}
\DoxyCodeLine{895     g\%dxCv(i,j) = m\_to\_l*ds\_di(xv(i,j), yv(i,j), gp)}
\DoxyCodeLine{896     g\%dyCv(i,j) = m\_to\_l*ds\_dj(xv(i,j), yv(i,j), gp)}
\DoxyCodeLine{897 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{898 }
\DoxyCodeLine{899   \textcolor{keywordflow}{if} (.not.simple\_area) \textcolor{keywordflow}{then}}
\DoxyCodeLine{900     \textcolor{keywordflow}{do} j=jsdb+1,jed ; \textcolor{keywordflow}{do} i=isdb+1,ied}
\DoxyCodeLine{901       g\%areaT(i,j) = m\_to\_l**2*gp\%Rad\_Earth**2 * \&}
\DoxyCodeLine{902           (dl(xq(i-1,j-1),xq(i-1,j),yq(i-1,j-1),yq(i-1,j)) + \&}
\DoxyCodeLine{903           (dl(xq(i-1,j),xq(i,j),yq(i-1,j),yq(i,j)) +          \&}
\DoxyCodeLine{904           (dl(xq(i,j),xq(i,j-1),yq(i,j),yq(i,j-1)) +          \&}
\DoxyCodeLine{905            dl(xq(i,j-1),xq(i-1,j-1),yq(i,j-1),yq(i-1,j-1)))))}
\DoxyCodeLine{906 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{enddo}}
\DoxyCodeLine{907     \textcolor{keywordflow}{if} ((isdb == isd) .or. (jsdb == jsq)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{908       \textcolor{comment}{! Fill in row and column 1 to calculate the area in the southernmost}}
\DoxyCodeLine{909       \textcolor{comment}{! and westernmost land cells when we are not using symmetric memory.}}
\DoxyCodeLine{910       \textcolor{comment}{! The pass\_var call updates these values if they are not land cells.}}
\DoxyCodeLine{911       g\%areaT(isd+1,jsd) = g\%areaT(isd+1,jsd+1)}
\DoxyCodeLine{912       \textcolor{keywordflow}{do} j=jsd,jed ; g\%areaT(isd,j) = g\%areaT(isd+1,j) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{913       \textcolor{keywordflow}{do} i=isd,ied ; g\%areaT(i,jsd) = g\%areaT(i,jsd+1) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{914       \textcolor{comment}{! Now replace the data in the halos, if value values exist.}}
\DoxyCodeLine{915       \textcolor{keyword}{call }pass\_var(g\%areaT,g\%Domain)}
\DoxyCodeLine{916 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{917     \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{918       g\%IareaT(i,j) = 1.0 / (g\%areaT(i,j))}
\DoxyCodeLine{919 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{920 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{921 }
\DoxyCodeLine{922   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"set\_grid\_metrics\_mercator()"})}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid__initialize_a7c37b75811701cbca250a34359e44a4a}\label{namespacemom__grid__initialize_a7c37b75811701cbca250a34359e44a4a}} 
\index{mom\_grid\_initialize@{mom\_grid\_initialize}!set\_grid\_metrics\_spherical@{set\_grid\_metrics\_spherical}}
\index{set\_grid\_metrics\_spherical@{set\_grid\_metrics\_spherical}!mom\_grid\_initialize@{mom\_grid\_initialize}}
\subsubsection{\texorpdfstring{set\_grid\_metrics\_spherical()}{set\_grid\_metrics\_spherical()}}
{\footnotesize\ttfamily subroutine mom\+\_\+grid\+\_\+initialize\+::set\+\_\+grid\+\_\+metrics\+\_\+spherical (\begin{DoxyParamCaption}\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(inout)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in), optional}]{US }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculate the values of the metric terms that might be used and save them in arrays. 

Within this subroutine, the x-\/ and y-\/ grid spacings and their inverses and the cell areas centered on h, q, u, and v points are calculated, as are the geographic locations of each of these 4 sets of points. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The dynamic horizontal grid type \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & Parameter file structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\end{DoxyParams}


Definition at line 558 of file M\+O\+M\+\_\+grid\+\_\+initialize.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{558   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{           !< The dynamic horizontal grid type}}
\DoxyCodeLine{559   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)}     :: param\_file\textcolor{comment}{  !< Parameter file structure}}
\DoxyCodeLine{560   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{    !< A dimensional unit scaling type}}
\DoxyCodeLine{561   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{562 \textcolor{keywordtype}{  real} :: PI, PI\_180\textcolor{comment}{! PI = 3.1415926... as 4*atan(1)}}
\DoxyCodeLine{563   \textcolor{keywordtype}{integer} :: i, j, isd, ied, jsd, jed}
\DoxyCodeLine{564   \textcolor{keywordtype}{integer} :: is, ie, js, je, Isq, Ieq, Jsq, Jeq, IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{565   \textcolor{keywordtype}{integer} :: i\_offset, j\_offset}
\DoxyCodeLine{566 \textcolor{keywordtype}{  real} :: grid\_latT(G\%jsd:G\%jed), grid\_latB(G\%JsdB:G\%JedB)}
\DoxyCodeLine{567 \textcolor{keywordtype}{  real} :: grid\_lonT(G\%isd:G\%ied), grid\_lonB(G\%IsdB:G\%IedB)}
\DoxyCodeLine{568 \textcolor{keywordtype}{  real} :: dLon,dLat,latitude,longitude,dL\_di}
\DoxyCodeLine{569 \textcolor{keywordtype}{  real} :: m\_to\_L  \textcolor{comment}{! A unit conversion factor [L m-1 ~> nondim]}}
\DoxyCodeLine{570   \textcolor{keywordtype}{character(len=48)}  :: mdl  = \textcolor{stringliteral}{"MOM\_grid\_init set\_grid\_metrics\_spherical"}}
\DoxyCodeLine{571 }
\DoxyCodeLine{572   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{573   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{574   isq = g\%IscB ; ieq = g\%IecB ; jsq = g\%JscB ; jeq = g\%JecB}
\DoxyCodeLine{575   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{576   i\_offset = g\%idg\_offset ; j\_offset = g\%jdg\_offset}
\DoxyCodeLine{577 }
\DoxyCodeLine{578   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"set\_grid\_metrics\_spherical(), MOM\_grid\_initialize.F90"})}
\DoxyCodeLine{579   m\_to\_l = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) m\_to\_l = us\%m\_to\_L}
\DoxyCodeLine{580 }
\DoxyCodeLine{581 \textcolor{comment}{!    Calculate the values of the metric terms that might be used}}
\DoxyCodeLine{582 \textcolor{comment}{!  and save them in arrays.}}
\DoxyCodeLine{583   pi = 4.0*atan(1.0); pi\_180 = atan(1.0)/45.}
\DoxyCodeLine{584 }
\DoxyCodeLine{585   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SOUTHLAT"}, g\%south\_lat, \&}
\DoxyCodeLine{586                  \textcolor{stringliteral}{"The southern latitude of the domain."}, units=\textcolor{stringliteral}{"degrees"}, \&}
\DoxyCodeLine{587                  fail\_if\_missing=.true.)}
\DoxyCodeLine{588   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LENLAT"}, g\%len\_lat, \&}
\DoxyCodeLine{589                  \textcolor{stringliteral}{"The latitudinal length of the domain."}, units=\textcolor{stringliteral}{"degrees"}, \&}
\DoxyCodeLine{590                  fail\_if\_missing=.true.)}
\DoxyCodeLine{591   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"WESTLON"}, g\%west\_lon, \&}
\DoxyCodeLine{592                  \textcolor{stringliteral}{"The western longitude of the domain."}, units=\textcolor{stringliteral}{"degrees"}, \&}
\DoxyCodeLine{593                  default=0.0)}
\DoxyCodeLine{594   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LENLON"}, g\%len\_lon, \&}
\DoxyCodeLine{595                  \textcolor{stringliteral}{"The longitudinal length of the domain."}, units=\textcolor{stringliteral}{"degrees"}, \&}
\DoxyCodeLine{596                  fail\_if\_missing=.true.)}
\DoxyCodeLine{597   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RAD\_EARTH"}, g\%Rad\_Earth, \&}
\DoxyCodeLine{598                  \textcolor{stringliteral}{"The radius of the Earth."}, units=\textcolor{stringliteral}{"m"}, default=6.378e6)}
\DoxyCodeLine{599 }
\DoxyCodeLine{600   dlon = g\%len\_lon/g\%Domain\%niglobal}
\DoxyCodeLine{601   dlat = g\%len\_lat/g\%Domain\%njglobal}
\DoxyCodeLine{602 }
\DoxyCodeLine{603   \textcolor{comment}{! Note that the dynamic grid always uses symmetric memory for the global}}
\DoxyCodeLine{604   \textcolor{comment}{! arrays G\%gridLatB and G\%gridLonB.}}
\DoxyCodeLine{605   \textcolor{keywordflow}{do} j=g\%jsg-1,g\%jeg}
\DoxyCodeLine{606     latitude = g\%south\_lat + dlat*(real(j-(g\%jsg-1)))}
\DoxyCodeLine{607     g\%gridLatB(j) = min(max(latitude,-90.),90.)}
\DoxyCodeLine{608 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{609   \textcolor{keywordflow}{do} j=g\%jsg,g\%jeg}
\DoxyCodeLine{610     latitude = g\%south\_lat + dlat*(real(j-g\%jsg)+0.5)}
\DoxyCodeLine{611     g\%gridLatT(j) = min(max(latitude,-90.),90.)}
\DoxyCodeLine{612 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{613   \textcolor{keywordflow}{do} i=g\%isg-1,g\%ieg}
\DoxyCodeLine{614     g\%gridLonB(i) = g\%west\_lon + dlon*(real(i-(g\%isg-1)))}
\DoxyCodeLine{615 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{616   \textcolor{keywordflow}{do} i=g\%isg,g\%ieg}
\DoxyCodeLine{617     g\%gridLonT(i) = g\%west\_lon + dlon*(real(i-g\%isg)+0.5)}
\DoxyCodeLine{618 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{619 }
\DoxyCodeLine{620   \textcolor{keywordflow}{do} j=jsdb,jedb}
\DoxyCodeLine{621     latitude = g\%south\_lat + dlat* real(j+j\_offset-(g\%jsg-1))}
\DoxyCodeLine{622     grid\_latb(j) = min(max(latitude,-90.),90.)}
\DoxyCodeLine{623 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{624   \textcolor{keywordflow}{do} j=jsd,jed}
\DoxyCodeLine{625     latitude = g\%south\_lat + dlat*(real(j+j\_offset-g\%jsg)+0.5)}
\DoxyCodeLine{626     grid\_latt(j) = min(max(latitude,-90.),90.)}
\DoxyCodeLine{627 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{628   \textcolor{keywordflow}{do} i=isdb,iedb}
\DoxyCodeLine{629     grid\_lonb(i) = g\%west\_lon + dlon*real(i+i\_offset-(g\%isg-1))}
\DoxyCodeLine{630 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{631   \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{632     grid\_lont(i) = g\%west\_lon + dlon*(real(i+i\_offset-g\%isg)+0.5)}
\DoxyCodeLine{633 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{634 }
\DoxyCodeLine{635   dl\_di = (g\%len\_lon * 4.0*atan(1.0)) / (180.0 * g\%Domain\%niglobal)}
\DoxyCodeLine{636   \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isdb,iedb}
\DoxyCodeLine{637     g\%geoLonBu(i,j) = grid\_lonb(i)}
\DoxyCodeLine{638     g\%geoLatBu(i,j) = grid\_latb(j)}
\DoxyCodeLine{639 }
\DoxyCodeLine{640     \textcolor{comment}{! The following line is needed to reproduce the solution from}}
\DoxyCodeLine{641     \textcolor{comment}{! set\_grid\_metrics\_mercator when used to generate a simple spherical grid.}}
\DoxyCodeLine{642     g\%dxBu(i,j) = m\_to\_l*g\%Rad\_Earth * cos( g\%geoLatBu(i,j)*pi\_180 ) * dl\_di}
\DoxyCodeLine{643 \textcolor{comment}{!   G\%dxBu(I,J) = m\_to\_L*G\%Rad\_Earth * dLon*PI\_180 * COS( G\%geoLatBu(I,J)*PI\_180 )}}
\DoxyCodeLine{644     g\%dyBu(i,j) = m\_to\_l*g\%Rad\_Earth * dlat*pi\_180}
\DoxyCodeLine{645     g\%areaBu(i,j) = g\%dxBu(i,j) * g\%dyBu(i,j)}
\DoxyCodeLine{646 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{647 }
\DoxyCodeLine{648   \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{649     g\%geoLonCv(i,j) = grid\_lont(i)}
\DoxyCodeLine{650     g\%geoLatCv(i,j) = grid\_latb(j)}
\DoxyCodeLine{651 }
\DoxyCodeLine{652     \textcolor{comment}{! The following line is needed to reproduce the solution from}}
\DoxyCodeLine{653     \textcolor{comment}{! set\_grid\_metrics\_mercator when used to generate a simple spherical grid.}}
\DoxyCodeLine{654     g\%dxCv(i,j) = m\_to\_l*g\%Rad\_Earth * cos( g\%geoLatCv(i,j)*pi\_180 ) * dl\_di}
\DoxyCodeLine{655 \textcolor{comment}{!   G\%dxCv(i,J) = m\_to\_L*G\%Rad\_Earth * (dLon*PI\_180) * COS( G\%geoLatCv(i,J)*PI\_180 )}}
\DoxyCodeLine{656     g\%dyCv(i,j) = m\_to\_l*g\%Rad\_Earth * dlat*pi\_180}
\DoxyCodeLine{657 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{658 }
\DoxyCodeLine{659   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb}
\DoxyCodeLine{660     g\%geoLonCu(i,j) = grid\_lonb(i)}
\DoxyCodeLine{661     g\%geoLatCu(i,j) = grid\_latt(j)}
\DoxyCodeLine{662 }
\DoxyCodeLine{663     \textcolor{comment}{! The following line is needed to reproduce the solution from}}
\DoxyCodeLine{664     \textcolor{comment}{! set\_grid\_metrics\_mercator when used to generate a simple spherical grid.}}
\DoxyCodeLine{665     g\%dxCu(i,j) = m\_to\_l*g\%Rad\_Earth * cos( g\%geoLatCu(i,j)*pi\_180 ) * dl\_di}
\DoxyCodeLine{666 \textcolor{comment}{!   G\%dxCu(I,j) = m\_to\_L*G\%Rad\_Earth * dLon*PI\_180 * COS( latitude )}}
\DoxyCodeLine{667     g\%dyCu(i,j) = m\_to\_l*g\%Rad\_Earth * dlat*pi\_180}
\DoxyCodeLine{668 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{669 }
\DoxyCodeLine{670   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{671     g\%geoLonT(i,j) = grid\_lont(i)}
\DoxyCodeLine{672     g\%geoLatT(i,j) = grid\_latt(j)}
\DoxyCodeLine{673 }
\DoxyCodeLine{674     \textcolor{comment}{! The following line is needed to reproduce the solution from}}
\DoxyCodeLine{675     \textcolor{comment}{! set\_grid\_metrics\_mercator when used to generate a simple spherical grid.}}
\DoxyCodeLine{676     g\%dxT(i,j) = m\_to\_l*g\%Rad\_Earth * cos( g\%geoLatT(i,j)*pi\_180 ) * dl\_di}
\DoxyCodeLine{677 \textcolor{comment}{!   G\%dxT(i,j) = G\%Rad\_Earth * dLon*PI\_180 * COS( latitude )}}
\DoxyCodeLine{678     g\%dyT(i,j) = m\_to\_l*g\%Rad\_Earth * dlat*pi\_180}
\DoxyCodeLine{679 }
\DoxyCodeLine{680 \textcolor{comment}{!   latitude = G\%geoLatCv(i,J)*PI\_180             ! In radians}}
\DoxyCodeLine{681 \textcolor{comment}{!   dL\_di    = G\%geoLatCv(i,max(jsd,J-1))*PI\_180  ! In radians}}
\DoxyCodeLine{682 \textcolor{comment}{!   G\%areaT(i,j) = m\_to\_L**2 * Rad\_Earth**2*dLon*dLat*ABS(SIN(latitude)-SIN(dL\_di))}}
\DoxyCodeLine{683     g\%areaT(i,j) = g\%dxT(i,j) * g\%dyT(i,j)}
\DoxyCodeLine{684 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{685 }
\DoxyCodeLine{686   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"set\_grid\_metrics\_spherical()"})}

\end{DoxyCode}
