\hypertarget{namespacemom__spatial__means}{}\doxysection{mom\+\_\+spatial\+\_\+means Module Reference}
\label{namespacemom__spatial__means}\index{mom\_spatial\_means@{mom\_spatial\_means}}


\doxysubsection{Detailed Description}
Functions and routines to take area, volume, mass-\/weighted, layerwise, zonal or meridional means. \doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
real function, public \mbox{\hyperlink{namespacemom__spatial__means_a87cad4a44f65c4849de870d15cc3f2a6}{global\+\_\+area\+\_\+mean}} (var, G, scale)
\begin{DoxyCompactList}\small\item\em Return the global area mean of a variable. This uses reproducing sums. \end{DoxyCompactList}\item 
real function, public \mbox{\hyperlink{namespacemom__spatial__means_a25f8ecef035d51fed0f4e97dbf448b63}{global\+\_\+area\+\_\+integral}} (var, G, scale, area)
\begin{DoxyCompactList}\small\item\em Return the global area integral of a variable, by default using the masked area from the grid, but an alternate could be used instead. This uses reproducing sums. \end{DoxyCompactList}\item 
real function, dimension(gv \%ke), public \mbox{\hyperlink{namespacemom__spatial__means_a91bb6f6bd366e02268c5bae2d2c2d79c}{global\+\_\+layer\+\_\+mean}} (var, h, G, GV, scale)
\begin{DoxyCompactList}\small\item\em Return the layerwise global thickness-\/weighted mean of a variable. This uses reproducing sums. \end{DoxyCompactList}\item 
real function, public \mbox{\hyperlink{namespacemom__spatial__means_a54a974cd43b127c910090103890d0bef}{global\+\_\+volume\+\_\+mean}} (var, h, G, GV, scale)
\begin{DoxyCompactList}\small\item\em Find the global thickness-\/weighted mean of a variable. This uses reproducing sums. \end{DoxyCompactList}\item 
real function, public \mbox{\hyperlink{namespacemom__spatial__means_a4c637edc1baf0fbac110c0c6b98ee161}{global\+\_\+mass\+\_\+integral}} (h, G, GV, var, on\+\_\+\+P\+E\+\_\+only, scale)
\begin{DoxyCompactList}\small\item\em Find the global mass-\/weighted integral of a variable. This uses reproducing sums. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__spatial__means_a257babe85df2c4435f119236b94eafe9}{global\+\_\+i\+\_\+mean}} (array, i\+\_\+mean, G, mask, scale, tmp\+\_\+scale)
\begin{DoxyCompactList}\small\item\em Determine the global mean of a field along rows of constant i, returning it in a 1-\/d array using the local indexing. This uses reproducing sums. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__spatial__means_a3c955830f3b9d150d657cb4c18c4b2d9}{global\+\_\+j\+\_\+mean}} (array, j\+\_\+mean, G, mask, scale, tmp\+\_\+scale)
\begin{DoxyCompactList}\small\item\em Determine the global mean of a field along rows of constant j, returning it in a 1-\/d array using the local indexing. This uses reproducing sums. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__spatial__means_ad9473cfc35e049c8cd062b94a5acfc7a}{adjust\+\_\+area\+\_\+mean\+\_\+to\+\_\+zero}} (array, G, scaling, unit\+\_\+scale)
\begin{DoxyCompactList}\small\item\em Adjust 2d array such that area mean is zero without moving the zero contour. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__spatial__means_ad9473cfc35e049c8cd062b94a5acfc7a}\label{namespacemom__spatial__means_ad9473cfc35e049c8cd062b94a5acfc7a}} 
\index{mom\_spatial\_means@{mom\_spatial\_means}!adjust\_area\_mean\_to\_zero@{adjust\_area\_mean\_to\_zero}}
\index{adjust\_area\_mean\_to\_zero@{adjust\_area\_mean\_to\_zero}!mom\_spatial\_means@{mom\_spatial\_means}}
\doxysubsubsection{\texorpdfstring{adjust\_area\_mean\_to\_zero()}{adjust\_area\_mean\_to\_zero()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+spatial\+\_\+means\+::adjust\+\_\+area\+\_\+mean\+\_\+to\+\_\+zero (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(inout)}]{array,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{real, intent(out), optional}]{scaling,  }\item[{real, intent(in), optional}]{unit\+\_\+scale }\end{DoxyParamCaption})}



Adjust 2d array such that area mean is zero without moving the zero contour. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & Grid structure \\
\hline
\mbox{\texttt{ in,out}}  & {\em array} & 2D array to be adjusted \\
\hline
\mbox{\texttt{ out}}  & {\em scaling} & The scaling factor used \\
\hline
\mbox{\texttt{ in}}  & {\em unit\+\_\+scale} & A rescaling factor for the variable \\
\hline
\end{DoxyParams}


