*DECK SPHSCO
      SUBROUTINE SPHSCO(IPCPO,ICAL,IMPX,NMIL,NGRP,NWGTH,SPH)
*
*-----------------------------------------------------------------------
*
*Purpose:
* apply a new set of SPH factors for an elementary calculation in a
* Multicompo.
*
*Copyright:
* Copyright (C) 2012 Ecole Polytechnique de Montreal
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version
*
*Author(s): A. Hebert
*
*Parameters: input
* IPCPO   pointer to the Multicompo (L_MULTICOMPO signature).
* ICAL    index of the elementary calculation being considered.
* IMPX    print parameter (equal to zero for no print).
* NMIL    number of mixtures in the elementary calculation.
* NGRP    number of energy groups in the elementary calculation.
* NWGTH   order of SPH factors used in equivalence:
*         = 0 only P0; = 1 P0 and P1.
* SPH     SPH-factor set to be applied to the Multicompo.
*
*-----------------------------------------------------------------------
*
      USE GANLIB
*----
*  SUBROUTINE ARGUMENTS
*----
      TYPE(C_PTR) IPCPO
      INTEGER ICAL,IMPX,NMIL,NGRP
      REAL SPH(NMIL,NGRP,NWGTH+1)
*----
*  LOCAL VARIABLES
*----
      PARAMETER (NSTATE=40,IOUT=6)
      INTEGER ISTATE(NSTATE)
      TYPE(C_PTR) JPCPO,KPCPO,LPCPO,MPCPO
      REAL, ALLOCATABLE, DIMENSION(:) :: SPH2
*
      CALL LCMLEN(IPCPO,'STATE-VECTOR',ILENG,ITYLCM)
      IF(ILENG.EQ.0) CALL XABORT('SPHSCO: INVALID MULTICOMPO.')
      CALL LCMGET(IPCPO,'STATE-VECTOR',ISTATE)
      IF(NMIL.NE.ISTATE(1)) THEN
        CALL XABORT('SPHSCO: INVALID NUMBER OF MIXTURES(1).')
      ELSE IF(NGRP.NE.ISTATE(2)) THEN
        CALL XABORT('SPHSCO: INVALID NUMBER OF ENERGY GROUPS(1).')
      ELSE IF((ICAL.LE.0).OR.(ICAL.GT.ISTATE(3))) THEN
        CALL XABORT('SPHSCO: INVALID VALUE OF ICAL.')
      ENDIF
      JPCPO=LCMGID(IPCPO,'MIXTURES')
      DO 20 IBM=1,NMIL
      IF(IMPX.GT.0) WRITE(IOUT,'(/33H SPHSCO: PROCESS MULTICOMPO MIXTU,
     1 2HRE,I5)') IBM
      KPCPO=LCMGIL(JPCPO,IBM)
      LPCPO=LCMGID(KPCPO,'CALCULATIONS')
      MPCPO=LCMGIL(LPCPO,ICAL)
      CALL LCMGET(MPCPO,'STATE-VECTOR',ISTATE)
      IF(ISTATE(1).NE.1) THEN
        CALL XABORT('SPHSCO: INVALID NUMBER OF MIXTURES(2).')
      ELSE IF(ISTATE(3).NE.NGRP) THEN
        CALL XABORT('SPHSCO: INVALID NUMBER OF ENERGY GROUPS(2).')
      ENDIF
      NISOT=ISTATE(2)
      NL=ISTATE(4)
      NED=ISTATE(13)
      NDEL=ISTATE(19)
      ALLOCATE(SPH2(NGRP*(NWGTH+1)))
      DO 10 IW=0,NWGTH
      DO 10 IGR=1,NGRP
   10 SPH2(IW*NGRP+IGR)=SPH(IBM,IGR,IW+1)
      CALL SPHCMI(MPCPO,IMPX,1,NISOT,NGRP,NWGTH,NL,NED,NDEL,SPH2)
      DEALLOCATE(SPH2)
   20 CONTINUE
      RETURN
      END
