\hypertarget{namespacemom__diag__remap}{}\section{mom\+\_\+diag\+\_\+remap Module Reference}
\label{namespacemom__diag__remap}\index{mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}}


\subsection{Detailed Description}
provides runtime remapping of diagnostics to z star, sigma and rho vertical coordinates. 

The \hyperlink{structmom__diag__remap_1_1diag__remap__ctrl}{diag\+\_\+remap\+\_\+ctrl} type represents a remapping of diagnostics to a particular vertical coordinate. The module is used by the diag mediator module in the following way\+:
\begin{DoxyEnumerate}
\item \hyperlink{namespacemom__diag__remap_a3a3c0c9aaae22cbd2390eb42feafd622}{diag\+\_\+remap\+\_\+init()} is called to initialize a \hyperlink{structmom__diag__remap_1_1diag__remap__ctrl}{diag\+\_\+remap\+\_\+ctrl} instance.
\item \hyperlink{namespacemom__diag__remap_a0f3324e591a16e1ef6e3fc7b9f800270}{diag\+\_\+remap\+\_\+configure\+\_\+axes()} is called to read the configuration file and set up the vertical coordinate / axes definitions.
\item \hyperlink{namespacemom__diag__remap_aaaa62e290958a9364ffd3d73825ce3f2}{diag\+\_\+remap\+\_\+get\+\_\+axes\+\_\+info()} returns information needed for the diag mediator to define new axes for the remapped diagnostics.
\item \hyperlink{namespacemom__diag__remap_aaa0a887dc724438845e88598d439b20a}{diag\+\_\+remap\+\_\+update()} is called periodically (whenever h, T or S change) to either create or update the target remapping grids.
\item \hyperlink{namespacemom__diag__remap_a125ada6654d47c8d9750b620cdd0af7c}{diag\+\_\+remap\+\_\+do\+\_\+remap()} is called from within a diag post() to do the remapping before the diagnostic is written out. 
\end{DoxyEnumerate}\subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \hyperlink{structmom__diag__remap_1_1diag__remap__ctrl}{diag\+\_\+remap\+\_\+ctrl}
\begin{DoxyCompactList}\small\item\em Represents remapping of diagnostics to a particular vertical coordinate. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \hyperlink{namespacemom__diag__remap_a3a3c0c9aaae22cbd2390eb42feafd622}{diag\+\_\+remap\+\_\+init} (remap\+\_\+cs, coord\+\_\+tuple, answers\+\_\+2018)
\begin{DoxyCompactList}\small\item\em Initialize a diagnostic remapping type with the given vertical coordinate. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diag__remap_a3cfd706c08bbd33ad21b77c6b045a9c5}{diag\+\_\+remap\+\_\+end} (remap\+\_\+cs)
\begin{DoxyCompactList}\small\item\em De-\/init a diagnostic remapping type. Free allocated memory. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diag__remap_a924b98a931082a788dfdabf86d40f295}{diag\+\_\+remap\+\_\+diag\+\_\+registration\+\_\+closed} (remap\+\_\+cs)
\begin{DoxyCompactList}\small\item\em Inform that all diagnostics have been registered. If \+\_\+set\+\_\+active() has not been called on the remapping control structure will be disabled. This saves time in the case that a vertical coordinate was configured but no diagnostics which use the coordinate appeared in the diag\+\_\+table. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diag__remap_ab530334ce02c1bedad08ba84507ee5d1}{diag\+\_\+remap\+\_\+set\+\_\+active} (remap\+\_\+cs)
\begin{DoxyCompactList}\small\item\em Indicate that this remapping type is actually used by the diag manager. If this is never called then the type will be disabled to save time. See further explanation with diag\+\_\+remap\+\_\+registration\+\_\+closed. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diag__remap_a0f3324e591a16e1ef6e3fc7b9f800270}{diag\+\_\+remap\+\_\+configure\+\_\+axes} (remap\+\_\+cs, GV, US, param\+\_\+file)
\begin{DoxyCompactList}\small\item\em Configure the vertical axes for a diagnostic remapping control structure. Reads a configuration parameters to determine coordinate generation. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diag__remap_aaaa62e290958a9364ffd3d73825ce3f2}{diag\+\_\+remap\+\_\+get\+\_\+axes\+\_\+info} (remap\+\_\+cs, nz, id\+\_\+layer, id\+\_\+interface)
\begin{DoxyCompactList}\small\item\em Get layer and interface axes ids for this coordinate Needed when defining axes groups. \end{DoxyCompactList}\item 
logical function, public \hyperlink{namespacemom__diag__remap_af12d73b4028ee53365d1bdad8a2baa00}{diag\+\_\+remap\+\_\+axes\+\_\+configured} (remap\+\_\+cs)
\begin{DoxyCompactList}\small\item\em Whether or not the axes for this vertical coordinated has been configured. Configuration is complete when \hyperlink{namespacemom__diag__remap_a0f3324e591a16e1ef6e3fc7b9f800270}{diag\+\_\+remap\+\_\+configure\+\_\+axes()} has been successfully called. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diag__remap_aaa0a887dc724438845e88598d439b20a}{diag\+\_\+remap\+\_\+update} (remap\+\_\+cs, G, GV, US, h, T, S, eqn\+\_\+of\+\_\+state, h\+\_\+target)
\begin{DoxyCompactList}\small\item\em Build/update target vertical grids for diagnostic remapping. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diag__remap_a125ada6654d47c8d9750b620cdd0af7c}{diag\+\_\+remap\+\_\+do\+\_\+remap} (remap\+\_\+cs, G, GV, h, staggered\+\_\+in\+\_\+x, staggered\+\_\+in\+\_\+y, mask, field, remapped\+\_\+field)
\begin{DoxyCompactList}\small\item\em Remap diagnostic field to alternative vertical grid. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diag__remap_a5b0f7f8140918d3567bcc568cda0932e}{diag\+\_\+remap\+\_\+calc\+\_\+hmask} (remap\+\_\+cs, G, mask)
\begin{DoxyCompactList}\small\item\em Calculate masks for target grid. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diag__remap_ae1d52582964ba4213e0fa9b7ea183c39}{vertically\+\_\+reintegrate\+\_\+diag\+\_\+field} (remap\+\_\+cs, G, h, h\+\_\+target, staggered\+\_\+in\+\_\+x, staggered\+\_\+in\+\_\+y, mask, field, reintegrated\+\_\+field)
\begin{DoxyCompactList}\small\item\em Vertically re-\/grid an already vertically-\/integrated diagnostic field to alternative vertical grid. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diag__remap_a058317602b134c09ff42005dfe8b2bc0}{vertically\+\_\+interpolate\+\_\+diag\+\_\+field} (remap\+\_\+cs, G, h, staggered\+\_\+in\+\_\+x, staggered\+\_\+in\+\_\+y, mask, field, interpolated\+\_\+field)
\begin{DoxyCompactList}\small\item\em Vertically interpolate diagnostic field to alternative vertical grid. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__diag__remap_ae649e9dc9616184266d542bce5d9a452}{horizontally\+\_\+average\+\_\+diag\+\_\+field} (G, GV, h, staggered\+\_\+in\+\_\+x, staggered\+\_\+in\+\_\+y, is\+\_\+layer, is\+\_\+extensive, field, averaged\+\_\+field, averaged\+\_\+mask)
\begin{DoxyCompactList}\small\item\em Horizontally average field. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__diag__remap_af12d73b4028ee53365d1bdad8a2baa00}\label{namespacemom__diag__remap_af12d73b4028ee53365d1bdad8a2baa00}} 
\index{mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}!diag\+\_\+remap\+\_\+axes\+\_\+configured@{diag\+\_\+remap\+\_\+axes\+\_\+configured}}
\index{diag\+\_\+remap\+\_\+axes\+\_\+configured@{diag\+\_\+remap\+\_\+axes\+\_\+configured}!mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}}
\subsubsection{\texorpdfstring{diag\+\_\+remap\+\_\+axes\+\_\+configured()}{diag\_remap\_axes\_configured()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+diag\+\_\+remap\+::diag\+\_\+remap\+\_\+axes\+\_\+configured (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__diag__remap_1_1diag__remap__ctrl}{diag\+\_\+remap\+\_\+ctrl}), intent(in)}]{remap\+\_\+cs }\end{DoxyParamCaption})}



Whether or not the axes for this vertical coordinated has been configured. Configuration is complete when \hyperlink{namespacemom__diag__remap_a0f3324e591a16e1ef6e3fc7b9f800270}{diag\+\_\+remap\+\_\+configure\+\_\+axes()} has been successfully called. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em remap\+\_\+cs} & Diagnostic coordinate control structure \\
\hline
\end{DoxyParams}


Definition at line 263 of file M\+O\+M\+\_\+diag\+\_\+remap.\+F90.


\begin{DoxyCode}
263   \textcolor{keywordtype}{type}(diag\_remap\_ctrl), \textcolor{keywordtype}{intent(in)} :: remap\_cs\textcolor{comment}{ !< Diagnostic coordinate control structure}
264   \textcolor{keywordtype}{logical} :: diag\_remap\_axes\_configured
265 
266   diag\_remap\_axes\_configured = remap\_cs%configured
267 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diag__remap_a5b0f7f8140918d3567bcc568cda0932e}\label{namespacemom__diag__remap_a5b0f7f8140918d3567bcc568cda0932e}} 
\index{mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}!diag\+\_\+remap\+\_\+calc\+\_\+hmask@{diag\+\_\+remap\+\_\+calc\+\_\+hmask}}
\index{diag\+\_\+remap\+\_\+calc\+\_\+hmask@{diag\+\_\+remap\+\_\+calc\+\_\+hmask}!mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}}
\subsubsection{\texorpdfstring{diag\+\_\+remap\+\_\+calc\+\_\+hmask()}{diag\_remap\_calc\_hmask()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diag\+\_\+remap\+::diag\+\_\+remap\+\_\+calc\+\_\+hmask (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__diag__remap_1_1diag__remap__ctrl}{diag\+\_\+remap\+\_\+ctrl}), intent(in)}]{remap\+\_\+cs,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{real, dimension(\+:,\+:,\+:), intent(out)}]{mask }\end{DoxyParamCaption})}