Definition at line 368 of file M\+O\+M\+\_\+spatial\+\_\+means.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{368   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{       !< Grid structure}}
\DoxyCodeLine{369 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(inout)} :: array\textcolor{comment}{   !< 2D array to be adjusted}}
\DoxyCodeLine{370 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{optional},                   \textcolor{keywordtype}{intent(out)}   :: scaling\textcolor{comment}{ !< The scaling factor used}}
\DoxyCodeLine{371 \textcolor{keywordtype}{  real},                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: unit\_scale\textcolor{comment}{ !< A rescaling factor for the variable}}
\DoxyCodeLine{372   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{373 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isc:G\%iec, G\%jsc:G\%jec)} :: posVals, negVals, areaXposVals, areaXnegVals}
\DoxyCodeLine{374   \textcolor{keywordtype}{integer} :: i,j}
\DoxyCodeLine{375   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{dimension(2)} :: areaInt\_EFP}
\DoxyCodeLine{376 \textcolor{keywordtype}{  real} :: scalefac  \textcolor{comment}{! A scaling factor for the variable.}}
\DoxyCodeLine{377 \textcolor{keywordtype}{  real} :: I\_scalefac \textcolor{comment}{! The Adcroft reciprocal of scalefac}}
\DoxyCodeLine{378 \textcolor{keywordtype}{  real} :: areaIntPosVals, areaIntNegVals, posScale, negScale}
\DoxyCodeLine{379 }
\DoxyCodeLine{380   scalefac = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(unit\_scale)) scalefac = unit\_scale}
\DoxyCodeLine{381   i\_scalefac = 0.0 ; \textcolor{keywordflow}{if} (scalefac /= 0.0) i\_scalefac = 1.0 / scalefac}
\DoxyCodeLine{382 }
\DoxyCodeLine{383   \textcolor{comment}{! areaXposVals(:,:) = 0.  ! This zeros out halo points.}}
\DoxyCodeLine{384   \textcolor{comment}{! areaXnegVals(:,:) = 0.  ! This zeros out halo points.}}
\DoxyCodeLine{385 }
\DoxyCodeLine{386   \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{387     posvals(i,j) = max(0., scalefac*array(i,j))}
\DoxyCodeLine{388     areaxposvals(i,j) = g\%US\%L\_to\_m**2*g\%areaT(i,j) * posvals(i,j)}
\DoxyCodeLine{389     negvals(i,j) = min(0., scalefac*array(i,j))}
\DoxyCodeLine{390     areaxnegvals(i,j) = g\%US\%L\_to\_m**2*g\%areaT(i,j) * negvals(i,j)}
\DoxyCodeLine{391 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{392 }
\DoxyCodeLine{393   \textcolor{comment}{! Combining the sums like this avoids separate blocking global sums.}}
\DoxyCodeLine{394   areaint\_efp(1) = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum__efp}{reproducing\_sum\_efp}}( areaxposvals, only\_on\_pe=.true. )}
\DoxyCodeLine{395   areaint\_efp(2) = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum__efp}{reproducing\_sum\_efp}}( areaxnegvals, only\_on\_pe=.true. )}
\DoxyCodeLine{396   \textcolor{keyword}{call }\mbox{\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}}(areaint\_efp, 2)}
\DoxyCodeLine{397   areaintposvals = efp\_to\_real( areaint\_efp(1) )}
\DoxyCodeLine{398   areaintnegvals = efp\_to\_real( areaint\_efp(2) )}
\DoxyCodeLine{399 }
\DoxyCodeLine{400   posscale = 0.0 ; negscale = 0.0}
\DoxyCodeLine{401   \textcolor{keywordflow}{if} ((areaintposvals>0.).and.(areaintnegvals<0.)) \textcolor{keywordflow}{then} \textcolor{comment}{! Only adjust if possible}}
\DoxyCodeLine{402     \textcolor{keywordflow}{if} (areaintposvals>-\/areaintnegvals) \textcolor{keywordflow}{then} \textcolor{comment}{! Scale down positive values}}
\DoxyCodeLine{403       posscale = -\/ areaintnegvals / areaintposvals}
\DoxyCodeLine{404       \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{405         array(i,j) = ((posscale * posvals(i,j)) + negvals(i,j)) * i\_scalefac}
\DoxyCodeLine{406 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{407     \textcolor{keywordflow}{elseif} (areaintposvals<-\/areaintnegvals) \textcolor{keywordflow}{then} \textcolor{comment}{! Scale down negative values}}
\DoxyCodeLine{408       negscale = -\/ areaintposvals / areaintnegvals}
\DoxyCodeLine{409       \textcolor{keywordflow}{do} j=g\%jsc,g\%jec ; \textcolor{keywordflow}{do} i=g\%isc,g\%iec}
\DoxyCodeLine{410         array(i,j) = (posvals(i,j) + (negscale * negvals(i,j))) * i\_scalefac}
\DoxyCodeLine{411 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{412 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{413 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{414   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scaling)) scaling = posscale -\/ negscale}
\DoxyCodeLine{415 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__spatial__means_a25f8ecef035d51fed0f4e97dbf448b63}\label{namespacemom__spatial__means_a25f8ecef035d51fed0f4e97dbf448b63}} 
\index{mom\_spatial\_means@{mom\_spatial\_means}!global\_area\_integral@{global\_area\_integral}}
\index{global\_area\_integral@{global\_area\_integral}!mom\_spatial\_means@{mom\_spatial\_means}}
\doxysubsubsection{\texorpdfstring{global\_area\_integral()}{global\_area\_integral()}}
{\footnotesize\ttfamily real function, public mom\+\_\+spatial\+\_\+means\+::global\+\_\+area\+\_\+integral (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{var,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{real, intent(in), optional}]{scale,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in), optional}]{area }\end{DoxyParamCaption})}



Return the global area integral of a variable, by default using the masked area from the grid, but an alternate could be used instead. This uses reproducing sums. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em var} & The variable to integrate \\
\hline
\mbox{\texttt{ in}}  & {\em scale} & A rescaling factor for the variable \\
\hline
\mbox{\texttt{ in}}  & {\em area} & The alternate area to use, including any required masking \mbox{[}L2 $\sim$$>$ m2\mbox{]}. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The returned area integral, usually in the units of var times \mbox{[}m2\mbox{]}. 
\end{DoxyReturn}


