PROGRAM Road_Construction
!-----------------------------------------------------------------------
! Program to approximate the volume of dirt to be removed in
! constructing a section of highway through a hill.  Identifiers
! used are:
!   Length    : length of the section of road
!   Width     : width of the road
!   FileName  : name of data file containing hill information
!   NumPoints : the number of points where height of hill was measured
!   DeltaX    : distance between points
!   I         : counter
!   Y         : the height of the hill
!   Sum       : sum approximating the integral for cross-sectional area
!                of the hill
!
! Input (keyboard): Length, Width
! Input (file)    : NumPoints and values of Y (heights of hill)
! Output:         : Volume of dirt to be removed
!-----------------------------------------------------------------------

  IMPLICIT NONE
  REAL :: Length, Width, Delta_X, Y, Sum
  INTEGER :: NumPoints, I
  CHARACTER(20) :: FileName

  ! Get road information and name of data file containing hill information

  WRITE (*, '(1X, A)', ADVANCE = "NO") &
        "Enter length and width of section of road (in feet): "
  READ *, Length, Width
  WRITE (*, '(1X, A)', ADVANCE = "NO") &
         "Enter name of file containing hill information: "
  READ *, FileName

  ! Open the data file, read the number of points at which height of hill
  ! was measured, and compute the distance between these points

  OPEN (UNIT = 10, FILE = FileName, STATUS = "OLD", &
        ACTION = "READ", POSITION = "REWIND")
  READ (10, *) NumPoints
  Delta_X = Length / REAL(NumPoints - 1)

  ! Initialize the approximating Sum
  READ (10, *) Y
  Sum = Y / 2.0

  ! Now calculate Sum, which approximates cross-sectional area of hill
  DO I = 1, NumPoints - 2
     READ (10, *) Y
     Sum = Sum + Y
  END DO

  READ (10, *) Y
  Sum = Sum + Y / 2.0
  Sum = Delta_X * Sum

  PRINT *, "Volume of dirt to be removed is approximately"
  PRINT *, Sum * Width, "cubic feet."

END PROGRAM Road_Construction
