COSMOS v7.655  COSMOSv7655
(AirShowerMC)
bin2bin.f
Go to the documentation of this file.
1  program main
2  use modhistogram1
3  use modhistogram2
4  use modhistogram3
5  implicit none
6 ! binary hist file: binary output file made by programs
7 ! in UserHook/Hist
8 ! This program is intended to read binary hist file
9 ! and hybrid data file to modify the hybrid data information
10 ! in the binary hist file, and then re-make the binary
11 ! hist file.
12 ! Usage: compile: make -f bin2bin.mk
13 ! execution:
14 ! set environmental variable HISTFILE0 to be
15 ! a binary hist file.
16 ! you MUST give another env. var.
17 ! HYBFILE0 to be a hybrid data output file
18 ! made by a program in UserHook/DisPara/FleshHist.
19 ! bin2bin$ARCH
20 ! temp.hist will be created.
21 !
22 
23  type(histogram1) h10
24  type(histogram2) h20
25  type(histogram3) h30
26 
27 
28  integer kgetenv2
29  integer leng, i, fn0, fout
30  integer icon0, iconhyb
31  character*120 hist0, histout
32  character*6 histid0, oldhist
33  real normf
34  data normf/-1.0/
35 
36  fn0 = 2
37 ! fn1 = 3 may be defined later for hybrid data
38  fout = 4
39  call kwhistso( 2 ) ! binary write
40  leng = kgetenv2("HISTFILE0", hist0)
41  call copenfw2(fn0, hist0, 2, icon0)
42  if(icon0 .ne. 1) then
43  write(0,*) "File specified by HISTFILE0 "
44  if( icon0 .eq. 0) then
45  write(0,*) 'not exists'
46  else
47  write(0,*) ' cannot be opened '
48  endif
49  write(0,*) ' icon=',icon0
50  stop 9999
51  else
52  write(0,*) hist0(1:leng), ' opened'
53  endif
54  leng = kgetenv2("HISTFILE1", histout)
55  if(leng .le. 0) then
56  write(0,*)
57  * "Output file name is not given by the HISTFILE1"
58  write(0,*) "Set Env. Var. HISTFILE1"
59  stop 1234
60  endif
61  call copenfw2(fout, histout(1:leng), 2, icon0)
62  if(icon0 .ne. 0) then
63  write(0,*) "For binary output "//histout(1:leng)
64  write(0,*) "is specified but old one seems to exist"
65  write(0,*) "delete or mv that file beforehand"
66  stop 9999
67  else
68  write(0,*)
69  * histout(1:leng)//' will be created for binary hist"'
70  endif
71 
72 !c? call openhyb(iconhyb)
73  leng = kgetenv2("OLDHIST", oldhist)
74  if( leng .gt. 0 .and. oldhist .eq. "yes") then
75  write(0,*) 'Old hist format assumed'
76  call kwhistfmt(.true.)
77  else
78  call kwhistfmt(.false.)
79  endif
80 
81  do while(.true.)
82  read( fn0, end=1000 ) histid0
83  100 continue
84  if( histid0 .eq. '#hist1' ) then
85  call kwhistr(h10, fn0, icon0)
86 
87  if(iconhyb .eq. 1) then
88 ! call mergehyb1(h10)
89  endif
90  call kwhists(h10, normf)
91  call kwhistp(h10, fout)
92  call kwhistd(h10)
93  elseif(histid0 .eq. '#hist2' ) then
94  call kwhistr2(h20, fn0, icon0)
95  if(iconhyb .eq. 1) then
96  call mergehyb2(h20)
97  endif
98  call kwhists2(h20, normf)
99  call kwhistp2(h20, fout)
100  call kwhistd2(h20)
101  elseif(histid0 .eq. '#hist3' ) then
102  call kwhistr3(h30, fn0, icon0)
103  if(iconhyb .eq. 1) then
104  call mergehyb3(h30)
105  endif
106  call kwhists3(h30, normf)
107  call kwhistp3(h30, fout)
108  call kwhistd3(h30)
109  else
110  write(0,*) 'histid=', histid0, ' invalid'
111  stop 9000
112  endif
113  enddo
114  1000 continue
115  write(0,*) 'all events processed '
116  end
117 ! **********************
118  subroutine get1hyb( rew )
119  implicit none
120  logical rew
121  character*128 input0
122  integer i, klena
123 
124  integer ndepth
125  parameter(ndepth= 50)
126  integer fn1
127  real*8 ASdep(ndepth), munit(ndepth)
128  real*8 Esize0(ndepth),
129  * age0(ndepth), cogdep0(ndepth),
130  * seloss0(ndepth),
131  * ng0(ndepth), ne0(ndepth), nmu0(ndepth),
132  * cog0
133  integer EvNo0
134 
135  common /zbin2ascii/
136  * asdep, esize0, age0,
137  * cogdep0, seloss0, munit,
138  * ng0, ne0, nmu0, cog0,
139  * fn1, evno0
140 
141  if(rew) rewind fn1
142 
143  input0 = "x"
144 !////////////
145 ! write(0,*) ' while'
146 !////////
147  do while (input0(1:10) .ne. " ")
148  input0=" "
149  read( fn1 ,'(a)') input0
150 !////////////
151 ! write(0,*) ' input0=',input0
152 !//////////////
153  if(input0(1:10) .ne. " ") then
154  read(input0(1:klena(input0)), *)
155  * evno0, i, asdep(i), esize0(i), age0(i),
156  * cogdep0(i), seloss0(i),
157  * munit(i), ng0(i), ne0(i), nmu0(i), cog0
158 !/////////
159 ! write(0,*) ' input0 read'
160 !//////////////
161  endif
162  enddo
163  end
164 ! ***********************
165  subroutine mergehyb1(h1)
166  use modhistogram1
167  use modhistogram2
168  use modhistogram3
169  implicit none
170 
171  type(histogram1) h1
172  type(histogram2) h2
173  type(histogram3) h3
174 
175  integer ndepth
176  integer nc
177  parameter(ndepth= 50)
178  integer fn1
179  real*8 ASdep(ndepth), munit(ndepth)
180  real*8 Esize0(ndepth),
181  * age0(ndepth), cogdep0(ndepth),
182  * seloss0(ndepth),
183  * ng0(ndepth), ne0(ndepth), nmu0(ndepth),
184  * cog0
185  integer EvNo0
186 
187  common /zbin2ascii/
188  * asdep, esize0, age0,
189  * cogdep0, seloss0, munit,
190  * ng0, ne0, nmu0, cog0,
191  * fn1, evno0
192 
193  integer klena
194  integer j
195 
196  do while (h1%c%eventno .ne. evno0)
197  call get1hyb( h1%c%eventno .lt. evno0)
198  enddo
199 !
200 ! available variables
201 ! * idx, ASdep(idx), Esize0(idx), age0(idx),
202 ! * SEloss0(idx), munit(idx),
203 ! * Ng0(idx), Ne0(idx), Nmu0(idx),
204 ! * ASdep(idx)/cog0, cog0
205 !
206 ! this part must be consistent with
207 ! FleshHist/interface.f output for evid
208 !//////////////
209 ! write(0,*) ' id', h1%c%id
210 !///////////
211 
212  read(h1%c%id, '(i3)') j
213 !//////////////
214 ! write(0,*) ' j=',j
215 !///////////
216  write(h1%c%id,
217  * '(i3, i5, f5.2, f5.2,
218  * i5, i5)')
219  * j, int( asdep(j) ),
220  * age0(j), asdep(j)/cog0,
221  * int(munit(j)), int(cog0)
222 !//////////////
223 ! write(0,*) ' j=',j
224 !///////////
225  return
226 ! *******************
227  entry mergehyb2(h2)
228 ! *******************
229 
230 
231  do while (h2%c%eventno .ne. evno0)
232  call get1hyb( h2%c%eventno .lt. evno0)
233  enddo
234  read(h2%c%id, '(i3)') j
235  write(h2%c%id,
236  * '(i3, i5, f5.2, f5.2,
237  * i5, i5)')
238  * j, int( asdep(j) ),
239  * age0(j), asdep(j)/cog0,
240  * int(munit(j)), int(cog0)
241 
242  return
243 ! *****************
244  entry mergehyb3(h3)
245 ! ****************
246  do while (h3%c%eventno .ne. evno0)
247  call get1hyb( h3%c%eventno .lt. evno0)
248  enddo
249 
250  read(h3%c%id, '(i3)') j
251  write(h3%c%id,
252  * '(i3, i5, f5.2, f5.2,
253  * i5, i5)')
254  * j, int( asdep(j) ),
255  * age0(j), asdep(j)/cog0,
256  * int(munit(j)), int(cog0)
257  end
258 
259 
260  subroutine openhyb(icon)
261  implicit none
262  integer icon ! output. 1--> hybrid must be read
263  ! 0--> hybrid need not be used
264  integer leng
265  integer ndepth
266  parameter(ndepth= 50)
267  integer fn1
268  real*8 ASdep(ndepth), munit(ndepth)
269  real*8 Esize0(ndepth),
270  * age0(ndepth), cogdep0(ndepth),
271  * seloss0(ndepth),
272  * ng0(ndepth), ne0(ndepth), nmu0(ndepth),
273  * cog0
274  integer EvNo0
275 
276  common /zbin2ascii/
277  * asdep, esize0, age0,
278  * cogdep0, seloss0, munit,
279  * ng0, ne0, nmu0, cog0,
280  * fn1, evno0
281 
282  character*120 hyb0
283  integer kgetenv2
284 
285  fn1= 3
286  leng = kgetenv2("HYBFILE0", hyb0)
287  call copenfw2(fn1, hyb0, 1, icon)
288  if(icon .ne. 1) then
289  write(0,*)
290  * "You haven't given env. var. HYBFILE0"
291  write(0,*)
292  * "or File specified by HYBFILE0"
293  if( icon .eq. 0) then
294  write(0,*) 'not exists'
295  else
296  write(0,*) ' cannot be opened '
297  endif
298  stop 9999
299  else
300  write(0,*) hyb0(1:leng), ' opened'
301  icon = 1
302  endif
303 
304  evno0 =0
305  end
integer npitbl real *nx parameter(n=101, npitbl=46, nx=n-1) real *8 uconst
subroutine get1hyb
void kwhistp(struct histogram1 *h, FILE *fno)
void kwhistd(struct histogram1 *h)
block data cblkElemag data *AnihiE ! Eposi< 1 TeV, anihilation considered *X0/365.667/, ! radiation length of air in kg/m2 *Ecrit/81.e-3/, ! critical energy of air in GeV *MaxComptonE/1./, ! compton is considered below 1 GeV *MaxPhotoE/1.e-3/, ! above this, PhotoElectric effect neg. *MinPhotoProdE/153.e-3/, ! below 153 MeV, no gp --> hadrons ! scattering const not MeV *Knockon true
Definition: cblkElemag.h:7
subroutine mergehyb1(h1)
Definition: bin2bin.f:166
void kwhistso(int binw)
subroutine copenfw2(io, fnin, form, icon)
Definition: copenf.f:205
void kwhistr(struct histogram1 *h, FILE *bfnor, int icon)
program main
Definition: ascii2bin.f:1
block data cblkElemag data *AnihiE ! Eposi< 1 TeV, anihilation considered *X0/365.667/, ! radiation length of air in kg/m2 *Ecrit/81.e-3/, ! critical energy of air in GeV *MaxComptonE/1./, ! compton is considered below 1 GeV *MaxPhotoE/1.e-3/, ! above this, PhotoElectric effect neg. *MinPhotoProdE/153.e-3/, ! below 153 MeV, no gp --> hadrons ! scattering const not MeV *Knockon ! knockon is considered Obsolete *PhotoProd false
Definition: cblkElemag.h:7
void kwhists(struct histogram1 *h, float inorm)
subroutine openhyb(icon)
Definition: bin2bin.f:261