GRIB-394:grib_filter arithmetic operators not correct for floating point values

This commit is contained in:
Shahram Najm 2013-07-17 17:08:16 +01:00
parent da3ae73708
commit f1340999c2
9 changed files with 1204 additions and 1137 deletions

View File

@ -95,31 +95,32 @@ static void init_class(grib_action_class* c)
/* END_CLASS_IMP */
grib_action* grib_action_create_if( grib_context* context,
grib_expression* expression,
grib_action* block_true,grib_action* block_false,int transient)
{ char name[1024];
grib_action_if* a ;
grib_action_class* c = grib_action_class_if;
grib_action* act = (grib_action*)grib_context_malloc_clear_persistent(context,c->size);
act->op = grib_context_strdup_persistent(context,"section");
grib_expression* expression,
grib_action* block_true,grib_action* block_false,int transient)
{
char name[1024];
grib_action_if* a ;
grib_action_class* c = grib_action_class_if;
grib_action* act = (grib_action*)grib_context_malloc_clear_persistent(context,c->size);
act->op = grib_context_strdup_persistent(context,"section");
act->cclass = c;
a = (grib_action_if*)act;
act->context = context;
act->cclass = c;
a = (grib_action_if*)act;
act->context = context;
a->expression = expression;
a->block_true = block_true;
a->block_false = block_false;
a->transient = transient;
a->expression = expression;
a->block_true = block_true;
a->block_false = block_false;
a->transient = transient;
if (transient)
sprintf(name,"__if%p",(void*)a);
else
sprintf(name,"_if%p",(void*)a);
if (transient)
sprintf(name,"__if%p",(void*)a);
else
sprintf(name,"_if%p",(void*)a);
act->name = grib_context_strdup_persistent(context,name);
act->name = grib_context_strdup_persistent(context,name);
return act;
return act;
}
static void compile(grib_action* act, grib_compiler *compiler)
@ -145,157 +146,165 @@ static void compile(grib_action* act, grib_compiler *compiler)
static int create_accessor( grib_section* p, grib_action* act, grib_loader *h)
{
grib_action_if* a = (grib_action_if*)act;
grib_action* next = NULL;
int ret = 0;
long lres=0;
grib_action_if* a = (grib_action_if*)act;
grib_action* next = NULL;
int ret = 0;
long lres=0;
grib_accessor* as = NULL;
grib_section* gs = NULL;
grib_accessor* as = NULL;
grib_section* gs = NULL;
as = grib_accessor_factory(p, act,0,NULL);
if(!as)return GRIB_INTERNAL_ERROR;
gs = as->sub_section;
grib_push_accessor(as,p->block);
as = grib_accessor_factory(p, act,0,NULL);
if(!as)return GRIB_INTERNAL_ERROR;
gs = as->sub_section;
grib_push_accessor(as,p->block);
if ((ret=grib_expression_evaluate_long(p->h,a->expression,&lres)) != GRIB_SUCCESS)
return ret;
if ((ret=grib_expression_evaluate_long(p->h,a->expression,&lres)) != GRIB_SUCCESS)
return ret;
if(lres)
next = a->block_true;
else
next = a->block_false;
if(lres)
next = a->block_true;
else
next = a->block_false;
#if 0
if(p->h->context->debug > 1)
{
printf("EVALUATE create_accessor_handle ");
grib_expression_print(p->h->context,a->expression,p->h);
printf(" [%d]\n", next == a->block_true);
if(p->h->context->debug > 1)
{
printf("EVALUATE create_accessor_handle ");
grib_expression_print(p->h->context,a->expression,p->h);
printf(" [%d]\n", next == a->block_true);
grib_dump_action_branch(stdout,next,5);
}
grib_dump_action_branch(stdout,next,5);
}
#endif
gs->branch = next;
grib_dependency_observe_expression(as,a->expression);
gs->branch = next;
grib_dependency_observe_expression(as,a->expression);
while(next){
while(next){
ret = grib_create_accessor(gs, next, h);
if(ret != GRIB_SUCCESS) return ret;
next= next->next;
}
ret = grib_create_accessor(gs, next, h);
if(ret != GRIB_SUCCESS) return ret;
next= next->next;
}
return GRIB_SUCCESS;
return GRIB_SUCCESS;
}
static int execute(grib_action* act, grib_handle *h)
{
grib_action_if* a = (grib_action_if*)act;
grib_action* next = NULL;
int ret = 0;
long lres=0;
grib_action_if* a = (grib_action_if*)act;
grib_action* next = NULL;
int ret = 0;
long lres=0;
if ((ret=grib_expression_evaluate_long(h,a->expression,&lres)) != GRIB_SUCCESS) {
if (ret == GRIB_NOT_FOUND) lres=0;
/* See GRIB-394 */
int type = grib_expression_native_type(h, a->expression);
if (type != GRIB_TYPE_DOUBLE) {
if ((ret=grib_expression_evaluate_long(h,a->expression,&lres)) != GRIB_SUCCESS) {
if (ret == GRIB_NOT_FOUND) lres=0;
else return ret;
}
}
else {
double dres = 0.0;
ret = grib_expression_evaluate_double(h, a->expression, &dres);
lres = (long)dres;
if ( ret != GRIB_SUCCESS ) {
if (ret == GRIB_NOT_FOUND) lres=0;
else return ret;
}
}
if(lres)
next = a->block_true;
else
return ret;
}
next = a->block_false;
if(lres)
next = a->block_true;
else
next = a->block_false;
while(next){
ret = grib_action_execute(next, h);
if(ret != GRIB_SUCCESS) return ret;
next= next->next;
}
while(next){
ret = grib_action_execute(next, h);
if(ret != GRIB_SUCCESS) return ret;
next= next->next;
}
return GRIB_SUCCESS;
return GRIB_SUCCESS;
}
static void dump(grib_action* act, FILE* f, int lvl)
{
grib_action_if* a = (grib_action_if*)act;
int i = 0;
grib_action_if* a = (grib_action_if*)act;
int i = 0;
for (i=0;i<lvl;i++)
grib_context_print(act->context,f," ");
for (i=0;i<lvl;i++)
grib_context_print(act->context,f," ");
printf("if(%s) { ",act->name); grib_expression_print(act->context,a->expression,0);
printf("if(%s) { ",act->name); grib_expression_print(act->context,a->expression,0);
printf("\n");
if(a->block_true){
/* grib_context_print(act->context,f,"IF \t TODO \n"); TODO */
grib_dump_action_branch(f,a->block_true,lvl+1);
}
if(a->block_false){
printf("}\n");
for (i=0;i<lvl;i++)
grib_context_print(act->context,f," ");
printf("else(%s) { ",act->name); grib_expression_print(act->context,a->expression,0);
/* grib_context_print(act->context,f,"ELSE \n" );*/
grib_dump_action_branch(f,a->block_false,lvl+1);
}
for (i=0;i<lvl;i++)
grib_context_print(act->context,f," ");
if(a->block_true){
/* grib_context_print(act->context,f,"IF \t TODO \n"); TODO */
grib_dump_action_branch(f,a->block_true,lvl+1);
}
if(a->block_false){
printf("}\n");
for (i=0;i<lvl;i++)
grib_context_print(act->context,f," ");
printf("else(%s) { ",act->name); grib_expression_print(act->context,a->expression,0);
/* grib_context_print(act->context,f,"ELSE \n" );*/
grib_dump_action_branch(f,a->block_false,lvl+1);
}
for (i=0;i<lvl;i++)
grib_context_print(act->context,f," ");
printf("}\n");
}
static grib_action* reparse(grib_action* a,grib_accessor* acc,int* doit)
{
int ret=0;
long lres=0;
grib_action_if* self = (grib_action_if*)a;
int ret=0;
long lres=0;
grib_action_if* self = (grib_action_if*)a;
/* printf("reparse %s %s\n",a->name,acc->name); */
/* printf("reparse %s %s\n",a->name,acc->name); */
if((ret=grib_expression_evaluate_long(acc->parent->h,self->expression,&lres)) != GRIB_SUCCESS)
grib_context_log(acc->parent->h->context,
GRIB_LOG_ERROR,"if reparse grib_expression_evaluate_long %s",
grib_get_error_message(ret));
if((ret=grib_expression_evaluate_long(acc->parent->h,self->expression,&lres)) != GRIB_SUCCESS)
grib_context_log(acc->parent->h->context,
GRIB_LOG_ERROR,"if reparse grib_expression_evaluate_long %s",
grib_get_error_message(ret));
if(lres)
return self->block_true;
else
return self->block_false;
if(lres)
return self->block_true;
else
return self->block_false;
}
static void destroy(grib_context* context,grib_action* act)
{
grib_action_if* a = (grib_action_if*) act;
grib_action *t = a->block_true;
grib_action *f = a->block_false;
grib_action_if* a = (grib_action_if*) act;
grib_action *t = a->block_true;
grib_action *f = a->block_false;
while(t)
{
grib_action *nt = t->next;
grib_free_action(context,t);
t = nt;
}
while(t)
{
grib_action *nt = t->next;
grib_free_action(context,t);
t = nt;
}
while(f)
{
grib_action *nf = f->next;
grib_free_action(context,f);
f = nf;
}
while(f)
{
grib_action *nf = f->next;
grib_free_action(context,f);
f = nf;
}
grib_expression_free(context,a->expression);
grib_expression_free(context,a->expression);
grib_context_free_persistent(context, act->name);
grib_context_free_persistent(context, act->op);
grib_context_free_persistent(context, act->name);
grib_context_free_persistent(context, act->op);
}
static void xref(grib_action* d, FILE* f,const char* path)
{
}

