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 utilities for neighbour search
23 c see H. Kantz, T. Schreiber, Nonlinear Time Series Analysis, Cambridge
24 c University Press (1997)
25 c author T. Schreiber (1999)
26 c last modified H. Kantz Feb.2007
27 c===========================================================================
28 subroutine base(nmax,y,id,m,jh,jpntr,eps)
29 parameter(im=100,ii=100000000)
30 dimension y(nmax),jh(0:im*im),jpntr(nmax)
34 do 20 n=(m-1)*id+1,nmax ! make histogram
35 i=mod(int(y(n)/eps)+ii,im)
36 if(m.gt.1) i=im*i+mod(int(y(n-(m-1)*id)/eps)+ii,im)
38 do 30 i=1,im*im ! accumulate it
39 30 jh(i)=jh(i)+jh(i-1)
40 do 40 n=(m-1)*id+1,nmax ! fill list of pointers
42 i=mod(int(y(n)/eps)+ii,im)
43 if(m.gt.1) i=im*i+mod(int(y(n-(m-1)*id)/eps)+ii,im)
48 subroutine neigh(nmax,y,x,n,nlast,id,m,jh,jpntr,eps,nlist,nfound)
49 parameter(im=100,ii=100000000)
50 dimension y(nmax),x(nmax),jh(0:im*im),jpntr(nmax),nlist(nmax)
57 kk=int(y(n-(m-1)*id)/eps)
58 do 10 j=jj-1,jj+1 ! scan neighbouring boxes
59 do 20 k=kk-kloop,kk+kloop
61 if(m.gt.1) jk=im*jk+mod(k+ii,im)
62 do 30 ip=jh(jk+1),jh(jk)+1,-1 ! this is in time order
64 if(np.gt.nlast) goto 20
66 40 if(abs(y(n-i*id)-x(np-i*id)).ge.eps) goto 30
68 nlist(nfound)=np ! make list of neighbours
74 c versions for multivariate series
75 c author T. Schreiber (1999)
77 subroutine mbase(nmax,mmax,nxx,y,id,m,jh,jpntr,eps)
78 parameter(im=100,ii=100000000)
79 dimension y(nxx,mmax),jh(0:im*im),jpntr(nmax)
82 call base(nmax,y,id,m,jh,jpntr,eps)
88 do 20 n=(mt-1)*id+1,nmax ! make histogram
89 i=im*mod(int(y(n,1)/eps)+ii,im)+mod(int(y(n,mmax)/eps)+ii,im)
91 do 30 i=1,im*im ! accumulate it
92 30 jh(i)=jh(i)+jh(i-1)
93 do 40 n=(mt-1)*id+1,nmax ! fill list of pointers
94 i=im*mod(int(y(n,1)/eps)+ii,im)+mod(int(y(n,mmax)/eps)+ii,im)
99 subroutine mneigh(nmax,mmax,nxx,y,n,nlast,id,m,jh,jpntr,eps,
101 parameter(im=100,ii=100000000)
102 dimension y(nxx,mmax),jh(0:im*im),jpntr(nmax),nlist(nmax)
105 call neigh(nmax,y,y,n,nlast,id,m,jh,jpntr,eps,nlist,nfound)
111 kk=int(y(n,mmax)/eps)
112 do 10 j=jj-1,jj+1 ! scan neighbouring boxes
114 jk=im*mod(j+ii,im)+mod(k+ii,im)
115 do 30 ip=jh(jk+1),jh(jk)+1,-1 ! this is in time order
117 if(np.gt.nlast) goto 20
122 if(mcount.gt.m) goto 1
123 40 if(abs(y(n-i*id,is)-y(np-i*id,is)).ge.eps) goto 30
125 nlist(nfound)=np ! make list of neighbours
130 c>---------------------------------------------------------------------
131 c modified version for multivariate series
132 c author H. Kantz (2004)
134 subroutine mneigh2(nmax,mdim,y,nx,vx,jh,jpntr,eps,
137 c search neighbours for vx among the set of all y's
138 c multivariate: mmax: spatial dimension
139 c no additional delay!
140 parameter(im=100,ii=100000000)
141 dimension y(nx,mdim),jh(0:im*im),jpntr(nmax),nlist(nmax)
147 do 10 j=jj-1,jj+1 ! scan neighbouring boxes
149 jk=im*mod(j+ii,im)+mod(k+ii,im)
150 do 30 ip=jh(jk+1),jh(jk)+1,-1 ! this is in time order
152 c if(np.gt.nlast) goto 20
155 40 if(abs(vx(is)-y(np,is)).ge.eps) goto 30
157 nlist(nfound)=np ! make list of neighbours
163 subroutine mbase2(nmax,mmax,nxx,y,jh,jpntr,eps)
164 parameter(im=100,ii=100000000)
165 dimension y(nxx,mmax),jh(0:im*im),jpntr(nmax)
168 call base(nmax,y,id,m,jh,jpntr,eps)
173 do 20 n=1,nmax ! make histogram
174 i=im*mod(int(y(n,1)/eps)+ii,im)+mod(int(y(n,mmax)/eps)+ii,im)
176 do 30 i=1,im*im ! accumulate it
177 30 jh(i)=jh(i)+jh(i-1)
178 do 40 n=(mmax-1)*id+1,nmax ! fill list of pointers
179 i=im*mod(int(y(n,1)/eps)+ii,im)+mod(int(y(n,mmax)/eps)+ii,im)