      SUBROUTINE EVALA(CXADIA,CXAOFF,CXALPH,CXALOF,MXN3,NAT)
      IMPLICIT NONE
C*** Arguments:
      INTEGER MXN3,NAT
      COMPLEX CXADIA(MXN3),CXALOF(MXN3),CXALPH(MXN3),CXAOFF(MXN3)

C*** Local variables:
      INTEGER J1,J2,J3
      COMPLEX CX1,CX2,CX3,DENOM

C*********************************************************************
C Subroutine EVALA
C Purpose: to evaluate 3x3 diagonal blocks of matrix A for use in
C discrete-dipole scattering calculation.
C
C Given:   CXALPH(J,1-3)=(alpha_11,alpha_22,alpha_33) where alpha=
C                         complex polarizability tensor 
C                         of dipole J (J=1-NAT, first 3*NAT elements
C                         of CXALPH used)
C          CXALOF(J,1-3)=(alpha_23,alpha_31,alpha_12) for dipole J
C                        (J=1-NAT, first 3*NAT elements of CXALOF used)
C          NAT=number of dipoles
C          MXN3,MXNAT=dimensioning information

C Returns: CXADIAG(1-3*NAT)=diagonal elements of matrix A
C          CXAOFF(J,1-3)=(a_23,a_31,a_12) where a_ij=3x3 matrix
C                        equal to inverse of 3x3 matrix alpha_ij
C                        for dipole J (first 3*NAT elements of CXAOFF
C                        are used)

C Note that it is assumed that vectors E and P will have data
C in order E_1x,E_2x,...,E_Nx,E_1y,E_2y,...,E_Ny,E_1z,E_2z,...,E_Nz
C
C B. T. Draine, Princeton Univ. Obs., 87.01.07
C History:
C 88.05.05 (BTD): Modifications...
C 90.11.06 (BTD): Modified to pass array dimensions
C 97.12.25 (BTD): Added CXAOFF,CXALOF to argument list
C                 Modified to allow nondiagonal polarizabilities
C                 alpha_ij
C 98.01.01 (BTD): Correct inconsistency in assumed data ordering.
C
C End history
C Copyright (C) 1993,1997,1998 B.T. Draine and P.J. Flatau
C This code is covered by the GNU General Public License.
C***********************************************************************
C***********************************************************************
C Given symmetric matrix m with six independent elements a1, a2, a3, b1,
C b2, b3 (see below), we seek inverse matrix M with six independent
C elements A1, A2, A3, B1, B2, B3 such that
C
C      (a1 b3 b2)   (A1 B3 B2)   (1 0 0)
C      (b3 a2 b1) x (B3 A2 B1) = (0 1 0)
C      (b2 b1 a3)   (B2 B1 A3)   (0 0 1)
C
C solution:
C                     a2*a3 - b1*b1
C A1 = ----------------------------------------------
C      a1*a2*a3+2*b1*b2*b3-a1*b1**2-a2*b2**2-a3*b3**2
C
C                     a3*a1 - b2*b2
C A2 = ----------------------------------------------
C      a1*a2*a3+2*b1*b2*b3-a1*b1**2-a2*b2**2-a3*b3**2
C
C                     a1*a2 - b3*b3
C A3 = ----------------------------------------------
C      a1*a2*a3+2*b1*b2*b3-a1*b1**2-a2*b2**2-a3*b3**2
C
C                     b2*b3 - a1*b1
C B1 = ----------------------------------------------
C      a1*a2*a3+2*b1*b2*b3-a1*b1**2-a2*b2**2-a3*b3**2
C
C                     b3*b1 - a2*b2
C B2 = ----------------------------------------------
C      a1*a2*a3+2*b1*b2*b3-a1*b1**2-a2*b2**2-a3*b3**2
C
C                     b1*b2 - a3*b3
C B3 = ----------------------------------------------
C      a1*a2*a3+2*b1*b2*b3-a1*b1**2-a2*b2**2-a3*b3**2
C
C***********************************************************************
C
      DO 100 J1=1,NAT
         J2=J1+NAT
         J3=J2+NAT
         CX1=CXALOF(J1)**2
         CX2=CXALOF(J2)**2
         CX3=CXALOF(J3)**2
         DENOM=CXALPH(J1)*CXALPH(J2)*CXALPH(J3)+
     &         2.*CXALOF(J1)*CXALOF(J2)*CXALOF(J3)-
     &         CXALPH(J1)*CX1-CXALPH(J2)*CX2-CXALPH(J3)*CX3
         CXADIA(J1)=(CXALPH(J2)*CXALPH(J3)-CX1)/DENOM
         CXADIA(J2)=(CXALPH(J3)*CXALPH(J1)-CX2)/DENOM
         CXADIA(J3)=(CXALPH(J1)*CXALPH(J2)-CX3)/DENOM
         CXAOFF(J1)=(CXALOF(J2)*CXALOF(J3)-CXALPH(J1)*CXALOF(J1))/DENOM
         CXAOFF(J2)=(CXALOF(J3)*CXALOF(J1)-CXALPH(J2)*CXALOF(J2))/DENOM
         CXAOFF(J3)=(CXALOF(J1)*CXALOF(J2)-CXALPH(J3)*CXALOF(J3))/DENOM
  100 CONTINUE
      RETURN
C
      END
