Merge branch 'feature/ECC-1137-bufr-fixed-length' into develop

This commit is contained in:
Shahram Najm 2020-07-28 17:05:27 +01:00
commit 57b2d991dc
7 changed files with 93 additions and 17 deletions

View File

@ -343,6 +343,8 @@ static int bufr_get_from_table(grib_accessor* a, bufr_descriptor* v)
int ret = 0;
char** list = 0;
char code[7] = { 0 };
const size_t maxlen_shortName = sizeof(v->shortName);
const size_t maxlen_units = sizeof(v->units);
grib_trie* table = load_bufr_elements_table(a, &ret);
if (ret)
@ -354,10 +356,12 @@ static int bufr_get_from_table(grib_accessor* a, bufr_descriptor* v)
if (!list)
return GRIB_NOT_FOUND;
v->shortName = grib_context_strdup(a->context, list[1]);
DebugAssert( strlen(list[1]) < maxlen_shortName );
strcpy(v->shortName, list[1]);
v->type = convert_type(list[2]);
/* v->name=grib_context_strdup(c,list[3]); See ECC-489 */
v->units = grib_context_strdup(a->context, list[4]);
DebugAssert( strlen(list[4]) < maxlen_units );
strcpy(v->units, list[4]);
/* ECC-985: Scale and reference are often 0 so we can reduce calls to atol */
v->scale = atol_fast(list[5]);

View File

@ -399,9 +399,9 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_
bufr_descriptor* au = grib_bufr_descriptor_new(self->tablesAccessor, 999999, err);
au->width = ccp->associatedFieldWidth;
grib_bufr_descriptor_set_scale(au, 0);
au->shortName = grib_context_strdup(c, "associatedField");
strcpy(au->shortName, "associatedField");
/* au->name=grib_context_strdup(c,"associated field"); See ECC-489 */
au->units = grib_context_strdup(c, "associated units");
strcpy(au->units, "associated units");
#if MYDEBUG
for (idepth = 0; idepth < global_depth; idepth++)
printf("\t");

View File

@ -820,8 +820,8 @@ struct bufr_descriptor
int Y;
int type;
/*char* name; Not needed: All usage commented out. See ECC-489 */
char* shortName;
char* units;
char shortName[128];
char units[128];
long scale;
double factor;
long reference;

View File

@ -35,8 +35,8 @@ bufr_descriptor* grib_bufr_descriptor_clone(bufr_descriptor* d)
cd->X = d->X;
cd->Y = d->Y;
/* cd->name=grib_context_strdup(d->context,d->name); See ECC-489 */
cd->shortName = grib_context_strdup(d->context, d->shortName);
cd->units = grib_context_strdup(d->context, d->units);
strcpy(cd->shortName, d->shortName);
strcpy(cd->units, d->units);
cd->scale = d->scale;
cd->factor = d->factor;
cd->width = d->width;
@ -50,14 +50,11 @@ bufr_descriptor* grib_bufr_descriptor_clone(bufr_descriptor* d)
int grib_bufr_descriptor_set_code(grib_accessor* tables_accessor, int code, bufr_descriptor* v)
{
int err = 0;
grib_context* c;
bufr_descriptor* d;
if (!v)
return GRIB_NULL_POINTER;
c = v->context;
if (v->type == BUFR_DESCRIPTOR_TYPE_REPLICATION || v->type == BUFR_DESCRIPTOR_TYPE_OPERATOR) {
v->code = code;
v->F = code / 100000;
@ -74,10 +71,10 @@ int grib_bufr_descriptor_set_code(grib_accessor* tables_accessor, int code, bufr
v->Y = d->Y;
/* grib_context_free(c,v->name); See ECC-489 */
/* v->name=grib_context_strdup(c,d->name); See ECC-489 */
grib_context_free(c, v->shortName);
v->shortName = grib_context_strdup(c, d->shortName);
grib_context_free(c, v->units);
v->units = grib_context_strdup(c, d->units);
strcpy(v->shortName,d->shortName);
strcpy(v->units,d->units);
v->scale = d->scale;
v->factor = d->factor;
v->width = d->width;
@ -130,7 +127,5 @@ void grib_bufr_descriptor_delete(bufr_descriptor* v)
c = v->context;
/* grib_context_free(c,v->name); See ECC-489 */
grib_context_free(c, v->shortName);
grib_context_free(c, v->units);
grib_context_free(c, v);
}

View File

@ -30,6 +30,7 @@ list( APPEND test_bins
bufr_ecc-517
bufr_get_element
bufr_extract_headers
bufr_check_descriptors
grib_sh_ieee64
ieee
grib_sh_imag
@ -52,6 +53,7 @@ list(APPEND tests_no_data_reqd
julian
grib_dump_samples
bufr_dump_samples
bufr_check_descriptors
definitions
grib_calendar
grib_md5

View File

@ -0,0 +1,59 @@
/*
* (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 <assert.h>
#include "grib_api_internal.h"
int main(int argc, char** argv)
{
char* filename = NULL;
FILE* fp = NULL;
char line[1024] = {0,};
char** list = NULL;
size_t i = 0, line_number = 0;
char* str_key = NULL;
char* str_units = NULL;
bufr_descriptor v = {0,};
const size_t maxlen_keyName = sizeof(v.shortName);
const size_t maxlen_units = sizeof(v.units);
Assert(argc == 2);
filename = argv[1];
fp = fopen(filename, "r");
Assert(fp);
while (fgets(line, sizeof(line) - 1, fp)) {
++line_number;
Assert(strlen(line) > 0);
if (line[0] == '#') continue; /* Ignore first line with column titles */
list = string_split(line, "|");
Assert(list);
str_key = list[1];
str_units = list[4];
if (strlen(str_key) >= maxlen_keyName) {
fprintf(stderr, "Error on line %lu: bufr_descriptor key name '%s' exceeds %lu characters.\n",
line_number, str_key, maxlen_keyName);
return 1;
}
if (strlen(str_units) >= maxlen_units) {
fprintf(stderr, "Error on line %lu: bufr_descriptor units '%s' exceeds %lu characters.\n",
line_number, str_units, maxlen_units);
return 1;
}
for (i = 0; list[i] != NULL; ++i) free(list[i]);
free(list);
}
fclose(fp);
return 0;
}

16
tests/bufr_check_descriptors.sh Executable file
View File

@ -0,0 +1,16 @@
#!/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
for file in `find ${ECCODES_DEFINITION_PATH}/bufr/ -name 'element.table' -print`
do
${test_dir}/bufr_check_descriptors $file
done