*DECK SCRMEM
      SUBROUTINE SCRMEM(IPSAP,IPMEM,NCAL,NMIL,NMIX,TERP,MIXC)
*
*-----------------------------------------------------------------------
*
*Purpose:
* copy a Saphyb into memory taking care to keep only required
* calculations and mixtures.
*
*Copyright:
* Copyright (C) 2013 Ecole Polytechnique de Montreal
*
*Author(s): A. Hebert
*
*Parameters: input
* IPSAP   address of the Saphyb object.
* IPMEM   address of the simplified Saphyb in memory created by SCRMEM.
* NCAL    number of elementary calculations in the Saphyb.
* NMIL    number of material mixtures in the Saphyb
* NMIX    maximum number of material mixtures in the microlib.
* TERP    interpolation factors.
* MIXC    mixture index in the Saphyb corresponding to each microlib
*         mixture.
*
*-----------------------------------------------------------------------
*
      USE GANLIB
*----
*  SUBROUTINE ARGUMENTS
*----
      TYPE(C_PTR) IPSAP,IPMEM
      INTEGER NCAL,NMIL,NMIX,MIXC(NMIX)
      REAL TERP(NCAL,NMIX)
*----
*  LOCAL VARIABLES
*----
      INTEGER DIMSAP(50)
      CHARACTER SIGN*12,TEXT12*12
      TYPE(C_PTR) JPSAP,JPMEM,KPSAP,KPMEM
*
      CALL LCMOP(IPMEM,'*tempSaphyb*',0,1,0)
      CALL LCMGTC(IPSAP,'SIGNATURE',12,1,SIGN)
      CALL LCMPTC(IPMEM,'SIGNATURE',12,1,SIGN)
      CALL LCMGET(IPSAP,'DIMSAP',DIMSAP)
      CALL LCMPUT(IPMEM,'DIMSAP',50,1,DIMSAP)
      JPSAP=LCMGID(IPSAP,'constphysiq')
      JPMEM=LCMDID(IPMEM,'constphysiq')
      CALL LCMEQU(JPSAP,JPMEM)
      JPSAP=LCMGID(IPSAP,'contenu')
      JPMEM=LCMDID(IPMEM,'contenu')
      CALL LCMEQU(JPSAP,JPMEM)
      JPSAP=LCMGID(IPSAP,'adresses')
      JPMEM=LCMDID(IPMEM,'adresses')
      CALL LCMEQU(JPSAP,JPMEM)
      JPSAP=LCMGID(IPSAP,'geom')
      JPMEM=LCMDID(IPMEM,'geom')
      CALL LCMEQU(JPSAP,JPMEM)
      DO 30 ICAL=1,NCAL
        DO IBM=1,NMIX
          IF(TERP(ICAL,IBM).NE.0.0) GO TO 10
        ENDDO
        GO TO 30
   10   WRITE(TEXT12,'(4Hcalc,I8)') ICAL
        JPSAP=LCMGID(IPSAP,TEXT12)
        JPMEM=LCMDID(IPMEM,TEXT12)
        KPSAP=LCMGID(JPSAP,'info')
        KPMEM=LCMDID(JPMEM,'info')
        CALL LCMEQU(KPSAP,KPMEM)
        KPSAP=LCMGID(JPSAP,'divers')
        KPMEM=LCMDID(JPMEM,'divers')
        CALL LCMEQU(KPSAP,KPMEM)
        CALL LCMLEN(JPSAP,'outflx',ILONG,ITYLCM)
        IF(ILONG.NE.0) THEN
          KPSAP=LCMGID(JPSAP,'outflx')
          KPMEM=LCMDID(JPMEM,'outflx')
          CALL LCMEQU(KPSAP,KPMEM)
        ENDIF
        DO IBMOLD=1,NMIL
          DO IBM=1,NMIX
           IF((TERP(ICAL,IBM).NE.0.).AND.(MIXC(IBM).EQ.IBMOLD)) GO TO 20
          ENDDO
          CYCLE
   20     WRITE(TEXT12,'(4Hmili,I8)') IBMOLD
          KPSAP=LCMGID(JPSAP,TEXT12)
          KPMEM=LCMDID(JPMEM,TEXT12)
          CALL LCMEQU(KPSAP,KPMEM)
        ENDDO
   30 CONTINUE
      RETURN
      END