Definition at line 53 of file M\+O\+M\+\_\+spatial\+\_\+means.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{53   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{     !< The ocean's grid structure}}
\DoxyCodeLine{54 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}  :: var\textcolor{comment}{   !< The variable to integrate}}
\DoxyCodeLine{55 \textcolor{keywordtype}{  real},                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: scale\textcolor{comment}{ !< A rescaling factor for the variable}}
\DoxyCodeLine{56 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: area\textcolor{comment}{ !< The alternate area to use, including}}
\DoxyCodeLine{57 \textcolor{comment}{                                                          !! any required masking [L2 ~> m2].}}
\DoxyCodeLine{58 \textcolor{keywordtype}{  real} :: global\_area\_integral\textcolor{comment}{ !< The returned area integral, usually in the units of var times [m2].}}
\DoxyCodeLine{59 }
\DoxyCodeLine{60   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{61 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: tmpForSumming}
\DoxyCodeLine{62 \textcolor{keywordtype}{  real} :: scalefac  \textcolor{comment}{! An overall scaling factor for the areas and variable.}}
\DoxyCodeLine{63   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je}
\DoxyCodeLine{64   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{65 }
\DoxyCodeLine{66   scalefac = g\%US\%L\_to\_m**2 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) scalefac = g\%US\%L\_to\_m**2*scale}
\DoxyCodeLine{67 }
\DoxyCodeLine{68   tmpforsumming(:,:) = 0.}
\DoxyCodeLine{69   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(area)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{70     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{71       tmpforsumming(i,j) = var(i,j) * (scalefac * area(i,j))}
\DoxyCodeLine{72 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{73   \textcolor{keywordflow}{else}}
\DoxyCodeLine{74     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{75       tmpforsumming(i,j) = var(i,j) * (scalefac * g\%areaT(i,j) * g\%mask2dT(i,j))}
\DoxyCodeLine{76 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{77 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{78   global\_area\_integral = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}}(tmpforsumming)}
\DoxyCodeLine{79 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__spatial__means_a87cad4a44f65c4849de870d15cc3f2a6}\label{namespacemom__spatial__means_a87cad4a44f65c4849de870d15cc3f2a6}} 
\index{mom\_spatial\_means@{mom\_spatial\_means}!global\_area\_mean@{global\_area\_mean}}
\index{global\_area\_mean@{global\_area\_mean}!mom\_spatial\_means@{mom\_spatial\_means}}
\doxysubsubsection{\texorpdfstring{global\_area\_mean()}{global\_area\_mean()}}
{\footnotesize\ttfamily real function, public mom\+\_\+spatial\+\_\+means\+::global\+\_\+area\+\_\+mean (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g), szj\+\_\+(g)), intent(in)}]{var,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{real, intent(in), optional}]{scale }\end{DoxyParamCaption})}



Return the global area mean of a variable. This uses reproducing sums. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em var} & The variable to average \\
\hline
\mbox{\texttt{ in}}  & {\em scale} & A rescaling factor for the variable \\
\hline
\end{DoxyParams}


Definition at line 29 of file M\+O\+M\+\_\+spatial\+\_\+means.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{29   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{30 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}  :: var\textcolor{comment}{  !< The variable to average}}
\DoxyCodeLine{31 \textcolor{keywordtype}{  real},                    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: scale\textcolor{comment}{ !< A rescaling factor for the variable}}
\DoxyCodeLine{32 }
\DoxyCodeLine{33 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))}              :: tmpForSumming}
\DoxyCodeLine{34 \textcolor{keywordtype}{  real} :: global\_area\_mean}
\DoxyCodeLine{35 }
\DoxyCodeLine{36 \textcolor{keywordtype}{  real} :: scalefac  \textcolor{comment}{! An overall scaling factor for the areas and variable.}}
\DoxyCodeLine{37   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je}
\DoxyCodeLine{38   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{39 }
\DoxyCodeLine{40   scalefac = g\%US\%L\_to\_m**2 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) scalefac = g\%US\%L\_to\_m**2*scale}
\DoxyCodeLine{41 }
\DoxyCodeLine{42   tmpforsumming(:,:) = 0.}
\DoxyCodeLine{43   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{44     tmpforsumming(i,j) = var(i,j) * (scalefac * g\%areaT(i,j) * g\%mask2dT(i,j))}
\DoxyCodeLine{45 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{46   global\_area\_mean = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}}(tmpforsumming) * g\%IareaT\_global}
\DoxyCodeLine{47 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__spatial__means_a257babe85df2c4435f119236b94eafe9}\label{namespacemom__spatial__means_a257babe85df2c4435f119236b94eafe9}} 
\index{mom\_spatial\_means@{mom\_spatial\_means}!global\_i\_mean@{global\_i\_mean}}
\index{global\_i\_mean@{global\_i\_mean}!mom\_spatial\_means@{mom\_spatial\_means}}
\doxysubsubsection{\texorpdfstring{global\_i\_mean()}{global\_i\_mean()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+spatial\+\_\+means\+::global\+\_\+i\+\_\+mean (\begin{DoxyParamCaption}\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in)}]{array,  }\item[{real, dimension(szj\+\_\+(g)), intent(out)}]{i\+\_\+mean,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(in), optional}]{mask,  }\item[{real, intent(in), optional}]{scale,  }\item[{real, intent(in), optional}]{tmp\+\_\+scale }\end{DoxyParamCaption})}



