Commit 9cb0a2c6 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Set constant variables to const.

parent f325db4b
......@@ -193,17 +193,17 @@ Outputgmt(void *process)
cdoInitialize(process);
// clang-format off
int OUTPUTCENTER = cdoOperatorAdd("gmtxyz", 0, 0, nullptr);
int OUTPUTCENTER2 = cdoOperatorAdd("outputcenter2", 0, 0, nullptr);
int OUTPUTCENTERCPT = cdoOperatorAdd("outputcentercpt", 0, 0, nullptr);
int OUTPUTBOUNDS = cdoOperatorAdd("gmtcells", 0, 0, nullptr);
int OUTPUTBOUNDSCPT = cdoOperatorAdd("outputboundscpt", 0, 0, nullptr);
int OUTPUTVECTOR = cdoOperatorAdd("outputvector", 0, 0, nullptr);
int OUTPUTTRI = cdoOperatorAdd("outputtri", 0, 0, nullptr);
int OUTPUTVRML = cdoOperatorAdd("outputvrml", 0, 0, nullptr);
const int OUTPUTCENTER = cdoOperatorAdd("gmtxyz", 0, 0, nullptr);
const int OUTPUTCENTER2 = cdoOperatorAdd("outputcenter2", 0, 0, nullptr);
const int OUTPUTCENTERCPT = cdoOperatorAdd("outputcentercpt", 0, 0, nullptr);
const int OUTPUTBOUNDS = cdoOperatorAdd("gmtcells", 0, 0, nullptr);
const int OUTPUTBOUNDSCPT = cdoOperatorAdd("outputboundscpt", 0, 0, nullptr);
const int OUTPUTVECTOR = cdoOperatorAdd("outputvector", 0, 0, nullptr);
const int OUTPUTTRI = cdoOperatorAdd("outputtri", 0, 0, nullptr);
const int OUTPUTVRML = cdoOperatorAdd("outputvrml", 0, 0, nullptr);
// clang-format on
int operatorID = cdoOperatorID();
const int operatorID = cdoOperatorID();
if (operatorID == OUTPUTVECTOR)
{
......@@ -223,32 +223,37 @@ Outputgmt(void *process)
FILE *cpt_fp = fopen(cpt_file, "r");
if (cpt_fp == nullptr) cdoAbort("Open failed on color palette table %s", cpt_file);
int status = cptRead(cpt_fp, &cpt);
const int status = cptRead(cpt_fp, &cpt);
if (status != 0) cdoAbort("Error during read of color palette table %s", cpt_file);
if (Options::cdoVerbose) cptWrite(stderr, cpt);
}
int streamID = cdoStreamOpenRead(cdoStreamName(0));
const int streamID = cdoStreamOpenRead(cdoStreamName(0));
int vlistID = cdoStreamInqVlist(streamID);
int taxisID = vlistInqTaxis(vlistID);
const int vlistID = cdoStreamInqVlist(streamID);
const int taxisID = vlistInqTaxis(vlistID);
int varID = 0;
vlistInqVarName(vlistID, varID, varname);
int code = vlistInqVarCode(vlistID, varID);
const int code = vlistInqVarCode(vlistID, varID);
int gridID = vlistInqVarGrid(vlistID, varID);
int zaxisID = vlistInqVarZaxis(vlistID, varID);
double missval = vlistInqVarMissval(vlistID, varID);
const int zaxisID = vlistInqVarZaxis(vlistID, varID);
const double missval = vlistInqVarMissval(vlistID, varID);
size_t gridsize = gridInqSize(gridID);
int gridtype = gridInqType(gridID);
const size_t gridsize = gridInqSize(gridID);
if (gridtype == GRID_GME) gridID = gridToUnstructured(gridID, 1);
int gridtype = gridInqType(gridID);
if (gridtype == GRID_GME || gridtype == GRID_GAUSSIAN_REDUCED)
{
gridID = gridToUnstructured(gridID, 1);
gridtype = gridInqType(gridID);
}
if (gridtype != GRID_UNSTRUCTURED && gridtype != GRID_CURVILINEAR)
{
gridID = gridToCurvilinear(gridID, 1);
gridtype = gridInqType(gridID);
lgrid_gen_bounds = true;
}
......@@ -302,9 +307,9 @@ Outputgmt(void *process)
if (operatorID == OUTPUTBOUNDS || operatorID == OUTPUTBOUNDSCPT) cdoAbort("Bounds not available hovmoeller data!");
}
int ncorner = (gridInqType(gridID) == GRID_UNSTRUCTURED) ? gridInqNvertex(gridID) : 4;
const int ncorner = (gridInqType(gridID) == GRID_UNSTRUCTURED) ? gridInqNvertex(gridID) : 4;
bool grid_is_circular = gridIsCircular(gridID);
const bool grid_is_circular = gridIsCircular(gridID);
std::vector<double> grid_center_lat(gridsize), grid_center_lon(gridsize);
gridInqYvals(gridID, grid_center_lat.data());
......@@ -332,7 +337,7 @@ Outputgmt(void *process)
for (int j = 0; j < nlat; ++j)
{
int ij2 = j * (nlon + 1);
const int ij2 = j * (nlon + 1);
grid_center_lon2[ij2 + nlon] += 360;
}
......@@ -350,7 +355,7 @@ Outputgmt(void *process)
if (luse_grid_corner)
{
if (ncorner == 0) cdoAbort("Number of cell corners undefined!");
size_t nalloc = ncorner * gridsize;
const size_t nalloc = ncorner * gridsize;
grid_corner_lat.resize(nalloc);
grid_corner_lon.resize(nalloc);
......@@ -419,8 +424,8 @@ Outputgmt(void *process)
int tsID = 0;
while ((nrecs = cdoStreamInqTimestep(streamID, tsID)))
{
int64_t vdate = taxisInqVdate(taxisID);
int vtime = taxisInqVtime(taxisID);
const int64_t vdate = taxisInqVdate(taxisID);
const int vtime = taxisInqVtime(taxisID);
date2str(vdate, vdatestr, sizeof(vdatestr));
time2str(vtime, vtimestr, sizeof(vtimestr));
......@@ -444,11 +449,11 @@ Outputgmt(void *process)
if (operatorID == OUTPUTVECTOR) fprintf(stdout, "# Increment = %d\n", ninc);
fprintf(stdout, "#\n");
fprintf(stdout, "# File = %s\n", cdoGetStreamName(0));
fprintf(stdout, "# Date = %s\n", vdatestr);
fprintf(stdout, "# Time = %s\n", vtimestr);
fprintf(stdout, "# Name = %s\n", varname);
fprintf(stdout, "# Code = %d\n", code);
fprintf(stdout, "# Stream = %s\n", cdoGetStreamName(0));
fprintf(stdout, "# Date = %s\n", vdatestr);
fprintf(stdout, "# Time = %s\n", vtimestr);
fprintf(stdout, "# Name = %s\n", varname);
fprintf(stdout, "# Code = %d\n", code);
}
varID0 = varID;
......@@ -464,9 +469,9 @@ Outputgmt(void *process)
if (operatorID == OUTPUTCENTER2 && grid_is_circular) make_cyclic(array.data(), array2.data(), nlon, nlat);
double level = zaxis_center_lev[levelID];
const double level = zaxis_center_lev[levelID];
if ((tsID == 0 || lzon || lmer) && operatorID != OUTPUTTRI) fprintf(stdout, "# Level = %g\n", level);
if ((tsID == 0 || lzon || lmer) && operatorID != OUTPUTTRI) fprintf(stdout, "# Level = %g\n", level);
if (lhov) fprintf(stdout, "# Timestep = %d\n", tsID + 1);
if (operatorID != OUTPUTTRI) fprintf(stdout, "#\n");
......@@ -477,7 +482,7 @@ Outputgmt(void *process)
{
double minval, maxval, meanval;
arrayMinMaxMeanMV(gridsize, array.data(), missval, minval, maxval, meanval);
double range = maxval - minval;
const double range = maxval - minval;
fprintf(stderr, "makecpt -T%g/%g/%g -Crainbow > gmt.cpt\n", minval, maxval, range / 20);
fprintf(stderr, "pscontour -K -JQ0/10i -Rd -I -Cgmt.cpt data.gmt > gmtplot.ps\n");
fprintf(stderr, "pscoast -O -J -R -Dc -W -B40g20 >> gmtplot.ps\n");
......@@ -516,20 +521,18 @@ Outputgmt(void *process)
}
else if (operatorID == OUTPUTTRI)
{
int c1, c2, c3;
int ip1;
if (gridInqType(gridID) != GRID_CURVILINEAR) cdoAbort("Unsupported grid!");
int mlon = nlon - 1;
/* if ( gridIsCircular(gridID) ) mlon = nlon; */
const int mlon = nlon - 1;
// if ( gridIsCircular(gridID) ) mlon = nlon;
for (int j = 0; j < nlat - 1; ++j)
for (int i = 0; i < mlon; ++i)
{
ip1 = i + 1;
int ip1 = i + 1;
if (i == nlon - 1) ip1 = 0;
c1 = (j) *nlon + ip1;
c2 = (j) *nlon + i;
c3 = (j + 1) * nlon + i;
int c1 = (j) *nlon + ip1;
int c2 = (j) *nlon + i;
int c3 = (j + 1) * nlon + i;
fprintf(stdout, "%d %d %d\n", c1, c2, c3);
c1 = (j) *nlon + i + 1;
c2 = (j + 1) * nlon + i;
......@@ -548,7 +551,7 @@ Outputgmt(void *process)
for (int j = 0; j < nlat; j += ninc)
for (int i = 0; i < nlon; i += ninc)
{
/* compute length of velocity vector */
// compute length of velocity vector
auv[IX2D(j, i, nlon)]
= sqrt(uf[IX2D(j, i, nlon)] * uf[IX2D(j, i, nlon)] + vf[IX2D(j, i, nlon)] * vf[IX2D(j, i, nlon)]);
......@@ -576,7 +579,7 @@ Outputgmt(void *process)
{
double minval, maxval, meanval;
arrayMinMaxMeanMV(gridsize, array.data(), missval, minval, maxval, meanval);
double range = maxval - minval;
const double range = maxval - minval;
fprintf(stderr, "makecpt -T%g/%g/%g -Crainbow > gmt.cpt\n", minval, maxval, range / 20);
fprintf(stderr, "psxy -K -JQ0/10i -Rd -L -Cgmt.cpt -m data.gmt > gmtplot.ps\n");
// fprintf(stderr, "psxy -K -Jx0.028id -Rd -L -Cgmt.cpt -m
......@@ -683,7 +686,7 @@ Outputgmt(void *process)
{
const double *lon_bounds = grid_corner_lon.data() + i * ncorner;
const double *lat_bounds = grid_corner_lat.data() + i * ncorner;
int ncorner_new = check_ncorner(ncorner, lon_bounds, lat_bounds);
const int ncorner_new = check_ncorner(ncorner, lon_bounds, lat_bounds);
for (int ic = 0; ic < ncorner_new; ic++) fprintf(stdout, " %g %g\n", lon_bounds[ic], lat_bounds[ic]);
fprintf(stdout, " %g %g\n", lon_bounds[0], lat_bounds[0]);
......
......@@ -25,12 +25,6 @@
#include "compare.h"
//from cdi but not in its interface!
//
extern "C"{
void gaussaw(double *pa, double *pw, size_t nlat);
}
static void
skip_nondigit_lines(FILE *gfp)
{
......@@ -164,7 +158,7 @@ grid_read_pingo(FILE *gfp)
}
bool lgauss = false;
if (nlat > 2) /* check if gaussian */
if (nlat > 2) // check if gaussian
{
std::vector<double> yvals(grid.ysize);
std::vector<double> yw(grid.ysize);
......
......@@ -170,11 +170,11 @@ print_xyvals2D(int gridID, int dig)
gridInqYunits(gridID, yunits);
const size_t gridsize = gridInqSize(gridID);
double *xvals2D = (double *) malloc(gridsize * sizeof(double));
double *yvals2D = (double *) malloc(gridsize * sizeof(double));
std::vector<double> xvals2D(gridsize);
std::vector<double> yvals2D(gridsize);
gridInqXvals(gridID, xvals2D);
gridInqYvals(gridID, yvals2D);
gridInqXvals(gridID, xvals2D.data());
gridInqYvals(gridID, yvals2D.data());
double xfirst = xvals2D[0];
double xlast = xvals2D[0];
......@@ -197,7 +197,7 @@ print_xyvals2D(int gridID, int dig)
const size_t ysize = gridInqYsize(gridID);
if (xsize > 1)
{
double *xvals = (double *) malloc((size_t) xsize * sizeof(double));
std::vector<double> xvals(xsize);
for (size_t i = 0; i < xsize; ++i) xvals[i] = xvals2D[i];
xinc = fabs(xvals[xsize - 1] - xvals[0]) / (xsize - 1);
for (size_t i = 1; i < xsize; i++)
......@@ -206,7 +206,6 @@ print_xyvals2D(int gridID, int dig)
xinc = 0;
break;
}
free(xvals);
if (IS_NOT_EQUAL(xinc, 0))
{
for (size_t i = 1; i < ysize; i++)
......@@ -220,7 +219,7 @@ print_xyvals2D(int gridID, int dig)
}
if (ysize > 1)
{
double *yvals = (double *) malloc((size_t) ysize * sizeof(double));
std::vector<double> yvals(ysize);
for (size_t i = 0; i < ysize; ++i) yvals[i] = yvals2D[i * xsize];
yinc = fabs(yvals[ysize - 1] - yvals[0]) / (ysize - 1);
for (size_t i = 1; i < ysize; i++)
......@@ -229,7 +228,6 @@ print_xyvals2D(int gridID, int dig)
yinc = 0;
break;
}
free(yvals);
if (IS_NOT_EQUAL(yinc, 0))
{
for (size_t i = 1; i < xsize; i++)
......@@ -254,16 +252,13 @@ print_xyvals2D(int gridID, int dig)
if (IS_NOT_EQUAL(yinc, 0)) fprintf(stdout, " by %.*g", dig, yinc);
fprintf(stdout, " %s", yunits);
fprintf(stdout, "\n");
free(xvals2D);
free(yvals2D);
}
}
static void
printGridNp(int gridtype, int gridID, size_t gridsize, size_t xsize, size_t ysize)
{
size_t xysize = xsize * ysize;
const size_t xysize = xsize * ysize;
fprintf(stdout, "points=%zu", gridsize);
if (gridtype == GRID_GAUSSIAN_REDUCED)
fprintf(stdout, " nlat=%zu", ysize);
......@@ -332,6 +327,8 @@ printGridInfoKernel(int gridID, int index, int lproj)
{
fprintf(stdout, "%33s :", "available");
if (gridInqXbounds(gridID, NULL) && gridInqYbounds(gridID, NULL)) fprintf(stdout, " cellbounds");
else if (gridInqXbounds(gridID, NULL)) fprintf(stdout, " xbounds");
else if (gridInqYbounds(gridID, NULL)) fprintf(stdout, " ybounds");
if (gridHasArea(gridID)) fprintf(stdout, " area");
if (gridInqMask(gridID, NULL)) fprintf(stdout, " mask");
fprintf(stdout, "\n");
......@@ -483,8 +480,8 @@ static void
printZaxisLevelInfo(const int levelsize, const int zaxisID, const int zaxistype, double &zinc, const int dig, const char *zname,
const char *zunits)
{
double *levels = (double *) malloc((size_t) levelsize * sizeof(double));
zaxisInqLevels(zaxisID, levels);
std::vector<double> levels((size_t) levelsize);
zaxisInqLevels(zaxisID, levels.data());
if (!(zaxisTypeIsSingleLayer(zaxistype) && levelsize == 1 && fabs(levels[0]) <= 0))
{
......@@ -510,8 +507,6 @@ printZaxisLevelInfo(const int levelsize, const int zaxisID, const int zaxistype,
fprintf(stdout, " %s", zunits);
fprintf(stdout, "\n");
}
free(levels);
}
static void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment