PROGRAM Out_of_Bounds_Subscripts
!-----------------------------------------------------------------------
! Program to demonstrate what may result when subscripts get out of 
! bounds.  Variables used are:
!     A, B, C : one-dimensional arrays of integers
!
! Output:  Arrays A, B, and C before and after subscripts get out of
!          range
!-----------------------------------------------------------------------
  IMPLICIT NONE
  INTEGER, DIMENSION(4) :: &
      A = (/ 1, 2, 3, 4 /), &
      B = (/ 5, 6, 7, 8 /), &
      C = (/ 9, 10, 11, 12 /)
  INTEGER :: I

  ! Display the original arrays

  PRINT 100, "A =", A
  PRINT 100, "B =", B
  PRINT 100, "C =", C
  100 FORMAT(' ', A, 4I5)

  ! Reference array B with a subscript that is out of bounds

  I = -2
  B(I) = -999
  B(I+9) = 999

  ! Print each of the arrays again

  PRINT *
  PRINT 100, "A =", A
  PRINT 100, "B =", B
  PRINT 100, "C =", C
  STOP
END PROGRAM Out_of_Bounds_Subscripts
