\hypertarget{namespacemom__grid}{}\doxysection{mom\+\_\+grid Module Reference}
\label{namespacemom__grid}\index{mom\_grid@{mom\_grid}}


\doxysubsection{Detailed Description}
Provides the ocean grid type. 

Grid metrics and their inverses are labelled according to their staggered location on a Arakawa C (or B) grid.
\begin{DoxyItemize}
\item Metrics centered on h-\/ or T-\/points are labelled T, e.\+g. dxT is the distance across the cell in the x-\/direction.
\item Metrics centered on u-\/points are labelled Cu (C-\/grid u location). e.\+g. dy\+Cu is the y-\/distance between two corners of a T-\/cell.
\item Metrics centered on v-\/points are labelled Cv (C-\/grid v location). e.\+g. dy\+Cv is the y-\/distance between two -\/points.
\item Metrics centered on q-\/points are labelled Bu (B-\/grid u,v location). e.\+g. area\+Bu is the area centered on a q-\/point.
\end{DoxyItemize}

 location on an T-\/cell and around a q-\/point."

Areas centered at T-\/, u-\/, v-\/ and q-\/ points are {\ttfamily areaT}, {\ttfamily area\+Cu}, {\ttfamily area\+Cv} and {\ttfamily area\+Bu} respectively.

The reciprocal of metrics are pre-\/calculated and also stored in the \mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}} with a I prepended to the name. For example, {\ttfamily 1./areaT} is called {\ttfamily IareaT}, and {\ttfamily 1./dy\+Cv} is {\ttfamily Idy\+Cv}.

Geographic latitude and longitude (or model coordinates if not on a sphere) are stored in {\ttfamily geo\+LatT}, {\ttfamily geo\+LonT} for T-\/points. u-\/, v-\/ and q-\/ point coordinates are follow same pattern of replacing T with Cu, Cv and Bu respectively.

