C.hr DMCVT
C@
C....*...1.........2.........3.........4.........5.........6.........7.*
C     DMCVT    2/28/74
C
C     PURPOSE
C     CONVERT SYMMETRIC MATRICES FROM STORAGE MODE 0 TO MODE 1 OR FROM
C     STORAGE MODE 1 TO MODE 0.
C
C     USAGE
C     CALL DMCVT(A,R,N,MA,MR)
C
C     ARGUMENTS
C     A  - INPUT SYMMETRIC N BY N MATRIX STORED IN MODE MA.
C          REAL*8
C     R  - OUTPUT COPY OF A STORED IN MODE MR.
C          REAL*8
C     N  - ORDER OF A AND R.
C          INTEGER*4
C     MA - INPUT STORAGE MODE OF A.  MA MUST BE 0 OR 1 ONLY.
C          INTEGER*4
C     MR - INPUT STORAGE MODE OF R.  MR MUST BE 0 OR 1 ONLY.
C          INTEGER*4
C
C     REMARK
C     FOR IN-PLACE CONVERSTION THE USAGE IS:
C     CALL DMCVT(A,A,N,MA,MR)
C
C
C
      SUBROUTINE DMCVT(A,R,N,MA,MR)
      implicit real*8 (a-h,o-z)
      save
      REAL*8 A(N*N),R(N*N)
      IF((MA.EQ.0).AND.(MR.EQ.0)) GO TO 40
      IF((MA.EQ.0).AND.(MR.EQ.1)) GO TO 10
      IF((MA.EQ.1).AND.(MR.EQ.0)) GO TO 20
      IF((MA.EQ.1).AND.(MR.EQ.1)) GO TO 50
      RETURN
C
C     CONVERT MODE 0  TO MODE 1
C
10    DO 15 J=1,N
      DO 15 I=1,J
15    R((J*(J-1))/2+I)=A(N*(J-1)+I)
      RETURN
C
C     CONVERT MODE 1 TO MODE 0
C
20    DO 25 JJ=1,N
      J=N-(JJ-1)
      DO 25 II=1,J
      I=J-(II-1)
25    R(N*(J-1)+I)=A((J*(J-1))/2+I)
      DO 30 J=1,N
      DO 30 I=1,J
30    R(N*(I-1)+J)=R(N*(J-1)+I)
      RETURN
C
C     COPY MODE 0 TO MODE 0
C
40    NN=N*N
      DO 45 I=1,NN
45    R(I)=A(I)
      RETURN
C
C     COPY MODE 1 TO MODE 1
C
50    NN=(N*(N-1))/2+N
      DO 55 I=1,NN
55    R(I)=A(I)
      RETURN
      END
