!===============================================================================
! SVN $Id: seq_avdata_mod.F90 40372 2012-09-18 23:34:49Z tcraig $
! SVN $URL: https://svn-ccsm-models.cgd.ucar.edu/drv/seq_mct/branch_tags/rasm_tags/rasm04_cesm1_1_0_n01_drvseq4_2_08/driver/seq_avdata_mod.F90 $
!===============================================================================
!BOP ===========================================================================
!
! !MODULE: seq_avdata_mod -- provides use access to public cpl7 aVect, domain,
!     and fraction data.
!
! !DESCRIPTION:
!
!    provides use access to public cpl7 aVect, domain, and fraction data.
!
! !REMARKS:
!
!    use access to public cpl7 aVect, domain, and fraction info is to avoid 
!    excessively long routine arg lists, eg. for history & restart modules.
!    Note: while cpl7's non-main program ("driver") routines CAN access this
!    data by use'ing this module, they SHOULD access it via agrument lists 
!    if it is reasonable to do so.  Do the right thing.
!
! !REVISION HISTORY:
!     2009-Sep-25 - B. Kauffman - initial version
!
! !INTERFACE: ------------------------------------------------------------------

module seq_avdata_mod

! !USES:

   use shr_kind_mod  ,only: IN => SHR_KIND_IN
   use mct_mod           ! mct_ wrappers for mct lib

   use seq_cdata_mod     ! "cdata" type & methods (domain + decomp + infodata in one datatype)
   use seq_infodata_mod  ! "infodata" gathers various control flags into one datatype
   use seq_comm_mct, only : num_inst_atm, num_inst_lnd, num_inst_ocn, &
                            num_inst_ice, num_inst_glc, num_inst_rof

   implicit none

   public  ! default is public

