*DECK ALINV
      SUBROUTINE ALINV(N,A,MAX,IER)
*
*-----------------------------------------------------------------------
*
* IN-PLACE INVERSION OF A NON SINGULAR MATRIX USING GAUSSIAN ELIMINATION
* WITH PARTIAL PIVOTING. SIMPLE PRECISION VERSION.
*
* INPUT PARAMETERS:
*  N       : ORDER OF THE COEFFICIENT MATRIX.
*  A       : COEFFICIENT MATRIX TO BE INVERTED. DIMENSION A(MAX,N)
*  MAX     : FIRST DIMENTION OF MATRIX A.
*
* OUTPUT PARAMETERS:
*  A       : INVERTED MATRIX.
*  IER     : ERROR FLAG. EXECUTION FAILURE IF IER.NE.0.
*------------------------------------------------ AUTHOR: A. HEBERT ----
*
      REAL A(MAX,*)
      INTEGER, DIMENSION(:), ALLOCATABLE :: IND
      ALLOCATE(IND(N))
      IN=0
      IER=0
      DO 1 I=1,N
1     IND(I)=I
      DO 11 J=1,N
      TEST=0.0
      DO 2 I=J,N
      IF (ABS(A(I,J)).LE.TEST) GO TO 2
      TEST=ABS(A(I,J))
      IN=I
2     CONTINUE
      IF (TEST.NE.0.0) GO TO 3
      IER=1
      DEALLOCATE(IND)
      RETURN
3     PMX=A(IN,J)
      A(IN,J)=1.0
      DO 4 I=1,N
      PER=A(IN,I)/PMX
      A(IN,I)=A(J,I)
4     A(J,I)=PER
      IPER=IND(IN)
      IND(IN)=IND(J)
      IND(J)=IPER
      DO 11 I=1,N
      IF (I.EQ.J) GO TO 11
      PMX=A(I,J)
      A(I,J)=0.0
      DO 9 K=1,N
9     A(I,K)=A(I,K)-PMX*A(J,K)
11    CONTINUE
      DO 15 J=1,N
      DO 13 K=J,N
      IF (IND(K).NE.J) GO TO 13
      IN=K
      GO TO 14
13    CONTINUE
14    DO 15 I=1,N
      PER=A(I,J)
      A(I,J)=A(I,IN)
      A(I,IN)=PER
      IND(IN)=IND(J)
15    CONTINUE
      DEALLOCATE(IND)
      RETURN
      END
