C-------------------------------------------------------------------- SUBROUTINE TOFUNPACK(vecta,lung,me) C D.Campana, Dec. 04 C--------------------------------------------------------------------- IMPLICIT NONE C C Normal variables definition C integer lung integer*1 vecta(lung) integer me integer check, crctof integer ic0,sup,inf integer i, ic, bit, bi,j integer start,ntdc integer tdcid(12),evcount(12) integer tdcmask(12),adc(4,12),tdc(4,12) integer rawadc(4,12),rawtdc(4,12),grayadc(4,12),graytdc(4,12) integer temp1(12),temp2(12) C c data start,ntdc /150,12/ ! to read data before Christmas 2004 data start,ntdc /153,12/ ! to read data after Christmas 2004 COMMON / tofvar /tdcid,evcount,tdcmask,adc,tdc,temp1,temp2 save / tofvar / C C Begin ! C C C AAA : Bisogna definire un pattern per il tof C ic = start C c print *,'++++++++++ Tof Unpack ++++++++++++++++' do j = 1,ntdc ic0 = ic ! primo indice per il calcolo del CRC tdcid(j) = 0 evcount(j) = 0 do bit = 0, 7 bi = ibits(vecta(ic),bit,1) if (bi.eq.1) tdcid(j) = ibset(tdcid(j),bit) bi = ibits(vecta(ic+1),bit,1) if (bi.eq.1) evcount(j) = ibset(evcount(j),bit) enddo c print *,'tdcid(',j,')', 'evcount(',j,')' c print *,tdcid(j), evcount(j) c ic=ic+2 tdcmask(j) = 0 do bit = 0, 7 bi = ibits(vecta(ic),bit,1) if (bi.eq.1) tdcmask(j) = ibset(tdcmask(j),bit+8) bi = ibits(vecta(ic+1),bit,1) if (bi.eq.1) tdcmask(j) = ibset(tdcmask(j),bit) enddo c print *,'tdcmask(',j,')' c print *,tdcmask(j) ic=ic+2 do i=1,4 rawadc(i,j) = 0 rawtdc(i,j) = 0 grayadc(i,j) = 0 graytdc(i,j) = 0 do bit = 0, 7 bi = ibits(vecta(ic),bit,1) if (bi.eq.1) rawadc(i,j) = ibset(rawadc(i,j),bit+8) bi = ibits(vecta(ic+1),bit,1) if (bi.eq.1) rawadc(i,j) = ibset(rawadc(i,j),bit) bi = ibits(vecta(ic+2),bit,1) if (bi.eq.1) rawtdc(i,j) = ibset(rawtdc(i,j),bit+8) bi = ibits(vecta(ic+3),bit,1) if (bi.eq.1) rawtdc(i,j) = ibset(rawtdc(i,j),bit) enddo c print *,'rawadc(',i,',',j,')','rawtdc(',i,',',j,')' c print *, rawadc(i,j),rawtdc(i,j) c c adc e tdc data have to be translated from Gray code to binary (bit 0-11) c bit 12 is added after conversion (control bit) c bit 13 is 1(0) for charge(time) information c bits 14-15 give the channel 1-4 on the board. c grayadc(i,j)=ibits(rawadc(i,j),0,12) graytdc(i,j)=ibits(rawtdc(i,j),0,12) c call graytobin(grayadc(i,j),adc(i,j),12) call graytobin(graytdc(i,j),tdc(i,j),12) c print *,'grayadc(',i,',',j,')','graytdc(',i,',',j,')' c print *, grayadc(i,j),graytdc(i,j) c print *,'adc(',i,',',j,')','tdc(',i,',',j,')','prima del bit 12' c print *, adc(i,j),tdc(i,j) c bi = ibits(rawtdc(i,j),12,1) if (bi.eq.1) tdc(i,j) = ibset(tdc(i,j),12) bi = ibits(rawadc(i,j),12,1) if (bi.eq.1) adc(i,j) = ibset(adc(i,j),12) c c print *,'adc(',i,',',j,')','tdc(',i,',',j,')' c print *, adc(i,j),tdc(i,j) c ic=ic+4 enddo c temp1(j) = 0 temp2(j) = 0 do bit = 0, 7 bi = ibits(vecta(ic),bit,1) if (bi.eq.1) temp1(j) = ibset(temp1(j),bit) bi = ibits(vecta(ic+1),bit,1) if (bi.eq.1) temp2(j) = ibset(temp2(j),bit) enddo c print *,'temp1(',j,')', 'temp2(',j,')' c print *,temp1(j), temp2(j) ic=ic+2 c c vecta(ic) is the CRC c Check consistency of CRC. c if(vecta(ic).lt.0)vecta(ic)=vecta(ic)+256 check = 0 inf = ic0 sup = ic - 1 do i = inf,sup check=crctof(check,vecta(i)) enddo if (check.ne.vecta(ic)) then c print *,'crc sbagliato ',vecta(ic), check me = 1 else c print *,'crc corretto ',vecta(ic) endif c c print *,'---------> ic, j' ,ic,j ic=ic+1 enddo ! j = 1,ntdc RETURN END