Fix compile error for IBM VMX on ppc64
[gromacs/AngularHB.git] / src / contrib / compnl.c
blob0f1e4e4d83254f9c7106097791d89ae10a95b30e
1 /*
2 *
3 * This source code is part of
4 *
5 * G R O M A C S
6 *
7 * GROningen MAchine for Chemical Simulations
8 *
9 * VERSION 3.2.0
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
32 * And Hey:
33 * GROwing Monsters And Cloning Shrimps
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
39 #include "ns.h"
40 #include "gromacs/utility/smalloc.h"
41 #include "wnblist.h"
42 #include "gromacs/utility/futil.h"
43 #include "macros.h"
44 #include "gromacs/commandline/pargs.h"
45 #include "copyrite.h"
46 #include "gromacs/fileio/confio.h"
47 #include "gromacs/pbcutil/pbc.h"
48 #include "gromacs/math/vec.h"
50 int main(int argc,char *argv[])
52 static char *desc[] = {
53 "[TT]compnl[tt] compares two neighborlists as generated by [TT]mdrun[tt]",
54 "in the log file, when the environment variable DUMPNL is set to",
55 "a number larger than 0. [TT]compnl[tt] is mainly used for debugging the",
56 "[TT]mdrun[tt] internals and not for end-users."
58 FILE *in,*out;
59 int i,j,nmiss,mod;
60 char **fn,title[256];
61 int ***mat,nnb;
62 real mb;
63 gmx_bool bConf;
64 rvec *x = NULL;
65 rvec dx;
66 matrix box;
67 t_atoms atoms;
68 t_pbc pbc;
70 t_filenm fnm[] = {
71 { efLOG, "-f1", NULL, ffREAD },
72 { efLOG, "-f2", NULL, ffREAD },
73 { efOUT, "-o", "compnl", ffWRITE },
74 { efSTX, "-c", NULL, ffOPTRD }
76 #define NFILE asize(fnm)
77 static int natoms=648;
78 static gmx_bool bSymm=TRUE;
79 static t_pargs pa[] = {
80 { "-nat", FALSE, etINT, { &natoms }, "Number of atoms" },
81 { "-symm", FALSE, etBOOL,{ &bSymm }, "Symmetrize the matrices" },
84 CopyRight(stderr,argv[0]);
85 parse_common_args(&argc,argv,0,NFILE,fnm,asize(pa),pa,
86 asize(desc),desc,0,NULL);
88 bConf = (opt2bSet("-c",NFILE,fnm));
89 if (bConf) {
90 get_stx_coordnum (opt2fn("-c",NFILE,fnm),&natoms);
91 init_t_atoms(&atoms,natoms,FALSE);
92 snew(x,natoms);
93 read_stx_conf(opt2fn("-c",NFILE,fnm),title,&atoms,x,NULL,box);
94 set_pbc(&pbc,box);
96 snew(fn,2);
97 fn[0] = opt2fn("-f1",NFILE,fnm);
98 fn[1] = opt2fn("-f2",NFILE,fnm);
100 snew(mat,2);
101 out = gmx_fio_fopen(ftp2fn(efOUT,NFILE,fnm),"w");
102 mb = sizeof(int)*sqr(natoms/1024.0);
103 for(i=0; (i<2); i++) {
104 in = gmx_fio_fopen(fn[i],"r");
105 fprintf(stderr,"Reading %s\n",fn[i]);
106 fprintf(out, "Reading %s\n",fn[i]);
107 fprintf(stderr,"Going to allocate %.0f Mb of memory\n",mb);
108 fprintf(out, "Going to allocate %.0f Mb of memory\n",mb);
109 snew(mat[i],natoms);
110 for(j=0; (j<natoms); j++)
111 snew(mat[i][j],natoms);
112 nnb = read_nblist(in,out,mat[i],natoms,bSymm);
113 gmx_fio_fclose(in);
114 fprintf(stderr,"Interaction matrix %d has %d entries\n",i,nnb);
115 fprintf(out, "Interaction matrix %d has %d entries\n",i,nnb);
117 fprintf(stderr,"Comparing Interaction Matrices\n");
118 mod=1;
119 nmiss = 0;
120 for(i=0; (i<natoms); i+=mod) {
121 for(j=0; (j<natoms); j+=mod) {
122 if (mat[0][i][j] != mat[1][i][j]) {
123 fprintf(out,"i: %5d, j: %5d, shift[%s]: %3d, shift[%s]: %3d",
124 i,j,fn[0],mat[0][i][j]-1,fn[1],mat[1][i][j]-1);
125 if (bConf) {
126 pbc_dx(&pbc,x[i],x[j],dx);
127 fprintf(out," dist: %8.3f\n",norm(dx));
129 else
130 fprintf(out,"\n");
131 nmiss++;
135 fprintf(out,"There were %d mismatches\n",nmiss);
136 fprintf(out,"Done.\n");
137 gmx_fio_fclose(out);
138 fprintf(stderr,"There were %d mismatches\n",nmiss);
139 fprintf(stderr,"Finished\n");
141 gmx_thanx(stdout);
143 return 0;