Dead code removal

This commit is contained in:
Shahram Najm 2023-06-24 12:49:25 +01:00
parent 1f392203d5
commit 413d7da794
6 changed files with 318 additions and 340 deletions

View File

@ -271,13 +271,11 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
return ret; return ret;
} }
#if 0 // if(!grib_find_accessor(grib_handle_of_accessor(a),self->bitmap)){
if(!grib_find_accessor(grib_handle_of_accessor(a),self->bitmap)){ // grib_context_log(a->context, GRIB_LOG_ERROR,
grib_context_log(a->context, GRIB_LOG_ERROR, // "Accessor %s cannot access bitmap \n", a->name, self->bitmap_present, ret);
"Accessor %s cannot access bitmap \n", a->name, self->bitmap_present, ret); // return ret;
return ret; // }
}
#endif
ret = grib_set_double_array_internal(grib_handle_of_accessor(a), self->coded_values, val, *len); ret = grib_set_double_array_internal(grib_handle_of_accessor(a), self->coded_values, val, *len);
if (ret) { if (ret) {

View File

@ -465,15 +465,15 @@ static int unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len
count++; count++;
n++; n++;
} }
#if 0
for (j=0;j<groupLengths[i];j++) { // for (j=0;j<groupLengths[i];j++) {
X[n]=grib_decode_unsigned_long(buf,&pos,groupWidths[i]); // X[n]=grib_decode_unsigned_long(buf,&pos,groupWidths[i]);
//printf("DXXXXX %ld %ld %ld %ld\n",n,X[n],groupWidths[i],groupLengths[i]); // //printf("DXXXXX %ld %ld %ld %ld\n",n,X[n],groupWidths[i],groupLengths[i]);
X[n]+=firstOrderValues[i]; // X[n]+=firstOrderValues[i];
count++; // count++;
n++; // n++;
} // }
#endif
} }
else { else {
for (j = 0; j < groupLengths[i]; j++) { for (j = 0; j < groupLengths[i]; j++) {
@ -992,23 +992,23 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
*/ */
incrementGroupLengthA = startGroupLength; incrementGroupLengthA = startGroupLength;
computeGroupA = 1; computeGroupA = 1;
#if 0
if (numberOfGroups==MAX_NUMBER_OF_GROUPS) { // if (numberOfGroups==MAX_NUMBER_OF_GROUPS) {
groupLengthA= remainingValues ; // groupLengthA= remainingValues ;
maxA=X[count]; // maxA=X[count];
minA=X[count]; // minA=X[count];
for (i=1;i<groupLengthA;i++) { // for (i=1;i<groupLengthA;i++) {
if (maxA<X[count+i]) maxA=X[count+i]; // if (maxA<X[count+i]) maxA=X[count+i];
if (minA>X[count+i]) minA=X[count+i]; // if (minA>X[count+i]) minA=X[count+i];
} // }
groupWidthA=number_of_bits(maxA-minA); // groupWidthA=number_of_bits(maxA-minA);
range=(long)codes_power<double>(groupWidthA,2)-1; // range=(long)codes_power<double>(groupWidthA,2)-1;
groupLengths[numberOfGroups]=groupLengthA; // groupLengths[numberOfGroups]=groupLengthA;
groupWidths[numberOfGroups]=groupWidthA; // groupWidths[numberOfGroups]=groupWidthA;
firstOrderValues[numberOfGroups] = maxA-range > 0 ? maxA-range : 0; // firstOrderValues[numberOfGroups] = maxA-range > 0 ? maxA-range : 0;
break; // break;
} // }
#endif
continue; continue;
} }
@ -1057,23 +1057,23 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
count += groupLengthA; count += groupLengthA;
remainingValues -= groupLengthA; remainingValues -= groupLengthA;
numberOfGroups++; numberOfGroups++;
#if 0
if (numberOfGroups==MAX_NUMBER_OF_GROUPS) { // if (numberOfGroups==MAX_NUMBER_OF_GROUPS) {
groupLengthA= remainingValues ; // groupLengthA= remainingValues ;
maxA=X[count]; // maxA=X[count];
minA=X[count]; // minA=X[count];
for (i=1;i<groupLengthA;i++) { // for (i=1;i<groupLengthA;i++) {
if (maxA<X[count+i]) maxA=X[count+i]; // if (maxA<X[count+i]) maxA=X[count+i];
if (minA>X[count+i]) minA=X[count+i]; // if (minA>X[count+i]) minA=X[count+i];
} // }
groupWidthA=number_of_bits(maxA-minA); // groupWidthA=number_of_bits(maxA-minA);
range=(long)codes_power<double>(groupWidthA,2)-1; // range=(long)codes_power<double>(groupWidthA,2)-1;
groupLengths[numberOfGroups]=groupLengthA; // groupLengths[numberOfGroups]=groupLengthA;
groupWidths[numberOfGroups]=groupWidthA; // groupWidths[numberOfGroups]=groupWidthA;
firstOrderValues[numberOfGroups] = maxA-range > 0 ? maxA-range : 0; // firstOrderValues[numberOfGroups] = maxA-range > 0 ? maxA-range : 0;
break; // break;
} // }
#endif
incrementGroupLengthA = startGroupLength; incrementGroupLengthA = startGroupLength;
computeGroupA = 1; computeGroupA = 1;
continue; continue;
@ -1331,8 +1331,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
if (ret) if (ret)
return ret; return ret;
Xp = X + orderOfSPD; Xp = X + orderOfSPD;
pos = 0; pos = 0;
#if EFDEBUG #if EFDEBUG
count = 0; count = 0;
#endif #endif

View File

@ -384,77 +384,75 @@ static int min_max_array(double* data, unsigned int n, double* min, double* max)
return GRIB_SUCCESS; return GRIB_SUCCESS;
} }
#if 0 // static void uint_char(unsigned int i, unsigned char* p)
static void uint_char(unsigned int i, unsigned char* p) // {
{ // p[0] = (i >> 24) & 255;
p[0] = (i >> 24) & 255; // p[1] = (i >> 16) & 255;
p[1] = (i >> 16) & 255; // p[2] = (i >> 8) & 255;
p[2] = (i >> 8) & 255; // p[3] = (i)&255;
p[3] = (i)&255; // }
}
static unsigned char* mk_bms(grib_accessor* a, double* data, unsigned int* ndata) // static unsigned char* mk_bms(grib_accessor* a, double* data, unsigned int* ndata)
{ // {
int bms_size; // int bms_size;
unsigned char *bms, *cbits; // unsigned char *bms, *cbits;
unsigned int nn, i, start, c, imask, i0; // unsigned int nn, i, start, c, imask, i0;
nn = *ndata; // nn = *ndata;
/* find first grid point with undefined data */ // /* find first grid point with undefined data */
for (i = 0; i < nn; i++) { // for (i = 0; i < nn; i++) {
if (UNDEFINED_VAL(data[i])) break; // if (UNDEFINED_VAL(data[i])) break;
} // }
if (i == nn) { /* all defined values, no need for bms */ // if (i == nn) { /* all defined values, no need for bms */
bms = reinterpret_cast<unsigned char*>(grib_context_malloc(a->context, 6)); // bms = reinterpret_cast<unsigned char*>(grib_context_malloc(a->context, 6));
if (bms == NULL) // if (bms == NULL)
grib_context_log(a->context, GRIB_LOG_ERROR, "mk_bms: memory allocation problem", ""); // grib_context_log(a->context, GRIB_LOG_ERROR, "mk_bms: memory allocation problem", "");
uint_char(6, bms); // length of section 6 // uint_char(6, bms); // length of section 6
bms[4] = 6; // section 6 // bms[4] = 6; // section 6
bms[5] = 255; // no bitmap // bms[5] = 255; // no bitmap
return bms; // return bms;
} // }
bms_size = 6 + (nn + 7) / 8; // bms_size = 6 + (nn + 7) / 8;
bms = reinterpret_cast<unsigned char*>(grib_context_malloc(a->context, bms_size)); // bms = reinterpret_cast<unsigned char*>(grib_context_malloc(a->context, bms_size));
if (bms == NULL) // if (bms == NULL)
grib_context_log(a->context, GRIB_LOG_ERROR, "mk_bms: memory allocation problem", ""); // grib_context_log(a->context, GRIB_LOG_ERROR, "mk_bms: memory allocation problem", "");
uint_char(bms_size, bms); // length of section 6 // uint_char(bms_size, bms); // length of section 6
bms[4] = 6; // section 6 // bms[4] = 6; // section 6
bms[5] = 0; // has bitmap // bms[5] = 0; // has bitmap
/* bitmap is accessed by bytes, make i0=i/8 bytes of bitmap */ // /* bitmap is accessed by bytes, make i0=i/8 bytes of bitmap */
cbits = bms + 6; // cbits = bms + 6;
i0 = i >> 3; // Number of bytes, required to store the bitmap // i0 = i >> 3; // Number of bytes, required to store the bitmap
for (i = 0; i < i0; i++) { // for (i = 0; i < i0; i++) {
// Set all bits in the bitmap to 1 // // Set all bits in the bitmap to 1
*cbits++ = 255; // *cbits++ = 255;
} // }
/* start processing data, skip i0*8 */ // /* start processing data, skip i0*8 */
c = 0; // counter: c += imask // c = 0; // counter: c += imask
imask = 128; // 100.0000 // imask = 128; // 100.0000
i0 = i0 << 3; // Number of bits in the bitmap // i0 = i0 << 3; // Number of bits in the bitmap
start = i0; // start = i0;
for (i = i0; i < nn; i++) { // for (i = i0; i < nn; i++) {
if (DEFINED_VAL(data[i])) { // if (DEFINED_VAL(data[i])) {
c += imask; // c += imask;
data[start++] = data[i]; // data[start++] = data[i];
} // }
if ((imask >>= 1) == 0) { // if ((imask >>= 1) == 0) {
*cbits++ = c; // *cbits++ = c;
c = 0; // c = 0;
imask = 128; // imask = 128;
} // }
} // }
if (imask != 128) *cbits = c; // if (imask != 128) *cbits = c;
*ndata = start; // *ndata = start;
return bms; // return bms;
} // }
#endif
static int post_process(grib_context* c, long* vals, long len, long order, long bias, const unsigned long extras[2]) static int post_process(grib_context* c, long* vals, long len, long order, long bias, const unsigned long extras[2])
{ {

View File

@ -9,8 +9,7 @@
*/ */
/*************************************************************************** /***************************************************************************
* Jean Baptiste Filippi - 01.11.2005 * * Jean Baptiste Filippi - 01.11.2005 *
* *
***************************************************************************/ ***************************************************************************/
#include "grib_api_internal.h" #include "grib_api_internal.h"
@ -31,7 +30,7 @@ grib_buffer* grib_create_growable_buffer(const grib_context* c)
grib_buffer* b = (grib_buffer*)grib_context_malloc_clear(c, sizeof(grib_buffer)); grib_buffer* b = (grib_buffer*)grib_context_malloc_clear(c, sizeof(grib_buffer));
if (b == NULL) { if (b == NULL) {
grib_context_log(c, GRIB_LOG_ERROR, "grib_new_buffer: cannot allocate buffer"); grib_context_log(c, GRIB_LOG_ERROR, "%s: cannot allocate buffer", __func__);
return NULL; return NULL;
} }
@ -42,7 +41,7 @@ grib_buffer* grib_create_growable_buffer(const grib_context* c)
b->growable = 1; b->growable = 1;
if (!b->data) { if (!b->data) {
grib_context_log(c, GRIB_LOG_ERROR, "grib_new_buffer: cannot allocate buffer"); grib_context_log(c, GRIB_LOG_ERROR, "%s: cannot allocate buffer", __func__);
grib_context_free(c, b); grib_context_free(c, b);
return NULL; return NULL;
} }
@ -55,7 +54,7 @@ grib_buffer* grib_new_buffer(const grib_context* c, const unsigned char* data, s
grib_buffer* b = (grib_buffer*)grib_context_malloc_clear(c, sizeof(grib_buffer)); grib_buffer* b = (grib_buffer*)grib_context_malloc_clear(c, sizeof(grib_buffer));
if (b == NULL) { if (b == NULL) {
grib_context_log(c, GRIB_LOG_ERROR, "grib_new_buffer: cannot allocate buffer"); grib_context_log(c, GRIB_LOG_ERROR, "%s: cannot allocate buffer", __func__);
return NULL; return NULL;
} }
@ -138,87 +137,75 @@ static void update_offsets_after(grib_accessor* a, long len)
} }
} }
#if 0 // /* 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*/ // void grib_recompute_sections_lengths(grib_section* s)
void grib_recompute_sections_lengths(grib_section* s) // {
{ // if(s)
if(s) // {
{ // long plen = 0;
long plen = 0; // size_t len = 1;
size_t len = 1;
grib_accessor* a = s->block->first; // grib_accessor* a = s->block->first;
while(a) // while(a)
{ // {
/* grib_recompute_sections_lengths(grib_get_sub_section(a)); */ // /* grib_recompute_sections_lengths(grib_get_sub_section(a)); */
grib_recompute_sections_lengths(a->sub_section); // grib_recompute_sections_lengths(a->sub_section);
a = a->next; // a = a->next;
} // }
if(s->aclength) // if(s->aclength)
{ // {
int ret; // int ret;
if(s->owner) // if(s->owner)
plen = grib_get_next_position_offset(s->block->last) - s->owner->offset; // plen = grib_get_next_position_offset(s->block->last) - s->owner->offset;
else // else
plen = grib_get_next_position_offset(s->block->last); // plen = grib_get_next_position_offset(s->block->last);
if((ret = grib_pack_long(s->aclength, &plen, &len)) != GRIB_SUCCESS) // if((ret = grib_pack_long(s->aclength, &plen, &len)) != GRIB_SUCCESS)
; // ;
#if 0 //
if(s->h->context->debug) // if(s->h->context->debug)
printf("SECTION updating length %ld .. %s\n",plen,s->owner->name); // printf("SECTION updating length %ld .. %s\n",plen,s->owner->name);
#endif // }
// }
// }
} // /* new GCC compiler v4.5.0 complains function is defined but not used*/
} // static void update_sections_lengths(grib_section* s)
} // {
#endif // long plen = 0;
// size_t len = 1;
// if(!s) return;
// if(s->aclength)
// {
// int ret;
// if(s->owner)
// plen = grib_get_next_position_offset(s->block->last) - s->owner->offset;
// else
// plen = grib_get_next_position_offset(s->block->last);
#if 0 // /* if(s->owner) */
/* new GCC compiler v4.5.0 complains function is defined but not used*/ // /* s->owner->length = plen; */
static void update_sections_lengths(grib_section* s)
{
long plen = 0;
size_t len = 1;
if(!s) return; // /* if(s->aclength) */
// if((ret = grib_pack_long(s->aclength, &plen, &len)) != GRIB_SUCCESS)
// ;
if(s->aclength)
{
int ret;
if(s->owner)
plen = grib_get_next_position_offset(s->block->last) - s->owner->offset;
else
plen = grib_get_next_position_offset(s->block->last);
/* if(s->owner) */
/* s->owner->length = plen; */
/* if(s->aclength) */
if((ret = grib_pack_long(s->aclength, &plen, &len)) != GRIB_SUCCESS)
;
if(s->h->context->debug)
{
printf("SECTION updating length %ld .. %s\n",plen,s->owner->name);
printf("NEXT_POS = %ld, owner offset= %ld %s %s\n",
grib_get_next_position_offset(s->block->last),
s->owner ? s->owner->offset : 0L, s->owner->name,
s->block->last->name);
}
}
if(s->owner)
update_sections_lengths(s->owner->parent);
}
#endif
// if(s->h->context->debug)
// {
// printf("SECTION updating length %ld .. %s\n",plen,s->owner->name);
// printf("NEXT_POS = %ld, owner offset= %ld %s %s\n",
// grib_get_next_position_offset(s->block->last),
// s->owner ? s->owner->offset : 0L, s->owner->name,
// s->block->last->name);
// }
// }
// if(s->owner)
// update_sections_lengths(s->owner->parent);
// }
void grib_buffer_replace(grib_accessor* a, const unsigned char* data, void grib_buffer_replace(grib_accessor* a, const unsigned char* data,
size_t newsize, int update_lengths, int update_paddings) size_t newsize, int update_lengths, int update_paddings)

