Indentation

This commit is contained in:
Shahram Najm 2019-08-06 16:46:12 +01:00
parent 9cfdcf506e
commit 4a725d1ee9
4 changed files with 251 additions and 252 deletions

View File

@ -79,14 +79,14 @@ static void init_class(grib_action_class* c)
/* new GCC compiler v4.5.0 complains function is defined but not used*/ /* new GCC compiler v4.5.0 complains function is defined but not used*/
static void check_sections(grib_section *s,grib_handle* h) static void check_sections(grib_section *s,grib_handle* h)
{ {
grib_accessor *a = s?s->block->first:NULL; grib_accessor *a = s?s->block->first:NULL;
if(s) Assert(s->h == h); if(s) Assert(s->h == h);
while(a) while(a)
{ {
Assert(grib_handle_of_accessor(a) == h); Assert(grib_handle_of_accessor(a) == h);
check_sections(a->sub_section,h); check_sections(a->sub_section,h);
a = a->next; a = a->next;
} }
} }
#endif #endif

View File

@ -137,156 +137,159 @@ static void init_class(grib_accessor_class* c)
static void init(grib_accessor* a, const long len , grib_arguments* arg ) static void init(grib_accessor* a, const long len , grib_arguments* arg )
{ {
a->length = len; a->length = len;
Assert(a->length>=0); Assert(a->length>=0);
} }
static int value_count(grib_accessor* a,long* count){ static int value_count(grib_accessor* a,long* count)
*count=1; {
return 0; *count=1;
return 0;
} }
static size_t string_length(grib_accessor* a){ static size_t string_length(grib_accessor* a)
return a->length; {
return a->length;
} }
static void dump(grib_accessor* a, grib_dumper* dumper) static void dump(grib_accessor* a, grib_dumper* dumper)
{ {
grib_dump_string(dumper,a,NULL); grib_dump_string(dumper,a,NULL);
} }
static int get_native_type(grib_accessor* a){ static int get_native_type(grib_accessor* a)
return GRIB_TYPE_STRING; {
return GRIB_TYPE_STRING;
} }
static int unpack_string(grib_accessor* a, char* val, size_t *len) static int unpack_string(grib_accessor* a, char* val, size_t *len)
{ {
int i = 0; int i = 0;
grib_handle* hand = grib_handle_of_accessor(a); grib_handle* hand = grib_handle_of_accessor(a);
if(len[0] < (a->length+1)) if(len[0] < (a->length+1))
{ {
grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%d) for %s it contains %d values ", len[0], a->name , a->length+1 ); grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%d) for %s it contains %d values ", len[0], a->name , a->length+1 );
len[0] = 0; len[0] = 0;
return GRIB_ARRAY_TOO_SMALL; return GRIB_ARRAY_TOO_SMALL;
} }
for ( i = 0; i < a->length; i++) for ( i = 0; i < a->length; i++)
val[i] = hand->buffer->data[a->offset+i]; val[i] = hand->buffer->data[a->offset+i];
val[i] = 0; val[i] = 0;
len[0] = i; len[0] = i;
return GRIB_SUCCESS; return GRIB_SUCCESS;
} }
static int pack_string(grib_accessor* a, const char* val, size_t *len) static int pack_string(grib_accessor* a, const char* val, size_t *len)
{ {
int i = 0; int i = 0;
grib_handle* hand = grib_handle_of_accessor(a); grib_handle* hand = grib_handle_of_accessor(a);
if(len[0] > (a->length)+1) if(len[0] > (a->length)+1)
{ {
grib_context_log(a->context, GRIB_LOG_ERROR, "pack_string: Wrong size (%d) for %s it contains %d values ", len[0], a->name , a->length+1 ); grib_context_log(a->context, GRIB_LOG_ERROR, "pack_string: Wrong size (%d) for %s it contains %d values ", len[0], a->name , a->length+1 );
len[0] = 0; len[0] = 0;
return GRIB_BUFFER_TOO_SMALL; return GRIB_BUFFER_TOO_SMALL;
} }
for ( i = 0; i < a->length; i++) for ( i = 0; i < a->length; i++)
{ {
if( i < len[0] ) if( i < len[0] )
hand->buffer->data[a->offset+i] = val[i]; hand->buffer->data[a->offset+i] = val[i];
else else
hand->buffer->data[a->offset+i] = 0; hand->buffer->data[a->offset+i] = 0;
} }
return GRIB_SUCCESS; return GRIB_SUCCESS;
} }
static int pack_long(grib_accessor* a, const long* v, size_t *len){ static int pack_long(grib_accessor* a, const long* v, size_t *len)
grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as long", a->name); {
return GRIB_NOT_IMPLEMENTED; grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as long", a->name);
return GRIB_NOT_IMPLEMENTED;
} }
static int pack_double(grib_accessor* a, const double*v, size_t *len){ static int pack_double(grib_accessor* a, const double*v, size_t *len)
grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as double", a->name); {
return GRIB_NOT_IMPLEMENTED; grib_context_log(a->context,GRIB_LOG_ERROR, " Should not pack %s as double", a->name);
return GRIB_NOT_IMPLEMENTED;
} }
static int unpack_long (grib_accessor* a, long* v, size_t *len)
{
char val[1024]={0,};
size_t l = sizeof(val);
size_t i =0;
char *last = NULL;
int err=grib_unpack_string (a , val, &l);
static int unpack_long (grib_accessor* a, long* v, size_t *len){ if (err) return err;
char val[1024]={0,}; i=0;
size_t l = sizeof(val); while ( val[i]==' ' && val[i]!=0 && i<l-1) i++;
size_t i =0;
char *last = NULL;
int err=grib_unpack_string (a , val, &l);
if (err) return err; if (val[i]==0) {
*v=0;
return 0;
}
if (val[i+1]==' ' && i<l-2) val[i+1]=0;
i=0; *v = strtol(val,&last,10);
while ( val[i]==' ' && val[i]!=0 && i<l-1) i++;
if (val[i]==0) {
*v=0;
return 0;
}
if (val[i+1]==' ' && i<l-2) val[i+1]=0;
*v = strtol(val,&last,10);
grib_context_log(a->context,GRIB_LOG_DEBUG, " Casting string %s to long", a->name);
return GRIB_SUCCESS;
}
static int unpack_double (grib_accessor* a, double*v, size_t *len){
char val[1024];
size_t l = sizeof(val);
char *last = NULL;
grib_unpack_string (a , val, &l);
*v = strtod(val,&last);
if(*last == 0)
{
grib_context_log(a->context,GRIB_LOG_DEBUG, " Casting string %s to long", a->name); grib_context_log(a->context,GRIB_LOG_DEBUG, " Casting string %s to long", a->name);
return GRIB_SUCCESS; return GRIB_SUCCESS;
}
return GRIB_NOT_IMPLEMENTED;
} }
static int unpack_double (grib_accessor* a, double*v, size_t *len)
{
char val[1024];
size_t l = sizeof(val);
char *last = NULL;
grib_unpack_string (a , val, &l);
static int compare(grib_accessor* a,grib_accessor* b) { *v = strtod(val,&last);
int retval=0;
char *aval=0;
char *bval=0;
int err=0;
size_t alen = 0; if(*last == 0)
size_t blen = 0; {
long count=0; grib_context_log(a->context,GRIB_LOG_DEBUG, " Casting string %s to long", a->name);
return GRIB_SUCCESS;
}
err=grib_value_count(a,&count); return GRIB_NOT_IMPLEMENTED;
if (err) return err;
alen=count;
err=grib_value_count(b,&count);
if (err) return err;
blen=count;
if (alen != blen) return GRIB_COUNT_MISMATCH;
aval=(char*)grib_context_malloc(a->context,alen*sizeof(char));
bval=(char*)grib_context_malloc(b->context,blen*sizeof(char));
grib_unpack_string(a,aval,&alen);
grib_unpack_string(b,bval,&blen);
retval = GRIB_SUCCESS;
if (strcmp(aval,bval)) retval = GRIB_STRING_VALUE_MISMATCH;
grib_context_free(a->context,aval);
grib_context_free(b->context,bval);
return retval;
} }
static int compare(grib_accessor* a,grib_accessor* b)
{
int retval=0;
char *aval=0;
char *bval=0;
int err=0;
size_t alen = 0;
size_t blen = 0;
long count=0;
err=grib_value_count(a,&count);
if (err) return err;
alen=count;
err=grib_value_count(b,&count);
if (err) return err;
blen=count;
if (alen != blen) return GRIB_COUNT_MISMATCH;
aval=(char*)grib_context_malloc(a->context,alen*sizeof(char));
bval=(char*)grib_context_malloc(b->context,blen*sizeof(char));
grib_unpack_string(a,aval,&alen);
grib_unpack_string(b,bval,&blen);
retval = GRIB_SUCCESS;
if (strcmp(aval,bval)) retval = GRIB_STRING_VALUE_MISMATCH;
grib_context_free(a->context,aval);
grib_context_free(b->context,bval);
return retval;
}

