      MODULE mod_boundary
!
!svn $Id: mod_boundary.F 314 2009-02-20 22:06:49Z arango $
!================================================== Hernan G. Arango ===
!  Copyright (c) 2002-2009 The ROMS/TOMS Group                         !
!    Licensed under a MIT/X style license                              !
!    See License_ROMS.txt                                              !
!=======================================================================
!                                                                      !
!  Open boundary conditions arrays:                                    !
!                                                                      !
!  zeta_east      Free-surface (m) eastern boundary conditions.        !
!  zetaG_east     Latest two-time snapshots of input free-surface (m)  !
!                   eastern boundary data.                             !
!  ubar_east      2D u-momentum (m/s) eastern boundary conditions.     !
!  vbar_east      2D v-momentum (m/s) eastern boundary conditions.     !
!  ubarG_east     Latest two-time snapshots of input 2D u-momentum     !
!                   (m/s) eastern boundary data.                       !
!  vbarG_east     Latest two-time snapshots of input 2D v-momentum     !
!                   (m/s) eastern boundary data.                       !
!  t_east         Tracer (T units) eastern boundary conditions.        !
!  tG_east        Latest two-time snapshots of input tracer (Tunits)   !
!                   eastern boundary data.                             !
!                                                                      !
!=======================================================================
!
        USE mod_kinds
        implicit none
        TYPE T_BOUNDARY
!
!  Nonlinear model state.
!
          real(r8), pointer :: zeta_east(:)
          real(r8), pointer :: zetaG_east(:,:)
          real(r8), pointer :: ubar_east(:)
          real(r8), pointer :: vbar_east(:)
          real(r8), pointer :: ubarG_east(:,:)
          real(r8), pointer :: vbarG_east(:,:)
          real(r8), pointer :: t_east(:,:,:)
          real(r8), pointer :: tG_east(:,:,:,:)
        END TYPE T_BOUNDARY
        TYPE (T_BOUNDARY), allocatable ::BOUNDARY(:)
      CONTAINS
      SUBROUTINE allocate_boundary (ng)
!
!=======================================================================
!                                                                      !
!  This routine initializes all variables in the module for all nested !
!  grids.  Currently, there is not parallel tiling in boundary arrays. !
!                                                                      !
!=======================================================================
!
      USE mod_param
!
!  Imported variable declarations.
!
      integer, intent(in) :: ng
!
!-----------------------------------------------------------------------
!  Initialize module variables.
!-----------------------------------------------------------------------
!
      IF (ng.eq.1) allocate ( BOUNDARY(Ngrids) )
!
!  Nonlinear model state.
!
      allocate ( BOUNDARY(ng) % zeta_east(0:Jm(ng)+1) )
      allocate ( BOUNDARY(ng) % zetaG_east(0:Jm(ng)+1,2) )
      allocate ( BOUNDARY(ng) % ubar_east(0:Jm(ng)+1) )
      allocate ( BOUNDARY(ng) % vbar_east(0:Jm(ng)+1) )
      allocate ( BOUNDARY(ng) % ubarG_east(0:Jm(ng)+1,2) )
      allocate ( BOUNDARY(ng) % vbarG_east(0:Jm(ng)+1,2) )
      allocate ( BOUNDARY(ng) % t_east(0:Jm(ng)+1,N(ng),NT(ng)) )
      allocate ( BOUNDARY(ng) % tG_east(0:Jm(ng)+1,N(ng),2,NT(ng)) )
      RETURN
      END SUBROUTINE allocate_boundary
      SUBROUTINE initialize_boundary (ng, tile, model)
!
!=======================================================================
!                                                                      !
!  This routine initialize all variables in the module using first     !
!  touch distribution policy. In shared-memory configuration, this     !
!  operation actually performs propagation of the  "shared arrays"     !
!  across the cluster, unless another policy is specified to           !
!  override the default.                                               !
!                                                                      !
!=======================================================================
!
      USE mod_param
!
!  Imported variable declarations.
!
      integer, intent(in) :: ng, tile, model
!
!  Local variable declarations.
!
      real(r8), parameter :: IniVal = 0.0_r8
!
!-----------------------------------------------------------------------
!  Initialize module variables.
!-----------------------------------------------------------------------
!
!  Nonlinear model state.
!
      IF ((model.eq.0).or.(model.eq.iNLM)) THEN
        IF (.TRUE.) THEN
          BOUNDARY(ng) % zeta_east = IniVal
          BOUNDARY(ng) % zetaG_east = IniVal
        END IF
        IF (.TRUE.) THEN
          BOUNDARY(ng) % ubar_east = IniVal
          BOUNDARY(ng) % vbar_east = IniVal
          BOUNDARY(ng) % ubarG_east = IniVal
          BOUNDARY(ng) % vbarG_east = IniVal
        END IF
        IF (.TRUE.) THEN
          BOUNDARY(ng) % t_east = IniVal
          BOUNDARY(ng) % tG_east = IniVal
        END IF
      END IF
      RETURN
      END SUBROUTINE initialize_boundary
      END MODULE mod_boundary
