\hypertarget{namespaceuser__change__diffusivity}{}\section{user\+\_\+change\+\_\+diffusivity Module Reference}
\label{namespaceuser__change__diffusivity}\index{user\+\_\+change\+\_\+diffusivity@{user\+\_\+change\+\_\+diffusivity}}


\subsection{Detailed Description}
Increments the diapycnal diffusivity in a specified band of latitudes and densities. \subsection*{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}
\subsection*{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}


\subsection{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}}
\subsubsection{\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{\tt in}  & {\em range} & Four values to check.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Return value. 
\end{DoxyReturn}


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


\begin{DoxyCode}
152   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(4)}, \textcolor{keywordtype}{intent(in)} :: range\textcolor{comment}{  !< Four values to check.}
153   \textcolor{keywordtype}{logical}                        :: OK\textcolor{comment}{     !< Return value.}
154 
155   ok = ((range(1) <= range(2)) .and. (range(2) <= range(3)) .and. &
156         (range(3) <= range(4)))
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}}
\subsubsection{\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(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{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{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em tv} & A structure containing pointers to any available thermodynamic fields. Absent fields have N\+U\+LL ptrs.\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em cs} & This module\textquotesingle{}s control structure.\\
\hline
\mbox{\tt in,out}  & {\em kd\+\_\+lay} & The diapycnal diffusivity of each layer \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}.\\
\hline
\mbox{\tt in,out}  & {\em kd\+\_\+int} & The diapycnal diffusivity at each interface \mbox{[}Z2 T-\/1 $\sim$$>$ m2 s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em t\+\_\+f} & Temperature with massless layers filled in vertically \mbox{[}degC\mbox{]}.\\
\hline
\mbox{\tt 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 48 of file user\+\_\+change\+\_\+diffusivity.\+F90.


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


\begin{DoxyCode}
263   \textcolor{keywordtype}{type}(user\_change\_diff\_CS), \textcolor{keywordtype}{pointer} :: CS\textcolor{comment}{ !< A pointer that is set to point to the control}
264 \textcolor{comment}{                                           !! structure for this module.}
265 
266   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keyword}{deallocate}(cs)
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}}
\subsubsection{\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(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(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{\tt in}  & {\em time} & The current model time.\\
\hline
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure.\\
\hline
\mbox{\tt in}  & {\em gv} & The ocean\textquotesingle{}s vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & A structure indicating the open file to parse for model parameter values.\\
\hline
\mbox{\tt 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 191 of file user\+\_\+change\+\_\+diffusivity.\+F90.


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


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