*/
#include "gmxpre.h"
-#include <ctype.h>
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cctype>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
#include "gromacs/fileio/pdbio.h"
#include "gromacs/fileio/xvgr.h"
#include "gromacs/gmxana/eigio.h"
+#include "gromacs/gmxana/gmx_ana.h"
#include "gromacs/legacyheaders/macros.h"
#include "gromacs/legacyheaders/readinp.h"
#include "gromacs/legacyheaders/txtdump.h"
int i, istep;
char c;
char *pos, *startpos, *step;
- int n = strlen(str);
+ int n = std::strlen(str);
/*enums to define the different lexical stati */
enum {
step = NULL;
snew(pos, n+4);
startpos = pos;
- strcpy(pos, str);
+ std::strcpy(pos, str);
pos[n] = ',';
pos[n+1] = '1';
pos[n+2] = '\0';
switch (status)
{
/* expect a number */
- case sBefore: if (isdigit(c))
+ case sBefore: if (std::isdigit(c))
{
start = pos;
status = sNumber;
{
/*store number*/
srenew(*list, nvecs+1);
- (*list)[nvecs++] = number = strtol(start, NULL, 10);
+ (*list)[nvecs++] = number = std::strtol(start, NULL, 10);
status = sBefore;
if (number == 0)
{
{
status = sMinus; break;
}
- else if (isdigit(c))
+ else if (std::isdigit(c))
{
break;
}
/* have read a '-' -> expect a number */
case sMinus:
- if (isdigit(c))
+ if (std::isdigit(c))
{
end = pos;
status = sRange; break;
} break;
case sSteppedRange:
- if (isdigit(c))
+ if (std::isdigit(c))
{
if (step)
{
if (c == ',')
{
/*store numbers*/
- end_number = strtol(end, NULL, 10);
- number = strtol(start, NULL, 10);
+ end_number = std::strtol(end, NULL, 10);
+ number = std::strtol(start, NULL, 10);
status = sBefore;
if (number == 0)
{
status = sSteppedRange;
break;
}
- else if (isdigit(c))
+ else if (std::isdigit(c))
{
break;
}
*/
int n = 0, i; rvec x;
- real sum;
while (eig_list[n++])
{
; /*count selected eigenvecs*/
/* dump coordinates of the selected eigenvectors */
while (eig_list[n])
{
- sum = 0;
for (i = 0; i < natoms; i++)
{
if (eig_list[n] > nvec)
gmx_fatal(FARGS, "Selected eigenvector %d is higher than maximum number %d of available eigenvectors", eig_list[n], nvec);
}
copy_rvec(eigvecs[eig_list[n]-1][i], x);
- sum += norm2(x);
fprintf(fp, "%8.5f %8.5f %8.5f\n", x[XX], x[YY], x[ZZ]);
}
n++;
static real *scan_vecparams(const char *str, const char * par, int nvecs)
{
char f0[256], f1[256]; /*format strings adapted every pass of the loop*/
- double d, tcap = 0;
+ double d;
int i;
real *vec_params;
f0[0] = '\0';
for (i = 0; (i < nvecs); i++)
{
- strcpy(f1, f0); /*f0 is the format string for the "to-be-ignored" numbers*/
- strcat(f1, "%lf"); /*and f1 to read the actual number in this pass of the loop*/
+ std::strcpy(f1, f0); /*f0 is the format string for the "to-be-ignored" numbers*/
+ std::strcat(f1, "%lf"); /*and f1 to read the actual number in this pass of the loop*/
if (sscanf(str, f1, &d) != 1)
{
gmx_fatal(FARGS, "Not enough elements for %s parameter (I need %d)", par, nvecs);
}
vec_params[i] = d;
- tcap += d;
- strcat(f0, "%*s");
+ std::strcat(f0, "%*s");
}
}
return vec_params;
char title[STRLEN];
matrix topbox;
rvec *xtop;
- gmx_bool bTop, bFit1;
+ gmx_bool bFit1;
t_filenm fnm[] = {
{ efTRN, "-f", "eigenvec", ffREAD },
read_eigenvectors(EigvecFile, &nav, &bFit1,
&xref1, &edi_params.fitmas, &xav1, &edi_params.pcamas, &nvec1, &eignr1, &eigvec1, &eigval1);
- bTop = read_tps_conf(ftp2fn(efTPS, NFILE, fnm),
- title, &top, &ePBC, &xtop, NULL, topbox, 0);
+ read_tps_conf(ftp2fn(efTPS, NFILE, fnm),
+ title, &top, &ePBC, &xtop, NULL, topbox, 0);
atoms = &top.atoms;
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,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.
*/
#include "gmxpre.h"
-#include <ctype.h>
-#include <string.h>
+#include <cctype>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
+#include "gromacs/gmxana/gmx_ana.h"
#include "gromacs/legacyheaders/macros.h"
#include "gromacs/legacyheaders/typedefs.h"
#include "gromacs/math/vec.h"
*/
const char *spec = " !&|";
- return (c != '\0' && strchr(spec, c) == NULL);
+ return (c != '\0' && std::strchr(spec, c) == NULL);
}
static int parse_names(char **string, int *n_names, char **names)
*c = ' ';
- if (isdigit((*string)[0]))
+ if (std::isdigit((*string)[0]))
{
*nr = (*string)[0]-'0';
(*string)++;
- while (isdigit((*string)[0]))
+ while (std::isdigit((*string)[0]))
{
*nr = (*nr)*10+(*string)[0]-'0';
(*string)++;
}
- if (isalpha((*string)[0]))
+ if (std::isalpha((*string)[0]))
{
*c = (*string)[0];
(*string)++;
}
/* Check if there is at most one non-digit character */
- if (!isalnum((*string)[0]))
+ if (!std::isalnum((*string)[0]))
{
bRet = TRUE;
}
c = (*string)[0];
(*string)++;
s = gmx_strdup((*string));
- sp = strchr(s, c);
+ sp = std::strchr(s, c);
if (sp != NULL)
{
(*string) += sp-s + 1;
{
sprintf(buf, "a_%d-%d", n1, up);
}
- strcpy(gname, buf);
+ std::strcpy(gname, buf);
}
}
else
index[*nr] = i-1;
(*nr)++;
sprintf(buf, "_%d", i);
- strcat(gname, buf);
+ std::strcat(gname, buf);
}
else
{
{
sprintf(buf, "r_%d-%d", n1, up);
}
- strcpy(gname, buf);
+ std::strcpy(gname, buf);
}
else
{
}
}
sprintf(buf, "_%d", j);
- strcat(gname, buf);
+ std::strcat(gname, buf);
}
while (parse_int_char(string, &j, &c));
}
{
sprintf(buf, "r_%d-%d", n1, up);
}
- strcpy(gname, buf);
+ std::strcpy(gname, buf);
}
else
{
}
}
sprintf(buf, "_%d", j);
- strcat(gname, buf);
+ std::strcat(gname, buf);
}
while (parse_int_char(string, &j, &c));
}
break;
default:
/* Compare a single character */
- if (( bCase && strncmp(name, search, 1)) ||
+ if (( bCase && std::strncmp(name, search, 1)) ||
(!bCase && gmx_strncasecmp(name, search, 1)))
{
return FALSE;
{
int i;
- strcpy(gname, names[0]);
+ std::strcpy(gname, names[0]);
for (i = 1; i < n; i++)
{
- strcat(gname, "_");
- strcat(gname, names[i]);
+ std::strcat(gname, "_");
+ std::strcat(gname, names[i]);
}
}
while (ca_start < natoms)
{
- while ((ca_start < natoms) && strcmp(*atoms->atomname[ca_start], "CA"))
+ while ((ca_start < natoms) && std::strcmp(*atoms->atomname[ca_start], "CA"))
{
ca_start++;
}
{
i++;
}
- while ((i < natoms) && strcmp(*atoms->atomname[i], "CA"));
+ while ((i < natoms) && std::strcmp(*atoms->atomname[i], "CA"));
if (i < natoms)
{
rvec_sub(x[ca_end], x[i], vec);
if ((sel_nr1 >= 0) && (sel_nr1 < block->nr))
{
copy_group(sel_nr1, block, nr, index);
- strcpy(gname, (*gn)[sel_nr1]);
+ std::strcpy(gname, (*gn)[sel_nr1]);
printf("Copied index group %d '%s'\n", sel_nr1, (*gn)[sel_nr1]);
bRet = TRUE;
}
}
}
}
- else if (strncmp(*string, "res", 3) == 0)
+ else if (std::strncmp(*string, "res", 3) == 0)
{
(*string) += 3;
if (check_have_atoms(atoms, ostring) &&
sprintf(gname, "atom_%s", (*gn)[sel_nr1]);
}
}
- else if (strncmp(*string, "ri", 2) == 0)
+ else if (std::strncmp(*string, "ri", 2) == 0)
{
(*string) += 2;
if (check_have_atoms(atoms, ostring) &&
}
}
}
- else if (strncmp(*string, "chain", 5) == 0)
+ else if (std::strncmp(*string, "chain", 5) == 0)
{
(*string) += 5;
if (check_have_atoms(atoms, ostring) &&
sprintf(gname, "ch%s", names[0]);
for (i = 1; i < n_names; i++)
{
- strcat(gname, names[i]);
+ std::strcat(gname, names[i]);
}
}
}
}
sfree(index1);
- for (i = strlen(gname)+1; i > 0; i--)
+ for (i = std::strlen(gname)+1; i > 0; i--)
{
gname[i] = gname[i-1];
}
resind = atoms->atom[i].resind;
if ((resind != prev_resind) || (i == atoms->nr-1))
{
- if ((bDiff = strcmp(*atoms->resinfo[resind].name,
- *atoms->resinfo[start].name)) ||
+ if ((bDiff = std::strcmp(*atoms->resinfo[resind].name,
+ *atoms->resinfo[start].name)) ||
(i == atoms->nr-1))
{
if (bDiff)
{
gmx_fatal(FARGS, "Error reading user input");
}
- inp_string[strlen(inp_string)-1] = 0;
+ inp_string[std::strlen(inp_string)-1] = 0;
printf("\n");
string = inp_string;
while (string[0] == ' ')
getchar();
}
}
- else if (strncmp(string, "del", 3) == 0)
+ else if (std::strncmp(string, "del", 3) == 0)
{
string += 3;
if (parse_int(&string, &sel_nr))
}
}
}
- else if (strncmp(string, "keep", 4) == 0)
+ else if (std::strncmp(string, "keep", 4) == 0)
{
string += 4;
if (parse_int(&string, &sel_nr))
remove_group(0, sel_nr-1, block, gn);
}
}
- else if (strncmp(string, "name", 4) == 0)
+ else if (std::strncmp(string, "name", 4) == 0)
{
string += 4;
if (parse_int(&string, &sel_nr))
}
}
}
- else if (strncmp(string, "case", 4) == 0)
+ else if (std::strncmp(string, "case", 4) == 0)
{
bCase = !bCase;
printf("Switched to case %s\n", bCase ? "sensitive" : "insensitive");
list_residues(atoms);
}
}
- else if (strncmp(string, "splitch", 7) == 0)
+ else if (std::strncmp(string, "splitch", 7) == 0)
{
string += 7;
if (check_have_atoms(atoms, ostring) &&
split_chain(atoms, x, sel_nr, block, gn);
}
}
- else if (strncmp(string, "splitres", 8) == 0)
+ else if (std::strncmp(string, "splitres", 8) == 0)
{
string += 8;
if (check_have_atoms(atoms, ostring) &&
split_group(atoms, sel_nr, block, gn, FALSE);
}
}
- else if (strncmp(string, "splitat", 7) == 0)
+ else if (std::strncmp(string, "splitat", 7) == 0)
{
string += 7;
if (check_have_atoms(atoms, ostring) &&
}
else if (string[0] != 'q')
{
- nr1 = -1;
nr2 = -1;
if (parse_entry(&string, natoms, atoms, block, gn, &nr, index, gname))
{
{
index1[i] = index[i];
}
- strcpy(gname1, gname);
+ std::strcpy(gname1, gname);
if (parse_entry(&string, natoms, atoms, block, gn, &nr2, index2, gname2))
{
if (bOr)
natoms = 0;
for (i = 0; i < block->nra; i++)
{
- natoms = max(natoms, block->a[i]);
+ natoms = std::max(natoms, block->a[i]);
}
natoms++;
*/
#include "gmxpre.h"
-#include <math.h>
-#include <string.h>
+#include <cmath>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
nmat[resi][j]++;
nmat[resj][i]++;
}
- mdmat[resi][resj] = min(r2, mdmat[resi][resj]);
+ mdmat[resi][resj] = std::min(r2, mdmat[resi][resj]);
}
}
mdmat[resi][resi] = 0;
for (resj = resi+1; (resj < nres); resj++)
{
- r = sqrt(mdmat[resi][resj]);
+ r = std::sqrt(mdmat[resi][resj]);
mdmat[resi][resj] = r;
mdmat[resj][resi] = r;
}
"The output can be processed with [gmx-xpm2ps] to make a PostScript (tm) plot."
};
static real truncate = 1.5;
- static gmx_bool bAtom = FALSE;
static int nlevels = 40;
t_pargs pa[] = {
{ "-t", FALSE, etREAL, {&truncate},
char *grpname;
int *rndx, *natm, prevres, newres;
- int i, j, nres, natoms, nframes, it, trxnat;
+ int i, j, nres, natoms, nframes, trxnat;
t_trxstatus *status;
- int nr0;
gmx_bool bCalcN, bFrames;
real t, ratio;
char title[256], label[234];
*/
#include "gmxpre.h"
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
#include "gromacs/topology/index.h"
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
real sqr_box, r2min, r2max, r2;
rvec shift[NSHIFT_MAX], d0, d;
- sqr_box = min(norm2(box[XX]), norm2(box[YY]));
+ sqr_box = std::min(norm2(box[XX]), norm2(box[YY]));
if (ePBC == epbcXYZ)
{
- sqr_box = min(sqr_box, norm2(box[ZZ]));
+ sqr_box = std::min(sqr_box, norm2(box[ZZ]));
nsz = 1;
}
else if (ePBC == epbcXY)
}
}
- *rmin = sqrt(r2min);
- *rmax = sqrt(r2max);
+ *rmin = std::sqrt(r2min);
+ *rmax = std::sqrt(r2max);
}
static void periodic_mindist_plot(const char *trxfn, const char *outfn,
rvec *x;
matrix box;
int natoms, ind_min[2] = {0, 0}, ind_mini = 0, ind_minj = 0;
- real r, rmin, rmax, rmint, tmint;
+ real rmin, rmax, rmint, tmint;
gmx_bool bFirst;
gmx_rmpbc_t gpbc = NULL;
ind_mini = ind_min[0];
ind_minj = ind_min[1];
}
- if (bSplit && !bFirst && fabs(t/output_env_get_time_factor(oenv)) < 1e-5)
+ if (bSplit && !bFirst && std::abs(t/output_env_get_time_factor(oenv)) < 1e-5)
{
fprintf(out, "%s\n", output_env_get_print_xvgr_codes(oenv) ? "&" : "");
}
*nmax += nmax_j;
}
}
- *rmin = sqrt(rmin2);
- *rmax = sqrt(rmax2);
+ *rmin = std::sqrt(rmin2);
+ *rmax = std::sqrt(rmax2);
}
void dist_plot(const char *fn, const char *afile, const char *dfile,
real t, dmin, dmax, **mindres = NULL, **maxdres = NULL;
int nmin, nmax;
t_trxstatus *status;
- int i = -1, j, k, natoms;
- int min1, min2, max1, max2, min1r, min2r, max1r, max2r;
+ int i = -1, j, k;
+ int min2, max2, min1r, min2r, max1r, max2r;
+ int min1 = 0;
+ int max1 = 0;
atom_id oindex[2];
rvec *x0;
matrix box;
- t_trxframe frout;
gmx_bool bFirst;
FILE *respertime = NULL;
- if ((natoms = read_first_x(oenv, &status, fn, &t, &x0, box)) == 0)
+ if (read_first_x(oenv, &status, fn, &t, &x0, box) == 0)
{
gmx_fatal(FARGS, "Could not read coordinates from statusfile\n");
}
}
- j = 0;
if (nres)
{
snew(mindres, ng-1);
bFirst = TRUE;
do
{
- if (bSplit && !bFirst && fabs(t/output_env_get_time_factor(oenv)) < 1e-5)
+ if (bSplit && !bFirst && std::abs(t/output_env_get_time_factor(oenv)) < 1e-5)
{
fprintf(dist, "%s\n", output_env_get_print_xvgr_codes(oenv) ? "&" : "");
if (num)
calc_dist(rcut, bPBC, ePBC, box, x0, residue[j+1]-residue[j], gnx[i],
&(index[0][residue[j]]), index[i], bGroup,
&dmin, &dmax, &nmin, &nmax, &min1r, &min2r, &max1r, &max2r);
- mindres[i-1][j] = min(mindres[i-1][j], dmin);
- maxdres[i-1][j] = max(maxdres[i-1][j], dmax);
+ mindres[i-1][j] = std::min(mindres[i-1][j], dmin);
+ maxdres[i-1][j] = std::max(maxdres[i-1][j], dmax);
}
}
}
"of the three box vectors.[PAR]",
"Also [gmx-distance] and [gmx-pairdist] calculate distances."
};
- const char *bugs[] = {
- "The [TT]-pi[tt] option is very slow."
- };
static gmx_bool bMat = FALSE, bPI = FALSE, bSplit = FALSE, bMax = FALSE, bPBC = TRUE;
static gmx_bool bGroup = FALSE;
t_topology *top = NULL;
int ePBC = -1;
char title[256];
- real t;
rvec *x;
matrix box;
gmx_bool bTop = FALSE;
- FILE *atm;
- int i, j, nres = 0;
+ int i, nres = 0;
const char *trxfnm, *tpsfnm, *ndxfnm, *distfnm, *numfnm, *atmfnm, *oxfnm, *resfnm;
char **grpname;
int *gnx;
if (resfnm)
{
- nres = find_residues(top ? &(top->atoms) : NULL,
- gnx[0], index[0], &residues);
+ GMX_RELEASE_ASSERT(top != NULL, "top pointer cannot be NULL when finding residues");
+ nres = find_residues(&(top->atoms), gnx[0], index[0], &residues);
+
if (debug)
{
dump_res(debug, nres, residues, index[0]);
*/
#include "gmxpre.h"
-#include <math.h>
+#include <cmath>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/trxio.h"
+#include "gromacs/gmxana/gmx_ana.h"
#include "gromacs/legacyheaders/macros.h"
#include "gromacs/legacyheaders/typedefs.h"
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
static int calc_ntype(int nft, int *ft, t_idef *idef)
{
for (j = 0; j < fac; j++)
{
- if (atom[ia[1+j]].m < 1.5 && fabs(atom[ia[1+j]].q) < hq)
+ if (atom[ia[1+j]].m < 1.5 && std::abs(atom[ia[1+j]].q) < hq)
{
bUse = FALSE;
}
return 0;
}
+ GMX_RELEASE_ASSERT(opt[0] != 0, "Options inconsistency; opt[0] is NULL");
ft = select_ftype(opt[0], &nft, &mult);
*/
#include "gmxpre.h"
-#include <math.h>
-#include <string.h>
+#include <cmath>
+#include <cstring>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
#include "gromacs/topology/index.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
#define FACTOR 1000.0 /* Convert nm^2/ps to 10e-5 cm^2/s */
{
if ((thistime(curr) >= (curr->nlast*curr->delta_t)) && (nr == 0))
{
- memcpy(curr->x0[curr->nlast], xc, curr->ncoords*sizeof(xc[0]));
+ std::memcpy(curr->x0[curr->nlast], xc, curr->ncoords*sizeof(xc[0]));
curr->n_offs[curr->nlast] = curr->nframes;
copy_rvec(com, curr->com[curr->nlast]);
curr->nlast++;
clear_dvec(sx);
tmass = 0;
- mass = 1;
prep_data(bMol, gnx, index, xcur, xprev, box);
for (i = 0; (i < gnx); i++)
fprintf(out, "%10d %10g\n", i, D);
if (pdbinfo)
{
- sqrtD = sqrt(D);
+ sqrtD = std::sqrt(D);
if (sqrtD > sqrtD_max)
{
sqrtD_max = sqrtD;
D2av /= curr->nmol;
VarD = D2av - sqr(Dav);
printf("<D> = %.4f Std. Dev. = %.4f Error = %.4f\n",
- Dav, sqrt(VarD), sqrt(VarD/curr->nmol));
+ Dav, std::sqrt(VarD), std::sqrt(VarD/curr->nmol));
if (fn_pdb && x)
{
{
scale *= 10;
}
+ GMX_RELEASE_ASSERT(pdbinfo != NULL, "Internal error - pdbinfo not set for PDB input");
for (i = 0; i < top->atoms.nr; i++)
{
pdbinfo[i].bfac *= scale;
/* for the first frame, the previous frame is a copy of the first frame */
if (bFirst)
{
- memcpy(xa[prev], xa[cur], curr->ncoords*sizeof(xa[prev][0]));
+ std::memcpy(xa[prev], xa[cur], curr->ncoords*sizeof(xa[prev][0]));
bFirst = FALSE;
}
if (beginfit == -1)
{
- i0 = (int)(0.1*(msd->nframes - 1) + 0.5);
+ i0 = static_cast<int>(0.1*(msd->nframes - 1) + 0.5);
beginfit = msd->time[i0];
}
else
if (endfit == -1)
{
- i1 = (int)(0.9*(msd->nframes - 1) + 0.5) + 1;
+ i1 = static_cast<int>(0.9*(msd->nframes - 1) + 0.5) + 1;
endfit = msd->time[i1-1];
}
else
{
lsq_y_ax_b(N/2, &(msd->time[i0]), &(msd->data[j][i0]), &a, &b, &r, &chi2);
lsq_y_ax_b(N/2, &(msd->time[i0+N/2]), &(msd->data[j][i0+N/2]), &a2, &b, &r, &chi2);
- SigmaD[j] = fabs(a-a2);
+ SigmaD[j] = std::abs(a-a2);
}
else
{
fprintf(stderr, "Calculating diffusion coefficients for molecules.\n");
}
+ GMX_RELEASE_ASSERT(normtype[0] != 0, "Options inconsistency; normtype[0]Â is NULL");
+ GMX_RELEASE_ASSERT(axtitle[0] != 0, "Options inconsistency; axtitle[0]Â is NULL");
+
if (normtype[0][0] != 'n')
{
type = normtype[0][0] - 'x' + X; /* See defines above */
*/
#include "gmxpre.h"
-#include <math.h>
-#include <string.h>
+#include <cmath>
+#include <cstring>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/mtxio.h"
#include "gromacs/math/vec.h"
#include "gromacs/topology/mtop_util.h"
#include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
static double cv_corr(double nu, double T)
{
double x = PLANCK*nu/(BOLTZ*T);
- double ex = exp(x);
+ double ex = std::exp(x);
if (nu <= 0)
{
static double u_corr(double nu, double T)
{
double x = PLANCK*nu/(BOLTZ*T);
- double ex = exp(x);
+ double ex = std::exp(x);
if (nu <= 0)
{
real * eigenvectors)
{
int i, j, k, l;
- real mass_fac, rdum;
+ real mass_fac;
int natoms;
natoms = top->atoms.nr;
/* Cannot check symmetry since we only store half matrix */
/* divide elements hess[i][j] by sqrt(mas[i])*sqrt(mas[j]) when required */
+ GMX_RELEASE_ASSERT(sparse_hessian != NULL, "NULL matrix pointer provided to nma_sparse_hessian");
+
if (bM)
{
for (iatom = 0; (iatom < natoms); iatom++)
"Width (sigma) of the gaussian peaks (1/cm) when generating a spectrum" }
};
FILE *out, *qc, *spec;
- int status, trjout;
t_topology top;
gmx_mtop_t mtop;
- int ePBC;
rvec *top_x;
matrix box;
real *eigenvalues;
real *eigenvectors;
- real rdum, mass_fac, qcvtot, qutot, qcv, qu;
- int natoms, ndim, nrow, ncol, count, nharm, nvsite;
- char *grpname;
- int i, j, k, l, d, gnx;
+ real qcvtot, qutot, qcv, qu;
+ int natoms, ndim, nrow, ncol, nharm, nvsite;
+ int i, j, k;
gmx_bool bSuck;
- atom_id *index;
t_tpxheader tpx;
int version, generation;
real value, omega, nu;
bSuck = FALSE;
for (i = begin-1; (i < 6); i++)
{
- if (fabs(eigenvalues[i]) > 1.0e-3)
+ if (std::abs(eigenvalues[i]) > 1.0e-3)
{
bSuck = TRUE;
}
{
value = 0;
}
- omega = sqrt(value*factor_gmx_to_omega2);
+ omega = std::sqrt(value*factor_gmx_to_omega2);
nu = 1e-12*omega/(2*M_PI);
value = omega*factor_omega_to_wavenumber;
fprintf (out, "%6d %15g\n", i, value);
if (NULL != spec)
{
- wfac = eigenvalues[i-begin]/(width*sqrt(2*M_PI));
+ wfac = eigenvalues[i-begin]/(width*std::sqrt(2*M_PI));
for (j = 0; (j < maxspec); j++)
{
- spectrum[j] += wfac*exp(-sqr(j-value)/(2*sqr(width)));
+ spectrum[j] += wfac*std::exp(-sqr(j-value)/(2*sqr(width)));
}
}
if (NULL != qc)
*/
#include "gmxpre.h"
-#include <math.h>
-#include <string.h>
+#include <cmath>
+#include <cstring>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
#define NPA asize(pa)
t_trxstatus *out;
- int status, trjout;
t_topology top;
int ePBC;
t_atoms *atoms;
int nvec, *eignr = NULL;
rvec **eigvec = NULL;
matrix box;
- real *eigval, totmass, *invsqrtm, t, disp;
- int natoms, neigval;
+ real *eigval, *invsqrtm, t, disp;
+ int natoms;
char *grpname, title[STRLEN];
const char *indexfile;
int i, j, d, s, v;
int nout, *iout, noutvec, *outvec;
atom_id *index;
- real rfac, invfr, rhalf, jr;
- int * eigvalnr;
+ real rfac, rhalf, jr;
output_env_t oenv;
gmx_rng_t rng;
- unsigned long jran;
+ int jran;
const unsigned long im = 0xffff;
const unsigned long ia = 1093;
const unsigned long ic = 18257;
if (seed == -1)
{
- seed = (int)gmx_rng_make_seed();
+ seed = static_cast<int>(gmx_rng_make_seed());
rng = gmx_rng_init(seed);
}
else
snew(xout1, natoms);
snew(xout2, atoms->nr);
out = open_trx(ftp2fn(efTRO, NFILE, fnm), "w");
- jran = (unsigned long)((real)im*gmx_rng_uniform_real(rng));
+ jran = static_cast<int>(im*gmx_rng_uniform_real(rng));
gmx_rng_destroy(rng);
for (s = 0; s < nstruct; s++)
{
/* (r-0.5) n times: var_n = n * var_1 = n/12
n=4: var_n = 1/3, so multiply with 3 */
- rfac = sqrt(3.0 * BOLTZ*temp/eigval[iout[j]]);
+ rfac = std::sqrt(3.0 * BOLTZ*temp/eigval[iout[j]]);
rhalf = 2.0*rfac;
- rfac = rfac/(real)im;
+ rfac = rfac/im;
jran = (jran*ia+ic) & im;
- jr = (real)jran;
+ jr = jran;
jran = (jran*ia+ic) & im;
- jr += (real)jran;
+ jr += jran;
jran = (jran*ia+ic) & im;
- jr += (real)jran;
+ jr += jran;
jran = (jran*ia+ic) & im;
- jr += (real)jran;
+ jr += jran;
disp = rfac * jr - rhalf;
for (i = 0; i < natoms; i++)
*/
#include "gmxpre.h"
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cctype>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/futil.h"
#include "gromacs/utility/smalloc.h"
-
+#include "gromacs/utility/stringutil.h"
int gmx_nmtraj(int argc, char *argv[])
{
t_atoms *atoms;
rvec *xtop, *xref, *xav, *xout;
int nvec, *eignr = NULL;
- int *eigvalnr;
rvec **eigvec = NULL;
matrix box;
int natoms;
- int i, j, k, kmode, d, s, v;
+ int i, j, k, kmode, d;
gmx_bool bDMR, bDMA, bFit;
- char * indexfile;
- char * grpname;
real * eigval;
- int neigval;
int * dummy;
real * invsqrtm;
char title[STRLEN];
real fraction;
int *out_eigidx;
- real *out_eigval;
rvec * this_eigvec;
- real omega, Ekin, sum, m, vel;
- gmx_bool found;
+ real omega, Ekin, m, vel;
int nmodes, nphases;
int *imodes;
real *amplitude;
real *phases;
- real dum;
const char *p;
char *pe;
output_env_t oenv;
/* Find vectors and phases */
/* first find number of args in string */
- nmodes = 0;
- p = eignrvec;
- while (*p != 0)
- {
- dum = strtod(p, &pe);
- p = pe;
- nmodes++;
- }
+ nmodes = gmx::countWords(eignrvec);
snew(imodes, nmodes);
p = eignrvec;
for (i = 0; i < nmodes; i++)
{
/* C indices start on 0 */
- imodes[i] = strtol(p, &pe, 10)-1;
+ imodes[i] = std::strtol(p, &pe, 10)-1;
p = pe;
}
/* Now read phases */
- nphases = 0;
- p = phasevec;
- while (*p != 0)
- {
- dum = strtod(p, &pe);
- p = pe;
- nphases++;
- }
+ nphases = gmx::countWords(phasevec);
+
if (nphases > nmodes)
{
gmx_fatal(FARGS, "More phases than eigenvector indices specified.\n");
/* Derive amplitude from temperature and eigenvalue if we can */
/* Convert eigenvalue to angular frequency, in units s^(-1) */
- omega = sqrt(eigval[kmode]*1.0E21/(AVOGADRO*AMU));
+ omega = std::sqrt(eigval[kmode]*1.0E21/(AVOGADRO*AMU));
/* Harmonic motion will be x=x0 + A*sin(omega*t)*eigenvec.
* The velocity is thus:
*
Ekin *= AMU*1E-18;
/* Set the amplitude so the energy is kT/2 */
- amplitude[i] = sqrt(0.5*BOLTZMANN*temp/Ekin);
+ amplitude[i] = std::sqrt(0.5*BOLTZMANN*temp/Ekin);
}
else
{
for (i = 0; i < nframes; i++)
{
- fraction = (real)i/(real)nframes;
+ fraction = static_cast<real>(i)/nframes;
for (j = 0; j < natoms; j++)
{
copy_rvec(xav[j], xout[j]);
{
for (d = 0; d < DIM; d++)
{
- xout[j][d] += amplitude[k]*sin(2*M_PI*(fraction+phases[k]/360.0))*this_eigvec[j][d];
+ xout[j][d] += amplitude[k]*std::sin(2*M_PI*(fraction+phases[k]/360.0))*this_eigvec[j][d];
}
}
}
- write_trx(out, natoms, dummy, atoms, i, (real)i/(real)nframes, box, xout, NULL, NULL);
+ write_trx(out, natoms, dummy, atoms, i, static_cast<real>(i)/nframes, box, xout, NULL, NULL);
}
fprintf(stderr, "\n");
*/
#include "gmxpre.h"
-#include <math.h>
-#include <string.h>
+#include <cmath>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
/****************************************************************************/
real sgslice[], real skslice[],
gmx_rmpbc_t gpbc)
{
- FILE *fpoutdist;
- char fnsgdist[32];
int ix, jx, nsgbin, *sgbin;
- int i1, i2, i, ibin, j, k, l, n, *nn[4];
- rvec dx, dx1, dx2, rj, rk, urk, urj;
+ int i, ibin, j, k, l, n, *nn[4];
+ rvec dx, rj, rk, urk, urj;
real cost, cost2, *sgmol, *skmol, rmean, rmean2, r2, box2, *r_nn[4];
t_pbc pbc;
- t_mat *dmat;
- t_dist *d;
- int m1, mm, sl_index;
- int **nnb, *sl_count;
+ int sl_index;
+ int *sl_count;
real onethird = 1.0/3.0;
/* dmat = init_mat(maxidx, FALSE); */
box2 = box[XX][XX] * box[XX][XX];
gmx_rmpbc(gpbc, natoms, box, x);
- nsgbin = 1 + 1/0.0005;
+ nsgbin = 2001; // Calculated as (1 + 1/0.0005)
snew(sgbin, nsgbin);
*sgmean = 0.0;
rmean = 0;
for (j = 0; (j < 4); j++)
{
- r_nn[j][i] = sqrt(r_nn[j][i]);
+ r_nn[j][i] = std::sqrt(r_nn[j][i]);
rmean += r_nn[j][i];
}
rmean /= 4;
sgmol[i] += cost2;
/* determine distribution */
- ibin = nsgbin * cost2;
+ ibin = static_cast<int>(nsgbin * cost2);
if (ibin < nsgbin)
{
sgbin[ibin]++;
FILE *fpsg = NULL, *fpsk = NULL;
t_topology top;
int ePBC;
- char title[STRLEN], fn[STRLEN], subtitle[STRLEN];
+ char title[STRLEN];
t_trxstatus *status;
int natoms;
real t;
int natoms, /* nr. atoms in trj */
nr_tails, /* nr tails, to check if index file is correct */
size = 0, /* nr. of atoms in group. same as nr_tails */
- i, j, m, k, l, teller = 0,
+ i, j, m, k, teller = 0,
slice, /* current slice number */
nr_frames = 0;
int *slCount; /* nr. of atoms in one slice */
- real dbangle = 0, /* angle between double bond and axis */
- sdbangle = 0; /* sum of these angles */
+ real sdbangle = 0; /* sum of these angles */
gmx_bool use_unitvector = FALSE; /* use a specified unit vector instead of axis to specify unit normal*/
rvec direction, com, dref, dvec;
int comsize, distsize;
/* PBC added for center-of-mass vector*/
/* Initiate the pbc structure */
- memset(&pbc, 0, sizeof(pbc));
+ std::memset(&pbc, 0, sizeof(pbc));
if ((natoms = read_first_x(oenv, &status, fn, &t, &x0, box)) == 0)
{
rvec_sub(x1[a[index[i+1]+j]], x1[a[index[i]+j]], dist);
length = norm(dist);
check_length(length, a[index[i]+j], a[index[i+1]+j]);
- svmul(1/length, dist, Sz);
+ svmul(1.0/length, dist, Sz);
/* this is actually the cosine of the angle between the double bond
and axis, because Sz is normalized and the two other components of
}
else
{
- sdbangle += acos(Sz[axis]);
+ sdbangle += std::acos(Sz[axis]);
}
}
else
length = norm(dist); /* determine distance between two atoms */
check_length(length, a[index[i-1]+j], a[index[i+1]+j]);
- svmul(1/length, dist, Sz);
+ svmul(1.0/length, dist, Sz);
/* Sz is now the molecular axis Sz, normalized and all that */
}
rvec_sub(x1[a[index[i+1]+j]], x1[a[index[i]+j]], tmp1);
rvec_sub(x1[a[index[i-1]+j]], x1[a[index[i]+j]], tmp2);
cprod(tmp1, tmp2, Sx);
- svmul(1/norm(Sx), Sx, Sx);
+ svmul(1.0/norm(Sx), Sx, Sx);
/* now we can get Sy from the outer product of Sx and Sz */
cprod(Sz, Sx, Sy);
- svmul(1/norm(Sy), Sy, Sy);
+ svmul(1.0/norm(Sy), Sy, Sy);
/* the square of cosine of the angle between dist and the axis.
Using the innerproduct, but two of the three elements are zero
for (m = 0; m < DIM; m++)
{
- frameorder[m] += 0.5 * (3 * cossum[m] - 1);
+ frameorder[m] += 0.5 * (3.0 * cossum[m] - 1.0);
}
if (bSliced)
z_ave -= box[axis][axis];
}
- slice = (int)(0.5 + (z_ave / (*slWidth))) - 1;
+ slice = static_cast<int>((0.5 + (z_ave / (*slWidth))) - 1);
slCount[slice]++; /* determine slice, increase count */
slFrameorder[slice] += 0.5 * (3 * cossum[axis] - 1);
/* store per-molecule order parameter
* To just track single-axis order: (*slOrder)[j][i] += 0.5 * (3 * iprod(cossum,direction) - 1);
* following is for Scd order: */
- (*slOrder)[j][i] += -1* (0.3333 * (3 * cossum[XX] - 1) + 0.3333 * 0.5 * (3 * cossum[YY] - 1));
+ (*slOrder)[j][i] += -1* (1.0/3.0 * (3 * cossum[XX] - 1) + 1.0/3.0 * 0.5 * (3.0 * cossum[YY] - 1));
}
if (distcalc)
{
pbc_dx(&pbc, x1[distidx[k]], x1[a[index[i]+j]], dvec);
/* at the moment, just remove dvec[axis] */
dvec[axis] = 0;
- tmpdist = min(tmpdist, norm2(dvec));
+ tmpdist = std::min(tmpdist, norm2(dvec));
}
//fprintf(stderr, "Min dist %f; trace %f\n", tmpdist, trace(box));
- (*distvals)[j][i] += sqrt(tmpdist);
+ (*distvals)[j][i] += std::sqrt(tmpdist);
}
}
} /* end loop j, over all atoms in group */
slOrd = xvgropen(bfile, buf, "Molecule", "S", oenv);
for (atom = 1; atom < ngrps - 1; atom++)
{
- fprintf(ord, "%12d %12g\n", atom, -1 * (0.6667 * order[atom][XX] +
- 0.333 * order[atom][YY]));
+ fprintf(ord, "%12d %12g\n", atom, -1.0 * (2.0/3.0 * order[atom][XX] +
+ 1.0/3.0 * order[atom][YY]));
}
for (slice = 0; slice < nslices; slice++)
{
fprintf(ord, "%12d %12g %12g %12g\n", atom, order[atom][XX],
order[atom][YY], order[atom][ZZ]);
- fprintf(slOrd, "%12d %12g\n", atom, -1 * (0.6667 * order[atom][XX] +
- 0.333 * order[atom][YY]));
+ fprintf(slOrd, "%12d %12g\n", atom, -1.0 * (2.0/3.0 * order[atom][XX] +
+ 1.0/3.0 * order[atom][YY]));
}
}
/*function to write order parameters as B factors in PDB file using
first frame of trajectory*/
t_trxstatus *status;
- int natoms;
t_trxframe fr, frout;
t_atoms useatoms;
int i, j, ctr, nout;
ngrps -= 2; /*we don't have an order parameter for the first or
last atom in each chain*/
nout = nslices*ngrps;
- natoms = read_first_frame(oenv, &status, ftp2fn(efTRX, nfile, fnm), &fr,
- TRX_NEED_X);
+ read_first_frame(oenv, &status, ftp2fn(efTRX, nfile, fnm), &fr, TRX_NEED_X);
+
close_trj(status);
frout = fr;
frout.natoms = nout;
copy_rvec(fr.x[a[index[i+1]+j]], frout.x[ctr]);
useatoms.atomname[ctr] = top->atoms.atomname[a[index[i+1]+j]];
useatoms.atom[ctr] = top->atoms.atom[a[index[i+1]+j]];
- useatoms.nres = max(useatoms.nres, useatoms.atom[ctr].resind+1);
+ useatoms.nres = std::max(useatoms.nres, useatoms.atom[ctr].resind+1);
useatoms.resinfo[useatoms.atom[ctr].resind] = top->atoms.resinfo[useatoms.atom[ctr].resind]; /*copy resinfo*/
}
}
trxfnm = ftp2fn(efTRX, NFILE, fnm);
/* Calculate axis */
- if (strcmp(normal_axis[0], "x") == 0)
+ GMX_RELEASE_ASSERT(normal_axis[0] != NULL, "Options inconsistency; normal_axis[0] is NULL");
+ if (std::strcmp(normal_axis[0], "x") == 0)
{
axis = XX;
}
- else if (strcmp(normal_axis[0], "y") == 0)
+ else if (std::strcmp(normal_axis[0], "y") == 0)
{
axis = YY;
}
- else if (strcmp(normal_axis[0], "z") == 0)
+ else if (std::strcmp(normal_axis[0], "z") == 0)
{
axis = ZZ;
}
*/
#include "gmxpre.h"
-#include <math.h>
-#include <string.h>
+#include <cmath>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/tpxio.h"
/* Calculate mean square internal distances (Auhl et al., JCP 119, 12718) */
static void calc_int_dist(double *intd, rvec *x, int i0, int i1)
{
- int ii, jj;
+ int ii;
const int ml = i1 - i0 + 1; /* Number of beads in molecule. */
int bd; /* Distance between beads */
double d;
nat_max = 0;
for (mol = 0; mol < nmol; mol++)
{
- nat_min = min(nat_min, molind[mol+1]-molind[mol]);
- nat_max = max(nat_max, molind[mol+1]-molind[mol]);
+ nat_min = std::min(nat_min, molind[mol+1]-molind[mol]);
+ nat_max = std::max(nat_max, molind[mol+1]-molind[mol]);
}
fprintf(stderr, "Group %s consists of %d molecules\n", grpname, nmol);
fprintf(stderr, "Group size per molecule, min: %d atoms, max %d atoms\n",
fprintf(out, "%10.3f %8.4f %8.4f %8.4f %8.4f %8.4f",
t*output_env_get_time_factor(oenv),
- sqrt(sum_eed2), sqrt(sum_gyro),
- sqrt(eig[ord[0]]), sqrt(eig[ord[1]]), sqrt(eig[ord[2]]));
+ std::sqrt(sum_eed2), sqrt(sum_gyro),
+ std::sqrt(eig[ord[0]]), std::sqrt(eig[ord[1]]), std::sqrt(eig[ord[2]]));
if (bPC)
{
for (d = 0; d < DIM; d++)
{
- fprintf(out, " %8.4f", sqrt(sum_eig[d]/nmol));
+ fprintf(out, " %8.4f", std::sqrt(sum_eig[d]/nmol));
}
}
fprintf(out, "\n");
for (j = 0; j < nat_min/2; j += 2)
{
sum_inp[j] /= ninp[j];
- if (i == -1 && sum_inp[j] <= exp(-1.0))
+ if (i == -1 && sum_inp[j] <= std::exp(-1.0))
{
i = j;
}
else
{
/* Do linear interpolation on a log scale */
- pers = i - 2
- + 2*(log(sum_inp[i-2]) + 1)/(log(sum_inp[i-2]) - log(sum_inp[i]));
+ pers = i - 2.0
+ + 2.0*(std::log(sum_inp[i-2]) + 1.0)/(std::log(sum_inp[i-2]) - std::log(sum_inp[i]));
}
fprintf(outp, "%10.3f %8.4f\n", t*output_env_get_time_factor(oenv), pers);
sum_pers_tot += pers;
sum_gyro_tot /= frame;
sum_pers_tot /= frame;
fprintf(stdout, "\nAverage end to end distance: %.3f (nm)\n",
- sqrt(sum_eed2_tot));
+ std::sqrt(sum_eed2_tot));
fprintf(stdout, "\nAverage radius of gyration: %.3f (nm)\n",
- sqrt(sum_gyro_tot));
+ std::sqrt(sum_gyro_tot));
if (opt2bSet("-p", NFILE, fnm))
{
fprintf(stdout, "\nAverage persistence length: %.2f bonds\n",
*/
#include "gmxpre.h"
-#include <ctype.h>
-#include <math.h>
-#include <string.h>
+#include <cctype>
+#include <cmath>
+#include <cstring>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/trxio.h"
double fudge_z, gmx_bool bSpherical, gmx_bool bCorrect,
const output_env_t oenv)
{
- rvec *x0; /* coordinates without pbc */
- matrix box; /* box (3x3) */
- int natoms; /* nr. atoms in trj */
+ rvec *x0; /* coordinates without pbc */
+ matrix box; /* box (3x3) */
+ int natoms; /* nr. atoms in trj */
t_trxstatus *status;
- int **slCount, /* nr. of atoms in one slice for a group */
- i, j, n, /* loop indices */
+ int i, n, /* loop indices */
teller = 0,
ax1 = 0, ax2 = 0,
nr_frames = 0, /* number of frames */
if (!*nslices)
{
- *nslices = (int)(box[axis][axis] * 10); /* default value */
+ *nslices = static_cast<int>(box[axis][axis] * 10.0); /* default value */
}
fprintf(stderr, "\nDividing the box in %d slices\n", *nslices);
{
rvec_add(x0[index[n][i]], xcm, x0[index[n][i]]);
/* only distance from origin counts, not sign */
- slice = norm(x0[index[n][i]])/(*slWidth);
+ slice = static_cast<int>(norm(x0[index[n][i]])/(*slWidth));
/* this is a nice check for spherical groups but not for
all water in a cubic box since a lot will fall outside
z -= box[axis][axis];
}
/* determine which slice atom is in */
- slice = (z / (*slWidth));
+ slice = static_cast<int>((z / (*slWidth)));
(*slCharge)[n][slice] += top->atoms.atom[index[n][i]].q;
}
}
qsum = 0;
for (i = 0; i < *nslices; i++)
{
- if (fabs((*slCharge)[n][i]) >= GMX_DOUBLE_MIN)
+ if (std::abs((*slCharge)[n][i]) >= GMX_DOUBLE_MIN)
{
nn++;
qsum += (*slCharge)[n][i];
qsum /= nn;
for (i = 0; i < *nslices; i++)
{
- if (fabs((*slCharge)[n][i]) >= GMX_DOUBLE_MIN)
+ if (std::abs((*slCharge)[n][i]) >= GMX_DOUBLE_MIN)
{
(*slCharge)[n][i] -= qsum;
}
qsum = 0;
for (i = 0; i < *nslices; i++)
{
- if (fabs((*slCharge)[n][i]) >= GMX_DOUBLE_MIN)
+ if (std::abs((*slCharge)[n][i]) >= GMX_DOUBLE_MIN)
{
nn++;
qsum += (*slField)[n][i];
qsum /= nn;
for (i = 0; i < *nslices; i++)
{
- if (fabs((*slCharge)[n][i]) >= GMX_DOUBLE_MIN)
+ if (std::abs((*slCharge)[n][i]) >= GMX_DOUBLE_MIN)
{
(*slField)[n][i] -= qsum;
}
*/
#include "gmxpre.h"
-#include <math.h>
-#include <string.h>
+#include <cmath>
+#include <cstring>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
int natoms;
char *grpname, title[256];
- int i, j, m, gnx, nam, mol;
+ int i, gnx;
atom_id *index;
- rvec a1, a2, a3, moi;
+ rvec moi;
FILE * axis1;
FILE * axis2;
FILE * axis3;
*/
#include "gmxpre.h"
-#include <math.h>
-#include <string.h>
+#include <cmath>
+#include <cstring>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/xvgr.h"
*/
#include "gmxpre.h"
-#include <math.h>
-#include <stdlib.h>
+#include <cmath>
+#include <cstdlib>
+
+#include <algorithm>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
{
vec[m] += sqr(x[index[i]][m]);
}
- vec[m] = sqrt(vec[m] / isize);
+ vec[m] = std::sqrt(vec[m] / isize);
/* calculate scaling constants */
- vec[m] = 1 / (sqrt(3) * vec[m]);
+ vec[m] = 1.0 / (std::sqrt(3.0) * vec[m]);
}
/* scale coordinates */
"\nWARNING: topology has %d atoms, whereas trajectory has %d\n",
top.atoms.nr, natoms_trx);
}
- natoms = min(top.atoms.nr, natoms_trx);
+ natoms = std::min(top.atoms.nr, natoms_trx);
if (bMat || bBond || bPrev)
{
snew(mat_x, NFRAME);
{
if (IS_CHEMBOND(k))
{
- iatom = top.idef.il[k].iatoms;
ncons += top.idef.il[k].nr/3;
}
}
{
if (bDeltaLog)
{
- delta_scalex = 8.0/log(2.0);
- delta_xsize = (int)(log(tel_mat/2)*delta_scalex+0.5)+1;
+ delta_scalex = 8.0/std::log(2.0);
+ delta_xsize = static_cast<int>(std::log(static_cast<real>(tel_mat/2))*delta_scalex+0.5)+1;
}
else
{
{
rvec_sub(mat_x[i][ind_bond1[m]], mat_x[i][ind_bond2[m]], vec1);
rvec_sub(mat_x2_j[ind_bond1[m]], mat_x2_j[ind_bond2[m]], vec2);
- ang += acos(cos_angle(vec1, vec2));
+ ang += std::acos(cos_angle(vec1, vec2));
}
bond_mat[i][j] = ang*180.0/(M_PI*ibond);
if (bond_mat[i][j] > bond_max)
{
if ((j+my >= 0) && (j+my < tel_mat))
{
- abs_my = abs(my);
+ abs_my = std::abs(my);
for (mx = -avl; mx <= avl; mx++)
{
if ((i+mx >= 0) && (i+mx < tel_mat))
{
- weight = (real)(avl+1-max(abs(mx), abs_my));
+ weight = avl+1.0-std::max(std::abs(mx), abs_my);
av_tot += weight*rmsd_mat[i+mx][j+my];
weight_tot += weight;
}
{
if (bDeltaLog)
{
- mx = (int)(log(mx)*delta_scalex+0.5);
+ mx = static_cast<int>(std::log(static_cast<real>(mx))*delta_scalex+0.5);
}
- my = (int)(rmsd_mat[i][j]*delta_scaley*del_lev+0.5);
+ my = static_cast<int>(rmsd_mat[i][j]*delta_scaley*del_lev+0.5);
delta_tot[mx] += 1.0;
if ((rmsd_mat[i][j] >= 0) && (rmsd_mat[i][j] <= delta_maxy))
{
fp = ftp2FILE(efDAT, NFILE, fnm, "wb");
for (i = 0; i < tel_mat; i++)
{
- if (fwrite(rmsd_mat[i], sizeof(**rmsd_mat), tel_mat2, fp) != tel_mat2)
+ if (static_cast<int>(fwrite(rmsd_mat[i], sizeof(**rmsd_mat), tel_mat2, fp)) != tel_mat2)
{
gmx_fatal(FARGS, "Error writing to output file");
}
for (i = 0; (i < teller); i++)
{
if (bSplit && i > 0 &&
- fabs(time[bPrev ? freq*i : i]/output_env_get_time_factor(oenv)) < 1e-5)
+ std::abs(time[bPrev ? freq*i : i]/output_env_get_time_factor(oenv)) < 1e-5)
{
fprintf(fp, "%s\n", output_env_get_print_xvgr_codes(oenv) ? "&" : "");
}
if (output_env_get_print_xvgr_codes(oenv))
{
fprintf(fp, "@ subtitle \"of %s after lsq fit to mirror of %s\"\n",
- gn_rms[0], gn_fit);
+ gn_rms[0], bFit ? gn_fit : "");
}
}
else
{
if (output_env_get_print_xvgr_codes(oenv))
{
- fprintf(fp, "@ subtitle \"after lsq fit to mirror %s\"\n", gn_fit);
+ fprintf(fp, "@ subtitle \"after lsq fit to mirror %s\"\n", bFit ? gn_fit : "");
}
xvgr_legend(fp, nrms, (const char**)gn_rms, oenv);
}
for (i = 0; (i < teller); i++)
{
- if (bSplit && i > 0 && fabs(time[i]) < 1e-5)
+ if (bSplit && i > 0 && std::abs(time[i]) < 1e-5)
{
fprintf(fp, "%s\n", output_env_get_print_xvgr_codes(oenv) ? "&" : "");
}
*/
#include "gmxpre.h"
-#include <math.h>
+#include <cmath>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
{
pbc_dx(&pbc, xi, x[index[j]], dx);
temp2 = norm2(dx);
- d[i][j] = sqrt(temp2);
+ d[i][j] = std::sqrt(temp2);
}
}
}
{
pbc_dx(&pbc, xi, x[index[j]], dx);
temp2 = norm2(dx);
- temp = sqrt(temp2);
+ temp = std::sqrt(temp2);
d[i][j] = temp;
dtot[i][j] += temp;
dtot2[i][j] += temp2;
{
for (j = i+1; (j < nind); j++)
{
- temp1_3 = pow(dtot1_3[i][j]/nframes, -1.0/3.0);
- temp1_6 = pow(dtot1_6[i][j]/nframes, -1.0/6.0);
+ temp1_3 = std::pow(dtot1_3[i][j]/nframes, static_cast<real>(-1.0/3.0));
+ temp1_6 = std::pow(dtot1_6[i][j]/nframes, static_cast<real>(-1.0/6.0));
if (temp1_3 > *max1_3)
{
*max1_3 = temp1_3;
for (j = 0; equiv[i][j].rnr != NOTSET && !bFound; j++)
{
bFound = ( equiv[i][j].rnr == rnr1 &&
- strcmp(equiv[i][j].rname, rname1) == 0 &&
- strcmp(equiv[i][j].aname, aname1) == 0 );
+ std::strcmp(equiv[i][j].rname, rname1) == 0 &&
+ std::strcmp(equiv[i][j].aname, aname1) == 0 );
}
if (bFound)
{
for (j = 0; equiv[i][j].rnr != NOTSET && !bFound; j++)
{
bFound = ( equiv[i][j].rnr == rnr2 &&
- strcmp(equiv[i][j].rname, rname2) == 0 &&
- strcmp(equiv[i][j].aname, aname2) == 0 );
+ std::strcmp(equiv[i][j].rname, rname2) == 0 &&
+ std::strcmp(equiv[i][j].aname, aname2) == 0 );
}
}
}
gmx_bool bSumH,
atom_id *noe_index, t_noe_gr *noe_gr)
{
- FILE *fp;
int i, j, anmil, anmjl, rnri, rnrj, gi, groupnr, neq;
char *anmi, *anmj, **nnm;
gmx_bool bMatch, bEquiv;
X are any number of letters or digits and ? goes from 1 to 3
This is supposed to cover all CH3 groups and the like */
anmi = *atoms->atomname[index[i]];
- anmil = strlen(anmi);
+ anmil = std::strlen(anmi);
bMatch = i <= isize-3 && anmi[anmil-1] == '1';
if (bMatch)
{
for (j = 1; j < 3; j++)
{
anmj = *atoms->atomname[index[i+j]];
- anmjl = strlen(anmj);
+ anmjl = std::strlen(anmj);
bMatch = bMatch && ( anmil == anmjl && anmj[anmjl-1] == Hnum[j] &&
- strncmp(anmi, anmj, anmil-1) == 0 );
+ std::strncmp(anmi, anmj, anmil-1) == 0 );
}
}
/* set index for this atom */
noe_gr[gi].aname = gmx_strdup(*atoms->atomname[index[i]]);
if (noe_index[i] == noe_index[i+1])
{
- noe_gr[gi].aname[strlen(noe_gr[gi].aname)-1] = '*';
+ noe_gr[gi].aname[std::strlen(noe_gr[gi].aname)-1] = '*';
}
}
noe_gr[gi].rnr = atoms->atom[index[i]].resind;
/* r goes from 0 to rmax
NSCALE*r/rmax goes from 0 to NSCALE
NSCALE - NSCALE*r/rmax goes from NSCALE to 0 */
- s3 = NSCALE - min(NSCALE, (int)(NSCALE*r3/rmax));
- s6 = NSCALE - min(NSCALE, (int)(NSCALE*r6/rmax));
+ s3 = NSCALE - std::min(NSCALE, static_cast<int>(NSCALE*r3/rmax));
+ s6 = NSCALE - std::min(NSCALE, static_cast<int>(NSCALE*r6/rmax));
for (i = 0; i < s3; i++)
{
{
gj = noe_index[j];
noe[gi][gj].nr++;
- noe[gi][gj].i_3 += pow(dtot1_3[i][j], -3);
- noe[gi][gj].i_6 += pow(dtot1_6[i][j], -6);
+ noe[gi][gj].i_3 += std::pow(dtot1_3[i][j], static_cast<real>(-3.0));
+ noe[gi][gj].i_6 += std::pow(dtot1_6[i][j], static_cast<real>(-6.0));
}
}
{
for (j = i+1; j < gnr; j++)
{
- noe[i][j].r_3 = pow(noe[i][j].i_3/noe[i][j].nr, -1.0/3.0);
- noe[i][j].r_6 = pow(noe[i][j].i_6/noe[i][j].nr, -1.0/6.0);
+ noe[i][j].r_3 = std::pow(noe[i][j].i_3/noe[i][j].nr, static_cast<real>(-1.0/3.0));
+ noe[i][j].r_6 = std::pow(noe[i][j].i_6/noe[i][j].nr, static_cast<real>(-1.0/6.0));
noe[j][i] = noe[i][j];
}
}
grj = noe_gr[j];
r3 = noe[i][j].r_3;
r6 = noe[i][j].r_6;
- min3 = min(r3, min3);
- min6 = min(r6, min6);
+ min3 = std::min(r3, min3);
+ min6 = std::min(r6, min6);
if (r3 < rmax || r6 < rmax)
{
if (grj.rnr == gri.rnr)
}
else
{
- strcpy(b3, "-");
+ std::strcpy(b3, "-");
}
if (r6 < rmax)
{
}
else
{
- strcpy(b6, "-");
+ std::strcpy(b6, "-");
}
fprintf(fp,
"%4d %4d %4s %4s%3d %4d %4d %4s %4s%3d %5s %5s %8d %2d %2s %s\n",
gri.ianr+1, gri.anr+1, gri.aname, gri.rname, gri.rnr+1,
grj.ianr+1, grj.anr+1, grj.aname, grj.rname, grj.rnr+1,
- b3, b6, (int)(noe[i][j].i_6+0.5), grj.rnr-gri.rnr, buf,
+ b3, b6, static_cast<int>(noe[i][j].i_6+0.5), grj.rnr-gri.rnr, buf,
noe2scale(r3, r6, rmax));
}
}
{
mean = dtot[i][j]/nframes;
mean2 = dtot2[i][j]/nframes;
- rms = sqrt(max(0, mean2-mean*mean));
+ rms = std::sqrt(std::max(static_cast<real>(0.0), mean2-mean*mean));
rmsc = rms/mean;
if (mean > *meanmax)
{
}
r2 /= (natom*(natom-1))/2;
- return sqrt(r2);
+ return std::sqrt(r2);
}
int gmx_rmsdist(int argc, char *argv[])
};
- int natom, i, j, teller, gi, gj;
+ int i, teller;
real t;
t_topology top;
}
/*do a first step*/
- natom = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
+ read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
teller = 0;
do
*/
#include "gmxpre.h"
-#include <math.h>
+#include <cmath>
+#include <cstring>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
char rresnm[8];
int i;
- strcpy(rresnm, *ri->name);
+ std::strcpy(rresnm, *ri->name);
rresnm[3] = '\0';
for (i = 0; (i < atoms->nr); i++)
{
if ((ri->nr == atoms->resinfo[atoms->atom[i].resind].nr) &&
(ri->ic == atoms->resinfo[atoms->atom[i].resind].ic) &&
- (strcmp(*atoms->resinfo[atoms->atom[i].resind].name, rresnm) == 0) &&
- (strstr(*atoms->atomname[i], atomnm) != NULL))
+ (std::strcmp(*atoms->resinfo[atoms->atom[i].resind].name, rresnm) == 0) &&
+ (std::strstr(*atoms->atomname[i], atomnm) != NULL))
{
break;
}
"This shows the directions in which the atoms fluctuate the most and",
"the least."
};
- static gmx_bool bRes = FALSE, bAniso = FALSE, bdevX = FALSE, bFit = TRUE;
+ static gmx_bool bRes = FALSE, bAniso = FALSE, bFit = TRUE;
t_pargs pargs[] = {
{ "-res", FALSE, etBOOL, {&bRes},
"Calculate averages for each residue" },
"Do a least squares superposition before computing RMSF. Without this you must make sure that the reference structure and the trajectory match." }
};
int natom;
- int step, nre, natoms, i, g, m, teller = 0;
- real t, lambda, *w_rls, *w_rms;
+ int i, m, teller = 0;
+ real t, *w_rls;
- t_inputrec ir;
t_topology top;
int ePBC;
t_atoms *pdbatoms, *refatoms;
- gmx_bool bCont;
matrix box, pdbbox;
rvec *x, *pdbx, *xref;
t_trxstatus *status;
- int npdbatoms, res0;
- char buf[256];
+ int npdbatoms;
const char *label;
char title[STRLEN];
{
aid = index[i];
pdbatoms->pdbinfo[aid].bAnisotropic = TRUE;
- pdbatoms->pdbinfo[aid].uij[U11] = 1e6*U[i][XX*DIM + XX];
- pdbatoms->pdbinfo[aid].uij[U22] = 1e6*U[i][YY*DIM + YY];
- pdbatoms->pdbinfo[aid].uij[U33] = 1e6*U[i][ZZ*DIM + ZZ];
- pdbatoms->pdbinfo[aid].uij[U12] = 1e6*U[i][XX*DIM + YY];
- pdbatoms->pdbinfo[aid].uij[U13] = 1e6*U[i][XX*DIM + ZZ];
- pdbatoms->pdbinfo[aid].uij[U23] = 1e6*U[i][YY*DIM + ZZ];
+ pdbatoms->pdbinfo[aid].uij[U11] = static_cast<int>(1e6*U[i][XX*DIM + XX]);
+ pdbatoms->pdbinfo[aid].uij[U22] = static_cast<int>(1e6*U[i][YY*DIM + YY]);
+ pdbatoms->pdbinfo[aid].uij[U33] = static_cast<int>(1e6*U[i][ZZ*DIM + ZZ]);
+ pdbatoms->pdbinfo[aid].uij[U12] = static_cast<int>(1e6*U[i][XX*DIM + YY]);
+ pdbatoms->pdbinfo[aid].uij[U13] = static_cast<int>(1e6*U[i][XX*DIM + ZZ]);
+ pdbatoms->pdbinfo[aid].uij[U23] = static_cast<int>(1e6*U[i][YY*DIM + ZZ]);
}
}
if (bRes)
top.atoms.atom[index[i]].resind != top.atoms.atom[index[i+1]].resind)
{
fprintf(fp, "%5d %8.4f\n",
- bRes ? top.atoms.resinfo[top.atoms.atom[index[i]].resind].nr : index[i]+1, sqrt(rmsf[i]));
+ bRes ? top.atoms.resinfo[top.atoms.atom[index[i]].resind].nr : index[i]+1, std::sqrt(rmsf[i]));
}
}
xvgrclose(fp);
top.atoms.atom[index[i]].resind != top.atoms.atom[index[i+1]].resind)
{
fprintf(fp, "%5d %8.4f\n",
- bRes ? top.atoms.resinfo[top.atoms.atom[index[i]].resind].nr : index[i]+1, sqrt(rmsf[i]));
+ bRes ? top.atoms.resinfo[top.atoms.atom[index[i]].resind].nr : index[i]+1, std::sqrt(rmsf[i]));
}
}
xvgrclose(fp);
*
* 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.
*/
#include "gmxpre.h"
-#include <math.h>
-#include <string.h>
+#include <cmath>
+#include <cstring>
#include "gromacs/commandline/pargs.h"
#include "gromacs/correlationfunctions/autocorr.h"
gpbc = gmx_rmpbc_init(&(top->idef), ePBC, natoms);
/* Start the loop over frames */
- t1 = t0 = t;
+ t0 = t;
teller = 0;
do
{
*/
#include "gmxpre.h"
-#include <math.h>
-#include <string.h>
+#include <cmath>
+#include <cstring>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
#include "gromacs/pbcutil/rmpbc.h"
#include "gromacs/topology/index.h"
#include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
static void get_refx(output_env_t oenv, const char *trxfn, int nfitdim, int skip,
}
}
msd /= tot_mass;
- srmsd[i] += sqrt(msd);
- srmsd[j] += sqrt(msd);
+ srmsd[i] += std::sqrt(msd);
+ srmsd[j] += std::sqrt(msd);
}
sfree(xi[i]);
}
get_index(&top.atoms, ftp2fn_null(efNDX, NFILE, fnm), 1, &gnx, &index, &grpname);
+ GMX_RELEASE_ASSERT(reffit[0] != NULL, "Options inconsistency; reffit[0] is NULL");
if (reffit[0][0] != 'n')
{
get_refx(oenv, ftp2fn(efTRX, NFILE, fnm), reffit[0][2] == 'z' ? 3 : 2, skip,
*/
#include "gmxpre.h"
-#include <math.h>
-#include <string.h>
+#include <cmath>
+#include <cstring>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/filenm.h"
{
qq += atoms->atom[j].q;
}
- if (fabs(qq) > 1.0e-5)
+ if (std::abs(qq) > 1.0e-5)
{
srenew(cg, ncg+1);
cg[ncg].q = qq;
}
}
}
- return sqrt(mindist2);
+ return std::sqrt(mindist2);
}
int gmx_saltbr(int argc, char *argv[])
int ePBC;
char *buf;
t_trxstatus *status;
- int i, j, k, m, nnn, teller, ncg, n1, n2, n3, natoms;
+ int i, j, k, m, nnn, teller, ncg;
real t, *time, qi, qj;
t_charge *cg;
real ***cgdist;
int **nWithin;
- double t0, dt;
- char label[234];
t_pbc pbc;
rvec *x;
matrix box;
snew(nWithin[i], ncg);
}
- natoms = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
+ read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
teller = 0;
time = NULL;
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/gmxomp.h"
#include "gromacs/utility/smalloc.h"
#endif
};
FILE *fp;
- const char *fnTPX, *fnNDX, *fnTRX, *fnDAT = NULL;
+ const char *fnTPX, *fnTRX, *fnDAT = NULL;
t_trxstatus *status;
t_topology *top = NULL;
- t_atom *atom = NULL;
gmx_rmpbc_t gpbc = NULL;
- gmx_bool bTPX;
gmx_bool bFFT = FALSE, bDEBYE = FALSE;
gmx_bool bMC = FALSE;
int ePBC = -1;
char **grpname = NULL;
atom_id *index = NULL;
int isize;
- int i, j;
+ int i;
char *hdr = NULL;
char *suffix = NULL;
t_filenm *fnmdup = NULL;
gmx_omp_set_num_threads(nthreads);
/* Now try to parse opts for modes */
+ GMX_RELEASE_ASSERT(emethod[0] != NULL, "Options inconsistency; emethod[0]Â is NULL");
switch (emethod[0][0])
{
case 'd':
snew(grpname, 1);
snew(index, 1);
- bTPX = read_tps_conf(fnTPX, title, top, &ePBC, &x, NULL, box, TRUE);
+ read_tps_conf(fnTPX, title, top, &ePBC, &x, NULL, box, TRUE);
printf("\nPlease select group for SANS spectra calculation:\n");
get_index(&(top->atoms), ftp2fn_null(efNDX, NFILE, fnm), 1, &isize, &index, grpname);
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,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.
#include "gmxpre.h"
-#include <math.h>
+#include <cmath>
#include "gromacs/commandline/pargs.h"
#include "gromacs/gmxana/gmx_ana.h"
*/
#include "gmxpre.h"
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/matio.h"
void print_minimum(FILE *fp, int num, const t_minimum *min)
{
fprintf(fp,
- "Minimum %d at index " "%"GMX_PRId64 " energy %10.3f\n",
+ "Minimum %d at index " "%" GMX_PRId64 " energy %10.3f\n",
num, min->index, min->ener);
}
real **PP, *W, *E, **WW, **EE, *S, **SS, *M, *bE;
rvec xxx;
char *buf;
- double *bfac, efac, bref, Pmax, Wmin, Wmax, Winf, Emin, Emax, Einf, Smin, Smax, Sinf, Mmin, Mmax;
+ double *bfac, efac, bref, Pmax, Wmin, Wmax, Winf, Emin, Emax, Einf, Smin, Smax, Sinf;
real *delta;
- int i, j, k, imin, len, index, d, *nbin, *bindex, bi;
+ int i, j, k, imin, len, index, *nbin, *bindex, bi;
int *nxyz, maxbox;
t_blocka *b;
gmx_bool bOutside;
min_eig[i] = max_eig[i] = eig[i][0];
for (j = 0; (j < n); j++)
{
- min_eig[i] = min(min_eig[i], eig[i][j]);
- max_eig[i] = max(max_eig[i], eig[i][j]);
+ min_eig[i] = std::min(min_eig[i], eig[i][j]);
+ max_eig[i] = std::max(max_eig[i], eig[i][j]);
delta[i] = (max_eig[i]-min_eig[i])/(2.0*ibox[i]);
}
/* Add some extra space, half a bin on each side, unless the
{
bE[j] = (bref - 1/(BOLTZ*enerT[1][j]))*enerT[0][j];
}
- Emin = min(Emin, bE[j]);
+ Emin = std::min(Emin, static_cast<double>(bE[j]));
}
}
else
bOutside = FALSE;
for (i = 0; (i < neig); i++)
{
- nxyz[i] = bfac[i]*(eig[i][j]-min_eig[i]);
+ nxyz[i] = static_cast<int>(bfac[i]*(eig[i][j]-min_eig[i]));
if (nxyz[i] < 0 || nxyz[i] >= ibox[i])
{
bOutside = TRUE;
/* Compute the exponential factor */
if (enerT)
{
- efac = exp(-bE[j]+Emin);
+ efac = std::exp(-bE[j]+Emin);
}
else
{
}
else if (idim[i] == -1)
{
- efac /= sin(DEG2RAD*eig[i][j]);
+ efac /= std::sin(DEG2RAD*eig[i][j]);
}
}
/* Update the probability */
{
if (P[i] != 0)
{
- Pmax = max(P[i], Pmax);
- W[i] = -BOLTZ*Tref*log(P[i]);
+ Pmax = std::max(P[i], Pmax);
+ W[i] = -BOLTZ*Tref*std::log(P[i]);
if (W[i] < Wmin)
{
Wmin = W[i];
imin = i;
}
- Emin = min(E[i], Emin);
- Emax = max(E[i], Emax);
- Wmax = max(W[i], Wmax);
+ Emin = std::min(static_cast<double>(E[i]), Emin);
+ Emax = std::max(static_cast<double>(E[i]), Emax);
+ Wmax = std::max(static_cast<double>(W[i]), Wmax);
}
}
if (pmax > 0)
snew(axis_x, ibox[0]+1);
snew(axis_y, ibox[1]+1);
snew(axis_z, ibox[2]+1);
- maxbox = max(ibox[0], max(ibox[1], ibox[2]));
+ maxbox = std::max(ibox[0], std::max(ibox[1], ibox[2]));
snew(PP, maxbox*maxbox);
snew(WW, maxbox*maxbox);
snew(EE, maxbox*maxbox);
snew(SS, maxbox*maxbox);
- for (i = 0; (i < min(neig, 3)); i++)
+ for (i = 0; (i < std::min(neig, 3)); i++)
{
switch (i)
{
WW[i][j] = W[index3(ibox, i, j, nxyz[ZZ])];
}
}
- snew(buf, strlen(xpm)+4);
+ snew(buf, std::strlen(xpm)+4);
sprintf(buf, "%s", xpm);
- sprintf(&buf[strlen(xpm)-4], "12.xpm");
+ sprintf(&buf[std::strlen(xpm)-4], "12.xpm");
fp = gmx_ffopen(buf, "w");
write_xpm(fp, flags, "Gibbs Energy Landscape", "W (kJ/mol)", "PC1", "PC2",
ibox[0], ibox[1], axis_x, axis_y, WW, 0, gmax, rlo, rhi, &nlevels);
WW[i][j] = W[index3(ibox, i, nxyz[YY], j)];
}
}
- sprintf(&buf[strlen(xpm)-4], "13.xpm");
+ sprintf(&buf[std::strlen(xpm)-4], "13.xpm");
fp = gmx_ffopen(buf, "w");
write_xpm(fp, flags, "SHAM Energy Landscape", "kJ/mol", "PC1", "PC3",
ibox[0], ibox[2], axis_x, axis_z, WW, 0, gmax, rlo, rhi, &nlevels);
WW[i][j] = W[index3(ibox, nxyz[XX], i, j)];
}
}
- sprintf(&buf[strlen(xpm)-4], "23.xpm");
+ sprintf(&buf[std::strlen(xpm)-4], "23.xpm");
fp = gmx_ffopen(buf, "w");
write_xpm(fp, flags, "SHAM Energy Landscape", "kJ/mol", "PC2", "PC3",
ibox[1], ibox[2], axis_y, axis_z, WW, 0, gmax, rlo, rhi, &nlevels);
T[nbin] = enerT[1][j];
nbin++;
}
- bmin = min(enerT[0][j], bmin);
- bmax = max(enerT[0][j], bmax);
+ bmin = std::min(enerT[0][j], bmin);
+ bmax = std::max(enerT[0][j], bmax);
}
bwidth = 1.0;
- blength = (bmax - bmin)/bwidth + 2;
+ blength = static_cast<int>((bmax - bmin)/bwidth + 2);
snew(histo, nbin);
for (i = 0; (i < nbin); i++)
{
}
for (j = 0; (j < n); j++)
{
- k = (enerT[0][j]-bmin)/bwidth;
+ k = static_cast<int>((enerT[0][j]-bmin)/bwidth);
histo[bindex[j]][k]++;
}
fp = xvgropen(fh, "Energy distribution", "E (kJ/mol)", "", oenv);
"is the natural quantity to use, as it will produce bins of the same",
"volume."
};
- static real tb = -1, te = -1, frac = 0.5, filtlen = 0;
- static gmx_bool bHaveT = TRUE, bDer = FALSE, bSubAv = TRUE, bAverCorr = FALSE, bXYdy = FALSE;
- static gmx_bool bEESEF = FALSE, bEENLC = FALSE, bEeFitAc = FALSE, bPower = FALSE;
- static gmx_bool bShamEner = TRUE, bSham = TRUE;
+ static real tb = -1, te = -1;
+ static gmx_bool bHaveT = TRUE, bDer = FALSE;
+ static gmx_bool bSham = TRUE;
static real Tref = 298.15, pmin = 0, ttol = 0, pmax = 0, gmax = 0, emin = 0, emax = 0;
static rvec nrdim = {1, 1, 1};
static rvec nrbox = {32, 32, 32};
static rvec xmin = {0, 0, 0}, xmax = {1, 1, 1};
- static int nsets_in = 1, nb_min = 4, resol = 10, nlevels = 25;
+ static int nsets_in = 1, nlevels = 25;
t_pargs pa[] = {
{ "-time", FALSE, etBOOL, {&bHaveT},
"Expect a time in the input" },
};
#define NPA asize(pa)
- FILE *out;
- int n, e_n, nlast, s, nset, e_nset, d_nset, i, j = 0, *idim, *ibox;
- real **val, **et_val, *t, *e_t, e_dt, d_dt, dt, tot, error;
+ int n, e_n, nset, e_nset = 0, i, *idim, *ibox;
+ real **val, **et_val, *t, *e_t, e_dt, dt;
real *rmin, *rmax;
- double *av, *sig, cum1, cum2, cum3, cum4, db;
const char *fn_ge, *fn_ene;
output_env_t oenv;
gmx_int64_t num_grid_points;
ehisto(opt2fn("-histo", NFILE, fnm), e_n, et_val, oenv);
}
- snew(idim, max(3, nset));
- snew(ibox, max(3, nset));
- snew(rmin, max(3, nset));
- snew(rmax, max(3, nset));
- for (i = 0; (i < min(3, nset)); i++)
+ snew(idim, std::max(3, nset));
+ snew(ibox, std::max(3, nset));
+ snew(rmin, std::max(3, nset));
+ snew(rmax, std::max(3, nset));
+ for (i = 0; (i < std::min(3, nset)); i++)
{
- idim[i] = nrdim[i];
- ibox[i] = nrbox[i];
+ idim[i] = static_cast<int>(nrdim[i]);
+ ibox[i] = static_cast<int>(nrbox[i]);
rmin[i] = xmin[i];
rmax[i] = xmax[i];
}
for (; (i < nset); i++)
{
- idim[i] = nrdim[2];
- ibox[i] = nrbox[2];
+ idim[i] = static_cast<int>(nrdim[2]);
+ ibox[i] = static_cast<int>(nrbox[2]);
rmin[i] = xmin[2];
rmax[i] = xmax[2];
}
*/
#include "gmxpre.h"
-#include <math.h>
-#include <stdio.h>
+#include <cmath>
+#include <cstdio>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/xvgr.h"
+#include "gromacs/gmxana/gmx_ana.h"
#include "gromacs/legacyheaders/macros.h"
#include "gromacs/legacyheaders/names.h"
#include "gromacs/legacyheaders/txtdump.h"
real pot(real x, real qq, real c6, real cn, int npow)
{
- return cn*pow(x, -npow)-c6*pow(x, -6)+qq*ONE_4PI_EPS0/x;
+ return cn*pow(x, -npow)-c6*std::pow(x, -6)+qq*ONE_4PI_EPS0/x;
}
real bhpot(real x, real A, real B, real C)
{
- return A*exp(-B*x) - C*pow(x, -6.0);
+ return A*std::exp(-B*x) - C*std::pow(x, -6);
}
real dpot(real x, real qq, real c6, real cn, int npow)
{
- return -(npow*cn*pow(x, -npow-1)-6*c6*pow(x, -7)+qq*ONE_4PI_EPS0/sqr(x));
+ return -(npow*cn*std::pow(x, -npow-1)-6*c6*std::pow(x, -7)+qq*ONE_4PI_EPS0/sqr(x));
}
int gmx_sigeps(int argc, char *argv[])
FILE *fp;
int i;
gmx_bool bBham;
- real qq, x, oldx, minimum, mval, dp[2], pp[2];
+ real qq, x, oldx, minimum, mval, dp[2];
int cur = 0;
#define next (1-cur)
if (bBham)
{
c6 = Cbh;
- sig = pow((6.0/npow)*pow(npow/Bbh, npow-6.0), 1.0/(npow-6.0));
- eps = c6/(4*pow(sig, 6.0));
- cn = 4*eps*pow(sig, npow);
+ sig = std::pow((6.0/npow)*std::pow(npow/Bbh, npow-6), 1.0/(npow-6));
+ eps = c6/(4*std::pow(sig, 6));
+ cn = 4*eps*std::pow(sig, npow);
}
else
{
if (opt2parg_bSet("-sig", asize(pa), pa) ||
opt2parg_bSet("-eps", asize(pa), pa))
{
- c6 = 4*eps*pow(sig, 6);
- cn = 4*eps*pow(sig, npow);
+ c6 = 4*eps*std::pow(sig, 6);
+ cn = 4*eps*std::pow(sig, npow);
}
else if (opt2parg_bSet("-c6", asize(pa), pa) ||
opt2parg_bSet("-cn", asize(pa), pa) ||
opt2parg_bSet("-pow", asize(pa), pa))
{
- sig = pow(cn/c6, 1.0/(npow-6.0));
- eps = 0.25*c6*pow(sig, -6.0);
+ sig = std::pow(cn/c6, static_cast<real>(1.0/(npow-6)));
+ eps = 0.25*c6*std::pow(sig, -6);
}
else
{
printf("c6 = %12.5e, c%d = %12.5e\n", c6, npow, cn);
printf("sigma = %12.5f, epsilon = %12.5f\n", sig, eps);
- minimum = pow(npow/6.0*pow(sig, npow-6.0), 1.0/(npow-6));
+ minimum = std::pow(npow/6.0*std::pow(sig, npow-6), 1.0/(npow-6));
printf("Van der Waals minimum at %g, V = %g\n\n",
minimum, pot(minimum, 0, c6, cn, npow));
printf("Fit of Lennard Jones (%d-6) to Buckingham:\n", npow);
Bbh = npow/minimum;
Cbh = c6;
- Abh = 4*eps*pow(sig/minimum, npow)*exp(npow);
+ Abh = 4*eps*std::pow(sig/minimum, static_cast<real>(npow))*std::exp(static_cast<real>(npow));
printf("A = %g, B = %g, C = %g\n", Abh, Bbh, Cbh);
}
qq = qi*qj;
{
sig = 0.25;
}
- minimum = -1;
- mval = 0;
oldx = 0;
for (i = 0; (i < 100); i++)
{
*/
#include "gmxpre.h"
+#include <cmath>
+
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
#include "gromacs/fileio/trxio.h"
rvec_add(xref, dx, xtest);
for (j = 0; (j < DIM); j++)
{
- if (fabs(xtest[j]-x[ai][j]) > tol)
+ if (std::abs(xtest[j]-x[ai][j]) > tol)
{
/* Here we have used the wrong image for contributing to the COM */
xref[j] += mass*(xtest[j]-x[ai][j]);
matrix box;
FILE *fp;
- int i, j, p, sa0, sa1, sa2, n, ntot, nf, m, *hist1, *hist2, *histn, nbin1, nbin2, nrbin;
+ int i, p, sa0, sa1, sa2, n, ntot, nf, m, *hist1, *hist2, *histn, nbin1, nbin2, nrbin;
real *histi1, *histi2, invbw, invrbw;
double sum1, sum2;
int *isize, nrefgrp, nrefat;
atom_id **index;
char **grpname;
- real inp, outp, two_pi, nav, normfac, rmin2, rmax2, rcut, rcut2, r2, r, mass, mtot;
+ real inp, outp, nav, normfac, rmin2, rmax2, rcut, rcut2, r2, r;
real c1, c2;
char str[STRLEN];
gmx_bool bTPS;
return 0;
}
- two_pi = 2/M_PI;
-
bTPS = (opt2bSet("-s", NFILE, fnm) || !opt2bSet("-n", NFILE, fnm) || bCom);
if (bTPS)
{
rmin2 = sqr(rmin);
rmax2 = sqr(rmax);
- rcut = 0.99*sqrt(max_cutoff2(guess_ePBC(box), box));
+ rcut = 0.99*std::sqrt(max_cutoff2(guess_ePBC(box), box));
if (rcut == 0)
{
rcut = 10*rmax;
rcut2 = sqr(rcut);
invbw = 1/binwidth;
- nbin1 = 1+(int)(2*invbw + 0.5);
- nbin2 = 1+(int)(invbw + 0.5);
+ nbin1 = 1+static_cast<int>(2*invbw + 0.5);
+ nbin2 = 1+static_cast<int>(invbw + 0.5);
invrbw = 1/rbinw;
snew(hist1, nbin1);
snew(hist2, nbin2);
- nrbin = 1+(int)(rcut/rbinw);
+ nrbin = 1+static_cast<int>(rcut/rbinw);
if (nrbin == 0)
{
nrbin = 1;
set_pbc(&pbc, ePBC, box);
n = 0;
inp = 0;
- outp = 0;
for (p = 0; (p < nrefgrp); p++)
{
if (bCom)
r2 = norm2(dx);
if (r2 < rcut2)
{
- r = sqrt(r2);
+ r = std::sqrt(r2);
if (!bVec23)
{
/* Determine the normal to the plain */
outp = iprod(dx, dxh2)/r;
}
{
- int ii = (int)(invrbw*r);
+ int ii = static_cast<int>(invrbw*r);
range_check(ii, 0, nrbin);
histi1[ii] += inp;
histi2[ii] += 3*sqr(outp) - 1;
}
if ((r2 >= rmin2) && (r2 < rmax2))
{
- int ii1 = (int)(invbw*(inp + 1));
- int ii2 = (int)(invbw*fabs(outp));
+ int ii1 = static_cast<int>(invbw*(inp + 1));
+ int ii2 = static_cast<int>(invbw*std::abs(outp));
range_check(ii1, 0, nbin1);
range_check(ii2, 0, nbin2);
hist1[nbin1-1] += hist1[nbin1];
hist2[nbin2-1] += hist2[nbin2];
- nav = (real)ntot/(nrefgrp*nf);
+ nav = static_cast<real>(ntot)/(nrefgrp*nf);
normfac = invbw/ntot;
fprintf(stderr, "Average nr of molecules between %g and %g nm: %.1f\n",
*/
#include "gmxpre.h"
-#include <math.h>
-#include <stdlib.h>
+#include <cmath>
+#include <cstdlib>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
};
static gmx_bool bPBC = FALSE;
- static gmx_bool bSHIFT = FALSE;
static int iIGNOREOUTER = -1; /*Positive values may help if the surface is spikey */
static gmx_bool bCUTDOWN = TRUE;
static real rBINWIDTH = 0.05; /* nm */
int ePBC;
char title[STRLEN];
t_trxframe fr;
- rvec *xtop, *shx[26];
+ rvec *xtop;
matrix box, box_pbc;
t_trxstatus *status;
int flags = TRX_READ_X;
int i, nidx, nidxp;
int v;
int j, k;
- long ***bin = (long ***)NULL;
- long nbin[3];
+ int ***bin = NULL;
+ int nbin[3];
FILE *flp;
- long x, y, z, minx, miny, minz, maxx, maxy, maxz;
- long numfr, numcu;
- long tot, max, min;
+ int x, y, z, minx, miny, minz, maxx, maxy, maxz;
+ int numfr, numcu;
+ int tot, maxval, minval;
double norm;
output_env_t oenv;
gmx_rmpbc_t gpbc = NULL;
}
for (i = ZZ; i >= XX; --i)
{
- MAXBIN[i] = (ceil((MAXBIN[i]-MINBIN[i])/rBINWIDTH)+(double)iNAB)*rBINWIDTH+MINBIN[i];
- MINBIN[i] -= (double)iNAB*rBINWIDTH;
- nbin[i] = (long)ceil((MAXBIN[i]-MINBIN[i])/rBINWIDTH);
+ MAXBIN[i] = (std::ceil((MAXBIN[i]-MINBIN[i])/rBINWIDTH)+iNAB)*rBINWIDTH+MINBIN[i];
+ MINBIN[i] -= iNAB*rBINWIDTH;
+ nbin[i] = static_cast<int>(std::ceil((MAXBIN[i]-MINBIN[i])/rBINWIDTH));
}
snew(bin, nbin[XX]);
for (i = 0; i < nbin[XX]; ++i)
printf("Memory was required for [%f,%f,%f]\n", fr.x[index[i]][XX], fr.x[index[i]][YY], fr.x[index[i]][ZZ]);
exit(1);
}
- x = (long)ceil((fr.x[index[i]][XX]-MINBIN[XX])/rBINWIDTH);
- y = (long)ceil((fr.x[index[i]][YY]-MINBIN[YY])/rBINWIDTH);
- z = (long)ceil((fr.x[index[i]][ZZ]-MINBIN[ZZ])/rBINWIDTH);
+ x = static_cast<int>(std::ceil((fr.x[index[i]][XX]-MINBIN[XX])/rBINWIDTH));
+ y = static_cast<int>(std::ceil((fr.x[index[i]][YY]-MINBIN[YY])/rBINWIDTH));
+ z = static_cast<int>(std::ceil((fr.x[index[i]][ZZ]-MINBIN[ZZ])/rBINWIDTH));
++bin[x][y][z];
if (x < minx)
{
fprintf(flp, "Spatial Distribution Function\n");
fprintf(flp, "test\n");
fprintf(flp, "%5d%12.6f%12.6f%12.6f\n", nidxp, (MINBIN[XX]+(minx+iIGNOREOUTER)*rBINWIDTH)*10./bohr, (MINBIN[YY]+(miny+iIGNOREOUTER)*rBINWIDTH)*10./bohr, (MINBIN[ZZ]+(minz+iIGNOREOUTER)*rBINWIDTH)*10./bohr);
- fprintf(flp, "%5ld%12.6f%12.6f%12.6f\n", maxx-minx+1-(2*iIGNOREOUTER), rBINWIDTH*10./bohr, 0., 0.);
- fprintf(flp, "%5ld%12.6f%12.6f%12.6f\n", maxy-miny+1-(2*iIGNOREOUTER), 0., rBINWIDTH*10./bohr, 0.);
- fprintf(flp, "%5ld%12.6f%12.6f%12.6f\n", maxz-minz+1-(2*iIGNOREOUTER), 0., 0., rBINWIDTH*10./bohr);
+ fprintf(flp, "%5d%12.6f%12.6f%12.6f\n", maxx-minx+1-(2*iIGNOREOUTER), rBINWIDTH*10./bohr, 0., 0.);
+ fprintf(flp, "%5d%12.6f%12.6f%12.6f\n", maxy-miny+1-(2*iIGNOREOUTER), 0., rBINWIDTH*10./bohr, 0.);
+ fprintf(flp, "%5d%12.6f%12.6f%12.6f\n", maxz-minz+1-(2*iIGNOREOUTER), 0., 0., rBINWIDTH*10./bohr);
for (i = 0; i < nidxp; i++)
{
v = 2;
{
v = 16;
}
- fprintf(flp, "%5d%12.6f%12.6f%12.6f%12.6f\n", v, 0., (double)fr.x[indexp[i]][XX]*10./bohr, (double)fr.x[indexp[i]][YY]*10./bohr, (double)fr.x[indexp[i]][ZZ]*10./bohr);
+ fprintf(flp, "%5d%12.6f%12.6f%12.6f%12.6f\n", v, 0., fr.x[indexp[i]][XX]*10.0/bohr, fr.x[indexp[i]][YY]*10.0/bohr, fr.x[indexp[i]][ZZ]*10.0/bohr);
}
tot = 0;
if (bin[k][j][i] != 0)
{
printf("A bin was not empty when it should have been empty. Programming error.\n");
- printf("bin[%d][%d][%d] was = %ld\n", k, j, i, bin[k][j][i]);
+ printf("bin[%d][%d][%d] was = %d\n", k, j, i, bin[k][j][i]);
exit(1);
}
}
}
}
- min = 999;
- max = 0;
+ minval = 999;
+ maxval = 0;
for (k = 0; k < nbin[XX]; k++)
{
if (k < minx+iIGNOREOUTER || k > maxx-iIGNOREOUTER)
continue;
}
tot += bin[k][j][i];
- if (bin[k][j][i] > max)
+ if (bin[k][j][i] > maxval)
{
- max = bin[k][j][i];
+ maxval = bin[k][j][i];
}
- if (bin[k][j][i] < min)
+ if (bin[k][j][i] < minval)
{
- min = bin[k][j][i];
+ minval = bin[k][j][i];
}
}
}
numcu = (maxx-minx+1-(2*iIGNOREOUTER))*(maxy-miny+1-(2*iIGNOREOUTER))*(maxz-minz+1-(2*iIGNOREOUTER));
if (bCALCDIV)
{
- norm = ((double)numcu*(double)numfr) / (double)tot;
+ norm = static_cast<double>(numcu*numfr)/tot;
}
else
{
{
continue;
}
- fprintf(flp, "%12.6f ", norm*(double)bin[k][j][i]/(double)numfr);
+ fprintf(flp, "%12.6f ", static_cast<double>(norm*bin[k][j][i])/numfr);
}
fprintf(flp, "\n");
}
}
gmx_ffclose(flp);
- /* printf("x=%d to %d\n",minx,maxx); */
- /* printf("y=%d to %d\n",miny,maxy); */
- /* printf("z=%d to %d\n",minz,maxz); */
-
if (bCALCDIV)
{
- printf("Counts per frame in all %ld cubes divided by %le\n", numcu, 1.0/norm);
- printf("Normalized data: average %le, min %le, max %le\n", 1.0, norm*(double)min/(double)numfr, norm*(double)max/(double)numfr);
+ printf("Counts per frame in all %d cubes divided by %le\n", numcu, 1.0/norm);
+ printf("Normalized data: average %le, min %le, max %le\n", 1.0, minval*norm/numfr, maxval*norm/numfr);
}
else
{
- printf("grid.cube contains counts per frame in all %ld cubes\n", numcu);
- printf("Raw data: average %le, min %le, max %le\n", 1.0/norm, (double)min/(double)numfr, (double)max/(double)numfr);
+ printf("grid.cube contains counts per frame in all %d cubes\n", numcu);
+ printf("Raw data: average %le, min %le, max %le\n", 1.0/norm, static_cast<double>(minval)/numfr, static_cast<double>(maxval)/numfr);
}
return 0;
*/
#include "gmxpre.h"
+#include <cmath>
+
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/tpxio.h"
#include "gromacs/fileio/trxio.h"
rvec_add(xref, dx, xtest);
for (j = 0; (j < DIM); j++)
{
- if (fabs(xtest[j]-x[ai][j]) > tol)
+ if (std::abs(xtest[j]-x[ai][j]) > tol)
{
/* Here we have used the wrong image for contributing to the COM */
xref[j] += mass*(xtest[j]-x[ai][j]);
t_topology *top;
t_inputrec *ir;
t_atom *atom;
- char title[STRLEN];
t_trxstatus *status;
int nrefat, natoms, nf, ntot;
real t;
- rvec *xtop, *x, xref, trial, dx = {0}, dip, dir;
+ rvec *x, xref, trial, dx = {0}, dip, dir;
matrix box;
FILE *fp;
};
output_env_t oenv;
- static gmx_bool bCom = FALSE, bPBC = FALSE;
+ static gmx_bool bCom = FALSE;
static int srefat = 1;
static real rmin = 0.0, rmax = 0.32, refdip = 0, bw = 0.01;
t_pargs pa[] = {
/* initialize reading trajectory: */
natoms = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
- rcut = 0.99*sqrt(max_cutoff2(ir->ePBC, box));
+ rcut = 0.99*std::sqrt(max_cutoff2(ir->ePBC, box));
if (rcut == 0)
{
rcut = 10*rmax;
}
rcut2 = sqr(rcut);
invbw = 1/bw;
- nbin = (int)(rcut*invbw)+2;
+ nbin = static_cast<int>(rcut*invbw)+2;
snew(hist, nbin);
rmin2 = sqr(rmin);
}
if (rdx2 < rcut2)
{
- hist[(int)(sqrt(rdx2)*invbw)+1]++;
+ hist[static_cast<int>(std::sqrt(rdx2)*invbw)+1]++;
}
if (rdx2 >= rmin2 && rdx2 < rmax2)
{
svmul(ENM2DEBYE, dip, dip);
dip2 = norm2(dip);
- sdip += sqrt(dip2);
+ sdip += std::sqrt(dip2);
sdip2 += dip2;
for (d = 0; d < DIM; d++)
{
close_trj(status);
fprintf(stderr, "Average number of molecules within %g nm is %.1f\n",
- rmax, (real)ntot/(real)nf);
+ rmax, static_cast<real>(ntot)/nf);
if (ntot > 0)
{
sdip /= ntot;
sinp /= ntot;
sdinp /= ntot;
fprintf(stderr, "Average dipole: %f (D), std.dev. %f\n",
- sdip, sqrt(sdip2-sqr(sdip)));
+ sdip, std::sqrt(sdip2-sqr(sdip)));
fprintf(stderr, "Average radial component of the dipole: %f (D)\n",
sinp);
fprintf(stderr, "Average radial component of the polarization: %f (D)\n",
*/
#include "gmxpre.h"
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
+#include <cmath>
+#include <cstdio>
+#include <cstring>
#include "gromacs/commandline/pargs.h"
#include "gromacs/correlationfunctions/autocorr.h"
#include "gromacs/topology/index.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
#define NK 24
}
ncorr = (nframes+1)/2;
- if (ncorr > (int)(5*wt/dt+0.5))
+ if (ncorr > static_cast<int>(5*wt/dt+0.5))
{
- ncorr = (int)(5*wt/dt+0.5)+1;
+ ncorr = static_cast<int>(5*wt/dt+0.5)+1;
}
snew(tcaf, nk);
for (k = 0; k < nk; k++)
snew(sig, ncorr);
for (i = 0; i < ncorr; i++)
{
- sig[i] = exp(0.5*i*dt/wt);
+ sig[i] = std::exp(0.5*i*dt/wt);
}
low_do_autocorr(fn_tca, oenv, "Transverse Current Autocorrelation Functions",
int ePBC;
t_trxframe fr;
matrix box;
- gmx_bool bTPS, bTop; /* ,bCubic; */
+ gmx_bool bTop;
int gnx;
atom_id *index, *atndx = NULL, at;
char *grpname;
int nframes, n_alloc, i, j, k, d;
rvec mv_mol, cm_mol, kfac[NK];
int nkc, nk, ntc;
- real **c1, **tc;
+ real **tc;
output_env_t oenv;
#define NHISTO 360
n_alloc = 0;
nframes = 0;
rho = 0;
- /* bCubic = TRUE; */
+
do
{
- /*
- bCubic = bCubic && !TRICLINIC(fr.box) &&
- fabs(fr.box[XX][XX]-fr.box[YY][YY]) < 0.001*fr.box[XX][XX] &&
- fabs(fr.box[XX][XX]-fr.box[ZZ][ZZ]) < 0.001*fr.box[XX][XX];
- */
if (nframes >= n_alloc)
{
j = 0;
for (k = 0; k < nk; k++)
{
- sx = sin(iprod(kfac[k], cm_mol));
- cx = cos(iprod(kfac[k], cm_mol));
+ sx = std::sin(iprod(kfac[k], cm_mol));
+ cx = std::cos(iprod(kfac[k], cm_mol));
tc[j][nframes] += sx*iprod(v1[k], mv_mol);
j++;
tc[j][nframes] += cx*iprod(v1[k], mv_mol);
*/
#include "gmxpre.h"
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
real max, len2, scale;
atom_id maxi;
int i, m, onedim;
- gmx_bool bOne;
if ((nfr_x == 0) || (nfr_v == 0))
{
}
else
{
- scale = 10.0/sqrt(max);
+ scale = 10.0/std::sqrt(max);
}
}
printf("Maximum %s is %g on atom %d %s, res. %s %d\n",
- title, sqrt(max), maxi+1, *(atoms->atomname[maxi]),
+ title, std::sqrt(max), maxi+1, *(atoms->atomname[maxi]),
*(atoms->resinfo[atoms->atom[maxi].resind].name),
atoms->resinfo[atoms->atom[maxi].resind].nr);
len2 += sqr(sum[index[i]][m]);
}
}
- atoms->pdbinfo[index[i]].bfac = sqrt(len2)*scale;
+ atoms->pdbinfo[index[i]].bfac = std::sqrt(len2)*scale;
}
}
else
for (i = 0; (i < gnx); i++)
{
vn = norm(v[index[i]]);
- vnmax = max(vn, vnmax);
+ vnmax = std::max(vn, vnmax);
}
vnmax *= 2;
- *nhisto = 1+(vnmax/binwidth);
+ *nhisto = static_cast<int>(1+(vnmax/binwidth));
snew(*histo, *nhisto);
}
for (i = 0; (i < gnx); i++)
{
vn = norm(v[index[i]]);
- in = vn/binwidth;
+ in = static_cast<int>(vn/binwidth);
if (in >= *nhisto)
{
nnn = in+100;
t_trxstatus *status;
t_trxstatus *status_out = NULL;
gmx_rmpbc_t gpbc = NULL;
- int i, j, n;
+ int i, j;
int nr_xfr, nr_vfr, nr_ffr;
char **grpname;
int *isize0, *isize;
t_block *mols;
gmx_bool bTop, bOX, bOXT, bOV, bOF, bOB, bOT, bEKT, bEKR, bCV, bCF;
gmx_bool bDim[4], bDum[4], bVD;
- char *sffmt, sffmt6[1024];
+ char sffmt[STRLEN], sffmt6[STRLEN];
const char *box_leg[6] = { "XX", "YY", "ZZ", "YX", "ZX", "ZY" };
output_env_t oenv;
if (bFP)
{
- sffmt = "\t" gmx_real_fullprecision_pfmt;
+ sprintf(sffmt, "\t%s", gmx_real_fullprecision_pfmt);
}
else
{
- sffmt = "\t%g";
+ sprintf(sffmt, "\t%%g");
}
sprintf(sffmt6, "%s%s%s%s%s%s", sffmt, sffmt, sffmt, sffmt, sffmt, sffmt);
*/
#include "gmxpre.h"
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
/* Check start time of all files */
int i, natoms = 0;
t_trxstatus *status;
- real t;
t_trxframe fr;
gmx_bool ok;
gmx_fatal(FARGS, "Error reading user input" );
}
- inputstring[strlen(inputstring)-1] = 0;
+ inputstring[std::strlen(inputstring)-1] = 0;
if (inputstring[0] == 'c' || inputstring[0] == 'C')
{
{ &bCat }, "Do not discard double time frames" }
};
#define npargs asize(pa)
- int ftpin, i, frame, frame_out, step = 0, trjout = 0;
+ int ftpin, i, frame, frame_out;
t_trxstatus *status, *trxout = NULL;
- rvec *x, *v;
real t_corr;
t_trxframe fr, frout;
- char **fnms, **fnms_out, *in_file, *out_file;
+ char **fnms, **fnms_out, *out_file;
int n_append;
gmx_bool bNewFile, bIndex, bWrite;
- int earliersteps, nfile_in, nfile_out, *cont_type, last_ok_step;
+ int nfile_in, nfile_out, *cont_type;
real *readtime, *timest, *settime;
real first_time = 0, lasttime = NOTSET, last_ok_t = -1, timestep;
real last_frame_time, searchtime;
- int isize, j;
+ int isize = 0, j;
atom_id *index = NULL, imax;
char *grpname;
real **val = NULL, *t = NULL, dt_remd;
int n, nset, ftpout = -1, prevEndStep = 0, filetype;
- gmx_bool bOK;
gmx_off_t fpos;
output_env_t oenv;
t_filenm fnm[] =
imax = index[0];
for (i = 1; i < isize; i++)
{
- imax = max(imax, index[i]);
+ imax = std::max(imax, index[i]);
}
}
if (bDeMux)
snew(fnms_out, nset);
for (i = 0; (i < nset); i++)
{
- snew(fnms_out[i], strlen(buf)+32);
+ snew(fnms_out[i], std::strlen(buf)+32);
sprintf(fnms_out[i], "%d_%s", i, buf);
}
sfree(buf);
n_append = -1;
for (i = 0; ((i < nfile_in) && (n_append == -1)); i++)
{
- if (strcmp(fnms[i], out_file) == 0)
+ if (std::strcmp(fnms[i], out_file) == 0)
{
n_append = i;
}
gmx_fatal(FARGS, "Can only append to the first file which is %s (not %s)",
fnms[0], out_file);
}
- earliersteps = 0;
/* Not checking input format, could be dangerous :-) */
/* Not checking output format, equally dangerous :-) */
{
trxout = open_trx(out_file, "w");
}
- memset(&frout, 0, sizeof(frout));
+ std::memset(&frout, 0, sizeof(frout));
}
else
{
gmx_fatal(FARGS, "Error seeking to append position.");
}
read_next_frame(oenv, status, &fr);
- if (fabs(searchtime - fr.time) > timest[0]*0.5)
+ if (std::abs(searchtime - fr.time) > timest[0]*0.5)
{
gmx_fatal(FARGS, "Error seeking: attempted to seek to %f but got %f.",
searchtime, fr.time);
while (read_next_frame(oenv, status, &fr));
close_trj(status);
-
- earliersteps += step;
}
if (trxout)
{
*/
#include "gmxpre.h"
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
gmx_bool *bMol, *bTmp;
rvec *m_com, *m_shift;
t_pbc pbc;
- real *com_dist2;
int *cluster;
int *added;
int ncluster, nadded;
calc_box_center(ecenter, box, box_center);
/* Initiate the pbc structure */
- memset(&pbc, 0, sizeof(pbc));
+ std::memset(&pbc, 0, sizeof(pbc));
set_pbc(&pbc, ePBC, box);
/* Convert atom index to molecular */
{
atom_id i, j;
int d;
- rvec com, new_com, shift, dx, box_center;
+ rvec com, new_com, shift, box_center;
real m;
double mtot;
t_pbc pbc;
int natoms, t_atom atom[],
int ePBC, matrix box, rvec x[])
{
- atom_id i, j, res_start, res_end, res_nat;
+ atom_id i, j, res_start, res_end;
int d, presnr;
real m;
double mtot;
{
/* calculate final COM */
res_end = i;
- res_nat = res_end - res_start;
svmul(1.0/mtot, com, com);
/* check if COM is outside box */
char nbuf[128];
int nd = 0, fnr;
- strcpy(out_file, base);
+ std::strcpy(out_file, base);
fnr = file_nr;
do
{
if (nd < ndigit)
{
- strncat(out_file, "00000000000", ndigit-nd);
+ std::strncat(out_file, "00000000000", ndigit-nd);
}
sprintf(nbuf, "%d.", file_nr);
- strcat(out_file, nbuf);
- strcat(out_file, ext);
+ std::strcat(out_file, nbuf);
+ std::strcat(out_file, ext);
}
void check_trr(const char *fn)
{
gmx_fatal(FARGS, "Error reading user input");
}
- if (strcmp(yesno, "YES") == 0)
+ if (std::strcmp(yesno, "YES") == 0)
{
fprintf(stderr, "Once again, I'm gonna DO this...\n");
gmx_trr_close(in);
};
#define NPA asize(pa)
- FILE *out = NULL;
- t_trxstatus *trxout = NULL;
- t_trxstatus *trxin;
- int ftp, ftpin = 0, file_nr;
- t_trxframe fr, frout;
- int flags;
- rvec *xmem = NULL, *vmem = NULL, *fmem = NULL;
- rvec *xp = NULL, x_shift, hbox, box_center, dx;
- real xtcpr, lambda, *w_rls = NULL;
- int m, i, d, frame, outframe, natoms, nout, ncent, nre, newstep = 0, model_nr;
+ FILE *out = NULL;
+ t_trxstatus *trxout = NULL;
+ t_trxstatus *trxin;
+ int ftp, ftpin = 0, file_nr;
+ t_trxframe fr, frout;
+ int flags;
+ rvec *xmem = NULL, *vmem = NULL, *fmem = NULL;
+ rvec *xp = NULL, x_shift, hbox;
+ real *w_rls = NULL;
+ int m, i, d, frame, outframe, natoms, nout, ncent, newstep = 0, model_nr;
#define SKIP 10
- t_topology top;
- gmx_mtop_t *mtop = NULL;
- gmx_conect gc = NULL;
- int ePBC = -1;
- t_atoms *atoms = NULL, useatoms;
- matrix top_box;
- atom_id *index, *cindex;
- char *grpnm;
- int *frindex, nrfri;
- char *frname;
- int ifit, irms, my_clust = -1;
- atom_id *ind_fit, *ind_rms;
- char *gn_fit, *gn_rms;
- t_cluster_ndx *clust = NULL;
- t_trxstatus **clust_status = NULL;
- int *clust_status_id = NULL;
- int ntrxopen = 0;
- int *nfwritten = NULL;
- int ndrop = 0, ncol, drop0 = 0, drop1 = 0, dropuse = 0;
- double **dropval;
- real tshift = 0, t0 = -1, dt = 0.001, prec;
- gmx_bool bFit, bFitXY, bPFit, bReset;
- int nfitdim;
- gmx_rmpbc_t gpbc = NULL;
- gmx_bool bRmPBC, bPBCWhole, bPBCcomRes, bPBCcomMol, bPBCcomAtom, bPBC, bNoJump, bCluster;
- gmx_bool bCopy, bDoIt, bIndex, bTDump, bSetTime, bTPS = FALSE, bDTset = FALSE;
- gmx_bool bExec, bTimeStep = FALSE, bDumpFrame = FALSE, bSetPrec, bNeedPrec;
- gmx_bool bHaveFirstFrame, bHaveNextFrame, bSetBox, bSetUR, bSplit = FALSE;
- gmx_bool bSubTraj = FALSE, bDropUnder = FALSE, bDropOver = FALSE, bTrans = FALSE;
- gmx_bool bWriteFrame, bSplitHere;
- const char *top_file, *in_file, *out_file = NULL;
- char out_file2[256], *charpt;
- char *outf_base = NULL;
- const char *outf_ext = NULL;
- char top_title[256], title[256], command[256], filemode[5];
- int xdr = 0;
- gmx_bool bWarnCompact = FALSE;
- const char *warn;
- output_env_t oenv;
-
- t_filenm fnm[] = {
+ t_topology top;
+ gmx_mtop_t *mtop = NULL;
+ gmx_conect gc = NULL;
+ int ePBC = -1;
+ t_atoms *atoms = NULL, useatoms;
+ matrix top_box;
+ atom_id *index, *cindex;
+ char *grpnm;
+ int *frindex, nrfri;
+ char *frname;
+ int ifit, my_clust = -1;
+ atom_id *ind_fit;
+ char *gn_fit;
+ t_cluster_ndx *clust = NULL;
+ t_trxstatus **clust_status = NULL;
+ int *clust_status_id = NULL;
+ int ntrxopen = 0;
+ int *nfwritten = NULL;
+ int ndrop = 0, ncol, drop0 = 0, drop1 = 0, dropuse = 0;
+ double **dropval;
+ real tshift = 0, t0 = -1, dt = 0.001, prec;
+ gmx_bool bFit, bPFit, bReset;
+ int nfitdim;
+ gmx_rmpbc_t gpbc = NULL;
+ gmx_bool bRmPBC, bPBCWhole, bPBCcomRes, bPBCcomMol, bPBCcomAtom, bPBC, bNoJump, bCluster;
+ gmx_bool bCopy, bDoIt, bIndex, bTDump, bSetTime, bTPS = FALSE, bDTset = FALSE;
+ gmx_bool bExec, bTimeStep = FALSE, bDumpFrame = FALSE, bSetPrec, bNeedPrec;
+ gmx_bool bHaveFirstFrame, bHaveNextFrame, bSetBox, bSetUR, bSplit = FALSE;
+ gmx_bool bSubTraj = FALSE, bDropUnder = FALSE, bDropOver = FALSE, bTrans = FALSE;
+ gmx_bool bWriteFrame, bSplitHere;
+ const char *top_file, *in_file, *out_file = NULL;
+ char out_file2[256], *charpt;
+ char *outf_base = NULL;
+ const char *outf_ext = NULL;
+ char top_title[256], title[256], filemode[5];
+ gmx_bool bWarnCompact = FALSE;
+ const char *warn;
+ output_env_t oenv;
+
+ t_filenm fnm[] = {
{ efTRX, "-f", NULL, ffREAD },
{ efTRO, "-o", NULL, ffWRITE },
{ efTPS, NULL, NULL, ffOPTRD },
/* parse enum options */
fit_enum = nenum(fit);
bFit = (fit_enum == efFit || fit_enum == efFitXY);
- bFitXY = fit_enum == efFitXY;
bReset = (fit_enum == efReset || fit_enum == efResetXY);
bPFit = fit_enum == efPFit;
pbc_enum = nenum(pbc_opt);
" only has effect in combination with -pbc %s, %s or %s.\n"
" Ingoring unitcell representation.\n\n",
unitcell_opt[0], pbc_opt[2], pbc_opt[3], pbc_opt[4]);
- bSetUR = FALSE;
}
}
if (bFit && bPBC)
}
if (bSeparate || bSplit)
{
- outf_ext = strrchr(out_file, '.');
+ outf_ext = std::strrchr(out_file, '.');
if (outf_ext == NULL)
{
gmx_fatal(FARGS, "Output file name '%s' does not contain a '.'", out_file);
* the header in such a file is top_title t= ...
* to prevent a double t=, remove it from top_title
*/
- if ((charpt = strstr(top_title, " t= ")))
+ if ((charpt = std::strstr(top_title, " t= ")))
{
charpt[0] = '\0';
}
{
useatoms.pdbinfo[i] = atoms->pdbinfo[index[i]];
}
- useatoms.nres = max(useatoms.nres, useatoms.atom[i].resind+1);
+ useatoms.nres = std::max(useatoms.nres, useatoms.atom[i].resind+1);
}
useatoms.nr = nout;
}
}
/* open output for writing */
- strcpy(filemode, "w");
+ std::strcpy(filemode, "w");
switch (ftp)
{
case efTNG:
drop0 = drop1;
drop1++;
}
- if (fabs(dropval[0][drop0] - fr.time)
- < fabs(dropval[0][drop1] - fr.time))
+ if (std::abs(dropval[0][drop0] - fr.time)
+ < std::abs(dropval[0][drop1] - fr.time))
{
dropuse = drop0;
}
else
{
/* round() is not C89 compatible, so we do this: */
- bDoIt = bRmod(floor(frout_time+0.5), floor(tzero+0.5),
- floor(delta_t+0.5));
+ bDoIt = bRmod(std::floor(frout_time+0.5), std::floor(tzero+0.5),
+ std::floor(delta_t+0.5));
}
}
else
{
/* round() is not C89 compatible, so we do this: */
- bSplitHere = bSplit && bRmod(floor(frout.time+0.5),
- floor(tzero+0.5),
- floor(split_t+0.5));
+ bSplitHere = bSplit && bRmod(std::floor(frout.time+0.5),
+ std::floor(tzero+0.5),
+ std::floor(split_t+0.5));
}
if (bSeparate || bSplitHere)
{
*/
#include "gmxpre.h"
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
xsol[i][d] += mass*x[sa][d];
}
}
- svmul(1/totmass, xsol[i], xsol[i]);
+ svmul(1.0/totmass, xsol[i], xsol[i]);
}
}
else
sr = ind_ref[j];
for (i = 0; (i < nwat); i++)
{
- sa = ind_sol[na*i];
pbc_dx(&pbc, x[sr], xsol[i], dx);
n2 = norm2(dx);
if (n2 < order[i].d2)
{
for (j = 0; (j < na); j++)
{
- top.atoms.pdbinfo[order[i].i+j].bfac = sqrt(order[i].d2);
+ top.atoms.pdbinfo[order[i].i+j].bfac = std::sqrt(order[i].d2);
}
}
}
#include "config.h"
-#include <stdlib.h>
-#include <time.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+
+#include <algorithm>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
+#include "gmx_ana.h"
+
/* Enum for situations that can occur during log file parsing, the
* corresponding string entries can be found in do_the_tests() in
* const char* ParseLog[] */
/* Check if string starts with substring */
static gmx_bool str_starts(const char *string, const char *substring)
{
- return ( strncmp(string, substring, strlen(substring)) == 0);
+ return ( std::strncmp(string, substring, std::strlen(substring)) == 0);
}
ltrim(line);
/* Check for TERM and INT signals from user: */
- if (strstr(line, errSIG) != NULL)
+ if (std::strstr(line, errSIG) != NULL)
{
fclose(fp);
cleandata(perfdata, test_nr);
/* Check whether cycle resetting worked */
if (presteps > 0 && !bFoundResetStr)
{
- if (strstr(line, matchstrcr) != NULL)
+ if (std::strstr(line, matchstrcr) != NULL)
{
- sprintf(dumstring, "step %s", "%"GMX_SCNd64);
+ sprintf(dumstring, "step %s", "%" GMX_SCNd64);
sscanf(line, dumstring, &resetsteps);
bFoundResetStr = TRUE;
if (resetsteps == presteps+cpt_steps)
}
else
{
- sprintf(dumstring, "%"GMX_PRId64, resetsteps);
- sprintf(dumstring2, "%"GMX_PRId64, presteps+cpt_steps);
+ sprintf(dumstring, "%" GMX_PRId64, resetsteps);
+ sprintf(dumstring2, "%" GMX_PRId64, presteps+cpt_steps);
fprintf(stderr, "WARNING: Time step counters were reset at step %s,\n"
" though they were supposed to be reset at step %s!\n",
dumstring, dumstring2);
/* Look for PME mesh/force balance (not necessarily present, though) */
else if (str_starts(line, matchstrbal))
{
- sscanf(&line[strlen(matchstrbal)], "%f", &(perfdata->PME_f_load[test_nr]));
+ sscanf(&line[std::strlen(matchstrbal)], "%f", &(perfdata->PME_f_load[test_nr]));
}
/* Look for matchstring */
else if (str_starts(line, matchstring))
s = 0.0;
for (j = 0; j < nrepeats; j++)
{
- s += pow( pd->Gcycles[j] - pd->Gcycles_Av, 2 );
+ s += std::pow( pd->Gcycles[j] - pd->Gcycles_Av, 2 );
}
s /= (nrepeats - 1);
- s = sqrt(s);
+ s = std::sqrt(s);
fprintf(fp, "%4d %3d %4d%s %12.3f %12.3f %12.3f %s",
line, k, pd->nPMEnodes, strbuf, pd->Gcycles_Av, s,
static void get_program_paths(gmx_bool bThreads, char *cmd_mpirun[], char *cmd_mdrun[])
{
char *cp;
- FILE *fp;
const char def_mpirun[] = "mpirun";
const char def_mdrun[] = "mdrun";
fprintf(stdout, "Making sure that mdrun can be executed. ");
if (bThreads)
{
- snew(command, strlen(cmd_mdrun) + strlen(cmd_np) + strlen(filename) + 50);
+ snew(command, std::strlen(cmd_mdrun) + std::strlen(cmd_np) + std::strlen(filename) + 50);
sprintf(command, "%s%s-version -maxh 0.001 1> %s 2>&1", cmd_mdrun, cmd_np, filename);
}
else
{
- snew(command, strlen(cmd_mpirun) + strlen(cmd_np) + strlen(cmd_mdrun) + strlen(filename) + 50);
+ snew(command, std::strlen(cmd_mpirun) + std::strlen(cmd_np) + std::strlen(cmd_mdrun) + std::strlen(filename) + 50);
sprintf(command, "%s%s%s -version -maxh 0.001 1> %s 2>&1", cmd_mpirun, cmd_np, cmd_mdrun, filename);
}
fprintf(stdout, "Trying '%s' ... ", command);
/* Handles the no-GPU case by emitting an empty string. */
static char *make_gpu_id_command_line(int numRanks, int numPmeRanks, const t_eligible_gpu_ids *gpu_ids)
{
- char *command_line, *flag = "-gpu_id ", *ptr;
- int flag_length;
+ char *command_line, *ptr;
+ const char *flag = "-gpu_id ";
+ int flag_length;
/* Reserve enough room for the option name, enough single-digit
GPU ids (since that is currently all that is possible to use
with mdrun), and a terminating NULL. */
- flag_length = strlen(flag);
+ flag_length = std::strlen(flag);
snew(command_line, flag_length + numRanks + 1);
ptr = command_line;
int gpu_id, rank;
/* Write the option flag */
- strcpy(ptr, flag);
+ std::strcpy(ptr, flag);
ptr += flag_length;
numPpRanks = numRanks - numPmeRanks;
/* Make enough space for the system call command,
* (200 extra chars for -npme ... etc. options should suffice): */
- snew(command, strlen(cmd_mpirun)+strlen(cmd_mdrun)+strlen(cmd_np)+strlen(args_for_mdrun)+strlen(simulation_tpr)+200);
+ snew(command, std::strlen(cmd_mpirun)+std::strlen(cmd_mdrun)+std::strlen(cmd_np)+std::strlen(args_for_mdrun)+std::strlen(simulation_tpr)+200);
cmd_gpu_ids = make_gpu_id_command_line(nnodes, nPMEnodes, gpu_ids);
ir->init_step = init_step;
/* Write the tpr file which will be launched */
- sprintf(buf, "Writing optimized simulation file %s with nsteps=%s.\n", fn_sim_tpr, "%"GMX_PRId64);
+ sprintf(buf, "Writing optimized simulation file %s with nsteps=%s.\n", fn_sim_tpr, "%" GMX_PRId64);
fprintf(stdout, buf, ir->nsteps);
fflush(stdout);
write_tpx_state(fn_sim_tpr, ir, &state, &mtop);
sprintf(buf, "Making benchmark tpr file%s with %s time step%s",
- *ntprs > 1 ? "s" : "", "%"GMX_PRId64, benchsteps > 1 ? "s" : "");
+ *ntprs > 1 ? "s" : "", "%" GMX_PRId64, benchsteps > 1 ? "s" : "");
fprintf(stdout, buf, benchsteps);
if (statesteps > 0)
{
- sprintf(buf, " (adding %s steps from checkpoint file)", "%"GMX_PRId64);
+ sprintf(buf, " (adding %s steps from checkpoint file)", "%" GMX_PRId64);
fprintf(stdout, buf, statesteps);
benchsteps += statesteps;
}
{
box_size[d] += state.box[d][i]*state.box[d][i];
}
- box_size[d] = sqrt(box_size[d]);
+ box_size[d] = std::sqrt(box_size[d]);
}
if (ir->fourier_spacing > 0)
else
{
/* Use the maximum observed spacing */
- fourierspacing = max(max(info->fsx[0], info->fsy[0]), info->fsz[0]);
+ fourierspacing = std::max(std::max(info->fsx[0], info->fsy[0]), info->fsz[0]);
}
fprintf(stdout, "Calculating PME grid points on the basis of a fourierspacing of %f nm\n", fourierspacing);
else
{
/* For vdw cutoff, rvdw >= rlist */
- ir->rvdw = max(info->rvdw[0], ir->rlist);
+ ir->rvdw = std::max(info->rvdw[0], ir->rlist);
}
}
info->fsz[j] = fac*fourierspacing;
/* Write the benchmark tpr file */
- strncpy(fn_bench_tprs[j], fn_sim_tpr, strlen(fn_sim_tpr)-strlen(".tpr"));
+ std::strncpy(fn_bench_tprs[j], fn_sim_tpr, std::strlen(fn_sim_tpr)-std::strlen(".tpr"));
sprintf(buf, "_bench%.2d.tpr", j);
- strcat(fn_bench_tprs[j], buf);
+ std::strcat(fn_bench_tprs[j], buf);
fprintf(stdout, "Writing benchmark tpr %s with nsteps=", fn_bench_tprs[j]);
- fprintf(stdout, "%"GMX_PRId64, ir->nsteps);
+ fprintf(stdout, "%" GMX_PRId64, ir->nsteps);
if (j > 0)
{
fprintf(stdout, ", scaling factor %f\n", fac);
for (i = 0; i < nfile; i++)
{
opt = (char *)fnm[i].opt;
- if (strcmp(opt, "-p") == 0)
+ if (std::strcmp(opt, "-p") == 0)
{
/* do nothing; keep this file */
;
}
- else if (strcmp(opt, "-bg") == 0)
+ else if (std::strcmp(opt, "-bg") == 0)
{
/* Give the log file a nice name so one can later see which parameters were used */
numstring[0] = '\0';
rename(opt2fn("-bg", nfile, fnm), newfilename);
}
}
- else if (strcmp(opt, "-err") == 0)
+ else if (std::strcmp(opt, "-err") == 0)
{
/* This file contains the output of stderr. We want to keep it in
* cases where there have been problems. */
}
}
/* Delete the files which are created for each benchmark run: (options -b*) */
- else if ( (0 == strncmp(opt, "-b", 2)) && (opt2bSet(opt, nfile, fnm) || !is_optional(&fnm[i])) )
+ else if ( (0 == std::strncmp(opt, "-b", 2)) && (opt2bSet(opt, nfile, fnm) || !is_optional(&fnm[i])) )
{
remove_if_exists(opt2fn(opt, nfile, fnm));
}
/* Do we need to check all possible values for -npme or is a reduced list enough? */
- if (0 == strcmp(npmevalues_opt, "all") )
+ if (!std::strcmp(npmevalues_opt, "all") )
{
eNPME = eNpmeAll;
}
- else if (0 == strcmp(npmevalues_opt, "subset") )
+ else if (!std::strcmp(npmevalues_opt, "subset") )
{
eNPME = eNpmeSubset;
}
case eNpmeSubset:
/* For 2d PME we want a common largest factor of at least the cube
* root of the number of PP nodes */
- min_factor = (int) pow(npp, 1.0/3.0);
+ min_factor = static_cast<int>(std::pow(npp, 1.0/3.0));
break;
default:
gmx_fatal(FARGS, "Unknown option for eNPME in make_npme_list");
static void make_sure_it_runs(char *mdrun_cmd_line, int length, FILE *fp,
const t_filenm *fnm, int nfile)
{
- const char *fn = NULL;
char *command, *msg;
int ret;
-
snew(command, length + 15);
snew(msg, length + 500);
char buf[STRLEN];
gmx_bool bResetProblem = FALSE;
gmx_bool bFirst = TRUE;
- gmx_bool bUsingGpus = 0 < gpu_ids->n;
/* This string array corresponds to the eParselog enum type at the start
* of this file */
/* Allocate space for the mdrun command line. 100 extra characters should
be more than enough for the -npme etcetera arguments */
- cmdline_length = strlen(cmd_mpirun)
- + strlen(cmd_np)
- + strlen(cmd_mdrun)
- + strlen(cmd_args_bench)
- + strlen(tpr_names[0]) + 100;
+ cmdline_length = std::strlen(cmd_mpirun)
+ + std::strlen(cmd_np)
+ + std::strlen(cmd_mdrun)
+ + std::strlen(cmd_args_bench)
+ + std::strlen(tpr_names[0]) + 100;
snew(command, cmdline_length);
snew(cmd_stub, cmdline_length);
}
/* Make sure that the checkpoint file is not overwritten during benchmarking */
- if ( (0 == strcmp(opt2fn("-cpi", nfile, fnm), opt2fn("-bcpo", nfile, fnm)) ) && (sim_part > 1) )
+ if ( (0 == std::strcmp(opt2fn("-cpi", nfile, fnm), opt2fn("-bcpo", nfile, fnm)) ) && (sim_part > 1) )
{
gmx_fatal(FARGS, "Checkpoint input (-cpi) and benchmark checkpoint output (-bcpo) files must not be identical.\n"
"The checkpoint input file must not be overwritten during the benchmarks.\n");
/* If one of rmin, rmax is set, we need 2 tpr files at minimum */
if (!gmx_within_tol(*rmax, rcoulomb, GMX_REAL_EPS) || !gmx_within_tol(*rmin, rcoulomb, GMX_REAL_EPS) )
{
- *ntprs = max(*ntprs, 2);
+ *ntprs = std::max(*ntprs, 2);
}
/* If both rmin, rmax are set, we need 3 tpr files at minimum */
if (!gmx_within_tol(*rmax, rcoulomb, GMX_REAL_EPS) && !gmx_within_tol(*rmin, rcoulomb, GMX_REAL_EPS) )
{
- *ntprs = max(*ntprs, 3);
+ *ntprs = std::max(*ntprs, 3);
}
if (old != *ntprs)
if (bench_nsteps > 10000 || bench_nsteps < 100)
{
fprintf(stderr, "WARNING: steps=");
- fprintf(stderr, "%"GMX_PRId64, bench_nsteps);
+ fprintf(stderr, "%" GMX_PRId64, bench_nsteps);
fprintf(stderr, ". Are you sure you want to perform so %s steps for each benchmark?\n", (bench_nsteps < 100) ? "few" : "many");
}
if ((npme_fixed > 0) && (5*npme_fixed < nnodes))
{
fprintf(stderr, "WARNING: Only %g percent of the ranks are assigned as PME-only ranks.\n",
- 100.0*((real)npme_fixed / (real)nnodes));
+ (100.0*npme_fixed)/nnodes);
}
if (opt2parg_bSet("-min", npargs, pa) || opt2parg_bSet("-max", npargs, pa))
{
/* Returns TRUE when "opt" is needed at launch time */
static gmx_bool is_launch_file(char *opt, gmx_bool bSet)
{
- if (0 == strncmp(opt, "-swap", 5))
+ if (0 == std::strncmp(opt, "-swap", 5))
{
return bSet;
}
/* Apart from the input .tpr and the output log files we need all options that
* were set on the command line and that do not start with -b */
- if (0 == strncmp(opt, "-b", 2) || 0 == strncmp(opt, "-s", 2)
- || 0 == strncmp(opt, "-err", 4) || 0 == strncmp(opt, "-p", 2) )
+ if (0 == std::strncmp(opt, "-b", 2) || 0 == std::strncmp(opt, "-s", 2)
+ || 0 == std::strncmp(opt, "-err", 4) || 0 == std::strncmp(opt, "-p", 2) )
{
return FALSE;
}
{
/* Apart from the input .tpr, all files starting with "-b" are for
* _b_enchmark files exclusively */
- if (0 == strncmp(opt, "-s", 2))
+ if (0 == std::strncmp(opt, "-s", 2))
{
return FALSE;
}
- if (0 == strncmp(opt, "-b", 2) || 0 == strncmp(opt, "-s", 2))
+ if (0 == std::strncmp(opt, "-b", 2) || 0 == std::strncmp(opt, "-s", 2))
{
if (!bOptional || bSet)
{
/* Adds 'buf' to 'str' */
-static void add_to_string(char **str, char *buf)
+static void add_to_string(char **str, const char *buf)
{
int len;
- len = strlen(*str) + strlen(buf) + 1;
+ len = std::strlen(*str) + std::strlen(buf) + 1;
srenew(*str, len);
- strcat(*str, buf);
+ std::strcat(*str, buf);
}
{
/* All options starting with -b* need the 'b' removed,
* therefore overwrite strbuf */
- if (0 == strncmp(opt, "-b", 2))
+ if (0 == std::strncmp(opt, "-b", 2))
{
sprintf(strbuf, "-%s %s ", &opt[2], name);
}
for (i = 0; (i < nfile); i++)
{
- if (strcmp(opt, fnm[i].opt) == 0)
+ if (std::strcmp(opt, fnm[i].opt) == 0)
{
fnm[i].flag |= ffSET;
}
{
opt = (char *)fnm[i].opt;
bSet = ((fnm[i].flag & ffSET) != 0);
- bBench = (0 == strncmp(opt, "-b", 2));
+ bBench = (0 == std::strncmp(opt, "-b", 2));
/* Check optional files */
/* If e.g. -eo is set, then -beo also needs to be set */
t_inputinfo *info;
int i;
FILE *fp;
- t_commrec *cr;
/* Print out how long the tuning took */
double seconds;
return 0;
}
+ // procstring[0]Â is used inside two different conditionals further down
+ GMX_RELEASE_ASSERT(procstring[0] != NULL, "Options inconsistency; procstring[0]Â is NULL");
+
/* Store the remaining unparsed command line entries in a string which
* is then attached to the mdrun command line */
snew(ExtraArgs, 1);
{
/* This string will be used for MPI runs and will appear after the
* mpirun command. */
- if (strcmp(procstring[0], "none") != 0)
+ if (std::strcmp(procstring[0], "none") != 0)
{
sprintf(bbuf, " %s %d ", procstring[0], nnodes);
}
* the actual list of settings is build in do_the_tests(). */
if ((nnodes > 2) && (npme_fixed < -1))
{
- if (0 == strcmp(npmevalues_opt[0], "auto"))
+ if (0 == std::strcmp(npmevalues_opt[0], "auto"))
{
/* Determine the npme range automatically based on the PME:PP load guess */
if (guessPMEratio > 1.0)
else
{
/* PME : PP load is in the range 0..1, let's test around the guess */
- guessPMEnodes = nnodes/(1.0 + 1.0/guessPMEratio);
- minPMEnodes = floor(0.7*guessPMEnodes);
- maxPMEnodes = ceil(1.6*guessPMEnodes);
- maxPMEnodes = min(maxPMEnodes, nnodes/2);
+ guessPMEnodes = static_cast<int>(nnodes/(1.0 + 1.0/guessPMEratio));
+ minPMEnodes = static_cast<int>(std::floor(0.7*guessPMEnodes));
+ maxPMEnodes = static_cast<int>(std::ceil(1.6*guessPMEnodes));
+ maxPMEnodes = std::min(maxPMEnodes, nnodes/2);
}
}
else
{
/* Determine the npme range based on user input */
- maxPMEnodes = floor(maxPMEfraction*nnodes);
- minPMEnodes = max(floor(minPMEfraction*nnodes), 0);
+ maxPMEnodes = static_cast<int>(std::floor(maxPMEfraction*nnodes));
+ minPMEnodes = std::max(static_cast<int>(std::floor(minPMEfraction*nnodes)), 0);
fprintf(stdout, "Will try runs with %d ", minPMEnodes);
if (maxPMEnodes != minPMEnodes)
{
{
fprintf(fp, "Number of ranks : %d\n", nnodes);
fprintf(fp, "The mpirun command is : %s\n", cmd_mpirun);
- if (strcmp(procstring[0], "none") != 0)
+ if (std::strcmp(procstring[0], "none") != 0)
{
fprintf(fp, "Passing # of ranks via : %s\n", procstring[0]);
}
fprintf(fp, "The mdrun command is : %s\n", cmd_mdrun);
fprintf(fp, "mdrun args benchmarks : %s\n", cmd_args_bench);
fprintf(fp, "Benchmark steps : ");
- fprintf(fp, "%"GMX_PRId64, bench_nsteps);
+ fprintf(fp, "%" GMX_PRId64, bench_nsteps);
fprintf(fp, "\n");
fprintf(fp, "dlb equilibration steps : %d\n", presteps);
if (sim_part > 1)
{
fprintf(fp, "Checkpoint time step : ");
- fprintf(fp, "%"GMX_PRId64, cpt_steps);
+ fprintf(fp, "%" GMX_PRId64, cpt_steps);
fprintf(fp, "\n");
}
fprintf(fp, "mdrun args at launchtime: %s\n", cmd_args_launch);
{
bOverwrite = TRUE;
fprintf(stderr, "Note: Simulation input file %s will have ", opt2fn("-so", NFILE, fnm));
- fprintf(stderr, "%"GMX_PRId64, new_sim_nsteps+cpt_steps);
+ fprintf(stderr, "%" GMX_PRId64, new_sim_nsteps+cpt_steps);
fprintf(stderr, " steps.\n");
fprintf(fp, "Simulation steps : ");
- fprintf(fp, "%"GMX_PRId64, new_sim_nsteps);
+ fprintf(fp, "%" GMX_PRId64, new_sim_nsteps);
fprintf(fp, "\n");
}
if (repeats > 1)
snew(perfdata, ntprs);
if (bBenchmark)
{
+ GMX_RELEASE_ASSERT(npmevalues_opt[0] != NULL, "Options inconsistency; npmevalues_opt[0] is NULL");
do_the_tests(fp, tpr_names, maxPMEnodes, minPMEnodes, npme_fixed, npmevalues_opt[0], perfdata, &pmeentries,
repeats, nnodes, ntprs, bThreads, cmd_mpirun, cmd_np, cmd_mdrun,
cmd_args_bench, fnm, NFILE, presteps, cpt_steps, bCheck, gpu_ids);
*/
#include "gmxpre.h"
-#include <assert.h>
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/confio.h"
#include "gromacs/topology/index.h"
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
int ePBC;
matrix boxtop, box, *sbox, avbox, corr;
rvec *xtop, *x, **sx;
- int isize, nalloc, nallocn, natom;
+ int isize, nalloc, nallocn;
t_trxstatus *status;
atom_id *index;
char *grpname;
sx = NULL;
clear_mat(avbox);
- natom = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
+ read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
nfr = 0;
do
{
srenew(sbox, nalloc);
srenew(sx, nalloc);
}
- assert(time != NULL); assert(sbox != NULL);
+ GMX_RELEASE_ASSERT(time != NULL, "Memory allocation failure; time array is NULL");
+ GMX_RELEASE_ASSERT(sbox != NULL, "Memory allocation failure; sbox array is NULL");
time[nfr] = t;
copy_mat(box, sbox[nfr]);
dt = (time[nfr-1] - time[0])/(nfr - 1);
/* Some ugly rounding to get nice nice times in the output */
- dt = (int)(10000.0*dt + 0.5)/10000.0;
+ dt = static_cast<int>((10000.0*dt + 0.5)/10000.0);
invbin = 1.0/rbin;
fmmax = nfr - 1;
}
snew(mcount, fmmax);
- nbin = (int)(rmax*invbin + 0.5);
+ nbin = static_cast<int>(rmax*invbin + 0.5);
if (sbin == 0)
{
mat_nx = fmmax + 1;
else
{
invsbin = 1.0/sbin;
- mat_nx = sqrt(fmmax*dt)*invsbin + 1;
+ mat_nx = static_cast<int>(std::sqrt(fmmax*dt)*invsbin + 1);
}
snew(mat, mat_nx);
for (f = 0; f < mat_nx; f++)
}
else
{
- mbin = (int)(sqrt(fbin*dt)*invsbin + 0.5);
+ mbin = static_cast<int>(std::sqrt(fbin*dt)*invsbin + 0.5);
}
for (i = 0; i < isize; i++)
{
d2 = distance2(sx[f][i], sx[ff][i]);
if (mbin < mat_nx && d2 < rmax2)
{
- bin = (int)(sqrt(d2)*invbin + 0.5);
+ bin = static_cast<int>(std::sqrt(d2)*invbin + 0.5);
if (bin < nbin)
{
mat[mbin][bin] += 1;
for (i = 0; i < isize; i++)
{
d2 = distance2(sx[f][i], sx[ff][i]);
- bin = (int)(sqrt(d2)*invbin + 0.5);
+ bin = static_cast<int>(std::sqrt(d2)*invbin + 0.5);
if (bin >= nalloc)
{
nallocn = 10*(bin/10) + 11;
fprintf(fp, "%g", i*rbin);
for (fbin = 0; fbin < nr; fbin++)
{
- fprintf(fp, " %g",
- (real)pr[fbin][i]/(rcount[fbin]*isize*rbin*(i == 0 ? 0.5 : 1)));
+ fprintf(fp, " %g", static_cast<real>(pr[fbin][i])/(rcount[fbin]*isize*rbin*(i == 0 ? 0.5 : 1.0)));
}
fprintf(fp, "\n");
}
}
for (f = 0; f <= ftmax; f++)
{
- fprintf(fp, "%g %g\n", f*dt, (real)pt[f]/(tcount[f]*isize));
+ fprintf(fp, "%g %g\n", f*dt, static_cast<real>(pt[f])/(tcount[f]*isize));
}
xvgrclose(fp);
}
*/
#include "gmxpre.h"
-#include <math.h>
-#include <stdio.h>
-#include <string.h>
+#include <cmath>
+#include <cstdio>
+#include <cstring>
#include "gromacs/commandline/pargs.h"
#include "gromacs/correlationfunctions/autocorr.h"
*/
#include "gmxpre.h"
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/strdb.h"
for (i = 0; (i < nres); i++)
{
snew(rnms[i], 256);
- sl = strlen(resnm[i]);
+ sl = std::strlen(resnm[i]);
sign = resnm[i][sl-1];
if ((sign == '+') || (sign == '-'))
{
sprintf(rnms[i], "%s-%d", resnm[i], i+r0);
if ((sign == '+') || (sign == '-'))
{
- sl = strlen(rnms[i]);
+ sl = std::strlen(rnms[i]);
rnms[i][sl] = sign;
rnms[i][sl+1] = '\0';
}
- slen = max(slen, (int)strlen(rnms[i]));
+ slen = std::max(slen, static_cast<int>(std::strlen(rnms[i])));
}
ring = (2+slen)*fontwidth;
outer = inner+ring;
slen = 0;
for (i = 0; (i < nres); i++)
{
- slen = max(slen, (int)strlen(resnm[i]));
+ slen = std::max(slen, static_cast<int>(strlen(resnm[i])));
}
fprintf(stderr, "slen = %d\n", slen);
- ring = (slen)*fontwidth;
+ ring = slen*fontwidth;
outer = inner+ring;
box = (1+(nres / (2*angle)))*outer;
for (i = 1; (i < argc); i++)
{
- if (strcmp(argv[i], "-r0") == 0)
+ if (std::strcmp(argv[i], "-r0") == 0)
{
- r0 = strtol(argv[++i], NULL, 10);
+ r0 = std::strtol(argv[++i], NULL, 10);
fprintf(stderr, "First residue is %d\n", r0);
}
- else if (strcmp(argv[i], "-rot0") == 0)
+ else if (std::strcmp(argv[i], "-rot0") == 0)
{
rot0 = strtod(argv[++i], NULL);
fprintf(stderr, "Initial rotation is %g\n", rot0);
}
- else if (strcmp(argv[i], "-T") == 0)
+ else if (std::strcmp(argv[i], "-T") == 0)
{
title = gmx_strdup(argv[++i]);
fprintf(stderr, "Title will be '%s'\n", title);
}
- else if (strcmp(argv[i], "-nn") == 0)
+ else if (std::strcmp(argv[i], "-nn") == 0)
{
bNum = FALSE;
fprintf(stderr, "No residue numbers\n");
*/
#include "gmxpre.h"
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <cmath>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
#include "gromacs/commandline/pargs.h"
#include "gromacs/fileio/matio.h"
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
#define FUDGE 1.2
{
bDiff = TRUE;
}
- if (strcmp(map1[i].desc, map2[i].desc) != 0)
+ if (std::strcmp(map1[i].desc, map2[i].desc) != 0)
{
bDiff = TRUE;
}
ps_rgb(ps, BLACK);
ps_strfont(ps, font, fontsize);
yhh = y0+fontsize+3*DDD;
- if ((int)strlen(label) > 0)
+ if (std::strlen(label) > 0)
{
ps_ctext(ps, x0, yhh, label, eXLeft);
}
{
x = 8*fontsize;
}
- boxxh = (real)x/(real)(nmap-mapoffset);
+ boxxh = x/(nmap-mapoffset);
if (boxxh > fontsize)
{
boxxh = fontsize;
}
+ GMX_RELEASE_ASSERT(map != NULL, "NULL map array provided to leg_continuous()");
+
/* LANDSCAPE */
xx0 = x0-((nmap-mapoffset)*boxxh)/2.0;
yhh = y0+boxyh+3*DDD;
ps_ctext(ps, xx0+boxxh/2, yhh, map[0].desc, eXCenter);
- if ((int)strlen(label) > 0)
+ if (std::strlen(label) > 0)
{
ps_ctext(ps, x0, yhh, label, eXCenter);
}
real xxx;
char **xtick, **ytick;
real xx, yy, dy, xx00, yy00, offset_x, offset_y;
- int i, j, x, y, ntx, nty, strlength;
+ int i, j, x, y, ntx, nty;
+ size_t strlength;
/* Only necessary when there will be no y-labels */
strlength = 0;
/* Draw the box */
ps_rgb(ps, BLACK);
- ps_linewidth(ps, psr->boxlinewidth);
+ ps_linewidth(ps, static_cast<int>(psr->boxlinewidth));
yy00 = y0;
for (i = 0; (i < nmat); i++)
{
}
/* Draw the ticks on the axes */
- ps_linewidth(ps, psr->ticklinewidth);
+ ps_linewidth(ps, static_cast<int>(psr->ticklinewidth));
xx00 = x0-1;
yy00 = y0-1;
for (i = 0; (i < nmat); i++)
(psr->Y.first && (y == 0)))
{
/* Major ticks */
- strlength = max(strlength, (int)strlen(ytick[y]));
+ strlength = std::max(strlength, std::strlen(ytick[y]));
ps_line (ps, xx00, yy, xx00-psr->Y.majorticklen, yy);
ps_ctext(ps, xx00-psr->Y.majorticklen-DDD,
yy-psr->Y.tickfontsize/3.0, ytick[y], eXRight);
xx00 = x0-1.5;
yy00 = y0-1.5;
- ps_linewidth(out, psr->zerolinewidth);
+ ps_linewidth(out, static_cast<int>(psr->zerolinewidth));
for (i = 0; (i < nmat); i++)
{
dy = box_height(&(mat[i]), psr);
xx = xx00+(x+0.7)*psr->xboxsize;
/* draw lines whenever tick label almost zero (e.g. next trajectory) */
if (x != 0 && x < mat[i].nx-1 &&
- fabs(mat[i].axis_x[x]) <
- 0.1*fabs(mat[i].axis_x[x+1]-mat[i].axis_x[x]) )
+ std::abs(mat[i].axis_x[x]) <
+ 0.1*std::abs(mat[i].axis_x[x+1]-mat[i].axis_x[x]) )
{
ps_line (out, xx, yy00, xx, yy00+dy+2);
}
yy = yy00+(y+0.7)*psr->yboxsize;
/* draw lines whenever tick label almost zero (e.g. next trajectory) */
if (y != 0 && y < mat[i].ny-1 &&
- fabs(mat[i].axis_y[y]) <
- 0.1*fabs(mat[i].axis_y[y+1]-mat[i].axis_y[y]) )
+ std::abs(mat[i].axis_y[y]) <
+ 0.1*std::abs(mat[i].axis_y[y+1]-mat[i].axis_y[y]) )
{
ps_line (out, xx00, yy, xx00+w+2, yy);
}
ww = 0;
for (i = 0; (i < nmat); i++)
{
- ww = max(ww, mat[i].nx*psr->xboxsize);
+ ww = std::max(ww, mat[i].nx*psr->xboxsize);
hh += box_height(&(mat[i]), psr);
- maxytick = max(maxytick, mat[i].nx);
+ maxytick = std::max(maxytick, mat[i].nx);
}
if (bFrame)
{
if (psr->Y.major > 0)
{
dww += psr->Y.majorticklen + DDD +
- psr->Y.tickfontsize*(log(maxytick)/log(10.0));
+ psr->Y.tickfontsize*(std::log(static_cast<real>(maxytick))/std::log(10.0));
}
else if (psr->Y.minor > 0)
{
int nmap, j, k;
t_mapping *map;
- nsymbols = strlen(mapper);
+ nsymbols = std::strlen(mapper);
nmap = nmap1+nmap2;
if (nmap > nsymbols*nsymbols)
{
gmx_bool bDiag, gmx_bool bFirstDiag)
{
FILE *out;
- char buf[100];
- int i, j, k, x, y, col;
+ int i, x, y, col;
int nmap;
t_mapping *map = NULL;
sfree(mat[i].map);
mat[i].nmap = nmap;
mat[i].map = map;
- if (strcmp(mat[i].title, mat2[i].title) != 0)
+ if (std::strcmp(mat[i].title, mat2[i].title) != 0)
{
sprintf(mat[i].title+strlen(mat[i].title), " / %s", mat2[i].title);
}
- if (strcmp(mat[i].legend, mat2[i].legend) != 0)
+ if (std::strcmp(mat[i].legend, mat2[i].legend) != 0)
{
sprintf(mat[i].legend+strlen(mat[i].legend), " / %s", mat2[i].legend);
}
real *major, real *minor)
{
real space;
- gmx_bool bTryAgain, bFive;
+ gmx_bool bTryAgain;
int i, j, t, f = 0, ten;
#define NFACT 4
real major_fact[NFACT] = {5, 4, 2, 1};
real minor_fact[NFACT] = {5, 4, 4, 5};
/* start with interval between 10 matrix points: */
- space = max(10*axis[1]-axis[0], axis[min(10, n-1)]-axis[0]);
+ space = std::max(10*axis[1]-axis[0], axis[std::min(10, n-1)]-axis[0]);
/* get power of 10 */
- ten = (int)ceil(log(space)/log(10))-1;
+ ten = static_cast<int>(std::ceil(std::log(space)/std::log(10.0))-1);
bTryAgain = TRUE;
for (t = ten+2; t > ten-3 && bTryAgain; t--)
{
for (f = 0; f < NFACT && bTryAgain; f++)
{
- space = pow(10, t) * major_fact[f];
+ space = std::pow(static_cast<real>(10.0), static_cast<real>(t)) * major_fact[f];
/* count how many ticks we would get: */
i = 0;
for (j = 0; j < n; j++)
}
}
/* do we have a reasonable number of ticks ? */
- bTryAgain = (i > min(10, n-1)) || (i < 5);
+ bTryAgain = (i > std::min(10, n-1)) || (i < 5);
}
}
if (bTryAgain)
{
- space = max(10*axis[1]-axis[0], axis[min(10, n-1)]-axis[0]);
+ space = std::max(10*axis[1]-axis[0], axis[std::min(10, n-1)]-axis[0]);
fprintf(stderr, "Auto tick spacing failed for %c-axis, guessing %g\n",
axisnm, space);
}
*major = space;
- *minor = space / minor_fact[f-1];
+ *minor = space / minor_fact[(f > 0) ? f-1 : 0];
fprintf(stderr, "Auto tick spacing for %c-axis: major %g, minor %g\n",
axisnm, *major, *minor);
}
t_psdata out;
t_psrec psrec, *psr;
int W, H;
- int i, j, x, y, col, leg = 0;
+ int i, x, y, col, leg = 0;
real x0, y0, xx;
real w, h, dw, dh;
int nmap1 = 0, nmap2 = 0, leg_nmap;
}
if ( (mat[0].legend[0] == 0) && psr->legend)
{
- strcpy(mat[0].legend, psr->leglabel);
+ std::strcpy(mat[0].legend, psr->leglabel);
}
bTitle = bTitle && mat[nmat-1].title[0];
box_dim(nmat, mat, mat2, psr, elegend, bFrame, &w, &h, &dw, &dh);
/* Set up bounding box */
- W = w+dw;
- H = h+dh;
+ W = static_cast<int>(w+dw);
+ H = static_cast<int>(h+dh);
/* Start box at */
x0 = dw;
y0 = dh;
- x = W+psr->xoffs;
- y = H+psr->yoffs;
+ x = static_cast<int>(W+psr->xoffs);
+ y = static_cast<int>(H+psr->yoffs);
if (bFrame)
{
x += 5*DDD;
y += 4*DDD;
}
out = ps_open(outf, 0, 0, x, y);
- ps_linewidth(out, psr->linewidth);
+ ps_linewidth(out, static_cast<int>(psr->linewidth));
ps_init_rgb_box(out, psr->xboxsize, psr->yboxsize);
ps_init_rgb_nbox(out, psr->xboxsize, psr->yboxsize);
ps_translate(out, psr->xoffs, psr->yoffs);
/* Print title, if any */
ps_rgb(out, BLACK);
ps_strfont(out, psr->titfont, psr->titfontsize);
- if (!mat2 || (strcmp(mat[i].title, mat2[i].title) == 0))
+ if (!mat2 || (std::strcmp(mat[i].title, mat2[i].title) == 0))
{
- strcpy(buf, mat[i].title);
+ std::strcpy(buf, mat[i].title);
}
else
{
if (elegend != elNone)
{
ps_comment(out, "Now it's legend time!");
- ps_linewidth(out, psr->linewidth);
+ ps_linewidth(out, static_cast<int>(psr->linewidth));
if (mat2 == NULL || elegend != elSecond)
{
bDiscrete = mat[0].bDiscrete;
}
for (x = 0; x < mats[i].nx-1; x++)
{
- if (fabs(mats[i].axis_x[x+1]) < 1e-5)
+ if (std::abs(mats[i].axis_x[x+1]) < 1e-5)
{
for (y = 0; y < mats[i].ny; y++)
{
}
for (y = 0; y < mats[i].ny-1; y++)
{
- if (fabs(mats[i].axis_y[y+1]) < 1e-5)
+ if (std::abs(mats[i].axis_y[y+1]) < 1e-5)
{
for (x = 0; x < mats[i].nx; x++)
{
real *cmin, real *cmax)
{
int i, j, k, nlevels;
- t_mapping *map = NULL;
FILE *out;
real **rmat1, **rmat2;
real rhi, rlo;
default:
gmx_fatal(FARGS, "No such combination rule %d for matrices", ecombine);
}
- rlo = min(rlo, rmat1[i][j]);
- rhi = max(rhi, rmat1[i][j]);
+ rlo = std::min(rlo, rmat1[i][j]);
+ rhi = std::max(rhi, rmat1[i][j]);
}
}
if (cmin)
{
rhi = *cmax;
}
- nlevels = max(mat1[k].nmap, mat2[k].nmap);
+ nlevels = std::max(mat1[k].nmap, mat2[k].nmap);
if (rhi == rlo)
{
fprintf(stderr,
if (c <= 0.25) /* 0-0.25 */
{
r = 0;
- g = pow(4*c, 0.666);
+ g = std::pow(4.0*c, 2.0/3.0);
b = 1;
}
else if (c <= 0.5) /* 0.25-0.5 */
{
r = 0;
g = 1;
- b = pow(2-4*c, 0.666);
+ b = std::pow(2.0-4.0*c, 2.0/3.0);
}
else if (c <= 0.75) /* 0.5-0.75 */
{
- r = pow(4*c-2, 0.666);
+ r = std::pow(4.0*c-2.0, 2.0/3.0);
g = 1;
b = 0;
}
else /* 0.75-1 */
{
r = 1;
- g = pow(4-4*c, 0.666);
+ g = std::pow(4.0-4.0*c, 2.0/3.0);
b = 0;
}
map[i].rgb.r = r;
int i, nmat, nmat2, etitle, elegend, ediag, erainbow, ecombine;
t_matrix *mat = NULL, *mat2 = NULL;
gmx_bool bTitle, bTitleOnce, bDiag, bFirstDiag, bGrad;
- static gmx_bool bFrame = TRUE, bZeroLine = FALSE, bYonce = FALSE, bAdd = FALSE;
+ static gmx_bool bFrame = TRUE, bZeroLine = FALSE, bYonce = FALSE;
static real size = 400, boxx = 0, boxy = 0, cmin = 0, cmax = 0;
static rvec grad = {0, 0, 0};
enum {
if (nmat != nmat2)
{
fprintf(stderr, "Different number of matrices, using the smallest number.\n");
- nmat = nmat2 = min(nmat, nmat2);
+ nmat = nmat2 = std::min(nmat, nmat2);
}
}
else
{
for (i = 0; (i < nmat); i++)
{
- strcpy(mat[i].label_y, mat[i].title);
+ std::strcpy(mat[i].label_y, mat[i].title);
if (mat2)
{
- strcpy(mat2[i].label_y, mat2[i].title);
+ std::strcpy(mat2[i].label_y, mat2[i].title);
}
}
}
namespace gmx
{
+std::size_t
+countWords(const char *s)
+{
+ std::size_t nWords = 0;
+ // Use length variable to avoid N^2 complexity when executing strlen(s) every iteration
+ std::size_t length = std::strlen(s);
+
+ for (std::size_t i = 0; i < length; i++)
+ {
+ // If we found a new word, increase counter and step through the word
+ if (std::isalnum(s[i]))
+ {
+ ++nWords;
+ // If we hit string end, '\0' is not alphanumerical
+ while (std::isalnum(s[i]))
+ {
+ // This might increment i to the string end, and then the outer
+ // loop will increment i one unit beyond that, but since
+ // we compare to the string length in the outer loop this is fine.
+ i++;
+ }
+ }
+ }
+ return nWords;
+}
+
+
+std::size_t
+countWords(const std::string &str)
+{
+ // Under out beautiful C++ interface hides an ugly c-string implementation :-)
+ return countWords(str.c_str());
+}
+
bool endsWith(const char *str, const char *suffix)
{
if (isNullOrEmpty(suffix))
return endsWith(str.c_str(), suffix);
}
+/*!\brief Returns number of space-separated words in zero-terminated char ptr
+ *
+ * \param s Character pointer to zero-terminated, which will not be changed.
+ *
+ * \returns number of words in string.
+ *
+ * \note This routine is mainly meant to support legacy code in GROMACS. For
+ * new source you should try hard to use C++ string objects instead.
+ */
+std::size_t
+countWords(const char *s);
+
+/*!\brief Returns the number of space-separated words in a string object
+ *
+ * \param str Reference to string object, which will not be changed.
+ *
+ * \returns number of words in string.
+ */
+std::size_t
+countWords(const std::string &str);
+
/*! \brief
* Removes a suffix from a string.
*