Skip to content

Commit

Permalink
ECC-1903: Use MTG2SwitchViaTablesVersion instead of datasetForLocal
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramn committed Feb 17, 2025
1 parent 69c5376 commit 57c558d
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 42 deletions.
3 changes: 2 additions & 1 deletion definitions/grib2/MTG2SwitchConcept.def
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Concept defining the MTG2Switch at the top level
-1 = {dummy=0;}

# Can also include a centre in here to have them permanently pre MTG2.
# By default all centres are post MTG2.
0 = {centre=400;}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Concept by which we define which conditions will imply using the tablesVersion
# to switch between pre and post MTG2
1 = {edition=2;}
1 = {true=1;}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This pseudocentre can be permanently on post-MTG2 definitions
1 = {edition=2;}
1 = {true=1;}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This pseudocentre can be permanently on post-MTG2 definitions
1 = {edition=2;}
1 = {true=1;}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Concept by which we define which conditions will imply using the tablesVersion
# to switch between pre and post MTG2
1 = {edition=2;}
1 = {true=1;}
2 changes: 1 addition & 1 deletion definitions/grib2/localConcepts/era/MTG2SwitchConcept.def
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This pseudocentre should remain permanently on pre-MTG2 definitions
0 = {edition=2;}
0 = {true=1;}
2 changes: 1 addition & 1 deletion definitions/grib2/localConcepts/era6/MTG2SwitchConcept.def
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This pseudocentre can be permanently on post-MTG2 definitions
1 = {edition=2;}
1 = {true=1;}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This pseudocentre should remain permanently on pre-MTG2 definitions
0 = {edition=2;}
0 = {true=1;}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This pseudocentre can be permanently on post-MTG2 definitions
1 = {edition=2;}
1 = {true=1;}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Concept by which we define which conditions will imply using the tablesVersion
# to switch between pre and post MTG2
1 = {edition=2;}
1 = {true=1;}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Concept by which we define which conditions will imply using the tablesVersion
# to switch between pre and post MTG2
1 = {edition=2;}
1 = {true=1;}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Concept by which we define which conditions will imply using the tablesVersion
# to switch between pre and post MTG2
1 = {edition=2;}
1 = {true=1;}
4 changes: 2 additions & 2 deletions definitions/grib2/section.4.def
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ concept datasetForLocal(unknown) {
"unknown" = { dummy=1; }
}

#concept MTG2SwitchViaTablesVersion(false, "MTG2SwitchViaTablesVersionConcept.def", conceptsDir2, conceptsDir1): hidden, read_only;
# meta MTG2SwitchDefault mtg2_switch_default(tablesVersion, tablesVersionMTG2Switch, marsClass, datasetForLocal) : hidden, read_only;
concept MTG2SwitchViaTablesVersion(false, "MTG2SwitchViaTablesVersionConcept.def", conceptsDir2, conceptsDir1): hidden, read_only;
meta MTG2SwitchDefault mtg2_switch_default(tablesVersion, tablesVersionMTG2Switch, marsClass, MTG2SwitchViaTablesVersion) : hidden, read_only;

# ECC-2002
# if datasetForLocal is not "unknown", we remap conceptsDir1 and conceptsDir2
Expand Down
32 changes: 5 additions & 27 deletions src/accessor/grib_accessor_class_mtg2_switch_default.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void grib_accessor_mtg2_switch_default_t::init(const long len, grib_arguments* a
tablesVersion_ = arg->get_name(h, 0);
tablesVersionMTG2Switch_ = arg->get_name(h, 1);
marsClass_ = arg->get_name(h, 2);
datasetForLocal_ = arg->get_name(h, 3);
MTG2SwitchViaTablesVersion_ = arg->get_name(h, 3);

length_ = 0;
flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY;
Expand Down Expand Up @@ -68,34 +68,12 @@ int grib_accessor_mtg2_switch_default_t::unpack_long(long* val, size_t* len)
}
}

char datasetForLocal[128] = {0,};
size = sizeof(datasetForLocal);
bool datasetForLocalExists = true;
err = grib_get_string(h, datasetForLocal_, datasetForLocal, &size);
if (err) {
if (err == GRIB_NOT_FOUND) {
// This can happen if accessor is called before section 4
datasetForLocalExists = false;
err = 0;
}
else {
return err;
}
}

long centre = 0;
err = grib_get_long(h, "centre", &centre);
// This is a boolean
long MTG2SwitchViaTablesVersion = 0;
err = grib_get_long(h, MTG2SwitchViaTablesVersion_, &MTG2SwitchViaTablesVersion);
if (err) return err;

bool isSpecialDataset = false;
if (centre == 98) isSpecialDataset = true; // ECMWF
if (datasetForLocalExists) {
if (STR_EQUAL(datasetForLocal, "s2s") || STR_EQUAL(datasetForLocal, "tigge") || STR_EQUAL(datasetForLocal, "uerra")) {
isSpecialDataset = true;
}
}

if (isSpecialDataset) {
if (MTG2SwitchViaTablesVersion) {
if (tablesVersion <= tablesVersionMTG2Switch) {
*val = 0; // Pre-MTG2
}
Expand Down
2 changes: 1 addition & 1 deletion src/accessor/grib_accessor_class_mtg2_switch_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ class grib_accessor_mtg2_switch_default_t : public grib_accessor_long_t
const char* tablesVersion_ = nullptr; // int
const char* tablesVersionMTG2Switch_ = nullptr; // int
const char* marsClass_ = nullptr; // str
const char* datasetForLocal_ = nullptr; // str: e.g. tigge or s2s
const char* MTG2SwitchViaTablesVersion_ = nullptr; //int
};

0 comments on commit 57c558d

Please sign in to comment.