NADCON5-ng  0.0.2
NADCON5 Next Generation Documentation
select2_mod.for
Go to the documentation of this file.
1 c copied from /home/dru/NumRec/Modified/select2.for
2 c> \ingroup core
3 c> \if MANPAGE
4 c> \page select2_mod
5 c> \endif
6 c>
7 c> Function to select an element of a partially filled, but packed multi dimensional array, single 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 c - Like "select" but modified by D. Smith on 7/17/2008
23 c - to allow an "nmax" array given, but which only
24 c - has values in elements 1-n. Maintain the Real*4 nature of arr.
25 
26 c - Finds the "kth" element of an array, "arr", which
27 c - is dimensioned to be "nmax" values long, but which
28 c - only has data in the first "n" cells.
29 
30  INTEGER k,n,nmax
31  REAL*4 select2,arr(nmax)
32  INTEGER i,ir,j,l,mid
33  REAL*4 a,temp
34  l=1
35  ir=n
36 1 if(ir-l.le.1)then
37  if(ir-l.eq.1)then
38  if(arr(ir).lt.arr(l))then
39  temp=arr(l)
40  arr(l)=arr(ir)
41  arr(ir)=temp
42  endif
43  endif
44  select2=arr(k)
45  return
46  else
47  mid=(l+ir)/2
48  temp=arr(mid)
49  arr(mid)=arr(l+1)
50  arr(l+1)=temp
51  if(arr(l+1).gt.arr(ir))then
52  temp=arr(l+1)
53  arr(l+1)=arr(ir)
54  arr(ir)=temp
55  endif
56  if(arr(l).gt.arr(ir))then
57  temp=arr(l)
58  arr(l)=arr(ir)
59  arr(ir)=temp
60  endif
61  if(arr(l+1).gt.arr(l))then
62  temp=arr(l+1)
63  arr(l+1)=arr(l)
64  arr(l)=temp
65  endif
66  i=l+1
67  j=ir
68  a=arr(l)
69 3 continue
70  i=i+1
71  if(arr(i).lt.a)goto 3
72 4 continue
73  j=j-1
74  if(arr(j).gt.a)goto 4
75  if(j.lt.i)goto 5
76  temp=arr(i)
77  arr(i)=arr(j)
78  arr(j)=temp
79  goto 3
80 5 arr(l)=arr(j)
81  arr(j)=a
82  if(j.ge.k)ir=j-1
83  if(j.le.k)l=i
84  endif
85  goto 1
86  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