/[PAMELA software]/yoda/techmodel/forroutines/calorimeter/calunpack.for
ViewVC logotype

Annotation of /yoda/techmodel/forroutines/calorimeter/calunpack.for

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6.1 - (hide annotations) (download)
Fri Jun 30 13:09:19 2006 UTC (18 years, 5 months ago) by kusanagi
Branch: MAIN
CVS Tags: YODA6_3/10, YODA6_3/06, YODA6_3/05, YODA6_3/07, YODA6_3/08, YODA6_3/09
Changes since 6.0: +24 -16 lines
Upgrade received from Emiliano 30 June 2006

1 kusanagi 1.8 C
2 kusanagi 2.2 C Written by Emiliano Mocchiutti and Mirko Boezio
3 kusanagi 1.8 C
4 kusanagi 6.1 C * Version: 3.4.08 *
5 kusanagi 1.9 C
6 kusanagi 2.2 C Changelog:
7     C
8 kusanagi 6.1 C 3.4.07 - 3.4.08: (2006-06-29) XO is rotated, not XE!! fixed.
9     C
10     C 3.4.06 - 3.4.07: (2006-06-29) save CRC values in calselftrig(section,1) and calselftrig(section,2) in case of CRC errors
11     C
12 kusanagi 2.10 C 3.4.05 - 3.4.06: (2005-01-12) section order wrong in CLEARSEC, fixed.
13     C
14 kusanagi 2.9 C 3.4.04 - 3.4.05: (2005-01-05) XE is section y odd not even, fixed.
15     C
16 kusanagi 2.8 C 3.4.03 - 3.4.04: (2004-12-21) bug in recognising decoding errors, fixed.
17     C
18 kusanagi 2.7 C 3.4.02 - 3.4.03: (2004-12-17) forget to clear esci/stwerr and vector vect
19     C plus problems with lleng (truncated vect!). Fixed the
20     C clearing, workaround for lleng (to be further investigated)
21     C
22 kusanagi 2.6 C 3.4.01 - 3.4.02: (2004-12-10) cleanup of the code and changed sections order.
23     C
24 kusanagi 2.5 C 3.4.00 - 3.4.01: (2004-11-26) CA50 comes after Strips Hit, fixed.
25     C
26     C 3.3.03 - 3.4.00: (2004-11-08) changed the DSP program hence changed calunpack
27     C to better find the calorimeter sections.
28     C
29     C 3.3.02 - 3.3.03: (2004-11-08) changes in the commons (one more common for
30     C calpulse and from calstripshit to calstriphit).
31     C
32     C 3.3.01 - 3.3.02: (2004-10-19) italian name of subroutines translated to
33     C english. Forgot to clear vector in case of CRC errors,
34     C fixed. stwerr is integer not real! fixed
35     C
36 kusanagi 2.4 C 3.3.00 - 3.3.01: (2004-10-18) forgot to clear stwerr if no sections are found
37     C fixed.
38     C
39 kusanagi 2.2 C 3.2.00 - 3.3.00: (2004-10-15) enanched search of sections in case of one or
40     C more missing sections.
41     C Switched to c function "fillin" to create calorimeter words
42     C instead of fortran function "riempi": great improvement in
43     C time processing!!
44     C
45     C 3.1.00 - 3.2.00: (2004-10-13) forget to clean some variables, fixed.
46     C Reprocess event in the case we have CRC errors and a high
47     C number of error trying to understand the kind of event
48     C we are processing (raw, compress, full mode) in order to
49 kusanagi 2.4 C distinguish better the four section.The reprocessing happens
50 kusanagi 2.2 C on about the 30% of events with CRC errors (in the case of
51     C file 040827_005 the reprocessing is done on about 2% of all
52     C the events).
53     C
54     C 3.0.00 - 3.1.00: (2004-10-12) cleanup and speedup of the code, less loops
55     C same strength in finding the calorimeter sections.
56     C
57     C 2.18.4 - 3.0.00: (2004-10-07) major changes in the procedure to find the
58     C calorimeter sections and enhanced search in the case of
59     c CRC errors (to fix a bug which made the misunderstanding
60     C some kind of CRC errors with missing sections).
61     C Clean up unused variables, speeded up some loops.
62     C Zero length input vector error added.
63     C Enhanced search of the first section recorded since the
64     C starting point is very important to correctly find and
65     C interpret all the other sections.
66     C If section length is absurd and the CRC header bit = 0
67     C then search again for that section (needed to make a
68     C better search of section when in presence of CRC errors)
69     C Search all the sections and if you reach the end of vector
70     C (EOV) continue searching if you haven't find all the four
71     C section (and go out without looping if no section is
72     C present).
73 kusanagi 2.1 C
74     C 2.18.3 - 2.18.4: consider a bad thing if you find a section in the wrong
75     C position of the vector and try again to
76     C find the real data (if they exist).
77     C
78     C 2.18.2 - 2.18.3: vectors belonging to common must be cleared if the calo
79     C isn't found. Fixed.
80 kusanagi 1.8 C
81 kusanagi 2.1 C 2.18.1 - 2.18.2: fixed unclearing error codes if the program doesn't find
82     C the calorimeter where it should be but shifted somewhere
83 kusanagi 2.2 C else forgotten to clear st2c variable: fixed
84 kusanagi 2.1 C exit error code wrong in some cases: fixed
85 kusanagi 2.2 C self trigger data not saved: fixed.
86 kusanagi 2.1 C
87     C 2.18.0 - 2.18.1: small changes in the common varie to fix a memory leak;
88 kusanagi 2.2 C fixed an error in reporting error codes (stwerr,pwerror).
89 kusanagi 2.1 C
90 kusanagi 2.2 C 2.17.0 - 2.18.0: corrected bug which made unable the program to find CRC
91     C errors in the last section of the calorimeter;
92     C added a "debugging" option to dump to standard output
93     C the whole packet in hexadecimal format and other
94     C useful informations. To activate it the dump variable
95     C in the common varie must be passed with the value
96     C of iev you want to check. Do nothing if you don't want
97     C any output.
98 kusanagi 1.9 C
99 kusanagi 1.3 C------------------------------------------------
100 kusanagi 1.7 SUBROUTINE CALUNPACK(vecta,lung,me)
101 kusanagi 1.3 C------------------------------------------------
102    
103     IMPLICIT NONE
104     C
105 kusanagi 2.2 C PARAMETERS DEFINITION
106     C
107     C START = WHERE TO START TO LOOK FOR THE CALORIMETER, IN WORDS
108     C 1STSEC = MAXIMUM POSITION, IN BYTES, WHERE WE SUPPOSE TO FIND THE
109     C HEADER OF THE FIRST SECTION
110 kusanagi 1.3 C
111 kusanagi 2.2 INTEGER START, SEC1ST
112 kusanagi 1.3 INTEGER NPLA, NCHA, LENSEV
113 kusanagi 2.2 INTEGER*2 ival
114     C
115     PARAMETER (START=50,SEC1ST=1200)
116 kusanagi 1.3 PARAMETER (NPLA=22,NCHA=96,LENSEV=NPLA*NCHA)
117 kusanagi 2.2 PARAMETER (ival='FFFF'x)
118 kusanagi 1.3 C
119 kusanagi 2.2 C Normal variables definition
120 kusanagi 1.3 C
121 kusanagi 2.2 integer lung, SOGLIA0, SEC2ND
122 kusanagi 1.7 INTEGER*1 VECTA(lung)
123 kusanagi 1.9 INTEGER*2 vect(60000), test
124 kusanagi 1.6 integer*2 check, crc, e2(4)
125 kusanagi 2.2 INTEGER*2 length, length2
126     integer me, m, dumpo, finoa
127     INTEGER merror(4), headcor, ichc, coco
128 kusanagi 2.6 INTEGER i, j, iev, min, st2c, bit, bi, lleng
129 kusanagi 2.2 INTEGER ic, k,l, ke, ic0, icsave, chi
130     INTEGER hcchi(1000), hcic(1000),hcco
131     INTEGER contr, isfull, israw, iscomp
132     INTEGER inf, sup, em, icb
133 kusanagi 2.6 INTEGER XO, YO, XE, YE, icold
134 kusanagi 2.2 integer st1b, st2b, lunga, pari
135     integer stwerr(4),yescbra, chis, esci, icprima
136     integer seemcomp, seemfull, cberaw, yesisco, yesisfu,yesisra
137 kusanagi 2.5 integer ca50, ca50a, ca50b
138 kusanagi 2.2 C
139 kusanagi 1.3 real dedx1(11,96),dedx2(11,96),dedx3(11,96),dedx4(11,96)
140     real dedx1c(11,96),dedx2c(11,96),dedx3c(11,96),dedx4c(11,96)
141     real base1(11,6),base2(11,6),base3(11,6),base4(11,6)
142 kusanagi 2.2 REAL DEXY(2,NPLA,NCHA), dexyc(2,npla,ncha), base(2,npla,6)
143 kusanagi 1.3 real auto(7)
144 kusanagi 2.5 real calselftrig(4,7), calIItrig(4), calstriphit(4),
145 kusanagi 1.3 & calDSPtaberr(4), calevnum(4)
146 kusanagi 2.2 real perror(4)
147     C
148 kusanagi 2.5 DATA YE/246/ ! CODE_EV_R YE = 111 10110
149 kusanagi 1.3 DATA YO/237/ ! CODE_EV_R YO = 111 01101
150     DATA XE/234/ ! CODE_EV_R XE = 111 01010
151 kusanagi 2.5 DATA XO/241/ ! CODE_EV_R XO = 111 10001
152 kusanagi 2.2 C
153 kusanagi 2.6 COMMON / evento / iev, stwerr, perror,
154 kusanagi 1.3 & dexy,dexyc,base,
155     & calselftrig,calIItrig,
156 kusanagi 2.5 & calstriphit,calDSPtaberr,calevnum
157 kusanagi 1.3 save / evento /
158 kusanagi 2.2 C
159 kusanagi 2.8 COMMON / VARIE / dumpo, CONTR, merror
160 kusanagi 2.2 SAVE / VARIE /
161 kusanagi 1.3 C
162     C Begin !
163     C
164 kusanagi 2.2 SOGLIA0 = 70
165     C
166     C input length must be > 0, if not go out with error code 142
167     C
168 kusanagi 2.5 if (lung.le.0) then
169 kusanagi 2.2 if (dumpo.eq.iev) print *,'lung = ',lung
170     do i=1,4
171     merror(i)=142
172     enddo
173     goto 999
174     endif
175     C
176     C no debug informations
177     C
178 kusanagi 2.1 if (dumpo.eq.0) dumpo=-1
179 kusanagi 2.2 C
180     C DEBUG: PRINT OUT THE INPUT VECTOR
181     C
182 kusanagi 2.1 if (iev.eq.dumpo) then
183 kusanagi 1.9 do l=1,lung
184     write(*,17)l,vecta(l)
185     enddo
186     endif
187 kusanagi 2.2 C
188     C DETERMINE LENGTH IN WORDS FROM LENGTH IN BYTES
189     C
190 kusanagi 1.7 IF (MOD(LUNG,2).EQ.0) THEN
191     lunga = lung / 2
192     pari = 1
193     else
194     lunga = int(lung/2) + 1
195     endif
196 kusanagi 2.2 SEC2ND = LUNGA
197     C
198     C IS LENGTH IS TOO LONG?
199     C
200 kusanagi 2.1 if (lunga.gt.60000.and.dumpo.gt.0) then
201 kusanagi 1.9 print *,'Calorimeter WARNING: more than 60000 words!'
202     lunga = 60000
203 kusanagi 1.6 endif
204 kusanagi 2.2 C
205     C PRE-CLEAR VARIABLES
206     C
207     yesisco = 0
208     yesisfu = 0
209     yesisra = 0
210     yescbra = 0
211     C
212     1 CONTINUE
213 kusanagi 1.5 c
214 kusanagi 2.2 C CLEAR VARIABLES
215     C
216     if (iev.lt.0.or.iev.gt.90000000) iev = 0
217     esci = 0
218     chi = 0
219     chis = 0
220     min = 0
221     lleng = 0
222     m = 0
223     pari = 0
224     icb = 0
225     em = 0
226     coco = 0
227     me = 1
228     contr = 1
229     ic = 1
230     icsave = 0
231     C
232 kusanagi 2.5 call clearall
233 kusanagi 1.6 call azero(dedx1,11*96)
234     call azero(dedx2,11*96)
235     call azero(dedx3,11*96)
236     call azero(dedx4,11*96)
237     call azero(dedx1c,11*96)
238     call azero(dedx2c,11*96)
239     call azero(dedx3c,11*96)
240     call azero(dedx4c,11*96)
241     call azero(base1,11*6)
242     call azero(base2,11*6)
243     call azero(base3,11*6)
244     call azero(base4,11*6)
245     C
246 kusanagi 1.5 do l = 1,4
247 kusanagi 2.1 e2(l) = 0
248 kusanagi 1.8 perror(l) = 0.
249     stwerr(l) = 0
250 kusanagi 1.5 merror(l) = 0
251     enddo
252 kusanagi 2.2 C
253     C DETERMINE WHERE TO START TO FIND THE CALORIMETER IN THE INBUT BUFFER
254     C
255     length2 = start
256 kusanagi 1.3 c
257     20 continue
258 kusanagi 2.2 C
259 kusanagi 1.5 if (length2.ge.-2) then
260     ic = ic + (2 * (length2 + 2))
261     else
262 kusanagi 2.1 if (dumpo.gt.0)
263 kusanagi 2.2 & print *,'Calorimeter WARNING: length errors ',ic,length2
264 kusanagi 1.5 endif
265 kusanagi 2.2 C
266     headcor = 0
267     ichc = ic
268     icprima = ic
269     hcco = 0
270     do i=1,1000
271     hcchi(i) = 0
272     hcic(i) = 0
273     enddo
274 kusanagi 1.5 c
275     32 continue
276 kusanagi 2.2 C
277 kusanagi 1.3 ke = 0
278 kusanagi 2.2 chis = chi
279 kusanagi 2.1 icold = ic
280 kusanagi 2.7 DO i = 1, 60000
281     vect(i) = 0
282     enddo
283 kusanagi 1.3 do while (ke.eq.0)
284     C
285 kusanagi 2.2 C if (iev.eq.dumpo) print *,'parto da ',ic,contr
286     C
287 kusanagi 1.3 C Check consistency of header.
288     C it is composed by CODE+D# (8 bits) and by SATUS WORD (8 bits)
289     c so we must split vect into the two components:
290     C
291 kusanagi 1.5 st1b = 0
292     st2b = 0
293 kusanagi 2.2 C
294     C A CALORIMETER SECTION IS MADE OF AT LEAST 4 BYTES
295     C IF WE HAVE NO ROOM FOR A SECTION GO OUT
296     C
297     if ((ic+4).gt.lung.or.esci.eq.1) then
298     if (headcor.eq.1.and.contr.lt.5) then
299     headcor=-1
300     ic=ichc
301     goto 32
302     else
303     if (headcor.eq.0.or.headcor.eq.2) then
304     chi = chi + 8 * (5 - contr)
305     endif
306     merror(contr) = 129
307 kusanagi 2.7 stwerr(contr) = 0
308 kusanagi 2.6 if (iev.eq.dumpo) print *,'put to zero here ',headcor
309 kusanagi 2.2 if (esci.eq.0) then
310     ic = icsave
311     else
312     ic = icprima
313     endif
314     if (headcor.eq.2) then
315     chi = chis
316     endif
317     esci = 0
318     headcor = 0
319     hcco = 0
320     ichc = 0
321     do i=1,1000
322     hcchi(i) = 0
323     hcic(i) = 0
324     enddo
325     length2 = -2
326     lleng = 0
327     length = 0
328     goto 150
329     endif
330 kusanagi 1.7 endif
331 kusanagi 2.2 C
332     C ST1B IS "CODE", ST2B IS "D#"
333     C
334 kusanagi 1.5 do bit = 0, 7
335     bi = ibits(vecta(ic),bit,1)
336     if (bi.eq.1) st1b = ibset(st1b,bit)
337     bi = ibits(vecta(ic+1),bit,1)
338     if (bi.eq.1) st2b = ibset(st2b,bit)
339     enddo
340 kusanagi 1.6 c
341 kusanagi 2.2 C IC+2 AND IC+3 CONTAINS THE LENGTH OF THE CALORIMETER SECTION
342 kusanagi 1.6 c
343 kusanagi 1.5 length2 = 0
344     do bit=0, 7
345     bi = ibits(vecta(ic+3),bit,1)
346     if (bi.eq.1) length2 = ibset(length2,bit)
347     bi = ibits(vecta(ic+2),bit,1)
348     if (bi.eq.1) length2 = ibset(length2,bit+8)
349 kusanagi 2.5 enddo
350     C
351     C calorimeter signature in DSP mode (CA50 CA50):
352     C
353     ca50 = 0
354     if (ic+24.lt.lung) then
355     ca50a = 0
356     do bit=0, 7
357     bi = ibits(vecta(ic+23),bit,1)
358     if (bi.eq.1) ca50a = ibset(ca50a,bit)
359     bi = ibits(vecta(ic+22),bit,1)
360     if (bi.eq.1) ca50a = ibset(ca50a,bit+8)
361     enddo
362     ca50b = 0
363     do bit=0, 7
364     bi = ibits(vecta(ic+25),bit,1)
365     if (bi.eq.1) ca50b = ibset(ca50b,bit)
366     bi = ibits(vecta(ic+24),bit,1)
367     if (bi.eq.1) ca50b = ibset(ca50b,bit+8)
368     enddo
369     if (ca50a.eq.ca50b.and.ca50a.eq.51792) ca50 = 1
370     endif
371    
372 kusanagi 2.2 C
373 kusanagi 1.3 c the crc should be at vect(length) with
374 kusanagi 2.2 C
375 kusanagi 1.5 length = length2 + 1
376 kusanagi 1.3 C
377 kusanagi 2.2 c some checks to be sure we have found the calorimeter data:
378 kusanagi 1.3 c status word is always less then 129
379     c
380 kusanagi 1.5 if (st2b.gt.128) then
381     length = 0
382 kusanagi 2.2 length2 = 0
383 kusanagi 1.5 goto 100
384     endif
385 kusanagi 1.3 c
386 kusanagi 2.2 c length of the packet IN WORDS must be less then HALF OF THE
387     C LENGTH IN BYTES if noT THERE ARE SOME errors
388 kusanagi 1.3 c
389 kusanagi 2.2 bi = ibits(st2b,0,1)
390     if (length2.gt.lunga.OR.LENGTH2.LE.0) then
391     if (headcor.eq.2) then
392     chi = chi + 4
393     endif
394 kusanagi 1.5 length = 0
395 kusanagi 2.2 length2 = 0
396 kusanagi 1.5 goto 100
397     endif
398     c
399 kusanagi 1.3 e2(contr) = 0
400     C
401 kusanagi 2.2 if (CONTR.eq.1) then
402 kusanagi 1.3 c
403     c is it the first section?
404     c
405 kusanagi 2.5 if (st1b.eq.XE.and.(ca50.eq.1.or.length2.eq.1064)) then
406 kusanagi 1.3 c if so go out of this loop and go on recording data
407     ke = 1
408 kusanagi 2.2 icsave = ic
409     m = ic
410 kusanagi 2.7 if (iev.eq.dumpo) then
411     print *,'1m,lunga,lleng,lung,pari',m,lunga,lleng,lung,
412     & pari
413     endif
414 kusanagi 2.2 call fillin(m,lunga,lleng,lung,pari,vect,vecta)
415     C
416 kusanagi 1.5 icb = 1
417 kusanagi 2.2 E2(contr) = vect(icb)
418 kusanagi 2.7 if (iev.eq.dumpo) then
419     print *,'headcor ',headcor
420     write(*,22)vect(icb)
421     print *,'1m,lunga,lleng,lung,pari',m,lunga,lleng,lung,
422     & pari
423     endif
424 kusanagi 2.2 if (headcor.eq.2) then
425     if (coco.ne.1) then
426     coco = 1
427     else
428     coco = -1
429     endif
430     if (st2b.ne.0) then
431 kusanagi 2.5 call counter(e2(contr),chi)
432 kusanagi 2.2 endif
433 kusanagi 1.3 endif
434 kusanagi 2.2 goto 100
435 kusanagi 1.3 endif
436     ENDIF
437     C
438     c the same for the second section, ...
439     c
440     if (CONTR.eq.2) then
441 kusanagi 2.5 if (st1b.eq.XO.and.(ca50.eq.1.or.length2.eq.1064)) then
442 kusanagi 2.2 ke = 2
443     icsave = ic
444 kusanagi 1.5 m = ic
445 kusanagi 2.7 if (iev.eq.dumpo) then
446     print *,'2m,lunga,lleng,lung,pari',m,lunga,lleng,lung,
447     & pari
448     endif
449 kusanagi 2.2 call fillin(m,lunga,lleng,lung,pari,vect,vecta)
450 kusanagi 1.5 icb = 1
451 kusanagi 2.2 E2(contr) = vect(icb)
452 kusanagi 2.7 if (iev.eq.dumpo) then
453     print *,'headcor ',headcor
454     write(*,22)vect(icb)
455     print *,'2m,lunga,lleng,lung,pari',m,lunga,lleng,lung,
456     & pari
457     endif
458 kusanagi 2.2 if (headcor.eq.2) then
459     if (coco.ne.2) then
460     coco = 2
461     else
462     coco = -1
463     endif
464     if ((ic-icold).ne.0) chi=chi+abs(ic-icold)
465     if (st2b.ne.0) then
466 kusanagi 2.5 call counter(e2(contr),chi)
467 kusanagi 1.3 endif
468     endif
469 kusanagi 2.2 goto 100
470 kusanagi 1.3 endif
471     ENDIF
472     c
473     C ... for the third,...
474     c
475     if (CONTR.eq.3) then
476 kusanagi 2.5 if (st1b.eq.YE.and.(ca50.eq.1.or.length2.eq.1064)) then
477 kusanagi 2.2 ke = 3
478     icsave = ic
479     m = ic
480     if (iev.eq.dumpo) then
481 kusanagi 2.7 print *,'3m,lunga,lleng,lung,pari',m,lunga,lleng,lung,
482 kusanagi 2.2 & pari
483 kusanagi 1.3 endif
484 kusanagi 2.2 call fillin(m,lunga,lleng,lung,pari,vect,vecta)
485 kusanagi 1.5 icb = 1
486 kusanagi 2.2 E2(contr) = vect(icb)
487     if (iev.eq.dumpo) then
488     print *,'headcor ',headcor
489     write(*,22)vect(icb)
490 kusanagi 2.7 print *,'3m,lunga,lleng,lung,pari',m,lunga,lleng,lung,
491 kusanagi 2.2 & pari
492 kusanagi 1.3 endif
493 kusanagi 2.2 if (headcor.eq.2) then
494     if (coco.eq.3) then
495     coco = 3
496     else
497     coco = -1
498     endif
499     if (ic-icold.ne.0) chi = chi + abs(ic-icold)
500     if (st2b.ne.0) then
501 kusanagi 2.5 call counter(e2(contr),chi)
502 kusanagi 1.3 endif
503     endif
504 kusanagi 2.2 goto 100
505 kusanagi 1.3 endif
506     ENDIF
507     C
508     c ...and for the last section.
509     c
510     if (CONTR.eq.4) then
511 kusanagi 2.5 if (st1b.eq.YO.and.(ca50.eq.1.or.length2.eq.1064)) then
512 kusanagi 2.2 ke = 4
513     icsave = ic
514 kusanagi 1.5 m = ic
515 kusanagi 2.2 call fillin(m,lunga,lleng,lung,pari,vect,vecta)
516 kusanagi 1.5 icb = 1
517 kusanagi 2.2 E2(contr) = vect(icb)
518     if (headcor.eq.2) then
519     if (coco.eq.4) then
520     coco = 4
521     else
522     coco = -1
523     endif
524     if ((ic-icold).ne.0) chi = chi + abs(ic-icold)
525     if (st2b.ne.0) then
526 kusanagi 2.5 call counter(e2(contr),chi)
527 kusanagi 2.2 endif
528 kusanagi 1.3 endif
529 kusanagi 1.5 goto 100
530 kusanagi 1.3 endif
531     endif
532 kusanagi 2.2 C
533     if (contr.gt.4) then
534 kusanagi 2.6 if (iev.eq.dumpo) print *,'go out here'
535 kusanagi 2.2 headcor = 0
536     hcco = 0
537     ichc = 0
538     do i=1,1000
539     hcchi(i) = 0
540     hcic(i) = 0
541     enddo
542     goto 200
543     endif
544 kusanagi 1.3 C
545     100 CONTINUE
546     c
547     c increment vector of one searching for the next section
548     c
549     ic = ic + 1
550     c
551     enddo
552     C
553     c format not used
554     c
555 kusanagi 1.7 10 FORMAT(2X,'Error for view:',2X,I1,2X,'Status word:',2X,Z4)
556     11 FORMAT(2X,'View or command not recognized for view:',2X,I1,2X,
557     & 'Status word:',2X,Z4)
558     12 FORMAT(2X,'Error - did NOT find view:',2X,I1)
559     13 FORMAT(2X,'Error - eof reached, exiting')
560     14 FORMAT(2X,I8,2X,I10)
561     15 FORMAT(2X,I8,2X,Z8)
562 kusanagi 2.5 17 FORMAT(2X,'Element:',2X,I6,2X,' word:',2X,Z8)
563     18 FORMAT(2X,'Element:',2X,I6,2X,' word:',2X,Z2,Z2)
564 kusanagi 1.9 21 FORMAT(2X,'CRC: ',2X,Z8)
565 kusanagi 2.2 22 FORMAT(2X,'vect(icb): ',2X,Z8)
566 kusanagi 1.9 C
567 kusanagi 1.3 c go on recording data
568 kusanagi 1.7 ic = ic - 1
569 kusanagi 2.2 c
570 kusanagi 1.7 c
571     K = CONTR
572     ic0 = icb
573     icb = icb + 1
574     length = vect(icb) + 2
575     length2 = vect(icb)
576 kusanagi 1.8 lleng = (length*2) - 1
577 kusanagi 1.3 C
578 kusanagi 2.2 C Check consistency of CRCs.
579     C
580     C
581     C IF THE STATUS WORD HAS THE CRC BIT ON AND WE ARE NOT IN THE
582     C HEADCOR CASE 0 (WE WERE BELIEVING THE SECTION FOUND WAS FINE)
583     C
584     if ((ibits(e2(contr),0,1).ne.0.or.
585     & (ibits(e2(contr),3,1).eq.1.and.length2.ne.1064))
586     & .and.headcor.EQ.0) then
587     headcor = 1
588     ichc = ic - 1
589     if (iev.eq.dumpo) print *,'crc st word wrong',ic,ichc,headcor
590     endif
591     C
592     C HEADOCR = 1 MEANS SEARCH AGAIN FOR THAT SECTION
593 kusanagi 1.3 C
594 kusanagi 2.2 if (headcor.eq.1) then
595     hcco = hcco + 1
596     if (st2b.ne.0) then
597 kusanagi 2.5 call counter(e2(contr),hcchi(hcco))
598 kusanagi 2.2 endif
599     C
600     if (contr.gt.1.or.yesisco.ne.0.or.yesisfu.ne.0
601     & .or.yesisra.ne.0.or.yescbra.ne.0) then
602     iscomp = 0
603     isfull = 0
604     israw = 0
605     if (yesisco.ne.0.or.yesisfu.ne.0
606     & .or.yesisra.ne.0.or.yescbra.ne.0) then
607     if (yesisra.ne.0.or.yescbra.ne.0) israw = 2
608     if (yesisco.ne.0) iscomp = 2
609     if (yesisfu.ne.0) isfull = 2
610     else
611     i = 1
612     do while(iscomp.eq.0.and.isfull.eq.0.and.israw.eq.0.and.
613     & i.lt.(contr-1))
614     if (ibits(stwerr(i),16,1).eq.1) iscomp = iscomp + 1
615     if (ibits(stwerr(i),17,1).eq.1) isfull = isfull + 1
616     if (ibits(e2(i),3,1).eq.1.and.merror(i).eq.0)
617     & israw = israw + 1
618     i = i + 1
619     enddo
620     endif
621     c
622     c how does this section look like? (note that in case of crc errors
623     c this test has no value...)
624     c
625 kusanagi 2.5 test = vect(icb+12)
626 kusanagi 2.2 seemcomp = 0
627     seemfull = 0
628     if (test.eq.ival) then
629     seemcomp = 1
630     elseif (test.eq.0) then
631     seemfull = 1
632     endif
633     c
634     c if a previous good section was raw and this header we are analyzing
635     c is not raw something strange is happening, add a weight.
636     c
637     if ((israw.ne.0.and.ibits(e2(contr),3,1).ne.1)
638     & .or.(israw.ne.0.and.length2.ne.1064)) then
639     hcco = hcco - 1
640     length=0
641     length2=0
642     lleng=0
643     ic = ic + 1
644     if (iev.eq.dumpo)
645     & print *,'not raw, search again ',ic,ichc,headcor
646     goto 32
647     endif
648     c
649     c the same with compress and full mode
650     c
651     if ((iscomp.ne.0.or.isfull.ne.0)
652     & .and.ibits(e2(contr),3,1).eq.1) then
653     hcco = hcco - 1
654     length=0
655     length2=0
656     lleng=0
657     ic = ic + 1
658     if (iev.eq.dumpo)
659     & print *,'raw in full or compress mode, search again ',ic,ichc,
660     & headcor
661     goto 32
662     endif
663    
664     if (iscomp.ne.0.and.(ibits(e2(contr),3,1).eq.1.or.
665     & seemcomp.eq.0)) hcchi(hcco) = hcchi(hcco) + 2
666     if (isfull.ne.0.and.(ibits(e2(contr),3,1).eq.1.or.
667     & seemfull.eq.0)) hcchi(hcco) = hcchi(hcco) + 2
668     endif
669     C
670     if (ibits(e2(contr),3,1).eq.1.and.length2.eq.1064) then
671     hcchi(hcco) = hcchi(hcco) - 2
672     elseif ((ibits(e2(contr),3,1).eq.1.or.israw.ne.0)
673     & .and.length2.ne.1064) then
674     hcco = hcco - 1
675     length=0
676     length2=0
677     lleng=0
678     ic = ic + 1
679     if (iev.eq.dumpo)
680     & print *,'raw bit not raw length, search again ',ic,ichc,headcor
681     goto 32
682     endif
683     C
684     hcic(hcco) = ic
685     ic = ic + 1
686     length=0
687     length2=0
688     lleng=0
689     if (iev.eq.dumpo) print *,'search again ',ic,ichc,headcor
690     goto 32
691     endif
692     C
693     C HEADCOR = - 1 MEANS STOP SEARCHING FOR THAT SECTION, SELECT
694     C THE CASE WITH LESS ERRORS, FOUND THAT SECTION AND GIVE
695     C HEADCOR = 2 (I.E. GO OUT OF THE LOOP)
696     C
697     if (headcor.eq.-1) then
698 kusanagi 2.6 if (iev.eq.dumpo) print *,'enter -1, ',hcco,ke
699 kusanagi 2.2 headcor = 2
700     if (ke.le.2.and.hcco.ge.1) then
701     finoa = 0
702     do i = 1, hcco
703     if (ke.eq.1.and.hcic(i).lt.SEC1ST) finoa = i
704     if (ke.eq.2.and.hcic(i).lt.SEC2ND) finoa = i
705     enddo
706     if (finoa.eq.0) then
707     esci = 1
708     if (iev.eq.dumpo)
709     & print *,'finoa=0! no possible solutions '
710     else
711     if (iev.eq.dumpo) print *,'ke = ',ke,' and hcco>1 ',finoa
712     call minerr(ic,hcic,hcchi,min,finoa)
713     endif
714     else
715     if (hcco.eq.0) then
716     esci = 1
717     if (iev.eq.dumpo)
718     & print *,'hcco=0! no possible solutions'
719     else
720     call minerr(ic,hcic,hcchi,min,hcco)
721     endif
722     endif
723     e2(contr) = 0
724     if (iev.eq.dumpo) then
725     print *,'stop searching'
726     print *,'ic,hcic(min),min,... ',ic,hcic(min),min,
727     & hcchi(min),hcco,coco
728     do i=1,hcco
729     print *,'i, hcchi ',i,hcchi(i)
730     enddo
731     endif
732     c
733     length=0
734     length2=0
735     lleng=0
736 kusanagi 2.7 esci = 0
737     MERROR(contr) = 0
738 kusanagi 2.2 goto 32
739     endif
740     C
741     C determine the type of data if not raw (compress or full)
742     C
743     if (headcor.eq.0.or.headcor.eq.2
744     & .and.ibits(e2(contr),3,1).ne.1) then
745 kusanagi 2.5 test = vect(icb+12)
746 kusanagi 2.2 seemcomp = 0
747     seemfull = 0
748     if (test.eq.ival) then
749 kusanagi 2.5 C
750 kusanagi 2.2 C compress mode
751 kusanagi 2.5 C
752 kusanagi 2.2 stwerr(contr) = ibset(stwerr(contr),16)
753     elseif (test.eq.0) then
754     C
755 kusanagi 2.5 C full mode
756     C
757 kusanagi 2.2 stwerr(contr) = ibset(stwerr(contr),17)
758     endif
759     endif
760     C
761     hcco = 0
762     ichc = 0
763 kusanagi 2.1 check = 0
764 kusanagi 2.2 do i=1,1000
765     hcchi(i) = 0
766     hcic(i) = 0
767     enddo
768 kusanagi 1.7 inf = ic0
769     sup = length - 1
770     do i = inf,sup
771     check=crc(check,vect(i))
772     enddo
773 kusanagi 2.2 C
774 kusanagi 2.7 if (iev.eq.dumpo) then
775     write(*,21)vect(length)
776     print *,' CRC position ',length
777     write(*,21)check
778     endif
779 kusanagi 2.2 C
780 kusanagi 1.7 if (check.ne.vect(length)) then
781 kusanagi 6.1 C
782     C clear vectors of that section in the common
783     C
784     call clearsec
785     C
786     calselftrig(k,1) = check
787     calselftrig(k,2) = vect(length)
788     c
789 kusanagi 1.7 merror(contr) = 132
790 kusanagi 2.2 chi = chi + 4
791 kusanagi 1.7 lleng = 0
792 kusanagi 2.2 length2 = 0
793     length = 0
794 kusanagi 6.1 c
795 kusanagi 2.2 if (ke.eq.1.and.headcor.ne.2) then
796     ic = 10
797     elseif (headcor.eq.2) then
798     contr = contr + 1
799 kusanagi 1.8 endif
800 kusanagi 2.2 headcor = 1
801     ichc = ic - 1
802     if (iev.eq.dumpo)
803 kusanagi 2.6 & print *,'crc is wrong ',ic,
804     & ' search section ',contr,' coco = ',coco
805 kusanagi 2.2 goto 32
806     else
807     chi = chi - 4
808     if (chi.lt.0) chi = 0
809 kusanagi 1.7 endif
810 kusanagi 2.2 C
811     headcor = 0
812 kusanagi 1.3 C
813 kusanagi 1.8 19 CONTINUE
814 kusanagi 2.2 C
815     C Process data.
816     C
817 kusanagi 2.5 call clearsec
818 kusanagi 2.2 do i = 1, 7
819     icb = icb + 1
820     auto(i) = vect(icb)
821     enddo
822     C
823     st2c = 0
824     if (st2b.ne.0) then
825     do bit=0, 6
826     bi = ibits(st2b,bit,1)
827     if (bit.eq.3.and.bi.ne.0) st2c = 8
828 kusanagi 1.3 enddo
829 kusanagi 2.2 endif
830 kusanagi 1.7 C
831 kusanagi 2.2 if (st2c.eq.8) then
832     if (length2.ne.1064) then
833     merror(contr) = 133
834     chi = chi + 4
835     if (iev.eq.dumpo)
836     & print *,'raw lung 4'
837     lleng = 0
838     goto 150
839     else
840 kusanagi 2.5 if (k.eq.1) call CALRAW(vect,icb+1,length-1,dedx1)
841 kusanagi 2.2 if (k.eq.2) call CALRAW(vect,icb+1,length-1,dedx2)
842     if (k.eq.3) call CALRAW(vect,icb+1,length-1,dedx3)
843     if (k.eq.4) call CALRAW(vect,icb+1,length-1,dedx4)
844 kusanagi 1.5 endif
845 kusanagi 2.2 goto 50
846     endif
847 kusanagi 1.7 C
848 kusanagi 2.2 41 FORMAT(2X,I2,2X,'word :',1x,z4)
849 kusanagi 2.5 test = vect(icb+5)
850 kusanagi 2.2 c
851     if (test.eq.ival) then
852     if (length2.gt.1201) then
853     merror(contr) = 134
854     chi = chi + 4
855     if (iev.eq.dumpo)
856     & print *,'compr lung 4'
857     lleng = 0
858     goto 150
859     else
860     icb = icb + 1
861     calIItrig(k) = vect(icb)
862     icb = icb + 1
863 kusanagi 2.5 calstriphit(k) = vect(icb)
864     icb = icb + 1
865     C FIRST CALORIMETER SIGNATURE: CA50
866 kusanagi 2.2 icb = icb + 1
867 kusanagi 2.5 C SECOND CALORIMETER SIGNATURE: CA50
868     icb = icb + 1
869     C test is here!
870 kusanagi 2.2 icb = icb + 1
871     calDSPtaberr(k) = vect(icb)
872     icb = icb + 1
873     calevnum(k) = vect(icb)
874 kusanagi 2.5 if (k.eq.1) call CALCOMPRESS(vect,icb+1,length-1,dedx1c,
875     & base1)
876 kusanagi 2.2 if (k.eq.2) call CALCOMPRESS(vect,icb+1,length-1,dedx2c,
877     & base2)
878     if (k.eq.3) call CALCOMPRESS(vect,icb+1,length-1,dedx3c,
879     & base3)
880     if (k.eq.4) call CALCOMPRESS(vect,icb+1,length-1,dedx4c,
881     & base4)
882 kusanagi 1.5 goto 50
883 kusanagi 1.3 endif
884 kusanagi 2.2 else if (test.eq.0) then
885     if (length2.gt.2257) then
886     merror(contr) = 135
887     chi = chi + 4
888     if (iev.eq.dumpo)
889     & print *,'full lung 4'
890     lleng = 0
891     goto 150
892     else
893     icb = icb + 1
894     calIItrig(k) = vect(icb)
895     icb = icb + 1
896 kusanagi 2.5 calstriphit(k) = vect(icb)
897     icb = icb + 1
898     C FIRST CALORIMETER SIGNATURE: CA50
899 kusanagi 2.2 icb = icb + 1
900 kusanagi 2.5 C SECOND CALORIMETER SIGNATURE: CA50
901     icb = icb + 1
902     C test is here!
903 kusanagi 2.2 icb = icb + 1
904     calDSPtaberr(k) = vect(icb)
905     icb = icb + 1
906     calevnum(k) = vect(icb)
907 kusanagi 2.5 if (k.eq.1) call CALFULL(vect,icb+1,length-1,dedx1,
908     & dedx1c,base1)
909 kusanagi 2.2 if (k.eq.2) call CALFULL(vect,icb+1,length-1,dedx2,
910     & dedx2c,base2)
911     if (k.eq.3) call CALFULL(vect,icb+1,length-1,dedx3,
912     & dedx3c,base3)
913     if (k.eq.4) call CALFULL(vect,icb+1,length-1,dedx4,
914     & dedx4c,base4)
915     goto 50
916 kusanagi 1.3 endif
917 kusanagi 2.2 else
918     merror(contr) = 136
919     chi = chi + 4
920     if (iev.eq.dumpo)
921     & print *,'decoding problems 4'
922     lleng = 0
923     goto 150
924     endif
925 kusanagi 2.1 c
926 kusanagi 2.2 50 continue
927 kusanagi 2.1 c
928 kusanagi 1.7 C
929 kusanagi 2.2 do i = 1,7
930     calselftrig(k,i) = auto(i)
931     enddo
932     C
933     DO I = 1,11
934     DO J = 1,96
935 kusanagi 6.1 DEXY(2,2*I,97-J) = DEDX2(I,J)
936 kusanagi 2.5 DEXY(1,2*I-1,J) = DEDX4(I,J)
937 kusanagi 6.1 DEXY(2,2*I-1,J) = DEDX1(I,J)
938 kusanagi 2.5 DEXY(1,2*I,J) = DEDX3(I,J)
939 kusanagi 6.1 DEXYC(2,2*I,97-J) = DEDX2C(I,J)
940 kusanagi 2.5 DEXYC(1,2*I-1,J) = DEDX4C(I,J)
941 kusanagi 6.1 DEXYC(2,2*I-1,J) = DEDX1C(I,J)
942 kusanagi 2.5 DEXYC(1,2*I,J) = DEDX3C(I,J)
943 kusanagi 1.3 enddo
944 kusanagi 2.2 do j = 1,6
945 kusanagi 6.1 base(2,2*i,7-j) = base2(i,j)
946 kusanagi 2.5 base(1,2*i-1,j) = base4(i,j)
947 kusanagi 6.1 base(2,2*i-1,j) = base1(i,j)
948 kusanagi 2.5 base(1,2*i,j) = base3(i,j)
949 kusanagi 1.3 enddo
950 kusanagi 2.2 enddo
951 kusanagi 1.3 C
952     150 continue
953     C
954     contr = contr + 1
955     C
956     c go on till we have found all the four sections
957     c
958 kusanagi 1.5 if (contr.lt.5) goto 20
959 kusanagi 1.3 c
960 kusanagi 1.8 200 continue
961     C
962 kusanagi 2.2 iscomp = 0
963     isfull = 0
964     israw = 0
965     do i = 1, 4
966     if (ibits(stwerr(i),16,1).eq.1) iscomp = iscomp + 1
967     if (ibits(stwerr(i),17,1).eq.1) isfull = isfull + 1
968     if (ibits(e2(i),3,1).eq.1) israw = israw + 1
969     enddo
970     if (iscomp.ne.0) chi = chi + 8 * (4 - iscomp)
971     if (israw.ne.0) chi = chi + 8 * (4 - israw)
972     if (isfull.ne.0) chi = chi + 8 * (4 - isfull)
973     C
974     C if chi>10 and we have information enough to understand the physic event
975     C was acquired in a certain mode (RAW, FULL or COMPRESS) then reprocess
976     C the event using this information, sometimes we miss a section due to
977     C CRC errors in the previous one but if we know what we are looking for
978     C then it is possible to save this kind of events.
979     C
980     if (chi.gt.5.and.yesisco.eq.0.and.yesisfu.eq.0
981     & .and.yesisra.eq.0.and.yescbra.eq.0) then
982     israw = 0
983     cberaw = 0
984     do i = 1, 4
985     if (ibits(e2(i),3,1).eq.1.and.merror(i).eq.0)
986     & israw = israw + 1
987     if (ibits(e2(i),3,1).eq.1.and.merror(i).eq.132)
988     & cberaw = cberaw + 1
989     enddo
990     yesisco = 0
991     yesisfu = 0
992     yesisra = 0
993     yescbra = 0
994     if (iscomp.ne.0) yesisco = 1
995     if (isfull.ne.0) yesisfu = 1
996     if (israw.ne.0) yesisra = 1
997     if (cberaw.ne.0) yescbra = 1
998     if ((yesisco+yesisfu+yesisra).eq.1.or.
999     & ((yesisco+yesisfu+yesisra).eq.0.and.yescbra.eq.1)) then
1000     if (iev.eq.dumpo) then
1001     print *,'************************'
1002     if (iscomp.ne.0) print *,'is a compress acq.'
1003     if (isfull.ne.0) print *,'is a full acq.'
1004     if (israw.ne.0) print *,'is a raw acq.'
1005     if (israw.eq.0.and.cberaw.ne.0)
1006     & print *,'could be a raw acq.'
1007     print *,'so, SGARBUF, do it again! ',chi
1008     print *,'************************'
1009 kusanagi 1.8 endif
1010 kusanagi 2.2 SOGLIA0 = SOGLIA0 - ISCOMP - ISFULL - ISRAW
1011     goto 1
1012 kusanagi 1.8 endif
1013 kusanagi 2.2 if ((yesisco+yesisfu+yesisra+yescbra).eq.0) chi = 1000
1014 kusanagi 1.8 endif
1015 kusanagi 2.2 C
1016     if (iev.eq.dumpo)
1017     & print *,'chi <= soglia0 ?',chi,soglia0
1018     if (chi.lt.soglia0) then
1019     me = 0
1020     else
1021     me = 1
1022     do i = 1, 4
1023     merror(i) = 129
1024     e2(i) = 0
1025 kusanagi 2.5 stwerr(i) = 0
1026 kusanagi 2.1 enddo
1027 kusanagi 2.5 call clearall
1028 kusanagi 2.2 goto 999
1029 kusanagi 1.8 endif
1030 kusanagi 1.3 C
1031     C if all section are missing clear vectors and go out
1032     C
1033     if (merror(1).eq.129.and.merror(2).eq.129
1034 kusanagi 2.2 & .and.merror(3).eq.129.and.merror(4).eq.129) then
1035 kusanagi 1.3 do l = 1,4
1036     e2(l) = 0
1037 kusanagi 2.4 stwerr(l) = 0
1038 kusanagi 1.3 enddo
1039 kusanagi 2.5 call clearall
1040 kusanagi 1.3 endif
1041     c
1042     999 continue
1043 kusanagi 2.1 c
1044 kusanagi 1.8 do l = 1, 4
1045     do bit=0, 31
1046     if (bit.lt.16) then
1047     bi = ibits(E2(L),bit,1)
1048 kusanagi 2.2 elseif (bit.gt.17) then
1049 kusanagi 1.8 bi = 0
1050 kusanagi 2.2 elseif (bit.ge.16.and.bit.le.17) then
1051     bi = 2
1052 kusanagi 1.8 endif
1053 kusanagi 2.1 if (bi.eq.1) then
1054     stwerr(l) = ibset(stwerr(l),bit)
1055 kusanagi 2.2 elseif (bi.eq.0) then
1056 kusanagi 2.1 stwerr(l) = ibclr(stwerr(l),bit)
1057     endif
1058 kusanagi 1.8 enddo
1059     perror(l) = float(merror(l))
1060 kusanagi 1.7 enddo
1061 kusanagi 2.1 c
1062 kusanagi 2.10 if ( iev.eq.dumpo ) then
1063     if (perror(3).eq.132.and.perror(4).eq.129) then
1064     do i = 1, 2
1065     do j = 1, 22
1066     do l = 1, 96
1067     print *,'Evento ',i,j,l,dexy(i,j,l)
1068     enddo
1069     enddo
1070     enddo
1071     do l=1,lung
1072     write(*,17)l,vecta(l)
1073     enddo
1074     endif
1075     endif
1076     iev = iev + 1
1077 kusanagi 1.3 RETURN
1078     END
1079    
1080    
1081     C------------------------------------------------
1082     SUBROUTINE CALRAW(vect,inf,sup,dedx)
1083     C------------------------------------------------
1084    
1085     IMPLICIT NONE
1086 kusanagi 2.2 C
1087     INTEGER NPLA, NCHA, LENSEV
1088     PARAMETER (NPLA=22,NCHA=96,LENSEV=NPLA*NCHA)
1089     C
1090 kusanagi 1.7 INTEGER*2 VECT(30000)
1091 kusanagi 1.3 INTEGER inf, sup
1092 kusanagi 2.6 INTEGER i,j,k, iev
1093 kusanagi 2.2 INTEGER contr
1094 kusanagi 2.8 integer stwerr(4), dumpo, merror(4)
1095 kusanagi 1.3 C
1096 kusanagi 2.2 REAL DEXY(2,NPLA,NCHA), dexyc(2,npla,ncha), base(2,npla,6)
1097 kusanagi 2.5 real calselftrig(4,7), calIItrig(4), calstriphit(4),
1098 kusanagi 1.3 & calDSPtaberr(4), calevnum(4)
1099     REAL dedx(11,96)
1100 kusanagi 2.6 real perror(4)
1101 kusanagi 2.2 C
1102 kusanagi 2.6 COMMON / evento / iev, stwerr, perror,
1103 kusanagi 1.3 & dexy,dexyc,base,
1104     & calselftrig,calIItrig,
1105 kusanagi 2.5 & calstriphit,calDSPtaberr,calevnum
1106 kusanagi 1.3
1107     save / evento /
1108     c
1109 kusanagi 2.8 COMMON / VARIE / dumpo, CONTR, merror
1110 kusanagi 1.3 SAVE / VARIE /
1111 kusanagi 2.2 c
1112 kusanagi 1.3 k = inf
1113     do j = 1,96
1114     do i = 1,11
1115 kusanagi 2.2 DEDX(I,J) = 0.
1116 kusanagi 1.3 dedx(i,j) = vect(k)
1117     k = k + 1
1118     enddo
1119     enddo
1120     c
1121     RETURN
1122     END
1123    
1124     C------------------------------------------------
1125     SUBROUTINE CALCOMPRESS(vect,inf,sup,dedx,basse)
1126     C------------------------------------------------
1127    
1128     IMPLICIT NONE
1129    
1130 kusanagi 2.2 INTEGER NPLA, NCHA, LENSEV
1131     PARAMETER (NPLA=22,NCHA=96,LENSEV=NPLA*NCHA)
1132 kusanagi 1.3 C
1133 kusanagi 2.2 INTEGER*2 VECT(30000)
1134 kusanagi 2.10 INTEGER*2 st, st1
1135 kusanagi 1.3 INTEGER inf, sup
1136 kusanagi 2.6 INTEGER i,j, iev
1137 kusanagi 1.3 INTEGER ib
1138     INTEGER ipl, ipr, ist
1139     INTEGER merror(4)
1140     INTEGER contr
1141 kusanagi 2.2 integer stwerr(4),dumpo
1142 kusanagi 2.8 integer bit,bi
1143 kusanagi 2.2 C
1144     REAL DEXY(2,NPLA,NCHA), dexyc(2,npla,ncha), base(2,npla,6)
1145 kusanagi 2.5 real calselftrig(4,7), calIItrig(4), calstriphit(4),
1146 kusanagi 1.3 & calDSPtaberr(4), calevnum(4)
1147     REAL dedx(11,96), basse(11,6)
1148 kusanagi 2.6 real perror(4)
1149 kusanagi 1.3 C
1150 kusanagi 1.8 COMMON / evento / IEV, stwerr,perror,
1151 kusanagi 1.3 & dexy,dexyc,base,
1152     & calselftrig,calIItrig,
1153 kusanagi 2.5 & calstriphit,calDSPtaberr,calevnum
1154 kusanagi 1.3
1155     save / evento /
1156     c
1157 kusanagi 2.8 COMMON / VARIE / dumpo, CONTR, merror
1158 kusanagi 1.3 SAVE / VARIE /
1159    
1160     C
1161     DO I = 1,11
1162     DO J = 1,96
1163 kusanagi 2.2 if (j.le.6) basse(i,j) = 0.
1164 kusanagi 1.3 DEDX(I,J) = 0.
1165     ENDDO
1166     ENDDO
1167     C
1168 kusanagi 1.5 i = inf
1169     c
1170 kusanagi 1.3 10 continue
1171 kusanagi 1.6 if (i.gt.sup) then
1172     RETURN
1173     endif
1174 kusanagi 1.3 C
1175     40 format(2x,i5,2x,'status :',1x,Z4)
1176 kusanagi 1.5 C
1177     c
1178     st1 = 0
1179 kusanagi 2.8 do bit=0, 7
1180     bi = ibits(vect(i),bit+8,1)
1181     if (bi.eq.1) st1 = ibset(st1,bit)
1182     enddo
1183     43 format(2x,'vect(i) = ',Z8)
1184     if (st1.eq.8) then
1185 kusanagi 1.3 ib = 1
1186     else
1187 kusanagi 2.8 if (st1.eq.16) then
1188 kusanagi 1.3 ib = 0
1189     else
1190 kusanagi 2.1 if (iev.eq.dumpo) then
1191 kusanagi 1.9 print *,'i ',i
1192     write(*,43)vect(i)
1193     endif
1194 kusanagi 1.5 merror(contr) = 139
1195 kusanagi 1.3 RETURN
1196     endif
1197     endif
1198     C
1199     if (ib.eq.1) then
1200 kusanagi 1.6 C
1201 kusanagi 1.3 st = IAND(vect(i),'00FF'x)
1202 kusanagi 1.5 c
1203 kusanagi 1.3 ipl = int(st/6) + 1
1204 kusanagi 1.5 ipr = st - (ipl - 1) * 6 + 1
1205 kusanagi 1.3 i = i + 1
1206 kusanagi 1.6 if (i.gt.sup) RETURN
1207 kusanagi 1.3 basse(ipl,ipr) = vect(i)
1208 kusanagi 1.6 c
1209 kusanagi 1.3 20 continue
1210     if (i.gt.sup) RETURN
1211     C
1212     i = i + 1
1213 kusanagi 1.6 if (i.gt.sup) RETURN
1214     if ((vect(i)+1).gt.16.or.(vect(i)+1).lt.1) then
1215 kusanagi 2.8
1216 kusanagi 1.6 goto 10
1217     endif
1218     ist = vect(i) + 1 + 16 * (ipr - 1)
1219 kusanagi 1.3 i = i + 1
1220 kusanagi 1.6 if (i.gt.sup) RETURN
1221 kusanagi 1.5 dedx(ipl,ist) = vect(i)
1222 kusanagi 1.6 goto 20
1223 kusanagi 1.3 else
1224     C
1225     st = IAND(vect(i),'00FF'x)
1226 kusanagi 1.6 ipl = int(st/6) + 1
1227 kusanagi 1.5 ipr = st - (ipl - 1) * 6 + 1
1228 kusanagi 1.3 do j = 1,16
1229     i = i + 1
1230 kusanagi 1.6 if (i.gt.sup) RETURN
1231     ist = j + 16 * (ipr - 1)
1232     dedx(ipl,ist) = vect(i)
1233 kusanagi 1.3 enddo
1234 kusanagi 1.6 i = i + 1
1235     if (i.gt.sup) RETURN
1236 kusanagi 1.3 goto 10
1237     C
1238     endif
1239    
1240    
1241     RETURN
1242     END
1243    
1244    
1245 kusanagi 1.5 C----------------------------------------------------------
1246 kusanagi 1.3 SUBROUTINE CALFULL(vect,inf,sup,dedx,dedxc,basse)
1247 kusanagi 1.5 C--------------------------------------------------------------
1248 kusanagi 1.3
1249     IMPLICIT NONE
1250    
1251 kusanagi 2.2 INTEGER NPLA, NCHA, LENSEV
1252     PARAMETER (NPLA=22,NCHA=96,LENSEV=NPLA*NCHA)
1253     C
1254 kusanagi 1.7 INTEGER*2 VECT(30000)
1255 kusanagi 1.3 INTEGER inf, sup
1256 kusanagi 2.6 INTEGER i,j,k, iev
1257 kusanagi 2.2 INTEGER contr
1258 kusanagi 2.8 integer stwerr(4),dumpo,merror(4)
1259 kusanagi 1.3 C
1260 kusanagi 2.2 REAL DEXY(2,NPLA,NCHA), dexyc(2,npla,ncha), base(2,npla,6)
1261 kusanagi 2.5 real calselftrig(4,7), calIItrig(4), calstriphit(4),
1262 kusanagi 1.3 & calDSPtaberr(4), calevnum(4)
1263     REAL dedx(11,96), basse(11,6), dedxc(11,96)
1264 kusanagi 2.6 real perror(4)
1265 kusanagi 2.2 C
1266 kusanagi 2.6 COMMON / evento / iev, stwerr,perror,
1267 kusanagi 1.3 & dexy,dexyc,base,
1268     & calselftrig,calIItrig,
1269 kusanagi 2.5 & calstriphit,calDSPtaberr,calevnum
1270 kusanagi 1.3
1271     save / evento /
1272     c
1273 kusanagi 2.8 COMMON / VARIE / dumpo, CONTR, merror
1274 kusanagi 1.3 SAVE / VARIE /
1275     C
1276 kusanagi 1.6 k = inf
1277 kusanagi 1.3 do i = 1,11
1278     do j = 1,96
1279 kusanagi 2.2 DEDX(I,J) = 0.
1280 kusanagi 1.3 dedx(i,j) = vect(k)
1281     k = k + 1
1282     enddo
1283     enddo
1284     C
1285     call CALCOMPRESS(vect,k,sup,dedxc,basse)
1286 kusanagi 1.6 C
1287     10 FORMAT(2X,'Status word:',2X,Z8)
1288 kusanagi 1.3
1289     RETURN
1290     END
1291    
1292    
1293     C------------------------------------------------
1294 kusanagi 2.5 SUBROUTINE COUNTER(ve,er)
1295 kusanagi 1.3 C------------------------------------------------
1296    
1297     IMPLICIT NONE
1298    
1299     INTEGER NPLA, NCHA, LENSEV
1300     PARAMETER (NPLA=22,NCHA=96,LENSEV=NPLA*NCHA)
1301 kusanagi 2.2 C
1302     INTEGER*2 VE, st4
1303 kusanagi 2.6 INTEGER er, bit, bi, iev
1304 kusanagi 1.3 INTEGER contr
1305 kusanagi 2.8 integer stwerr(4),dumpo, merror(4)
1306 kusanagi 2.2 C
1307     REAL DEXY(2,NPLA,NCHA), dexyc(2,npla,ncha), base(2,npla,6)
1308 kusanagi 2.5 real calselftrig(4,7), calIItrig(4), calstriphit(4),
1309 kusanagi 2.2 & calDSPtaberr(4), calevnum(4)
1310 kusanagi 2.6 real perror(4)
1311 kusanagi 2.2 C
1312 kusanagi 1.8 COMMON / evento / IEV, stwerr,perror,
1313 kusanagi 1.3 & dexy,dexyc,base,
1314     & calselftrig,calIItrig,
1315 kusanagi 2.5 & calstriphit,calDSPtaberr,calevnum
1316 kusanagi 1.3
1317     save / evento /
1318    
1319 kusanagi 2.8 COMMON / VARIE / dumpo, CONTR, merror
1320 kusanagi 1.3 SAVE / VARIE /
1321    
1322    
1323     st4 = 0
1324     st4 = IAND(ve,'00FF'x)
1325     if (st4.ne.0) then
1326     do bit=0, 6
1327     bi = ibits(st4,bit,1)
1328     if (bi.ne.0) then
1329 kusanagi 2.2 er = er + 2
1330 kusanagi 1.3 endif
1331     enddo
1332     endif
1333    
1334     10 FORMAT(2X,'Status word:',2X,Z4)
1335     return
1336     end
1337    
1338    
1339     C------------------------------------------------
1340     SUBROUTINE MINERR(ic,icsave,chi,min,co)
1341     C------------------------------------------------
1342    
1343     IMPLICIT NONE
1344     C
1345 kusanagi 2.2 INTEGER NPLA, NCHA, LENSEV
1346     PARAMETER (NPLA=22,NCHA=96,LENSEV=NPLA*NCHA)
1347     C
1348 kusanagi 1.3 INTEGER ic, icsave(1000), chi(1000)
1349     integer l, st, min,co
1350 kusanagi 2.6 INTEGER iev
1351 kusanagi 2.2 INTEGER contr
1352 kusanagi 2.8 integer stwerr(4),dumpo, merror(4)
1353 kusanagi 1.3 C
1354 kusanagi 2.2 REAL DEXY(2,NPLA,NCHA), dexyc(2,npla,ncha), base(2,npla,6)
1355 kusanagi 2.5 real calselftrig(4,7), calIItrig(4), calstriphit(4),
1356 kusanagi 2.2 & calDSPtaberr(4), calevnum(4)
1357 kusanagi 2.6 real perror(4)
1358 kusanagi 2.2 C
1359 kusanagi 2.6 COMMON / evento / iev, stwerr,perror,
1360 kusanagi 1.3 & dexy,dexyc,base,
1361     & calselftrig,calIItrig,
1362 kusanagi 2.5 & calstriphit,calDSPtaberr,calevnum
1363 kusanagi 1.3
1364     save / evento /
1365 kusanagi 2.6 C
1366 kusanagi 2.8 COMMON / VARIE / dumpo, CONTR, merror
1367 kusanagi 1.3 SAVE / VARIE /
1368    
1369     st = chi(1)
1370     min = 1
1371     if (co.gt.1) then
1372     do l = 2, co
1373     if (chi(l).lt.st) then
1374     st = chi(l)
1375     min = l
1376     endif
1377     enddo
1378     endif
1379     ic = icsave(min)
1380    
1381     return
1382     end
1383 kusanagi 1.7
1384     C-----------------------------------------------------
1385 kusanagi 2.5 SUBROUTINE CLEARSEC
1386 kusanagi 1.7 C-----------------------------------------------------
1387    
1388     IMPLICIT NONE
1389     C
1390     INTEGER NPLA, NCHA, LENSEV
1391     PARAMETER (NPLA=22,NCHA=96,LENSEV=NPLA*NCHA)
1392 kusanagi 2.2 C
1393 kusanagi 2.6 INTEGER iev
1394 kusanagi 2.5 INTEGER contr, i,j
1395 kusanagi 2.8 integer stwerr(4),dumpo, merror(4)
1396 kusanagi 2.2 C
1397     REAL DEXY(2,NPLA,NCHA), dexyc(2,npla,ncha), base(2,npla,6)
1398 kusanagi 2.5 real calselftrig(4,7), calIItrig(4), calstriphit(4),
1399 kusanagi 1.7 & calDSPtaberr(4), calevnum(4)
1400 kusanagi 2.6 real perror(4)
1401 kusanagi 2.2 C
1402 kusanagi 2.6 COMMON / evento / iev, stwerr,perror,
1403 kusanagi 1.7 & dexy,dexyc,base,
1404     & calselftrig,calIItrig,
1405 kusanagi 2.5 & calstriphit,calDSPtaberr,calevnum
1406 kusanagi 1.7
1407     save / evento /
1408     c
1409 kusanagi 2.8 COMMON / VARIE / dumpo, CONTR, merror
1410 kusanagi 2.5 SAVE / VARIE /
1411 kusanagi 1.7 C
1412 kusanagi 2.5 DO I = 1,11
1413     DO J = 1,96
1414 kusanagi 2.10 if (contr.eq.3) then
1415 kusanagi 2.5 DEXY(1,2*I,J) = 0.
1416     DEXYC(1,2*I,J) = 0.
1417     endif
1418 kusanagi 2.10 if (contr.eq.4) then
1419 kusanagi 2.5 DEXY(1,2*I-1,J) = 0.
1420     DEXYC(1,2*I-1,J) = 0.
1421     endif
1422 kusanagi 2.10 if (contr.eq.1) then
1423 kusanagi 6.1 DEXY(2,2*I-1,J) = 0.
1424     DEXYC(2,2*I-1,J) = 0.
1425 kusanagi 2.5 endif
1426 kusanagi 2.10 if (contr.eq.2) then
1427 kusanagi 6.1 DEXY(2,2*I,97-J) = 0.
1428     DEXYC(2,2*I,97-J) = 0.
1429 kusanagi 2.5 endif
1430     enddo
1431     do j = 1,6
1432 kusanagi 2.10 if (contr.eq.1) base(2,2*i-1,7-j) = 0.
1433     if (contr.eq.4) base(1,2*i-1,j) = 0.
1434     if (contr.eq.2) base(2,2*i,j) = 0.
1435     if (contr.eq.3) base(1,2*i,j) = 0.
1436 kusanagi 2.5 enddo
1437     if (i.le.7) calselftrig(contr,i) = 0.
1438     enddo
1439     calIItrig(contr) = 0.
1440     calstriphit(contr) = 0.
1441     calDSPtaberr(contr) = 0.
1442     calevnum(contr) = 0.
1443     return
1444 kusanagi 1.7 end
1445 kusanagi 2.5 C

  ViewVC Help
Powered by ViewVC 1.1.23