*/
#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);
}
}
}