C====to calculate real and imag.self-energy matrix  for scat======
      SUBROUTINE  INVMA1(W,NW1,K2,SR,DET,RRR,RRM,
     *        CC,QQ,DD1,RE1,IM1)
C =================================================
      INTEGER K2,W,NW1,I,J
      REAL*8 RE1,IM1,DET,
     *       RRR(K2,*),RRM(K2,*),SR(2*K2,2*K2),
     *       CC(*),QQ(*),DD1(*)

      DO 10 I=1,2*K2
      DO 15 J=1,2*K2
      IF(I.EQ.J) THEN
      SR(J,I)=1.D 00
      ELSE
      SR(J,I)=0.D 00
      END IF
C      IF(I.EQ.J) WRITE(6,16)SR(J,I)
C 16   FORMAT(' diag ',E15.8)
 15   CONTINUE
 10   CONTINUE
      DO 30 I=1,K2
      DO 35 J=1,K2
      SR(J,I)=SR(J,I)-RRR(I,J)*(CC(J)-QQ(J))*DD1(J)
      SR(J+K2,I+K2)=SR(J,I)
C      IF(I.EQ.J) WRITE(6,36)SR(J,I)
C 36   FORMAT(' diag after chang ',E15.8)
 35   CONTINUE
 30   CONTINUE
      DO 50 I=1,K2
      DO 55 J=1,K2
      SR(J,I+K2)=SR(J,I+K2)-RRM(I,J)*(CC(J)-QQ(J))*DD1(J)
      SR(J+K2,I)=-SR(J,I+K2)
C      IF(I.EQ.J) WRITE(6,56) SR(J,I)
C 56   FORMAT(' nondiag ',E15.8)
 55   CONTINUE
 50   CONTINUE
      CALL INVERT(SR,0.00001,DET,2*K2,*100)
      RE1=0.D 00
      IM1=0.D 00
      DO 70 I=1,K2
      RE1=RE1+RRR(I,W)*SR(I,W)+RRM(I,W)*SR(I+K2,W)
      IM1=IM1+RRR(I,W)*SR(I,W+K2)+RRM(I,W)*SR(I+K2,W+K2)
      WRITE(6, 80)I,RE1,IM1
 80   FORMAT(' K ',I3,' RE ',E15.8,' IM ',E15.8)
 70   CONTINUE
100   RETURN
      END