Calculate masks for target grid. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em remap\+\_\+cs} & Diagnostic coodinate control structure\\
\hline
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt out}  & {\em mask} & h-\/point mask for target grid \mbox{[}nondim\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 447 of file M\+O\+M\+\_\+diag\+\_\+remap.\+F90.


\begin{DoxyCode}
447   \textcolor{keywordtype}{type}(diag\_remap\_ctrl),  \textcolor{keywordtype}{intent(in)}  :: remap\_cs\textcolor{comment}{ !< Diagnostic coodinate control structure}
448   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)}  :: g\textcolor{comment}{    !< Ocean grid structure}
449   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{intent(out)} :: mask\textcolor{comment}{ !< h-point mask for target grid [nondim]}
450   \textcolor{comment}{! Local variables}
451   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(remap\_cs%nz)} :: h\_dest \textcolor{comment}{! Destination thicknesses [H ~> m or kg m-2]}
452   \textcolor{keywordtype}{integer} :: i, j, k
453   \textcolor{keywordtype}{logical} :: mask\_vanished\_layers
454   \textcolor{keywordtype}{real} :: h\_tot      \textcolor{comment}{! Sum of all thicknesses [H ~> m or kg m-2]}
455   \textcolor{keywordtype}{real} :: h\_err      \textcolor{comment}{! An estimate of a negligible thickness [H ~> m or kg m-2]}
456 
457   \textcolor{keyword}{call }assert(remap\_cs%initialized, \textcolor{stringliteral}{'diag\_remap\_calc\_hmask: remap\_cs not initialized.'})
458 
459   \textcolor{comment}{! Only z*-like diagnostic coordinates should have a 3d mask}
460   mask\_vanished\_layers = (remap\_cs%vertical\_coord == coordinatemode(\textcolor{stringliteral}{'ZSTAR'}))
461   mask(:,:,:) = 0.
462 
463   \textcolor{keywordflow}{do} j=g%jsc-1, g%jec+1 ; \textcolor{keywordflow}{do} i=g%isc-1, g%iec+1
464     \textcolor{keywordflow}{if} (g%mask2dT(i,j)>0.) \textcolor{keywordflow}{then}
465       \textcolor{keywordflow}{if} (mask\_vanished\_layers) \textcolor{keywordflow}{then}
466         h\_dest(:) = remap\_cs%h(i,j,:)
467         h\_tot = 0.
468         h\_err = 0.
469         \textcolor{keywordflow}{do} k=1, remap\_cs%nz
470           h\_tot = h\_tot + h\_dest(k)
471           \textcolor{comment}{! This is an overestimate of how thick a vanished layer might be, that}
472           \textcolor{comment}{! appears due to round-off.}
473           h\_err = h\_err + epsilon(h\_tot) * h\_tot
474           \textcolor{comment}{! Mask out vanished layers}
475           \textcolor{keywordflow}{if} (h\_dest(k)<=8.*h\_err) \textcolor{keywordflow}{then}
476             mask(i,j,k) = 0.
477           \textcolor{keywordflow}{else}
478             mask(i,j,k) = 1.
479 \textcolor{keywordflow}{          endif}
480 \textcolor{keywordflow}{        enddo}
481       \textcolor{keywordflow}{else} \textcolor{comment}{! all layers might contain data}
482         mask(i,j,:) = 1.
483 \textcolor{keywordflow}{      endif}
484 \textcolor{keywordflow}{    endif}
485 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
486 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diag__remap_a0f3324e591a16e1ef6e3fc7b9f800270}\label{namespacemom__diag__remap_a0f3324e591a16e1ef6e3fc7b9f800270}} 
\index{mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}!diag\+\_\+remap\+\_\+configure\+\_\+axes@{diag\+\_\+remap\+\_\+configure\+\_\+axes}}
\index{diag\+\_\+remap\+\_\+configure\+\_\+axes@{diag\+\_\+remap\+\_\+configure\+\_\+axes}!mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}}
\subsubsection{\texorpdfstring{diag\+\_\+remap\+\_\+configure\+\_\+axes()}{diag\_remap\_configure\_axes()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diag\+\_\+remap\+::diag\+\_\+remap\+\_\+configure\+\_\+axes (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__diag__remap_1_1diag__remap__ctrl}{diag\+\_\+remap\+\_\+ctrl}), intent(inout)}]{remap\+\_\+cs,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file }\end{DoxyParamCaption})}



Configure the vertical axes for a diagnostic remapping control structure. Reads a configuration parameters to determine coordinate generation. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em remap\+\_\+cs} & Diag remap control structure\\
\hline
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file structure \\
\hline
\end{DoxyParams}


Definition at line 188 of file M\+O\+M\+\_\+diag\+\_\+remap.\+F90.


\begin{DoxyCode}
188   \textcolor{keywordtype}{type}(diag\_remap\_ctrl),   \textcolor{keywordtype}{intent(inout)} :: remap\_cs\textcolor{comment}{ !< Diag remap control structure}
189   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{ !< ocean vertical grid structure}
190   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{ !< A dimensional unit scaling type}
191   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file structure}
192   \textcolor{comment}{! Local variables}
193   \textcolor{keywordtype}{integer} :: nzi(4), nzl(4), k
194   \textcolor{keywordtype}{character(len=200)} :: inputdir, string, filename, int\_varname, layer\_varname
195   \textcolor{keywordtype}{character(len=40)}  :: mod  = \textcolor{stringliteral}{"MOM\_diag\_remap"} \textcolor{comment}{! This module's name.}
196   \textcolor{keywordtype}{character(len=8)}   :: units, expected\_units
197   \textcolor{keywordtype}{character(len=34)}  :: longname, string2
198 
199   \textcolor{keywordtype}{character(len=256)} :: err\_msg
200   \textcolor{keywordtype}{logical} :: ierr
201 
202   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)} :: interfaces, layers
203 
204   \textcolor{keyword}{call }initialize\_regridding(remap\_cs%regrid\_cs, gv, us, gv%max\_depth, param\_file, mod, &
205            trim(remap\_cs%vertical\_coord\_name), \textcolor{stringliteral}{"DIAG\_COORD"}, trim(remap\_cs%diag\_coord\_name))
206   \textcolor{keyword}{call }set\_regrid\_params(remap\_cs%regrid\_cs, min\_thickness=0., integrate\_downward\_for\_e=.false.)
207 
208   remap\_cs%nz = get\_regrid\_size(remap\_cs%regrid\_cs)
209 
210   \textcolor{keywordflow}{if} (remap\_cs%vertical\_coord == coordinatemode(\textcolor{stringliteral}{'SIGMA'})) \textcolor{keywordflow}{then}
211     units = \textcolor{stringliteral}{'nondim'}
212     longname = \textcolor{stringliteral}{'Fraction'}
213   \textcolor{keywordflow}{elseif} (remap\_cs%vertical\_coord == coordinatemode(\textcolor{stringliteral}{'RHO'})) \textcolor{keywordflow}{then}
214     units = \textcolor{stringliteral}{'kg m-3'}
215     longname = \textcolor{stringliteral}{'Target Potential Density'}
216   \textcolor{keywordflow}{else}
217     units = \textcolor{stringliteral}{'meters'}
218     longname = \textcolor{stringliteral}{'Depth'}
219 \textcolor{keywordflow}{  endif}
220 
221   \textcolor{comment}{! Make axes objects}
222   \textcolor{keyword}{allocate}(interfaces(remap\_cs%nz+1))
223   \textcolor{keyword}{allocate}(layers(remap\_cs%nz))
224 
225   interfaces(:) = getcoordinateinterfaces(remap\_cs%regrid\_cs)
226   layers(:) = 0.5 * ( interfaces(1:remap\_cs%nz) + interfaces(2:remap\_cs%nz+1) )
227 
228   remap\_cs%interface\_axes\_id = diag\_axis\_init(lowercase(trim(remap\_cs%diag\_coord\_name))//\textcolor{stringliteral}{'\_i'}, &
229                                               interfaces, trim(units), \textcolor{stringliteral}{'z'}, &
230                                               trim(longname)//\textcolor{stringliteral}{' at interface'}, direction=-1)
231   remap\_cs%layer\_axes\_id = diag\_axis\_init(lowercase(trim(remap\_cs%diag\_coord\_name))//\textcolor{stringliteral}{'\_l'}, &
232                                           layers, trim(units), \textcolor{stringliteral}{'z'}, &
233                                           trim(longname)//\textcolor{stringliteral}{' at cell center'}, direction=-1, &
234                                           edges=remap\_cs%interface\_axes\_id)
235 
236   \textcolor{comment}{! Axes have now been configured.}
237   remap\_cs%configured = .true.
238 
239   \textcolor{keyword}{deallocate}(interfaces)
240   \textcolor{keyword}{deallocate}(layers)
241 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diag__remap_a924b98a931082a788dfdabf86d40f295}\label{namespacemom__diag__remap_a924b98a931082a788dfdabf86d40f295}} 
\index{mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}!diag\+\_\+remap\+\_\+diag\+\_\+registration\+\_\+closed@{diag\+\_\+remap\+\_\+diag\+\_\+registration\+\_\+closed}}
\index{diag\+\_\+remap\+\_\+diag\+\_\+registration\+\_\+closed@{diag\+\_\+remap\+\_\+diag\+\_\+registration\+\_\+closed}!mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}}
\subsubsection{\texorpdfstring{diag\+\_\+remap\+\_\+diag\+\_\+registration\+\_\+closed()}{diag\_remap\_diag\_registration\_closed()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diag\+\_\+remap\+::diag\+\_\+remap\+\_\+diag\+\_\+registration\+\_\+closed (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__diag__remap_1_1diag__remap__ctrl}{diag\+\_\+remap\+\_\+ctrl}), intent(inout)}]{remap\+\_\+cs }\end{DoxyParamCaption})}