View File

@ -98,82 +98,81 @@ static void init_class(grib_expression_class* c)
static int evaluate_long(grib_expression *g,grib_handle* h,long* lres)
{
long v1=0;
long v2=0;
int ret;
grib_expression_binop* e = (grib_expression_binop*)g;
long v1=0;
long v2=0;
int ret;
grib_expression_binop* e = (grib_expression_binop*)g;
ret = grib_expression_evaluate_long(h,e->left,&v1);
if (ret != GRIB_SUCCESS) return ret;
ret = grib_expression_evaluate_long(h,e->left,&v1);
if (ret != GRIB_SUCCESS) return ret;
ret = grib_expression_evaluate_long(h,e->right,&v2);
if (ret != GRIB_SUCCESS) return ret;
ret = grib_expression_evaluate_long(h,e->right,&v2);
if (ret != GRIB_SUCCESS) return ret;
*lres=e->long_func(v1,v2);
return GRIB_SUCCESS;
*lres=e->long_func(v1,v2);
return GRIB_SUCCESS;
}
static int evaluate_double(grib_expression *g,grib_handle* h,double* dres)
{
double v1=0.0;
double v2=0.0;
int ret;
double v1=0.0;
double v2=0.0;
int ret;
grib_expression_binop* e = (grib_expression_binop*)g;
grib_expression_binop* e = (grib_expression_binop*)g;
ret = grib_expression_evaluate_double(h,e->left,&v1);
if (ret != GRIB_SUCCESS) return ret;
ret = grib_expression_evaluate_double(h,e->left,&v1);
if (ret != GRIB_SUCCESS) return ret;
ret = grib_expression_evaluate_double(h,e->right,&v2);
if (ret != GRIB_SUCCESS) return ret;
ret = grib_expression_evaluate_double(h,e->right,&v2);
if (ret != GRIB_SUCCESS) return ret;
*dres = e->double_func ? e->double_func(v1,v2) : e->long_func(v1,v2);
return GRIB_SUCCESS;
*dres = e->double_func ? e->double_func(v1,v2) : e->long_func(v1,v2);
return GRIB_SUCCESS;
}
static void print(grib_context* c,grib_expression* g,grib_handle* f)
{
grib_expression_binop* e = (grib_expression_binop*)g;
printf("binop(");
grib_expression_print(c,e->left,f);
printf(",");
grib_expression_print(c,e->right,f);
printf(")");
grib_expression_binop* e = (grib_expression_binop*)g;
printf("binop(");
grib_expression_print(c,e->left,f);
printf(",");
grib_expression_print(c,e->right,f);
printf(")");
}
static void destroy(grib_context* c,grib_expression* g)
{
grib_expression_binop* e = (grib_expression_binop*)g;
grib_expression_free(c,e->left);
grib_expression_free(c,e->right);
grib_expression_binop* e = (grib_expression_binop*)g;
grib_expression_free(c,e->left);
grib_expression_free(c,e->right);
}
static void add_dependency(grib_expression* g, grib_accessor* observer){
grib_expression_binop* e = (grib_expression_binop*)g;
grib_dependency_observe_expression(observer,e->left);
grib_dependency_observe_expression(observer,e->right);
static void add_dependency(grib_expression* g, grib_accessor* observer)
{
grib_expression_binop* e = (grib_expression_binop*)g;
grib_dependency_observe_expression(observer,e->left);
grib_dependency_observe_expression(observer,e->right);
}
grib_expression* new_binop_expression(grib_context* c,
grib_binop_long_proc long_func,
grib_binop_double_proc double_func,
grib_expression* left,grib_expression* right)
grib_binop_long_proc long_func,
grib_binop_double_proc double_func,
grib_expression* left,grib_expression* right)
{
grib_expression_binop* e = grib_context_malloc_clear_persistent(c,sizeof(grib_expression_binop));
e->base.cclass = grib_expression_class_binop;
e->left = left;
e->right = right;
e->long_func = long_func;
e->double_func = double_func;
return (grib_expression*)e;
grib_expression_binop* e = grib_context_malloc_clear_persistent(c,sizeof(grib_expression_binop));
e->base.cclass = grib_expression_class_binop;
e->left = left;
e->right = right;
e->long_func = long_func;
e->double_func = double_func;
return (grib_expression*)e;
}
static void compile(grib_expression* g,grib_compiler* c)
{
grib_expression_binop* e = (grib_expression_binop*)g;
grib_expression_binop* e = (grib_expression_binop*)g;
fprintf(c->out,"new_binop_expression(ctx,");
fprintf(c->out,"%s,",grib_binop_long_proc_name(e->long_func));
fprintf(c->out,"%s,",grib_binop_double_proc_name(e->double_func));
@ -185,6 +184,12 @@ static void compile(grib_expression* g,grib_compiler* c)
static int native_type(grib_expression* g,grib_handle *h)
{
grib_expression_binop* e = (grib_expression_binop*)g;
return e->double_func ? GRIB_TYPE_LONG : GRIB_TYPE_DOUBLE;
grib_expression_binop* e = (grib_expression_binop*)g;
/* See GRIB-394 : The type of this binary expression will be double if any of its operands are double */
if (grib_expression_native_type(h, e->left) == GRIB_TYPE_DOUBLE ||
grib_expression_native_type(h, e->right) == GRIB_TYPE_DOUBLE)
{
return GRIB_TYPE_DOUBLE;
}
return e->double_func ? GRIB_TYPE_LONG : GRIB_TYPE_DOUBLE;
}

View File

@ -94,63 +94,63 @@ static void init_class(grib_expression_class* c)
static int evaluate_long(grib_expression* g,grib_handle* h,long* lres)
{
int ret;
long v=0;
grib_expression_unop* e = (grib_expression_unop*)g;
ret = grib_expression_evaluate_long(h,e->exp,&v);
if (ret != GRIB_SUCCESS) return ret;
*lres=e->long_func(v);
return GRIB_SUCCESS;
int ret;
long v=0;
grib_expression_unop* e = (grib_expression_unop*)g;
ret = grib_expression_evaluate_long(h,e->exp,&v);
if (ret != GRIB_SUCCESS) return ret;
*lres=e->long_func(v);
return GRIB_SUCCESS;
}
static int evaluate_double(grib_expression* g,grib_handle* h,double* dres)
{
int ret;
double v=0;
grib_expression_unop* e = (grib_expression_unop*)g;
ret = grib_expression_evaluate_double(h,e->exp,&v);
if (ret != GRIB_SUCCESS) return ret;
*dres = e->double_func ? e->double_func(v) : e->long_func(v);
return GRIB_SUCCESS;
int ret;
double v=0;
grib_expression_unop* e = (grib_expression_unop*)g;
ret = grib_expression_evaluate_double(h,e->exp,&v);
if (ret != GRIB_SUCCESS) return ret;
*dres = e->double_func ? e->double_func(v) : e->long_func(v);
return GRIB_SUCCESS;
}
static void print(grib_context* c,grib_expression* g,grib_handle* f)
{
grib_expression_unop* e = (grib_expression_unop*)g;
printf("unop(");
grib_expression_print(c,e->exp,f);
printf(")");
grib_expression_unop* e = (grib_expression_unop*)g;
printf("unop(");
grib_expression_print(c,e->exp,f);
printf(")");
}
static void destroy(grib_context* c,grib_expression* g)
{
grib_expression_unop* e = (grib_expression_unop*)g;
grib_expression_free(c,e->exp);
grib_expression_unop* e = (grib_expression_unop*)g;
grib_expression_free(c,e->exp);
}
static void add_dependency(grib_expression* g, grib_accessor* observer){
grib_expression_unop* e = (grib_expression_unop*)g;
grib_dependency_observe_expression(observer,e->exp);
grib_expression_unop* e = (grib_expression_unop*)g;
grib_dependency_observe_expression(observer,e->exp);
}
grib_expression* new_unop_expression(grib_context* c,
grib_unop_long_proc long_func,
grib_unop_double_proc double_func,
grib_expression* exp)
grib_unop_long_proc long_func,
grib_unop_double_proc double_func,
grib_expression* exp)
{
grib_expression_unop* e = grib_context_malloc_clear_persistent(c,sizeof(grib_expression_unop));
e->base.cclass = grib_expression_class_unop;
e->exp = exp;
e->long_func = long_func;
e->double_func = double_func;
return (grib_expression*)e;
grib_expression_unop* e = grib_context_malloc_clear_persistent(c,sizeof(grib_expression_unop));
e->base.cclass = grib_expression_class_unop;
e->exp = exp;
e->long_func = long_func;
e->double_func = double_func;
return (grib_expression*)e;
}
static void compile(grib_expression* g,grib_compiler* c)
{
grib_expression_unop* e = (grib_expression_unop*)g;
grib_expression_unop* e = (grib_expression_unop*)g;
fprintf(c->out,"new_unop_expression(ctx,");
fprintf(c->out,"%s,",grib_unop_long_proc_name(e->long_func));
fprintf(c->out,"%s,",grib_unop_double_proc_name(e->double_func));
@ -160,7 +160,6 @@ static void compile(grib_expression* g,grib_compiler* c)
static int native_type(grib_expression* g,grib_handle *h)
{
grib_expression_unop* e = (grib_expression_unop*)g;
return e->double_func ? GRIB_TYPE_LONG : GRIB_TYPE_DOUBLE;
grib_expression_unop* e = (grib_expression_unop*)g;
return e->double_func ? GRIB_TYPE_DOUBLE : GRIB_TYPE_LONG;
}

View File

@ -359,8 +359,8 @@ static void grib_yy_fatal_error (grib_yyconst char msg[] );
*grib_yy_cp = '\0'; \
(grib_yy_c_buf_p) = grib_yy_cp;
#define YY_NUM_RULES 100
#define YY_END_OF_BUFFER 101
#define YY_NUM_RULES 102
#define YY_END_OF_BUFFER 103
/* This struct is not used in this scanner,
but its presence is necessary. */
struct grib_yy_trans_info
@ -370,62 +370,62 @@ struct grib_yy_trans_info
};
static grib_yyconst flex_int16_t grib_yy_accept[507] =
{ 0,
97, 97, 101, 99, 97, 98, 10, 91, 96, 99,
99, 94, 99, 99, 99, 93, 93, 93, 92, 93,
93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
93, 93, 93, 93, 93, 93, 93, 93, 93, 99,
16, 97, 4, 12, 0, 0, 94, 3, 5, 1,
2, 93, 93, 93, 93, 93, 93, 93, 93, 93,
93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
93, 93, 93, 93, 93, 93, 18, 93, 8, 93,
93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
13, 93, 93, 93, 93, 93, 93, 93, 93, 93,
99, 99, 103, 101, 99, 100, 12, 93, 98, 101,
101, 96, 5, 101, 3, 95, 95, 95, 94, 95,
95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95, 95, 101,
18, 99, 6, 14, 0, 0, 96, 4, 7, 1,
2, 95, 95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 20, 95, 10, 95,
95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
15, 95, 95, 95, 95, 95, 95, 95, 95, 95,
93, 93, 93, 93, 93, 93, 14, 95, 93, 19,
93, 11, 93, 93, 93, 6, 55, 93, 93, 93,
93, 93, 93, 93, 93, 93, 93, 93, 30, 93,
93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
9, 93, 93, 43, 93, 93, 93, 93, 93, 78,
93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
93, 93, 0, 93, 93, 93, 93, 93, 23, 93,
81, 93, 93, 93, 93, 93, 93, 70, 93, 20,
93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
95, 95, 95, 95, 95, 95, 16, 97, 95, 21,
95, 13, 95, 95, 95, 8, 57, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95, 32, 95,
95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
11, 95, 95, 45, 95, 95, 95, 95, 95, 80,
95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 0, 95, 95, 95, 95, 95, 25, 95,
83, 95, 95, 95, 95, 95, 95, 72, 95, 22,
95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
93, 56, 93, 93, 25, 93, 93, 93, 93, 39,
93, 93, 93, 93, 93, 15, 93, 93, 93, 93,
93, 93, 93, 93, 93, 89, 93, 93, 93, 93,
93, 93, 93, 80, 93, 93, 0, 95, 93, 46,
93, 22, 93, 93, 93, 93, 93, 93, 93, 93,
93, 93, 93, 37, 93, 93, 93, 93, 93, 93,
93, 93, 93, 93, 24, 93, 93, 93, 93, 93,
93, 93, 93, 93, 93, 93, 41, 93, 88, 93,
93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
93, 26, 86, 93, 87, 66, 93, 93, 93, 93,
95, 58, 95, 95, 27, 95, 95, 95, 95, 41,
95, 95, 95, 95, 95, 17, 95, 95, 95, 95,
95, 95, 95, 95, 95, 91, 95, 95, 95, 95,
95, 95, 95, 82, 95, 95, 0, 97, 95, 48,
95, 24, 95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 39, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 26, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 43, 95, 90, 95,
95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
95, 28, 88, 95, 89, 68, 95, 95, 95, 95,
93, 93, 93, 93, 93, 63, 93, 93, 93, 93,
35, 72, 93, 93, 93, 93, 93, 65, 93, 38,
93, 93, 59, 93, 93, 93, 7, 93, 93, 93,
93, 93, 64, 93, 93, 33, 93, 82, 93, 93,
93, 93, 93, 74, 93, 93, 93, 84, 93, 93,
77, 83, 93, 57, 93, 93, 93, 93, 93, 90,
93, 93, 93, 93, 45, 54, 68, 71, 93, 93,
93, 93, 93, 93, 93, 93, 93, 93, 29, 47,
93, 93, 93, 93, 93, 49, 93, 93, 93, 93,
93, 31, 93, 53, 93, 93, 93, 76, 93, 93,
95, 95, 95, 95, 95, 65, 95, 95, 95, 95,
37, 74, 95, 95, 95, 95, 95, 67, 95, 40,
95, 95, 61, 95, 95, 95, 9, 95, 95, 95,
95, 95, 66, 95, 95, 35, 95, 84, 95, 95,
95, 95, 95, 76, 95, 95, 95, 86, 95, 95,
79, 85, 95, 59, 95, 95, 95, 95, 95, 92,
95, 95, 95, 95, 47, 56, 70, 73, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95, 31, 49,
95, 95, 95, 95, 95, 51, 95, 95, 95, 95,
95, 33, 95, 55, 95, 95, 95, 78, 95, 95,
48, 93, 93, 93, 93, 27, 93, 21, 93, 34,
93, 93, 93, 93, 93, 93, 93, 32, 93, 52,
17, 40, 93, 67, 93, 93, 93, 93, 50, 93,
93, 93, 75, 93, 93, 93, 93, 93, 93, 93,
79, 93, 93, 93, 93, 93, 93, 93, 93, 93,
58, 93, 93, 51, 93, 93, 93, 93, 93, 93,
93, 93, 93, 93, 93, 93, 93, 93, 93, 93,
93, 93, 42, 93, 93, 73, 93, 85, 93, 93,
93, 93, 93, 93, 93, 93, 93, 93, 93, 44,
28, 93, 69, 93, 93, 93, 36, 93, 61, 93,
50, 95, 95, 95, 95, 29, 95, 23, 95, 36,
95, 95, 95, 95, 95, 95, 95, 34, 95, 54,
19, 42, 95, 69, 95, 95, 95, 95, 52, 95,
95, 95, 77, 95, 95, 95, 95, 95, 95, 95,
81, 95, 95, 95, 95, 95, 95, 95, 95, 95,
60, 95, 95, 53, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 44, 95, 95, 75, 95, 87, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95, 95, 46,
30, 95, 71, 95, 95, 95, 38, 95, 63, 95,
93, 62, 93, 93, 60, 0
95, 64, 95, 95, 62, 0
} ;
static grib_yyconst flex_int32_t grib_yy_ec[256] =
@ -1398,167 +1398,167 @@ return GE ;
case 3:
YY_RULE_SETUP
#line 62 "gribl.l"
return LE ;
return GT ;
YY_BREAK
case 4:
YY_RULE_SETUP
#line 63 "gribl.l"
return NE ;
return LE ;
YY_BREAK
case 5:
YY_RULE_SETUP
#line 64 "gribl.l"
return NE ;
return LT ;
YY_BREAK
case 6:
YY_RULE_SETUP
#line 65 "gribl.l"
return BIT ;
return NE ;
YY_BREAK
case 7:
YY_RULE_SETUP
#line 66 "gribl.l"
return BITOFF ;
return NE ;
YY_BREAK
case 8:
YY_RULE_SETUP
#line 68 "gribl.l"
return IS ;
#line 67 "gribl.l"
return BIT ;
YY_BREAK
case 9:
YY_RULE_SETUP
#line 69 "gribl.l"
return NOT ;
#line 68 "gribl.l"
return BITOFF ;
YY_BREAK
case 10:
YY_RULE_SETUP
#line 70 "gribl.l"
return NOT ;
return IS ;
YY_BREAK
case 11:
YY_RULE_SETUP
#line 71 "gribl.l"
return AND ;
return NOT ;
YY_BREAK
case 12:
YY_RULE_SETUP
#line 72 "gribl.l"
return AND ;
return NOT ;
YY_BREAK
case 13:
YY_RULE_SETUP
#line 73 "gribl.l"
return OR ;
return AND ;
YY_BREAK
case 14:
YY_RULE_SETUP
#line 74 "gribl.l"
return OR ;
return AND ;
YY_BREAK
case 15:
YY_RULE_SETUP
#line 76 "gribl.l"
return NIL ;
#line 75 "gribl.l"
return OR ;
YY_BREAK
case 16:
YY_RULE_SETUP
#line 77 "gribl.l"
return DUMMY ;
#line 76 "gribl.l"
return OR ;
YY_BREAK
case 17:
YY_RULE_SETUP
#line 79 "gribl.l"
return LOWERCASE;
#line 78 "gribl.l"
return NIL ;
YY_BREAK
case 18:
YY_RULE_SETUP
#line 80 "gribl.l"
return IF ;
#line 79 "gribl.l"
return DUMMY ;
YY_BREAK
case 19:
YY_RULE_SETUP
#line 81 "gribl.l"
return IF_TRANSIENT ;
return LOWERCASE;
YY_BREAK
case 20:
YY_RULE_SETUP
#line 82 "gribl.l"
return ELSE ;
return IF ;
YY_BREAK
case 21:
YY_RULE_SETUP
#line 83 "gribl.l"
return UNSIGNED ;
return IF_TRANSIENT ;
YY_BREAK
case 22:
YY_RULE_SETUP
#line 84 "gribl.l"
return ASCII ;
return ELSE ;
YY_BREAK
case 23:
YY_RULE_SETUP
#line 85 "gribl.l"
return BYTE ;
return UNSIGNED ;
YY_BREAK
case 24:
YY_RULE_SETUP
#line 86 "gribl.l"
return LABEL ;
return ASCII ;
YY_BREAK
case 25:
YY_RULE_SETUP
#line 87 "gribl.l"
return LIST ;
return BYTE ;
YY_BREAK
case 26:
YY_RULE_SETUP
#line 88 "gribl.l"
return WHILE ;
return LABEL ;
YY_BREAK
case 27:
YY_RULE_SETUP
#line 89 "gribl.l"
return TEMPLATE ;
return LIST ;
YY_BREAK
case 28:
YY_RULE_SETUP
#line 90 "gribl.l"
return TEMPLATE_NOFAIL ;
return WHILE ;
YY_BREAK
case 29:
YY_RULE_SETUP
#line 91 "gribl.l"
return TRIGGER ;
return TEMPLATE ;
YY_BREAK
case 30:
YY_RULE_SETUP
#line 92 "gribl.l"
return END ;
return TEMPLATE_NOFAIL ;
YY_BREAK
case 31:
YY_RULE_SETUP
#line 93 "gribl.l"
return IBMFLOAT ;
return TRIGGER ;
YY_BREAK
case 32:
YY_RULE_SETUP
#line 94 "gribl.l"
return FLOAT ;
return END ;
YY_BREAK
case 33:
YY_RULE_SETUP
#line 95 "gribl.l"
return SIGNED ;
return IBMFLOAT ;
YY_BREAK
case 34:
YY_RULE_SETUP
#line 96 "gribl.l"
return CODETABLE;
return FLOAT ;
YY_BREAK
case 35:
YY_RULE_SETUP
#line 97 "gribl.l"
return GETENV;
return SIGNED ;
YY_BREAK
case 36:
YY_RULE_SETUP
@ -1568,271 +1568,281 @@ return CODETABLE;
case 37:
YY_RULE_SETUP
#line 99 "gribl.l"
return FLAG ;
return GETENV;
YY_BREAK
case 38:
YY_RULE_SETUP
#line 100 "gribl.l"
return LOOKUP ;
return CODETABLE;
YY_BREAK
case 39:
YY_RULE_SETUP
#line 101 "gribl.l"
return META ;
return FLAG ;
YY_BREAK
case 40:
YY_RULE_SETUP
#line 102 "gribl.l"
return PADTOEVEN ;
return LOOKUP ;
YY_BREAK
case 41:
YY_RULE_SETUP
#line 103 "gribl.l"
return PADTO ;
return META ;
YY_BREAK
case 42:
YY_RULE_SETUP
#line 104 "gribl.l"
return PADTOMULTIPLE ;
return PADTOEVEN ;
YY_BREAK
case 43:
YY_RULE_SETUP
#line 105 "gribl.l"
return PAD ;
return PADTO ;
YY_BREAK
case 44:
YY_RULE_SETUP
#line 106 "gribl.l"
return SECTION_PADDING ;
return PADTOMULTIPLE ;
YY_BREAK
case 45:
YY_RULE_SETUP
#line 107 "gribl.l"
return MESSAGE ;
return PAD ;
YY_BREAK
case 46:
YY_RULE_SETUP
#line 108 "gribl.l"
return ALIAS ;
return SECTION_PADDING ;
YY_BREAK
case 47:
YY_RULE_SETUP
#line 109 "gribl.l"
return UNALIAS ;
return MESSAGE ;
YY_BREAK
case 48:
YY_RULE_SETUP
#line 110 "gribl.l"
return POS ;
return ALIAS ;
YY_BREAK
case 49:
YY_RULE_SETUP
#line 111 "gribl.l"
return INTCONST ;
return UNALIAS ;
YY_BREAK
case 50:
YY_RULE_SETUP
#line 112 "gribl.l"
return TRANS ;
return POS ;
YY_BREAK
case 51:
YY_RULE_SETUP
#line 113 "gribl.l"
return STRING_TYPE ;
return INTCONST ;
YY_BREAK
case 52:
YY_RULE_SETUP
#line 114 "gribl.l"
return LONG_TYPE ;
return TRANS ;
YY_BREAK
case 53:
YY_RULE_SETUP
#line 115 "gribl.l"
return ITERATOR ;
return STRING_TYPE ;
YY_BREAK
case 54:
YY_RULE_SETUP
#line 116 "gribl.l"
return NEAREST ;
return LONG_TYPE ;
YY_BREAK
case 55:
YY_RULE_SETUP
#line 117 "gribl.l"
return BOX ;
return ITERATOR ;
YY_BREAK
case 56:
YY_RULE_SETUP
#line 118 "gribl.l"
return KSEC ;
return NEAREST ;
YY_BREAK
case 57:
YY_RULE_SETUP
#line 119 "gribl.l"
return FLAGBIT ;
return BOX ;
YY_BREAK
case 58:
YY_RULE_SETUP
#line 120 "gribl.l"
return KSEC1EXPVER ;
return KSEC ;
YY_BREAK
case 59:
YY_RULE_SETUP
#line 121 "gribl.l"
return MODIFY ;
return FLAGBIT ;
YY_BREAK
case 60:
YY_RULE_SETUP
#line 123 "gribl.l"
return G1_HALF_BYTE ;
#line 122 "gribl.l"
return KSEC1EXPVER ;
YY_BREAK
case 61:
YY_RULE_SETUP
#line 124 "gribl.l"
return G1_MESSAGE_LENGTH ;
#line 123 "gribl.l"
return MODIFY ;
YY_BREAK
case 62:
YY_RULE_SETUP
#line 125 "gribl.l"
return G1_SECTION4_LENGTH ;
return G1_HALF_BYTE ;
YY_BREAK
case 63:
YY_RULE_SETUP
#line 127 "gribl.l"
return EXPORT;
#line 126 "gribl.l"
return G1_MESSAGE_LENGTH ;
YY_BREAK
case 64:
YY_RULE_SETUP
#line 128 "gribl.l"
return REMOVE;
#line 127 "gribl.l"
return G1_SECTION4_LENGTH ;
YY_BREAK
case 65:
YY_RULE_SETUP
#line 130 "gribl.l"
return SECTION_LENGTH ;
#line 129 "gribl.l"
return EXPORT;
YY_BREAK
case 66:
YY_RULE_SETUP
#line 132 "gribl.l"
return ASSERT ;
#line 130 "gribl.l"
return REMOVE;
YY_BREAK
case 67:
YY_RULE_SETUP
#line 134 "gribl.l"
return READ_ONLY;
#line 132 "gribl.l"
return SECTION_LENGTH ;
YY_BREAK
case 68:
YY_RULE_SETUP
#line 135 "gribl.l"
return NO_COPY;
#line 134 "gribl.l"
return ASSERT ;
YY_BREAK
case 69:
YY_RULE_SETUP
#line 136 "gribl.l"
return EDITION_SPECIFIC;
return READ_ONLY;
YY_BREAK
case 70:
YY_RULE_SETUP
#line 137 "gribl.l"
return DUMP;
return NO_COPY;
YY_BREAK
case 71:
YY_RULE_SETUP
#line 138 "gribl.l"
return NO_FAIL;
return EDITION_SPECIFIC;
YY_BREAK
case 72:
YY_RULE_SETUP
#line 139 "gribl.l"
return HIDDEN;
return DUMP;
YY_BREAK
case 73:
YY_RULE_SETUP
#line 140 "gribl.l"
return CAN_BE_MISSING;
return NO_FAIL;
YY_BREAK
case 74:
YY_RULE_SETUP
#line 141 "gribl.l"
return MISSING;
return HIDDEN;
YY_BREAK
case 75:
YY_RULE_SETUP
#line 142 "gribl.l"
return CONSTRAINT;
return CAN_BE_MISSING;
YY_BREAK
case 76:
YY_RULE_SETUP
#line 143 "gribl.l"
return OVERRIDE;
return MISSING;
YY_BREAK
case 77:
YY_RULE_SETUP
#line 144 "gribl.l"
return COPY_OK;
return CONSTRAINT;
YY_BREAK
case 78:
YY_RULE_SETUP
#line 146 "gribl.l"
return SET;
#line 145 "gribl.l"
return OVERRIDE;
YY_BREAK
case 79:
YY_RULE_SETUP
#line 147 "gribl.l"
return SET_NOFAIL;
#line 146 "gribl.l"
return COPY_OK;
YY_BREAK
case 80:
YY_RULE_SETUP
#line 148 "gribl.l"
return WHEN;
return SET;
YY_BREAK
case 81:
YY_RULE_SETUP
#line 149 "gribl.l"
return CASE;
return SET_NOFAIL;
YY_BREAK
case 82:
YY_RULE_SETUP
#line 150 "gribl.l"
return SWITCH;
return WHEN;
YY_BREAK
case 83:
YY_RULE_SETUP
#line 151 "gribl.l"
return DEFAULT;
return CASE;
YY_BREAK
case 84:
YY_RULE_SETUP
#line 152 "gribl.l"
return CONCEPT;
return SWITCH;
YY_BREAK
case 85:
YY_RULE_SETUP
#line 153 "gribl.l"
return CONCEPT_NOFAIL;
return DEFAULT;
YY_BREAK
case 86:
YY_RULE_SETUP
#line 154 "gribl.l"
return WRITE;
return CONCEPT;
YY_BREAK
case 87:
YY_RULE_SETUP
#line 155 "gribl.l"
return APPEND;
return CONCEPT_NOFAIL;
YY_BREAK
case 88:
YY_RULE_SETUP
#line 156 "gribl.l"
return PRINT;
return WRITE;
YY_BREAK
case 89:
YY_RULE_SETUP
#line 157 "gribl.l"
return SKIP;
return APPEND;
YY_BREAK
case 90:
YY_RULE_SETUP
#line 158 "gribl.l"
return PRINT;
YY_BREAK
case 91:
YY_RULE_SETUP
#line 159 "gribl.l"
return SKIP;
YY_BREAK
case 92:
YY_RULE_SETUP
#line 161 "gribl.l"
{
int c,q;
while((c = input()) && isspace(c) && c != '\n') ;
@ -1850,9 +1860,9 @@ YY_RULE_SETUP
grib_parser_include(grib_yytext);
}
YY_BREAK
case 91:
case 93:
YY_RULE_SETUP
#line 176 "gribl.l"
#line 178 "gribl.l"
{
int c,q = grib_yytext[0];
@ -1869,9 +1879,9 @@ YY_RULE_SETUP
return STRING;
}
YY_BREAK
case 92:
case 94:
YY_RULE_SETUP
#line 192 "gribl.l"
#line 194 "gribl.l"
{
int c;
unsigned long val = 0;
@ -1885,24 +1895,24 @@ YY_RULE_SETUP
return INTEGER;
}
YY_BREAK
case 93:
YY_RULE_SETUP
#line 206 "gribl.l"
{ grib_yylval.str = strdup(grib_yytext); return IDENT; }
YY_BREAK
case 94:
YY_RULE_SETUP
#line 207 "gribl.l"
{ grib_yylval.lval = atol((const char *)grib_yytext); return INTEGER; }
YY_BREAK
case 95:
YY_RULE_SETUP
#line 208 "gribl.l"
{ grib_yylval.dval = atof((const char *)grib_yytext); return FLOAT; }
{ grib_yylval.str = strdup(grib_yytext); return IDENT; }
YY_BREAK
case 96:
YY_RULE_SETUP
#line 211 "gribl.l"
#line 209 "gribl.l"
{ grib_yylval.lval = atol((const char *)grib_yytext); return INTEGER; }
YY_BREAK
case 97:
YY_RULE_SETUP
#line 210 "gribl.l"
{ grib_yylval.dval = atof((const char *)grib_yytext); return FLOAT; }
YY_BREAK
case 98:
YY_RULE_SETUP
#line 213 "gribl.l"
{
int c;
while((c = input()) && (c != '\n')){}
@ -1910,28 +1920,28 @@ YY_RULE_SETUP
grib_yylineno++;
}
YY_BREAK
case 97:
YY_RULE_SETUP
#line 217 "gribl.l"
;
YY_BREAK
case 98:
/* rule 98 can match eol */
YY_RULE_SETUP
#line 218 "gribl.l"
grib_yylineno++;
YY_BREAK
case 99:
YY_RULE_SETUP
#line 222 "gribl.l"
return *grib_yytext;
#line 219 "gribl.l"
;
YY_BREAK
case 100:
/* rule 100 can match eol */
YY_RULE_SETUP
#line 220 "gribl.l"
grib_yylineno++;
YY_BREAK
case 101:
YY_RULE_SETUP
#line 224 "gribl.l"
return *grib_yytext;
YY_BREAK
case 102:
YY_RULE_SETUP
#line 226 "gribl.l"
ECHO;
YY_BREAK
#line 1935 "lex.grib_yy.c"
#line 1945 "lex.grib_yy.c"
case YY_STATE_EOF(INITIAL):
grib_yyterminate();
@ -2929,7 +2939,7 @@ void grib_yyfree (void * ptr )
#define YYTABLES_NAME "grib_yytables"
#line 224 "gribl.l"
#line 226 "gribl.l"

