PROGRAM Numbers
    USE double
    IMPLICIT NONE
    CHARACTER(LEN=*), PARAMETER :: filename = "Programs/numbers.data", &
        format = "(I0, ' lines (', I0, ' rejected)', /, &
            & I0, ' numbers, totalling ', F0.3)"
    REAL(KIND=dp), DIMENSION(5) :: scratch
    REAL(KIND=dp) :: total = 0.0_dp
    INTEGER :: lines = 0, badlines = 0, count = 0, err

    OPEN (23, FILE=filename, ACTION="read", IOSTAT=err)
    IF (err /= 0) THEN
        PRINT *, "Unable to open " // filename
        STOP 1
    END IF

    DO
        READ (23, *, IOSTAT=err) scratch
        lines = lines + 1
        IF (err < 0) THEN
            EXIT
        ELSE IF (err > 0) THEN
            badlines = badlines + 1
            CYCLE
        ELSE
            count = count+5
            total = total+sum(scratch)
        END IF
    END DO

    WRITE (*, format) lines, badlines, count, total

END PROGRAM Numbers
