\hypertarget{interfacemom__diag__mediator_1_1downsample__field}{}\section{mom\+\_\+diag\+\_\+mediator\+:\+:downsample\+\_\+field Interface Reference}
\label{interfacemom__diag__mediator_1_1downsample__field}\index{mom\+\_\+diag\+\_\+mediator\+::downsample\+\_\+field@{mom\+\_\+diag\+\_\+mediator\+::downsample\+\_\+field}}


\subsection{Detailed Description}
Down sample a field. 

Definition at line 75 of file M\+O\+M\+\_\+diag\+\_\+mediator.\+F90.

\subsection*{Private functions}
\begin{DoxyCompactItemize}
\item 
subroutine \mbox{\hyperlink{interfacemom__diag__mediator_1_1downsample__field_a4132786a946807df4a4a5912d353942e}{downsample\+\_\+field\+\_\+2d}} (field\+\_\+in, field\+\_\+out, dl, method, mask, diag\+\_\+cs, diag, isv\+\_\+o, jsv\+\_\+o, isv\+\_\+d, iev\+\_\+d, jsv\+\_\+d, jev\+\_\+d)
\begin{DoxyCompactList}\small\item\em This subroutine allocates and computes a down sampled 2d array given an input array The down sample method is based on the \char`\"{}cell\+\_\+methods\char`\"{} for the diagnostics as explained in the above table. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{interfacemom__diag__mediator_1_1downsample__field_ad2a7ea1af24e10714f1324470d0886fe}{downsample\+\_\+field\+\_\+3d}} (field\+\_\+in, field\+\_\+out, dl, method, mask, diag\+\_\+cs, diag, isv\+\_\+o, jsv\+\_\+o, isv\+\_\+d, iev\+\_\+d, jsv\+\_\+d, jev\+\_\+d)
\begin{DoxyCompactList}\small\item\em This subroutine allocates and computes a down sampled 3d array given an input array The down sample method is based on the \char`\"{}cell\+\_\+methods\char`\"{} for the diagnostics as explained in the above table. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Down sample a field. 

Definition at line 75 of file M\+O\+M\+\_\+diag\+\_\+mediator.\+F90.



