      SUBROUTINE SCAT(AK,AKS,EM1,EM2,E02,CMDTRQ,
     &    CBKSCA,CSCA,CSCAG,CTRQIN,CTRQSC,
     &    CXE,CXE00,CXF1L,CXF2L,CXP,CXSCR1,CXSCR2,CXSCR3,CXSCR4,
     &    ICTHM,IPHIM,MXN3,MXNAT,MXSCA,NAT,NAT3,NDIR,
     &    PHIN,SCRRS1,SCRRS2,THETAN,IXYZ)
C
C Arguments:
C
      CHARACTER CMDTRQ*6
      REAL CBKSCA,CSCA,E02
      INTEGER ICTHM,IPHIM,MXN3,MXNAT,MXSCA,NAT,NAT3,NDIR
      INTEGER*2 IXYZ(MXNAT,3)
      COMPLEX CXE(NAT,3),CXE00(3),CXF1L(MXSCA),CXF2L(MXSCA),CXP(NAT,3),
     &        CXSCR1(MXN3),CXSCR2(MXN3),CXSCR3(MXN3),CXSCR4(MXNAT,3)
      REAL AK(3),AKS(3,MXSCA),CSCAG(3),CTRQIN(3),CTRQSC(3),
     &     EM1(3,MXSCA),EM2(3,MXSCA),
     &     PHIN(MXSCA),SCRRS1(NAT,3),SCRRS2(MXNAT),THETAN(MXSCA)
C
C Local variables:
C
      COMPLEX CXI,CXSCL1,CXSCL2,CXSCL3
      REAL AK2,AK3,AKK,CONST,COSPHI,COSTH,DCOSTH,DPHI,EINC,ES2,
     &     PI,PHI,RRR,SINPHI,SINTH,TERM,W,WTH
      INTEGER ICOSTH,IPHI,IPHM,J,K,ND
      COMPLEX CXBS(3),CXES(3),CXTRM(3)
      REAL AKS0(3),AKS1(3),AKS2(3),AKSN(3),CTRQSCTF(3),XYZCM(3)
C
C Intrinsic functions:
C
      INTRINSIC COS,EXP,MIN,SIN,SQRT,CONJG,REAL
C
C Data statements:
C
      DATA CXI/(0.,1.)/