Each location also has a 2D mask indicating whether the entire column is land or ocean. {\ttfamily mask2dT} is 1 if the column is wet or 0 if the T-\/cell is land. {\ttfamily mask2d\+Cu} is 1 if both neighboring column are ocean, and 0 if either is land. \doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}
\begin{DoxyCompactList}\small\item\em Ocean grid type. See \mbox{\hyperlink{namespacemom__grid}{mom\+\_\+grid}} for details. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__grid_a1de9705f83b687ad9a711630a95fe52c}{mom\+\_\+grid\+\_\+init}} (G, param\+\_\+file, US, HI, global\+\_\+indexing, bathymetry\+\_\+at\+\_\+vel)
\begin{DoxyCompactList}\small\item\em M\+O\+M\+\_\+grid\+\_\+init initializes the ocean grid array sizes and grid memory. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__grid_a2ef4227cc0bc03d2937270fcc14d7354}{rescale\+\_\+grid\+\_\+bathymetry}} (G, m\+\_\+in\+\_\+new\+\_\+units)
\begin{DoxyCompactList}\small\item\em rescale\+\_\+grid\+\_\+bathymetry permits a change in the internal units for the bathymetry on the grid, both rescaling the depths and recording the new internal units. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__grid_a1ed8ca50737525ff437bdb349c8d701f}{set\+\_\+derived\+\_\+metrics}} (G, US)
\begin{DoxyCompactList}\small\item\em set\+\_\+derived\+\_\+metrics calculates metric terms that are derived from other metrics. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespacemom__grid_a49cb0213b535091f3c12e9152fbbda03}{adcroft\+\_\+reciprocal}} (val)
\begin{DoxyCompactList}\small\item\em Adcroft\+\_\+reciprocal(x) = 1/x for $\vert$x$\vert$$>$0 or 0 for x=0. \end{DoxyCompactList}\item 
logical function, public \mbox{\hyperlink{namespacemom__grid_a7d20103f37477e32f1a4a7b7570af144}{ispointincell}} (G, i, j, x, y)
\begin{DoxyCompactList}\small\item\em Returns true if the coordinates (x,y) are within the h-\/cell (i,j) \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__grid_a9d2aac0ba53c9072f5f37d9bf97187b2}{set\+\_\+first\+\_\+direction}} (G, y\+\_\+first)
\begin{DoxyCompactList}\small\item\em Store an integer indicating which direction to work on first. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__grid_a1cee4daea572d4efd1565b24ca652a2d}{get\+\_\+global\+\_\+grid\+\_\+size}} (G, niglobal, njglobal)
\begin{DoxyCompactList}\small\item\em Return global shape of horizontal grid. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__grid_a4a0b721d65abedfe5208a1e0904cd327}{allocate\+\_\+metrics}} (G)
\begin{DoxyCompactList}\small\item\em Allocate memory used by the \mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}} and related structures. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__grid_a889221e5714c3935f276c28dffe5e460}{mom\+\_\+grid\+\_\+end}} (G)
\begin{DoxyCompactList}\small\item\em Release memory used by the \mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}} and related structures. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__grid_a49cb0213b535091f3c12e9152fbbda03}\label{namespacemom__grid_a49cb0213b535091f3c12e9152fbbda03}} 
\index{mom\_grid@{mom\_grid}!adcroft\_reciprocal@{adcroft\_reciprocal}}
\index{adcroft\_reciprocal@{adcroft\_reciprocal}!mom\_grid@{mom\_grid}}
\doxysubsubsection{\texorpdfstring{adcroft\_reciprocal()}{adcroft\_reciprocal()}}
{\footnotesize\ttfamily real function mom\+\_\+grid\+::adcroft\+\_\+reciprocal (\begin{DoxyParamCaption}\item[{real, intent(in)}]{val }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Adcroft\+\_\+reciprocal(x) = 1/x for $\vert$x$\vert$$>$0 or 0 for x=0. 


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


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


\begin{DoxyCode}{0}
\DoxyCodeLine{466 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{intent(in)} :: val\textcolor{comment}{  !< The value being inverted.}}
\DoxyCodeLine{467 \textcolor{keywordtype}{  real} :: I\_val\textcolor{comment}{            !< The Adcroft reciprocal of val.}}
\DoxyCodeLine{468 }
\DoxyCodeLine{469   i\_val = 0.0 ; \textcolor{keywordflow}{if} (val /= 0.0) i\_val = 1.0/val}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid_a4a0b721d65abedfe5208a1e0904cd327}\label{namespacemom__grid_a4a0b721d65abedfe5208a1e0904cd327}} 
\index{mom\_grid@{mom\_grid}!allocate\_metrics@{allocate\_metrics}}
\index{allocate\_metrics@{allocate\_metrics}!mom\_grid@{mom\_grid}}
\doxysubsubsection{\texorpdfstring{allocate\_metrics()}{allocate\_metrics()}}
{\footnotesize\ttfamily subroutine mom\+\_\+grid\+::allocate\+\_\+metrics (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Allocate memory used by the \mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}} and related structures. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The horizontal grid type \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{527   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{ !< The horizontal grid type}}
\DoxyCodeLine{528   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB, isg, ieg, jsg, jeg}
\DoxyCodeLine{529 }
\DoxyCodeLine{530   \textcolor{comment}{! This subroutine allocates the lateral elements of the ocean\_grid\_type that}}
\DoxyCodeLine{531   \textcolor{comment}{! are always used and zeros them out.}}
\DoxyCodeLine{532 }
\DoxyCodeLine{533   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{534   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{535   isg = g\%isg ; ieg = g\%ieg ; jsg = g\%jsg ; jeg = g\%jeg}
\DoxyCodeLine{536 }
\DoxyCodeLine{537   alloc\_(g\%dxT(isd:ied,jsd:jed))       ; g\%dxT(:,:) = 0.0}
\DoxyCodeLine{538   alloc\_(g\%dxCu(isdb:iedb,jsd:jed))    ; g\%dxCu(:,:) = 0.0}
\DoxyCodeLine{539   alloc\_(g\%dxCv(isd:ied,jsdb:jedb))    ; g\%dxCv(:,:) = 0.0}
\DoxyCodeLine{540   alloc\_(g\%dxBu(isdb:iedb,jsdb:jedb))  ; g\%dxBu(:,:) = 0.0}
\DoxyCodeLine{541   alloc\_(g\%IdxT(isd:ied,jsd:jed))      ; g\%IdxT(:,:) = 0.0}
\DoxyCodeLine{542   alloc\_(g\%IdxCu(isdb:iedb,jsd:jed))   ; g\%IdxCu(:,:) = 0.0}
\DoxyCodeLine{543   alloc\_(g\%IdxCv(isd:ied,jsdb:jedb))   ; g\%IdxCv(:,:) = 0.0}
\DoxyCodeLine{544   alloc\_(g\%IdxBu(isdb:iedb,jsdb:jedb)) ; g\%IdxBu(:,:) = 0.0}
\DoxyCodeLine{545 }
\DoxyCodeLine{546   alloc\_(g\%dyT(isd:ied,jsd:jed))       ; g\%dyT(:,:) = 0.0}
\DoxyCodeLine{547   alloc\_(g\%dyCu(isdb:iedb,jsd:jed))    ; g\%dyCu(:,:) = 0.0}
\DoxyCodeLine{548   alloc\_(g\%dyCv(isd:ied,jsdb:jedb))    ; g\%dyCv(:,:) = 0.0}
\DoxyCodeLine{549   alloc\_(g\%dyBu(isdb:iedb,jsdb:jedb))  ; g\%dyBu(:,:) = 0.0}
\DoxyCodeLine{550   alloc\_(g\%IdyT(isd:ied,jsd:jed))      ; g\%IdyT(:,:) = 0.0}
\DoxyCodeLine{551   alloc\_(g\%IdyCu(isdb:iedb,jsd:jed))   ; g\%IdyCu(:,:) = 0.0}
\DoxyCodeLine{552   alloc\_(g\%IdyCv(isd:ied,jsdb:jedb))   ; g\%IdyCv(:,:) = 0.0}
\DoxyCodeLine{553   alloc\_(g\%IdyBu(isdb:iedb,jsdb:jedb)) ; g\%IdyBu(:,:) = 0.0}
\DoxyCodeLine{554 }
\DoxyCodeLine{555   alloc\_(g\%areaT(isd:ied,jsd:jed))       ; g\%areaT(:,:) = 0.0}
\DoxyCodeLine{556   alloc\_(g\%IareaT(isd:ied,jsd:jed))      ; g\%IareaT(:,:) = 0.0}
\DoxyCodeLine{557   alloc\_(g\%areaBu(isdb:iedb,jsdb:jedb))  ; g\%areaBu(:,:) = 0.0}
\DoxyCodeLine{558   alloc\_(g\%IareaBu(isdb:iedb,jsdb:jedb)) ; g\%IareaBu(:,:) = 0.0}
\DoxyCodeLine{559 }
\DoxyCodeLine{560   alloc\_(g\%mask2dT(isd:ied,jsd:jed))      ; g\%mask2dT(:,:) = 0.0}
\DoxyCodeLine{561   alloc\_(g\%mask2dCu(isdb:iedb,jsd:jed))   ; g\%mask2dCu(:,:) = 0.0}
\DoxyCodeLine{562   alloc\_(g\%mask2dCv(isd:ied,jsdb:jedb))   ; g\%mask2dCv(:,:) = 0.0}
\DoxyCodeLine{563   alloc\_(g\%mask2dBu(isdb:iedb,jsdb:jedb)) ; g\%mask2dBu(:,:) = 0.0}
\DoxyCodeLine{564   alloc\_(g\%geoLatT(isd:ied,jsd:jed))      ; g\%geoLatT(:,:) = 0.0}
\DoxyCodeLine{565   alloc\_(g\%geoLatCu(isdb:iedb,jsd:jed))   ; g\%geoLatCu(:,:) = 0.0}
\DoxyCodeLine{566   alloc\_(g\%geoLatCv(isd:ied,jsdb:jedb))   ; g\%geoLatCv(:,:) = 0.0}
\DoxyCodeLine{567   alloc\_(g\%geoLatBu(isdb:iedb,jsdb:jedb)) ; g\%geoLatBu(:,:) = 0.0}
\DoxyCodeLine{568   alloc\_(g\%geoLonT(isd:ied,jsd:jed))      ; g\%geoLonT(:,:) = 0.0}
\DoxyCodeLine{569   alloc\_(g\%geoLonCu(isdb:iedb,jsd:jed))   ; g\%geoLonCu(:,:) = 0.0}
\DoxyCodeLine{570   alloc\_(g\%geoLonCv(isd:ied,jsdb:jedb))   ; g\%geoLonCv(:,:) = 0.0}
\DoxyCodeLine{571   alloc\_(g\%geoLonBu(isdb:iedb,jsdb:jedb)) ; g\%geoLonBu(:,:) = 0.0}
\DoxyCodeLine{572 }
\DoxyCodeLine{573   alloc\_(g\%dx\_Cv(isd:ied,jsdb:jedb))     ; g\%dx\_Cv(:,:) = 0.0}
\DoxyCodeLine{574   alloc\_(g\%dy\_Cu(isdb:iedb,jsd:jed))     ; g\%dy\_Cu(:,:) = 0.0}
\DoxyCodeLine{575 }
\DoxyCodeLine{576   alloc\_(g\%areaCu(isdb:iedb,jsd:jed))  ; g\%areaCu(:,:) = 0.0}
\DoxyCodeLine{577   alloc\_(g\%areaCv(isd:ied,jsdb:jedb))  ; g\%areaCv(:,:) = 0.0}
\DoxyCodeLine{578   alloc\_(g\%IareaCu(isdb:iedb,jsd:jed)) ; g\%IareaCu(:,:) = 0.0}
\DoxyCodeLine{579   alloc\_(g\%IareaCv(isd:ied,jsdb:jedb)) ; g\%IareaCv(:,:) = 0.0}
\DoxyCodeLine{580 }
\DoxyCodeLine{581   alloc\_(g\%bathyT(isd:ied, jsd:jed)) ; g\%bathyT(:,:) = 0.0}
\DoxyCodeLine{582   alloc\_(g\%CoriolisBu(isdb:iedb, jsdb:jedb)) ; g\%CoriolisBu(:,:) = 0.0}
\DoxyCodeLine{583   alloc\_(g\%dF\_dx(isd:ied, jsd:jed)) ; g\%dF\_dx(:,:) = 0.0}
\DoxyCodeLine{584   alloc\_(g\%dF\_dy(isd:ied, jsd:jed)) ; g\%dF\_dy(:,:) = 0.0}
\DoxyCodeLine{585 }
\DoxyCodeLine{586   alloc\_(g\%sin\_rot(isd:ied,jsd:jed)) ; g\%sin\_rot(:,:) = 0.0}
\DoxyCodeLine{587   alloc\_(g\%cos\_rot(isd:ied,jsd:jed)) ; g\%cos\_rot(:,:) = 1.0}
\DoxyCodeLine{588 }
\DoxyCodeLine{589   \textcolor{keyword}{allocate}(g\%gridLonT(isg:ieg))   ; g\%gridLonT(:) = 0.0}
\DoxyCodeLine{590   \textcolor{keyword}{allocate}(g\%gridLonB(g\%IsgB:g\%IegB)) ; g\%gridLonB(:) = 0.0}
\DoxyCodeLine{591   \textcolor{keyword}{allocate}(g\%gridLatT(jsg:jeg))   ; g\%gridLatT(:) = 0.0}
\DoxyCodeLine{592   \textcolor{keyword}{allocate}(g\%gridLatB(g\%JsgB:g\%JegB)) ; g\%gridLatB(:) = 0.0}
\DoxyCodeLine{593 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid_a1cee4daea572d4efd1565b24ca652a2d}\label{namespacemom__grid_a1cee4daea572d4efd1565b24ca652a2d}} 
\index{mom\_grid@{mom\_grid}!get\_global\_grid\_size@{get\_global\_grid\_size}}
\index{get\_global\_grid\_size@{get\_global\_grid\_size}!mom\_grid@{mom\_grid}}
\doxysubsubsection{\texorpdfstring{get\_global\_grid\_size()}{get\_global\_grid\_size()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+grid\+::get\+\_\+global\+\_\+grid\+\_\+size (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G,  }\item[{integer, intent(out)}]{niglobal,  }\item[{integer, intent(out)}]{njglobal }\end{DoxyParamCaption})}



Return global shape of horizontal grid. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The horizontal grid type \\
\hline
\mbox{\texttt{ out}}  & {\em niglobal} & i-\/index global size of grid \\
\hline
\mbox{\texttt{ out}}  & {\em njglobal} & j-\/index global size of grid \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{517   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{ !< The horizontal grid type}}
\DoxyCodeLine{518   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(out)}   :: niglobal\textcolor{comment}{ !< i-\/index global size of grid}}
\DoxyCodeLine{519   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(out)}   :: njglobal\textcolor{comment}{ !< j-\/index global size of grid}}
\DoxyCodeLine{520 }
\DoxyCodeLine{521   \textcolor{keyword}{call }get\_global\_shape(g\%domain, niglobal, njglobal)}
\DoxyCodeLine{522 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid_a7d20103f37477e32f1a4a7b7570af144}\label{namespacemom__grid_a7d20103f37477e32f1a4a7b7570af144}} 
\index{mom\_grid@{mom\_grid}!ispointincell@{ispointincell}}
\index{ispointincell@{ispointincell}!mom\_grid@{mom\_grid}}
\doxysubsubsection{\texorpdfstring{ispointincell()}{ispointincell()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+grid\+::ispointincell (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{integer, intent(in)}]{i,  }\item[{integer, intent(in)}]{j,  }\item[{real, intent(in)}]{x,  }\item[{real, intent(in)}]{y }\end{DoxyParamCaption})}



