!------------------------------------------------------------------------------
!
!  Program name:
!
!    array_constructor
!
!  Purpose:
!
!    This program demonstrates the use of array constructors.
!
!------------------------------------------------------------------------------

PROGRAM array_constructor

  IMPLICIT NONE
  REAL, DIMENSION (6) :: ra
  REAL, DIMENSION (3,2) :: r2d
  REAL, DIMENSION (5,5) :: r2da
  INTEGER, DIMENSION (2) :: shape
  INTEGER :: i, j

  ! Simple list:

  ra = (/ 1.2,3.4,3.0,11.2,1.0,3.7 /)
  WRITE(*,'("ra = ",6f6.2/)') ra

  ! Specific elements from a 5x5 array:

  DO i=1,5
    DO j=1,5
      r2da(j,i) = j*10 + i		! r2da(r,c) = rc
    END DO
  END DO

  i = 2
  ra = (/ r2da(i,2:4), r2da(1:5:2,i+3) /)
  WRITE(*,'("ra = ",6f6.2)') ra

  ! Implied DO:

  ra = (/ (1.0/REAL(i), i=1,6) /)
  WRITE(*,'(/"ra = ",6f6.2)') ra

  ! Nested implied DO:

  ra = (/ (((j-1)*3 + i, i=1,3), j=1,2) /)
  WRITE(*,'(/"ra = ",6f6.2/)') ra

  ! Assign elements in two dimensional array via RESHAPE function:

  shape = (/ 3,2 /)
  r2d = RESHAPE ( (/ (((j-1)*3 + i, i=1,3), j=1,2) /), shape )
  WRITE(*,*) 'r2d is a 3x2 array:'
  DO i=1,3
    WRITE(*,'(3f6.2)') r2d(i,:)
  END DO

END PROGRAM array_constructor