Determine the global mean of a field along rows of constant i, returning it in a 1-\/d array using the local indexing. This uses reproducing sums. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em array} & The variable being averaged \\
\hline
\mbox{\texttt{ out}}  & {\em i\+\_\+mean} & Global mean of array along its i-\/axis \\
\hline
\mbox{\texttt{ in}}  & {\em mask} & An array used for weighting the i-\/mean \\
\hline
\mbox{\texttt{ in}}  & {\em scale} & A rescaling factor for the output variable \\
\hline
\mbox{\texttt{ in}}  & {\em tmp\+\_\+scale} & A rescaling factor for the internal calculations that is removed from the output \\
\hline
\end{DoxyParams}


Definition at line 197 of file M\+O\+M\+\_\+spatial\+\_\+means.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{197   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{198 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: array\textcolor{comment}{  !< The variable being averaged}}
\DoxyCodeLine{199 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZJ\_(G))},         \textcolor{keywordtype}{intent(out)}   :: i\_mean\textcolor{comment}{ !< Global mean of array along its i-\/axis}}
\DoxyCodeLine{200 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \&}
\DoxyCodeLine{201                           \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: mask\textcolor{comment}{  !< An array used for weighting the i-\/mean}}
\DoxyCodeLine{202 \textcolor{keywordtype}{  real},                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: scale\textcolor{comment}{ !< A rescaling factor for the output variable}}
\DoxyCodeLine{203 \textcolor{keywordtype}{  real},                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: tmp\_scale\textcolor{comment}{ !< A rescaling factor for the internal}}
\DoxyCodeLine{204 \textcolor{comment}{                                                           !! calculations that is removed from the output}}
\DoxyCodeLine{205 }
\DoxyCodeLine{206   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{207   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)} :: asum, mask\_sum}
\DoxyCodeLine{208 \textcolor{keywordtype}{  real} :: scalefac  \textcolor{comment}{! A scaling factor for the variable.}}
\DoxyCodeLine{209 \textcolor{keywordtype}{  real} :: unscale   \textcolor{comment}{! A factor for undoing any internal rescaling before output.}}
\DoxyCodeLine{210 \textcolor{keywordtype}{  real} :: mask\_sum\_r}
\DoxyCodeLine{211   \textcolor{keywordtype}{integer} :: is, ie, js, je, idg\_off, jdg\_off}
\DoxyCodeLine{212   \textcolor{keywordtype}{integer} :: i, j}
\DoxyCodeLine{213 }
\DoxyCodeLine{214   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{215   idg\_off = g\%idg\_offset ; jdg\_off = g\%jdg\_offset}
\DoxyCodeLine{216 }
\DoxyCodeLine{217   scalefac = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) scalefac = scale}
\DoxyCodeLine{218   unscale = 1.0}
\DoxyCodeLine{219   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(tmp\_scale)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (tmp\_scale /= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{220     scalefac = scalefac * tmp\_scale ; unscale = 1.0 / tmp\_scale}
\DoxyCodeLine{221 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{222   \textcolor{keyword}{call }reset\_efp\_overflow\_error()}
\DoxyCodeLine{223 }
\DoxyCodeLine{224   \textcolor{keyword}{allocate}(asum(g\%jsg:g\%jeg))}
\DoxyCodeLine{225   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(mask)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{226     \textcolor{keyword}{allocate}(mask\_sum(g\%jsg:g\%jeg))}
\DoxyCodeLine{227 }
\DoxyCodeLine{228     \textcolor{keywordflow}{do} j=g\%jsg,g\%jeg}
\DoxyCodeLine{229       asum(j) = real\_to\_efp(0.0) ; mask\_sum(j) = real\_to\_efp(0.0)}
\DoxyCodeLine{230 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{231 }
\DoxyCodeLine{232     \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{233       asum(j+jdg\_off) = asum(j+jdg\_off) + real\_to\_efp(scalefac*array(i,j)*mask(i,j))}
\DoxyCodeLine{234       mask\_sum(j+jdg\_off) = mask\_sum(j+jdg\_off) + real\_to\_efp(mask(i,j))}
\DoxyCodeLine{235 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{236 }
\DoxyCodeLine{237     \textcolor{keywordflow}{if} (query\_efp\_overflow\_error()) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{238       \textcolor{stringliteral}{"global\_i\_mean overflow error occurred before sums across PEs."})}
\DoxyCodeLine{239 }
\DoxyCodeLine{240     \textcolor{keyword}{call }\mbox{\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}}(asum(g\%jsg:g\%jeg), g\%jeg-\/g\%jsg+1)}
\DoxyCodeLine{241     \textcolor{keyword}{call }\mbox{\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}}(mask\_sum(g\%jsg:g\%jeg), g\%jeg-\/g\%jsg+1)}
\DoxyCodeLine{242 }
\DoxyCodeLine{243     \textcolor{keywordflow}{if} (query\_efp\_overflow\_error()) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{244       \textcolor{stringliteral}{"global\_i\_mean overflow error occurred during sums across PEs."})}
\DoxyCodeLine{245 }
\DoxyCodeLine{246     \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{247       mask\_sum\_r = efp\_to\_real(mask\_sum(j+jdg\_off))}
\DoxyCodeLine{248       \textcolor{keywordflow}{if} (mask\_sum\_r == 0.0 ) \textcolor{keywordflow}{then} ; i\_mean(j) = 0.0 ; \textcolor{keywordflow}{else}}
\DoxyCodeLine{249         i\_mean(j) = efp\_to\_real(asum(j+jdg\_off)) / mask\_sum\_r}
\DoxyCodeLine{250 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{251 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{252 }
\DoxyCodeLine{253     \textcolor{keyword}{deallocate}(mask\_sum)}
\DoxyCodeLine{254   \textcolor{keywordflow}{else}}
\DoxyCodeLine{255     \textcolor{keywordflow}{do} j=g\%jsg,g\%jeg ; asum(j) = real\_to\_efp(0.0) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{256 }
\DoxyCodeLine{257     \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{258       asum(j+jdg\_off) = asum(j+jdg\_off) + real\_to\_efp(scalefac*array(i,j))}
\DoxyCodeLine{259 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{260 }
\DoxyCodeLine{261     \textcolor{keywordflow}{if} (query\_efp\_overflow\_error()) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{262       \textcolor{stringliteral}{"global\_i\_mean overflow error occurred before sum across PEs."})}
\DoxyCodeLine{263 }
\DoxyCodeLine{264     \textcolor{keyword}{call }\mbox{\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}}(asum(g\%jsg:g\%jeg), g\%jeg-\/g\%jsg+1)}
\DoxyCodeLine{265 }
\DoxyCodeLine{266     \textcolor{keywordflow}{if} (query\_efp\_overflow\_error()) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{267       \textcolor{stringliteral}{"global\_i\_mean overflow error occurred during sum across PEs."})}
\DoxyCodeLine{268 }
\DoxyCodeLine{269     \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{270       i\_mean(j) = efp\_to\_real(asum(j+jdg\_off)) / real(g\%ieg-\/g\%isg+1)}
\DoxyCodeLine{271 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{272 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{273 }
\DoxyCodeLine{274   \textcolor{keywordflow}{if} (unscale /= 1.0) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} j=js,je ; i\_mean(j) = unscale*i\_mean(j) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{275 }
\DoxyCodeLine{276   \textcolor{keyword}{deallocate}(asum)}
\DoxyCodeLine{277 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__spatial__means_a3c955830f3b9d150d657cb4c18c4b2d9}\label{namespacemom__spatial__means_a3c955830f3b9d150d657cb4c18c4b2d9}} 
\index{mom\_spatial\_means@{mom\_spatial\_means}!global\_j\_mean@{global\_j\_mean}}
\index{global\_j\_mean@{global\_j\_mean}!mom\_spatial\_means@{mom\_spatial\_means}}
\doxysubsubsection{\texorpdfstring{global\_j\_mean()}{global\_j\_mean()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+spatial\+\_\+means\+::global\+\_\+j\+\_\+mean (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in)}]{array,  }\item[{real, dimension( g \%isd\+: g \%ied), intent(out)}]{j\+\_\+mean,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed), intent(in), optional}]{mask,  }\item[{real, intent(in), optional}]{scale,  }\item[{real, intent(in), optional}]{tmp\+\_\+scale }\end{DoxyParamCaption})}



Determine the global mean of a field along rows of constant j, returning it in a 1-\/d array using the local indexing. This uses reproducing sums. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em array} & The variable being averaged \\
\hline
\mbox{\texttt{ out}}  & {\em j\+\_\+mean} & Global mean of array along its j-\/axis \\
\hline
\mbox{\texttt{ in}}  & {\em mask} & An array used for weighting the j-\/mean \\
\hline
\mbox{\texttt{ in}}  & {\em scale} & A rescaling factor for the output variable \\
\hline
\mbox{\texttt{ in}}  & {\em tmp\+\_\+scale} & A rescaling factor for the internal calculations that is removed from the output \\
\hline
\end{DoxyParams}


Definition at line 283 of file M\+O\+M\+\_\+spatial\+\_\+means.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{283   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(inout)} :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{284 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: array\textcolor{comment}{  !< The variable being averaged}}
\DoxyCodeLine{285 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G))},         \textcolor{keywordtype}{intent(out)}   :: j\_mean\textcolor{comment}{ !<  Global mean of array along its j-\/axis}}
\DoxyCodeLine{286 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \&}
\DoxyCodeLine{287                           \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: mask\textcolor{comment}{  !< An array used for weighting the j-\/mean}}
\DoxyCodeLine{288 \textcolor{keywordtype}{  real},                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: scale\textcolor{comment}{ !< A rescaling factor for the output variable}}
\DoxyCodeLine{289 \textcolor{keywordtype}{  real},                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: tmp\_scale\textcolor{comment}{ !< A rescaling factor for the internal}}
\DoxyCodeLine{290 \textcolor{comment}{                                                           !! calculations that is removed from the output}}
\DoxyCodeLine{291 }
\DoxyCodeLine{292   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{293   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)} :: asum, mask\_sum}
\DoxyCodeLine{294 \textcolor{keywordtype}{  real} :: mask\_sum\_r}
\DoxyCodeLine{295 \textcolor{keywordtype}{  real} :: scalefac  \textcolor{comment}{! A scaling factor for the variable.}}
\DoxyCodeLine{296 \textcolor{keywordtype}{  real} :: unscale   \textcolor{comment}{! A factor for undoing any internal rescaling before output.}}
\DoxyCodeLine{297   \textcolor{keywordtype}{integer} :: is, ie, js, je, idg\_off, jdg\_off}
\DoxyCodeLine{298   \textcolor{keywordtype}{integer} :: i, j}
\DoxyCodeLine{299 }
\DoxyCodeLine{300   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{301   idg\_off = g\%idg\_offset ; jdg\_off = g\%jdg\_offset}
\DoxyCodeLine{302 }
\DoxyCodeLine{303   scalefac = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) scalefac = scale}
\DoxyCodeLine{304   unscale = 1.0}
\DoxyCodeLine{305   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(tmp\_scale)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (tmp\_scale /= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{306     scalefac = scalefac * tmp\_scale ; unscale = 1.0 / tmp\_scale}
\DoxyCodeLine{307 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{308   \textcolor{keyword}{call }reset\_efp\_overflow\_error()}
\DoxyCodeLine{309 }
\DoxyCodeLine{310   \textcolor{keyword}{allocate}(asum(g\%isg:g\%ieg))}
\DoxyCodeLine{311   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(mask)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{312     \textcolor{keyword}{allocate} (mask\_sum(g\%isg:g\%ieg))}
\DoxyCodeLine{313 }
\DoxyCodeLine{314     \textcolor{keywordflow}{do} i=g\%isg,g\%ieg}
\DoxyCodeLine{315       asum(i) = real\_to\_efp(0.0) ; mask\_sum(i) = real\_to\_efp(0.0)}
\DoxyCodeLine{316 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{317 }
\DoxyCodeLine{318     \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{319       asum(i+idg\_off) = asum(i+idg\_off) + real\_to\_efp(scalefac*array(i,j)*mask(i,j))}
\DoxyCodeLine{320       mask\_sum(i+idg\_off) = mask\_sum(i+idg\_off) + real\_to\_efp(mask(i,j))}
\DoxyCodeLine{321 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{322 }
\DoxyCodeLine{323     \textcolor{keywordflow}{if} (query\_efp\_overflow\_error()) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{324       \textcolor{stringliteral}{"global\_j\_mean overflow error occurred before sums across PEs."})}
\DoxyCodeLine{325 }
\DoxyCodeLine{326     \textcolor{keyword}{call }\mbox{\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}}(asum(g\%isg:g\%ieg), g\%ieg-\/g\%isg+1)}
\DoxyCodeLine{327     \textcolor{keyword}{call }\mbox{\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}}(mask\_sum(g\%isg:g\%ieg), g\%ieg-\/g\%isg+1)}
\DoxyCodeLine{328 }
\DoxyCodeLine{329     \textcolor{keywordflow}{if} (query\_efp\_overflow\_error()) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{330       \textcolor{stringliteral}{"global\_j\_mean overflow error occurred during sums across PEs."})}
\DoxyCodeLine{331 }
\DoxyCodeLine{332     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{333       mask\_sum\_r = efp\_to\_real(mask\_sum(i+idg\_off))}
\DoxyCodeLine{334       \textcolor{keywordflow}{if} (mask\_sum\_r == 0.0 ) \textcolor{keywordflow}{then} ; j\_mean(i) = 0.0 ; \textcolor{keywordflow}{else}}
\DoxyCodeLine{335         j\_mean(i) = efp\_to\_real(asum(i+idg\_off)) / mask\_sum\_r}
\DoxyCodeLine{336 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{337 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{338 }
\DoxyCodeLine{339     \textcolor{keyword}{deallocate}(mask\_sum)}
\DoxyCodeLine{340   \textcolor{keywordflow}{else}}
\DoxyCodeLine{341     \textcolor{keywordflow}{do} i=g\%isg,g\%ieg ; asum(i) = real\_to\_efp(0.0) ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{342 }
\DoxyCodeLine{343     \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{344       asum(i+idg\_off) = asum(i+idg\_off) + real\_to\_efp(scalefac*array(i,j))}
\DoxyCodeLine{345 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{346 }
\DoxyCodeLine{347     \textcolor{keywordflow}{if} (query\_efp\_overflow\_error()) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{348       \textcolor{stringliteral}{"global\_j\_mean overflow error occurred before sum across PEs."})}
\DoxyCodeLine{349 }
\DoxyCodeLine{350     \textcolor{keyword}{call }\mbox{\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}}(asum(g\%isg:g\%ieg), g\%ieg-\/g\%isg+1)}
\DoxyCodeLine{351 }
\DoxyCodeLine{352     \textcolor{keywordflow}{if} (query\_efp\_overflow\_error()) \textcolor{keyword}{call }mom\_error(fatal, \&}
\DoxyCodeLine{353       \textcolor{stringliteral}{"global\_j\_mean overflow error occurred during sum across PEs."})}
\DoxyCodeLine{354 }
\DoxyCodeLine{355     \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{356       j\_mean(i) = efp\_to\_real(asum(i+idg\_off)) / real(g\%jeg-\/g\%jsg+1)}
\DoxyCodeLine{357 \textcolor{keywordflow}{    enddo}}
\DoxyCodeLine{358 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{359 }
\DoxyCodeLine{360   \textcolor{keywordflow}{if} (unscale /= 1.0) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} i=is,ie ; j\_mean(i) = unscale*j\_mean(i) ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ endif}}
\DoxyCodeLine{361 }
\DoxyCodeLine{362   \textcolor{keyword}{deallocate}(asum)}
\DoxyCodeLine{363 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__spatial__means_a91bb6f6bd366e02268c5bae2d2c2d79c}\label{namespacemom__spatial__means_a91bb6f6bd366e02268c5bae2d2c2d79c}} 
\index{mom\_spatial\_means@{mom\_spatial\_means}!global\_layer\_mean@{global\_layer\_mean}}
\index{global\_layer\_mean@{global\_layer\_mean}!mom\_spatial\_means@{mom\_spatial\_means}}
\doxysubsubsection{\texorpdfstring{global\_layer\_mean()}{global\_layer\_mean()}}
{\footnotesize\ttfamily real function, dimension( gv \%ke), public mom\+\_\+spatial\+\_\+means\+::global\+\_\+layer\+\_\+mean (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{var,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{h,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, intent(in), optional}]{scale }\end{DoxyParamCaption})}



Return the layerwise global thickness-\/weighted mean of a variable. This uses reproducing sums. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em var} & The variable to average \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em scale} & A rescaling factor for the variable \\
\hline
\end{DoxyParams}


Definition at line 84 of file M\+O\+M\+\_\+spatial\+\_\+means.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{84   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{85   \textcolor{keywordtype}{type}(verticalGrid\_type),                   \textcolor{keywordtype}{intent(in)}  :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{86 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \textcolor{keywordtype}{intent(in)}  :: var\textcolor{comment}{  !< The variable to average}}
\DoxyCodeLine{87 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \textcolor{keywordtype}{intent(in)}  :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-\/2]}}
\DoxyCodeLine{88 \textcolor{keywordtype}{  real},                            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: scale\textcolor{comment}{ !< A rescaling factor for the variable}}
\DoxyCodeLine{89 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV))}                   :: global\_layer\_mean}
\DoxyCodeLine{90 }
\DoxyCodeLine{91 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(G\%isc:G\%iec, G\%jsc:G\%jec, SZK\_(GV))} :: tmpForSumming, weight}
\DoxyCodeLine{92   \textcolor{keywordtype}{type}(EFP\_type), \textcolor{keywordtype}{dimension(2*SZK\_(GV))} :: laysums}
\DoxyCodeLine{93 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZK\_(GV))} :: global\_temp\_scalar, global\_weight\_scalar}
\DoxyCodeLine{94 \textcolor{keywordtype}{  real} :: scalefac  \textcolor{comment}{! A scaling factor for the variable.}}
\DoxyCodeLine{95   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz}
\DoxyCodeLine{96   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = gv\%ke}
\DoxyCodeLine{97 }
\DoxyCodeLine{98   scalefac = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) scalefac = scale}
\DoxyCodeLine{99   tmpforsumming(:,:,:) = 0. ; weight(:,:,:) = 0.}
\DoxyCodeLine{100 }
\DoxyCodeLine{101   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{102     weight(i,j,k)  =  (gv\%H\_to\_m * h(i,j,k)) * (g\%US\%L\_to\_m**2*g\%areaT(i,j) * g\%mask2dT(i,j))}
\DoxyCodeLine{103     tmpforsumming(i,j,k) =  scalefac * var(i,j,k) * weight(i,j,k)}
\DoxyCodeLine{104 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{105 }
\DoxyCodeLine{106   global\_temp\_scalar = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}}(tmpforsumming, efp\_lay\_sums=laysums(1:nz), only\_on\_pe=.true.)}
\DoxyCodeLine{107   global\_weight\_scalar = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}}(weight, efp\_lay\_sums=laysums(nz+1:2*nz), only\_on\_pe=.true.)}
\DoxyCodeLine{108   \textcolor{keyword}{call }\mbox{\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}}(laysums, 2*nz)}
\DoxyCodeLine{109 }
\DoxyCodeLine{110   \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{111     global\_layer\_mean(k) = efp\_to\_real(laysums(k)) / efp\_to\_real(laysums(nz+k))}
\DoxyCodeLine{112 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{113 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__spatial__means_a4c637edc1baf0fbac110c0c6b98ee161}\label{namespacemom__spatial__means_a4c637edc1baf0fbac110c0c6b98ee161}} 
\index{mom\_spatial\_means@{mom\_spatial\_means}!global\_mass\_integral@{global\_mass\_integral}}
\index{global\_mass\_integral@{global\_mass\_integral}!mom\_spatial\_means@{mom\_spatial\_means}}
\doxysubsubsection{\texorpdfstring{global\_mass\_integral()}{global\_mass\_integral()}}
{\footnotesize\ttfamily real function, public mom\+\_\+spatial\+\_\+means\+::global\+\_\+mass\+\_\+integral (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{h,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in), optional}]{var,  }\item[{logical, intent(in), optional}]{on\+\_\+\+P\+E\+\_\+only,  }\item[{real, intent(in), optional}]{scale }\end{DoxyParamCaption})}



