\hypertarget{namespaceuser__change__diffusivity}{}\doxysection{user\+\_\+change\+\_\+diffusivity Module Reference}
\label{namespaceuser__change__diffusivity}\index{user\_change\_diffusivity@{user\_change\_diffusivity}}


\doxysubsection{Detailed Description}
Increments the diapycnal diffusivity in a specified band of latitudes and densities. \doxysubsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structuser__change__diffusivity_1_1user__change__diff__cs}{user\+\_\+change\+\_\+diff\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Control structure for \mbox{\hyperlink{namespaceuser__change__diffusivity}{user\+\_\+change\+\_\+diffusivity}}. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespaceuser__change__diffusivity_a5bb4d2c096aabd7a7f7a6159fd0db073}{user\+\_\+change\+\_\+diff}} (h, tv, G, GV, US, CS, Kd\+\_\+lay, Kd\+\_\+int, T\+\_\+f, S\+\_\+f, Kd\+\_\+int\+\_\+add)
\begin{DoxyCompactList}\small\item\em This subroutine provides an interface for a user to use to modify the main code to alter the diffusivities as needed. The specific example implemented here augments the diffusivity for a specified range of latitude and coordinate potential density. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespaceuser__change__diffusivity_a14ddfad060f517dcda132b2fd279181e}{range\+\_\+ok}} (range)
\begin{DoxyCompactList}\small\item\em This subroutine checks whether the 4 values of range are in ascending order. \end{DoxyCompactList}\item 
real function \mbox{\hyperlink{namespaceuser__change__diffusivity_a9b291c89fbc92f517c683b5fa2797e92}{val\+\_\+weights}} (val, range)
\begin{DoxyCompactList}\small\item\em This subroutine returns a value that goes smoothly from 0 to 1, stays at 1, and then goes smoothly back to 0 at the four values of range. The transitions are cubic, and have zero first derivatives where the curves hit 0 and 1. The values in range must be in ascending order, as can be checked by calling range\+\_\+\+OK. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespaceuser__change__diffusivity_ac852c6588286315c2bba0900114ce5a6}{user\+\_\+change\+\_\+diff\+\_\+init}} (Time, G, GV, US, param\+\_\+file, diag, CS)
\begin{DoxyCompactList}\small\item\em Set up the module control structure. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespaceuser__change__diffusivity_ad92d8d57a14b020dcff685bc1da32507}{user\+\_\+change\+\_\+diff\+\_\+end}} (CS)
\begin{DoxyCompactList}\small\item\em Clean up the module control structure. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespaceuser__change__diffusivity_a14ddfad060f517dcda132b2fd279181e}\label{namespaceuser__change__diffusivity_a14ddfad060f517dcda132b2fd279181e}} 
\index{user\_change\_diffusivity@{user\_change\_diffusivity}!range\_ok@{range\_ok}}
\index{range\_ok@{range\_ok}!user\_change\_diffusivity@{user\_change\_diffusivity}}
\doxysubsubsection{\texorpdfstring{range\_ok()}{range\_ok()}}
{\footnotesize\ttfamily logical function user\+\_\+change\+\_\+diffusivity\+::range\+\_\+ok (\begin{DoxyParamCaption}\item[{real, dimension(4), intent(in)}]{range }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine checks whether the 4 values of range are in ascending order. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em range} & Four values to check. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Return value. 
\end{DoxyReturn}


Definition at line 151 of file user\+\_\+change\+\_\+diffusivity.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{152 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(4)}, \textcolor{keywordtype}{intent(in)} :: range\textcolor{comment}{  !< Four values to check.}}
\DoxyCodeLine{153   \textcolor{keywordtype}{logical}                        :: OK\textcolor{comment}{     !< Return value.}}
\DoxyCodeLine{154 }
\DoxyCodeLine{155   ok = ((range(1) <= range(2)) .and. (range(2) <= range(3)) .and. \&}
\DoxyCodeLine{156         (range(3) <= range(4)))}
\DoxyCodeLine{157 }