C***********************************************************************
C
C SCAT computes energy radiated by array of oscillating dipoles
C and corresponding scattering properties if oscillations are in
C response to incident E field.
C
C Given:
C     AK(1-3) = KX,KY,KZ = components of incident k-vector in TF
C     AKS(3,MXSCA)=scattered k vectors in TF
C     CMDTRQ = 'DOTORQ' to calculate torques
C            = 'NOTORQ' to skip calculation of torques
C     EM1(3,MXSCA)=pol.vector 1 for each scattering direction in TF
C     EM2(3,MXSCA)=pol.vector 2 for each scattering direction in TF
C     E02 = |E_0|^2 , where E_0 = incident complex E field
C     NAT = number of dipoles
C     NAT3 = 3*NAT
C     IXYZ(NAT,1-3) = x/d, y/d, z/d (integers) for dipoles 1-NAT
C     CXE(1-NAT,1-3) = components of E field at each dipole at t=0
C     CXE00(1-3) = (complex) reference polarization vector
C     CXP(1-NAT,1-3) = components of polarization of each dipole
C     ICTHM = number of THETA values for calculation of CSCA and G
C             (ICTHM must be odd; recommend ICTHM > 5*(2*pi*a/lambda)
C              for accuracy)
C     IPHIM = number of PHI values for calculation of CSCA and G
C     NDIR = number of directions at which scattering matrix elements
C            are to be computed
C     THETAN(1-NDIR) : scattering angle (radians);
C                      cos(THETAN) = n0 dot n
C                      *** BTD 98.11.18: THETAN is not used ***
C     PHIN(1-NDIR)   : scattering angle (radians);
C                      *** BTD 98.11.18: PHIN is not used ***
C
C Returns:
C     CBKSCA=differential scattering cross section for theta=pi
C            (lattice units)
C     CSCA = scattering cross section (lattice units)
C     CSCAG(1) = CSCA*<cos(theta)> , where theta=scattering angle
C     CSCAG(2) = CSCA*<sin(theta)cos(phi)>
C     CSCAG(3) = CSCA*<sin(theta)sin(phi)>
C     CTRQIN(1-3)=cross section for torque on grain due to incident
C                 E and B fields,
C                 for torque in directions x,y,z assuming incident 
C                 radiation is along x direction, 
C                 and "reference pol state" is in y direction.
C     CTRQSC(1-3)=cross section for torque on grain due to scattered
C                 E and B fields,
C                 for torque in directions x,y,z assuming incident 
C                 radiation is along x direction, 
C                 and "reference pol state" is in y direction
C                 Here "torque cross section" is defined so that
C                 torque(1-3)=(momentum flux)*(1/k)*C_torque(1-3)
C                 Total torque cross section=CTRQIN+CTRQSC
C     CXF1L(NDIR)=f_{1L} for direction NDIR
C     CXF2L(NDIR)=f_{2L} for direction NDIR
C                 where f_{1L} connects incident polarization L to
C                 outgoing theta polarization (E in scattering plane)
C                 f_{2L} connects incident polarization L to outgoing phi
C                 polarization (E perpendicular to scattering plane)
C                 This is same f_{ml} notation as used by Draine (1988;
C                 Ap.J., 333, 848).
C
C Notes:
C     AKS0(1-3)=k_s=scattered k vector (lattice units)
C     AKSN(1-3)=k_s/|k_s|=unit vector in scattering direction
C Scratch vectors introduced to permit vectorization:
C     SCRRS1 = real vector of length.GE.3*NAT
C     SCRRS2 = real vector of length.GE.NAT
C     CXSCR1 = complex scratch array of length 3*MXNAT
C     CXSCR2 = complex scratch array of length 3*MXNAT
C     CXSCR3 = complex scratch array of length 3*MXNAT
C     CXSCR4 = complex scratch array of length 3*MXNAT
C
C B.T.Draine, Princeton Univ. Obs., 87.01.04
C History:
C 88.06.29 (BTD): modified
C 89.11.28 (BTD): modified
C 90.11.02 (BTD): modified to enable use with vacuum sites.
C 90.11.20 (BTD): corrected error in calculation of f_ml (missing
C                 factor of k).
C 90.12.03 (BTD): changed ordering of XYZ0 and CXP
C                 eliminated cxe0 from argument list
C 90.12.10 (BTD): replaced XYZ0 with IXYZ0 to reduce memory use
C 91.08.14 (BTD): add CBKSCA to argument list for SCAT
C                 add code to eliminate sum over phi when theta=0 or pi
C                 add code to calculate CBKSCA
C 94.04.04 (BTD): removed superfluous CMPLX( ) operation from 2 lines
C                 in DO 200 loop. Also added new variable TERM to move
C                 some computation out of last DO loop.
C 95.06.14 (BTD): modified to compute moments <sin(theta)cos(phi)>
C                 and <sin(theta)sin(phi)> of scattered radiation
C                 added code to compute torque on grain relative to
C                 grain centroid XYZCM(1-3)
C                 NOTE: handling of grain centroid is not as efficient
C                 as it should be.  Can be recoded to reduce number
C                 of computations.
C 95.06.15 (BTD): modified to compute absorption contribution to
C                 torque on grain.
C                 added CXE and CTRQIN to argument list
C 95.06.15 (BTD): corrected errors found by Joseph Weingartner
C 95.06.16 (BTD): more corrections
C 95.06.20 (BTD): added argument CMDTRQ to allow torque calculations
C                 to be skipped if not desired.
C 95.06.22 (BTD): added factor CXI in terms appearing in evaluation
C                 of scattered torque
C 95.06.29 (BTD): Added loop to compute AKS0(1-3) for special cases
C                 theta-0 and 180. Error found by J. Weingartner.
C 95.07.20 (BTD): Add scratch vector SCRRS2
C                 Add scratch array CXSCR4 to argument list
C                 Rewrite to make torque computation more efficient:
C                 move as many calculations as possible out of loops 
C                 over scattering directions:
C                 SCRRS1 now used to store coords relative to centroid
C                 SCRRS2 now used to store (k_s dot r_j)
C                 CXSCR4 is needed to store (p_j cross r_j)
C 95.07.21 (BTD): Rewrite (again!) to make the correspondence
C                 to notation of Draine & Weingartner more apparent.
C                 This involved changing various definitions by
C                 factors of k, and change of sign of CXBS
C 95.07.24 (BTD): Corrected errors in evaluation of both scattering
C                 torque and incident torque
C 95.07.28 (BTD): Reenabled computation of CBKSCA
C 98.11.18 (BTD): Edited comments
C
C Copyright (C) 1993,1994,1995,1998 B.T. Draine and P.J. Flatau
C This code is covered by the GNU General Public License.
C***********************************************************************
      PI=4.*ATAN(1.)