\subsection{Functions and subroutines}
\mbox{\Hypertarget{interfacemom__diag__mediator_1_1downsample__field_a4132786a946807df4a4a5912d353942e}\label{interfacemom__diag__mediator_1_1downsample__field_a4132786a946807df4a4a5912d353942e}} 
\index{mom\+\_\+diag\+\_\+mediator\+::downsample\+\_\+field@{mom\+\_\+diag\+\_\+mediator\+::downsample\+\_\+field}!downsample\+\_\+field\+\_\+2d@{downsample\+\_\+field\+\_\+2d}}
\index{downsample\+\_\+field\+\_\+2d@{downsample\+\_\+field\+\_\+2d}!mom\+\_\+diag\+\_\+mediator\+::downsample\+\_\+field@{mom\+\_\+diag\+\_\+mediator\+::downsample\+\_\+field}}
\subsubsection{\texorpdfstring{downsample\+\_\+field\+\_\+2d()}{downsample\_field\_2d()}}
{\footnotesize\ttfamily subroutine mom\+\_\+diag\+\_\+mediator\+::downsample\+\_\+field\+::downsample\+\_\+field\+\_\+2d (\begin{DoxyParamCaption}\item[{real, dimension(\+:,\+:), pointer}]{field\+\_\+in,  }\item[{real, dimension(\+:,\+:), allocatable}]{field\+\_\+out,  }\item[{integer, intent(in)}]{dl,  }\item[{integer, intent(in)}]{method,  }\item[{real, dimension(\+:,\+:), pointer}]{mask,  }\item[{type(\mbox{\hyperlink{structmom__diag__mediator_1_1diag__ctrl}{diag\+\_\+ctrl}}), intent(in)}]{diag\+\_\+cs,  }\item[{type(\mbox{\hyperlink{structmom__diag__mediator_1_1diag__type}{diag\+\_\+type}}), intent(in)}]{diag,  }\item[{integer, intent(in)}]{isv\+\_\+o,  }\item[{integer, intent(in)}]{jsv\+\_\+o,  }\item[{integer, intent(in)}]{isv\+\_\+d,  }\item[{integer, intent(in)}]{iev\+\_\+d,  }\item[{integer, intent(in)}]{jsv\+\_\+d,  }\item[{integer, intent(in)}]{jev\+\_\+d }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine allocates and computes a down sampled 2d array given an input array The down sample method is based on the \char`\"{}cell\+\_\+methods\char`\"{} for the diagnostics as explained in the above table. 


\begin{DoxyParams}[1]{Parameters}
 & {\em field\+\_\+in} & Original field to be down sampled\\
\hline
 & {\em field\+\_\+out} & Down sampled field\\
\hline
\mbox{\tt in}  & {\em dl} & Level of down sampling\\
\hline
\mbox{\tt in}  & {\em method} & Sampling method\\
\hline
 & {\em mask} & Mask for field\\
\hline
\mbox{\tt in}  & {\em diag\+\_\+cs} & Structure used to regulate diagnostic output\\
\hline
\mbox{\tt in}  & {\em diag} & A structure describing the diagnostic to post\\
\hline
\mbox{\tt in}  & {\em isv\+\_\+o} & Original i-\/start index\\
\hline
\mbox{\tt in}  & {\em jsv\+\_\+o} & Original j-\/start index\\
\hline
\mbox{\tt in}  & {\em isv\+\_\+d} & i-\/start index of down sampled data\\
\hline
\mbox{\tt in}  & {\em iev\+\_\+d} & i-\/end index of down sampled data\\
\hline
\mbox{\tt in}  & {\em jsv\+\_\+d} & j-\/start index of down sampled data\\
\hline
\mbox{\tt in}  & {\em jev\+\_\+d} & j-\/end index of down sampled data \\
\hline
\end{DoxyParams}


Definition at line 4107 of file M\+O\+M\+\_\+diag\+\_\+mediator.\+F90.


\begin{DoxyCode}
4107   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer} :: field\_in\textcolor{comment}{      !< Original field to be down sampled}
4108   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{allocatable} :: field\_out\textcolor{comment}{ !< Down sampled field}
4109   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: dl\textcolor{comment}{                !< Level of down sampling}
4110   \textcolor{keywordtype}{integer},  \textcolor{keywordtype}{intent(in)} :: method\textcolor{comment}{           !< Sampling method}
4111   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer} :: mask\textcolor{comment}{    !< Mask for field}
4112   \textcolor{keywordtype}{type}(diag\_ctrl),   \textcolor{keywordtype}{intent(in)} :: diag\_CS\textcolor{comment}{ !< Structure used to regulate diagnostic output}
4113   \textcolor{keywordtype}{type}(diag\_type),   \textcolor{keywordtype}{intent(in)} :: diag\textcolor{comment}{    !< A structure describing the diagnostic to post}
4114   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: isv\_o\textcolor{comment}{             !< Original i-start index}
4115   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: jsv\_o\textcolor{comment}{             !< Original j-start index}
4116   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: isv\_d\textcolor{comment}{             !< i-start index of down sampled data}
4117   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: iev\_d\textcolor{comment}{             !< i-end index of down sampled data}
4118   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: jsv\_d\textcolor{comment}{             !< j-start index of down sampled data}
4119   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: jev\_d\textcolor{comment}{             !< j-end index of down sampled data}
4120   \textcolor{comment}{! Locals}
4121   \textcolor{keywordtype}{character(len=240)} :: mesg
4122   \textcolor{keywordtype}{integer} :: i,j,ii,jj,i0,j0,f1,f2,f\_in1,f\_in2
4123   \textcolor{keywordtype}{real} :: ave, total\_weight, weight
4124   \textcolor{keywordtype}{real} :: epsilon = 1.0e-20  \textcolor{comment}{! A negligibly small count of weights [nondim]}
4125   \textcolor{keywordtype}{real} :: eps\_area  \textcolor{comment}{! A negligibly small area [L2 ~> m2]}
4126   \textcolor{keywordtype}{real} :: eps\_len   \textcolor{comment}{! A negligibly small horizontal length [L ~> m]}
4127 
4128   eps\_len = 1.0e-20 * diag\_cs%G%US%m\_to\_L
4129   eps\_area = 1.0e-20 * diag\_cs%G%US%m\_to\_L**2
4130 
4131   \textcolor{comment}{! Allocate the down sampled field on the down sampled data domain}
4132 \textcolor{comment}{! 
       allocate(field\_out(diag\_cs%dsamp(dl)%isd:diag\_cs%dsamp(dl)%ied,diag\_cs%dsamp(dl)%jsd:diag\_cs%dsamp(dl)%jed))}
