#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"
};