C
C ICTHM,IPHIM determine angular grid used for calculation of total
C scattering cross section and G=<cos(theta)>
C ICTHM=number of theta values for which scattering is evaluated
C       (0 to pi)
C IPHIM=number of phi values for which scattering is evaluated
C       (0 to 2*pi)
C Note: ICTHM must be odd as Simpson's rule integration is employed.
C Check whether ICTHM is odd, and increase by 1 if not.
C
      IF(ICTHM.EQ.2*(ICTHM/2))ICTHM=ICTHM+1
C
C Incident k vector AK defines one axis (for spherical integration)
C Use (real part of) reference polarization vector CXE00 to define
C second coordinate axis.
C Construct third coordinate axis by taking cross product of first
C two axes.
C AKS1, AKS2 = vectors of length equal to AK lying along second and
C              third coordinate axes.
C
      AK2=AK(1)*AK(1)+AK(2)*AK(2)+AK(3)*AK(3)
      AKK=SQRT(AK2)
      AK3=AKK*AK2
      AKS1(1)=REAL(CXE00(1))
      AKS1(2)=REAL(CXE00(2))
      AKS1(3)=REAL(CXE00(3))
C
C EINC = magnitude of (real part of) reference electric field
C
      EINC=SQRT(AKS1(1)**2+AKS1(2)**2+AKS1(3)**2)
      IF(EINC.LE.0.)CALL ERRMSG('FATAL','SCAT',
     &                          'CXE00 IS PURE IMAGINARY!')
      RRR=AKK/EINC
      AKS1(1)=RRR*AKS1(1)
      AKS1(2)=RRR*AKS1(2)
      AKS1(3)=RRR*AKS1(3)
      AKS2(1)=(AK(2)*AKS1(3)-AK(3)*AKS1(2))/AKK
      AKS2(2)=(AK(3)*AKS1(1)-AK(1)*AKS1(3))/AKK
      AKS2(3)=(AK(1)*AKS1(2)-AK(2)*AKS1(1))/AKK
C
      DCOSTH=2./REAL(ICTHM-1)
      DPHI=2.*PI/REAL(IPHIM)
      CSCA=0.
      DO K=1,3
         CSCAG(K)=0.
         CTRQSCTF(K)=0.
      ENDDO
C
C CONST = multiplicative factor entering weights
C factor 2/(ICTHM-1) = d(cos(theta))
C factor 2*pi/IPHIM = d(phi)
C factor 3 in denom from Simpson's rule (later mult. by 1,4,2..)
C Use Simpson's rule integration over d(cos(theta))
C
      CONST=4.*PI/ (3.*REAL((ICTHM-1)*IPHIM))
C
C Note that for cos(theta)=-1 or 1 we do not need to sum over phi,
C so treat these two directions separately
C
      IF(CMDTRQ.EQ.'DOTORQ')THEN
