changed reading hint
[gromacs/adressmacs.git] / src / mdlib / wnblist.c
blobcea7be9d0131d696db036c5605e60f0cf5fe160f
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 2.0
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * Please refer to:
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
23 * or e-mail to:
24 * gromacs@chem.rug.nl
26 * And Hey:
27 * GRowing Old MAkes el Chrono Sweat
29 static char *SRCID_wnblist_c = "$Id$";
31 #include <stdio.h>
32 #include <string.h>
33 #include "string2.h"
34 #include "force.h"
35 #include "smalloc.h"
36 #include "wnblist.h"
37 #include "fatal.h"
38 #include "macros.h"
39 #include "futil.h"
41 #define header "Neighborlist:"
43 static void write_nblist(FILE *out,t_nblist *nblist)
45 int i,j,j0,k,i_atom,jid;
47 fprintf(out,"nri=%d nrj=%d\n",nblist->nri,nblist->nrj);
48 for(i=0; i<nblist->nri; i++) {
49 fprintf(out,"i: %d, shift: %d, gid: %d\n",
50 nblist->iinr[i],nblist->shift[i],nblist->gid[i]);
51 for(j=nblist->jindex[i]; (j<nblist->jindex[i+1]); j++)
52 fprintf(out," j: %d\n",nblist->jjnr[j]);
54 fflush(out);
57 void read_nblist(FILE *in,FILE *log,int **mat,int natoms)
59 char buf[256];
60 int i,ii,j,nnbl,full,icmp,nri;
61 int iatom,nrj,nj,shift;
63 do {
64 if (fgets2(buf,255,in) == NULL)
65 fatal_error(0,"EOF when looking for '%s' in logfile",header);
66 } while (strstr(buf,header) == NULL);
67 if (fscanf(in,"%d",&nnbl) != 1)
68 fatal_error(0,"Not enough arguments read line %d",__LINE__);
70 for(i=0; (i<nnbl); i++) {
71 if (fscanf(in,"%*s%d",&nri) != 1)
72 fatal_error(0,"Not enough arguments read line %d",__LINE__);
73 nrj = 0;
74 for(ii=0; (ii<nri); ii++) {
75 if (fscanf(in,"%*s%d%*s%d%*s%d",&iatom,&nj,&shift) != 3)
76 fatal_error(0,"Not enough arguments read line %d",__LINE__);
77 if ((iatom < 0) || (iatom >= natoms))
78 fatal_error(0,"iatom = %d (max %d)\n",iatom,natoms);
79 nrj+=nj;
80 fscanf(in,"%*s%*s");
81 for(i=0; (i<nj); i++) {
82 if (fscanf(in,"%d",&j) != 1)
83 fatal_error(0,"Not enough arguments read line %d",__LINE__);
84 if ((j < 0) || (j >= natoms))
85 fatal_error(0,"iatom = %d (max %d)\n",iatom,natoms);
86 if (mat[iatom][j] != 0)
87 fprintf(log,"mat[%d][%d] changing from %d to %d\n",
88 i,j,mat[iatom][j],shift+1);
89 mat[iatom][j] = shift+1;
92 fprintf(log,"nri = %d nrj = %d\n",nri,nrj);
96 void dump_nblist(FILE *out,t_forcerec *fr,int nDNL)
98 int i;
100 fprintf(out,"%s\n",header);
102 for(i=0; (i<eNL_NR); i++)
103 write_nblist(out,&fr->nlist_sr[i]);