\hypertarget{namespacemom__spatial__means}{}\section{mom\+\_\+spatial\+\_\+means Module Reference}
\label{namespacemom__spatial__means}\index{mom\+\_\+spatial\+\_\+means@{mom\+\_\+spatial\+\_\+means}}


\subsection{Detailed Description}
Functions and routines to take area, volume, mass-\/weighted, layerwise, zonal or meridional means. \subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
real function, public \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 \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 \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 \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 \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 \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 \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 \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}


\subsection{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}}
\subsubsection{\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{\tt in}  & {\em g} & Grid structure\\
\hline
\mbox{\tt in,out}  & {\em array} & 2D array to be adjusted\\
\hline
\mbox{\tt out}  & {\em scaling} & The scaling factor used\\
\hline
\mbox{\tt 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}
368   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{       !< Grid structure}
369   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(inout)} :: array\textcolor{comment}{   !< 2D array to be adjusted}
370   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional},                   \textcolor{keywordtype}{intent(out)}   :: scaling\textcolor{comment}{ !< The scaling factor used}
371   \textcolor{keywordtype}{real},                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: unit\_scale\textcolor{comment}{ !< A rescaling factor for the variable}
372   \textcolor{comment}{! Local variables}
373   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isc:G%iec, G%jsc:G%jec)} :: posvals, negvals, areaxposvals, areaxnegvals
374   \textcolor{keywordtype}{integer} :: i,j
375   \textcolor{keywordtype}{type}(\hyperlink{structmom__coms_1_1efp__type}{efp\_type}), \textcolor{keywordtype}{dimension(2)} :: areaint\_efp
376   \textcolor{keywordtype}{real} :: scalefac  \textcolor{comment}{! A scaling factor for the variable.}
377   \textcolor{keywordtype}{real} :: i\_scalefac \textcolor{comment}{! The Adcroft reciprocal of scalefac}
378   \textcolor{keywordtype}{real} :: areaintposvals, areaintnegvals, posscale, negscale
379 
380   scalefac = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(unit\_scale)) scalefac = unit\_scale
381   i\_scalefac = 0.0 ; \textcolor{keywordflow}{if} (scalefac /= 0.0) i\_scalefac = 1.0 / scalefac
382 
383   \textcolor{comment}{! areaXposVals(:,:) = 0.  ! This zeros out halo points.}
384   \textcolor{comment}{! areaXnegVals(:,:) = 0.  ! This zeros out halo points.}
385 
386   \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
387     posvals(i,j) = max(0., scalefac*array(i,j))
388     areaxposvals(i,j) = g%US%L\_to\_m**2*g%areaT(i,j) * posvals(i,j)
389     negvals(i,j) = min(0., scalefac*array(i,j))
390     areaxnegvals(i,j) = g%US%L\_to\_m**2*g%areaT(i,j) * negvals(i,j)
391 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
392 
393   \textcolor{comment}{! Combining the sums like this avoids separate blocking global sums.}
394   areaint\_efp(1) = \hyperlink{interfacemom__coms_1_1reproducing__sum__efp}{reproducing\_sum\_efp}( areaxposvals, only\_on\_pe=.true. )
395   areaint\_efp(2) = \hyperlink{interfacemom__coms_1_1reproducing__sum__efp}{reproducing\_sum\_efp}( areaxnegvals, only\_on\_pe=.true. )
396   \textcolor{keyword}{call }\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}(areaint\_efp, 2)
397   areaintposvals = efp\_to\_real( areaint\_efp(1) )
398   areaintnegvals = efp\_to\_real( areaint\_efp(2) )
399 
400   posscale = 0.0 ; negscale = 0.0
401   \textcolor{keywordflow}{if} ((areaintposvals>0.).and.(areaintnegvals<0.)) \textcolor{keywordflow}{then} \textcolor{comment}{! Only adjust if possible}
402     \textcolor{keywordflow}{if} (areaintposvals>-areaintnegvals) \textcolor{keywordflow}{then} \textcolor{comment}{! Scale down positive values}
403       posscale = - areaintnegvals / areaintposvals
404       \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
405         array(i,j) = ((posscale * posvals(i,j)) + negvals(i,j)) * i\_scalefac
406 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
407     \textcolor{keywordflow}{elseif} (areaintposvals<-areaintnegvals) \textcolor{keywordflow}{then} \textcolor{comment}{! Scale down negative values}
408       negscale = - areaintposvals / areaintnegvals
409       \textcolor{keywordflow}{do} j=g%jsc,g%jec ; \textcolor{keywordflow}{do} i=g%isc,g%iec
410         array(i,j) = (posvals(i,j) + (negscale * negvals(i,j))) * i\_scalefac
411 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
412 \textcolor{keywordflow}{    endif}
413 \textcolor{keywordflow}{  endif}
414   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scaling)) scaling = posscale - negscale
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}}
\subsubsection{\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{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em var} & The variable to integrate\\
\hline
\mbox{\tt in}  & {\em scale} & A rescaling factor for the variable\\
\hline
\mbox{\tt 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}
53   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{     !< The ocean's grid structure}
54   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}  :: var\textcolor{comment}{   !< The variable to integrate}
55   \textcolor{keywordtype}{real},                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: scale\textcolor{comment}{ !< A rescaling factor for the variable}
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}
57 \textcolor{comment}{                                                          !! any required masking [L2 ~> m2].}
58   \textcolor{keywordtype}{real} :: global\_area\_integral\textcolor{comment}{ !< The returned area integral, usually in the units of var times [m2].}
59 
60   \textcolor{comment}{! Local variables}
61   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))} :: tmpforsumming
62   \textcolor{keywordtype}{real} :: scalefac  \textcolor{comment}{! An overall scaling factor for the areas and variable.}
63   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je
64   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
65 
66   scalefac = g%US%L\_to\_m**2 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) scalefac = g%US%L\_to\_m**2*scale
67 
68   tmpforsumming(:,:) = 0.
69   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(area)) \textcolor{keywordflow}{then}
70     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
71       tmpforsumming(i,j) = var(i,j) * (scalefac * area(i,j))
72 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
73   \textcolor{keywordflow}{else}
74     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
75       tmpforsumming(i,j) = var(i,j) * (scalefac * g%areaT(i,j) * g%mask2dT(i,j))
76 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
77 \textcolor{keywordflow}{  endif}
78   global\_area\_integral = \hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}(tmpforsumming)
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}}
\subsubsection{\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{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em var} & The variable to average\\
\hline
\mbox{\tt 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}
29   \textcolor{keywordtype}{type}(ocean\_grid\_type),             \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{    !< The ocean's grid structure}
30   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}  :: var\textcolor{comment}{  !< The variable to average}
31   \textcolor{keywordtype}{real},                    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: scale\textcolor{comment}{ !< A rescaling factor for the variable}
32 
33   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))}              :: tmpforsumming
34   \textcolor{keywordtype}{real} :: global\_area\_mean
35 
36   \textcolor{keywordtype}{real} :: scalefac  \textcolor{comment}{! An overall scaling factor for the areas and variable.}
37   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je
38   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
39 
40   scalefac = g%US%L\_to\_m**2 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) scalefac = g%US%L\_to\_m**2*scale
41 
42   tmpforsumming(:,:) = 0.
43   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
44     tmpforsumming(i,j) = var(i,j) * (scalefac * g%areaT(i,j) * g%mask2dT(i,j))
45 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
46   global\_area\_mean = \hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}(tmpforsumming) * g%IareaT\_global
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}}
\subsubsection{\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{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em array} & The variable being averaged\\
\hline
\mbox{\tt out}  & {\em i\+\_\+mean} & Global mean of array along its i-\/axis\\
\hline
\mbox{\tt in}  & {\em mask} & An array used for weighting the i-\/mean\\
\hline
\mbox{\tt in}  & {\em scale} & A rescaling factor for the output variable\\
\hline
\mbox{\tt 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}
197   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< The ocean's grid structure}
198   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: array\textcolor{comment}{  !< The variable being averaged}
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}
200   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
201                           \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: mask\textcolor{comment}{  !< An array used for weighting the i-mean}
202   \textcolor{keywordtype}{real},                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: scale\textcolor{comment}{ !< A rescaling factor for the output variable}
203   \textcolor{keywordtype}{real},                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: tmp\_scale\textcolor{comment}{ !< A rescaling factor for the internal}
204 \textcolor{comment}{                                                           !! calculations that is removed from the output}
205 
206   \textcolor{comment}{! Local variables}
207   \textcolor{keywordtype}{type}(\hyperlink{structmom__coms_1_1efp__type}{efp\_type}), \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)} :: asum, mask\_sum
208   \textcolor{keywordtype}{real} :: scalefac  \textcolor{comment}{! A scaling factor for the variable.}
209   \textcolor{keywordtype}{real} :: unscale   \textcolor{comment}{! A factor for undoing any internal rescaling before output.}
210   \textcolor{keywordtype}{real} :: mask\_sum\_r
211   \textcolor{keywordtype}{integer} :: is, ie, js, je, idg\_off, jdg\_off
212   \textcolor{keywordtype}{integer} :: i, j
213 
214   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
215   idg\_off = g%idg\_offset ; jdg\_off = g%jdg\_offset
216 
217   scalefac = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) scalefac = scale
218   unscale = 1.0
219   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(tmp\_scale)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (tmp\_scale /= 0.0) \textcolor{keywordflow}{then}
220     scalefac = scalefac * tmp\_scale ; unscale = 1.0 / tmp\_scale
221 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
222   \textcolor{keyword}{call }reset\_efp\_overflow\_error()
223 
224   \textcolor{keyword}{allocate}(asum(g%jsg:g%jeg))
225   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(mask)) \textcolor{keywordflow}{then}
226     \textcolor{keyword}{allocate}(mask\_sum(g%jsg:g%jeg))
227 
228     \textcolor{keywordflow}{do} j=g%jsg,g%jeg
229       asum(j) = real\_to\_efp(0.0) ; mask\_sum(j) = real\_to\_efp(0.0)
230 \textcolor{keywordflow}{    enddo}
231 
232     \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{do} j=js,je
233       asum(j+jdg\_off) = asum(j+jdg\_off) + real\_to\_efp(scalefac*array(i,j)*mask(i,j))
234       mask\_sum(j+jdg\_off) = mask\_sum(j+jdg\_off) + real\_to\_efp(mask(i,j))
235 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
236 
237     \textcolor{keywordflow}{if} (query\_efp\_overflow\_error()) \textcolor{keyword}{call }mom\_error(fatal, &
238       \textcolor{stringliteral}{"global\_i\_mean overflow error occurred before sums across PEs."})
239 
240     \textcolor{keyword}{call }\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}(asum(g%jsg:g%jeg), g%jeg-g%jsg+1)
241     \textcolor{keyword}{call }\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}(mask\_sum(g%jsg:g%jeg), g%jeg-g%jsg+1)
242 
243     \textcolor{keywordflow}{if} (query\_efp\_overflow\_error()) \textcolor{keyword}{call }mom\_error(fatal, &
244       \textcolor{stringliteral}{"global\_i\_mean overflow error occurred during sums across PEs."})
245 
246     \textcolor{keywordflow}{do} j=js,je
247       mask\_sum\_r = efp\_to\_real(mask\_sum(j+jdg\_off))
248       \textcolor{keywordflow}{if} (mask\_sum\_r == 0.0 ) \textcolor{keywordflow}{then} ; i\_mean(j) = 0.0 ; \textcolor{keywordflow}{else}
249         i\_mean(j) = efp\_to\_real(asum(j+jdg\_off)) / mask\_sum\_r
250 \textcolor{keywordflow}{      endif}
251 \textcolor{keywordflow}{    enddo}
252 
253     \textcolor{keyword}{deallocate}(mask\_sum)
254   \textcolor{keywordflow}{else}
255     \textcolor{keywordflow}{do} j=g%jsg,g%jeg ; asum(j) = real\_to\_efp(0.0) ;\textcolor{keywordflow}{ enddo}
256 
257     \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{do} j=js,je
258       asum(j+jdg\_off) = asum(j+jdg\_off) + real\_to\_efp(scalefac*array(i,j))
259 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
260 
261     \textcolor{keywordflow}{if} (query\_efp\_overflow\_error()) \textcolor{keyword}{call }mom\_error(fatal, &
262       \textcolor{stringliteral}{"global\_i\_mean overflow error occurred before sum across PEs."})
263 
264     \textcolor{keyword}{call }\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}(asum(g%jsg:g%jeg), g%jeg-g%jsg+1)
265 
266     \textcolor{keywordflow}{if} (query\_efp\_overflow\_error()) \textcolor{keyword}{call }mom\_error(fatal, &
267       \textcolor{stringliteral}{"global\_i\_mean overflow error occurred during sum across PEs."})
268 
269     \textcolor{keywordflow}{do} j=js,je
270       i\_mean(j) = efp\_to\_real(asum(j+jdg\_off)) / \textcolor{keywordtype}{real}(g%ieg-g%isg+1)
271 \textcolor{keywordflow}{    enddo}
272 \textcolor{keywordflow}{  endif}
273 
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}
275 
276   \textcolor{keyword}{deallocate}(asum)
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}}
\subsubsection{\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{\tt in,out}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em array} & The variable being averaged\\
\hline
\mbox{\tt out}  & {\em j\+\_\+mean} & Global mean of array along its j-\/axis\\
\hline
\mbox{\tt in}  & {\em mask} & An array used for weighting the j-\/mean\\
\hline
\mbox{\tt in}  & {\em scale} & A rescaling factor for the output variable\\
\hline
\mbox{\tt 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}
283   \textcolor{keywordtype}{type}(ocean\_grid\_type),            \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{    !< The ocean's grid structure}
284   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(in)}    :: array\textcolor{comment}{  !< The variable being averaged}
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}
286   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, &
287                           \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: mask\textcolor{comment}{  !< An array used for weighting the j-mean}
288   \textcolor{keywordtype}{real},                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: scale\textcolor{comment}{ !< A rescaling factor for the output variable}
289   \textcolor{keywordtype}{real},                   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: tmp\_scale\textcolor{comment}{ !< A rescaling factor for the internal}
290 \textcolor{comment}{                                                           !! calculations that is removed from the output}
291 
292   \textcolor{comment}{! Local variables}
293   \textcolor{keywordtype}{type}(\hyperlink{structmom__coms_1_1efp__type}{efp\_type}), \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)} :: asum, mask\_sum
294   \textcolor{keywordtype}{real} :: mask\_sum\_r
295   \textcolor{keywordtype}{real} :: scalefac  \textcolor{comment}{! A scaling factor for the variable.}
296   \textcolor{keywordtype}{real} :: unscale   \textcolor{comment}{! A factor for undoing any internal rescaling before output.}
297   \textcolor{keywordtype}{integer} :: is, ie, js, je, idg\_off, jdg\_off
298   \textcolor{keywordtype}{integer} :: i, j
299 
300   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
301   idg\_off = g%idg\_offset ; jdg\_off = g%jdg\_offset
302 
303   scalefac = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) scalefac = scale
304   unscale = 1.0
305   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(tmp\_scale)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (tmp\_scale /= 0.0) \textcolor{keywordflow}{then}
306     scalefac = scalefac * tmp\_scale ; unscale = 1.0 / tmp\_scale
307 \textcolor{keywordflow}{  endif} ;\textcolor{keywordflow}{ endif}
308   \textcolor{keyword}{call }reset\_efp\_overflow\_error()
309 
310   \textcolor{keyword}{allocate}(asum(g%isg:g%ieg))
311   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(mask)) \textcolor{keywordflow}{then}
312     \textcolor{keyword}{allocate} (mask\_sum(g%isg:g%ieg))
313 
314     \textcolor{keywordflow}{do} i=g%isg,g%ieg
315       asum(i) = real\_to\_efp(0.0) ; mask\_sum(i) = real\_to\_efp(0.0)
316 \textcolor{keywordflow}{    enddo}
317 
318     \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{do} j=js,je
319       asum(i+idg\_off) = asum(i+idg\_off) + real\_to\_efp(scalefac*array(i,j)*mask(i,j))
320       mask\_sum(i+idg\_off) = mask\_sum(i+idg\_off) + real\_to\_efp(mask(i,j))
321 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
322 
323     \textcolor{keywordflow}{if} (query\_efp\_overflow\_error()) \textcolor{keyword}{call }mom\_error(fatal, &
324       \textcolor{stringliteral}{"global\_j\_mean overflow error occurred before sums across PEs."})
325 
326     \textcolor{keyword}{call }\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}(asum(g%isg:g%ieg), g%ieg-g%isg+1)
327     \textcolor{keyword}{call }\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}(mask\_sum(g%isg:g%ieg), g%ieg-g%isg+1)
328 
329     \textcolor{keywordflow}{if} (query\_efp\_overflow\_error()) \textcolor{keyword}{call }mom\_error(fatal, &
330       \textcolor{stringliteral}{"global\_j\_mean overflow error occurred during sums across PEs."})
331 
332     \textcolor{keywordflow}{do} i=is,ie
333       mask\_sum\_r = efp\_to\_real(mask\_sum(i+idg\_off))
334       \textcolor{keywordflow}{if} (mask\_sum\_r == 0.0 ) \textcolor{keywordflow}{then} ; j\_mean(i) = 0.0 ; \textcolor{keywordflow}{else}
335         j\_mean(i) = efp\_to\_real(asum(i+idg\_off)) / mask\_sum\_r
336 \textcolor{keywordflow}{      endif}
337 \textcolor{keywordflow}{    enddo}
338 
339     \textcolor{keyword}{deallocate}(mask\_sum)
340   \textcolor{keywordflow}{else}
341     \textcolor{keywordflow}{do} i=g%isg,g%ieg ; asum(i) = real\_to\_efp(0.0) ;\textcolor{keywordflow}{ enddo}
342 
343     \textcolor{keywordflow}{do} i=is,ie ; \textcolor{keywordflow}{do} j=js,je
344       asum(i+idg\_off) = asum(i+idg\_off) + real\_to\_efp(scalefac*array(i,j))
345 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
346 
347     \textcolor{keywordflow}{if} (query\_efp\_overflow\_error()) \textcolor{keyword}{call }mom\_error(fatal, &
348       \textcolor{stringliteral}{"global\_j\_mean overflow error occurred before sum across PEs."})
349 
350     \textcolor{keyword}{call }\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}(asum(g%isg:g%ieg), g%ieg-g%isg+1)
351 
352     \textcolor{keywordflow}{if} (query\_efp\_overflow\_error()) \textcolor{keyword}{call }mom\_error(fatal, &
353       \textcolor{stringliteral}{"global\_j\_mean overflow error occurred during sum across PEs."})
354 
355     \textcolor{keywordflow}{do} i=is,ie
356       j\_mean(i) = efp\_to\_real(asum(i+idg\_off)) / \textcolor{keywordtype}{real}(g%jeg-g%jsg+1)
357 \textcolor{keywordflow}{    enddo}
358 \textcolor{keywordflow}{  endif}
359 
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}
361 
362   \textcolor{keyword}{deallocate}(asum)
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}}
\subsubsection{\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{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em var} & The variable to average\\
\hline
\mbox{\tt in}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt 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}
84   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{    !< The ocean's grid structure}
85   \textcolor{keywordtype}{type}(verticalgrid\_type),                   \textcolor{keywordtype}{intent(in)}  :: gv\textcolor{comment}{   !< The ocean's vertical grid structure}
86   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, \textcolor{keywordtype}{intent(in)}  :: var\textcolor{comment}{  !< The variable to average}
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]}
88   \textcolor{keywordtype}{real},                            \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: scale\textcolor{comment}{ !< A rescaling factor for the variable}
89   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(GV))}                   :: global\_layer\_mean
90 
91   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isc:G%iec, G%jsc:G%jec, SZK\_(GV))} :: tmpforsumming, weight
92   \textcolor{keywordtype}{type}(\hyperlink{structmom__coms_1_1efp__type}{efp\_type}), \textcolor{keywordtype}{dimension(2*SZK\_(GV))} :: laysums
93   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZK\_(GV))} :: global\_temp\_scalar, global\_weight\_scalar
94   \textcolor{keywordtype}{real} :: scalefac  \textcolor{comment}{! A scaling factor for the variable.}
95   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz
96   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = gv%ke
97 
98   scalefac = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) scalefac = scale
99   tmpforsumming(:,:,:) = 0. ; weight(:,:,:) = 0.
100 
101   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
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))
103     tmpforsumming(i,j,k) =  scalefac * var(i,j,k) * weight(i,j,k)
104 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
105 
106   global\_temp\_scalar = \hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}(tmpforsumming, efp\_lay\_sums=laysums(1:nz), only\_on\_pe
      =.true.)