! !PUBLIC DATA MEMBERS:

   !----------------------------------------------------------------------------
   ! Infodata: inter-model control flags, domain info
   !----------------------------------------------------------------------------

   type (seq_infodata_type) :: infodata ! single instance for cpl and all comps

   !----------------------------------------------------------------------------
   ! cdata types: contains pointers to domain info + component ID + infobuffer
   !----------------------------------------------------------------------------

   type (seq_cdata) :: cdata_aa(num_inst_atm)    ! on component pes
   type (seq_cdata) :: cdata_ll(num_inst_lnd)
   type (seq_cdata) :: cdata_oo(num_inst_ocn)
   type (seq_cdata) :: cdata_ii(num_inst_ice)
   type (seq_cdata) :: cdata_rr(num_inst_rof)
   type (seq_cdata) :: cdata_gg(num_inst_glc)
   type (seq_cdata) :: cdata_ss(num_inst_lnd)

   type (seq_cdata) :: cdata_ax    ! on cpl pes
   type (seq_cdata) :: cdata_lx
   type (seq_cdata) :: cdata_ox
   type (seq_cdata) :: cdata_ix
   type (seq_cdata) :: cdata_rx
   type (seq_cdata) :: cdata_gx
   type (seq_cdata) :: cdata_sx

   !----------------------------------------------------------------------------
   ! domain info: coords, fractions, decomps, area correction factors
   !----------------------------------------------------------------------------

   !--- domain coords, area, mask  (MCT General Grids) --

   type(mct_gGrid) :: dom_aa(num_inst_atm)      ! atm domain on atm pes
   type(mct_gGrid) :: dom_ll(num_inst_lnd)      ! lnd domain
   type(mct_gGrid) :: dom_ii(num_inst_ice)      ! ice domain
   type(mct_gGrid) :: dom_oo(num_inst_ocn)      ! ocn domain
   type(mct_gGrid) :: dom_rr(num_inst_rof)      ! runoff domain
   type(mct_gGrid) :: dom_gg(num_inst_glc)      ! glc domain
   type(mct_gGrid) :: dom_ss(num_inst_lnd)      ! sno domain

   type(mct_gGrid) :: dom_ax      ! atm domain on cpl pes
   type(mct_gGrid) :: dom_lx      ! lnd domain
   type(mct_gGrid) :: dom_ix      ! ice domain
   type(mct_gGrid) :: dom_ox      ! ocn domain
   type(mct_gGrid) :: dom_rx      ! runoff domain
   type(mct_gGrid) :: dom_gx      ! glc domain
   type(mct_gGrid) :: dom_sx      ! sno domain

   !--- domain fractions (only defined on cpl pes) ---

   type(mct_aVect),pointer :: fractions_ax(:)   ! Fractions on atm grid
   type(mct_aVect),pointer :: fractions_lx(:)   ! Fractions on lnd grid 
   type(mct_aVect),pointer :: fractions_ix(:)   ! Fractions on ice grid
   type(mct_aVect),pointer :: fractions_ox(:)   ! Fractions on ocn grid
   type(mct_aVect),pointer :: fractions_gx(:)   ! Fractions on glc grid
   type(mct_aVect),pointer :: fractions_rx(:)   ! Fractions on rof grid

   !----------------------------------------------------------------------------
   ! State/flux field bundles (MCT attribute vectors)
   !----------------------------------------------------------------------------

   type(mct_aVect) :: x2a_aa(num_inst_atm)    ! Atm import, atm grid, atm pes - allocated in atm gc
   type(mct_aVect) :: a2x_aa(num_inst_atm)    ! Atm export, atm grid, atm pes - allocated in atm gc

   type(mct_aVect) :: x2a_ax(num_inst_atm)    ! Atm import, atm grid, cpl pes - allocated in driver
   type(mct_aVect) :: a2x_ax(num_inst_atm)    ! Atm export, atm grid, cpl pes - allocated in driver
   type(mct_aVect) :: a2x_lx(num_inst_atm)    ! Atm export, lnd grid, cpl pes - allocated in driver
   type(mct_aVect) :: a2x_ix(num_inst_atm)    ! Atm export, ice grid, cpl pes - allocated in driver
   type(mct_aVect) :: a2x_ox(num_inst_atm)    ! Atm export, ocn grid, cpl pes - allocated in driver

   type(mct_aVect) :: x2l_ll(num_inst_lnd)    ! Lnd import, lnd grid, lnd pes - allocated in lnd gc
   type(mct_aVect) :: l2x_ll(num_inst_lnd)    ! Lnd export, lnd grid, lnd pes - allocated in lnd gc

   type(mct_aVect) :: x2l_lx(num_inst_lnd)    ! Lnd import, lnd grid, cpl pes - allocated in driver
   type(mct_aVect) :: l2x_lx(num_inst_lnd)    ! Lnd export, lnd grid, cpl pes - allocated in driver
   type(mct_aVect) :: l2racc_lx(num_inst_lnd) ! Lnd export, lnd grid, cpl pes - allocated in driver
   type(mct_aVect) :: l2r_rx                  ! Lnd export, rof grid, cpl pes - allocated in driver, temporary single instance
   type(mct_aVect) :: l2x_ax(num_inst_lnd)    ! Lnd export, atm grid, cpl pes - allocated in driver

   type(mct_aVect) :: x2r_rr(num_inst_rof)    ! Rof import, rof grid, lnd pes - allocated in lnd gc
   type(mct_aVect) :: r2x_rr(num_inst_rof)    ! Rof export, rof grid, lnd pes - allocated in lnd gc

   type(mct_aVect) :: x2r_rx(num_inst_rof)    ! Rof import, rof grid, lnd pes - allocated in lnd gc
   type(mct_aVect) :: r2x_rx(num_inst_rof)    ! Rof export, rof grid, cpl pes - allocated in driver
   type(mct_aVect) :: r2oacc_rx(num_inst_rof) ! Rof export, rof grid, cpl pes - allocated in driver
   type(mct_aVect) :: r2x_lx(num_inst_rof)    ! Rof export, lnd grid, lnd pes - allocated in lnd gc
   type(mct_aVect) :: r2o_ox(num_inst_rof)    ! Rof export, ocn grid, cpl pes - allocated in driver

   type(mct_aVect) :: x2s_ss(num_inst_lnd)    ! Sno import, sno grid, sno pes - allocated in lnd gc
   type(mct_aVect) :: s2x_ss(num_inst_lnd)    ! Sno export, sno grid, sno pes - allocated in lnd gc

   type(mct_aVect) :: x2s_sx(num_inst_lnd)    ! Sno import, sno grid, cpl pes - allocated in driver
   type(mct_aVect) :: s2x_sx(num_inst_lnd)    ! Sno export, sno grid, cpl pes - allocated in driver
   type(mct_aVect) :: s2x_gx(num_inst_lnd)    ! Sno export, glc grid, cpl pes - allocated in driver

   type(mct_aVect) :: x2i_ii(num_inst_ice)    ! Ice import, ice grid, ice pes - allocated in ice gc
   type(mct_aVect) :: i2x_ii(num_inst_ice)    ! Ice export, ice grid, ice pes - allocated in ice gc

   type(mct_aVect) :: x2i_ix(num_inst_ice)    ! Ice import, ice grid, cpl pes - allocated in driver
   type(mct_aVect) :: i2x_ix(num_inst_ice)    ! Ice export, ice grid, cpl pes - allocated in driver
   type(mct_aVect) :: i2x_ax(num_inst_ice)    ! Ice export, atm grid, cpl pes - allocated in driver
   type(mct_aVect) :: i2x_ox(num_inst_ice)    ! Ice export, ocn grid, cpl pes - allocated in driver

   type(mct_aVect) :: x2o_oo(num_inst_ocn)    ! Ocn import, ocn grid, ocn pes - allocated in ocn gc
   type(mct_aVect) :: o2x_oo(num_inst_ocn)    ! Ocn export, ocn grid, ocn pes - allocated in ocn gc

   type(mct_aVect) :: x2o_ox(num_inst_ocn)    ! Ocn import, ocn grid, cpl pes - allocated in driver
   type(mct_aVect) :: x2oacc_ox(num_inst_ocn) ! Ocn import, ocn grid, cpl pes - allocated in driver
   type(mct_aVect) :: o2x_ox(num_inst_ocn)    ! Ocn export, ocn grid, cpl pes - allocated in driver
   type(mct_aVect) :: o2x_ax(num_inst_ocn)    ! Ocn export, atm grid, cpl pes - allocated in driver
   type(mct_aVect) :: o2x_ix(num_inst_ocn)    ! Ocn export, ice grid, cpl pes - allocated in driver

   type(mct_aVect),pointer :: xao_ox(:)       ! Atm-ocn fluxes, ocn grid, cpl pes - allocated in driver
   type(mct_aVect),pointer :: xao_ax(:)       ! Atm-ocn fluxes, atm grid, cpl pes - allocated in driver
   type(mct_aVect),pointer :: xao_ix(:)       ! Atm-ocn fluxes, ice grid, cpl pes - allocated in driver

   type(mct_aVect) :: x2g_gg(num_inst_glc)    ! Glc import, glc grid, ice pes - allocated in glc gc
   type(mct_aVect) :: g2x_gg(num_inst_glc)    ! Glc export, glc grid, ice pes - allocated in glc gc

   type(mct_aVect) :: x2g_gx(num_inst_glc)    ! Glc import, glc grid, cpl pes - allocated in driver
   type(mct_aVect) :: g2x_gx(num_inst_glc)    ! Glc export, glc grid, cpl pes - allocated in driver
   type(mct_aVect) :: g2x_sx(num_inst_glc)    ! Glc export, sno grid, cpl pes - allocated in driver

   integer(IN)     :: r2oacc_rx_cnt ! r2oacc_rx: number of time samples accumulated
   integer(IN)     :: x2oacc_ox_cnt ! x2oacc_ox: number of time samples accumulated
   integer(IN)     :: l2racc_lx_cnt ! l2racc_lx: number of time samples accumulated

! !PUBLIC MEMBER FUNCTIONS

   ! no public routines

! !PUBLIC TYPES:

   ! no public types

end module seq_avdata_mod

!===============================================================================
