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