\end{DoxyCode}
\mbox{\Hypertarget{namespaceuser__change__diffusivity_a5bb4d2c096aabd7a7f7a6159fd0db073}\label{namespaceuser__change__diffusivity_a5bb4d2c096aabd7a7f7a6159fd0db073}} 
\index{user\_change\_diffusivity@{user\_change\_diffusivity}!user\_change\_diff@{user\_change\_diff}}
\index{user\_change\_diff@{user\_change\_diff}!user\_change\_diffusivity@{user\_change\_diffusivity}}
\doxysubsubsection{\texorpdfstring{user\_change\_diff()}{user\_change\_diff()}}
{\footnotesize\ttfamily subroutine, public user\+\_\+change\+\_\+diffusivity\+::user\+\_\+change\+\_\+diff (\begin{DoxyParamCaption}\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed, g \%ke), intent(in)}]{h,  }\item[{type(\mbox{\hyperlink{structmom__variables_1_1thermo__var__ptrs}{thermo\+\_\+var\+\_\+ptrs}}), intent(in)}]{tv,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structuser__change__diffusivity_1_1user__change__diff__cs}{user\+\_\+change\+\_\+diff\+\_\+cs}}), pointer}]{CS,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout), optional}]{Kd\+\_\+lay,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)+1), intent(inout), optional}]{Kd\+\_\+int,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in), optional}]{T\+\_\+f,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in), optional}]{S\+\_\+f,  }\item[{real, dimension(\+:,\+:,\+:), optional, pointer}]{Kd\+\_\+int\+\_\+add }\end{DoxyParamCaption})}



This subroutine provides an interface for a user to use to modify the main code to alter the diffusivities as needed. The specific example implemented here augments the diffusivity for a specified range of latitude and coordinate potential density. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em tv} & A structure containing pointers to any available thermodynamic fields. Absent fields have N\+U\+LL ptrs. \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
 & {\em cs} & This module\textquotesingle{}s control structure. \\
\hline
\mbox{\texttt{ in,out}}  & {\em kd\+\_\+lay} & The diapycnal diffusivity of each layer \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in,out}}  & {\em kd\+\_\+int} & The diapycnal diffusivity at each interface \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em t\+\_\+f} & Temperature with massless layers filled in vertically \mbox{[}degC\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em s\+\_\+f} & Salinity with massless layers filled in vertically \mbox{[}ppt\mbox{]}. \\
\hline
 & {\em kd\+\_\+int\+\_\+add} & The diapycnal diffusivity that is being added at each interface \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}. \\
\hline
\end{DoxyParams}


