*DECK KINXSD
      SUBROUTINE KINXSD(IPMAC,NGR,NBM,NBFIS,NDG,EVL,DT,DNF,DNS,LNUD,
     1 LCHD,OVR,CHI,CHD,SGF,SGD)
*
*-----------------------------------------------------------------------
*
*Purpose:
* recover the 1/v and fission properties from L_MACROLIB which will be
* used for assembling source and kinetics matrix systems.
*
*Copyright:
* Copyright (C) 2010 Ecole Polytechnique de Montreal.
*
*Author(s): A. Hebert
*
*Parameters: input
* IPMAC  pointer to L_MACROLIB object.
* NGR    number of energy groups.
* NBM    number of material mixtures.
* NBFIS  number of fissile isotopes.
* NDG    number of delayed-neutron groups.
* EVL    steady-state eigenvalue.
* DNF    delayed neutron fractions (from module input).
* DNS    delayed neutron spectrum (from module input).
* LNUD   flag: =.true. if DNF provided from module input.
* LCHD   flag: =.true. if DNS provided from module input.
*
*Parameters: output
* OVR    reciprocal neutron velocities/DT.
* CHI    steady-state fission spectrum.
* CHD    delayed fission spectrum
* SGF    nu*fission macroscopic x-sections/keff.
* SGD    delayed nu*fission macroscopic x-sections/keff.
*
*-----------------------------------------------------------------------
*
      USE GANLIB
*----
*  SUBROUTINE ARGUMENTS
*----
      TYPE(C_PTR) IPMAC
      INTEGER NGR,NBM,NBFIS,NDG
      REAL EVL,DT,DNF(NDG),DNS(NDG,NGR),OVR(NBM,NGR),CHI(NBM,NBFIS,NGR),
     1 CHD(NBM,NBFIS,NGR,NDG),SGF(NBM,NBFIS,NGR),SGD(NBM,NBFIS,NGR,NDG)
      LOGICAL LNUD,LCHD
*----
*  LOCAL VARIABLES (AUTOMATIC ALLOCATION)
*----
      LOGICAL LFIS,LFISD
      CHARACTER TEXT12*12
      TYPE(C_PTR) JPMAC,KPMAC