Find the global mass-\/weighted integral of a variable. This uses reproducing sums. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em var} & The variable being integrated \\
\hline
\mbox{\texttt{ in}}  & {\em on\+\_\+pe\+\_\+only} & If present and true, the sum is only done on the local PE, and it is {\itshape not} order invariant. \\
\hline
\mbox{\texttt{ in}}  & {\em scale} & A rescaling factor for the variable \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The mass-\/weighted integral of var (or 1) in kg times the units of var 
\end{DoxyReturn}


Definition at line 149 of file M\+O\+M\+\_\+spatial\+\_\+means.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{149   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{150   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}  :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{151 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \&}
\DoxyCodeLine{152                            \textcolor{keywordtype}{intent(in)}  :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-\/2]}}
\DoxyCodeLine{153 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \&}
\DoxyCodeLine{154                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: var\textcolor{comment}{  !< The variable being integrated}}
\DoxyCodeLine{155   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: on\_PE\_only\textcolor{comment}{  !< If present and true, the sum is only}}
\DoxyCodeLine{156 \textcolor{comment}{                                !! done on the local PE, and it is \_not\_ order invariant.}}
\DoxyCodeLine{157 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: scale\textcolor{comment}{ !< A rescaling factor for the variable}}
\DoxyCodeLine{158 \textcolor{keywordtype}{  real} :: global\_mass\_integral\textcolor{comment}{  !< The mass-\/weighted integral of var (or 1) in}}
\DoxyCodeLine{159 \textcolor{comment}{                                !! kg times the units of var}}
\DoxyCodeLine{160 }
\DoxyCodeLine{161 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))} :: tmpForSumming}
\DoxyCodeLine{162 \textcolor{keywordtype}{  real} :: scalefac  \textcolor{comment}{! An overall scaling factor for the areas and variable.}}
\DoxyCodeLine{163   \textcolor{keywordtype}{logical} :: global\_sum}
\DoxyCodeLine{164   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz}
\DoxyCodeLine{165   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = gv\%ke}
\DoxyCodeLine{166 }
\DoxyCodeLine{167   scalefac = g\%US\%L\_to\_m**2 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) scalefac = g\%US\%L\_to\_m**2*scale}
\DoxyCodeLine{168   tmpforsumming(:,:) = 0.0}
\DoxyCodeLine{169 }
\DoxyCodeLine{170   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(var)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{171     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{172       tmpforsumming(i,j) = tmpforsumming(i,j) + var(i,j,k) * \&}
\DoxyCodeLine{173                 ((gv\%H\_to\_kg\_m2 * h(i,j,k)) * (scalefac*g\%areaT(i,j) * g\%mask2dT(i,j)))}
\DoxyCodeLine{174 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{175   \textcolor{keywordflow}{else}}
\DoxyCodeLine{176     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{177       tmpforsumming(i,j) = tmpforsumming(i,j) + \&}
\DoxyCodeLine{178                 ((gv\%H\_to\_kg\_m2 * h(i,j,k)) * (scalefac*g\%areaT(i,j) * g\%mask2dT(i,j)))}
\DoxyCodeLine{179 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{180 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{181   global\_sum = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(on\_pe\_only)) global\_sum = .not.on\_pe\_only}
\DoxyCodeLine{182   \textcolor{keywordflow}{if} (global\_sum) \textcolor{keywordflow}{then}}
\DoxyCodeLine{183     global\_mass\_integral = \mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}}(tmpforsumming)}
\DoxyCodeLine{184   \textcolor{keywordflow}{else}}
\DoxyCodeLine{185     global\_mass\_integral = 0.0}
\DoxyCodeLine{186     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{187       global\_mass\_integral = global\_mass\_integral + tmpforsumming(i,j)}
\DoxyCodeLine{188 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{189 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{190 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__spatial__means_a54a974cd43b127c910090103890d0bef}\label{namespacemom__spatial__means_a54a974cd43b127c910090103890d0bef}} 
\index{mom\_spatial\_means@{mom\_spatial\_means}!global\_volume\_mean@{global\_volume\_mean}}
\index{global\_volume\_mean@{global\_volume\_mean}!mom\_spatial\_means@{mom\_spatial\_means}}
\doxysubsubsection{\texorpdfstring{global\_volume\_mean()}{global\_volume\_mean()}}
{\footnotesize\ttfamily real function, public mom\+\_\+spatial\+\_\+means\+::global\+\_\+volume\+\_\+mean (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{var,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, gv \%ke), intent(in)}]{h,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, intent(in), optional}]{scale }\end{DoxyParamCaption})}



Find the global thickness-\/weighted mean of a variable. This uses reproducing sums. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em var} & The variable being averaged \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em scale} & A rescaling factor for the variable \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The thickness-\/weighted average of var 
\end{DoxyReturn}