File diff suppressed because it is too large Load Diff

View File

@ -117,16 +117,18 @@
NE = 333,
GE = 334,
LE = 335,
BIT = 336,
BITOFF = 337,
AND = 338,
OR = 339,
NOT = 340,
IS = 341,
IDENT = 342,
STRING = 343,
INTEGER = 344,
FLOAT = 345
LT = 336,
GT = 337,
BIT = 338,
BITOFF = 339,
AND = 340,
OR = 341,
NOT = 342,
IS = 343,
IDENT = 344,
STRING = 345,
INTEGER = 346,
FLOAT = 347
};
#endif
/* Tokens. */
@ -208,16 +210,18 @@
#define NE 333
#define GE 334
#define LE 335
#define BIT 336
#define BITOFF 337
#define AND 338
#define OR 339
#define NOT 340
#define IS 341
#define IDENT 342
#define STRING 343
#define INTEGER 344
#define FLOAT 345
#define LT 336
#define GT 337
#define BIT 338
#define BITOFF 339
#define AND 340
#define OR 341
#define NOT 342
#define IS 343
#define IDENT 344
#define STRING 345
#define INTEGER 346
#define FLOAT 347
@ -246,7 +250,7 @@ typedef union YYSTYPE
/* Line 1676 of yacc.c */
#line 250 "y.tab.h"
#line 254 "y.tab.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define grib_yystype YYSTYPE /* obsolescent; will be withdrawn */

