<p><b>dwj07@fsu.edu</b> 2012-12-18 13:51:47 -0700 (Tue, 18 Dec 2012)</p><p><br>
        -- BRANCH COMMIT --<br>
<br>
        Adding coupled forcing driver.<br>
</p><hr noshade><pre><font color="gray">Added: branches/ocean_projects/generic_forcing/src/core_ocean/mpas_ocn_forcing_coupled.F
===================================================================
--- branches/ocean_projects/generic_forcing/src/core_ocean/mpas_ocn_forcing_coupled.F                                (rev 0)
+++ branches/ocean_projects/generic_forcing/src/core_ocean/mpas_ocn_forcing_coupled.F        2012-12-18 20:51:47 UTC (rev 2359)
@@ -0,0 +1,234 @@
+!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+!
+!  ocn_forcing_coupled
+!
+!&gt; \brief MPAS ocean coupled forcing
+!&gt; \author Doug Jacobsen
+!&gt; \date   04/25/12
+!&gt; \version SVN:$Id:$
+!&gt; \details
+!&gt;  This module contains routines for building the forcing arrays,
+!&gt;  if coupled forcing is used.
+!
+!-----------------------------------------------------------------------
+
+module ocn_forcing_coupled
+
+   use mpas_kind_types
+   use mpas_grid_types
+   use mpas_configure
+   use mpas_timekeeping
+   use ocn_constants
+
+   implicit none
+   private
+   save
+
+   !--------------------------------------------------------------------
+   !
+   ! Public parameters
+   !
+   !--------------------------------------------------------------------
+
+   !--------------------------------------------------------------------
+   !
+   ! Public member functions
+   !
+   !--------------------------------------------------------------------
+
+   public :: ocn_build_forcing_arrays_coupled, &amp;
+             ocn_forcing_coupled_init
+
+   !--------------------------------------------------------------------
+   !
+   ! Private module variables
+   !
+   !--------------------------------------------------------------------
+
+   logical :: coupledForcingOn !&lt; Flag to turn on/off coupled forcing
+
+!***********************************************************************
+
+contains
+
+!***********************************************************************
+!
+!  routine ocn_build_forcing_arrays
+!
+!&gt; \brief   Determines the forcing array used for the coupled forcing.
+!&gt; \author  Doug Jacobsen
+!&gt; \date    04/25/12
+!&gt; \version SVN:$Id$
+!&gt; \details 
+!&gt;  This routine computes the forcing arrays used later in MPAS.
+!
+!-----------------------------------------------------------------------
+
+   subroutine ocn_build_forcing_arrays_coupled(timeStamp, grid, err)!{{{
+
+      !-----------------------------------------------------------------
+      !
+      ! input variables
+      !
+      !-----------------------------------------------------------------
+
+      type(MPAS_Time_type), intent(in) :: timeStamp
+
+      !-----------------------------------------------------------------
+      !
+      ! input/output variables
+      !
+      !-----------------------------------------------------------------
+
+      type (mesh_type), intent(inout) :: &amp;
+         grid          !&lt; Input: grid information
+
+
+      !-----------------------------------------------------------------
+      !
+      ! output variables
+      !
+      !-----------------------------------------------------------------
+
+      integer, intent(out) :: err !&lt; Output: Error flag
+
+      !-----------------------------------------------------------------
+      !
+      ! local variables
+      !
+      !-----------------------------------------------------------------
+
+      integer :: iEdge, cell1, cell2
+      integer :: iCell
+      integer :: index_temperature_flux, index_salinity_flux
+
+      integer, dimension(:,:), pointer :: cellsOnEdge
+
+      real :: meridionalAverage, zonalAverage
+      real, dimension(:), pointer :: windStress, angleEdge
+      real, dimension(:), pointer :: zonalWindStress, meridionalWindStress
+      real, dimension(:), pointer :: latentHeatFlux, sensibleHeatFlux, longWaveHeatFluxUp, longWaveHeatFluxDown, evaportationFlux, seaIceHeatFlux, snowFlux
+      real, dimension(:), pointer :: seaIceFreshWaterFlux, seaIceSalinityFlux, riverRunoffFlux, iceRunoffFlux
+
+      real, dimension(:), pointer :: rainFlux
+      real, dimension(:), pointer :: seaLevelPressure, iceFraction
+
+      real, dimension(:), pointer :: surfaceMassFlux
+      real, dimension(:,:), pointer :: surfaceTracerFlux
+
+
+#ifdef MPAS_CESM
+      index_temperature_flux = grid % index_temperatureFlux
+      index_salinity_flux = grid % index_salinityFlux
+
+      angleEdge =&gt; grid % angleEdge % array
+
+      cellsOnEdge =&gt; grid % cellsOnEdge % array
+
+      windStress =&gt; grid % windStress % array
+      zonalWindStress =&gt; grid % zonalWindStress % array
+      meridionalWindStress =&gt; grid % meridionalWindStress % array
+      latentHeatFlux =&gt; grid % latentHeatFlux % array
+      sensibleHeatFlux =&gt; grid % sensibleHeatFlux % array
+      longWaveHeatFluxUp =&gt; grid % longWaveHeatFluxUp % array
+      longWaveHeatFluxDown =&gt; grid % longWaveHeatFluxDown % array
+      evaporationFlux =&gt; grid % evaporationFlux % array
+      seaIceHeatFlux =&gt; grid % seaIceHeatFlux % array
+      snowFlux =&gt; grid % snowFlux % array
+
+      seaIceFreshWaterFlux =&gt; grid % seaIceFreshWaterFlux % array
+      seaIceSalinityFlux =&gt; grid % seaIceSalinityFlux % array
+      riverRunoffFlux =&gt; grid % riverRunoffFlux % array
+      iceRunoffFlux =&gt; grid % iceRunoffFlux % array
+
+      rainFlux =&gt; grid % rainFlux % array
+
+      seaLevelPressure =&gt; grid % seaLevelPressure % array
+      iceFraction =&gt; grid % iceFration % array
+
+      surfaceMassFlux =&gt; grid % surfaceMassFlux % array
+      surfaceTracerFlux =&gt; grid % surfaceTracerFlux % array
+
+      ! Convert CESM wind stress to MPAS-O windstress
+      do iEdge = 1, grid % nEdges
+        cell1 = cellsOnEdge(1, iEdge)
+        cell2 = cellsOnEdge(2, iEdge)
+
+        zonalAverage = 0.5 * (zonalWindStress(cell1) + zonalWindStress(cell2))
+        meridionalAverage = 0.5 * (meridionalWindStress(cell1) + meridionalWindStress(cell2))
+
+        windStress(iEdge) = cos(angleEdge(iEdge)) * zonalAverage + sin(angleEdge(iEdge)) * meridionalAverage
+      end do
+
+
+      do iCell = 1, grid % nCells
+!       surfaceTracerFlux(index_temperature_flux, iCell) = (latentHeatFlux(iCell) + evaporationFlux(iCell) * latent_heat_vapor_mks + sensibleHeatFlux(iCell) + longWaveHeatFluxUp(iCell) + longWaveHeatFluxDown(iCell) &amp;
+!                                                          + seaIceHeatFlux(iCell) - (snowFlux(iCell) + iceRunoffFlux(iCell)) * latent_heat_fusion_mks) * hflux_factor
+
+        surfaceTracerFlux(index_temperature_flux, iCell) = (latentHeatFlux(iCell) + sensibleHeatFlux(iCell) + longWaveHeatFluxUp(iCell) + longWaveHeatFluxDown(iCell) &amp;
+                                                           + seaIceHeatFlux(iCell) - (snowFlux(iCell) + iceRunoffFlux(iCell)) * latent_heat_fusion_mks) * hflux_factor
+
+        if(config_use_virtual_salinity_flux) then
+           surfaceTracerFlux(index_salinity_flux, iCell) = (rainFlux(iCell) + snowFlux(iCell) + evaportationFlux(iCell) + seaIceFreshWaterFlux(iCell) + riverRunoffFlux(iCell) + iceRunOffFlux(iCell)) * salinity_factor &amp;
+                                                           + seaIceSalinityFlux(iCell) * sflux_factor
+           surfaceMassFlux(iCell) = 0.0_RKIND
+        else
+           surfaceTracerFlux(index_salinity_flux, iCell) = seaIceSalinityFlux(iCell) * sflux_factor
+
+           surfaceMassFlux(iCell) = snowFlux(iCell) + rainFlux(iCell) + evaporationFlux(iCell) + seaIceFreshWaterFlux(iCell) + iceRunoffFlux(iCell) + riverRunoffFlux(iCell)
+        end if
+
+        ! FROM POP -- Heat Fluxes
+!       STF(:,:,1,iblock) = (EVAP_F(:,:,iblock)*latent_heat_vapor_mks         &amp;    
+!                    + SENH_F(:,:,iblock) + LWUP_F(:,:,iblock)        &amp;    
+!                    + LWDN_F(:,:,iblock) + MELTH_F(:,:,iblock)       &amp;    
+!                    -(SNOW_F(:,:,iblock)+IOFF_F(:,:,iblock)) * latent_heat_fusion_mks)*  &amp;
+!                      RCALCT(:,:,iblock)*hflux_factor
+        
+        ! FROM POP -- Salinity Fluxes
+!       STF(:,:,2,iblock) = RCALCT(:,:,iblock)*(  &amp;
+!                    (PREC_F(:,:,iblock)+EVAP_F(:,:,iblock)+  &amp;
+!                     MELT_F(:,:,iblock)+ROFF_F(:,:,iblock)+IOFF_F(:,:,iblock))*salinity_factor   &amp;
+!                   + SALT_F(:,:,iblock)*sflux_factor)
+      end do
+
+
+#endif
+   !--------------------------------------------------------------------
+
+   end subroutine ocn_build_forcing_arrays_coupled!}}}
+
+!***********************************************************************
+!
+!  routine ocn_forcing_coupled_init
+!
+!&gt; \brief   Initializes coupled forcing module
+!&gt; \author  Doug Jacobsen
+!&gt; \date    04/25/12
+!&gt; \version SVN:$Id$
+!&gt; \details 
+!&gt;  This routine initializes the coupled forcing module.
+!
+!-----------------------------------------------------------------------
+
+   subroutine ocn_forcing_coupled_init(err)!{{{
+
+      integer, intent(out) :: err !&lt; Output: error flag
+
+      err = 0
+
+      coupledForcingOn = .false.
+
+      if(config_use_coupled_forcing) then
+        coupledForcingOn = .true.
+      end if
+
+   end subroutine ocn_forcing_coupled_init!}}}
+
+!***********************************************************************
+
+end module ocn_forcing_coupled
+
+
+!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+! vim: foldmethod=marker

</font>
</pre>