!------------------------------------------------------------------------------
!
!  Program name:
!
!    vector_subscript
!
!  Purpose:
!
!    This program demonstrates the use of vector subscript.
!
!    It declares a vector subscript, iv, with extent 5. From the array 
!    constructed in matrix.f90 (read in from the file matrix.dat) it
!    creates a 9x5 array containing only the odd values.
!
!------------------------------------------------------------------------------

PROGRAM vector_subscript

  IMPLICIT NONE
  INTEGER, PARAMETER :: n = 9
  INTEGER, DIMENSION (n,n) :: ia
  INTEGER, DIMENSION (5) :: iv
  INTEGER, DIMENSION (n,5) :: i5x5
  INTEGER :: i

  ! read matrix ia from the file matrix.dat generated by matrix.f90
  WRITE(*,'(//"Read in array from the file matrix.dat:"/)')
  OPEN (UNIT = 1, FILE = 'matrix.dat')
  READ (1, *) ia
  CLOSE (1)

  ! Write out whole array, rowwise:
  WRITE(*,'(9i5)') (ia(i,:), i = 1, n)

  ! Construct an array of odd values using vector subscript:
  WRITE(*,'(//"Construct an array of odd values using vector subscript:"/)')

  iv = (/ 1, 3, 5, 7, 9 /)
  i5x5 = ia(:,iv)

  ! Write out array of odd values, rowwise:
  WRITE(*,'(5i5)') (i5x5(i,:), i = 1, n)

END PROGRAM vector_subscript
