diff --git a/src/grib_darray.c b/src/grib_darray.c index 5dfe35f60..21f09023d 100644 --- a/src/grib_darray.c +++ b/src/grib_darray.c @@ -30,91 +30,91 @@ void grib_darray_print(const char* title, const grib_darray* darray) grib_darray* grib_darray_new_from_array(grib_context* c,double* a,size_t size) { - size_t i; - grib_darray* v; + size_t i; + grib_darray* v; - if (!c) c=grib_context_get_default(); + if (!c) c=grib_context_get_default(); - v=grib_darray_new(c,size,100); - for (i=0;iv[i]=a[i]; - v->n=size; - v->context=c; - return v; + v=grib_darray_new(c,size,100); + for (i=0;iv[i]=a[i]; + v->n=size; + v->context=c; + return v; } grib_darray* grib_darray_new(grib_context* c,size_t size,size_t incsize) { - grib_darray* v=NULL; - if (!c) c=grib_context_get_default(); - v=(grib_darray*)grib_context_malloc_clear(c,sizeof(grib_darray)); - if (!v) { - grib_context_log(c,GRIB_LOG_ERROR, - "grib_darray_new unable to allocate %d bytes\n",sizeof(grib_darray)); - return NULL; - } - v->size=size; - v->n=0; - v->incsize=incsize; - v->v=(double*)grib_context_malloc_clear(c,sizeof(double)*size); - if (!v->v) { - grib_context_log(c,GRIB_LOG_ERROR, - "grib_darray_new unable to allocate %d bytes\n",sizeof(double)*size); - return NULL; - } - return v; + grib_darray* v=NULL; + if (!c) c=grib_context_get_default(); + v=(grib_darray*)grib_context_malloc_clear(c,sizeof(grib_darray)); + if (!v) { + grib_context_log(c,GRIB_LOG_ERROR, + "grib_darray_new unable to allocate %d bytes\n",sizeof(grib_darray)); + return NULL; + } + v->size=size; + v->n=0; + v->incsize=incsize; + v->v=(double*)grib_context_malloc_clear(c,sizeof(double)*size); + if (!v->v) { + grib_context_log(c,GRIB_LOG_ERROR, + "grib_darray_new unable to allocate %d bytes\n",sizeof(double)*size); + return NULL; + } + return v; } grib_darray* grib_darray_resize(grib_context* c,grib_darray* v) { - int newsize=v->incsize+v->size; + int newsize=v->incsize+v->size; - if (!c) c=grib_context_get_default(); + if (!c) c=grib_context_get_default(); - v->v = (double*)grib_context_realloc(c,v->v,newsize*sizeof(double)); - v->size=newsize; - if (!v->v) { - grib_context_log(c,GRIB_LOG_ERROR, - "grib_darray_resize unable to allocate %d bytes\n",sizeof(double)*newsize); - return NULL; - } - return v; + v->v = (double*)grib_context_realloc(c,v->v,newsize*sizeof(double)); + v->size=newsize; + if (!v->v) { + grib_context_log(c,GRIB_LOG_ERROR, + "grib_darray_resize unable to allocate %d bytes\n",sizeof(double)*newsize); + return NULL; + } + return v; } grib_darray* grib_darray_push(grib_context* c,grib_darray* v,double val) { - size_t start_size=100; - size_t start_incsize=100; - if (!v) v=grib_darray_new(c,start_size,start_incsize); + size_t start_size=100; + size_t start_incsize=100; + if (!v) v=grib_darray_new(c,start_size,start_incsize); - if (v->n >= v->size) v=grib_darray_resize(c,v); - v->v[v->n]=val; - v->n++; - return v; + if (v->n >= v->size) v=grib_darray_resize(c,v); + v->v[v->n]=val; + v->n++; + return v; } void grib_darray_delete(grib_context* c,grib_darray* v) { - if (!v) return; - if (!c) grib_context_get_default(); - if (v->v) grib_context_free(c,v->v); - grib_context_free(c,v); + if (!v) return; + if (!c) grib_context_get_default(); + if (v->v) grib_context_free(c,v->v); + grib_context_free(c,v); } double* grib_darray_get_array(grib_context* c,grib_darray* v) { - double* ret; - int i; - if (!v) return NULL; - ret=(double*)grib_context_malloc_clear(c,sizeof(double)*v->n); - for (i=0;in;i++) ret[i]=v->v[i]; - return ret; + double* ret; + int i; + if (!v) return NULL; + ret=(double*)grib_context_malloc_clear(c,sizeof(double)*v->n); + for (i=0;in;i++) ret[i]=v->v[i]; + return ret; } int grib_darray_is_constant(grib_darray* v,double eps) { - int i; - double val; - if (v->n == 1) return 1; + int i; + double val; + if (v->n == 1) return 1; - val=v->v[0]; - for (i=1;in;i++) { - if (fabs(val-v->v[i]) > eps) return 0; - } - return 1; + val=v->v[0]; + for (i=1;in;i++) { + if (fabs(val-v->v[i]) > eps) return 0; + } + return 1; } size_t grib_darray_used_size(grib_darray* v) { return v->n;} diff --git a/src/grib_iarray.c b/src/grib_iarray.c index 4e4e38b3c..09f798f09 100644 --- a/src/grib_iarray.c +++ b/src/grib_iarray.c @@ -227,14 +227,13 @@ long* grib_iarray_get_array(grib_iarray* v) size_t grib_iarray_used_size(grib_iarray* v) {return v==NULL ? 0 : v->n;} int grib_iarray_is_constant(grib_iarray* v) { - int i; - long val; - if (v->n == 1) return 1; + int i; + long val; + if (v->n == 1) return 1; - val=v->v[0]; - for (i=1;in;i++) { - if (val!=v->v[i]) return 0; - } - return 1; + val=v->v[0]; + for (i=1;in;i++) { + if (val!=v->v[i]) return 0; + } + return 1; } -