Inform that all diagnostics have been registered. If \+\_\+set\+\_\+active() has not been called on the remapping control structure will be disabled. This saves time in the case that a vertical coordinate was configured but no diagnostics which use the coordinate appeared in the diag\+\_\+table. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em remap\+\_\+cs} & Diag remapping control structure \\
\hline
\end{DoxyParams}


Definition at line 167 of file M\+O\+M\+\_\+diag\+\_\+remap.\+F90.


\begin{DoxyCode}
167   \textcolor{keywordtype}{type}(diag\_remap\_ctrl), \textcolor{keywordtype}{intent(inout)} :: remap\_cs\textcolor{comment}{ !< Diag remapping control structure}
168 
169   \textcolor{keywordflow}{if} (.not. remap\_cs%used) \textcolor{keywordflow}{then}
170     \textcolor{keyword}{call }diag\_remap\_end(remap\_cs)
171 \textcolor{keywordflow}{  endif}
172 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diag__remap_a125ada6654d47c8d9750b620cdd0af7c}\label{namespacemom__diag__remap_a125ada6654d47c8d9750b620cdd0af7c}} 
\index{mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}!diag\+\_\+remap\+\_\+do\+\_\+remap@{diag\+\_\+remap\+\_\+do\+\_\+remap}}
\index{diag\+\_\+remap\+\_\+do\+\_\+remap@{diag\+\_\+remap\+\_\+do\+\_\+remap}!mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}}
\subsubsection{\texorpdfstring{diag\+\_\+remap\+\_\+do\+\_\+remap()}{diag\_remap\_do\_remap()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diag\+\_\+remap\+::diag\+\_\+remap\+\_\+do\+\_\+remap (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__diag__remap_1_1diag__remap__ctrl}{diag\+\_\+remap\+\_\+ctrl}), intent(in)}]{remap\+\_\+cs,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension(\+:,\+:,\+:), intent(in)}]{h,  }\item[{logical, intent(in)}]{staggered\+\_\+in\+\_\+x,  }\item[{logical, intent(in)}]{staggered\+\_\+in\+\_\+y,  }\item[{real, dimension(\+:,\+:,\+:), pointer}]{mask,  }\item[{real, dimension(\+:,\+:,\+:), intent(in)}]{field,  }\item[{real, dimension(\+:,\+:,\+:), intent(inout)}]{remapped\+\_\+field }\end{DoxyParamCaption})}



Remap diagnostic field to alternative vertical grid. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em remap\+\_\+cs} & Diagnostic coodinate control structure\\
\hline
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em h} & The current thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em staggered\+\_\+in\+\_\+x} & True is the x-\/axis location is at u or q points\\
\hline
\mbox{\tt in}  & {\em staggered\+\_\+in\+\_\+y} & True is the y-\/axis location is at v or q points\\
\hline
 & {\em mask} & A mask for the field \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt in}  & {\em field} & The diagnostic field to be remapped \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em remapped\+\_\+field} & Field remapped to new coordinate \mbox{[}A\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 352 of file M\+O\+M\+\_\+diag\+\_\+remap.\+F90.


\begin{DoxyCode}
352   \textcolor{keywordtype}{type}(diag\_remap\_ctrl),   \textcolor{keywordtype}{intent(in)} :: remap\_cs\textcolor{comment}{ !< Diagnostic coodinate control structure}
353   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{  !< Ocean grid structure}
354   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)} :: gv\textcolor{comment}{ !< ocean vertical grid structure}
355   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)},  \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{  !< The current thicknesses [H ~> m or kg m-2]}
356   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(in)} :: staggered\_in\_x\textcolor{comment}{ !< True is the x-axis location is at u or q points}
357   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(in)} :: staggered\_in\_y\textcolor{comment}{ !< True is the y-axis location is at v or q points}
358   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)},  \textcolor{keywordtype}{pointer}    :: mask\textcolor{comment}{ !< A mask for the field [nondim]}
359   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)},  \textcolor{keywordtype}{intent(in)} :: field(:,:,:)\textcolor{comment}{ !< The diagnostic field to be remapped [A]}
360   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)},  \textcolor{keywordtype}{intent(inout)} :: remapped\_field\textcolor{comment}{ !< Field remapped to new coordinate [A]}
361   \textcolor{comment}{! Local variables}
362   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(remap\_cs%nz)} :: h\_dest \textcolor{comment}{! Destination thicknesses [H ~> m or kg m-2]}
363   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(size(h,3))} :: h\_src    \textcolor{comment}{! A column of source thicknesses [H ~> m or kg m-2]}
364   \textcolor{keywordtype}{real} :: h\_neglect, h\_neglect\_edge \textcolor{comment}{! Negligible thicknesses [H ~> m or kg m-2]}
365   \textcolor{keywordtype}{integer} :: nz\_src, nz\_dest
366   \textcolor{keywordtype}{integer} :: i, j, k\textcolor{comment}{                !< Grid index}
367   \textcolor{keywordtype}{integer} :: i1, j1\textcolor{comment}{                 !< 1-based index}
368   \textcolor{keywordtype}{integer} :: i\_lo, i\_hi, j\_lo, j\_hi\textcolor{comment}{ !< (uv->h) interpolation indices}
369   \textcolor{keywordtype}{integer} :: shift\textcolor{comment}{                  !< Symmetric offset for 1-based indexing}
370 
371   \textcolor{keyword}{call }assert(remap\_cs%initialized, \textcolor{stringliteral}{'diag\_remap\_do\_remap: remap\_cs not initialized.'})
372   \textcolor{keyword}{call }assert(\textcolor{keyword}{size}(field, 3) == \textcolor{keyword}{size}(h, 3), &
373               \textcolor{stringliteral}{'diag\_remap\_do\_remap: Remap field and thickness z-axes do not match.'})
374 
375   \textcolor{keywordflow}{if} (.not.remap\_cs%answers\_2018) \textcolor{keywordflow}{then}
376     h\_neglect = gv%H\_subroundoff ; h\_neglect\_edge = gv%H\_subroundoff
377   \textcolor{keywordflow}{elseif} (gv%Boussinesq) \textcolor{keywordflow}{then}
378     h\_neglect = gv%m\_to\_H*1.0e-30 ; h\_neglect\_edge = gv%m\_to\_H*1.0e-10
379   \textcolor{keywordflow}{else}
380     h\_neglect = gv%kg\_m2\_to\_H*1.0e-30 ; h\_neglect\_edge = gv%kg\_m2\_to\_H*1.0e-10
381 \textcolor{keywordflow}{  endif}
382 
383   nz\_src = \textcolor{keyword}{size}(field,3)
384   nz\_dest = remap\_cs%nz
385   remapped\_field(:,:,:) = 0.
386 
387   \textcolor{comment}{! Symmetric grid offset under 1-based indexing; see header for details.}
388   shift = 0; \textcolor{keywordflow}{if} (g%symmetric) shift = 1
389 
390   \textcolor{keywordflow}{if} (staggered\_in\_x .and. .not. staggered\_in\_y) \textcolor{keywordflow}{then}
391     \textcolor{comment}{! U-points}
392     \textcolor{keywordflow}{do} j=g%jsc, g%jec
393       \textcolor{keywordflow}{do} i=g%iscB, g%iecB
394         i1 = i - g%isdB + 1
395         i\_lo = i1 - shift; i\_hi = i\_lo + 1
396         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(mask)) \textcolor{keywordflow}{then}
397           \textcolor{keywordflow}{if} (mask(i,j,1) == 0.) cycle
398 \textcolor{keywordflow}{        endif}
399         h\_src(:) = 0.5 * (h(i\_lo,j,:) + h(i\_hi,j,:))
400         h\_dest(:) = 0.5 * (remap\_cs%h(i\_lo,j,:) + remap\_cs%h(i\_hi,j,:))
401         \textcolor{keyword}{call }remapping\_core\_h(remap\_cs%remap\_cs, &
402                               nz\_src, h\_src(:), field(i1,j,:), &
403                               nz\_dest, h\_dest(:), remapped\_field(i1,j,:), &
404                               h\_neglect, h\_neglect\_edge)
405 \textcolor{keywordflow}{      enddo}
406 \textcolor{keywordflow}{    enddo}
407   \textcolor{keywordflow}{elseif} (staggered\_in\_y .and. .not. staggered\_in\_x) \textcolor{keywordflow}{then}
408     \textcolor{comment}{! V-points}
409     \textcolor{keywordflow}{do} j=g%jscB, g%jecB
410       j1 = j - g%jsdB + 1
411       j\_lo = j1 - shift; j\_hi = j\_lo + 1
412       \textcolor{keywordflow}{do} i=g%isc, g%iec
413         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(mask)) \textcolor{keywordflow}{then}
414           \textcolor{keywordflow}{if} (mask(i,j,1) == 0.) cycle
415 \textcolor{keywordflow}{        endif}
416         h\_src(:) = 0.5 * (h(i,j\_lo,:) + h(i,j\_hi,:))
417         h\_dest(:) = 0.5 * (remap\_cs%h(i,j\_lo,:) + remap\_cs%h(i,j\_hi,:))
418         \textcolor{keyword}{call }remapping\_core\_h(remap\_cs%remap\_cs, &
419                               nz\_src, h\_src(:), field(i,j1,:), &
420                               nz\_dest, h\_dest(:), remapped\_field(i,j1,:), &
421                               h\_neglect, h\_neglect\_edge)
422 \textcolor{keywordflow}{      enddo}
423 \textcolor{keywordflow}{    enddo}
424   \textcolor{keywordflow}{elseif} ((.not. staggered\_in\_x) .and. (.not. staggered\_in\_y)) \textcolor{keywordflow}{then}
425     \textcolor{comment}{! H-points}
426     \textcolor{keywordflow}{do} j=g%jsc, g%jec
427       \textcolor{keywordflow}{do} i=g%isc, g%iec
428         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(mask)) \textcolor{keywordflow}{then}
429           \textcolor{keywordflow}{if} (mask(i,j,1) == 0.) cycle
430 \textcolor{keywordflow}{        endif}
431         h\_src(:) = h(i,j,:)
432         h\_dest(:) = remap\_cs%h(i,j,:)
433         \textcolor{keyword}{call }remapping\_core\_h(remap\_cs%remap\_cs, &
434                               nz\_src, h\_src(:), field(i,j,:), &
435                               nz\_dest, h\_dest(:), remapped\_field(i,j,:), &
436                               h\_neglect, h\_neglect\_edge)
437 \textcolor{keywordflow}{      enddo}
438 \textcolor{keywordflow}{    enddo}
439   \textcolor{keywordflow}{else}
440     \textcolor{keyword}{call }assert(.false., \textcolor{stringliteral}{'diag\_remap\_do\_remap: Unsupported axis combination'})
441 \textcolor{keywordflow}{  endif}
442 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diag__remap_a3cfd706c08bbd33ad21b77c6b045a9c5}\label{namespacemom__diag__remap_a3cfd706c08bbd33ad21b77c6b045a9c5}} 
\index{mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}!diag\+\_\+remap\+\_\+end@{diag\+\_\+remap\+\_\+end}}
\index{diag\+\_\+remap\+\_\+end@{diag\+\_\+remap\+\_\+end}!mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}}
\subsubsection{\texorpdfstring{diag\+\_\+remap\+\_\+end()}{diag\_remap\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diag\+\_\+remap\+::diag\+\_\+remap\+\_\+end (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__diag__remap_1_1diag__remap__ctrl}{diag\+\_\+remap\+\_\+ctrl}), intent(inout)}]{remap\+\_\+cs }\end{DoxyParamCaption})}



