!-------------------------------------- LICENCE BEGIN ------------------------------------
!Environment Canada - Atmospheric Science and Technology License/Disclaimer, 
!                     version 3; Last Modified: May 7, 2008.
!This is free but copyrighted software; you can use/redistribute/modify it under the terms 
!of the Environment Canada - Atmospheric Science and Technology License/Disclaimer 
!version 3 or (at your option) any later version that should be found at: 
!http://collaboration.cmc.ec.gc.ca/science/rpn.comm/license.html 
!
!This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
!without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
!See the above mentioned License/Disclaimer for more details.
!You should have received a copy of the License/Disclaimer along with this software; 
!if not, you can write to: EC-RPN COMM Group, 2121 TransCanada, suite 500, Dorval (Quebec), 
!CANADA, H9P 1J3; or send e-mail to service.rpn@ec.gc.ca
!-------------------------------------- LICENCE END --------------------------------------
!     #########################################

      SUBROUTINE INTERP_GRID1D(PZ1,PT1,PZ2,PT2),4
!     #########################################
!!
!!****  *INTERP_GRID1D* - interpolation on the vertical
!!
!!    PURPOSE
!!    -------
!!
!! input  grid/data is (x,z1)
!! output grid/data is (x,z2)
!!
!!**  METHOD
!!    ------
!!
!!    REFERENCE
!!    ---------
!!      
!!
!!    AUTHOR
!!    ------
!!     V. Masson 
!!
!!    MODIFICATIONS
!!    -------------
!!      Original    01/2004
!!------------------------------------------------------------------
!
USE MODD_SURF_PAR,   ONLY : XUNDEF
USE MODI_COEF_VER_INTERP_LIN2D
USE MODI_VER_INTERP_LIN2D
!
!* 0.1 Declaration of dummy arguments
!
REAL, DIMENSION(:,:), INTENT(IN)   :: PZ1  ! input vertical grid
REAL, DIMENSION(:,:), INTENT(IN)   :: PT1  ! input temperatures
REAL, DIMENSION(:),   INTENT(IN)   :: PZ2  ! output vertical grid
REAL, DIMENSION(:,:), INTENT(OUT)  :: PT2  ! output temperatures
!
!* 0.2 Declaration of local variables
!
INTEGER :: JL, JI ! loop counter
REAL,    DIMENSION(SIZE(PZ1,1),SIZE(PZ2)) :: ZZ2      ! output grid
REAL,    DIMENSION(SIZE(PZ1,1),SIZE(PZ2)) :: ZCOEFLIN ! interpolation coefficients
INTEGER, DIMENSION(SIZE(PZ1,1),SIZE(PZ2)) :: IKLIN    ! lower interpolating level of
!                                                     ! grid 1 for each level of grid 2 
!
!-----------------------------------------------------------------------------
DO JL=1,SIZE(PZ2)
  ZZ2(:,JL) = PZ2(JL)
END DO
!
CALL COEF_VER_INTERP_LIN2D(PZ1,ZZ2,KKLIN=IKLIN,PCOEFLIN=ZCOEFLIN)
!
PT2= VER_INTERP_LIN2D(PT1,IKLIN,ZCOEFLIN)
!
!  On reporte le mask sur tous les niveaux
!
DO JL=1,SIZE(PT1,2)
  DO JI=1,SIZE(PT1,1)
    IF (PT1(JI,JL)==XUNDEF) THEN
      PT2(JI,:)=XUNDEF
    ENDIF
  END DO
END DO
!
!-----------------------------------------------------------------------------
END SUBROUTINE INTERP_GRID1D