#include "confio.h"
-#include <errno.h>
-#include <math.h>
-#include <stdio.h>
+#include <cerrno>
+#include <cmath>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/fileio/filenm.h"
#include "gromacs/fileio/gmxfio.h"
bEnd = FALSE;
while (!bEnd && fgets2(line, STRLEN, fp))
{
- bEnd = (strncmp(line, "END", 3) == 0);
+ bEnd = (std::strncmp(line, "END", 3) == 0);
if (!bEnd && (line[0] != '#'))
{
if (sscanf(line+shift, "%15lf%15lf%15lf", &db1, &db2, &db3) != 3)
{
while (!fr->bTitle && fgets2(line, STRLEN, fp))
{
- fr->bTitle = (strcmp(line, "TITLE") == 0);
+ fr->bTitle = (std::strcmp(line, "TITLE") == 0);
}
if (fr->title == NULL)
{
bEnd = FALSE;
while (!bEnd && fgets2(line, STRLEN, fp))
{
- bEnd = (strcmp(line, "END") == 0);
+ bEnd = (std::strcmp(line, "END") == 0);
}
fgets2(line, STRLEN, fp);
}
bFinished = FALSE;
do
{
- bTime = (strcmp(line, "TIMESTEP") == 0);
- bAtoms = (strcmp(line, "POSITION") == 0);
+ bTime = (std::strcmp(line, "TIMESTEP") == 0);
+ bAtoms = (std::strcmp(line, "POSITION") == 0);
bPos = (bAtoms || (strcmp(line, "POSITIONRED") == 0));
- bVel = (strncmp(line, "VELOCITY", 8) == 0);
- bBox = (strcmp(line, "BOX") == 0);
+ bVel = (std::strncmp(line, "VELOCITY", 8) == 0);
+ bBox = (std::strcmp(line, "BOX") == 0);
if (bTime)
{
if (!fr->bTime && !fr->bX)
t_symtab *symtab = NULL;
FILE *fp;
char word[STRLEN], buf[STRLEN];
- int natoms, level, npar, r, nprop, p, i, m, molnr;
+ int level, r, nprop, p, i, m, molnr;
int prop[32];
double d;
gmx_bool bFoundParticles, bFoundProp, bFoundVariable, bMol;
level = 0;
while ((r = get_espresso_word(fp, word)))
{
- if (level == 1 && strcmp(word, "particles") == 0 && !bFoundParticles)
+ if (level == 1 && std::strcmp(word, "particles") == 0 && !bFoundParticles)
{
bFoundParticles = TRUE;
level += check_open_parenthesis(fp, r, infile, "particles");
break;
case espTYPE:
r = get_espresso_word(fp, word);
- atoms->atom[i].type = strtol(word, NULL, 10);
+ atoms->atom[i].type = std::strtol(word, NULL, 10);
break;
case espQ:
r = get_espresso_word(fp, word);
break;
case espMOLECULE:
r = get_espresso_word(fp, word);
- molnr = strtol(word, NULL, 10);
+ molnr = std::strtol(word, NULL, 10);
if (i == 0 ||
atoms->resinfo[atoms->atom[i-1].resind].nr != molnr)
{
gmx_fatal(FARGS, "Internal inconsistency in Espresso routines, read %d atoms, expected %d atoms", i, atoms->nr);
}
}
- else if (level == 1 && strcmp(word, "variable") == 0 && !bFoundVariable)
+ else if (level == 1 && std::strcmp(word, "variable") == 0 && !bFoundVariable)
{
bFoundVariable = TRUE;
level += check_open_parenthesis(fp, r, infile, "variable");
while (level == 2 && (r = get_espresso_word(fp, word)))
{
- if (level == 2 && strcmp(word, "box_l") == 0)
+ if (level == 2 && std::strcmp(word, "box_l") == 0)
{
for (m = 0; m < 3; m++)
{
}
/* atomname */
- memcpy(name, line+10, 5);
+ std::memcpy(name, line+10, 5);
atoms->atomname[i] = put_symtab(symtab, name);
/* Copy resname to oldresname after we are done with the sanity check above */
- strncpy(oldresname, resname, sizeof(oldresname));
+ std::strncpy(oldresname, resname, sizeof(oldresname));
/* eventueel controle atomnumber met i+1 */
{
for (m = 0; (m < DIM); m++)
{
- xmin[m] = min(xmin[m], x[i][m]);
- xmax[m] = max(xmax[m], x[i][m]);
+ xmin[m] = std::min(xmin[m], x[i][m]);
+ xmax[m] = std::max(xmax[m], x[i][m]);
}
}
for (i = 0; i < DIM; i++)
ai = index[i];
resind = atoms->atom[ai].resind;
- strncpy(resnm, " ??? ", sizeof(resnm)-1);
+ std::strncpy(resnm, " ??? ", sizeof(resnm)-1);
if (resind < atoms->nres)
{
- strncpy(resnm, *atoms->resinfo[resind].name, sizeof(resnm)-1);
+ std::strncpy(resnm, *atoms->resinfo[resind].name, sizeof(resnm)-1);
resnr = atoms->resinfo[resind].nr;
}
else
{
- strncpy(resnm, " ??? ", sizeof(resnm)-1);
+ std::strncpy(resnm, " ??? ", sizeof(resnm)-1);
resnr = resind + 1;
}
if (atoms->atom)
{
- strncpy(nm, *atoms->atomname[ai], sizeof(nm)-1);
+ std::strncpy(nm, *atoms->atomname[ai], sizeof(nm)-1);
}
else
{
- strncpy(nm, " ??? ", sizeof(nm)-1);
+ std::strncpy(nm, " ??? ", sizeof(nm)-1);
}
fprintf(out, "%5d%-5.5s%5.5s%5d", resnr%100000, resnm, nm, (ai+1)%100000);
rvec x[], rvec *v, int *ePBC, matrix box)
{
FILE *in;
- char buf[256];
gmx_mtop_t *mtop;
t_topology top;
t_trxframe fr;
int i, ftp, natoms;
- real d;
char g96_line[STRLEN+1];
if (atoms->nr == 0)
read_g96_conf(in, infile, &fr, g96_line);
gmx_fio_fclose(in);
copy_mat(fr.box, box);
- strncpy(title, fr.title, STRLEN);
+ std::strncpy(title, fr.title, STRLEN);
break;
case efPDB:
case efBRK:
#include "enxio.h"
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/fileio/gmxfio.h"
#include "gromacs/fileio/gmxfio-xdr.h"
#include "gromacs/topology/topology.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
/* The source code in this file should be thread-safe.
XDR *xdr;
gmx_bool bRead = gmx_fio_getread(ef->fio);
int file_version;
- int i;
xdr = gmx_fio_getxdr(ef->fio);
{
int magic = -7777777;
real first_real_to_check;
- int b, i, zero = 0, dum = 0;
+ int b, zero = 0, dum = 0;
gmx_bool bRead = gmx_fio_getread(ef->fio);
- int tempfix_nr = 0;
int ndisre = 0;
int startb = 0;
#ifndef GMX_DOUBLE
}
else
{
- fr->nsteps = max(1, fr->nsum);
+ fr->nsteps = std::max(1, fr->nsum);
}
if (*file_version >= 5)
{
((fr->nre > 0 && fr->nre != nre_test) ||
fr->nre < 0 || ndisre < 0 || fr->nblock < 0))
{
- *bWrongPrecision = TRUE;
+ if (bWrongPrecision)
+ {
+ *bWrongPrecision = TRUE;
+ }
return *bOK;
}
}
}
-static gmx_bool empty_file(const char *fn)
+/*!\brief Return TRUE if a file exists but is empty, otherwise FALSE.
+ *
+ * If the file exists but has length larger than zero, if it does not exist, or
+ * if there is a file system error, FALSE will be returned instead.
+ *
+ * \param fn File name to test
+ *
+ * \return TRUE if file could be open but is empty, otherwise FALSE.
+ */
+static gmx_bool
+empty_file(const char *fn)
{
FILE *fp;
char dum;
bEmpty = feof(fp);
gmx_fio_fclose(fp);
- return bEmpty;
+ // bEmpty==TRUE but ret!=0 would likely be some strange I/O error, but at
+ // least it's not a normal empty file, so we return FALSE in that case.
+ return (bEmpty && ret == 0);
}
ener_file_t open_enx(const char *fn, const char *mode)
{
- int nre, i;
+ int nre;
gmx_enxnm_t *nms = NULL;
int file_version = -1;
t_enxframe *fr;
{
fprintf(stderr, "\nWARNING: there may be something wrong with energy file %s\n",
gmx_fio_getname(ef->fio));
- fprintf(stderr, "Found: step=%"GMX_PRId64 ", nre=%d, nblock=%d, time=%g.\n"
+ fprintf(stderr, "Found: step=%" GMX_PRId64 ", nre=%d, nblock=%d, time=%g.\n"
"Trying to skip frame expect a crash though\n",
fr->step, fr->nre, fr->nblock, fr->t);
}
}
/* read/write data */
- bOK1 = TRUE;
switch (sub->type)
{
case xdr_datatype_float:
for (i = 0; i < nre; i++)
{
- if (strcmp(enm[i].name, name) == 0)
+ if (std::strcmp(enm[i].name, name) == 0)
{
return fr->ener[i].e;
}
"Box-Vel-YX", "Box-Vel-ZX", "Box-Vel-ZY"
};
- static const char *pcouplmu_nm[] = {
- "Pcoupl-Mu-XX", "Pcoupl-Mu-YY", "Pcoupl-Mu-ZZ",
- "Pcoupl-Mu-YX", "Pcoupl-Mu-ZX", "Pcoupl-Mu-ZY"
- };
static const char *baro_nm[] = {
"Barostat"
};
#include "filenm.h"
-#include <stdio.h>
-#include <string.h>
+#include <cstdio>
+#include <cstring>
#include "gromacs/legacyheaders/macros.h"
#include "gromacs/legacyheaders/types/commrec.h"
{ eftASC, "", "rundir", NULL, "Run directory" }
};
-#define NZEXT 2
-static const char *z_ext[NZEXT] =
-{ ".gz", ".Z" };
-
const char *ftp2ext(int ftp)
{
if ((0 <= ftp) && (ftp < efNR))
return efNR;
}
- len = strlen(fn);
+ len = std::strlen(fn);
if ((len >= 4) && (fn[len - 4] == '.'))
{
feptr = &(fn[len - 4]);
for (i = 0; (i < nfile); i++)
{
- if (strcmp(opt, fnm[i].opt) == 0)
+ if (std::strcmp(opt, fnm[i].opt) == 0)
{
return fnm[i].fns[0];
}
for (i = 0; (i < nfile); i++)
{
- if (strcmp(opt, fnm[i].opt) == 0)
+ if (std::strcmp(opt, fnm[i].opt) == 0)
{
return (gmx_bool) IS_SET(fnm[i]);
}
for (i = 0; (i < nfile); i++)
{
- if (strcmp(opt, fnm[i].opt) == 0)
+ if (std::strcmp(opt, fnm[i].opt) == 0)
{
if (IS_OPT(fnm[i]) && !IS_SET(fnm[i]))
{
int add_suffix_to_output_names(t_filenm *fnm, int nfile, const char *suffix)
{
- int i, j, pos;
+ int i, j;
char buf[STRLEN], newname[STRLEN];
char *extpos;
for it, just in case... */
for (j = 0; j < fnm[i].nfiles; j++)
{
- strncpy(buf, fnm[i].fns[j], STRLEN - 1);
+ std::strncpy(buf, fnm[i].fns[j], STRLEN - 1);
extpos = strrchr(buf, '.');
*extpos = '\0';
sprintf(newname, "%s%s.%s", buf, suffix, extpos + 1);
#if GMX_INTERNAL_XDR
-#include "gmx_system_xdr.h"
+#include "gmx_internal_xdr.h"
-#include <limits.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
/* NB - THIS FILE IS ONLY USED ON MICROSOFT WINDOWS, since that
{
xdr_uint32_t y;
int i;
- char *px = (char *)&x;
- char *py = (char *)&y;
+ char *px = reinterpret_cast<char *>(&x);
+ char *py = reinterpret_cast<char *>(&y);
for (i = 0; i < 4; i++)
{
static xdr_uint32_t xdr_htonl(xdr_uint32_t x)
{
short s = 0x0F00;
- if (*((char *)&s) == (char)0x0F)
+ if (*(reinterpret_cast<char *>(&s)) == static_cast<char>(0x0F))
{
/* bigendian, do nothing */
return x;
static xdr_uint32_t xdr_ntohl(xdr_uint32_t x)
{
short s = 0x0F00;
- if (*((char *)&s) == (char)0x0F)
+ if (*(reinterpret_cast<char *>(&s)) == static_cast<char>(0x0F))
{
/* bigendian, do nothing */
return x;
switch (xdrs->x_op)
{
case XDR_ENCODE:
- l = (xdr_int32_t) (*ip);
+ l = static_cast<xdr_int32_t>(*ip);
return xdr_putint32 (xdrs, &l);
case XDR_DECODE:
{
return FALSE;
}
- *ip = (int) l;
+ *ip = static_cast<int>(l);
case XDR_FREE:
return TRUE;
switch (xdrs->x_op)
{
case XDR_ENCODE:
- l = (xdr_uint32_t) (*up);
+ l = static_cast<xdr_uint32_t>(*up);
return xdr_putuint32 (xdrs, &l);
case XDR_DECODE:
{
return FALSE;
}
- *up = (unsigned int) l;
+ *up = static_cast<unsigned int>(l);
case XDR_FREE:
return TRUE;
switch (xdrs->x_op)
{
case XDR_ENCODE:
- l = (xdr_int32_t) *sp;
+ l = static_cast<xdr_int32_t>(*sp);
return xdr_putint32 (xdrs, &l);
case XDR_DECODE:
{
return FALSE;
}
- *sp = (short) l;
+ *sp = static_cast<short>(l);
return TRUE;
case XDR_FREE:
switch (xdrs->x_op)
{
case XDR_ENCODE:
- l = (xdr_uint32_t) *usp;
+ l = static_cast<xdr_uint32_t>(*usp);
return xdr_putuint32 (xdrs, &l);
case XDR_DECODE:
{
return FALSE;
}
- *usp = (unsigned short) l;
+ *usp = static_cast<unsigned short>(l);
return TRUE;
case XDR_FREE:
{
return TRUE;
}
- return xdr_getbytes (xdrs, (char *)crud, rndup);
+ return xdr_getbytes (xdrs, crud, rndup);
case XDR_ENCODE:
if (!xdr_putbytes (xdrs, cp, cnt))
* storage is allocated. The last parameter is the max allowed length
* of the string as specified by a protocol.
*/
-bool_t
-xdr_string (xdrs, cpp, maxsize)
-XDR *xdrs;
-char **cpp;
-unsigned int maxsize;
+bool_t xdr_string (XDR *xdrs, char ** cpp, unsigned int maxsize)
{
char *sp = *cpp; /* sp is the actual string pointer */
unsigned int size = 0;
{
return FALSE;
}
- size = strlen (sp);
+ size = std::strlen (sp);
break;
case XDR_DECODE:
break;
}
if (sp == NULL)
{
- *cpp = sp = (char *) malloc (nodesize);
+ *cpp = sp = static_cast<char *>(std::malloc (nodesize));
}
if (sp == NULL)
{
/* Floating-point stuff */
-bool_t
-xdr_float(xdrs, fp)
-XDR *xdrs;
-float *fp;
+bool_t xdr_float(XDR * xdrs, float * fp)
{
xdr_int32_t tmp;
{
case XDR_ENCODE:
- tmp = *(xdr_int32_t *)fp;
+ tmp = *(reinterpret_cast<xdr_int32_t *>(fp));
return (xdr_putint32(xdrs, &tmp));
break;
case XDR_DECODE:
if (xdr_getint32(xdrs, &tmp))
{
- *(xdr_int32_t *)fp = tmp;
+ *(reinterpret_cast<xdr_int32_t *>(fp)) = tmp;
return (TRUE);
}
}
-bool_t
-xdr_double(xdrs, dp)
-XDR *xdrs;
-double *dp;
+bool_t xdr_double(XDR * xdrs, double * dp)
{
/* Windows and some other systems dont define double-precision
* B B 3f ef 9a dd 3c 0e 56 b8
*/
- unsigned char ix = *((char *)&x);
+ unsigned char ix = *(reinterpret_cast<char *>(&x));
if (ix == 0xdd || ix == 0x3f)
{
{
case XDR_ENCODE:
- ip = (int *)dp;
+ ip = reinterpret_cast<int *>(dp);
tmp[0] = ip[!LSW];
tmp[1] = ip[LSW];
return (xdr_putint32(xdrs, tmp) &&
break;
case XDR_DECODE:
- ip = (int *)dp;
+ ip = reinterpret_cast<int *>(dp);
if (xdr_getint32(xdrs, tmp+!LSW) &&
xdr_getint32(xdrs, tmp+LSW))
{
* > elemsize: size of each element
* > xdr_elem: routine to XDR each element
*/
-bool_t
-xdr_vector (xdrs, basep, nelem, elemsize, xdr_elem)
-XDR *xdrs;
-char *basep;
-unsigned int nelem;
-unsigned int elemsize;
-xdrproc_t xdr_elem;
+bool_t xdr_vector (XDR * xdrs, char * basep, unsigned int nelem,
+ unsigned int elemsize, xdrproc_t xdr_elem)
{
#define LASTUNSIGNED ((unsigned int)0-1)
unsigned int i;
static bool_t xdrstdio_getuint32 (XDR *, xdr_uint32_t *);
static bool_t xdrstdio_putuint32 (XDR *, xdr_uint32_t *);
-/*
- * Ops vector for stdio type XDR
- */
-static const struct xdr_ops xdrstdio_ops =
-{
- xdrstdio_getbytes, /* deserialize counted bytes */
- xdrstdio_putbytes, /* serialize counted bytes */
- xdrstdio_getpos, /* get offset in the stream */
- xdrstdio_setpos, /* set offset in the stream */
- xdrstdio_inline, /* prime stream for inline macros */
- xdrstdio_destroy, /* destroy stream */
- xdrstdio_getint32, /* deserialize a int */
- xdrstdio_putint32, /* serialize a int */
- xdrstdio_getuint32, /* deserialize a int */
- xdrstdio_putuint32 /* serialize a int */
-};
-
-/*
- * Initialize a stdio xdr stream.
- * Sets the xdr stream handle xdrs for use on the stream file.
- * Operation flag is set to op.
- */
-void
-xdrstdio_create (XDR *xdrs, FILE *file, enum xdr_op op)
-{
- xdrs->x_op = op;
- /* We have to add the const since the `struct xdr_ops' in `struct XDR'
- is not `const'. */
- xdrs->x_ops = (struct xdr_ops *) &xdrstdio_ops;
- xdrs->x_private = (char *) file;
- xdrs->x_handy = 0;
- xdrs->x_base = 0;
-}
-
/*
* Destroy a stdio xdr stream.
* Cleans up the xdr stream handle xdrs previously set up by xdrstdio_create.
static void
xdrstdio_destroy (XDR *xdrs)
{
- (void) fflush ((FILE *) xdrs->x_private);
+ fflush (reinterpret_cast<FILE *>(xdrs->x_private));
/* xx should we close the file ?? */
}
static bool_t
xdrstdio_getbytes (XDR *xdrs, char *addr, unsigned int len)
{
- if ((len != 0) && (fread (addr, (int) len, 1,
- (FILE *) xdrs->x_private) != 1))
+ if ((len != 0) && (fread (addr, static_cast<int>(len), 1,
+ reinterpret_cast<FILE *>(xdrs->x_private)) != 1))
{
return FALSE;
}
static bool_t
xdrstdio_putbytes (XDR *xdrs, char *addr, unsigned int len)
{
- if ((len != 0) && (fwrite (addr, (int) len, 1,
- (FILE *) xdrs->x_private) != 1))
+ if ((len != 0) && (fwrite (addr, static_cast<int>(len), 1,
+ reinterpret_cast<FILE *>(xdrs->x_private)) != 1))
{
return FALSE;
}
static unsigned int
xdrstdio_getpos (XDR *xdrs)
{
- return (unsigned int) ftell ((FILE *) xdrs->x_private);
+ return static_cast<int>(ftell (reinterpret_cast<FILE *>(xdrs->x_private)));
}
static bool_t
xdrstdio_setpos (XDR *xdrs, unsigned int pos)
{
- return fseek ((FILE *) xdrs->x_private, (xdr_int32_t) pos, 0) < 0 ? FALSE : TRUE;
+ return fseek (reinterpret_cast<FILE *>(xdrs->x_private), static_cast<xdr_int32_t>(pos), 0) < 0 ? FALSE : TRUE;
}
static xdr_int32_t *
{
xdr_int32_t mycopy;
- if (fread ((char *) &mycopy, 4, 1, (FILE *) xdrs->x_private) != 1)
+ if (fread (&mycopy, 4, 1, reinterpret_cast<FILE *>(xdrs->x_private)) != 1)
{
return FALSE;
}
xdr_int32_t mycopy = xdr_htonl (*ip);
ip = &mycopy;
- if (fwrite ((char *) ip, 4, 1, (FILE *) xdrs->x_private) != 1)
+ if (fwrite (ip, 4, 1, reinterpret_cast<FILE *>(xdrs->x_private)) != 1)
{
return FALSE;
}
{
xdr_uint32_t mycopy;
- if (fread ((char *) &mycopy, 4, 1, (FILE *) xdrs->x_private) != 1)
+ if (fread (&mycopy, 4, 1, reinterpret_cast<FILE *>(xdrs->x_private)) != 1)
{
return FALSE;
}
xdr_uint32_t mycopy = xdr_htonl (*ip);
ip = &mycopy;
- if (fwrite ((char *) ip, 4, 1, (FILE *) xdrs->x_private) != 1)
+ if (fwrite (ip, 4, 1, reinterpret_cast<FILE *>(xdrs->x_private)) != 1)
{
return FALSE;
}
return TRUE;
}
+/*
+ * Ops vector for stdio type XDR
+ */
+static struct XDR::xdr_ops xdrstdio_ops =
+{
+ xdrstdio_getbytes, /* deserialize counted bytes */
+ xdrstdio_putbytes, /* serialize counted bytes */
+ xdrstdio_getpos, /* get offset in the stream */
+ xdrstdio_setpos, /* set offset in the stream */
+ xdrstdio_inline, /* prime stream for inline macros */
+ xdrstdio_destroy, /* destroy stream */
+ xdrstdio_getint32, /* deserialize a int */
+ xdrstdio_putint32, /* serialize a int */
+ xdrstdio_getuint32, /* deserialize a int */
+ xdrstdio_putuint32 /* serialize a int */
+};
+
+/*
+ * Initialize a stdio xdr stream.
+ * Sets the xdr stream handle xdrs for use on the stream file.
+ * Operation flag is set to op.
+ */
+void
+xdrstdio_create (XDR *xdrs, FILE *file, enum xdr_op op)
+{
+ xdrs->x_op = op;
+ xdrs->x_ops = &xdrstdio_ops;
+ xdrs->x_private = reinterpret_cast<char *>(file);
+ xdrs->x_handy = 0;
+ xdrs->x_base = 0;
+}
+
#else
-int
- gmx_system_xdr_empty;
-#endif /* GMX_SYSTEM_XDR */
+int gmx_internal_xdr_empty;
+#endif /* GMX_INTERNAL_XDR */
*
* 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) 2013,2015, 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.
#ifndef GMX_FILEIO_GMX_SYSTEM_XDR_H
#define GMX_FILEIO_GMX_SYSTEM_XDR_H
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-
+#include <climits>
+#include <cstdio>
+#include <cstdlib>
/*
* This header file is ONLY used on windows systems, since these do
#include "gmxfio-xdr.h"
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
+#include <cstdio>
+#include <cstring>
#include "gromacs/fileio/gmxfio.h"
#include "gromacs/fileio/xdrf.h"
#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
#include "gmxfio-impl.h"
{
XDR *ret = NULL;
gmx_fio_lock(fio);
- assert(fio->xdr != NULL);
+ GMX_RELEASE_ASSERT( fio->xdr != NULL, "Implementation error: NULL XDR pointers");
ret = fio->xdr;
gmx_fio_unlock(fio);
return ret;
static void gmx_fio_fe(t_fileio *fio, int eio, const char *desc,
const char *srcfile, int line)
{
-
gmx_fatal(FARGS, "Trying to %s %s type %d (%s), src %s, line %d",
fio->bRead ? "read" : "write", desc, eio,
((eio >= 0) && (eio < eioNR)) ? eioNames[eio] : "unknown",
double d = 0;
float f = 0;
- assert(fio->xdr != NULL);
+ GMX_RELEASE_ASSERT( fio->xdr != NULL, "Implementation error: NULL XDR pointers");
gmx_fio_check_nitem(eio, nitem, srcfile, line);
switch (eio)
{
}
}
res = xdr_vector(fio->xdr, (char *) dvec, DIM,
- (unsigned int) sizeof(double),
+ static_cast<unsigned int>(sizeof(double)),
(xdrproc_t) xdr_double);
if (item)
{
}
}
res = xdr_vector(fio->xdr, (char *) fvec, DIM,
- (unsigned int) sizeof(float),
+ static_cast<unsigned int>(sizeof(float)),
(xdrproc_t) xdr_float);
if (item)
{
#include "config.h"
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
+#include <cerrno>
+#include <cstdio>
+#include <cstring>
#ifdef HAVE_IO_H
#include <io.h>
gmx_bool bRead, bReadWrite;
/* sanitize the mode string */
- if (strncmp(mode, "r+", 2) == 0)
+ if (std::strncmp(mode, "r+", 2) == 0)
{
- strcpy(newmode, "r+");
+ std::strcpy(newmode, "r+");
}
else if (mode[0] == 'r')
{
- strcpy(newmode, "r");
+ std::strcpy(newmode, "r");
}
else if (strncmp(mode, "w+", 2) == 0)
{
- strcpy(newmode, "w+");
+ std::strcpy(newmode, "w+");
}
else if (mode[0] == 'w')
{
- strcpy(newmode, "w");
+ std::strcpy(newmode, "w");
}
else if (strncmp(mode, "a+", 2) == 0)
{
- strcpy(newmode, "a+");
+ std::strcpy(newmode, "a+");
}
else if (mode[0] == 'a')
{
- strcpy(newmode, "a");
+ std::strcpy(newmode, "a");
}
else
{
gmx_fseek(fio->fp, 0, SEEK_END);
}
}
+ else
+ {
+ gmx_fatal(FARGS, "Cannot open file with NULL filename string");
+ }
+
fio->bRead = bRead;
fio->bReadWrite = bReadWrite;
fio->bDouble = (sizeof(real) == sizeof(double));
srenew(outputfiles, nalloc);
}
- strncpy(outputfiles[nfiles].filename, cur->fn, STRLEN - 1);
+ std::strncpy(outputfiles[nfiles].filename, cur->fn, STRLEN - 1);
/* Get the file position */
gmx_fio_int_get_file_position(cur, &outputfiles[nfiles].offset);
{
rc = gmx_fsync(fio->fp);
}
-
return rc;
}
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, 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.
*/
#include "gmxpre.h"
-#include <limits.h>
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <climits>
+#include <cmath>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/fileio/xdr_datatype.h"
#include "gromacs/fileio/xdrf.h"
*/
#define MAXABS INT_MAX-2
-#ifndef MIN
-#define MIN(x, y) ((x) < (y) ? (x) : (y))
-#endif
-#ifndef MAX
-#define MAX(x, y) ((x) > (y) ? (x) : (y))
-#endif
#ifndef SQR
#define SQR(x) ((x)*(x))
#endif
#define FIRSTIDX 9
/* note that magicints[FIRSTIDX-1] == 0 */
-#define LASTIDX (sizeof(magicints) / sizeof(*magicints))
+#define LASTIDX static_cast<int>((sizeof(magicints) / sizeof(*magicints)))
/*____________________________________________________________________________
int lastbits;
unsigned char * cbuf;
- cbuf = ((unsigned char *)buf) + 3 * sizeof(*buf);
- cnt = (unsigned int) buf[0];
+ cbuf = (reinterpret_cast<unsigned char *>(buf)) + 3 * sizeof(*buf);
+ cnt = static_cast<unsigned int>(buf[0]);
lastbits = buf[1];
- lastbyte = (unsigned int) buf[2];
+ lastbyte = static_cast<unsigned int>(buf[2]);
while (num_of_bits >= 8)
{
lastbyte = (lastbyte << 8) | ((num >> (num_of_bits -8)) /* & 0xff*/);
unsigned char * cbuf;
int mask = (1 << num_of_bits) -1;
- cbuf = ((unsigned char *)buf) + 3 * sizeof(*buf);
+ cbuf = reinterpret_cast<unsigned char *>(buf) + 3 * sizeof(*buf);
cnt = buf[0];
- lastbits = (unsigned int) buf[1];
- lastbyte = (unsigned int) buf[2];
+ lastbits = static_cast<unsigned int>(buf[1]);
+ lastbyte = static_cast<unsigned int>(buf[2]);
num = 0;
while (num_of_bits >= 8)
int tmp, *thiscoord, prevcoord[3];
unsigned int tmpcoord[30];
- int bufsize, xdrid, lsize;
+ int bufsize, lsize;
unsigned int bitsize;
float inv_precision;
int errval = 1;
bitsizeint[0] = bitsizeint[1] = bitsizeint[2] = 0;
prevcoord[0] = prevcoord[1] = prevcoord[2] = 0;
+ // The static analyzer warns about garbage values for thiscoord[] further
+ // down. It might be thrown off by all the reinterpret_casts, but we might
+ // as well make sure the small preallocated buffer is zero-initialized.
+ for (i = 0; i < static_cast<int>(prealloc_size); i++)
+ {
+ prealloc_ip[i] = 0;
+ }
+
if (!bRead)
{
/* xdrs is open for writing */
*/
if (*size <= 9)
{
- return (xdr_vector(xdrs, (char *) fp, (unsigned int)size3,
- (unsigned int)sizeof(*fp), (xdrproc_t)xdr_float));
+ return (xdr_vector(xdrs, reinterpret_cast<char *>(fp), static_cast<unsigned int>(size3),
+ static_cast<unsigned int>(sizeof(*fp)), (xdrproc_t)xdr_float));
}
if (xdr_float(xdrs, precision) == 0)
else
{
we_should_free = 1;
- bufsize = size3 * 1.2;
- ip = (int *)malloc((size_t)(size3 * sizeof(*ip)));
- buf = (int *)malloc((size_t)(bufsize * sizeof(*buf)));
+ bufsize = static_cast<int>(size3 * 1.2);
+ ip = reinterpret_cast<int *>(malloc(size3 * sizeof(*ip)));
+ buf = reinterpret_cast<int *>(malloc(bufsize * sizeof(*buf)));
if (ip == NULL || buf == NULL)
{
fprintf(stderr, "malloc failed\n");
/* scaling would cause overflow */
errval = 0;
}
- lint1 = lf;
+ lint1 = static_cast<int>(lf);
if (lint1 < minint[0])
{
minint[0] = lint1;
/* scaling would cause overflow */
errval = 0;
}
- lint2 = lf;
+ lint2 = static_cast<int>(lf);
if (lint2 < minint[1])
{
minint[1] = lint2;
{
lf = *lfp * *precision - 0.5;
}
- if (fabs(lf) > MAXABS)
+ if (std::abs(lf) > MAXABS)
{
/* scaling would cause overflow */
errval = 0;
}
- lint3 = lf;
+ lint3 = static_cast<int>(lf);
if (lint3 < minint[2])
{
minint[2] = lint3;
}
*lip++ = lint3;
lfp++;
- diff = abs(oldlint1-lint1)+abs(oldlint2-lint2)+abs(oldlint3-lint3);
+ diff = std::abs(oldlint1-lint1)+std::abs(oldlint2-lint2)+std::abs(oldlint3-lint3);
if (diff < mindiff && lfp > fp + 3)
{
mindiff = diff;
{
bitsize = sizeofints(3, sizeint);
}
- lip = ip;
- luip = (unsigned int *) ip;
+ luip = reinterpret_cast<unsigned int *>(ip);
smallidx = FIRSTIDX;
while (smallidx < LASTIDX && magicints[smallidx] < mindiff)
{
return 0;
}
- maxidx = MIN(LASTIDX, smallidx + 8);
+ maxidx = std::min(LASTIDX, smallidx + 8);
minidx = maxidx - 8; /* often this equal smallidx */
- smaller = magicints[MAX(FIRSTIDX, smallidx-1)] / 2;
+ smaller = magicints[std::max(FIRSTIDX, smallidx-1)] / 2;
smallnum = magicints[smallidx] / 2;
sizesmall[0] = sizesmall[1] = sizesmall[2] = magicints[smallidx];
larger = magicints[maxidx] / 2;
while (i < *size)
{
is_small = 0;
- thiscoord = (int *)(luip) + i * 3;
+ thiscoord = reinterpret_cast<int *>(luip) + i * 3;
if (smallidx < maxidx && i >= 1 &&
- abs(thiscoord[0] - prevcoord[0]) < larger &&
- abs(thiscoord[1] - prevcoord[1]) < larger &&
- abs(thiscoord[2] - prevcoord[2]) < larger)
+ std::abs(thiscoord[0] - prevcoord[0]) < larger &&
+ std::abs(thiscoord[1] - prevcoord[1]) < larger &&
+ std::abs(thiscoord[2] - prevcoord[2]) < larger)
{
is_smaller = 1;
}
}
if (i + 1 < *size)
{
- if (abs(thiscoord[0] - thiscoord[3]) < smallnum &&
- abs(thiscoord[1] - thiscoord[4]) < smallnum &&
- abs(thiscoord[2] - thiscoord[5]) < smallnum)
+ if (std::abs(thiscoord[0] - thiscoord[3]) < smallnum &&
+ std::abs(thiscoord[1] - thiscoord[4]) < smallnum &&
+ std::abs(thiscoord[2] - thiscoord[5]) < smallnum)
{
/* interchange first with second atom for better
* compression of water molecules
}
- rc = errval * (xdr_opaque(xdrs, (char *)&(buf[3]), (unsigned int)buf[0]));
+ rc = errval * (xdr_opaque(xdrs, reinterpret_cast<char *>(&(buf[3])), static_cast<unsigned int>(buf[0])));
if (we_should_free)
{
free(ip);
if (*size <= 9)
{
*precision = -1;
- return (xdr_vector(xdrs, (char *) fp, (unsigned int)size3,
- (unsigned int)sizeof(*fp), (xdrproc_t)xdr_float));
+ return (xdr_vector(xdrs, reinterpret_cast<char *>(fp), static_cast<unsigned int>(size3),
+ static_cast<unsigned int>(sizeof(*fp)), (xdrproc_t)xdr_float));
}
if (xdr_float(xdrs, precision) == 0)
{
else
{
we_should_free = 1;
- bufsize = size3 * 1.2;
- ip = (int *)malloc((size_t)(size3 * sizeof(*ip)));
- buf = (int *)malloc((size_t)(bufsize * sizeof(*buf)));
+ bufsize = static_cast<int>(size3 * 1.2);
+ ip = reinterpret_cast<int *>(malloc(size3 * sizeof(*ip)));
+ buf = reinterpret_cast<int *>(malloc(bufsize * sizeof(*buf)));
if (ip == NULL || buf == NULL)
{
fprintf(stderr, "malloc failed\n");
return 0;
}
- maxidx = MIN(LASTIDX, smallidx + 8);
- minidx = maxidx - 8; /* often this equal smallidx */
- smaller = magicints[MAX(FIRSTIDX, smallidx-1)] / 2;
+ smaller = magicints[std::max(FIRSTIDX, smallidx-1)] / 2;
smallnum = magicints[smallidx] / 2;
sizesmall[0] = sizesmall[1] = sizesmall[2] = magicints[smallidx];
- larger = magicints[maxidx];
/* buf[0] holds the length in bytes */
}
- if (xdr_opaque(xdrs, (char *)&(buf[3]), (unsigned int)buf[0]) == 0)
+ if (xdr_opaque(xdrs, reinterpret_cast<char *>(&(buf[3])), static_cast<unsigned int>(buf[0])) == 0)
{
if (we_should_free)
{
lip = ip;
while (i < lsize)
{
- thiscoord = (int *)(lip) + i * 3;
+ thiscoord = reinterpret_cast<int *>(lip) + i * 3;
if (bitsize == 0)
{
static gmx_off_t xtc_get_next_frame_start(FILE *fp, XDR *xdrs, int natoms)
{
- int inp;
gmx_off_t res;
int ret;
int step;
gmx_bool bOK = FALSE;
gmx_off_t low = 0;
gmx_off_t high, offset, pos;
- int res;
int dt_sign = 0;
if (bSeekForwardOnly)
{
float time;
gmx_off_t off;
- int res;
*bOK = 1;
off = gmx_ftell(fp);
if (off < 0)
return -1;
}
- if ( (res = gmx_fseek(fp, -3*XDR_INT_SIZE, SEEK_END)) != 0)
+ if (gmx_fseek(fp, -3*XDR_INT_SIZE, SEEK_END) != 0)
{
*bOK = 0;
return -1;
return -1;
}
- if ( (res = gmx_fseek(fp, off, SEEK_SET)) != 0)
+ if (gmx_fseek(fp, off, SEEK_SET) != 0)
{
*bOK = 0;
return -1;
{
int frame;
gmx_off_t off;
- int res;
*bOK = 1;
if ((off = gmx_ftell(fp)) < 0)
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, 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.
#include "matio.h"
-#include <ctype.h>
-#include <stdio.h>
+#include <cctype>
+#include <cstdio>
+#include <cstring>
#include <algorithm>
llmax = STRLEN;
while ((NULL != fgetline(&line_buf, llmax, &llalloc, in)) &&
- (strncmp(line_buf, "static", 6) != 0))
+ (std::strncmp(line_buf, "static", 6) != 0))
{
line = line_buf;
parsestring(line, "title", (mm->title));
m = 0;
while ((m < mm->nmap) && (NULL != fgetline(&line_buf, llmax, &llalloc, in)))
{
- line = strchr(line_buf, '\"');
+ line = std::strchr(line_buf, '\"');
if (line)
{
line++;
map[m].code.c2 = line[1];
}
line += nch;
- str = strchr(line, '#');
+ str = std::strchr(line, '#');
if (str)
{
str++;
col_len = 0;
- while (isxdigit(str[col_len]))
+ while (std::isxdigit(str[col_len]))
{
col_len++;
}
}
else
{
- str = strchr(line, 'c');
+ str = std::strchr(line, 'c');
if (str)
{
str += 2;
map[m].rgb.g = 1;
map[m].rgb.b = 1;
}
- line = strchr(line, '\"');
+ line = std::strchr(line, '\"');
line++;
line2string(&line);
map[m].desc = gmx_strdup(line);
bSetLine = TRUE;
if (strstr(line, "x-axis"))
{
- line = strstr(line, "x-axis");
+ line = std::strstr(line, "x-axis");
skipstr(line);
if (mm->axis_x == NULL)
{
skipstr(line);
}
}
- else if (strstr(line, "y-axis"))
+ else if (std::strstr(line, "y-axis"))
{
- line = strstr(line, "y-axis");
+ line = std::strstr(line, "y-axis");
skipstr(line);
if (mm->axis_y == NULL)
{
nmat = 0;
while (NULL != fgetline(&line, STRLEN, &llalloc, in))
{
- if (strstr(line, "/* XPM */"))
+ if (std::strstr(line, "/* XPM */"))
{
srenew(*mat, nmat+1);
read_xpm_entry(in, &(*mat)[nmat]);
fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%.3g\" */,\n",
mapper[i % NMAP],
(*nlevels <= NMAP) ? ' ' : mapper[i/NMAP],
- (unsigned int)round(255*r),
- (unsigned int)round(255*g),
- (unsigned int)round(255*b),
+ static_cast<unsigned int>(round(255*r)),
+ static_cast<unsigned int>(round(255*g)),
+ static_cast<unsigned int>(round(255*b)),
((nmid - i)*lo + i*mid)/clev_lo);
}
for (i = 0; (i < (*nlevels-nmid)); i++)
fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%.3g\" */,\n",
mapper[(i+nmid) % NMAP],
(*nlevels <= NMAP) ? ' ' : mapper[(i+nmid)/NMAP],
- (unsigned int)round(255*r),
- (unsigned int)round(255*g),
- (unsigned int)round(255*b),
+ static_cast<unsigned int>(round(255*r)),
+ static_cast<unsigned int>(round(255*g)),
+ static_cast<unsigned int>(round(255*b)),
((*nlevels - 1 - nmid - i)*mid + i*hi)/clev_hi);
}
}
fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%.3g\" */,\n",
mapper[(i+i0) % NMAP],
(nlevel <= NMAP) ? ' ' : mapper[(i+i0)/NMAP],
- (unsigned int)round(255*r),
- (unsigned int)round(255*g),
- (unsigned int)round(255*b),
+ static_cast<unsigned int>(round(255*r)),
+ static_cast<unsigned int>(round(255*g)),
+ static_cast<unsigned int>(round(255*b)),
lo+fac*(hi-lo));
}
}
fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%3d\" */,\n",
mapper[(i+i0) % NMAP],
(n <= NMAP) ? ' ' : mapper[(i+i0)/NMAP],
- (unsigned int)round(255*rgbd[i].r),
- (unsigned int)round(255*rgbd[i].g),
- (unsigned int)round(255*rgbd[i].b),
+ static_cast<unsigned int>(round(255*rgbd[i].r)),
+ static_cast<unsigned int>(round(255*rgbd[i].g)),
+ static_cast<unsigned int>(round(255*rgbd[i].b)),
i);
}
}
b = (nlo*rlo.b+i*rhi.b)*invlevel;
fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%.3g\" */,\n",
mapper[i % NMAP], (*nlevels <= NMAP) ? ' ' : mapper[i/NMAP],
- (unsigned int)round(255*r),
- (unsigned int)round(255*g),
- (unsigned int)round(255*b),
+ static_cast<unsigned int>(round(255*r)),
+ static_cast<unsigned int>(round(255*g)),
+ static_cast<unsigned int>(round(255*b)),
(nlo*lo+i*hi)*invlevel);
}
}
fprintf(out, "\"%c%c c #%02X%02X%02X \" /* \"%s\" */,\n",
m.map[i].code.c1,
bOneChar ? ' ' : m.map[i].code.c2,
- (unsigned int)round(m.map[i].rgb.r*255),
- (unsigned int)round(m.map[i].rgb.g*255),
- (unsigned int)round(m.map[i].rgb.b*255), m.map[i].desc);
+ static_cast<unsigned int>(round(m.map[i].rgb.r*255)),
+ static_cast<unsigned int>(round(m.map[i].rgb.g*255)),
+ static_cast<unsigned int>(round(m.map[i].rgb.b*255)), m.map[i].desc);
}
write_xpm_axis(out, "x", m.flags & MAT_SPATIAL_X, m.nx, m.axis_x);
write_xpm_axis(out, "y", m.flags & MAT_SPATIAL_Y, m.ny, m.axis_y);
#include "config.h"
+#include <cstring>
+
#if GMX_INTEGER_BIG_ENDIAN
#define ARCH_IS_BIG_ENDIAN 1
#else
#include "md5.h"
-#include <string.h>
-
#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
#ifdef ARCH_IS_BIG_ENDIAN
# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
*/
static const int w = 1;
- if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
+ if (*(reinterpret_cast<const md5_byte_t *>(&w))) /* dynamic little-endian */
#endif
-#if BYTE_ORDER <= 0 /* little-endian */
+#if BYTE_ORDER <= 0 /* little-endian */
{
/*
* On little-endian machines, we can process properly aligned
* data without copying it.
*/
- if (!((data - (const md5_byte_t *)0) & 3))
+ if (!((data - reinterpret_cast<const md5_byte_t *>(0)) & 3))
{
/* data are properly aligned */
X = (const md5_word_t *)data;
else
{
/* not aligned */
- memcpy(xbuf, data, 64);
+ std::memcpy(xbuf, data, 64);
X = xbuf;
}
}
{
int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
- memcpy(pms->buf + offset, p, copy);
+ std::memcpy(pms->buf + offset, p, copy);
if (offset + copy < 64)
{
return;
of->bExpanded = ir->bExpanded;
of->elamstats = ir->expandedvals->elamstats;
of->simulation_part = ir->simulation_part;
- of->x_compression_precision = ir->x_compression_precision;
+ of->x_compression_precision = static_cast<int>(ir->x_compression_precision);
of->wcycle = wcycle;
if (MASTER(cr))
}
gmx_fwrite_tng(of->tng, FALSE, step, t, state_local->lambda[efptFEP],
- (const rvec *) state_local->box,
+ state_local->box,
top_global->natoms,
- (mdof_flags & MDOF_X) ? (const rvec *) state_global->x : NULL,
- (mdof_flags & MDOF_V) ? (const rvec *) global_v : NULL,
- (mdof_flags & MDOF_F) ? (const rvec *) f_global : NULL);
+ (mdof_flags & MDOF_X) ? state_global->x : NULL,
+ (mdof_flags & MDOF_V) ? global_v : NULL,
+ (mdof_flags & MDOF_F) ? f_global : NULL);
}
if (mdof_flags & MDOF_X_COMPRESSED)
{
step,
t,
state_local->lambda[efptFEP],
- (const rvec *) state_local->box,
+ state_local->box,
of->natoms_x_compressed,
- (const rvec *) xxtc,
+ xxtc,
NULL,
NULL);
if (of->natoms_x_compressed != of->natoms_global)
{
t_fileio *fio;
int i, j, prec;
- gmx_bool bDum = TRUE;
- gmx_bool bRead = FALSE;
size_t sz;
if (full_matrix != NULL && sparse_matrix != NULL)
i = GMX_MTXIO_FULL_MATRIX;
gmx_fio_do_int(fio, i);
sz = nrow*ncol;
- bDum = gmx_fio_ndo_real(fio, full_matrix, sz);
+ gmx_fio_ndo_real(fio, full_matrix, sz);
}
else
{
{
gmx_fatal(FARGS, "Internal inconsistency in sparse matrix.\n");
}
- bDum = gmx_fio_ndo_int(fio, sparse_matrix->ndata, sparse_matrix->nrow);
+ gmx_fio_ndo_int(fio, sparse_matrix->ndata, sparse_matrix->nrow);
for (i = 0; i < sparse_matrix->nrow; i++)
{
for (j = 0; j < sparse_matrix->ndata[i]; j++)
{
t_fileio *fio;
int i, j, prec;
- gmx_bool bDum = TRUE;
- gmx_bool bRead = TRUE;
char gmxver[256];
size_t sz;
sz = (*nrow) * (*ncol);
snew((*full_matrix), sz);
- bDum = gmx_fio_ndo_real(fio, (*full_matrix), sz);
+ gmx_fio_ndo_real(fio, (*full_matrix), sz);
}
else if (NULL != sparse_matrix)
{
snew((*sparse_matrix)->ndata, (*sparse_matrix)->nrow);
snew((*sparse_matrix)->nalloc, (*sparse_matrix)->nrow);
snew((*sparse_matrix)->data, (*sparse_matrix)->nrow);
- bDum = gmx_fio_ndo_int(fio, (*sparse_matrix)->ndata,
- (*sparse_matrix)->nrow);
+ gmx_fio_ndo_int(fio, (*sparse_matrix)->ndata,
+ (*sparse_matrix)->nrow);
for (i = 0; i < (*sparse_matrix)->nrow; i++)
{
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, 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.
#include "pdbio.h"
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cctype>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
#include "gromacs/fileio/gmxfio.h"
#include "gromacs/legacyheaders/copyrite.h"
int i, length;
char temp;
- length = strlen(name);
- if (length > 3 && isdigit(name[0]))
+ length = std::strlen(name);
+ if (length > 3 && std::isdigit(name[0]))
{
temp = name[0];
for (i = 1; i < length; i++)
int i, length;
char temp;
- length = strlen(name);
- if (length > 3 && isdigit(name[length-1]))
+ length = std::strlen(name);
+ if (length > 3 && std::isdigit(name[length-1]))
{
temp = name[length-1];
for (i = length-1; i > 0; --i)
if (norm2(box[YY])*norm2(box[ZZ]) != 0)
{
- alpha = RAD2DEG*acos(cos_angle_no_table(box[YY], box[ZZ]));
+ alpha = RAD2DEG*std::acos(cos_angle_no_table(box[YY], box[ZZ]));
}
else
{
}
if (norm2(box[XX])*norm2(box[ZZ]) != 0)
{
- beta = RAD2DEG*acos(cos_angle_no_table(box[XX], box[ZZ]));
+ beta = RAD2DEG*std::acos(cos_angle_no_table(box[XX], box[ZZ]));
}
else
{
}
if (norm2(box[XX])*norm2(box[YY]) != 0)
{
- gamma = RAD2DEG*acos(cos_angle_no_table(box[XX], box[YY]));
+ gamma = RAD2DEG*std::acos(cos_angle_no_table(box[XX], box[YY]));
}
else
{
{
if (alpha != 90.0)
{
- cosa = cos(alpha*DEG2RAD);
+ cosa = std::cos(alpha*DEG2RAD);
}
else
{
}
if (beta != 90.0)
{
- cosb = cos(beta*DEG2RAD);
+ cosb = std::cos(beta*DEG2RAD);
}
else
{
}
if (gamma != 90.0)
{
- cosg = cos(gamma*DEG2RAD);
- sing = sin(gamma*DEG2RAD);
+ cosg = std::cos(gamma*DEG2RAD);
+ sing = std::sin(gamma*DEG2RAD);
}
else
{
box[YY][YY] = fb*sing;
box[ZZ][XX] = fc*cosb;
box[ZZ][YY] = fc*(cosa - cosb*cosg)/sing;
- box[ZZ][ZZ] = sqrt(fc*fc
- - box[ZZ][XX]*box[ZZ][XX] - box[ZZ][YY]*box[ZZ][YY]);
+ box[ZZ][ZZ] = std::sqrt(fc*fc
+ - box[ZZ][XX]*box[ZZ][XX] - box[ZZ][YY]*box[ZZ][YY]);
}
else
{
char altloc;
real occup, bfac;
gmx_bool bOccup;
- int nlongname = 0;
int chainnum, lastchainnum;
- int lastresind, lastchainresind;
gmx_residuetype_t*rt;
const char *p_restype;
const char *p_lastrestype;
fprintf(out, "MODEL %8d\n", model_nr > 0 ? model_nr : 1);
- lastchainresind = -1;
lastchainnum = -1;
- resind = -1;
p_restype = NULL;
for (ii = 0; ii < nindex; ii++)
{
i = index[ii];
- lastresind = resind;
resind = atoms->atom[i].resind;
chainnum = atoms->resinfo[resind].chainnum;
p_lastrestype = p_restype;
fprintf(out, "TER\n");
}
lastchainnum = chainnum;
- lastchainresind = lastresind;
}
strncpy(resnm, *atoms->resinfo[resind].name, sizeof(resnm)-1);
}
if (atoms->pdbinfo)
{
- type = (enum PDB_record)(atoms->pdbinfo[i].type);
+ type = static_cast<enum PDB_record>(atoms->pdbinfo[i].type);
altloc = atoms->pdbinfo[i].altloc;
if (!isalnum(altloc))
{
for (k = 0; (k < epdbNR); k++)
{
- if (strncmp(type, pdbtp[k], strlen(pdbtp[k])) == 0)
+ if (std::strncmp(type, pdbtp[k], strlen(pdbtp[k])) == 0)
{
break;
}
trim(anm);
/* Search backwards for number and name only */
- atomnr = strtol(anr, NULL, 10);
+ atomnr = std::strtol(anr, NULL, 10);
for (i = natom-1; (i >= 0); i--)
{
- if ((strcmp(anm, *(atoms->atomname[i])) == 0) &&
+ if ((std::strcmp(anm, *(atoms->atomname[i])) == 0) &&
(atomnr == atoms->pdbinfo[i].atomnr))
{
break;
}
for (i = 0; (i < atoms->nr); i++)
{
- strcpy(anm, atoms->pdbinfo[i].atomnm);
- strcpy(anm_copy, atoms->pdbinfo[i].atomnm);
+ std::strcpy(anm, atoms->pdbinfo[i].atomnm);
+ std::strcpy(anm_copy, atoms->pdbinfo[i].atomnm);
len = strlen(anm);
atomnumber = NOTSET;
- if ((anm[0] != ' ') && ((len <= 2) || ((len > 2) && !isdigit(anm[2]))))
+ if ((anm[0] != ' ') && ((len <= 2) || ((len > 2) && !std::isdigit(anm[2]))))
{
anm_copy[2] = nc;
if (gmx_atomprop_query(aps, epropElement, "???", anm_copy, &eval))
if (atomnumber == NOTSET)
{
k = 0;
- while ((k < strlen(anm)) && (isspace(anm[k]) || isdigit(anm[k])))
+ while ((k < std::strlen(anm)) && (std::isspace(anm[k]) || std::isdigit(anm[k])))
{
k++;
}
}
atoms->atom[i].atomnumber = atomnumber;
ptr = gmx_atomprop_element(aps, atomnumber);
- strncpy(atoms->atom[i].elem, ptr == NULL ? "" : ptr, 4);
+ std::strncpy(atoms->atom[i].elem, ptr == NULL ? "" : ptr, 4);
if (debug)
{
fprintf(debug, "Atomnumber for atom '%s' is %d\n", anm, atomnumber);
anm[k] = line[j];
}
anm[k] = nc;
- strcpy(anm_copy, anm);
+ std::strcpy(anm_copy, anm);
rtrim(anm_copy);
atomnumber = NOTSET;
trim(anm);
}
rnr[k] = nc;
trim(rnr);
- resnr = strtol(rnr, NULL, 10);
+ resnr = std::strtol(rnr, NULL, 10);
resic = line[j];
j += 4;
{
char buf[30];
- strcpy(buf, nm);
+ std::strcpy(buf, nm);
trim(buf);
if (buf[0] == 'H')
{
return TRUE;
}
- else if ((isdigit(buf[0])) && (buf[1] == 'H'))
+ else if ((std::isdigit(buf[0])) && (buf[1] == 'H'))
{
return TRUE;
}
{
char buf[30];
- strcpy(buf, nm);
+ std::strcpy(buf, nm);
trim(buf);
- if ((buf[0] == 'M') && isdigit(buf[strlen(buf)-1]))
+ if ((buf[0] == 'M') && std::isdigit(buf[strlen(buf)-1]))
{
return TRUE;
}
{
do
{
- strcat(form2, "%*s");
+ std::strcat(form2, "%*s");
sprintf(format, "%s%%d", form2);
n = sscanf(line, format, &aj);
if (n == 1)
snew(gc, 1);
- return (gmx_conect) gc;
+ return gc;
}
void gmx_conect_done(gmx_conect conect)
{
- gmx_conect_t *gc = (gmx_conect_t *)conect;
+ gmx_conect_t *gc = conect;
sfree(gc->conect);
}
gmx_bool gmx_conect_exist(gmx_conect conect, int ai, int aj)
{
- gmx_conect_t *gc = (gmx_conect_t *)conect;
+ gmx_conect_t *gc = conect;
int i;
/* if (!gc->bSorted)
void gmx_conect_add(gmx_conect conect, int ai, int aj)
{
gmx_conect_t *gc = (gmx_conect_t *)conect;
- int i;
/* if (!gc->bSorted)
sort_conect(gc);*/
t_atoms *atoms, rvec x[], int *ePBC, matrix box, gmx_bool bChange,
gmx_conect conect)
{
- gmx_conect_t *gc = (gmx_conect_t *)conect;
+ gmx_conect_t *gc = conect;
t_symtab symtab;
gmx_bool bCOMPND;
gmx_bool bConnWarn = FALSE;
char line[STRLEN+1];
int line_type;
char *c, *d;
- int natom, chainnum, nres_ter_prev = 0;
- char chidmax = ' ';
+ int natom, chainnum;
gmx_bool bStop = FALSE;
if (ePBC)
case epdbTITLE:
case epdbHEADER:
- if (strlen(line) > 6)
+ if (std::strlen(line) > 6)
{
c = line+6;
/* skip HEADER or TITLE and spaces */
c++;
}
/* truncate after title */
- d = strstr(c, " ");
+ d = std::strstr(c, " ");
if (d)
{
d[0] = '\0';
}
- if (strlen(c) > 0)
+ if (std::strlen(c) > 0)
{
- strcpy(title, c);
+ std::strcpy(title, c);
}
}
break;
case epdbCOMPND:
- if ((!strstr(line, ": ")) || (strstr(line+6, "MOLECULE:")))
+ if ((!std::strstr(line, ": ")) || (std::strstr(line+6, "MOLECULE:")))
{
- if (!(c = strstr(line+6, "MOLECULE:")) )
+ if (!(c = std::strstr(line+6, "MOLECULE:")) )
{
c = line;
}
{
if (bCOMPND)
{
- strcat(title, "; ");
- strcat(title, c);
+ std::strcat(title, "; ");
+ std::strcat(title, c);
}
else
{
- strcpy(title, c);
+ std::strcpy(title, c);
}
}
bCOMPND = TRUE;
*natoms = 0;
while (fgets2(line, STRLEN, in))
{
- if (strncmp(line, "ENDMDL", 6) == 0)
+ if (std::strncmp(line, "ENDMDL", 6) == 0)
{
break;
}
- if ((strncmp(line, "ATOM ", 6) == 0) || (strncmp(line, "HETATM", 6) == 0))
+ if ((std::strncmp(line, "ATOM ", 6) == 0) || (std::strncmp(line, "HETATM", 6) == 0))
{
(*natoms)++;
}
/* If the atom name is an element name with two chars, it should start already in column 13.
* Otherwise it should start in column 14, unless the name length is 4 chars.
*/
- if ( (element != NULL) && (strlen(element) >= 2) && (gmx_strncasecmp(atom_name, element, 2) == 0) )
+ if ( (element != NULL) && (std::strlen(element) >= 2) && (gmx_strncasecmp(atom_name, element, 2) == 0) )
{
start_name_in_col13 = TRUE;
}
else
{
- start_name_in_col13 = (strlen(atom_name) >= 4);
+ start_name_in_col13 = (std::strlen(atom_name) >= 4);
}
sprintf(tmp_atomname, start_name_in_col13 ? "" : " ");
- strncat(tmp_atomname, atom_name, 4);
+ std::strncat(tmp_atomname, atom_name, 4);
tmp_atomname[5] = '\0';
}
else
}
/* Format residue name */
- strncpy(tmp_resname, (res_name != NULL) ? res_name : "", 4);
+ std::strncpy(tmp_resname, (res_name != NULL) ? res_name : "", 4);
/* Make sure the string is terminated if strlen was > 4 */
tmp_resname[4] = '\0';
/* String is properly terminated, so now we can use strcat. By adding a
* space we can write it right-justified, and if the original name was
* three characters or less there will be a space added on the right side.
*/
- strcat(tmp_resname, " ");
+ std::strcat(tmp_resname, " ");
/* Truncate integers so they fit */
atom_seq_number = atom_seq_number % 100000;
#include "strdb.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/fatalerror.h"
sfree(line0);
return FALSE;
}
- dum = strchr(line0, '\n');
+ dum = std::strchr(line0, '\n');
if (dum)
{
dum[0] = '\0';
}
- else if (strlen(line0) == n)
+ else if (static_cast<int>(std::strlen(line0)) == n)
{
fprintf(stderr, "Warning: line length exceeds buffer length (%d), data might be corrupted\n", n);
line0[n-1] = '\0';
fprintf(stderr, "Warning: file does not end with a newline, last line:\n%s\n",
line0);
}
- dum = strchr(line0, ';');
+ dum = std::strchr(line0, ';');
if (dum)
{
dum[0] = '\0';
}
- strncpy(line, line0, n);
+ std::strncpy(line, line0, n);
dum = line0;
ltrim(dum);
}
{
char temp[STRLEN], *dum;
- strcpy(temp, line);
- dum = strchr(temp, '[');
+ std::strcpy(temp, line);
+ dum = std::strchr(temp, '[');
if (dum == NULL)
{
return FALSE;
}
dum[0] = ' ';
- dum = strchr(temp, ']');
+ dum = std::strchr(temp, ']');
if (dum == NULL)
{
gmx_fatal(FARGS, "header is not terminated on line:\n'%s'\n", line);
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, 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.
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, 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.
#include "config.h"
-#include <math.h>
+#include <cmath>
#ifdef GMX_USE_TNG
#include "tng/tng_io.h"
frame->step,
frame->time,
0,
- (const rvec *) frame->box,
+ frame->box,
natoms,
- (const rvec *) frame->x,
- (const rvec *) frame->v,
- (const rvec *) frame->f);
+ frame->x,
+ frame->v,
+ frame->f);
#else
GMX_UNUSED_VALUE(output);
GMX_UNUSED_VALUE(frame);
{
for (j = 0; j < nValues; j++)
{
- to[i*nValues+j] = (real)((float *)from)[i*nValues+j] * fact;
+ to[i*nValues+j] = reinterpret_cast<float *>(from)[i*nValues+j] * fact;
}
}
}
{
for (j = 0; j < nValues; j++)
{
- to[i*nValues+j] = (real)((float *)from)[i*nValues+j] * fact;
+ to[i*nValues+j] = reinterpret_cast<float *>(from)[i*nValues+j] * fact;
}
}
}
{
for (j = 0; j < nValues; j++)
{
- to[i*nValues+j] = (real)((gmx_int64_t *)from)[i*nValues+j] * fact;
+ to[i*nValues+j] = reinterpret_cast<gmx_int64_t *>(from)[i*nValues+j] * fact;
}
}
break;
{
for (j = 0; j < nValues; j++)
{
- to[i*nValues+j] = (real)((double *)from)[i*nValues+j] * fact;
+ to[i*nValues+j] = reinterpret_cast<double *>(from)[i*nValues+j] * fact;
}
}
}
{
for (j = 0; j < nValues; j++)
{
- to[i*nValues+j] = (real)((double *)from)[i*nValues+j] * fact;
+ to[i*nValues+j] = reinterpret_cast<double *>(from)[i*nValues+j] * fact;
}
}
}
}
for (int i = 0; i < DIM; i++)
{
- convert_array_to_real_array((char *)(values) + size * i * DIM,
- (real *) fr->box[i],
+ convert_array_to_real_array(reinterpret_cast<char *>(values) + size * i * DIM,
+ reinterpret_cast<real *>(fr->box[i]),
getDistanceScaleFactor(input),
1,
DIM,
case TNG_TRAJ_POSITIONS:
srenew(fr->x, fr->natoms);
convert_array_to_real_array(values,
- (real *) fr->x,
+ reinterpret_cast<real *>(fr->x),
getDistanceScaleFactor(input),
fr->natoms,
DIM,
case TNG_TRAJ_FORCES:
srenew(fr->f, fr->natoms);
convert_array_to_real_array(values,
- (real *) fr->f,
+ reinterpret_cast<real *>(fr->f),
getDistanceScaleFactor(input),
fr->natoms,
DIM,
switch (datatype)
{
case TNG_FLOAT_DATA:
- fr->lambda = (*(float *)values);
+ fr->lambda = *(reinterpret_cast<float *>(values));
break;
case TNG_DOUBLE_DATA:
- fr->lambda = (*(double *)values);
+ fr->lambda = *(reinterpret_cast<double *>(values));
break;
default:
gmx_incons("Illegal datatype lambda value!");
* be reallocated if it is not NULL. */
}
- fr->step = (int) frameNumber;
+ fr->step = static_cast<int>(frameNumber);
fr->bStep = TRUE;
// Convert the time to ps
fr->time = frameTime / PICO;
#include "tpxio.h"
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/fileio/confio.h"
#include "gromacs/fileio/filenm.h"
gmx_bool bRead,
int file_version)
{
- int i;
rvec tmp;
gmx_fio_do_int(fio, pgrp->nat);
static void do_pull_group(t_fileio *fio, t_pull_group *pgrp, gmx_bool bRead)
{
- int i;
-
gmx_fio_do_int(fio, pgrp->nat);
if (bRead)
{
static void do_pull_coord(t_fileio *fio, t_pull_coord *pcrd, int file_version,
int ePullOld, int eGeomOld, ivec dimOld)
{
- int i;
-
gmx_fio_do_int(fio, pcrd->group[0]);
gmx_fio_do_int(fio, pcrd->group[1]);
if (file_version >= tpxv_PullCoordTypeGeom)
static void do_expandedvals(t_fileio *fio, t_expanded *expand, t_lambda *fepvals, gmx_bool bRead, int file_version)
{
- /* i is used in the ndo_double macro*/
- int i;
- real fv;
- real rdum;
int n_lambda = fepvals->n_lambda;
/* reset the lambda calculation window */
static void do_fepvals(t_fileio *fio, t_lambda *fepvals, gmx_bool bRead, int file_version)
{
/* i is defined in the ndo_double macro; use g to iterate. */
- int i, g;
- real fv;
+ int g;
real rdum;
/* free energy values */
static void do_pull(t_fileio *fio, pull_params_t *pull, gmx_bool bRead,
int file_version, int ePullOld)
{
- int eGeomOld;
+ int eGeomOld = -1;
ivec dimOld;
int g;
for (g = 0; g < pull->ngroup; g++)
{
/* We read and ignore a pull coordinate for group 0 */
- do_pullgrp_tpx_pre95(fio, &pull->group[g], &pull->coord[max(g-1, 0)],
+ do_pullgrp_tpx_pre95(fio, &pull->group[g], &pull->coord[std::max(g-1, 0)],
bRead, file_version);
if (g > 0)
{
static void do_rotgrp(t_fileio *fio, t_rotgrp *rotg, gmx_bool bRead)
{
- int i;
-
gmx_fio_do_int(fio, rotg->eType);
gmx_fio_do_int(fio, rotg->bMassW);
gmx_fio_do_int(fio, rotg->nat);
static void do_swapcoords(t_fileio *fio, t_swapcoords *swap, gmx_bool bRead)
{
- int i, j;
-
+ int j;
gmx_fio_do_int(fio, swap->nat);
gmx_fio_do_int(fio, swap->nat_sol);
static void do_ilist(t_fileio *fio, t_ilist *ilist, gmx_bool bRead, int file_version)
{
- int i, k, idum;
+ int i, idum;
if (file_version < 44)
{
static void do_ffparams(t_fileio *fio, gmx_ffparams_t *ffparams,
gmx_bool bRead, int file_version)
{
- int idum, i, j;
+ int idum, i;
unsigned int k;
gmx_fio_do_int(fio, ffparams->atnr);
static void do_ilists(t_fileio *fio, t_ilist *ilist, gmx_bool bRead,
int file_version)
{
- int i, j, renum[F_NRE];
+ int j;
gmx_bool bClear;
unsigned int k;
int file_version, gmx_groups_t *groups, int atnr)
{
int i, myngrp;
- char * p_elem;
gmx_fio_do_real(fio, atom->m);
gmx_fio_do_real(fio, atom->q);
/* Set element string from atomic number if present.
* This routine returns an empty string if the name is not found.
*/
- strncpy(atom->elem, atomicnumber_to_element(atom->atomnumber), 4);
+ std::strncpy(atom->elem, atomicnumber_to_element(atom->atomnumber), 4);
/* avoid warnings about potentially unterminated string */
atom->elem[3] = '\0';
}
static void do_grps(t_fileio *fio, int ngrp, t_grps grps[], gmx_bool bRead,
int file_version)
{
- int i, j, myngrp;
+ int j, myngrp;
if (file_version < 23)
{
gmx_bool bRead, t_symtab *symtab,
int file_version)
{
- int g, n, i;
+ int g;
do_grps(fio, egcNR, groups->grps, bRead, file_version);
gmx_fio_do_int(fio, groups->ngrpname);
static void do_atomtypes(t_fileio *fio, t_atomtypes *atomtypes, gmx_bool bRead,
int file_version)
{
- int i, j;
+ int j;
if (file_version > 25)
{
t_symtab *symtab, int file_version,
gmx_groups_t *groups)
{
- int i;
-
if (file_version >= 57)
{
do_symstr(fio, &(molt->name), bRead, symtab);
static void do_molblock(t_fileio *fio, gmx_molblock_t *molb, gmx_bool bRead)
{
- int i;
-
gmx_fio_do_int(fio, molb->type);
gmx_fio_do_int(fio, molb->nmol);
gmx_fio_do_int(fio, molb->natoms_mol);
for (i = 0; i < il->nr; i += 2)
{
ip = &mtop->ffparams.iparams[il->iatoms[i]];
- am = max(am, il->iatoms[i+1]);
+ am = std::max(am, il->iatoms[i+1]);
if (ip->posres.pos0B[XX] != ip->posres.pos0A[XX] ||
ip->posres.pos0B[YY] != ip->posres.pos0A[YY] ||
ip->posres.pos0B[ZZ] != ip->posres.pos0A[ZZ])
{
for (i = 0; i < ilfb->nr; i += 2)
{
- ip = &mtop->ffparams.iparams[ilfb->iatoms[i]];
- am = max(am, ilfb->iatoms[i+1]);
+ am = std::max(am, ilfb->iatoms[i+1]);
}
}
/* Make the posres coordinate block end at a molecule end */
static void do_mtop(t_fileio *fio, gmx_mtop_t *mtop, gmx_bool bRead,
int file_version)
{
- int mt, mb, i;
+ int mt, mb;
t_blocka dumb;
if (bRead)
if (bRead)
{
gmx_fio_do_string(fio, buf);
- if (strncmp(buf, "VERSION", 7))
+ if (std::strncmp(buf, "VERSION", 7))
{
gmx_fatal(FARGS, "Can not read file %s,\n"
" this file is from a GROMACS version which is older than 2.0\n"
sprintf(file_tag, "%s", TPX_TAG_RELEASE);
}
- if (strcmp(file_tag, tpx_tag) != 0)
+ if (std::strcmp(file_tag, tpx_tag) != 0)
{
fprintf(stderr, "Note: file tpx tag '%s', software tpx tag '%s'\n",
file_tag, tpx_tag);
/* We only support reading tpx files with the same tag as the code
* or tpx files with the release tag and with lower version number.
*/
- if (strcmp(file_tag, TPX_TAG_RELEASE) != 0 && fver < tpx_version)
+ if (std::strcmp(file_tag, TPX_TAG_RELEASE) != 0 && fver < tpx_version)
{
gmx_fatal(FARGS, "tpx tag/version mismatch: reading tpx file (%s) version %d, tag '%s' with program for tpx version %d, tag '%s'",
gmx_fio_getname(fio), fver, file_tag,
gmx_mtop_t dum_top;
gmx_bool TopOnlyOK;
int file_version, file_generation;
- int i;
rvec *xptr, *vptr;
int ePBC;
gmx_bool bPeriodicMols;
rvec *x, rvec *v, rvec *f, t_topology *top)
{
gmx_mtop_t mtop;
- t_topology *ltop;
int ePBC;
ePBC = read_tpx(fn, ir, box, natoms, x, v, f, &mtop);
int natoms, i, version, generation;
gmx_bool bTop, bXNULL = FALSE;
gmx_mtop_t *mtop;
- t_topology *topconv;
gmx_atomprop_t aps;
bTop = fn2bTPX(infile);
/* In this case we need to throw away the group data too */
done_gmx_groups_t(&mtop->groups);
sfree(mtop);
- strcpy(title, *top->name);
+ std::strcpy(title, *top->name);
tpx_make_chain_identifiers(&top->atoms, &top->mols);
}
else
#include "trnio.h"
-#include <string.h>
+#include <cstring>
#include "gromacs/fileio/gmxfio.h"
#include "gromacs/fileio/gmxfio-xdr.h"
#include "config.h"
-#include <assert.h>
-#include <math.h>
+#include <cassert>
+#include <cmath>
#include "gromacs/fileio/confio.h"
#include "gromacs/fileio/gmxfio.h"
#include "gromacs/topology/atoms.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
#ifdef GMX_USE_PLUGINS
real pt;
int ct;
gmx_bool bOK, bRet, bMissingData = FALSE, bSkip = FALSE;
- int dummy = 0;
int ftp;
bRet = FALSE;
{
t_fileio *fio;
gmx_bool bFirst, bOK;
- int dummy = 0;
int ftp = fn2ftp(fn);
- gmx_int64_t *tng_ids;
clear_trxframe(fr, TRUE);
fr->flags = flags;
{
snew(fr->v, fr->natoms);
}
- fio = (*status)->fio = gmx_fio_open(fn, "r");
+ (*status)->fio = gmx_fio_open(fn, "r");
break;
case efXTC:
if (read_first_xtc(fio, &fr->natoms, &fr->step, &fr->time, fr->box, &fr->x,
&fr->prec, &bOK) == 0)
{
- assert(!bOK);
+ GMX_RELEASE_ASSERT(!bOK, "Inconsistent results - OK status from read_first_xtc, but 0 atom coords read");
fr->not_ok = DATA_NOT_OK;
}
if (fr->not_ok)
static int load_vmd_library(const char *fn, t_gmxvmdplugin *vmdplugin)
{
- char pathname[GMX_PATH_MAX], filename[GMX_PATH_MAX];
+ char pathname[GMX_PATH_MAX];
const char *pathenv;
const char *err;
- int i;
int ret = 0;
char pathenv_buffer[GMX_PATH_MAX];
#ifndef GMX_NATIVE_WINDOWS
"The architecture (e.g. 32bit versus 64bit) of GROMACS and VMD has to match.\n");
return 0;
}
- for (i = 0; i < globbuf.gl_pathc && vmdplugin->api == NULL; i++)
+ for (size_t i = 0; i < globbuf.gl_pathc && vmdplugin->api == NULL; i++)
{
/* FIXME: Undefined which plugin is chosen if more than one plugin
can read a certain file ending. Requires some additional command
}
do
{
+ char filename[GMX_PATH_MAX];
sprintf(filename, "%s\\%s", pathenv, ffd.cFileName);
ret |= load_sharedlibrary_plugins(filename, vmdplugin);
}
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, 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.
#include "writeps.h"
-#include <stdio.h>
+#include <cstdio>
#include "gromacs/fileio/gmxfio.h"
#include "gromacs/utility/fatalerror.h"
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, 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.
sfree(ffp);
return ret;
#else
- return xdr3dfcoord(xdrs, (float *)fp, size, (float *)precision);
+ return xdr3dfcoord(xdrs, reinterpret_cast<float *>(fp), size, reinterpret_cast<float *>(precision));
#endif
}
imaj64 = ((*i)>>32) & two_p32_m1;
imin64 = (*i) & two_p32_m1;
- imaj = (int)imaj64;
- imin = (int)imin64;
+ imaj = static_cast<int>(imaj64);
+ imin = static_cast<int>(imin64);
ret = xdr_int(xdrs, &imaj);
ret |= xdr_int(xdrs, &imin);
- *i = (((gmx_int64_t)imaj << 32) | ((gmx_int64_t)imin & two_p32_m1));
+ *i = ((static_cast<gmx_int64_t>(imaj) << 32) | (static_cast<gmx_int64_t>(imin) & two_p32_m1));
return ret;
}
#include "config.h"
#if GMX_INTERNAL_XDR
-#include "gromacs/fileio/gmx_system_xdr.h"
+#include "gromacs/fileio/gmx_internal_xdr.h"
#else
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include "xtcio.h"
-#include <string.h>
+#include <cstring>
#include "gromacs/fileio/gmxfio.h"
#include "gromacs/fileio/gmxfio-xdr.h"
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, 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.
#include "xvgr.h"
-#include <ctype.h>
-#include <string.h>
+#include <cctype>
+#include <cstring>
#include "gromacs/fileio/gmxfio.h"
#include "gromacs/legacyheaders/copyrite.h"
break;
}
g++;
- b = strlen(buf);
+ b = std::strlen(buf);
}
else
{
/* Check for special symbol */
i = 0;
while (sym[i] != NULL &&
- gmx_strncasecmp(sym[i], gmx+g, strlen(sym[i])) != 0)
+ gmx_strncasecmp(sym[i], gmx+g, std::strlen(sym[i])) != 0)
{
i++;
}
if (sym[i] != NULL)
{
c = symc[i];
- if (isupper(gmx[g]))
+ if (std::isupper(gmx[g]))
{
- c = toupper(c);
+ c = std::toupper(c);
}
switch (xvgf)
{
sprintf(buf+b, "%s%c%s", "\\8", c, "\\4");
break;
default:
- strncat(buf+b, gmx+g, strlen(sym[i]));
- b += strlen(sym[i]);
- if (gmx[g+strlen(sym[i])] != ' ')
+ std::strncat(buf+b, gmx+g, std::strlen(sym[i]));
+ b += std::strlen(sym[i]);
+ if (gmx[g+std::strlen(sym[i])] != ' ')
{
buf[b++] = ' ';
}
buf[b] = '\0';
break;
}
- g += strlen(sym[i]);
- b = strlen(buf);
+ g += std::strlen(sym[i]);
+ b = std::strlen(buf);
}
else
{
curp += len_remaining-1; /* overwrite the nul char in next iteration */
len_remaining = 1;
}
- while ((strchr(*ptr, '\n') == NULL) && (!feof(fp)));
+ while ((std::strchr(*ptr, '\n') == NULL) && (!feof(fp)));
if (*len + STRLEN >= maxlen)
{
}
{
/* now remove newline */
- int slen = strlen(*ptr);
+ int slen = std::strlen(*ptr);
if ((*ptr)[slen-1] == '\n')
{
(*ptr)[slen-1] = '\0';
{
for (i = 0; (ptr[i] != '\0'); i++)
{
- is[cur] = isspace(ptr[i]);
+ is[cur] = std::isspace(ptr[i]);
if ((0 == i) && !is[cur])
{
n++;
const char *ptr0, *ptr1;
char *str;
- ptr0 = strchr(line, '"');
+ ptr0 = std::strchr(line, '"');
if (ptr0 != NULL)
{
ptr0++;
- ptr1 = strchr(ptr0, '"');
+ ptr1 = std::strchr(ptr0, '"');
if (ptr1 != NULL)
{
str = gmx_strdup(ptr0);
ptr++;
trim(ptr);
set = -1;
- if (strncmp(ptr, "subtitle", 8) == 0)
+ if (std::strncmp(ptr, "subtitle", 8) == 0)
{
ptr += 8;
if (subtitle != NULL)
*subtitle = read_xvgr_string(ptr);
}
}
- else if (strncmp(ptr, "legend string", 13) == 0)
+ else if (std::strncmp(ptr, "legend string", 13) == 0)
{
ptr += 13;
sscanf(ptr, "%d%n", &set, &nchar);
sscanf(ptr, "%d%n", &set, &nchar);
ptr += nchar;
trim(ptr);
- if (strncmp(ptr, "legend", 6) == 0)
+ if (std::strncmp(ptr, "legend", 6) == 0)
{
ptr += 6;
}
/* fprintf(stderr,"ptr='%s'\n",ptr);*/
for (k = 0; (k < nny); k++)
{
- strcpy(fmt, base);
- strcat(fmt, "%lf");
+ std::strcpy(fmt, base);
+ std::strcat(fmt, "%lf");
rval = sscanf(ptr, fmt, &lf);
/* fprintf(stderr,"rval = %d\n",rval);*/
if ((rval == EOF) || (rval == 0))
yy[k][nx] = lf;
srenew(fmt, 3*(nny+1)+1);
srenew(base, 3*nny+1);
- strcat(base, "%*s");
+ std::strcat(base, "%*s");
}
if (k != nny)
{