\hypertarget{namespacemom__open__boundary}{}\section{mom\+\_\+open\+\_\+boundary Module Reference}
\label{namespacemom__open__boundary}\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}


\subsection{Detailed Description}
Controls where open boundary conditions are applied. 

This module implements some aspects of internal open boundary conditions in M\+OM.

A small fragment of the grid is shown below\+:

j+1 x $^\wedge$ x $^\wedge$ x At x\+: q, Coriolis\+Bu j+1 $>$ o $>$ o $>$ At $^\wedge$\+: v, tauy j x $^\wedge$ x $^\wedge$ x At $>$\+: u, taux j $>$ o $>$ o $>$ At o\+: h, bathyT, buoy, tr, T, S, Rml, ustar j-\/1 x $^\wedge$ x $^\wedge$ x i-\/1 i i+1 At x \& $^\wedge$\+: i i+1 At $>$ \& o\+:

The boundaries always run through q grid points (x). \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \hyperlink{structmom__open__boundary_1_1file__obc__cs}{file\+\_\+obc\+\_\+cs}
\begin{DoxyCompactList}\small\item\em Control structure for open boundaries that read from files. Probably lots to update here. \end{DoxyCompactList}\item 
type \hyperlink{structmom__open__boundary_1_1obc__registry__type}{obc\+\_\+registry\+\_\+type}
\begin{DoxyCompactList}\small\item\em Type to carry basic O\+BC information needed for updating values. \end{DoxyCompactList}\item 
type \hyperlink{structmom__open__boundary_1_1obc__segment__data__type}{obc\+\_\+segment\+\_\+data\+\_\+type}
\begin{DoxyCompactList}\small\item\em Open boundary segment data from files (mostly). \end{DoxyCompactList}\item 
type \hyperlink{structmom__open__boundary_1_1obc__segment__tracer__type}{obc\+\_\+segment\+\_\+tracer\+\_\+type}
\begin{DoxyCompactList}\small\item\em Tracer on O\+BC segment data structure, for putting into a segment tracer registry. \end{DoxyCompactList}\item 
type \hyperlink{structmom__open__boundary_1_1obc__segment__type}{obc\+\_\+segment\+\_\+type}
\begin{DoxyCompactList}\small\item\em Open boundary segment data structure. \end{DoxyCompactList}\item 
type \hyperlink{structmom__open__boundary_1_1obc__struct__type}{obc\+\_\+struct\+\_\+type}
\begin{DoxyCompactList}\small\item\em Type to carry something (what\mbox{]} for the O\+BC registry. \end{DoxyCompactList}\item 
type \hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}
\begin{DoxyCompactList}\small\item\em Open-\/boundary data. \end{DoxyCompactList}\item 
type \hyperlink{structmom__open__boundary_1_1segment__tracer__registry__type}{segment\+\_\+tracer\+\_\+registry\+\_\+type}
\begin{DoxyCompactList}\small\item\em Registry type for tracers on segments. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \hyperlink{namespacemom__open__boundary_ac94938f1a657896ff03efd3864faa02a}{open\+\_\+boundary\+\_\+config} (G, US, param\+\_\+file, O\+BC)
\begin{DoxyCompactList}\small\item\em Enables O\+BC module and reads configuration parameters This routine is called from M\+O\+M\+\_\+initialize\+\_\+fixed which occurs before the initialization of the vertical coordinate and A\+L\+E\+\_\+init. Therefore segment data are not fully initialized here. The remainder of the segment data are initialized in a later call to update\+\_\+open\+\_\+boundary\+\_\+data. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a81b020bcce067d3c3a45a21faa526227}{initialize\+\_\+segment\+\_\+data} (G, O\+BC, PF)
\begin{DoxyCompactList}\small\item\em Allocate space for reading O\+BC data from files. It sets up the required vertical remapping. In the process, it does funky stuff with the M\+PI processes. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__open__boundary_a47ad907f8613e7400ac3c6919c22bb11}{initialize\+\_\+obc\+\_\+tides} (O\+BC, param\+\_\+file)
\item 
subroutine \hyperlink{namespacemom__open__boundary_ac357a1fb341db3aaffdfeca2eacab60b}{setup\+\_\+segment\+\_\+indices} (G, seg, Is\+\_\+obc, Ie\+\_\+obc, Js\+\_\+obc, Je\+\_\+obc)
\begin{DoxyCompactList}\small\item\em Define indices for segment and store in hor\+\_\+index\+\_\+type using global segment bounds corresponding to q-\/points. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__open__boundary_aa40e3464225d4e017b1a738995eeb3b2}{setup\+\_\+u\+\_\+point\+\_\+obc} (O\+BC, G, US, segment\+\_\+str, l\+\_\+seg, PF, reentrant\+\_\+y)
\begin{DoxyCompactList}\small\item\em Parse an O\+B\+C\+\_\+\+S\+E\+G\+M\+E\+N\+T\+\_\+\%\%\% string starting with \char`\"{}\+I=\char`\"{} and configure placement and type of O\+BC accordingly. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__open__boundary_a706dd2fb2049757b3b76bf8b481e735c}{setup\+\_\+v\+\_\+point\+\_\+obc} (O\+BC, G, US, segment\+\_\+str, l\+\_\+seg, PF, reentrant\+\_\+x)
\begin{DoxyCompactList}\small\item\em Parse an O\+B\+C\+\_\+\+S\+E\+G\+M\+E\+N\+T\+\_\+\%\%\% string starting with \char`\"{}\+J=\char`\"{} and configure placement and type of O\+BC accordingly. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__open__boundary_a0eb361009a2dddf3ad9a24d0d7223898}{parse\+\_\+segment\+\_\+str} (ni\+\_\+global, nj\+\_\+global, segment\+\_\+str, l, m, n, action\+\_\+str, reentrant)
\begin{DoxyCompactList}\small\item\em Parse an O\+B\+C\+\_\+\+S\+E\+G\+M\+E\+N\+T\+\_\+\%\%\% string. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__open__boundary_a69848c26ddd38fe0f619311fa518313f}{parse\+\_\+segment\+\_\+manifest\+\_\+str} (segment\+\_\+str, num\+\_\+fields, fields)
\begin{DoxyCompactList}\small\item\em Parse an O\+B\+C\+\_\+\+S\+E\+G\+M\+E\+N\+T\+\_\+\%\%\+\_\+\+D\+A\+TA string and determine its fields. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__open__boundary_ae97f243936ebbcd30c8cfe91d41729c4}{parse\+\_\+segment\+\_\+data\+\_\+str} (segment\+\_\+str, idx, var, value, filename, fieldname)
\begin{DoxyCompactList}\small\item\em Parse an O\+B\+C\+\_\+\+S\+E\+G\+M\+E\+N\+T\+\_\+\%\%\+\_\+\+D\+A\+TA string. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__open__boundary_a2e2dbab2a3e23eb9848aba473f635cec}{parse\+\_\+for\+\_\+tracer\+\_\+reservoirs} (O\+BC, PF, use\+\_\+temperature)
\begin{DoxyCompactList}\small\item\em Parse all the O\+B\+C\+\_\+\+S\+E\+G\+M\+E\+N\+T\+\_\+\%\%\+\_\+\+D\+A\+TA strings again to see which need tracer reservoirs (all pes need to know). \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__open__boundary_a349df847b304948d5b98352ddfd7bf8d}{parse\+\_\+segment\+\_\+param\+\_\+real} (segment\+\_\+str, var, param\+\_\+value, debug)
\begin{DoxyCompactList}\small\item\em Parse an O\+B\+C\+\_\+\+S\+E\+G\+M\+E\+N\+T\+\_\+\%\%\+\_\+\+P\+A\+R\+A\+MS string. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a53dc87c231fcaf1c99fe818956fb111e}{open\+\_\+boundary\+\_\+init} (G, GV, US, param\+\_\+file, O\+BC, restart\+\_\+\+C\+Sp)
\begin{DoxyCompactList}\small\item\em Initialize open boundary control structure and do any necessary rescaling of O\+BC fields that have been read from a restart file. \end{DoxyCompactList}\item 
logical function, public \hyperlink{namespacemom__open__boundary_af55e663cc3a1f5f697e72066d75c9160}{open\+\_\+boundary\+\_\+query} (O\+BC, apply\+\_\+open\+\_\+\+O\+BC, apply\+\_\+specified\+\_\+\+O\+BC, apply\+\_\+\+Flather\+\_\+\+O\+BC, apply\+\_\+nudged\+\_\+\+O\+BC, needs\+\_\+ext\+\_\+seg\+\_\+data)
\item 
subroutine \hyperlink{namespacemom__open__boundary_a709a33b9e33b5689d5ca73349ed51fb6}{open\+\_\+boundary\+\_\+dealloc} (O\+BC)
\begin{DoxyCompactList}\small\item\em Deallocate open boundary data. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_afb86d9ee7fc99dea787b88cfdb70f139}{open\+\_\+boundary\+\_\+end} (O\+BC)
\begin{DoxyCompactList}\small\item\em Close open boundary data. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_afc301353fde1f12ef04dab751ddb7ac2}{open\+\_\+boundary\+\_\+impose\+\_\+normal\+\_\+slope} (O\+BC, G, depth)
\begin{DoxyCompactList}\small\item\em Sets the slope of bathymetry normal to an open bounndary to zero. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a7aa6f2b520108ce761ef107557f69069}{open\+\_\+boundary\+\_\+impose\+\_\+land\+\_\+mask} (O\+BC, G, area\+Cu, area\+Cv, US)
\begin{DoxyCompactList}\small\item\em Reconcile masks and open boundaries, deallocate O\+BC on P\+Es where it is not needed. Also adjust u-\/ and v-\/point cell area on specified open boundaries and mask all points outside open boundaries. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__open__boundary_a2578141730f51e42c56bb05c3648ea08}{setup\+\_\+obc\+\_\+tracer\+\_\+reservoirs} (G, O\+BC)
\begin{DoxyCompactList}\small\item\em Make sure the O\+BC tracer reservoirs are initialized. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_ae5ceafcce53e896d30012f321c73d9f4}{radiation\+\_\+open\+\_\+bdry\+\_\+conds} (O\+BC, u\+\_\+new, u\+\_\+old, v\+\_\+new, v\+\_\+old, G, US, dt)
\begin{DoxyCompactList}\small\item\em Apply radiation conditions to 3D u,v at open boundaries. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a11acc9ede6f2b975bfc6b849a2603b46}{open\+\_\+boundary\+\_\+apply\+\_\+normal\+\_\+flow} (O\+BC, G, u, v)
\begin{DoxyCompactList}\small\item\em Applies O\+BC values stored in segments to 3d u,v fields. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a9d48e6925d93fa98cbf5bb73903f94be}{open\+\_\+boundary\+\_\+zero\+\_\+normal\+\_\+flow} (O\+BC, G, u, v)
\begin{DoxyCompactList}\small\item\em Applies zero values to 3d u,v fields on O\+BC segments. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__open__boundary_a151df14c3b8b1094ddf8f44c86493fd5}{gradient\+\_\+at\+\_\+q\+\_\+points} (G, segment, uvel, vvel)
\begin{DoxyCompactList}\small\item\em Calculate the tangential gradient of the normal flow at the boundary q-\/points. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a0a4c67f2e0fe21f1a2274be12844a71a}{set\+\_\+tracer\+\_\+data} (O\+BC, tv, h, G, PF, tracer\+\_\+\+Reg)
\begin{DoxyCompactList}\small\item\em Sets the initial values of the tracer open boundary conditions. Redoing this elsewhere. \end{DoxyCompactList}\item 
integer function \hyperlink{namespacemom__open__boundary_a29dd2dc87f43e0e26d22367ce93519ff}{lookup\+\_\+seg\+\_\+field} (O\+B\+C\+\_\+seg, field)
\begin{DoxyCompactList}\small\item\em Needs documentation. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__open__boundary_aa7f532a65dd8ae4db981f2ef4791fc56}{allocate\+\_\+obc\+\_\+segment\+\_\+data} (O\+BC, segment)
\begin{DoxyCompactList}\small\item\em Allocate segment data fields. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__open__boundary_a5d71c596c3bd7d773a39f5c63d5389ac}{deallocate\+\_\+obc\+\_\+segment\+\_\+data} (O\+BC, segment)
\begin{DoxyCompactList}\small\item\em Deallocate segment data fields. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a556977a2754fab17e837a8fba75cd9ee}{open\+\_\+boundary\+\_\+test\+\_\+extern\+\_\+uv} (G, O\+BC, u, v)
\begin{DoxyCompactList}\small\item\em Set tangential velocities outside of open boundaries to silly values (used for checking the interior state is independent of values outside of the domain). \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a4123d11abdb141b21a4d52a0c43c4adb}{open\+\_\+boundary\+\_\+test\+\_\+extern\+\_\+h} (G, GV, O\+BC, h)
\begin{DoxyCompactList}\small\item\em Set thicknesses outside of open boundaries to silly values (used for checking the interior state is independent of values outside of the domain). \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a8d2c8b028b9fc7d65f17155497a0487d}{update\+\_\+obc\+\_\+segment\+\_\+data} (G, GV, US, O\+BC, tv, h, Time)
\begin{DoxyCompactList}\small\item\em Update the O\+BC values on the segments. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a2459650f97c35ba541246d1418efb6a1}{update\+\_\+obc\+\_\+ramp} (Time, O\+BC, activate)
\begin{DoxyCompactList}\small\item\em Update the O\+BC ramp value as a function of time. If called with the optional argument activate=.true., record the value of Time as the beginning of the ramp period. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a8e0e22d829c122134f039228c6f1c7fb}{register\+\_\+obc} (name, param\+\_\+file, Reg)
\begin{DoxyCompactList}\small\item\em register open boundary objects for boundary updates. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a0a6e28bbfec6ab82bfe2fd2848902945}{obc\+\_\+registry\+\_\+init} (param\+\_\+file, Reg)
\begin{DoxyCompactList}\small\item\em This routine include declares and sets the variable \char`\"{}version\char`\"{}. \end{DoxyCompactList}\item 
logical function, public \hyperlink{namespacemom__open__boundary_a05d15beca2ef2b44fb36d129166907fa}{register\+\_\+file\+\_\+obc} (param\+\_\+file, CS, O\+B\+C\+\_\+\+Reg)
\begin{DoxyCompactList}\small\item\em Add file to O\+BC registry. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a55081f00e4a95f87ddc5dfe1d61f52e0}{file\+\_\+obc\+\_\+end} (CS)
\begin{DoxyCompactList}\small\item\em Clean up the file O\+BC from registry. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_adcd9637c6cc17658fe064ce1dc1011bf}{segment\+\_\+tracer\+\_\+registry\+\_\+init} (param\+\_\+file, segment)
\begin{DoxyCompactList}\small\item\em Initialize the segment tracer registry. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a5d5843dd1a4e1475f69b5eb2c5b0197d}{register\+\_\+segment\+\_\+tracer} (tr\+\_\+ptr, param\+\_\+file, GV, segment, O\+B\+C\+\_\+scalar, O\+B\+C\+\_\+array)
\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a71194a8dc156fea37aab6539cc124086}{segment\+\_\+tracer\+\_\+registry\+\_\+end} (Reg)
\begin{DoxyCompactList}\small\item\em Clean up the segment tracer registry. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a0459cfc5b4e4115bde6ada1dd7c25139}{register\+\_\+temp\+\_\+salt\+\_\+segments} (GV, O\+BC, tr\+\_\+\+Reg, param\+\_\+file)
\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a70d8b2b93599effe185abbc5a586b35c}{fill\+\_\+temp\+\_\+salt\+\_\+segments} (G, O\+BC, tv)
\item 
subroutine \hyperlink{namespacemom__open__boundary_a7dbf161294debd059a40659ba691ca0b}{mask\+\_\+outside\+\_\+obcs} (G, US, param\+\_\+file, O\+BC)
\begin{DoxyCompactList}\small\item\em Find the region outside of all open boundary segments and make sure it is set to land mask. Gonna need to know global land mask as well to get it right... \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__open__boundary_ab5a04fc90320c3af571f02f8c98f0b18}{flood\+\_\+fill} (G, color, cin, cout, cland)
\begin{DoxyCompactList}\small\item\em flood the cin, cout values \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__open__boundary_a13ac2cc232309a51db31c3b9ee5f22af}{flood\+\_\+fill2} (G, color, cin, cout, cland)
\begin{DoxyCompactList}\small\item\em flood the cin, cout values \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_af1d4f35b2cff85617fc5766739db81de}{open\+\_\+boundary\+\_\+register\+\_\+restarts} (HI, GV, O\+BC, Reg, param\+\_\+file, restart\+\_\+\+C\+Sp, use\+\_\+temperature)
\begin{DoxyCompactList}\small\item\em Register O\+BC segment data for restarts. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a230cf67375352c9d55b4330180d35d7c}{update\+\_\+segment\+\_\+tracer\+\_\+reservoirs} (G, GV, uhr, vhr, h, O\+BC, dt, Reg)
\begin{DoxyCompactList}\small\item\em Update the O\+BC tracer reservoirs after the tracers have been updated. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__open__boundary_a2c6f236ceed8e7e696215f1638cf4b9c}{adjustsegmentetatofitbathymetry} (G, GV, US, segment, fld)
\begin{DoxyCompactList}\small\item\em Adjust interface heights to fit the bathymetry and diagnose layer thickness. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_a0c4401f57b9a8275c8bb3d2f7c5e013f}{rotate\+\_\+obc\+\_\+config} (O\+B\+C\+\_\+in, G\+\_\+in, O\+BC, G, turns)
\begin{DoxyCompactList}\small\item\em This is more of a rotate initialization than an actual rotate. \end{DoxyCompactList}\item 
subroutine \hyperlink{namespacemom__open__boundary_a68a208918e01e2393f12f737bdff3776}{rotate\+\_\+obc\+\_\+segment\+\_\+config} (segment\+\_\+in, G\+\_\+in, segment, G, turns)
\begin{DoxyCompactList}\small\item\em Rotate the O\+BC segment configuration data from the input to model index map. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespacemom__open__boundary_acafa1a47d4e7f4d347963286d7614104}{rotate\+\_\+obc\+\_\+init} (O\+B\+C\+\_\+in, G, GV, US, param\+\_\+file, tv, restart\+\_\+\+C\+Sp, O\+BC)
\begin{DoxyCompactList}\small\item\em Initialize the segments and field-\/related data of a rotated O\+BC. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__open__boundary_ae12e12fb8589f53ee4494f46e6e2f96e}\label{namespacemom__open__boundary_ae12e12fb8589f53ee4494f46e6e2f96e}} 
subroutine \hyperlink{namespacemom__open__boundary_ae12e12fb8589f53ee4494f46e6e2f96e}{rotate\+\_\+obc\+\_\+segment\+\_\+data} (segment\+\_\+in, segment, turns)
\begin{DoxyCompactList}\small\item\em Rotate an O\+BC segment\textquotesingle{}s fields from the input to the model index map. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__open__boundary_a1dd4294ac05ea337431a26395003325f}\label{namespacemom__open__boundary_a1dd4294ac05ea337431a26395003325f}} 
integer, parameter, public \hyperlink{namespacemom__open__boundary_a1dd4294ac05ea337431a26395003325f}{obc\+\_\+none} = 0
\begin{DoxyCompactList}\small\item\em Indicates the use of no open boundary. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__open__boundary_ad14f75b62184f667bb07c0f31b633c7c}\label{namespacemom__open__boundary_ad14f75b62184f667bb07c0f31b633c7c}} 
integer, parameter, public \hyperlink{namespacemom__open__boundary_ad14f75b62184f667bb07c0f31b633c7c}{obc\+\_\+simple} = 1
\begin{DoxyCompactList}\small\item\em Indicates the use of a simple inflow open boundary. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__open__boundary_a59020084f9aa725ff55812572cabe6e6}\label{namespacemom__open__boundary_a59020084f9aa725ff55812572cabe6e6}} 
integer, parameter, public \hyperlink{namespacemom__open__boundary_a59020084f9aa725ff55812572cabe6e6}{obc\+\_\+wall} = 2
\begin{DoxyCompactList}\small\item\em Indicates the use of a closed wall. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__open__boundary_aab15bba6b94442339da4ea4dcb35811d}\label{namespacemom__open__boundary_aab15bba6b94442339da4ea4dcb35811d}} 
integer, parameter, public \hyperlink{namespacemom__open__boundary_aab15bba6b94442339da4ea4dcb35811d}{obc\+\_\+flather} = 3
\begin{DoxyCompactList}\small\item\em Indicates the use of a Flather open boundary. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__open__boundary_a8f7b9f941c542c5bcddb75de5fa8e38e}\label{namespacemom__open__boundary_a8f7b9f941c542c5bcddb75de5fa8e38e}} 
integer, parameter, public \hyperlink{namespacemom__open__boundary_a8f7b9f941c542c5bcddb75de5fa8e38e}{obc\+\_\+radiation} = 4
\begin{DoxyCompactList}\small\item\em Indicates the use of a radiation open boundary. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__open__boundary_a6ace8760d7fa465a59d8cbc3340a5b5e}\label{namespacemom__open__boundary_a6ace8760d7fa465a59d8cbc3340a5b5e}} 
integer, parameter, public \hyperlink{namespacemom__open__boundary_a6ace8760d7fa465a59d8cbc3340a5b5e}{obc\+\_\+direction\+\_\+n} = 100
\begin{DoxyCompactList}\small\item\em Indicates the boundary is an effective northern boundary. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__open__boundary_a29aee121a765fc751bd1c21adf80af10}\label{namespacemom__open__boundary_a29aee121a765fc751bd1c21adf80af10}} 
integer, parameter, public \hyperlink{namespacemom__open__boundary_a29aee121a765fc751bd1c21adf80af10}{obc\+\_\+direction\+\_\+s} = 200
\begin{DoxyCompactList}\small\item\em Indicates the boundary is an effective southern boundary. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__open__boundary_a876256dbb0556d7e04cdf091f1744b65}\label{namespacemom__open__boundary_a876256dbb0556d7e04cdf091f1744b65}} 
integer, parameter, public \hyperlink{namespacemom__open__boundary_a876256dbb0556d7e04cdf091f1744b65}{obc\+\_\+direction\+\_\+e} = 300
\begin{DoxyCompactList}\small\item\em Indicates the boundary is an effective eastern boundary. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__open__boundary_a015e27a65957919ea3cd67767b8f26f7}\label{namespacemom__open__boundary_a015e27a65957919ea3cd67767b8f26f7}} 
integer, parameter, public \hyperlink{namespacemom__open__boundary_a015e27a65957919ea3cd67767b8f26f7}{obc\+\_\+direction\+\_\+w} = 400
\begin{DoxyCompactList}\small\item\em Indicates the boundary is an effective western boundary. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__open__boundary_a6997b7b50a4afe32b14fd61ba858254f}\label{namespacemom__open__boundary_a6997b7b50a4afe32b14fd61ba858254f}} 
integer, parameter \hyperlink{namespacemom__open__boundary_a6997b7b50a4afe32b14fd61ba858254f}{max\+\_\+obc\+\_\+fields} = 100
\begin{DoxyCompactList}\small\item\em Maximum number of data fields needed for O\+BC segments. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__open__boundary_ad6193d2825ef41d066e20706754a0d68}\label{namespacemom__open__boundary_ad6193d2825ef41d066e20706754a0d68}} 
integer \hyperlink{namespacemom__open__boundary_ad6193d2825ef41d066e20706754a0d68}{id\+\_\+clock\+\_\+pass}
\begin{DoxyCompactList}\small\item\em A C\+PU time clock. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__open__boundary_aafc1b36aca40a894743f1565f4f9d152}\label{namespacemom__open__boundary_aafc1b36aca40a894743f1565f4f9d152}} 
character(len=40) \hyperlink{namespacemom__open__boundary_aafc1b36aca40a894743f1565f4f9d152}{mdl} = \char`\"{}M\+O\+M\+\_\+open\+\_\+boundary\char`\"{}
\begin{DoxyCompactList}\small\item\em This module\textquotesingle{}s name. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__open__boundary_a2c6f236ceed8e7e696215f1638cf4b9c}\label{namespacemom__open__boundary_a2c6f236ceed8e7e696215f1638cf4b9c}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!adjustsegmentetatofitbathymetry@{adjustsegmentetatofitbathymetry}}
\index{adjustsegmentetatofitbathymetry@{adjustsegmentetatofitbathymetry}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{adjustsegmentetatofitbathymetry()}{adjustsegmentetatofitbathymetry()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::adjustsegmentetatofitbathymetry (\begin{DoxyParamCaption}\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(\hyperlink{structmom__open__boundary_1_1obc__segment__type}{obc\+\_\+segment\+\_\+type}), intent(inout)}]{segment,  }\item[{integer, intent(in)}]{fld }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Adjust interface heights to fit the bathymetry and diagnose layer thickness. 

If the bottom most interface is below the topography then the bottom-\/most layers are contracted to GVAngstrom\+\_\+m. If the bottom most interface is above the topography then the entire column is dilated (expanded) to fill the void. \begin{DoxyRemark}{Remarks}
\{There is a (hard-\/wired) \char`\"{}tolerance\char`\"{} parameter such that the criteria for adjustment must equal or exceed 10cm.\}
\end{DoxyRemark}

\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 us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in,out}  & {\em segment} & pointer to segment type\\
\hline
\mbox{\tt in}  & {\em fld} & field index to adjust thickness \\
\hline
\end{DoxyParams}


Definition at line 5145 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
5145   \textcolor{keywordtype}{type}(ocean\_grid\_type),                      \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{   !< The ocean's grid structure}
5146   \textcolor{keywordtype}{type}(verticalgrid\_type),                    \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{  !< The ocean's vertical grid structure}
5147   \textcolor{keywordtype}{type}(unit\_scale\_type),                      \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{  !< A dimensional unit scaling type}
5148   \textcolor{keywordtype}{type}(obc\_segment\_type),                     \textcolor{keywordtype}{intent(inout)} :: segment\textcolor{comment}{ !< pointer to segment type}
5149   \textcolor{keywordtype}{integer},                                    \textcolor{keywordtype}{intent(in)}    :: fld\textcolor{comment}{  !< field index to adjust thickness}
5150   \textcolor{comment}{! Local variables}
5151   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, nz, contractions, dilations
5152   \textcolor{keywordtype}{integer} :: n
5153   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: eta \textcolor{comment}{! Segment source data interface heights, [Z -> m]}
5154   \textcolor{keywordtype}{real} :: htolerance = 0.1\textcolor{comment}{ !<  Tolerance to exceed adjustment criteria [Z ~> m]}
5155   \textcolor{keywordtype}{real} :: htmp, etmp, dilate
5156   \textcolor{keywordtype}{character(len=100)} :: mesg
5157 
5158   htolerance = 0.1*us%m\_to\_Z
5159 
5160   nz = \textcolor{keyword}{size}(segment%field(fld)%dz\_src,3)
5161 
5162   \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
5163      \textcolor{comment}{! segment thicknesses are defined at cell face centers.}
5164      is = segment%HI%isdB ; ie = segment%HI%iedB
5165      js = segment%HI%jsd ; je = segment%HI%jed
5166   \textcolor{keywordflow}{else}
5167      is = segment%HI%isd ; ie = segment%HI%ied
5168      js = segment%HI%jsdB ; je = segment%HI%jedB
5169 \textcolor{keywordflow}{  endif}
5170   \textcolor{keyword}{allocate}(eta(is:ie,js:je,nz+1))
5171   contractions=0; dilations=0
5172   \textcolor{keywordflow}{do} j=js,je ; \textcolor{keywordflow}{do} i=is,ie
5173     eta(i,j,1)=0.0   \textcolor{comment}{! segment data are assumed to be located on a static grid}
5174     \textcolor{comment}{! For remapping calls, the entire column will be dilated}
5175     \textcolor{comment}{! by a factor equal to the ratio of the sum of the geopotential referenced}
5176     \textcolor{comment}{! source data thicknesses, and the current model thicknesses. This could be}
5177     \textcolor{comment}{! an issue to be addressed, for instance if we are placing open boundaries}
5178     \textcolor{comment}{! under ice shelf cavities.}
5179     \textcolor{keywordflow}{do} k=2,nz+1
5180       eta(i,j,k)=eta(i,j,k-1)-segment%field(fld)%dz\_src(i,j,k-1)
5181 \textcolor{keywordflow}{    enddo}
5182     \textcolor{comment}{! The normal slope at the boundary is zero by a}
5183     \textcolor{comment}{! previous call to open\_boundary\_impose\_normal\_slope}
5184     \textcolor{keywordflow}{do} k=nz+1,1,-1
5185       \textcolor{keywordflow}{if} (-eta(i,j,k) > segment%Htot(i,j)*gv%H\_to\_Z + htolerance) \textcolor{keywordflow}{then}
5186          eta(i,j,k) = -segment%Htot(i,j)*gv%H\_to\_Z
5187          contractions = contractions + 1
5188 \textcolor{keywordflow}{      endif}
5189 \textcolor{keywordflow}{    enddo}
5190 
5191     \textcolor{keywordflow}{do} k=1,nz
5192       \textcolor{comment}{! Collapse layers to thinnest possible if the thickness less than}
5193       \textcolor{comment}{! the thinnest possible (or negative).}
5194       \textcolor{keywordflow}{if} (eta(i,j,k) < (eta(i,j,k+1) + gv%Angstrom\_Z)) \textcolor{keywordflow}{then}
5195          eta(i,j,k) = eta(i,j,k+1) + gv%Angstrom\_Z
5196          segment%field(fld)%dz\_src(i,j,k) = gv%Angstrom\_Z
5197       \textcolor{keywordflow}{else}
5198          segment%field(fld)%dz\_src(i,j,k) = (eta(i,j,k) - eta(i,j,k+1))
5199 \textcolor{keywordflow}{      endif}
5200 \textcolor{keywordflow}{    enddo}
5201 
5202     \textcolor{comment}{!   The whole column is dilated to accommodate deeper topography than}
5203     \textcolor{comment}{! the bathymetry would indicate.}
5204     \textcolor{keywordflow}{if} (-eta(i,j,nz+1) < (segment%Htot(i,j) * gv%H\_to\_Z) - htolerance) \textcolor{keywordflow}{then}
5205        dilations = dilations + 1
5206        \textcolor{comment}{! expand bottom-most cell only}
5207        eta(i,j,nz+1) = -(segment%Htot(i,j) * gv%H\_to\_Z)
5208        segment%field(fld)%dz\_src(i,j,nz)= eta(i,j,nz)-eta(i,j,nz+1)
5209        \textcolor{comment}{! if (eta(i,j,1) <= eta(i,j,nz+1)) then}
5210        \textcolor{comment}{!   do k=1,nz ; segment%field(fld)%dz\_src(i,j,k) = (eta(i,j,1) + G%bathyT(i,j)) / real(nz) ; enddo}
5211        \textcolor{comment}{! else}
5212        \textcolor{comment}{!   dilate = (eta(i,j,1) + G%bathyT(i,j)) / (eta(i,j,1) - eta(i,j,nz+1))}
5213        \textcolor{comment}{!   do k=1,nz ; segment%field(fld)%dz\_src(i,j,k) = segment%field(fld)%dz\_src(i,j,k) * dilate ; enddo}
5214        \textcolor{comment}{! endif}
5215        \textcolor{comment}{!do k=nz,2,-1 ; eta(i,j,K) = eta(i,j,K+1) + segment%field(fld)%dz\_src(i,j,k) ; enddo}
5216 \textcolor{keywordflow}{    endif}
5217     \textcolor{comment}{! Now convert thicknesses to units of H.}
5218     \textcolor{keywordflow}{do} k=1,nz
5219       segment%field(fld)%dz\_src(i,j,k) = segment%field(fld)%dz\_src(i,j,k)*gv%Z\_to\_H
5220 \textcolor{keywordflow}{    enddo}
5221 \textcolor{keyword}{  end}do; enddo
5222 
5223   \textcolor{comment}{! can not do communication call here since only PEs on the current segment are here}
5224 
5225   \textcolor{comment}{! call sum\_across\_PEs(contractions)}
5226   \textcolor{comment}{! if ((contractions > 0) .and. (is\_root\_pe())) then}
5227   \textcolor{comment}{!    write(mesg,'("Thickness OBCs were contracted ",'// &}
5228   \textcolor{comment}{!         '"to fit topography in ",I8," places.")') contractions}
5229   \textcolor{comment}{!    call MOM\_error(WARNING, 'adjustEtaToFitBathymetry: '//mesg)}
5230   \textcolor{comment}{! endif}
5231   \textcolor{comment}{! call sum\_across\_PEs(dilations)}
5232   \textcolor{comment}{! if ((dilations > 0) .and. (is\_root\_pe())) then}
5233   \textcolor{comment}{!    write(mesg,'("Thickness OBCs were dilated ",'// &}
5234   \textcolor{comment}{!         '"to fit topography in ",I8," places.")') dilations}
5235   \textcolor{comment}{!    call MOM\_error(WARNING, 'adjustEtaToFitBathymetry: '//mesg)}
5236   \textcolor{comment}{! endif}
5237   \textcolor{keyword}{deallocate}(eta)
5238 
5239 
5240 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_aa7f532a65dd8ae4db981f2ef4791fc56}\label{namespacemom__open__boundary_aa7f532a65dd8ae4db981f2ef4791fc56}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!allocate\+\_\+obc\+\_\+segment\+\_\+data@{allocate\+\_\+obc\+\_\+segment\+\_\+data}}
\index{allocate\+\_\+obc\+\_\+segment\+\_\+data@{allocate\+\_\+obc\+\_\+segment\+\_\+data}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{allocate\+\_\+obc\+\_\+segment\+\_\+data()}{allocate\_obc\_segment\_data()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::allocate\+\_\+obc\+\_\+segment\+\_\+data (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{type(\hyperlink{structmom__open__boundary_1_1obc__segment__type}{obc\+\_\+segment\+\_\+type}), intent(inout)}]{segment }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Allocate segment data fields. 


\begin{DoxyParams}[1]{Parameters}
 & {\em obc} & Open boundary structure\\
\hline
\mbox{\tt in,out}  & {\em segment} & Open boundary segment \\
\hline
\end{DoxyParams}


Definition at line 3502 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
3502   \textcolor{keywordtype}{type}(ocean\_obc\_type),   \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{     !< Open boundary structure}
3503   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{intent(inout)} :: segment\textcolor{comment}{ !< Open boundary segment}
3504   \textcolor{comment}{! Local variables}
3505   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed
3506   \textcolor{keywordtype}{integer} :: isdb, iedb, jsdb, jedb
3507   \textcolor{keywordtype}{integer} :: iscb, iecb, jscb, jecb
3508   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"allocate\_OBC\_segment\_data"} \textcolor{comment}{! This subroutine's name.}
3509 
3510   isd = segment%HI%isd ; ied = segment%HI%ied
3511   jsd = segment%HI%jsd ; jed = segment%HI%jed
3512   isdb = segment%HI%IsdB ; iedb = segment%HI%IedB
3513   jsdb = segment%HI%JsdB ; jedb = segment%HI%JedB
3514   iscb = segment%HI%IscB ; iecb = segment%HI%IecB
3515   jscb = segment%HI%JscB ; jecb = segment%HI%JecB
3516 
3517   \textcolor{keywordflow}{if} (.not. segment%on\_pe) \textcolor{keywordflow}{return}
3518 
3519   \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
3520     \textcolor{comment}{! If these are just Flather, change update\_OBC\_segment\_data accordingly}
3521     \textcolor{keyword}{allocate}(segment%Cg(isdb:iedb,jsd:jed));                  segment%Cg(:,:)=0.
3522     \textcolor{keyword}{allocate}(segment%Htot(isdb:iedb,jsd:jed));                segment%Htot(:,:)=0.0
3523     \textcolor{keyword}{allocate}(segment%h(isdb:iedb,jsd:jed,obc%ke));            segment%h(:,:,:)=0.0
3524     \textcolor{keyword}{allocate}(segment%eta(isdb:iedb,jsd:jed));                 segment%eta(:,:)=0.0
3525     \textcolor{keywordflow}{if} (segment%radiation) \textcolor{keywordflow}{then}
3526       \textcolor{keyword}{allocate}(segment%rx\_norm\_rad(isdb:iedb,jsd:jed,obc%ke));  segment%rx\_norm\_rad(:,:,:)=0.0
3527 \textcolor{keywordflow}{    endif}
3528     \textcolor{keyword}{allocate}(segment%normal\_vel(isdb:iedb,jsd:jed,obc%ke));   segment%normal\_vel(:,:,:)=0.0
3529     \textcolor{keyword}{allocate}(segment%normal\_vel\_bt(isdb:iedb,jsd:jed));       segment%normal\_vel\_bt(:,:)=0.0
3530     \textcolor{keyword}{allocate}(segment%normal\_trans(isdb:iedb,jsd:jed,obc%ke)); segment%normal\_trans(:,:,:)=0.0
3531     \textcolor{keywordflow}{if} (segment%nudged) \textcolor{keywordflow}{then}
3532       \textcolor{keyword}{allocate}(segment%nudged\_normal\_vel(isdb:iedb,jsd:jed,obc%ke)); segment%nudged\_normal\_vel(:,:,:)=0.0
3533 \textcolor{keywordflow}{    endif}
3534     \textcolor{keywordflow}{if} (segment%radiation\_tan .or. segment%nudged\_tan .or. segment%specified\_tan .or. &
3535         segment%oblique\_tan .or. obc%computed\_vorticity .or. obc%computed\_strain) \textcolor{keywordflow}{then}
3536       \textcolor{keyword}{allocate}(segment%tangential\_vel(isdb:iedb,jsdb:jedb,obc%ke)); segment%tangential\_vel(:,:,:)=0.0
3537 \textcolor{keywordflow}{    endif}
3538     \textcolor{keywordflow}{if} (segment%nudged\_tan) \textcolor{keywordflow}{then}
3539       \textcolor{keyword}{allocate}(segment%nudged\_tangential\_vel(isdb:iedb,jsdb:jedb,obc%ke)); segment%nudged\_tangential\_vel(:,
      :,:)=0.0
3540 \textcolor{keywordflow}{    endif}
3541     \textcolor{keywordflow}{if} (segment%nudged\_grad) \textcolor{keywordflow}{then}
3542       \textcolor{keyword}{allocate}(segment%nudged\_tangential\_grad(isdb:iedb,jsdb:jedb,obc%ke)); segment%nudged\_tangential\_grad(
      :,:,:)=0.0
3543 \textcolor{keywordflow}{    endif}
3544     \textcolor{keywordflow}{if} (obc%specified\_vorticity .or. obc%specified\_strain .or. segment%radiation\_grad .or. &
3545               segment%oblique\_grad .or. segment%specified\_grad) \textcolor{keywordflow}{then}
3546       \textcolor{keyword}{allocate}(segment%tangential\_grad(isdb:iedb,jsdb:jedb,obc%ke)); segment%tangential\_grad(:,:,:)=0.0
3547 \textcolor{keywordflow}{    endif}
3548     \textcolor{keywordflow}{if} (segment%oblique) \textcolor{keywordflow}{then}
3549       \textcolor{keyword}{allocate}(segment%grad\_normal(jsdb:jedb,2,obc%ke));      segment%grad\_normal(:,:,:) = 0.0
3550       \textcolor{keyword}{allocate}(segment%rx\_norm\_obl(isdb:iedb,jsd:jed,obc%ke));  segment%rx\_norm\_obl(:,:,:)=0.0
3551       \textcolor{keyword}{allocate}(segment%ry\_norm\_obl(isdb:iedb,jsd:jed,obc%ke));  segment%ry\_norm\_obl(:,:,:)=0.0
3552       \textcolor{keyword}{allocate}(segment%cff\_normal(isdb:iedb,jsd:jed,obc%ke)); segment%cff\_normal(:,:,:)=0.0
3553 \textcolor{keywordflow}{    endif}
3554     \textcolor{keywordflow}{if} (segment%oblique\_tan) \textcolor{keywordflow}{then}
3555       \textcolor{keyword}{allocate}(segment%grad\_tan(jsd-1:jed+1,2,obc%ke));           segment%grad\_tan(:,:,:) = 0.0
3556 \textcolor{keywordflow}{    endif}
3557     \textcolor{keywordflow}{if} (segment%oblique\_grad) \textcolor{keywordflow}{then}
3558       \textcolor{keyword}{allocate}(segment%grad\_gradient(jsd:jed,2,obc%ke));      segment%grad\_gradient(:,:,:) = 0.0
3559 \textcolor{keywordflow}{    endif}
3560 \textcolor{keywordflow}{  endif}
3561 
3562   \textcolor{keywordflow}{if} (segment%is\_N\_or\_S) \textcolor{keywordflow}{then}
3563     \textcolor{comment}{! If these are just Flather, change update\_OBC\_segment\_data accordingly}
3564     \textcolor{keyword}{allocate}(segment%Cg(isd:ied,jsdb:jedb));                  segment%Cg(:,:)=0.
3565     \textcolor{keyword}{allocate}(segment%Htot(isd:ied,jsdb:jedb));                segment%Htot(:,:)=0.0
3566     \textcolor{keyword}{allocate}(segment%h(isd:ied,jsdb:jedb,obc%ke));            segment%h(:,:,:)=0.0
3567     \textcolor{keyword}{allocate}(segment%eta(isd:ied,jsdb:jedb));                 segment%eta(:,:)=0.0
3568     \textcolor{keywordflow}{if} (segment%radiation) \textcolor{keywordflow}{then}
3569       \textcolor{keyword}{allocate}(segment%ry\_norm\_rad(isd:ied,jsdb:jedb,obc%ke));  segment%ry\_norm\_rad(:,:,:)=0.0
3570 \textcolor{keywordflow}{    endif}
3571     \textcolor{keyword}{allocate}(segment%normal\_vel(isd:ied,jsdb:jedb,obc%ke));   segment%normal\_vel(:,:,:)=0.0
3572     \textcolor{keyword}{allocate}(segment%normal\_vel\_bt(isd:ied,jsdb:jedb));       segment%normal\_vel\_bt(:,:)=0.0
3573     \textcolor{keyword}{allocate}(segment%normal\_trans(isd:ied,jsdb:jedb,obc%ke)); segment%normal\_trans(:,:,:)=0.0
3574     \textcolor{keywordflow}{if} (segment%nudged) \textcolor{keywordflow}{then}
3575       \textcolor{keyword}{allocate}(segment%nudged\_normal\_vel(isd:ied,jsdb:jedb,obc%ke)); segment%nudged\_normal\_vel(:,:,:)=0.0
3576 \textcolor{keywordflow}{    endif}
3577     \textcolor{keywordflow}{if} (segment%radiation\_tan .or. segment%nudged\_tan .or. segment%specified\_tan .or. &
3578         segment%oblique\_tan .or. obc%computed\_vorticity .or. obc%computed\_strain) \textcolor{keywordflow}{then}
3579       \textcolor{keyword}{allocate}(segment%tangential\_vel(isdb:iedb,jsdb:jedb,obc%ke)); segment%tangential\_vel(:,:,:)=0.0
3580 \textcolor{keywordflow}{    endif}
3581     \textcolor{keywordflow}{if} (segment%nudged\_tan) \textcolor{keywordflow}{then}
3582       \textcolor{keyword}{allocate}(segment%nudged\_tangential\_vel(isdb:iedb,jsdb:jedb,obc%ke)); segment%nudged\_tangential\_vel(:,
      :,:)=0.0
3583 \textcolor{keywordflow}{    endif}
3584     \textcolor{keywordflow}{if} (segment%nudged\_grad) \textcolor{keywordflow}{then}
3585       \textcolor{keyword}{allocate}(segment%nudged\_tangential\_grad(isdb:iedb,jsdb:jedb,obc%ke)); segment%nudged\_tangential\_grad(
      :,:,:)=0.0
3586 \textcolor{keywordflow}{    endif}
3587     \textcolor{keywordflow}{if} (obc%specified\_vorticity .or. obc%specified\_strain .or. segment%radiation\_grad .or. &
3588               segment%oblique\_grad .or. segment%specified\_grad) \textcolor{keywordflow}{then}
3589       \textcolor{keyword}{allocate}(segment%tangential\_grad(isdb:iedb,jsdb:jedb,obc%ke)); segment%tangential\_grad(:,:,:)=0.0
3590 \textcolor{keywordflow}{    endif}
3591     \textcolor{keywordflow}{if} (segment%oblique) \textcolor{keywordflow}{then}
3592       \textcolor{keyword}{allocate}(segment%grad\_normal(isdb:iedb,2,obc%ke));      segment%grad\_normal(:,:,:) = 0.0
3593       \textcolor{keyword}{allocate}(segment%rx\_norm\_obl(isd:ied,jsdb:jedb,obc%ke));  segment%rx\_norm\_obl(:,:,:)=0.0
3594       \textcolor{keyword}{allocate}(segment%ry\_norm\_obl(isd:ied,jsdb:jedb,obc%ke));  segment%ry\_norm\_obl(:,:,:)=0.0
3595       \textcolor{keyword}{allocate}(segment%cff\_normal(isd:ied,jsdb:jedb,obc%ke)); segment%cff\_normal(:,:,:)=0.0
3596 \textcolor{keywordflow}{    endif}
3597     \textcolor{keywordflow}{if} (segment%oblique\_tan) \textcolor{keywordflow}{then}
3598       \textcolor{keyword}{allocate}(segment%grad\_tan(isd-1:ied+1,2,obc%ke));           segment%grad\_tan(:,:,:) = 0.0
3599 \textcolor{keywordflow}{    endif}
3600     \textcolor{keywordflow}{if} (segment%oblique\_grad) \textcolor{keywordflow}{then}
3601       \textcolor{keyword}{allocate}(segment%grad\_gradient(isd:ied,2,obc%ke));      segment%grad\_gradient(:,:,:) = 0.0
3602 \textcolor{keywordflow}{    endif}
3603 \textcolor{keywordflow}{  endif}
3604 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a5d71c596c3bd7d773a39f5c63d5389ac}\label{namespacemom__open__boundary_a5d71c596c3bd7d773a39f5c63d5389ac}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!deallocate\+\_\+obc\+\_\+segment\+\_\+data@{deallocate\+\_\+obc\+\_\+segment\+\_\+data}}
\index{deallocate\+\_\+obc\+\_\+segment\+\_\+data@{deallocate\+\_\+obc\+\_\+segment\+\_\+data}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{deallocate\+\_\+obc\+\_\+segment\+\_\+data()}{deallocate\_obc\_segment\_data()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::deallocate\+\_\+obc\+\_\+segment\+\_\+data (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{type(\hyperlink{structmom__open__boundary_1_1obc__segment__type}{obc\+\_\+segment\+\_\+type}), intent(inout)}]{segment }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Deallocate segment data fields. 


\begin{DoxyParams}[1]{Parameters}
 & {\em obc} & Open boundary structure\\
\hline
\mbox{\tt in,out}  & {\em segment} & Open boundary segment \\
\hline
\end{DoxyParams}


Definition at line 3609 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
3609   \textcolor{keywordtype}{type}(ocean\_obc\_type),   \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{     !< Open boundary structure}
3610   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{intent(inout)} :: segment\textcolor{comment}{ !< Open boundary segment}
3611   \textcolor{comment}{! Local variables}
3612   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"deallocate\_OBC\_segment\_data"} \textcolor{comment}{! This subroutine's name.}
3613 
3614   \textcolor{keywordflow}{if} (.not. segment%on\_pe) \textcolor{keywordflow}{return}
3615 
3616   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%Cg)) \textcolor{keyword}{deallocate}(segment%Cg)
3617   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%Htot)) \textcolor{keyword}{deallocate}(segment%Htot)
3618   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%h)) \textcolor{keyword}{deallocate}(segment%h)
3619   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%eta)) \textcolor{keyword}{deallocate}(segment%eta)
3620   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%rx\_norm\_rad)) \textcolor{keyword}{deallocate}(segment%rx\_norm\_rad)
3621   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%ry\_norm\_rad)) \textcolor{keyword}{deallocate}(segment%ry\_norm\_rad)
3622   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%rx\_norm\_obl)) \textcolor{keyword}{deallocate}(segment%rx\_norm\_obl)
3623   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%ry\_norm\_obl)) \textcolor{keyword}{deallocate}(segment%ry\_norm\_obl)
3624   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%cff\_normal)) \textcolor{keyword}{deallocate}(segment%cff\_normal)
3625   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%grad\_normal)) \textcolor{keyword}{deallocate}(segment%grad\_normal)
3626   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%grad\_tan)) \textcolor{keyword}{deallocate}(segment%grad\_tan)
3627   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%grad\_gradient)) \textcolor{keyword}{deallocate}(segment%grad\_gradient)
3628   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%normal\_vel)) \textcolor{keyword}{deallocate}(segment%normal\_vel)
3629   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%normal\_vel\_bt)) \textcolor{keyword}{deallocate}(segment%normal\_vel\_bt)
3630   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%normal\_trans)) \textcolor{keyword}{deallocate}(segment%normal\_trans)
3631   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%nudged\_normal\_vel)) \textcolor{keyword}{deallocate}(segment%nudged\_normal\_vel)
3632   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%tangential\_vel)) \textcolor{keyword}{deallocate}(segment%tangential\_vel)
3633   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%nudged\_tangential\_vel)) \textcolor{keyword}{deallocate}(segment%nudged\_tangential\_vel)
3634   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%nudged\_tangential\_grad)) \textcolor{keyword}{deallocate}(segment%nudged\_tangential\_grad)
3635   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%tangential\_grad)) \textcolor{keyword}{deallocate}(segment%tangential\_grad)
3636   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated} (segment%tr\_Reg)) \textcolor{keyword}{call }segment\_tracer\_registry\_end(segment%tr\_Reg)
3637 
3638 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a55081f00e4a95f87ddc5dfe1d61f52e0}\label{namespacemom__open__boundary_a55081f00e4a95f87ddc5dfe1d61f52e0}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!file\+\_\+obc\+\_\+end@{file\+\_\+obc\+\_\+end}}
\index{file\+\_\+obc\+\_\+end@{file\+\_\+obc\+\_\+end}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{file\+\_\+obc\+\_\+end()}{file\_obc\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::file\+\_\+obc\+\_\+end (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1file__obc__cs}{file\+\_\+obc\+\_\+cs}), pointer}]{CS }\end{DoxyParamCaption})}



Clean up the file O\+BC from registry. 


\begin{DoxyParams}{Parameters}
{\em cs} & O\+BC file control structure. \\
\hline
\end{DoxyParams}


Definition at line 4487 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
4487   \textcolor{keywordtype}{type}(file\_obc\_cs), \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{   !< OBC file control structure.}
4488 
4489   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
4490     \textcolor{keyword}{deallocate}(cs)
4491 \textcolor{keywordflow}{  endif}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a70d8b2b93599effe185abbc5a586b35c}\label{namespacemom__open__boundary_a70d8b2b93599effe185abbc5a586b35c}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!fill\+\_\+temp\+\_\+salt\+\_\+segments@{fill\+\_\+temp\+\_\+salt\+\_\+segments}}
\index{fill\+\_\+temp\+\_\+salt\+\_\+segments@{fill\+\_\+temp\+\_\+salt\+\_\+segments}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{fill\+\_\+temp\+\_\+salt\+\_\+segments()}{fill\_temp\_salt\_segments()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::fill\+\_\+temp\+\_\+salt\+\_\+segments (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(inout)}]{tv }\end{DoxyParamCaption})}


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
 & {\em obc} & Open boundary structure\\
\hline
\mbox{\tt in,out}  & {\em tv} & Thermodynamics structure \\
\hline
\end{DoxyParams}


Definition at line 4637 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
4637   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{          !< Ocean grid structure}
4638   \textcolor{keywordtype}{type}(ocean\_obc\_type),       \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{        !< Open boundary structure}
4639   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),      \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{         !< Thermodynamics structure}
4640 
4641 \textcolor{comment}{! Local variables}
4642   \textcolor{keywordtype}{integer} :: isd, ied, isdb, iedb, jsd, jed, jsdb, jedb, n, nz
4643   \textcolor{keywordtype}{integer} :: i, j, k
4644   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null() \textcolor{comment}{! pointer to segment type list}
4645 
4646   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{return}
4647   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(tv%T) .and. \textcolor{keyword}{associated}(tv%S)) \textcolor{keywordflow}{return}
4648   \textcolor{comment}{! Both temperature and salinity fields}
4649 
4650   \textcolor{keyword}{call }pass\_var(tv%T, g%Domain)
4651   \textcolor{keyword}{call }pass\_var(tv%S, g%Domain)
4652 
4653   nz = g%ke
4654 
4655   \textcolor{keywordflow}{do} n=1, obc%number\_of\_segments
4656     segment => obc%segment(n)
4657     \textcolor{keywordflow}{if} (.not. segment%on\_pe) cycle
4658 
4659     isd = segment%HI%isd ; ied = segment%HI%ied
4660     jsd = segment%HI%jsd ; jed = segment%HI%jed
4661     isdb = segment%HI%IsdB ; iedb = segment%HI%IedB
4662     jsdb = segment%HI%JsdB ; jedb = segment%HI%JedB
4663 
4664     \textcolor{comment}{! Fill with T and S values}
4665     \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
4666       i=segment%HI%IsdB
4667       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
4668         \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_w) \textcolor{keywordflow}{then}
4669           segment%tr\_Reg%Tr(1)%t(i,j,k) = tv%T(i+1,j,k)
4670           segment%tr\_Reg%Tr(2)%t(i,j,k) = tv%S(i+1,j,k)
4671         \textcolor{keywordflow}{else}
4672           segment%tr\_Reg%Tr(1)%t(i,j,k) = tv%T(i,j,k)
4673           segment%tr\_Reg%Tr(2)%t(i,j,k) = tv%S(i,j,k)
4674 \textcolor{keywordflow}{        endif}
4675 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
4676     \textcolor{keywordflow}{else}
4677       j=segment%HI%JsdB
4678       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
4679         \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_s) \textcolor{keywordflow}{then}
4680           segment%tr\_Reg%Tr(1)%t(i,j,k) = tv%T(i,j+1,k)
4681           segment%tr\_Reg%Tr(2)%t(i,j,k) = tv%S(i,j+1,k)
4682         \textcolor{keywordflow}{else}
4683           segment%tr\_Reg%Tr(1)%t(i,j,k) = tv%T(i,j,k)
4684           segment%tr\_Reg%Tr(2)%t(i,j,k) = tv%S(i,j,k)
4685 \textcolor{keywordflow}{        endif}
4686 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
4687 \textcolor{keywordflow}{    endif}
4688     segment%tr\_Reg%Tr(1)%tres(:,:,:) = segment%tr\_Reg%Tr(1)%t(:,:,:)
4689     segment%tr\_Reg%Tr(2)%tres(:,:,:) = segment%tr\_Reg%Tr(2)%t(:,:,:)
4690 \textcolor{keywordflow}{  enddo}
4691 
4692   \textcolor{keyword}{call }setup\_obc\_tracer\_reservoirs(g, obc)
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_ab5a04fc90320c3af571f02f8c98f0b18}\label{namespacemom__open__boundary_ab5a04fc90320c3af571f02f8c98f0b18}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!flood\+\_\+fill@{flood\+\_\+fill}}
\index{flood\+\_\+fill@{flood\+\_\+fill}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{flood\+\_\+fill()}{flood\_fill()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::flood\+\_\+fill (\begin{DoxyParamCaption}\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(inout)}]{G,  }\item[{real, dimension(\+:,\+:), intent(inout)}]{color,  }\item[{integer, intent(in)}]{cin,  }\item[{integer, intent(in)}]{cout,  }\item[{integer, intent(in)}]{cland }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



flood the cin, cout values 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in,out}  & {\em color} & For sorting inside from outside\\
\hline
\mbox{\tt in}  & {\em cin} & color for inside the domain\\
\hline
\mbox{\tt in}  & {\em cout} & color for outside the domain\\
\hline
\mbox{\tt in}  & {\em cland} & color for inside the land mask \\
\hline
\end{DoxyParams}


Definition at line 4821 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
4821   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{      !< Ocean grid structure}
4822   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)},   \textcolor{keywordtype}{intent(inout)} :: color\textcolor{comment}{  !< For sorting inside from outside}
4823   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: cin\textcolor{comment}{    !< color for inside the domain}
4824   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: cout\textcolor{comment}{   !< color for outside the domain}
4825   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: cland\textcolor{comment}{  !< color for inside the land mask}
4826 
4827 \textcolor{comment}{! Local variables}
4828   \textcolor{keywordtype}{integer} :: i, j, ncount
4829 
4830   ncount = 1
4831   \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (ncount > 0)
4832     ncount = 0
4833     \textcolor{keywordflow}{do} j=g%jsd+1,g%jed-1
4834       \textcolor{keywordflow}{do} i=g%isd+1,g%ied-1
4835         \textcolor{keywordflow}{if} (color(i,j) == 0.0 .and. color(i-1,j) > 0.0) \textcolor{keywordflow}{then}
4836           color(i,j) = color(i-1,j)
4837           ncount = ncount + 1
4838 \textcolor{keywordflow}{        endif}
4839         \textcolor{keywordflow}{if} (color(i,j) == 0.0 .and. color(i+1,j) > 0.0) \textcolor{keywordflow}{then}
4840           color(i,j) = color(i+1,j)
4841           ncount = ncount + 1
4842 \textcolor{keywordflow}{        endif}
4843         \textcolor{keywordflow}{if} (color(i,j) == 0.0 .and. color(i,j-1) > 0.0) \textcolor{keywordflow}{then}
4844           color(i,j) = color(i,j-1)
4845           ncount = ncount + 1
4846 \textcolor{keywordflow}{        endif}
4847         \textcolor{keywordflow}{if} (color(i,j) == 0.0 .and. color(i,j+1) > 0.0) \textcolor{keywordflow}{then}
4848           color(i,j) = color(i,j+1)
4849           ncount = ncount + 1
4850 \textcolor{keywordflow}{        endif}
4851 \textcolor{keywordflow}{      enddo}
4852 \textcolor{keywordflow}{    enddo}
4853     \textcolor{keywordflow}{do} j=g%jed-1,g%jsd+1,-1
4854       \textcolor{keywordflow}{do} i=g%ied-1,g%isd+1,-1
4855         \textcolor{keywordflow}{if} (color(i,j) == 0.0 .and. color(i-1,j) > 0.0) \textcolor{keywordflow}{then}
4856           color(i,j) = color(i-1,j)
4857           ncount = ncount + 1
4858 \textcolor{keywordflow}{        endif}
4859         \textcolor{keywordflow}{if} (color(i,j) == 0.0 .and. color(i+1,j) > 0.0) \textcolor{keywordflow}{then}
4860           color(i,j) = color(i+1,j)
4861           ncount = ncount + 1
4862 \textcolor{keywordflow}{        endif}
4863         \textcolor{keywordflow}{if} (color(i,j) == 0.0 .and. color(i,j-1) > 0.0) \textcolor{keywordflow}{then}
4864           color(i,j) = color(i,j-1)
4865           ncount = ncount + 1
4866 \textcolor{keywordflow}{        endif}
4867         \textcolor{keywordflow}{if} (color(i,j) == 0.0 .and. color(i,j+1) > 0.0) \textcolor{keywordflow}{then}
4868           color(i,j) = color(i,j+1)
4869           ncount = ncount + 1
4870 \textcolor{keywordflow}{        endif}
4871 \textcolor{keywordflow}{      enddo}
4872 \textcolor{keywordflow}{    enddo}
4873     \textcolor{keyword}{call }pass\_var(color, g%Domain)
4874     \textcolor{keyword}{call }sum\_across\_pes(ncount)
4875 \textcolor{keywordflow}{  enddo}
4876 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a13ac2cc232309a51db31c3b9ee5f22af}\label{namespacemom__open__boundary_a13ac2cc232309a51db31c3b9ee5f22af}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!flood\+\_\+fill2@{flood\+\_\+fill2}}
\index{flood\+\_\+fill2@{flood\+\_\+fill2}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{flood\+\_\+fill2()}{flood\_fill2()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::flood\+\_\+fill2 (\begin{DoxyParamCaption}\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(inout)}]{G,  }\item[{real, dimension(\+:,\+:), intent(inout)}]{color,  }\item[{integer, intent(in)}]{cin,  }\item[{integer, intent(in)}]{cout,  }\item[{integer, intent(in)}]{cland }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



flood the cin, cout values 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in,out}  & {\em color} & For sorting inside from outside\\
\hline
\mbox{\tt in}  & {\em cin} & color for inside the domain\\
\hline
\mbox{\tt in}  & {\em cout} & color for outside the domain\\
\hline
\mbox{\tt in}  & {\em cland} & color for inside the land mask \\
\hline
\end{DoxyParams}


Definition at line 4881 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
4881   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{       !< Ocean grid structure}
4882   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)},   \textcolor{keywordtype}{intent(inout)} :: color\textcolor{comment}{   !< For sorting inside from outside}
4883   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: cin\textcolor{comment}{    !< color for inside the domain}
4884   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: cout\textcolor{comment}{   !< color for outside the domain}
4885   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: cland\textcolor{comment}{  !< color for inside the land mask}
4886 
4887 \textcolor{comment}{! Local variables}
4888   \textcolor{keywordtype}{integer} :: i, j, ncount
4889 
4890   ncount = 1
4891   \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (ncount > 0)
4892     ncount = 0
4893     \textcolor{keywordflow}{do} i=g%isd+1,g%ied-1
4894       \textcolor{keywordflow}{do} j=g%jsd+1,g%jed-1
4895         \textcolor{keywordflow}{if} (color(i,j) == 0.0 .and. color(i-1,j) > 0.0) \textcolor{keywordflow}{then}
4896           color(i,j) = color(i-1,j)
4897           ncount = ncount + 1
4898 \textcolor{keywordflow}{        endif}
4899         \textcolor{keywordflow}{if} (color(i,j) == 0.0 .and. color(i+1,j) > 0.0) \textcolor{keywordflow}{then}
4900           color(i,j) = color(i+1,j)
4901           ncount = ncount + 1
4902 \textcolor{keywordflow}{        endif}
4903         \textcolor{keywordflow}{if} (color(i,j) == 0.0 .and. color(i,j-1) > 0.0) \textcolor{keywordflow}{then}
4904           color(i,j) = color(i,j-1)
4905           ncount = ncount + 1
4906 \textcolor{keywordflow}{        endif}
4907         \textcolor{keywordflow}{if} (color(i,j) == 0.0 .and. color(i,j+1) > 0.0) \textcolor{keywordflow}{then}
4908           color(i,j) = color(i,j+1)
4909           ncount = ncount + 1
4910 \textcolor{keywordflow}{        endif}
4911 \textcolor{keywordflow}{      enddo}
4912 \textcolor{keywordflow}{    enddo}
4913     \textcolor{keywordflow}{do} i=g%ied-1,g%isd+1,-1
4914       \textcolor{keywordflow}{do} j=g%jed-1,g%jsd+1,-1
4915         \textcolor{keywordflow}{if} (color(i,j) == 0.0 .and. color(i-1,j) > 0.0) \textcolor{keywordflow}{then}
4916           color(i,j) = color(i-1,j)
4917           ncount = ncount + 1
4918 \textcolor{keywordflow}{        endif}
4919         \textcolor{keywordflow}{if} (color(i,j) == 0.0 .and. color(i+1,j) > 0.0) \textcolor{keywordflow}{then}
4920           color(i,j) = color(i+1,j)
4921           ncount = ncount + 1
4922 \textcolor{keywordflow}{        endif}
4923         \textcolor{keywordflow}{if} (color(i,j) == 0.0 .and. color(i,j-1) > 0.0) \textcolor{keywordflow}{then}
4924           color(i,j) = color(i,j-1)
4925           ncount = ncount + 1
4926 \textcolor{keywordflow}{        endif}
4927         \textcolor{keywordflow}{if} (color(i,j) == 0.0 .and. color(i,j+1) > 0.0) \textcolor{keywordflow}{then}
4928           color(i,j) = color(i,j+1)
4929           ncount = ncount + 1
4930 \textcolor{keywordflow}{        endif}
4931 \textcolor{keywordflow}{      enddo}
4932 \textcolor{keywordflow}{    enddo}
4933     \textcolor{keyword}{call }pass\_var(color, g%Domain)
4934     \textcolor{keyword}{call }sum\_across\_pes(ncount)
4935 \textcolor{keywordflow}{  enddo}
4936 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a151df14c3b8b1094ddf8f44c86493fd5}\label{namespacemom__open__boundary_a151df14c3b8b1094ddf8f44c86493fd5}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!gradient\+\_\+at\+\_\+q\+\_\+points@{gradient\+\_\+at\+\_\+q\+\_\+points}}
\index{gradient\+\_\+at\+\_\+q\+\_\+points@{gradient\+\_\+at\+\_\+q\+\_\+points}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{gradient\+\_\+at\+\_\+q\+\_\+points()}{gradient\_at\_q\_points()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::gradient\+\_\+at\+\_\+q\+\_\+points (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\hyperlink{structmom__open__boundary_1_1obc__segment__type}{obc\+\_\+segment\+\_\+type}), pointer}]{segment,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{uvel,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{vvel }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculate the tangential gradient of the normal flow at the boundary q-\/points. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
 & {\em segment} & O\+BC segment structure\\
\hline
\mbox{\tt in}  & {\em uvel} & zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em vvel} & meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 3297 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
3297   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{ !< Ocean grid structure}
3298   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment\textcolor{comment}{ !< OBC segment structure}
3299   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: uvel\textcolor{comment}{ !< zonal velocity [L T-1 ~> m s-1]}
3300   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: vvel\textcolor{comment}{ !< meridional velocity [L T-1 ~> m s-1]}
3301   \textcolor{keywordtype}{integer} :: i,j,k
3302 
3303   \textcolor{keywordflow}{if} (.not. segment%on\_pe) \textcolor{keywordflow}{return}
3304 
3305   \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
3306     \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_e) \textcolor{keywordflow}{then}
3307       i=segment%HI%isdB
3308       \textcolor{keywordflow}{do} k=1,g%ke
3309         \textcolor{keywordflow}{do} j=max(segment%HI%JsdB, g%HI%JsdB+1),min(segment%HI%JedB, g%HI%JedB-1)
3310           segment%grad\_normal(j,1,k) = (uvel(i-1,j+1,k)-uvel(i-1,j,k)) * g%mask2dBu(i-1,j)
3311           segment%grad\_normal(j,2,k) = (uvel(i,j+1,k)-uvel(i,j,k)) * g%mask2dBu(i,j)
3312 \textcolor{keywordflow}{        enddo}
3313 \textcolor{keywordflow}{      enddo}
3314       \textcolor{keywordflow}{if} (segment%oblique\_tan) \textcolor{keywordflow}{then}
3315         \textcolor{keywordflow}{do} k=1,g%ke
3316           \textcolor{keywordflow}{do} j=max(segment%HI%jsd-1, g%HI%jsd),min(segment%HI%jed+1, g%HI%jed)
3317             segment%grad\_tan(j,1,k) = (vvel(i-1,j,k)-vvel(i-1,j-1,k)) * g%mask2dT(i-1,j)
3318             segment%grad\_tan(j,2,k) = (vvel(i,j,k)-vvel(i,j-1,k)) * g%mask2dT(i,j)
3319 \textcolor{keywordflow}{          enddo}
3320 \textcolor{keywordflow}{        enddo}
3321 \textcolor{keywordflow}{      endif}
3322       \textcolor{keywordflow}{if} (segment%oblique\_grad) \textcolor{keywordflow}{then}
3323         \textcolor{keywordflow}{do} k=1,g%ke
3324           \textcolor{keywordflow}{do} j=max(segment%HI%jsd, g%HI%jsd+1),min(segment%HI%jed, g%HI%jed-1)
3325             segment%grad\_gradient(j,1,k) = (((vvel(i-1,j,k) - vvel(i-2,j,k))*g%IdxBu(i-2,j)) - &
3326                  (vvel(i-1,j-1,k) - vvel(i-2,j-1,k))*g%IdxBu(i-2,j-1)) * g%mask2dCu(i-2,j)
3327             segment%grad\_gradient(j,2,k) = (((vvel(i,j,k) - vvel(i-1,j,k))*g%IdxBu(i-1,j)) - &
3328                  (vvel(i,j-1,k) - vvel(i-1,j-1,k))*g%IdxBu(i-1,j-1)) * g%mask2dCu(i-1,j)
3329 \textcolor{keywordflow}{          enddo}
3330 \textcolor{keywordflow}{        enddo}
3331 \textcolor{keywordflow}{      endif}
3332     \textcolor{keywordflow}{else} \textcolor{comment}{! western segment}
3333       i=segment%HI%isdB
3334       \textcolor{keywordflow}{do} k=1,g%ke
3335         \textcolor{keywordflow}{do} j=max(segment%HI%JsdB, g%HI%JsdB+1),min(segment%HI%JedB, g%HI%JedB-1)
3336           segment%grad\_normal(j,1,k) = (uvel(i+1,j+1,k)-uvel(i+1,j,k)) * g%mask2dBu(i+1,j)
3337           segment%grad\_normal(j,2,k) = (uvel(i,j+1,k)-uvel(i,j,k)) * g%mask2dBu(i,j)
3338 \textcolor{keywordflow}{        enddo}
3339 \textcolor{keywordflow}{      enddo}
3340       \textcolor{keywordflow}{if} (segment%oblique\_tan) \textcolor{keywordflow}{then}
3341         \textcolor{keywordflow}{do} k=1,g%ke
3342           \textcolor{keywordflow}{do} j=max(segment%HI%jsd-1, g%HI%jsd),min(segment%HI%jed+1, g%HI%jed)
3343             segment%grad\_tan(j,1,k) = (vvel(i+2,j,k)-vvel(i+2,j-1,k)) * g%mask2dT(i+2,j)
3344             segment%grad\_tan(j,2,k) = (vvel(i+1,j,k)-vvel(i+1,j-1,k)) * g%mask2dT(i+1,j)
3345 \textcolor{keywordflow}{          enddo}
3346 \textcolor{keywordflow}{        enddo}
3347 \textcolor{keywordflow}{      endif}
3348       \textcolor{keywordflow}{if} (segment%oblique\_grad) \textcolor{keywordflow}{then}
3349         \textcolor{keywordflow}{do} k=1,g%ke
3350           \textcolor{keywordflow}{do} j=max(segment%HI%jsd, g%HI%jsd+1),min(segment%HI%jed, g%HI%jed-1)
3351             segment%grad\_gradient(j,1,k) = (((vvel(i+3,j,k) - vvel(i+2,j,k))*g%IdxBu(i+2,j)) - &
3352                  (vvel(i+3,j-1,k) - vvel(i+2,j-1,k))*g%IdxBu(i+2,j-1)) * g%mask2dCu(i+2,j)
3353             segment%grad\_gradient(j,2,k) = (((vvel(i+2,j,k) - vvel(i+1,j,k))*g%IdxBu(i+1,j)) - &
3354                  (vvel(i+2,j-1,k) - vvel(i+1,j-1,k))*g%IdxBu(i+1,j-1)) * g%mask2dCu(i+1,j)
3355 \textcolor{keywordflow}{          enddo}
3356 \textcolor{keywordflow}{        enddo}
3357 \textcolor{keywordflow}{      endif}
3358 \textcolor{keywordflow}{    endif}
3359   \textcolor{keywordflow}{elseif} (segment%is\_N\_or\_S) \textcolor{keywordflow}{then}
3360     \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_n) \textcolor{keywordflow}{then}
3361       j=segment%HI%jsdB
3362       \textcolor{keywordflow}{do} k=1,g%ke
3363         \textcolor{keywordflow}{do} i=max(segment%HI%IsdB, g%HI%IsdB+1),min(segment%HI%IedB, g%HI%IedB-1)
3364           segment%grad\_normal(i,1,k) = (vvel(i+1,j-1,k)-vvel(i,j-1,k)) * g%mask2dBu(i,j-1)
3365           segment%grad\_normal(i,2,k) = (vvel(i+1,j,k)-vvel(i,j,k)) * g%mask2dBu(i,j)
3366 \textcolor{keywordflow}{        enddo}
3367 \textcolor{keywordflow}{      enddo}
3368       \textcolor{keywordflow}{if} (segment%oblique\_tan) \textcolor{keywordflow}{then}
3369         \textcolor{keywordflow}{do} k=1,g%ke
3370           \textcolor{keywordflow}{do} i=max(segment%HI%isd-1, g%HI%isd),min(segment%HI%ied+1, g%HI%ied)
3371             segment%grad\_tan(i,1,k) = (uvel(i,j-1,k)-uvel(i-1,j-1,k)) * g%mask2dT(i,j-1)
3372             segment%grad\_tan(i,2,k) = (uvel(i,j,k)-uvel(i-1,j,k)) * g%mask2dT(i,j)
3373 \textcolor{keywordflow}{          enddo}
3374 \textcolor{keywordflow}{        enddo}
3375 \textcolor{keywordflow}{      endif}
3376       \textcolor{keywordflow}{if} (segment%oblique\_grad) \textcolor{keywordflow}{then}
3377         \textcolor{keywordflow}{do} k=1,g%ke
3378           \textcolor{keywordflow}{do} i=max(segment%HI%isd, g%HI%isd+1),min(segment%HI%ied, g%HI%ied-1)
3379             segment%grad\_gradient(i,1,k) = (((uvel(i,j-1,k) - uvel(i,j-2,k))*g%IdyBu(i,j-2)) - &
3380                  (uvel(i-1,j-1,k) - uvel(i-1,j-2,k))*g%IdyBu(i-1,j-2)) * g%mask2dCv(i,j-2)
3381             segment%grad\_gradient(i,2,k) = (((uvel(i,j,k) - uvel(i,j-1,k))*g%IdyBu(i,j-1)) - &
3382                  (uvel(i-1,j,k) - uvel(i-1,j-1,k))*g%IdyBu(i-1,j-1)) * g%mask2dCv(i,j-1)
3383 \textcolor{keywordflow}{          enddo}
3384 \textcolor{keywordflow}{        enddo}
3385 \textcolor{keywordflow}{      endif}
3386     \textcolor{keywordflow}{else} \textcolor{comment}{! south segment}
3387       j=segment%HI%jsdB
3388       \textcolor{keywordflow}{do} k=1,g%ke
3389         \textcolor{keywordflow}{do} i=max(segment%HI%IsdB, g%HI%IsdB+1),min(segment%HI%IedB, g%HI%IedB-1)
3390           segment%grad\_normal(i,1,k) = (vvel(i+1,j+1,k)-vvel(i,j+1,k)) * g%mask2dBu(i,j+1)
3391           segment%grad\_normal(i,2,k) = (vvel(i+1,j,k)-vvel(i,j,k)) * g%mask2dBu(i,j)
3392 \textcolor{keywordflow}{        enddo}
3393 \textcolor{keywordflow}{      enddo}
3394       \textcolor{keywordflow}{if} (segment%oblique\_tan) \textcolor{keywordflow}{then}
3395         \textcolor{keywordflow}{do} k=1,g%ke
3396           \textcolor{keywordflow}{do} i=max(segment%HI%isd-1, g%HI%isd),min(segment%HI%ied+1, g%HI%ied)
3397             segment%grad\_tan(i,1,k) = (uvel(i,j+2,k)-uvel(i-1,j+2,k)) * g%mask2dT(i,j+2)
3398             segment%grad\_tan(i,2,k) = (uvel(i,j+1,k)-uvel(i-1,j+1,k)) * g%mask2dT(i,j+1)
3399 \textcolor{keywordflow}{          enddo}
3400 \textcolor{keywordflow}{        enddo}
3401 \textcolor{keywordflow}{      endif}
3402       \textcolor{keywordflow}{if} (segment%oblique\_grad) \textcolor{keywordflow}{then}
3403         \textcolor{keywordflow}{do} k=1,g%ke
3404           \textcolor{keywordflow}{do} i=max(segment%HI%isd, g%HI%isd+1),min(segment%HI%ied, g%HI%ied-1)
3405             segment%grad\_gradient(i,1,k) = (((uvel(i,j+3,k) - uvel(i,j+2,k))*g%IdyBu(i,j+2)) - &
3406                  (uvel(i-1,j+3,k) - uvel(i-1,j+2,k))*g%IdyBu(i-1,j+2)) * g%mask2dCv(i,j+2)
3407             segment%grad\_gradient(i,2,k) = (((uvel(i,j+2,k) - uvel(i,j+1,k))*g%IdyBu(i,j+1)) - &
3408                  (uvel(i-1,j+2,k) - uvel(i-1,j+1,k))*g%IdyBu(i-1,j+1)) * g%mask2dCv(i,j+1)
3409 \textcolor{keywordflow}{          enddo}
3410 \textcolor{keywordflow}{        enddo}
3411 \textcolor{keywordflow}{      endif}
3412 \textcolor{keywordflow}{    endif}
3413 \textcolor{keywordflow}{  endif}
3414 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a47ad907f8613e7400ac3c6919c22bb11}\label{namespacemom__open__boundary_a47ad907f8613e7400ac3c6919c22bb11}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!initialize\+\_\+obc\+\_\+tides@{initialize\+\_\+obc\+\_\+tides}}
\index{initialize\+\_\+obc\+\_\+tides@{initialize\+\_\+obc\+\_\+tides}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{initialize\+\_\+obc\+\_\+tides()}{initialize\_obc\_tides()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::initialize\+\_\+obc\+\_\+tides (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file }\end{DoxyParamCaption})}


\begin{DoxyParams}[1]{Parameters}
 & {\em obc} & Open boundary control structure\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file handle \\
\hline
\end{DoxyParams}


Definition at line 963 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
963   \textcolor{keywordtype}{type}(ocean\_obc\_type), \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{ !< Open boundary control structure}
964   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file handle}
965   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(3)} :: tide\_ref\_date\textcolor{comment}{      !< Reference date (t = 0) for tidal forcing (year, month,
       day).}
966   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(3)} :: nodal\_ref\_date\textcolor{comment}{     !< Date to calculate nodal modulation for (year, month, day).}
967   \textcolor{keywordtype}{character(len=50)} :: tide\_constituent\_str\textcolor{comment}{   !< List of tidal constituents to include on boundary.}
968   \textcolor{keywordtype}{type}(astro\_longitudes) :: nodal\_longitudes\textcolor{comment}{              !< Solar and lunar longitudes for tidal forcing}
969   \textcolor{keywordtype}{type}(time\_type) :: nodal\_time\textcolor{comment}{                           !< Model time to calculate nodal modulation for.}
970   \textcolor{keywordtype}{integer} :: c\textcolor{comment}{                                            !< Index to tidal constituent.}
971 
972   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_TIDE\_CONSTITUENTS"}, tide\_constituent\_str, &
973       \textcolor{stringliteral}{"Names of tidal constituents being added to the open boundaries."}, &
974       fail\_if\_missing=.true.)
975 
976   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_TIDE\_ADD\_EQ\_PHASE"}, obc%add\_eq\_phase, &
977       \textcolor{stringliteral}{"If true, add the equilibrium phase argument to the specified tidal phases."}, &
978       default=.false., fail\_if\_missing=.false.)
979 
980   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_TIDE\_ADD\_NODAL"}, obc%add\_nodal\_terms, &
981       \textcolor{stringliteral}{"If true, include 18.6 year nodal modulation in the boundary tidal forcing."}, &
982       default=.false.)
983 
984   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_TIDE\_REF\_DATE"}, tide\_ref\_date, &
985       \textcolor{stringliteral}{"Reference date to use for tidal calculations and equilibrium phase."}, &
986       fail\_if\_missing=.true.)
987 
988   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_TIDE\_NODAL\_REF\_DATE"}, nodal\_ref\_date, &
989       \textcolor{stringliteral}{"Fixed reference date to use for nodal modulation of boundary tides."}, &
990       fail\_if\_missing=.false., default=0)
991 
992   \textcolor{keywordflow}{if} (.not. obc%add\_eq\_phase) \textcolor{keywordflow}{then}
993     \textcolor{comment}{! If equilibrium phase argument is not added, the input phases}
994     \textcolor{comment}{! should already be relative to the reference time.}
995     \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{'OBC tidal phases will *not* be corrected with equilibrium arguments.'})
996 \textcolor{keywordflow}{  endif}
997 
998   \textcolor{keyword}{allocate}(obc%tide\_names(obc%n\_tide\_constituents))
999   \textcolor{keyword}{read}(tide\_constituent\_str, *) obc%tide\_names
1000 
1001   \textcolor{comment}{! Set reference time (t = 0) for boundary tidal forcing.}
1002   obc%time\_ref = set\_date(tide\_ref\_date(1), tide\_ref\_date(2), tide\_ref\_date(3))
1003 
1004   \textcolor{comment}{! Find relevant lunar and solar longitudes at the reference time}
1005   \textcolor{keywordflow}{if} (obc%add\_eq\_phase) \textcolor{keyword}{call }astro\_longitudes\_init(obc%time\_ref, obc%tidal\_longitudes)
1006 
1007   \textcolor{comment}{! If the nodal correction is based on a different time, initialize that.}
1008   \textcolor{comment}{! Otherwise, it can use N from the time reference.}
1009   \textcolor{keywordflow}{if} (obc%add\_nodal\_terms) \textcolor{keywordflow}{then}
1010     \textcolor{keywordflow}{if} (sum(nodal\_ref\_date) .ne. 0) \textcolor{keywordflow}{then}
1011       \textcolor{comment}{! A reference date was provided for the nodal correction}
1012       nodal\_time = set\_date(nodal\_ref\_date(1), nodal\_ref\_date(2), nodal\_ref\_date(3))
1013       \textcolor{keyword}{call }astro\_longitudes\_init(nodal\_time, nodal\_longitudes)
1014     \textcolor{keywordflow}{elseif} (obc%add\_eq\_phase) \textcolor{keywordflow}{then}
1015       \textcolor{comment}{! Astronomical longitudes were already calculated for use in equilibrium phases,}
1016       \textcolor{comment}{! so use nodal longitude from that.}
1017       nodal\_longitudes = obc%tidal\_longitudes
1018     \textcolor{keywordflow}{else}
1019       \textcolor{comment}{! Tidal reference time is a required parameter, so calculate the longitudes from that.}
1020       \textcolor{keyword}{call }astro\_longitudes\_init(obc%time\_ref, nodal\_longitudes)
1021 \textcolor{keywordflow}{    endif}
1022 \textcolor{keywordflow}{  endif}
1023 
1024   \textcolor{keyword}{allocate}(obc%tide\_frequencies(obc%n\_tide\_constituents))
1025   \textcolor{keyword}{allocate}(obc%tide\_eq\_phases(obc%n\_tide\_constituents))
1026   \textcolor{keyword}{allocate}(obc%tide\_fn(obc%n\_tide\_constituents))
1027   \textcolor{keyword}{allocate}(obc%tide\_un(obc%n\_tide\_constituents))
1028 
1029   \textcolor{keywordflow}{do} c=1,obc%n\_tide\_constituents
1030     \textcolor{comment}{! If tidal frequency is overridden by setting TIDE\_*\_FREQ, use that, otherwise use the}
1031     \textcolor{comment}{! default realistic frequency for this constituent.}
1032     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"TIDE\_"}//trim(obc%tide\_names(c))//\textcolor{stringliteral}{"\_FREQ"}, obc%tide\_frequencies(c), &
1033         \textcolor{stringliteral}{"Frequency of the "}//trim(obc%tide\_names(c))//\textcolor{stringliteral}{" tidal constituent. "}//&
1034         \textcolor{stringliteral}{"This is only used if TIDES and TIDE\_"}//trim(obc%tide\_names(c))// &
1035         \textcolor{stringliteral}{" are true, or if OBC\_TIDE\_N\_CONSTITUENTS > 0 and "}//trim(obc%tide\_names(c))//&
1036         \textcolor{stringliteral}{" is in OBC\_TIDE\_CONSTITUENTS."}, units=\textcolor{stringliteral}{"s-1"}, default=tidal\_frequency(trim(obc%tide\_names(c))))
1037 
1038     \textcolor{comment}{! Find equilibrum phase if needed}
1039     \textcolor{keywordflow}{if} (obc%add\_eq\_phase) \textcolor{keywordflow}{then}
1040       obc%tide\_eq\_phases(c) = eq\_phase(trim(obc%tide\_names(c)), obc%tidal\_longitudes)
1041     \textcolor{keywordflow}{else}
1042       obc%tide\_eq\_phases(c) = 0.0
1043 \textcolor{keywordflow}{    endif}
1044 
1045     \textcolor{comment}{! Find nodal corrections if needed}
1046     \textcolor{keywordflow}{if} (obc%add\_nodal\_terms) \textcolor{keywordflow}{then}
1047       \textcolor{keyword}{call }nodal\_fu(trim(obc%tide\_names(c)), nodal\_longitudes%N, obc%tide\_fn(c), obc%tide\_un(c))
1048     \textcolor{keywordflow}{else}
1049       obc%tide\_fn(c) = 1.0
1050       obc%tide\_un(c) = 0.0
1051 \textcolor{keywordflow}{    endif}
1052 \textcolor{keywordflow}{  enddo}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a81b020bcce067d3c3a45a21faa526227}\label{namespacemom__open__boundary_a81b020bcce067d3c3a45a21faa526227}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!initialize\+\_\+segment\+\_\+data@{initialize\+\_\+segment\+\_\+data}}
\index{initialize\+\_\+segment\+\_\+data@{initialize\+\_\+segment\+\_\+data}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{initialize\+\_\+segment\+\_\+data()}{initialize\_segment\_data()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::initialize\+\_\+segment\+\_\+data (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), intent(inout)}]{O\+BC,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{PF }\end{DoxyParamCaption})}



Allocate space for reading O\+BC data from files. It sets up the required vertical remapping. In the process, it does funky stuff with the M\+PI processes. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in,out}  & {\em obc} & Open boundary control structure\\
\hline
\mbox{\tt in}  & {\em pf} & Parameter file handle \\
\hline
\end{DoxyParams}


Definition at line 654 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
654   \textcolor{keywordtype}{use }mpp\_mod\textcolor{keywordtype}{, only} : mpp\_pe, mpp\_set\_current\_pelist, mpp\_get\_current\_pelist,mpp\_npes
655 
656   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{   !< Ocean grid structure}
657   \textcolor{keywordtype}{type}(ocean\_obc\_type),   \textcolor{keywordtype}{intent(inout)} :: obc\textcolor{comment}{ !< Open boundary control structure}
658   \textcolor{keywordtype}{type}(param\_file\_type),  \textcolor{keywordtype}{intent(in)}    :: pf\textcolor{comment}{  !< Parameter file handle}
659 
660   \textcolor{keywordtype}{integer} :: n,m,num\_fields
661   \textcolor{keywordtype}{character(len=1024)} :: segstr
662   \textcolor{keywordtype}{character(len=256)} :: filename
663   \textcolor{keywordtype}{character(len=20)}  :: segnam, suffix
664   \textcolor{keywordtype}{character(len=32)}  :: varnam, fieldname
665   \textcolor{keywordtype}{real}               :: value
666   \textcolor{keywordtype}{character(len=32)}, \textcolor{keywordtype}{dimension(MAX\_OBC\_FIELDS)} :: fields  \textcolor{comment}{! segment field names}
667   \textcolor{keywordtype}{character(len=128)} :: inputdir
668   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null() \textcolor{comment}{! pointer to segment type list}
669   \textcolor{keywordtype}{character(len=256)} :: mesg    \textcolor{comment}{! Message for error messages.}
670   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(4)} :: siz,siz2
671   \textcolor{keywordtype}{integer} :: is, ie, js, je
672   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed
673   \textcolor{keywordtype}{integer} :: isdb, iedb, jsdb, jedb
674   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable} :: saved\_pelist
675   \textcolor{keywordtype}{integer} :: current\_pe
676   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(1)} :: single\_pelist
677   \textcolor{comment}{!will be able to dynamically switch between sub-sampling refined grid data or model grid}
678 
679   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
680 
681   \textcolor{comment}{! There is a problem with the order of the OBC initialization}
682   \textcolor{comment}{! with respect to ALE\_init. Currently handling this by copying the}
683   \textcolor{comment}{! param file so that I can use it later in step\_MOM in order to finish}
684   \textcolor{comment}{! initializing segments on the first step.}
685 
686   \textcolor{keyword}{call }get\_param(pf, mdl, \textcolor{stringliteral}{"INPUTDIR"}, inputdir, default=\textcolor{stringliteral}{"."})
687   inputdir = slasher(inputdir)
688 
689   \textcolor{keywordflow}{if} (obc%user\_BCs\_set\_globally) \textcolor{keywordflow}{return}
690 
691   \textcolor{comment}{! Try this here just for the documentation. It is repeated below.}
692   \textcolor{keywordflow}{do} n=1, obc%number\_of\_segments
693     segment => obc%segment(n)
694     \textcolor{keyword}{write}(segnam,\textcolor{stringliteral}{"('OBC\_SEGMENT\_',i3.3,'\_DATA')"}) n
695     \textcolor{keyword}{call }get\_param(pf, mdl, segnam, segstr, \textcolor{stringliteral}{'OBC segment docs'})
696 \textcolor{keywordflow}{  enddo}
697 
698   \textcolor{comment}{!< temporarily disable communication in order to read segment data independently}
699 
700   \textcolor{keyword}{allocate}(saved\_pelist(0:mpp\_npes()-1))
701   \textcolor{keyword}{call }mpp\_get\_current\_pelist(saved\_pelist)
702   current\_pe = mpp\_pe()
703   single\_pelist(1) = current\_pe
704   \textcolor{keyword}{call }mpp\_set\_current\_pelist(single\_pelist)
705 
706   \textcolor{keywordflow}{do} n=1, obc%number\_of\_segments
707     segment => obc%segment(n)
708     \textcolor{keywordflow}{if} (.not. segment%values\_needed) cycle
709 
710     \textcolor{keyword}{write}(segnam,\textcolor{stringliteral}{"('OBC\_SEGMENT\_',i3.3,'\_DATA')"}) n
711     \textcolor{keyword}{write}(suffix,\textcolor{stringliteral}{"('\_segment\_',i3.3)"}) n
712     \textcolor{comment}{! needs documentation !!  Yet, unsafe for now, causes grief for}
713     \textcolor{comment}{! MOM\_parameter\_docs in circle\_obcs on two processes.}
714 \textcolor{comment}{!   call get\_param(PF, mdl, segnam, segstr, 'xyz')}
715     \textcolor{comment}{! Clear out any old values}
716     segstr = \textcolor{stringliteral}{''}
717     \textcolor{keyword}{call }get\_param(pf, mdl, segnam, segstr)
718     \textcolor{keywordflow}{if} (segstr == \textcolor{stringliteral}{''}) \textcolor{keywordflow}{then}
719       \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("No OBC\_SEGMENT\_XXX\_DATA string for OBC segment ",I3)'}) n
720       \textcolor{keyword}{call }mom\_error(fatal, mesg)
721 \textcolor{keywordflow}{    endif}
722 
723     \textcolor{keyword}{call }parse\_segment\_manifest\_str(trim(segstr), num\_fields, fields)
724     \textcolor{keywordflow}{if} (num\_fields == 0) \textcolor{keywordflow}{then}
725       \textcolor{keyword}{call }mom\_mesg(\textcolor{stringliteral}{'initialize\_segment\_data: num\_fields = 0'})
726       cycle \textcolor{comment}{! cycle to next segment}
727 \textcolor{keywordflow}{    endif}
728 
729     \textcolor{keyword}{allocate}(segment%field(num\_fields))
730     segment%num\_fields = num\_fields
731 
732     segment%temp\_segment\_data\_exists=.false.
733     segment%salt\_segment\_data\_exists=.false.
734 \textcolor{comment}{!!}
735 \textcolor{comment}{! CODE HERE FOR OTHER OPTIONS (CLAMPED, NUDGED,..)}
736 \textcolor{comment}{!!}
737 
738     isd = segment%HI%isd ; ied = segment%HI%ied
739     jsd = segment%HI%jsd ; jed = segment%HI%jed
740     isdb = segment%HI%IsdB ; iedb = segment%HI%IedB
741     jsdb = segment%HI%JsdB ; jedb = segment%HI%JedB
742 
743     \textcolor{keywordflow}{do} m=1,num\_fields
744       \textcolor{keyword}{call }parse\_segment\_data\_str(trim(segstr), m, trim(fields(m)), &
745           \textcolor{keywordtype}{value}, filename, fieldname)
746       \textcolor{keywordflow}{if} (trim(filename) /= \textcolor{stringliteral}{'none'}) \textcolor{keywordflow}{then}
747         obc%update\_OBC = .true. \textcolor{comment}{! Data is assumed to be time-dependent if we are reading from file}
748         obc%needs\_IO\_for\_data = .true. \textcolor{comment}{! At least one segment is using I/O for OBC data}
749 \textcolor{comment}{!       segment%values\_needed = .true. ! Indicates that i/o will be needed for this segment}
750         segment%field(m)%name = trim(fields(m))
751         \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'TEMP'}) \textcolor{keywordflow}{then}
752            segment%temp\_segment\_data\_exists=.true.
753            segment%t\_values\_needed = .false.
754 \textcolor{keywordflow}{        endif}
755         \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'SALT'}) \textcolor{keywordflow}{then}
756            segment%salt\_segment\_data\_exists=.true.
757            segment%s\_values\_needed = .false.
758 \textcolor{keywordflow}{        endif}
759         filename = trim(inputdir)//trim(filename)
760         fieldname = trim(fieldname)//trim(suffix)
761         \textcolor{keyword}{call }field\_size(filename,fieldname,siz,no\_domain=.true.)
762 \textcolor{comment}{!       if (siz(4) == 1) segment%values\_needed = .false.}
763         \textcolor{keywordflow}{if} (segment%on\_pe) \textcolor{keywordflow}{then}
764           \textcolor{keywordflow}{if} (obc%brushcutter\_mode .and. (modulo(siz(1),2) == 0 .or. modulo(siz(2),2) == 0)) \textcolor{keywordflow}{then}
765             \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'segment data are not on the supergrid'})
766 \textcolor{keywordflow}{          endif}
767           siz2(1)=1
768 
769           \textcolor{keywordflow}{if} (siz(1)>1) \textcolor{keywordflow}{then}
770             \textcolor{keywordflow}{if} (obc%brushcutter\_mode) \textcolor{keywordflow}{then}
771               siz2(1)=(siz(1)-1)/2
772             \textcolor{keywordflow}{else}
773               siz2(1)=siz(1)
774 \textcolor{keywordflow}{            endif}
775 \textcolor{keywordflow}{          endif}
776           siz2(2)=1
777           \textcolor{keywordflow}{if} (siz(2)>1) \textcolor{keywordflow}{then}
778             \textcolor{keywordflow}{if} (obc%brushcutter\_mode) \textcolor{keywordflow}{then}
779               siz2(2)=(siz(2)-1)/2
780             \textcolor{keywordflow}{else}
781               siz2(2)=siz(2)
782 \textcolor{keywordflow}{            endif}
783 \textcolor{keywordflow}{          endif}
784           siz2(3)=siz(3)
785 
786           \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
787             \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'V'}) \textcolor{keywordflow}{then}
788               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_src(isdb:iedb,jsdb:jedb,siz2(3)))
789               segment%v\_values\_needed = .false.
790             \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Vamp'}) \textcolor{keywordflow}{then}
791               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_src(isdb:iedb,jsdb:jedb,siz2(3)))
792               segment%vamp\_values\_needed = .false.
793               segment%vamp\_index = m
794             \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Vphase'}) \textcolor{keywordflow}{then}
795               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_src(isdb:iedb,jsdb:jedb,siz2(3)))
796               segment%vphase\_values\_needed = .false.
797               segment%vphase\_index = m
798             \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'DVDX'}) \textcolor{keywordflow}{then}
799               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_src(isdb:iedb,jsdb:jedb,siz2(3)))
800               segment%g\_values\_needed = .false.
801             \textcolor{keywordflow}{else}
802               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_src(isdb:iedb,jsd:jed,siz2(3)))
803               \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'U'}) \textcolor{keywordflow}{then}
804                 segment%u\_values\_needed = .false.
805               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Uamp'}) \textcolor{keywordflow}{then}
806                 segment%uamp\_values\_needed = .false.
807                 segment%uamp\_index = m
808               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Uphase'}) \textcolor{keywordflow}{then}
809                 segment%uphase\_values\_needed = .false.
810                 segment%uphase\_index = m
811               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'SSH'}) \textcolor{keywordflow}{then}
812                 segment%z\_values\_needed = .false.
813               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'SSHamp'}) \textcolor{keywordflow}{then}
814                 segment%zamp\_values\_needed = .false.
815                 segment%zamp\_index = m
816               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'SSHphase'}) \textcolor{keywordflow}{then}
817                 segment%zphase\_values\_needed = .false.
818                 segment%zphase\_index = m
819               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'TEMP'}) \textcolor{keywordflow}{then}
820                 segment%t\_values\_needed = .false.
821               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'SALT'}) \textcolor{keywordflow}{then}
822                 segment%s\_values\_needed = .false.
823 \textcolor{keywordflow}{              endif}
824 \textcolor{keywordflow}{            endif}
825           \textcolor{keywordflow}{else}
826             \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'U'}) \textcolor{keywordflow}{then}
827               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_src(isdb:iedb,jsdb:jedb,siz2(3)))
828               segment%u\_values\_needed = .false.
829             \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'DUDY'}) \textcolor{keywordflow}{then}
830               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_src(isdb:iedb,jsdb:jedb,siz2(3)))
831               segment%g\_values\_needed = .false.
832             \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Uamp'}) \textcolor{keywordflow}{then}
833               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_src(isdb:iedb,jsdb:jedb,siz2(3)))
834               segment%uamp\_values\_needed = .false.
835               segment%uamp\_index = m
836             \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Uphase'}) \textcolor{keywordflow}{then}
837               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_src(isdb:iedb,jsdb:jedb,siz2(3)))
838               segment%uphase\_values\_needed = .false.
839               segment%uphase\_index = m
840             \textcolor{keywordflow}{else}
841               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_src(isd:ied,jsdb:jedb,siz2(3)))
842               \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'V'}) \textcolor{keywordflow}{then}
843                 segment%v\_values\_needed = .false.
844               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Vamp'}) \textcolor{keywordflow}{then}
845                 segment%vamp\_values\_needed = .false.
846                 segment%vamp\_index = m
847               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Vphase'}) \textcolor{keywordflow}{then}
848                 segment%vphase\_values\_needed = .false.
849                 segment%vphase\_index = m
850               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'SSH'}) \textcolor{keywordflow}{then}
851                 segment%z\_values\_needed = .false.
852               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'SSHamp'}) \textcolor{keywordflow}{then}
853                 segment%zamp\_values\_needed = .false.
854                 segment%zamp\_index = m
855               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'SSHphase'}) \textcolor{keywordflow}{then}
856                 segment%zphase\_values\_needed = .false.
857                 segment%zphase\_index = m
858               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'TEMP'}) \textcolor{keywordflow}{then}
859                 segment%t\_values\_needed = .false.
860               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'SALT'}) \textcolor{keywordflow}{then}
861                 segment%s\_values\_needed = .false.
862 \textcolor{keywordflow}{              endif}
863 \textcolor{keywordflow}{            endif}
864 \textcolor{keywordflow}{          endif}
865           segment%field(m)%buffer\_src(:,:,:)=0.0
866           segment%field(m)%fid = init\_external\_field(trim(filename),&
867                trim(fieldname),ignore\_axis\_atts=.true.,threading=single\_file)
868           \textcolor{keywordflow}{if} (siz(3) > 1) \textcolor{keywordflow}{then}
869             \textcolor{keywordflow}{if} ((index(segment%field(m)%name, \textcolor{stringliteral}{'phase'}) > 0) .or. (index(segment%field(m)%name, \textcolor{stringliteral}{'amp'}) > 0))
       \textcolor{keywordflow}{then}
870               \textcolor{comment}{! siz(3) is constituent for tidal variables}
871               \textcolor{keyword}{call }field\_size(filename, \textcolor{stringliteral}{'constituent'}, siz, no\_domain=.true.)
872               \textcolor{comment}{! expect third dimension to be number of constituents in MOM\_input}
873               \textcolor{keywordflow}{if} (siz(3) .ne. obc%n\_tide\_constituents .and. obc%add\_tide\_constituents) \textcolor{keywordflow}{then}
874                 \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{'Number of constituents in input data is not '}//&
875                     \textcolor{stringliteral}{'the same as the number specified'})
876 \textcolor{keywordflow}{              endif}
877               segment%field(m)%nk\_src=siz(3)
878             \textcolor{keywordflow}{else}
879               \textcolor{comment}{! siz(3) is depth for everything else}
880               fieldname = \textcolor{stringliteral}{'dz\_'}//trim(fieldname)
881               \textcolor{keyword}{call }field\_size(filename,fieldname,siz,no\_domain=.true.)
882               \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
883                 \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'V'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DVDX'}) \textcolor{keywordflow}{then}
884                   \textcolor{keyword}{allocate}(segment%field(m)%dz\_src(isdb:iedb,jsdb:jedb,siz(3)))
885                 \textcolor{keywordflow}{else}
886                   \textcolor{keyword}{allocate}(segment%field(m)%dz\_src(isdb:iedb,jsd:jed,siz(3)))
887 \textcolor{keywordflow}{                endif}
888               \textcolor{keywordflow}{else}
889                 \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'U'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DUDY'}) \textcolor{keywordflow}{then}
890                   \textcolor{keyword}{allocate}(segment%field(m)%dz\_src(isdb:iedb,jsdb:jedb,siz(3)))
891                 \textcolor{keywordflow}{else}
892                   \textcolor{keyword}{allocate}(segment%field(m)%dz\_src(isd:ied,jsdb:jedb,siz(3)))
893 \textcolor{keywordflow}{                endif}
894 \textcolor{keywordflow}{              endif}
895               segment%field(m)%dz\_src(:,:,:)=0.0
896               segment%field(m)%nk\_src=siz(3)
897               segment%field(m)%fid\_dz = init\_external\_field(trim(filename),trim(fieldname),&
898                         ignore\_axis\_atts=.true.,threading=single\_file)
899 \textcolor{keywordflow}{            endif}
900           \textcolor{keywordflow}{else}
901             segment%field(m)%nk\_src=1
902 \textcolor{keywordflow}{          endif}
903 \textcolor{keywordflow}{        endif}
904       \textcolor{keywordflow}{else}
905         segment%field(m)%fid = -1
906         segment%field(m)%value = \textcolor{keywordtype}{value}
907         segment%field(m)%name = trim(fields(m))
908         \textcolor{comment}{! Check if this is a tidal field. If so, the number}
909         \textcolor{comment}{! of expected constiuents must be 1.}
910         \textcolor{keywordflow}{if} ((index(segment%field(m)%name, \textcolor{stringliteral}{'phase'}) > 0) .or. (index(segment%field(m)%name, \textcolor{stringliteral}{'amp'}) > 0)) \textcolor{keywordflow}{
      then}
911           \textcolor{keywordflow}{if} (obc%n\_tide\_constituents .gt. 1 .and. obc%add\_tide\_constituents) \textcolor{keywordflow}{then}
912             \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{'Only one constituent is supported when specifying '}//&
913                 \textcolor{stringliteral}{'tidal boundary conditions by value rather than file.'})
914 \textcolor{keywordflow}{          endif}
915 \textcolor{keywordflow}{        endif}
916         \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'U'}) \textcolor{keywordflow}{then}
917           segment%u\_values\_needed = .false.
918         \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Uamp'}) \textcolor{keywordflow}{then}
919           segment%uamp\_values\_needed = .false.
920           segment%uamp\_index = m
921         \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Uphase'}) \textcolor{keywordflow}{then}
922           segment%uphase\_values\_needed = .false.
923           segment%uphase\_index = m
924         \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'V'}) \textcolor{keywordflow}{then}
925           segment%v\_values\_needed = .false.
926         \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Vamp'}) \textcolor{keywordflow}{then}
927           segment%vamp\_values\_needed = .false.
928           segment%vamp\_index = m
929         \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Vphase'}) \textcolor{keywordflow}{then}
930           segment%vphase\_values\_needed = .false.
931           segment%vphase\_index = m
932         \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'SSH'}) \textcolor{keywordflow}{then}
933           segment%z\_values\_needed = .false.
934         \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'SSHamp'}) \textcolor{keywordflow}{then}
935           segment%zamp\_values\_needed = .false.
936           segment%zamp\_index = m
937         \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'SSHphase'}) \textcolor{keywordflow}{then}
938           segment%zphase\_values\_needed = .false.
939           segment%zphase\_index = m
940         \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'TEMP'}) \textcolor{keywordflow}{then}
941           segment%t\_values\_needed = .false.
942         \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'SALT'}) \textcolor{keywordflow}{then}
943           segment%s\_values\_needed = .false.
944         \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'DVDX'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DUDY'}) \textcolor{keywordflow}{then}
945           segment%g\_values\_needed = .false.
946 \textcolor{keywordflow}{        endif}
947 \textcolor{keywordflow}{      endif}
948 \textcolor{keywordflow}{    enddo}
949     \textcolor{keywordflow}{if} (segment%u\_values\_needed .or. segment%uamp\_values\_needed .or. segment%uphase\_values\_needed .or. &
950         segment%v\_values\_needed .or. segment%vamp\_values\_needed .or. segment%vphase\_values\_needed .or. &
951         segment%t\_values\_needed .or. segment%s\_values\_needed .or. segment%g\_values\_needed .or. &
952         segment%z\_values\_needed .or. segment%zamp\_values\_needed .or. segment%zphase\_values\_needed ) \textcolor{keywordflow}{then}
953       \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("Values needed for OBC segment ",I3)'}) n
954       \textcolor{keyword}{call }mom\_error(fatal, mesg)
955 \textcolor{keywordflow}{    endif}
956 \textcolor{keywordflow}{  enddo}
957 
958   \textcolor{keyword}{call }mpp\_set\_current\_pelist(saved\_pelist)
959 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a29dd2dc87f43e0e26d22367ce93519ff}\label{namespacemom__open__boundary_a29dd2dc87f43e0e26d22367ce93519ff}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!lookup\+\_\+seg\+\_\+field@{lookup\+\_\+seg\+\_\+field}}
\index{lookup\+\_\+seg\+\_\+field@{lookup\+\_\+seg\+\_\+field}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{lookup\+\_\+seg\+\_\+field()}{lookup\_seg\_field()}}
{\footnotesize\ttfamily integer function mom\+\_\+open\+\_\+boundary\+::lookup\+\_\+seg\+\_\+field (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1obc__segment__type}{obc\+\_\+segment\+\_\+type}), pointer}]{O\+B\+C\+\_\+seg,  }\item[{character(len=32), intent(in)}]{field }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Needs documentation. 


\begin{DoxyParams}[1]{Parameters}
 & {\em obc\+\_\+seg} & O\+BC segment\\
\hline
\mbox{\tt in}  & {\em field} & The field name \\
\hline
\end{DoxyParams}


Definition at line 3483 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
3483   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: obc\_seg\textcolor{comment}{ !< OBC segment}
3484   \textcolor{keywordtype}{character(len=32)}, \textcolor{keywordtype}{intent(in)} :: field\textcolor{comment}{ !< The field name}
3485   \textcolor{keywordtype}{integer} :: lookup\_seg\_field
3486   \textcolor{comment}{! Local variables}
3487   \textcolor{keywordtype}{integer} :: n
3488 
3489   lookup\_seg\_field=-1
3490   \textcolor{keywordflow}{do} n=1,obc\_seg%num\_fields
3491    \textcolor{keywordflow}{if} (trim(field) == obc\_seg%field(n)%name) \textcolor{keywordflow}{then}
3492      lookup\_seg\_field=n
3493      \textcolor{keywordflow}{return}
3494 \textcolor{keywordflow}{   endif}
3495 \textcolor{keywordflow}{  enddo}
3496 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a7dbf161294debd059a40659ba691ca0b}\label{namespacemom__open__boundary_a7dbf161294debd059a40659ba691ca0b}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!mask\+\_\+outside\+\_\+obcs@{mask\+\_\+outside\+\_\+obcs}}
\index{mask\+\_\+outside\+\_\+obcs@{mask\+\_\+outside\+\_\+obcs}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{mask\+\_\+outside\+\_\+obcs()}{mask\_outside\_obcs()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::mask\+\_\+outside\+\_\+obcs (\begin{DoxyParamCaption}\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Find the region outside of all open boundary segments and make sure it is set to land mask. Gonna need to know global land mask as well to get it right... 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file handle\\
\hline
 & {\em obc} & Open boundary structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type \\
\hline
\end{DoxyParams}


Definition at line 4699 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
4699   \textcolor{keywordtype}{type}(dyn\_horgrid\_type),       \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{          !< Ocean grid structure}
4700   \textcolor{keywordtype}{type}(param\_file\_type),        \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file handle}
4701   \textcolor{keywordtype}{type}(ocean\_obc\_type),         \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{        !< Open boundary structure}
4702   \textcolor{keywordtype}{type}(unit\_scale\_type),        \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{         !< A dimensional unit scaling type}
4703 
4704   \textcolor{comment}{! Local variables}
4705   \textcolor{keywordtype}{integer} :: isd, ied, isdb, iedb, jsd, jed, jsdb, jedb, n
4706   \textcolor{keywordtype}{integer} :: i, j
4707   \textcolor{keywordtype}{integer} :: l\_seg
4708   \textcolor{keywordtype}{logical} :: fatal\_error = .false.
4709   \textcolor{keywordtype}{real}    :: min\_depth
4710   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: cin = 3, cout = 4, cland = -1, cedge = -2
4711   \textcolor{keywordtype}{character(len=256)} :: mesg    \textcolor{comment}{! Message for error messages.}
4712   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null() \textcolor{comment}{! pointer to segment type list}
4713   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)} :: color, color2  \textcolor{comment}{! For sorting inside from outside,}
4714                                                       \textcolor{comment}{! two different ways}
4715 
4716   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{return}
4717 
4718   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MINIMUM\_DEPTH"}, min\_depth, &
4719                  units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us%m\_to\_Z, do\_not\_log=.true.)
4720 
4721   \textcolor{keyword}{allocate}(color(g%isd:g%ied, g%jsd:g%jed)) ; color = 0
4722   \textcolor{keyword}{allocate}(color2(g%isd:g%ied, g%jsd:g%jed)) ; color2 = 0
4723 
4724 
4725   \textcolor{comment}{! Paint a frame around the outside.}
4726   \textcolor{keywordflow}{do} j=g%jsd,g%jed
4727     color(g%isd,j) = cedge
4728     color(g%ied,j) = cedge
4729     color2(g%isd,j) = cedge
4730     color2(g%ied,j) = cedge
4731 \textcolor{keywordflow}{  enddo}
4732   \textcolor{keywordflow}{do} i=g%isd,g%ied
4733     color(i,g%jsd) = cedge
4734     color(i,g%jed) = cedge
4735     color2(i,g%jsd) = cedge
4736     color2(i,g%jed) = cedge
4737 \textcolor{keywordflow}{  enddo}
4738 
4739   \textcolor{comment}{! Set color to cland in the land. Note that this is before the land}
4740   \textcolor{comment}{! mask has been initialized, set mask values based on depth.}
4741   \textcolor{keywordflow}{do} j=g%jsd,g%jed
4742     \textcolor{keywordflow}{do} i=g%isd,g%ied
4743       \textcolor{keywordflow}{if} (g%bathyT(i,j) <= min\_depth) color(i,j) = cland
4744       \textcolor{keywordflow}{if} (g%bathyT(i,j) <= min\_depth) color2(i,j) = cland
4745 \textcolor{keywordflow}{    enddo}
4746 \textcolor{keywordflow}{  enddo}
4747 
4748   \textcolor{keywordflow}{do} j=g%jsd,g%jed ; \textcolor{keywordflow}{do} i=g%IsdB+1,g%IedB-1
4749     l\_seg = obc%segnum\_u(i,j)
4750     \textcolor{keywordflow}{if} (l\_seg == obc\_none) cycle
4751 
4752     \textcolor{keywordflow}{if} (obc%segment(l\_seg)%direction == obc\_direction\_w) \textcolor{keywordflow}{then}
4753       \textcolor{keywordflow}{if} (color(i,j) == 0.0) color(i,j) = cout
4754       \textcolor{keywordflow}{if} (color(i+1,j) == 0.0) color(i+1,j) = cin
4755     \textcolor{keywordflow}{elseif} (obc%segment(l\_seg)%direction == obc\_direction\_e) \textcolor{keywordflow}{then}
4756       \textcolor{keywordflow}{if} (color(i,j) == 0.0) color(i,j) = cin
4757       \textcolor{keywordflow}{if} (color(i+1,j) == 0.0) color(i+1,j) = cout
4758 \textcolor{keywordflow}{    endif}
4759 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
4760   \textcolor{keywordflow}{do} j=g%JsdB+1,g%JedB-1 ; \textcolor{keywordflow}{do} i=g%isd,g%ied
4761     l\_seg = obc%segnum\_v(i,j)
4762     \textcolor{keywordflow}{if} (l\_seg == obc\_none) cycle
4763 
4764     \textcolor{keywordflow}{if} (obc%segment(l\_seg)%direction == obc\_direction\_s) \textcolor{keywordflow}{then}
4765       \textcolor{keywordflow}{if} (color(i,j) == 0.0) color(i,j) = cout
4766       \textcolor{keywordflow}{if} (color(i,j+1) == 0.0) color(i,j+1) = cin
4767     \textcolor{keywordflow}{elseif} (obc%segment(l\_seg)%direction == obc\_direction\_n) \textcolor{keywordflow}{then}
4768       \textcolor{keywordflow}{if} (color(i,j) == 0.0) color(i,j) = cin
4769       \textcolor{keywordflow}{if} (color(i,j+1) == 0.0) color(i,j+1) = cout
4770 \textcolor{keywordflow}{    endif}
4771 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
4772 
4773   \textcolor{keywordflow}{do} j=g%JsdB+1,g%JedB-1 ; \textcolor{keywordflow}{do} i=g%isd,g%ied
4774     l\_seg = obc%segnum\_v(i,j)
4775     \textcolor{keywordflow}{if} (l\_seg == obc\_none) cycle
4776 
4777     \textcolor{keywordflow}{if} (obc%segment(l\_seg)%direction == obc\_direction\_s) \textcolor{keywordflow}{then}
4778       \textcolor{keywordflow}{if} (color2(i,j) == 0.0) color2(i,j) = cout
4779       \textcolor{keywordflow}{if} (color2(i,j+1) == 0.0) color2(i,j+1) = cin
4780     \textcolor{keywordflow}{elseif} (obc%segment(l\_seg)%direction == obc\_direction\_n) \textcolor{keywordflow}{then}
4781       \textcolor{keywordflow}{if} (color2(i,j) == 0.0) color2(i,j) = cin
4782       \textcolor{keywordflow}{if} (color2(i,j+1) == 0.0) color2(i,j+1) = cout
4783 \textcolor{keywordflow}{    endif}
4784 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
4785   \textcolor{keywordflow}{do} j=g%jsd,g%jed ; \textcolor{keywordflow}{do} i=g%IsdB+1,g%IedB-1
4786     l\_seg = obc%segnum\_u(i,j)
4787     \textcolor{keywordflow}{if} (l\_seg == obc\_none) cycle
4788 
4789     \textcolor{keywordflow}{if} (obc%segment(l\_seg)%direction == obc\_direction\_w) \textcolor{keywordflow}{then}
4790       \textcolor{keywordflow}{if} (color2(i,j) == 0.0) color2(i,j) = cout
4791       \textcolor{keywordflow}{if} (color2(i+1,j) == 0.0) color2(i+1,j) = cin
4792     \textcolor{keywordflow}{elseif} (obc%segment(l\_seg)%direction == obc\_direction\_e) \textcolor{keywordflow}{then}
4793       \textcolor{keywordflow}{if} (color2(i,j) == 0.0) color2(i,j) = cin
4794       \textcolor{keywordflow}{if} (color2(i+1,j) == 0.0) color2(i+1,j) = cout
4795 \textcolor{keywordflow}{    endif}
4796 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
4797 
4798   \textcolor{comment}{! Do the flood fill until there are no more uncolored cells.}
4799   \textcolor{keyword}{call }flood\_fill(g, color, cin, cout, cland)
4800   \textcolor{keyword}{call }flood\_fill2(g, color2, cin, cout, cland)
4801 
4802   \textcolor{comment}{! Use the color to set outside to min\_depth on this process.}
4803   \textcolor{keywordflow}{do} j=g%jsd,g%jed ; \textcolor{keywordflow}{do} i=g%isd,g%ied
4804     \textcolor{keywordflow}{if} (color(i,j) /= color2(i,j)) \textcolor{keywordflow}{then}
4805       fatal\_error = .true.
4806       \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("MOM\_open\_boundary: problem with OBC segments specification at ",I5,",",I5," during\(\backslash\)n",
       &}
4807 \textcolor{stringliteral}{}\textcolor{stringliteral}{          "the masking of the outside grid points.")'}) i, j
4808       \textcolor{keyword}{call }mom\_error(warning,\textcolor{stringliteral}{"MOM register\_tracer: "}//mesg, all\_print=.true.)
4809 \textcolor{keywordflow}{    endif}
4810     \textcolor{keywordflow}{if} (color(i,j) == cout) g%bathyT(i,j) = min\_depth
4811 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ enddo}
4812   \textcolor{keywordflow}{if} (fatal\_error) \textcolor{keyword}{call }mom\_error(fatal, &
4813       \textcolor{stringliteral}{"MOM\_open\_boundary: inconsistent OBC segments."})
4814 
4815   \textcolor{keyword}{deallocate}(color)
4816   \textcolor{keyword}{deallocate}(color2)
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a0a6e28bbfec6ab82bfe2fd2848902945}\label{namespacemom__open__boundary_a0a6e28bbfec6ab82bfe2fd2848902945}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!obc\+\_\+registry\+\_\+init@{obc\+\_\+registry\+\_\+init}}
\index{obc\+\_\+registry\+\_\+init@{obc\+\_\+registry\+\_\+init}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{obc\+\_\+registry\+\_\+init()}{obc\_registry\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::obc\+\_\+registry\+\_\+init (\begin{DoxyParamCaption}\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\hyperlink{structmom__open__boundary_1_1obc__registry__type}{obc\+\_\+registry\+\_\+type}), pointer}]{Reg }\end{DoxyParamCaption})}



This routine include declares and sets the variable \char`\"{}version\char`\"{}. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em param\+\_\+file} & open file to parse for model parameters\\
\hline
 & {\em reg} & pointer to O\+BC registry \\
\hline
\end{DoxyParams}


Definition at line 4440 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
4440   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< open file to parse for model parameters}
4441   \textcolor{keywordtype}{type}(obc\_registry\_type), \textcolor{keywordtype}{pointer}    :: reg\textcolor{comment}{        !< pointer to OBC registry}
4442 
4443   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{save} :: init\_calls = 0
4444 
4445 \textcolor{preprocessor}{#include "version\_variable.h"}
4446 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"MOM\_open\_boundary"} \textcolor{comment}{! This module's name.}
4447   \textcolor{keywordtype}{character(len=256)} :: mesg    \textcolor{comment}{! Message for error messages.}
4448 
4449   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(reg)) \textcolor{keywordflow}{then} ; \textcolor{keyword}{allocate}(reg)
4450   \textcolor{keywordflow}{else} ; \textcolor{keywordflow}{return} ;\textcolor{keywordflow}{ endif}
4451 
4452   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}
4453 \textcolor{comment}{! call log\_version(param\_file, mdl,s version, "")}
4454 
4455   init\_calls = init\_calls + 1
4456   \textcolor{keywordflow}{if} (init\_calls > 1) \textcolor{keywordflow}{then}
4457     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("OBC\_registry\_init called ",I3, &}
4458 \textcolor{stringliteral}{}\textcolor{stringliteral}{      &" times with different registry pointers.")'}) init\_calls
4459     \textcolor{keywordflow}{if} (is\_root\_pe()) \textcolor{keyword}{call }mom\_error(warning,\textcolor{stringliteral}{"MOM\_open\_boundary"}//mesg)
4460 \textcolor{keywordflow}{  endif}
4461 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a11acc9ede6f2b975bfc6b849a2603b46}\label{namespacemom__open__boundary_a11acc9ede6f2b975bfc6b849a2603b46}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!open\+\_\+boundary\+\_\+apply\+\_\+normal\+\_\+flow@{open\+\_\+boundary\+\_\+apply\+\_\+normal\+\_\+flow}}
\index{open\+\_\+boundary\+\_\+apply\+\_\+normal\+\_\+flow@{open\+\_\+boundary\+\_\+apply\+\_\+normal\+\_\+flow}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{open\+\_\+boundary\+\_\+apply\+\_\+normal\+\_\+flow()}{open\_boundary\_apply\_normal\_flow()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::open\+\_\+boundary\+\_\+apply\+\_\+normal\+\_\+flow (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{u,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{v }\end{DoxyParamCaption})}



Applies O\+BC values stored in segments to 3d u,v fields. 


\begin{DoxyParams}[1]{Parameters}
 & {\em obc} & Open boundary control structure\\
\hline
\mbox{\tt in,out}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in,out}  & {\em u} & u field to update on open boundaries \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em v} & v field to update on open boundaries \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 3229 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
3229   \textcolor{comment}{! Arguments}
3230   \textcolor{keywordtype}{type}(ocean\_obc\_type),                      \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{ !< Open boundary control structure}
3231   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{   !< Ocean grid structure}
3232   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: u\textcolor{comment}{   !< u field to update on open}
3233 \textcolor{comment}{                                                                  !! boundaries [L T-1 ~> m s-1]}
3234   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: v\textcolor{comment}{   !< v field to update on open}
3235 \textcolor{comment}{                                                                  !! boundaries [L T-1 ~> m s-1]}
3236   \textcolor{comment}{! Local variables}
3237   \textcolor{keywordtype}{integer} :: i, j, k, n
3238   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()
3239 
3240   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{return} \textcolor{comment}{! Bail out if OBC is not available}
3241 
3242   \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
3243     segment => obc%segment(n)
3244     \textcolor{keywordflow}{if} (.not. segment%on\_pe) \textcolor{keywordflow}{then}
3245       cycle
3246     \textcolor{keywordflow}{elseif} (segment%radiation .or. segment%oblique .or. segment%gradient) \textcolor{keywordflow}{then}
3247       \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
3248         i=segment%HI%IsdB
3249         \textcolor{keywordflow}{do} k=1,g%ke ;  \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
3250           u(i,j,k) = segment%normal\_vel(i,j,k)
3251 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
3252       \textcolor{keywordflow}{elseif} (segment%is\_N\_or\_S) \textcolor{keywordflow}{then}
3253         j=segment%HI%JsdB
3254         \textcolor{keywordflow}{do} k=1,g%ke ;  \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
3255           v(i,j,k) = segment%normal\_vel(i,j,k)
3256 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
3257 \textcolor{keywordflow}{      endif}
3258 \textcolor{keywordflow}{    endif}
3259 \textcolor{keywordflow}{  enddo}
3260 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_ac94938f1a657896ff03efd3864faa02a}\label{namespacemom__open__boundary_ac94938f1a657896ff03efd3864faa02a}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!open\+\_\+boundary\+\_\+config@{open\+\_\+boundary\+\_\+config}}
\index{open\+\_\+boundary\+\_\+config@{open\+\_\+boundary\+\_\+config}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{open\+\_\+boundary\+\_\+config()}{open\_boundary\_config()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::open\+\_\+boundary\+\_\+config (\begin{DoxyParamCaption}\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC }\end{DoxyParamCaption})}



Enables O\+BC module and reads configuration parameters This routine is called from M\+O\+M\+\_\+initialize\+\_\+fixed which occurs before the initialization of the vertical coordinate and A\+L\+E\+\_\+init. Therefore segment data are not fully initialized here. The remainder of the segment data are initialized in a later call to update\+\_\+open\+\_\+boundary\+\_\+data. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file handle\\
\hline
 & {\em obc} & Open boundary control structure \\
\hline
\end{DoxyParams}


Definition at line 360 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
360   \textcolor{keywordtype}{type}(dyn\_horgrid\_type),  \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{   !< Ocean grid structure}
361   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{  !< A dimensional unit scaling type}
362   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< Parameter file handle}
363   \textcolor{keywordtype}{type}(ocean\_obc\_type),    \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{ !< Open boundary control structure}
364   \textcolor{comment}{! Local variables}
365   \textcolor{keywordtype}{integer} :: l \textcolor{comment}{! For looping over segments}
366   \textcolor{keywordtype}{logical} :: debug\_obc, debug, mask\_outside, reentrant\_x, reentrant\_y
367   \textcolor{keywordtype}{character(len=15)} :: segment\_param\_str \textcolor{comment}{! The run-time parameter name for each segment}
368   \textcolor{keywordtype}{character(len=1024)} :: segment\_str      \textcolor{comment}{! The contents (rhs) for parameter "segment\_param\_str"}
369   \textcolor{keywordtype}{character(len=200)} :: config1          \textcolor{comment}{! String for OBC\_USER\_CONFIG}
370   \textcolor{keywordtype}{real}               :: lscale\_in, lscale\_out \textcolor{comment}{! parameters controlling tracer values at the boundaries [L
       ~> m]}
371   \textcolor{keywordtype}{character(len=128)} :: inputdir
372   \textcolor{keywordtype}{logical} :: answers\_2018, default\_2018\_answers
373   \textcolor{keywordtype}{logical} :: check\_reconstruction, check\_remapping, force\_bounds\_in\_subcell
374   \textcolor{keywordtype}{character(len=32)}  :: remappingscheme
375   \textcolor{keyword}{allocate}(obc)
376 
377   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_NUMBER\_OF\_SEGMENTS"}, obc%number\_of\_segments, &
378                  default=0, do\_not\_log=.true.)
379   \textcolor{keyword}{call }log\_version(param\_file, mdl, version, &
380                  \textcolor{stringliteral}{"Controls where open boundaries are located, what kind of boundary condition "}//&
381                  \textcolor{stringliteral}{"to impose, and what data to apply, if any."}, &
382                  all\_default=(obc%number\_of\_segments<=0))
383   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_NUMBER\_OF\_SEGMENTS"}, obc%number\_of\_segments, &
384                  \textcolor{stringliteral}{"The number of open boundary segments."}, &
385                  default=0)
386   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_USER\_CONFIG"}, config1, &
387                  \textcolor{stringliteral}{"A string that sets how the open boundary conditions are "}//&
388                  \textcolor{stringliteral}{" configured: \(\backslash\)n"}, default=\textcolor{stringliteral}{"none"}, do\_not\_log=.true.)
389   \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"NK"}, obc%ke, &
390                  \textcolor{stringliteral}{"The number of model layers"}, default=0, do\_not\_log=.true.)
391 
392   \textcolor{keywordflow}{if} (config1 /= \textcolor{stringliteral}{"none"} .and. config1 /= \textcolor{stringliteral}{"dyed\_obcs"}) obc%user\_BCs\_set\_globally = .true.
393 
394   \textcolor{keywordflow}{if} (obc%number\_of\_segments > 0) \textcolor{keywordflow}{then}
395     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_ZERO\_VORTICITY"}, obc%zero\_vorticity, &
396          \textcolor{stringliteral}{"If true, sets relative vorticity to zero on open boundaries."}, &
397          default=.false.)
398     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_FREESLIP\_VORTICITY"}, obc%freeslip\_vorticity, &
399          \textcolor{stringliteral}{"If true, sets the normal gradient of tangential velocity to "}//&
400          \textcolor{stringliteral}{"zero in the relative vorticity on open boundaries. This cannot "}//&
401          \textcolor{stringliteral}{"be true if another OBC\_XXX\_VORTICITY option is True."}, default=.true.)
402     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_COMPUTED\_VORTICITY"}, obc%computed\_vorticity, &
403          \textcolor{stringliteral}{"If true, uses the external values of tangential velocity "}//&
404          \textcolor{stringliteral}{"in the relative vorticity on open boundaries. This cannot "}//&
405          \textcolor{stringliteral}{"be true if another OBC\_XXX\_VORTICITY option is True."}, default=.false.)
406     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_SPECIFIED\_VORTICITY"}, obc%specified\_vorticity, &
407          \textcolor{stringliteral}{"If true, uses the external values of tangential velocity "}//&
408          \textcolor{stringliteral}{"in the relative vorticity on open boundaries. This cannot "}//&
409          \textcolor{stringliteral}{"be true if another OBC\_XXX\_VORTICITY option is True."}, default=.false.)
410     \textcolor{keywordflow}{if} ((obc%zero\_vorticity .and. obc%freeslip\_vorticity) .or.  &
411         (obc%zero\_vorticity .and. obc%computed\_vorticity) .or.  &
412         (obc%zero\_vorticity .and. obc%specified\_vorticity) .or.  &
413         (obc%freeslip\_vorticity .and. obc%computed\_vorticity) .or.  &
414         (obc%freeslip\_vorticity .and. obc%specified\_vorticity) .or.  &
415         (obc%computed\_vorticity .and. obc%specified\_vorticity))  &
416          \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, open\_boundary\_config:\(\backslash\)n"}//&
417          \textcolor{stringliteral}{"Only one of OBC\_ZERO\_VORTICITY, OBC\_FREESLIP\_VORTICITY, OBC\_COMPUTED\_VORTICITY\(\backslash\)n"}//&
418          \textcolor{stringliteral}{"and OBC\_IMPORTED\_VORTICITY can be True at once."})
419     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_ZERO\_STRAIN"}, obc%zero\_strain, &
420          \textcolor{stringliteral}{"If true, sets the strain used in the stress tensor to zero on open boundaries."}, &
421          default=.false.)
422     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_FREESLIP\_STRAIN"}, obc%freeslip\_strain, &
423          \textcolor{stringliteral}{"If true, sets the normal gradient of tangential velocity to "}//&
424          \textcolor{stringliteral}{"zero in the strain use in the stress tensor on open boundaries. This cannot "}//&
425          \textcolor{stringliteral}{"be true if another OBC\_XXX\_STRAIN option is True."}, default=.true.)
426     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_COMPUTED\_STRAIN"}, obc%computed\_strain, &
427          \textcolor{stringliteral}{"If true, sets the normal gradient of tangential velocity to "}//&
428          \textcolor{stringliteral}{"zero in the strain use in the stress tensor on open boundaries. This cannot "}//&
429          \textcolor{stringliteral}{"be true if another OBC\_XXX\_STRAIN option is True."}, default=.false.)
430     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_SPECIFIED\_STRAIN"}, obc%specified\_strain, &
431          \textcolor{stringliteral}{"If true, sets the normal gradient of tangential velocity to "}//&
432          \textcolor{stringliteral}{"zero in the strain use in the stress tensor on open boundaries. This cannot "}//&
433          \textcolor{stringliteral}{"be true if another OBC\_XXX\_STRAIN option is True."}, default=.false.)
434     \textcolor{keywordflow}{if} ((obc%zero\_strain .and. obc%freeslip\_strain) .or.  &
435         (obc%zero\_strain .and. obc%computed\_strain) .or.  &
436         (obc%zero\_strain .and. obc%specified\_strain) .or.  &
437         (obc%freeslip\_strain .and. obc%computed\_strain) .or.  &
438         (obc%freeslip\_strain .and. obc%specified\_strain) .or.  &
439         (obc%computed\_strain .and. obc%specified\_strain))  &
440          \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, open\_boundary\_config: \(\backslash\)n"}//&
441          \textcolor{stringliteral}{"Only one of OBC\_ZERO\_STRAIN, OBC\_FREESLIP\_STRAIN, OBC\_COMPUTED\_STRAIN \(\backslash\)n"}//&
442          \textcolor{stringliteral}{"and OBC\_IMPORTED\_STRAIN can be True at once."})
443     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_ZERO\_BIHARMONIC"}, obc%zero\_biharmonic, &
444          \textcolor{stringliteral}{"If true, zeros the Laplacian of flow on open boundaries in the biharmonic "}//&
445          \textcolor{stringliteral}{"viscosity term."}, default=.false.)
446     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"MASK\_OUTSIDE\_OBCS"}, mask\_outside, &
447          \textcolor{stringliteral}{"If true, set the areas outside open boundaries to be land."}, &
448          default=.false.)
449     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"RAMP\_OBCS"}, obc%ramp, &
450          \textcolor{stringliteral}{"If true, ramps from zero to the external values over time, with"}//&
451          \textcolor{stringliteral}{"a ramping timescale given by RAMP\_TIMESCALE. Ramping SSH only so far"}, &
452          default=.false.)
453     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_RAMP\_TIMESCALE"}, obc%ramp\_timescale, &
454          \textcolor{stringliteral}{"If RAMP\_OBCS is true, this sets the ramping timescale."}, &
455          units=\textcolor{stringliteral}{"days"}, default=1.0, scale=86400.0*us%s\_to\_T)
456     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_TIDE\_N\_CONSTITUENTS"}, obc%n\_tide\_constituents, &
457          \textcolor{stringliteral}{"Number of tidal constituents being added to the open boundary."}, &
458          default=0)
459 
460     \textcolor{keywordflow}{if} (obc%n\_tide\_constituents > 0) \textcolor{keywordflow}{then}
461       obc%add\_tide\_constituents = .true.
462     \textcolor{keywordflow}{else}
463       obc%add\_tide\_constituents = .false.
464 \textcolor{keywordflow}{    endif}
465 
466     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEBUG"}, debug, default=.false.)
467     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEBUG\_OBC"}, debug\_obc, default=.false.)
468     \textcolor{keywordflow}{if} (debug\_obc .or. debug) &
469       \textcolor{keyword}{call }log\_param(param\_file, mdl, \textcolor{stringliteral}{"DEBUG\_OBC"}, debug\_obc, &
470                  \textcolor{stringliteral}{"If true, do additional calls to help debug the performance "}//&
471                  \textcolor{stringliteral}{"of the open boundary condition code."}, default=.false., &
472                  debuggingparam=.true.)
473 
474     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_SILLY\_THICK"}, obc%silly\_h, &
475                  \textcolor{stringliteral}{"A silly value of thicknesses used outside of open boundary "}//&
476                  \textcolor{stringliteral}{"conditions for debugging."}, units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us%m\_to\_Z, &
477                  do\_not\_log=.not.debug\_obc, debuggingparam=.true.)
478     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_SILLY\_VEL"}, obc%silly\_u, &
479                  \textcolor{stringliteral}{"A silly value of velocities used outside of open boundary "}//&
480                  \textcolor{stringliteral}{"conditions for debugging."}, units=\textcolor{stringliteral}{"m/s"}, default=0.0, scale=us%m\_s\_to\_L\_T, &
481                  do\_not\_log=.not.debug\_obc, debuggingparam=.true.)
482     reentrant\_x = .false.
483     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REENTRANT\_X"}, reentrant\_x, default=.true.)
484     reentrant\_y = .false.
485     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REENTRANT\_Y"}, reentrant\_y, default=.false.)
486 
487     \textcolor{comment}{! Allocate everything}
488     \textcolor{keyword}{allocate}(obc%segment(1:obc%number\_of\_segments))
489     \textcolor{keywordflow}{do} l=1,obc%number\_of\_segments
490       obc%segment(l)%Flather = .false.
491       obc%segment(l)%radiation = .false.
492       obc%segment(l)%radiation\_tan = .false.
493       obc%segment(l)%radiation\_grad = .false.
494       obc%segment(l)%oblique = .false.
495       obc%segment(l)%oblique\_tan = .false.
496       obc%segment(l)%oblique\_grad = .false.
497       obc%segment(l)%nudged = .false.
498       obc%segment(l)%nudged\_tan = .false.
499       obc%segment(l)%nudged\_grad = .false.
500       obc%segment(l)%specified = .false.
501       obc%segment(l)%specified\_tan = .false.
502       obc%segment(l)%specified\_grad = .false.
503       obc%segment(l)%open = .false.
504       obc%segment(l)%gradient = .false.
505       obc%segment(l)%values\_needed = .false.
506       obc%segment(l)%u\_values\_needed = .false.
507       obc%segment(l)%uamp\_values\_needed = obc%add\_tide\_constituents
508       obc%segment(l)%uphase\_values\_needed = obc%add\_tide\_constituents
509       obc%segment(l)%v\_values\_needed = .false.
510       obc%segment(l)%vamp\_values\_needed = obc%add\_tide\_constituents
511       obc%segment(l)%vphase\_values\_needed = obc%add\_tide\_constituents
512       obc%segment(l)%t\_values\_needed = .false.
513       obc%segment(l)%s\_values\_needed = .false.
514       obc%segment(l)%z\_values\_needed = .false.
515       obc%segment(l)%zamp\_values\_needed = obc%add\_tide\_constituents
516       obc%segment(l)%zphase\_values\_needed = obc%add\_tide\_constituents
517       obc%segment(l)%g\_values\_needed = .false.
518       obc%segment(l)%direction = obc\_none
519       obc%segment(l)%is\_N\_or\_S = .false.
520       obc%segment(l)%is\_E\_or\_W = .false.
521       obc%segment(l)%is\_E\_or\_W\_2 = .false.
522       obc%segment(l)%Velocity\_nudging\_timescale\_in = 0.0
523       obc%segment(l)%Velocity\_nudging\_timescale\_out = 0.0
524       obc%segment(l)%num\_fields = 0
525 \textcolor{keywordflow}{    enddo}
526     \textcolor{keyword}{allocate}(obc%segnum\_u(g%IsdB:g%IedB,g%jsd:g%jed)) ; obc%segnum\_u(:,:) = obc\_none
527     \textcolor{keyword}{allocate}(obc%segnum\_v(g%isd:g%ied,g%JsdB:g%JedB)) ; obc%segnum\_v(:,:) = obc\_none
528 
529     \textcolor{keywordflow}{do} l = 1, obc%number\_of\_segments
530       \textcolor{keyword}{write}(segment\_param\_str(1:15),\textcolor{stringliteral}{"('OBC\_SEGMENT\_',i3.3)"}) l
531       \textcolor{keyword}{call }get\_param(param\_file, mdl, segment\_param\_str, segment\_str, &
532            \textcolor{stringliteral}{"Documentation needs to be dynamic?????"}, &
533            fail\_if\_missing=.true.)
534       segment\_str = remove\_spaces(segment\_str)
535       \textcolor{keywordflow}{if} (segment\_str(1:2) == \textcolor{stringliteral}{'I='}) \textcolor{keywordflow}{then}
536         \textcolor{keyword}{call }setup\_u\_point\_obc(obc, g, us, segment\_str, l, param\_file, reentrant\_y)
537       \textcolor{keywordflow}{elseif} (segment\_str(1:2) == \textcolor{stringliteral}{'J='}) \textcolor{keywordflow}{then}
538         \textcolor{keyword}{call }setup\_v\_point\_obc(obc, g, us, segment\_str, l, param\_file, reentrant\_x)
539       \textcolor{keywordflow}{else}
540         \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, open\_boundary\_config: "}//&
541              \textcolor{stringliteral}{"Unable to interpret "}//segment\_param\_str//\textcolor{stringliteral}{" = "}//trim(segment\_str))
542 \textcolor{keywordflow}{      endif}
543 \textcolor{keywordflow}{    enddo}
544 
545     \textcolor{comment}{! Moved this earlier because time\_interp\_external\_init needs to be called}
546     \textcolor{comment}{! before anything that uses time\_interp\_external (such as initialize\_segment\_data)}
547     \textcolor{keywordflow}{if} (obc%specified\_u\_BCs\_exist\_globally .or. obc%specified\_v\_BCs\_exist\_globally .or. &
548       obc%open\_u\_BCs\_exist\_globally .or. obc%open\_v\_BCs\_exist\_globally) \textcolor{keywordflow}{then}
549       \textcolor{comment}{! Need this for ocean\_only mode boundary interpolation.}
550       \textcolor{keyword}{call }time\_interp\_external\_init()
551 \textcolor{keywordflow}{    endif}
552     \textcolor{comment}{!    if (open\_boundary\_query(OBC, needs\_ext\_seg\_data=.true.)) &}
553  \textcolor{comment}{!   call initialize\_segment\_data(G, OBC, param\_file)}
554 
555     \textcolor{keywordflow}{if} (open\_boundary\_query(obc, apply\_open\_obc=.true.)) \textcolor{keywordflow}{then}
556       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_RADIATION\_MAX"}, obc%rx\_max, &
557                    \textcolor{stringliteral}{"The maximum magnitude of the baroclinic radiation velocity (or speed of "}//&
558                    \textcolor{stringliteral}{"characteristics), in gridpoints per timestep.  This is only "}//&
559                    \textcolor{stringliteral}{"used if one of the open boundary segments is using Orlanski."}, &
560                    units=\textcolor{stringliteral}{"nondim"}, default=1.0)
561       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_RAD\_VEL\_WT"}, obc%gamma\_uv, &
562                    \textcolor{stringliteral}{"The relative weighting for the baroclinic radiation "}//&
563                    \textcolor{stringliteral}{"velocities (or speed of characteristics) at the new "}//&
564                    \textcolor{stringliteral}{"time level (1) or the running mean (0) for velocities. "}//&
565                    \textcolor{stringliteral}{"Valid values range from 0 to 1. This is only used if "}//&
566                    \textcolor{stringliteral}{"one of the open boundary segments is using Orlanski."}, &
567                    units=\textcolor{stringliteral}{"nondim"}, default=0.3)
568 \textcolor{keywordflow}{    endif}
569 
570     lscale\_in = 0.
571     lscale\_out = 0.
572     \textcolor{keywordflow}{if} (open\_boundary\_query(obc, apply\_open\_obc=.true.)) \textcolor{keywordflow}{then}
573       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_TRACER\_RESERVOIR\_LENGTH\_SCALE\_OUT "}, lscale\_out, &
574                  \textcolor{stringliteral}{"An effective length scale for restoring the tracer concentration "}//&
575                  \textcolor{stringliteral}{"at the boundaries to externally imposed values when the flow "}//&
576                  \textcolor{stringliteral}{"is exiting the domain."}, units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us%m\_to\_L)
577 
578       \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"OBC\_TRACER\_RESERVOIR\_LENGTH\_SCALE\_IN "}, lscale\_in, &
579                  \textcolor{stringliteral}{"An effective length scale for restoring the tracer concentration "}//&
580                  \textcolor{stringliteral}{"at the boundaries to values from the interior when the flow "}//&
581                  \textcolor{stringliteral}{"is entering the domain."}, units=\textcolor{stringliteral}{"m"}, default=0.0, scale=us%m\_to\_L)
582 \textcolor{keywordflow}{    endif}
583 
584     \textcolor{keywordflow}{if} (mask\_outside) \textcolor{keyword}{call }mask\_outside\_obcs(g, us, param\_file, obc)
585 
586     \textcolor{comment}{! All tracers are using the same restoring length scale for now, but we may want to make this}
587     \textcolor{comment}{! tracer-specific in the future for example, in cases where certain tracers are poorly constrained}
588     \textcolor{comment}{! by data while others are well constrained - MJH.}
589     \textcolor{keywordflow}{do} l = 1, obc%number\_of\_segments
590       obc%segment(l)%Tr\_InvLscale\_in = 0.0
591       \textcolor{keywordflow}{if} (lscale\_in>0.) obc%segment(l)%Tr\_InvLscale\_in =  1.0/lscale\_in
592       obc%segment(l)%Tr\_InvLscale\_out = 0.0
593       \textcolor{keywordflow}{if} (lscale\_out>0.) obc%segment(l)%Tr\_InvLscale\_out =  1.0/lscale\_out
594 \textcolor{keywordflow}{    enddo}
595 
596     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REMAPPING\_SCHEME"}, remappingscheme, &
597           \textcolor{stringliteral}{"This sets the reconstruction scheme used "}//&
598           \textcolor{stringliteral}{"for vertical remapping for all variables. "}//&
599           \textcolor{stringliteral}{"It can be one of the following schemes: \(\backslash\)n"}//&
600           trim(remappingschemesdoc), default=remappingdefaultscheme,do\_not\_log=.true.)
601     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"FATAL\_CHECK\_RECONSTRUCTIONS"}, check\_reconstruction, &
602           \textcolor{stringliteral}{"If true, cell-by-cell reconstructions are checked for "}//&
603           \textcolor{stringliteral}{"consistency and if non-monotonicity or an inconsistency is "}//&
604           \textcolor{stringliteral}{"detected then a FATAL error is issued."}, default=.false.,do\_not\_log=.true.)
605     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"FATAL\_CHECK\_REMAPPING"}, check\_remapping, &
606           \textcolor{stringliteral}{"If true, the results of remapping are checked for "}//&
607           \textcolor{stringliteral}{"conservation and new extrema and if an inconsistency is "}//&
608           \textcolor{stringliteral}{"detected then a FATAL error is issued."}, default=.false.,do\_not\_log=.true.)
609     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"BRUSHCUTTER\_MODE"}, obc%brushcutter\_mode, &
610          \textcolor{stringliteral}{"If true, read external OBC data on the supergrid."}, &
611          default=.false.)
612     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REMAP\_BOUND\_INTERMEDIATE\_VALUES"}, force\_bounds\_in\_subcell, &
613           \textcolor{stringliteral}{"If true, the values on the intermediate grid used for remapping "}//&
614           \textcolor{stringliteral}{"are forced to be bounded, which might not be the case due to "}//&
615           \textcolor{stringliteral}{"round off."}, default=.false.,do\_not\_log=.true.)
616     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"DEFAULT\_2018\_ANSWERS"}, default\_2018\_answers, &
617                  \textcolor{stringliteral}{"This sets the default value for the various \_2018\_ANSWERS parameters."}, &
618                  default=.false.)
619     \textcolor{keyword}{call }get\_param(param\_file, mdl, \textcolor{stringliteral}{"REMAPPING\_2018\_ANSWERS"}, answers\_2018, &
620                  \textcolor{stringliteral}{"If true, use the order of arithmetic and expressions that recover the "}//&
621                  \textcolor{stringliteral}{"answers from the end of 2018.  Otherwise, use updated and more robust "}//&
622                  \textcolor{stringliteral}{"forms of the same expressions."}, default=default\_2018\_answers)
623 
624     \textcolor{keyword}{allocate}(obc%remap\_CS)
625     \textcolor{keyword}{call }initialize\_remapping(obc%remap\_CS, remappingscheme, boundary\_extrapolation = .false., &
626                check\_reconstruction=check\_reconstruction, check\_remapping=check\_remapping, &
627                force\_bounds\_in\_subcell=force\_bounds\_in\_subcell, answers\_2018=answers\_2018)
628 
629 \textcolor{keywordflow}{  endif} \textcolor{comment}{! OBC%number\_of\_segments > 0}
630 
631     \textcolor{comment}{! Safety check}
632   \textcolor{keywordflow}{if} ((obc%open\_u\_BCs\_exist\_globally .or. obc%open\_v\_BCs\_exist\_globally) .and. &
633        .not.g%symmetric ) \textcolor{keyword}{call }mom\_error(fatal, &
634        \textcolor{stringliteral}{"MOM\_open\_boundary, open\_boundary\_config: "}//&
635        \textcolor{stringliteral}{"Symmetric memory must be used when using Flather OBCs."})
636   \textcolor{comment}{! Need to do this last, because it depends on time\_interp\_external\_init having already been called}
637   \textcolor{keywordflow}{if} (obc%add\_tide\_constituents) \textcolor{keywordflow}{then}
638     \textcolor{keyword}{call }initialize\_obc\_tides(obc, param\_file)
639     \textcolor{comment}{! Tide update is done within update\_OBC\_segment\_data, so this should be true if tides are included.}
640     obc%update\_OBC = .true.
641 \textcolor{keywordflow}{  endif}
642 
643   \textcolor{keywordflow}{if} (.not.(obc%specified\_u\_BCs\_exist\_globally .or. obc%specified\_v\_BCs\_exist\_globally .or. &
644               obc%open\_u\_BCs\_exist\_globally .or. obc%open\_v\_BCs\_exist\_globally)) \textcolor{keywordflow}{then}
645     \textcolor{comment}{! No open boundaries have been requested}
646     \textcolor{keyword}{call }open\_boundary\_dealloc(obc)
647 \textcolor{keywordflow}{  endif}
648 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a709a33b9e33b5689d5ca73349ed51fb6}\label{namespacemom__open__boundary_a709a33b9e33b5689d5ca73349ed51fb6}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!open\+\_\+boundary\+\_\+dealloc@{open\+\_\+boundary\+\_\+dealloc}}
\index{open\+\_\+boundary\+\_\+dealloc@{open\+\_\+boundary\+\_\+dealloc}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{open\+\_\+boundary\+\_\+dealloc()}{open\_boundary\_dealloc()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::open\+\_\+boundary\+\_\+dealloc (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Deallocate open boundary data. 


\begin{DoxyParams}{Parameters}
{\em obc} & Open boundary control structure \\
\hline
\end{DoxyParams}


Definition at line 1894 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
1894   \textcolor{keywordtype}{type}(ocean\_obc\_type), \textcolor{keywordtype}{pointer} :: obc\textcolor{comment}{ !< Open boundary control structure}
1895   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()
1896   \textcolor{keywordtype}{integer} :: n
1897 
1898   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{return}
1899 
1900   \textcolor{keywordflow}{do} n=1, obc%number\_of\_segments
1901     segment => obc%segment(n)
1902     \textcolor{keyword}{call }deallocate\_obc\_segment\_data(obc, segment)
1903 \textcolor{keywordflow}{  enddo}
1904   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc%segment)) \textcolor{keyword}{deallocate}(obc%segment)
1905   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc%segnum\_u)) \textcolor{keyword}{deallocate}(obc%segnum\_u)
1906   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc%segnum\_v)) \textcolor{keyword}{deallocate}(obc%segnum\_v)
1907   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc%rx\_normal)) \textcolor{keyword}{deallocate}(obc%rx\_normal)
1908   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc%ry\_normal)) \textcolor{keyword}{deallocate}(obc%ry\_normal)
1909   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc%rx\_oblique)) \textcolor{keyword}{deallocate}(obc%rx\_oblique)
1910   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc%ry\_oblique)) \textcolor{keyword}{deallocate}(obc%ry\_oblique)
1911   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc%cff\_normal)) \textcolor{keyword}{deallocate}(obc%cff\_normal)
1912   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc%tres\_x)) \textcolor{keyword}{deallocate}(obc%tres\_x)
1913   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc%tres\_y)) \textcolor{keyword}{deallocate}(obc%tres\_y)
1914   \textcolor{keyword}{deallocate}(obc)
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_afb86d9ee7fc99dea787b88cfdb70f139}\label{namespacemom__open__boundary_afb86d9ee7fc99dea787b88cfdb70f139}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!open\+\_\+boundary\+\_\+end@{open\+\_\+boundary\+\_\+end}}
\index{open\+\_\+boundary\+\_\+end@{open\+\_\+boundary\+\_\+end}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{open\+\_\+boundary\+\_\+end()}{open\_boundary\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::open\+\_\+boundary\+\_\+end (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC }\end{DoxyParamCaption})}



Close open boundary data. 


\begin{DoxyParams}{Parameters}
{\em obc} & Open boundary control structure \\
\hline
\end{DoxyParams}


Definition at line 1919 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
1919   \textcolor{keywordtype}{type}(ocean\_obc\_type), \textcolor{keywordtype}{pointer} :: obc\textcolor{comment}{ !< Open boundary control structure}
1920   \textcolor{keyword}{call }open\_boundary\_dealloc(obc)
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a7aa6f2b520108ce761ef107557f69069}\label{namespacemom__open__boundary_a7aa6f2b520108ce761ef107557f69069}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!open\+\_\+boundary\+\_\+impose\+\_\+land\+\_\+mask@{open\+\_\+boundary\+\_\+impose\+\_\+land\+\_\+mask}}
\index{open\+\_\+boundary\+\_\+impose\+\_\+land\+\_\+mask@{open\+\_\+boundary\+\_\+impose\+\_\+land\+\_\+mask}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{open\+\_\+boundary\+\_\+impose\+\_\+land\+\_\+mask()}{open\_boundary\_impose\_land\_mask()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::open\+\_\+boundary\+\_\+impose\+\_\+land\+\_\+mask (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(inout)}]{G,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g)), intent(inout)}]{area\+Cu,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g)), intent(inout)}]{area\+Cv,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US }\end{DoxyParamCaption})}



Reconcile masks and open boundaries, deallocate O\+BC on P\+Es where it is not needed. Also adjust u-\/ and v-\/point cell area on specified open boundaries and mask all points outside open boundaries. 


\begin{DoxyParams}[1]{Parameters}
 & {\em obc} & Open boundary control structure\\
\hline
\mbox{\tt in,out}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in,out}  & {\em areacu} & Area of a u-\/cell \mbox{[}L2 $\sim$$>$ m2\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em areacv} & Area of a u-\/cell \mbox{[}L2 $\sim$$>$ m2\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 1970 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
1970   \textcolor{keywordtype}{type}(ocean\_obc\_type),              \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{ !< Open boundary control structure}
1971   \textcolor{keywordtype}{type}(dyn\_horgrid\_type),            \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{   !< Ocean grid structure}
1972   \textcolor{keywordtype}{type}(unit\_scale\_type),             \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{  !< A dimensional unit scaling type}
1973   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(inout)} :: areacu\textcolor{comment}{ !< Area of a u-cell [L2 ~> m2]}
1974   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G))}, \textcolor{keywordtype}{intent(inout)} :: areacv\textcolor{comment}{ !< Area of a u-cell [L2 ~> m2]}
1975   \textcolor{comment}{! Local variables}
1976   \textcolor{keywordtype}{integer} :: i, j, n
1977   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()
1978   \textcolor{keywordtype}{logical} :: any\_u, any\_v
1979 
1980   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{return}
1981 
1982   \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
1983     segment=>obc%segment(n)
1984     \textcolor{keywordflow}{if} (.not. segment%on\_pe) cycle
1985     \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
1986       \textcolor{comment}{! Sweep along u-segments and delete the OBC for blocked points.}
1987       \textcolor{comment}{! Also, mask all points outside.}
1988       i=segment%HI%IsdB
1989       \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
1990         \textcolor{keywordflow}{if} (g%mask2dCu(i,j) == 0) obc%segnum\_u(i,j) = obc\_none
1991         \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_w) \textcolor{keywordflow}{then}
1992           g%mask2dT(i,j) = 0
1993         \textcolor{keywordflow}{else}
1994           g%mask2dT(i+1,j) = 0
1995 \textcolor{keywordflow}{        endif}
1996 \textcolor{keywordflow}{      enddo}
1997       \textcolor{keywordflow}{do} j=segment%HI%JsdB+1,segment%HI%JedB-1
1998         \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_w) \textcolor{keywordflow}{then}
1999           g%mask2dCv(i,j) = 0
2000         \textcolor{keywordflow}{else}
2001           g%mask2dCv(i+1,j) = 0
2002 \textcolor{keywordflow}{        endif}
2003 \textcolor{keywordflow}{      enddo}
2004     \textcolor{keywordflow}{else}
2005       \textcolor{comment}{! Sweep along v-segments and delete the OBC for blocked points.}
2006       j=segment%HI%JsdB
2007       \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
2008         \textcolor{keywordflow}{if} (g%mask2dCv(i,j) == 0) obc%segnum\_v(i,j) = obc\_none
2009         \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_s) \textcolor{keywordflow}{then}
2010           g%mask2dT(i,j) = 0
2011         \textcolor{keywordflow}{else}
2012           g%mask2dT(i,j+1) = 0
2013 \textcolor{keywordflow}{        endif}
2014 \textcolor{keywordflow}{      enddo}
2015       \textcolor{keywordflow}{do} i=segment%HI%IsdB+1,segment%HI%IedB-1
2016         \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_s) \textcolor{keywordflow}{then}
2017           g%mask2dCu(i,j) = 0
2018         \textcolor{keywordflow}{else}
2019           g%mask2dCu(i,j+1) = 0
2020 \textcolor{keywordflow}{        endif}
2021 \textcolor{keywordflow}{      enddo}
2022 \textcolor{keywordflow}{    endif}
2023 \textcolor{keywordflow}{  enddo}
2024 
2025   \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
2026     segment=>obc%segment(n)
2027     \textcolor{keywordflow}{if} (.not. segment%on\_pe .or. .not. segment%specified) cycle
2028     \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
2029       \textcolor{comment}{! Sweep along u-segments and for %specified BC points reset the u-point area which was masked out}
2030       i=segment%HI%IsdB
2031       \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
2032         \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_e) \textcolor{keywordflow}{then}
2033           areacu(i,j) = g%areaT(i,j)   \textcolor{comment}{! Both of these are in [L2 ~> m2]}
2034         \textcolor{keywordflow}{else}   \textcolor{comment}{! West}
2035           areacu(i,j) = g%areaT(i+1,j) \textcolor{comment}{! Both of these are in [L2 ~> m2]}
2036 \textcolor{keywordflow}{        endif}
2037 \textcolor{keywordflow}{      enddo}
2038     \textcolor{keywordflow}{else}
2039       \textcolor{comment}{! Sweep along v-segments and for %specified BC points reset the v-point area which was masked out}
2040       j=segment%HI%JsdB
2041       \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
2042         \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_s) \textcolor{keywordflow}{then}
2043           areacv(i,j) = g%areaT(i,j+1) \textcolor{comment}{! Both of these are in [L2 ~> m2]}
2044         \textcolor{keywordflow}{else}      \textcolor{comment}{! North}
2045           areacu(i,j) = g%areaT(i,j)   \textcolor{comment}{! Both of these are in [L2 ~> m2]}
2046 \textcolor{keywordflow}{        endif}
2047 \textcolor{keywordflow}{      enddo}
2048 \textcolor{keywordflow}{    endif}
2049 \textcolor{keywordflow}{  enddo}
2050 
2051   \textcolor{comment}{! G%mask2du will be open wherever bathymetry allows it.}
2052   \textcolor{comment}{! Bathymetry outside of the open boundary was adjusted to match}
2053   \textcolor{comment}{! the bathymetry inside so these points will be open unless the}
2054   \textcolor{comment}{! bathymetry inside the boundary was too shallow and flagged as land.}
2055   any\_u = .false.
2056   any\_v = .false.
2057   \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
2058     segment=>obc%segment(n)
2059     \textcolor{keywordflow}{if} (.not. segment%on\_pe) cycle
2060     \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
2061       i=segment%HI%IsdB
2062       \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
2063         \textcolor{keywordflow}{if} (obc%segnum\_u(i,j) /= obc\_none) any\_u = .true.
2064 \textcolor{keywordflow}{      enddo}
2065     \textcolor{keywordflow}{else}
2066       j=segment%HI%JsdB
2067       \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
2068         \textcolor{keywordflow}{if} (obc%segnum\_v(i,j) /= obc\_none) any\_v = .true.
2069 \textcolor{keywordflow}{      enddo}
2070 \textcolor{keywordflow}{    endif}
2071 \textcolor{keywordflow}{  enddo}
2072 
2073   obc%OBC\_pe = .true.
2074   \textcolor{keywordflow}{if} (.not.(any\_u .or. any\_v)) obc%OBC\_pe = .false.
2075 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_afc301353fde1f12ef04dab751ddb7ac2}\label{namespacemom__open__boundary_afc301353fde1f12ef04dab751ddb7ac2}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!open\+\_\+boundary\+\_\+impose\+\_\+normal\+\_\+slope@{open\+\_\+boundary\+\_\+impose\+\_\+normal\+\_\+slope}}
\index{open\+\_\+boundary\+\_\+impose\+\_\+normal\+\_\+slope@{open\+\_\+boundary\+\_\+impose\+\_\+normal\+\_\+slope}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{open\+\_\+boundary\+\_\+impose\+\_\+normal\+\_\+slope()}{open\_boundary\_impose\_normal\_slope()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::open\+\_\+boundary\+\_\+impose\+\_\+normal\+\_\+slope (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(in)}]{G,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g)), intent(inout)}]{depth }\end{DoxyParamCaption})}



Sets the slope of bathymetry normal to an open bounndary to zero. 


\begin{DoxyParams}[1]{Parameters}
 & {\em obc} & Open boundary control structure\\
\hline
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in,out}  & {\em depth} & Bathymetry at h-\/points \\
\hline
\end{DoxyParams}


Definition at line 1925 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
1925   \textcolor{keywordtype}{type}(ocean\_obc\_type),             \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{ !< Open boundary control structure}
1926   \textcolor{keywordtype}{type}(dyn\_horgrid\_type),           \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{ !< Ocean grid structure}
1927   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G))}, \textcolor{keywordtype}{intent(inout)} :: depth\textcolor{comment}{ !< Bathymetry at h-points}
1928   \textcolor{comment}{! Local variables}
1929   \textcolor{keywordtype}{integer} :: i, j, n
1930   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()
1931 
1932   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{return}
1933 
1934   \textcolor{keywordflow}{if} (.not.(obc%specified\_u\_BCs\_exist\_globally .or. obc%specified\_v\_BCs\_exist\_globally .or. &
1935               obc%open\_u\_BCs\_exist\_globally .or. obc%open\_v\_BCs\_exist\_globally)) &
1936     \textcolor{keywordflow}{return}
1937 
1938   \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
1939     segment=>obc%segment(n)
1940     \textcolor{keywordflow}{if} (.not. segment%on\_pe) cycle
1941     \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_e) \textcolor{keywordflow}{then}
1942       i=segment%HI%IsdB
1943       \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
1944         depth(i+1,j) = depth(i,j)
1945 \textcolor{keywordflow}{      enddo}
1946     \textcolor{keywordflow}{elseif} (segment%direction == obc\_direction\_w) \textcolor{keywordflow}{then}
1947       i=segment%HI%IsdB
1948       \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
1949         depth(i,j) = depth(i+1,j)
1950 \textcolor{keywordflow}{      enddo}
1951     \textcolor{keywordflow}{elseif} (segment%direction == obc\_direction\_n) \textcolor{keywordflow}{then}
1952       j=segment%HI%JsdB
1953       \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
1954         depth(i,j+1) = depth(i,j)
1955 \textcolor{keywordflow}{      enddo}
1956     \textcolor{keywordflow}{elseif} (segment%direction == obc\_direction\_s) \textcolor{keywordflow}{then}
1957       j=segment%HI%JsdB
1958       \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
1959         depth(i,j) = depth(i,j+1)
1960 \textcolor{keywordflow}{      enddo}
1961 \textcolor{keywordflow}{    endif}
1962 \textcolor{keywordflow}{  enddo}
1963 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a53dc87c231fcaf1c99fe818956fb111e}\label{namespacemom__open__boundary_a53dc87c231fcaf1c99fe818956fb111e}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!open\+\_\+boundary\+\_\+init@{open\+\_\+boundary\+\_\+init}}
\index{open\+\_\+boundary\+\_\+init@{open\+\_\+boundary\+\_\+init}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{open\+\_\+boundary\+\_\+init()}{open\_boundary\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::open\+\_\+boundary\+\_\+init (\begin{DoxyParamCaption}\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(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+C\+Sp }\end{DoxyParamCaption})}



Initialize open boundary control structure and do any necessary rescaling of O\+BC fields that have been read from a restart file. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & Container for vertical grid information\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file handle\\
\hline
 & {\em obc} & Open boundary control structure\\
\hline
 & {\em restart\+\_\+csp} & Restart structure, data intent(inout) \\
\hline
\end{DoxyParams}


Definition at line 1792 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
1792   \textcolor{keywordtype}{type}(ocean\_grid\_type),   \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{   !< Ocean grid structure}
1793   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)} :: gv\textcolor{comment}{  !< Container for vertical grid information}
1794   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)} :: us\textcolor{comment}{  !< A dimensional unit scaling type}
1795   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< Parameter file handle}
1796   \textcolor{keywordtype}{type}(ocean\_obc\_type),    \textcolor{keywordtype}{pointer}    :: obc\textcolor{comment}{ !< Open boundary control structure}
1797   \textcolor{keywordtype}{type}(mom\_restart\_cs),    \textcolor{keywordtype}{pointer}    :: restart\_csp\textcolor{comment}{ !< Restart structure, data intent(inout)}
1798 
1799   \textcolor{comment}{! Local variables}
1800   \textcolor{keywordtype}{real} :: vel2\_rescale \textcolor{comment}{! A rescaling factor for squared velocities from the representation in}
1801                        \textcolor{comment}{! a restart file to the internal representation in this run.}
1802   \textcolor{keywordtype}{integer} :: i, j, k, isd, ied, jsd, jed, nz, m
1803   \textcolor{keywordtype}{integer} :: isdb, iedb, jsdb, jedb
1804   isd  = g%isd  ; ied  = g%ied  ; jsd  = g%jsd  ; jed  = g%jed ; nz = gv%ke
1805   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
1806 
1807   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{return}
1808 
1809   id\_clock\_pass = cpu\_clock\_id(\textcolor{stringliteral}{'(Ocean OBC halo updates)'}, grain=clock\_routine)
1810   \textcolor{keywordflow}{if} (obc%radiation\_BCs\_exist\_globally) \textcolor{keyword}{call }pass\_vector(obc%rx\_normal, obc%ry\_normal, g%Domain, &
1811                      to\_all+scalar\_pair)
1812   \textcolor{keywordflow}{if} (obc%oblique\_BCs\_exist\_globally) \textcolor{keyword}{call }pass\_vector(obc%rx\_oblique, obc%ry\_oblique, g%Domain, &
1813                      to\_all+scalar\_pair)
1814   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc%cff\_normal)) \textcolor{keyword}{call }pass\_var(obc%cff\_normal, g%Domain, position=corner)
1815   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc%tres\_x) .and. \textcolor{keyword}{associated}(obc%tres\_y)) \textcolor{keywordflow}{then}
1816     \textcolor{keywordflow}{do} m=1,obc%ntr
1817       \textcolor{keyword}{call }pass\_vector(obc%tres\_x(:,:,:,m), obc%tres\_y(:,:,:,m), g%Domain, to\_all+scalar\_pair)
1818 \textcolor{keywordflow}{    enddo}
1819   \textcolor{keywordflow}{elseif} (\textcolor{keyword}{associated}(obc%tres\_x)) \textcolor{keywordflow}{then}
1820     \textcolor{keywordflow}{do} m=1,obc%ntr
1821       \textcolor{keyword}{call }pass\_var(obc%tres\_x(:,:,:,m), g%Domain, position=east\_face)
1822 \textcolor{keywordflow}{    enddo}
1823   \textcolor{keywordflow}{elseif} (\textcolor{keyword}{associated}(obc%tres\_y)) \textcolor{keywordflow}{then}
1824     \textcolor{keywordflow}{do} m=1,obc%ntr
1825       \textcolor{keyword}{call }pass\_var(obc%tres\_y(:,:,:,m), g%Domain, position=north\_face)
1826 \textcolor{keywordflow}{    enddo}
1827 \textcolor{keywordflow}{  endif}
1828 
1829   \textcolor{comment}{! The rx\_normal and ry\_normal arrays used with radiation OBCs are currently in units of grid}
1830   \textcolor{comment}{! points per timestep, but if this were to be corrected to [L T-1 ~> m s-1] or [T-1 ~> s-1] to}
1831   \textcolor{comment}{! permit timesteps to change between calls to the OBC code, the following would be needed:}
1832 \textcolor{comment}{!  if ( OBC%radiation\_BCs\_exist\_globally .and. (US%s\_to\_T\_restart * US%m\_to\_L\_restart /= 0.0) .and. &}
1833 \textcolor{comment}{!       ((US%m\_to\_L * US%s\_to\_T\_restart) /= (US%m\_to\_L\_restart * US%s\_to\_T)) ) then}
1834 \textcolor{comment}{!    vel\_rescale = (US%m\_to\_L * US%s\_to\_T\_restart) /  (US%m\_to\_L\_restart * US%s\_to\_T)}
1835 \textcolor{comment}{!    if (query\_initialized(OBC%rx\_normal, "rx\_normal", restart\_CSp)) then}
1836 \textcolor{comment}{!      do k=1,nz ; do j=jsd,jed ; do I=IsdB,IedB}
1837 \textcolor{comment}{!        OBC%rx\_normal(I,j,k) = vel\_rescale * OBC%rx\_normal(I,j,k)}
1838 \textcolor{comment}{!      enddo ; enddo ; enddo}
1839 \textcolor{comment}{!    endif}
1840 \textcolor{comment}{!    if (query\_initialized(OBC%ry\_normal, "ry\_normal", restart\_CSp)) then}
1841 \textcolor{comment}{!      do k=1,nz ; do J=JsdB,JedB ; do i=isd,ied}
1842 \textcolor{comment}{!        OBC%ry\_normal(i,J,k) = vel\_rescale * OBC%ry\_normal(i,J,k)}
1843 \textcolor{comment}{!      enddo ; enddo ; enddo}
1844 \textcolor{comment}{!    endif}
1845 \textcolor{comment}{!  endif}
1846 
1847   \textcolor{comment}{! The oblique boundary condition terms have units of [L2 T-2 ~> m2 s-2] and may need to be rescaled.}
1848   \textcolor{keywordflow}{if} ( obc%oblique\_BCs\_exist\_globally .and. (us%s\_to\_T\_restart * us%m\_to\_L\_restart /= 0.0) .and. &
1849        ((us%m\_to\_L * us%s\_to\_T\_restart) /= (us%m\_to\_L\_restart * us%s\_to\_T)) ) \textcolor{keywordflow}{then}
1850     vel2\_rescale = (us%m\_to\_L * us%s\_to\_T\_restart)**2 /  (us%m\_to\_L\_restart * us%s\_to\_T)**2
1851     \textcolor{keywordflow}{if} (query\_initialized(obc%rx\_oblique, \textcolor{stringliteral}{"rx\_oblique"}, restart\_csp)) \textcolor{keywordflow}{then}
1852       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsd,jed ; \textcolor{keywordflow}{do} i=isdb,iedb
1853         obc%rx\_oblique(i,j,k) = vel2\_rescale * obc%rx\_oblique(i,j,k)
1854 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1855 \textcolor{keywordflow}{    endif}
1856     \textcolor{keywordflow}{if} (query\_initialized(obc%ry\_oblique, \textcolor{stringliteral}{"ry\_oblique"}, restart\_csp)) \textcolor{keywordflow}{then}
1857       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isd,ied
1858         obc%ry\_oblique(i,j,k) = vel2\_rescale * obc%ry\_oblique(i,j,k)
1859 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1860 \textcolor{keywordflow}{    endif}
1861     \textcolor{keywordflow}{if} (query\_initialized(obc%cff\_normal, \textcolor{stringliteral}{"cff\_normal"}, restart\_csp)) \textcolor{keywordflow}{then}
1862       \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=jsdb,jedb ; \textcolor{keywordflow}{do} i=isdb,iedb
1863         obc%cff\_normal(i,j,k) = vel2\_rescale * obc%cff\_normal(i,j,k)
1864 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
1865 \textcolor{keywordflow}{    endif}
1866 \textcolor{keywordflow}{   endif}
1867 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_af55e663cc3a1f5f697e72066d75c9160}\label{namespacemom__open__boundary_af55e663cc3a1f5f697e72066d75c9160}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!open\+\_\+boundary\+\_\+query@{open\+\_\+boundary\+\_\+query}}
\index{open\+\_\+boundary\+\_\+query@{open\+\_\+boundary\+\_\+query}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{open\+\_\+boundary\+\_\+query()}{open\_boundary\_query()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+open\+\_\+boundary\+::open\+\_\+boundary\+\_\+query (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{logical, intent(in), optional}]{apply\+\_\+open\+\_\+\+O\+BC,  }\item[{logical, intent(in), optional}]{apply\+\_\+specified\+\_\+\+O\+BC,  }\item[{logical, intent(in), optional}]{apply\+\_\+\+Flather\+\_\+\+O\+BC,  }\item[{logical, intent(in), optional}]{apply\+\_\+nudged\+\_\+\+O\+BC,  }\item[{logical, intent(in), optional}]{needs\+\_\+ext\+\_\+seg\+\_\+data }\end{DoxyParamCaption})}


\begin{DoxyParams}[1]{Parameters}
 & {\em obc} & Open boundary control structure\\
\hline
\mbox{\tt in}  & {\em apply\+\_\+open\+\_\+obc} & Returns True if open\+\_\+$\ast$\+\_\+\+B\+Cs\+\_\+exist\+\_\+globally is true\\
\hline
\mbox{\tt in}  & {\em apply\+\_\+specified\+\_\+obc} & Returns True if specified\+\_\+$\ast$\+\_\+\+B\+Cs\+\_\+exist\+\_\+globally is true\\
\hline
\mbox{\tt in}  & {\em apply\+\_\+flather\+\_\+obc} & Returns True if Flather\+\_\+$\ast$\+\_\+\+B\+Cs\+\_\+exist\+\_\+globally is true\\
\hline
\mbox{\tt in}  & {\em apply\+\_\+nudged\+\_\+obc} & Returns True if nudged\+\_\+$\ast$\+\_\+\+B\+Cs\+\_\+exist\+\_\+globally is true\\
\hline
\mbox{\tt in}  & {\em needs\+\_\+ext\+\_\+seg\+\_\+data} & Returns True if external segment data needed \\
\hline
\end{DoxyParams}


Definition at line 1872 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
1872   \textcolor{keywordtype}{type}(ocean\_obc\_type), \textcolor{keywordtype}{pointer}    :: obc\textcolor{comment}{ !< Open boundary control structure}
1873   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},    \textcolor{keywordtype}{intent(in)} :: apply\_open\_obc\textcolor{comment}{      !< Returns True if open\_*\_BCs\_exist\_globally is
       true}
1874   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},    \textcolor{keywordtype}{intent(in)} :: apply\_specified\_obc\textcolor{comment}{ !< Returns True if specified\_*\_BCs\_exist\_globally
       is true}
1875   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},    \textcolor{keywordtype}{intent(in)} :: apply\_flather\_obc\textcolor{comment}{   !< Returns True if Flather\_*\_BCs\_exist\_globally
       is true}
1876   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},    \textcolor{keywordtype}{intent(in)} :: apply\_nudged\_obc\textcolor{comment}{    !< Returns True if nudged\_*\_BCs\_exist\_globally is
       true}
1877   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},    \textcolor{keywordtype}{intent(in)} :: needs\_ext\_seg\_data\textcolor{comment}{  !< Returns True if external segment data needed}
1878   open\_boundary\_query = .false.
1879   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{return}
1880   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(apply\_open\_obc)) open\_boundary\_query = obc%open\_u\_BCs\_exist\_globally .or. &
1881                                                      obc%open\_v\_BCs\_exist\_globally
1882   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(apply\_specified\_obc)) open\_boundary\_query = obc%specified\_u\_BCs\_exist\_globally .or. &
1883                                                           obc%specified\_v\_BCs\_exist\_globally
1884   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(apply\_flather\_obc)) open\_boundary\_query = obc%Flather\_u\_BCs\_exist\_globally .or. &
1885                                                         obc%Flather\_v\_BCs\_exist\_globally
1886   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(apply\_nudged\_obc)) open\_boundary\_query = obc%nudged\_u\_BCs\_exist\_globally .or. &
1887                                                        obc%nudged\_v\_BCs\_exist\_globally
1888   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(needs\_ext\_seg\_data)) open\_boundary\_query = obc%needs\_IO\_for\_data
1889 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_af1d4f35b2cff85617fc5766739db81de}\label{namespacemom__open__boundary_af1d4f35b2cff85617fc5766739db81de}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!open\+\_\+boundary\+\_\+register\+\_\+restarts@{open\+\_\+boundary\+\_\+register\+\_\+restarts}}
\index{open\+\_\+boundary\+\_\+register\+\_\+restarts@{open\+\_\+boundary\+\_\+register\+\_\+restarts}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{open\+\_\+boundary\+\_\+register\+\_\+restarts()}{open\_boundary\_register\_restarts()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::open\+\_\+boundary\+\_\+register\+\_\+restarts (\begin{DoxyParamCaption}\item[{type(hor\+\_\+index\+\_\+type), intent(in)}]{HI,  }\item[{type(verticalgrid\+\_\+type), pointer}]{GV,  }\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{type(tracer\+\_\+registry\+\_\+type), pointer}]{Reg,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(mom\+\_\+restart\+\_\+cs), pointer}]{restart\+\_\+\+C\+Sp,  }\item[{logical, intent(in)}]{use\+\_\+temperature }\end{DoxyParamCaption})}



Register O\+BC segment data for restarts. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em hi} & Horizontal indices\\
\hline
 & {\em gv} & Container for vertical grid information\\
\hline
 & {\em obc} & O\+BC data structure, data intent(inout)\\
\hline
 & {\em reg} & pointer to tracer registry\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Parameter file handle\\
\hline
 & {\em restart\+\_\+csp} & Restart structure, data intent(inout)\\
\hline
\mbox{\tt in}  & {\em use\+\_\+temperature} & If true, T and S are used \\
\hline
\end{DoxyParams}


Definition at line 4942 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
4942   \textcolor{keywordtype}{type}(hor\_index\_type),    \textcolor{keywordtype}{intent(in)} :: hi\textcolor{comment}{ !< Horizontal indices}
4943   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{pointer}    :: gv\textcolor{comment}{ !< Container for vertical grid information}
4944   \textcolor{keywordtype}{type}(ocean\_obc\_type),    \textcolor{keywordtype}{pointer}    :: obc\textcolor{comment}{ !< OBC data structure, data intent(inout)}
4945   \textcolor{keywordtype}{type}(tracer\_registry\_type), \textcolor{keywordtype}{pointer} :: reg\textcolor{comment}{ !< pointer to tracer registry}
4946   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< Parameter file handle}
4947   \textcolor{keywordtype}{type}(mom\_restart\_cs),    \textcolor{keywordtype}{pointer}    :: restart\_csp\textcolor{comment}{ !< Restart structure, data intent(inout)}
4948   \textcolor{keywordtype}{logical},                 \textcolor{keywordtype}{intent(in)} :: use\_temperature\textcolor{comment}{ !< If true, T and S are used}
4949   \textcolor{comment}{! Local variables}
4950   \textcolor{keywordtype}{type}(vardesc) :: vd(2)
4951   \textcolor{keywordtype}{integer}       :: m, n
4952   \textcolor{keywordtype}{character(len=100)} :: mesg
4953   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment=>null()
4954 
4955   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(obc)) &
4956        \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"open\_boundary\_register\_restarts: Called with "}//&
4957                       \textcolor{stringliteral}{"uninitialized OBC control structure"})
4958 
4959   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc%rx\_normal) .or. \textcolor{keyword}{associated}(obc%ry\_normal) .or. &
4960       \textcolor{keyword}{associated}(obc%rx\_oblique) .or. \textcolor{keyword}{associated}(obc%ry\_oblique) .or. \textcolor{keyword}{associated}(obc%cff\_normal)) &
4961        \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"open\_boundary\_register\_restarts: Restart "}//&
4962                       \textcolor{stringliteral}{"arrays were previously allocated"})
4963 
4964   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc%tres\_x) .or. \textcolor{keyword}{associated}(obc%tres\_y)) &
4965        \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"open\_boundary\_register\_restarts: Restart "}//&
4966                       \textcolor{stringliteral}{"arrays were previously allocated"})
4967 
4968   \textcolor{comment}{! *** This is a temporary work around for restarts with OBC segments.}
4969   \textcolor{comment}{! This implementation uses 3D arrays solely for restarts. We need}
4970   \textcolor{comment}{! to be able to add 2D ( x,z or y,z ) data to restarts to avoid using}
4971   \textcolor{comment}{! so much memory and disk space. ***}
4972   \textcolor{keywordflow}{if} (obc%radiation\_BCs\_exist\_globally) \textcolor{keywordflow}{then}
4973     \textcolor{keyword}{allocate}(obc%rx\_normal(hi%isdB:hi%iedB,hi%jsd:hi%jed,gv%ke))
4974     \textcolor{keyword}{allocate}(obc%ry\_normal(hi%isd:hi%ied,hi%jsdB:hi%jedB,gv%ke))
4975     obc%rx\_normal(:,:,:) = 0.0
4976     obc%ry\_normal(:,:,:) = 0.0
4977 
4978     vd(1) = var\_desc(\textcolor{stringliteral}{"rx\_normal"}, \textcolor{stringliteral}{"m s-1"}, \textcolor{stringliteral}{"Normal Phase Speed for EW radiation OBCs"}, \textcolor{stringliteral}{'u'}, \textcolor{stringliteral}{'L'})
4979     vd(2) = var\_desc(\textcolor{stringliteral}{"ry\_normal"}, \textcolor{stringliteral}{"m s-1"}, \textcolor{stringliteral}{"Normal Phase Speed for NS radiation OBCs"}, \textcolor{stringliteral}{'v'}, \textcolor{stringliteral}{'L'})
4980     \textcolor{keyword}{call }register\_restart\_pair(obc%rx\_normal, obc%ry\_normal, vd(1), vd(2), &
4981         .false., restart\_csp)
4982 \textcolor{keywordflow}{  endif}
4983 
4984   \textcolor{keywordflow}{if} (obc%oblique\_BCs\_exist\_globally) \textcolor{keywordflow}{then}
4985     \textcolor{keyword}{allocate}(obc%rx\_oblique(hi%isdB:hi%iedB,hi%jsd:hi%jed,gv%ke))
4986     \textcolor{keyword}{allocate}(obc%ry\_oblique(hi%isd:hi%ied,hi%jsdB:hi%jedB,gv%ke))
4987     obc%rx\_oblique(:,:,:) = 0.0
4988     obc%ry\_oblique(:,:,:) = 0.0
4989 
4990     vd(1) = var\_desc(\textcolor{stringliteral}{"rx\_oblique"}, \textcolor{stringliteral}{"m2 s-2"}, \textcolor{stringliteral}{"Radiation Speed Squared for EW oblique OBCs"}, \textcolor{stringliteral}{'u'}, \textcolor{stringliteral}{'L'})
4991     vd(2) = var\_desc(\textcolor{stringliteral}{"ry\_oblique"}, \textcolor{stringliteral}{"m2 s-2"}, \textcolor{stringliteral}{"Radiation Speed Squared for NS oblique OBCs"}, \textcolor{stringliteral}{'v'}, \textcolor{stringliteral}{'L'})
4992     \textcolor{keyword}{call }register\_restart\_pair(obc%rx\_oblique, obc%ry\_oblique, vd(1), vd(2), &
4993         .false., restart\_csp)
4994 
4995     \textcolor{keyword}{allocate}(obc%cff\_normal(hi%IsdB:hi%IedB,hi%jsdB:hi%jedB,gv%ke))
4996     obc%cff\_normal(:,:,:) = 0.0
4997     vd(1) = var\_desc(\textcolor{stringliteral}{"cff\_normal"}, \textcolor{stringliteral}{"m2 s-2"}, \textcolor{stringliteral}{"denominator for oblique OBCs"}, \textcolor{stringliteral}{'q'}, \textcolor{stringliteral}{'L'})
4998     \textcolor{keyword}{call }register\_restart\_field(obc%cff\_normal, vd(1), .false., restart\_csp)
4999 \textcolor{keywordflow}{  endif}
5000 
5001   \textcolor{keywordflow}{if} (reg%ntr == 0) \textcolor{keywordflow}{return}
5002   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(obc%tracer\_x\_reservoirs\_used)) \textcolor{keywordflow}{then}
5003     obc%ntr = reg%ntr
5004     \textcolor{keyword}{allocate}(obc%tracer\_x\_reservoirs\_used(reg%ntr))
5005     \textcolor{keyword}{allocate}(obc%tracer\_y\_reservoirs\_used(reg%ntr))
5006     obc%tracer\_x\_reservoirs\_used(:) = .false.
5007     obc%tracer\_y\_reservoirs\_used(:) = .false.
5008     \textcolor{keyword}{call }parse\_for\_tracer\_reservoirs(obc, param\_file, use\_temperature)
5009   \textcolor{keywordflow}{else}
5010     \textcolor{comment}{! This would be coming from user code such as DOME.}
5011     \textcolor{keywordflow}{if} (obc%ntr /= reg%ntr) \textcolor{keywordflow}{then}
5012 \textcolor{comment}{!        call MOM\_error(FATAL, "open\_boundary\_regiser\_restarts: Inconsistent value for ntr")}
5013       \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("Inconsistent values for ntr ", I8," and ",I8,".")'}) obc%ntr, reg%ntr
5014       \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{'open\_boundary\_register\_restarts: '}//mesg)
5015 \textcolor{keywordflow}{    endif}
5016 \textcolor{keywordflow}{  endif}
5017 
5018   \textcolor{comment}{! Still painfully inefficient, now in four dimensions.}
5019   \textcolor{keywordflow}{if} (any(obc%tracer\_x\_reservoirs\_used)) \textcolor{keywordflow}{then}
5020     \textcolor{keyword}{allocate}(obc%tres\_x(hi%isdB:hi%iedB,hi%jsd:hi%jed,gv%ke,obc%ntr))
5021     obc%tres\_x(:,:,:,:) = 0.0
5022     \textcolor{keywordflow}{do} m=1,obc%ntr
5023       \textcolor{keywordflow}{if} (obc%tracer\_x\_reservoirs\_used(m)) \textcolor{keywordflow}{then}
5024         \textcolor{keywordflow}{if} (modulo(hi%turns, 2) /= 0) \textcolor{keywordflow}{then}
5025           \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("tres\_y\_",I3.3)'}) m
5026           vd(1) = var\_desc(mesg,\textcolor{stringliteral}{"Conc"}, \textcolor{stringliteral}{"Tracer concentration for NS OBCs"},\textcolor{stringliteral}{'v'},\textcolor{stringliteral}{'L'})
5027           \textcolor{keyword}{call }register\_restart\_field(obc%tres\_x(:,:,:,m), vd(1), .false., restart\_csp)
5028         \textcolor{keywordflow}{else}
5029           \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("tres\_x\_",I3.3)'}) m
5030           vd(1) = var\_desc(mesg,\textcolor{stringliteral}{"Conc"}, \textcolor{stringliteral}{"Tracer concentration for EW OBCs"},\textcolor{stringliteral}{'u'},\textcolor{stringliteral}{'L'})
5031           \textcolor{keyword}{call }register\_restart\_field(obc%tres\_x(:,:,:,m), vd(1), .false., restart\_csp)
5032 \textcolor{keywordflow}{        endif}
5033 \textcolor{keywordflow}{      endif}
5034 \textcolor{keywordflow}{    enddo}
5035 \textcolor{keywordflow}{  endif}
5036   \textcolor{keywordflow}{if} (any(obc%tracer\_y\_reservoirs\_used)) \textcolor{keywordflow}{then}
5037     \textcolor{keyword}{allocate}(obc%tres\_y(hi%isd:hi%ied,hi%jsdB:hi%jedB,gv%ke,obc%ntr))
5038     obc%tres\_y(:,:,:,:) = 0.0
5039     \textcolor{keywordflow}{do} m=1,obc%ntr
5040       \textcolor{keywordflow}{if} (obc%tracer\_y\_reservoirs\_used(m)) \textcolor{keywordflow}{then}
5041         \textcolor{keywordflow}{if} (modulo(hi%turns, 2) /= 0) \textcolor{keywordflow}{then}
5042           \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("tres\_x\_",I3.3)'}) m
5043           vd(1) = var\_desc(mesg,\textcolor{stringliteral}{"Conc"}, \textcolor{stringliteral}{"Tracer concentration for EW OBCs"},\textcolor{stringliteral}{'u'},\textcolor{stringliteral}{'L'})
5044           \textcolor{keyword}{call }register\_restart\_field(obc%tres\_y(:,:,:,m), vd(1), .false., restart\_csp)
5045         \textcolor{keywordflow}{else}
5046           \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("tres\_y\_",I3.3)'}) m
5047           vd(1) = var\_desc(mesg,\textcolor{stringliteral}{"Conc"}, \textcolor{stringliteral}{"Tracer concentration for NS OBCs"},\textcolor{stringliteral}{'v'},\textcolor{stringliteral}{'L'})
5048           \textcolor{keyword}{call }register\_restart\_field(obc%tres\_y(:,:,:,m), vd(1), .false., restart\_csp)
5049 \textcolor{keywordflow}{        endif}
5050 \textcolor{keywordflow}{      endif}
5051 \textcolor{keywordflow}{    enddo}
5052 \textcolor{keywordflow}{  endif}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a4123d11abdb141b21a4d52a0c43c4adb}\label{namespacemom__open__boundary_a4123d11abdb141b21a4d52a0c43c4adb}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!open\+\_\+boundary\+\_\+test\+\_\+extern\+\_\+h@{open\+\_\+boundary\+\_\+test\+\_\+extern\+\_\+h}}
\index{open\+\_\+boundary\+\_\+test\+\_\+extern\+\_\+h@{open\+\_\+boundary\+\_\+test\+\_\+extern\+\_\+h}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{open\+\_\+boundary\+\_\+test\+\_\+extern\+\_\+h()}{open\_boundary\_test\_extern\_h()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::open\+\_\+boundary\+\_\+test\+\_\+extern\+\_\+h (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed,  gv \%ke), intent(inout)}]{h }\end{DoxyParamCaption})}



Set thicknesses outside of open boundaries to silly values (used for checking the interior state is independent of values outside of the domain). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & Ocean vertical grid structure\\
\hline
 & {\em obc} & Open boundary structure\\
\hline
\mbox{\tt in,out}  & {\em h} & Layer thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 3688 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
3688   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{   !< Ocean grid structure}
3689   \textcolor{keywordtype}{type}(verticalgrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{  !<  Ocean vertical grid structure}
3690   \textcolor{keywordtype}{type}(ocean\_obc\_type),                      \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{ !< Open boundary structure}
3691   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G), SZK\_(GV))},\textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{   !< Layer thickness [H ~> m or kg m-2]}
3692   \textcolor{comment}{! Local variables}
3693   \textcolor{keywordtype}{real} :: silly\_h  \textcolor{comment}{! A silly thickness for testing [H ~> m or kg m-2]}
3694   \textcolor{keywordtype}{integer} :: i, j, k, n
3695 
3696   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{return}
3697 
3698   silly\_h = gv%Z\_to\_H*obc%silly\_h
3699 
3700   \textcolor{keywordflow}{do} n = 1, obc%number\_of\_segments
3701     \textcolor{keywordflow}{do} k = 1, gv%ke
3702       \textcolor{keywordflow}{if} (obc%segment(n)%is\_N\_or\_S) \textcolor{keywordflow}{then}
3703         j = obc%segment(n)%HI%JsdB
3704         \textcolor{keywordflow}{if} (obc%segment(n)%direction == obc\_direction\_n) \textcolor{keywordflow}{then}
3705           \textcolor{keywordflow}{do} i = obc%segment(n)%HI%isd, obc%segment(n)%HI%ied
3706             h(i,j+1,k) = silly\_h
3707 \textcolor{keywordflow}{          enddo}
3708         \textcolor{keywordflow}{else}
3709           \textcolor{keywordflow}{do} i = obc%segment(n)%HI%isd, obc%segment(n)%HI%ied
3710             h(i,j,k) = silly\_h
3711 \textcolor{keywordflow}{          enddo}
3712 \textcolor{keywordflow}{        endif}
3713       \textcolor{keywordflow}{elseif} (obc%segment(n)%is\_E\_or\_W) \textcolor{keywordflow}{then}
3714         i = obc%segment(n)%HI%IsdB
3715         \textcolor{keywordflow}{if} (obc%segment(n)%direction == obc\_direction\_e) \textcolor{keywordflow}{then}
3716           \textcolor{keywordflow}{do} j = obc%segment(n)%HI%jsd, obc%segment(n)%HI%jed
3717             h(i+1,j,k) = silly\_h
3718 \textcolor{keywordflow}{          enddo}
3719         \textcolor{keywordflow}{else}
3720           \textcolor{keywordflow}{do} j = obc%segment(n)%HI%jsd, obc%segment(n)%HI%jed
3721             h(i,j,k) = silly\_h
3722 \textcolor{keywordflow}{          enddo}
3723 \textcolor{keywordflow}{        endif}
3724 \textcolor{keywordflow}{      endif}
3725 \textcolor{keywordflow}{    enddo}
3726 \textcolor{keywordflow}{  enddo}
3727 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a556977a2754fab17e837a8fba75cd9ee}\label{namespacemom__open__boundary_a556977a2754fab17e837a8fba75cd9ee}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!open\+\_\+boundary\+\_\+test\+\_\+extern\+\_\+uv@{open\+\_\+boundary\+\_\+test\+\_\+extern\+\_\+uv}}
\index{open\+\_\+boundary\+\_\+test\+\_\+extern\+\_\+uv@{open\+\_\+boundary\+\_\+test\+\_\+extern\+\_\+uv}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{open\+\_\+boundary\+\_\+test\+\_\+extern\+\_\+uv()}{open\_boundary\_test\_extern\_uv()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::open\+\_\+boundary\+\_\+test\+\_\+extern\+\_\+uv (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{real, dimension( g \%isdb\+: g \%iedb, g \%jsd\+: g \%jed,  g \%ke), intent(inout)}]{u,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsdb\+: g \%jedb,  g \%ke), intent(inout)}]{v }\end{DoxyParamCaption})}



Set tangential velocities outside of open boundaries to silly values (used for checking the interior state is independent of values outside of the domain). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
 & {\em obc} & Open boundary structure\\
\hline
\mbox{\tt in,out}  & {\em u} & Zonal velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em v} & Meridional velocity \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 3645 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
3645   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{ !< Ocean grid structure}
3646   \textcolor{keywordtype}{type}(ocean\_obc\_type),                      \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{ !< Open boundary structure}
3647   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G), SZK\_(G))},\textcolor{keywordtype}{intent(inout)} :: u\textcolor{comment}{ !< Zonal velocity [L T-1 ~> m s-1]}
3648   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G), SZK\_(G))},\textcolor{keywordtype}{intent(inout)} :: v\textcolor{comment}{ !< Meridional velocity [L T-1 ~> m s-1]}
3649   \textcolor{comment}{! Local variables}
3650   \textcolor{keywordtype}{integer} :: i, j, k, n
3651 
3652   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{return}
3653 
3654   \textcolor{keywordflow}{do} n = 1, obc%number\_of\_segments
3655     \textcolor{keywordflow}{do} k = 1, g%ke
3656       \textcolor{keywordflow}{if} (obc%segment(n)%is\_N\_or\_S) \textcolor{keywordflow}{then}
3657         j = obc%segment(n)%HI%JsdB
3658         \textcolor{keywordflow}{if} (obc%segment(n)%direction == obc\_direction\_n) \textcolor{keywordflow}{then}
3659           \textcolor{keywordflow}{do} i = obc%segment(n)%HI%IsdB, obc%segment(n)%HI%IedB
3660             u(i,j+1,k) = obc%silly\_u
3661 \textcolor{keywordflow}{          enddo}
3662         \textcolor{keywordflow}{else}
3663           \textcolor{keywordflow}{do} i = obc%segment(n)%HI%IsdB, obc%segment(n)%HI%IedB
3664             u(i,j,k) = obc%silly\_u
3665 \textcolor{keywordflow}{          enddo}
3666 \textcolor{keywordflow}{        endif}
3667       \textcolor{keywordflow}{elseif} (obc%segment(n)%is\_E\_or\_W) \textcolor{keywordflow}{then}
3668         i = obc%segment(n)%HI%IsdB
3669         \textcolor{keywordflow}{if} (obc%segment(n)%direction == obc\_direction\_e) \textcolor{keywordflow}{then}
3670           \textcolor{keywordflow}{do} j = obc%segment(n)%HI%JsdB, obc%segment(n)%HI%JedB
3671             v(i+1,j,k) = obc%silly\_u
3672 \textcolor{keywordflow}{          enddo}
3673         \textcolor{keywordflow}{else}
3674           \textcolor{keywordflow}{do} j = obc%segment(n)%HI%JsdB, obc%segment(n)%HI%JedB
3675             v(i,j,k) = obc%silly\_u
3676 \textcolor{keywordflow}{          enddo}
3677 \textcolor{keywordflow}{        endif}
3678 \textcolor{keywordflow}{      endif}
3679 \textcolor{keywordflow}{    enddo}
3680 \textcolor{keywordflow}{  enddo}
3681 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a9d48e6925d93fa98cbf5bb73903f94be}\label{namespacemom__open__boundary_a9d48e6925d93fa98cbf5bb73903f94be}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!open\+\_\+boundary\+\_\+zero\+\_\+normal\+\_\+flow@{open\+\_\+boundary\+\_\+zero\+\_\+normal\+\_\+flow}}
\index{open\+\_\+boundary\+\_\+zero\+\_\+normal\+\_\+flow@{open\+\_\+boundary\+\_\+zero\+\_\+normal\+\_\+flow}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{open\+\_\+boundary\+\_\+zero\+\_\+normal\+\_\+flow()}{open\_boundary\_zero\_normal\_flow()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::open\+\_\+boundary\+\_\+zero\+\_\+normal\+\_\+flow (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{u,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{v }\end{DoxyParamCaption})}



Applies zero values to 3d u,v fields on O\+BC segments. 


\begin{DoxyParams}[1]{Parameters}
 & {\em obc} & Open boundary control structure\\
\hline
\mbox{\tt in,out}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in,out}  & {\em u} & u field to update on open boundaries\\
\hline
\mbox{\tt in,out}  & {\em v} & v field to update on open boundaries \\
\hline
\end{DoxyParams}


Definition at line 3265 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
3265   \textcolor{comment}{! Arguments}
3266   \textcolor{keywordtype}{type}(ocean\_obc\_type),                      \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{ !< Open boundary control structure}
3267   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{   !< Ocean grid structure}
3268   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: u\textcolor{comment}{   !< u field to update on open boundaries}
3269   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: v\textcolor{comment}{   !< v field to update on open boundaries}
3270   \textcolor{comment}{! Local variables}
3271   \textcolor{keywordtype}{integer} :: i, j, k, n
3272   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()
3273 
3274   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{return} \textcolor{comment}{! Bail out if OBC is not available}
3275 
3276   \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
3277     segment => obc%segment(n)
3278     \textcolor{keywordflow}{if} (.not. segment%on\_pe) \textcolor{keywordflow}{then}
3279       cycle
3280     \textcolor{keywordflow}{elseif} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
3281       i=segment%HI%IsdB
3282       \textcolor{keywordflow}{do} k=1,g%ke ;  \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
3283         u(i,j,k) = 0.
3284 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
3285     \textcolor{keywordflow}{elseif} (segment%is\_N\_or\_S) \textcolor{keywordflow}{then}
3286       j=segment%HI%JsdB
3287       \textcolor{keywordflow}{do} k=1,g%ke ;  \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
3288         v(i,j,k) = 0.
3289 \textcolor{keywordflow}{      enddo} ;\textcolor{keywordflow}{ enddo}
3290 \textcolor{keywordflow}{    endif}
3291 \textcolor{keywordflow}{  enddo}
3292 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a2e2dbab2a3e23eb9848aba473f635cec}\label{namespacemom__open__boundary_a2e2dbab2a3e23eb9848aba473f635cec}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!parse\+\_\+for\+\_\+tracer\+\_\+reservoirs@{parse\+\_\+for\+\_\+tracer\+\_\+reservoirs}}
\index{parse\+\_\+for\+\_\+tracer\+\_\+reservoirs@{parse\+\_\+for\+\_\+tracer\+\_\+reservoirs}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{parse\+\_\+for\+\_\+tracer\+\_\+reservoirs()}{parse\_for\_tracer\_reservoirs()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::parse\+\_\+for\+\_\+tracer\+\_\+reservoirs (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), intent(inout)}]{O\+BC,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{PF,  }\item[{logical, intent(in)}]{use\+\_\+temperature }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Parse all the O\+B\+C\+\_\+\+S\+E\+G\+M\+E\+N\+T\+\_\+\%\%\+\_\+\+D\+A\+TA strings again to see which need tracer reservoirs (all pes need to know). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em obc} & Open boundary control structure\\
\hline
\mbox{\tt in}  & {\em pf} & Parameter file handle\\
\hline
\mbox{\tt in}  & {\em use\+\_\+temperature} & If true, T and S are used \\
\hline
\end{DoxyParams}


Definition at line 1643 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
1643   \textcolor{keywordtype}{type}(ocean\_obc\_type),   \textcolor{keywordtype}{intent(inout)} :: obc\textcolor{comment}{ !< Open boundary control structure}
1644   \textcolor{keywordtype}{type}(param\_file\_type),  \textcolor{keywordtype}{intent(in)}    :: pf\textcolor{comment}{  !< Parameter file handle}
1645   \textcolor{keywordtype}{logical},                \textcolor{keywordtype}{intent(in)} :: use\_temperature\textcolor{comment}{ !< If true, T and S are used}
1646 
1647   \textcolor{comment}{! Local variables}
1648   \textcolor{keywordtype}{integer} :: n,m,num\_fields
1649   \textcolor{keywordtype}{character(len=1024)} :: segstr
1650   \textcolor{keywordtype}{character(len=256)} :: filename
1651   \textcolor{keywordtype}{character(len=20)}  :: segnam, suffix
1652   \textcolor{keywordtype}{character(len=32)}  :: varnam, fieldname
1653   \textcolor{keywordtype}{real}               :: value
1654   \textcolor{keywordtype}{character(len=32)}, \textcolor{keywordtype}{dimension(MAX\_OBC\_FIELDS)} :: fields  \textcolor{comment}{! segment field names}
1655   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null() \textcolor{comment}{! pointer to segment type list}
1656   \textcolor{keywordtype}{character(len=256)} :: mesg    \textcolor{comment}{! Message for error messages.}
1657 
1658   \textcolor{keywordflow}{do} n=1, obc%number\_of\_segments
1659     segment => obc%segment(n)
1660     \textcolor{keyword}{write}(segnam,\textcolor{stringliteral}{"('OBC\_SEGMENT\_',i3.3,'\_DATA')"}) n
1661     \textcolor{keyword}{write}(suffix,\textcolor{stringliteral}{"('\_segment\_',i3.3)"}) n
1662     \textcolor{comment}{! Clear out any old values}
1663     segstr = \textcolor{stringliteral}{''}
1664     \textcolor{keyword}{call }get\_param(pf, mdl, segnam, segstr)
1665     \textcolor{keywordflow}{if} (segstr == \textcolor{stringliteral}{''}) cycle
1666 
1667     \textcolor{keyword}{call }parse\_segment\_manifest\_str(trim(segstr), num\_fields, fields)
1668     \textcolor{keywordflow}{if} (num\_fields == 0) cycle
1669 
1670     \textcolor{comment}{! At this point, just search for TEMP and SALT as tracers 1 and 2.}
1671     \textcolor{keywordflow}{do} m=1,num\_fields
1672       \textcolor{keyword}{call }parse\_segment\_data\_str(trim(segstr), m, trim(fields(m)), &
1673           \textcolor{keywordtype}{value}, filename, fieldname)
1674       \textcolor{keywordflow}{if} (trim(filename) /= \textcolor{stringliteral}{'none'}) \textcolor{keywordflow}{then}
1675         \textcolor{keywordflow}{if} (fields(m) == \textcolor{stringliteral}{'TEMP'}) \textcolor{keywordflow}{then}
1676           \textcolor{keywordflow}{if} (segment%is\_E\_or\_W\_2) \textcolor{keywordflow}{then}
1677             obc%tracer\_x\_reservoirs\_used(1) = .true.
1678           \textcolor{keywordflow}{else}
1679             obc%tracer\_y\_reservoirs\_used(1) = .true.
1680 \textcolor{keywordflow}{          endif}
1681 \textcolor{keywordflow}{        endif}
1682         \textcolor{keywordflow}{if} (fields(m) == \textcolor{stringliteral}{'SALT'}) \textcolor{keywordflow}{then}
1683           \textcolor{keywordflow}{if} (segment%is\_E\_or\_W\_2) \textcolor{keywordflow}{then}
1684             obc%tracer\_x\_reservoirs\_used(2) = .true.
1685           \textcolor{keywordflow}{else}
1686             obc%tracer\_y\_reservoirs\_used(2) = .true.
1687 \textcolor{keywordflow}{          endif}
1688 \textcolor{keywordflow}{        endif}
1689 \textcolor{keywordflow}{      endif}
1690 \textcolor{keywordflow}{    enddo}
1691     \textcolor{comment}{! Alternately, set first two to true if use\_temperature is true}
1692     \textcolor{keywordflow}{if} (use\_temperature) \textcolor{keywordflow}{then}
1693       \textcolor{keywordflow}{if} (segment%is\_E\_or\_W\_2) \textcolor{keywordflow}{then}
1694         obc%tracer\_x\_reservoirs\_used(1) = .true.
1695         obc%tracer\_x\_reservoirs\_used(2) = .true.
1696       \textcolor{keywordflow}{else}
1697         obc%tracer\_y\_reservoirs\_used(1) = .true.
1698         obc%tracer\_y\_reservoirs\_used(2) = .true.
1699 \textcolor{keywordflow}{      endif}
1700 \textcolor{keywordflow}{    endif}
1701 \textcolor{keywordflow}{  enddo}
1702 
1703   \textcolor{keywordflow}{return}
1704 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_ae97f243936ebbcd30c8cfe91d41729c4}\label{namespacemom__open__boundary_ae97f243936ebbcd30c8cfe91d41729c4}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!parse\+\_\+segment\+\_\+data\+\_\+str@{parse\+\_\+segment\+\_\+data\+\_\+str}}
\index{parse\+\_\+segment\+\_\+data\+\_\+str@{parse\+\_\+segment\+\_\+data\+\_\+str}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{parse\+\_\+segment\+\_\+data\+\_\+str()}{parse\_segment\_data\_str()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::parse\+\_\+segment\+\_\+data\+\_\+str (\begin{DoxyParamCaption}\item[{character(len=$\ast$), intent(in)}]{segment\+\_\+str,  }\item[{integer, intent(in)}]{idx,  }\item[{character(len=$\ast$), intent(in)}]{var,  }\item[{real, intent(out), optional}]{value,  }\item[{character(len=$\ast$), intent(out)}]{filename,  }\item[{character(len=$\ast$), intent(out)}]{fieldname }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Parse an O\+B\+C\+\_\+\+S\+E\+G\+M\+E\+N\+T\+\_\+\%\%\+\_\+\+D\+A\+TA string. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em segment\+\_\+str} & A string in form of \char`\"{}\+V\+A\+R1=file\+:foo1.\+nc(varnam1),\+V\+A\+R2=file\+:foo2.\+nc(varnam2),...\char`\"{}\\
\hline
\mbox{\tt in}  & {\em idx} & Index of segment\+\_\+str record\\
\hline
\mbox{\tt in}  & {\em var} & The name of the variable for which parameters are needed\\
\hline
\mbox{\tt out}  & {\em filename} & The name of the input file if using \char`\"{}file\char`\"{} method\\
\hline
\mbox{\tt out}  & {\em fieldname} & The name of the variable in the input file if using \char`\"{}file\char`\"{} method\\
\hline
\mbox{\tt out}  & {\em value} & A constant value if using the \char`\"{}value\char`\"{} method \\
\hline
\end{DoxyParams}


Definition at line 1596 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
1596   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)} :: segment\_str\textcolor{comment}{   !< A string in form of}
1597 \textcolor{comment}{      !! "VAR1=file:foo1.nc(varnam1),VAR2=file:foo2.nc(varnam2),..."}
1598   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: idx\textcolor{comment}{                    !< Index of segment\_str record}
1599   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)} :: var\textcolor{comment}{           !< The name of the variable for which parameters are needed}
1600   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(out)} :: filename\textcolor{comment}{     !< The name of the input file if using "file" method}
1601   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(out)} :: fieldname\textcolor{comment}{    !< The name of the variable in the input file if using}
1602 \textcolor{comment}{                                                !! "file" method}
1603   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}  :: \textcolor{keywordtype}{value}\textcolor{comment}{         !< A constant value if using the "value" method}
1604 
1605   \textcolor{comment}{! Local variables}
1606   \textcolor{keywordtype}{character(len=128)} :: word1, word2, word3, method
1607   \textcolor{keywordtype}{integer} :: lword
1608 
1609   \textcolor{comment}{! Process first word which will start with the fieldname}
1610   word3 = extract\_word(segment\_str, \textcolor{stringliteral}{','}, idx)
1611   word1 = extract\_word(word3, \textcolor{stringliteral}{':'}, 1)
1612   \textcolor{comment}{!if (trim(word1) == '') exit}
1613   word2 = extract\_word(word1, \textcolor{stringliteral}{'='}, 1)
1614   \textcolor{keywordflow}{if} (trim(word2) == trim(var)) \textcolor{keywordflow}{then}
1615     method = trim(extract\_word(word1, \textcolor{stringliteral}{'='}, 2))
1616     lword = len\_trim(method)
1617     \textcolor{keywordflow}{if} (method(lword-3:lword) == \textcolor{stringliteral}{'file'}) \textcolor{keywordflow}{then}
1618       \textcolor{comment}{! raise an error id filename/fieldname not in argument list}
1619       word1 = extract\_word(word3, \textcolor{stringliteral}{':'}, 2)
1620       filename = extract\_word(word1, \textcolor{stringliteral}{'('}, 1)
1621       fieldname = extract\_word(word1, \textcolor{stringliteral}{'('}, 2)
1622       lword = len\_trim(fieldname)
1623       fieldname = fieldname(1:lword-1)  \textcolor{comment}{! remove trailing parenth}
1624       \textcolor{keywordtype}{value} = -999.
1625     \textcolor{keywordflow}{elseif} (method(lword-4:lword) == \textcolor{stringliteral}{'value'}) \textcolor{keywordflow}{then}
1626       filename = \textcolor{stringliteral}{'none'}
1627       fieldname = \textcolor{stringliteral}{'none'}
1628       word1 = extract\_word(word3, \textcolor{stringliteral}{':'}, 2)
1629       lword = len\_trim(word1)
1630       \textcolor{keyword}{read}(word1(1:lword), *, end=986, err=987) \textcolor{keywordtype}{value}
1631 \textcolor{keywordflow}{    endif}
1632 \textcolor{keywordflow}{  endif}
1633 
1634   \textcolor{keywordflow}{return}
1635 986 \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'End of record while parsing segment data specification! '}//trim(segment\_str))
1636 987 \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'Error while parsing segment data specification! '}//trim(segment\_str))
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a69848c26ddd38fe0f619311fa518313f}\label{namespacemom__open__boundary_a69848c26ddd38fe0f619311fa518313f}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!parse\+\_\+segment\+\_\+manifest\+\_\+str@{parse\+\_\+segment\+\_\+manifest\+\_\+str}}
\index{parse\+\_\+segment\+\_\+manifest\+\_\+str@{parse\+\_\+segment\+\_\+manifest\+\_\+str}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{parse\+\_\+segment\+\_\+manifest\+\_\+str()}{parse\_segment\_manifest\_str()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::parse\+\_\+segment\+\_\+manifest\+\_\+str (\begin{DoxyParamCaption}\item[{character(len=$\ast$), intent(in)}]{segment\+\_\+str,  }\item[{integer, intent(out)}]{num\+\_\+fields,  }\item[{character(len=$\ast$), dimension(\hyperlink{namespacemom__open__boundary_a6997b7b50a4afe32b14fd61ba858254f}{max\+\_\+obc\+\_\+fields}), intent(out)}]{fields }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Parse an O\+B\+C\+\_\+\+S\+E\+G\+M\+E\+N\+T\+\_\+\%\%\+\_\+\+D\+A\+TA string and determine its fields. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em segment\+\_\+str} & A string in form of \char`\"{}\+V\+A\+R1=file\+:foo1.\+nc(varnam1),\+V\+A\+R2=file\+:foo2.\+nc(varnam2),...\char`\"{}\\
\hline
\mbox{\tt out}  & {\em num\+\_\+fields} & The number of fields in the segment data\\
\hline
\mbox{\tt out}  & {\em fields} & List of fieldnames for each segment \\
\hline
\end{DoxyParams}


Definition at line 1574 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
1574   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)} :: segment\_str\textcolor{comment}{   !< A string in form of}
1575 \textcolor{comment}{                                        !< "VAR1=file:foo1.nc(varnam1),VAR2=file:foo2.nc(varnam2),..."}
1576   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(out)} :: num\_fields\textcolor{comment}{    !< The number of fields in the segment data}
1577   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{dimension(MAX\_OBC\_FIELDS)}, \textcolor{keywordtype}{intent(out)} :: fields
1578                                         \textcolor{comment}{!< List of fieldnames for each segment}
1579 
1580   \textcolor{comment}{! Local variables}
1581   \textcolor{keywordtype}{character(len=128)} :: word1, word2
1582 
1583   num\_fields = 0
1584   \textcolor{keywordflow}{do}
1585     word1 = extract\_word(segment\_str, \textcolor{stringliteral}{','}, num\_fields+1)
1586     \textcolor{keywordflow}{if} (trim(word1) == \textcolor{stringliteral}{''}) \textcolor{keywordflow}{exit}
1587     num\_fields = num\_fields + 1
1588     word2 = extract\_word(word1, \textcolor{stringliteral}{'='}, 1)
1589     fields(num\_fields) = trim(word2)
1590 \textcolor{keywordflow}{  enddo}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a349df847b304948d5b98352ddfd7bf8d}\label{namespacemom__open__boundary_a349df847b304948d5b98352ddfd7bf8d}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!parse\+\_\+segment\+\_\+param\+\_\+real@{parse\+\_\+segment\+\_\+param\+\_\+real}}
\index{parse\+\_\+segment\+\_\+param\+\_\+real@{parse\+\_\+segment\+\_\+param\+\_\+real}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{parse\+\_\+segment\+\_\+param\+\_\+real()}{parse\_segment\_param\_real()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::parse\+\_\+segment\+\_\+param\+\_\+real (\begin{DoxyParamCaption}\item[{character(len=$\ast$), intent(in)}]{segment\+\_\+str,  }\item[{character(len=$\ast$), intent(in)}]{var,  }\item[{real, intent(out)}]{param\+\_\+value,  }\item[{logical, intent(in), optional}]{debug }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Parse an O\+B\+C\+\_\+\+S\+E\+G\+M\+E\+N\+T\+\_\+\%\%\+\_\+\+P\+A\+R\+A\+MS string. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em segment\+\_\+str} & A string in form of \char`\"{}\+V\+A\+R1=file\+:foo1.\+nc(varnam1),\+V\+A\+R2=file\+:foo2.\+nc(varnam2),...\char`\"{}\\
\hline
\mbox{\tt in}  & {\em var} & The name of the variable for which parameters are needed\\
\hline
\mbox{\tt out}  & {\em param\+\_\+value} & The value of the parameter\\
\hline
\mbox{\tt in}  & {\em debug} & If present and true, write verbose debugging messages \\
\hline
\end{DoxyParams}


Definition at line 1709 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
1709    \textcolor{keywordtype}{character(len=*)},  \textcolor{keywordtype}{intent(in)}  :: segment\_str\textcolor{comment}{ !< A string in form of}
1710 \textcolor{comment}{                                                 !!
       "VAR1=file:foo1.nc(varnam1),VAR2=file:foo2.nc(varnam2),..."}
1711    \textcolor{keywordtype}{character(len=*)},  \textcolor{keywordtype}{intent(in)}  :: var\textcolor{comment}{         !< The name of the variable for which parameters are
       needed}
1712    \textcolor{keywordtype}{real},              \textcolor{keywordtype}{intent(out)} :: param\_value\textcolor{comment}{ !< The value of the parameter}
1713    \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: debug\textcolor{comment}{       !< If present and true, write verbose debugging messages}
1714    \textcolor{comment}{! Local variables}
1715    \textcolor{keywordtype}{character(len=128)} :: word1, word2, word3, method
1716    \textcolor{keywordtype}{integer} :: lword, nfields, n, m
1717    \textcolor{keywordtype}{logical} :: continue,dbg
1718    \textcolor{keywordtype}{character(len=32)}, \textcolor{keywordtype}{dimension(MAX\_OBC\_FIELDS)} :: flds
1719 
1720    nfields=0
1721    continue=.true.
1722    dbg=.false.
1723    \textcolor{keywordflow}{if} (\textcolor{keyword}{PRESENT}(debug)) dbg=debug
1724 
1725    \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (continue)
1726       word1 = extract\_word(segment\_str,\textcolor{stringliteral}{','},nfields+1)
1727       \textcolor{keywordflow}{if} (trim(word1) == \textcolor{stringliteral}{''}) \textcolor{keywordflow}{exit}
1728       nfields=nfields+1
1729       word2 = extract\_word(word1,\textcolor{stringliteral}{'='},1)
1730       flds(nfields) = trim(word2)
1731 \textcolor{keywordflow}{   enddo}
1732 
1733    \textcolor{comment}{! if (PRESENT(fields)) then}
1734    \textcolor{comment}{!   do n=1,nfields}
1735    \textcolor{comment}{!     fields(n) = flds(n)}
1736    \textcolor{comment}{!   enddo}
1737    \textcolor{comment}{! endif}
1738 
1739    \textcolor{comment}{! if (PRESENT(num\_fields)) then}
1740    \textcolor{comment}{!    num\_fields=nfields}
1741    \textcolor{comment}{!    return}
1742    \textcolor{comment}{! endif}
1743 
1744    m=0
1745 \textcolor{comment}{!   if (PRESENT(var)) then}
1746      \textcolor{keywordflow}{do} n=1,nfields
1747        \textcolor{keywordflow}{if} (trim(var)==trim(flds(n))) \textcolor{keywordflow}{then}
1748           m=n
1749           \textcolor{keywordflow}{exit}
1750 \textcolor{keywordflow}{       endif}
1751 \textcolor{keywordflow}{     enddo}
1752      \textcolor{keywordflow}{if} (m==0) \textcolor{keywordflow}{then}
1753         \textcolor{keyword}{call }abort()
1754 \textcolor{keywordflow}{     endif}
1755 
1756     \textcolor{comment}{! Process first word which will start with the fieldname}
1757      word3 = extract\_word(segment\_str,\textcolor{stringliteral}{','},m)
1758 \textcolor{comment}{!     word1 = extract\_word(word3,':',1)}
1759 \textcolor{comment}{!     if (trim(word1) == '') exit}
1760      word2 = extract\_word(word1,\textcolor{stringliteral}{'='},1)
1761      \textcolor{keywordflow}{if} (trim(word2) == trim(var)) \textcolor{keywordflow}{then}
1762         method=trim(extract\_word(word1,\textcolor{stringliteral}{'='},2))
1763         lword=len\_trim(method)
1764         \textcolor{keyword}{read}(method(1:lword),*,err=987) param\_value
1765         \textcolor{comment}{! if (method(lword-3:lword) == 'file') then}
1766         \textcolor{comment}{!    ! raise an error id filename/fieldname not in argument list}
1767         \textcolor{comment}{!    word1 = extract\_word(word3,':',2)}
1768         \textcolor{comment}{!    filenam = extract\_word(word1,'(',1)}
1769         \textcolor{comment}{!    fieldnam = extract\_word(word1,'(',2)}
1770         \textcolor{comment}{!    lword=len\_trim(fieldnam)}
1771         \textcolor{comment}{!    fieldnam = fieldnam(1:lword-1)  ! remove trailing parenth}
1772         \textcolor{comment}{!    value=-999.}
1773         \textcolor{comment}{! elseif (method(lword-4:lword) == 'value') then}
1774         \textcolor{comment}{!    filenam = 'none'}
1775         \textcolor{comment}{!    fieldnam = 'none'}
1776         \textcolor{comment}{!    word1 = extract\_word(word3,':',2)}
1777         \textcolor{comment}{!    lword=len\_trim(word1)}
1778         \textcolor{comment}{!    read(word1(1:lword),*,end=986,err=987) value}
1779         \textcolor{comment}{! endif}
1780 \textcolor{keywordflow}{      endif}
1781 \textcolor{comment}{!    endif}
1782 
1783    \textcolor{keywordflow}{return}
1784  986 \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'End of record while parsing segment data specification! '}//trim(segment\_str))
1785  987 \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'Error while parsing segment parameter specification! '}//trim(segment\_str))
1786 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a0eb361009a2dddf3ad9a24d0d7223898}\label{namespacemom__open__boundary_a0eb361009a2dddf3ad9a24d0d7223898}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!parse\+\_\+segment\+\_\+str@{parse\+\_\+segment\+\_\+str}}
\index{parse\+\_\+segment\+\_\+str@{parse\+\_\+segment\+\_\+str}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{parse\+\_\+segment\+\_\+str()}{parse\_segment\_str()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::parse\+\_\+segment\+\_\+str (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{ni\+\_\+global,  }\item[{integer, intent(in)}]{nj\+\_\+global,  }\item[{character(len=$\ast$), intent(in)}]{segment\+\_\+str,  }\item[{integer, intent(out)}]{l,  }\item[{integer, intent(out)}]{m,  }\item[{integer, intent(out)}]{n,  }\item[{character(len=$\ast$), dimension(\+:), intent(out)}]{action\+\_\+str,  }\item[{logical, intent(in)}]{reentrant }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Parse an O\+B\+C\+\_\+\+S\+E\+G\+M\+E\+N\+T\+\_\+\%\%\% string. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em ni\+\_\+global} & Number of h-\/points in zonal direction\\
\hline
\mbox{\tt in}  & {\em nj\+\_\+global} & Number of h-\/points in meridional direction\\
\hline
\mbox{\tt in}  & {\em segment\+\_\+str} & A string in form of \char`\"{}\+I=l,\+J=m\+:n,string\char`\"{} or \char`\"{}\+J=l,\+I=m,n,string\char`\"{}\\
\hline
\mbox{\tt out}  & {\em l} & The value of I=l, if segment\+\_\+str begins with I=l, or the value of J=l\\
\hline
\mbox{\tt out}  & {\em m} & The value of J=m, if segment\+\_\+str begins with I=, or the value of I=m\\
\hline
\mbox{\tt out}  & {\em n} & The value of J=n, if segment\+\_\+str begins with I=, or the value of I=n\\
\hline
\mbox{\tt out}  & {\em action\+\_\+str} & The \char`\"{}string\char`\"{} part of segment\+\_\+str\\
\hline
\mbox{\tt in}  & {\em reentrant} & is domain reentrant in relevant direction? \\
\hline
\end{DoxyParams}


Definition at line 1459 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
1459   \textcolor{keywordtype}{integer},          \textcolor{keywordtype}{intent(in)}  :: ni\_global\textcolor{comment}{ !< Number of h-points in zonal direction}
1460   \textcolor{keywordtype}{integer},          \textcolor{keywordtype}{intent(in)}  :: nj\_global\textcolor{comment}{ !< Number of h-points in meridional direction}
1461   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)}  :: segment\_str\textcolor{comment}{ !< A string in form of "I=l,J=m:n,string" or
       "J=l,I=m,n,string"}
1462   \textcolor{keywordtype}{integer},          \textcolor{keywordtype}{intent(out)} :: l\textcolor{comment}{ !< The value of I=l, if segment\_str begins with I=l, or the value of
       J=l}
1463   \textcolor{keywordtype}{integer},          \textcolor{keywordtype}{intent(out)} :: m\textcolor{comment}{ !< The value of J=m, if segment\_str begins with I=, or the value of
       I=m}
1464   \textcolor{keywordtype}{integer},          \textcolor{keywordtype}{intent(out)} :: n\textcolor{comment}{ !< The value of J=n, if segment\_str begins with I=, or the value of
       I=n}
1465   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(out)} :: action\_str(:)\textcolor{comment}{ !< The "string" part of segment\_str}
1466   \textcolor{keywordtype}{logical},          \textcolor{keywordtype}{intent(in)}  :: reentrant\textcolor{comment}{ !< is domain reentrant in relevant direction?}
1467   \textcolor{comment}{! Local variables}
1468   \textcolor{keywordtype}{character(len=24)} :: word1, word2, m\_word, n\_word\textcolor{comment}{ !< Words delineated by commas in a string in form of}
1469 \textcolor{comment}{                                                    !! "I=%,J=%:%,string"}
1470   \textcolor{keywordtype}{integer} :: l\_max\textcolor{comment}{ !< Either ni\_global or nj\_global, depending on whether segment\_str begins with "I=" or
       "J="}
1471   \textcolor{keywordtype}{integer} :: mn\_max\textcolor{comment}{ !< Either nj\_global or ni\_global, depending on whether segment\_str begins with "I=" or
       "J="}
1472   \textcolor{keywordtype}{integer} :: j
1473   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: halo = 10
1474 
1475   \textcolor{comment}{! Process first word which will started with either 'I=' or 'J='}
1476   word1 = extract\_word(segment\_str,\textcolor{stringliteral}{','},1)
1477   word2 = extract\_word(segment\_str,\textcolor{stringliteral}{','},2)
1478   \textcolor{keywordflow}{if} (word1(1:2)==\textcolor{stringliteral}{'I='}) \textcolor{keywordflow}{then}
1479     l\_max = ni\_global
1480     mn\_max = nj\_global
1481     \textcolor{keywordflow}{if} (.not. (word2(1:2)==\textcolor{stringliteral}{'J='})) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, parse\_segment\_str: "}//&
1482                      \textcolor{stringliteral}{"Second word of string '"}//trim(segment\_str)//\textcolor{stringliteral}{"' must start with 'J='."})
1483   \textcolor{keywordflow}{elseif} (word1(1:2)==\textcolor{stringliteral}{'J='}) \textcolor{keywordflow}{then} \textcolor{comment}{! Note that the file\_parser uniformaly expands "=" to " = "}
1484     l\_max = nj\_global
1485     mn\_max = ni\_global
1486     \textcolor{keywordflow}{if} (.not. (word2(1:2)==\textcolor{stringliteral}{'I='})) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, parse\_segment\_str: "}//&
1487                      \textcolor{stringliteral}{"Second word of string '"}//trim(segment\_str)//\textcolor{stringliteral}{"' must start with 'I='."})
1488   \textcolor{keywordflow}{else}
1489     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, parse\_segment\_str"}//&
1490                    \textcolor{stringliteral}{"String '"}//segment\_str//\textcolor{stringliteral}{"' must start with 'I=' or 'J='."})
1491 \textcolor{keywordflow}{  endif}
1492 
1493   \textcolor{comment}{! Read l}
1494   l = interpret\_int\_expr( word1(3:24), l\_max )
1495   \textcolor{keywordflow}{if} (l<0 .or. l>l\_max) \textcolor{keywordflow}{then}
1496     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, parse\_segment\_str: "}//&
1497                    \textcolor{stringliteral}{"First value from string '"}//trim(segment\_str)//\textcolor{stringliteral}{"' is outside of the physical domain."})
1498 \textcolor{keywordflow}{  endif}
1499 
1500   \textcolor{comment}{! Read m}
1501   m\_word = extract\_word(word2(3:24),\textcolor{stringliteral}{':'},1)
1502   m = interpret\_int\_expr( m\_word, mn\_max )
1503   \textcolor{keywordflow}{if} (reentrant) \textcolor{keywordflow}{then}
1504     \textcolor{keywordflow}{if} (m<-halo .or. m>mn\_max+halo) \textcolor{keywordflow}{then}
1505       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, parse\_segment\_str: "}//&
1506                      \textcolor{stringliteral}{"Beginning of range in string '"}//trim(segment\_str)//\textcolor{stringliteral}{"' is outside of the physical
       domain."})
1507 \textcolor{keywordflow}{    endif}
1508   \textcolor{keywordflow}{else}
1509     \textcolor{keywordflow}{if} (m<-1 .or. m>mn\_max+1) \textcolor{keywordflow}{then}
1510       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, parse\_segment\_str: "}//&
1511                      \textcolor{stringliteral}{"Beginning of range in string '"}//trim(segment\_str)//\textcolor{stringliteral}{"' is outside of the physical
       domain."})
1512 \textcolor{keywordflow}{    endif}
1513 \textcolor{keywordflow}{  endif}
1514 
1515   \textcolor{comment}{! Read n}
1516   n\_word = extract\_word(word2(3:24),\textcolor{stringliteral}{':'},2)
1517   n = interpret\_int\_expr( n\_word, mn\_max )
1518   \textcolor{keywordflow}{if} (reentrant) \textcolor{keywordflow}{then}
1519     \textcolor{keywordflow}{if} (n<-halo .or. n>mn\_max+halo) \textcolor{keywordflow}{then}
1520       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, parse\_segment\_str: "}//&
1521                      \textcolor{stringliteral}{"End of range in string '"}//trim(segment\_str)//\textcolor{stringliteral}{"' is outside of the physical domain."})
1522 \textcolor{keywordflow}{    endif}
1523   \textcolor{keywordflow}{else}
1524     \textcolor{keywordflow}{if} (n<-1 .or. n>mn\_max+1) \textcolor{keywordflow}{then}
1525       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, parse\_segment\_str: "}//&
1526                      \textcolor{stringliteral}{"End of range in string '"}//trim(segment\_str)//\textcolor{stringliteral}{"' is outside of the physical domain."})
1527 \textcolor{keywordflow}{    endif}
1528 \textcolor{keywordflow}{  endif}
1529 
1530   \textcolor{keywordflow}{if} (abs(n-m)==0) \textcolor{keywordflow}{then}
1531     \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, parse\_segment\_str: "}//&
1532                    \textcolor{stringliteral}{"Range in string '"}//trim(segment\_str)//\textcolor{stringliteral}{"' must span one cell."})
1533 \textcolor{keywordflow}{  endif}
1534 
1535   \textcolor{comment}{! Type of open boundary condition}
1536   \textcolor{keywordflow}{do} j = 1, \textcolor{keyword}{size}(action\_str)
1537     action\_str(j) = extract\_word(segment\_str,\textcolor{stringliteral}{','},2+j)
1538 \textcolor{keywordflow}{  enddo}
1539 
1540   \textcolor{keyword}{contains}
1541 
1542   \textcolor{comment}{! Returns integer value interpreted from string in form of %I, N or N+-%I}
1543 \textcolor{keyword}{  integer }\textcolor{keyword}{function }interpret\_int\_expr(string, imax)
1544     \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)} :: string\textcolor{comment}{ !< Integer in form or %I, N or N-%I}
1545     \textcolor{keywordtype}{integer},          \textcolor{keywordtype}{intent(in)} :: imax\textcolor{comment}{ !< Value to replace 'N' with}
1546     \textcolor{comment}{! Local variables}
1547     \textcolor{keywordtype}{integer} slen
1548 
1549     slen = len\_trim(string)
1550     \textcolor{keywordflow}{if} (slen==0) \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, parse\_segment\_str"}//&
1551                                 \textcolor{stringliteral}{"Parsed string was empty!"})
1552     \textcolor{keywordflow}{if} (len\_trim(string)==1 .and. string(1:1)==\textcolor{stringliteral}{'N'}) \textcolor{keywordflow}{then}
1553       interpret\_int\_expr = imax
1554     \textcolor{keywordflow}{elseif} (string(1:1)==\textcolor{stringliteral}{'N'}) \textcolor{keywordflow}{then}
1555       \textcolor{keywordflow}{if} (string(2:2)==\textcolor{stringliteral}{'+'}) \textcolor{keywordflow}{then}
1556         \textcolor{keyword}{read}(string(3:slen),*,err=911) interpret\_int\_expr
1557         interpret\_int\_expr = imax + interpret\_int\_expr
1558       \textcolor{keywordflow}{elseif} (string(2:2)==\textcolor{stringliteral}{'-'}) \textcolor{keywordflow}{then}
1559         \textcolor{keyword}{read}(string(3:slen),*,err=911) interpret\_int\_expr
1560         interpret\_int\_expr = imax - interpret\_int\_expr
1561 \textcolor{keywordflow}{      endif}
1562     \textcolor{keywordflow}{else}
1563       \textcolor{keyword}{read}(string(1:slen),*,err=911) interpret\_int\_expr
1564 \textcolor{keywordflow}{    endif}
1565     \textcolor{keywordflow}{return}
1566     911 \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, parse\_segment\_str"}//&
1567                        \textcolor{stringliteral}{"Problem reading value from string '"}//trim(string)//\textcolor{stringliteral}{"'."})
1568 \textcolor{keyword}{  end function }interpret\_int\_expr
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_ae5ceafcce53e896d30012f321c73d9f4}\label{namespacemom__open__boundary_ae5ceafcce53e896d30012f321c73d9f4}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!radiation\+\_\+open\+\_\+bdry\+\_\+conds@{radiation\+\_\+open\+\_\+bdry\+\_\+conds}}
\index{radiation\+\_\+open\+\_\+bdry\+\_\+conds@{radiation\+\_\+open\+\_\+bdry\+\_\+conds}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{radiation\+\_\+open\+\_\+bdry\+\_\+conds()}{radiation\_open\_bdry\_conds()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::radiation\+\_\+open\+\_\+bdry\+\_\+conds (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{u\+\_\+new,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{u\+\_\+old,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(inout)}]{v\+\_\+new,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{v\+\_\+old,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{real, intent(in)}]{dt }\end{DoxyParamCaption})}



Apply radiation conditions to 3D u,v at open boundaries. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean grid structure\\
\hline
 & {\em obc} & Open boundary control structure\\
\hline
\mbox{\tt in,out}  & {\em u\+\_\+new} & On exit, new u values on open boundaries On entry, the old time-\/level v but including barotropic accelerations \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em u\+\_\+old} & Original unadjusted u \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em v\+\_\+new} & On exit, new v values on open boundaries. On entry, the old time-\/level v but including barotropic accelerations \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}.\\
\hline
\mbox{\tt in}  & {\em v\+\_\+old} & Original unadjusted v \mbox{[}L T-\/1 $\sim$$>$ m s-\/1\mbox{]}\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em dt} & Appropriate timestep \mbox{[}T $\sim$$>$ s\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 2119 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
2119   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{ !< Ocean grid structure}
2120   \textcolor{keywordtype}{type}(ocean\_obc\_type),                      \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{ !< Open boundary control structure}
2121   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: u\_new\textcolor{comment}{ !< On exit, new u values on open
       boundaries}
2122 \textcolor{comment}{                                                                    !! On entry, the old time-level v but
       including}
2123 \textcolor{comment}{                                                                    !! barotropic accelerations [L T-1 ~> m
       s-1].}
2124   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: u\_old\textcolor{comment}{ !< Original unadjusted u [L T-1 ~> m
       s-1]}
2125   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: v\_new\textcolor{comment}{ !< On exit, new v values on open
       boundaries.}
2126 \textcolor{comment}{                                                                    !! On entry, the old time-level v but
       including}
2127 \textcolor{comment}{                                                                    !! barotropic accelerations [L T-1 ~> m
       s-1].}
2128   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)}    :: v\_old\textcolor{comment}{ !< Original unadjusted v  [L T-1 ~> m
       s-1]}
2129   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{    !< A dimensional unit scaling type}
2130   \textcolor{keywordtype}{real},                                      \textcolor{keywordtype}{intent(in)}    :: dt\textcolor{comment}{    !< Appropriate timestep [T ~> s]}
2131   \textcolor{comment}{! Local variables}
2132   \textcolor{keywordtype}{real} :: dhdt, dhdx, dhdy  \textcolor{comment}{! One-point differences in time or space [L T-1 ~> m s-1]}
2133   \textcolor{keywordtype}{real} :: gamma\_u, gamma\_2  \textcolor{comment}{! Fractional weightings of new values [nondim]}
2134   \textcolor{keywordtype}{real} :: tau            \textcolor{comment}{! A local nudging timescale [T ~> s]}
2135   \textcolor{keywordtype}{real} :: rx\_max, ry\_max \textcolor{comment}{! coefficients for radiation [nondim]}
2136   \textcolor{keywordtype}{real} :: rx\_new, rx\_avg \textcolor{comment}{! coefficients for radiation [nondim] or [L2 T-2 ~> m2 s-2]}
2137   \textcolor{keywordtype}{real} :: ry\_new, ry\_avg \textcolor{comment}{! coefficients for radiation [nondim] or [L2 T-2 ~> m2 s-2]}
2138   \textcolor{keywordtype}{real} :: cff\_new, cff\_avg \textcolor{comment}{! denominator in oblique [L2 T-2 ~> m2 s-2]}
2139   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:,:)} :: &
2140     rx\_tang\_rad, & \textcolor{comment}{! The phase speed at u-points for tangential oblique OBCs}
2141                    \textcolor{comment}{! in units of grid points per timestep [nondim]}
2142     ry\_tang\_rad, & \textcolor{comment}{! The phase speed at v-points for tangential oblique OBCs}
2143                    \textcolor{comment}{! in units of grid points per timestep [nondim]}
2144     rx\_tang\_obl, & \textcolor{comment}{! The x-coefficient for tangential oblique OBCs [L2 T-2 ~> m2 s-2]}
2145     ry\_tang\_obl, & \textcolor{comment}{! The y-coefficient for tangential oblique OBCs [L2 T-2 ~> m2 s-2]}
2146     cff\_tangential \textcolor{comment}{! The denominator for tangential oblique OBCs [L2 T-2 ~> m2 s-2]}
2147   \textcolor{keywordtype}{real} :: eps      \textcolor{comment}{! A small velocity squared [L2 T-2 ~> m2 s-2]}
2148   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()
2149   \textcolor{keywordtype}{integer} :: i, j, k, is, ie, js, je, m, nz, n
2150   \textcolor{keywordtype}{integer} :: is\_obc, ie\_obc, js\_obc, je\_obc
2151 
2152   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
2153 
2154   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{return}
2155 
2156   \textcolor{keywordflow}{if} (.not.(obc%open\_u\_BCs\_exist\_globally .or. obc%open\_v\_BCs\_exist\_globally)) &
2157     \textcolor{keywordflow}{return}
2158 
2159   eps = 1.0e-20*us%m\_s\_to\_L\_T**2
2160 
2161   \textcolor{comment}{!! Copy previously calculated phase velocity from global arrays into segments}
2162   \textcolor{comment}{!! This is terribly inefficient and temporary solution for continuity across restarts}
2163   \textcolor{comment}{!! and needs to be revisited in the future.}
2164   \textcolor{keywordflow}{if} (obc%gamma\_uv < 1.0) \textcolor{keywordflow}{then}
2165     \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
2166       segment=>obc%segment(n)
2167       \textcolor{keywordflow}{if} (.not. segment%on\_pe) cycle
2168       \textcolor{keywordflow}{if} (segment%is\_E\_or\_W .and. segment%radiation) \textcolor{keywordflow}{then}
2169         \textcolor{keywordflow}{do} k=1,g%ke
2170           i=segment%HI%IsdB
2171           \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
2172             segment%rx\_norm\_rad(i,j,k) = obc%rx\_normal(i,j,k)
2173 \textcolor{keywordflow}{          enddo}
2174 \textcolor{keywordflow}{        enddo}
2175       \textcolor{keywordflow}{elseif} (segment%is\_N\_or\_S .and. segment%radiation) \textcolor{keywordflow}{then}
2176         \textcolor{keywordflow}{do} k=1,g%ke
2177           j=segment%HI%JsdB
2178           \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
2179             segment%ry\_norm\_rad(i,j,k) = obc%ry\_normal(i,j,k)
2180 \textcolor{keywordflow}{          enddo}
2181 \textcolor{keywordflow}{        enddo}
2182 \textcolor{keywordflow}{      endif}
2183       \textcolor{keywordflow}{if} (segment%is\_E\_or\_W .and. segment%oblique) \textcolor{keywordflow}{then}
2184         \textcolor{keywordflow}{do} k=1,g%ke
2185           i=segment%HI%IsdB
2186           \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
2187             segment%rx\_norm\_obl(i,j,k) = obc%rx\_oblique(i,j,k)
2188             segment%ry\_norm\_obl(i,j,k) = obc%ry\_oblique(i,j,k)
2189             segment%cff\_normal(i,j,k) = obc%cff\_normal(i,j,k)
2190 \textcolor{keywordflow}{          enddo}
2191 \textcolor{keywordflow}{        enddo}
2192       \textcolor{keywordflow}{elseif} (segment%is\_N\_or\_S .and. segment%oblique) \textcolor{keywordflow}{then}
2193         \textcolor{keywordflow}{do} k=1,g%ke
2194           j=segment%HI%JsdB
2195           \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
2196             segment%rx\_norm\_obl(i,j,k) = obc%rx\_oblique(i,j,k)
2197             segment%ry\_norm\_obl(i,j,k) = obc%ry\_oblique(i,j,k)
2198             segment%cff\_normal(i,j,k) = obc%cff\_normal(i,j,k)
2199 \textcolor{keywordflow}{          enddo}
2200 \textcolor{keywordflow}{        enddo}
2201 \textcolor{keywordflow}{      endif}
2202 \textcolor{keywordflow}{    enddo}
2203 \textcolor{keywordflow}{  endif}
2204 
2205   \textcolor{comment}{! Now tracers (if any)}
2206   \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
2207     segment=>obc%segment(n)
2208     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tr\_Reg)) \textcolor{keywordflow}{then}
2209       \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
2210         i = segment%HI%IsdB
2211         \textcolor{keywordflow}{do} m=1,obc%ntr
2212           \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tr\_Reg%Tr(m)%tres)) \textcolor{keywordflow}{then}
2213             \textcolor{keywordflow}{do} k=1,g%ke
2214               \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
2215                 segment%tr\_Reg%Tr(m)%tres(i,j,k) = obc%tres\_x(i,j,k,m)
2216 \textcolor{keywordflow}{              enddo}
2217 \textcolor{keywordflow}{            enddo}
2218 \textcolor{keywordflow}{          endif}
2219 \textcolor{keywordflow}{        enddo}
2220       \textcolor{keywordflow}{else}
2221         j = segment%HI%JsdB
2222         \textcolor{keywordflow}{do} m=1,obc%ntr
2223           \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tr\_Reg%Tr(m)%tres)) \textcolor{keywordflow}{then}
2224             \textcolor{keywordflow}{do} k=1,g%ke
2225               \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
2226                 segment%tr\_Reg%Tr(m)%tres(i,j,k) = obc%tres\_y(i,j,k,m)
2227 \textcolor{keywordflow}{              enddo}
2228 \textcolor{keywordflow}{            enddo}
2229 \textcolor{keywordflow}{          endif}
2230 \textcolor{keywordflow}{        enddo}
2231 \textcolor{keywordflow}{      endif}
2232 \textcolor{keywordflow}{    endif}
2233 \textcolor{keywordflow}{  enddo}
2234 
2235   gamma\_u = obc%gamma\_uv
2236   rx\_max = obc%rx\_max ; ry\_max = obc%rx\_max
2237   \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
2238      segment=>obc%segment(n)
2239      \textcolor{keywordflow}{if} (.not. segment%on\_pe) cycle
2240      \textcolor{keywordflow}{if} (segment%oblique) \textcolor{keyword}{call }gradient\_at\_q\_points(g, segment, u\_new(:,:,:), v\_new(:,:,:))
2241      \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_e) \textcolor{keywordflow}{then}
2242        i=segment%HI%IsdB
2243        \textcolor{keywordflow}{if} (i<g%HI%IscB) cycle
2244        \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
2245          \textcolor{keywordflow}{if} (segment%radiation) \textcolor{keywordflow}{then}
2246            dhdt = (u\_old(i-1,j,k) - u\_new(i-1,j,k)) \textcolor{comment}{!old-new}
2247            dhdx = (u\_new(i-1,j,k) - u\_new(i-2,j,k)) \textcolor{comment}{!in new time backward sasha for I-1}
2248            rx\_new = 0.0
2249            \textcolor{keywordflow}{if} (dhdt*dhdx > 0.0) rx\_new = min( (dhdt/dhdx), rx\_max) \textcolor{comment}{! outward phase speed}
2250            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2251              rx\_avg = (1.0-gamma\_u)*segment%rx\_norm\_rad(i,j,k) + gamma\_u*rx\_new
2252            \textcolor{keywordflow}{else}
2253              rx\_avg = rx\_new
2254 \textcolor{keywordflow}{           endif}
2255            segment%rx\_norm\_rad(i,j,k) = rx\_avg
2256            \textcolor{comment}{! The new boundary value is interpolated between future interior}
2257            \textcolor{comment}{! value, u\_new(I-1) and past boundary value but with barotropic}
2258            \textcolor{comment}{! accelerations, u\_new(I).}
2259            segment%normal\_vel(i,j,k) = (u\_new(i,j,k) + rx\_avg*u\_new(i-1,j,k)) / (1.0+rx\_avg)
2260            \textcolor{comment}{! Copy restart fields into 3-d arrays. This is an inefficient and temporary issues}
2261            \textcolor{comment}{! implemented as a work-around to limitations in restart capability}
2262            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2263              obc%rx\_normal(i,j,k) = segment%rx\_norm\_rad(i,j,k)
2264 \textcolor{keywordflow}{           endif}
2265          \textcolor{keywordflow}{elseif} (segment%oblique) \textcolor{keywordflow}{then}
2266            dhdt = (u\_old(i-1,j,k) - u\_new(i-1,j,k)) \textcolor{comment}{!old-new}
2267            dhdx = (u\_new(i-1,j,k) - u\_new(i-2,j,k)) \textcolor{comment}{!in new time backward sasha for I-1}
2268            \textcolor{keywordflow}{if} (dhdt*(segment%grad\_normal(j,1,k) + segment%grad\_normal(j-1,1,k)) > 0.0) \textcolor{keywordflow}{then}
2269              dhdy = segment%grad\_normal(j-1,1,k)
2270            \textcolor{keywordflow}{elseif} (dhdt*(segment%grad\_normal(j,1,k) + segment%grad\_normal(j-1,1,k)) == 0.0) \textcolor{keywordflow}{then}
2271              dhdy = 0.0
2272            \textcolor{keywordflow}{else}
2273              dhdy = segment%grad\_normal(j,1,k)
2274 \textcolor{keywordflow}{           endif}
2275            \textcolor{keywordflow}{if} (dhdt*dhdx < 0.0) dhdt = 0.0
2276            cff\_new = max(dhdx*dhdx + dhdy*dhdy, eps)
2277            rx\_new = min(dhdt*dhdx, cff\_new*rx\_max)
2278            ry\_new = min(cff\_new,max(dhdt*dhdy,-cff\_new))
2279            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2280              rx\_avg = (1.0-gamma\_u)*segment%rx\_norm\_obl(i,j,k) + gamma\_u*rx\_new
2281              ry\_avg = (1.0-gamma\_u)*segment%ry\_norm\_obl(i,j,k) + gamma\_u*ry\_new
2282              cff\_avg = (1.0-gamma\_u)*segment%cff\_normal(i,j,k) + gamma\_u*cff\_new
2283            \textcolor{keywordflow}{else}
2284              rx\_avg = rx\_new
2285              ry\_avg = ry\_new
2286              cff\_avg = cff\_new
2287 \textcolor{keywordflow}{           endif}
2288            segment%rx\_norm\_obl(i,j,k) = rx\_avg
2289            segment%ry\_norm\_obl(i,j,k) = ry\_avg
2290            segment%cff\_normal(i,j,k) = cff\_avg
2291            segment%normal\_vel(i,j,k) = ((cff\_avg*u\_new(i,j,k) + rx\_avg*u\_new(i-1,j,k)) - &
2292                               (max(ry\_avg,0.0)*segment%grad\_normal(j-1,2,k) + &
2293                                min(ry\_avg,0.0)*segment%grad\_normal(j,2,k))) / &
2294                             (cff\_avg + rx\_avg)
2295            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2296              \textcolor{comment}{! Copy restart fields into 3-d arrays. This is an inefficient and temporary}
2297              \textcolor{comment}{! implementation as a work-around to limitations in restart capability}
2298              obc%rx\_oblique(i,j,k) = segment%rx\_norm\_obl(i,j,k)
2299              obc%ry\_oblique(i,j,k) = segment%ry\_norm\_obl(i,j,k)
2300              obc%cff\_normal(i,j,k) = segment%cff\_normal(i,j,k)
2301 \textcolor{keywordflow}{           endif}
2302          \textcolor{keywordflow}{elseif} (segment%gradient) \textcolor{keywordflow}{then}
2303            segment%normal\_vel(i,j,k) = u\_new(i-1,j,k)
2304 \textcolor{keywordflow}{         endif}
2305          \textcolor{keywordflow}{if} ((segment%radiation .or. segment%oblique) .and. segment%nudged) \textcolor{keywordflow}{then}
2306            \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
2307            \textcolor{keywordflow}{if} (dhdt*dhdx <= 0.0) \textcolor{keywordflow}{then}
2308              tau = segment%Velocity\_nudging\_timescale\_in
2309            \textcolor{keywordflow}{else}
2310              tau = segment%Velocity\_nudging\_timescale\_out
2311 \textcolor{keywordflow}{           endif}
2312            gamma\_2 = dt / (tau + dt)
2313            segment%normal\_vel(i,j,k) = (1.0 - gamma\_2) * segment%normal\_vel(i,j,k) + &
2314                                  gamma\_2 * segment%nudged\_normal\_vel(i,j,k)
2315 \textcolor{keywordflow}{         endif}
2316 \textcolor{keywordflow}{       enddo} ;\textcolor{keywordflow}{ enddo}
2317        \textcolor{keywordflow}{if} (segment%radiation\_tan .or. segment%radiation\_grad) \textcolor{keywordflow}{then}
2318          i=segment%HI%IsdB
2319          \textcolor{keyword}{allocate}(rx\_tang\_rad(segment%HI%IsdB:segment%HI%IedB,segment%HI%JsdB:segment%HI%JedB,nz))
2320          \textcolor{keywordflow}{do} k=1,nz
2321            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2322              rx\_tang\_rad(i,segment%HI%JsdB,k) = segment%rx\_norm\_rad(i,segment%HI%jsd,k)
2323              rx\_tang\_rad(i,segment%HI%JedB,k) = segment%rx\_norm\_rad(i,segment%HI%jed,k)
2324              \textcolor{keywordflow}{do} j=segment%HI%JsdB+1,segment%HI%JedB-1
2325                rx\_tang\_rad(i,j,k) = 0.5*(segment%rx\_norm\_rad(i,j,k) + segment%rx\_norm\_rad(i,j+1,k))
2326 \textcolor{keywordflow}{             enddo}
2327            \textcolor{keywordflow}{else}
2328              \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
2329                dhdt = v\_old(i,j,k)-v\_new(i,j,k)   \textcolor{comment}{!old-new}
2330                dhdx = v\_new(i,j,k)-v\_new(i-1,j,k) \textcolor{comment}{!in new time backward sasha for I-1}
2331                rx\_tang\_rad(i,j,k) = 0.0
2332                \textcolor{keywordflow}{if} (dhdt*dhdx > 0.0) rx\_tang\_rad(i,j,k) = min( (dhdt/dhdx), rx\_max) \textcolor{comment}{! outward phase speed}
2333 \textcolor{keywordflow}{             enddo}
2334 \textcolor{keywordflow}{           endif}
2335 \textcolor{keywordflow}{         enddo}
2336          \textcolor{keywordflow}{if} (segment%radiation\_tan) \textcolor{keywordflow}{then}
2337            \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
2338              rx\_avg = rx\_tang\_rad(i,j,k)
2339              segment%tangential\_vel(i,j,k) = (v\_new(i,j,k) + rx\_avg*v\_new(i-1,j,k)) / (1.0+rx\_avg)
2340 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2341 \textcolor{keywordflow}{         endif}
2342          \textcolor{keywordflow}{if} (segment%nudged\_tan) \textcolor{keywordflow}{then}
2343            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
2344              \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
2345              \textcolor{keywordflow}{if} (rx\_tang\_rad(i,j,k) <= 0.0) \textcolor{keywordflow}{then}
2346                tau = segment%Velocity\_nudging\_timescale\_in
2347              \textcolor{keywordflow}{else}
2348                tau = segment%Velocity\_nudging\_timescale\_out
2349 \textcolor{keywordflow}{             endif}
2350              gamma\_2 = dt / (tau + dt)
2351              segment%tangential\_vel(i,j,k) = (1.0 - gamma\_2) * segment%tangential\_vel(i,j,k) + &
2352                                  gamma\_2 * segment%nudged\_tangential\_vel(i,j,k)
2353 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2354 \textcolor{keywordflow}{         endif}
2355          \textcolor{keywordflow}{if} (segment%radiation\_grad) \textcolor{keywordflow}{then}
2356            js\_obc = max(segment%HI%JsdB,g%jsd+1)
2357            je\_obc = min(segment%HI%JedB,g%jed-1)
2358            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=js\_obc,je\_obc
2359              rx\_avg = rx\_tang\_rad(i,j,k)
2360 \textcolor{comment}{!            if (G%mask2dCu(I-1,j) > 0.0 .and. G%mask2dCu(I-1,j+1) > 0.0) then}
2361 \textcolor{comment}{!              rx\_avg = 0.5*(u\_new(I-1,j,k) + u\_new(I-1,j+1,k)) * dt * G%IdxBu(I-1,J)}
2362 \textcolor{comment}{!            elseif (G%mask2dCu(I-1,j) > 0.0) then}
2363 \textcolor{comment}{!              rx\_avg = u\_new(I-1,j,k) * dt * G%IdxBu(I-1,J)}
2364 \textcolor{comment}{!            elseif (G%mask2dCu(I-1,j+1) > 0.0) then}
2365 \textcolor{comment}{!              rx\_avg = u\_new(I-1,j+1,k) * dt * G%IdxBu(I-1,J)}
2366 \textcolor{comment}{!            else}
2367 \textcolor{comment}{!              rx\_avg = 0.0}
2368 \textcolor{comment}{!            endif}
2369              segment%tangential\_grad(i,j,k) = ((v\_new(i,j,k) - v\_new(i-1,j,k))*g%IdxBu(i-1,j) + &
2370                                rx\_avg*(v\_new(i-1,j,k) - v\_new(i-2,j,k))*g%IdxBu(i-2,j)) / (1.0+rx\_avg)
2371 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2372 \textcolor{keywordflow}{         endif}
2373          \textcolor{keywordflow}{if} (segment%nudged\_grad) \textcolor{keywordflow}{then}
2374            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
2375              \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
2376              \textcolor{keywordflow}{if} (rx\_tang\_rad(i,j,k) <= 0.0) \textcolor{keywordflow}{then}
2377                tau = segment%Velocity\_nudging\_timescale\_in
2378              \textcolor{keywordflow}{else}
2379                tau = segment%Velocity\_nudging\_timescale\_out
2380 \textcolor{keywordflow}{             endif}
2381              gamma\_2 = dt / (tau + dt)
2382              segment%tangential\_grad(i,j,k) = (1.0 - gamma\_2) * segment%tangential\_grad(i,j,k) + &
2383                                  gamma\_2 * segment%nudged\_tangential\_grad(i,j,k)
2384 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2385 \textcolor{keywordflow}{         endif}
2386          \textcolor{keyword}{deallocate}(rx\_tang\_rad)
2387 \textcolor{keywordflow}{       endif}
2388        \textcolor{keywordflow}{if} (segment%oblique\_tan .or. segment%oblique\_grad) \textcolor{keywordflow}{then}
2389          i=segment%HI%IsdB
2390          \textcolor{keyword}{allocate}(rx\_tang\_obl(segment%HI%IsdB:segment%HI%IedB,segment%HI%JsdB:segment%HI%JedB,nz))
2391          \textcolor{keyword}{allocate}(ry\_tang\_obl(segment%HI%IsdB:segment%HI%IedB,segment%HI%JsdB:segment%HI%JedB,nz))
2392          \textcolor{keyword}{allocate}(cff\_tangential(segment%HI%IsdB:segment%HI%IedB,segment%HI%JsdB:segment%HI%JedB,nz))
2393          \textcolor{keywordflow}{do} k=1,nz
2394            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2395              rx\_tang\_obl(i,segment%HI%JsdB,k) = segment%rx\_norm\_obl(i,segment%HI%jsd,k)
2396              rx\_tang\_obl(i,segment%HI%JedB,k) = segment%rx\_norm\_obl(i,segment%HI%jed,k)
2397              ry\_tang\_obl(i,segment%HI%JsdB,k) = segment%ry\_norm\_obl(i,segment%HI%jsd,k)
2398              ry\_tang\_obl(i,segment%HI%JedB,k) = segment%ry\_norm\_obl(i,segment%HI%jed,k)
2399              cff\_tangential(i,segment%HI%JsdB,k) = segment%cff\_normal(i,segment%HI%jsd,k)
2400              cff\_tangential(i,segment%HI%JedB,k) = segment%cff\_normal(i,segment%HI%jed,k)
2401              \textcolor{keywordflow}{do} j=segment%HI%JsdB+1,segment%HI%JedB-1
2402                rx\_tang\_obl(i,j,k) = 0.5*(segment%rx\_norm\_obl(i,j,k) + segment%rx\_norm\_obl(i,j+1,k))
2403                ry\_tang\_obl(i,j,k) = 0.5*(segment%ry\_norm\_obl(i,j,k) + segment%ry\_norm\_obl(i,j+1,k))
2404                cff\_tangential(i,j,k) = 0.5*(segment%cff\_normal(i,j,k) + segment%cff\_normal(i,j+1,k))
2405 \textcolor{keywordflow}{             enddo}
2406            \textcolor{keywordflow}{else}
2407              \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
2408                dhdt = v\_old(i,j,k)-v\_new(i,j,k)   \textcolor{comment}{!old-new}
2409                dhdx = v\_new(i,j,k)-v\_new(i-1,j,k) \textcolor{comment}{!in new time backward sasha for I-1}
2410                \textcolor{keywordflow}{if} (dhdt*(segment%grad\_tan(j,1,k) + segment%grad\_tan(j+1,1,k)) > 0.0) \textcolor{keywordflow}{then}
2411                  dhdy = segment%grad\_tan(j,1,k)
2412                \textcolor{keywordflow}{elseif} (dhdt*(segment%grad\_tan(j,1,k) + segment%grad\_tan(j+1,1,k)) == 0.0) \textcolor{keywordflow}{then}
2413                  dhdy = 0.0
2414                \textcolor{keywordflow}{else}
2415                  dhdy = segment%grad\_tan(j+1,1,k)
2416 \textcolor{keywordflow}{               endif}
2417                \textcolor{keywordflow}{if} (dhdt*dhdx < 0.0) dhdt = 0.0
2418                cff\_new = max(dhdx*dhdx + dhdy*dhdy, eps)
2419                rx\_new = min(dhdt*dhdx, cff\_new*rx\_max)
2420                ry\_new = min(cff\_new,max(dhdt*dhdy,-cff\_new))
2421                rx\_tang\_obl(i,j,k) = rx\_new
2422                ry\_tang\_obl(i,j,k) = ry\_new
2423                cff\_tangential(i,j,k) = cff\_new
2424 \textcolor{keywordflow}{             enddo}
2425 \textcolor{keywordflow}{           endif}
2426 \textcolor{keywordflow}{         enddo}
2427          \textcolor{keywordflow}{if} (segment%oblique\_tan) \textcolor{keywordflow}{then}
2428            \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
2429              rx\_avg = rx\_tang\_obl(i,j,k)
2430              ry\_avg = ry\_tang\_obl(i,j,k)
2431              cff\_avg = cff\_tangential(i,j,k)
2432              segment%tangential\_vel(i,j,k) = ((cff\_avg*v\_new(i,j,k) + rx\_avg*v\_new(i-1,j,k)) - &
2433                                               (max(ry\_avg,0.0)*segment%grad\_tan(j,2,k) + &
2434                                                min(ry\_avg,0.0)*segment%grad\_tan(j+1,2,k))) / &
2435                                              (cff\_avg + rx\_avg)
2436 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2437 \textcolor{keywordflow}{         endif}
2438          \textcolor{keywordflow}{if} (segment%nudged\_tan) \textcolor{keywordflow}{then}
2439            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
2440              \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
2441              \textcolor{keywordflow}{if} (rx\_tang\_obl(i,j,k) <= 0.0) \textcolor{keywordflow}{then}
2442                tau = segment%Velocity\_nudging\_timescale\_in
2443              \textcolor{keywordflow}{else}
2444                tau = segment%Velocity\_nudging\_timescale\_out
2445 \textcolor{keywordflow}{             endif}
2446              gamma\_2 = dt / (tau + dt)
2447              segment%tangential\_vel(i,j,k) = (1.0 - gamma\_2) * segment%tangential\_vel(i,j,k) + &
2448                                  gamma\_2 * segment%nudged\_tangential\_vel(i,j,k)
2449 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2450 \textcolor{keywordflow}{         endif}
2451          \textcolor{keywordflow}{if} (segment%oblique\_grad) \textcolor{keywordflow}{then}
2452            js\_obc = max(segment%HI%JsdB,g%jsd+1)
2453            je\_obc = min(segment%HI%JedB,g%jed-1)
2454            \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} j=segment%HI%JsdB+1,segment%HI%JedB-1
2455              rx\_avg = rx\_tang\_obl(i,j,k)
2456              ry\_avg = ry\_tang\_obl(i,j,k)
2457              cff\_avg = cff\_tangential(i,j,k)
2458              segment%tangential\_grad(i,j,k) =  &
2459                  ((cff\_avg*(v\_new(i,j,k)  - v\_new(i-1,j,k))*g%IdxBu(i-1,j) + &
2460                    rx\_avg*(v\_new(i-1,j,k) - v\_new(i-2,j,k))*g%IdxBu(i-2,j)) - &
2461                   (max(ry\_avg,0.0)*segment%grad\_gradient(j,2,k) + &
2462                    min(ry\_avg,0.0)*segment%grad\_gradient(j+1,2,k)) ) / &
2463                  (cff\_avg + rx\_avg)
2464 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2465 \textcolor{keywordflow}{         endif}
2466          \textcolor{keywordflow}{if} (segment%nudged\_grad) \textcolor{keywordflow}{then}
2467            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
2468              \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
2469              \textcolor{keywordflow}{if} (rx\_tang\_obl(i,j,k) <= 0.0) \textcolor{keywordflow}{then}
2470                tau = segment%Velocity\_nudging\_timescale\_in
2471              \textcolor{keywordflow}{else}
2472                tau = segment%Velocity\_nudging\_timescale\_out
2473 \textcolor{keywordflow}{             endif}
2474              gamma\_2 = dt / (tau + dt)
2475              segment%tangential\_grad(i,j,k) = (1.0 - gamma\_2) * segment%tangential\_grad(i,j,k) + &
2476                                  gamma\_2 * segment%nudged\_tangential\_grad(i,j,k)
2477 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2478 \textcolor{keywordflow}{         endif}
2479          \textcolor{keyword}{deallocate}(rx\_tang\_obl)
2480          \textcolor{keyword}{deallocate}(ry\_tang\_obl)
2481          \textcolor{keyword}{deallocate}(cff\_tangential)
2482 \textcolor{keywordflow}{       endif}
2483 \textcolor{keywordflow}{     endif}
2484 
2485      \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_w) \textcolor{keywordflow}{then}
2486        i=segment%HI%IsdB
2487        \textcolor{keywordflow}{if} (i>g%HI%IecB) cycle
2488        \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
2489          \textcolor{keywordflow}{if} (segment%radiation) \textcolor{keywordflow}{then}
2490            dhdt = (u\_old(i+1,j,k) - u\_new(i+1,j,k)) \textcolor{comment}{!old-new}
2491            dhdx = (u\_new(i+1,j,k) - u\_new(i+2,j,k)) \textcolor{comment}{!in new time forward sasha for I+1}
2492            rx\_new = 0.0
2493            \textcolor{keywordflow}{if} (dhdt*dhdx > 0.0) rx\_new = min( (dhdt/dhdx), rx\_max)
2494            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2495              rx\_avg = (1.0-gamma\_u)*segment%rx\_norm\_rad(i,j,k) + gamma\_u*rx\_new
2496            \textcolor{keywordflow}{else}
2497              rx\_avg = rx\_new
2498 \textcolor{keywordflow}{           endif}
2499            segment%rx\_norm\_rad(i,j,k) = rx\_avg
2500            \textcolor{comment}{! The new boundary value is interpolated between future interior}
2501            \textcolor{comment}{! value, u\_new(I+1) and past boundary value but with barotropic}
2502            \textcolor{comment}{! accelerations, u\_new(I).}
2503            segment%normal\_vel(i,j,k) = (u\_new(i,j,k) + rx\_avg*u\_new(i+1,j,k)) / (1.0+rx\_avg)
2504            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2505              \textcolor{comment}{! Copy restart fields into 3-d arrays. This is an inefficient and temporary issues}
2506              \textcolor{comment}{! implemented as a work-around to limitations in restart capability}
2507              obc%rx\_normal(i,j,k) = segment%rx\_norm\_rad(i,j,k)
2508 \textcolor{keywordflow}{           endif}
2509          \textcolor{keywordflow}{elseif} (segment%oblique) \textcolor{keywordflow}{then}
2510            dhdt = (u\_old(i+1,j,k) - u\_new(i+1,j,k)) \textcolor{comment}{!old-new}
2511            dhdx = (u\_new(i+1,j,k) - u\_new(i+2,j,k)) \textcolor{comment}{!in new time forward sasha for I+1}
2512            \textcolor{keywordflow}{if} (dhdt*(segment%grad\_normal(j,1,k) + segment%grad\_normal(j-1,1,k)) > 0.0) \textcolor{keywordflow}{then}
2513              dhdy = segment%grad\_normal(j-1,1,k)
2514            \textcolor{keywordflow}{elseif} (dhdt*(segment%grad\_normal(j,1,k) + segment%grad\_normal(j-1,1,k)) == 0.0) \textcolor{keywordflow}{then}
2515              dhdy = 0.0
2516            \textcolor{keywordflow}{else}
2517              dhdy = segment%grad\_normal(j,1,k)
2518 \textcolor{keywordflow}{           endif}
2519            \textcolor{keywordflow}{if} (dhdt*dhdx < 0.0) dhdt = 0.0
2520 
2521            cff\_new = max(dhdx*dhdx + dhdy*dhdy, eps)
2522            rx\_new = min(dhdt*dhdx, cff\_new*rx\_max)
2523            ry\_new = min(cff\_new,max(dhdt*dhdy,-cff\_new))
2524            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2525              rx\_avg = (1.0-gamma\_u)*segment%rx\_norm\_obl(i,j,k) + gamma\_u*rx\_new
2526              ry\_avg = (1.0-gamma\_u)*segment%ry\_norm\_obl(i,j,k) + gamma\_u*ry\_new
2527              cff\_avg = (1.0-gamma\_u)*segment%cff\_normal(i,j,k) + gamma\_u*cff\_new
2528            \textcolor{keywordflow}{else}
2529              rx\_avg = rx\_new
2530              ry\_avg = ry\_new
2531              cff\_avg = cff\_new
2532 \textcolor{keywordflow}{           endif}
2533            segment%rx\_norm\_obl(i,j,k) = rx\_avg
2534            segment%ry\_norm\_obl(i,j,k) = ry\_avg
2535            segment%cff\_normal(i,j,k) = cff\_avg
2536            segment%normal\_vel(i,j,k) = ((cff\_avg*u\_new(i,j,k) + rx\_avg*u\_new(i+1,j,k)) - &
2537                                         (max(ry\_avg,0.0)*segment%grad\_normal(j-1,2,k) + &
2538                                          min(ry\_avg,0.0)*segment%grad\_normal(j,2,k))) / &
2539                                        (cff\_avg + rx\_avg)
2540            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2541              \textcolor{comment}{! Copy restart fields into 3-d arrays. This is an inefficient and temporary issues}
2542              \textcolor{comment}{! implemented as a work-around to limitations in restart capability}
2543              obc%rx\_oblique(i,j,k) = segment%rx\_norm\_obl(i,j,k)
2544              obc%ry\_oblique(i,j,k) = segment%ry\_norm\_obl(i,j,k)
2545              obc%cff\_normal(i,j,k) = segment%cff\_normal(i,j,k)
2546 \textcolor{keywordflow}{           endif}
2547          \textcolor{keywordflow}{elseif} (segment%gradient) \textcolor{keywordflow}{then}
2548            segment%normal\_vel(i,j,k) = u\_new(i+1,j,k)
2549 \textcolor{keywordflow}{         endif}
2550          \textcolor{keywordflow}{if} ((segment%radiation .or. segment%oblique) .and. segment%nudged) \textcolor{keywordflow}{then}
2551            \textcolor{comment}{! dhdt gets set to 0. on inflow in oblique case}
2552            \textcolor{keywordflow}{if} (dhdt*dhdx <= 0.0) \textcolor{keywordflow}{then}
2553              tau = segment%Velocity\_nudging\_timescale\_in
2554            \textcolor{keywordflow}{else}
2555              tau = segment%Velocity\_nudging\_timescale\_out
2556 \textcolor{keywordflow}{           endif}
2557            gamma\_2 = dt / (tau + dt)
2558            segment%normal\_vel(i,j,k) = (1.0 - gamma\_2) * segment%normal\_vel(i,j,k) + &
2559                                  gamma\_2 * segment%nudged\_normal\_vel(i,j,k)
2560 \textcolor{keywordflow}{         endif}
2561 \textcolor{keywordflow}{       enddo} ;\textcolor{keywordflow}{ enddo}
2562        \textcolor{keywordflow}{if} (segment%radiation\_tan .or. segment%radiation\_grad) \textcolor{keywordflow}{then}
2563          i=segment%HI%IsdB
2564          \textcolor{keyword}{allocate}(rx\_tang\_rad(segment%HI%IsdB:segment%HI%IedB,segment%HI%JsdB:segment%HI%JedB,nz))
2565          \textcolor{keywordflow}{do} k=1,nz
2566            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2567              rx\_tang\_rad(i,segment%HI%JsdB,k) = segment%rx\_norm\_rad(i,segment%HI%jsd,k)
2568              rx\_tang\_rad(i,segment%HI%JedB,k) = segment%rx\_norm\_rad(i,segment%HI%jed,k)
2569              \textcolor{keywordflow}{do} j=segment%HI%JsdB+1,segment%HI%JedB-1
2570                rx\_tang\_rad(i,j,k) = 0.5*(segment%rx\_norm\_rad(i,j,k) + segment%rx\_norm\_rad(i,j+1,k))
2571 \textcolor{keywordflow}{             enddo}
2572            \textcolor{keywordflow}{else}
2573              \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
2574                dhdt = v\_old(i+1,j,k)-v\_new(i+1,j,k)   \textcolor{comment}{!old-new}
2575                dhdx = v\_new(i+1,j,k)-v\_new(i+2,j,k) \textcolor{comment}{!in new time backward sasha for I-1}
2576                rx\_tang\_rad(i,j,k) = 0.0
2577                \textcolor{keywordflow}{if} (dhdt*dhdx > 0.0) rx\_tang\_rad(i,j,k) = min( (dhdt/dhdx), rx\_max) \textcolor{comment}{! outward phase speed}
2578 \textcolor{keywordflow}{             enddo}
2579 \textcolor{keywordflow}{           endif}
2580 \textcolor{keywordflow}{         enddo}
2581          \textcolor{keywordflow}{if} (segment%radiation\_tan) \textcolor{keywordflow}{then}
2582            \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
2583              rx\_avg = rx\_tang\_rad(i,j,k)
2584              segment%tangential\_vel(i,j,k) = (v\_new(i+1,j,k) + rx\_avg*v\_new(i+2,j,k)) / (1.0+rx\_avg)
2585 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2586 \textcolor{keywordflow}{         endif}
2587          \textcolor{keywordflow}{if} (segment%nudged\_tan) \textcolor{keywordflow}{then}
2588            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
2589              \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
2590              \textcolor{keywordflow}{if} (rx\_tang\_rad(i,j,k) <= 0.0) \textcolor{keywordflow}{then}
2591                tau = segment%Velocity\_nudging\_timescale\_in
2592              \textcolor{keywordflow}{else}
2593                tau = segment%Velocity\_nudging\_timescale\_out
2594 \textcolor{keywordflow}{             endif}
2595              gamma\_2 = dt / (tau + dt)
2596              segment%tangential\_vel(i,j,k) = (1.0 - gamma\_2) * segment%tangential\_vel(i,j,k) + &
2597                                  gamma\_2 * segment%nudged\_tangential\_vel(i,j,k)
2598 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2599 \textcolor{keywordflow}{         endif}
2600          \textcolor{keywordflow}{if} (segment%radiation\_grad) \textcolor{keywordflow}{then}
2601            js\_obc = max(segment%HI%JsdB,g%jsd+1)
2602            je\_obc = min(segment%HI%JedB,g%jed-1)
2603            \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} j=js\_obc,je\_obc
2604              rx\_avg = rx\_tang\_rad(i,j,k)
2605 \textcolor{comment}{!            if (G%mask2dCu(I+1,j) > 0.0 .and. G%mask2dCu(I+1,j+1) > 0.0) then}
2606 \textcolor{comment}{!              rx\_avg = 0.5*(u\_new(I+1,j,k) + u\_new(I+1,j+1,k)) * dt * G%IdxBu(I+1,J)}
2607 \textcolor{comment}{!            elseif (G%mask2dCu(I+1,j) > 0.0) then}
2608 \textcolor{comment}{!              rx\_avg = u\_new(I+1,j,k) * dt * G%IdxBu(I+1,J)}
2609 \textcolor{comment}{!            elseif (G%mask2dCu(I+1,j+1) > 0.0) then}
2610 \textcolor{comment}{!              rx\_avg = u\_new(I+1,j+1,k) * dt * G%IdxBu(I+1,J)}
2611 \textcolor{comment}{!            else}
2612 \textcolor{comment}{!              rx\_avg = 0.0}
2613 \textcolor{comment}{!            endif}
2614              segment%tangential\_grad(i,j,k) = ((v\_new(i+2,j,k) - v\_new(i+1,j,k))*g%IdxBu(i+1,j) + &
2615                                rx\_avg*(v\_new(i+3,j,k) - v\_new(i+2,j,k))*g%IdxBu(i+2,j)) / (1.0+rx\_avg)
2616 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2617 \textcolor{keywordflow}{         endif}
2618          \textcolor{keywordflow}{if} (segment%nudged\_grad) \textcolor{keywordflow}{then}
2619            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
2620              \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
2621              \textcolor{keywordflow}{if} (rx\_tang\_rad(i,j,k) <= 0.0) \textcolor{keywordflow}{then}
2622                tau = segment%Velocity\_nudging\_timescale\_in
2623              \textcolor{keywordflow}{else}
2624                tau = segment%Velocity\_nudging\_timescale\_out
2625 \textcolor{keywordflow}{             endif}
2626              gamma\_2 = dt / (tau + dt)
2627              segment%tangential\_grad(i,j,k) = (1.0 - gamma\_2) * segment%tangential\_grad(i,j,k) + &
2628                                  gamma\_2 * segment%nudged\_tangential\_grad(i,j,k)
2629 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2630 \textcolor{keywordflow}{         endif}
2631          \textcolor{keyword}{deallocate}(rx\_tang\_rad)
2632 \textcolor{keywordflow}{       endif}
2633        \textcolor{keywordflow}{if} (segment%oblique\_tan .or. segment%oblique\_grad) \textcolor{keywordflow}{then}
2634          i=segment%HI%IsdB
2635          \textcolor{keyword}{allocate}(rx\_tang\_obl(segment%HI%IsdB:segment%HI%IedB,segment%HI%JsdB:segment%HI%JedB,nz))
2636          \textcolor{keyword}{allocate}(ry\_tang\_obl(segment%HI%IsdB:segment%HI%IedB,segment%HI%JsdB:segment%HI%JedB,nz))
2637          \textcolor{keyword}{allocate}(cff\_tangential(segment%HI%IsdB:segment%HI%IedB,segment%HI%JsdB:segment%HI%JedB,nz))
2638          \textcolor{keywordflow}{do} k=1,nz
2639            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2640              rx\_tang\_obl(i,segment%HI%JsdB,k) = segment%rx\_norm\_obl(i,segment%HI%jsd,k)
2641              rx\_tang\_obl(i,segment%HI%JedB,k) = segment%rx\_norm\_obl(i,segment%HI%jed,k)
2642              ry\_tang\_obl(i,segment%HI%JsdB,k) = segment%ry\_norm\_obl(i,segment%HI%jsd,k)
2643              ry\_tang\_obl(i,segment%HI%JedB,k) = segment%ry\_norm\_obl(i,segment%HI%jed,k)
2644              cff\_tangential(i,segment%HI%JsdB,k) = segment%cff\_normal(i,segment%HI%jsd,k)
2645              cff\_tangential(i,segment%HI%JedB,k) = segment%cff\_normal(i,segment%HI%jed,k)
2646              \textcolor{keywordflow}{do} j=segment%HI%JsdB+1,segment%HI%JedB-1
2647                rx\_tang\_obl(i,j,k) = 0.5*(segment%rx\_norm\_obl(i,j,k) + segment%rx\_norm\_obl(i,j+1,k))
2648                ry\_tang\_obl(i,j,k) = 0.5*(segment%ry\_norm\_obl(i,j,k) + segment%ry\_norm\_obl(i,j+1,k))
2649                cff\_tangential(i,j,k) = 0.5*(segment%cff\_normal(i,j,k) + segment%cff\_normal(i,j+1,k))
2650 \textcolor{keywordflow}{             enddo}
2651            \textcolor{keywordflow}{else}
2652              \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
2653                dhdt = v\_old(i+1,j,k)-v\_new(i+1,j,k)   \textcolor{comment}{!old-new}
2654                dhdx = v\_new(i+1,j,k)-v\_new(i+2,j,k) \textcolor{comment}{!in new time backward sasha for I-1}
2655                \textcolor{keywordflow}{if} (dhdt*(segment%grad\_tan(j,1,k) + segment%grad\_tan(j+1,1,k)) > 0.0) \textcolor{keywordflow}{then}
2656                  dhdy = segment%grad\_tan(j,1,k)
2657                \textcolor{keywordflow}{elseif} (dhdt*(segment%grad\_tan(j,1,k) + segment%grad\_tan(j+1,1,k)) == 0.0) \textcolor{keywordflow}{then}
2658                  dhdy = 0.0
2659                \textcolor{keywordflow}{else}
2660                  dhdy = segment%grad\_tan(j+1,1,k)
2661 \textcolor{keywordflow}{               endif}
2662                \textcolor{keywordflow}{if} (dhdt*dhdx < 0.0) dhdt = 0.0
2663                cff\_new = max(dhdx*dhdx + dhdy*dhdy, eps)
2664                rx\_new = min(dhdt*dhdx, cff\_new*rx\_max)
2665                ry\_new = min(cff\_new,max(dhdt*dhdy,-cff\_new))
2666                rx\_tang\_obl(i,j,k) = rx\_new
2667                ry\_tang\_obl(i,j,k) = ry\_new
2668                cff\_tangential(i,j,k) = cff\_new
2669 \textcolor{keywordflow}{             enddo}
2670 \textcolor{keywordflow}{           endif}
2671 \textcolor{keywordflow}{         enddo}
2672          \textcolor{keywordflow}{if} (segment%oblique\_tan) \textcolor{keywordflow}{then}
2673            \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
2674              rx\_avg = rx\_tang\_obl(i,j,k)
2675              ry\_avg = ry\_tang\_obl(i,j,k)
2676              cff\_avg = cff\_tangential(i,j,k)
2677              segment%tangential\_vel(i,j,k) = ((cff\_avg*v\_new(i+1,j,k) + rx\_avg*v\_new(i+2,j,k)) - &
2678                                               (max(ry\_avg,0.0)*segment%grad\_tan(j,2,k) + &
2679                                                min(ry\_avg,0.0)*segment%grad\_tan(j+1,2,k))) / &
2680                                              (cff\_avg + rx\_avg)
2681 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2682 \textcolor{keywordflow}{         endif}
2683          \textcolor{keywordflow}{if} (segment%nudged\_tan) \textcolor{keywordflow}{then}
2684            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
2685              \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
2686              \textcolor{keywordflow}{if} (rx\_tang\_obl(i,j,k) <= 0.0) \textcolor{keywordflow}{then}
2687                tau = segment%Velocity\_nudging\_timescale\_in
2688              \textcolor{keywordflow}{else}
2689                tau = segment%Velocity\_nudging\_timescale\_out
2690 \textcolor{keywordflow}{             endif}
2691              gamma\_2 = dt / (tau + dt)
2692              segment%tangential\_vel(i,j,k) = (1.0 - gamma\_2) * segment%tangential\_vel(i,j,k) + &
2693                                  gamma\_2 * segment%nudged\_tangential\_vel(i,j,k)
2694 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2695 \textcolor{keywordflow}{         endif}
2696          \textcolor{keywordflow}{if} (segment%oblique\_grad) \textcolor{keywordflow}{then}
2697            js\_obc = max(segment%HI%JsdB,g%jsd+1)
2698            je\_obc = min(segment%HI%JedB,g%jed-1)
2699            \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} j=segment%HI%JsdB+1,segment%HI%JedB-1
2700              rx\_avg = rx\_tang\_obl(i,j,k)
2701              ry\_avg = ry\_tang\_obl(i,j,k)
2702              cff\_avg = cff\_tangential(i,j,k)
2703              segment%tangential\_grad(i,j,k) = &
2704                  ((cff\_avg*(v\_new(i+2,j,k) - v\_new(i+1,j,k))*g%IdxBu(i+1,j) + &
2705                     rx\_avg*(v\_new(i+3,j,k) - v\_new(i+2,j,k))*g%IdxBu(i+2,j)) - &
2706                   (max(ry\_avg,0.0)*segment%grad\_gradient(j,2,k) + &
2707                    min(ry\_avg,0.0)*segment%grad\_gradient(j+1,2,k))) / &
2708                  (cff\_avg + rx\_avg)
2709 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2710 \textcolor{keywordflow}{         endif}
2711          \textcolor{keywordflow}{if} (segment%nudged\_grad) \textcolor{keywordflow}{then}
2712            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
2713              \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
2714              \textcolor{keywordflow}{if} (rx\_tang\_obl(i,j,k) <= 0.0) \textcolor{keywordflow}{then}
2715                tau = segment%Velocity\_nudging\_timescale\_in
2716              \textcolor{keywordflow}{else}
2717                tau = segment%Velocity\_nudging\_timescale\_out
2718 \textcolor{keywordflow}{             endif}
2719              gamma\_2 = dt / (tau + dt)
2720              segment%tangential\_grad(i,j,k) = (1.0 - gamma\_2) * segment%tangential\_grad(i,j,k) + &
2721                                  gamma\_2 * segment%nudged\_tangential\_grad(i,j,k)
2722 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2723 \textcolor{keywordflow}{         endif}
2724          \textcolor{keyword}{deallocate}(rx\_tang\_obl)
2725          \textcolor{keyword}{deallocate}(ry\_tang\_obl)
2726          \textcolor{keyword}{deallocate}(cff\_tangential)
2727 \textcolor{keywordflow}{       endif}
2728 \textcolor{keywordflow}{     endif}
2729 
2730      \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_n) \textcolor{keywordflow}{then}
2731        j=segment%HI%JsdB
2732        \textcolor{keywordflow}{if} (j<g%HI%JscB) cycle
2733        \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
2734          \textcolor{keywordflow}{if} (segment%radiation) \textcolor{keywordflow}{then}
2735            dhdt = (v\_old(i,j-1,k) - v\_new(i,j-1,k)) \textcolor{comment}{!old-new}
2736            dhdy = (v\_new(i,j-1,k) - v\_new(i,j-2,k)) \textcolor{comment}{!in new time backward sasha for J-1}
2737            ry\_new = 0.0
2738            \textcolor{keywordflow}{if} (dhdt*dhdy > 0.0) ry\_new = min( (dhdt/dhdy), ry\_max)
2739            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2740              ry\_avg = (1.0-gamma\_u)*segment%ry\_norm\_rad(i,j,k) + gamma\_u*ry\_new
2741            \textcolor{keywordflow}{else}
2742              ry\_avg = ry\_new
2743 \textcolor{keywordflow}{           endif}
2744            segment%ry\_norm\_rad(i,j,k) = ry\_avg
2745            \textcolor{comment}{! The new boundary value is interpolated between future interior}
2746            \textcolor{comment}{! value, v\_new(J-1) and past boundary value but with barotropic}
2747            \textcolor{comment}{! accelerations, v\_new(J).}
2748            segment%normal\_vel(i,j,k) = (v\_new(i,j,k) + ry\_avg*v\_new(i,j-1,k)) / (1.0+ry\_avg)
2749            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2750              \textcolor{comment}{! Copy restart fields into 3-d arrays. This is an inefficient and temporary issues}
2751              \textcolor{comment}{! implemented as a work-around to limitations in restart capability}
2752              obc%ry\_normal(i,j,k) = segment%ry\_norm\_rad(i,j,k)
2753 \textcolor{keywordflow}{           endif}
2754          \textcolor{keywordflow}{elseif} (segment%oblique) \textcolor{keywordflow}{then}
2755            dhdt = (v\_old(i,j-1,k) - v\_new(i,j-1,k)) \textcolor{comment}{!old-new}
2756            dhdy = (v\_new(i,j-1,k) - v\_new(i,j-2,k)) \textcolor{comment}{!in new time backward sasha for J-1}
2757            \textcolor{keywordflow}{if} (dhdt*(segment%grad\_normal(i,1,k) + segment%grad\_normal(i-1,1,k)) > 0.0) \textcolor{keywordflow}{then}
2758              dhdx = segment%grad\_normal(i-1,1,k)
2759            \textcolor{keywordflow}{elseif} (dhdt*(segment%grad\_normal(i,1,k) + segment%grad\_normal(i-1,1,k)) == 0.0) \textcolor{keywordflow}{then}
2760              dhdx = 0.0
2761            \textcolor{keywordflow}{else}
2762              dhdx = segment%grad\_normal(i,1,k)
2763 \textcolor{keywordflow}{           endif}
2764            \textcolor{keywordflow}{if} (dhdt*dhdy < 0.0) dhdt = 0.0
2765            cff\_new = max(dhdx*dhdx + dhdy*dhdy, eps)
2766            ry\_new = min(dhdt*dhdy, cff\_new*ry\_max)
2767            rx\_new = min(cff\_new,max(dhdt*dhdx,-cff\_new))
2768            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2769              rx\_avg = (1.0-gamma\_u)*segment%rx\_norm\_obl(i,j,k) + gamma\_u*rx\_new
2770              ry\_avg = (1.0-gamma\_u)*segment%ry\_norm\_obl(i,j,k) + gamma\_u*ry\_new
2771              cff\_avg = (1.0-gamma\_u)*segment%cff\_normal(i,j,k) + gamma\_u*cff\_new
2772            \textcolor{keywordflow}{else}
2773              rx\_avg = rx\_new
2774              ry\_avg = ry\_new
2775              cff\_avg = cff\_new
2776 \textcolor{keywordflow}{           endif}
2777            segment%rx\_norm\_obl(i,j,k) = rx\_avg
2778            segment%ry\_norm\_obl(i,j,k) = ry\_avg
2779            segment%cff\_normal(i,j,k) = cff\_avg
2780            segment%normal\_vel(i,j,k) = ((cff\_avg*v\_new(i,j,k) + ry\_avg*v\_new(i,j-1,k)) - &
2781                                         (max(rx\_avg,0.0)*segment%grad\_normal(i-1,2,k) +&
2782                                          min(rx\_avg,0.0)*segment%grad\_normal(i,2,k))) / &
2783                                        (cff\_avg + ry\_avg)
2784            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2785              \textcolor{comment}{! Copy restart fields into 3-d arrays. This is an inefficient and temporary issues}
2786              \textcolor{comment}{! implemented as a work-around to limitations in restart capability}
2787              obc%rx\_oblique(i,j,k) = segment%rx\_norm\_obl(i,j,k)
2788              obc%ry\_oblique(i,j,k) = segment%ry\_norm\_obl(i,j,k)
2789              obc%cff\_normal(i,j,k) = segment%cff\_normal(i,j,k)
2790 \textcolor{keywordflow}{           endif}
2791          \textcolor{keywordflow}{elseif} (segment%gradient) \textcolor{keywordflow}{then}
2792            segment%normal\_vel(i,j,k) = v\_new(i,j-1,k)
2793 \textcolor{keywordflow}{         endif}
2794          \textcolor{keywordflow}{if} ((segment%radiation .or. segment%oblique) .and. segment%nudged) \textcolor{keywordflow}{then}
2795            \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
2796            \textcolor{keywordflow}{if} (dhdt*dhdy <= 0.0) \textcolor{keywordflow}{then}
2797              tau = segment%Velocity\_nudging\_timescale\_in
2798            \textcolor{keywordflow}{else}
2799              tau = segment%Velocity\_nudging\_timescale\_out
2800 \textcolor{keywordflow}{           endif}
2801            gamma\_2 = dt / (tau + dt)
2802            segment%normal\_vel(i,j,k) = (1.0 - gamma\_2) * segment%normal\_vel(i,j,k) + &
2803                                  gamma\_2 * segment%nudged\_normal\_vel(i,j,k)
2804 \textcolor{keywordflow}{         endif}
2805 \textcolor{keywordflow}{       enddo} ;\textcolor{keywordflow}{ enddo}
2806        \textcolor{keywordflow}{if} (segment%radiation\_tan .or. segment%radiation\_grad) \textcolor{keywordflow}{then}
2807          j=segment%HI%JsdB
2808          \textcolor{keyword}{allocate}(ry\_tang\_rad(segment%HI%IsdB:segment%HI%IedB,segment%HI%JsdB:segment%HI%JedB,nz))
2809          \textcolor{keywordflow}{do} k=1,nz
2810            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2811              ry\_tang\_rad(segment%HI%IsdB,j,k) = segment%ry\_norm\_rad(segment%HI%isd,j,k)
2812              ry\_tang\_rad(segment%HI%IedB,j,k) = segment%ry\_norm\_rad(segment%HI%ied,j,k)
2813              \textcolor{keywordflow}{do} i=segment%HI%IsdB+1,segment%HI%IedB-1
2814                ry\_tang\_rad(i,j,k) = 0.5*(segment%ry\_norm\_rad(i,j,k) + segment%ry\_norm\_rad(i+1,j,k))
2815 \textcolor{keywordflow}{             enddo}
2816            \textcolor{keywordflow}{else}
2817              \textcolor{keywordflow}{do} i=segment%HI%IsdB,segment%HI%IedB
2818                dhdt = u\_old(i,j-1,k)-u\_new(i,j-1,k)   \textcolor{comment}{!old-new}
2819                dhdy = u\_new(i,j-1,k)-u\_new(i,j-2,k) \textcolor{comment}{!in new time backward sasha for I-1}
2820                ry\_tang\_rad(i,j,k) = 0.0
2821                \textcolor{keywordflow}{if} (dhdt*dhdy > 0.0) ry\_tang\_rad(i,j,k) = min( (dhdt/dhdy), rx\_max) \textcolor{comment}{! outward phase speed}
2822 \textcolor{keywordflow}{             enddo}
2823 \textcolor{keywordflow}{           endif}
2824 \textcolor{keywordflow}{         enddo}
2825          \textcolor{keywordflow}{if} (segment%radiation\_tan) \textcolor{keywordflow}{then}
2826            \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} i=segment%HI%IsdB,segment%HI%IedB
2827              ry\_avg = ry\_tang\_rad(i,j,k)
2828              segment%tangential\_vel(i,j,k) = (u\_new(i,j,k) + ry\_avg*u\_new(i,j-1,k)) / (1.0+ry\_avg)
2829 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2830 \textcolor{keywordflow}{         endif}
2831          \textcolor{keywordflow}{if} (segment%nudged\_tan) \textcolor{keywordflow}{then}
2832            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=segment%HI%IsdB,segment%HI%IedB
2833              \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
2834              \textcolor{keywordflow}{if} (ry\_tang\_rad(i,j,k) <= 0.0) \textcolor{keywordflow}{then}
2835                tau = segment%Velocity\_nudging\_timescale\_in
2836              \textcolor{keywordflow}{else}
2837                tau = segment%Velocity\_nudging\_timescale\_out
2838 \textcolor{keywordflow}{             endif}
2839              gamma\_2 = dt / (tau + dt)
2840              segment%tangential\_vel(i,j,k) = (1.0 - gamma\_2) * segment%tangential\_vel(i,j,k) + &
2841                                  gamma\_2 * segment%nudged\_tangential\_vel(i,j,k)
2842 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2843 \textcolor{keywordflow}{         endif}
2844          \textcolor{keywordflow}{if} (segment%radiation\_grad) \textcolor{keywordflow}{then}
2845            is\_obc = max(segment%HI%IsdB,g%isd+1)
2846            ie\_obc = min(segment%HI%IedB,g%ied-1)
2847            \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} i=is\_obc,ie\_obc
2848              ry\_avg = ry\_tang\_rad(i,j,k)
2849 \textcolor{comment}{!            if (G%mask2dCv(i,J-1) > 0.0 .and. G%mask2dCv(i+1,J-1) > 0.0) then}
2850 \textcolor{comment}{!              ry\_avg = 0.5*(v\_new(i,J-1,k) + v\_new(i+1,J-1,k) * dt * G%IdyBu(I,J-1))}
2851 \textcolor{comment}{!            elseif (G%mask2dCv(i,J-1) > 0.0) then}
2852 \textcolor{comment}{!              ry\_avg = v\_new(i,J-1,k) * dt *G%IdyBu(I,J-1)}
2853 \textcolor{comment}{!            elseif (G%mask2dCv(i+1,J-1) > 0.0) then}
2854 \textcolor{comment}{!              ry\_avg = v\_new(i+1,J-1,k) * dt *G%IdyBu(I,J-1)}
2855 \textcolor{comment}{!            else}
2856 \textcolor{comment}{!              ry\_avg = 0.0}
2857 \textcolor{comment}{!            endif}
2858              segment%tangential\_grad(i,j,k) = ((u\_new(i,j,k) - u\_new(i,j-1,k))*g%IdyBu(i,j-1) + &
2859                                ry\_avg*(u\_new(i,j-1,k) - u\_new(i,j-2,k))*g%IdyBu(i,j-2)) / (1.0+ry\_avg)
2860 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2861 \textcolor{keywordflow}{         endif}
2862          \textcolor{keywordflow}{if} (segment%nudged\_grad) \textcolor{keywordflow}{then}
2863            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=segment%HI%IsdB,segment%HI%IedB
2864              \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
2865              \textcolor{keywordflow}{if} (ry\_tang\_rad(i,j,k) <= 0.0) \textcolor{keywordflow}{then}
2866                tau = segment%Velocity\_nudging\_timescale\_in
2867              \textcolor{keywordflow}{else}
2868                tau = segment%Velocity\_nudging\_timescale\_out
2869 \textcolor{keywordflow}{             endif}
2870              gamma\_2 = dt / (tau + dt)
2871              segment%tangential\_grad(i,j,k) = (1.0 - gamma\_2) * segment%tangential\_grad(i,j,k) + &
2872                                  gamma\_2 * segment%nudged\_tangential\_grad(i,j,k)
2873 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2874 \textcolor{keywordflow}{         endif}
2875          \textcolor{keyword}{deallocate}(ry\_tang\_rad)
2876 \textcolor{keywordflow}{       endif}
2877        \textcolor{keywordflow}{if} (segment%oblique\_tan .or. segment%oblique\_grad) \textcolor{keywordflow}{then}
2878          j=segment%HI%JsdB
2879          \textcolor{keyword}{allocate}(rx\_tang\_obl(segment%HI%IsdB:segment%HI%IedB,segment%HI%JsdB:segment%HI%JedB,nz))
2880          \textcolor{keyword}{allocate}(ry\_tang\_obl(segment%HI%IsdB:segment%HI%IedB,segment%HI%JsdB:segment%HI%JedB,nz))
2881          \textcolor{keyword}{allocate}(cff\_tangential(segment%HI%IsdB:segment%HI%IedB,segment%HI%JsdB:segment%HI%JedB,nz))
2882          \textcolor{keywordflow}{do} k=1,nz
2883            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2884              rx\_tang\_obl(segment%HI%IsdB,j,k) = segment%rx\_norm\_obl(segment%HI%isd,j,k)
2885              rx\_tang\_obl(segment%HI%IedB,j,k) = segment%rx\_norm\_obl(segment%HI%ied,j,k)
2886              ry\_tang\_obl(segment%HI%IsdB,j,k) = segment%ry\_norm\_obl(segment%HI%isd,j,k)
2887              ry\_tang\_obl(segment%HI%IedB,j,k) = segment%ry\_norm\_obl(segment%HI%ied,j,k)
2888              cff\_tangential(segment%HI%IsdB,j,k) = segment%cff\_normal(segment%HI%isd,j,k)
2889              cff\_tangential(segment%HI%IedB,j,k) = segment%cff\_normal(segment%HI%ied,j,k)
2890              \textcolor{keywordflow}{do} i=segment%HI%IsdB+1,segment%HI%IedB-1
2891                rx\_tang\_obl(i,j,k) = 0.5*(segment%rx\_norm\_obl(i,j,k) + segment%rx\_norm\_obl(i+1,j,k))
2892                ry\_tang\_obl(i,j,k) = 0.5*(segment%ry\_norm\_obl(i,j,k) + segment%ry\_norm\_obl(i+1,j,k))
2893                cff\_tangential(i,j,k) = 0.5*(segment%cff\_normal(i,j,k) + segment%cff\_normal(i+1,j,k))
2894 \textcolor{keywordflow}{             enddo}
2895            \textcolor{keywordflow}{else}
2896              \textcolor{keywordflow}{do} i=segment%HI%IsdB,segment%HI%IedB
2897                dhdt = u\_old(i,j,k)-u\_new(i,j,k)   \textcolor{comment}{!old-new}
2898                dhdy = u\_new(i,j,k)-u\_new(i,j-1,k) \textcolor{comment}{!in new time backward sasha for I-1}
2899                \textcolor{keywordflow}{if} (dhdt*(segment%grad\_tan(i,1,k) + segment%grad\_tan(i+1,1,k)) > 0.0) \textcolor{keywordflow}{then}
2900                  dhdx = segment%grad\_tan(i,1,k)
2901                \textcolor{keywordflow}{elseif} (dhdt*(segment%grad\_tan(i,1,k) + segment%grad\_tan(i+1,1,k)) == 0.0) \textcolor{keywordflow}{then}
2902                  dhdx = 0.0
2903                \textcolor{keywordflow}{else}
2904                  dhdx = segment%grad\_tan(i+1,1,k)
2905 \textcolor{keywordflow}{               endif}
2906                \textcolor{keywordflow}{if} (dhdt*dhdy < 0.0) dhdt = 0.0
2907                cff\_new = max(dhdx*dhdx + dhdy*dhdy, eps)
2908                ry\_new = min(dhdt*dhdy, cff\_new*ry\_max)
2909                rx\_new = min(cff\_new,max(dhdt*dhdx,-cff\_new))
2910                rx\_tang\_obl(i,j,k) = rx\_new
2911                ry\_tang\_obl(i,j,k) = ry\_new
2912                cff\_tangential(i,j,k) = cff\_new
2913 \textcolor{keywordflow}{             enddo}
2914 \textcolor{keywordflow}{           endif}
2915 \textcolor{keywordflow}{         enddo}
2916          \textcolor{keywordflow}{if} (segment%oblique\_tan) \textcolor{keywordflow}{then}
2917            \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} i=segment%HI%IsdB,segment%HI%IedB
2918              rx\_avg = rx\_tang\_obl(i,j,k)
2919              ry\_avg = ry\_tang\_obl(i,j,k)
2920              cff\_avg = cff\_tangential(i,j,k)
2921              segment%tangential\_vel(i,j,k) = ((cff\_avg*u\_new(i,j,k) + ry\_avg*u\_new(i,j-1,k)) - &
2922                                               (max(rx\_avg,0.0)*segment%grad\_tan(i,2,k) + &
2923                                                min(rx\_avg,0.0)*segment%grad\_tan(i+1,2,k))) / &
2924                                              (cff\_avg + ry\_avg)
2925 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2926 \textcolor{keywordflow}{         endif}
2927          \textcolor{keywordflow}{if} (segment%nudged\_tan) \textcolor{keywordflow}{then}
2928            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=segment%HI%IsdB,segment%HI%IedB
2929              \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
2930              \textcolor{keywordflow}{if} (ry\_tang\_obl(i,j,k) <= 0.0) \textcolor{keywordflow}{then}
2931                tau = segment%Velocity\_nudging\_timescale\_in
2932              \textcolor{keywordflow}{else}
2933                tau = segment%Velocity\_nudging\_timescale\_out
2934 \textcolor{keywordflow}{             endif}
2935              gamma\_2 = dt / (tau + dt)
2936              segment%tangential\_vel(i,j,k) = (1.0 - gamma\_2) * segment%tangential\_vel(i,j,k) + &
2937                                  gamma\_2 * segment%nudged\_tangential\_vel(i,j,k)
2938 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2939 \textcolor{keywordflow}{         endif}
2940          \textcolor{keywordflow}{if} (segment%oblique\_grad) \textcolor{keywordflow}{then}
2941            is\_obc = max(segment%HI%IsdB,g%isd+1)
2942            ie\_obc = min(segment%HI%IedB,g%ied-1)
2943            \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} i=segment%HI%IsdB+1,segment%HI%IedB-1
2944              rx\_avg = rx\_tang\_obl(i,j,k)
2945              ry\_avg = ry\_tang\_obl(i,j,k)
2946              cff\_avg = cff\_tangential(i,j,k)
2947              segment%tangential\_grad(i,j,k) =  &
2948                  ((cff\_avg*(u\_new(i,j,k)   - u\_new(i,j-1,k))*g%IdyBu(i,j-1) + &
2949                     ry\_avg*(u\_new(i,j-1,k) - u\_new(i,j-2,k))*g%IdyBu(i,j-2)) - &
2950                                   (max(rx\_avg,0.0)*segment%grad\_gradient(i,2,k) + &
2951                                    min(rx\_avg,0.0)*segment%grad\_gradient(i+1,2,k))) / &
2952                                  (cff\_avg + ry\_avg)
2953 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2954 \textcolor{keywordflow}{         endif}
2955          \textcolor{keywordflow}{if} (segment%nudged\_grad) \textcolor{keywordflow}{then}
2956            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=segment%HI%IsdB,segment%HI%IedB
2957              \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
2958              \textcolor{keywordflow}{if} (ry\_tang\_obl(i,j,k) <= 0.0) \textcolor{keywordflow}{then}
2959                tau = segment%Velocity\_nudging\_timescale\_in
2960              \textcolor{keywordflow}{else}
2961                tau = segment%Velocity\_nudging\_timescale\_out
2962 \textcolor{keywordflow}{             endif}
2963              gamma\_2 = dt / (tau + dt)
2964              segment%tangential\_grad(i,j,k) = (1.0 - gamma\_2) * segment%tangential\_grad(i,j,k) + &
2965                                  gamma\_2 * segment%nudged\_tangential\_grad(i,j,k)
2966 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
2967 \textcolor{keywordflow}{         endif}
2968          \textcolor{keyword}{deallocate}(rx\_tang\_obl)
2969          \textcolor{keyword}{deallocate}(ry\_tang\_obl)
2970          \textcolor{keyword}{deallocate}(cff\_tangential)
2971 \textcolor{keywordflow}{       endif}
2972 \textcolor{keywordflow}{     endif}
2973 
2974      \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_s) \textcolor{keywordflow}{then}
2975        j=segment%HI%JsdB
2976        \textcolor{keywordflow}{if} (j>g%HI%JecB) cycle
2977        \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
2978          \textcolor{keywordflow}{if} (segment%radiation) \textcolor{keywordflow}{then}
2979            dhdt = (v\_old(i,j+1,k) - v\_new(i,j+1,k)) \textcolor{comment}{!old-new}
2980            dhdy = (v\_new(i,j+1,k) - v\_new(i,j+2,k)) \textcolor{comment}{!in new time backward sasha for J-1}
2981            ry\_new = 0.0
2982            \textcolor{keywordflow}{if} (dhdt*dhdy > 0.0) ry\_new = min( (dhdt/dhdy), ry\_max)
2983            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2984              ry\_avg = (1.0-gamma\_u)*segment%ry\_norm\_rad(i,j,k) + gamma\_u*ry\_new
2985            \textcolor{keywordflow}{else}
2986              ry\_avg = ry\_new
2987 \textcolor{keywordflow}{           endif}
2988            segment%ry\_norm\_rad(i,j,k) = ry\_avg
2989            \textcolor{comment}{! The new boundary value is interpolated between future interior}
2990            \textcolor{comment}{! value, v\_new(J+1) and past boundary value but with barotropic}
2991            \textcolor{comment}{! accelerations, v\_new(J).}
2992            segment%normal\_vel(i,j,k) = (v\_new(i,j,k) + ry\_avg*v\_new(i,j+1,k)) / (1.0+ry\_avg)
2993            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
2994              \textcolor{comment}{! Copy restart fields into 3-d arrays. This is an inefficient and temporary issues}
2995              \textcolor{comment}{! implemented as a work-around to limitations in restart capability}
2996              obc%ry\_normal(i,j,k) = segment%ry\_norm\_rad(i,j,k)
2997 \textcolor{keywordflow}{           endif}
2998          \textcolor{keywordflow}{elseif} (segment%oblique) \textcolor{keywordflow}{then}
2999            dhdt = (v\_old(i,j+1,k) - v\_new(i,j+1,k)) \textcolor{comment}{!old-new}
3000            dhdy = (v\_new(i,j+1,k) - v\_new(i,j+2,k)) \textcolor{comment}{!in new time backward sasha for J-1}
3001            \textcolor{keywordflow}{if} (dhdt*(segment%grad\_normal(i,1,k) + segment%grad\_normal(i-1,1,k)) > 0.0) \textcolor{keywordflow}{then}
3002              dhdx = segment%grad\_normal(i-1,1,k)
3003            \textcolor{keywordflow}{elseif} (dhdt*(segment%grad\_normal(i,1,k) + segment%grad\_normal(i-1,1,k)) == 0.0) \textcolor{keywordflow}{then}
3004              dhdx = 0.0
3005            \textcolor{keywordflow}{else}
3006              dhdx = segment%grad\_normal(i,1,k)
3007 \textcolor{keywordflow}{           endif}
3008            \textcolor{keywordflow}{if} (dhdt*dhdy < 0.0) dhdt = 0.0
3009 
3010            cff\_new = max(dhdx*dhdx + dhdy*dhdy, eps)
3011            ry\_new = min(dhdt*dhdy, cff\_new*ry\_max)
3012            rx\_new = min(cff\_new,max(dhdt*dhdx,-cff\_new))
3013            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
3014              rx\_avg = (1.0-gamma\_u)*segment%rx\_norm\_obl(i,j,k) + gamma\_u*rx\_new
3015              ry\_avg = (1.0-gamma\_u)*segment%ry\_norm\_obl(i,j,k) + gamma\_u*ry\_new
3016              cff\_avg = (1.0-gamma\_u)*segment%cff\_normal(i,j,k) + gamma\_u*cff\_new
3017            \textcolor{keywordflow}{else}
3018              rx\_avg = rx\_new
3019              ry\_avg = ry\_new
3020              cff\_avg = cff\_new
3021 \textcolor{keywordflow}{           endif}
3022            segment%rx\_norm\_obl(i,j,k) = rx\_avg
3023            segment%ry\_norm\_obl(i,j,k) = ry\_avg
3024            segment%cff\_normal(i,j,k) = cff\_avg
3025            segment%normal\_vel(i,j,k) = ((cff\_avg*v\_new(i,j,k) + ry\_avg*v\_new(i,j+1,k)) - &
3026                                         (max(rx\_avg,0.0)*segment%grad\_normal(i-1,2,k) + &
3027                                          min(rx\_avg,0.0)*segment%grad\_normal(i,2,k))) / &
3028                                        (cff\_avg + ry\_avg)
3029            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
3030              \textcolor{comment}{! Copy restart fields into 3-d arrays. This is an inefficient and temporary issues}
3031              \textcolor{comment}{! implemented as a work-around to limitations in restart capability}
3032              obc%rx\_oblique(i,j,k) = segment%rx\_norm\_obl(i,j,k)
3033              obc%ry\_oblique(i,j,k) = segment%ry\_norm\_obl(i,j,k)
3034              obc%cff\_normal(i,j,k) = segment%cff\_normal(i,j,k)
3035 \textcolor{keywordflow}{           endif}
3036          \textcolor{keywordflow}{elseif} (segment%gradient) \textcolor{keywordflow}{then}
3037            segment%normal\_vel(i,j,k) = v\_new(i,j+1,k)
3038 \textcolor{keywordflow}{         endif}
3039          \textcolor{keywordflow}{if} ((segment%radiation .or. segment%oblique) .and. segment%nudged) \textcolor{keywordflow}{then}
3040            \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
3041            \textcolor{keywordflow}{if} (dhdt*dhdy <= 0.0) \textcolor{keywordflow}{then}
3042              tau = segment%Velocity\_nudging\_timescale\_in
3043            \textcolor{keywordflow}{else}
3044              tau = segment%Velocity\_nudging\_timescale\_out
3045 \textcolor{keywordflow}{           endif}
3046            gamma\_2 = dt / (tau + dt)
3047            segment%normal\_vel(i,j,k) = (1.0 - gamma\_2) * segment%normal\_vel(i,j,k) + &
3048                                  gamma\_2 * segment%nudged\_normal\_vel(i,j,k)
3049 \textcolor{keywordflow}{         endif}
3050 \textcolor{keywordflow}{       enddo} ;\textcolor{keywordflow}{ enddo}
3051        \textcolor{keywordflow}{if} (segment%radiation\_tan .or. segment%radiation\_grad) \textcolor{keywordflow}{then}
3052          j=segment%HI%JsdB
3053          \textcolor{keyword}{allocate}(ry\_tang\_rad(segment%HI%IsdB:segment%HI%IedB,segment%HI%JsdB:segment%HI%JedB,nz))
3054          \textcolor{keywordflow}{do} k=1,nz
3055            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
3056              ry\_tang\_rad(segment%HI%IsdB,j,k) = segment%ry\_norm\_rad(segment%HI%isd,j,k)
3057              ry\_tang\_rad(segment%HI%IedB,j,k) = segment%ry\_norm\_rad(segment%HI%ied,j,k)
3058              \textcolor{keywordflow}{do} i=segment%HI%IsdB+1,segment%HI%IedB-1
3059                ry\_tang\_rad(i,j,k) = 0.5*(segment%ry\_norm\_rad(i,j,k) + segment%ry\_norm\_rad(i+1,j,k))
3060 \textcolor{keywordflow}{             enddo}
3061            \textcolor{keywordflow}{else}
3062              \textcolor{keywordflow}{do} i=segment%HI%IsdB,segment%HI%IedB
3063                dhdt = u\_old(i,j+1,k)-u\_new(i,j+1,k)   \textcolor{comment}{!old-new}
3064                dhdy = u\_new(i,j+1,k)-u\_new(i,j+2,k) \textcolor{comment}{!in new time backward sasha for I-1}
3065                ry\_tang\_rad(i,j,k) = 0.0
3066                \textcolor{keywordflow}{if} (dhdt*dhdy > 0.0) ry\_tang\_rad(i,j,k) = min( (dhdt/dhdy), rx\_max) \textcolor{comment}{! outward phase speed}
3067 \textcolor{keywordflow}{             enddo}
3068 \textcolor{keywordflow}{           endif}
3069 \textcolor{keywordflow}{         enddo}
3070          \textcolor{keywordflow}{if} (segment%radiation\_tan) \textcolor{keywordflow}{then}
3071            \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} i=segment%HI%IsdB,segment%HI%IedB
3072              ry\_avg = ry\_tang\_rad(i,j,k)
3073              segment%tangential\_vel(i,j,k) = (u\_new(i,j+1,k) + ry\_avg*u\_new(i,j+2,k)) / (1.0+ry\_avg)
3074 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
3075 \textcolor{keywordflow}{         endif}
3076          \textcolor{keywordflow}{if} (segment%nudged\_tan) \textcolor{keywordflow}{then}
3077            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=segment%HI%IsdB,segment%HI%IedB
3078              \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
3079              \textcolor{keywordflow}{if} (ry\_tang\_rad(i,j,k) <= 0.0) \textcolor{keywordflow}{then}
3080                tau = segment%Velocity\_nudging\_timescale\_in
3081              \textcolor{keywordflow}{else}
3082                tau = segment%Velocity\_nudging\_timescale\_out
3083 \textcolor{keywordflow}{             endif}
3084              gamma\_2 = dt / (tau + dt)
3085              segment%tangential\_vel(i,j,k) = (1.0 - gamma\_2) * segment%tangential\_vel(i,j,k) + &
3086                                  gamma\_2 * segment%nudged\_tangential\_vel(i,j,k)
3087 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
3088 \textcolor{keywordflow}{         endif}
3089          \textcolor{keywordflow}{if} (segment%radiation\_grad) \textcolor{keywordflow}{then}
3090            is\_obc = max(segment%HI%IsdB,g%isd+1)
3091            ie\_obc = min(segment%HI%IedB,g%ied-1)
3092            \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} i=is\_obc,ie\_obc
3093              ry\_avg = ry\_tang\_rad(i,j,k)
3094 \textcolor{comment}{!            if (G%mask2dCv(i,J+1) > 0.0 .and. G%mask2dCv(i+1,J+1) > 0.0) then}
3095 \textcolor{comment}{!              ry\_avg = 0.5*(v\_new(i,J+1,k) + v\_new(i+1,J+1,k)) * dt * G%IdyBu(I,J+1)}
3096 \textcolor{comment}{!            elseif (G%mask2dCv(i,J+1) > 0.0) then}
3097 \textcolor{comment}{!              ry\_avg = v\_new(i,J+1,k) * dt * G%IdyBu(I,J+1)}
3098 \textcolor{comment}{!            elseif (G%mask2dCv(i+1,J+1) > 0.0) then}
3099 \textcolor{comment}{!              ry\_avg = v\_new(i+1,J+1,k) * dt * G%IdyBu(I,J+1)}
3100 \textcolor{comment}{!            else}
3101 \textcolor{comment}{!              ry\_avg = 0.0}
3102 \textcolor{comment}{!            endif}
3103              segment%tangential\_grad(i,j,k) = ((u\_new(i,j+2,k) - u\_new(i,j+1,k))*g%IdyBu(i,j+1) + &
3104                                ry\_avg*(u\_new(i,j+3,k) - u\_new(i,j+2,k))*g%IdyBu(i,j+2)) / (1.0+ry\_avg)
3105 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
3106 \textcolor{keywordflow}{         endif}
3107          \textcolor{keywordflow}{if} (segment%nudged\_grad) \textcolor{keywordflow}{then}
3108            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=segment%HI%IsdB,segment%HI%IedB
3109              \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
3110              \textcolor{keywordflow}{if} (ry\_tang\_rad(i,j,k) <= 0.0) \textcolor{keywordflow}{then}
3111                tau = segment%Velocity\_nudging\_timescale\_in
3112              \textcolor{keywordflow}{else}
3113                tau = segment%Velocity\_nudging\_timescale\_out
3114 \textcolor{keywordflow}{             endif}
3115              gamma\_2 = dt / (tau + dt)
3116              segment%tangential\_grad(i,j,k) = (1.0 - gamma\_2) * segment%tangential\_grad(i,j,k) + &
3117                                  gamma\_2 * segment%nudged\_tangential\_grad(i,j,k)
3118 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
3119 \textcolor{keywordflow}{         endif}
3120          \textcolor{keyword}{deallocate}(ry\_tang\_rad)
3121 \textcolor{keywordflow}{       endif}
3122        \textcolor{keywordflow}{if} (segment%oblique\_tan .or. segment%oblique\_grad) \textcolor{keywordflow}{then}
3123          j=segment%HI%JsdB
3124          \textcolor{keyword}{allocate}(rx\_tang\_obl(segment%HI%IsdB:segment%HI%IedB,segment%HI%JsdB:segment%HI%JedB,nz))
3125          \textcolor{keyword}{allocate}(ry\_tang\_obl(segment%HI%IsdB:segment%HI%IedB,segment%HI%JsdB:segment%HI%JedB,nz))
3126          \textcolor{keyword}{allocate}(cff\_tangential(segment%HI%IsdB:segment%HI%IedB,segment%HI%JsdB:segment%HI%JedB,nz))
3127          \textcolor{keywordflow}{do} k=1,nz
3128            \textcolor{keywordflow}{if} (gamma\_u < 1.0) \textcolor{keywordflow}{then}
3129              rx\_tang\_obl(segment%HI%IsdB,j,k) = segment%rx\_norm\_obl(segment%HI%isd,j,k)
3130              rx\_tang\_obl(segment%HI%IedB,j,k) = segment%rx\_norm\_obl(segment%HI%ied,j,k)
3131              ry\_tang\_obl(segment%HI%IsdB,j,k) = segment%ry\_norm\_obl(segment%HI%isd,j,k)
3132              ry\_tang\_obl(segment%HI%IedB,j,k) = segment%ry\_norm\_obl(segment%HI%ied,j,k)
3133              cff\_tangential(segment%HI%IsdB,j,k) = segment%cff\_normal(segment%HI%isd,j,k)
3134              cff\_tangential(segment%HI%IedB,j,k) = segment%cff\_normal(segment%HI%ied,j,k)
3135              \textcolor{keywordflow}{do} i=segment%HI%IsdB+1,segment%HI%IedB-1
3136                rx\_tang\_obl(i,j,k) = 0.5*(segment%rx\_norm\_obl(i,j,k) + segment%rx\_norm\_obl(i+1,j,k))
3137                ry\_tang\_obl(i,j,k) = 0.5*(segment%ry\_norm\_obl(i,j,k) + segment%ry\_norm\_obl(i+1,j,k))
3138                cff\_tangential(i,j,k) = 0.5*(segment%cff\_normal(i,j,k) + segment%cff\_normal(i+1,j,k))
3139 \textcolor{keywordflow}{             enddo}
3140            \textcolor{keywordflow}{else}
3141              \textcolor{keywordflow}{do} i=segment%HI%IsdB,segment%HI%IedB
3142                dhdt = u\_old(i,j+1,k)-u\_new(i,j+1,k)   \textcolor{comment}{!old-new}
3143                dhdy = u\_new(i,j+1,k)-u\_new(i,j+2,k) \textcolor{comment}{!in new time backward sasha for I-1}
3144                \textcolor{keywordflow}{if} (dhdt*(segment%grad\_tan(i,1,k) + segment%grad\_tan(i+1,1,k)) > 0.0) \textcolor{keywordflow}{then}
3145                  dhdx = segment%grad\_tan(i,1,k)
3146                \textcolor{keywordflow}{elseif} (dhdt*(segment%grad\_tan(i,1,k) + segment%grad\_tan(i+1,1,k)) == 0.0) \textcolor{keywordflow}{then}
3147                  dhdx = 0.0
3148                \textcolor{keywordflow}{else}
3149                  dhdx = segment%grad\_tan(i+1,1,k)
3150 \textcolor{keywordflow}{               endif}
3151                \textcolor{keywordflow}{if} (dhdt*dhdy < 0.0) dhdt = 0.0
3152                cff\_new = max(dhdx*dhdx + dhdy*dhdy, eps)
3153                ry\_new = min(dhdt*dhdy, cff\_new*ry\_max)
3154                rx\_new = min(cff\_new,max(dhdt*dhdx,-cff\_new))
3155                rx\_tang\_obl(i,j,k) = rx\_new
3156                ry\_tang\_obl(i,j,k) = ry\_new
3157                cff\_tangential(i,j,k) = cff\_new
3158 \textcolor{keywordflow}{             enddo}
3159 \textcolor{keywordflow}{           endif}
3160 \textcolor{keywordflow}{         enddo}
3161          \textcolor{keywordflow}{if} (segment%oblique\_tan) \textcolor{keywordflow}{then}
3162            \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} i=segment%HI%IsdB,segment%HI%IedB
3163              rx\_avg = rx\_tang\_obl(i,j,k)
3164              ry\_avg = ry\_tang\_obl(i,j,k)
3165              cff\_avg = cff\_tangential(i,j,k)
3166              segment%tangential\_vel(i,j,k) = ((cff\_avg*u\_new(i,j+1,k) + ry\_avg*u\_new(i,j+2,k)) - &
3167                                               (max(rx\_avg,0.0)*segment%grad\_tan(i,2,k) + &
3168                                                min(rx\_avg,0.0)*segment%grad\_tan(i+1,2,k)) ) / &
3169                                              (cff\_avg + ry\_avg)
3170 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
3171 \textcolor{keywordflow}{         endif}
3172          \textcolor{keywordflow}{if} (segment%nudged\_tan) \textcolor{keywordflow}{then}
3173            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} i=segment%HI%IsdB,segment%HI%IedB
3174              \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
3175              \textcolor{keywordflow}{if} (ry\_tang\_obl(i,j,k) <= 0.0) \textcolor{keywordflow}{then}
3176                tau = segment%Velocity\_nudging\_timescale\_in
3177              \textcolor{keywordflow}{else}
3178                tau = segment%Velocity\_nudging\_timescale\_out
3179 \textcolor{keywordflow}{             endif}
3180              gamma\_2 = dt / (tau + dt)
3181              segment%tangential\_vel(i,j,k) = (1.0 - gamma\_2) * segment%tangential\_vel(i,j,k) + &
3182                                              gamma\_2 * segment%nudged\_tangential\_vel(i,j,k)
3183 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
3184 \textcolor{keywordflow}{         endif}
3185          \textcolor{keywordflow}{if} (segment%oblique\_grad) \textcolor{keywordflow}{then}
3186            is\_obc = max(segment%HI%IsdB,g%isd+1)
3187            ie\_obc = min(segment%HI%IedB,g%ied-1)
3188            \textcolor{keywordflow}{do} k=1,nz ;  \textcolor{keywordflow}{do} i=segment%HI%IsdB+1,segment%HI%IedB-1
3189              rx\_avg = rx\_tang\_obl(i,j,k)
3190              ry\_avg = ry\_tang\_obl(i,j,k)
3191              cff\_avg = cff\_tangential(i,j,k)
3192              segment%tangential\_grad(i,j,k) = &
3193                  ((cff\_avg*(u\_new(i,j+2,k) - u\_new(i,j+1,k))*g%IdyBu(i,j+1) + &
3194                     ry\_avg*(u\_new(i,j+3,k) - u\_new(i,j+2,k))*g%IdyBu(i,j+2)) - &
3195                                   (max(rx\_avg,0.0)*segment%grad\_gradient(i,2,k) + &
3196                                    min(rx\_avg,0.0)*segment%grad\_gradient(i+1,2,k))) / &
3197                                  (cff\_avg + ry\_avg)
3198 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
3199 \textcolor{keywordflow}{         endif}
3200          \textcolor{keywordflow}{if} (segment%nudged\_grad) \textcolor{keywordflow}{then}
3201            \textcolor{keywordflow}{do} k=1,nz ; \textcolor{keywordflow}{do} j=segment%HI%JsdB,segment%HI%JedB
3202              \textcolor{comment}{! dhdt gets set to 0 on inflow in oblique case}
3203              \textcolor{keywordflow}{if} (ry\_tang\_obl(i,j,k) <= 0.0) \textcolor{keywordflow}{then}
3204                tau = segment%Velocity\_nudging\_timescale\_in
3205              \textcolor{keywordflow}{else}
3206                tau = segment%Velocity\_nudging\_timescale\_out
3207 \textcolor{keywordflow}{             endif}
3208              gamma\_2 = dt / (tau + dt)
3209              segment%tangential\_grad(i,j,k) = (1.0 - gamma\_2) * segment%tangential\_grad(i,j,k) + &
3210                                  gamma\_2 * segment%nudged\_tangential\_grad(i,j,k)
3211 \textcolor{keywordflow}{           enddo} ;\textcolor{keywordflow}{ enddo}
3212 \textcolor{keywordflow}{         endif}
3213          \textcolor{keyword}{deallocate}(rx\_tang\_obl)
3214          \textcolor{keyword}{deallocate}(ry\_tang\_obl)
3215          \textcolor{keyword}{deallocate}(cff\_tangential)
3216 \textcolor{keywordflow}{       endif}
3217 \textcolor{keywordflow}{     endif}
3218 \textcolor{keywordflow}{  enddo}
3219 
3220   \textcolor{comment}{! Actually update u\_new, v\_new}
3221   \textcolor{keyword}{call }open\_boundary\_apply\_normal\_flow(obc, g, u\_new, v\_new)
3222 
3223   \textcolor{keyword}{call }pass\_vector(u\_new, v\_new, g%Domain, clock=id\_clock\_pass)
3224 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a05d15beca2ef2b44fb36d129166907fa}\label{namespacemom__open__boundary_a05d15beca2ef2b44fb36d129166907fa}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!register\+\_\+file\+\_\+obc@{register\+\_\+file\+\_\+obc}}
\index{register\+\_\+file\+\_\+obc@{register\+\_\+file\+\_\+obc}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{register\+\_\+file\+\_\+obc()}{register\_file\_obc()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+open\+\_\+boundary\+::register\+\_\+file\+\_\+obc (\begin{DoxyParamCaption}\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\hyperlink{structmom__open__boundary_1_1file__obc__cs}{file\+\_\+obc\+\_\+cs}), pointer}]{CS,  }\item[{type(\hyperlink{structmom__open__boundary_1_1obc__registry__type}{obc\+\_\+registry\+\_\+type}), pointer}]{O\+B\+C\+\_\+\+Reg }\end{DoxyParamCaption})}



Add file to O\+BC registry. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em param\+\_\+file} & parameter file.\\
\hline
 & {\em cs} & file control structure.\\
\hline
 & {\em obc\+\_\+reg} & O\+BC registry. \\
\hline
\end{DoxyParams}


Definition at line 4466 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
4466   \textcolor{keywordtype}{type}(param\_file\_type),    \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{ !< parameter file.}
4467   \textcolor{keywordtype}{type}(file\_obc\_cs),        \textcolor{keywordtype}{pointer}    :: cs\textcolor{comment}{         !< file control structure.}
4468   \textcolor{keywordtype}{type}(obc\_registry\_type),  \textcolor{keywordtype}{pointer}    :: obc\_reg\textcolor{comment}{    !< OBC registry.}
4469   \textcolor{keywordtype}{logical}                              :: register\_file\_obc
4470   \textcolor{keywordtype}{character(len=32)}  :: casename = \textcolor{stringliteral}{"OBC file"}\textcolor{comment}{        !< This case's name.}
4471 
4472   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(cs)) \textcolor{keywordflow}{then}
4473     \textcolor{keyword}{call }mom\_error(warning, \textcolor{stringliteral}{"register\_file\_OBC called with an "}// &
4474                             \textcolor{stringliteral}{"associated control structure."})
4475     \textcolor{keywordflow}{return}
4476 \textcolor{keywordflow}{  endif}
4477   \textcolor{keyword}{allocate}(cs)
4478 
4479   \textcolor{comment}{! Register the file for boundary updates.}
4480   \textcolor{keyword}{call }register\_obc(casename, param\_file, obc\_reg)
4481   register\_file\_obc = .true.
4482 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a8e0e22d829c122134f039228c6f1c7fb}\label{namespacemom__open__boundary_a8e0e22d829c122134f039228c6f1c7fb}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!register\+\_\+obc@{register\+\_\+obc}}
\index{register\+\_\+obc@{register\+\_\+obc}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{register\+\_\+obc()}{register\_obc()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::register\+\_\+obc (\begin{DoxyParamCaption}\item[{character(len=32), intent(in)}]{name,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\hyperlink{structmom__open__boundary_1_1obc__registry__type}{obc\+\_\+registry\+\_\+type}), pointer}]{Reg }\end{DoxyParamCaption})}



register open boundary objects for boundary updates. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em name} & O\+BC name used for error messages\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & file to parse for model parameter values\\
\hline
 & {\em reg} & pointer to the tracer registry \\
\hline
\end{DoxyParams}


Definition at line 4414 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
4414   \textcolor{keywordtype}{character(len=32)},     \textcolor{keywordtype}{intent(in)}  :: name\textcolor{comment}{        !< OBC name used for error messages}
4415   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)}  :: param\_file\textcolor{comment}{  !< file to parse for  model parameter values}
4416   \textcolor{keywordtype}{type}(obc\_registry\_type), \textcolor{keywordtype}{pointer}   :: reg\textcolor{comment}{         !< pointer to the tracer registry}
4417   \textcolor{keywordtype}{integer} :: nobc
4418   \textcolor{keywordtype}{character(len=256)} :: mesg    \textcolor{comment}{! Message for error messages.}
4419 
4420   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(reg)) \textcolor{keyword}{call }obc\_registry\_init(param\_file, reg)
4421 
4422   \textcolor{keywordflow}{if} (reg%nobc>=max\_fields\_) \textcolor{keywordflow}{then}
4423     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("Increase MAX\_FIELDS\_ in MOM\_memory.h to at least ",I3," to allow for &}
4424 \textcolor{stringliteral}{}\textcolor{stringliteral}{        &all the open boundaries being registered via register\_OBC.")'}) reg%nobc+1
4425     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"MOM register\_tracer: "}//mesg)
4426 \textcolor{keywordflow}{  endif}
4427   reg%nobc = reg%nobc + 1
4428   nobc     = reg%nobc
4429 
4430   reg%OB(nobc)%name = name
4431 
4432   \textcolor{keywordflow}{if} (reg%locked) \textcolor{keyword}{call }mom\_error(fatal, &
4433       \textcolor{stringliteral}{"MOM register\_tracer was called for variable "}//trim(reg%OB(nobc)%name)//&
4434       \textcolor{stringliteral}{" with a locked tracer registry."})
4435 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a5d5843dd1a4e1475f69b5eb2c5b0197d}\label{namespacemom__open__boundary_a5d5843dd1a4e1475f69b5eb2c5b0197d}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!register\+\_\+segment\+\_\+tracer@{register\+\_\+segment\+\_\+tracer}}
\index{register\+\_\+segment\+\_\+tracer@{register\+\_\+segment\+\_\+tracer}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{register\+\_\+segment\+\_\+tracer()}{register\_segment\_tracer()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::register\+\_\+segment\+\_\+tracer (\begin{DoxyParamCaption}\item[{type(tracer\+\_\+type), target}]{tr\+\_\+ptr,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(\hyperlink{structmom__open__boundary_1_1obc__segment__type}{obc\+\_\+segment\+\_\+type}), intent(inout)}]{segment,  }\item[{real, intent(in), optional}]{O\+B\+C\+\_\+scalar,  }\item[{logical, intent(in), optional}]{O\+B\+C\+\_\+array }\end{DoxyParamCaption})}


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
 & {\em tr\+\_\+ptr} & A target that can be used to set a pointer to the stored value of tr. This target must be an enduring part of the control structure, because the tracer registry will use this memory, but it also means that any updates to this structure in the calling module will be available subsequently to the tracer registry.\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & file to parse for model parameter values\\
\hline
\mbox{\tt in,out}  & {\em segment} & current segment data structure\\
\hline
\mbox{\tt in}  & {\em obc\+\_\+scalar} & If present, use scalar value for segment tracer inflow concentration.\\
\hline
\mbox{\tt in}  & {\em obc\+\_\+array} & If true, use array values for segment tracer inflow concentration. \\
\hline
\end{DoxyParams}


Definition at line 4528 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
4528   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)}   :: gv\textcolor{comment}{         !< ocean vertical grid structure}
4529   \textcolor{keywordtype}{type}(tracer\_type), \textcolor{keywordtype}{target}             :: tr\_ptr\textcolor{comment}{     !< A target that can be used to set a pointer to the}
4530 \textcolor{comment}{                                                      !! stored value of tr. This target must be}
4531 \textcolor{comment}{                                                      !! an enduring part of the control structure,}
4532 \textcolor{comment}{                                                      !! because the tracer registry will use this memory,}
4533 \textcolor{comment}{                                                      !! but it also means that any updates to this}
4534 \textcolor{comment}{                                                      !! structure in the calling module will be}
4535 \textcolor{comment}{                                                      !! available subsequently to the tracer registry.}
4536   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)}     :: param\_file\textcolor{comment}{ !< file to parse for  model parameter values}
4537   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{intent(inout)} :: segment\textcolor{comment}{    !< current segment data structure}
4538   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}            :: obc\_scalar\textcolor{comment}{ !< If present, use scalar value for segment tracer}
4539 \textcolor{comment}{                                                      !! inflow concentration.}
4540   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}         :: obc\_array\textcolor{comment}{  !< If true, use array values for segment tracer}
4541 \textcolor{comment}{                                                      !! inflow concentration.}
4542 
4543 
4544 \textcolor{comment}{! Local variables}
4545   \textcolor{keywordtype}{integer} :: ntseg
4546   \textcolor{keywordtype}{integer} :: isd, ied, jsd, jed
4547   \textcolor{keywordtype}{integer} :: isdb, iedb, jsdb, jedb
4548   \textcolor{keywordtype}{character(len=256)} :: mesg    \textcolor{comment}{! Message for error messages.}
4549 
4550   \textcolor{keyword}{call }segment\_tracer\_registry\_init(param\_file, segment)
4551 
4552   \textcolor{keywordflow}{if} (segment%tr\_Reg%ntseg>=max\_fields\_) \textcolor{keywordflow}{then}
4553     \textcolor{keyword}{write}(mesg,\textcolor{stringliteral}{'("Increase MAX\_FIELDS\_ in MOM\_memory.h to at least ",I3," to allow for &}
4554 \textcolor{stringliteral}{}\textcolor{stringliteral}{        &all the tracers being registered via register\_tracer.")'}) segment%tr\_Reg%ntseg+1
4555     \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"MOM register\_tracer: "}//mesg)
4556 \textcolor{keywordflow}{  endif}
4557   segment%tr\_Reg%ntseg = segment%tr\_Reg%ntseg + 1
4558   ntseg     = segment%tr\_Reg%ntseg
4559 
4560   isd = segment%HI%isd ; ied = segment%HI%ied
4561   jsd = segment%HI%jsd ; jed = segment%HI%jed
4562   isdb = segment%HI%IsdB ; iedb = segment%HI%IedB
4563   jsdb = segment%HI%JsdB ; jedb = segment%HI%JedB
4564 
4565   segment%tr\_Reg%Tr(ntseg)%Tr => tr\_ptr
4566   segment%tr\_Reg%Tr(ntseg)%name = tr\_ptr%name
4567 
4568   \textcolor{keywordflow}{if} (segment%tr\_Reg%locked) \textcolor{keyword}{call }mom\_error(fatal, &
4569       \textcolor{stringliteral}{"MOM register\_tracer was called for variable "}//trim(segment%tr\_Reg%Tr(ntseg)%name)//&
4570       \textcolor{stringliteral}{" with a locked tracer registry."})
4571 
4572   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc\_scalar)) segment%tr\_Reg%Tr(ntseg)%OBC\_inflow\_conc = obc\_scalar \textcolor{comment}{! initialize tracer value
       later}
4573   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(obc\_array)) \textcolor{keywordflow}{then}
4574     \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
4575       \textcolor{keyword}{allocate}(segment%tr\_Reg%Tr(ntseg)%t(isdb:iedb,jsd:jed,1:gv%ke));segment%tr\_Reg%Tr(ntseg)%t(:,:,:)=0.0
4576       \textcolor{keyword}{allocate}(segment%tr\_Reg%Tr(ntseg)%tres(isdb:iedb,jsd:jed,1:gv%ke));segment%tr\_Reg%Tr(ntseg)%tres(:,:,
      :)=0.0
4577       segment%tr\_Reg%Tr(ntseg)%is\_initialized=.false.
4578     \textcolor{keywordflow}{elseif} (segment%is\_N\_or\_S) \textcolor{keywordflow}{then}
4579       \textcolor{keyword}{allocate}(segment%tr\_Reg%Tr(ntseg)%t(isd:ied,jsdb:jedb,1:gv%ke));segment%tr\_Reg%Tr(ntseg)%t(:,:,:)=0.0
4580       \textcolor{keyword}{allocate}(segment%tr\_Reg%Tr(ntseg)%tres(isd:ied,jsdb:jedb,1:gv%ke));segment%tr\_Reg%Tr(ntseg)%tres(:,:,
      :)=0.0
4581       segment%tr\_Reg%Tr(ntseg)%is\_initialized=.false.
4582 \textcolor{keywordflow}{    endif}
4583 \textcolor{keywordflow}{  endif}
4584 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a0459cfc5b4e4115bde6ada1dd7c25139}\label{namespacemom__open__boundary_a0459cfc5b4e4115bde6ada1dd7c25139}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!register\+\_\+temp\+\_\+salt\+\_\+segments@{register\+\_\+temp\+\_\+salt\+\_\+segments}}
\index{register\+\_\+temp\+\_\+salt\+\_\+segments@{register\+\_\+temp\+\_\+salt\+\_\+segments}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{register\+\_\+temp\+\_\+salt\+\_\+segments()}{register\_temp\_salt\_segments()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::register\+\_\+temp\+\_\+salt\+\_\+segments (\begin{DoxyParamCaption}\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{type(tracer\+\_\+registry\+\_\+type), pointer}]{tr\+\_\+\+Reg,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file }\end{DoxyParamCaption})}


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em gv} & ocean vertical grid structure\\
\hline
 & {\em obc} & Open boundary structure\\
\hline
 & {\em tr\+\_\+reg} & Tracer registry\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & file to parse for model parameter values \\
\hline
\end{DoxyParams}


Definition at line 4603 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
4603   \textcolor{keywordtype}{type}(verticalgrid\_type),    \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{         !< ocean vertical grid structure}
4604   \textcolor{keywordtype}{type}(ocean\_obc\_type),       \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{        !< Open boundary structure}
4605   \textcolor{keywordtype}{type}(tracer\_registry\_type), \textcolor{keywordtype}{pointer}       :: tr\_reg\textcolor{comment}{     !< Tracer registry}
4606   \textcolor{keywordtype}{type}(param\_file\_type),      \textcolor{keywordtype}{intent(in)}    :: param\_file\textcolor{comment}{ !< file to parse for  model parameter values}
4607 
4608 \textcolor{comment}{! Local variables}
4609   \textcolor{keywordtype}{integer} :: isd, ied, isdb, iedb, jsd, jed, jsdb, jedb, nz, nf
4610   \textcolor{keywordtype}{integer} :: i, j, k, n
4611   \textcolor{keywordtype}{character(len=32)}  :: name
4612   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null() \textcolor{comment}{! pointer to segment type list}
4613   \textcolor{keywordtype}{type}(tracer\_type), \textcolor{keywordtype}{pointer}      :: tr\_ptr => null()
4614 
4615   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{return}
4616 
4617   \textcolor{keywordflow}{do} n=1, obc%number\_of\_segments
4618     segment=>obc%segment(n)
4619     \textcolor{keywordflow}{if} (.not. segment%on\_pe) cycle
4620 
4621     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tr\_Reg)) &
4622          \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{"register\_temp\_salt\_segments: tracer array was previously allocated"})
4623 
4624     name = \textcolor{stringliteral}{'temp'}
4625     \textcolor{keyword}{call }tracer\_name\_lookup(tr\_reg, tr\_ptr, name)
4626     \textcolor{keyword}{call }register\_segment\_tracer(tr\_ptr, param\_file, gv, segment, &
4627                                  obc\_array=segment%temp\_segment\_data\_exists)
4628     name = \textcolor{stringliteral}{'salt'}
4629     \textcolor{keyword}{call }tracer\_name\_lookup(tr\_reg, tr\_ptr, name)
4630     \textcolor{keyword}{call }register\_segment\_tracer(tr\_ptr, param\_file, gv, segment, &
4631                                  obc\_array=segment%salt\_segment\_data\_exists)
4632 \textcolor{keywordflow}{  enddo}
4633 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a0c4401f57b9a8275c8bb3d2f7c5e013f}\label{namespacemom__open__boundary_a0c4401f57b9a8275c8bb3d2f7c5e013f}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!rotate\+\_\+obc\+\_\+config@{rotate\+\_\+obc\+\_\+config}}
\index{rotate\+\_\+obc\+\_\+config@{rotate\+\_\+obc\+\_\+config}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{rotate\+\_\+obc\+\_\+config()}{rotate\_obc\_config()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::rotate\+\_\+obc\+\_\+config (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), intent(in), pointer}]{O\+B\+C\+\_\+in,  }\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(in)}]{G\+\_\+in,  }\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), intent(inout), pointer}]{O\+BC,  }\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(in)}]{G,  }\item[{integer, intent(in)}]{turns }\end{DoxyParamCaption})}



This is more of a rotate initialization than an actual rotate. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em obc\+\_\+in} & Input O\+BC\\
\hline
\mbox{\tt in}  & {\em g\+\_\+in} & Input grid metric\\
\hline
\mbox{\tt in,out}  & {\em obc} & Rotated O\+BC\\
\hline
\mbox{\tt in}  & {\em g} & Rotated grid metric\\
\hline
\mbox{\tt in}  & {\em turns} & Number of quarter turns \\
\hline
\end{DoxyParams}


Definition at line 5245 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
5245   \textcolor{keywordtype}{type}(ocean\_obc\_type), \textcolor{keywordtype}{pointer}, \textcolor{keywordtype}{intent(in)} :: obc\_in\textcolor{comment}{   !< Input OBC}
5246   \textcolor{keywordtype}{type}(dyn\_horgrid\_type),  \textcolor{keywordtype}{intent(in)} :: g\_in\textcolor{comment}{           !< Input grid metric}
5247   \textcolor{keywordtype}{type}(ocean\_obc\_type), \textcolor{keywordtype}{pointer}, \textcolor{keywordtype}{intent(inout)} :: obc\textcolor{comment}{   !< Rotated OBC}
5248   \textcolor{keywordtype}{type}(dyn\_horgrid\_type),  \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{              !< Rotated grid metric}
5249   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: turns\textcolor{comment}{                      !< Number of quarter turns}
5250 
5251   \textcolor{keywordtype}{integer} :: l
5252 
5253   \textcolor{keywordflow}{if} (obc\_in%number\_of\_segments==0) \textcolor{keywordflow}{return}
5254 
5255   \textcolor{comment}{! Scalar and logical transfer}
5256   obc%number\_of\_segments = obc\_in%number\_of\_segments
5257   obc%ke = obc\_in%ke
5258   obc%user\_BCs\_set\_globally = obc\_in%user\_BCs\_set\_globally
5259 
5260   \textcolor{comment}{! These are conditionally read and set if number\_of\_segments > 0}
5261   obc%zero\_vorticity = obc\_in%zero\_vorticity
5262   obc%freeslip\_vorticity = obc\_in%freeslip\_vorticity
5263   obc%computed\_vorticity = obc\_in%computed\_vorticity
5264   obc%specified\_vorticity = obc\_in%specified\_vorticity
5265   obc%zero\_strain = obc\_in%zero\_strain
5266   obc%freeslip\_strain = obc\_in%freeslip\_strain
5267   obc%computed\_strain = obc\_in%computed\_strain
5268   obc%specified\_strain = obc\_in%specified\_strain
5269   obc%zero\_biharmonic = obc\_in%zero\_biharmonic
5270   obc%silly\_h = obc\_in%silly\_h
5271   obc%silly\_u = obc\_in%silly\_u
5272 
5273   \textcolor{comment}{! Segment rotation}
5274   \textcolor{keyword}{allocate}(obc%segment(0:obc%number\_of\_segments))
5275   \textcolor{keywordflow}{do} l = 1, obc%number\_of\_segments
5276     \textcolor{keyword}{call }rotate\_obc\_segment\_config(obc\_in%segment(l), g\_in, obc%segment(l), g, turns)
5277     \textcolor{comment}{! Data up to setup\_[uv]\_point\_obc is needed for allocate\_obc\_segment\_data!}
5278     \textcolor{keyword}{call }allocate\_obc\_segment\_data(obc, obc%segment(l))
5279     \textcolor{keyword}{call }rotate\_obc\_segment\_data(obc\_in%segment(l), obc%segment(l), turns)
5280 \textcolor{keywordflow}{  enddo}
5281 
5282   \textcolor{comment}{! The horizontal segment map}
5283   \textcolor{keyword}{allocate}(obc%segnum\_u(g%IsdB:g%IedB,g%jsd:g%jed))
5284   \textcolor{keyword}{allocate}(obc%segnum\_v(g%isd:g%ied,g%JsdB:g%JedB))
5285   \textcolor{keyword}{call }rotate\_array\_pair(obc\_in%segnum\_u, obc\_in%segnum\_v, turns, &
5286       obc%segnum\_u, obc%segnum\_v)
5287 
5288   \textcolor{comment}{! These are conditionally enabled during segment configuration}
5289   obc%open\_u\_BCs\_exist\_globally = obc\_in%open\_v\_BCs\_exist\_globally
5290   obc%open\_v\_BCs\_exist\_globally = obc\_in%open\_u\_BCs\_exist\_globally
5291   obc%Flather\_u\_BCs\_exist\_globally = obc\_in%Flather\_v\_BCs\_exist\_globally
5292   obc%Flather\_v\_BCs\_exist\_globally = obc\_in%Flather\_u\_BCs\_exist\_globally
5293   obc%oblique\_BCs\_exist\_globally = obc\_in%oblique\_BCs\_exist\_globally
5294   obc%nudged\_u\_BCs\_exist\_globally = obc\_in%nudged\_v\_BCs\_exist\_globally
5295   obc%nudged\_v\_BCs\_exist\_globally = obc\_in%nudged\_u\_BCs\_exist\_globally
5296   obc%specified\_u\_BCs\_exist\_globally= obc\_in%specified\_v\_BCs\_exist\_globally
5297   obc%specified\_v\_BCs\_exist\_globally= obc\_in%specified\_u\_BCs\_exist\_globally
5298   obc%radiation\_BCs\_exist\_globally = obc\_in%radiation\_BCs\_exist\_globally
5299 
5300   \textcolor{comment}{! These are set by initialize\_segment\_data}
5301   obc%brushcutter\_mode = obc\_in%brushcutter\_mode
5302   obc%update\_OBC = obc\_in%update\_OBC
5303   obc%needs\_IO\_for\_data = obc\_in%needs\_IO\_for\_data
5304 
5305   obc%ntr = obc\_in%ntr
5306 
5307   obc%gamma\_uv = obc\_in%gamma\_uv
5308   obc%rx\_max = obc\_in%rx\_max
5309   obc%OBC\_pe = obc\_in%OBC\_pe
5310 
5311   \textcolor{comment}{! remap\_CS is set up by initialize\_segment\_data, so we copy the fields here.}
5312   \textcolor{keywordflow}{if} (\textcolor{keyword}{ASSOCIATED}(obc\_in%remap\_CS)) \textcolor{keywordflow}{then}
5313      \textcolor{keyword}{allocate}(obc%remap\_CS)
5314      obc%remap\_CS = obc\_in%remap\_CS
5315 \textcolor{keywordflow}{  endif}
5316 
5317   \textcolor{comment}{! TODO: The OBC registry seems to be a list of "registered" OBC types.}
5318   \textcolor{comment}{!   It does not appear to be used, so for now we skip this record.}
5319   \textcolor{comment}{!OBC%OBC\_Reg => OBC\_in%OBC\_Reg}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_acafa1a47d4e7f4d347963286d7614104}\label{namespacemom__open__boundary_acafa1a47d4e7f4d347963286d7614104}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!rotate\+\_\+obc\+\_\+init@{rotate\+\_\+obc\+\_\+init}}
\index{rotate\+\_\+obc\+\_\+init@{rotate\+\_\+obc\+\_\+init}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{rotate\+\_\+obc\+\_\+init()}{rotate\_obc\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::rotate\+\_\+obc\+\_\+init (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), intent(in), pointer}]{O\+B\+C\+\_\+in,  }\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(thermo\+\_\+var\+\_\+ptrs), intent(inout)}]{tv,  }\item[{type(mom\+\_\+restart\+\_\+cs), intent(in), pointer}]{restart\+\_\+\+C\+Sp,  }\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), intent(inout), pointer}]{O\+BC }\end{DoxyParamCaption})}



Initialize the segments and field-\/related data of a rotated O\+BC. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em obc\+\_\+in} & O\+BC on input map\\
\hline
\mbox{\tt in}  & {\em g} & Rotated grid metric\\
\hline
\mbox{\tt in}  & {\em gv} & Vertical grid\\
\hline
\mbox{\tt in}  & {\em us} & Unit scaling\\
\hline
\mbox{\tt in}  & {\em param\+\_\+file} & Input parameters\\
\hline
\mbox{\tt in,out}  & {\em tv} & Tracer fields\\
\hline
\mbox{\tt in}  & {\em restart\+\_\+csp} & Restart CS\\
\hline
\mbox{\tt in,out}  & {\em obc} & Rotated O\+BC \\
\hline
\end{DoxyParams}


Definition at line 5458 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
5458   \textcolor{keywordtype}{type}(ocean\_obc\_type), \textcolor{keywordtype}{pointer}, \textcolor{keywordtype}{intent(in)} :: obc\_in\textcolor{comment}{   !< OBC on input map}
5459   \textcolor{keywordtype}{type}(ocean\_grid\_type), \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{                !< Rotated grid metric}
5460   \textcolor{keywordtype}{type}(verticalgrid\_type), \textcolor{keywordtype}{intent(in)} :: gv\textcolor{comment}{             !< Vertical grid}
5461   \textcolor{keywordtype}{type}(unit\_scale\_type), \textcolor{keywordtype}{intent(in)} :: us\textcolor{comment}{               !< Unit scaling}
5462   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)} :: param\_file\textcolor{comment}{       !< Input parameters}
5463   \textcolor{keywordtype}{type}(thermo\_var\_ptrs), \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{            !< Tracer fields}
5464   \textcolor{keywordtype}{type}(mom\_restart\_cs), \textcolor{keywordtype}{pointer}, \textcolor{keywordtype}{intent(in)} :: restart\_csp\textcolor{comment}{  !< Restart CS}
5465   \textcolor{keywordtype}{type}(ocean\_obc\_type), \textcolor{keywordtype}{pointer}, \textcolor{keywordtype}{intent(inout)} :: obc\textcolor{comment}{   !< Rotated OBC}
5466 
5467   \textcolor{keywordtype}{logical} :: use\_temperature
5468   \textcolor{keywordtype}{integer} :: l
5469 
5470   \textcolor{keyword}{call }get\_param(param\_file, \textcolor{stringliteral}{"MOM"}, \textcolor{stringliteral}{"ENABLE\_THERMODYNAMICS"}, use\_temperature, &
5471                  \textcolor{stringliteral}{"If true, Temperature and salinity are used as state "}//&
5472                  \textcolor{stringliteral}{"variables."}, default=.true., do\_not\_log=.true.)
5473 
5474   \textcolor{keywordflow}{do} l = 1, obc%number\_of\_segments
5475     \textcolor{keyword}{call }rotate\_obc\_segment\_data(obc\_in%segment(l), obc%segment(l), g%HI%turns)
5476 \textcolor{keywordflow}{  enddo}
5477 
5478   \textcolor{keywordflow}{if} (use\_temperature) &
5479     \textcolor{keyword}{call }fill\_temp\_salt\_segments(g, obc, tv)
5480 
5481   \textcolor{keyword}{call }open\_boundary\_init(g, gv, us, param\_file, obc, restart\_csp)
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a68a208918e01e2393f12f737bdff3776}\label{namespacemom__open__boundary_a68a208918e01e2393f12f737bdff3776}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!rotate\+\_\+obc\+\_\+segment\+\_\+config@{rotate\+\_\+obc\+\_\+segment\+\_\+config}}
\index{rotate\+\_\+obc\+\_\+segment\+\_\+config@{rotate\+\_\+obc\+\_\+segment\+\_\+config}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{rotate\+\_\+obc\+\_\+segment\+\_\+config()}{rotate\_obc\_segment\_config()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::rotate\+\_\+obc\+\_\+segment\+\_\+config (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1obc__segment__type}{obc\+\_\+segment\+\_\+type}), intent(in)}]{segment\+\_\+in,  }\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(in)}]{G\+\_\+in,  }\item[{type(\hyperlink{structmom__open__boundary_1_1obc__segment__type}{obc\+\_\+segment\+\_\+type}), intent(inout)}]{segment,  }\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(in)}]{G,  }\item[{integer, intent(in)}]{turns }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Rotate the O\+BC segment configuration data from the input to model index map. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em segment\+\_\+in} & Input O\+BC segment\\
\hline
\mbox{\tt in}  & {\em g\+\_\+in} & Input grid metric\\
\hline
\mbox{\tt in,out}  & {\em segment} & Rotated O\+BC segment\\
\hline
\mbox{\tt in}  & {\em g} & Rotated grid metric\\
\hline
\mbox{\tt in}  & {\em turns} & Number of quarter turns \\
\hline
\end{DoxyParams}


Definition at line 5324 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
5324   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{intent(in)} :: segment\_in\textcolor{comment}{  !< Input OBC segment}
5325   \textcolor{keywordtype}{type}(dyn\_horgrid\_type),  \textcolor{keywordtype}{intent(in)} :: g\_in\textcolor{comment}{       !< Input grid metric}
5326   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{intent(inout)} :: segment\textcolor{comment}{  !< Rotated OBC segment}
5327   \textcolor{keywordtype}{type}(dyn\_horgrid\_type),  \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{          !< Rotated grid metric}
5328   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: turns\textcolor{comment}{                      !< Number of quarter turns}
5329 
5330   \textcolor{comment}{! Global segment indices}
5331   \textcolor{keywordtype}{integer} :: is\_obc\_in, ie\_obc\_in, js\_obc\_in, je\_obc\_in \textcolor{comment}{! Input domain}
5332   \textcolor{keywordtype}{integer} :: is\_obc, ie\_obc, js\_obc, je\_obc             \textcolor{comment}{! Rotated domain}
5333 
5334   \textcolor{comment}{! NOTE: A "rotation" of the OBC segment string would allow us to use}
5335   \textcolor{comment}{!   setup\_[uv]\_point\_obc to set up most of this.  For now, we just copy/swap}
5336   \textcolor{comment}{!   flags and manually rotate the indices.}
5337 
5338   \textcolor{comment}{! This is set if the segment is in the local grid}
5339   segment%on\_pe = segment\_in%on\_pe
5340 
5341   \textcolor{comment}{! Transfer configuration flags}
5342   segment%Flather = segment\_in%Flather
5343   segment%radiation = segment\_in%radiation
5344   segment%radiation\_tan = segment\_in%radiation\_tan
5345   segment%radiation\_grad = segment\_in%radiation\_grad
5346   segment%oblique = segment\_in%oblique
5347   segment%oblique\_tan = segment\_in%oblique\_tan
5348   segment%oblique\_grad = segment\_in%oblique\_grad
5349   segment%nudged = segment\_in%nudged
5350   segment%nudged\_tan = segment\_in%nudged\_tan
5351   segment%nudged\_grad = segment\_in%nudged\_grad
5352   segment%specified = segment\_in%specified
5353   segment%specified\_tan = segment\_in%specified\_tan
5354   segment%specified\_grad = segment\_in%specified\_grad
5355   segment%open = segment\_in%open
5356   segment%gradient = segment\_in%gradient
5357 
5358   \textcolor{comment}{! NOTE: [uv]\_values\_needed are swapped}
5359   segment%u\_values\_needed = segment\_in%v\_values\_needed
5360   segment%v\_values\_needed = segment\_in%u\_values\_needed
5361   segment%z\_values\_needed = segment\_in%z\_values\_needed
5362   segment%g\_values\_needed = segment\_in%g\_values\_needed
5363   segment%t\_values\_needed = segment\_in%t\_values\_needed
5364   segment%s\_values\_needed = segment\_in%s\_values\_needed
5365 
5366   segment%values\_needed = segment\_in%values\_needed
5367 
5368   \textcolor{comment}{! These are conditionally set if nudged}
5369   segment%Velocity\_nudging\_timescale\_in = segment\_in%Velocity\_nudging\_timescale\_in
5370   segment%Velocity\_nudging\_timescale\_out= segment\_in%Velocity\_nudging\_timescale\_out
5371 
5372   \textcolor{comment}{! Rotate segment indices}
5373 
5374   \textcolor{comment}{! Reverse engineer the input [IJ][se]\_obc segment indices}
5375   \textcolor{comment}{! NOTE: The values stored in the segment are always saved in ascending order,}
5376   \textcolor{comment}{!   e.g. (is < ie).  In order to use setup\_segment\_indices, we reorder the}
5377   \textcolor{comment}{!   indices here to indicate face direction.}
5378   \textcolor{comment}{!   Segment indices are also indexed locally, so we remove the halo offset.}
5379   \textcolor{keywordflow}{if} (segment\_in%direction == obc\_direction\_n) \textcolor{keywordflow}{then}
5380     is\_obc\_in = segment\_in%Ie\_obc + g\_in%idg\_offset
5381     ie\_obc\_in = segment\_in%Is\_obc + g\_in%idg\_offset
5382   \textcolor{keywordflow}{else}
5383     is\_obc\_in = segment\_in%Is\_obc + g\_in%idg\_offset
5384     ie\_obc\_in = segment\_in%Ie\_obc + g\_in%idg\_offset
5385 \textcolor{keywordflow}{  endif}
5386 
5387   \textcolor{keywordflow}{if} (segment\_in%direction == obc\_direction\_w) \textcolor{keywordflow}{then}
5388     js\_obc\_in = segment\_in%Je\_obc + g\_in%jdg\_offset
5389     je\_obc\_in = segment\_in%Js\_obc + g\_in%jdg\_offset
5390   \textcolor{keywordflow}{else}
5391     js\_obc\_in = segment\_in%Js\_obc + g\_in%jdg\_offset
5392     je\_obc\_in = segment\_in%Je\_obc + g\_in%jdg\_offset
5393 \textcolor{keywordflow}{  endif}
5394 
5395   \textcolor{comment}{! TODO: This is hardcoded for 90 degrees, and needs to be generalized.}
5396   is\_obc = g\_in%jegB - js\_obc\_in
5397   ie\_obc = g\_in%JegB - je\_obc\_in
5398   js\_obc = is\_obc\_in
5399   je\_obc = ie\_obc\_in
5400 
5401   \textcolor{comment}{! Orientation is based on the index ordering, [IJ][se]\_obc are re-ordered}
5402   \textcolor{comment}{! after the index is set.  So we now need to restore the original order}
5403 
5404   \textcolor{keyword}{call }setup\_segment\_indices(g, segment, is\_obc, ie\_obc, js\_obc, je\_obc)
5405 
5406   \textcolor{comment}{! Re-order [IJ][se]\_obc back to ascending, and remove the halo offset.}
5407   \textcolor{keywordflow}{if} (is\_obc > ie\_obc) \textcolor{keywordflow}{then}
5408     segment%Is\_obc = ie\_obc - g%idg\_offset
5409     segment%Ie\_obc = is\_obc - g%idg\_offset
5410   \textcolor{keywordflow}{else}
5411     segment%Is\_obc = is\_obc - g%idg\_offset
5412     segment%Ie\_obc = ie\_obc - g%idg\_offset
5413 \textcolor{keywordflow}{  endif}
5414 
5415   \textcolor{keywordflow}{if} (js\_obc > je\_obc) \textcolor{keywordflow}{then}
5416     segment%Js\_obc = je\_obc - g%jdg\_offset
5417     segment%Je\_obc = js\_obc - g%jdg\_offset
5418   \textcolor{keywordflow}{else}
5419     segment%Js\_obc = js\_obc - g%jdg\_offset
5420     segment%Je\_obc = je\_obc - g%jdg\_offset
5421 \textcolor{keywordflow}{  endif}
5422 
5423   \textcolor{comment}{! Reconfigure the directional flags}
5424   \textcolor{comment}{! TODO: This is hardcoded for 90 degrees, and needs to be generalized.}
5425   \textcolor{keywordflow}{select case} (segment\_in%direction)
5426     \textcolor{keywordflow}{case} (obc\_direction\_n)
5427       segment%direction = obc\_direction\_w
5428       segment%is\_E\_or\_W\_2 = segment\_in%is\_N\_or\_S
5429       segment%is\_E\_or\_W = segment\_in%is\_N\_or\_S .and. segment\_in%on\_pe
5430       segment%is\_N\_or\_S = .false.
5431     \textcolor{keywordflow}{case} (obc\_direction\_w)
5432       segment%direction = obc\_direction\_s
5433       segment%is\_N\_or\_S = segment\_in%is\_E\_or\_W
5434       segment%is\_E\_or\_W = .false.
5435       segment%is\_E\_or\_W\_2 = .false.
5436     \textcolor{keywordflow}{case} (obc\_direction\_s)
5437       segment%direction = obc\_direction\_e
5438       segment%is\_E\_or\_W\_2 = segment\_in%is\_N\_or\_S
5439       segment%is\_E\_or\_W = segment\_in%is\_N\_or\_S .and. segment\_in%on\_pe
5440       segment%is\_N\_or\_S = .false.
5441     \textcolor{keywordflow}{case} (obc\_direction\_e)
5442       segment%direction = obc\_direction\_n
5443       segment%is\_N\_or\_S = segment\_in%is\_E\_or\_W
5444       segment%is\_E\_or\_W = .false.
5445       segment%is\_E\_or\_W\_2 = .false.
5446     \textcolor{keywordflow}{case} (obc\_none)
5447       segment%direction = obc\_none
5448 \textcolor{keywordflow}{  end select}
5449 
5450   \textcolor{comment}{! These are conditionally set if Lscale\_\{in,out\} are present}
5451   segment%Tr\_InvLscale\_in = segment\_in%Tr\_InvLscale\_in
5452   segment%Tr\_InvLscale\_out = segment\_in%Tr\_InvLscale\_out
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a71194a8dc156fea37aab6539cc124086}\label{namespacemom__open__boundary_a71194a8dc156fea37aab6539cc124086}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!segment\+\_\+tracer\+\_\+registry\+\_\+end@{segment\+\_\+tracer\+\_\+registry\+\_\+end}}
\index{segment\+\_\+tracer\+\_\+registry\+\_\+end@{segment\+\_\+tracer\+\_\+registry\+\_\+end}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{segment\+\_\+tracer\+\_\+registry\+\_\+end()}{segment\_tracer\_registry\_end()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::segment\+\_\+tracer\+\_\+registry\+\_\+end (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1segment__tracer__registry__type}{segment\+\_\+tracer\+\_\+registry\+\_\+type}), pointer}]{Reg }\end{DoxyParamCaption})}



Clean up the segment tracer registry. 


\begin{DoxyParams}{Parameters}
{\em reg} & pointer to tracer registry \\
\hline
\end{DoxyParams}


Definition at line 4589 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
4589   \textcolor{keywordtype}{type}(segment\_tracer\_registry\_type), \textcolor{keywordtype}{pointer} :: reg\textcolor{comment}{        !< pointer to tracer registry}
4590 
4591 \textcolor{comment}{! Local variables}
4592   \textcolor{keywordtype}{integer} n
4593 
4594   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(reg)) \textcolor{keywordflow}{then}
4595     \textcolor{keywordflow}{do} n = 1, reg%ntseg
4596       \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(reg%Tr(n)%t)) \textcolor{keyword}{deallocate}(reg%Tr(n)%t)
4597 \textcolor{keywordflow}{    enddo}
4598     \textcolor{keyword}{deallocate}(reg)
4599 \textcolor{keywordflow}{  endif}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_adcd9637c6cc17658fe064ce1dc1011bf}\label{namespacemom__open__boundary_adcd9637c6cc17658fe064ce1dc1011bf}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!segment\+\_\+tracer\+\_\+registry\+\_\+init@{segment\+\_\+tracer\+\_\+registry\+\_\+init}}
\index{segment\+\_\+tracer\+\_\+registry\+\_\+init@{segment\+\_\+tracer\+\_\+registry\+\_\+init}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{segment\+\_\+tracer\+\_\+registry\+\_\+init()}{segment\_tracer\_registry\_init()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::segment\+\_\+tracer\+\_\+registry\+\_\+init (\begin{DoxyParamCaption}\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{param\+\_\+file,  }\item[{type(\hyperlink{structmom__open__boundary_1_1obc__segment__type}{obc\+\_\+segment\+\_\+type}), intent(inout)}]{segment }\end{DoxyParamCaption})}



Initialize the segment tracer registry. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em param\+\_\+file} & open file to parse for model parameters\\
\hline
\mbox{\tt in,out}  & {\em segment} & the segment \\
\hline
\end{DoxyParams}


Definition at line 4496 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
4496   \textcolor{keywordtype}{type}(param\_file\_type),      \textcolor{keywordtype}{intent(in)}      :: param\_file\textcolor{comment}{ !< open file to parse for model parameters}
4497   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{intent(inout)}       :: segment\textcolor{comment}{    !<  the segment}
4498 
4499   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{save} :: init\_calls = 0
4500 
4501 \textcolor{comment}{! This include declares and sets the variable "version".}
4502 \textcolor{preprocessor}{#include "version\_variable.h"}
4503 \textcolor{preprocessor}{}  \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"segment\_tracer\_registry\_init"} \textcolor{comment}{! This routine's name.}
4504   \textcolor{keywordtype}{character(len=256)} :: mesg    \textcolor{comment}{! Message for error messages.}
4505 
4506   \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(segment%tr\_Reg)) \textcolor{keywordflow}{then}
4507     \textcolor{keyword}{allocate}(segment%tr\_Reg)
4508   \textcolor{keywordflow}{else}
4509     \textcolor{keywordflow}{return}
4510 \textcolor{keywordflow}{  endif}
4511 
4512   init\_calls = init\_calls + 1
4513 
4514   \textcolor{comment}{! Read all relevant parameters and write them to the model log.}
4515   \textcolor{keywordflow}{if} (init\_calls == 1) \textcolor{keyword}{call }log\_version(param\_file, mdl, version, \textcolor{stringliteral}{""})
4516 
4517 \textcolor{comment}{! Need to call once per segment with tracers...}
4518 \textcolor{comment}{! if (init\_calls > 1) then}
4519 \textcolor{comment}{!   write(mesg,'("segment\_tracer\_registry\_init called ",I3, &}
4520 \textcolor{comment}{!     &" times with different registry pointers.")') init\_calls}
4521 \textcolor{comment}{!   if (is\_root\_pe()) call MOM\_error(WARNING,"MOM\_tracer"//mesg)}
4522 \textcolor{comment}{! endif}
4523 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a0a4c67f2e0fe21f1a2274be12844a71a}\label{namespacemom__open__boundary_a0a4c67f2e0fe21f1a2274be12844a71a}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!set\+\_\+tracer\+\_\+data@{set\+\_\+tracer\+\_\+data}}
\index{set\+\_\+tracer\+\_\+data@{set\+\_\+tracer\+\_\+data}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{set\+\_\+tracer\+\_\+data()}{set\_tracer\_data()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::set\+\_\+tracer\+\_\+data (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(inout)}]{tv,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g), szk\+\_\+(g)), intent(inout)}]{h,  }\item[{type(ocean\+\_\+grid\+\_\+type), intent(inout)}]{G,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{PF,  }\item[{type(tracer\+\_\+registry\+\_\+type), pointer}]{tracer\+\_\+\+Reg }\end{DoxyParamCaption})}



Sets the initial values of the tracer open boundary conditions. Redoing this elsewhere. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em g} & Ocean grid structure\\
\hline
 & {\em obc} & Open boundary structure\\
\hline
\mbox{\tt in,out}  & {\em tv} & Thermodynamics structure\\
\hline
\mbox{\tt in,out}  & {\em h} & Thickness\\
\hline
\mbox{\tt in}  & {\em pf} & Parameter file handle\\
\hline
 & {\em tracer\+\_\+reg} & Tracer registry \\
\hline
\end{DoxyParams}


Definition at line 3421 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
3421   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(inout)} :: g\textcolor{comment}{ !< Ocean grid structure}
3422   \textcolor{keywordtype}{type}(ocean\_obc\_type),                      \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{ !< Open boundary structure}
3423   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                     \textcolor{keywordtype}{intent(inout)} :: tv\textcolor{comment}{ !< Thermodynamics structure}
3424   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G), SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{ !< Thickness}
3425   \textcolor{keywordtype}{type}(param\_file\_type),                     \textcolor{keywordtype}{intent(in)}    :: pf\textcolor{comment}{ !< Parameter file handle}
3426   \textcolor{keywordtype}{type}(tracer\_registry\_type),                \textcolor{keywordtype}{pointer}       :: tracer\_reg\textcolor{comment}{ !< Tracer registry}
3427   \textcolor{comment}{! Local variables}
3428   \textcolor{keywordtype}{integer} :: i, j, k, itt, is, ie, js, je, isd, ied, jsd, jed, nz, n
3429   \textcolor{keywordtype}{integer} :: isd\_off, jsd\_off
3430   \textcolor{keywordtype}{integer} :: isdb, iedb, jsdb, jedb
3431   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment  => null() \textcolor{comment}{! pointer to segment type list}
3432   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"set\_tracer\_data"} \textcolor{comment}{! This subroutine's name.}
3433   \textcolor{keywordtype}{character(len=200)} :: filename, obc\_file, inputdir \textcolor{comment}{! Strings for file/path}
3434 
3435   \textcolor{keywordtype}{real} :: temp\_u(g%domain%niglobal+1,g%domain%njglobal)
3436   \textcolor{keywordtype}{real} :: temp\_v(g%domain%niglobal,g%domain%njglobal+1)
3437 
3438   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec ; nz = g%ke
3439   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
3440   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
3441 
3442   \textcolor{comment}{! For now, there are no radiation conditions applied to the thicknesses, since}
3443   \textcolor{comment}{! the thicknesses might not be physically motivated.  Instead, sponges should be}
3444   \textcolor{comment}{! used to enforce the near-boundary layer structure.}
3445 
3446   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(tv%T)) \textcolor{keywordflow}{then}
3447 
3448     \textcolor{keyword}{call }pass\_var(tv%T, g%Domain)
3449     \textcolor{keyword}{call }pass\_var(tv%S, g%Domain)
3450 
3451     \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
3452       segment => obc%segment(n)
3453       \textcolor{keywordflow}{if} (.not. segment%on\_pe) cycle
3454 
3455       \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_e) \textcolor{keywordflow}{then}
3456         i=segment%HI%IsdB
3457         \textcolor{keywordflow}{do} k=1,g%ke ;  \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
3458           tv%T(i+1,j,k) = tv%T(i,j,k) ; tv%S(i+1,j,k) = tv%S(i,j,k)
3459 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
3460       \textcolor{keywordflow}{elseif} (segment%direction == obc\_direction\_w) \textcolor{keywordflow}{then}
3461         i=segment%HI%IsdB
3462         \textcolor{keywordflow}{do} k=1,g%ke ;  \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
3463           tv%T(i,j,k) = tv%T(i+1,j,k) ; tv%S(i,j,k) = tv%S(i+1,j,k)
3464 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
3465       \textcolor{keywordflow}{elseif} (segment%direction == obc\_direction\_n) \textcolor{keywordflow}{then}
3466         j=segment%HI%JsdB
3467         \textcolor{keywordflow}{do} k=1,g%ke ;  \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
3468           tv%T(i,j+1,k) = tv%T(i,j,k) ; tv%S(i,j+1,k) = tv%S(i,j,k)
3469 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
3470       \textcolor{keywordflow}{elseif} (segment%direction == obc\_direction\_s) \textcolor{keywordflow}{then}
3471         j=segment%HI%JsdB
3472         \textcolor{keywordflow}{do} k=1,g%ke ;  \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
3473           tv%T(i,j,k) = tv%T(i,j+1,k) ; tv%S(i,j,k) = tv%S(i,j+1,k)
3474 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ enddo}
3475 \textcolor{keywordflow}{      endif}
3476 \textcolor{keywordflow}{    enddo}
3477 \textcolor{keywordflow}{  endif}
3478 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a2578141730f51e42c56bb05c3648ea08}\label{namespacemom__open__boundary_a2578141730f51e42c56bb05c3648ea08}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!setup\+\_\+obc\+\_\+tracer\+\_\+reservoirs@{setup\+\_\+obc\+\_\+tracer\+\_\+reservoirs}}
\index{setup\+\_\+obc\+\_\+tracer\+\_\+reservoirs@{setup\+\_\+obc\+\_\+tracer\+\_\+reservoirs}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{setup\+\_\+obc\+\_\+tracer\+\_\+reservoirs()}{setup\_obc\_tracer\_reservoirs()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::setup\+\_\+obc\+\_\+tracer\+\_\+reservoirs (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Make sure the O\+BC tracer reservoirs are initialized. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
 & {\em obc} & Open boundary control structure \\
\hline
\end{DoxyParams}


Definition at line 2080 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
2080   \textcolor{keywordtype}{type}(ocean\_grid\_type),      \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{          !< Ocean grid structure}
2081   \textcolor{keywordtype}{type}(ocean\_obc\_type),       \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{ !< Open boundary control structure}
2082   \textcolor{comment}{! Local variables}
2083   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()
2084   \textcolor{keywordtype}{integer} :: i, j, k, m, n
2085 
2086   \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
2087     segment=>obc%segment(n)
2088     \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tr\_Reg)) \textcolor{keywordflow}{then}
2089       \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
2090         i = segment%HI%IsdB
2091         \textcolor{keywordflow}{do} m=1,obc%ntr
2092           \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tr\_Reg%Tr(m)%tres)) \textcolor{keywordflow}{then}
2093             \textcolor{keywordflow}{do} k=1,g%ke
2094               \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
2095                 obc%tres\_x(i,j,k,m) = segment%tr\_Reg%Tr(m)%t(i,j,k)
2096 \textcolor{keywordflow}{              enddo}
2097 \textcolor{keywordflow}{            enddo}
2098 \textcolor{keywordflow}{          endif}
2099 \textcolor{keywordflow}{        enddo}
2100       \textcolor{keywordflow}{else}
2101         j = segment%HI%JsdB
2102         \textcolor{keywordflow}{do} m=1,obc%ntr
2103           \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tr\_Reg%Tr(m)%tres)) \textcolor{keywordflow}{then}
2104             \textcolor{keywordflow}{do} k=1,g%ke
2105               \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
2106                 obc%tres\_y(i,j,k,m) = segment%tr\_Reg%Tr(m)%t(i,j,k)
2107 \textcolor{keywordflow}{              enddo}
2108 \textcolor{keywordflow}{            enddo}
2109 \textcolor{keywordflow}{          endif}
2110 \textcolor{keywordflow}{        enddo}
2111 \textcolor{keywordflow}{      endif}
2112 \textcolor{keywordflow}{    endif}
2113 \textcolor{keywordflow}{  enddo}
2114 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_ac357a1fb341db3aaffdfeca2eacab60b}\label{namespacemom__open__boundary_ac357a1fb341db3aaffdfeca2eacab60b}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!setup\+\_\+segment\+\_\+indices@{setup\+\_\+segment\+\_\+indices}}
\index{setup\+\_\+segment\+\_\+indices@{setup\+\_\+segment\+\_\+indices}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{setup\+\_\+segment\+\_\+indices()}{setup\_segment\_indices()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::setup\+\_\+segment\+\_\+indices (\begin{DoxyParamCaption}\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(in)}]{G,  }\item[{type(\hyperlink{structmom__open__boundary_1_1obc__segment__type}{obc\+\_\+segment\+\_\+type}), intent(inout)}]{seg,  }\item[{integer, intent(in)}]{Is\+\_\+obc,  }\item[{integer, intent(in)}]{Ie\+\_\+obc,  }\item[{integer, intent(in)}]{Js\+\_\+obc,  }\item[{integer, intent(in)}]{Je\+\_\+obc }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Define indices for segment and store in hor\+\_\+index\+\_\+type using global segment bounds corresponding to q-\/points. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & grid type\\
\hline
\mbox{\tt in,out}  & {\em seg} & Open boundary segment\\
\hline
\mbox{\tt in}  & {\em is\+\_\+obc} & Q-\/point global i-\/index of start of segment\\
\hline
\mbox{\tt in}  & {\em ie\+\_\+obc} & Q-\/point global i-\/index of end of segment\\
\hline
\mbox{\tt in}  & {\em js\+\_\+obc} & Q-\/point global j-\/index of start of segment\\
\hline
\mbox{\tt in}  & {\em je\+\_\+obc} & Q-\/point global j-\/index of end of segment \\
\hline
\end{DoxyParams}


Definition at line 1058 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
1058   \textcolor{keywordtype}{type}(dyn\_horgrid\_type), \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{ !< grid type}
1059   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{intent(inout)} :: seg\textcolor{comment}{  !< Open boundary segment}
1060   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: is\_obc\textcolor{comment}{ !< Q-point global i-index of start of segment}
1061   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: ie\_obc\textcolor{comment}{ !< Q-point global i-index of end of segment}
1062   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: js\_obc\textcolor{comment}{ !< Q-point global j-index of start of segment}
1063   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: je\_obc\textcolor{comment}{ !< Q-point global j-index of end of segment}
1064   \textcolor{comment}{! Local variables}
1065   \textcolor{keywordtype}{integer} :: isgb, iegb, jsgb, jegb
1066   \textcolor{keywordtype}{integer} :: isg, ieg, jsg, jeg
1067 
1068   \textcolor{comment}{! Isg, Ieg will be I*\_obc in global space}
1069   \textcolor{keywordflow}{if} (ie\_obc < is\_obc) \textcolor{keywordflow}{then}
1070     isgb = ie\_obc
1071     iegb = is\_obc
1072   \textcolor{keywordflow}{else}
1073     isgb = is\_obc
1074     iegb = ie\_obc
1075 \textcolor{keywordflow}{  endif}
1076 
1077   \textcolor{keywordflow}{if} (je\_obc < js\_obc) \textcolor{keywordflow}{then}
1078     jsgb = je\_obc
1079     jegb = js\_obc
1080   \textcolor{keywordflow}{else}
1081     jsgb = js\_obc
1082     jegb = je\_obc
1083 \textcolor{keywordflow}{  endif}
1084 
1085   \textcolor{comment}{! NOTE: h-points are defined along the interior of the segment q-points.}
1086   \textcolor{comment}{!   For a given segment and its start and end index pairs, [IJ][se]gB, the}
1087   \textcolor{comment}{!   h-cell corresponding to this pair are shown in the figure below.}
1088   \textcolor{comment}{!}
1089   \textcolor{comment}{! x-x----------------x-x}
1090   \textcolor{comment}{! | |        N       | |}
1091   \textcolor{comment}{! x-x   W         E  x-x}
1092   \textcolor{comment}{!   |        S         |}
1093   \textcolor{comment}{! x-x----------------x-x}
1094   \textcolor{comment}{! | |                | |}
1095   \textcolor{comment}{! x-x                x-x}
1096   \textcolor{comment}{!}
1097   \textcolor{comment}{! For segment points on the west and south, h-point indices are incremented}
1098   \textcolor{comment}{! in order to move to the interior cell.}
1099 
1100   \textcolor{keywordflow}{if} (is\_obc > ie\_obc) \textcolor{keywordflow}{then}
1101     \textcolor{comment}{! Northern boundary}
1102     isg = isgb + 1
1103     jsg = jsgb
1104     ieg = iegb
1105     jeg = jegb
1106 \textcolor{keywordflow}{  endif}
1107 
1108   \textcolor{keywordflow}{if} (is\_obc < ie\_obc) \textcolor{keywordflow}{then}
1109     \textcolor{comment}{! Southern boundary}
1110     isg = isgb + 1
1111     jsg = jsgb + 1
1112     ieg = iegb
1113     jeg = jegb + 1
1114 \textcolor{keywordflow}{  endif}
1115 
1116   \textcolor{keywordflow}{if} (js\_obc < je\_obc) \textcolor{keywordflow}{then}
1117     \textcolor{comment}{! Eastern boundary}
1118     isg = isgb
1119     jsg = jsgb + 1
1120     ieg = iegb
1121     jeg = jegb
1122 \textcolor{keywordflow}{  endif}
1123 
1124   \textcolor{keywordflow}{if} (js\_obc > je\_obc) \textcolor{keywordflow}{then}
1125     \textcolor{comment}{! Western boundary}
1126     isg = isgb + 1
1127     jsg = jsgb + 1
1128     ieg = iegb + 1
1129     jeg = jegb
1130 \textcolor{keywordflow}{  endif}
1131 
1132   \textcolor{comment}{! Global space I*\_obc but sorted}
1133   seg%HI%IsgB = isgb
1134   seg%HI%JegB = jegb
1135   seg%HI%IegB = iegb
1136   seg%HI%JsgB = jsgb
1137 
1138   seg%HI%isg = isg
1139   seg%HI%jsg = jsg
1140   seg%HI%ieg = ieg
1141   seg%HI%jeg = jeg
1142 
1143   \textcolor{comment}{! Move into local index space}
1144   isgb = isgb - g%idg\_offset
1145   jsgb = jsgb - g%jdg\_offset
1146   iegb = iegb - g%idg\_offset
1147   jegb = jegb - g%jdg\_offset
1148 
1149   isg = isg - g%idg\_offset
1150   jsg = jsg - g%jdg\_offset
1151   ieg = ieg - g%idg\_offset
1152   jeg = jeg - g%jdg\_offset
1153 
1154   \textcolor{comment}{! This is the i-extent of the segment on this PE.}
1155   \textcolor{comment}{! The values are nonsense if the segment is not on this PE.}
1156   seg%HI%IsdB = min(max(isgb, g%HI%IsdB), g%HI%IedB)
1157   seg%HI%IedB = min(max(iegb, g%HI%IsdB), g%HI%IedB)
1158   seg%HI%isd = min(max(isg, g%HI%isd), g%HI%ied)
1159   seg%HI%ied = min(max(ieg, g%HI%isd), g%HI%ied)
1160   seg%HI%IscB = min(max(isgb, g%HI%IscB), g%HI%IecB)
1161   seg%HI%IecB = min(max(iegb, g%HI%IscB), g%HI%IecB)
1162   seg%HI%isc = min(max(isg, g%HI%isc), g%HI%iec)
1163   seg%HI%iec = min(max(ieg, g%HI%isc), g%HI%iec)
1164 
1165   \textcolor{comment}{! This is the j-extent of the segment on this PE.}
1166   \textcolor{comment}{! The values are nonsense if the segment is not on this PE.}
1167   seg%HI%JsdB = min(max(jsgb, g%HI%JsdB), g%HI%JedB)
1168   seg%HI%JedB = min(max(jegb, g%HI%JsdB), g%HI%JedB)
1169   seg%HI%jsd = min(max(jsg, g%HI%jsd), g%HI%jed)
1170   seg%HI%jed = min(max(jeg, g%HI%jsd), g%HI%jed)
1171   seg%HI%JscB = min(max(jsgb, g%HI%JscB), g%HI%JecB)
1172   seg%HI%JecB = min(max(jegb, g%HI%JscB), g%HI%JecB)
1173   seg%HI%jsc = min(max(jsg, g%HI%jsc), g%HI%jec)
1174   seg%HI%jec = min(max(jeg, g%HI%jsc), g%HI%jec)
1175 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_aa40e3464225d4e017b1a738995eeb3b2}\label{namespacemom__open__boundary_aa40e3464225d4e017b1a738995eeb3b2}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!setup\+\_\+u\+\_\+point\+\_\+obc@{setup\+\_\+u\+\_\+point\+\_\+obc}}
\index{setup\+\_\+u\+\_\+point\+\_\+obc@{setup\+\_\+u\+\_\+point\+\_\+obc}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{setup\+\_\+u\+\_\+point\+\_\+obc()}{setup\_u\_point\_obc()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::setup\+\_\+u\+\_\+point\+\_\+obc (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{character(len=$\ast$), intent(in)}]{segment\+\_\+str,  }\item[{integer, intent(in)}]{l\+\_\+seg,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{PF,  }\item[{logical, intent(in)}]{reentrant\+\_\+y }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Parse an O\+B\+C\+\_\+\+S\+E\+G\+M\+E\+N\+T\+\_\+\%\%\% string starting with \char`\"{}\+I=\char`\"{} and configure placement and type of O\+BC accordingly. 


\begin{DoxyParams}[1]{Parameters}
 & {\em obc} & Open boundary control structure\\
\hline
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em segment\+\_\+str} & A string in form of \char`\"{}\+I=\%,\+J=\%\+:\%,string\char`\"{}\\
\hline
\mbox{\tt in}  & {\em l\+\_\+seg} & which segment is this?\\
\hline
\mbox{\tt in}  & {\em pf} & Parameter file handle\\
\hline
\mbox{\tt in}  & {\em reentrant\+\_\+y} & is the domain reentrant in y? \\
\hline
\end{DoxyParams}


Definition at line 1180 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
1180   \textcolor{keywordtype}{type}(ocean\_obc\_type),    \textcolor{keywordtype}{pointer}    :: obc\textcolor{comment}{ !< Open boundary control structure}
1181   \textcolor{keywordtype}{type}(dyn\_horgrid\_type),  \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{   !< Ocean grid structure}
1182   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)} :: us\textcolor{comment}{  !< A dimensional unit scaling type}
1183   \textcolor{keywordtype}{character(len=*)},        \textcolor{keywordtype}{intent(in)} :: segment\_str\textcolor{comment}{ !< A string in form of "I=%,J=%:%,string"}
1184   \textcolor{keywordtype}{integer},                 \textcolor{keywordtype}{intent(in)} :: l\_seg\textcolor{comment}{ !< which segment is this?}
1185   \textcolor{keywordtype}{type}(param\_file\_type), \textcolor{keywordtype}{intent(in)}   :: pf\textcolor{comment}{  !< Parameter file handle}
1186   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{intent(in)}                 :: reentrant\_y\textcolor{comment}{ !< is the domain reentrant in y?}
1187   \textcolor{comment}{! Local variables}
1188   \textcolor{keywordtype}{integer} :: i\_obc, js\_obc, je\_obc \textcolor{comment}{! Position of segment in global index space}
1189   \textcolor{keywordtype}{integer} :: j, a\_loop
1190   \textcolor{keywordtype}{character(len=32)} :: action\_str(8)
1191   \textcolor{keywordtype}{character(len=128)} :: segment\_param\_str
1192   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)}  :: tnudge
1193   \textcolor{comment}{! This returns the global indices for the segment}
1194   \textcolor{keyword}{call }parse\_segment\_str(g%ieg, g%jeg, segment\_str, i\_obc, js\_obc, je\_obc, action\_str, reentrant\_y)
1195 
1196   \textcolor{keyword}{call }setup\_segment\_indices(g, obc%segment(l\_seg),i\_obc,i\_obc,js\_obc,je\_obc)
1197 
1198   i\_obc = i\_obc - g%idg\_offset \textcolor{comment}{! Convert to local tile indices on this tile}
1199   js\_obc = js\_obc - g%jdg\_offset \textcolor{comment}{! Convert to local tile indices on this tile}
1200   je\_obc = je\_obc - g%jdg\_offset \textcolor{comment}{! Convert to local tile indices on this tile}
1201 
1202   \textcolor{keywordflow}{if} (je\_obc>js\_obc) \textcolor{keywordflow}{then}
1203     obc%segment(l\_seg)%direction = obc\_direction\_e
1204   \textcolor{keywordflow}{elseif} (je\_obc<js\_obc) \textcolor{keywordflow}{then}
1205     obc%segment(l\_seg)%direction = obc\_direction\_w
1206     j=js\_obc;js\_obc=je\_obc;je\_obc=j
1207 \textcolor{keywordflow}{  endif}
1208 
1209   obc%segment(l\_seg)%on\_pe = .false.
1210 
1211   \textcolor{keywordflow}{do} a\_loop = 1,8 \textcolor{comment}{! up to 8 options available}
1212     \textcolor{keywordflow}{if} (len\_trim(action\_str(a\_loop)) == 0) \textcolor{keywordflow}{then}
1213       cycle
1214     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'FLATHER'}) \textcolor{keywordflow}{then}
1215       obc%segment(l\_seg)%Flather = .true.
1216       obc%segment(l\_seg)%open = .true.
1217       obc%Flather\_u\_BCs\_exist\_globally = .true.
1218       obc%open\_u\_BCs\_exist\_globally = .true.
1219       obc%segment(l\_seg)%z\_values\_needed = .true.
1220       obc%segment(l\_seg)%u\_values\_needed = .true.
1221     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'ORLANSKI'}) \textcolor{keywordflow}{then}
1222       obc%segment(l\_seg)%radiation = .true.
1223       obc%segment(l\_seg)%open = .true.
1224       obc%open\_u\_BCs\_exist\_globally = .true.
1225       obc%radiation\_BCs\_exist\_globally = .true.
1226     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'ORLANSKI\_TAN'}) \textcolor{keywordflow}{then}
1227       obc%segment(l\_seg)%radiation = .true.
1228       obc%segment(l\_seg)%radiation\_tan = .true.
1229       obc%radiation\_BCs\_exist\_globally = .true.
1230     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'ORLANSKI\_GRAD'}) \textcolor{keywordflow}{then}
1231       obc%segment(l\_seg)%radiation = .true.
1232       obc%segment(l\_seg)%radiation\_grad = .true.
1233     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'OBLIQUE'}) \textcolor{keywordflow}{then}
1234       obc%segment(l\_seg)%oblique = .true.
1235       obc%segment(l\_seg)%open = .true.
1236       obc%oblique\_BCs\_exist\_globally = .true.
1237       obc%open\_u\_BCs\_exist\_globally = .true.
1238     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'OBLIQUE\_TAN'}) \textcolor{keywordflow}{then}
1239       obc%segment(l\_seg)%oblique = .true.
1240       obc%segment(l\_seg)%oblique\_tan = .true.
1241       obc%oblique\_BCs\_exist\_globally = .true.
1242     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'OBLIQUE\_GRAD'}) \textcolor{keywordflow}{then}
1243       obc%segment(l\_seg)%oblique = .true.
1244       obc%segment(l\_seg)%oblique\_grad = .true.
1245     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'NUDGED'}) \textcolor{keywordflow}{then}
1246       obc%segment(l\_seg)%nudged = .true.
1247       obc%nudged\_u\_BCs\_exist\_globally = .true.
1248       obc%segment(l\_seg)%u\_values\_needed = .true.
1249     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'NUDGED\_TAN'}) \textcolor{keywordflow}{then}
1250       obc%segment(l\_seg)%nudged\_tan = .true.
1251       obc%nudged\_u\_BCs\_exist\_globally = .true.
1252       obc%segment(l\_seg)%v\_values\_needed = .true.
1253     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'NUDGED\_GRAD'}) \textcolor{keywordflow}{then}
1254       obc%segment(l\_seg)%nudged\_grad = .true.
1255       obc%segment(l\_seg)%g\_values\_needed = .true.
1256     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'GRADIENT'}) \textcolor{keywordflow}{then}
1257       obc%segment(l\_seg)%gradient = .true.
1258       obc%segment(l\_seg)%open = .true.
1259       obc%open\_u\_BCs\_exist\_globally = .true.
1260     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'SIMPLE'}) \textcolor{keywordflow}{then}
1261       obc%segment(l\_seg)%specified = .true.
1262       obc%specified\_u\_BCs\_exist\_globally = .true. \textcolor{comment}{! This avoids deallocation}
1263       obc%segment(l\_seg)%u\_values\_needed = .true.
1264     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'SIMPLE\_TAN'}) \textcolor{keywordflow}{then}
1265       obc%segment(l\_seg)%specified\_tan = .true.
1266       obc%segment(l\_seg)%v\_values\_needed = .true.
1267     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'SIMPLE\_GRAD'}) \textcolor{keywordflow}{then}
1268       obc%segment(l\_seg)%specified\_grad = .true.
1269       obc%segment(l\_seg)%g\_values\_needed = .true.
1270     \textcolor{keywordflow}{else}
1271       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, setup\_u\_point\_obc: "}//&
1272                      \textcolor{stringliteral}{"String '"}//trim(action\_str(a\_loop))//\textcolor{stringliteral}{"' not understood."})
1273 \textcolor{keywordflow}{    endif}
1274     \textcolor{keywordflow}{if} (obc%segment(l\_seg)%nudged .or. obc%segment(l\_seg)%nudged\_tan) \textcolor{keywordflow}{then}
1275       \textcolor{keyword}{write}(segment\_param\_str(1:43),\textcolor{stringliteral}{"('OBC\_SEGMENT\_',i3.3,'\_VELOCITY\_NUDGING\_TIMESCALES')"}) l\_seg
1276       \textcolor{keyword}{allocate}(tnudge(2))
1277       \textcolor{keyword}{call }get\_param(pf, mdl, segment\_param\_str(1:43), tnudge, &
1278                      \textcolor{stringliteral}{"Timescales in days for nudging along a segment, "}//&
1279                      \textcolor{stringliteral}{"for inflow, then outflow. Setting both to zero should "}//&
1280                      \textcolor{stringliteral}{"behave like SIMPLE obcs for the baroclinic velocities."}, &
1281                      fail\_if\_missing=.true., default=0., units=\textcolor{stringliteral}{"days"}, scale=86400.0*us%s\_to\_T)
1282       obc%segment(l\_seg)%Velocity\_nudging\_timescale\_in = tnudge(1)
1283       obc%segment(l\_seg)%Velocity\_nudging\_timescale\_out = tnudge(2)
1284       \textcolor{keyword}{deallocate}(tnudge)
1285 \textcolor{keywordflow}{    endif}
1286 
1287 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! a\_loop}
1288 
1289   obc%segment(l\_seg)%is\_E\_or\_W\_2 = .true.
1290 
1291   \textcolor{keywordflow}{if} (i\_obc<=g%HI%IsdB+1 .or. i\_obc>=g%HI%IedB-1) \textcolor{keywordflow}{return} \textcolor{comment}{! Boundary is not on tile}
1292   \textcolor{keywordflow}{if} (je\_obc<=g%HI%JsdB .or. js\_obc>=g%HI%JedB) \textcolor{keywordflow}{return} \textcolor{comment}{! Segment is not on tile}
1293 
1294   obc%segment(l\_seg)%on\_pe = .true.
1295   obc%segment(l\_seg)%is\_E\_or\_W = .true.
1296 
1297   \textcolor{keywordflow}{do} j=g%HI%jsd, g%HI%jed
1298     \textcolor{keywordflow}{if} (j>js\_obc .and. j<=je\_obc) \textcolor{keywordflow}{then}
1299       obc%segnum\_u(i\_obc,j) = l\_seg
1300 \textcolor{keywordflow}{    endif}
1301 \textcolor{keywordflow}{  enddo}
1302   obc%segment(l\_seg)%Is\_obc = i\_obc
1303   obc%segment(l\_seg)%Ie\_obc = i\_obc
1304   obc%segment(l\_seg)%Js\_obc = js\_obc
1305   obc%segment(l\_seg)%Je\_obc = je\_obc
1306   \textcolor{keyword}{call }allocate\_obc\_segment\_data(obc, obc%segment(l\_seg))
1307 
1308   \textcolor{keywordflow}{if} (obc%segment(l\_seg)%oblique .and.  obc%segment(l\_seg)%radiation) &
1309          \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, setup\_u\_point\_obc: \(\backslash\)n"}//&
1310          \textcolor{stringliteral}{"Orlanski and Oblique OBC options cannot be used together on one segment."})
1311 
1312   \textcolor{keywordflow}{if} (obc%segment(l\_seg)%u\_values\_needed .or. obc%segment(l\_seg)%v\_values\_needed .or. &
1313       obc%segment(l\_seg)%t\_values\_needed .or. obc%segment(l\_seg)%s\_values\_needed .or. &
1314       obc%segment(l\_seg)%z\_values\_needed .or. obc%segment(l\_seg)%g\_values\_needed) &
1315     obc%segment(l\_seg)%values\_needed = .true.
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a706dd2fb2049757b3b76bf8b481e735c}\label{namespacemom__open__boundary_a706dd2fb2049757b3b76bf8b481e735c}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!setup\+\_\+v\+\_\+point\+\_\+obc@{setup\+\_\+v\+\_\+point\+\_\+obc}}
\index{setup\+\_\+v\+\_\+point\+\_\+obc@{setup\+\_\+v\+\_\+point\+\_\+obc}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{setup\+\_\+v\+\_\+point\+\_\+obc()}{setup\_v\_point\_obc()}}
{\footnotesize\ttfamily subroutine mom\+\_\+open\+\_\+boundary\+::setup\+\_\+v\+\_\+point\+\_\+obc (\begin{DoxyParamCaption}\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{type(dyn\+\_\+horgrid\+\_\+type), intent(in)}]{G,  }\item[{type(unit\+\_\+scale\+\_\+type), intent(in)}]{US,  }\item[{character(len=$\ast$), intent(in)}]{segment\+\_\+str,  }\item[{integer, intent(in)}]{l\+\_\+seg,  }\item[{type(param\+\_\+file\+\_\+type), intent(in)}]{PF,  }\item[{logical, intent(in)}]{reentrant\+\_\+x }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Parse an O\+B\+C\+\_\+\+S\+E\+G\+M\+E\+N\+T\+\_\+\%\%\% string starting with \char`\"{}\+J=\char`\"{} and configure placement and type of O\+BC accordingly. 


\begin{DoxyParams}[1]{Parameters}
 & {\em obc} & Open boundary control structure\\
\hline
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
\mbox{\tt in}  & {\em segment\+\_\+str} & A string in form of \char`\"{}\+J=\%,\+I=\%\+:\%,string\char`\"{}\\
\hline
\mbox{\tt in}  & {\em l\+\_\+seg} & which segment is this?\\
\hline
\mbox{\tt in}  & {\em pf} & Parameter file handle\\
\hline
\mbox{\tt in}  & {\em reentrant\+\_\+x} & is the domain reentrant in x? \\
\hline
\end{DoxyParams}


Definition at line 1320 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
1320   \textcolor{keywordtype}{type}(ocean\_obc\_type),    \textcolor{keywordtype}{pointer}    :: obc\textcolor{comment}{ !< Open boundary control structure}
1321   \textcolor{keywordtype}{type}(dyn\_horgrid\_type),  \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{   !< Ocean grid structure}
1322   \textcolor{keywordtype}{type}(unit\_scale\_type),   \textcolor{keywordtype}{intent(in)} :: us\textcolor{comment}{  !< A dimensional unit scaling type}
1323   \textcolor{keywordtype}{character(len=*)},        \textcolor{keywordtype}{intent(in)} :: segment\_str\textcolor{comment}{ !< A string in form of "J=%,I=%:%,string"}
1324   \textcolor{keywordtype}{integer},                 \textcolor{keywordtype}{intent(in)} :: l\_seg\textcolor{comment}{ !< which segment is this?}
1325   \textcolor{keywordtype}{type}(param\_file\_type),   \textcolor{keywordtype}{intent(in)} :: pf\textcolor{comment}{  !< Parameter file handle}
1326   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{intent(in)}                 :: reentrant\_x\textcolor{comment}{ !< is the domain reentrant in x?}
1327   \textcolor{comment}{! Local variables}
1328   \textcolor{keywordtype}{integer} :: j\_obc, is\_obc, ie\_obc \textcolor{comment}{! Position of segment in global index space}
1329   \textcolor{keywordtype}{integer} :: i, a\_loop
1330   \textcolor{keywordtype}{character(len=32)} :: action\_str(8)
1331   \textcolor{keywordtype}{character(len=128)} :: segment\_param\_str
1332   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:)}  :: tnudge
1333 
1334   \textcolor{comment}{! This returns the global indices for the segment}
1335   \textcolor{keyword}{call }parse\_segment\_str(g%ieg, g%jeg, segment\_str, j\_obc, is\_obc, ie\_obc, action\_str, reentrant\_x)
1336 
1337   \textcolor{keyword}{call }setup\_segment\_indices(g, obc%segment(l\_seg),is\_obc,ie\_obc,j\_obc,j\_obc)
1338 
1339   j\_obc = j\_obc - g%jdg\_offset \textcolor{comment}{! Convert to local tile indices on this tile}
1340   is\_obc = is\_obc - g%idg\_offset \textcolor{comment}{! Convert to local tile indices on this tile}
1341   ie\_obc = ie\_obc - g%idg\_offset \textcolor{comment}{! Convert to local tile indices on this tile}
1342 
1343   \textcolor{keywordflow}{if} (ie\_obc>is\_obc) \textcolor{keywordflow}{then}
1344      obc%segment(l\_seg)%direction = obc\_direction\_s
1345   \textcolor{keywordflow}{elseif} (ie\_obc<is\_obc) \textcolor{keywordflow}{then}
1346      obc%segment(l\_seg)%direction = obc\_direction\_n
1347      i=is\_obc;is\_obc=ie\_obc;ie\_obc=i
1348 \textcolor{keywordflow}{  endif}
1349 
1350   obc%segment(l\_seg)%on\_pe = .false.
1351 
1352   \textcolor{keywordflow}{do} a\_loop = 1,8
1353     \textcolor{keywordflow}{if} (len\_trim(action\_str(a\_loop)) == 0) \textcolor{keywordflow}{then}
1354       cycle
1355     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'FLATHER'}) \textcolor{keywordflow}{then}
1356       obc%segment(l\_seg)%Flather = .true.
1357       obc%segment(l\_seg)%open = .true.
1358       obc%Flather\_v\_BCs\_exist\_globally = .true.
1359       obc%open\_v\_BCs\_exist\_globally = .true.
1360       obc%segment(l\_seg)%z\_values\_needed = .true.
1361       obc%segment(l\_seg)%v\_values\_needed = .true.
1362     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'ORLANSKI'}) \textcolor{keywordflow}{then}
1363       obc%segment(l\_seg)%radiation = .true.
1364       obc%segment(l\_seg)%open = .true.
1365       obc%open\_v\_BCs\_exist\_globally = .true.
1366       obc%radiation\_BCs\_exist\_globally = .true.
1367     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'ORLANSKI\_TAN'}) \textcolor{keywordflow}{then}
1368       obc%segment(l\_seg)%radiation = .true.
1369       obc%segment(l\_seg)%radiation\_tan = .true.
1370       obc%radiation\_BCs\_exist\_globally = .true.
1371     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'ORLANSKI\_GRAD'}) \textcolor{keywordflow}{then}
1372       obc%segment(l\_seg)%radiation = .true.
1373       obc%segment(l\_seg)%radiation\_grad = .true.
1374     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'OBLIQUE'}) \textcolor{keywordflow}{then}
1375       obc%segment(l\_seg)%oblique = .true.
1376       obc%segment(l\_seg)%open = .true.
1377       obc%oblique\_BCs\_exist\_globally = .true.
1378       obc%open\_v\_BCs\_exist\_globally = .true.
1379     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'OBLIQUE\_TAN'}) \textcolor{keywordflow}{then}
1380       obc%segment(l\_seg)%oblique = .true.
1381       obc%segment(l\_seg)%oblique\_tan = .true.
1382       obc%oblique\_BCs\_exist\_globally = .true.
1383     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'OBLIQUE\_GRAD'}) \textcolor{keywordflow}{then}
1384       obc%segment(l\_seg)%oblique = .true.
1385       obc%segment(l\_seg)%oblique\_grad = .true.
1386     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'NUDGED'}) \textcolor{keywordflow}{then}
1387       obc%segment(l\_seg)%nudged = .true.
1388       obc%nudged\_v\_BCs\_exist\_globally = .true.
1389       obc%segment(l\_seg)%v\_values\_needed = .true.
1390     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'NUDGED\_TAN'}) \textcolor{keywordflow}{then}
1391       obc%segment(l\_seg)%nudged\_tan = .true.
1392       obc%nudged\_v\_BCs\_exist\_globally = .true.
1393       obc%segment(l\_seg)%u\_values\_needed = .true.
1394     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'NUDGED\_GRAD'}) \textcolor{keywordflow}{then}
1395       obc%segment(l\_seg)%nudged\_grad = .true.
1396       obc%segment(l\_seg)%g\_values\_needed = .true.
1397     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'GRADIENT'}) \textcolor{keywordflow}{then}
1398       obc%segment(l\_seg)%gradient = .true.
1399       obc%segment(l\_seg)%open = .true.
1400       obc%open\_v\_BCs\_exist\_globally = .true.
1401     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'SIMPLE'}) \textcolor{keywordflow}{then}
1402       obc%segment(l\_seg)%specified = .true.
1403       obc%specified\_v\_BCs\_exist\_globally = .true. \textcolor{comment}{! This avoids deallocation}
1404       obc%segment(l\_seg)%v\_values\_needed = .true.
1405     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'SIMPLE\_TAN'}) \textcolor{keywordflow}{then}
1406       obc%segment(l\_seg)%specified\_tan = .true.
1407       obc%segment(l\_seg)%u\_values\_needed = .true.
1408     \textcolor{keywordflow}{elseif} (trim(action\_str(a\_loop)) == \textcolor{stringliteral}{'SIMPLE\_GRAD'}) \textcolor{keywordflow}{then}
1409       obc%segment(l\_seg)%specified\_grad = .true.
1410       obc%segment(l\_seg)%g\_values\_needed = .true.
1411     \textcolor{keywordflow}{else}
1412       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, setup\_v\_point\_obc: "}//&
1413                      \textcolor{stringliteral}{"String '"}//trim(action\_str(a\_loop))//\textcolor{stringliteral}{"' not understood."})
1414 \textcolor{keywordflow}{    endif}
1415     \textcolor{keywordflow}{if} (obc%segment(l\_seg)%nudged .or. obc%segment(l\_seg)%nudged\_tan) \textcolor{keywordflow}{then}
1416       \textcolor{keyword}{write}(segment\_param\_str(1:43),\textcolor{stringliteral}{"('OBC\_SEGMENT\_',i3.3,'\_VELOCITY\_NUDGING\_TIMESCALES')"}) l\_seg
1417       \textcolor{keyword}{allocate}(tnudge(2))
1418       \textcolor{keyword}{call }get\_param(pf, mdl, segment\_param\_str(1:43), tnudge, &
1419                      \textcolor{stringliteral}{"Timescales in days for nudging along a segment, "}//&
1420                      \textcolor{stringliteral}{"for inflow, then outflow. Setting both to zero should "}//&
1421                      \textcolor{stringliteral}{"behave like SIMPLE obcs for the baroclinic velocities."}, &
1422                      fail\_if\_missing=.true., default=0., units=\textcolor{stringliteral}{"days"}, scale=86400.0*us%s\_to\_T)
1423       obc%segment(l\_seg)%Velocity\_nudging\_timescale\_in = tnudge(1)
1424       obc%segment(l\_seg)%Velocity\_nudging\_timescale\_out = tnudge(2)
1425       \textcolor{keyword}{deallocate}(tnudge)
1426 \textcolor{keywordflow}{    endif}
1427 
1428 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! a\_loop}
1429 
1430   \textcolor{keywordflow}{if} (j\_obc<=g%HI%JsdB+1 .or. j\_obc>=g%HI%JedB-1) \textcolor{keywordflow}{return} \textcolor{comment}{! Boundary is not on tile}
1431   \textcolor{keywordflow}{if} (ie\_obc<=g%HI%IsdB .or. is\_obc>=g%HI%IedB) \textcolor{keywordflow}{return} \textcolor{comment}{! Segment is not on tile}
1432 
1433   obc%segment(l\_seg)%on\_pe = .true.
1434   obc%segment(l\_seg)%is\_N\_or\_S = .true.
1435 
1436   \textcolor{keywordflow}{do} i=g%HI%isd, g%HI%ied
1437     \textcolor{keywordflow}{if} (i>is\_obc .and. i<=ie\_obc) \textcolor{keywordflow}{then}
1438       obc%segnum\_v(i,j\_obc) = l\_seg
1439 \textcolor{keywordflow}{    endif}
1440 \textcolor{keywordflow}{  enddo}
1441   obc%segment(l\_seg)%Is\_obc = is\_obc
1442   obc%segment(l\_seg)%Ie\_obc = ie\_obc
1443   obc%segment(l\_seg)%Js\_obc = j\_obc
1444   obc%segment(l\_seg)%Je\_obc = j\_obc
1445   \textcolor{keyword}{call }allocate\_obc\_segment\_data(obc, obc%segment(l\_seg))
1446 
1447   \textcolor{keywordflow}{if} (obc%segment(l\_seg)%oblique .and.  obc%segment(l\_seg)%radiation) &
1448          \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"MOM\_open\_boundary.F90, setup\_v\_point\_obc: \(\backslash\)n"}//&
1449          \textcolor{stringliteral}{"Orlanski and Oblique OBC options cannot be used together on one segment."})
1450 
1451   \textcolor{keywordflow}{if} (obc%segment(l\_seg)%u\_values\_needed .or. obc%segment(l\_seg)%v\_values\_needed .or. &
1452       obc%segment(l\_seg)%t\_values\_needed .or. obc%segment(l\_seg)%s\_values\_needed .or. &
1453       obc%segment(l\_seg)%z\_values\_needed .or. obc%segment(l\_seg)%g\_values\_needed) &
1454     obc%segment(l\_seg)%values\_needed = .true.
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a2459650f97c35ba541246d1418efb6a1}\label{namespacemom__open__boundary_a2459650f97c35ba541246d1418efb6a1}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!update\+\_\+obc\+\_\+ramp@{update\+\_\+obc\+\_\+ramp}}
\index{update\+\_\+obc\+\_\+ramp@{update\+\_\+obc\+\_\+ramp}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{update\+\_\+obc\+\_\+ramp()}{update\_obc\_ramp()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::update\+\_\+obc\+\_\+ramp (\begin{DoxyParamCaption}\item[{type(time\+\_\+type), intent(in), target}]{Time,  }\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{logical, intent(in), optional}]{activate }\end{DoxyParamCaption})}



Update the O\+BC ramp value as a function of time. If called with the optional argument activate=.true., record the value of Time as the beginning of the ramp period. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em time} & Current model time\\
\hline
 & {\em obc} & Open boundary structure\\
\hline
\mbox{\tt in}  & {\em activate} & Specifiy whether to record the value of Time as the beginning of the ramp period \\
\hline
\end{DoxyParams}


Definition at line 4374 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
4374   \textcolor{keywordtype}{type}(time\_type), \textcolor{keywordtype}{target}, \textcolor{keywordtype}{intent(in)}    :: time\textcolor{comment}{     !< Current model time}
4375   \textcolor{keywordtype}{type}(ocean\_obc\_type),    \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{      !< Open boundary structure}
4376   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},       \textcolor{keywordtype}{intent(in)}    :: activate\textcolor{comment}{ !< Specifiy whether to record the value of}
4377 \textcolor{comment}{                                                     !! Time as the beginning of the ramp period}
4378 
4379   \textcolor{comment}{! Local variables}
4380   \textcolor{keywordtype}{real} :: deltatime, wghta
4381   \textcolor{keywordtype}{character(len=12)} :: msg
4382 
4383   \textcolor{keywordflow}{if} (.not. obc%ramp) \textcolor{keywordflow}{return} \textcolor{comment}{! This indicates the ramping is turned off}
4384 
4385   \textcolor{comment}{! We use the optional argument to indicate this Time should be recorded as the}
4386   \textcolor{comment}{! beginning of the ramp-up period.}
4387   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(activate)) \textcolor{keywordflow}{then}
4388     \textcolor{keywordflow}{if} (activate) \textcolor{keywordflow}{then}
4389       obc%ramp\_start\_time = time \textcolor{comment}{! Record the current time}
4390       obc%ramping\_is\_activated = .true.
4391       obc%trunc\_ramp\_time = obc%ramp\_timescale \textcolor{comment}{! times 3.0 for tanh}
4392 \textcolor{keywordflow}{    endif}
4393 \textcolor{keywordflow}{  endif}
4394   \textcolor{keywordflow}{if} (.not.obc%ramping\_is\_activated) \textcolor{keywordflow}{return}
4395   deltatime = max( 0., time\_type\_to\_real( time - obc%ramp\_start\_time ) )
4396   \textcolor{keywordflow}{if} (deltatime >= obc%trunc\_ramp\_time) \textcolor{keywordflow}{then}
4397     obc%ramp\_value = 1.0
4398     obc%ramp = .false. \textcolor{comment}{! This turns off ramping after this call}
4399   \textcolor{keywordflow}{else}
4400     wghta = min( 1., deltatime / obc%ramp\_timescale ) \textcolor{comment}{! Linear profile in time}
4401     \textcolor{comment}{!wghtA = wghtA*wghtA ! Convert linear profile to parabolic profile in time}
4402     \textcolor{comment}{!wghtA = wghtA*wghtA*(3. - 2.*wghtA) ! Convert linear profile to cosine profile}
4403     \textcolor{comment}{!wghtA = 1. - ( (1. - wghtA)**2 ) ! Convert linear profile to inverted parabolic profile}
4404     \textcolor{comment}{!wghtA = tanh(wghtA)              ! Convert linear profile to tanh}
4405     obc%ramp\_value = wghta
4406 \textcolor{keywordflow}{  endif}
4407   \textcolor{keyword}{write}(msg(1:12),\textcolor{stringliteral}{'(es12.3)'}) obc%ramp\_value
4408   \textcolor{keyword}{call }mom\_error(note, \textcolor{stringliteral}{"MOM\_open\_boundary: update\_OBC\_ramp set OBC"}// &
4409                        \textcolor{stringliteral}{" ramp to "}//trim(msg))
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a8d2c8b028b9fc7d65f17155497a0487d}\label{namespacemom__open__boundary_a8d2c8b028b9fc7d65f17155497a0487d}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!update\+\_\+obc\+\_\+segment\+\_\+data@{update\+\_\+obc\+\_\+segment\+\_\+data}}
\index{update\+\_\+obc\+\_\+segment\+\_\+data@{update\+\_\+obc\+\_\+segment\+\_\+data}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{update\+\_\+obc\+\_\+segment\+\_\+data()}{update\_obc\_segment\_data()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::update\+\_\+obc\+\_\+segment\+\_\+data (\begin{DoxyParamCaption}\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(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{type(thermo\+\_\+var\+\_\+ptrs), intent(in)}]{tv,  }\item[{real, dimension( g \%isd\+: g \%ied, g \%jsd\+: g \%jed,  g \%ke), intent(inout)}]{h,  }\item[{type(time\+\_\+type), intent(in)}]{Time }\end{DoxyParamCaption})}



Update the O\+BC values on the segments. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & Ocean grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & Ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em us} & A dimensional unit scaling type\\
\hline
 & {\em obc} & Open boundary structure\\
\hline
\mbox{\tt in}  & {\em tv} & Thermodynamics structure\\
\hline
\mbox{\tt in,out}  & {\em h} & Thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
\mbox{\tt in}  & {\em time} & Model time \\
\hline
\end{DoxyParams}


Definition at line 3732 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
3732   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)}    :: g\textcolor{comment}{    !< Ocean grid structure}
3733   \textcolor{keywordtype}{type}(verticalgrid\_type),                   \textcolor{keywordtype}{intent(in)}    :: gv\textcolor{comment}{   !<  Ocean vertical grid structure}
3734   \textcolor{keywordtype}{type}(unit\_scale\_type),                     \textcolor{keywordtype}{intent(in)}    :: us\textcolor{comment}{   !< A dimensional unit scaling type}
3735   \textcolor{keywordtype}{type}(ocean\_obc\_type),                      \textcolor{keywordtype}{pointer}       :: obc\textcolor{comment}{  !< Open boundary structure}
3736   \textcolor{keywordtype}{type}(thermo\_var\_ptrs),                     \textcolor{keywordtype}{intent(in)}    :: tv\textcolor{comment}{   !< Thermodynamics structure}
3737   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G), SZK\_(G))}, \textcolor{keywordtype}{intent(inout)} :: h\textcolor{comment}{    !< Thickness [H ~> m or kg m-2]}
3738   \textcolor{keywordtype}{type}(time\_type),                           \textcolor{keywordtype}{intent(in)}    :: time\textcolor{comment}{ !< Model time}
3739   \textcolor{comment}{! Local variables}
3740   \textcolor{keywordtype}{integer} :: c, i, j, k, is, ie, js, je, isd, ied, jsd, jed
3741   \textcolor{keywordtype}{integer} :: isdb, iedb, jsdb, jedb, n, m, nz
3742   \textcolor{keywordtype}{character(len=40)}  :: mdl = \textcolor{stringliteral}{"update\_OBC\_segment\_data"} \textcolor{comment}{! This subroutine's name.}
3743   \textcolor{keywordtype}{character(len=200)} :: filename, obc\_file, inputdir \textcolor{comment}{! Strings for file/path}
3744   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment => null()
3745   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(4)} :: siz
3746   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{pointer} :: tmp\_buffer\_in => null()  \textcolor{comment}{! Unrotated input}
3747   \textcolor{keywordtype}{integer} :: ni\_seg, nj\_seg  \textcolor{comment}{! number of src gridpoints along the segments}
3748   \textcolor{keywordtype}{integer} :: ni\_buf, nj\_buf  \textcolor{comment}{! Number of filled values in tmp\_buffer}
3749   \textcolor{keywordtype}{integer} :: i2, j2          \textcolor{comment}{! indices for referencing local domain array}
3750   \textcolor{keywordtype}{integer} :: is\_obc, ie\_obc, js\_obc, je\_obc  \textcolor{comment}{! segment indices within local domain}
3751   \textcolor{keywordtype}{integer} :: ishift, jshift  \textcolor{comment}{! offsets for staggered locations}
3752   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer} :: seg\_vel => null()  \textcolor{comment}{! pointer to segment velocity array}
3753   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{pointer} :: seg\_trans => null()  \textcolor{comment}{! pointer to segment transport array}
3754   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:,:)}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{target} :: tmp\_buffer
3755   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{allocatable} :: h\_stack
3756   \textcolor{keywordtype}{integer} :: is\_obc2, js\_obc2
3757   \textcolor{keywordtype}{real} :: net\_h\_src, net\_h\_int, scl\_fac
3758   \textcolor{keywordtype}{real} :: tidal\_vel, tidal\_elev
3759   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{pointer}, \textcolor{keywordtype}{dimension(:,:)}   :: normal\_trans\_bt=>null() \textcolor{comment}{! barotropic transport}
3760   \textcolor{keywordtype}{integer} :: turns      \textcolor{comment}{! Number of index quarter turns}
3761   \textcolor{keywordtype}{real} :: time\_delta  \textcolor{comment}{! Time since tidal reference date}
3762 
3763   is = g%isc ; ie = g%iec ; js = g%jsc ; je = g%jec
3764   isd = g%isd ; ied = g%ied ; jsd = g%jsd ; jed = g%jed
3765   isdb = g%IsdB ; iedb = g%IedB ; jsdb = g%JsdB ; jedb = g%JedB
3766   nz=g%ke
3767 
3768   turns = g%HI%turns
3769 
3770   \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{return}
3771 
3772   \textcolor{keywordflow}{if} (obc%add\_tide\_constituents) time\_delta = time\_type\_to\_real(time - obc%time\_ref)
3773 
3774   \textcolor{keywordflow}{do} n = 1, obc%number\_of\_segments
3775     segment => obc%segment(n)
3776 
3777     \textcolor{keywordflow}{if} (.not. segment%on\_pe) cycle \textcolor{comment}{! continue to next segment if not in computational domain}
3778 
3779     \textcolor{comment}{! NOTE: These are in segment%HI, but defined slightly differently}
3780     ni\_seg = segment%ie\_obc-segment%is\_obc+1
3781     nj\_seg = segment%je\_obc-segment%js\_obc+1
3782     is\_obc = max(segment%is\_obc,isd-1)
3783     ie\_obc = min(segment%ie\_obc,ied)
3784     js\_obc = max(segment%js\_obc,jsd-1)
3785     je\_obc = min(segment%je\_obc,jed)
3786 
3787 \textcolor{comment}{! Calculate auxiliary fields at staggered locations.}
3788 \textcolor{comment}{! Segment indices are on q points:}
3789 \textcolor{comment}{!}
3790 \textcolor{comment}{!       |-----------|------------|-----------|-----------|  J\_obc}
3791 \textcolor{comment}{!     Is\_obc                                          Ie\_obc}
3792 \textcolor{comment}{!}
3793 \textcolor{comment}{! i2 has to start at Is\_obc+1 and end at Ie\_obc.}
3794 \textcolor{comment}{! j2 is J\_obc and jshift has to be +1 at both the north and south.}
3795 
3796      \textcolor{comment}{! calculate auxiliary fields at staggered locations}
3797     ishift=0;jshift=0
3798     \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
3799       \textcolor{keyword}{allocate}(normal\_trans\_bt(segment%HI%IsdB:segment%HI%IedB,segment%HI%jsd:segment%HI%jed))
3800       normal\_trans\_bt(:,:)=0.0
3801       \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_w) ishift=1
3802       i=segment%HI%IsdB
3803       \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
3804         segment%Cg(i,j) = sqrt(gv%g\_prime(1)*g%bathyT(i+ishift,j))
3805         segment%Htot(i,j)=0.0
3806         \textcolor{keywordflow}{do} k=1,g%ke
3807           segment%h(i,j,k) = h(i+ishift,j,k)
3808           segment%Htot(i,j)=segment%Htot(i,j)+segment%h(i,j,k)
3809 \textcolor{keywordflow}{        enddo}
3810 \textcolor{keywordflow}{      enddo}
3811     else\textcolor{comment}{! (segment%direction == OBC\_DIRECTION\_N .or. segment%direction == OBC\_DIRECTION\_S)}
3812       \textcolor{keyword}{allocate}(normal\_trans\_bt(segment%HI%isd:segment%HI%ied,segment%HI%JsdB:segment%HI%JedB))
3813       normal\_trans\_bt(:,:)=0.0
3814       \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_s) jshift=1
3815       j=segment%HI%JsdB
3816       \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
3817         segment%Cg(i,j) = sqrt(gv%g\_prime(1)*g%bathyT(i,j+jshift))
3818         segment%Htot(i,j)=0.0
3819         \textcolor{keywordflow}{do} k=1,g%ke
3820           segment%h(i,j,k) = h(i,j+jshift,k)
3821           segment%Htot(i,j)=segment%Htot(i,j)+segment%h(i,j,k)
3822 \textcolor{keywordflow}{        enddo}
3823 \textcolor{keywordflow}{      enddo}
3824 \textcolor{keywordflow}{    endif}
3825 
3826     \textcolor{keyword}{allocate}(h\_stack(g%ke))
3827     h\_stack(:) = 0.0
3828     \textcolor{keywordflow}{do} m = 1,segment%num\_fields
3829       \textcolor{keywordflow}{if} (segment%field(m)%fid > 0) \textcolor{keywordflow}{then}
3830         siz(1)=\textcolor{keyword}{size}(segment%field(m)%buffer\_src,1)
3831         siz(2)=\textcolor{keyword}{size}(segment%field(m)%buffer\_src,2)
3832         siz(3)=\textcolor{keyword}{size}(segment%field(m)%buffer\_src,3)
3833         \textcolor{keywordflow}{if} (.not.\textcolor{keyword}{associated}(segment%field(m)%buffer\_dst)) \textcolor{keywordflow}{then}
3834           \textcolor{keywordflow}{if} (siz(3) /= segment%field(m)%nk\_src) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'nk\_src inconsistency'})
3835           \textcolor{keywordflow}{if} (segment%field(m)%nk\_src > 1) \textcolor{keywordflow}{then}
3836             \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
3837               \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'V'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DVDX'}) \textcolor{keywordflow}{then}
3838                 \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc:je\_obc,g%ke))
3839               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Vamp'} .or. segment%field(m)%name == \textcolor{stringliteral}{'Vphase'}) \textcolor{keywordflow}{then}
3840                 \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc:je\_obc,siz(3))) \textcolor{comment}{! 3rd dim is
       constituent}
3841               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Uamp'} .or. segment%field(m)%name == \textcolor{stringliteral}{'Uphase'} .or. &
3842                   segment%field(m)%name == \textcolor{stringliteral}{'SSHamp'} .or. segment%field(m)%name == \textcolor{stringliteral}{'SSHphase'}) \textcolor{keywordflow}{then}
3843                 \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc+1:je\_obc,siz(3)))  \textcolor{comment}{! 3rd dim is
       constituent}
3844               \textcolor{keywordflow}{else}
3845                 \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc+1:je\_obc,g%ke))
3846 \textcolor{keywordflow}{              endif}
3847             \textcolor{keywordflow}{else}
3848               \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'U'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DUDY'}) \textcolor{keywordflow}{then}
3849                 \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc:je\_obc,g%ke))
3850               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Uamp'} .or. segment%field(m)%name == \textcolor{stringliteral}{'Uphase'}) \textcolor{keywordflow}{then}
3851                 \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc:je\_obc,siz(3))) \textcolor{comment}{! 3rd dim is
       constituent}
3852               \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Vamp'} .or. segment%field(m)%name == \textcolor{stringliteral}{'Vphase'} .or. &
3853                   segment%field(m)%name == \textcolor{stringliteral}{'SSHamp'} .or. segment%field(m)%name == \textcolor{stringliteral}{'SSHphase'}) \textcolor{keywordflow}{then}
3854                 \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc+1:ie\_obc,js\_obc:je\_obc,siz(3))) \textcolor{comment}{! 3rd dim is
       constituent}
3855               \textcolor{keywordflow}{else}
3856                 \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc+1:ie\_obc,js\_obc:je\_obc,g%ke))
3857 \textcolor{keywordflow}{              endif}
3858 \textcolor{keywordflow}{            endif}
3859           \textcolor{keywordflow}{else}
3860             \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
3861               \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'V'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DVDX'} .or. &
3862                   segment%field(m)%name == \textcolor{stringliteral}{'Vamp'} .or. segment%field(m)%name == \textcolor{stringliteral}{'Vphase'}) \textcolor{keywordflow}{then}
3863                 \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc:je\_obc,1))
3864               \textcolor{keywordflow}{else}
3865                 \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc+1:je\_obc,1))
3866 \textcolor{keywordflow}{              endif}
3867             \textcolor{keywordflow}{else}
3868               \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'U'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DUDY'} .or. &
3869                 segment%field(m)%name == \textcolor{stringliteral}{'Uamp'} .or. segment%field(m)%name == \textcolor{stringliteral}{'Uphase'}) \textcolor{keywordflow}{then}
3870                 \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc:je\_obc,1))
3871               \textcolor{keywordflow}{else}
3872                 \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc+1:ie\_obc,js\_obc:je\_obc,1))
3873 \textcolor{keywordflow}{              endif}
3874 \textcolor{keywordflow}{            endif}
3875 \textcolor{keywordflow}{          endif}
3876           segment%field(m)%buffer\_dst(:,:,:)=0.0
3877 \textcolor{keywordflow}{        endif}
3878         \textcolor{comment}{! read source data interpolated to the current model time}
3879         \textcolor{comment}{! NOTE: buffer is sized for vertex points, but may be used for faces}
3880         \textcolor{keywordflow}{if} (siz(1)==1) \textcolor{keywordflow}{then}
3881           \textcolor{keywordflow}{if} (obc%brushcutter\_mode) \textcolor{keywordflow}{then}
3882             \textcolor{keyword}{allocate}(tmp\_buffer(1,nj\_seg*2-1,segment%field(m)%nk\_src))  \textcolor{comment}{! segment data is currrently on
       supergrid}
3883           \textcolor{keywordflow}{else}
3884             \textcolor{keyword}{allocate}(tmp\_buffer(1,nj\_seg,segment%field(m)%nk\_src))  \textcolor{comment}{! segment data is currrently on
       supergrid}
3885 \textcolor{keywordflow}{          endif}
3886         \textcolor{keywordflow}{else}
3887           \textcolor{keywordflow}{if} (obc%brushcutter\_mode) \textcolor{keywordflow}{then}
3888             \textcolor{keyword}{allocate}(tmp\_buffer(ni\_seg*2-1,1,segment%field(m)%nk\_src))  \textcolor{comment}{! segment data is currrently on
       supergrid}
3889           \textcolor{keywordflow}{else}
3890             \textcolor{keyword}{allocate}(tmp\_buffer(ni\_seg,1,segment%field(m)%nk\_src))  \textcolor{comment}{! segment data is currrently on
       supergrid}
3891 \textcolor{keywordflow}{          endif}
3892 \textcolor{keywordflow}{        endif}
3893 
3894         \textcolor{comment}{! TODO: Since we conditionally rotate a subset of tmp\_buffer\_in after}
3895         \textcolor{comment}{!   reading the value, it is currently not possible to use the rotated}
3896         \textcolor{comment}{!   implementation of time\_interp\_external.}
3897         \textcolor{comment}{!   For now, we must explicitly allocate and rotate this array.}
3898         \textcolor{keywordflow}{if} (turns /= 0) \textcolor{keywordflow}{then}
3899           \textcolor{keywordflow}{if} (modulo(turns, 2) /= 0) \textcolor{keywordflow}{then}
3900             \textcolor{keyword}{allocate}(tmp\_buffer\_in(\textcolor{keyword}{size}(tmp\_buffer, 2), \textcolor{keyword}{size}(tmp\_buffer, 1), \textcolor{keyword}{size}(tmp\_buffer, 3)))
3901           \textcolor{keywordflow}{else}
3902             \textcolor{keyword}{allocate}(tmp\_buffer\_in(\textcolor{keyword}{size}(tmp\_buffer, 1), \textcolor{keyword}{size}(tmp\_buffer, 2), \textcolor{keyword}{size}(tmp\_buffer, 3)))
3903 \textcolor{keywordflow}{          endif}
3904         \textcolor{keywordflow}{else}
3905           tmp\_buffer\_in => tmp\_buffer
3906 \textcolor{keywordflow}{        endif}
3907 
3908         \textcolor{keyword}{call }time\_interp\_external(segment%field(m)%fid,time, tmp\_buffer\_in)
3909         \textcolor{comment}{! NOTE: Rotation of face-points require that we skip the final value}
3910         \textcolor{keywordflow}{if} (turns /= 0) \textcolor{keywordflow}{then}
3911           \textcolor{comment}{! TODO: This is hardcoded for 90 degrees, and needs to be generalized.}
3912           \textcolor{keywordflow}{if} (segment%is\_E\_or\_W &
3913               .and. .not. (segment%field(m)%name == \textcolor{stringliteral}{'V'} .or. segment%field(m)%name == \textcolor{stringliteral}{'Vamp'} &
3914                   .or. segment%field(m)%name == \textcolor{stringliteral}{'Vphase'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DVDX'})) \textcolor{keywordflow}{then}
3915             nj\_buf = \textcolor{keyword}{size}(tmp\_buffer, 2) - 1
3916             \textcolor{keyword}{call }rotate\_array(tmp\_buffer\_in(:nj\_buf,:,:), turns, tmp\_buffer(:,:nj\_buf,:))
3917           \textcolor{keywordflow}{elseif} (segment%is\_N\_or\_S &
3918               .and. .not. (segment%field(m)%name == \textcolor{stringliteral}{'U'} .or. segment%field(m)%name == \textcolor{stringliteral}{'Uamp'} &
3919                   .or. segment%field(m)%name == \textcolor{stringliteral}{'Uphase'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DUDY'})) \textcolor{keywordflow}{then}
3920             ni\_buf = \textcolor{keyword}{size}(tmp\_buffer, 1) - 1
3921             \textcolor{keyword}{call }rotate\_array(tmp\_buffer\_in(:,:ni\_buf,:), turns, tmp\_buffer(:ni\_buf,:,:))
3922           \textcolor{keywordflow}{else}
3923             \textcolor{keyword}{call }rotate\_array(tmp\_buffer\_in, turns, tmp\_buffer)
3924 \textcolor{keywordflow}{          endif}
3925 
3926           \textcolor{comment}{! TODO: This is hardcoded for 90 degrees, and needs to be generalized.}
3927           \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'U'} &
3928               .or. segment%field(m)%name == \textcolor{stringliteral}{'DVDX'} &
3929               .or. segment%field(m)%name == \textcolor{stringliteral}{'DUDY'} &
3930               .or. segment%field(m)%name == \textcolor{stringliteral}{'Uamp'}) \textcolor{keywordflow}{then}
3931             tmp\_buffer(:,:,:) = -tmp\_buffer(:,:,:)
3932 \textcolor{keywordflow}{          endif}
3933 \textcolor{keywordflow}{        endif}
3934 
3935         \textcolor{keywordflow}{if} (obc%brushcutter\_mode) \textcolor{keywordflow}{then}
3936           \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
3937             \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'V'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DVDX'} .or. &
3938                 segment%field(m)%name == \textcolor{stringliteral}{'Vamp'} .or. segment%field(m)%name == \textcolor{stringliteral}{'Vphase'}) \textcolor{keywordflow}{then}
3939               segment%field(m)%buffer\_src(is\_obc,:,:) = &
3940                   tmp\_buffer(1,2*(js\_obc+g%jdg\_offset)+1:2*(je\_obc+g%jdg\_offset)+1:2,:)
3941             \textcolor{keywordflow}{else}
3942               segment%field(m)%buffer\_src(is\_obc,:,:) = &
3943                   tmp\_buffer(1,2*(js\_obc+g%jdg\_offset)+1:2*(je\_obc+g%jdg\_offset):2,:)
3944 \textcolor{keywordflow}{            endif}
3945           \textcolor{keywordflow}{else}
3946             \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'U'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DUDY'} .or. &
3947                 segment%field(m)%name == \textcolor{stringliteral}{'Uamp'} .or. segment%field(m)%name == \textcolor{stringliteral}{'Uphase'}) \textcolor{keywordflow}{then}
3948               segment%field(m)%buffer\_src(:,js\_obc,:) = &
3949                   tmp\_buffer(2*(is\_obc+g%idg\_offset)+1:2*(ie\_obc+g%idg\_offset)+1:2,1,:)
3950             \textcolor{keywordflow}{else}
3951               segment%field(m)%buffer\_src(:,js\_obc,:) = &
3952                   tmp\_buffer(2*(is\_obc+g%idg\_offset)+1:2*(ie\_obc+g%idg\_offset):2,1,:)
3953 \textcolor{keywordflow}{            endif}
3954 \textcolor{keywordflow}{          endif}
3955         \textcolor{keywordflow}{else}
3956           \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
3957             \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'V'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DVDX'} .or. &
3958                 segment%field(m)%name == \textcolor{stringliteral}{'Vamp'} .or. segment%field(m)%name == \textcolor{stringliteral}{'Vphase'}) \textcolor{keywordflow}{then}
3959               segment%field(m)%buffer\_src(is\_obc,:,:)=tmp\_buffer(1,js\_obc+g%jdg\_offset+1:je\_obc+g
      %jdg\_offset+1,:)
3960             \textcolor{keywordflow}{else}
3961               segment%field(m)%buffer\_src(is\_obc,:,:)=tmp\_buffer(1,js\_obc+g%jdg\_offset+1:je\_obc+g
      %jdg\_offset,:)
3962 \textcolor{keywordflow}{            endif}
3963           \textcolor{keywordflow}{else}
3964             \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'U'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DUDY'} .or. &
3965                 segment%field(m)%name == \textcolor{stringliteral}{'Uamp'} .or. segment%field(m)%name == \textcolor{stringliteral}{'Uphase'}) \textcolor{keywordflow}{then}
3966               segment%field(m)%buffer\_src(:,js\_obc,:)=tmp\_buffer(is\_obc+g%idg\_offset+1:ie\_obc+g%idg\_offset+
      1,1,:)
3967             \textcolor{keywordflow}{else}
3968               segment%field(m)%buffer\_src(:,js\_obc,:)=tmp\_buffer(is\_obc+g%idg\_offset+1:ie\_obc+g%idg\_offset,
      1,:)
3969 \textcolor{keywordflow}{            endif}
3970 \textcolor{keywordflow}{          endif}
3971 \textcolor{keywordflow}{        endif}
3972         \textcolor{comment}{! no dz for tidal variables}
3973         \textcolor{keywordflow}{if} (segment%field(m)%nk\_src > 1 .and.&
3974             (index(segment%field(m)%name, \textcolor{stringliteral}{'phase'}) .le. 0 .and. index(segment%field(m)%name, \textcolor{stringliteral}{'amp'}) .le. 0)
      ) \textcolor{keywordflow}{then}
3975           \textcolor{keyword}{call }time\_interp\_external(segment%field(m)%fid\_dz,time, tmp\_buffer\_in)
3976           \textcolor{keywordflow}{if} (turns /= 0) \textcolor{keywordflow}{then}
3977             \textcolor{comment}{! TODO: This is hardcoded for 90 degrees, and needs to be generalized.}
3978             \textcolor{keywordflow}{if} (segment%is\_E\_or\_W &
3979                 .and. .not. (segment%field(m)%name == \textcolor{stringliteral}{'V'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DVDX'})) \textcolor{keywordflow}{then}
3980               nj\_buf = \textcolor{keyword}{size}(tmp\_buffer, 2) - 1
3981               \textcolor{keyword}{call }rotate\_array(tmp\_buffer\_in(:nj\_buf,:,:), turns, tmp\_buffer(:,:nj\_buf,:))
3982             \textcolor{keywordflow}{elseif} (segment%is\_N\_or\_S &
3983                 .and. .not. (segment%field(m)%name == \textcolor{stringliteral}{'U'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DUDY'})) \textcolor{keywordflow}{then}
3984               ni\_buf = \textcolor{keyword}{size}(tmp\_buffer, 1) - 1
3985               \textcolor{keyword}{call }rotate\_array(tmp\_buffer\_in(:,:ni\_buf,:), turns, tmp\_buffer(:ni\_buf,:,:))
3986             \textcolor{keywordflow}{else}
3987               \textcolor{keyword}{call }rotate\_array(tmp\_buffer\_in, turns, tmp\_buffer)
3988 \textcolor{keywordflow}{            endif}
3989 \textcolor{keywordflow}{          endif}
3990           \textcolor{keywordflow}{if} (obc%brushcutter\_mode) \textcolor{keywordflow}{then}
3991             \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
3992               \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'V'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DVDX'}) \textcolor{keywordflow}{then}
3993                 segment%field(m)%dz\_src(is\_obc,:,:) = &
3994                     tmp\_buffer(1,2*(js\_obc+g%jdg\_offset)+1:2*(je\_obc+g%jdg\_offset)+1:2,:)
3995               \textcolor{keywordflow}{else}
3996                 segment%field(m)%dz\_src(is\_obc,:,:) = &
3997                     tmp\_buffer(1,2*(js\_obc+g%jdg\_offset)+1:2*(je\_obc+g%jdg\_offset):2,:)
3998 \textcolor{keywordflow}{              endif}
3999             \textcolor{keywordflow}{else}
4000               \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'U'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DUDY'}) \textcolor{keywordflow}{then}
4001                 segment%field(m)%dz\_src(:,js\_obc,:) = &
4002                     tmp\_buffer(2*(is\_obc+g%idg\_offset)+1:2*(ie\_obc+g%idg\_offset)+1:2,1,:)
4003               \textcolor{keywordflow}{else}
4004                 segment%field(m)%dz\_src(:,js\_obc,:) = &
4005                     tmp\_buffer(2*(is\_obc+g%idg\_offset)+1:2*(ie\_obc+g%idg\_offset):2,1,:)
4006 \textcolor{keywordflow}{              endif}
4007 \textcolor{keywordflow}{            endif}
4008           \textcolor{keywordflow}{else}
4009             \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
4010               \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'V'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DVDX'}) \textcolor{keywordflow}{then}
4011                 segment%field(m)%dz\_src(is\_obc,:,:)=tmp\_buffer(1,js\_obc+g%jdg\_offset+1:je\_obc+g%jdg\_offset+
      1,:)
4012               \textcolor{keywordflow}{else}
4013                 segment%field(m)%dz\_src(is\_obc,:,:)=tmp\_buffer(1,js\_obc+g%jdg\_offset+1:je\_obc+g%jdg\_offset,
      :)
4014 \textcolor{keywordflow}{              endif}
4015             \textcolor{keywordflow}{else}
4016               \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'U'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DUDY'}) \textcolor{keywordflow}{then}
4017                 segment%field(m)%dz\_src(:,js\_obc,:)=tmp\_buffer(is\_obc+g%idg\_offset+1:ie\_obc+g%idg\_offset+1,
      1,:)
4018               \textcolor{keywordflow}{else}
4019                 segment%field(m)%dz\_src(:,js\_obc,:)=tmp\_buffer(is\_obc+g%idg\_offset+1:ie\_obc+g%idg\_offset,1,
      :)
4020 \textcolor{keywordflow}{              endif}
4021 \textcolor{keywordflow}{            endif}
4022 \textcolor{keywordflow}{          endif}
4023 
4024           \textcolor{keyword}{call }adjustsegmentetatofitbathymetry(g,gv,us,segment,m)
4025 
4026           \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
4027             ishift=1
4028             \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_e) ishift=0
4029             i=is\_obc
4030             \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'V'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DVDX'}) \textcolor{keywordflow}{then}
4031               \textcolor{comment}{! Do q points for the whole segment}
4032               \textcolor{keywordflow}{do} j=max(js\_obc,jsd),min(je\_obc,jed-1)
4033                 \textcolor{comment}{! Using the h remapping approach}
4034                 \textcolor{comment}{! Pretty sure we need to check for source/target grid consistency here}
4035                 segment%field(m)%buffer\_dst(i,j,:)=0.0  \textcolor{comment}{! initialize remap destination buffer}
4036                 \textcolor{keywordflow}{if} (g%mask2dCu(i,j)>0. .and. g%mask2dCu(i,j+1)>0.) \textcolor{keywordflow}{then}
4037                   h\_stack(:) = 0.5*(h(i+ishift,j,:) + h(i+ishift,j+1,:))
4038                   \textcolor{keyword}{call }remapping\_core\_h(obc%remap\_CS, &
4039                        segment%field(m)%nk\_src,segment%field(m)%dz\_src(i,j,:), &
4040                        segment%field(m)%buffer\_src(i,j,:), &
4041                        g%ke, h\_stack, segment%field(m)%buffer\_dst(i,j,:))
4042                 \textcolor{keywordflow}{elseif} (g%mask2dCu(i,j)>0.) \textcolor{keywordflow}{then}
4043                   h\_stack(:) = h(i+ishift,j,:)
4044                   \textcolor{keyword}{call }remapping\_core\_h(obc%remap\_CS, &
4045                        segment%field(m)%nk\_src,segment%field(m)%dz\_src(i,j,:), &
4046                        segment%field(m)%buffer\_src(i,j,:), &
4047                        g%ke, h\_stack, segment%field(m)%buffer\_dst(i,j,:))
4048                 \textcolor{keywordflow}{elseif} (g%mask2dCu(i,j+1)>0.) \textcolor{keywordflow}{then}
4049                   h\_stack(:) = h(i+ishift,j+1,:)
4050                   \textcolor{keyword}{call }remapping\_core\_h(obc%remap\_CS, &
4051                        segment%field(m)%nk\_src,segment%field(m)%dz\_src(i,j,:), &
4052                        segment%field(m)%buffer\_src(i,j,:), &
4053                        g%ke, h\_stack, segment%field(m)%buffer\_dst(i,j,:))
4054 \textcolor{keywordflow}{                endif}
4055 \textcolor{keywordflow}{              enddo}
4056             \textcolor{keywordflow}{else}
4057               \textcolor{keywordflow}{do} j=js\_obc+1,je\_obc
4058                 \textcolor{comment}{! Using the h remapping approach}
4059                 \textcolor{comment}{! Pretty sure we need to check for source/target grid consistency here}
4060                 segment%field(m)%buffer\_dst(i,j,:)=0.0  \textcolor{comment}{! initialize remap destination buffer}
4061                 \textcolor{keywordflow}{if} (g%mask2dCu(i,j)>0.) \textcolor{keywordflow}{then}
4062                   net\_h\_src = sum( segment%field(m)%dz\_src(i,j,:) )
4063                   net\_h\_int = sum( h(i+ishift,j,:) )
4064                   scl\_fac = net\_h\_int / net\_h\_src
4065                   \textcolor{keyword}{call }remapping\_core\_h(obc%remap\_CS, &
4066                        segment%field(m)%nk\_src, scl\_fac*segment%field(m)%dz\_src(i,j,:), &
4067                        segment%field(m)%buffer\_src(i,j,:), &
4068                        g%ke, h(i+ishift,j,:), segment%field(m)%buffer\_dst(i,j,:))
4069 \textcolor{keywordflow}{                endif}
4070 \textcolor{keywordflow}{              enddo}
4071 \textcolor{keywordflow}{            endif}
4072           \textcolor{keywordflow}{else}
4073             jshift=1
4074             \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_n) jshift=0
4075             j=js\_obc
4076             \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'U'} .or. segment%field(m)%name == \textcolor{stringliteral}{'DUDY'}) \textcolor{keywordflow}{then}
4077               \textcolor{comment}{! Do q points for the whole segment}
4078               \textcolor{keywordflow}{do} i=max(is\_obc,isd),min(ie\_obc,ied-1)
4079                 segment%field(m)%buffer\_dst(i,j,:)=0.0  \textcolor{comment}{! initialize remap destination buffer}
4080                 \textcolor{keywordflow}{if} (g%mask2dCv(i,j)>0. .and. g%mask2dCv(i+1,j)>0.) \textcolor{keywordflow}{then}
4081               \textcolor{comment}{! Using the h remapping approach}
4082               \textcolor{comment}{! Pretty sure we need to check for source/target grid consistency here}
4083                   h\_stack(:) = 0.5*(h(i,j+jshift,:) + h(i+1,j+jshift,:))
4084                   \textcolor{keyword}{call }remapping\_core\_h(obc%remap\_CS, &
4085                        segment%field(m)%nk\_src,segment%field(m)%dz\_src(i,j,:), &
4086                        segment%field(m)%buffer\_src(i,j,:), &
4087                        g%ke, h\_stack, segment%field(m)%buffer\_dst(i,j,:))
4088                 \textcolor{keywordflow}{elseif} (g%mask2dCv(i,j)>0.) \textcolor{keywordflow}{then}
4089                   h\_stack(:) = h(i,j+jshift,:)
4090                   \textcolor{keyword}{call }remapping\_core\_h(obc%remap\_CS, &
4091                        segment%field(m)%nk\_src,segment%field(m)%dz\_src(i,j,:), &
4092                        segment%field(m)%buffer\_src(i,j,:), &
4093                        g%ke, h\_stack, segment%field(m)%buffer\_dst(i,j,:))
4094                 \textcolor{keywordflow}{elseif} (g%mask2dCv(i+1,j)>0.) \textcolor{keywordflow}{then}
4095                   h\_stack(:) = h(i+1,j+jshift,:)
4096                   \textcolor{keyword}{call }remapping\_core\_h(obc%remap\_CS, &
4097                        segment%field(m)%nk\_src,segment%field(m)%dz\_src(i,j,:), &
4098                        segment%field(m)%buffer\_src(i,j,:), &
4099                        g%ke, h\_stack, segment%field(m)%buffer\_dst(i,j,:))
4100 \textcolor{keywordflow}{                endif}
4101 \textcolor{keywordflow}{              enddo}
4102             \textcolor{keywordflow}{else}
4103               \textcolor{keywordflow}{do} i=is\_obc+1,ie\_obc
4104               \textcolor{comment}{! Using the h remapping approach}
4105               \textcolor{comment}{! Pretty sure we need to check for source/target grid consistency here}
4106                 segment%field(m)%buffer\_dst(i,j,:)=0.0  \textcolor{comment}{! initialize remap destination buffer}
4107                 \textcolor{keywordflow}{if} (g%mask2dCv(i,j)>0.) \textcolor{keywordflow}{then}
4108                   net\_h\_src = sum( segment%field(m)%dz\_src(i,j,:) )
4109                   net\_h\_int = sum( h(i,j+jshift,:) )
4110                   scl\_fac = net\_h\_int / net\_h\_src
4111                   \textcolor{keyword}{call }remapping\_core\_h(obc%remap\_CS, &
4112                        segment%field(m)%nk\_src, scl\_fac*segment%field(m)%dz\_src(i,j,:), &
4113                        segment%field(m)%buffer\_src(i,j,:), &
4114                        g%ke, h(i,j+jshift,:), segment%field(m)%buffer\_dst(i,j,:))
4115 \textcolor{keywordflow}{                endif}
4116 \textcolor{keywordflow}{              enddo}
4117 \textcolor{keywordflow}{            endif}
4118 \textcolor{keywordflow}{          endif}
4119         \textcolor{keywordflow}{elseif} (segment%field(m)%nk\_src > 1 .and. &
4120             (index(segment%field(m)%name, \textcolor{stringliteral}{'phase'}) > 0 .or. index(segment%field(m)%name, \textcolor{stringliteral}{'amp'}) > 0)) \textcolor{keywordflow}{then}
4121           \textcolor{comment}{! no dz for tidal variables}
4122           segment%field(m)%buffer\_dst(:,:,:) = segment%field(m)%buffer\_src(:,:,:)
4123         \textcolor{keywordflow}{else}  \textcolor{comment}{! 2d data}
4124           segment%field(m)%buffer\_dst(:,:,1) = segment%field(m)%buffer\_src(:,:,1)  \textcolor{comment}{! initialize remap
       destination buffer}
4125 \textcolor{keywordflow}{        endif}
4126         \textcolor{keyword}{deallocate}(tmp\_buffer)
4127         \textcolor{keywordflow}{if} (turns /= 0) &
4128           \textcolor{keyword}{deallocate}(tmp\_buffer\_in)
4129       \textcolor{keywordflow}{else} \textcolor{comment}{! fid <= 0 (Uniform value)}
4130         \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(segment%field(m)%buffer\_dst)) \textcolor{keywordflow}{then}
4131           \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
4132             \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'V'}) \textcolor{keywordflow}{then}
4133               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc:je\_obc,g%ke))
4134             \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'Vamp'} .or. segment%field(m)%name == \textcolor{stringliteral}{'Vphase'}) \textcolor{keywordflow}{then}
4135               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc:je\_obc,1))
4136             \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'U'}) \textcolor{keywordflow}{then}
4137               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc+1:je\_obc,g%ke))
4138             \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Uamp'} .or. segment%field(m)%name == \textcolor{stringliteral}{'Uphase'}) \textcolor{keywordflow}{then}
4139               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc+1:je\_obc,1))
4140             \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'DVDX'}) \textcolor{keywordflow}{then}
4141               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc:je\_obc,g%ke))
4142             \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'SSH'} .or. segment%field(m)%name == \textcolor{stringliteral}{'SSHamp'} &
4143                 .or. segment%field(m)%name == \textcolor{stringliteral}{'SSHphase'}) \textcolor{keywordflow}{then}
4144               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc:je\_obc,1))
4145             \textcolor{keywordflow}{else}
4146               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc+1:je\_obc,g%ke))
4147 \textcolor{keywordflow}{            endif}
4148           \textcolor{keywordflow}{else}
4149             \textcolor{keywordflow}{if} (segment%field(m)%name == \textcolor{stringliteral}{'U'}) \textcolor{keywordflow}{then}
4150               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc:je\_obc,g%ke))
4151             \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Uamp'} .or. segment%field(m)%name == \textcolor{stringliteral}{'Uphase'}) \textcolor{keywordflow}{then}
4152               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc:je\_obc,1))
4153             \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'V'}) \textcolor{keywordflow}{then}
4154               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc+1:ie\_obc,js\_obc:je\_obc,g%ke))
4155             \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'Vamp'} .or. segment%field(m)%name == \textcolor{stringliteral}{'Vphase'}) \textcolor{keywordflow}{then}
4156               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc+1:ie\_obc,js\_obc:je\_obc,1))
4157             \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'DUDY'}) \textcolor{keywordflow}{then}
4158               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc:je\_obc,g%ke))
4159             \textcolor{keywordflow}{elseif} (segment%field(m)%name == \textcolor{stringliteral}{'SSH'} .or. segment%field(m)%name == \textcolor{stringliteral}{'SSHamp'} &
4160                 .or. segment%field(m)%name == \textcolor{stringliteral}{'SSHphase'}) \textcolor{keywordflow}{then}
4161               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc:ie\_obc,js\_obc:je\_obc,1))
4162             \textcolor{keywordflow}{else}
4163               \textcolor{keyword}{allocate}(segment%field(m)%buffer\_dst(is\_obc+1:ie\_obc,js\_obc:je\_obc,g%ke))
4164 \textcolor{keywordflow}{            endif}
4165 \textcolor{keywordflow}{          endif}
4166           segment%field(m)%buffer\_dst(:,:,:) = segment%field(m)%value
4167 \textcolor{keywordflow}{        endif}
4168 \textcolor{keywordflow}{      endif}
4169 \textcolor{keywordflow}{    enddo}
4170     \textcolor{comment}{! Start second loop to update all fields now that data for all fields are available.}
4171     \textcolor{comment}{! (split because tides depend on multiple variables).}
4172     \textcolor{keywordflow}{do} m = 1,segment%num\_fields
4173       \textcolor{comment}{! if (segment%field(m)%fid>0) then}
4174       \textcolor{comment}{! calculate external BT velocity and transport if needed}
4175       \textcolor{keywordflow}{if} (trim(segment%field(m)%name) == \textcolor{stringliteral}{'U'} .or. trim(segment%field(m)%name) == \textcolor{stringliteral}{'V'}) \textcolor{keywordflow}{then}
4176         \textcolor{keywordflow}{if} (trim(segment%field(m)%name) == \textcolor{stringliteral}{'U'} .and. segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
4177           i=is\_obc
4178           \textcolor{keywordflow}{do} j=js\_obc+1,je\_obc
4179             normal\_trans\_bt(i,j) = 0.0
4180             tidal\_vel = 0.0
4181             \textcolor{keywordflow}{if} (obc%add\_tide\_constituents) \textcolor{keywordflow}{then}
4182               \textcolor{keywordflow}{do} c=1,obc%n\_tide\_constituents
4183                 tidal\_vel = tidal\_vel + (obc%tide\_fn(c) * segment%field(segment%uamp\_index)%buffer\_dst(i,j,
      c)) * &
4184                   cos((time\_delta*obc%tide\_frequencies(c) - segment%field(segment%uphase\_index)%buffer\_dst(
      i,j,c)) &
4185                       + (obc%tide\_eq\_phases(c) + obc%tide\_un(c)))
4186 \textcolor{keywordflow}{              enddo}
4187 \textcolor{keywordflow}{            endif}
4188             \textcolor{keywordflow}{do} k=1,g%ke
4189               segment%normal\_vel(i,j,k) = us%m\_s\_to\_L\_T*(segment%field(m)%buffer\_dst(i,j,k) + tidal\_vel)
4190               segment%normal\_trans(i,j,k) = segment%normal\_vel(i,j,k)*segment%h(i,j,k) * g%dyCu(i,j)
4191               normal\_trans\_bt(i,j) = normal\_trans\_bt(i,j) + segment%normal\_trans(i,j,k)
4192 \textcolor{keywordflow}{            enddo}
4193             segment%normal\_vel\_bt(i,j) = normal\_trans\_bt(i,j) &
4194                 / (max(segment%Htot(i,j), 1.e-12 * gv%m\_to\_H) * g%dyCu(i,j))
4195             \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%nudged\_normal\_vel)) segment%nudged\_normal\_vel(i,j,:) = segment
      %normal\_vel(i,j,:)
4196 \textcolor{keywordflow}{          enddo}
4197         \textcolor{keywordflow}{elseif} (trim(segment%field(m)%name) == \textcolor{stringliteral}{'V'} .and. segment%is\_N\_or\_S) \textcolor{keywordflow}{then}
4198           j=js\_obc
4199           \textcolor{keywordflow}{do} i=is\_obc+1,ie\_obc
4200             normal\_trans\_bt(i,j) = 0.0
4201             tidal\_vel = 0.0
4202             \textcolor{keywordflow}{if} (obc%add\_tide\_constituents) \textcolor{keywordflow}{then}
4203               \textcolor{keywordflow}{do} c=1,obc%n\_tide\_constituents
4204                 tidal\_vel = tidal\_vel + (obc%tide\_fn(c) * segment%field(segment%vamp\_index)%buffer\_dst(i,j,
      c)) * &
4205                   cos((time\_delta*obc%tide\_frequencies(c) - segment%field(segment%vphase\_index)%buffer\_dst(
      i,j,c)) &
4206                       + (obc%tide\_eq\_phases(c) + obc%tide\_un(c)))
4207 \textcolor{keywordflow}{              enddo}
4208 \textcolor{keywordflow}{            endif}
4209             \textcolor{keywordflow}{do} k=1,g%ke
4210               segment%normal\_vel(i,j,k) = us%m\_s\_to\_L\_T*(segment%field(m)%buffer\_dst(i,j,k) + tidal\_vel)
4211               segment%normal\_trans(i,j,k) = segment%normal\_vel(i,j,k)*segment%h(i,j,k) * &
4212                         g%dxCv(i,j)
4213               normal\_trans\_bt(i,j) = normal\_trans\_bt(i,j) + segment%normal\_trans(i,j,k)
4214 \textcolor{keywordflow}{            enddo}
4215             segment%normal\_vel\_bt(i,j) = normal\_trans\_bt(i,j) &
4216                 / (max(segment%Htot(i,j), 1.e-12 * gv%m\_to\_H) * g%dxCv(i,j))
4217             \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%nudged\_normal\_vel)) segment%nudged\_normal\_vel(i,j,:) = segment
      %normal\_vel(i,j,:)
4218 \textcolor{keywordflow}{          enddo}
4219         \textcolor{keywordflow}{elseif} (trim(segment%field(m)%name) == \textcolor{stringliteral}{'V'} .and. segment%is\_E\_or\_W .and. &
4220                 \textcolor{keyword}{associated}(segment%tangential\_vel)) \textcolor{keywordflow}{then}
4221           i=is\_obc
4222           \textcolor{keywordflow}{do} j=js\_obc,je\_obc
4223             tidal\_vel = 0.0
4224             \textcolor{keywordflow}{if} (obc%add\_tide\_constituents) \textcolor{keywordflow}{then}
4225               \textcolor{keywordflow}{do} c=1,obc%n\_tide\_constituents
4226                 tidal\_vel = tidal\_vel + (obc%tide\_fn(c) * segment%field(segment%vamp\_index)%buffer\_dst(i,j,
      c)) * &
4227                   cos((time\_delta*obc%tide\_frequencies(c) - segment%field(segment%vphase\_index)%buffer\_dst(
      i,j,c)) &
4228                       + (obc%tide\_eq\_phases(c) + obc%tide\_un(c)))
4229 \textcolor{keywordflow}{              enddo}
4230 \textcolor{keywordflow}{            endif}
4231             \textcolor{keywordflow}{do} k=1,g%ke
4232               segment%tangential\_vel(i,j,k) = us%m\_s\_to\_L\_T*(segment%field(m)%buffer\_dst(i,j,k) + tidal\_vel
      )
4233 \textcolor{keywordflow}{            enddo}
4234             \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%nudged\_tangential\_vel)) &
4235               segment%nudged\_tangential\_vel(i,j,:) = segment%tangential\_vel(i,j,:)
4236 \textcolor{keywordflow}{          enddo}
4237         \textcolor{keywordflow}{elseif} (trim(segment%field(m)%name) == \textcolor{stringliteral}{'U'} .and. segment%is\_N\_or\_S .and. &
4238                 \textcolor{keyword}{associated}(segment%tangential\_vel)) \textcolor{keywordflow}{then}
4239           j=js\_obc
4240           \textcolor{keywordflow}{do} i=is\_obc,ie\_obc
4241             tidal\_vel = 0.0
4242             \textcolor{keywordflow}{if} (obc%add\_tide\_constituents) \textcolor{keywordflow}{then}
4243               \textcolor{keywordflow}{do} c=1,obc%n\_tide\_constituents
4244                 tidal\_vel = tidal\_vel + (obc%tide\_fn(c) * segment%field(segment%uamp\_index)%buffer\_dst(i,j,
      c)) * &
4245                     cos((time\_delta*obc%tide\_frequencies(c) - segment%field(segment%uphase\_index)
      %buffer\_dst(i,j,c)) &
4246                         + (obc%tide\_eq\_phases(c) + obc%tide\_un(c)))
4247 \textcolor{keywordflow}{              enddo}
4248 \textcolor{keywordflow}{            endif}
4249             \textcolor{keywordflow}{do} k=1,g%ke
4250               segment%tangential\_vel(i,j,k) = us%m\_s\_to\_L\_T*(segment%field(m)%buffer\_dst(i,j,k) + tidal\_vel
      )
4251 \textcolor{keywordflow}{            enddo}
4252             \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%nudged\_tangential\_vel)) &
4253               segment%nudged\_tangential\_vel(i,j,:) = segment%tangential\_vel(i,j,:)
4254 \textcolor{keywordflow}{          enddo}
4255 \textcolor{keywordflow}{        endif}
4256       \textcolor{keywordflow}{elseif} (trim(segment%field(m)%name) == \textcolor{stringliteral}{'DVDX'} .and. segment%is\_E\_or\_W .and. &
4257               \textcolor{keyword}{associated}(segment%tangential\_grad)) \textcolor{keywordflow}{then}
4258         i=is\_obc
4259         \textcolor{keywordflow}{do} j=js\_obc,je\_obc
4260           \textcolor{keywordflow}{do} k=1,g%ke
4261             segment%tangential\_grad(i,j,k) = us%T\_to\_s*segment%field(m)%buffer\_dst(i,j,k)
4262             \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%nudged\_tangential\_grad)) &
4263               segment%nudged\_tangential\_grad(i,j,:) = segment%tangential\_grad(i,j,:)
4264 \textcolor{keywordflow}{          enddo}
4265 \textcolor{keywordflow}{        enddo}
4266       \textcolor{keywordflow}{elseif} (trim(segment%field(m)%name) == \textcolor{stringliteral}{'DUDY'} .and. segment%is\_N\_or\_S .and. &
4267               \textcolor{keyword}{associated}(segment%tangential\_grad)) \textcolor{keywordflow}{then}
4268         j=js\_obc
4269         \textcolor{keywordflow}{do} i=is\_obc,ie\_obc
4270           \textcolor{keywordflow}{do} k=1,g%ke
4271             segment%tangential\_grad(i,j,k) = us%T\_to\_s*segment%field(m)%buffer\_dst(i,j,k)
4272             \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%nudged\_tangential\_grad)) &
4273               segment%nudged\_tangential\_grad(i,j,:) = segment%tangential\_grad(i,j,:)
4274 \textcolor{keywordflow}{          enddo}
4275 \textcolor{keywordflow}{        enddo}
4276 \textcolor{keywordflow}{      endif}
4277 
4278       \textcolor{comment}{! endif}
4279 
4280       \textcolor{comment}{! from this point on, data are entirely on segments - will}
4281       \textcolor{comment}{! write all segment loops as 2d loops.}
4282       \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
4283         js\_obc2 = js\_obc+1
4284         is\_obc2 = is\_obc
4285       \textcolor{keywordflow}{else}
4286         js\_obc2 = js\_obc
4287         is\_obc2 = is\_obc+1
4288 \textcolor{keywordflow}{      endif}
4289       \textcolor{keywordflow}{if} (segment%is\_N\_or\_S) \textcolor{keywordflow}{then}
4290         is\_obc2 = is\_obc+1
4291         js\_obc2 = js\_obc
4292       \textcolor{keywordflow}{else}
4293         is\_obc2 = is\_obc
4294         js\_obc2 = js\_obc+1
4295 \textcolor{keywordflow}{      endif}
4296 
4297       \textcolor{keywordflow}{if} (trim(segment%field(m)%name) == \textcolor{stringliteral}{'SSH'}) \textcolor{keywordflow}{then}
4298         \textcolor{keywordflow}{if} (obc%ramp) \textcolor{keywordflow}{then}
4299           \textcolor{keywordflow}{do} j=js\_obc2,je\_obc
4300             \textcolor{keywordflow}{do} i=is\_obc2,ie\_obc
4301               tidal\_elev = 0.0
4302               \textcolor{keywordflow}{if} (obc%add\_tide\_constituents) \textcolor{keywordflow}{then}
4303                 \textcolor{keywordflow}{do} c=1,obc%n\_tide\_constituents
4304                   tidal\_elev = tidal\_elev + (obc%tide\_fn(c) * segment%field(segment%zamp\_index)%buffer\_dst(
      i,j,c)) * &
4305                       cos((time\_delta*obc%tide\_frequencies(c) - segment%field(segment%zphase\_index)
      %buffer\_dst(i,j,c)) &
4306                           + (obc%tide\_eq\_phases(c) + obc%tide\_un(c)))
4307 \textcolor{keywordflow}{                enddo}
4308 \textcolor{keywordflow}{              endif}
4309               segment%eta(i,j) = gv%m\_to\_H * obc%ramp\_value &
4310                 * (segment%field(m)%buffer\_dst(i,j,1) + tidal\_elev)
4311 \textcolor{keywordflow}{            enddo}
4312 \textcolor{keywordflow}{          enddo}
4313         \textcolor{keywordflow}{else}
4314           \textcolor{keywordflow}{do} j=js\_obc2,je\_obc
4315             \textcolor{keywordflow}{do} i=is\_obc2,ie\_obc
4316               tidal\_elev = 0.0
4317               \textcolor{keywordflow}{if} (obc%add\_tide\_constituents) \textcolor{keywordflow}{then}
4318                 \textcolor{keywordflow}{do} c=1,obc%n\_tide\_constituents
4319                   tidal\_elev = tidal\_elev + (obc%tide\_fn(c) * segment%field(segment%zamp\_index)%buffer\_dst(
      i,j,c)) * &
4320                       cos((time\_delta*obc%tide\_frequencies(c) - segment%field(segment%zphase\_index)
      %buffer\_dst(i,j,c)) &
4321                           + (obc%tide\_eq\_phases(c) + obc%tide\_un(c)))
4322 \textcolor{keywordflow}{                enddo}
4323 \textcolor{keywordflow}{              endif}
4324               segment%eta(i,j) = gv%m\_to\_H * (segment%field(m)%buffer\_dst(i,j,1) + tidal\_elev)
4325 \textcolor{keywordflow}{            enddo}
4326 \textcolor{keywordflow}{          enddo}
4327 \textcolor{keywordflow}{        endif}
4328 \textcolor{keywordflow}{      endif}
4329 
4330       \textcolor{keywordflow}{if} (trim(segment%field(m)%name) == \textcolor{stringliteral}{'TEMP'}) \textcolor{keywordflow}{then}
4331         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%field(m)%buffer\_dst)) \textcolor{keywordflow}{then}
4332           \textcolor{keywordflow}{do} k=1,nz; \textcolor{keywordflow}{do} j=js\_obc2, je\_obc; \textcolor{keywordflow}{do} i=is\_obc2,ie\_obc
4333             segment%tr\_Reg%Tr(1)%t(i,j,k) = segment%field(m)%buffer\_dst(i,j,k)
4334 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
4335           \textcolor{keywordflow}{if} (.not. segment%tr\_Reg%Tr(1)%is\_initialized) \textcolor{keywordflow}{then}
4336             \textcolor{comment}{! if the tracer reservoir has not yet been initialized, then set to external value.}
4337             \textcolor{keywordflow}{do} k=1,nz; \textcolor{keywordflow}{do} j=js\_obc2, je\_obc; \textcolor{keywordflow}{do} i=is\_obc2,ie\_obc
4338               segment%tr\_Reg%Tr(1)%tres(i,j,k) = segment%tr\_Reg%Tr(1)%t(i,j,k)
4339 \textcolor{keywordflow}{            enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
4340             segment%tr\_Reg%Tr(1)%is\_initialized=.true.
4341 \textcolor{keywordflow}{          endif}
4342         \textcolor{keywordflow}{else}
4343           segment%tr\_Reg%Tr(1)%OBC\_inflow\_conc = segment%field(m)%value
4344 \textcolor{keywordflow}{        endif}
4345       \textcolor{keywordflow}{elseif} (trim(segment%field(m)%name) == \textcolor{stringliteral}{'SALT'}) \textcolor{keywordflow}{then}
4346         \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%field(m)%buffer\_dst)) \textcolor{keywordflow}{then}
4347           \textcolor{keywordflow}{do} k=1,nz; \textcolor{keywordflow}{do} j=js\_obc2, je\_obc; \textcolor{keywordflow}{do} i=is\_obc2,ie\_obc
4348             segment%tr\_Reg%Tr(2)%t(i,j,k) = segment%field(m)%buffer\_dst(i,j,k)
4349 \textcolor{keywordflow}{          enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
4350           \textcolor{keywordflow}{if} (.not. segment%tr\_Reg%Tr(2)%is\_initialized) \textcolor{keywordflow}{then}
4351             \textcolor{comment}{!if the tracer reservoir has not yet been initialized, then set to external value.}
4352             \textcolor{keywordflow}{do} k=1,nz; \textcolor{keywordflow}{do} j=js\_obc2, je\_obc; \textcolor{keywordflow}{do} i=is\_obc2,ie\_obc
4353               segment%tr\_Reg%Tr(2)%tres(i,j,k) = segment%tr\_Reg%Tr(2)%t(i,j,k)
4354 \textcolor{keywordflow}{            enddo} ;\textcolor{keywordflow}{ enddo} ;\textcolor{keywordflow}{ enddo}
4355             segment%tr\_Reg%Tr(2)%is\_initialized=.true.
4356 \textcolor{keywordflow}{          endif}
4357         \textcolor{keywordflow}{else}
4358           segment%tr\_Reg%Tr(2)%OBC\_inflow\_conc = segment%field(m)%value
4359 \textcolor{keywordflow}{        endif}
4360 \textcolor{keywordflow}{      endif}
4361 
4362 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! end field loop}
4363     \textcolor{keyword}{deallocate}(h\_stack)
4364     \textcolor{keyword}{deallocate}(normal\_trans\_bt)
4365 
4366 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! end segment loop}
4367 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__open__boundary_a230cf67375352c9d55b4330180d35d7c}\label{namespacemom__open__boundary_a230cf67375352c9d55b4330180d35d7c}} 
\index{mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}!update\+\_\+segment\+\_\+tracer\+\_\+reservoirs@{update\+\_\+segment\+\_\+tracer\+\_\+reservoirs}}
\index{update\+\_\+segment\+\_\+tracer\+\_\+reservoirs@{update\+\_\+segment\+\_\+tracer\+\_\+reservoirs}!mom\+\_\+open\+\_\+boundary@{mom\+\_\+open\+\_\+boundary}}
\subsubsection{\texorpdfstring{update\+\_\+segment\+\_\+tracer\+\_\+reservoirs()}{update\_segment\_tracer\_reservoirs()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+open\+\_\+boundary\+::update\+\_\+segment\+\_\+tracer\+\_\+reservoirs (\begin{DoxyParamCaption}\item[{type(ocean\+\_\+grid\+\_\+type), intent(in)}]{G,  }\item[{type(verticalgrid\+\_\+type), intent(in)}]{GV,  }\item[{real, dimension(szib\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{uhr,  }\item[{real, dimension(szi\+\_\+(g),szjb\+\_\+(g),szk\+\_\+(g)), intent(in)}]{vhr,  }\item[{real, dimension(szi\+\_\+(g),szj\+\_\+(g),szk\+\_\+(g)), intent(in)}]{h,  }\item[{type(\hyperlink{structmom__open__boundary_1_1ocean__obc__type}{ocean\+\_\+obc\+\_\+type}), pointer}]{O\+BC,  }\item[{real, intent(in)}]{dt,  }\item[{type(tracer\+\_\+registry\+\_\+type), pointer}]{Reg }\end{DoxyParamCaption})}



Update the O\+BC tracer reservoirs after the tracers have been updated. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em g} & The ocean\textquotesingle{}s grid structure\\
\hline
\mbox{\tt in}  & {\em gv} & Ocean vertical grid structure\\
\hline
\mbox{\tt in}  & {\em uhr} & accumulated volume/mass flux through the zonal face \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
\mbox{\tt in}  & {\em vhr} & accumulated volume/mass flux through the meridional face \mbox{[}H L2 $\sim$$>$ m3 or kg\mbox{]}\\
\hline
\mbox{\tt in}  & {\em h} & layer thickness after advection \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]}\\
\hline
 & {\em obc} & Open boundary structure\\
\hline
\mbox{\tt in}  & {\em dt} & time increment \mbox{[}T $\sim$$>$ s\mbox{]}\\
\hline
 & {\em reg} & pointer to tracer registry \\
\hline
\end{DoxyParams}


Definition at line 5057 of file M\+O\+M\+\_\+open\+\_\+boundary.\+F90.


\begin{DoxyCode}
5057   \textcolor{keywordtype}{type}(ocean\_grid\_type),                     \textcolor{keywordtype}{intent(in)} :: g\textcolor{comment}{   !< The ocean's grid structure}
5058   \textcolor{keywordtype}{type}(verticalgrid\_type),                   \textcolor{keywordtype}{intent(in)} :: gv\textcolor{comment}{  !<  Ocean vertical grid structure}
5059   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZIB\_(G),SZJ\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)} :: uhr\textcolor{comment}{ !< accumulated volume/mass flux through}
5060 \textcolor{comment}{                                                               !! the zonal face [H L2 ~> m3 or kg]}
5061   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJB\_(G),SZK\_(G))}, \textcolor{keywordtype}{intent(in)} :: vhr\textcolor{comment}{ !< accumulated volume/mass flux through}
5062 \textcolor{comment}{                                                               !! the meridional face [H L2 ~> m3 or kg]}
5063   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(SZI\_(G),SZJ\_(G),SZK\_(G))},  \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{   !< layer thickness after advection}
5064 \textcolor{comment}{                                                               !! [H ~> m or kg m-2]}
5065   \textcolor{keywordtype}{type}(ocean\_obc\_type),                      \textcolor{keywordtype}{pointer}    :: obc\textcolor{comment}{ !< Open boundary structure}
5066   \textcolor{keywordtype}{real},                                      \textcolor{keywordtype}{intent(in)} :: dt\textcolor{comment}{  !< time increment [T ~> s]}
5067   \textcolor{keywordtype}{type}(tracer\_registry\_type),                \textcolor{keywordtype}{pointer}    :: reg\textcolor{comment}{ !< pointer to tracer registry}
5068   \textcolor{comment}{! Local variables}
5069   \textcolor{keywordtype}{type}(obc\_segment\_type), \textcolor{keywordtype}{pointer} :: segment=>null()
5070   \textcolor{keywordtype}{real} :: u\_l\_in, u\_l\_out \textcolor{comment}{! The zonal distance moved in or out of a cell [L ~> m]}
5071   \textcolor{keywordtype}{real} :: v\_l\_in, v\_l\_out \textcolor{comment}{! The meridional distance moved in or out of a cell [L ~> m]}
5072   \textcolor{keywordtype}{real} :: fac1            \textcolor{comment}{! The denominator of the expression for tracer updates [nondim]}
5073   \textcolor{keywordtype}{integer} :: i, j, k, m, n, ntr, nz
5074   \textcolor{keywordtype}{integer} :: ishift, idir, jshift, jdir
5075 
5076   nz = gv%ke
5077   ntr = reg%ntr
5078   \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{if} (obc%OBC\_pe) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} n=1,obc%number\_of\_segments
5079     segment=>obc%segment(n)
5080     \textcolor{keywordflow}{if} (.not. \textcolor{keyword}{associated}(segment%tr\_Reg)) cycle
5081     \textcolor{keywordflow}{if} (segment%is\_E\_or\_W) \textcolor{keywordflow}{then}
5082       i = segment%HI%IsdB
5083       \textcolor{keywordflow}{do} j=segment%HI%jsd,segment%HI%jed
5084         \textcolor{comment}{! ishift+I corresponds to the nearest interior tracer cell index}
5085         \textcolor{comment}{! idir switches the sign of the flow so that positive is into the reservoir}
5086         \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_w) \textcolor{keywordflow}{then}
5087           ishift = 1 ; idir = -1
5088         \textcolor{keywordflow}{else}
5089           ishift = 0 ; idir = 1
5090 \textcolor{keywordflow}{        endif}
5091         \textcolor{comment}{! Can keep this or take it out, either way}
5092         \textcolor{keywordflow}{if} (g%mask2dT(i+ishift,j) == 0.0) cycle
5093         \textcolor{comment}{! Update the reservoir tracer concentration implicitly using a Backward-Euler timestep}
5094         \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tr\_Reg%Tr(m)%tres)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz
5095           u\_l\_out = max(0.0, (idir*uhr(i,j,k))*segment%Tr\_InvLscale\_out / &
5096                     ((h(i+ishift,j,k) + gv%H\_subroundoff)*g%dyCu(i,j)))
5097           u\_l\_in  = min(0.0, (idir*uhr(i,j,k))*segment%Tr\_InvLscale\_in  / &
5098                     ((h(i+ishift,j,k) + gv%H\_subroundoff)*g%dyCu(i,j)))
5099           fac1 = 1.0 + (u\_l\_out-u\_l\_in)
5100           segment%tr\_Reg%Tr(m)%tres(i,j,k) = (1.0/fac1)*(segment%tr\_Reg%Tr(m)%tres(i,j,k) + &
5101                             (u\_l\_out*reg%Tr(m)%t(i+ishift,j,k) - &
5102                              u\_l\_in*segment%tr\_Reg%Tr(m)%t(i,j,k)))
5103           \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc%tres\_x)) obc%tres\_x(i,j,k,m) = segment%tr\_Reg%Tr(m)%tres(i,j,k)
5104 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ endif} ;\textcolor{keywordflow}{ enddo}
5105 \textcolor{keywordflow}{      enddo}
5106     \textcolor{keywordflow}{elseif} (segment%is\_N\_or\_S) \textcolor{keywordflow}{then}
5107       j = segment%HI%JsdB
5108       \textcolor{keywordflow}{do} i=segment%HI%isd,segment%HI%ied
5109         \textcolor{comment}{! jshift+J corresponds to the nearest interior tracer cell index}
5110         \textcolor{comment}{! jdir switches the sign of the flow so that positive is into the reservoir}
5111         \textcolor{keywordflow}{if} (segment%direction == obc\_direction\_s) \textcolor{keywordflow}{then}
5112           jshift = 1 ; jdir = -1
5113         \textcolor{keywordflow}{else}
5114           jshift = 0 ; jdir = 1
5115 \textcolor{keywordflow}{        endif}
5116         \textcolor{comment}{! Can keep this or take it out, either way}
5117         \textcolor{keywordflow}{if} (g%mask2dT(i,j+jshift) == 0.0) cycle
5118         \textcolor{comment}{! Update the reservoir tracer concentration implicitly using a Backward-Euler timestep}
5119         \textcolor{keywordflow}{do} m=1,ntr ; \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(segment%tr\_Reg%Tr(m)%tres)) \textcolor{keywordflow}{then} ; \textcolor{keywordflow}{do} k=1,nz
5120           v\_l\_out = max(0.0, (jdir*vhr(i,j,k))*segment%Tr\_InvLscale\_out / &
5121                     ((h(i,j+jshift,k) + gv%H\_subroundoff)*g%dxCv(i,j)))
5122           v\_l\_in  = min(0.0, (jdir*vhr(i,j,k))*segment%Tr\_InvLscale\_in  / &
5123                     ((h(i,j+jshift,k) + gv%H\_subroundoff)*g%dxCv(i,j)))
5124           fac1 = 1.0 + (v\_l\_out-v\_l\_in)
5125           segment%tr\_Reg%Tr(m)%tres(i,j,k) = (1.0/fac1)*(segment%tr\_Reg%Tr(m)%tres(i,j,k) + &
5126                             (v\_l\_out*reg%Tr(m)%t(i,j+jshift,k) - &
5127                              v\_l\_in*segment%tr\_Reg%Tr(m)%t(i,j,k)))
5128           \textcolor{keywordflow}{if} (\textcolor{keyword}{associated}(obc%tres\_y)) obc%tres\_y(i,j,k,m) = segment%tr\_Reg%Tr(m)%tres(i,j,k)
5129 \textcolor{keywordflow}{        enddo} ;\textcolor{keywordflow}{ endif} ;\textcolor{keywordflow}{ enddo}
5130 \textcolor{keywordflow}{      enddo}
5131 \textcolor{keywordflow}{    endif}
5132 \textcolor{keywordflow}{  enddo} ;\textcolor{keywordflow}{ endif} ;\textcolor{keywordflow}{ endif}
5133 
\end{DoxyCode}
