From a73f2eb96e7bd25221b6bd844ad87d84e1d65163 Mon Sep 17 00:00:00 2001 From: Baudouin Raoult Date: Mon, 13 Dec 2021 07:41:39 +0000 Subject: [PATCH] Better error message --- .vscode/settings.json | 4 +++- src/decoders/NetcdfData.cc | 12 ++++++------ src/decoders/NetcdfData.h | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index ae489949..3a3390c6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,11 +2,13 @@ "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", "cmake.configureOnOpen": false, "files.associations": { + "*.make": "makefile", "vector": "cpp", "utility": "cpp", "ostream": "cpp", "iostream": "cpp", "map": "cpp", - "iosfwd": "cpp" + "iosfwd": "cpp", + "filesystem": "cpp" } } diff --git a/src/decoders/NetcdfData.cc b/src/decoders/NetcdfData.cc index 5c1a4c42..5466f8fa 100644 --- a/src/decoders/NetcdfData.cc +++ b/src/decoders/NetcdfData.cc @@ -53,14 +53,14 @@ void TypedAccessor::operator()(vector& to, vector& start, vecto std::transform(from.begin(), from.begin() + to.size(), to.begin(), Convertor(var)); // for (auto x = start.begin(); x != start.end(); ++x) { cout << "start " << *x << endl; } // for (auto x = edges.begin(); x != edges.end(); ++x) { cout << "edges " << *x << endl; } - + } template void TypedAccessor::get(vector& from, vector& start, vector& edges, NetVariable& var) const { var.get(&from.front(), start, edges); - - + + } Netcdf::Netcdf(const string& path, const string& method) : file_(-1) { @@ -68,7 +68,7 @@ Netcdf::Netcdf(const string& path, const string& method) : file_(-1) { if (status != NC_NOERR) { fprintf(stderr, "ERROR while opening NetCDF file - %s\n", nc_strerror(status)); - throw NoSuchNetcdfFile(path); + throw NoSuchNetcdfFile(path, nc_strerror(status)); } int num_var; @@ -157,11 +157,11 @@ int NetDimension::index(const string& val) { } int NetDimension::value(const string& val) { - + if (variable_ != -1) { // int index = Index::get(variable_->type(), val, variable_->values(), variable_->num_vals()); NetVariable var(name_, variable_, parent_, "index"); - + return var.find(val); } diff --git a/src/decoders/NetcdfData.h b/src/decoders/NetcdfData.h index e9372827..27f9abe3 100644 --- a/src/decoders/NetcdfData.h +++ b/src/decoders/NetcdfData.h @@ -47,8 +47,8 @@ class NoSuchNetcdfDimension : public MagicsException { class NoSuchNetcdfFile : public MagicsException { public: - NoSuchNetcdfFile(const string& file) : - MagicsException("Netcdf MagException: The file " + file + " does not exist or is not a valid netcdf file") { + NoSuchNetcdfFile(const string& file, const string& why) : + MagicsException("Netcdf MagException: Cannot open " + file + ": " + why) { MagLog::error() << what() << "\n"; } };