4133 \textcolor{comment}{!  allocate(field\_out(1:size(field\_in,1)/dl,1:size(field\_in,2)/dl))}
4134   \textcolor{comment}{! Fill the down sampled field on the down sampled diagnostics (almost always compuate) domain}
4135   f\_in1 = \textcolor{keyword}{size}(field\_in,1)
4136   f\_in2 = \textcolor{keyword}{size}(field\_in,2)
4137   f1 = f\_in1/dl
4138   f2 = f\_in2/dl
4139   \textcolor{comment}{! Correction for the symmetric case}
4140   \textcolor{keywordflow}{if} (diag\_cs%G%symmetric) \textcolor{keywordflow}{then}
4141      f1 = f1 + mod(f\_in1,dl)
4142      f2 = f2 + mod(f\_in2,dl)
4143 \textcolor{keywordflow}{  endif}
4144   \textcolor{keyword}{allocate}(field\_out(1:f1,1:f2))
4145 
4146   \textcolor{keywordflow}{if} (method == mmp) \textcolor{keywordflow}{then}
4147      \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d
4148         i0 = isv\_o+dl*(i-isv\_d)
4149         j0 = jsv\_o+dl*(j-jsv\_d)
4150         ave = 0.0
4151         total\_weight = 0.0
4152         \textcolor{keywordflow}{do} jj=j0,j0+dl-1 ; \textcolor{keywordflow}{do} ii=i0,i0+dl-1
4153 \textcolor{comment}{!        do ii=i0,i0+dl-1 ; do jj=j0,j0+dl-1}
4154            weight = mask(ii,jj)*diag\_cs%G%areaT(ii,jj)
4155            total\_weight = total\_weight + weight
4156            ave = ave+field\_in(ii,jj)*weight
4157 \textcolor{keyword}{        end}do; enddo
4158         field\_out(i,j)  = ave/(total\_weight + eps\_area)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where
       ave=0.0}
4159 \textcolor{keyword}{     end}do; enddo
4160   \textcolor{keywordflow}{elseif}(method == ssp) \textcolor{keywordflow}{then}    \textcolor{comment}{! e.g., T\_dfxy\_cont\_tendency\_2d}
4161      \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d
4162         i0 = isv\_o+dl*(i-isv\_d)
4163         j0 = jsv\_o+dl*(j-jsv\_d)
4164         ave = 0.0
4165         total\_weight = 0.0
4166         \textcolor{keywordflow}{do} jj=j0,j0+dl-1 ; \textcolor{keywordflow}{do} ii=i0,i0+dl-1
4167 \textcolor{comment}{!        do ii=i0,i0+dl-1 ; do jj=j0,j0+dl-1}
4168            weight = mask(ii,jj)
4169            total\_weight = total\_weight + weight
4170            ave=ave+field\_in(ii,jj)*weight
4171 \textcolor{keyword}{        end}do; enddo
4172         field\_out(i,j)  = ave/(total\_weight+epsilon)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where
       ave=0.0}
4173 \textcolor{keyword}{     end}do; enddo
4174   \textcolor{keywordflow}{elseif}(method == psp) \textcolor{keywordflow}{then}    \textcolor{comment}{! e.g., umo\_2d}
4175      \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d
4176         i0 = isv\_o+dl*(i-isv\_d)
4177         j0 = jsv\_o+dl*(j-jsv\_d)
4178         ave = 0.0
4179         total\_weight = 0.0
4180         ii=i0
4181         \textcolor{keywordflow}{do} jj=j0,j0+dl-1
4182            weight = mask(ii,jj)
4183            total\_weight = total\_weight +weight
4184            ave=ave+field\_in(ii,jj)*weight
4185 \textcolor{keywordflow}{        enddo}
4186         field\_out(i,j)  = ave/(total\_weight+epsilon)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where
       ave=0.0}
4187 \textcolor{keyword}{     end}do; enddo
4188   \textcolor{keywordflow}{elseif}(method == spp) \textcolor{keywordflow}{then}    \textcolor{comment}{! e.g., vmo\_2d}
4189      \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d
4190         i0 = isv\_o+dl*(i-isv\_d)
4191         j0 = jsv\_o+dl*(j-jsv\_d)
4192         ave = 0.0
4193         total\_weight = 0.0
4194         jj=j0
4195         \textcolor{keywordflow}{do} ii=i0,i0+dl-1
4196            weight = mask(ii,jj)
4197            total\_weight = total\_weight +weight
4198            ave=ave+field\_in(ii,jj)*weight
4199 \textcolor{keywordflow}{        enddo}
4200         field\_out(i,j)  = ave/(total\_weight+epsilon)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where
       ave=0.0}
