1       SUBROUTINE DSYSWAPR( UPLO, N, A, LDA, I1, I2)
  2 *
  3 *  -- LAPACK auxiliary routine (version 3.3.1) --
  4 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
  5 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  6 *  -- April 2011                                                      --
  7 *
  8 *     .. Scalar Arguments ..
  9       CHARACTER        UPLO
 10       INTEGER          I1, I2, LDA, N
 11 *     ..
 12 *     .. Array Arguments ..
 13       DOUBLE PRECISION A( LDA, N )
 14 *
 15 *  Purpose
 16 *  =======
 17 *
 18 *  DSYSWAPR applies an elementary permutation on the rows and the columns of
 19 *  a symmetric matrix.
 20 *
 21 *  Arguments
 22 *  =========
 23 *
 24 *  UPLO    (input) CHARACTER*1
 25 *          Specifies whether the details of the factorization are stored
 26 *          as an upper or lower triangular matrix.
 27 *          = 'U':  Upper triangular, form is A = U*D*U**T;
 28 *          = 'L':  Lower triangular, form is A = L*D*L**T.
 29 *
 30 *  N       (input) INTEGER
 31 *          The order of the matrix A.  N >= 0.
 32 *
 33 *  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
 34 *          On entry, the NB diagonal matrix D and the multipliers
 35 *          used to obtain the factor U or L as computed by DSYTRF.
 36 *
 37 *          On exit, if INFO = 0, the (symmetric) inverse of the original
 38 *          matrix.  If UPLO = 'U', the upper triangular part of the
 39 *          inverse is formed and the part of A below the diagonal is not
 40 *          referenced; if UPLO = 'L' the lower triangular part of the
 41 *          inverse is formed and the part of A above the diagonal is
 42 *          not referenced.
 43 *
 44 *  LDA     (input) INTEGER
 45 *          The leading dimension of the array A.  LDA >= max(1,N).
 46 *
 47 *  I1      (input) INTEGER
 48 *          Index of the first row to swap
 49 *
 50 *  I2      (input) INTEGER
 51 *          Index of the second row to swap
 52 *
 53 *  =====================================================================
 54 *
 55 *     ..
 56 *     .. Local Scalars ..
 57       LOGICAL            UPPER
 58       INTEGER            I
 59       DOUBLE PRECISION   TMP
 60 *
 61 *     .. External Functions ..
 62       LOGICAL            LSAME
 63       EXTERNAL           LSAME
 64 *     ..
 65 *     .. External Subroutines ..
 66       EXTERNAL         DSWAP
 67 *     ..
 68 *     .. Executable Statements ..
 69 *
 70       UPPER = LSAME( UPLO, 'U' )
 71       IF (UPPER) THEN
 72 *
 73 *         UPPER
 74 *         first swap
 75 *          - swap column I1 and I2 from I1 to I1-1 
 76          CALL DSWAP( I1-1, A(1,I1), 1, A(1,I2), 1 )
 77 *
 78 *          second swap :
 79 *          - swap A(I1,I1) and A(I2,I2)
 80 *          - swap row I1 from I1+1 to I2-1 with col I2 from I1+1 to I2-1     
 81          TMP=A(I1,I1)
 82          A(I1,I1)=A(I2,I2)
 83          A(I2,I2)=TMP
 84 *
 85          DO I=1,I2-I1-1
 86             TMP=A(I1,I1+I)
 87             A(I1,I1+I)=A(I1+I,I2)
 88             A(I1+I,I2)=TMP
 89          END DO
 90 *
 91 *          third swap
 92 *          - swap row I1 and I2 from I2+1 to N
 93          DO I=I2+1,N
 94             TMP=A(I1,I)
 95             A(I1,I)=A(I2,I)
 96             A(I2,I)=TMP
 97          END DO
 98 *
 99         ELSE
100 *
101 *         LOWER
102 *         first swap
103 *          - swap row I1 and I2 from I1 to I1-1 
104          CALL DSWAP( I1-1, A(I1,1), LDA, A(I2,1), LDA )
105 *
106 *         second swap :
107 *          - swap A(I1,I1) and A(I2,I2)
108 *          - swap col I1 from I1+1 to I2-1 with row I2 from I1+1 to I2-1     
109           TMP=A(I1,I1)
110           A(I1,I1)=A(I2,I2)
111           A(I2,I2)=TMP
112 *
113           DO I=1,I2-I1-1
114              TMP=A(I1+I,I1)
115              A(I1+I,I1)=A(I2,I1+I)
116              A(I2,I1+I)=TMP
117           END DO
118 *
119 *         third swap
120 *          - swap col I1 and I2 from I2+1 to N
121           DO I=I2+1,N
122              TMP=A(I,I1)
123              A(I,I1)=A(I,I2)
124              A(I,I2)=TMP
125           END DO
126 *
127       ENDIF
128       END SUBROUTINE DSYSWAPR
129