COSMOS v7.655  COSMOSv7655
(AirShowerMC)
kcsr1idx.f
Go to the documentation of this file.
1 ! test kcsr1idx (comb-sort for 1 dimension real double prec. array)
2 !
3 ! implicit none
4 ! integer nrec, l
5 ! parameter (nrec =10000)
6 ! real*8 a(nrec), u
7 ! integer idx(nrec)
8 ! do l = 1, nrec
9 ! call rndc(u)
10 ! a(l)= 2*u -1
11 ! enddo
12 ! write(*,*) '============ original'
13 ! do l=1, 10
14 ! write(*,*) a(l)
15 ! enddo
16 !
17 ! call kcsr1idx(a, nrec, idx, 'd')
18 ! write(*,*) '============ descending first 10'
19 ! do l=1, 10
20 ! write(*, *) a(idx(l))
21 ! enddo
22 ! write(*,*) ' last 10'
23 ! do l=nrec-10, nrec
24 ! write(*, *) a(idx(l))
25 ! enddo
26 !
27 ! call kcsr1idx(a, nrec, idx, 'a')
28 ! write(*,*) '============ ascending first 10'
29 ! do l=1, 10
30 ! write(*, *) a(idx(l))
31 ! enddo
32 ! write(*,*) ' last 10'
33 ! do l=nrec-10, nrec
34 ! write(*, *) a(idx(l))
35 ! enddo
36 ! end
37 
38 
39 !--------------------------------------------------------------
40 
41  subroutine kcsr1idx(a, nrec, idx, ad)
42  implicit none
43 
44  integer nrec
45  real*8 a(nrec) ! input. unchagned
46  integer idx(nrec) ! outut. a(k) is to be moved idx(k)-th position.
47  ! ,that is, a(idx(k)) is the k-th largest or
48  ! smallest among a.
49  character*(*) ad
50 
51  integer j, k, gap, imax, i
52  real*8 x, sf/1.30/
53  logical exch, more
54 
55  gap=nrec
56  more=.true.
57  do i = 1, nrec
58  idx(i) = i
59  enddo
60 
61  do while( more )
62  gap=float(gap)/sf
63  if(gap .le. 0) then
64  gap=1
65  elseif(gap .eq. 9 .or. gap .eq. 10) then
66  gap=11
67  endif
68  imax=nrec - gap
69  exch = .false.
70  do j=1, imax
71  k=j+gap
72  if(ad .eq. 'a') then
73  if(a(idx(j)) .gt. a(idx(k))) then
74  x =idx(j)
75  idx(j) = idx(k)
76  idx(k) = x
77  exch = .true.
78  endif
79  else
80  if(a(idx(j)) .lt. a(idx(k))) then
81  x = idx(j)
82  idx(j) = idx(k)
83  idx(k) = x
84  exch = .true.
85  endif
86  endif
87  enddo
88  more=exch .or. gap .ne. 1
89  enddo
90  end
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 kcsr1idx(a, nrec, idx, ad)
Definition: kcsr1idx.f:42
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