Mac binaries
[jabaws.git] / website / archive / binaries / mac / src / disembl / Tisean_3.0.1 / source_c / routines / find_neighbors.c
1 /*
2  *   This file is part of TISEAN
3  *
4  *   Copyright (c) 1998-2007 Rainer Hegger, Holger Kantz, Thomas Schreiber
5  *
6  *   TISEAN is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   TISEAN is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with TISEAN; if not, write to the Free Software
18  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20 /*Author: Rainer Hegger Last modified: March 1st, 1998 */
21 #include <math.h>
22
23 unsigned long find_neighbors(double *s,long **box,long *list,double *x,
24                              unsigned long l,unsigned int bs,unsigned int dim,
25                              unsigned int del,double eps,unsigned long *flist)
26 {
27   unsigned long nf=0;
28   int i,i1,i2,j,j1,k,k1;
29   int ib=bs-1;
30   long element;
31   double dx;
32   
33   k=(int)((dim-1)*del);
34   i=(int)(x[-k]/eps)&ib;
35   j=(int)(x[0]/eps)&ib;
36   
37   for (i1=i-1;i1<=i+1;i1++) {
38     i2=i1&ib;
39     for (j1=j-1;j1<=j+1;j1++) {
40       element=box[i2][j1&ib];
41       while (element != -1) {
42         for (k=0;k<dim;k++) {
43           k1= -k*(int)del;
44           dx=fabs(x[k1]-s[element+k1]);
45           if (dx > eps)
46             break;
47         }
48         if (k == dim)
49           flist[nf++]=element;
50         element=list[element];
51       }
52     }
53   }
54   return nf;
55 }