mirror of https://github.com/ecmwf/eccodes.git
ECC-1403: WIP
This commit is contained in:
parent
e7b5750113
commit
8ab02b62b4
|
@ -269,19 +269,20 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
|
|||
double* bvals = NULL;
|
||||
size_t n_vals = 0;
|
||||
long nn = 0;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
|
||||
err = grib_value_count(a, &nn);
|
||||
n_vals = nn;
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (!grib_find_accessor(grib_handle_of_accessor(a), self->bitmap))
|
||||
return grib_get_double_element_internal(grib_handle_of_accessor(a), self->coded_values, idx, val);
|
||||
if (!grib_find_accessor(gh, self->bitmap))
|
||||
return grib_get_double_element_internal(gh, self->coded_values, idx, val);
|
||||
|
||||
if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &missing_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(gh, self->missing_value, &missing_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if ((err = grib_get_double_element_internal(grib_handle_of_accessor(a), self->bitmap, idx, val)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_element_internal(gh, self->bitmap, idx, val)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
if (*val == 0) {
|
||||
|
@ -293,7 +294,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
|
|||
if (bvals == NULL)
|
||||
return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
if ((err = grib_get_double_array_internal(grib_handle_of_accessor(a), self->bitmap, bvals, &n_vals)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_array_internal(gh, self->bitmap, bvals, &n_vals)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
cidx = 0;
|
||||
|
@ -303,13 +304,14 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
|
|||
|
||||
grib_context_free(a->context, bvals);
|
||||
|
||||
return grib_get_double_element_internal(grib_handle_of_accessor(a), self->coded_values, cidx, val);
|
||||
return grib_get_double_element_internal(gh, self->coded_values, cidx, val);
|
||||
}
|
||||
|
||||
static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
|
||||
{
|
||||
grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a;
|
||||
int err = 0, all_missing = 1;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
size_t cidx = 0; /* index into the coded_values array */
|
||||
size_t* cidx_array = NULL; /* array of indexes into the coded_values */
|
||||
double missing_value = 0;
|
||||
|
@ -321,24 +323,18 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array
|
|||
n_vals = nn;
|
||||
if (err) return err;
|
||||
|
||||
if (!grib_find_accessor(grib_handle_of_accessor(a), self->bitmap))
|
||||
return grib_get_double_element_set_internal(grib_handle_of_accessor(a), self->coded_values, index_array, len, val_array);
|
||||
if (!grib_find_accessor(gh, self->bitmap))
|
||||
return grib_get_double_element_set_internal(gh, self->coded_values, index_array, len, val_array);
|
||||
|
||||
if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &missing_value)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_internal(gh, self->missing_value, &missing_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
err = grib_get_double_element_set_internal(grib_handle_of_accessor(a), self->bitmap, index_array, len, val_array);
|
||||
err = grib_get_double_element_set_internal(gh, self->bitmap, index_array, len, val_array);
|
||||
if (err) return err;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (val_array[i] == 0) val_array[i] = missing_value;
|
||||
else all_missing = 0;
|
||||
}
|
||||
// for (i = 0; i < len; i++) {
|
||||
// if ((err = grib_get_double_element_internal(grib_handle_of_accessor(a), self->bitmap, index_array[i], val_array + i)) != GRIB_SUCCESS)
|
||||
// return err;
|
||||
// if (val_array[i] == 0) val_array[i] = missing_value;
|
||||
// else all_missing = 0;
|
||||
// }
|
||||
|
||||
if (all_missing) {
|
||||
return GRIB_SUCCESS;
|
||||
|
@ -347,18 +343,20 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array
|
|||
bvals = (double*)grib_context_malloc(a->context, n_vals * sizeof(double));
|
||||
if (bvals == NULL) return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
if ((err = grib_get_double_array_internal(grib_handle_of_accessor(a), self->bitmap, bvals, &n_vals)) != GRIB_SUCCESS)
|
||||
if ((err = grib_get_double_array_internal(gh, self->bitmap, bvals, &n_vals)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
cidx_array = (size_t*)grib_context_malloc(a->context, len * sizeof(size_t));
|
||||
for (i = 0; i < len; i++) {
|
||||
size_t idx = index_array[i];
|
||||
cidx = 0;
|
||||
for (j = 0; j < index_array[i]; j++) {
|
||||
for (j = 0; j < idx; j++) {
|
||||
cidx += bvals[j];
|
||||
}
|
||||
printf("dbg: idx=%ld setting cidx_array[%ld]=%ld\n", idx, i, cidx);
|
||||
cidx_array[i] = cidx;
|
||||
}
|
||||
err = grib_get_double_element_set_internal(grib_handle_of_accessor(a), self->coded_values, cidx_array, len, val_array);
|
||||
err = grib_get_double_element_set_internal(gh, self->coded_values, cidx_array, len, val_array);
|
||||
if (err) return err;
|
||||
|
||||
grib_context_free(a->context, bvals);
|
||||
|
|
|
@ -345,8 +345,58 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
|
|||
|
||||
static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
|
||||
{
|
||||
Assert(!"unpack_double_element_set: apply boustrophedonic bmp packing ");
|
||||
return GRIB_DECODING_ERROR;
|
||||
grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a;
|
||||
grib_handle* gh = grib_handle_of_accessor(a);
|
||||
int err = 0, all_missing = 1;
|
||||
size_t cidx = 0; /* index into the coded_values array */
|
||||
size_t* cidx_array = NULL; /* array of indexes into the coded_values */
|
||||
double missing_value = 0;
|
||||
double* bvals = NULL;
|
||||
size_t n_vals = 0, i = 0, j = 0;
|
||||
long nn = 0;
|
||||
|
||||
err = grib_value_count(a, &nn);
|
||||
n_vals = nn;
|
||||
if (err) return err;
|
||||
|
||||
if (!grib_find_accessor(gh, self->bitmap))
|
||||
return grib_get_double_element_set_internal(gh, self->coded_values, index_array, len, val_array);
|
||||
|
||||
if ((err = grib_get_double_internal(gh, self->missing_value, &missing_value)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
err = grib_get_double_element_set_internal(gh, self->bitmap, index_array, len, val_array);
|
||||
if (err) return err;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (val_array[i] == 0) val_array[i] = missing_value;
|
||||
else all_missing = 0;
|
||||
}
|
||||
|
||||
if (all_missing) {
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
bvals = (double*)grib_context_malloc(a->context, n_vals * sizeof(double));
|
||||
if (bvals == NULL) return GRIB_OUT_OF_MEMORY;
|
||||
|
||||
if ((err = grib_get_double_array_internal(gh, self->bitmap, bvals, &n_vals)) != GRIB_SUCCESS)
|
||||
return err;
|
||||
|
||||
cidx_array = (size_t*)grib_context_malloc(a->context, len * sizeof(size_t));
|
||||
for (i = 0; i < len; i++) {
|
||||
cidx = 0;
|
||||
for (j = 0; j < index_array[i]; j++) {
|
||||
cidx += bvals[j];
|
||||
}
|
||||
cidx_array[i] = cidx;
|
||||
}
|
||||
err = grib_get_double_element_set_internal(gh, self->coded_values, cidx_array, len, val_array);
|
||||
if (err) return err;
|
||||
|
||||
grib_context_free(a->context, bvals);
|
||||
grib_context_free(a->context, cidx_array);
|
||||
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
|
||||
static int pack_double(grib_accessor* a, const double* val, size_t* len)
|
||||
|
|
|
@ -302,7 +302,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
|
|||
*len = n_vals;
|
||||
return GRIB_SUCCESS;
|
||||
}
|
||||
//printf("dbg.....\tjpeg unpack\n");
|
||||
|
||||
buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data;
|
||||
buf += grib_byte_offset(a);
|
||||
|
||||
|
|
Loading…
Reference in New Issue