View File

@ -137,114 +137,115 @@ static void init_class(grib_accessor_class* c)
static void init(grib_accessor* a,const long l, grib_arguments* c) static void init(grib_accessor* a,const long l, grib_arguments* c)
{ {
grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a; grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a;
int n = 0; int n = 0;
self->verifyingMonth = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++); self->verifyingMonth = grib_arguments_get_name(grib_handle_of_accessor(a),c,n++);
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN;
self->number_of_elements=6; self->number_of_elements=6;
self->v=(double*)grib_context_malloc(a->context, self->v=(double*)grib_context_malloc(a->context,
sizeof(double)*self->number_of_elements); sizeof(double)*self->number_of_elements);
a->length=0; a->length=0;
a->dirty=1; a->dirty=1;
} }
static int unpack_double (grib_accessor* a, double* val, size_t *len) static int unpack_double (grib_accessor* a, double* val, size_t *len)
{ {
grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a; grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a;
int ret = 0; int ret = 0;
char verifyingMonth[7]={0,}; char verifyingMonth[7]={0,};
size_t slen=7; size_t slen=7;
long year=0,month=0,date=0; long year=0,month=0,date=0;
long mdays[]={31,28,31,30,31,30,31,31,30,31,30,31}; long mdays[]={31,28,31,30,31,30,31,31,30,31,30,31};
long days=0; long days=0;
if (!a->dirty) return GRIB_SUCCESS; if (!a->dirty) return GRIB_SUCCESS;
if((ret=grib_get_string(grib_handle_of_accessor(a),self->verifyingMonth,verifyingMonth,&slen)) if((ret=grib_get_string(grib_handle_of_accessor(a),self->verifyingMonth,verifyingMonth,&slen))
!= GRIB_SUCCESS) return ret; != GRIB_SUCCESS) return ret;
date=atoi(verifyingMonth); date=atoi(verifyingMonth);
year=date/100; year=date/100;
month=date-year*100; month=date-year*100;
if ( month == 2 ) { if ( month == 2 ) {
days=28; days=28;
if (year%400 == 0 || ( year%4 == 0 && year%100 != 0) ) days=29; if (year%400 == 0 || ( year%4 == 0 && year%100 != 0) ) days=29;
} else days=mdays[month-1]; } else days=mdays[month-1];
self->v[0]=year; self->v[0]=year;
self->v[1]=month; self->v[1]=month;
self->v[2]=days;
self->v[3]=24;
self->v[4]=00;
self->v[5]=00;
a->dirty=0; self->v[2]=days;
self->v[3]=24;
self->v[4]=00;
self->v[5]=00;
val[0]=self->v[0]; a->dirty=0;
val[1]=self->v[1];
val[2]=self->v[2];
val[3]=self->v[3];
val[4]=self->v[4];
val[5]=self->v[5];
return ret; val[0]=self->v[0];
val[1]=self->v[1];
val[2]=self->v[2];
val[3]=self->v[3];
val[4]=self->v[4];
val[5]=self->v[5];
return ret;
} }
static int value_count(grib_accessor* a,long *count) static int value_count(grib_accessor* a,long *count)
{ {
grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a; grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a;
*count=self->number_of_elements; *count=self->number_of_elements;
return 0; return 0;
} }
static void destroy(grib_context* c,grib_accessor* a) static void destroy(grib_context* c,grib_accessor* a)
{ {
grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a; grib_accessor_g1end_of_interval_monthly* self = (grib_accessor_g1end_of_interval_monthly*)a;
grib_context_free(c,self->v); grib_context_free(c,self->v);
} }
static int compare(grib_accessor* a, grib_accessor* b) { static int compare(grib_accessor* a, grib_accessor* b)
int retval = GRIB_SUCCESS; {
double *aval=0; int retval = GRIB_SUCCESS;
double *bval=0; double *aval=0;
double *bval=0;
long count=0; long count=0;
size_t alen = 0; size_t alen = 0;
size_t blen = 0; size_t blen = 0;
int err=0; int err=0;
err=grib_value_count(a,&count); err=grib_value_count(a,&count);
if (err) return err; if (err) return err;
alen=count; alen=count;
err=grib_value_count(b,&count); err=grib_value_count(b,&count);
if (err) return err; if (err) return err;
blen=count; blen=count;
if (alen != blen) return GRIB_COUNT_MISMATCH; if (alen != blen) return GRIB_COUNT_MISMATCH;
aval=(double*)grib_context_malloc(a->context,alen*sizeof(double)); aval=(double*)grib_context_malloc(a->context,alen*sizeof(double));
bval=(double*)grib_context_malloc(b->context,blen*sizeof(double)); bval=(double*)grib_context_malloc(b->context,blen*sizeof(double));
b->dirty=1; b->dirty=1;
a->dirty=1; a->dirty=1;
grib_unpack_double(a,aval,&alen); grib_unpack_double(a,aval,&alen);
grib_unpack_double(b,bval,&blen); grib_unpack_double(b,bval,&blen);
while (alen != 0) { while (alen != 0) {
if (*bval != *aval) retval = GRIB_DOUBLE_VALUE_MISMATCH; if (*bval != *aval) retval = GRIB_DOUBLE_VALUE_MISMATCH;
alen--; alen--;
} }
grib_context_free(a->context,aval); grib_context_free(a->context,aval);
grib_context_free(b->context,bval); grib_context_free(b->context,bval);
return retval; return retval;
} }