De-\/init a diagnostic remapping type. Free allocated memory. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em remap\+\_\+cs} & Diag remapping control structure \\
\hline
\end{DoxyParams}


Definition at line 151 of file M\+O\+M\+\_\+diag\+\_\+remap.\+F90.


\begin{DoxyCode}
151   \textcolor{keywordtype}{type}(diag\_remap\_ctrl), \textcolor{keywordtype}{intent(inout)} :: remap\_cs\textcolor{comment}{ !< Diag remapping control structure}
152 
153   \textcolor{keywordflow}{if} (\textcolor{keyword}{allocated}(remap\_cs%h)) \textcolor{keyword}{deallocate}(remap\_cs%h)
154   remap\_cs%configured = .false.
155   remap\_cs%initialized = .false.
156   remap\_cs%used = .false.
157   remap\_cs%nz = 0
158 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diag__remap_aaaa62e290958a9364ffd3d73825ce3f2}\label{namespacemom__diag__remap_aaaa62e290958a9364ffd3d73825ce3f2}} 
\index{mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}!diag\+\_\+remap\+\_\+get\+\_\+axes\+\_\+info@{diag\+\_\+remap\+\_\+get\+\_\+axes\+\_\+info}}
\index{diag\+\_\+remap\+\_\+get\+\_\+axes\+\_\+info@{diag\+\_\+remap\+\_\+get\+\_\+axes\+\_\+info}!mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}}
\subsubsection{\texorpdfstring{diag\+\_\+remap\+\_\+get\+\_\+axes\+\_\+info()}{diag\_remap\_get\_axes\_info()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diag\+\_\+remap\+::diag\+\_\+remap\+\_\+get\+\_\+axes\+\_\+info (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__diag__remap_1_1diag__remap__ctrl}{diag\+\_\+remap\+\_\+ctrl}), intent(in)}]{remap\+\_\+cs,  }\item[{integer, intent(out)}]{nz,  }\item[{integer, intent(out)}]{id\+\_\+layer,  }\item[{integer, intent(out)}]{id\+\_\+interface }\end{DoxyParamCaption})}



Get layer and interface axes ids for this coordinate Needed when defining axes groups. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em remap\+\_\+cs} & Diagnostic coordinate control structure\\
\hline
\mbox{\tt out}  & {\em nz} & Number of vertical levels for the coordinate\\
\hline
\mbox{\tt out}  & {\em id\+\_\+layer} & 1\+D-\/axes id for layer points\\
\hline
\mbox{\tt out}  & {\em id\+\_\+interface} & 1\+D-\/axes id for interface points \\
\hline
\end{DoxyParams}


Definition at line 247 of file M\+O\+M\+\_\+diag\+\_\+remap.\+F90.


\begin{DoxyCode}
247   \textcolor{keywordtype}{type}(diag\_remap\_ctrl), \textcolor{keywordtype}{intent(in)} :: remap\_cs\textcolor{comment}{ !< Diagnostic coordinate control structure}
248   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(out)} :: nz\textcolor{comment}{ !< Number of vertical levels for the coordinate}
249   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(out)} :: id\_layer\textcolor{comment}{ !< 1D-axes id for layer points}
250   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(out)} :: id\_interface\textcolor{comment}{ !< 1D-axes id for interface points}
251 
252   nz = remap\_cs%nz
253   id\_layer = remap\_cs%layer\_axes\_id
254   id\_interface = remap\_cs%interface\_axes\_id
255 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diag__remap_a3a3c0c9aaae22cbd2390eb42feafd622}\label{namespacemom__diag__remap_a3a3c0c9aaae22cbd2390eb42feafd622}} 
\index{mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}!diag\+\_\+remap\+\_\+init@{diag\+\_\+remap\+\_\+init}}
\index{diag\+\_\+remap\+\_\+init@{diag\+\_\+remap\+\_\+init}!mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}}
\subsubsection{\texorpdfstring{diag\+\_\+remap\+\_\+init()}{diag\_remap\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diag\+\_\+remap\+::diag\+\_\+remap\+\_\+init (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__diag__remap_1_1diag__remap__ctrl}{diag\+\_\+remap\+\_\+ctrl}), intent(inout)}]{remap\+\_\+cs,  }\item[{character(len=$\ast$), intent(in)}]{coord\+\_\+tuple,  }\item[{logical, intent(in)}]{answers\+\_\+2018 }\end{DoxyParamCaption})}



Initialize a diagnostic remapping type with the given vertical coordinate. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em remap\+\_\+cs} & Diag remapping control structure\\
\hline
\mbox{\tt in}  & {\em coord\+\_\+tuple} & A string in form of M\+O\+D\+U\+L\+E\+\_\+\+S\+U\+F\+F\+IX P\+A\+R\+A\+M\+E\+T\+E\+R\+\_\+\+S\+U\+F\+F\+IX C\+O\+O\+R\+D\+I\+N\+A\+T\+E\+\_\+\+N\+A\+ME\\
\hline
\mbox{\tt in}  & {\em answers\+\_\+2018} & If true, use the order of arithmetic and expressions for remapping that recover the answers from the end of 2018. Otherwise, use more robust forms of the same expressions. \\
\hline
\end{DoxyParams}


Definition at line 129 of file M\+O\+M\+\_\+diag\+\_\+remap.\+F90.


\begin{DoxyCode}
129   \textcolor{keywordtype}{type}(diag\_remap\_ctrl), \textcolor{keywordtype}{intent(inout)} :: remap\_cs\textcolor{comment}{ !< Diag remapping control structure}
130   \textcolor{keywordtype}{character(len=*)},      \textcolor{keywordtype}{intent(in)}    :: coord\_tuple\textcolor{comment}{ !< A string in form of}
131 \textcolor{comment}{                                                      !! MODULE\_SUFFIX PARAMETER\_SUFFIX COORDINATE\_NAME}
132   \textcolor{keywordtype}{logical},               \textcolor{keywordtype}{intent(in)}    :: answers\_2018\textcolor{comment}{ !< If true, use the order of arithmetic and
       expressions}
133 \textcolor{comment}{                                                      !! for remapping that recover the answers from the
       end of 2018.}
134 \textcolor{comment}{                                                      !! Otherwise, use more robust forms of the same
       expressions.}
135 
136   remap\_cs%diag\_module\_suffix = trim(extractword(coord\_tuple, 1))
137   remap\_cs%diag\_coord\_name = trim(extractword(coord\_tuple, 2))
138   remap\_cs%vertical\_coord\_name = trim(extractword(coord\_tuple, 3))
139   remap\_cs%vertical\_coord = coordinatemode(remap\_cs%vertical\_coord\_name)
140   remap\_cs%configured = .false.
141   remap\_cs%initialized = .false.
142   remap\_cs%used = .false.
143   remap\_cs%answers\_2018 = answers\_2018
144   remap\_cs%nz = 0
145 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diag__remap_ab530334ce02c1bedad08ba84507ee5d1}\label{namespacemom__diag__remap_ab530334ce02c1bedad08ba84507ee5d1}} 
\index{mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}!diag\+\_\+remap\+\_\+set\+\_\+active@{diag\+\_\+remap\+\_\+set\+\_\+active}}
\index{diag\+\_\+remap\+\_\+set\+\_\+active@{diag\+\_\+remap\+\_\+set\+\_\+active}!mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}}
\subsubsection{\texorpdfstring{diag\+\_\+remap\+\_\+set\+\_\+active()}{diag\_remap\_set\_active()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diag\+\_\+remap\+::diag\+\_\+remap\+\_\+set\+\_\+active (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__diag__remap_1_1diag__remap__ctrl}{diag\+\_\+remap\+\_\+ctrl}), intent(inout)}]{remap\+\_\+cs }\end{DoxyParamCaption})}



Indicate that this remapping type is actually used by the diag manager. If this is never called then the type will be disabled to save time. See further explanation with diag\+\_\+remap\+\_\+registration\+\_\+closed. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em remap\+\_\+cs} & Diag remapping control structure \\
\hline
\end{DoxyParams}


Definition at line 179 of file M\+O\+M\+\_\+diag\+\_\+remap.\+F90.


