Skip to content

Commit

Permalink
Magics : grib_file_address_mode="byte_offset" not working for large f…
Browse files Browse the repository at this point in the history
…iles [MAGP-1357]

Advanced wind plotting hangs when no values found above min speed[MAGP-1355]
  • Loading branch information
sylvielamythepaut committed Apr 17, 2023
1 parent 6e1a57c commit 225e960
Show file tree
Hide file tree
Showing 21 changed files with 263 additions and 25 deletions.
18 changes: 18 additions & 0 deletions src/api/MagicsCalls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,20 @@ const char* MagicsCalls::metainput() {
const char* MagicsCalls::metanetcdf() {
return FortranMagics::instance().metanetcdf();
}
const char* MagicsCalls::long_parameters() {
static string result;
ostringstream os;
os << "{";
os << "\"grib_field_position\": \"grib_field_large_position\",";
os << "\"grib_wind_position_1\": \"grib_wind_large_position_1\",";
os << "\"grib_wind_position_2\": \"grib_wind_large_position_2\",";
os << "\"grib_wind_position_colour\": \"grib_wind_large_position_colour\"";
os << "}";
result = os.str();
return result.c_str();


}
const char* MagicsCalls::keep_compatibility() {
NOTIMP;
}
Expand Down Expand Up @@ -385,6 +398,11 @@ void MagicsCalls::seti(const std::string& name, int value) {
ParameterManager::set(name, value);
}

void MagicsCalls::setli(const std::string& name, unsigned long long value) {
// if (CompatibilityHelper::check(name, value))
// return;
ParameterManager::set(name, value);
}

void MagicsCalls::set1i(const std::string& name, const std::vector<int>& data) {
set1i(name, data.data(), data.size());
Expand Down
2 changes: 2 additions & 0 deletions src/api/MagicsCalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class MagicsCalls {
static const char* metainput();
static const char* metanetcdf();
static const char* keep_compatibility();
static const char* long_parameters();

// =================================================================
static void axis();
Expand Down Expand Up @@ -82,6 +83,7 @@ class MagicsCalls {
static void set1c(const std::string& name, const std::vector<std::string>& data);

static void seti(const std::string& name, int value);
static void setli(const std::string& name, unsigned long long value);
static void set1i(const std::string& name, const int* data, const int dim1);
static void set1i(const std::string& name, const std::vector<int>& data);
static void set2i(const std::string& name, const int* data, const int dim1, const int dim2);
Expand Down
6 changes: 5 additions & 1 deletion src/api/MagicsCallsPython.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ PYTHON_VOID(tile)
PYTHON_VOID(unmute) // TODO: review name
PYTHON_VOID(wind)
PYTHON_VOID(wrepjson)

PYTHON_CHAR(long_parameters)
PYTHON_CHAR(knowndrivers) // TODO: review name
PYTHON_CHAR(metagrib) // TODO: review name
PYTHON_CHAR(metainput) // TODO: review name
Expand Down Expand Up @@ -193,6 +193,10 @@ MAGICS_EXPORT const char* py_seti(const char* name, const int value) {
return python_void("seti", [name, value] { MagicsCalls::seti(name, value); });
}

MAGICS_EXPORT const char* py_setli(const char* name, const unsigned long long value) {
return python_void("setli", [name, value] { MagicsCalls::setli(name, value); });
}

MAGICS_EXPORT const char* py_set1r(const char* name, const double* data, const int dim1) {
return python_void("set1r", [name, data, dim1] { MagicsCalls::set1r(name, data, dim1); });
}
Expand Down
2 changes: 2 additions & 0 deletions src/api/py_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ MAGICS_EXPORT const char* py_import();
MAGICS_EXPORT const char* py_input();
MAGICS_EXPORT const char* py_keep_compatibility();
MAGICS_EXPORT const char* py_knowndrivers();
MAGICS_EXPORT const char* py_long_parameters();
MAGICS_EXPORT const char* py_legend();
MAGICS_EXPORT const char* py_line();
MAGICS_EXPORT const char* py_mapgen();
Expand Down Expand Up @@ -50,6 +51,7 @@ MAGICS_EXPORT const char* py_reset(const char* name);
MAGICS_EXPORT const char* py_setc(const char* name, const char* value);
MAGICS_EXPORT const char* py_setr(const char* name, const double value);
MAGICS_EXPORT const char* py_seti(const char* name, const int value);
MAGICS_EXPORT const char* py_setli(const char* name, const unsigned long long value);
MAGICS_EXPORT const char* py_set1r(const char* name, const double* data, const int dim1);
MAGICS_EXPORT const char* py_set2r(const char* name, const double* data, const int dim1, const int dim2);
MAGICS_EXPORT const char* py_set1i(const char* name, const int* data, const int dim1);
Expand Down
28 changes: 28 additions & 0 deletions src/attributes/GribDecoderAttributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ GribDecoderAttributes::GribDecoderAttributes():
expver_(ParameterManager::getBool("grib_text_experiment")),
units_(ParameterManager::getBool("grib_text_units")),
field_position_(ParameterManager::getInt("grib_field_position")),
large_field_position_(ParameterManager::getULong("grib_field_large_position")),
position_1_(ParameterManager::getInt("grib_wind_position_1")),
position_2_(ParameterManager::getInt("grib_wind_position_2")),
colour_position_(ParameterManager::getInt("grib_wind_position_colour")),
large_position_1_(ParameterManager::getULong("grib_wind_large_position_1")),
large_position_2_(ParameterManager::getULong("grib_wind_large_position_2")),
large_colour_position_(ParameterManager::getULong("grib_wind_large_position_colour")),
missing_value_(ParameterManager::getDouble("grib_missing_value_indicator")),
wind_style_(ParameterManager::getBool("grib_wind_style"))
,
Expand Down Expand Up @@ -83,9 +87,13 @@ void GribDecoderAttributes::set(const std::map<string, string>& params)
setAttribute(prefix, "grib_text_experiment", expver_, params);
setAttribute(prefix, "grib_text_units", units_, params);
setAttribute(prefix, "grib_field_position", field_position_, params);
setAttribute(prefix, "grib_field_large_position", large_field_position_, params);
setAttribute(prefix, "grib_wind_position_1", position_1_, params);
setAttribute(prefix, "grib_wind_position_2", position_2_, params);
setAttribute(prefix, "grib_wind_position_colour", colour_position_, params);
setAttribute(prefix, "grib_wind_large_position_1", large_position_1_, params);
setAttribute(prefix, "grib_wind_large_position_2", large_position_2_, params);
setAttribute(prefix, "grib_wind_large_position_colour", large_colour_position_, params);
setAttribute(prefix, "grib_missing_value_indicator", missing_value_, params);
setAttribute(prefix, "grib_wind_style", wind_style_, params);

Expand All @@ -112,9 +120,13 @@ void GribDecoderAttributes::copy(const GribDecoderAttributes& other)
expver_ = other.expver_;
units_ = other.units_;
field_position_ = other.field_position_;
large_field_position_ = other.large_field_position_;
position_1_ = other.position_1_;
position_2_ = other.position_2_;
colour_position_ = other.colour_position_;
large_position_1_ = other.large_position_1_;
large_position_2_ = other.large_position_2_;
large_colour_position_ = other.large_colour_position_;
missing_value_ = other.missing_value_;
wind_style_ = other.wind_style_;
address_mode_ = unique_ptr<GribAddressMode>(other.address_mode_->clone());
Expand Down Expand Up @@ -181,9 +193,13 @@ void GribDecoderAttributes::print(ostream& out) const
out << " expver = " << expver_;
out << " units = " << units_;
out << " field_position = " << field_position_;
out << " large_field_position = " << large_field_position_;
out << " position_1 = " << position_1_;
out << " position_2 = " << position_2_;
out << " colour_position = " << colour_position_;
out << " large_position_1 = " << large_position_1_;
out << " large_position_2 = " << large_position_2_;
out << " large_colour_position = " << large_colour_position_;
out << " missing_value = " << missing_value_;
out << " wind_style = " << wind_style_;
out << " address_mode = " << *address_mode_;
Expand Down Expand Up @@ -227,12 +243,20 @@ void GribDecoderAttributes::toxml(ostream& out) const
niceprint(out,units_);
out << ", \"grib_field_position\":";
niceprint(out,field_position_);
out << ", \"grib_field_large_position\":";
niceprint(out,large_field_position_);
out << ", \"grib_wind_position_1\":";
niceprint(out,position_1_);
out << ", \"grib_wind_position_2\":";
niceprint(out,position_2_);
out << ", \"grib_wind_position_colour\":";
niceprint(out,colour_position_);
out << ", \"grib_wind_large_position_1\":";
niceprint(out,large_position_1_);
out << ", \"grib_wind_large_position_2\":";
niceprint(out,large_position_2_);
out << ", \"grib_wind_large_position_colour\":";
niceprint(out,large_colour_position_);
out << ", \"grib_missing_value_indicator\":";
niceprint(out,missing_value_);
out << ", \"grib_wind_style\":";
Expand Down Expand Up @@ -260,9 +284,13 @@ static MagicsParameter<int> grib_interpolation_method_missing_fill_count("grib_i
static MagicsParameter<string> grib_text_experiment("grib_text_experiment", "off");
static MagicsParameter<string> grib_text_units("grib_text_units", "off");
static MagicsParameter<int> grib_field_position("grib_field_position", 1);
static MagicsParameter<unsigned long long> grib_field_large_position("grib_field_large_position", 0);
static MagicsParameter<int> grib_wind_position_1("grib_wind_position_1", 1);
static MagicsParameter<int> grib_wind_position_2("grib_wind_position_2", -1);
static MagicsParameter<int> grib_wind_position_colour("grib_wind_position_colour", -1);
static MagicsParameter<unsigned long long> grib_wind_large_position_1("grib_wind_large_position_1", 0);
static MagicsParameter<unsigned long long> grib_wind_large_position_2("grib_wind_large_position_2", 0);
static MagicsParameter<unsigned long long> grib_wind_large_position_colour("grib_wind_large_position_colour", 0);
static MagicsParameter<double> grib_missing_value_indicator("grib_missing_value_indicator", -1.5e+21);
static MagicsParameter<string> grib_wind_style("grib_wind_style", "off");
static MagicsParameter<string> grib_file_address_mode("grib_file_address_mode", "record");
Expand Down
4 changes: 4 additions & 0 deletions src/attributes/GribDecoderAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ class GribDecoderAttributes
bool expver_;
bool units_;
int field_position_;
unsigned long long large_field_position_;
int position_1_;
int position_2_;
int colour_position_;
unsigned long long large_position_1_;
unsigned long long large_position_2_;
unsigned long long large_colour_position_;
double missing_value_;
bool wind_style_;
unique_ptr<GribAddressMode> address_mode_;
Expand Down
76 changes: 76 additions & 0 deletions src/attributes/GribDecoderWrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,78 @@ void GribDecoderWrapper::set(const MagRequest& request)
gribdecoder_->wind_mode_ = unique_ptr<WindMode>(wind_mode_wrapper->object());
delete wind_mode_wrapper;

string large_field_position_value = request.countValues("GRIB_FIELD_LARGE_POSITION") ? (string) request("GRIB_FIELD_LARGE_POSITION") : "0";
MagLog::debug() << " GRIB_FIELD_LARGE_POSITION set to " << large_field_position_value << endl;
unsigned long longWrapper* large_field_position_wrapper = 0;
try
{
large_field_position_wrapper = SimpleFactory<unsigned long longWrapper>::create(large_field_position_value);
}
catch (NoFactoryException&) {
if (MagicsGlobal::strict()) {
throw;
}
MagLog::warning() << "[" << large_field_position_value << "] is not a valid value for large_field_position: reset to default -> [0]" << endl;
large_field_position_wrapper = SimpleFactory<unsigned long longWrapper>::create("0");
}
large_field_position_wrapper->set(request);
gribdecoder_->large_field_position_ = unique_ptr<unsigned long long>(large_field_position_wrapper->object());
delete large_field_position_wrapper;

string large_position_1_value = request.countValues("GRIB_WIND_LARGE_POSITION_1") ? (string) request("GRIB_WIND_LARGE_POSITION_1") : "0";
MagLog::debug() << " GRIB_WIND_LARGE_POSITION_1 set to " << large_position_1_value << endl;
unsigned long longWrapper* large_position_1_wrapper = 0;
try
{
large_position_1_wrapper = SimpleFactory<unsigned long longWrapper>::create(large_position_1_value);
}
catch (NoFactoryException&) {
if (MagicsGlobal::strict()) {
throw;
}
MagLog::warning() << "[" << large_position_1_value << "] is not a valid value for large_position_1: reset to default -> [0]" << endl;
large_position_1_wrapper = SimpleFactory<unsigned long longWrapper>::create("0");
}
large_position_1_wrapper->set(request);
gribdecoder_->large_position_1_ = unique_ptr<unsigned long long>(large_position_1_wrapper->object());
delete large_position_1_wrapper;

string large_position_2_value = request.countValues("GRIB_WIND_LARGE_POSITION_2") ? (string) request("GRIB_WIND_LARGE_POSITION_2") : "0";
MagLog::debug() << " GRIB_WIND_LARGE_POSITION_2 set to " << large_position_2_value << endl;
unsigned long longWrapper* large_position_2_wrapper = 0;
try
{
large_position_2_wrapper = SimpleFactory<unsigned long longWrapper>::create(large_position_2_value);
}
catch (NoFactoryException&) {
if (MagicsGlobal::strict()) {
throw;
}
MagLog::warning() << "[" << large_position_2_value << "] is not a valid value for large_position_2: reset to default -> [0]" << endl;
large_position_2_wrapper = SimpleFactory<unsigned long longWrapper>::create("0");
}
large_position_2_wrapper->set(request);
gribdecoder_->large_position_2_ = unique_ptr<unsigned long long>(large_position_2_wrapper->object());
delete large_position_2_wrapper;

string large_colour_position_value = request.countValues("GRIB_WIND_LARGE_POSITION_COLOUR") ? (string) request("GRIB_WIND_LARGE_POSITION_COLOUR") : "0";
MagLog::debug() << " GRIB_WIND_LARGE_POSITION_COLOUR set to " << large_colour_position_value << endl;
unsigned long longWrapper* large_colour_position_wrapper = 0;
try
{
large_colour_position_wrapper = SimpleFactory<unsigned long longWrapper>::create(large_colour_position_value);
}
catch (NoFactoryException&) {
if (MagicsGlobal::strict()) {
throw;
}
MagLog::warning() << "[" << large_colour_position_value << "] is not a valid value for large_colour_position: reset to default -> [0]" << endl;
large_colour_position_wrapper = SimpleFactory<unsigned long longWrapper>::create("0");
}
large_colour_position_wrapper->set(request);
gribdecoder_->large_colour_position_ = unique_ptr<unsigned long long>(large_colour_position_wrapper->object());
delete large_colour_position_wrapper;

}

void GribDecoderWrapper::print(ostream& out) const
Expand Down Expand Up @@ -229,3 +301,7 @@ static SimpleObjectMaker<SDWindModeWrapper, WindModeWrapper> GribDecoder_grib_wi







4 changes: 4 additions & 0 deletions src/attributes/GribDecoderWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@

#include "GribAddressModeWrapper.h"
#include "WindModeWrapper.h"
#include "unsigned long longWrapper.h"
#include "unsigned long longWrapper.h"
#include "unsigned long longWrapper.h"
#include "unsigned long longWrapper.h"


namespace magics {
Expand Down
15 changes: 15 additions & 0 deletions src/common/BaseParameter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ void BaseParameter::set(const bool& value) {
throw MistmatchType(name_, getType(value), type());
}

void BaseParameter::get(unsigned long long& value) const {
throw MistmatchType(name_, getType(value), type());
}

void BaseParameter::set(const unsigned long long& value) {
throw MistmatchType(name_, getType(value), type());
}

void BaseParameter::get(bool& value) const {
throw MistmatchType(name_, getType(value), type());
}
Expand Down Expand Up @@ -308,6 +316,13 @@ void BaseParameter::get(Matrix& value) const {
string BaseParameter::getType(const string&) const {
return "string";
}
string BaseParameter::getType(const unsigned long long&) const {
return "unsigned long ";
}

string BaseParameter::getType(const unsigned int&) const {
return "unsigned int ";
}

string BaseParameter::getType(const int&) const {
return "integer";
Expand Down
5 changes: 5 additions & 0 deletions src/common/BaseParameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class BaseParameter {
virtual void set(const int&);
virtual void get(int&) const;

virtual void set(const unsigned long long&);
virtual void get(unsigned long long&) const;

virtual void set(const magvector<int>&);
virtual void get(magvector<int>&) const;

Expand Down Expand Up @@ -104,6 +107,8 @@ class BaseParameter {

string getType(const string&) const;
string getType(const int&) const;
string getType(const unsigned long long&) const;
string getType(const unsigned int&) const;
string getType(const double&) const;
string getType(const magvector<string>&) const;
string getType(const magvector<int>&) const;
Expand Down
23 changes: 23 additions & 0 deletions src/common/MagTranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,29 @@ class MagTranslator<string, int> {
}
};

template <>
class MagTranslator<string, unsigned long long> {
public:
int operator()(const string& value) { return atoll(value.c_str()); }
int magics(const string& param) {
int from;
ParameterManager::get(param, from);
return from;
}
};


template <>
class MagTranslator<unsigned long long, unsigned long long> {
public:
int operator()(unsigned long long& value) { return value; }
int magics(const string& param) {
unsigned long long from;
ParameterManager::get(param, from);
return from;
}
};

template <>
class MagTranslator<int, int> {
public:
Expand Down
6 changes: 6 additions & 0 deletions src/common/ParameterManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ int ParameterManager::getInt(const string& name) {
ASSERT(get(name, value));
return value;
}
unsigned long long ParameterManager::getULong(const string& name) {
unsigned long long value;

ASSERT(get(name, value));
return value;
}

string ParameterManager::getString(const string& name) {
string value;
Expand Down
3 changes: 3 additions & 0 deletions src/common/ParameterManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ParameterManager : public map<string, BaseParameter*> {

template <class T>
static void set(const string& name, const T& value) {

ASSERT(table_);
BaseParameter* param = (*table_).parameter(name);
if (param) {
Expand Down Expand Up @@ -80,6 +81,8 @@ class ParameterManager : public map<string, BaseParameter*> {
static double getDouble(const string& name);

static int getInt(const string& name);
static int getUnsignedInt(const string& name);
static unsigned long long getULong(const string& name);

static string getString(const string& name);
static stringarray getStringArray(const string& name);
Expand Down
Loading

0 comments on commit 225e960

Please sign in to comment.