      SUBROUTINE get_data (ng)
!
!svn $Id: get_data.F 337 2009-03-25 20:09:58Z arango $
!================================================== Hernan G. Arango ===
!  Copyright (c) 2002-2009 The ROMS/TOMS Group                         !
!    Licensed under a MIT/X style license                              !
!    See License_ROMS.txt                                              !
!=======================================================================
!                                                                      !
!  This routine reads in forcing, climatology and assimilation data    !
!  from input NetCDF files.  If there is more than one time-record,    !
!  data  is loaded  into global two-time record arrays.  The actual    !
!  interpolation is carried elsewhere.                                 !
!                                                                      !
!  Currently,  this routine is only executed in serial mode by the     !
!  main thread.                                                        !
!                                                                      !
!=======================================================================
!
      USE mod_param
      USE mod_boundary
      USE mod_forces
      USE mod_grid
      USE mod_iounits
      USE mod_ncparam
      USE mod_scalars
      USE mod_sources
      USE mod_stepping
!
      implicit none
!
!  Imported variable declarations.
!
      integer, intent(in) :: ng
!
!  Local variable declarations.
!
      logical, dimension(3) :: update =                                 &
     &         (/ .FALSE., .FALSE., .FALSE. /)
      integer :: ILB, IUB, JLB, JUB
      integer :: LBi, UBi, LBj, UBj
      integer :: i
!
!  Lower and upper bounds for nontiled boundary arrays.
!
      ILB=0
      IUB=Im(ng)+1
      JLB=0
      JUB=Jm(ng)+1
!
!  Lower and upper bounds for tiled arrays.
!
      LBi=LBOUND(GRID(ng)%h,DIM=1)
      UBi=UBOUND(GRID(ng)%h,DIM=1)
      LBj=LBOUND(GRID(ng)%h,DIM=2)
      UBj=UBOUND(GRID(ng)%h,DIM=2)
!
!-----------------------------------------------------------------------
!  Turn on input data time wall clock.
!-----------------------------------------------------------------------
!
      CALL wclock_on (ng, iNLM, 3)
!
!=======================================================================
!  Read in forcing data from FORCING NetCDF file.
!=======================================================================
!
!
!-----------------------------------------------------------------------
!  Point Sources/Sinks time dependent data.
!-----------------------------------------------------------------------
!
!
!  Point Source/Sink vertically integrated mass transport.
!
      CALL get_ngfld (ng, iNLM, idRtra, ncFRCid(idRtra,ng),             &
     &                nFfiles(ng), FRCname(1,ng), update(1),            &
     &                1, Nsrc(ng), 1, 2, 1, Nsrc(ng), 1,                &
     &                SOURCES(ng) % QbarG(1,1))
!
!  Tracer Sources/Sinks.
!
      DO i=1,NT(ng)
        IF (SOURCES(ng)%Ltracer(i)) THEN
          CALL get_ngfld (ng, iNLM, idRtrc(i), ncFRCid(idRtrc(i),ng),   &
     &                    nFfiles(ng), FRCname(1,ng), update(1),        &
     &                    1, Nsrc(ng), N(ng), 2, 1, Nsrc(ng), N(ng),    &
     &                    SOURCES(ng) % TsrcG(1,1,1,i))
        END IF
      END DO
!
!-----------------------------------------------------------------------
!  Surface wind stress components.
!-----------------------------------------------------------------------
!
      CALL get_2dfld (ng, iNLM, idUsms, ncFRCid(idUsms,ng),             &
     &                nFfiles(ng), FRCname(1,ng), update(1),            &
     &                LBi, UBi, LBj, UBj, 2, 1,                         &
     &                GRID(ng) % umask(LBi,LBj),                        &
     &                FORCES(ng) % sustrG(LBi,LBj,1))
      CALL get_2dfld (ng, iNLM, idVsms, ncFRCid(idVsms,ng),             &
     &                nFfiles(ng), FRCname(1,ng), update(1),            &
     &                LBi, UBi, LBj, UBj, 2, 1,                         &
     &                GRID(ng) % vmask(LBi,LBj),                        &
     &                FORCES(ng) % svstrG(LBi,LBj,1))
!    added by Liejun ZHONG / UMCES, 2007/5/15
!
!  MUST UNDEF QCORRECTION
!  Sea surface temeprature relaxation: sea surface temperature
!  (SST) and nudging coefficient (TnudgSST).
!     
      CALL get_2dfld (ng, iNLM, idSSTc, ncFRCid(idSSTc,ng),             &
     &                nFfiles(ng), FRCname(1,ng), update(1),            &
     &                LBi, UBi, LBj, UBj, 2, 1,                         &
     &                GRID(ng) % rmask(LBi,LBj),                        &
     &                FORCES(ng) % sstG(LBi,LBj,1))
      CALL get_2dfld (ng, iNLM, idTnudgSST, ncFRCid(idTnudgSST,ng),     &
     &                nFfiles(ng), FRCname(1,ng), update(1),            &
     &                LBi, UBi, LBj, UBj, 2, 1,                         &
     &                GRID(ng) % rmask(LBi,LBj),                        &
     &                FORCES(ng) % TnudgSSTG(LBi,LBj,1))
!
!=======================================================================
!  Read in open boundary conditions from BOUNDARY NetCDF file.
!=======================================================================
!
      CALL get_ngfld (ng, iNLM, idZbry(ieast), ncBRYid(ng), 1,          &
     &                BRYname(ng), update(1),                           &
     &                JLB, JUB, 1, 2, 0, Mm(ng)+1, 1,                   &
     &                BOUNDARY(ng) % zetaG_east(JLB,1))
      CALL get_ngfld (ng, iNLM, idU2bc(ieast), ncBRYid(ng), 1,          &
     &                BRYname(ng), update(1),                           &
     &                JLB, JUB, 1, 2, 0, Mm(ng)+1, 1,                   &
     &                BOUNDARY(ng) % ubarG_east(JLB,1))
      CALL get_ngfld (ng, iNLM, idV2bc(ieast), ncBRYid(ng), 1,          &
     &                BRYname(ng), update(1),                           &
     &                JLB, JUB, 1, 2, 1, Mm(ng)+1, 1,                   &
     &                BOUNDARY(ng) % vbarG_east(JLB,1))
      DO i=1,NT(ng)
        CALL get_ngfld (ng, iNLM, idTbry(ieast,i), ncBRYid(ng), 1,      &
     &                  BRYname(ng), update(1),                         &
     &                  JLB, JUB, N(ng), 2, 0, Mm(ng)+1, N(ng),         &
     &                  BOUNDARY(ng) % tG_east(JLB,1,1,i))
      END DO
!
!-----------------------------------------------------------------------
!  Turn off input data time wall clock.
!-----------------------------------------------------------------------
!
      CALL wclock_off (ng, iNLM, 3)
      RETURN
      END SUBROUTINE get_data
