PROGRAM Finding_Row_Maxima_1
!-----------------------------------------------------------------------
! Program to read an array of numbers and to find the maximum value in
! each row using the subroutine FindRowMaxima.  Identifiers used are:
!   IntArray      : two-dimensional array of numbers
!   NumRows       : number of rows in IntArray (constant)
!   NumColumns    : number of columns in IntArray (constant)
!   FindRowMaxima : subroutine to find the row maxima
!   I, J          : subscripts
!
! Input:  NumRows, NumColumns, and IntArray
! Output: The maximum value in each row (using FindRowMaxima)
!-----------------------------------------------------------------------

  IMPLICIT NONE
  INTEGER, PARAMETER :: NumRows = 4, NumColumns = 5
  INTEGER, DIMENSION(NumRows, NumColumns) :: IntArray
  INTEGER :: I, J

  PRINT *, "Enter the", NumRows, "x", NumColumns, "array of integers &
           &in a rowwise manner:"
  READ *, ((IntArray(I,J), J = 1, NumColumns), I = 1, NumRows)
  
  CALL FindRowMaxima(IntArray)
  
CONTAINS

  !-FindRowMaxima-------------------------------------------------------
  ! Subroutine to find and display the maximum value in each row of an
  ! array Table of integers.  Local identifiers used are:
  !   Rows   : number of rows in array Table (named constant)
  !   Cols   : number of columns in array Table (named constant)
  !   RowMax : one-dimensional array of row maxima
  !   I      : subscript
  !
  ! Accepts: Array Table
  ! Output:  The maximum value in each row of Table
  !---------------------------------------------------------------------
  
  SUBROUTINE FindRowMaxima(Table)
  
    INTEGER, PARAMETER :: Rows = 4, Cols = 5
    INTEGER, DIMENSION(Rows, Cols), INTENT(IN) :: Table
    INTEGER, DIMENSION(Rows) :: RowMax
    INTEGER :: I
  
    RowMax = MAXVAL(Table, 2)  ! Find max values along dimension 2
    DO I = 1, Rows
       PRINT *, "Maximum entry in row", I, "is", RowMax(I)
    END DO
  
  END SUBROUTINE FindRowMaxima
  
END PROGRAM Finding_Row_Maxima_1