View File

@ -132,96 +132,91 @@ static void init_class(grib_accessor_class* c)
/* END_CLASS_IMP */ /* END_CLASS_IMP */
static void init(grib_accessor* a, const long len , grib_arguments* arg ) static void init(grib_accessor* a, const long len , grib_arguments* arg )
{ {
a->sub_section = grib_section_create(grib_handle_of_accessor(a),a); a->sub_section = grib_section_create(grib_handle_of_accessor(a),a);
a->length = 0; a->length = 0;
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
} }
static void dump(grib_accessor* a, grib_dumper* dumper) static void dump(grib_accessor* a, grib_dumper* dumper)
{ {
grib_dump_section(dumper,a,a->sub_section->block); grib_dump_section(dumper,a,a->sub_section->block);
} }
static long byte_count(grib_accessor* a) static long byte_count(grib_accessor* a)
{ {
if( !a->length || grib_handle_of_accessor(a)->loader ) if( !a->length || grib_handle_of_accessor(a)->loader )
{ {
if(a->name[1]=='_') return 0; if(a->name[1]=='_') return 0;
/* printf("adjusting sizes SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); */ /* printf("adjusting sizes SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); */
grib_section_adjust_sizes(a->sub_section,grib_handle_of_accessor(a)->loader != NULL,0); grib_section_adjust_sizes(a->sub_section,grib_handle_of_accessor(a)->loader != NULL,0);
/* printf(" SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); */ /* printf(" SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); */
} }
/* printf("SECTION %s is %ld %d\n",a->name,a->length,a->sub_section->aclength != NULL); */
/* printf("SECTION %s is %ld %d\n",a->name,a->length,a->sub_section->aclength != NULL); */ return a->length;
return a->length;
} }
static long next_offset(grib_accessor* a) static long next_offset(grib_accessor* a)
{ {
return a->offset + byte_count(a); return a->offset + byte_count(a);
} }
static void destroy(grib_context* ct, grib_accessor* a) static void destroy(grib_context* ct, grib_accessor* a)
{ {
grib_section_delete(ct,a->sub_section); grib_section_delete(ct,a->sub_section);
} }
static int get_native_type(grib_accessor* a){ static int get_native_type(grib_accessor* a)
return GRIB_TYPE_SECTION; {
return GRIB_TYPE_SECTION;
} }
static grib_section* sub_section(grib_accessor* a){ static grib_section* sub_section(grib_accessor* a)
/* grib_accessor_section* self = (grib_accessor_section*)a; */ {
return a->sub_section; /* grib_accessor_section* self = (grib_accessor_section*)a; */
return a->sub_section;
} }
static void update_size(grib_accessor* a,size_t length) static void update_size(grib_accessor* a,size_t length)
{ {
size_t size = 1;
long len = length;
Assert(length <= 0x7fffffff);
if(a->sub_section->aclength)
{
int e=grib_pack_long(a->sub_section->aclength,&len,&size);
Assert( e == GRIB_SUCCESS);
printf("update_length %s %ld %ld\n",a->sub_section->aclength->name,
(long)a->sub_section->aclength->offset,
(long)a->sub_section->aclength->length
size_t size = 1; );
long len = length; }
Assert(length <= 0x7fffffff);
if(a->sub_section->aclength)
{
int e=grib_pack_long(a->sub_section->aclength,&len,&size);
Assert( e == GRIB_SUCCESS);
printf("update_length %s %ld %ld\n",a->sub_section->aclength->name,
(long)a->sub_section->aclength->offset,
(long)a->sub_section->aclength->length
); a->sub_section->length = a->length = length;
} a->sub_section->padding = 0;
a->sub_section->length = a->length = length; printf("update_size %s %ld\n",a->name,a->length);
a->sub_section->padding = 0;
printf("update_size %s %ld\n",a->name,a->length); Assert(a->length>=0);
Assert(a->length>=0);
} }
static grib_accessor* next(grib_accessor* a,int explore) { static grib_accessor* next(grib_accessor* a,int explore)
grib_accessor* next=NULL; {
if (explore) { grib_accessor* next=NULL;
next=a->sub_section->block->first; if (explore) {
if (!next) next=a->next; next=a->sub_section->block->first;
} else { if (!next) next=a->next;
next=a->next; } else {
} next=a->next;
if (!next) { }
if (a->parent->owner) if (!next) {
next=a->parent->owner->cclass->next(a->parent->owner,0); if (a->parent->owner)
} next=a->parent->owner->cclass->next(a->parent->owner,0);
return next; }
return next;
} }