*DECK NXTAVS
      SUBROUTINE NXTAVS(IPRINT,NDIM  ,ITYPBC,
     >                  NFSUR ,NFREG ,NSUR  ,NREG  ,
     >                  MIX   ,INDXSR,IDSUR ,IDREG ,SVSGEO,DFACC ,
     >                  MATALB,SURVOL)
*
*----------
*
*Purpose:
* To add current cell information to global
* surfaces and volumes for geometry.
*
*Copyright:
* Copyright (C) 2005 Ecole Polytechnique de Montreal.
*
*Author(s):
* G. Marleau.
*
*Update(s):
* 2005/09/29: Validated with DRAGON and documented in
*             Report IGE-260.
*
*Reference:
*  G. Marleau,
*  \textsl{New Geometries Processing in DRAGON: The NXT: Module},
*  Report IGE-260, \'{E}cole Polytechnique de Montr\'{e}al,
*  Montr\'{e}al, 2005.
*
*Parameters: input
* IPRINT  print level.
* NDIM    problem dimensions.
* ITYPBC  type of boundary conditions where
*         \begin{itemize}
*         \item \moc{ITYPBC}=0 for geometry with Cartesian
*         boundaries;
*         \item \moc{ITYPBC}=1 for geometry with annular
*         boundary;
*         \item \moc{ITYPBC}=2 for geometry with hexagonal
*         boundary;
*         \end{itemize}
* NFSUR   final number of surfaces.
* NFREG   final number of regions.
* NSUR    maximum number of surfaces in splitted geometry.
* NREG    maximum number of regions in splitted geometry.
* MIX     geometry mixtures (including HMIX).
* INDXSR  local indexing of surfaces/regions.
* IDSUR   local surface identifier .
* IDREG   local region identifier.
* SVSGEO  area/volume of regions.
* DFACC   multiplication factor for surface and volume.
*
*Parameters: input/output
* MATALB  global mixture/albedo identification vector (including HMIX).
* SURVOL  global surface volume vector.
*
*Parameters: temporary storage
*
*----------
*
      IMPLICIT         NONE
*----
*  Subroutine arguments
*----
      INTEGER          IPRINT,NDIM,ITYPBC,NFSUR,NFREG,NSUR,NREG
      INTEGER          MIX(NREG,2),INDXSR(4,-NSUR:NREG),
     >                 IDREG(NREG),IDSUR(NSUR)
      DOUBLE PRECISION SVSGEO(-NSUR:NREG),DFACC
      INTEGER          MATALB(-NFSUR:NFREG,2)
      DOUBLE PRECISION SURVOL(-NFSUR:NFREG)
*----
*  Local parameters
*----
      INTEGER          IOUT
      CHARACTER        NAMSBR*6
      PARAMETER       (IOUT=6,NAMSBR='NXTAVS')
*----
*  Local variables
*----
      INTEGER          NDSCAN,ISV,IDSV,IFSV,ID,IDSA
      INTEGER          IDALB(8)
*----
*  Processing starts:
*  print routine openning output header if required
*  and initialize various parameters.
*----
      IF(IPRINT .GE. 100) THEN
        WRITE(IOUT,6000) NAMSBR
*        IF(IPRINT .GE. 500) THEN
*          WRITE(IOUT,*) 'MATALB'
*          WRITE(IOUT,'(10I10)') (MATALB(ISV,1),ISV=-NFSUR,NFREG)
*          WRITE(IOUT,*) 'HOMMATALB'
*          WRITE(IOUT,'(10I10)') (MATALB(ISV,2),ISV=-NFSUR,NFREG)
*          WRITE(IOUT,*) 'SURVOL'
*          WRITE(IOUT,'(1P,5E20.10)') (SURVOL(ISV),ISV=-NFSUR,NFREG)
*        ENDIF
      ENDIF
      NDSCAN=NDIM
      IF(ITYPBC .EQ. 2) THEN
        NDSCAN=4
        CALL XDISET(IDALB,8,-1)
        IDALB(5)=-5
        IDALB(6)=-6
      ELSE
        NDSCAN=NDIM
        DO ISV=1,6
          IDALB(ISV)=-ISV
        ENDDO
        IDALB(7)=-1
        IDALB(8)=-2
      ENDIF
*----
*  Add surface contributions
*----
      DO ISV=1,NSUR
        IDSV=IDSUR(ISV)
*         WRITE(IOUT,*) 'Surface =',ISV,IDSV,SVSGEO(-ISV),
*     >  INDXSR(1,-ISV),INDXSR(2,-ISV),
*     >  INDXSR(3,-ISV),INDXSR(4,-ISV)
        IF(IDSV .NE. 0) THEN
          IFSV=-ABS(IDSV)
          SURVOL(IFSV)=SURVOL(IFSV)+DFACC*SVSGEO(-ISV)
          IF(IDSV .GT. 0) THEN
            DO ID=1,NDSCAN
              IF(INDXSR(ID,-ISV) .LT. 0) THEN
                IDSA=2*(ID-1)-INDXSR(ID,-ISV)
*                WRITE(IOUT,*) 'SS',ISV,IDSV,IFSV,ID,IDSA,IDALB(IDSA)
                MATALB(IFSV,1)=IDALB(IDSA)
                MATALB(IFSV,2)=IDALB(IDSA)
                GO TO 105
              ENDIF
            ENDDO
*----
*  Albedo type not found
*----
            CALL XABORT(NAMSBR//': Albedo type not found')
 105        CONTINUE
          ENDIF
        ENDIF
      ENDDO
*----
*  Add volume contribution
*----
      DO ISV=1,NREG
        IDSV=IDREG(ISV)
        IF(IDSV .NE. 0) THEN
          IFSV=ABS(IDSV)
          SURVOL(IFSV)=SURVOL(IFSV)+DFACC*SVSGEO(ISV)
          IF(IDSV .GT. 0) THEN
            MATALB(IFSV,1)=MIX(ISV,1)
            MATALB(IFSV,2)=MIX(ISV,2)
          ENDIF
        ENDIF
      ENDDO
*----
*  Processing finished:
*  print routine closing output header if required
*  and return
*----
      IF(IPRINT .GE. 100) THEN
        IF(IPRINT .GE. 500) THEN
          WRITE(IOUT,*) 'MATALB'
          WRITE(IOUT,'(10I10)') (MATALB(ISV,1),ISV=-NFSUR,NFREG)
          WRITE(IOUT,*) 'HOMMATALB'
          WRITE(IOUT,'(10I10)') (MATALB(ISV,2),ISV=-NFSUR,NFREG)
          WRITE(IOUT,*) 'SURVOL'
          WRITE(IOUT,'(1P,5E20.10)') (SURVOL(ISV),ISV=-NFSUR,NFREG)
        ENDIF
        WRITE(IOUT,6001) NAMSBR
      ENDIF
      RETURN
*----
*  Output formats
*----
 6000 FORMAT('(* Output from --',A6,'-- follows ')
 6001 FORMAT('   Output from --',A6,'-- completed *)')
      END
