mirror of https://github.com/ecmwf/eccodes.git
Merge branch 'develop' into feature/ECC-1467_grib_power_single_precision
This commit is contained in:
commit
fb209c4404
|
@ -273,7 +273,6 @@ list( APPEND eccodes_src_files
|
|||
grib_dumper_class_serialize.cc
|
||||
grib_dumper_class_debug.cc
|
||||
grib_dumper_class_default.cc
|
||||
grib_dumper_class_keys.cc
|
||||
grib_dumper_class_bufr_encode_C.cc
|
||||
grib_dumper_class_bufr_encode_filter.cc
|
||||
grib_dumper_class_bufr_encode_fortran.cc
|
||||
|
@ -325,9 +324,6 @@ list( APPEND eccodes_src_files
|
|||
grib_expression_class_double.cc
|
||||
grib_expression_class_string.cc
|
||||
grib_expression_class_sub_string.cc
|
||||
grib_box.cc
|
||||
grib_box_class.cc
|
||||
grib_box_class_gen.cc
|
||||
grib_nearest.cc
|
||||
grib_nearest_class.cc
|
||||
grib_nearest_class_gen.cc
|
||||
|
@ -363,8 +359,6 @@ list( APPEND eccodes_src_files
|
|||
grib_accessor_factory.h
|
||||
grib_api_internal.h
|
||||
eccodes_prototypes.h
|
||||
grib_box_class.h
|
||||
grib_box_factory.h
|
||||
grib_dumper_class.h
|
||||
grib_dumper_factory.h
|
||||
grib_emoslib.h
|
||||
|
|
|
@ -784,7 +784,7 @@ static const char* codes_bufr_header_get_centre_name(long edition, long centre_c
|
|||
}
|
||||
|
||||
#if defined(BUFR_PROCESS_CODE_TABLE)
|
||||
// TODO: Not efficient as it opens the code table every time
|
||||
// TODO(masn): Not efficient as it opens the code table every time
|
||||
static char* codes_bufr_header_get_centre_name(long edition, long centre_code)
|
||||
{
|
||||
char full_path[2014] = {0,};
|
||||
|
|
|
@ -0,0 +1,273 @@
|
|||
/*
|
||||
* (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.
|
||||
*/
|
||||
|
||||
/******************************
|
||||
* Enrico Fucile
|
||||
*****************************/
|
||||
|
||||
#include "grib_api_internal.h"
|
||||
|
||||
/*
|
||||
This is used by make_class.pl
|
||||
|
||||
START_CLASS_DEF
|
||||
CLASS = accessor
|
||||
SUPER = grib_accessor_class_gen
|
||||
IMPLEMENTS = init
|
||||
IMPLEMENTS = unpack_double
|
||||
IMPLEMENTS = pack_double
|
||||
IMPLEMENTS = value_count
|
||||
MEMBERS=const char* missing_value
|
||||
MEMBERS=const char* number_of_values
|
||||
MEMBERS=const char* number_of_points
|
||||
MEMBERS=const char* latitude_of_first_point
|
||||
MEMBERS=const char* ni
|
||||
|
||||
END_CLASS_DEF
|
||||
*/
|
||||
|
||||
/* START_CLASS_IMP */
|
||||
|
||||
/*
|
||||
|
||||
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
|
||||
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
|
||||
or edit "accessor.class" and rerun ./make_class.pl
|
||||
|
||||
*/
|
||||
|
||||
static int pack_double(grib_accessor*, const double* val, size_t* len);
|
||||
static int unpack_double(grib_accessor*, double* val, size_t* len);
|
||||
static int value_count(grib_accessor*, long*);
|
||||
static void init(grib_accessor*, const long, grib_arguments*);
|
||||
//static void init_class(grib_accessor_class*);
|
||||
|
||||
typedef struct grib_accessor_gds_not_present_bitmap
|
||||
{
|
||||
grib_accessor att;
|
||||
/* Members defined in gen */
|
||||
/* Members defined in gds_not_present_bitmap */
|
||||
const char* missing_value;
|
||||
const char* number_of_values;
|
||||
const char* number_of_points;
|
||||
const char* latitude_of_first_point;
|
||||
const char* ni;
|
||||
} grib_accessor_gds_not_present_bitmap;
|
||||
|
||||
extern grib_accessor_class* grib_accessor_class_gen;
|
||||
|
||||
static grib_accessor_class _grib_accessor_class_gds_not_present_bitmap = {
|
||||
&grib_accessor_class_gen, /* super */
|
||||
"gds_not_present_bitmap", /* name */
|
||||
sizeof(grib_accessor_gds_not_present_bitmap), /* size */
|
||||
0, /* inited */
|
||||
0, /* init_class */
|
||||
&init, /* init */
|
||||
0, /* post_init */
|
||||
0, /* destroy */
|
||||
0, /* dump */
|
||||
0, /* next_offset */
|
||||
0, /* get length of string */
|
||||
&value_count, /* get number of values */
|
||||
0, /* get number of bytes */
|
||||
0, /* get offset to bytes */
|
||||
0, /* get native type */
|
||||
0, /* get sub_section */
|
||||
0, /* pack_missing */
|
||||
0, /* is_missing */
|
||||
0, /* pack_long */
|
||||
0, /* unpack_long */
|
||||
&pack_double, /* pack_double */
|
||||
0, /* pack_float */
|
||||
&unpack_double, /* unpack_double */
|
||||
0, /* unpack_float */
|
||||
0, /* pack_string */
|
||||
0, /* unpack_string */
|
||||
0, /* pack_string_array */
|
||||
0, /* unpack_string_array */
|
||||
0, /* pack_bytes */
|
||||
0, /* unpack_bytes */
|
||||
0, /* pack_expression */
|
||||
0, /* notify_change */
|
||||
0, /* update_size */
|
||||
0, /* preferred_size */
|
||||
0, /* resize */
|
||||
0, /* nearest_smaller_value */
|
||||
0, /* next accessor */
|
||||
0, /* compare vs. another accessor */
|
||||
0, /* unpack only ith value (double) */
|
||||
0, /* unpack only ith value (float) */
|
||||
0, /* unpack a given set of elements (double) */
|
||||
0, /* unpack a given set of elements (float) */
|
||||
0, /* unpack a subarray */
|
||||
0, /* clear */
|
||||
0, /* clone accessor */
|
||||
};
|
||||
|
||||
|
||||
grib_accessor_class* grib_accessor_class_gds_not_present_bitmap = &_grib_accessor_class_gds_not_present_bitmap;
|
||||
|
||||
|
||||
//static void init_class(grib_accessor_class* c)
|
||||
//{
|
||||
// INIT
|
||||
//}
|
||||
|
||||
/* END_CLASS_IMP */
|
||||
|
||||
static void init(grib_accessor* a, const long v, grib_arguments* args)
|
||||
{
|
||||
int n = 0;
|
||||
grib_accessor_gds_not_present_bitmap* self = (grib_accessor_gds_not_present_bitmap*)a;
|
||||
|
||||
self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->number_of_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->number_of_points = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->latitude_of_first_point = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->ni = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
a->length = 0;
|
||||
}
|
||||
|
||||
static int value_count(grib_accessor* a, long* number_of_points)
|
||||
{
|
||||
grib_accessor_gds_not_present_bitmap* self = (grib_accessor_gds_not_present_bitmap*)a;
|
||||
*number_of_points = 0;
|
||||
return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_points, number_of_points);
|
||||
}
|
||||
|
||||
static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_gds_not_present_bitmap* self = (grib_accessor_gds_not_present_bitmap*)a;
|
||||
|
||||
long number_of_points = 0, number_of_values = 0, ni = 0;
|
||||
long latitude_of_first_point = 0;
|
||||
size_t i = 0;
|
||||
size_t n_vals = 0;
|
||||
long nn = 0;
|
||||
long missing_value;
|
||||
|
||||
int err = 0;
|
||||
double* coded_vals = NULL;
|
||||
err = grib_value_count(a, &nn);
|
||||
n_vals = nn;
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long(grib_handle_of_accessor(a), self->number_of_points, &number_of_points)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long(grib_handle_of_accessor(a), self->number_of_values, &number_of_values)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long(grib_handle_of_accessor(a), self->latitude_of_first_point, &latitude_of_first_point)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long(grib_handle_of_accessor(a), self->missing_value, &missing_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long(grib_handle_of_accessor(a), self->ni, &ni)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if (*len < number_of_points) {
|
||||
*len = n_vals;
|
||||
return GRIB_ARRAY_TOO_SMALL;
|
||||
}
|
||||
|
||||
if (number_of_values > 0) {
|
||||
coded_vals = (double*)grib_context_malloc(a->context, number_of_values * sizeof(double));
|
||||
|
||||
if (coded_vals == NULL)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (latitude_of_first_point == 0) {
|
||||
for (i = 0; i < number_of_values; i++)
|
||||
val[i] = 1;
|
||||
for (i = number_of_values; i < number_of_points; i++)
|
||||
val[i] = 0;
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < ni - 1; i++)
|
||||
val[i] = 0;
|
||||
for (i = ni - 1; i < number_of_points; i++)
|
||||
val[i] = 1;
|
||||
}
|
||||
|
||||
*len = number_of_points;
|
||||
|
||||
grib_context_free(a->context, coded_vals);
|
||||
return err;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
static void grib_set_bit_on( unsigned char* p, long *bitp){
|
||||
unsigned char o = 1;
|
||||
p += (*bitp >> 3);
|
||||
o <<= 7-((*bitp)%8);
|
||||
*p |= o;
|
||||
(*bitp)+=1;
|
||||
}
|
||||
static int pack_double(grib_accessor* a, const double* val,size_t *len)
|
||||
{
|
||||
grib_accessor_gds_not_present_bitmap* self = (grib_accessor_gds_not_present_bitmap*)a;
|
||||
|
||||
size_t tlen;
|
||||
|
||||
unsigned char* buf = NULL;
|
||||
long i;
|
||||
int err = 0;
|
||||
long pos = 0;
|
||||
long bmaplen = 0;
|
||||
const int bit_padding = 16;
|
||||
double miss_values = 0;
|
||||
tlen = ((*len+bit_padding-1)/bit_padding*bit_padding)/8;
|
||||
|
||||
if((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &miss_values)) != GRIB_SUCCESS)
|
||||
{
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_class_bitmap : pack_double : Cannot unpack %s err=%d ",self->missing_value,err);
|
||||
return err;
|
||||
}
|
||||
|
||||
buf = grib_context_malloc_clear(a->context,tlen);
|
||||
if(!buf) return GRIB_OUT_OF_MEMORY;
|
||||
pos=0;
|
||||
for(i=0;i<*len;i++)
|
||||
{
|
||||
if (val[i] == miss_values)
|
||||
pos++;
|
||||
else{
|
||||
bmaplen++;
|
||||
grib_set_bit_on(buf, &pos);
|
||||
}
|
||||
}
|
||||
|
||||
if((err = grib_set_long_internal(grib_handle_of_accessor(a), self->unusedBits,tlen*8 - *len )) != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_class_bitmap : pack_double : Cannot pack %s err=%d ",self->unusedBits,err);
|
||||
grib_context_free(a->context,buf);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
grib_buffer_replace(a, buf, tlen,1,1);
|
||||
|
||||
grib_context_free(a->context,buf);
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
{
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -156,7 +156,6 @@ typedef struct grib_iterator codes_iterator;
|
|||
\struct codes_nearest
|
||||
*/
|
||||
typedef struct grib_nearest codes_nearest;
|
||||
typedef struct grib_points codes_points;
|
||||
|
||||
/*! Codes keys iterator. Iterator over keys.
|
||||
\ingroup keys_iterator
|
||||
|
|
|
@ -886,8 +886,6 @@ void grib_dump_footer(grib_dumper* d, const grib_handle* h);
|
|||
|
||||
/* grib_dumper_class_default.cc*/
|
||||
|
||||
/* grib_dumper_class_keys.cc*/
|
||||
|
||||
/* grib_dumper_class_bufr_encode_C.cc*/
|
||||
|
||||
/* grib_dumper_class_bufr_encode_filter.cc*/
|
||||
|
@ -1256,7 +1254,6 @@ int grib_get_double_element_set(const grib_handle* h, const char* name, const si
|
|||
int grib_get_float_element_set_internal(grib_handle* h, const char* name, const size_t* index_array, size_t len, float* val_array);
|
||||
int grib_get_float_element_set(const grib_handle* h, const char* name, const size_t* index_array, size_t len, float* val_array);
|
||||
|
||||
int grib_points_get_values(grib_handle* h, grib_points* points, double* val);
|
||||
int grib_get_double_elements(const grib_handle* h, const char* name, const int* index_array, long len, double* val_array);
|
||||
int grib_get_float_elements(const grib_handle* h, const char* name, const int* index_array, long len, float* val_array);
|
||||
int grib_get_string_internal(grib_handle* h, const char* name, char* val, size_t* length);
|
||||
|
@ -1347,15 +1344,6 @@ grib_expression* new_string_expression(grib_context* c, const char* value);
|
|||
/* grib_expression_class_sub_string.cc*/
|
||||
grib_expression* new_sub_string_expression(grib_context* c, const char* value, size_t start, size_t length);
|
||||
|
||||
/* grib_box.cc*/
|
||||
int grib_box_init(grib_box* box, grib_handle* h, grib_arguments* args);
|
||||
void grib_points_delete(grib_points* points);
|
||||
|
||||
/* grib_box_class.cc*/
|
||||
grib_box* grib_box_factory(grib_handle* h, grib_arguments* args);
|
||||
|
||||
/* grib_box_class_gen.cc*/
|
||||
|
||||
/* grib_nearest.cc*/
|
||||
int grib_nearest_find(grib_nearest* nearest, const grib_handle* h, double inlat, double inlon, unsigned long flags, double* outlats, double* outlons, double* values, double* distances, int* indexes, size_t* len);
|
||||
int grib_nearest_init(grib_nearest* i, grib_handle* h, grib_arguments* args);
|
||||
|
|
|
@ -882,18 +882,3 @@ void grib_accessors_list_delete(grib_context* c, grib_accessors_list* al)
|
|||
al = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
void grib_print_accessor_flags(const grib_accessor* acc)
|
||||
{
|
||||
const unsigned long f = acc->flags;
|
||||
if (f & GRIB_ACCESSOR_FLAG_READ_ONLY) printf("READ_ONLY ");
|
||||
if (f & GRIB_ACCESSOR_FLAG_DUMP) printf("DUMP ");
|
||||
if (f & GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC) printf("EDITION_SPECIFIC ");
|
||||
if (f & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) printf("CAN_BE_MISSING ");
|
||||
if (f & GRIB_ACCESSOR_FLAG_LOWERCASE) printf("LOWERCASE ");
|
||||
if (f & GRIB_ACCESSOR_FLAG_HIDDEN) printf("HIDDEN ");
|
||||
/* TODO: the rest */
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -2322,11 +2322,9 @@ static int is_bitmap_start_descriptor(grib_accessors_list* al, int* err)
|
|||
case 237000:
|
||||
/*case 243000:*/
|
||||
{
|
||||
#if 0
|
||||
long index[1];
|
||||
grib_accessor* anindex=grib_accessor_get_attribute(al->accessor,"index");
|
||||
grib_unpack_long(anindex,index,&l);
|
||||
#endif
|
||||
//long index[1];
|
||||
//grib_accessor* anindex=grib_accessor_get_attribute(al->accessor,"index");
|
||||
//grib_unpack_long(anindex,index,&l);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -2412,20 +2410,19 @@ static grib_accessor* accessor_or_attribute_with_same_name(grib_accessor* a, con
|
|||
return ok;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
static int get_key_rank(grib_trie* accessorsRank,grib_accessor* a)
|
||||
{
|
||||
int* r=(int*)grib_trie_get(accessorsRank,a->name);
|
||||
|
||||
if (r) (*r)++;
|
||||
else {
|
||||
r=(int*)grib_context_malloc(a->context,sizeof(int));
|
||||
*r=1;
|
||||
grib_trie_insert(accessorsRank,a->name,(void*)r);
|
||||
}
|
||||
return *r;
|
||||
}
|
||||
#endif
|
||||
// static int get_key_rank(grib_trie* accessorsRank,grib_accessor* a)
|
||||
// {
|
||||
// int* r=(int*)grib_trie_get(accessorsRank,a->name);
|
||||
// if (r) (*r)++;
|
||||
// else {
|
||||
// r=(int*)grib_context_malloc(a->context,sizeof(int));
|
||||
// *r=1;
|
||||
// grib_trie_insert(accessorsRank,a->name,(void*)r);
|
||||
// }
|
||||
// return *r;
|
||||
// }
|
||||
|
||||
static int grib_data_accessors_trie_push(grib_trie_with_rank* accessorsTrie, grib_accessor* a)
|
||||
{
|
||||
return grib_trie_with_rank_insert(accessorsTrie, a->name, a);
|
||||
|
|
|
@ -160,11 +160,9 @@ static int grib_get_codeflag(grib_accessor* a, long code, char* codename)
|
|||
return GRIB_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
#if 0
|
||||
strcpy(codename, self->tablename);
|
||||
strcat(codename,": ");
|
||||
j = strlen(codename);
|
||||
#endif
|
||||
// strcpy(codename, self->tablename);
|
||||
// strcat(codename,": ");
|
||||
// j = strlen(codename);
|
||||
|
||||
while (fgets(line, sizeof(line) - 1, f)) {
|
||||
sscanf(line, "%49s %49s", num, bval);
|
||||
|
|
|
@ -455,10 +455,10 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
|
|||
char buf[80];
|
||||
size_t s;
|
||||
snprintf(buf, sizeof(buf), "%ld", *val);
|
||||
#if 0
|
||||
if(*len > 1)
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
//if(*len > 1)
|
||||
// return GRIB_NOT_IMPLEMENTED;
|
||||
|
||||
s = strlen(buf) + 1;
|
||||
return pack_string(a, buf, &s);
|
||||
}
|
||||
|
@ -589,62 +589,56 @@ static int get_native_type(grib_accessor* a)
|
|||
|
||||
static void destroy(grib_context* c, grib_accessor* a)
|
||||
{
|
||||
/*
|
||||
* grib_accessor_concept *self = (grib_accessor_concept*)a;
|
||||
* grib_context_free(c,self->cval);
|
||||
*/
|
||||
//grib_accessor_concept *self = (grib_accessor_concept*)a;
|
||||
//grib_context_free(c,self->cval);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int is_local_ecmwf_grib2_param_key(grib_accessor* a, long edition, long centre)
|
||||
{
|
||||
if (edition == 2 && centre == 98) {
|
||||
if (a->parent->owner && a->parent->owner->name && strcmp(a->parent->owner->name, "parameters") == 0)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
// static int is_local_ecmwf_grib2_param_key(grib_accessor* a, long edition, long centre)
|
||||
// {
|
||||
// if (edition == 2 && centre == 98) {
|
||||
// if (a->parent->owner && a->parent->owner->name && strcmp(a->parent->owner->name, "parameters") == 0)
|
||||
// return 1;
|
||||
// }
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
#if 0
|
||||
/* Try to get the name, shortName, units etc for a GRIB2 message with
|
||||
* local ECMWF coding i.e. discipline=192 etc
|
||||
*/
|
||||
static const char* get_ECMWF_local_parameter(grib_accessor* a, grib_handle* h)
|
||||
{
|
||||
int err = 0;
|
||||
const char* key_name = a->name; /*this is the key whose value we want*/
|
||||
long edition, centre;
|
||||
if (h->product_kind != PRODUCT_GRIB)
|
||||
return NULL;
|
||||
err = grib_get_long(h, "centre", ¢re);
|
||||
if (err)
|
||||
return NULL;
|
||||
err = grib_get_long(h, "edition", &edition);
|
||||
if (err)
|
||||
return NULL;
|
||||
if (is_local_ecmwf_grib2_param_key(a, edition, centre)) {
|
||||
/* Must be one of: 'name', 'shortName', 'units', 'cfName' etc */
|
||||
grib_accessor* a2 = NULL;
|
||||
const long pid_guess = guess_paramId(h);
|
||||
if (pid_guess == -1)
|
||||
return NULL;
|
||||
// /* Try to get the name, shortName, units etc for a GRIB2 message with
|
||||
// * local ECMWF coding i.e. discipline=192 etc
|
||||
// */
|
||||
// static const char* get_ECMWF_local_parameter(grib_accessor* a, grib_handle* h)
|
||||
// {
|
||||
// int err = 0;
|
||||
// const char* key_name = a->name; /*this is the key whose value we want*/
|
||||
// long edition, centre;
|
||||
// if (h->product_kind != PRODUCT_GRIB)
|
||||
// return NULL;
|
||||
// err = grib_get_long(h, "centre", ¢re);
|
||||
// if (err)
|
||||
// return NULL;
|
||||
// err = grib_get_long(h, "edition", &edition);
|
||||
// if (err)
|
||||
// return NULL;
|
||||
// if (is_local_ecmwf_grib2_param_key(a, edition, centre)) {
|
||||
// /* Must be one of: 'name', 'shortName', 'units', 'cfName' etc */
|
||||
// grib_accessor* a2 = NULL;
|
||||
// const long pid_guess = guess_paramId(h);
|
||||
// if (pid_guess == -1)
|
||||
// return NULL;
|
||||
|
||||
/* Change the paramId so we can get the other string key*/
|
||||
err = grib_set_long(h, "paramId", pid_guess);
|
||||
if (err)
|
||||
return NULL;
|
||||
/* Get the string value of key. Do not call grib_get_string() to avoid
|
||||
* dangers of infinite recursion as that calls unpack_string()!
|
||||
*/
|
||||
a2 = grib_find_accessor(h, key_name);
|
||||
if (!a2)
|
||||
return NULL;
|
||||
return concept_evaluate(a2);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
// /* Change the paramId so we can get the other string key*/
|
||||
// err = grib_set_long(h, "paramId", pid_guess);
|
||||
// if (err)
|
||||
// return NULL;
|
||||
// /* Get the string value of key. Do not call grib_get_string() to avoid
|
||||
// * dangers of infinite recursion as that calls unpack_string()!
|
||||
// */
|
||||
// a2 = grib_find_accessor(h, key_name);
|
||||
// if (!a2)
|
||||
// return NULL;
|
||||
// return concept_evaluate(a2);
|
||||
// }
|
||||
// return NULL;
|
||||
// }
|
||||
|
||||
static int unpack_string(grib_accessor* a, char* val, size_t* len)
|
||||
{
|
||||
|
@ -669,14 +663,14 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len)
|
|||
}
|
||||
strcpy(val, p); /* NOLINT: CWE-119 clang-analyzer-security.insecureAPI.strcpy */
|
||||
*len = slen;
|
||||
#if 0
|
||||
if (a->context->debug==1) {
|
||||
int err = 0;
|
||||
char result[1024] = {0,};
|
||||
err = get_concept_condition_string(grib_handle_of_accessor(a), a->name, val, result);
|
||||
if (!err) fprintf(stderr, "ECCODES DEBUG concept name=%s, value=%s, conditions=%s\n", a->name, val, result);
|
||||
}
|
||||
#endif
|
||||
|
||||
// if (a->context->debug==1) {
|
||||
// int err = 0;
|
||||
// char result[1024] = {0,};
|
||||
// err = get_concept_condition_string(grib_handle_of_accessor(a), a->name, val, result);
|
||||
// if (!err) fprintf(stderr, "ECCODES DEBUG concept name=%s, value=%s, conditions=%s\n", a->name, val, result);
|
||||
// }
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -391,7 +391,7 @@ static void uint_char(unsigned int i, unsigned char* p)
|
|||
p[1] = (i >> 16) & 255;
|
||||
p[2] = (i >> 8) & 255;
|
||||
p[3] = (i)&255;
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned char* mk_bms(grib_accessor* a, double* data, unsigned int* ndata)
|
||||
{
|
||||
|
|
|
@ -105,15 +105,12 @@ grib_accessor_class* grib_accessor_class_forward = &_grib_accessor_class_forward
|
|||
|
||||
static void dump(grib_accessor* a, grib_dumper* dumper)
|
||||
{
|
||||
#if 0
|
||||
/* grib_accessor_forward* self = (grib_accessor_forward*)a; */
|
||||
grib_accessor *target = grib_find_accessor(grib_handle_of_accessor(a),a->alias);
|
||||
if(target) {
|
||||
grib_dump_label(dumper,a,"is:");
|
||||
dumper->depth += 2;
|
||||
grib_accessor_dump(target, dumper);
|
||||
dumper->depth -= 2;
|
||||
}
|
||||
else grib_dump_label(dumper,a," undefined ");
|
||||
#endif
|
||||
// grib_accessor *target = grib_find_accessor(grib_handle_of_accessor(a),a->alias);
|
||||
// if(target) {
|
||||
// grib_dump_label(dumper,a,"is:");
|
||||
// dumper->depth += 2;
|
||||
// grib_accessor_dump(target, dumper);
|
||||
// dumper->depth -= 2;
|
||||
// }
|
||||
// else grib_dump_label(dumper,a," undefined ");
|
||||
}
|
||||
|
|
|
@ -110,7 +110,6 @@ grib_accessor_class* grib_accessor_class_g1_section4_length = &_grib_accessor_cl
|
|||
|
||||
/* END_CLASS_IMP */
|
||||
|
||||
|
||||
static void init(grib_accessor* a, const long len, grib_arguments* args)
|
||||
{
|
||||
grib_accessor_g1_section4_length* self = (grib_accessor_g1_section4_length*)a;
|
||||
|
@ -119,36 +118,31 @@ static void init(grib_accessor* a, const long len, grib_arguments* args)
|
|||
|
||||
static int pack_long(grib_accessor* a, const long* val, size_t* len)
|
||||
{
|
||||
#if 0
|
||||
grib_accessor_class* super = *(a->cclass->super);
|
||||
// Old implementation:
|
||||
// Here we assume that the totalLength will be coded AFTER the section4 length, and
|
||||
// the section4 length will be overwritten by the totalLength accessor for large GRIBs
|
||||
// grib_accessor_class* super = *(a->cclass->super);
|
||||
// return super->pack_long(a,val,len);
|
||||
|
||||
/* Here we assume that the totalLength will be coded AFTER the section4 length, and
|
||||
the section4 length will be overwritten by the totalLength accessor for large GRIBs */
|
||||
|
||||
/*printf("UPDATING sec4len %ld\n",*val);*/
|
||||
|
||||
return super->pack_long(a,val,len);
|
||||
#endif
|
||||
/* Do not directly call pack_long on base class */
|
||||
/* because in this special case we want to skip the checks. */
|
||||
/* So we call the helper function which has an extra argument */
|
||||
// Note: Do not directly call pack_long on base class
|
||||
// because in this special case we want to skip the checks.
|
||||
// So we call the helper function which has an extra argument
|
||||
return pack_long_unsigned_helper(a, val, len, /*check=*/0);
|
||||
}
|
||||
|
||||
static int unpack_long(grib_accessor* a, long* val, size_t* len)
|
||||
{
|
||||
grib_accessor_g1_section4_length* self = (grib_accessor_g1_section4_length*)a;
|
||||
int ret;
|
||||
|
||||
long total_length, sec4_length;
|
||||
int ret = 0;
|
||||
long total_length = 0, sec4_length = 0;
|
||||
|
||||
if ((ret = grib_get_g1_message_size(grib_handle_of_accessor(a),
|
||||
grib_find_accessor(grib_handle_of_accessor(a), self->total_length),
|
||||
a,
|
||||
&total_length,
|
||||
&sec4_length)) != GRIB_SUCCESS)
|
||||
&sec4_length)) != GRIB_SUCCESS) {
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
*val = sec4_length;
|
||||
|
||||
|
|
|
@ -121,10 +121,11 @@ static void init(grib_accessor* a, const long l, grib_arguments* c)
|
|||
{
|
||||
int n = 0;
|
||||
grib_accessor_gds_is_present* self = (grib_accessor_gds_is_present*)a;
|
||||
self->gds_present = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
|
||||
self->grid_definition = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
|
||||
self->bitmap_present = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
|
||||
self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
self->gds_present = grib_arguments_get_name(h, c, n++);
|
||||
self->grid_definition = grib_arguments_get_name(h, c, n++);
|
||||
self->bitmap_present = grib_arguments_get_name(h, c, n++);
|
||||
self->values = grib_arguments_get_name(h, c, n++);
|
||||
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN;
|
||||
|
@ -133,13 +134,13 @@ static void init(grib_accessor* a, const long l, grib_arguments* c)
|
|||
|
||||
static int pack_long(grib_accessor* a, const long* val, size_t* len)
|
||||
{
|
||||
long missing = 255;
|
||||
int ret = 0;
|
||||
size_t size = 0;
|
||||
double* values;
|
||||
grib_context* c = a->context;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
grib_accessor_gds_is_present* self = (grib_accessor_gds_is_present*)a;
|
||||
long missing = 255;
|
||||
int ret = 0;
|
||||
size_t size = 0;
|
||||
double* values = NULL;
|
||||
grib_context* c = a->context;
|
||||
grib_handle* h = grib_handle_of_accessor(a);
|
||||
|
||||
if (*val != 1)
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
|
|
|
@ -126,12 +126,13 @@ static void init(grib_accessor* a, const long v, grib_arguments* args)
|
|||
{
|
||||
int n = 0;
|
||||
grib_accessor_gds_not_present_bitmap* self = (grib_accessor_gds_not_present_bitmap*)a;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
|
||||
self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->number_of_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->number_of_points = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->latitude_of_first_point = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->ni = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
|
||||
self->missing_value = grib_arguments_get_name(hand, args, n++);
|
||||
self->number_of_values = grib_arguments_get_name(hand, args, n++);
|
||||
self->number_of_points = grib_arguments_get_name(hand, args, n++);
|
||||
self->latitude_of_first_point = grib_arguments_get_name(hand, args, n++);
|
||||
self->ni = grib_arguments_get_name(hand, args, n++);
|
||||
a->length = 0;
|
||||
}
|
||||
|
||||
|
@ -145,6 +146,7 @@ static int value_count(grib_accessor* a, long* number_of_points)
|
|||
static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
||||
{
|
||||
grib_accessor_gds_not_present_bitmap* self = (grib_accessor_gds_not_present_bitmap*)a;
|
||||
grib_handle* hand = grib_handle_of_accessor(a);
|
||||
|
||||
long number_of_points = 0, number_of_values = 0, ni = 0;
|
||||
long latitude_of_first_point = 0;
|
||||
|
@ -160,19 +162,19 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
|||
if (err)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long(grib_handle_of_accessor(a), self->number_of_points, &number_of_points)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long(hand, self->number_of_points, &number_of_points)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long(grib_handle_of_accessor(a), self->number_of_values, &number_of_values)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long(hand, self->number_of_values, &number_of_values)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long(grib_handle_of_accessor(a), self->latitude_of_first_point, &latitude_of_first_point)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long(hand, self->latitude_of_first_point, &latitude_of_first_point)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long(grib_handle_of_accessor(a), self->missing_value, &missing_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long(hand, self->missing_value, &missing_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_long(grib_handle_of_accessor(a), self->ni, &ni)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_long(hand, self->ni, &ni)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if (*len < number_of_points) {
|
||||
|
@ -206,68 +208,9 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
|||
return err;
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
static void grib_set_bit_on( unsigned char* p, long *bitp){
|
||||
unsigned char o = 1;
|
||||
p += (*bitp >> 3);
|
||||
o <<= 7-((*bitp)%8);
|
||||
*p |= o;
|
||||
(*bitp)+=1;
|
||||
}
|
||||
|
||||
static int pack_double(grib_accessor* a, const double* val,size_t *len){
|
||||
grib_accessor_gds_not_present_bitmap* self = (grib_accessor_gds_not_present_bitmap*)a;
|
||||
|
||||
size_t tlen;
|
||||
|
||||
unsigned char* buf = NULL;
|
||||
long i;
|
||||
int err = 0;
|
||||
long pos = 0;
|
||||
long bmaplen = 0;
|
||||
const int bit_padding = 16;
|
||||
double miss_values = 0;
|
||||
tlen = ((*len+bit_padding-1)/bit_padding*bit_padding)/8;
|
||||
|
||||
if((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &miss_values)) != GRIB_SUCCESS)
|
||||
{
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_class_bitmap : pack_double : Cannot unpack %s err=%d ",self->missing_value,err);
|
||||
return err;
|
||||
}
|
||||
|
||||
buf = grib_context_malloc_clear(a->context,tlen);
|
||||
if(!buf) return GRIB_OUT_OF_MEMORY;
|
||||
pos=0;
|
||||
for(i=0;i<*len;i++)
|
||||
{
|
||||
if (val[i] == miss_values)
|
||||
pos++;
|
||||
else{
|
||||
bmaplen++;
|
||||
grib_set_bit_on(buf, &pos);
|
||||
}
|
||||
}
|
||||
|
||||
if((err = grib_set_long_internal(grib_handle_of_accessor(a), self->unusedBits,tlen*8 - *len )) != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_class_bitmap : pack_double : Cannot pack %s err=%d ",self->unusedBits,err);
|
||||
grib_context_free(a->context,buf);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
grib_buffer_replace(a, buf, tlen,1,1);
|
||||
|
||||
grib_context_free(a->context,buf);
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
{
|
||||
// See deprecated/grib_accessor_class_gds_not_present_bitmap.cc for
|
||||
// a possible implementation
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -222,15 +222,6 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
|||
*val = (double)directionIncrement / angleDivisor * angleMultiplier;
|
||||
}
|
||||
|
||||
#if 0
|
||||
printf("unpack -- %s=%ld %s=%ld %s=%f %s=%f %s=%ld %s=%f\n",
|
||||
self->directionIncrementGiven,directionIncrementGiven,
|
||||
self->directionIncrement,directionIncrement,
|
||||
self->last,last,
|
||||
self->first,first,
|
||||
self->numberOfPoints,numberOfPoints,
|
||||
a->name,*val);
|
||||
#endif
|
||||
if (ret == GRIB_SUCCESS)
|
||||
*len = 1;
|
||||
|
||||
|
@ -317,16 +308,6 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
if (ret)
|
||||
return ret;
|
||||
|
||||
#if 0
|
||||
printf("pack -- %s=%ld %s=%ld \n ------- %s=%f %s=%f \n ------- %s=%ld codedNumberOfPoints=%ld %s=%f\n",
|
||||
self->directionIncrementGiven,directionIncrementGiven,
|
||||
self->directionIncrement,directionIncrement,
|
||||
self->last,last,
|
||||
self->first,first,
|
||||
self->numberOfPoints,numberOfPoints,
|
||||
codedNumberOfPoints,
|
||||
a->name,*val);
|
||||
#endif
|
||||
if (ret == GRIB_SUCCESS)
|
||||
*len = 1;
|
||||
|
||||
|
|
|
@ -178,7 +178,6 @@ static int is_missing(grib_accessor* a){
|
|||
Assert( ret == 0);
|
||||
return value == GRIB_MISSING_LONG;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
@ -277,12 +276,10 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len)
|
|||
{
|
||||
long v = 0; /* The converted value */
|
||||
|
||||
#if 0
|
||||
/* Requires more work e.g. filter */
|
||||
if (strcmp_nocase(val, "missing")==0) {
|
||||
return pack_missing(a);
|
||||
}
|
||||
#endif
|
||||
// Requires more work e.g. filter
|
||||
//if (strcmp_nocase(val, "missing")==0) {
|
||||
// return pack_missing(a);
|
||||
//}
|
||||
|
||||
if (string_to_long(val, &v) != GRIB_SUCCESS) {
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
* Enrico Fucile
|
||||
**************************************/
|
||||
|
||||
|
||||
#include "grib_api_internal.h"
|
||||
/*
|
||||
This is used by make_class.pl
|
||||
|
@ -124,11 +123,9 @@ static size_t preferred_size(grib_accessor* a, int from_handle)
|
|||
grib_get_long_internal(grib_handle_of_accessor(a), self->section_length, &length);
|
||||
|
||||
if ((length % 2) && from_handle) {
|
||||
#if 0
|
||||
grib_context_log(a->context,
|
||||
GRIB_LOG_ERROR,"GRIB message has an odd length section (%ld, %s)",
|
||||
(long)length,a->name);
|
||||
#endif
|
||||
// grib_context_log(a->context,
|
||||
// GRIB_LOG_ERROR,"GRIB message has an odd length section (%ld, %s)",
|
||||
// (long)length,a->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -204,12 +204,6 @@ typedef struct grib_iterator grib_iterator;
|
|||
*/
|
||||
typedef struct grib_nearest grib_nearest;
|
||||
|
||||
/*! Grib box, structure used to crop a box given north/west/south/east boundaries.
|
||||
\ingroup grib_box
|
||||
*/
|
||||
typedef struct grib_box grib_box;
|
||||
typedef struct grib_points grib_points;
|
||||
|
||||
/*! Grib keys iterator. Iterator over keys.
|
||||
\ingroup keys_iterator
|
||||
*/
|
||||
|
@ -1388,19 +1382,6 @@ int grib_read_any_from_file(grib_context* ctx, FILE* f, void* buffer, size_t* le
|
|||
int grib_get_message_offset(const grib_handle* h, off_t* offset);
|
||||
int grib_get_message_size(const grib_handle* h, size_t* size);
|
||||
|
||||
struct grib_points
|
||||
{
|
||||
grib_context* context;
|
||||
double* latitudes;
|
||||
double* longitudes;
|
||||
size_t* indexes;
|
||||
size_t* group_start;
|
||||
size_t* group_len;
|
||||
size_t n_groups;
|
||||
size_t n;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
|
||||
/* --------------------------------------- */
|
||||
#define GRIB_UTIL_GRID_SPEC_REGULAR_LL 1
|
||||
|
|
|
@ -272,7 +272,6 @@ typedef struct grib_smart_table grib_smart_table;
|
|||
typedef struct grib_accessor grib_accessor;
|
||||
typedef struct grib_iterator_class grib_iterator_class;
|
||||
typedef struct grib_nearest_class grib_nearest_class;
|
||||
typedef struct grib_box_class grib_box_class;
|
||||
typedef struct grib_dumper grib_dumper;
|
||||
typedef struct grib_dumper_class grib_dumper_class;
|
||||
typedef struct grib_dependency grib_dependency;
|
||||
|
@ -292,11 +291,6 @@ typedef int (*nearest_find_proc)(grib_nearest* nearest, grib_handle* h,
|
|||
double* distances, int* indexes, size_t* len);
|
||||
typedef int (*nearest_destroy_proc)(grib_nearest* nearest);
|
||||
|
||||
typedef void (*box_init_class_proc)(grib_box_class*);
|
||||
typedef int (*box_destroy_proc)(grib_box*);
|
||||
typedef int (*box_init_proc)(grib_box*, grib_handle*, grib_arguments*);
|
||||
typedef grib_points* (*box_get_points_proc)(grib_box*, double, double, double, double, int*);
|
||||
|
||||
typedef void (*iterator_init_class_proc)(grib_iterator_class*);
|
||||
typedef int (*iterator_init_proc)(grib_iterator* i, grib_handle*, grib_arguments*);
|
||||
|
||||
|
@ -631,18 +625,6 @@ struct grib_nearest_class
|
|||
nearest_find_proc find;
|
||||
};
|
||||
|
||||
struct grib_box_class
|
||||
{
|
||||
grib_box_class** super;
|
||||
const char* name;
|
||||
size_t size;
|
||||
int inited;
|
||||
box_init_class_proc init_class;
|
||||
box_init_proc init;
|
||||
box_destroy_proc destroy;
|
||||
box_get_points_proc get_points;
|
||||
};
|
||||
|
||||
/* --------------- */
|
||||
/* --------------- */
|
||||
typedef void (*search_all_callback_proc)(grib_accessor*, void* data);
|
||||
|
@ -712,16 +694,6 @@ struct grib_nearest
|
|||
unsigned long flags;
|
||||
};
|
||||
|
||||
struct grib_box
|
||||
{
|
||||
grib_box_class* cclass;
|
||||
grib_context* context;
|
||||
grib_arguments* args;
|
||||
grib_handle* h;
|
||||
unsigned long flags;
|
||||
grib_points* points;
|
||||
};
|
||||
|
||||
struct grib_dependency
|
||||
{
|
||||
grib_dependency* next;
|
||||
|
@ -1297,30 +1269,6 @@ struct grib_fieldset
|
|||
};
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/* grib db */
|
||||
struct grib_db
|
||||
{
|
||||
grib_context* context;
|
||||
size_t size;
|
||||
size_t fields_array_size;
|
||||
grib_column* columns;
|
||||
size_t columns_size;
|
||||
grib_field** fields;
|
||||
};
|
||||
|
||||
struct grib_fieldset
|
||||
{
|
||||
grib_context* context;
|
||||
grib_db* db;
|
||||
grib_int_array* filter;
|
||||
grib_int_array* order;
|
||||
size_t size;
|
||||
grib_query* query;
|
||||
long current;
|
||||
};
|
||||
#endif
|
||||
|
||||
/* concept index structures */
|
||||
|
||||
typedef struct grib_concept_index_key grib_concept_index_key;
|
||||
|
|
|
@ -27,7 +27,7 @@ int grib_decode_array(const unsigned char* p, long* bitp, long bitsPerValue,
|
|||
unsigned long lvalue = 0;
|
||||
T x;
|
||||
|
||||
#if 0
|
||||
#ifdef SLOW_OLD_CODE
|
||||
/* slow reference code */
|
||||
int j=0;
|
||||
for(i=0; i < n_vals; i++) {
|
||||
|
|
|
@ -13,7 +13,6 @@ extern grib_dumper_class* grib_dumper_class_default;
|
|||
extern grib_dumper_class* grib_dumper_class_file;
|
||||
extern grib_dumper_class* grib_dumper_class_grib_encode_C;
|
||||
extern grib_dumper_class* grib_dumper_class_json;
|
||||
extern grib_dumper_class* grib_dumper_class_keys;
|
||||
extern grib_dumper_class* grib_dumper_class_serialize;
|
||||
extern grib_dumper_class* grib_dumper_class_string;
|
||||
extern grib_dumper_class* grib_dumper_class_wmo;
|
||||
|
|
|
@ -12,6 +12,5 @@
|
|||
{ "default", &grib_dumper_class_default, },
|
||||
{ "grib_encode_C", &grib_dumper_class_grib_encode_C, },
|
||||
{ "json", &grib_dumper_class_json, },
|
||||
{ "keys", &grib_dumper_class_keys, },
|
||||
{ "serialize", &grib_dumper_class_serialize, },
|
||||
{ "wmo", &grib_dumper_class_wmo, },
|
||||
|
|
|
@ -115,7 +115,7 @@ static Fraction_type fraction_construct_from_double(double x)
|
|||
|
||||
x = 1.0 / (x - a);
|
||||
|
||||
if (x > LLONG_MAX) {
|
||||
if (x > (double)LLONG_MAX) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -1750,7 +1750,7 @@ static void grib_dump_index_keys(FILE* fout, grib_index_key* keys)
|
|||
grib_dump_key_values(fout, keys->values);
|
||||
grib_dump_index_keys(fout, keys->next);
|
||||
}
|
||||
#if 0
|
||||
#ifdef INDEX_DUMPS
|
||||
static void grib_dump_files(FILE* fout, grib_file* files)
|
||||
{
|
||||
if (!files) return;
|
||||
|
|
|
@ -434,7 +434,7 @@ static int read_GRIB(reader* r, int no_alloc)
|
|||
return err;
|
||||
}
|
||||
|
||||
static int read_PSEUDO(reader* r, const char* type)
|
||||
static int read_PSEUDO(reader* r, const char* type, int no_alloc)
|
||||
{
|
||||
unsigned char tmp[32]; /* Should be enough */
|
||||
size_t sec1len = 0;
|
||||
|
@ -480,7 +480,7 @@ static int read_PSEUDO(reader* r, const char* type)
|
|||
/* fprintf(stderr,"%s sec4len=%d i=%d l=%d\n",type,sec4len,i,4+sec1len+sec4len+4); */
|
||||
|
||||
Assert(i <= sizeof(tmp));
|
||||
return read_the_rest(r, 4 + sec1len + sec4len + 4, tmp, i, /*check7777=*/1, /*no_alloc=*/0);
|
||||
return read_the_rest(r, 4 + sec1len + sec4len + 4, tmp, i, /*check7777=*/1, no_alloc);
|
||||
}
|
||||
|
||||
static int read_HDF5_offset(reader* r, int length, unsigned long* v, unsigned char* tmp, int* i)
|
||||
|
@ -899,19 +899,19 @@ static int ecc_read_any(reader* r, int no_alloc, int grib_ok, int bufr_ok, int h
|
|||
|
||||
case BUDG:
|
||||
if (grib_ok) {
|
||||
err = read_PSEUDO(r, "BUDG");
|
||||
err = read_PSEUDO(r, "BUDG", no_alloc);
|
||||
return err == GRIB_END_OF_FILE ? GRIB_PREMATURE_END_OF_FILE : err; /* Premature EOF */
|
||||
}
|
||||
break;
|
||||
case DIAG:
|
||||
if (grib_ok) {
|
||||
err = read_PSEUDO(r, "DIAG");
|
||||
err = read_PSEUDO(r, "DIAG", no_alloc);
|
||||
return err == GRIB_END_OF_FILE ? GRIB_PREMATURE_END_OF_FILE : err; /* Premature EOF */
|
||||
}
|
||||
break;
|
||||
case TIDE:
|
||||
if (grib_ok) {
|
||||
err = read_PSEUDO(r, "TIDE");
|
||||
err = read_PSEUDO(r, "TIDE", no_alloc);
|
||||
return err == GRIB_END_OF_FILE ? GRIB_PREMATURE_END_OF_FILE : err; /* Premature EOF */
|
||||
}
|
||||
break;
|
||||
|
@ -1754,11 +1754,9 @@ int grib_count_in_file(grib_context* c, FILE* f, int* n)
|
|||
}
|
||||
}
|
||||
else {
|
||||
void* mesg = NULL;
|
||||
size_t size = 0;
|
||||
off_t offset = 0;
|
||||
while ((mesg = wmo_read_any_from_file_malloc(f, 0, &size, &offset, &err)) != NULL && err == GRIB_SUCCESS) {
|
||||
grib_context_free(c, mesg);
|
||||
while ((err = wmo_read_any_from_file_fast(f, &size, &offset)) == GRIB_SUCCESS) {
|
||||
(*n)++;
|
||||
}
|
||||
}
|
||||
|
@ -1785,15 +1783,15 @@ int grib_count_in_filename(grib_context* c, const char* filename, int* n)
|
|||
return err;
|
||||
}
|
||||
|
||||
typedef void* (*decoder_proc)(FILE* f, int headers_only, size_t* size, off_t* offset, int* err);
|
||||
typedef int (*decoder_proc)(FILE* f, size_t* size, off_t* offset);
|
||||
|
||||
static decoder_proc get_reader_for_product(ProductKind product)
|
||||
{
|
||||
decoder_proc decoder = NULL;
|
||||
if (product == PRODUCT_GRIB) decoder = &wmo_read_grib_from_file_malloc;
|
||||
else if (product == PRODUCT_BUFR) decoder = &wmo_read_bufr_from_file_malloc;
|
||||
else if (product == PRODUCT_GTS) decoder = &wmo_read_gts_from_file_malloc;
|
||||
else if (product == PRODUCT_ANY) decoder = &wmo_read_any_from_file_malloc;
|
||||
if (product == PRODUCT_GRIB) decoder = &wmo_read_grib_from_file_fast;
|
||||
else if (product == PRODUCT_BUFR) decoder = &wmo_read_bufr_from_file_fast;
|
||||
else if (product == PRODUCT_GTS) decoder = &wmo_read_gts_from_file_fast;
|
||||
else if (product == PRODUCT_ANY) decoder = &wmo_read_any_from_file_fast;
|
||||
return decoder;
|
||||
}
|
||||
|
||||
|
@ -1807,20 +1805,18 @@ static int count_product_in_file(grib_context* c, FILE* f, ProductKind product,
|
|||
decoder = get_reader_for_product(product);
|
||||
|
||||
if (!decoder) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "count_product_in_file: not supported for given product");
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "%s: Not supported for given product", __func__);
|
||||
return GRIB_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
if (c->multi_support_on && product == PRODUCT_GRIB) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "count_product_in_file: Multi-field GRIBs not supported");
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "%s: Multi-field GRIBs not supported", __func__);
|
||||
err = GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
else {
|
||||
void* mesg = NULL;
|
||||
size_t size = 0;
|
||||
off_t offset = 0;
|
||||
while ((mesg = decoder(f, 0, &size, &offset, &err)) != NULL && err == GRIB_SUCCESS) {
|
||||
grib_context_free(c, mesg);
|
||||
while ((err = decoder(f, &size, &offset)) == GRIB_SUCCESS) {
|
||||
(*count)++;
|
||||
}
|
||||
rewind(f);
|
||||
|
@ -1832,7 +1828,6 @@ static int count_product_in_file(grib_context* c, FILE* f, ProductKind product,
|
|||
int codes_extract_offsets_malloc(grib_context* c, const char* filename, ProductKind product, off_t** offsets, int* length, int strict_mode)
|
||||
{
|
||||
int err = 0;
|
||||
void* mesg = NULL;
|
||||
size_t size = 0;
|
||||
off_t offset = 0;
|
||||
int num_messages = 0, i = 0;
|
||||
|
@ -1841,26 +1836,26 @@ int codes_extract_offsets_malloc(grib_context* c, const char* filename, ProductK
|
|||
|
||||
decoder = get_reader_for_product(product);
|
||||
if (!decoder) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "codes_extract_offsets_malloc: not supported for given product");
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "%s: Not supported for given product", __func__);
|
||||
return GRIB_INVALID_ARGUMENT;
|
||||
}
|
||||
if (!c) c = grib_context_get_default();
|
||||
f = fopen(filename, "rb");
|
||||
if (!f) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "codes_extract_offsets_malloc: Unable to read file \"%s\"", filename);
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to read file \"%s\"", __func__, filename);
|
||||
perror(filename);
|
||||
return GRIB_IO_PROBLEM;
|
||||
}
|
||||
|
||||
err = count_product_in_file(c, f, product, &num_messages);
|
||||
if (err) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "codes_extract_offsets_malloc: Unable to count messages");
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "%s: Unable to count messages (%s)", __func__, grib_get_error_message(err));
|
||||
fclose(f);
|
||||
return err;
|
||||
}
|
||||
*length = num_messages;
|
||||
if (num_messages == 0) {
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "codes_extract_offsets_malloc: No messages in file");
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "%s: No messages in file", __func__);
|
||||
fclose(f);
|
||||
return GRIB_INVALID_MESSAGE;
|
||||
}
|
||||
|
@ -1875,28 +1870,16 @@ int codes_extract_offsets_malloc(grib_context* c, const char* filename, ProductK
|
|||
if (i >= num_messages)
|
||||
break;
|
||||
|
||||
mesg = decoder(f, 0, &size, &offset, &err);
|
||||
if (mesg != NULL && err == 0) {
|
||||
err = decoder(f, &size, &offset);
|
||||
if (!err) {
|
||||
(*offsets)[i] = offset;
|
||||
grib_context_free(c, mesg);
|
||||
}
|
||||
if (mesg && err) {
|
||||
if (strict_mode) {
|
||||
grib_context_free(c, mesg);
|
||||
else {
|
||||
if (strict_mode && (err != GRIB_END_OF_FILE && err != GRIB_PREMATURE_END_OF_FILE)) {
|
||||
fclose(f);
|
||||
return GRIB_DECODING_ERROR;
|
||||
}
|
||||
}
|
||||
if (!mesg) {
|
||||
if (err != GRIB_END_OF_FILE && err != GRIB_PREMATURE_END_OF_FILE) {
|
||||
/* An error occurred */
|
||||
grib_context_log(c, GRIB_LOG_ERROR, "codes_extract_offsets_malloc: Unable to read message");
|
||||
if (strict_mode) {
|
||||
fclose(f);
|
||||
return GRIB_DECODING_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,19 +18,6 @@ grib_rule_entry* grib_new_rule_entry(grib_context* c, const char* name, grib_exp
|
|||
return e;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* GCC compiler complains function is defined but not used*/
|
||||
static void grib_rule_entry_delete(grib_context* c,grib_rule_entry* e)
|
||||
{
|
||||
if(e) {
|
||||
grib_context_free_persistent(c,e->name);
|
||||
grib_rule_entry_delete(c,e->next);
|
||||
grib_context_free_persistent(c,e);
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
grib_rule* grib_new_rule(grib_context* c, grib_expression* condition, grib_rule_entry* entries)
|
||||
{
|
||||
grib_rule* r = (grib_rule*)grib_context_malloc_clear_persistent(c, sizeof(grib_rule));
|
||||
|
|
|
@ -26,8 +26,6 @@ typedef struct grib_templates {
|
|||
size_t size;
|
||||
} grib_templates;
|
||||
|
||||
#include "grib_templates.h"
|
||||
|
||||
#define NUMBER(x) (sizeof(x) / sizeof(x[0]))
|
||||
|
||||
grib_handle* grib_internal_sample(grib_context* c,const char* name)
|
||||
|
|
|
@ -382,7 +382,7 @@ void grib_trie_with_rank_delete_container(grib_trie_with_rank* t)
|
|||
GRIB_MUTEX_UNLOCK(&mutex);
|
||||
}
|
||||
|
||||
#if 0
|
||||
#ifdef TRIE_WITH_RANK_OLD
|
||||
static void grib_trie_with_rank_delete_list(grib_context* c,grib_trie_with_rank_list *list)
|
||||
{
|
||||
grib_trie_with_rank_list* next=list;
|
||||
|
|
|
@ -1125,23 +1125,6 @@ int grib_get_float_element_set(const grib_handle* h, const char* name, const siz
|
|||
return GRIB_NOT_FOUND;
|
||||
}
|
||||
|
||||
int grib_points_get_values(grib_handle* h, grib_points* points, double* val)
|
||||
{
|
||||
int i, ret;
|
||||
grib_accessor* a = NULL;
|
||||
fprintf(stderr, "Warning: The grib_points_get_values function is deprecated and will be removed later.");
|
||||
|
||||
a = grib_find_accessor(h, "values");
|
||||
|
||||
for (i = 0; i < points->n_groups; i++) {
|
||||
ret = grib_unpack_double_subarray(a, val, points->group_start[i], points->group_len[i]);
|
||||
if (ret)
|
||||
return ret;
|
||||
val += points->group_len[i];
|
||||
}
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
int grib_get_double_elements(const grib_handle* h, const char* name, const int* index_array, long len, double* val_array)
|
||||
{
|
||||
double* values = 0;
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
||||
*/
|
||||
|
||||
#include <float.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#ifdef __PGI
|
||||
#undef __AVX__
|
||||
|
@ -20,18 +23,12 @@
|
|||
#endif
|
||||
|
||||
#ifdef __AVX__
|
||||
#include <float.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
#include <immintrin.h>
|
||||
#ifdef _GET_X86_COUNTER
|
||||
#include <x86intrin.h>
|
||||
#endif
|
||||
#else
|
||||
#ifdef __SSE2__
|
||||
#include <float.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
#include <emmintrin.h>
|
||||
#ifdef _GET_X86_COUNTER
|
||||
#include <x86intrin.h>
|
||||
|
@ -229,7 +226,7 @@ static void minmax_val(const double* restrict data, long datasize, double* fmin,
|
|||
#else
|
||||
|
||||
#ifdef _ARCH_PWR6
|
||||
#define __UNROLL_DEPTH_1 6
|
||||
#define kUNROLL_DEPTH_1 6
|
||||
|
||||
/* to allow pipelining we have to unroll */
|
||||
|
||||
|
@ -238,18 +235,18 @@ static void minmax_val(const double* restrict data, long datasize, double* fmin,
|
|||
#endif
|
||||
{
|
||||
long i, j;
|
||||
long residual = datasize % __UNROLL_DEPTH_1;
|
||||
long residual = datasize % kUNROLL_DEPTH_1;
|
||||
long ofs = datasize - residual;
|
||||
double dmin[__UNROLL_DEPTH_1];
|
||||
double dmax[__UNROLL_DEPTH_1];
|
||||
double dmin[kUNROLL_DEPTH_1];
|
||||
double dmax[kUNROLL_DEPTH_1];
|
||||
|
||||
for (j = 0; j < __UNROLL_DEPTH_1; j++) {
|
||||
for (j = 0; j < kUNROLL_DEPTH_1; j++) {
|
||||
dmin[j] = data[0];
|
||||
dmax[j] = data[0];
|
||||
}
|
||||
|
||||
for (i = 0; i < datasize - residual; i += __UNROLL_DEPTH_1) {
|
||||
for (j = 0; j < __UNROLL_DEPTH_1; j++) {
|
||||
for (i = 0; i < datasize - residual; i += kUNROLL_DEPTH_1) {
|
||||
for (j = 0; j < kUNROLL_DEPTH_1; j++) {
|
||||
dmin[j] = __fsel(dmin[j] - data[i + j], data[i + j], dmin[j]);
|
||||
dmax[j] = __fsel(data[i + j] - dmax[j], data[i + j], dmax[j]);
|
||||
}
|
||||
|
@ -260,7 +257,7 @@ static void minmax_val(const double* restrict data, long datasize, double* fmin,
|
|||
dmax[j] = __fsel(data[ofs + j] - dmax[j], data[ofs + j], dmax[j]);
|
||||
}
|
||||
|
||||
for (j = 0; j < __UNROLL_DEPTH_1; j++) {
|
||||
for (j = 0; j < kUNROLL_DEPTH_1; j++) {
|
||||
*fmin = __fsel(*fmin - dmin[j], dmin[j], *fmin);
|
||||
*fmax = __fsel(dmax[j] - *fmax, dmax[j], *fmax);
|
||||
}
|
||||
|
@ -269,7 +266,7 @@ static void minmax_val(const double* restrict data, long datasize, double* fmin,
|
|||
hpmStop(1);
|
||||
#endif
|
||||
|
||||
#undef __UNROLL_DEPTH_1
|
||||
#undef kUNROLL_DEPTH_1
|
||||
#else
|
||||
|
||||
#ifdef _GET_IBM_COUNTER
|
||||
|
|
|
@ -11,31 +11,42 @@
|
|||
. ./include.ctest.sh
|
||||
|
||||
# Define a common label for all the tmp files
|
||||
label="bufr_extract_offsets_test"
|
||||
label="extract_offsets_test"
|
||||
temp1="temp.${label}.1"
|
||||
temp2="temp.${label}.2"
|
||||
tempLog="temp.${label}.log"
|
||||
|
||||
echo "Multi-message BUFR..."
|
||||
# ---------------------------
|
||||
input=${data_dir}/bufr/aeolus_wmo_26.bufr
|
||||
$EXEC ${test_dir}/extract_offsets $input > $temp1
|
||||
${tools_dir}/bufr_get -p offset:i $input > $temp2
|
||||
${tools_dir}/bufr_get -p offset:i $input > $temp2
|
||||
diff $temp1 $temp2
|
||||
|
||||
echo "Multi-message GRIB..."
|
||||
echo "Multi-message GRIBs..."
|
||||
# --------------------------
|
||||
input=${data_dir}/mixed.grib
|
||||
$EXEC ${test_dir}/extract_offsets $input > $temp1
|
||||
${tools_dir}/grib_get -p offset:i $input > $temp2
|
||||
diff $temp1 $temp2
|
||||
|
||||
inputs="${data_dir}/mixed.grib ${data_dir}/test.grib1 ${data_dir}/v.grib2"
|
||||
for input in $inputs; do
|
||||
$EXEC ${test_dir}/extract_offsets $input > $temp1
|
||||
${tools_dir}/grib_get -p offset:i $input > $temp2
|
||||
diff $temp1 $temp2
|
||||
done
|
||||
|
||||
echo "Test with invalid inputs..."
|
||||
# ---------------------------------
|
||||
set +e
|
||||
$EXEC ${test_dir}/extract_offsets ${data_dir}
|
||||
$EXEC ${test_dir}/extract_offsets ${data_dir} > $tempLog 2>&1
|
||||
status=$?
|
||||
set -e
|
||||
[ $status -ne 0 ]
|
||||
grep -q "Input output problem" $tempLog
|
||||
|
||||
rm -f $temp1 $temp2
|
||||
set +e
|
||||
$EXEC ${test_dir}/extract_offsets ${data_dir}/bad.grib > $tempLog 2>&1
|
||||
status=$?
|
||||
set -e
|
||||
[ $status -ne 0 ]
|
||||
grep -q "Wrong message length" $tempLog
|
||||
|
||||
# Clean up
|
||||
rm -f $temp1 $temp2 $tempLog
|
||||
|
|
|
@ -56,5 +56,8 @@ cat > $tempRef << EOF
|
|||
EOF
|
||||
diff $tempRef $tempOut
|
||||
|
||||
# Count
|
||||
count=`${tools_dir}/grib_count ${data_dir}/budg`
|
||||
[ $count -eq 1 ]
|
||||
|
||||
rm -f $tempRef $tempOut $tempBud
|
||||
|
|
|
@ -25,6 +25,10 @@ sample=$ECCODES_SAMPLES_PATH/diag.tmpl
|
|||
${tools_dir}/grib_ls $sample > $REDIRECT
|
||||
${tools_dir}/grib_dump $sample > $REDIRECT
|
||||
|
||||
count=`${tools_dir}/grib_count $sample`
|
||||
[ $count -eq 1 ]
|
||||
|
||||
|
||||
echo "Check setting integer keys..."
|
||||
# ----------------------------------
|
||||
echo 'set numberOfIntegers=3; set integerValues={55, 44, 66}; write;' | ${tools_dir}/grib_filter -o $tempOut - $sample
|
||||
|
|
Loading…
Reference in New Issue