Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pydump.f
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file pydump.f
1 
2 C*********************************************************************
3 
4 C...PYDUMP
5 C...Dumps histogram contents on file for reading by other program.
6 C...Can also read back own dump.
7 
8  SUBROUTINE pydump(MDUMP,LFN,NHI,IHI)
9 
10 C...Double precision declaration.
11  IMPLICIT DOUBLE PRECISION(a-h, o-z)
12  IMPLICIT INTEGER(i-n)
13 C...Commonblock.
14  common/pybins/ihist(4),indx(1000),bin(20000)
15  SAVE /pybins/
16 C...Local arrays and character variables.
17  dimension ihi(*),iss(100),val(5)
18  CHARACTER title*60,format*13
19 
20 C...Dump all histograms that have been booked,
21 C...including titles and ranges, one after the other.
22  IF(mdump.EQ.1) THEN
23 
24 C...Loop over histograms and find which are wanted and booked.
25  IF(nhi.LE.0) THEN
26  nw=ihist(1)
27  ELSE
28  nw=nhi
29  ENDIF
30  DO 130 iw=1,nw
31  IF(nhi.EQ.0) THEN
32  id=iw
33  ELSE
34  id=ihi(iw)
35  ENDIF
36  is=indx(id)
37  IF(is.NE.0) THEN
38 
39 C...Write title, histogram size, filling statistics.
40  nx=nint(bin(is+1))
41  DO 100 it=1,20
42  ieq=nint(bin(is+8+nx+it))
43  title(3*it-2:3*it)=char(ieq/256**2)//
44  & char(mod(ieq,256**2)/256)//char(mod(ieq,256))
45  100 CONTINUE
46  WRITE(lfn,5100) id,title
47  WRITE(lfn,5200) nx,bin(is+2),bin(is+3)
48  WRITE(lfn,5300) nint(bin(is+5)),bin(is+6),bin(is+7),
49  & bin(is+8)
50 
51 
52 C...Write histogram contents, in groups of five.
53  DO 120 ixg=1,(nx+4)/5
54  DO 110 ixv=1,5
55  ix=5*ixg+ixv-5
56  IF(ix.LE.nx) THEN
57  val(ixv)=bin(is+8+ix)
58  ELSE
59  val(ixv)=0d0
60  ENDIF
61  110 CONTINUE
62  WRITE(lfn,5400) (val(ixv),ixv=1,5)
63  120 CONTINUE
64 
65 C...Go to next histogram; finish.
66  ELSEIF(nhi.GT.0) THEN
67  CALL pyerrm(8,'(PYDUMP:) unknown histogram number')
68  ENDIF
69  130 CONTINUE
70 
71 C...Read back in histograms dumped MDUMP=1.
72  ELSEIF(mdump.EQ.2) THEN
73 
74 C...Read histogram number, title and range, and book.
75  140 READ(lfn,5100,end=170) id,title
76  READ(lfn,5200) nx,xl,xu
77  CALL pybook(id,title,nx,xl,xu)
78  is=indx(id)
79 
80 C...Read filling statistics.
81  READ(lfn,5300) nentry,bin(is+6),bin(is+7),bin(is+8)
82  bin(is+5)=dble(nentry)
83 
84 C...Read histogram contents, in groups of five.
85  DO 160 ixg=1,(nx+4)/5
86  READ(lfn,5400) (val(ixv),ixv=1,5)
87  DO 150 ixv=1,5
88  ix=5*ixg+ixv-5
89  IF(ix.LE.nx) bin(is+8+ix)=val(ixv)
90  150 CONTINUE
91  160 CONTINUE
92 
93 C...Go to next histogram; finish.
94  goto 140
95  170 CONTINUE
96 
97 C...Write histogram contents in column format,
98 C...convenient e.g. for GNUPLOT input.
99  ELSEIF(mdump.EQ.3) THEN
100 
101 C...Find addresses to wanted histograms.
102  nss=0
103  IF(nhi.LE.0) THEN
104  nw=ihist(1)
105  ELSE
106  nw=nhi
107  ENDIF
108  DO 180 iw=1,nw
109  IF(nhi.EQ.0) THEN
110  id=iw
111  ELSE
112  id=ihi(iw)
113  ENDIF
114  is=indx(id)
115  IF(is.NE.0.AND.nss.LT.100) THEN
116  nss=nss+1
117  iss(nss)=is
118  ELSEIF(nss.GE.100) THEN
119  CALL pyerrm(8,'(PYDUMP:) too many histograms requested')
120  ELSEIF(nhi.GT.0) THEN
121  CALL pyerrm(8,'(PYDUMP:) unknown histogram number')
122  ENDIF
123  180 CONTINUE
124 
125 C...Check that they have common number of x bins. Fix format.
126  nx=nint(bin(iss(1)+1))
127  DO 190 iw=2,nss
128  IF(nint(bin(iss(iw)+1)).NE.nx) THEN
129  CALL pyerrm(8,'(PYDUMP:) different number of bins')
130  RETURN
131  ENDIF
132  190 CONTINUE
133  format='(1P,000E12.4)'
134  WRITE(FORMAT(5:7),'(I3)') nss+1
135 
136 C...Write histogram contents; first column x values.
137  DO 200 ix=1,nx
138  x=bin(iss(1)+2)+(ix-0.5d0)*bin(iss(1)+4)
139  WRITE(lfn,format) x, (bin(iss(iw)+8+ix),iw=1,nss)
140  200 CONTINUE
141 
142  ENDIF
143 
144 C...Formats for output.
145  5100 FORMAT(i5,5x,a60)
146  5200 FORMAT(i5,1p,2d12.4)
147  5300 FORMAT(i12,1p,3d12.4)
148  5400 FORMAT(1p,5d12.4)
149 
150  RETURN
151  END