4201 \textcolor{keyword}{     end}do; enddo
4202   \textcolor{keywordflow}{elseif}(method == pmp) \textcolor{keywordflow}{then}
4203      \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d
4204         i0 = isv\_o+dl*(i-isv\_d)
4205         j0 = jsv\_o+dl*(j-jsv\_d)
4206         ave = 0.0
4207         total\_weight = 0.0
4208         ii=i0
4209         \textcolor{keywordflow}{do} jj=j0,j0+dl-1
4210            weight = mask(ii,jj) * diag\_cs%G%dyCu(ii,jj)\textcolor{comment}{!*diag\_cs%h(ii,jj,1) !Niki?}
4211            total\_weight = total\_weight +weight
4212            ave=ave+field\_in(ii,jj)*weight
4213 \textcolor{keywordflow}{        enddo}
4214         field\_out(i,j)  = ave/(total\_weight+eps\_len)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where
       ave=0.0}
4215 \textcolor{keyword}{     end}do; enddo
4216   \textcolor{keywordflow}{elseif}(method == mpp) \textcolor{keywordflow}{then}
4217      \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d
4218         i0 = isv\_o+dl*(i-isv\_d)
4219         j0 = jsv\_o+dl*(j-jsv\_d)
4220         ave = 0.0
4221         total\_weight = 0.0
4222         jj=j0
4223         \textcolor{keywordflow}{do} ii=i0,i0+dl-1
4224            weight = mask(ii,jj)* diag\_cs%G%dxCv(ii,jj)\textcolor{comment}{!*diag\_cs%h(ii,jj,1) !Niki?}
4225            total\_weight = total\_weight +weight
4226            ave=ave+field\_in(ii,jj)*weight
4227 \textcolor{keywordflow}{        enddo}
4228         field\_out(i,j)  = ave/(total\_weight+eps\_len)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where
       ave=0.0}
