!------------------------------------------------------------------------------
!
!  Program name:
!
!    renum
!
!  Purpose:
!
!    This program illustrates the fact that elements in an expression are 
!    renumbered with 1 as the lower bound in each dimension.
!
!------------------------------------------------------------------------------

PROGRAM renum

  IMPLICIT NONE

  REAL, DIMENSION (-3:4) :: ra
  INTEGER, DIMENSION (1) :: locmax1, locmax2

  ! Assign elements of array ra:
  ra = (/ 1.2, 3.4, 5.4, 11.2, 1.0, 3.7, 1.0, 1.0 /)

  ! Find location of maximum value of whole array:
  ! (Note value given assumes first element has location 1.)
  locmax1 = MAXLOC(ra)
  WRITE(*,*) 'Location of maximum value of whole array is: ', locmax1(1)

  ! Find location of maximum value of array section:
  locmax2 = MAXLOC(ra(1:3))
  WRITE(*,*) 'Location of maximum value of ra(1:3) is: ', locmax2(1)

  WRITE(*,*)
  
  ! Find value of element with maximum value of whole array from location:
  WRITE(*,*) 'Maximum value of whole array is: ', &
             ra(LBOUND(ra) + locmax1(1) - 1)

  ! Check with MAXVAL:
   WRITE(*,*) 'Maximum value of whole array using MAXVAL is: ', MAXVAL(ra)

  WRITE(*,*)

  ! Find value of element with maximum value of array section from location:
  WRITE(*,*) 'Maximum value of ra(1:3) is: ', ra(locmax2(1))
  ! ( Value is ra(1 + locmax2(1) - 1) )

  ! Check with MAXVAL:
  WRITE(*,*) 'Maximum value of ra(1:3) using MAXVAL is: ', MAXVAL(ra(1:3))

END PROGRAM renum