View File

@ -82,23 +82,21 @@ void grib_oarray_delete(grib_context* c, grib_oarray* v)
grib_context_free(c, v); grib_context_free(c, v);
} }
#if 0 // void grib_oarray_delete_content(grib_context* c, grib_oarray* v)
void grib_oarray_delete_content(grib_context* c, grib_oarray* v) // {
{ // int i;
int i; // if (!v || !v->v)
if (!v || !v->v) // return;
return; // if (!c)
if (!c) // c = grib_context_get_default();
c = grib_context_get_default(); // for (i = 0; i < v->n; i++) {
for (i = 0; i < v->n; i++) { // if (v->v[i]) {
if (v->v[i]) { // grib_context_free(c, v->v[i]);
grib_context_free(c, v->v[i]); // v->v[i] = 0;
v->v[i] = 0; // }
} // }
} // v->n = 0;
v->n = 0; // }
}
#endif
void** grib_oarray_get_array(grib_context* c, grib_oarray* v) void** grib_oarray_get_array(grib_context* c, grib_oarray* v)
{ {

View File

@ -434,23 +434,22 @@ static void print_values(grib_context* c,
fprintf(stderr, "ECCODES DEBUG grib_util: packing_spec->packing_type = %s\n", fprintf(stderr, "ECCODES DEBUG grib_util: packing_spec->packing_type = %s\n",
get_packing_spec_packing_type_name(packing_spec->packing_type)); get_packing_spec_packing_type_name(packing_spec->packing_type));
#if 0 // if (spec->bitmapPresent) {
if (spec->bitmapPresent) { // int missing = 0;
int missing = 0; // size_t j = 0;
size_t j = 0; // double min = 1e100;
double min = 1e100; // for(j = 0; j < data_values_count ; j++)
for(j = 0; j < data_values_count ; j++) // {
{ // double d = data_values[j] - spec->missingValue;
double d = data_values[j] - spec->missingValue; // if(d < 0) d = -d;
if(d < 0) d = -d; // if(d < min) {
if(d < min) { // min = d;
min = d; // }
} // if(data_values[j] == spec->missingValue)
if(data_values[j] == spec->missingValue) // missing++;
missing++; // }
} // }
}
#endif
} }
/* /*
@ -459,33 +458,32 @@ static int DBL_EQUAL(double d1, double d2, double tolerance)
return fabs(d1-d2) < tolerance; return fabs(d1-d2) < tolerance;
} }
*/ */
#if 0
/* Returns a boolean: 1 if angle can be encoded, 0 otherwise */
static int grib1_angle_can_be_encoded(const double angle)
{
const double angle_milliDegrees = angle * 1000;
double rounded = (int)(angle_milliDegrees+0.5)/1000.0;
if (angle<0) {
rounded = (int)(angle_milliDegrees-0.5)/1000.0;
}
if (angle == rounded) return 1;
return 0; /* sub millidegree. Cannot be encoded in grib1 */
}
/* Returns a boolean: 1 if angle can be encoded, 0 otherwise */ // /* Returns a boolean: 1 if angle can be encoded, 0 otherwise */
static int angle_can_be_encoded(const double angle, const double angular_precision) // static int grib1_angle_can_be_encoded(const double angle)
{ // {
const double angle_expanded = angle * angular_precision; // const double angle_milliDegrees = angle * 1000;
Assert(angular_precision>0); // double rounded = (int)(angle_milliDegrees+0.5)/1000.0;
double rounded = (long)(angle_expanded+0.5)/angular_precision; // if (angle<0) {
if (angle<0) { // rounded = (int)(angle_milliDegrees-0.5)/1000.0;
rounded = (long)(angle_expanded-0.5)/angular_precision; // }
} // if (angle == rounded) return 1;
if (angle == rounded) return 1; // return 0; /* sub millidegree. Cannot be encoded in grib1 */
/*printf(" ......... angle cannot be encoded: %.10e\n", angle);*/ // }
return 0; /* Cannot be encoded */
} // /* Returns a boolean: 1 if angle can be encoded, 0 otherwise */
#endif // static int angle_can_be_encoded(const double angle, const double angular_precision)
// {
// const double angle_expanded = angle * angular_precision;
// Assert(angular_precision>0);
// double rounded = (long)(angle_expanded+0.5)/angular_precision;
// if (angle<0) {
// rounded = (long)(angle_expanded-0.5)/angular_precision;
// }
// if (angle == rounded) return 1;
// /*printf(" ......... angle cannot be encoded: %.10e\n", angle);*/
// return 0; /* Cannot be encoded */
// }
/* Returns a boolean: 1 if angle can be encoded, 0 otherwise */ /* Returns a boolean: 1 if angle can be encoded, 0 otherwise */
static int angle_can_be_encoded(grib_handle* h, const double angle) static int angle_can_be_encoded(grib_handle* h, const double angle)
@ -1612,17 +1610,17 @@ grib_handle* grib_util_set_spec2(grib_handle* h,
} }
/* Disable check: need to re-examine GRIB-864 */ /* Disable check: need to re-examine GRIB-864 */
#if 0
if ( (*err = check_handle_against_spec(h_out, editionNumber, spec, global_grid)) != GRIB_SUCCESS) { // if ( (*err = check_handle_against_spec(h_out, editionNumber, spec, global_grid)) != GRIB_SUCCESS) {
grib_context* c=grib_context_get_default(); // grib_context* c=grib_context_get_default();
fprintf(stderr,"GRIB_UTIL_SET_SPEC: Geometry check failed: %s\n", grib_get_error_message(*err)); // fprintf(stderr,"GRIB_UTIL_SET_SPEC: Geometry check failed: %s\n", grib_get_error_message(*err));
if (editionNumber == 1) { // if (editionNumber == 1) {
fprintf(stderr,"Note: in GRIB edition 1 latitude and longitude values cannot be represented with sub-millidegree precision.\n"); // fprintf(stderr,"Note: in GRIB edition 1 latitude and longitude values cannot be represented with sub-millidegree precision.\n");
} // }
if (c->write_on_fail) grib_write_message(h_out,"error.grib","w"); // if (c->write_on_fail) grib_write_message(h_out,"error.grib","w");
goto cleanup; // goto cleanup;
} // }
#endif
if (h->context->debug == -1) fprintf(stderr, "ECCODES DEBUG grib_util: grib_util_set_spec end\n"); if (h->context->debug == -1) fprintf(stderr, "ECCODES DEBUG grib_util: grib_util_set_spec end\n");
return h_out; return h_out;
@ -1632,94 +1630,93 @@ cleanup:
grib_handle_delete(h_out); grib_handle_delete(h_out);
return NULL; return NULL;
} }
#if 0
int grib_moments(grib_handle* h, double east, double north, double west, double south, int order, double* moments, long* count)
{
grib_iterator* iter = NULL;
int ret = 0, i, j, l;
size_t n = 0, numberOfPoints = 0;
double *lat, *lon, *values;
double vlat, vlon, val;
double dx, dy, ddx, ddy;
double mass, centroidX, centroidY;
double missingValue;
grib_context* c = grib_context_get_default();
ret = grib_get_size(h, "values", &n); // int grib_moments(grib_handle* h, double east, double north, double west, double south, int order, double* moments, long* count)
if (ret) // {
return ret; // grib_iterator* iter = NULL;
// int ret = 0, i, j, l;
// size_t n = 0, numberOfPoints = 0;
// double *lat, *lon, *values;
// double vlat, vlon, val;
// double dx, dy, ddx, ddy;
// double mass, centroidX, centroidY;
// double missingValue;
// grib_context* c = grib_context_get_default();
lat = (double*)grib_context_malloc_clear(c, sizeof(double) * n); // ret = grib_get_size(h, "values", &n);
lon = (double*)grib_context_malloc_clear(c, sizeof(double) * n); // if (ret)
values = (double*)grib_context_malloc_clear(c, sizeof(double) * n); // return ret;
iter = grib_iterator_new(h, 0, &ret); // lat = (double*)grib_context_malloc_clear(c, sizeof(double) * n);
numberOfPoints = 0; // lon = (double*)grib_context_malloc_clear(c, sizeof(double) * n);
while (grib_iterator_next(iter, &vlat, &vlon, &val)) { // values = (double*)grib_context_malloc_clear(c, sizeof(double) * n);
if (vlon >= east && vlon <= west && vlat >= south && vlat <= north) {
lat[numberOfPoints] = vlat;
lon[numberOfPoints] = vlon;
values[numberOfPoints] = val;
numberOfPoints++;
}
}
grib_iterator_delete(iter);
ret = grib_get_double(h, "missingValue", &missingValue); // iter = grib_iterator_new(h, 0, &ret);
// numberOfPoints = 0;
// while (grib_iterator_next(iter, &vlat, &vlon, &val)) {
// if (vlon >= east && vlon <= west && vlat >= south && vlat <= north) {
// lat[numberOfPoints] = vlat;
// lon[numberOfPoints] = vlon;
// values[numberOfPoints] = val;
// numberOfPoints++;
// }
// }
// grib_iterator_delete(iter);
centroidX = 0; // ret = grib_get_double(h, "missingValue", &missingValue);
centroidY = 0;
mass = 0;
*count = 0;
for (i = 0; i < numberOfPoints; i++) {
if (values[i] != missingValue) {
centroidX += lon[i] * values[i];
centroidY += lat[i] * values[i];
mass += values[i];
(*count)++;
}
}
centroidX /= mass;
centroidY /= mass;
mass /= *count;
for (j = 0; j < order * order; j++) // centroidX = 0;
moments[j] = 0; // centroidY = 0;
// mass = 0;
// *count = 0;
// for (i = 0; i < numberOfPoints; i++) {
// if (values[i] != missingValue) {
// centroidX += lon[i] * values[i];
// centroidY += lat[i] * values[i];
// mass += values[i];
// (*count)++;
// }
// }
// centroidX /= mass;
// centroidY /= mass;
// mass /= *count;
for (i = 0; i < numberOfPoints; i++) { // for (j = 0; j < order * order; j++)
if (values[i] != missingValue) { // moments[j] = 0;
dx = (lon[i] - centroidX);
dy = (lat[i] - centroidY);
ddx = 1;
for (j = 0; j < order; j++) {
ddy = 1;
for (l = 0; l < order; l++) {
moments[j * order + l] += ddx * ddy * values[i];
ddy *= dy;
}
ddx *= dx;
}
}
}
for (j = 0; j < order; j++) {
for (l = 0; l < order; l++) {
if (j + l > 1) {
moments[j * order + l] = pow(fabs(moments[j * order + l]), 1.0 / (j + l)) / *count;
}
else {
moments[j * order + l] /= *count;
}
}
}
grib_context_free(c, lat); // for (i = 0; i < numberOfPoints; i++) {
grib_context_free(c, lon); // if (values[i] != missingValue) {
grib_context_free(c, values); // dx = (lon[i] - centroidX);
(void)mass; // dy = (lat[i] - centroidY);
// ddx = 1;
// for (j = 0; j < order; j++) {
// ddy = 1;
// for (l = 0; l < order; l++) {
// moments[j * order + l] += ddx * ddy * values[i];
// ddy *= dy;
// }
// ddx *= dx;
// }
// }
// }
// for (j = 0; j < order; j++) {
// for (l = 0; l < order; l++) {
// if (j + l > 1) {
// moments[j * order + l] = pow(fabs(moments[j * order + l]), 1.0 / (j + l)) / *count;
// }
// else {
// moments[j * order + l] /= *count;
// }
// }
// }
return ret; // grib_context_free(c, lat);
} // grib_context_free(c, lon);
#endif // grib_context_free(c, values);
// (void)mass;
// return ret;
// }
// Helper function for 'parse_keyval_string' // Helper function for 'parse_keyval_string'
static void set_value(grib_values* value, char* str, int equal) static void set_value(grib_values* value, char* str, int equal)