Skip to content

Commit

Permalink
Merge branch 'feature/netcdf-fixes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaciel committed Nov 23, 2024
2 parents 0379d79 + 1970543 commit 598d2b9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
14 changes: 1 addition & 13 deletions src/mir/netcdf/Codec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,10 @@ Codec* CodecFactory::build(const std::string& name, const Variable& variable) {

Log::debug() << "CodecFactory: looking for '" << name << "'" << std::endl;

if (auto j = m->find(name); j == m->end()) {
if (auto j = m->find(name); j != m->end()) {
return j->second->make(variable);
}

auto trim = [](const std::string& str, const std::string& trimmable) -> std::string {
size_t first = str.find_first_not_of(trimmable);
size_t last = str.find_last_not_of(trimmable);

return first == std::string::npos || last == 0 ? "" : str.substr(first, last - first + 1);
};

if (auto name_trimmed = trim(name, " \t\n\r\f\v"); name_trimmed != name) {
Log::warning() << "CodecFactory: looking for (trimmed) '" << name << "'" << std::endl;
return build(name_trimmed, variable);
}

list(Log::error() << "CodecFactory: unknown '" << name << "', choices are: ");
throw exception::SeriousBug("CodecFactory: unknown '" + name + "'");
}
Expand Down
11 changes: 4 additions & 7 deletions src/mir/netcdf/DataInputVariable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ void DataInputVariable::get2DValues(MIRValuesVector& values, size_t index) const
dims.pop_back();

std::vector<size_t> coords(dims.size());
for (int i = int(dims.size()) - 1; i >= 0; i--) {
auto j = size_t(i);
for (int i = static_cast<int>(dims.size()) - 1; i >= 0; i--) {
auto j = static_cast<size_t>(i);
coords[j] = (index % dims[j]);
index /= dims[j];
}
Expand All @@ -139,11 +139,8 @@ void DataInputVariable::get2DValues(MIRValuesVector& values, size_t index) const
start[j] = coords[j];
}

std::vector<double> data(nx * ny);
matrix_->read(data, start, count);

// FIXME: this copies, so is slow, but we could 'move' data instead
values.assign(data.begin(), data.end());
values.resize(nx * ny);
matrix_->read(values, start, count);
}


Expand Down
3 changes: 1 addition & 2 deletions src/mir/netcdf/Type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "mir/netcdf/Type.h"

#include <algorithm>
#include <cstring>
#include <ostream>
#include <vector>

Expand Down Expand Up @@ -416,7 +415,7 @@ Value* TypeT<std::string>::attributeValue(int nc, int id, const char* name, size

std::string value(len + 1, '\0');
NC_CALL(nc_get_att_text(nc, id, name, value.data()), path);
auto* v = new ValueT<std::string>(*this, value);
auto* v = new ValueT<std::string>(*this, value.data());
return v;
}

Expand Down

0 comments on commit 598d2b9

Please sign in to comment.