Skip to content

Commit

Permalink
Merge changes from hotfix 2.28.1
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramn committed Feb 24, 2023
2 parents cf72281 + bc105ef commit 49dc5dd
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 48 deletions.
4 changes: 4 additions & 0 deletions definitions/grib1/section.1.def
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ if( indicatorOfTypeOfLevel == 109 ||
{
alias mars.levelist = level;
}
if (indicatorOfTypeOfLevel == 117) {
# See ECC-1081
constant levelFactor = 6;
}

unsigned[1] yearOfCentury : edition_specific;
unsigned[1] month;
Expand Down
1 change: 1 addition & 0 deletions definitions/grib2/crraLocalVersion.table
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
1 CRRA Copernicus regional reanalysis
2 CRRA Copernicus regional reanalysis with expver
7 changes: 7 additions & 0 deletions definitions/grib2/local.crra.2.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# CARRA/CERRA local

codetable[2] suiteName "grib2/crra_suiteName.table" : dump;
alias crraSuiteID = suiteName;

ksec1expver[4] experimentVersionNumber = "0002" : dump;
alias marsExpver = experimentVersionNumber ;
4 changes: 3 additions & 1 deletion definitions/grib2/products_10.def
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# (C) Copyright 2005- ECMWF.

# Copernicus regional reanalysis (CARRA/CERRA)
constant marsExpver = 'prod';
if (!defined(marsExpver)) {
constant marsExpver = 'prod';
}
include "grib2/products_crra.def"
6 changes: 4 additions & 2 deletions definitions/grib2/products_11.def
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# (C) Copyright 2005- ECMWF.

# Copernicus regional reanalysis (CARRA/CERRA)
constant marsExpver = 'test';
# Copernicus regional reanalysis test (CARRA/CERRA)
if (!defined(marsExpver)) {
constant marsExpver = 'test';
}
include "grib2/products_crra.def"
1 change: 1 addition & 0 deletions experimental/show_compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ echo
echo "Compilation for C ..."
echo "$CCMP myprog.c $LIBS $INCL"
echo
echo
6 changes: 6 additions & 0 deletions src/grib_accessor_class_g2level.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
long value_first = *val;
long scale_first = 0;
long type_first = 0;
long levelFactor = 1;
char pressure_units[10] = {0,};
size_t pressure_units_len = 10;

Expand Down Expand Up @@ -324,6 +325,11 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
if (!strcmp(pressure_units, "hPa"))
value_first *= 100;
break;
case 109:
if ((ret = grib_get_long(hand, "levelFactor", &levelFactor)) == GRIB_SUCCESS) {
/* See ECC-1081 */
scale_first = levelFactor;
}

default:
break;
Expand Down
6 changes: 6 additions & 0 deletions src/grib_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,12 @@ grib_handle* grib_util_set_spec2(grib_handle* h,
if (STR_EQUAL(input_packing_type, "grid_ieee")) {
SET_STRING_VALUE("packingType", input_packing_type);
}
if (STR_EQUAL(input_packing_type, "grid_ccsds")) {
setCcsdsPacking = 1;
}
if (STR_EQUAL(input_packing_type, "grid_second_order")) {
setSecondOrder = 1;
}
}

/*if ( (*err=check_values(data_values, data_values_count))!=GRIB_SUCCESS ) {
Expand Down
3 changes: 2 additions & 1 deletion tests/grib_threads_ecc-604.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ GRIB2_INPUTS="
${data_dir}/test_file.grib2
${data_dir}/sample.grib2"

if [ $HAVE_JPEG -eq 1 ]; then
# There is a problem with multi-threading and Jasper versions > 2
if [ $HAVE_JPEG -eq 1 -a $HAVE_LIBJASPER -eq 0 ]; then
echo "Adding extra files (HAVE_JPEG=1)"
GRIB2_INPUTS="${data_dir}/jpeg.grib2 ${data_dir}/reduced_gaussian_surface_jpeg.grib2 "$GRIB2_INPUTS
fi
Expand Down
25 changes: 25 additions & 0 deletions tests/grib_uerra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,30 @@ status=$?
set -e
[ $status -ne 0 ]

# ECC-1532
# ---------
# By default crraLocalVersion=1 which does not allow expver to be set
# because it is a constant (prod or test)
set +e
${tools_dir}/grib_set -s \
productionStatusOfProcessedData=10,grib2LocalSectionPresent=1,marsExpver=coco \
$grib2_sample $temp1
status=$?
set -e
[ $status -ne 0 ]

# ECC-1532
# crraLocalVersion=2 has a coded key for experimentVersionNumber
${tools_dir}/grib_set -s \
productionStatusOfProcessedData=10,grib2LocalSectionPresent=1,crraLocalVersion=2,marsExpver=coco \
$grib2_sample $temp1
grib_check_key_equals $temp1 'marsExpver,mars.expver' 'coco coco'

${tools_dir}/grib_set -s \
productionStatusOfProcessedData=11,grib2LocalSectionPresent=1,crraLocalVersion=2,experimentVersionNumber=0078 \
$grib2_sample $temp1
grib_check_key_equals $temp1 'marsExpver,mars.expver' '0078 0078'


# Clean up
rm -f $temp1 $temp2 $tempSample
83 changes: 48 additions & 35 deletions tests/grib_util_set_spec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ static int get_packing_type_code(const char* packingType)
{
int result = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
if (packingType == NULL)
return result;
return GRIB_UTIL_PACKING_TYPE_SAME_AS_INPUT;

if (STR_EQUAL(packingType, "grid_jpeg"))
result = GRIB_UTIL_PACKING_TYPE_JPEG;
if (STR_EQUAL(packingType, "grid_ccsds"))
result = GRIB_UTIL_PACKING_TYPE_CCSDS;
return GRIB_UTIL_PACKING_TYPE_JPEG;
else if (STR_EQUAL(packingType, "grid_ccsds"))
return GRIB_UTIL_PACKING_TYPE_CCSDS;
else if (STR_EQUAL(packingType, "grid_simple"))
result = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
return GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
else if (STR_EQUAL(packingType, "grid_second_order"))
result = GRIB_UTIL_PACKING_TYPE_GRID_SECOND_ORDER;
return GRIB_UTIL_PACKING_TYPE_GRID_SECOND_ORDER;
else if (STR_EQUAL(packingType, "grid_ieee"))
result = GRIB_UTIL_PACKING_TYPE_IEEE;
return GRIB_UTIL_PACKING_TYPE_IEEE;

Assert(!"Invalid packingType");
return result;
}

Expand All @@ -47,8 +48,8 @@ static void test_reduced_gg(int remove_local_def, int edition, const char* packi
const void* buffer = NULL;
char gridType[128] = {0,};

codes_handle* handle = 0;
codes_handle* finalh = 0;
grib_handle* handle = 0;
grib_handle* finalh = 0;
grib_util_grid_spec spec = {0,};
grib_util_packing_spec packing_spec = {0,};

Expand All @@ -70,6 +71,9 @@ static void test_reduced_gg(int remove_local_def, int edition, const char* packi
CODES_CHECK(grib_get_size(handle, "values", &inlen), 0);
values = (double*)malloc(sizeof(double) * inlen);
CODES_CHECK(grib_get_double_array(handle, "values", values, &inlen), 0);
// make sure values are not constant
values[0] = 4.4;
values[1] = 5.5;
for (i = 0; i < inlen; ++i) {
values[i] *= 1.10;
}
Expand All @@ -90,7 +94,10 @@ static void test_reduced_gg(int remove_local_def, int edition, const char* packi
packing_spec.packing_type = get_packing_type_code(packingType);
packing_spec.bitsPerValue = 24;
packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES;
packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED;
if (packingType)
packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED;
else
packing_spec.packing = GRIB_UTIL_PACKING_SAME_AS_INPUT;

/*Extra settings
packing_spec.extra_settings_count++;
Expand All @@ -112,7 +119,7 @@ static void test_reduced_gg(int remove_local_def, int edition, const char* packi

/* Try some invalid inputs and check it is handled */
{
codes_handle* h2 = 0;
grib_handle* h2 = 0;
packing_spec.accuracy = 999;
h2 = grib_util_set_spec(handle, &spec, &packing_spec, set_spec_flags, values, outlen, &err);
Assert(err == GRIB_INTERNAL_ERROR);
Expand Down Expand Up @@ -158,18 +165,18 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi
char gridType[128] = {0,};
long input_edition = 0;

codes_handle* handle = 0;
codes_handle* finalh = 0;
grib_handle* handle = 0;
grib_handle* finalh = 0;
grib_util_grid_spec spec = {0,};
grib_util_packing_spec packing_spec = {0,};

Assert(input_filename);
in = fopen(input_filename, "rb");
Assert(in);
handle = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
handle = grib_handle_new_from_file(0, in, &err);
Assert(handle);

CODES_CHECK(codes_get_long(handle, "edition", &input_edition), 0);
CODES_CHECK(grib_get_long(handle, "edition", &input_edition), 0);

CODES_CHECK(grib_get_string(handle, "gridType", gridType, &slen), 0);
if (!STR_EQUAL(gridType, "regular_ll")) {
Expand All @@ -180,9 +187,12 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi
out = fopen(output_filename, "wb");
Assert(out);

CODES_CHECK(codes_get_size(handle, "values", &inlen), 0);
CODES_CHECK(grib_get_size(handle, "values", &inlen), 0);
values = (double*)malloc(sizeof(double) * inlen);
CODES_CHECK(codes_get_double_array(handle, "values", values, &inlen), 0);
CODES_CHECK(grib_get_double_array(handle, "values", values, &inlen), 0);
// make sure values are not constant
values[0] = 4.4;
values[1] = 5.5;

spec.grid_type = GRIB_UTIL_GRID_SPEC_REGULAR_LL;
spec.Nj = 14;
Expand All @@ -201,7 +211,10 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi
packing_spec.packing_type = get_packing_type_code(packingType);
packing_spec.bitsPerValue = 24;
packing_spec.accuracy = GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES;
packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED;
if (packingType)
packing_spec.packing = GRIB_UTIL_PACKING_USE_PROVIDED;
else
packing_spec.packing = GRIB_UTIL_PACKING_SAME_AS_INPUT;

packing_spec.extra_settings_count++;
packing_spec.extra_settings[0].type = GRIB_TYPE_LONG;
Expand All @@ -215,7 +228,7 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi
packing_spec.deleteLocalDefinition = 1;
}

finalh = codes_grib_util_set_spec(
finalh = grib_util_set_spec(
handle,
&spec,
&packing_spec,
Expand All @@ -232,19 +245,19 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi
if (input_edition == 1) {
const double expected_lat1 = 60.001;
double lat1 = 0;
CODES_CHECK(codes_get_double(finalh, "latitudeOfFirstGridPointInDegrees", &lat1), 0);
CODES_CHECK(grib_get_double(finalh, "latitudeOfFirstGridPointInDegrees", &lat1), 0);
Assert(fabs(lat1 - expected_lat1) < 1e-10);
}

/* Write out the message to the output file */
CODES_CHECK(codes_get_message(finalh, &buffer, &size), 0);
CODES_CHECK(grib_get_message(finalh, &buffer, &size), 0);
CODES_CHECK(codes_check_message_header(buffer, size, PRODUCT_GRIB), 0);
CODES_CHECK(codes_check_message_footer(buffer, size, PRODUCT_GRIB), 0);
if (fwrite(buffer, 1, size, out) != size) {
Assert(0);
}
codes_handle_delete(handle);
codes_handle_delete(finalh);
grib_handle_delete(handle);
grib_handle_delete(finalh);
free(values);
fclose(in);
fclose(out);
Expand All @@ -266,13 +279,13 @@ static void test_grid_complex_spatial_differencing(int remove_local_def, int edi
char gridType[128] = {0,};
double theMax,theMin,theAverage;

codes_handle *handle = 0;
codes_handle *finalh = 0;
grib_handle *handle = 0;
grib_handle *finalh = 0;
grib_util_grid_spec spec={0,};
grib_util_packing_spec packing_spec={0,};

in = fopen(input_filename,"rb"); Assert(in);
handle = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err); Assert(handle);
handle = grib_handle_new_from_file(0, in, &err); Assert(handle);

CODES_CHECK(grib_get_string(handle, "packingType", gridType, &slen),0);
if (!STR_EQUAL(gridType, "grid_complex_spatial_differencing")) {
Expand All @@ -281,13 +294,13 @@ static void test_grid_complex_spatial_differencing(int remove_local_def, int edi
}
out = fopen(output_filename,"wb"); Assert(out);

CODES_CHECK(codes_get_size(handle,"values",&inlen), 0);
CODES_CHECK(grib_get_size(handle,"values",&inlen), 0);
values = (double*)malloc(sizeof(double)*inlen);
CODES_CHECK(codes_get_double_array(handle, "values", values,&inlen), 0);
CODES_CHECK(grib_get_double_array(handle, "values", values,&inlen), 0);

CODES_CHECK(codes_get_double(handle, "max", &theMax),0);
CODES_CHECK(codes_get_double(handle, "min", &theMin),0);
CODES_CHECK(codes_get_double(handle, "average",&theAverage),0);
CODES_CHECK(grib_get_double(handle, "max", &theMax),0);
CODES_CHECK(grib_get_double(handle, "min", &theMin),0);
CODES_CHECK(grib_get_double(handle, "average",&theAverage),0);
printf("inlen=%lu \t max=%g \t min=%g \t avg=%g\n", inlen, theMax, theMin, theAverage);

spec.grid_type = GRIB_UTIL_GRID_SPEC_REGULAR_LL;
Expand Down Expand Up @@ -315,7 +328,7 @@ static void test_grid_complex_spatial_differencing(int remove_local_def, int edi
packing_spec.deleteLocalDefinition = 1;
}

finalh = codes_grib_util_set_spec(
finalh = grib_util_set_spec(
handle,
&spec,
&packing_spec,
Expand All @@ -327,12 +340,12 @@ static void test_grid_complex_spatial_differencing(int remove_local_def, int edi
Assert(err == 0);

/* Write out the message to the output file */
CODES_CHECK(codes_get_message(finalh, &buffer, &size),0);
CODES_CHECK(grib_get_message(finalh, &buffer, &size),0);
if(fwrite(buffer,1,size,out) != size) {
Assert(0);
}
codes_handle_delete(handle);
codes_handle_delete(finalh);
grib_handle_delete(handle);
grib_handle_delete(finalh);
fclose(in);
fclose(out);
}
Expand Down
Loading

0 comments on commit 49dc5dd

Please sign in to comment.