C
C***********************************************************************
C Additional quantities required for torque computations
C XYZCM(1-3) = coordinates of grain centroid
C SCRRS1(J,K)= r_j = coordinates of dipole J relative to centroid.
C CXSCR3(J) = r_j dot p_j
C CXSCR4(J,1-3) = p_j cross r_j
C
         DO K=1,3
            XYZCM(K)=0.
            DO J=1,NAT
               XYZCM(K)=XYZCM(K)+IXYZ(J,K)
            ENDDO
            XYZCM(K)=XYZCM(K)/NAT
         ENDDO
         DO K=1,3
            DO J=1,NAT
               SCRRS1(J,K)=IXYZ(J,K)-XYZCM(K)
            ENDDO
         ENDDO
         DO J=1,NAT
            CXSCR3(J)=(0.,0.)
            DO K=1,3
               CXSCR3(J)=CXSCR3(J)+SCRRS1(J,K)*CXP(J,K)
            ENDDO
         ENDDO
         DO J=1,NAT
            CXSCR4(J,1)=CXP(J,2)*SCRRS1(J,3)-CXP(J,3)*SCRRS1(J,2)
            CXSCR4(J,2)=CXP(J,3)*SCRRS1(J,1)-CXP(J,1)*SCRRS1(J,3)
            CXSCR4(J,3)=CXP(J,1)*SCRRS1(J,2)-CXP(J,2)*SCRRS1(J,1)
         ENDDO
C***********************************************************************
      ELSE
         DO K=1,3
            DO J=1,NAT
               SCRRS1(J,K)=IXYZ(J,K)
            ENDDO
         ENDDO
      ENDIF
C
C Proceed to sum over scattering angles:
C
      DO ICOSTH=1,ICTHM
         IPHM=IPHIM
         WTH=4.
         IF(ICOSTH.GT.2*(ICOSTH/2))WTH=2.
C
C In special case ICOSTH=1 or ICTHM, we have theta=0 or pi,
C and the angle phi becomes irrelevant.  In this case we
C need only one value of phi, so we set IPHM=1 and adjust weights
C accordingly.
C
         IF(ICOSTH.EQ.1.OR.ICOSTH.EQ.ICTHM)THEN
            WTH=IPHIM
            IPHM=1
         ENDIF
         COSTH=1.-REAL(ICOSTH-1)*DCOSTH
         SINTH=SQRT(1.-MIN(COSTH*COSTH,1.))
C
C Evaluate total weight factor W
C
         W=CONST*WTH
         DO IPHI=1,IPHM
            PHI=DPHI*(REAL(IPHI)-0.5)
            SINPHI=SIN(PHI)
            COSPHI=COS(PHI)
C
C Compute scattered k vector AKS0(1-3)
C Initialize CXES(1-3) = scattered electric field
C
            DO  K=1,3
               AKS0(K)=COSTH*AK(K)+SINTH*
     &                 (COSPHI*AKS1(K)+SINPHI*AKS2(K))
               CXES(K)=(0.,0.)
            ENDDO
C
C Compute normalized scattering vector = nhat
C
            DO K=1,3
               AKSN(K)=AKS0(K)/AKK
            ENDDO
C
C Now compute CXES(1-3) = sum_j[p_j-nhat(nhat dot p_j)]exp[-ik_s dot x_j]
C      =(r/k*k)*exp(-ikr+iwt)*E(k_s,r,t)
C      where E(k_s,r,t) is complex electric field vector propagating
C      with wave vector k_s, at distance r from origin
C Notation:
C    If CMDTRQ='DOTORQ', then r_j = position relative to centroid XYZCM
C    If CMDTRQ='NOTORQ', then r_j = original lattice coords, and XYZCM=0.
C Note that since we are not concerned with overall phase shifts for
C evaluation of forces and torques, we do NOT need to worry about change 
C in phase resulting from using two different definitions of r_j when
C computing phase factors exp[-i k_s dot r_j]
C 
            DO J=1,NAT
C
C CXSCR1(J) = nhat dot p(j)
C
               CXSCR1(J)=(0.,0.)
               DO K=1,3
                  CXSCR1(J)=CXSCR1(J)+AKSN(K)*CXP(J,K)
               ENDDO