Definition at line 118 of file M\+O\+M\+\_\+spatial\+\_\+means.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{118   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}  :: G\textcolor{comment}{    !< The ocean's grid structure}}
\DoxyCodeLine{119   \textcolor{keywordtype}{type}(verticalGrid\_type), \textcolor{keywordtype}{intent(in)}  :: GV\textcolor{comment}{   !< The ocean's vertical grid structure}}
\DoxyCodeLine{120 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \&}
\DoxyCodeLine{121                            \textcolor{keywordtype}{intent(in)}  :: var\textcolor{comment}{  !< The variable being averaged}}
\DoxyCodeLine{122 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \&}
\DoxyCodeLine{123                            \textcolor{keywordtype}{intent(in)}  :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-\/2]}}
\DoxyCodeLine{124 \textcolor{keywordtype}{  real},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: scale\textcolor{comment}{ !< A rescaling factor for the variable}}
\DoxyCodeLine{125 \textcolor{keywordtype}{  real} :: global\_volume\_mean\textcolor{comment}{  !< The thickness-\/weighted average of var}}
\DoxyCodeLine{126 }
\DoxyCodeLine{127 \textcolor{keywordtype}{  real} :: scalefac  \textcolor{comment}{! A scaling factor for the variable.}}
\DoxyCodeLine{128 \textcolor{keywordtype}{  real} :: weight\_here}
\DoxyCodeLine{129 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))} :: tmpForSumming, sum\_weight}
\DoxyCodeLine{130   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz}
\DoxyCodeLine{131   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = gv\%ke}
\DoxyCodeLine{132 }
\DoxyCodeLine{133   scalefac = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) scalefac = scale}
\DoxyCodeLine{134   tmpforsumming(:,:) = 0. ; sum\_weight(:,:) = 0.}
\DoxyCodeLine{135 }
\DoxyCodeLine{136   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{137     weight\_here  =  (gv\%H\_to\_m * h(i,j,k)) * (g\%US\%L\_to\_m**2*g\%areaT(i,j) * g\%mask2dT(i,j))}
\DoxyCodeLine{138     tmpforsumming(i,j) = tmpforsumming(i,j) + scalefac * var(i,j,k) * weight\_here}
\DoxyCodeLine{139     sum\_weight(i,j) = sum\_weight(i,j) + weight\_here}
\DoxyCodeLine{140 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{141   global\_volume\_mean = (\mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}}(tmpforsumming)) / \&}
\DoxyCodeLine{142                        (\mbox{\hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}}(sum\_weight))}
\DoxyCodeLine{143 }

\end{DoxyCode}
