mirror of https://github.com/ecmwf/eccodes.git
Dead code removal
This commit is contained in:
parent
1f392203d5
commit
413d7da794
|
@ -271,13 +271,11 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if(!grib_find_accessor(grib_handle_of_accessor(a),self->bitmap)){
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
"Accessor %s cannot access bitmap \n", a->name, self->bitmap_present, ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
// if(!grib_find_accessor(grib_handle_of_accessor(a),self->bitmap)){
|
||||
// grib_context_log(a->context, GRIB_LOG_ERROR,
|
||||
// "Accessor %s cannot access bitmap \n", a->name, self->bitmap_present, ret);
|
||||
// return ret;
|
||||
// }
|
||||
|
||||
ret = grib_set_double_array_internal(grib_handle_of_accessor(a), self->coded_values, val, *len);
|
||||
if (ret) {
|
||||
|
|
|
@ -465,15 +465,15 @@ static int unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len
|
|||
count++;
|
||||
n++;
|
||||
}
|
||||
#if 0
|
||||
for (j=0;j<groupLengths[i];j++) {
|
||||
X[n]=grib_decode_unsigned_long(buf,&pos,groupWidths[i]);
|
||||
//printf("DXXXXX %ld %ld %ld %ld\n",n,X[n],groupWidths[i],groupLengths[i]);
|
||||
X[n]+=firstOrderValues[i];
|
||||
count++;
|
||||
n++;
|
||||
}
|
||||
#endif
|
||||
|
||||
// for (j=0;j<groupLengths[i];j++) {
|
||||
// X[n]=grib_decode_unsigned_long(buf,&pos,groupWidths[i]);
|
||||
// //printf("DXXXXX %ld %ld %ld %ld\n",n,X[n],groupWidths[i],groupLengths[i]);
|
||||
// X[n]+=firstOrderValues[i];
|
||||
// count++;
|
||||
// n++;
|
||||
// }
|
||||
|
||||
}
|
||||
else {
|
||||
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;
|
||||
computeGroupA = 1;
|
||||
#if 0
|
||||
if (numberOfGroups==MAX_NUMBER_OF_GROUPS) {
|
||||
groupLengthA= remainingValues ;
|
||||
maxA=X[count];
|
||||
minA=X[count];
|
||||
for (i=1;i<groupLengthA;i++) {
|
||||
if (maxA<X[count+i]) maxA=X[count+i];
|
||||
if (minA>X[count+i]) minA=X[count+i];
|
||||
}
|
||||
groupWidthA=number_of_bits(maxA-minA);
|
||||
range=(long)codes_power<double>(groupWidthA,2)-1;
|
||||
groupLengths[numberOfGroups]=groupLengthA;
|
||||
groupWidths[numberOfGroups]=groupWidthA;
|
||||
firstOrderValues[numberOfGroups] = maxA-range > 0 ? maxA-range : 0;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
// if (numberOfGroups==MAX_NUMBER_OF_GROUPS) {
|
||||
// groupLengthA= remainingValues ;
|
||||
// maxA=X[count];
|
||||
// minA=X[count];
|
||||
// for (i=1;i<groupLengthA;i++) {
|
||||
// if (maxA<X[count+i]) maxA=X[count+i];
|
||||
// if (minA>X[count+i]) minA=X[count+i];
|
||||
// }
|
||||
// groupWidthA=number_of_bits(maxA-minA);
|
||||
// range=(long)codes_power<double>(groupWidthA,2)-1;
|
||||
// groupLengths[numberOfGroups]=groupLengthA;
|
||||
// groupWidths[numberOfGroups]=groupWidthA;
|
||||
// firstOrderValues[numberOfGroups] = maxA-range > 0 ? maxA-range : 0;
|
||||
// break;
|
||||
// }
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1057,23 +1057,23 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
count += groupLengthA;
|
||||
remainingValues -= groupLengthA;
|
||||
numberOfGroups++;
|
||||
#if 0
|
||||
if (numberOfGroups==MAX_NUMBER_OF_GROUPS) {
|
||||
groupLengthA= remainingValues ;
|
||||
maxA=X[count];
|
||||
minA=X[count];
|
||||
for (i=1;i<groupLengthA;i++) {
|
||||
if (maxA<X[count+i]) maxA=X[count+i];
|
||||
if (minA>X[count+i]) minA=X[count+i];
|
||||
}
|
||||
groupWidthA=number_of_bits(maxA-minA);
|
||||
range=(long)codes_power<double>(groupWidthA,2)-1;
|
||||
groupLengths[numberOfGroups]=groupLengthA;
|
||||
groupWidths[numberOfGroups]=groupWidthA;
|
||||
firstOrderValues[numberOfGroups] = maxA-range > 0 ? maxA-range : 0;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
// if (numberOfGroups==MAX_NUMBER_OF_GROUPS) {
|
||||
// groupLengthA= remainingValues ;
|
||||
// maxA=X[count];
|
||||
// minA=X[count];
|
||||
// for (i=1;i<groupLengthA;i++) {
|
||||
// if (maxA<X[count+i]) maxA=X[count+i];
|
||||
// if (minA>X[count+i]) minA=X[count+i];
|
||||
// }
|
||||
// groupWidthA=number_of_bits(maxA-minA);
|
||||
// range=(long)codes_power<double>(groupWidthA,2)-1;
|
||||
// groupLengths[numberOfGroups]=groupLengthA;
|
||||
// groupWidths[numberOfGroups]=groupWidthA;
|
||||
// firstOrderValues[numberOfGroups] = maxA-range > 0 ? maxA-range : 0;
|
||||
// break;
|
||||
// }
|
||||
|
||||
incrementGroupLengthA = startGroupLength;
|
||||
computeGroupA = 1;
|
||||
continue;
|
||||
|
@ -1331,8 +1331,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
|||
if (ret)
|
||||
return ret;
|
||||
|
||||
Xp = X + orderOfSPD;
|
||||
pos = 0;
|
||||
Xp = X + orderOfSPD;
|
||||
pos = 0;
|
||||
#if EFDEBUG
|
||||
count = 0;
|
||||
#endif
|
||||
|
|
|
@ -384,77 +384,75 @@ static int min_max_array(double* data, unsigned int n, double* min, double* max)
|
|||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void uint_char(unsigned int i, unsigned char* p)
|
||||
{
|
||||
p[0] = (i >> 24) & 255;
|
||||
p[1] = (i >> 16) & 255;
|
||||
p[2] = (i >> 8) & 255;
|
||||
p[3] = (i)&255;
|
||||
}
|
||||
// static void uint_char(unsigned int i, unsigned char* p)
|
||||
// {
|
||||
// p[0] = (i >> 24) & 255;
|
||||
// p[1] = (i >> 16) & 255;
|
||||
// p[2] = (i >> 8) & 255;
|
||||
// p[3] = (i)&255;
|
||||
// }
|
||||
|
||||
static unsigned char* mk_bms(grib_accessor* a, double* data, unsigned int* ndata)
|
||||
{
|
||||
int bms_size;
|
||||
unsigned char *bms, *cbits;
|
||||
unsigned int nn, i, start, c, imask, i0;
|
||||
// static unsigned char* mk_bms(grib_accessor* a, double* data, unsigned int* ndata)
|
||||
// {
|
||||
// int bms_size;
|
||||
// unsigned char *bms, *cbits;
|
||||
// unsigned int nn, i, start, c, imask, i0;
|
||||
|
||||
nn = *ndata;
|
||||
// nn = *ndata;
|
||||
|
||||
/* find first grid point with undefined data */
|
||||
for (i = 0; i < nn; i++) {
|
||||
if (UNDEFINED_VAL(data[i])) break;
|
||||
}
|
||||
// /* find first grid point with undefined data */
|
||||
// for (i = 0; i < nn; i++) {
|
||||
// if (UNDEFINED_VAL(data[i])) break;
|
||||
// }
|
||||
|
||||
if (i == nn) { /* all defined values, no need for bms */
|
||||
bms = reinterpret_cast<unsigned char*>(grib_context_malloc(a->context, 6));
|
||||
if (bms == NULL)
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "mk_bms: memory allocation problem", "");
|
||||
uint_char(6, bms); // length of section 6
|
||||
bms[4] = 6; // section 6
|
||||
bms[5] = 255; // no bitmap
|
||||
return bms;
|
||||
}
|
||||
// if (i == nn) { /* all defined values, no need for bms */
|
||||
// bms = reinterpret_cast<unsigned char*>(grib_context_malloc(a->context, 6));
|
||||
// if (bms == NULL)
|
||||
// grib_context_log(a->context, GRIB_LOG_ERROR, "mk_bms: memory allocation problem", "");
|
||||
// uint_char(6, bms); // length of section 6
|
||||
// bms[4] = 6; // section 6
|
||||
// bms[5] = 255; // no bitmap
|
||||
// return bms;
|
||||
// }
|
||||
|
||||
bms_size = 6 + (nn + 7) / 8;
|
||||
bms = reinterpret_cast<unsigned char*>(grib_context_malloc(a->context, bms_size));
|
||||
if (bms == NULL)
|
||||
grib_context_log(a->context, GRIB_LOG_ERROR, "mk_bms: memory allocation problem", "");
|
||||
// bms_size = 6 + (nn + 7) / 8;
|
||||
// bms = reinterpret_cast<unsigned char*>(grib_context_malloc(a->context, bms_size));
|
||||
// if (bms == NULL)
|
||||
// grib_context_log(a->context, GRIB_LOG_ERROR, "mk_bms: memory allocation problem", "");
|
||||
|
||||
uint_char(bms_size, bms); // length of section 6
|
||||
bms[4] = 6; // section 6
|
||||
bms[5] = 0; // has bitmap
|
||||
// uint_char(bms_size, bms); // length of section 6
|
||||
// bms[4] = 6; // section 6
|
||||
// bms[5] = 0; // has bitmap
|
||||
|
||||
/* bitmap is accessed by bytes, make i0=i/8 bytes of bitmap */
|
||||
cbits = bms + 6;
|
||||
i0 = i >> 3; // Number of bytes, required to store the bitmap
|
||||
for (i = 0; i < i0; i++) {
|
||||
// Set all bits in the bitmap to 1
|
||||
*cbits++ = 255;
|
||||
}
|
||||
// /* bitmap is accessed by bytes, make i0=i/8 bytes of bitmap */
|
||||
// cbits = bms + 6;
|
||||
// i0 = i >> 3; // Number of bytes, required to store the bitmap
|
||||
// for (i = 0; i < i0; i++) {
|
||||
// // Set all bits in the bitmap to 1
|
||||
// *cbits++ = 255;
|
||||
// }
|
||||
|
||||
/* start processing data, skip i0*8 */
|
||||
// /* start processing data, skip i0*8 */
|
||||
|
||||
c = 0; // counter: c += imask
|
||||
imask = 128; // 100.0000
|
||||
i0 = i0 << 3; // Number of bits in the bitmap
|
||||
start = i0;
|
||||
for (i = i0; i < nn; i++) {
|
||||
if (DEFINED_VAL(data[i])) {
|
||||
c += imask;
|
||||
data[start++] = data[i];
|
||||
}
|
||||
if ((imask >>= 1) == 0) {
|
||||
*cbits++ = c;
|
||||
c = 0;
|
||||
imask = 128;
|
||||
}
|
||||
}
|
||||
if (imask != 128) *cbits = c;
|
||||
*ndata = start;
|
||||
return bms;
|
||||
}
|
||||
#endif
|
||||
// c = 0; // counter: c += imask
|
||||
// imask = 128; // 100.0000
|
||||
// i0 = i0 << 3; // Number of bits in the bitmap
|
||||
// start = i0;
|
||||
// for (i = i0; i < nn; i++) {
|
||||
// if (DEFINED_VAL(data[i])) {
|
||||
// c += imask;
|
||||
// data[start++] = data[i];
|
||||
// }
|
||||
// if ((imask >>= 1) == 0) {
|
||||
// *cbits++ = c;
|
||||
// c = 0;
|
||||
// imask = 128;
|
||||
// }
|
||||
// }
|
||||
// if (imask != 128) *cbits = c;
|
||||
// *ndata = start;
|
||||
// return bms;
|
||||
// }
|
||||
|
||||
static int post_process(grib_context* c, long* vals, long len, long order, long bias, const unsigned long extras[2])
|
||||
{
|
||||
|
|
|
@ -9,8 +9,7 @@
|
|||
*/
|
||||
|
||||
/***************************************************************************
|
||||
* Jean Baptiste Filippi - 01.11.2005 *
|
||||
* *
|
||||
* Jean Baptiste Filippi - 01.11.2005 *
|
||||
***************************************************************************/
|
||||
#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));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -42,7 +41,7 @@ grib_buffer* grib_create_growable_buffer(const grib_context* c)
|
|||
b->growable = 1;
|
||||
|
||||
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);
|
||||
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));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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*/
|
||||
void grib_recompute_sections_lengths(grib_section* s)
|
||||
{
|
||||
if(s)
|
||||
{
|
||||
long plen = 0;
|
||||
size_t len = 1;
|
||||
// /* new GCC compiler v4.5.0 complains function is defined but not used*/
|
||||
// void grib_recompute_sections_lengths(grib_section* s)
|
||||
// {
|
||||
// if(s)
|
||||
// {
|
||||
// long plen = 0;
|
||||
// size_t len = 1;
|
||||
|
||||
grib_accessor* a = s->block->first;
|
||||
// grib_accessor* a = s->block->first;
|
||||
|
||||
while(a)
|
||||
{
|
||||
/* grib_recompute_sections_lengths(grib_get_sub_section(a)); */
|
||||
grib_recompute_sections_lengths(a->sub_section);
|
||||
a = a->next;
|
||||
}
|
||||
// while(a)
|
||||
// {
|
||||
// /* grib_recompute_sections_lengths(grib_get_sub_section(a)); */
|
||||
// grib_recompute_sections_lengths(a->sub_section);
|
||||
// a = a->next;
|
||||
// }
|
||||
|
||||
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->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((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)
|
||||
printf("SECTION updating length %ld .. %s\n",plen,s->owner->name);
|
||||
#endif
|
||||
//
|
||||
// if(s->h->context->debug)
|
||||
// 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)
|
||||
// {
|
||||
// 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
|
||||
/* new GCC compiler v4.5.0 complains function is defined but not used*/
|
||||
static void update_sections_lengths(grib_section* s)
|
||||
{
|
||||
long plen = 0;
|
||||
size_t len = 1;
|
||||
// /* if(s->owner) */
|
||||
// /* s->owner->length = plen; */
|
||||
|
||||
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(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->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);
|
||||
// }
|
||||
|
||||
void grib_buffer_replace(grib_accessor* a, const unsigned char* data,
|
||||
size_t newsize, int update_lengths, int update_paddings)
|
||||
|
|
|
@ -82,23 +82,21 @@ void grib_oarray_delete(grib_context* c, grib_oarray* v)
|
|||
grib_context_free(c, v);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void grib_oarray_delete_content(grib_context* c, grib_oarray* v)
|
||||
{
|
||||
int i;
|
||||
if (!v || !v->v)
|
||||
return;
|
||||
if (!c)
|
||||
c = grib_context_get_default();
|
||||
for (i = 0; i < v->n; i++) {
|
||||
if (v->v[i]) {
|
||||
grib_context_free(c, v->v[i]);
|
||||
v->v[i] = 0;
|
||||
}
|
||||
}
|
||||
v->n = 0;
|
||||
}
|
||||
#endif
|
||||
// void grib_oarray_delete_content(grib_context* c, grib_oarray* v)
|
||||
// {
|
||||
// int i;
|
||||
// if (!v || !v->v)
|
||||
// return;
|
||||
// if (!c)
|
||||
// c = grib_context_get_default();
|
||||
// for (i = 0; i < v->n; i++) {
|
||||
// if (v->v[i]) {
|
||||
// grib_context_free(c, v->v[i]);
|
||||
// v->v[i] = 0;
|
||||
// }
|
||||
// }
|
||||
// v->n = 0;
|
||||
// }
|
||||
|
||||
void** grib_oarray_get_array(grib_context* c, grib_oarray* v)
|
||||
{
|
||||
|
|
263
src/grib_util.cc
263
src/grib_util.cc
|
@ -434,23 +434,22 @@ static void print_values(grib_context* c,
|
|||
fprintf(stderr, "ECCODES DEBUG grib_util: packing_spec->packing_type = %s\n",
|
||||
get_packing_spec_packing_type_name(packing_spec->packing_type));
|
||||
|
||||
#if 0
|
||||
if (spec->bitmapPresent) {
|
||||
int missing = 0;
|
||||
size_t j = 0;
|
||||
double min = 1e100;
|
||||
for(j = 0; j < data_values_count ; j++)
|
||||
{
|
||||
double d = data_values[j] - spec->missingValue;
|
||||
if(d < 0) d = -d;
|
||||
if(d < min) {
|
||||
min = d;
|
||||
}
|
||||
if(data_values[j] == spec->missingValue)
|
||||
missing++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// if (spec->bitmapPresent) {
|
||||
// int missing = 0;
|
||||
// size_t j = 0;
|
||||
// double min = 1e100;
|
||||
// for(j = 0; j < data_values_count ; j++)
|
||||
// {
|
||||
// double d = data_values[j] - spec->missingValue;
|
||||
// if(d < 0) d = -d;
|
||||
// if(d < min) {
|
||||
// min = d;
|
||||
// }
|
||||
// if(data_values[j] == spec->missingValue)
|
||||
// missing++;
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -459,33 +458,32 @@ static int DBL_EQUAL(double d1, double d2, double 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 */
|
||||
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 */
|
||||
}
|
||||
#endif
|
||||
// /* 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 */
|
||||
// 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 */
|
||||
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 */
|
||||
#if 0
|
||||
if ( (*err = check_handle_against_spec(h_out, editionNumber, spec, global_grid)) != GRIB_SUCCESS) {
|
||||
grib_context* c=grib_context_get_default();
|
||||
fprintf(stderr,"GRIB_UTIL_SET_SPEC: Geometry check failed: %s\n", grib_get_error_message(*err));
|
||||
if (editionNumber == 1) {
|
||||
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");
|
||||
goto cleanup;
|
||||
}
|
||||
#endif
|
||||
|
||||
// if ( (*err = check_handle_against_spec(h_out, editionNumber, spec, global_grid)) != GRIB_SUCCESS) {
|
||||
// grib_context* c=grib_context_get_default();
|
||||
// fprintf(stderr,"GRIB_UTIL_SET_SPEC: Geometry check failed: %s\n", grib_get_error_message(*err));
|
||||
// if (editionNumber == 1) {
|
||||
// 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");
|
||||
// goto cleanup;
|
||||
// }
|
||||
|
||||
if (h->context->debug == -1) fprintf(stderr, "ECCODES DEBUG grib_util: grib_util_set_spec end\n");
|
||||
|
||||
return h_out;
|
||||
|
@ -1632,94 +1630,93 @@ cleanup:
|
|||
grib_handle_delete(h_out);
|
||||
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);
|
||||
if (ret)
|
||||
return ret;
|
||||
// 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();
|
||||
|
||||
lat = (double*)grib_context_malloc_clear(c, sizeof(double) * n);
|
||||
lon = (double*)grib_context_malloc_clear(c, sizeof(double) * n);
|
||||
values = (double*)grib_context_malloc_clear(c, sizeof(double) * n);
|
||||
// ret = grib_get_size(h, "values", &n);
|
||||
// if (ret)
|
||||
// return ret;
|
||||
|
||||
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);
|
||||
// lat = (double*)grib_context_malloc_clear(c, sizeof(double) * n);
|
||||
// lon = (double*)grib_context_malloc_clear(c, sizeof(double) * n);
|
||||
// values = (double*)grib_context_malloc_clear(c, sizeof(double) * n);
|
||||
|
||||
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;
|
||||
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;
|
||||
// ret = grib_get_double(h, "missingValue", &missingValue);
|
||||
|
||||
for (j = 0; j < order * order; j++)
|
||||
moments[j] = 0;
|
||||
// centroidX = 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++) {
|
||||
if (values[i] != missingValue) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
// for (j = 0; j < order * order; j++)
|
||||
// moments[j] = 0;
|
||||
|
||||
grib_context_free(c, lat);
|
||||
grib_context_free(c, lon);
|
||||
grib_context_free(c, values);
|
||||
(void)mass;
|
||||
// for (i = 0; i < numberOfPoints; i++) {
|
||||
// if (values[i] != missingValue) {
|
||||
// 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;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
// grib_context_free(c, lat);
|
||||
// grib_context_free(c, lon);
|
||||
// grib_context_free(c, values);
|
||||
// (void)mass;
|
||||
|
||||
// return ret;
|
||||
// }
|
||||
|
||||
// Helper function for 'parse_keyval_string'
|
||||
static void set_value(grib_values* value, char* str, int equal)
|
||||
|
|
Loading…
Reference in New Issue