18% tests passed, 276 tests failed out of 337

This commit is contained in:
Eugen Betke 2024-03-18 22:41:56 +00:00
parent c598a51954
commit f1d68aa7f6
532 changed files with 21431 additions and 34120 deletions

View File

@ -51,7 +51,7 @@ static void* process_grib(void* threadID)
ProductKind prod_kind = 0;
codes_handle* h = codes_grib_handle_new_from_samples(0, "regular_ll_pl_grib2");
Assert(h);
Assert(h != NULL);
CODES_CHECK(codes_get_product_kind(h, &prod_kind), 0);
Assert(prod_kind == PRODUCT_GRIB);
printf("Thread %ld running\n", tid);

View File

@ -12,6 +12,7 @@ list( APPEND eccodes_src_files
accessor/grib_accessor.cc
accessor/grib_accessors_list.cc
grib_accessor_class.cc
shared_functions.cc
step_unit.cc
step.cc
step_utilities.cc
@ -23,9 +24,9 @@ list( APPEND eccodes_src_files
action_class_gen.cc
action_class_if.cc
action_class_switch.cc
#accessor/grib_accessor_class_g1fcperiod.cc
#accessor/grib_accessor_class_g1end_of_interval_monthly.cc
#accessor/grib_accessor_class_mars_param.cc
accessor/grib_accessor_class_g1fcperiod.cc
accessor/grib_accessor_class_g1end_of_interval_monthly.cc
accessor/grib_accessor_class_mars_param.cc
action_class_section.cc
action_class_list.cc
action_class_while.cc
@ -63,207 +64,207 @@ list( APPEND eccodes_src_files
grib_viarray.cc
codes_memfs.cc
accessor/grib_accessor_class_gen.cc
#accessor/grib_accessor_class_ascii.cc
#accessor/grib_accessor_class_bit.cc
#accessor/grib_accessor_class_bitmap.cc
#accessor/grib_accessor_class_bits.cc
#accessor/grib_accessor_class_bits_per_value.cc
#accessor/grib_accessor_class_bufr_elements_table.cc
#accessor/grib_accessor_class_bufr_data_array.cc
#accessor/grib_accessor_class_bufr_data_element.cc
#accessor/grib_accessor_class_bufr_group.cc
#accessor/grib_accessor_class_bufr_string_values.cc
#accessor/grib_accessor_class_pack_bufr_values.cc
#accessor/grib_accessor_class_unpack_bufr_values.cc
#accessor/grib_accessor_class_group.cc
#accessor/grib_accessor_class_non_alpha.cc
#accessor/grib_accessor_class_g1bitmap.cc
#accessor/grib_accessor_class_g2bitmap.cc
#accessor/grib_accessor_class_concept.cc
#accessor/grib_accessor_class_hash_array.cc
#accessor/grib_accessor_class_decimal_precision.cc
#accessor/grib_accessor_class_divdouble.cc
#accessor/grib_accessor_class_multdouble.cc
#accessor/grib_accessor_class_budgdate.cc
#accessor/grib_accessor_class_validity_date.cc
#accessor/grib_accessor_class_validity_time.cc
#accessor/grib_accessor_class_bytes.cc
#accessor/grib_accessor_class_change_alternative_row_scanning.cc
#accessor/grib_accessor_class_change_scanning_direction.cc
#accessor/grib_accessor_class_check_internal_version.cc
#accessor/grib_accessor_class_codeflag.cc
accessor/grib_accessor_class_ascii.cc
accessor/grib_accessor_class_bit.cc
accessor/grib_accessor_class_bitmap.cc
accessor/grib_accessor_class_bits.cc
accessor/grib_accessor_class_bits_per_value.cc
accessor/grib_accessor_class_bufr_elements_table.cc
accessor/grib_accessor_class_bufr_data_array.cc
accessor/grib_accessor_class_bufr_data_element.cc
accessor/grib_accessor_class_bufr_group.cc
accessor/grib_accessor_class_bufr_string_values.cc
accessor/grib_accessor_class_pack_bufr_values.cc
accessor/grib_accessor_class_unpack_bufr_values.cc
accessor/grib_accessor_class_group.cc
accessor/grib_accessor_class_non_alpha.cc
accessor/grib_accessor_class_g1bitmap.cc
accessor/grib_accessor_class_g2bitmap.cc
accessor/grib_accessor_class_concept.cc
accessor/grib_accessor_class_hash_array.cc
accessor/grib_accessor_class_decimal_precision.cc
accessor/grib_accessor_class_divdouble.cc
accessor/grib_accessor_class_multdouble.cc
accessor/grib_accessor_class_budgdate.cc
accessor/grib_accessor_class_validity_date.cc
accessor/grib_accessor_class_validity_time.cc
accessor/grib_accessor_class_bytes.cc
accessor/grib_accessor_class_change_alternative_row_scanning.cc
accessor/grib_accessor_class_change_scanning_direction.cc
accessor/grib_accessor_class_check_internal_version.cc
accessor/grib_accessor_class_codeflag.cc
accessor/grib_accessor_class_smart_table.cc
#accessor/grib_accessor_class_smart_table_column.cc
accessor/grib_accessor_class_smart_table_column.cc
accessor/grib_accessor_class_codetable.cc
#accessor/grib_accessor_class_codetable_units.cc
#accessor/grib_accessor_class_codetable_title.cc
#accessor/grib_accessor_class_step_human_readable.cc
#accessor/grib_accessor_class_count_file.cc
#accessor/grib_accessor_class_count_total.cc
#accessor/grib_accessor_class_double.cc
#accessor/grib_accessor_class_element.cc
#accessor/grib_accessor_class_evaluate.cc
#accessor/grib_accessor_class_g1date.cc
#accessor/grib_accessor_class_g1monthlydate.cc
#accessor/grib_accessor_class_library_version.cc
#accessor/grib_accessor_class_when.cc
#accessor/grib_accessor_class_g1verificationdate.cc
#accessor/grib_accessor_class_g1day_of_the_year_date.cc
#accessor/grib_accessor_class_g1_half_byte_codeflag.cc
#accessor/grib_accessor_class_g1forecastmonth.cc
#accessor/grib_accessor_class_g1step_range.cc
#accessor/grib_accessor_class_g2step_range.cc
#accessor/grib_accessor_class_data_g22order_packing.cc
#accessor/grib_accessor_class_mars_step.cc
#accessor/grib_accessor_class_message_copy.cc
#accessor/grib_accessor_class_dictionary.cc
#accessor/grib_accessor_class_latlon_increment.cc
#accessor/grib_accessor_class_g2date.cc
#accessor/grib_accessor_class_g2level.cc
#accessor/grib_accessor_class_g2end_step.cc
#accessor/grib_accessor_class_g2latlon.cc
#accessor/grib_accessor_class_g2lon.cc
#accessor/grib_accessor_class_global_gaussian.cc
#accessor/grib_accessor_class_gaussian_grid_name.cc
#accessor/grib_accessor_class_gen.cc
#accessor/grib_accessor_class_getenv.cc
#accessor/grib_accessor_class_gts_header.cc
#accessor/grib_accessor_class_ifs_param.cc
#accessor/grib_accessor_class_julian_day.cc
#accessor/grib_accessor_class_julian_date.cc
#accessor/grib_accessor_class_closest_date.cc
#accessor/grib_accessor_class_latlonvalues.cc
#accessor/grib_accessor_class_latitudes.cc
#accessor/grib_accessor_class_longitudes.cc
#accessor/grib_accessor_class_offset_file.cc
#accessor/grib_accessor_class_scale.cc
#accessor/grib_accessor_class_from_scale_factor_scaled_value.cc
#accessor/grib_accessor_class_g2bitmap_present.cc
#accessor/grib_accessor_class_ibmfloat.cc
#accessor/grib_accessor_class_ieeefloat.cc
accessor/grib_accessor_class_codetable_units.cc
accessor/grib_accessor_class_codetable_title.cc
accessor/grib_accessor_class_step_human_readable.cc
accessor/grib_accessor_class_count_file.cc
accessor/grib_accessor_class_count_total.cc
accessor/grib_accessor_class_double.cc
accessor/grib_accessor_class_element.cc
accessor/grib_accessor_class_evaluate.cc
accessor/grib_accessor_class_g1date.cc
accessor/grib_accessor_class_g1monthlydate.cc
accessor/grib_accessor_class_library_version.cc
accessor/grib_accessor_class_when.cc
accessor/grib_accessor_class_g1verificationdate.cc
accessor/grib_accessor_class_g1day_of_the_year_date.cc
accessor/grib_accessor_class_g1_half_byte_codeflag.cc
accessor/grib_accessor_class_g1forecastmonth.cc
accessor/grib_accessor_class_g1step_range.cc
accessor/grib_accessor_class_g2step_range.cc
accessor/grib_accessor_class_data_g22order_packing.cc
accessor/grib_accessor_class_mars_step.cc
accessor/grib_accessor_class_message_copy.cc
accessor/grib_accessor_class_dictionary.cc
accessor/grib_accessor_class_latlon_increment.cc
accessor/grib_accessor_class_g2date.cc
accessor/grib_accessor_class_g2level.cc
accessor/grib_accessor_class_g2end_step.cc
accessor/grib_accessor_class_g2latlon.cc
accessor/grib_accessor_class_g2lon.cc
accessor/grib_accessor_class_global_gaussian.cc
accessor/grib_accessor_class_gaussian_grid_name.cc
accessor/grib_accessor_class_gen.cc
accessor/grib_accessor_class_getenv.cc
accessor/grib_accessor_class_gts_header.cc
accessor/grib_accessor_class_ifs_param.cc
accessor/grib_accessor_class_julian_day.cc
accessor/grib_accessor_class_julian_date.cc
accessor/grib_accessor_class_closest_date.cc
accessor/grib_accessor_class_latlonvalues.cc
accessor/grib_accessor_class_latitudes.cc
accessor/grib_accessor_class_longitudes.cc
accessor/grib_accessor_class_offset_file.cc
accessor/grib_accessor_class_scale.cc
accessor/grib_accessor_class_from_scale_factor_scaled_value.cc
accessor/grib_accessor_class_g2bitmap_present.cc
accessor/grib_accessor_class_ibmfloat.cc
accessor/grib_accessor_class_ieeefloat.cc
accessor/grib_accessor_class_constant.cc
accessor/grib_accessor_class_iterator.cc
#accessor/grib_accessor_class_message.cc
accessor/grib_accessor_class_message.cc
accessor/grib_accessor_class_nearest.cc
#accessor/grib_accessor_class_ksec1expver.cc
#accessor/grib_accessor_class_label.cc
accessor/grib_accessor_class_ksec1expver.cc
accessor/grib_accessor_class_label.cc
accessor/grib_accessor_class_long.cc
#accessor/grib_accessor_class_lookup.cc
#accessor/grib_accessor_class_octahedral_gaussian.cc
#accessor/grib_accessor_class_octet_number.cc
#accessor/grib_accessor_class_headers_only.cc
#accessor/grib_accessor_class_padding.cc
#accessor/grib_accessor_class_pad.cc
#accessor/grib_accessor_class_padto.cc
#accessor/grib_accessor_class_padtoeven.cc
#accessor/grib_accessor_class_padtomultiple.cc
#accessor/grib_accessor_class_section_padding.cc
#accessor/grib_accessor_class_packing_type.cc
#accessor/grib_accessor_class_section_pointer.cc
#accessor/grib_accessor_class_position.cc
#accessor/grib_accessor_class_signed.cc
#accessor/grib_accessor_class_signed_bits.cc
#accessor/grib_accessor_class_section.cc
#accessor/grib_accessor_class_step_in_units.cc
#accessor/grib_accessor_class_optimal_step_units.cc
#accessor/grib_accessor_class_section_length.cc
#accessor/grib_accessor_class_g1_message_length.cc
#accessor/grib_accessor_class_g1_section4_length.cc
#accessor/grib_accessor_class_size.cc
#accessor/grib_accessor_class_rdbtime_guess_date.cc
#accessor/grib_accessor_class_scale_values.cc
#accessor/grib_accessor_class_offset_values.cc
#accessor/grib_accessor_class_sprintf.cc
#accessor/grib_accessor_class_round.cc
#accessor/grib_accessor_class_spectral_truncation.cc
#accessor/grib_accessor_class_time.cc
accessor/grib_accessor_class_lookup.cc
accessor/grib_accessor_class_octahedral_gaussian.cc
accessor/grib_accessor_class_octet_number.cc
accessor/grib_accessor_class_headers_only.cc
accessor/grib_accessor_class_padding.cc
accessor/grib_accessor_class_pad.cc
accessor/grib_accessor_class_padto.cc
accessor/grib_accessor_class_padtoeven.cc
accessor/grib_accessor_class_padtomultiple.cc
accessor/grib_accessor_class_section_padding.cc
accessor/grib_accessor_class_packing_type.cc
accessor/grib_accessor_class_section_pointer.cc
accessor/grib_accessor_class_position.cc
accessor/grib_accessor_class_signed.cc
accessor/grib_accessor_class_signed_bits.cc
accessor/grib_accessor_class_section.cc
accessor/grib_accessor_class_step_in_units.cc
accessor/grib_accessor_class_optimal_step_units.cc
accessor/grib_accessor_class_section_length.cc
accessor/grib_accessor_class_g1_message_length.cc
accessor/grib_accessor_class_g1_section4_length.cc
accessor/grib_accessor_class_size.cc
accessor/grib_accessor_class_rdbtime_guess_date.cc
accessor/grib_accessor_class_scale_values.cc
accessor/grib_accessor_class_offset_values.cc
accessor/grib_accessor_class_sprintf.cc
accessor/grib_accessor_class_round.cc
accessor/grib_accessor_class_spectral_truncation.cc
accessor/grib_accessor_class_time.cc
accessor/grib_accessor_class_transient.cc
#accessor/grib_accessor_class_trim.cc
#accessor/grib_accessor_class_transient_darray.cc
#accessor/grib_accessor_class_values.cc
#accessor/grib_accessor_class_simple_packing_error.cc
#accessor/grib_accessor_class_data_simple_packing.cc
#accessor/grib_accessor_class_count_missing.cc
#accessor/grib_accessor_class_data_sh_packed.cc
#accessor/grib_accessor_class_data_sh_unpacked.cc
#accessor/grib_accessor_class_number_of_values_data_raw_packing.cc
#accessor/grib_accessor_class_data_g1simple_packing.cc
#accessor/grib_accessor_class_data_g1shsimple_packing.cc
#accessor/grib_accessor_class_data_shsimple_packing.cc
#accessor/grib_accessor_class_data_dummy_field.cc
accessor/grib_accessor_class_trim.cc
accessor/grib_accessor_class_transient_darray.cc
accessor/grib_accessor_class_values.cc
accessor/grib_accessor_class_simple_packing_error.cc
accessor/grib_accessor_class_data_simple_packing.cc
accessor/grib_accessor_class_count_missing.cc
accessor/grib_accessor_class_data_sh_packed.cc
accessor/grib_accessor_class_data_sh_unpacked.cc
accessor/grib_accessor_class_number_of_values_data_raw_packing.cc
accessor/grib_accessor_class_data_g1simple_packing.cc
accessor/grib_accessor_class_data_g1shsimple_packing.cc
accessor/grib_accessor_class_data_shsimple_packing.cc
accessor/grib_accessor_class_data_dummy_field.cc
accessor/grib_accessor_class_variable.cc
#accessor/grib_accessor_class_second_order_bits_per_value.cc
#accessor/grib_accessor_class_data_g2simple_packing.cc
#accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc
#accessor/grib_accessor_class_data_g2shsimple_packing.cc
#accessor/grib_accessor_class_data_g2complex_packing.cc
#accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc
#accessor/grib_accessor_class_data_g1second_order_constant_width_packing.cc
#accessor/grib_accessor_class_data_g1second_order_general_packing.cc
#accessor/grib_accessor_class_data_g1second_order_general_extended_packing.cc
#accessor/grib_accessor_class_g2grid.cc
#accessor/grib_accessor_class_unexpanded_descriptors.cc
#accessor/grib_accessor_class_expanded_descriptors.cc
#accessor/grib_accessor_class_bufrdc_expanded_descriptors.cc
#accessor/grib_accessor_class_data_apply_bitmap.cc
#accessor/grib_accessor_class_data_apply_boustrophedonic.cc
#accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.cc
#accessor/grib_accessor_class_data_secondary_bitmap.cc
#accessor/grib_accessor_class_data_g1secondary_bitmap.cc
#accessor/grib_accessor_class_data_g2secondary_bitmap.cc
#accessor/grib_accessor_class_data_jpeg2000_packing.cc
#accessor/grib_accessor_class_data_png_packing.cc
#accessor/grib_accessor_class_data_ccsds_packing.cc
#accessor/grib_accessor_class_data_raw_packing.cc
#accessor/grib_accessor_class_data_complex_packing.cc
#accessor/grib_accessor_class_data_g1complex_packing.cc
#accessor/grib_accessor_class_gds_not_present_bitmap.cc
#accessor/grib_accessor_class_gds_is_present.cc
#accessor/grib_accessor_class_select_step_template.cc
#accessor/grib_accessor_class_local_definition.cc
#accessor/grib_accessor_class_g2_eps.cc
#accessor/grib_accessor_class_g2_aerosol.cc
#accessor/grib_accessor_class_g2_chemical.cc
#accessor/grib_accessor_class_g2_mars_labeling.cc
#accessor/grib_accessor_class_md5.cc
#accessor/grib_accessor_class_proj_string.cc
accessor/grib_accessor_class_second_order_bits_per_value.cc
accessor/grib_accessor_class_data_g2simple_packing.cc
accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc
accessor/grib_accessor_class_data_g2shsimple_packing.cc
accessor/grib_accessor_class_data_g2complex_packing.cc
accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc
accessor/grib_accessor_class_data_g1second_order_constant_width_packing.cc
accessor/grib_accessor_class_data_g1second_order_general_packing.cc
accessor/grib_accessor_class_data_g1second_order_general_extended_packing.cc
accessor/grib_accessor_class_g2grid.cc
accessor/grib_accessor_class_unexpanded_descriptors.cc
accessor/grib_accessor_class_expanded_descriptors.cc
accessor/grib_accessor_class_bufrdc_expanded_descriptors.cc
accessor/grib_accessor_class_data_apply_bitmap.cc
accessor/grib_accessor_class_data_apply_boustrophedonic.cc
accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.cc
accessor/grib_accessor_class_data_secondary_bitmap.cc
accessor/grib_accessor_class_data_g1secondary_bitmap.cc
accessor/grib_accessor_class_data_g2secondary_bitmap.cc
accessor/grib_accessor_class_data_jpeg2000_packing.cc
accessor/grib_accessor_class_data_png_packing.cc
accessor/grib_accessor_class_data_ccsds_packing.cc
accessor/grib_accessor_class_data_raw_packing.cc
accessor/grib_accessor_class_data_complex_packing.cc
accessor/grib_accessor_class_data_g1complex_packing.cc
accessor/grib_accessor_class_gds_not_present_bitmap.cc
accessor/grib_accessor_class_gds_is_present.cc
accessor/grib_accessor_class_select_step_template.cc
accessor/grib_accessor_class_local_definition.cc
accessor/grib_accessor_class_g2_eps.cc
accessor/grib_accessor_class_g2_aerosol.cc
accessor/grib_accessor_class_g2_chemical.cc
accessor/grib_accessor_class_g2_mars_labeling.cc
accessor/grib_accessor_class_md5.cc
accessor/grib_accessor_class_proj_string.cc
grib_jasper_encoding.cc
grib_openjpeg_encoding.cc
action_class_set_missing.cc
#accessor/grib_accessor_class_number_of_points.cc
#accessor/grib_accessor_class_suppressed.cc
accessor/grib_accessor_class_number_of_points.cc
accessor/grib_accessor_class_suppressed.cc
grib_index.cc
#accessor/grib_accessor_class_number_of_points_gaussian.cc
#accessor/grib_accessor_class_number_of_values.cc
#accessor/grib_accessor_class_number_of_coded_values.cc
#accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.cc
#accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.cc
#accessor/grib_accessor_class_dirty.cc
#accessor/grib_accessor_class_statistics.cc
#accessor/grib_accessor_class_statistics_spectral.cc
accessor/grib_accessor_class_number_of_points_gaussian.cc
accessor/grib_accessor_class_number_of_values.cc
accessor/grib_accessor_class_number_of_coded_values.cc
accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.cc
accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.cc
accessor/grib_accessor_class_dirty.cc
accessor/grib_accessor_class_statistics.cc
accessor/grib_accessor_class_statistics_spectral.cc
accessor/grib_accessor_class_unsigned.cc
#accessor/grib_accessor_class_unsigned_bits.cc
#accessor/grib_accessor_class_raw.cc
#accessor/grib_accessor_class_bufr_simple_thinning.cc
#accessor/grib_accessor_class_bufr_extract_subsets.cc
#accessor/grib_accessor_class_bufr_extract_area_subsets.cc
#accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc
#accessor/grib_accessor_class_spd.cc
#accessor/grib_accessor_class_sum.cc
#accessor/grib_accessor_class_to_integer.cc
#accessor/grib_accessor_class_to_double.cc
#accessor/grib_accessor_class_to_string.cc
#accessor/grib_accessor_class_sexagesimal2decimal.cc
#accessor/grib_accessor_class_vector.cc
#accessor/grib_accessor_class_long_vector.cc
accessor/grib_accessor_class_unsigned_bits.cc
accessor/grib_accessor_class_raw.cc
accessor/grib_accessor_class_bufr_simple_thinning.cc
accessor/grib_accessor_class_bufr_extract_subsets.cc
accessor/grib_accessor_class_bufr_extract_area_subsets.cc
accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc
accessor/grib_accessor_class_spd.cc
accessor/grib_accessor_class_sum.cc
accessor/grib_accessor_class_to_integer.cc
accessor/grib_accessor_class_to_double.cc
accessor/grib_accessor_class_to_string.cc
accessor/grib_accessor_class_sexagesimal2decimal.cc
accessor/grib_accessor_class_vector.cc
accessor/grib_accessor_class_long_vector.cc
grib_gaussian_reduced.cc
#accessor/grib_accessor_class_abstract_vector.cc
#accessor/grib_accessor_class_abstract_long_vector.cc
accessor/grib_accessor_class_abstract_vector.cc
accessor/grib_accessor_class_abstract_long_vector.cc
grib_loader_from_handle.cc
grib_bits.cc
grib_ibmfloat.cc
grib_ieeefloat.cc
#accessor/grib_accessor_class_reference_value_error.cc
accessor/grib_accessor_class_reference_value_error.cc
grib_memory.cc
grib_buffer.cc
grib_dumper.cc
@ -366,16 +367,16 @@ list( APPEND eccodes_src_files
grib_yacc.h
md5.h
md5.cc
#accessor/grib_accessor_class_uint16.cc
#accessor/grib_accessor_class_uint32.cc
#accessor/grib_accessor_class_uint32_little_endian.cc
#accessor/grib_accessor_class_uint64.cc
#accessor/grib_accessor_class_uint64_little_endian.cc
#accessor/grib_accessor_class_uint8.cc
#accessor/grib_accessor_class_blob.cc
accessor/grib_accessor_class_uint16.cc
accessor/grib_accessor_class_uint32.cc
accessor/grib_accessor_class_uint32_little_endian.cc
accessor/grib_accessor_class_uint64.cc
accessor/grib_accessor_class_uint64_little_endian.cc
accessor/grib_accessor_class_uint8.cc
accessor/grib_accessor_class_blob.cc
grib_optimize_decimal_factor.cc
#accessor/grib_accessor_class_data_g2bifourier_packing.cc
#accessor/grib_accessor_class_data_run_length_packing.cc
accessor/grib_accessor_class_data_g2bifourier_packing.cc
accessor/grib_accessor_class_data_run_length_packing.cc
eccodes_windef.h
# We ship our own generated lex/yacc C files
grib_yacc.cc grib_lex.cc )

View File

@ -0,0 +1,17 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_abstract_long_vector.h"
grib_accessor_class_abstract_long_vector_t _grib_accessor_class_abstract_long_vector{"abstract_long_vector"};
grib_accessor_class* grib_accessor_class_abstract_long_vector = &_grib_accessor_class_abstract_long_vector;

View File

@ -0,0 +1,33 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_abstract_long_vector_h
#define eccodes_accessor_abstract_long_vector_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_abstract_long_vector_t : public grib_accessor_gen_t
{
public:
/* Members defined in abstract_long_vector */
long* v;
long pack_index;
int number_of_elements;
};
class grib_accessor_class_abstract_long_vector_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_abstract_long_vector_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_abstract_long_vector_t{}; }
};
#endif /* eccodes_accessor_abstract_long_vector_h */

View File

@ -0,0 +1,17 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_abstract_vector.h"
grib_accessor_class_abstract_vector_t _grib_accessor_class_abstract_vector{"abstract_vector"};
grib_accessor_class* grib_accessor_class_abstract_vector = &_grib_accessor_class_abstract_vector;

View File

@ -0,0 +1,32 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_abstract_vector_h
#define eccodes_accessor_abstract_vector_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_double.h"
class grib_accessor_abstract_vector_t : public grib_accessor_double_t
{
public:
/* Members defined in abstract_vector */
double* v;
int number_of_elements;
};
class grib_accessor_class_abstract_vector_t : public grib_accessor_class_double_t
{
public:
grib_accessor_class_abstract_vector_t(const char* name) : grib_accessor_class_double_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_abstract_vector_t{}; }
};
#endif /* eccodes_accessor_abstract_vector_h */

View File

@ -0,0 +1,164 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_ascii.h"
grib_accessor_class_ascii_t _grib_accessor_class_ascii{"ascii"};
grib_accessor_class* grib_accessor_class_ascii = &_grib_accessor_class_ascii;
void grib_accessor_class_ascii_t::init(grib_accessor* a, const long len, grib_arguments* arg){
a->length = len;
Assert(a->length >= 0);
}
int grib_accessor_class_ascii_t::value_count(grib_accessor* a, long* count){
*count = 1;
return 0;
}
size_t grib_accessor_class_ascii_t::string_length(grib_accessor* a){
return a->length;
}
void grib_accessor_class_ascii_t::dump(grib_accessor* a, grib_dumper* dumper){
grib_dump_string(dumper, a, NULL);
}
int grib_accessor_class_ascii_t::get_native_type(grib_accessor* a){
return GRIB_TYPE_STRING;
}
int grib_accessor_class_ascii_t::unpack_string(grib_accessor* a, char* val, size_t* len){
size_t i = 0;
grib_handle* hand = grib_handle_of_accessor(a);
const size_t alen = a->length;
if (*len < (alen + 1)) {
const char* cclass_name = a->cclass->name;
grib_context_log(a->context, GRIB_LOG_ERROR,
"%s: Buffer too small for %s. It is %zu bytes long (len=%zu)",
cclass_name, a->name, alen+1, *len);
*len = alen + 1;
return GRIB_BUFFER_TOO_SMALL;
}
for (i = 0; i < alen; i++)
val[i] = hand->buffer->data[a->offset + i];
val[i] = 0;
*len = i;
return GRIB_SUCCESS;
}
int grib_accessor_class_ascii_t::pack_string(grib_accessor* a, const char* val, size_t* len){
size_t i = 0;
grib_handle* hand = grib_handle_of_accessor(a);
const size_t alen = a->length;
if (len[0] > (alen + 1)) {
grib_context_log(a->context, GRIB_LOG_ERROR,
"pack_string: Wrong size (%zu) for %s, it contains %ld values", len[0], a->name, a->length + 1);
len[0] = 0;
return GRIB_BUFFER_TOO_SMALL;
}
for (i = 0; i < alen; i++) {
if (i < len[0])
hand->buffer->data[a->offset + i] = val[i];
else
hand->buffer->data[a->offset + i] = 0;
}
return GRIB_SUCCESS;
}
int grib_accessor_class_ascii_t::pack_long(grib_accessor* a, const long* v, size_t* len){
grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as long (It's a string)", a->name);
return GRIB_NOT_IMPLEMENTED;
}
int grib_accessor_class_ascii_t::pack_double(grib_accessor* a, const double* v, size_t* len){
grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as double (It's a string)", a->name);
return GRIB_NOT_IMPLEMENTED;
}
int grib_accessor_class_ascii_t::unpack_long(grib_accessor* a, long* v, size_t* len){
char val[1024] = {0,};
size_t l = sizeof(val);
size_t i = 0;
char* last = NULL;
int err = a->unpack_string(val, &l);
if (err)
return err;
i = 0;
while (i < l - 1 && val[i] == ' ')
i++;
if (val[i] == 0) {
*v = 0;
return 0;
}
if (val[i + 1] == ' ' && i < l - 2)
val[i + 1] = 0;
*v = strtol(val, &last, 10);
grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name);
return GRIB_SUCCESS;
}
int grib_accessor_class_ascii_t::unpack_double(grib_accessor* a, double* v, size_t* len){
char val[1024];
size_t l = sizeof(val);
char* last = NULL;
int err = a->unpack_string(val, &l); if (err) return err;
*v = strtod(val, &last);
if (*last == 0) {
grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name);
return GRIB_SUCCESS;
}
grib_context_log(a->context, GRIB_LOG_WARNING, "Cannot unpack %s as double. Hint: Try unpacking as string", a->name);
return GRIB_NOT_IMPLEMENTED;
}
int grib_accessor_class_ascii_t::compare(grib_accessor* a, grib_accessor* b){
int retval = 0;
char* aval = 0;
char* bval = 0;
int err = 0;
size_t alen = a->length+1;
size_t blen = b->length+1;
if (alen != blen)
return GRIB_COUNT_MISMATCH;
aval = (char*)grib_context_malloc(a->context, alen * sizeof(char));
bval = (char*)grib_context_malloc(b->context, blen * sizeof(char));
err = a->unpack_string(aval, &alen); if (err) return err;
err = b->unpack_string(bval, &blen); if (err) return err;
retval = GRIB_SUCCESS;
if (!STR_EQUAL(aval, bval))
retval = GRIB_STRING_VALUE_MISMATCH;
grib_context_free(a->context, aval);
grib_context_free(b->context, bval);
return retval;
}

View File

@ -0,0 +1,42 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_ascii_h
#define eccodes_accessor_ascii_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_ascii_t : public grib_accessor_gen_t
{
public:
/* Members defined in ascii */
};
class grib_accessor_class_ascii_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_ascii_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_ascii_t{}; }
int get_native_type(grib_accessor*) override;
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int pack_long(grib_accessor*, const long* val, size_t* len) override;
int pack_string(grib_accessor*, const char*, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int unpack_long(grib_accessor*, long* val, size_t* len) override;
int unpack_string(grib_accessor*, char*, size_t* len) override;
size_t string_length(grib_accessor*) override;
int value_count(grib_accessor*, long*) override;
void dump(grib_accessor*, grib_dumper*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
int compare(grib_accessor*, grib_accessor*) override;
};
#endif /* eccodes_accessor_ascii_h */

View File

@ -0,0 +1,79 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_bit.h"
grib_accessor_class_bit_t _grib_accessor_class_bit{"bit"};
grib_accessor_class* grib_accessor_class_bit = &_grib_accessor_class_bit;
void grib_accessor_class_bit_t::init(grib_accessor* a, const long len, grib_arguments* arg){
grib_accessor_bit_t* self = (grib_accessor_bit_t*)a;
a->length = 0;
self->owner = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 0);
self->bit_index = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1);
}
int grib_accessor_class_bit_t::unpack_long(grib_accessor* a, long* val, size_t* len){
grib_accessor_bit_t* self = (grib_accessor_bit_t*)a;
int ret = 0;
long data = 0;
if (*len < 1) {
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit_t: unpack_long: Wrong size for %s, it contains %d values ", a->name, 1);
*len = 1;
return GRIB_ARRAY_TOO_SMALL;
}
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->owner, &data)) != GRIB_SUCCESS) {
*len = 0;
return ret;
}
if (data & (1 << self->bit_index))
*val = 1;
else
*val = 0;
*len = 1;
return GRIB_SUCCESS;
}
int grib_accessor_class_bit_t::pack_long(grib_accessor* a, const long* val, size_t* len){
grib_accessor_bit_t* self = (grib_accessor_bit_t*)a;
if (*len < 1) {
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit_t: pack_long: At least one value to pack for %s", a->name);
*len = 1;
return GRIB_ARRAY_TOO_SMALL;
}
grib_accessor* owner = grib_find_accessor(grib_handle_of_accessor(a), self->owner);
if (!owner) {
grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_bit_t: Cannot get the owner %s for computing the bit value of %s",
self->owner, a->name);
*len = 0;
return GRIB_NOT_FOUND;
}
unsigned char* mdata = grib_handle_of_accessor(a)->buffer->data;
mdata += owner->byte_offset();
/* Note: In the definitions, flagbit numbers go from 7 to 0 (the bit_index), while WMO convention is from 1 to 8 */
if (a->context->debug) {
/* Print bit positions from 1 (MSB) */
fprintf(stderr, "ECCODES DEBUG Setting bit %d in %s to %d\n", 8 - self->bit_index, owner->name, (*val > 0) );
}
grib_set_bit(mdata, 7 - self->bit_index, *val > 0);
*len = 1;
return GRIB_SUCCESS;
}

