From: Erik Lindahl Date: Sat, 11 Jul 2015 20:51:14 +0000 (+0200) Subject: Move fileio sources to C++ X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?p=alexxy%2Fgromacs.git;a=commitdiff_plain;h=a772ad17234cccd6ec9572f9904a03266bfbd129 Move fileio sources to C++ String functions have been moved into std namespace, unused variables removed. The internal XDR implementation has been modified to work in C++, and while doing so it has been renamed to gmx_internal_xdr.cpp to avoid confusion with the external system implementations. Change-Id: Iadaf812da88ba24530b637b8e3259fd3cac417e0 --- diff --git a/src/gromacs/fileio/confio.c b/src/gromacs/fileio/confio.cpp similarity index 96% rename from src/gromacs/fileio/confio.c rename to src/gromacs/fileio/confio.cpp index c8a35d79cf..e7fbebf333 100644 --- a/src/gromacs/fileio/confio.c +++ b/src/gromacs/fileio/confio.cpp @@ -38,9 +38,13 @@ #include "confio.h" -#include -#include -#include +#include +#include +#include +#include +#include + +#include #include "gromacs/fileio/filenm.h" #include "gromacs/fileio/gmxfio.h" @@ -96,7 +100,7 @@ static int read_g96_pos(char line[], t_symtab *symtab, 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) @@ -250,7 +254,7 @@ int read_g96_conf(FILE *fp, const char *infile, t_trxframe *fr, char *line) { while (!fr->bTitle && fgets2(line, STRLEN, fp)) { - fr->bTitle = (strcmp(line, "TITLE") == 0); + fr->bTitle = (std::strcmp(line, "TITLE") == 0); } if (fr->title == NULL) { @@ -260,7 +264,7 @@ int read_g96_conf(FILE *fp, const char *infile, t_trxframe *fr, char *line) bEnd = FALSE; while (!bEnd && fgets2(line, STRLEN, fp)) { - bEnd = (strcmp(line, "END") == 0); + bEnd = (std::strcmp(line, "END") == 0); } fgets2(line, STRLEN, fp); } @@ -272,11 +276,11 @@ int read_g96_conf(FILE *fp, const char *infile, t_trxframe *fr, char *line) 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) @@ -601,7 +605,7 @@ static void read_espresso_conf(const char *infile, 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; @@ -622,7 +626,7 @@ static void read_espresso_conf(const char *infile, 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"); @@ -684,7 +688,7 @@ static void read_espresso_conf(const char *infile, 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); @@ -708,7 +712,7 @@ static void read_espresso_conf(const char *infile, 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) { @@ -768,13 +772,13 @@ static void read_espresso_conf(const char *infile, 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++) { @@ -1024,11 +1028,11 @@ static gmx_bool get_w_conf(FILE *in, const char *infile, char *title, } /* 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 */ @@ -1094,8 +1098,8 @@ static gmx_bool get_w_conf(FILE *in, const char *infile, char *title, { 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++) @@ -1325,25 +1329,25 @@ void write_hconf_indexed_p(FILE *out, const char *title, t_atoms *atoms, 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); @@ -1632,12 +1636,10 @@ void read_stx_conf(const char *infile, char *title, t_atoms *atoms, 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) @@ -1671,7 +1673,7 @@ void read_stx_conf(const char *infile, char *title, t_atoms *atoms, 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: diff --git a/src/gromacs/fileio/enxio.c b/src/gromacs/fileio/enxio.cpp similarity index 97% rename from src/gromacs/fileio/enxio.c rename to src/gromacs/fileio/enxio.cpp index 892ef18119..ece8f4eea4 100644 --- a/src/gromacs/fileio/enxio.c +++ b/src/gromacs/fileio/enxio.cpp @@ -38,8 +38,10 @@ #include "enxio.h" -#include -#include +#include +#include + +#include #include "gromacs/fileio/gmxfio.h" #include "gromacs/fileio/gmxfio-xdr.h" @@ -50,6 +52,7 @@ #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. @@ -386,7 +389,6 @@ void do_enxnms(ener_file_t ef, int *nre, gmx_enxnm_t **nms) XDR *xdr; gmx_bool bRead = gmx_fio_getread(ef->fio); int file_version; - int i; xdr = gmx_fio_getxdr(ef->fio); @@ -438,9 +440,8 @@ static gmx_bool do_eheader(ener_file_t ef, int *file_version, t_enxframe *fr, { 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 @@ -536,7 +537,7 @@ static gmx_bool do_eheader(ener_file_t ef, int *file_version, t_enxframe *fr, } else { - fr->nsteps = max(1, fr->nsum); + fr->nsteps = std::max(1, fr->nsum); } if (*file_version >= 5) { @@ -596,7 +597,10 @@ static gmx_bool do_eheader(ener_file_t ef, int *file_version, t_enxframe *fr, ((fr->nre > 0 && fr->nre != nre_test) || fr->nre < 0 || ndisre < 0 || fr->nblock < 0)) { - *bWrongPrecision = TRUE; + if (bWrongPrecision) + { + *bWrongPrecision = TRUE; + } return *bOK; } @@ -746,7 +750,17 @@ void close_enx(ener_file_t ef) } } -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; @@ -758,13 +772,15 @@ static gmx_bool empty_file(const char *fn) 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; @@ -970,7 +986,7 @@ gmx_bool do_enx(ener_file_t ef, 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); } @@ -1045,7 +1061,6 @@ gmx_bool do_enx(ener_file_t ef, t_enxframe *fr) } /* read/write data */ - bOK1 = TRUE; switch (sub->type) { case xdr_datatype_float: @@ -1107,7 +1122,7 @@ static real find_energy(const char *name, int nre, gmx_enxnm_t *enm, 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; } @@ -1128,10 +1143,6 @@ void get_enx_state(const char *fn, real t, gmx_groups_t *groups, t_inputrec *ir, "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" }; diff --git a/src/gromacs/fileio/filenm.c b/src/gromacs/fileio/filenm.cpp similarity index 97% rename from src/gromacs/fileio/filenm.c rename to src/gromacs/fileio/filenm.cpp index 1333091c11..ca750d2200 100644 --- a/src/gromacs/fileio/filenm.c +++ b/src/gromacs/fileio/filenm.cpp @@ -38,8 +38,8 @@ #include "filenm.h" -#include -#include +#include +#include #include "gromacs/legacyheaders/macros.h" #include "gromacs/legacyheaders/types/commrec.h" @@ -169,10 +169,6 @@ static const t_deffile { 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)) @@ -312,7 +308,7 @@ int fn2ftp(const char *fn) return efNR; } - len = strlen(fn); + len = std::strlen(fn); if ((len >= 4) && (fn[len - 4] == '.')) { feptr = &(fn[len - 4]); @@ -342,7 +338,7 @@ const char *opt2fn(const char *opt, int nfile, const t_filenm fnm[]) 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]; } @@ -432,7 +428,7 @@ gmx_bool opt2bSet(const char *opt, int nfile, const t_filenm fnm[]) 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]); } @@ -449,7 +445,7 @@ const char *opt2fn_null(const char *opt, int nfile, const t_filenm fnm[]) 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])) { @@ -504,7 +500,7 @@ gmx_bool is_set(const t_filenm *fnm) 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; @@ -516,7 +512,7 @@ int add_suffix_to_output_names(t_filenm *fnm, int nfile, const char *suffix) 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); diff --git a/src/gromacs/fileio/gmx_system_xdr.c b/src/gromacs/fileio/gmx_internal_xdr.cpp similarity index 86% rename from src/gromacs/fileio/gmx_system_xdr.c rename to src/gromacs/fileio/gmx_internal_xdr.cpp index 3a01286733..d711909f3a 100644 --- a/src/gromacs/fileio/gmx_system_xdr.c +++ b/src/gromacs/fileio/gmx_internal_xdr.cpp @@ -41,11 +41,10 @@ #if GMX_INTERNAL_XDR -#include "gmx_system_xdr.h" +#include "gmx_internal_xdr.h" -#include -#include -#include +#include +#include /* NB - THIS FILE IS ONLY USED ON MICROSOFT WINDOWS, since that @@ -103,8 +102,8 @@ static xdr_uint32_t xdr_swapbytes(xdr_uint32_t x) { xdr_uint32_t y; int i; - char *px = (char *)&x; - char *py = (char *)&y; + char *px = reinterpret_cast(&x); + char *py = reinterpret_cast(&y); for (i = 0; i < 4; i++) { @@ -117,7 +116,7 @@ static xdr_uint32_t xdr_swapbytes(xdr_uint32_t x) static xdr_uint32_t xdr_htonl(xdr_uint32_t x) { short s = 0x0F00; - if (*((char *)&s) == (char)0x0F) + if (*(reinterpret_cast(&s)) == static_cast(0x0F)) { /* bigendian, do nothing */ return x; @@ -132,7 +131,7 @@ static xdr_uint32_t xdr_htonl(xdr_uint32_t x) static xdr_uint32_t xdr_ntohl(xdr_uint32_t x) { short s = 0x0F00; - if (*((char *)&s) == (char)0x0F) + if (*(reinterpret_cast(&s)) == static_cast(0x0F)) { /* bigendian, do nothing */ return x; @@ -178,7 +177,7 @@ xdr_int (XDR *xdrs, int *ip) switch (xdrs->x_op) { case XDR_ENCODE: - l = (xdr_int32_t) (*ip); + l = static_cast(*ip); return xdr_putint32 (xdrs, &l); case XDR_DECODE: @@ -186,7 +185,7 @@ xdr_int (XDR *xdrs, int *ip) { return FALSE; } - *ip = (int) l; + *ip = static_cast(l); case XDR_FREE: return TRUE; @@ -206,7 +205,7 @@ xdr_u_int (XDR *xdrs, unsigned int *up) switch (xdrs->x_op) { case XDR_ENCODE: - l = (xdr_uint32_t) (*up); + l = static_cast(*up); return xdr_putuint32 (xdrs, &l); case XDR_DECODE: @@ -214,7 +213,7 @@ xdr_u_int (XDR *xdrs, unsigned int *up) { return FALSE; } - *up = (unsigned int) l; + *up = static_cast(l); case XDR_FREE: return TRUE; @@ -236,7 +235,7 @@ xdr_short (XDR *xdrs, short *sp) switch (xdrs->x_op) { case XDR_ENCODE: - l = (xdr_int32_t) *sp; + l = static_cast(*sp); return xdr_putint32 (xdrs, &l); case XDR_DECODE: @@ -244,7 +243,7 @@ xdr_short (XDR *xdrs, short *sp) { return FALSE; } - *sp = (short) l; + *sp = static_cast(l); return TRUE; case XDR_FREE: @@ -265,7 +264,7 @@ xdr_u_short (XDR *xdrs, unsigned short *usp) switch (xdrs->x_op) { case XDR_ENCODE: - l = (xdr_uint32_t) *usp; + l = static_cast(*usp); return xdr_putuint32 (xdrs, &l); case XDR_DECODE: @@ -273,7 +272,7 @@ xdr_u_short (XDR *xdrs, unsigned short *usp) { return FALSE; } - *usp = (unsigned short) l; + *usp = static_cast(l); return TRUE; case XDR_FREE: @@ -391,7 +390,7 @@ xdr_opaque (XDR *xdrs, char *cp, unsigned int cnt) { return TRUE; } - return xdr_getbytes (xdrs, (char *)crud, rndup); + return xdr_getbytes (xdrs, crud, rndup); case XDR_ENCODE: if (!xdr_putbytes (xdrs, cp, cnt)) @@ -419,11 +418,7 @@ xdr_opaque (XDR *xdrs, char *cp, unsigned int 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; @@ -445,7 +440,7 @@ unsigned int maxsize; { return FALSE; } - size = strlen (sp); + size = std::strlen (sp); break; case XDR_DECODE: break; @@ -473,7 +468,7 @@ unsigned int maxsize; } if (sp == NULL) { - *cpp = sp = (char *) malloc (nodesize); + *cpp = sp = static_cast(std::malloc (nodesize)); } if (sp == NULL) { @@ -498,10 +493,7 @@ unsigned int maxsize; /* 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; @@ -509,7 +501,7 @@ float *fp; { case XDR_ENCODE: - tmp = *(xdr_int32_t *)fp; + tmp = *(reinterpret_cast(fp)); return (xdr_putint32(xdrs, &tmp)); break; @@ -517,7 +509,7 @@ float *fp; case XDR_DECODE: if (xdr_getint32(xdrs, &tmp)) { - *(xdr_int32_t *)fp = tmp; + *(reinterpret_cast(fp)) = tmp; return (TRUE); } @@ -530,10 +522,7 @@ float *fp; } -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 @@ -564,7 +553,7 @@ double *dp; * B B 3f ef 9a dd 3c 0e 56 b8 */ - unsigned char ix = *((char *)&x); + unsigned char ix = *(reinterpret_cast(&x)); if (ix == 0xdd || ix == 0x3f) { @@ -588,7 +577,7 @@ double *dp; { case XDR_ENCODE: - ip = (int *)dp; + ip = reinterpret_cast(dp); tmp[0] = ip[!LSW]; tmp[1] = ip[LSW]; return (xdr_putint32(xdrs, tmp) && @@ -597,7 +586,7 @@ double *dp; break; case XDR_DECODE: - ip = (int *)dp; + ip = reinterpret_cast(dp); if (xdr_getint32(xdrs, tmp+!LSW) && xdr_getint32(xdrs, tmp+LSW)) { @@ -627,13 +616,8 @@ double *dp; * > 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; @@ -665,40 +649,6 @@ static bool_t xdrstdio_putint32 (XDR *, xdr_int32_t *); 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. @@ -706,7 +656,7 @@ xdrstdio_create (XDR *xdrs, FILE *file, enum xdr_op op) static void xdrstdio_destroy (XDR *xdrs) { - (void) fflush ((FILE *) xdrs->x_private); + fflush (reinterpret_cast(xdrs->x_private)); /* xx should we close the file ?? */ } @@ -714,8 +664,8 @@ xdrstdio_destroy (XDR *xdrs) 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(len), 1, + reinterpret_cast(xdrs->x_private)) != 1)) { return FALSE; } @@ -725,8 +675,8 @@ xdrstdio_getbytes (XDR *xdrs, char *addr, unsigned int len) 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(len), 1, + reinterpret_cast(xdrs->x_private)) != 1)) { return FALSE; } @@ -736,13 +686,13 @@ xdrstdio_putbytes (XDR *xdrs, char *addr, unsigned int len) static unsigned int xdrstdio_getpos (XDR *xdrs) { - return (unsigned int) ftell ((FILE *) xdrs->x_private); + return static_cast(ftell (reinterpret_cast(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(xdrs->x_private), static_cast(pos), 0) < 0 ? FALSE : TRUE; } static xdr_int32_t * @@ -767,7 +717,7 @@ xdrstdio_getint32 (XDR *xdrs, xdr_int32_t *ip) { xdr_int32_t mycopy; - if (fread ((char *) &mycopy, 4, 1, (FILE *) xdrs->x_private) != 1) + if (fread (&mycopy, 4, 1, reinterpret_cast(xdrs->x_private)) != 1) { return FALSE; } @@ -781,7 +731,7 @@ xdrstdio_putint32 (XDR *xdrs, xdr_int32_t *ip) 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(xdrs->x_private)) != 1) { return FALSE; } @@ -793,7 +743,7 @@ xdrstdio_getuint32 (XDR *xdrs, xdr_uint32_t *ip) { xdr_uint32_t mycopy; - if (fread ((char *) &mycopy, 4, 1, (FILE *) xdrs->x_private) != 1) + if (fread (&mycopy, 4, 1, reinterpret_cast(xdrs->x_private)) != 1) { return FALSE; } @@ -807,14 +757,45 @@ xdrstdio_putuint32 (XDR *xdrs, xdr_uint32_t *ip) 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(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(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 */ diff --git a/src/gromacs/fileio/gmx_system_xdr.h b/src/gromacs/fileio/gmx_internal_xdr.h similarity index 98% rename from src/gromacs/fileio/gmx_system_xdr.h rename to src/gromacs/fileio/gmx_internal_xdr.h index 23e156bec7..bc38df8afd 100644 --- a/src/gromacs/fileio/gmx_system_xdr.h +++ b/src/gromacs/fileio/gmx_internal_xdr.h @@ -3,7 +3,7 @@ * * 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. @@ -38,10 +38,9 @@ #ifndef GMX_FILEIO_GMX_SYSTEM_XDR_H #define GMX_FILEIO_GMX_SYSTEM_XDR_H -#include -#include -#include - +#include +#include +#include /* * This header file is ONLY used on windows systems, since these do diff --git a/src/gromacs/fileio/gmxfio-xdr.cpp b/src/gromacs/fileio/gmxfio-xdr.cpp index b2876d0566..0d3b70bb25 100644 --- a/src/gromacs/fileio/gmxfio-xdr.cpp +++ b/src/gromacs/fileio/gmxfio-xdr.cpp @@ -38,13 +38,13 @@ #include "gmxfio-xdr.h" -#include -#include -#include +#include +#include #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" @@ -73,7 +73,7 @@ XDR *gmx_fio_getxdr(t_fileio *fio) { 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; @@ -95,7 +95,6 @@ static void gmx_fio_check_nitem(int eio, int nitem, const char *file, int line) 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", @@ -118,7 +117,7 @@ static gmx_bool do_xdr(t_fileio *fio, void *item, int nitem, int eio, 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) { @@ -233,7 +232,7 @@ static gmx_bool do_xdr(t_fileio *fio, void *item, int nitem, int eio, } } res = xdr_vector(fio->xdr, (char *) dvec, DIM, - (unsigned int) sizeof(double), + static_cast(sizeof(double)), (xdrproc_t) xdr_double); if (item) { @@ -253,7 +252,7 @@ static gmx_bool do_xdr(t_fileio *fio, void *item, int nitem, int eio, } } res = xdr_vector(fio->xdr, (char *) fvec, DIM, - (unsigned int) sizeof(float), + static_cast(sizeof(float)), (xdrproc_t) xdr_float); if (item) { diff --git a/src/gromacs/fileio/gmxfio.cpp b/src/gromacs/fileio/gmxfio.cpp index a094435c73..e08f55a1e3 100644 --- a/src/gromacs/fileio/gmxfio.cpp +++ b/src/gromacs/fileio/gmxfio.cpp @@ -40,9 +40,9 @@ #include "config.h" -#include -#include -#include +#include +#include +#include #ifdef HAVE_IO_H #include @@ -273,29 +273,29 @@ t_fileio *gmx_fio_open(const char *fn, const char *mode) 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 { @@ -347,6 +347,11 @@ t_fileio *gmx_fio_open(const char *fn, const char *mode) 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)); @@ -606,7 +611,7 @@ int gmx_fio_get_output_file_positions(gmx_file_position_t **p_outputfiles, 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); @@ -688,7 +693,6 @@ static int gmx_fio_int_fsync(t_fileio *fio) { rc = gmx_fsync(fio->fp); } - return rc; } diff --git a/src/gromacs/fileio/libxdrf.c b/src/gromacs/fileio/libxdrf.cpp similarity index 93% rename from src/gromacs/fileio/libxdrf.c rename to src/gromacs/fileio/libxdrf.cpp index 401cfa8883..8f6aecf9b8 100644 --- a/src/gromacs/fileio/libxdrf.c +++ b/src/gromacs/fileio/libxdrf.cpp @@ -3,7 +3,7 @@ * * 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. @@ -36,11 +36,13 @@ */ #include "gmxpre.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include + +#include #include "gromacs/fileio/xdr_datatype.h" #include "gromacs/fileio/xdrf.h" @@ -69,12 +71,6 @@ const char *xdr_datatype_names[] = */ #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 @@ -91,7 +87,7 @@ static const int magicints[] = { #define FIRSTIDX 9 /* note that magicints[FIRSTIDX-1] == 0 */ -#define LASTIDX (sizeof(magicints) / sizeof(*magicints)) +#define LASTIDX static_cast((sizeof(magicints) / sizeof(*magicints))) /*____________________________________________________________________________ @@ -112,10 +108,10 @@ static void sendbits(int buf[], int num_of_bits, int num) int lastbits; unsigned char * cbuf; - cbuf = ((unsigned char *)buf) + 3 * sizeof(*buf); - cnt = (unsigned int) buf[0]; + cbuf = (reinterpret_cast(buf)) + 3 * sizeof(*buf); + cnt = static_cast(buf[0]); lastbits = buf[1]; - lastbyte = (unsigned int) buf[2]; + lastbyte = static_cast(buf[2]); while (num_of_bits >= 8) { lastbyte = (lastbyte << 8) | ((num >> (num_of_bits -8)) /* & 0xff*/); @@ -299,10 +295,10 @@ static int receivebits(int buf[], int num_of_bits) unsigned char * cbuf; int mask = (1 << num_of_bits) -1; - cbuf = ((unsigned char *)buf) + 3 * sizeof(*buf); + cbuf = reinterpret_cast(buf) + 3 * sizeof(*buf); cnt = buf[0]; - lastbits = (unsigned int) buf[1]; - lastbyte = (unsigned int) buf[2]; + lastbits = static_cast(buf[1]); + lastbyte = static_cast(buf[2]); num = 0; while (num_of_bits >= 8) @@ -420,7 +416,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) 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; @@ -430,6 +426,14 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) 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(prealloc_size); i++) + { + prealloc_ip[i] = 0; + } + if (!bRead) { /* xdrs is open for writing */ @@ -444,8 +448,8 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) */ 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(fp), static_cast(size3), + static_cast(sizeof(*fp)), (xdrproc_t)xdr_float)); } if (xdr_float(xdrs, precision) == 0) @@ -461,9 +465,9 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) 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(size3 * 1.2); + ip = reinterpret_cast(malloc(size3 * sizeof(*ip))); + buf = reinterpret_cast(malloc(bufsize * sizeof(*buf))); if (ip == NULL || buf == NULL) { fprintf(stderr, "malloc failed\n"); @@ -495,7 +499,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) /* scaling would cause overflow */ errval = 0; } - lint1 = lf; + lint1 = static_cast(lf); if (lint1 < minint[0]) { minint[0] = lint1; @@ -519,7 +523,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) /* scaling would cause overflow */ errval = 0; } - lint2 = lf; + lint2 = static_cast(lf); if (lint2 < minint[1]) { minint[1] = lint2; @@ -538,12 +542,12 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) { 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(lf); if (lint3 < minint[2]) { minint[2] = lint3; @@ -554,7 +558,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) } *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; @@ -603,8 +607,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) { bitsize = sizeofints(3, sizeint); } - lip = ip; - luip = (unsigned int *) ip; + luip = reinterpret_cast(ip); smallidx = FIRSTIDX; while (smallidx < LASTIDX && magicints[smallidx] < mindiff) { @@ -620,9 +623,9 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) 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; @@ -630,11 +633,11 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) while (i < *size) { is_small = 0; - thiscoord = (int *)(luip) + i * 3; + thiscoord = reinterpret_cast(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; } @@ -648,9 +651,9 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) } 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 @@ -764,7 +767,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) } - rc = errval * (xdr_opaque(xdrs, (char *)&(buf[3]), (unsigned int)buf[0])); + rc = errval * (xdr_opaque(xdrs, reinterpret_cast(&(buf[3])), static_cast(buf[0]))); if (we_should_free) { free(ip); @@ -792,8 +795,8 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) 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(fp), static_cast(size3), + static_cast(sizeof(*fp)), (xdrproc_t)xdr_float)); } if (xdr_float(xdrs, precision) == 0) { @@ -808,9 +811,9 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) 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(size3 * 1.2); + ip = reinterpret_cast(malloc(size3 * sizeof(*ip))); + buf = reinterpret_cast(malloc(bufsize * sizeof(*buf))); if (ip == NULL || buf == NULL) { fprintf(stderr, "malloc failed\n"); @@ -862,12 +865,9 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) 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 */ @@ -882,7 +882,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) } - if (xdr_opaque(xdrs, (char *)&(buf[3]), (unsigned int)buf[0]) == 0) + if (xdr_opaque(xdrs, reinterpret_cast(&(buf[3])), static_cast(buf[0])) == 0) { if (we_should_free) { @@ -903,7 +903,7 @@ int xdr3dfcoord(XDR *xdrs, float *fp, int *size, float *precision) lip = ip; while (i < lsize) { - thiscoord = (int *)(lip) + i * 3; + thiscoord = reinterpret_cast(lip) + i * 3; if (bitsize == 0) { @@ -1272,7 +1272,6 @@ xtc_get_current_frame_number(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK) 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; @@ -1431,7 +1430,6 @@ int xdr_xtc_seek_time(real time, FILE *fp, XDR *xdrs, int natoms, gmx_bool bSeek gmx_bool bOK = FALSE; gmx_off_t low = 0; gmx_off_t high, offset, pos; - int res; int dt_sign = 0; if (bSeekForwardOnly) @@ -1592,7 +1590,6 @@ xdr_xtc_get_last_frame_time(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK) { float time; gmx_off_t off; - int res; *bOK = 1; off = gmx_ftell(fp); if (off < 0) @@ -1601,7 +1598,7 @@ xdr_xtc_get_last_frame_time(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK) 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; @@ -1613,7 +1610,7 @@ xdr_xtc_get_last_frame_time(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK) return -1; } - if ( (res = gmx_fseek(fp, off, SEEK_SET)) != 0) + if (gmx_fseek(fp, off, SEEK_SET) != 0) { *bOK = 0; return -1; @@ -1627,7 +1624,6 @@ xdr_xtc_get_last_frame_number(FILE *fp, XDR *xdrs, int natoms, gmx_bool * bOK) { int frame; gmx_off_t off; - int res; *bOK = 1; if ((off = gmx_ftell(fp)) < 0) diff --git a/src/gromacs/fileio/matio.cpp b/src/gromacs/fileio/matio.cpp index 6d464f8c91..8b1e7a976a 100644 --- a/src/gromacs/fileio/matio.cpp +++ b/src/gromacs/fileio/matio.cpp @@ -3,7 +3,7 @@ * * 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. @@ -38,8 +38,9 @@ #include "matio.h" -#include -#include +#include +#include +#include #include @@ -294,7 +295,7 @@ static void read_xpm_entry(FILE *in, t_matrix *mm) 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)); @@ -361,7 +362,7 @@ static void read_xpm_entry(FILE *in, t_matrix *mm) 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++; @@ -376,12 +377,12 @@ static void read_xpm_entry(FILE *in, t_matrix *mm) 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++; } @@ -406,7 +407,7 @@ static void read_xpm_entry(FILE *in, t_matrix *mm) } else { - str = strchr(line, 'c'); + str = std::strchr(line, 'c'); if (str) { str += 2; @@ -420,7 +421,7 @@ static void read_xpm_entry(FILE *in, t_matrix *mm) 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); @@ -446,7 +447,7 @@ static void read_xpm_entry(FILE *in, t_matrix *mm) 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) { @@ -467,9 +468,9 @@ static void read_xpm_entry(FILE *in, t_matrix *mm) 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) { @@ -560,7 +561,7 @@ int read_xpm_matrix(const char *fnm, t_matrix **mat) 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]); @@ -705,9 +706,9 @@ static void write_xpm_map3(FILE *out, int n_x, int n_y, int *nlevels, 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(round(255*r)), + static_cast(round(255*g)), + static_cast(round(255*b)), ((nmid - i)*lo + i*mid)/clev_lo); } for (i = 0; (i < (*nlevels-nmid)); i++) @@ -718,9 +719,9 @@ static void write_xpm_map3(FILE *out, int n_x, int n_y, int *nlevels, 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(round(255*r)), + static_cast(round(255*g)), + static_cast(round(255*b)), ((*nlevels - 1 - nmid - i)*mid + i*hi)/clev_hi); } } @@ -740,9 +741,9 @@ static void pr_simple_cmap(FILE *out, real lo, real hi, int nlevel, t_rgb rlo, 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(round(255*r)), + static_cast(round(255*g)), + static_cast(round(255*b)), lo+fac*(hi-lo)); } } @@ -777,9 +778,9 @@ static void pr_discrete_cmap(FILE *out, int *nlevel, int i0) 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(round(255*rgbd[i].r)), + static_cast(round(255*rgbd[i].g)), + static_cast(round(255*rgbd[i].b)), i); } } @@ -848,9 +849,9 @@ static void write_xpm_map(FILE *out, int n_x, int n_y, int *nlevels, 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(round(255*r)), + static_cast(round(255*g)), + static_cast(round(255*b)), (nlo*lo+i*hi)*invlevel); } } @@ -1054,9 +1055,9 @@ void write_xpm_m(FILE *out, t_matrix m) 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(round(m.map[i].rgb.r*255)), + static_cast(round(m.map[i].rgb.g*255)), + static_cast(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); diff --git a/src/gromacs/fileio/md5.c b/src/gromacs/fileio/md5.cpp similarity index 97% rename from src/gromacs/fileio/md5.c rename to src/gromacs/fileio/md5.cpp index 521f37c090..bacff2887d 100644 --- a/src/gromacs/fileio/md5.c +++ b/src/gromacs/fileio/md5.cpp @@ -40,6 +40,8 @@ #include "config.h" +#include + #if GMX_INTEGER_BIG_ENDIAN #define ARCH_IS_BIG_ENDIAN 1 #else @@ -100,8 +102,6 @@ #include "md5.h" -#include - #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) @@ -201,15 +201,15 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) */ static const int w = 1; - if (*((const md5_byte_t *)&w)) /* dynamic little-endian */ + if (*(reinterpret_cast(&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(0)) & 3)) { /* data are properly aligned */ X = (const md5_word_t *)data; @@ -217,7 +217,7 @@ md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) else { /* not aligned */ - memcpy(xbuf, data, 64); + std::memcpy(xbuf, data, 64); X = xbuf; } } @@ -398,7 +398,7 @@ gmx_md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes) { 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; diff --git a/src/gromacs/fileio/mdoutf.c b/src/gromacs/fileio/mdoutf.cpp similarity index 96% rename from src/gromacs/fileio/mdoutf.c rename to src/gromacs/fileio/mdoutf.cpp index 5cab6d917a..db89c8ea6a 100644 --- a/src/gromacs/fileio/mdoutf.c +++ b/src/gromacs/fileio/mdoutf.cpp @@ -98,7 +98,7 @@ gmx_mdoutf_t init_mdoutf(FILE *fplog, int nfile, const t_filenm fnm[], 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(ir->x_compression_precision); of->wcycle = wcycle; if (MASTER(cr)) @@ -327,11 +327,11 @@ void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *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) { @@ -369,9 +369,9 @@ void mdoutf_write_to_trajectory_files(FILE *fplog, t_commrec *cr, 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) diff --git a/src/gromacs/fileio/mtxio.c b/src/gromacs/fileio/mtxio.cpp similarity index 94% rename from src/gromacs/fileio/mtxio.c rename to src/gromacs/fileio/mtxio.cpp index ae9b15d9e8..827452131c 100644 --- a/src/gromacs/fileio/mtxio.c +++ b/src/gromacs/fileio/mtxio.cpp @@ -87,8 +87,6 @@ void gmx_mtxio_write(const char * filename, { 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) @@ -125,7 +123,7 @@ void gmx_mtxio_write(const char * filename, 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 { @@ -139,7 +137,7 @@ void gmx_mtxio_write(const char * filename, { 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++) @@ -162,8 +160,6 @@ gmx_mtxio_read (const char * filename, { t_fileio *fio; int i, j, prec; - gmx_bool bDum = TRUE; - gmx_bool bRead = TRUE; char gmxver[256]; size_t sz; @@ -210,7 +206,7 @@ gmx_mtxio_read (const char * filename, 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) { @@ -227,8 +223,8 @@ gmx_mtxio_read (const char * filename, 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++) { diff --git a/src/gromacs/fileio/pdbio.c b/src/gromacs/fileio/pdbio.cpp similarity index 90% rename from src/gromacs/fileio/pdbio.c rename to src/gromacs/fileio/pdbio.cpp index 20bd556dae..572b3f94b5 100644 --- a/src/gromacs/fileio/pdbio.c +++ b/src/gromacs/fileio/pdbio.cpp @@ -3,7 +3,7 @@ * * 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. @@ -38,9 +38,10 @@ #include "pdbio.h" -#include -#include -#include +#include +#include +#include +#include #include "gromacs/fileio/gmxfio.h" #include "gromacs/legacyheaders/copyrite.h" @@ -82,8 +83,8 @@ static void xlate_atomname_pdb2gmx(char *name) 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++) @@ -99,8 +100,8 @@ static void xlate_atomname_gmx2pdb(char *name) 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) @@ -128,7 +129,7 @@ void gmx_write_pdb_box(FILE *out, int ePBC, matrix box) 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 { @@ -136,7 +137,7 @@ void gmx_write_pdb_box(FILE *out, int ePBC, matrix box) } 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 { @@ -144,7 +145,7 @@ void gmx_write_pdb_box(FILE *out, int ePBC, matrix box) } 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 { @@ -217,7 +218,7 @@ static void read_cryst1(char *line, int *ePBC, matrix box) { if (alpha != 90.0) { - cosa = cos(alpha*DEG2RAD); + cosa = std::cos(alpha*DEG2RAD); } else { @@ -225,7 +226,7 @@ static void read_cryst1(char *line, int *ePBC, matrix box) } if (beta != 90.0) { - cosb = cos(beta*DEG2RAD); + cosb = std::cos(beta*DEG2RAD); } else { @@ -233,8 +234,8 @@ static void read_cryst1(char *line, int *ePBC, matrix box) } if (gamma != 90.0) { - cosg = cos(gamma*DEG2RAD); - sing = sin(gamma*DEG2RAD); + cosg = std::cos(gamma*DEG2RAD); + sing = std::sin(gamma*DEG2RAD); } else { @@ -245,8 +246,8 @@ static void read_cryst1(char *line, int *ePBC, matrix box) 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 { @@ -271,9 +272,7 @@ void write_pdbfile_indexed(FILE *out, const char *title, 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; @@ -305,15 +304,12 @@ void write_pdbfile_indexed(FILE *out, const char *title, 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; @@ -328,7 +324,6 @@ void write_pdbfile_indexed(FILE *out, const char *title, fprintf(out, "TER\n"); } lastchainnum = chainnum; - lastchainresind = lastresind; } strncpy(resnm, *atoms->resinfo[resind].name, sizeof(resnm)-1); @@ -359,7 +354,7 @@ void write_pdbfile_indexed(FILE *out, const char *title, } if (atoms->pdbinfo) { - type = (enum PDB_record)(atoms->pdbinfo[i].type); + type = static_cast(atoms->pdbinfo[i].type); altloc = atoms->pdbinfo[i].altloc; if (!isalnum(altloc)) { @@ -444,7 +439,7 @@ int line2type(char *line) 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; } @@ -478,10 +473,10 @@ static void read_anisou(char line[], int natom, t_atoms *atoms) 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; @@ -524,11 +519,11 @@ void get_pdb_atomnumber(t_atoms *atoms, gmx_atomprop_t aps) } 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)) @@ -547,7 +542,7 @@ void get_pdb_atomnumber(t_atoms *atoms, gmx_atomprop_t aps) 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++; } @@ -560,7 +555,7 @@ void get_pdb_atomnumber(t_atoms *atoms, gmx_atomprop_t aps) } 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); @@ -601,7 +596,7 @@ static int read_atom(t_symtab *symtab, anm[k] = line[j]; } anm[k] = nc; - strcpy(anm_copy, anm); + std::strcpy(anm_copy, anm); rtrim(anm_copy); atomnumber = NOTSET; trim(anm); @@ -623,7 +618,7 @@ static int read_atom(t_symtab *symtab, } rnr[k] = nc; trim(rnr); - resnr = strtol(rnr, NULL, 10); + resnr = std::strtol(rnr, NULL, 10); resic = line[j]; j += 4; @@ -723,14 +718,14 @@ gmx_bool is_hydrogen(const char *nm) { 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; } @@ -741,10 +736,10 @@ gmx_bool is_dummymass(const char *nm) { 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; } @@ -763,7 +758,7 @@ static void gmx_conect_addline(gmx_conect_t *con, char *line) { do { - strcat(form2, "%*s"); + std::strcat(form2, "%*s"); sprintf(format, "%s%%d", form2); n = sscanf(line, format, &aj); if (n == 1) @@ -795,19 +790,19 @@ gmx_conect gmx_conect_init() 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) @@ -829,7 +824,6 @@ gmx_bool gmx_conect_exist(gmx_conect conect, int ai, int aj) 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);*/ @@ -846,15 +840,14 @@ int read_pdbfile(FILE *in, char *title, int *model_nr, 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) @@ -897,7 +890,7 @@ int read_pdbfile(FILE *in, char *title, int *model_nr, case epdbTITLE: case epdbHEADER: - if (strlen(line) > 6) + if (std::strlen(line) > 6) { c = line+6; /* skip HEADER or TITLE and spaces */ @@ -910,22 +903,22 @@ int read_pdbfile(FILE *in, char *title, int *model_nr, 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; } @@ -952,12 +945,12 @@ int read_pdbfile(FILE *in, char *title, int *model_nr, { if (bCOMPND) { - strcat(title, "; "); - strcat(title, c); + std::strcat(title, "; "); + std::strcat(title, c); } else { - strcpy(title, c); + std::strcpy(title, c); } } bCOMPND = TRUE; @@ -1006,11 +999,11 @@ void get_pdb_coordnum(FILE *in, int *natoms) *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)++; } @@ -1082,16 +1075,16 @@ gmx_fprintf_pdb_atomline(FILE * fp, /* 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 @@ -1100,14 +1093,14 @@ gmx_fprintf_pdb_atomline(FILE * fp, } /* 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; diff --git a/src/gromacs/fileio/strdb.c b/src/gromacs/fileio/strdb.cpp similarity index 94% rename from src/gromacs/fileio/strdb.c rename to src/gromacs/fileio/strdb.cpp index a0fc276d8f..937256031b 100644 --- a/src/gromacs/fileio/strdb.c +++ b/src/gromacs/fileio/strdb.cpp @@ -38,9 +38,9 @@ #include "strdb.h" -#include -#include -#include +#include +#include +#include #include "gromacs/utility/cstringutil.h" #include "gromacs/utility/fatalerror.h" @@ -61,12 +61,12 @@ gmx_bool get_a_line(FILE *fp, char line[], int n) 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(std::strlen(line0)) == n) { fprintf(stderr, "Warning: line length exceeds buffer length (%d), data might be corrupted\n", n); line0[n-1] = '\0'; @@ -76,12 +76,12 @@ gmx_bool get_a_line(FILE *fp, char line[], int n) 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); } @@ -95,14 +95,14 @@ gmx_bool get_header(char line[], char *header) { 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); diff --git a/src/gromacs/fileio/timecontrol.c b/src/gromacs/fileio/timecontrol.cpp similarity index 97% rename from src/gromacs/fileio/timecontrol.c rename to src/gromacs/fileio/timecontrol.cpp index 735d649423..06c211e5da 100644 --- a/src/gromacs/fileio/timecontrol.c +++ b/src/gromacs/fileio/timecontrol.cpp @@ -3,7 +3,7 @@ * * 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. diff --git a/src/gromacs/fileio/tngio_for_tools.cpp b/src/gromacs/fileio/tngio_for_tools.cpp index 15a92c1398..b006a042f1 100644 --- a/src/gromacs/fileio/tngio_for_tools.cpp +++ b/src/gromacs/fileio/tngio_for_tools.cpp @@ -1,7 +1,7 @@ /* * 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. @@ -38,7 +38,7 @@ #include "config.h" -#include +#include #ifdef GMX_USE_TNG #include "tng/tng_io.h" @@ -205,11 +205,11 @@ void gmx_write_tng_from_trxframe(tng_trajectory_t output, 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); @@ -243,7 +243,7 @@ convert_array_to_real_array(void *from, { for (j = 0; j < nValues; j++) { - to[i*nValues+j] = (real)((float *)from)[i*nValues+j] * fact; + to[i*nValues+j] = reinterpret_cast(from)[i*nValues+j] * fact; } } } @@ -254,7 +254,7 @@ convert_array_to_real_array(void *from, { for (j = 0; j < nValues; j++) { - to[i*nValues+j] = (real)((float *)from)[i*nValues+j] * fact; + to[i*nValues+j] = reinterpret_cast(from)[i*nValues+j] * fact; } } } @@ -264,7 +264,7 @@ convert_array_to_real_array(void *from, { 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(from)[i*nValues+j] * fact; } } break; @@ -281,7 +281,7 @@ convert_array_to_real_array(void *from, { for (j = 0; j < nValues; j++) { - to[i*nValues+j] = (real)((double *)from)[i*nValues+j] * fact; + to[i*nValues+j] = reinterpret_cast(from)[i*nValues+j] * fact; } } } @@ -292,7 +292,7 @@ convert_array_to_real_array(void *from, { for (j = 0; j < nValues; j++) { - to[i*nValues+j] = (real)((double *)from)[i*nValues+j] * fact; + to[i*nValues+j] = reinterpret_cast(from)[i*nValues+j] * fact; } } } @@ -541,8 +541,8 @@ gmx_bool gmx_read_next_tng_frame(tng_trajectory_t input, } 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(values) + size * i * DIM, + reinterpret_cast(fr->box[i]), getDistanceScaleFactor(input), 1, DIM, @@ -553,7 +553,7 @@ gmx_bool gmx_read_next_tng_frame(tng_trajectory_t input, case TNG_TRAJ_POSITIONS: srenew(fr->x, fr->natoms); convert_array_to_real_array(values, - (real *) fr->x, + reinterpret_cast(fr->x), getDistanceScaleFactor(input), fr->natoms, DIM, @@ -587,7 +587,7 @@ gmx_bool gmx_read_next_tng_frame(tng_trajectory_t input, case TNG_TRAJ_FORCES: srenew(fr->f, fr->natoms); convert_array_to_real_array(values, - (real *) fr->f, + reinterpret_cast(fr->f), getDistanceScaleFactor(input), fr->natoms, DIM, @@ -598,10 +598,10 @@ gmx_bool gmx_read_next_tng_frame(tng_trajectory_t input, switch (datatype) { case TNG_FLOAT_DATA: - fr->lambda = (*(float *)values); + fr->lambda = *(reinterpret_cast(values)); break; case TNG_DOUBLE_DATA: - fr->lambda = (*(double *)values); + fr->lambda = *(reinterpret_cast(values)); break; default: gmx_incons("Illegal datatype lambda value!"); @@ -615,7 +615,7 @@ gmx_bool gmx_read_next_tng_frame(tng_trajectory_t input, * be reallocated if it is not NULL. */ } - fr->step = (int) frameNumber; + fr->step = static_cast(frameNumber); fr->bStep = TRUE; // Convert the time to ps fr->time = frameTime / PICO; diff --git a/src/gromacs/fileio/tpxio.c b/src/gromacs/fileio/tpxio.cpp similarity index 99% rename from src/gromacs/fileio/tpxio.c rename to src/gromacs/fileio/tpxio.cpp index 509aa4a15d..8aa9492c46 100644 --- a/src/gromacs/fileio/tpxio.c +++ b/src/gromacs/fileio/tpxio.cpp @@ -40,8 +40,10 @@ #include "tpxio.h" -#include -#include +#include +#include + +#include #include "gromacs/fileio/confio.h" #include "gromacs/fileio/filenm.h" @@ -240,7 +242,6 @@ static void do_pullgrp_tpx_pre95(t_fileio *fio, gmx_bool bRead, int file_version) { - int i; rvec tmp; gmx_fio_do_int(fio, pgrp->nat); @@ -274,8 +275,6 @@ static void do_pullgrp_tpx_pre95(t_fileio *fio, 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) { @@ -294,8 +293,6 @@ static void do_pull_group(t_fileio *fio, t_pull_group *pgrp, gmx_bool 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) @@ -334,10 +331,6 @@ static void do_pull_coord(t_fileio *fio, t_pull_coord *pcrd, int file_version, 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 */ @@ -412,8 +405,7 @@ static void do_imd(t_fileio *fio, t_IMD *imd, gmx_bool bRead) 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 */ @@ -637,7 +629,7 @@ static void do_fepvals(t_fileio *fio, t_lambda *fepvals, gmx_bool bRead, int fil 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; @@ -700,7 +692,7 @@ static void do_pull(t_fileio *fio, pull_params_t *pull, gmx_bool bRead, 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) { @@ -728,8 +720,6 @@ static void do_pull(t_fileio *fio, pull_params_t *pull, gmx_bool bRead, 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); @@ -775,8 +765,7 @@ static void do_rot(t_fileio *fio, t_rot *rot, gmx_bool bRead) 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); @@ -2161,7 +2150,7 @@ void do_iparams(t_fileio *fio, t_functype ftype, t_iparams *iparams, 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) { @@ -2181,7 +2170,7 @@ static void do_ilist(t_fileio *fio, t_ilist *ilist, gmx_bool bRead, int file_ver 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); @@ -2276,7 +2265,7 @@ static void add_settle_atoms(t_ilist *ilist) 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; @@ -2432,7 +2421,6 @@ static void do_atom(t_fileio *fio, t_atom *atom, int ngrp, gmx_bool bRead, 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); @@ -2450,7 +2438,7 @@ static void do_atom(t_fileio *fio, t_atom *atom, int ngrp, gmx_bool bRead, /* 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'; } @@ -2491,7 +2479,7 @@ static void do_atom(t_fileio *fio, t_atom *atom, int ngrp, gmx_bool bRead, 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) { @@ -2635,7 +2623,7 @@ static void do_groups(t_fileio *fio, gmx_groups_t *groups, 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); @@ -2668,7 +2656,7 @@ static void do_groups(t_fileio *fio, gmx_groups_t *groups, 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) { @@ -2832,8 +2820,6 @@ static void do_moltype(t_fileio *fio, gmx_moltype_t *molt, gmx_bool bRead, t_symtab *symtab, int file_version, gmx_groups_t *groups) { - int i; - if (file_version >= 57) { do_symstr(fio, &(molt->name), bRead, symtab); @@ -2863,8 +2849,6 @@ static void do_moltype(t_fileio *fio, gmx_moltype_t *molt, gmx_bool bRead, 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); @@ -2941,7 +2925,7 @@ static void add_posres_molblock(gmx_mtop_t *mtop) 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]) @@ -2956,8 +2940,7 @@ static void add_posres_molblock(gmx_mtop_t *mtop) { 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 */ @@ -3042,7 +3025,7 @@ static void set_disres_npair(gmx_mtop_t *mtop) 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) @@ -3227,7 +3210,7 @@ static void do_tpxheader(t_fileio *fio, gmx_bool bRead, t_tpxheader *tpx, 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" @@ -3291,7 +3274,7 @@ static void do_tpxheader(t_fileio *fio, gmx_bool bRead, t_tpxheader *tpx, 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); @@ -3299,7 +3282,7 @@ static void do_tpxheader(t_fileio *fio, gmx_bool bRead, t_tpxheader *tpx, /* 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, @@ -3374,7 +3357,6 @@ static int do_tpx(t_fileio *fio, gmx_bool bRead, gmx_mtop_t dum_top; gmx_bool TopOnlyOK; int file_version, file_generation; - int i; rvec *xptr, *vptr; int ePBC; gmx_bool bPeriodicMols; @@ -3714,7 +3696,6 @@ int read_tpx_top(const char *fn, 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); @@ -3757,7 +3738,6 @@ gmx_bool read_tps_conf(const char *infile, char *title, t_topology *top, int *eP int natoms, i, version, generation; gmx_bool bTop, bXNULL = FALSE; gmx_mtop_t *mtop; - t_topology *topconv; gmx_atomprop_t aps; bTop = fn2bTPX(infile); @@ -3780,7 +3760,7 @@ gmx_bool read_tps_conf(const char *infile, char *title, t_topology *top, int *eP /* 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 diff --git a/src/gromacs/fileio/trajectory_writing.c b/src/gromacs/fileio/trajectory_writing.cpp similarity index 100% rename from src/gromacs/fileio/trajectory_writing.c rename to src/gromacs/fileio/trajectory_writing.cpp diff --git a/src/gromacs/fileio/trnio.c b/src/gromacs/fileio/trnio.cpp similarity index 99% rename from src/gromacs/fileio/trnio.c rename to src/gromacs/fileio/trnio.cpp index 5afef1afa2..b843db3317 100644 --- a/src/gromacs/fileio/trnio.c +++ b/src/gromacs/fileio/trnio.cpp @@ -38,7 +38,7 @@ #include "trnio.h" -#include +#include #include "gromacs/fileio/gmxfio.h" #include "gromacs/fileio/gmxfio-xdr.h" diff --git a/src/gromacs/fileio/trxio.c b/src/gromacs/fileio/trxio.cpp similarity index 99% rename from src/gromacs/fileio/trxio.c rename to src/gromacs/fileio/trxio.cpp index 8c296dcee5..86b52201af 100644 --- a/src/gromacs/fileio/trxio.c +++ b/src/gromacs/fileio/trxio.cpp @@ -40,8 +40,8 @@ #include "config.h" -#include -#include +#include +#include #include "gromacs/fileio/confio.h" #include "gromacs/fileio/gmxfio.h" @@ -61,6 +61,7 @@ #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 @@ -784,7 +785,6 @@ gmx_bool read_next_frame(const output_env_t oenv, t_trxstatus *status, t_trxfram real pt; int ct; gmx_bool bOK, bRet, bMissingData = FALSE, bSkip = FALSE; - int dummy = 0; int ftp; bRet = FALSE; @@ -914,9 +914,7 @@ int read_first_frame(const output_env_t oenv, t_trxstatus **status, { 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; @@ -964,13 +962,13 @@ int read_first_frame(const output_env_t oenv, t_trxstatus **status, { 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) diff --git a/src/gromacs/fileio/vmdio.c b/src/gromacs/fileio/vmdio.cpp similarity index 98% rename from src/gromacs/fileio/vmdio.c rename to src/gromacs/fileio/vmdio.cpp index 8533c243f6..84e6878716 100644 --- a/src/gromacs/fileio/vmdio.c +++ b/src/gromacs/fileio/vmdio.cpp @@ -262,10 +262,9 @@ gmx_bool read_next_vmd_frame(t_trxframe *fr) 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 @@ -328,7 +327,7 @@ static int load_vmd_library(const char *fn, t_gmxvmdplugin *vmdplugin) "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 @@ -348,6 +347,7 @@ static int load_vmd_library(const char *fn, t_gmxvmdplugin *vmdplugin) } do { + char filename[GMX_PATH_MAX]; sprintf(filename, "%s\\%s", pathenv, ffd.cFileName); ret |= load_sharedlibrary_plugins(filename, vmdplugin); } diff --git a/src/gromacs/fileio/writeps.c b/src/gromacs/fileio/writeps.cpp similarity index 99% rename from src/gromacs/fileio/writeps.c rename to src/gromacs/fileio/writeps.cpp index a0ae4e15cb..7f9f6229f5 100644 --- a/src/gromacs/fileio/writeps.c +++ b/src/gromacs/fileio/writeps.cpp @@ -3,7 +3,7 @@ * * 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. @@ -38,7 +38,7 @@ #include "writeps.h" -#include +#include #include "gromacs/fileio/gmxfio.h" #include "gromacs/utility/fatalerror.h" diff --git a/src/gromacs/fileio/xdrd.c b/src/gromacs/fileio/xdrd.cpp similarity index 89% rename from src/gromacs/fileio/xdrd.c rename to src/gromacs/fileio/xdrd.cpp index 5af573e7b3..5556316ae1 100644 --- a/src/gromacs/fileio/xdrd.c +++ b/src/gromacs/fileio/xdrd.cpp @@ -3,7 +3,7 @@ * * 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. @@ -88,7 +88,7 @@ int xdr3drcoord(XDR *xdrs, real *fp, int *size, real *precision) sfree(ffp); return ret; #else - return xdr3dfcoord(xdrs, (float *)fp, size, (float *)precision); + return xdr3dfcoord(xdrs, reinterpret_cast(fp), size, reinterpret_cast(precision)); #endif } @@ -104,12 +104,12 @@ int xdr_int64(XDR *xdrs, gmx_int64_t *i) imaj64 = ((*i)>>32) & two_p32_m1; imin64 = (*i) & two_p32_m1; - imaj = (int)imaj64; - imin = (int)imin64; + imaj = static_cast(imaj64); + imin = static_cast(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(imaj) << 32) | (static_cast(imin) & two_p32_m1)); return ret; } diff --git a/src/gromacs/fileio/xdrf.h b/src/gromacs/fileio/xdrf.h index 258a19b71c..72a67afb66 100644 --- a/src/gromacs/fileio/xdrf.h +++ b/src/gromacs/fileio/xdrf.h @@ -49,7 +49,7 @@ #include "config.h" #if GMX_INTERNAL_XDR -#include "gromacs/fileio/gmx_system_xdr.h" +#include "gromacs/fileio/gmx_internal_xdr.h" #else #include #include diff --git a/src/gromacs/fileio/xtcio.c b/src/gromacs/fileio/xtcio.cpp similarity index 99% rename from src/gromacs/fileio/xtcio.c rename to src/gromacs/fileio/xtcio.cpp index a477f568d5..cf4bfd4573 100644 --- a/src/gromacs/fileio/xtcio.c +++ b/src/gromacs/fileio/xtcio.cpp @@ -38,7 +38,7 @@ #include "xtcio.h" -#include +#include #include "gromacs/fileio/gmxfio.h" #include "gromacs/fileio/gmxfio-xdr.h" diff --git a/src/gromacs/fileio/xvgr.cpp b/src/gromacs/fileio/xvgr.cpp index f38f950b8c..1b5a47909a 100644 --- a/src/gromacs/fileio/xvgr.cpp +++ b/src/gromacs/fileio/xvgr.cpp @@ -3,7 +3,7 @@ * * 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. @@ -38,8 +38,8 @@ #include "xvgr.h" -#include -#include +#include +#include #include "gromacs/fileio/gmxfio.h" #include "gromacs/legacyheaders/copyrite.h" @@ -166,23 +166,23 @@ static char *xvgrstr(const char *gmx, const output_env_t oenv, 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) { @@ -193,17 +193,17 @@ static char *xvgrstr(const char *gmx, const output_env_t oenv, 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 { @@ -467,7 +467,7 @@ static char *fgets3(FILE *fp, char **ptr, int *len, int maxlen) 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) { @@ -481,7 +481,7 @@ static char *fgets3(FILE *fp, char **ptr, int *len, int maxlen) } { /* now remove newline */ - int slen = strlen(*ptr); + int slen = std::strlen(*ptr); if ((*ptr)[slen-1] == '\n') { (*ptr)[slen-1] = '\0'; @@ -501,7 +501,7 @@ static int wordcount(char *ptr) { for (i = 0; (ptr[i] != '\0'); i++) { - is[cur] = isspace(ptr[i]); + is[cur] = std::isspace(ptr[i]); if ((0 == i) && !is[cur]) { n++; @@ -521,11 +521,11 @@ static char *read_xvgr_string(const char *line) 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); @@ -584,7 +584,7 @@ int read_xvg_legend(const char *fn, double ***y, int *ny, ptr++; trim(ptr); set = -1; - if (strncmp(ptr, "subtitle", 8) == 0) + if (std::strncmp(ptr, "subtitle", 8) == 0) { ptr += 8; if (subtitle != NULL) @@ -592,7 +592,7 @@ int read_xvg_legend(const char *fn, double ***y, int *ny, *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); @@ -604,7 +604,7 @@ int read_xvg_legend(const char *fn, double ***y, int *ny, 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; } @@ -654,8 +654,8 @@ int read_xvg_legend(const char *fn, double ***y, int *ny, /* 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)) @@ -665,7 +665,7 @@ int read_xvg_legend(const char *fn, double ***y, int *ny, 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) {