Skip to content

Commit

Permalink
MULTIOM grib1-to-grib2 Fix setting reduced_gg grid
Browse files Browse the repository at this point in the history
  • Loading branch information
geier1993 committed Feb 21, 2025
1 parent 9b25ce9 commit 8009eda
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/multiom/api/api_encoder_wrapper_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,9 @@ PP_THREAD_SAFE FUNCTION MULTIO_GRIB2_ENCODER_ENCODE( MULTIO_GRIB2, C_MARS_DICT,
PP_TRYCALL(ERRFLAG_EXTRACT_MARS_DICTIONARY) EXTRACT_MARS_DICTIONARY( F_MARS_DICT, MARS_DICT, HOOKS )

PP_TRYCALL(ERRFLAG_EXTRACT_PAR_DICTIONARY) EXTRACT_PAR_DICTIONARY( F_PAR_DICT, PAR_DICT, HOOKS )

! WRITE(6, *) "PAR YAML.."
! PP_TRYCALL(ERRFLAG_EXTRACT_PAR_DICTIONARY) PAR_DICT%WRITE_TO_YAML(6_JPIB_K, 0_JPIB_K, HOOKS)

! Call the encoder
PP_TRYCALL(ERRFLAG_CALL_THE_ENCODER) ENCODER%ENCODE( MARS_DICT, PAR_DICT, METADATA_LIST, HOOKS )
Expand Down
9 changes: 5 additions & 4 deletions src/multiom/api/api_extract_metadata_c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ namespace {

int getAndSetLongArray(codes_handle* h, void* dict, const char* key, const char* setName=NULL) {
if(hasKey(h, key)) {
int ret = multio_grib2_dict_set(dict, setName == NULL ? key : setName, arrayToJSONString(getLongArray(h, key)).data());
auto jsonData = arrayToJSONString(getLongArray(h, key));
int ret = multio_grib2_dict_set(dict, setName == NULL ? key : setName, jsonData.data());
if(ret != 0) return ret;
}
return 0;
Expand All @@ -148,10 +149,10 @@ namespace {
ret = getAndSet(h, geom, "truncateDegrees", "truncate-degrees");
if(ret != 0) return ret;

ret = getAndSetIfNonZero(h, geom, "numberOfPointsALongAMeridian", "number-of-points-along-a-meridian");
ret = getAndSetIfNonZero(h, geom, "numberOfPointsAlongAMeridian", "number-of-points-along-a-meridian");
if(ret != 0) return ret;

ret = getAndSetIfNonZero(h, geom, "numberOfParallelsBetweenPoleAndEquator", "number-of-parallels-between-pole-and-equator");
ret = getAndSetIfNonZero(h, geom, "numberOfParallelsBetweenAPoleAndTheEquator", "number-of-parallels-between-pole-and-equator");
if(ret != 0) return ret;

ret = getAndSet(h, geom, "latitudeOfFirstGridPointInDegrees", "latitude-of-first-grid-point-in-degrees");
Expand All @@ -165,7 +166,7 @@ namespace {

ret = getAndSet(h, geom, "longitudeOfLastGridPointInDegrees", "longitude-of-last-grid-point-in-degrees");
if(ret != 0) return ret;

ret = getAndSetLongArray(h, geom, "pl", "pl");
if(ret != 0) return ret;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ PP_THREAD_SAFE FUNCTION GRIB2_SECTION3_040_ALLOCATE( THIS, &
INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_GEOMETRY_PL_ARRAY_NOT_ASSOCIATED=3_JPIB_K
INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_NOT_IMPLEMENTED=4_JPIB_K
INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_METADATA=5_JPIB_K
INTEGER(KIND=JPIB_K), PARAMETER :: ERRFLAG_GEOMETRY_PL_ARRAY_WRONG_SIZE=6_JPIB_K

! Local variables declared by the preprocessor for debugging purposes
PP_DEBUG_DECL_VARS
Expand All @@ -534,11 +535,12 @@ PP_THREAD_SAFE FUNCTION GRIB2_SECTION3_040_ALLOCATE( THIS, &

! Enable section 3
PP_METADATA_SET( METADATA, ERRFLAG_METADATA, 'gridDefinitionTemplateNumber', 40 )

! Configure the representation
SELECT TYPE ( R => PAR%GEOMETRY%REPRES )

CLASS IS (REGULAR_GG_T)


! Set the specific metadata for a regular_gg grid
PP_METADATA_SET( METADATA, ERRFLAG_METADATA, 'gridType','regular_gg' )
Expand All @@ -556,6 +558,8 @@ PP_THREAD_SAFE FUNCTION GRIB2_SECTION3_040_ALLOCATE( THIS, &

! Error handling
PP_DEBUG_CRITICAL_COND_THROW( .NOT. ASSOCIATED(R%PL), ERRFLAG_GEOMETRY_PL_ARRAY_NOT_ASSOCIATED )

PP_DEBUG_CRITICAL_COND_THROW( R%NUMBER_OF_PARALLELS_BETWEEN_POLE_AND_EQUATOR.NE.(SIZE(R%PL)/2), ERRFLAG_GEOMETRY_PL_ARRAY_WRONG_SIZE )

! Set the specific metadata for a reduced_gg grid
PP_METADATA_SET( METADATA, ERRFLAG_METADATA, 'gridType','reduced_gg' )
Expand Down Expand Up @@ -609,6 +613,8 @@ PP_THREAD_SAFE FUNCTION GRIB2_SECTION3_040_ALLOCATE( THIS, &
PP_DEBUG_PUSH_MSG_TO_FRAME( 'not implemented' )
CASE (ERRFLAG_METADATA)
PP_DEBUG_PUSH_MSG_TO_FRAME( 'metadata error' )
CASE (ERRFLAG_GEOMETRY_PL_ARRAY_WRONG_SIZE)
PP_DEBUG_PUSH_MSG_TO_FRAME( 'Wrong size of PL array or N has a invalid number' )
CASE DEFAULT
PP_DEBUG_PUSH_MSG_TO_FRAME( 'unhandled error' )
END SELECT
Expand Down

0 comments on commit 8009eda

Please sign in to comment.