mirror of https://github.com/ecmwf/eccodes.git
ECC-997: grib_util_set_spec: Add support for CCSDS packing (GRIB2)
This commit is contained in:
parent
a9ecad64c7
commit
591b071b4a
|
@ -1497,14 +1497,15 @@ typedef struct grib_util_grid_spec2 {
|
|||
|
||||
} grib_util_grid_spec2;
|
||||
|
||||
#define GRIB_UTIL_PACKING_TYPE_SAME_AS_INPUT 0
|
||||
#define GRIB_UTIL_PACKING_TYPE_SPECTRAL_COMPLEX 1
|
||||
#define GRIB_UTIL_PACKING_TYPE_SPECTRAL_SIMPLE 2
|
||||
#define GRIB_UTIL_PACKING_TYPE_JPEG 3
|
||||
#define GRIB_UTIL_PACKING_TYPE_GRID_COMPLEX 4
|
||||
#define GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE 5
|
||||
#define GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE_MATRIX 6
|
||||
#define GRIB_UTIL_PACKING_TYPE_GRID_SECOND_ORDER 7
|
||||
#define GRIB_UTIL_PACKING_TYPE_SAME_AS_INPUT 0
|
||||
#define GRIB_UTIL_PACKING_TYPE_SPECTRAL_COMPLEX 1
|
||||
#define GRIB_UTIL_PACKING_TYPE_SPECTRAL_SIMPLE 2
|
||||
#define GRIB_UTIL_PACKING_TYPE_JPEG 3
|
||||
#define GRIB_UTIL_PACKING_TYPE_GRID_COMPLEX 4
|
||||
#define GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE 5
|
||||
#define GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE_MATRIX 6
|
||||
#define GRIB_UTIL_PACKING_TYPE_GRID_SECOND_ORDER 7
|
||||
#define GRIB_UTIL_PACKING_TYPE_CCSDS 8
|
||||
|
||||
#define GRIB_UTIL_PACKING_SAME_AS_INPUT 0
|
||||
#define GRIB_UTIL_PACKING_USE_PROVIDED 1
|
||||
|
|
|
@ -857,6 +857,7 @@ grib_handle* grib_util_set_spec2(grib_handle* h,
|
|||
int packingTypeIsSet=0;
|
||||
int setSecondOrder=0;
|
||||
int setJpegPacking=0;
|
||||
int setCcsdsPacking=0;
|
||||
int convertEditionEarlier=0;/* For cases when we cannot set some keys without converting */
|
||||
size_t slen=17;
|
||||
int grib1_high_resolution_fix = 0; /* boolean: See GRIB-863 */
|
||||
|
@ -925,6 +926,10 @@ grib_handle* grib_util_set_spec2(grib_handle* h,
|
|||
if (strcmp(input_packing_type,"grid_jpeg") && !strcmp(input_packing_type,"grid_simple"))
|
||||
SET_STRING_VALUE("packingType","grid_jpeg");
|
||||
break;
|
||||
case GRIB_UTIL_PACKING_TYPE_CCSDS:
|
||||
if (strcmp(input_packing_type,"grid_ccsds") && !strcmp(input_packing_type,"grid_simple"))
|
||||
SET_STRING_VALUE("packingType","grid_ccsds");
|
||||
break;
|
||||
case GRIB_UTIL_PACKING_TYPE_GRID_SECOND_ORDER:
|
||||
/* we delay the set of grid_second_order because we don't want
|
||||
to do it on a field with bitsPerValue=0 */
|
||||
|
@ -1327,6 +1332,14 @@ grib_handle* grib_util_set_spec2(grib_handle* h,
|
|||
if (strcmp(input_packing_type,"grid_jpeg") && !strcmp(input_packing_type,"grid_simple"))
|
||||
setJpegPacking = 1;
|
||||
break;
|
||||
case GRIB_UTIL_PACKING_TYPE_CCSDS:
|
||||
/* Have to delay CCSDS packing:
|
||||
* Reason 1: It is not available in GRIB1 and so we have to wait until we change edition
|
||||
* Reason 2: It has to be done AFTER we set the data values
|
||||
*/
|
||||
if (strcmp(input_packing_type,"grid_ccsds") && !strcmp(input_packing_type,"grid_simple"))
|
||||
setCcsdsPacking = 1;
|
||||
break;
|
||||
case GRIB_UTIL_PACKING_TYPE_GRID_SECOND_ORDER:
|
||||
/* we delay the set of grid_second_order because we don't want
|
||||
to do it on a field with bitsPerValue=0 */
|
||||
|
@ -1606,6 +1619,14 @@ grib_handle* grib_util_set_spec2(grib_handle* h,
|
|||
goto cleanup;
|
||||
}
|
||||
}
|
||||
if (setCcsdsPacking == 1) {
|
||||
*err = grib_set_string(outh, "packingType", "grid_ccsds", &slen);
|
||||
if (*err != GRIB_SUCCESS) {
|
||||
fprintf(stderr,"GRIB_UTIL_SET_SPEC: Failed to change packingType to CCSDS: %s\n",
|
||||
grib_get_error_message(*err));
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (packing_spec->deleteLocalDefinition) {
|
||||
|
|
|
@ -23,6 +23,8 @@ static int get_packing_type_code(const char* packingType)
|
|||
|
||||
if (STR_EQUAL(packingType, "grid_jpeg"))
|
||||
result = GRIB_UTIL_PACKING_TYPE_JPEG;
|
||||
if (STR_EQUAL(packingType, "grid_ccsds"))
|
||||
result = GRIB_UTIL_PACKING_TYPE_CCSDS;
|
||||
else if (STR_EQUAL(packingType, "grid_simple"))
|
||||
result = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
|
||||
else if (STR_EQUAL(packingType, "grid_second_order"))
|
||||
|
@ -178,6 +180,7 @@ static void test_regular_ll(int remove_local_def, int edition, const char* packi
|
|||
spec.Nj = 14;
|
||||
spec.Ni = 17;
|
||||
outlen = spec.Nj * spec.Ni;
|
||||
/* outlen = inlen; */
|
||||
spec.iDirectionIncrementInDegrees = 1.5;
|
||||
spec.jDirectionIncrementInDegrees = 1.5;
|
||||
spec.latitudeOfFirstGridPointInDegrees = 60.0001;
|
||||
|
@ -330,7 +333,7 @@ static void test_grid_complex_spatial_differencing(int remove_local_def, int edi
|
|||
static void usage(const char *prog)
|
||||
{
|
||||
fprintf(stderr, "%s: [-p packingType] [-r] [-e edition] in.grib out.grib\n", prog);
|
||||
fprintf(stderr, "-p packingType: one of grid_jpeg, grid_second_order or grid_simple\n");
|
||||
fprintf(stderr, "-p packingType: one of grid_jpeg, grid_ccsds, grid_second_order or grid_simple\n");
|
||||
fprintf(stderr, "-r remove local definition\n");
|
||||
fprintf(stderr, "-e edition: 1 or 2\n");
|
||||
exit(1);
|
||||
|
|
|
@ -58,6 +58,14 @@ if [ $HAVE_JPEG -eq 1 ]; then
|
|||
[ "$res" = "2 1 grid_jpeg" ]
|
||||
fi
|
||||
|
||||
# Convert to edition2 and use CCSDS for packing
|
||||
if [ $HAVE_AEC -eq 1 ]; then
|
||||
infile=../data/latlon.grib
|
||||
$EXEC $grib_util_set_spec -e 2 -p grid_ccsds $infile $outfile > /dev/null
|
||||
res=`${tools_dir}/grib_get -p edition,section2Used,packingType $outfile`
|
||||
[ "$res" = "2 1 grid_ccsds" ]
|
||||
fi
|
||||
|
||||
# --------------------------------------------------
|
||||
# Reduced Gaussian Grid N=32 second order packing
|
||||
# --------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue