!+ Program to increment a SAMSON field.
!
! Method:
!	An increment is added to a SAMSON field within a range of
!	pressures.
!
! 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 INC_FIELD
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/dimensions_field.ucf'
      INCLUDE 'incl/error.pcf'
      INCLUDE 'incl/samson_pstar.ecf'
!
!     DECLARATION OF VARIABLES.
      CHARACTER
     &     FILE_IN*80
!             NAME OF INPUT FILE
     &   , TITLE*80
!             TITLE OF FILE
     &   , TITLE_OUT*80
!             TITLE OF OUTPUT FILE
     &   , CHAR_YN*1
!             REPONSE VARIABLE
     &   , FILE_OUT*80
!             OUTPUT FILE
      INTEGER
     &     IERR
!             ERROR FLAG
     &   , IOS
!             I/O ERROR FLAG
     &   , N_PROFILE
!             NUMBER OF PROFILES
     &   , N_LAYER
!             NUMBER OF LAYERS
     &   , I
!             LOOP VARIABLE
     &   , L
!             LOOP VARIABLE
      REAL*8
     &     P(NPD_LAYER+1)
!             PRESSURE LAYER
     &   , PSTAR
!             SURFACE PRESSURE
     &   , FIELD(NPD_PROFILE, NPD_LAYER+1)
!             FIELD READ IN
     &   , P_LOW
!             LOW SCALING PRESSURE
     &   , P_HIGH
!             HIGH SCALING PRESSURE
     &   , INCREMENT
!             INCREMENT
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     READ_SAMSON_FIELD, WRITE_SAMSON_FIELD
!
!
      DATA PSTAR/PSTAR_DEFAULT/
!
!
!
      WRITE(IU_USER, '(/A)') 'ENTER NAME OF FILE FOR INCREMENTING.'
      READ(IU_STDIN, '(A)') FILE_IN
      CALL READ_SAMSON_FIELD(IERR, .TRUE., .FALSE.
     &   , FILE_IN, TITLE
     &   , N_PROFILE, N_LAYER, P, PSTAR, FIELD
     &   )
      IF (IERR.NE.I_NORMAL) STOP
!
1     WRITE(IU_USER, '(/A)') 'ENTER RANGE OF PRESSURES '
     &   //'FOR INCREMENTING.'
      READ(IU_STDIN, *, IOSTAT=IOS) P_LOW, P_HIGH
      IF (IOS.NE.0) THEN
         WRITE(IU_ERR, '(A)') '+++ ILLEGAL RESPONSE: PLEASE REENTER.'
         GOTO 1
      ENDIF
2     WRITE(IU_USER, '(/A)') 'ENTER INCREMENT.'
      READ(IU_STDIN, *, IOSTAT=IOS) INCREMENT
      IF (IOS.NE.0) THEN
         WRITE(IU_ERR, '(A)') '+++ ILLEGAL RESPONSE: PLEASE REENTER.'
         GOTO 2
      ENDIF
      DO I=1, N_LAYER+1
         IF ( (P(I).GE.P_LOW).AND.(P(I).LE.P_HIGH) ) THEN
            DO L=1, N_PROFILE
               FIELD(L, I)=FIELD(L, I)+INCREMENT
            ENDDO
         ENDIF
      ENDDO
!
      WRITE(IU_USER, '(/A)') 'INCREMENT A NEW RANGE? (Y/N)'
      READ(IU_STDIN, '(A)') CHAR_YN
      IF ( (CHAR_YN.EQ.'Y').OR.(CHAR_YN.EQ.'y') ) GOTO 1
!
      WRITE(IU_USER, '(/A)') 'ENTER NAME OF OUTPUT FILE'
      READ(IU_STDIN, '(A)') FILE_OUT
      WRITE(IU_USER, '(/A)') 'ENTER TITLE OF OUTPUT FILE'
      READ(IU_STDIN, '(A)') TITLE_OUT
      CALL WRITE_SAMSON_FIELD(IERR, .FALSE.
     &   , FILE_OUT, TITLE_OUT
     &   , N_PROFILE, N_LAYER, P, PSTAR, FIELD)
      IF (IERR.NE.I_NORMAL) STOP
!
!
      STOP
      END
