diff --git a/src/mir/key/style/ECMWFStyle.cc b/src/mir/key/style/ECMWFStyle.cc index be9ae1b51..001d64e90 100644 --- a/src/mir/key/style/ECMWFStyle.cc +++ b/src/mir/key/style/ECMWFStyle.cc @@ -270,8 +270,13 @@ void ECMWFStyle::sh2grid(action::ActionPlan& plan) const { bool vod2uv = option(user, "vod2uv", false); bool uv2uv = option(user, "uv2uv", false) || uv_input; // where "MIR knowledge of winds" is hardcoded - if (vod2uv && uv_input) { - throw exception::UserError("ECMWFStyle: option 'vod2uv' is incompatible with input U/V"); + if (vod2uv) { + if (uv2uv) { + throw exception::UserError("ECMWFStyle: option 'vod2uv' is incompatible with 'uv2uv'"); + } + if (uv_input) { + throw exception::UserError("ECMWFStyle: option 'vod2uv' is incompatible with input U/V"); + } } if (resol.resultIsSpectral()) { @@ -281,29 +286,31 @@ void ECMWFStyle::sh2grid(action::ActionPlan& plan) const { auto target = target_gridded_from_parametrisation(parametrisation_, false); if (!target.empty()) { if (resol.resultIsSpectral()) { - plan.add("transform." + std::string(vod2uv ? "sh-vod-to-uv-" : "sh-scalar-to-") + target); + + if (uv2uv) { + plan.add("filter.adjust-winds-scale-cos-latitude"); + } + + if ((vod2uv || uv2uv) && rotation) { + plan.add("filter.adjust-winds-directions"); + } } else { - resol.prepare(plan); + if (uv2uv) { + plan.add("filter.adjust-winds-scale-cos-latitude"); + } + // if the intermediate grid is the same as the target grid, the interpolation to the // intermediate grid is not followed by an additional interpolation std::string grid; if (rotation || !user.get("grid", grid) || grid != resol.gridname()) { plan.add("interpolate.grid2" + target); } - } - - if (vod2uv || uv2uv) { - ASSERT(vod2uv != uv2uv); - - if (uv2uv) { - plan.add("filter.adjust-winds-scale-cos-latitude"); - } - if (rotation) { + if ((vod2uv || uv2uv) && rotation) { plan.add("filter.adjust-winds-directions"); } } diff --git a/src/mir/repres/regular/Lambert.cc b/src/mir/repres/regular/Lambert.cc index 94968a4ed..10527a044 100644 --- a/src/mir/repres/regular/Lambert.cc +++ b/src/mir/repres/regular/Lambert.cc @@ -12,8 +12,6 @@ #include "mir/repres/regular/Lambert.h" -#include - #include "mir/param/MIRParametrisation.h" #include "mir/util/Angles.h" #include "mir/util/Exceptions.h" @@ -88,8 +86,8 @@ void Lambert::fillGrib(grib_info& info) const { info.grid.longitudeOfSouthernPoleInDegrees = longitudeOfSouthernPoleInDegrees_; info.grid.uvRelativeToGrid = uvRelativeToGrid_ ? 1 : 0; - info.extra_set("DxInMetres", std::abs(x().step())); - info.extra_set("DyInMetres", std::abs(y().step())); + info.extra_set("DxInMetres", x().step()); + info.extra_set("DyInMetres", y().step()); info.extra_set("Latin1InDegrees", reference[LLCOORDS::LAT]); info.extra_set("Latin2InDegrees", reference[LLCOORDS::LAT]); info.extra_set("LoVInDegrees", writeLonPositive_ ? util::normalise_longitude(reference[LLCOORDS::LON], 0) diff --git a/src/mir/util/Shape.cc b/src/mir/util/Shape.cc index ea16bee55..bcae379de 100644 --- a/src/mir/util/Shape.cc +++ b/src/mir/util/Shape.cc @@ -19,8 +19,6 @@ namespace mir::util { Shape::Shape(const param::MIRParametrisation& param) { - param.get("edition", edition = 0); - provided = param.get("shapeOfTheEarth", code = 6); bool isOblate = false; @@ -30,7 +28,7 @@ Shape::Shape(const param::MIRParametrisation& param) { } -Shape::Shape(const Projection::Spec& spec) : edition(0) { +Shape::Shape(const Projection::Spec& spec) { if (spec.has("radius")) { code = 1L; a = b = spec.getDouble("radius"); @@ -58,6 +56,17 @@ Shape& Shape::operator=(const Shape&) = default; void Shape::fillGrib(grib_info& info, const Projection::Spec& spec) const { // GRIB2 encoding of user-provided shape + long edition = info.packing.editionNumber; + + const std::string EDITION("edition"); + for (size_t j = 0; j < info.packing.extra_settings_count; ++j) { + auto& set = info.packing.extra_settings[j]; + if (set.name == EDITION && set.type == CODES_TYPE_LONG) { + edition = set.long_value; + break; + } + } + if (edition != 2) { return; } diff --git a/src/mir/util/Shape.h b/src/mir/util/Shape.h index a538bd1d6..fc916b2b8 100644 --- a/src/mir/util/Shape.h +++ b/src/mir/util/Shape.h @@ -39,7 +39,6 @@ struct Shape { long code; double a; double b; - long edition; bool provided; };