NADCON5-ng  0.0.1
NADCON5 Next Generation
select2_dbl.for
Go to the documentation of this file.
1 c copied from /home/dru/NumRec/Double/select2.for
2 c> \ingroup core
3 c> Function to select an element of a partially filled, but packed multi dimensional array, double precision
4 c>
5 c> Finds the "kth" element of an array, "arr", which
6 c> is dimensioned to be "nmax" values long, but which
7 c> only has data in the first "n" cells.
8 c>
9 c> ## Changelog
10 c>
11 c> ### 7/17/2008:
12 c> Like "select2" but modified by D. Smith
13 c> to allow an "nmax" array given, but which only
14 c> has values in elements 1-n, and to have "arr"
15 c> be Integer*2
16 c>
17  FUNCTION select2(k,n,arr,nmax)
18 
19 c - Like "select" but modified by D. Smith on 7/17/2008
20 c - to allow an "nmax" array given, but which only
21 c - has values in elements 1-n
22 
23  INTEGER k,n,nmax
24  REAL*8 select2,arr(nmax)
25  INTEGER i,ir,j,l,mid
26  REAL*8 a,temp
27  l=1
28  ir=n
29 1 if(ir-l.le.1)then
30  if(ir-l.eq.1)then
31  if(arr(ir).lt.arr(l))then
32  temp=arr(l)
33  arr(l)=arr(ir)
34  arr(ir)=temp
35  endif
36  endif
37  select2=arr(k)
38  return
39  else
40  mid=(l+ir)/2
41  temp=arr(mid)
42  arr(mid)=arr(l+1)
43  arr(l+1)=temp
44  if(arr(l+1).gt.arr(ir))then
45  temp=arr(l+1)
46  arr(l+1)=arr(ir)
47  arr(ir)=temp
48  endif
49  if(arr(l).gt.arr(ir))then
50  temp=arr(l)
51  arr(l)=arr(ir)
52  arr(ir)=temp
53  endif
54  if(arr(l+1).gt.arr(l))then
55  temp=arr(l+1)
56  arr(l+1)=arr(l)
57  arr(l)=temp
58  endif
59  i=l+1
60  j=ir
61  a=arr(l)
62 3 continue
63  i=i+1
64  if(arr(i).lt.a)goto 3
65 4 continue
66  j=j-1
67  if(arr(j).gt.a)goto 4
68  if(j.lt.i)goto 5
69  temp=arr(i)
70  arr(i)=arr(j)
71  arr(j)=temp
72  goto 3
73 5 arr(l)=arr(j)
74  arr(j)=a
75  if(j.ge.k)ir=j-1
76  if(j.le.k)l=i
77  endif
78  goto 1
79  END
real *8 function select2(k, n, arr, nmax)
Function to select an element of a partially filled, but packed multi dimensional array...
Definition: select2_dbl.for:18