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