C
C SCRRS2(J) = nhat dot r(j)
C
               SCRRS2(J)=0.
               DO K=1,3
                  SCRRS2(J)=SCRRS2(J)+SCRRS1(J,K)*AKSN(K)
               ENDDO
C
C CXSCR2(J) = exp(-i*k_s dot r_j) factor for atom j
C
               CXSCR2(J)=EXP(-CXI*AKK*SCRRS2(J))
C
C CXES(1-3) = sum_j[p_j-nhat(nhat dot p_j)]exp[-ik_s dot x_j]
C
               DO K=1,3
                  CXES(K)=CXES(K)+(CXP(J,K)-AKSN(K)*CXSCR1(J))*
     &                    CXSCR2(J)
               ENDDO
            ENDDO
C
            IF(CMDTRQ.EQ.'DOTORQ')THEN
C***********************************************************************
C Additional terms required to compute torque on grain
C Have already computed
C CXES(1-3)=sum_j[p_j - k_s*(k_s dot p_j)/|k|^2]exp[-ik_s dot x_j]
C             where p_j = polarization of dipole j
C                   x_j = position of dipole j rel. to CM
C                   k_s = scattered k vector
C
C CXBS = -nhat cross CXES  = -(r/k*k)*exp(-ikr+iwt)*B(k_s,r,t)
C
               CXBS(1)=AKSN(3)*CXES(2)-AKSN(2)*CXES(3)
               CXBS(2)=AKSN(1)*CXES(3)-AKSN(3)*CXES(1)
               CXBS(3)=AKSN(2)*CXES(1)-AKSN(1)*CXES(2)
C
C CXSCL1 = sum_j p_j dot (r_j cross nhat)*exp(-i*k_s dot r_j)
C        = nhat dot sum_j (p_j cross r_j)*exp(-i*k_s dot r_j)
C recall that have previously evaluated
C CXSCR2(J) = exp(-i*k_s dot r_j) factor for atom j
C CXSCR4(J,K)=p_j cross r_j
C
               CXSCL1=(0.,0.)
               DO K=1,3
                  CXTRM(K)=(0.,0.)
               ENDDO
               DO K=1,3
                  DO J=1,NAT
                     CXTRM(K)=CXTRM(K)+CXSCR2(J)*CXSCR4(J,K)
                  ENDDO
                  CXSCL1=CXSCL1+AKSN(K)*CXTRM(K)
               ENDDO
C
C CXSCL2 = sum_j[(r_j dot p_j) - 
C                 (nhat dot p_j)*((nhat dot r_j) + 2i/k_s)]*
C                 exp(-i*k_s dot r_j)
C Have previously computed
C CXSCR1(J) = nhat dot p(j)
C CXSCR2(J) = exp(-i*k_s dot r_j) factor for atom j
C CXSCR3(J) = r_j dot p_j
C SCRRS2(J) = nhat dot r(j)
C
               CXSCL2=(0.,0.)
               DO J=1,NAT
                  CXSCL2=CXSCL2+CXSCR2(J)*(
     &                   CXSCR3(J)-CXSCR1(J)*(SCRRS2(J)+2.*CXI/AKK))
               ENDDO
C
C Note following notational correspondence:
C    present    Draine & Weingartner (1996)
C    -------    ---------------------------
C     CXES   =        V_E
C     CXBS   =        V_B
C    CXSCL1  =        S_B
C    CXSCL2  =        S_E
C
C***********************************************************************
            ENDIF
