NADCON5-ng  0.0.1
NADCON5 Next Generation
indexxi.for
Go to the documentation of this file.
1 c> \ingroup core
2 c> Subroutine to perform ?? indexing on integer data
3 c>
4 c> \param[in] n number of iterations (rows?)
5 c> \param[in] nd array and index dimensions
6 c> \param[in] arr input data array
7 c> \param[out] indx index out
8 c>
9 c> ## Changelog
10 c>
11 c> ### 2/5/2013:
12 c> Modified by D. Smith. Arr has been
13 c> changed to integer*4. And like other versions
14 c> of "indexx" which I've modified,
15 c> I allow indx and arr to
16 c> be DIMENSIONED differently than the number of good
17 c> values they contain
18 c>
19  SUBROUTINE indexxi(n,nd,arr,indx)
20 
21 c> Modified by D. Smith, 2/5/2013 . Arr has been
22 c> changed to integer*4. And like other versions
23 c> of "indexx" which I've modified,
24 c> I allow indx and arr to
25 c> be DIMENSIONED differently than the number of good
26 c> values they contain
27 
28  integer nd
29  INTEGER n,indx(nd),M,NSTACK
30 cDAS REAL*4 arr(nd)
31  integer*4 arr(nd)
32  parameter(m=7,nstack=50)
33  INTEGER i,indxt,ir,itemp,j,jstack,k,l,istack(nstack)
34 cDAS REAL*4 a
35  integer*4 a
36 
37  do 11 j=1,n
38  indx(j)=j
39 11 continue
40  jstack=0
41  l=1
42  ir=n
43 1 if(ir-l.lt.m)then
44  do 13 j=l+1,ir
45  indxt=indx(j)
46  a=arr(indxt)
47  do 12 i=j-1,1,-1
48  if(arr(indx(i)).le.a)goto 2
49  indx(i+1)=indx(i)
50 12 continue
51  i=0
52 2 indx(i+1)=indxt
53 13 continue
54  if(jstack.eq.0)return
55  ir=istack(jstack)
56  l=istack(jstack-1)
57  jstack=jstack-2
58  else
59  k=(l+ir)/2
60  itemp=indx(k)
61  indx(k)=indx(l+1)
62  indx(l+1)=itemp
63  if(arr(indx(l+1)).gt.arr(indx(ir)))then
64  itemp=indx(l+1)
65  indx(l+1)=indx(ir)
66  indx(ir)=itemp
67  endif
68  if(arr(indx(l)).gt.arr(indx(ir)))then
69  itemp=indx(l)
70  indx(l)=indx(ir)
71  indx(ir)=itemp
72  endif
73  if(arr(indx(l+1)).gt.arr(indx(l)))then
74  itemp=indx(l+1)
75  indx(l+1)=indx(l)
76  indx(l)=itemp
77  endif
78  i=l+1
79  j=ir
80  indxt=indx(l)
81  a=arr(indxt)
82 3 continue
83  i=i+1
84  if(arr(indx(i)).lt.a)goto 3
85 4 continue
86  j=j-1
87  if(arr(indx(j)).gt.a)goto 4
88  if(j.lt.i)goto 5
89  itemp=indx(i)
90  indx(i)=indx(j)
91  indx(j)=itemp
92  goto 3
93 5 indx(l)=indx(j)
94  indx(j)=indxt
95  jstack=jstack+2
96  if(jstack.gt.nstack)pause 'NSTACK too small in indexx'
97  if(ir-i+1.ge.j-l)then
98  istack(jstack)=ir
99  istack(jstack-1)=i
100  ir=j-1
101  else
102  istack(jstack)=j-1
103  istack(jstack-1)=l
104  l=i
105  endif
106  endif
107  goto 1
108  END
subroutine indexxi(n, nd, arr, indx)
Subroutine to perform ?? indexing on integer data.
Definition: indexxi.for:20