1
C/MEMBR ADD NAME=DSORT,SSI=0
3
subroutine dsort(count,n,index)
6
c dsort sort double precision array,maintaining an index array
9
c subroutine dsort(count,n,index)
11
c double precision count(n)
13
c count : array to be sorted
14
c n :size of count and index
15
c index : array containing on return index of sorted array
18
c quick sort metjod is used
20
c n must be less than 2**(50/2) ! due to lengh of work space mark
22
dimension mark(50),index(n)
23
double precision count(n),av,x
24
c set index array to original order .
28
c check that a trivial case has not been entered .
32
c 'm' is the length of segment which is short enough to enter
33
c the final sorting routine. it may be easily changed.
35
c set up initial values.
40
c if segment is short enough sort with final sorting routine .
42
if((ifka+1).gt.m)goto 70
43
c********* final sorting ***
44
c ( a simple bubble sort )
48
40 if(count(i-1).gt.count(i))goto 60
49
if(count(i-1).lt.count(i))goto 50
50
if(index(i-1).lt.index(i))goto 60
62
c ******* quicksort ********
63
c select the number in the central position in the segment as
64
c the test number.replace it with the number from the segment's
71
c the markers 'i' and 'ifk' are used for the beginning and end
72
c of the section not so far tested against the present value
76
c we alternate between the outer loop that increases i and the
77
c inner loop that reduces ifk, moving numbers and indices as
78
c necessary, until they meet .
80
if(x.lt.count(i))goto 110
81
if(x.gt.count(i))goto 80
82
if(intest.gt.index(i))goto 110
83
80 if(i.ge.ifk)goto 120
89
if(count(ifk).lt.x)goto 100
90
if(count(ifk).gt.x)goto 90
91
if(intest.le.index(ifk))goto 100
92
90 if(i.ge.ifk)goto 130
99
c return the test number to the position marked by the marker
100
c which did not move last. it divides the initial segment into
101
c 2 parts. any element in the first part is less than or equal
102
c to any element in the second part, and they may now be sorted
111
c store the longer subdivision in workspace.
112
140 if((ip-is).gt.(if-ip))goto 150
120
c find the length of the shorter subdivision.
122
if(lngth.le.0)goto 180
123
c if it contains more than one element supply it with workspace .
126
170 if(la.le.0)goto 200
127
c obtain the address of the shortest segment awaiting quicksort