!+ Program to convert from humidity mxing ratios to specific humidity.
!
! 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 HMRSPH
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_field.ucf'
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/error.pcf'
      INCLUDE 'incl/samson_pstar.ecf'
!
!     DECLARATION OF VARIABLES.
      CHARACTER
     &     FILE_HMR*80
!             FILE OF HUMIDITY MIXING RATIOS
     &   , FILE_SPH*80
!             FILE OF SPECIFIC HUMIDITIES
     &   , TITLE_HMR*80
!             TITLE OF INPUT FILE
     &   , TITLE_SPH*80
!             TITLE OF OUTPUT FILE
      INTEGER
     &     IERR
!             ERROR FLAG
     &   , N_PROFILE
!             NUMBER OF PROFILES
     &   , N_LEVEL
!             NUMBER OF LEVELS
     &   , I
!             LOOP VARIABLE
     &   , L
!             LOOP VARIABLE
      REAL*8
     &     P(NPD_PROFILE, NPD_LAYER+1)
!             PRESSURE LEVELS
     &   , Q(NPD_PROFILE, NPD_LAYER+1)
!             SPECIFIC HUMIDITY
     &   , R(NPD_PROFILE, NPD_LAYER+1)
!             HUMIDITY MIXING RATIO
     &   , PSTAR(NPD_PROFILE)
!             SURFACE PRESSURE
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     READ_SAMSON_FIELD, WRITE_SAMSON_FIELD
!
!
      DATA PSTAR/NPD_PROFILE*PSTAR_DEFAULT/
      DATA TITLE_SPH(1:43)
     &   /' Water Vapour Mass Mixing Ratio (converted)'/
!
!
!
      WRITE(IU_USER, '(/A)')
     &     'ENTER NAME OF FILE CONTAINING HUMIDITY MIXING RATIO.'
      READ(IU_STDIN, '(A)') FILE_HMR
      CALL READ_SAMSON_FIELD(IERR, .TRUE., .FALSE.
     &   , FILE_HMR, TITLE_HMR
     &   , N_PROFILE, N_LEVEL, P, PSTAR, R)
      N_LEVEL=N_LEVEL+1
      IF (IERR.NE.I_NORMAL) STOP
!
      DO I=1, N_LEVEL
         DO L=1, N_PROFILE
            Q(L, I)=R(L, I)/(1.0D+00+R(L, I))
         ENDDO
      ENDDO
!
      WRITE(IU_USER, '(/A)') 'ENTER NAME OF OUTPUT FILE.'
      READ(IU_STDIN, '(A)') FILE_SPH
      CALL WRITE_SAMSON_FIELD(IERR, .FALSE.
     &   , FILE_SPH, TITLE_SPH
     &   , N_PROFILE, N_LEVEL-1, P, PSTAR, Q)
      IF (IERR.NE.I_NORMAL) STOP
!
!
      STOP
      END
