/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,2018,2019,2020,2021, 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.
for (size_t b = 0; b < block_.size(); b++)
{
- sub[b].type = xdr_datatype_float;
+ sub[b].type = XdrDataType::Float;
sub[b].nr = block_[b].data().size();
sub[b].fval = block_[b].data().data();
}
template<>
struct xdr_type<int>
{
- static const int value = xdr_datatype_int;
+ static const XdrDataType value = XdrDataType::Int;
};
template<>
struct xdr_type<float>
{
- static const int value = xdr_datatype_float;
+ static const XdrDataType value = XdrDataType::Float;
};
template<>
struct xdr_type<double>
{
- static const int value = xdr_datatype_double;
+ static const XdrDataType value = XdrDataType::Double;
};
-//! \brief Returns size in byte of an xdr_datatype
-static inline unsigned int sizeOfXdrType(int xdrType)
+//! \brief Returns size in byte of an XdrDataType
+static inline unsigned int sizeOfXdrType(XdrDataType xdrType)
{
switch (xdrType)
{
- case xdr_datatype_int: return sizeof(int);
- case xdr_datatype_float: return sizeof(float);
- case xdr_datatype_double: return sizeof(double);
+ case XdrDataType::Int: return sizeof(int);
+ case XdrDataType::Float: return sizeof(float);
+ case XdrDataType::Double: return sizeof(double);
default: GMX_RELEASE_ASSERT(false, "XDR data type not implemented");
}
}
//! \brief Returns the XDR process function for i/o of an XDR type
-static inline xdrproc_t xdrProc(int xdrType)
+static inline xdrproc_t xdrProc(XdrDataType xdrType)
{
switch (xdrType)
{
- case xdr_datatype_int: return reinterpret_cast<xdrproc_t>(xdr_int);
- case xdr_datatype_float: return reinterpret_cast<xdrproc_t>(xdr_float);
- case xdr_datatype_double: return reinterpret_cast<xdrproc_t>(xdr_double);
+ case XdrDataType::Int: return reinterpret_cast<xdrproc_t>(xdr_int);
+ case XdrDataType::Float: return reinterpret_cast<xdrproc_t>(xdr_float);
+ case XdrDataType::Double: return reinterpret_cast<xdrproc_t>(xdr_double);
default: GMX_RELEASE_ASSERT(false, "XDR data type not implemented");
}
* When list==NULL only reads the elements.
*/
template<typename Enum>
-static bool_t listXdrVector(XDR* xd, Enum ecpt, int nf, int xdrType, FILE* list, CptElementType cptElementType)
+static bool_t listXdrVector(XDR* xd, Enum ecpt, int nf, XdrDataType xdrType, FILE* list, CptElementType cptElementType)
{
bool_t res = 0;
{
switch (xdrType)
{
- case xdr_datatype_int:
+ case XdrDataType::Int:
pr_ivec(list, 0, enumValueToString(ecpt), reinterpret_cast<const int*>(data.data()), nf, TRUE);
break;
- case xdr_datatype_float:
+ case XdrDataType::Float:
#if !GMX_DOUBLE
if (cptElementType == CptElementType::real3)
{
pr_fvec(list, 0, enumValueToString(ecpt), reinterpret_cast<const float*>(data.data()), nf, TRUE);
}
break;
- case xdr_datatype_double:
+ case XdrDataType::Double:
#if GMX_DOUBLE
if (cptElementType == CptElementType::real3)
{
return -1;
}
/* Read/write the element data type */
- constexpr int xdrTypeInTheCode = xdr_type<T>::value;
- int xdrTypeInTheFile = xdrTypeInTheCode;
- res = xdr_int(xd, &xdrTypeInTheFile);
+ constexpr XdrDataType xdrTypeInTheCode = xdr_type<T>::value;
+ XdrDataType xdrTypeInTheFile = xdrTypeInTheCode;
+ int xdrTypeInTheFileAsInt = static_cast<int>(xdrTypeInTheFile);
+ res = xdr_int(xd, &xdrTypeInTheFileAsInt);
+ xdrTypeInTheFile = static_cast<XdrDataType>(xdrTypeInTheFileAsInt);
if (res == 0)
{
return -1;
sprintf(buf,
"mismatch for state entry %s, code precision is %s, file precision is %s",
enumValueToString(ecpt),
- xdr_datatype_names[xdrTypeInTheCode],
- xdr_datatype_names[xdrTypeInTheFile]);
+ enumValueToString(xdrTypeInTheCode),
+ enumValueToString(xdrTypeInTheFile));
/* Matching int and real should never occur, but check anyhow */
- if (xdrTypeInTheFile == xdr_datatype_int || xdrTypeInTheCode == xdr_datatype_int)
+ if (xdrTypeInTheFile == XdrDataType::Int || xdrTypeInTheCode == XdrDataType::Int)
{
gmx_fatal(FARGS,
"Type %s: incompatible checkpoint formats or corrupted checkpoint file.",
{
sb->nr = 0;
#if GMX_DOUBLE
- sb->type = xdr_datatype_double;
+ sb->type = XdrDataType::Double;
#else
- sb->type = xdr_datatype_float;
+ sb->type = XdrDataType::Float;
#endif
sb->fval = nullptr;
sb->dval = nullptr;
/* allocate the appropriate amount of memory */
switch (sb->type)
{
- case xdr_datatype_float:
+ case XdrDataType::Float:
if (sb->nr > sb->fval_alloc)
{
srenew(sb->fval, sb->nr);
sb->fval_alloc = sb->nr;
}
break;
- case xdr_datatype_double:
+ case XdrDataType::Double:
if (sb->nr > sb->dval_alloc)
{
srenew(sb->dval, sb->nr);
sb->dval_alloc = sb->nr;
}
break;
- case xdr_datatype_int:
+ case XdrDataType::Int:
if (sb->nr > sb->ival_alloc)
{
srenew(sb->ival, sb->nr);
sb->ival_alloc = sb->nr;
}
break;
- case xdr_datatype_int64:
+ case XdrDataType::Int64:
if (sb->nr > sb->lval_alloc)
{
srenew(sb->lval, sb->nr);
sb->lval_alloc = sb->nr;
}
break;
- case xdr_datatype_char:
+ case XdrDataType::Char:
if (sb->nr > sb->cval_alloc)
{
srenew(sb->cval, sb->nr);
sb->cval_alloc = sb->nr;
}
break;
- case xdr_datatype_string:
+ case XdrDataType::String:
if (sb->nr > sb->sval_alloc)
{
int i;
int ndisre = 0;
int startb = 0;
#if !GMX_DOUBLE
- xdr_datatype dtreal = xdr_datatype_float;
+ XdrDataType xdrDataType = XdrDataType::Float;
#else
- xdr_datatype dtreal = xdr_datatype_double;
+ XdrDataType xdrDataType = XdrDataType::Double;
#endif
if (bWrongPrecision)
fr->block[0].id = enxDISRE;
fr->block[0].sub[0].nr = ndisre;
fr->block[0].sub[1].nr = ndisre;
- fr->block[0].sub[0].type = dtreal;
- fr->block[0].sub[1].type = dtreal;
+ fr->block[0].sub[0].type = xdrDataType;
+ fr->block[0].sub[1].type = xdrDataType;
startb++;
}
{
gmx_incons("Writing an old version .edr file with too many subblocks");
}
- if (fr->block[b].sub[0].type != dtreal)
+ if (fr->block[b].sub[0].type != xdrDataType)
{
gmx_incons("Writing an old version .edr file the wrong subblock type");
}
}
fr->block[b].id = b - startb;
fr->block[b].sub[0].nr = nrint;
- fr->block[b].sub[0].type = dtreal;
+ fr->block[b].sub[0].type = xdrDataType;
}
else
{
for (i = 0; i < nsub; i++)
{
t_enxsubblock* sub = &(fr->block[b].sub[i]); /* shortcut */
- int typenr = sub->type;
+ int typenr = static_cast<int>(sub->type);
*bOK = *bOK && gmx_fio_do_int(ef->fio, typenr);
*bOK = *bOK && gmx_fio_do_int(ef->fio, sub->nr);
- sub->type = static_cast<xdr_datatype>(typenr);
+ sub->type = static_cast<XdrDataType>(typenr);
}
}
}
/* read/write data */
switch (sub->type)
{
- case xdr_datatype_float:
+ case XdrDataType::Float:
bOK1 = gmx_fio_ndo_float(ef->fio, sub->fval, sub->nr);
break;
- case xdr_datatype_double:
+ case XdrDataType::Double:
bOK1 = gmx_fio_ndo_double(ef->fio, sub->dval, sub->nr);
break;
- case xdr_datatype_int: bOK1 = gmx_fio_ndo_int(ef->fio, sub->ival, sub->nr); break;
- case xdr_datatype_int64:
+ case XdrDataType::Int: bOK1 = gmx_fio_ndo_int(ef->fio, sub->ival, sub->nr); break;
+ case XdrDataType::Int64:
bOK1 = gmx_fio_ndo_int64(ef->fio, sub->lval, sub->nr);
break;
- case xdr_datatype_char:
+ case XdrDataType::Char:
bOK1 = gmx_fio_ndo_uchar(ef->fio, sub->cval, sub->nr);
break;
- case xdr_datatype_string:
+ case XdrDataType::String:
bOK1 = gmx_fio_ndo_string(ef->fio, sub->sval, sub->nr);
break;
default:
{
switch (s1->type)
{
- case xdr_datatype_float:
+ case XdrDataType::Float:
for (k = 0; k < s1->nr; k++)
{
cmp_float(stdout, buf, i, s1->fval[k], s2->fval[k], ftol, abstol);
}
break;
- case xdr_datatype_double:
+ case XdrDataType::Double:
for (k = 0; k < s1->nr; k++)
{
cmp_double(stdout, buf, i, s1->dval[k], s2->dval[k], ftol, abstol);
}
break;
- case xdr_datatype_int:
+ case XdrDataType::Int:
for (k = 0; k < s1->nr; k++)
{
cmp_int(stdout, buf, i, s1->ival[k], s2->ival[k]);
}
break;
- case xdr_datatype_int64:
+ case XdrDataType::Int64:
for (k = 0; k < s1->nr; k++)
{
cmp_int64(stdout, buf, s1->lval[k], s2->lval[k]);
}
break;
- case xdr_datatype_char:
+ case XdrDataType::Char:
for (k = 0; k < s1->nr; k++)
{
cmp_uc(stdout, buf, i, s1->cval[k], s2->cval[k]);
}
break;
- case xdr_datatype_string:
+ case XdrDataType::String:
for (k = 0; k < s1->nr; k++)
{
cmp_str(stdout, buf, i, s1->sval[k], s2->sval[k]);
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
has a number of values of a single data type in a .edr file. */
struct t_enxsubblock
{
- int nr; /* number of items in subblock */
- xdr_datatype type; /* the block type */
+ int nr; /* number of items in subblock */
+ XdrDataType type; /* the block type */
/* the values: pointers for each type */
float* fval;
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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 "gromacs/fileio/xdr_datatype.h"
#include "gromacs/fileio/xdrf.h"
+#include "gromacs/utility/enumerationhelpers.h"
#include "gromacs/utility/futil.h"
/* This is just for clarity - it can never be anything but 4! */
#define XDR_INT_SIZE 4
-/* same order as the definition of xdr_datatype */
-const char* xdr_datatype_names[] = { "int", "float", "double", "large int", "char", "string" };
+/* Human-friendly names for XdrDataType enum class */
+const char* enumValueToString(XdrDataType enumValue)
+{
+ constexpr gmx::EnumerationArray<XdrDataType, const char*> xdrDataTypeNames = {
+ "int", "float", "double", "large int", "char", "string"
+ };
+ return xdrDataTypeNames[enumValue];
+}
/*___________________________________________________________________________
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2013,2018,2019,2021, 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.
/* the xdr data types; note that there is no data type 'real' because
here we deal with the types as they are actually written to disk. */
-typedef enum
+enum class XdrDataType : int
{
- xdr_datatype_int,
- xdr_datatype_float,
- xdr_datatype_double,
- xdr_datatype_int64,
- xdr_datatype_char,
- xdr_datatype_string
-} xdr_datatype;
+ Int,
+ Float,
+ Double,
+ Int64,
+ Char,
+ String,
+ Count
+};
-/* names corresponding to the xdr_datatype enum */
-extern const char* xdr_datatype_names[];
+/* names corresponding to the XdrDataType enum */
+const char* enumValueToString(XdrDataType enumValue);
#endif
int startj;
/* check the block types etc. */
- if ((blk->nsub < 3) || (blk->sub[0].type != xdr_datatype_int) || (blk->sub[1].type != xdr_datatype_double)
- || ((blk->sub[2].type != xdr_datatype_float) && (blk->sub[2].type != xdr_datatype_double))
+ if ((blk->nsub < 3) || (blk->sub[0].type != XdrDataType::Int)
+ || (blk->sub[1].type != XdrDataType::Double)
+ || ((blk->sub[2].type != XdrDataType::Float) && (blk->sub[2].type != XdrDataType::Double))
|| (blk->sub[0].nr < 1) || (blk->sub[1].nr < 1))
{
gmx_fatal(FARGS, "Unexpected/corrupted block data in file %s around time %f.", filename, start_time);
/* and copy the data*/
for (j = 0; j < blk->sub[2].nr; j++)
{
- if (blk->sub[2].type == xdr_datatype_float)
+ if (blk->sub[2].type == XdrDataType::Float)
{
s->du[startj + j] = blk->sub[2].fval[j];
}
int nbins[2];
/* check the block types etc. */
- if ((blk->nsub < 2) || (blk->sub[0].type != xdr_datatype_double)
- || (blk->sub[1].type != xdr_datatype_int64) || (blk->sub[0].nr < 2) || (blk->sub[1].nr < 2))
+ if ((blk->nsub < 2) || (blk->sub[0].type != XdrDataType::Double)
+ || (blk->sub[1].type != XdrDataType::Int64) || (blk->sub[0].nr < 2) || (blk->sub[1].nr < 2))
{
gmx_fatal(FARGS, "Unexpected/corrupted block data in file %s around time %f", filename, start_time);
}
if (fr->block[i].id == enxDHCOLL)
{
nlam++;
- if ((fr->block[i].nsub < 1) || (fr->block[i].sub[0].type != xdr_datatype_double)
+ if ((fr->block[i].nsub < 1) || (fr->block[i].sub[0].type != XdrDataType::Double)
|| (fr->block[i].sub[0].nr < 5))
{
gmx_fatal(FARGS, "Unexpected block data in file %s", fn);
else if (fr->block[i].id == enxDHCOLL)
{
nblock_dhcoll++;
- if ((fr->block[i].nsub < 1) || (fr->block[i].sub[0].type != xdr_datatype_double)
+ if ((fr->block[i].nsub < 1) || (fr->block[i].sub[0].type != XdrDataType::Double)
|| (fr->block[i].sub[0].nr < 5))
{
gmx_fatal(FARGS, "Unexpected block data");
int nhist, derivative;
/* check the block types etc. */
- if ((blk->nsub < 2) || (blk->sub[0].type != xdr_datatype_double)
- || (blk->sub[1].type != xdr_datatype_int64) || (blk->sub[0].nr < 2)
+ if ((blk->nsub < 2) || (blk->sub[0].type != XdrDataType::Double)
+ || (blk->sub[1].type != XdrDataType::Int64) || (blk->sub[0].nr < 2)
|| (blk->sub[1].nr < 2))
{
gmx_fatal(FARGS, "Unexpected block data in file");
if (blk->id == enxDH)
{
double value;
- if (blk->sub[2].type == xdr_datatype_float)
+ if (blk->sub[2].type == XdrDataType::Float)
{
value = blk->sub[2].fval[i];
}
static real blk_value(t_enxblock* blk, int sub, int index)
{
range_check(index, 0, blk->sub[sub].nr);
- if (blk->sub[sub].type == xdr_datatype_float)
+ if (blk->sub[sub].type == XdrDataType::Float)
{
return blk->sub[sub].fval[index];
}
- else if (blk->sub[sub].type == xdr_datatype_double)
+ else if (blk->sub[sub].type == XdrDataType::Double)
{
return blk->sub[sub].dval[index];
}
fr.block[b].id = id[b];
fr.block[b].sub[0].nr = nr[b];
#if !GMX_DOUBLE
- fr.block[b].sub[0].type = xdr_datatype_float;
+ fr.block[b].sub[0].type = XdrDataType::Float;
fr.block[b].sub[0].fval = block[b];
#else
- fr.block[b].sub[0].type = xdr_datatype_double;
+ fr.block[b].sub[0].type = XdrDataType::Double;
fr.block[b].sub[0].dval = block[b];
#endif
}
fr.block[db].sub[0].nr = ndisre;
fr.block[db].sub[1].nr = ndisre;
#if !GMX_DOUBLE
- fr.block[db].sub[0].type = xdr_datatype_float;
- fr.block[db].sub[1].type = xdr_datatype_float;
+ fr.block[db].sub[0].type = XdrDataType::Float;
+ fr.block[db].sub[1].type = XdrDataType::Float;
fr.block[db].sub[0].fval = disres.rt;
fr.block[db].sub[1].fval = disres.rm3tav;
#else
- fr.block[db].sub[0].type = xdr_datatype_double;
- fr.block[db].sub[1].type = xdr_datatype_double;
+ fr.block[db].sub[0].type = XdrDataType::Double;
+ fr.block[db].sub[1].type = XdrDataType::Double;
fr.block[db].sub[0].dval = disres.rt;
fr.block[db].sub[1].dval = disres.rm3tav;
#endif
starting from first coord in
the main delta_h_coll) */
blk->sub[0].nr = 2;
- blk->sub[0].type = xdr_datatype_int;
+ blk->sub[0].type = XdrDataType::Int;
blk->sub[0].ival = dh->subblock_meta_i;
/* subblock 2 */
dh->subblock_meta_d[i] = dh->lambda[i];
}
blk->sub[1].nr = dh->nlambda;
- blk->sub[1].type = xdr_datatype_double;
+ blk->sub[1].type = XdrDataType::Double;
blk->sub[1].dval = dh->subblock_meta_d;
/* subblock 3 */
blk->sub[2].nr = dh->ndh;
/* Michael commented in 2012 that this use of explicit
- xdr_datatype_float was good for F@H for now.
+ XdrDataType::Float was good for F@H for now.
Apparently it's still good enough. */
- blk->sub[2].type = xdr_datatype_float;
+ blk->sub[2].type = XdrDataType::Float;
for (i = 0; i < dh->ndh; i++)
{
dh->dhf[i] = static_cast<float>(dh->dh[i]);
else
{
blk->sub[2].nr = 0;
- blk->sub[2].type = xdr_datatype_float;
+ blk->sub[2].type = XdrDataType::Float;
blk->sub[2].fval = nullptr;
}
}
}
dh->subblock_meta_d[1] = dh->dx;
blk->sub[0].nr = 2 + ((dh->nlambda > 1) ? dh->nlambda : 0);
- blk->sub[0].type = xdr_datatype_double;
+ blk->sub[0].type = XdrDataType::Double;
blk->sub[0].dval = dh->subblock_meta_d;
/* subblock 2: the starting point(s) as a long integer */
dh->subblock_meta_l[k++] = dh->derivative;
blk->sub[1].nr = nhist_written + 3;
- blk->sub[1].type = xdr_datatype_int64;
+ blk->sub[1].type = XdrDataType::Int64;
blk->sub[1].lval = dh->subblock_meta_l;
/* subblock 3 + 4 : the histogram data */
{
blk->sub[i + 2].nr = dh->maxbin[i] + 1; /* it's +1 because size=index+1
in C */
- blk->sub[i + 2].type = xdr_datatype_int;
+ blk->sub[i + 2].type = XdrDataType::Int;
blk->sub[i + 2].ival = dh->bin[i];
}
}
}
blk->id = enxDHCOLL;
blk->sub[0].nr = c_subblockDNumPreEntries + dhc->n_lambda_vec;
- blk->sub[0].type = xdr_datatype_double;
+ blk->sub[0].type = XdrDataType::Double;
blk->sub[0].dval = dhc->subblock_d;
if (dhc->native_lambda_components != nullptr)
dhc->subblock_i[c_subblockINumPreEntries + i] = dhc->native_lambda_components[i];
}
blk->sub[1].nr = c_subblockINumPreEntries + dhc->n_lambda_vec;
- blk->sub[1].type = xdr_datatype_int;
+ blk->sub[1].type = XdrDataType::Int;
blk->sub[1].ival = dhc->subblock_i;
}
printf(" Sub block %3d (%5d elems, type=%s) values:\n",
i,
sb->nr,
- xdr_datatype_names[sb->type]);
+ enumValueToString(sb->type));
switch (sb->type)
{
- case xdr_datatype_float:
+ case XdrDataType::Float:
for (j = 0; j < sb->nr; j++)
{
printf("%14d %8.4f\n", j, sb->fval[j]);
}
break;
- case xdr_datatype_double:
+ case XdrDataType::Double:
for (j = 0; j < sb->nr; j++)
{
printf("%14d %10.6f\n", j, sb->dval[j]);
}
break;
- case xdr_datatype_int:
+ case XdrDataType::Int:
for (j = 0; j < sb->nr; j++)
{
printf("%14d %10d\n", j, sb->ival[j]);
}
break;
- case xdr_datatype_int64:
+ case XdrDataType::Int64:
for (j = 0; j < sb->nr; j++)
{
printf("%14d %s\n", j, gmx_step_str(sb->lval[j], buf));
}
break;
- case xdr_datatype_char:
+ case XdrDataType::Char:
for (j = 0; j < sb->nr; j++)
{
printf("%14d %1c\n", j, sb->cval[j]);
}
break;
- case xdr_datatype_string:
+ case XdrDataType::String:
for (j = 0; j < sb->nr; j++)
{
printf("%14d %80s\n", j, sb->sval[j]);