COSMOS v7.655  COSMOSv7655
(AirShowerMC)
timeslice.f
Go to the documentation of this file.
1 ! #define G95
2 ! #define ABSOFT
3  implicit none
4 #include "Zprivate2.f"
5 
6  character*120 tracefile, timeprofile, filename
7  integer i
8  integer klena, ntime
9  integer ntimem
10  parameter(ntimem = 10)
11  real ta1(ntimem), ta2(ntimem), dta(ntimem),
12  * pixela(ntimem), rmaxa(ntimem),
13  * maxppta(ntimem), maxthina(ntimem),
14  * offseta(ntimem)
15  character*120 dira(ntimem)
16 
17  do i = 1, 9
18  codesel(i) = 0
19  enddo
20  read(*,*)
21  read(*,*)
22  * tracefile, timeprofile, split, outtype
23  read(*,*)
24  read(*,*) chgsel, codesel
25 !
26 ! read det to primary system conversion matrix
27  read(*,*)
28  read(*,*) aax, aay, aaz
29  read(*,*) bbx, bby, bbz
30  read(*,*) ccx, ccy, ccz
31 
32 
33  ncodes = 0
34  do i = 1, 9
35  if( codesel(i) .eq. 0) goto 10
36  ncodes = ncodes + 1
37  enddo
38  10 continue
39  select = 0
40  if(chgsel .ne. -1) select = select + 1
41 ! code selection imposed
42  if(ncodes .gt. 0) select = select + 2
43 !
44 !
45  write(0,*) tracefile(1:klena(tracefile)), " ",
46  * timeprofile(1:klena(timeprofile)), split, outtype
47  write(0,*) chgsel, codesel
48  write(0,*) aax, aay, aaz
49  write(0,*) bbx, bby, bbz
50  write(0,*) ccx, ccy, ccz
51 
52 #ifndef ABSOFT
53  call flush(0)
54 #endif
55  open(11, file=timeprofile(1:klena(timeprofile)) )
56  ntime = 0
57  write(0,*) ' profile opened'
58  read(11,*)
59  do while(.true.)
60  i = ntime +1
61  read(11,*, end=200) ta1(i), ta2(i), dta(i), pixela(i),
62  * rmaxa(i), maxppta(i), maxthina(i),
63  * offseta(i), dira(i)
64  if( ta1(i) .eq. 0. .and. ta2(i) .eq. 0.) goto 200
65 
66  write(0, *) ta1(i), ta2(i), dta(i), pixela(i),
67  * rmaxa(i), maxppta(i), maxthina(i),
68  * offseta(i), dira(i)(1:klena(dira(i)))
69 
70  ntime = ntime +1
71  if(rmaxa(i) .eq. 0.) then
72  rmaxa(i) = 1.e10
73  endif
74  enddo
75  200 continue
76  close(11)
77  do i = 1, ntime
78  filename = ' '
79  filename = dira(i)(1:klena(dira(i)))//"/dummy"
80  open(11, file=filename, err=210)
81  close(11)
82  enddo
83  goto 220
84  210 continue
85  write(0,*) ' following dir may be missing:= ',
86  * dira(i)(1:klena(dira(i)))
87  stop 3333
88 
89 
90  220 continue
91  open(11, file=tracefile(1:klena(tracefile)),
92  * form='formatted', err=230 )
93  goto 240
94  230 continue
95  write(0,*) ' trace file may be missing:= ',
96  * tracefile(1:klena(tracefile))
97  stop 4444
98  240 continue
99  write(0,*) ' trace file opend'
100  do i = 1, ntime
101  if(maxppta(i) .eq. 0) then
102  maxppt = maxp
103  else
104  maxppt = maxppta(i)
105  endif
106  maxthin = maxthina(i)
107  offset = offseta(i)
108  dir = dira(i)
109  call slice1tbin(
110  * ta1(i), ta2(i), dta(i), pixela(i), rmaxa(i) )
111  rewind 11
112  enddo
113  end
114 
115  subroutine slice1tbin(mint, maxt, dt, pixelin, rmax)
116  implicit none
117 #include "Zprivate2.f"
118  real*4 mint, maxt, dt, t1, t2, rmax, pixelin
119 
120  rmax2 = rmax**2
121  t2 = mint
122  pixel = pixelin
123  do while (t2 .lt. maxt)
124  t1 = t2
125  t2 = min(t1+ dt*n , maxt)
126  jmax = 0
127  jmin = 10000000
128 
129  call slice(t1, t2, dt)
130  write(0,*) ' t1=',t1, 't2=',t2, ' slice ended'
131  write(0,*) ' maxppt=', maxppt
132  call thinning(jmin, jmax)
133  write(0,*) ' thinning ended'
134  if(split) then
135  if( ibits(outtype, 0, 1) .ne. 0) then
136  call mkfiles
137  endif
138  if( ibits(outtype, 1, 1) .ne. 0) then
139  call mkskelfiles
140  endif
141  write(0,*) ' all output finished'
142  else
143  if(ibits(outtype, 0, 1) .ne. 0) then
144  call mkafile
145  endif
146  if(ibits(outtype, 1, 1) .ne. 0) then
147  call mkaskelfile
148  endif
149  write(0,*) ' ouput to a file ended'
150  endif
151  rewind(11)
152  enddo
153  end
154 ! *********************************
155 ! read one trace file and slice data by constant time surface.
156 ! data is accumulated in x(i,j) etc. where i is the index of
157 ! number of ptcls in the given time plane. j the index of the
158 ! time plane.
159 ! *********************************
160  subroutine slice(mint, maxt, dt)
161  implicit none
162 #include "Zprivate2.f"
163 
164  real*4 mint, maxt, dt
165  integer i, j, kk
166  real*4 t, k
167  integer*2 code, chg
168  integer it1, it2, kkk
169  real*4 xx1, yy1, zz1, time1
170  real*4 xx2, yy2, zz2, time2
171  real*4 xxp, yyp
172  real*4 kerg1, kerg2
173  logical chkcode
174  character* 120 input
175  real*8 linec
176  data linec/0.0/
177  save linec
178 
179  chkcode = ncodes .gt. 0
180 
181  do j = 1, n
182  idx(j) = 0
183  thinc(j) = 0
184  enddo
185 
186  do while (.true.)
187 
188  input = ' '
189  read(11, '(a)', end=1000 ) input
190  linec = linec + 1.d0
191  if( mod(linec, 1.d7) .eq. 0 ) then
192  write(0,*)
193  * ' ------------------------------------linec=',linec
194 #ifndef ABSOFT
195  call flush(0)
196 #endif
197  endif
198  if( input .ne. " " ) then
199  read(input, * ) xx1, yy1, zz1, code, kerg1, chg,
200  * time1
201  if(select .eq. 0) goto 100
202 ! select all
203  if( chgsel .ne. -1 ) then
204 ! charge selection
205  if(chgsel .eq. 0 .and. chg .ne. 0) goto 950
206  if(chgsel .eq. 1 .and. chg .eq. 0) goto 950
207  endif
208  if( chkcode ) then
209  do kkk = 1, ncodes
210  if(codesel(kkk) .eq. code) goto 100
211  enddo
212  goto 950
213  endif
214 !
215  100 continue
216  do while( input .ne. " " )
217  read(11, '(a)', end =1000) input
218  linec = linec + 1.d0
219  if( mod(linec, 1.d7) .eq. 0 ) then
220  write(0,*)
221  * ' ------------------------------------linec=',
222  * linec
223 #ifndef ABSOFT
224  call flush(0)
225 #endif
226  endif
227 
228  if( input .ne. " " ) then
229  read(input, * ) xx2, yy2, zz2, code, kerg2, chg,
230  * time2
231  xxp = xx2*aax + yy2*aay ! aaz =0
232  yyp = xx2*bbx + yy2*bby + zz2*bbz
233  it1 = (time1- mint)/dt +1
234  it2 = (time2- mint)/dt +1
235 
236  if(xxp**2 + yyp**2 .gt. rmax2) goto 900
237  if(it1 .lt. 1) goto 900
238  if(it2 .gt. n) goto 900
239  if(time2 .gt. maxt) goto 900
240  jmin = min(jmin, it1)
241  jmax = max(jmax, it2)
242  do j = it1, it2
243  t = j*dt + mint
244  if( idx(j) .eq. maxppt .and.
245  * thinc(j) .lt. maxthin ) then
246  write(0,*)
247  * 'ptcls at time=', t , ' > ', maxppt
248  write(0,*)
249 #ifndef ABSOFT
250  call flush(0)
251 #endif
252  call thinning(j, j)
253  thinc(j) = thinc(j) + 1
254  endif
255  idx(j) = idx(j) + 1
256  if(idx(j) .le. maxppt) then
257 ! (x2-x1)/(t2-t1) *(t-t1) +x1
258  if(time2 .eq. time1) then
259  k =0.
260  else
261  k = (t - time1) /(time2-time1)
262  endif
263  x(idx(j), j) = (xx2-xx1) * k + xx1
264  y(idx(j), j) = (yy2-yy1) * k + yy1
265  z(idx(j), j) = (zz2-zz1) * k + zz1
266  codex(idx(j), j) = code
267  chgx(idx(j), j) = chg
268  endif
269  enddo
270  900 continue
271  xx1 = xx2
272  yy1 = yy2
273  zz1 = zz2
274  time1 = time2
275  endif
276  enddo
277  endif
278  950 continue
279  enddo
280  1000 continue
281  end
282 
283 ! ***********************************
284 ! do thinning if two or more data fall in the dame pixel.
285 ! **********************************
286  subroutine thinning(i1, i2)
287  implicit none
288 #include "Zprivate2.f"
289 ! culling overlapping points in a pixel
290 ! this is very rough thinning
291 ! sorr each x
292  integer i1, i2
293  integer nc, j, i, k1, k2, l, nc0
294  logical dothin
295  integer ntp
296 
297 
298  do j = i1, i2
299  ntp= min(idx(j), maxppt)
300  dothin = .false.
301  if( ntp .gt. maxppt/2.0 ) then
302  call kqsortr(x(1,j), si, ntp)
303  do i = 1, ntp-1
304  k1 = si(i)
305  if( k1 .lt. 0 ) goto 20
306  do l = i+1, ntp
307  k2 = si(l)
308  if(k2 .lt. 0) goto 10
309  if(abs(x(k1, j)- x(k2,j)) .gt. pixel ) goto 20
310 ! since xx is sorted, we may safe to skip
311 ! further check
312 !
313  if(abs(y(k1, j)- y(k2,j)) .gt. pixel ) goto 10
314  if(abs(z(k1, j)- z(k2,j)) .gt. pixel ) goto 10
315 ! remove k2
316  si(l) = - k2
317  dothin = .true.
318  10 continue
319  enddo
320  20 continue
321  enddo
322  if(dothin) then
323  nc0 = ntp
324  call mvdata(x, j, nc)
325  call mvdata(y, j, nc)
326  call mvdata(z, j, nc)
327  call mvdatai(codex, j, nc)
328  call mvdatai(chgx, j, nc)
329  write(0,*) ' at time idx=',j,
330  * ' thinning ', nc0, "-->", nc
331 #ifndef ABSOFT
332  call flush(0)
333 #endif
334  idx(j) = nc
335  endif
336  endif
337  enddo
338  end
339 ! *******************************
340  subroutine mvdata(f, j, nc)
341  implicit none
342 #include "Zprivate2.f"
343 
344  integer j
345  real*4 f(maxp, n)
346 
347  real*4 temp(maxp)
348  integer i, nc, l, ntp
349 
350 
351  nc = 0
352  ntp = min(idx(j), maxppt)
353  do i = 1, ntp
354  l = si(i)
355  if(l .gt. 0 ) then
356  nc = nc + 1
357  temp(nc) = f(l, j)
358  endif
359  enddo
360 
361  do i = 1, nc
362  f(i, j) = temp(i)
363  enddo
364 
365 
366  end
367  subroutine mvdatai(f, j, nc)
368  implicit none
369 #include "Zprivate2.f"
370  integer j
371  integer*2 f(maxp, n)
372 
373  integer*2 temp(maxp)
374  integer i, nc, l, ntp
375 
376 
377  nc = 0
378  ntp = min(idx(j), maxppt)
379 
380  do i = 1, ntp
381  l = si(i)
382  if(l .gt. 0 ) then
383  nc = nc + 1
384  temp(nc) = f(l, j)
385  endif
386  enddo
387 
388  do i = 1, nc
389  f(i, j) = temp(i)
390  enddo
391 
392 
393  end
394 
395  subroutine mkfiles
396  implicit none
397 #include "Zprivate2.f"
398 
399  character* 130 filename
400  integer filec
401  integer klena
402  integer i, j
403  data filec/0/
404  save filec
405 
406  do j = jmin, jmax
407  if(idx(j) .gt. 0) then
408  filec = filec +1
409  write(filename,'(a, a, i5.5,a)') dir(1:klena(dir)),
410  * "/ts", filec+offset, ".dat"
411  open(20, file=filename(1:klena(filename)),
412  * form='formatted')
413  do i= 1, min( idx(j), maxppt)
414  write(20,'(3g16.8,i3,i3)')
415  * x(i, j), y(i,j), z(i,j), codex(i,j), chgx(i,j)
416  enddo
417  close(20)
418  endif
419  enddo
420  end
421 
422  subroutine mkskelfiles
423  implicit none
424 #include "Zprivate2.f"
425 
426  character* 130 filename
427  integer filec
428 
429  integer klena, ntp
430 
431  integer i, j
432  data filec/0/
433  save filec
434 
435 
436  write(0,*) ' jmin,max=', jmin, jmax
437 
438 
439  do j = jmin, jmax
440  ntp = min(idx(j), maxppt)
441  if(idx(j) .gt. 0) then
442  filec = filec + 1
443  write(filename,'(a, a, i5.5, a)') dir(1:klena(dir)),
444  * "/ts", filec+offset, ".skel"
445 
446  open(20, file=filename(1:klena(filename)),
447  * form='formatted')
448  write(20, '(a)') "SKEL"
449  call wtaskel(20, x(1,j), y(1,j), z(1,j),
450  * codex(1,j), chgx(1, j), ntp)
451  close(20)
452  endif
453  enddo
454  end
455 
456  subroutine mkafile
457  implicit none
458 #include "Zprivate2.f"
459 
460  integer i, j
461  character* 130 filename
462 
463  integer filec
464  integer klena
465  data filec/0/
466  save filec
467 
468  if( filec .eq. 0 ) then
469  filename = dir(1:klena(dir))//"/timesorted.dat"
470  open(20, file=filename(1:klena(filename)),
471  * form='formatted')
472  filec = 1
473  endif
474 
475  do j = jmin, jmax
476  do i= 1, min(idx(j), maxppt)
477  write(20,'(3g16.8, i3,i3)' )
478  * x(i, j), y(i,j), z(i,j), codex(i,j), chgx(i,j)
479  enddo
480  if( idx(j) .gt. 0 ) write(20,*)
481  enddo
482  end
483  subroutine mkaskelfile
484  implicit none
485 #include "Zprivate2.f"
486 
487  integer i, j
488  character* 130 filename
489 
490  integer filec
491  integer klena, ntp
492  data filec/0/
493  save filec
494 
495  if( filec .eq. 0 ) then
496  filename = dir(1:klena(dir))//"/timesorted.skel"
497  open(20, file=filename(1:klena(filename)),
498  * form='formatted')
499  filec = 1
500  endif
501 
502  do j = jmin, jmax
503  ntp = min(idx(j), maxppt)
504  if(idx(j) .gt. 0) then
505  write(20,'(a)') "SKEL"
506  call wtaskel(20,
507  * x(1, j), y(1,j), z(1,j), codex(1,j), chgx(1,j), ntp)
508  write(20,*)
509  endif
510  enddo
511  end
512 ! ******************
513 ! write a skel data for Geomview
514  subroutine wtaskel(fno, xa, ya, za, code, chg, np)
515 !
516  implicit none
517  integer fno, np
518  real*4 xa(np), ya(np), za(np)
519  integer*2 code(np), chg(np)
520 
521  real r, g, b, alpha
522  integer i
523 
524 
525  if(np .gt. 0) then
526  write(fno, '(2i9)') np, np
527  do i = 1, np
528  write(fno, '(3g16.8)' ) xa(i), ya(i), za(i)
529  enddo
530  do i= 1, np
531  call code2rgb(code(i), chg(i), r, g, b, alpha)
532  write(fno, '("1 ", i8, 3f5.2)')
533  * i-1, r, g, b
534  enddo
535  endif
536  end
537  subroutine code2rgb(codei, chgi, r, g, b, alpha)
538  implicit none
539  integer*2 codei, chgi
540  real r, g, b, alpha
541 
542  integer ncolor, mncolor
543  parameter( mncolor = 17 )
544 ! structure /colortab/
545  integer*2 tcode(mncolor)
546  integer*2 tchg(mncolor)
547  real tr(mncolor)
548  real tg(mncolor)
549  real tb(mncolor)
550  real talpha(mncolor)
551 ! end structure
552 ! record /colortab/ tab(mncolor)
553 
554  character*80 input
555  integer i
556 
557  integer first
558  data first/0/
559  save first, ncolor, tcode, tchg, tr, tg, tb, talpha
560 
561 
562  if(first .eq. 0) then
563  input = ' '
564 
565  open(13, file='colortab')
566  i = 0
567  do while(.true.)
568  read(13,'(a)',end=10) input
569 
570  if(input(1:1) .ne. "#" .and. input .ne. ' ') then
571  i = i + 1
572  if(i .gt. mncolor) then
573  write(0,*) ' too many color spec. in colortab'
574  stop 99999
575  endif
576 
577  read(input,*)
578  * tcode(i), tchg(i),
579  * tr(i), tg(i), tb(i),
580  * talpha(i)
581  endif
582  enddo
583  10 continue
584  ncolor = i
585  first = 1
586  close(13)
587  endif
588 
589  do i = 1, ncolor
590  if(tcode(i) .eq. codei .and. tchg(i) .eq. chgi) goto 100
591  enddo
592  i = ncolor
593  100 continue
594 
595  r = tr(i)
596  g = tg(i)
597  b = tb(i)
598  alpha = talpha(i)
599  end
600 
601 
602 
integer npitbl real *nx parameter(n=101, npitbl=46, nx=n-1) real *8 uconst
nodes z
subroutine mkfiles
Definition: timeslice.f:242
nodes i
subroutine slice1tbin(mint, maxt, dt, pixelin, rmax)
Definition: timeslice.f:116
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
*************************block data cblkTracking *************************implicit none data *ExactThick *Freec *RatioToE0 *MagChgDist *TimeStructure *Truncn *Truncx data *IncMuonPolari *KEminObs *ThinSampling *EthinRatio *Generate *LpmEffect *MagPairEmin e10
Definition: cblkTracking.h:9
!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