\begin{DoxyCode}
179   \textcolor{keywordtype}{type}(diag\_remap\_ctrl), \textcolor{keywordtype}{intent(inout)} :: remap\_cs\textcolor{comment}{ !< Diag remapping control structure}
180 
181   remap\_cs%used = .true.
182 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diag__remap_aaa0a887dc724438845e88598d439b20a}\label{namespacemom__diag__remap_aaa0a887dc724438845e88598d439b20a}} 
\index{mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}!diag\+\_\+remap\+\_\+update@{diag\+\_\+remap\+\_\+update}}
\index{diag\+\_\+remap\+\_\+update@{diag\+\_\+remap\+\_\+update}!mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}}
\subsubsection{\texorpdfstring{diag\+\_\+remap\+\_\+update()}{diag\_remap\_update()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diag\+\_\+remap\+::diag\+\_\+remap\+\_\+update (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__diag__remap_1_1diag__remap__ctrl}{diag\+\_\+remap\+\_\+ctrl}), intent(inout)}]{remap\+\_\+cs,  }\item[{type(ocean\+\_\+grid\+\_\+type), pointer}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, dimension(\+:,\+:,\+:), intent(in)}]{h,  }\item[{real, dimension(\+:,\+:,\+:), intent(in)}]{T,  }\item[{real, dimension(\+:,\+:,\+:), intent(in)}]{S,  }\item[{type(eos\+\_\+type), pointer}]{eqn\+\_\+of\+\_\+state,  }\item[{real, dimension(\+:,\+:,\+:), intent(inout)}]{h\+\_\+target }\end{DoxyParamCaption})}



Build/update target vertical grids for diagnostic remapping. 

\begin{DoxyNote}{Note}
The target grids need to be updated whenever sea surface height or layer thicknesses changes. In the case of density-\/based coordinates then technically we should also regenerate the target grid whenever T/S change.
\end{DoxyNote}

\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em remap\+\_\+cs} & Diagnostic coordinate control structure\\
\hline
 & {\em g} & The ocean\textquotesingle{}s grid type\\
\hline
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em h} & New thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em t} & New temperatures \mbox{[}degC\mbox{]}\\
\hline
\mbox{\tt in}  & {\em s} & New salinities \mbox{[}ppt\mbox{]}\\
\hline
 & {\em eqn\+\_\+of\+\_\+state} & A pointer to the equation of state\\
\hline
\mbox{\tt in,out}  & {\em h\+\_\+target} & The new diagnostic thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 276 of file M\+O\+M\+\_\+diag\+\_\+remap.\+F90.


\begin{DoxyCode}
276   \textcolor{keywordtype}{type}(diag\_remap\_ctrl),   \textcolor{keywordtype}{intent(inout)} :: remap\_cs\textcolor{comment}{ !< Diagnostic coordinate control structure}
277   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{pointer}    :: g\textcolor{comment}{  !< The ocean's grid type}
278   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)} :: gv\textcolor{comment}{ !< ocean vertical grid structure}
279   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)} :: us\textcolor{comment}{ !< A dimensional unit scaling type}
280   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)},  \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{  !< New thickness [H ~> m or kg m-2]}
281   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)},  \textcolor{keywordtype}{intent(in)} :: t\textcolor{comment}{  !< New temperatures [degC]}
282   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)},  \textcolor{keywordtype}{intent(in)} :: s\textcolor{comment}{  !< New salinities [ppt]}
283   \textcolor{keywordtype}{type}(eos\_type),          \textcolor{keywordtype}{pointer}    :: eqn\_of\_state\textcolor{comment}{ !< A pointer to the equation of state}
284   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)},  \textcolor{keywordtype}{intent(inout)} :: h\_target\textcolor{comment}{  !< The new diagnostic thicknesses [H ~> m or kg m-2]}
285 
286   \textcolor{comment}{! Local variables}
287   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(remap\_cs%nz + 1)} :: zinterfaces \textcolor{comment}{! Interface positions [H ~> m or kg m-2]}
288   \textcolor{keywordtype}{real} :: h\_neglect, h\_neglect\_edge \textcolor{comment}{! Negligible thicknesses [H ~> m or kg m-2]}
289   \textcolor{keywordtype}{integer} :: i, j, k, nz
290 
291   \textcolor{comment}{! Note that coordinateMode('LAYER') is never 'configured' so will}
292   \textcolor{comment}{! always return here.}
293   \textcolor{keywordflow}{if} (.not. remap\_cs%configured) \textcolor{keywordflow}{then}
294     \textcolor{keywordflow}{return}
295 \textcolor{keywordflow}{  endif}
296 
297   \textcolor{keywordflow}{if} (.not.remap\_cs%answers\_2018) \textcolor{keywordflow}{then}
298     h\_neglect = gv%H\_subroundoff ; h\_neglect\_edge = gv%H\_subroundoff
299   \textcolor{keywordflow}{elseif} (gv%Boussinesq) \textcolor{keywordflow}{then}
300     h\_neglect = gv%m\_to\_H*1.0e-30 ; h\_neglect\_edge = gv%m\_to\_H*1.0e-10
301   \textcolor{keywordflow}{else}
302     h\_neglect = gv%kg\_m2\_to\_H*1.0e-30 ; h\_neglect\_edge = gv%kg\_m2\_to\_H*1.0e-10
303 \textcolor{keywordflow}{  endif}
304   nz = remap\_cs%nz
305 
306   \textcolor{keywordflow}{if} (.not. remap\_cs%initialized) \textcolor{keywordflow}{then}
307     \textcolor{comment}{! Initialize remapping and regridding on the first call}
308     \textcolor{keyword}{call }initialize\_remapping(remap\_cs%remap\_cs, \textcolor{stringliteral}{'PPM\_IH4'}, boundary\_extrapolation=.false., &
309                               answers\_2018=remap\_cs%answers\_2018)
310     remap\_cs%initialized = .true.
311 \textcolor{keywordflow}{  endif}
312 
313   \textcolor{comment}{! Calculate remapping thicknesses for different target grids based on}
314   \textcolor{comment}{! nominal/target interface locations. This happens for every call on the}
315   \textcolor{comment}{! assumption that h, T, S has changed.}
316   \textcolor{keywordflow}{do} j=g%jsc-1, g%jec+1 ; \textcolor{keywordflow}{do} i=g%isc-1, g%iec+1
317     \textcolor{keywordflow}{if} (g%mask2dT(i,j)==0.) \textcolor{keywordflow}{then}
318       h\_target(i,j,:) = 0.
319       cycle
320 \textcolor{keywordflow}{    endif}
321 
322     \textcolor{keywordflow}{if} (remap\_cs%vertical\_coord == coordinatemode(\textcolor{stringliteral}{'ZSTAR'})) \textcolor{keywordflow}{then}
323       \textcolor{keyword}{call }build\_zstar\_column(get\_zlike\_cs(remap\_cs%regrid\_cs), &
324                               gv%Z\_to\_H*g%bathyT(i,j), sum(h(i,j,:)), &
325                               zinterfaces, zscale=gv%Z\_to\_H)
326     \textcolor{keywordflow}{elseif} (remap\_cs%vertical\_coord == coordinatemode(\textcolor{stringliteral}{'SIGMA'})) \textcolor{keywordflow}{then}
327       \textcolor{keyword}{call }build\_sigma\_column(get\_sigma\_cs(remap\_cs%regrid\_cs), &
328                               gv%Z\_to\_H*g%bathyT(i,j), sum(h(i,j,:)), zinterfaces)
329     \textcolor{keywordflow}{elseif} (remap\_cs%vertical\_coord == coordinatemode(\textcolor{stringliteral}{'RHO'})) \textcolor{keywordflow}{then}
330       \textcolor{keyword}{call }build\_rho\_column(get\_rho\_cs(remap\_cs%regrid\_cs), g%ke, &
331                             gv%Z\_to\_H*g%bathyT(i,j), h(i,j,:), t(i,j,:), s(i,j,:), &
332                             eqn\_of\_state, zinterfaces, h\_neglect, h\_neglect\_edge)
333     \textcolor{keywordflow}{elseif} (remap\_cs%vertical\_coord == coordinatemode(\textcolor{stringliteral}{'SLIGHT'})) \textcolor{keywordflow}{then}
334 \textcolor{comment}{!     call build\_slight\_column(remap\_cs%regrid\_cs,remap\_cs%remap\_cs, nz, &}
335 \textcolor{comment}{!                           GV%Z\_to\_H*G%bathyT(i,j), sum(h(i,j,:)), zInterfaces)}
336       \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"diag\_remap\_update: SLIGHT coordinate not coded for diagnostics yet!"})
337     \textcolor{keywordflow}{elseif} (remap\_cs%vertical\_coord == coordinatemode(\textcolor{stringliteral}{'HYCOM1'})) \textcolor{keywordflow}{then}
338 \textcolor{comment}{!     call build\_hycom1\_column(remap\_cs%regrid\_cs, nz, &}
339 \textcolor{comment}{!                           GV%Z\_to\_H*G%bathyT(i,j), sum(h(i,j,:)), zInterfaces)}
340       \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"diag\_remap\_update: HYCOM1 coordinate not coded for diagnostics yet!"})
341 \textcolor{keywordflow}{    endif}
342     \textcolor{keywordflow}{do} k = 1,nz
343       h\_target(i,j,k) = zinterfaces(k) - zinterfaces(k+1)
344 \textcolor{keywordflow}{    enddo}
345 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
346 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diag__remap_ae649e9dc9616184266d542bce5d9a452}\label{namespacemom__diag__remap_ae649e9dc9616184266d542bce5d9a452}} 
\index{mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}!horizontally\+\_\+average\+\_\+diag\+\_\+field@{horizontally\+\_\+average\+\_\+diag\+\_\+field}}
\index{horizontally\+\_\+average\+\_\+diag\+\_\+field@{horizontally\+\_\+average\+\_\+diag\+\_\+field}!mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}}
\subsubsection{\texorpdfstring{horizontally\+\_\+average\+\_\+diag\+\_\+field()}{horizontally\_average\_diag\_field()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diag\+\_\+remap\+::horizontally\+\_\+average\+\_\+diag\+\_\+field (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension(\+:,\+:,\+:), intent(in)}]{h,  }\item[{logical, intent(in)}]{staggered\+\_\+in\+\_\+x,  }\item[{logical, intent(in)}]{staggered\+\_\+in\+\_\+y,  }\item[{logical, intent(in)}]{is\+\_\+layer,  }\item[{logical, intent(in)}]{is\+\_\+extensive,  }\item[{real, dimension(\+:,\+:,\+:), intent(in)}]{field,  }\item[{real, dimension(\+:), intent(inout)}]{averaged\+\_\+field,  }\item[{logical, dimension(\+:), intent(inout)}]{averaged\+\_\+mask }\end{DoxyParamCaption})}