C
C Have completed computation of vector CXES(1-3) and terms to calculate
C angular momentum flux for scattering direction (THETA,PHI).
C CTRQSCTF(K) is "torque cross section" due to "scattered radiation"
C resulting in torque in lattice direction k (i.e., in "target
C frame".  After CTRQSCTF has been evaluated, we will compute CTRQSC in
C the "scattering frame", where the radiation is incident along x,
C and the "reference polarization state" is along the y direction.
C
            ES2=0.0
            DO K=1,3
               ES2=ES2+CXES(K)*CONJG(CXES(K))
            ENDDO
            CSCA=CSCA+W*ES2
            CSCAG(1)=CSCAG(1)+W*COSTH*ES2
            CSCAG(2)=CSCAG(2)+W*SINTH*COSPHI*ES2
            CSCAG(3)=CSCAG(3)+W*SINTH*SINPHI*ES2
            IF(CMDTRQ.EQ.'DOTORQ')THEN
               DO K=1,3
                  CTRQSCTF(K)=CTRQSCTF(K)-
     &               W*REAL(CONJG(CXBS(K))*CXSCL2+CONJG(CXES(K))*CXSCL1)
               ENDDO
            ENDIF
         ENDDO
C
C Save backscattering cross section:
C
         IF(ICOSTH.EQ.ICTHM)CBKSCA=AK2*AK2*ES2/E02
      ENDDO
C
C***********************************************************************
C
      CSCA=AK2*AK2*CSCA/E02
C
C Convert CSCAG and CTRQSCTF to cross sections measured in lattice units:
C
      DO K=1,3
         CSCAG(K)=AK2*AK2*CSCAG(K)/E02
      ENDDO
      IF(CMDTRQ.EQ.'DOTORQ')THEN
C
C***********************************************************************
C Compute the two contributions to the torque on the target:
C (1) torque due to E and B fields of incident radiation (CTRQIN)
C (2) torque due to E and B fields of scattered radiation (CTRQSC)
C These are first computed in the target frame, then transformed to
C the lab frame (frame where incident radiation propagates along
C the x axis, and "reference pol. state 1" is along the y axis).
C
         DO K=1,3
            CTRQSCTF(K)=AK2*AK2*CTRQSCTF(K)/E02
         ENDDO
C
C CTRQSCTF(1-3) is the vector torque cross section/|k| measured in the
C target frame.  We now compute CTRQSC(1-3)=the vector torque cross
C section in the "scattering frame", where the radiation is incident along
C the x axis, and the "reference polarization state" (at t=0) is
C linearly polarized along the y axis.
C Note that the following computation introduces an additional factor
C of |k|.
C
         CTRQSC(1)=AK(1)*CTRQSCTF(1)+AK(2)*CTRQSCTF(2)+AK(3)*CTRQSCTF(3)
         CTRQSC(2)=AKS1(1)*CTRQSCTF(1)+AKS1(2)*CTRQSCTF(2)+
     &             AKS1(3)*CTRQSCTF(3)
         CTRQSC(3)=AKS2(1)*CTRQSCTF(1)+AKS2(2)*CTRQSCTF(2)+
     &             AKS2(3)*CTRQSCTF(3)
C
C Now compute vector torque cross section due to incident radiation:
C
         DO K=1,3
            CTRQIN(K)=0.
         ENDDO
C
C Redefine scratch vector CXSCR1:
C CXSCR1(J)=conjg(p_j) dot E_0j at t=0
C
         DO J=1,NAT
            CXSCR1(J)=0.
            DO K=1,3
               CXSCR1(J)=CXSCR1(J)+CONJG(CXP(J,K))*CXE(J,K)
            ENDDO
         ENDDO
         CXSCL1=0.
         CXSCL2=0.
         CXSCL3=0.
C
C Compute CXSCL1,CXSCL2,CXSCL3=components of the torque due to
C incident E and B fields in the target frame.
C 95.06.22 (BTD): added factor CXI in r cross k term appearing in
C                 evaluations of CXSCL1,CXSCL2,CXSCL2
C 95.07.21 (BTD): corrected sign mistake (+CXI -> -CXI)
C 95.07.24 (BTD): changed def. of CXSCR1 to agree with paper,
C                 changed calc. of CXSCLn to more closely mirror paper,
C                 and changed AKS0 to AK
C
         DO J=1,NAT
            CXSCL1=CXSCL1+CONJG(CXP(J,2))*CXE(J,3)-
     &                    CONJG(CXP(J,3))*CXE(J,2)-CXI*
     &             (AK(2)*SCRRS1(J,3)-AK(3)*SCRRS1(J,2))*CXSCR1(J)
            CXSCL2=CXSCL2+CONJG(CXP(J,3))*CXE(J,1)-
     &                    CONJG(CXP(J,1))*CXE(J,3)-CXI*
     &             (AK(3)*SCRRS1(J,1)-AK(1)*SCRRS1(J,3))*CXSCR1(J)
            CXSCL3=CXSCL3+CONJG(CXP(J,1))*CXE(J,2)-
     &                    CONJG(CXP(J,2))*CXE(J,1)-CXI*
     &             (AK(1)*SCRRS1(J,2)-AK(2)*SCRRS1(J,1))*CXSCR1(J)
         ENDDO
C
C Compute CTRQIN(1-3)=2*components of torque due to incident E and B
C fields (in lab frame), expressed as a cross section:
C
         CTRQIN(1)=AK(1)*REAL(CXSCL1)+AK(2)*REAL(CXSCL2)+
     &             AK(3)*REAL(CXSCL3)
         CTRQIN(2)=AKS1(1)*REAL(CXSCL1)+AKS1(2)*REAL(CXSCL2)+
     &             AKS1(3)*REAL(CXSCL3)
         CTRQIN(3)=AKS2(1)*REAL(CXSCL1)+AKS2(2)*REAL(CXSCL2)+
     &             AKS2(3)*REAL(CXSCL3)
         DO K=1,3
            CTRQIN(K)=4.*PI*CTRQIN(K)/E02
         ENDDO
      ENDIF
C
C***********************************************************************
C
      IF(NDIR.LE.0)RETURN
C
C*** Calculate the 2 matrix elements FM1 for selected directions
C F1L(NDIR) is to the polarization state e1 (E in scattering plane)
C F2L(NDIR) is to the polarization state e2 (E perp. to scatt. plane)
C
C IMPORTANT NOTE: If the incident radiation is not linearly polarized,
C with zero imaginary component to the polarization vector, then the
C F1L and F2L computed here are NOT the "usual" f_ml, which
C describe scattering from linearly polarized states l to linearly
C polarized states m.
C If one wishes to reconstruct the "usual" f_ml even when computing
C with elliptically polarized light, then one must add additional
C code to the routine SCAT to reconstruct the f_ml from the F1L and
C F2L computed here.
C
      TERM=AK3/SQRT(E02)
      DO ND=1,NDIR
         CXF1L(ND)=(0.0,0.0)
         CXF2L(ND)=(0.0,0.0)
         DO J=1,NAT
            CXSCR2(J)=(0.0,0.0)
            CXSCR3(J)=(0.0,0.0)
            DO K=1,3
               CXSCR2(J)=CXSCR2(J)+CXP(J,K)*EM1(K,ND)
               CXSCR3(J)=CXSCR3(J)+CXP(J,K)*EM2(K,ND)
            ENDDO
         ENDDO
         DO J=1,NAT
            CXSCR1(J)=EXP(-CXI*(AKS(1,ND)*IXYZ(J,1)+
     &                          AKS(2,ND)*IXYZ(J,2)+
     &                          AKS(3,ND)*IXYZ(J,3)))
            CXF1L(ND)=CXF1L(ND)+CXSCR2(J)*CXSCR1(J)
            CXF2L(ND)=CXF2L(ND)+CXSCR3(J)*CXSCR1(J)
         ENDDO
C
C   Units: Dipole polarizations are in units of [E]*d**3, where d=lattice
C          spacing, and [E]=dimensions of E field
C          Therefore, up to this point CXF1L, CXF2L are in units
C          of [E]*d**3
C          Now multiply by AK3/SQRT(E02) (units of 1/([E]d**3)) to get
C          dimensionless result.
C
         CXF1L(ND)=CXF1L(ND)*TERM
         CXF2L(ND)=CXF2L(ND)*TERM
      ENDDO
      RETURN
C
      END


