Merge branch 'develop' into bugfix/ECC-1431-CCSDS-OutputBufferSize

This commit is contained in:
Shahram Najm 2022-07-29 17:53:31 +01:00
commit ff7d5c6d63
24 changed files with 220 additions and 194 deletions

View File

@ -45,7 +45,7 @@ if (section2Used == 1) {
}
# See GRIB-911 re typeOfProcessedData values in UERRA
concept marsType {
concept marsType(unknown) {
fc = {
typeOfProcessedData = 1;
@ -73,20 +73,15 @@ concept marsType {
typeOfGeneratingProcess = 0;
generatingProcessIdentifier = 50;
}
"default" = {
dummyc = 0;
}
}
# See GRIB-205 re no_copy
# Cannot use typeOfProcessedData for stream. See GRIB-911
concept marsStream {
concept marsStream(unknown) {
oper = {
productDefinitionTemplateNumber = 8;
}
oper = {
productDefinitionTemplateNumber = 0;
}
@ -94,14 +89,9 @@ concept marsStream {
enda = {
productDefinitionTemplateNumber = 11;
}
enda = {
productDefinitionTemplateNumber = 1;
}
"default" = {
dummyc = 0;
}
} : no_copy;
alias mars.stream = marsStream;

View File

@ -24,8 +24,7 @@ if (centre is "cnmc" && subCentre == 102) {
unalias mars.domain;
concept marsType {
concept marsType(unknown) {
fc = {
typeOfProcessedData = 2;
}
@ -46,19 +45,13 @@ concept marsType {
"11" = {
typeOfProcessedData = 4;
}
"default" = {
dummyc = 0;
}
}
# See GRIB-205 re no_copy
concept marsStream {
concept marsStream(unknown) {
oper = {
typeOfProcessedData = 0;
}
oper = {
typeOfProcessedData = 2;
}
@ -66,18 +59,12 @@ concept marsStream {
enfo = {
typeOfProcessedData = 3;
}
enfo = {
typeOfProcessedData = 4;
}
enfo = {
typeOfProcessedData = 8;
}
"default" = {
dummyc = 0;
}
} : no_copy;
alias mars.stream = marsStream;

View File

@ -34,7 +34,7 @@ if (section2Used == 1) {
unalias mars.domain; # No mars domain needed
}
concept marsType {
concept marsType(unknown) {
fc = {
typeOfProcessedData = 2;
@ -56,19 +56,14 @@ concept marsType {
"11" = {
typeOfProcessedData = 4;
}
"default" = {
dummyc = 0;
}
}
# See GRIB-205 re no_copy
concept marsStream {
concept marsStream(unknown) {
oper = {
typeOfProcessedData = 0;
}
oper = {
typeOfProcessedData = 2;
}
@ -76,18 +71,12 @@ concept marsStream {
enfo = {
typeOfProcessedData = 3;
}
enfo = {
typeOfProcessedData = 4;
}
enfo = {
typeOfProcessedData = 8;
}
"default" = {
dummyc = 0;
}
} : no_copy;
alias mars.stream = marsStream;

View File

@ -40,8 +40,7 @@ alias mars.param = paramId;
alias mars.origin = centre;
# See GRIB-911 re typeOfProcessedData values in UERRA
concept marsType {
concept marsType(unknown) {
fc = {
typeOfProcessedData = 1;
}
@ -68,20 +67,14 @@ concept marsType {
typeOfGeneratingProcess = 0;
generatingProcessIdentifier = 50;
}
"default" = {
dummyc = 0;
}
}
# See GRIB-205 re no_copy
# Cannot use typeOfProcessedData for stream. See GRIB-911
concept marsStream {
concept marsStream(unknown) {
oper = {
productDefinitionTemplateNumber = 8;
}
oper = {
productDefinitionTemplateNumber = 0;
}
@ -89,14 +82,9 @@ concept marsStream {
enda = {
productDefinitionTemplateNumber = 11;
}
enda = {
productDefinitionTemplateNumber = 1;
}
"default" = {
dummyc = 0;
}
} : no_copy;
alias mars.stream = marsStream;

View File

@ -306,8 +306,12 @@ int grib_nearest_smaller_ieee_float(double a, double* ret)
init_table_if_needed();
if (a > ieee_table.vmax)
if (a > ieee_table.vmax) {
grib_context* c = grib_context_get_default();
grib_context_log(c, GRIB_LOG_ERROR,
"Number is too large: x=%e > xmax=%e (IEEE float)", a, ieee_table.vmax);
return GRIB_INTERNAL_ERROR;
}
l = grib_ieee_nearest_smaller_to_long(a);
*ret = grib_long_to_ieee(l);

View File

@ -92,6 +92,7 @@ if( HAVE_BUILD_TOOLS )
grib_packing_order
filter_substr
grib_uerra
grib_s2s
grib_fire
grib_element
grib_suppressed

View File

@ -3,7 +3,6 @@
*/
#include <time.h>
#include <pthread.h>
#include <assert.h>
#include <unistd.h>
#include "eccodes.h"
@ -26,13 +25,13 @@ static int encode_file(char* template_file, char* output_file)
int err = 0;
long numSubsets = 0;
assert(template_file);
Assert(template_file);
in = fopen(template_file, "rb");
assert(in);
Assert(in);
if (opt_write) {
assert(output_file);
Assert(output_file);
out = fopen(output_file, "wb");
assert(out);
Assert(out);
}
/* loop over the messages in the source BUFR and clone them */
@ -41,7 +40,7 @@ static int encode_file(char* template_file, char* output_file)
if (opt_clone) {
h = codes_handle_clone(source_handle);
assert(h);
Assert(h);
}
CODES_CHECK(codes_get_long(h, "numberOfSubsets", &numSubsets), 0);

View File

@ -12,7 +12,6 @@
* Check GRIB2 parameter concept file e.g. shortName.def, paramId.def
*/
#include <assert.h>
#include "grib_api_internal.h"
typedef struct grib_expression_long {
@ -154,7 +153,7 @@ int main(int argc, char** argv)
const char* concepts_key = argv[1];
const char* concepts_filename = argv[2];
assert(argc == 3);
Assert(argc == 3);
err = grib_check_param_concepts(concepts_key, concepts_filename);
if (err) return err;

View File

@ -10,8 +10,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <assert.h>
#include "grib_api.h"
#include "grib_api_internal.h"
#define NUM_THREADS 8
#define FILES_PER_ITERATION 10
@ -57,8 +57,8 @@ static int encode_file(char* input_file, char* output_file)
FILE* in = fopen(input_file, "rb");
FILE* out = fopen(output_file, "wb");
assert(in);
assert(out);
Assert(in);
Assert(out);
while ((source_handle = grib_handle_new_from_file(0, in, &err)) != NULL) {
size_t size = 0, values_len = 0;
@ -68,7 +68,7 @@ static int encode_file(char* input_file, char* output_file)
double d, e;
grib_handle* clone_handle = grib_handle_clone(source_handle);
assert(clone_handle);
Assert(clone_handle);
GRIB_CHECK(grib_get_size(clone_handle, "values", &values_len), 0);
values = (double*)malloc(values_len * sizeof(double));

View File

@ -227,7 +227,7 @@ cat >$tempFilt <<EOF
print "pl_scaled=[pl_scaled%.2f]";
EOF
${tools_dir}/grib_filter $tempFilt $input > $tempOut
cat $tempOut
cat >$tempRef <<EOF
pl_scaled=2.00 2.70 3.60 4.00 4.50 5.00 6.00 6.40
7.20 7.50 8.00 9.00 9.00 9.60 10.00 10.80
@ -242,6 +242,21 @@ EOF
diff $tempRef $tempOut
echo "Test IEEE float overflow"
# -----------------------------------------
input="${samp_dir}/GRIB2.tmpl"
cat >$tempFilt <<EOF
set values={ 5.4e100 };
write;
EOF
set +e
${tools_dir}/grib_filter $tempFilt $input 2> $tempOut
status=$?
set -e
[ $status -ne 0 ]
grep -q "ECCODES ERROR.*Number is too large" $tempOut
# Clean up
rm -f $tempGrib $tempFilt $tempOut $tempRef
rm -f ${data_dir}/formatint.rules ${data_dir}/binop.rules

View File

@ -1,36 +1,35 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "eccodes.h"
#include "grib_api_internal.h"
int main(int argc, char* argv[])
{
FILE* f = NULL;
codes_handle* h = NULL;
grib_handle* h = NULL;
int err = 0;
assert(argc == 2);
Assert(argc == 2);
f = fopen(argv[1], "rb");
assert(f);
Assert(f);
while ((h = codes_handle_new_from_file(0, f, PRODUCT_GRIB, &err)) != NULL) {
codes_keys_iterator* kiter = NULL;
while ((h = grib_handle_new_from_file(0, f, &err)) != NULL) {
grib_keys_iterator* kiter = NULL;
/* Use namespace of NULL to get ALL keys */
/* Set flags to 0 to not filter any keys */
kiter = codes_keys_iterator_new(h, /*flags=*/0, /*namespace=*/NULL);
assert(kiter);
kiter = grib_keys_iterator_new(h, /*flags=*/0, /*namespace=*/NULL);
Assert(kiter);
while (codes_keys_iterator_next(kiter)) {
const char* name = codes_keys_iterator_get_name(kiter);
assert(name);
while (grib_keys_iterator_next(kiter)) {
const char* name = grib_keys_iterator_get_name(kiter);
Assert(name);
printf("%s\n", name);
}
codes_keys_iterator_delete(kiter);
codes_handle_delete(h);
grib_keys_iterator_delete(kiter);
grib_handle_delete(h);
}
fclose(f);
return 0;

View File

@ -8,8 +8,8 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api.h"
#include <assert.h>
#include "grib_api_internal.h"
/*
* Test FA conversion to grib_api
* philippe.marguinaud@meteo.fr 02/2016
@ -849,7 +849,7 @@ int main(int argc, char* argv[])
size_t len = 0;
const char* outfile;
assert(argc == 2);
Assert(argc == 2);
outfile = argv[1];
GRIB_CHECK(((h = grib_handle_new_from_samples(NULL, "regular_ll_pl_grib2")) == NULL), 0);

View File

@ -13,7 +13,6 @@
*/
#include "grib_api_internal.h"
#include <assert.h>
static void usage(const char* prog)
@ -52,7 +51,7 @@ int main(int argc, char* argv[])
else
usage(argv[0]);
assert(filename);
Assert(filename);
f = fopen(filename, "rb");
if (!f) {
perror(filename);

View File

@ -8,8 +8,7 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include <assert.h>
#include "eccodes.h"
#include "grib_api_internal.h"
/* Values taken from an actual IFS forecast run for paramId=133 (Specific humidity) */
const double values[] = {
@ -24797,7 +24796,7 @@ int main(int argc, char** argv)
{
size_t values_len = sizeof(values)/sizeof(values[0]);
const char* sample_filename = "gg_sfc_grib2";
codes_handle* h = NULL;
grib_handle* h = NULL;
size_t str_len = 0;
PackingStage packing_stage;
char* packing_type;
@ -24817,28 +24816,28 @@ int main(int argc, char** argv)
outfile_name = argv[3];
fprintf(stderr,"Using sample_filename = %s\n", sample_filename);
h = codes_grib_handle_new_from_samples(0, sample_filename);
assert(h);
h = grib_handle_new_from_samples(0, sample_filename);
Assert(h);
if (strcmp(packing_type, "grid_second_order")==0 && packing_stage == VALUES_BEFORE_PACKING_TYPE) {
check = 0; /* TDOD */
}
CODES_CHECK(codes_set_long(h, "bitsPerValue", 16), 0);
GRIB_CHECK(grib_set_long(h, "bitsPerValue", 16), 0);
if (packing_stage == PACKING_TYPE_BEFORE_VALUES) {
fprintf(stderr,"Set packingType to %s\n", packing_type);
CODES_CHECK(codes_set_string(h, "packingType", packing_type, &str_len), 0);
GRIB_CHECK(grib_set_string(h, "packingType", packing_type, &str_len), 0);
}
fprintf(stderr,"Set values. values_len=%lu\n", (unsigned long)values_len);
CODES_CHECK(codes_set_double_array(h, "values", values, values_len), 0);
GRIB_CHECK(grib_set_double_array(h, "values", values, values_len), 0);
if (packing_stage == VALUES_BEFORE_PACKING_TYPE) {
fprintf(stderr, "Set packingType to %s\n", packing_type);
CODES_CHECK(codes_set_string(h, "packingType", packing_type, &str_len), 0);
GRIB_CHECK(grib_set_string(h, "packingType", packing_type, &str_len), 0);
}
CODES_CHECK(codes_write_message(h, outfile_name, "w"), 0);
GRIB_CHECK(grib_write_message(h, outfile_name, "w"), 0);
fprintf(stderr, "%s checks on decoded values '%s' (%s) ...\n",
(check?"Doing":"Skipping"), packing_type, argv[2]);
@ -24861,12 +24860,12 @@ int main(int argc, char** argv)
GRIB_CHECK(grib_get_long(h, "offsetBeforeData", &offsetBeforeData), 0);
calc = (offsetAfterData - offsetBeforeData) * 8.0 / values_len;
printf("bitsPerValue calculated as = (offsetAfterData - offsetBeforeData)*8/numValues = %g\n", calc);
assert( calc == 16 || calc == 32 || calc == 64 );
Assert( calc == 16 || calc == 32 || calc == 64 );
}
free(vals);
}
codes_handle_delete(h);
grib_handle_delete(h);
fprintf(stderr,"All done\n");
return 0;
}

43
tests/grib_s2s.sh Executable file
View File

@ -0,0 +1,43 @@
#!/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.ctest.sh
grib2_sample=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
label=grib_s2s_test
tempSample=tempSample.${label}.grib2
temp1=temp1.${label}.grib2
temp2=temp2.${label}.grib2
${tools_dir}/grib_set -s tablesVersion=14,productionStatusOfProcessedData=6 \
$grib2_sample $tempSample
# GRIB-761. For Italy, subCentre 102 is ISAC-CNR
# ----------------------------------------------
${tools_dir}/grib_set -s centre=cnmc,subCentre=102 $tempSample $temp1
grib_check_key_equals $temp1 mars.origin 'isac'
# ECC-1428. Valid and invalid mars types
# ---------------------------------------
${tools_dir}/grib_set -s marsType=fc $tempSample $temp1
${tools_dir}/grib_set -s marsType=cf $tempSample $temp1
${tools_dir}/grib_set -s marsType=pf $tempSample $temp1
set +e
${tools_dir}/grib_set -s marsType=xx $tempSample $temp1
status=$?
set -e
[ $status -ne 0 ]
# Clean up
rm -f $temp1 $temp2 $tempSample

View File

@ -10,8 +10,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "eccodes.h"
#include "grib_api_internal.h"
int main(int argc, char** argv)
{
@ -21,7 +21,7 @@ int main(int argc, char** argv)
const char* infile = "../data/test_uuid.grib2";
FILE* out = NULL;
const char* outfile = "temp.grib_set_bytes.grib";
codes_handle* h = NULL;
grib_handle* h = NULL;
const void* buffer = NULL;
unsigned char uuid_short[] = { /* not enough bytes */
@ -48,30 +48,30 @@ int main(int argc, char** argv)
size_t uuid_long_len = sizeof (uuid_long);
in = fopen(infile, "rb");
assert(in);
Assert(in);
out = fopen(outfile, "wb");
assert(out);
Assert(out);
h = codes_handle_new_from_file(0, in, PRODUCT_GRIB, &err);
assert(h);
h = grib_handle_new_from_file(0, in, &err);
Assert(h);
/* The uuidOfVGrid key is 16 bytes long */
err = codes_set_bytes(h, "uuidOfVGrid", uuid_short, &uuid_short_len);
assert(err == CODES_BUFFER_TOO_SMALL);
err = codes_set_bytes(h, "uuidOfVGrid", uuid_long, &uuid_long_len);
assert(err == CODES_BUFFER_TOO_SMALL);
err = grib_set_bytes(h, "uuidOfVGrid", uuid_short, &uuid_short_len);
Assert(err == GRIB_BUFFER_TOO_SMALL);
err = grib_set_bytes(h, "uuidOfVGrid", uuid_long, &uuid_long_len);
Assert(err == GRIB_BUFFER_TOO_SMALL);
/* This one should work */
err = codes_set_bytes(h, "uuidOfVGrid", uuid_good, &uuid_good_len);
assert(err == 0);
err = grib_set_bytes(h, "uuidOfVGrid", uuid_good, &uuid_good_len);
Assert(err == 0);
CODES_CHECK(codes_get_message(h, &buffer, &size), 0);
GRIB_CHECK(grib_get_message(h, &buffer, &size), 0);
if (fwrite(buffer, 1, size, out) != size) {
perror(argv[1]);
exit(1);
}
codes_handle_delete(h);
grib_handle_delete(h);
fclose(in);
fclose(out);
return 0;

View File

@ -8,11 +8,9 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "eccodes.h"
#include "grib_api_internal.h"
/*
* Start off with an input GRIB which already has a bitmap (which we do not change)
@ -151,50 +149,50 @@ int main(int argc, char** argv)
const char* outfile = NULL;
FILE* in = NULL;
FILE* out = NULL;
codes_handle* h = NULL;
grib_handle* h = NULL;
const void* buffer = NULL;
const char* mode = NULL;
assert(argc == 4);
Assert(argc == 4);
mode = argv[1]; /*all_values or coded_values*/
infile = argv[2];
outfile = argv[3];
in = fopen(infile, "rb");
assert(in);
Assert(in);
out = fopen(outfile, "wb");
assert(out);
Assert(out);
while ((h = codes_handle_new_from_file(NULL, in, PRODUCT_GRIB, &err)) != NULL || err != CODES_SUCCESS) {
while ((h = grib_handle_new_from_file(NULL, in, &err)) != NULL || err != GRIB_SUCCESS) {
long numberOfDataPoints = 0;
CODES_CHECK(codes_get_long(h, "numberOfDataPoints", &numberOfDataPoints), 0);
GRIB_CHECK(grib_get_long(h, "numberOfDataPoints", &numberOfDataPoints), 0);
if (strcmp(mode, "all_values") == 0) {
double missing = 9999;
const size_t num_all_vals = sizeof(values) / sizeof(values[0]);
assert(num_all_vals == numberOfDataPoints); /*Sanity check*/
CODES_CHECK(codes_set_long(h, "bitmapPresent", 1), 0);
CODES_CHECK(codes_set_double(h, "missingValue", missing), 0);
Assert(num_all_vals == numberOfDataPoints); /*Sanity check*/
GRIB_CHECK(grib_set_long(h, "bitmapPresent", 1), 0);
GRIB_CHECK(grib_set_double(h, "missingValue", missing), 0);
printf("Fully specified: %ld values\n", num_all_vals);
CODES_CHECK(codes_set_double_array(h, "values", values, num_all_vals), 0);
GRIB_CHECK(grib_set_double_array(h, "values", values, num_all_vals), 0);
}
else {
const size_t num_coded_vals = sizeof(codedValues) / sizeof(codedValues[0]);
assert(strcmp(mode, "coded_values") == 0);
assert(num_coded_vals < numberOfDataPoints); /*Sanity check*/
Assert(strcmp(mode, "coded_values") == 0);
Assert(num_coded_vals < numberOfDataPoints); /*Sanity check*/
printf("Partially specified: %ld values\n", num_coded_vals);
CODES_CHECK(codes_set_force_double_array(h, "codedValues", codedValues, num_coded_vals), 0);
GRIB_CHECK(grib_set_force_double_array(h, "codedValues", codedValues, num_coded_vals), 0);
}
/* Write out the new GRIB */
CODES_CHECK(codes_get_message(h, &buffer, &size), 0);
GRIB_CHECK(grib_get_message(h, &buffer, &size), 0);
if (fwrite(buffer, 1, size, out) != size) {
perror(outfile);
exit(1);
}
codes_handle_delete(h);
grib_handle_delete(h);
}
printf("Wrote %s\n", outfile);
fclose(in);

View File

@ -8,8 +8,7 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api.h"
#include <assert.h>
#include "grib_api_internal.h"
/*
* Check that first coefficient have an imaginary part equal to zero.
@ -30,7 +29,7 @@ int main(int argc, char* argv[])
int m, n, k;
const char* outfile;
assert(argc == 2);
Assert(argc == 2);
outfile = argv[1];
GRIB_CHECK(((h = grib_handle_new_from_samples(NULL, "sh_ml_grib2")) == NULL), 0);

View File

@ -8,8 +8,7 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api.h"
#include <assert.h>
#include "grib_api_internal.h"
#include "grib_sh_values.h" /* array 'values' defined here*/
@ -49,7 +48,7 @@ int main(int argc, char* argv[])
fout = fopen(TEMPFILE, "wb");
GRIB_CHECK(grib_get_message(h, &buffer, &size), 0);
if (fwrite(buffer, 1, size, fout) != size) {
assert(!"Failed to write data");
Assert(!"Failed to write data");
}
fclose(fout);
@ -80,8 +79,8 @@ int main(int argc, char* argv[])
/* Read in the saved GRIB file */
printf("Load values from saved file and compare....\n");
fin = fopen(TEMPFILE, "rb"); assert(fin);
h = grib_handle_new_from_file(0, fin, &err); assert(h);
fin = fopen(TEMPFILE, "rb"); Assert(fin);
h = grib_handle_new_from_file(0, fin, &err); Assert(h);
GRIB_CHECK(grib_get_double_array(h, "values", zval, &len), 0);
for (i = 0; i < ILCHAM; ++i) {
const double diff = fabs(zval[i] - values[i]);

View File

@ -3,10 +3,9 @@
*/
#include <time.h>
#include <pthread.h>
#include <assert.h>
#include <unistd.h>
#include "grib_api.h"
#include "grib_api_internal.h"
/* These are passed in via argv */
static size_t NUM_THREADS = 0;
@ -26,10 +25,10 @@ static int encode_file(char* template_file, char* output_file)
double* values;
in = fopen(template_file, "rb");
assert(in);
Assert(in);
if (opt_write && output_file) {
out = fopen(output_file, "wb");
assert(out);
Assert(out);
}
/* loop over the messages in the source GRIB and clone them */
@ -41,7 +40,7 @@ static int encode_file(char* template_file, char* output_file)
if (opt_clone) {
h = grib_handle_clone(source_handle);
assert(h);
Assert(h);
}
GRIB_CHECK(grib_get_size(h, "values", &values_len), 0);

View File

@ -107,4 +107,14 @@ for file in $tigge_bad_validity; do
grep -q "invalid validity Date/Time" $TEMP
done
# ECC-1428
# ----------
set +e
${tools_dir}/grib_set -s productionStatusOfProcessedData=5,marsType=xx $sample_g2 $TEMP
status=$?
set -e
[ $status -ne 0 ]
rm -f $TEMP

View File

@ -63,4 +63,15 @@ test_stream_and_type()
test_stream_and_type 'oper'
test_stream_and_type 'test'
# ECC-1428
# ----------
${tools_dir}/grib_set -s marsType=oi $tempSample $temp1
grib_check_key_equals $temp1 'mars.type' 'oi'
set +e
${tools_dir}/grib_set -s marsType=xx $tempSample $temp1
status=$?
set -e
[ $status -ne 0 ]
# Clean up
rm -f $temp1 $temp2 $tempSample

View File

@ -8,8 +8,7 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api.h"
#include <assert.h>
#include "grib_api_internal.h"
#define EPSILON 1e-12
#define DBL_EQUAL(a, b) (fabs((a) - (b)) <= (EPSILON)*fabs((a)))
@ -75,16 +74,16 @@ static void Test0()
sec = 24;
grib_datetime_to_julian(year, month, day, hour, min, sec, &jd);
assert(DBL_EQUAL(jd, 2378891.268333));
Assert(DBL_EQUAL(jd, 2378891.268333));
printf("%ld %ld %ld %ld:%ld:%ld -> %f\n", year, month, day, hour, min, sec, jd);
grib_julian_to_datetime(jd, &year, &month, &day, &hour, &min, &sec);
assert(year == 1801);
assert(month == 1);
assert(day == 30);
assert(hour == 18);
assert(min == 26);
assert(sec == 24);
Assert(year == 1801);
Assert(month == 1);
Assert(day == 30);
Assert(hour == 18);
Assert(min == 26);
Assert(sec == 24);
printf("%ld %ld %ld %ld:%ld:%ld -> %f\n", year, month, day, hour, min, sec, jd);
}
@ -103,16 +102,16 @@ static void Test1()
sec = 24;
grib_datetime_to_julian(year, month, day, hour, min, sec, &jd);
assert(DBL_EQUAL(jd, 2436116.31));
Assert(DBL_EQUAL(jd, 2436116.31));
printf("%ld %ld %ld %ld:%ld:%ld -> %f\n", year, month, day, hour, min, sec, jd);
grib_julian_to_datetime(jd, &year, &month, &day, &hour, &min, &sec);
assert(year == 1957);
assert(month == 10);
assert(day == 4);
assert(hour == 19);
assert(min == 26);
assert(sec == 24);
Assert(year == 1957);
Assert(month == 10);
Assert(day == 4);
Assert(hour == 19);
Assert(min == 26);
Assert(sec == 24);
printf("%ld %ld %ld %ld:%ld:%ld -> %f\n", year, month, day, hour, min, sec, jd);
}
@ -150,7 +149,7 @@ static void Test2()
if (!DBL_EQUAL(jd, jds[i])) {
fprintf(stderr, "i=%d: Got: %f, expected: %f\n", i, jd, jds[i]);
assert(0);
Assert(0);
}
jdl = (long)(jd + 0.5);

View File

@ -8,7 +8,6 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include <assert.h>
#include "grib_api_internal.h"
#define STR_EQUAL(s1, s2) (strcmp((s1), (s2)) == 0)
@ -23,7 +22,7 @@ typedef enum
static void compare_doubles(const double d1, const double d2, const double epsilon)
{
assert(fabs(d1 - d2) < epsilon);
Assert(fabs(d1 - d2) < epsilon);
}
static void check_float_representation(const double val, const double expected, const FloatRep rep)
@ -31,9 +30,9 @@ static void check_float_representation(const double val, const double expected,
double out = 0;
const double tolerance = 1e-9;
if (rep == IBM_FLOAT)
assert(grib_nearest_smaller_ibm_float(val, &out) == GRIB_SUCCESS);
Assert(grib_nearest_smaller_ibm_float(val, &out) == GRIB_SUCCESS);
else
assert(grib_nearest_smaller_ieee_float(val, &out) == GRIB_SUCCESS);
Assert(grib_nearest_smaller_ieee_float(val, &out) == GRIB_SUCCESS);
/*printf("%s: d1=%10.20f, out=%10.20f\n", (rep==IBM_FLOAT)?"ibm":"ieee", val, out);*/
@ -1400,9 +1399,9 @@ static void test_string_splitting()
printf("Testing: test_string_splitting...\n");
list = string_split(input, "|");
if (!list) { assert(!"List is NULL"); return; }
if (!list) { Assert(!"List is NULL"); return; }
for (i = 0; list[i] != NULL; ++i) {} /* count how many tokens */
assert(i == 4);
Assert(i == 4);
if (!list[0] || !STR_EQ(list[0], "Born")) Assert(0);
if (!list[1] || !STR_EQ(list[1], "To")) Assert(0);
if (!list[2] || !STR_EQ(list[2], "Be")) Assert(0);
@ -1413,22 +1412,22 @@ static void test_string_splitting()
strcpy(input, "12345|a gap|");
list = string_split(input, "|");
if (!list) { assert(0); return; }
if (!list) { Assert(0); return; }
for (i = 0; list[i] != NULL; ++i) {} /* count how many tokens */
assert(i == 2);
Assert(i == 2);
if (!list[0] || !STR_EQ(list[0], "12345")) Assert(0);
if (!list[1] || !STR_EQ(list[1], "a gap")) Assert(0);
assert(list[2] == NULL);
Assert(list[2] == NULL);
for (i = 0; list[i] != NULL; ++i) free(list[i]);
free(list);
strcpy(input, "Steppenwolf");
list = string_split(input, ",");
if (!list) { assert(0); return; }
if (!list) { Assert(0); return; }
for (i = 0; list[i] != NULL; ++i) {} /* count how many tokens */
assert(i == 1);
Assert(i == 1);
if (!list[0] || !STR_EQ(list[0], "Steppenwolf")) Assert(0);
assert(list[1] == NULL);
Assert(list[1] == NULL);
for (i = 0; list[i] != NULL; ++i) free(list[i]);
free(list);
@ -1449,7 +1448,7 @@ static void test_assertion_catching()
char empty[] = "";
char** list = 0;
int i = 0;
assert(assertion_caught == 0);
Assert(assertion_caught == 0);
codes_set_codes_assertion_failed_proc(&my_assertion_proc);
printf("Testing: test_assertion_catching...\n");
@ -1457,7 +1456,7 @@ static void test_assertion_catching()
/* Do something illegal */
list = string_split(empty, " ");
assert(assertion_caught == 1);
Assert(assertion_caught == 1);
/* Restore everything */
codes_set_codes_assertion_failed_proc(NULL);
@ -1512,34 +1511,34 @@ static void test_trimming()
printf("Testing: test_trimming...\n");
string_lrtrim(&pA, 0, 1); /*right only*/
assert( strcmp(pA, " Standing")==0 );
Assert( strcmp(pA, " Standing")==0 );
string_lrtrim(&pB, 1, 0); /*left only*/
assert( strcmp(pB, "Weeping ")==0 );
Assert( strcmp(pB, "Weeping ")==0 );
string_lrtrim(&pC, 1, 1); /*both ends*/
assert( strcmp(pC, "Silhouette")==0 );
Assert( strcmp(pC, "Silhouette")==0 );
string_lrtrim(&pD, 1, 1); /*make sure other spaces are not removed*/
assert( strcmp(pD, "The Forest Of October")==0 );
Assert( strcmp(pD, "The Forest Of October")==0 );
string_lrtrim(&pE, 1, 1); /* Other chars */
assert( strcmp(pE, "Apostle In Triumph")==0 );
Assert( strcmp(pE, "Apostle In Triumph")==0 );
}
static void test_string_ends_with()
{
printf("Testing: test_string_ends_with...\n");
assert( string_ends_with("GRIB2.tmpl", "tmpl") == 1 );
assert( string_ends_with("GRIB2.tmpl", ".tmpl") == 1 );
assert( string_ends_with("", "") == 1 );
assert( string_ends_with(".", ".") == 1 );
assert( string_ends_with("Bam", "") == 1 );
Assert( string_ends_with("GRIB2.tmpl", "tmpl") == 1 );
Assert( string_ends_with("GRIB2.tmpl", ".tmpl") == 1 );
Assert( string_ends_with("", "") == 1 );
Assert( string_ends_with(".", ".") == 1 );
Assert( string_ends_with("Bam", "") == 1 );
assert( string_ends_with("GRIB2.tmpl", "tmp") == 0 );
assert( string_ends_with("GRIB2.tmpl", "tmpl0") == 0 );
assert( string_ends_with("GRIB2.tmpl", "1.tmpl") == 0 );
assert( string_ends_with("GRIB2.tmpl", " ") == 0 );
Assert( string_ends_with("GRIB2.tmpl", "tmp") == 0 );
Assert( string_ends_with("GRIB2.tmpl", "tmpl0") == 0 );
Assert( string_ends_with("GRIB2.tmpl", "1.tmpl") == 0 );
Assert( string_ends_with("GRIB2.tmpl", " ") == 0 );
}
static void test_gribex_mode()
@ -1547,11 +1546,11 @@ static void test_gribex_mode()
grib_context* c = grib_context_get_default();
printf("Testing: test_gribex_mode...\n");
assert( grib_get_gribex_mode(c) == 0 ); /* default is OFF */
Assert( grib_get_gribex_mode(c) == 0 ); /* default is OFF */
grib_gribex_mode_on(c);
assert( grib_get_gribex_mode(c) == 1 );
Assert( grib_get_gribex_mode(c) == 1 );
grib_gribex_mode_off(c);
assert( grib_get_gribex_mode(c) == 0 );
Assert( grib_get_gribex_mode(c) == 0 );
}
int main(int argc, char** argv)