Horizontally average field. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em h} & The current thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em staggered\+\_\+in\+\_\+x} & True if the x-\/axis location is at u or q points\\
\hline
\mbox{\tt in}  & {\em staggered\+\_\+in\+\_\+y} & True if the y-\/axis location is at v or q points\\
\hline
\mbox{\tt in}  & {\em is\+\_\+layer} & True if the z-\/axis location is at h points\\
\hline
\mbox{\tt in}  & {\em is\+\_\+extensive} & True if the z-\/direction is spatially integrated (over layers)\\
\hline
\mbox{\tt in}  & {\em field} & The diagnostic field to be remapped \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em averaged\+\_\+field} & Field argument horizontally averaged \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em averaged\+\_\+mask} & Mask for horizontally averaged field \mbox{[}nondim\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 656 of file M\+O\+M\+\_\+diag\+\_\+remap.\+F90.


\begin{DoxyCode}
656   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{ !< Ocean grid structure}
657   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)} :: gv\textcolor{comment}{ !< The ocean vertical grid structure}
658   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{ !< The current thicknesses [H ~> m or kg m-2]}
659   \textcolor{keywordtype}{logical},                \textcolor{keywordtype}{intent(in)} :: staggered\_in\_x\textcolor{comment}{ !< True if the x-axis location is at u or q points}
660   \textcolor{keywordtype}{logical},                \textcolor{keywordtype}{intent(in)} :: staggered\_in\_y\textcolor{comment}{ !< True if the y-axis location is at v or q points}
661   \textcolor{keywordtype}{logical},                \textcolor{keywordtype}{intent(in)} :: is\_layer\textcolor{comment}{ !< True if the z-axis location is at h points}
662   \textcolor{keywordtype}{logical},                \textcolor{keywordtype}{intent(in)} :: is\_extensive\textcolor{comment}{ !< True if the z-direction is spatially integrated
       (over layers)}
663   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{intent(in)} :: field\textcolor{comment}{ !<  The diagnostic field to be remapped [A]}
664   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)},  \textcolor{keywordtype}{intent(inout)} :: averaged\_field\textcolor{comment}{ !< Field argument horizontally averaged [A]}
665   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(inout)} :: averaged\_mask\textcolor{comment}{  !< Mask for horizontally averaged field [nondim]}
666 
667   \textcolor{comment}{! Local variables}
668   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(G%isc:G%iec, G%jsc:G%jec, size(field,3))} :: volume, stuff
669   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(size(field, 3))} :: vol\_sum, stuff\_sum \textcolor{comment}{! nz+1 is needed for interface averages}
670   \textcolor{keywordtype}{type}(efp\_type), \textcolor{keywordtype}{dimension(2*size(field,3))} :: sums\_efp \textcolor{comment}{! Sums of volume or stuff by layer}
671   \textcolor{keywordtype}{real} :: height  \textcolor{comment}{! An average thickness attributed to an velocity point [H ~> m or kg m-2]}
672   \textcolor{keywordtype}{integer} :: i, j, k, nz
673   \textcolor{keywordtype}{integer} :: i1, j1\textcolor{comment}{                 !< 1-based index}
674 
675   nz = \textcolor{keyword}{size}(field, 3)
676 
677   \textcolor{comment}{! TODO: These averages could potentially be modified to use the function in}
678   \textcolor{comment}{!       the MOM\_spatial\_means module.}
679   \textcolor{comment}{! NOTE: Reproducible sums must be computed in the original MKS units}
680 
681   \textcolor{keywordflow}{if} (staggered\_in\_x .and. .not. staggered\_in\_y) \textcolor{keywordflow}{then}
682     \textcolor{keywordflow}{if} (is\_layer) \textcolor{keywordflow}{then}
683       \textcolor{comment}{! U-points}
684       \textcolor{keywordflow}{do} k=1,nz
685         vol\_sum(k) = 0.
686         stuff\_sum(k) = 0.
687         \textcolor{keywordflow}{if} (is\_extensive) \textcolor{keywordflow}{then}
688           \textcolor{keywordflow}{do} j=g%jsc, g%jec ; \textcolor{keywordflow}{do} i=g%isc, g%iec
689             i1 = i - g%isdB + 1
690             volume(i,j,k) = (g%US%L\_to\_m**2 * g%areaCu(i,j)) * g%mask2dCu(i,j)
691             stuff(i,j,k) = volume(i,j,k) * field(i1,j,k)
692 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
693         \textcolor{keywordflow}{else} \textcolor{comment}{! Intensive}
694           \textcolor{keywordflow}{do} j=g%jsc, g%jec ; \textcolor{keywordflow}{do} i=g%isc, g%iec
695             i1 = i - g%isdB + 1
696             height = 0.5 * (h(i,j,k) + h(i+1,j,k))
697             volume(i,j,k) = (g%US%L\_to\_m**2 * g%areaCu(i,j)) &
698                 * (gv%H\_to\_m * height) * g%mask2dCu(i,j)
699             stuff(i,j,k) = volume(i,j,k) * field(i1,j,k)
700 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
701 \textcolor{keywordflow}{        endif}
702 \textcolor{keywordflow}{      enddo}
703     \textcolor{keywordflow}{else} \textcolor{comment}{! Interface}
704       \textcolor{keywordflow}{do} k=1,nz
705         \textcolor{keywordflow}{do} j=g%jsc, g%jec ; \textcolor{keywordflow}{do} i=g%isc, g%iec
706           i1 = i - g%isdB + 1
707           volume(i,j,k) = (g%US%L\_to\_m**2 * g%areaCu(i,j)) * g%mask2dCu(i,j)
708           stuff(i,j,k) = volume(i,j,k) * field(i1,j,k)
709 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
710 \textcolor{keywordflow}{      enddo}
711 \textcolor{keywordflow}{    endif}
712   \textcolor{keywordflow}{elseif} (staggered\_in\_y .and. .not. staggered\_in\_x) \textcolor{keywordflow}{then}
713     \textcolor{keywordflow}{if} (is\_layer) \textcolor{keywordflow}{then}
714       \textcolor{comment}{! V-points}
715       \textcolor{keywordflow}{do} k=1,nz
716         \textcolor{keywordflow}{if} (is\_extensive) \textcolor{keywordflow}{then}
717           \textcolor{keywordflow}{do} j=g%jsc, g%jec ; \textcolor{keywordflow}{do} i=g%isc, g%iec
718             j1 = j - g%jsdB + 1
719             volume(i,j,k) = (g%US%L\_to\_m**2 * g%areaCv(i,j)) * g%mask2dCv(i,j)
720             stuff(i,j,k) = volume(i,j,k) * field(i,j1,k)
721 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
722         \textcolor{keywordflow}{else} \textcolor{comment}{! Intensive}
723           \textcolor{keywordflow}{do} j=g%jsc, g%jec ; \textcolor{keywordflow}{do} i=g%isc, g%iec
724             j1 = j - g%jsdB + 1
725             height = 0.5 * (h(i,j,k) + h(i,j+1,k))
726             volume(i,j,k) = (g%US%L\_to\_m**2 * g%areaCv(i,j)) &
727                 * (gv%H\_to\_m * height) * g%mask2dCv(i,j)
728             stuff(i,j,k) = volume(i,j,k) * field(i,j1,k)
729 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
730 \textcolor{keywordflow}{        endif}
731 \textcolor{keywordflow}{      enddo}
732     \textcolor{keywordflow}{else} \textcolor{comment}{! Interface}
733       \textcolor{keywordflow}{do} k=1,nz
734         \textcolor{keywordflow}{do} j=g%jsc, g%jec ; \textcolor{keywordflow}{do} i=g%isc, g%iec
735           j1 = j - g%jsdB + 1
736           volume(i,j,k) = (g%US%L\_to\_m**2 * g%areaCv(i,j)) * g%mask2dCv(i,j)
737           stuff(i,j,k) = volume(i,j,k) * field(i,j1,k)
738 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
739 \textcolor{keywordflow}{      enddo}
740 \textcolor{keywordflow}{    endif}
741   \textcolor{keywordflow}{elseif} ((.not. staggered\_in\_x) .and. (.not. staggered\_in\_y)) \textcolor{keywordflow}{then}
742     \textcolor{keywordflow}{if} (is\_layer) \textcolor{keywordflow}{then}
743       \textcolor{comment}{! H-points}
744       \textcolor{keywordflow}{do} k=1,nz
745         \textcolor{keywordflow}{if} (is\_extensive) \textcolor{keywordflow}{then}
746           \textcolor{keywordflow}{do} j=g%jsc, g%jec ; \textcolor{keywordflow}{do} i=g%isc, g%iec
747             \textcolor{keywordflow}{if} (h(i,j,k) > 0.) \textcolor{keywordflow}{then}
748               volume(i,j,k) = (g%US%L\_to\_m**2 * g%areaT(i,j)) * g%mask2dT(i,j)
749               stuff(i,j,k) = volume(i,j,k) * field(i,j,k)
750             \textcolor{keywordflow}{else}
751               volume(i,j,k) = 0.
752               stuff(i,j,k) = 0.
753 \textcolor{keywordflow}{            endif}
754 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
755         \textcolor{keywordflow}{else} \textcolor{comment}{! Intensive}
756           \textcolor{keywordflow}{do} j=g%jsc, g%jec ; \textcolor{keywordflow}{do} i=g%isc, g%iec
757             volume(i,j,k) = (g%US%L\_to\_m**2 * g%areaT(i,j)) &
758                 * (gv%H\_to\_m * h(i,j,k)) * g%mask2dT(i,j)
759             stuff(i,j,k) = volume(i,j,k) * field(i,j,k)
760 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo}
761 \textcolor{keywordflow}{        endif}
762 \textcolor{keywordflow}{      enddo}
763     \textcolor{keywordflow}{else} \textcolor{comment}{! Interface}
764       \textcolor{keywordflow}{do} k=1,nz
765         \textcolor{keywordflow}{do} j=g%jsc, g%jec ; \textcolor{keywordflow}{do} i=g%isc, g%iec
766           volume(i,j,k) = (g%US%L\_to\_m**2 * g%areaT(i,j)) * g%mask2dT(i,j)
767           stuff(i,j,k) = volume(i,j,k) * field(i,j,k)
768 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
769 \textcolor{keywordflow}{      enddo}
770 \textcolor{keywordflow}{    endif}
771   \textcolor{keywordflow}{else}
772     \textcolor{keyword}{call }assert(.false., \textcolor{stringliteral}{'horizontally\_average\_diag\_field: Q point averaging is not coded yet.'})
773 \textcolor{keywordflow}{  endif}
774 
775   \textcolor{comment}{! Packing the sums into a single array with a single call to sum across PEs saves reduces}
776   \textcolor{comment}{! the costs of communication.}
777   \textcolor{keywordflow}{do} k=1,nz
778     sums\_efp(2*k-1) = reproducing\_sum\_efp(volume(:,:,k), only\_on\_pe=.true.)
779     sums\_efp(2*k)   = reproducing\_sum\_efp(stuff(:,:,k), only\_on\_pe=.true.)
780 \textcolor{keywordflow}{  enddo}
781   \textcolor{keyword}{call }efp\_sum\_across\_pes(sums\_efp, 2*nz)
782   \textcolor{keywordflow}{do} k=1,nz
783     vol\_sum(k) = efp\_to\_real(sums\_efp(2*k-1))
784     stuff\_sum(k) = efp\_to\_real(sums\_efp(2*k))
785 \textcolor{keywordflow}{  enddo}
786 
787   averaged\_mask(:) = .true.
788   \textcolor{keywordflow}{do} k=1,nz
789     \textcolor{keywordflow}{if} (vol\_sum(k) > 0.) \textcolor{keywordflow}{then}
790       averaged\_field(k) = stuff\_sum(k) / vol\_sum(k)
791     \textcolor{keywordflow}{else}
792       averaged\_field(k) = 0.
793       averaged\_mask(k) = .false.
794 \textcolor{keywordflow}{    endif}
795 \textcolor{keywordflow}{  enddo}
796 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diag__remap_a058317602b134c09ff42005dfe8b2bc0}\label{namespacemom__diag__remap_a058317602b134c09ff42005dfe8b2bc0}} 
\index{mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}!vertically\+\_\+interpolate\+\_\+diag\+\_\+field@{vertically\+\_\+interpolate\+\_\+diag\+\_\+field}}
\index{vertically\+\_\+interpolate\+\_\+diag\+\_\+field@{vertically\+\_\+interpolate\+\_\+diag\+\_\+field}!mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}}
\subsubsection{\texorpdfstring{vertically\+\_\+interpolate\+\_\+diag\+\_\+field()}{vertically\_interpolate\_diag\_field()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diag\+\_\+remap\+::vertically\+\_\+interpolate\+\_\+diag\+\_\+field (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__diag__remap_1_1diag__remap__ctrl}{diag\+\_\+remap\+\_\+ctrl}), intent(in)}]{remap\+\_\+cs,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{real, dimension(\+:,\+:,\+:), intent(in)}]{h,  }\item[{logical, intent(in)}]{staggered\+\_\+in\+\_\+x,  }\item[{logical, intent(in)}]{staggered\+\_\+in\+\_\+y,  }\item[{real, dimension(\+:,\+:,\+:), pointer}]{mask,  }\item[{real, dimension(\+:,\+:,\+:), intent(in)}]{field,  }\item[{real, dimension(\+:,\+:,\+:), intent(inout)}]{interpolated\+\_\+field }\end{DoxyParamCaption})}