4229 \textcolor{keyword}{     end}do; enddo
4230   \textcolor{keywordflow}{elseif}(method == msk) \textcolor{keywordflow}{then} \textcolor{comment}{!The input field is a mask, subsample}
4231      field\_out(:,:) = 0.0
4232      \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d
4233         i0 = isv\_o+dl*(i-isv\_d)
4234         j0 = jsv\_o+dl*(j-jsv\_d)
4235         ave = 0.0
4236         \textcolor{keywordflow}{do} jj=j0,j0+dl-1 ; \textcolor{keywordflow}{do} ii=i0,i0+dl-1
4237            ave=ave+field\_in(ii,jj)
4238 \textcolor{keyword}{        end}do; enddo
4239         \textcolor{keywordflow}{if}(ave > 0.0) field\_out(i,j)=1.0
4240 \textcolor{keyword}{     end}do; enddo
4241   \textcolor{keywordflow}{else}
4242      \textcolor{keyword}{write} (mesg,*) \textcolor{stringliteral}{" unknown sampling method: "},method
4243      \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"downsample\_field\_2d: "}//trim(mesg)//\textcolor{stringliteral}{" "}//trim(diag%debug\_str))
4244 \textcolor{keywordflow}{  endif}
4245 
\end{DoxyCode}
\mbox{\Hypertarget{interfacemom__diag__mediator_1_1downsample__field_ad2a7ea1af24e10714f1324470d0886fe}\label{interfacemom__diag__mediator_1_1downsample__field_ad2a7ea1af24e10714f1324470d0886fe}} 
\index{mom\+\_\+diag\+\_\+mediator\+::downsample\+\_\+field@{mom\+\_\+diag\+\_\+mediator\+::downsample\+\_\+field}!downsample\+\_\+field\+\_\+3d@{downsample\+\_\+field\+\_\+3d}}
\index{downsample\+\_\+field\+\_\+3d@{downsample\+\_\+field\+\_\+3d}!mom\+\_\+diag\+\_\+mediator\+::downsample\+\_\+field@{mom\+\_\+diag\+\_\+mediator\+::downsample\+\_\+field}}
\subsubsection{\texorpdfstring{downsample\+\_\+field\+\_\+3d()}{downsample\_field\_3d()}}
{\footnotesize\ttfamily subroutine mom\+\_\+diag\+\_\+mediator\+::downsample\+\_\+field\+::downsample\+\_\+field\+\_\+3d (\begin{DoxyParamCaption}\item[{real, dimension(\+:,\+:,\+:), pointer}]{field\+\_\+in,  }\item[{real, dimension(\+:,\+:,\+:), allocatable}]{field\+\_\+out,  }\item[{integer, intent(in)}]{dl,  }\item[{integer, intent(in)}]{method,  }\item[{real, dimension(\+:,\+:,\+:), pointer}]{mask,  }\item[{type(\mbox{\hyperlink{structmom__diag__mediator_1_1diag__ctrl}{diag\+\_\+ctrl}}), intent(in)}]{diag\+\_\+cs,  }\item[{type(\mbox{\hyperlink{structmom__diag__mediator_1_1diag__type}{diag\+\_\+type}}), intent(in)}]{diag,  }\item[{integer, intent(in)}]{isv\+\_\+o,  }\item[{integer, intent(in)}]{jsv\+\_\+o,  }\item[{integer, intent(in)}]{isv\+\_\+d,  }\item[{integer, intent(in)}]{iev\+\_\+d,  }\item[{integer, intent(in)}]{jsv\+\_\+d,  }\item[{integer, intent(in)}]{jev\+\_\+d }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine allocates and computes a down sampled 3d array given an input array The down sample method is based on the \char`\"{}cell\+\_\+methods\char`\"{} for the diagnostics as explained in the above table. 

\hypertarget{namespacemom__diag__mediator_downsampling}{}\subsection{The down sample algorithm}\label{namespacemom__diag__mediator_downsampling}
The down sample method could be deduced (before send\+\_\+data call) from the diagx\+\_\+cell\+\_\+method, diagy\+\_\+cell\+\_\+method and diagv\+\_\+cell\+\_\+method

This is the summary of the down sample algoritm for a diagnostic field f\+: \[ f(Id,Jd) = \sum_{i,j} f(Id+i,Jd+j) * weight(Id+i,Jd+j) / [ \sum_{i,j} weight(Id+i,Jd+j)] \] Here, i and j run from 0 to dl-\/1 (dl being the down sample level). Id,Jd are the down sampled (coarse grid) indices run over the coarsened compute grid, if and jf are the original (fine grid) indices.

\begin{DoxyVerb} Example   x_cell y_cell v_cell algorithm_id    implemented weight(if,jf)
 ---------------------------------------------------------------------------------------
 theta     mean   mean   mean   MMM =222        G%areaT(if,jf)*h(if,jf)
 u         point  mean   mean   PMM =022        dyCu(if,jf)*h(if,jf)*delta(if,Id)
 v         mean   point  mean   MPM =202        dxCv(if,jf)*h(if,jf)*delta(jf,Jd)
 ?         point  sum    mean   PSM =012        h(if,jf)*delta(if,Id)
 volcello  sum    sum    sum    SSS =111        1
 T_dfxy_co sum    sum    point  SSP =110        1
 umo       point  sum    sum    PSS =011        1*delta(if,Id)
 vmo       sum    point  sum    SPS =101        1*delta(jf,Jd)
 umo_2d    point  sum    point  PSP =010        1*delta(if,Id)
 vmo_2d    sum    point  point  SPP =100        1*delta(jf,Jd)
 ?         point  mean   point  PMP =020        dyCu(if,jf)*delta(if,Id)
 ?         mean   point  point  MPP =200        dxCv(if,jf)*delta(jf,Jd)
 w         mean   mean   point  MMP =220        G%areaT(if,jf)
 h*theta   mean   mean   sum    MMS =221        G%areaT(if,jf)

 delta is the Kronecker delta\end{DoxyVerb}



\begin{DoxyParams}[1]{Parameters}
 & {\em field\+\_\+in} & Original field to be down sampled\\
\hline
 & {\em field\+\_\+out} & down sampled field\\
\hline
\mbox{\tt in}  & {\em dl} & Level of down sampling\\
\hline
\mbox{\tt in}  & {\em method} & Sampling method\\
\hline
 & {\em mask} & Mask for field\\
\hline
\mbox{\tt in}  & {\em diag\+\_\+cs} & Structure used to regulate diagnostic output\\
\hline
\mbox{\tt in}  & {\em diag} & A structure describing the diagnostic to post\\
\hline
\mbox{\tt in}  & {\em isv\+\_\+o} & Original i-\/start index\\
\hline
\mbox{\tt in}  & {\em jsv\+\_\+o} & Original j-\/start index\\
\hline
\mbox{\tt in}  & {\em isv\+\_\+d} & i-\/start index of down sampled data\\
\hline
\mbox{\tt in}  & {\em iev\+\_\+d} & i-\/end index of down sampled data\\
\hline
\mbox{\tt in}  & {\em jsv\+\_\+d} & j-\/start index of down sampled data\\
\hline
\mbox{\tt in}  & {\em jev\+\_\+d} & j-\/end index of down sampled data \\
\hline
\end{DoxyParams}


Definition at line 3951 of file M\+O\+M\+\_\+diag\+\_\+mediator.\+F90.


\begin{DoxyCode}
3951   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{pointer} :: field\_in\textcolor{comment}{      !< Original field to be down sampled}
3952   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{allocatable} :: field\_out\textcolor{comment}{ !< down sampled field}
3953   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: dl\textcolor{comment}{                !< Level of down sampling}
3954   \textcolor{keywordtype}{integer},  \textcolor{keywordtype}{intent(in)} :: method\textcolor{comment}{           !< Sampling method}
3955   \textcolor{keywordtype}{real},  \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{pointer} :: mask\textcolor{comment}{ !< Mask for field}
3956   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{intent(in)} :: diag\_CS\textcolor{comment}{   !< Structure used to regulate diagnostic output}
3957   \textcolor{keywordtype}{type}(diag\_type), \textcolor{keywordtype}{intent(in)} :: diag\textcolor{comment}{      !< A structure describing the diagnostic to post}
3958   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: isv\_o\textcolor{comment}{             !< Original i-start index}
3959   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: jsv\_o\textcolor{comment}{             !< Original j-start index}
3960   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: isv\_d\textcolor{comment}{             !< i-start index of down sampled data}
3961   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: iev\_d\textcolor{comment}{             !< i-end index of down sampled data}
3962   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: jsv\_d\textcolor{comment}{             !< j-start index of down sampled data}
3963   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: jev\_d\textcolor{comment}{             !< j-end index of down sampled data}
3964   \textcolor{comment}{! Locals}
3965   \textcolor{keywordtype}{character(len=240)} :: mesg
3966   \textcolor{keywordtype}{integer} :: i,j,ii,jj,i0,j0,f1,f2,f\_in1,f\_in2
3967   \textcolor{keywordtype}{integer} :: k,ks,ke
3968   \textcolor{keywordtype}{real} :: ave,total\_weight,weight
3969   \textcolor{keywordtype}{real} :: eps\_vol   \textcolor{comment}{! A negligibly small volume or mass [H L2 ~> m3 or kg]}
3970   \textcolor{keywordtype}{real} :: eps\_area  \textcolor{comment}{! A negligibly small area [L2 ~> m2]}
3971   \textcolor{keywordtype}{real} :: eps\_face  \textcolor{comment}{! A negligibly small face area [H L ~> m2 or kg m-1]}
3972 
3973   ks = 1 ; ke = \textcolor{keyword}{size}(field\_in,3)
3974   eps\_face = 1.0e-20 * diag\_cs%G%US%m\_to\_L * diag\_cs%GV%m\_to\_H
3975   eps\_area = 1.0e-20 * diag\_cs%G%US%m\_to\_L**2
3976   eps\_vol = 1.0e-20 * diag\_cs%G%US%m\_to\_L**2 * diag\_cs%GV%m\_to\_H
3977 
3978   \textcolor{comment}{! Allocate the down sampled field on the down sampled data domain}
3979 \textcolor{comment}{! 
       allocate(field\_out(diag\_cs%dsamp(dl)%isd:diag\_cs%dsamp(dl)%ied,diag\_cs%dsamp(dl)%jsd:diag\_cs%dsamp(dl)%jed,ks:ke))}
3980 \textcolor{comment}{!  allocate(field\_out(1:size(field\_in,1)/dl,1:size(field\_in,2)/dl,ks:ke))}
3981   f\_in1 = \textcolor{keyword}{size}(field\_in,1)
3982   f\_in2 = \textcolor{keyword}{size}(field\_in,2)
3983   f1 = f\_in1/dl
3984   f2 = f\_in2/dl
3985   \textcolor{comment}{!Correction for the symmetric case}
3986   \textcolor{keywordflow}{if} (diag\_cs%G%symmetric) \textcolor{keywordflow}{then}
3987      f1 = f1 + mod(f\_in1,dl)
3988      f2 = f2 + mod(f\_in2,dl)
3989 \textcolor{keywordflow}{  endif}
3990   \textcolor{keyword}{allocate}(field\_out(1:f1,1:f2,ks:ke))
3991 
3992   \textcolor{comment}{! Fill the down sampled field on the down sampled diagnostics (almost always compuate) domain}
3993   \textcolor{keywordflow}{if} (method == mmm) \textcolor{keywordflow}{then}
3994      \textcolor{keywordflow}{do} k= ks,ke ; \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d
3995         i0 = isv\_o+dl*(i-isv\_d)
3996         j0 = jsv\_o+dl*(j-jsv\_d)
3997         ave = 0.0
3998         total\_weight = 0.0
3999         \textcolor{keywordflow}{do} jj=j0,j0+dl-1 ; \textcolor{keywordflow}{do} ii=i0,i0+dl-1
4000 \textcolor{comment}{!        do ii=i0,i0+dl-1 ; do jj=j0,j0+dl-1 !This seems to be faster!!!!}
4001            weight = mask(ii,jj,k) * diag\_cs%G%areaT(ii,jj) * diag\_cs%h(ii,jj,k)
4002            total\_weight = total\_weight + weight
4003            ave = ave+field\_in(ii,jj,k) * weight
4004 \textcolor{keyword}{        end}do; enddo
4005         field\_out(i,j,k)  = ave/(total\_weight + eps\_vol)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where
       ave=0.0}
4006 \textcolor{keyword}{     end}do; enddo; enddo
4007   \textcolor{keywordflow}{elseif} (method == sss) \textcolor{keywordflow}{then}    \textcolor{comment}{!e.g., volcello}
4008      \textcolor{keywordflow}{do} k= ks,ke ; \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d
4009         i0 = isv\_o+dl*(i-isv\_d)
4010         j0 = jsv\_o+dl*(j-jsv\_d)
4011         ave = 0.0
4012         \textcolor{keywordflow}{do} jj=j0,j0+dl-1 ; \textcolor{keywordflow}{do} ii=i0,i0+dl-1
4013            weight = mask(ii,jj,k)
4014            ave = ave+field\_in(ii,jj,k)*weight
4015 \textcolor{keyword}{        end}do; enddo
4016         field\_out(i,j,k)  = ave \textcolor{comment}{!Masked Sum (total\_weight=1)}
4017 \textcolor{keyword}{     end}do; enddo; enddo
4018   \textcolor{keywordflow}{elseif}(method == mmp .or. method == mms) \textcolor{keywordflow}{then}    \textcolor{comment}{!e.g., T\_advection\_xy}
4019      \textcolor{keywordflow}{do} k= ks,ke ; \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d
4020         i0 = isv\_o+dl*(i-isv\_d)
4021         j0 = jsv\_o+dl*(j-jsv\_d)
4022         ave = 0.0
4023         total\_weight = 0.0
4024         \textcolor{keywordflow}{do} jj=j0,j0+dl-1 ; \textcolor{keywordflow}{do} ii=i0,i0+dl-1
4025 \textcolor{comment}{!        do ii=i0,i0+dl-1 ; do jj=j0,j0+dl-1}
4026            weight = mask(ii,jj,k) * diag\_cs%G%areaT(ii,jj)
4027            total\_weight = total\_weight + weight
4028            ave = ave+field\_in(ii,jj,k)*weight
4029 \textcolor{keyword}{        end}do; enddo
4030         field\_out(i,j,k)  = ave / (total\_weight+eps\_area)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where
       ave=0.0}
