*/
#include "gmxpre.h"
-#include <ctype.h>
-#include <float.h>
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cctype>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
+#include <limits>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/enxio.h"
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/dir_separator.h"
#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/snprintf.h"
srenew(lc->names, lc->Nalloc);
}
snew(lc->names[lc->N], name_length+1);
- strncpy(lc->names[lc->N], name, name_length);
+ std::strncpy(lc->names[lc->N], name, name_length);
lc->N++;
}
{
return FALSE;
}
- len = strlen(lc->names[index]);
+ len = std::strlen(lc->names[index]);
if (len != name_length)
{
return FALSE;
}
- if (strncmp(lc->names[index], name, name_length) == 0)
+ if (std::strncmp(lc->names[index], name, name_length) == 0)
{
return TRUE;
}
for (i = 0; i < lc->N; i++)
{
- if (strncmp(lc->names[i], name, name_length) == 0)
+ if (std::strncmp(lc->names[i], name, name_length) == 0)
{
return i;
}
static void lambda_vec_print(const lambda_vec_t *lv, char *str, gmx_bool named)
{
int i;
- size_t np;
str[0] = 0; /* reset the string */
if (lv->dhdl < 0)
}
if (lv->lc->N > 1)
{
- str += sprintf(str, ")");
+ sprintf(str, ")");
}
}
else
{
/* this lambda vector describes a derivative */
str += sprintf(str, "dH/dl");
- if (strlen(lv->lc->names[lv->dhdl]) > 0)
+ if (std::strlen(lv->lc->names[lv->dhdl]) > 0)
{
sprintf(str, " (%s)", lv->lc->names[lv->dhdl]);
}
/* write a shortened version of the lambda vec to a preallocated string */
static void lambda_vec_print_short(const lambda_vec_t *lv, char *str)
{
- int i;
- size_t np;
-
if (lv->index >= 0)
{
sprintf(str, "%6d", lv->index);
static void lambda_vec_print_intermediate(const lambda_vec_t *a,
const lambda_vec_t *b, char *str)
{
- int i;
- size_t np;
-
str[0] = 0;
if ( (a->index >= 0) && (b->index >= 0) )
{
- sprintf(str, "%6.3f", ((double)a->index+(double)b->index)/2.);
+ sprintf(str, "%6.3f", (a->index+b->index)/2.0);
}
else
{
if ( (a->dhdl < 0) && (b->dhdl < 0) )
{
- sprintf(str, "%6.3f", (a->val[0]+b->val[0])/2.);
+ sprintf(str, "%6.3f", (a->val[0]+b->val[0])/2.0);
}
}
}
double df = a->val[i] - b->val[i];
ret += df*df;
}
- return sqrt(ret);
+ return std::sqrt(ret);
}
static gmx_bool lambda_vec_cmp_native(const lambda_vec_t *a,
const lambda_vec_t *b)
{
- int i;
-
if (a->lc != b->lc)
{
gmx_fatal(FARGS, "Can't compare lambdas with differing basis sets");
/* check if there's room */
if ( (sc->nsamples + 1) > sc->nsamples_alloc)
{
- sc->nsamples_alloc = max(2*sc->nsamples_alloc, 2);
+ sc->nsamples_alloc = std::max(2*sc->nsamples_alloc, 2);
srenew(sc->s, sc->nsamples_alloc);
srenew(sc->r, sc->nsamples_alloc);
}
}
else
{
- *nbin = (xmax-(*xmin))/(*dx);
+ *nbin = static_cast<int>((xmax-(*xmin))/(*dx));
}
if (*nbin > *nbin_alloc)
/* calculate the bin corresponding to the middle of the
original bin */
double x = hdx*(j+0.5) + xmin_hist;
- int binnr = (int)((x-(*xmin))/(*dx));
+ int binnr = static_cast<int>((x-(*xmin))/(*dx));
if (binnr >= *nbin || binnr < 0)
{
int endi = sc->r[i].end;
for (j = starti; j < endi; j++)
{
- int binnr = (int)((sc->s[i]->du[j]-(*xmin))/(*dx));
+ int binnr = static_cast<int>((sc->s[i]->du[j]-(*xmin))/(*dx));
if (binnr >= *nbin || binnr < 0)
{
binnr = (*nbin)-1;
int nbin = 0;
int nbin_alloc = 0;
double dx = 0;
- double min = 0;
+ double minval = 0;
int i;
lambda_data_t *bl_head = sd->lb;
xvgr_new_dataset(fp, 0, 0, NULL, oenv);
}
- sample_coll_make_hist(sc, &hist, &nbin_alloc, &nbin, &dx, &min,
+ sample_coll_make_hist(sc, &hist, &nbin_alloc, &nbin, &dx, &minval,
nbin_default);
for (i = 0; i < nbin; i++)
{
- double xmin = i*dx + min;
- double xmax = (i+1)*dx + min;
+ double xmin = i*dx + minval;
+ double xmax = (i+1)*dx + minval;
fprintf(fp, "%g %d\n%g %d\n", xmin, hist[i], xmax, hist[i]);
}
lambda_data_t *bl;
int nlambda = 0;
barres_t *res;
- int i;
gmx_bool dhdl = FALSE;
gmx_bool first = TRUE;
lambda_data_t *bl_head = sd->lb;
Wfac = delta_lambda;
}
- disc_err = max(disc_err, Wfac*br->a->s[j]->hist->dx[0]);
+ disc_err = std::max(disc_err, Wfac*br->a->s[j]->hist->dx[0]);
}
}
for (j = 0; j < br->b->nsamples; j++)
{
Wfac = delta_lambda;
}
- disc_err = max(disc_err, Wfac*br->b->s[j]->hist->dx[0]);
+ disc_err = std::max(disc_err, Wfac*br->b->s[j]->hist->dx[0]);
}
}
}
double end_time;
if (s->start_time < begin_t)
{
- r->start = (int)((begin_t - s->start_time)/s->delta_time);
+ r->start = static_cast<int>((begin_t - s->start_time)/s->delta_time);
}
end_time = s->delta_time*s->ndu + s->start_time;
if (end_time > end_t)
{
- r->end = (int)((end_t - s->start_time)/s->delta_time);
+ r->end = static_cast<int>((end_t - s->start_time)/s->delta_time);
}
}
else
int i, int ni)
{
int j;
- int hist_start, hist_end;
gmx_int64_t ntot_start;
gmx_int64_t ntot_end;
/* now fix start and end fields */
/* the casts avoid possible overflows */
- ntot_start = (gmx_int64_t)(sc_orig->ntot*(double)i/(double)ni);
- ntot_end = (gmx_int64_t)(sc_orig->ntot*(double)(i+1)/(double)ni);
+ ntot_start = static_cast<gmx_int64_t>(sc_orig->ntot*static_cast<double>(i)/static_cast<double>(ni));
+ ntot_end = static_cast<gmx_int64_t>(sc_orig->ntot*static_cast<double>(i+1)/static_cast<double>(ni));
ntot_so_far = 0;
for (j = 0; j < sc->nsamples; j++)
{
new_end = 0;
}
/* and write the new range */
- sc->r[j].start = (int)new_start;
- sc->r[j].end = (int)new_end;
+ GMX_RELEASE_ASSERT(new_start <= std::numeric_limits<int>::max(), "Value of 'new_start' too large for int converstion");
+ GMX_RELEASE_ASSERT(new_end <= std::numeric_limits<int>::max(), "Value of 'new_end' too large for int converstion");
+ sc->r[j].start = static_cast<int>(new_start);
+ sc->r[j].end = static_cast<int>(new_end);
}
else
{
/* first calculate normalized bounds
(where 0 is the start of the hist range, and 1 the end) */
- ntot_start_norm = (ntot_start-ntot_so_far)/(double)ntot_add;
- ntot_end_norm = (ntot_end-ntot_so_far)/(double)ntot_add;
+ ntot_start_norm = (ntot_start-ntot_so_far)/static_cast<double>(ntot_add);
+ ntot_end_norm = (ntot_end-ntot_so_far)/static_cast<double>(ntot_add);
/* now fix the boundaries */
- ntot_start_norm = min(1, max(0., ntot_start_norm));
- ntot_end_norm = max(0, min(1., ntot_end_norm));
+ ntot_start_norm = std::min(1.0, std::max(0.0, ntot_start_norm));
+ ntot_end_norm = std::max(0.0, std::min(1.0, ntot_end_norm));
/* and calculate the overlap */
overlap = ntot_end_norm - ntot_start_norm;
{
int i, j;
- *Wmin = FLT_MAX;
- *Wmax = -FLT_MAX;
+ *Wmin = std::numeric_limits<float>::max();
+ *Wmax = -std::numeric_limits<float>::max();
for (i = 0; i < sc->nsamples; i++)
{
{
for (j = r->start; j < r->end; j++)
{
- *Wmin = min(*Wmin, s->du[j]*Wfac);
- *Wmax = max(*Wmax, s->du[j]*Wfac);
+ *Wmin = std::min(*Wmin, s->du[j]*Wfac);
+ *Wmax = std::max(*Wmax, s->du[j]*Wfac);
}
}
else
for (j = s->hist->nbin[hd]-1; j >= 0; j--)
{
- *Wmin = min(*Wmin, Wfac*(s->hist->x0[hd])*dx);
- *Wmax = max(*Wmax, Wfac*(s->hist->x0[hd])*dx);
+ *Wmin = std::min(*Wmin, Wfac*(s->hist->x0[hd])*dx);
+ *Wmax = std::max(*Wmax, Wfac*(s->hist->x0[hd])*dx);
/* look for the highest value bin with values */
if (s->hist->bin[hd][j] > 0)
{
- *Wmin = min(*Wmin, Wfac*(j+s->hist->x0[hd]+1)*dx);
- *Wmax = max(*Wmax, Wfac*(j+s->hist->x0[hd]+1)*dx);
+ *Wmin = std::min(*Wmin, Wfac*(j+s->hist->x0[hd]+1)*dx);
+ *Wmax = std::max(*Wmax, Wfac*(j+s->hist->x0[hd]+1)*dx);
break;
}
}
for (i = 0; i < n; i++)
{
- sum += 1./(1. + exp(Wfac*W[i] + sbMmDG));
+ sum += 1./(1. + std::exp(Wfac*W[i] + sbMmDG));
}
return sum;
{
double sum = 0.;
int i;
- int max;
+ int maxbin;
/* normalization factor multiplied with bin width and
number of samples (we normalize through M): */
double normdx = 1.;
{
hd = 1;
}
- dx = hist->dx[hd];
- max = hist->nbin[hd]-1;
+ dx = hist->dx[hd];
+ maxbin = hist->nbin[hd]-1;
if (type == 1)
{
- max = hist->nbin[hd]; /* we also add whatever was out of range */
+ maxbin = hist->nbin[hd]; /* we also add whatever was out of range */
}
- for (i = 0; i < max; i++)
+ for (i = 0; i < maxbin; i++)
{
double x = Wfac*((i+hist->x0[hd])+0.5)*dx; /* bin middle */
double pxdx = hist->bin[0][i]*normdx; /* p(x)dx */
- sum += pxdx/(1. + exp(x + sbMmDG));
+ sum += pxdx/(1. + std::exp(x + sbMmDG));
}
return sum;
double temp, double tol, int type)
{
double kT, beta, M;
- double DG;
- int i, j;
+ int i;
double Wfac1, Wfac2, Wmin, Wmax;
double DG0, DG1, DG2, dDG1;
- double sum1, sum2;
double n1, n2; /* numbers of samples as doubles */
kT = BOLTZ*temp;
n1 = ca->ntot;
n2 = cb->ntot;
- M = log(n1/n2);
+ M = std::log(n1/n2);
/*if (!lambda_vec_same(ca->native_lambda, ca->foreign_lambda))*/
if (ca->foreign_lambda->dhdl < 0)
sample_coll_min_max(ca, Wfac1, &Wmin1, &Wmax1);
sample_coll_min_max(cb, Wfac2, &Wmin2, &Wmax2);
- Wmin = min(Wmin1, Wmin2);
- Wmax = max(Wmax1, Wmax2);
+ Wmin = std::min(Wmin1, Wmin2);
+ Wmax = std::max(Wmax1, Wmax2);
}
DG0 = Wmin;
Wfac2 = -beta*delta_lambda;
}
- M = log(n1/n2);
+ M = std::log(n1/n2);
/* calculate average in both directions */
{
for (j = r->start; j < r->end; j++)
{
- sigmafact += 1./(2. + 2.*cosh((M + Wfac1*s->du[j] - dg)));
+ sigmafact += 1./(2. + 2.*std::cosh((M + Wfac1*s->du[j] - dg)));
}
}
else
double x = Wfac1*((j+s->hist->x0[0])+0.5)*dx; /*bin ctr*/
double pxdx = s->hist->bin[0][j]*normdx; /* p(x)dx */
- sigmafact += pxdx/(2. + 2.*cosh((M + x - dg)));
+ sigmafact += pxdx/(2. + 2.*std::cosh((M + x - dg)));
}
}
}
{
for (j = r->start; j < r->end; j++)
{
- sigmafact += 1./(2. + 2.*cosh((M - Wfac2*s->du[j] - dg)));
+ sigmafact += 1./(2. + 2.*std::cosh((M - Wfac2*s->du[j] - dg)));
}
}
else
double x = Wfac2*((j+s->hist->x0[0])+0.5)*dx; /*bin ctr*/
double pxdx = s->hist->bin[0][j]*normdx; /* p(x)dx */
- sigmafact += pxdx/(2. + 2.*cosh((M - x - dg)));
+ sigmafact += pxdx/(2. + 2.*std::cosh((M - x - dg)));
}
}
}
/* Eq. 10 from
Shirts, Bair, Hooker & Pande, Phys. Rev. Lett 91, 140601 (2003): */
- *stddev = sqrt(((1./sigmafact) - ( (n1+n2)/n1 + (n1+n2)/n2 )));
+ *stddev = std::sqrt(((1.0/sigmafact) - ( (n1+n2)/n1 + (n1+n2)/n2 )));
}
int npee, p;
double dg_sig2, sa_sig2, sb_sig2, stddev_sig2; /* intermediate variance values
for calculated quantities */
- int nsample1, nsample2;
double temp = br->a->temp;
- int i, j;
+ int i;
double dg_min, dg_max;
gmx_bool have_hist = FALSE;
dg_min = calc_bar_lowlevel(br->a, br->b, temp, tol, -1);
dg_max = calc_bar_lowlevel(br->a, br->b, temp, tol, 1);
- if (fabs(dg_max - dg_min) > GMX_REAL_EPS*10)
+ if (std::abs(dg_max - dg_min) > GMX_REAL_EPS*10)
{
/* the histogram range error is the biggest of the differences
between the best estimate and the extremes */
- br->dg_histrange_err = fabs(dg_max - dg_min);
+ br->dg_histrange_err = std::abs(dg_max - dg_min);
}
br->dg_disc_err = 0.;
for (i = 0; i < br->a->nsamples; i++)
{
if (br->a->s[i]->hist)
{
- br->dg_disc_err = max(br->dg_disc_err, br->a->s[i]->hist->dx[0]);
+ br->dg_disc_err = std::max(br->dg_disc_err, br->a->s[i]->hist->dx[0]);
}
}
for (i = 0; i < br->b->nsamples; i++)
{
if (br->b->s[i]->hist)
{
- br->dg_disc_err = max(br->dg_disc_err, br->b->s[i]->hist->dx[0]);
+ br->dg_disc_err = std::max(br->dg_disc_err, br->b->s[i]->hist->dx[0]);
}
}
}
dstddev2 /= npee;
stddev_sig2 += (dstddev2-dstddev*dstddev)/(npee-1);
}
- br->dg_err = sqrt(dg_sig2/(npee_max - npee_min + 1));
- br->sa_err = sqrt(sa_sig2/(npee_max - npee_min + 1));
- br->sb_err = sqrt(sb_sig2/(npee_max - npee_min + 1));
- br->dg_stddev_err = sqrt(stddev_sig2/(npee_max - npee_min + 1));
+ br->dg_err = std::sqrt(dg_sig2/(npee_max - npee_min + 1));
+ br->sa_err = std::sqrt(sa_sig2/(npee_max - npee_min + 1));
+ br->sb_err = std::sqrt(sb_sig2/(npee_max - npee_min + 1));
+ br->dg_stddev_err = std::sqrt(stddev_sig2/(npee_max - npee_min + 1));
}
}
svar += (s2 - s*s)/(nb - 1);
}
- return sqrt(svar/(nbmax + 1 - nbmin));
+ return std::sqrt(svar/(nbmax + 1 - nbmin));
}
/* first find the end of the name */
if (!name_end_found)
{
- if (isspace(*str) || (*str == '=') )
+ if (std::isspace(*str) || (*str == '=') )
{
name_end_found = TRUE;
}
}
else
{
- if (!( isspace(*str) || (*str == '=') ))
+ if (!( std::isspace(*str) || (*str == '=') ))
{
return str;
}
}
-
/* read a vector-notation description of a lambda vector */
static gmx_bool read_lambda_compvec(const char *str,
lambda_vec_t *lv,
{
if (!start_reached)
{
- if (isalnum(*str))
+ if (std::isalnum(*str))
{
vector = FALSE;
start_reached = TRUE;
vector = TRUE;
start_reached = TRUE;
}
- else if (!isspace(*str))
+ else if (!std::isspace(*str))
{
gmx_fatal(FARGS, "Error in lambda components in %s", fn);
}
{
if (val_start)
{
- if (isspace(*str) || *str == ')' || *str == ',' || *str == '\0')
+ if (std::isspace(*str) || *str == ')' || *str == ',' || *str == '\0')
{
/* end of value */
if (lv == NULL)
}
}
}
- else if (isalnum(*str))
+ else if (std::isalnum(*str))
{
val_start = str;
}
}
else
{
+ GMX_RELEASE_ASSERT(lc_in != NULL, "Internal inconsistency? lc_in==NULL");
if (n == lc_in->N)
{
return OK;
const char *legend,
lambda_vec_t *lam)
{
- double lambda = 0;
const char *ptr = NULL, *ptr2 = NULL;
gmx_bool ok = FALSE;
gmx_bool bdhdl = FALSE;
ptr2 = legend;
do
{
- ptr2 = strstr(ptr2, tostr);
+ ptr2 = std::strstr(ptr2, tostr);
if (ptr2 != NULL)
{
ptr = ptr2;
if (ptr)
{
- ptr += strlen(tostr)-1; /* and advance past that 'to' */
+ ptr += std::strlen(tostr)-1; /* and advance past that 'to' */
}
else
{
/* look for the = sign */
- ptr = strrchr(legend, '=');
+ ptr = std::strrchr(legend, '=');
if (!ptr)
{
/* otherwise look for the last space */
- ptr = strrchr(legend, ' ');
+ ptr = std::strrchr(legend, ' ');
}
}
- if (strstr(legend, "dH"))
+ if (std::strstr(legend, "dH"))
{
ok = TRUE;
bdhdl = TRUE;
}
- else if (strchr(legend, 'D') != NULL && strchr(legend, 'H') != NULL)
+ else if (std::strchr(legend, 'D') != NULL && std::strchr(legend, 'H') != NULL)
{
ok = TRUE;
bdhdl = FALSE;
}
- else /*if (strstr(legend, "pV"))*/
+ else /*if (std::strstr(legend, "pV"))*/
{
return FALSE;
}
{
int dhdl_index;
const char *end;
- char buf[STRLEN];
- ptr = strrchr(legend, '=');
+ ptr = std::strrchr(legend, '=');
end = ptr;
if (ptr)
{
gmx_fatal(FARGS, "dhdl legend '%s' %s faulty", legend, fn);
}
}
- while (!isspace(*ptr))
+ while (!std::isspace(*ptr))
{
ptr--;
if (ptr < legend)
}
}
ptr++;
- strncpy(buf, ptr, (end-ptr));
- buf[(end-ptr)] = '\0';
dhdl_index = lambda_components_find(lam->lc, ptr, (end-ptr));
if (dhdl_index < 0)
{
char buf[STRLEN];
- strncpy(buf, ptr, (end-ptr));
+ std::strncpy(buf, ptr, (end-ptr));
buf[(end-ptr)] = '\0';
gmx_fatal(FARGS,
"Did not find lambda component for '%s' in %s",
bFound = FALSE;
/* first check for a state string */
- ptr = strstr(subtitle, "state");
+ ptr = std::strstr(subtitle, "state");
if (ptr)
{
int index = -1;
ptr = find_value(ptr);
if (ptr)
{
- index = strtol(ptr, &end, 10);
+ index = std::strtol(ptr, &end, 10);
if (ptr == end)
{
gmx_fatal(FARGS, "Incomplete state data in %s", fn);
return FALSE;
}
/* now find the lambda vector component names */
- while (*ptr != '(' && !isalnum(*ptr))
+ while (*ptr != '(' && !std::isalnum(*ptr))
{
ptr++;
if (*ptr == '\0')
{
/* compatibility mode: check for lambda in other ways. */
/* plain text lambda string */
- ptr = strstr(subtitle, "lambda");
+ ptr = std::strstr(subtitle, "lambda");
if (ptr == NULL)
{
/* xmgrace formatted lambda string */
- ptr = strstr(subtitle, "\\xl\\f{}");
+ ptr = std::strstr(subtitle, "\\xl\\f{}");
}
if (ptr == NULL)
{
/* xmgr formatted lambda string */
- ptr = strstr(subtitle, "\\8l\\4");
+ ptr = std::strstr(subtitle, "\\8l\\4");
}
if (ptr != NULL)
{
- ptr = strstr(ptr, "=");
+ ptr = std::strstr(ptr, "=");
}
if (ptr != NULL)
{
return bFound;
}
-static void filename2lambda(const char *fn)
+static double filename2lambda(const char *fn)
{
double lambda;
const char *ptr, *digitptr;
}
/* save the last position of a digit between the last two
separators = in the last dirname */
- if (dirsep > 0 && isdigit(*ptr))
+ if (dirsep > 0 && std::isdigit(*ptr))
{
digitptr = ptr;
}
{
gmx_fatal(FARGS, "Malformed number in file path '%s'", fn);
}
+ return lambda;
}
static void read_bar_xvg_lowlevel(const char *fn, real *temp, xvg_t *ba,
int np;
gmx_bool native_lambda_read = FALSE;
char buf[STRLEN];
- lambda_vec_t lv;
xvg_init(ba);
if (subtitle != NULL)
{
/* try to extract temperature */
- ptr = strstr(subtitle, "T =");
+ ptr = std::strstr(subtitle, "T =");
if (ptr != NULL)
{
ptr += 3;
{
if (!native_lambda_read)
{
- /* Deduce lambda from the file name */
+ // Deduce lambda from the file name.
+ // Updated the routine filename2lambda to actually return lambda
+ // to avoid C++ warnings, but this usage does not seem to need it?
+ // EL 2015-07-10
filename2lambda(fn);
native_lambda_read = TRUE;
}
xvg_t *barsim;
samples_t *s;
int i;
- double *lambda;
snew(barsim, 1);
double *last_t, const char *filename)
{
int i, j;
- gmx_bool allocated;
- double old_foreign_lambda;
lambda_vec_t *foreign_lambda;
int type;
samples_t *s; /* convenience pointer */
int i, j;
samples_t *s;
int nhist;
- double old_foreign_lambda;
lambda_vec_t *foreign_lambda;
int type;
int nbins[2];
snew(foreign_lambda, 1);
lambda_vec_init(foreign_lambda, native_lambda->lc);
lambda_vec_copy(foreign_lambda, native_lambda);
- type = (int)(blk->sub[1].lval[1]);
+ type = static_cast<int>(blk->sub[1].lval[1]);
if (type == dhbtDH)
{
double old_foreign_lambda;
for (i = 0; i < nhist; i++)
{
- int nbin;
gmx_int64_t sum = 0;
for (j = 0; j < s->hist->nbin[i]; j++)
{
- int binv = (int)(blk->sub[i+2].ival[j]);
+ int binv = static_cast<int>(blk->sub[i+2].ival[j]);
s->hist->bin[i][j] = binv;
sum += binv;
int *npts = NULL; /* array to keep count & print at end */
lambda_vec_t **lambdas = NULL; /* array to keep count & print at end */
lambda_vec_t *native_lambda;
- double end_time; /* the end time of the last batch of samples */
int nsamples = 0;
lambda_vec_t start_lambda;
}
/* read the data from the DHCOLL block */
- rtemp = fr->block[i].sub[0].dval[0];
- start_time = fr->block[i].sub[0].dval[1];
- delta_time = fr->block[i].sub[0].dval[2];
+ rtemp = fr->block[i].sub[0].dval[0];
+ start_time = fr->block[i].sub[0].dval[1];
+ delta_time = fr->block[i].sub[0].dval[2];
old_start_lambda = fr->block[i].sub[0].dval[3];
delta_lambda = fr->block[i].sub[0].dval[4];
{
/* check the components */
lambda_components_check(&(sd->lc), j, name,
- strlen(name));
+ std::strlen(name));
}
else
{
lambda_components_add(&(sd->lc), name,
- strlen(name));
+ std::strlen(name));
}
}
lambda_vec_init(&start_lambda, &(sd->lc));
gmx_fatal(FARGS, "Can't handle both raw delta U data and histograms in the same file %s", fn);
}
- if (nsamples > 0)
+ if (nsamples == 0)
{
+ /* this is the first round; allocate the associated data
+ structures */
+ /*native_lambda=start_lambda;*/
+ lambda_vec_init(native_lambda, &(sd->lc));
+ lambda_vec_copy(native_lambda, &start_lambda);
+ nsamples = nblocks_raw+nblocks_hist;
+ snew(nhists, nsamples);
+ snew(npts, nsamples);
+ snew(lambdas, nsamples);
+ snew(samples_rawdh, nsamples);
+ for (i = 0; i < nsamples; i++)
+ {
+ nhists[i] = 0;
+ npts[i] = 0;
+ lambdas[i] = NULL;
+ samples_rawdh[i] = NULL; /* init to NULL so we know which
+ ones contain values */
+ }
+ }
+ else
+ {
+ // nsamples > 0 means this is NOT the first iteration
+
/* check the native lambda */
if (!lambda_vec_same(&start_lambda, native_lambda) )
{
}
/* check whether last iterations's end time matches with
the currrent start time */
- if ( (fabs(last_t - start_time) > 2*delta_time) && last_t >= 0)
+ if ( (std::abs(last_t - start_time) > 2*delta_time) && last_t >= 0)
{
/* it didn't. We need to store our samples and reallocate */
+
for (i = 0; i < nsamples; i++)
{
+ // nsamples is always >0 here, so samples_rawdh must be a valid pointer. Unfortunately
+ // cppcheck does not understand the logic unless the assert is inside the loop, but
+ // this is not performance-sensitive code.
+ GMX_RELEASE_ASSERT(samples_rawdh != NULL, "samples_rawdh==NULL with nsamples>0");
if (samples_rawdh[i])
{
/* insert it into the existing list */
}
}
}
- else
- {
- /* this is the first round; allocate the associated data
- structures */
- /*native_lambda=start_lambda;*/
- lambda_vec_init(native_lambda, &(sd->lc));
- lambda_vec_copy(native_lambda, &start_lambda);
- nsamples = nblocks_raw+nblocks_hist;
- snew(nhists, nsamples);
- snew(npts, nsamples);
- snew(lambdas, nsamples);
- snew(samples_rawdh, nsamples);
- for (i = 0; i < nsamples; i++)
- {
- nhists[i] = 0;
- npts[i] = 0;
- lambdas[i] = NULL;
- samples_rawdh[i] = NULL; /* init to NULL so we know which
- ones contain values */
- }
- }
/* and read them */
k = 0; /* counter for the lambdas, etc. arrays */
}
else if (fr->block[i].id == enxDHHIST)
{
- int type = (int)(fr->block[i].sub[1].lval[1]);
+ int type = static_cast<int>(fr->block[i].sub[1].lval[1]);
if (type == dhbtDH || type == dhbtDHDL)
{
int j;
int nd = 2, nbmin = 5, nbmax = 5;
int nbin = 100;
gmx_bool use_dhdl = FALSE;
- gmx_bool calc_s, calc_v;
- t_pargs pa[] = {
+ t_pargs pa[] = {
{ "-b", FALSE, etREAL, {&begin}, "Begin time for BAR" },
{ "-e", FALSE, etREAL, {&end}, "End time for BAR" },
{ "-temp", FALSE, etREAL, {&temp}, "Temperature (K)" },
};
#define NFILE asize(fnm)
- int f, i, j;
+ int f;
int nf = 0; /* file counter */
- int nbs;
int nfile_tot; /* total number of input files */
int nxvgfile = 0;
int nedrfile = 0;
int nresults; /* number of results in results array */
double *partsum;
- double prec, dg_tot, dg, sig, dg_tot_max, dg_tot_min;
+ double prec, dg_tot;
FILE *fpb, *fpi;
char dgformat[20], xvg2format[STRLEN], xvg3format[STRLEN];
char buf[STRLEN], buf2[STRLEN];
char ktformat[STRLEN], sktformat[STRLEN];
char kteformat[STRLEN], skteformat[STRLEN];
output_env_t oenv;
- double kT, beta;
+ double kT;
gmx_bool result_OK = TRUE, bEE = TRUE;
gmx_bool disc_err = FALSE;
{
gmx_fatal(FARGS, "Can not have negative number of digits");
}
- prec = pow(10, -nd);
+ prec = std::pow(10.0, static_cast<double>(-nd));
snew(partsum, (nbmax+1)*(nbmax+1));
nf = 0;
if (sum_disc_err > prec)
{
prec = sum_disc_err;
- nd = ceil(-log10(prec));
+ nd = static_cast<int>(std::ceil(-std::log10(prec)));
printf("WARNING: setting the precision to %g because that is the minimum\n reasonable number, given the expected discretization error.\n", prec);
}
/* print results in kT */
kT = BOLTZ*temp;
- beta = 1/kT;
printf("\nTemperature: %g K\n", temp);
{
stat_err = bar_err(nbmin, nbmax, partsum)*kT;
printf(" +/- ");
- printf(dgformat, max(max(stat_err, sum_disc_err), sum_histrange_err));
+ printf(dgformat, std::max(std::max(stat_err, sum_disc_err), sum_histrange_err));
}
printf("\n");
if (disc_err)