Vertically interpolate diagnostic field to alternative vertical grid. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em remap\+\_\+cs} & Diagnostic coodinate control structure\\
\hline
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em h} & The current thicknesses \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em staggered\+\_\+in\+\_\+x} & True is the x-\/axis location is at u or q points\\
\hline
\mbox{\tt in}  & {\em staggered\+\_\+in\+\_\+y} & True is the y-\/axis location is at v or q points\\
\hline
 & {\em mask} & A mask for the field \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt in}  & {\em field} & The diagnostic field to be remapped \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em interpolated\+\_\+field} & Field argument remapped to alternative coordinate \mbox{[}A\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 573 of file M\+O\+M\+\_\+diag\+\_\+remap.\+F90.


\begin{DoxyCode}
573   \textcolor{keywordtype}{type}(diag\_remap\_ctrl),  \textcolor{keywordtype}{intent(in)} :: remap\_cs\textcolor{comment}{ !< Diagnostic coodinate control structure}
574   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{   !< Ocean grid structure}
575   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{   !< The current thicknesses [H ~> m or kg m-2]}
576   \textcolor{keywordtype}{logical},                \textcolor{keywordtype}{intent(in)} :: staggered\_in\_x\textcolor{comment}{ !< True is the x-axis location is at u or q points}
577   \textcolor{keywordtype}{logical},                \textcolor{keywordtype}{intent(in)} :: staggered\_in\_y\textcolor{comment}{ !< True is the y-axis location is at v or q points}
578   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{pointer}    :: mask\textcolor{comment}{ !< A mask for the field [nondim]}
579   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{intent(in)} :: field\textcolor{comment}{ !<  The diagnostic field to be remapped [A]}
580   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{intent(inout)} :: interpolated\_field\textcolor{comment}{ !< Field argument remapped to alternative
       coordinate [A]}
581   \textcolor{comment}{! Local variables}
582   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(remap\_cs%nz)} :: h\_dest \textcolor{comment}{! Destination thicknesses [H ~> m or kg m-2]}
583   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(size(h,3))} :: h\_src    \textcolor{comment}{! A column of source thicknesses [H ~> m or kg m-2]}
584   \textcolor{keywordtype}{integer} :: nz\_src, nz\_dest
585   \textcolor{keywordtype}{integer} :: i, j, k\textcolor{comment}{                !< Grid index}
586   \textcolor{keywordtype}{integer} :: i1, j1\textcolor{comment}{                 !< 1-based index}
587   \textcolor{keywordtype}{integer} :: i\_lo, i\_hi, j\_lo, j\_hi\textcolor{comment}{ !< (uv->h) interpolation indices}
588   \textcolor{keywordtype}{integer} :: shift\textcolor{comment}{                  !< Symmetric offset for 1-based indexing}
589 
590   \textcolor{keyword}{call }assert(remap\_cs%initialized, \textcolor{stringliteral}{'vertically\_interpolate\_diag\_field: remap\_cs not initialized.'})
591   \textcolor{keyword}{call }assert(\textcolor{keyword}{size}(field, 3) == \textcolor{keyword}{size}(h, 3)+1, &
592               \textcolor{stringliteral}{'vertically\_interpolate\_diag\_field: Remap field and thickness z-axes do not match.'})
593 
594   interpolated\_field(:,:,:) = 0.
595 
596   nz\_src = \textcolor{keyword}{size}(h,3)
597   nz\_dest = remap\_cs%nz
598 
599   \textcolor{comment}{! Symmetric grid offset under 1-based indexing; see header for details.}
600   shift = 0; \textcolor{keywordflow}{if} (g%symmetric) shift = 1
601 
602   \textcolor{keywordflow}{if} (staggered\_in\_x .and. .not. staggered\_in\_y) \textcolor{keywordflow}{then}
603     \textcolor{comment}{! U-points}
604     \textcolor{keywordflow}{do} j=g%jsc, g%jec
605       \textcolor{keywordflow}{do} i=g%iscB, g%iecB
606         i1 = i - g%isdB + 1
607         i\_lo = i1 - shift; i\_hi = i\_lo + 1
608         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(mask)) \textcolor{keywordflow}{then}
609           \textcolor{keywordflow}{if} (mask(i,j,1) == 0.) cycle
610 \textcolor{keywordflow}{        endif}
611         h\_src(:) = 0.5 * (h(i\_lo,j,:) + h(i\_hi,j,:))
612         h\_dest(:) = 0.5 * (remap\_cs%h(i\_lo,j,:) + remap\_cs%h(i\_hi,j,:))
613         \textcolor{keyword}{call }interpolate\_column(nz\_src, h\_src, field(i1,j,:), &
614                                 nz\_dest, h\_dest, 0., interpolated\_field(i1,j,:))
615 \textcolor{keywordflow}{      enddo}
616 \textcolor{keywordflow}{    enddo}
617   \textcolor{keywordflow}{elseif} (staggered\_in\_y .and. .not. staggered\_in\_x) \textcolor{keywordflow}{then}
618     \textcolor{comment}{! V-points}
619     \textcolor{keywordflow}{do} j=g%jscB, g%jecB
620       j1 = j - g%jsdB + 1
621       j\_lo = j1 - shift; j\_hi = j\_lo + 1
622       \textcolor{keywordflow}{do} i=g%isc, g%iec
623         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(mask)) \textcolor{keywordflow}{then}
624           \textcolor{keywordflow}{if} (mask(i,j,1) == 0.) cycle
625 \textcolor{keywordflow}{        endif}
626         h\_src(:) = 0.5 * (h(i,j\_lo,:) + h(i,j\_hi,:))
627         h\_dest(:) = 0.5 * (remap\_cs%h(i,j\_lo,:) + remap\_cs%h(i,j\_hi,:))
628         \textcolor{keyword}{call }interpolate\_column(nz\_src, h\_src, field(i,j1,:), &
629                                 nz\_dest, h\_dest, 0., interpolated\_field(i,j1,:))
630 \textcolor{keywordflow}{      enddo}
631 \textcolor{keywordflow}{    enddo}
632   \textcolor{keywordflow}{elseif} ((.not. staggered\_in\_x) .and. (.not. staggered\_in\_y)) \textcolor{keywordflow}{then}
633     \textcolor{comment}{! H-points}
634     \textcolor{keywordflow}{do} j=g%jsc, g%jec
635       \textcolor{keywordflow}{do} i=g%isc, g%iec
636         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(mask)) \textcolor{keywordflow}{then}
637           \textcolor{keywordflow}{if} (mask(i,j,1) == 0.) cycle
638 \textcolor{keywordflow}{        endif}
639         h\_src(:) = h(i,j,:)
640         h\_dest(:) = remap\_cs%h(i,j,:)
641         \textcolor{keyword}{call }interpolate\_column(nz\_src, h\_src, field(i,j,:), &
642                                 nz\_dest, h\_dest, 0., interpolated\_field(i,j,:))
643 \textcolor{keywordflow}{      enddo}
644 \textcolor{keywordflow}{    enddo}
645   \textcolor{keywordflow}{else}
646     \textcolor{keyword}{call }assert(.false., \textcolor{stringliteral}{'vertically\_interpolate\_diag\_field: Q point remapping is not coded yet.'})
647 \textcolor{keywordflow}{  endif}
648 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__diag__remap_ae1d52582964ba4213e0fa9b7ea183c39}\label{namespacemom__diag__remap_ae1d52582964ba4213e0fa9b7ea183c39}} 
\index{mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}!vertically\+\_\+reintegrate\+\_\+diag\+\_\+field@{vertically\+\_\+reintegrate\+\_\+diag\+\_\+field}}
\index{vertically\+\_\+reintegrate\+\_\+diag\+\_\+field@{vertically\+\_\+reintegrate\+\_\+diag\+\_\+field}!mom\+\_\+diag\+\_\+remap@{mom\+\_\+diag\+\_\+remap}}
\subsubsection{\texorpdfstring{vertically\+\_\+reintegrate\+\_\+diag\+\_\+field()}{vertically\_reintegrate\_diag\_field()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+diag\+\_\+remap\+::vertically\+\_\+reintegrate\+\_\+diag\+\_\+field (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__diag__remap_1_1diag__remap__ctrl}{diag\+\_\+remap\+\_\+ctrl}), intent(in)}]{remap\+\_\+cs,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{real, dimension(\+:,\+:,\+:), intent(in)}]{h,  }\item[{real, dimension(\+:,\+:,\+:), intent(in)}]{h\+\_\+target,  }\item[{logical, intent(in)}]{staggered\+\_\+in\+\_\+x,  }\item[{logical, intent(in)}]{staggered\+\_\+in\+\_\+y,  }\item[{real, dimension(\+:,\+:,\+:), pointer}]{mask,  }\item[{real, dimension(\+:,\+:,\+:), intent(in)}]{field,  }\item[{real, dimension(\+:,\+:,\+:), intent(inout)}]{reintegrated\+\_\+field }\end{DoxyParamCaption})}



