Performance: Replace multiple calls to grib_handle_of_accessor

This commit is contained in:
Shahram Najm 2024-01-20 21:22:14 +00:00
parent 86131db2f2
commit ee7d5a5b11
6 changed files with 70 additions and 72 deletions

View File

@ -119,20 +119,21 @@ grib_accessor_class* grib_accessor_class_bufr_extract_area_subsets = &_grib_acce
static void init(grib_accessor* a, const long len, grib_arguments* arg) static void init(grib_accessor* a, const long len, grib_arguments* arg)
{ {
int n = 0;
grib_accessor_bufr_extract_area_subsets* self = (grib_accessor_bufr_extract_area_subsets*)a; grib_accessor_bufr_extract_area_subsets* self = (grib_accessor_bufr_extract_area_subsets*)a;
grib_handle* h = grib_handle_of_accessor(a);
int n = 0;
a->length = 0; a->length = 0;
self->doExtractSubsets = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->doExtractSubsets = grib_arguments_get_name(h, arg, n++);
self->numberOfSubsets = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->numberOfSubsets = grib_arguments_get_name(h, arg, n++);
self->extractSubsetList = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->extractSubsetList = grib_arguments_get_name(h, arg, n++);
self->extractAreaWestLongitude = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->extractAreaWestLongitude = grib_arguments_get_name(h, arg, n++);
self->extractAreaEastLongitude = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->extractAreaEastLongitude = grib_arguments_get_name(h, arg, n++);
self->extractAreaNorthLatitude = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->extractAreaNorthLatitude = grib_arguments_get_name(h, arg, n++);
self->extractAreaSouthLatitude = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->extractAreaSouthLatitude = grib_arguments_get_name(h, arg, n++);
self->extractAreaLongitudeRank = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->extractAreaLongitudeRank = grib_arguments_get_name(h, arg, n++);
self->extractAreaLatitudeRank = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->extractAreaLatitudeRank = grib_arguments_get_name(h, arg, n++);
self->extractedAreaNumberOfSubsets = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->extractedAreaNumberOfSubsets = grib_arguments_get_name(h, arg, n++);
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
} }
@ -152,11 +153,12 @@ static void fill_in(double a[], long length)
static int select_area(grib_accessor* a) static int select_area(grib_accessor* a)
{ {
int ret = 0;
long compressed = 0;
grib_accessor_bufr_extract_area_subsets* self = (grib_accessor_bufr_extract_area_subsets*)a; grib_accessor_bufr_extract_area_subsets* self = (grib_accessor_bufr_extract_area_subsets*)a;
grib_handle* h = grib_handle_of_accessor(a);
grib_context* c = h->context; int ret = 0;
long compressed = 0;
grib_handle* h = grib_handle_of_accessor(a);
grib_context* c = h->context;
double* lat = NULL; double* lat = NULL;
double* lon = NULL; double* lon = NULL;

View File

@ -111,16 +111,17 @@ grib_accessor_class* grib_accessor_class_bufr_simple_thinning = &_grib_accessor_
static void init(grib_accessor* a, const long len, grib_arguments* arg) static void init(grib_accessor* a, const long len, grib_arguments* arg)
{ {
int n = 0;
grib_accessor_bufr_simple_thinning* self = (grib_accessor_bufr_simple_thinning*)a; grib_accessor_bufr_simple_thinning* self = (grib_accessor_bufr_simple_thinning*)a;
grib_handle* h = grib_handle_of_accessor(a);
int n = 0;
a->length = 0; a->length = 0;
self->doExtractSubsets = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->doExtractSubsets = grib_arguments_get_name(h, arg, n++);
self->numberOfSubsets = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->numberOfSubsets = grib_arguments_get_name(h, arg, n++);
self->extractSubsetList = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->extractSubsetList = grib_arguments_get_name(h, arg, n++);
self->simpleThinningStart = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->simpleThinningStart = grib_arguments_get_name(h, arg, n++);
self->simpleThinningMissingRadius = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->simpleThinningMissingRadius = grib_arguments_get_name(h, arg, n++);
self->simpleThinningSkip = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); self->simpleThinningSkip = grib_arguments_get_name(h, arg, n++);
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
} }

View File

@ -117,17 +117,18 @@ grib_accessor_class* grib_accessor_class_change_scanning_direction = &_grib_acce
static void init(grib_accessor* a, const long len, grib_arguments* args) static void init(grib_accessor* a, const long len, grib_arguments* args)
{ {
int n = 0;
grib_accessor_change_scanning_direction* self = (grib_accessor_change_scanning_direction*)a; grib_accessor_change_scanning_direction* self = (grib_accessor_change_scanning_direction*)a;
grib_handle* h = grib_handle_of_accessor(a);
int n = 0;
self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); self->values = grib_arguments_get_name(h, args, n++);
self->Ni = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); self->Ni = grib_arguments_get_name(h, args, n++);
self->Nj = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); self->Nj = grib_arguments_get_name(h, args, n++);
self->i_scans_negatively = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); self->i_scans_negatively = grib_arguments_get_name(h, args, n++);
self->j_scans_positively = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); self->j_scans_positively = grib_arguments_get_name(h, args, n++);
self->first = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); self->first = grib_arguments_get_name(h, args, n++);
self->last = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); self->last = grib_arguments_get_name(h, args, n++);
self->axis = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); self->axis = grib_arguments_get_name(h, args, n++);
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
a->length = 0; a->length = 0;
@ -150,7 +151,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
const char* cclass_name = a->cclass->name; const char* cclass_name = a->cclass->name;
if (*val == 0) if (*val == 0)
return 0; return GRIB_SUCCESS;
/* Make sure Ni / Nj are not missing */ /* Make sure Ni / Nj are not missing */
if (grib_is_missing(h, self->Ni, &err) && !err) { if (grib_is_missing(h, self->Ni, &err) && !err) {

View File

@ -136,26 +136,25 @@ grib_accessor_class* grib_accessor_class_data_png_packing = &_grib_accessor_clas
static void init(grib_accessor* a, const long v, grib_arguments* args) static void init(grib_accessor* a, const long v, grib_arguments* args)
{ {
grib_accessor_data_png_packing* self = (grib_accessor_data_png_packing*)a; grib_accessor_data_png_packing* self = (grib_accessor_data_png_packing*)a;
grib_handle* h = grib_handle_of_accessor(a);
self->number_of_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); self->number_of_values = grib_arguments_get_name(h, args, self->carg++);
self->reference_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); self->reference_value = grib_arguments_get_name(h, args, self->carg++);
self->binary_scale_factor = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); self->binary_scale_factor = grib_arguments_get_name(h, args, self->carg++);
self->decimal_scale_factor = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); self->decimal_scale_factor = grib_arguments_get_name(h, args, self->carg++);
self->bits_per_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); self->bits_per_value = grib_arguments_get_name(h, args, self->carg++);
self->ni = grib_arguments_get_name(h, args, self->carg++);
self->ni = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); self->nj = grib_arguments_get_name(h, args, self->carg++);
self->nj = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); self->list_defining_points = grib_arguments_get_name(h, args, self->carg++);
self->number_of_data_points = grib_arguments_get_name(h, args, self->carg++);
self->list_defining_points = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); self->scanning_mode = grib_arguments_get_name(h, args, self->carg++);
self->number_of_data_points = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
self->scanning_mode = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
a->flags |= GRIB_ACCESSOR_FLAG_DATA; a->flags |= GRIB_ACCESSOR_FLAG_DATA;
} }
static int value_count(grib_accessor* a, long* n_vals) static int value_count(grib_accessor* a, long* n_vals)
{ {
grib_accessor_data_png_packing* self = (grib_accessor_data_png_packing*)a; grib_accessor_data_png_packing* self = (grib_accessor_data_png_packing*)a;
*n_vals = 0; *n_vals = 0;
return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals); return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals);
} }
@ -228,10 +227,9 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
self->dirty = 0; self->dirty = 0;
err = grib_value_count(a, &nn); err = grib_value_count(a, &nn);
n_vals = nn; n_vals = nn;
if (err) if (err) return err;
return err;
if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS)
return err; return err;

