GRIB-799: Added test for grib_util_set_spec

This commit is contained in:
Shahram Najm 2015-07-21 14:24:02 +01:00
parent 680d28f81b
commit 776a7ad5b7
5 changed files with 114 additions and 2 deletions

View File

@ -21,6 +21,7 @@ gts.grib
index.grib
grid_ieee.grib
jpeg.grib2
latlon.grib
lfpw.grib1
missing_field.grib1
missing.grib2

View File

@ -17,6 +17,7 @@ list( APPEND test_bins
read_index
unit_tests
gauss_sub
grib_util_set_spec
)
foreach( tool ${test_bins} )
@ -84,6 +85,7 @@ list( APPEND tests2
padding
debug
md5
grib_util_set_spec
)
# These tests do not require any data downloads

View File

@ -14,7 +14,7 @@ TESTS = definitions.sh calendar.sh \
multi_from_message.sh change_scanning.sh \
julian.sh statistics.sh tigge.sh tigge_conversions.sh \
read_any.sh padding.sh lamb_az_eq_area.sh grib_to_netcdf.sh debug.sh \
jpeg.sh ccsds.sh md5.sh
jpeg.sh ccsds.sh md5.sh grib_util_set_spec.sh
# First download all the necessary data for testing
# Note: if download fails, no tests will be done
@ -25,7 +25,7 @@ download_data:
noinst_PROGRAMS = packing_check gauss_sub read_any double_cmp packing pack_unpack \
multi_from_message julian read_index index gribex_perf\
jpeg_perf ccsds_perf so_perf png_perf bpv_limit laplacian \
unit_tests
unit_tests grib_util_set_spec
multi_from_message_SOURCES = multi_from_message.c
laplacian_SOURCES = laplacian.c
@ -44,6 +44,7 @@ png_perf_SOURCES = png_perf.c
ccsds_perf_SOURCES = ccsds_perf.c
gribex_perf_SOURCES = gribex_perf.c
gauss_sub_SOURCES = gauss_sub.c
grib_util_set_spec_SOURCES = grib_util_set_spec.c
LDADD = $(top_builddir)/src/libeccodes.la $(EMOS_LIB)

View File

@ -0,0 +1,85 @@
/*
* Copyright 2005-2015 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 "eccodes.h"
#include <assert.h>
void test1(const char* input_filename, const char* output_filename)
{
/* based on copy_spec_from_ksec */
int err = 0;
size_t inlen = 0;
size_t outlen = 0;
size_t size=0;
int set_spec_flags=0;
double* values = NULL;
FILE* in = NULL;
FILE* out = NULL;
const void* buffer = NULL;
codes_handle *handle = 0;
codes_handle *finalh = 0;
grib_util_grid_spec spec={0,};
grib_util_packing_spec packing_spec={0,};
in = fopen(input_filename,"r"); assert(in);
out = fopen(output_filename,"w"); assert(out);
handle = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
assert(handle);
CODES_CHECK(codes_get_size(handle,"values",&inlen), 0);
values = (double*)malloc(sizeof(double)*inlen);
GRIB_CHECK(codes_get_double_array(handle, "values", values,&inlen), 0);
spec.grid_type = GRIB_UTIL_GRID_SPEC_REGULAR_LL;
spec.Nj = 14;
spec.Ni = 17;
outlen = spec.Nj * spec.Ni;
spec.iDirectionIncrementInDegrees = 1.5;
spec.jDirectionIncrementInDegrees = 1.5;
spec.latitudeOfFirstGridPointInDegrees = 60.0;
spec.longitudeOfFirstGridPointInDegrees = -9.0;
spec.latitudeOfLastGridPointInDegrees = 40.5;
spec.longitudeOfLastGridPointInDegrees = 15.0;
spec.bitmapPresent = 0;
packing_spec.packing_type = GRIB_UTIL_PACKING_TYPE_GRID_SIMPLE;
packing_spec.bitsPerValue = 24;
packing_spec.accuracy=GRIB_UTIL_ACCURACY_USE_PROVIDED_BITS_PER_VALUES;
packing_spec.packing=GRIB_UTIL_PACKING_USE_PROVIDED;
finalh = codes_grib_util_set_spec(
handle,
&spec,
&packing_spec,
set_spec_flags,
values,
outlen,
&err);
assert(finalh);
assert(err == 0);
/* Write out the message to the output file */
CODES_CHECK(codes_get_message(finalh, &buffer, &size),0);
if(fwrite(buffer,1,size,out) != size) {
assert(0);
}
codes_handle_delete(handle);
codes_handle_delete(finalh);
}
int main(int argc, char *argv[])
{
const char *infile = argv[1];
const char *outfile = argv[2];
test1(infile, outfile);
return 0;
}

23
tests/grib_util_set_spec.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
# Copyright 2005-2015 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
infile=../data/latlon.grib
outfile=out.grib_util_set_spec.grib
${test_dir}/grib_util_set_spec $infile $outfile > /dev/null
res=`${tools_dir}grib_get -p Ni,Nj,numberOfValues,bitsPerValue $outfile`
[ "$res" = "17 14 238 24" ]
${tools_dir}grib_get_data $outfile > /dev/null
rm -f $outfile