~useakat/cfmc/gg_4g_cfmc

« back to all changes in this revision

Viewing changes to mylib/rsort.f

  • Committer: useakat at gmail
  • Date: 2012-10-01 07:45:50 UTC
  • mfrom: (4.1.13 gg_3g_cfmc_dev)
  • Revision ID: useakat@gmail.com-20121001074550-zs09eu30khm4yvyx
independent ver.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
      subroutine rsort_asc(n, a,m)
 
2
c by Yoshitaro Takaesu -Jul/28/2011 @KEK
 
3
 
 
4
      implicit none
 
5
      
 
6
      integer i,j
 
7
      integer n
 
8
      integer m(n)
 
9
      real*8 a(n)
 
10
 
 
11
      integer mini,tmp
 
12
      real*8 min
 
13
 
 
14
      do i = 1,n
 
15
         m(i) = i
 
16
      enddo
 
17
      do i = 1,n-1
 
18
         mini = i
 
19
         min = a(i)
 
20
         do j = i+1,n
 
21
            if( a(j) < min ) then
 
22
               min = a(j)
 
23
               mini = j
 
24
            endif
 
25
         enddo
 
26
         if( mini.ne.i ) then
 
27
            a(mini) = a(i)
 
28
            a(i) = min
 
29
            tmp = m(mini)
 
30
            m(mini) = m(i)
 
31
            m(i) = tmp
 
32
         endif
 
33
      enddo
 
34
 
 
35
      end
 
36
 
 
37
 
 
38
      subroutine rsort_des(n, a,m)
 
39
c by Yoshitaro Takaesu -Jul/28/2011 @KEK
 
40
 
 
41
      implicit none
 
42
      
 
43
      integer i,j
 
44
      integer n
 
45
      integer m(n)
 
46
      real*8 a(n)
 
47
 
 
48
      integer maxi,tmp
 
49
      real*8 max
 
50
 
 
51
      do i = 1,n
 
52
         m(i) = i
 
53
      enddo
 
54
      do i = 1,n-1
 
55
         maxi = i
 
56
         max = a(i)
 
57
         do j = i+1,n
 
58
            if( a(j) > max ) then
 
59
               max = a(j)
 
60
               maxi = j
 
61
            endif
 
62
         enddo
 
63
         if( maxi.ne.i ) then
 
64
            a(maxi) = a(i)
 
65
            a(i) = max
 
66
            tmp = m(maxi)
 
67
            m(maxi) = m(i)
 
68
            m(i) = tmp
 
69
         endif
 
70
      enddo
 
71
 
 
72
      end