Refactoring

This commit is contained in:
Shahram Najm 2019-09-25 14:35:43 +01:00
parent e79a19c741
commit 9fd0f613d3
14 changed files with 174 additions and 174 deletions

View File

@ -101,7 +101,6 @@ static int create_accessor(grib_section* p, grib_action* act,grib_loader *h)
grib_push_accessor(as,p->block);
return GRIB_SUCCESS;
}
@ -123,7 +122,8 @@ static void destroy(grib_context* context,grib_action* act)
grib_context_free_persistent(context, act->op);
}
static int execute(grib_action* a,grib_handle* h) {
static int execute(grib_action* a,grib_handle* h)
{
int ret=0;
double res=0;
grib_action_assert* self= (grib_action_assert*)a;
@ -131,8 +131,9 @@ static int execute(grib_action* a,grib_handle* h) {
if ((ret=grib_expression_evaluate_double(h,self->expression,&res)) != GRIB_SUCCESS)
return ret;
if (res != 0)
if (res != 0) {
return GRIB_SUCCESS;
}
else {
grib_context_log(h->context,GRIB_LOG_ERROR,"Assertion failure: ");
grib_expression_print(h->context,self->expression,h);
@ -151,7 +152,6 @@ static int notify_change(grib_action* a, grib_accessor* observer,grib_accessor*
if ((ret = grib_expression_evaluate_long(grib_handle_of_accessor(observed), self->expression,&lres))
!= GRIB_SUCCESS) return ret;
if (lres != 0)
return GRIB_SUCCESS;
else

View File

@ -111,12 +111,10 @@ static int execute(grib_action* act, grib_handle *h)
return err;
}
static void dump(grib_action* act, FILE* f, int lvl)
{
}
static void destroy(grib_context* context,grib_action* act)
{
grib_action_close* a = (grib_action_close*) act;
@ -124,5 +122,4 @@ static void destroy(grib_context* context,grib_action* act)
grib_context_free_persistent(context, a->filename);
grib_context_free_persistent(context, act->name);
grib_context_free_persistent(context, act->op);
}

View File

@ -199,11 +199,8 @@ void encode_double_array_unrolled(int numBits, long packStart, long datasize,
{
U_BYTEORDER;
long i, j, z = *gz;
#ifdef _ARCH_PWR6
#define __UNROLL_DEPTH_2 8
#else
#define __UNROLL_DEPTH_2 8
#endif
data += packStart;
datasize -= packStart;

View File

@ -131,14 +131,15 @@ static void init(grib_accessor* a, const long len , grib_arguments* arg )
{
grib_get_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, arg, 0), &a->length);
Assert(a->length>=0);
}
static int get_native_type(grib_accessor* a){
static int get_native_type(grib_accessor* a)
{
return GRIB_TYPE_BYTES;
}
static int unpack_bytes (grib_accessor* a,unsigned char* buffer, size_t *len) {
static int unpack_bytes (grib_accessor* a,unsigned char* buffer, size_t *len)
{
if (*len < a->length) {
*len = a->length;
return GRIB_ARRAY_TOO_SMALL;

View File

@ -183,7 +183,7 @@ static int build_long_array(grib_context* c, grib_handle* h, int compressed,
long** array, const char* key, long numberOfSubsets, int zero_on_error)
{
int err = 0;
size_t i;
long i;
size_t n=numberOfSubsets;
*array=(long*)grib_context_malloc_clear(c, sizeof(long)*numberOfSubsets);
if(compressed) {

View File

@ -132,15 +132,15 @@ static void init(grib_accessor* a, const long len , grib_arguments* arg )
/*grib_accessor_signed* self = (grib_accessor_signed*)a; */
a->length = len;
Assert(a->length>=0);
}
static int get_native_type(grib_accessor* a){
static int get_native_type(grib_accessor* a)
{
return GRIB_TYPE_BYTES;
}
static int compare(grib_accessor* a, grib_accessor* b) {
static int compare(grib_accessor* a, grib_accessor* b)
{
int retval=GRIB_SUCCESS;
size_t alen = (size_t)grib_byte_count(a);
@ -151,7 +151,8 @@ static int compare(grib_accessor* a, grib_accessor* b) {
return retval;
}
static int unpack_string(grib_accessor *a , char* v, size_t *len){
static int unpack_string(grib_accessor *a , char* v, size_t *len)
{
unsigned char* p=NULL;
char* s=v;
int i;

View File

@ -331,7 +331,7 @@ static int _unpack_double(grib_accessor* a, double* val, size_t *len,unsigned c
GRIB_SUCCESS)
return err;
/*/
/*
* check we don't decode bpv > max(ulong) as it is
* not currently supported by the algorithm
*/
@ -557,7 +557,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t *len)
if((err = grib_get_long_internal(gh,self->optimize_scaling_factor, &optimize_scaling_factor))
!= GRIB_SUCCESS)
return err;
/*/
/*
* check we don't encode bpv > max(ulong)-1 as it is
* not currently supported by the algorithm
*/

View File

@ -129,8 +129,6 @@ static void init_class(grib_accessor_class* c)
/* END_CLASS_IMP */
static int get_native_type(grib_accessor* a)
{
return GRIB_TYPE_LONG;
@ -216,8 +214,7 @@ static int unpack_double(grib_accessor* a, double* val,size_t *len)
if (ret) return ret;
rlen=count;
if(*len < rlen)
{
if(*len < rlen) {
grib_context_log(a->context, GRIB_LOG_ERROR, " wrong size for %s it contains %d values ", a->name , rlen);
*len = 0;
return GRIB_ARRAY_TOO_SMALL;
@ -234,7 +231,6 @@ static int unpack_double(grib_accessor* a, double* val,size_t *len)
values = (long*)grib_context_malloc(a->context,rlen*sizeof(long));
if(!values) return GRIB_INTERNAL_ERROR;
ret = grib_unpack_long(a,values,&rlen);
if(ret != GRIB_SUCCESS){
grib_context_free(a->context,values);

View File

@ -205,7 +205,7 @@ static void dump_values(grib_dumper* d,grib_accessor* a)
depth-=2;
/* Note: In Python to make a tuple with one element, you need the trailing comma */
if (size > 4) fprintf(self->dumper.out,",) # %ld values\n", size);
if (size > 4) fprintf(self->dumper.out,",) # %lu values\n", (unsigned long)size);
else fprintf(self->dumper.out,",)\n");
grib_context_free(c,values);
@ -287,7 +287,7 @@ static void dump_values_attribute(grib_dumper* d,grib_accessor* a, const char* p
depth-=2;
/* Note: In python to make a tuple with one element, you need the trailing comma */
if (size > 4) fprintf(self->dumper.out,",) # %ld values\n", size);
if (size > 4) fprintf(self->dumper.out,",) # %lu values\n", (unsigned long)size);
else fprintf(self->dumper.out,",)\n");
grib_context_free(c,values);
@ -374,7 +374,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment)
depth-=2;
/* Note: In python to make a tuple with one element, you need the trailing comma */
if (size > 4) fprintf(self->dumper.out,",) # %ld values\n", size);
if (size > 4) fprintf(self->dumper.out,",) # %lu values\n", (unsigned long)size);
else fprintf(self->dumper.out,",)\n");
grib_context_free(a->context,values);
@ -462,7 +462,7 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr
depth-=2;
/* Note: In python to make a tuple with one element, you need the trailing comma */
if (size > 4) fprintf(self->dumper.out,",) # %ld values\n", size);
if (size > 4) fprintf(self->dumper.out,",) # %lu values\n", (unsigned long)size);
else fprintf(self->dumper.out,",)\n");
grib_context_free(a->context,values);
@ -697,7 +697,7 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha
}
if (icount>cols) {fprintf(f," \n ");}
/* Note: In python to make a tuple with one element, you need the trailing comma */
if (size > 4) fprintf(f,"%ld ,) # %ld values\n",val[size-1], size);
if (size > 4) fprintf(f,"%ld ,) # %lu values\n",val[size-1], (unsigned long)size);
else fprintf(f,"%ld ,)\n",val[size-1]);
grib_context_free(h->context,val);

View File

@ -494,7 +494,9 @@ static int read_HDF5_offset(reader *r, int length, unsigned long* v, unsigned ch
static int read_HDF5(reader *r)
{
/* See: http://www.hdfgroup.org/HDF5/doc/H5.format.html#Superblock */
/*
* See: http://www.hdfgroup.org/HDF5/doc/H5.format.html#Superblock
*/
unsigned char tmp[49]; /* Should be enough */
unsigned char buf[4];
@ -629,7 +631,9 @@ static int read_HDF5(reader *r)
static int read_WRAP(reader *r)
{
/* See: http://www.hdfgroup.org/HDF5/doc/H5.format.html#Superblock */
/*
* See: http://www.hdfgroup.org/HDF5/doc/H5.format.html#Superblock
*/
unsigned char tmp[36]; /* Should be enough */
unsigned char buf[8];

View File

@ -177,7 +177,9 @@ static int init(grib_iterator* iter, grib_handle* h, grib_arguments* args)
if((err = grib_get_long_internal(h, salternativeRowScanning,&alternativeRowScanning)) !=GRIB_SUCCESS)
return err;
/* See Wolfram MathWorld: http://mathworld.wolfram.com/LambertConformalConicProjection.html */
/*
* See Wolfram MathWorld: http://mathworld.wolfram.com/LambertConformalConicProjection.html
*/
latFirstInRadians = latFirstInDegrees * DEG2RAD;
lonFirstInRadians = lonFirstInDegrees * DEG2RAD;
Latin1InRadians = Latin1InDegrees * DEG2RAD;

View File

@ -211,7 +211,9 @@ cleanup:
/* OpenJPEG 2.1 version of grib_openjpeg_encoding.c */
/* opj_* Helper code from https://groups.google.com/forum/#!topic/openjpeg/8cebr0u7JgY */
/* opj_* Helper code from
* https://groups.google.com/forum/#!topic/openjpeg/8cebr0u7JgY
*/
/* These routines are added to use memory instead of a file for input and output */
/* struct need to treat memory as a stream */
typedef struct