!+ Program to form a SAMSON-file of mid-points.
!
! Method:
!	A SAMSON-file is read in, giving the boundaries of layers.
!	A SAMSON-file with levels at the mid-points of these layers 
!	is written out with a zero field.
!
! 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 MID_POINT
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/dimensions_field.ucf'
      INCLUDE 'incl/samson_parm.ecf'
      INCLUDE 'incl/samson_pstar.ecf'
      INCLUDE 'incl/error.pcf'
!
!     DECLARATION OF VARIABLES.
      CHARACTER
     &     FILE_IN*80
!             NAME OF INPUT FILE
     &   , FILE_OUT*80
!             NAME OF OUTPUT FILE
     &   , TITLE_IN*80
!             TITLE OF INPUT FILE
     &   , TITLE_OUT*80
!             TITLE OF OUTPUT FILE
!
      INTEGER
     &     IERR
!             ERROR FLAG
     &   , N_PROFILE_IN
!             NUMBER OF INPUT PROFILES
     &   , N_LEVEL_IN
!             NUMBER OF INPUT LEVELS
     &   , N_LAYER_OUT
!             NUMBER OF LAYERS IN OUTPUT
     &   , N_PROFILE_OUT
!             NUMBER OF PROFILES IN OUTPUT
     &   , I
!             LOOP VARIABLE
     &   , L
!             LOOP VARIABLE
      REAL*8
     &     FIELD_IN(NPD_PROFILE, NPD_LAYER+1)
!             INPUT FIELD
     &   , FIELD_OUT(NPD_PROFILE, NPD_LAYER+1)
!             OUTPUT FIELD
     &   , P_IN(NPD_LAYER+1)
!             PRESSURE FOR INTERPOLATION
     &   , P_OUT(NPD_LAYER+1)
!             PRESSURE LEVELS OF OUTPUT FIELD
     &   , pstar
!             SURFACE PRESSURE
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     READ_SAMSON_FIELD, WRITE_SAMSON_FIELD
!
!
      DATA PSTAR/PSTAR_DEFAULT/
!
!
!
!     READ IN THE BASIC FIELD.
      WRITE(IU_USER, '(/A)')
     &   'ENTER THE NAME OF THE INPUT FILE.'
      READ(IU_STDIN, '(A)') FILE_IN
      CALL READ_SAMSON_FIELD(IERR, .TRUE., .FALSE.
     &   , FILE_IN, TITLE_IN
     &   , N_PROFILE_IN, N_LEVEL_IN, P_IN, PSTAR, FIELD_IN)
      IF (IERR.NE.I_NORMAL) STOP
      N_LEVEL_IN=N_LEVEL_IN+1
!     READ IN THE NAME OF THE OUTPUT FILE.
      WRITE(IU_USER, '(/A)')
     &   'ENTER THE NAME OF THE OUTPUT FILE.'
      READ(IU_STDIN, '(A)') FILE_OUT
!
!     THE OUTPUT FIELD IS GIVEN IN LAYERS.
      N_LAYER_OUT=N_LEVEL_IN-1
      N_PROFILE_OUT=N_PROFILE_IN
      DO I=1, N_LAYER_OUT
         P_OUT(I)=0.5D+00*(P_IN(I+1)+P_IN(I))
      ENDDO
      DO L=1, N_PROFILE_IN
         DO I=1, N_LAYER_OUT
            FIELD_OUT(L, I)=0.0D+00
         ENDDO
      ENDDO
      TITLE_OUT(1:80)='Null Field'//'          '
     &              //'                    '
     &              //'                    '
     &              //'                    '
!
      CALL WRITE_SAMSON_FIELD(IERR, .FALSE.
     &   , FILE_OUT, TITLE_OUT
     &   , N_PROFILE_OUT, N_LAYER_OUT-1, P_OUT, PSTAR, FIELD_OUT)
!
!
      STOP
      END
