1 c===========================================================================
3 c This file is part of TISEAN
5 c Copyright (c) 1998-2007 Rainer Hegger, Holger Kantz, Thomas Schreiber
7 c TISEAN is free software; you can redistribute it and/or modify
8 c it under the terms of the GNU General Public License as published by
9 c the Free Software Foundation; either version 2 of the License, or
10 c (at your option) any later version.
12 c TISEAN is distributed in the hope that it will be useful,
13 c but WITHOUT ANY WARRANTY; without even the implied warranty of
14 c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 c GNU General Public License for more details.
17 c You should have received a copy of the GNU General Public License
18 c along with TISEAN; if not, write to the Free Software
19 c Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 c===========================================================================
22 c box assisted sorting/ranking utilities
23 c author T. Schreiber (1998) based on earlier versions
24 c===========================================================================
25 subroutine rank(nmax,x,list)
27 parameter(nptr=100000)
28 dimension x(nmax), list(nmax), jptr(0:nptr)
30 call minmax(nmax,x,xmin,xmax)
44 if ((ip.eq.0).or.(xn.le.x(ip))) then
49 if ((ip.gt.0).and.(xn.gt.x(ip))) goto 1
56 2 if (ip.eq.0) goto 40
65 subroutine indexx(nmax,x,list)
66 c make index table using rank
67 dimension x(nmax), list(nmax)
69 call rank(nmax,x,list)
70 call rank2index(nmax,list)
73 subroutine rank2index(nmax,list)
74 c converts a list of ranks into an index table (or vice versa) in place
80 if(list(n).gt.0) goto 20 ! has been put in place already
95 subroutine sort(nmax,x,list)
96 c sort using rank and rank2sort
97 dimension x(nmax), list(nmax)
99 call rank(nmax,x,list)
100 call rank2sort(nmax,x,list)
103 subroutine rank2sort(nmax,x,list)
104 c sort x using list of ranks
105 dimension x(nmax), list(nmax)
110 if(list(n).gt.0) goto 20 ! has been put in place already
125 subroutine index2sort(nmax,x,list)
126 c sort x using list of indices
127 dimension x(nmax), list(nmax)
132 if(list(n).gt.0) goto 20 ! has been put in place already
147 function which(nmax,x,k,list)
148 dimension x(nmax), list(nmax)
150 call indexx(nmax,x,list)