C CUPCHM    SOURCE    CB215821  25/04/23    21:15:10     12247          
      subroutine cupchm(bu,bufPos,pChelm)
C=======================================================================
C     COLlaborateur UnPAQuettage Champ par eleMent
C     Recuperation d'un champ par element  dans le buffer bu
C=======================================================================
      integer bufPos
      integer lonBuf
      integer nbComp,iComp,nbInf
      integer longTit,longConch
      integer nbCons,iCons,nconch
      integer n1,n2,n3,l1,n1ptel,n1el,n2ptel,n2el

-INC PPARAM
-INC SMCHAML
-INC SMCOORD

      segment BUFFER
      character ffer(lonBuf)
      endsegment
      pointeur pChelm.MCHELM
      pointeur pChaml.MCHAML
      pointeur pElval.MELVAL
      pointeur bu.BUFFER

C      write(ioimp,*) 'Entre dans CUPCHM'
      lonBuf=bu.ffer(/2)
      call mpiupI(nbCons,1, bu,bufPos)
C      write(ioimp,*)'Nombre de constituants',nbCons
      call mpiupI(nbInf,1, bu,bufPos)
C      write(ioimp,*)'Nombre d infos',nbInf
      call mpiupI(longTit,1, bu,bufPos)
C      write(ioimp,*)'Longueur titre',longTit
      call mpiupI(longConch,1, bu,bufPos)
C      write(ioimp,*)'Longueur nom constituant',longConch

      l1=longtit
      if(nconch.ne.longConch) then
         write(ioimp,*) 'Taille de chaine de caracterer incoherente'
         call erreur(5)
      endif
      n1=nbcons
      n3=nbinf
      if (pChelm.ne.0) then
         segact pChelm*mod
         segadj pChelm
      else
         segini pChelm
      endif
C     Lecture du titre
      call mpiupC( pChelm.titche,longTit , bu,bufPos)
C      write(ioimp,*)'Lecture du titre'
C               write(ioimp,*)'Position du buffer',bufPos
C     Lecture du nom des constituants
      call mpiupC( pChelm.conche,nbCons*longConch , bu,bufPos)
C      write(ioimp,*)'Lecture des noms'
      call mpiupI( pChelm.imache,nbCons, bu,bufPos)
C      write(ioimp,*)'Lecture des maillages',pChelm.imache(1)
      call mpiupI( pChelm.infche(1,1),nbCons*nbInf, bu,bufPos)
C      write(ioimp,*)'Lecture des infos'
      call mpiupI( pChelm.ifoche,1, bu,bufPos)
C      write(ioimp,*)'Lecture de ifoche',pChelm.ifoche
C               write(ioimp,*)'Position du buffer',bufPos

      do iCons=1,nbCons
C         write(ioimp,*) 'Constituant :',iCons
      call mpiupI(nbComp,1, bu,bufPos)
C         write(ioimp,*)'nbComp',nbComp
      n2=nbComp
      segini pChaml
C         write(ioimp,*) 'pChaml',pChaml
      pChelm.ichaml(iCons)=pChaml
      if(nbComp.gt.0)then
         call mpiupC( pChaml.nomche(1),nbComp*LOCOMP, bu,bufPos)
C            write(ioimp,*)'Lecture du nom de composante'
C            write(ioimp,*)'Position du buffer',bufPos
         call mpiupC( pChaml.typche(1),nbComp*16, bu,bufPos)
C            write(ioimp,*)'Lecture du type de composante'
C            write(ioimp,*)'Position du buffer',bufPos
         do iComp=1,nbComp
         call mpiupI(n1ptel,1, bu,bufPos)
         call mpiupI(n1el,1, bu,bufPos)
         call mpiupi(n2ptel,1, bu,bufPos)
         call mpiupI(n2el,1, bu,bufPos)
C            write(ioimp,*)'Nombre de choses',n1ptel,n1el,n2ptel,n2el
         segini pElval
C            write(ioimp,*) 'pElval alloue',pElval
         pChaml.iElval(iComp)=pElval

         if(n1ptel*n1el.ne.0) then
            call mpiupR(pElval.velche(1,1),n1ptel*n1el, bu,bufPos)
         endif
         if(n2ptel*n2el.ne.0) then
            call mpiupI( pElval.ielche(1,1),n2ptel*n2el, bu,bufPos)
         endif
         segdes pElval
         enddo
      endif
      segdes pChaml
      enddo
      segdes pChelm
C      write(ioimp,*) 'Sortie de CUPCHM'
      end


 
 
