c===========================================================
c     Program to test understanding of Fortran 77 array
c     storage scheme.
c
c     EXERCISE:  Predict program output.
c
c     SOLUTION:  Assignments to a in main result in following 
c     equivalent 1-d array (* indicates (2,2) element):
c
c     a -> 101, 102, 103, 201, 202, 203, 301, 302, 303
c                               *
c
c     "Reinterpreted" (reshaped) as a 2x2 array in sub
c     results in (* indicates (2,2) element):
c
c     a -> 101, 102, 103, 201
c                          *
c
c     So output is 
c
c        main: a(2,2) =   202
c        sub: a(2,2) =   201
c
c  
c===========================================================
      program     t2d

      implicit    none

      integer     n
      parameter ( n = 3 )

      real*8      a(n,n),   aij
      integer     i,        j

      do j = 1 , n
         do i = 1 , n
            a(i,j) = 100.0d0 * j + i
         end do
      end do

      write(0,*) 'main: a(2,2) = ', a(2,2)

      call sub(a,2,2)

      stop

      end

      subroutine sub(a,n,m)

         implicit      none
         integer       n,      m
         real*8        a(n,m)

         write(0,*) 'sub: a(2,2) = ', a(2,2)

         return

      end