Vertically re-\/grid an already vertically-\/integrated diagnostic field to alternative vertical grid. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em remap\+\_\+cs} & Diagnostic coodinate control structure\\
\hline
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em h} & The thicknesses of the source grid \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em h\+\_\+target} & The thicknesses of the target grid \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em staggered\+\_\+in\+\_\+x} & True is the x-\/axis location is at u or q points\\
\hline
\mbox{\tt in}  & {\em staggered\+\_\+in\+\_\+y} & True is the y-\/axis location is at v or q points\\
\hline
 & {\em mask} & A mask for the field \mbox{[}nondim\mbox{]}\\
\hline
\mbox{\tt in}  & {\em field} & The diagnostic field to be remapped \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em reintegrated\+\_\+field} & Field argument remapped to alternative coordinate \mbox{[}A\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 492 of file M\+O\+M\+\_\+diag\+\_\+remap.\+F90.


\begin{DoxyCode}
492   \textcolor{keywordtype}{type}(diag\_remap\_ctrl),  \textcolor{keywordtype}{intent(in)} :: remap\_cs\textcolor{comment}{ !< Diagnostic coodinate control structure}
493   \textcolor{keywordtype}{type}(ocean\_grid\_type),  \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{        !< Ocean grid structure}
494   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{        !< The thicknesses of the source grid [H ~> m or kg m-2]}
495   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{intent(in)} :: h\_target\textcolor{comment}{ !< The thicknesses of the target grid [H ~> m or kg m-2]}
496   \textcolor{keywordtype}{logical},                \textcolor{keywordtype}{intent(in)} :: staggered\_in\_x\textcolor{comment}{ !< True is the x-axis location is at u or q points}
497   \textcolor{keywordtype}{logical},                \textcolor{keywordtype}{intent(in)} :: staggered\_in\_y\textcolor{comment}{ !< True is the y-axis location is at v or q points}
498   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{pointer}    :: mask\textcolor{comment}{     !< A mask for the field [nondim]}
499   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{intent(in)} :: field\textcolor{comment}{    !<  The diagnostic field to be remapped [A]}
500   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{intent(inout)} :: reintegrated\_field\textcolor{comment}{ !< Field argument remapped to alternative
       coordinate [A]}
501   \textcolor{comment}{! Local variables}
502   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(remap\_cs%nz)} :: h\_dest \textcolor{comment}{! Destination thicknesses [H ~> m or kg m-2]}
503   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(size(h,3))} :: h\_src    \textcolor{comment}{! A column of source thicknesses [H ~> m or kg m-2]}
504   \textcolor{keywordtype}{integer} :: nz\_src, nz\_dest
505   \textcolor{keywordtype}{integer} :: i, j, k\textcolor{comment}{                !< Grid index}
506   \textcolor{keywordtype}{integer} :: i1, j1\textcolor{comment}{                 !< 1-based index}
507   \textcolor{keywordtype}{integer} :: i\_lo, i\_hi, j\_lo, j\_hi\textcolor{comment}{ !< (uv->h) interpolation indices}
508   \textcolor{keywordtype}{integer} :: shift\textcolor{comment}{                  !< Symmetric offset for 1-based indexing}
509 
510   \textcolor{keyword}{call }assert(remap\_cs%initialized, \textcolor{stringliteral}{'vertically\_reintegrate\_diag\_field: remap\_cs not initialized.'})
511   \textcolor{keyword}{call }assert(\textcolor{keyword}{size}(field, 3) == \textcolor{keyword}{size}(h, 3), &
512               \textcolor{stringliteral}{'vertically\_reintegrate\_diag\_field: Remap field and thickness z-axes do not match.'})
513 
514   nz\_src = \textcolor{keyword}{size}(field,3)
515   nz\_dest = remap\_cs%nz
516   reintegrated\_field(:,:,:) = 0.
517 
518   \textcolor{comment}{! Symmetric grid offset under 1-based indexing; see header for details.}
519   shift = 0; \textcolor{keywordflow}{if} (g%symmetric) shift = 1
520 
521   \textcolor{keywordflow}{if} (staggered\_in\_x .and. .not. staggered\_in\_y) \textcolor{keywordflow}{then}
522     \textcolor{comment}{! U-points}
523     \textcolor{keywordflow}{do} j=g%jsc, g%jec
524       \textcolor{keywordflow}{do} i=g%iscB, g%iecB
525         i1 = i - g%isdB + 1
526         i\_lo = i1 - shift; i\_hi = i\_lo + 1
527         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(mask)) \textcolor{keywordflow}{then}
528           \textcolor{keywordflow}{if} (mask(i,j,1) == 0.) cycle
529 \textcolor{keywordflow}{        endif}
530         h\_src(:) = 0.5 * (h(i\_lo,j,:) + h(i\_hi,j,:))
531         h\_dest(:) = 0.5 * (h\_target(i\_lo,j,:) + h\_target(i\_hi,j,:))
532         \textcolor{keyword}{call }reintegrate\_column(nz\_src, h\_src, field(i1,j,:), &
533                                 nz\_dest, h\_dest, 0., reintegrated\_field(i1,j,:))
534 \textcolor{keywordflow}{      enddo}
535 \textcolor{keywordflow}{    enddo}
536   \textcolor{keywordflow}{elseif} (staggered\_in\_y .and. .not. staggered\_in\_x) \textcolor{keywordflow}{then}
537     \textcolor{comment}{! V-points}
538     \textcolor{keywordflow}{do} j=g%jscB, g%jecB
539       j1 = j - g%jsdB + 1
540       j\_lo = j1 - shift; j\_hi = j\_lo + 1
541       \textcolor{keywordflow}{do} i=g%isc, g%iec
542         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(mask)) \textcolor{keywordflow}{then}
543           \textcolor{keywordflow}{if} (mask(i,j,1) == 0.) cycle
544 \textcolor{keywordflow}{        endif}
545         h\_src(:) = 0.5 * (h(i,j\_lo,:) + h(i,j\_hi,:))
546         h\_dest(:) = 0.5 * (h\_target(i,j\_lo,:) + h\_target(i,j\_hi,:))
547         \textcolor{keyword}{call }reintegrate\_column(nz\_src, h\_src, field(i,j1,:), &
548                                 nz\_dest, h\_dest, 0., reintegrated\_field(i,j1,:))
549 \textcolor{keywordflow}{      enddo}
550 \textcolor{keywordflow}{    enddo}
551   \textcolor{keywordflow}{elseif} ((.not. staggered\_in\_x) .and. (.not. staggered\_in\_y)) \textcolor{keywordflow}{then}
552     \textcolor{comment}{! H-points}
553     \textcolor{keywordflow}{do} j=g%jsc, g%jec
554       \textcolor{keywordflow}{do} i=g%isc, g%iec
555         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(mask)) \textcolor{keywordflow}{then}
556           \textcolor{keywordflow}{if} (mask(i,j,1) == 0.) cycle
557 \textcolor{keywordflow}{        endif}
558         h\_src(:) = h(i,j,:)
559         h\_dest(:) = h\_target(i,j,:)
560         \textcolor{keyword}{call }reintegrate\_column(nz\_src, h\_src, field(i,j,:), &
561                                 nz\_dest, h\_dest, 0., reintegrated\_field(i,j,:))
562 \textcolor{keywordflow}{      enddo}
563 \textcolor{keywordflow}{    enddo}
564   \textcolor{keywordflow}{else}
565     \textcolor{keyword}{call }assert(.false., \textcolor{stringliteral}{'vertically\_reintegrate\_diag\_field: Q point remapping is not coded yet.'})
566 \textcolor{keywordflow}{  endif}
567 
\end{DoxyCode}
