All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
pxsorv.f
Go to the documentation of this file.
1 CDECK ID>, PXSORV.
2  SUBROUTINE pxsorv (ISZ,ARY,KIX,COPT)
3 *.*********************************************************
4 *. ------
5 *. PXSORV
6 *. ------
7 *. SOURCE: HERWIG (B.Webber,G.Marchesini)
8 *. Sort a real array into assending order based on
9 *. the magnitude of its elements; provide an
10 *. integer "index array" which specifies the ordering
11 *. of the array.
12 *. Usage :
13 *.
14 *. PARAMETER (NDIM=1.or.more)
15 *. REAL ARY (NDIM)
16 *. INTEGER KIX (NDIM)
17 *. INTEGER ISIZ
18 *. CHARACTER*1 COPT
19 *.
20 *. ISIZ = 1.to.NDIM
21 *. COPT = 'I'
22 *. CALL PXSORV (ISIZ,ARY,KIX,COPT)
23 *.
24 *. INPUT : ISIZ The dimension of the input array
25 *. INPUT : ARY The input array
26 *. OUTPUT : KIX The index array
27 *. CONTROL : COPT Control of output vector ARY
28 *. = ' ' : return sorted ARY and index array KIX
29 *. = 'I' : return index array KIX only, don't
30 *. modify ARY
31 *.
32 *.*********************************************************
33  IMPLICIT NONE
34  INTEGER mxsz
35  parameter(mxsz=500)
36  INTEGER isz,ix,jx
37  INTEGER kix (*),il (mxsz),ir (mxsz)
38  REAL ary (*),bry (mxsz)
39  CHARACTER*1 copt
40  IF (isz.GT.mxsz) THEN
41  WRITE (6,fmt='('' PXSORT: Error,'',
42  + '' Max array size ='',I6)') mxsz
43  kix(1) = -1
44  go to 990
45  END IF
46  il(1) = 0
47  ir(1) = 0
48  DO 10 ix = 2,isz
49  il(ix) = 0
50  ir(ix) = 0
51  jx = 1
52  2 IF (ary(ix).GT.ary(jx)) go to 5
53  3 IF (il(jx).EQ.0) go to 4
54  jx = il(jx)
55  go to 2
56  4 ir(ix) = -jx
57  il(jx) = ix
58  go to 10
59  5 IF (ir(jx).LE.0) go to 6
60  jx = ir(jx)
61  go to 2
62  6 ir(ix) = ir(jx)
63  ir(jx) = ix
64  10 CONTINUE
65  ix = 1
66  jx = 1
67  go to 8
68  20 jx = il(jx)
69  8 IF (il(jx).GT.0) go to 20
70  9 kix(ix) = jx
71  bry(ix) = ary(jx)
72  ix = ix + 1
73  IF (ir(jx)) 12,30,13
74  13 jx = ir(jx)
75  go to 8
76  12 jx = -ir(jx)
77  go to 9
78  30 IF (copt.EQ.'I') RETURN
79  DO 31 ix = 1,isz
80  31 ary(ix) = bry(ix)
81  990 RETURN
82  END
subroutine pxsorv(ISZ, ARY, KIX, COPT)
Definition: pxsorv.f:2