Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/mtg2_tablesVersion_switc…
Browse files Browse the repository at this point in the history
…h' into feature/mtg2_tablesVersion_switch_parameters
  • Loading branch information
mjg41 committed Jan 8, 2025
2 parents b00478e + 0ac2f88 commit a75936c
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 42 deletions.
2 changes: 2 additions & 0 deletions definitions/grib2/localConcepts/s2s/MTG2SwitchConcept.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This pseudocentre should remain permanently on pre-MTG2 definitions
0 = {edition=2;}
2 changes: 2 additions & 0 deletions definitions/grib2/localConcepts/tigge/MTG2SwitchConcept.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This pseudocentre should remain permanently on pre-MTG2 definitions
0 = {edition=2;}
2 changes: 2 additions & 0 deletions definitions/grib2/localConcepts/uerra/MTG2SwitchConcept.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This pseudocentre should remain permanently on pre-MTG2 definitions
0 = {edition=2;}
15 changes: 8 additions & 7 deletions definitions/grib2/products_crra.def
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,11 @@ if (marsStream is "dame") {
unalias mars.step;
}
# MTG2 support given lack of local section
if (tablesVersion <= tablesVersionMTG2Switch) {
# Pre-MTG2
constant MTG2SwitchDefault = 0;
} else {
# All other cases we are post-MTG2
constant MTG2SwitchDefault = 1;
}
# This comes after the paramId is already decided, so doesn't work.
# if (tablesVersion <= tablesVersionMTG2Switch) {
# # Pre-MTG2
# constant MTG2SwitchDefault = 0;
# } else {
# # All other cases we are post-MTG2
# constant MTG2SwitchDefault = 1;
# }
15 changes: 8 additions & 7 deletions definitions/grib2/products_s2s.def
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ if (is_ocean3d_param) {
}

# MTG2 support given lack of local section
if (tablesVersion <= tablesVersionMTG2Switch) {
# Pre-MTG2
constant MTG2SwitchDefault = 0;
} else {
# All other cases we are post-MTG2
constant MTG2SwitchDefault = 1;
}
# This comes after the paramId is already decided, so doesn't work.
# if (tablesVersion <= tablesVersionMTG2Switch) {
# # Pre-MTG2
# constant MTG2SwitchDefault = 0;
# } else {
# # All other cases we are post-MTG2
# constant MTG2SwitchDefault = 1;
# }
15 changes: 8 additions & 7 deletions definitions/grib2/products_tigge.def
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ alias mars.stream = marsStream;
alias mars.type = marsType;

# MTG2 support given lack of local section
if (tablesVersion <= tablesVersionMTG2Switch) {
# Pre-MTG2
constant MTG2SwitchDefault = 0;
} else {
# All other cases we are post-MTG2
constant MTG2SwitchDefault = 1;
}
# This comes after the paramId is already decided, so doesn't work.
# if (tablesVersion <= tablesVersionMTG2Switch) {
# # Pre-MTG2
# constant MTG2SwitchDefault = 0;
# } else {
# # All other cases we are post-MTG2
# constant MTG2SwitchDefault = 1;
# }
15 changes: 8 additions & 7 deletions definitions/grib2/products_uerra.def
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ alias mars.stream = marsStream;
alias mars.type = marsType;

# MTG2 support given lack of local section
if (tablesVersion <= tablesVersionMTG2Switch) {
# Pre-MTG2
constant MTG2SwitchDefault = 0;
} else {
# All other cases we are post-MTG2
constant MTG2SwitchDefault = 1;
}
# This comes after the paramId is already decided, so doesn't work.
# if (tablesVersion <= tablesVersionMTG2Switch) {
# # Pre-MTG2
# constant MTG2SwitchDefault = 0;
# } else {
# # All other cases we are post-MTG2
# constant MTG2SwitchDefault = 1;
# }
27 changes: 13 additions & 14 deletions src/accessor/grib_accessor_class_g2_concept_dir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,18 @@ int grib_accessor_g2_concept_dir_t::unpack_string(char* v, size_t* len)
if (err) return err;

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

const size_t dsize = string_length() - 1; // size for destination string "v"
if (preferLocal) {
Expand All @@ -74,26 +84,15 @@ int grib_accessor_g2_concept_dir_t::unpack_string(char* v, size_t* len)
}
}

// Override if datasetForLocal is not unknown
if (!STR_EQUAL(datasetForLocal, "unknown")) {
// Override if datasetForLocal exists and is not unknown
if (datasetForLocalExists && !STR_EQUAL(datasetForLocal, "unknown")) {
if (mode_ == 1) {
snprintf(v, dsize, "%s", masterDir); // conceptsDir1
} else {
snprintf(v, dsize, "grib2/localConcepts/%s", datasetForLocal); // conceptsDir2
}
}

// if (mode_ == 1) {
// if (STR_EQUAL(datasetForLocal, "unknown")) {
// char centre[64] = {0,};
// size = sizeof(centre) / sizeof(*centre);
// grib_get_string(h, "centre", centre, &size);
// snprintf(v, 256, "grib2/localConcepts/%s", centre);
// } else {
// snprintf(v, 64, "grib2");
// }
// }

size = strlen(v);
ECCODES_ASSERT(size > 0);
*len = size + 1;
Expand Down

0 comments on commit a75936c

Please sign in to comment.