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===========================================================================
27
c Modified: Piotr Held <pjheld@gmail.com> (2015).
28
c This function is based on neigh.f of TISEAN 3.0.1 https://github.com/heggus/Tisean"
29
c===========================================================================
30
subroutine base(nmax,y,id,m,jh,jpntr,eps)
34
parameter (im = 100, ii = 100000000)
36
c -- input variables --
42
integer*4 jh(0:im*im),jpntr(nmax)
49
do 20 n=(m-1)*id+1,nmax ! make histogram
50
i=mod(int(y(n)/eps)+ii,im)
51
if(m.gt.1) i=im*i+mod(int(y(n-(m-1)*id)/eps)+ii,im)
53
do 30 i=1,im*im ! accumulate it
54
30 jh(i)=jh(i)+jh(i-1)
55
do 40 n=(m-1)*id+1,nmax ! fill list of pointers
57
i=mod(int(y(n)/eps)+ii,im)
58
if(m.gt.1) i=im*i+mod(int(y(n-(m-1)*id)/eps)+ii,im)
62
c>-------------------------------------------------------------
63
subroutine neigh(nmax,y,x,n,nlast,id,m,jh,jpntr,eps,nlist,nfound)
67
parameter (im = 100, ii = 100000000)
69
c -- input variables --
70
integer*4 nmax, id, m, nfound
74
real*8 y(nmax), x(nmax)
75
integer*4 jh(0:im*im),jpntr(nmax), nlist(nmax)
78
integer*4 i, j, n, np, k, kk, kloop, jk, ip, jj, nlast
85
kk=int(y(n-(m-1)*id)/eps)
86
do 10 j=jj-1,jj+1 ! scan neighbouring boxes
87
do 20 k=kk-kloop,kk+kloop
89
if(m.gt.1) jk=im*jk+mod(k+ii,im)
90
do 30 ip=jh(jk+1),jh(jk)+1,-1 ! this is in time order
92
if(np.gt.nlast) goto 20
94
40 if(abs(y(n-i*id)-x(np-i*id)).ge.eps) goto 30
96
nlist(nfound)=np ! make list of neighbours
102
c versions for multivariate series
103
c author T. Schreiber (1999)
105
subroutine mbase(nmax,mmax,nxx,y,id,m,jh,jpntr,eps)
109
parameter (im = 100, ii = 100000000)
111
c -- input variables --
112
integer*4 nmax, id, m, mmax, nxx
117
integer*4 jh(0:im*im), jpntr(nmax)
123
call base(nmax,y,id,m,jh,jpntr,eps)
129
do 20 n=(mt-1)*id+1,nmax ! make histogram
130
i=im*mod(int(y(n,1)/eps)+ii,im)+mod(int(y(n,mmax)/eps)+ii,im)
132
do 30 i=1,im*im ! accumulate it
133
30 jh(i)=jh(i)+jh(i-1)
134
do 40 n=(mt-1)*id+1,nmax ! fill list of pointers
135
i=im*mod(int(y(n,1)/eps)+ii,im)+mod(int(y(n,mmax)/eps)+ii,im)
139
c>--------------------------------------------------------------
140
subroutine mneigh(nmax,mmax,nxx,y,n,nlast,id,m,jh,jpntr,eps,
145
parameter (im = 100, ii = 100000000)
147
c -- input variables --
148
integer*4 nmax, mmax, nxx, id, m, nfound
153
integer*4 jh(0:im*im),jpntr(nmax), nlist(nmax)
156
integer*4 i, j, n, np, k, kk, jk, ip, jj, nlast, is, mcount
160
call neigh(nmax,y,y,n,nlast,id,m,jh,jpntr,eps,nlist,nfound)
166
kk=int(y(n,mmax)/eps)
167
do 10 j=jj-1,jj+1 ! scan neighbouring boxes
169
jk=im*mod(j+ii,im)+mod(k+ii,im)
170
do 30 ip=jh(jk+1),jh(jk)+1,-1 ! this is in time order
172
if(np.gt.nlast) goto 20
177
if(mcount.gt.m) goto 1
178
40 if(abs(y(n-i*id,is)-y(np-i*id,is)).ge.eps) goto 30
180
nlist(nfound)=np ! make list of neighbours
185
c>---------------------------------------------------------------------
186
c modified version for multivariate series
187
c author H. Kantz (2004)
189
subroutine mneigh2(nmax,mdim,y,nx,vx,jh,jpntr,eps,
192
c search neighbours for vx among the set of all y's
193
c multivariate: mmax: spatial dimension
194
c no additional delay!
198
parameter (im = 100, ii = 100000000)
200
c -- input variables --
201
integer*4 nmax, mdim, nx, nfound
205
real*8 y(nx,mdim), vx(mdim)
206
integer*4 jh(0:im*im), jpntr(nmax), nlist(nmax)
209
integer*4 j, np, k, kk, jk, ip, jj, is, mcount
214
do 10 j=jj-1,jj+1 ! scan neighbouring boxes
216
jk=im*mod(j+ii,im)+mod(k+ii,im)
217
do 30 ip=jh(jk+1),jh(jk)+1,-1 ! this is in time order
219
c if(np.gt.nlast) goto 20
222
40 if(abs(vx(is)-y(np,is)).ge.eps) goto 30
224
nlist(nfound)=np ! make list of neighbours
229
c>---------------------------------------------------------------------
230
subroutine mbase2(nmax,mmax,nxx,y,jh,jpntr,eps)
235
parameter (im = 100, ii = 100000000)
237
c -- input variables --
238
integer*4 nmax, id, m, mmax, nxx
243
integer*4 jh(0:im*im), jpntr(nmax)
249
call base(nmax,y,id,m,jh,jpntr,eps)
254
do 20 n=1,nmax ! make histogram
255
i=im*mod(int(y(n,1)/eps)+ii,im)+mod(int(y(n,mmax)/eps)+ii,im)
257
do 30 i=1,im*im ! accumulate it
258
30 jh(i)=jh(i)+jh(i-1)
259
do 40 n=(mmax-1)*id+1,nmax ! fill list of pointers
260
i=im*mod(int(y(n,1)/eps)+ii,im)+mod(int(y(n,mmax)/eps)+ii,im)