mirror of https://github.com/ecmwf/eccodes.git
ECC-158 part 2
This commit is contained in:
parent
8d56538abd
commit
a724329f8a
|
@ -23,6 +23,7 @@ list( APPEND grib_api_srcs
|
|||
action_class_concept.c
|
||||
action_class_hash_array.c
|
||||
action_class_set.c
|
||||
action_class_set_sarray.c
|
||||
action_class_set_darray.c
|
||||
action_class_set_iarray.c
|
||||
action_class_noop.c
|
||||
|
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* Copyright 2005-2015 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 = action
|
||||
IMPLEMENTS = dump;xref
|
||||
IMPLEMENTS = destroy;execute
|
||||
MEMBERS = grib_sarray *sarray
|
||||
MEMBERS = char *name
|
||||
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 "action.class" and rerun ./make_class.pl
|
||||
|
||||
*/
|
||||
|
||||
static void init_class (grib_action_class*);
|
||||
static void dump (grib_action* d, FILE*,int);
|
||||
static void xref (grib_action* d, FILE* f,const char* path);
|
||||
static void destroy (grib_context*,grib_action*);
|
||||
static int execute(grib_action* a,grib_handle* h);
|
||||
|
||||
|
||||
typedef struct grib_action_set_sarray {
|
||||
grib_action act;
|
||||
/* Members defined in set_sarray */
|
||||
grib_sarray *sarray;
|
||||
char *name;
|
||||
} grib_action_set_sarray;
|
||||
|
||||
|
||||
static grib_action_class _grib_action_class_set_sarray = {
|
||||
0, /* super */
|
||||
"action_class_set_sarray", /* name */
|
||||
sizeof(grib_action_set_sarray), /* size */
|
||||
0, /* inited */
|
||||
&init_class, /* init_class */
|
||||
0, /* init */
|
||||
&destroy, /* destroy */
|
||||
|
||||
&dump, /* dump */
|
||||
&xref, /* xref */
|
||||
|
||||
0, /* create_accessor*/
|
||||
|
||||
0, /* notify_change */
|
||||
0, /* reparse */
|
||||
&execute, /* execute */
|
||||
0, /* compile */
|
||||
};
|
||||
|
||||
grib_action_class* grib_action_class_set_sarray = &_grib_action_class_set_sarray;
|
||||
|
||||
static void init_class(grib_action_class* c)
|
||||
{
|
||||
}
|
||||
/* END_CLASS_IMP */
|
||||
|
||||
grib_action* grib_action_create_set_sarray( grib_context* context,
|
||||
const char* name,
|
||||
grib_sarray* sarray)
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
grib_action_set_sarray* a ;
|
||||
grib_action_class* c = grib_action_class_set_sarray;
|
||||
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_set_sarray*)act;
|
||||
act->context = context;
|
||||
|
||||
a->sarray = sarray;
|
||||
a->name = grib_context_strdup_persistent(context,name);
|
||||
|
||||
|
||||
sprintf(buf,"set_sarray%p",(void*)sarray);
|
||||
|
||||
act->name = grib_context_strdup_persistent(context,buf);
|
||||
|
||||
return act;
|
||||
}
|
||||
|
||||
static int execute(grib_action* a, grib_handle *h)
|
||||
{
|
||||
grib_action_set_sarray* self = (grib_action_set_sarray*) a;
|
||||
|
||||
return grib_set_string_array(h,self->name,self->sarray->v,self->sarray->n);
|
||||
}
|
||||
|
||||
|
||||
static void dump(grib_action* act, FILE* f, int lvl)
|
||||
{
|
||||
int i =0;
|
||||
grib_action_set_sarray* self=(grib_action_set_sarray*)act;
|
||||
for (i=0;i<lvl;i++)
|
||||
grib_context_print(act->context,f," ");
|
||||
grib_context_print(act->context,f,self->name);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
static void destroy(grib_context* context,grib_action* act)
|
||||
{
|
||||
grib_action_set_sarray* a = (grib_action_set_sarray*) act;
|
||||
|
||||
grib_context_free_persistent(context, a->name);
|
||||
grib_sarray_delete(context,a->sarray);
|
||||
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)
|
||||
{
|
||||
}
|
|
@ -132,6 +132,23 @@ int grib_pack_string(grib_accessor* a, const char* v, size_t *len )
|
|||
return 0;
|
||||
}
|
||||
|
||||
int grib_pack_string_array(grib_accessor* a, const char** v, size_t *len )
|
||||
{
|
||||
grib_accessor_class *c = a->cclass;
|
||||
/*grib_context_log(a->parent->h->context, GRIB_LOG_DEBUG, "(%s)%s is packing (string) %s",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?v:"(null)");*/
|
||||
while(c)
|
||||
{
|
||||
|
||||
if(c->pack_string_array)
|
||||
{
|
||||
return c->pack_string_array(a,v,len);
|
||||
}
|
||||
c = c->super ? *(c->super) : NULL;
|
||||
}
|
||||
Assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int grib_pack_long(grib_accessor* a,const long* v, size_t *len )
|
||||
{
|
||||
grib_accessor_class *c = a->cclass;
|
||||
|
|
|
@ -499,7 +499,6 @@ static int encode_string_array(grib_context* c,grib_buffer* buff,long* pos, int
|
|||
grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+6);
|
||||
grib_encode_unsigned_longb(buff->data,width/8,pos,6);
|
||||
if (width) {
|
||||
grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+6);
|
||||
grib_buffer_set_ulength_bits(c,buff,buff->ulength_bits+width*end);
|
||||
for (j=start;j<end;j++) {
|
||||
grib_encode_string(buff->data,pos,width/8,stringValues->v[j]);
|
||||
|
|
|
@ -228,8 +228,6 @@ static int unpack_string_array (grib_accessor* a, char** val, size_t *len)
|
|||
long count=0;
|
||||
grib_context* c=a->parent->h->context;
|
||||
|
||||
if (*len<count) return GRIB_ARRAY_TOO_SMALL;
|
||||
|
||||
if (self->compressedData) {
|
||||
idx=((int)self->numericValues->v[self->index]->v[0]/1000-1)/self->numberOfSubsets;
|
||||
count=grib_sarray_used_size(self->stringValues->v[idx]);
|
||||
|
@ -445,7 +443,8 @@ static int value_count(grib_accessor* a,long* count)
|
|||
type=get_native_type(a);
|
||||
|
||||
if (type==GRIB_TYPE_STRING) {
|
||||
size=grib_sarray_used_size(self->stringValues);
|
||||
idx=((int)self->numericValues->v[self->index]->v[0]/1000-1)/self->numberOfSubsets;
|
||||
size=grib_sarray_used_size(self->stringValues->v[idx]);
|
||||
} else {
|
||||
size=grib_darray_used_size(self->numericValues->v[self->index]);
|
||||
}
|
||||
|
|
|
@ -108,6 +108,7 @@ int grib_is_missing_internal(grib_accessor *a);
|
|||
int grib_pack_double(grib_accessor *a, const double *v, size_t *len);
|
||||
int grib_pack_expression(grib_accessor *a, grib_expression *e);
|
||||
int grib_pack_string(grib_accessor *a, const char *v, size_t *len);
|
||||
int grib_pack_string_array(grib_accessor *a, const char **v, size_t *len);
|
||||
int grib_pack_long(grib_accessor *a, const long *v, size_t *len);
|
||||
int grib_pack_bytes(grib_accessor *a, const unsigned char *v, size_t *len);
|
||||
int grib_unpack_bytes(grib_accessor *a, unsigned char *v, size_t *len);
|
||||
|
@ -288,6 +289,10 @@ bufr_descriptor *accessor_bufr_elements_table_get_descriptor(grib_accessor *a, i
|
|||
|
||||
/* grib_accessor_class_bufr_group.c */
|
||||
|
||||
/* grib_accessor_class_bufr_string_values.c */
|
||||
|
||||
/* grib_accessor_class_pack_bufr_values.c */
|
||||
|
||||
/* grib_accessor_class_group.c */
|
||||
|
||||
/* grib_accessor_class_unpack_bufr_values.c */
|
||||
|
@ -1145,6 +1150,7 @@ int grib_copy_namespace(grib_handle *dest, const char *name, grib_handle *src);
|
|||
int grib_set_double(grib_handle *h, const char *name, double val);
|
||||
int grib_set_string_internal(grib_handle *h, const char *name, const char *val, size_t *length);
|
||||
int grib_set_string(grib_handle *h, const char *name, const char *val, size_t *length);
|
||||
int grib_set_string_array(grib_handle *h, const char *name, const char **val, size_t length);
|
||||
int grib_set_bytes_internal(grib_handle *h, const char *name, const unsigned char *val, size_t *length);
|
||||
int grib_set_bytes(grib_handle *h, const char *name, const unsigned char *val, size_t *length);
|
||||
int grib_clear(grib_handle *h, const char *name);
|
||||
|
|
|
@ -96,6 +96,8 @@ int grib_decode_double_array(const unsigned char* p, long *bitp, long bitsPerVal
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int grib_decode_double_array_complex(const unsigned char* p, long *bitp, long nbits,double reference_value,double s,double* d,size_t size,double* val) {
|
||||
return GRIB_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
|
@ -377,6 +377,29 @@ int grib_set_string(grib_handle* h, const char* name, const char* val, size_t *l
|
|||
return GRIB_NOT_FOUND;
|
||||
}
|
||||
|
||||
int grib_set_string_array(grib_handle* h, const char* name, const char** val, size_t length)
|
||||
{
|
||||
int ret=0;
|
||||
grib_accessor* a;
|
||||
|
||||
a = grib_find_accessor(h, name);
|
||||
|
||||
grib_context_log(h->context,GRIB_LOG_DEBUG,"grib_set_string %s=%s\n",name,val);
|
||||
|
||||
if(a)
|
||||
{
|
||||
if(a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)
|
||||
return GRIB_READ_ONLY;
|
||||
|
||||
ret=grib_pack_string_array(a, val, length);
|
||||
if(ret == GRIB_SUCCESS){
|
||||
return grib_dependency_notify_change(a);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
return GRIB_NOT_FOUND;
|
||||
}
|
||||
|
||||
int grib_set_bytes_internal(grib_handle* h, const char* name, const unsigned char* val, size_t *length)
|
||||
{
|
||||
int ret = GRIB_SUCCESS;
|
||||
|
|
4046
src/grib_yacc.c
4046
src/grib_yacc.c
File diff suppressed because it is too large
Load Diff
|
@ -1,10 +1,8 @@
|
|||
/* A Bison parser, made by GNU Bison 2.7. */
|
||||
|
||||
/* A Bison parser, made by GNU Bison 2.4.1. */
|
||||
|
||||
/* Skeleton interface for Bison's Yacc-like parsers in C
|
||||
/* Bison interface for Yacc-like parsers in C
|
||||
|
||||
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
|
||||
Free Software Foundation, Inc.
|
||||
Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -32,6 +30,15 @@
|
|||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
#ifndef YY_YY_Y_TAB_H_INCLUDED
|
||||
# define YY_YY_Y_TAB_H_INCLUDED
|
||||
/* Enabling traces. */
|
||||
#ifndef YYDEBUG
|
||||
# define YYDEBUG 0
|
||||
#endif
|
||||
#if YYDEBUG
|
||||
extern int grib_yydebug;
|
||||
#endif
|
||||
|
||||
/* Tokens. */
|
||||
#ifndef YYTOKENTYPE
|
||||
|
@ -293,18 +300,17 @@
|
|||
|
||||
|
||||
|
||||
|
||||
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
|
||||
typedef union YYSTYPE
|
||||
{
|
||||
|
||||
/* Line 1676 of yacc.c */
|
||||
/* Line 2058 of yacc.c */
|
||||
#line 37 "griby.y"
|
||||
|
||||
char *str;
|
||||
long lval;
|
||||
double dval;
|
||||
grib_darray *dvalue;
|
||||
grib_sarray *svalue;
|
||||
grib_iarray *ivalue;
|
||||
grib_action *act;
|
||||
grib_arguments *explist;
|
||||
|
@ -317,9 +323,8 @@ typedef union YYSTYPE
|
|||
grib_rule_entry *rule_entry;
|
||||
|
||||
|
||||
|
||||
/* Line 1676 of yacc.c */
|
||||
#line 323 "y.tab.h"
|
||||
/* Line 2058 of yacc.c */
|
||||
#line 328 "y.tab.h"
|
||||
} YYSTYPE;
|
||||
# define YYSTYPE_IS_TRIVIAL 1
|
||||
# define grib_yystype YYSTYPE /* obsolescent; will be withdrawn */
|
||||
|
@ -328,4 +333,18 @@ typedef union YYSTYPE
|
|||
|
||||
extern YYSTYPE grib_yylval;
|
||||
|
||||
#ifdef YYPARSE_PARAM
|
||||
#if defined __STDC__ || defined __cplusplus
|
||||
int grib_yyparse (void *YYPARSE_PARAM);
|
||||
#else
|
||||
int grib_yyparse ();
|
||||
#endif
|
||||
#else /* ! YYPARSE_PARAM */
|
||||
#if defined __STDC__ || defined __cplusplus
|
||||
int grib_yyparse (void);
|
||||
#else
|
||||
int grib_yyparse ();
|
||||
#endif
|
||||
#endif /* ! YYPARSE_PARAM */
|
||||
|
||||
#endif /* !YY_YY_Y_TAB_H_INCLUDED */
|
||||
|
|
|
@ -39,6 +39,7 @@ static grib_hash_array_value *_reverse_hash_array(grib_hash_array_value *r,grib_
|
|||
long lval;
|
||||
double dval;
|
||||
grib_darray *dvalue;
|
||||
grib_sarray *svalue;
|
||||
grib_iarray *ivalue;
|
||||
grib_action *act;
|
||||
grib_arguments *explist;
|
||||
|
@ -196,6 +197,7 @@ static grib_hash_array_value *_reverse_hash_array(grib_hash_array_value *r,grib_
|
|||
%token <dval>FLOAT
|
||||
|
||||
%type <dvalue> dvalues
|
||||
%type <svalue> svalues
|
||||
%type <ivalue> integer_array
|
||||
|
||||
%type <act> instructions
|
||||
|
@ -275,6 +277,11 @@ dvalues : FLOAT { $$=grib_darray_push(0,0,$1);}
|
|||
| dvalues ',' INTEGER { $$=grib_darray_push(0,$1,$3);}
|
||||
;
|
||||
|
||||
svalues : STRING { $$=grib_sarray_push(0,0,$1);}
|
||||
| svalues ',' STRING { $$=grib_sarray_push(0,$1,$3);}
|
||||
;
|
||||
|
||||
|
||||
integer_array : INTEGER { $$=grib_iarray_push(0,$1);}
|
||||
| integer_array ',' INTEGER { $$=grib_iarray_push($1,$3);}
|
||||
;
|
||||
|
@ -598,6 +605,7 @@ simple : UNSIGNED '[' INTEGER ']' IDENT default flags
|
|||
| SET IDENT '=' MISSING { $$ = grib_action_create_set_missing(grib_parser_context,$2); free($2); }
|
||||
| SET IDENT '=' expression { $$ = grib_action_create_set(grib_parser_context,$2,$4,0); free($2); }
|
||||
| SET IDENT '=' '{' dvalues '}' { $$ = grib_action_create_set_darray(grib_parser_context,$2,$5); free($2); }
|
||||
| SET IDENT '=' '{' svalues '}' { $$ = grib_action_create_set_sarray(grib_parser_context,$2,$5); free($2); }
|
||||
|
||||
| SET_NOFAIL IDENT '=' expression { $$ = grib_action_create_set(grib_parser_context,$2,$4,1); free($2); }
|
||||
|
||||
|
|
Loading…
Reference in New Issue