View File

@ -0,0 +1,35 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_bit_h
#define eccodes_accessor_bit_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_long.h"
class grib_accessor_bit_t : public grib_accessor_long_t
{
public:
/* Members defined in bit */
const char* owner;
int bit_index;
};
class grib_accessor_class_bit_t : public grib_accessor_class_long_t
{
public:
grib_accessor_class_bit_t(const char* name) : grib_accessor_class_long_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_bit_t{}; }
int pack_long(grib_accessor*, const long* val, size_t* len) override;
int unpack_long(grib_accessor*, long* val, size_t* len) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_bit_h */

View File

@ -0,0 +1,175 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_bitmap.h"
grib_accessor_class_bitmap_t _grib_accessor_class_bitmap{"bitmap"};
grib_accessor_class* grib_accessor_class_bitmap = &_grib_accessor_class_bitmap;
void compute_size(grib_accessor* a){
long slen = 0;
long off = 0;
grib_handle* hand = grib_handle_of_accessor(a);
grib_accessor_bitmap_t* self = (grib_accessor_bitmap_t*)a;
grib_get_long_internal(hand, self->offsetbsec, &off);
grib_get_long_internal(hand, self->sLength, &slen);
if (slen == 0) {
grib_accessor* seclen;
size_t size;
/* Assume reparsing */
Assert(hand->loader != 0);
if (hand->loader != 0) {
seclen = grib_find_accessor(hand, self->sLength);
Assert(seclen);
grib_get_block_length(seclen->parent, &size);
slen = size;
}
}
// printf("compute_size off=%ld slen=%ld a->offset=%ld\n", (long)off,(long)slen,(long)a->offset);
a->length = off + (slen - a->offset);
if (a->length < 0) {
/* Assume reparsing */
/*Assert(hand->loader != 0);*/
a->length = 0;
}
Assert(a->length >= 0);
}
void grib_accessor_class_bitmap_t::init(grib_accessor* a, const long len, grib_arguments* arg){
grib_accessor_bitmap_t* self = (grib_accessor_bitmap_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
int n = 0;
self->tableReference = grib_arguments_get_name(hand, arg, n++);
self->missing_value = grib_arguments_get_name(hand, arg, n++);
self->offsetbsec = grib_arguments_get_name(hand, arg, n++);
self->sLength = grib_arguments_get_name(hand, arg, n++);
compute_size(a);
}
long grib_accessor_class_bitmap_t::next_offset(grib_accessor* a){
return a->byte_offset() + a->byte_count();}
void grib_accessor_class_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper){
long len = 0;
char label[1024];
a->value_count(&len);
snprintf(label, 1024, "Bitmap of %ld values", len);
grib_dump_bytes(dumper, a, label);
}
int grib_accessor_class_bitmap_t::unpack_long(grib_accessor* a, long* val, size_t* len){
long pos = a->offset * 8;
long tlen = 0;
const grib_handle* hand = grib_handle_of_accessor(a);
int err = a->value_count(&tlen); if (err)
return err;
if (*len < tlen) {
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", a->name, tlen);
*len = tlen;
return GRIB_ARRAY_TOO_SMALL;
}
for (long i = 0; i < tlen; i++) {
val[i] = (long)grib_decode_unsigned_long(hand->buffer->data, &pos, 1);
}
*len = tlen;
return GRIB_SUCCESS;
}
template <typename T>
int unpack(grib_accessor* a, T* val, size_t* len){
static_assert(std::is_floating_point<T>::value, "Requires floating points numbers");
long pos = a->offset * 8;
long tlen;
grib_handle* hand = grib_handle_of_accessor(a);
int err = a->value_count(&tlen); if (err)
return err;
if (*len < tlen) {
grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", a->name, tlen);
*len = tlen;
return GRIB_ARRAY_TOO_SMALL;
}
for (long i = 0; i < tlen; i++) {
val[i] = (T)grib_decode_unsigned_long(hand->buffer->data, &pos, 1);
}
*len = tlen;
return GRIB_SUCCESS;
}
int grib_accessor_class_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len){
return unpack<double>(a, val, len);
}
int grib_accessor_class_bitmap_t::unpack_float(grib_accessor* a, float* val, size_t* len){
return unpack<float>(a, val, len);
}
int grib_accessor_class_bitmap_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){
long pos = a->offset * 8;
pos += idx;
*val = (double)grib_decode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, &pos, 1);
return GRIB_SUCCESS;
}
int grib_accessor_class_bitmap_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){
for (size_t i=0; i<len; ++i) {
unpack_double_element(a, index_array[i], val_array + i);
}
return GRIB_SUCCESS;
}
void grib_accessor_class_bitmap_t::update_size(grib_accessor* a, size_t s){
a->length = s;
}
size_t grib_accessor_class_bitmap_t::string_length(grib_accessor* a){
return a->length;
}
int grib_accessor_class_bitmap_t::unpack_string(grib_accessor* a, char* val, size_t* len){
grib_handle* hand = grib_handle_of_accessor(a);
const size_t l = a->length;
if (*len < l) {
const char* cclass_name = a->cclass->name;
grib_context_log(a->context, GRIB_LOG_ERROR,
"%s: Buffer too small for %s. It is %zu bytes long (len=%zu)",
cclass_name, a->name, l, *len);
*len = l;
return GRIB_BUFFER_TOO_SMALL;
}
for (long i = 0; i < a->length; i++) {
val[i] = hand->buffer->data[a->offset + i];
}
*len = a->length;
return GRIB_SUCCESS;
}

View File

@ -0,0 +1,45 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_bitmap_h
#define eccodes_accessor_bitmap_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_bytes.h"
class grib_accessor_bitmap_t : public grib_accessor_bytes_t
{
public:
/* Members defined in bitmap */
const char* tableReference;
const char* missing_value;
const char* offsetbsec;
const char* sLength;
};
class grib_accessor_class_bitmap_t : public grib_accessor_class_bytes_t
{
public:
grib_accessor_class_bitmap_t(const char* name) : grib_accessor_class_bytes_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_bitmap_t{}; }
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int unpack_float(grib_accessor*, float* val, size_t* len) override;
int unpack_long(grib_accessor*, long* val, size_t* len) override;
int unpack_string(grib_accessor*, char*, size_t* len) override;
size_t string_length(grib_accessor*) override;
long next_offset(grib_accessor*) override;
void dump(grib_accessor*, grib_dumper*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
void update_size(grib_accessor*, size_t) override;
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override;
};
#endif /* eccodes_accessor_bitmap_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -8,127 +9,15 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
/**************************************
* Enrico Fucile
**************************************/
#include "grib_api_internal.h"
#include "grib_accessor_class_bits.h"
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_gen
IMPLEMENTS = get_native_type
IMPLEMENTS = unpack_long; pack_long
IMPLEMENTS = unpack_bytes; byte_count
IMPLEMENTS = unpack_double; pack_double
IMPLEMENTS = unpack_string
IMPLEMENTS = init
MEMBERS=const char* argument
MEMBERS=long start
MEMBERS=long len
MEMBERS=double referenceValue
MEMBERS=double referenceValuePresent
MEMBERS=double scale
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int get_native_type(grib_accessor*);
static int pack_double(grib_accessor*, const double* val, size_t* len);
static int pack_long(grib_accessor*, const long* val, size_t* len);
static int unpack_bytes(grib_accessor*, unsigned char*, size_t* len);
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int unpack_long(grib_accessor*, long* val, size_t* len);
static int unpack_string(grib_accessor*, char*, size_t* len);
static long byte_count(grib_accessor*);
static void init(grib_accessor*, const long, grib_arguments*);
typedef struct grib_accessor_bits
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in bits */
const char* argument;
long start;
long len;
double referenceValue;
double referenceValuePresent;
double scale;
} grib_accessor_bits;
extern grib_accessor_class* grib_accessor_class_gen;
static grib_accessor_class _grib_accessor_class_bits = {
&grib_accessor_class_gen, /* super */
"bits", /* name */
sizeof(grib_accessor_bits), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
0, /* dump */
0, /* next_offset */
0, /* get length of string */
0, /* get number of values */
&byte_count, /* get number of bytes */
0, /* get offset to bytes */
&get_native_type, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
&pack_long, /* pack_long */
&unpack_long, /* unpack_long */
&pack_double, /* pack_double */
0, /* pack_float */
&unpack_double, /* unpack_double */
0, /* unpack_float */
0, /* pack_string */
&unpack_string, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
&unpack_bytes, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
0, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
0, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
grib_accessor_class_bits_t _grib_accessor_class_bits{"bits"};
grib_accessor_class* grib_accessor_class_bits = &_grib_accessor_class_bits;
/* END_CLASS_IMP */
static void init(grib_accessor* a, const long l, grib_arguments* c)
{
grib_accessor_bits* self = (grib_accessor_bits*)a;
void grib_accessor_class_bits_t::init(grib_accessor* a, const long l, grib_arguments* c){
grib_accessor_bits_t* self = (grib_accessor_bits_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
grib_expression* e = NULL;
int n = 0;
@ -154,9 +43,8 @@ static void init(grib_accessor* a, const long l, grib_arguments* c)
a->length = 0;
}
static int unpack_long(grib_accessor* a, long* val, size_t* len)
{
grib_accessor_bits* self = (grib_accessor_bits*)a;
int grib_accessor_class_bits_t::unpack_long(grib_accessor* a, long* val, size_t* len){
grib_accessor_bits_t* self = (grib_accessor_bits_t*)a;
grib_accessor* x = NULL;
unsigned char* p = NULL;
grib_handle* h = grib_handle_of_accessor(a);
@ -173,17 +61,15 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
if (!x)
return GRIB_NOT_FOUND;
p = h->buffer->data + grib_byte_offset(x);
*val = grib_decode_unsigned_long(p, &start, length);
p = h->buffer->data + x->byte_offset(); *val = grib_decode_unsigned_long(p, &start, length);
*len = 1;
return ret;
}
static int unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_bits* self = (grib_accessor_bits*)a;
int grib_accessor_class_bits_t::unpack_double(grib_accessor* a, double* val, size_t* len){
grib_accessor_bits_t* self = (grib_accessor_bits_t*)a;
grib_accessor* x = NULL;
unsigned char* p = NULL;
grib_handle* h = grib_handle_of_accessor(a);
@ -200,8 +86,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
if (!x)
return GRIB_NOT_FOUND;
p = h->buffer->data + grib_byte_offset(x);
*val = grib_decode_unsigned_long(p, &start, length);
p = h->buffer->data + x->byte_offset(); *val = grib_decode_unsigned_long(p, &start, length);
*val = ((long)*val + self->referenceValue) / self->scale;
@ -210,9 +95,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
return ret;
}
static int pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_bits* self = (grib_accessor_bits*)a;
int grib_accessor_class_bits_t::pack_double(grib_accessor* a, const double* val, size_t* len){
grib_accessor_bits_t* self = (grib_accessor_bits_t*)a;
grib_accessor* x = NULL;
grib_handle* h = grib_handle_of_accessor(a);
unsigned char* p = NULL;
@ -228,15 +112,13 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
if (!x)
return GRIB_NOT_FOUND;
p = h->buffer->data + grib_byte_offset(x);
p = h->buffer->data + x->byte_offset();
lval = round(*val * self->scale) - self->referenceValue;
return grib_encode_unsigned_longb(p, lval, &start, length);
}
static int pack_long(grib_accessor* a, const long* val, size_t* len)
{
grib_accessor_bits* self = (grib_accessor_bits*)a;
int grib_accessor_class_bits_t::pack_long(grib_accessor* a, const long* val, size_t* len){
grib_accessor_bits_t* self = (grib_accessor_bits_t*)a;
grib_accessor* x = NULL;
grib_handle* h = grib_handle_of_accessor(a);
unsigned char* p = NULL;
@ -285,14 +167,12 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
return GRIB_ENCODING_ERROR;
}
p = h->buffer->data + grib_byte_offset(x);
return grib_encode_unsigned_longb(p, *val, &start, length);
p = h->buffer->data + x->byte_offset(); return grib_encode_unsigned_longb(p, *val, &start, length);
}
static int get_native_type(grib_accessor* a)
{
int grib_accessor_class_bits_t::get_native_type(grib_accessor* a){
int type = GRIB_TYPE_BYTES;
grib_accessor_bits* self = (grib_accessor_bits*)a;
grib_accessor_bits_t* self = (grib_accessor_bits_t*)a;
if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE)
type = GRIB_TYPE_STRING;
@ -306,8 +186,7 @@ static int get_native_type(grib_accessor* a)
return type;
}
static int unpack_string(grib_accessor* a, char* v, size_t* len)
{
int grib_accessor_class_bits_t::unpack_string(grib_accessor* a, char* v, size_t* len){
int ret = 0;
double dval = 0;
long lval = 0;
@ -328,20 +207,17 @@ static int unpack_string(grib_accessor* a, char* v, size_t* len)
break;
default:
super = *(a->cclass->super);
ret = super->unpack_string(a, v, len);
ret = grib_accessor_class_gen_t::unpack_string(a, v, len);
}
return ret;
}
static long byte_count(grib_accessor* a)
{
long grib_accessor_class_bits_t::byte_count(grib_accessor* a){
grib_context_log(a->context, GRIB_LOG_DEBUG, "byte_count of %s = %ld", a->name, a->length);
return a->length;
}
static int unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len)
{
int grib_accessor_class_bits_t::unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len){
if (*len < a->length) {
*len = a->length;
return GRIB_ARRAY_TOO_SMALL;

View File

@ -0,0 +1,45 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_bits_h
#define eccodes_accessor_bits_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_bits_t : public grib_accessor_gen_t
{
public:
/* Members defined in bits */
const char* argument;
long start;
long len;
double referenceValue;
double referenceValuePresent;
double scale;
};
class grib_accessor_class_bits_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_bits_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_bits_t{}; }
int get_native_type(grib_accessor*) override;
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int pack_long(grib_accessor*, const long* val, size_t* len) override;
int unpack_bytes(grib_accessor*, unsigned char*, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int unpack_long(grib_accessor*, long* val, size_t* len) override;
int unpack_string(grib_accessor*, char*, size_t* len) override;
long byte_count(grib_accessor*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_bits_h */

View File

@ -0,0 +1,73 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_bits_per_value.h"
grib_accessor_class_bits_per_value_t _grib_accessor_class_bits_per_value{"bits_per_value"};
grib_accessor_class* grib_accessor_class_bits_per_value = &_grib_accessor_class_bits_per_value;
void grib_accessor_class_bits_per_value_t::init(grib_accessor* a, const long l, grib_arguments* args){
int n = 0;
grib_accessor_bits_per_value_t* self = (grib_accessor_bits_per_value_t*)a;
self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
self->bits_per_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
a->length = 0;
}
int grib_accessor_class_bits_per_value_t::unpack_long(grib_accessor* a, long* val, size_t* len){
int ret = 0;
grib_accessor_bits_per_value_t* self = (grib_accessor_bits_per_value_t*)a;
grib_handle* h = grib_handle_of_accessor(a);
if ((ret = grib_get_long_internal(h, self->bits_per_value, val)) != GRIB_SUCCESS)
return ret;
*len = 1;
return ret;
}
int grib_accessor_class_bits_per_value_t::pack_long(grib_accessor* a, const long* val, size_t* len){
double* values = NULL;
size_t size = 0;
int ret = 0;
grib_accessor_bits_per_value_t* self = (grib_accessor_bits_per_value_t*)a;
grib_context* c = a->context;
grib_handle* h = grib_handle_of_accessor(a);
if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS)
return ret;
values = (double*)grib_context_malloc(c, size * sizeof(double));
if (!values)
return GRIB_OUT_OF_MEMORY;
if ((ret = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) {
grib_context_free(c, values);
return ret;
}
if ((ret = grib_set_long_internal(h, self->bits_per_value, *val)) != GRIB_SUCCESS) {
grib_context_free(c, values);
return ret;
}
if ((ret = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) {
grib_context_free(c, values);
return ret;
}
grib_context_free(c, values);
return GRIB_SUCCESS;
}

View File

@ -0,0 +1,35 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_bits_per_value_h
#define eccodes_accessor_bits_per_value_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_long.h"
class grib_accessor_bits_per_value_t : public grib_accessor_long_t
{
public:
/* Members defined in bits_per_value */
const char* values;
const char* bits_per_value;
};
class grib_accessor_class_bits_per_value_t : public grib_accessor_class_long_t
{
public:
grib_accessor_class_bits_per_value_t(const char* name) : grib_accessor_class_long_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_bits_per_value_t{}; }
int pack_long(grib_accessor*, const long* val, size_t* len) override;
int unpack_long(grib_accessor*, long* val, size_t* len) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_bits_per_value_h */

View File

@ -0,0 +1,42 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_blob.h"
grib_accessor_class_blob_t _grib_accessor_class_blob{"blob"};
grib_accessor_class* grib_accessor_class_blob = &_grib_accessor_class_blob;
void grib_accessor_class_blob_t::init(grib_accessor* a, const long len, grib_arguments* arg){
grib_get_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, arg, 0), &a->length);
Assert(a->length >= 0);
}
int grib_accessor_class_blob_t::get_native_type(grib_accessor* a){
return GRIB_TYPE_BYTES;
}
int grib_accessor_class_blob_t::unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len){
if (*len < (size_t)a->length) {
*len = a->length;
return GRIB_ARRAY_TOO_SMALL;
}
*len = a->length;
memcpy(buffer, grib_handle_of_accessor(a)->buffer->data + a->offset, *len);
return GRIB_SUCCESS;
}
void grib_accessor_class_blob_t::dump(grib_accessor* a, grib_dumper* dumper){
grib_dump_bytes(dumper, a, NULL);
}

View File

@ -0,0 +1,34 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_blob_h
#define eccodes_accessor_blob_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_blob_t : public grib_accessor_gen_t
{
public:
/* Members defined in blob */
};
class grib_accessor_class_blob_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_blob_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_blob_t{}; }
int get_native_type(grib_accessor*) override;
int unpack_bytes(grib_accessor*, unsigned char*, size_t* len) override;
void dump(grib_accessor*, grib_dumper*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_blob_h */

View File

@ -0,0 +1,82 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_budgdate.h"
grib_accessor_class_budgdate_t _grib_accessor_class_budgdate{"budgdate"};
grib_accessor_class* grib_accessor_class_budgdate = &_grib_accessor_class_budgdate;
void grib_accessor_class_budgdate_t::init(grib_accessor* a, const long l, grib_arguments* c){
grib_accessor_budgdate_t* self = (grib_accessor_budgdate_t*)a;
int n = 0;
self->year = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
self->month = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
self->day = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++);
}
int grib_accessor_class_budgdate_t::unpack_long(grib_accessor* a, long* val, size_t* len){
int ret = 0;
grib_accessor_budgdate_t* self = (grib_accessor_budgdate_t*)a;
long year = 0;
long month = 0;
long day = 0;
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->day, &day)) != GRIB_SUCCESS)
return ret;
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->month, &month)) != GRIB_SUCCESS)
return ret;
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->year, &year)) != GRIB_SUCCESS)
return ret;
if (*len < 1)
return GRIB_WRONG_ARRAY_SIZE;
val[0] = (1900 + year) * 10000 + month * 100 + day;
return ret;
}
/* TODO: Check for a valid date */
int grib_accessor_class_budgdate_t::pack_long(grib_accessor* a, const long* val, size_t* len){
int ret = 0;
long v = val[0];
grib_accessor_budgdate_t* self = (grib_accessor_budgdate_t*)a;
long year = 0;
long month = 0;
long day = 0;
if (*len != 1)
return GRIB_WRONG_ARRAY_SIZE;
year = v / 10000;
v %= 10000;
month = v / 100;
v %= 100;
day = v;
year -= 1900;
Assert(year < 255);
if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->day, day)) != GRIB_SUCCESS)
return ret;
if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->month, month)) != GRIB_SUCCESS)
return ret;
if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->year, year)) != GRIB_SUCCESS)
return ret;
return ret;
}

View File

@ -0,0 +1,36 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_budgdate_h
#define eccodes_accessor_budgdate_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_long.h"
class grib_accessor_budgdate_t : public grib_accessor_long_t
{
public:
/* Members defined in budgdate */
const char* year;
const char* month;
const char* day;
};
class grib_accessor_class_budgdate_t : public grib_accessor_class_long_t
{
public:
grib_accessor_class_budgdate_t(const char* name) : grib_accessor_class_long_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_budgdate_t{}; }
int pack_long(grib_accessor*, const long* val, size_t* len) override;
int unpack_long(grib_accessor*, long* val, size_t* len) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_budgdate_h */

View File

