2013-03-25 12:04:10 +00:00
|
|
|
/*
|
2020-01-28 14:32:34 +00:00
|
|
|
* (C) Copyright 2005- ECMWF.
|
2013-03-25 12:04:10 +00:00
|
|
|
*
|
|
|
|
* 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 "grib_api_internal.h"
|
|
|
|
#include <limits.h>
|
|
|
|
/*
|
|
|
|
This is used by make_class.pl
|
|
|
|
|
|
|
|
START_CLASS_DEF
|
|
|
|
CLASS = accessor
|
|
|
|
SUPER = grib_accessor_class_gen
|
|
|
|
IMPLEMENTS = unpack_double;pack_double
|
|
|
|
IMPLEMENTS = unpack_string;pack_string;string_length
|
|
|
|
IMPLEMENTS = unpack_long;pack_long;destroy;byte_count
|
|
|
|
IMPLEMENTS = init;dump;value_count;get_native_type
|
2015-11-06 15:12:08 +00:00
|
|
|
IMPLEMENTS = compare; make_clone
|
2013-03-25 12:04:10 +00:00
|
|
|
MEMBERS=double dval
|
|
|
|
MEMBERS=char* cval
|
2019-08-30 11:47:18 +00:00
|
|
|
MEMBERS=char* cname
|
2013-03-25 12:04:10 +00:00
|
|
|
MEMBERS=int type
|
|
|
|
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
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
static int get_native_type(grib_accessor*);
|
|
|
|
static int pack_double(grib_accessor*, const double* val, size_t* len);
|
|
|
|
static int pack_long(grib_accessor*, const long* val, size_t* len);
|
|
|
|
static int pack_string(grib_accessor*, const char*, size_t* len);
|
|
|
|
static int unpack_double(grib_accessor*, double* val, size_t* len);
|
|
|
|
static int unpack_long(grib_accessor*, long* val, size_t* len);
|
|
|
|
static int unpack_string(grib_accessor*, char*, size_t* len);
|
2013-03-25 12:04:10 +00:00
|
|
|
static size_t string_length(grib_accessor*);
|
|
|
|
static long byte_count(grib_accessor*);
|
2020-01-22 13:10:59 +00:00
|
|
|
static int value_count(grib_accessor*, long*);
|
|
|
|
static void destroy(grib_context*, grib_accessor*);
|
2013-03-25 12:04:10 +00:00
|
|
|
static void dump(grib_accessor*, grib_dumper*);
|
2020-01-22 13:10:59 +00:00
|
|
|
static void init(grib_accessor*, const long, grib_arguments*);
|
2013-03-25 12:04:10 +00:00
|
|
|
static void init_class(grib_accessor_class*);
|
|
|
|
static int compare(grib_accessor*, grib_accessor*);
|
2020-01-22 13:10:59 +00:00
|
|
|
static grib_accessor* make_clone(grib_accessor*, grib_section*, int*);
|
|
|
|
|
|
|
|
typedef struct grib_accessor_variable
|
|
|
|
{
|
|
|
|
grib_accessor att;
|
|
|
|
/* Members defined in gen */
|
|
|
|
/* Members defined in variable */
|
|
|
|
double dval;
|
|
|
|
char* cval;
|
|
|
|
char* cname;
|
|
|
|
int type;
|
2013-03-25 12:04:10 +00:00
|
|
|
} grib_accessor_variable;
|
|
|
|
|
|
|
|
extern grib_accessor_class* grib_accessor_class_gen;
|
|
|
|
|
|
|
|
static grib_accessor_class _grib_accessor_class_variable = {
|
2020-01-22 13:10:59 +00:00
|
|
|
&grib_accessor_class_gen, /* super */
|
|
|
|
"variable", /* name */
|
|
|
|
sizeof(grib_accessor_variable), /* size */
|
|
|
|
0, /* inited */
|
|
|
|
&init_class, /* init_class */
|
|
|
|
&init, /* init */
|
|
|
|
0, /* post_init */
|
|
|
|
&destroy, /* free mem */
|
|
|
|
&dump, /* describes himself */
|
|
|
|
0, /* get length of section */
|
|
|
|
&string_length, /* get length of string */
|
|
|
|
&value_count, /* get number of values */
|
|
|
|
&byte_count, /* get number of bytes */
|
|
|
|
0, /* get offset to bytes */
|
|
|
|
&get_native_type, /* get native type */
|
|
|
|
0, /* get sub_section */
|
|
|
|
0, /* grib_pack procedures long */
|
|
|
|
0, /* grib_pack procedures long */
|
|
|
|
&pack_long, /* grib_pack procedures long */
|
|
|
|
&unpack_long, /* grib_unpack procedures long */
|
|
|
|
&pack_double, /* grib_pack procedures double */
|
|
|
|
&unpack_double, /* grib_unpack procedures double */
|
|
|
|
&pack_string, /* grib_pack procedures string */
|
|
|
|
&unpack_string, /* grib_unpack procedures string */
|
|
|
|
0, /* grib_pack array procedures string */
|
|
|
|
0, /* grib_unpack array procedures string */
|
|
|
|
0, /* grib_pack procedures bytes */
|
|
|
|
0, /* grib_unpack procedures bytes */
|
|
|
|
0, /* pack_expression */
|
|
|
|
0, /* notify_change */
|
|
|
|
0, /* update_size */
|
|
|
|
0, /* preferred_size */
|
|
|
|
0, /* resize */
|
|
|
|
0, /* nearest_smaller_value */
|
|
|
|
0, /* next accessor */
|
|
|
|
&compare, /* compare vs. another accessor */
|
|
|
|
0, /* unpack only ith value */
|
|
|
|
0, /* unpack a subarray */
|
|
|
|
0, /* clear */
|
|
|
|
&make_clone, /* clone accessor */
|
2013-03-25 12:04:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
grib_accessor_class* grib_accessor_class_variable = &_grib_accessor_class_variable;
|
|
|
|
|
|
|
|
|
|
|
|
static void init_class(grib_accessor_class* c)
|
|
|
|
{
|
2020-01-22 13:10:59 +00:00
|
|
|
c->next_offset = (*(c->super))->next_offset;
|
|
|
|
c->byte_offset = (*(c->super))->byte_offset;
|
|
|
|
c->sub_section = (*(c->super))->sub_section;
|
|
|
|
c->pack_missing = (*(c->super))->pack_missing;
|
|
|
|
c->is_missing = (*(c->super))->is_missing;
|
|
|
|
c->pack_string_array = (*(c->super))->pack_string_array;
|
|
|
|
c->unpack_string_array = (*(c->super))->unpack_string_array;
|
|
|
|
c->pack_bytes = (*(c->super))->pack_bytes;
|
|
|
|
c->unpack_bytes = (*(c->super))->unpack_bytes;
|
|
|
|
c->pack_expression = (*(c->super))->pack_expression;
|
|
|
|
c->notify_change = (*(c->super))->notify_change;
|
|
|
|
c->update_size = (*(c->super))->update_size;
|
|
|
|
c->preferred_size = (*(c->super))->preferred_size;
|
|
|
|
c->resize = (*(c->super))->resize;
|
|
|
|
c->nearest_smaller_value = (*(c->super))->nearest_smaller_value;
|
|
|
|
c->next = (*(c->super))->next;
|
|
|
|
c->unpack_double_element = (*(c->super))->unpack_double_element;
|
|
|
|
c->unpack_double_subarray = (*(c->super))->unpack_double_subarray;
|
|
|
|
c->clear = (*(c->super))->clear;
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* END_CLASS_IMP */
|
|
|
|
|
|
|
|
#define MAX_VARIABLE_STRING_LENGTH 255
|
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
static void init(grib_accessor* a, const long length, grib_arguments* args)
|
2013-03-25 12:04:10 +00:00
|
|
|
{
|
2014-03-08 19:13:46 +00:00
|
|
|
grib_accessor_variable* self = (grib_accessor_variable*)a;
|
2020-01-22 13:10:59 +00:00
|
|
|
grib_handle* hand = grib_handle_of_accessor(a);
|
|
|
|
grib_expression* expression = grib_arguments_get_expression(hand, args, 0);
|
|
|
|
const char* p = 0;
|
|
|
|
size_t len = 1;
|
2014-03-08 19:13:46 +00:00
|
|
|
long l;
|
2020-01-22 13:10:59 +00:00
|
|
|
int ret = 0;
|
2014-03-08 19:13:46 +00:00
|
|
|
double d;
|
2019-08-30 11:47:18 +00:00
|
|
|
self->cname = NULL;
|
2014-03-08 19:13:46 +00:00
|
|
|
|
|
|
|
a->length = 0;
|
2020-01-22 13:10:59 +00:00
|
|
|
if (self->type == GRIB_TYPE_UNDEFINED && expression) {
|
|
|
|
self->type = grib_expression_native_type(hand, expression);
|
|
|
|
|
|
|
|
switch (self->type) {
|
|
|
|
case GRIB_TYPE_DOUBLE:
|
|
|
|
grib_expression_evaluate_double(hand, expression, &d);
|
|
|
|
pack_double(a, &d, &len);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GRIB_TYPE_LONG:
|
|
|
|
grib_expression_evaluate_long(hand, expression, &l);
|
|
|
|
pack_long(a, &l, &len);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: {
|
|
|
|
char tmp[1024];
|
|
|
|
len = sizeof(tmp);
|
|
|
|
p = grib_expression_evaluate_string(hand, expression, tmp, &len, &ret);
|
|
|
|
if (ret != GRIB_SUCCESS) {
|
|
|
|
grib_context_log(a->context, GRIB_LOG_ERROR, "unable to evaluate %s as string", a->name);
|
|
|
|
Assert(0);
|
|
|
|
}
|
|
|
|
len = strlen(p) + 1;
|
|
|
|
pack_string(a, p, &len);
|
|
|
|
break;
|
2017-06-16 13:53:10 +00:00
|
|
|
}
|
2014-03-08 19:13:46 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
void accessor_variable_set_type(grib_accessor* a, int type)
|
|
|
|
{
|
|
|
|
grib_accessor_variable* self = (grib_accessor_variable*)a;
|
|
|
|
self->type = type;
|
2015-02-10 17:56:44 +00:00
|
|
|
}
|
|
|
|
|
2013-03-25 12:04:10 +00:00
|
|
|
static void dump(grib_accessor* a, grib_dumper* dumper)
|
|
|
|
{
|
2020-01-22 13:10:59 +00:00
|
|
|
grib_accessor_variable* self = (grib_accessor_variable*)a;
|
|
|
|
switch (self->type) {
|
|
|
|
case GRIB_TYPE_DOUBLE:
|
|
|
|
grib_dump_double(dumper, a, NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GRIB_TYPE_LONG:
|
|
|
|
grib_dump_long(dumper, a, NULL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
grib_dump_string(dumper, a, NULL);
|
|
|
|
break;
|
2014-03-08 19:13:46 +00:00
|
|
|
}
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
2013-03-25 12:04:10 +00:00
|
|
|
{
|
2020-01-22 13:10:59 +00:00
|
|
|
grib_accessor_variable* self = (grib_accessor_variable*)a;
|
2014-03-08 19:13:46 +00:00
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
if (*len != 1) {
|
|
|
|
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1);
|
2014-03-08 19:13:46 +00:00
|
|
|
*len = 1;
|
|
|
|
return GRIB_ARRAY_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->dval = *val;
|
2020-01-22 13:10:59 +00:00
|
|
|
if (*val < (double)LONG_MIN || *val > (double)LONG_MAX)
|
2014-03-08 19:13:46 +00:00
|
|
|
self->type = GRIB_TYPE_DOUBLE;
|
|
|
|
else
|
|
|
|
self->type = ((long)*val == *val) ? GRIB_TYPE_LONG : GRIB_TYPE_DOUBLE;
|
|
|
|
|
|
|
|
return GRIB_SUCCESS;
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
static int pack_long(grib_accessor* a, const long* val, size_t* len)
|
2013-03-25 12:04:10 +00:00
|
|
|
{
|
2020-01-22 13:10:59 +00:00
|
|
|
grib_accessor_variable* self = (grib_accessor_variable*)a;
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
if (*len != 1) {
|
|
|
|
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1);
|
2014-03-08 19:13:46 +00:00
|
|
|
*len = 1;
|
|
|
|
return GRIB_ARRAY_TOO_SMALL;
|
|
|
|
}
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2014-03-08 19:13:46 +00:00
|
|
|
self->dval = *val;
|
|
|
|
self->type = GRIB_TYPE_LONG;
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2014-03-08 19:13:46 +00:00
|
|
|
return GRIB_SUCCESS;
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
2013-03-25 12:04:10 +00:00
|
|
|
{
|
2020-01-22 13:10:59 +00:00
|
|
|
grib_accessor_variable* ac = (grib_accessor_variable*)a;
|
2014-03-08 19:13:46 +00:00
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
if (*len < 1) {
|
|
|
|
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1);
|
2014-03-08 19:13:46 +00:00
|
|
|
*len = 0;
|
|
|
|
return GRIB_ARRAY_TOO_SMALL;
|
|
|
|
}
|
|
|
|
*val = ac->dval;
|
|
|
|
*len = 1;
|
|
|
|
return GRIB_SUCCESS;
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
2020-01-22 13:10:59 +00:00
|
|
|
static int unpack_long(grib_accessor* a, long* val, size_t* len)
|
2013-03-25 12:04:10 +00:00
|
|
|
{
|
2020-01-22 13:10:59 +00:00
|
|
|
grib_accessor_variable* ac = (grib_accessor_variable*)a;
|
2014-03-08 19:13:46 +00:00
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
if (*len < 1) {
|
|
|
|
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1);
|
2014-03-08 19:13:46 +00:00
|
|
|
*len = 0;
|
|
|
|
return GRIB_ARRAY_TOO_SMALL;
|
|
|
|
}
|
|
|
|
*val = (long)ac->dval;
|
|
|
|
*len = 1;
|
|
|
|
return GRIB_SUCCESS;
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int get_native_type(grib_accessor* a)
|
|
|
|
{
|
2020-01-22 13:10:59 +00:00
|
|
|
grib_accessor_variable* self = (grib_accessor_variable*)a;
|
2014-03-08 19:13:46 +00:00
|
|
|
return self->type;
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
static void destroy(grib_context* c, grib_accessor* a)
|
2013-03-25 12:04:10 +00:00
|
|
|
{
|
2020-01-22 13:10:59 +00:00
|
|
|
grib_accessor_variable* self = (grib_accessor_variable*)a;
|
|
|
|
int i = 0;
|
2019-08-30 15:29:57 +00:00
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
grib_context_free(c, self->cval);
|
|
|
|
if (self->cname)
|
|
|
|
grib_context_free(c, self->cname); /* ECC-765 */
|
2019-08-30 15:29:57 +00:00
|
|
|
|
|
|
|
/* Note: BUFR operator descriptors are variables and have attributes so need to free them */
|
2020-01-22 13:10:59 +00:00
|
|
|
while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) {
|
2019-08-30 15:29:57 +00:00
|
|
|
grib_accessor_delete(c, a->attributes[i]);
|
2020-01-22 13:10:59 +00:00
|
|
|
a->attributes[i] = NULL;
|
2019-08-30 15:29:57 +00:00
|
|
|
++i;
|
|
|
|
}
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
static int unpack_string(grib_accessor* a, char* val, size_t* len)
|
|
|
|
{
|
|
|
|
grib_accessor_variable* self = (grib_accessor_variable*)a;
|
2014-03-08 19:13:46 +00:00
|
|
|
|
|
|
|
char buf[80];
|
2020-01-22 13:10:59 +00:00
|
|
|
char* p = buf;
|
|
|
|
size_t slen;
|
2014-03-08 19:13:46 +00:00
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
if (self->type == GRIB_TYPE_STRING) {
|
2014-03-08 19:13:46 +00:00
|
|
|
p = self->cval;
|
2020-01-22 13:10:59 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
sprintf(p, "%g", self->dval);
|
2014-03-08 19:13:46 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
slen = strlen(p) + 1;
|
|
|
|
if (*len < slen) {
|
|
|
|
grib_context_log(a->context, GRIB_LOG_ERROR, "Variable unpack_string Wrong size for %s it is %d bytes big (len=%d)", a->name, slen, *len);
|
2014-03-08 19:13:46 +00:00
|
|
|
*len = slen;
|
|
|
|
return GRIB_BUFFER_TOO_SMALL;
|
|
|
|
}
|
2020-01-22 13:10:59 +00:00
|
|
|
strcpy(val, p);
|
2013-03-25 12:04:10 +00:00
|
|
|
*len = slen;
|
|
|
|
|
2014-03-08 19:13:46 +00:00
|
|
|
return GRIB_SUCCESS;
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
static int pack_string(grib_accessor* a, const char* val, size_t* len)
|
2013-03-25 12:04:10 +00:00
|
|
|
{
|
2020-01-22 13:10:59 +00:00
|
|
|
grib_accessor_variable* self = (grib_accessor_variable*)a;
|
|
|
|
grib_context* c = a->context;
|
2014-03-08 19:13:46 +00:00
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
grib_context_free(c, self->cval);
|
|
|
|
self->cval = grib_context_strdup(c, val);
|
2019-08-30 11:47:18 +00:00
|
|
|
self->dval = atof(val);
|
|
|
|
self->type = GRIB_TYPE_STRING;
|
|
|
|
self->cname = NULL;
|
2014-03-08 19:13:46 +00:00
|
|
|
return GRIB_SUCCESS;
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
static int value_count(grib_accessor* a, long* count)
|
2013-03-25 12:04:10 +00:00
|
|
|
{
|
2020-01-22 13:10:59 +00:00
|
|
|
*count = 1;
|
2014-03-08 19:13:46 +00:00
|
|
|
return 0;
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t string_length(grib_accessor* a)
|
|
|
|
{
|
2020-01-22 13:10:59 +00:00
|
|
|
grib_accessor_variable* self = (grib_accessor_variable*)a;
|
|
|
|
if (self->type == GRIB_TYPE_STRING)
|
2014-03-08 19:13:46 +00:00
|
|
|
return strlen(self->cval);
|
|
|
|
else
|
|
|
|
return MAX_VARIABLE_STRING_LENGTH;
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-19 11:31:53 +00:00
|
|
|
static long byte_count(grib_accessor* a)
|
|
|
|
{
|
2014-03-08 19:13:46 +00:00
|
|
|
return a->length;
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* NOT ANY MORE
|
|
|
|
static long byte_count(grib_accessor* a) {
|
2020-01-09 13:03:43 +00:00
|
|
|
grib_accessor_variable *self = (grib_accessor_variable*)a;
|
|
|
|
char buf[80]={0,};
|
|
|
|
|
|
|
|
if(self->type == GRIB_TYPE_STRING) {
|
|
|
|
return strlen(self->cval) +1;
|
|
|
|
} else {
|
|
|
|
sprintf(buf,"%g",self->dval);
|
|
|
|
printf("========> \"%s\"\n",buf);
|
|
|
|
return strlen(buf)+1;
|
|
|
|
}
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
2019-09-25 13:35:43 +00:00
|
|
|
*/
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2017-06-19 11:31:53 +00:00
|
|
|
static int compare(grib_accessor* a, grib_accessor* b)
|
|
|
|
{
|
2020-01-22 13:10:59 +00:00
|
|
|
int retval = 0;
|
|
|
|
double* aval = 0;
|
|
|
|
double* bval = 0;
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2014-03-08 19:13:46 +00:00
|
|
|
size_t alen = 0;
|
|
|
|
size_t blen = 0;
|
2020-01-22 13:10:59 +00:00
|
|
|
int err = 0;
|
|
|
|
long count = 0;
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
err = grib_value_count(a, &count);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
alen = count;
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
err = grib_value_count(b, &count);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
blen = count;
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
if (alen != blen)
|
|
|
|
return GRIB_COUNT_MISMATCH;
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
aval = (double*)grib_context_malloc(a->context, alen * sizeof(double));
|
|
|
|
bval = (double*)grib_context_malloc(b->context, blen * sizeof(double));
|
2014-03-08 19:13:46 +00:00
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
grib_unpack_double(a, aval, &alen);
|
|
|
|
grib_unpack_double(b, bval, &blen);
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2014-03-08 19:13:46 +00:00
|
|
|
retval = GRIB_SUCCESS;
|
|
|
|
while (alen != 0) {
|
2020-01-22 13:10:59 +00:00
|
|
|
if (*bval != *aval)
|
|
|
|
retval = GRIB_DOUBLE_VALUE_MISMATCH;
|
2014-03-08 19:13:46 +00:00
|
|
|
alen--;
|
|
|
|
}
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
grib_context_free(a->context, aval);
|
|
|
|
grib_context_free(b->context, bval);
|
2013-03-25 12:04:10 +00:00
|
|
|
|
2014-03-08 19:13:46 +00:00
|
|
|
return retval;
|
2013-03-25 12:04:10 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
static grib_accessor* make_clone(grib_accessor* a, grib_section* s, int* err)
|
2015-11-06 15:12:08 +00:00
|
|
|
{
|
2020-01-22 13:10:59 +00:00
|
|
|
grib_accessor* the_clone = NULL;
|
|
|
|
grib_accessor_variable* self = (grib_accessor_variable*)a;
|
|
|
|
grib_accessor_variable* variableAccessor = NULL;
|
2020-01-22 14:48:06 +00:00
|
|
|
grib_action creator = {0,};
|
2017-06-16 13:53:10 +00:00
|
|
|
creator.op = "variable";
|
|
|
|
creator.name_space = "";
|
|
|
|
creator.set = 0;
|
|
|
|
|
2020-01-22 13:10:59 +00:00
|
|
|
creator.name = grib_context_strdup(a->context, a->name);
|
|
|
|
the_clone = grib_accessor_factory(s, &creator, 0, NULL);
|
|
|
|
the_clone->parent = NULL;
|
|
|
|
the_clone->h = s->h;
|
|
|
|
the_clone->flags = a->flags;
|
|
|
|
variableAccessor = (grib_accessor_variable*)the_clone;
|
|
|
|
variableAccessor->cname = creator.name; /* ECC-765: Store for later freeing memory */
|
|
|
|
|
|
|
|
*err = 0;
|
|
|
|
variableAccessor->type = self->type;
|
|
|
|
if (self->type == GRIB_TYPE_STRING && self->cval != NULL) {
|
|
|
|
variableAccessor->cval = grib_context_strdup(a->context, self->cval);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
variableAccessor->dval = self->dval;
|
2017-06-16 13:53:10 +00:00
|
|
|
}
|
2015-10-30 10:46:42 +00:00
|
|
|
|
2017-06-16 13:53:10 +00:00
|
|
|
return the_clone;
|
2015-10-30 10:46:42 +00:00
|
|
|
}
|