*DECK RESHID
      SUBROUTINE RESHID(IPMAP,IPMTX,NX,NZ,LX,LZ,MIX,NFUEL,IMPX)
*
*-----------------------------------------------------------------------
*
*Purpose:
* update material index, it will store the negative fuel mixtures.
*
*Copyright:
* Copyright (C) 2007 Ecole Polytechnique de Montreal.
*
*Author(s): V. Descotes
*
*Parameters: input/output
* IPMAP  pointer to fuel-map information.
* IPMTX  pointer to matex information.
* NX     number of elements along x-axis in fuel map.
* NZ     number of elements along z-axis in fuel map.
* LX     number of elements along x-axis in geometry.
* LZ     number of elements along z-axis in geometry.
* MIX    renumbered index over the fuel-map geometry.
* NFUEL  number of fuel types.
* IMPX   printing index (=0 for no print).
*
*-----------------------------------------------------------------------
*
      USE GANLIB
*----
*  SUBROUTINE ARGUMENTS
*----
      TYPE(C_PTR) IPMAP,IPMTX
      INTEGER NX,NZ,LX,LZ,MIX(NX*NZ),NFUEL,IMPX
*----
*  LOCAL VARIABLES
*----
      PARAMETER(IOUT=6)
      INTEGER INDX(LX*LZ),FTOT(NFUEL)
      REAL    MAPZZ(NZ+1),MTXSIDE,GEOZZ(LZ+1),MAPSIDE
      TYPE(C_PTR) JPMAP
*----
*  ALLOCATABLE ARRAYS
*----
      INTEGER, ALLOCATABLE, DIMENSION(:) :: IMAT
*----
*  UPDATE MATERIAL INDEX
*----
      CALL LCMGET(IPMTX,'SIDE',MTXSIDE)
      CALL LCMGET(IPMTX,'MESHZ',GEOZZ)
      JPMAP=LCMGID(IPMAP,'GEOMAP')
      CALL LCMGET(JPMAP,'SIDE',MAPSIDE)
      CALL LCMGET(JPMAP,'MESHZ',MAPZZ)
      CALL XDISET(INDX,LX*LZ,0)
      IF(IMPX.GT.2)WRITE(IOUT,*)'UPDATING MATERIAL INDEX'
      K1=0
      K2=0
      DO 30 KM=1,NZ
      DO 30 IM=1,NX
      DO KG=1,LZ
      IF(MAPZZ(KM).EQ.GEOZZ(KG)) K1=KG
      IF(MAPZZ(KM+1).EQ.GEOZZ(KG+1))THEN
        K2=KG
        GOTO 10
      ENDIF
      ENDDO
   10 IELM=(KM-1)*NX+IM
      DO 20 KG=K1,K2
      IG=IM
      IELG=(KG-1)*LX+IG
      INDX(IELG)=MIX(IELM)
   20 CONTINUE
   30 CONTINUE
*     CHECK TOTAL NUMBER
      ITOT=0
      DO 40 IEL=1,LX*LZ
   40 IF(INDX(IEL).NE.0)ITOT=ITOT+1
      NTOT=0
      CALL LCMGET(IPMTX,'FTOT',FTOT)
      DO 50 IFUEL=1,NFUEL
   50 NTOT=NTOT+FTOT(IFUEL)
      IF(ITOT.NE.NTOT) THEN
         WRITE(IOUT,'(/15H @RESHID: ITOT=,I8,6H NTOT=,I8)') ITOT,NTOT
         CALL XABORT('@RESHID: FOUND DIFFERENT TOTAL NUMBER OF FUEL MI'
     1   //'XTURES IN FUEL-MAP AND MATEX.')
      ENDIF
*     STORE NEGATIVE FUEL MIXTURES
      CALL LCMLEN(IPMTX,'MAT',LENGT,ITYP)
      ALLOCATE(IMAT(LENGT))
      CALL XDISET(IMAT,LENGT,0)
      CALL LCMGET(IPMTX,'MAT',IMAT)
      DO 100 IEL=1,LX*LZ
  100 IF(INDX(IEL).NE.0)IMAT(IEL)=-INDX(IEL)
      CALL LCMPUT(IPMTX,'MAT',LENGT,1,IMAT)
      DEALLOCATE(IMAT)
      RETURN
      END
