\hypertarget{interfacemom__diag__mediator_1_1downsample__field}{}\doxysection{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}}


\doxysubsection{Detailed Description}
Down sample a field. 

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

\doxysubsection*{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}


\doxysubsection{Detailed Description}
Down sample a field. 

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



\doxysubsection{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}}
\doxysubsubsection{\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{\texttt{ in}}  & {\em dl} & Level of down sampling \\
\hline
\mbox{\texttt{ in}}  & {\em method} & Sampling method \\
\hline
 & {\em mask} & Mask for field \\
\hline
\mbox{\texttt{ in}}  & {\em diag\+\_\+cs} & Structure used to regulate diagnostic output \\
\hline
\mbox{\texttt{ in}}  & {\em diag} & A structure describing the diagnostic to post \\
\hline
\mbox{\texttt{ in}}  & {\em isv\+\_\+o} & Original i-\/start index \\
\hline
\mbox{\texttt{ in}}  & {\em jsv\+\_\+o} & Original j-\/start index \\
\hline
\mbox{\texttt{ in}}  & {\em isv\+\_\+d} & i-\/start index of down sampled data \\
\hline
\mbox{\texttt{ in}}  & {\em iev\+\_\+d} & i-\/end index of down sampled data \\
\hline
\mbox{\texttt{ in}}  & {\em jsv\+\_\+d} & j-\/start index of down sampled data \\
\hline
\mbox{\texttt{ 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}{0}
\DoxyCodeLine{4107 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer} :: field\_in\textcolor{comment}{      !< Original field to be down sampled}}
\DoxyCodeLine{4108 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{allocatable} :: field\_out\textcolor{comment}{ !< Down sampled field}}
\DoxyCodeLine{4109   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: dl\textcolor{comment}{                !< Level of down sampling}}
\DoxyCodeLine{4110   \textcolor{keywordtype}{integer},  \textcolor{keywordtype}{intent(in)} :: method\textcolor{comment}{           !< Sampling method}}
\DoxyCodeLine{4111 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer} :: mask\textcolor{comment}{    !< Mask for field}}
\DoxyCodeLine{4112   \textcolor{keywordtype}{type}(diag\_ctrl),   \textcolor{keywordtype}{intent(in)} :: diag\_CS\textcolor{comment}{ !< Structure used to regulate diagnostic output}}
\DoxyCodeLine{4113   \textcolor{keywordtype}{type}(diag\_type),   \textcolor{keywordtype}{intent(in)} :: diag\textcolor{comment}{    !< A structure describing the diagnostic to post}}
\DoxyCodeLine{4114   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: isv\_o\textcolor{comment}{             !< Original i-\/start index}}
\DoxyCodeLine{4115   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: jsv\_o\textcolor{comment}{             !< Original j-\/start index}}
\DoxyCodeLine{4116   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: isv\_d\textcolor{comment}{             !< i-\/start index of down sampled data}}
\DoxyCodeLine{4117   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: iev\_d\textcolor{comment}{             !< i-\/end index of down sampled data}}
\DoxyCodeLine{4118   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: jsv\_d\textcolor{comment}{             !< j-\/start index of down sampled data}}
\DoxyCodeLine{4119   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: jev\_d\textcolor{comment}{             !< j-\/end index of down sampled data}}
\DoxyCodeLine{4120   \textcolor{comment}{! Locals}}
\DoxyCodeLine{4121   \textcolor{keywordtype}{character(len=240)} :: mesg}
\DoxyCodeLine{4122   \textcolor{keywordtype}{integer} :: i,j,ii,jj,i0,j0,f1,f2,f\_in1,f\_in2}
\DoxyCodeLine{4123 \textcolor{keywordtype}{  real} :: ave, total\_weight, weight}
\DoxyCodeLine{4124 \textcolor{keywordtype}{  real} :: epsilon = 1.0e-\/20  \textcolor{comment}{! A negligibly small count of weights [nondim]}}
\DoxyCodeLine{4125 \textcolor{keywordtype}{  real} :: eps\_area  \textcolor{comment}{! A negligibly small area [L2 ~> m2]}}
\DoxyCodeLine{4126 \textcolor{keywordtype}{  real} :: eps\_len   \textcolor{comment}{! A negligibly small horizontal length [L ~> m]}}
\DoxyCodeLine{4127 }
\DoxyCodeLine{4128   eps\_len = 1.0e-\/20 * diag\_cs\%G\%US\%m\_to\_L}
\DoxyCodeLine{4129   eps\_area = 1.0e-\/20 * diag\_cs\%G\%US\%m\_to\_L**2}
\DoxyCodeLine{4130 }
\DoxyCodeLine{4131   \textcolor{comment}{! Allocate the down sampled field on the down sampled data domain}}
\DoxyCodeLine{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))}}
\DoxyCodeLine{4133 \textcolor{comment}{!  allocate(field\_out(1:size(field\_in,1)/dl,1:size(field\_in,2)/dl))}}
\DoxyCodeLine{4134   \textcolor{comment}{! Fill the down sampled field on the down sampled diagnostics (almost always compuate) domain}}
\DoxyCodeLine{4135   f\_in1 = \textcolor{keyword}{size}(field\_in,1)}
\DoxyCodeLine{4136   f\_in2 = \textcolor{keyword}{size}(field\_in,2)}
\DoxyCodeLine{4137   f1 = f\_in1/dl}
\DoxyCodeLine{4138   f2 = f\_in2/dl}
\DoxyCodeLine{4139   \textcolor{comment}{! Correction for the symmetric case}}
\DoxyCodeLine{4140   \textcolor{keywordflow}{if} (diag\_cs\%G\%symmetric) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4141      f1 = f1 + mod(f\_in1,dl)}
\DoxyCodeLine{4142      f2 = f2 + mod(f\_in2,dl)}
\DoxyCodeLine{4143 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{4144   \textcolor{keyword}{allocate}(field\_out(1:f1,1:f2))}
\DoxyCodeLine{4145 }
\DoxyCodeLine{4146   \textcolor{keywordflow}{if} (method == mmp) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4147      \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d}
\DoxyCodeLine{4148         i0 = isv\_o+dl*(i-\/isv\_d)}
\DoxyCodeLine{4149         j0 = jsv\_o+dl*(j-\/jsv\_d)}
\DoxyCodeLine{4150         ave = 0.0}
\DoxyCodeLine{4151         total\_weight = 0.0}
\DoxyCodeLine{4152         \textcolor{keywordflow}{do} jj=j0,j0+dl-\/1 ; \textcolor{keywordflow}{do} ii=i0,i0+dl-\/1}
\DoxyCodeLine{4153 \textcolor{comment}{!        do ii=i0,i0+dl-\/1 ; do jj=j0,j0+dl-\/1}}
\DoxyCodeLine{4154            weight = mask(ii,jj)*diag\_cs\%G\%areaT(ii,jj)}
\DoxyCodeLine{4155            total\_weight = total\_weight + weight}
\DoxyCodeLine{4156            ave = ave+field\_in(ii,jj)*weight}
\DoxyCodeLine{4157         enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4158         field\_out(i,j)  = ave/(total\_weight + eps\_area)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where ave=0.0}}
\DoxyCodeLine{4159      enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4160   \textcolor{keywordflow}{elseif}(method == ssp) \textcolor{keywordflow}{then}    \textcolor{comment}{! e.g., T\_dfxy\_cont\_tendency\_2d}}
\DoxyCodeLine{4161      \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d}
\DoxyCodeLine{4162         i0 = isv\_o+dl*(i-\/isv\_d)}
\DoxyCodeLine{4163         j0 = jsv\_o+dl*(j-\/jsv\_d)}
\DoxyCodeLine{4164         ave = 0.0}
\DoxyCodeLine{4165         total\_weight = 0.0}
\DoxyCodeLine{4166         \textcolor{keywordflow}{do} jj=j0,j0+dl-\/1 ; \textcolor{keywordflow}{do} ii=i0,i0+dl-\/1}
\DoxyCodeLine{4167 \textcolor{comment}{!        do ii=i0,i0+dl-\/1 ; do jj=j0,j0+dl-\/1}}
\DoxyCodeLine{4168            weight = mask(ii,jj)}
\DoxyCodeLine{4169            total\_weight = total\_weight + weight}
\DoxyCodeLine{4170            ave=ave+field\_in(ii,jj)*weight}
\DoxyCodeLine{4171         enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4172         field\_out(i,j)  = ave/(total\_weight+epsilon)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where ave=0.0}}
\DoxyCodeLine{4173      enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4174   \textcolor{keywordflow}{elseif}(method == psp) \textcolor{keywordflow}{then}    \textcolor{comment}{! e.g., umo\_2d}}
\DoxyCodeLine{4175      \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d}
\DoxyCodeLine{4176         i0 = isv\_o+dl*(i-\/isv\_d)}
\DoxyCodeLine{4177         j0 = jsv\_o+dl*(j-\/jsv\_d)}
\DoxyCodeLine{4178         ave = 0.0}
\DoxyCodeLine{4179         total\_weight = 0.0}
\DoxyCodeLine{4180         ii=i0}
\DoxyCodeLine{4181         \textcolor{keywordflow}{do} jj=j0,j0+dl-\/1}
\DoxyCodeLine{4182            weight = mask(ii,jj)}
\DoxyCodeLine{4183            total\_weight = total\_weight +weight}
\DoxyCodeLine{4184            ave=ave+field\_in(ii,jj)*weight}
\DoxyCodeLine{4185 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{4186         field\_out(i,j)  = ave/(total\_weight+epsilon)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where ave=0.0}}
\DoxyCodeLine{4187      enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4188   \textcolor{keywordflow}{elseif}(method == spp) \textcolor{keywordflow}{then}    \textcolor{comment}{! e.g., vmo\_2d}}
\DoxyCodeLine{4189      \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d}
\DoxyCodeLine{4190         i0 = isv\_o+dl*(i-\/isv\_d)}
\DoxyCodeLine{4191         j0 = jsv\_o+dl*(j-\/jsv\_d)}
\DoxyCodeLine{4192         ave = 0.0}
\DoxyCodeLine{4193         total\_weight = 0.0}
\DoxyCodeLine{4194         jj=j0}
\DoxyCodeLine{4195         \textcolor{keywordflow}{do} ii=i0,i0+dl-\/1}
\DoxyCodeLine{4196            weight = mask(ii,jj)}
\DoxyCodeLine{4197            total\_weight = total\_weight +weight}
\DoxyCodeLine{4198            ave=ave+field\_in(ii,jj)*weight}
\DoxyCodeLine{4199 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{4200         field\_out(i,j)  = ave/(total\_weight+epsilon)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where ave=0.0}}
\DoxyCodeLine{4201      enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4202   \textcolor{keywordflow}{elseif}(method == pmp) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4203      \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d}
\DoxyCodeLine{4204         i0 = isv\_o+dl*(i-\/isv\_d)}
\DoxyCodeLine{4205         j0 = jsv\_o+dl*(j-\/jsv\_d)}
\DoxyCodeLine{4206         ave = 0.0}
\DoxyCodeLine{4207         total\_weight = 0.0}
\DoxyCodeLine{4208         ii=i0}
\DoxyCodeLine{4209         \textcolor{keywordflow}{do} jj=j0,j0+dl-\/1}
\DoxyCodeLine{4210            weight = mask(ii,jj) * diag\_cs\%G\%dyCu(ii,jj)\textcolor{comment}{!*diag\_cs\%h(ii,jj,1) !Niki?}}
\DoxyCodeLine{4211            total\_weight = total\_weight +weight}
\DoxyCodeLine{4212            ave=ave+field\_in(ii,jj)*weight}
\DoxyCodeLine{4213 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{4214         field\_out(i,j)  = ave/(total\_weight+eps\_len)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where ave=0.0}}
\DoxyCodeLine{4215      enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4216   \textcolor{keywordflow}{elseif}(method == mpp) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4217      \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d}
\DoxyCodeLine{4218         i0 = isv\_o+dl*(i-\/isv\_d)}
\DoxyCodeLine{4219         j0 = jsv\_o+dl*(j-\/jsv\_d)}
\DoxyCodeLine{4220         ave = 0.0}
\DoxyCodeLine{4221         total\_weight = 0.0}
\DoxyCodeLine{4222         jj=j0}
\DoxyCodeLine{4223         \textcolor{keywordflow}{do} ii=i0,i0+dl-\/1}
\DoxyCodeLine{4224            weight = mask(ii,jj)* diag\_cs\%G\%dxCv(ii,jj)\textcolor{comment}{!*diag\_cs\%h(ii,jj,1) !Niki?}}
\DoxyCodeLine{4225            total\_weight = total\_weight +weight}
\DoxyCodeLine{4226            ave=ave+field\_in(ii,jj)*weight}
\DoxyCodeLine{4227 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{4228         field\_out(i,j)  = ave/(total\_weight+eps\_len)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where ave=0.0}}
\DoxyCodeLine{4229      enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4230   \textcolor{keywordflow}{elseif}(method == msk) \textcolor{keywordflow}{then} \textcolor{comment}{!The input field is a mask, subsample}}
\DoxyCodeLine{4231      field\_out(:,:) = 0.0}
\DoxyCodeLine{4232      \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d}
\DoxyCodeLine{4233         i0 = isv\_o+dl*(i-\/isv\_d)}
\DoxyCodeLine{4234         j0 = jsv\_o+dl*(j-\/jsv\_d)}
\DoxyCodeLine{4235         ave = 0.0}
\DoxyCodeLine{4236         \textcolor{keywordflow}{do} jj=j0,j0+dl-\/1 ; \textcolor{keywordflow}{do} ii=i0,i0+dl-\/1}
\DoxyCodeLine{4237            ave=ave+field\_in(ii,jj)}
\DoxyCodeLine{4238         enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4239         \textcolor{keywordflow}{if}(ave > 0.0) field\_out(i,j)=1.0}
\DoxyCodeLine{4240      enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4241   \textcolor{keywordflow}{else}}
\DoxyCodeLine{4242      \textcolor{keyword}{write} (mesg,*) \textcolor{stringliteral}{" unknown sampling method: "},method}
\DoxyCodeLine{4243      \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"downsample\_field\_2d: "}//trim(mesg)//\textcolor{stringliteral}{" "}//trim(diag\%debug\_str))}
\DoxyCodeLine{4244 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{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}}
\doxysubsubsection{\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}{}\doxysubsection{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{\texttt{ in}}  & {\em dl} & Level of down sampling \\
\hline
\mbox{\texttt{ in}}  & {\em method} & Sampling method \\
\hline
 & {\em mask} & Mask for field \\
\hline
\mbox{\texttt{ in}}  & {\em diag\+\_\+cs} & Structure used to regulate diagnostic output \\
\hline
\mbox{\texttt{ in}}  & {\em diag} & A structure describing the diagnostic to post \\
\hline
\mbox{\texttt{ in}}  & {\em isv\+\_\+o} & Original i-\/start index \\
\hline
\mbox{\texttt{ in}}  & {\em jsv\+\_\+o} & Original j-\/start index \\
\hline
\mbox{\texttt{ in}}  & {\em isv\+\_\+d} & i-\/start index of down sampled data \\
\hline
\mbox{\texttt{ in}}  & {\em iev\+\_\+d} & i-\/end index of down sampled data \\
\hline
\mbox{\texttt{ in}}  & {\em jsv\+\_\+d} & j-\/start index of down sampled data \\
\hline
\mbox{\texttt{ 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}{0}
\DoxyCodeLine{3951 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{pointer} :: field\_in\textcolor{comment}{      !< Original field to be down sampled}}
\DoxyCodeLine{3952 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{allocatable} :: field\_out\textcolor{comment}{ !< down sampled field}}
\DoxyCodeLine{3953   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: dl\textcolor{comment}{                !< Level of down sampling}}
\DoxyCodeLine{3954   \textcolor{keywordtype}{integer},  \textcolor{keywordtype}{intent(in)} :: method\textcolor{comment}{           !< Sampling method}}
\DoxyCodeLine{3955 \textcolor{keywordtype}{  real},  \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{pointer} :: mask\textcolor{comment}{ !< Mask for field}}
\DoxyCodeLine{3956   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{intent(in)} :: diag\_CS\textcolor{comment}{   !< Structure used to regulate diagnostic output}}
\DoxyCodeLine{3957   \textcolor{keywordtype}{type}(diag\_type), \textcolor{keywordtype}{intent(in)} :: diag\textcolor{comment}{      !< A structure describing the diagnostic to post}}
\DoxyCodeLine{3958   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: isv\_o\textcolor{comment}{             !< Original i-\/start index}}
\DoxyCodeLine{3959   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: jsv\_o\textcolor{comment}{             !< Original j-\/start index}}
\DoxyCodeLine{3960   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: isv\_d\textcolor{comment}{             !< i-\/start index of down sampled data}}
\DoxyCodeLine{3961   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: iev\_d\textcolor{comment}{             !< i-\/end index of down sampled data}}
\DoxyCodeLine{3962   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: jsv\_d\textcolor{comment}{             !< j-\/start index of down sampled data}}
\DoxyCodeLine{3963   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: jev\_d\textcolor{comment}{             !< j-\/end index of down sampled data}}
\DoxyCodeLine{3964   \textcolor{comment}{! Locals}}
\DoxyCodeLine{3965   \textcolor{keywordtype}{character(len=240)} :: mesg}
\DoxyCodeLine{3966   \textcolor{keywordtype}{integer} :: i,j,ii,jj,i0,j0,f1,f2,f\_in1,f\_in2}
\DoxyCodeLine{3967   \textcolor{keywordtype}{integer} :: k,ks,ke}
\DoxyCodeLine{3968 \textcolor{keywordtype}{  real} :: ave,total\_weight,weight}
\DoxyCodeLine{3969 \textcolor{keywordtype}{  real} :: eps\_vol   \textcolor{comment}{! A negligibly small volume or mass [H L2 ~> m3 or kg]}}
\DoxyCodeLine{3970 \textcolor{keywordtype}{  real} :: eps\_area  \textcolor{comment}{! A negligibly small area [L2 ~> m2]}}
\DoxyCodeLine{3971 \textcolor{keywordtype}{  real} :: eps\_face  \textcolor{comment}{! A negligibly small face area [H L ~> m2 or kg m-\/1]}}
\DoxyCodeLine{3972 }
\DoxyCodeLine{3973   ks = 1 ; ke = \textcolor{keyword}{size}(field\_in,3)}
\DoxyCodeLine{3974   eps\_face = 1.0e-\/20 * diag\_cs\%G\%US\%m\_to\_L * diag\_cs\%GV\%m\_to\_H}
\DoxyCodeLine{3975   eps\_area = 1.0e-\/20 * diag\_cs\%G\%US\%m\_to\_L**2}
\DoxyCodeLine{3976   eps\_vol = 1.0e-\/20 * diag\_cs\%G\%US\%m\_to\_L**2 * diag\_cs\%GV\%m\_to\_H}
\DoxyCodeLine{3977 }
\DoxyCodeLine{3978   \textcolor{comment}{! Allocate the down sampled field on the down sampled data domain}}
\DoxyCodeLine{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))}}
\DoxyCodeLine{3980 \textcolor{comment}{!  allocate(field\_out(1:size(field\_in,1)/dl,1:size(field\_in,2)/dl,ks:ke))}}
\DoxyCodeLine{3981   f\_in1 = \textcolor{keyword}{size}(field\_in,1)}
\DoxyCodeLine{3982   f\_in2 = \textcolor{keyword}{size}(field\_in,2)}
\DoxyCodeLine{3983   f1 = f\_in1/dl}
\DoxyCodeLine{3984   f2 = f\_in2/dl}
\DoxyCodeLine{3985   \textcolor{comment}{!Correction for the symmetric case}}
\DoxyCodeLine{3986   \textcolor{keywordflow}{if} (diag\_cs\%G\%symmetric) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3987      f1 = f1 + mod(f\_in1,dl)}
\DoxyCodeLine{3988      f2 = f2 + mod(f\_in2,dl)}
\DoxyCodeLine{3989 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{3990   \textcolor{keyword}{allocate}(field\_out(1:f1,1:f2,ks:ke))}
\DoxyCodeLine{3991 }
\DoxyCodeLine{3992   \textcolor{comment}{! Fill the down sampled field on the down sampled diagnostics (almost always compuate) domain}}
\DoxyCodeLine{3993   \textcolor{keywordflow}{if} (method == mmm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{3994      \textcolor{keywordflow}{do} k= ks,ke ; \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d}
\DoxyCodeLine{3995         i0 = isv\_o+dl*(i-\/isv\_d)}
\DoxyCodeLine{3996         j0 = jsv\_o+dl*(j-\/jsv\_d)}
\DoxyCodeLine{3997         ave = 0.0}
\DoxyCodeLine{3998         total\_weight = 0.0}
\DoxyCodeLine{3999         \textcolor{keywordflow}{do} jj=j0,j0+dl-\/1 ; \textcolor{keywordflow}{do} ii=i0,i0+dl-\/1}
\DoxyCodeLine{4000 \textcolor{comment}{!        do ii=i0,i0+dl-\/1 ; do jj=j0,j0+dl-\/1 !This seems to be faster!!!!}}
\DoxyCodeLine{4001            weight = mask(ii,jj,k) * diag\_cs\%G\%areaT(ii,jj) * diag\_cs\%h(ii,jj,k)}
\DoxyCodeLine{4002            total\_weight = total\_weight + weight}
\DoxyCodeLine{4003            ave = ave+field\_in(ii,jj,k) * weight}
\DoxyCodeLine{4004         enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4005         field\_out(i,j,k)  = ave/(total\_weight + eps\_vol)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where ave=0.0}}
\DoxyCodeLine{4006      enddo; enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4007   \textcolor{keywordflow}{elseif} (method == sss) \textcolor{keywordflow}{then}    \textcolor{comment}{!e.g., volcello}}
\DoxyCodeLine{4008      \textcolor{keywordflow}{do} k= ks,ke ; \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d}
\DoxyCodeLine{4009         i0 = isv\_o+dl*(i-\/isv\_d)}
\DoxyCodeLine{4010         j0 = jsv\_o+dl*(j-\/jsv\_d)}
\DoxyCodeLine{4011         ave = 0.0}
\DoxyCodeLine{4012         \textcolor{keywordflow}{do} jj=j0,j0+dl-\/1 ; \textcolor{keywordflow}{do} ii=i0,i0+dl-\/1}
\DoxyCodeLine{4013            weight = mask(ii,jj,k)}
\DoxyCodeLine{4014            ave = ave+field\_in(ii,jj,k)*weight}
\DoxyCodeLine{4015         enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4016         field\_out(i,j,k)  = ave \textcolor{comment}{!Masked Sum (total\_weight=1)}}
\DoxyCodeLine{4017      enddo; enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4018   \textcolor{keywordflow}{elseif}(method == mmp .or. method == mms) \textcolor{keywordflow}{then}    \textcolor{comment}{!e.g., T\_advection\_xy}}
\DoxyCodeLine{4019      \textcolor{keywordflow}{do} k= ks,ke ; \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d}
\DoxyCodeLine{4020         i0 = isv\_o+dl*(i-\/isv\_d)}
\DoxyCodeLine{4021         j0 = jsv\_o+dl*(j-\/jsv\_d)}
\DoxyCodeLine{4022         ave = 0.0}
\DoxyCodeLine{4023         total\_weight = 0.0}
\DoxyCodeLine{4024         \textcolor{keywordflow}{do} jj=j0,j0+dl-\/1 ; \textcolor{keywordflow}{do} ii=i0,i0+dl-\/1}
\DoxyCodeLine{4025 \textcolor{comment}{!        do ii=i0,i0+dl-\/1 ; do jj=j0,j0+dl-\/1}}
\DoxyCodeLine{4026            weight = mask(ii,jj,k) * diag\_cs\%G\%areaT(ii,jj)}
\DoxyCodeLine{4027            total\_weight = total\_weight + weight}
\DoxyCodeLine{4028            ave = ave+field\_in(ii,jj,k)*weight}
\DoxyCodeLine{4029         enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4030         field\_out(i,j,k)  = ave / (total\_weight+eps\_area)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where ave=0.0}}
\DoxyCodeLine{4031      enddo; enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4032   \textcolor{keywordflow}{elseif}(method == pmm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4033      \textcolor{keywordflow}{do} k= ks,ke ; \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d}
\DoxyCodeLine{4034         i0 = isv\_o+dl*(i-\/isv\_d)}
\DoxyCodeLine{4035         j0 = jsv\_o+dl*(j-\/jsv\_d)}
\DoxyCodeLine{4036         ave = 0.0}
\DoxyCodeLine{4037         total\_weight = 0.0}
\DoxyCodeLine{4038         ii=i0}
\DoxyCodeLine{4039         \textcolor{keywordflow}{do} jj=j0,j0+dl-\/1}
\DoxyCodeLine{4040            weight =mask(ii,jj,k) * diag\_cs\%G\%dyCu(ii,jj) * diag\_cs\%h(ii,jj,k)}
\DoxyCodeLine{4041            total\_weight = total\_weight +weight}
\DoxyCodeLine{4042            ave=ave+field\_in(ii,jj,k)*weight}
\DoxyCodeLine{4043 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{4044         field\_out(i,j,k)  = ave/(total\_weight+eps\_face)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where ave=0.0}}
\DoxyCodeLine{4045      enddo; enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4046   \textcolor{keywordflow}{elseif}(method == pss) \textcolor{keywordflow}{then}    \textcolor{comment}{!e.g. umo}}
\DoxyCodeLine{4047      \textcolor{keywordflow}{do} k= ks,ke ; \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d}
\DoxyCodeLine{4048         i0 = isv\_o+dl*(i-\/isv\_d)}
\DoxyCodeLine{4049         j0 = jsv\_o+dl*(j-\/jsv\_d)}
\DoxyCodeLine{4050         ave = 0.0}
\DoxyCodeLine{4051         ii=i0}
\DoxyCodeLine{4052         \textcolor{keywordflow}{do} jj=j0,j0+dl-\/1}
\DoxyCodeLine{4053            weight =mask(ii,jj,k)}
\DoxyCodeLine{4054            ave=ave+field\_in(ii,jj,k)*weight}
\DoxyCodeLine{4055 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{4056         field\_out(i,j,k)  = ave  \textcolor{comment}{!Masked Sum (total\_weight=1)}}
\DoxyCodeLine{4057      enddo; enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4058   \textcolor{keywordflow}{elseif}(method == sps) \textcolor{keywordflow}{then}    \textcolor{comment}{!e.g. vmo}}
\DoxyCodeLine{4059      \textcolor{keywordflow}{do} k= ks,ke ; \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d}
\DoxyCodeLine{4060         i0 = isv\_o+dl*(i-\/isv\_d)}
\DoxyCodeLine{4061         j0 = jsv\_o+dl*(j-\/jsv\_d)}
\DoxyCodeLine{4062         ave = 0.0}
\DoxyCodeLine{4063         jj=j0}
\DoxyCodeLine{4064         \textcolor{keywordflow}{do} ii=i0,i0+dl-\/1}
\DoxyCodeLine{4065            weight =mask(ii,jj,k)}
\DoxyCodeLine{4066            ave=ave+field\_in(ii,jj,k)*weight}
\DoxyCodeLine{4067 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{4068         field\_out(i,j,k)  = ave  \textcolor{comment}{!Masked Sum (total\_weight=1)}}
\DoxyCodeLine{4069      enddo; enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4070   \textcolor{keywordflow}{elseif}(method == mpm) \textcolor{keywordflow}{then}}
\DoxyCodeLine{4071      \textcolor{keywordflow}{do} k= ks,ke ; \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d}
\DoxyCodeLine{4072         i0 = isv\_o+dl*(i-\/isv\_d)}
\DoxyCodeLine{4073         j0 = jsv\_o+dl*(j-\/jsv\_d)}
\DoxyCodeLine{4074         ave = 0.0}
\DoxyCodeLine{4075         total\_weight = 0.0}
\DoxyCodeLine{4076         jj=j0}
\DoxyCodeLine{4077         \textcolor{keywordflow}{do} ii=i0,i0+dl-\/1}
\DoxyCodeLine{4078            weight = mask(ii,jj,k) * diag\_cs\%G\%dxCv(ii,jj) * diag\_cs\%h(ii,jj,k)}
\DoxyCodeLine{4079            total\_weight = total\_weight + weight}
\DoxyCodeLine{4080            ave=ave+field\_in(ii,jj,k)*weight}
\DoxyCodeLine{4081 \textcolor{keywordflow}{        enddo}}
\DoxyCodeLine{4082         field\_out(i,j,k)  = ave/(total\_weight+eps\_face)  \textcolor{comment}{!Avoid zero mask at all aggregating cells where ave=0.0}}
\DoxyCodeLine{4083      enddo; enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4084   \textcolor{keywordflow}{elseif}(method == msk) \textcolor{keywordflow}{then} \textcolor{comment}{!The input field is a mask, subsample}}
\DoxyCodeLine{4085      field\_out(:,:,:) = 0.0}
\DoxyCodeLine{4086      \textcolor{keywordflow}{do} k= ks,ke ; \textcolor{keywordflow}{do} j=jsv\_d,jev\_d ; \textcolor{keywordflow}{do} i=isv\_d,iev\_d}
\DoxyCodeLine{4087         i0 = isv\_o+dl*(i-\/isv\_d)}
\DoxyCodeLine{4088         j0 = jsv\_o+dl*(j-\/jsv\_d)}
\DoxyCodeLine{4089         ave = 0.0}
\DoxyCodeLine{4090         \textcolor{keywordflow}{do} jj=j0,j0+dl-\/1 ; \textcolor{keywordflow}{do} ii=i0,i0+dl-\/1}
\DoxyCodeLine{4091            ave=ave+field\_in(ii,jj,k)}
\DoxyCodeLine{4092         enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4093         \textcolor{keywordflow}{if}(ave > 0.0) field\_out(i,j,k)=1.0}
\DoxyCodeLine{4094      enddo; enddo;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{4095   \textcolor{keywordflow}{else}}
\DoxyCodeLine{4096      \textcolor{keyword}{write} (mesg,*) \textcolor{stringliteral}{" unknown sampling method: "},method}
\DoxyCodeLine{4097      \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"downsample\_field\_3d: "}//trim(mesg)//\textcolor{stringliteral}{" "}//trim(diag\%debug\_str))}
\DoxyCodeLine{4098 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{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}
