PROGRAM CALC
!     Last change:  X     8 Nov 2004    9:25 pm
!-----------------------------------------------------------------------------
!                                                           Date:
! Names:
!
! Program to calculate the input into the second program
!
! Variables use are:
!
! Input  :
! Output :
!-----------------------------------------------------------------------------
IMPLICIT NONE

REAL (KIND=8) :: x, rootR, rootL, dist1, dist2, a, b, chopper, x0, x1
INTEGER :: temp, i
CHARACTER(1) :: answer

WRITE (*,*) "Does this root have roots on both sides of it? (y/n) "
READ (*,*) answer

IF (answer == "n" .OR. answer == "N") THEN
   DO i = 1,1,1
      WRITE (*,*) "Enter the root, and the root value next to it: "
      READ (*,*) x, rootL

      !!! rounds each variable to 4 places after the decimal
      temp = x*10000.0D0
      chopper = (x - REAL(temp)/10000.0D0)
      x = x - chopper

      temp = rootL*10000.0D0
      chopper = rootL - REAL(temp)/10000.0D0
      rootL = rootL - chopper
   END DO

   dist1 = ABS(x-rootL)
   a = dist1 * 0.1D0
   b = dist1 * 0.3D0
   x0 = x - a
   x1 = x + b
   WRITE (*,*) "The value of x0 is: ", x0, "and the value of x1 is: ", x1

   ELSE

   WRITE(*,*) "Enter a root x, the root on the left, and the root on the right: "
   READ(*,*) x, rootL, rootR

   ! rounds each variable to 4 places after the decimol
   temp = x*10000.0D0
   chopper = x - REAL(temp)/10000.0D0
   x = x - chopper

   temp = rootL*10000.0D0
   chopper = rootL - REAL(temp)/10000.0D0
   rootL = rootL - chopper

   temp = rootR*10000.0D0
   chopper = rootR - REAL(temp)/10000.0D0
   rootR = rootR - chopper

   ! Determines distance to use
   dist1 = ABS(x - rootL)
   dist2 = ABS(rootR - x)
      IF (dist1 < dist2) THEN
         a = 0.1D0 * dist1
         b = 0.3D0 * dist1
      ELSE
         a = 0.1D0 * dist2
         b = 0.3D0 * dist2
     END IF

   x0 = x - a
   x1 = x + b
   WRITE(*,*) "The value for x0 is: ", x0
   WRITE(*,*) "The value for x1 is: ", x1
   END IF
STOP
END PROGRAM CALC
