*DECK XENCAL
      SUBROUTINE XENCAL(IPLIB,IPPOW,NB,NCH,NGRP,NMIX,XEN)
*
*-----------------------------------------------------------------------
*
*Purpose:
* compute the Xenon distribution according to the bundle flux
*
*Copyright:
* Copyright (C) 2010 Ecole Polytechnique de Montreal
*
*Author(s): M. Guyot
*
*Parameters: input/output
* IPLIB   adress of the L_LIBRARY
* IPPOW   adress of the L_POWER
* NB      number of fuel bundles per channel
* NCH     number of channels
* NGRP    number of energy groups
* NMIX    number of mixtures present in the library
* FLUB    bundle fluxes
* XEN     xenon concentrations in each bundle
* SIGX    microscopic capture cross section of Xe-135
* SIGF    macroscopic fission cross section
*
*-----------------------------------------------------------------------
*
      USE GANLIB
*----
*  SUBROUTINE ARGUMENTS
*----
      TYPE(C_PTR) IPLIB,IPPOW
      INTEGER NB,NCH,NGRP,NMIX
      REAL XEN(NMIX)
*----
*  LOCAL VARIABLES
*----
      INTEGER ICH,IB,IGRP,IMIX
      REAL TAUF(NMIX,NGRP),TAUX(NMIX,NGRP),XLAMBDA,GAMMAI,GAMMAX,CF,TF,
     1 TX
      CHARACTER TEXT*12
      TYPE(C_PTR) JPLIB,KPLIB
      REAL, ALLOCATABLE, DIMENSION(:) :: SIGX,SIGF
      REAL, ALLOCATABLE, DIMENSION(:,:,:) :: FLUB
*----
*  SCRATCH STORAGE ALLOCATION
*----
      ALLOCATE(SIGX(NGRP),SIGF(NMIX),FLUB(NCH,NB,NGRP))
*----
* SET THE YIELD AND THE DECAY CONSTANTE FOR XENON
*----
      XLAMBDA = 2.09E-5
      GAMMAI = 0.0631
      GAMMAX = 0.0045
      CF=1.0E-24
*----
*  COMPUTE FISSION AND XENON REACTION RATES IN EACH BUNDLE
*---- 
      CALL XDRSET(FLUB,NCH*NB*NGRP,0.0)
      CALL LCMGET(IPPOW,'FLUX-BUND',FLUB)
      CALL XDRSET(TAUX,NMIX*NGRP,0.0)
      CALL XDRSET(TAUF,NMIX*NGRP,0.0)
      TEXT(1:8)='Xe135   '
      CALL LCMSIX(IPLIB,'MACROLIB',1)
      JPLIB=LCMGID(IPLIB,'GROUP')
      CALL LCMSIX(IPLIB,' ',2)

      DO 10 IGRP=1,NGRP 
        KPLIB=LCMGIL(JPLIB,IGRP)
        CALL LCMGET(KPLIB,'NFTOT',SIGF)
        DO 20 ICH=1,NCH
          DO 30 IB=1,NB
            IMIX=NCH*(IB-1)+ICH
            WRITE(TEXT(9:12),'(I4.4)') IMIX
            CALL LCMSIX(IPLIB,TEXT,1)
            CALL LCMGET(IPLIB,'NG',SIGX)
            CALL LCMSIX(IPLIB,' ',2)
            TAUX(IMIX,IGRP)=TAUX(IMIX,IGRP)+FLUB(ICH,IB,IGRP)*
     +        SIGX(IGRP)
            TAUF(IMIX,IGRP)=TAUF(IMIX,IGRP)+FLUB(ICH,IB,IGRP)*
     +        SIGF(IMIX)
   30     CONTINUE
   20   CONTINUE
   10 CONTINUE

      DO 40 IMIX=1,NMIX
        TF=0.0
        TX=0.0
        DO 50 IGRP=1,NGRP
          TF=TF+TAUF(IMIX,IGRP)
          TX=TX+TAUX(IMIX,IGRP)
   50   CONTINUE
        XEN(IMIX)=CF*(GAMMAX+GAMMAI)*TF/(XLAMBDA+TX*CF)
   40 CONTINUE
*----
*  SCRATCH STORAGE DEALLOCATION
*----
      DEALLOCATE(FLUB,SIGF,SIGX)
      RETURN
      END
