From 5b5a1c8fd1282a543fc0902548d35eedcd0f7aa7 Mon Sep 17 00:00:00 2001 From: Michael Uleysky Date: Mon, 11 Nov 2024 05:50:13 +1000 Subject: [PATCH] Fixed some clang warnings --- include/ncfilew.h | 70 ++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/include/ncfilew.h b/include/ncfilew.h index 02594b8..1576b3b 100644 --- a/include/ncfilew.h +++ b/include/ncfilew.h @@ -280,9 +280,7 @@ class NCFileWBase template requires requires(int nc, int vid, const T* d) { - { - NCTypeD::put_var(nc, vid, d) - } -> std::same_as; + { NCTypeD::put_var(nc, vid, d) } -> std::same_as; } void WriteVar(const MString& vname, const T* data) { @@ -297,9 +295,7 @@ class NCFileWBase template requires requires(int nc, int vid, const size_t* start, const size_t* count, const T* d) { - { - NCTypeD::put_vara(nc, vid, start, count, d) - } -> std::same_as; + { NCTypeD::put_vara(nc, vid, start, count, d) } -> std::same_as; } void WriteVar(const MString& vname, size_t ind, const T* data) { @@ -421,24 +417,24 @@ class NCFileW: public NCFileWBase if constexpr(Is1DType(dtype)) { - const size_t c = data.N(); - float buf[c]; + const size_t c = data.N(); + auto buf = std::make_unique(c); for(size_t ix = 0; ix < c; ix++) buf[ix] = data.IsFill(ix) ? fill : op(ix); if(tdep) - WriteVar(name, tind, buf); + WriteVar(name, tind, buf.get()); else - WriteVar(name, buf); + WriteVar(name, buf.get()); } else { const size_t c[2] = {data.Ny(), data.Nx()}; - float buf[c[0] * c[1]]; + auto buf = std::make_unique(c[0] * c[1]); for(size_t iy = 0; iy < c[0]; iy++) for(size_t ix = 0; ix < c[1]; ix++) buf[iy * c[1] + ix] = data.IsFill(ix, iy) ? fill : op(ix, iy); if(tdep) - WriteVar(name, tind, buf); + WriteVar(name, tind, buf.get()); else - WriteVar(name, buf); + WriteVar(name, buf.get()); } if(!*this) return "Can't write variable " + name + ": " + ErrMessage(); @@ -449,11 +445,9 @@ class NCFileW: public NCFileWBase template MString WriteVariable(const D& data, const MString& name, size_t tind) { if constexpr(Is1DType(DetType())) - return WriteVariable( - data, name, [&data = std::as_const(data)](size_t i) { return data(i); }, tind); + return WriteVariable(data, name, [&data = std::as_const(data)](size_t i) { return data(i); }, tind); else - return WriteVariable( - data, name, [&data = std::as_const(data)](size_t i, size_t j) { return data(i, j); }, tind); + return WriteVariable(data, name, [&data = std::as_const(data)](size_t i, size_t j) { return data(i, j); }, tind); } template @@ -489,64 +483,64 @@ class NCFileW: public NCFileWBase } else if constexpr(dtype == GPSET) { - const size_t c = data.N(); - float bufx[c]; - float bufy[c]; + const size_t c = data.N(); + auto bufx = std::make_unique(c); + auto bufy = std::make_unique(c); for(size_t ix = 0; ix < c; ix++) { bufx[ix] = data.Lon(ix); bufy[ix] = data.Lat(ix); } - WriteVar("longitude", bufx); - WriteVar("latitude", bufy); + WriteVar("longitude", bufx.get()); + WriteVar("latitude", bufy.get()); } else if constexpr(dtype == RGRID) { const size_t cx = data.Nx(), cy = data.Ny(); - float bufx[cx]; - float bufy[cy]; + auto bufx = std::make_unique(cx); + auto bufy = std::make_unique(cy); for(size_t ix = 0; ix < cx; ix++) bufx[ix] = data.Ix2X(ix); for(size_t iy = 0; iy < cy; iy++) bufy[iy] = data.Iy2Y(iy); - WriteVar("x", bufx); - WriteVar("y", bufy); + WriteVar("x", bufx.get()); + WriteVar("y", bufy.get()); } else if constexpr(dtype == GRGRID) { const size_t cx = data.Nx(), cy = data.Ny(); - float bufx[cx]; - float bufy[cy]; + auto bufx = std::make_unique(cx); + auto bufy = std::make_unique(cy); for(size_t ix = 0; ix < cx; ix++) bufx[ix] = data.Ix2Lon(ix); for(size_t iy = 0; iy < cy; iy++) bufy[iy] = data.Iy2Lat(iy); - WriteVar("longitude", bufx); - WriteVar("latitude", bufy); + WriteVar("longitude", bufx.get()); + WriteVar("latitude", bufy.get()); } else if constexpr(dtype == GRID) { const size_t c[2] = {data.Ny(), data.Nx()}; - float bufx[c[0] * c[1]]; - float bufy[c[0] * c[1]]; + auto bufx = std::make_unique(c[0] * c[1]); + auto bufy = std::make_unique(c[0] * c[1]); for(size_t iy = 0; iy < c[0]; iy++) for(size_t ix = 0; ix < c[1]; ix++) { bufx[iy * c[1] + ix] = data.X(ix, iy); bufy[iy * c[1] + ix] = data.Y(ix, iy); } - WriteVar("x", bufx); - WriteVar("y", bufy); + WriteVar("x", bufx.get()); + WriteVar("y", bufy.get()); } else if constexpr(dtype == GGRID) { const size_t c[2] = {data.Ny(), data.Nx()}; - float bufx[c[0] * c[1]]; - float bufy[c[0] * c[1]]; + auto bufx = std::make_unique(c[0] * c[1]); + auto bufy = std::make_unique(c[0] * c[1]); for(size_t iy = 0; iy < c[0]; iy++) for(size_t ix = 0; ix < c[1]; ix++) { bufx[iy * c[1] + ix] = data.Lon(ix, iy); bufy[iy * c[1] + ix] = data.Lat(ix, iy); } - WriteVar("longitude", bufx); - WriteVar("latitude", bufy); + WriteVar("longitude", bufx.get()); + WriteVar("latitude", bufy.get()); } else return "Unknown data type";