@ -0,0 +1,93 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_bufr_data_array_h
#define eccodes_accessor_bufr_data_array_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_bufr_data_array_t : public grib_accessor_gen_t
{
public:
/* Members defined in bufr_data_array */
const char* bufrDataEncodedName;
const char* numberOfSubsetsName;
const char* expandedDescriptorsName;
const char* flagsName;
const char* unitsName;
const char* elementsDescriptorsIndexName;
const char* compressedDataName;
bufr_descriptors_array* expanded;
grib_accessor* expandedAccessor;
int* canBeMissing;
long numberOfSubsets;
long compressedData;
grib_vdarray* numericValues;
grib_vsarray* stringValues;
grib_viarray* elementsDescriptorsIndex;
int do_decode;
int bitmapStartElementsDescriptorsIndex;
int bitmapCurrentElementsDescriptorsIndex;
int bitmapSize;
int bitmapStart;
int bitmapCurrent;
grib_accessors_list* dataAccessors;
int unpackMode;
int bitsToEndData;
grib_section* dataKeys;
double* inputBitmap;
int nInputBitmap;
int iInputBitmap;
long* inputReplications;
int nInputReplications;
int iInputReplications;
long* inputExtendedReplications;
int nInputExtendedReplications;
int iInputExtendedReplications;
long* inputShortReplications;
int nInputShortReplications;
int iInputShortReplications;
grib_iarray* iss_list;
grib_trie_with_rank* dataAccessorsTrie;
grib_sarray* tempStrings;
grib_vdarray* tempDoubleValues;
int change_ref_value_operand;
size_t refValListSize;
long* refValList;
long refValIndex;
bufr_tableb_override* tableb_override;
int set_to_missing_if_out_of_range;
};
class grib_accessor_class_bufr_data_array_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_bufr_data_array_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_data_array_t{}; }
int get_native_type(grib_accessor*) override;
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int pack_long(grib_accessor*, const long* val, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
long byte_count(grib_accessor*) override;
long byte_offset(grib_accessor*) override;
long next_offset(grib_accessor*) override;
int value_count(grib_accessor*, long*) override;
void destroy(grib_context*, grib_accessor*) override;
void dump(grib_accessor*, grib_dumper*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
grib_vsarray* accessor_bufr_data_array_get_stringValues(grib_accessor* a);
grib_accessors_list* accessor_bufr_data_array_get_dataAccessors(grib_accessor* a);
grib_trie_with_rank* accessor_bufr_data_array_get_dataAccessorsTrie(grib_accessor* a);
void accessor_bufr_data_array_set_unpackMode(grib_accessor* a, int unpackMode);
#endif /* eccodes_accessor_bufr_data_array_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -8,144 +9,19 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
/*****************************************
* Enrico Fucile
****************************************/
#include "grib_api_internal.h"
#include "grib_accessor_class_bufr_data_element.h"
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_gen
IMPLEMENTS = init;dump
IMPLEMENTS = unpack_string;unpack_string_array;unpack_long; unpack_double
IMPLEMENTS = unpack_double_element ; is_missing
IMPLEMENTS = pack_long; pack_double ; pack_string_array; pack_string; pack_missing
IMPLEMENTS = value_count; get_native_type; make_clone; destroy
MEMBERS = long index
MEMBERS = int type
MEMBERS = long compressedData
MEMBERS = long subsetNumber
MEMBERS = long numberOfSubsets
MEMBERS = bufr_descriptors_array* descriptors
MEMBERS = grib_vdarray* numericValues
MEMBERS = grib_vsarray* stringValues
MEMBERS = grib_viarray* elementsDescriptorsIndex
MEMBERS = char* cname
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int get_native_type(grib_accessor*);
static int pack_missing(grib_accessor*);
static int is_missing(grib_accessor*);
static int pack_double(grib_accessor*, const double* val, size_t* len);
static int pack_long(grib_accessor*, const long* val, size_t* len);
static int pack_string(grib_accessor*, const char*, size_t* len);
static int pack_string_array(grib_accessor*, const char**, size_t* len);
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int unpack_long(grib_accessor*, long* val, size_t* len);
static int unpack_string(grib_accessor*, char*, size_t* len);
static int unpack_string_array(grib_accessor*, char**, size_t* len);
static int value_count(grib_accessor*, long*);
static void destroy(grib_context*, grib_accessor*);
static void dump(grib_accessor*, grib_dumper*);
static void init(grib_accessor*, const long, grib_arguments*);
static int unpack_double_element(grib_accessor*, size_t i, double* val);
static grib_accessor* make_clone(grib_accessor*, grib_section*, int*);
typedef struct grib_accessor_bufr_data_element
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in bufr_data_element */
long index;
int type;
long compressedData;
long subsetNumber;
long numberOfSubsets;
bufr_descriptors_array* descriptors;
grib_vdarray* numericValues;
grib_vsarray* stringValues;
grib_viarray* elementsDescriptorsIndex;
char* cname;
} grib_accessor_bufr_data_element;
extern grib_accessor_class* grib_accessor_class_gen;
static grib_accessor_class _grib_accessor_class_bufr_data_element = {
&grib_accessor_class_gen, /* super */
"bufr_data_element", /* name */
sizeof(grib_accessor_bufr_data_element), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
&destroy, /* destroy */
&dump, /* dump */
0, /* next_offset */
0, /* get length of string */
&value_count, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
&get_native_type, /* get native type */
0, /* get sub_section */
&pack_missing, /* pack_missing */
&is_missing, /* is_missing */
&pack_long, /* pack_long */
&unpack_long, /* unpack_long */
&pack_double, /* pack_double */
0, /* pack_float */
&unpack_double, /* unpack_double */
0, /* unpack_float */
&pack_string, /* pack_string */
&unpack_string, /* unpack_string */
&pack_string_array, /* pack_string_array */
&unpack_string_array, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
&unpack_double_element, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
0, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
&make_clone, /* clone accessor */
};
grib_accessor_class_bufr_data_element_t _grib_accessor_class_bufr_data_element{"bufr_data_element"};
grib_accessor_class* grib_accessor_class_bufr_data_element = &_grib_accessor_class_bufr_data_element;
/* END_CLASS_IMP */
static grib_accessor* make_clone(grib_accessor* a, grib_section* s, int* err)
{
grib_accessor* the_clone = NULL;
grib_accessor* attribute = NULL;
grib_accessor_bufr_data_element* elementAccessor;
grib_accessor_bufr_data_element* self;
grib_accessor_bufr_data_element_t* elementAccessor;
grib_accessor_bufr_data_element_t* self;
char* copied_name = NULL;
int i;
grib_action creator = {0,};
@ -161,8 +37,8 @@ static grib_accessor* make_clone(grib_accessor* a, grib_section* s, int* err)
the_clone = grib_accessor_factory(s, &creator, 0, NULL);
copied_name = grib_context_strdup(a->context, a->name);
the_clone->name = copied_name;
elementAccessor = (grib_accessor_bufr_data_element*)the_clone;
self = (grib_accessor_bufr_data_element*)a;
elementAccessor = (grib_accessor_bufr_data_element_t*)the_clone;
self = (grib_accessor_bufr_data_element_t*)a;
the_clone->flags = a->flags;
the_clone->parent = NULL;
the_clone->h = s->h;
@ -179,9 +55,9 @@ static grib_accessor* make_clone(grib_accessor* a, grib_section* s, int* err)
i = 0;
while (a->attributes[i]) {
attribute = grib_accessor_clone(a->attributes[i], s, err);
attribute = a->attributes[i]->clone(s, err);
/* attribute->parent=a->parent; */
grib_accessor_add_attribute(the_clone, attribute, 0);
the_clone->add_attribute(attribute, 0);
i++;
}
@ -190,69 +66,67 @@ static grib_accessor* make_clone(grib_accessor* a, grib_section* s, int* err)
void accessor_bufr_data_element_set_index(grib_accessor* a, long index)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
self->index = index;
}
void accessor_bufr_data_element_set_type(grib_accessor* a, int type)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
self->type = type;
}
void accessor_bufr_data_element_set_numberOfSubsets(grib_accessor* a, long numberOfSubsets)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
self->numberOfSubsets = numberOfSubsets;
}
void accessor_bufr_data_element_set_subsetNumber(grib_accessor* a, long subsetNumber)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
self->subsetNumber = subsetNumber;
}
void accessor_bufr_data_element_set_compressedData(grib_accessor* a, int compressedData)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
self->compressedData = compressedData;
}
void accessor_bufr_data_element_set_descriptors(grib_accessor* a, bufr_descriptors_array* descriptors)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
self->descriptors = descriptors;
}
void accessor_bufr_data_element_set_numericValues(grib_accessor* a, grib_vdarray* numericValues)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
self->numericValues = numericValues;
}
void accessor_bufr_data_element_set_stringValues(grib_accessor* a, grib_vsarray* stringValues)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
self->stringValues = stringValues;
}
void accessor_bufr_data_element_set_elementsDescriptorsIndex(grib_accessor* a, grib_viarray* elementsDescriptorsIndex)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
self->elementsDescriptorsIndex = elementsDescriptorsIndex;
}
static void init(grib_accessor* a, const long len, grib_arguments* params)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
void grib_accessor_class_bufr_data_element_t::init(grib_accessor* a, const long len, grib_arguments* params){
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
a->length = 0;
a->flags |= GRIB_ACCESSOR_FLAG_BUFR_DATA;
/* a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; */
self->cname = NULL;
}
static void dump(grib_accessor* a, grib_dumper* dumper)
{
void grib_accessor_class_bufr_data_element_t::dump(grib_accessor* a, grib_dumper* dumper){
int type = get_native_type(a);
switch (type) {
@ -268,9 +142,8 @@ static void dump(grib_accessor* a, grib_dumper* dumper)
}
}
static int unpack_string_array(grib_accessor* a, char** val, size_t* len)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int grib_accessor_class_bufr_data_element_t::unpack_string_array(grib_accessor* a, char** val, size_t* len){
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
int ret = 0, idx = 0;
size_t count = 0, i = 0;
@ -297,9 +170,8 @@ static int unpack_string_array(grib_accessor* a, char** val, size_t* len)
return ret;
}
static int pack_string_array(grib_accessor* a, const char** v, size_t* len)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int grib_accessor_class_bufr_data_element_t::pack_string_array(grib_accessor* a, const char** v, size_t* len){
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
int ret = GRIB_SUCCESS, idx = 0;
size_t i = 0;
@ -340,9 +212,8 @@ static int pack_string_array(grib_accessor* a, const char** v, size_t* len)
return ret;
}
static int unpack_string(grib_accessor* a, char* val, size_t* len)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int grib_accessor_class_bufr_data_element_t::unpack_string(grib_accessor* a, char* val, size_t* len){
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
char* str = NULL;
char* p = 0;
size_t slen = 0;
@ -409,9 +280,8 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len)
return GRIB_SUCCESS;
}
static int pack_string(grib_accessor* a, const char* val, size_t* len)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int grib_accessor_class_bufr_data_element_t::pack_string(grib_accessor* a, const char* val, size_t* len){
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
int ret = GRIB_SUCCESS, idx = 0;
char* s = NULL;
@ -432,9 +302,8 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len)
return ret;
}
static int unpack_long(grib_accessor* a, long* val, size_t* len)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int grib_accessor_class_bufr_data_element_t::unpack_long(grib_accessor* a, long* val, size_t* len){
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
int ret = GRIB_SUCCESS;
long count = 0, i = 0;
@ -461,9 +330,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
return ret;
}
static int unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int grib_accessor_class_bufr_data_element_t::unpack_double(grib_accessor* a, double* val, size_t* len){
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
int ret = GRIB_SUCCESS;
long count = 0, i = 0;
@ -490,9 +358,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
return ret;
}
static int pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int grib_accessor_class_bufr_data_element_t::pack_double(grib_accessor* a, const double* val, size_t* len){
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
int ret = GRIB_SUCCESS;
size_t count = 1, i = 0;
grib_context* c = a->context;
@ -520,9 +387,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
return ret;
}
static int pack_long(grib_accessor* a, const long* val, size_t* len)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int grib_accessor_class_bufr_data_element_t::pack_long(grib_accessor* a, const long* val, size_t* len){
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
int ret = 0;
size_t count = 1, i = 0;
grib_context* c = a->context;
@ -550,11 +416,10 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
return ret;
}
static int value_count(grib_accessor* a, long* count)
{
int grib_accessor_class_bufr_data_element_t::value_count(grib_accessor* a, long* count){
int ret = 0, type = 0, idx = 0;
size_t size = 0;
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
if (!self->compressedData) {
*count = 1;
@ -577,10 +442,9 @@ static int value_count(grib_accessor* a, long* count)
return ret;
}
static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
{
int grib_accessor_class_bufr_data_element_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){
/* ECC-415 */
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
int ret = GRIB_SUCCESS;
long count = 0;
@ -598,9 +462,8 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
return ret;
}
static int get_native_type(grib_accessor* a)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
int grib_accessor_class_bufr_data_element_t::get_native_type(grib_accessor* a){
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
int ret = GRIB_TYPE_DOUBLE;
DEBUG_ASSERT(self);
switch (self->type) {
@ -624,16 +487,15 @@ static int get_native_type(grib_accessor* a)
return ret;
}
static void destroy(grib_context* ct, grib_accessor* a)
{
grib_accessor_bufr_data_element* self = (grib_accessor_bufr_data_element*)a;
void grib_accessor_class_bufr_data_element_t::destroy(grib_context* ct, grib_accessor* a){
grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a;
int i = 0;
if (self->cname)
grib_context_free(ct, self->cname); /* ECC-765 */
while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) {
/*grib_context_log(ct,GRIB_LOG_DEBUG,"deleting attribute %s->%s",a->name,a->attributes[i]->name);*/
/*printf("bufr_data_element destroy %s %p\n", a->attributes[i]->name, (void*)a->attributes[i]);*/
grib_accessor_delete(ct, a->attributes[i]);
a->attributes[i]->destroy(ct);
a->attributes[i] = NULL;
i++;
}
@ -641,8 +503,7 @@ static void destroy(grib_context* ct, grib_accessor* a)
#define MAX_STRING_SIZE 4096
/* Return 1 if BUFR element(s) is/are missing, 0 otherwise. In case of decoding errors, also return 0 */
static int is_missing(grib_accessor* a)
{
int grib_accessor_class_bufr_data_element_t::is_missing(grib_accessor* a){
const int ktype = get_native_type(a);
int err = 0, result = 1; /* default: assume all are missing */
long count = 0;
@ -657,11 +518,9 @@ static int is_missing(grib_accessor* a)
size = size2 = count;
if (size > 1) {
values = (long*)grib_context_malloc_clear(c, sizeof(long) * size);
err = grib_unpack_long(a, values, &size2);
}
err = a->unpack_long(values, &size2); }
else {
err = grib_unpack_long(a, &value, &size2);
}
err = a->unpack_long(&value, &size2); }
if (err) return 0; /* TODO: no way of propagating the error up */
Assert(size2 == size);
if (size > 1) {
@ -684,11 +543,9 @@ static int is_missing(grib_accessor* a)
size = size2 = count;
if (size > 1) {
values = (double*)grib_context_malloc_clear(c, sizeof(double) * size);
err = grib_unpack_double(a, values, &size2);
}
err = a->unpack_double(values, &size2); }
else {
err = grib_unpack_double(a, &value, &size2);
}
err = a->unpack_double(&value, &size2); }
if (err) return 0; /* TODO: no way of propagating the error up */
Assert(size2 == size);
if (size > 1) {
@ -710,8 +567,7 @@ static int is_missing(grib_accessor* a)
size = count;
if (size > 1) {
values = (char**)grib_context_malloc_clear(a->context, size * sizeof(char*));
err = grib_unpack_string_array(a, values, &size);
if (err) return 0; /* TODO: no way of propagating the error up */
err = a->unpack_string_array(values, &size); if (err) return 0; /* TODO: no way of propagating the error up */
for (i = 0; i < size; i++) {
if (!grib_is_missing_string(a, (unsigned char*)values[i], size)) {
result = 0;
@ -723,8 +579,7 @@ static int is_missing(grib_accessor* a)
} else {
char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */
size = MAX_STRING_SIZE;
err = grib_unpack_string(a, value, &size);
if (err) return 0; /* TODO: no way of propagating the error up */
err = a->unpack_string(value, &size); if (err) return 0; /* TODO: no way of propagating the error up */
result = grib_is_missing_string(a, (unsigned char*)value, size);
}
}
@ -734,8 +589,7 @@ static int is_missing(grib_accessor* a)
return result;
}
static int pack_missing(grib_accessor* a)
{
int grib_accessor_class_bufr_data_element_t::pack_missing(grib_accessor* a){
int ktype = GRIB_TYPE_UNDEFINED;
int err = 0;
size_t size = 1;

View File

@ -0,0 +1,56 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_bufr_data_element_h
#define eccodes_accessor_bufr_data_element_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_bufr_data_element_t : public grib_accessor_gen_t
{
public:
/* Members defined in bufr_data_element */
long index;
int type;
long compressedData;
long subsetNumber;
long numberOfSubsets;
bufr_descriptors_array* descriptors;
grib_vdarray* numericValues;
grib_vsarray* stringValues;
grib_viarray* elementsDescriptorsIndex;
char* cname;
};
class grib_accessor_class_bufr_data_element_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_bufr_data_element_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_data_element_t{}; }
int get_native_type(grib_accessor*) override;
int pack_missing(grib_accessor*) override;
int is_missing(grib_accessor*) override;
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int pack_long(grib_accessor*, const long* val, size_t* len) override;
int pack_string(grib_accessor*, const char*, size_t* len) override;
int pack_string_array(grib_accessor*, const char**, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int unpack_long(grib_accessor*, long* val, size_t* len) override;
int unpack_string(grib_accessor*, char*, size_t* len) override;
int unpack_string_array(grib_accessor*, char**, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void destroy(grib_context*, grib_accessor*) override;
void dump(grib_accessor*, grib_dumper*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
};
#endif /* eccodes_accessor_bufr_data_element_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -8,12 +9,10 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
/*****************************************
* Enrico Fucile
****************************************/
#include "grib_scaling.h"
#include "grib_api_internal.h"
#include "grib_accessor_class_bufr_elements_table.h"
#include "grib_scaling.h"
#if GRIB_PTHREADS
static pthread_once_t once = PTHREAD_ONCE_INIT;
@ -31,7 +30,7 @@ static void thread_init()
static int once = 0;
static omp_nest_lock_t mutex1;
static void thread_init()
void thread_init()
{
GRIB_OMP_CRITICAL(lock_grib_accessor_class_bufr_elements_table_c)
{
@ -43,107 +42,14 @@ static void thread_init()
}
#endif
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_gen
IMPLEMENTS = init;unpack_string;unpack_long;unpack_double
IMPLEMENTS = value_count; get_native_type;
MEMBERS = const char* dictionary
MEMBERS = const char* masterDir
MEMBERS = const char* localDir
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int get_native_type(grib_accessor*);
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int unpack_long(grib_accessor*, long* val, size_t* len);
static int unpack_string(grib_accessor*, char*, size_t* len);
static int value_count(grib_accessor*, long*);
static void init(grib_accessor*, const long, grib_arguments*);
typedef struct grib_accessor_bufr_elements_table
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in bufr_elements_table */
const char* dictionary;
const char* masterDir;
const char* localDir;
} grib_accessor_bufr_elements_table;
extern grib_accessor_class* grib_accessor_class_gen;
static grib_accessor_class _grib_accessor_class_bufr_elements_table = {
&grib_accessor_class_gen, /* super */
"bufr_elements_table", /* name */
sizeof(grib_accessor_bufr_elements_table), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
0, /* dump */
0, /* next_offset */
0, /* get length of string */
&value_count, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
&get_native_type, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
0, /* pack_long */
&unpack_long, /* unpack_long */
0, /* pack_double */
0, /* pack_float */
&unpack_double, /* unpack_double */
0, /* unpack_float */
0, /* pack_string */
&unpack_string, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
0, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
0, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
grib_accessor_class_bufr_elements_table_t _grib_accessor_class_bufr_elements_table{"bufr_elements_table"};
grib_accessor_class* grib_accessor_class_bufr_elements_table = &_grib_accessor_class_bufr_elements_table;
/* END_CLASS_IMP */
static void init(grib_accessor* a, const long len, grib_arguments* params)
{
void grib_accessor_class_bufr_elements_table_t::init(grib_accessor* a, const long len, grib_arguments* params){
int n = 0;
grib_accessor_bufr_elements_table* self = (grib_accessor_bufr_elements_table*)a;
grib_accessor_bufr_elements_table_t* self = (grib_accessor_bufr_elements_table_t*)a;
self->dictionary = grib_arguments_get_string(grib_handle_of_accessor(a), params, n++);
self->masterDir = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++);
@ -155,7 +61,7 @@ static void init(grib_accessor* a, const long len, grib_arguments* params)
static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err)
{
grib_accessor_bufr_elements_table* self = (grib_accessor_bufr_elements_table*)a;
grib_accessor_bufr_elements_table_t* self = (grib_accessor_bufr_elements_table_t*)a;
char* filename = NULL;
char line[1024] = {0,};
@ -273,8 +179,7 @@ the_end:
return dictionary;
}
static int convert_type(const char* stype)
{
int convert_type(const char* stype){
int ret = BUFR_DESCRIPTOR_TYPE_UNKNOWN;
switch (stype[0]) {
case 's':
@ -304,14 +209,13 @@ static int convert_type(const char* stype)
return ret;
}
static long atol_fast(const char* input)
{
long atol_fast(const char* input){
if (strcmp(input, "0") == 0)
return 0;
return atol(input);
}
static int bufr_get_from_table(grib_accessor* a, bufr_descriptor* v)
{
int bufr_get_from_table(grib_accessor* a, bufr_descriptor* v){
int ret = 0;
char** list = 0;
char code[7] = { 0 };
@ -407,28 +311,23 @@ bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, i
return v;
}
static int unpack_string(grib_accessor* a, char* buffer, size_t* len)
{
int grib_accessor_class_bufr_elements_table_t::unpack_string(grib_accessor* a, char* buffer, size_t* len){
return GRIB_NOT_IMPLEMENTED;
}
static int value_count(grib_accessor* a, long* count)
{
int grib_accessor_class_bufr_elements_table_t::value_count(grib_accessor* a, long* count){
*count = 1;
return 0;
}
static int get_native_type(grib_accessor* a)
{
int grib_accessor_class_bufr_elements_table_t::get_native_type(grib_accessor* a){
return GRIB_TYPE_STRING;
}
static int unpack_long(grib_accessor* a, long* val, size_t* len)
{
int grib_accessor_class_bufr_elements_table_t::unpack_long(grib_accessor* a, long* val, size_t* len){
return GRIB_NOT_IMPLEMENTED;
}
static int unpack_double(grib_accessor* a, double* val, size_t* len)
{
int grib_accessor_class_bufr_elements_table_t::unpack_double(grib_accessor* a, double* val, size_t* len){
return GRIB_NOT_IMPLEMENTED;
}

View File

@ -0,0 +1,39 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_bufr_elements_table_h
#define eccodes_accessor_bufr_elements_table_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_bufr_elements_table_t : public grib_accessor_gen_t
{
public:
/* Members defined in bufr_elements_table */
const char* dictionary;
const char* masterDir;
const char* localDir;
};
class grib_accessor_class_bufr_elements_table_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_bufr_elements_table_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_elements_table_t{}; }
int get_native_type(grib_accessor*) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int unpack_long(grib_accessor*, long* val, size_t* len) override;
int unpack_string(grib_accessor*, char*, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_bufr_elements_table_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -9,117 +10,14 @@
*/
#include "grib_api_internal.h"
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_gen
IMPLEMENTS = init; get_native_type
IMPLEMENTS = pack_long;
MEMBERS = const char* doExtractSubsets
MEMBERS = const char* numberOfSubsets
MEMBERS = const char* extractSubsetList
MEMBERS = const char* extractAreaWestLongitude
MEMBERS = const char* extractAreaEastLongitude
MEMBERS = const char* extractAreaNorthLatitude
MEMBERS = const char* extractAreaSouthLatitude
MEMBERS = const char* extractAreaLongitudeRank
MEMBERS = const char* extractAreaLatitudeRank
MEMBERS = const char* extractedAreaNumberOfSubsets
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int get_native_type(grib_accessor*);
static int pack_long(grib_accessor*, const long* val, size_t* len);
static void init(grib_accessor*, const long, grib_arguments*);
typedef struct grib_accessor_bufr_extract_area_subsets
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in bufr_extract_area_subsets */
const char* doExtractSubsets;
const char* numberOfSubsets;
const char* extractSubsetList;
const char* extractAreaWestLongitude;
const char* extractAreaEastLongitude;
const char* extractAreaNorthLatitude;
const char* extractAreaSouthLatitude;
const char* extractAreaLongitudeRank;
const char* extractAreaLatitudeRank;
const char* extractedAreaNumberOfSubsets;
} grib_accessor_bufr_extract_area_subsets;
extern grib_accessor_class* grib_accessor_class_gen;
static grib_accessor_class _grib_accessor_class_bufr_extract_area_subsets = {
&grib_accessor_class_gen, /* super */
"bufr_extract_area_subsets", /* name */
sizeof(grib_accessor_bufr_extract_area_subsets), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
0, /* dump */
0, /* next_offset */
0, /* get length of string */
0, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
&get_native_type, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
&pack_long, /* pack_long */
0, /* unpack_long */
0, /* pack_double */
0, /* pack_float */
0, /* unpack_double */
0, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
0, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
0, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
#include "grib_accessor_class_bufr_extract_area_subsets.h"
grib_accessor_class_bufr_extract_area_subsets_t _grib_accessor_class_bufr_extract_area_subsets{"bufr_extract_area_subsets"};
grib_accessor_class* grib_accessor_class_bufr_extract_area_subsets = &_grib_accessor_class_bufr_extract_area_subsets;
/* END_CLASS_IMP */
static void init(grib_accessor* a, const long len, grib_arguments* arg)
{
grib_accessor_bufr_extract_area_subsets* self = (grib_accessor_bufr_extract_area_subsets*)a;
void grib_accessor_class_bufr_extract_area_subsets_t::init(grib_accessor* a, const long len, grib_arguments* arg){
grib_accessor_bufr_extract_area_subsets_t* self = (grib_accessor_bufr_extract_area_subsets_t*)a;
grib_handle* h = grib_handle_of_accessor(a);
int n = 0;
@ -138,22 +36,19 @@ static void init(grib_accessor* a, const long len, grib_arguments* arg)
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
}
static int get_native_type(grib_accessor* a)
{
int grib_accessor_class_bufr_extract_area_subsets_t::get_native_type(grib_accessor* a){
return GRIB_TYPE_LONG;
}
/* Copy first element of array into all others */
static void fill_in(double a[], long length)
{
void fill_in(double a[], long length){
long i;
for (i = 1; i < length; ++i)
a[i] = a[0];
}
static int select_area(grib_accessor* a)
{
grib_accessor_bufr_extract_area_subsets* self = (grib_accessor_bufr_extract_area_subsets*)a;
int select_area(grib_accessor* a){
grib_accessor_bufr_extract_area_subsets_t* self = (grib_accessor_bufr_extract_area_subsets_t*)a;
int ret = 0;
long compressed = 0;
@ -281,9 +176,8 @@ static int select_area(grib_accessor* a)
return ret;
}
static int pack_long(grib_accessor* a, const long* val, size_t* len)
{
/*grib_accessor_bufr_extract_area_subsets *self =(grib_accessor_bufr_extract_area_subsets*)a;*/
int grib_accessor_class_bufr_extract_area_subsets_t::pack_long(grib_accessor* a, const long* val, size_t* len){
/*grib_accessor_bufr_extract_area_subsets_t *self =(grib_accessor_bufr_extract_area_subsets_t*)a;*/
if (*len == 0)
return GRIB_SUCCESS;

View File

@ -0,0 +1,43 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_bufr_extract_area_subsets_h
#define eccodes_accessor_bufr_extract_area_subsets_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_bufr_extract_area_subsets_t : public grib_accessor_gen_t
{
public:
/* Members defined in bufr_extract_area_subsets */
const char* doExtractSubsets;
const char* numberOfSubsets;
const char* extractSubsetList;
const char* extractAreaWestLongitude;
const char* extractAreaEastLongitude;
const char* extractAreaNorthLatitude;
const char* extractAreaSouthLatitude;
const char* extractAreaLongitudeRank;
const char* extractAreaLatitudeRank;
const char* extractedAreaNumberOfSubsets;
};
class grib_accessor_class_bufr_extract_area_subsets_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_bufr_extract_area_subsets_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_extract_area_subsets_t{}; }
int get_native_type(grib_accessor*) override;
int pack_long(grib_accessor*, const long* val, size_t* len) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_bufr_extract_area_subsets_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -9,104 +10,15 @@
*/
#include "grib_api_internal.h"
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_gen
IMPLEMENTS = init; get_native_type
IMPLEMENTS = pack_long;
MEMBERS = const char* doExtractSubsets
MEMBERS = const char* numberOfSubsets
MEMBERS = const char* extractSubsetList
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int get_native_type(grib_accessor*);
static int pack_long(grib_accessor*, const long* val, size_t* len);
static void init(grib_accessor*, const long, grib_arguments*);
typedef struct grib_accessor_bufr_extract_datetime_subsets
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in bufr_extract_datetime_subsets */
const char* doExtractSubsets;
const char* numberOfSubsets;
const char* extractSubsetList;
} grib_accessor_bufr_extract_datetime_subsets;
extern grib_accessor_class* grib_accessor_class_gen;
static grib_accessor_class _grib_accessor_class_bufr_extract_datetime_subsets = {
&grib_accessor_class_gen, /* super */
"bufr_extract_datetime_subsets", /* name */
sizeof(grib_accessor_bufr_extract_datetime_subsets), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
0, /* dump */
0, /* next_offset */
0, /* get length of string */
0, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
&get_native_type, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
&pack_long, /* pack_long */
0, /* unpack_long */
0, /* pack_double */
0, /* pack_float */
0, /* unpack_double */
0, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
0, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
0, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
#include "grib_accessor_class_bufr_extract_datetime_subsets.h"
grib_accessor_class_bufr_extract_datetime_subsets_t _grib_accessor_class_bufr_extract_datetime_subsets{"bufr_extract_datetime_subsets"};
grib_accessor_class* grib_accessor_class_bufr_extract_datetime_subsets = &_grib_accessor_class_bufr_extract_datetime_subsets;
/* END_CLASS_IMP */
static void init(grib_accessor* a, const long len, grib_arguments* arg)
{
void grib_accessor_class_bufr_extract_datetime_subsets_t::init(grib_accessor* a, const long len, grib_arguments* arg){
int n = 0;
grib_accessor_bufr_extract_datetime_subsets* self = (grib_accessor_bufr_extract_datetime_subsets*)a;
grib_accessor_bufr_extract_datetime_subsets_t* self = (grib_accessor_bufr_extract_datetime_subsets_t*)a;
a->length = 0;
self->doExtractSubsets = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++);
@ -116,14 +28,12 @@ static void init(grib_accessor* a, const long len, grib_arguments* arg)
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
}
static int get_native_type(grib_accessor* a)
{
int grib_accessor_class_bufr_extract_datetime_subsets_t::get_native_type(grib_accessor* a){
return GRIB_TYPE_LONG;
}
/* Convert input date to Julian number. If date is invalid, return -1 */
static double date_to_julian(long year, long month, long day, long hour, long minute, double second)
{
double date_to_julian(long year, long month, long day, long hour, long minute, double second){
double result = 0; /* Julian number in units of days */
/* For validating the date/time, we specify seconds as an integer */
@ -194,11 +104,10 @@ static int build_long_array(grib_context* c, grib_handle* h, int compressed,
return err;
}
static int select_datetime(grib_accessor* a)
{
int select_datetime(grib_accessor* a){
int ret = 0;
long compressed = 0;
grib_accessor_bufr_extract_datetime_subsets* self = (grib_accessor_bufr_extract_datetime_subsets*)a;
grib_accessor_bufr_extract_datetime_subsets_t* self = (grib_accessor_bufr_extract_datetime_subsets_t*)a;
grib_handle* h = grib_handle_of_accessor(a);
grib_context* c = h->context;
size_t n;
@ -423,9 +332,8 @@ cleanup:
return ret;
}
static int pack_long(grib_accessor* a, const long* val, size_t* len)
{
/*grib_accessor_bufr_extract_datetime_subsets *self =(grib_accessor_bufr_extract_datetime_subsets*)a;*/
int grib_accessor_class_bufr_extract_datetime_subsets_t::pack_long(grib_accessor* a, const long* val, size_t* len){
/*grib_accessor_bufr_extract_datetime_subsets_t *self =(grib_accessor_bufr_extract_datetime_subsets_t*)a;*/
if (*len == 0)
return GRIB_SUCCESS;

View File

@ -0,0 +1,36 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_bufr_extract_datetime_subsets_h
#define eccodes_accessor_bufr_extract_datetime_subsets_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_bufr_extract_datetime_subsets_t : public grib_accessor_gen_t
{
public:
/* Members defined in bufr_extract_datetime_subsets */
const char* doExtractSubsets;
const char* numberOfSubsets;
const char* extractSubsetList;
};
class grib_accessor_class_bufr_extract_datetime_subsets_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_bufr_extract_datetime_subsets_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_extract_datetime_subsets_t{}; }
int get_native_type(grib_accessor*) override;
int pack_long(grib_accessor*, const long* val, size_t* len) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_bufr_extract_datetime_subsets_h */

View File

@ -0,0 +1,58 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_bufr_extract_subsets.h"
grib_accessor_class_bufr_extract_subsets_t _grib_accessor_class_bufr_extract_subsets{"bufr_extract_subsets"};
grib_accessor_class* grib_accessor_class_bufr_extract_subsets = &_grib_accessor_class_bufr_extract_subsets;
void get_accessors(grib_accessor* a){
grib_accessor_bufr_extract_subsets_t* self = (grib_accessor_bufr_extract_subsets_t*)a;
const grib_handle* h = grib_handle_of_accessor(a);
if (self->packAccessor)
return;
self->numericValuesAccessor = grib_find_accessor(h, self->numericValues);
self->packAccessor = grib_find_accessor(h, self->pack);
}
void grib_accessor_class_bufr_extract_subsets_t::init(grib_accessor* a, const long len, grib_arguments* arg){
int n = 0;
grib_accessor_bufr_extract_subsets_t* self = (grib_accessor_bufr_extract_subsets_t*)a;
a->length = 0;
self->numericValues = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++);
self->pack = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++);
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
}
int grib_accessor_class_bufr_extract_subsets_t::get_native_type(grib_accessor* a){
return GRIB_TYPE_LONG;
}
int grib_accessor_class_bufr_extract_subsets_t::pack_long(grib_accessor* a, const long* val, size_t* len){
grib_accessor_bufr_extract_subsets_t* self = (grib_accessor_bufr_extract_subsets_t*)a;
size_t l = 1;
long v[1];
get_accessors(a);
v[0] = 1;
int err = self->packAccessor->pack_long(v, &l); if (err) {
if (err == GRIB_ENCODING_ERROR)
grib_context_log(a->context, GRIB_LOG_ERROR, "Could not extract subset(s).\n\tHint: Did you forget to set unpack=1?");
return err;
}
return err;
}

View File

@ -0,0 +1,37 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_bufr_extract_subsets_h
#define eccodes_accessor_bufr_extract_subsets_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_bufr_extract_subsets_t : public grib_accessor_gen_t
{
public:
/* Members defined in bufr_extract_subsets */
const char* numericValues;
const char* pack;
grib_accessor* numericValuesAccessor;
grib_accessor* packAccessor;
};
class grib_accessor_class_bufr_extract_subsets_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_bufr_extract_subsets_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_extract_subsets_t{}; }
int get_native_type(grib_accessor*) override;
int pack_long(grib_accessor*, const long* val, size_t* len) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_bufr_extract_subsets_h */

View File

@ -0,0 +1,39 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_bufr_group.h"
grib_accessor_class_bufr_group_t _grib_accessor_class_bufr_group{"bufr_group"};
grib_accessor_class* grib_accessor_class_bufr_group = &_grib_accessor_class_bufr_group;
void grib_accessor_class_bufr_group_t::dump(grib_accessor* a, grib_dumper* dumper){
grib_dump_section(dumper, a, a->sub_section->block);
}
static grib_accessor* next(grib_accessor* a, int explore)
{
grib_accessor* next = NULL;
if (explore) {
next = a->sub_section->block->first;
if (!next)
next = a->next;
}
else {
next = a->next;
}
if (!next) {
if (a->parent->owner)
next = a->parent->owner->cclass->next(a->parent->owner, 0);
}
return next;
}

View File

@ -0,0 +1,31 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_bufr_group_h
#define eccodes_accessor_bufr_group_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_variable.h"
class grib_accessor_bufr_group_t : public grib_accessor_variable_t
{
public:
/* Members defined in bufr_group */
};
class grib_accessor_class_bufr_group_t : public grib_accessor_class_variable_t
{
public:
grib_accessor_class_bufr_group_t(const char* name) : grib_accessor_class_variable_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_group_t{}; }
void dump(grib_accessor*, grib_dumper*) override;
};
#endif /* eccodes_accessor_bufr_group_h */

View File

@ -0,0 +1,114 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_bufr_simple_thinning.h"
grib_accessor_class_bufr_simple_thinning_t _grib_accessor_class_bufr_simple_thinning{"bufr_simple_thinning"};
grib_accessor_class* grib_accessor_class_bufr_simple_thinning = &_grib_accessor_class_bufr_simple_thinning;
void grib_accessor_class_bufr_simple_thinning_t::init(grib_accessor* a, const long len, grib_arguments* arg){
grib_accessor_bufr_simple_thinning_t* self = (grib_accessor_bufr_simple_thinning_t*)a;
grib_handle* h = grib_handle_of_accessor(a);
int n = 0;
a->length = 0;
self->doExtractSubsets = grib_arguments_get_name(h, arg, n++);
self->numberOfSubsets = grib_arguments_get_name(h, arg, n++);
self->extractSubsetList = grib_arguments_get_name(h, arg, n++);
self->simpleThinningStart = grib_arguments_get_name(h, arg, n++);
self->simpleThinningMissingRadius = grib_arguments_get_name(h, arg, n++);
self->simpleThinningSkip = grib_arguments_get_name(h, arg, n++);
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
}
int grib_accessor_class_bufr_simple_thinning_t::get_native_type(grib_accessor* a){
return GRIB_TYPE_LONG;
}
int apply_thinning(grib_accessor* a){
const grib_accessor_bufr_simple_thinning_t* self = (grib_accessor_bufr_simple_thinning_t*)a;
long skip;
grib_handle* h = grib_handle_of_accessor(a);
grib_context* c = h->context;
long compressed = 0, nsubsets;
grib_iarray* subsets;
long* subsets_ar = 0;
long start = 0, radius = 0;
int ret = grib_get_long(h, "compressedData", &compressed);
if (ret)
return ret;
if (compressed) {
long numberOfSubsets = 0;
ret = grib_get_long(h, self->numberOfSubsets, &numberOfSubsets);
if (ret)
return ret;
ret = grib_get_long(h, self->simpleThinningStart, &start);
if (ret)
return ret;
ret = grib_get_long(h, self->simpleThinningSkip, &skip);
if (ret)
return ret;
if (skip <= 0)
return GRIB_INVALID_KEY_VALUE;
ret = grib_get_long(h, self->simpleThinningMissingRadius, &radius);
if (ret)
return ret;
subsets = grib_iarray_new(c, numberOfSubsets / skip + 1, 10);
for (long i = 0; i < numberOfSubsets; i += skip + 1) {
grib_iarray_push(subsets, i + 1);
}
nsubsets = grib_iarray_used_size(subsets);
if (nsubsets != 0) {
subsets_ar = grib_iarray_get_array(subsets);
ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets);
grib_context_free(c, subsets_ar);
if (ret)
return ret;
ret = grib_set_long(h, "unpack", 1);
if (ret)
return ret;
ret = grib_set_long(h, self->doExtractSubsets, 1);
if (ret)
return ret;
}
grib_iarray_delete(subsets);
}
else {
return GRIB_NOT_IMPLEMENTED;
}
return ret;
}
int grib_accessor_class_bufr_simple_thinning_t::pack_long(grib_accessor* a, const long* val, size_t* len){
const grib_accessor_bufr_simple_thinning_t* self = (grib_accessor_bufr_simple_thinning_t*)a;
if (*len == 0)
return GRIB_SUCCESS;
int err = apply_thinning(a);
if (err)
return err;
return grib_set_long(a->parent->h, self->doExtractSubsets, 1);
}

View File

@ -0,0 +1,39 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_bufr_simple_thinning_h
#define eccodes_accessor_bufr_simple_thinning_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_bufr_simple_thinning_t : public grib_accessor_gen_t
{
public:
/* Members defined in bufr_simple_thinning */
const char* doExtractSubsets;
const char* numberOfSubsets;
const char* extractSubsetList;
const char* simpleThinningStart;
const char* simpleThinningMissingRadius;
const char* simpleThinningSkip;
};
class grib_accessor_class_bufr_simple_thinning_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_bufr_simple_thinning_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_simple_thinning_t{}; }
int get_native_type(grib_accessor*) override;
int pack_long(grib_accessor*, const long* val, size_t* len) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_bufr_simple_thinning_h */

View File

@ -0,0 +1,84 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_bufr_string_values.h"
#include "grib_accessor_class_bufr_data_array.h"
grib_accessor_class_bufr_string_values_t _grib_accessor_class_bufr_string_values{"bufr_string_values"};
grib_accessor_class* grib_accessor_class_bufr_string_values = &_grib_accessor_class_bufr_string_values;
void grib_accessor_class_bufr_string_values_t::init(grib_accessor* a, const long len, grib_arguments* args){
grib_accessor_bufr_string_values_t* self = (grib_accessor_bufr_string_values_t*)a;
int n = 0;
self->dataAccessorName = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
self->dataAccessor = NULL;
a->length = 0;
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
}
void grib_accessor_class_bufr_string_values_t::dump(grib_accessor* a, grib_dumper* dumper){
grib_dump_string_array(dumper, a, NULL);
}
static grib_accessor* get_accessor(grib_accessor* a)
{
grib_accessor_bufr_string_values_t* self = (grib_accessor_bufr_string_values_t*)a;
if (!self->dataAccessor) {
self->dataAccessor = grib_find_accessor(grib_handle_of_accessor(a), self->dataAccessorName);
}
return self->dataAccessor;
}
int grib_accessor_class_bufr_string_values_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len){
grib_accessor* data = 0;
grib_context* c = a->context;
grib_vsarray* stringValues = NULL;
size_t l = 0, tl;
size_t i, j, n = 0;
char** b = buffer;
data = get_accessor(a);
if (!data)
return GRIB_NOT_FOUND;
stringValues = accessor_bufr_data_array_get_stringValues(data);
n = grib_vsarray_used_size(stringValues);
tl = 0;
for (j = 0; j < n; j++) {
l = grib_sarray_used_size(stringValues->v[j]);
tl += l;
if (tl > *len)
return GRIB_ARRAY_TOO_SMALL;
for (i = 0; i < l; i++) {
*(b++) = grib_context_strdup(c, stringValues->v[j]->v[i]);
}
}
*len = tl;
return GRIB_SUCCESS;
}
int grib_accessor_class_bufr_string_values_t::unpack_string(grib_accessor* a, char* val, size_t* len){
return GRIB_NOT_IMPLEMENTED;
}
int grib_accessor_class_bufr_string_values_t::value_count(grib_accessor* a, long* rlen){
grib_accessor* descriptors = get_accessor(a);
return descriptors->value_count(rlen);}
void grib_accessor_class_bufr_string_values_t::destroy(grib_context* c, grib_accessor* a){
}

View File

@ -0,0 +1,38 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_bufr_string_values_h
#define eccodes_accessor_bufr_string_values_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_ascii.h"
class grib_accessor_bufr_string_values_t : public grib_accessor_ascii_t
{
public:
/* Members defined in bufr_string_values */
const char* dataAccessorName;
grib_accessor* dataAccessor;
};
class grib_accessor_class_bufr_string_values_t : public grib_accessor_class_ascii_t
{
public:
grib_accessor_class_bufr_string_values_t(const char* name) : grib_accessor_class_ascii_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_string_values_t{}; }
int unpack_string(grib_accessor*, char*, size_t* len) override;
int unpack_string_array(grib_accessor*, char**, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void destroy(grib_context*, grib_accessor*) override;
void dump(grib_accessor*, grib_dumper*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_bufr_string_values_h */

View File

@ -0,0 +1,98 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_bufrdc_expanded_descriptors.h"
grib_accessor_class_bufrdc_expanded_descriptors_t _grib_accessor_class_bufrdc_expanded_descriptors{"bufrdc_expanded_descriptors"};
grib_accessor_class* grib_accessor_class_bufrdc_expanded_descriptors = &_grib_accessor_class_bufrdc_expanded_descriptors;
void grib_accessor_class_bufrdc_expanded_descriptors_t::init(grib_accessor* a, const long len, grib_arguments* args){
grib_accessor_bufrdc_expanded_descriptors_t* self = (grib_accessor_bufrdc_expanded_descriptors_t*)a;
int n = 0;
self->expandedDescriptors = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
self->expandedDescriptorsAccessor = 0;
a->length = 0;
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
}
static grib_accessor* get_accessor(grib_accessor* a)
{
grib_accessor_bufrdc_expanded_descriptors_t* self = (grib_accessor_bufrdc_expanded_descriptors_t*)a;
if (!self->expandedDescriptorsAccessor) {
self->expandedDescriptorsAccessor = grib_find_accessor(grib_handle_of_accessor(a), self->expandedDescriptors);
}
return self->expandedDescriptorsAccessor;
}
int grib_accessor_class_bufrdc_expanded_descriptors_t::unpack_long(grib_accessor* a, long* val, size_t* len){
grib_accessor* descriptors = 0;
size_t rlen = 0, l;
long lenall = 0;
size_t i = 0;
long* v = 0;
grib_context* c = a->context;
descriptors = get_accessor(a);
if (!descriptors) return GRIB_NOT_FOUND;
a->value_count(&lenall); v = (long*)grib_context_malloc_clear(c, sizeof(long) * lenall);
l = lenall;
descriptors->unpack_long(v, &l);
rlen = 0;
for (i = 0; i < l; i++) {
if ((v[i] < 100000 || v[i] > 221999))
val[rlen++] = v[i];
}
*len = rlen;
grib_context_free(c,v);
return GRIB_SUCCESS;
}
int grib_accessor_class_bufrdc_expanded_descriptors_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len){
int err = 0;
grib_accessor* descriptors = 0;
size_t l = 0;
long lenall = 0;
size_t i = 0;
long* v = 0;
char buf[25] = {0,};
grib_context* c = a->context;
descriptors = get_accessor(a);
if (!descriptors) return GRIB_NOT_FOUND;
err = a->value_count(&lenall); if (err) return err;
l = lenall;
if (l > *len) return GRIB_ARRAY_TOO_SMALL;
v = (long*)grib_context_malloc_clear(c, sizeof(long) * l);
err = descriptors->unpack_long(v, &l); if (err) return err;
for (i = 0; i < l; i++) {
snprintf(buf, sizeof(buf), "%06ld", v[i]);
buffer[i] = grib_context_strdup(c, buf);
}
*len = l;
grib_context_free(c,v);
return GRIB_SUCCESS;
}
int grib_accessor_class_bufrdc_expanded_descriptors_t::value_count(grib_accessor* a, long* rlen){
grib_accessor* descriptors = get_accessor(a);
return descriptors->value_count(rlen);}
void grib_accessor_class_bufrdc_expanded_descriptors_t::destroy(grib_context* c, grib_accessor* a){
}

View File

@ -0,0 +1,37 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_bufrdc_expanded_descriptors_h
#define eccodes_accessor_bufrdc_expanded_descriptors_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_long.h"
class grib_accessor_bufrdc_expanded_descriptors_t : public grib_accessor_long_t
{
public:
/* Members defined in bufrdc_expanded_descriptors */
const char* expandedDescriptors;
grib_accessor* expandedDescriptorsAccessor;
};
class grib_accessor_class_bufrdc_expanded_descriptors_t : public grib_accessor_class_long_t
{
public:
grib_accessor_class_bufrdc_expanded_descriptors_t(const char* name) : grib_accessor_class_long_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_bufrdc_expanded_descriptors_t{}; }
int unpack_long(grib_accessor*, long* val, size_t* len) override;
int unpack_string_array(grib_accessor*, char**, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void destroy(grib_context*, grib_accessor*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_bufrdc_expanded_descriptors_h */

View File

@ -0,0 +1,99 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_bytes.h"
grib_accessor_class_bytes_t _grib_accessor_class_bytes{"bytes"};
grib_accessor_class* grib_accessor_class_bytes = &_grib_accessor_class_bytes;
void grib_accessor_class_bytes_t::init(grib_accessor* a, const long len, grib_arguments* arg){
/*grib_accessor_signed* self = (grib_accessor_signed*)a; */
a->length = len;
Assert(a->length >= 0);
}
int grib_accessor_class_bytes_t::get_native_type(grib_accessor* a){
return GRIB_TYPE_BYTES;
}
int grib_accessor_class_bytes_t::compare(grib_accessor* a, grib_accessor* b){
int retval = GRIB_SUCCESS;
size_t alen = (size_t)a->byte_count(); size_t blen = (size_t)b->byte_count();
if (alen != blen)
return GRIB_COUNT_MISMATCH;
return retval;
}
int grib_accessor_class_bytes_t::unpack_string(grib_accessor* a, char* v, size_t* len){
unsigned char* p = NULL;
char* s = v;
long i = 0;
const long length = a->byte_count(); const long slength = 2 * length;
if (*len < (size_t)slength) {
*len = slength;
return GRIB_BUFFER_TOO_SMALL;
}
p = grib_handle_of_accessor(a)->buffer->data + a->byte_offset();
for (i = 0; i < length; i++) {
snprintf(s, INT_MAX, "%02x", *(p++));
s += 2;
}
*len = slength;
return GRIB_SUCCESS;
}
int grib_accessor_class_bytes_t::pack_string(grib_accessor* a, const char* val, size_t* len){
/* The string representation (val) of the byte array will have two chars
* per byte e.g. 4C5B means the 2 bytes 0114 and 0133 in octal
* so has to be twice the length of the byte array
*/
int err = 0;
grib_context* c = a->context;
size_t nbytes = a->length;
const size_t expected_blen = nbytes;
const size_t expected_slen = 2 * expected_blen;
unsigned char* bytearray = NULL;
size_t i = 0, slen = strlen(val);
if (slen != expected_slen || *len != expected_slen) {
grib_context_log(c, GRIB_LOG_ERROR,
"%s: Key %s is %lu bytes. Expected a string with %lu characters (actual length=%zu)",
__func__, a->name, expected_blen, expected_slen, *len);
return GRIB_WRONG_ARRAY_SIZE;
}
bytearray = (unsigned char*)grib_context_malloc(c, nbytes * (sizeof(unsigned char)));
if (!bytearray) return GRIB_OUT_OF_MEMORY;
for (i = 0; i < (slen/2); i++) {
unsigned int byteVal = 0;
if (sscanf(val + 2*i, "%02x", &byteVal) != 1) {
grib_context_log(c, GRIB_LOG_ERROR,"%s: Invalid hex byte specfication '%.2s'", __func__, val + 2*i);
grib_context_free(c, bytearray);
return GRIB_INVALID_KEY_VALUE;
}
Assert(byteVal < 256);
bytearray[i] = (int)byteVal;
}
/* Forward to base class to pack the byte array */
err = grib_accessor_class_gen_t::pack_bytes(a, bytearray, &nbytes);
grib_context_free(c, bytearray);
return err;
}

View File

@ -0,0 +1,35 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_bytes_h
#define eccodes_accessor_bytes_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_bytes_t : public grib_accessor_gen_t
{
public:
/* Members defined in bytes */
};
class grib_accessor_class_bytes_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_bytes_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_bytes_t{}; }
int get_native_type(grib_accessor*) override;
int pack_string(grib_accessor*, const char*, size_t* len) override;
int unpack_string(grib_accessor*, char*, size_t* len) override;
void init(grib_accessor*, const long, grib_arguments*) override;
int compare(grib_accessor*, grib_accessor*) override;
};
#endif /* eccodes_accessor_bytes_h */

View File

@ -0,0 +1,117 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_change_alternative_row_scanning.h"
grib_accessor_class_change_alternative_row_scanning_t _grib_accessor_class_change_alternative_row_scanning{"change_alternative_row_scanning"};
grib_accessor_class* grib_accessor_class_change_alternative_row_scanning = &_grib_accessor_class_change_alternative_row_scanning;
void grib_accessor_class_change_alternative_row_scanning_t::init(grib_accessor* a, const long len, grib_arguments* args){
int n = 0;
grib_accessor_change_alternative_row_scanning_t* self = (grib_accessor_change_alternative_row_scanning_t*)a;
self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
self->Ni = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
self->Nj = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
self->alternativeRowScanning = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION;
a->length = 0;
}
int grib_accessor_class_change_alternative_row_scanning_t::pack_long(grib_accessor* a, const long* val, size_t* len){
int err = 0;
grib_accessor_change_alternative_row_scanning_t* self = (grib_accessor_change_alternative_row_scanning_t*)a;
const grib_context* c = a->context;
grib_handle* h = grib_handle_of_accessor(a);
long i, j, jr, theEnd, Ni, Nj, k, kp, alternativeRowScanning;
size_t size = 0;
double* values = NULL;
double tmp = 0.0;
if (*val == 0)
return 0;
/* Make sure Ni / Nj are not missing */
if (grib_is_missing(h, self->Ni, &err) && !err) {
grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: Key %s cannot be 'missing'!", self->Ni);
return GRIB_WRONG_GRID;
}
if (grib_is_missing(h, self->Nj, &err) && !err) {
grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: Key %s cannot be 'missing'!", self->Nj);
return GRIB_WRONG_GRID;
}
if ((err = grib_get_long_internal(h, self->Ni, &Ni)) != GRIB_SUCCESS)
return err;
if ((err = grib_get_long_internal(h, self->Nj, &Nj)) != GRIB_SUCCESS)
return err;
if ((err = grib_get_long_internal(h, self->alternativeRowScanning, &alternativeRowScanning)) != GRIB_SUCCESS)
return err;
if ((err = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS)
return err;
if ( size > (size_t)(Ni * Nj) ) {
grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: wrong values size!=Ni*Nj (%zu!=%ld*%ld)", size, Ni, Nj);
return GRIB_WRONG_ARRAY_SIZE;
}
values = (double*)grib_context_malloc(c, size * sizeof(double));
if (!values)
return GRIB_OUT_OF_MEMORY;
if ((err = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) {
grib_context_free(c, values);
return err;
}
theEnd = Ni / 2;
for (j = 0; j < Nj; j++) {
jr = Ni * j;
for (i = 0; i < theEnd; i++) {
if (j % 2 == 1) {
/* Swap first and last value on every odd row */
k = jr + i;
kp = jr + Ni - i - 1;
tmp = values[k];
values[k] = values[kp];
values[kp] = tmp;
}
}
}
alternativeRowScanning = !alternativeRowScanning;
if ((err = grib_set_long_internal(h, self->alternativeRowScanning, alternativeRowScanning)) != GRIB_SUCCESS) {
grib_context_free(c, values);
return err;
}
if ((err = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) {
grib_context_free(c, values);
return err;
}
grib_context_free(c, values);
return GRIB_SUCCESS;
}
int grib_accessor_class_change_alternative_row_scanning_t::get_native_type(grib_accessor* a){
return GRIB_TYPE_LONG;
}
int grib_accessor_class_change_alternative_row_scanning_t::unpack_long(grib_accessor* a, long* v, size_t* len){
/* Decoding this accessor doesn't make sense so we return a dummy value */
*v = -1;
return GRIB_SUCCESS;
}

View File

@ -0,0 +1,38 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_change_alternative_row_scanning_h
#define eccodes_accessor_change_alternative_row_scanning_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_change_alternative_row_scanning_t : public grib_accessor_gen_t
{
public:
/* Members defined in change_alternative_row_scanning */
const char* values;
const char* Ni;
const char* Nj;
const char* alternativeRowScanning;
};
class grib_accessor_class_change_alternative_row_scanning_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_change_alternative_row_scanning_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_change_alternative_row_scanning_t{}; }
int get_native_type(grib_accessor*) override;
int pack_long(grib_accessor*, const long* val, size_t* len) override;
int unpack_long(grib_accessor*, long* val, size_t* len) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_change_alternative_row_scanning_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -9,115 +10,14 @@
*/
#include "grib_api_internal.h"
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_gen
IMPLEMENTS = pack_long;
IMPLEMENTS = unpack_long
IMPLEMENTS = init;get_native_type
MEMBERS = const char* values
MEMBERS = const char* Ni
MEMBERS = const char* Nj
MEMBERS = const char* i_scans_negatively
MEMBERS = const char* j_scans_positively
MEMBERS = const char* first
MEMBERS = const char* last
MEMBERS = const char* axis
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int get_native_type(grib_accessor*);
static int pack_long(grib_accessor*, const long* val, size_t* len);
static int unpack_long(grib_accessor*, long* val, size_t* len);
static void init(grib_accessor*, const long, grib_arguments*);
typedef struct grib_accessor_change_scanning_direction
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in change_scanning_direction */
const char* values;
const char* Ni;
const char* Nj;
const char* i_scans_negatively;
const char* j_scans_positively;
const char* first;
const char* last;
const char* axis;
} grib_accessor_change_scanning_direction;
extern grib_accessor_class* grib_accessor_class_gen;
static grib_accessor_class _grib_accessor_class_change_scanning_direction = {
&grib_accessor_class_gen, /* super */
"change_scanning_direction", /* name */
sizeof(grib_accessor_change_scanning_direction), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
0, /* dump */
0, /* next_offset */
0, /* get length of string */
0, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
&get_native_type, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
&pack_long, /* pack_long */
&unpack_long, /* unpack_long */
0, /* pack_double */
0, /* pack_float */
0, /* unpack_double */
0, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
0, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
0, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
#include "grib_accessor_class_change_scanning_direction.h"
grib_accessor_class_change_scanning_direction_t _grib_accessor_class_change_scanning_direction{"change_scanning_direction"};
grib_accessor_class* grib_accessor_class_change_scanning_direction = &_grib_accessor_class_change_scanning_direction;
/* END_CLASS_IMP */
static void init(grib_accessor* a, const long len, grib_arguments* args)
{
grib_accessor_change_scanning_direction* self = (grib_accessor_change_scanning_direction*)a;
void grib_accessor_class_change_scanning_direction_t::init(grib_accessor* a, const long len, grib_arguments* args){
grib_accessor_change_scanning_direction_t* self = (grib_accessor_change_scanning_direction_t*)a;
grib_handle* h = grib_handle_of_accessor(a);
int n = 0;
@ -134,8 +34,7 @@ static void init(grib_accessor* a, const long len, grib_arguments* args)
a->length = 0;
}
static int pack_long(grib_accessor* a, const long* val, size_t* len)
{
int grib_accessor_class_change_scanning_direction_t::pack_long(grib_accessor* a, const long* val, size_t* len){
int err = 0;
long i, j, jr, theEnd, Ni, Nj, k, kp;
double tmp;
@ -145,7 +44,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
double last = 0;
size_t size = 0;
double* values = NULL;
grib_accessor_change_scanning_direction* self = (grib_accessor_change_scanning_direction*)a;
grib_accessor_change_scanning_direction_t* self = (grib_accessor_change_scanning_direction_t*)a;
const grib_context* c = a->context;
grib_handle* h = grib_handle_of_accessor(a);
const char* cclass_name = a->cclass->name;
@ -248,13 +147,11 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
return GRIB_SUCCESS;
}
static int get_native_type(grib_accessor* a)
{
int grib_accessor_class_change_scanning_direction_t::get_native_type(grib_accessor* a){
return GRIB_TYPE_LONG;
}
static int unpack_long(grib_accessor* a, long* v, size_t* len)
{
int grib_accessor_class_change_scanning_direction_t::unpack_long(grib_accessor* a, long* v, size_t* len){
/* ECC-976: decoding this accessor doesn't make sense so we return a dummy value */
*v = -1;
return GRIB_SUCCESS;

View File

@ -0,0 +1,42 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_change_scanning_direction_h
#define eccodes_accessor_change_scanning_direction_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_change_scanning_direction_t : public grib_accessor_gen_t
{
public:
/* Members defined in change_scanning_direction */
const char* values;
const char* Ni;
const char* Nj;
const char* i_scans_negatively;
const char* j_scans_positively;
const char* first;
const char* last;
const char* axis;
};
class grib_accessor_class_change_scanning_direction_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_change_scanning_direction_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_change_scanning_direction_t{}; }
int get_native_type(grib_accessor*) override;
int pack_long(grib_accessor*, const long* val, size_t* len) override;
int unpack_long(grib_accessor*, long* val, size_t* len) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_change_scanning_direction_h */

View File

@ -0,0 +1,51 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_check_internal_version.h"
grib_accessor_class_check_internal_version_t _grib_accessor_class_check_internal_version{"check_internal_version"};
grib_accessor_class* grib_accessor_class_check_internal_version = &_grib_accessor_class_check_internal_version;
/* This is the internal engine version number */
/* We check this against the version number found in the definitions boot.def file */
/* See the key "internalVersion" */
#define LATEST_ENGINE_VERSION 30
void grib_accessor_class_check_internal_version_t::init(grib_accessor* a, const long l, grib_arguments* args){
/* Check version of definition files is compatible with the engine */
int err = 0;
long defs_file_version = 0;
grib_handle* h = grib_handle_of_accessor(a);
const char* s_defn_version = grib_arguments_get_name(h, args, 0);
Assert(s_defn_version);
err = grib_get_long_internal(h, s_defn_version, &defs_file_version);
if (!err) {
if (defs_file_version > LATEST_ENGINE_VERSION) {
grib_context_log(h->context, GRIB_LOG_FATAL,
"Definition files version (%d) is greater than engine version (%d)!\n"
" " /* indent for 2nd line */
"These definition files are for a later version of the ecCodes engine.",
defs_file_version, LATEST_ENGINE_VERSION);
}
}
}
int grib_accessor_class_check_internal_version_t::value_count(grib_accessor* a, long* count){
*count = 1;
return 0;
}
size_t grib_accessor_class_check_internal_version_t::string_length(grib_accessor* a){
return 255;
}

View File

@ -0,0 +1,33 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_check_internal_version_h
#define eccodes_accessor_check_internal_version_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_ascii.h"
class grib_accessor_check_internal_version_t : public grib_accessor_ascii_t
{
public:
/* Members defined in check_internal_version */
};
class grib_accessor_class_check_internal_version_t : public grib_accessor_class_ascii_t
{
public:
grib_accessor_class_check_internal_version_t(const char* name) : grib_accessor_class_ascii_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_check_internal_version_t{}; }
size_t string_length(grib_accessor*) override;
int value_count(grib_accessor*, long*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_check_internal_version_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -9,121 +10,15 @@
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_closest_date.h"
#include <float.h>
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_double
IMPLEMENTS = unpack_long
IMPLEMENTS = unpack_double
IMPLEMENTS = dump
IMPLEMENTS = init
MEMBERS = const char *dateLocal
MEMBERS = const char *timeLocal
MEMBERS = const char *numForecasts
MEMBERS = const char *year
MEMBERS = const char *month
MEMBERS = const char *day
MEMBERS = const char *hour
MEMBERS = const char *minute
MEMBERS = const char *second
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int unpack_long(grib_accessor*, long* val, size_t* len);
static void dump(grib_accessor*, grib_dumper*);
static void init(grib_accessor*, const long, grib_arguments*);
typedef struct grib_accessor_closest_date
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in double */
/* Members defined in closest_date */
const char *dateLocal;
const char *timeLocal;
const char *numForecasts;
const char *year;
const char *month;
const char *day;
const char *hour;
const char *minute;
const char *second;
} grib_accessor_closest_date;
extern grib_accessor_class* grib_accessor_class_double;
static grib_accessor_class _grib_accessor_class_closest_date = {
&grib_accessor_class_double, /* super */
"closest_date", /* name */
sizeof(grib_accessor_closest_date), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
&dump, /* dump */
0, /* next_offset */
0, /* get length of string */
0, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
0, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
0, /* pack_long */
&unpack_long, /* unpack_long */
0, /* pack_double */
0, /* pack_float */
&unpack_double, /* unpack_double */
0, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
0, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
0, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
grib_accessor_class_closest_date_t _grib_accessor_class_closest_date{"closest_date"};
grib_accessor_class* grib_accessor_class_closest_date = &_grib_accessor_class_closest_date;
/* END_CLASS_IMP */
static void init(grib_accessor* a, const long l, grib_arguments* c)
{
grib_accessor_closest_date* self = (grib_accessor_closest_date*)a;
void grib_accessor_class_closest_date_t::init(grib_accessor* a, const long l, grib_arguments* c){
grib_accessor_closest_date_t* self = (grib_accessor_closest_date_t*)a;
grib_handle* h = grib_handle_of_accessor(a);
int n = 0;
@ -140,13 +35,11 @@ static void init(grib_accessor* a, const long l, grib_arguments* c)
a->length = 0;
}
static void dump(grib_accessor* a, grib_dumper* dumper)
{
void grib_accessor_class_closest_date_t::dump(grib_accessor* a, grib_dumper* dumper){
grib_dump_string(dumper, a, NULL);
}
static int unpack_long(grib_accessor* a, long* val, size_t* len)
{
int grib_accessor_class_closest_date_t::unpack_long(grib_accessor* a, long* val, size_t* len){
int ret = 0;
double v = 0;
@ -157,9 +50,8 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
}
/* Sets val to the 'index' of the closes date */
static int unpack_double(grib_accessor* a, double* val, size_t* len)
{
const grib_accessor_closest_date* self = (grib_accessor_closest_date*)a;
int grib_accessor_class_closest_date_t::unpack_double(grib_accessor* a, double* val, size_t* len){
const grib_accessor_closest_date_t* self = (grib_accessor_closest_date_t*)a;
int err = 0;
long num_forecasts = 0; /* numberOfForecastsUsedInLocalTime */

View File

@ -0,0 +1,43 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_closest_date_h
#define eccodes_accessor_closest_date_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_double.h"
class grib_accessor_closest_date_t : public grib_accessor_double_t
{
public:
/* Members defined in closest_date */
const char *dateLocal;
const char *timeLocal;
const char *numForecasts;
const char *year;
const char *month;
const char *day;
const char *hour;
const char *minute;
const char *second;
};
class grib_accessor_class_closest_date_t : public grib_accessor_class_double_t
{
public:
grib_accessor_class_closest_date_t(const char* name) : grib_accessor_class_double_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_closest_date_t{}; }
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int unpack_long(grib_accessor*, long* val, size_t* len) override;
void dump(grib_accessor*, grib_dumper*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_closest_date_h */

View File

@ -0,0 +1,119 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_codeflag.h"
grib_accessor_class_codeflag_t _grib_accessor_class_codeflag{"codeflag"};
grib_accessor_class* grib_accessor_class_codeflag = &_grib_accessor_class_codeflag;
void grib_accessor_class_codeflag_t::init(grib_accessor* a, const long len, grib_arguments* param){
grib_accessor_codeflag_t* self = (grib_accessor_codeflag_t*)a;
a->length = len;
self->tablename = grib_arguments_get_string(grib_handle_of_accessor(a), param, 0);
Assert(a->length >= 0);
}
int test_bit(long a, long b){
DEBUG_ASSERT(b>=0);
return a & (1 << b);
}
int grib_get_codeflag(grib_accessor* a, long code, char* codename){
const grib_accessor_codeflag_t* self = (grib_accessor_codeflag_t*)a;
FILE* f = NULL;
char fname[1024];
char bval[50];
char num[50];
char* filename = 0;
char line[1024];
size_t i = 0;
int j = 0;
int err = 0;
err = grib_recompose_name(grib_handle_of_accessor(a), NULL, self->tablename, fname, 1);
if (err) {
strncpy(fname, self->tablename, sizeof(fname)-1);
fname[sizeof(fname)-1] = '\0';
}
if ((filename = grib_context_full_defs_path(a->context, fname)) == NULL) {
grib_context_log(a->context, GRIB_LOG_WARNING, "Cannot open flag table %s", filename);
strcpy(codename, "Cannot open flag table");
return GRIB_FILE_NOT_FOUND;
}
f = codes_fopen(filename, "r");
if (!f) {
grib_context_log(a->context, (GRIB_LOG_WARNING) | (GRIB_LOG_PERROR), "Cannot open flag table %s", filename);
strcpy(codename, "Cannot open flag table");
return GRIB_FILE_NOT_FOUND;
}
// strcpy(codename, self->tablename);
// strcat(codename,": ");
// j = strlen(codename);
while (fgets(line, sizeof(line) - 1, f)) {
sscanf(line, "%49s %49s", num, bval);
if (num[0] != '#') {
if ((test_bit(code, a->length * 8 - atol(num)) > 0) == atol(bval)) {
size_t linelen = strlen(line);
codename[j++] = '(';
codename[j++] = num[0];
codename[j++] = '=';
codename[j++] = bval[0];
codename[j++] = ')';
codename[j++] = ' ';
if (j)
codename[j++] = ' ';
for (i = (strlen(num) + strlen(bval) + 2); i < linelen - 1; i++)
codename[j++] = line[i];
if (line[i] != '\n')
codename[j++] = line[i];
codename[j++] = ';';
}
}
}
if (j > 1 && codename[j - 1] == ';')
j--;
codename[j] = 0;
strcat(codename, ":");
strcat(codename, fname);
fclose(f);
return GRIB_SUCCESS;
}
int grib_accessor_class_codeflag_t::value_count(grib_accessor* a, long* count){
*count = 1;
return 0;
}
void grib_accessor_class_codeflag_t::dump(grib_accessor* a, grib_dumper* dumper){
const grib_accessor_codeflag_t* self = (grib_accessor_codeflag_t*)a;
long v = 0;
char flagname[1024] = {0,};
char fname[1024] = {0,};
size_t llen = 1;
grib_recompose_name(grib_handle_of_accessor(a), NULL, self->tablename, fname, 1);
a->unpack_long(&v, &llen);
grib_get_codeflag(a, v, flagname);
grib_dump_bits(dumper, a, flagname);
}

View File

@ -0,0 +1,34 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_codeflag_h
#define eccodes_accessor_codeflag_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_unsigned.h"
class grib_accessor_codeflag_t : public grib_accessor_unsigned_t
{
public:
/* Members defined in codeflag */
const char* tablename;
};
class grib_accessor_class_codeflag_t : public grib_accessor_class_unsigned_t
{
public:
grib_accessor_class_codeflag_t(const char* name) : grib_accessor_class_unsigned_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_codeflag_t{}; }
int value_count(grib_accessor*, long*) override;
void dump(grib_accessor*, grib_dumper*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_codeflag_h */

View File

@ -0,0 +1,69 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_codetable_title.h"
#include "grib_accessor_class_codetable.h"
grib_accessor_class_codetable_title_t _grib_accessor_class_codetable_title{"codetable_title"};
grib_accessor_class* grib_accessor_class_codetable_title = &_grib_accessor_class_codetable_title;
void grib_accessor_class_codetable_title_t::init(grib_accessor* a, const long len, grib_arguments* params){
grib_accessor_codetable_title_t* self = (grib_accessor_codetable_title_t*)a;
int n = 0;
self->codetable = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++);
a->length = 0;
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
}
int grib_accessor_class_codetable_title_t::get_native_type(grib_accessor* a){
return GRIB_TYPE_STRING;
}
int grib_accessor_class_codetable_title_t::unpack_string(grib_accessor* a, char* buffer, size_t* len){
grib_accessor_codetable_title_t* self = (grib_accessor_codetable_title_t*)a;
grib_codetable* table = NULL;
size_t size = 1;
long value;
int err = GRIB_SUCCESS;
char tmp[1024];
size_t l = 1024;
grib_accessor_codetable_t* ca = (grib_accessor_codetable_t*)grib_find_accessor(grib_handle_of_accessor(a), self->codetable);
if ((err = ((grib_accessor*)ca)->unpack_long(&value, &size)) != GRIB_SUCCESS)
return err;
table = ca->table;
if (table && (value >= 0) && (value < table->size) && table->entries[value].title) {
strcpy(tmp, table->entries[value].title);
}
else {
snprintf(tmp, sizeof(tmp), "%d", (int)value);
}
l = strlen(tmp) + 1;
if (*len < l) {
const char* cclass_name = a->cclass->name;
grib_context_log(a->context, GRIB_LOG_ERROR,
"%s: Buffer too small for %s. It is %zu bytes long (len=%zu)",
cclass_name, a->name, l, *len);
*len = l;
return GRIB_BUFFER_TOO_SMALL;
}
strcpy(buffer, tmp);
*len = l;
return GRIB_SUCCESS;
}

View File

@ -0,0 +1,34 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_codetable_title_h
#define eccodes_accessor_codetable_title_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_codetable_title_t : public grib_accessor_gen_t
{
public:
/* Members defined in codetable_title */
const char* codetable;
};
class grib_accessor_class_codetable_title_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_codetable_title_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_codetable_title_t{}; }
int get_native_type(grib_accessor*) override;
int unpack_string(grib_accessor*, char*, size_t* len) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_codetable_title_h */

View File

@ -0,0 +1,70 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_codetable_units.h"
#include "grib_accessor_class_codetable.h"
grib_accessor_class_codetable_units_t _grib_accessor_class_codetable_units{"codetable_units"};
grib_accessor_class* grib_accessor_class_codetable_units = &_grib_accessor_class_codetable_units;
void grib_accessor_class_codetable_units_t::init(grib_accessor* a, const long len, grib_arguments* params){
grib_accessor_codetable_units_t* self = (grib_accessor_codetable_units_t*)a;
int n = 0;
self->codetable = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++);
a->length = 0;
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
}
int grib_accessor_class_codetable_units_t::get_native_type(grib_accessor* a){
return GRIB_TYPE_STRING;
}
int grib_accessor_class_codetable_units_t::unpack_string(grib_accessor* a, char* buffer, size_t* len){
grib_accessor_codetable_units_t* self = (grib_accessor_codetable_units_t*)a;
grib_codetable* table = NULL;
size_t size = 1;
long value;
int err = GRIB_SUCCESS;
char tmp[1024];
size_t l = sizeof(tmp);
grib_accessor_codetable_t* ca = (grib_accessor_codetable_t*)grib_find_accessor(grib_handle_of_accessor(a), self->codetable);
if ((err = ((grib_accessor*)ca)->unpack_long(&value, &size)) != GRIB_SUCCESS)
return err;
table = ca->table;
if (table && (value >= 0) && (value < table->size) && table->entries[value].units) {
strcpy(tmp, table->entries[value].units);
}
else {
snprintf(tmp, sizeof(tmp), "%d", (int)value);
}
l = strlen(tmp) + 1;
if (*len < l) {
const char* cclass_name = a->cclass->name;
grib_context_log(a->context, GRIB_LOG_ERROR,
"%s: Buffer too small for %s. It is %zu bytes long (len=%zu)",
cclass_name, a->name, l, *len);
*len = l;
return GRIB_BUFFER_TOO_SMALL;
}
strcpy(buffer, tmp);
*len = l;
return GRIB_SUCCESS;
}

View File

@ -0,0 +1,34 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_codetable_units_h
#define eccodes_accessor_codetable_units_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_codetable_units_t : public grib_accessor_gen_t
{
public:
/* Members defined in codetable_units */
const char* codetable;
};
class grib_accessor_class_codetable_units_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_codetable_units_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_codetable_units_t{}; }
int get_native_type(grib_accessor*) override;
int unpack_string(grib_accessor*, char*, size_t* len) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_codetable_units_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -8,113 +9,12 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
/*******************************************************
* Enrico Fucile
******************************************************/
#include "grib_api_internal.h"
#include "grib_accessor_class_concept.h"
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_gen
IMPLEMENTS = unpack_double;pack_double
IMPLEMENTS = unpack_string;pack_string;string_length
IMPLEMENTS = unpack_long;pack_long;destroy
IMPLEMENTS = init;dump;value_count;get_native_type
IMPLEMENTS = compare
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int get_native_type(grib_accessor*);
static int pack_double(grib_accessor*, const double* val, size_t* len);
static int pack_long(grib_accessor*, const long* val, size_t* len);
static int pack_string(grib_accessor*, const char*, size_t* len);
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int unpack_long(grib_accessor*, long* val, size_t* len);
static int unpack_string(grib_accessor*, char*, size_t* len);
static size_t string_length(grib_accessor*);
static int value_count(grib_accessor*, long*);
static void destroy(grib_context*, grib_accessor*);
static void dump(grib_accessor*, grib_dumper*);
static void init(grib_accessor*, const long, grib_arguments*);
static int compare(grib_accessor*, grib_accessor*);
typedef struct grib_accessor_concept
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in concept */
} grib_accessor_concept;
extern grib_accessor_class* grib_accessor_class_gen;
static grib_accessor_class _grib_accessor_class_concept = {
&grib_accessor_class_gen, /* super */
"concept", /* name */
sizeof(grib_accessor_concept), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
&destroy, /* destroy */
&dump, /* dump */
0, /* next_offset */
&string_length, /* get length of string */
&value_count, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
&get_native_type, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
&pack_long, /* pack_long */
&unpack_long, /* unpack_long */
&pack_double, /* pack_double */
0, /* pack_float */
&unpack_double, /* unpack_double */
0, /* unpack_float */
&pack_string, /* pack_string */
&unpack_string, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
&compare, /* compare vs. another accessor */
0, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
0, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
grib_accessor_class_concept_t _grib_accessor_class_concept{"concept"};
grib_accessor_class* grib_accessor_class_concept = &_grib_accessor_class_concept;
/* END_CLASS_IMP */
#define MAX_CONCEPT_STRING_LENGTH 255
@ -134,19 +34,16 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b)
return (*a == 0 && *b == 0) ? 0 : 1;
}
static void init(grib_accessor* a, const long len, grib_arguments* args)
{
void grib_accessor_class_concept_t::init(grib_accessor* a, const long len, grib_arguments* args){
a->length = 0;
}
static void dump(grib_accessor* a, grib_dumper* dumper)
{
void grib_accessor_class_concept_t::dump(grib_accessor* a, grib_dumper* dumper){
grib_dump_string(dumper, a, NULL);
}
/* Return 1 (=True) or 0 (=False) */
static int concept_condition_expression_true(grib_handle* h, grib_concept_condition* c)
{
int concept_condition_expression_true(grib_handle* h, grib_concept_condition* c){
long lval;
long lres = 0;
int ok = FALSE; /* Boolean */
@ -190,8 +87,7 @@ static int concept_condition_expression_true(grib_handle* h, grib_concept_condit
}
/* Return 1 (=True) or 0 (=False) */
static int concept_condition_iarray_true(grib_handle* h, grib_concept_condition* c)
{
int concept_condition_iarray_true(grib_handle* h, grib_concept_condition* c){
long* val = NULL;
size_t size = 0, i;
int ret; /* Boolean */
@ -221,8 +117,7 @@ static int concept_condition_iarray_true(grib_handle* h, grib_concept_condition*
}
/* Return 1 (=True) or 0 (=False) */
static int concept_condition_true(grib_handle* h, grib_concept_condition* c)
{
int concept_condition_true(grib_handle* h, grib_concept_condition* c){
if (c->expression == NULL)
return concept_condition_iarray_true(h, c);
else
@ -263,8 +158,7 @@ static const char* concept_evaluate(grib_accessor* a)
#define MAX_NUM_CONCEPT_VALUES 40
static int concept_conditions_expression_apply(grib_handle* h, grib_concept_condition* e, grib_values* values, grib_sarray* sa, int* n)
{
int concept_conditions_expression_apply(grib_handle* h, grib_concept_condition* e, grib_values* values, grib_sarray* sa, int* n){
long lres = 0;
double dres = 0.0;
int count = *n;
@ -295,30 +189,26 @@ static int concept_conditions_expression_apply(grib_handle* h, grib_concept_cond
return err;
}
static int concept_conditions_iarray_apply(grib_handle* h, grib_concept_condition* c)
{
int concept_conditions_iarray_apply(grib_handle* h, grib_concept_condition* c){
size_t size = grib_iarray_used_size(c->iarray);
return grib_set_long_array(h, c->name, c->iarray->v, size);
}
static int concept_conditions_apply(grib_handle* h, grib_concept_condition* c, grib_values* values, grib_sarray* sa, int* n)
{
int concept_conditions_apply(grib_handle* h, grib_concept_condition* c, grib_values* values, grib_sarray* sa, int* n){
if (c->expression == NULL)
return concept_conditions_iarray_apply(h, c);
else
return concept_conditions_expression_apply(h, c, values, sa, n);
}
static int cmpstringp(const void* p1, const void* p2)
{
int cmpstringp(const void* p1, const void* p2){
/* The actual arguments to this function are "pointers to
pointers to char", but strcmp(3) arguments are "pointers
to char", hence the following cast plus dereference */
return strcmp(*(char* const*)p1, *(char* const*)p2);
}
static bool blacklisted(grib_handle* h, long edition, const char* concept_name, const char* concept_value)
{
bool blacklisted(grib_handle* h, long edition, const char* concept_name, const char* concept_value){
if ( strcmp(concept_name, "packingType")==0 ) {
char input_packing_type[100];
size_t len = sizeof(input_packing_type);
@ -345,8 +235,7 @@ static bool blacklisted(grib_handle* h, long edition, const char* concept_name,
return false;
}
static int grib_concept_apply(grib_accessor* a, const char* name)
{
int grib_concept_apply(grib_accessor* a, const char* name){
int err = 0;
int count = 0;
grib_concept_condition* e = NULL;
@ -440,13 +329,11 @@ static int grib_concept_apply(grib_accessor* a, const char* name)
return err;
}
static int pack_double(grib_accessor* a, const double* val, size_t* len)
{
int grib_accessor_class_concept_t::pack_double(grib_accessor* a, const double* val, size_t* len){
return GRIB_NOT_IMPLEMENTED;
}
static int pack_long(grib_accessor* a, const long* val, size_t* len)
{
int grib_accessor_class_concept_t::pack_long(grib_accessor* a, const long* val, size_t* len){
char buf[80];
size_t s;
snprintf(buf, sizeof(buf), "%ld", *val);
@ -458,8 +345,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len)
return pack_string(a, buf, &s);
}
static int unpack_double(grib_accessor* a, double* val, size_t* len)
{
int grib_accessor_class_concept_t::unpack_double(grib_accessor* a, double* val, size_t* len){
/*
* If we want to have a condition which contains tests for paramId as well
* as a floating point key, then need to be able to evaluate paramId as a
@ -491,8 +377,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
return ret;
}
static int unpack_long(grib_accessor* a, long* val, size_t* len)
{
int grib_accessor_class_concept_t::unpack_long(grib_accessor* a, long* val, size_t* len){
const char* p = concept_evaluate(a);
if (!p) {
@ -527,8 +412,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
return GRIB_SUCCESS;
}
static int get_native_type(grib_accessor* a)
{
int grib_accessor_class_concept_t::get_native_type(grib_accessor* a){
int type = GRIB_TYPE_STRING;
if (a->flags & GRIB_ACCESSOR_FLAG_LONG_TYPE)
type = GRIB_TYPE_LONG;
@ -536,14 +420,12 @@ static int get_native_type(grib_accessor* a)
return type;
}
static void destroy(grib_context* c, grib_accessor* a)
{
//grib_accessor_concept *self = (grib_accessor_concept*)a;
void grib_accessor_class_concept_t::destroy(grib_context* c, grib_accessor* a){
//grib_accessor_concept_t *self = (grib_accessor_concept_t*)a;
//grib_context_free(c,self->cval);
}
static int unpack_string(grib_accessor* a, char* val, size_t* len)
{
int grib_accessor_class_concept_t::unpack_string(grib_accessor* a, char* val, size_t* len){
size_t slen;
const char* p = concept_evaluate(a);
@ -576,24 +458,20 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len)
return GRIB_SUCCESS;
}
static int pack_string(grib_accessor* a, const char* val, size_t* len)
{
int grib_accessor_class_concept_t::pack_string(grib_accessor* a, const char* val, size_t* len){
return grib_concept_apply(a, val);
}
static size_t string_length(grib_accessor* a)
{
size_t grib_accessor_class_concept_t::string_length(grib_accessor* a){
return MAX_CONCEPT_STRING_LENGTH;
}
static int value_count(grib_accessor* a, long* count)
{
int grib_accessor_class_concept_t::value_count(grib_accessor* a, long* count){
*count = 1;
return 0;
}
static int compare(grib_accessor* a, grib_accessor* b)
{
int grib_accessor_class_concept_t::compare(grib_accessor* a, grib_accessor* b){
int retval = 0;
char* aval = 0;
char* bval = 0;
@ -603,12 +481,10 @@ static int compare(grib_accessor* a, grib_accessor* b)
int err = 0;
long count = 0;
err = grib_value_count(a, &count);
if (err) return err;
err = a->value_count(&count); if (err) return err;
alen = count;
err = grib_value_count(b, &count);
if (err) return err;
err = b->value_count(&count); if (err) return err;
blen = count;
if (alen != blen)
@ -619,10 +495,8 @@ static int compare(grib_accessor* a, grib_accessor* b)
aval = (char*)grib_context_malloc(a->context, alen * sizeof(char));
bval = (char*)grib_context_malloc(b->context, blen * sizeof(char));
err = grib_unpack_string(a, aval, &alen);
if (err) return err;
err = grib_unpack_string(b, bval, &blen);
if (err) return err;
err = a->unpack_string(aval, &alen); if (err) return err;
err = b->unpack_string(bval, &blen); if (err) return err;
retval = GRIB_SUCCESS;
if (!aval || !bval || grib_inline_strcmp(aval, bval))

View File

@ -0,0 +1,43 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_concept_h
#define eccodes_accessor_concept_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_concept_t : public grib_accessor_gen_t
{
public:
/* Members defined in concept */
};
class grib_accessor_class_concept_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_concept_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_concept_t{}; }
int get_native_type(grib_accessor*) override;
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int pack_long(grib_accessor*, const long* val, size_t* len) override;
int pack_string(grib_accessor*, const char*, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int unpack_long(grib_accessor*, long* val, size_t* len) override;
int unpack_string(grib_accessor*, char*, size_t* len) override;
size_t string_length(grib_accessor*) override;
int value_count(grib_accessor*, long*) override;
void destroy(grib_context*, grib_accessor*) override;
void dump(grib_accessor*, grib_dumper*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
int compare(grib_accessor*, grib_accessor*) override;
};
#endif /* eccodes_accessor_concept_h */

View File

@ -0,0 +1,28 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_count_file.h"
grib_accessor_class_count_file_t _grib_accessor_class_count_file{"count_file"};
grib_accessor_class* grib_accessor_class_count_file = &_grib_accessor_class_count_file;
void grib_accessor_class_count_file_t::init(grib_accessor* a, const long l, grib_arguments* c){
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
a->length = 0;
}
int grib_accessor_class_count_file_t::unpack_long(grib_accessor* a, long* val, size_t* len){
*val = grib_context_get_handle_file_count(a->context);
*len = 1;
return 0;
}

View File

@ -0,0 +1,32 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_count_file_h
#define eccodes_accessor_count_file_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_long.h"
class grib_accessor_count_file_t : public grib_accessor_long_t
{
public:
/* Members defined in count_file */
};
class grib_accessor_class_count_file_t : public grib_accessor_class_long_t
{
public:
grib_accessor_class_count_file_t(const char* name) : grib_accessor_class_long_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_count_file_t{}; }
int unpack_long(grib_accessor*, long* val, size_t* len) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_count_file_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -9,103 +10,11 @@
*/
#include "grib_api_internal.h"
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_long
IMPLEMENTS = unpack_long
IMPLEMENTS = init;
IMPLEMENTS = value_count
MEMBERS = const char* bitmap
MEMBERS = const char* unusedBitsInBitmap
MEMBERS = const char* numberOfDataPoints
MEMBERS = const char* missingValueManagementUsed
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int unpack_long(grib_accessor*, long* val, size_t* len);
static int value_count(grib_accessor*, long*);
static void init(grib_accessor*, const long, grib_arguments*);
typedef struct grib_accessor_count_missing
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in long */
/* Members defined in count_missing */
const char* bitmap;
const char* unusedBitsInBitmap;
const char* numberOfDataPoints;
const char* missingValueManagementUsed;
} grib_accessor_count_missing;
extern grib_accessor_class* grib_accessor_class_long;
static grib_accessor_class _grib_accessor_class_count_missing = {
&grib_accessor_class_long, /* super */
"count_missing", /* name */
sizeof(grib_accessor_count_missing), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
0, /* dump */
0, /* next_offset */
0, /* get length of string */
&value_count, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
0, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
0, /* pack_long */
&unpack_long, /* unpack_long */
0, /* pack_double */
0, /* pack_float */
0, /* unpack_double */
0, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
0, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
0, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
#include "grib_accessor_class_count_missing.h"
grib_accessor_class_count_missing_t _grib_accessor_class_count_missing{"count_missing"};
grib_accessor_class* grib_accessor_class_count_missing = &_grib_accessor_class_count_missing;
/* END_CLASS_IMP */
static const unsigned char bitsoff[] = {
8, 7, 7, 6, 7, 6, 6, 5, 7, 6, 6, 5, 6, 5, 5, 4, 7,
@ -126,10 +35,9 @@ static const unsigned char bitsoff[] = {
0
};
static void init(grib_accessor* a, const long len, grib_arguments* arg)
{
void grib_accessor_class_count_missing_t::init(grib_accessor* a, const long len, grib_arguments* arg){
int n = 0;
grib_accessor_count_missing* self = (grib_accessor_count_missing*)a;
grib_accessor_count_missing_t* self = (grib_accessor_count_missing_t*)a;
grib_handle* h = grib_handle_of_accessor(a);
a->length = 0;
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
@ -141,8 +49,7 @@ static void init(grib_accessor* a, const long len, grib_arguments* arg)
static const int used[] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
static int get_count_of_missing_values(grib_handle* h, long* p_count_of_missing)
{
int get_count_of_missing_values(grib_handle* h, long* p_count_of_missing){
int err = 0;
long count_of_missing = 0;
size_t vsize = 0, ii = 0;
@ -165,9 +72,8 @@ static int get_count_of_missing_values(grib_handle* h, long* p_count_of_missing)
return GRIB_SUCCESS;
}
static int unpack_long(grib_accessor* a, long* val, size_t* len)
{
grib_accessor_count_missing* self = (grib_accessor_count_missing*)a;
int grib_accessor_class_count_missing_t::unpack_long(grib_accessor* a, long* val, size_t* len){
grib_accessor_count_missing_t* self = (grib_accessor_count_missing_t*)a;
unsigned char* p;
int i;
long size = 0;
@ -195,9 +101,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
return GRIB_SUCCESS;
}
size = grib_byte_count(bitmap);
offset = grib_byte_offset(bitmap);
size = bitmap->byte_count(); offset = bitmap->byte_offset();
if (grib_get_long(h, self->unusedBitsInBitmap, &unusedBitsInBitmap) != GRIB_SUCCESS) {
if (grib_get_long(h, self->numberOfDataPoints, &numberOfDataPoints) != GRIB_SUCCESS) {
grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to count missing values");
@ -224,8 +128,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len)
return GRIB_SUCCESS;
}
static int value_count(grib_accessor* a, long* count)
{
int grib_accessor_class_count_missing_t::value_count(grib_accessor* a, long* count){
*count = 1;
return 0;
}

View File

@ -0,0 +1,37 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_count_missing_h
#define eccodes_accessor_count_missing_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_long.h"
class grib_accessor_count_missing_t : public grib_accessor_long_t
{
public:
/* Members defined in count_missing */
const char* bitmap;
const char* unusedBitsInBitmap;
const char* numberOfDataPoints;
const char* missingValueManagementUsed;
};
class grib_accessor_class_count_missing_t : public grib_accessor_class_long_t
{
public:
grib_accessor_class_count_missing_t(const char* name) : grib_accessor_class_long_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_count_missing_t{}; }
int unpack_long(grib_accessor*, long* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_count_missing_h */

View File

@ -0,0 +1,28 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_count_total.h"
grib_accessor_class_count_total_t _grib_accessor_class_count_total{"count_total"};
grib_accessor_class* grib_accessor_class_count_total = &_grib_accessor_class_count_total;
void grib_accessor_class_count_total_t::init(grib_accessor* a, const long l, grib_arguments* c){
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
a->length = 0;
}
int grib_accessor_class_count_total_t::unpack_long(grib_accessor* a, long* val, size_t* len){
*val = grib_context_get_handle_total_count(a->context);
*len = 1;
return 0;
}

View File

@ -0,0 +1,32 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_count_total_h
#define eccodes_accessor_count_total_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_long.h"
class grib_accessor_count_total_t : public grib_accessor_long_t
{
public:
/* Members defined in count_total */
};
class grib_accessor_class_count_total_t : public grib_accessor_class_long_t
{
public:
grib_accessor_class_count_total_t(const char* name) : grib_accessor_class_long_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_count_total_t{}; }
int unpack_long(grib_accessor*, long* val, size_t* len) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_count_total_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -8,123 +9,16 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_value.h"
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_gen
IMPLEMENTS = init
IMPLEMENTS = unpack_double;unpack_double_element;unpack_double_element_set
IMPLEMENTS = unpack_float
IMPLEMENTS = pack_double
IMPLEMENTS = value_count
IMPLEMENTS = dump;get_native_type
IMPLEMENTS = compare
MEMBERS=const char* coded_values
MEMBERS=const char* bitmap
MEMBERS=const char* missing_value
MEMBERS=const char* number_of_data_points
MEMBERS=const char* number_of_values
MEMBERS=const char* binary_scale_factor
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int get_native_type(grib_accessor*);
static int pack_double(grib_accessor*, const double* val, size_t* len);
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int unpack_float(grib_accessor*, float* val, size_t* len);
static int value_count(grib_accessor*, long*);
static void dump(grib_accessor*, grib_dumper*);
static void init(grib_accessor*, const long, grib_arguments*);
static int compare(grib_accessor*, grib_accessor*);
static int unpack_double_element(grib_accessor*, size_t i, double* val);
static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array);
typedef struct grib_accessor_data_apply_bitmap
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in data_apply_bitmap */
const char* coded_values;
const char* bitmap;
const char* missing_value;
const char* number_of_data_points;
const char* number_of_values;
const char* binary_scale_factor;
} grib_accessor_data_apply_bitmap;
extern grib_accessor_class* grib_accessor_class_gen;
static grib_accessor_class _grib_accessor_class_data_apply_bitmap = {
&grib_accessor_class_gen, /* super */
"data_apply_bitmap", /* name */
sizeof(grib_accessor_data_apply_bitmap), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
&dump, /* dump */
0, /* next_offset */
0, /* get length of string */
&value_count, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
&get_native_type, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
0, /* pack_long */
0, /* unpack_long */
&pack_double, /* pack_double */
0, /* pack_float */
&unpack_double, /* unpack_double */
&unpack_float, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
&compare, /* compare vs. another accessor */
&unpack_double_element, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
&unpack_double_element_set, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
#include "grib_api_internal.h"
#include "grib_accessor_class_data_apply_bitmap.h"
grib_accessor_class_data_apply_bitmap_t _grib_accessor_class_data_apply_bitmap{"data_apply_bitmap"};
grib_accessor_class* grib_accessor_class_data_apply_bitmap = &_grib_accessor_class_data_apply_bitmap;
/* END_CLASS_IMP */
static void init(grib_accessor* a, const long v, grib_arguments* args)
{
void grib_accessor_class_data_apply_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args){
int n = 0;
grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a;
grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a;
self->coded_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
self->bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
@ -135,14 +29,12 @@ static void init(grib_accessor* a, const long v, grib_arguments* args)
a->length = 0;
}
static void dump(grib_accessor* a, grib_dumper* dumper)
{
void grib_accessor_class_data_apply_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper){
grib_dump_values(dumper, a);
}
static int value_count(grib_accessor* a, long* count)
{
grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a;
int grib_accessor_class_data_apply_bitmap_t::value_count(grib_accessor* a, long* count){
grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a;
size_t len = 0;
int ret = 0;
@ -156,9 +48,8 @@ static int value_count(grib_accessor* a, long* count)
return ret;
}
static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
{
grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a;
int grib_accessor_class_data_apply_bitmap_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){
grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
int err = 0, i = 0;
size_t cidx = 0;
@ -167,8 +58,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
size_t n_vals = 0;
long nn = 0;
err = grib_value_count(a, &nn);
n_vals = nn;
err = a->value_count(&nn); n_vals = nn;
if (err)
return err;
@ -203,9 +93,8 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
return grib_get_double_element_internal(gh, self->coded_values, cidx, val);
}
static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
{
grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a;
int grib_accessor_class_data_apply_bitmap_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){
grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
int err = 0, all_missing = 1;
size_t cidx = 0; /* index into the coded_values array */
@ -216,8 +105,7 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array
size_t n_vals = 0, i = 0, j = 0, idx = 0, count_1s = 0, ci = 0;
long nn = 0;
err = grib_value_count(a, &nn);
n_vals = nn;
err = a->value_count(&nn); n_vals = nn;
if (err) return err;
if (!grib_find_accessor(gh, self->bitmap))
@ -283,9 +171,8 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array
return GRIB_SUCCESS;
}
static int pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a;
int grib_accessor_class_data_apply_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len){
grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a;
int err = 0;
size_t bmaplen = *len;
long coded_n_vals = 0;
@ -344,10 +231,9 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
}
template <typename T>
static int unpack(grib_accessor* a, T* val, size_t* len)
{
int unpack(grib_accessor* a, T* val, size_t* len){
static_assert(std::is_floating_point<T>::value, "Requires floating point numbers");
grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a;
grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a;
size_t i = 0;
size_t j = 0;
@ -358,8 +244,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
T* coded_vals = NULL;
double missing_value = 0;
err = grib_value_count(a, &nn);
n_vals = nn;
err = a->value_count(&nn); n_vals = nn;
if (err)
return err;
@ -426,26 +311,22 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
return err;
}
static int unpack_double(grib_accessor* a, double* val, size_t* len)
{
int grib_accessor_class_data_apply_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len){
return unpack<double>(a, val, len);
}
static int unpack_float(grib_accessor* a, float* val, size_t* len)
{
int grib_accessor_class_data_apply_bitmap_t::unpack_float(grib_accessor* a, float* val, size_t* len){
return unpack<float>(a, val, len);
}
static int get_native_type(grib_accessor* a)
{
//grib_accessor_data_apply_bitmap* self = (grib_accessor_data_apply_bitmap*)a;
int grib_accessor_class_data_apply_bitmap_t::get_native_type(grib_accessor* a){
//grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a;
//return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(a),self->coded_values));
return GRIB_TYPE_DOUBLE;
}
static int compare(grib_accessor* a, grib_accessor* b)
{
int grib_accessor_class_data_apply_bitmap_t::compare(grib_accessor* a, grib_accessor* b){
int retval = GRIB_SUCCESS;
double* aval = 0;
double* bval = 0;
@ -455,13 +336,11 @@ static int compare(grib_accessor* a, grib_accessor* b)
int err = 0;
long count = 0;
err = grib_value_count(a, &count);
if (err)
err = a->value_count(&count); if (err)
return err;
alen = count;
err = grib_value_count(b, &count);
if (err)
err = b->value_count(&count); if (err)
return err;
blen = count;
@ -471,9 +350,7 @@ static int compare(grib_accessor* a, grib_accessor* b)
aval = (double*)grib_context_malloc(a->context, alen * sizeof(double));
bval = (double*)grib_context_malloc(b->context, blen * sizeof(double));
grib_unpack_double(a, aval, &alen);
grib_unpack_double(b, bval, &blen);
a->unpack_double(aval, &alen); b->unpack_double(bval, &blen);
retval = GRIB_SUCCESS;
for (size_t i=0; i<alen && retval == GRIB_SUCCESS; ++i) {
if (aval[i] != bval[i]) retval = GRIB_DOUBLE_VALUE_MISMATCH;

View File

@ -0,0 +1,46 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_apply_bitmap_h
#define eccodes_accessor_data_apply_bitmap_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_data_apply_bitmap_t : public grib_accessor_gen_t
{
public:
/* Members defined in data_apply_bitmap */
const char* coded_values;
const char* bitmap;
const char* missing_value;
const char* number_of_data_points;
const char* number_of_values;
const char* binary_scale_factor;
};
class grib_accessor_class_data_apply_bitmap_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_data_apply_bitmap_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_apply_bitmap_t{}; }
int get_native_type(grib_accessor*) override;
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int unpack_float(grib_accessor*, float* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void dump(grib_accessor*, grib_dumper*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
int compare(grib_accessor*, grib_accessor*) override;
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override;
};
#endif /* eccodes_accessor_data_apply_bitmap_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -9,118 +10,15 @@
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_data_apply_boustrophedonic.h"
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_gen
IMPLEMENTS = init
IMPLEMENTS = unpack_double;unpack_double_element;unpack_double_element_set
IMPLEMENTS = unpack_float
IMPLEMENTS = pack_double
IMPLEMENTS = value_count
IMPLEMENTS = dump;get_native_type
MEMBERS=const char* values
MEMBERS=const char* numberOfRows
MEMBERS=const char* numberOfColumns
MEMBERS=const char* numberOfPoints
MEMBERS=const char* pl
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int get_native_type(grib_accessor*);
static int pack_double(grib_accessor*, const double* val, size_t* len);
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int unpack_float(grib_accessor*, float* val, size_t* len);
static int value_count(grib_accessor*, long*);
static void dump(grib_accessor*, grib_dumper*);
static void init(grib_accessor*, const long, grib_arguments*);
static int unpack_double_element(grib_accessor*, size_t i, double* val);
static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array);
typedef struct grib_accessor_data_apply_boustrophedonic
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in data_apply_boustrophedonic */
const char* values;
const char* numberOfRows;
const char* numberOfColumns;
const char* numberOfPoints;
const char* pl;
} grib_accessor_data_apply_boustrophedonic;
extern grib_accessor_class* grib_accessor_class_gen;
static grib_accessor_class _grib_accessor_class_data_apply_boustrophedonic = {
&grib_accessor_class_gen, /* super */
"data_apply_boustrophedonic", /* name */
sizeof(grib_accessor_data_apply_boustrophedonic), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
&dump, /* dump */
0, /* next_offset */
0, /* get length of string */
&value_count, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
&get_native_type, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
0, /* pack_long */
0, /* unpack_long */
&pack_double, /* pack_double */
0, /* pack_float */
&unpack_double, /* unpack_double */
&unpack_float, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
&unpack_double_element, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
&unpack_double_element_set, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
grib_accessor_class_data_apply_boustrophedonic_t _grib_accessor_class_data_apply_boustrophedonic{"data_apply_boustrophedonic"};
grib_accessor_class* grib_accessor_class_data_apply_boustrophedonic = &_grib_accessor_class_data_apply_boustrophedonic;
/* END_CLASS_IMP */
static void init(grib_accessor* a, const long v, grib_arguments* args)
{
void grib_accessor_class_data_apply_boustrophedonic_t::init(grib_accessor* a, const long v, grib_arguments* args){
int n = 0;
grib_accessor_data_apply_boustrophedonic* self = (grib_accessor_data_apply_boustrophedonic*)a;
grib_accessor_data_apply_boustrophedonic_t* self = (grib_accessor_data_apply_boustrophedonic_t*)a;
self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
self->numberOfRows = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++);
@ -130,14 +28,12 @@ static void init(grib_accessor* a, const long v, grib_arguments* args)
a->length = 0;
}
static void dump(grib_accessor* a, grib_dumper* dumper)
{
void grib_accessor_class_data_apply_boustrophedonic_t::dump(grib_accessor* a, grib_dumper* dumper){
grib_dump_values(dumper, a);
}
static int value_count(grib_accessor* a, long* numberOfPoints)
{
grib_accessor_data_apply_boustrophedonic* self = (grib_accessor_data_apply_boustrophedonic*)a;
int grib_accessor_class_data_apply_boustrophedonic_t::value_count(grib_accessor* a, long* numberOfPoints){
grib_accessor_data_apply_boustrophedonic_t* self = (grib_accessor_data_apply_boustrophedonic_t*)a;
int ret = 0;
*numberOfPoints = 0;
@ -147,9 +43,8 @@ static int value_count(grib_accessor* a, long* numberOfPoints)
}
template <typename T>
static int unpack(grib_accessor* a, T* val, size_t* len)
{
grib_accessor_data_apply_boustrophedonic* self = (grib_accessor_data_apply_boustrophedonic*)a;
int unpack(grib_accessor* a, T* val, size_t* len){
grib_accessor_data_apply_boustrophedonic_t* self = (grib_accessor_data_apply_boustrophedonic_t*)a;
size_t plSize = 0;
long* pl = 0;
@ -242,18 +137,15 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
return GRIB_SUCCESS;
}
static int unpack_double(grib_accessor* a, double* val, size_t* len)
{
int grib_accessor_class_data_apply_boustrophedonic_t::unpack_double(grib_accessor* a, double* val, size_t* len){
return unpack<double>(a, val, len);
}
static int unpack_float(grib_accessor* a, float* val, size_t* len)
{
int grib_accessor_class_data_apply_boustrophedonic_t::unpack_float(grib_accessor* a, float* val, size_t* len){
return unpack<float>(a, val, len);
}
static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
{
int grib_accessor_class_data_apply_boustrophedonic_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){
size_t size;
double* values;
int err = 0;
@ -276,8 +168,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
return GRIB_SUCCESS;
}
static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
{
int grib_accessor_class_data_apply_boustrophedonic_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){
size_t size = 0, i = 0;
double* values;
int err = 0;
@ -304,9 +195,8 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array
return GRIB_SUCCESS;
}
static int pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_apply_boustrophedonic* self = (grib_accessor_data_apply_boustrophedonic*)a;
int grib_accessor_class_data_apply_boustrophedonic_t::pack_double(grib_accessor* a, const double* val, size_t* len){
grib_accessor_data_apply_boustrophedonic_t* self = (grib_accessor_data_apply_boustrophedonic_t*)a;
size_t plSize = 0;
long* pl = 0;
@ -388,7 +278,6 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
return GRIB_SUCCESS;
}
static int get_native_type(grib_accessor* a)
{
int grib_accessor_class_data_apply_boustrophedonic_t::get_native_type(grib_accessor* a){
return GRIB_TYPE_DOUBLE;
}

View File

@ -0,0 +1,44 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_apply_boustrophedonic_h
#define eccodes_accessor_data_apply_boustrophedonic_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_data_apply_boustrophedonic_t : public grib_accessor_gen_t
{
public:
/* Members defined in data_apply_boustrophedonic */
const char* values;
const char* numberOfRows;
const char* numberOfColumns;
const char* numberOfPoints;
const char* pl;
};
class grib_accessor_class_data_apply_boustrophedonic_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_data_apply_boustrophedonic_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_apply_boustrophedonic_t{}; }
int get_native_type(grib_accessor*) override;
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int unpack_float(grib_accessor*, float* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void dump(grib_accessor*, grib_dumper*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override;
};
#endif /* eccodes_accessor_data_apply_boustrophedonic_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -9,121 +10,15 @@
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_data_apply_boustrophedonic_bitmap.h"
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_gen
IMPLEMENTS = init
IMPLEMENTS = unpack_double;unpack_double_element;unpack_double_element_set
IMPLEMENTS = pack_double
IMPLEMENTS = value_count
IMPLEMENTS = dump;get_native_type
MEMBERS=const char* coded_values
MEMBERS=const char* bitmap
MEMBERS=const char* missing_value
MEMBERS=const char* binary_scale_factor
MEMBERS=const char* numberOfRows
MEMBERS=const char* numberOfColumns
MEMBERS=const char* numberOfPoints
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int get_native_type(grib_accessor*);
static int pack_double(grib_accessor*, const double* val, size_t* len);
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int value_count(grib_accessor*, long*);
static void dump(grib_accessor*, grib_dumper*);
static void init(grib_accessor*, const long, grib_arguments*);
static int unpack_double_element(grib_accessor*, size_t i, double* val);
static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array);
typedef struct grib_accessor_data_apply_boustrophedonic_bitmap
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in data_apply_boustrophedonic_bitmap */
const char* coded_values;
const char* bitmap;
const char* missing_value;
const char* binary_scale_factor;
const char* numberOfRows;
const char* numberOfColumns;
const char* numberOfPoints;
} grib_accessor_data_apply_boustrophedonic_bitmap;
extern grib_accessor_class* grib_accessor_class_gen;
static grib_accessor_class _grib_accessor_class_data_apply_boustrophedonic_bitmap = {
&grib_accessor_class_gen, /* super */
"data_apply_boustrophedonic_bitmap", /* name */
sizeof(grib_accessor_data_apply_boustrophedonic_bitmap), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
&dump, /* dump */
0, /* next_offset */
0, /* get length of string */
&value_count, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
&get_native_type, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
0, /* pack_long */
0, /* unpack_long */
&pack_double, /* pack_double */
0, /* pack_float */
&unpack_double, /* unpack_double */
0, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
&unpack_double_element, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
&unpack_double_element_set, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
grib_accessor_class_data_apply_boustrophedonic_bitmap_t _grib_accessor_class_data_apply_boustrophedonic_bitmap{"data_apply_boustrophedonic_bitmap"};
grib_accessor_class* grib_accessor_class_data_apply_boustrophedonic_bitmap = &_grib_accessor_class_data_apply_boustrophedonic_bitmap;
/* END_CLASS_IMP */
static void init(grib_accessor* a, const long v, grib_arguments* args)
{
void grib_accessor_class_data_apply_boustrophedonic_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args){
int n = 0;
grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a;
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
self->coded_values = grib_arguments_get_name(gh, args, n++);
@ -138,14 +33,12 @@ static void init(grib_accessor* a, const long v, grib_arguments* args)
a->length = 0;
}
static void dump(grib_accessor* a, grib_dumper* dumper)
{
void grib_accessor_class_data_apply_boustrophedonic_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper){
grib_dump_values(dumper, a);
}
static int value_count(grib_accessor* a, long* count)
{
grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a;
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::value_count(grib_accessor* a, long* count){
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
size_t len = 0;
int ret = 0;
@ -158,9 +51,8 @@ static int value_count(grib_accessor* a, long* count)
return ret;
}
static int unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a;
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len){
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
size_t i = 0, j = 0, n_vals = 0, irow = 0;
@ -171,8 +63,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
double missing_value = 0;
long numberOfPoints, numberOfRows, numberOfColumns;
err = grib_value_count(a, &nn);
n_vals = nn;
err = a->value_count(&nn); n_vals = nn;
if (err)
return err;
@ -268,9 +159,8 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
return err;
}
static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
{
grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a;
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
int err = 0, i = 0;
size_t cidx = 0;
@ -279,8 +169,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
size_t n_vals = 0;
long nn = 0;
err = grib_value_count(a, &nn);
n_vals = nn;
err = a->value_count(&nn); n_vals = nn;
if (err)
return err;
@ -315,9 +204,8 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
return grib_get_double_element_internal(gh, self->coded_values, cidx, val);
}
static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
{
grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a;
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
int err = 0, all_missing = 1;
size_t cidx = 0; /* index into the coded_values array */
@ -328,8 +216,7 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array
size_t n_vals = 0, i = 0, j = 0, idx = 0, count_1s = 0, ci = 0;
long nn = 0;
err = grib_value_count(a, &nn);
n_vals = nn;
err = a->value_count(&nn); n_vals = nn;
if (err) return err;
if (!grib_find_accessor(gh, self->bitmap))
@ -395,9 +282,8 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array
return GRIB_SUCCESS;
}
static int pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a;
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len){
grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
int err = 0;
size_t bmaplen = *len;
@ -495,9 +381,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
return err;
}
static int get_native_type(grib_accessor* a)
{
//grib_accessor_data_apply_boustrophedonic_bitmap* self = (grib_accessor_data_apply_boustrophedonic_bitmap*)a;
int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::get_native_type(grib_accessor* a){
//grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a;
//return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(a),self->coded_values));
return GRIB_TYPE_DOUBLE;

View File

@ -0,0 +1,45 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_apply_boustrophedonic_bitmap_h
#define eccodes_accessor_data_apply_boustrophedonic_bitmap_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_gen.h"
class grib_accessor_data_apply_boustrophedonic_bitmap_t : public grib_accessor_gen_t
{
public:
/* Members defined in data_apply_boustrophedonic_bitmap */
const char* coded_values;
const char* bitmap;
const char* missing_value;
const char* binary_scale_factor;
const char* numberOfRows;
const char* numberOfColumns;
const char* numberOfPoints;
};
class grib_accessor_class_data_apply_boustrophedonic_bitmap_t : public grib_accessor_class_gen_t
{
public:
grib_accessor_class_data_apply_boustrophedonic_bitmap_t(const char* name) : grib_accessor_class_gen_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_apply_boustrophedonic_bitmap_t{}; }
int get_native_type(grib_accessor*) override;
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void dump(grib_accessor*, grib_dumper*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override;
};
#endif /* eccodes_accessor_data_apply_boustrophedonic_bitmap_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -8,137 +9,16 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_bits_any_endian_simple.h"
#include "grib_api_internal.h"
#include "grib_accessor_class_data_ccsds_packing.h"
#include "grib_scaling.h"
#include <cstdint>
#include <type_traits>
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_values
IMPLEMENTS = init
IMPLEMENTS = unpack_double
IMPLEMENTS = unpack_float
IMPLEMENTS = pack_double
IMPLEMENTS = unpack_double_element;unpack_double_element_set
IMPLEMENTS = value_count
MEMBERS=const char* number_of_values
MEMBERS=const char* reference_value
MEMBERS=const char* binary_scale_factor
MEMBERS=const char* decimal_scale_factor
MEMBERS=const char* optimize_scaling_factor
MEMBERS=const char* bits_per_value
MEMBERS=const char* number_of_data_points
MEMBERS=const char* ccsds_flags
MEMBERS=const char* ccsds_block_size
MEMBERS=const char* ccsds_rsi
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int pack_double(grib_accessor*, const double* val, size_t* len);
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int unpack_float(grib_accessor*, float* val, size_t* len);
static int value_count(grib_accessor*, long*);
static void init(grib_accessor*, const long, grib_arguments*);
static int unpack_double_element(grib_accessor*, size_t i, double* val);
static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array);
typedef struct grib_accessor_data_ccsds_packing
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in values */
int carg;
const char* seclen;
const char* offsetdata;
const char* offsetsection;
int dirty;
/* Members defined in data_ccsds_packing */
const char* number_of_values;
const char* reference_value;
const char* binary_scale_factor;
const char* decimal_scale_factor;
const char* optimize_scaling_factor;
const char* bits_per_value;
const char* number_of_data_points;
const char* ccsds_flags;
const char* ccsds_block_size;
const char* ccsds_rsi;
} grib_accessor_data_ccsds_packing;
extern grib_accessor_class* grib_accessor_class_values;
static grib_accessor_class _grib_accessor_class_data_ccsds_packing = {
&grib_accessor_class_values, /* super */
"data_ccsds_packing", /* name */
sizeof(grib_accessor_data_ccsds_packing), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
0, /* dump */
0, /* next_offset */
0, /* get length of string */
&value_count, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
0, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
0, /* pack_long */
0, /* unpack_long */
&pack_double, /* pack_double */
0, /* pack_float */
&unpack_double, /* unpack_double */
&unpack_float, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
&unpack_double_element, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
&unpack_double_element_set, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
grib_accessor_class_data_ccsds_packing_t _grib_accessor_class_data_ccsds_packing{"data_ccsds_packing"};
grib_accessor_class* grib_accessor_class_data_ccsds_packing = &_grib_accessor_class_data_ccsds_packing;
/* END_CLASS_IMP */
static void init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a;
void grib_accessor_class_data_ccsds_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a;
grib_handle* h = grib_handle_of_accessor(a);
self->number_of_values = grib_arguments_get_name(h, args, self->carg++);
@ -155,9 +35,8 @@ static void init(grib_accessor* a, const long v, grib_arguments* args)
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
static int value_count(grib_accessor* a, long* count)
{
grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a;
int grib_accessor_class_data_ccsds_packing_t::value_count(grib_accessor* a, long* count){
grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a;
*count = 0;
return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, count);
}
@ -177,8 +56,7 @@ static bool is_big_endian()
return reinterpret_cast<const char*>(&endianess_test)[0] == is_big_endian;
}
static void modify_aec_flags(long* flags)
{
void modify_aec_flags(long* flags){
// ECC-1602: Performance improvement: enabled the use of native data types
*flags &= ~AEC_DATA_3BYTE; // disable support for 3-bytes per value
if (is_big_endian())
@ -197,8 +75,7 @@ static const char* aec_get_error_message(int code)
return "Unknown error code";
}
static void print_aec_stream_info(struct aec_stream* strm, const char* func)
{
void print_aec_stream_info(struct aec_stream* strm, const char* func){
fprintf(stderr, "ECCODES DEBUG CCSDS %s aec_stream.flags=%u\n", func, strm->flags);
fprintf(stderr, "ECCODES DEBUG CCSDS %s aec_stream.bits_per_sample=%u\n", func, strm->bits_per_sample);
fprintf(stderr, "ECCODES DEBUG CCSDS %s aec_stream.block_size=%u\n", func, strm->block_size);
@ -207,9 +84,8 @@ static void print_aec_stream_info(struct aec_stream* strm, const char* func)
fprintf(stderr, "ECCODES DEBUG CCSDS %s aec_stream.avail_in=%lu\n", func, strm->avail_in);
}
static int pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a;
int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
const char* cclass_name = a->cclass->name;
@ -499,10 +375,9 @@ cleanup:
}
template <typename T>
static int unpack(grib_accessor* a, T* val, size_t* len)
{
int unpack(grib_accessor* a, T* val, size_t* len){
static_assert(std::is_floating_point<T>::value, "Requires floating point numbers");
grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a;
grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
const char* cclass_name = a->cclass->name;
@ -530,7 +405,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
self->dirty = 0;
if ((err = grib_value_count(a, &nn)) != GRIB_SUCCESS)
if ((err = a->value_count(&nn)) != GRIB_SUCCESS)
return err;
n_vals = nn;
@ -569,10 +444,8 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
bscale = codes_power<T>(binary_scale_factor, 2);
dscale = codes_power<T>(-decimal_scale_factor, 10);
buflen = grib_byte_count(a);
buf = (unsigned char*)hand->buffer->data;
buf += grib_byte_offset(a);
buflen = a->byte_count(); buf = (unsigned char*)hand->buffer->data;
buf += a->byte_offset();
strm.flags = ccsds_flags;
strm.bits_per_sample = bits_per_value;
strm.block_size = ccsds_block_size;
@ -637,20 +510,17 @@ cleanup:
return err;
}
static int unpack_double(grib_accessor* a, double* val, size_t* len)
{
int grib_accessor_class_data_ccsds_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){
return unpack<double>(a, val, len);
}
static int unpack_float(grib_accessor* a, float* val, size_t* len)
{
int grib_accessor_class_data_ccsds_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len){
return unpack<float>(a, val, len);
}
static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
{
int grib_accessor_class_data_ccsds_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){
// The index idx relates to codedValues NOT values!
const grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a;
const grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
int err = 0;
size_t size = 0;
@ -684,9 +554,8 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
return GRIB_SUCCESS;
}
static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
{
const grib_accessor_data_ccsds_packing* self = (grib_accessor_data_ccsds_packing*)a;
int grib_accessor_class_data_ccsds_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){
const grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
size_t size = 0, i = 0;
double* values = NULL;
@ -732,34 +601,28 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array
#else
static void print_error_feature_not_enabled(grib_context* c)
{
static void print_error_feature_not_enabled(grib_context* c){
grib_context_log(c, GRIB_LOG_ERROR,
"CCSDS support not enabled. "
"Please rebuild with -DENABLE_AEC=ON (Adaptive Entropy Coding library)");
}
static int pack_double(grib_accessor* a, const double* val, size_t* len)
{
int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
print_error_feature_not_enabled(a->context);
return GRIB_FUNCTIONALITY_NOT_ENABLED;
}
static int unpack_double(grib_accessor* a, double* val, size_t* len)
{
int grib_accessor_class_data_ccsds_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){
print_error_feature_not_enabled(a->context);
return GRIB_FUNCTIONALITY_NOT_ENABLED;
}
static int unpack_float(grib_accessor* a, float* val, size_t* len)
{
int grib_accessor_class_data_ccsds_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len){
print_error_feature_not_enabled(a->context);
return GRIB_FUNCTIONALITY_NOT_ENABLED;
}
static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
{
int grib_accessor_class_data_ccsds_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){
print_error_feature_not_enabled(a->context);
return GRIB_FUNCTIONALITY_NOT_ENABLED;
}
static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
{
int grib_accessor_class_data_ccsds_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){
print_error_feature_not_enabled(a->context);
return GRIB_FUNCTIONALITY_NOT_ENABLED;
}

View File

@ -0,0 +1,47 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_ccsds_packing_h
#define eccodes_accessor_data_ccsds_packing_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_values.h"
class grib_accessor_data_ccsds_packing_t : public grib_accessor_values_t
{
public:
/* Members defined in data_ccsds_packing */
const char* number_of_values;
const char* reference_value;
const char* binary_scale_factor;
const char* decimal_scale_factor;
const char* optimize_scaling_factor;
const char* bits_per_value;
const char* number_of_data_points;
const char* ccsds_flags;
const char* ccsds_block_size;
const char* ccsds_rsi;
};
class grib_accessor_class_data_ccsds_packing_t : public grib_accessor_class_values_t
{
public:
grib_accessor_class_data_ccsds_packing_t(const char* name) : grib_accessor_class_values_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_ccsds_packing_t{}; }
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int unpack_float(grib_accessor*, float* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override;
};
#endif /* eccodes_accessor_data_ccsds_packing_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -8,147 +9,20 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_ieeefloat.h"
#include "grib_api_internal.h"
#include "grib_accessor_class_data_complex_packing.h"
#include "grib_scaling.h"
#include <cmath>
#include <algorithm>
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_data_simple_packing
IMPLEMENTS = unpack_double
IMPLEMENTS = unpack_float
IMPLEMENTS = pack_double
IMPLEMENTS = value_count
IMPLEMENTS = init
MEMBERS= const char* GRIBEX_sh_bug_present
MEMBERS= const char* ieee_floats
MEMBERS= const char* laplacianOperatorIsSet
MEMBERS= const char* laplacianOperator
MEMBERS= const char* sub_j
MEMBERS= const char* sub_k
MEMBERS= const char* sub_m
MEMBERS= const char* pen_j
MEMBERS= const char* pen_k
MEMBERS= const char* pen_m
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int pack_double(grib_accessor*, const double* val, size_t* len);
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int unpack_float(grib_accessor*, float* val, size_t* len);
static int value_count(grib_accessor*, long*);
static void init(grib_accessor*, const long, grib_arguments*);
typedef struct grib_accessor_data_complex_packing
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in values */
int carg;
const char* seclen;
const char* offsetdata;
const char* offsetsection;
int dirty;
/* Members defined in data_simple_packing */
int edition;
const char* units_factor;
const char* units_bias;
const char* changing_precision;
const char* number_of_values;
const char* bits_per_value;
const char* reference_value;
const char* binary_scale_factor;
const char* decimal_scale_factor;
const char* optimize_scaling_factor;
/* Members defined in data_complex_packing */
const char* GRIBEX_sh_bug_present;
const char* ieee_floats;
const char* laplacianOperatorIsSet;
const char* laplacianOperator;
const char* sub_j;
const char* sub_k;
const char* sub_m;
const char* pen_j;
const char* pen_k;
const char* pen_m;
} grib_accessor_data_complex_packing;
extern grib_accessor_class* grib_accessor_class_data_simple_packing;
static grib_accessor_class _grib_accessor_class_data_complex_packing = {
&grib_accessor_class_data_simple_packing, /* super */
"data_complex_packing", /* name */
sizeof(grib_accessor_data_complex_packing), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
0, /* dump */
0, /* next_offset */
0, /* get length of string */
&value_count, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
0, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
0, /* pack_long */
0, /* unpack_long */
&pack_double, /* pack_double */
0, /* pack_float */
&unpack_double, /* unpack_double */
&unpack_float, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
0, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
0, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
#include "grib_ieeefloat.h"
grib_accessor_class_data_complex_packing_t _grib_accessor_class_data_complex_packing{"data_complex_packing"};
grib_accessor_class* grib_accessor_class_data_complex_packing = &_grib_accessor_class_data_complex_packing;
/* END_CLASS_IMP */
typedef unsigned long (*encode_float_proc)(double);
typedef double (*decode_float_proc)(unsigned long);
static void init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_data_complex_packing* self = (grib_accessor_data_complex_packing*)a;
void grib_accessor_class_data_complex_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
grib_accessor_data_complex_packing_t* self = (grib_accessor_data_complex_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
self->GRIBEX_sh_bug_present = grib_arguments_get_name(gh, args, self->carg++);
@ -165,9 +39,8 @@ static void init(grib_accessor* a, const long v, grib_arguments* args)
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
static int value_count(grib_accessor* a, long* count)
{
grib_accessor_data_complex_packing* self = (grib_accessor_data_complex_packing*)a;
int grib_accessor_class_data_complex_packing_t::value_count(grib_accessor* a, long* count){
grib_accessor_data_complex_packing_t* self = (grib_accessor_data_complex_packing_t*)a;
int ret = 0;
grib_handle* gh = grib_handle_of_accessor(a);
long pen_j = 0;
@ -195,8 +68,7 @@ static int value_count(grib_accessor* a, long* count)
return ret;
}
static double calculate_pfactor(const grib_context* ctx, const double* spectralField, long fieldTruncation, long subsetTruncation)
{
double calculate_pfactor(const grib_context* ctx, const double* spectralField, long fieldTruncation, long subsetTruncation){
/*long n_vals = ((fieldTruncation+1)*(fieldTruncation+2));*/
long loop, index, m, n = 0;
double pFactor, zeps = 1.0e-15;
@ -302,9 +174,8 @@ static double calculate_pfactor(const grib_context* ctx, const double* spectralF
return pFactor;
}
static int pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_complex_packing* self = (grib_accessor_data_complex_packing*)a;
int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
grib_accessor_data_complex_packing_t* self = (grib_accessor_data_complex_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
const char* cclass_name = a->cclass->name;
@ -673,10 +544,9 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
template <typename T>
static int unpack(grib_accessor* a, T* val, size_t* len)
{
int unpack(grib_accessor* a, T* val, size_t* len){
static_assert(std::is_floating_point<T>::value, "Requires floating point numbers");
grib_accessor_data_complex_packing* self = (grib_accessor_data_complex_packing*)a;
grib_accessor_data_complex_packing_t* self = (grib_accessor_data_complex_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
const char* cclass_name = a->cclass->name;
@ -724,8 +594,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
decode_float_proc decode_float = NULL;
err = grib_value_count(a, &n_vals);
if (err)
err = a->value_count(&n_vals); if (err)
return err;
if (*len < n_vals) {
@ -798,8 +667,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
maxv = pen_j + 1;
buf += grib_byte_offset(a);
hres = buf;
buf += a->byte_offset(); hres = buf;
lres = buf;
if (pen_j == sub_j) {
@ -814,8 +682,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
return 0;
}
packed_offset = grib_byte_offset(a) + bytes * (sub_k + 1) * (sub_k + 2);
packed_offset = a->byte_offset() + bytes * (sub_k + 1) * (sub_k + 2);
lpos = 8 * (packed_offset - offsetdata);
s = codes_power<T>(binary_scale_factor, 2);
@ -895,13 +762,11 @@ static int unpack(grib_accessor* a, T* val, size_t* len)
return ret;
}
static int unpack_double(grib_accessor* a, double* val, size_t* len)
{
int grib_accessor_class_data_complex_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){
return unpack<double>(a, val, len);
}
static int unpack_float(grib_accessor* a, float* val, size_t* len)
{
int grib_accessor_class_data_complex_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len){
// TODO(maee): See ECC-1579
// Investigate why results are not bit-identical

View File

@ -0,0 +1,45 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_complex_packing_h
#define eccodes_accessor_data_complex_packing_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_data_simple_packing.h"
class grib_accessor_data_complex_packing_t : public grib_accessor_data_simple_packing_t
{
public:
/* Members defined in data_complex_packing */
const char* GRIBEX_sh_bug_present;
const char* ieee_floats;
const char* laplacianOperatorIsSet;
const char* laplacianOperator;
const char* sub_j;
const char* sub_k;
const char* sub_m;
const char* pen_j;
const char* pen_k;
const char* pen_m;
};
class grib_accessor_class_data_complex_packing_t : public grib_accessor_class_data_simple_packing_t
{
public:
grib_accessor_class_data_complex_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_complex_packing_t{}; }
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int unpack_float(grib_accessor*, float* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_data_complex_packing_h */

View File

@ -0,0 +1,102 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_data_dummy_field.h"
grib_accessor_class_data_dummy_field_t _grib_accessor_class_data_dummy_field{"data_dummy_field"};
grib_accessor_class* grib_accessor_class_data_dummy_field = &_grib_accessor_class_data_dummy_field;
void grib_accessor_class_data_dummy_field_t::init(grib_accessor* a, const long v, grib_arguments* args){
grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a;
self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
self->numberOfPoints = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
self->bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
}
int grib_accessor_class_data_dummy_field_t::unpack_double(grib_accessor* a, double* val, size_t* len){
grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a;
size_t i = 0, n_vals = 0;
long numberOfPoints;
double missing_value = 0;
int err = 0;
if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, &numberOfPoints)) != GRIB_SUCCESS)
return err;
n_vals = numberOfPoints;
if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &missing_value)) != GRIB_SUCCESS)
return err;
if (*len < n_vals) {
*len = n_vals;
return GRIB_ARRAY_TOO_SMALL;
}
for (i = 0; i < n_vals; i++)
val[i] = missing_value;
if (grib_find_accessor(grib_handle_of_accessor(a), self->bitmap)) {
if ((err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->bitmap, val, n_vals)) != GRIB_SUCCESS)
return err;
}
*len = (long)n_vals;
return err;
}
int grib_accessor_class_data_dummy_field_t::pack_double(grib_accessor* a, const double* val, size_t* len){
grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a;
size_t n_vals = *len;
int err = 0;
long bits_per_value = 0;
long half_byte = 0;
size_t buflen = 0;
unsigned char* buf = NULL;
if (*len == 0)
return GRIB_NO_VALUES;
if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS)
return err;
buflen = (1 + ((bits_per_value * n_vals) / 8)) * sizeof(unsigned char);
buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen);
if (!buf)
return GRIB_OUT_OF_MEMORY;
half_byte = (buflen * 8) - ((*len) * bits_per_value);
if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->half_byte, half_byte)) != GRIB_SUCCESS) {
grib_context_free(a->context, buf);
return err;
}
grib_buffer_replace(a, buf, buflen, 1, 1);
grib_context_free(a->context, buf);
return GRIB_SUCCESS;
}
int grib_accessor_class_data_dummy_field_t::value_count(grib_accessor* a, long* numberOfPoints){
grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a;
int err = 0;
*numberOfPoints = 0;
if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, numberOfPoints)) != GRIB_SUCCESS) {
grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to get count of %s (%s)", a->name, grib_get_error_message(err));
}
return err;
}

View File

@ -0,0 +1,37 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_dummy_field_h
#define eccodes_accessor_data_dummy_field_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_data_g1simple_packing.h"
class grib_accessor_data_dummy_field_t : public grib_accessor_data_g1simple_packing_t
{
public:
/* Members defined in data_dummy_field */
const char* missing_value;
const char* numberOfPoints;
const char* bitmap;
};
class grib_accessor_class_data_dummy_field_t : public grib_accessor_class_data_g1simple_packing_t
{
public:
grib_accessor_class_data_dummy_field_t(const char* name) : grib_accessor_class_data_g1simple_packing_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_dummy_field_t{}; }
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_data_dummy_field_h */

View File

@ -0,0 +1,112 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_data_g1complex_packing.h"
grib_accessor_class_data_g1complex_packing_t _grib_accessor_class_data_g1complex_packing{"data_g1complex_packing"};
grib_accessor_class* grib_accessor_class_data_g1complex_packing = &_grib_accessor_class_data_g1complex_packing;
void grib_accessor_class_data_g1complex_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
grib_accessor_data_g1complex_packing_t* self = (grib_accessor_data_g1complex_packing_t*)a;
self->half_byte = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
self->N = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
self->packingType = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
self->ieee_packing = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
self->precision = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
self->edition = 1;
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
int grib_accessor_class_data_g1complex_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
grib_accessor_data_g1complex_packing_t* self = (grib_accessor_data_g1complex_packing_t*)a;
int ret = GRIB_SUCCESS;
long seclen = 0;
long sub_j = 0;
long sub_k = 0;
long sub_m = 0;
long n = 0;
long half_byte = 0;
long bits_per_value = 0;
size_t buflen = 0;
if (*len == 0)
return GRIB_NO_VALUES;
// /* TODO: spectral_ieee does not work */
// if (c->ieee_packing && self->ieee_packing) {
// grib_handle* h = grib_handle_of_accessor(a);
// grib_context* c = a->context;
// char* packingType_s = NULL;
// char* ieee_packing_s = NULL;
// long precision = c->ieee_packing == 32 ? 1 : 2;
// size_t lenstr = strlen(self->ieee_packing);
// packingType_s = grib_context_strdup(c, self->packingType);
// ieee_packing_s = grib_context_strdup(c, self->ieee_packing);
// precision_s = grib_context_strdup(c, self->precision);
// grib_set_string(h, packingType_s, ieee_packing_s, &lenstr);
// grib_set_long(h, precision_s, precision);
// grib_context_free(c, packingType_s);
// grib_context_free(c, ieee_packing_s);
// grib_context_free(c, precision_s);
// return grib_set_double_array(h, "values", val, *len);
// }
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_j, &sub_j)) != GRIB_SUCCESS)
return ret;
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_k, &sub_k)) != GRIB_SUCCESS)
return ret;
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_m, &sub_m)) != GRIB_SUCCESS)
return ret;
self->dirty = 1;
Assert((sub_j == sub_k) && (sub_m == sub_j));
ret = grib_accessor_class_data_complex_packing_t::pack_double(a, val, len);
if (ret == GRIB_SUCCESS) {
n = a->offset + 4 * ((sub_k + 1) * (sub_k + 2));
/* Octet number starts from beginning of message but shouldn't */
if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->N, n)) != GRIB_SUCCESS)
return ret;
// ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetsection, &offsetsection);
// if (ret != GRIB_SUCCESS)
// return ret;
// if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->N, n - offsetsection)) != GRIB_SUCCESS)
// return ret;
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value);
if (ret != GRIB_SUCCESS)
return ret;
ret = grib_get_long_internal(grib_handle_of_accessor(a), self->seclen, &seclen);
if (ret != GRIB_SUCCESS)
return ret;
buflen = 32 * (sub_k + 1) * (sub_k + 2) + (*len - (sub_k + 1) * (sub_k + 2)) * bits_per_value + 18 * 8;
half_byte = seclen * 8 - buflen;
if (a->context->debug == -1) {
fprintf(stderr, "ECCODES DEBUG: half_byte=%ld\n", half_byte);
}
ret = grib_set_long_internal(grib_handle_of_accessor(a), self->half_byte, half_byte);
if (ret != GRIB_SUCCESS)
return ret;
}
return ret;
}

View File

@ -0,0 +1,37 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_g1complex_packing_h
#define eccodes_accessor_data_g1complex_packing_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_data_complex_packing.h"
class grib_accessor_data_g1complex_packing_t : public grib_accessor_data_complex_packing_t
{
public:
/* Members defined in data_g1complex_packing */
const char* N;
const char* half_byte;
const char* packingType;
const char* ieee_packing;
const char* precision;
};
class grib_accessor_class_data_g1complex_packing_t : public grib_accessor_class_data_complex_packing_t
{
public:
grib_accessor_class_data_g1complex_packing_t(const char* name) : grib_accessor_class_data_complex_packing_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1complex_packing_t{}; }
int pack_double(grib_accessor*, const double* val, size_t* len) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_data_g1complex_packing_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -8,157 +9,16 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_scaling.h"
#include "grib_api_internal.h"
#include "grib_accessor_class_data_g1second_order_constant_width_packing.h"
#include "grib_scaling.h"
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_data_simple_packing
IMPLEMENTS = init
IMPLEMENTS = pack_double
IMPLEMENTS = unpack_double;unpack_float
IMPLEMENTS = unpack_double_element;unpack_double_element_set
IMPLEMENTS = value_count
MEMBERS=const char* half_byte
MEMBERS=const char* packingType
MEMBERS=const char* ieee_packing
MEMBERS=const char* precision
MEMBERS=const char* widthOfFirstOrderValues
MEMBERS=const char* N1
MEMBERS=const char* N2
MEMBERS=const char* numberOfGroups
MEMBERS=const char* numberOfSecondOrderPackedValues
MEMBERS=const char* extraValues
MEMBERS=const char* pl
MEMBERS=const char* Ni
MEMBERS=const char* Nj
MEMBERS=const char* jPointsAreConsecutive
MEMBERS=const char* bitmap
MEMBERS=const char* groupWidth
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int pack_double(grib_accessor*, const double* val, size_t* len);
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int unpack_float(grib_accessor*, float* val, size_t* len);
static int value_count(grib_accessor*, long*);
static void init(grib_accessor*, const long, grib_arguments*);
static int unpack_double_element(grib_accessor*, size_t i, double* val);
static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array);
typedef struct grib_accessor_data_g1second_order_constant_width_packing
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in values */
int carg;
const char* seclen;
const char* offsetdata;
const char* offsetsection;
int dirty;
/* Members defined in data_simple_packing */
int edition;
const char* units_factor;
const char* units_bias;
const char* changing_precision;
const char* number_of_values;
const char* bits_per_value;
const char* reference_value;
const char* binary_scale_factor;
const char* decimal_scale_factor;
const char* optimize_scaling_factor;
/* Members defined in data_g1second_order_constant_width_packing */
const char* half_byte;
const char* packingType;
const char* ieee_packing;
const char* precision;
const char* widthOfFirstOrderValues;
const char* N1;
const char* N2;
const char* numberOfGroups;
const char* numberOfSecondOrderPackedValues;
const char* extraValues;
const char* pl;
const char* Ni;
const char* Nj;
const char* jPointsAreConsecutive;
const char* bitmap;
const char* groupWidth;
} grib_accessor_data_g1second_order_constant_width_packing;
extern grib_accessor_class* grib_accessor_class_data_simple_packing;
static grib_accessor_class _grib_accessor_class_data_g1second_order_constant_width_packing = {
&grib_accessor_class_data_simple_packing, /* super */
"data_g1second_order_constant_width_packing", /* name */
sizeof(grib_accessor_data_g1second_order_constant_width_packing), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
0, /* dump */
0, /* next_offset */
0, /* get length of string */
&value_count, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
0, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
0, /* pack_long */
0, /* unpack_long */
&pack_double, /* pack_double */
0, /* pack_float */
&unpack_double, /* unpack_double */
&unpack_float, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
&unpack_double_element, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
&unpack_double_element_set, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
grib_accessor_class_data_g1second_order_constant_width_packing_t _grib_accessor_class_data_g1second_order_constant_width_packing{"data_g1second_order_constant_width_packing"};
grib_accessor_class* grib_accessor_class_data_g1second_order_constant_width_packing = &_grib_accessor_class_data_g1second_order_constant_width_packing;
/* END_CLASS_IMP */
static void init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_data_g1second_order_constant_width_packing* self = (grib_accessor_data_g1second_order_constant_width_packing*)a;
void grib_accessor_class_data_g1second_order_constant_width_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
grib_accessor_data_g1second_order_constant_width_packing_t* self = (grib_accessor_data_g1second_order_constant_width_packing_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
self->half_byte = grib_arguments_get_name(hand, args, self->carg++);
@ -181,10 +41,9 @@ static void init(grib_accessor* a, const long v, grib_arguments* args)
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
static int value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues)
{
int grib_accessor_class_data_g1second_order_constant_width_packing_t::value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues){
int err = 0;
grib_accessor_data_g1second_order_constant_width_packing* self = (grib_accessor_data_g1second_order_constant_width_packing*)a;
grib_accessor_data_g1second_order_constant_width_packing_t* self = (grib_accessor_data_g1second_order_constant_width_packing_t*)a;
*numberOfSecondOrderPackedValues = 0;
err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfSecondOrderPackedValues, numberOfSecondOrderPackedValues);
@ -192,14 +51,12 @@ static int value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues)
return err;
}
static int unpack_float(grib_accessor*, float* val, size_t* len)
{
int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_float(grib_accessor*, float* val, size_t* len){
return GRIB_NOT_IMPLEMENTED;
}
static int unpack_double(grib_accessor* a, double* values, size_t* len)
{
grib_accessor_data_g1second_order_constant_width_packing* self = (grib_accessor_data_g1second_order_constant_width_packing*)a;
int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len){
grib_accessor_data_g1second_order_constant_width_packing_t* self = (grib_accessor_data_g1second_order_constant_width_packing_t*)a;
int ret = 0;
long numberOfGroups, numberOfSecondOrderPackedValues;
long groupWidth = 0;
@ -218,8 +75,7 @@ static int unpack_double(grib_accessor* a, double* values, size_t* len)
long* secondaryBitmap;
grib_handle* hand = grib_handle_of_accessor(a);
buf += grib_byte_offset(a);
buf += a->byte_offset();
if ((ret = grib_get_long_internal(hand, self->numberOfGroups, &numberOfGroups)) != GRIB_SUCCESS)
return ret;
@ -321,15 +177,13 @@ static int unpack_double(grib_accessor* a, double* values, size_t* len)
return ret;
}
static int pack_double(grib_accessor* a, const double* cval, size_t* len)
{
int grib_accessor_class_data_g1second_order_constant_width_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len){
const char* cclass_name = a->cclass->name;
grib_context_log(a->context, GRIB_LOG_ERROR, "%s: %s: Not implemented", cclass_name, __func__);
return GRIB_NOT_IMPLEMENTED;
}
static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
{
int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){
grib_handle* hand = grib_handle_of_accessor(a);
size_t size = 0;
double* values = NULL;
@ -354,8 +208,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
return GRIB_SUCCESS;
}
static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
{
int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){
grib_handle* hand = grib_handle_of_accessor(a);
size_t size = 0, i = 0;
double* values = NULL;

View File

@ -0,0 +1,53 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_g1second_order_constant_width_packing_h
#define eccodes_accessor_data_g1second_order_constant_width_packing_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_data_simple_packing.h"
class grib_accessor_data_g1second_order_constant_width_packing_t : public grib_accessor_data_simple_packing_t
{
public:
/* Members defined in data_g1second_order_constant_width_packing */
const char* half_byte;
const char* packingType;
const char* ieee_packing;
const char* precision;
const char* widthOfFirstOrderValues;
const char* N1;
const char* N2;
const char* numberOfGroups;
const char* numberOfSecondOrderPackedValues;
const char* extraValues;
const char* pl;
const char* Ni;
const char* Nj;
const char* jPointsAreConsecutive;
const char* bitmap;
const char* groupWidth;
};
class grib_accessor_class_data_g1second_order_constant_width_packing_t : public grib_accessor_class_data_simple_packing_t
{
public:
grib_accessor_class_data_g1second_order_constant_width_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1second_order_constant_width_packing_t{}; }
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int unpack_float(grib_accessor*, float* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override;
};
#endif /* eccodes_accessor_data_g1second_order_constant_width_packing_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -8,178 +9,13 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_scaling.h"
#include "grib_api_internal.h"
#include "grib_optimize_decimal_factor.h"
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_data_simple_packing
IMPLEMENTS = init
IMPLEMENTS = pack_double
IMPLEMENTS = unpack_double;unpack_float
IMPLEMENTS = unpack_double_element;unpack_double_element_set
IMPLEMENTS = value_count
IMPLEMENTS = destroy
MEMBERS=const char* half_byte
MEMBERS=const char* packingType
MEMBERS=const char* ieee_packing
MEMBERS=const char* precision
MEMBERS=const char* widthOfFirstOrderValues
MEMBERS=const char* firstOrderValues
MEMBERS=const char* N1
MEMBERS=const char* N2
MEMBERS=const char* numberOfGroups
MEMBERS=const char* codedNumberOfGroups
MEMBERS=const char* numberOfSecondOrderPackedValues
MEMBERS=const char* extraValues
MEMBERS=const char* groupWidths
MEMBERS=const char* widthOfWidths
MEMBERS=const char* groupLengths
MEMBERS=const char* widthOfLengths
MEMBERS=const char* NL
MEMBERS=const char* SPD
MEMBERS=const char* widthOfSPD
MEMBERS=const char* orderOfSPD
MEMBERS=const char* numberOfPoints
MEMBERS=const char* dataFlag
MEMBERS=double* dvalues
MEMBERS=float* fvalues
MEMBERS=int double_dirty
MEMBERS=int float_dirty
MEMBERS=size_t size
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int pack_double(grib_accessor*, const double* val, size_t* len);
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int unpack_float(grib_accessor*, float* val, size_t* len);
static int value_count(grib_accessor*, long*);
static void destroy(grib_context*, grib_accessor*);
static void init(grib_accessor*, const long, grib_arguments*);
static int unpack_double_element(grib_accessor*, size_t i, double* val);
static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array);
typedef struct grib_accessor_data_g1second_order_general_extended_packing
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in values */
int carg;
const char* seclen;
const char* offsetdata;
const char* offsetsection;
int dirty;
/* Members defined in data_simple_packing */
int edition;
const char* units_factor;
const char* units_bias;
const char* changing_precision;
const char* number_of_values;
const char* bits_per_value;
const char* reference_value;
const char* binary_scale_factor;
const char* decimal_scale_factor;
const char* optimize_scaling_factor;
/* Members defined in data_g1second_order_general_extended_packing */
const char* half_byte;
const char* packingType;
const char* ieee_packing;
const char* precision;
const char* widthOfFirstOrderValues;
const char* firstOrderValues;
const char* N1;
const char* N2;
const char* numberOfGroups;
const char* codedNumberOfGroups;
const char* numberOfSecondOrderPackedValues;
const char* extraValues;
const char* groupWidths;
const char* widthOfWidths;
const char* groupLengths;
const char* widthOfLengths;
const char* NL;
const char* SPD;
const char* widthOfSPD;
const char* orderOfSPD;
const char* numberOfPoints;
const char* dataFlag;
double* dvalues;
float* fvalues;
int double_dirty;
int float_dirty;
size_t size;
} grib_accessor_data_g1second_order_general_extended_packing;
extern grib_accessor_class* grib_accessor_class_data_simple_packing;
static grib_accessor_class _grib_accessor_class_data_g1second_order_general_extended_packing = {
&grib_accessor_class_data_simple_packing, /* super */
"data_g1second_order_general_extended_packing", /* name */
sizeof(grib_accessor_data_g1second_order_general_extended_packing), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
&destroy, /* destroy */
0, /* dump */
0, /* next_offset */
0, /* get length of string */
&value_count, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
0, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
0, /* pack_long */
0, /* unpack_long */
&pack_double, /* pack_double */
0, /* pack_float */
&unpack_double, /* unpack_double */
&unpack_float, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
&unpack_double_element, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
&unpack_double_element_set, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
#include "grib_accessor_class_data_g1second_order_general_extended_packing.h"
#include "grib_scaling.h"
grib_accessor_class_data_g1second_order_general_extended_packing_t _grib_accessor_class_data_g1second_order_general_extended_packing{"data_g1second_order_general_extended_packing"};
grib_accessor_class* grib_accessor_class_data_g1second_order_general_extended_packing = &_grib_accessor_class_data_g1second_order_general_extended_packing;
/* END_CLASS_IMP */
#define MAX_NUMBER_OF_GROUPS 65534
#define EFDEBUG 0
@ -203,8 +39,7 @@ static const unsigned long nbits[64] = {
0x1000000000000000, 0x2000000000000000, 0x4000000000000000, 0x8000000000000000
};
static long number_of_bits(grib_handle* h, unsigned long x)
{
long number_of_bits(grib_handle* h, unsigned long x){
const unsigned long* n = nbits;
const int count = sizeof(nbits) / sizeof(nbits[0]);
long i = 0;
@ -220,9 +55,8 @@ static long number_of_bits(grib_handle* h, unsigned long x)
return i;
}
static void init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_data_g1second_order_general_extended_packing* self = (grib_accessor_data_g1second_order_general_extended_packing*)a;
void grib_accessor_class_data_g1second_order_general_extended_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a;
grib_handle* handle = grib_handle_of_accessor(a);
self->half_byte = grib_arguments_get_name(handle, args, self->carg++);
@ -256,9 +90,8 @@ static void init(grib_accessor* a, const long v, grib_arguments* args)
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
static int value_count(grib_accessor* a, long* count)
{
grib_accessor_data_g1second_order_general_extended_packing* self = (grib_accessor_data_g1second_order_general_extended_packing*)a;
int grib_accessor_class_data_g1second_order_general_extended_packing_t::value_count(grib_accessor* a, long* count){
grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a;
long numberOfCodedValues = 0;
long numberOfGroups = 0;
size_t ngroups;
@ -293,8 +126,7 @@ static int value_count(grib_accessor* a, long* count)
return err;
}
static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
{
int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){
size_t size;
double* values;
int err = 0;
@ -317,8 +149,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
return GRIB_SUCCESS;
}
static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
{
int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){
size_t size = 0, i = 0;
double* values;
int err = 0;
@ -345,9 +176,8 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array
return GRIB_SUCCESS;
}
static int unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len)
{
grib_accessor_data_g1second_order_general_extended_packing* self = (grib_accessor_data_g1second_order_general_extended_packing*)a;
int unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len){
grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a;
int ret = 0;
long numberOfGroups, numberOfSecondOrderPackedValues;
long* firstOrderValues = 0;
@ -396,8 +226,9 @@ static int unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len
self->float_dirty = 0;
}
buf += grib_byte_offset(a);
ret = value_count(a, &numberOfValues);
buf += a->byte_offset();
ret = a->value_count(&numberOfValues);
if (ret)
return ret;
@ -565,13 +396,11 @@ static int unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len
return ret;
}
static int unpack_float(grib_accessor* a, float* values, size_t* len)
{
int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_float(grib_accessor* a, float* values, size_t* len){
return unpack(a, NULL, values, len);
}
static int unpack_double(grib_accessor* a, double* values, size_t* len)
{
int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len){
return unpack(a, values, NULL, len);
}
@ -684,8 +513,7 @@ static void grib_split_long_groups(grib_handle* hand, grib_context* c, long* num
grib_context_free(c, localFirstOrderValues);
}
static int get_bits_per_value(grib_handle* h, const char* bits_per_value_str, long* bits_per_value)
{
int get_bits_per_value(grib_handle* h, const char* bits_per_value_str, long* bits_per_value){
int err = 0;
if ((err = grib_get_long_internal(h, bits_per_value_str, bits_per_value)) != GRIB_SUCCESS)
return err;
@ -708,9 +536,8 @@ static int get_bits_per_value(grib_handle* h, const char* bits_per_value_str, lo
// For the old implementation of pack_double, see
// src/deprecated/grib_accessor_class_data_g1second_order_general_extended_packing.pack_double.cc
// See ECC-441 and ECC-261
static int pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_g1second_order_general_extended_packing* self = (grib_accessor_data_g1second_order_general_extended_packing*)a;
int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a;
int ret = 0;
int grib2 = 0;
long bits_per_value, orderOfSPD, binary_scale_factor;
@ -1365,9 +1192,8 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
return GRIB_SUCCESS;
}
static void destroy(grib_context* context, grib_accessor* a)
{
grib_accessor_data_g1second_order_general_extended_packing* self = (grib_accessor_data_g1second_order_general_extended_packing*)a;
void grib_accessor_class_data_g1second_order_general_extended_packing_t::destroy(grib_context* context, grib_accessor* a){
grib_accessor_data_g1second_order_general_extended_packing_t* self = (grib_accessor_data_g1second_order_general_extended_packing_t*)a;
if (self->dvalues != NULL) {
grib_context_free(context, self->dvalues);
self->dvalues = NULL;

View File

@ -0,0 +1,65 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_g1second_order_general_extended_packing_h
#define eccodes_accessor_data_g1second_order_general_extended_packing_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_data_simple_packing.h"
class grib_accessor_data_g1second_order_general_extended_packing_t : public grib_accessor_data_simple_packing_t
{
public:
/* Members defined in data_g1second_order_general_extended_packing */
const char* half_byte;
const char* packingType;
const char* ieee_packing;
const char* precision;
const char* widthOfFirstOrderValues;
const char* firstOrderValues;
const char* N1;
const char* N2;
const char* numberOfGroups;
const char* codedNumberOfGroups;
const char* numberOfSecondOrderPackedValues;
const char* extraValues;
const char* groupWidths;
const char* widthOfWidths;
const char* groupLengths;
const char* widthOfLengths;
const char* NL;
const char* SPD;
const char* widthOfSPD;
const char* orderOfSPD;
const char* numberOfPoints;
const char* dataFlag;
double* dvalues;
float* fvalues;
int double_dirty;
int float_dirty;
size_t size;
};
class grib_accessor_class_data_g1second_order_general_extended_packing_t : public grib_accessor_class_data_simple_packing_t
{
public:
grib_accessor_class_data_g1second_order_general_extended_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1second_order_general_extended_packing_t{}; }
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int unpack_float(grib_accessor*, float* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void destroy(grib_context*, grib_accessor*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override;
};
#endif /* eccodes_accessor_data_g1second_order_general_extended_packing_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -8,156 +9,16 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_scaling.h"
#include "grib_api_internal.h"
#include <type_traits>
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_data_simple_packing
IMPLEMENTS = init
IMPLEMENTS = pack_double
IMPLEMENTS = unpack_double;unpack_float
IMPLEMENTS = value_count
MEMBERS=const char* half_byte
MEMBERS=const char* packingType
MEMBERS=const char* ieee_packing
MEMBERS=const char* precision
MEMBERS=const char* widthOfFirstOrderValues
MEMBERS=const char* N1
MEMBERS=const char* N2
MEMBERS=const char* numberOfGroups
MEMBERS=const char* numberOfSecondOrderPackedValues
MEMBERS=const char* extraValues
MEMBERS=const char* pl
MEMBERS=const char* Ni
MEMBERS=const char* Nj
MEMBERS=const char* jPointsAreConsecutive
MEMBERS=const char* bitmap
MEMBERS=const char* groupWidths
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int pack_double(grib_accessor*, const double* val, size_t* len);
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int unpack_float(grib_accessor*, float* val, size_t* len);
static int value_count(grib_accessor*, long*);
static void init(grib_accessor*, const long, grib_arguments*);
typedef struct grib_accessor_data_g1second_order_general_packing
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in values */
int carg;
const char* seclen;
const char* offsetdata;
const char* offsetsection;
int dirty;
/* Members defined in data_simple_packing */
int edition;
const char* units_factor;
const char* units_bias;
const char* changing_precision;
const char* number_of_values;
const char* bits_per_value;
const char* reference_value;
const char* binary_scale_factor;
const char* decimal_scale_factor;
const char* optimize_scaling_factor;
/* Members defined in data_g1second_order_general_packing */
const char* half_byte;
const char* packingType;
const char* ieee_packing;
const char* precision;
const char* widthOfFirstOrderValues;
const char* N1;
const char* N2;
const char* numberOfGroups;
const char* numberOfSecondOrderPackedValues;
const char* extraValues;
const char* pl;
const char* Ni;
const char* Nj;
const char* jPointsAreConsecutive;
const char* bitmap;
const char* groupWidths;
} grib_accessor_data_g1second_order_general_packing;
extern grib_accessor_class* grib_accessor_class_data_simple_packing;
static grib_accessor_class _grib_accessor_class_data_g1second_order_general_packing = {
&grib_accessor_class_data_simple_packing, /* super */
"data_g1second_order_general_packing", /* name */
sizeof(grib_accessor_data_g1second_order_general_packing), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
0, /* dump */
0, /* next_offset */
0, /* get length of string */
&value_count, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
0, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
0, /* pack_long */
0, /* unpack_long */
&pack_double, /* pack_double */
0, /* pack_float */
&unpack_double, /* unpack_double */
&unpack_float, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
0, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
0, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
#include "grib_accessor_class_data_g1second_order_general_packing.h"
#include "grib_scaling.h"
grib_accessor_class_data_g1second_order_general_packing_t _grib_accessor_class_data_g1second_order_general_packing{"data_g1second_order_general_packing"};
grib_accessor_class* grib_accessor_class_data_g1second_order_general_packing = &_grib_accessor_class_data_g1second_order_general_packing;
/* END_CLASS_IMP */
static void init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_data_g1second_order_general_packing* self = (grib_accessor_data_g1second_order_general_packing*)a;
void grib_accessor_class_data_g1second_order_general_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
grib_accessor_data_g1second_order_general_packing_t* self = (grib_accessor_data_g1second_order_general_packing_t*)a;
grib_handle* hand = grib_handle_of_accessor(a);
self->half_byte = grib_arguments_get_name(hand, args, self->carg++);
@ -180,10 +41,9 @@ static void init(grib_accessor* a, const long v, grib_arguments* args)
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
static int value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues)
{
int grib_accessor_class_data_g1second_order_general_packing_t::value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues){
int err = 0;
grib_accessor_data_g1second_order_general_packing* self = (grib_accessor_data_g1second_order_general_packing*)a;
grib_accessor_data_g1second_order_general_packing_t* self = (grib_accessor_data_g1second_order_general_packing_t*)a;
*numberOfSecondOrderPackedValues = 0;
err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfSecondOrderPackedValues, numberOfSecondOrderPackedValues);
@ -192,10 +52,9 @@ static int value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues)
}
template <typename T>
static int unpack(grib_accessor* a, T* values, size_t* len)
{
int unpack(grib_accessor* a, T* values, size_t* len){
static_assert(std::is_floating_point<T>::value, "Requires floating point numbers");
grib_accessor_data_g1second_order_general_packing* self = (grib_accessor_data_g1second_order_general_packing*)a;
grib_accessor_data_g1second_order_general_packing_t* self = (grib_accessor_data_g1second_order_general_packing_t*)a;
int ret = 0;
long numberOfGroups, numberOfSecondOrderPackedValues;
long* groupWidths = 0;
@ -213,8 +72,7 @@ static int unpack(grib_accessor* a, T* values, size_t* len)
long groupLength, j;
size_t groupWidthsSize;
buf += grib_byte_offset(a);
buf += a->byte_offset();
if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfGroups, &numberOfGroups)) != GRIB_SUCCESS)
return ret;
@ -296,18 +154,15 @@ static int unpack(grib_accessor* a, T* values, size_t* len)
return ret;
}
static int unpack_float(grib_accessor* a, float* values, size_t* len)
{
int grib_accessor_class_data_g1second_order_general_packing_t::unpack_float(grib_accessor* a, float* values, size_t* len){
return unpack<float>(a, values, len);
}
static int unpack_double(grib_accessor* a, double* values, size_t* len)
{
int grib_accessor_class_data_g1second_order_general_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len){
return unpack<double>(a, values, len);
}
static int pack_double(grib_accessor* a, const double* cval, size_t* len)
{
int grib_accessor_class_data_g1second_order_general_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len){
/* return GRIB_NOT_IMPLEMENTED; */
int err = 0;
char type[] = "grid_second_order";

View File

@ -0,0 +1,51 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_g1second_order_general_packing_h
#define eccodes_accessor_data_g1second_order_general_packing_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_data_simple_packing.h"
class grib_accessor_data_g1second_order_general_packing_t : public grib_accessor_data_simple_packing_t
{
public:
/* Members defined in data_g1second_order_general_packing */
const char* half_byte;
const char* packingType;
const char* ieee_packing;
const char* precision;
const char* widthOfFirstOrderValues;
const char* N1;
const char* N2;
const char* numberOfGroups;
const char* numberOfSecondOrderPackedValues;
const char* extraValues;
const char* pl;
const char* Ni;
const char* Nj;
const char* jPointsAreConsecutive;
const char* bitmap;
const char* groupWidths;
};
class grib_accessor_class_data_g1second_order_general_packing_t : public grib_accessor_class_data_simple_packing_t
{
public:
grib_accessor_class_data_g1second_order_general_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1second_order_general_packing_t{}; }
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int unpack_float(grib_accessor*, float* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_data_g1second_order_general_packing_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -8,154 +9,16 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_scaling.h"
#include "grib_api_internal.h"
#include "grib_accessor_class_data_g1second_order_row_by_row_packing.h"
#include "grib_scaling.h"
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_data_simple_packing
IMPLEMENTS = init
IMPLEMENTS = pack_double
IMPLEMENTS = unpack_double;unpack_float
IMPLEMENTS = value_count
MEMBERS=const char* half_byte
MEMBERS=const char* packingType
MEMBERS=const char* ieee_packing
MEMBERS=const char* precision
MEMBERS=const char* widthOfFirstOrderValues
MEMBERS=const char* N1
MEMBERS=const char* N2
MEMBERS=const char* numberOfGroups
MEMBERS=const char* numberOfSecondOrderPackedValues
MEMBERS=const char* extraValues
MEMBERS=const char* pl
MEMBERS=const char* Ni
MEMBERS=const char* Nj
MEMBERS=const char* jPointsAreConsecutive
MEMBERS=const char* bitmap
MEMBERS=const char* groupWidths
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int pack_double(grib_accessor*, const double* val, size_t* len);
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int unpack_float(grib_accessor*, float* val, size_t* len);
static int value_count(grib_accessor*, long*);
static void init(grib_accessor*, const long, grib_arguments*);
typedef struct grib_accessor_data_g1second_order_row_by_row_packing
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in values */
int carg;
const char* seclen;
const char* offsetdata;
const char* offsetsection;
int dirty;
/* Members defined in data_simple_packing */
int edition;
const char* units_factor;
const char* units_bias;
const char* changing_precision;
const char* number_of_values;
const char* bits_per_value;
const char* reference_value;
const char* binary_scale_factor;
const char* decimal_scale_factor;
const char* optimize_scaling_factor;
/* Members defined in data_g1second_order_row_by_row_packing */
const char* half_byte;
const char* packingType;
const char* ieee_packing;
const char* precision;
const char* widthOfFirstOrderValues;
const char* N1;
const char* N2;
const char* numberOfGroups;
const char* numberOfSecondOrderPackedValues;
const char* extraValues;
const char* pl;
const char* Ni;
const char* Nj;
const char* jPointsAreConsecutive;
const char* bitmap;
const char* groupWidths;
} grib_accessor_data_g1second_order_row_by_row_packing;
extern grib_accessor_class* grib_accessor_class_data_simple_packing;
static grib_accessor_class _grib_accessor_class_data_g1second_order_row_by_row_packing = {
&grib_accessor_class_data_simple_packing, /* super */
"data_g1second_order_row_by_row_packing", /* name */
sizeof(grib_accessor_data_g1second_order_row_by_row_packing), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
0, /* dump */
0, /* next_offset */
0, /* get length of string */
&value_count, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
0, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
0, /* pack_long */
0, /* unpack_long */
&pack_double, /* pack_double */
0, /* pack_float */
&unpack_double, /* unpack_double */
&unpack_float, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
0, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
0, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
grib_accessor_class_data_g1second_order_row_by_row_packing_t _grib_accessor_class_data_g1second_order_row_by_row_packing{"data_g1second_order_row_by_row_packing"};
grib_accessor_class* grib_accessor_class_data_g1second_order_row_by_row_packing = &_grib_accessor_class_data_g1second_order_row_by_row_packing;
/* END_CLASS_IMP */
static void init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_data_g1second_order_row_by_row_packing* self = (grib_accessor_data_g1second_order_row_by_row_packing*)a;
void grib_accessor_class_data_g1second_order_row_by_row_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
grib_accessor_data_g1second_order_row_by_row_packing_t* self = (grib_accessor_data_g1second_order_row_by_row_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
self->half_byte = grib_arguments_get_name(gh, args, self->carg++);
@ -178,9 +41,8 @@ static void init(grib_accessor* a, const long v, grib_arguments* args)
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
static int value_count(grib_accessor* a, long* count)
{
grib_accessor_data_g1second_order_row_by_row_packing* self = (grib_accessor_data_g1second_order_row_by_row_packing*)a;
int grib_accessor_class_data_g1second_order_row_by_row_packing_t::value_count(grib_accessor* a, long* count){
grib_accessor_data_g1second_order_row_by_row_packing_t* self = (grib_accessor_data_g1second_order_row_by_row_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
long n = 0, i = 0;
long numberOfRows = 0;
@ -254,9 +116,8 @@ static int value_count(grib_accessor* a, long* count)
}
template <typename T>
static int unpack(grib_accessor* a, T* values, size_t* len)
{
grib_accessor_data_g1second_order_row_by_row_packing* self = (grib_accessor_data_g1second_order_row_by_row_packing*)a;
int unpack(grib_accessor* a, T* values, size_t* len){
grib_accessor_data_g1second_order_row_by_row_packing_t* self = (grib_accessor_data_g1second_order_row_by_row_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
int ret = 0;
long numberOfGroups, numberOfSecondOrderPackedValues;
@ -279,8 +140,7 @@ static int unpack(grib_accessor* a, T* values, size_t* len)
size_t plSize = 0;
long* pl = 0;
buf += grib_byte_offset(a);
buf += a->byte_offset();
if ((ret = grib_get_long_internal(gh, self->numberOfGroups, &numberOfGroups)) != GRIB_SUCCESS)
return ret;
@ -421,18 +281,15 @@ static int unpack(grib_accessor* a, T* values, size_t* len)
return ret;
}
static int unpack_float(grib_accessor* a, float* values, size_t* len)
{
int grib_accessor_class_data_g1second_order_row_by_row_packing_t::unpack_float(grib_accessor* a, float* values, size_t* len){
return unpack<float>(a, values, len);
}
static int unpack_double(grib_accessor* a, double* values, size_t* len)
{
int grib_accessor_class_data_g1second_order_row_by_row_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len){
return unpack<double>(a, values, len);
}
static int pack_double(grib_accessor* a, const double* cval, size_t* len)
{
int grib_accessor_class_data_g1second_order_row_by_row_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len){
int err = 0;
grib_handle* gh = grib_handle_of_accessor(a);
char type[] = "grid_second_order";

View File

@ -0,0 +1,51 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_g1second_order_row_by_row_packing_h
#define eccodes_accessor_data_g1second_order_row_by_row_packing_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_data_simple_packing.h"
class grib_accessor_data_g1second_order_row_by_row_packing_t : public grib_accessor_data_simple_packing_t
{
public:
/* Members defined in data_g1second_order_row_by_row_packing */
const char* half_byte;
const char* packingType;
const char* ieee_packing;
const char* precision;
const char* widthOfFirstOrderValues;
const char* N1;
const char* N2;
const char* numberOfGroups;
const char* numberOfSecondOrderPackedValues;
const char* extraValues;
const char* pl;
const char* Ni;
const char* Nj;
const char* jPointsAreConsecutive;
const char* bitmap;
const char* groupWidths;
};
class grib_accessor_class_data_g1second_order_row_by_row_packing_t : public grib_accessor_class_data_simple_packing_t
{
public:
grib_accessor_class_data_g1second_order_row_by_row_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1second_order_row_by_row_packing_t{}; }
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int unpack_float(grib_accessor*, float* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_data_g1second_order_row_by_row_packing_h */

View File

@ -0,0 +1,128 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_data_g1secondary_bitmap.h"
grib_accessor_class_data_g1secondary_bitmap_t _grib_accessor_class_data_g1secondary_bitmap{"data_g1secondary_bitmap"};
grib_accessor_class* grib_accessor_class_data_g1secondary_bitmap = &_grib_accessor_class_data_g1secondary_bitmap;
void grib_accessor_class_data_g1secondary_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args){
grib_accessor_data_g1secondary_bitmap_t* self = (grib_accessor_data_g1secondary_bitmap_t*)a;
self->number_of_ones = grib_arguments_get_name(grib_handle_of_accessor(a), args, 4);
}
int grib_accessor_class_data_g1secondary_bitmap_t::value_count(grib_accessor* a, long* count){
grib_accessor_data_g1secondary_bitmap_t* self = (grib_accessor_data_g1secondary_bitmap_t*)a;
size_t len = 0;
int err = 0;
long expand_by;
*count = 0;
err = grib_get_long_internal(grib_handle_of_accessor(a), self->expand_by, &expand_by);
if (err)
return err;
err = grib_get_size(grib_handle_of_accessor(a), self->primary_bitmap, &len);
if (err)
return err;
*count = expand_by * len;
return GRIB_SUCCESS;
}
int grib_accessor_class_data_g1secondary_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len){
grib_accessor_data_g1secondary_bitmap_t* self = (grib_accessor_data_g1secondary_bitmap_t*)a;
int err = 0;
long primary_len = 0;
long secondary_len = 0;
double* primary_bitmap = NULL;
double* secondary_bitmap = NULL;
long i = 0;
long j = 0;
long on = 0;
long k;
long m;
double missing_value = 0;
double present_value = 0;
long expand_by = 0;
if (*len == 0)
return GRIB_NO_VALUES;
if ((err = grib_get_long(grib_handle_of_accessor(a), self->expand_by, &expand_by)) != GRIB_SUCCESS)
return err;
if (expand_by <= 0)
return GRIB_ENCODING_ERROR;
if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &missing_value)) != GRIB_SUCCESS)
return err;
if (*len % expand_by) {
/*TODO: issue warning */
return GRIB_ENCODING_ERROR;
}
primary_len = *len / expand_by;
primary_bitmap = (double*)grib_context_malloc_clear(a->context, primary_len * sizeof(double));
if (!primary_bitmap)
return GRIB_OUT_OF_MEMORY;
secondary_len = *len;
secondary_bitmap = (double*)grib_context_malloc_clear(a->context, secondary_len * sizeof(double));
if (!secondary_bitmap) {
grib_context_free(a->context, primary_bitmap);
return GRIB_OUT_OF_MEMORY;
}
if (missing_value == 0)
present_value = 1;
else
present_value = 0;
k = 0;
m = 0;
for (i = 0; i < *len; i += expand_by) {
int cnt = 0;
for (j = 0; j < expand_by; j++)
if (val[i + j] == missing_value)
cnt++;
if (cnt == expand_by) /* all expand_by values are missing */
primary_bitmap[k++] = missing_value;
else {
primary_bitmap[k++] = present_value;
for (j = 0; j < expand_by; j++)
secondary_bitmap[m++] = val[i + j];
on++;
}
}
*len = k;
/*printf("QQQQQQQ %ld %ld second=%ld\n",primary_len,on,m);*/
Assert(k == primary_len);
err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->primary_bitmap, primary_bitmap, k);
if (err == GRIB_SUCCESS)
err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->secondary_bitmap, secondary_bitmap, m);
grib_context_free(a->context, primary_bitmap);
grib_context_free(a->context, secondary_bitmap);
if (err == GRIB_SUCCESS)
err = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_ones, on);
return err;
}

View File

@ -0,0 +1,34 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_g1secondary_bitmap_h
#define eccodes_accessor_data_g1secondary_bitmap_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_data_secondary_bitmap.h"
class grib_accessor_data_g1secondary_bitmap_t : public grib_accessor_data_secondary_bitmap_t
{
public:
/* Members defined in data_g1secondary_bitmap */
const char* number_of_ones;
};
class grib_accessor_class_data_g1secondary_bitmap_t : public grib_accessor_class_data_secondary_bitmap_t
{
public:
grib_accessor_class_data_g1secondary_bitmap_t(const char* name) : grib_accessor_class_data_secondary_bitmap_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1secondary_bitmap_t{}; }
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_data_g1secondary_bitmap_h */

View File

@ -0,0 +1,64 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_data_g1shsimple_packing.h"
grib_accessor_class_data_g1shsimple_packing_t _grib_accessor_class_data_g1shsimple_packing{"data_g1shsimple_packing"};
grib_accessor_class* grib_accessor_class_data_g1shsimple_packing = &_grib_accessor_class_data_g1shsimple_packing;
int grib_accessor_class_data_g1shsimple_packing_t::value_count(grib_accessor* a, long* count){
grib_accessor_data_g1shsimple_packing_t* self = (grib_accessor_data_g1shsimple_packing_t*)a;
size_t len = 0;
int err = 0;
err = grib_get_size(grib_handle_of_accessor(a), self->coded_values, &len);
len += 1;
*count = len;
return err;
}
int grib_accessor_class_data_g1shsimple_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){
grib_accessor_data_g1shsimple_packing_t* self = (grib_accessor_data_g1shsimple_packing_t*)a;
int err = GRIB_SUCCESS;
size_t coded_n_vals = 0;
size_t n_vals = 0;
if ((err = grib_get_size(grib_handle_of_accessor(a), self->coded_values, &coded_n_vals)) != GRIB_SUCCESS)
return err;
n_vals = coded_n_vals + 1;
if (*len < n_vals) {
*len = n_vals;
return GRIB_ARRAY_TOO_SMALL;
}
if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->real_part, val)) != GRIB_SUCCESS)
return err;
val++;
if ((err = grib_get_double_array_internal(grib_handle_of_accessor(a), self->coded_values, val, &coded_n_vals)) != GRIB_SUCCESS)
return err;
grib_context_log(a->context, GRIB_LOG_DEBUG,
"grib_accessor_data_g1shsimple_packing_t_bitmap : unpack_double : creating %s, %d values",
a->name, n_vals);
*len = n_vals;
return err;
}

View File

@ -0,0 +1,32 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_g1shsimple_packing_h
#define eccodes_accessor_data_g1shsimple_packing_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_data_shsimple_packing.h"
class grib_accessor_data_g1shsimple_packing_t : public grib_accessor_data_shsimple_packing_t
{
public:
/* Members defined in data_g1shsimple_packing */
};
class grib_accessor_class_data_g1shsimple_packing_t : public grib_accessor_class_data_shsimple_packing_t
{
public:
grib_accessor_class_data_g1shsimple_packing_t(const char* name) : grib_accessor_class_data_shsimple_packing_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1shsimple_packing_t{}; }
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
};
#endif /* eccodes_accessor_data_g1shsimple_packing_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -8,126 +9,16 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_scaling.h"
#include "grib_api_internal.h"
#include "grib_accessor_class_data_g1simple_packing.h"
#include "grib_scaling.h"
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_data_simple_packing
IMPLEMENTS = init
IMPLEMENTS = pack_double
IMPLEMENTS = value_count
MEMBERS=const char* half_byte
MEMBERS=const char* packingType
MEMBERS=const char* ieee_packing
MEMBERS=const char* precision
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int pack_double(grib_accessor*, const double* val, size_t* len);
static int value_count(grib_accessor*, long*);
static void init(grib_accessor*, const long, grib_arguments*);
typedef struct grib_accessor_data_g1simple_packing
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in values */
int carg;
const char* seclen;
const char* offsetdata;
const char* offsetsection;
int dirty;
/* Members defined in data_simple_packing */
int edition;
const char* units_factor;
const char* units_bias;
const char* changing_precision;
const char* number_of_values;
const char* bits_per_value;
const char* reference_value;
const char* binary_scale_factor;
const char* decimal_scale_factor;
const char* optimize_scaling_factor;
/* Members defined in data_g1simple_packing */
const char* half_byte;
const char* packingType;
const char* ieee_packing;
const char* precision;
} grib_accessor_data_g1simple_packing;
extern grib_accessor_class* grib_accessor_class_data_simple_packing;
static grib_accessor_class _grib_accessor_class_data_g1simple_packing = {
&grib_accessor_class_data_simple_packing, /* super */
"data_g1simple_packing", /* name */
sizeof(grib_accessor_data_g1simple_packing), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
0, /* dump */
0, /* next_offset */
0, /* get length of string */
&value_count, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
0, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
0, /* pack_long */
0, /* unpack_long */
&pack_double, /* pack_double */
0, /* pack_float */
0, /* unpack_double */
0, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
0, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
0, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
grib_accessor_class_data_g1simple_packing_t _grib_accessor_class_data_g1simple_packing{"data_g1simple_packing"};
grib_accessor_class* grib_accessor_class_data_g1simple_packing = &_grib_accessor_class_data_g1simple_packing;
/* END_CLASS_IMP */
static void init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_data_g1simple_packing* self = (grib_accessor_data_g1simple_packing*)a;
void grib_accessor_class_data_g1simple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
grib_accessor_data_g1simple_packing_t* self = (grib_accessor_data_g1simple_packing_t*)a;
self->half_byte = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
self->packingType = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
@ -137,9 +28,8 @@ static void init(grib_accessor* a, const long v, grib_arguments* args)
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
static int value_count(grib_accessor* a, long* number_of_values)
{
grib_accessor_data_g1simple_packing* self = (grib_accessor_data_g1simple_packing*)a;
int grib_accessor_class_data_g1simple_packing_t::value_count(grib_accessor* a, long* number_of_values){
grib_accessor_data_g1simple_packing_t* self = (grib_accessor_data_g1simple_packing_t*)a;
*number_of_values = 0;
/* Special case for when values are cleared */
@ -149,10 +39,8 @@ static int value_count(grib_accessor* a, long* number_of_values)
return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, number_of_values);
}
static int pack_double(grib_accessor* a, const double* cval, size_t* len)
{
grib_accessor_data_g1simple_packing* self = (grib_accessor_data_g1simple_packing*)a;
grib_accessor_class* super = *(a->cclass->super);
int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len){
grib_accessor_data_g1simple_packing_t* self = (grib_accessor_data_g1simple_packing_t*)a;
size_t n_vals = *len;
long half_byte = 0;
@ -234,7 +122,7 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len)
}
}
ret = super->pack_double(a, val, len);
ret = grib_accessor_class_data_simple_packing_t::pack_double(a, val, len);
switch (ret) {
case GRIB_CONSTANT_FIELD:
ret = grib_get_long(grib_handle_of_accessor(a), "constantFieldHalfByte", &constantFieldHalfByte);
@ -319,7 +207,7 @@ static int pack_double(grib_accessor* a, const double* cval, size_t* len)
grib_encode_double_array(n_vals, val, bits_per_value, reference_value, decimal, divisor, encoded, &off);
grib_context_log(a->context, GRIB_LOG_DEBUG,
"grib_accessor_data_g1simple_packing : pack_double : packing %s, %d values", a->name, n_vals);
"grib_accessor_data_g1simple_packing_t : pack_double : packing %s, %d values", a->name, n_vals);
ret = grib_buffer_replace(a, buf, buflen, 1, 1);
if (ret != GRIB_SUCCESS) return ret;

View File

@ -0,0 +1,37 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_g1simple_packing_h
#define eccodes_accessor_data_g1simple_packing_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_data_simple_packing.h"
class grib_accessor_data_g1simple_packing_t : public grib_accessor_data_simple_packing_t
{
public:
/* Members defined in data_g1simple_packing */
const char* half_byte;
const char* packingType;
const char* ieee_packing;
const char* precision;
};
class grib_accessor_class_data_g1simple_packing_t : public grib_accessor_class_data_simple_packing_t
{
public:
grib_accessor_class_data_g1simple_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g1simple_packing_t{}; }
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_data_g1simple_packing_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -8,157 +9,16 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_scaling.h"
#include "grib_api_internal.h"
#include <type_traits>
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_values
IMPLEMENTS = init
IMPLEMENTS = unpack_double
IMPLEMENTS = unpack_float
IMPLEMENTS = pack_double
IMPLEMENTS = unpack_double_element;unpack_double_element_set
IMPLEMENTS = value_count
MEMBERS=const char* numberOfValues
MEMBERS=const char* bits_per_value
MEMBERS=const char* reference_value
MEMBERS=const char* binary_scale_factor
MEMBERS=const char* decimal_scale_factor
MEMBERS=const char* optimize_scale_factor
MEMBERS=const char* typeOfOriginalFieldValues
MEMBERS=const char* groupSplittingMethodUsed
MEMBERS=const char* missingValueManagementUsed
MEMBERS=const char* primaryMissingValueSubstitute
MEMBERS=const char* secondaryMissingValueSubstitute
MEMBERS=const char* numberOfGroupsOfDataValues
MEMBERS=const char* referenceForGroupWidths
MEMBERS=const char* numberOfBitsUsedForTheGroupWidths
MEMBERS=const char* referenceForGroupLengths
MEMBERS=const char* lengthIncrementForTheGroupLengths
MEMBERS=const char* trueLengthOfLastGroup
MEMBERS=const char* numberOfBitsUsedForTheScaledGroupLengths
MEMBERS=const char* orderOfSpatialDifferencing
MEMBERS=const char* numberOfOctetsExtraDescriptors
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int pack_double(grib_accessor*, const double* val, size_t* len);
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int unpack_float(grib_accessor*, float* val, size_t* len);
static int value_count(grib_accessor*, long*);
static void init(grib_accessor*, const long, grib_arguments*);
static int unpack_double_element(grib_accessor*, size_t i, double* val);
static int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array);
typedef struct grib_accessor_data_g22order_packing
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in values */
int carg;
const char* seclen;
const char* offsetdata;
const char* offsetsection;
int dirty;
/* Members defined in data_g22order_packing */
const char* numberOfValues;
const char* bits_per_value;
const char* reference_value;
const char* binary_scale_factor;
const char* decimal_scale_factor;
const char* optimize_scale_factor;
const char* typeOfOriginalFieldValues;
const char* groupSplittingMethodUsed;
const char* missingValueManagementUsed;
const char* primaryMissingValueSubstitute;
const char* secondaryMissingValueSubstitute;
const char* numberOfGroupsOfDataValues;
const char* referenceForGroupWidths;
const char* numberOfBitsUsedForTheGroupWidths;
const char* referenceForGroupLengths;
const char* lengthIncrementForTheGroupLengths;
const char* trueLengthOfLastGroup;
const char* numberOfBitsUsedForTheScaledGroupLengths;
const char* orderOfSpatialDifferencing;
const char* numberOfOctetsExtraDescriptors;
} grib_accessor_data_g22order_packing;
extern grib_accessor_class* grib_accessor_class_values;
static grib_accessor_class _grib_accessor_class_data_g22order_packing = {
&grib_accessor_class_values, /* super */
"data_g22order_packing", /* name */
sizeof(grib_accessor_data_g22order_packing), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
0, /* dump */
0, /* next_offset */
0, /* get length of string */
&value_count, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
0, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
0, /* pack_long */
0, /* unpack_long */
&pack_double, /* pack_double */
0, /* pack_float */
&unpack_double, /* unpack_double */
&unpack_float, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
&unpack_double_element, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
&unpack_double_element_set, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
#include "grib_accessor_class_data_g22order_packing.h"
#include "../grib_scaling.h"
grib_accessor_class_data_g22order_packing_t _grib_accessor_class_data_g22order_packing{"data_g22order_packing"};
grib_accessor_class* grib_accessor_class_data_g22order_packing = &_grib_accessor_class_data_g22order_packing;
/* END_CLASS_IMP */
static void init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_data_g22order_packing* self = reinterpret_cast<grib_accessor_data_g22order_packing*>(a);
void grib_accessor_class_data_g22order_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
grib_accessor_data_g22order_packing_t* self = reinterpret_cast<grib_accessor_data_g22order_packing_t*>(a);
grib_handle* gh = grib_handle_of_accessor(a);
self->numberOfValues = grib_arguments_get_name(gh, args, self->carg++);
@ -206,14 +66,12 @@ struct bitstream_context {
int n_bitstream;
};
static void init_bitstream(bitstream_context *ctx, unsigned char* new_bitstream)
{
void init_bitstream(bitstream_context *ctx, unsigned char* new_bitstream){
ctx->bitstream = new_bitstream;
ctx->n_bitstream = ctx->reg = ctx->rbits = 0;
}
static void finish_bitstream(bitstream_context *ctx)
{
void finish_bitstream(bitstream_context *ctx){
if (ctx->rbits) {
ctx->n_bitstream++;
*ctx->bitstream++ = (ctx->reg << (8 - ctx->rbits)) & 255;
@ -221,8 +79,7 @@ static void finish_bitstream(bitstream_context *ctx)
}
}
static void add_many_bitstream(bitstream_context *ctx, grib_accessor* a, int* t, int n, int n_bits)
{
void add_many_bitstream(bitstream_context *ctx, grib_accessor* a, int* t, int n, int n_bits){
unsigned int jmask;
int i;
const int max_numbits = 25;
@ -245,8 +102,7 @@ static void add_many_bitstream(bitstream_context *ctx, grib_accessor* a, int* t,
}
}
static void add_bitstream(bitstream_context *ctx, grib_accessor* a, int t, int n_bits)
{
void add_bitstream(bitstream_context *ctx, grib_accessor* a, int t, int n_bits){
unsigned int jmask;
const int max_numbits = 25;
@ -270,8 +126,7 @@ static void add_bitstream(bitstream_context *ctx, grib_accessor* a, int t, int n
// find min/max of an integer array
// return 0: if min max found
// return 1: if min max not found, min = max = 0
static int int_min_max_array(int* data, unsigned int n, int* min, int* max)
{
int int_min_max_array(int* data, unsigned int n, int* min, int* max){
unsigned int first;
int mn, mx;
@ -312,8 +167,7 @@ static int int_min_max_array(int* data, unsigned int n, int* min, int* max)
return 0;
}
static double Int_Power(double x, int y)
{
double Int_Power(double x, int y){
double value;
if (y < 0) {
@ -332,8 +186,7 @@ static double Int_Power(double x, int y)
return value;
}
static int min_max_array(double* data, unsigned int n, double* min, double* max)
{
int min_max_array(double* data, unsigned int n, double* min, double* max){
unsigned int first;
double mn, mx;
@ -445,8 +298,7 @@ static int min_max_array(double* data, unsigned int n, double* min, double* max)
// return bms;
// }
static int post_process(grib_context* c, long* vals, long len, long order, long bias, const unsigned long extras[2])
{
int post_process(grib_context* c, long* vals, long len, long order, long bias, const unsigned long extras[2]){
unsigned long last, penultimate = 0, j = 0;
Assert(order > 0);
Assert(order <= 3);
@ -507,10 +359,9 @@ static int post_process(grib_context* c, long* vals, long len, long order, long
}
template <typename T>
static int unpack(grib_accessor* a, T* val, const size_t* len)
{
int unpack(grib_accessor* a, T* val, const size_t* len){
static_assert(std::is_floating_point<T>::value, "Requires floating points numbers");
grib_accessor_data_g22order_packing* self = reinterpret_cast<grib_accessor_data_g22order_packing*>(a);
grib_accessor_data_g22order_packing_t* self = reinterpret_cast<grib_accessor_data_g22order_packing_t*>(a);
const char* cclass_name = a->cclass->name;
grib_handle* gh = grib_handle_of_accessor(a);
@ -557,8 +408,7 @@ static int unpack(grib_accessor* a, T* val, const size_t* len)
long numberOfOctetsExtraDescriptors = 0;
double missingValue = 0;
err = grib_value_count(a, &n_vals);
if (err)
err = a->value_count(&n_vals); if (err)
return err;
if (*len < static_cast<size_t>(n_vals))
@ -755,8 +605,7 @@ static int unpack(grib_accessor* a, T* val, const size_t* len)
return err;
}
static int find_nbits(unsigned int i)
{
int find_nbits(unsigned int i){
#if !defined __GNUC__ || __GNUC__ < 4
int j;
j = 0;
@ -794,8 +643,7 @@ struct section
struct section *head, *tail;
};
static int sizeofsection(struct section* s, int ref_bits, int width_bits, int has_undef)
{
int sizeofsection(struct section* s, int ref_bits, int width_bits, int has_undef){
if (s->mn == INT_MAX) { // all undef
return ref_bits + width_bits;
}
@ -823,8 +671,7 @@ static int sizeofsection2(int mn, int mx, int n, int ref_bits, int width_bits,
return find_nbits(mx - mn + has_undef) * n + ref_bits + width_bits;
}
static int size_all(struct section* s, int ref_bits, int width_bits, int has_undef)
{
int size_all(struct section* s, int ref_bits, int width_bits, int has_undef){
int bits;
bits = 0;
@ -835,8 +682,7 @@ static int size_all(struct section* s, int ref_bits, int width_bits, int has_und
return (bits + 7) / 8;
}
static void move_one_left(struct section* s, int* v)
{
void move_one_left(struct section* s, int* v){
struct section* t;
int val, i, j, k;
@ -901,8 +747,7 @@ static void move_one_left(struct section* s, int* v)
}
}
static void move_one_right(struct section* s, int* v)
{
void move_one_right(struct section* s, int* v){
struct section* t;
int val, i, j, k;
@ -983,8 +828,7 @@ static void move_one_right(struct section* s, int* v)
return;
}
static void exchange(struct section* s, int* v, int has_undef, int LEN_SEC_MAX)
{
void exchange(struct section* s, int* v, int has_undef, int LEN_SEC_MAX){
struct section* t;
int val0, val1, nbit_s, nbit_t;
@ -1059,8 +903,7 @@ static void exchange(struct section* s, int* v, int has_undef, int LEN_SEC_MAX)
}
}
static void merge_j(struct section* h, int ref_bits, int width_bits, int has_undef, int param, int LEN_SEC_MAX)
{
void merge_j(struct section* h, int ref_bits, int width_bits, int has_undef, int param, int LEN_SEC_MAX){
struct section *t, *m;
int size_head, size_mid, size_tail, saving_mt, saving_hm;
int min0, max0, min1, max1;
@ -1164,9 +1007,8 @@ static void merge_j(struct section* h, int ref_bits, int width_bits, int has_und
}
}
static int pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_g22order_packing* self = reinterpret_cast<grib_accessor_data_g22order_packing*>(a);
int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
grib_accessor_data_g22order_packing_t* self = reinterpret_cast<grib_accessor_data_g22order_packing_t*>(a);
grib_handle* gh = grib_handle_of_accessor(a);
const char* cclass_name = a->cclass->name;
@ -1850,18 +1692,15 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len)
return GRIB_SUCCESS;
}
static int unpack_double(grib_accessor* a, double* val, size_t* len)
{
int grib_accessor_class_data_g22order_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){
return unpack<double>(a, val, len);
}
static int unpack_float(grib_accessor* a, float* val, size_t* len)
{
int grib_accessor_class_data_g22order_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len){
return unpack<float>(a, val, len);
}
static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
{
int grib_accessor_class_data_g22order_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val){
size_t size = 0;
double* values = NULL;
int err = grib_get_size(grib_handle_of_accessor(a), "codedValues", &size);
@ -1881,8 +1720,7 @@ static int unpack_double_element(grib_accessor* a, size_t idx, double* val)
return GRIB_SUCCESS;
}
static int unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array)
{
int grib_accessor_class_data_g22order_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array){
size_t size = 0, i = 0;
double* values;
int err = 0;
@ -1909,9 +1747,8 @@ static int unpack_double_element_set(grib_accessor* a, const size_t* index_array
return GRIB_SUCCESS;
}
static int value_count(grib_accessor* a, long* count)
{
grib_accessor_data_g22order_packing* self = reinterpret_cast<grib_accessor_data_g22order_packing*>(a);
int grib_accessor_class_data_g22order_packing_t::value_count(grib_accessor* a, long* count){
grib_accessor_data_g22order_packing_t* self = reinterpret_cast<grib_accessor_data_g22order_packing_t*>(a);
*count = 0;
return grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfValues, count);
}

View File

@ -0,0 +1,57 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_g22order_packing_h
#define eccodes_accessor_data_g22order_packing_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_values.h"
class grib_accessor_data_g22order_packing_t : public grib_accessor_values_t
{
public:
/* Members defined in data_g22order_packing */
const char* numberOfValues;
const char* bits_per_value;
const char* reference_value;
const char* binary_scale_factor;
const char* decimal_scale_factor;
const char* optimize_scale_factor;
const char* typeOfOriginalFieldValues;
const char* groupSplittingMethodUsed;
const char* missingValueManagementUsed;
const char* primaryMissingValueSubstitute;
const char* secondaryMissingValueSubstitute;
const char* numberOfGroupsOfDataValues;
const char* referenceForGroupWidths;
const char* numberOfBitsUsedForTheGroupWidths;
const char* referenceForGroupLengths;
const char* lengthIncrementForTheGroupLengths;
const char* trueLengthOfLastGroup;
const char* numberOfBitsUsedForTheScaledGroupLengths;
const char* orderOfSpatialDifferencing;
const char* numberOfOctetsExtraDescriptors;
};
class grib_accessor_class_data_g22order_packing_t : public grib_accessor_class_values_t
{
public:
grib_accessor_class_data_g22order_packing_t(const char* name) : grib_accessor_class_values_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g22order_packing_t{}; }
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int unpack_float(grib_accessor*, float* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
int unpack_double_element(grib_accessor*, size_t i, double* val) override;
int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override;
};
#endif /* eccodes_accessor_data_g22order_packing_h */

View File

@ -1,3 +1,4 @@
/*
* (C) Copyright 2005- ECMWF.
*
@ -8,156 +9,19 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
/********************************
* philippe.marguinaud@meteo.fr
*******************************/
#include "grib_scaling.h"
#include "grib_api_internal.h"
#include "grib_optimize_decimal_factor.h"
#include <cmath>
#include <algorithm>
/*
This is used by make_class.pl
START_CLASS_DEF
CLASS = accessor
SUPER = grib_accessor_class_data_simple_packing
IMPLEMENTS = init
IMPLEMENTS = unpack_double
IMPLEMENTS = pack_double
IMPLEMENTS = value_count
MEMBERS= const char* ieee_floats
MEMBERS= const char* laplacianOperatorIsSet
MEMBERS= const char* laplacianOperator
MEMBERS= const char* biFourierTruncationType
MEMBERS= const char* sub_i
MEMBERS= const char* sub_j
MEMBERS= const char* bif_i
MEMBERS= const char* bif_j
MEMBERS= const char* biFourierSubTruncationType
MEMBERS= const char* biFourierDoNotPackAxes
MEMBERS= const char* biFourierMakeTemplate
MEMBERS= const char* totalNumberOfValuesInUnpackedSubset
MEMBERS=const char* numberOfValues
END_CLASS_DEF
*/
/* START_CLASS_IMP */
/*
Don't edit anything between START_CLASS_IMP and END_CLASS_IMP
Instead edit values between START_CLASS_DEF and END_CLASS_DEF
or edit "accessor.class" and rerun ./make_class.pl
*/
static int pack_double(grib_accessor*, const double* val, size_t* len);
static int unpack_double(grib_accessor*, double* val, size_t* len);
static int value_count(grib_accessor*, long*);
static void init(grib_accessor*, const long, grib_arguments*);
typedef struct grib_accessor_data_g2bifourier_packing
{
grib_accessor att;
/* Members defined in gen */
/* Members defined in values */
int carg;
const char* seclen;
const char* offsetdata;
const char* offsetsection;
int dirty;
/* Members defined in data_simple_packing */
int edition;
const char* units_factor;
const char* units_bias;
const char* changing_precision;
const char* number_of_values;
const char* bits_per_value;
const char* reference_value;
const char* binary_scale_factor;
const char* decimal_scale_factor;
const char* optimize_scaling_factor;
/* Members defined in data_g2bifourier_packing */
const char* ieee_floats;
const char* laplacianOperatorIsSet;
const char* laplacianOperator;
const char* biFourierTruncationType;
const char* sub_i;
const char* sub_j;
const char* bif_i;
const char* bif_j;
const char* biFourierSubTruncationType;
const char* biFourierDoNotPackAxes;
const char* biFourierMakeTemplate;
const char* totalNumberOfValuesInUnpackedSubset;
const char* numberOfValues;
} grib_accessor_data_g2bifourier_packing;
extern grib_accessor_class* grib_accessor_class_data_simple_packing;
static grib_accessor_class _grib_accessor_class_data_g2bifourier_packing = {
&grib_accessor_class_data_simple_packing, /* super */
"data_g2bifourier_packing", /* name */
sizeof(grib_accessor_data_g2bifourier_packing), /* size */
0, /* inited */
0, /* init_class */
&init, /* init */
0, /* post_init */
0, /* destroy */
0, /* dump */
0, /* next_offset */
0, /* get length of string */
&value_count, /* get number of values */
0, /* get number of bytes */
0, /* get offset to bytes */
0, /* get native type */
0, /* get sub_section */
0, /* pack_missing */
0, /* is_missing */
0, /* pack_long */
0, /* unpack_long */
&pack_double, /* pack_double */
0, /* pack_float */
&unpack_double, /* unpack_double */
0, /* unpack_float */
0, /* pack_string */
0, /* unpack_string */
0, /* pack_string_array */
0, /* unpack_string_array */
0, /* pack_bytes */
0, /* unpack_bytes */
0, /* pack_expression */
0, /* notify_change */
0, /* update_size */
0, /* preferred_size */
0, /* resize */
0, /* nearest_smaller_value */
0, /* next accessor */
0, /* compare vs. another accessor */
0, /* unpack only ith value (double) */
0, /* unpack only ith value (float) */
0, /* unpack a given set of elements (double) */
0, /* unpack a given set of elements (float) */
0, /* unpack a subarray */
0, /* clear */
0, /* clone accessor */
};
#include "grib_accessor_class_data_g2bifourier_packing.h"
#include "grib_scaling.h"
grib_accessor_class_data_g2bifourier_packing_t _grib_accessor_class_data_g2bifourier_packing{"data_g2bifourier_packing"};
grib_accessor_class* grib_accessor_class_data_g2bifourier_packing = &_grib_accessor_class_data_g2bifourier_packing;
/* END_CLASS_IMP */
typedef unsigned long (*encode_float_proc)(double);
typedef double (*decode_float_proc)(unsigned long);
static void init(grib_accessor* a, const long v, grib_arguments* args)
{
grib_accessor_data_g2bifourier_packing* self = (grib_accessor_data_g2bifourier_packing*)a;
void grib_accessor_class_data_g2bifourier_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
self->ieee_floats = grib_arguments_get_name(gh, args, self->carg++);
@ -178,17 +42,15 @@ static void init(grib_accessor* a, const long v, grib_arguments* args)
self->dirty = 1;
}
static int value_count(grib_accessor* a, long* numberOfValues)
{
grib_accessor_data_g2bifourier_packing* self = (grib_accessor_data_g2bifourier_packing*)a;
int grib_accessor_class_data_g2bifourier_packing_t::value_count(grib_accessor* a, long* numberOfValues){
grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
*numberOfValues = 0;
return grib_get_long_internal(gh, self->number_of_values, numberOfValues);
}
static void ellipse(long ni, long nj, long itrunc[], long jtrunc[])
{
void ellipse(long ni, long nj, long itrunc[], long jtrunc[]){
const double zeps = 1.E-10;
const double zauxil = 0.;
int i, j;
@ -229,8 +91,7 @@ static void ellipse(long ni, long nj, long itrunc[], long jtrunc[])
}
}
static void rectangle(long ni, long nj, long itrunc[], long jtrunc[])
{
void rectangle(long ni, long nj, long itrunc[], long jtrunc[]){
int i, j;
/*
@ -248,8 +109,7 @@ static void rectangle(long ni, long nj, long itrunc[], long jtrunc[])
jtrunc[i] = nj;
}
static void diamond(long ni, long nj, long itrunc[], long jtrunc[])
{
void diamond(long ni, long nj, long itrunc[], long jtrunc[]){
int i, j;
if (nj == 0)
@ -311,8 +171,7 @@ typedef struct bif_trunc_t
/*
* Total number of coefficients
*/
static size_t size_bif(bif_trunc_t* bt)
{
size_t size_bif(bif_trunc_t* bt){
size_t n_vals = 0;
int j;
for (j = 0; j <= bt->bif_j; j++)
@ -323,8 +182,7 @@ static size_t size_bif(bif_trunc_t* bt)
/*
* Number of unpacked coefficients
*/
static size_t size_sub(bif_trunc_t* bt)
{
size_t size_sub(bif_trunc_t* bt){
size_t n_vals = 0;
int i, j;
for_ij()
@ -339,8 +197,7 @@ static size_t size_sub(bif_trunc_t* bt)
return n_vals;
}
static double laplam(bif_trunc_t* bt, const double val[])
{
double laplam(bif_trunc_t* bt, const double val[]){
/*
* For bi-Fourier spectral fields, the Laplacian operator is a multiplication by (i*i+j*j)
*/
@ -476,8 +333,7 @@ static double laplam(bif_trunc_t* bt, const double val[])
return zp;
}
static void free_bif_trunc(bif_trunc_t* bt, grib_accessor* a)
{
void free_bif_trunc(bif_trunc_t* bt, grib_accessor* a){
grib_handle* gh = grib_handle_of_accessor(a);
if (bt == NULL)
return;
@ -496,7 +352,7 @@ static void free_bif_trunc(bif_trunc_t* bt, grib_accessor* a)
static bif_trunc_t* new_bif_trunc(grib_accessor* a)
{
int ret;
grib_accessor_data_g2bifourier_packing* self = (grib_accessor_data_g2bifourier_packing*)a;
grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
bif_trunc_t* bt = (bif_trunc_t*)grib_context_malloc(gh->context, sizeof(bif_trunc_t));
@ -607,9 +463,8 @@ cleanup:
return NULL;
}
static int unpack_double(grib_accessor* a, double* val, size_t* len)
{
grib_accessor_data_g2bifourier_packing* self = (grib_accessor_data_g2bifourier_packing*)a;
int grib_accessor_class_data_g2bifourier_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len){
grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
unsigned char* buf = NULL;
@ -633,7 +488,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
int ret = GRIB_SUCCESS;
int i, j, k;
if ((ret = grib_value_count(a, &count)) != GRIB_SUCCESS)
if ((ret = a->value_count(&count)) != GRIB_SUCCESS)
goto cleanup;
bt = new_bif_trunc(a);
@ -659,8 +514,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
self->dirty = 0;
buf = (unsigned char*)gh->buffer->data;
buf += grib_byte_offset(a);
buf += a->byte_offset();
s = codes_power<double>(bt->binary_scale_factor, 2);
d = codes_power<double>(-bt->decimal_scale_factor, 10);
@ -670,7 +524,7 @@ static int unpack_double(grib_accessor* a, double* val, size_t* len)
hres = buf;
lres = buf;
packed_offset = grib_byte_offset(a) + bt->bytes * bt->n_vals_sub;
packed_offset = a->byte_offset() + bt->bytes * bt->n_vals_sub;
lpos = 8 * (packed_offset - offsetdata);
hpos = 0;
@ -706,9 +560,8 @@ cleanup:
return ret;
}
static int pack_double(grib_accessor* a, const double* val, size_t* len)
{
grib_accessor_data_g2bifourier_packing* self = (grib_accessor_data_g2bifourier_packing*)a;
int grib_accessor_class_data_g2bifourier_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a;
grib_handle* gh = grib_handle_of_accessor(a);
const char* cclass_name = a->cclass->name;

View File

@ -0,0 +1,47 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_g2bifourier_packing_h
#define eccodes_accessor_data_g2bifourier_packing_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_data_simple_packing.h"
class grib_accessor_data_g2bifourier_packing_t : public grib_accessor_data_simple_packing_t
{
public:
/* Members defined in data_g2bifourier_packing */
const char* ieee_floats;
const char* laplacianOperatorIsSet;
const char* laplacianOperator;
const char* biFourierTruncationType;
const char* sub_i;
const char* sub_j;
const char* bif_i;
const char* bif_j;
const char* biFourierSubTruncationType;
const char* biFourierDoNotPackAxes;
const char* biFourierMakeTemplate;
const char* totalNumberOfValuesInUnpackedSubset;
const char* numberOfValues;
};
class grib_accessor_class_data_g2bifourier_packing_t : public grib_accessor_class_data_simple_packing_t
{
public:
grib_accessor_class_data_g2bifourier_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g2bifourier_packing_t{}; }
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int unpack_double(grib_accessor*, double* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_data_g2bifourier_packing_h */

View File

@ -0,0 +1,47 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_data_g2complex_packing.h"
grib_accessor_class_data_g2complex_packing_t _grib_accessor_class_data_g2complex_packing{"data_g2complex_packing"};
grib_accessor_class* grib_accessor_class_data_g2complex_packing = &_grib_accessor_class_data_g2complex_packing;
void grib_accessor_class_data_g2complex_packing_t::init(grib_accessor* a, const long v, grib_arguments* args){
grib_accessor_data_g2complex_packing_t* self = (grib_accessor_data_g2complex_packing_t*)a;
self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++);
self->edition = 2;
a->flags |= GRIB_ACCESSOR_FLAG_DATA;
}
int grib_accessor_class_data_g2complex_packing_t::value_count(grib_accessor* a, long* numberOfValues){
grib_accessor_data_g2complex_packing_t* self = (grib_accessor_data_g2complex_packing_t*)a;
*numberOfValues = 0;
return grib_get_long(grib_handle_of_accessor(a), self->numberOfValues, numberOfValues);
}
int grib_accessor_class_data_g2complex_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len){
grib_accessor_data_g2complex_packing_t* self = (grib_accessor_data_g2complex_packing_t*)a;
int ret = GRIB_SUCCESS;
if (*len == 0)
return GRIB_NO_VALUES;
ret = grib_accessor_class_data_complex_packing_t::pack_double(a, val, len);
if (ret == GRIB_SUCCESS)
ret = grib_set_long_internal(grib_handle_of_accessor(a), self->numberOfValues, *len);
return ret;
}

View File

@ -0,0 +1,34 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_g2complex_packing_h
#define eccodes_accessor_data_g2complex_packing_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_data_complex_packing.h"
class grib_accessor_data_g2complex_packing_t : public grib_accessor_data_complex_packing_t
{
public:
/* Members defined in data_g2complex_packing */
const char* numberOfValues;
};
class grib_accessor_class_data_g2complex_packing_t : public grib_accessor_class_data_complex_packing_t
{
public:
grib_accessor_class_data_g2complex_packing_t(const char* name) : grib_accessor_class_data_complex_packing_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g2complex_packing_t{}; }
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_data_g2complex_packing_h */

View File

@ -0,0 +1,107 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#include "grib_api_internal.h"
#include "grib_accessor_class_data_g2secondary_bitmap.h"
grib_accessor_class_data_g2secondary_bitmap_t _grib_accessor_class_data_g2secondary_bitmap{"data_g2secondary_bitmap"};
grib_accessor_class* grib_accessor_class_data_g2secondary_bitmap = &_grib_accessor_class_data_g2secondary_bitmap;
void grib_accessor_class_data_g2secondary_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args){
grib_accessor_data_g2secondary_bitmap_t* self = (grib_accessor_data_g2secondary_bitmap_t*)a;
self->number_of_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, 4);
}
int grib_accessor_class_data_g2secondary_bitmap_t::value_count(grib_accessor* a, long* len){
grib_accessor_data_g2secondary_bitmap_t* self = (grib_accessor_data_g2secondary_bitmap_t*)a;
*len = 0;
return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, len);
}
int grib_accessor_class_data_g2secondary_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len){
grib_accessor_data_g2secondary_bitmap_t* self = (grib_accessor_data_g2secondary_bitmap_t*)a;
int err = 0;
long primary_len = 0, secondary_len = 0;
double* primary_bitmap = NULL;
double* secondary_bitmap = NULL;
long i = 0, j = 0, k = 0, m = 0;
double missing_value = 0, present_value = 0;
long expand_by = 0;
if (*len == 0)
return GRIB_NO_VALUES;
if ((err = grib_get_long(grib_handle_of_accessor(a), self->expand_by, &expand_by)) != GRIB_SUCCESS)
return err;
if (expand_by <= 0)
return GRIB_ENCODING_ERROR;
if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &missing_value)) != GRIB_SUCCESS)
return err;
if (*len % expand_by) {
/*TODO: issue warning */
return GRIB_ENCODING_ERROR;
}
primary_len = *len / expand_by;
primary_bitmap = (double*)grib_context_malloc_clear(a->context, primary_len * sizeof(double));
if (!primary_bitmap)
return GRIB_OUT_OF_MEMORY;
secondary_len = *len;
secondary_bitmap = (double*)grib_context_malloc_clear(a->context, secondary_len * sizeof(double));
if (!secondary_bitmap) {
grib_context_free(a->context, primary_bitmap);
return GRIB_OUT_OF_MEMORY;
}
if (missing_value == 0)
present_value = 1;
else
present_value = 0;
k = 0;
m = 0;
for (i = 0; i < *len; i += expand_by) {
int cnt = 0;
for (j = 0; j < expand_by; j++)
if (val[i + j] == missing_value)
cnt++;
if (cnt == expand_by) /* all expand_by values are missing */
primary_bitmap[k++] = missing_value;
else {
primary_bitmap[k++] = present_value;
for (j = 0; j < expand_by; j++)
secondary_bitmap[m++] = val[i + j];
//on++;
}
}
*len = k;
Assert(k == primary_len);
err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->primary_bitmap, primary_bitmap, k);
if (err == GRIB_SUCCESS)
err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->secondary_bitmap, secondary_bitmap, m);
grib_context_free(a->context, primary_bitmap);
grib_context_free(a->context, secondary_bitmap);
if (err == GRIB_SUCCESS)
err = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_values, *len * expand_by);
return err;
}

View File

@ -0,0 +1,34 @@
/*
* (C) Copyright 2005- ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
*
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
#ifndef eccodes_accessor_data_g2secondary_bitmap_h
#define eccodes_accessor_data_g2secondary_bitmap_h
#include "../grib_api_internal.h"
#include "grib_accessor_class_data_secondary_bitmap.h"
class grib_accessor_data_g2secondary_bitmap_t : public grib_accessor_data_secondary_bitmap_t
{
public:
/* Members defined in data_g2secondary_bitmap */
const char* number_of_values;
};
class grib_accessor_class_data_g2secondary_bitmap_t : public grib_accessor_class_data_secondary_bitmap_t
{
public:
grib_accessor_class_data_g2secondary_bitmap_t(const char* name) : grib_accessor_class_data_secondary_bitmap_t(name) {}
grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g2secondary_bitmap_t{}; }
int pack_double(grib_accessor*, const double* val, size_t* len) override;
int value_count(grib_accessor*, long*) override;
void init(grib_accessor*, const long, grib_arguments*) override;
};
#endif /* eccodes_accessor_data_g2secondary_bitmap_h */

Some files were not shown because too many files have changed in this diff Show More