COSMOS v7.655  COSMOSv7655
(AirShowerMC)
ksmooth.f
Go to the documentation of this file.
1  subroutine ksmooth(x,intvx, y, intvy, n, jin, repeat,
2  * cgap, icon)
3 ! very simple smoothing of data
4 ! This is intended to smooth arrival time distribution
5 ! which is integrated from smaller time side and normalized
6 ! to be 1 at the largest time.
7 ! In many cases, the distribution has long tail approaching to 1.
8 ! The smooting is tried until the maximum gap of current y values
9 ! and those after smoothing becomes < cgap/Neff. ( y is updated
10 ! at each smoothing). Where Neff
11 ! is the effective number of data points. Neff is defined as
12 ! the data number which lie below y=0.95. (This is to avoid the
13 ! effect of long tail close to y=1.0).
14  implicit none
15  integer intvx ! input see below
16  integer intvy ! input see below. Normally these two are 1
17  integer n ! input number of data point
18  real*8 x(intvx, n) ! input. data points are given at
19  ! x(1, i), i=1,...n
20  real*8 y(intvy, n) ! input/output. data to be smoothed at x.
21  integer jin ! input. 0. no smoothing for the 1 st and last points
22  ! 1. smoothing is tried also to the 1st and last
23  ! For time distribution, 0 is ok
24 
25  integer repeat ! input. The maximum number of smoothing.
26  ! smooting is ceased at this number even cgap/Neff
27  ! condtion is not satisfied. Normally 500~1000 is ok
28 !
29 ! if repeat is large, this procedure gives a straight line.
30 !
31  real*8 cgap ! input. critical value to judge the max gap. As explained
32 ! above. 0.03~0.2.
33  integer icon ! output. number of smoothing actually tried.
34  ! -1 means no success.
35 
36 ! take 3 data points from smallest x, and get average of
37 ! 3 y's and make it to be the value of 2nd y.
38 ! Then, extract next 3 x's until the 3rd point becomes then
39 ! n-th point. if jin==1,
40 
41  integer i, j
42  real*8 sum, y2, y3, yn1, yn2, r, dy1, dy2, dy3
43  real*8 temp
44  real*8 gap
45  integer neff
46  neff = 0
47  do i = 1, n
48  if(y(1,i) .gt. 0.95 ) exit
49  neff = neff+ 1
50  enddo
51  if(neff .lt. 3) then
52  neff= n
53  endif
54 
55  if( n .le. 2) then
56  icon = -1
57  else
58  icon = 0
59  do i = 1, repeat
60  icon = icon + 1
61  gap = 0.
62  if(jin .eq. 1) then
63  y2 = y(1, 2)
64  y3 = y(1, 3)
65  yn1 = y(1, n-1)
66  yn2 = y(1, n-2)
67  endif
68 
69  do j = 2, n-1
70  r =(x(1,j)-x(1,j-1))/(x(1,j+1)-x(1,j))
71  sum = y(1, j-1) + y(1,j) +
72  * y(1,j+1)*r
73  if( j .eq. 2) then
74  temp = sum/(2.0d0 + r)
75  else
76  if(gap .lt. abs(temp-y(1,j-1)) ) then
77  gap = abs(temp-y(1,j-1))
78  endif
79  y(1,j-1) = temp
80  temp = sum/(2.0d0 + r)
81  endif
82  enddo
83  y(1,n-1) = temp
84  if( jin .eq. 1) then
85  dy3= y3-y(1,3)
86  dy2 = y2-y(1,2)
87  y(1, 1) = (dy3-dy2)/(x(1,3)-x(1,2)) *
88  * (x(1,1)-x(1,2)) + dy2 + y(1, 1)
89 
90  dy1 = yn1 - y(1, n-1)
91  dy2 = yn2 - y(1, n-2)
92  y(1,n) =(dy2-dy1)/(x(1,n-2)-x(1,n-1))*
93  * (x(1,n)-x(1,n-1)) + dy1 + y(1,n)
94  endif
95  if(gap .lt. cgap/neff) exit
96  enddo
97  endif
98  end
99 !c test program
100 !c ifort ksmooth.f
101 !c ./a.out cgapvalue < data > outdta
102 !
103 ! implicit none
104 ! integer n, an, i
105 ! parameter (n=2000)
106 ! integer repeat, icon
107 ! real*8 x(n), y(n)
108 ! real*8 cgap
109 ! integer count, status
110 ! character*80 buf
111 !
112 !
113 ! count = NARGS()
114 ! if(count .ne. 2) then
115 ! write(0,*) ' must give cgap'
116 ! stop
117 ! endif
118 ! call getarg(1, buf, status)
119 ! write(0,*) status, buf
120 ! read(buf, *) cgap
121 ! write(0, *) ' cgap =',cgap
122 ! an = 0
123 ! repeat = 1000
124 ! do while(.true.)
125 !c write(0,*) an
126 ! read(*,*, end=1000) x(an+1), y(an+1)
127 ! if(an .gt. n) then
128 ! write(0,*) ' too many data'
129 ! stop
130 ! endif
131 ! an = an +1
132 ! enddo
133 ! 1000 continue
134 ! write(0,*) ' data read: n=',an
135 !
136 ! call ksmooth(x, 1, y, 1, an, 0, repeat, cgap, icon)
137 ! write(0,*) ' icon=',icon
138 ! do i = 1, an
139 ! write(*,*) x(i), y(i)
140 ! enddo
141 ! end
block data cblkEvhnp ! currently usable models data RegMdls ad *special data *Cekaon d0
Definition: cblkEvhnp.h:5
subroutine ksmooth(x, intvx, y, intvy, n, jin, repeat, cgap, icon)
Definition: ksmooth.f:3