*----
*  PROCESS FISSION SPECTRUM TERMS.
*----
      CALL XDRSET(CHI,NBM*NBFIS*NGR,0.)
      CALL XDRSET(CHD,NBM*NBFIS*NGR*NDG,0.)
      CALL XDRSET(SGF,NBM*NBFIS*NGR,0.)
      CALL XDRSET(SGD,NBM*NBFIS*NGR*NDG,0.)
      JPMAC=LCMGID(IPMAC,'GROUP')
      KPMAC=LCMGIL(JPMAC,1)
      CALL LCMLEN(KPMAC,'CHI',LENGT,ITYLCM)
      IF(LENGT.GT.0) THEN
        IF(LENGT.NE.NBM*NBFIS) CALL XABORT('@KINXSD: INVALID LENGTH FO'
     1  //'R CHI INFORMATION.')
        DO 10 IGR=1,NGR
        KPMAC=LCMGIL(JPMAC,IGR)
        CALL LCMGET(KPMAC,'CHI',CHI(1,1,IGR))
   10   CONTINUE
      ELSE
        DO 20 IBM=1,NBM
        DO 20 IFIS=1,NBFIS
        CHI(IBM,IFIS,1)=1.0
        DO 20 IGR=2,NGR
   20   CHI(IBM,IFIS,IGR)=0.0
      ENDIF
      IF(LCHD) THEN
        DO 30 IDEL=1,NDG
        DO 30 IGR=1,NGR
        DO 30 IFIS=1,NBFIS
        DO 30 IBM=1,NBM
   30   CHD(IBM,IFIS,IGR,IDEL)=DNS(IDEL,IGR)
      ELSE
        KPMAC=LCMGIL(JPMAC,1)
        CALL LCMLEN(KPMAC,'CHI01',LENGT,ITYLCM)
        IF(LENGT.GT.0) THEN
          IF(LENGT.NE.NBM*NBFIS) CALL XABORT('@KINXSD: INVALID LENGTH '
     1    //'FOR DELAYED CHI INFORMATION.')
          DO 40 IDEL=1,NDG
          WRITE(TEXT12,'(3HCHI,I2.2)') IDEL
          DO 40 IGR=1,NGR
          KPMAC=LCMGIL(JPMAC,IGR)
          CALL LCMGET(KPMAC,TEXT12,CHD(1,1,IGR,IDEL))
   40     CONTINUE
        ELSE
          CALL XDRSET(CHD,NBM*NBFIS*NGR*NDG,0.)
        ENDIF
      ENDIF
      LFIS=.FALSE.
      LFISD=.FALSE.
      DO 50 IGR=1,NGR
      DO 50 IFIS=1,NBFIS
      DO 50 IBM=1,NBM
      LFIS=LFIS.OR.(CHI(IBM,IFIS,IGR).NE.0.0)
   50 LFISD=LFISD.OR.(CHD(IBM,IFIS,IGR,1).NE.0.0)
*
      DO 80 IGR=1,NGR
      KPMAC=LCMGIL(JPMAC,IGR)
*----
*  PROCESS FISSION NUSIGF TERMS.
*----
      IF(LFIS) THEN
        CALL LCMLEN(KPMAC,'NUSIGF',LENGT,ITYLCM)
        IF(LENGT.NE.NBM*NBFIS) CALL XABORT('@KINXSD: INVALID LENGTH FO'
     1  //'R NUSIGF INFORMATION.')
        IF(LENGT.GT.0) CALL LCMGET(KPMAC,'NUSIGF',SGF(1,1,IGR))
      ENDIF
      IF(LNUD) THEN
        DO 60 IDEL=1,NDG
        DO 60 IFIS=1,NBFIS
        DO 60 IBM=1,NBM
   60   SGD(IBM,IFIS,IGR,IDEL)=SGF(IBM,IFIS,IGR)*DNF(IDEL)
      ELSE IF(LFISD) THEN
        DO 70 IDEL=1,NDG
        WRITE(TEXT12,'(6HNUSIGF,I2.2)') IDEL
        CALL LCMLEN(KPMAC,TEXT12,LENGT,ITYLCM)
        IF(LENGT.NE.NBM*NBFIS) CALL XABORT('@KINXSD: INVALID LENGTH FO'
     1  //'R DELAYED NUSIGF INFORMATION.')
        IF(LENGT.GT.0) CALL LCMGET(KPMAC,TEXT12,SGD(1,1,IGR,IDEL))
   70   CONTINUE
      ENDIF
*----
*  PROCESS 1/V TERMS.
*----
      CALL LCMLEN(KPMAC,'OVERV',LENGT,ITYLCM)
      IF(LENGT.EQ.NBM)THEN
        CALL LCMGET(KPMAC,'OVERV',OVR(1,IGR))
      ELSEIF(LENGT.EQ.0)THEN
        CALL XABORT('@KINXSD: MISSING OVERV DATA.')
      ELSE
        CALL XABORT('@KINXSD: INVALID OVERV DATA.')
      ENDIF
      DO 80 IBM=1,NBM
      OVR(IBM,IGR)=OVR(IBM,IGR)/DT
   80 CONTINUE
*
      DO 90 IGR=1,NGR
      DO 90 IFIS=1,NBFIS
      DO 90 IBM=1,NBM
      SGF(IBM,IFIS,IGR)=SGF(IBM,IFIS,IGR)/EVL
      DO 90 IDEL=1,NDG
   90 SGD(IBM,IFIS,IGR,IDEL)=SGD(IBM,IFIS,IGR,IDEL)/EVL
      RETURN
      END
