diff --git a/src/accessor/grib_accessor_class_abstract_vector.h b/src/accessor/grib_accessor_class_abstract_vector.h index a9393d065..408a58f46 100644 --- a/src/accessor/grib_accessor_class_abstract_vector.h +++ b/src/accessor/grib_accessor_class_abstract_vector.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_ascii.h b/src/accessor/grib_accessor_class_ascii.h index 05e5a85dd..1e06aa9da 100644 --- a/src/accessor/grib_accessor_class_ascii.h +++ b/src/accessor/grib_accessor_class_ascii.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_bit.h b/src/accessor/grib_accessor_class_bit.h index 1f818b398..ec0fed2c1 100644 --- a/src/accessor/grib_accessor_class_bit.h +++ b/src/accessor/grib_accessor_class_bit.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_bits.h b/src/accessor/grib_accessor_class_bits.h index 58787ff4c..246b89747 100644 --- a/src/accessor/grib_accessor_class_bits.h +++ b/src/accessor/grib_accessor_class_bits.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_bits_per_value.h b/src/accessor/grib_accessor_class_bits_per_value.h index b7995d794..7ccaf90f5 100644 --- a/src/accessor/grib_accessor_class_bits_per_value.h +++ b/src/accessor/grib_accessor_class_bits_per_value.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_bufr_elements_table.h b/src/accessor/grib_accessor_class_bufr_elements_table.h index 36c566622..3736c0d8e 100644 --- a/src/accessor/grib_accessor_class_bufr_elements_table.h +++ b/src/accessor/grib_accessor_class_bufr_elements_table.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h index d3da8f49f..9f508b5a9 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h +++ b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h index 05a4e83ae..977dc1104 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h +++ b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_bufr_group.h b/src/accessor/grib_accessor_class_bufr_group.h index 8b11dfb7c..320e326f1 100644 --- a/src/accessor/grib_accessor_class_bufr_group.h +++ b/src/accessor/grib_accessor_class_bufr_group.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_bufr_string_values.h b/src/accessor/grib_accessor_class_bufr_string_values.h index e794213a4..a566fd4d8 100644 --- a/src/accessor/grib_accessor_class_bufr_string_values.h +++ b/src/accessor/grib_accessor_class_bufr_string_values.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h b/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h index f8170e774..01fb97b98 100644 --- a/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h +++ b/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_bytes.h b/src/accessor/grib_accessor_class_bytes.h index d13c15c8a..3c33a4aac 100644 --- a/src/accessor/grib_accessor_class_bytes.h +++ b/src/accessor/grib_accessor_class_bytes.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_change_alternative_row_scanning.h b/src/accessor/grib_accessor_class_change_alternative_row_scanning.h index 85a375046..885ca06dc 100644 --- a/src/accessor/grib_accessor_class_change_alternative_row_scanning.h +++ b/src/accessor/grib_accessor_class_change_alternative_row_scanning.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_change_scanning_direction.h b/src/accessor/grib_accessor_class_change_scanning_direction.h index f3eccdc61..72c3387a6 100644 --- a/src/accessor/grib_accessor_class_change_scanning_direction.h +++ b/src/accessor/grib_accessor_class_change_scanning_direction.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_check_internal_version.h b/src/accessor/grib_accessor_class_check_internal_version.h index b3edc0ee0..70517c33f 100644 --- a/src/accessor/grib_accessor_class_check_internal_version.h +++ b/src/accessor/grib_accessor_class_check_internal_version.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_closest_date.h b/src/accessor/grib_accessor_class_closest_date.h index 79c84d291..8e2a7a254 100644 --- a/src/accessor/grib_accessor_class_closest_date.h +++ b/src/accessor/grib_accessor_class_closest_date.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_codeflag.h b/src/accessor/grib_accessor_class_codeflag.h index af055fd2f..1cdbfa561 100644 --- a/src/accessor/grib_accessor_class_codeflag.h +++ b/src/accessor/grib_accessor_class_codeflag.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_codetable_title.h b/src/accessor/grib_accessor_class_codetable_title.h index 2d4da16ed..728aa4e23 100644 --- a/src/accessor/grib_accessor_class_codetable_title.h +++ b/src/accessor/grib_accessor_class_codetable_title.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_codetable_units.h b/src/accessor/grib_accessor_class_codetable_units.h index f2da99da5..6d1410f0a 100644 --- a/src/accessor/grib_accessor_class_codetable_units.h +++ b/src/accessor/grib_accessor_class_codetable_units.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_concept.cc b/src/accessor/grib_accessor_class_concept.cc index 8f8bf869b..249dde888 100644 --- a/src/accessor/grib_accessor_class_concept.cc +++ b/src/accessor/grib_accessor_class_concept.cc @@ -272,18 +272,84 @@ bool blacklisted(grib_handle* h, long edition, const char* concept_name, const c return false; } +static void print_user_friendly_message(grib_handle* h, const char* name, grib_concept_value* concepts, grib_action* act) +{ + size_t i = 0, concept_count = 0; + long dummy = 0, editionNumber = 0; + char centre_s[32] = {0,}; + size_t centre_len = sizeof(centre_s); + char* all_concept_vals[MAX_NUM_CONCEPT_VALUES] = {NULL,}; /* sorted array containing concept values */ + grib_concept_value* pCon = concepts; + + grib_context_log(h->context, GRIB_LOG_ERROR, "concept: no match for %s=%s", act->name, name); + if (grib_get_long(h, "edition", &editionNumber) == GRIB_SUCCESS && + grib_get_string(h, "centre", centre_s, ¢re_len) == GRIB_SUCCESS) { + grib_context_log(h->context, GRIB_LOG_ERROR, "concept: input handle edition=%ld, centre=%s", editionNumber, centre_s); + } + char dataset_s[80]; + size_t dataset_len = sizeof(dataset_s); + if (grib_get_string(h, "datasetForLocal", dataset_s, &dataset_len) == GRIB_SUCCESS && !STR_EQUAL(dataset_s, "unknown")) { + grib_context_log(h->context, GRIB_LOG_ERROR, "concept: input handle dataset=%s", dataset_s); + } + if (strcmp(act->name, "paramId") == 0) { + if (string_to_long(name, &dummy, 1) == GRIB_SUCCESS) { + // The paramId value is an integer. Show them the param DB + grib_context_log(h->context, GRIB_LOG_ERROR, + "Please check the Parameter Database 'https://codes.ecmwf.int/grib/param-db/?id=%s'", name); + } + else { + // paramId being set to a non-integer + grib_context_log(h->context, GRIB_LOG_ERROR, + "The paramId value should be an integer. Are you trying to set the shortName?"); + } + } + if (strcmp(act->name, "shortName") == 0) { + grib_context_log(h->context, GRIB_LOG_ERROR, + "Please check the Parameter Database 'https://codes.ecmwf.int/grib/param-db/'"); + } + + // Create a list of all possible values for this concept and sort it + while (pCon) { + if (i >= MAX_NUM_CONCEPT_VALUES) + break; + all_concept_vals[i++] = pCon->name; + pCon = pCon->next; + } + concept_count = i; + // Only print out all concepts if fewer than MAX_NUM_CONCEPT_VALUES. + // Printing out all values for concepts like paramId would be silly! + if (concept_count < MAX_NUM_CONCEPT_VALUES) { + fprintf(stderr, "Here are some possible values for concept %s:\n", act->name); + qsort(&all_concept_vals, concept_count, sizeof(char*), cmpstringp); + for (i = 0; i < concept_count; ++i) { + if (all_concept_vals[i]) { + bool print_it = true; + if (i > 0 && all_concept_vals[i - 1] && strcmp(all_concept_vals[i], all_concept_vals[i - 1]) == 0) { + print_it = false; // skip duplicate entries + } + if (blacklisted(h, editionNumber, act->name, all_concept_vals[i])) { + print_it = false; + } + if (print_it) { + fprintf(stderr, "\t%s\n", all_concept_vals[i]); + } + } + } + } +} + static int grib_concept_apply(grib_accessor* a, const char* name) { - int err = 0; - int count = 0; + int err = 0; + int count = 0; grib_concept_condition* e = NULL; - grib_values values[1024]; - grib_sarray* sa = NULL; - grib_concept_value* c = NULL; + grib_values values[1024] = {{0},}; // key/value pair array + grib_sarray* sa = NULL; + grib_concept_value* c = NULL; grib_concept_value* concepts = action_concept_get_concept(a); - grib_handle* h = grib_handle_of_accessor(a); - grib_action* act = a->creator_; - int nofail = action_concept_get_nofail(a); + grib_handle* h = grib_handle_of_accessor(a); + grib_action* act = a->creator_; + const int nofail = action_concept_get_nofail(a); DEBUG_ASSERT(concepts); @@ -295,70 +361,7 @@ static int grib_concept_apply(grib_accessor* a, const char* name) if (!c) { err = nofail ? GRIB_SUCCESS : GRIB_CONCEPT_NO_MATCH; if (err) { - size_t i = 0, concept_count = 0; - long dummy = 0, editionNumber = 0; - char centre_s[32] = {0,}; - size_t centre_len = sizeof(centre_s); - char* all_concept_vals[MAX_NUM_CONCEPT_VALUES] = { - NULL, - }; /* sorted array containing concept values */ - grib_concept_value* pCon = concepts; - - grib_context_log(h->context, GRIB_LOG_ERROR, "concept: no match for %s=%s", act->name, name); - if (grib_get_long(h, "edition", &editionNumber) == GRIB_SUCCESS && - grib_get_string(h, "centre", centre_s, ¢re_len) == GRIB_SUCCESS) { - grib_context_log(h->context, GRIB_LOG_ERROR, "concept: input handle edition=%ld, centre=%s", editionNumber, centre_s); - } - char dataset_s[80]; - size_t dataset_len = sizeof(dataset_s); - if (grib_get_string(h, "datasetForLocal", dataset_s, &dataset_len) == GRIB_SUCCESS && !STR_EQUAL(dataset_s, "unknown")) { - grib_context_log(h->context, GRIB_LOG_ERROR, "concept: input handle dataset=%s", dataset_s); - } - if (strcmp(act->name, "paramId") == 0) { - if (string_to_long(name, &dummy, 1) == GRIB_SUCCESS) { - // The paramId value is an integer. Show them the param DB - grib_context_log(h->context, GRIB_LOG_ERROR, - "Please check the Parameter Database 'https://codes.ecmwf.int/grib/param-db/?id=%s'", name); - } - else { - // paramId being set to a non-integer - grib_context_log(h->context, GRIB_LOG_ERROR, - "The paramId value should be an integer. Are you trying to set the shortName?"); - } - } - if (strcmp(act->name, "shortName") == 0) { - grib_context_log(h->context, GRIB_LOG_ERROR, - "Please check the Parameter Database 'https://codes.ecmwf.int/grib/param-db/'"); - } - - /* Create a list of all possible values for this concept and sort it */ - while (pCon) { - if (i >= MAX_NUM_CONCEPT_VALUES) - break; - all_concept_vals[i++] = pCon->name; - pCon = pCon->next; - } - concept_count = i; - /* Only print out all concepts if fewer than MAX_NUM_CONCEPT_VALUES. - * Printing out all values for concepts like paramId would be silly! */ - if (concept_count < MAX_NUM_CONCEPT_VALUES) { - fprintf(stderr, "Here are some possible values for concept %s:\n", act->name); - qsort(&all_concept_vals, concept_count, sizeof(char*), cmpstringp); - for (i = 0; i < concept_count; ++i) { - if (all_concept_vals[i]) { - bool print_it = true; - if (i > 0 && all_concept_vals[i - 1] && strcmp(all_concept_vals[i], all_concept_vals[i - 1]) == 0) { - print_it = false; /* skip duplicate entries */ - } - if (blacklisted(h, editionNumber, act->name, all_concept_vals[i])) { - print_it = false; - } - if (print_it) { - fprintf(stderr, "\t%s\n", all_concept_vals[i]); - } - } - } - } + print_user_friendly_message(h, name, concepts, act); } return err; } @@ -370,8 +373,49 @@ static int grib_concept_apply(grib_accessor* a, const char* name) } grib_sarray_delete(sa); - if (count) - err = grib_set_values(h, values, count); + if (count) { + err = grib_set_values_silent(h, values, count, /*silent=*/1); + if (err) { + // GRIB2 product template selection + bool resubmit = false; + for (int i = 0; i < count; i++) { + if (values[i].error == GRIB_NOT_FOUND) { + // Repair the most common cause of failure: input GRIB2 handle + // is instantaneous but paramId/shortName being set is for accum/avg etc + if (STR_EQUAL(values[i].name, "typeOfStatisticalProcessing")) { + grib_context_log(h->context, GRIB_LOG_DEBUG, "%s: Switch from instantaneous to interval-based", __func__); + if (grib_set_long(h, "selectStepTemplateInterval", 1) == GRIB_SUCCESS) { + resubmit = true; + grib_set_values(h, &values[i], 1); + } + } + // else if (STR_EQUAL(values[i].name, "sourceSinkChemicalPhysicalProcess")) { + // if (grib_set_long(h, "is_chemical_srcsink", 1) == GRIB_SUCCESS) { + // resubmit = true; + // grib_set_values(h, &values[i], 1); + // } + // } + } + } + + if (resubmit) { + grib_context_log(h->context, GRIB_LOG_DEBUG, "%s: Resubmitting key/values", __func__); + err = grib_set_values(h, values, count); + } + } + } + //grib_print_values("DEBUG grib_concept_apply", values, stdout, count); + if (err) { + for (int i = 0; i < count; i++) { + if (values[i].error != GRIB_SUCCESS) { + grib_context_log(h->context, GRIB_LOG_ERROR, + "grib_set_values[%d] %s (type=%s) failed: %s", + i, values[i].name, grib_get_type_name(values[i].type), + grib_get_error_message(values[i].error)); + } + } + } + return err; } diff --git a/src/accessor/grib_accessor_class_concept.h b/src/accessor/grib_accessor_class_concept.h index b04cc4cb2..cf89b19b5 100644 --- a/src/accessor/grib_accessor_class_concept.h +++ b/src/accessor/grib_accessor_class_concept.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_count_file.h b/src/accessor/grib_accessor_class_count_file.h index 0dec594fb..8f1ef4919 100644 --- a/src/accessor/grib_accessor_class_count_file.h +++ b/src/accessor/grib_accessor_class_count_file.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_count_missing.h b/src/accessor/grib_accessor_class_count_missing.h index 78debfeb1..0c1e8207f 100644 --- a/src/accessor/grib_accessor_class_count_missing.h +++ b/src/accessor/grib_accessor_class_count_missing.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_count_total.h b/src/accessor/grib_accessor_class_count_total.h index 6f4e9020c..2f6dcaad9 100644 --- a/src/accessor/grib_accessor_class_count_total.h +++ b/src/accessor/grib_accessor_class_count_total.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_data_jpeg2000_packing.cc b/src/accessor/grib_accessor_class_data_jpeg2000_packing.cc index 7a98e6725..55bf9ea8a 100644 --- a/src/accessor/grib_accessor_class_data_jpeg2000_packing.cc +++ b/src/accessor/grib_accessor_class_data_jpeg2000_packing.cc @@ -94,6 +94,8 @@ int grib_accessor_data_jpeg2000_packing_t::unpack_float(float* val, size_t* len) int grib_accessor_data_jpeg2000_packing_t::unpack_double(double* val, size_t* len) { int err = GRIB_SUCCESS; + grib_handle* hand = grib_handle_of_accessor(this); + size_t i = 0; size_t buflen = byte_count(); double bscale = 0; @@ -116,18 +118,18 @@ int grib_accessor_data_jpeg2000_packing_t::unpack_double(double* val, size_t* le return err; if (units_factor_) - grib_get_double_internal(grib_handle_of_accessor(this), units_factor_, &units_factor); + grib_get_double_internal(hand, units_factor_, &units_factor); if (units_bias_) - grib_get_double_internal(grib_handle_of_accessor(this), units_bias_, &units_bias); + grib_get_double_internal(hand, units_bias_, &units_bias); - if ((err = grib_get_long_internal(grib_handle_of_accessor(this), bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(grib_handle_of_accessor(this), reference_value_, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(hand, reference_value_, &reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(this), binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(this), decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; dirty_ = 0; @@ -194,7 +196,6 @@ int grib_accessor_data_jpeg2000_packing_t::pack_double(const double* cval, size_ { size_t n_vals = *len; int err = 0; - int i; double reference_value = 0; long binary_scale_factor = 0; long bits_per_value = 0; @@ -237,14 +238,14 @@ int grib_accessor_data_jpeg2000_packing_t::pack_double(const double* cval, size_ if (units_factor != 1.0) { if (units_bias != 0.0) - for (i = 0; i < n_vals; i++) + for (size_t i = 0; i < n_vals; i++) val[i] = val[i] * units_factor + units_bias; else - for (i = 0; i < n_vals; i++) + for (size_t i = 0; i < n_vals; i++) val[i] *= units_factor; } else if (units_bias != 0.0) - for (i = 0; i < n_vals; i++) + for (size_t i = 0; i < n_vals; i++) val[i] += units_bias; ret = grib_accessor_data_simple_packing_t::pack_double(val, len); diff --git a/src/accessor/grib_accessor_class_double.h b/src/accessor/grib_accessor_class_double.h index 539d550ee..cde2e0c50 100644 --- a/src/accessor/grib_accessor_class_double.h +++ b/src/accessor/grib_accessor_class_double.h @@ -17,7 +17,7 @@ class grib_accessor_double_t : public grib_accessor_gen_t public: grib_accessor_double_t() : grib_accessor_gen_t() { class_name_ = "double"; } - grib_accessor* create_empty_accessor() override { return new grib_accessor_double_t{}; } + // grib_accessor* create_empty_accessor() override { return new grib_accessor_double_t{}; } long get_native_type() override; int pack_missing() override; int unpack_string(char*, size_t* len) override; diff --git a/src/accessor/grib_accessor_class_evaluate.cc b/src/accessor/grib_accessor_class_evaluate.cc index a8158ee96..9cca2b034 100644 --- a/src/accessor/grib_accessor_class_evaluate.cc +++ b/src/accessor/grib_accessor_class_evaluate.cc @@ -16,15 +16,16 @@ grib_accessor* grib_accessor_evaluate = &_grib_accessor_evaluate; void grib_accessor_evaluate_t::init(const long l, grib_arguments* c) { grib_accessor_long_t::init(l, c); - arg_ = c; + arg_ = c; // the expression to be evaluated flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } int grib_accessor_evaluate_t::unpack_long(long* val, size_t* len) { - grib_expression* e = grib_arguments_get_expression(grib_handle_of_accessor(this), arg_, 0); + grib_handle* h = grib_handle_of_accessor(this); + grib_expression* e = grib_arguments_get_expression(h, arg_, 0); - int ret = grib_expression_evaluate_long(grib_handle_of_accessor(this), e, val); + int ret = grib_expression_evaluate_long(h, e, val); *len = 1; return ret; diff --git a/src/accessor/grib_accessor_class_evaluate.h b/src/accessor/grib_accessor_class_evaluate.h index 53f5420ae..aa76049bf 100644 --- a/src/accessor/grib_accessor_class_evaluate.h +++ b/src/accessor/grib_accessor_class_evaluate.h @@ -22,5 +22,5 @@ public: void init(const long, grib_arguments*) override; protected: - grib_arguments* arg_; + grib_arguments* arg_; // expression to be evaluated }; diff --git a/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.h b/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.h index 7398083fa..2b8e6372a 100644 --- a/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.h +++ b/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g1_half_byte_codeflag.h b/src/accessor/grib_accessor_class_g1_half_byte_codeflag.h index b751be642..9b70ac93a 100644 --- a/src/accessor/grib_accessor_class_g1_half_byte_codeflag.h +++ b/src/accessor/grib_accessor_class_g1_half_byte_codeflag.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g1_message_length.h b/src/accessor/grib_accessor_class_g1_message_length.h index 226fabf3a..95335a67e 100644 --- a/src/accessor/grib_accessor_class_g1_message_length.h +++ b/src/accessor/grib_accessor_class_g1_message_length.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g1_section4_length.h b/src/accessor/grib_accessor_class_g1_section4_length.h index a7407d063..5a0eb4ee0 100644 --- a/src/accessor/grib_accessor_class_g1_section4_length.h +++ b/src/accessor/grib_accessor_class_g1_section4_length.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g1bitmap.h b/src/accessor/grib_accessor_class_g1bitmap.h index 7c509662c..e7fb884e4 100644 --- a/src/accessor/grib_accessor_class_g1bitmap.h +++ b/src/accessor/grib_accessor_class_g1bitmap.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g1date.h b/src/accessor/grib_accessor_class_g1date.h index f4195215f..9186e2f49 100644 --- a/src/accessor/grib_accessor_class_g1date.h +++ b/src/accessor/grib_accessor_class_g1date.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g1day_of_the_year_date.h b/src/accessor/grib_accessor_class_g1day_of_the_year_date.h index b2ea10c49..372114ff0 100644 --- a/src/accessor/grib_accessor_class_g1day_of_the_year_date.h +++ b/src/accessor/grib_accessor_class_g1day_of_the_year_date.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g1end_of_interval_monthly.h b/src/accessor/grib_accessor_class_g1end_of_interval_monthly.h index 462fb7c8f..28dbfb4a0 100644 --- a/src/accessor/grib_accessor_class_g1end_of_interval_monthly.h +++ b/src/accessor/grib_accessor_class_g1end_of_interval_monthly.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g1fcperiod.h b/src/accessor/grib_accessor_class_g1fcperiod.h index e609853b9..8943966dc 100644 --- a/src/accessor/grib_accessor_class_g1fcperiod.h +++ b/src/accessor/grib_accessor_class_g1fcperiod.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g1forecastmonth.h b/src/accessor/grib_accessor_class_g1forecastmonth.h index 9737eb16a..1d3f8569b 100644 --- a/src/accessor/grib_accessor_class_g1forecastmonth.h +++ b/src/accessor/grib_accessor_class_g1forecastmonth.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g1monthlydate.h b/src/accessor/grib_accessor_class_g1monthlydate.h index 8c904c524..a46aa000a 100644 --- a/src/accessor/grib_accessor_class_g1monthlydate.h +++ b/src/accessor/grib_accessor_class_g1monthlydate.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.h b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.h index f14604d8f..757358d5a 100644 --- a/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.h +++ b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.h b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.h index 0619a72dd..1f7c15a2a 100644 --- a/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.h +++ b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g1step_range.h b/src/accessor/grib_accessor_class_g1step_range.h index 29858ce1a..a76bd520c 100644 --- a/src/accessor/grib_accessor_class_g1step_range.h +++ b/src/accessor/grib_accessor_class_g1step_range.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g1verificationdate.h b/src/accessor/grib_accessor_class_g1verificationdate.h index 5e1f0ac24..0b1abf641 100644 --- a/src/accessor/grib_accessor_class_g1verificationdate.h +++ b/src/accessor/grib_accessor_class_g1verificationdate.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g2_aerosol.h b/src/accessor/grib_accessor_class_g2_aerosol.h index f50542862..3f02da7a5 100644 --- a/src/accessor/grib_accessor_class_g2_aerosol.h +++ b/src/accessor/grib_accessor_class_g2_aerosol.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g2_chemical.h b/src/accessor/grib_accessor_class_g2_chemical.h index 68d7ece7c..7ceece9c5 100644 --- a/src/accessor/grib_accessor_class_g2_chemical.h +++ b/src/accessor/grib_accessor_class_g2_chemical.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g2_eps.h b/src/accessor/grib_accessor_class_g2_eps.h index a4bfb818b..646b29349 100644 --- a/src/accessor/grib_accessor_class_g2_eps.h +++ b/src/accessor/grib_accessor_class_g2_eps.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g2_mars_labeling.h b/src/accessor/grib_accessor_class_g2_mars_labeling.h index 7655fd60d..11c1178c3 100644 --- a/src/accessor/grib_accessor_class_g2_mars_labeling.h +++ b/src/accessor/grib_accessor_class_g2_mars_labeling.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g2bitmap.h b/src/accessor/grib_accessor_class_g2bitmap.h index c305fb494..0bc1e1cf5 100644 --- a/src/accessor/grib_accessor_class_g2bitmap.h +++ b/src/accessor/grib_accessor_class_g2bitmap.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g2end_step.cc b/src/accessor/grib_accessor_class_g2end_step.cc index 002a07779..c175ebe88 100644 --- a/src/accessor/grib_accessor_class_g2end_step.cc +++ b/src/accessor/grib_accessor_class_g2end_step.cc @@ -403,8 +403,8 @@ int grib_accessor_g2end_step_t::unpack_double(double* val, size_t* len) int grib_accessor_g2end_step_t::pack_long_(const long end_step_value, const long end_step_unit) { - grib_handle* h = grib_handle_of_accessor(this); - int err = 0; + grib_handle* h = grib_handle_of_accessor(this); + int err = 0; long year; long month; @@ -527,13 +527,13 @@ int grib_accessor_g2end_step_t::pack_long_(const long end_step_value, const long time_range_opt = eccodes::Step{ time_range.value(eccodes::Unit{ force_step_units }), eccodes::Unit{ force_step_units } }; } - if ((err = grib_set_long_internal(grib_handle_of_accessor(this), time_range_value_, time_range_opt.value())) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(h, time_range_value_, time_range_opt.value())) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(grib_handle_of_accessor(this), time_range_unit_, time_range_opt.unit().value())) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(h, time_range_unit_, time_range_opt.unit().value())) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(grib_handle_of_accessor(this), forecast_time_value_key, forecast_time_opt.value())) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(h, forecast_time_value_key, forecast_time_opt.value())) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(grib_handle_of_accessor(this), forecast_time_unit_key, forecast_time_opt.unit().value())) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(h, forecast_time_unit_key, forecast_time_opt.unit().value())) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; @@ -639,7 +639,7 @@ int grib_accessor_g2end_step_t::pack_string(const char* val, size_t* len) long grib_accessor_g2end_step_t::get_native_type() { - grib_handle* h = grib_handle_of_accessor(this); + grib_handle* h = grib_handle_of_accessor(this); const int show_units_for_hours = context_->grib_hourly_steps_with_units; if (!show_units_for_hours) { diff --git a/src/accessor/grib_accessor_class_g2end_step.h b/src/accessor/grib_accessor_class_g2end_step.h index d66a01d5e..18a9a78ee 100644 --- a/src/accessor/grib_accessor_class_g2end_step.h +++ b/src/accessor/grib_accessor_class_g2end_step.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g2grid.h b/src/accessor/grib_accessor_class_g2grid.h index 07fc48fc0..8ec82e7a6 100644 --- a/src/accessor/grib_accessor_class_g2grid.h +++ b/src/accessor/grib_accessor_class_g2grid.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g2latlon.h b/src/accessor/grib_accessor_class_g2latlon.h index 2bcd564b7..b7e5537c7 100644 --- a/src/accessor/grib_accessor_class_g2latlon.h +++ b/src/accessor/grib_accessor_class_g2latlon.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g2level.h b/src/accessor/grib_accessor_class_g2level.h index e51fef38d..50fc6d0d1 100644 --- a/src/accessor/grib_accessor_class_g2level.h +++ b/src/accessor/grib_accessor_class_g2level.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_g2lon.h b/src/accessor/grib_accessor_class_g2lon.h index b78cab8dc..a781f666a 100644 --- a/src/accessor/grib_accessor_class_g2lon.h +++ b/src/accessor/grib_accessor_class_g2lon.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_global_gaussian.h b/src/accessor/grib_accessor_class_global_gaussian.h index ebb59b6b6..6a3517784 100644 --- a/src/accessor/grib_accessor_class_global_gaussian.h +++ b/src/accessor/grib_accessor_class_global_gaussian.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_group.h b/src/accessor/grib_accessor_class_group.h index dc6bb1822..ad6146c61 100644 --- a/src/accessor/grib_accessor_class_group.h +++ b/src/accessor/grib_accessor_class_group.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_gts_header.h b/src/accessor/grib_accessor_class_gts_header.h index 81a58ba4b..f1718fb36 100644 --- a/src/accessor/grib_accessor_class_gts_header.h +++ b/src/accessor/grib_accessor_class_gts_header.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_hash_array.h b/src/accessor/grib_accessor_class_hash_array.h index 9dabd2db8..69b4bedc8 100644 --- a/src/accessor/grib_accessor_class_hash_array.h +++ b/src/accessor/grib_accessor_class_hash_array.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_headers_only.h b/src/accessor/grib_accessor_class_headers_only.h index 3ca33f2a6..e0637317d 100644 --- a/src/accessor/grib_accessor_class_headers_only.h +++ b/src/accessor/grib_accessor_class_headers_only.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_julian_day.cc b/src/accessor/grib_accessor_class_julian_day.cc index 3183ef60a..7b22252a0 100644 --- a/src/accessor/grib_accessor_class_julian_day.cc +++ b/src/accessor/grib_accessor_class_julian_day.cc @@ -17,11 +17,12 @@ void grib_accessor_julian_day_t::init(const long l, grib_arguments* c) { grib_accessor_double_t::init(l, c); int n = 0; + grib_handle* h = grib_handle_of_accessor(this); - date_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - hour_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - minute_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - second_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + date_ = grib_arguments_get_name(h, c, n++); + hour_ = grib_arguments_get_name(h, c, n++); + minute_ = grib_arguments_get_name(h, c, n++); + second_ = grib_arguments_get_name(h, c, n++); length_ = 0; } @@ -39,29 +40,27 @@ int grib_accessor_julian_day_t::pack_long(const long* val, size_t* len) int grib_accessor_julian_day_t::pack_double(const double* val, size_t* len) { - int ret = 0; - long hour = 0; - long minute = 0; - long second = 0; - long date = 0; - long year, month, day; + int ret = GRIB_SUCCESS; + long hour = 0, minute = 0, second = 0; + long year = 0, month = 0, day = 0; + grib_handle* h = grib_handle_of_accessor(this); ret = grib_julian_to_datetime(*val, &year, &month, &day, &hour, &minute, &second); if (ret != 0) return ret; - date = year * 10000 + month * 100 + day; + long date = year * 10000 + month * 100 + day; - ret = grib_set_long_internal(grib_handle_of_accessor(this), date_, date); + ret = grib_set_long_internal(h, date_, date); if (ret != 0) return ret; - ret = grib_set_long_internal(grib_handle_of_accessor(this), hour_, hour); + ret = grib_set_long_internal(h, hour_, hour); if (ret != 0) return ret; - ret = grib_set_long_internal(grib_handle_of_accessor(this), minute_, minute); + ret = grib_set_long_internal(h, minute_, minute); if (ret != 0) return ret; - ret = grib_set_long_internal(grib_handle_of_accessor(this), second_, second); + ret = grib_set_long_internal(h, second_, second); return ret; } @@ -82,17 +81,18 @@ int grib_accessor_julian_day_t::unpack_double(double* val, size_t* len) int ret = 0; long date, hour, minute, second; long year, month, day; + grib_handle* h = grib_handle_of_accessor(this); - ret = grib_get_long_internal(grib_handle_of_accessor(this), date_, &date); + ret = grib_get_long_internal(h, date_, &date); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long_internal(grib_handle_of_accessor(this), hour_, &hour); + ret = grib_get_long_internal(h, hour_, &hour); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long_internal(grib_handle_of_accessor(this), minute_, &minute); + ret = grib_get_long_internal(h, minute_, &minute); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long_internal(grib_handle_of_accessor(this), second_, &second); + ret = grib_get_long_internal(h, second_, &second); if (ret != GRIB_SUCCESS) return ret; diff --git a/src/accessor/grib_accessor_class_long.h b/src/accessor/grib_accessor_class_long.h index 98f54ee09..bce7dd9e9 100644 --- a/src/accessor/grib_accessor_class_long.h +++ b/src/accessor/grib_accessor_class_long.h @@ -17,7 +17,7 @@ class grib_accessor_long_t : public grib_accessor_gen_t public: grib_accessor_long_t() : grib_accessor_gen_t() { class_name_ = "long"; } - grib_accessor* create_empty_accessor() override { return new grib_accessor_long_t{}; } + // grib_accessor* create_empty_accessor() override { return new grib_accessor_long_t{}; } void init(const long len, grib_arguments* arg) override; long get_native_type() override; int pack_missing() override; diff --git a/src/accessor/grib_accessor_class_number_of_coded_values.cc b/src/accessor/grib_accessor_class_number_of_coded_values.cc index 36a699516..4ca9d4c2b 100644 --- a/src/accessor/grib_accessor_class_number_of_coded_values.cc +++ b/src/accessor/grib_accessor_class_number_of_coded_values.cc @@ -16,12 +16,14 @@ grib_accessor* grib_accessor_number_of_coded_values = &_grib_accessor_number_of_ void grib_accessor_number_of_coded_values_t::init(const long l, grib_arguments* c) { grib_accessor_long_t::init(l, c); + grib_handle* h = grib_handle_of_accessor(this); + int n = 0; - bitsPerValue_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - offsetBeforeData_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - offsetAfterData_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - unusedBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - numberOfValues_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + bitsPerValue_ = grib_arguments_get_name(h, c, n++); + offsetBeforeData_ = grib_arguments_get_name(h, c, n++); + offsetAfterData_ = grib_arguments_get_name(h, c, n++); + unusedBits_ = grib_arguments_get_name(h, c, n++); + numberOfValues_ = grib_arguments_get_name(h, c, n++); flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; length_ = 0; @@ -29,30 +31,31 @@ void grib_accessor_number_of_coded_values_t::init(const long l, grib_arguments* int grib_accessor_number_of_coded_values_t::unpack_long(long* val, size_t* len) { - int ret = GRIB_SUCCESS; - long bpv = 0; - long offsetBeforeData = 0, offsetAfterData = 0, unusedBits = 0, numberOfValues; + int ret = GRIB_SUCCESS; + long bpv = 0, offsetBeforeData = 0, offsetAfterData = 0, unusedBits = 0, numberOfValues; + grib_handle* h = grib_handle_of_accessor(this); - if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), bitsPerValue_, &bpv)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, bitsPerValue_, &bpv)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetBeforeData_, &offsetBeforeData)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, offsetBeforeData_, &offsetBeforeData)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetAfterData_, &offsetAfterData)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, offsetAfterData_, &offsetAfterData)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), unusedBits_, &unusedBits)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, unusedBits_, &unusedBits)) != GRIB_SUCCESS) return ret; if (bpv != 0) { - grib_context_log(context_, GRIB_LOG_DEBUG, "grib_accessor_number_of_coded_values_t: offsetAfterData=%ld offsetBeforeData=%ld unusedBits=%ld bpv=%ld\n", - offsetAfterData, offsetBeforeData, unusedBits, bpv); + grib_context_log(context_, GRIB_LOG_DEBUG, + "grib_accessor_number_of_coded_values_t: offsetAfterData=%ld offsetBeforeData=%ld unusedBits=%ld bpv=%ld", + offsetAfterData, offsetBeforeData, unusedBits, bpv); DEBUG_ASSERT(offsetAfterData > offsetBeforeData); *val = ((offsetAfterData - offsetBeforeData) * 8 - unusedBits) / bpv; } else { - if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfValues_, &numberOfValues)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, numberOfValues_, &numberOfValues)) != GRIB_SUCCESS) return ret; *val = numberOfValues; diff --git a/src/accessor/grib_accessor_class_padding.h b/src/accessor/grib_accessor_class_padding.h index 5b3e64f2b..ac0c37d14 100644 --- a/src/accessor/grib_accessor_class_padding.h +++ b/src/accessor/grib_accessor_class_padding.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -18,7 +17,7 @@ class grib_accessor_padding_t : public grib_accessor_bytes_t public: grib_accessor_padding_t() : grib_accessor_bytes_t() { class_name_ = "padding"; } - grib_accessor* create_empty_accessor() override { return new grib_accessor_padding_t{}; } + //grib_accessor* create_empty_accessor() override { return new grib_accessor_padding_t{}; } size_t string_length() override; long byte_count() override; int value_count(long*) override; diff --git a/src/accessor/grib_accessor_class_statistics_spectral.cc b/src/accessor/grib_accessor_class_statistics_spectral.cc index 033dfb692..5a092e25b 100644 --- a/src/accessor/grib_accessor_class_statistics_spectral.cc +++ b/src/accessor/grib_accessor_class_statistics_spectral.cc @@ -17,12 +17,13 @@ void grib_accessor_statistics_spectral_t::init(const long l, grib_arguments* c) { grib_accessor_abstract_vector_t::init(l, c); int n = 0; + grib_handle* h = grib_handle_of_accessor(this); - values_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - J_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - K_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - M_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - JS_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + values_ = grib_arguments_get_name(h, c, n++); + J_ = grib_arguments_get_name(h, c, n++); + K_ = grib_arguments_get_name(h, c, n++); + M_ = grib_arguments_get_name(h, c, n++); + JS_ = grib_arguments_get_name(h, c, n++); flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; @@ -53,13 +54,13 @@ int grib_accessor_statistics_spectral_t::unpack_double(double* val, size_t* len) if ((ret = grib_get_size(h, values_, &size)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long(grib_handle_of_accessor(this), J_, &J)) != GRIB_SUCCESS) + if ((ret = grib_get_long(h, J_, &J)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long(grib_handle_of_accessor(this), K_, &K)) != GRIB_SUCCESS) + if ((ret = grib_get_long(h, K_, &K)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long(grib_handle_of_accessor(this), M_, &M)) != GRIB_SUCCESS) + if ((ret = grib_get_long(h, M_, &M)) != GRIB_SUCCESS) return ret; if (J != M || M != K) @@ -114,7 +115,7 @@ int grib_accessor_statistics_spectral_t::unpack_double(double* val, size_t* len) int grib_accessor_statistics_spectral_t::value_count(long* count) { *count = number_of_elements_; - return 0; + return GRIB_SUCCESS; } void grib_accessor_statistics_spectral_t::destroy(grib_context* c) diff --git a/src/accessor/grib_accessor_class_time.h b/src/accessor/grib_accessor_class_time.h index d73427a84..dfa439ee2 100644 --- a/src/accessor/grib_accessor_class_time.h +++ b/src/accessor/grib_accessor_class_time.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_to_double.h b/src/accessor/grib_accessor_class_to_double.h index 02fd4f6a6..cbf3af18a 100644 --- a/src/accessor/grib_accessor_class_to_double.h +++ b/src/accessor/grib_accessor_class_to_double.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_trim.h b/src/accessor/grib_accessor_class_trim.h index f0a0a552a..34337ee48 100644 --- a/src/accessor/grib_accessor_class_trim.h +++ b/src/accessor/grib_accessor_class_trim.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_uint8.h b/src/accessor/grib_accessor_class_uint8.h index 948f75d9e..ab5601a20 100644 --- a/src/accessor/grib_accessor_class_uint8.h +++ b/src/accessor/grib_accessor_class_uint8.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_unexpanded_descriptors.h b/src/accessor/grib_accessor_class_unexpanded_descriptors.h index 6aed3eb8e..bc25ef6e4 100644 --- a/src/accessor/grib_accessor_class_unexpanded_descriptors.h +++ b/src/accessor/grib_accessor_class_unexpanded_descriptors.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_validity_time.h b/src/accessor/grib_accessor_class_validity_time.h index f3e8cb608..2c72ebd83 100644 --- a/src/accessor/grib_accessor_class_validity_time.h +++ b/src/accessor/grib_accessor_class_validity_time.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/accessor/grib_accessor_class_values.h b/src/accessor/grib_accessor_class_values.h index 6a40e16f2..b8c30cd65 100644 --- a/src/accessor/grib_accessor_class_values.h +++ b/src/accessor/grib_accessor_class_values.h @@ -17,7 +17,7 @@ class grib_accessor_values_t : public grib_accessor_gen_t public: grib_accessor_values_t() : grib_accessor_gen_t() { class_name_ = "values"; } - grib_accessor* create_empty_accessor() override { return new grib_accessor_values_t{}; } + // grib_accessor* create_empty_accessor() override { return new grib_accessor_values_t{}; } long get_native_type() override; int pack_long(const long* val, size_t* len) override; long byte_count() override; diff --git a/src/accessor/grib_accessor_class_when.h b/src/accessor/grib_accessor_class_when.h index b330a9246..ae8f89ccc 100644 --- a/src/accessor/grib_accessor_class_when.h +++ b/src/accessor/grib_accessor_class_when.h @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * diff --git a/src/grib_gaussian_N1280.h b/src/grib_gaussian_N1280.h new file mode 100644 index 000000000..637ae3daf --- /dev/null +++ b/src/grib_gaussian_N1280.h @@ -0,0 +1,259 @@ +// Num elements = 1280 from the north pole to equator +static const double lats_N1280[] = { + 89.946187715665616, 89.876478353332288, 89.806357319542244, 89.736143271609578, 89.6658939412157, + 89.595627537554492, 89.525351592371393, 89.45506977912261, 89.3847841013921, 89.314495744374256, + 89.24420545380525, 89.173913722284126, 89.103620888238879, 89.033327191845927, 88.96303280826325, + 88.892737868230952, 88.822442471310097, 88.752146694650691, 88.681850598961759, 88.611554232668382, + 88.541257634868515, 88.470960837474877, 88.40066386679355, 88.330366744702559, 88.26006948954614, + 88.189772116820762, 88.119474639706425, 88.049177069484486, 87.978879415867283, 87.908581687261687, + 87.838283890981543, 87.767986033419561, 87.697688120188062, 87.627390156234085, 87.557092145935584, + 87.486794093180748, 87.416496001434894, 87.346197873795816, 87.275899713041966, 87.205601521672108, + 87.135303301939786, 87.065005055882821, 86.994706785348129, 86.924408492014166, 86.854110177408927, + 86.783811842927179, 86.713513489844246, 86.643215119328573, 86.572916732453024, 86.502618330203831, + 86.432319913489792, 86.362021483149363, 86.291723039957418, 86.221424584631109, 86.151126117835304, + 86.080827640187209, 86.010529152260403, 85.940230654588888, 85.869932147670127, 85.799633631968391, + 85.729335107917464, 85.659036575922883, 85.588738036364362, 85.518439489597966, 85.448140935957483, + 85.377842375756586, 85.307543809290152, 85.237245236835548, 85.16694665865414, 85.09664807499216, + 85.026349486081983, 84.95605089214304, 84.885752293382765, 84.81545368999717, 84.745155082171991, + 84.674856470082915, 84.604557853896708, 84.534259233771479, 84.463960609857125, 84.393661982296322, + 84.323363351224444, 84.253064716770425, 84.18276607905679, 84.112467438200326, 84.042168794312317, + 83.971870147498763, 83.901571497860914, 83.831272845495249, 83.760974190494011, 83.690675532945292, + 83.620376872933264, 83.550078210538487, 83.479779545838113, 83.409480878905782, 83.339182209812321, + 83.268883538625232, 83.198584865409657, 83.128286190227698, 83.057987513139125, 82.987688834201322, + 82.917390153469313, 82.84709147099602, 82.77679278683226, 82.706494101026948, 82.63619541362705, + 82.56589672467787, 82.495598034222837, 82.425299342304029, 82.355000648961692, 82.284701954234833, + 82.214403258160871, 82.144104560776, 82.073805862115165, 82.003507162211946, 81.933208461098829, + 81.862909758807191, 81.792611055367345, 81.722312350808508, 81.652013645158945, 81.581714938445955, + 81.511416230696042, 81.441117521934686, 81.370818812186627, 81.300520101475826, 81.230221389825374, + 81.159922677257711, 81.089623963794551, 81.019325249456955, 80.949026534265244, 80.878727818239184, + 80.808429101397948, 80.73813038376008, 80.667831665343556, 80.59753294616587, 80.527234226243991, + 80.456935505594302, 80.386636784232863, 80.316338062175078, 80.246039339436052, 80.175740616030438, + 80.105441891972376, 80.035143167275749, 79.9648444419539, 79.894545716019948, 79.824246989486554, + 79.753948262366038, 79.683649534670437, 79.61335080641139, 79.543052077600308, 79.472753348248219, + 79.402454618365894, 79.332155887963822, 79.261857157052191, 79.191558425640977, 79.121259693739859, + 79.050960961358285, 78.980662228505423, 78.910363495190211, 78.840064761421445, 78.769766027207638, + 78.699467292557102, 78.629168557477882, 78.558869821977908, 78.488571086064923, 78.418272349746417, + 78.347973613029708, 78.277674875922045, 78.207376138430348, 78.137077400561424, 78.066778662322022, + 77.996479923718596, 77.926181184757539, 77.855882445445019, 77.785583705787161, 77.71528496578982, + 77.644986225458879, 77.574687484799924, 77.504388743818524, 77.434090002520122, 77.363791260909963, + 77.293492518993247, 77.22319377677502, 77.15289503426024, 77.082596291453768, 77.012297548360323, + 76.941998804984564, 76.871700061330955, 76.801401317404, 76.731102573208048, 76.660803828747362, + 76.59050508402602, 76.520206339048215, 76.449907593817869, 76.379608848338933, 76.3093101026152, + 76.239011356650423, 76.16871261044831, 76.098413864012443, 76.028115117346374, 75.957816370453543, + 75.887517623337317, 75.81721887600105, 75.746920128447996, 75.67662138068134, 75.60632263270422, + 75.536023884519707, 75.465725136130786, 75.395426387540439, 75.325127638751567, 75.254828889766983, + 75.184530140589501, 75.114231391221821, 75.043932641666672, 74.973633891926625, 74.903335142004323, + 74.833036391902269, 74.762737641622991, 74.692438891168877, 74.622140140542356, 74.551841389745761, + 74.481542638781434, 74.411243887651622, 74.340945136358584, 74.270646384904481, 74.200347633291472, + 74.13004888152166, 74.059750129597163, 73.98945137751997, 73.919152625292114, 73.848853872915541, + 73.778555120392184, 73.70825636772399, 73.637957614912779, 73.567658861960396, 73.497360108868662, + 73.427061355639339, 73.356762602274188, 73.2864638487749, 73.216165095143182, 73.145866341380668, + 73.075567587489019, 73.005268833469799, 72.934970079324657, 72.864671325055056, 72.794372570662574, + 72.724073816148703, 72.653775061514935, 72.583476306762691, 72.513177551893421, 72.442878796908545, + 72.3725800418094, 72.302281286597392, 72.231982531273843, 72.161683775840089, 72.091385020297409, + 72.02108626464711, 71.950787508890414, 71.880488753028587, 71.810189997062835, 71.739891240994368, + 71.669592484824364, 71.599293728553988, 71.528994972184378, 71.458696215716685, 71.388397459152031, + 71.318098702491469, 71.247799945736105, 71.177501188887007, 71.107202431945211, 71.036903674911756, + 70.966604917787635, 70.896306160573886, 70.826007403271475, 70.755708645881384, 70.685409888404578, + 70.615111130841967, 70.544812373194532, 70.474513615463138, 70.404214857648739, 70.333916099752187, + 70.263617341774406, 70.193318583716191, 70.123019825578467, 70.052721067362043, 69.982422309067744, + 69.912123550696421, 69.841824792248843, 69.771526033725834, 69.701227275128161, 69.630928516456592, + 69.560629757711908, 69.490330998894862, 69.420032240006194, 69.349733481046613, 69.279434722016902, + 69.209135962917699, 69.138837203749759, 69.068538444513763, 68.998239685210365, 68.927940925840304, + 68.85764216640419, 68.787343406902693, 68.717044647336493, 68.646745887706189, 68.576447128012447, + 68.506148368255865, 68.435849608437067, 68.365550848556666, 68.295252088615257, 68.224953328613438, + 68.154654568551791, 68.084355808430871, 68.014057048251274, 67.943758288013555, 67.873459527718282, + 67.803160767365966, 67.732862006957205, 67.662563246492482, 67.592264485972336, 67.521965725397308, + 67.451666964767895, 67.381368204084609, 67.311069443347961, 67.240770682558434, 67.170471921716526, + 67.100173160822706, 67.029874399877471, 66.95957563888129, 66.889276877834618, 66.818978116737924, + 66.748679355591662, 66.678380594396273, 66.608081833152212, 66.537783071859891, 66.467484310519808, + 66.397185549132331, 66.326886787697887, 66.256588026216932, 66.186289264689833, 66.115990503117033, + 66.045691741498899, 65.975392979835888, 65.905094218128355, 65.834795456376696, 65.764496694581283, + 65.694197932742526, 65.623899170860767, 65.553600408936404, 65.483301646969792, 65.413002884961315, + 65.342704122911286, 65.272405360820116, 65.202106598688133, 65.131807836515677, 65.061509074303089, + 64.991210312050711, 64.920911549758912, 64.850612787427963, 64.780314025058246, 64.710015262650074, + 64.639716500203733, 64.569417737719576, 64.499118975197902, 64.428820212639039, 64.358521450043284, + 64.288222687410922, 64.21792392474228, 64.147625162037642, 64.07732639929732, 64.00702763652157, + 63.93672887371072, 63.866430110865004, 63.796131347984762, 63.725832585070251, 63.655533822121711, + 63.585235059139464, 63.514936296123757, 63.444637533074854, 63.374338769993031, 63.304040006878537, + 63.23374124373165, 63.163442480552604, 63.093143717341647, 63.022844954099064, 62.952546190825068, + 62.882247427519928, 62.811948664183866, 62.741649900817137, 62.67135113741999, 62.60105237399263, + 62.530753610535321, 62.460454847048261, 62.3901560835317, 62.319857319985871, 62.249558556410982, + 62.179259792807258, 62.108961029174914, 62.038662265514176, 61.968363501825259, 61.898064738108381, + 61.827765974363729, 61.757467210591535, 61.687168446791986, 61.616869682965287, 61.546570919111666, + 61.476272155231321, 61.405973391324409, 61.335674627391185, 61.265375863431785, 61.195077099446451, + 61.124778335435344, 61.054479571398652, 60.984180807336578, 60.913882043249295, 60.843583279137007, + 60.773284514999872, 60.702985750838074, 60.632686986651805, 60.562388222441243, 60.492089458206543, + 60.421790693947884, 60.35149192966545, 60.28119316535939, 60.21089440102989, 60.140595636677112, + 60.070296872301235, 59.999998107902378, 59.929699343480763, 59.859400579036503, 59.78910181456979, + 59.718803050080759, 59.64850428556958, 59.578205521036402, 59.507906756481383, 59.43760799190467, + 59.3673092273064, 59.29701046268675, 59.226711698045854, 59.156412933383855, 59.086114168700909, + 59.015815403997145, 58.945516639272725, 58.875217874527763, 58.804919109762423, 58.73462034497684, + 58.664321580171141, 58.594022815345468, 58.523724050499972, 58.453425285634758, 58.383126520749968, + 58.312827755845746, 58.242528990922203, 58.172230225979497, 58.101931461017728, 58.031632696037022, + 57.961333931037537, 57.891035166019364, 57.820736400982646, 57.75043763592749, 57.680138870854037, + 57.60984010576238, 57.539541340652676, 57.469242575525016, 57.398943810379521, 57.328645045216312, + 57.258346280035504, 57.188047514837208, 57.117748749621541, 57.047449984388614, 56.977151219138541, + 56.90685245387143, 56.836553688587379, 56.766254923286517, 56.695956157968951, 56.625657392634771, + 56.555358627284086, 56.485059861917016, 56.41476109653366, 56.34446233113411, 56.274163565718467, + 56.203864800286865, 56.133566034839362, 56.063267269376091, 55.992968503897131, 55.922669738402583, + 55.852370972892551, 55.782072207367136, 55.711773441826416, 55.641474676270505, 55.571175910699488, + 55.500877145113449, 55.430578379512511, 55.360279613896743, 55.289980848266232, 55.219682082621084, + 55.149383316961377, 55.07908455128721, 55.008785785598668, 54.938487019895831, 54.868188254178797, + 54.797889488447652, 54.727590722702473, 54.657291956943347, 54.586993191170357, 54.516694425383605, + 54.446395659583146, 54.376096893769081, 54.305798127941479, 54.235499362100448, 54.165200596246031, + 54.094901830378333, 54.024603064497434, 53.954304298603383, 53.884005532696307, 53.813706766776235, + 53.743408000843282, 53.673109234897495, 53.602810468938962, 53.53251170296776, 53.462212936983953, + 53.391914170987633, 53.321615404978871, 53.251316638957725, 53.181017872924265, 53.110719106878584, + 53.040420340820731, 52.970121574750792, 52.899822808668837, 52.829524042574917, 52.759225276469131, + 52.688926510351514, 52.618627744222159, 52.548328978081123, 52.478030211928477, 52.407731445764284, + 52.337432679588609, 52.26713391340153, 52.196835147203096, 52.126536380993372, 52.056237614772435, + 51.985938848540336, 51.915640082297152, 51.845341316042933, 51.775042549777737, 51.704743783501634, + 51.634445017214695, 51.56414625091697, 51.493847484608516, 51.423548718289396, 51.353249951959683, + 51.282951185619417, 51.21265241926865, 51.14235365290746, 51.072054886535909, 51.001756120154049, + 50.931457353761914, 50.86115858735959, 50.790859820947119, 50.720561054524559, 50.650262288091959, + 50.579963521649397, 50.509664755196901, 50.439365988734544, 50.369067222262359, 50.298768455780426, + 50.228469689288779, 50.158170922787484, 50.087872156276575, 50.017573389756123, 49.947274623226157, + 49.876975856686762, 49.80667709013796, 49.736378323579807, 49.66607955701236, 49.595780790435676, + 49.525482023849783, 49.455183257254745, 49.384884490650613, 49.314585724037435, 49.244286957415234, + 49.173988190784094, 49.103689424144044, 49.03339065749514, 48.963091890837418, 48.892793124170929, + 48.822494357495721, 48.752195590811837, 48.681896824119335, 48.611598057418242, 48.541299290708608, + 48.47100052399049, 48.400701757263917, 48.330402990528938, 48.260104223785596, 48.189805457033941, + 48.119506690274015, 48.049207923505868, 47.978909156729507, 47.908610389945018, 47.838311623152421, + 47.76801285635176, 47.697714089543084, 47.627415322726435, 47.557116555901828, 47.486817789069342, + 47.416519022228997, 47.346220255380835, 47.275921488524894, 47.205622721661214, 47.13532395478984, + 47.065025187910805, 46.994726421024154, 46.924427654129929, 46.85412888722815, 46.783830120318882, + 46.713531353402139, 46.643232586477971, 46.572933819546414, 46.502635052607502, 46.432336285661272, + 46.362037518707766, 46.291738751747012, 46.221439984779053, 46.151141217803925, 46.080842450821663, + 46.01054368383231, 45.94024491683588, 45.869946149832437, 45.799647382821995, 45.729348615804589, + 45.659049848780263, 45.588751081749038, 45.51845231471097, 45.448153547666081, 45.377854780614399, + 45.30755601355596, 45.237257246490813, 45.166958479418959, 45.096659712340461, 45.026360945255341, + 44.956062178163634, 44.885763411065362, 44.81546464396056, 44.745165876849271, 44.674867109731515, + 44.604568342607337, 44.534269575476756, 44.463970808339802, 44.39367204119651, 44.323373274046915, + 44.253074506891046, 44.182775739728925, 44.112476972560586, 44.042178205386072, 43.971879438205391, + 43.9015806710186, 43.831281903825705, 43.760983136626741, 43.690684369421732, 43.620385602210717, + 43.550086834993728, 43.479788067770777, 43.409489300541907, 43.339190533307139, 43.26889176606651, + 43.19859299882004, 43.128294231567757, 43.057995464309691, 42.987696697045862, 42.917397929776307, + 42.847099162501053, 42.776800395220121, 42.706501627933541, 42.63620286064134, 42.565904093343548, + 42.495605326040177, 42.425306558731272, 42.355007791416853, 42.284709024096927, 42.214410256771551, + 42.144111489440725, 42.073812722104492, 42.003513954762873, 41.933215187415882, 41.862916420063563, + 41.792617652705921, 41.722318885343, 41.6520201179748, 41.581721350601363, 41.511422583222718, + 41.441123815838885, 41.370825048449873, 41.300526281055724, 41.230227513656445, 41.159928746252085, + 41.089629978842645, 41.01933121142816, 40.949032444008644, 40.878733676584126, 40.808434909154634, + 40.738136141720176, 40.667837374280786, 40.597538606836487, 40.527239839387299, 40.456941071933244, + 40.386642304474343, 40.316343537010617, 40.246044769542102, 40.175746002068806, 40.105447234590748, + 40.035148467107952, 39.964849699620437, 39.894550932128247, 39.824252164631375, 39.753953397129855, + 39.683654629623703, 39.613355862112947, 39.543057094597607, 39.472758327077692, 39.402459559553229, + 39.332160792024254, 39.261862024490775, 39.191563256952804, 39.121264489410365, 39.050965721863491, + 38.980666954312184, 38.910368186756479, 38.840069419196389, 38.769770651631937, 38.699471884063136, + 38.629173116490001, 38.558874348912568, 38.488575581330842, 38.418276813744846, 38.347978046154608, + 38.277679278560143, 38.20738051096145, 38.137081743358586, 38.066782975751536, 37.99648420814033, + 37.926185440524989, 37.855886672905527, 37.785587905281965, 37.715289137654317, 37.644990370022605, + 37.574691602386856, 37.504392834747065, 37.434094067103274, 37.363795299455489, 37.293496531803719, + 37.223197764147997, 37.152898996488332, 37.082600228824752, 37.012301461157264, 36.942002693485883, + 36.871703925810628, 36.801405158131523, 36.731106390448581, 36.660807622761808, 36.590508855071242, + 36.520210087376888, 36.449911319678755, 36.379612551976876, 36.309313784271254, 36.239015016561908, + 36.16871624884886, 36.098417481132117, 36.028118713411708, 35.957819945687639, 35.887521177959933, + 35.817222410228595, 35.746923642493655, 35.676624874755113, 35.606326107012997, 35.536027339267314, + 35.465728571518085, 35.395429803765317, 35.325131036009047, 35.254832268249267, 35.184533500486005, + 35.114234732719261, 35.043935964949064, 34.973637197175435, 34.903338429398374, 34.833039661617903, + 34.762740893834028, 34.692442126046771, 34.622143358256153, 34.551844590462188, 34.481545822664863, + 34.411247054864234, 34.340948287060286, 34.270649519253041, 34.200350751442521, 34.130051983628725, + 34.059753215811682, 33.989454447991392, 33.919155680167876, 33.848856912341155, 33.778558144511237, + 33.708259376678136, 33.637960608841851, 33.567661841002426, 33.497363073159853, 33.42706430531414, + 33.356765537465314, 33.286466769613391, 33.216168001758369, 33.145869233900278, 33.075570466039117, + 33.005271698174909, 32.934972930307666, 32.864674162437396, 32.794375394564113, 32.724076626687825, + 32.653777858808567, 32.583479090926325, 32.513180323041112, 32.442881555152965, 32.372582787261891, + 32.302284019367875, 32.231985251470959, 32.161686483571145, 32.091387715668439, 32.021088947762863, + 31.950790179854422, 31.880491411943137, 31.810192644029012, 31.739893876112063, 31.669595108192297, + 31.599296340269738, 31.528997572344384, 31.458698804416255, 31.388400036485361, 31.318101268551715, + 31.247802500615318, 31.177503732676204, 31.107204964734358, 31.036906196789811, 30.966607428842572, + 30.896308660892647, 30.826009892940046, 30.755711124984781, 30.685412357026873, 30.615113589066322, + 30.544814821103138, 30.47451605313735, 30.404217285168947, 30.333918517197947, 30.263619749224372, + 30.19332098124822, 30.123022213269511, 30.052723445288244, 29.98242467730444, 29.91212590931811, + 29.841827141329258, 29.771528373337894, 29.701229605344039, 29.630930837347698, 29.560632069348884, + 29.490333301347597, 29.420034533343859, 29.349735765337677, 29.279436997329057, 29.209138229318015, + 29.138839461304556, 29.068540693288696, 28.998241925270449, 28.927943157249814, 28.857644389226806, + 28.787345621201432, 28.717046853173709, 28.646748085143642, 28.576449317111244, 28.506150549076519, + 28.435851781039485, 28.365553013000145, 28.29525424495851, 28.224955476914594, 28.154656708868405, + 28.084357940819952, 28.014059172769244, 27.94376040471629, 27.873461636661098, 27.803162868603682, + 27.732864100544052, 27.662565332482213, 27.592266564418171, 27.521967796351948, 27.451669028283543, + 27.381370260212968, 27.311071492140236, 27.240772724065348, 27.170473955988321, 27.100175187909159, + 27.029876419827872, 26.959577651744471, 26.889278883658971, 26.818980115571364, 26.748681347481678, + 26.678382579389908, 26.608083811296069, 26.53778504320017, 26.467486275102218, 26.397187507002222, + 26.326888738900195, 26.256589970796135, 26.186291202690064, 26.115992434581983, 26.045693666471902, + 25.975394898359827, 25.90509613024577, 25.834797362129745, 25.764498594011751, 25.694199825891793, + 25.623901057769892, 25.553602289646051, 25.483303521520277, 25.413004753392578, 25.342705985262967, + 25.272407217131445, 25.202108448998025, 25.13180968086272, 25.061510912725527, 24.991212144586456, + 24.920913376445526, 24.850614608302738, 24.780315840158096, 24.710017072011613, 24.639718303863294, + 24.569419535713152, 24.499120767561195, 24.428821999407425, 24.358523231251851, 24.288224463094483, + 24.217925694935328, 24.1476269267744, 24.077328158611696, 24.007029390447226, 23.936730622281004, + 23.866431854113038, 23.796133085943328, 23.725834317771888, 23.655535549598721, 23.585236781423838, + 23.514938013247242, 23.444639245068949, 23.374340476888957, 23.304041708707278, 23.233742940523921, + 23.163444172338895, 23.0931454041522, 23.022846635963852, 22.952547867773848, 22.882249099582204, + 22.811950331388925, 22.741651563194019, 22.671352794997489, 22.60105402679935, 22.530755258599601, + 22.460456490398254, 22.390157722195315, 22.319858953990789, 22.249560185784691, 22.179261417577013, + 22.108962649367779, 22.038663881156989, 21.968365112944642, 21.898066344730758, 21.827767576515338, + 21.757468808298391, 21.687170040079913, 21.616871271859928, 21.546572503638437, 21.47627373541544, + 21.40597496719095, 21.335676198964972, 21.265377430737512, 21.195078662508585, 21.124779894278181, + 21.054481126046323, 20.984182357813012, 20.913883589578251, 20.843584821342048, 20.773286053104417, + 20.702987284865355, 20.632688516624874, 20.562389748382977, 20.492090980139672, 20.421792211894967, + 20.35149344364887, 20.28119467540138, 20.210895907152516, 20.140597138902272, 20.070298370650661, + 19.999999602397686, 19.929700834143357, 19.859402065887682, 19.789103297630657, 19.718804529372303, + 19.648505761112613, 19.578206992851602, 19.507908224589269, 19.437609456325632, 19.367310688060684, + 19.297011919794439, 19.226713151526898, 19.15641438325807, 19.086115614987968, 19.015816846716586, + 18.945518078443939, 18.875219310170031, 18.804920541894862, 18.734621773618446, 18.664323005340787, + 18.594024237061891, 18.523725468781763, 18.453426700500408, 18.383127932217832, 18.312829163934047, + 18.242530395649048, 18.172231627362851, 18.101932859075458, 18.031634090786874, 17.96133532249711, + 17.89103655420616, 17.820737785914044, 17.75043901762076, 17.680140249326314, 17.60984148103071, + 17.539542712733962, 17.469243944436066, 17.39894517613704, 17.328646407836878, 17.258347639535586, + 17.188048871233182, 17.117750102929655, 17.04745133462502, 16.977152566319283, 16.906853798012452, + 16.836555029704527, 16.766256261395515, 16.69595749308542, 16.625658724774254, 16.555359956462013, + 16.485061188148713, 16.41476241983435, 16.344463651518936, 16.274164883202477, 16.203866114884974, + 16.133567346566434, 16.063268578246863, 15.992969809926265, 15.922671041604652, 15.852372273282016, + 15.78207350495838, 15.711774736633735, 15.641475968308091, 15.571177199981456, 15.500878431653829, + 15.430579663325226, 15.360280894995643, 15.289982126665089, 15.219683358333569, 15.149384590001089, + 15.07908582166765, 15.008787053333259, 14.938488284997929, 14.868189516661655, 14.797890748324447, + 14.727591979986309, 14.657293211647247, 14.586994443307265, 14.516695674966371, 14.446396906624567, + 14.376098138281863, 14.305799369938256, 14.23550060159376, 14.165201833248371, 14.0949030649021, + 14.024604296554955, 13.954305528206934, 13.884006759858046, 13.813707991508297, 13.743409223157688, + 13.673110454806226, 13.602811686453919, 13.532512918100766, 13.46221414974678, 13.391915381391959, + 13.32161661303631, 13.251317844679837, 13.181019076322551, 13.110720307964451, 13.040421539605545, + 12.970122771245832, 12.899824002885323, 12.829525234524022, 12.759226466161934, 12.688927697799061, + 12.618628929435411, 12.548330161070988, 12.478031392705796, 12.407732624339841, 12.337433855973126, + 12.267135087605659, 12.196836319237443, 12.126537550868482, 12.056238782498781, 11.985940014128348, + 11.915641245757183, 11.845342477385294, 11.775043709012685, 11.704744940639358, 11.634446172265324, + 11.564147403890583, 11.493848635515141, 11.423549867139002, 11.35325109876217, 11.282952330384653, + 11.212653562006453, 11.142354793627575, 11.072056025248026, 11.001757256867807, 10.931458488486923, + 10.861159720105382, 10.790860951723188, 10.720562183340341, 10.65026341495685, 10.579964646572719, + 10.509665878187954, 10.439367109802557, 10.369068341416533, 10.298769573029887, 10.228470804642624, + 10.158172036254747, 10.087873267866264, 10.017574499477174, 9.9472757310874869, 9.8769769626972046, + 9.8066781943063344, 9.7363794259148779, 9.6660806575228388, 9.5957818891302242, 9.5254831207370376, + 9.4551843523432826, 9.3848855839489662, 9.3145868155540921, 9.2442880471586619, 9.1739892787626829, + 9.1036905103661585, 9.0333917419690941, 8.963092973571495, 8.8927942051733631, 8.8224954367747017, + 8.7521966683755217, 8.6818978999758194, 8.6115991315756055, 8.5413003631748801, 8.4710015947736537, + 8.4007028263719228, 8.3304040579696963, 8.2601052895669778, 8.1898065211637725, 8.1195077527600841, + 8.049208984355916, 7.9789102159512737, 7.9086114475461606, 7.8383126791405831, 7.7680139107345463, + 7.6977151423280494, 7.6274163739210996, 7.557117605513703, 7.4868188371058624, 7.4165200686975803, + 7.3462213002888648, 7.2759225318797176, 7.2056237634701441, 7.1353249950601469, 7.0650262266497315, + 6.994727458238903, 6.924428689827665, 6.8541299214160212, 6.7838311530039768, 6.7135323845915353, + 6.6432336161787013, 6.5729348477654792, 6.5026360793518734, 6.4323373109378874, 6.3620385425235257, + 6.2917397741087928, 6.2214410056936931, 6.151142237278231, 6.0808434688624091, 6.0105447004462347, + 5.9402459320297085, 5.869947163612836, 5.7996483951956233, 5.729349626778073, 5.6590508583601888, + 5.5887520899419751, 5.5184533215234373, 5.4481545531045787, 5.3778557846854023, 5.3075570162659149, + 5.2372582478461194, 5.1669594794260192, 5.0966607110056197, 5.0263619425849244, 4.9560631741639369, + 4.8857644057426626, 4.8154656373211049, 4.7451668688992683, 4.6748681004771564, 4.6045693320547736, + 4.5342705636321252, 4.4639717952092139, 4.3936730267860451, 4.3233742583626205, 4.2530754899389471, + 4.1827767215150269, 4.1124779530908659, 4.0421791846664661, 3.9718804162418326, 3.90158164781697, + 3.8312828793918823, 3.7609841109665734, 3.6906853425410477, 3.6203865741153085, 3.5500878056893601, + 3.4797890372632065, 3.4094902688368531, 3.339191500410303, 3.2688927319835597, 3.1985939635566285, + 3.1282951951295126, 3.0579964267022164, 2.9876976582747439, 2.9173988898470999, 2.8471001214192873, + 2.7768013529913107, 2.7065025845631743, 2.6362038161348824, 2.5659050477064382, 2.4956062792778466, + 2.4253075108491116, 2.3550087424202366, 2.2847099739912267, 2.2144112055620848, 2.1441124371328155, + 2.0738136687034232, 2.0035149002739114, 1.9332161318442849, 1.8629173634145471, 1.792618594984702, + 1.7223198265547539, 1.6520210581247066, 1.5817222896945646, 1.5114235212643317, 1.4411247528340119, + 1.3708259844036093, 1.300527215973128, 1.2302284475425722, 1.1599296791119456, 1.0896309106812523, + 1.0193321422504964, 0.949033373819682, 0.87873460538881287, 0.80843583695789356, 0.73813706852692773, + 0.66783830009591949, 0.59753953166487306, 0.52724076323379232, 0.45694199480268116, 0.3866432263715438, + 0.31634445794038429, 0.24604568950920663, 0.17574692107801482, 0.10544815264681295, 0.035149384215604956 +}; diff --git a/src/grib_gaussian_N640.h b/src/grib_gaussian_N640.h new file mode 100644 index 000000000..b82e1a97f --- /dev/null +++ b/src/grib_gaussian_N640.h @@ -0,0 +1,131 @@ +// Num elements = 640 from the north pole to equator +static const double lats_N640[] = { + 89.892396445590066, 89.753004943174034, 89.612790258599077, 89.472389582061126, 89.331918354381827, + 89.191412986832432, 89.050888539966436, 88.91035235926023, 88.76980845110036, 88.629259185411627, + 88.488706053376362, 88.348150039999084, 88.207591822004105, 88.067031879650926, 87.926470563186442, + 87.785908134040668, 87.645344791295628, 87.504780689222315, 87.364215949214667, 87.223650668104085, + 87.083084924070917, 86.942518780928566, 86.801952291278369, 86.661385498868242, 86.520818440379529, + 86.380251146798656, 86.239683644481104, 86.0991159559849, 85.958548100730781, 85.817980095529578, + 85.677411955006008, 85.536843691942948, 85.396275317562669, 85.255706841757572, 85.115138273281829, + 84.974569619910426, 84.834000888572191, 84.693432085462035, 84.552863216135577, 84.412294285589354, + 84.271725298329656, 84.131156258431133, 83.990587169587158, 83.850018035153667, 83.709448858186462, + 83.568879641474325, 83.428310387567549, 83.287741098802584, 83.147171777324388, 83.006602425105484, + 82.866033043962815, 82.725463635573107, 82.584894201485696, 82.444324743134914, 82.303755261850071, + 82.163185758865239, 82.022616235327504, 81.882046692304485, 81.741477130791196, 81.600907551715878, + 81.460337955945846, 81.319768344292086, 81.179198717514012, 81.038629076323318, 80.898059421387785, + 80.757489753334553, 80.616920072753146, 80.47635038019834, 80.335780676192584, 80.195210961228469, + 80.054641235770603, 79.914071500257819, 79.773501755104689, 79.632932000703448, 79.492362237425226, + 79.351792465621628, 79.211222685625927, 79.070652897754229, 78.930083102306568, 78.789513299567957, + 78.648943489809355, 78.508373673288318, 78.367803850250056, 78.227234020928066, 78.086664185544819, + 77.946094344312371, 77.805524497433041, 77.664954645099883, 77.524384787497311, 77.383814924801513, + 77.243245057180829, 77.102675184796354, 76.962105307802219, 76.821535426345932, 76.680965540568806, + 76.540395650606285, 76.399825756588143, 76.259255858638895, 76.118685956877997, 75.978116051420102, + 75.837546142375359, 75.69697622984954, 75.556406313944308, 75.41583639475742, 75.275266472382896, + 75.134696546911186, 74.994126618429377, 74.853556687021296, 74.712986752767719, 74.57241681574645, + 74.431846876032495, 74.291276933698185, 74.150706988813226, 74.010137041445006, 73.869567091658411, + 73.728997139516167, 73.588427185078871, 73.447857228405013, 73.307287269551111, 73.166717308571819, + 73.026147345520002, 72.885577380446747, 72.745007413401481, 72.604437444432065, 72.463867473584784, + 72.323297500904502, 72.182727526434604, 72.042157550217183, 71.901587572292982, 71.761017592701492, + 71.620447611481026, 71.47987762866866, 71.339307644300462, 71.198737658411332, 71.058167671035164, + 70.917597682204899, 70.777027691952398, 70.636457700308753, 70.495887707304007, 70.355317712967462, + 70.214747717327526, 70.074177720411782, 69.933607722247146, 69.793037722859665, 69.65246772227475, + 69.511897720517084, 69.37132771761064, 69.230757713578825, 69.090187708444333, 68.949617702229318, + 68.809047694955296, 68.668477686643286, 68.52790767731365, 68.387337666986312, 68.246767655680657, + 68.106197643415527, 67.965627630209354, 67.825057616080073, 67.684487601045149, 67.543917585121662, + 67.403347568326168, 67.262777550674912, 67.122207532183722, 66.981637512867991, 66.841067492742795, + 66.700497471822814, 66.559927450122359, 66.41935742765547, 66.278787404435761, 66.138217380476604, + 65.997647355791017, 65.85707733039176, 65.716507304291198, 65.575937277501538, 65.435367250034616, + 65.294797221902016, 65.154227193115119, 65.013657163684968, 64.873087133622406, 64.732517102938033, + 64.591947071642196, 64.451377039745026, 64.310807007256443, 64.170236974186125, 64.029666940543564, + 63.889096906338061, 63.748526871578648, 63.607956836274255, 63.467386800433559, 63.326816764065093, + 63.186246727177178, 63.045676689778013, 62.905106651875542, 62.764536613477638, 62.62396657459194, + 62.483396535225978, 62.342826495387122, 62.202256455082583, 62.061686414319418, 61.921116373104539, + 61.780546331444761, 61.639976289346727, 61.499406246816953, 61.358836203861841, 61.21826616048768, + 61.077696116700601, 60.937126072506608, 60.796556027911663, 60.655985982921543, 60.515415937541938, + 60.374845891778421, 60.234275845636503, 60.093705799121537, 59.953135752238794, 59.812565704993467, + 59.671995657390596, 59.531425609435225, 59.390855561132213, 59.250285512486386, 59.10971546350244, + 58.96914541418505, 58.828575364538722, 58.688005314567938, 58.547435264277105, 58.406865213670514, + 58.266295162752428, 58.125725111526968, 57.985155059998249, 57.844585008170284, 57.704014956047033, + 57.563444903632337, 57.422874850930043, 57.282304797943887, 57.141734744677549, 57.001164691134662, + 56.860594637318769, 56.720024583233375, 56.579454528881925, 56.438884474267795, 56.29831441939433, + 56.157744364264779, 56.017174308882367, 55.876604253250278, 55.736034197371588, 55.595464141249401, + 55.45489408488671, 55.314324028286471, 55.173753971451625, 55.033183914385013, 54.892613857089486, + 54.752043799567822, 54.611473741822735, 54.470903683856939, 54.330333625673063, 54.189763567273758, + 54.049193508661538, 53.90862344983897, 53.768053390808532, 53.627483331572677, 53.486913272133812, + 53.346343212494332, 53.205773152656562, 53.065203092622802, 52.924633032395342, 52.784062971976404, + 52.643492911368206, 52.502922850572908, 52.362352789592649, 52.221782728429538, 52.081212667085637, + 51.940642605563028, 51.800072543863692, 51.659502481989627, 51.518932419942786, 51.378362357725095, + 51.237792295338465, 51.097222232784773, 50.956652170065858, 50.81608210718354, 50.675512044139623, + 50.534941980935862, 50.39437191757402, 50.253801854055808, 50.113231790382912, 49.972661726557028, + 49.832091662579785, 49.691521598452823, 49.550951534177734, 49.410381469756118, 49.269811405189529, + 49.129241340479489, 48.988671275627539, 48.848101210635171, 48.707531145503857, 48.56696108023506, + 48.42639101483023, 48.285820949290759, 48.145250883618075, 48.004680817813544, 47.864110751878535, + 47.723540685814392, 47.582970619622444, 47.442400553303997, 47.301830486860368, 47.161260420292813, + 47.020690353602596, 46.880120286790955, 46.73955021985914, 46.598980152808338, 46.458410085639763, + 46.317840018354602, 46.177269950954006, 46.036699883439134, 45.896129815811136, 45.755559748071114, + 45.614989680220205, 45.474419612259481, 45.333849544190024, 45.193279476012933, 45.052709407729239, + 44.912139339339987, 44.771569270846214, 44.630999202248923, 44.490429133549149, 44.349859064747854, + 44.209288995846045, 44.068718926844674, 43.928148857744716, 43.787578788547094, 43.64700871925276, + 43.506438649862638, 43.365868580377636, 43.225298510798666, 43.0847284411266, 42.944158371362349, + 42.803588301506764, 42.663018231560706, 42.522448161525034, 42.381878091400594, 42.241308021188203, + 42.100737950888686, 41.960167880502873, 41.819597810031553, 41.679027739475522, 41.538457668835562, + 41.397887598112455, 41.257317527306981, 41.116747456419873, 40.976177385451912, 40.835607314403816, + 40.695037243276325, 40.554467172070169, 40.41389710078608, 40.273327029424742, 40.132756957986885, + 39.992186886473185, 39.851616814884331, 39.711046743220997, 39.570476671483874, 39.429906599673615, + 39.289336527790894, 39.148766455836338, 39.008196383810613, 38.867626311714339, 38.727056239548169, + 38.5864861673127, 38.44591609500857, 38.305346022636385, 38.164775950196741, 38.02420587769025, + 37.883635805117493, 37.743065732479067, 37.602495659775542, 37.461925587007492, 37.321355514175501, + 37.180785441280122, 37.040215368321896, 36.899645295301404, 36.759075222219167, 36.618505149075737, + 36.477935075871656, 36.33736500260742, 36.196794929283605, 36.056224855900687, 35.9156547824592, + 35.775084708959632, 35.634514635402525, 35.493944561788332, 35.353374488117588, 35.21280441439076, + 35.072234340608333, 34.931664266770788, 34.79109419287861, 34.650524118932253, 34.509954044932208, + 34.369383970878907, 34.228813896772813, 34.088243822614395, 33.9476737484041, 33.807103674142361, + 33.66653359982962, 33.525963525466317, 33.385393451052892, 33.244823376589757, 33.104253302077339, + 32.963683227516071, 32.823113152906366, 32.682543078248621, 32.541973003543255, 32.401402928790681, + 32.260832853991289, 32.120262779145477, 31.979692704253651, 31.839122629316183, 31.698552554333489, + 31.55798247930592, 31.417412404233875, 31.276842329117731, 31.136272253957859, 30.99570217875463, + 30.855132103508407, 30.71456202821955, 30.573991952888438, 30.433421877515418, 30.292851802100841, + 30.152281726645064, 30.011711651148435, 29.87114157561129, 29.730571500033992, 29.590001424416862, + 29.449431348760253, 29.308861273064483, 29.168291197329893, 29.027721121556816, 28.887151045745565, + 28.746580969896474, 28.606010894009859, 28.465440818086037, 28.324870742125327, 28.184300666128038, + 28.043730590094491, 27.903160514024975, 27.762590437919812, 27.622020361779295, 27.481450285603731, + 27.340880209393415, 27.200310133148644, 27.05974005686971, 26.919169980556905, 26.778599904210516, + 26.638029827830831, 26.497459751418134, 26.356889674972713, 26.216319598494842, 26.075749521984797, + 25.935179445442859, 25.794609368869299, 25.654039292264386, 25.513469215628398, 25.3728991389616, + 25.232329062264245, 25.091758985536615, 24.951188908778963, 24.810618831991551, 24.670048755174633, + 24.529478678328466, 24.388908601453309, 24.248338524549407, 24.107768447617016, 23.96719837065638, + 23.826628293667756, 23.686058216651375, 23.545488139607492, 23.404918062536346, 23.264347985438178, + 23.123777908313219, 22.98320783116171, 22.84263775398389, 22.70206767677999, 22.561497599550243, + 22.420927522294875, 22.280357445014126, 22.139787367708202, 21.999217290377352, 21.858647213021786, + 21.718077135641735, 21.577507058237412, 21.436936980809044, 21.296366903356844, 21.155796825881037, + 21.015226748381831, 20.874656670859444, 20.734086593314085, 20.593516515745968, 20.452946438155308, + 20.312376360542309, 20.171806282907177, 20.031236205250121, 19.890666127571347, 19.750096049871054, + 19.609525972149449, 19.468955894406733, 19.328385816643106, 19.187815738858767, 19.04724566105391, + 18.906675583228736, 18.766105505383443, 18.625535427518219, 18.484965349633256, 18.344395271728757, + 18.203825193804899, 18.063255115861882, 17.922685037899889, 17.782114959919113, 17.641544881919739, + 17.500974803901951, 17.360404725865926, 17.219834647811862, 17.079264569739937, 16.938694491650331, + 16.798124413543224, 16.657554335418794, 16.516984257277226, 16.376414179118694, 16.235844100943371, + 16.09527402275144, 15.954703944543072, 15.814133866318445, 15.673563788077727, 15.532993709821094, + 15.392423631548718, 15.251853553260768, 15.111283474957411, 14.970713396638821, 14.830143318305167, + 14.689573239956617, 14.549003161593328, 14.408433083215476, 14.267863004823225, 14.127292926416734, + 13.986722847996173, 13.8461527695617, 13.705582691113481, 13.565012612651675, 13.424442534176441, + 13.283872455687943, 13.143302377186339, 13.002732298671786, 12.862162220144443, 12.72159214160447, + 12.58102206305202, 12.440451984487247, 12.299881905910311, 12.159311827321366, 12.018741748720567, + 11.878171670108063, 11.73760159148401, 11.597031512848561, 11.456461434201868, 11.315891355544077, + 11.175321276875344, 11.034751198195819, 10.894181119505649, 10.753611040804984, 10.613040962093971, + 10.472470883372759, 10.331900804641496, 10.191330725900327, 10.050760647149401, 9.9101905683888614, + 9.7696204896188554, 9.6290504108395272, 9.4884803320510205, 9.3479102532534792, 9.2073401744470491, + 9.0667700956318686, 8.9262000168080871, 8.7856299379758411, 8.645059859135273, 8.5044897802865282, + 8.3639197014297419, 8.223349622565058, 8.0827795436926184, 7.9422094648125583, 7.8016393859250206, + 7.661069307030143, 7.5204992281280649, 7.3799291492189223, 7.2393590703028563, 7.098788991380002, + 6.9582189124504987, 6.8176488335144816, 6.6770787545720891, 6.5365086756234554, 6.3959385966687181, + 6.2553685177080123, 6.1147984387414738, 5.9742283597692367, 5.833658280791437, 5.6930882018082087, + 5.5525181228196869, 5.4119480438260039, 5.2713779648272956, 5.1308078858236934, 4.9902378068153324, + 4.8496677278023448, 4.7090976487848639, 4.5685275697630221, 4.4279574907369508, 4.2873874117067841, + 4.1468173326726534, 4.0062472536346903, 3.8656771745930261, 3.7251070955477918, 3.5845370164991213, + 3.4439669374471427, 3.3033968583919884, 3.1628267793337885, 3.0222567002726746, 2.8816866212087762, + 2.7411165421422243, 2.6005464630731496, 2.4599763840016813, 2.3194063049279499, 2.1788362258520855, + 2.0382661467742174, 1.8976960676944756, 1.7571259886129893, 1.6165559095298885, 1.4759858304453026, + 1.3354157513593612, 1.194845672272193, 1.0542755931839276, 0.91370551409469447, 0.77313543500462234, + 0.63256535591384055, 0.49199527682247807, 0.351425197730664, 0.21085511863852741, 0.070285039546197275 +}; diff --git a/src/grib_geography.cc b/src/grib_geography.cc index c864fec9e..1457615c6 100644 --- a/src/grib_geography.cc +++ b/src/grib_geography.cc @@ -148,10 +148,53 @@ static int compute_gaussian_latitudes(long trunc, double* lats) return GRIB_SUCCESS; } +// Performance: return the precomputed latitudes for N=640 +// The provided 'lats' array should have allocated 2*N elements +static int get_precomputed_latitudes_N640(double* lats) +{ + #include "grib_gaussian_N640.h" + const size_t N = 640; + for (size_t i = 0; i < N; ++i) { + lats[i] = lats_N640[i]; + } + + const size_t ilast = N * 2 - 1; + for (size_t i = ilast; i > ilast / 2; --i) { + lats[i] = -lats[ilast - i]; + } + + return GRIB_SUCCESS; +} + +// Performance: return the precomputed latitudes for N=1280 +// The provided 'lats' array should have allocated 2*N elements +static int get_precomputed_latitudes_N1280(double* lats) +{ + #include "grib_gaussian_N1280.h" + const size_t N = 1280; + for (size_t i = 0; i < N; ++i) { + lats[i] = lats_N1280[i]; + } + + const size_t ilast = N * 2 - 1; + for (size_t i = ilast; i > ilast / 2; --i) { + lats[i] = -lats[ilast - i]; + } + + return GRIB_SUCCESS; +} + int grib_get_gaussian_latitudes(long trunc, double* lats) { if (trunc <= 0) return GRIB_GEOCALCULUS_PROBLEM; + + if (trunc == 640) { + return get_precomputed_latitudes_N640(lats); + } + if (trunc == 1280) { + return get_precomputed_latitudes_N1280(lats); + } return compute_gaussian_latitudes(trunc, lats); } diff --git a/src/grib_value.cc b/src/grib_value.cc index 97315c557..c3cf55e55 100644 --- a/src/grib_value.cc +++ b/src/grib_value.cc @@ -1801,15 +1801,15 @@ int grib_set_values_silent(grib_handle* h, grib_values* args, size_t count, int h->values[stack] = args; h->values_count[stack] = count; - for (i = 0; i < count; i++) - args[i].error = GRIB_NOT_FOUND; - if (h->context->debug) { for (i = 0; i < count; i++) { grib_print_values("ECCODES DEBUG about to set key/value pair", &args[i], stderr, 1); } } + for (i = 0; i < count; i++) + args[i].error = GRIB_NOT_FOUND; + while (more) { more = 0; for (i = 0; i < count; i++) { @@ -1899,7 +1899,9 @@ void grib_print_values(const char* title, const grib_values* values, FILE* out, fprintf(out, "%s", aVal.string_value); break; } - fprintf(out, " (type=%s)\n", grib_get_type_name(aVal.type)); + fprintf(out, " (type=%s)", grib_get_type_name(aVal.type)); + if (aVal.error) fprintf(out, "\t(%s)\n", grib_get_error_message(aVal.error)); + else fprintf(out, "\n"); } } diff --git a/tests/grib2_product_templates.sh b/tests/grib2_product_templates.sh index 29e70a96c..579592462 100755 --- a/tests/grib2_product_templates.sh +++ b/tests/grib2_product_templates.sh @@ -53,6 +53,36 @@ else echo "No duplicates in $def_file" fi +# Automatic PDT selection +# from instantaneous to statistically processed (accum,max,etc) +# ------------------------------------------------------------- +grib_check_key_equals $sample_g2 productDefinitionTemplateNumber,stepType '0 instant' +$tools_dir/grib_set -s shortName=tp $sample_g2 $tempGribA +grib_check_key_equals $tempGribA productDefinitionTemplateNumber 8 +grib_check_key_equals $tempGribA typeOfStatisticalProcessing,stepType '1 accum' +grib_check_key_equals $tempGribA shortName,name 'tp Total precipitation' + +$tools_dir/grib_set -s productDefinitionTemplateNumber=1,shortName=tp,perturbationNumber=32 $sample_g2 $tempGribA +grib_check_key_equals $tempGribA productDefinitionTemplateNumber 11 +grib_check_key_equals $tempGribA number 32 +grib_check_key_equals $tempGribA typeOfStatisticalProcessing,stepType '1 accum' +grib_check_key_equals $tempGribA shortName,name 'tp Total precipitation' + +$tools_dir/grib_set -s paramId=237382 $sample_g2 $tempGribA +$tools_dir/grib_ls -jn parameter $tempGribA +grib_check_key_equals $tempGribA productDefinitionTemplateNumber 8 +grib_check_key_equals $tempGribA typeOfStatisticalProcessing,stepType '2 max' +grib_check_key_equals $tempGribA shortName,name 'max_visp Time-maximum visibility through precipitation' + +# Test an expected failure. paramId=140114 contains wave keys +set +e +$tools_dir/grib_set -s paramId=140114 $sample_g2 $tempGribA 2>$tempText +status=$? +set -e +[ $status -ne 0 ] +grep -q "typeOfWavePeriodInterval .* failed: Key/value not found" $tempText +grep -q "scaleFactorOfLowerWavePeriodLimit .* failed: Key/value not found" $tempText + # Clean up rm -f $tempText $tempGribA $tempGribB