10 |
C |
C |
11 |
integer lung |
integer lung |
12 |
integer*1 vecta(lung) |
integer*1 vecta(lung) |
13 |
|
integer*2 ibuf |
14 |
integer me |
integer me |
15 |
integer check, crctof |
integer check, crctof |
16 |
integer ic0,sup,inf |
integer ic0,sup,inf |
17 |
integer i, ic, bit, bi,j |
integer i, ic, bit, bi,j |
18 |
integer start,ntdc |
integer start,ntdc,tdcfirst |
19 |
integer tdcid(12),evcount(12) |
integer tdcid(12),evcount(12) |
20 |
integer tdcmask(12),adc(4,12),tdc(4,12) |
integer tdcmask(12),adc(4,12),tdc(4,12) |
21 |
integer rawadc(4,12),rawtdc(4,12),grayadc(4,12),graytdc(4,12) |
integer rawadc(4,12),rawtdc(4,12),grayadc(4,12),graytdc(4,12) |
22 |
integer temp1(12),temp2(12) |
integer temp1(12),temp2(12) |
23 |
|
logical flag2 |
24 |
C |
C |
25 |
c data start,ntdc /150,12/ ! to read data before Christmas 2004 |
c data start,ntdc /150,12/ ! to read data before Christmas 2004 |
26 |
data start,ntdc /153,12/ ! to read data after Christmas 2004 |
data start,ntdc /153,12/ ! to read data after Christmas 2004 |
33 |
C |
C |
34 |
|
|
35 |
C |
C |
36 |
C AAA : Bisogna definire un pattern per il tof |
C AAA : would be better to have a pattern for the tof! |
37 |
|
C at this moment we have just a pointer (start) |
38 |
C |
C |
39 |
|
|
40 |
ic = start |
ic = start |
42 |
c print *,'++++++++++ Tof Unpack ++++++++++++++++' |
c print *,'++++++++++ Tof Unpack ++++++++++++++++' |
43 |
|
|
44 |
do j = 1,ntdc |
do j = 1,ntdc |
45 |
ic0 = ic ! primo indice per il calcolo del CRC |
flag2=.true. |
46 |
|
ic0 = ic ! first index for the CRC computation |
47 |
tdcid(j) = 0 |
tdcid(j) = 0 |
48 |
evcount(j) = 0 |
evcount(j) = 0 |
49 |
do bit = 0, 7 |
do bit = 0, 7 |
52 |
bi = ibits(vecta(ic+1),bit,1) |
bi = ibits(vecta(ic+1),bit,1) |
53 |
if (bi.eq.1) evcount(j) = ibset(evcount(j),bit) |
if (bi.eq.1) evcount(j) = ibset(evcount(j),bit) |
54 |
enddo |
enddo |
|
c print *,'tdcid(',j,')', 'evcount(',j,')' |
|
|
c print *,tdcid(j), evcount(j) |
|
55 |
c |
c |
56 |
ic=ic+2 |
ic=ic+2 |
57 |
tdcmask(j) = 0 |
tdcmask(j) = 0 |
61 |
bi = ibits(vecta(ic+1),bit,1) |
bi = ibits(vecta(ic+1),bit,1) |
62 |
if (bi.eq.1) tdcmask(j) = ibset(tdcmask(j),bit) |
if (bi.eq.1) tdcmask(j) = ibset(tdcmask(j),bit) |
63 |
enddo |
enddo |
64 |
c print *,'tdcmask(',j,')' |
c |
|
c print *,tdcmask(j) |
|
|
|
|
65 |
ic=ic+2 |
ic=ic+2 |
66 |
|
c |
67 |
|
c |
68 |
|
c if first 3 bit of the word RAWADC are equal to 0 |
69 |
|
c the data storage is shifted by a word --> ic = ic+1 |
70 |
|
c and TEMP2 is overwritten by the CRC --> flag2=.false. |
71 |
|
c |
72 |
|
tdcfirst = 0 |
73 |
|
do bit = 5,7 |
74 |
|
bi = ibits(vecta(ic),bit,1) |
75 |
|
if (bi.eq.1) tdcfirst = ibset(tdcfirst,bit-5) |
76 |
|
enddo |
77 |
|
if (tdcfirst.eq.0) then |
78 |
|
ic=ic+1 |
79 |
|
flag2=.false. |
80 |
|
endif |
81 |
|
c |
82 |
do i=1,4 |
do i=1,4 |
83 |
rawadc(i,j) = 0 |
rawadc(i,j) = 0 |
84 |
rawtdc(i,j) = 0 |
rawtdc(i,j) = 0 |
94 |
bi = ibits(vecta(ic+3),bit,1) |
bi = ibits(vecta(ic+3),bit,1) |
95 |
if (bi.eq.1) rawtdc(i,j) = ibset(rawtdc(i,j),bit) |
if (bi.eq.1) rawtdc(i,j) = ibset(rawtdc(i,j),bit) |
96 |
enddo |
enddo |
|
c print *,'rawadc(',i,',',j,')','rawtdc(',i,',',j,')' |
|
|
c print *, rawadc(i,j),rawtdc(i,j) |
|
97 |
c |
c |
98 |
c adc e tdc data have to be translated from Gray code to binary (bit 0-11) |
c adc e tdc data have to be translated from Gray code to binary (bit 0-11) |
99 |
c bit 12 is added after conversion (control bit) |
c bit 12 is added after conversion (control bit) |
105 |
c |
c |
106 |
call graytobin(grayadc(i,j),adc(i,j),12) |
call graytobin(grayadc(i,j),adc(i,j),12) |
107 |
call graytobin(graytdc(i,j),tdc(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) |
|
108 |
c |
c |
109 |
bi = ibits(rawtdc(i,j),12,1) |
bi = ibits(rawtdc(i,j),12,1) |
110 |
if (bi.eq.1) tdc(i,j) = ibset(tdc(i,j),12) |
if (bi.eq.1) tdc(i,j) = ibset(tdc(i,j),12) |
111 |
bi = ibits(rawadc(i,j),12,1) |
bi = ibits(rawadc(i,j),12,1) |
112 |
if (bi.eq.1) adc(i,j) = ibset(adc(i,j),12) |
if (bi.eq.1) adc(i,j) = ibset(adc(i,j),12) |
113 |
c |
c |
|
c print *,'adc(',i,',',j,')','tdc(',i,',',j,')' |
|
|
c print *, adc(i,j),tdc(i,j) |
|
|
c |
|
114 |
ic=ic+4 |
ic=ic+4 |
115 |
enddo |
enddo |
116 |
c |
c |
119 |
do bit = 0, 7 |
do bit = 0, 7 |
120 |
bi = ibits(vecta(ic),bit,1) |
bi = ibits(vecta(ic),bit,1) |
121 |
if (bi.eq.1) temp1(j) = ibset(temp1(j),bit) |
if (bi.eq.1) temp1(j) = ibset(temp1(j),bit) |
122 |
bi = ibits(vecta(ic+1),bit,1) |
enddo |
123 |
if (bi.eq.1) temp2(j) = ibset(temp2(j),bit) |
ic=ic+1 |
124 |
enddo |
c |
125 |
c print *,'temp1(',j,')', 'temp2(',j,')' |
if (flag2.eqv..true.) then |
126 |
c print *,temp1(j), temp2(j) |
do bit = 0, 7 |
127 |
|
bi = ibits(vecta(ic),bit,1) |
128 |
ic=ic+2 |
if (bi.eq.1) temp2(j) = ibset(temp2(j),bit) |
129 |
|
enddo |
130 |
|
ic=ic+1 |
131 |
|
else |
132 |
|
temp2(j) = 99 |
133 |
|
endif |
134 |
c |
c |
135 |
c vecta(ic) is the CRC |
c vecta(ic) is the CRC |
136 |
c Check consistency of CRC. |
c Check consistency of CRC. |
137 |
c |
c |
138 |
if(vecta(ic).lt.0)vecta(ic)=vecta(ic)+256 |
ccc if(vecta(ic).lt.0)vecta(ic)=vecta(ic)+256 |
139 |
|
|
140 |
|
ibuf=0 |
141 |
|
do bit = 0, 7 |
142 |
|
bi = ibits(vecta(ic),bit,1) |
143 |
|
if (bi.eq.1) ibuf = ibset(ibuf,bit) |
144 |
|
enddo |
145 |
|
c |
146 |
check = 0 |
check = 0 |
147 |
inf = ic0 |
inf = ic0 |
148 |
sup = ic - 1 |
sup = ic - 1 |
149 |
do i = inf,sup |
do i = inf,sup |
150 |
check=crctof(check,vecta(i)) |
check=crctof(check,vecta(i)) |
151 |
enddo |
enddo |
152 |
if (check.ne.vecta(ic)) then |
c if (check.ne.vecta(ic)) then |
153 |
c print *,'crc sbagliato ',vecta(ic), check |
if (check.ne.ibuf) then |
154 |
|
c print *,'crc wrong ',ibuf, check |
155 |
me = 1 |
me = 1 |
|
else |
|
|
c print *,'crc corretto ',vecta(ic) |
|
156 |
endif |
endif |
157 |
|
|
158 |
c |
c |
164 |
|
|
165 |
RETURN |
RETURN |
166 |
END |
END |
|
|
|
|
|
|
|
|
|