View File

@ -8,11 +8,6 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/ */
/**************************************
* Enrico Fucile
**************************************/
#include "grib_scaling.h" #include "grib_scaling.h"
#include "grib_api_internal.h" #include "grib_api_internal.h"
/* /*
@ -116,13 +111,14 @@ grib_accessor_class* grib_accessor_class_simple_packing_error = &_grib_accessor_
static void init(grib_accessor* a, const long l, grib_arguments* c) static void init(grib_accessor* a, const long l, grib_arguments* c)
{ {
grib_accessor_simple_packing_error* self = (grib_accessor_simple_packing_error*)a; grib_accessor_simple_packing_error* self = (grib_accessor_simple_packing_error*)a;
int n = 0; int n = 0;
grib_handle* h = grib_handle_of_accessor(a);
self->bitsPerValue = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); self->bitsPerValue = grib_arguments_get_name(h, c, n++);
self->binaryScaleFactor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); self->binaryScaleFactor = grib_arguments_get_name(h, c, n++);
self->decimalScaleFactor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); self->decimalScaleFactor = grib_arguments_get_name(h, c, n++);
self->referenceValue = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); self->referenceValue = grib_arguments_get_name(h, c, n++);
self->floatType = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); self->floatType = grib_arguments_get_name(h, c, n++);
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
a->length = 0; a->length = 0;
@ -131,25 +127,23 @@ static void init(grib_accessor* a, const long l, grib_arguments* c)
static int unpack_double(grib_accessor* a, double* val, size_t* len) static int unpack_double(grib_accessor* a, double* val, size_t* len)
{ {
grib_accessor_simple_packing_error* self = (grib_accessor_simple_packing_error*)a; grib_accessor_simple_packing_error* self = (grib_accessor_simple_packing_error*)a;
int ret = 0;
long binaryScaleFactor = 0;
long bitsPerValue = 0;
long decimalScaleFactor = 0;
double referenceValue = 0;
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), int ret = 0;
self->binaryScaleFactor, &binaryScaleFactor)) != GRIB_SUCCESS) long binaryScaleFactor = 0;
long bitsPerValue = 0;
long decimalScaleFactor = 0;
double referenceValue = 0;
grib_handle* h = grib_handle_of_accessor(a);
if ((ret = grib_get_long_internal(h, self->binaryScaleFactor, &binaryScaleFactor)) != GRIB_SUCCESS)
return ret; return ret;
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), if ((ret = grib_get_long_internal(h, self->bitsPerValue, &bitsPerValue)) != GRIB_SUCCESS)
self->bitsPerValue, &bitsPerValue)) != GRIB_SUCCESS)
return ret; return ret;
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), if ((ret = grib_get_long_internal(h, self->decimalScaleFactor, &decimalScaleFactor)) != GRIB_SUCCESS)
self->decimalScaleFactor, &decimalScaleFactor)) != GRIB_SUCCESS)
return ret; return ret;
if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), if ((ret = grib_get_double_internal(h, self->referenceValue, &referenceValue)) != GRIB_SUCCESS)
self->referenceValue, &referenceValue)) != GRIB_SUCCESS)
return ret; return ret;
if (!strcmp(self->floatType, "ibm")) if (!strcmp(self->floatType, "ibm"))

View File

@ -22,5 +22,7 @@ ${tools_dir}/grib_dump -TA -O $input
id=`${tools_dir}/grib_get -TA -p identifier $input` id=`${tools_dir}/grib_get -TA -p identifier $input`
[ "$id" = "WRAP" ] [ "$id" = "WRAP" ]
echo 'print "[data]";' | ${tools_dir}/grib_filter -TA - $input
# Clean up # Clean up
rm -f $tempOut $tempRef $tempTxt rm -f $tempOut $tempRef $tempTxt