/[PAMELA software]/yoda/techmodel/forroutines/tof/tofunpack.for
ViewVC logotype

Contents of /yoda/techmodel/forroutines/tof/tofunpack.for

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Sat Jan 29 00:30:16 2005 UTC (19 years, 10 months ago) by kusanagi
Branch: MAIN
*** empty log message ***

1 C--------------------------------------------------------------------
2 SUBROUTINE TOFUNPACK(vecta,lung,me)
3 C D.Campana, Dec. 04
4 C---------------------------------------------------------------------
5
6 IMPLICIT NONE
7
8 C
9 C Normal variables definition
10 C
11 integer lung
12 integer*1 vecta(lung)
13 integer me
14 integer check, crctof
15 integer ic0,sup,inf
16 integer i, ic, bit, bi,j
17 integer start,ntdc
18 integer tdcid(12),evcount(12)
19 integer tdcmask(12),adc(4,12),tdc(4,12)
20 integer rawadc(4,12),rawtdc(4,12),grayadc(4,12),graytdc(4,12)
21 integer temp1(12),temp2(12)
22 C
23 c data start,ntdc /150,12/ ! to read data before Christmas 2004
24 data start,ntdc /153,12/ ! to read data after Christmas 2004
25
26 COMMON / tofvar /tdcid,evcount,tdcmask,adc,tdc,temp1,temp2
27 save / tofvar /
28
29 C
30 C Begin !
31 C
32
33 C
34 C AAA : Bisogna definire un pattern per il tof
35 C
36
37 ic = start
38 C
39 c print *,'++++++++++ Tof Unpack ++++++++++++++++'
40
41 do j = 1,ntdc
42 ic0 = ic ! primo indice per il calcolo del CRC
43 tdcid(j) = 0
44 evcount(j) = 0
45 do bit = 0, 7
46 bi = ibits(vecta(ic),bit,1)
47 if (bi.eq.1) tdcid(j) = ibset(tdcid(j),bit)
48 bi = ibits(vecta(ic+1),bit,1)
49 if (bi.eq.1) evcount(j) = ibset(evcount(j),bit)
50 enddo
51 c print *,'tdcid(',j,')', 'evcount(',j,')'
52 c print *,tdcid(j), evcount(j)
53 c
54 ic=ic+2
55 tdcmask(j) = 0
56 do bit = 0, 7
57 bi = ibits(vecta(ic),bit,1)
58 if (bi.eq.1) tdcmask(j) = ibset(tdcmask(j),bit+8)
59 bi = ibits(vecta(ic+1),bit,1)
60 if (bi.eq.1) tdcmask(j) = ibset(tdcmask(j),bit)
61 enddo
62 c print *,'tdcmask(',j,')'
63 c print *,tdcmask(j)
64
65 ic=ic+2
66 do i=1,4
67 rawadc(i,j) = 0
68 rawtdc(i,j) = 0
69 grayadc(i,j) = 0
70 graytdc(i,j) = 0
71 do bit = 0, 7
72 bi = ibits(vecta(ic),bit,1)
73 if (bi.eq.1) rawadc(i,j) = ibset(rawadc(i,j),bit+8)
74 bi = ibits(vecta(ic+1),bit,1)
75 if (bi.eq.1) rawadc(i,j) = ibset(rawadc(i,j),bit)
76 bi = ibits(vecta(ic+2),bit,1)
77 if (bi.eq.1) rawtdc(i,j) = ibset(rawtdc(i,j),bit+8)
78 bi = ibits(vecta(ic+3),bit,1)
79 if (bi.eq.1) rawtdc(i,j) = ibset(rawtdc(i,j),bit)
80 enddo
81 c print *,'rawadc(',i,',',j,')','rawtdc(',i,',',j,')'
82 c print *, rawadc(i,j),rawtdc(i,j)
83 c
84 c adc e tdc data have to be translated from Gray code to binary (bit 0-11)
85 c bit 12 is added after conversion (control bit)
86 c bit 13 is 1(0) for charge(time) information
87 c bits 14-15 give the channel 1-4 on the board.
88 c
89 grayadc(i,j)=ibits(rawadc(i,j),0,12)
90 graytdc(i,j)=ibits(rawtdc(i,j),0,12)
91 c
92 call graytobin(grayadc(i,j),adc(i,j),12)
93 call graytobin(graytdc(i,j),tdc(i,j),12)
94 c print *,'grayadc(',i,',',j,')','graytdc(',i,',',j,')'
95 c print *, grayadc(i,j),graytdc(i,j)
96 c print *,'adc(',i,',',j,')','tdc(',i,',',j,')','prima del bit 12'
97 c print *, adc(i,j),tdc(i,j)
98 c
99 bi = ibits(rawtdc(i,j),12,1)
100 if (bi.eq.1) tdc(i,j) = ibset(tdc(i,j),12)
101 bi = ibits(rawadc(i,j),12,1)
102 if (bi.eq.1) adc(i,j) = ibset(adc(i,j),12)
103 c
104 c print *,'adc(',i,',',j,')','tdc(',i,',',j,')'
105 c print *, adc(i,j),tdc(i,j)
106 c
107 ic=ic+4
108 enddo
109 c
110 temp1(j) = 0
111 temp2(j) = 0
112 do bit = 0, 7
113 bi = ibits(vecta(ic),bit,1)
114 if (bi.eq.1) temp1(j) = ibset(temp1(j),bit)
115 bi = ibits(vecta(ic+1),bit,1)
116 if (bi.eq.1) temp2(j) = ibset(temp2(j),bit)
117 enddo
118 c print *,'temp1(',j,')', 'temp2(',j,')'
119 c print *,temp1(j), temp2(j)
120
121 ic=ic+2
122
123 c
124 c vecta(ic) is the CRC
125 c Check consistency of CRC.
126 c
127 if(vecta(ic).lt.0)vecta(ic)=vecta(ic)+256
128 check = 0
129 inf = ic0
130 sup = ic - 1
131 do i = inf,sup
132 check=crctof(check,vecta(i))
133 enddo
134 if (check.ne.vecta(ic)) then
135 c print *,'crc sbagliato ',vecta(ic), check
136 me = 1
137 else
138 c print *,'crc corretto ',vecta(ic)
139 endif
140
141 c
142 c print *,'---------> ic, j' ,ic,j
143 ic=ic+1
144
145 enddo ! j = 1,ntdc
146
147
148 RETURN
149 END
150
151
152

  ViewVC Help
Powered by ViewVC 1.1.23