View File

@ -59,7 +59,9 @@ FLOAT {SIGN}?{DIGIT}+\.{DIGIT}+{EXP}?
"==" return EQ ;
">=" return GE ;
">" return GT ;
"<=" return LE ;
"<" return LT ;
"!=" return NE ;
"<>" return NE ;
"bit" return BIT ;

View File

@ -134,6 +134,8 @@ static grib_concept_value *reverse_concept(grib_concept_value *r,grib_concept_va
%token NE
%token GE
%token LE
%token LT
%token GT
%token BIT
%token BITOFF
@ -627,13 +629,13 @@ term : term '+' factor { $$ = new_binop_expression(grib_parser_cont
| factor
;
condition : condition '>' term { $$ = new_binop_expression(grib_parser_context,&grib_op_gt,&grib_op_gt_d,$1,$3); }
/* | condition '=' term { $$ = new_binop_expression(grib_parser_context,&grib_op_eq,$1,$3); } */
condition : condition GT term { $$ = new_binop_expression(grib_parser_context,&grib_op_gt,&grib_op_gt_d,$1,$3); }
/* | condition '=' term { $$ = new_binop_expression(grib_parser_context,&grib_op_eq,$1,$3); } */
| condition EQ term { $$ = new_binop_expression(grib_parser_context,&grib_op_eq,&grib_op_eq_d,$1,$3); }
| condition '<' term { $$ = new_binop_expression(grib_parser_context,&grib_op_lt,&grib_op_lt_d,$1,$3); }
| condition GE term { $$ = new_binop_expression(grib_parser_context,&grib_op_ge,&grib_op_ge_d,$1,$3); }
| condition LE term { $$ = new_binop_expression(grib_parser_context,&grib_op_le,&grib_op_le_d,$1,$3); }
| condition NE term { $$ = new_binop_expression(grib_parser_context,&grib_op_ne,&grib_op_ne_d,$1,$3); }
| condition LT term { $$ = new_binop_expression(grib_parser_context,&grib_op_lt,&grib_op_lt_d,$1,$3); }
| condition GE term { $$ = new_binop_expression(grib_parser_context,&grib_op_ge,&grib_op_ge_d,$1,$3); }
| condition LE term { $$ = new_binop_expression(grib_parser_context,&grib_op_le,&grib_op_le_d,$1,$3); }
| condition NE term { $$ = new_binop_expression(grib_parser_context,&grib_op_ne,&grib_op_ne_d,$1,$3); }
| string_or_ident IS string_or_ident { $$ = new_string_compare_expression(grib_parser_context,$1,$3); }
/*
| condition IN term { $$ = new_binop_expression(grib_parser_context,grib_op_pow,$1,$3); }

View File

@ -72,6 +72,36 @@ ${tools_dir}/grib_filter -o temp.grib2 temp.filt $GRIB_SAMPLES_PATH/GRIB1.tmpl
result=`${tools_dir}/grib_get -p typeOfFirstFixedSurface,NV,nlev temp.grib2`
[ "$result" = "150 6 41" ]
rm -f temp.grib2 temp.filt
rm -f ${data_dir}/formatint.rules
# GRIB-394: grib_filter arithmetic operators not correct for floating point values
###################################################################################
cat > ${data_dir}/binop.rules <<EOF
transient val_exact=209.53530883789062500000;
if (referenceValue == val_exact) {
print "OK Equality test passed";
}
else {
print "***ERROR: float equality test";
assert(0);
}
transient val_lower=209;
if (referenceValue > val_lower) {
print "OK [referenceValue] > [val_lower]";
}
else {
print "***ERROR: [referenceValue] <= [val_lower]";
assert(0);
}
transient val_higher=209.99;
if (referenceValue < val_higher) {
print "OK [referenceValue] < [val_higher]";
}
else {
print "***ERROR: [referenceValue] >= [val_higher]";
assert(0);
}
EOF
${tools_dir}/grib_filter ${data_dir}/binop.rules $GRIB_SAMPLES_PATH/gg_sfc_grib1.tmpl >/dev/null
rm -f temp.grib2 temp.filt
rm -f ${data_dir}/formatint.rules ${data_dir}/binop.rules