4031 \textcolor{keyword}{     end}do; enddo; enddo
4032   \textcolor{keywordflow}{elseif}(method == pmm) \textcolor{keywordflow}{then}
4033      \textcolor{keywordflow}{do} k= ks,ke ; \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d
4034         i0 = isv\_o+dl*(i-isv\_d)
4035         j0 = jsv\_o+dl*(j-jsv\_d)
4036         ave = 0.0
4037         total\_weight = 0.0
4038         ii=i0
4039         \textcolor{keywordflow}{do} jj=j0,j0+dl-1
4040            weight =mask(ii,jj,k) * diag\_cs%G%dyCu(ii,jj) * diag\_cs%h(ii,jj,k)
4041            total\_weight = total\_weight +weight
4042            ave=ave+field\_in(ii,jj,k)*weight
4043 \textcolor{keywordflow}{        enddo}
4044         field\_out(i,j,k)  = ave/(total\_weight+eps\_face)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where
       ave=0.0}
4045 \textcolor{keyword}{     end}do; enddo; enddo
4046   \textcolor{keywordflow}{elseif}(method == pss) \textcolor{keywordflow}{then}    \textcolor{comment}{!e.g. umo}
4047      \textcolor{keywordflow}{do} k= ks,ke ; \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d
4048         i0 = isv\_o+dl*(i-isv\_d)
4049         j0 = jsv\_o+dl*(j-jsv\_d)
4050         ave = 0.0
4051         ii=i0
4052         \textcolor{keywordflow}{do} jj=j0,j0+dl-1
4053            weight =mask(ii,jj,k)
4054            ave=ave+field\_in(ii,jj,k)*weight
4055 \textcolor{keywordflow}{        enddo}
4056         field\_out(i,j,k)  = ave  \textcolor{comment}{!Masked Sum (total\_weight=1)}
4057 \textcolor{keyword}{     end}do; enddo; enddo
4058   \textcolor{keywordflow}{elseif}(method == sps) \textcolor{keywordflow}{then}    \textcolor{comment}{!e.g. vmo}
4059      \textcolor{keywordflow}{do} k= ks,ke ; \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d
4060         i0 = isv\_o+dl*(i-isv\_d)
4061         j0 = jsv\_o+dl*(j-jsv\_d)
4062         ave = 0.0
4063         jj=j0
4064         \textcolor{keywordflow}{do} ii=i0,i0+dl-1
4065            weight =mask(ii,jj,k)
4066            ave=ave+field\_in(ii,jj,k)*weight
4067 \textcolor{keywordflow}{        enddo}
4068         field\_out(i,j,k)  = ave  \textcolor{comment}{!Masked Sum (total\_weight=1)}
4069 \textcolor{keyword}{     end}do; enddo; enddo
4070   \textcolor{keywordflow}{elseif}(method == mpm) \textcolor{keywordflow}{then}
4071      \textcolor{keywordflow}{do} k= ks,ke ; \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d
4072         i0 = isv\_o+dl*(i-isv\_d)
4073         j0 = jsv\_o+dl*(j-jsv\_d)
4074         ave = 0.0
4075         total\_weight = 0.0
4076         jj=j0
4077         \textcolor{keywordflow}{do} ii=i0,i0+dl-1
4078            weight = mask(ii,jj,k) * diag\_cs%G%dxCv(ii,jj) * diag\_cs%h(ii,jj,k)
4079            total\_weight = total\_weight + weight
4080            ave=ave+field\_in(ii,jj,k)*weight
4081 \textcolor{keywordflow}{        enddo}
4082         field\_out(i,j,k)  = ave/(total\_weight+eps\_face)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where
       ave=0.0}