Returns true if the coordinates (x,y) are within the h-\/cell (i,j) 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Grid type \\
\hline
\mbox{\texttt{ in}}  & {\em i} & i index of cell to test \\
\hline
\mbox{\texttt{ in}}  & {\em j} & j index of cell to test \\
\hline
\mbox{\texttt{ in}}  & {\em x} & x coordinate of point \\
\hline
\mbox{\texttt{ in}}  & {\em y} & y coordinate of point \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{474   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: G\textcolor{comment}{ !< Grid type}}
\DoxyCodeLine{475   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)} :: i\textcolor{comment}{ !< i index of cell to test}}
\DoxyCodeLine{476   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)} :: j\textcolor{comment}{ !< j index of cell to test}}
\DoxyCodeLine{477 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)} :: x\textcolor{comment}{ !< x coordinate of point}}
\DoxyCodeLine{478 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)} :: y\textcolor{comment}{ !< y coordinate of point}}
\DoxyCodeLine{479   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{480 \textcolor{keywordtype}{  real} :: xNE, xNW, xSE, xSW, yNE, yNW, ySE, ySW}
\DoxyCodeLine{481 \textcolor{keywordtype}{  real} :: p0, p1, p2, p3, l0, l1, l2, l3}
\DoxyCodeLine{482   ispointincell = .false.}
\DoxyCodeLine{483   xne = g\%geoLonBu(i  ,j  ) ; yne = g\%geoLatBu(i  ,j  )}
\DoxyCodeLine{484   xnw = g\%geoLonBu(i-\/1,j  ) ; ynw = g\%geoLatBu(i-\/1,j  )}
\DoxyCodeLine{485   xse = g\%geoLonBu(i  ,j-\/1) ; yse = g\%geoLatBu(i  ,j-\/1)}
\DoxyCodeLine{486   xsw = g\%geoLonBu(i-\/1,j-\/1) ; ysw = g\%geoLatBu(i-\/1,j-\/1)}
\DoxyCodeLine{487   \textcolor{comment}{! This is a crude calculation that assume a geographic coordinate system}}
\DoxyCodeLine{488   \textcolor{keywordflow}{if} (x<min(xne,xnw,xse,xsw) .or. x>max(xne,xnw,xse,xsw) .or. \&}
\DoxyCodeLine{489       y<min(yne,ynw,yse,ysw) .or. y>max(yne,ynw,yse,ysw) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{490     \textcolor{keywordflow}{return} \textcolor{comment}{! Avoid the more complicated calculation}}
\DoxyCodeLine{491 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{492   l0 = (x-\/xsw)*(yse-\/ysw) -\/ (y-\/ysw)*(xse-\/xsw)}
\DoxyCodeLine{493   l1 = (x-\/xse)*(yne-\/yse) -\/ (y-\/yse)*(xne-\/xse)}
\DoxyCodeLine{494   l2 = (x-\/xne)*(ynw-\/yne) -\/ (y-\/yne)*(xnw-\/xne)}
\DoxyCodeLine{495   l3 = (x-\/xnw)*(ysw-\/ynw) -\/ (y-\/ynw)*(xsw-\/xnw)}
\DoxyCodeLine{496 }
\DoxyCodeLine{497   p0 = sign(1., l0) ; \textcolor{keywordflow}{if} (l0 == 0.) p0=0.}
\DoxyCodeLine{498   p1 = sign(1., l1) ; \textcolor{keywordflow}{if} (l1 == 0.) p1=0.}
\DoxyCodeLine{499   p2 = sign(1., l2) ; \textcolor{keywordflow}{if} (l2 == 0.) p2=0.}
\DoxyCodeLine{500   p3 = sign(1., l3) ; \textcolor{keywordflow}{if} (l3 == 0.) p3=0.}
\DoxyCodeLine{501 }
\DoxyCodeLine{502   \textcolor{keywordflow}{if} ( (abs(p0)+abs(p2)) + (abs(p1)+abs(p3)) == abs((p0+p2) + (p1+p3)) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{503     ispointincell=.true.}
\DoxyCodeLine{504 \textcolor{keywordflow}{  endif}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid_a889221e5714c3935f276c28dffe5e460}\label{namespacemom__grid_a889221e5714c3935f276c28dffe5e460}} 
\index{mom\_grid@{mom\_grid}!mom\_grid\_end@{mom\_grid\_end}}
\index{mom\_grid\_end@{mom\_grid\_end}!mom\_grid@{mom\_grid}}
\doxysubsubsection{\texorpdfstring{mom\_grid\_end()}{mom\_grid\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+grid\+::mom\+\_\+grid\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G }\end{DoxyParamCaption})}



Release memory used by the \mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}} and related structures. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The horizontal grid type \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{598   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{ !< The horizontal grid type}}
\DoxyCodeLine{599 }
\DoxyCodeLine{600   dealloc\_(g\%dxT)  ; dealloc\_(g\%dxCu)  ; dealloc\_(g\%dxCv)  ; dealloc\_(g\%dxBu)}
\DoxyCodeLine{601   dealloc\_(g\%IdxT) ; dealloc\_(g\%IdxCu) ; dealloc\_(g\%IdxCv) ; dealloc\_(g\%IdxBu)}
\DoxyCodeLine{602 }
\DoxyCodeLine{603   dealloc\_(g\%dyT)  ; dealloc\_(g\%dyCu)  ; dealloc\_(g\%dyCv)  ; dealloc\_(g\%dyBu)}
\DoxyCodeLine{604   dealloc\_(g\%IdyT) ; dealloc\_(g\%IdyCu) ; dealloc\_(g\%IdyCv) ; dealloc\_(g\%IdyBu)}
\DoxyCodeLine{605 }
\DoxyCodeLine{606   dealloc\_(g\%areaT)  ; dealloc\_(g\%IareaT)}
\DoxyCodeLine{607   dealloc\_(g\%areaBu) ; dealloc\_(g\%IareaBu)}
\DoxyCodeLine{608   dealloc\_(g\%areaCu) ; dealloc\_(g\%IareaCu)}
\DoxyCodeLine{609   dealloc\_(g\%areaCv)  ; dealloc\_(g\%IareaCv)}
\DoxyCodeLine{610 }
\DoxyCodeLine{611   dealloc\_(g\%mask2dT)  ; dealloc\_(g\%mask2dCu)}
\DoxyCodeLine{612   dealloc\_(g\%mask2dCv) ; dealloc\_(g\%mask2dBu)}
\DoxyCodeLine{613 }
\DoxyCodeLine{614   dealloc\_(g\%geoLatT)  ; dealloc\_(g\%geoLatCu)}
\DoxyCodeLine{615   dealloc\_(g\%geoLatCv) ; dealloc\_(g\%geoLatBu)}
\DoxyCodeLine{616   dealloc\_(g\%geoLonT)  ; dealloc\_(g\%geoLonCu)}
\DoxyCodeLine{617   dealloc\_(g\%geoLonCv) ; dealloc\_(g\%geoLonBu)}
\DoxyCodeLine{618 }
\DoxyCodeLine{619   dealloc\_(g\%dx\_Cv) ; dealloc\_(g\%dy\_Cu)}
\DoxyCodeLine{620 }
\DoxyCodeLine{621   dealloc\_(g\%bathyT)  ; dealloc\_(g\%CoriolisBu)}
\DoxyCodeLine{622   dealloc\_(g\%dF\_dx)  ; dealloc\_(g\%dF\_dy)}
\DoxyCodeLine{623   dealloc\_(g\%sin\_rot) ; dealloc\_(g\%cos\_rot)}
\DoxyCodeLine{624 }
\DoxyCodeLine{625   \textcolor{keywordflow}{if} (g\%bathymetry\_at\_vel) \textcolor{keywordflow}{then}}
\DoxyCodeLine{626     dealloc\_(g\%Dblock\_u) ; dealloc\_(g\%Dopen\_u)}
\DoxyCodeLine{627     dealloc\_(g\%Dblock\_v) ; dealloc\_(g\%Dopen\_v)}
\DoxyCodeLine{628 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{629 }
\DoxyCodeLine{630   \textcolor{keyword}{deallocate}(g\%gridLonT) ; \textcolor{keyword}{deallocate}(g\%gridLatT)}
\DoxyCodeLine{631   \textcolor{keyword}{deallocate}(g\%gridLonB) ; \textcolor{keyword}{deallocate}(g\%gridLatB)}
\DoxyCodeLine{632 }
\DoxyCodeLine{633   \textcolor{keyword}{deallocate}(g\%Domain\%mpp\_domain)}
\DoxyCodeLine{634   \textcolor{keyword}{deallocate}(g\%Domain)}
\DoxyCodeLine{635 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid_a1de9705f83b687ad9a711630a95fe52c}\label{namespacemom__grid_a1de9705f83b687ad9a711630a95fe52c}} 
\index{mom\_grid@{mom\_grid}!mom\_grid\_init@{mom\_grid\_init}}
\index{mom\_grid\_init@{mom\_grid\_init}!mom\_grid@{mom\_grid}}
\doxysubsubsection{\texorpdfstring{mom\_grid\_init()}{mom\_grid\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+grid\+::mom\+\_\+grid\+\_\+init (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(unit\+\_\+scale\+\_\+type), optional, pointer}]{US,  }\item[{type(hor\+\_\+index\+\_\+type), intent(in), optional}]{HI,  }\item[{logical, intent(in), optional}]{global\+\_\+indexing,  }\item[{logical, intent(in), optional}]{bathymetry\+\_\+at\+\_\+vel }\end{DoxyParamCaption})}



M\+O\+M\+\_\+grid\+\_\+init initializes the ocean grid array sizes and grid memory. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The horizontal grid type \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & Parameter file handle \\
\hline
 & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em hi} & A hor\+\_\+index\+\_\+type for array extents \\
