From 712c51230f4966b689f1b0411944ee782ed30c12 Mon Sep 17 00:00:00 2001 From: Uwe Schulzweida <uwe.schulzweida@mpimet.mpg.de> Date: Thu, 19 Oct 2023 15:26:18 +0200 Subject: [PATCH] Declare object as pointer to const --- libcdi | 2 +- src/remap_bicubic.cc | 2 +- src/remap_bilinear.cc | 4 ++-- src/remap_conserv.cc | 6 +++--- src/remap_store_link.cc | 8 ++++---- src/remap_store_link.h | 4 ++-- src/remap_vars.cc | 20 ++++++++++---------- src/sellist.cc | 25 ++++++++++++++----------- src/specspace.cc | 9 +++++---- src/specspace.h | 10 +++++----- 10 files changed, 47 insertions(+), 43 deletions(-) diff --git a/libcdi b/libcdi index bd90f1f69..e890330eb 160000 --- a/libcdi +++ b/libcdi @@ -1 +1 @@ -Subproject commit bd90f1f6913b8d3e704d667cac4bbd886418e09c +Subproject commit e890330ebfcf84fbc95a6ab932302459314ca695 diff --git a/src/remap_bicubic.cc b/src/remap_bicubic.cc index 0f8af997d..8c1b8e6b4 100644 --- a/src/remap_bicubic.cc +++ b/src/remap_bicubic.cc @@ -114,7 +114,7 @@ bicubic_warning() void remap_bicubic_weights(RemapSearch &rsearch, RemapVars &rv) { - auto srcGrid = rsearch.srcGrid; + const auto srcGrid = rsearch.srcGrid; auto tgtGrid = rsearch.tgtGrid; if (Options::cdoVerbose) cdo_print("Called %s()", __func__); diff --git a/src/remap_bilinear.cc b/src/remap_bilinear.cc index 1658c6a63..cb123f2bd 100644 --- a/src/remap_bilinear.cc +++ b/src/remap_bilinear.cc @@ -239,7 +239,7 @@ remap_bilinear_weights_healpix(const RemapSearch &rsearch, const Varray<short> & void remap_bilinear_weights(RemapSearch &rsearch, RemapVars &rv) { - auto srcGrid = rsearch.srcGrid; + const auto srcGrid = rsearch.srcGrid; auto tgtGrid = rsearch.tgtGrid; auto isHealpixGrid = (srcGrid->type == RemapGridType::HealPix); @@ -381,7 +381,7 @@ template <typename T> static void remap_bilinear(RemapSearch &rsearch, const Varray<T> &srcArray, Varray<T> &tgtArray, T missval, size_t nmiss) { - auto srcGrid = rsearch.srcGrid; + const auto srcGrid = rsearch.srcGrid; auto tgtGrid = rsearch.tgtGrid; auto isHealpixGrid = (srcGrid->type == RemapGridType::HealPix); diff --git a/src/remap_conserv.cc b/src/remap_conserv.cc index 048eb0206..bee27efcb 100644 --- a/src/remap_conserv.cc +++ b/src/remap_conserv.cc @@ -144,7 +144,7 @@ cdo_compute_overlap_areas(size_t numSearchCells, CellSearch &search, const GridC } static double -get_edge_direction(double *ref_corner, double *corner_a, double *corner_b) +get_edge_direction(const double *ref_corner, double *corner_a, double *corner_b) { double edge_norm[3]; crossproduct_ld(corner_a, corner_b, edge_norm); @@ -244,8 +244,8 @@ set_cell_coordinates_yac(RemapGridType remapGridType, size_t cellIndex, size_t n auto nx = remapGrid->dims[0]; auto iy = cellIndex / nx; auto ix = cellIndex - iy * nx; - auto reg2d_corner_lon = &remapGrid->reg2d_corner_lon[ix]; - auto reg2d_corner_lat = &remapGrid->reg2d_corner_lat[iy]; + const auto reg2d_corner_lon = &remapGrid->reg2d_corner_lon[ix]; + const auto reg2d_corner_lat = &remapGrid->reg2d_corner_lat[iy]; constexpr int xi[4] = { 0, 1, 1, 0 }; constexpr int yi[4] = { 0, 0, 1, 1 }; for (int k = 0; k < 4; ++k) diff --git a/src/remap_store_link.cc b/src/remap_store_link.cc index 48ef9a66d..664ead2ee 100644 --- a/src/remap_store_link.cc +++ b/src/remap_store_link.cc @@ -23,13 +23,13 @@ is_sorted_list(size_t n, const size_t *list) static int qcompare_index(const void *a, const void *b) { - return (((const IndexWeight *) a)->index < ((const IndexWeight *) b)->index); + return (static_cast<const IndexWeight *>(a)->index < static_cast<const IndexWeight *>(b)->index); } static int qcompare_index4(const void *a, const void *b) { - return (((const IndexWeight4 *) a)->index < ((const IndexWeight4 *) b)->index); + return (static_cast<const IndexWeight4 *>(a)->index < static_cast<const IndexWeight4 *>(b)->index); } static void @@ -45,7 +45,7 @@ sort_indexWeights4(IndexWeight4 *indexWeights) } void -store_weightlinks(int doAlloc, size_t numWeights, size_t *indices, double *weights, size_t cellIndex, +store_weightlinks(int doAlloc, size_t numWeights, const size_t *indices, const double *weights, size_t cellIndex, std::vector<WeightLinks> &weightLinks) { weightLinks[cellIndex].nlinks = 0; @@ -70,7 +70,7 @@ store_weightlinks(int doAlloc, size_t numWeights, size_t *indices, double *weigh } void -store_weightlinks_bicubic(size_t *indices, double (&weights)[4][4], size_t cellIndex, std::vector<WeightLinks4> &weightLinks) +store_weightlinks_bicubic(const size_t *indices, double (&weights)[4][4], size_t cellIndex, std::vector<WeightLinks4> &weightLinks) { weightLinks[cellIndex].nlinks = 0; weightLinks[cellIndex].offset = 0; diff --git a/src/remap_store_link.h b/src/remap_store_link.h index 215f5ec3d..2821f1e8d 100644 --- a/src/remap_store_link.h +++ b/src/remap_store_link.h @@ -42,9 +42,9 @@ bool is_sorted_list(size_t n, const size_t *list); void weight_links_alloc(size_t numNeighbors, size_t gridSize, std::vector<WeightLinks> &weightLinks); void weight_links_4_alloc(size_t gridSize, std::vector<WeightLinks4> &weightLinks); -void store_weightlinks(int doAlloc, size_t numWeights, size_t *indices, double *weights, size_t cellIndex, +void store_weightlinks(int doAlloc, size_t numWeights, const size_t *indices, const double *weights, size_t cellIndex, std::vector<WeightLinks> &weightLinks); -void store_weightlinks_bicubic(size_t *indices, double (&weights)[4][4], size_t cellIndex, std::vector<WeightLinks4> &weightLinks); +void store_weightlinks_bicubic(const size_t *indices, double (&weights)[4][4], size_t cellIndex, std::vector<WeightLinks4> &weightLinks); void weight_links_to_remap_links(int doAlloc, size_t gridSize, std::vector<WeightLinks> &weightLinks, RemapVars &rv); void weight_links_4_to_remap_links(size_t gridSize, std::vector<WeightLinks4> &weightLinks, RemapVars &rv); diff --git a/src/remap_vars.cc b/src/remap_vars.cc index ac98c090d..aa0cd6096 100644 --- a/src/remap_vars.cc +++ b/src/remap_vars.cc @@ -51,8 +51,8 @@ remap_first_order(Varray<T2> &tgtArray, const RemapVars &rv, const Varray<T1> &s for (size_t i = 0; i < nlinks; ++i) { auto noff = i * 2; - auto s = &srcIndices[noff]; - auto w = &weights[noff]; + const auto s = &srcIndices[noff]; + const auto w = &weights[noff]; auto tgtPoint = srcArray[s[0]] * w[0] + srcArray[s[1]] * w[1]; tgtArray[tgtIndices[noff]] = tgtPoint; } @@ -65,8 +65,8 @@ remap_first_order(Varray<T2> &tgtArray, const RemapVars &rv, const Varray<T1> &s for (size_t i = 0; i < nlinks; ++i) { auto noff = i * 3; - auto s = &srcIndices[noff]; - auto w = &weights[noff]; + const auto s = &srcIndices[noff]; + const auto w = &weights[noff]; auto tgtPoint = srcArray[s[0]] * w[0] + srcArray[s[1]] * w[1] + srcArray[s[2]] * w[2]; tgtArray[tgtIndices[noff]] = tgtPoint; } @@ -79,8 +79,8 @@ remap_first_order(Varray<T2> &tgtArray, const RemapVars &rv, const Varray<T1> &s for (size_t i = 0; i < nlinks; ++i) { auto noff = i * 4; - auto s = &srcIndices[noff]; - auto w = &weights[noff]; + const auto s = &srcIndices[noff]; + const auto w = &weights[noff]; auto tgtPoint = srcArray[s[0]] * w[0] + srcArray[s[1]] * w[1] + srcArray[s[2]] * w[2] + srcArray[s[3]] * w[3]; tgtArray[tgtIndices[noff]] = tgtPoint; } @@ -93,8 +93,8 @@ remap_first_order(Varray<T2> &tgtArray, const RemapVars &rv, const Varray<T1> &s for (size_t i = 0; i < nlinks; ++i) { auto noff = i * linksPerValue; - auto s = &srcIndices[noff]; - auto w = &weights[noff]; + const auto s = &srcIndices[noff]; + const auto w = &weights[noff]; auto tgtPoint = srcArray[s[0]] * w[0]; for (size_t k = 1; k < (size_t) linksPerValue; ++k) tgtPoint += srcArray[s[k]] * w[k]; tgtArray[tgtIndices[noff]] = tgtPoint; @@ -149,7 +149,7 @@ remap_second_order(Varray<T2> &tgtArray, const RemapVars &rv, const Varray<T1> & { auto noff = i * 4 + k; auto ik = srcIndices[noff]; - auto w = &weights[numWeights * noff]; + const auto w = &weights[numWeights * noff]; tgtPoint += srcArray[ik] * w[0] + grad1[ik] * w[1] + grad2[ik] * w[2] + grad3[ik] * w[3]; } tgtArray[tgtIndices[i * 4]] = tgtPoint; @@ -161,7 +161,7 @@ remap_second_order(Varray<T2> &tgtArray, const RemapVars &rv, const Varray<T1> & for (size_t i = 0; i < numLinks; ++i) { auto k = srcIndices[i]; - auto w = &weights[4 * i]; + const auto w = &weights[4 * i]; tgtArray[tgtIndices[i]] += srcArray[k] * w[0] + grad1[k] * w[1] + grad2[k] * w[2] + grad3[k] * w[3]; } } diff --git a/src/sellist.cc b/src/sellist.cc index 0d0b906a2..5c7c84453 100644 --- a/src/sellist.cc +++ b/src/sellist.cc @@ -197,7 +197,7 @@ selinfo_check(SelectInfo &selInfo, int listIdx, void *par) { case SelType::INT: { - int ival = *(int *) par; + int ival = *static_cast<int *>(par); for (int i = 0; i < nvalues; ++i) { if (ival == e.ivalues[i]) @@ -210,7 +210,7 @@ selinfo_check(SelectInfo &selInfo, int listIdx, void *par) } case SelType::FLT: { - const double dval = *(double *) par; + const double dval = *static_cast<double *>(par); for (int i = 0; i < nvalues; ++i) { if (std::fabs(dval - e.dvalues[i]) < 1.e-4) @@ -223,7 +223,7 @@ selinfo_check(SelectInfo &selInfo, int listIdx, void *par) } case SelType::WORD: { - const char *cval = *(char **) par; + const char *cval = *static_cast<char **>(par); for (int i = 0; i < nvalues; ++i) { if (wildcardmatch(e.cvalues[i], cval) == 0) @@ -342,8 +342,11 @@ selinfo_def_flag(SelectInfo &selInfo, int listIdx, int valIdx, bool flag) auto nvalues = selInfo.nvalues(listIdx); if (nvalues) { - auto &e = selList[listIdx]; - if (valIdx >= 0 && valIdx < nvalues) e.flag[valIdx] = flag; + if (valIdx >= 0 && valIdx < nvalues) + { + auto &e = selList[listIdx]; + e.flag[valIdx] = flag; + } } } @@ -359,9 +362,9 @@ selinfo_get_val(const SelectInfo &selInfo, int listIdx, int valIdx, void *val) const auto &e = selList[listIdx]; switch (e.type) { - case SelType::INT: *(int *) val = e.ivalues[valIdx]; break; - case SelType::FLT: *(double *) val = e.dvalues[valIdx]; break; - case SelType::WORD: *(const char **) val = e.cvalues[valIdx]; break; + case SelType::INT: *static_cast<int *>(val) = e.ivalues[valIdx]; break; + case SelType::FLT: *static_cast<double *>(val) = e.dvalues[valIdx]; break; + case SelType::WORD: *static_cast<const char **>(val) = e.cvalues[valIdx]; break; case SelType::UNDEF: break; } } @@ -379,9 +382,9 @@ selinfo_def_val(SelectInfo &selInfo, int listIdx, int valIdx, void *val) auto &e = selList[listIdx]; switch (e.type) { - case SelType::INT: e.ivalues[valIdx] = *(int *) val; break; - case SelType::FLT: e.dvalues[valIdx] = *(double *) val; break; - case SelType::WORD: e.cvalues[valIdx] = *(const char **) val; break; + case SelType::INT: e.ivalues[valIdx] = *static_cast<int *>(val); break; + case SelType::FLT: e.dvalues[valIdx] = *static_cast<double *>(val); break; + case SelType::WORD: e.cvalues[valIdx] = *static_cast<char **>(val); break; case SelType::UNDEF: break; } } diff --git a/src/specspace.cc b/src/specspace.cc index dd5338bb1..ea33b9ac7 100644 --- a/src/specspace.cc +++ b/src/specspace.cc @@ -122,7 +122,7 @@ spec2spec(int gridIDin, const Varray<double> &arrayIn, int gridIDout, Varray<dou } void -speccut(int gridIDin, const Varray<double> &arrayIn, Varray<double> &arrayOut, Varray<int> &waves) +speccut(int gridIDin, const Varray<double> &arrayIn, Varray<double> &arrayOut, const Varray<int> &waves) { long ntr = gridInqTrunc(gridIDin); @@ -130,7 +130,8 @@ speccut(int gridIDin, const Varray<double> &arrayIn, Varray<double> &arrayOut, V } void -trans_uv2dv(const SP_Transformation &spTrans, long nlev, int gridID1, double *gu, double *gv, int gridID2, double *sd, double *svo) +trans_uv2dv(const SP_Transformation &spTrans, long nlev, int gridID1, const double *gu, const double *gv, int gridID2, double *sd, + double *svo) { if (gridInqType(gridID1) != GRID_GAUSSIAN) cdo_abort("unexpected grid1 type: %s instead of Gaussian", gridNamePtr(gridInqType(gridID1))); @@ -166,8 +167,8 @@ trans_uv2dv(const SP_Transformation &spTrans, long nlev, int gridID1, double *gu } void -trans_dv2uv(const SP_Transformation &spTrans, const DV_Transformation &dvTrans, long nlev, int gridID1, double *sd, double *svo, - int gridID2, double *gu, double *gv) +trans_dv2uv(const SP_Transformation &spTrans, const DV_Transformation &dvTrans, long nlev, int gridID1, const double *sd, + const double *svo, int gridID2, double *gu, double *gv) { if (gridInqType(gridID1) != GRID_SPECTRAL) cdo_warning("unexpected grid1 type: %s instead of spectral", gridNamePtr(gridInqType(gridID1))); diff --git a/src/specspace.h b/src/specspace.h index ece06c863..800c16ecd 100644 --- a/src/specspace.h +++ b/src/specspace.h @@ -167,11 +167,11 @@ public: void dv2ps(const double *div, double *pot, long nlev, long ntr); -void trans_uv2dv(const SP_Transformation &spTrans, long nlev, int gridID1, double *gu, double *gv, int gridID2, double *sd, - double *svo); +void trans_uv2dv(const SP_Transformation &spTrans, long nlev, int gridID1, const double *gu, const double *gv, int gridID2, + double *sd, double *svo); -void trans_dv2uv(const SP_Transformation &spTrans, const DV_Transformation &dvTrans, long nlev, int gridID1, double *sd, - double *svo, int gridID2, double *gu, double *gv); +void trans_dv2uv(const SP_Transformation &spTrans, const DV_Transformation &dvTrans, long nlev, int gridID1, const double *sd, + const double *svo, int gridID2, double *gu, double *gv); void grid2spec(const SP_Transformation &spTrans, int gridIDin, const Varray<double> &arrayIn, int gridIDout, Varray<double> &arrayOut); @@ -187,7 +187,7 @@ void grid2four(const FC_Transformation &fcTrans, int gridIDin, const Varray<doub Varray<double> &arrayOut); void spec2spec(int gridIDin, const Varray<double> &arrayIn, int gridIDout, Varray<double> &arrayOut); -void speccut(int gridIDin, const Varray<double> &arrayIn, Varray<double> &arrayOut, Varray<int> &waves); +void speccut(int gridIDin, const Varray<double> &arrayIn, Varray<double> &arrayOut, const Varray<int> &waves); void spcut(const double *arrayIn, double *arrayOut, long ntr, const int *waves); -- GitLab