C
C PURPOSE: CALCULATE EMISSION COEFFICIENTS FOR STOKES VECTOR 
C
C INPUTS:
C       KR   TRANSITION INDEX (1=FIRST TRANSITION, ETC)
C       T0   GEOMETRIC TENSOR (TABLE 1 OF
C            CASINI, R. & JUDGE, P. G., 1999. AP J 522, 524-539)
C OUTPUTS:
C   EMISS(KR,I,NY)  EMISSION COEFFICIENT IN PH/CM2/S/SR/ANGSTROM 
C   WHERE  KR IS THE LINE INDEX
C          I IS THE STOKES INDEX (0=INTENSITY, 1=Q, ETC.)
C          NU IS THE FREQUENCY INDEX
C
C COMMON:
C       CSE CSLINE CATOM CORON SGNM CLU
C COMMENTS: OCTOBER 6, 1999, P. JUDGE
C 
	SUBROUTINE EMISSION(KR,T0)
	INCLUDE 'PREC'
	INCLUDE 'PARAM'
	INCLUDE 'CSE'
	INCLUDE 'CSLINE'
	INCLUDE 'CCONST'
	INCLUDE 'CATOM'
	INCLUDE 'CORON'
	INCLUDE 'SGNM'
	INCLUDE 'CINTS'
	INCLUDE 'CLU'
C
	PARAMETER (SQRT2=.14142135623730950488E1)
	PARAMETER (SQRT3=.17320508075688772935E1)
C
	DIMENSION T0(0:3,0:2)
	DIMENSION EM_FACT(0:4)
C
	IJ0=IRAD(KR)
	IJ1=JRAD(KR)
	RJ0=AJ(IJ0)
	RJ1=AJ(IJ1)
C
C CALCULATE C_COEFF
C
	HNU=HH*CC / (ALAMB(KR)/1.E8)
	C_COEFF=TOTN*SQRT(TWO*RJ1+ONE)*RHO(IJ1,0)*A(KR)
     *         *HNU/FOUR/PI
C 	WRITE(*,*) 'KR,IJ1,C_COEFF,TOTN,RJ1,RHO(IJ1,0),A(KR)',
C     *     KR,IJ1,C_COEFF,TOTN,RJ1,RHO(IJ1,0),A(KR)
C
C  	write(*,*) kr, alamb(kr),label(ij1),rho(ij1,0)
	G0=GLAND(IJ0)
	G1=GLAND(IJ1)
	GEFF=0.5*(G0+G1)+0.25*(G0-G1)*(RJ0*(RJ0+ONE)-RJ1*(RJ1+ONE))
	SIGMA=RHO(IJ1,2)/RHO(IJ1,0)
C        WRITE(*,*) RHO(IJ1,2),RHO(IJ1,0)
C
C   CALCULATE DCOEFF AND ECOEFF
C
	D_COEFF=-SG(NINT(RJ0+RJ1))*SQRT(THREE*(TWO*RJ1+1))
     /	 *FUN6J(ONE,ONE,TWO,RJ1,RJ1,RJ0)
C
      E_COEFF=THREE*SQRT(TWO*RJ1+ONE)
     /	 *(SG(NINT(RJ1-RJ0))*G1*SQRT(RJ1*(RJ1+ONE)*(TWO*RJ1+ONE))
     /	 *FUN6J(ONE,TWO,ONE,RJ1,RJ1,RJ1)
     /	 *FUN6J(ONE,ONE,ONE,RJ1,RJ1,RJ0)
     /	 -G0*SQRT(RJ0*(RJ0+ONE)*(TWO*RJ0+ONE))
     /	 *FUN9J(ONE,TWO,ONE,RJ0,RJ1,ONE,RJ0,RJ1,ONE))
C
C   CALCULATE EMISSION COEFFICIENTS
C
	EM_FACT(0)=ONE+D_COEFF*SIGMA*T0(0,2)
	EM_FACT(1)=D_COEFF*SIGMA*T0(1,2)
	EM_FACT(2)=D_COEFF*SIGMA*T0(2,2)
	EM_FACT(3)=-(SQRT2/SQRT3)*ALARMOR*(GEFF+E_COEFF*SIGMA)*T0(3,1) 
	EM_FACT(4)=-(SQRT2/SQRT3)*ALARMOR*GEFF*T0(3,1) 
C	write(*,*) em_fact(0),em_fact(1),em_fact(2),em_fact(3),em_fact(4)
C
C EMISS(*,4,*): MAGNETOGRAM STOKES V
C
	SCL=C_COEFF*1.E-13*ALAMB(KR)
	DO NY=1,NQ(KR)
	  EMISS(KR,0,NY)=EM_FACT(0)*PHI(KR,NY)*C_COEFF
	  EMISS(KR,1,NY)=EM_FACT(1)*PHI(KR,NY)*C_COEFF
	  EMISS(KR,2,NY)=EM_FACT(2)*PHI(KR,NY)*C_COEFF
	  EMISS(KR,3,NY)=-EM_FACT(3)*PHIP(KR,NY)*SCL
	  EMISS(KR,4,NY)=-EM_FACT(4)*PHIP(KR,NY)*SCL
	END DO
C	WRITE(*,*) EMISS(1,0,1),EMISS(1,1,1),EMISS(1,2,1),EMISS(1,3,1),EMISS(1,4,1)
C	WRITE(*,*) EM_FACT(0),EM_FACT(1),EM_FACT(2),EM_FACT(3),EM_FACT(4)
C	WRITE(*,*) D_COEFF,SIGMA,T0(0,2),T0(1,2),T0(2,2),T0(3,1),ALARMOR,GEFF,E_COEFF
C	WRITE(*,*) SIGMA
	RETURN
	END
