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