4083 \textcolor{keyword}{     end}do; enddo; enddo
4084   \textcolor{keywordflow}{elseif}(method == msk) \textcolor{keywordflow}{then} \textcolor{comment}{!The input field is a mask, subsample}
4085      field\_out(:,:,:) = 0.0
4086      \textcolor{keywordflow}{do} k= ks,ke ; \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d
4087         i0 = isv\_o+dl*(i-isv\_d)
4088         j0 = jsv\_o+dl*(j-jsv\_d)
4089         ave = 0.0
4090         \textcolor{keywordflow}{do} jj=j0,j0+dl-1 ; \textcolor{keywordflow}{do} ii=i0,i0+dl-1
4091            ave=ave+field\_in(ii,jj,k)
4092 \textcolor{keyword}{        end}do; enddo
4093         \textcolor{keywordflow}{if}(ave > 0.0) field\_out(i,j,k)=1.0
4094 \textcolor{keyword}{     end}do; enddo; enddo
4095   \textcolor{keywordflow}{else}
4096      \textcolor{keyword}{write} (mesg,*) \textcolor{stringliteral}{" unknown sampling method: "},method
4097      \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"downsample\_field\_3d: "}//trim(mesg)//\textcolor{stringliteral}{" "}//trim(diag%debug\_str))
4098 \textcolor{keywordflow}{  endif}
4099 
\end{DoxyCode}


The documentation for this interface was generated from the following file\+:\begin{DoxyCompactItemize}
\item 
/home/cermak/src/\+M\+O\+M6.\+devrob/src/framework/M\+O\+M\+\_\+diag\+\_\+mediator.\+F90\end{DoxyCompactItemize}
