<p><b>dwj07@fsu.edu</b> 2011-09-20 11:15:08 -0600 (Tue, 20 Sep 2011)</p><p>        <br>
        -- BRANCH COMMITT--<br>
<br>
        Adding modules for horizontal advection of tracers.<br>
</p><hr noshade><pre><font color="gray">Added: branches/ocean_projects/performance/src/core_ocean/module_OcnTracerHadv.F
===================================================================
--- branches/ocean_projects/performance/src/core_ocean/module_OcnTracerHadv.F                                (rev 0)
+++ branches/ocean_projects/performance/src/core_ocean/module_OcnTracerHadv.F        2011-09-20 17:15:08 UTC (rev 1012)
@@ -0,0 +1,180 @@
+!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+!
+!  OcnTracerHadv
+!
+!&gt; \brief MPAS ocean horizontal tracer advection driver
+!&gt; \author Doug Jacobsen
+!&gt; \date   16 September 2011
+!&gt; \version SVN:$Id:$
+!&gt; \details
+!&gt;  This module contains the main driver routine for computing 
+!&gt;  horizontal advection tendencies.  
+!
+!-----------------------------------------------------------------------
+
+module OcnTracerHadv
+
+   use grid_types
+   use configure
+
+   use OcnTracerHadv2
+   use OcnTracerHadv3
+   use OcnTracerHadv4
+
+   implicit none
+   private
+   save
+
+   !--------------------------------------------------------------------
+   !
+   ! Public parameters
+   !
+   !--------------------------------------------------------------------
+
+   !--------------------------------------------------------------------
+   !
+   ! Public member functions
+   !
+   !--------------------------------------------------------------------
+
+   public :: OcnTracerHadvTend, &amp;
+             OcnTracerHadvInit
+
+   !--------------------------------------------------------------------
+   !
+   ! Private module variables
+   !
+   !--------------------------------------------------------------------
+
+
+!***********************************************************************
+
+contains
+
+!***********************************************************************
+!
+!  routine OcnTracerHadvTend
+!
+!&gt; \brief   Computes tendency term for horizontal tracer advection
+!&gt; \author  Phil Jones, Doug Jacobsen
+!&gt; \date    15 September 2011
+!&gt; \version SVN:$Id$
+!&gt; \details 
+!&gt;  This routine computes the horizontal advection tendency for tracer
+!&gt;  based on current state and user choices of advection parameterization.
+!&gt;  Multiple parameterizations may be chosen and added together.  These
+!&gt;  tendencies are generally computed by calling the specific routine
+!&gt;  for the chosen parameterization, so this routine is primarily a
+!&gt;  driver for managing these choices.
+!
+!-----------------------------------------------------------------------
+
+   subroutine OcnTracerHadvTend(grid, u, h_edge, tracers, tend, err)
+
+      !-----------------------------------------------------------------
+      !
+      ! input variables
+      !
+      !-----------------------------------------------------------------
+
+      real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         u    !&lt; Input: velocity
+
+      real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         h_edge     !&lt; Input: thickness at edge
+
+      real (kind=RKIND), dimension(:,:,:), intent(in) :: &amp;
+         tracers     !&lt; Input: tracers
+
+      type (mesh_type), intent(in) :: &amp;
+         grid          !&lt; Input: grid information
+
+      !-----------------------------------------------------------------
+      !
+      ! input/output variables
+      !
+      !-----------------------------------------------------------------
+
+      real (kind=RKIND), dimension(:,:,:), intent(inout) :: &amp;
+         tend          !&lt; Input/Output: velocity tendency
+
+      !-----------------------------------------------------------------
+      !
+      ! output variables
+      !
+      !-----------------------------------------------------------------
+
+      integer, intent(out) :: err
+
+      !-----------------------------------------------------------------
+      !
+      ! local variables
+      !
+      !-----------------------------------------------------------------
+
+      integer :: err1, err2, err3
+
+      !-----------------------------------------------------------------
+      !
+      ! call relevant routines for computing tendencies
+      ! note that the user can choose multiple options and the 
+      !   tendencies will be added together
+      !
+      !-----------------------------------------------------------------
+
+      call OcnTracerHadv2Tend(grid, u, h_edge, tracers, tend, err1)
+      call OcnTracerHadv3Tend(grid, u, h_edge, tracers, tend, err2)
+      call OcnTracerHadv4Tend(grid, u, h_edge, tracers, tend, err3)
+
+      err = err1 .or. err2 .or. err3
+
+   !--------------------------------------------------------------------
+
+   end subroutine OcnTracerHadvTend
+
+!***********************************************************************
+!
+!  routine OcnTracerHadvInit
+!
+!&gt; \brief   Initializes ocean tracer horizontal advection quantities
+!&gt; \author  Phil Jones, Doug Jacobsen
+!&gt; \date    15 September 2011
+!&gt; \version SVN:$Id$
+!&gt; \details 
+!&gt;  This routine initializes a variety of quantities related to 
+!&gt;  horizontal velocity advection in the ocean. Since a variety of 
+!&gt;  parameterizations are available, this routine primarily calls the
+!&gt;  individual init routines for each parameterization. 
+!
+!-----------------------------------------------------------------------
+
+
+   subroutine OcnTracerHadvInit(err)
+
+   !--------------------------------------------------------------------
+
+      !-----------------------------------------------------------------
+      !
+      ! call individual init routines for each parameterization
+      !
+      !-----------------------------------------------------------------
+
+      integer, intent(out) :: err
+
+      integer :: err1, err2, err3
+
+      call OcnTracerHadv2Init(err1)
+      call OcnTracerHadv3Init(err2)
+      call OcnTracerHadv4Init(err3)
+
+      err = err1 .or. err2 .or. err3
+
+   !--------------------------------------------------------------------
+
+   end subroutine OcnTracerHadvInit
+
+!***********************************************************************
+
+end module OcnTracerHadv
+
+!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Added: branches/ocean_projects/performance/src/core_ocean/module_OcnTracerHadv2.F
===================================================================
--- branches/ocean_projects/performance/src/core_ocean/module_OcnTracerHadv2.F                                (rev 0)
+++ branches/ocean_projects/performance/src/core_ocean/module_OcnTracerHadv2.F        2011-09-20 17:15:08 UTC (rev 1012)
@@ -0,0 +1,205 @@
+!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+!
+!  OcnTracerHadv2
+!
+!&gt; \brief MPAS ocean horizontal tracer advection 2nd order
+!&gt; \author Doug Jacobsen
+!&gt; \date   16 September 2011
+!&gt; \version SVN:$Id:$
+!&gt; \details
+!&gt;  This module contains the main driver routine for computing 
+!&gt;  horizontal advection tendencies.  
+!
+!-----------------------------------------------------------------------
+
+module OcnTracerHadv2
+
+   use grid_types
+   use configure
+   use timer
+
+   implicit none
+   private
+   save
+
+   !--------------------------------------------------------------------
+   !
+   ! Public parameters
+   !
+   !--------------------------------------------------------------------
+
+   !--------------------------------------------------------------------
+   !
+   ! Public member functions
+   !
+   !--------------------------------------------------------------------
+
+   public :: OcnTracerHadv2Tend, &amp;
+             OcnTracerHadv2Init
+
+   !--------------------------------------------------------------------
+   !
+   ! Private module variables
+   !
+   !--------------------------------------------------------------------
+
+   logical :: hadv2On
+
+!***********************************************************************
+
+contains
+
+!***********************************************************************
+!
+!  routine OcnTracerHadv2Tend
+!
+!&gt; \brief   Computes tendency term for horizontal tracer advection
+!&gt; \author  Phil Jones, Doug Jacobsen
+!&gt; \date    15 September 2011
+!&gt; \version SVN:$Id$
+!&gt; \details 
+!&gt;  This routine computes the horizontal advection tendency for tracer
+!&gt;  based on current state and user choices of advection parameterization.
+!&gt;  Multiple parameterizations may be chosen and added together.  These
+!&gt;  tendencies are generally computed by calling the specific routine
+!&gt;  for the chosen parameterization, so this routine is primarily a
+!&gt;  driver for managing these choices.
+!
+!-----------------------------------------------------------------------
+
+   subroutine OcnTracerHadv2Tend(grid, u, h_edge, tracers , tend, err)
+
+      !-----------------------------------------------------------------
+      !
+      ! input variables
+      !
+      !-----------------------------------------------------------------
+
+      real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         u    !&lt; Input: velocity
+
+      real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         h_edge     !&lt; Input: thickness at edge
+
+      real (kind=RKIND), dimension(:,:,:), intent(in) :: &amp;
+        tracers     !&lt; Input: tracers
+
+      type (mesh_type), intent(in) :: &amp;
+         grid          !&lt; Input: grid information
+
+      !-----------------------------------------------------------------
+      !
+      ! input/output variables
+      !
+      !-----------------------------------------------------------------
+
+      real (kind=RKIND), dimension(:,:,:), intent(inout) :: &amp;
+         tend          !&lt; Input/Output: velocity tendency
+
+      !-----------------------------------------------------------------
+      !
+      ! output variables
+      !
+      !-----------------------------------------------------------------
+
+      integer, intent(out) :: err
+
+      !-----------------------------------------------------------------
+      !
+      ! local variables
+      !
+      !-----------------------------------------------------------------
+
+      integer :: iEdge, nEdges, cell1, cell2, iTracer, num_tracers, k
+
+      integer, dimension(:), pointer :: maxLevelEdgeTop
+      integer, dimension(:,:), pointer :: cellsOnEdge
+
+      real (kind=RKIND) :: flux, tracer_edge
+
+      real (kind=RKIND), dimension(:), pointer :: dvEdge, areaCell
+
+      !-----------------------------------------------------------------
+      !
+      ! call relevant routines for computing tendencies
+      ! note that the user can choose multiple options and the 
+      !   tendencies will be added together
+      !
+      !-----------------------------------------------------------------
+
+      err = 0
+
+      if(.not.hadv2On) return
+
+      call timer_start(&quot;compute_scalar_tend-horiz adv 2&quot;)
+
+      nEdges = grid % nEdges
+      maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
+      cellsOnEdge =&gt; grid % cellsOnEdge % array
+      dvEdge =&gt; grid % dvEdge % array
+      areaCell =&gt; grid % areaCell % array
+      num_tracers = size(tracers, 1)
+
+      do iEdge=1,nEdges
+         cell1 = cellsOnEdge(1,iEdge)
+         cell2 = cellsOnEdge(2,iEdge)
+         do k=1,maxLevelEdgeTop(iEdge)
+            do iTracer=1,num_tracers
+               tracer_edge = 0.5 * (tracers(iTracer,k,cell1) + tracers(iTracer,k,cell2))
+               flux = u(k,iEdge) * dvEdge(iEdge) * h_edge(k,iEdge) * tracer_edge
+               tend(iTracer,k,cell1) = tend(iTracer,k,cell1) - flux/areaCell(cell1)
+               tend(iTracer,k,cell2) = tend(iTracer,k,cell2) + flux/areaCell(cell2)
+            end do
+         end do
+      end do
+
+      call timer_stop(&quot;compute_scalar_tend-horiz adv 2&quot;)
+   !--------------------------------------------------------------------
+
+   end subroutine OcnTracerHadv2Tend
+
+!***********************************************************************
+!
+!  routine OcnTracerHadv2Init
+!
+!&gt; \brief   Initializes ocean tracer horizontal advection quantities
+!&gt; \author  Phil Jones, Doug Jacobsen
+!&gt; \date    15 September 2011
+!&gt; \version SVN:$Id$
+!&gt; \details 
+!&gt;  This routine initializes a variety of quantities related to 
+!&gt;  horizontal velocity advection in the ocean. Since a variety of 
+!&gt;  parameterizations are available, this routine primarily calls the
+!&gt;  individual init routines for each parameterization. 
+!
+!-----------------------------------------------------------------------
+
+
+   subroutine OcnTracerHadv2Init(err)
+
+   !--------------------------------------------------------------------
+
+      !-----------------------------------------------------------------
+      !
+      ! call individual init routines for each parameterization
+      !
+      !-----------------------------------------------------------------
+
+      integer, intent(out) :: err
+
+      err = 0
+      hadv2On = .false.
+
+      if (config_tracer_adv_order == 2) then
+          hadv2On = .true.
+      end if
+
+   !--------------------------------------------------------------------
+
+   end subroutine OcnTracerHadv2Init
+
+!***********************************************************************
+
+end module OcnTracerHadv2
+
+!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Added: branches/ocean_projects/performance/src/core_ocean/module_OcnTracerHadv3.F
===================================================================
--- branches/ocean_projects/performance/src/core_ocean/module_OcnTracerHadv3.F                                (rev 0)
+++ branches/ocean_projects/performance/src/core_ocean/module_OcnTracerHadv3.F        2011-09-20 17:15:08 UTC (rev 1012)
@@ -0,0 +1,254 @@
+!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+!
+!  OcnTracerHadv3
+!
+!&gt; \brief MPAS ocean horizontal tracer advection 3rd order
+!&gt; \author Doug Jacobsen
+!&gt; \date   16 September 2011
+!&gt; \version SVN:$Id:$
+!&gt; \details
+!&gt;  This module contains the main driver routine for computing 
+!&gt;  horizontal advection tendencies.  
+!
+!-----------------------------------------------------------------------
+
+module OcnTracerHadv3
+
+   use grid_types
+   use configure
+   use timer
+
+   implicit none
+   private
+   save
+
+   !--------------------------------------------------------------------
+   !
+   ! Public parameters
+   !
+   !--------------------------------------------------------------------
+
+   !--------------------------------------------------------------------
+   !
+   ! Public member functions
+   !
+   !--------------------------------------------------------------------
+
+   public :: OcnTracerHadv3Tend, &amp;
+             OcnTracerHadv3Init
+
+   !--------------------------------------------------------------------
+   !
+   ! Private module variables
+   !
+   !--------------------------------------------------------------------
+
+   logical :: hadv3On
+   real (kind=RKIND) :: coef_3rd_order
+
+!***********************************************************************
+
+contains
+
+!***********************************************************************
+!
+!  routine OcnTracerHadv3Tend
+!
+!&gt; \brief   Computes tendency term for horizontal tracer advection
+!&gt; \author  Phil Jones, Doug Jacobsen
+!&gt; \date    15 September 2011
+!&gt; \version SVN:$Id$
+!&gt; \details 
+!&gt;  This routine computes the horizontal advection tendency for tracer
+!&gt;  based on current state and user choices of advection parameterization.
+!&gt;  Multiple parameterizations may be chosen and added together.  These
+!&gt;  tendencies are generally computed by calling the specific routine
+!&gt;  for the chosen parameterization, so this routine is primarily a
+!&gt;  driver for managing these choices.
+!
+!-----------------------------------------------------------------------
+
+   subroutine OcnTracerHadv3Tend(grid, u, h_edge, tracers , tend, err)
+
+      !-----------------------------------------------------------------
+      !
+      ! input variables
+      !
+      !-----------------------------------------------------------------
+
+      real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         u    !&lt; Input: velocity
+
+      real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         h_edge     !&lt; Input: thickness at edge
+
+      real (kind=RKIND), dimension(:,:,:), intent(in) :: &amp;
+        tracers     !&lt; Input: tracers
+
+      type (mesh_type), intent(in) :: &amp;
+         grid          !&lt; Input: grid information
+
+      !-----------------------------------------------------------------
+      !
+      ! input/output variables
+      !
+      !-----------------------------------------------------------------
+
+      real (kind=RKIND), dimension(:,:,:), intent(inout) :: &amp;
+         tend          !&lt; Input/Output: velocity tendency
+
+      !-----------------------------------------------------------------
+      !
+      ! output variables
+      !
+      !-----------------------------------------------------------------
+
+      integer, intent(out) :: err
+
+      !-----------------------------------------------------------------
+      !
+      ! local variables
+      !
+      !-----------------------------------------------------------------
+
+      integer :: iEdge, nEdges, cell1, cell2, iTracer, num_tracers, i, k
+
+      integer, dimension(:), pointer :: maxLevelEdgeTop, nEdgesOnCell
+      integer, dimension(:,:), pointer :: cellsOnEdge, cellsOnCell, &amp;
+                                          boundaryCell
+
+      real (kind=RKIND) :: flux, tracer_edge, d2fdx2_cell1, d2fdx2_cell2
+
+      real (kind=RKIND), dimension(:), pointer :: dvEdge, dcEdge, areaCell
+      real (kind=RKIND), dimension(:,:,:), pointer :: deriv_two
+
+      !-----------------------------------------------------------------
+      !
+      ! call relevant routines for computing tendencies
+      ! note that the user can choose multiple options and the 
+      !   tendencies will be added together
+      !
+      !-----------------------------------------------------------------
+
+      err = 0
+
+      if(.not.hadv3On) return
+
+      nEdges = grid % nEdges
+      num_tracers = size(tracers, dim=1)
+      maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
+      nEdgesOnCell =&gt; grid % nEdgesOnCell % array
+      boundaryCell =&gt; grid % boundaryCell % array
+      cellsOnEdge =&gt; grid % cellsOnEdge % array
+      cellsOnCell =&gt; grid % cellsOnCell % array
+      dvEdge =&gt; grid % dvEdge % array
+      dcEdge =&gt; grid % dcEdge % array
+      areaCell =&gt; grid % areaCell % array
+      deriv_two =&gt; grid % deriv_two % array
+
+      call timer_start(&quot;compute_scalar_tend-horiz adv 3&quot;)
+      do iEdge=1,nEdges
+         cell1 = cellsOnEdge(1,iEdge)
+         cell2 = cellsOnEdge(2,iEdge)
+
+         do k=1,maxLevelEdgeTop(iEdge)
+
+            d2fdx2_cell1 = 0.0
+            d2fdx2_cell2 = 0.0
+
+            do iTracer=1,num_tracers
+
+               !-- if not a boundary cell
+               if(boundaryCell(k,cell1).eq.0.and.boundaryCell(k,cell2).eq.0) then
+
+                  d2fdx2_cell1 = deriv_two(1,1,iEdge) * tracers(iTracer,k,cell1)
+                  d2fdx2_cell2 = deriv_two(1,2,iEdge) * tracers(iTracer,k,cell2)
+
+                  !-- all edges of cell 1
+                  do i=1,nEdgesOnCell(cell1)
+                     d2fdx2_cell1 = d2fdx2_cell1 + &amp;
+                     deriv_two(i+1,1,iEdge) * tracers(iTracer,k,cellsOnCell(i,cell1))
+                  end do
+
+                  !-- all edges of cell 2
+                  do i=1,nEdgesOnCell(cell2)
+                     d2fdx2_cell2 = d2fdx2_cell2 + &amp;
+                     deriv_two(i+1,2,iEdge) * tracers(iTracer,k,cellsOnCell(i,cell2))
+                  end do
+
+               endif
+
+               !-- if u &gt; 0:
+               if (u(k,iEdge) &gt; 0) then
+                  flux = dvEdge(iEdge) * u(k,iEdge) * h_edge(k,iEdge) * (          &amp;
+                       0.5*(tracers(iTracer,k,cell1) + tracers(iTracer,k,cell2))      &amp;
+                       -(dcEdge(iEdge) **2) * (d2fdx2_cell1 + d2fdx2_cell2) / 12.          &amp;
+                       -(dcEdge(iEdge) **2) * coef_3rd_order*(d2fdx2_cell1 - d2fdx2_cell2) / 12. )
+               !-- else u &lt;= 0:
+               else
+                  flux = dvEdge(iEdge) *  u(k,iEdge) * h_edge(k,iEdge) * (          &amp;
+                       0.5*(tracers(iTracer,k,cell1) + tracers(iTracer,k,cell2))      &amp;
+                       -(dcEdge(iEdge) **2) * (d2fdx2_cell1 + d2fdx2_cell2) / 12.          &amp;
+                       +(dcEdge(iEdge) **2) * coef_3rd_order*(d2fdx2_cell1 - d2fdx2_cell2) / 12. )
+               end if
+
+               !-- update tendency
+               tend(iTracer,k,cell1) = tend(iTracer,k,cell1) - flux/areaCell(cell1)
+               tend(iTracer,k,cell2) = tend(iTracer,k,cell2) + flux/areaCell(cell2)
+            enddo
+         end do
+      end do
+      call timer_stop(&quot;compute_scalar_tend-horiz adv 3&quot;)
+
+   !--------------------------------------------------------------------
+
+   end subroutine OcnTracerHadv3Tend
+
+!***********************************************************************
+!
+!  routine OcnTracerHadv3Init
+!
+!&gt; \brief   Initializes ocean tracer horizontal advection quantities
+!&gt; \author  Phil Jones, Doug Jacobsen
+!&gt; \date    15 September 2011
+!&gt; \version SVN:$Id$
+!&gt; \details 
+!&gt;  This routine initializes a variety of quantities related to 
+!&gt;  horizontal velocity advection in the ocean. Since a variety of 
+!&gt;  parameterizations are available, this routine primarily calls the
+!&gt;  individual init routines for each parameterization. 
+!
+!-----------------------------------------------------------------------
+
+
+   subroutine OcnTracerHadv3Init(err)
+
+   !--------------------------------------------------------------------
+
+      !-----------------------------------------------------------------
+      !
+      ! call individual init routines for each parameterization
+      !
+      !-----------------------------------------------------------------
+
+      integer, intent(out) :: err
+
+      err = 0
+      hadv3On = .false.
+
+      if (config_tracer_adv_order == 3) then
+          hadv3On = .true.
+
+          coef_3rd_order = 1.0
+          if (config_monotonic) coef_3rd_order = 0.25
+      end if
+
+   !--------------------------------------------------------------------
+
+   end subroutine OcnTracerHadv3Init
+
+!***********************************************************************
+
+end module OcnTracerHadv3
+
+!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Added: branches/ocean_projects/performance/src/core_ocean/module_OcnTracerHadv4.F
===================================================================
--- branches/ocean_projects/performance/src/core_ocean/module_OcnTracerHadv4.F                                (rev 0)
+++ branches/ocean_projects/performance/src/core_ocean/module_OcnTracerHadv4.F        2011-09-20 17:15:08 UTC (rev 1012)
@@ -0,0 +1,239 @@
+!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+!
+!  OcnTracerHadv4
+!
+!&gt; \brief MPAS ocean horizontal tracer advection 4th order
+!&gt; \author Doug Jacobsen
+!&gt; \date   16 September 2011
+!&gt; \version SVN:$Id:$
+!&gt; \details
+!&gt;  This module contains the main driver routine for computing 
+!&gt;  horizontal advection tendencies.  
+!
+!-----------------------------------------------------------------------
+
+module OcnTracerHadv4
+
+   use grid_types
+   use configure
+   use timer
+
+   implicit none
+   private
+   save
+
+   !--------------------------------------------------------------------
+   !
+   ! Public parameters
+   !
+   !--------------------------------------------------------------------
+
+   !--------------------------------------------------------------------
+   !
+   ! Public member functions
+   !
+   !--------------------------------------------------------------------
+
+   public :: OcnTracerHadv4Tend, &amp;
+             OcnTracerHadv4Init
+
+   !--------------------------------------------------------------------
+   !
+   ! Private module variables
+   !
+   !--------------------------------------------------------------------
+
+   logical :: hadv4On
+
+!***********************************************************************
+
+contains
+
+!***********************************************************************
+!
+!  routine OcnTracerHadv4Tend
+!
+!&gt; \brief   Computes tendency term for horizontal tracer advection
+!&gt; \author  Phil Jones, Doug Jacobsen
+!&gt; \date    15 September 2011
+!&gt; \version SVN:$Id$
+!&gt; \details 
+!&gt;  This routine computes the horizontal advection tendency for tracer
+!&gt;  based on current state and user choices of advection parameterization.
+!&gt;  Multiple parameterizations may be chosen and added together.  These
+!&gt;  tendencies are generally computed by calling the specific routine
+!&gt;  for the chosen parameterization, so this routine is primarily a
+!&gt;  driver for managing these choices.
+!
+!-----------------------------------------------------------------------
+
+   subroutine OcnTracerHadv4Tend(grid, u, h_edge, tracers , tend, err)
+
+      !-----------------------------------------------------------------
+      !
+      ! input variables
+      !
+      !-----------------------------------------------------------------
+
+      real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         u    !&lt; Input: velocity
+
+      real (kind=RKIND), dimension(:,:), intent(in) :: &amp;
+         h_edge     !&lt; Input: thickness at edge
+
+      real (kind=RKIND), dimension(:,:,:), intent(in) :: &amp;
+        tracers     !&lt; Input: tracers
+
+      type (mesh_type), intent(in) :: &amp;
+         grid          !&lt; Input: grid information
+
+      !-----------------------------------------------------------------
+      !
+      ! input/output variables
+      !
+      !-----------------------------------------------------------------
+
+      real (kind=RKIND), dimension(:,:,:), intent(inout) :: &amp;
+         tend          !&lt; Input/Output: velocity tendency
+
+      !-----------------------------------------------------------------
+      !
+      ! output variables
+      !
+      !-----------------------------------------------------------------
+
+      integer, intent(out) :: err
+
+      !-----------------------------------------------------------------
+      !
+      ! local variables
+      !
+      !-----------------------------------------------------------------
+
+      integer :: iEdge, nEdges, cell1, cell2, iTracer, num_tracers, i, k
+
+      integer, dimension(:), pointer :: maxLevelEdgeTop
+      integer, dimension(:,:), pointer :: cellsOnEdge, cellsOnCell, boundaryCell
+
+      real (kind=RKIND) :: flux, tracer_edge, d2fdx2_cell1, d2fdx2_cell2
+
+      real (kind=RKIND), dimension(:), pointer :: dvEdge, dcEdge, areaCell
+      real (kind=RKIND), dimension(:,:,:), pointer :: deriv_two
+
+      !-----------------------------------------------------------------
+      !
+      ! call relevant routines for computing tendencies
+      ! note that the user can choose multiple options and the 
+      !   tendencies will be added together
+      !
+      !-----------------------------------------------------------------
+
+      err = 0
+
+      if(.not.hadv4On) return
+
+      nEdges = grid % nEdges
+      num_tracers = size(tracers, dim=1)
+      maxLevelEdgeTop =&gt; grid % maxLevelEdgeTop % array
+      boundaryCell =&gt; grid % boundaryCell % array
+      cellsOnEdge =&gt; grid % cellsOnEdge % array
+      cellsOnCell =&gt; grid % cellsOnCell % array
+      dvEdge =&gt; grid % dvEdge % array
+      dcEdge =&gt; grid % dcEdge % array
+      areaCell =&gt; grid % areaCell % array
+      deriv_two =&gt; grid % deriv_two % array
+
+      call timer_start(&quot;compute_scalar_tend-horiz adv 4&quot;)
+
+      do iEdge=1,nEdges
+         cell1 = cellsOnEdge(1,iEdge)
+         cell2 = cellsOnEdge(2,iEdge)
+
+         do k=1,maxLevelEdgeTop(iEdge)
+
+            d2fdx2_cell1 = 0.0
+            d2fdx2_cell2 = 0.0
+
+            do iTracer=1,num_tracers
+
+               !-- if not a boundary cell
+               if(boundaryCell(k,cell1).eq.0.and.boundaryCell(k,cell2).eq.0) then
+
+                  d2fdx2_cell1 = deriv_two(1,1,iEdge) * tracers(iTracer,k,cell1)
+                  d2fdx2_cell2 = deriv_two(1,2,iEdge) * tracers(iTracer,k,cell2)
+
+                  !-- all edges of cell 1
+                  do i=1, grid % nEdgesOnCell % array (cell1)
+                     d2fdx2_cell1 = d2fdx2_cell1 + &amp;
+                     deriv_two(i+1,1,iEdge) * tracers(iTracer,k,cellsOnCell(i,cell1))
+                  end do
+
+                  !-- all edges of cell 2
+                  do i=1, grid % nEdgesOnCell % array (cell2)
+                      d2fdx2_cell2 = d2fdx2_cell2 + &amp;
+                      deriv_two(i+1,2,iEdge) * tracers(iTracer,k,cellsOnCell(i,cell2))
+                  end do
+
+               endif
+
+               flux = dvEdge(iEdge) *  u(k,iEdge) * h_edge(k,iEdge) * (          &amp;
+                    0.5*(tracers(iTracer,k,cell1) + tracers(iTracer,k,cell2))      &amp;
+                       -(dcEdge(iEdge) **2) * (d2fdx2_cell1 + d2fdx2_cell2) / 12. )
+
+               !-- update tendency
+               tend(iTracer,k,cell1) = tend(iTracer,k,cell1) - flux/areaCell(cell1)
+               tend(iTracer,k,cell2) = tend(iTracer,k,cell2) + flux/areaCell(cell2)
+            enddo
+         end do
+      end do
+      call timer_stop(&quot;compute_scalar_tend-horiz adv 4&quot;)
+
+   !--------------------------------------------------------------------
+
+   end subroutine OcnTracerHadv4Tend
+
+!***********************************************************************
+!
+!  routine OcnTracerHadv4Init
+!
+!&gt; \brief   Initializes ocean tracer horizontal advection quantities
+!&gt; \author  Phil Jones, Doug Jacobsen
+!&gt; \date    15 September 2011
+!&gt; \version SVN:$Id$
+!&gt; \details 
+!&gt;  This routine initializes a variety of quantities related to 
+!&gt;  horizontal velocity advection in the ocean. Since a variety of 
+!&gt;  parameterizations are available, this routine primarily calls the
+!&gt;  individual init routines for each parameterization. 
+!
+!-----------------------------------------------------------------------
+
+
+   subroutine OcnTracerHadv4Init(err)
+
+   !--------------------------------------------------------------------
+
+      !-----------------------------------------------------------------
+      !
+      ! call individual init routines for each parameterization
+      !
+      !-----------------------------------------------------------------
+
+      integer, intent(out) :: err
+
+      err = 0
+      hadv4On = .false.
+
+      if (config_tracer_adv_order == 4) then
+          hadv4On = .true.
+      end if
+
+   !--------------------------------------------------------------------
+
+   end subroutine OcnTracerHadv4Init
+
+!***********************************************************************
+
+end module OcnTracerHadv4
+
+!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

</font>
</pre>