mirror of https://github.com/ecmwf/eccodes.git
Test harness for grib_util_set_spec improved
This commit is contained in:
parent
d62fee70c5
commit
5bf974a3b0
|
@ -7,12 +7,31 @@
|
||||||
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
|
* 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.
|
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "grib_api_internal.h"
|
||||||
#include "eccodes.h"
|
#include "eccodes.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#define STR_EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
|
#define STR_EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
|
||||||
|
|
||||||
void test_reduced_gg(const char* input_filename, const char* output_filename)
|
int get_packing_type_code(const char* packingType)
|
||||||
|
{
|
||||||
|
int result = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
|
||||||
|
if (packingType==NULL)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
if (STR_EQUAL(packingType, "grid_jpeg"))
|
||||||
|
result = GRIB_UTIL_PACKING_TYPE_JPEG;
|
||||||
|
else if (STR_EQUAL(packingType, "grid_simple"))
|
||||||
|
result = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
|
||||||
|
else if (STR_EQUAL(packingType, "grid_second_order"))
|
||||||
|
result = GRIB_UTIL_PACKING_TYPE_GRID_SECOND_ORDER;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_reduced_gg(int remove_local_def, int edition, const char* packingType,
|
||||||
|
const char* input_filename, const char* output_filename)
|
||||||
{
|
{
|
||||||
/* based on copy_spec_from_ksec */
|
/* based on copy_spec_from_ksec */
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
@ -59,7 +78,8 @@ void test_reduced_gg(const char* input_filename, const char* output_filename)
|
||||||
spec.longitudeOfLastGridPointInDegrees = 357.187500;
|
spec.longitudeOfLastGridPointInDegrees = 357.187500;
|
||||||
spec.bitmapPresent = 0;
|
spec.bitmapPresent = 0;
|
||||||
|
|
||||||
packing_spec.packing_type = GRIB_UTIL_PACKING_TYPE_GRID_SECOND_ORDER;
|
/*packing_spec.packing_type = GRIB_UTIL_PACKING_TYPE_GRID_SECOND_ORDER;*/
|
||||||
|
packing_spec.packing_type = get_packing_type_code(packingType);
|
||||||
packing_spec.bitsPerValue = 24;
|
packing_spec.bitsPerValue = 24;
|
||||||
packing_spec.accuracy=GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES;
|
packing_spec.accuracy=GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES;
|
||||||
packing_spec.packing=GRIB_UTIL_PACKING_USE_PROVIDED;
|
packing_spec.packing=GRIB_UTIL_PACKING_USE_PROVIDED;
|
||||||
|
@ -86,7 +106,8 @@ void test_reduced_gg(const char* input_filename, const char* output_filename)
|
||||||
fclose(out);
|
fclose(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_regular_ll(const char* input_filename, const char* output_filename)
|
void test_regular_ll(int remove_local_def, int edition, const char* packingType,
|
||||||
|
const char* input_filename, const char* output_filename)
|
||||||
{
|
{
|
||||||
/* based on copy_spec_from_ksec */
|
/* based on copy_spec_from_ksec */
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
@ -130,13 +151,18 @@ void test_regular_ll(const char* input_filename, const char* output_filename)
|
||||||
spec.longitudeOfLastGridPointInDegrees = 15.0;
|
spec.longitudeOfLastGridPointInDegrees = 15.0;
|
||||||
spec.bitmapPresent = 0;
|
spec.bitmapPresent = 0;
|
||||||
|
|
||||||
packing_spec.packing_type = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
|
/*packing_spec.packing_type = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;*/
|
||||||
|
packing_spec.packing_type = get_packing_type_code(packingType);
|
||||||
packing_spec.bitsPerValue = 24;
|
packing_spec.bitsPerValue = 24;
|
||||||
packing_spec.accuracy=GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES;
|
packing_spec.accuracy=GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES;
|
||||||
packing_spec.packing=GRIB_UTIL_PACKING_USE_PROVIDED;
|
packing_spec.packing=GRIB_UTIL_PACKING_USE_PROVIDED;
|
||||||
/* Convert to edition 2 and remove local use section */
|
|
||||||
packing_spec.editionNumber = 2;
|
if (edition != 0) {
|
||||||
packing_spec.deleteLocalDefinition = 1;
|
packing_spec.editionNumber = edition;
|
||||||
|
}
|
||||||
|
if (remove_local_def) {
|
||||||
|
packing_spec.deleteLocalDefinition = 1;
|
||||||
|
}
|
||||||
|
|
||||||
finalh = codes_grib_util_set_spec(
|
finalh = codes_grib_util_set_spec(
|
||||||
handle,
|
handle,
|
||||||
|
@ -160,13 +186,53 @@ void test_regular_ll(const char* input_filename, const char* output_filename)
|
||||||
fclose(out);
|
fclose(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, "-r remove local definition\n");
|
||||||
|
fprintf(stderr, "-e edition: 1 or 2\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char *infile = argv[1];
|
int opt = 0, remove_local_def = 0, i = 0;
|
||||||
const char *outfile = argv[2];
|
int edition = 0;
|
||||||
|
char* packingType = NULL;
|
||||||
|
const char* prog = argv[0];
|
||||||
|
char* infile_name = NULL;
|
||||||
|
char* outfile_name = NULL;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "re:p:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'r':
|
||||||
|
remove_local_def=1;
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
packingType = optarg;
|
||||||
|
break;
|
||||||
|
case 'e':
|
||||||
|
edition = atoi(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
usage(prog);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* After option processing expect just two files */
|
||||||
|
if (argc-optind != 2) usage(prog);
|
||||||
|
|
||||||
|
for (i = optind; i < argc; i++) {
|
||||||
|
printf ("File argument %s\n", argv[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
infile_name = argv[argc-2];
|
||||||
|
outfile_name = argv[argc-1];
|
||||||
|
|
||||||
|
test_regular_ll(remove_local_def, edition, packingType, infile_name, outfile_name);
|
||||||
|
test_reduced_gg(remove_local_def, edition, packingType, infile_name, outfile_name);
|
||||||
|
|
||||||
test_regular_ll(infile, outfile);
|
|
||||||
test_reduced_gg(infile, outfile);
|
|
||||||
printf("ALL OK\n");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@ outfile=out.grib_util_set_spec.grib
|
||||||
tempOut=temp.grib_util_set_spec.grib
|
tempOut=temp.grib_util_set_spec.grib
|
||||||
rm -f $outfile
|
rm -f $outfile
|
||||||
|
|
||||||
# GRIB1 with local definition for MARS
|
# GRIB1 with local definition for MARS. Convert to edition2 and remove local def
|
||||||
${test_dir}grib_util_set_spec $infile $outfile > /dev/null
|
${test_dir}grib_util_set_spec -e 2 -r $infile $outfile > /dev/null
|
||||||
|
|
||||||
res=`${tools_dir}grib_get -p edition,section2Used,Ni,Nj,numberOfValues,bitsPerValue $outfile`
|
res=`${tools_dir}grib_get -p edition,section2Used,Ni,Nj,numberOfValues,bitsPerValue $outfile`
|
||||||
[ "$res" = "2 0 17 14 238 24" ]
|
[ "$res" = "2 0 17 14 238 24" ]
|
||||||
|
@ -35,19 +35,26 @@ ${test_dir}grib_util_set_spec $tempOut $outfile > /dev/null
|
||||||
# Add another grib1 local definition (which is not in grib2)
|
# Add another grib1 local definition (which is not in grib2)
|
||||||
${tools_dir}grib_set -s setLocalDefinition=1,localDefinitionNumber=5 $infile $tempOut
|
${tools_dir}grib_set -s setLocalDefinition=1,localDefinitionNumber=5 $infile $tempOut
|
||||||
infile=$tempOut
|
infile=$tempOut
|
||||||
${test_dir}grib_util_set_spec $tempOut $outfile > /dev/null
|
${test_dir}grib_util_set_spec -r -e 2 $tempOut $outfile > /dev/null
|
||||||
res=`${tools_dir}grib_get -p edition,section2Used $outfile`
|
res=`${tools_dir}grib_get -p edition,section2Used $outfile`
|
||||||
[ "$res" = "2 0" ]
|
[ "$res" = "2 0" ]
|
||||||
|
|
||||||
# GRIB2 input with local definition
|
# GRIB2 input with local definition
|
||||||
infile=../data/regular_latlon_surface.grib2
|
infile=../data/regular_latlon_surface.grib2
|
||||||
${test_dir}grib_util_set_spec $infile $outfile > /dev/null
|
${test_dir}grib_util_set_spec -r $infile $outfile > /dev/null
|
||||||
grib_check_key_equals $outfile section2Used 0
|
grib_check_key_equals $outfile section2Used 0
|
||||||
# GRIB2 input without local definition
|
# GRIB2 input without local definition
|
||||||
infile=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
infile=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
|
||||||
${test_dir}grib_util_set_spec $infile $outfile > /dev/null
|
${test_dir}grib_util_set_spec $infile $outfile > /dev/null
|
||||||
grib_check_key_equals $outfile section2Used 0
|
grib_check_key_equals $outfile section2Used 0
|
||||||
|
|
||||||
|
# Convert to edition2 and use JPEG for packing
|
||||||
|
infile=../data/latlon.grib
|
||||||
|
${test_dir}grib_util_set_spec -e 2 -p grid_jpeg $infile $outfile > /dev/null
|
||||||
|
res=`${tools_dir}grib_get -p edition,section2Used,packingType $outfile`
|
||||||
|
[ "$res" = "2 1 grid_jpeg" ]
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
# Reduced Gaussian Grid N=32 second order packing
|
# Reduced Gaussian Grid N=32 second order packing
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
|
@ -58,7 +65,7 @@ rm -f $outfile
|
||||||
stats_old=`${tools_dir}grib_get -F%.2f -p min,max $infile`
|
stats_old=`${tools_dir}grib_get -F%.2f -p min,max $infile`
|
||||||
[ "$stats_old" = "160.25 224.45" ]
|
[ "$stats_old" = "160.25 224.45" ]
|
||||||
|
|
||||||
${test_dir}grib_util_set_spec $infile $outfile
|
${test_dir}grib_util_set_spec -p grid_second_order $infile $outfile
|
||||||
|
|
||||||
# Check output file. Values are scaled up by 1.1
|
# Check output file. Values are scaled up by 1.1
|
||||||
grib_check_key_equals $outfile packingType grid_second_order
|
grib_check_key_equals $outfile packingType grid_second_order
|
||||||
|
|
Loading…
Reference in New Issue