4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * GRowing Old MAkes el Chrono Sweat
29 static char *SRCID_sorting_c
= "$Id$";
36 /*****************************************************************************
38 * Block sorting on coordinates *
40 *****************************************************************************/
42 static rvec
*make_xblock(t_block
*block
,rvec x
[])
51 for (j
=0; j
<DIM
; j
++) xblock
[i
][j
]=0.0;
52 for (j
=block
->index
[i
]; j
<(int)(block
->index
[i
+1]); j
++)
53 for (k
=0; k
<DIM
; k
++) xblock
[i
][k
]+=x
[j
][k
];
54 n
=block
->index
[i
+1]-block
->index
[i
];
55 for (k
=0; k
<DIM
; k
++) xblock
[i
][k
]/=n
;
60 static rvec
*xblock
; /* just global to bcomp1, used in qsort */
62 static int bomp1(const void *p1
,const void *p2
)
69 if (xblock
[i1
][i
]<xblock
[i2
][i
]) return -1;
70 else if (xblock
[i1
][i
]>xblock
[i2
][i
]) return 1;
74 void sort_xblock(t_block
*block
,rvec x
[],int renum
[])
80 xblock
=make_xblock(block
,x
);
81 for (i
=0; i
<nr
; i
++) invnum
[i
]=i
;
82 qsort((void *)invnum
,nr
,(size_t)sizeof(invnum
[0]),bomp1
);
83 for (i
=0; i
<nr
; i
++) renum
[invnum
[i
]]=i
;
88 /*****************************************************************************
92 *****************************************************************************/
94 static int bcomp2(const void *p1
,const void *p2
)
98 if ((((atom_id
*)p1
)[0])!=(((atom_id
*)p2
)[0]))
99 done
=((((atom_id
*)p1
)[0])-(((atom_id
*)p2
)[0]));
101 done
=((((atom_id
*)p1
)[1])-(((atom_id
*)p2
)[1]));
103 printf("bcomp2: [%d,%d] with [%d,%d] result %d\n",
104 ((atom_id
*)p1
)[0],((atom_id
*)p1
)[1],
105 ((atom_id
*)p2
)[0],((atom_id
*)p2
)[1],done
);
110 void sort_bond_list(t_bond bonds
[],int nr
)
112 qsort((void *)bonds
,nr
,(size_t)sizeof(bonds
[0]),bcomp2
);