~maddevelopers/mg5amcnlo/2.9.4

« back to all changes in this revision

Viewing changes to vendor/StdHEP/mcfio/example/tN2.F

pass to v2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
        program tN2
 
2
c
 
3
c       Example program for mcfio. Simple case. Read the file produced by t1
 
4
c
 
5
        implicit none
 
6
#include "mcfio.inc"
 
7
        integer ostr_all, ostr_sel, istr_old, nopen, length
 
8
        integer inum, iblki(5)
 
9
        character *255 filename
 
10
        character *80 title
 
11
        character *255 answer
 
12
        integer MAX_NUMNTUPLE
 
13
        parameter (MAX_NUMNTUPLE = 10)
 
14
        integer numblocks, numNTuples, blkids(MAX_NUMNTUPLE)
 
15
        integer i, j, numevts_real, ntu22, ntu23, nn,ll
 
16
        integer xdr_stdhep_multi
 
17
        external xdr_stdhep_multi
 
18
#include "glob22.inc"
 
19
#include "glo23.inc"
 
20
        
 
21
c
 
22
c       Initialization phase.
 
23
c
 
24
        call mcfio_Init
 
25
        call mcfio_SetForSaveDecoding(.False.)
 
26
c       call mcfio_PrintDictionary()
 
27
        
 
28
c       istr_old = mcfio_OpenReadDirect('testN1_l.dat')
 
29
        istr_old = mcfio_OpenReadMapped('testN1_l.dat')
 
30
c       filename = '/home/focus/scr1/pltmp/mcfio_mcfio/testN1_l.dat'
 
31
c       istr_old = mcfio_OpenReadDirect(filename)
 
32
        call mcfio_InfoStreamChar(
 
33
     &               istr_old, MCFIO_CREATIONDATE, answer, length)
 
34
        print *, ' Creation Date ', answer(1:length)
 
35
        
 
36
        call mcfio_InfoStreamInt(istr_old, MCFIO_NUMEVTS, inum)
 
37
        print *,' Number of events ', inum
 
38
        numevts_real = inum
 
39
c
 
40
c       Look for the Ntuple content from the file header.
 
41
c
 
42
        call mcfio_InfoStreamInt(istr_old, MCFIO_NUMNTUPLES, numNTuples)
 
43
        print *, ' Number of Ntuples for this stream ',  numNTuples
 
44
c
 
45
c       Inquire about identifier list for the stream.
 
46
c
 
47
        if (numNTuples .gt. MAX_NUMNTUPLE) then 
 
48
           print *, ' Too many NTuple on this stream, gave up'
 
49
           stop
 
50
        end if
 
51
        nn = mcfio_GetNTupleIds(istr_old, blkids, MAX_NUMNTUPLE)
 
52
        if (nn .gt. MAX_NUMNTUPLE) then 
 
53
           print *, ' Too many NTuple on this stream, gave up'
 
54
           stop
 
55
        end if
 
56
c
 
57
c       We are interested only in the structure with the uid 22
 
58
c
 
59
        ntu22 = -1
 
60
        ntu23 = -1
 
61
        do i = 1, numNTuples
 
62
            print *, ' Ntuple Sequential number ',i 
 
63
            ll =  mcfio_GetNtupleCategory(blkids(i), answer)
 
64
            print *, '        Category  ', answer(1:ll)
 
65
            ll =  mcfio_GetNtupleTitle(blkids(i), answer)
 
66
            print *, '        Title  ', answer(1:ll)
 
67
            ll =  mcfio_GetNtupleName(blkids(i), answer)
 
68
            print *, '        Template Name ', answer(1:ll)
 
69
            if (mcfio_GetNTupleUID(blkids(i)) .eq. 22) ntu22 = blkids(i)
 
70
            if (mcfio_GetNTupleUID(blkids(i)) .eq. 23) ntu23 = blkids(i)
 
71
        end do
 
72
c
 
73
        If (ntu22 .eq. -1) then 
 
74
            print *, ' Can not find Ntuple number 22 '
 
75
            stop
 
76
        end if                  
 
77
        do i = 1, numevts_real
 
78
          if (mcfio_NextEvent(istr_old) .ne. MCFIO_RUNNING) then 
 
79
             print *,'  Error reading next event '
 
80
             call mcfio_InfoStreamInt(istr_old, MCFIO_STATUS, inum)
 
81
             if (inum .eq. MCFIO_EOF ) then
 
82
                 print *, ' Reached EOF, Close and Stop '
 
83
                 call mcfio_Close(istr_old)
 
84
               stop
 
85
             else 
 
86
               print *, ' Unrecognized Status, stat = ',  inum
 
87
             end if 
 
88
             stop
 
89
          end if 
 
90
          if (mcfio_NTupleMult(istr_old, ntu22, glob_c.version)
 
91
     &           .eq. -1) then 
 
92
            print *, 'Problem decoding Multiplicty from Ntuple glob22'
 
93
            stop
 
94
          end if
 
95
          if (glob_c.nglob .gt. 5) then
 
96
           if (mcfio_NTupleSubStruct(istr_old, ntu22,
 
97
     &                             5, glob_c.version)
 
98
     &           .eq. -1) then 
 
99
              print *, 'Problem decoding SubVariable from Ntuple glob22'
 
100
              stop
 
101
             end if
 
102
                if (ifix(glob_c.glob_var(5).v7_now2).ne.(i*10 +5))
 
103
     &          print *, ' v7_now2 is wrong '
 
104
             
 
105
             
 
106
c              if (mcfio_NTuple(istr_old, ntu22, glob_c.version)
 
107
c     &           .eq. -1) then 
 
108
c            print *, 'Problem decoding Multiplicty from Ntuple glob22'
 
109
c              stop
 
110
c              end if
 
111
c             call check_glob22(i)
 
112
c              if (mcfio_NTuple(istr_old, ntu23, version_glo23)
 
113
c     &           .eq. -1) then 
 
114
c            print *, 'Problem decoding Multiplicty from Ntuple glob23'
 
115
c              stop
 
116
c              end if
 
117
          end if          
 
118
        end do
 
119
        call mcfio_close(istr_old)
 
120
        stop 
 
121
        end 
 
122
        subroutine check_glob22(ievt)
 
123
        implicit none
 
124
        integer i,ievt
 
125
#include "glob22.inc"
 
126
        
 
127
        if (ievt .eq. 1) print *, ' Version ', glob_c.version
 
128
        print *, ' --- Dump for evt ', ievt       
 
129
        print *, ' Nglob ', glob_c.nglob
 
130
        print *, ' MissingEt, Something ',
 
131
     &       glob_c.Missinget, glob_c.something
 
132
        do i = 1,glob_c.nglob
 
133
           if (ifix(glob_c.glob_var(i).v7_now2) .ne. (ievt*10 +i))
 
134
     &           print *,'v7_now is wrong'
 
135
           if (glob_c.glob_var(i).v7_now_last .ne. i*1.d0) 
 
136
     &         print *,'v7_now_last is wrong'
 
137
        end do
 
138
        print *, ' ------ ' 
 
139
        return
 
140
        end
 
141