#include "config.h"
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cctype>
+#include <cmath>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
#include <algorithm>
#include <sstream>
}
for (i = 0; i < nl-1; i++)
{
- if (fabs(y[0][i+1]-y[0][i]-opt->tabDz) > opt->tabDz/1e6)
+ if (std::abs(y[0][i+1]-y[0][i]-opt->tabDz) > opt->tabDz/1e6)
{
gmx_fatal(FARGS, "z-values in %s are not equally spaced.\n", ny, fn);
}
}
ist.str(line);
ist >> Buffer0 >> Buffer1 >> Buffer2;
- if (strcmp(Buffer1, "UMBRELLA"))
+ if (std::strcmp(Buffer1, "UMBRELLA"))
{
gmx_fatal(FARGS, "This does not appear to be a valid pdo file. Found %s, expected %s\n"
"(Found in first line: `%s')\n",
Buffer1, "UMBRELLA", line);
}
- if (strcmp(Buffer2, "3.0"))
+ if (std::strcmp(Buffer2, "3.0"))
{
gmx_fatal(FARGS, "This does not appear to be a version 3.0 pdo file");
}
}
ist.str(line);
ist >> Buffer3;
- if (strcmp(Buffer3, "#####") != 0)
+ if (std::strcmp(Buffer3, "#####") != 0)
{
gmx_fatal(FARGS, "Expected '#####', found %s. Hick.\n", Buffer3);
}
return NULL;
}
p = ptr;
- while ((strchr(ptr, '\n') == NULL) && (!feof(fp)))
+ while ((std::strchr(ptr, '\n') == NULL) && (!feof(fp)))
{
/* This line is longer than len characters, let's increase len! */
*len += STRLEN;
break;
}
}
- slen = strlen(ptr);
+ slen = std::strlen(ptr);
if (ptr[slen-1] == '\n')
{
ptr[slen-1] = '\0';
gmx_bool bGetMinMax, real *mintmp, real *maxtmp)
{
int i, inttemp, bins, count, ntot;
- real min, max, minfound = 1e20, maxfound = -1e20;
+ real minval, maxval, minfound = 1e20, maxfound = -1e20;
double temp, time, time0 = 0, dt;
char *ptr = 0;
t_UmbrellaWindow * window = 0;
if (!bGetMinMax)
{
- bins = opt->bins;
- min = opt->min;
- max = opt->max;
+ bins = opt->bins;
+ minval = opt->min;
+ maxval = opt->max;
window = win+fileno;
/* Need to alocate memory and set up structure */
{
minfound = 1e20;
maxfound = -1e20;
- min = max = bins = 0; /* Get rid of warnings */
+ minval = maxval = bins = 0; /* Get rid of warnings */
}
count = 0;
{
trim(ptr);
- if (ptr[0] == '#' || strlen(ptr) < 2)
+ if (ptr[0] == '#' || std::strlen(ptr) < 2)
{
continue;
}
/* Initiate format string */
fmtign[0] = '\0';
- strcat(fmtign, "%*s");
+ std::strcat(fmtign, "%*s");
sscanf(ptr, fmtlf, &time); /* printf("Time %f\n",time); */
/* Round time to fs */
{
for (i = 0; i < header->nPull; ++i)
{
- strcpy(fmt, fmtign);
- strcat(fmt, "%lf"); /* Creating a format stings such as "%*s...%*s%lf" */
- strcat(fmtign, "%*s"); /* ignoring one more entry in the next loop */
+ std::strcpy(fmt, fmtign);
+ std::strcat(fmt, "%lf"); /* Creating a format stings such as "%*s...%*s%lf" */
+ std::strcat(fmtign, "%*s"); /* ignoring one more entry in the next loop */
if (sscanf(ptr, fmt, &temp))
{
temp += header->UmbPos[i][0];
window->ztime[i][ntot] = temp;
}
- temp -= min;
- temp /= (max-min);
+ temp -= minval;
+ temp /= (maxval-minval);
temp *= bins;
- temp = floor(temp);
+ temp = std::floor(temp);
inttemp = static_cast<int> (temp);
if (opt->bCycl)
int jl, ju;
double pl, pu, dz, dp;
- jl = static_cast<int> (floor((dist-opt->tabMin)/opt->tabDz));
+ jl = static_cast<int> (std::floor((dist-opt->tabMin)/opt->tabDz));
ju = jl+1;
if (jl < 0 || ju >= opt->tabNbins)
{
{
U = tabulated_pot(distance, opt); /* Use tabulated potential */
}
- contrib1 = profile[k]*exp(-U/(8.314e-3*opt->Temperature));
- contrib2 = window[i].N[j]*exp(-U/(8.314e-3*opt->Temperature) + window[i].z[j]);
+ contrib1 = profile[k]*std::exp(-U/(8.314e-3*opt->Temperature));
+ contrib2 = window[i].N[j]*std::exp(-U/(8.314e-3*opt->Temperature) + window[i].z[j]);
window[i].bContrib[j][k] = (contrib1 > wham_contrib_lim || contrib2 > wham_contrib_lim);
bAnyContrib = (bAnyContrib | window[i].bContrib[j][k]);
if (window[i].bContrib[j][k])
{
U = tabulated_pot(distance, opt); /* Use tabulated potential */
}
- denom += invg*window[j].N[k]*exp(-U/(8.314e-3*opt->Temperature) + window[j].z[k]);
+ denom += invg*window[j].N[k]*std::exp(-U/(8.314e-3*opt->Temperature) + window[j].z[k]);
}
}
profile[i] = num/denom;
{
U = tabulated_pot(distance, opt); /* Use tabulated potential */
}
- total += profile[k]*exp(-U/(8.314e-3*opt->Temperature));
+ total += profile[k]*std::exp(-U/(8.314e-3*opt->Temperature));
}
/* Avoid floating point exception if window is far outside min and max */
if (total != 0.0)
{
- total = -log(total);
+ total = -std::log(total);
}
else
{
total = 1000.0;
}
- temp = fabs(total - window[i].z[j]);
+ temp = std::abs(total - window[i].z[j]);
if (temp > maxloc)
{
maxloc = temp;
z = min+(i+0.5)*dz;
zsym = -z;
/* bin left of zsym */
- j = static_cast<int> (floor((zsym-min)/dz-0.5));
+ j = static_cast<int> (std::floor((zsym-min)/dz-0.5));
if (j >= 0 && (j+1) < bins)
{
/* interpolate profile linearly between bins j and j+1 */
}
}
- memcpy(profile, prof2, bins*sizeof(double));
+ std::memcpy(profile, prof2, bins*sizeof(double));
sfree(prof2);
}
{
if (profile[i] > 0.0)
{
- profile[i] = -log(profile[i])*unit_factor;
+ profile[i] = -std::log(profile[i])*unit_factor;
}
}
if (opt->bs_verbose)
{
- snew(fn, strlen(fnhist)+10);
- snew(buf, strlen(fnhist)+10);
- sprintf(fn, "%s_cumul.xvg", strncpy(buf, fnhist, strlen(fnhist)-4));
+ snew(fn, std::strlen(fnhist)+10);
+ snew(buf, std::strlen(fnhist)+10);
+ sprintf(fn, "%s_cumul.xvg", std::strncpy(buf, fnhist, std::strlen(fnhist)-4));
fp = xvgropen(fn, "CDFs of umbrella windows", xlabel, "CDF", opt->oenv);
}
"cannot be predicted. You have 3 options:\n"
"1) Make g_wham estimate the ACTs (options -ac and -acsig).\n"
"2) Calculate the ACTs by yourself (e.g. with g_analyze) and provide them\n");
- strcat(errstr,
- " with option -iiact for all umbrella windows.\n"
- "3) If all ACTs are identical and know, you can define them with -bs-tau.\n"
- " Use option (3) only if you are sure what you're doing, you may severely\n"
- " underestimate the error if a too small ACT is given.\n");
+ std::strcat(errstr,
+ " with option -iiact for all umbrella windows.\n"
+ "3) If all ACTs are identical and know, you can define them with -bs-tau.\n"
+ " Use option (3) only if you are sure what you're doing, you may severely\n"
+ " underestimate the error if a too small ACT is given.\n");
gmx_fatal(FARGS, errstr);
}
Note: The ACT of the flat distribution and of the generated histogram is not
100% exactly tau, but near tau (my test was 3.8 instead of 4).
*/
- a = exp(-1.0/tausteps);
- ap = sqrt(1-a*a);
- invsqrt2 = 1./sqrt(2.0);
+ a = std::exp(-1.0/tausteps);
+ ap = std::sqrt(1.0-a*a);
+ invsqrt2 = 1.0/std::sqrt(2.0);
/* init random sequence */
x = gmx_rng_gaussian_table(opt->rng);
y = gmx_rng_gaussian_table(opt->rng);
x = a*x+ap*y;
z = x*sig+mu;
- ibin = static_cast<int> (floor((z-opt->min)/opt->dz));
+ ibin = static_cast<int> (std::floor((z-opt->min)/opt->dz));
if (opt->bCycl)
{
if (ibin < 0)
if (bs_index >= 0)
{
- snew(fn, strlen(fnhist)+10);
- snew(buf, strlen(fnhist)+1);
- sprintf(fn, "%s_bs%d.xvg", strncpy(buf, fnhist, strlen(fnhist)-4), bs_index);
+ snew(fn, std::strlen(fnhist)+10);
+ snew(buf, std::strlen(fnhist)+1);
+ sprintf(fn, "%s_bs%d.xvg", std::strncpy(buf, fnhist, std::strlen(fnhist)-4), bs_index);
sprintf(title, "Umbrella histograms. Bootstrap #%d", bs_index);
}
else
{
fn = gmx_strdup(fnhist);
- strcpy(title, "Umbrella histograms");
+ std::strcpy(title, "Umbrella histograms");
}
fp = xvgropen(fn, title, xlabel, "count", opt->oenv);
/* Write histograms */
for (l = 0; l < bins; ++l)
{
- fprintf(fp, "%e\t", (double)(l+0.5)*opt->dz+opt->min);
+ fprintf(fp, "%e\t", (l+0.5)*opt->dz+opt->min);
for (i = 0; i < nWindows; ++i)
{
for (j = 0; j < window[i].nPull; ++j)
i = 0;
bExact = FALSE;
maxchange = 1e20;
- memcpy(bsProfile, profile, opt->bins*sizeof(double)); /* use profile as guess */
+ std::memcpy(bsProfile, profile, opt->bins*sizeof(double)); /* use profile as guess */
do
{
if ( (i%opt->stepUpdateContrib) == 0)
bsProfiles_av [i] /= opt->nBootStrap;
bsProfiles_av2[i] /= opt->nBootStrap;
tmp = bsProfiles_av2[i]-sqr(bsProfiles_av[i]);
- stddev = (tmp >= 0.) ? sqrt(tmp) : 0.; /* Catch rouding errors */
+ stddev = (tmp >= 0.) ? std::sqrt(tmp) : 0.; /* Catch rouding errors */
fprintf(fp, "%e\t%e\t%e\n", (i+0.5)*opt->dz+opt->min, bsProfiles_av [i], stddev);
}
xvgrclose(fp);
int whaminFileType(char *fn)
{
int len;
- len = strlen(fn);
- if (strcmp(fn+len-3, "tpr") == 0)
+ len = std::strlen(fn);
+ if (std::strcmp(fn+len-3, "tpr") == 0)
{
return whamin_tpr;
}
- else if (strcmp(fn+len-3, "xvg") == 0 || strcmp(fn+len-6, "xvg.gz") == 0)
+ else if (std::strcmp(fn+len-3, "xvg") == 0 || std::strcmp(fn+len-6, "xvg.gz") == 0)
{
return whamin_pullxf;
}
- else if (strcmp(fn+len-3, "pdo") == 0 || strcmp(fn+len-6, "pdo.gz") == 0)
+ else if (std::strcmp(fn+len-3, "pdo") == 0 || std::strcmp(fn+len-6, "pdo.gz") == 0)
{
return whamin_pdo;
}
sizenow = 0;
while (fgets(tmp, sizeof(tmp), fp) != NULL)
{
- if (strlen(tmp) >= WHAM_MAXFILELEN)
+ if (std::strlen(tmp) >= WHAM_MAXFILELEN)
{
gmx_fatal(FARGS, "Filename too long in %s. Only %d characters allowed.\n", fn, WHAM_MAXFILELEN);
}
}
}
/* remove newline if there is one */
- if (tmp[strlen(tmp)-1] == '\n')
+ if (tmp[std::strlen(tmp)-1] == '\n')
{
- tmp[strlen(tmp)-1] = '\0';
+ tmp[std::strlen(tmp)-1] = '\0';
}
- strcpy(filename[nread], tmp);
+ std::strcpy(filename[nread], tmp);
if (opt->verbose)
{
printf("Found file %s in %s\n", filename[nread], fn);
static gmx_bool bFirst = 1;
/* gzipped pdo file? */
- if ((strcmp(fn+strlen(fn)-3, ".gz") == 0))
+ if ((std::strcmp(fn+std::strlen(fn)-3, ".gz") == 0))
{
/* search gunzip executable */
if (!(Path = getenv("GMX_PATH_GZIP")))
{
r2 += sqr(dx[i][line]);
}
- return sqrt(r2);
+ return std::sqrt(r2);
}
//! Read pullx.xvg or pullf.xvg
window->ztime[gUsed][ntot] = pos;
}
- ibin = static_cast<int> (floor((pos-min)/(max-min)*bins));
+ ibin = static_cast<int> (std::floor((pos-min)/(max-min)*bins));
if (opt->bCycl)
{
if (ibin < 0)
siglim = 3.0*opt->sigSmoothIact;
siglim2 = dsqr(siglim);
/* pre-factor of Gaussian */
- gaufact = 1.0/(sqrt(2*M_PI)*opt->sigSmoothIact);
+ gaufact = 1.0/(std::sqrt(2*M_PI)*opt->sigSmoothIact);
invtwosig2 = 0.5/dsqr(opt->sigSmoothIact);
for (i = 0; i < nwins; i++)
dpos2 = dsqr(window[j].pos[jg]-pos);
if (dpos2 < siglim2)
{
- w = gaufact*exp(-dpos2*invtwosig2);
+ w = gaufact*std::exp(-dpos2*invtwosig2);
weight += w;
tausm += w*window[j].tau[jg];
/*printf("Weight %g dpos2=%g pos=%g gaufact=%g invtwosig2=%g\n",
diff = ztime[k]-av;
sum2 += diff*diff;
}
- sig = sqrt(sum2/ntot);
+ sig = std::sqrt(sum2/ntot);
window[i].aver[ig] = av;
/* Note: This estimate for sigma is biased from the limited sampling.
for (ig = 0; ig < window[i].nPull; ig++)
{
hispos = window[i].pos[ig];
- dist = fabs(hispos-pos);
+ dist = std::abs(hispos-pos);
/* average force within bin */
if (dist < dz/2)
{
*/
for (j = 0; j < opt->bins; ++j)
{
- pot[j] = exp(-pot[j]/(8.314e-3*opt->Temperature));
+ pot[j] = std::exp(-pot[j]/(8.314e-3*opt->Temperature));
}
calc_z(pot, window, nWindows, opt, TRUE);
int i, n, is[2];
int cur = 0;
- if (strlen(ptr) == 0)
+ if (std::strlen(ptr) == 0)
{
return 0;
}
fmtign[0] = '\0';
for (i = 0; i < n; i++)
{
- strcpy(fmt, fmtign);
- strcat(fmt, "%d");
+ std::strcpy(fmt, fmtign);
+ std::strcat(fmt, "%d");
if (sscanf(ptr, fmt, &temp))
{
opt->groupsel[iline].bUse[i] = (temp > 0);
opt->groupsel[iline].nUse++;
}
}
- strcat(fmtign, "%*s");
+ std::strcat(fmtign, "%*s");
}
iline++;
}
xlabel, "count", opt.oenv);
for (l = 0; l < opt.bins; ++l)
{
- fprintf(histout, "%e\t", (double)(l+0.5)/opt.bins*(opt.max-opt.min)+opt.min);
+ fprintf(histout, "%e\t", (l+0.5)/opt.bins*(opt.max-opt.min)+opt.min);
for (i = 0; i < nwins; ++i)
{
for (j = 0; j < window[i].nPull; ++j)
if (opt.bLog)
{
prof_normalization_and_unit(profile, &opt);
- strcpy(ylabel, en_unit_label[opt.unit]);
- strcpy(title, "Umbrella potential");
+ std::strcpy(ylabel, en_unit_label[opt.unit]);
+ std::strcpy(title, "Umbrella potential");
}
else
{
- strcpy(ylabel, "Density of states");
- strcpy(title, "Density of states");
+ std::strcpy(ylabel, "Density of states");
+ std::strcpy(title, "Density of states");
}
/* symmetrize profile around z=0? */
profout = xvgropen(opt2fn("-o", NFILE, fnm), title, xlabel, ylabel, opt.oenv);
for (i = 0; i < opt.bins; ++i)
{
- fprintf(profout, "%e\t%e\n", (double)(i+0.5)/opt.bins*(opt.max-opt.min)+opt.min, profile[i]);
+ fprintf(profout, "%e\t%e\n", (i+0.5)/opt.bins*(opt.max-opt.min)+opt.min, profile[i]);
}
xvgrclose(profout);
printf("Wrote %s\n", opt2fn("-o", NFILE, fnm));