COSMOS v7.655  COSMOSv7655
(AirShowerMC)
timesliceg77.f
Go to the documentation of this file.
1  implicit none
2  include "Zprivate2g77.f"
3 
4  character*120 tracefile
5  integer leng, icon, i, outtype
6  real*4 mint, maxt, dt, t1, t2, rmax
7  logical split
8  integer klena
9 
10  mint = 000.
11  maxt = 20000.
12  dt = 10.
13  pixel0 = dt
14  maxppt = maxp
15  read(*,*)
16  * tracefile, dir, mint, maxt, dt, pixel0, pixelinc, split,
17  * outtype, mulalpha, maxppt, rmax
18 ! read det to primary system conversion matrix
19 !
20  read(*,*) aax, aay, aaz
21  read(*,*) bbx, bby, bbz
22  read(*,*) ccx, ccy, ccz
23 
24  if(maxppt .le. 0) then
25  maxppt = maxp
26  endif
27  write(0,*)
28  * tracefile(1:klena(tracefile)), " ", dir(1:klena(dir)),
29  * mint, maxt, dt, pixel0, pixelinc, split,
30  * outtype, mulalpha, maxppt, rmax
31 
32  rmax2 = rmax**2
33 ! call copenfw2(11, tracefile, 1, icon)
34  open(11, file=tracefile, form='formatted' )
35 ! if(icon .ne. 1) then
36 ! write(0,*) tracefile, ' cannot be opened'
37 ! stop 1111
38 ! endif
39 
40  t2 = mint
41  offset = mint/dt
42  do while (t2 .lt. maxt)
43  t1 = t2
44  t2 = min(t1+ dt*n , maxt)
45  jmax = 0
46  jmin = 10000000
47  call slice(t1, t2, dt)
48  write(0,*) ' t1=',t1, 't2=',t2, ' slice ended'
49  call thinning(0, jmin, jmax)
50  write(0,*) ' thinning ended'
51 
52  if(split) then
53  if( ibits(outtype, 0, 1) .ne. 0) then
54  call mkfiles
55  endif
56  if( ibits(outtype, 1, 1) .ne. 0) then
57  call mkskelfiles
58  endif
59  write(0,*) ' all output finished'
60  else
61  if(ibits(outtype, 0, 1) .ne. 0) then
62  call mkafile
63  endif
64  if(ibits(outtype, 1, 1) .ne. 0) then
65  call mkaskelfile
66  endif
67  write(0,*) ' ouput to a file ended'
68  endif
69  rewind(11)
70  enddo
71  end
72 ! *********************************
73 ! read one trace file and slice data by constant time surface.
74 ! data is accumulated in x(i,j) etc. where i is the index of
75 ! number of ptcls in the given time plane. j the index of the
76 ! time plane.
77 ! *********************************
78  subroutine slice(mint, maxt, dt)
79  implicit none
80  include "Zprivate2g77.f"
81 
82  real*4 mint, maxt, dt
83  integer i, j, kk
84  real*4 t, k
85  integer*2 code, chg
86  integer it1, it2
87  real*4 xx1, yy1, zz1, time1
88  real*4 xx2, yy2, zz2, time2
89  real*4 xxp, yyp
90 
91  character* 120 input
92  real*8 linec
93  data linec/0.0/
94  save linec
95 
96  do j = 1, n
97  idx(j) = 0
98  enddo
99 
100  do while (.true.)
101  input = ' '
102  read(11, '(a)', end=1000 ) input
103  linec = linec + 1.d0
104  if( mod(linec, 1.d7) .eq. 0 ) then
105  write(0,*)
106  * ' ------------------------------------linec=',linec
107  endif
108  if( input .ne. " " ) then
109  read(input, * ) xx1, yy1, zz1, time1, code, chg
110  do while( input .ne. " ")
111  read(11, '(a)', end =1000) input
112  linec = linec + 1.d0
113  if( mod(linec, 1.d7) .eq. 0 ) then
114  write(0,*)
115  * ' ------------------------------------linec=',
116  * linec
117  endif
118 
119  if( input .ne. " " ) then
120  read(input, * ) xx2, yy2, zz2, time2, code, chg
121  xxp = xx2*aax + yy2*aay ! aaz =0
122  yyp = xx2*bbx + yy2*bby + zz2*bbz
123  if(xxp**2 + yyp**2 .gt. rmax2) goto 900
124  it1 = (time1- mint)/dt +1
125  it2 = (time2- mint)/dt
126  if(it1 .lt. 1) goto 900
127  if(it2 .gt. n) goto 900
128  if(time2 .gt. maxt) goto 900
129  jmin = min(jmin, it1)
130  jmax = max(jmax, it2)
131  do j = it1, it2
132  t = j*dt + mint
133  if( idx(j) .ge. maxppt ) then
134  pixel = pixel0
135  write(0,*)
136  * 'ptcls at time=', t , ' > ', maxppt
137  write(0,*)
138  * 'try to thin ptcls in the same pixel'
139  kk = 0
140  call thinning(kk, j, j)
141  endif
142  do while (idx(j) .ge. maxppt)
143  pixel = pixel*pixelinc
144  write(0,*) 'ptcls > ', maxppt
145  write(0,*) 'thinning not worked'
146  write(0,*)
147  * 'brute thinning is tried by',pixelinc,
148  * 'x current pixel =', pixel
149 ! if kk == 1, don't do sort; kk may be
150 ! reset to 0 inside of thinning
151  call thinning(kk, j, j)
152  enddo
153  idx(j) = idx(j) + 1
154 ! (x2-x1)/(t2-t1) *(t-t1) +x1
155  k = (t - time1) /(time2-time1)
156  x(idx(j), j) = (xx2-xx1) * k + xx1
157  y(idx(j), j) = (yy2-yy1) * k + yy1
158  z(idx(j), j) = (zz2-zz1) * k + zz1
159  codex(idx(j), j) = code
160  chgx(idx(j), j) = chg
161  enddo
162  900 continue
163  xx1 = xx2
164  yy1 = yy2
165  zz1 = zz2
166  time1 = time2
167  endif
168  enddo
169  endif
170  enddo
171  1000 continue
172  end
173 ! ***********************************
174 ! do thinning if two or more data fall in the dame pixel.
175 ! **********************************
176  subroutine thinning(kk, i1, i2)
177  implicit none
178  include "Zprivate2g77.f"
179 ! culling overlapping points in a pixel
180 ! this is very rough thinning
181 ! sorr each x
182  integer kk ! in/out. if 0, sort x before thinning
183  integer i1, i2
184  integer nc, j, i, k1, k2, l, nc0
185  logical dothin
186 
187  do j = i1, i2
188  dothin = .false.
189  if( idx(j) .gt. 0) then
190  if(kk .eq. 0) then
191  call kqsortr(x(1,j), si, idx(j))
192  endif
193  do i = 1, idx(j)-1
194  k1 = si(i)
195  if(k1 .lt. 0) goto 20
196  do l = i+1, idx(j)
197  k2 = si(l)
198  if(k2 .lt. 0) goto 10
199  if(abs(x(k1, j)- x(k2,j)) .gt. pixel ) goto 20
200 ! since xx is sorted, we may safe to skip
201 ! further check
202 !
203  if(abs(y(k1, j)- y(k2,j)) .gt. pixel ) goto 10
204  if(abs(z(k1, j)- z(k2,j)) .gt. pixel ) goto 10
205 ! remove k2
206  si(l) = - k2
207  dothin = .true.
208  10 continue
209  enddo
210  20 continue
211  enddo
212  if(dothin) then
213  nc0 = idx(j)
214  call mvdata(x, j, nc)
215  call mvdata(y, j, nc)
216  call mvdata(z, j, nc)
217  call mvdatai(codex, j, nc)
218  call mvdatai(chgx, j, nc)
219  idx(j) = nc
220  write(0,*) ' thinning ', nc0, "-->", nc
221  else
222  if(i1 .eq. i2) then
223 ! sorted data remain the same; so if
224 ! thinning is tried with larger pixel
225 ! we don't need to sort again
226  kk = 1
227  endif
228  endif
229  endif
230  enddo
231  end
232 ! *******************************
233  subroutine mvdata(f, j, nc)
234  implicit none
235  include "Zprivate2g77.f"
236 
237  integer j
238  real*4 f(maxp, n)
239 
240  real*4 temp(maxp)
241  integer i, nc, l
242 
243  nc = 0
244 
245  do i = 1, idx(j)
246  l = si(i)
247  if(l .gt. 0 ) then
248  nc = nc + 1
249  temp(nc) = f(l, j)
250  endif
251  enddo
252 
253  do i = 1, nc
254  f(i, j) = temp(i)
255  enddo
256 
257 
258  end
259  subroutine mvdatai(f, j, nc)
260  implicit none
261  include "Zprivate2g77.f"
262  integer j
263  integer*2 f(maxp, n)
264 
265  integer*2 temp(maxp)
266  integer i, nc, l
267  nc = 0
268 
269  do i = 1, idx(j)
270  l = si(i)
271  if(l .gt. 0 ) then
272  nc = nc + 1
273  temp(nc) = f(l, j)
274  endif
275  enddo
276 
277  do i = 1, nc
278  f(i, j) = temp(i)
279  enddo
280 
281 
282  end
283 
284  subroutine mkfiles
285  implicit none
286  include "Zprivate2g77.f"
287 
288  character* 130 filename
289 
290  integer klena
291 
292  integer i, j
293 
294  do j = jmin, jmax
295  if(idx(j) .gt. 0) then
296  write(filename,'(a, a, i5.5,a)') dir(1:klena(dir)),
297  * "/ts", j+offset, ".dat"
298  open(20, file=filename, form='formatted')
299  do i= 1, idx(j)
300  write(20,'(3g16.8,i3,i3)')
301  * x(i, j), y(i,j), z(i,j), codex(i,j), chgx(i,j)
302  enddo
303  close(20)
304  endif
305  enddo
306  end
307 
308  subroutine mkskelfiles
309  implicit none
310  include "Zprivate2g77.f"
311 
312  character* 130 filename
313 
314 
315  integer klena
316 
317  integer i, j
318 
319  do j = jmin, jmax
320  if(idx(j) .gt. 0) then
321  write(filename,'(a, a, i5.5, a)') dir(1:klena(dir)),
322  * "/ts", j+offset, ".skel"
323  open(20, file=filename, form='formatted')
324  write(20, '(a)') "SKEL"
325  call wtaskel(20, x(1,j), y(1,j), z(1,j),
326  * codex(1,j), chgx(1, j), idx(j), mulalpha)
327 
328  close(20)
329  endif
330  enddo
331  end
332 
333  subroutine mkafile
334  implicit none
335  include "Zprivate2g77.f"
336 
337  integer i, j
338  character* 130 filename
339 
340  integer filec
341  integer klena
342  data filec/0/
343  save filec
344 
345  if( filec .eq. 0 ) then
346  filename = dir(1:klena(dir))//"/timesorted.dat"
347  open(20, file=filename,
348  * form='formatted')
349  filec = 1
350  endif
351 
352  do j = jmin, jmax
353  do i= 1, idx(j)
354  write(20,'(3g16.8, i3,i3)' )
355  * x(i, j), y(i,j), z(i,j), codex(i,j), chgx(i,j)
356  enddo
357  if( idx(j) .gt. 0 ) write(20,*)
358  enddo
359  end
360  subroutine mkaskelfile
361  implicit none
362  include "Zprivate2g77.f"
363 
364  integer i, j
365  character* 130 filename
366 
367  integer filec
368  integer klena
369  data filec/0/
370  save filec
371 
372  if( filec .eq. 0 ) then
373  filename = dir(1:klena(dir))//"/timesorted.skel"
374  open(20, file=filename,
375  * form='formatted')
376  filec = 1
377  endif
378 
379  do j = jmin, jmax
380  if(idx(j) .gt. 0) then
381  write(20,'(a)') "SKEL"
382  call wtaskel(20,
383  * x(1, j), y(1,j), z(1,j), codex(1,j), chgx(1,j), idx(j),
384  * mulalpha)
385  write(20,*)
386  endif
387  enddo
388  end
389 ! ******************
390 ! write a skel data for Geomview
391  subroutine wtaskel(fno, xa, ya, za, code, chg, np, mulalpha)
392 !
393  implicit none
394  integer fno, np
395  real*4 xa(np), ya(np), za(np)
396  real*4 mulalpha
397  integer*2 code(np), chg(np)
398 
399  real r, g, b, alpha
400  integer i
401 
402  if(np .gt. 0) then
403  write(fno, '(2i9)') np, np
404  do i = 1, np
405  write(fno, '(3g16.8)' ) xa(i), ya(i), za(i)
406  enddo
407  do i= 1, np
408  call code2rgb(code(i), chg(i), r, g, b, alpha)
409  write(fno, '("1 ", i8, 3f5.2,f6.3)')
410  * i-1, r, g, b, alpha*mulalpha
411  enddo
412  endif
413  end
414  subroutine code2rgb(codei, chgi, r, g, b, alpha)
415  implicit none
416  integer*2 codei, chgi
417  real r, g, b, alpha
418 
419  integer ncolor, mncolor
420  parameter( mncolor = 17 )
421 ! type colortab
422  integer*2 tcode(mncolor)
423  integer*2 tchg(mncolor)
424  real tr(mncolor)
425  real tg(mncolor)
426  real tb(mncolor)
427  real talpha(mncolor)
428 ! end type colortab
429 ! type(colortab):: tab(mncolor)
430 
431  character*80 input
432  integer i
433 
434  integer first
435  data first/0/
436  save first, ncolor, tcode, tchg, tr, tg, tb, talpha
437 
438  if(first .eq. 0) then
439  input = ' '
440 
441  open(13, file='colortab')
442  i = 0
443  do while(.true.)
444  read(13,'(a)',end=10) input
445 
446  if(input(1:1) .ne. "#" .and. input .ne. ' ') then
447  i = i + 1
448  if(i .gt. mncolor) then
449  write(0,*) ' too many color spec. in colortab'
450  stop 99999
451  endif
452 
453  read(input,*)
454  * tcode(i), tchg(i),
455  * tr(i), tg(i), tb(i),
456  * talpha(i)
457  endif
458  enddo
459  10 continue
460  ncolor = i
461  first = 1
462  close(13)
463  endif
464 
465  do i = 1, ncolor
466  if(tcode(i) .eq. codei .and. tchg(i) .eq. chgi) goto 100
467  enddo
468  i = ncolor
469  100 continue
470 
471  r = tr(i)
472  g = tg(i)
473  b = tb(i)
474  alpha = talpha(i)
475  end
476 
477 
478 
integer npitbl real *nx parameter(n=101, npitbl=46, nx=n-1) real *8 uconst
nodes z
subroutine mkfiles
Definition: timeslice.f:242
subroutine mvdata(f, j, nc)
Definition: timeslice.f:191
subroutine thinning(i1, i2)
Definition: timeslice.f:141
subroutine wtaskel(fno, xa, ya, za, code, chg, np, mulalpha)
Definition: timeslice.f:359
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
averg real MaxCPU integer idx(Maxp)
subroutine mkskelfiles
Definition: timeslice.f:271
subroutine mkaskelfile
Definition: timeslice.f:328
block data cblkEvhnp ! currently usable models data RegMdls ad *special data *Cekaon d0
Definition: cblkEvhnp.h:5
subroutine code2rgb(codei, chgi, r, g, b, alpha)
Definition: timeslice.f:381
latitude latitude this system is used *****************************************************************! type coord sequence union map real y
Definition: Zcoord.h:25
integer function klena(cha)
Definition: klena.f:20
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
!onst int maxp
Definition: Zprivate.h:3
subroutine mvdatai(f, j, nc)
Definition: timeslice.f:217
integer n
Definition: Zcinippxc.h:1
subroutine mkafile
Definition: timeslice.f:301
subroutine kqsortr(A, ORD, N)
Definition: kqsortr.f:23
! structure defining a particle at production ! Basic idea of what is to be contained in ! the particle structue is that dynamical ones should be included those derivable from the particle code ! is not included ******************************************************type fmom momentum sequence union map real e endmap map real * x
Definition: Zptcl.h:21
subroutine slice(mint, maxt, dt)
Definition: timeslice.f:69