!+ Program to convert from hybrid coordinates to pure pressure levels.
!
! Method:
!	Straightforward.
!
! Current Owner of Code: J. M. Edwards
!
! History:
!	Version		Date		Comment
!	1.0		12-04-95	First Version under RCS
!					(J. M. Edwards)
!
! Description of Code:
!   FORTRAN 77 with extensions listed in documentation.
!
!- ---------------------------------------------------------------------
      PROGRAM HYBTOPL
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_field.ucf'
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/error.pcf'
      INCLUDE 'incl/physical_constants_0.ccf'
      INCLUDE 'incl/samson_pstar.ecf'
!
!     DECLARATION OF VARIABLES.
      CHARACTER
     &     FILE_HYBRID*80
!             NAME OF FILE WITH HYBRID FIELD
     &   , FILE_PSTAR*80
!             NAME OF FILE OF SURFACE PRESSURES
     &   , FILE_OUT*80
!             NAME OF OUTPUT FILE
     &   , TITLE_FIELD*80
!             NAME OF FIELD
      INTEGER
     &     IERR
!             ERROR FLAG
     &   , N_PROFILE
!             NUMBER OF PROFILES
     &   , N_PROFILE_PSTAR
!             NUMBER OF PROFILES IN PSTAR
     &   , N_LEVEL
!             NUMBER OF LEVELS
     &   , N_DUM
!             DUMMY VARIABLE
      REAL*8
     &     P(NPD_PROFILE, NPD_LAYER+1)
!             PRESSURE LEVELS
     &   , X(NPD_PROFILE, NPD_LAYER+1)
!             FIELD
     &   , PSTAR_DUM(NPD_PROFILE)
!             DUMMY SURFACE PRESSURE
     &   , PSTAR(NPD_PROFILE)
!             SURFACE PRESSURE
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     READ_SAMSON_FIELD, WRITE_SAMSON_FIELD
!
!
      DATA PSTAR_DUM/NPD_PROFILE*PSTAR_DEFAULT/
!
!
!
      WRITE(IU_USER, '(/A)')
     &     'ENTER NAME OF FILE THE HYBRID FIELD.'
      READ(IU_STDIN, '(A)') FILE_HYBRID
      WRITE(IU_USER, '(/A)')
     &     'ENTER NAME OF FILE THE SURFACE PRESSURES.'
      READ(IU_STDIN, '(A)') FILE_PSTAR
      CALL READ_SAMSON_FIELD(IERR, .TRUE., .FALSE.
     &   , FILE_PSTAR, TITLE_FIELD
     &   , N_PROFILE_PSTAR, N_DUM, P, PSTAR_DUM, PSTAR)
      CALL READ_SAMSON_FIELD(IERR, .TRUE., .FALSE.
     &   , FILE_HYBRID, TITLE_FIELD
     &   , N_PROFILE, N_LEVEL, P, PSTAR, X)
      N_LEVEL=N_LEVEL+1
      IF (IERR.NE.I_NORMAL) STOP
      IF (N_PROFILE_PSTAR.NE.N_PROFILE) THEN
         WRITE(IU_ERR, '(/A)')
     &      '*** ERROR: INPUT FILES HAVE DIFFERENT NUMBERS OF PROFILES.'
         STOP
      ENDIF
!
      WRITE(IU_USER, '(/A)') 'ENTER NAME OF OUTPUT FILE.'
      READ(IU_STDIN, '(A)') FILE_OUT
      CALL WRITE_SAMSON_FIELD(IERR, .FALSE.
     &   , FILE_OUT, TITLE_FIELD
     &   , N_PROFILE, N_LEVEL-1, P, PSTAR_DUM, X)
      IF (IERR.NE.I_NORMAL) STOP
!
!
      STOP
      END