107   global\_weight\_scalar = \hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}(weight, efp\_lay\_sums=laysums(nz+1:2*nz), only\_on\_pe
      =.true.)
108   \textcolor{keyword}{call }\hyperlink{interfacemom__coms_1_1efp__sum__across__pes}{efp\_sum\_across\_pes}(laysums, 2*nz)
109 
110   \textcolor{keywordflow}{do} k=1,nz
111     global\_layer\_mean(k) = efp\_to\_real(laysums(k)) / efp\_to\_real(laysums(nz+k))
112 \textcolor{keywordflow}{  enddo}
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}}
\subsubsection{\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{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em var} & The variable being integrated\\
\hline
\mbox{\tt 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{\tt 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}
149   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{    !< The ocean's grid structure}
150   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}  :: gv\textcolor{comment}{   !< The ocean's vertical grid structure}
151   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, &
152                            \textcolor{keywordtype}{intent(in)}  :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-2]}
153   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, &
154                  \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: var\textcolor{comment}{  !< The variable being integrated}
155   \textcolor{keywordtype}{logical},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: on\_pe\_only\textcolor{comment}{  !< If present and true, the sum is only}
156 \textcolor{comment}{                                !! done on the local PE, and it is \_not\_ order invariant.}
157   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: scale\textcolor{comment}{ !< A rescaling factor for the variable}
158   \textcolor{keywordtype}{real} :: global\_mass\_integral\textcolor{comment}{  !< The mass-weighted integral of var (or 1) in}
159 \textcolor{comment}{                                !! kg times the units of var}
160 
161   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))} :: tmpforsumming
162   \textcolor{keywordtype}{real} :: scalefac  \textcolor{comment}{! An overall scaling factor for the areas and variable.}
163   \textcolor{keywordtype}{logical} :: global\_sum
164   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz
165   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = gv%ke
166 
167   scalefac = g%US%L\_to\_m**2 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) scalefac = g%US%L\_to\_m**2*scale
168   tmpforsumming(:,:) = 0.0
169 
170   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(var)) \textcolor{keywordflow}{then}
171     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
172       tmpforsumming(i,j) = tmpforsumming(i,j) + var(i,j,k) * &
173                 ((gv%H\_to\_kg\_m2 * h(i,j,k)) * (scalefac*g%areaT(i,j) * g%mask2dT(i,j)))
174 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
175   \textcolor{keywordflow}{else}
176     \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
177       tmpforsumming(i,j) = tmpforsumming(i,j) + &
178                 ((gv%H\_to\_kg\_m2 * h(i,j,k)) * (scalefac*g%areaT(i,j) * g%mask2dT(i,j)))
179 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
180 \textcolor{keywordflow}{  endif}
181   global\_sum = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(on\_pe\_only)) global\_sum = .not.on\_pe\_only
182   \textcolor{keywordflow}{if} (global\_sum) \textcolor{keywordflow}{then}
183     global\_mass\_integral = \hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}(tmpforsumming)
184   \textcolor{keywordflow}{else}
185     global\_mass\_integral = 0.0
186     \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
187       global\_mass\_integral = global\_mass\_integral + tmpforsumming(i,j)
188 \textcolor{keywordflow}{    enddo} ;\textcolor{keywordflow}{ enddo}
189 \textcolor{keywordflow}{  endif}
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}}
\subsubsection{\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{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em var} & The variable being averaged\\
\hline
\mbox{\tt in}  & {\em h} & Layer thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt 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}
118   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{    !< The ocean's grid structure}
119   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}  :: gv\textcolor{comment}{   !< The ocean's vertical grid structure}
120   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, &
121                            \textcolor{keywordtype}{intent(in)}  :: var\textcolor{comment}{  !< The variable being averaged}
122   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(GV))}, &
123                            \textcolor{keywordtype}{intent(in)}  :: h\textcolor{comment}{    !< Layer thicknesses [H ~> m or kg m-2]}
124   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: scale\textcolor{comment}{ !< A rescaling factor for the variable}
125   \textcolor{keywordtype}{real} :: global\_volume\_mean\textcolor{comment}{  !< The thickness-weighted average of var}
126 
127   \textcolor{keywordtype}{real} :: scalefac  \textcolor{comment}{! A scaling factor for the variable.}
128   \textcolor{keywordtype}{real} :: weight\_here
129   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G), SZJ\_(G))} :: tmpforsumming, sum\_weight
130   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz
131   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = gv%ke
132 
133   scalefac = 1.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(scale)) scalefac = scale
134   tmpforsumming(:,:) = 0. ; sum\_weight(:,:) = 0.
135 
136   \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
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))
138     tmpforsumming(i,j) = tmpforsumming(i,j) + scalefac * var(i,j,k) * weight\_here
139     sum\_weight(i,j) = sum\_weight(i,j) + weight\_here
140 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
141   global\_volume\_mean = (\hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}(tmpforsumming)) / &
142                        (\hyperlink{interfacemom__coms_1_1reproducing__sum}{reproducing\_sum}(sum\_weight))
143 
\end{DoxyCode}
