C
C  Written by Mirko Boezio and Emiliano Mocchiutti
C
C     * Version: 2.17.1 *
C 
C-----------------------------------------------------
      SUBROUTINE RIEMPI(m,lunga,lleng,lung,pari,vect,vecta)
C-----------------------------------------------------

      IMPLICIT NONE
C
      integer m, lunga ,lleng, lung, i, bi, bit,pari
      INTEGER*2 VECT(30000) 
      INTEGER*1 VECTA(lung) 
C
      INTEGER iev,iev2
C
      INTEGER NPLA, NCHA, LENSEV
      PARAMETER (NPLA=22,NCHA=96,LENSEV=NPLA*NCHA)
      INTEGER merror(4)
      integer*2 e2(4)
      INTEGER contr
      REAL DEXY(2,NPLA,NCHA), dexyc(2,npla,ncha), base(2,npla,6)

  
      real calselftrig(4,7), calIItrig(4), calstripshit(4),
     &     calDSPtaberr(4), calevnum(4)
      

      REAL calped(4,11,96), calgood(4,11,96), calthr(4,11,6)
      REAL calrms(4,11,96), calbase(4,11,6), calvar(4,11,6)
      REAL calpuls(4,11,96)
      real perror(4)
      integer stwerr(4),dump

      COMMON / evento / IEV, stwerr,perror,
     &     dexy,dexyc,base,
     &     calselftrig,calIItrig,
     &     calstripshit,calDSPtaberr,calevnum
      
      save / evento /

      COMMON / calib / IEV2, calped, calgood, calthr, calrms, 
     &     calbase,
     &     calvar,
     &     calpuls

      save / calib /
c
      COMMON / VARIE / dump, CONTR
      SAVE / VARIE /
C
      do i = 1, (lunga - lleng)
         vect(i) = 0
         if (m.le.lung) then
            do bit=0, 7
               if (pari.eq.1.and.m.eq.lung) then
                  bi = ibits(vecta(m+1),bit,1)                     
                  if (bi.eq.1) vect(i) = ibset(vect(i),bit)
               endif
               if (m.lt.lung) then
                  bi = ibits(vecta(m+1),bit,1)                     
                  if (bi.eq.1) vect(i) = ibset(vect(i),bit)
               endif                       
               bi = ibits(vecta(m),bit,1)
               if (bi.eq.1) vect(i) = ibset(vect(i),bit+8)
            enddo 
         endif
         m = m + 2
      enddo
c
 17   FORMAT(2X,'Elemento:',2X,I4,2X,' word:',2X,Z8)
      return 
      end
