C
C      ________________________________________________________
C     |                                                        |
C     |   REARRANGE THE ELEMENTS OF A REAL ARRAY SO THAT THE   |
C     |  ELEMENTS OF A SQUARE MATRIX ARE STORED SEQUENTIALLY   |
C     |                                                        |
C     |    INPUT:                                              |
C     |                                                        |
C     |         A     --REAL ARRAY CONTAINING SQUARE MATRIX    |
C     |                                                        |
C     |         LA    --LEADING (ROW) DIMENSION OF ARRAY A     |
C     |                                                        |
C     |         N     --DIMENSION OF MATRIX STORED IN A        |
C     |                                                        |
C     |    OUTPUT:                                             |
C     |                                                        |
C     |         A     --MATRIX PACKED AT START OF ARRAY        |
C     |________________________________________________________|
C
      SUBROUTINE PACK(A,LA,N)
      REAL A(1)
      INTEGER H,I,J,K,L,LA,N,O
      H = LA - N
      IF ( H .EQ. 0 ) RETURN
      IF ( H .GT. 0 ) GOTO 10
      WRITE(6,*) 'ERROR: LA ARGUMENT IN PACK MUST BE .GE. N ARGUMENT'
      STOP
10    I = 0
      K = 1
      L = N
      O = N*N
20    IF ( L .EQ. O ) RETURN
      I = I + H
      K = K + N
      L = L + N
      DO 30 J = K,L
30         A(J) = A(I+J)
      GOTO 20
      END