mirror of https://github.com/ecmwf/eccodes.git
CCSDS packing: add other cases
This commit is contained in:
parent
a27618253e
commit
98c687ef15
|
@ -330,7 +330,6 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
unsigned char* buf = NULL;
|
||||
unsigned char* encoded = NULL;
|
||||
size_t n_vals = 0;
|
||||
//long nn = 0;
|
||||
|
||||
long binary_scale_factor = 0;
|
||||
long decimal_scale_factor = 0;
|
||||
|
@ -350,9 +349,6 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
|
||||
self->dirty = 1;
|
||||
|
||||
//if ((err = grib_value_count(a, &nn)) != GRIB_SUCCESS)
|
||||
// return err;
|
||||
//n_vals = nn;
|
||||
n_vals = *len;
|
||||
|
||||
if ((err = grib_get_long_internal(hand, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS)
|
||||
|
|
|
@ -65,6 +65,7 @@ if( HAVE_BUILD_TOOLS )
|
|||
grib_calendar
|
||||
grib_md5
|
||||
grib_cfNames
|
||||
grib_packing_order
|
||||
filter_substr
|
||||
grib_uerra
|
||||
grib_2nd_order_numValues
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "eccodes.h"
|
||||
|
||||
/* Values taken from an actual IFS forecast run for paramId=133 (Specific humidity) */
|
||||
const double values[] = {
|
||||
0.0000026822,0.0000026803,0.0000026786,0.0000026773,0.0000026768,
|
||||
0.0000026771,0.0000026783,0.0000026801,0.0000026820,0.0000026840,
|
||||
|
@ -130888,41 +130888,44 @@ const double values[] = {
|
|||
|
||||
static void usage(const char* prog)
|
||||
{
|
||||
printf("usage: %s packingType packingStage outfile\n", prog);
|
||||
printf("Usage: %s packingType packingStage outfile\n", prog);
|
||||
printf("packingStage: either packing_type_before_values or values_before_packing_type\n");
|
||||
exit(1);
|
||||
}
|
||||
// SIMPLE
|
||||
// max min avg sd skew kurt const
|
||||
// 2.97473e-06 1.26532e-06 2.17382e-06 3.84169e-07 0.32796 -1.03089 0
|
||||
//
|
||||
// CCSDS
|
||||
// 2.8052e-06 2.6129e-06 2.61477e-06 1.36989e-08 7.77715 62.686 0
|
||||
|
||||
typedef enum {
|
||||
PACKING_TYPE_BEFORE_VALUES,
|
||||
VALUES_BEFORE_PACKING_TYPE
|
||||
} PackingStage;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
size_t values_len = sizeof(values)/sizeof(values[0]); // 654400;
|
||||
const char* sample_filename = "gg_sfc_grib2"; // GRIB2 ??
|
||||
//const char* sample_filename = "GRIB2"; //constant field
|
||||
size_t values_len = sizeof(values)/sizeof(values[0]); /* 654400 */
|
||||
const char* sample_filename = "gg_sfc_grib2";
|
||||
codes_handle* h = NULL;
|
||||
size_t str_len = 0;
|
||||
int packing_stage;
|
||||
PackingStage packing_stage;
|
||||
char* packing_type;
|
||||
char* outfile_name;
|
||||
|
||||
if (argc != 4) usage(argv[0]);
|
||||
|
||||
packing_type = argv[1];
|
||||
packing_stage = atoi(argv[2]);
|
||||
outfile_name = argv[3];
|
||||
assert(packing_stage == 1 || packing_stage == 2);
|
||||
|
||||
if (strcmp(argv[2], "packing_type_before_values")==0)
|
||||
packing_stage = PACKING_TYPE_BEFORE_VALUES;
|
||||
else if (strcmp(argv[2], "values_before_packing_type")==0)
|
||||
packing_stage = VALUES_BEFORE_PACKING_TYPE;
|
||||
else
|
||||
exit(1);
|
||||
|
||||
outfile_name = argv[3];
|
||||
|
||||
printf("Using sample_filename = %s\n", sample_filename);
|
||||
h = codes_grib_handle_new_from_samples(0, sample_filename);
|
||||
assert(h);
|
||||
assert( 654400==values_len );
|
||||
|
||||
CODES_CHECK(codes_set_long(h, "bitsPerValue", 16), 0);
|
||||
if (packing_stage == 1) {
|
||||
if (packing_stage == PACKING_TYPE_BEFORE_VALUES) {
|
||||
printf("Set packingType to %s\n", packing_type);
|
||||
CODES_CHECK(codes_set_string(h, "packingType", packing_type, &str_len), 0);
|
||||
}
|
||||
|
@ -130930,9 +130933,9 @@ int main(int argc, char** argv)
|
|||
printf("Set values\n");
|
||||
CODES_CHECK(codes_set_double_array(h, "values", values, values_len), 0);
|
||||
|
||||
if (packing_stage == 2) {
|
||||
if (packing_stage == VALUES_BEFORE_PACKING_TYPE) {
|
||||
printf("Set packingType to %s\n", packing_type);
|
||||
CODES_CHECK(codes_set_string(h, "packingType", packing_type, &str_len), 0); //WORKS
|
||||
CODES_CHECK(codes_set_string(h, "packingType", packing_type, &str_len), 0);
|
||||
}
|
||||
|
||||
CODES_CHECK(codes_write_message(h, outfile_name, "w"), 0);
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
#!/bin/sh
|
||||
# (C) Copyright 2005- ECMWF.
|
||||
#
|
||||
# This software is licensed under the terms of the Apache Licence Version 2.0
|
||||
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
|
||||
#
|
||||
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
|
||||
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
||||
#
|
||||
|
||||
. ./include.sh
|
||||
set -u
|
||||
REDIRECT=/dev/null
|
||||
label="grib_packing_order"
|
||||
temp=${label}".grib.tmp"
|
||||
temp_simple1=${label}".simple1.tmp"
|
||||
temp_simple2=${label}".simple2.tmp"
|
||||
temp_ccsds1=${label}".ccsds1.tmp"
|
||||
temp_ccsds2=${label}".ccsds2.tmp"
|
||||
temp_jpeg1=${label}".jpeg1.tmp"
|
||||
temp_jpeg2=${label}".jpeg2.tmp"
|
||||
|
||||
# Simple Packing
|
||||
$EXEC ${test_dir}/grib_packing_order grid_simple packing_type_before_values $temp_simple1
|
||||
$EXEC ${test_dir}/grib_packing_order grid_simple values_before_packing_type $temp_simple2
|
||||
grib_check_key_equals $temp_simple1 packingType grid_simple
|
||||
${tools_dir}/grib_compare $temp_simple1 $temp_simple2
|
||||
|
||||
if [ $HAVE_AEC -eq 1 ]; then
|
||||
# CCSDS (AEC) Packing
|
||||
$EXEC ${test_dir}/grib_packing_order grid_ccsds packing_type_before_values $temp_ccsds1
|
||||
$EXEC ${test_dir}/grib_packing_order grid_ccsds values_before_packing_type $temp_ccsds2
|
||||
grib_check_key_equals $temp_ccsds1 packingType grid_ccsds
|
||||
${tools_dir}/grib_compare $temp_ccsds1 $temp_ccsds2
|
||||
|
||||
${tools_dir}/grib_compare -c data:n $temp_simple1 $temp_ccsds1
|
||||
fi
|
||||
|
||||
if [ $HAVE_JPEG -eq 1 ]; then
|
||||
# JPEG Packing
|
||||
$EXEC ${test_dir}/grib_packing_order grid_jpeg packing_type_before_values $temp_jpeg1
|
||||
$EXEC ${test_dir}/grib_packing_order grid_jpeg values_before_packing_type $temp_jpeg2
|
||||
grib_check_key_equals $temp_jpeg1 packingType grid_jpeg
|
||||
${tools_dir}/grib_compare $temp_jpeg1 $temp_jpeg2
|
||||
|
||||
${tools_dir}/grib_compare -c data:n $temp_simple1 $temp_jpeg1
|
||||
fi
|
||||
|
||||
|
||||
# Clean up
|
||||
rm -f $temp_simple1 $temp_simple2 $temp_ccsds1 $temp_ccsds2 $temp_jpeg1 $temp_jpeg2
|
Loading…
Reference in New Issue