\hline
\mbox{\texttt{ in}}  & {\em global\+\_\+indexing} & If true use global index values instead of having the data domain on each processor start at 1. \\
\hline
\mbox{\texttt{ in}}  & {\em bathymetry\+\_\+at\+\_\+vel} & If true, there are separate values for the ocean bottom depths at velocity points. Otherwise the effects of topography are entirely determined from thickness points. \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{184   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{          !< The horizontal grid type}}
\DoxyCodeLine{185   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file handle}}
\DoxyCodeLine{186   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer} :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{187   \textcolor{keywordtype}{type}(hor\_index\_type), \&}
\DoxyCodeLine{188                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: HI\textcolor{comment}{ !< A hor\_index\_type for array extents}}
\DoxyCodeLine{189   \textcolor{keywordtype}{logical},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: global\_indexing\textcolor{comment}{ !< If true use global index}}
\DoxyCodeLine{190 \textcolor{comment}{                             !! values instead of having the data domain on each}}
\DoxyCodeLine{191 \textcolor{comment}{                             !! processor start at 1.}}
\DoxyCodeLine{192   \textcolor{keywordtype}{logical},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: bathymetry\_at\_vel\textcolor{comment}{ !< If true, there are}}
\DoxyCodeLine{193 \textcolor{comment}{                             !! separate values for the ocean bottom depths at}}
\DoxyCodeLine{194 \textcolor{comment}{                             !! velocity points.  Otherwise the effects of topography}}
\DoxyCodeLine{195 \textcolor{comment}{                             !! are entirely determined from thickness points.}}
\DoxyCodeLine{196 }
\DoxyCodeLine{197   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{198 \textcolor{keywordtype}{  real} :: mean\_SeaLev\_scale}
\DoxyCodeLine{199   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed, nk}
\DoxyCodeLine{200   \textcolor{keywordtype}{integer} :: IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{201   \textcolor{keywordtype}{integer} :: ied\_max, jed\_max}
\DoxyCodeLine{202   \textcolor{keywordtype}{integer} :: niblock, njblock, nihalo, njhalo, nblocks, n, i, j}
\DoxyCodeLine{203   \textcolor{keywordtype}{logical} :: local\_indexing  \textcolor{comment}{! If false use global index values instead of having}}
\DoxyCodeLine{204                              \textcolor{comment}{! the data domain on each processor start at 1.}}
\DoxyCodeLine{205   \textcolor{comment}{! This include declares and sets the variable "version".}}
\DoxyCodeLine{206 \textcolor{preprocessor}{\# include "version\_variable.h"}}
\DoxyCodeLine{207 \textcolor{preprocessor}{}}
\DoxyCodeLine{208   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)} :: ibegin, iend, jbegin, jend}
\DoxyCodeLine{209   \textcolor{keywordtype}{character(len=40)}  :: mod\_nm  = \textcolor{stringliteral}{"MOM\_grid"} \textcolor{comment}{! This module's name.}}
\DoxyCodeLine{210 }
\DoxyCodeLine{211 }
\DoxyCodeLine{212   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}}
\DoxyCodeLine{213   \textcolor{keyword}{call }get\_param(param\_file, mod\_nm, \textcolor{stringliteral}{"REFERENCE\_HEIGHT"}, g\%Z\_ref, default=0.0, do\_not\_log=.true.)}
\DoxyCodeLine{214   \textcolor{keyword}{call }log\_version(param\_file, mod\_nm, version, \&}
\DoxyCodeLine{215                    \textcolor{stringliteral}{"Parameters providing information about the lateral grid."}, \&}
\DoxyCodeLine{216                    log\_to\_all=.true., layout=.true., all\_default=(g\%Z\_ref==0.0))}
\DoxyCodeLine{217 }
\DoxyCodeLine{218   \textcolor{keyword}{call }get\_param(param\_file, mod\_nm, \textcolor{stringliteral}{"NIBLOCK"}, niblock, \textcolor{stringliteral}{"The number of blocks "}// \&}
\DoxyCodeLine{219                  \textcolor{stringliteral}{"in the x-\/direction on each processor (for openmp)."}, default=1, \&}
\DoxyCodeLine{220                  layoutparam=.true.)}
\DoxyCodeLine{221   \textcolor{keyword}{call }get\_param(param\_file, mod\_nm, \textcolor{stringliteral}{"NJBLOCK"}, njblock, \textcolor{stringliteral}{"The number of blocks "}// \&}
\DoxyCodeLine{222                  \textcolor{stringliteral}{"in the y-\/direction on each processor (for openmp)."}, default=1, \&}
\DoxyCodeLine{223                  layoutparam=.true.)}
\DoxyCodeLine{224   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(us)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(us)) g\%US => us ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{225 }
\DoxyCodeLine{226   mean\_sealev\_scale = 1.0 ;  \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(g\%US)) mean\_sealev\_scale = g\%US\%m\_to\_Z}
\DoxyCodeLine{227   \textcolor{keyword}{call }get\_param(param\_file, mod\_nm, \textcolor{stringliteral}{"REFERENCE\_HEIGHT"}, g\%Z\_ref, \&}
\DoxyCodeLine{228                  \textcolor{stringliteral}{"A reference value for geometric height fields, such as bathyT."}, \&}
\DoxyCodeLine{229                  units=\textcolor{stringliteral}{"m"}, default=0.0, scale=mean\_sealev\_scale)}
\DoxyCodeLine{230 }
\DoxyCodeLine{231   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(hi)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{232     g\%HI = hi}
\DoxyCodeLine{233 }
\DoxyCodeLine{234     g\%isc = hi\%isc ; g\%iec = hi\%iec ; g\%jsc = hi\%jsc ; g\%jec = hi\%jec}
\DoxyCodeLine{235     g\%isd = hi\%isd ; g\%ied = hi\%ied ; g\%jsd = hi\%jsd ; g\%jed = hi\%jed}
\DoxyCodeLine{236     g\%isg = hi\%isg ; g\%ieg = hi\%ieg ; g\%jsg = hi\%jsg ; g\%jeg = hi\%jeg}
\DoxyCodeLine{237 }
\DoxyCodeLine{238     g\%IscB = hi\%IscB ; g\%IecB = hi\%IecB ; g\%JscB = hi\%JscB ; g\%JecB = hi\%JecB}
\DoxyCodeLine{239     g\%IsdB = hi\%IsdB ; g\%IedB = hi\%IedB ; g\%JsdB = hi\%JsdB ; g\%JedB = hi\%JedB}
\DoxyCodeLine{240     g\%IsgB = hi\%IsgB ; g\%IegB = hi\%IegB ; g\%JsgB = hi\%JsgB ; g\%JegB = hi\%JegB}
\DoxyCodeLine{241 }
\DoxyCodeLine{242     g\%idg\_offset = hi\%idg\_offset ; g\%jdg\_offset = hi\%jdg\_offset}
\DoxyCodeLine{243     g\%isd\_global = g\%isd + hi\%idg\_offset ; g\%jsd\_global = g\%jsd + hi\%jdg\_offset}
\DoxyCodeLine{244     g\%symmetric = hi\%symmetric}
\DoxyCodeLine{245   \textcolor{keywordflow}{else}}
\DoxyCodeLine{246     local\_indexing = .true.}
\DoxyCodeLine{247     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(global\_indexing)) local\_indexing = .not.global\_indexing}
\DoxyCodeLine{248     \textcolor{keyword}{call }hor\_index\_init(g\%Domain, g\%HI, param\_file, \&}
\DoxyCodeLine{249                         local\_indexing=local\_indexing)}
\DoxyCodeLine{250 }
\DoxyCodeLine{251     \textcolor{comment}{! get\_domain\_extent ensures that domains start at 1 for compatibility between}}
\DoxyCodeLine{252     \textcolor{comment}{! static and dynamically allocated arrays, unless global\_indexing is true.}}
\DoxyCodeLine{253     \textcolor{keyword}{call }get\_domain\_extent(g\%Domain, g\%isc, g\%iec, g\%jsc, g\%jec, \&}
\DoxyCodeLine{254                            g\%isd, g\%ied, g\%jsd, g\%jed, \&}
\DoxyCodeLine{255                            g\%isg, g\%ieg, g\%jsg, g\%jeg, \&}
\DoxyCodeLine{256                            g\%idg\_offset, g\%jdg\_offset, g\%symmetric, \&}
\DoxyCodeLine{257                            local\_indexing=local\_indexing)}
\DoxyCodeLine{258     g\%isd\_global = g\%isd+g\%idg\_offset ; g\%jsd\_global = g\%jsd+g\%jdg\_offset}
\DoxyCodeLine{259 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{260 }
\DoxyCodeLine{261   g\%nonblocking\_updates = g\%Domain\%nonblocking\_updates}
\DoxyCodeLine{262 }
\DoxyCodeLine{263   \textcolor{comment}{! Set array sizes for fields that are discretized at tracer cell boundaries.}}
\DoxyCodeLine{264   g\%IscB = g\%isc ; g\%JscB = g\%jsc}
\DoxyCodeLine{265   g\%IsdB = g\%isd ; g\%JsdB = g\%jsd}
\DoxyCodeLine{266   g\%IsgB = g\%isg ; g\%JsgB = g\%jsg}
\DoxyCodeLine{267   \textcolor{keywordflow}{if} (g\%symmetric) \textcolor{keywordflow}{then}}
\DoxyCodeLine{268     g\%IscB = g\%isc-\/1 ; g\%JscB = g\%jsc-\/1}
\DoxyCodeLine{269     g\%IsdB = g\%isd-\/1 ; g\%JsdB = g\%jsd-\/1}
\DoxyCodeLine{270     g\%IsgB = g\%isg-\/1 ; g\%JsgB = g\%jsg-\/1}
\DoxyCodeLine{271 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{272   g\%IecB = g\%iec ; g\%JecB = g\%jec}
\DoxyCodeLine{273   g\%IedB = g\%ied ; g\%JedB = g\%jed}
\DoxyCodeLine{274   g\%IegB = g\%ieg ; g\%JegB = g\%jeg}
\DoxyCodeLine{275 }
\DoxyCodeLine{276   \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{"  MOM\_grid.F90, MOM\_grid\_init: allocating metrics"}, 5)}
\DoxyCodeLine{277 }
\DoxyCodeLine{278   \textcolor{keyword}{call }allocate\_metrics(g)}
\DoxyCodeLine{279 }
\DoxyCodeLine{280   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{281   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{282 }
\DoxyCodeLine{283   g\%bathymetry\_at\_vel = .false.}
\DoxyCodeLine{284   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(bathymetry\_at\_vel)) g\%bathymetry\_at\_vel = bathymetry\_at\_vel}
\DoxyCodeLine{285   \textcolor{keywordflow}{if} (g\%bathymetry\_at\_vel) \textcolor{keywordflow}{then}}
\DoxyCodeLine{286     alloc\_(g\%Dblock\_u(isdb:iedb, jsd:jed)) ; g\%Dblock\_u(:,:) = 0.0}
\DoxyCodeLine{287     alloc\_(g\%Dopen\_u(isdb:iedb, jsd:jed))  ; g\%Dopen\_u(:,:) = 0.0}
\DoxyCodeLine{288     alloc\_(g\%Dblock\_v(isd:ied, jsdb:jedb)) ; g\%Dblock\_v(:,:) = 0.0}
\DoxyCodeLine{289     alloc\_(g\%Dopen\_v(isd:ied, jsdb:jedb))  ; g\%Dopen\_v(:,:) = 0.0}
\DoxyCodeLine{290 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{291 }
\DoxyCodeLine{292 \textcolor{comment}{! setup block indices.}}
\DoxyCodeLine{293   nihalo = g\%Domain\%nihalo}
\DoxyCodeLine{294   njhalo = g\%Domain\%njhalo}
\DoxyCodeLine{295   nblocks = niblock * njblock}
\DoxyCodeLine{296   \textcolor{keywordflow}{if} (nblocks < 1) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_grid\_init: "} // \&}
\DoxyCodeLine{297        \textcolor{stringliteral}{"nblocks(=NI\_BLOCK*NJ\_BLOCK) must be no less than 1"})}
\DoxyCodeLine{298 }
\DoxyCodeLine{299   \textcolor{keyword}{allocate}(ibegin(niblock), iend(niblock), jbegin(njblock), jend(njblock))}
\DoxyCodeLine{300   \textcolor{keyword}{call }compute\_block\_extent(g\%HI\%isc,g\%HI\%iec,niblock,ibegin,iend)}
\DoxyCodeLine{301   \textcolor{keyword}{call }compute\_block\_extent(g\%HI\%jsc,g\%HI\%jec,njblock,jbegin,jend)}
\DoxyCodeLine{302   \textcolor{comment}{!-\/-\/ make sure the last block is the largest.}}
\DoxyCodeLine{303   \textcolor{keywordflow}{do} i = 1, niblock-\/1}
\DoxyCodeLine{304     \textcolor{keywordflow}{if} (iend(i)-\/ibegin(i) > iend(niblock)-\/ibegin(niblock) ) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{305        \textcolor{stringliteral}{"MOM\_grid\_init: the last block size in x-\/direction is not the largest"})}
\DoxyCodeLine{306 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{307   \textcolor{keywordflow}{do} j = 1, njblock-\/1}
\DoxyCodeLine{308     \textcolor{keywordflow}{if} (jend(j)-\/jbegin(j) > jend(njblock)-\/jbegin(njblock) ) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{309        \textcolor{stringliteral}{"MOM\_grid\_init: the last block size in y-\/direction is not the largest"})}
\DoxyCodeLine{310 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{311 }
\DoxyCodeLine{312   g\%nblocks = nblocks}
\DoxyCodeLine{313   \textcolor{keyword}{allocate}(g\%Block(nblocks))}
\DoxyCodeLine{314   ied\_max = 1 ; jed\_max = 1}
\DoxyCodeLine{315   \textcolor{keywordflow}{do} n = 1,nblocks}
\DoxyCodeLine{316     \textcolor{comment}{! Copy all information from the array index type describing the local grid.}}
\DoxyCodeLine{317     g\%Block(n) = g\%HI}
\DoxyCodeLine{318 }
\DoxyCodeLine{319     i = mod((n-\/1), niblock) + 1}
\DoxyCodeLine{320     j = (n-\/1)/niblock + 1}
\DoxyCodeLine{321     \textcolor{comment}{!-\/-\/-\/ isd and jsd are always 1 for each block to permit array reuse.}}
\DoxyCodeLine{322     g\%Block(n)\%isd = 1 ; g\%Block(n)\%jsd = 1}
\DoxyCodeLine{323     g\%Block(n)\%isc = g\%Block(n)\%isd+nihalo}
\DoxyCodeLine{324     g\%Block(n)\%jsc = g\%Block(n)\%jsd+njhalo}
\DoxyCodeLine{325     g\%Block(n)\%iec = g\%Block(n)\%isc + iend(i) -\/ ibegin(i)}
\DoxyCodeLine{326     g\%Block(n)\%jec = g\%Block(n)\%jsc + jend(j) -\/ jbegin(j)}
\DoxyCodeLine{327     g\%Block(n)\%ied = g\%Block(n)\%iec + nihalo}
\DoxyCodeLine{328     g\%Block(n)\%jed = g\%Block(n)\%jec + njhalo}
\DoxyCodeLine{329     g\%Block(n)\%IscB = g\%Block(n)\%isc; g\%Block(n)\%IecB = g\%Block(n)\%iec}
\DoxyCodeLine{330     g\%Block(n)\%JscB = g\%Block(n)\%jsc; g\%Block(n)\%JecB = g\%Block(n)\%jec}
\DoxyCodeLine{331     \textcolor{comment}{!   For symmetric memory domains, the first block will have the extra point}}
\DoxyCodeLine{332     \textcolor{comment}{! at the lower boundary of its computational domain.}}
\DoxyCodeLine{333     \textcolor{keywordflow}{if} (g\%symmetric) \textcolor{keywordflow}{then}}
\DoxyCodeLine{334       \textcolor{keywordflow}{if} (i==1) g\%Block(n)\%IscB = g\%Block(n)\%IscB-\/1}
\DoxyCodeLine{335       \textcolor{keywordflow}{if} (j==1) g\%Block(n)\%JscB = g\%Block(n)\%JscB-\/1}
\DoxyCodeLine{336 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{337     g\%Block(n)\%IsdB = g\%Block(n)\%isd; g\%Block(n)\%IedB = g\%Block(n)\%ied}
\DoxyCodeLine{338     g\%Block(n)\%JsdB = g\%Block(n)\%jsd; g\%Block(n)\%JedB = g\%Block(n)\%jed}
\DoxyCodeLine{339     \textcolor{comment}{!-\/-\/-\/ For symmetric memory domain, every block will have an extra point}}
\DoxyCodeLine{340     \textcolor{comment}{!-\/-\/-\/ at the lower boundary of its data domain.}}
\DoxyCodeLine{341     \textcolor{keywordflow}{if} (g\%symmetric) \textcolor{keywordflow}{then}}
\DoxyCodeLine{342       g\%Block(n)\%IsdB = g\%Block(n)\%IsdB-\/1}
\DoxyCodeLine{343       g\%Block(n)\%JsdB = g\%Block(n)\%JsdB-\/1}
\DoxyCodeLine{344 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{345     g\%Block(n)\%idg\_offset = (ibegin(i) -\/ g\%Block(n)\%isc) + g\%HI\%idg\_offset}
\DoxyCodeLine{346     g\%Block(n)\%jdg\_offset = (jbegin(j) -\/ g\%Block(n)\%jsc) + g\%HI\%jdg\_offset}
\DoxyCodeLine{347     \textcolor{comment}{! Find the largest values of ied and jed so that all blocks will have the}}
\DoxyCodeLine{348     \textcolor{comment}{! same size in memory.}}
\DoxyCodeLine{349     ied\_max = max(ied\_max, g\%Block(n)\%ied)}
\DoxyCodeLine{350     jed\_max = max(jed\_max, g\%Block(n)\%jed)}
\DoxyCodeLine{351 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{352 }
\DoxyCodeLine{353   \textcolor{comment}{! Reset all of the data domain sizes to match the largest for array reuse,}}
\DoxyCodeLine{354   \textcolor{comment}{! recalling that all block have isd=jed=1 for array reuse.}}
\DoxyCodeLine{355   \textcolor{keywordflow}{do} n = 1,nblocks}
\DoxyCodeLine{356     g\%Block(n)\%ied = ied\_max ; g\%Block(n)\%IedB = ied\_max}
\DoxyCodeLine{357     g\%Block(n)\%jed = jed\_max ; g\%Block(n)\%JedB = jed\_max}
\DoxyCodeLine{358 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{359 }
\DoxyCodeLine{360   \textcolor{comment}{!-\/-\/ do some bounds error checking}}
\DoxyCodeLine{361   \textcolor{keywordflow}{if} ( g\%block(nblocks)\%ied+g\%block(nblocks)\%idg\_offset > g\%HI\%ied + g\%HI\%idg\_offset ) \&}
\DoxyCodeLine{362         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_grid\_init: G\%ied\_bk > G\%ied"})}
\DoxyCodeLine{363   \textcolor{keywordflow}{if} ( g\%block(nblocks)\%jed+g\%block(nblocks)\%jdg\_offset > g\%HI\%jed + g\%HI\%jdg\_offset ) \&}
\DoxyCodeLine{364         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_grid\_init: G\%jed\_bk > G\%jed"})}
\DoxyCodeLine{365 }
\DoxyCodeLine{366   \textcolor{keyword}{call }get\_domain\_extent\_dsamp2(g\%Domain, g\%HId2\%isc, g\%HId2\%iec, g\%HId2\%jsc, g\%HId2\%jec,\&}
\DoxyCodeLine{367                                           g\%HId2\%isd, g\%HId2\%ied, g\%HId2\%jsd, g\%HId2\%jed,\&}
\DoxyCodeLine{368                                           g\%HId2\%isg, g\%HId2\%ieg, g\%HId2\%jsg, g\%HId2\%jeg)}
\DoxyCodeLine{369 }
\DoxyCodeLine{370   \textcolor{comment}{! Set array sizes for fields that are discretized at tracer cell boundaries.}}
\DoxyCodeLine{371   g\%HId2\%IscB = g\%HId2\%isc ; g\%HId2\%JscB = g\%HId2\%jsc}
\DoxyCodeLine{372   g\%HId2\%IsdB = g\%HId2\%isd ; g\%HId2\%JsdB = g\%HId2\%jsd}
\DoxyCodeLine{373   g\%HId2\%IsgB = g\%HId2\%isg ; g\%HId2\%JsgB = g\%HId2\%jsg}
\DoxyCodeLine{374   \textcolor{keywordflow}{if} (g\%symmetric) \textcolor{keywordflow}{then}}
\DoxyCodeLine{375     g\%HId2\%IscB = g\%HId2\%isc-\/1 ; g\%HId2\%JscB = g\%HId2\%jsc-\/1}
\DoxyCodeLine{376     g\%HId2\%IsdB = g\%HId2\%isd-\/1 ; g\%HId2\%JsdB = g\%HId2\%jsd-\/1}
\DoxyCodeLine{377     g\%HId2\%IsgB = g\%HId2\%isg-\/1 ; g\%HId2\%JsgB = g\%HId2\%jsg-\/1}
\DoxyCodeLine{378 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{379   g\%HId2\%IecB = g\%HId2\%iec ; g\%HId2\%JecB = g\%HId2\%jec}
\DoxyCodeLine{380   g\%HId2\%IedB = g\%HId2\%ied ; g\%HId2\%JedB = g\%HId2\%jed}
\DoxyCodeLine{381   g\%HId2\%IegB = g\%HId2\%ieg ; g\%HId2\%JegB = g\%HId2\%jeg}
\DoxyCodeLine{382 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid_a2ef4227cc0bc03d2937270fcc14d7354}\label{namespacemom__grid_a2ef4227cc0bc03d2937270fcc14d7354}} 
\index{mom\_grid@{mom\_grid}!rescale\_grid\_bathymetry@{rescale\_grid\_bathymetry}}
\index{rescale\_grid\_bathymetry@{rescale\_grid\_bathymetry}!mom\_grid@{mom\_grid}}
\doxysubsubsection{\texorpdfstring{rescale\_grid\_bathymetry()}{rescale\_grid\_bathymetry()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+grid\+::rescale\+\_\+grid\+\_\+bathymetry (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G,  }\item[{real, intent(in)}]{m\+\_\+in\+\_\+new\+\_\+units }\end{DoxyParamCaption})}



rescale\+\_\+grid\+\_\+bathymetry permits a change in the internal units for the bathymetry on the grid, both rescaling the depths and recording the new internal units. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The horizontal grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em m\+\_\+in\+\_\+new\+\_\+units} & The new internal representation of 1 m depth. \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{388   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< The horizontal grid structure}}
\DoxyCodeLine{389 \textcolor{keywordtype}{  real},                  \textcolor{keywordtype}{intent(in)}    :: m\_in\_new\_units\textcolor{comment}{ !< The new internal representation of 1 m depth.}}
\DoxyCodeLine{390 }
\DoxyCodeLine{391   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{392 \textcolor{keywordtype}{  real} :: rescale}
\DoxyCodeLine{393   \textcolor{keywordtype}{integer} :: i, j, isd, ied, jsd, jed, IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{394 }
\DoxyCodeLine{395   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{396   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{397 }
\DoxyCodeLine{398   \textcolor{keywordflow}{if} (m\_in\_new\_units == 1.0) \textcolor{keywordflow}{return}}
\DoxyCodeLine{399   \textcolor{keywordflow}{if} (m\_in\_new\_units < 0.0) \&}
\DoxyCodeLine{400     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"rescale\_grid\_bathymetry: Negative depth units are not permitted."})}
\DoxyCodeLine{401   \textcolor{keywordflow}{if} (m\_in\_new\_units == 0.0) \&}
\DoxyCodeLine{402     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"rescale\_grid\_bathymetry: Zero depth units are not permitted."})}
\DoxyCodeLine{403 }
\DoxyCodeLine{404   rescale = 1.0 / m\_in\_new\_units}
\DoxyCodeLine{405   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{406     g\%bathyT(i,j) = rescale*g\%bathyT(i,j)}
\DoxyCodeLine{407 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{408   \textcolor{keywordflow}{if} (g\%bathymetry\_at\_vel) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb}
\DoxyCodeLine{409     g\%Dblock\_u(i,j) = rescale*g\%Dblock\_u(i,j) ; g\%Dopen\_u(i,j) = rescale*g\%Dopen\_u(i,j)}
\DoxyCodeLine{410 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{411   \textcolor{keywordflow}{if} (g\%bathymetry\_at\_vel) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{412     g\%Dblock\_v(i,j) = rescale*g\%Dblock\_v(i,j) ; g\%Dopen\_v(i,j) = rescale*g\%Dopen\_v(i,j)}
\DoxyCodeLine{413 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{414   g\%max\_depth = rescale*g\%max\_depth}
\DoxyCodeLine{415 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid_a1ed8ca50737525ff437bdb349c8d701f}\label{namespacemom__grid_a1ed8ca50737525ff437bdb349c8d701f}} 
\index{mom\_grid@{mom\_grid}!set\_derived\_metrics@{set\_derived\_metrics}}
\index{set\_derived\_metrics@{set\_derived\_metrics}!mom\_grid@{mom\_grid}}
\doxysubsubsection{\texorpdfstring{set\_derived\_metrics()}{set\_derived\_metrics()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+grid\+::set\+\_\+derived\+\_\+metrics (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US }\end{DoxyParamCaption})}



set\+\_\+derived\+\_\+metrics calculates metric terms that are derived from other metrics. 


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


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


\begin{DoxyCode}{0}
\DoxyCodeLine{420   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{  !< The horizontal grid structure}}
\DoxyCodeLine{421   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{ !< A dimensional unit scaling type}}
\DoxyCodeLine{422 \textcolor{comment}{!    Various inverse grid spacings and derived areas are calculated within this}}
\DoxyCodeLine{423 \textcolor{comment}{!  subroutine.}}
\DoxyCodeLine{424   \textcolor{keywordtype}{integer} :: i, j, isd, ied, jsd, jed}
\DoxyCodeLine{425   \textcolor{keywordtype}{integer} :: IsdB, IedB, JsdB, JedB}
\DoxyCodeLine{426 }
\DoxyCodeLine{427   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{428   isdb = g\%IsdB ; iedb = g\%IedB ; jsdb = g\%JsdB ; jedb = g\%JedB}
\DoxyCodeLine{429 }
\DoxyCodeLine{430   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{431     \textcolor{keywordflow}{if} (g\%dxT(i,j) < 0.0) g\%dxT(i,j) = 0.0}
\DoxyCodeLine{432     \textcolor{keywordflow}{if} (g\%dyT(i,j) < 0.0) g\%dyT(i,j) = 0.0}
\DoxyCodeLine{433     g\%IdxT(i,j) = adcroft\_reciprocal(g\%dxT(i,j))}
\DoxyCodeLine{434     g\%IdyT(i,j) = adcroft\_reciprocal(g\%dyT(i,j))}
\DoxyCodeLine{435     g\%IareaT(i,j) = adcroft\_reciprocal(g\%areaT(i,j))}
\DoxyCodeLine{436 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{437 }
\DoxyCodeLine{438   \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb}
\DoxyCodeLine{439     \textcolor{keywordflow}{if} (g\%dxCu(i,j) < 0.0) g\%dxCu(i,j) = 0.0}
\DoxyCodeLine{440     \textcolor{keywordflow}{if} (g\%dyCu(i,j) < 0.0) g\%dyCu(i,j) = 0.0}
\DoxyCodeLine{441     g\%IdxCu(i,j) = adcroft\_reciprocal(g\%dxCu(i,j))}
\DoxyCodeLine{442     g\%IdyCu(i,j) = adcroft\_reciprocal(g\%dyCu(i,j))}
\DoxyCodeLine{443 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{444 }
\DoxyCodeLine{445   \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied}
\DoxyCodeLine{446     \textcolor{keywordflow}{if} (g\%dxCv(i,j) < 0.0) g\%dxCv(i,j) = 0.0}
\DoxyCodeLine{447     \textcolor{keywordflow}{if} (g\%dyCv(i,j) < 0.0) g\%dyCv(i,j) = 0.0}
\DoxyCodeLine{448     g\%IdxCv(i,j) = adcroft\_reciprocal(g\%dxCv(i,j))}
\DoxyCodeLine{449     g\%IdyCv(i,j) = adcroft\_reciprocal(g\%dyCv(i,j))}
\DoxyCodeLine{450 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{451 }
\DoxyCodeLine{452   \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isdb,iedb}
\DoxyCodeLine{453     \textcolor{keywordflow}{if} (g\%dxBu(i,j) < 0.0) g\%dxBu(i,j) = 0.0}
\DoxyCodeLine{454     \textcolor{keywordflow}{if} (g\%dyBu(i,j) < 0.0) g\%dyBu(i,j) = 0.0}
\DoxyCodeLine{455 }
\DoxyCodeLine{456     g\%IdxBu(i,j) = adcroft\_reciprocal(g\%dxBu(i,j))}
\DoxyCodeLine{457     g\%IdyBu(i,j) = adcroft\_reciprocal(g\%dyBu(i,j))}
\DoxyCodeLine{458     \textcolor{comment}{! areaBu has usually been set to a positive area elsewhere.}}
\DoxyCodeLine{459     \textcolor{keywordflow}{if} (g\%areaBu(i,j) <= 0.0) g\%areaBu(i,j) = g\%dxBu(i,j) * g\%dyBu(i,j)}
\DoxyCodeLine{460     g\%IareaBu(i,j) =  adcroft\_reciprocal(g\%areaBu(i,j))}
\DoxyCodeLine{461 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__grid_a9d2aac0ba53c9072f5f37d9bf97187b2}\label{namespacemom__grid_a9d2aac0ba53c9072f5f37d9bf97187b2}} 
\index{mom\_grid@{mom\_grid}!set\_first\_direction@{set\_first\_direction}}
\index{set\_first\_direction@{set\_first\_direction}!mom\_grid@{mom\_grid}}
\doxysubsubsection{\texorpdfstring{set\_first\_direction()}{set\_first\_direction()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+grid\+::set\+\_\+first\+\_\+direction (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(inout)}]{G,  }\item[{integer, intent(in)}]{y\+\_\+first }\end{DoxyParamCaption})}



Store an integer indicating which direction to work on first. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em y\+\_\+first} & The first direction to store \\
\hline
\end{DoxyParams}


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


\begin{DoxyCode}{0}
\DoxyCodeLine{509   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{510   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)} :: y\_first\textcolor{comment}{ !< The first direction to store}}
\DoxyCodeLine{511 }
\DoxyCodeLine{512   g\%first\_direction = y\_first}

\end{DoxyCode}
