\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{\tt 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}
1221   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: val\textcolor{comment}{  !< The value being inverted.}
1222   \textcolor{keywordtype}{real} :: I\_val\textcolor{comment}{            !< The Adcroft reciprocal of val.}
1223 
1224   i\_val = 0.0
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{\tt in}  & {\em x1} & Segment starting longitude, in degrees E.\\
\hline
\mbox{\tt in}  & {\em x2} & Segment ending longitude, in degrees E.\\
\hline
\mbox{\tt in}  & {\em y1} & Segment ending latitude, in degrees N.\\
\hline
\mbox{\tt 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}
958   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: x1\textcolor{comment}{ !< Segment starting longitude, in degrees E.}
959   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: x2\textcolor{comment}{ !< Segment ending longitude, in degrees E.}
960   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: y1\textcolor{comment}{ !< Segment ending latitude, in degrees N.}
961   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: y2\textcolor{comment}{ !< Segment ending latitude, in degrees N.}
962   \textcolor{comment}{! Local variables}
963   \textcolor{keywordtype}{real} :: dL
964   \textcolor{keywordtype}{real} :: r, dy
965 
966   dy = y2 - y1
967 
968   \textcolor{keywordflow}{if} (abs(dy) > 2.5e-8) \textcolor{keywordflow}{then}
969     r = ((1.0 - cos(dy))*cos(y1) + sin(dy)*sin(y1)) / dy
970   \textcolor{keywordflow}{else}
971     r = (0.5*dy*cos(y1) + sin(y1))
972 \textcolor{keywordflow}{  endif}
973   dl = r * (x2 - x1)
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{\tt in}  & {\em x} & The longitude in question\\
\hline
\mbox{\tt in}  & {\em y} & The latitude in question\\
\hline
\mbox{\tt 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}
928   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: x\textcolor{comment}{  !< The longitude in question}
929   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: y\textcolor{comment}{  !< The latitude in question}
930   \textcolor{keywordtype}{type}(GPS), \textcolor{keywordtype}{intent(in)} :: GP\textcolor{comment}{  !< A structure of grid parameters}
931   \textcolor{keywordtype}{real} :: ds\_di
932   \textcolor{comment}{! Local variables}
933 
934   ds\_di = gp%Rad\_Earth * cos(y) * dx\_di(x,gp)
935   \textcolor{comment}{! In general, this might be...}
936   \textcolor{comment}{! ds\_di = GP%Rad\_Earth * sqrt( cos(y)*cos(y) * dx\_di(x,y,GP)*dx\_di(x,y,GP) + &}
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{\tt in}  & {\em x} & The longitude in question\\
\hline
\mbox{\tt in}  & {\em y} & The latitude in question\\
\hline
\mbox{\tt 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}
942   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: x\textcolor{comment}{  !< The longitude in question}
943   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: y\textcolor{comment}{  !< The latitude in question}
944   \textcolor{keywordtype}{type}(GPS), \textcolor{keywordtype}{intent(in)} :: GP\textcolor{comment}{  !< A structure of grid parameters}
945   \textcolor{comment}{! Local variables}
946   \textcolor{keywordtype}{real} :: ds\_dj
947 
948   ds\_dj = gp%Rad\_Earth * dy\_dj(y,gp)
949   \textcolor{comment}{! In general, this might be...}
950   \textcolor{comment}{! ds\_dj = GP%Rad\_Earth * sqrt( cos(y)*cos(y) * dx\_dj(x,y,GP)*dx\_dj(x,y,GP) + &}
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{\tt in}  & {\em x} & The longitude in question\\
\hline
\mbox{\tt 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}
1093   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: x\textcolor{comment}{  !< The longitude in question}
1094   \textcolor{keywordtype}{type}(GPS), \textcolor{keywordtype}{intent(in)} :: GP\textcolor{comment}{  !< A structure of grid parameters}
1095   \textcolor{keywordtype}{real} :: dx\_di
1096 
1097   dx\_di = (gp%len\_lon * 4.0*atan(1.0)) / (180.0 * gp%niglobal)
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{\tt in}  & {\em y} & The latitude in question\\
\hline
\mbox{\tt 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}
1115   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: y\textcolor{comment}{  !< The latitude in question}
1116   \textcolor{keywordtype}{type}(GPS), \textcolor{keywordtype}{intent(in)} :: GP\textcolor{comment}{  !< A structure of grid parameters}
1117   \textcolor{keywordtype}{real} :: dy\_dj
1118   \textcolor{comment}{! Local variables}
1119   \textcolor{keywordtype}{real} :: PI            \textcolor{comment}{! 3.1415926... calculated as 4*atan(1)}
1120   \textcolor{keywordtype}{real} :: C0            \textcolor{comment}{! The constant that converts the nominal y-spacing in}
1121                         \textcolor{comment}{! gridpoints to the nominal spacing in Radians.}
1122   \textcolor{keywordtype}{real} :: y\_eq\_enhance  \textcolor{comment}{! The latitude in radians within which the resolution}
1123                         \textcolor{comment}{! is enhanced.}
1124   pi = 4.0*atan(1.0)
1125   \textcolor{keywordflow}{if} (gp%isotropic) \textcolor{keywordflow}{then}
1126     c0 = (gp%len\_lon * pi) / (180.0 * gp%niglobal)
1127     y\_eq\_enhance = pi*abs(gp%lat\_eq\_enhance)/180.0
1128     \textcolor{keywordflow}{if} (abs(y) < y\_eq\_enhance) \textcolor{keywordflow}{then}
1129       dy\_dj = c0 * (cos(y) / (1.0 + 0.5*cos(y) * (gp%lat\_enhance\_factor - 1.0) * &
1130                          (1.0+cos(pi*y/y\_eq\_enhance)) ))
1131     \textcolor{keywordflow}{else}
1132       dy\_dj = c0 * cos(y)
1133 \textcolor{keywordflow}{    endif}
1134   \textcolor{keywordflow}{else}
1135     c0 = (gp%len\_lat * pi) / (180.0 * gp%njglobal)
1136     dy\_dj = c0
1137 \textcolor{keywordflow}{  endif}
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{\tt in,out}  & {\em var} & The array in which to fill in halos\\
\hline
\mbox{\tt in}  & {\em jh} & The size of the halos to be filled\\
\hline
\mbox{\tt 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}
1187   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: var\textcolor{comment}{     !< The array in which to fill in halos}
1188   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}    :: jh\textcolor{comment}{      !< The size of the halos to be filled}
1189   \textcolor{keywordtype}{real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: missing\textcolor{comment}{ !< The missing data fill value, 0 by default.}
1190   \textcolor{comment}{! Local variables}
1191   \textcolor{keywordtype}{real} :: badval
1192   \textcolor{keywordtype}{integer} :: i,j
1193 
1194   badval = 0.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(missing)) badval = missing
1195 
1196   \textcolor{comment}{! Fill in southern halo by extrapolating from the computational domain}
1197   \textcolor{keywordflow}{do} j=lbound(var,2)+jh,lbound(var,2),-1 ; \textcolor{keywordflow}{do} i=lbound(var,1),ubound(var,1)
1198     \textcolor{keywordflow}{if} (var(i,j)==badval) var(i,j) = 2.0*var(i,j+1)-var(i,j+2)
1199 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1200 
1201   \textcolor{comment}{! Fill in northern halo by extrapolating from the computational domain}
1202   \textcolor{keywordflow}{do} j=ubound(var,2)-jh,ubound(var,2) ; \textcolor{keywordflow}{do} i=lbound(var,1),ubound(var,1)
1203     \textcolor{keywordflow}{if} (var(i,j)==badval) var(i,j) = 2.0*var(i,j-1)-var(i,j-2)
1204 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1205 
1206   \textcolor{comment}{! Fill in western halo by extrapolating from the computational domain}
1207   \textcolor{keywordflow}{do} j=lbound(var,2),ubound(var,2) ; \textcolor{keywordflow}{do} i=lbound(var,1)+jh,lbound(var,1),-1
1208     \textcolor{keywordflow}{if} (var(i,j)==badval) var(i,j) = 2.0*var(i+1,j)-var(i+2,j)
1209 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1210 
1211   \textcolor{comment}{! Fill in eastern halo by extrapolating from the computational domain}
1212   \textcolor{keywordflow}{do} j=lbound(var,2),ubound(var,2) ; \textcolor{keywordflow}{do} i=ubound(var,1)-jh,ubound(var,1)
1213     \textcolor{keywordflow}{if} (var(i,j)==badval) var(i,j) = 2.0*var(i-1,j)-var(i-2,j)
1214 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
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{\tt in}  & {\em gp} & A structure of grid parameters\\
\hline
\mbox{\tt in}  & {\em fnval} & The value of fn being sought\\
\hline
\mbox{\tt in}  & {\em y1} & A first guess for y\\
\hline
\mbox{\tt in}  & {\em ymin} & The minimum permitted value of y\\
\hline
\mbox{\tt in}  & {\em ymax} & The maximum permitted value of y\\
\hline
\mbox{\tt 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}
981   \textcolor{keywordtype}{real} :: find\_root\textcolor{comment}{ !< The value of y where fn(y) = fnval that will be returned}
982   \textcolor{keywordtype}{real},      \textcolor{keywordtype}{external}    :: fn\textcolor{comment}{    !< The external function whose root is being sought}
983   \textcolor{keywordtype}{real},      \textcolor{keywordtype}{external}    :: dy\_df\textcolor{comment}{ !< The inverse of the derivative of that function}
984   \textcolor{keywordtype}{type}(GPS), \textcolor{keywordtype}{intent(in)}  :: GP\textcolor{comment}{  !< A structure of grid parameters}
985   \textcolor{keywordtype}{real},      \textcolor{keywordtype}{intent(in)}  :: fnval\textcolor{comment}{ !< The value of fn being sought}
986   \textcolor{keywordtype}{real},      \textcolor{keywordtype}{intent(in)}  :: y1\textcolor{comment}{    !< A first guess for y}
987   \textcolor{keywordtype}{real},      \textcolor{keywordtype}{intent(in)}  :: ymin\textcolor{comment}{  !< The minimum permitted value of y}
988   \textcolor{keywordtype}{real},      \textcolor{keywordtype}{intent(in)}  :: ymax\textcolor{comment}{  !< The maximum permitted value of y}
989   \textcolor{keywordtype}{integer},   \textcolor{keywordtype}{intent(out)} :: ittmax\textcolor{comment}{ !< The number of iterations used to polish the root}
990   \textcolor{comment}{! Local variables}
991   \textcolor{keywordtype}{real} :: y, y\_next
992   \textcolor{keywordtype}{real} :: ybot, ytop, fnbot, fntop
993   \textcolor{keywordtype}{integer} :: itt
994   \textcolor{keywordtype}{character(len=256)} :: warnmesg
995 
996   \textcolor{keywordtype}{real} :: dy\_dfn, dy, fny
997 
998 \textcolor{comment}{!  Bracket the root.  Do not use the bounding values because the value at the}
999 \textcolor{comment}{! function at the bounds could be infinite, as is the case for the Mercator}
1000 \textcolor{comment}{! grid recursion relation. (I.e., this is a search on an open interval.)}
1001   ybot = y1
1002   fnbot = fn(ybot,gp) - fnval ; itt = 0
1003   \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (fnbot > 0.0)
1004     \textcolor{keywordflow}{if} ((ybot - 2.0*dy\_df(ybot,gp)) < (0.5*(ybot+ymin))) \textcolor{keywordflow}{then}
1005       \textcolor{comment}{! Go twice as far as the secant method would normally go.}
1006       ybot = ybot - 2.0*dy\_df(ybot,gp)
1007     \textcolor{keywordflow}{else}  \textcolor{comment}{! But stay within the open interval!}
1008       ybot = 0.5*(ybot+ymin) ; itt = itt + 1
1009 \textcolor{keywordflow}{    endif}
1010     fnbot = fn(ybot,gp) - fnval
1011 
1012     \textcolor{keywordflow}{if} ((itt > 50) .and. (fnbot > 0.0)) \textcolor{keywordflow}{then}
1013       \textcolor{keyword}{write}(warnmesg, \textcolor{stringliteral}{'("PE ",I2," unable to find bottom bound for grid function. &}
1014 \textcolor{stringliteral}{}\textcolor{stringliteral}{        &x = ",ES10.4,", xmax = ",ES10.4,", fn = ",ES10.4,", dfn\_dx = ",ES10.4,&}
1015 \textcolor{stringliteral}{}\textcolor{stringliteral}{        &", seeking fn = ",ES10.4," - fn = ",ES10.4,".")'}) &
1016           pe\_here(),ybot,ymin,fn(ybot,gp),dy\_df(ybot,gp),fnval, fnbot
1017       \textcolor{keyword}{call }mom\_error(fatal,warnmesg)
1018 \textcolor{keywordflow}{    endif}
1019 \textcolor{keywordflow}{  enddo}
1020 
1021   ytop = y1
1022   fntop = fn(ytop,gp) - fnval ; itt = 0
1023   \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (fntop < 0.0)
1024     \textcolor{keywordflow}{if} ((ytop + 2.0*dy\_df(ytop,gp)) < (0.5*(ytop+ymax))) \textcolor{keywordflow}{then}
1025       \textcolor{comment}{! Go twice as far as the secant method would normally go.}
1026       ytop = ytop + 2.0*dy\_df(ytop,gp)
1027     \textcolor{keywordflow}{else} \textcolor{comment}{! But stay within the open interval!}
1028       ytop = 0.5*(ytop+ymax) ; itt = itt + 1
1029 \textcolor{keywordflow}{    endif}
1030     fntop = fn(ytop,gp) - fnval
1031 
1032     \textcolor{keywordflow}{if} ((itt > 50) .and. (fntop < 0.0)) \textcolor{keywordflow}{then}
1033       \textcolor{keyword}{write}(warnmesg, \textcolor{stringliteral}{'("PE ",I2," unable to find top bound for grid function. &}
1034 \textcolor{stringliteral}{}\textcolor{stringliteral}{        &x = ",ES10.4,", xmax = ",ES10.4,", fn = ",ES10.4,", dfn\_dx = ",ES10.4, &}
1035 \textcolor{stringliteral}{}\textcolor{stringliteral}{        &", seeking fn = ",ES10.4," - fn = ",ES10.4,".")'}) &
1036           pe\_here(),ytop,ymax,fn(ytop,gp),dy\_df(ytop,gp),fnval,fntop
1037       \textcolor{keyword}{call }mom\_error(fatal,warnmesg)
1038 \textcolor{keywordflow}{    endif}
1039 \textcolor{keywordflow}{  enddo}
1040 
1041   \textcolor{comment}{! Find the root using a bracketed variant of Newton's method, starting}
1042   \textcolor{comment}{! with a false-positon method first guess.}
1043   \textcolor{keywordflow}{if} ((fntop < 0.0) .or. (fnbot > 0.0) .or. (ytop < ybot)) \textcolor{keywordflow}{then}
1044     \textcolor{keyword}{write}(warnmesg, \textcolor{stringliteral}{'("PE ",I2," find\_root failed to bracket function. y = ",&}
1045 \textcolor{stringliteral}{}\textcolor{stringliteral}{              &2ES10.4,", fn = ",2ES10.4,".")'}) pe\_here(),ybot,ytop,fnbot,fntop
1046     \textcolor{keyword}{call }mom\_error(fatal, warnmesg)
1047 \textcolor{keywordflow}{  endif}
1048 
1049   \textcolor{keywordflow}{if} (fntop == 0.0) \textcolor{keywordflow}{then} ; y = ytop ; fny = fntop
1050   \textcolor{keywordflow}{elseif} (fnbot == 0.0) \textcolor{keywordflow}{then} ; y = ybot ; fny = fnbot
1051   \textcolor{keywordflow}{else}
1052     y = (ybot*fntop - ytop*fnbot) / (fntop - fnbot)
1053     fny = fn(y,gp) - fnval
1054     \textcolor{keywordflow}{if} (fny < 0.0) \textcolor{keywordflow}{then} ; fnbot = fny ; ybot = y
1055     \textcolor{keywordflow}{else} ; fntop = fny ; ytop = y ;\textcolor{keywordflow}{ endif}
1056 \textcolor{keywordflow}{  endif}
1057 
1058   \textcolor{keywordflow}{do} itt=1,50
1059     dy\_dfn = dy\_df(y,gp)
1060 
1061     dy = -1.0* fny * dy\_dfn
1062     y\_next = y + dy
1063     \textcolor{keywordflow}{if} ((y\_next >= ytop) .or. (y\_next <= ybot)) \textcolor{keywordflow}{then}
1064       \textcolor{comment}{! The Newton's method estimate has escaped bracketing, so use the}
1065       \textcolor{comment}{! false-position method instead.  The complicated test is to properly}
1066       \textcolor{comment}{! handle the case where the iteration is down to roundoff level differences.}
1067       y\_next = y
1068       \textcolor{keywordflow}{if} (abs(fntop - fnbot) > epsilon(y) * (abs(fntop) + abs(fnbot))) &
1069         y\_next = (ybot*fntop - ytop*fnbot) / (fntop - fnbot)
1070 \textcolor{keywordflow}{    endif}
1071 
1072     dy = y\_next - y
1073     \textcolor{keywordflow}{if} (abs(dy) < (2.0*epsilon(y)*(abs(y) + abs(y\_next)) + 1.0e-20)) \textcolor{keywordflow}{then}
1074       y = y\_next ; \textcolor{keywordflow}{exit}
1075 \textcolor{keywordflow}{    endif}
1076     y = y\_next
1077 
1078     fny = fn(y,gp) - fnval
1079     \textcolor{keywordflow}{if} (fny > 0.0) \textcolor{keywordflow}{then} ; ytop = y ; fntop = fny
1080     \textcolor{keywordflow}{elseif} (fny < 0.0) \textcolor{keywordflow}{then} ; ybot = y ; fnbot = fny
1081     \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{exit} ;\textcolor{keywordflow}{ endif}
1082 
1083 \textcolor{keywordflow}{  enddo}
1084   \textcolor{keywordflow}{if} (abs(y) < 1e-12) y = 0.0
1085 
1086   ittmax = itt
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{\tt in}  & {\em parent} & A string identifying the caller\\
\hline
\mbox{\tt in}  & {\em g} & The dynamic horizontal grid type\\
\hline
\mbox{\tt 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}
116   \textcolor{keywordtype}{character(len=*)},       \textcolor{keywordtype}{intent(in)} :: parent\textcolor{comment}{ !< A string identifying the caller}
117   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{      !< The dynamic horizontal grid type}
118   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{ !< A dimensional unit scaling type}
119 
120   \textcolor{keywordtype}{real} :: m\_to\_L  \textcolor{comment}{! A unit conversion factor [L m-1 ~> nondim]}
121   \textcolor{keywordtype}{real} :: L\_to\_m  \textcolor{comment}{! A unit conversion factor [m L-1 ~> nondim]}
122   \textcolor{keywordtype}{integer} :: halo
123   m\_to\_l = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) m\_to\_l = us%m\_to\_L
124   l\_to\_m = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) l\_to\_m = us%L\_to\_m
125 
126   halo = min(g%ied-g%iec, g%jed-g%jec, 1)
127 
128   \textcolor{keyword}{call }hchksum\_pair(trim(parent)//\textcolor{stringliteral}{': d[xy]T'}, g%dxT, g%dyT, g%HI, &
129                     haloshift=halo, scale=l\_to\_m, scalar\_pair=.true.)
130 
131   \textcolor{keyword}{call }uvchksum(trim(parent)//\textcolor{stringliteral}{': dxC[uv]'}, g%dxCu, g%dyCv, g%HI, haloshift=halo, scale=l\_to\_m)
132 
133   \textcolor{keyword}{call }uvchksum(trim(parent)//\textcolor{stringliteral}{': dxC[uv]'}, g%dyCu, g%dxCv, g%HI, haloshift=halo, scale=l\_to\_m)
134 
135   \textcolor{keyword}{call }bchksum\_pair(trim(parent)//\textcolor{stringliteral}{': dxB[uv]'}, g%dxBu, g%dyBu, g%HI, haloshift=halo, scale=l\_to\_m)
136 
137   \textcolor{keyword}{call }hchksum\_pair(trim(parent)//\textcolor{stringliteral}{': Id[xy]T'}, g%IdxT, g%IdyT, g%HI, &
138                     haloshift=halo, scale=m\_to\_l, scalar\_pair=.true.)
139 
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)
141 
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)
143 
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)
145 
146   \textcolor{keyword}{call }hchksum(g%areaT, trim(parent)//\textcolor{stringliteral}{': areaT'},g%HI, haloshift=halo, scale=l\_to\_m**2)
147   \textcolor{keyword}{call }bchksum(g%areaBu, trim(parent)//\textcolor{stringliteral}{': areaBu'},g%HI, haloshift=halo, scale=l\_to\_m**2)
148 
149   \textcolor{keyword}{call }hchksum(g%IareaT, trim(parent)//\textcolor{stringliteral}{': IareaT'},g%HI, haloshift=halo, scale=m\_to\_l**2)
150   \textcolor{keyword}{call }bchksum(g%IareaBu, trim(parent)//\textcolor{stringliteral}{': IareaBu'},g%HI, haloshift=halo, scale=m\_to\_l**2)
151 
152   \textcolor{keyword}{call }hchksum(g%geoLonT,trim(parent)//\textcolor{stringliteral}{': geoLonT'},g%HI, haloshift=halo)
153   \textcolor{keyword}{call }hchksum(g%geoLatT,trim(parent)//\textcolor{stringliteral}{': geoLatT'},g%HI, haloshift=halo)
154 
155   \textcolor{keyword}{call }bchksum(g%geoLonBu, trim(parent)//\textcolor{stringliteral}{': geoLonBu'},g%HI, haloshift=halo)
156   \textcolor{keyword}{call }bchksum(g%geoLatBu, trim(parent)//\textcolor{stringliteral}{': geoLatBu'},g%HI, haloshift=halo)
157 
158   \textcolor{keyword}{call }uvchksum(trim(parent)//\textcolor{stringliteral}{': geoLonC[uv]'}, g%geoLonCu, g%geoLonCv, g%HI, haloshift=halo)
159 
160   \textcolor{keyword}{call }uvchksum(trim(parent)//\textcolor{stringliteral}{': geoLatC[uv]'}, g%geoLatCu, g%geoLatCv, g%HI, haloshift=halo)
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{\tt in,out}  & {\em g} & The dynamic horizontal grid type\\
\hline
\mbox{\tt in}  & {\em pf} & Parameter file structure\\
\hline
\mbox{\tt 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}
1237   \textcolor{keywordtype}{type}(dyn\_horgrid\_type),          \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{  !< The dynamic horizontal grid type}
1238   \textcolor{keywordtype}{type}(param\_file\_type),           \textcolor{keywordtype}{intent(in)}    :: PF\textcolor{comment}{ !< Parameter file structure}
1239   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}
1240   \textcolor{comment}{! Local variables}
1241   \textcolor{keywordtype}{real} :: m\_to\_Z\_scale \textcolor{comment}{! A unit conversion factor from m to Z.}
1242   \textcolor{keywordtype}{real} :: m\_to\_L  \textcolor{comment}{! A unit conversion factor [L m-1 ~> nondim]}
1243   \textcolor{keywordtype}{real} :: Dmin       \textcolor{comment}{! The depth for masking in the same units as G%bathyT [Z ~> m].}
1244   \textcolor{keywordtype}{real} :: min\_depth  \textcolor{comment}{! The minimum ocean depth in the same units as G%bathyT [Z ~> m].}
1245   \textcolor{keywordtype}{real} :: mask\_depth \textcolor{comment}{! The depth shallower than which to mask a point as land [Z ~> m].}
1246   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_grid\_init initialize\_masks"}
1247   \textcolor{keywordtype}{integer} :: i, j
1248 
1249   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"initialize\_masks(), MOM\_grid\_initialize.F90"})
1250   m\_to\_z\_scale = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) m\_to\_z\_scale = us%m\_to\_Z
1251   m\_to\_l = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) m\_to\_l = us%m\_to\_L
1252 
1253   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"MINIMUM\_DEPTH"}, min\_depth, &
1254                  \textcolor{stringliteral}{"If MASKING\_DEPTH is unspecified, then anything shallower than "}//&
1255                  \textcolor{stringliteral}{"MINIMUM\_DEPTH is assumed to be land and all fluxes are masked out. "}//&
1256                  \textcolor{stringliteral}{"If MASKING\_DEPTH is specified, then all depths shallower than "}//&
1257                  \textcolor{stringliteral}{"MINIMUM\_DEPTH but deeper than MASKING\_DEPTH are rounded to MINIMUM\_DEPTH."}, &
1258                  units=\textcolor{stringliteral}{"m"}, default=0.0, scale=m\_to\_z\_scale)
1259   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"MASKING\_DEPTH"}, mask\_depth, &
1260                  \textcolor{stringliteral}{"The depth below which to mask points as land points, for which all "}//&
1261                  \textcolor{stringliteral}{"fluxes are zeroed out. MASKING\_DEPTH is ignored if negative."}, &
1262                  units=\textcolor{stringliteral}{"m"}, default=-9999.0, scale=m\_to\_z\_scale)
1263 
1264   dmin = min\_depth
1265   \textcolor{keywordflow}{if} (mask\_depth>=0.) dmin = mask\_depth
1266 
1267   g%mask2dCu(:,:) = 0.0 ; g%mask2dCv(:,:) = 0.0 ; g%mask2dBu(:,:) = 0.0
1268 
1269   \textcolor{comment}{! Construct the h-point or T-point mask}
1270   \textcolor{keywordflow}{do} j=g%jsd,g%jed ; \textcolor{keywordflow}{do} i=g%isd,g%ied
1271     \textcolor{keywordflow}{if} (g%bathyT(i,j) <= dmin) \textcolor{keywordflow}{then}
1272       g%mask2dT(i,j) = 0.0
1273     \textcolor{keywordflow}{else}
1274       g%mask2dT(i,j) = 1.0
1275 \textcolor{keywordflow}{    endif}
1276 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1277 
1278   \textcolor{keywordflow}{do} j=g%jsd,g%jed ; \textcolor{keywordflow}{do} i=g%isd,g%ied-1
1279     \textcolor{keywordflow}{if} ((g%bathyT(i,j) <= dmin) .or. (g%bathyT(i+1,j) <= dmin)) \textcolor{keywordflow}{then}
1280       g%mask2dCu(i,j) = 0.0
1281     \textcolor{keywordflow}{else}
1282       g%mask2dCu(i,j) = 1.0
1283 \textcolor{keywordflow}{    endif}
1284 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1285 
1286   \textcolor{keywordflow}{do} j=g%jsd,g%jed-1 ; \textcolor{keywordflow}{do} i=g%isd,g%ied
1287     \textcolor{keywordflow}{if} ((g%bathyT(i,j) <= dmin) .or. (g%bathyT(i,j+1) <= dmin)) \textcolor{keywordflow}{then}
1288       g%mask2dCv(i,j) = 0.0
1289     \textcolor{keywordflow}{else}
1290       g%mask2dCv(i,j) = 1.0
1291 \textcolor{keywordflow}{    endif}
1292 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1293 
1294   \textcolor{keywordflow}{do} j=g%jsd,g%jed-1 ; \textcolor{keywordflow}{do} i=g%isd,g%ied-1
1295     \textcolor{keywordflow}{if} ((g%bathyT(i+1,j) <= dmin) .or. (g%bathyT(i+1,j+1) <= dmin) .or. &
1296         (g%bathyT(i,j) <= dmin) .or. (g%bathyT(i,j+1) <= dmin)) \textcolor{keywordflow}{then}
1297       g%mask2dBu(i,j) = 0.0
1298     \textcolor{keywordflow}{else}
1299       g%mask2dBu(i,j) = 1.0
1300 \textcolor{keywordflow}{    endif}
1301 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1302 
1303   \textcolor{keyword}{call }pass\_var(g%mask2dBu, g%Domain, position=corner)
1304   \textcolor{keyword}{call }pass\_vector(g%mask2dCu, g%mask2dCv, g%Domain, to\_all+scalar\_pair, cgrid\_ne)
1305 
1306   \textcolor{keywordflow}{do} j=g%jsd,g%jed ; \textcolor{keywordflow}{do} i=g%IsdB,g%IedB
1307     g%dy\_Cu(i,j) = g%mask2dCu(i,j) * g%dyCu(i,j)
1308     g%areaCu(i,j) = g%dxCu(i,j) * g%dy\_Cu(i,j)
1309     g%IareaCu(i,j) = g%mask2dCu(i,j) * adcroft\_reciprocal(g%areaCu(i,j))
1310 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1311 
1312   \textcolor{keywordflow}{do} j=g%JsdB,g%JedB ; \textcolor{keywordflow}{do} i=g%isd,g%ied
1313     g%dx\_Cv(i,j) = g%mask2dCv(i,j) * g%dxCv(i,j)
1314     g%areaCv(i,j) = g%dyCv(i,j) * g%dx\_Cv(i,j)
1315     g%IareaCv(i,j) = g%mask2dCv(i,j) * adcroft\_reciprocal(g%areaCv(i,j))
1316 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
1317 
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{\tt in}  & {\em x} & The longitude in question\\
\hline
\mbox{\tt 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}
1104   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: x\textcolor{comment}{  !< The longitude in question}
1105   \textcolor{keywordtype}{type}(GPS), \textcolor{keywordtype}{intent(in)} :: GP\textcolor{comment}{  !< A structure of grid parameters}
1106   \textcolor{keywordtype}{real} :: Int\_di\_dx
1107 
1108   int\_di\_dx = x * ((180.0 * gp%niglobal) / (gp%len\_lon * 4.0*atan(1.0)))
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{\tt in}  & {\em y} & The latitude in question\\
\hline
\mbox{\tt 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}
1144   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{intent(in)} :: y\textcolor{comment}{  !< The latitude in question}
1145   \textcolor{keywordtype}{type}(GPS), \textcolor{keywordtype}{intent(in)} :: GP\textcolor{comment}{  !< A structure of grid parameters}
1146   \textcolor{keywordtype}{real} :: Int\_dj\_dy
1147   \textcolor{comment}{! Local variables}
1148   \textcolor{keywordtype}{real} :: I\_C0 = 0.0       \textcolor{comment}{!   The inverse of the constant that converts the}
1149                            \textcolor{comment}{! nominal spacing in gridpoints to the nominal}
1150                            \textcolor{comment}{! spacing in Radians.}
1151   \textcolor{keywordtype}{real} :: PI               \textcolor{comment}{! 3.1415926... calculated as 4*atan(1)}
1152   \textcolor{keywordtype}{real} :: y\_eq\_enhance     \textcolor{comment}{! The latitude in radians from}
1153                            \textcolor{comment}{! from the equator within which the}
1154                            \textcolor{comment}{! meridional grid spacing is enhanced by}
1155                            \textcolor{comment}{! a factor of GP%lat\_enhance\_factor.}
1156   \textcolor{keywordtype}{real} :: r
1157 
1158   pi = 4.0*atan(1.0)
1159   \textcolor{keywordflow}{if} (gp%isotropic) \textcolor{keywordflow}{then}
1160     i\_c0 = (180.0 * gp%niglobal) / (gp%len\_lon * pi)
1161     y\_eq\_enhance = pi*abs(gp%lat\_eq\_enhance)/180.0
1162 
1163     \textcolor{keywordflow}{if} (y >= 0.0) \textcolor{keywordflow}{then}
1164       r = i\_c0 * log((1.0 + sin(y))/cos(y))
1165     \textcolor{keywordflow}{else}
1166       r = -1.0 * i\_c0 * log((1.0 - sin(y))/cos(y))
1167 \textcolor{keywordflow}{    endif}
1168 
1169     \textcolor{keywordflow}{if} (y >= y\_eq\_enhance) \textcolor{keywordflow}{then}
1170       r = r + i\_c0*0.5*(gp%lat\_enhance\_factor - 1.0)*y\_eq\_enhance
1171     \textcolor{keywordflow}{elseif} (y <= -y\_eq\_enhance) \textcolor{keywordflow}{then}
1172       r = r - i\_c0*0.5*(gp%lat\_enhance\_factor - 1.0)*y\_eq\_enhance
1173     \textcolor{keywordflow}{else}
1174       r = r + i\_c0*0.5*(gp%lat\_enhance\_factor - 1.0) * &
1175               (y + (y\_eq\_enhance/pi)*sin(pi*y/y\_eq\_enhance))
1176 \textcolor{keywordflow}{    endif}
1177   \textcolor{keywordflow}{else}
1178     i\_c0 = (180.0 * gp%njglobal) / (gp%len\_lat * pi)
1179     r = i\_c0 * y
1180 \textcolor{keywordflow}{  endif}
1181 
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{\tt in,out}  & {\em g} & The dynamic horizontal grid type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file structure\\
\hline
\mbox{\tt 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}
63   \textcolor{keywordtype}{type}(dyn\_horgrid\_type),          \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{  !< The dynamic horizontal grid type}
64   \textcolor{keywordtype}{type}(param\_file\_type),           \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file structure}
65   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}
66   \textcolor{comment}{! Local variables}
67 \textcolor{comment}{! This include declares and sets the variable "version".}
68 \textcolor{preprocessor}{#include "version\_variable.h"}
69 \textcolor{preprocessor}{}  \textcolor{keywordtype}{logical} :: debug
70   \textcolor{keywordtype}{character(len=256)} :: config
71 
72   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"set\_grid\_metrics(), MOM\_grid\_initialize.F90"})
73   \textcolor{keyword}{call }log\_version(param\_file, \textcolor{stringliteral}{"MOM\_grid\_init"}, version, \textcolor{stringliteral}{""})
74   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM\_grid\_init"}, \textcolor{stringliteral}{"GRID\_CONFIG"}, config, &
75                  \textcolor{stringliteral}{"A character string that determines the method for "}//&
76                  \textcolor{stringliteral}{"defining the horizontal grid.  Current options are: \(\backslash\)n"}//&
77                  \textcolor{stringliteral}{" \(\backslash\)t mosaic - read the grid from a mosaic (supergrid) \(\backslash\)n"}//&
78                  \textcolor{stringliteral}{" \(\backslash\)t          file set by GRID\_FILE.\(\backslash\)n"}//&
79                  \textcolor{stringliteral}{" \(\backslash\)t cartesian - use a (flat) Cartesian grid.\(\backslash\)n"}//&
80                  \textcolor{stringliteral}{" \(\backslash\)t spherical - use a simple spherical grid.\(\backslash\)n"}//&
81                  \textcolor{stringliteral}{" \(\backslash\)t mercator - use a Mercator spherical grid."}, &
82                  fail\_if\_missing=.true.)
83   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM\_grid\_init"}, \textcolor{stringliteral}{"DEBUG"}, debug, &
84                  \textcolor{stringliteral}{"If true, write out verbose debugging data."}, &
85                  default=.false., debuggingparam=.true.)
86 
87   \textcolor{comment}{! These are defaults that may be changed in the next select block.}
88   g%x\_axis\_units = \textcolor{stringliteral}{"degrees\_east"} ; g%y\_axis\_units = \textcolor{stringliteral}{"degrees\_north"}
89   \textcolor{keywordflow}{select case} (trim(config))
90     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"mosaic"});    \textcolor{keyword}{call }set\_grid\_metrics\_from\_mosaic(g, param\_file, us)
91     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"cartesian"}); \textcolor{keyword}{call }set\_grid\_metrics\_cartesian(g, param\_file, us)
92     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"spherical"}); \textcolor{keyword}{call }set\_grid\_metrics\_spherical(g, param\_file, us)
93     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"mercator"});  \textcolor{keyword}{call }set\_grid\_metrics\_mercator(g, param\_file, us)
94     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"file"}); \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_grid\_init: set\_grid\_metrics "}//&
95            \textcolor{stringliteral}{'GRID\_CONFIG "file" is no longer a supported option.  Use a '}//&
96            \textcolor{stringliteral}{'mosaic file ("mosaic") or one of the analytic forms instead.'})
97 \textcolor{keywordflow}{    case default} ; \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_grid\_init: set\_grid\_metrics "}//&
98            \textcolor{stringliteral}{"Unrecognized grid configuration "}//trim(config))
99 \textcolor{keywordflow}{  end select}
100 
101   \textcolor{comment}{! Calculate derived metrics (i.e. reciprocals and products)}
102   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"set\_derived\_metrics(), MOM\_grid\_initialize.F90"})
103   \textcolor{keyword}{call }set\_derived\_dyn\_horgrid(g, us)
104   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"set\_derived\_metrics()"})
105 
106   \textcolor{keywordflow}{if} (debug) \textcolor{keyword}{call }grid\_metrics\_chksum(\textcolor{stringliteral}{'MOM\_grid\_init/set\_grid\_metrics'}, g, us)
107 
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{\tt in,out}  & {\em g} & The dynamic horizontal grid type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file structure\\
\hline
\mbox{\tt 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}
420   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{           !< The dynamic horizontal grid type}
421   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)}     :: param\_file\textcolor{comment}{  !< Parameter file structure}
422   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{    !< A dimensional unit scaling type}
423   \textcolor{comment}{! Local variables}
424   \textcolor{keywordtype}{integer} :: i, j, isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB, I1off, J1off
425   \textcolor{keywordtype}{integer} :: niglobal, njglobal
426   \textcolor{keywordtype}{real} :: grid\_latT(G%jsd:G%jed), grid\_latB(G%JsdB:G%JedB)
427   \textcolor{keywordtype}{real} :: grid\_lonT(G%isd:G%ied), grid\_lonB(G%IsdB:G%IedB)
428   \textcolor{keywordtype}{real} :: dx\_everywhere, dy\_everywhere \textcolor{comment}{! Grid spacings [m].}
429   \textcolor{keywordtype}{real} :: I\_dx, I\_dy                   \textcolor{comment}{! Inverse grid spacings [m-1].}
430   \textcolor{keywordtype}{real} :: PI
431   \textcolor{keywordtype}{real} :: m\_to\_L  \textcolor{comment}{! A unit conversion factor [L m-1 ~> nondim]}
432   \textcolor{keywordtype}{real} :: L\_to\_m  \textcolor{comment}{! A unit conversion factor [m L-1 ~> nondim]}
433   \textcolor{keywordtype}{character(len=80)} :: units\_temp
434   \textcolor{keywordtype}{character(len=48)} :: mdl  = \textcolor{stringliteral}{"MOM\_grid\_init set\_grid\_metrics\_cartesian"}
435 
436   niglobal = g%Domain%niglobal ; njglobal = g%Domain%njglobal
437   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
438   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
439   i1off = g%idg\_offset ; j1off = g%jdg\_offset
440 
441   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"set\_grid\_metrics\_cartesian(), MOM\_grid\_initialize.F90"})
442 
443   m\_to\_l = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) m\_to\_l = us%m\_to\_L
444   l\_to\_m = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) l\_to\_m = us%L\_to\_m
445   pi = 4.0*atan(1.0)
446 
447   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"AXIS\_UNITS"}, units\_temp, &
448                  \textcolor{stringliteral}{"The units for the Cartesian axes. Valid entries are: \(\backslash\)n"}//&
449                  \textcolor{stringliteral}{" \(\backslash\)t degrees - degrees of latitude and longitude \(\backslash\)n"}//&
450                  \textcolor{stringliteral}{" \(\backslash\)t m - meters \(\backslash\)n \(\backslash\)t k - kilometers"}, default=\textcolor{stringliteral}{"degrees"})
451   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SOUTHLAT"}, g%south\_lat, &
452                  \textcolor{stringliteral}{"The southern latitude of the domain or the equivalent "}//&
453                  \textcolor{stringliteral}{"starting value for the y-axis."}, units=units\_temp, &
454                  fail\_if\_missing=.true.)
455   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LENLAT"}, g%len\_lat, &
456                  \textcolor{stringliteral}{"The latitudinal or y-direction length of the domain."}, &
457                  units=units\_temp, fail\_if\_missing=.true.)
458   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"WESTLON"}, g%west\_lon, &
459                  \textcolor{stringliteral}{"The western longitude of the domain or the equivalent "}//&
460                  \textcolor{stringliteral}{"starting value for the x-axis."}, units=units\_temp, &
461                  default=0.0)
462   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LENLON"}, g%len\_lon, &
463                  \textcolor{stringliteral}{"The longitudinal or x-direction length of the domain."}, &
464                  units=units\_temp, fail\_if\_missing=.true.)
465   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RAD\_EARTH"}, g%Rad\_Earth, &
466                  \textcolor{stringliteral}{"The radius of the Earth."}, units=\textcolor{stringliteral}{"m"}, default=6.378e6)
467 
468   \textcolor{keywordflow}{if} (units\_temp(1:1) == \textcolor{stringliteral}{'k'}) \textcolor{keywordflow}{then}
469     g%x\_axis\_units = \textcolor{stringliteral}{"kilometers"} ; g%y\_axis\_units = \textcolor{stringliteral}{"kilometers"}
470   \textcolor{keywordflow}{elseif} (units\_temp(1:1) == \textcolor{stringliteral}{'m'}) \textcolor{keywordflow}{then}
471     g%x\_axis\_units = \textcolor{stringliteral}{"meters"} ; g%y\_axis\_units = \textcolor{stringliteral}{"meters"}
472 \textcolor{keywordflow}{  endif}
473   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"explicit AXIS\_UNITS"}, g%x\_axis\_units)
474 
475   \textcolor{comment}{! Note that the dynamic grid always uses symmetric memory for the global}
476   \textcolor{comment}{! arrays G%gridLatB and G%gridLonB.}
477   \textcolor{keywordflow}{do} j=g%jsg-1,g%jeg
478     g%gridLatB(j) = g%south\_lat + g%len\_lat*\textcolor{keywordtype}{REAL}(J-(G%jsg-1))/\textcolor{keywordtype}{REAL}(njglobal)
479 \textcolor{keywordflow}{  enddo}
480   \textcolor{keywordflow}{do} j=g%jsg,g%jeg
481     g%gridLatT(j) = g%south\_lat + g%len\_lat*(\textcolor{keywordtype}{REAL}(j-G%jsg)+0.5)/\textcolor{keywordtype}{REAL}(njglobal)
482 \textcolor{keywordflow}{  enddo}
483   \textcolor{keywordflow}{do} i=g%isg-1,g%ieg
484     g%gridLonB(i) = g%west\_lon + g%len\_lon*\textcolor{keywordtype}{REAL}(I-(G%isg-1))/\textcolor{keywordtype}{REAL}(niglobal)
485 \textcolor{keywordflow}{  enddo}
486   \textcolor{keywordflow}{do} i=g%isg,g%ieg
487     g%gridLonT(i) = g%west\_lon + g%len\_lon*(\textcolor{keywordtype}{REAL}(i-G%isg)+0.5)/\textcolor{keywordtype}{REAL}(niglobal)
488 \textcolor{keywordflow}{  enddo}
489 
490   \textcolor{keywordflow}{do} j=jsdb,jedb
491     grid\_latb(j) = g%south\_lat + g%len\_lat*\textcolor{keywordtype}{REAL}(J+J1off-(G%jsg-1))/\textcolor{keywordtype}{REAL}(njglobal)
492 \textcolor{keywordflow}{  enddo}
493   \textcolor{keywordflow}{do} j=jsd,jed
494     grid\_latt(j) = g%south\_lat + g%len\_lat*(\textcolor{keywordtype}{REAL}(j+J1off-G%jsg)+0.5)/\textcolor{keywordtype}{REAL}(njglobal)
495 \textcolor{keywordflow}{  enddo}
496   \textcolor{keywordflow}{do} i=isdb,iedb
497     grid\_lonb(i) = g%west\_lon + g%len\_lon*\textcolor{keywordtype}{REAL}(i+I1off-(G%isg-1))/\textcolor{keywordtype}{REAL}(niglobal)
498 \textcolor{keywordflow}{  enddo}
499   \textcolor{keywordflow}{do} i=isd,ied
500     grid\_lont(i) = g%west\_lon + g%len\_lon*(\textcolor{keywordtype}{REAL}(i+I1off-G%isg)+0.5)/\textcolor{keywordtype}{REAL}(niglobal)
501 \textcolor{keywordflow}{  enddo}
502 
503   \textcolor{keywordflow}{if} (units\_temp(1:1) == \textcolor{stringliteral}{'k'}) \textcolor{keywordflow}{then} \textcolor{comment}{! Axes are measured in km.}
504     dx\_everywhere = 1000.0 * g%len\_lon / (\textcolor{keywordtype}{REAL}(niglobal))
505     dy\_everywhere = 1000.0 * g%len\_lat / (\textcolor{keywordtype}{REAL}(njglobal))
506   \textcolor{keywordflow}{elseif} (units\_temp(1:1) == \textcolor{stringliteral}{'m'}) \textcolor{keywordflow}{then} \textcolor{comment}{! Axes are measured in m.}
507     dx\_everywhere = g%len\_lon / (\textcolor{keywordtype}{REAL}(niglobal))
508     dy\_everywhere = g%len\_lat / (\textcolor{keywordtype}{REAL}(njglobal))
509   \textcolor{keywordflow}{else} \textcolor{comment}{! Axes are measured in degrees of latitude and longitude.}
510     dx\_everywhere = g%Rad\_Earth * g%len\_lon * pi / (180.0 * niglobal)
511     dy\_everywhere = g%Rad\_Earth * g%len\_lat * pi / (180.0 * njglobal)
512 \textcolor{keywordflow}{  endif}
513 
514   i\_dx = 1.0 / dx\_everywhere ; i\_dy = 1.0 / dy\_everywhere
515 
516   \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isdb,iedb
517     g%geoLonBu(i,j) = grid\_lonb(i) ; g%geoLatBu(i,j) = grid\_latb(j)
518 
519     g%dxBu(i,j) = m\_to\_l*dx\_everywhere ; g%IdxBu(i,j) = l\_to\_m*i\_dx
520     g%dyBu(i,j) = m\_to\_l*dy\_everywhere ; g%IdyBu(i,j) = l\_to\_m*i\_dy
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
522 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
523 
524   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
525     g%geoLonT(i,j) = grid\_lont(i) ; g%geoLatT(i,j) = grid\_latt(j)
526     g%dxT(i,j) = m\_to\_l*dx\_everywhere ; g%IdxT(i,j) = l\_to\_m*i\_dx
527     g%dyT(i,j) = m\_to\_l*dy\_everywhere ; g%IdyT(i,j) = l\_to\_m*i\_dy
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
529 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
530 
531   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb
532     g%geoLonCu(i,j) = grid\_lonb(i) ; g%geoLatCu(i,j) = grid\_latt(j)
533 
534     g%dxCu(i,j) = m\_to\_l*dx\_everywhere ; g%IdxCu(i,j) = l\_to\_m*i\_dx
535     g%dyCu(i,j) = m\_to\_l*dy\_everywhere ; g%IdyCu(i,j) = l\_to\_m*i\_dy
536 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
537 
538   \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied
539     g%geoLonCv(i,j) = grid\_lont(i) ; g%geoLatCv(i,j) = grid\_latb(j)
540 
541     g%dxCv(i,j) = m\_to\_l*dx\_everywhere ; g%IdxCv(i,j) = l\_to\_m*i\_dx
542     g%dyCv(i,j) = m\_to\_l*dy\_everywhere ; g%IdyCv(i,j) = l\_to\_m*i\_dy
543 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
544 
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{\tt in,out}  & {\em g} & The dynamic horizontal grid type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file structure\\
\hline
\mbox{\tt 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}
168   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{           !< The dynamic horizontal grid type}
169   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)}     :: param\_file\textcolor{comment}{  !< Parameter file structure}
170   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{    !< A dimensional unit scaling type}
171   \textcolor{comment}{! Local variables}
172   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd :G%ied ,G%jsd :G%jed )} :: tempH1, tempH2, tempH3, tempH4
173   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%IsdB:G%IedB,G%JsdB:G%JedB)} :: tempQ1, tempQ2, tempQ3, tempQ4
174   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%IsdB:G%IedB,G%jsd :G%jed )} :: tempE1, tempE2
175   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd :G%ied ,G%JsdB:G%JedB)} :: tempN1, tempN2
176   \textcolor{comment}{! These arrays are a holdover from earlier code in which the arrays in G were}
177   \textcolor{comment}{! macros and may have had reduced dimensions.}
178   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd :G%ied ,G%jsd :G%jed )} :: dxT, dyT, areaT
179   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%IsdB:G%IedB,G%jsd :G%jed )} :: dxCu, dyCu
180   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd :G%ied ,G%JsdB:G%JedB)} :: dxCv, dyCv
181   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%IsdB:G%IedB,G%JsdB:G%JedB)} :: dxBu, dyBu, areaBu
182   \textcolor{comment}{! This are symmetric arrays, corresponding to the data in the mosaic file}
183   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(2*G%isd-2:2*G%ied+1,2*G%jsd-2:2*G%jed+1)} :: tmpT
184   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(2*G%isd-3:2*G%ied+1,2*G%jsd-2:2*G%jed+1)} :: tmpU
185   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(2*G%isd-2:2*G%ied+1,2*G%jsd-3:2*G%jed+1)} :: tmpV
186   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(2*G%isd-3:2*G%ied+1,2*G%jsd-3:2*G%jed+1)} :: tmpZ
187   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{allocatable} :: tmpGlbl
188   \textcolor{keywordtype}{real} :: m\_to\_L  \textcolor{comment}{! A unit conversion factor [L m-1 ~> nondim]}
189   \textcolor{keywordtype}{character(len=200)} :: filename, grid\_file, inputdir
190   \textcolor{keywordtype}{character(len=64)}  :: mdl = \textcolor{stringliteral}{"MOM\_grid\_init set\_grid\_metrics\_from\_mosaic"}
191   \textcolor{keywordtype}{integer} :: err=0, ni, nj, global\_indices(4)
192   \textcolor{keywordtype}{type}(MOM\_domain\_type) :: SGdom \textcolor{comment}{! Supergrid domain}
193   \textcolor{keywordtype}{logical} :: lon\_bug  \textcolor{comment}{! If true use an older buggy answer in the tripolar longitude.}
194   \textcolor{keywordtype}{integer} :: i, j, i2, j2
195   \textcolor{keywordtype}{integer} :: npei,npej
196   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable} :: exni,exnj
197   \textcolor{keywordtype}{integer}        :: start(4), nread(4)
198 
199   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"set\_grid\_metrics\_from\_mosaic(), MOM\_grid\_initialize.F90"})
200 
201   m\_to\_l = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) m\_to\_l = us%m\_to\_L
202   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"GRID\_FILE"}, grid\_file, &
203                  \textcolor{stringliteral}{"Name of the file from which to read horizontal grid data."}, &
204                  fail\_if\_missing=.true.)
205   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"USE\_TRIPOLAR\_GEOLONB\_BUG"}, lon\_bug, &
206                  \textcolor{stringliteral}{"If true, use older code that incorrectly sets the longitude "}//&
207                  \textcolor{stringliteral}{"in some points along the tripolar fold to be off by 360 degrees."}, &
208                  default=.false.)
209   \textcolor{keyword}{call }get\_param(param\_file,  mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."})
210   inputdir = slasher(inputdir)
211   filename = trim(adjustl(inputdir)) // trim(adjustl(grid\_file))
212   \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"INPUTDIR/GRID\_FILE"}, filename)
213   \textcolor{keywordflow}{if} (.not.file\_exists(filename)) &
214     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{" set\_grid\_metrics\_from\_mosaic: Unable to open "}//&
215                            trim(filename))
216 
217   \textcolor{comment}{! Initialize everything to 0.}
218   dxcu(:,:) = 0.0 ; dycu(:,:) = 0.0
219   dxcv(:,:) = 0.0 ; dycv(:,:) = 0.0
220   dxbu(:,:) = 0.0 ; dybu(:,:) = 0.0 ; areabu(:,:) = 0.0
221 
222   \textcolor{comment}{!<MISSING CODE TO READ REFINEMENT LEVEL>}
223   ni = 2*(g%iec-g%isc+1) \textcolor{comment}{! i size of supergrid}
224   nj = 2*(g%jec-g%jsc+1) \textcolor{comment}{! j size of supergrid}
225 
226   \textcolor{comment}{! Define a domain for the supergrid (SGdom)}
227   npei = g%domain%layout(1) ; npej = g%domain%layout(2)
228   \textcolor{keyword}{allocate}(exni(npei)) ; \textcolor{keyword}{allocate}(exnj(npej))
229   \textcolor{keyword}{call }mpp\_get\_domain\_extents(g%domain%mpp\_domain, exni, exnj)
230   \textcolor{keyword}{allocate}(sgdom%mpp\_domain)
231   sgdom%nihalo = 2*g%domain%nihalo+1
232   sgdom%njhalo = 2*g%domain%njhalo+1
233   sgdom%niglobal = 2*g%domain%niglobal
234   sgdom%njglobal = 2*g%domain%njglobal
235   sgdom%layout(:) = g%domain%layout(:)
236   sgdom%io\_layout(:) = g%domain%io\_layout(:)
237   global\_indices(1) = 1+sgdom%nihalo
238   global\_indices(2) = sgdom%niglobal+sgdom%nihalo
239   global\_indices(3) = 1+sgdom%njhalo
240   global\_indices(4) = sgdom%njglobal+sgdom%njhalo
241   exni(:) = 2*exni(:) ; exnj(:) = 2*exnj(:)
242   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(g%domain%maskmap)) \textcolor{keywordflow}{then}
243      \textcolor{keyword}{call }mom\_define\_domain(global\_indices, sgdom%layout, sgdom%mpp\_domain, &
244             xflags=g%domain%X\_FLAGS, yflags=g%domain%Y\_FLAGS, &
245             xhalo=sgdom%nihalo, yhalo=sgdom%njhalo, &
246             xextent=exni,yextent=exnj, &
247             symmetry=.true., name=\textcolor{stringliteral}{"MOM\_MOSAIC"}, maskmap=g%domain%maskmap)
248   \textcolor{keywordflow}{else}
249      \textcolor{keyword}{call }mom\_define\_domain(global\_indices, sgdom%layout, sgdom%mpp\_domain, &
250             xflags=g%domain%X\_FLAGS, yflags=g%domain%Y\_FLAGS, &
251             xhalo=sgdom%nihalo, yhalo=sgdom%njhalo, &
252             xextent=exni,yextent=exnj, &
253             symmetry=.true., name=\textcolor{stringliteral}{"MOM\_MOSAIC"})
254 \textcolor{keywordflow}{  endif}
255 
256   \textcolor{keyword}{call }mom\_define\_io\_domain(sgdom%mpp\_domain, sgdom%io\_layout)
257   \textcolor{keyword}{deallocate}(exni)
258   \textcolor{keyword}{deallocate}(exnj)
259 
260   \textcolor{comment}{! Read X from the supergrid}
261   tmpz(:,:) = 999.
262   \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'x'}, tmpz, sgdom, position=corner)
263 
264   \textcolor{keywordflow}{if} (lon\_bug) \textcolor{keywordflow}{then}
265     \textcolor{keyword}{call }pass\_var(tmpz, sgdom, position=corner)
266   \textcolor{keywordflow}{else}
267     \textcolor{keyword}{call }pass\_var(tmpz, sgdom, position=corner, inner\_halo=0)
268 \textcolor{keywordflow}{  endif}
269   \textcolor{keyword}{call }extrapolate\_metric(tmpz, 2*(g%jsc-g%jsd)+2, missing=999.)
270   \textcolor{keywordflow}{do} j=g%jsd,g%jed ; \textcolor{keywordflow}{do} i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
271     g%geoLonT(i,j) = tmpz(i2-1,j2-1)
272 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
273   \textcolor{keywordflow}{do} j=g%JsdB,g%JedB ; \textcolor{keywordflow}{do} i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
274     g%geoLonBu(i,j) = tmpz(i2,j2)
275 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
276   \textcolor{keywordflow}{do} j=g%jsd,g%jed ; \textcolor{keywordflow}{do} i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
277     g%geoLonCu(i,j) = tmpz(i2,j2-1)
278 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
279   \textcolor{keywordflow}{do} j=g%JsdB,g%JedB ; \textcolor{keywordflow}{do} i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
280     g%geoLonCv(i,j) = tmpz(i2-1,j2)
281 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
282   \textcolor{comment}{! For some reason, this messes up the solution...}
283   \textcolor{comment}{!   call pass\_var(G%geoLonBu, G%domain, position=CORNER)}
284 
285   \textcolor{comment}{! Read Y from the supergrid}
286   tmpz(:,:) = 999.
287   \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'y'}, tmpz, sgdom, position=corner)
288 
289   \textcolor{keyword}{call }pass\_var(tmpz, sgdom, position=corner)
290   \textcolor{keyword}{call }extrapolate\_metric(tmpz, 2*(g%jsc-g%jsd)+2, missing=999.)
291   \textcolor{keywordflow}{do} j=g%jsd,g%jed ; \textcolor{keywordflow}{do} i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
292     g%geoLatT(i,j) = tmpz(i2-1,j2-1)
293 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
294   \textcolor{keywordflow}{do} j=g%JsdB,g%JedB ; \textcolor{keywordflow}{do} i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
295     g%geoLatBu(i,j) = tmpz(i2,j2)
296 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
297   \textcolor{keywordflow}{do} j=g%jsd,g%jed ; \textcolor{keywordflow}{do} i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
298     g%geoLatCu(i,j) = tmpz(i2,j2-1)
299 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
300   \textcolor{keywordflow}{do} j=g%JsdB,g%JedB ; \textcolor{keywordflow}{do} i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
301     g%geoLatCv(i,j) = tmpz(i2-1,j2)
302 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
303 
304   \textcolor{comment}{! Read DX,DY from the supergrid}
305   tmpu(:,:) = 0. ; tmpv(:,:) = 0.
306   \textcolor{keyword}{call }mom\_read\_data(filename,\textcolor{stringliteral}{'dx'},tmpv,sgdom,position=north\_face)
307   \textcolor{keyword}{call }mom\_read\_data(filename,\textcolor{stringliteral}{'dy'},tmpu,sgdom,position=east\_face)
308   \textcolor{keyword}{call }pass\_vector(tmpu, tmpv, sgdom, to\_all+scalar\_pair, cgrid\_ne)
309   \textcolor{keyword}{call }extrapolate\_metric(tmpv, 2*(g%jsc-g%jsd)+2, missing=0.)
310   \textcolor{keyword}{call }extrapolate\_metric(tmpu, 2*(g%jsc-g%jsd)+2, missing=0.)
311 
312   \textcolor{keywordflow}{do} j=g%jsd,g%jed ; \textcolor{keywordflow}{do} i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
313     dxt(i,j) = tmpv(i2-1,j2-1) + tmpv(i2,j2-1)
314     dyt(i,j) = tmpu(i2-1,j2-1) + tmpu(i2-1,j2)
315 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
316 
317   \textcolor{keywordflow}{do} j=g%jsd,g%jed ; \textcolor{keywordflow}{do} i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
318     dxcu(i,j) = tmpv(i2,j2-1) + tmpv(i2+1,j2-1)
319     dycu(i,j) = tmpu(i2,j2-1) + tmpu(i2,j2)
320 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
321 
322   \textcolor{keywordflow}{do} j=g%JsdB,g%JedB ; \textcolor{keywordflow}{do} i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
323     dxcv(i,j) = tmpv(i2-1,j2) + tmpv(i2,j2)
324     dycv(i,j) = tmpu(i2-1,j2) + tmpu(i2-1,j2+1)
325 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
326 
327   \textcolor{keywordflow}{do} j=g%JsdB,g%JedB ; \textcolor{keywordflow}{do} i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
328     dxbu(i,j) = tmpv(i2,j2) + tmpv(i2+1,j2)
329     dybu(i,j) = tmpu(i2,j2) + tmpu(i2,j2+1)
330 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
331 
332   \textcolor{comment}{! Read AREA from the supergrid}
333   tmpt(:,:) = 0.
334   \textcolor{keyword}{call }mom\_read\_data(filename, \textcolor{stringliteral}{'area'}, tmpt, sgdom)
335   \textcolor{keyword}{call }pass\_var(tmpt, sgdom)
336   \textcolor{keyword}{call }extrapolate\_metric(tmpt, 2*(g%jsc-g%jsd)+2, missing=0.)
337 
338   \textcolor{keywordflow}{do} j=g%jsd,g%jed ; \textcolor{keywordflow}{do} i=g%isd,g%ied ; i2 = 2*i ; j2 = 2*j
339     areat(i,j) = (tmpt(i2-1,j2-1) + tmpt(i2,j2)) + &
340                  (tmpt(i2-1,j2) + tmpt(i2,j2-1))
341 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
342   \textcolor{keywordflow}{do} j=g%JsdB,g%JedB ; \textcolor{keywordflow}{do} i=g%IsdB,g%IedB ; i2 = 2*i ; j2 = 2*j
343     areabu(i,j) = (tmpt(i2,j2) + tmpt(i2+1,j2+1)) + &
344                   (tmpt(i2,j2+1) + tmpt(i2+1,j2))
345 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
346 
347   ni=sgdom%niglobal
348   nj=sgdom%njglobal
349   \textcolor{keyword}{call }mpp\_deallocate\_domain(sgdom%mpp\_domain)
350   \textcolor{keyword}{deallocate}(sgdom%mpp\_domain)
351 
352   \textcolor{keyword}{call }pass\_vector(dycu, dxcv, g%Domain, to\_all+scalar\_pair, cgrid\_ne)
353   \textcolor{keyword}{call }pass\_vector(dxcu, dycv, g%Domain, to\_all+scalar\_pair, cgrid\_ne)
354   \textcolor{keyword}{call }pass\_vector(dxbu, dybu, g%Domain, to\_all+scalar\_pair, bgrid\_ne)
355   \textcolor{keyword}{call }pass\_var(areat, g%Domain)
356   \textcolor{keyword}{call }pass\_var(areabu, g%Domain, position=corner)
357 
358   \textcolor{keywordflow}{do} i=g%isd,g%ied ; \textcolor{keywordflow}{do} j=g%jsd,g%jed
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)
360 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
361   \textcolor{keywordflow}{do} i=g%IsdB,g%IedB ; \textcolor{keywordflow}{do} j=g%jsd,g%jed
362     g%dxCu(i,j) = m\_to\_l*dxcu(i,j) ; g%dyCu(i,j) = m\_to\_l*dycu(i,j)
363 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
364   \textcolor{keywordflow}{do} i=g%isd,g%ied ; \textcolor{keywordflow}{do} j=g%JsdB,g%JedB
365     g%dxCv(i,j) = m\_to\_l*dxcv(i,j) ; g%dyCv(i,j) = m\_to\_l*dycv(i,j)
366 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
367   \textcolor{keywordflow}{do} i=g%IsdB,g%IedB ; \textcolor{keywordflow}{do} j=g%JsdB,g%JedB
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)
369 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
370 
371   \textcolor{comment}{! Construct axes for diagnostic output (only necessary because "ferret" uses}
372   \textcolor{comment}{! broken convention for interpretting netCDF files).}
373   start(:) = 1 ; nread(:) = 1
374   start(2) = 2 ; nread(1) = ni+1 ; nread(2) = 2
375   \textcolor{keyword}{allocate}( tmpglbl(ni+1,2) )
376   \textcolor{keywordflow}{if} (is\_root\_pe()) &
377     \textcolor{keyword}{call }read\_data(filename, \textcolor{stringliteral}{"x"}, tmpglbl, start, nread, no\_domain=.true.)
378   \textcolor{keyword}{call }broadcast(tmpglbl, 2*(ni+1), root\_pe())
379 
380   \textcolor{comment}{! I don't know why the second axis is 1 or 2 here. -RWH}
381   \textcolor{keywordflow}{do} i=g%isg,g%ieg
382     g%gridLonT(i) = tmpglbl(2*(i-g%isg)+2,2)
383 \textcolor{keywordflow}{  enddo}
384   \textcolor{comment}{! Note that the dynamic grid always uses symmetric memory for the global}
385   \textcolor{comment}{! arrays G%gridLatB and G%gridLonB.}
386   \textcolor{keywordflow}{do} i=g%isg-1,g%ieg
387     g%gridLonB(i) = tmpglbl(2*(i-g%isg)+3,1)
388 \textcolor{keywordflow}{  enddo}
389   \textcolor{keyword}{deallocate}( tmpglbl )
390 
391   \textcolor{keyword}{allocate}( tmpglbl(1, nj+1) )
392   start(:) = 1 ; nread(:) = 1
393   start(1) = int(ni/4)+1 ; nread(2) = nj+1
394   \textcolor{keywordflow}{if} (is\_root\_pe()) &
395     \textcolor{keyword}{call }read\_data(filename, \textcolor{stringliteral}{"y"}, tmpglbl, start, nread, no\_domain=.true.)
396   \textcolor{keyword}{call }broadcast(tmpglbl, nj+1, root\_pe())
397 
398   \textcolor{keywordflow}{do} j=g%jsg,g%jeg
399     g%gridLatT(j) = tmpglbl(1,2*(j-g%jsg)+2)
400 \textcolor{keywordflow}{  enddo}
401   \textcolor{keywordflow}{do} j=g%jsg-1,g%jeg
402     g%gridLatB(j) = tmpglbl(1,2*(j-g%jsg)+3)
403 \textcolor{keywordflow}{  enddo}
404   \textcolor{keyword}{deallocate}( tmpglbl )
405 
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{\tt in,out}  & {\em g} & The dynamic horizontal grid type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file structure\\
\hline
\mbox{\tt 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}
697   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{           !< The dynamic horizontal grid type}
698   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)}     :: param\_file\textcolor{comment}{  !< Parameter file structure}
699   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{    !< A dimensional unit scaling type}
700   \textcolor{comment}{! Local variables}
701   \textcolor{keywordtype}{integer} :: i, j, isd, ied, jsd, jed
702   \textcolor{keywordtype}{integer} :: I\_off, J\_off
703   \textcolor{keywordtype}{type}(GPS) :: GP
704   \textcolor{keywordtype}{character(len=128)} :: warnmesg
705   \textcolor{keywordtype}{character(len=48)}  :: mdl = \textcolor{stringliteral}{"MOM\_grid\_init set\_grid\_metrics\_mercator"}
706   \textcolor{keywordtype}{real} :: PI, PI\_2\textcolor{comment}{! PI = 3.1415926... as 4*atan(1), PI\_2 = (PI) /2.0}
707   \textcolor{keywordtype}{real} :: y\_q, y\_h, jd, x\_q, x\_h, id
708   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%jsd:G%jed)} :: &
709     xh, yh \textcolor{comment}{! Latitude and longitude of h points in radians.}
710   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%IsdB:G%IedB,G%jsd:G%jed)} :: &
711     xu, yu \textcolor{comment}{! Latitude and longitude of u points in radians.}
712   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isd:G%ied,G%JsdB:G%JedB)} :: &
713     xv, yv \textcolor{comment}{! Latitude and longitude of v points in radians.}
714   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%IsdB:G%IedB,G%JsdB:G%JedB)} :: &
715     xq, yq \textcolor{comment}{! Latitude and longitude of q points in radians.}
716   \textcolor{keywordtype}{real} :: fnRef           \textcolor{comment}{! fnRef is the value of Int\_dj\_dy or}
717                           \textcolor{comment}{! Int\_dj\_dy at a latitude or longitude that is}
718   \textcolor{keywordtype}{real} :: jRef, iRef      \textcolor{comment}{! being set to be at grid index jRef or iRef.}
719   \textcolor{keywordtype}{real} :: m\_to\_L  \textcolor{comment}{! A unit conversion factor [L m-1 ~> nondim]}
720   \textcolor{keywordtype}{integer} :: itt1, itt2
721   \textcolor{keywordtype}{logical} :: debug = .false., simple\_area = .true.
722   \textcolor{keywordtype}{integer} :: is, ie, js, je, Isq, Ieq, Jsq, Jeq, IsdB, IedB, JsdB, JedB
723 
724   \textcolor{comment}{!   All of the metric terms should be defined over the domain from}
725   \textcolor{comment}{! isd to ied.  Outside of the physical domain, both the metrics}
726   \textcolor{comment}{! and their inverses may be set to zero.}
727   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
728   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
729   isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
730   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
731   i\_off = g%idg\_offset ; j\_off = g%jdg\_offset
732 
733   gp%niglobal = g%Domain%niglobal
734   gp%njglobal = g%Domain%njglobal
735 
736   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"set\_grid\_metrics\_mercator(), MOM\_grid\_initialize.F90"})
737 
738   m\_to\_l = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) m\_to\_l = us%m\_to\_L
739   \textcolor{comment}{!   Calculate the values of the metric terms that might be used}
740   \textcolor{comment}{! and save them in arrays.}
741   pi = 4.0*atan(1.0) ; pi\_2 = 0.5*pi
742 
743   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SOUTHLAT"}, gp%south\_lat, &
744                  \textcolor{stringliteral}{"The southern latitude of the domain."}, units=\textcolor{stringliteral}{"degrees"}, &
745                  fail\_if\_missing=.true.)
746   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LENLAT"}, gp%len\_lat, &
747                  \textcolor{stringliteral}{"The latitudinal length of the domain."}, units=\textcolor{stringliteral}{"degrees"}, &
748                  fail\_if\_missing=.true.)
749   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"WESTLON"}, gp%west\_lon, &
750                  \textcolor{stringliteral}{"The western longitude of the domain."}, units=\textcolor{stringliteral}{"degrees"}, &
751                  default=0.0)
752   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LENLON"}, gp%len\_lon, &
753                  \textcolor{stringliteral}{"The longitudinal length of the domain."}, units=\textcolor{stringliteral}{"degrees"}, &
754                  fail\_if\_missing=.true.)
755   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RAD\_EARTH"}, gp%Rad\_Earth, &
756                  \textcolor{stringliteral}{"The radius of the Earth."}, units=\textcolor{stringliteral}{"m"}, default=6.378e6)
757   g%south\_lat = gp%south\_lat ; g%len\_lat = gp%len\_lat
758   g%west\_lon = gp%west\_lon ; g%len\_lon = gp%len\_lon
759   g%Rad\_Earth = gp%Rad\_Earth
760   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"ISOTROPIC"}, gp%isotropic, &
761                  \textcolor{stringliteral}{"If true, an isotropic grid on a sphere (also known as "}//&
762                  \textcolor{stringliteral}{"a Mercator grid) is used. With an isotropic grid, the "}//&
763                  \textcolor{stringliteral}{"meridional extent of the domain (LENLAT), the zonal "}//&
764                  \textcolor{stringliteral}{"extent (LENLON), and the number of grid points in each "}//&
765                  \textcolor{stringliteral}{"direction are \_not\_ independent. In MOM the meridional "}//&
766                  \textcolor{stringliteral}{"extent is determined to fit the zonal extent and the "}//&
767                  \textcolor{stringliteral}{"number of grid points, while grid is perfectly isotropic."}, &
768                  default=.false.)
769   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"EQUATOR\_REFERENCE"}, gp%equator\_reference, &
770                  \textcolor{stringliteral}{"If true, the grid is defined to have the equator at the "}//&
771                  \textcolor{stringliteral}{"nearest q- or h- grid point to (-LOWLAT*NJGLOBAL/LENLAT)."}, &
772                  default=.true.)
773   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LAT\_ENHANCE\_FACTOR"}, gp%Lat\_enhance\_factor, &
774                  \textcolor{stringliteral}{"The amount by which the meridional resolution is "}//&
775                  \textcolor{stringliteral}{"enhanced within LAT\_EQ\_ENHANCE of the equator."}, &
776                  units=\textcolor{stringliteral}{"nondim"}, default=1.0)
777   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LAT\_EQ\_ENHANCE"}, gp%Lat\_eq\_enhance, &
778                  \textcolor{stringliteral}{"The latitude range to the north and south of the equator "}//&
779                  \textcolor{stringliteral}{"over which the resolution is enhanced."}, units=\textcolor{stringliteral}{"degrees"}, &
780                  default=0.0)
781 
782   \textcolor{comment}{!   With an isotropic grid, the north-south extent of the domain,}
783   \textcolor{comment}{! the east-west extent, and the number of grid points in each}
784   \textcolor{comment}{! direction are \_not\_ independent.  Here the north-south extent}
785   \textcolor{comment}{! will be determined to fit the east-west extent and the number of}
786   \textcolor{comment}{! grid points.  The grid is perfectly isotropic.}
787   \textcolor{keywordflow}{if} (gp%equator\_reference) \textcolor{keywordflow}{then}
788     \textcolor{comment}{! With the following expression, the equator will always be placed}
789     \textcolor{comment}{! on either h or q points, in a position consistent with the ratio}
790     \textcolor{comment}{! GP%south\_lat to GP%len\_lat.}
791     jref =  (g%jsg-1) + 0.5*floor(gp%njglobal*((-1.0*gp%south\_lat*2.0)/gp%len\_lat)+0.5)
792     fnref = int\_dj\_dy(0.0, gp)
793   \textcolor{keywordflow}{else}
794     \textcolor{comment}{! The following line sets the reference latitude GP%south\_lat at j=js-1 (or -2?)}
795     jref = (g%jsg-1)
796     fnref = int\_dj\_dy((gp%south\_lat*pi/180.0), gp)
797 \textcolor{keywordflow}{  endif}
798 
799   \textcolor{comment}{! These calculations no longer depend on the the order in which they}
800   \textcolor{comment}{! are performed because they all use the same (poor) starting guess and}
801   \textcolor{comment}{! iterate to convergence.}
802   \textcolor{comment}{! Note that the dynamic grid always uses symmetric memory for the global}
803   \textcolor{comment}{! arrays G%gridLatB and G%gridLonB.}
804   \textcolor{keywordflow}{do} j=g%jsg-1,g%jeg
805     jd = fnref + (j - jref)
806     y\_q = find\_root(int\_dj\_dy, dy\_dj, gp, jd, 0.0, -1.0*pi\_2, pi\_2, itt2)
807     g%gridLatB(j) = y\_q*180.0/pi
808     \textcolor{comment}{! if (is\_root\_pe()) &}
809     \textcolor{comment}{!   write(*, '("J, y\_q = ",I4,ES14.4," itts = ",I4)')  j, y\_q, itt2}
810 \textcolor{keywordflow}{  enddo}
811   \textcolor{keywordflow}{do} j=g%jsg,g%jeg
812     jd = fnref + (j - jref) - 0.5
813     y\_h = find\_root(int\_dj\_dy, dy\_dj, gp, jd, 0.0, -1.0*pi\_2, pi\_2, itt1)
814     g%gridLatT(j) = y\_h*180.0/pi
815     \textcolor{comment}{! if (is\_root\_pe()) &}
816     \textcolor{comment}{!   write(*, '("j, y\_h = ",I4,ES14.4," itts = ",I4)')  j, y\_h, itt1}
817 \textcolor{keywordflow}{  enddo}
818   \textcolor{keywordflow}{do} j=jsdb+j\_off,jedb+j\_off
819     jd = fnref + (j - jref)
820     y\_q = find\_root(int\_dj\_dy, dy\_dj, gp, jd, 0.0, -1.0*pi\_2, pi\_2, itt2)
821     \textcolor{keywordflow}{do} i=isdb,iedb ; yq(i,j-j\_off) = y\_q ;\textcolor{keywordflow}{ enddo}
822     \textcolor{keywordflow}{do} i=isd,ied ; yv(i,j-j\_off) = y\_q ;\textcolor{keywordflow}{ enddo}
823 \textcolor{keywordflow}{  enddo}
824   \textcolor{keywordflow}{do} j=jsd+j\_off,jed+j\_off
825     jd = fnref + (j - jref) - 0.5
826     y\_h = find\_root(int\_dj\_dy, dy\_dj, gp, jd, 0.0, -1.0*pi\_2, pi\_2, itt1)
827     \textcolor{keywordflow}{if} ((j >= jsd+j\_off) .and. (j <= jed+j\_off)) \textcolor{keywordflow}{then}
828       \textcolor{keywordflow}{do} i=isd,ied ; yh(i,j-j\_off) = y\_h ;\textcolor{keywordflow}{ enddo}
829       \textcolor{keywordflow}{do} i=isdb,iedb ; yu(i,j-j\_off) = y\_h ;\textcolor{keywordflow}{ enddo}
830 \textcolor{keywordflow}{    endif}
831 \textcolor{keywordflow}{  enddo}
832 
833   \textcolor{comment}{! Determine the longitudes of the various points.}
834 
835   \textcolor{comment}{! These two lines place the western edge of the domain at GP%west\_lon.}
836   iref = (g%isg-1) + gp%niglobal
837   fnref = int\_di\_dx(((gp%west\_lon+gp%len\_lon)*pi/180.0), gp)
838 
839   \textcolor{comment}{! These calculations no longer depend on the the order in which they}
840   \textcolor{comment}{! are performed because they all use the same (poor) starting guess and}
841   \textcolor{comment}{! iterate to convergence.}
842   \textcolor{keywordflow}{do} i=g%isg-1,g%ieg
843     id = fnref + (i - iref)
844     x\_q = find\_root(int\_di\_dx, dx\_di, gp, id, 0.0, -4.0*pi, 4.0*pi, itt2)
845     g%gridLonB(i) = x\_q*180.0/pi
846 \textcolor{keywordflow}{  enddo}
847   \textcolor{keywordflow}{do} i=g%isg,g%ieg
848     id = fnref + (i - iref) - 0.5
849     x\_h = find\_root(int\_di\_dx, dx\_di, gp, id, 0.0, -4.0*pi, 4.0*pi, itt1)
850     g%gridLonT(i) = x\_h*180.0/pi
851 \textcolor{keywordflow}{  enddo}
852   \textcolor{keywordflow}{do} i=isdb+i\_off,iedb+i\_off
853     id = fnref + (i - iref)
854     x\_q = find\_root(int\_di\_dx, dx\_di, gp, id, 0.0, -4.0*pi, 4.0*pi, itt2)
855     \textcolor{keywordflow}{do} j=jsdb,jedb ; xq(i-i\_off,j) = x\_q ;\textcolor{keywordflow}{ enddo}
856     \textcolor{keywordflow}{do} j=jsd,jed ; xu(i-i\_off,j) = x\_q ;\textcolor{keywordflow}{ enddo}
857 \textcolor{keywordflow}{  enddo}
858   \textcolor{keywordflow}{do} i=isd+i\_off,ied+i\_off
859     id = fnref + (i - iref) - 0.5
860     x\_h = find\_root(int\_di\_dx, dx\_di, gp, id, 0.0, -4.0*pi, 4.0*pi, itt1)
861     \textcolor{keywordflow}{do} j=jsd,jed ; xh(i-i\_off,j) = x\_h ;\textcolor{keywordflow}{ enddo}
862     \textcolor{keywordflow}{do} j=jsdb,jedb ; xv(i-i\_off,j) = x\_h ;\textcolor{keywordflow}{ enddo}
863 \textcolor{keywordflow}{  enddo}
864 
865   \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isdb,iedb
866     g%geoLonBu(i,j) = xq(i,j)*180.0/pi
867     g%geoLatBu(i,j) = yq(i,j)*180.0/pi
868     g%dxBu(i,j) = m\_to\_l*ds\_di(xq(i,j), yq(i,j), gp)
869     g%dyBu(i,j) = m\_to\_l*ds\_dj(xq(i,j), yq(i,j), gp)
870 
871     g%areaBu(i,j) = g%dxBu(i,j) * g%dyBu(i,j)
872     g%IareaBu(i,j) = 1.0 / (g%areaBu(i,j))
873 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
874 
875   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
876     g%geoLonT(i,j) = xh(i,j)*180.0/pi
877     g%geoLatT(i,j) = yh(i,j)*180.0/pi
878     g%dxT(i,j) = m\_to\_l*ds\_di(xh(i,j), yh(i,j), gp)
879     g%dyT(i,j) = m\_to\_l*ds\_dj(xh(i,j), yh(i,j), gp)
880 
881     g%areaT(i,j) = g%dxT(i,j)*g%dyT(i,j)
882     g%IareaT(i,j) = 1.0 / (g%areaT(i,j))
883 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
884 
885   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb
886     g%geoLonCu(i,j) = xu(i,j)*180.0/pi
887     g%geoLatCu(i,j) = yu(i,j)*180.0/pi
888     g%dxCu(i,j) = m\_to\_l*ds\_di(xu(i,j), yu(i,j), gp)
889     g%dyCu(i,j) = m\_to\_l*ds\_dj(xu(i,j), yu(i,j), gp)
890 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
891 
892   \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied
893     g%geoLonCv(i,j) = xv(i,j)*180.0/pi
894     g%geoLatCv(i,j) = yv(i,j)*180.0/pi
895     g%dxCv(i,j) = m\_to\_l*ds\_di(xv(i,j), yv(i,j), gp)
896     g%dyCv(i,j) = m\_to\_l*ds\_dj(xv(i,j), yv(i,j), gp)
897 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
898 
899   \textcolor{keywordflow}{if} (.not.simple\_area) \textcolor{keywordflow}{then}
900     \textcolor{keywordflow}{do} j=jsdb+1,jed ; \textcolor{keywordflow}{do} i=isdb+1,ied
901       g%areaT(i,j) = m\_to\_l**2*gp%Rad\_Earth**2 * &
902           (dl(xq(i-1,j-1),xq(i-1,j),yq(i-1,j-1),yq(i-1,j)) + &
903           (dl(xq(i-1,j),xq(i,j),yq(i-1,j),yq(i,j)) +          &
904           (dl(xq(i,j),xq(i,j-1),yq(i,j),yq(i,j-1)) +          &
905            dl(xq(i,j-1),xq(i-1,j-1),yq(i,j-1),yq(i-1,j-1)))))
906 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{enddo}
907     \textcolor{keywordflow}{if} ((isdb == isd) .or. (jsdb == jsq)) \textcolor{keywordflow}{then}
908       \textcolor{comment}{! Fill in row and column 1 to calculate the area in the southernmost}
909       \textcolor{comment}{! and westernmost land cells when we are not using symmetric memory.}
910       \textcolor{comment}{! The pass\_var call updates these values if they are not land cells.}
911       g%areaT(isd+1,jsd) = g%areaT(isd+1,jsd+1)
912       \textcolor{keywordflow}{do} j=jsd,jed ; g%areaT(isd,j) = g%areaT(isd+1,j) ;\textcolor{keywordflow}{ enddo}
913       \textcolor{keywordflow}{do} i=isd,ied ; g%areaT(i,jsd) = g%areaT(i,jsd+1) ;\textcolor{keywordflow}{ enddo}
914       \textcolor{comment}{! Now replace the data in the halos, if value values exist.}
915       \textcolor{keyword}{call }pass\_var(g%areaT,g%Domain)
916 \textcolor{keywordflow}{    endif}
917     \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
918       g%IareaT(i,j) = 1.0 / (g%areaT(i,j))
919 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
920 \textcolor{keywordflow}{  endif}
921 
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{\tt in,out}  & {\em g} & The dynamic horizontal grid type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file structure\\
\hline
\mbox{\tt 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}
558   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{           !< The dynamic horizontal grid type}
559   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)}     :: param\_file\textcolor{comment}{  !< Parameter file structure}
560   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: US\textcolor{comment}{    !< A dimensional unit scaling type}
561   \textcolor{comment}{! Local variables}
562   \textcolor{keywordtype}{real} :: PI, PI\_180\textcolor{comment}{! PI = 3.1415926... as 4*atan(1)}
563   \textcolor{keywordtype}{integer} :: i, j, isd, ied, jsd, jed
564   \textcolor{keywordtype}{integer} :: is, ie, js, je, Isq, Ieq, Jsq, Jeq, IsdB, IedB, JsdB, JedB
565   \textcolor{keywordtype}{integer} :: i\_offset, j\_offset
566   \textcolor{keywordtype}{real} :: grid\_latT(G%jsd:G%jed), grid\_latB(G%JsdB:G%JedB)
567   \textcolor{keywordtype}{real} :: grid\_lonT(G%isd:G%ied), grid\_lonB(G%IsdB:G%IedB)
568   \textcolor{keywordtype}{real} :: dLon,dLat,latitude,longitude,dL\_di
569   \textcolor{keywordtype}{real} :: m\_to\_L  \textcolor{comment}{! A unit conversion factor [L m-1 ~> nondim]}
570   \textcolor{keywordtype}{character(len=48)}  :: mdl  = \textcolor{stringliteral}{"MOM\_grid\_init set\_grid\_metrics\_spherical"}
571 
572   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
573   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
574   isq = g%IscB ; ieq = g%IecB ; jsq = g%JscB ; jeq = g%JecB
575   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
576   i\_offset = g%idg\_offset ; j\_offset = g%jdg\_offset
577 
578   \textcolor{keyword}{call }calltree\_enter(\textcolor{stringliteral}{"set\_grid\_metrics\_spherical(), MOM\_grid\_initialize.F90"})
579   m\_to\_l = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) m\_to\_l = us%m\_to\_L
580 
581 \textcolor{comment}{!    Calculate the values of the metric terms that might be used}
582 \textcolor{comment}{!  and save them in arrays.}
583   pi = 4.0*atan(1.0); pi\_180 = atan(1.0)/45.
584 
585   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"SOUTHLAT"}, g%south\_lat, &
586                  \textcolor{stringliteral}{"The southern latitude of the domain."}, units=\textcolor{stringliteral}{"degrees"}, &
587                  fail\_if\_missing=.true.)
588   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LENLAT"}, g%len\_lat, &
589                  \textcolor{stringliteral}{"The latitudinal length of the domain."}, units=\textcolor{stringliteral}{"degrees"}, &
590                  fail\_if\_missing=.true.)
591   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"WESTLON"}, g%west\_lon, &
592                  \textcolor{stringliteral}{"The western longitude of the domain."}, units=\textcolor{stringliteral}{"degrees"}, &
593                  default=0.0)
594   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"LENLON"}, g%len\_lon, &
595                  \textcolor{stringliteral}{"The longitudinal length of the domain."}, units=\textcolor{stringliteral}{"degrees"}, &
596                  fail\_if\_missing=.true.)
597   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RAD\_EARTH"}, g%Rad\_Earth, &
598                  \textcolor{stringliteral}{"The radius of the Earth."}, units=\textcolor{stringliteral}{"m"}, default=6.378e6)
599 
600   dlon = g%len\_lon/g%Domain%niglobal
601   dlat = g%len\_lat/g%Domain%njglobal
602 
603   \textcolor{comment}{! Note that the dynamic grid always uses symmetric memory for the global}
604   \textcolor{comment}{! arrays G%gridLatB and G%gridLonB.}
605   \textcolor{keywordflow}{do} j=g%jsg-1,g%jeg
606     latitude = g%south\_lat + dlat*(\textcolor{keywordtype}{REAL}(J-(G%jsg-1)))
607     g%gridLatB(j) = min(max(latitude,-90.),90.)
608 \textcolor{keywordflow}{  enddo}
609   \textcolor{keywordflow}{do} j=g%jsg,g%jeg
610     latitude = g%south\_lat + dlat*(\textcolor{keywordtype}{REAL}(j-G%jsg)+0.5)
611     g%gridLatT(j) = min(max(latitude,-90.),90.)
612 \textcolor{keywordflow}{  enddo}
613   \textcolor{keywordflow}{do} i=g%isg-1,g%ieg
614     g%gridLonB(i) = g%west\_lon + dlon*(\textcolor{keywordtype}{REAL}(I-(G%isg-1)))
615 \textcolor{keywordflow}{  enddo}
616   \textcolor{keywordflow}{do} i=g%isg,g%ieg
617     g%gridLonT(i) = g%west\_lon + dlon*(\textcolor{keywordtype}{REAL}(i-G%isg)+0.5)
618 \textcolor{keywordflow}{  enddo}
619 
620   \textcolor{keywordflow}{do} j=jsdb,jedb
621     latitude = g%south\_lat + dlat* \textcolor{keywordtype}{REAL}(J+J\_offset-(G%jsg-1))
622     grid\_latb(j) = min(max(latitude,-90.),90.)
623 \textcolor{keywordflow}{  enddo}
624   \textcolor{keywordflow}{do} j=jsd,jed
625     latitude = g%south\_lat + dlat*(\textcolor{keywordtype}{REAL}(j+J\_offset-G%jsg)+0.5)
626     grid\_latt(j) = min(max(latitude,-90.),90.)
627 \textcolor{keywordflow}{  enddo}
628   \textcolor{keywordflow}{do} i=isdb,iedb
629     grid\_lonb(i) = g%west\_lon + dlon*\textcolor{keywordtype}{REAL}(I+I\_offset-(G%isg-1))
630 \textcolor{keywordflow}{  enddo}
631   \textcolor{keywordflow}{do} i=isd,ied
632     grid\_lont(i) = g%west\_lon + dlon*(\textcolor{keywordtype}{REAL}(i+I\_offset-G%isg)+0.5)
633 \textcolor{keywordflow}{  enddo}
634 
635   dl\_di = (g%len\_lon * 4.0*atan(1.0)) / (180.0 * g%Domain%niglobal)
636   \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isdb,iedb
637     g%geoLonBu(i,j) = grid\_lonb(i)
638     g%geoLatBu(i,j) = grid\_latb(j)
639 
640     \textcolor{comment}{! The following line is needed to reproduce the solution from}
641     \textcolor{comment}{! set\_grid\_metrics\_mercator when used to generate a simple spherical grid.}
642     g%dxBu(i,j) = m\_to\_l*g%Rad\_Earth * cos( g%geoLatBu(i,j)*pi\_180 ) * dl\_di
643 \textcolor{comment}{!   G%dxBu(I,J) = m\_to\_L*G%Rad\_Earth * dLon*PI\_180 * COS( G%geoLatBu(I,J)*PI\_180 )}
644     g%dyBu(i,j) = m\_to\_l*g%Rad\_Earth * dlat*pi\_180
645     g%areaBu(i,j) = g%dxBu(i,j) * g%dyBu(i,j)
646 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
647 
648   \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied
649     g%geoLonCv(i,j) = grid\_lont(i)
650     g%geoLatCv(i,j) = grid\_latb(j)
651 
652     \textcolor{comment}{! The following line is needed to reproduce the solution from}
653     \textcolor{comment}{! set\_grid\_metrics\_mercator when used to generate a simple spherical grid.}
654     g%dxCv(i,j) = m\_to\_l*g%Rad\_Earth * cos( g%geoLatCv(i,j)*pi\_180 ) * dl\_di
655 \textcolor{comment}{!   G%dxCv(i,J) = m\_to\_L*G%Rad\_Earth * (dLon*PI\_180) * COS( G%geoLatCv(i,J)*PI\_180 )}
656     g%dyCv(i,j) = m\_to\_l*g%Rad\_Earth * dlat*pi\_180
657 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
658 
659   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb
660     g%geoLonCu(i,j) = grid\_lonb(i)
661     g%geoLatCu(i,j) = grid\_latt(j)
662 
663     \textcolor{comment}{! The following line is needed to reproduce the solution from}
664     \textcolor{comment}{! set\_grid\_metrics\_mercator when used to generate a simple spherical grid.}
665     g%dxCu(i,j) = m\_to\_l*g%Rad\_Earth * cos( g%geoLatCu(i,j)*pi\_180 ) * dl\_di
666 \textcolor{comment}{!   G%dxCu(I,j) = m\_to\_L*G%Rad\_Earth * dLon*PI\_180 * COS( latitude )}
667     g%dyCu(i,j) = m\_to\_l*g%Rad\_Earth * dlat*pi\_180
668 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
669 
670   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied
671     g%geoLonT(i,j) = grid\_lont(i)
672     g%geoLatT(i,j) = grid\_latt(j)
673 
674     \textcolor{comment}{! The following line is needed to reproduce the solution from}
675     \textcolor{comment}{! set\_grid\_metrics\_mercator when used to generate a simple spherical grid.}
676     g%dxT(i,j) = m\_to\_l*g%Rad\_Earth * cos( g%geoLatT(i,j)*pi\_180 ) * dl\_di
677 \textcolor{comment}{!   G%dxT(i,j) = G%Rad\_Earth * dLon*PI\_180 * COS( latitude )}
678     g%dyT(i,j) = m\_to\_l*g%Rad\_Earth * dlat*pi\_180
679 
680 \textcolor{comment}{!   latitude = G%geoLatCv(i,J)*PI\_180             ! In radians}
681 \textcolor{comment}{!   dL\_di    = G%geoLatCv(i,max(jsd,J-1))*PI\_180  ! In radians}
682 \textcolor{comment}{!   G%areaT(i,j) = m\_to\_L**2 * Rad\_Earth**2*dLon*dLat*ABS(SIN(latitude)-SIN(dL\_di))}
683     g%areaT(i,j) = g%dxT(i,j) * g%dyT(i,j)
684 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
685 
686   \textcolor{keyword}{call }calltree\_leave(\textcolor{stringliteral}{"set\_grid\_metrics\_spherical()"})
\end{DoxyCode}
