* This file is part of the GROMACS molecular simulation package.
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team,
- * Copyright (c) 2013, by the GROMACS development team, led by
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013,2014, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
* To help us fund GROMACS development, we humbly ask that you cite
* the research papers on the package. Check out http://www.gromacs.org.
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "gmxpre.h"
-#include <math.h>
-#include "sysstuff.h"
-#include "typedefs.h"
-#include "smalloc.h"
-#include "sysstuff.h"
-#include <errno.h>
-#include "macros.h"
-#include "string2.h"
#include "confio.h"
-#include "vec.h"
-#include "symtab.h"
-#include "futil.h"
+
+#include <errno.h>
+#include <math.h>
+#include <stdio.h>
+
+#include "gromacs/legacyheaders/typedefs.h"
+#include "gromacs/legacyheaders/macros.h"
+#include "gromacs/utility/futil.h"
#include "xdrf.h"
#include "filenm.h"
#include "pdbio.h"
#include "tpxio.h"
#include "trxio.h"
-#include "gmx_fatal.h"
-#include "copyrite.h"
-#include "statutil.h"
-#include "pbc.h"
-#include "mtop_util.h"
+#include "gromacs/legacyheaders/copyrite.h"
+#include "gromacs/topology/mtop_util.h"
#include "gmxfio.h"
+#include "gromacs/fileio/trx.h"
+#include "gromacs/math/vec.h"
+#include "gromacs/pbcutil/pbc.h"
+#include "gromacs/topology/symtab.h"
+#include "gromacs/topology/topology.h"
+#include "gromacs/utility/cstringutil.h"
+#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/smalloc.h"
+
#define CHAR_SHIFT 24
static int read_g96_pos(char line[], t_symtab *symtab,
if (fr->title == NULL)
{
fgets2(line, STRLEN, fp);
- fr->title = strdup(line);
+ fr->title = gmx_strdup(line);
}
bEnd = FALSE;
while (!bEnd && fgets2(line, STRLEN, fp))
{
if ((fgets2 (line, STRLEN, in)) == NULL)
{
- unexpected_eof(infile, i+2);
+ gmx_fatal(FARGS, "Unexpected end of file in file %s at line %d",
+ infile, i+2);
}
if (strlen(line) < 39)
{
/* eventueel controle atomnumber met i+1 */
- /* coordinates (start after residue shit) */
+ /* coordinates (start after residue data) */
ptr = line + 20;
/* Read fixed format */
for (m = 0; m < DIM; m++)
gmx_fio_fclose(in);
}
+static gmx_bool gmx_one_before_eof(FILE *fp)
+{
+ char data[4];
+ gmx_bool beof;
+
+ if ((beof = fread(data, 1, 1, fp)) == 1)
+ {
+ gmx_fseek(fp, -1, SEEK_CUR);
+ }
+ return !beof;
+}
+
gmx_bool gro_next_x_or_v(FILE *status, t_trxframe *fr)
{
t_atoms atoms;
double tt;
int ndec = 0, i;
- if (gmx_eof(status))
+ if (gmx_one_before_eof(status))
{
return FALSE;
}
}
}
-static void write_xyz_conf(const char *outfile, const char *title,
- t_atoms *atoms, rvec *x)
-{
- FILE *fp;
- int i, anr;
- real value;
- char *ptr, *name;
- gmx_atomprop_t aps = gmx_atomprop_init();
-
- fp = gmx_fio_fopen(outfile, "w");
- fprintf(fp, "%3d\n", atoms->nr);
- fprintf(fp, "%s\n", title);
- for (i = 0; (i < atoms->nr); i++)
- {
- anr = atoms->atom[i].atomnumber;
- name = *atoms->atomname[i];
- if (anr == NOTSET)
- {
- if (gmx_atomprop_query(aps, epropElement, "???", name, &value))
- {
- anr = gmx_nint(value);
- }
- }
- if ((ptr = gmx_atomprop_element(aps, anr)) == NULL)
- {
- ptr = name;
- }
- fprintf(fp, "%3s%10.5f%10.5f%10.5f\n", ptr,
- 10*x[i][XX], 10*x[i][YY], 10*x[i][ZZ]);
- }
- gmx_fio_fclose(fp);
- gmx_atomprop_destroy(aps);
-}
-
void write_sto_conf(const char *outfile, const char *title, t_atoms *atoms,
rvec x[], rvec *v, int ePBC, matrix box)
{
write_g96_conf(out, &fr, -1, NULL);
gmx_fio_fclose(out);
break;
- case efXYZ:
- write_xyz_conf(outfile, (strlen(title) > 0) ? title : outfile, atoms, x);
- break;
case efPDB:
case efBRK:
case efENT:
}
}
-static int get_xyz_coordnum(const char *infile)
-{
- FILE *fp;
- int n;
-
- fp = gmx_fio_fopen(infile, "r");
- if (fscanf(fp, "%d", &n) != 1)
- {
- gmx_fatal(FARGS, "Can not read number of atoms from %s", infile);
- }
- gmx_fio_fclose(fp);
-
- return n;
-}
-
-static void read_xyz_conf(const char *infile, char *title,
- t_atoms *atoms, rvec *x)
-{
- FILE *fp;
- int i, n;
- double xx, yy, zz;
- t_symtab *tab;
- char atomnm[32], buf[STRLEN];
-
- snew(tab, 1);
- fp = gmx_fio_fopen(infile, "r");
- fgets2(buf, STRLEN-1, fp);
- if (sscanf(buf, "%d", &n) != 1)
- {
- gmx_fatal(FARGS, "Can not read number of atoms from %s", infile);
- }
- fgets2(buf, STRLEN-1, fp);
- strcpy(title, buf);
- for (i = 0; (i < n); i++)
- {
- fgets2(buf, STRLEN-1, fp);
- if (sscanf(buf, "%s%lf%lf%lf", atomnm, &xx, &yy, &zz) != 4)
- {
- gmx_fatal(FARGS, "Can not read coordinates from %s", infile);
- }
- atoms->atomname[i] = put_symtab(tab, atomnm);
- x[i][XX] = xx*0.1;
- x[i][YY] = yy*0.1;
- x[i][ZZ] = zz*0.1;
- }
- gmx_fio_fclose(fp);
-}
-
void get_stx_coordnum(const char *infile, int *natoms)
{
FILE *in;
*natoms = read_g96_conf(in, infile, &fr, g96_line);
gmx_fio_fclose(in);
break;
- case efXYZ:
- *natoms = get_xyz_coordnum(infile);
- break;
case efPDB:
case efBRK:
case efENT:
case efGRO:
read_whole_conf(infile, title, atoms, x, v, box);
break;
- case efXYZ:
- read_xyz_conf(infile, title, atoms, x);
- break;
case efG96:
fr.title = NULL;
fr.natoms = atoms->nr;