Definition at line 47 of file user\+\_\+change\+\_\+diffusivity.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{48   \textcolor{keywordtype}{type}(ocean\_grid\_type),                    \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{   !< The ocean's grid structure.}}
\DoxyCodeLine{49   \textcolor{keywordtype}{type}(verticalGrid\_type),                  \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{  !< The ocean's vertical grid structure}}
\DoxyCodeLine{50 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{   !< Layer thickness [H \string~> m or kg m-\/2].}}
\DoxyCodeLine{51   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                    \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{  !< A structure containing pointers}}
\DoxyCodeLine{52 \textcolor{comment}{                                                                 !! to any available thermodynamic}}
\DoxyCodeLine{53 \textcolor{comment}{                                                                 !! fields. Absent fields have NULL ptrs.}}
\DoxyCodeLine{54   \textcolor{keywordtype}{type}(unit\_scale\_type),                    \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{  !< A dimensional unit scaling type}}
\DoxyCodeLine{55   \textcolor{keywordtype}{type}(user\_change\_diff\_CS),                \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{  !< This module's control structure.}}
\DoxyCodeLine{56 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: Kd\_lay\textcolor{comment}{ !< The diapycnal diffusivity of}}
\DoxyCodeLine{57 \textcolor{comment}{                                                                  !! each layer [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{58 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G)+1)}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(inout)} :: Kd\_int\textcolor{comment}{ !< The diapycnal diffusivity}}
\DoxyCodeLine{59 \textcolor{comment}{                                                                  !! at each interface [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{60 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: T\_f\textcolor{comment}{ !< Temperature with massless}}
\DoxyCodeLine{61 \textcolor{comment}{                                                                  !! layers filled in vertically [degC].}}
\DoxyCodeLine{62 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},   \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: S\_f\textcolor{comment}{ !< Salinity with massless}}
\DoxyCodeLine{63 \textcolor{comment}{                                                                  !! layers filled in vertically [ppt].}}
\DoxyCodeLine{64 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:,:)},                     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{pointer}       :: Kd\_int\_add\textcolor{comment}{ !< The diapycnal}}
\DoxyCodeLine{65 \textcolor{comment}{                                                                  !! diffusivity that is being added at}}
\DoxyCodeLine{66 \textcolor{comment}{                                                                  !! each interface [Z2 T-\/1 \string~> m2 s-\/1].}}
\DoxyCodeLine{67   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{68 \textcolor{keywordtype}{  real} :: Rcv(SZI\_(G),SZK\_(G)) \textcolor{comment}{! The coordinate density in layers [R \string~> kg m-\/3].}}
\DoxyCodeLine{69 \textcolor{keywordtype}{  real} :: p\_ref(SZI\_(G))       \textcolor{comment}{! An array of tv\%P\_Ref pressures [R L2 T-\/2 \string~> Pa].}}
\DoxyCodeLine{70 \textcolor{keywordtype}{  real} :: rho\_fn      \textcolor{comment}{! The density dependence of the input function, 0-\/1 [nondim].}}
\DoxyCodeLine{71 \textcolor{keywordtype}{  real} :: lat\_fn      \textcolor{comment}{! The latitude dependence of the input function, 0-\/1 [nondim].}}
\DoxyCodeLine{72   \textcolor{keywordtype}{logical} :: use\_EOS  \textcolor{comment}{! If true, density is calculated from T \& S using an}}
\DoxyCodeLine{73                       \textcolor{comment}{! equation of state.}}
\DoxyCodeLine{74   \textcolor{keywordtype}{logical} :: store\_Kd\_add  \textcolor{comment}{! Save the added diffusivity as a diagnostic if true.}}
\DoxyCodeLine{75   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(2)} :: EOSdom \textcolor{comment}{! The i-\/computational domain for the equation of state}}
\DoxyCodeLine{76   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz}
\DoxyCodeLine{77   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed}
\DoxyCodeLine{78 }
\DoxyCodeLine{79 \textcolor{keywordtype}{  real} :: kappa\_fill  \textcolor{comment}{! diffusivity used to fill massless layers}}
\DoxyCodeLine{80 \textcolor{keywordtype}{  real} :: dt\_fill     \textcolor{comment}{! timestep used to fill massless layers}}
\DoxyCodeLine{81   \textcolor{keywordtype}{character(len=200)} :: mesg}
\DoxyCodeLine{82 }
\DoxyCodeLine{83   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec ; nz = g\%ke}
\DoxyCodeLine{84   isd = g\%isd ; ied = g\%ied ; jsd = g\%jsd ; jed = g\%jed}
\DoxyCodeLine{85 }
\DoxyCodeLine{86   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"{}user\_set\_diffusivity: "{}}//\&}
\DoxyCodeLine{87          \textcolor{stringliteral}{"{}Module must be initialized before it is used."{}})}
\DoxyCodeLine{88 }
\DoxyCodeLine{89   use\_eos = \textcolor{keyword}{associated}(tv\%eqn\_of\_state)}
\DoxyCodeLine{90   \textcolor{keywordflow}{if} (.not.use\_eos) \textcolor{keywordflow}{return}}
\DoxyCodeLine{91   store\_kd\_add = .false.}
\DoxyCodeLine{92   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_int\_add)) store\_kd\_add = \textcolor{keyword}{associated}(kd\_int\_add)}
\DoxyCodeLine{93 }
\DoxyCodeLine{94   \textcolor{keywordflow}{if} (.not.range\_ok(cs\%lat\_range)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{95     \textcolor{keyword}{write}(mesg, \textcolor{stringliteral}{'(4(1pe15.6))'}) cs\%lat\_range(1:4)}
\DoxyCodeLine{96     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}user\_set\_diffusivity: bad latitude range: \(\backslash\)n  "{}}//\&}
\DoxyCodeLine{97                     trim(mesg))}
\DoxyCodeLine{98 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{99   \textcolor{keywordflow}{if} (.not.range\_ok(cs\%rho\_range)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{100     \textcolor{keyword}{write}(mesg, \textcolor{stringliteral}{'(4(1pe15.6))'}) cs\%rho\_range(1:4)}
\DoxyCodeLine{101     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}user\_set\_diffusivity: bad density range: \(\backslash\)n  "{}}//\&}
\DoxyCodeLine{102                     trim(mesg))}
\DoxyCodeLine{103 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{104 }
\DoxyCodeLine{105   \textcolor{keywordflow}{if} (store\_kd\_add) kd\_int\_add(:,:,:) = 0.0}
\DoxyCodeLine{106 }
\DoxyCodeLine{107   \textcolor{keywordflow}{do} i=is,ie ; p\_ref(i) = tv\%P\_Ref ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{108   eosdom(:) = eos\_domain(g\%HI)}
\DoxyCodeLine{109   \textcolor{keywordflow}{do} j=js,je}
\DoxyCodeLine{110     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(t\_f) .and. \textcolor{keyword}{present}(s\_f)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{111       \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{112         \textcolor{keyword}{call }calculate\_density(t\_f(:,j,k), s\_f(:,j,k), p\_ref, rcv(:,k), tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{113 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{114     \textcolor{keywordflow}{else}}
\DoxyCodeLine{115       \textcolor{keywordflow}{do} k=1,nz}
\DoxyCodeLine{116         \textcolor{keyword}{call }calculate\_density(tv\%T(:,j,k), tv\%S(:,j,k), p\_ref, rcv(:,k), tv\%eqn\_of\_state, eosdom)}
\DoxyCodeLine{117 \textcolor{keywordflow}{      enddo}}
\DoxyCodeLine{118 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{119 }
\DoxyCodeLine{120     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_lay)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{121       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{122         \textcolor{keywordflow}{if} (cs\%use\_abs\_lat) \textcolor{keywordflow}{then}}
\DoxyCodeLine{123           lat\_fn = val\_weights(abs(g\%geoLatT(i,j)), cs\%lat\_range)}
\DoxyCodeLine{124         \textcolor{keywordflow}{else}}
\DoxyCodeLine{125           lat\_fn = val\_weights(g\%geoLatT(i,j), cs\%lat\_range)}
\DoxyCodeLine{126 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{127         rho\_fn = val\_weights(rcv(i,k), cs\%rho\_range)}
\DoxyCodeLine{128         \textcolor{keywordflow}{if} (rho\_fn * lat\_fn > 0.0) \&}
\DoxyCodeLine{129           kd\_lay(i,j,k) = kd\_lay(i,j,k) + cs\%Kd\_add * rho\_fn * lat\_fn}
\DoxyCodeLine{130 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{131 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{132     \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(kd\_int)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{133       \textcolor{keywordflow}{do} k=2,nz ; \textcolor{keywordflow}{do} i=is,ie}
\DoxyCodeLine{134         \textcolor{keywordflow}{if} (cs\%use\_abs\_lat) \textcolor{keywordflow}{then}}
\DoxyCodeLine{135           lat\_fn = val\_weights(abs(g\%geoLatT(i,j)), cs\%lat\_range)}
\DoxyCodeLine{136         \textcolor{keywordflow}{else}}
\DoxyCodeLine{137           lat\_fn = val\_weights(g\%geoLatT(i,j), cs\%lat\_range)}
\DoxyCodeLine{138 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{139         rho\_fn = val\_weights( 0.5*(rcv(i,k-\/1) + rcv(i,k)), cs\%rho\_range)}
\DoxyCodeLine{140         \textcolor{keywordflow}{if} (rho\_fn * lat\_fn > 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{141           kd\_int(i,j,k) = kd\_int(i,j,k) + cs\%Kd\_add * rho\_fn * lat\_fn}
\DoxyCodeLine{142           \textcolor{keywordflow}{if} (store\_kd\_add) kd\_int\_add(i,j,k) = cs\%Kd\_add * rho\_fn * lat\_fn}
\DoxyCodeLine{143 \textcolor{keywordflow}{        endif}}
\DoxyCodeLine{144 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}}
\DoxyCodeLine{145 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{146 \textcolor{keywordflow}{  enddo}}
\DoxyCodeLine{147 }

\end{DoxyCode}
\mbox{\Hypertarget{namespaceuser__change__diffusivity_ad92d8d57a14b020dcff685bc1da32507}\label{namespaceuser__change__diffusivity_ad92d8d57a14b020dcff685bc1da32507}} 
\index{user\_change\_diffusivity@{user\_change\_diffusivity}!user\_change\_diff\_end@{user\_change\_diff\_end}}
\index{user\_change\_diff\_end@{user\_change\_diff\_end}!user\_change\_diffusivity@{user\_change\_diffusivity}}
\doxysubsubsection{\texorpdfstring{user\_change\_diff\_end()}{user\_change\_diff\_end()}}
{\footnotesize\ttfamily subroutine, public user\+\_\+change\+\_\+diffusivity\+::user\+\_\+change\+\_\+diff\+\_\+end (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structuser__change__diffusivity_1_1user__change__diff__cs}{user\+\_\+change\+\_\+diff\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Clean up the module control structure. 


\begin{DoxyParams}{Parameters}
{\em cs} & A pointer that is set to point to the control structure for this module. \\
\hline
\end{DoxyParams}


Definition at line 262 of file user\+\_\+change\+\_\+diffusivity.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{263   \textcolor{keywordtype}{type}(user\_change\_diff\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< A pointer that is set to point to the control}}
\DoxyCodeLine{264 \textcolor{comment}{                                           !! structure for this module.}}
\DoxyCodeLine{265 }
\DoxyCodeLine{266   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{deallocate}(cs)}
\DoxyCodeLine{267 }

\end{DoxyCode}
\mbox{\Hypertarget{namespaceuser__change__diffusivity_ac852c6588286315c2bba0900114ce5a6}\label{namespaceuser__change__diffusivity_ac852c6588286315c2bba0900114ce5a6}} 
\index{user\_change\_diffusivity@{user\_change\_diffusivity}!user\_change\_diff\_init@{user\_change\_diff\_init}}
\index{user\_change\_diff\_init@{user\_change\_diff\_init}!user\_change\_diffusivity@{user\_change\_diffusivity}}
\doxysubsubsection{\texorpdfstring{user\_change\_diff\_init()}{user\_change\_diff\_init()}}
{\footnotesize\ttfamily subroutine, public user\+\_\+change\+\_\+diffusivity\+::user\+\_\+change\+\_\+diff\+\_\+init (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in)}]{Time,  }\item[{type(\mbox{\hyperlink{structmom__grid_1_1ocean__grid__type}{ocean\+\_\+grid\+\_\+type}}), intent(in)}]{G,  }\item[{type(\mbox{\hyperlink{structmom__verticalgrid_1_1verticalgrid__type}{verticalgrid\+\_\+type}}), intent(in)}]{GV,  }\item[{type(\mbox{\hyperlink{structmom__unit__scaling_1_1unit__scale__type}{unit\+\_\+scale\+\_\+type}}), intent(in)}]{US,  }\item[{type(\mbox{\hyperlink{structmom__file__parser_1_1param__file__type}{param\+\_\+file\+\_\+type}}), intent(in)}]{param\+\_\+file,  }\item[{type(\mbox{\hyperlink{structmom__diag__mediator_1_1diag__ctrl}{diag\+\_\+ctrl}}), intent(inout), target}]{diag,  }\item[{type(\mbox{\hyperlink{structuser__change__diffusivity_1_1user__change__diff__cs}{user\+\_\+change\+\_\+diff\+\_\+cs}}), pointer}]{CS }\end{DoxyParamCaption})}



Set up the module control structure. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em time} & The current model time. \\
\hline
\mbox{\texttt{ in}}  & {\em g} & The ocean\textquotesingle{}s grid structure. \\
\hline
\mbox{\texttt{ in}}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure \\
\hline
\mbox{\texttt{ in}}  & {\em us} & A dimensional unit scaling type \\
\hline
\mbox{\texttt{ in}}  & {\em param\+\_\+file} & A structure indicating the open file to parse for model parameter values. \\
\hline
\mbox{\texttt{ in,out}}  & {\em diag} & A structure that is used to regulate diagnostic output. \\
\hline
 & {\em cs} & A pointer that is set to point to the control structure for this module. \\
\hline
\end{DoxyParams}


Definition at line 190 of file user\+\_\+change\+\_\+diffusivity.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{191   \textcolor{keywordtype}{type}(time\_type),           \textcolor{keywordtype}{intent(in)}    :: Time\textcolor{comment}{       !< The current model time.}}
\DoxyCodeLine{192   \textcolor{keywordtype}{type}(ocean\_grid\_type),     \textcolor{keywordtype}{intent(in)}    :: G\textcolor{comment}{          !< The ocean's grid structure.}}
\DoxyCodeLine{193   \textcolor{keywordtype}{type}(verticalGrid\_type),   \textcolor{keywordtype}{intent(in)}    :: GV\textcolor{comment}{         !< The ocean's vertical grid structure}}
\DoxyCodeLine{194   \textcolor{keywordtype}{type}(unit\_scale\_type),     \textcolor{keywordtype}{intent(in)}    :: US\textcolor{comment}{         !< A dimensional unit scaling type}}
\DoxyCodeLine{195   \textcolor{keywordtype}{type}(param\_file\_type),     \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< A structure indicating the}}
\DoxyCodeLine{196 \textcolor{comment}{                                                         !! open file to parse for}}
\DoxyCodeLine{197 \textcolor{comment}{                                                         !! model parameter values.}}
\DoxyCodeLine{198   \textcolor{keywordtype}{type}(diag\_ctrl), \textcolor{keywordtype}{target},   \textcolor{keywordtype}{intent(inout)} :: diag\textcolor{comment}{       !< A structure that is used to}}
\DoxyCodeLine{199 \textcolor{comment}{                                                         !! regulate diagnostic output.}}
\DoxyCodeLine{200   \textcolor{keywordtype}{type}(user\_change\_diff\_CS), \textcolor{keywordtype}{pointer}       :: CS\textcolor{comment}{         !< A pointer that is set to}}
\DoxyCodeLine{201 \textcolor{comment}{                                                         !! point to the control}}
\DoxyCodeLine{202 \textcolor{comment}{                                                         !! structure for this module.}}
\DoxyCodeLine{203 }
\DoxyCodeLine{204 \textcolor{comment}{! This include declares and sets the variable "{}version"{}.}}
\DoxyCodeLine{205 \textcolor{preprocessor}{\#include "{}version\_variable.h"{}}}
\DoxyCodeLine{206 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"{}user\_set\_diffusivity"{}}  \textcolor{comment}{! This module's name.}}
\DoxyCodeLine{207   \textcolor{keywordtype}{character(len=200)} :: mesg}
\DoxyCodeLine{208   \textcolor{keywordtype}{integer} :: i, j, is, ie, js, je}
\DoxyCodeLine{209 }
\DoxyCodeLine{210   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{211     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"{}diabatic\_entrain\_init called with an associated "{}}// \&}
\DoxyCodeLine{212                             \textcolor{stringliteral}{"{}control structure."{}})}
\DoxyCodeLine{213     \textcolor{keywordflow}{return}}
\DoxyCodeLine{214 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{215   \textcolor{keyword}{allocate}(cs)}
\DoxyCodeLine{216 }
\DoxyCodeLine{217   is = g\%isc ; ie = g\%iec ; js = g\%jsc ; je = g\%jec}
\DoxyCodeLine{218 }
\DoxyCodeLine{219   cs\%diag => diag}
\DoxyCodeLine{220 }
\DoxyCodeLine{221   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}}
\DoxyCodeLine{222   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{"{}"{}})}
\DoxyCodeLine{223   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}USER\_KD\_ADD"{}}, cs\%Kd\_add, \&}
\DoxyCodeLine{224                  \textcolor{stringliteral}{"{}A user-\/specified additional diffusivity over a range of "{}}//\&}
\DoxyCodeLine{225                  \textcolor{stringliteral}{"{}latitude and density."{}}, default=0.0, units=\textcolor{stringliteral}{"{}m2 s-\/1"{}}, \&}
\DoxyCodeLine{226                  scale=us\%m2\_s\_to\_Z2\_T)}
\DoxyCodeLine{227   \textcolor{keywordflow}{if} (cs\%Kd\_add /= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{228     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}USER\_KD\_ADD\_LAT\_RANGE"{}}, cs\%lat\_range(:), \&}
\DoxyCodeLine{229                  \textcolor{stringliteral}{"{}Four successive values that define a range of latitudes "{}}//\&}
\DoxyCodeLine{230                  \textcolor{stringliteral}{"{}over which the user-\/specified extra diffusivity is "{}}//\&}
\DoxyCodeLine{231                  \textcolor{stringliteral}{"{}applied.  The four values specify the latitudes at "{}}//\&}
\DoxyCodeLine{232                  \textcolor{stringliteral}{"{}which the extra diffusivity starts to increase from 0, "{}}//\&}
\DoxyCodeLine{233                  \textcolor{stringliteral}{"{}hits its full value, starts to decrease again, and is "{}}//\&}
\DoxyCodeLine{234                  \textcolor{stringliteral}{"{}back to 0."{}}, units=\textcolor{stringliteral}{"{}degree"{}}, default=-\/1.0e9)}
\DoxyCodeLine{235     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}USER\_KD\_ADD\_RHO\_RANGE"{}}, cs\%rho\_range(:), \&}
\DoxyCodeLine{236                  \textcolor{stringliteral}{"{}Four successive values that define a range of potential "{}}//\&}
\DoxyCodeLine{237                  \textcolor{stringliteral}{"{}densities over which the user-\/given extra diffusivity "{}}//\&}
\DoxyCodeLine{238                  \textcolor{stringliteral}{"{}is applied.  The four values specify the density at "{}}//\&}
\DoxyCodeLine{239                  \textcolor{stringliteral}{"{}which the extra diffusivity starts to increase from 0, "{}}//\&}
\DoxyCodeLine{240                  \textcolor{stringliteral}{"{}hits its full value, starts to decrease again, and is "{}}//\&}
\DoxyCodeLine{241                  \textcolor{stringliteral}{"{}back to 0."{}}, units=\textcolor{stringliteral}{"{}kg m-\/3"{}}, default=-\/1.0e9, scale=us\%kg\_m3\_to\_R)}
\DoxyCodeLine{242     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"{}USER\_KD\_ADD\_USE\_ABS\_LAT"{}}, cs\%use\_abs\_lat, \&}
\DoxyCodeLine{243                  \textcolor{stringliteral}{"{}If true, use the absolute value of latitude when "{}}//\&}
\DoxyCodeLine{244                  \textcolor{stringliteral}{"{}checking whether a point fits into range of latitudes."{}}, \&}
\DoxyCodeLine{245                  default=.false.)}
\DoxyCodeLine{246 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{247 }
\DoxyCodeLine{248   \textcolor{keywordflow}{if} (.not.range\_ok(cs\%lat\_range)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{249     \textcolor{keyword}{write}(mesg, \textcolor{stringliteral}{'(4(1pe15.6))'}) cs\%lat\_range(1:4)}
\DoxyCodeLine{250     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}user\_set\_diffusivity: bad latitude range: \(\backslash\)n  "{}}//\&}
\DoxyCodeLine{251                     trim(mesg))}
\DoxyCodeLine{252 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{253   \textcolor{keywordflow}{if} (.not.range\_ok(cs\%rho\_range)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{254     \textcolor{keyword}{write}(mesg, \textcolor{stringliteral}{'(4(1pe15.6))'}) cs\%rho\_range(1:4)}
\DoxyCodeLine{255     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"{}user\_set\_diffusivity: bad density range: \(\backslash\)n  "{}}//\&}
\DoxyCodeLine{256                     trim(mesg))}
\DoxyCodeLine{257 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{258 }

\end{DoxyCode}
\mbox{\Hypertarget{namespaceuser__change__diffusivity_a9b291c89fbc92f517c683b5fa2797e92}\label{namespaceuser__change__diffusivity_a9b291c89fbc92f517c683b5fa2797e92}} 
\index{user\_change\_diffusivity@{user\_change\_diffusivity}!val\_weights@{val\_weights}}
\index{val\_weights@{val\_weights}!user\_change\_diffusivity@{user\_change\_diffusivity}}
\doxysubsubsection{\texorpdfstring{val\_weights()}{val\_weights()}}
{\footnotesize\ttfamily real function user\+\_\+change\+\_\+diffusivity\+::val\+\_\+weights (\begin{DoxyParamCaption}\item[{real, intent(in)}]{val,  }\item[{real, dimension(4), intent(in)}]{range }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



This subroutine returns a value that goes smoothly from 0 to 1, stays at 1, and then goes smoothly back to 0 at the four values of range. The transitions are cubic, and have zero first derivatives where the curves hit 0 and 1. The values in range must be in ascending order, as can be checked by calling range\+\_\+\+OK. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em val} & Value for which we need an answer \mbox{[}arbitrary units\mbox{]}. \\
\hline
\mbox{\texttt{ in}}  & {\em range} & Range over which the answer is non-\/zero \mbox{[}arbitrary units\mbox{]}. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Return value \mbox{[}nondim\mbox{]}. 
\end{DoxyReturn}


Definition at line 165 of file user\+\_\+change\+\_\+diffusivity.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{166 \textcolor{keywordtype}{  real},               \textcolor{keywordtype}{intent(in)} :: val\textcolor{comment}{    !< Value for which we need an answer [arbitrary units].}}
\DoxyCodeLine{167 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(4)}, \textcolor{keywordtype}{intent(in)} :: range\textcolor{comment}{  !< Range over which the answer is non-\/zero [arbitrary units].}}
\DoxyCodeLine{168 \textcolor{keywordtype}{  real}                           :: ans\textcolor{comment}{    !< Return value [nondim].}}
\DoxyCodeLine{169   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{170 \textcolor{keywordtype}{  real} :: x   \textcolor{comment}{! A nondimensional number between 0 and 1.}}
\DoxyCodeLine{171 }
\DoxyCodeLine{172   ans = 0.0}
\DoxyCodeLine{173   \textcolor{keywordflow}{if} ((val > range(1)) .and. (val < range(4))) \textcolor{keywordflow}{then}}
\DoxyCodeLine{174     \textcolor{keywordflow}{if} (val < range(2)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{175       \textcolor{comment}{! x goes from 0 to 1; ans goes from 0 to 1, with 0 derivatives at the ends.}}
\DoxyCodeLine{176       x = (val -\/ range(1)) / (range(2) -\/ range(1))}
\DoxyCodeLine{177       ans = x**2 * (3.0 -\/ 2.0 * x)}
\DoxyCodeLine{178     \textcolor{keywordflow}{elseif} (val > range(3)) \textcolor{keywordflow}{then}}
\DoxyCodeLine{179       \textcolor{comment}{! x goes from 0 to 1; ans goes from 0 to 1, with 0 derivatives at the ends.}}
\DoxyCodeLine{180       x = (range(4) -\/ val) / (range(4) -\/ range(3))}
\DoxyCodeLine{181       ans = x**2 * (3.0 -\/ 2.0 * x)}
\DoxyCodeLine{182     \textcolor{keywordflow}{else}}
\DoxyCodeLine{183       ans = 1.0}
\DoxyCodeLine{184 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{185 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{186 }

\end{DoxyCode}
