From 26f586f7c14a943f91b9cd69fcc4003d897ce456 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Mon, 12 Aug 2024 01:54:29 +0200 Subject: [PATCH] Modernisation: Merge accessor classes --- definitions/grib2/local.98.500.def | 2 +- .../grib2/local/ecmf/template.4.40033.def | 2 +- .../grib2/local/ecmf/template.4.40034.def | 2 +- .../grib2/local/ecmf/template.4.65533.def | 12 +- .../grib2/local/ecmf/template.4.65534.def | 12 +- .../grib2/local/kwbc/template.3.32769.def | 4 +- definitions/grib2/localConcepts/ecmf/name.def | 6 - .../grib2/localConcepts/ecmf/paramId.def | 6 - .../grib2/localConcepts/ecmf/shortName.def | 6 - .../grib2/localConcepts/ecmf/units.def | 6 - definitions/grib2/name.def | 12 +- definitions/grib2/paramId.def | 12 +- definitions/grib2/section.1.def | 2 +- definitions/grib2/section.3.def | 2 +- definitions/grib2/section.4.def | 4 +- definitions/grib2/section.5.def | 2 +- definitions/grib2/section.7.def | 2 +- definitions/grib2/shortName.def | 12 +- definitions/grib2/units.def | 12 +- fortran/eccodes_f90_tail.f90 | 6 + fortran/grib_api_externals.h | 2 +- fortran/grib_f90_tail.f90 | 7 + fortran/grib_fortran.cc | 15 +- fortran/grib_fortran_prototypes.h | 1 + src/accessor/grib_accessor.cc | 58 +- src/accessor/grib_accessor.h | 195 +-- ...rib_accessor_class_abstract_long_vector.cc | 4 +- ...grib_accessor_class_abstract_long_vector.h | 17 +- .../grib_accessor_class_abstract_vector.cc | 4 +- .../grib_accessor_class_abstract_vector.h | 15 +- src/accessor/grib_accessor_class_ascii.cc | 94 +- src/accessor/grib_accessor_class_ascii.h | 33 +- src/accessor/grib_accessor_class_bit.cc | 49 +- src/accessor/grib_accessor_class_bit.h | 21 +- src/accessor/grib_accessor_class_bitmap.cc | 118 +- src/accessor/grib_accessor_class_bitmap.h | 41 +- src/accessor/grib_accessor_class_bits.cc | 155 +- src/accessor/grib_accessor_class_bits.h | 41 +- .../grib_accessor_class_bits_per_value.cc | 46 +- .../grib_accessor_class_bits_per_value.h | 21 +- src/accessor/grib_accessor_class_blob.cc | 31 +- src/accessor/grib_accessor_class_blob.h | 17 +- src/accessor/grib_accessor_class_budgdate.cc | 42 +- src/accessor/grib_accessor_class_budgdate.h | 23 +- .../grib_accessor_class_bufr_data_array.cc | 1348 +++++++++-------- .../grib_accessor_class_bufr_data_array.h | 135 +- .../grib_accessor_class_bufr_data_element.cc | 426 +++--- .../grib_accessor_class_bufr_data_element.h | 65 +- ...grib_accessor_class_bufr_elements_table.cc | 94 +- .../grib_accessor_class_bufr_elements_table.h | 33 +- ...ccessor_class_bufr_extract_area_subsets.cc | 81 +- ...accessor_class_bufr_extract_area_subsets.h | 37 +- ...sor_class_bufr_extract_datetime_subsets.cc | 52 +- ...ssor_class_bufr_extract_datetime_subsets.h | 23 +- ...rib_accessor_class_bufr_extract_subsets.cc | 43 +- ...grib_accessor_class_bufr_extract_subsets.h | 25 +- .../grib_accessor_class_bufr_group.cc | 17 +- src/accessor/grib_accessor_class_bufr_group.h | 13 +- ...rib_accessor_class_bufr_simple_thinning.cc | 52 +- ...grib_accessor_class_bufr_simple_thinning.h | 29 +- .../grib_accessor_class_bufr_string_values.cc | 46 +- .../grib_accessor_class_bufr_string_values.h | 27 +- ...essor_class_bufrdc_expanded_descriptors.cc | 54 +- ...cessor_class_bufrdc_expanded_descriptors.h | 25 +- src/accessor/grib_accessor_class_bytes.cc | 35 +- src/accessor/grib_accessor_class_bytes.h | 19 +- .../grib_accessor_class_cf_var_name.cc | 42 +- .../grib_accessor_class_cf_var_name.h | 20 +- ...r_class_change_alternative_row_scanning.cc | 58 +- ...or_class_change_alternative_row_scanning.h | 27 +- ...ccessor_class_change_scanning_direction.cc | 99 +- ...accessor_class_change_scanning_direction.h | 35 +- ...b_accessor_class_check_internal_version.cc | 15 +- ...ib_accessor_class_check_internal_version.h | 15 +- .../grib_accessor_class_closest_date.cc | 80 +- .../grib_accessor_class_closest_date.h | 37 +- src/accessor/grib_accessor_class_codeflag.cc | 55 +- src/accessor/grib_accessor_class_codeflag.h | 19 +- src/accessor/grib_accessor_class_codetable.cc | 368 ++--- src/accessor/grib_accessor_class_codetable.h | 40 +- .../grib_accessor_class_codetable_title.cc | 34 +- .../grib_accessor_class_codetable_title.h | 19 +- .../grib_accessor_class_codetable_units.cc | 36 +- .../grib_accessor_class_codetable_units.h | 19 +- src/accessor/grib_accessor_class_concept.cc | 123 +- src/accessor/grib_accessor_class_concept.h | 35 +- src/accessor/grib_accessor_class_constant.cc | 10 +- src/accessor/grib_accessor_class_constant.h | 9 +- .../grib_accessor_class_count_file.cc | 17 +- src/accessor/grib_accessor_class_count_file.h | 13 +- .../grib_accessor_class_count_missing.cc | 51 +- .../grib_accessor_class_count_missing.h | 25 +- .../grib_accessor_class_count_total.cc | 17 +- .../grib_accessor_class_count_total.h | 13 +- .../grib_accessor_class_data_apply_bitmap.cc | 207 ++- .../grib_accessor_class_data_apply_bitmap.h | 43 +- ...cessor_class_data_apply_boustrophedonic.cc | 131 +- ...ccessor_class_data_apply_boustrophedonic.h | 39 +- ...class_data_apply_boustrophedonic_bitmap.cc | 193 ++- ..._class_data_apply_boustrophedonic_bitmap.h | 41 +- .../grib_accessor_class_data_ccsds_packing.cc | 234 ++- .../grib_accessor_class_data_ccsds_packing.h | 46 +- ...rib_accessor_class_data_complex_packing.cc | 218 ++- ...grib_accessor_class_data_complex_packing.h | 41 +- .../grib_accessor_class_data_dummy_field.cc | 52 +- .../grib_accessor_class_data_dummy_field.h | 25 +- ...b_accessor_class_data_g1complex_packing.cc | 69 +- ...ib_accessor_class_data_g1complex_packing.h | 25 +- ...a_g1second_order_constant_width_packing.cc | 124 +- ...ta_g1second_order_constant_width_packing.h | 57 +- ...g1second_order_general_extended_packing.cc | 356 +++-- ..._g1second_order_general_extended_packing.h | 83 +- ...ass_data_g1second_order_general_packing.cc | 97 +- ...lass_data_g1second_order_general_packing.h | 53 +- ..._data_g1second_order_row_by_row_packing.cc | 147 +- ...s_data_g1second_order_row_by_row_packing.h | 53 +- ..._accessor_class_data_g1secondary_bitmap.cc | 45 +- ...b_accessor_class_data_g1secondary_bitmap.h | 19 +- ..._accessor_class_data_g1shsimple_packing.cc | 29 +- ...b_accessor_class_data_g1shsimple_packing.h | 13 +- ...ib_accessor_class_data_g1simple_packing.cc | 113 +- ...rib_accessor_class_data_g1simple_packing.h | 25 +- ...ib_accessor_class_data_g22order_packing.cc | 357 +++-- ...rib_accessor_class_data_g22order_packing.h | 65 +- ...accessor_class_data_g2bifourier_packing.cc | 141 +- ..._accessor_class_data_g2bifourier_packing.h | 45 +- ...b_accessor_class_data_g2complex_packing.cc | 32 +- ...ib_accessor_class_data_g2complex_packing.h | 19 +- ..._accessor_class_data_g2secondary_bitmap.cc | 44 +- ...b_accessor_class_data_g2secondary_bitmap.h | 19 +- ..._accessor_class_data_g2shsimple_packing.cc | 51 +- ...b_accessor_class_data_g2shsimple_packing.h | 23 +- ...ib_accessor_class_data_g2simple_packing.cc | 74 +- ...rib_accessor_class_data_g2simple_packing.h | 15 +- ...ata_g2simple_packing_with_preprocessing.cc | 49 +- ...data_g2simple_packing_with_preprocessing.h | 23 +- ...ib_accessor_class_data_jpeg2000_packing.cc | 251 ++- ...rib_accessor_class_data_jpeg2000_packing.h | 43 +- .../grib_accessor_class_data_png_packing.cc | 212 ++- .../grib_accessor_class_data_png_packing.h | 42 +- .../grib_accessor_class_data_raw_packing.cc | 95 +- .../grib_accessor_class_data_raw_packing.h | 27 +- ..._accessor_class_data_run_length_packing.cc | 119 +- ...b_accessor_class_data_run_length_packing.h | 31 +- ...ib_accessor_class_data_secondary_bitmap.cc | 62 +- ...rib_accessor_class_data_secondary_bitmap.h | 27 +- .../grib_accessor_class_data_sh_packed.cc | 102 +- .../grib_accessor_class_data_sh_packed.h | 37 +- .../grib_accessor_class_data_sh_unpacked.cc | 84 +- .../grib_accessor_class_data_sh_unpacked.h | 37 +- ...ib_accessor_class_data_shsimple_packing.cc | 35 +- ...rib_accessor_class_data_shsimple_packing.h | 26 +- ...grib_accessor_class_data_simple_packing.cc | 263 ++-- .../grib_accessor_class_data_simple_packing.h | 47 +- .../grib_accessor_class_decimal_precision.cc | 61 +- .../grib_accessor_class_decimal_precision.h | 25 +- .../grib_accessor_class_dictionary.cc | 134 +- src/accessor/grib_accessor_class_dictionary.h | 35 +- src/accessor/grib_accessor_class_dirty.cc | 44 +- src/accessor/grib_accessor_class_dirty.h | 19 +- src/accessor/grib_accessor_class_divdouble.cc | 25 +- src/accessor/grib_accessor_class_divdouble.h | 19 +- src/accessor/grib_accessor_class_double.cc | 47 +- src/accessor/grib_accessor_class_double.h | 17 +- src/accessor/grib_accessor_class_element.cc | 85 +- src/accessor/grib_accessor_class_element.h | 23 +- src/accessor/grib_accessor_class_evaluate.cc | 21 +- src/accessor/grib_accessor_class_evaluate.h | 17 +- ...rib_accessor_class_expanded_descriptors.cc | 263 ++-- ...grib_accessor_class_expanded_descriptors.h | 48 +- ...or_class_from_scale_factor_scaled_value.cc | 109 +- ...sor_class_from_scale_factor_scaled_value.h | 25 +- ...ib_accessor_class_g1_half_byte_codeflag.cc | 37 +- ...rib_accessor_class_g1_half_byte_codeflag.h | 19 +- .../grib_accessor_class_g1_message_length.cc | 56 +- .../grib_accessor_class_g1_message_length.h | 19 +- .../grib_accessor_class_g1_section4_length.cc | 29 +- .../grib_accessor_class_g1_section4_length.h | 19 +- src/accessor/grib_accessor_class_g1bitmap.cc | 51 +- src/accessor/grib_accessor_class_g1bitmap.h | 21 +- src/accessor/grib_accessor_class_g1date.cc | 65 +- src/accessor/grib_accessor_class_g1date.h | 29 +- ...b_accessor_class_g1day_of_the_year_date.cc | 28 +- ...ib_accessor_class_g1day_of_the_year_date.h | 15 +- ...ccessor_class_g1end_of_interval_monthly.cc | 97 +- ...accessor_class_g1end_of_interval_monthly.h | 23 +- .../grib_accessor_class_g1fcperiod.cc | 9 +- src/accessor/grib_accessor_class_g1fcperiod.h | 11 +- .../grib_accessor_class_g1forecastmonth.cc | 68 +- .../grib_accessor_class_g1forecastmonth.h | 31 +- .../grib_accessor_class_g1monthlydate.cc | 21 +- .../grib_accessor_class_g1monthlydate.h | 17 +- ...ass_g1number_of_coded_values_sh_complex.cc | 55 +- ...lass_g1number_of_coded_values_sh_complex.h | 31 +- ...lass_g1number_of_coded_values_sh_simple.cc | 47 +- ...class_g1number_of_coded_values_sh_simple.h | 25 +- .../grib_accessor_class_g1step_range.cc | 248 ++- .../grib_accessor_class_g1step_range.h | 47 +- .../grib_accessor_class_g1verificationdate.cc | 30 +- .../grib_accessor_class_g1verificationdate.h | 21 +- .../grib_accessor_class_g2_aerosol.cc | 64 +- src/accessor/grib_accessor_class_g2_aerosol.h | 25 +- .../grib_accessor_class_g2_chemical.cc | 80 +- .../grib_accessor_class_g2_chemical.h | 25 +- src/accessor/grib_accessor_class_g2_eps.cc | 59 +- src/accessor/grib_accessor_class_g2_eps.h | 29 +- .../grib_accessor_class_g2_mars_labeling.cc | 189 ++- .../grib_accessor_class_g2_mars_labeling.h | 45 +- src/accessor/grib_accessor_class_g2bitmap.cc | 36 +- src/accessor/grib_accessor_class_g2bitmap.h | 19 +- .../grib_accessor_class_g2bitmap_present.cc | 29 +- .../grib_accessor_class_g2bitmap_present.h | 19 +- src/accessor/grib_accessor_class_g2date.cc | 37 +- src/accessor/grib_accessor_class_g2date.h | 25 +- .../grib_accessor_class_g2end_step.cc | 247 +-- src/accessor/grib_accessor_class_g2end_step.h | 63 +- src/accessor/grib_accessor_class_g2grid.cc | 91 +- src/accessor/grib_accessor_class_g2grid.h | 35 +- src/accessor/grib_accessor_class_g2latlon.cc | 64 +- src/accessor/grib_accessor_class_g2latlon.h | 27 +- src/accessor/grib_accessor_class_g2level.cc | 112 +- src/accessor/grib_accessor_class_g2level.h | 31 +- src/accessor/grib_accessor_class_g2lon.cc | 22 +- src/accessor/grib_accessor_class_g2lon.h | 19 +- .../grib_accessor_class_g2step_range.cc | 109 +- .../grib_accessor_class_g2step_range.h | 33 +- .../grib_accessor_class_gaussian_grid_name.cc | 48 +- .../grib_accessor_class_gaussian_grid_name.h | 25 +- .../grib_accessor_class_gds_is_present.cc | 65 +- .../grib_accessor_class_gds_is_present.h | 25 +- ...b_accessor_class_gds_not_present_bitmap.cc | 60 +- ...ib_accessor_class_gds_not_present_bitmap.h | 31 +- src/accessor/grib_accessor_class_gen.cc | 534 +++---- src/accessor/grib_accessor_class_gen.h | 149 +- src/accessor/grib_accessor_class_getenv.cc | 47 +- src/accessor/grib_accessor_class_getenv.h | 28 +- .../grib_accessor_class_global_gaussian.cc | 110 +- .../grib_accessor_class_global_gaussian.h | 39 +- src/accessor/grib_accessor_class_group.cc | 86 +- src/accessor/grib_accessor_class_group.h | 33 +- .../grib_accessor_class_gts_header.cc | 39 +- src/accessor/grib_accessor_class_gts_header.h | 23 +- .../grib_accessor_class_hash_array.cc | 138 +- src/accessor/grib_accessor_class_hash_array.h | 41 +- .../grib_accessor_class_headers_only.cc | 21 +- .../grib_accessor_class_headers_only.h | 15 +- src/accessor/grib_accessor_class_ibmfloat.cc | 89 +- src/accessor/grib_accessor_class_ibmfloat.h | 33 +- src/accessor/grib_accessor_class_ieeefloat.cc | 68 +- src/accessor/grib_accessor_class_ieeefloat.h | 26 +- src/accessor/grib_accessor_class_ifs_param.cc | 40 +- src/accessor/grib_accessor_class_ifs_param.h | 23 +- src/accessor/grib_accessor_class_iterator.cc | 29 +- src/accessor/grib_accessor_class_iterator.h | 18 +- .../grib_accessor_class_julian_date.cc | 187 ++- .../grib_accessor_class_julian_date.h | 47 +- .../grib_accessor_class_julian_day.cc | 58 +- src/accessor/grib_accessor_class_julian_day.h | 31 +- .../grib_accessor_class_ksec1expver.cc | 49 +- .../grib_accessor_class_ksec1expver.h | 17 +- src/accessor/grib_accessor_class_label.cc | 27 +- src/accessor/grib_accessor_class_label.h | 17 +- src/accessor/grib_accessor_class_latitudes.cc | 103 +- src/accessor/grib_accessor_class_latitudes.h | 27 +- .../grib_accessor_class_latlon_increment.cc | 98 +- .../grib_accessor_class_latlon_increment.h | 37 +- .../grib_accessor_class_latlonvalues.cc | 33 +- .../grib_accessor_class_latlonvalues.h | 19 +- .../grib_accessor_class_library_version.cc | 15 +- .../grib_accessor_class_library_version.h | 15 +- .../grib_accessor_class_local_definition.cc | 86 +- .../grib_accessor_class_local_definition.h | 37 +- src/accessor/grib_accessor_class_long.cc | 81 +- src/accessor/grib_accessor_class_long.h | 22 +- .../grib_accessor_class_long_vector.cc | 59 +- .../grib_accessor_class_long_vector.h | 25 +- .../grib_accessor_class_longitudes.cc | 84 +- src/accessor/grib_accessor_class_longitudes.h | 27 +- src/accessor/grib_accessor_class_lookup.cc | 92 +- src/accessor/grib_accessor_class_lookup.h | 34 +- .../grib_accessor_class_mars_param.cc | 38 +- src/accessor/grib_accessor_class_mars_param.h | 23 +- src/accessor/grib_accessor_class_mars_step.cc | 66 +- src/accessor/grib_accessor_class_mars_step.h | 31 +- src/accessor/grib_accessor_class_md5.cc | 89 +- src/accessor/grib_accessor_class_md5.h | 29 +- src/accessor/grib_accessor_class_message.cc | 55 +- src/accessor/grib_accessor_class_message.h | 21 +- .../grib_accessor_class_message_copy.cc | 35 +- .../grib_accessor_class_message_copy.h | 21 +- .../grib_accessor_class_multdouble.cc | 21 +- src/accessor/grib_accessor_class_multdouble.h | 19 +- src/accessor/grib_accessor_class_nearest.cc | 30 +- src/accessor/grib_accessor_class_nearest.h | 19 +- src/accessor/grib_accessor_class_non_alpha.cc | 61 +- src/accessor/grib_accessor_class_non_alpha.h | 27 +- ...b_accessor_class_number_of_coded_values.cc | 49 +- ...ib_accessor_class_number_of_coded_values.h | 25 +- .../grib_accessor_class_number_of_points.cc | 53 +- .../grib_accessor_class_number_of_points.h | 23 +- ...ccessor_class_number_of_points_gaussian.cc | 113 +- ...accessor_class_number_of_points_gaussian.h | 35 +- .../grib_accessor_class_number_of_values.cc | 50 +- .../grib_accessor_class_number_of_values.h | 27 +- ...class_number_of_values_data_raw_packing.cc | 30 +- ..._class_number_of_values_data_raw_packing.h | 21 +- ...grib_accessor_class_octahedral_gaussian.cc | 39 +- .../grib_accessor_class_octahedral_gaussian.h | 25 +- .../grib_accessor_class_octet_number.cc | 29 +- .../grib_accessor_class_octet_number.h | 21 +- .../grib_accessor_class_offset_file.cc | 39 +- .../grib_accessor_class_offset_file.h | 15 +- .../grib_accessor_class_offset_values.cc | 37 +- .../grib_accessor_class_offset_values.h | 21 +- .../grib_accessor_class_optimal_step_units.cc | 92 +- .../grib_accessor_class_optimal_step_units.h | 41 +- .../grib_accessor_class_pack_bufr_values.cc | 46 +- .../grib_accessor_class_pack_bufr_values.h | 35 +- .../grib_accessor_class_packing_type.cc | 47 +- .../grib_accessor_class_packing_type.h | 25 +- src/accessor/grib_accessor_class_pad.cc | 19 +- src/accessor/grib_accessor_class_pad.h | 18 +- src/accessor/grib_accessor_class_padding.cc | 49 +- src/accessor/grib_accessor_class_padding.h | 23 +- src/accessor/grib_accessor_class_padto.cc | 28 +- src/accessor/grib_accessor_class_padto.h | 19 +- src/accessor/grib_accessor_class_padtoeven.cc | 35 +- src/accessor/grib_accessor_class_padtoeven.h | 19 +- .../grib_accessor_class_padtomultiple.cc | 25 +- .../grib_accessor_class_padtomultiple.h | 19 +- src/accessor/grib_accessor_class_position.cc | 31 +- src/accessor/grib_accessor_class_position.h | 17 +- .../grib_accessor_class_proj_string.cc | 61 +- .../grib_accessor_class_proj_string.h | 21 +- src/accessor/grib_accessor_class_raw.cc | 86 +- src/accessor/grib_accessor_class_raw.h | 33 +- .../grib_accessor_class_rdbtime_guess_date.cc | 39 +- .../grib_accessor_class_rdbtime_guess_date.h | 27 +- ...ib_accessor_class_reference_value_error.cc | 31 +- ...rib_accessor_class_reference_value_error.h | 19 +- src/accessor/grib_accessor_class_round.cc | 32 +- src/accessor/grib_accessor_class_round.h | 16 +- src/accessor/grib_accessor_class_scale.cc | 77 +- src/accessor/grib_accessor_class_scale.h | 29 +- .../grib_accessor_class_scale_values.cc | 37 +- .../grib_accessor_class_scale_values.h | 21 +- ...essor_class_second_order_bits_per_value.cc | 60 +- ...cessor_class_second_order_bits_per_value.h | 25 +- src/accessor/grib_accessor_class_section.cc | 81 +- src/accessor/grib_accessor_class_section.h | 23 +- .../grib_accessor_class_section_length.cc | 25 +- .../grib_accessor_class_section_length.h | 15 +- .../grib_accessor_class_section_padding.cc | 34 +- .../grib_accessor_class_section_padding.h | 17 +- .../grib_accessor_class_section_pointer.cc | 80 +- .../grib_accessor_class_section_pointer.h | 27 +- ...rib_accessor_class_select_step_template.cc | 37 +- ...grib_accessor_class_select_step_template.h | 23 +- ...grib_accessor_class_sexagesimal2decimal.cc | 39 +- .../grib_accessor_class_sexagesimal2decimal.h | 17 +- src/accessor/grib_accessor_class_signed.cc | 142 +- src/accessor/grib_accessor_class_signed.h | 35 +- .../grib_accessor_class_signed_bits.cc | 77 +- .../grib_accessor_class_signed_bits.h | 31 +- ...rib_accessor_class_simple_packing_error.cc | 46 +- ...grib_accessor_class_simple_packing_error.h | 25 +- src/accessor/grib_accessor_class_size.cc | 28 +- src/accessor/grib_accessor_class_size.h | 17 +- .../grib_accessor_class_smart_table.cc | 248 +-- .../grib_accessor_class_smart_table.h | 47 +- .../grib_accessor_class_smart_table_column.cc | 107 +- .../grib_accessor_class_smart_table_column.h | 28 +- src/accessor/grib_accessor_class_spd.cc | 109 +- src/accessor/grib_accessor_class_spd.h | 31 +- ...grib_accessor_class_spectral_truncation.cc | 41 +- .../grib_accessor_class_spectral_truncation.h | 23 +- src/accessor/grib_accessor_class_sprintf.cc | 37 +- src/accessor/grib_accessor_class_sprintf.h | 21 +- .../grib_accessor_class_statistics.cc | 109 +- src/accessor/grib_accessor_class_statistics.h | 27 +- ...grib_accessor_class_statistics_spectral.cc | 100 +- .../grib_accessor_class_statistics_spectral.h | 31 +- ...grib_accessor_class_step_human_readable.cc | 34 +- .../grib_accessor_class_step_human_readable.h | 21 +- .../grib_accessor_class_step_in_units.cc | 138 +- .../grib_accessor_class_step_in_units.h | 37 +- src/accessor/grib_accessor_class_sum.cc | 107 +- src/accessor/grib_accessor_class_sum.h | 21 +- .../grib_accessor_class_suppressed.cc | 50 +- src/accessor/grib_accessor_class_suppressed.h | 25 +- src/accessor/grib_accessor_class_time.cc | 64 +- src/accessor/grib_accessor_class_time.h | 25 +- src/accessor/grib_accessor_class_to_double.cc | 94 +- src/accessor/grib_accessor_class_to_double.h | 37 +- .../grib_accessor_class_to_integer.cc | 90 +- src/accessor/grib_accessor_class_to_integer.h | 41 +- src/accessor/grib_accessor_class_to_string.cc | 81 +- src/accessor/grib_accessor_class_to_string.h | 35 +- src/accessor/grib_accessor_class_transient.cc | 9 +- src/accessor/grib_accessor_class_transient.h | 13 +- .../grib_accessor_class_transient_darray.cc | 83 +- .../grib_accessor_class_transient_darray.h | 33 +- src/accessor/grib_accessor_class_trim.cc | 61 +- src/accessor/grib_accessor_class_trim.h | 25 +- src/accessor/grib_accessor_class_uint16.cc | 13 +- src/accessor/grib_accessor_class_uint16.h | 13 +- src/accessor/grib_accessor_class_uint32.cc | 13 +- src/accessor/grib_accessor_class_uint32.h | 13 +- ...rib_accessor_class_uint32_little_endian.cc | 13 +- ...grib_accessor_class_uint32_little_endian.h | 13 +- src/accessor/grib_accessor_class_uint64.cc | 15 +- src/accessor/grib_accessor_class_uint64.h | 13 +- ...rib_accessor_class_uint64_little_endian.cc | 15 +- ...grib_accessor_class_uint64_little_endian.h | 13 +- src/accessor/grib_accessor_class_uint8.cc | 15 +- src/accessor/grib_accessor_class_uint8.h | 13 +- ...b_accessor_class_unexpanded_descriptors.cc | 71 +- ...ib_accessor_class_unexpanded_descriptors.h | 29 +- .../grib_accessor_class_unpack_bufr_values.cc | 70 +- .../grib_accessor_class_unpack_bufr_values.h | 35 +- src/accessor/grib_accessor_class_unsigned.cc | 158 +- src/accessor/grib_accessor_class_unsigned.h | 38 +- .../grib_accessor_class_unsigned_bits.cc | 98 +- .../grib_accessor_class_unsigned_bits.h | 31 +- .../grib_accessor_class_validity_date.cc | 62 +- .../grib_accessor_class_validity_date.h | 29 +- .../grib_accessor_class_validity_time.cc | 69 +- .../grib_accessor_class_validity_time.h | 29 +- src/accessor/grib_accessor_class_values.cc | 91 +- src/accessor/grib_accessor_class_values.h | 38 +- src/accessor/grib_accessor_class_variable.cc | 253 ++-- src/accessor/grib_accessor_class_variable.h | 55 +- src/accessor/grib_accessor_class_vector.cc | 47 +- src/accessor/grib_accessor_class_vector.h | 19 +- src/accessor/grib_accessor_class_when.cc | 23 +- src/accessor/grib_accessor_class_when.h | 17 +- src/accessor/grib_accessors_list.cc | 6 +- src/accessor/grib_accessors_list.h | 3 +- src/action_class_alias.cc | 49 +- src/action_class_assert.cc | 3 - src/action_class_close.cc | 11 +- src/action_class_concept.cc | 13 +- src/action_class_gen.cc | 2 +- src/action_class_hash_array.cc | 6 +- src/action_class_if.cc | 5 +- src/action_class_list.cc | 10 +- src/action_class_modify.cc | 2 +- src/action_class_remove.cc | 6 +- src/action_class_rename.cc | 14 +- src/action_class_section.cc | 14 +- src/action_class_template.cc | 10 +- src/action_class_transient_darray.cc | 2 +- src/action_class_when.cc | 7 +- src/bufr_keys_iterator.cc | 46 +- src/bufr_util.cc | 4 +- src/eccodes.cc | 5 + src/eccodes.h | 2 + src/grib_accessor_class.cc | 112 +- src/grib_accessor_class.h | 412 ++--- src/grib_accessor_classes_hash.cc | 996 ++++++------ src/grib_accessor_factory.h | 409 +++-- src/grib_accessor_factory_hash_list | 410 ++--- src/grib_api.h | 2 + src/grib_buffer.cc | 16 +- src/grib_bufr_descriptor.cc | 2 +- src/grib_dependency.cc | 12 +- src/grib_dumper.cc | 3 - src/grib_dumper_class_bufr_decode_C.cc | 158 +- src/grib_dumper_class_bufr_decode_filter.cc | 152 +- src/grib_dumper_class_bufr_decode_fortran.cc | 152 +- src/grib_dumper_class_bufr_decode_python.cc | 154 +- src/grib_dumper_class_bufr_encode_C.cc | 166 +- src/grib_dumper_class_bufr_encode_filter.cc | 166 +- src/grib_dumper_class_bufr_encode_fortran.cc | 156 +- src/grib_dumper_class_bufr_encode_python.cc | 156 +- src/grib_dumper_class_bufr_simple.cc | 166 +- src/grib_dumper_class_debug.cc | 94 +- src/grib_dumper_class_default.cc | 131 +- src/grib_dumper_class_grib_encode_C.cc | 54 +- src/grib_dumper_class_json.cc | 84 +- src/grib_dumper_class_serialize.cc | 74 +- src/grib_dumper_class_wmo.cc | 116 +- src/grib_expression_class_functor.cc | 14 +- src/grib_handle.cc | 14 +- src/grib_iterator_class_gaussian.cc | 3 - src/grib_iterator_class_latlon_reduced.cc | 5 - src/grib_keys_iterator.cc | 26 +- src/grib_loader_from_handle.cc | 44 +- src/grib_parse_utils.cc | 6 +- src/grib_query.cc | 46 +- src/grib_value.cc | 76 +- src/make_accessor_class_hash.sh | 4 +- tests/CMakeLists.txt | 2 - tests/bufr_check_descriptors.sh | 73 + tests/grib2_templates.sh | 2 +- tests/grib_bitmap.sh | 2 + tests/grib_filter.sh | 17 + tests/grib_list_keys.sh | 6 +- tests/unit_tests.cc | 26 + tools/bufr_compare.cc | 26 +- tools/bufr_compare_dir | 12 +- tools/grib_compare.cc | 4 +- tools/grib_to_netcdf.cc | 28 +- tools/grib_tools.cc | 2 +- tools/gts_compare.cc | 2 +- tools/metar_compare.cc | 2 +- 506 files changed, 13844 insertions(+), 15125 deletions(-) diff --git a/definitions/grib2/local.98.500.def b/definitions/grib2/local.98.500.def index 3fa593b58..d0d055743 100644 --- a/definitions/grib2/local.98.500.def +++ b/definitions/grib2/local.98.500.def @@ -41,7 +41,7 @@ codetable[2] instrument "grib2/tables/local/ecmf/obstat.5.0.table"; codetable[2] dataStream "grib2/tables/local/ecmf/obstat.6.0.table"; -# include "grib2/template.4.horizontal.def" +# include "grib2/templates/template.4.horizontal.def" codetable[2] observationDiagnostic "grib2/tables/local/ecmf/obstat.9.0.table"; diff --git a/definitions/grib2/local/ecmf/template.4.40033.def b/definitions/grib2/local/ecmf/template.4.40033.def index c5a1421ad..76eb92e2d 100644 --- a/definitions/grib2/local/ecmf/template.4.40033.def +++ b/definitions/grib2/local/ecmf/template.4.40033.def @@ -3,4 +3,4 @@ # # This is deprecated and only included for backward compatibility, use template 4.33 # -include "grib2/template.4.33.def" +include "grib2/templates/template.4.33.def" diff --git a/definitions/grib2/local/ecmf/template.4.40034.def b/definitions/grib2/local/ecmf/template.4.40034.def index 3c0fed44a..7897fd582 100644 --- a/definitions/grib2/local/ecmf/template.4.40034.def +++ b/definitions/grib2/local/ecmf/template.4.40034.def @@ -3,4 +3,4 @@ # # This is deprecated and only included for backward compatibility, use template 4.34 # -include "grib2/template.4.34.def" +include "grib2/templates/template.4.34.def" diff --git a/definitions/grib2/local/ecmf/template.4.65533.def b/definitions/grib2/local/ecmf/template.4.65533.def index 9ebacb060..949923b44 100644 --- a/definitions/grib2/local/ecmf/template.4.65533.def +++ b/definitions/grib2/local/ecmf/template.4.65533.def @@ -2,9 +2,9 @@ # TEMPLATE 4.65533, Individual member for large ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer at a point in time -include "grib2/template.4.parameter.def" -include "grib2/template.4.generating_process.def" -include "grib2/template.4.forecast_time.def" -include "grib2/template.4.point_in_time.def" -include "grib2/template.4.horizontal.def" -include "grib2/template.4.leps.def" +include "grib2/templates/template.4.parameter.def" +include "grib2/templates/template.4.generating_process.def" +include "grib2/templates/template.4.forecast_time.def" +include "grib2/templates/template.4.point_in_time.def" +include "grib2/templates/template.4.horizontal.def" +include "grib2/templates/template.4.leps.def" diff --git a/definitions/grib2/local/ecmf/template.4.65534.def b/definitions/grib2/local/ecmf/template.4.65534.def index 208b0d185..0a05fff8e 100644 --- a/definitions/grib2/local/ecmf/template.4.65534.def +++ b/definitions/grib2/local/ecmf/template.4.65534.def @@ -2,9 +2,9 @@ # TEMPLATE 4.65534, Individual member for large ensemble forecast, control and perturbed, at a horizontal level or in a horizontal layer in a continuous or non-continuous time interval -include "grib2/template.4.parameter.def" -include "grib2/template.4.generating_process.def" -include "grib2/template.4.forecast_time.def" -include "grib2/template.4.horizontal.def" -include "grib2/template.4.leps.def" -include "grib2/template.4.statistical.def" +include "grib2/templates/template.4.parameter.def" +include "grib2/templates/template.4.generating_process.def" +include "grib2/templates/template.4.forecast_time.def" +include "grib2/templates/template.4.horizontal.def" +include "grib2/templates/template.4.leps.def" +include "grib2/templates/template.4.statistical.def" diff --git a/definitions/grib2/local/kwbc/template.3.32769.def b/definitions/grib2/local/kwbc/template.3.32769.def index f6ed7da90..5aff8a025 100644 --- a/definitions/grib2/local/kwbc/template.3.32769.def +++ b/definitions/grib2/local/kwbc/template.3.32769.def @@ -3,8 +3,8 @@ # TEMPLATE 3.32769 - Rotate Latitude/Longitude (Arakawa Non-E Staggered grid) # See https://www.nco.ncep.noaa.gov/pmb/docs/grib2/grib2_doc/grib2_temp3-32769.shtml -include "grib2/template.3.shape_of_the_earth.def"; -include "grib2/template.3.grid.def"; +include "grib2/templates/template.3.shape_of_the_earth.def"; +include "grib2/templates/template.3.grid.def"; meta latitudeOfFirstGridPointInDegrees scale(La1,one,grib2divider,truncateDegrees) : dump; meta longitudeOfFirstGridPointInDegrees scale(Lo1,one,grib2divider,truncateDegrees) : dump; diff --git a/definitions/grib2/localConcepts/ecmf/name.def b/definitions/grib2/localConcepts/ecmf/name.def index f2d776220..1e390741a 100644 --- a/definitions/grib2/localConcepts/ecmf/name.def +++ b/definitions/grib2/localConcepts/ecmf/name.def @@ -115,12 +115,6 @@ parameterCategory = 128 ; parameterNumber = 25 ; } -#Lake cover -'Lake cover' = { - discipline = 192 ; - parameterCategory = 128 ; - parameterNumber = 26 ; - } #Snow albedo 'Snow albedo' = { localTablesVersion = 1 ; diff --git a/definitions/grib2/localConcepts/ecmf/paramId.def b/definitions/grib2/localConcepts/ecmf/paramId.def index 705e33a26..ab184ae4d 100644 --- a/definitions/grib2/localConcepts/ecmf/paramId.def +++ b/definitions/grib2/localConcepts/ecmf/paramId.def @@ -115,12 +115,6 @@ parameterCategory = 128 ; parameterNumber = 25 ; } -#Lake cover -'26' = { - discipline = 192 ; - parameterCategory = 128 ; - parameterNumber = 26 ; - } #Snow albedo '32' = { localTablesVersion = 1 ; diff --git a/definitions/grib2/localConcepts/ecmf/shortName.def b/definitions/grib2/localConcepts/ecmf/shortName.def index 78f8f2fe9..e5fa627d0 100644 --- a/definitions/grib2/localConcepts/ecmf/shortName.def +++ b/definitions/grib2/localConcepts/ecmf/shortName.def @@ -115,12 +115,6 @@ parameterCategory = 128 ; parameterNumber = 25 ; } -#Lake cover -'cl' = { - discipline = 192 ; - parameterCategory = 128 ; - parameterNumber = 26 ; - } #Snow albedo 'asn' = { localTablesVersion = 1 ; diff --git a/definitions/grib2/localConcepts/ecmf/units.def b/definitions/grib2/localConcepts/ecmf/units.def index 4f611fb61..7931fee09 100644 --- a/definitions/grib2/localConcepts/ecmf/units.def +++ b/definitions/grib2/localConcepts/ecmf/units.def @@ -115,12 +115,6 @@ parameterCategory = 128 ; parameterNumber = 25 ; } -#Lake cover -'(0 - 1)' = { - discipline = 192 ; - parameterCategory = 128 ; - parameterNumber = 26 ; - } #Snow albedo '(0 - 1)' = { localTablesVersion = 1 ; diff --git a/definitions/grib2/name.def b/definitions/grib2/name.def index e7ff266d0..9db74ef7c 100644 --- a/definitions/grib2/name.def +++ b/definitions/grib2/name.def @@ -181,6 +181,12 @@ parameterCategory = 2 ; parameterNumber = 45 ; } +#Lake cover +'Lake cover' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 2 ; + } #Low vegetation cover 'Low vegetation cover' = { discipline = 2 ; @@ -5416,12 +5422,6 @@ parameterCategory = 0 ; parameterNumber = 12 ; } -#Water fraction -'Water fraction' = { - discipline = 1 ; - parameterCategory = 2 ; - parameterNumber = 2 ; - } #Days since last observation 'Days since last observation' = { discipline = 0 ; diff --git a/definitions/grib2/paramId.def b/definitions/grib2/paramId.def index 9fa1fe993..670e477af 100644 --- a/definitions/grib2/paramId.def +++ b/definitions/grib2/paramId.def @@ -181,6 +181,12 @@ parameterCategory = 2 ; parameterNumber = 45 ; } +#Lake cover +'26' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 2 ; + } #Low vegetation cover '27' = { discipline = 2 ; @@ -5416,12 +5422,6 @@ parameterCategory = 0 ; parameterNumber = 12 ; } -#Water fraction -'240016' = { - discipline = 1 ; - parameterCategory = 2 ; - parameterNumber = 2 ; - } #Days since last observation '240017' = { discipline = 0 ; diff --git a/definitions/grib2/section.1.def b/definitions/grib2/section.1.def index c4e3c21f1..b19eb67f8 100644 --- a/definitions/grib2/section.1.def +++ b/definitions/grib2/section.1.def @@ -115,7 +115,7 @@ alias calendarIdPresent = false; if ( ((section1Length > 21) or setCalendarId > 0) and deleteCalendarId == 0) { alias calendarIdPresent = present; codetable[2] calendarIdentificationTemplateNumber ('1.5.table',masterDir,localDir) : dump,string_type,no_fail; - template calendarIdentification "grib2/template.1.[calendarIdentificationTemplateNumber:l].def"; + template calendarIdentification "grib2/templates/template.1.[calendarIdentificationTemplateNumber:l].def"; } constant conceptsMasterDir="grib2" : hidden; diff --git a/definitions/grib2/section.3.def b/definitions/grib2/section.3.def index 40f21e591..b0d2c8476 100644 --- a/definitions/grib2/section.3.def +++ b/definitions/grib2/section.3.def @@ -38,7 +38,7 @@ alias isRotatedGrid = false; if (gridDefinitionTemplateNumber >= 32768) { template gridDefinitionSection "grib2/local/[centreForLocal]/template.3.[gridDefinitionTemplateNumber:l].def"; } else { - template gridDefinitionSection "grib2/template.3.[gridDefinitionTemplateNumber:l].def"; + template gridDefinitionSection "grib2/templates/template.3.[gridDefinitionTemplateNumber:l].def"; } if(PLPresent){ diff --git a/definitions/grib2/section.4.def b/definitions/grib2/section.4.def index edb34d9b7..3ccdde8c2 100644 --- a/definitions/grib2/section.4.def +++ b/definitions/grib2/section.4.def @@ -68,13 +68,15 @@ transient genVertHeightCoords = 0; if (productDefinitionTemplateNumber >= 32768) { template productDefinition "grib2/local/[centreForLocal]/template.4.[productDefinitionTemplateNumber:l].def"; } else { - template productDefinition "grib2/template.4.[productDefinitionTemplateNumber:l].def"; + template productDefinition "grib2/templates/template.4.[productDefinitionTemplateNumber:l].def"; } if (defined(marsStream) && defined(marsType)) { template_nofail marsKeywords1 "mars/grib.[marsStream:s].[marsType:s].def"; } +concept productDefinitionTemplateName(unknown, "productDefinitionTemplateConcept.def", conceptsDir2,conceptsDir1): no_copy; + template parameters "grib2/parameters.def"; # Hook for local extras diff --git a/definitions/grib2/section.5.def b/definitions/grib2/section.5.def index 49980cdbe..5b2fc1e2b 100644 --- a/definitions/grib2/section.5.def +++ b/definitions/grib2/section.5.def @@ -51,7 +51,7 @@ concept packingType (unknown) { "grid_run_length" = { dataRepresentationTemplateNumber = 200; } } : dump; -template dataRepresentation "grib2/template.5.[dataRepresentationTemplateNumber:l].def"; +template dataRepresentation "grib2/templates/template.5.[dataRepresentationTemplateNumber:l].def"; alias ls.packingType=packingType; alias dataRepresentation=packingType; diff --git a/definitions/grib2/section.7.def b/definitions/grib2/section.7.def index f6d947674..0dc40afe4 100644 --- a/definitions/grib2/section.7.def +++ b/definitions/grib2/section.7.def @@ -13,7 +13,7 @@ unsigned[1] numberOfSection = 7:read_only; # Template number given in octets 10-11 of Section 5 position offsetBeforeData; #if (changed(dataRepresentationTemplateNumber)) { - template dataValues "grib2/template.7.[dataRepresentationTemplateNumber:l].def"; + template dataValues "grib2/templates/template.7.[dataRepresentationTemplateNumber:l].def"; #} meta changeDecimalPrecision decimal_precision(bitsPerValue,decimalScaleFactor,changingPrecision,values) : edition_specific; diff --git a/definitions/grib2/shortName.def b/definitions/grib2/shortName.def index 51823f5a7..81e6cd53a 100644 --- a/definitions/grib2/shortName.def +++ b/definitions/grib2/shortName.def @@ -181,6 +181,12 @@ parameterCategory = 2 ; parameterNumber = 45 ; } +#Lake cover +'cl' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 2 ; + } #Low vegetation cover 'cvl' = { discipline = 2 ; @@ -5416,12 +5422,6 @@ parameterCategory = 0 ; parameterNumber = 12 ; } -#Water fraction -'fldfrc' = { - discipline = 1 ; - parameterCategory = 2 ; - parameterNumber = 2 ; - } #Days since last observation 'dslr' = { discipline = 0 ; diff --git a/definitions/grib2/units.def b/definitions/grib2/units.def index 6ed54fc31..b6ebdbf3f 100644 --- a/definitions/grib2/units.def +++ b/definitions/grib2/units.def @@ -181,6 +181,12 @@ parameterCategory = 2 ; parameterNumber = 45 ; } +#Lake cover +'(0 - 1)' = { + discipline = 1 ; + parameterCategory = 2 ; + parameterNumber = 2 ; + } #Low vegetation cover '(0 - 1)' = { discipline = 2 ; @@ -5416,12 +5422,6 @@ parameterCategory = 0 ; parameterNumber = 12 ; } -#Water fraction -'(0 - 1)' = { - discipline = 1 ; - parameterCategory = 2 ; - parameterNumber = 2 ; - } #Days since last observation 'Integer' = { discipline = 0 ; diff --git a/fortran/eccodes_f90_tail.f90 b/fortran/eccodes_f90_tail.f90 index fcc0c860b..05d59beb5 100644 --- a/fortran/eccodes_f90_tail.f90 +++ b/fortran/eccodes_f90_tail.f90 @@ -2765,6 +2765,12 @@ call grib_skip_read_only(iterid, status) end subroutine codes_skip_read_only + !> Set debug mode + subroutine codes_set_debug(mode) + integer(kind=kindOfInt), intent(in) :: mode + call grib_set_debug(mode) + end subroutine codes_set_debug + !> Set the definition path !> !> In case of error, if the status parameter (optional) is not given, the program will diff --git a/fortran/grib_api_externals.h b/fortran/grib_api_externals.h index f789fb92e..fd3d6c10a 100644 --- a/fortran/grib_api_externals.h +++ b/fortran/grib_api_externals.h @@ -79,7 +79,7 @@ integer, external :: grib_f_set_int, grib_f_set_int_array, & integer, external :: grib_f_get_message_size, grib_f_copy_message, grib_f_count_in_file integer, external :: grib_f_write, grib_f_multi_write, grib_f_multi_append integer, external :: grib_f_clone, grib_f_copy_namespace -external :: grib_f_check +external :: grib_f_check , grib_f_set_debug integer, external :: grib_f_util_sections_copy integer, external :: grib_f_set_definitions_path, grib_f_set_samples_path integer, external :: grib_f_julian_to_datetime, grib_f_datetime_to_julian, grib_f_copy_key diff --git a/fortran/grib_f90_tail.f90 b/fortran/grib_f90_tail.f90 index c178eedbe..be1a574ff 100644 --- a/fortran/grib_f90_tail.f90 +++ b/fortran/grib_f90_tail.f90 @@ -3177,6 +3177,13 @@ end if end subroutine grib_skip_read_only + !> Set debug mode + subroutine grib_set_debug(mode) + integer(kind=kindOfInt), intent(in) :: mode + call grib_f_set_debug(mode) + end subroutine grib_set_debug + + !> Set the definition path !> !> In case of error, if the status parameter (optional) is not given, the program will diff --git a/fortran/grib_fortran.cc b/fortran/grib_fortran.cc index 972118384..1539bc9db 100644 --- a/fortran/grib_fortran.cc +++ b/fortran/grib_fortran.cc @@ -975,8 +975,9 @@ int grib_f_close_file_(int* fid) /*****************************************************************************/ static int file_count=0; -void grib_f_write_on_fail(int* gid) { - grib_context* c=grib_context_get_default(); +void grib_f_write_on_fail(int* gid) +{ + grib_context* c = grib_context_get_default(); if (c->write_on_fail) { char filename[100]={0,}; grib_handle* h=NULL; @@ -993,7 +994,8 @@ void grib_f_write_on_fail(int* gid) { if (h) grib_write_message(h,filename,"w"); } } -void grib_f_write_on_fail_(int* gid) { +void grib_f_write_on_fail_(int* gid) +{ grib_f_write_on_fail(gid); } /*****************************************************************************/ @@ -2890,6 +2892,13 @@ int codes_f_bufr_multi_element_constant_arrays_off_(void) return GRIB_SUCCESS; } +/*****************************************************************************/ +void grib_f_set_debug_(int mode) +{ + grib_context* c = grib_context_get_default(); + grib_context_set_debug(c, mode); +} + /*****************************************************************************/ int grib_f_set_definitions_path_(char* path, int len) { diff --git a/fortran/grib_fortran_prototypes.h b/fortran/grib_fortran_prototypes.h index 4eb0a313d..7af6b2101 100644 --- a/fortran/grib_fortran_prototypes.h +++ b/fortran/grib_fortran_prototypes.h @@ -309,6 +309,7 @@ int grib_f_multi_append__(int *ingid, int *sec, int *mgid); int codes_f_bufr_keys_iterator_new_(int* gid,int* iterid); int grib_f_read_file_(int* fid, void* buffer, size_t* nbytes); int codes_f_bufr_keys_iterator_delete_(int* iterid); +void grib_f_set_debug_(int mode); int grib_f_set_definitions_path_(char* path, int len); int grib_f_read_any_from_file_(int* fid, void* buffer, size_t* nbytes); int any_f_new_from_file_(int* fid, int* gid); diff --git a/src/accessor/grib_accessor.cc b/src/accessor/grib_accessor.cc index 23c52c888..f722e333c 100644 --- a/src/accessor/grib_accessor.cc +++ b/src/accessor/grib_accessor.cc @@ -30,14 +30,13 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) int grib_accessor::compare_accessors(grib_accessor* a2, int compare_flags) { - int ret = 0; - long type1 = 0; - long type2 = 0; - int type_mismatch = 0; - grib_accessor_class* c1 = NULL; - grib_accessor* a1 = this; + int ret = 0; + long type1 = 0; + long type2 = 0; + int type_mismatch = 0; + grib_accessor* a1 = this; - if ((compare_flags & GRIB_COMPARE_NAMES) && grib_inline_strcmp(a1->name, a2->name)) + if ((compare_flags & GRIB_COMPARE_NAMES) && grib_inline_strcmp(a1->name_, a2->name_)) return GRIB_NAME_MISMATCH; if (compare_flags & GRIB_COMPARE_TYPES) { @@ -48,8 +47,7 @@ int grib_accessor::compare_accessors(grib_accessor* a2, int compare_flags) } // ret = GRIB_UNABLE_TO_COMPARE_ACCESSORS; - c1 = a1->cclass; - ret = c1->compare(a1, a2); + ret = compare(a2); if (ret == GRIB_VALUE_MISMATCH && type_mismatch) ret = GRIB_TYPE_AND_VALUE_MISMATCH; @@ -59,13 +57,13 @@ int grib_accessor::compare_accessors(grib_accessor* a2, int compare_flags) int grib_accessor::add_attribute(grib_accessor* attr, int nest_if_clash) { - int id = 0; - int idx = 0; + int id = 0; + int idx = 0; grib_accessor* pSame = NULL; grib_accessor* pAloc = this; if (this->has_attributes()) { - pSame = this->get_attribute_index(attr->name, &id); + pSame = this->get_attribute_index(attr->name_, &id); } if (pSame) { @@ -75,27 +73,27 @@ int grib_accessor::add_attribute(grib_accessor* attr, int nest_if_clash) } for (id = 0; id < MAX_ACCESSOR_ATTRIBUTES; id++) { - if (pAloc->attributes[id] == NULL) { + if (pAloc->attributes_[id] == NULL) { // attr->parent=a->parent; - pAloc->attributes[id] = attr; - attr->parent_as_attribute = pAloc; - if (pAloc->same) - attr->same = pAloc->same->get_attribute_index(attr->name, &idx); + pAloc->attributes_[id] = attr; + attr->parent_as_attribute_ = pAloc; + if (pAloc->same_) + attr->same_ = pAloc->same_->get_attribute_index(attr->name_, &idx); - grib_context_log(this->context, GRIB_LOG_DEBUG, "added attribute %s->%s", this->name, attr->name); + grib_context_log(this->context_, GRIB_LOG_DEBUG, "added attribute %s->%s", this->name_, attr->name_); return GRIB_SUCCESS; } } return GRIB_TOO_MANY_ATTRIBUTES; } -grib_accessor* grib_accessor::get_attribute_index(const char* name, int* index) +grib_accessor* grib_accessor::get_attribute_index(const char* name_, int* index) { int i = 0; - while (i < MAX_ACCESSOR_ATTRIBUTES && this->attributes[i]) { - if (!grib_inline_strcmp(this->attributes[i]->name, name)) { + while (i < MAX_ACCESSOR_ATTRIBUTES && this->attributes_[i]) { + if (!grib_inline_strcmp(this->attributes_[i]->name_, name_)) { *index = i; - return this->attributes[i]; + return this->attributes_[i]; } i++; } @@ -104,29 +102,29 @@ grib_accessor* grib_accessor::get_attribute_index(const char* name, int* index) int grib_accessor::has_attributes() { - return this->attributes[0] ? 1 : 0; + return this->attributes_[0] ? 1 : 0; } -grib_accessor* grib_accessor::get_attribute(const char* name) +grib_accessor* grib_accessor::get_attribute(const char* name_) { int index = 0; const char* p = 0; char* basename = NULL; const char* attribute_name = NULL; grib_accessor* acc = NULL; - p = name; + p = name_; while (*(p + 1) != '\0' && (*p != '-' || *(p + 1) != '>')) p++; if (*(p + 1) == '\0') { - return this->get_attribute_index(name, &index); + return this->get_attribute_index(name_, &index); } else { - size_t size = p - name; + size_t size = p - name_; attribute_name = p + 2; - basename = (char*)grib_context_malloc_clear(this->context, size + 1); - basename = (char*)memcpy(basename, name, size); + basename = (char*)grib_context_malloc_clear(this->context_, size + 1); + basename = (char*)memcpy(basename, name_, size); acc = this->get_attribute_index(basename, &index); - grib_context_free(this->context, basename); + grib_context_free(this->context_, basename); if (acc) return acc->get_attribute(attribute_name); else diff --git a/src/accessor/grib_accessor.h b/src/accessor/grib_accessor.h index 7fe8aad19..811f8fd9b 100644 --- a/src/accessor/grib_accessor.h +++ b/src/accessor/grib_accessor.h @@ -16,132 +16,99 @@ class grib_accessor { public: - grib_accessor() : - name(nullptr), name_space(nullptr), context(nullptr), h(nullptr), creator(nullptr), - length(0), offset(0), parent(nullptr), next_(nullptr), previous_(nullptr), cclass(nullptr), - flags(0), sub_section(nullptr), dirty(0), same(nullptr), loop(0), vvalue(nullptr), - set(nullptr), parent_as_attribute(nullptr) {} + grib_accessor() : + context_(nullptr), name_(nullptr), class_name_(nullptr), name_space_(nullptr), h_(nullptr), creator_(nullptr), length_(0), offset_(0), parent_(nullptr), next_(nullptr), previous_(nullptr), flags_(0), sub_section_(nullptr), dirty_(0), same_(nullptr), loop_(0), vvalue_(nullptr), set_(nullptr), parent_as_attribute_(nullptr) {} + + grib_accessor(const char* name) : + context_(nullptr), name_(name), class_name_(nullptr), name_space_(nullptr), h_(nullptr), creator_(nullptr), length_(0), offset_(0), parent_(nullptr), next_(nullptr), previous_(nullptr), flags_(0), sub_section_(nullptr), dirty_(0), same_(nullptr), loop_(0), vvalue_(nullptr), set_(nullptr), parent_as_attribute_(nullptr) {} + virtual ~grib_accessor() {} virtual void init_accessor(const long, grib_arguments*) = 0; - virtual void dump(grib_dumper* f) = 0; - virtual int pack_missing() = 0; - //virtual int grib_pack_zero(grib_accessor* a) = 0; - virtual int is_missing_internal() = 0; - virtual int pack_double(const double* v, size_t* len) = 0; - virtual int pack_float(const float* v, size_t* len) = 0; - virtual int pack_expression(grib_expression* e) = 0; - virtual int pack_string(const char* v, size_t* len) = 0; - virtual int pack_string_array(const char** v, size_t* len) = 0; - virtual int pack_long(const long* v, size_t* len) = 0; - virtual int pack_bytes(const unsigned char* v, size_t* len) = 0; - virtual int unpack_bytes(unsigned char* v, size_t* len) = 0; - virtual int unpack_double_subarray(double* v, size_t start, size_t len) = 0; - virtual int unpack_double(double* v, size_t* len) = 0; - virtual int unpack_float(float* v, size_t* len) = 0; - virtual int unpack_double_element(size_t i, double* v) = 0; - virtual int unpack_float_element(size_t i, float* v) = 0; + virtual void dump(grib_dumper* f) = 0; + virtual int pack_missing() = 0; + // virtual int grib_pack_zero(grib_accessor* a) = 0; + virtual int is_missing_internal() = 0; + virtual int pack_double(const double* v, size_t* len) = 0; + virtual int pack_float(const float* v, size_t* len) = 0; + virtual int pack_expression(grib_expression* e) = 0; + virtual int pack_string(const char* v, size_t* len) = 0; + virtual int pack_string_array(const char** v, size_t* len) = 0; + virtual int pack_long(const long* v, size_t* len) = 0; + virtual int pack_bytes(const unsigned char* v, size_t* len) = 0; + virtual int unpack_bytes(unsigned char* v, size_t* len) = 0; + virtual int unpack_double_subarray(double* v, size_t start, size_t len) = 0; + virtual int unpack_double(double* v, size_t* len) = 0; + virtual int unpack_float(float* v, size_t* len) = 0; + virtual int unpack_double_element(size_t i, double* v) = 0; + virtual int unpack_float_element(size_t i, float* v) = 0; virtual int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) = 0; - virtual int unpack_float_element_set(const size_t* index_array, size_t len, float* val_array) = 0; - virtual int unpack_string(char* v, size_t* len) = 0; - virtual int unpack_string_array(char** v, size_t* len) = 0; - virtual int unpack_long(long* v, size_t* len) = 0; - virtual long get_native_type() = 0; - virtual long get_next_position_offset() = 0; - virtual long string_length() = 0; - virtual long byte_offset() = 0; - virtual long byte_count() = 0; - virtual int value_count(long* count) = 0; - virtual int notify_change(grib_accessor* changed) = 0; - virtual grib_accessor* clone(grib_section* s, int* err) = 0; - virtual void update_size(size_t len) = 0; - virtual int nearest_smaller_value(double val, double* nearest) = 0; - virtual size_t preferred_size(int from_handle) = 0; - virtual grib_accessor* next_accessor() = 0; - virtual void resize(size_t new_size) = 0; - virtual void destroy(grib_context* ct) = 0; + virtual int unpack_float_element_set(const size_t* index_array, size_t len, float* val_array) = 0; + virtual int unpack_string(char* v, size_t* len) = 0; + virtual int unpack_string_array(char** v, size_t* len) = 0; + virtual int unpack_long(long* v, size_t* len) = 0; + virtual long get_native_type() = 0; + virtual long get_next_position_offset() = 0; + virtual size_t string_length() = 0; + virtual long byte_offset() = 0; + virtual long byte_count() = 0; + virtual int value_count(long* count) = 0; + virtual int notify_change(grib_accessor* changed) = 0; + virtual grib_accessor* clone(grib_section* s, int* err) = 0; + virtual void update_size(size_t len) = 0; + virtual int nearest_smaller_value(double val, double* nearest) = 0; + virtual size_t preferred_size(int from_handle) = 0; + virtual grib_accessor* next_accessor() = 0; + virtual void resize(size_t new_size) = 0; + virtual void destroy(grib_context* ct) = 0; virtual int compare_accessors(grib_accessor* a2, int compare_flags); + virtual int compare(grib_accessor*) = 0; virtual int add_attribute(grib_accessor* attr, int nest_if_clash); virtual grib_accessor* get_attribute_index(const char* name, int* index); virtual int has_attributes(); virtual grib_accessor* get_attribute(const char* name); + virtual void init(const long, grib_arguments*) = 0; + virtual void post_init() = 0; + virtual grib_section* sub_section() = 0; + virtual grib_accessor* create_empty_accessor() = 0; + virtual int is_missing() = 0; + virtual long next_offset() = 0; + virtual grib_accessor* next(grib_accessor*, int) = 0; + virtual int clear() = 0; + virtual grib_accessor* make_clone(grib_section*, int*) = 0; - - const char* name; /** < name of the accessor */ - const char* name_space; /** < namespace to which the accessor belongs */ - grib_context* context; - grib_handle* h; - grib_action* creator; /** < action that created the accessor */ - long length; /** < byte length of the accessor */ - long offset; /** < offset of the data in the buffer */ - grib_section* parent; /** < section to which the accessor is attached */ - grib_accessor* next_; /** < next accessor in list */ - grib_accessor* previous_; /** < next accessor in list */ - grib_accessor_class* cclass; /** < behaviour of the accessor */ - unsigned long flags; /** < Various flags */ - grib_section* sub_section; - - const char* all_names[MAX_ACCESSOR_NAMES]= {0,}; /** < name of the accessor */ - const char* all_name_spaces[MAX_ACCESSOR_NAMES] = {0,}; /** < namespace to which the accessor belongs */ - int dirty; - - grib_accessor* same; /** < accessors with the same name */ - long loop; /** < used in lists */ - grib_virtual_value* vvalue; /** < virtual value used when transient flag on **/ - const char* set; - grib_accessor* attributes[MAX_ACCESSOR_ATTRIBUTES] = {0,}; /** < attributes are accessors */ - grib_accessor* parent_as_attribute; -}; - - -class grib_accessor_class -{ public: - const char* name; + // private: + // TODO(maee): make members private + grib_context* context_; + const char* name_; /** < name of the accessor */ + const char* class_name_; /** < name of the class (Artifact from C version of ecCodes) */ + const char* name_space_; /** < namespace to which the accessor belongs */ + grib_handle* h_; + grib_action* creator_; /** < action that created the accessor */ + long length_; /** < byte length of the accessor */ + long offset_; /** < offset of the data in the buffer */ + grib_section* parent_; /** < section to which the accessor is attached */ + grib_accessor* next_; /** < next accessor in list */ + grib_accessor* previous_; /** < next accessor in list */ + unsigned long flags_; /** < Various flags */ + grib_section* sub_section_; - grib_accessor_class(const char* name) : name(name){} - virtual ~grib_accessor_class(){} + const char* all_names_[MAX_ACCESSOR_NAMES] = { + 0, + }; /** < name of the accessor */ + const char* all_name_spaces_[MAX_ACCESSOR_NAMES] = { + 0, + }; /** < namespace to which the accessor belongs */ + int dirty_; - virtual grib_accessor* create_empty_accessor() = 0; - virtual grib_section* sub_section(grib_accessor* a) = 0; - virtual int get_native_type(grib_accessor*) = 0; - virtual int pack_missing(grib_accessor*) = 0; - virtual int is_missing(grib_accessor*) = 0; - virtual int pack_bytes(grib_accessor*, const unsigned char*, size_t* len) = 0; - virtual int pack_double(grib_accessor*, const double* val, size_t* len) = 0; - virtual int pack_float(grib_accessor*, const float* val, size_t* len) = 0; - virtual int pack_long(grib_accessor*, const long* val, size_t* len) = 0; - virtual int pack_string(grib_accessor*, const char*, size_t* len) = 0; - virtual int pack_string_array(grib_accessor*, const char**, size_t* len) = 0; - virtual int pack_expression(grib_accessor*, grib_expression*) = 0; - virtual int unpack_bytes(grib_accessor*, unsigned char*, size_t* len) = 0; - virtual int unpack_double(grib_accessor*, double* val, size_t* len) = 0; - virtual int unpack_float(grib_accessor*, float* val, size_t* len) = 0; - virtual int unpack_long(grib_accessor*, long* val, size_t* len) = 0; - virtual int unpack_string(grib_accessor*, char*, size_t* len) = 0; - virtual int unpack_string_array(grib_accessor*, char**, size_t* len) = 0; - virtual size_t string_length(grib_accessor*) = 0; - virtual long byte_count(grib_accessor*) = 0; - virtual long byte_offset(grib_accessor*) = 0; - virtual long next_offset(grib_accessor*) = 0; - virtual int value_count(grib_accessor*, long*) = 0; - virtual void destroy(grib_context*, grib_accessor*) = 0; - virtual void dump(grib_accessor*, grib_dumper*) = 0; - virtual void init(grib_accessor*, const long, grib_arguments*) = 0; - virtual void post_init(grib_accessor*) = 0; - virtual int notify_change(grib_accessor*, grib_accessor*) = 0; - virtual void update_size(grib_accessor*, size_t) = 0; - virtual size_t preferred_size(grib_accessor*, int) = 0; - virtual void resize(grib_accessor*,size_t) = 0; - virtual int nearest_smaller_value (grib_accessor*, double, double*) = 0; - virtual grib_accessor* next(grib_accessor*, int) = 0; - virtual int compare(grib_accessor*, grib_accessor*) = 0; - virtual int unpack_double_element(grib_accessor*, size_t i, double* val) = 0; - virtual int unpack_float_element(grib_accessor*, size_t i, float* val) = 0; - virtual int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) = 0; - virtual int unpack_float_element_set(grib_accessor*, const size_t* index_array, size_t len, float* val_array) = 0; - virtual int unpack_double_subarray(grib_accessor*, double* val, size_t start, size_t len) = 0; - virtual int clear(grib_accessor*) = 0; - virtual grib_accessor* make_clone(grib_accessor*, grib_section*, int*) = 0; + grib_accessor* same_; /** < accessors with the same name */ + long loop_; /** < used in lists */ + grib_virtual_value* vvalue_; /** < virtual value used when transient flag on **/ + const char* set_; + grib_accessor* attributes_[MAX_ACCESSOR_ATTRIBUTES] = { + 0, + }; /** < attributes are accessors */ + grib_accessor* parent_as_attribute_; }; diff --git a/src/accessor/grib_accessor_class_abstract_long_vector.cc b/src/accessor/grib_accessor_class_abstract_long_vector.cc index 0f4514aa1..3df25228b 100644 --- a/src/accessor/grib_accessor_class_abstract_long_vector.cc +++ b/src/accessor/grib_accessor_class_abstract_long_vector.cc @@ -11,5 +11,5 @@ #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; +grib_accessor_abstract_long_vector_t _grib_accessor_abstract_long_vector{}; +grib_accessor* grib_accessor_abstract_long_vector = &_grib_accessor_abstract_long_vector; diff --git a/src/accessor/grib_accessor_class_abstract_long_vector.h b/src/accessor/grib_accessor_class_abstract_long_vector.h index 94ed9d636..bf2786d82 100644 --- a/src/accessor/grib_accessor_class_abstract_long_vector.h +++ b/src/accessor/grib_accessor_class_abstract_long_vector.h @@ -16,15 +16,12 @@ 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_abstract_long_vector_t() : + grib_accessor_gen_t() { class_name_ = "abstract_long_vector"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_abstract_long_vector_t{}; } + +public: + long* v_; + long pack_index_; + int number_of_elements_; }; diff --git a/src/accessor/grib_accessor_class_abstract_vector.cc b/src/accessor/grib_accessor_class_abstract_vector.cc index 2ee141e8f..022586dfd 100644 --- a/src/accessor/grib_accessor_class_abstract_vector.cc +++ b/src/accessor/grib_accessor_class_abstract_vector.cc @@ -11,5 +11,5 @@ #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; +grib_accessor_abstract_vector_t _grib_accessor_abstract_vector{}; +grib_accessor* grib_accessor_abstract_vector = &_grib_accessor_abstract_vector; diff --git a/src/accessor/grib_accessor_class_abstract_vector.h b/src/accessor/grib_accessor_class_abstract_vector.h index b721a3adb..7d0f6a31e 100644 --- a/src/accessor/grib_accessor_class_abstract_vector.h +++ b/src/accessor/grib_accessor_class_abstract_vector.h @@ -16,14 +16,11 @@ 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_abstract_vector_t() : + grib_accessor_double_t() { class_name_ = "abstract_vector"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_abstract_vector_t{}; } + +public: + double* v_; + int number_of_elements_; }; diff --git a/src/accessor/grib_accessor_class_ascii.cc b/src/accessor/grib_accessor_class_ascii.cc index b3e9f6a8a..963da2fd0 100644 --- a/src/accessor/grib_accessor_class_ascii.cc +++ b/src/accessor/grib_accessor_class_ascii.cc @@ -11,101 +11,101 @@ #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; +grib_accessor_ascii_t _grib_accessor_ascii{}; +grib_accessor* grib_accessor_ascii = &_grib_accessor_ascii; - -void grib_accessor_class_ascii_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_ascii_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - a->length = len; - Assert(a->length >= 0); + grib_accessor_gen_t::init(len, arg); + length_ = len; + Assert(length_ >= 0); } -int grib_accessor_class_ascii_t::value_count(grib_accessor* a, long* count) +int grib_accessor_ascii_t::value_count(long* count) { *count = 1; return 0; } -size_t grib_accessor_class_ascii_t::string_length(grib_accessor* a) +size_t grib_accessor_ascii_t::string_length() { - return a->length; + return length_; } -void grib_accessor_class_ascii_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_ascii_t::dump(grib_dumper* dumper) { - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); } -int grib_accessor_class_ascii_t::get_native_type(grib_accessor* a) +long grib_accessor_ascii_t::get_native_type() { return GRIB_TYPE_STRING; } -int grib_accessor_class_ascii_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_ascii_t::unpack_string(char* val, size_t* len) { - grib_handle* hand = grib_handle_of_accessor(a); - const size_t alen = a->length; + grib_handle* hand = grib_handle_of_accessor(this); + const size_t alen = length_; if (*len < (alen + 1)) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, alen + 1, *len); + class_name_, name_, alen + 1, *len); *len = alen + 1; return GRIB_BUFFER_TOO_SMALL; } size_t i = 0; for (i = 0; i < alen; i++) - val[i] = hand->buffer->data[a->offset + i]; + val[i] = hand->buffer->data[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) +int grib_accessor_ascii_t::pack_string(const char* val, size_t* len) { - grib_handle* hand = grib_handle_of_accessor(a); - const size_t alen = a->length; + grib_handle* hand = grib_handle_of_accessor(this); + const size_t alen = length_; if (len[0] > (alen + 1)) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "pack_string: Wrong size (%zu) for %s, it contains %ld values", - len[0], a->name, a->length + 1); + len[0], name_, length_ + 1); len[0] = 0; return GRIB_BUFFER_TOO_SMALL; } for (size_t i = 0; i < alen; i++) { if (i < len[0]) - hand->buffer->data[a->offset + i] = val[i]; + hand->buffer->data[offset_ + i] = val[i]; else - hand->buffer->data[a->offset + i] = 0; + hand->buffer->data[offset_ + i] = 0; } return GRIB_SUCCESS; } -int grib_accessor_class_ascii_t::pack_long(grib_accessor* a, const long* v, size_t* len) +int grib_accessor_ascii_t::pack_long(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); + grib_context_log(this->context_, GRIB_LOG_ERROR, "Should not pack %s as long (It's a string)", name_); return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_ascii_t::pack_double(grib_accessor* a, const double* v, size_t* len) +int grib_accessor_ascii_t::pack_double(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); + grib_context_log(this->context_, GRIB_LOG_ERROR, "Should not pack %s as double (It's a string)", name_); return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_ascii_t::unpack_long(grib_accessor* a, long* v, size_t* len) +int grib_accessor_ascii_t::unpack_long(long* v, size_t* len) { - char val[1024] = {0,}; + char val[1024] = { + 0, + }; size_t l = sizeof(val); size_t i = 0; char* last = NULL; - int err = a->unpack_string(val, &l); + int err = unpack_string(val, &l); if (err) return err; @@ -122,48 +122,48 @@ int grib_accessor_class_ascii_t::unpack_long(grib_accessor* a, long* v, size_t* *v = strtol(val, &last, 10); - grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name); + grib_context_log(this->context_, GRIB_LOG_DEBUG, " Casting string %s to long", name_); return GRIB_SUCCESS; } -int grib_accessor_class_ascii_t::unpack_double(grib_accessor* a, double* v, size_t* len) +int grib_accessor_ascii_t::unpack_double(double* v, size_t* len) { char val[1024]; size_t l = sizeof(val); char* last = NULL; - int err = a->unpack_string(val, &l); + int err = 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); + grib_context_log(this->context_, GRIB_LOG_DEBUG, " Casting string %s to long", name_); return GRIB_SUCCESS; } - grib_context_log(a->context, GRIB_LOG_WARNING, "Cannot unpack %s as double. Hint: Try unpacking as string", a->name); + grib_context_log(this->context_, GRIB_LOG_WARNING, "Cannot unpack %s as double. Hint: Try unpacking as string", name_); return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_ascii_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_ascii_t::compare(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; + size_t alen = 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)); + aval = (char*)grib_context_malloc(context_, alen * sizeof(char)); + bval = (char*)grib_context_malloc(b->context_, blen * sizeof(char)); - err = a->unpack_string(aval, &alen); + err = unpack_string(aval, &alen); if (err) return err; err = b->unpack_string(bval, &blen); if (err) return err; @@ -172,8 +172,8 @@ int grib_accessor_class_ascii_t::compare(grib_accessor* a, grib_accessor* b) if (!STR_EQUAL(aval, bval)) retval = GRIB_STRING_VALUE_MISMATCH; - grib_context_free(a->context, aval); - grib_context_free(b->context, bval); + grib_context_free(context_, aval); + grib_context_free(b->context_, bval); return retval; } diff --git a/src/accessor/grib_accessor_class_ascii.h b/src/accessor/grib_accessor_class_ascii.h index 8bef5eaac..05e5a85dd 100644 --- a/src/accessor/grib_accessor_class_ascii.h +++ b/src/accessor/grib_accessor_class_ascii.h @@ -16,24 +16,19 @@ 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_ascii_t() : + grib_accessor_gen_t() { class_name_ = "ascii"; } 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; + long get_native_type() override; + int pack_double(const double* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + int pack_string(const char*, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + int value_count(long*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + int compare(grib_accessor*) override; }; diff --git a/src/accessor/grib_accessor_class_bit.cc b/src/accessor/grib_accessor_class_bit.cc index c1efac202..19477253e 100644 --- a/src/accessor/grib_accessor_class_bit.cc +++ b/src/accessor/grib_accessor_class_bit.cc @@ -11,37 +11,34 @@ #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; +grib_accessor_bit_t _grib_accessor_bit{}; +grib_accessor* grib_accessor_bit = &_grib_accessor_bit; - -void grib_accessor_class_bit_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_bit_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_long_t::init(a, len, 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); + grib_accessor_long_t::init(len, arg); + length_ = 0; + owner_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, 0); + bit_index_ = grib_arguments_get_long(grib_handle_of_accessor(this), arg, 1); } -int grib_accessor_class_bit_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_bit_t::unpack_long(long* val, size_t* len) { - grib_accessor_bit_t* self = (grib_accessor_bit_t*)a; - int ret = 0; - long data = 0; + 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); + grib_context_log(context_, GRIB_LOG_ERROR, "grib_accessor_bit_t: unpack_long: Wrong size for %s, it contains %d values ", 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) { + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), owner_, &data)) != GRIB_SUCCESS) { *len = 0; return ret; } - if (data & (1 << self->bit_index)) + if (data & (1 << bit_index_)) *val = 1; else *val = 0; @@ -50,32 +47,30 @@ int grib_accessor_class_bit_t::unpack_long(grib_accessor* a, long* val, size_t* return GRIB_SUCCESS; } -int grib_accessor_class_bit_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_bit_t::pack_long(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); + grib_context_log(context_, GRIB_LOG_ERROR, "grib_accessor_bit_t: pack_long: At least one value to pack for %s", name_); *len = 1; return GRIB_ARRAY_TOO_SMALL; } - grib_accessor* owner = grib_find_accessor(grib_handle_of_accessor(a), self->owner); + grib_accessor* owner = grib_find_accessor(grib_handle_of_accessor(this), 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); + grib_context_log(context_, GRIB_LOG_ERROR, "grib_accessor_bit_t: Cannot get the owner %s for computing the bit value of %s", + owner_, name_); *len = 0; return GRIB_NOT_FOUND; } - unsigned char* mdata = grib_handle_of_accessor(a)->buffer->data; + unsigned char* mdata = grib_handle_of_accessor(this)->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) { + if (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)); + fprintf(stderr, "ECCODES DEBUG Setting bit %d in %s to %d\n", 8 - bit_index_, owner->name_, (*val > 0)); } - grib_set_bit(mdata, 7 - self->bit_index, *val > 0); + grib_set_bit(mdata, 7 - bit_index_, *val > 0); *len = 1; return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_bit.h b/src/accessor/grib_accessor_class_bit.h index 188d5e370..1f818b398 100644 --- a/src/accessor/grib_accessor_class_bit.h +++ b/src/accessor/grib_accessor_class_bit.h @@ -16,17 +16,14 @@ 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_bit_t() : + grib_accessor_long_t() { class_name_ = "bit"; } 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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* owner_; + int bit_index_; }; diff --git a/src/accessor/grib_accessor_class_bitmap.cc b/src/accessor/grib_accessor_class_bitmap.cc index 05d9db3bf..b4327c720 100644 --- a/src/accessor/grib_accessor_class_bitmap.cc +++ b/src/accessor/grib_accessor_class_bitmap.cc @@ -11,18 +11,18 @@ #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; +grib_accessor_bitmap_t _grib_accessor_bitmap{}; +grib_accessor* grib_accessor_bitmap = &_grib_accessor_bitmap; static 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); + long slen = 0; + long off = 0; + grib_handle* hand = grib_handle_of_accessor(a); + + grib_get_long_internal(hand, self->offsetbsec_, &off); + grib_get_long_internal(hand, self->sLength_, &slen); if (slen == 0) { grib_accessor* seclen; @@ -30,68 +30,67 @@ static void compute_size(grib_accessor* a) /* Assume reparsing */ Assert(hand->loader != 0); if (hand->loader != 0) { - seclen = grib_find_accessor(hand, self->sLength); + seclen = grib_find_accessor(hand, self->sLength_); Assert(seclen); - grib_get_block_length(seclen->parent, &size); + 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); + // printf("compute_size off=%ld slen=%ld a->offset_=%ld\n", (long)off,(long)slen,(long)offset_ ); - a->length = off + (slen - a->offset); + a->length_ = off + (slen - a->offset_); - if (a->length < 0) { + if (a->length_ < 0) { /* Assume reparsing */ /*Assert(hand->loader != 0);*/ - a->length = 0; + a->length_ = 0; } - Assert(a->length >= 0); + Assert(a->length_ >= 0); } -void grib_accessor_class_bitmap_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_bitmap_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_bytes_t::init(a, len, arg); - grib_accessor_bitmap_t* self = (grib_accessor_bitmap_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_bytes_t::init(len, arg); + grib_handle* hand = grib_handle_of_accessor(this); + 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++); + tableReference_ = grib_arguments_get_name(hand, arg, n++); + missing_value_ = grib_arguments_get_name(hand, arg, n++); + offsetbsec_ = grib_arguments_get_name(hand, arg, n++); + sLength_ = grib_arguments_get_name(hand, arg, n++); - compute_size(a); + compute_size(this); } -long grib_accessor_class_bitmap_t::next_offset(grib_accessor* a) +long grib_accessor_bitmap_t::next_offset() { - return a->byte_offset() + a->byte_count(); + return byte_offset() + byte_count(); } -void grib_accessor_class_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_bitmap_t::dump(grib_dumper* dumper) { long len = 0; char label[1024]; - a->value_count(&len); + value_count(&len); snprintf(label, sizeof(label), "Bitmap of %ld values", len); - grib_dump_bytes(dumper, a, label); + grib_dump_bytes(dumper, this, label); } -int grib_accessor_class_bitmap_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_bitmap_t::unpack_long(long* val, size_t* len) { - long pos = a->offset * 8; - long tlen = 0; - const grib_handle* hand = grib_handle_of_accessor(a); + long pos = offset_ * 8; + long tlen = 0; + const grib_handle* hand = grib_handle_of_accessor(this); - int err = a->value_count(&tlen); + int err = 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); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", name_, tlen); *len = tlen; return GRIB_ARRAY_TOO_SMALL; } @@ -107,7 +106,7 @@ template static int unpack(grib_accessor* a, T* val, size_t* len) { static_assert(std::is_floating_point::value, "Requires floating points numbers"); - long pos = a->offset * 8; + long pos = a->offset_ * 8; long tlen; grib_handle* hand = grib_handle_of_accessor(a); @@ -116,7 +115,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return err; if (*len < tlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", a->name, 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; } @@ -128,62 +127,61 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_SUCCESS; } -int grib_accessor_class_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_bitmap_t::unpack_double(double* val, size_t* len) { - return unpack(a, val, len); + return unpack(this, val, len); } -int grib_accessor_class_bitmap_t::unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_bitmap_t::unpack_float(float* val, size_t* len) { - return unpack(a, val, len); + return unpack(this, val, len); } -int grib_accessor_class_bitmap_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_bitmap_t::unpack_double_element(size_t idx, double* val) { - long pos = a->offset * 8; + long pos = offset_ * 8; pos += idx; - *val = (double)grib_decode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, &pos, 1); + *val = (double)grib_decode_unsigned_long(grib_handle_of_accessor(this)->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) +int grib_accessor_bitmap_t::unpack_double_element_set(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); + unpack_double_element(index_array[i], val_array + i); } return GRIB_SUCCESS; } -void grib_accessor_class_bitmap_t::update_size(grib_accessor* a, size_t s) +void grib_accessor_bitmap_t::update_size(size_t s) { - a->length = s; + length_ = s; } -size_t grib_accessor_class_bitmap_t::string_length(grib_accessor* a) +size_t grib_accessor_bitmap_t::string_length() { - return a->length; + return length_; } -int grib_accessor_class_bitmap_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_bitmap_t::unpack_string(char* val, size_t* len) { - grib_handle* hand = grib_handle_of_accessor(a); - const size_t l = a->length; + grib_handle* hand = grib_handle_of_accessor(this); + const size_t l = length_; if (*len < l) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, l, *len); + class_name_, 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]; + for (long i = 0; i < length_; i++) { + val[i] = hand->buffer->data[offset_ + i]; } - *len = a->length; + *len = length_; return GRIB_SUCCESS; } diff --git a/src/accessor/grib_accessor_class_bitmap.h b/src/accessor/grib_accessor_class_bitmap.h index 4f07f3a6c..06153ab50 100644 --- a/src/accessor/grib_accessor_class_bitmap.h +++ b/src/accessor/grib_accessor_class_bitmap.h @@ -16,27 +16,24 @@ 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_bitmap_t() : + grib_accessor_bytes_t() { class_name_ = "bitmap"; } 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; + int unpack_double(double* val, size_t* len) override; + int unpack_float(float* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + long next_offset() override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + void update_size(size_t) override; + int unpack_double_element(size_t i, double* val) override; + int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; + // TODO(maee): make members private +public: + const char* tableReference_; + const char* missing_value_; + const char* offsetbsec_; + const char* sLength_; }; diff --git a/src/accessor/grib_accessor_class_bits.cc b/src/accessor/grib_accessor_class_bits.cc index 3e7826bfe..e3b35c37f 100644 --- a/src/accessor/grib_accessor_class_bits.cc +++ b/src/accessor/grib_accessor_class_bits.cc @@ -11,55 +11,52 @@ #include "grib_accessor_class_bits.h" -grib_accessor_class_bits_t _grib_accessor_class_bits{ "bits" }; -grib_accessor_class* grib_accessor_class_bits = &_grib_accessor_class_bits; +grib_accessor_bits_t _grib_accessor_bits{}; +grib_accessor* grib_accessor_bits = &_grib_accessor_bits; - -void grib_accessor_class_bits_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_bits_t::init(const long l, grib_arguments* c) { - grib_accessor_class_gen_t::init(a, l, 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; + grib_accessor_gen_t::init(l, c); + grib_handle* hand = grib_handle_of_accessor(this); + grib_expression* e = NULL; + int n = 0; - self->argument = grib_arguments_get_name(hand, c, n++); - self->start = grib_arguments_get_long(hand, c, n++); - self->len = grib_arguments_get_long(hand, c, n++); - e = grib_arguments_get_expression(hand, c, n++); + argument_ = grib_arguments_get_name(hand, c, n++); + start_ = grib_arguments_get_long(hand, c, n++); + len_ = grib_arguments_get_long(hand, c, n++); + e = grib_arguments_get_expression(hand, c, n++); if (e) { - grib_expression_evaluate_double(hand, e, &(self->referenceValue)); - self->referenceValuePresent = 1; + grib_expression_evaluate_double(hand, e, &(referenceValue_)); + referenceValuePresent_ = 1; } else { - self->referenceValuePresent = 0; + referenceValuePresent_ = 0; } - self->scale = 1; - if (self->referenceValuePresent) { - self->scale = grib_arguments_get_double(hand, c, n++); + scale_ = 1; + if (referenceValuePresent_) { + scale_ = grib_arguments_get_double(hand, c, n++); } - Assert(self->len <= sizeof(long) * 8); + Assert(len_ <= sizeof(long) * 8); - a->length = 0; + length_ = 0; } -int grib_accessor_class_bits_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_bits_t::unpack_long(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); + grib_accessor* x = NULL; + unsigned char* p = NULL; + grib_handle* h = grib_handle_of_accessor(this); long start, length; int ret = 0; if (*len < 1) return GRIB_WRONG_ARRAY_SIZE; - start = self->start; - length = self->len; + start = start_; + length = len_; - x = grib_find_accessor(grib_handle_of_accessor(a), self->argument); + x = grib_find_accessor(grib_handle_of_accessor(this), argument_); if (!x) return GRIB_NOT_FOUND; @@ -71,96 +68,93 @@ int grib_accessor_class_bits_t::unpack_long(grib_accessor* a, long* val, size_t* return ret; } -int grib_accessor_class_bits_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_bits_t::unpack_double(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); + grib_accessor* x = NULL; + unsigned char* p = NULL; + grib_handle* h = grib_handle_of_accessor(this); long start, length; int ret = 0; if (*len < 1) return GRIB_WRONG_ARRAY_SIZE; - start = self->start; - length = self->len; + start = start_; + length = len_; - x = grib_find_accessor(grib_handle_of_accessor(a), self->argument); + x = grib_find_accessor(grib_handle_of_accessor(this), argument_); if (!x) return GRIB_NOT_FOUND; p = h->buffer->data + x->byte_offset(); *val = grib_decode_unsigned_long(p, &start, length); - *val = ((long)*val + self->referenceValue) / self->scale; + *val = ((long)*val + referenceValue_) / scale_; *len = 1; return ret; } -int grib_accessor_class_bits_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_bits_t::pack_double(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; + grib_accessor* x = NULL; + grib_handle* h = grib_handle_of_accessor(this); + unsigned char* p = NULL; long start, length, lval; if (*len != 1) return GRIB_WRONG_ARRAY_SIZE; - start = self->start; - length = self->len; + start = start_; + length = len_; - x = grib_find_accessor(grib_handle_of_accessor(a), self->argument); + x = grib_find_accessor(grib_handle_of_accessor(this), argument_); if (!x) return GRIB_NOT_FOUND; p = h->buffer->data + x->byte_offset(); - lval = round(*val * self->scale) - self->referenceValue; + lval = round(*val * scale_) - referenceValue_; return grib_encode_unsigned_longb(p, lval, &start, length); } -int grib_accessor_class_bits_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_bits_t::pack_long(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; + grib_accessor* x = NULL; + grib_handle* h = grib_handle_of_accessor(this); + unsigned char* p = NULL; long start, length, maxval; if (*len != 1) return GRIB_WRONG_ARRAY_SIZE; - if (get_native_type(a) == GRIB_TYPE_DOUBLE) { + if (get_native_type() == GRIB_TYPE_DOUBLE) { /* ECC-402 */ const double dVal = (double)(*val); - return pack_double(a, &dVal, len); + return pack_double(&dVal, len); } - start = self->start; - length = self->len; + start = start_; + length = len_; - x = grib_find_accessor(grib_handle_of_accessor(a), self->argument); + x = grib_find_accessor(grib_handle_of_accessor(this), argument_); if (!x) return GRIB_NOT_FOUND; /* Check the input value */ if (*val < 0) { - grib_context_log(h->context, GRIB_LOG_ERROR, "key=%s: value cannot be negative", a->name); + grib_context_log(h->context, GRIB_LOG_ERROR, "key=%s: value cannot be negative", name_); return GRIB_ENCODING_ERROR; } #ifdef DEBUG { - const long numbits = (x->length) * 8; + const long numbits = (x->length_) * 8; if (start + length > numbits) { grib_context_log(h->context, GRIB_LOG_ERROR, - "grib_accessor_class_bits::pack_long: key=%s (x=%s): " + "grib_accessor_bits::pack_long: key=%s (x=%s): " "Invalid start/length. x->length=%ld, start=%ld, length=%ld", - a->name, x->name, numbits, start, length); + name_, x->name_, numbits, start, length); return GRIB_ENCODING_ERROR; } } @@ -170,7 +164,7 @@ int grib_accessor_class_bits_t::pack_long(grib_accessor* a, const long* val, siz if (*val > maxval) { grib_context_log(h->context, GRIB_LOG_ERROR, "key=%s: Trying to encode value of %ld but the maximum allowable value is %ld (number of bits=%ld)", - a->name, *val, maxval, length); + name_, *val, maxval, length); return GRIB_ENCODING_ERROR; } @@ -178,64 +172,63 @@ int grib_accessor_class_bits_t::pack_long(grib_accessor* a, const long* val, siz return grib_encode_unsigned_longb(p, *val, &start, length); } -int grib_accessor_class_bits_t::get_native_type(grib_accessor* a) +long grib_accessor_bits_t::get_native_type() { - int type = GRIB_TYPE_BYTES; - grib_accessor_bits_t* self = (grib_accessor_bits_t*)a; + int type = GRIB_TYPE_BYTES; - if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE) + if (flags_ & GRIB_ACCESSOR_FLAG_STRING_TYPE) type = GRIB_TYPE_STRING; - if (a->flags & GRIB_ACCESSOR_FLAG_LONG_TYPE) + if (flags_ & GRIB_ACCESSOR_FLAG_LONG_TYPE) type = GRIB_TYPE_LONG; - if (self->referenceValuePresent) + if (referenceValuePresent_) type = GRIB_TYPE_DOUBLE; return type; } -int grib_accessor_class_bits_t::unpack_string(grib_accessor* a, char* v, size_t* len) +int grib_accessor_bits_t::unpack_string(char* v, size_t* len) { int ret = 0; double dval = 0; long lval = 0; size_t llen = 1; - switch (get_native_type(a)) { + switch (get_native_type()) { case GRIB_TYPE_LONG: - ret = unpack_long(a, &lval, &llen); + ret = unpack_long(&lval, &llen); snprintf(v, 64, "%ld", lval); *len = strlen(v); break; case GRIB_TYPE_DOUBLE: - ret = unpack_double(a, &dval, &llen); + ret = unpack_double(&dval, &llen); snprintf(v, 64, "%g", dval); *len = strlen(v); break; default: - ret = grib_accessor_class_gen_t::unpack_string(a, v, len); + ret = grib_accessor_gen_t::unpack_string(v, len); } return ret; } -long grib_accessor_class_bits_t::byte_count(grib_accessor* a) +long grib_accessor_bits_t::byte_count() { - grib_context_log(a->context, GRIB_LOG_DEBUG, "byte_count of %s = %ld", a->name, a->length); - return a->length; + grib_context_log(context_, GRIB_LOG_DEBUG, "byte_count of %s = %ld", name_, length_); + return length_; } -int grib_accessor_class_bits_t::unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len) +int grib_accessor_bits_t::unpack_bytes(unsigned char* buffer, size_t* len) { - if (*len < a->length) { - *len = a->length; + if (*len < length_) { + *len = length_; return GRIB_ARRAY_TOO_SMALL; } - *len = a->length; + *len = length_; - memcpy(buffer, grib_handle_of_accessor(a)->buffer->data + a->offset, *len); + memcpy(buffer, grib_handle_of_accessor(this)->buffer->data + offset_, *len); return GRIB_SUCCESS; } diff --git a/src/accessor/grib_accessor_class_bits.h b/src/accessor/grib_accessor_class_bits.h index 19ec26b35..58787ff4c 100644 --- a/src/accessor/grib_accessor_class_bits.h +++ b/src/accessor/grib_accessor_class_bits.h @@ -16,27 +16,24 @@ 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_bits_t() : + grib_accessor_gen_t() { class_name_ = "bits"; } 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; + long get_native_type() override; + int pack_double(const double* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + int unpack_bytes(unsigned char*, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + long byte_count() override; + void init(const long, grib_arguments*) override; + +private: + const char* argument_; + long start_; + long len_; + double referenceValue_; + double referenceValuePresent_; + double scale_; }; diff --git a/src/accessor/grib_accessor_class_bits_per_value.cc b/src/accessor/grib_accessor_class_bits_per_value.cc index dbdef54cb..e65ea3a6c 100644 --- a/src/accessor/grib_accessor_class_bits_per_value.cc +++ b/src/accessor/grib_accessor_class_bits_per_value.cc @@ -11,63 +11,57 @@ #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; +grib_accessor_bits_per_value_t _grib_accessor_bits_per_value{}; +grib_accessor* grib_accessor_bits_per_value = &_grib_accessor_bits_per_value; - -void grib_accessor_class_bits_per_value_t::init(grib_accessor* a, const long l, grib_arguments* args) +void grib_accessor_bits_per_value_t::init(const long l, grib_arguments* args) { - grib_accessor_class_long_t::init(a, l, 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; + grib_accessor_long_t::init(l, args); + int n = 0; + values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + bits_per_value_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + length_ = 0; } -int grib_accessor_class_bits_per_value_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_bits_per_value_t::unpack_long(long* val, size_t* len) { - grib_accessor_bits_per_value_t* self = (grib_accessor_bits_per_value_t*)a; + int ret = 0; + grib_handle* h = grib_handle_of_accessor(this); - int ret = 0; - grib_handle* h = grib_handle_of_accessor(a); - - if ((ret = grib_get_long_internal(h, self->bits_per_value, val)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, 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) +int grib_accessor_bits_per_value_t::pack_long(const long* val, size_t* len) { - grib_accessor_bits_per_value_t* self = (grib_accessor_bits_per_value_t*)a; - double* values = NULL; size_t size = 0; int ret = 0; - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); + grib_context* c = context_; + grib_handle* h = grib_handle_of_accessor(this); - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + if ((ret = grib_get_size(h, 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) { + if ((ret = grib_get_double_array_internal(h, 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) { + if ((ret = grib_set_long_internal(h, 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) { + if ((ret = grib_set_double_array_internal(h, values_, values, size)) != GRIB_SUCCESS) { grib_context_free(c, values); return ret; } diff --git a/src/accessor/grib_accessor_class_bits_per_value.h b/src/accessor/grib_accessor_class_bits_per_value.h index 741ecd0e5..b7995d794 100644 --- a/src/accessor/grib_accessor_class_bits_per_value.h +++ b/src/accessor/grib_accessor_class_bits_per_value.h @@ -16,17 +16,14 @@ 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_bits_per_value_t() : + grib_accessor_long_t() { class_name_ = "bits_per_value"; } 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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* values_; + const char* bits_per_value_; }; diff --git a/src/accessor/grib_accessor_class_blob.cc b/src/accessor/grib_accessor_class_blob.cc index 4629de93a..9bc8a9476 100644 --- a/src/accessor/grib_accessor_class_blob.cc +++ b/src/accessor/grib_accessor_class_blob.cc @@ -11,37 +11,36 @@ #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; +grib_accessor_blob_t _grib_accessor_blob{}; +grib_accessor* grib_accessor_blob = &_grib_accessor_blob; - -void grib_accessor_class_blob_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_blob_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, 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); + grib_accessor_gen_t::init(len, arg); + grib_get_long_internal(grib_handle_of_accessor(this), + grib_arguments_get_name(parent_->h, arg, 0), &length_); + Assert(length_ >= 0); } -int grib_accessor_class_blob_t::get_native_type(grib_accessor* a) +long grib_accessor_blob_t::get_native_type() { return GRIB_TYPE_BYTES; } -int grib_accessor_class_blob_t::unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len) +int grib_accessor_blob_t::unpack_bytes(unsigned char* buffer, size_t* len) { - if (*len < (size_t)a->length) { - *len = a->length; + if (*len < (size_t)length_) { + *len = length_; return GRIB_ARRAY_TOO_SMALL; } - *len = a->length; + *len = length_; - memcpy(buffer, grib_handle_of_accessor(a)->buffer->data + a->offset, *len); + memcpy(buffer, grib_handle_of_accessor(this)->buffer->data + offset_, *len); return GRIB_SUCCESS; } -void grib_accessor_class_blob_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_blob_t::dump(grib_dumper* dumper) { - grib_dump_bytes(dumper, a, NULL); + grib_dump_bytes(dumper, this, NULL); } diff --git a/src/accessor/grib_accessor_class_blob.h b/src/accessor/grib_accessor_class_blob.h index 10dad4b7b..1164648e7 100644 --- a/src/accessor/grib_accessor_class_blob.h +++ b/src/accessor/grib_accessor_class_blob.h @@ -16,16 +16,11 @@ 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_blob_t() : + grib_accessor_gen_t() { class_name_ = "blob"; } 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; + long get_native_type() override; + int unpack_bytes(unsigned char*, size_t* len) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_budgdate.cc b/src/accessor/grib_accessor_class_budgdate.cc index 3efb0b79e..8bf79b077 100644 --- a/src/accessor/grib_accessor_class_budgdate.cc +++ b/src/accessor/grib_accessor_class_budgdate.cc @@ -11,35 +11,32 @@ #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; +grib_accessor_budgdate_t _grib_accessor_budgdate{}; +grib_accessor* grib_accessor_budgdate = &_grib_accessor_budgdate; - -void grib_accessor_class_budgdate_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_budgdate_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_budgdate_t* self = (grib_accessor_budgdate_t*)a; - int n = 0; + grib_accessor_long_t::init(l, c); + 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++); + year_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + month_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + day_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); } -int grib_accessor_class_budgdate_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_budgdate_t::unpack_long(long* val, size_t* len) { - int ret = 0; - grib_accessor_budgdate_t* self = (grib_accessor_budgdate_t*)a; + int ret = 0; 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) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), day_, &day)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->month, &month)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), month_, &month)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->year, &year)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), year_, &year)) != GRIB_SUCCESS) return ret; if (*len < 1) @@ -51,11 +48,10 @@ int grib_accessor_class_budgdate_t::unpack_long(grib_accessor* a, long* val, siz } /* TODO: Check for a valid date */ -int grib_accessor_class_budgdate_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_budgdate_t::pack_long(const long* val, size_t* len) { - int ret = 0; - long v = val[0]; - grib_accessor_budgdate_t* self = (grib_accessor_budgdate_t*)a; + int ret = 0; + long v = val[0]; long year = 0; long month = 0; @@ -74,11 +70,11 @@ int grib_accessor_class_budgdate_t::pack_long(grib_accessor* a, const long* val, Assert(year < 255); - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->day, day)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), day_, day)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->month, month)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), month_, month)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->year, year)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), year_, year)) != GRIB_SUCCESS) return ret; return ret; diff --git a/src/accessor/grib_accessor_class_budgdate.h b/src/accessor/grib_accessor_class_budgdate.h index ee18250e2..d9b7bcf66 100644 --- a/src/accessor/grib_accessor_class_budgdate.h +++ b/src/accessor/grib_accessor_class_budgdate.h @@ -16,18 +16,15 @@ 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_budgdate_t() : + grib_accessor_long_t() { class_name_ = "budgdate"; } 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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* year_; + const char* month_; + const char* day_; }; diff --git a/src/accessor/grib_accessor_class_bufr_data_array.cc b/src/accessor/grib_accessor_class_bufr_data_array.cc index b0b0dc50a..6da17a946 100644 --- a/src/accessor/grib_accessor_class_bufr_data_array.cc +++ b/src/accessor/grib_accessor_class_bufr_data_array.cc @@ -10,16 +10,16 @@ #include "grib_scaling.h" #include "grib_accessor_class_bufr_data_array.h" +#include "grib_accessor_class_expanded_descriptors.h" -grib_accessor_class_bufr_data_array_t _grib_accessor_class_bufr_data_array{"bufr_data_array"}; -grib_accessor_class* grib_accessor_class_bufr_data_array = &_grib_accessor_class_bufr_data_array; - +grib_accessor_bufr_data_array_t _grib_accessor_bufr_data_array{}; +grib_accessor* grib_accessor_bufr_data_array = &_grib_accessor_bufr_data_array; #define MAX_NESTED_REPLICATIONS 8 -#define PROCESS_DECODE 0 +#define PROCESS_DECODE 0 #define PROCESS_NEW_DATA 1 -#define PROCESS_ENCODE 2 +#define PROCESS_ENCODE 2 #define OVERRIDDEN_REFERENCE_VALUES_KEY "inputOverriddenReferenceValues" @@ -27,42 +27,41 @@ grib_accessor_class* grib_accessor_class_bufr_data_array = &_grib_accessor_class /* variable 'err' is assumed to be pointer to int */ /* If BUFRDC mode is enabled, then we tolerate problems like wrong data section length */ #define CHECK_END_DATA_RETURN(ctx, bd, b, size, retval) \ - { \ + { \ *err = check_end_data(ctx, bd, b, size); \ - if (*err != 0 && ctx->bufrdc_mode == 0) \ - return retval; \ + if (*err != 0 && ctx->bufrdc_mode == 0) \ + return retval; \ } static int process_elements(grib_accessor* a, int flag, long onlySubset, long startSubset, long endSubset); typedef int (*codec_element_proc)(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, grib_buffer* b, unsigned char* data, long* pos, int i, bufr_descriptor* descriptor, long elementIndex, grib_darray* dval, grib_sarray* sval); typedef int (*codec_replication_proc)(grib_context* c, grib_accessor_bufr_data_array_t* self, int subsetIndex, grib_buffer* buff, unsigned char* data, long* pos, int i, long elementIndex, grib_darray* dval, long* numberOfRepetitions); -static int create_keys(const grib_accessor* a, long onlySubset, long startSubset, long endSubset); +static int create_keys(const grib_accessor* a, long onlySubset, long startSubset, long endSubset); static void restart_bitmap(grib_accessor_bufr_data_array_t* self) { - self->bitmapCurrent = -1; - self->bitmapCurrentElementsDescriptorsIndex = self->bitmapStartElementsDescriptorsIndex - 1; + self->bitmapCurrent_ = -1; + self->bitmapCurrentElementsDescriptorsIndex_ = self->bitmapStartElementsDescriptorsIndex_ - 1; } static void cancel_bitmap(grib_accessor_bufr_data_array_t* self) { - self->bitmapCurrent = -1; - self->bitmapStart = -1; + self->bitmapCurrent_ = -1; + self->bitmapStart_ = -1; } static int is_bitmap_start_defined(grib_accessor_bufr_data_array_t* self) { - return self->bitmapStart == -1 ? 0 : 1; + return self->bitmapStart_ == -1 ? 0 : 1; } static size_t get_length(grib_accessor* a) { grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - size_t len = 0; + size_t len = 0; + const grib_handle* h = grib_handle_of_accessor(a); - const grib_handle* h = grib_handle_of_accessor(a); - - grib_get_size(h, self->bufrDataEncodedName, &len); + grib_get_size(h, self->bufrDataEncodedName_, &len); return len; } @@ -73,12 +72,12 @@ static void tableB_override_store_ref_val(grib_context* c, grib_accessor_bufr_da bufr_tableb_override* tb = (bufr_tableb_override*)grib_context_malloc_clear(c, sizeof(bufr_tableb_override)); tb->code = code; tb->new_ref_val = new_ref_val; - if (!self->tableb_override) { - self->tableb_override = tb; + if (!self->tableb_override_) { + self->tableb_override_ = tb; } else { /*Add to end of linked list*/ - bufr_tableb_override* q = self->tableb_override; + bufr_tableb_override* q = self->tableb_override_; while (q->next) q = q->next; q->next = tb; @@ -88,7 +87,7 @@ static void tableB_override_store_ref_val(grib_context* c, grib_accessor_bufr_da /* Operator 203YYY: Retrieve changed reference value from linked list */ static int tableB_override_get_ref_val(grib_accessor_bufr_data_array_t* self, int code, long* out_ref_val) { - bufr_tableb_override* p = self->tableb_override; + bufr_tableb_override* p = self->tableb_override_; while (p) { if (p->code == code) { *out_ref_val = p->new_ref_val; @@ -102,13 +101,13 @@ static int tableB_override_get_ref_val(grib_accessor_bufr_data_array_t* self, in /* Operator 203YYY: Clear and free linked list */ static void tableB_override_clear(grib_context* c, grib_accessor_bufr_data_array_t* self) { - bufr_tableb_override* tb = self->tableb_override; + bufr_tableb_override* tb = self->tableb_override_; while (tb) { bufr_tableb_override* n = tb->next; grib_context_free(c, tb); tb = n; } - self->tableb_override = NULL; + self->tableb_override_ = NULL; } /* Operator 203YYY: Copy contents of linked list to the transient array key */ @@ -118,7 +117,7 @@ static int tableB_override_set_key(grib_handle* h, grib_accessor_bufr_data_array size_t size = 0; long* refVals = NULL; grib_iarray* refValArray = grib_iarray_new(h->context, 10, 10); - bufr_tableb_override* p = self->tableb_override; + bufr_tableb_override* p = self->tableb_override_; while (p) { grib_iarray_push(refValArray, p->new_ref_val); p = p->next; @@ -151,7 +150,7 @@ static int check_overridden_reference_values(const grib_context* c, long* refVal // void tableB_override_dump(grib_accessor_bufr_data_array_t *self) // { -// bufr_tableb_override* p = self->tableb_override; +// bufr_tableb_override* p = self->tableb_override_ ; // int i = 1; // while (p) { // printf("ECCODES DEBUG: Table B Override: [%d] code=%d, rv=%ld\n", i, p->code, p->new_ref_val); @@ -163,45 +162,69 @@ static int check_overridden_reference_values(const grib_context* c, long* refVal #define DYN_ARRAY_SIZE_INIT 1000 /* Initial size for grib_iarray_new and grib_darray_new */ #define DYN_ARRAY_SIZE_INCR 1000 /* Increment size for grib_iarray_new and grib_darray_new */ -void grib_accessor_class_bufr_data_array_t::init(grib_accessor* a, const long v, grib_arguments* params) +void grib_accessor_bufr_data_array_t::init(const long v, grib_arguments* params) { - grib_accessor_class_gen_t::init(a, v, params); - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - int n = 0; - const char* dataKeysName = NULL; - grib_accessor* dataKeysAcc = NULL; + grib_accessor_gen_t::init(v, params); + int n = 0; + const char* dataKeysName = NULL; + grib_accessor* dataKeysAcc = NULL; - self->bufrDataEncodedName = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); - self->numberOfSubsetsName = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); - self->expandedDescriptorsName = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); - self->flagsName = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); - self->elementsDescriptorsIndexName = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); - self->compressedDataName = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); - dataKeysName = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); + unitsName_ = NULL; + canBeMissing_ = NULL; + numberOfSubsets_ = 0; + compressedData_ = 0; + bitmapStartElementsDescriptorsIndex_ = 0; + bitmapCurrentElementsDescriptorsIndex_ = 0; + bitmapSize_ = 0; + bitmapStart_ = 0; + bitmapCurrent_ = 0; + dataAccessors_ = NULL; + nInputBitmap_ = 0; + iInputBitmap_ = 0; + inputReplications_ = NULL; + nInputReplications_ = 0; + iInputReplications_ = 0; + inputExtendedReplications_ = NULL; + nInputExtendedReplications_ = 0; + iInputExtendedReplications_ = 0; + inputShortReplications_ = NULL; + nInputShortReplications_ = 0; + iInputShortReplications_ = 0; + iss_list_ = NULL; + tempStrings_ = NULL; - dataKeysAcc = grib_find_accessor(grib_handle_of_accessor(a), dataKeysName); - self->dataKeys = dataKeysAcc->parent; - self->do_decode = 1; - self->elementsDescriptorsIndex = 0; - self->numericValues = 0; - self->tempDoubleValues = 0; - self->stringValues = 0; - cancel_bitmap(self); - self->expanded = 0; - self->expandedAccessor = 0; - self->dataAccessorsTrie = 0; - self->change_ref_value_operand = 0; /* Operator 203YYY: 0, 255 or YYY */ - self->refValListSize = 0; /* Operator 203YYY: size of overridden reference values array */ - self->refValList = NULL; /* Operator 203YYY: overridden reference values array */ - self->refValIndex = 0; /* Operator 203YYY: index into overridden reference values array */ - self->tableb_override = NULL; /* Operator 203YYY: Table B lookup linked list */ - self->set_to_missing_if_out_of_range = 0; /* By default fail if out of range */ - a->length = 0; - self->bitsToEndData = get_length(a) * 8; - self->unpackMode = CODES_BUFR_UNPACK_STRUCTURE; - self->inputBitmap = NULL; - /* Assert(a->length>=0); */ + bufrDataEncodedName_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++); + numberOfSubsetsName_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++); + expandedDescriptorsName_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++); + flagsName_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++); + elementsDescriptorsIndexName_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++); + compressedDataName_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++); + dataKeysName = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++); + + dataKeysAcc = grib_find_accessor(grib_handle_of_accessor(this), dataKeysName); + dataKeys_ = dataKeysAcc->parent_; + do_decode_ = 1; + elementsDescriptorsIndex_ = 0; + numericValues_ = 0; + tempDoubleValues_ = 0; + stringValues_ = 0; + cancel_bitmap(this); + expanded_ = 0; + expandedAccessor_ = 0; + dataAccessorsTrie_ = 0; + change_ref_value_operand_ = 0; /* Operator 203YYY: 0, 255 or YYY */ + refValListSize_ = 0; /* Operator 203YYY: size of overridden reference values array */ + refValList_ = NULL; /* Operator 203YYY: overridden reference values array */ + refValIndex_ = 0; /* Operator 203YYY: index into overridden reference values array */ + tableb_override_ = NULL; /* Operator 203YYY: Table B lookup linked list */ + set_to_missing_if_out_of_range_ = 0; /* By default fail if out of range */ + + length_ = 0; + bitsToEndData_ = get_length(this) * 8; + unpackMode_ = CODES_BUFR_UNPACK_STRUCTURE; + inputBitmap_ = NULL; + /* Assert(length_ >=0); */ } // void clean_string(char* s,int len) @@ -216,11 +239,11 @@ void grib_accessor_class_bufr_data_array_t::init(grib_accessor* a, const long v, static int check_end_data(grib_context* c, bufr_descriptor* bd, grib_accessor_bufr_data_array_t* self, int size) { - const int saved_bitsToEndData = self->bitsToEndData; + const int saved_bitsToEndData = self->bitsToEndData_; if (c->debug == 1) - grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data decoding: \tbitsToEndData=%d elementSize=%d", self->bitsToEndData, size); - self->bitsToEndData -= size; - if (self->bitsToEndData < 0) { + grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data decoding: \tbitsToEndData=%d elementSize=%d", self->bitsToEndData_, size); + self->bitsToEndData_ -= size; + if (self->bitsToEndData_ < 0) { grib_context_log(c, GRIB_LOG_ERROR, "BUFR data decoding: Number of bits left=%d but element size=%d", saved_bitsToEndData, size); if (bd) grib_context_log(c, GRIB_LOG_ERROR, "BUFR data decoding: code=%06ld key=%s", bd->code, bd->shortName); @@ -231,117 +254,115 @@ static int check_end_data(grib_context* c, bufr_descriptor* bd, grib_accessor_bu void self_clear(grib_context* c, grib_accessor_bufr_data_array_t* self) { - grib_context_free(c, self->canBeMissing); - grib_vdarray_delete_content(c, self->numericValues); - grib_vdarray_delete(c, self->numericValues); + grib_context_free(c, self->canBeMissing_); + grib_vdarray_delete_content(c, self->numericValues_); + grib_vdarray_delete(c, self->numericValues_); - if (self->stringValues) { - /*printf("dbg self_clear: clear %p\n", (void*)(self->stringValues));*/ - grib_vsarray_delete_content(c, self->stringValues); - grib_vsarray_delete(c, self->stringValues); - self->stringValues = NULL; + if (self->stringValues_) { + /*printf("dbg self_clear: clear %p\n", (void*)(self->stringValues_ ));*/ + grib_vsarray_delete_content(c, self->stringValues_); + grib_vsarray_delete(c, self->stringValues_); + self->stringValues_ = NULL; } - grib_viarray_delete_content(c, self->elementsDescriptorsIndex); - grib_viarray_delete(c, self->elementsDescriptorsIndex); - if (self->inputReplications) - grib_context_free(c, self->inputReplications); - if (self->inputExtendedReplications) - grib_context_free(c, self->inputExtendedReplications); - if (self->inputShortReplications) - grib_context_free(c, self->inputShortReplications); - self->change_ref_value_operand = 0; - self->refValListSize = 0; - if (self->refValList) - grib_context_free(c, self->refValList); - self->refValIndex = 0; + grib_viarray_delete_content(c, self->elementsDescriptorsIndex_); + grib_viarray_delete(c, self->elementsDescriptorsIndex_); + if (self->inputReplications_) + grib_context_free(c, self->inputReplications_); + if (self->inputExtendedReplications_) + grib_context_free(c, self->inputExtendedReplications_); + if (self->inputShortReplications_) + grib_context_free(c, self->inputShortReplications_); + self->change_ref_value_operand_ = 0; + self->refValListSize_ = 0; + if (self->refValList_) + grib_context_free(c, self->refValList_); + self->refValIndex_ = 0; tableB_override_clear(c, self); - self->set_to_missing_if_out_of_range = 0; - if (self->inputBitmap) grib_context_free(c, self->inputBitmap); + self->set_to_missing_if_out_of_range_ = 0; + if (self->inputBitmap_) grib_context_free(c, self->inputBitmap_); } -int grib_accessor_class_bufr_data_array_t::get_native_type(grib_accessor* a) +long grib_accessor_bufr_data_array_t::get_native_type() { return GRIB_TYPE_DOUBLE; } -long grib_accessor_class_bufr_data_array_t::byte_count(grib_accessor* a) +long grib_accessor_bufr_data_array_t::byte_count() { return 0; } -long grib_accessor_class_bufr_data_array_t::byte_offset(grib_accessor* a) +long grib_accessor_bufr_data_array_t::byte_offset() { - return a->offset; + return offset_; } -long grib_accessor_class_bufr_data_array_t::next_offset(grib_accessor* a) +long grib_accessor_bufr_data_array_t::next_offset() { - return a->offset; + return offset_; } -int grib_accessor_class_bufr_data_array_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_bufr_data_array_t::pack_long(const long* val, size_t* len) { - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - self->do_decode = 1; + do_decode_ = 1; return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_bufr_data_array_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_bufr_data_array_t::pack_double(const double* val, size_t* len) { - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - self->do_decode = 1; - return process_elements(a, PROCESS_ENCODE, 0, 0, 0); + do_decode_ = 1; + return process_elements(this, PROCESS_ENCODE, 0, 0, 0); } grib_vsarray* accessor_bufr_data_array_get_stringValues(grib_accessor* a) { grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; process_elements(a, PROCESS_DECODE, 0, 0, 0); - return self->stringValues; + return self->stringValues_; } grib_accessors_list* accessor_bufr_data_array_get_dataAccessors(grib_accessor* a) { grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - return self->dataAccessors; + return self->dataAccessors_; } grib_trie_with_rank* accessor_bufr_data_array_get_dataAccessorsTrie(grib_accessor* a) { grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - return self->dataAccessorsTrie; + return self->dataAccessorsTrie_; } void accessor_bufr_data_array_set_unpackMode(grib_accessor* a, int unpackMode) { grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - self->unpackMode = unpackMode; + self->unpackMode_ = unpackMode; } static int get_descriptors(grib_accessor* a) { grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - int ret = 0, i, numberOfDescriptors; - grib_handle* h = grib_handle_of_accessor(a); - grib_context* c = a->context; + int ret = 0, i, numberOfDescriptors; + grib_handle* h = grib_handle_of_accessor(a); + grib_context* c = a->context_; - if (!self->expandedAccessor) - self->expandedAccessor = grib_find_accessor(grib_handle_of_accessor(a), self->expandedDescriptorsName); - self->expanded = grib_accessor_class_expanded_descriptors_get_expanded(self->expandedAccessor, &ret); + if (!self->expandedAccessor_) + self->expandedAccessor_ = grib_find_accessor(grib_handle_of_accessor(a), self->expandedDescriptorsName_); + self->expanded_ = grib_accessor_expanded_descriptors_get_expanded(self->expandedAccessor_, &ret); if (ret != GRIB_SUCCESS) return ret; - numberOfDescriptors = grib_bufr_descriptors_array_used_size(self->expanded); - if (self->canBeMissing ) grib_context_free(c, self->canBeMissing); - self->canBeMissing = (int*)grib_context_malloc_clear(c, numberOfDescriptors * sizeof(int)); + numberOfDescriptors = grib_bufr_descriptors_array_used_size(self->expanded_); + if (self->canBeMissing_) grib_context_free(c, self->canBeMissing_); + self->canBeMissing_ = (int*)grib_context_malloc_clear(c, numberOfDescriptors * sizeof(int)); for (i = 0; i < numberOfDescriptors; i++) - self->canBeMissing[i] = grib_bufr_descriptor_can_be_missing(self->expanded->v[i]); + self->canBeMissing_[i] = grib_bufr_descriptor_can_be_missing(self->expanded_->v[i]); - ret = grib_get_long(h, self->numberOfSubsetsName, &(self->numberOfSubsets)); + ret = grib_get_long(h, self->numberOfSubsetsName_, &(self->numberOfSubsets_)); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long(h, self->compressedDataName, &(self->compressedData)); + ret = grib_get_long(h, self->compressedDataName_, &(self->compressedData_)); return ret; } @@ -353,7 +374,7 @@ static int decode_string_array(grib_context* c, unsigned char* data, long* pos, int* err = &ret; char* sval = 0; int j, modifiedWidth, width; - grib_sarray* sa = grib_sarray_new(c, self->numberOfSubsets, 10); + grib_sarray* sa = grib_sarray_new(c, self->numberOfSubsets_, 10); int bufr_multi_element_constant_arrays = c->bufr_multi_element_constant_arrays; modifiedWidth = bd->width; @@ -362,26 +383,26 @@ static int decode_string_array(grib_context* c, unsigned char* data, long* pos, CHECK_END_DATA_RETURN(c, bd, self, modifiedWidth, *err); if (*err) { grib_sarray_push(c, sa, sval); - grib_vsarray_push(c, self->stringValues, sa); + grib_vsarray_push(c, self->stringValues_, sa); return ret; } grib_decode_string(data, pos, modifiedWidth / 8, sval); CHECK_END_DATA_RETURN(c, bd, self, 6, *err); if (*err) { grib_sarray_push(c, sa, sval); - grib_vsarray_push(c, self->stringValues, sa); + grib_vsarray_push(c, self->stringValues_, sa); return ret; } width = grib_decode_unsigned_long(data, pos, 6); if (width) { - CHECK_END_DATA_RETURN(c, bd, self, width * 8 * self->numberOfSubsets, *err); + CHECK_END_DATA_RETURN(c, bd, self, width * 8 * self->numberOfSubsets_, *err); if (*err) { grib_sarray_push(c, sa, sval); - grib_vsarray_push(c, self->stringValues, sa); + grib_vsarray_push(c, self->stringValues_, sa); return ret; } grib_context_free(c, sval); - for (j = 0; j < self->numberOfSubsets; j++) { + for (j = 0; j < self->numberOfSubsets_; j++) { sval = (char*)grib_context_malloc_clear(c, width + 1); grib_decode_string(data, pos, width, sval); grib_sarray_push(c, sa, sval); @@ -389,7 +410,7 @@ static int decode_string_array(grib_context* c, unsigned char* data, long* pos, } else { if (bufr_multi_element_constant_arrays) { - for (j = 0; j < self->numberOfSubsets; j++) { + for (j = 0; j < self->numberOfSubsets_; j++) { char* pStr = sval; if (j > 0) pStr = strdup(sval); @@ -400,13 +421,13 @@ static int decode_string_array(grib_context* c, unsigned char* data, long* pos, grib_sarray_push(c, sa, sval); } } - grib_vsarray_push(c, self->stringValues, sa); + grib_vsarray_push(c, self->stringValues_, sa); return ret; } grib_darray* decode_double_array(grib_context* c, unsigned char* data, long* pos, - bufr_descriptor* bd, int canBeMissing, - grib_accessor_bufr_data_array_t* self, int* err) + bufr_descriptor* bd, int canBeMissing, + grib_accessor_bufr_data_array_t* self, int* err) { grib_darray* ret = NULL; int j; @@ -435,9 +456,9 @@ grib_darray* decode_double_array(grib_context* c, unsigned char* data, long* pos localReference = (long)lval + modifiedReference; localWidth = grib_decode_unsigned_long(data, pos, 6); grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data decoding: \tlocalWidth=%d", localWidth); - ret = grib_darray_new(c, self->numberOfSubsets, 50); + ret = grib_darray_new(c, self->numberOfSubsets_, 50); if (localWidth) { - CHECK_END_DATA_RETURN(c, bd, self, localWidth * self->numberOfSubsets, NULL); + CHECK_END_DATA_RETURN(c, bd, self, localWidth * self->numberOfSubsets_, NULL); if (*err) { dval = GRIB_MISSING_DOUBLE; lval = 0; @@ -447,7 +468,7 @@ grib_darray* decode_double_array(grib_context* c, unsigned char* data, long* pos *err = 0; return ret; } - for (j = 0; j < self->numberOfSubsets; j++) { + for (j = 0; j < self->numberOfSubsets_; j++) { lval = grib_decode_size_t(data, pos, localWidth); if (canBeMissing && grib_is_all_bits_one(lval, localWidth)) { dval = GRIB_MISSING_DOUBLE; @@ -474,7 +495,7 @@ grib_darray* decode_double_array(grib_context* c, unsigned char* data, long* pos if (bufr_multi_element_constant_arrays) { grib_context_log(c, GRIB_LOG_DEBUG, " modifiedWidth=%d lval=%ld dval=%g (const array multi values) %6.6ld", modifiedWidth, lval, dval, bd->code); - for (j = 0; j < self->numberOfSubsets; j++) { + for (j = 0; j < self->numberOfSubsets_; j++) { grib_darray_push(c, ret, dval); } } @@ -493,14 +514,14 @@ static int encode_string_array(grib_context* c, grib_buffer* buff, long* pos, bu int err = 0, n, ival; int k, j, modifiedWidth, width; - if (self->iss_list == NULL) { - grib_context_log(c, GRIB_LOG_ERROR, "encode_string_array: self->iss_list==NULL"); + if (self->iss_list_ == NULL) { + grib_context_log(c, GRIB_LOG_ERROR, "encode_string_array: self->iss_list_ ==NULL"); return GRIB_INTERNAL_ERROR; } if (!stringValues) { return GRIB_INTERNAL_ERROR; } - n = grib_iarray_used_size(self->iss_list); + n = grib_iarray_used_size(self->iss_list_); if (n <= 0) return GRIB_NO_VALUES; @@ -510,7 +531,7 @@ static int encode_string_array(grib_context* c, grib_buffer* buff, long* pos, bu ival = 0; } else { - ival = self->iss_list->v[0]; + ival = self->iss_list_->v[0]; } if (n > grib_sarray_used_size(stringValues)) @@ -532,7 +553,7 @@ static int encode_string_array(grib_context* c, grib_buffer* buff, long* pos, bu if (width) { grib_buffer_set_ulength_bits(c, buff, buff->ulength_bits + width * n); for (j = 0; j < n; j++) { - k = self->iss_list->v[j]; + k = self->iss_list_->v[j]; err = grib_encode_string(buff->data, pos, width / 8, stringValues->v[k]); if (err) { grib_context_log(c, GRIB_LOG_ERROR, "encode_string_array: %s. Failed to encode '%s'", @@ -582,16 +603,16 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu size_t ii, index_of_min, index_of_max; int nvals = 0; double min = 0, max = 0, maxAllowed, minAllowed; - double* v = NULL; - double* values = NULL; + double* v = NULL; + double* values = NULL; bool thereIsAMissing = false; - bool is_constant = true; + bool is_constant = true; double val0; /* ECC-379, ECC-830 */ - const int dont_fail_if_out_of_range = self->set_to_missing_if_out_of_range; + const int dont_fail_if_out_of_range = self->set_to_missing_if_out_of_range_; - if (self->iss_list == NULL) { - grib_context_log(c, GRIB_LOG_ERROR, "encode_double_array: self->iss_list==NULL"); + if (self->iss_list_ == NULL) { + grib_context_log(c, GRIB_LOG_ERROR, "encode_double_array: self->iss_list_ ==NULL"); return GRIB_INTERNAL_ERROR; } @@ -603,7 +624,7 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu err = descriptor_get_min_max(bd, modifiedWidth, modifiedReference, modifiedFactor, &minAllowed, &maxAllowed); if (err) return err; - nvals = grib_iarray_used_size(self->iss_list); + nvals = grib_iarray_used_size(self->iss_list_); if (nvals <= 0) return GRIB_NO_VALUES; @@ -649,10 +670,10 @@ static int encode_double_array(grib_context* c, grib_buffer* buff, long* pos, bu if (nvals > grib_darray_used_size(dvalues)) return GRIB_ARRAY_TOO_SMALL; values = (double*)grib_context_malloc_clear(c, sizeof(double) * nvals); - val0 = dvalues->v[self->iss_list->v[0]]; + val0 = dvalues->v[self->iss_list_->v[0]]; is_constant = true; for (i = 0; i < nvals; i++) { - values[i] = dvalues->v[self->iss_list->v[i]]; + values[i] = dvalues->v[self->iss_list_->v[i]]; if (val0 != values[i]) is_constant = false; } @@ -797,7 +818,7 @@ static int encode_double_value(grib_context* c, grib_buffer* buff, long* pos, bu int modifiedWidth, modifiedReference; double modifiedFactor; /* ECC-379, ECC-830 */ - const int dont_fail_if_out_of_range = self->set_to_missing_if_out_of_range; + const int dont_fail_if_out_of_range = self->set_to_missing_if_out_of_range_; modifiedReference = bd->reference; modifiedFactor = bd->factor; @@ -909,22 +930,21 @@ static int decode_element(grib_context* c, grib_accessor_bufr_data_array_t* self grib_buffer* b, unsigned char* data, long* pos, int i, bufr_descriptor* descriptor, long elementIndex, grib_darray* dval, grib_sarray* sval) { - grib_accessor* a = (grib_accessor*)self; grib_darray* dar = 0; grib_sarray* sar = 0; int index = 0, ii, stringValuesLen; char* csval = 0; double cdval = 0, x; int err = 0; - bufr_descriptor* bd = descriptor == NULL ? self->expanded->v[i] : descriptor; + bufr_descriptor* bd = descriptor == NULL ? self->expanded_->v[i] : descriptor; /* Assert( b->data == data); */ - if (self->change_ref_value_operand > 0 && self->change_ref_value_operand != 255) { + if (self->change_ref_value_operand_ > 0 && self->change_ref_value_operand_ != 255) { /* Operator 203YYY: Change Reference Values: Definition phase */ - const int number_of_bits = self->change_ref_value_operand; + const int number_of_bits = self->change_ref_value_operand_; long new_ref_val = grib_decode_signed_longb(data, pos, number_of_bits); grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data decoding: -**- \tcode=203YYY width=%d pos=%ld -> %ld", - number_of_bits, (long)*pos, (long)(*pos - a->offset * 8)); + number_of_bits, (long)*pos, (long)(*pos - self->offset_ * 8)); grib_context_log(c, GRIB_LOG_DEBUG, "Operator 203YYY: Store for code %6.6ld => new ref val %ld", bd->code, new_ref_val); tableB_override_store_ref_val(c, self, bd->code, new_ref_val); bd->nokey = 1; @@ -933,29 +953,29 @@ static int decode_element(grib_context* c, grib_accessor_bufr_data_array_t* self } grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data decoding: -%d- \tcode=%6.6ld width=%ld scale=%ld ref=%ld type=%d (pos=%ld -> %ld)", i, bd->code, bd->width, bd->scale, bd->reference, bd->type, - (long)*pos, (long)(*pos - a->offset * 8)); + (long)*pos, (long)(*pos - self->offset_ * 8)); if (bd->type == BUFR_DESCRIPTOR_TYPE_STRING) { /* string */ - if (self->compressedData) { + if (self->compressedData_) { err = decode_string_array(c, data, pos, bd, self); - index = grib_vsarray_used_size(self->stringValues); - dar = grib_darray_new(c, self->numberOfSubsets, 10); - index = self->numberOfSubsets * (index - 1); - for (ii = 1; ii <= self->numberOfSubsets; ii++) { + index = grib_vsarray_used_size(self->stringValues_); + dar = grib_darray_new(c, self->numberOfSubsets_, 10); + index = self->numberOfSubsets_ * (index - 1); + for (ii = 1; ii <= self->numberOfSubsets_; ii++) { x = (index + ii) * 1000 + bd->width / 8; grib_darray_push(c, dar, x); } - grib_vdarray_push(c, self->numericValues, dar); + grib_vdarray_push(c, self->numericValues_, dar); } else { csval = decode_string_value(c, data, pos, bd, self, &err); grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data decoding: \t %s = %s", bd->shortName, csval); sar = grib_sarray_push(c, sar, csval); - grib_vsarray_push(c, self->stringValues, sar); - stringValuesLen = grib_vsarray_used_size(self->stringValues); + grib_vsarray_push(c, self->stringValues_, sar); + stringValuesLen = grib_vsarray_used_size(self->stringValues_); index = 0; for (ii = 0; ii < stringValuesLen; ii++) { - index += grib_sarray_used_size(self->stringValues->v[ii]); + index += grib_sarray_used_size(self->stringValues_->v[ii]); } cdval = index * 1000 + bd->width / 8; grib_darray_push(c, dval, cdval); @@ -964,7 +984,7 @@ static int decode_element(grib_context* c, grib_accessor_bufr_data_array_t* self else { /* numeric or codetable or flagtable */ /* Operator 203YYY: Check if we have changed ref value for this element. If so modify bd->reference */ - if (self->change_ref_value_operand != 0 && tableB_override_get_ref_val(self, bd->code, &(bd->reference)) == GRIB_SUCCESS) { + if (self->change_ref_value_operand_ != 0 && tableB_override_get_ref_val(self, bd->code, &(bd->reference)) == GRIB_SUCCESS) { grib_context_log(c, GRIB_LOG_DEBUG, "Operator 203YYY: For code %6.6ld, changed ref val: %ld", bd->code, bd->reference); } @@ -972,13 +992,13 @@ static int decode_element(grib_context* c, grib_accessor_bufr_data_array_t* self grib_context_log(c, GRIB_LOG_ERROR, "Descriptor %6.6ld has bit width %ld!", bd->code, bd->width); return GRIB_DECODING_ERROR; } - if (self->compressedData) { - dar = decode_double_array(c, data, pos, bd, self->canBeMissing[i], self, &err); - grib_vdarray_push(c, self->numericValues, dar); + if (self->compressedData_) { + dar = decode_double_array(c, data, pos, bd, self->canBeMissing_[i], self, &err); + grib_vdarray_push(c, self->numericValues_, dar); } else { /* Uncompressed */ - cdval = decode_double_value(c, data, pos, bd, self->canBeMissing[i], self, &err); + cdval = decode_double_value(c, data, pos, bd, self->canBeMissing_[i], self, &err); grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data decoding: \t %s = %g", bd->shortName, cdval); grib_darray_push(c, dval, cdval); @@ -995,13 +1015,13 @@ static int decode_replication(grib_context* c, grib_accessor_bufr_data_array_t* int localReference, width; bufr_descriptor** descriptors = 0; err = &ret; - descriptors = self->expanded->v; + descriptors = self->expanded_->v; /* Assert(buff->data == data); */ grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data decoding: -%d- \tcode=%6.6ld width=%ld ", - i, self->expanded->v[i]->code, self->expanded->v[i]->width); - if (self->compressedData) { + i, self->expanded_->v[i]->code, self->expanded_->v[i]->width); + if (self->compressedData_) { grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data decoding: \tdelayed replication localReference width=%ld", descriptors[i]->width); CHECK_END_DATA_RETURN(c, NULL, self, descriptors[i]->width + 6, *err); if (*err) { @@ -1033,18 +1053,18 @@ static int decode_replication(grib_context* c, grib_accessor_bufr_data_array_t* grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data decoding: \tdelayed replication value=%ld", *numberOfRepetitions); } } - if (self->compressedData) { + if (self->compressedData_) { dval = grib_darray_new(c, 1, 100); if (c->bufr_multi_element_constant_arrays) { long j; - for (j = 0; j < self->numberOfSubsets; j++) { + for (j = 0; j < self->numberOfSubsets_; j++) { grib_darray_push(c, dval, (double)(*numberOfRepetitions)); } } else { grib_darray_push(c, dval, (double)(*numberOfRepetitions)); } - grib_vdarray_push(c, self->numericValues, dval); + grib_vdarray_push(c, self->numericValues_, dval); } else { grib_darray_push(c, dval, (double)(*numberOfRepetitions)); @@ -1057,19 +1077,19 @@ static int encode_new_bitmap(grib_context* c, grib_buffer* buff, long* pos, int grib_darray* doubleValues = NULL; int err = 0; double cdval = 0; - if (self->nInputBitmap > 0) { - if (self->nInputBitmap < self->iInputBitmap) + if (self->nInputBitmap_ > 0) { + if (self->nInputBitmap_ < self->iInputBitmap_) return GRIB_ARRAY_TOO_SMALL; - cdval = self->inputBitmap[self->iInputBitmap++]; + cdval = self->inputBitmap_[self->iInputBitmap_++]; } - if (self->compressedData) { + if (self->compressedData_) { doubleValues = grib_darray_new(c, 1, 1); grib_darray_push(c, doubleValues, cdval); - err = encode_double_array(c, buff, pos, self->expanded->v[idx], self, doubleValues); + err = encode_double_array(c, buff, pos, self->expanded_->v[idx], self, doubleValues); grib_darray_delete(c, doubleValues); } else { - err = encode_double_value(c, buff, pos, self->expanded->v[idx], self, cdval); + err = encode_double_value(c, buff, pos, self->expanded_->v[idx], self, cdval); } return err; } @@ -1080,10 +1100,10 @@ static int encode_overridden_reference_value(grib_context* c, grib_accessor_bufr { int err = 0; long currRefVal = -1; - long numBits = self->change_ref_value_operand; + long numBits = self->change_ref_value_operand_; /* We must be encoding between 203YYY and 203255 */ - Assert(self->change_ref_value_operand > 0 && self->change_ref_value_operand != 255); - if (self->refValListSize == 0) { + Assert(self->change_ref_value_operand_ > 0 && self->change_ref_value_operand_ != 255); + if (self->refValListSize_ == 0) { grib_context_log(c, GRIB_LOG_ERROR, "encode_new_element: Overridden Reference Values array is empty! " "(Hint: set the key '%s')", @@ -1093,24 +1113,24 @@ static int encode_overridden_reference_value(grib_context* c, grib_accessor_bufr "number of descriptors between operator 203YYY and 203255"); return GRIB_ENCODING_ERROR; } - if (self->refValIndex >= self->refValListSize) { + if (self->refValIndex_ >= self->refValListSize_) { grib_context_log(c, GRIB_LOG_ERROR, "encode_new_element: Overridden Reference Values: index=%ld, size=%ld. " "\nThe number of overridden reference values must be equal to " "number of descriptors between operator 203YYY and 203255", - self->refValIndex, self->refValListSize); + self->refValIndex_, self->refValListSize_); return GRIB_ENCODING_ERROR; } - currRefVal = self->refValList[self->refValIndex]; - grib_context_log(c, GRIB_LOG_DEBUG, "encode_new_element: Operator 203YYY: writing ref val %ld (self->refValIndex=%ld)", - currRefVal, self->refValIndex); + currRefVal = self->refValList_[self->refValIndex_]; + grib_context_log(c, GRIB_LOG_DEBUG, "encode_new_element: Operator 203YYY: writing ref val %ld (self->refValIndex_ =%ld)", + currRefVal, self->refValIndex_); grib_buffer_set_ulength_bits(c, buff, buff->ulength_bits + numBits); err = grib_encode_signed_longb(buff->data, currRefVal, pos, numBits); if (err) { grib_context_log(c, GRIB_LOG_ERROR, "Encoding overridden reference value %ld for %s (code=%6.6ld)", currRefVal, bd->shortName, bd->code); } - self->refValIndex++; + self->refValIndex_++; return err; } @@ -1124,12 +1144,12 @@ static int encode_new_element(grib_context* c, grib_accessor_bufr_data_array_t* double cdval = GRIB_MISSING_DOUBLE; int err = 0; size_t slen; - bufr_descriptor* bd = descriptor == NULL ? self->expanded->v[i] : descriptor; + bufr_descriptor* bd = descriptor == NULL ? self->expanded_->v[i] : descriptor; grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data encoding: \tcode=%6.6ld width=%ld pos=%ld ulength=%ld ulength_bits=%ld", bd->code, bd->width, (long)*pos, buff->ulength, buff->ulength_bits); - if (self->change_ref_value_operand > 0 && self->change_ref_value_operand != 255) { + if (self->change_ref_value_operand_ > 0 && self->change_ref_value_operand_ != 255) { /* Operator 203YYY: Change Reference Values: Encoding definition phase */ err = encode_overridden_reference_value(c, self, buff, pos, bd); return err; @@ -1143,7 +1163,7 @@ static int encode_new_element(grib_context* c, grib_accessor_bufr_data_array_t* csval[ii] = missingChar; grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data encoding: \t %s = %s", bd->shortName, csval); - if (self->compressedData) { + if (self->compressedData_) { grib_sarray* stringValues = grib_sarray_new(c, 1, 1); grib_sarray_push(c, stringValues, csval); err = encode_string_array(c, buff, pos, bd, self, stringValues); @@ -1161,7 +1181,7 @@ static int encode_new_element(grib_context* c, grib_accessor_bufr_data_array_t* bd->shortName, cdval); if (bd->code == 31031) return encode_new_bitmap(c, buff, pos, i, self); - if (self->compressedData) { + if (self->compressedData_) { grib_darray* doubleValues = grib_darray_new(c, 1, 1); grib_darray_push(c, doubleValues, cdval); err = encode_double_array(c, buff, pos, bd, self, doubleValues); @@ -1179,41 +1199,41 @@ static int encode_new_replication(grib_context* c, grib_accessor_bufr_data_array { int err = 0; unsigned long repetitions = 1; - bufr_descriptor** descriptors = self->expanded->v; - DEBUG_ASSERT( buff->data == data ); + bufr_descriptor** descriptors = self->expanded_->v; + DEBUG_ASSERT(buff->data == data); switch (descriptors[i]->code) { case 31000: - if (self->nInputShortReplications >= 0) { - if (self->iInputShortReplications >= self->nInputShortReplications) { + if (self->nInputShortReplications_ >= 0) { + if (self->iInputShortReplications_ >= self->nInputShortReplications_) { grib_context_log(c, GRIB_LOG_ERROR, "Array inputShortDelayedDescriptorReplicationFactor: dimension mismatch (nInputShortReplications=%d)", - self->nInputShortReplications); + self->nInputShortReplications_); return GRIB_ARRAY_TOO_SMALL; } - repetitions = self->inputShortReplications[self->iInputShortReplications]; - self->iInputShortReplications++; + repetitions = self->inputShortReplications_[self->iInputShortReplications_]; + self->iInputShortReplications_++; } break; case 31001: - if (self->nInputReplications >= 0) { - if (self->iInputReplications >= self->nInputReplications) { + if (self->nInputReplications_ >= 0) { + if (self->iInputReplications_ >= self->nInputReplications_) { grib_context_log(c, GRIB_LOG_ERROR, "Array inputDelayedDescriptorReplicationFactor: dimension mismatch (nInputReplications=%d)", - self->nInputReplications); + self->nInputReplications_); return GRIB_ARRAY_TOO_SMALL; } - repetitions = self->inputReplications[self->iInputReplications]; - self->iInputReplications++; + repetitions = self->inputReplications_[self->iInputReplications_]; + self->iInputReplications_++; } break; case 31002: - if (self->nInputExtendedReplications >= 0) { - if (self->iInputExtendedReplications >= self->nInputExtendedReplications) { + if (self->nInputExtendedReplications_ >= 0) { + if (self->iInputExtendedReplications_ >= self->nInputExtendedReplications_) { grib_context_log(c, GRIB_LOG_ERROR, "Array inputExtendedDelayedDescriptorReplicationFactor: dimension mismatch (nInputExtendedReplications=%d)", - self->nInputExtendedReplications); + self->nInputExtendedReplications_); return GRIB_ARRAY_TOO_SMALL; } - repetitions = self->inputExtendedReplications[self->iInputExtendedReplications]; - self->iInputExtendedReplications++; + repetitions = self->inputExtendedReplications_[self->iInputExtendedReplications_]; + self->iInputExtendedReplications_++; } break; default: @@ -1229,7 +1249,7 @@ static int encode_new_replication(grib_context* c, grib_accessor_bufr_data_array *numberOfRepetitions = repetitions; - if (self->compressedData) { + if (self->compressedData_) { grib_buffer_set_ulength_bits(c, buff, buff->ulength_bits + 6); grib_encode_unsigned_longb(buff->data, 0, pos, 6); } @@ -1243,13 +1263,13 @@ static int encode_element(grib_context* c, grib_accessor_bufr_data_array_t* self { int idx, j; int err = 0; - bufr_descriptor* bd = descriptor == NULL ? self->expanded->v[i] : descriptor; + bufr_descriptor* bd = descriptor == NULL ? self->expanded_->v[i] : descriptor; /* Assert( buff->data == data); */ grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data encoding: -%d- \tcode=%6.6ld width=%ld pos=%ld ulength=%ld ulength_bits=%ld", i, bd->code, bd->width, (long)*pos, buff->ulength, buff->ulength_bits); - if (self->change_ref_value_operand > 0 && self->change_ref_value_operand != 255) { + if (self->change_ref_value_operand_ > 0 && self->change_ref_value_operand_ != 255) { /* Operator 203YYY: Change Reference Values: Encoding definition phase */ err = encode_overridden_reference_value(c, self, buff, pos, bd); return err; @@ -1259,49 +1279,50 @@ static int encode_element(grib_context* c, grib_accessor_bufr_data_array_t* self /* string */ /* grib_context_log(c, GRIB_LOG_DEBUG,"BUFR data encoding: \t %s = %s", bd->shortName,csval); */ - if (self->compressedData) { - idx = ((int)self->numericValues->v[elementIndex]->v[0] / 1000 - 1) / self->numberOfSubsets; - err = encode_string_array(c, buff, pos, bd, self, self->stringValues->v[idx]); + if (self->compressedData_) { + idx = ((int)self->numericValues_->v[elementIndex]->v[0] / 1000 - 1) / self->numberOfSubsets_; + err = encode_string_array(c, buff, pos, bd, self, self->stringValues_->v[idx]); } else { - if (self->numericValues->v[subsetIndex] == NULL) { - grib_context_log(c, GRIB_LOG_ERROR, "Invalid subset index %d (number of subsets=%ld)", subsetIndex, self->numberOfSubsets); + if (self->numericValues_->v[subsetIndex] == NULL) { + grib_context_log(c, GRIB_LOG_ERROR, "Invalid subset index %d (number of subsets=%ld)", subsetIndex, self->numberOfSubsets_); return GRIB_INVALID_ARGUMENT; } - idx = (int)self->numericValues->v[subsetIndex]->v[elementIndex] / 1000 - 1; - if (idx < 0 || idx >= self->stringValues->n) { + idx = (int)self->numericValues_->v[subsetIndex]->v[elementIndex] / 1000 - 1; + if (idx < 0 || idx >= self->stringValues_->n) { grib_context_log(c, GRIB_LOG_ERROR, "encode_element '%s': Invalid index %d", bd->shortName, idx); return GRIB_INVALID_ARGUMENT; } - err = encode_string_value(c, buff, pos, bd, self, self->stringValues->v[idx]->v[0]); + err = encode_string_value(c, buff, pos, bd, self, self->stringValues_->v[idx]->v[0]); } } else { /* numeric or codetable or flagtable */ - if (self->compressedData) { - err = encode_double_array(c, buff, pos, bd, self, self->numericValues->v[elementIndex]); + if (self->compressedData_) { + err = encode_double_array(c, buff, pos, bd, self, self->numericValues_->v[elementIndex]); if (err) { - grib_darray* varr = self->numericValues->v[elementIndex]; + grib_darray* varr = self->numericValues_->v[elementIndex]; grib_context_log(c, GRIB_LOG_ERROR, "Encoding key '%s' ( code=%6.6ld width=%ld scale=%ld reference=%ld )", bd->shortName, bd->code, bd->width, bd->scale, bd->reference); if (varr) { for (j = 0; j < grib_darray_used_size(varr); j++) grib_context_log(c, GRIB_LOG_ERROR, "value[%d]\t= %g", j, varr->v[j]); - } else { + } + else { grib_context_log(c, GRIB_LOG_ERROR, "Empty array: Check the order of keys being set!"); } } } else { - if (self->numericValues->v[subsetIndex] == NULL) { - grib_context_log(c, GRIB_LOG_ERROR, "Invalid subset index %d (number of subsets=%ld)", subsetIndex, self->numberOfSubsets); + if (self->numericValues_->v[subsetIndex] == NULL) { + grib_context_log(c, GRIB_LOG_ERROR, "Invalid subset index %d (number of subsets=%ld)", subsetIndex, self->numberOfSubsets_); return GRIB_INVALID_ARGUMENT; } - err = encode_double_value(c, buff, pos, bd, self, self->numericValues->v[subsetIndex]->v[elementIndex]); + err = encode_double_value(c, buff, pos, bd, self, self->numericValues_->v[subsetIndex]->v[elementIndex]); if (err) { grib_context_log(c, GRIB_LOG_ERROR, "Cannot encode %s=%g (subset=%d)", /*subsetIndex starts from 0*/ - bd->shortName, self->numericValues->v[subsetIndex]->v[elementIndex], subsetIndex + 1); + bd->shortName, self->numericValues_->v[subsetIndex]->v[elementIndex], subsetIndex + 1); } } } @@ -1313,12 +1334,12 @@ static int encode_replication(grib_context* c, grib_accessor_bufr_data_array_t* grib_darray* dval, long* numberOfRepetitions) { /* Assert( buff->data == data); */ - if (self->compressedData) { - DEBUG_ASSERT(grib_darray_used_size(self->numericValues->v[elementIndex]) == 1); - *numberOfRepetitions = self->numericValues->v[elementIndex]->v[0]; + if (self->compressedData_) { + DEBUG_ASSERT(grib_darray_used_size(self->numericValues_->v[elementIndex]) == 1); + *numberOfRepetitions = self->numericValues_->v[elementIndex]->v[0]; } else { - *numberOfRepetitions = self->numericValues->v[subsetIndex]->v[elementIndex]; + *numberOfRepetitions = self->numericValues_->v[subsetIndex]->v[elementIndex]; } return encode_element(c, self, subsetIndex, buff, data, pos, i, 0, elementIndex, dval, 0); @@ -1330,10 +1351,10 @@ static int build_bitmap(grib_accessor_bufr_data_array_t* self, unsigned char* da int bitmapSize = 0, iDelayedReplication = 0; int i, localReference, width, bitmapEndElementsDescriptorsIndex; long ppos, n; - grib_accessor* a = (grib_accessor*)self; - const grib_context* c = a->context; - bufr_descriptor** descriptors = self->expanded->v; - const long* edi = elementsDescriptorsIndex->v; + grib_accessor* a = (grib_accessor*)self; + const grib_context* c = a->context_; + bufr_descriptor** descriptors = self->expanded_->v; + const long* edi = elementsDescriptorsIndex->v; /* int iel=grib_iarray_used_size(elementsDescriptorsIndex)-1; */ int err = 0; @@ -1372,7 +1393,7 @@ static int build_bitmap(grib_accessor_bufr_data_array_t* self, unsigned char* da Assert(descriptors[iDelayedReplication]->code == 31001 || descriptors[iDelayedReplication]->code == 31002); i = iDelayedReplication; - if (self->compressedData) { + if (self->compressedData_) { ppos = *pos; if (err) return err; @@ -1411,7 +1432,7 @@ static int build_bitmap(grib_accessor_bufr_data_array_t* self, unsigned char* da n--; iel--; } - self->bitmapStartElementsDescriptorsIndex = iel; + self->bitmapStartElementsDescriptorsIndex_ = iel; restart_bitmap(self); break; default: @@ -1426,17 +1447,17 @@ static int consume_bitmap(grib_accessor_bufr_data_array_t* self, int iBitmapOper { int bitmapSize = 0, iDelayedReplication; int i; - bufr_descriptor** descriptors = self->expanded->v; + bufr_descriptor** descriptors = self->expanded_->v; i = iBitmapOperator + 1; if (descriptors[i]->code == 101000) { iDelayedReplication = iBitmapOperator + 2; switch (descriptors[iDelayedReplication]->code) { case 31001: - bitmapSize = self->inputReplications[self->iInputReplications]; + bitmapSize = self->inputReplications_[self->iInputReplications_]; break; case 31002: - bitmapSize = self->inputExtendedReplications[self->iInputExtendedReplications]; + bitmapSize = self->inputExtendedReplications_[self->iInputExtendedReplications_]; break; default: Assert(0); @@ -1449,20 +1470,20 @@ static int consume_bitmap(grib_accessor_bufr_data_array_t* self, int iBitmapOper i++; } } - self->bitmapCurrent += bitmapSize; + self->bitmapCurrent_ += bitmapSize; return GRIB_SUCCESS; } -static int build_bitmap_new_data(grib_accessor_bufr_data_array_t* self, unsigned char* data, long* pos, +static int build_bitmap_new_data(grib_accessor* a, unsigned char* data, long* pos, int iel, grib_iarray* elementsDescriptorsIndex, int iBitmapOperator) { + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; int bitmapSize = 0, iDelayedReplication = 0; int i, bitmapEndElementsDescriptorsIndex; long n; - grib_accessor* a = (grib_accessor*)self; - const grib_context* c = a->context; - bufr_descriptor** descriptors = self->expanded->v; - const long* edi = elementsDescriptorsIndex->v; + const grib_context* c = a->context_; + bufr_descriptor** descriptors = self->expanded_->v; + const long* edi = elementsDescriptorsIndex->v; switch (descriptors[iBitmapOperator]->code) { case 222000: @@ -1497,18 +1518,18 @@ static int build_bitmap_new_data(grib_accessor_bufr_data_array_t* self, unsigned iDelayedReplication = iBitmapOperator + 2; switch (descriptors[iDelayedReplication]->code) { case 31001: - if (!self->inputReplications) { + if (!self->inputReplications_) { grib_context_log(c, GRIB_LOG_ERROR, "build_bitmap_new_data: No inputReplications"); return GRIB_ENCODING_ERROR; } - bitmapSize = self->inputReplications[self->iInputReplications]; + bitmapSize = self->inputReplications_[self->iInputReplications_]; break; case 31002: - if (!self->inputExtendedReplications) { + if (!self->inputExtendedReplications_) { grib_context_log(c, GRIB_LOG_ERROR, "build_bitmap_new_data: No inputExtendedReplications"); return GRIB_ENCODING_ERROR; } - bitmapSize = self->inputExtendedReplications[self->iInputExtendedReplications]; + bitmapSize = self->inputExtendedReplications_[self->iInputExtendedReplications_]; break; default: Assert(0); @@ -1528,8 +1549,8 @@ static int build_bitmap_new_data(grib_accessor_bufr_data_array_t* self, unsigned n--; iel--; } - self->bitmapStartElementsDescriptorsIndex = iel; - self->bitmapCurrentElementsDescriptorsIndex = iel - 1; + self->bitmapStartElementsDescriptorsIndex_ = iel; + self->bitmapCurrentElementsDescriptorsIndex_ = iel - 1; break; default: grib_context_log(c, GRIB_LOG_ERROR, "build_bitmap_new_data: unsupported operator %ld\n", @@ -1543,59 +1564,59 @@ static int build_bitmap_new_data(grib_accessor_bufr_data_array_t* self, unsigned static int get_next_bitmap_descriptor_index_new_bitmap(grib_accessor_bufr_data_array_t* self, grib_iarray* elementsDescriptorsIndex, int compressedData) { int i; - bufr_descriptor** descriptors = self->expanded->v; + bufr_descriptor** descriptors = self->expanded_->v; - self->bitmapCurrent++; - self->bitmapCurrentElementsDescriptorsIndex++; - i = self->bitmapCurrent; + self->bitmapCurrent_++; + self->bitmapCurrentElementsDescriptorsIndex_++; + i = self->bitmapCurrent_; - if (self->compressedData) { - DEBUG_ASSERT(i < self->nInputBitmap); - if (i >= self->nInputBitmap) + if (self->compressedData_) { + DEBUG_ASSERT(i < self->nInputBitmap_); + if (i >= self->nInputBitmap_) return GRIB_WRONG_BITMAP_SIZE; - while (self->inputBitmap[i] == 1) { - self->bitmapCurrent++; - self->bitmapCurrentElementsDescriptorsIndex++; - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) - self->bitmapCurrentElementsDescriptorsIndex++; + while (self->inputBitmap_[i] == 1) { + self->bitmapCurrent_++; + self->bitmapCurrentElementsDescriptorsIndex_++; + while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) + self->bitmapCurrentElementsDescriptorsIndex_++; i++; } } else { - if (i >= self->nInputBitmap) + if (i >= self->nInputBitmap_) return GRIB_WRONG_BITMAP_SIZE; - while (self->inputBitmap[i] == 1) { - self->bitmapCurrent++; - self->bitmapCurrentElementsDescriptorsIndex++; - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) - self->bitmapCurrentElementsDescriptorsIndex++; + while (self->inputBitmap_[i] == 1) { + self->bitmapCurrent_++; + self->bitmapCurrentElementsDescriptorsIndex_++; + while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) + self->bitmapCurrentElementsDescriptorsIndex_++; i++; } } - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) - self->bitmapCurrentElementsDescriptorsIndex++; - return elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]; + while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) + self->bitmapCurrentElementsDescriptorsIndex_++; + return elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex_]; } /* ECC-1304: Will return an index if successful. In case of an error, a negative number is returned e.g. GRIB_WRONG_BITMAP_SIZE */ static int get_next_bitmap_descriptor_index(grib_accessor_bufr_data_array_t* self, grib_iarray* elementsDescriptorsIndex, grib_darray* numericValues) { int i; - bufr_descriptor** descriptors = self->expanded->v; + bufr_descriptor** descriptors = self->expanded_->v; - if (self->compressedData) { - if (self->numericValues->n == 0) + if (self->compressedData_) { + if (self->numericValues_->n == 0) return get_next_bitmap_descriptor_index_new_bitmap(self, elementsDescriptorsIndex, 1); - self->bitmapCurrent++; - self->bitmapCurrentElementsDescriptorsIndex++; - i = self->bitmapCurrent + self->bitmapStart; - DEBUG_ASSERT(i < self->numericValues->n); - while (self->numericValues->v[i]->v[0] == 1) { - self->bitmapCurrent++; - self->bitmapCurrentElementsDescriptorsIndex++; - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) - self->bitmapCurrentElementsDescriptorsIndex++; + self->bitmapCurrent_++; + self->bitmapCurrentElementsDescriptorsIndex_++; + i = self->bitmapCurrent_ + self->bitmapStart_; + DEBUG_ASSERT(i < self->numericValues_->n); + while (self->numericValues_->v[i]->v[0] == 1) { + self->bitmapCurrent_++; + self->bitmapCurrentElementsDescriptorsIndex_++; + while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) + self->bitmapCurrentElementsDescriptorsIndex_++; i++; } } @@ -1603,32 +1624,32 @@ static int get_next_bitmap_descriptor_index(grib_accessor_bufr_data_array_t* sel if (numericValues->n == 0) return get_next_bitmap_descriptor_index_new_bitmap(self, elementsDescriptorsIndex, 0); - self->bitmapCurrent++; - self->bitmapCurrentElementsDescriptorsIndex++; - i = self->bitmapCurrent + self->bitmapStart; + self->bitmapCurrent_++; + self->bitmapCurrentElementsDescriptorsIndex_++; + i = self->bitmapCurrent_ + self->bitmapStart_; DEBUG_ASSERT(i < numericValues->n); while (numericValues->v[i] == 1) { - self->bitmapCurrent++; - self->bitmapCurrentElementsDescriptorsIndex++; - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) - self->bitmapCurrentElementsDescriptorsIndex++; + self->bitmapCurrent_++; + self->bitmapCurrentElementsDescriptorsIndex_++; + while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) + self->bitmapCurrentElementsDescriptorsIndex_++; i++; } } - while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]]->code > 100000) - self->bitmapCurrentElementsDescriptorsIndex++; - return elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex]; + while (descriptors[elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex_]]->code > 100000) + self->bitmapCurrentElementsDescriptorsIndex_++; + return elementsDescriptorsIndex->v[self->bitmapCurrentElementsDescriptorsIndex_]; } -static void push_zero_element(grib_accessor_bufr_data_array_t* self, grib_darray* dval) +static void push_zero_element(grib_accessor* a, grib_darray* dval) { - grib_darray* d = 0; - grib_accessor* a = (grib_accessor*)self; - grib_context* c = a->context; - if (self->compressedData) { + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; + grib_darray* d = 0; + grib_context* c = a->context_; + if (self->compressedData_) { d = grib_darray_new(c, 1, 100); grib_darray_push(c, d, 0); - grib_vdarray_push(c, self->numericValues, d); + grib_vdarray_push(c, self->numericValues_, d); } else { grib_darray_push(c, dval, 0); @@ -1638,7 +1659,9 @@ static void push_zero_element(grib_accessor_bufr_data_array_t* self, grib_darray static grib_accessor* create_attribute_variable(const char* name, grib_section* section, int type, char* sval, double dval, long lval, unsigned long flags) { grib_accessor* a = NULL; - grib_action creator = {0,}; + grib_action creator = { + 0, + }; size_t len; creator.op = (char*)"variable"; creator.name_space = (char*)""; @@ -1647,22 +1670,25 @@ static grib_accessor* create_attribute_variable(const char* name, grib_section* creator.name = (char*)name; a = grib_accessor_factory(section, &creator, 0, NULL); - a->parent = NULL; - a->h = section->h; + a->parent_ = NULL; + a->h_ = section->h; accessor_variable_set_type(a, type); len = 1; switch (type) { case GRIB_TYPE_LONG: - a->pack_long(&lval, &len); break; + a->pack_long(&lval, &len); + break; case GRIB_TYPE_DOUBLE: - a->pack_double(&dval, &len); break; + a->pack_double(&dval, &len); + break; case GRIB_TYPE_STRING: if (!sval) return NULL; /* Performance: No need for len=strlen(sval). It's not used. */ /* See grib_accessor_class_variable.c, pack_string() */ len = 0; - a->pack_string(sval, &len); break; + a->pack_string(sval, &len); + break; } return a; @@ -1756,13 +1782,19 @@ static grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, gr int count, int add_extra_attributes) { grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - char code[10] = {0,}; + char code[10] = { + 0, + }; char* temp_str = NULL; int idx = 0; unsigned long flags = GRIB_ACCESSOR_FLAG_READ_ONLY; - grib_action operatorCreator = {0,}; + grib_action operatorCreator = { + 0, + }; grib_accessor* elementAccessor = NULL; - grib_action creator = {0,}; + grib_action creator = { + 0, + }; creator.op = (char*)"bufr_data_element"; creator.name_space = (char*)""; creator.set = 0; @@ -1774,7 +1806,7 @@ static grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, gr operatorCreator.name = (char*)"operator"; if (attribute) { - DEBUG_ASSERT(attribute->parent == NULL); + DEBUG_ASSERT(attribute->parent_ == NULL); } if (add_dump_flag) { @@ -1782,34 +1814,34 @@ static grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, gr operatorCreator.flags |= GRIB_ACCESSOR_FLAG_DUMP; } if (add_coord_flag) { - creator.flags |= GRIB_ACCESSOR_FLAG_BUFR_COORD; // ECC-1611 + creator.flags |= GRIB_ACCESSOR_FLAG_BUFR_COORD; // ECC-1611 } - idx = self->compressedData ? self->elementsDescriptorsIndex->v[0]->v[ide] : self->elementsDescriptorsIndex->v[subset]->v[ide]; + idx = self->compressedData_ ? self->elementsDescriptorsIndex_->v[0]->v[ide] : self->elementsDescriptorsIndex_->v[subset]->v[ide]; - switch (self->expanded->v[idx]->F) { + switch (self->expanded_->v[idx]->F) { case 0: case 1: - creator.name = grib_context_strdup(a->context, self->expanded->v[idx]->shortName); + creator.name = grib_context_strdup(a->context_, self->expanded_->v[idx]->shortName); /* ECC-325: store alloc'd string (due to strdup) for clean up later */ - grib_sarray_push(a->context, self->tempStrings, creator.name); + grib_sarray_push(a->context_, self->tempStrings_, creator.name); elementAccessor = grib_accessor_factory(section, &creator, 0, NULL); - if (self->canBeMissing[idx]) - elementAccessor->flags |= GRIB_ACCESSOR_FLAG_CAN_BE_MISSING; - if (self->expanded->v[idx]->code == 31000 || self->expanded->v[idx]->code == 31001 || self->expanded->v[idx]->code == 31002 || self->expanded->v[idx]->code == 31031) - elementAccessor->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + if (self->canBeMissing_[idx]) + elementAccessor->flags_ |= GRIB_ACCESSOR_FLAG_CAN_BE_MISSING; + if (self->expanded_->v[idx]->code == 31000 || self->expanded_->v[idx]->code == 31001 || self->expanded_->v[idx]->code == 31002 || self->expanded_->v[idx]->code == 31031) + elementAccessor->flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; accessor_bufr_data_element_set_index(elementAccessor, ide); - accessor_bufr_data_element_set_descriptors(elementAccessor, self->expanded); - accessor_bufr_data_element_set_elementsDescriptorsIndex(elementAccessor, self->elementsDescriptorsIndex); - accessor_bufr_data_element_set_numericValues(elementAccessor, self->numericValues); - accessor_bufr_data_element_set_stringValues(elementAccessor, self->stringValues); - accessor_bufr_data_element_set_compressedData(elementAccessor, self->compressedData); - accessor_bufr_data_element_set_type(elementAccessor, self->expanded->v[idx]->type); - accessor_bufr_data_element_set_numberOfSubsets(elementAccessor, self->numberOfSubsets); + accessor_bufr_data_element_set_descriptors(elementAccessor, self->expanded_); + accessor_bufr_data_element_set_elementsDescriptorsIndex(elementAccessor, self->elementsDescriptorsIndex_); + accessor_bufr_data_element_set_numericValues(elementAccessor, self->numericValues_); + accessor_bufr_data_element_set_stringValues(elementAccessor, self->stringValues_); + accessor_bufr_data_element_set_compressedData(elementAccessor, self->compressedData_); + accessor_bufr_data_element_set_type(elementAccessor, self->expanded_->v[idx]->type); + accessor_bufr_data_element_set_numberOfSubsets(elementAccessor, self->numberOfSubsets_); accessor_bufr_data_element_set_subsetNumber(elementAccessor, subset); - self->expanded->v[idx]->a = elementAccessor; + self->expanded_->v[idx]->a = elementAccessor; if (attribute) { /* attribute->parent=elementAccessor->parent; */ @@ -1826,50 +1858,50 @@ static grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, gr return NULL; elementAccessor->add_attribute(attribute, 0); - snprintf(code, sizeof(code), "%06ld", self->expanded->v[idx]->code); - temp_str = grib_context_strdup(a->context, code); + snprintf(code, sizeof(code), "%06ld", self->expanded_->v[idx]->code); + temp_str = grib_context_strdup(a->context_, code); attribute = create_attribute_variable("code", section, GRIB_TYPE_STRING, temp_str, 0, 0, flags); if (!attribute) return NULL; - grib_sarray_push(a->context, self->tempStrings, temp_str); /* ECC-325: store alloc'd string (due to strdup) for clean up later */ + grib_sarray_push(a->context_, self->tempStrings_, temp_str); /* ECC-325: store alloc'd string (due to strdup) for clean up later */ elementAccessor->add_attribute(attribute, 0); if (add_extra_attributes) { - attribute = create_attribute_variable("units", section, GRIB_TYPE_STRING, self->expanded->v[idx]->units, 0, 0, GRIB_ACCESSOR_FLAG_DUMP | flags); + attribute = create_attribute_variable("units", section, GRIB_TYPE_STRING, self->expanded_->v[idx]->units, 0, 0, GRIB_ACCESSOR_FLAG_DUMP | flags); if (!attribute) return NULL; elementAccessor->add_attribute(attribute, 0); - attribute = create_attribute_variable("scale", section, GRIB_TYPE_LONG, 0, 0, self->expanded->v[idx]->scale, flags); + attribute = create_attribute_variable("scale", section, GRIB_TYPE_LONG, 0, 0, self->expanded_->v[idx]->scale, flags); if (!attribute) return NULL; elementAccessor->add_attribute(attribute, 0); - attribute = create_attribute_variable("reference", section, GRIB_TYPE_DOUBLE, 0, self->expanded->v[idx]->reference, 0, flags); + attribute = create_attribute_variable("reference", section, GRIB_TYPE_DOUBLE, 0, self->expanded_->v[idx]->reference, 0, flags); if (!attribute) return NULL; elementAccessor->add_attribute(attribute, 0); - attribute = create_attribute_variable("width", section, GRIB_TYPE_LONG, 0, 0, self->expanded->v[idx]->width, flags); + attribute = create_attribute_variable("width", section, GRIB_TYPE_LONG, 0, 0, self->expanded_->v[idx]->width, flags); if (!attribute) return NULL; elementAccessor->add_attribute(attribute, 0); } break; case 2: - set_creator_name(&creator, self->expanded->v[idx]->code); - if (bufr_descriptor_is_marker(self->expanded->v[idx])) { + set_creator_name(&creator, self->expanded_->v[idx]->code); + if (bufr_descriptor_is_marker(self->expanded_->v[idx])) { elementAccessor = grib_accessor_factory(section, &creator, 0, NULL); - if (self->canBeMissing[idx]) - elementAccessor->flags |= GRIB_ACCESSOR_FLAG_CAN_BE_MISSING; + if (self->canBeMissing_[idx]) + elementAccessor->flags_ |= GRIB_ACCESSOR_FLAG_CAN_BE_MISSING; accessor_bufr_data_element_set_index(elementAccessor, ide); - accessor_bufr_data_element_set_descriptors(elementAccessor, self->expanded); - accessor_bufr_data_element_set_elementsDescriptorsIndex(elementAccessor, self->elementsDescriptorsIndex); - accessor_bufr_data_element_set_numericValues(elementAccessor, self->numericValues); - accessor_bufr_data_element_set_stringValues(elementAccessor, self->stringValues); - accessor_bufr_data_element_set_compressedData(elementAccessor, self->compressedData); - accessor_bufr_data_element_set_type(elementAccessor, self->expanded->v[idx]->type); - accessor_bufr_data_element_set_numberOfSubsets(elementAccessor, self->numberOfSubsets); + accessor_bufr_data_element_set_descriptors(elementAccessor, self->expanded_); + accessor_bufr_data_element_set_elementsDescriptorsIndex(elementAccessor, self->elementsDescriptorsIndex_); + accessor_bufr_data_element_set_numericValues(elementAccessor, self->numericValues_); + accessor_bufr_data_element_set_stringValues(elementAccessor, self->stringValues_); + accessor_bufr_data_element_set_compressedData(elementAccessor, self->compressedData_); + accessor_bufr_data_element_set_type(elementAccessor, self->expanded_->v[idx]->type); + accessor_bufr_data_element_set_numberOfSubsets(elementAccessor, self->numberOfSubsets_); accessor_bufr_data_element_set_subsetNumber(elementAccessor, subset); attribute = create_attribute_variable("index", section, GRIB_TYPE_LONG, 0, 0, count, flags); @@ -1886,25 +1918,25 @@ static grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, gr return NULL; elementAccessor->add_attribute(attribute, 0); - snprintf(code, sizeof(code), "%06ld", self->expanded->v[idx]->code); + snprintf(code, sizeof(code), "%06ld", self->expanded_->v[idx]->code); attribute = create_attribute_variable("code", section, GRIB_TYPE_STRING, code, 0, 0, flags); if (!attribute) return NULL; elementAccessor->add_attribute(attribute, 0); } - self->expanded->v[idx]->a = elementAccessor; + self->expanded_->v[idx]->a = elementAccessor; break; case 9: - set_creator_name(&creator, self->expanded->v[idx]->code); + set_creator_name(&creator, self->expanded_->v[idx]->code); elementAccessor = grib_accessor_factory(section, &creator, 0, NULL); accessor_bufr_data_element_set_index(elementAccessor, ide); - accessor_bufr_data_element_set_descriptors(elementAccessor, self->expanded); - accessor_bufr_data_element_set_elementsDescriptorsIndex(elementAccessor, self->elementsDescriptorsIndex); - accessor_bufr_data_element_set_numericValues(elementAccessor, self->numericValues); - accessor_bufr_data_element_set_stringValues(elementAccessor, self->stringValues); - accessor_bufr_data_element_set_compressedData(elementAccessor, self->compressedData); - accessor_bufr_data_element_set_type(elementAccessor, self->expanded->v[idx]->type); - accessor_bufr_data_element_set_numberOfSubsets(elementAccessor, self->numberOfSubsets); + accessor_bufr_data_element_set_descriptors(elementAccessor, self->expanded_); + accessor_bufr_data_element_set_elementsDescriptorsIndex(elementAccessor, self->elementsDescriptorsIndex_); + accessor_bufr_data_element_set_numericValues(elementAccessor, self->numericValues_); + accessor_bufr_data_element_set_stringValues(elementAccessor, self->stringValues_); + accessor_bufr_data_element_set_compressedData(elementAccessor, self->compressedData_); + accessor_bufr_data_element_set_type(elementAccessor, self->expanded_->v[idx]->type); + accessor_bufr_data_element_set_numberOfSubsets(elementAccessor, self->numberOfSubsets_); accessor_bufr_data_element_set_subsetNumber(elementAccessor, subset); attribute = create_attribute_variable("index", section, GRIB_TYPE_LONG, 0, 0, count, flags); @@ -1912,29 +1944,29 @@ static grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, gr return NULL; elementAccessor->add_attribute(attribute, 0); - snprintf(code, sizeof(code), "%06ld", self->expanded->v[idx]->code); + snprintf(code, sizeof(code), "%06ld", self->expanded_->v[idx]->code); attribute = create_attribute_variable("code", section, GRIB_TYPE_STRING, code, 0, 0, flags); if (!attribute) return NULL; elementAccessor->add_attribute(attribute, 0); if (add_extra_attributes) { - attribute = create_attribute_variable("units", section, GRIB_TYPE_STRING, self->expanded->v[idx]->units, 0, 0, GRIB_ACCESSOR_FLAG_DUMP); + attribute = create_attribute_variable("units", section, GRIB_TYPE_STRING, self->expanded_->v[idx]->units, 0, 0, GRIB_ACCESSOR_FLAG_DUMP); if (!attribute) return NULL; elementAccessor->add_attribute(attribute, 0); - attribute = create_attribute_variable("scale", section, GRIB_TYPE_LONG, 0, 0, self->expanded->v[idx]->scale, flags); + attribute = create_attribute_variable("scale", section, GRIB_TYPE_LONG, 0, 0, self->expanded_->v[idx]->scale, flags); if (!attribute) return NULL; elementAccessor->add_attribute(attribute, 0); - attribute = create_attribute_variable("reference", section, GRIB_TYPE_DOUBLE, 0, self->expanded->v[idx]->reference, 0, flags); + attribute = create_attribute_variable("reference", section, GRIB_TYPE_DOUBLE, 0, self->expanded_->v[idx]->reference, 0, flags); if (!attribute) return NULL; elementAccessor->add_attribute(attribute, 0); - attribute = create_attribute_variable("width", section, GRIB_TYPE_LONG, 0, 0, self->expanded->v[idx]->width, flags); + attribute = create_attribute_variable("width", section, GRIB_TYPE_LONG, 0, 0, self->expanded_->v[idx]->width, flags); if (!attribute) return NULL; elementAccessor->add_attribute(attribute, 0); @@ -1946,12 +1978,12 @@ static grib_accessor* create_accessor_from_descriptor(const grib_accessor* a, gr } /* Section 3.1.2.2 of WMO BUFR guide: classes 03 and 09 at present reserved for future use */ -#define IS_COORDINATE_DESCRIPTOR(a) (a == 8 || a == 1 || a == 2 || a == 4 || a == 5 || a == 6 || a == 7) +#define IS_COORDINATE_DESCRIPTOR(a) (a == 8 || a == 1 || a == 2 || a == 4 || a == 5 || a == 6 || a == 7) #define NUMBER_OF_QUALIFIERS_PER_CATEGORY 256 -#define NUMBER_OF_QUALIFIERS_CATEGORIES 7 -#define MAX_NUMBER_OF_BITMAPS 8 // See ECC-1699 +#define NUMBER_OF_QUALIFIERS_CATEGORIES 7 +#define MAX_NUMBER_OF_BITMAPS 8 // See ECC-1699 -static const int number_of_qualifiers = NUMBER_OF_QUALIFIERS_PER_CATEGORY * NUMBER_OF_QUALIFIERS_CATEGORIES; +static const int number_of_qualifiers = NUMBER_OF_QUALIFIERS_PER_CATEGORY * NUMBER_OF_QUALIFIERS_CATEGORIES; static const int significanceQualifierIndexArray[] = { -1, 0, 1, -1, 2, 3, 4, 5, 6 }; static GRIB_INLINE void reset_deeper_qualifiers( @@ -1983,7 +2015,8 @@ static grib_accessor* get_element_from_bitmap(const grib_accessor* a, bitmap_s* while (bitmapVal) { len = 1; if (bitmap->cursor && bitmap->cursor->accessor) { - ret = bitmap->cursor->accessor->unpack_long(&bitmapVal, &len); } + ret = bitmap->cursor->accessor->unpack_long(&bitmapVal, &len); + } else { return NULL; } @@ -2006,19 +2039,19 @@ static grib_accessor* get_element_from_bitmap(const grib_accessor* a, bitmap_s* static void grib_convert_to_attribute(grib_accessor* a) { - if (a->h == NULL && a->parent != NULL) { - a->h = grib_handle_of_accessor(a); - a->parent = NULL; + if (a->h_ == NULL && a->parent_ != NULL) { + a->h_ = grib_handle_of_accessor(a); + a->parent_ = NULL; } } /* subsetList can be NULL in which case subsetListSize will be 0 */ static grib_iarray* set_subset_list( - grib_context* c, grib_accessor_bufr_data_array_t* self, - long onlySubset, long startSubset, long endSubset, const long* subsetList, size_t subsetListSize) + grib_context* c, grib_accessor_bufr_data_array_t* self, + long onlySubset, long startSubset, long endSubset, const long* subsetList, size_t subsetListSize) { - grib_iarray* list = grib_iarray_new(c, self->numberOfSubsets, 10); - long s = 0; + grib_iarray* list = grib_iarray_new(c, self->numberOfSubsets_, 10); + long s = 0; #ifdef DEBUG if (subsetList == NULL) { @@ -2045,7 +2078,7 @@ static grib_iarray* set_subset_list( } if (grib_iarray_used_size(list) == 0) { - for (s = 0; s < self->numberOfSubsets; s++) + for (s = 0; s < self->numberOfSubsets_; s++) grib_iarray_push(list, s); } @@ -2064,7 +2097,8 @@ static int bitmap_ref_skip(grib_accessors_list* al, int* err) acode = al->accessor->get_attribute("code"); if (acode) - *err = acode->unpack_long(code, &l); else + *err = acode->unpack_long(code, &l); + else return 1; switch (code[0]) { @@ -2109,9 +2143,9 @@ static int is_bitmap_start_descriptor(grib_accessors_list* al, int* err) case 237000: /*case 243000:*/ { - //long index[1]; - //grib_accessor* anindex=grib_accessor_get_attribute(al->accessor,"index"); - //anindex->unpack_long(index,&l); + // long index[1]; + // grib_accessor* anindex=grib_accessor_get_attribute(al->accessor,"index"); + // anindex->unpack_long(index,&l); return 1; } } @@ -2138,7 +2172,7 @@ static void print_bitmap_debug_info(grib_context* c, bitmap_s* bitmap, grib_acce for (i = 1; i < bitmapSize; i++) { if (bitmap->referredElement) { - fprintf(stderr, "ECCODES DEBUG:\t bitmap_init: i=%d |%s|\n", i, bitmap->referredElement->accessor->name); + fprintf(stderr, "ECCODES DEBUG:\t bitmap_init: i=%d |%s|\n", i, bitmap->referredElement->accessor->name_); bitmap->referredElement = bitmap->referredElement->prev_; } } @@ -2200,25 +2234,25 @@ static grib_accessor* accessor_or_attribute_with_same_name(grib_accessor* a, con // static int get_key_rank(grib_trie* accessorsRank,grib_accessor* a) // { -// int* r=(int*)grib_trie_get(accessorsRank,a->name); +// int* r=(int*)grib_trie_get(accessorsRank,name_ ); // if (r) (*r)++; // else { -// r=(int*)grib_context_malloc(a->context,sizeof(int)); +// r=(int*)grib_context_malloc(context_ ,sizeof(int)); // *r=1; -// grib_trie_insert(accessorsRank,a->name,(void*)r); +// grib_trie_insert(accessorsRank,name_ ,(void*)r); // } // return *r; // } static int grib_data_accessors_trie_push(grib_trie_with_rank* accessorsTrie, grib_accessor* a) { - return grib_trie_with_rank_insert(accessorsTrie, a->name, a); + return grib_trie_with_rank_insert(accessorsTrie, a->name_, a); } static int create_keys(const grib_accessor* a, long onlySubset, long startSubset, long endSubset) { grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - int err = 0; + int err = 0; int rank; grib_accessor* elementAccessor = 0; grib_accessor* associatedFieldAccessor = 0; @@ -2234,26 +2268,42 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset int depth; int max_depth = -1; /* highest value of depth */ int idx; - grib_context* c = a->context; + grib_context* c = a->context_; int qualityPresent = 0; - bitmap_s bitmap = {0,}; + bitmap_s bitmap = { + 0, + }; int extraElement = 0; int add_extra_attributes = 1; grib_accessor* gaGroup = 0; - grib_action creatorGroup = {0,}; - grib_accessor* significanceQualifierGroup[NUMBER_OF_QUALIFIERS_PER_CATEGORY * NUMBER_OF_QUALIFIERS_CATEGORIES] = {0,}; - int significanceQualifierDepth[NUMBER_OF_QUALIFIERS_PER_CATEGORY * NUMBER_OF_QUALIFIERS_CATEGORIES] = {0,}; + grib_action creatorGroup = { + 0, + }; + grib_accessor* significanceQualifierGroup[NUMBER_OF_QUALIFIERS_PER_CATEGORY * NUMBER_OF_QUALIFIERS_CATEGORIES] = { + 0, + }; + int significanceQualifierDepth[NUMBER_OF_QUALIFIERS_PER_CATEGORY * NUMBER_OF_QUALIFIERS_CATEGORIES] = { + 0, + }; - grib_accessor* bitmapGroup[MAX_NUMBER_OF_BITMAPS] = {0,}; - int bitmapDepth[MAX_NUMBER_OF_BITMAPS] = {0,}; - int bitmapSize[MAX_NUMBER_OF_BITMAPS] = {0,}; - grib_accessors_list* bitmapStart[MAX_NUMBER_OF_BITMAPS] = {0,}; + grib_accessor* bitmapGroup[MAX_NUMBER_OF_BITMAPS] = { + 0, + }; + int bitmapDepth[MAX_NUMBER_OF_BITMAPS] = { + 0, + }; + int bitmapSize[MAX_NUMBER_OF_BITMAPS] = { + 0, + }; + grib_accessors_list* bitmapStart[MAX_NUMBER_OF_BITMAPS] = { + 0, + }; grib_accessors_list* lastAccessorInList = NULL; int bitmapIndex = -1; int incrementBitmapIndex = 1; grib_accessor* elementFromBitmap = NULL; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(a); /*int reuseBitmap=0;*/ int add_dump_flag = 1, add_coord_flag = 0, count = 0; /*int forceGroupClosure=0;*/ @@ -2264,40 +2314,40 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset creatorGroup.flags = GRIB_ACCESSOR_FLAG_DUMP; creatorGroup.set = 0; - if (self->dataAccessors) { - grib_accessors_list_delete(c, self->dataAccessors); + if (self->dataAccessors_) { + grib_accessors_list_delete(c, self->dataAccessors_); } - self->dataAccessors = grib_accessors_list_create(c); + self->dataAccessors_ = grib_accessors_list_create(c); - if (self->dataAccessorsTrie) { + if (self->dataAccessorsTrie_) { /* ECC-989: do not call grib_trie_with_rank_delete */ - grib_trie_with_rank_delete_container(self->dataAccessorsTrie); + grib_trie_with_rank_delete_container(self->dataAccessorsTrie_); } - self->dataAccessorsTrie = grib_trie_with_rank_new(c); + self->dataAccessorsTrie_ = grib_trie_with_rank_new(c); - if (self->tempStrings) { - grib_sarray_delete_content(c, self->tempStrings); - grib_sarray_delete(c, self->tempStrings); - self->tempStrings = NULL; + if (self->tempStrings_) { + grib_sarray_delete_content(c, self->tempStrings_); + grib_sarray_delete(c, self->tempStrings_); + self->tempStrings_ = NULL; } - self->tempStrings = self->numberOfSubsets? grib_sarray_new(c, self->numberOfSubsets, 500) : NULL; + self->tempStrings_ = self->numberOfSubsets_ ? grib_sarray_new(c, self->numberOfSubsets_, 500) : NULL; - end = self->compressedData ? 1 : self->numberOfSubsets; + end = self->compressedData_ ? 1 : self->numberOfSubsets_; // groupNumber = 1; - gaGroup = grib_accessor_factory(self->dataKeys, &creatorGroup, 0, NULL); - //gaGroup->bufr_group_number = groupNumber; - gaGroup->sub_section = grib_section_create(hand, gaGroup); - section = gaGroup->sub_section; + gaGroup = grib_accessor_factory(self->dataKeys_, &creatorGroup, 0, NULL); + // gaGroup->bufr_group_number = groupNumber; + gaGroup->sub_section_ = grib_section_create(hand, gaGroup); + section = gaGroup->sub_section_; /*rootSection=section;*/ - /*sectionUp=self->dataKeys;*/ - //accessor_constant_set_type(gaGroup, GRIB_TYPE_LONG); - //accessor_constant_set_dval(gaGroup, groupNumber); + /*sectionUp=self->dataKeys_;*/ + // accessor_constant_set_type(gaGroup, GRIB_TYPE_LONG); + // accessor_constant_set_dval(gaGroup, groupNumber); /* ECC-765: Don't empty out the section_4 keys otherwise there will be memory leaks. */ /* Setting first and last to zero effectively masks out those section 4 keys! */ - /* self->dataKeys->block->first=0; */ - /* self->dataKeys->block->last=0; */ - grib_push_accessor(gaGroup, self->dataKeys->block); /* Add group accessors to section 4 */ + /* self->dataKeys_->block->first=0; */ + /* self->dataKeys_->block->last=0; */ + grib_push_accessor(gaGroup, self->dataKeys_->block); /* Add group accessors to section 4 */ /*indexOfGroupNumber=0;*/ depth = 0; @@ -2307,7 +2357,7 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset for (iss = 0; iss < end; iss++) { qualityPresent = 0; /*forceGroupClosure=0;*/ - elementsInSubset = self->compressedData ? grib_iarray_used_size(self->elementsDescriptorsIndex->v[0]) : grib_iarray_used_size(self->elementsDescriptorsIndex->v[iss]); + elementsInSubset = self->compressedData_ ? grib_iarray_used_size(self->elementsDescriptorsIndex_->v[0]) : grib_iarray_used_size(self->elementsDescriptorsIndex_->v[iss]); /*if (associatedFieldAccessor) grib_accessor_delete(c, associatedFieldAccessor);*/ associatedFieldAccessor = NULL; if (associatedFieldSignificanceAccessor) { @@ -2315,23 +2365,23 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset associatedFieldSignificanceAccessor = NULL; } for (ide = 0; ide < elementsInSubset; ide++) { - idx = self->compressedData ? self->elementsDescriptorsIndex->v[0]->v[ide] : self->elementsDescriptorsIndex->v[iss]->v[ide]; + idx = self->compressedData_ ? self->elementsDescriptorsIndex_->v[0]->v[ide] : self->elementsDescriptorsIndex_->v[iss]->v[ide]; - descriptor = self->expanded->v[idx]; + descriptor = self->expanded_->v[idx]; if (descriptor->nokey == 1) { continue; /* Descriptor does not have an associated key e.g. inside op 203YYY */ } elementFromBitmap = NULL; - add_coord_flag = 0; + add_coord_flag = 0; if (descriptor->F == 0 && IS_COORDINATE_DESCRIPTOR(descriptor->X) && - self->unpackMode == CODES_BUFR_UNPACK_STRUCTURE) { + self->unpackMode_ == CODES_BUFR_UNPACK_STRUCTURE) { const int sidx = descriptor->Y + significanceQualifierIndexArray[descriptor->X] * NUMBER_OF_QUALIFIERS_PER_CATEGORY; DEBUG_ASSERT(sidx > 0); // groupNumber++; add_coord_flag = 1; if (significanceQualifierGroup[sidx]) { - groupSection = significanceQualifierGroup[sidx]->parent; + groupSection = significanceQualifierGroup[sidx]->parent_; depth = significanceQualifierDepth[sidx]; if (depth < max_depth) { /* If depth >= max_depth, then no entry will be deeper so no need for call */ @@ -2350,15 +2400,15 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset /* } */ } - gaGroup = grib_accessor_factory(groupSection, &creatorGroup, 0, NULL); - gaGroup->sub_section = grib_section_create(hand, gaGroup); - //gaGroup->bufr_group_number = groupNumber; + gaGroup = grib_accessor_factory(groupSection, &creatorGroup, 0, NULL); + gaGroup->sub_section_ = grib_section_create(hand, gaGroup); + // gaGroup->bufr_group_number = groupNumber; - //accessor_constant_set_type(gaGroup, GRIB_TYPE_LONG); - //accessor_constant_set_dval(gaGroup, groupNumber); + // accessor_constant_set_type(gaGroup, GRIB_TYPE_LONG); + // accessor_constant_set_dval(gaGroup, groupNumber); grib_push_accessor(gaGroup, groupSection->block); - section = gaGroup->sub_section; + section = gaGroup->sub_section_; /*sectionUp=gaGroup->parent;*/ significanceQualifierGroup[sidx] = gaGroup; @@ -2374,18 +2424,18 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset // groupNumber++; incrementBitmapIndex = 0; if (bitmapIndex >= MAX_NUMBER_OF_BITMAPS) { - //grib_context_log(c, GRIB_LOG_ERROR, "Bitmap error: bitmap index=%d, max num bitmaps=%d\n", bitmapIndex, MAX_NUMBER_OF_BITMAPS); - //err = GRIB_DECODING_ERROR; - //return err; + // grib_context_log(c, GRIB_LOG_ERROR, "Bitmap error: bitmap index=%d, max num bitmaps=%d\n", bitmapIndex, MAX_NUMBER_OF_BITMAPS); + // err = GRIB_DECODING_ERROR; + // return err; bitmapIndex--; } - bitmapStart[bitmapIndex] = self->dataAccessors->last(); + bitmapStart[bitmapIndex] = self->dataAccessors_->last(); bitmapSize[bitmapIndex] = 1; - if (self->expanded->v[idx - 1]->code == 31002 || self->expanded->v[idx - 1]->code == 31001) + if (self->expanded_->v[idx - 1]->code == 31002 || self->expanded_->v[idx - 1]->code == 31001) extraElement += 1; if (bitmapGroup[bitmapIndex]) { - groupSection = bitmapGroup[bitmapIndex]->parent; + groupSection = bitmapGroup[bitmapIndex]->parent_; depth = bitmapDepth[bitmapIndex]; reset_deeper_qualifiers(significanceQualifierGroup, significanceQualifierDepth, number_of_qualifiers, depth); @@ -2396,14 +2446,14 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset groupSection = section; depth++; } - gaGroup = grib_accessor_factory(groupSection, &creatorGroup, 0, NULL); - gaGroup->sub_section = grib_section_create(hand, gaGroup); + gaGroup = grib_accessor_factory(groupSection, &creatorGroup, 0, NULL); + gaGroup->sub_section_ = grib_section_create(hand, gaGroup); // gaGroup->bufr_group_number = groupNumber; - //accessor_constant_set_type(gaGroup, GRIB_TYPE_LONG); - //accessor_constant_set_dval(gaGroup, groupNumber); + // accessor_constant_set_type(gaGroup, GRIB_TYPE_LONG); + // accessor_constant_set_dval(gaGroup, groupNumber); grib_push_accessor(gaGroup, groupSection->block); - section = gaGroup->sub_section; + section = gaGroup->sub_section_; /*sectionUp=gaGroup->parent;*/ bitmapGroup[bitmapIndex] = gaGroup; bitmapDepth[bitmapIndex] = depth; @@ -2440,7 +2490,7 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset bitmap_init(c, &bitmap, bitmapStart[bitmapIndex], bitmapSize[bitmapIndex], lastAccessorInList); elementFromBitmap = get_element_from_bitmap(a, &bitmap); add_dump_flag = 1; - /* } else if ( descriptor->Y==1 && IS_COORDINATE_DESCRIPTOR(self->expanded->v[idx-1]->X)==0) { */ + /* } else if ( descriptor->Y==1 && IS_COORDINATE_DESCRIPTOR(self->expanded_ ->v[idx-1]->X)==0) { */ /* forceGroupClosure=1; */ /* reset_qualifiers(significanceQualifierGroup); */ } @@ -2448,11 +2498,13 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset add_dump_flag = 1; /* ECC-690: percentConfidence WITHOUT a bitmap! e.g. NOAA GOES16 BUFR */ } - if (ide == 0 && !self->compressedData) { + if (ide == 0 && !self->compressedData_) { grib_accessor* asn = NULL; long subsetNumber = iss + 1; size_t len = 1; - grib_action creatorsn = {0,}; + grib_action creatorsn = { + 0, + }; creatorsn.op = (char*)"variable"; creatorsn.name_space = (char*)""; creatorsn.flags = GRIB_ACCESSOR_FLAG_READ_ONLY | GRIB_ACCESSOR_FLAG_DUMP; @@ -2463,8 +2515,8 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset accessor_variable_set_type(asn, GRIB_TYPE_LONG); asn->pack_long(&subsetNumber, &len); grib_push_accessor(asn, section->block); - rank = grib_data_accessors_trie_push(self->dataAccessorsTrie, asn); - self->dataAccessors->push(asn, rank); + rank = grib_data_accessors_trie_push(self->dataAccessorsTrie_, asn); + self->dataAccessors_->push(asn, rank); } count++; elementAccessor = create_accessor_from_descriptor(a, associatedFieldAccessor, section, ide, iss, @@ -2473,26 +2525,26 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset err = GRIB_DECODING_ERROR; return err; } - if (elementAccessor->name == NULL) { + if (elementAccessor->name_ == NULL) { return GRIB_DECODING_ERROR; } /*if (associatedFieldAccessor) grib_accessor_delete(c, associatedFieldAccessor);*/ associatedFieldAccessor = NULL; - if (elementFromBitmap && self->unpackMode == CODES_BUFR_UNPACK_STRUCTURE) { + if (elementFromBitmap && self->unpackMode_ == CODES_BUFR_UNPACK_STRUCTURE) { if (descriptor->code != 33007 && descriptor->code != 223255) { - char* aname = grib_context_strdup(c, elementFromBitmap->name); + char* aname = grib_context_strdup(c, elementFromBitmap->name_); grib_accessor* newAccessor = elementAccessor->clone(section, &err); - newAccessor->parent = groupSection; - newAccessor->name = aname; - grib_sarray_push(a->context, self->tempStrings, aname); + newAccessor->parent_ = groupSection; + newAccessor->name_ = aname; + grib_sarray_push(a->context_, self->tempStrings_, aname); grib_push_accessor(newAccessor, groupSection->block); - rank = grib_data_accessors_trie_push(self->dataAccessorsTrie, newAccessor); - self->dataAccessors->push(newAccessor, rank); + rank = grib_data_accessors_trie_push(self->dataAccessorsTrie_, newAccessor); + self->dataAccessors_->push(newAccessor, rank); } - //err = grib_accessor_add_attribute(accessor_or_attribute_with_same_name(elementFromBitmap, elementAccessor->name), elementAccessor, 1); - err = accessor_or_attribute_with_same_name(elementFromBitmap, elementAccessor->name)->add_attribute( elementAccessor, 1); + // err = grib_accessor_add_attribute(accessor_or_attribute_with_same_name(elementFromBitmap, elementAccessor->name), elementAccessor, 1); + err = accessor_or_attribute_with_same_name(elementFromBitmap, elementAccessor->name_)->add_attribute(elementAccessor, 1); } else if (elementAccessor) { int add_key = 1; @@ -2504,7 +2556,7 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset if (associatedFieldSignificanceAccessor) { grib_accessor* newAccessor = associatedFieldSignificanceAccessor->clone(section, &err); if (err) { - grib_context_log(a->context, GRIB_LOG_ERROR,"Unable to clone accessor '%s'\n", associatedFieldSignificanceAccessor->name); + grib_context_log(a->context_, GRIB_LOG_ERROR, "Unable to clone accessor '%s'\n", associatedFieldSignificanceAccessor->name_); return err; } associatedFieldAccessor->add_attribute(newAccessor, 1); @@ -2529,9 +2581,9 @@ static int create_keys(const grib_accessor* a, long onlySubset, long startSubset } if (add_key) { grib_push_accessor(elementAccessor, section->block); - rank = grib_data_accessors_trie_push(self->dataAccessorsTrie, elementAccessor); - self->dataAccessors->push(elementAccessor, rank); - lastAccessorInList = self->dataAccessors->last(); + rank = grib_data_accessors_trie_push(self->dataAccessorsTrie_, elementAccessor); + self->dataAccessors_->push(elementAccessor, rank); + lastAccessorInList = self->dataAccessors_->last(); } } } @@ -2546,62 +2598,62 @@ static void set_input_replications(grib_handle* h, grib_accessor_bufr_data_array size_t nInputReplications; size_t nInputExtendedReplications; size_t nInputShortReplications; - self->nInputReplications = -1; - self->nInputExtendedReplications = -1; - self->nInputShortReplications = -1; - self->iInputReplications = 0; - self->iInputExtendedReplications = 0; - self->iInputShortReplications = 0; + self->nInputReplications_ = -1; + self->nInputExtendedReplications_ = -1; + self->nInputShortReplications_ = -1; + self->iInputReplications_ = 0; + self->iInputExtendedReplications_ = 0; + self->iInputShortReplications_ = 0; if (grib_get_size(h, "inputDelayedDescriptorReplicationFactor", &nInputReplications) == 0 && nInputReplications != 0) { - if (self->inputReplications) - grib_context_free(h->context, self->inputReplications); - self->inputReplications = (long*)grib_context_malloc_clear(h->context, sizeof(long) * nInputReplications); - grib_get_long_array(h, "inputDelayedDescriptorReplicationFactor", self->inputReplications, &nInputReplications); + if (self->inputReplications_) + grib_context_free(h->context, self->inputReplications_); + self->inputReplications_ = (long*)grib_context_malloc_clear(h->context, sizeof(long) * nInputReplications); + grib_get_long_array(h, "inputDelayedDescriptorReplicationFactor", self->inputReplications_, &nInputReplications); /* default-> no input replications*/ - if (self->inputReplications[0] < 0) - self->nInputReplications = -1; + if (self->inputReplications_[0] < 0) + self->nInputReplications_ = -1; else - self->nInputReplications = nInputReplications; + self->nInputReplications_ = nInputReplications; } if (grib_get_size(h, "inputExtendedDelayedDescriptorReplicationFactor", &nInputExtendedReplications) == 0 && nInputExtendedReplications != 0) { - if (self->inputExtendedReplications) - grib_context_free(h->context, self->inputExtendedReplications); - self->inputExtendedReplications = (long*)grib_context_malloc_clear(h->context, sizeof(long) * nInputExtendedReplications); - grib_get_long_array(h, "inputExtendedDelayedDescriptorReplicationFactor", self->inputExtendedReplications, &nInputExtendedReplications); + if (self->inputExtendedReplications_) + grib_context_free(h->context, self->inputExtendedReplications_); + self->inputExtendedReplications_ = (long*)grib_context_malloc_clear(h->context, sizeof(long) * nInputExtendedReplications); + grib_get_long_array(h, "inputExtendedDelayedDescriptorReplicationFactor", self->inputExtendedReplications_, &nInputExtendedReplications); /* default-> no input replications*/ - if (self->inputExtendedReplications[0] < 0) - self->nInputExtendedReplications = -1; + if (self->inputExtendedReplications_[0] < 0) + self->nInputExtendedReplications_ = -1; else - self->nInputExtendedReplications = nInputExtendedReplications; + self->nInputExtendedReplications_ = nInputExtendedReplications; } if (grib_get_size(h, "inputShortDelayedDescriptorReplicationFactor", &nInputShortReplications) == 0 && nInputShortReplications != 0) { - if (self->inputShortReplications) - grib_context_free(h->context, self->inputShortReplications); - self->inputShortReplications = (long*)grib_context_malloc_clear(h->context, sizeof(long) * nInputShortReplications); - grib_get_long_array(h, "inputShortDelayedDescriptorReplicationFactor", self->inputShortReplications, &nInputShortReplications); + if (self->inputShortReplications_) + grib_context_free(h->context, self->inputShortReplications_); + self->inputShortReplications_ = (long*)grib_context_malloc_clear(h->context, sizeof(long) * nInputShortReplications); + grib_get_long_array(h, "inputShortDelayedDescriptorReplicationFactor", self->inputShortReplications_, &nInputShortReplications); /* default-> no input replications*/ - if (self->inputShortReplications[0] < 0) - self->nInputShortReplications = -1; + if (self->inputShortReplications_[0] < 0) + self->nInputShortReplications_ = -1; else - self->nInputShortReplications = nInputShortReplications; + self->nInputShortReplications_ = nInputShortReplications; } } static void set_input_bitmap(grib_handle* h, grib_accessor_bufr_data_array_t* self) { size_t nInputBitmap; - self->nInputBitmap = -1; - self->iInputBitmap = 0; + self->nInputBitmap_ = -1; + self->iInputBitmap_ = 0; if (grib_get_size(h, "inputDataPresentIndicator", &nInputBitmap) == 0 && nInputBitmap != 0) { - if (self->inputBitmap) - grib_context_free(h->context, self->inputBitmap); - self->inputBitmap = (double*)grib_context_malloc_clear(h->context, sizeof(double) * nInputBitmap); - grib_get_double_array(h, "inputDataPresentIndicator", self->inputBitmap, &nInputBitmap); + if (self->inputBitmap_) + grib_context_free(h->context, self->inputBitmap_); + self->inputBitmap_ = (double*)grib_context_malloc_clear(h->context, sizeof(double) * nInputBitmap); + grib_get_double_array(h, "inputDataPresentIndicator", self->inputBitmap_, &nInputBitmap); /* default-> no input bitmap*/ - if (self->inputBitmap[0] < 0) - self->nInputBitmap = -1; + if (self->inputBitmap_[0] < 0) + self->nInputBitmap_ = -1; else - self->nInputBitmap = nInputBitmap; + self->nInputBitmap_ = nInputBitmap; } } @@ -2619,13 +2671,24 @@ static int set_to_missing_if_out_of_range(grib_handle* h) static int process_elements(grib_accessor* a, int flag, long onlySubset, long startSubset, long endSubset) { - int err = 0; + grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; + int err = 0; long inr, innr, ir, ip; - long n[MAX_NESTED_REPLICATIONS] = {0,}; - long nn[MAX_NESTED_REPLICATIONS] = {0,}; - long numberOfElementsToRepeat[MAX_NESTED_REPLICATIONS] = {0,}; - long numberOfRepetitions[MAX_NESTED_REPLICATIONS] = {0,}; - long startRepetition[MAX_NESTED_REPLICATIONS] = {0,}; + long n[MAX_NESTED_REPLICATIONS] = { + 0, + }; + long nn[MAX_NESTED_REPLICATIONS] = { + 0, + }; + long numberOfElementsToRepeat[MAX_NESTED_REPLICATIONS] = { + 0, + }; + long numberOfRepetitions[MAX_NESTED_REPLICATIONS] = { + 0, + }; + long startRepetition[MAX_NESTED_REPLICATIONS] = { + 0, + }; long numberOfNestedRepetitions = 0; unsigned char* data = 0; size_t subsetListSize = 0; @@ -2646,24 +2709,23 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st grib_accessor* dataAccessor = NULL; bufr_descriptor* bd = 0; - grib_darray* dval = NULL; - grib_sarray* sval = NULL; - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; + grib_darray* dval = NULL; + grib_sarray* sval = NULL; grib_handle* h = grib_handle_of_accessor(a); grib_context* c = h->context; - totalSize = self->bitsToEndData; + totalSize = self->bitsToEndData_; switch (flag) { case PROCESS_DECODE: - if (!self->do_decode) + if (!self->do_decode_) return 0; - self->do_decode = 0; - buffer = h->buffer; - decoding = 1; - do_clean = 1; - dataAccessor = grib_find_accessor(grib_handle_of_accessor(a), self->bufrDataEncodedName); + self->do_decode_ = 0; + buffer = h->buffer; + decoding = 1; + do_clean = 1; + dataAccessor = grib_find_accessor(grib_handle_of_accessor(a), self->bufrDataEncodedName_); DEBUG_ASSERT(dataAccessor); dataOffset = accessor_raw_get_offset(dataAccessor); pos = dataOffset * 8; @@ -2671,27 +2733,27 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st codec_replication = &decode_replication; break; case PROCESS_NEW_DATA: - buffer = grib_create_growable_buffer(c); - decoding = 0; - do_clean = 1; - self->do_decode = 1; - self->set_to_missing_if_out_of_range = set_to_missing_if_out_of_range(h); - pos = 0; - codec_element = &encode_new_element; - codec_replication = &encode_new_replication; + buffer = grib_create_growable_buffer(c); + decoding = 0; + do_clean = 1; + self->do_decode_ = 1; + self->set_to_missing_if_out_of_range_ = set_to_missing_if_out_of_range(h); + pos = 0; + codec_element = &encode_new_element; + codec_replication = &encode_new_replication; set_input_replications(h, self); set_input_bitmap(h, self); break; case PROCESS_ENCODE: - buffer = grib_create_growable_buffer(c); - decoding = 0; - do_clean = 0; - self->do_decode = 0; - self->set_to_missing_if_out_of_range = set_to_missing_if_out_of_range(h); - pos = 0; - codec_element = &encode_element; + buffer = grib_create_growable_buffer(c); + decoding = 0; + do_clean = 0; + self->do_decode_ = 0; + self->set_to_missing_if_out_of_range_ = set_to_missing_if_out_of_range(h); + pos = 0; + codec_element = &encode_element; grib_get_long(grib_handle_of_accessor(a), "extractSubset", &onlySubset); grib_get_long(grib_handle_of_accessor(a), "extractSubsetIntervalStart", &startSubset); grib_get_long(grib_handle_of_accessor(a), "extractSubsetIntervalEnd", &endSubset); @@ -2715,85 +2777,85 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st err = get_descriptors(a); if (err) return err; - descriptors = self->expanded->v; + descriptors = self->expanded_->v; if (!descriptors) { grib_context_log(c, GRIB_LOG_ERROR, "No descriptors found!"); return GRIB_INTERNAL_ERROR; } - if (do_clean == 1 && self->numericValues) { - grib_vdarray_delete_content(c, self->numericValues); - grib_vdarray_delete(c, self->numericValues); - /*printf("dbg process_elements: clear %p\n", (void*)(self->stringValues));*/ - grib_vsarray_delete_content(c, self->stringValues); - grib_vsarray_delete(c, self->stringValues); - self->stringValues = NULL; + if (do_clean == 1 && self->numericValues_) { + grib_vdarray_delete_content(c, self->numericValues_); + grib_vdarray_delete(c, self->numericValues_); + /*printf("dbg process_elements: clear %p\n", (void*)(self->stringValues_ ));*/ + grib_vsarray_delete_content(c, self->stringValues_); + grib_vsarray_delete(c, self->stringValues_); + self->stringValues_ = NULL; } if (flag != PROCESS_ENCODE) { - self->numericValues = grib_vdarray_new(c, 1000, 1000); - self->stringValues = grib_vsarray_new(c, 10, 10); + self->numericValues_ = grib_vdarray_new(c, 1000, 1000); + self->stringValues_ = grib_vsarray_new(c, 10, 10); - if (self->elementsDescriptorsIndex) { - grib_viarray_delete_content(c, self->elementsDescriptorsIndex); - grib_viarray_delete(c, self->elementsDescriptorsIndex); + if (self->elementsDescriptorsIndex_) { + grib_viarray_delete_content(c, self->elementsDescriptorsIndex_); + grib_viarray_delete(c, self->elementsDescriptorsIndex_); } - self->elementsDescriptorsIndex = grib_viarray_new(c, 100, 100); + self->elementsDescriptorsIndex_ = grib_viarray_new(c, 100, 100); } if (flag == PROCESS_NEW_DATA) { - self->tempDoubleValues = grib_vdarray_new(c, 1000, 1000); + self->tempDoubleValues_ = grib_vdarray_new(c, 1000, 1000); } if (flag != PROCESS_DECODE) { /* Operator 203YYY: key OVERRIDDEN_REFERENCE_VALUES_KEY */ - err = grib_get_size(h, OVERRIDDEN_REFERENCE_VALUES_KEY, &self->refValListSize); + err = grib_get_size(h, OVERRIDDEN_REFERENCE_VALUES_KEY, &self->refValListSize_); if (err) return err; - if (self->refValList) - grib_context_free(c, self->refValList); - if (self->refValListSize > 0) { - self->refValList = (long*)grib_context_malloc_clear(c, self->refValListSize * sizeof(long)); - err = grib_get_long_array(grib_handle_of_accessor(a), OVERRIDDEN_REFERENCE_VALUES_KEY, self->refValList, &self->refValListSize); + if (self->refValList_) + grib_context_free(c, self->refValList_); + if (self->refValListSize_ > 0) { + self->refValList_ = (long*)grib_context_malloc_clear(c, self->refValListSize_ * sizeof(long)); + err = grib_get_long_array(grib_handle_of_accessor(a), OVERRIDDEN_REFERENCE_VALUES_KEY, self->refValList_, &self->refValListSize_); if (err) return err; } } - numberOfDescriptors = grib_bufr_descriptors_array_used_size(self->expanded); + numberOfDescriptors = grib_bufr_descriptors_array_used_size(self->expanded_); - if (self->iss_list) { - grib_iarray_delete(self->iss_list); - self->iss_list = 0; + if (self->iss_list_) { + grib_iarray_delete(self->iss_list_); + self->iss_list_ = 0; } - end = self->compressedData == 1 ? 1 : self->numberOfSubsets; + end = self->compressedData_ == 1 ? 1 : self->numberOfSubsets_; if (flag != PROCESS_DECODE) { - self->iss_list = set_subset_list(c, self, onlySubset, startSubset, endSubset, subsetList, subsetListSize); - end = self->compressedData == 1 ? 1 : grib_iarray_used_size(self->iss_list); + self->iss_list_ = set_subset_list(c, self, onlySubset, startSubset, endSubset, subsetList, subsetListSize); + end = self->compressedData_ == 1 ? 1 : grib_iarray_used_size(self->iss_list_); } /* Go through all subsets */ for (iiss = 0; iiss < end; iiss++) { icount = 1; - if (self->compressedData == 0 && self->iss_list) { - iss = self->iss_list->v[iiss]; + if (self->compressedData_ == 0 && self->iss_list_) { + iss = self->iss_list_->v[iiss]; } else { iss = iiss; } grib_context_log(c, GRIB_LOG_DEBUG, "BUFR data processing: subsetNumber=%ld", iss + 1); - self->refValIndex = 0; + self->refValIndex_ = 0; if (flag != PROCESS_ENCODE) { elementsDescriptorsIndex = grib_iarray_new(c, DYN_ARRAY_SIZE_INIT, DYN_ARRAY_SIZE_INCR); - if (!self->compressedData) { + if (!self->compressedData_) { dval = grib_darray_new(c, DYN_ARRAY_SIZE_INIT, DYN_ARRAY_SIZE_INCR); } } else { - if (self->elementsDescriptorsIndex == NULL) { + if (self->elementsDescriptorsIndex_ == NULL) { return GRIB_ENCODING_ERROR; /* See ECC-359 */ } - elementsDescriptorsIndex = self->elementsDescriptorsIndex->v[iss]; - dval = self->numericValues->v[iss]; + elementsDescriptorsIndex = self->elementsDescriptorsIndex_->v[iss]; + dval = self->numericValues_->v[iss]; } elementIndex = 0; @@ -2805,15 +2867,15 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st switch (descriptors[i]->F) { case 0: /* Table B element */ - op203_definition_phase = (self->change_ref_value_operand > 0 && self->change_ref_value_operand != 255); + op203_definition_phase = (self->change_ref_value_operand_ > 0 && self->change_ref_value_operand_ != 255); if (flag != PROCESS_ENCODE) { if (!op203_definition_phase) grib_iarray_push(elementsDescriptorsIndex, i); } if (descriptors[i]->code == 31031 && !is_bitmap_start_defined(self)) { - /* self->bitmapStart=grib_iarray_used_size(elementsDescriptorsIndex)-1; */ - self->bitmapStart = elementIndex; + /* self->bitmapStart_ =grib_iarray_used_size(elementsDescriptorsIndex)-1; */ + self->bitmapStart_ = elementIndex; } err = codec_element(c, self, iss, buffer, data, &pos, i, 0, elementIndex, dval, sval); @@ -2830,7 +2892,7 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st n[inr] = numberOfElementsToRepeat[inr]; i++; - data = buffer->data; /* ECC-517 */ + data = buffer->data; /* ECC-517 */ err = codec_replication(c, self, iss, buffer, data, &pos, i, elementIndex, dval, &(numberOfRepetitions[inr])); if (err) return err; @@ -2865,13 +2927,13 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st /* Operator */ switch (descriptors[i]->X) { case 3: /* Change reference values */ - if (self->compressedData == 1 && flag != PROCESS_DECODE) { + if (self->compressedData_ == 1 && flag != PROCESS_DECODE) { grib_context_log(c, GRIB_LOG_ERROR, "process_elements: operator %d not supported for encoding compressed data", descriptors[i]->X); return GRIB_INTERNAL_ERROR; } if (descriptors[i]->Y == 255) { grib_context_log(c, GRIB_LOG_DEBUG, "Operator 203YYY: Y=255, definition of new reference values is concluded"); - self->change_ref_value_operand = 255; + self->change_ref_value_operand_ = 255; /*if (c->debug) tableB_override_dump(self);*/ if (iss == 0 && flag == PROCESS_DECODE) { /*Write out the contents of the TableB overridden reference values to the transient array key*/ @@ -2880,11 +2942,11 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st } if (flag != PROCESS_DECODE) { /* Encoding operator 203YYY */ - if (self->refValIndex != self->refValListSize) { + if (self->refValIndex_ != self->refValListSize_) { grib_context_log(c, GRIB_LOG_ERROR, "process_elements: The number of overridden reference values (%ld) different from" " number of descriptors between operator 203YYY and 203255 (%ld)", - self->refValListSize, self->refValIndex); + self->refValListSize_, self->refValIndex_); return GRIB_ENCODING_ERROR; } } @@ -2892,15 +2954,15 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st else if (descriptors[i]->Y == 0) { grib_context_log(c, GRIB_LOG_DEBUG, "Operator 203YYY: Y=0, clearing override of table B"); tableB_override_clear(c, self); - self->change_ref_value_operand = 0; + self->change_ref_value_operand_ = 0; } else { const int numBits = descriptors[i]->Y; grib_context_log(c, GRIB_LOG_DEBUG, "Operator 203YYY: Definition phase: Num bits=%d", numBits); - self->change_ref_value_operand = numBits; + self->change_ref_value_operand_ = numBits; tableB_override_clear(c, self); if (flag != PROCESS_DECODE) { - err = check_overridden_reference_values(c, self->refValList, self->refValListSize, numBits); + err = check_overridden_reference_values(c, self->refValList_, self->refValListSize_, numBits); if (err) return err; } } @@ -2952,17 +3014,17 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st push_zero_element(self, dval); elementIndex++; break; - case 24: /* First-order statistical values marker operator */ - case 32: /* Replaced/retained values marker operator */ + case 24: /* First-order statistical values marker operator */ + case 32: /* Replaced/retained values marker operator */ if (descriptors[i]->Y == 255) { index = get_next_bitmap_descriptor_index(self, elementsDescriptorsIndex, dval); if (index < 0) { /* Return value is an error code not an index */ err = index; return err; } - err = codec_element(c, self, iss, buffer, data, &pos, index, 0, elementIndex, dval, sval); + err = codec_element(c, self, iss, buffer, data, &pos, index, 0, elementIndex, dval, sval); if (err) return err; - /* self->expanded->v[index] */ + /* self->expanded_ ->v[index] */ if (flag != PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex, i); elementIndex++; @@ -2976,16 +3038,16 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st elementIndex++; } break; - case 23: /* Substituted values operator */ + case 23: /* Substituted values operator */ if (descriptors[i]->Y == 255) { index = get_next_bitmap_descriptor_index(self, elementsDescriptorsIndex, dval); if (index < 0) { /* Return value is an error code not an index */ err = index; return err; } - err = codec_element(c, self, iss, buffer, data, &pos, index, 0, elementIndex, dval, sval); + err = codec_element(c, self, iss, buffer, data, &pos, index, 0, elementIndex, dval, sval); if (err) return err; - /* self->expanded->v[index] */ + /* self->expanded_ ->v[index] */ if (flag != PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex, i); elementIndex++; @@ -3013,21 +3075,21 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st elementIndex++; } break; - case 25: /* Difference statistical values marker operator */ + case 25: /* Difference statistical values marker operator */ if (descriptors[i]->Y == 255) { - index = get_next_bitmap_descriptor_index(self, elementsDescriptorsIndex, dval); + index = get_next_bitmap_descriptor_index(self, elementsDescriptorsIndex, dval); if (index < 0) { /* Return value is an error code not an index */ err = index; return err; } - bd = grib_bufr_descriptor_clone(self->expanded->v[index]); + bd = grib_bufr_descriptor_clone(self->expanded_->v[index]); bd->reference = -codes_power(bd->width, 2); bd->width++; err = codec_element(c, self, iss, buffer, data, &pos, index, bd, elementIndex, dval, sval); grib_bufr_descriptor_delete(bd); if (err) return err; - /* self->expanded->v[index] */ + /* self->expanded_ ->v[index] */ if (flag != PROCESS_ENCODE) grib_iarray_push(elementsDescriptorsIndex, i); elementIndex++; @@ -3040,7 +3102,7 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st elementIndex++; } break; - case 35: /* Cancel backward data reference (cancel bitmap) */ + case 35: /* Cancel backward data reference (cancel bitmap) */ if (flag != PROCESS_ENCODE) { grib_iarray_push(elementsDescriptorsIndex, i); if (decoding) @@ -3050,7 +3112,7 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st } elementIndex++; break; - case 36: /* Define data present bit-map */ + case 36: /* Define data present bit-map */ if (flag == PROCESS_DECODE) { grib_iarray_push(elementsDescriptorsIndex, i); if (decoding) @@ -3068,7 +3130,7 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st } elementIndex++; break; - case 37: /* Use defined data present bit-map = reuse defined bitmap */ + case 37: /* Use defined data present bit-map = reuse defined bitmap */ if (flag != PROCESS_ENCODE) { grib_iarray_push(elementsDescriptorsIndex, i); if (decoding) @@ -3141,83 +3203,82 @@ static int process_elements(grib_accessor* a, int flag, long onlySubset, long st } /* for all descriptors */ if (flag != PROCESS_ENCODE) { - grib_viarray_push(c, self->elementsDescriptorsIndex, elementsDescriptorsIndex); + grib_viarray_push(c, self->elementsDescriptorsIndex_, elementsDescriptorsIndex); /*grib_iarray_print("DBG process_elements::elementsDescriptorsIndex", elementsDescriptorsIndex);*/ } - if (decoding && !self->compressedData) { - grib_vdarray_push(c, self->numericValues, dval); + if (decoding && !self->compressedData_) { + grib_vdarray_push(c, self->numericValues_, dval); /*grib_darray_print("DBG process_elements::dval", dval);*/ } - if (flag == PROCESS_NEW_DATA && !self->compressedData) { - grib_vdarray_push(c, self->tempDoubleValues, dval); /* ECC-1172 */ + if (flag == PROCESS_NEW_DATA && !self->compressedData_) { + grib_vdarray_push(c, self->tempDoubleValues_, dval); /* ECC-1172 */ } } /* for all subsets */ - /*grib_vdarray_print("DBG process_elements: self->numericValues", self->numericValues);*/ - /*grib_viarray_print("DBG process_elements: self->elementsDescriptorsIndex", self->elementsDescriptorsIndex);*/ + /*grib_vdarray_print("DBG process_elements: self->numericValues", self->numericValues_ );*/ + /*grib_viarray_print("DBG process_elements: self->elementsDescriptorsIndex", self->elementsDescriptorsIndex_ );*/ if (decoding) { - err = create_keys(a, 0, 0, 0); - self->bitsToEndData = totalSize; + err = create_keys(a, 0, 0, 0); + self->bitsToEndData_ = totalSize; } else { - self->bitsToEndData = buffer->ulength * 8; - grib_set_bytes(grib_handle_of_accessor(a), self->bufrDataEncodedName, buffer->data, &(buffer->ulength)); + self->bitsToEndData_ = buffer->ulength * 8; + grib_set_bytes(grib_handle_of_accessor(a), self->bufrDataEncodedName_, buffer->data, &(buffer->ulength)); grib_buffer_delete(c, buffer); - if (self->numberOfSubsets != grib_iarray_used_size(self->iss_list)) { - grib_set_long(h, self->numberOfSubsetsName, grib_iarray_used_size(self->iss_list)); + if (self->numberOfSubsets_ != grib_iarray_used_size(self->iss_list_)) { + grib_set_long(h, self->numberOfSubsetsName_, grib_iarray_used_size(self->iss_list_)); } } if (subsetList) - grib_context_free(c, subsetList);/* ECC-1498 */ + grib_context_free(c, subsetList); /* ECC-1498 */ return err; } -void grib_accessor_class_bufr_data_array_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_bufr_data_array_t::dump(grib_dumper* dumper) { // grib_accessor_bufr_data_array_t *self =(grib_accessor_bufr_data_array_t*)a; // int err=process_elements(a,PROCESS_DECODE); - // grib_dump_section(dumper,a,self->dataKeys->block); + // grib_dump_section(dumper,a,self->dataKeys_ ->block); + return; } -int grib_accessor_class_bufr_data_array_t::value_count(grib_accessor* a, long* count) +int grib_accessor_bufr_data_array_t::value_count(long* count) { int err = 0, l; long i; - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - err = process_elements(a, PROCESS_DECODE, 0, 0, 0); + err = process_elements(this, PROCESS_DECODE, 0, 0, 0); if (err) return err; - if (self->compressedData) { - l = grib_vdarray_used_size(self->numericValues); + if (compressedData_) { + l = grib_vdarray_used_size(numericValues_); - *count = l * self->numberOfSubsets; + *count = l * numberOfSubsets_; } else { *count = 0; - for (i = 0; i < self->numberOfSubsets; i++) - *count += grib_iarray_used_size(self->elementsDescriptorsIndex->v[i]); + for (i = 0; i < numberOfSubsets_; i++) + *count += grib_iarray_used_size(elementsDescriptorsIndex_->v[i]); } return err; } -int grib_accessor_class_bufr_data_array_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_bufr_data_array_t::unpack_double(double* val, size_t* len) { - int err = 0, i, k, ii; - int proc_flag = PROCESS_DECODE; - size_t l = 0, elementsInSubset; - long numberOfSubsets = 0; - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; + int err = 0, i, k, ii; + int proc_flag = PROCESS_DECODE; + size_t l = 0, elementsInSubset; + long numberOfSubsets = 0; - if (self->unpackMode == CODES_BUFR_NEW_DATA) + if (unpackMode_ == CODES_BUFR_NEW_DATA) proc_flag = PROCESS_NEW_DATA; - err = process_elements(a, proc_flag, 0, 0, 0); + err = process_elements(this, proc_flag, 0, 0, 0); if (err) return err; if (!val) @@ -3227,32 +3288,32 @@ int grib_accessor_class_bufr_data_array_t::unpack_double(grib_accessor* a, doubl * but when client requests a key like 'numericValues', then we end up here */ - l = grib_vdarray_used_size(self->numericValues); - err = grib_get_long(grib_handle_of_accessor(a), self->numberOfSubsetsName, &numberOfSubsets); + l = grib_vdarray_used_size(numericValues_); + err = grib_get_long(grib_handle_of_accessor(this), numberOfSubsetsName_, &numberOfSubsets); if (err) return err; - if (self->compressedData) { - const size_t rlen = l * self->numberOfSubsets; - ii = 0; + if (compressedData_) { + const size_t rlen = l * numberOfSubsets_; + ii = 0; if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "wrong size (%ld) for %s, it contains %ld values ", *len, a->name, rlen); + grib_context_log(context_, GRIB_LOG_ERROR, + "wrong size (%ld) for %s, it contains %ld values ", *len, name_, rlen); *len = 0; return GRIB_ARRAY_TOO_SMALL; } for (k = 0; k < numberOfSubsets; k++) { for (i = 0; i < l; i++) { - val[ii++] = self->numericValues->v[i]->n > 1 ? self->numericValues->v[i]->v[k] : self->numericValues->v[i]->v[0]; + val[ii++] = numericValues_->v[i]->n > 1 ? numericValues_->v[i]->v[k] : numericValues_->v[i]->v[0]; } } } else { ii = 0; for (k = 0; k < numberOfSubsets; k++) { - elementsInSubset = grib_iarray_used_size(self->elementsDescriptorsIndex->v[k]); + elementsInSubset = grib_iarray_used_size(elementsDescriptorsIndex_->v[k]); for (i = 0; i < elementsInSubset; i++) { - val[ii++] = self->numericValues->v[k]->v[i]; + val[ii++] = numericValues_->v[k]->v[i]; } } } @@ -3260,27 +3321,26 @@ int grib_accessor_class_bufr_data_array_t::unpack_double(grib_accessor* a, doubl return GRIB_SUCCESS; } -void grib_accessor_class_bufr_data_array_t::destroy(grib_context* c, grib_accessor* a) +void grib_accessor_bufr_data_array_t::destroy(grib_context* c) { - grib_accessor_bufr_data_array_t* self = (grib_accessor_bufr_data_array_t*)a; - self_clear(c, self); - if (self->dataAccessors) - grib_accessors_list_delete(c, self->dataAccessors); - if (self->dataAccessorsTrie) { - grib_trie_with_rank_delete_container(self->dataAccessorsTrie); - self->dataAccessorsTrie = NULL; + self_clear(c, this); + if (dataAccessors_) + grib_accessors_list_delete(c, dataAccessors_); + if (dataAccessorsTrie_) { + grib_trie_with_rank_delete_container(dataAccessorsTrie_); + dataAccessorsTrie_ = NULL; } - if (self->tempStrings) { - grib_sarray_delete_content(c, self->tempStrings); - grib_sarray_delete(c, self->tempStrings); + if (tempStrings_) { + grib_sarray_delete_content(c, tempStrings_); + grib_sarray_delete(c, tempStrings_); } - if (self->tempDoubleValues) { + if (tempDoubleValues_) { /* ECC-1172: Clean up to avoid memory leaks */ - grib_vdarray_delete_content(c, self->tempDoubleValues); - grib_vdarray_delete(c, self->tempDoubleValues); - self->tempDoubleValues = NULL; + grib_vdarray_delete_content(c, tempDoubleValues_); + grib_vdarray_delete(c, tempDoubleValues_); + tempDoubleValues_ = NULL; } - grib_iarray_delete(self->iss_list); - grib_accessor_class_gen_t::destroy(c, a); + grib_iarray_delete(iss_list_); + grib_accessor_gen_t::destroy(c); } diff --git a/src/accessor/grib_accessor_class_bufr_data_array.h b/src/accessor/grib_accessor_class_bufr_data_array.h index 75d02b9b4..35e3a21ca 100644 --- a/src/accessor/grib_accessor_class_bufr_data_array.h +++ b/src/accessor/grib_accessor_class_bufr_data_array.h @@ -15,75 +15,72 @@ class grib_accessor_bufr_data_array_t : public grib_accessor_gen_t { public: - 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_bufr_data_array_t() : + grib_accessor_gen_t() { class_name_ = "bufr_data_array"; } 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; + long get_native_type() override; + int pack_double(const double* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + long byte_count() override; + long byte_offset() override; + long next_offset() override; + int value_count(long*) override; + void destroy(grib_context*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +public: + 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_; }; -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); - +grib_vsarray* accessor_bufr_data_array_get_stringValues(grib_accessor*); +grib_accessors_list* accessor_bufr_data_array_get_dataAccessors(grib_accessor*); +grib_trie_with_rank* accessor_bufr_data_array_get_dataAccessorsTrie(grib_accessor*); +void accessor_bufr_data_array_set_unpackMode(grib_accessor*, int unpackMode); diff --git a/src/accessor/grib_accessor_class_bufr_data_element.cc b/src/accessor/grib_accessor_class_bufr_data_element.cc index 8d483b96d..350a54fda 100644 --- a/src/accessor/grib_accessor_class_bufr_data_element.cc +++ b/src/accessor/grib_accessor_class_bufr_data_element.cc @@ -10,10 +10,10 @@ #include "grib_accessor_class_bufr_data_element.h" -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; +grib_accessor_bufr_data_element_t _grib_accessor_bufr_data_element{}; +grib_accessor* grib_accessor_bufr_data_element = &_grib_accessor_bufr_data_element; -grib_accessor* grib_accessor_class_bufr_data_element_t::make_clone(grib_accessor* a, grib_section* s, int* err) +grib_accessor* grib_accessor_bufr_data_element_t::make_clone(grib_section* s, int* err) { grib_accessor* the_clone = NULL; grib_accessor* attribute = NULL; @@ -28,34 +28,34 @@ grib_accessor* grib_accessor_class_bufr_data_element_t::make_clone(grib_accessor creator.name_space = (char*)""; creator.set = 0; creator.name = (char*)"unknown"; - if (strcmp(a->cclass->name, "bufr_data_element")) { - grib_context_log(a->context, GRIB_LOG_FATAL, "wrong accessor type: '%s' should be '%s'", a->cclass->name, "bufr_data_element"); + if (strcmp(class_name_, "bufr_data_element")) { + grib_context_log(context_, GRIB_LOG_FATAL, "wrong accessor type: '%s' should be '%s'", class_name_, "bufr_data_element"); } *err = 0; - 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_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; - elementAccessor->index = self->index; - elementAccessor->type = self->type; - elementAccessor->numberOfSubsets = self->numberOfSubsets; - elementAccessor->subsetNumber = self->subsetNumber; - elementAccessor->compressedData = self->compressedData; - elementAccessor->descriptors = self->descriptors; - elementAccessor->numericValues = self->numericValues; - elementAccessor->stringValues = self->stringValues; - elementAccessor->elementsDescriptorsIndex = self->elementsDescriptorsIndex; - elementAccessor->cname = copied_name; /* ECC-765 */ + the_clone = grib_accessor_factory(s, &creator, 0, NULL); + copied_name = grib_context_strdup(context_, name_); + the_clone->name_ = copied_name; + elementAccessor = (grib_accessor_bufr_data_element_t*)the_clone; + self = (grib_accessor_bufr_data_element_t*)this; + the_clone->flags_ = flags_; + the_clone->parent_ = NULL; + the_clone->h_ = s->h; + elementAccessor->index_ = self->index_; + elementAccessor->type_ = self->type_; + elementAccessor->numberOfSubsets_ = self->numberOfSubsets_; + elementAccessor->subsetNumber_ = self->subsetNumber_; + elementAccessor->compressedData_ = self->compressedData_; + elementAccessor->descriptors_ = self->descriptors_; + elementAccessor->numericValues_ = self->numericValues_; + elementAccessor->stringValues_ = self->stringValues_; + elementAccessor->elementsDescriptorsIndex_ = self->elementsDescriptorsIndex_; + elementAccessor->cname_ = copied_name; /* ECC-765 */ i = 0; - while (a->attributes[i]) { - attribute = a->attributes[i]->clone(s, err); - /* attribute->parent=a->parent; */ + while (attributes_[i]) { + attribute = attributes_[i]->clone(s, err); + /* attribute->parent=parent_ ; */ the_clone->add_attribute(attribute, 0); i++; } @@ -66,149 +66,153 @@ grib_accessor* grib_accessor_class_bufr_data_element_t::make_clone(grib_accessor void accessor_bufr_data_element_set_index(grib_accessor* a, long index) { grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->index = index; + self->index_ = index; } void accessor_bufr_data_element_set_type(grib_accessor* a, int type) { grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->type = type; + self->type_ = type; } void accessor_bufr_data_element_set_numberOfSubsets(grib_accessor* a, long numberOfSubsets) { grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->numberOfSubsets = numberOfSubsets; + self->numberOfSubsets_ = numberOfSubsets; } void accessor_bufr_data_element_set_subsetNumber(grib_accessor* a, long subsetNumber) { grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->subsetNumber = subsetNumber; + self->subsetNumber_ = subsetNumber; } void accessor_bufr_data_element_set_compressedData(grib_accessor* a, int compressedData) { grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->compressedData = compressedData; + self->compressedData_ = compressedData; } void accessor_bufr_data_element_set_descriptors(grib_accessor* a, bufr_descriptors_array* descriptors) { grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->descriptors = descriptors; + self->descriptors_ = descriptors; } void accessor_bufr_data_element_set_numericValues(grib_accessor* a, grib_vdarray* numericValues) { grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->numericValues = numericValues; + self->numericValues_ = numericValues; } void accessor_bufr_data_element_set_stringValues(grib_accessor* a, grib_vsarray* stringValues) { grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->stringValues = stringValues; + self->stringValues_ = stringValues; } void accessor_bufr_data_element_set_elementsDescriptorsIndex(grib_accessor* a, grib_viarray* elementsDescriptorsIndex) { grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - self->elementsDescriptorsIndex = elementsDescriptorsIndex; + self->elementsDescriptorsIndex_ = elementsDescriptorsIndex; } -void grib_accessor_class_bufr_data_element_t::init(grib_accessor* a, const long len, grib_arguments* params) +void grib_accessor_bufr_data_element_t::init(const long len, grib_arguments* params) { - grib_accessor_class_gen_t::init(a, len, 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; + grib_accessor_gen_t::init(len, params); + length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_BUFR_DATA; + /* flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; */ + index_ = 0; + type_ = 0; + compressedData_ = 0; + subsetNumber_ = 0; + numberOfSubsets_ = 0; + descriptors_ = NULL; + numericValues_ = NULL; + stringValues_ = NULL; + elementsDescriptorsIndex_ = NULL; + cname_ = NULL; } -void grib_accessor_class_bufr_data_element_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_bufr_data_element_t::dump(grib_dumper* dumper) { - int type = get_native_type(a); + int type = get_native_type(); switch (type) { case GRIB_TYPE_LONG: - grib_dump_long(dumper, a, NULL); + grib_dump_long(dumper, this, NULL); break; case GRIB_TYPE_DOUBLE: - grib_dump_values(dumper, a); + grib_dump_values(dumper, this); break; case GRIB_TYPE_STRING: - grib_dump_string_array(dumper, a, NULL); + grib_dump_string_array(dumper, this, NULL); break; } } -int grib_accessor_class_bufr_data_element_t::unpack_string_array(grib_accessor* a, char** val, size_t* len) +int grib_accessor_bufr_data_element_t::unpack_string_array(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; - grib_context* c = a->context; + grib_context* c = context_; - if (self->compressedData) { - DEBUG_ASSERT(self->index < self->numericValues->n); - idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets; - DEBUG_ASSERT(idx < self->stringValues->n); - count = grib_sarray_used_size(self->stringValues->v[idx]); + if (compressedData_) { + DEBUG_ASSERT(index_ < numericValues_->n); + idx = ((int)numericValues_->v[index_]->v[0] / 1000 - 1) / numberOfSubsets_; + DEBUG_ASSERT(idx < stringValues_->n); + count = grib_sarray_used_size(stringValues_->v[idx]); for (i = 0; i < count; i++) { - val[i] = grib_context_strdup(c, self->stringValues->v[idx]->v[i]); + val[i] = grib_context_strdup(c, stringValues_->v[idx]->v[i]); } *len = count; } else { - DEBUG_ASSERT(self->subsetNumber < self->numericValues->n); - DEBUG_ASSERT(self->index < self->numericValues->v[self->subsetNumber]->n); - idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1; - val[0] = grib_context_strdup(c, self->stringValues->v[idx]->v[0]); + DEBUG_ASSERT(subsetNumber_ < numericValues_->n); + DEBUG_ASSERT(index_ < numericValues_->v[subsetNumber_]->n); + idx = (int)numericValues_->v[subsetNumber_]->v[index_] / 1000 - 1; + val[0] = grib_context_strdup(c, stringValues_->v[idx]->v[0]); *len = 1; } return ret; } -int grib_accessor_class_bufr_data_element_t::pack_string_array(grib_accessor* a, const char** v, size_t* len) +int grib_accessor_bufr_data_element_t::pack_string_array(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; char* s = NULL; - grib_context* c = a->context; + grib_context* c = context_; - if (self->compressedData) { - idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets; - if (*len != 1 && *len != (size_t)self->numberOfSubsets) { + if (compressedData_) { + idx = ((int)numericValues_->v[index_]->v[0] / 1000 - 1) / numberOfSubsets_; + if (*len != 1 && *len != (size_t)numberOfSubsets_) { grib_context_log(c, GRIB_LOG_ERROR, "Number of values mismatch for '%s': %ld strings provided but expected %ld (=number of subsets)", - self->descriptors->v[self->elementsDescriptorsIndex->v[0]->v[idx]]->shortName, *len, self->numberOfSubsets); + descriptors_->v[elementsDescriptorsIndex_->v[0]->v[idx]]->shortName, *len, numberOfSubsets_); return GRIB_ARRAY_TOO_SMALL; } - grib_sarray_delete_content(c, self->stringValues->v[idx]); /* ECC-1172 */ - grib_sarray_delete(c, self->stringValues->v[idx]); - self->stringValues->v[idx] = grib_sarray_new(c, *len, 1); + grib_sarray_delete_content(c, stringValues_->v[idx]); /* ECC-1172 */ + grib_sarray_delete(c, stringValues_->v[idx]); + stringValues_->v[idx] = grib_sarray_new(c, *len, 1); for (i = 0; i < *len; i++) { s = grib_context_strdup(c, v[i]); - grib_sarray_push(c, self->stringValues->v[idx], s); + grib_sarray_push(c, stringValues_->v[idx], s); } } else { // ECC-1623 - if (*len != (size_t)self->numberOfSubsets) { + if (*len != (size_t)numberOfSubsets_) { grib_context_log(c, GRIB_LOG_ERROR, "Number of values mismatch for '%s': %zu strings provided but expected %ld (=number of subsets)", - a->name, *len, self->numberOfSubsets); + name_, *len, numberOfSubsets_); return GRIB_WRONG_ARRAY_SIZE; } for (i = 0; i < *len; i++) { - // idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1; - idx = (int)self->numericValues->v[i]->v[self->index] / 1000 - 1; - self->stringValues->v[idx]->v[0] = strdup(v[i]); + // idx = (int)numericValues->v[subsetNumber]->v[index_ ] / 1000 - 1; + idx = (int)numericValues_->v[i]->v[index_] / 1000 - 1; + stringValues_->v[idx]->v[0] = strdup(v[i]); } *len = 1; } @@ -216,20 +220,21 @@ int grib_accessor_class_bufr_data_element_t::pack_string_array(grib_accessor* a, return ret; } -int grib_accessor_class_bufr_data_element_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_bufr_data_element_t::unpack_string(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; - double dval = 0; - size_t dlen = 1; + char* str = NULL; + char* p = 0; + size_t slen = 0; + double dval = 0; + size_t dlen = 1; int idx = 0, err = 0; - grib_context* c = a->context; + grib_context* c = context_; - if (self->type != BUFR_DESCRIPTOR_TYPE_STRING) { - char sval[32] = {0,}; - err = unpack_double(a, &dval, &dlen); + if (type_ != BUFR_DESCRIPTOR_TYPE_STRING) { + char sval[32] = { + 0, + }; + err = unpack_double(&dval, &dlen); if (err) return err; snprintf(sval, sizeof(sval), "%g", dval); slen = strlen(sval); @@ -239,20 +244,20 @@ int grib_accessor_class_bufr_data_element_t::unpack_string(grib_accessor* a, cha return GRIB_SUCCESS; } - if (self->compressedData) { - DEBUG_ASSERT(self->index < self->numericValues->n); - idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets; + if (compressedData_) { + DEBUG_ASSERT(index_ < numericValues_->n); + idx = ((int)numericValues_->v[index_]->v[0] / 1000 - 1) / numberOfSubsets_; if (idx < 0) return GRIB_INTERNAL_ERROR; - str = grib_context_strdup(c, self->stringValues->v[idx]->v[0]); + str = grib_context_strdup(c, stringValues_->v[idx]->v[0]); } else { - DEBUG_ASSERT(self->subsetNumber < self->numericValues->n); - idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1; + DEBUG_ASSERT(subsetNumber_ < numericValues_->n); + idx = (int)numericValues_->v[subsetNumber_]->v[index_] / 1000 - 1; if (idx < 0) return GRIB_INTERNAL_ERROR; - DEBUG_ASSERT(idx < self->stringValues->n); - str = grib_context_strdup(c, self->stringValues->v[idx]->v[0]); + DEBUG_ASSERT(idx < stringValues_->n); + str = grib_context_strdup(c, stringValues_->v[idx]->v[0]); } if (str == NULL || strlen(str) == 0) { @@ -285,188 +290,180 @@ int grib_accessor_class_bufr_data_element_t::unpack_string(grib_accessor* a, cha return GRIB_SUCCESS; } -int grib_accessor_class_bufr_data_element_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_bufr_data_element_t::pack_string(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; - grib_context* c = a->context; + grib_context* c = context_; - if (self->compressedData) { - idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets; + if (compressedData_) { + idx = ((int)numericValues_->v[index_]->v[0] / 1000 - 1) / numberOfSubsets_; } else { - idx = (int)self->numericValues->v[self->subsetNumber]->v[self->index] / 1000 - 1; + idx = (int)numericValues_->v[subsetNumber_]->v[index_] / 1000 - 1; } - grib_sarray_delete_content(c, self->stringValues->v[idx]); /* ECC-1172 */ - grib_sarray_delete(c, self->stringValues->v[idx]); - self->stringValues->v[idx] = grib_sarray_new(c, 1, 1); - s = grib_context_strdup(c, val); - grib_sarray_push(c, self->stringValues->v[idx], s); + grib_sarray_delete_content(c, stringValues_->v[idx]); /* ECC-1172 */ + grib_sarray_delete(c, stringValues_->v[idx]); + stringValues_->v[idx] = grib_sarray_new(c, 1, 1); + s = grib_context_strdup(c, val); + grib_sarray_push(c, stringValues_->v[idx], s); return ret; } -int grib_accessor_class_bufr_data_element_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_bufr_data_element_t::unpack_long(long* val, size_t* len) { - grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - int ret = GRIB_SUCCESS; + int ret = GRIB_SUCCESS; long count = 0, i = 0; - value_count(a, &count); + value_count(&count); if (*len < (size_t)count) return GRIB_ARRAY_TOO_SMALL; - if (self->compressedData) { + if (compressedData_) { for (i = 0; i < count; i++) { - DEBUG_ASSERT(self->index < self->numericValues->n); - DEBUG_ASSERT(i < self->numericValues->v[self->index]->n); - val[i] = self->numericValues->v[self->index]->v[i] == GRIB_MISSING_DOUBLE ? GRIB_MISSING_LONG : (long)self->numericValues->v[self->index]->v[i]; + DEBUG_ASSERT(index_ < numericValues_->n); + DEBUG_ASSERT(i < numericValues_->v[index_]->n); + val[i] = numericValues_->v[index_]->v[i] == GRIB_MISSING_DOUBLE ? GRIB_MISSING_LONG : (long)numericValues_->v[index_]->v[i]; } *len = count; } else { - DEBUG_ASSERT(self->subsetNumber < self->numericValues->n); - DEBUG_ASSERT(self->index < self->numericValues->v[self->subsetNumber]->n); - val[0] = self->numericValues->v[self->subsetNumber]->v[self->index] == GRIB_MISSING_DOUBLE ? GRIB_MISSING_LONG : (long)self->numericValues->v[self->subsetNumber]->v[self->index]; + DEBUG_ASSERT(subsetNumber_ < numericValues_->n); + DEBUG_ASSERT(index_ < numericValues_->v[subsetNumber_]->n); + val[0] = numericValues_->v[subsetNumber_]->v[index_] == GRIB_MISSING_DOUBLE ? GRIB_MISSING_LONG : (long)numericValues_->v[subsetNumber_]->v[index_]; *len = 1; } return ret; } -int grib_accessor_class_bufr_data_element_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_bufr_data_element_t::unpack_double(double* val, size_t* len) { - grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - int ret = GRIB_SUCCESS; + int ret = GRIB_SUCCESS; long count = 0, i = 0; - value_count(a, &count); + value_count(&count); if (*len < (size_t)count) return GRIB_ARRAY_TOO_SMALL; - if (self->compressedData) { + if (compressedData_) { for (i = 0; i < count; i++) { - DEBUG_ASSERT(self->index < self->numericValues->n); - DEBUG_ASSERT(i < self->numericValues->v[self->index]->n); - val[i] = self->numericValues->v[self->index]->v[i]; + DEBUG_ASSERT(index_ < numericValues_->n); + DEBUG_ASSERT(i < numericValues_->v[index_]->n); + val[i] = numericValues_->v[index_]->v[i]; } *len = count; } else { - DEBUG_ASSERT(self->subsetNumber < self->numericValues->n); - DEBUG_ASSERT(self->index < self->numericValues->v[self->subsetNumber]->n); - val[0] = self->numericValues->v[self->subsetNumber]->v[self->index]; + DEBUG_ASSERT(subsetNumber_ < numericValues_->n); + DEBUG_ASSERT(index_ < numericValues_->v[subsetNumber_]->n); + val[0] = numericValues_->v[subsetNumber_]->v[index_]; *len = 1; } return ret; } -int grib_accessor_class_bufr_data_element_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_bufr_data_element_t::pack_double(const double* val, size_t* len) { - grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - int ret = GRIB_SUCCESS; + int ret = GRIB_SUCCESS; size_t count = 1, i = 0; - grib_context* c = a->context; + grib_context* c = context_; - if (self->compressedData) { + if (compressedData_) { count = *len; - if (count != 1 && count != (size_t)self->numberOfSubsets) { + if (count != 1 && count != (size_t)numberOfSubsets_) { grib_context_log(c, GRIB_LOG_ERROR, "Number of values mismatch for '%s': %ld doubles provided but expected %ld (=number of subsets)", - self->descriptors->v[self->elementsDescriptorsIndex->v[0]->v[self->index]]->shortName, count, self->numberOfSubsets); + descriptors_->v[elementsDescriptorsIndex_->v[0]->v[index_]]->shortName, count, numberOfSubsets_); return GRIB_ARRAY_TOO_SMALL; } - grib_darray_delete(a->context, self->numericValues->v[self->index]); - self->numericValues->v[self->index] = grib_darray_new(a->context, count, 1); + grib_darray_delete(context_, numericValues_->v[index_]); + numericValues_->v[index_] = grib_darray_new(context_, count, 1); for (i = 0; i < count; i++) - grib_darray_push(a->context, self->numericValues->v[self->index], val[i]); + grib_darray_push(context_, numericValues_->v[index_], val[i]); *len = count; } else { - self->numericValues->v[self->subsetNumber]->v[self->index] = val[0]; - *len = 1; + numericValues_->v[subsetNumber_]->v[index_] = val[0]; + *len = 1; } return ret; } -int grib_accessor_class_bufr_data_element_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_bufr_data_element_t::pack_long(const long* val, size_t* len) { - grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - int ret = 0; + int ret = 0; size_t count = 1, i = 0; - grib_context* c = a->context; + grib_context* c = context_; - if (self->compressedData) { + if (compressedData_) { count = *len; - if (count != 1 && count != (size_t)self->numberOfSubsets) { + if (count != 1 && count != (size_t)numberOfSubsets_) { grib_context_log(c, GRIB_LOG_ERROR, "Number of values mismatch for '%s': %zu integers provided but expected %ld (=number of subsets)", - self->descriptors->v[self->elementsDescriptorsIndex->v[0]->v[self->index]]->shortName, count, self->numberOfSubsets); + descriptors_->v[elementsDescriptorsIndex_->v[0]->v[index_]]->shortName, count, numberOfSubsets_); return GRIB_ARRAY_TOO_SMALL; } - grib_darray_delete(a->context, self->numericValues->v[self->index]); - self->numericValues->v[self->index] = grib_darray_new(a->context, count, 1); + grib_darray_delete(context_, numericValues_->v[index_]); + numericValues_->v[index_] = grib_darray_new(context_, count, 1); for (i = 0; i < count; i++) { - grib_darray_push(a->context, self->numericValues->v[self->index], val[i] == GRIB_MISSING_LONG ? GRIB_MISSING_DOUBLE : val[i]); + grib_darray_push(context_, numericValues_->v[index_], val[i] == GRIB_MISSING_LONG ? GRIB_MISSING_DOUBLE : val[i]); } *len = count; } else { - self->numericValues->v[self->subsetNumber]->v[self->index] = val[0] == GRIB_MISSING_LONG ? GRIB_MISSING_DOUBLE : val[0]; - *len = 1; + numericValues_->v[subsetNumber_]->v[index_] = val[0] == GRIB_MISSING_LONG ? GRIB_MISSING_DOUBLE : val[0]; + *len = 1; } return ret; } -int grib_accessor_class_bufr_data_element_t::value_count(grib_accessor* a, long* count) +int grib_accessor_bufr_data_element_t::value_count(long* count) { int ret = 0, type = 0, idx = 0; - size_t size = 0; - grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; + size_t size = 0; - if (!self->compressedData) { + if (!compressedData_) { *count = 1; return 0; } - type = get_native_type(a); + type = get_native_type(); if (type == GRIB_TYPE_STRING) { - DEBUG_ASSERT(self->index < self->numericValues->n); - idx = ((int)self->numericValues->v[self->index]->v[0] / 1000 - 1) / self->numberOfSubsets; - size = grib_sarray_used_size(self->stringValues->v[idx]); + DEBUG_ASSERT(index_ < numericValues_->n); + idx = ((int)numericValues_->v[index_]->v[0] / 1000 - 1) / numberOfSubsets_; + size = grib_sarray_used_size(stringValues_->v[idx]); } else { - DEBUG_ASSERT(self->index < self->numericValues->n); - size = grib_darray_used_size(self->numericValues->v[self->index]); + DEBUG_ASSERT(index_ < numericValues_->n); + size = grib_darray_used_size(numericValues_->v[index_]); } - *count = size == 1 ? 1 : self->numberOfSubsets; + *count = size == 1 ? 1 : numberOfSubsets_; return ret; } -int grib_accessor_class_bufr_data_element_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_bufr_data_element_t::unpack_double_element(size_t idx, double* val) { /* ECC-415 */ - grib_accessor_bufr_data_element_t* self = (grib_accessor_bufr_data_element_t*)a; - int ret = GRIB_SUCCESS; - long count = 0; + int ret = GRIB_SUCCESS; + long count = 0; - value_count(a, &count); + value_count(&count); if (idx >= (size_t)count) { return GRIB_INTERNAL_ERROR; } - if (self->compressedData) { - *val = self->numericValues->v[self->index]->v[idx]; + if (compressedData_) { + *val = numericValues_->v[index_]->v[idx]; } else { ret = GRIB_NOT_IMPLEMENTED; @@ -474,12 +471,10 @@ int grib_accessor_class_bufr_data_element_t::unpack_double_element(grib_accessor return ret; } -int grib_accessor_class_bufr_data_element_t::get_native_type(grib_accessor* a) +long grib_accessor_bufr_data_element_t::get_native_type() { - 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) { + int ret = GRIB_TYPE_DOUBLE; + switch (type_) { case BUFR_DESCRIPTOR_TYPE_STRING: ret = GRIB_TYPE_STRING; break; @@ -500,50 +495,49 @@ int grib_accessor_class_bufr_data_element_t::get_native_type(grib_accessor* a) return ret; } -void grib_accessor_class_bufr_data_element_t::destroy(grib_context* ct, grib_accessor* a) +void grib_accessor_bufr_data_element_t::destroy(grib_context* ct) { - 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]);*/ - a->attributes[i]->destroy(ct); - a->attributes[i] = NULL; + int i = 0; + if (cname_) + grib_context_free(ct, cname_); /* ECC-765 */ + while (i < MAX_ACCESSOR_ATTRIBUTES && attributes_[i]) { + /*grib_context_log(ct,GRIB_LOG_DEBUG,"deleting attribute %s->%s",a->name,attributes_ [i]->name);*/ + /*printf("bufr_data_element destroy %s %p\n", a->attributes_[i]->name, (void*)attributes_ [i]);*/ + attributes_[i]->destroy(ct); + attributes_[i] = NULL; i++; } - grib_accessor_class_gen_t::destroy(ct, a); + grib_accessor_gen_t::destroy(ct); } #define MAX_STRING_SIZE 4096 /* Return 1 if BUFR element(s) is/are missing, 0 otherwise. In case of decoding errors, also return 0 */ -int grib_accessor_class_bufr_data_element_t::is_missing(grib_accessor* a) +int grib_accessor_bufr_data_element_t::is_missing() { - const int ktype = get_native_type(a); + const int ktype = get_native_type(); int err = 0, result = 1; /* default: assume all are missing */ long count = 0; size_t i = 0, size = 1, size2 = 0; - grib_context* c = a->context; + grib_context* c = context_; if (ktype == GRIB_TYPE_LONG) { long* values = NULL; long value = 0; - value_count(a, &count); + value_count(&count); size = size2 = count; if (size > 1) { values = (long*)grib_context_malloc_clear(c, sizeof(long) * size); - err = a->unpack_long(values, &size2); + err = unpack_long(values, &size2); } else { - err = a->unpack_long(&value, &size2); + err = unpack_long(&value, &size2); } if (err) return 0; /* TODO: no way of propagating the error up */ Assert(size2 == size); if (size > 1) { for (i = 0; i < size; i++) { - if (!grib_is_missing_long(a, values[i])) { + if (!grib_is_missing_long(this, values[i])) { result = 0; /* at least one not missing */ break; } @@ -551,27 +545,27 @@ int grib_accessor_class_bufr_data_element_t::is_missing(grib_accessor* a) grib_context_free(c, values); } else { - result = grib_is_missing_long(a, value); + result = grib_is_missing_long(this, value); } } else if (ktype == GRIB_TYPE_DOUBLE) { double value = 0; double* values = NULL; - value_count(a, &count); + value_count(&count); size = size2 = count; if (size > 1) { values = (double*)grib_context_malloc_clear(c, sizeof(double) * size); - err = a->unpack_double(values, &size2); + err = unpack_double(values, &size2); } else { - err = a->unpack_double(&value, &size2); + err = unpack_double(&value, &size2); } if (err) return 0; /* TODO: no way of propagating the error up */ Assert(size2 == size); if (size > 1) { for (i = 0; i < size; ++i) { - if (!grib_is_missing_double(a, values[i])) { + if (!grib_is_missing_double(this, values[i])) { result = 0; break; } @@ -579,19 +573,19 @@ int grib_accessor_class_bufr_data_element_t::is_missing(grib_accessor* a) grib_context_free(c, values); } else { - result = grib_is_missing_double(a, value); + result = grib_is_missing_double(this, value); } } else if (ktype == GRIB_TYPE_STRING) { char** values = NULL; - value_count(a, &count); + value_count(&count); size = count; if (size > 1) { - values = (char**)grib_context_malloc_clear(a->context, size * sizeof(char*)); - err = a->unpack_string_array(values, &size); + values = (char**)grib_context_malloc_clear(context_, size * sizeof(char*)); + err = 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)) { + if (!grib_is_missing_string(this, (unsigned char*)values[i], size)) { result = 0; break; } @@ -601,11 +595,13 @@ int grib_accessor_class_bufr_data_element_t::is_missing(grib_accessor* a) grib_context_free(c, values); } else { - char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */ + char value[MAX_STRING_SIZE] = { + 0, + }; /* See ECC-710 */ size = MAX_STRING_SIZE; - err = a->unpack_string(value, &size); + err = 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); + result = grib_is_missing_string(this, (unsigned char*)value, size); } } else { @@ -614,26 +610,26 @@ int grib_accessor_class_bufr_data_element_t::is_missing(grib_accessor* a) return result; } -int grib_accessor_class_bufr_data_element_t::pack_missing(grib_accessor* a) +int grib_accessor_bufr_data_element_t::pack_missing() { int ktype = GRIB_TYPE_UNDEFINED; int err = 0; size_t size = 1; - const int can_be_missing = (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING); + const int can_be_missing = (flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING); if (!can_be_missing) return GRIB_VALUE_CANNOT_BE_MISSING; - ktype = get_native_type(a); + ktype = get_native_type(); if (ktype == GRIB_TYPE_LONG) { long missing = GRIB_MISSING_LONG; - err = pack_long(a, &missing, &size); + err = pack_long(&missing, &size); } else if (ktype == GRIB_TYPE_DOUBLE) { double missing = GRIB_MISSING_DOUBLE; - err = pack_double(a, &missing, &size); + err = pack_double(&missing, &size); } else if (ktype == GRIB_TYPE_STRING) { - err = pack_string(a, "", &size); + err = pack_string("", &size); } else { err = GRIB_INVALID_TYPE; diff --git a/src/accessor/grib_accessor_class_bufr_data_element.h b/src/accessor/grib_accessor_class_bufr_data_element.h index bbed1785b..6c70ee200 100644 --- a/src/accessor/grib_accessor_class_bufr_data_element.h +++ b/src/accessor/grib_accessor_class_bufr_data_element.h @@ -16,39 +16,36 @@ 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_bufr_data_element_t() : + grib_accessor_gen_t() { class_name_ = "bufr_data_element"; } 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; - grib_accessor* make_clone(grib_accessor*, grib_section*, int*) override; + long get_native_type() override; + int pack_missing() override; + int is_missing() override; + int pack_double(const double* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + int pack_string(const char*, size_t* len) override; + int pack_string_array(const char**, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + int unpack_string_array(char**, size_t* len) override; + int value_count(long*) override; + void destroy(grib_context*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + int unpack_double_element(size_t i, double* val) override; + grib_accessor* make_clone(grib_section*, int*) override; + +public: + 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_; }; diff --git a/src/accessor/grib_accessor_class_bufr_elements_table.cc b/src/accessor/grib_accessor_class_bufr_elements_table.cc index a4db0249b..244d42f7b 100644 --- a/src/accessor/grib_accessor_class_bufr_elements_table.cc +++ b/src/accessor/grib_accessor_class_bufr_elements_table.cc @@ -29,7 +29,7 @@ static omp_nest_lock_t mutex1; static void init_mutex() { - GRIB_OMP_CRITICAL(lock_grib_accessor_class_bufr_elements_table_c) + GRIB_OMP_CRITICAL(lock_grib_accessor_bufr_elements_table_c) { if (once == 0) { omp_init_nest_lock(&mutex1); @@ -39,36 +39,44 @@ static void init_mutex() } #endif +grib_accessor_bufr_elements_table_t _grib_accessor_bufr_elements_table{}; +grib_accessor* grib_accessor_bufr_elements_table = &_grib_accessor_bufr_elements_table; -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; - - -void grib_accessor_class_bufr_elements_table_t::init(grib_accessor* a, const long len, grib_arguments* params) +void grib_accessor_bufr_elements_table_t::init(const long len, grib_arguments* params) { - grib_accessor_class_gen_t::init(a, len, params); - int n = 0; - grib_accessor_bufr_elements_table_t* self = (grib_accessor_bufr_elements_table_t*)a; + grib_accessor_gen_t::init(len, params); + int n = 0; - 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++); - self->localDir = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); + dictionary_ = grib_arguments_get_string(grib_handle_of_accessor(this), params, n++); + masterDir_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++); + localDir_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) { grib_accessor_bufr_elements_table_t* self = (grib_accessor_bufr_elements_table_t*)a; - - char* filename = NULL; - char line[1024] = {0,}; - char masterDir[1024] = {0,}; - char localDir[1024] = {0,}; - char dictName[1024] = {0,}; - char masterRecomposed[1024] = {0,}; //e.g. bufr/tables/0/wmo/36/element.table - char localRecomposed[1024] = {0,}; //e.g. bufr/tables/0/local/0/98/0/element.table + char* filename = NULL; + char line[1024] = { + 0, + }; + char masterDir[1024] = { + 0, + }; + char localDir[1024] = { + 0, + }; + char dictName[1024] = { + 0, + }; + char masterRecomposed[1024] = { + 0, + }; // e.g. bufr/tables/0/wmo/36/element.table + char localRecomposed[1024] = { + 0, + }; // e.g. bufr/tables/0/local/0/98/0/element.table char* localFilename = 0; char** list = 0; char** cached_list = 0; @@ -76,33 +84,37 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) grib_trie* dictionary = NULL; FILE* f = NULL; grib_handle* h = grib_handle_of_accessor(a); - grib_context* c = a->context; + grib_context* c = a->context_; *err = GRIB_SUCCESS; len = 1024; - if (self->masterDir != NULL) - grib_get_string(h, self->masterDir, masterDir, &len); + if (self->masterDir_ != NULL) + grib_get_string(h, self->masterDir_, masterDir, &len); len = 1024; - if (self->localDir != NULL) - grib_get_string(h, self->localDir, localDir, &len); + if (self->localDir_ != NULL) + grib_get_string(h, self->localDir_, localDir, &len); GRIB_MUTEX_INIT_ONCE(&once, &init_mutex); GRIB_MUTEX_LOCK(&mutex1); if (*masterDir != 0) { - char name[4096] = {0,}; - snprintf(name, 4096, "%s/%s", masterDir, self->dictionary); + char name[4096] = { + 0, + }; + snprintf(name, 4096, "%s/%s", masterDir, self->dictionary_); grib_recompose_name(h, NULL, name, masterRecomposed, 0); filename = grib_context_full_defs_path(c, masterRecomposed); } else { - filename = grib_context_full_defs_path(c, self->dictionary); + filename = grib_context_full_defs_path(c, self->dictionary_); } if (*localDir != 0) { - char localName[2048] = {0,}; - snprintf(localName, 2048, "%s/%s", localDir, self->dictionary); + char localName[2048] = { + 0, + }; + snprintf(localName, 2048, "%s/%s", localDir, self->dictionary_); grib_recompose_name(h, NULL, localName, localRecomposed, 0); localFilename = grib_context_full_defs_path(c, localRecomposed); snprintf(dictName, 1024, "%s:%s", localFilename, filename); @@ -112,7 +124,7 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) } if (!filename) { - grib_context_log(c, GRIB_LOG_ERROR, "Unable to find definition file %s", self->dictionary); + grib_context_log(c, GRIB_LOG_ERROR, "Unable to find definition file %s", self->dictionary_); if (strlen(masterRecomposed) > 0) grib_context_log(c, GRIB_LOG_DEBUG, "master path=%s", masterRecomposed); if (strlen(localRecomposed) > 0) grib_context_log(c, GRIB_LOG_DEBUG, "local path=%s", localRecomposed); *err = GRIB_FILE_NOT_FOUND; @@ -122,11 +134,11 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) dictionary = (grib_trie*)grib_trie_get(c->lists, dictName); if (dictionary) { - /*grib_context_log(c,GRIB_LOG_DEBUG,"using dictionary %s from cache",self->dictionary);*/ + /*grib_context_log(c,GRIB_LOG_DEBUG,"using dictionary %s from cache",a->dictionary_ );*/ goto the_end; } else { - grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from file %s", self->dictionary, filename); + grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from file %s", self->dictionary_, filename); } f = codes_fopen(filename, "r"); @@ -282,7 +294,7 @@ bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, i if (!a) return NULL; - c = a->context; + c = a->context_; DEBUG_ASSERT(c); v = (bufr_descriptor*)grib_context_malloc_clear(c, sizeof(bufr_descriptor)); if (!v) { @@ -314,28 +326,28 @@ bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, i return v; } -int grib_accessor_class_bufr_elements_table_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) +int grib_accessor_bufr_elements_table_t::unpack_string(char* buffer, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_bufr_elements_table_t::value_count(grib_accessor* a, long* count) +int grib_accessor_bufr_elements_table_t::value_count(long* count) { *count = 1; return 0; } -int grib_accessor_class_bufr_elements_table_t::get_native_type(grib_accessor* a) +long grib_accessor_bufr_elements_table_t::get_native_type() { return GRIB_TYPE_STRING; } -int grib_accessor_class_bufr_elements_table_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_bufr_elements_table_t::unpack_long(long* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_bufr_elements_table_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_bufr_elements_table_t::unpack_double(double* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } diff --git a/src/accessor/grib_accessor_class_bufr_elements_table.h b/src/accessor/grib_accessor_class_bufr_elements_table.h index 4f133c9e4..5d3684684 100644 --- a/src/accessor/grib_accessor_class_bufr_elements_table.h +++ b/src/accessor/grib_accessor_class_bufr_elements_table.h @@ -16,21 +16,22 @@ 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; + grib_accessor_bufr_elements_table_t() : + grib_accessor_gen_t() { class_name_ = "bufr_elements_table"; } + grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_elements_table_t{}; } + long get_native_type() override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + // TODO(maee): make members private + // private: +public: + 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; -}; +int bufr_descriptor_is_marker(bufr_descriptor* d); +bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, int code, int* err); diff --git a/src/accessor/grib_accessor_class_bufr_extract_area_subsets.cc b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.cc index 91a34c72c..3bc01645a 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_area_subsets.cc +++ b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.cc @@ -11,33 +11,31 @@ #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; +grib_accessor_bufr_extract_area_subsets_t _grib_accessor_bufr_extract_area_subsets{}; +grib_accessor* grib_accessor_bufr_extract_area_subsets = &_grib_accessor_bufr_extract_area_subsets; - -void grib_accessor_class_bufr_extract_area_subsets_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_bufr_extract_area_subsets_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, 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; + grib_accessor_gen_t::init(len, arg); + grib_handle* h = grib_handle_of_accessor(this); + 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->extractAreaWestLongitude = grib_arguments_get_name(h, arg, n++); - self->extractAreaEastLongitude = grib_arguments_get_name(h, arg, n++); - self->extractAreaNorthLatitude = grib_arguments_get_name(h, arg, n++); - self->extractAreaSouthLatitude = grib_arguments_get_name(h, arg, n++); - self->extractAreaLongitudeRank = grib_arguments_get_name(h, arg, n++); - self->extractAreaLatitudeRank = grib_arguments_get_name(h, arg, n++); - self->extractedAreaNumberOfSubsets = grib_arguments_get_name(h, arg, n++); + length_ = 0; + doExtractSubsets_ = grib_arguments_get_name(h, arg, n++); + numberOfSubsets_ = grib_arguments_get_name(h, arg, n++); + extractSubsetList_ = grib_arguments_get_name(h, arg, n++); + extractAreaWestLongitude_ = grib_arguments_get_name(h, arg, n++); + extractAreaEastLongitude_ = grib_arguments_get_name(h, arg, n++); + extractAreaNorthLatitude_ = grib_arguments_get_name(h, arg, n++); + extractAreaSouthLatitude_ = grib_arguments_get_name(h, arg, n++); + extractAreaLongitudeRank_ = grib_arguments_get_name(h, arg, n++); + extractAreaLatitudeRank_ = grib_arguments_get_name(h, arg, n++); + extractedAreaNumberOfSubsets_ = grib_arguments_get_name(h, arg, n++); - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; } -int grib_accessor_class_bufr_extract_area_subsets_t::get_native_type(grib_accessor* a) +long grib_accessor_bufr_extract_area_subsets_t::get_native_type() { return GRIB_TYPE_LONG; } @@ -53,11 +51,10 @@ static void fill_in(double a[], long length) static 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; - grib_handle* h = grib_handle_of_accessor(a); - grib_context* c = h->context; + int ret = 0; + long compressed = 0; + grib_handle* h = grib_handle_of_accessor(a); + grib_context* c = h->context; double* lat = NULL; double* lon = NULL; @@ -66,13 +63,17 @@ static int select_area(grib_accessor* a) long numberOfSubsets, i, latRank, lonRank; grib_iarray* subsets = NULL; size_t nsubsets = 0; - char latstr[32] = {0,}; - char lonstr[32] = {0,}; + char latstr[32] = { + 0, + }; + char lonstr[32] = { + 0, + }; ret = grib_get_long(h, "compressedData", &compressed); if (ret) return ret; - ret = grib_get_long(h, self->numberOfSubsets, &numberOfSubsets); + ret = grib_get_long(h, self->numberOfSubsets_, &numberOfSubsets); if (ret) return ret; subsets = grib_iarray_new(c, numberOfSubsets, 10); @@ -81,10 +82,10 @@ static int select_area(grib_accessor* a) if (ret) return ret; if (compressed) { - ret = grib_get_long(h, self->extractAreaLongitudeRank, &lonRank); + ret = grib_get_long(h, self->extractAreaLongitudeRank_, &lonRank); if (ret) return ret; snprintf(lonstr, sizeof(lonstr), "#%ld#longitude", lonRank); - ret = grib_get_long(h, self->extractAreaLatitudeRank, &latRank); + ret = grib_get_long(h, self->extractAreaLatitudeRank_, &latRank); if (ret) return ret; snprintf(latstr, sizeof(latstr), "#%ld#latitude", latRank); } @@ -141,13 +142,13 @@ static int select_area(grib_accessor* a) } } - ret = grib_get_double(h, self->extractAreaWestLongitude, &lonWest); + ret = grib_get_double(h, self->extractAreaWestLongitude_, &lonWest); if (ret) return ret; - ret = grib_get_double(h, self->extractAreaEastLongitude, &lonEast); + ret = grib_get_double(h, self->extractAreaEastLongitude_, &lonEast); if (ret) return ret; - ret = grib_get_double(h, self->extractAreaNorthLatitude, &latNorth); + ret = grib_get_double(h, self->extractAreaNorthLatitude_, &latNorth); if (ret) return ret; - ret = grib_get_double(h, self->extractAreaSouthLatitude, &latSouth); + ret = grib_get_double(h, self->extractAreaSouthLatitude_, &latSouth); if (ret) return ret; for (i = 0; i < numberOfSubsets; i++) { @@ -159,16 +160,16 @@ static int select_area(grib_accessor* a) } nsubsets = grib_iarray_used_size(subsets); - ret = grib_set_long(h, self->extractedAreaNumberOfSubsets, nsubsets); + ret = grib_set_long(h, self->extractedAreaNumberOfSubsets_, nsubsets); if (ret) return ret; if (nsubsets != 0) { long* subsets_ar = grib_iarray_get_array(subsets); - ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets); + 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, self->doExtractSubsets, 1); + ret = grib_set_long(h, self->doExtractSubsets_, 1); if (ret) return ret; } @@ -180,11 +181,11 @@ static int select_area(grib_accessor* a) return ret; } -int grib_accessor_class_bufr_extract_area_subsets_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_bufr_extract_area_subsets_t::pack_long(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; - return select_area(a); + return select_area(this); } diff --git a/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h index 941f38ac0..325c857b3 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h +++ b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h @@ -16,25 +16,22 @@ 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_bufr_extract_area_subsets_t() : + grib_accessor_gen_t() { class_name_ = "bufr_extract_area_subsets"; } 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; + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +public: + 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_; }; diff --git a/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc index fc49cdcae..91037c0bb 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc +++ b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.cc @@ -10,25 +10,23 @@ #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; +grib_accessor_bufr_extract_datetime_subsets_t _grib_accessor_bufr_extract_datetime_subsets{}; +grib_accessor* grib_accessor_bufr_extract_datetime_subsets = &_grib_accessor_bufr_extract_datetime_subsets; - -void grib_accessor_class_bufr_extract_datetime_subsets_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_bufr_extract_datetime_subsets_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - int n = 0; - grib_accessor_bufr_extract_datetime_subsets_t* self = (grib_accessor_bufr_extract_datetime_subsets_t*)a; + grib_accessor_gen_t::init(len, arg); + int n = 0; - a->length = 0; - self->doExtractSubsets = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); - self->numberOfSubsets = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); - self->extractSubsetList = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); + length_ = 0; + doExtractSubsets_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, n++); + numberOfSubsets_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, n++); + extractSubsetList_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, n++); - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; } -int grib_accessor_class_bufr_extract_datetime_subsets_t::get_native_type(grib_accessor* a) +long grib_accessor_bufr_extract_datetime_subsets_t::get_native_type() { return GRIB_TYPE_LONG; } @@ -87,7 +85,9 @@ static int build_long_array(grib_context* c, grib_handle* h, int compressed, } else { /* uncompressed */ - char keystr[32] = {0,}; + char keystr[32] = { + 0, + }; size_t values_len = 0; for (i = 0; i < numberOfSubsets; ++i) { long lVal = 0; @@ -108,16 +108,22 @@ static int build_long_array(grib_context* c, grib_handle* h, int compressed, static int select_datetime(grib_accessor* a) { + grib_accessor_bufr_extract_datetime_subsets_t* self = (grib_accessor_bufr_extract_datetime_subsets_t*)a; int ret = 0; long compressed = 0; - 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; double julianStart = 0, julianEnd = 0, julianDT = 0; - char start_str[80] = {0,}, - end_str[80] = {0,}, - datetime_str[80] = {0,}; + char start_str[80] = { + 0, + }, + end_str[80] = { + 0, + }, + datetime_str[80] = { + 0, + }; long yearRank, monthRank, dayRank, hourRank, minuteRank, secondRank; long yearStart, monthStart, dayStart, hourStart, minuteStart, secondStart; long yearEnd, monthEnd, dayEnd, hourEnd, minuteEnd, secondEnd; @@ -136,7 +142,7 @@ static int select_datetime(grib_accessor* a) ret = grib_get_long(h, "compressedData", &compressed); if (ret) return ret; - ret = grib_get_long(h, self->numberOfSubsets, &numberOfSubsets); + ret = grib_get_long(h, self->numberOfSubsets_, &numberOfSubsets); if (ret) return ret; subsets = grib_iarray_new(c, numberOfSubsets, 10); @@ -316,11 +322,11 @@ static int select_datetime(grib_accessor* a) if (nsubsets != 0) { long* subsets_ar = grib_iarray_get_array(subsets); - ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets); + 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, self->doExtractSubsets, 1); + ret = grib_set_long(h, self->doExtractSubsets_, 1); if (ret) return ret; } @@ -337,11 +343,11 @@ cleanup: return ret; } -int grib_accessor_class_bufr_extract_datetime_subsets_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_bufr_extract_datetime_subsets_t::pack_long(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; - return select_datetime(a); + return select_datetime(this); } diff --git a/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h index 765786cd2..553866caf 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h +++ b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h @@ -16,18 +16,15 @@ 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_bufr_extract_datetime_subsets_t() : + grib_accessor_gen_t() { class_name_ = "bufr_extract_datetime_subsets"; } 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; + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +public: + const char* doExtractSubsets_; + const char* numberOfSubsets_; + const char* extractSubsetList_; }; diff --git a/src/accessor/grib_accessor_class_bufr_extract_subsets.cc b/src/accessor/grib_accessor_class_bufr_extract_subsets.cc index 3826d0b32..fd3b987aa 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_subsets.cc +++ b/src/accessor/grib_accessor_class_bufr_extract_subsets.cc @@ -11,51 +11,52 @@ #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; - +grib_accessor_bufr_extract_subsets_t _grib_accessor_bufr_extract_subsets{}; +grib_accessor* grib_accessor_bufr_extract_subsets = &_grib_accessor_bufr_extract_subsets; void get_accessors(grib_accessor* a) { + const grib_handle* h = grib_handle_of_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); + int n = 0; - if (self->packAccessor) + if (self->packAccessor_) return; - self->numericValuesAccessor = grib_find_accessor(h, self->numericValues); - self->packAccessor = grib_find_accessor(h, self->pack); + 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) +void grib_accessor_bufr_extract_subsets_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - grib_accessor_bufr_extract_subsets_t* self = (grib_accessor_bufr_extract_subsets_t*)a; + grib_accessor_gen_t::init(len, arg); int n = 0; - 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; + length_ = 0; + numericValues_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, n++); + pack_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, n++); + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + + numericValuesAccessor_ = NULL; + packAccessor_ = NULL; } -int grib_accessor_class_bufr_extract_subsets_t::get_native_type(grib_accessor* a) +long grib_accessor_bufr_extract_subsets_t::get_native_type() { return GRIB_TYPE_LONG; } -int grib_accessor_class_bufr_extract_subsets_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_bufr_extract_subsets_t::pack_long(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); + get_accessors(this); - v[0] = 1; - int err = self->packAccessor->pack_long(v, &l); + v[0] = 1; + int err = 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?"); + grib_context_log(context_, GRIB_LOG_ERROR, "Could not extract subset(s).\n\tHint: Did you forget to set unpack=1?"); return err; } diff --git a/src/accessor/grib_accessor_class_bufr_extract_subsets.h b/src/accessor/grib_accessor_class_bufr_extract_subsets.h index 3015d87ae..3915195c6 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_subsets.h +++ b/src/accessor/grib_accessor_class_bufr_extract_subsets.h @@ -16,19 +16,16 @@ 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_bufr_extract_subsets_t() : + grib_accessor_gen_t() { class_name_ = "bufr_extract_subsets"; } 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; + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +public: + const char* numericValues_; + const char* pack_; + grib_accessor* numericValuesAccessor_; + grib_accessor* packAccessor_; }; diff --git a/src/accessor/grib_accessor_class_bufr_group.cc b/src/accessor/grib_accessor_class_bufr_group.cc index e5b7a0841..781820fa4 100644 --- a/src/accessor/grib_accessor_class_bufr_group.cc +++ b/src/accessor/grib_accessor_class_bufr_group.cc @@ -10,20 +10,19 @@ #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; +grib_accessor_bufr_group_t _grib_accessor_bufr_group{}; +grib_accessor* grib_accessor_bufr_group = &_grib_accessor_bufr_group; - -void grib_accessor_class_bufr_group_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_bufr_group_t::dump(grib_dumper* dumper) { - grib_dump_section(dumper, a, a->sub_section->block); + grib_dump_section(dumper, this, sub_section_->block); } -grib_accessor* grib_accessor_class_bufr_group_t::next(grib_accessor* a, int explore) +grib_accessor* grib_accessor_bufr_group_t::next(grib_accessor* a, int explore) { grib_accessor* next = NULL; if (explore) { - next = a->sub_section->block->first; + next = a->sub_section_->block->first; if (!next) next = a->next_; } @@ -31,8 +30,8 @@ grib_accessor* grib_accessor_class_bufr_group_t::next(grib_accessor* a, int expl next = a->next_; } if (!next) { - if (a->parent->owner) - next = a->parent->owner->cclass->next(a->parent->owner, 0); + if (a->parent_->owner) + next = a->parent_->owner->next(a->parent_->owner, 0); } return next; } diff --git a/src/accessor/grib_accessor_class_bufr_group.h b/src/accessor/grib_accessor_class_bufr_group.h index 758c5c772..8b11dfb7c 100644 --- a/src/accessor/grib_accessor_class_bufr_group.h +++ b/src/accessor/grib_accessor_class_bufr_group.h @@ -16,14 +16,9 @@ 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_bufr_group_t() : + grib_accessor_variable_t() { class_name_ = "bufr_group"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_bufr_group_t{}; } - void dump(grib_accessor*, grib_dumper*) override; - grib_accessor* next(grib_accessor* a, int explore) override; + void dump(grib_dumper*) override; + grib_accessor* next(grib_accessor*, int explore) override; }; diff --git a/src/accessor/grib_accessor_class_bufr_simple_thinning.cc b/src/accessor/grib_accessor_class_bufr_simple_thinning.cc index a74d7a74c..451d3a6c7 100644 --- a/src/accessor/grib_accessor_class_bufr_simple_thinning.cc +++ b/src/accessor/grib_accessor_class_bufr_simple_thinning.cc @@ -11,29 +11,27 @@ #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; +grib_accessor_bufr_simple_thinning_t _grib_accessor_bufr_simple_thinning{}; +grib_accessor* grib_accessor_bufr_simple_thinning = &_grib_accessor_bufr_simple_thinning; - -void grib_accessor_class_bufr_simple_thinning_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_bufr_simple_thinning_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, 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; + grib_accessor_gen_t::init(len, arg); + grib_handle* h = grib_handle_of_accessor(this); + 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++); + length_ = 0; + doExtractSubsets_ = grib_arguments_get_name(h, arg, n++); + numberOfSubsets_ = grib_arguments_get_name(h, arg, n++); + extractSubsetList_ = grib_arguments_get_name(h, arg, n++); + simpleThinningStart_ = grib_arguments_get_name(h, arg, n++); + simpleThinningMissingRadius_ = grib_arguments_get_name(h, arg, n++); + simpleThinningSkip_ = grib_arguments_get_name(h, arg, n++); - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; } -int grib_accessor_class_bufr_simple_thinning_t::get_native_type(grib_accessor* a) +long grib_accessor_bufr_simple_thinning_t::get_native_type() { return GRIB_TYPE_LONG; } @@ -55,21 +53,21 @@ static int apply_thinning(grib_accessor* a) return ret; if (compressed) { long numberOfSubsets = 0; - ret = grib_get_long(h, self->numberOfSubsets, &numberOfSubsets); + ret = grib_get_long(h, self->numberOfSubsets_, &numberOfSubsets); if (ret) return ret; - ret = grib_get_long(h, self->simpleThinningStart, &start); + ret = grib_get_long(h, self->simpleThinningStart_, &start); if (ret) return ret; - ret = grib_get_long(h, self->simpleThinningSkip, &skip); + 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); + ret = grib_get_long(h, self->simpleThinningMissingRadius_, &radius); if (ret) return ret; @@ -82,7 +80,7 @@ static int apply_thinning(grib_accessor* a) if (nsubsets != 0) { subsets_ar = grib_iarray_get_array(subsets); - ret = grib_set_long_array(h, self->extractSubsetList, subsets_ar, nsubsets); + ret = grib_set_long_array(h, self->extractSubsetList_, subsets_ar, nsubsets); grib_context_free(c, subsets_ar); if (ret) return ret; @@ -91,7 +89,7 @@ static int apply_thinning(grib_accessor* a) if (ret) return ret; - ret = grib_set_long(h, self->doExtractSubsets, 1); + ret = grib_set_long(h, self->doExtractSubsets_, 1); if (ret) return ret; } @@ -104,15 +102,13 @@ static int apply_thinning(grib_accessor* a) return ret; } -int grib_accessor_class_bufr_simple_thinning_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_bufr_simple_thinning_t::pack_long(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); + int err = apply_thinning(this); if (err) return err; - return grib_set_long(a->parent->h, self->doExtractSubsets, 1); + return grib_set_long(parent_->h, doExtractSubsets_, 1); } diff --git a/src/accessor/grib_accessor_class_bufr_simple_thinning.h b/src/accessor/grib_accessor_class_bufr_simple_thinning.h index 9b7467914..f28af36f7 100644 --- a/src/accessor/grib_accessor_class_bufr_simple_thinning.h +++ b/src/accessor/grib_accessor_class_bufr_simple_thinning.h @@ -16,21 +16,18 @@ 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_bufr_simple_thinning_t() : + grib_accessor_gen_t() { class_name_ = "bufr_simple_thinning"; } 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; + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +public: + const char* doExtractSubsets_; + const char* numberOfSubsets_; + const char* extractSubsetList_; + const char* simpleThinningStart_; + const char* simpleThinningMissingRadius_; + const char* simpleThinningSkip_; }; diff --git a/src/accessor/grib_accessor_class_bufr_string_values.cc b/src/accessor/grib_accessor_class_bufr_string_values.cc index 31e616b6f..4f3cebeea 100644 --- a/src/accessor/grib_accessor_class_bufr_string_values.cc +++ b/src/accessor/grib_accessor_class_bufr_string_values.cc @@ -12,45 +12,43 @@ #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; +grib_accessor_bufr_string_values_t _grib_accessor_bufr_string_values{}; +grib_accessor* grib_accessor_bufr_string_values = &_grib_accessor_bufr_string_values; - -void grib_accessor_class_bufr_string_values_t::init(grib_accessor* a, const long len, grib_arguments* args) +void grib_accessor_bufr_string_values_t::init(const long len, grib_arguments* args) { - grib_accessor_class_ascii_t::init(a, len, 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; + grib_accessor_ascii_t::init(len, args); + int n = 0; + dataAccessorName_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + dataAccessor_ = NULL; + length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -void grib_accessor_class_bufr_string_values_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_bufr_string_values_t::dump(grib_dumper* dumper) { - grib_dump_string_array(dumper, a, NULL); + grib_dump_string_array(dumper, this, 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); + if (!self->dataAccessor_) { + self->dataAccessor_ = grib_find_accessor(grib_handle_of_accessor(a), self->dataAccessorName_); } - return self->dataAccessor; + return self->dataAccessor_; } -int grib_accessor_class_bufr_string_values_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len) +int grib_accessor_bufr_string_values_t::unpack_string_array(char** buffer, size_t* len) { grib_accessor* data = 0; - grib_context* c = a->context; + grib_context* c = context_; grib_vsarray* stringValues = NULL; size_t l = 0, tl; size_t i, j, n = 0; char** b = buffer; - data = get_accessor(a); + data = get_accessor(this); if (!data) return GRIB_NOT_FOUND; @@ -75,18 +73,18 @@ int grib_accessor_class_bufr_string_values_t::unpack_string_array(grib_accessor* return GRIB_SUCCESS; } -int grib_accessor_class_bufr_string_values_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_bufr_string_values_t::unpack_string(char* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_bufr_string_values_t::value_count(grib_accessor* a, long* rlen) +int grib_accessor_bufr_string_values_t::value_count(long* rlen) { - grib_accessor* descriptors = get_accessor(a); + grib_accessor* descriptors = get_accessor(this); return descriptors->value_count(rlen); } -void grib_accessor_class_bufr_string_values_t::destroy(grib_context* c, grib_accessor* a) +void grib_accessor_bufr_string_values_t::destroy(grib_context* c) { - grib_accessor_class_ascii_t::destroy(c, a); + grib_accessor_ascii_t::destroy(c); } diff --git a/src/accessor/grib_accessor_class_bufr_string_values.h b/src/accessor/grib_accessor_class_bufr_string_values.h index fe6c2acb7..a3c4d50e0 100644 --- a/src/accessor/grib_accessor_class_bufr_string_values.h +++ b/src/accessor/grib_accessor_class_bufr_string_values.h @@ -16,20 +16,17 @@ 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_bufr_string_values_t() : + grib_accessor_ascii_t() { class_name_ = "bufr_string_values"; } 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; + int unpack_string(char*, size_t* len) override; + int unpack_string_array(char**, size_t* len) override; + int value_count(long*) override; + void destroy(grib_context*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +public: + const char* dataAccessorName_; + grib_accessor* dataAccessor_; }; diff --git a/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.cc b/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.cc index 777fa351c..4234f0378 100644 --- a/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.cc +++ b/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.cc @@ -11,43 +11,41 @@ #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; +grib_accessor_bufrdc_expanded_descriptors_t _grib_accessor_bufrdc_expanded_descriptors{}; +grib_accessor* grib_accessor_bufrdc_expanded_descriptors = &_grib_accessor_bufrdc_expanded_descriptors; - -void grib_accessor_class_bufrdc_expanded_descriptors_t::init(grib_accessor* a, const long len, grib_arguments* args) +void grib_accessor_bufrdc_expanded_descriptors_t::init(const long len, grib_arguments* args) { - grib_accessor_class_long_t::init(a, len, 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; + grib_accessor_long_t::init(len, args); + int n = 0; + expandedDescriptors_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + expandedDescriptorsAccessor_ = 0; + length_ = 0; + 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); + if (!self->expandedDescriptorsAccessor_) { + self->expandedDescriptorsAccessor_ = grib_find_accessor(grib_handle_of_accessor(a), self->expandedDescriptors_); } - return self->expandedDescriptorsAccessor; + return self->expandedDescriptorsAccessor_; } -int grib_accessor_class_bufrdc_expanded_descriptors_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_bufrdc_expanded_descriptors_t::unpack_long(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; + grib_context* c = context_; - descriptors = get_accessor(a); + descriptors = get_accessor(this); if (!descriptors) return GRIB_NOT_FOUND; - a->value_count(&lenall); + value_count(&lenall); v = (long*)grib_context_malloc_clear(c, sizeof(long) * lenall); l = lenall; descriptors->unpack_long(v, &l); @@ -62,7 +60,7 @@ int grib_accessor_class_bufrdc_expanded_descriptors_t::unpack_long(grib_accessor return GRIB_SUCCESS; } -int grib_accessor_class_bufrdc_expanded_descriptors_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len) +int grib_accessor_bufrdc_expanded_descriptors_t::unpack_string_array(char** buffer, size_t* len) { int err = 0; grib_accessor* descriptors = 0; @@ -70,13 +68,15 @@ int grib_accessor_class_bufrdc_expanded_descriptors_t::unpack_string_array(grib_ long lenall = 0; size_t i = 0; long* v = 0; - char buf[25] = {0,}; - grib_context* c = a->context; + char buf[25] = { + 0, + }; + grib_context* c = context_; - descriptors = get_accessor(a); + descriptors = get_accessor(this); if (!descriptors) return GRIB_NOT_FOUND; - err = a->value_count(&lenall); + err = value_count(&lenall); if (err) return err; l = lenall; if (l > *len) return GRIB_ARRAY_TOO_SMALL; @@ -95,14 +95,14 @@ int grib_accessor_class_bufrdc_expanded_descriptors_t::unpack_string_array(grib_ return GRIB_SUCCESS; } -int grib_accessor_class_bufrdc_expanded_descriptors_t::value_count(grib_accessor* a, long* rlen) +int grib_accessor_bufrdc_expanded_descriptors_t::value_count(long* rlen) { - grib_accessor* descriptors = get_accessor(a); + grib_accessor* descriptors = get_accessor(this); return descriptors->value_count(rlen); } -void grib_accessor_class_bufrdc_expanded_descriptors_t::destroy(grib_context* c, grib_accessor* a) +void grib_accessor_bufrdc_expanded_descriptors_t::destroy(grib_context* c) { - grib_accessor_class_long_t::destroy(c, a); + grib_accessor_long_t::destroy(c); } diff --git a/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h b/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h index 92cf595ad..c20cd2f74 100644 --- a/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h +++ b/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h @@ -16,19 +16,16 @@ 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_bufrdc_expanded_descriptors_t() : + grib_accessor_long_t() { class_name_ = "bufrdc_expanded_descriptors"; } 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; + int unpack_long(long* val, size_t* len) override; + int unpack_string_array(char**, size_t* len) override; + int value_count(long*) override; + void destroy(grib_context*) override; + void init(const long, grib_arguments*) override; + +public: + const char* expandedDescriptors_; + grib_accessor* expandedDescriptorsAccessor_; }; diff --git a/src/accessor/grib_accessor_class_bytes.cc b/src/accessor/grib_accessor_class_bytes.cc index b95b2338a..6ae039dcd 100644 --- a/src/accessor/grib_accessor_class_bytes.cc +++ b/src/accessor/grib_accessor_class_bytes.cc @@ -10,28 +10,27 @@ #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; +grib_accessor_bytes_t _grib_accessor_bytes{}; +grib_accessor* grib_accessor_bytes = &_grib_accessor_bytes; - -void grib_accessor_class_bytes_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_bytes_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); + grib_accessor_gen_t::init(len, arg); /*grib_accessor_signed* self = (grib_accessor_signed*)a; */ - a->length = len; - Assert(a->length >= 0); + length_ = len; + Assert(length_ >= 0); } -int grib_accessor_class_bytes_t::get_native_type(grib_accessor* a) +long grib_accessor_bytes_t::get_native_type() { return GRIB_TYPE_BYTES; } -int grib_accessor_class_bytes_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_bytes_t::compare(grib_accessor* b) { int retval = GRIB_SUCCESS; - size_t alen = (size_t)a->byte_count(); + size_t alen = (size_t)byte_count(); size_t blen = (size_t)b->byte_count(); if (alen != blen) return GRIB_COUNT_MISMATCH; @@ -39,12 +38,12 @@ int grib_accessor_class_bytes_t::compare(grib_accessor* a, grib_accessor* b) return retval; } -int grib_accessor_class_bytes_t::unpack_string(grib_accessor* a, char* v, size_t* len) +int grib_accessor_bytes_t::unpack_string(char* v, size_t* len) { unsigned char* p = NULL; char* s = v; long i = 0; - const long length = a->byte_count(); + const long length = byte_count(); const long slength = 2 * length; if (*len < (size_t)slength) { @@ -52,7 +51,7 @@ int grib_accessor_class_bytes_t::unpack_string(grib_accessor* a, char* v, size_t return GRIB_BUFFER_TOO_SMALL; } - p = grib_handle_of_accessor(a)->buffer->data + a->byte_offset(); + p = grib_handle_of_accessor(this)->buffer->data + byte_offset(); for (i = 0; i < length; i++) { snprintf(s, INT_MAX, "%02x", *(p++)); s += 2; @@ -63,15 +62,15 @@ int grib_accessor_class_bytes_t::unpack_string(grib_accessor* a, char* v, size_t return GRIB_SUCCESS; } -int grib_accessor_class_bytes_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_bytes_t::pack_string(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; + grib_context* c = context_; + size_t nbytes = length_; const size_t expected_blen = nbytes; const size_t expected_slen = 2 * expected_blen; unsigned char* bytearray = NULL; @@ -80,7 +79,7 @@ int grib_accessor_class_bytes_t::pack_string(grib_accessor* a, const char* 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); + __func__, name_, expected_blen, expected_slen, *len); return GRIB_WRONG_ARRAY_SIZE; } @@ -99,7 +98,7 @@ int grib_accessor_class_bytes_t::pack_string(grib_accessor* a, const char* val, } /* Forward to base class to pack the byte array */ - err = grib_accessor_class_gen_t::pack_bytes(a, bytearray, &nbytes); + err = grib_accessor_gen_t::pack_bytes(bytearray, &nbytes); grib_context_free(c, bytearray); return err; } diff --git a/src/accessor/grib_accessor_class_bytes.h b/src/accessor/grib_accessor_class_bytes.h index 676cf55c4..d13c15c8a 100644 --- a/src/accessor/grib_accessor_class_bytes.h +++ b/src/accessor/grib_accessor_class_bytes.h @@ -16,17 +16,12 @@ 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_bytes_t() : + grib_accessor_gen_t() { class_name_ = "bytes"; } 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; + long get_native_type() override; + int pack_string(const char*, size_t* len) override; + int unpack_string(char*, size_t* len) override; + void init(const long, grib_arguments*) override; + int compare(grib_accessor*) override; }; diff --git a/src/accessor/grib_accessor_class_cf_var_name.cc b/src/accessor/grib_accessor_class_cf_var_name.cc index 41f42ff30..93e808c4f 100644 --- a/src/accessor/grib_accessor_class_cf_var_name.cc +++ b/src/accessor/grib_accessor_class_cf_var_name.cc @@ -10,40 +10,38 @@ #include "grib_accessor_class_cf_var_name.h" -grib_accessor_class_cf_var_name_t _grib_accessor_class_cf_var_name{ "cf_var_name" }; -grib_accessor_class* grib_accessor_class_cf_var_name = &_grib_accessor_class_cf_var_name; +grib_accessor_cf_var_name_t _grib_accessor_cf_var_name{}; +grib_accessor* grib_accessor_cf_var_name = &_grib_accessor_cf_var_name; - -void grib_accessor_class_cf_var_name_t::init(grib_accessor* a, const long l, grib_arguments* arg) +void grib_accessor_cf_var_name_t::init(const long l, grib_arguments* arg) { - grib_accessor_class_ascii_t::init(a, l, arg); - - grib_accessor_cf_var_name_t* self = (grib_accessor_cf_var_name_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - - self->defaultKey = grib_arguments_get_name(h, arg, 0); + grib_accessor_ascii_t::init(l, arg); + grib_handle* h = grib_handle_of_accessor(this); + defaultKey_ = grib_arguments_get_name(h, arg, 0); } -int grib_accessor_class_cf_var_name_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_cf_var_name_t::unpack_string(char* val, size_t* len) { - grib_accessor_cf_var_name_t* self = (grib_accessor_cf_var_name_t*)a; - - grib_handle* h = grib_handle_of_accessor(a); - char defaultKey[256] = {0,}; - size_t size = sizeof(defaultKey) / sizeof(*defaultKey); + grib_handle* h = grib_handle_of_accessor(this); + char defaultKey[256] = { + 0, + }; + size_t size = sizeof(defaultKey) / sizeof(*defaultKey); char* pDefaultKey = defaultKey; - int err = grib_get_string(h, self->defaultKey, defaultKey, &size); + int err = grib_get_string(h, defaultKey_, defaultKey, &size); if (err) return err; Assert(size > 0); Assert(strlen(defaultKey) > 0); - if ( STR_EQUAL(defaultKey, "~") || isdigit(defaultKey[0]) ) { + if (STR_EQUAL(defaultKey, "~") || isdigit(defaultKey[0])) { // NetCDF variables cannot start with a digit long paramId = 0; - err = grib_get_long(h, "paramId", ¶mId); - if (err) snprintf(val, 1024, "%s", "unknown"); - else snprintf(val, 1024, "p%ld", paramId); + err = grib_get_long(h, "paramId", ¶mId); + if (err) + snprintf(val, 1024, "%s", "unknown"); + else + snprintf(val, 1024, "p%ld", paramId); } else { snprintf(val, 1024, "%s", pDefaultKey); @@ -53,7 +51,7 @@ int grib_accessor_class_cf_var_name_t::unpack_string(grib_accessor* a, char* val return GRIB_SUCCESS; } -size_t grib_accessor_class_cf_var_name_t::string_length(grib_accessor* a) +size_t grib_accessor_cf_var_name_t::string_length() { return 1024; } diff --git a/src/accessor/grib_accessor_class_cf_var_name.h b/src/accessor/grib_accessor_class_cf_var_name.h index aa0007a54..f536bfec9 100644 --- a/src/accessor/grib_accessor_class_cf_var_name.h +++ b/src/accessor/grib_accessor_class_cf_var_name.h @@ -15,16 +15,14 @@ class grib_accessor_cf_var_name_t : public grib_accessor_ascii_t { public: - /* Members defined in cf_var_name */ - const char* defaultKey; -}; - -class grib_accessor_class_cf_var_name_t : public grib_accessor_class_ascii_t -{ -public: - grib_accessor_class_cf_var_name_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor_cf_var_name_t() : + grib_accessor_ascii_t() { class_name_ = "cf_var_name"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_cf_var_name_t{}; } - int unpack_string(grib_accessor*, char*, size_t* len) override; - size_t string_length(grib_accessor*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + void init(const long, grib_arguments*) override; + +public: + /* Members defined in cf_var_name */ + const char* defaultKey_; }; diff --git a/src/accessor/grib_accessor_class_change_alternative_row_scanning.cc b/src/accessor/grib_accessor_class_change_alternative_row_scanning.cc index afd372549..67bb0eca8 100644 --- a/src/accessor/grib_accessor_class_change_alternative_row_scanning.cc +++ b/src/accessor/grib_accessor_class_change_alternative_row_scanning.cc @@ -10,32 +10,28 @@ #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; +grib_accessor_change_alternative_row_scanning_t _grib_accessor_change_alternative_row_scanning{}; +grib_accessor* grib_accessor_change_alternative_row_scanning = &_grib_accessor_change_alternative_row_scanning; - -void grib_accessor_class_change_alternative_row_scanning_t::init(grib_accessor* a, const long len, grib_arguments* args) +void grib_accessor_change_alternative_row_scanning_t::init(const long len, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, len, args); - grib_accessor_change_alternative_row_scanning_t* self = (grib_accessor_change_alternative_row_scanning_t*)a; - + grib_accessor_gen_t::init(len, args); int n = 0; - 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; + values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + Ni_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + Nj_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + alternativeRowScanning_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + length_ = 0; } -int grib_accessor_class_change_alternative_row_scanning_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_change_alternative_row_scanning_t::pack_long(const long* val, size_t* len) { - grib_accessor_change_alternative_row_scanning_t* self = (grib_accessor_change_alternative_row_scanning_t*)a; - int err = 0; - const grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); + const grib_context* c = context_; + grib_handle* h = grib_handle_of_accessor(this); long i, j, jr, theEnd, Ni, Nj, k, kp, alternativeRowScanning; size_t size = 0; double* values = NULL; @@ -45,23 +41,23 @@ int grib_accessor_class_change_alternative_row_scanning_t::pack_long(grib_access 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); + if (grib_is_missing(h, Ni_, &err) && !err) { + grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: Key %s cannot be 'missing'!", 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); + if (grib_is_missing(h, Nj_, &err) && !err) { + grib_context_log(c, GRIB_LOG_ERROR, "change_alternative_row_scanning: Key %s cannot be 'missing'!", Nj_); return GRIB_WRONG_GRID; } - if ((err = grib_get_long_internal(h, self->Ni, &Ni)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, Ni_, &Ni)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->Nj, &Nj)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, Nj_, &Nj)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->alternativeRowScanning, &alternativeRowScanning)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, alternativeRowScanning_, &alternativeRowScanning)) != GRIB_SUCCESS) return err; - if ((err = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + if ((err = grib_get_size(h, values_, &size)) != GRIB_SUCCESS) return err; if (size > (size_t)(Ni * Nj)) { @@ -73,7 +69,7 @@ int grib_accessor_class_change_alternative_row_scanning_t::pack_long(grib_access if (!values) return GRIB_OUT_OF_MEMORY; - if ((err = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { + if ((err = grib_get_double_array_internal(h, values_, values, &size)) != GRIB_SUCCESS) { grib_context_free(c, values); return err; } @@ -93,12 +89,12 @@ int grib_accessor_class_change_alternative_row_scanning_t::pack_long(grib_access } } alternativeRowScanning = !alternativeRowScanning; - if ((err = grib_set_long_internal(h, self->alternativeRowScanning, alternativeRowScanning)) != GRIB_SUCCESS) { + if ((err = grib_set_long_internal(h, 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) { + if ((err = grib_set_double_array_internal(h, values_, values, size)) != GRIB_SUCCESS) { grib_context_free(c, values); return err; } @@ -108,12 +104,12 @@ int grib_accessor_class_change_alternative_row_scanning_t::pack_long(grib_access return GRIB_SUCCESS; } -int grib_accessor_class_change_alternative_row_scanning_t::get_native_type(grib_accessor* a) +long grib_accessor_change_alternative_row_scanning_t::get_native_type() { return GRIB_TYPE_LONG; } -int grib_accessor_class_change_alternative_row_scanning_t::unpack_long(grib_accessor* a, long* v, size_t* len) +int grib_accessor_change_alternative_row_scanning_t::unpack_long(long* v, size_t* len) { /* Decoding this accessor doesn't make sense so we return a dummy value */ *v = -1; diff --git a/src/accessor/grib_accessor_class_change_alternative_row_scanning.h b/src/accessor/grib_accessor_class_change_alternative_row_scanning.h index f889931a0..85a375046 100644 --- a/src/accessor/grib_accessor_class_change_alternative_row_scanning.h +++ b/src/accessor/grib_accessor_class_change_alternative_row_scanning.h @@ -16,20 +16,17 @@ 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_change_alternative_row_scanning_t() : + grib_accessor_gen_t() { class_name_ = "change_alternative_row_scanning"; } 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; + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* values_; + const char* Ni_; + const char* Nj_; + const char* alternativeRowScanning_; }; diff --git a/src/accessor/grib_accessor_class_change_scanning_direction.cc b/src/accessor/grib_accessor_class_change_scanning_direction.cc index e98df6f93..e4f618d20 100644 --- a/src/accessor/grib_accessor_class_change_scanning_direction.cc +++ b/src/accessor/grib_accessor_class_change_scanning_direction.cc @@ -10,75 +10,72 @@ #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; +grib_accessor_change_scanning_direction_t _grib_accessor_change_scanning_direction{}; +grib_accessor* grib_accessor_change_scanning_direction = &_grib_accessor_change_scanning_direction; - -void grib_accessor_class_change_scanning_direction_t::init(grib_accessor* a, const long len, grib_arguments* args) +void grib_accessor_change_scanning_direction_t::init(const long len, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, len, args); - grib_accessor_change_scanning_direction_t* self = (grib_accessor_change_scanning_direction_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_gen_t::init(len, args); + grib_handle* h = grib_handle_of_accessor(this); + int n = 0; - int n = 0; - self->values = grib_arguments_get_name(h, args, n++); - self->Ni = grib_arguments_get_name(h, args, n++); - self->Nj = grib_arguments_get_name(h, args, n++); - self->i_scans_negatively = grib_arguments_get_name(h, args, n++); - self->j_scans_positively = grib_arguments_get_name(h, args, n++); - self->first = grib_arguments_get_name(h, args, n++); - self->last = grib_arguments_get_name(h, args, n++); - self->axis = grib_arguments_get_name(h, args, n++); + values_ = grib_arguments_get_name(h, args, n++); + Ni_ = grib_arguments_get_name(h, args, n++); + Nj_ = grib_arguments_get_name(h, args, n++); + i_scans_negatively_ = grib_arguments_get_name(h, args, n++); + j_scans_positively_ = grib_arguments_get_name(h, args, n++); + first_ = grib_arguments_get_name(h, args, n++); + last_ = grib_arguments_get_name(h, args, n++); + axis_ = grib_arguments_get_name(h, args, n++); - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + length_ = 0; } -int grib_accessor_class_change_scanning_direction_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_change_scanning_direction_t::pack_long(const long* val, size_t* len) { int err = 0; long i, j, jr, theEnd, Ni, Nj, k, kp; double tmp; - long iScansNegatively = 0; - long jScansPositively = 0; - double first = 0; - double last = 0; - size_t size = 0; - double* values = NULL; - 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; + long iScansNegatively = 0; + long jScansPositively = 0; + double first = 0; + double last = 0; + size_t size = 0; + double* values = NULL; + const grib_context* c = context_; + grib_handle* h = grib_handle_of_accessor(this); + const char* cclass_name = class_name_; if (*val == 0) return GRIB_SUCCESS; /* Make sure Ni / Nj are not missing */ - if (grib_is_missing(h, self->Ni, &err) && !err) { - grib_context_log(c, GRIB_LOG_ERROR, "%s: Key %s cannot be 'missing'!", cclass_name, self->Ni); + if (grib_is_missing(h, Ni_, &err) && !err) { + grib_context_log(c, GRIB_LOG_ERROR, "%s: Key %s cannot be 'missing'!", cclass_name, Ni_); return GRIB_WRONG_GRID; } - if (grib_is_missing(h, self->Nj, &err) && !err) { - grib_context_log(c, GRIB_LOG_ERROR, "%s: Key %s cannot be 'missing'!", cclass_name, self->Nj); + if (grib_is_missing(h, Nj_, &err) && !err) { + grib_context_log(c, GRIB_LOG_ERROR, "%s: Key %s cannot be 'missing'!", cclass_name, Nj_); return GRIB_WRONG_GRID; } - if ((err = grib_get_long_internal(h, self->Ni, &Ni)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, Ni_, &Ni)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->Nj, &Nj)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, Nj_, &Nj)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->i_scans_negatively, &iScansNegatively)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, i_scans_negatively_, &iScansNegatively)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->j_scans_positively, &jScansPositively)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, j_scans_positively_, &jScansPositively)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->first, &first)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, first_, &first)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->last, &last)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, last_, &last)) != GRIB_SUCCESS) return err; - if ((err = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + if ((err = grib_get_size(h, values_, &size)) != GRIB_SUCCESS) return err; if (size > Ni * Nj) { @@ -90,15 +87,15 @@ int grib_accessor_class_change_scanning_direction_t::pack_long(grib_accessor* a, if (!values) return GRIB_OUT_OF_MEMORY; - if ((err = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { + if ((err = grib_get_double_array_internal(h, values_, values, &size)) != GRIB_SUCCESS) { grib_context_free(c, values); return err; } - Assert(self->axis); - Assert(strcmp(self->axis, "x") == 0 || strcmp(self->axis, "y") == 0); + Assert(axis_); + Assert(strcmp(axis_, "x") == 0 || strcmp(axis_, "y") == 0); - if (self->axis[0] == 'x') { + if (axis_[0] == 'x') { theEnd = Ni / 2; for (j = 0; j < Nj; j++) { jr = Ni * j; @@ -111,7 +108,7 @@ int grib_accessor_class_change_scanning_direction_t::pack_long(grib_accessor* a, } } iScansNegatively = !iScansNegatively; - if ((err = grib_set_long_internal(h, self->i_scans_negatively, iScansNegatively)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(h, i_scans_negatively_, iScansNegatively)) != GRIB_SUCCESS) return err; } else { @@ -128,19 +125,19 @@ int grib_accessor_class_change_scanning_direction_t::pack_long(grib_accessor* a, } } jScansPositively = !jScansPositively; - if ((err = grib_set_long_internal(h, self->j_scans_positively, jScansPositively)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(h, j_scans_positively_, jScansPositively)) != GRIB_SUCCESS) return err; } - if ((err = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) { + if ((err = grib_set_double_array_internal(h, values_, values, size)) != GRIB_SUCCESS) { grib_context_free(c, values); return err; } - if ((err = grib_set_double_internal(h, self->first, last)) != GRIB_SUCCESS) + if ((err = grib_set_double_internal(h, first_, last)) != GRIB_SUCCESS) return err; - if ((err = grib_set_double_internal(h, self->last, first)) != GRIB_SUCCESS) + if ((err = grib_set_double_internal(h, last_, first)) != GRIB_SUCCESS) return err; grib_context_free(c, values); @@ -148,12 +145,12 @@ int grib_accessor_class_change_scanning_direction_t::pack_long(grib_accessor* a, return GRIB_SUCCESS; } -int grib_accessor_class_change_scanning_direction_t::get_native_type(grib_accessor* a) +long grib_accessor_change_scanning_direction_t::get_native_type() { return GRIB_TYPE_LONG; } -int grib_accessor_class_change_scanning_direction_t::unpack_long(grib_accessor* a, long* v, size_t* len) +int grib_accessor_change_scanning_direction_t::unpack_long(long* v, size_t* len) { /* ECC-976: decoding this accessor doesn't make sense so we return a dummy value */ *v = -1; diff --git a/src/accessor/grib_accessor_class_change_scanning_direction.h b/src/accessor/grib_accessor_class_change_scanning_direction.h index ead274485..f3eccdc61 100644 --- a/src/accessor/grib_accessor_class_change_scanning_direction.h +++ b/src/accessor/grib_accessor_class_change_scanning_direction.h @@ -16,24 +16,21 @@ 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_change_scanning_direction_t() : + grib_accessor_gen_t() { class_name_ = "change_scanning_direction"; } 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; + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + 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_; }; diff --git a/src/accessor/grib_accessor_class_check_internal_version.cc b/src/accessor/grib_accessor_class_check_internal_version.cc index 3dc480820..86aec25f3 100644 --- a/src/accessor/grib_accessor_class_check_internal_version.cc +++ b/src/accessor/grib_accessor_class_check_internal_version.cc @@ -10,22 +10,21 @@ #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; - +grib_accessor_check_internal_version_t _grib_accessor_check_internal_version{}; +grib_accessor* grib_accessor_check_internal_version = &_grib_accessor_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) +void grib_accessor_check_internal_version_t::init(const long l, grib_arguments* args) { - grib_accessor_class_ascii_t::init(a, l, args); + grib_accessor_ascii_t::init(l, 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); + grib_handle* h = grib_handle_of_accessor(this); const char* s_defn_version = grib_arguments_get_name(h, args, 0); Assert(s_defn_version); @@ -41,13 +40,13 @@ void grib_accessor_class_check_internal_version_t::init(grib_accessor* a, const } } -int grib_accessor_class_check_internal_version_t::value_count(grib_accessor* a, long* count) +int grib_accessor_check_internal_version_t::value_count(long* count) { *count = 1; return 0; } -size_t grib_accessor_class_check_internal_version_t::string_length(grib_accessor* a) +size_t grib_accessor_check_internal_version_t::string_length() { return 255; } diff --git a/src/accessor/grib_accessor_class_check_internal_version.h b/src/accessor/grib_accessor_class_check_internal_version.h index d37b57282..b3edc0ee0 100644 --- a/src/accessor/grib_accessor_class_check_internal_version.h +++ b/src/accessor/grib_accessor_class_check_internal_version.h @@ -16,15 +16,10 @@ 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_check_internal_version_t() : + grib_accessor_ascii_t() { class_name_ = "check_internal_version"; } 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; + size_t string_length() override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_closest_date.cc b/src/accessor/grib_accessor_class_closest_date.cc index 5113de7ae..46db8c1f3 100644 --- a/src/accessor/grib_accessor_class_closest_date.cc +++ b/src/accessor/grib_accessor_class_closest_date.cc @@ -11,51 +11,47 @@ #include "grib_accessor_class_closest_date.h" #include -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; +grib_accessor_closest_date_t _grib_accessor_closest_date{}; +grib_accessor* grib_accessor_closest_date = &_grib_accessor_closest_date; - -void grib_accessor_class_closest_date_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_closest_date_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_closest_date_t* self = (grib_accessor_closest_date_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_double_t::init(l, c); + grib_handle* h = grib_handle_of_accessor(this); + int n = 0; - self->dateLocal = grib_arguments_get_name(h, c, n++); - self->timeLocal = grib_arguments_get_name(h, c, n++); - self->numForecasts = grib_arguments_get_name(h, c, n++); - self->year = grib_arguments_get_name(h, c, n++); - self->month = grib_arguments_get_name(h, c, n++); - self->day = grib_arguments_get_name(h, c, n++); - self->hour = grib_arguments_get_name(h, c, n++); - self->minute = grib_arguments_get_name(h, c, n++); - self->second = grib_arguments_get_name(h, c, n++); + dateLocal_ = grib_arguments_get_name(h, c, n++); + timeLocal_ = grib_arguments_get_name(h, c, n++); + numForecasts_ = grib_arguments_get_name(h, c, n++); + year_ = grib_arguments_get_name(h, c, n++); + month_ = grib_arguments_get_name(h, c, n++); + day_ = grib_arguments_get_name(h, c, n++); + hour_ = grib_arguments_get_name(h, c, n++); + minute_ = grib_arguments_get_name(h, c, n++); + second_ = grib_arguments_get_name(h, c, n++); - a->length = 0; + length_ = 0; } -void grib_accessor_class_closest_date_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_closest_date_t::dump(grib_dumper* dumper) { - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); } -int grib_accessor_class_closest_date_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_closest_date_t::unpack_long(long* val, size_t* len) { int ret = 0; double v = 0; - ret = unpack_double(a, &v, len); + ret = unpack_double(&v, len); *val = (long)v; return ret; } /* Sets val to the 'index' of the closes date */ -int grib_accessor_class_closest_date_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_closest_date_t::unpack_double(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 */ /* These relate to the date and time in Section 1 */ @@ -68,56 +64,56 @@ int grib_accessor_class_closest_date_t::unpack_double(grib_accessor* a, double* /* These relate to the forecast dates and times in Section 4 */ long *yearArray, *monthArray, *dayArray, *hourArray, *minuteArray, *secondArray; - grib_handle* h = grib_handle_of_accessor(a); - const grib_context* c = a->context; + grib_handle* h = grib_handle_of_accessor(this); + const grib_context* c = context_; *val = -1; /* initialise to an invalid index */ - if ((err = grib_get_long_internal(h, self->numForecasts, &num_forecasts)) != GRIB_SUCCESS) return err; + if ((err = grib_get_long_internal(h, numForecasts_, &num_forecasts)) != GRIB_SUCCESS) return err; Assert(num_forecasts > 1); - if ((err = grib_get_long(h, self->dateLocal, &ymdLocal)) != GRIB_SUCCESS) return err; + if ((err = grib_get_long(h, dateLocal_, &ymdLocal)) != GRIB_SUCCESS) return err; yearLocal = ymdLocal / 10000; ymdLocal %= 10000; monthLocal = ymdLocal / 100; ymdLocal %= 100; dayLocal = ymdLocal; - if ((err = grib_get_long(h, self->timeLocal, &hmsLocal)) != GRIB_SUCCESS) return err; + if ((err = grib_get_long(h, timeLocal_, &hmsLocal)) != GRIB_SUCCESS) return err; hourLocal = hmsLocal / 100; hmsLocal %= 100; minuteLocal = hmsLocal / 100; hmsLocal %= 100; secondLocal = hmsLocal; - if ((err = grib_get_size(h, self->year, &size)) != GRIB_SUCCESS) return err; + if ((err = grib_get_size(h, year_, &size)) != GRIB_SUCCESS) return err; Assert(size == (size_t)num_forecasts); yearArray = (long*)grib_context_malloc_clear(c, size * sizeof(long)); - if ((err = grib_get_long_array_internal(h, self->year, yearArray, &size)) != GRIB_SUCCESS) return err; + if ((err = grib_get_long_array_internal(h, year_, yearArray, &size)) != GRIB_SUCCESS) return err; - if ((err = grib_get_size(h, self->month, &size)) != GRIB_SUCCESS) return err; + if ((err = grib_get_size(h, month_, &size)) != GRIB_SUCCESS) return err; Assert(size == (size_t)num_forecasts); monthArray = (long*)grib_context_malloc_clear(c, size * sizeof(long)); - if ((err = grib_get_long_array_internal(h, self->month, monthArray, &size)) != GRIB_SUCCESS) return err; + if ((err = grib_get_long_array_internal(h, month_, monthArray, &size)) != GRIB_SUCCESS) return err; - if ((err = grib_get_size(h, self->day, &size)) != GRIB_SUCCESS) return err; + if ((err = grib_get_size(h, day_, &size)) != GRIB_SUCCESS) return err; Assert(size == (size_t)num_forecasts); dayArray = (long*)grib_context_malloc_clear(c, size * sizeof(long)); - if ((err = grib_get_long_array_internal(h, self->day, dayArray, &size)) != GRIB_SUCCESS) return err; + if ((err = grib_get_long_array_internal(h, day_, dayArray, &size)) != GRIB_SUCCESS) return err; - if ((err = grib_get_size(h, self->hour, &size)) != GRIB_SUCCESS) return err; + if ((err = grib_get_size(h, hour_, &size)) != GRIB_SUCCESS) return err; Assert(size == (size_t)num_forecasts); hourArray = (long*)grib_context_malloc_clear(c, size * sizeof(long)); - if ((err = grib_get_long_array_internal(h, self->hour, hourArray, &size)) != GRIB_SUCCESS) return err; + if ((err = grib_get_long_array_internal(h, hour_, hourArray, &size)) != GRIB_SUCCESS) return err; - if ((err = grib_get_size(h, self->minute, &size)) != GRIB_SUCCESS) return err; + if ((err = grib_get_size(h, minute_, &size)) != GRIB_SUCCESS) return err; Assert(size == (size_t)num_forecasts); minuteArray = (long*)grib_context_malloc_clear(c, size * sizeof(long)); - if ((err = grib_get_long_array_internal(h, self->minute, minuteArray, &size)) != GRIB_SUCCESS) return err; + if ((err = grib_get_long_array_internal(h, minute_, minuteArray, &size)) != GRIB_SUCCESS) return err; - if ((err = grib_get_size(h, self->second, &size)) != GRIB_SUCCESS) return err; + if ((err = grib_get_size(h, second_, &size)) != GRIB_SUCCESS) return err; Assert(size == (size_t)num_forecasts); secondArray = (long*)grib_context_malloc_clear(c, size * sizeof(long)); - if ((err = grib_get_long_array_internal(h, self->second, secondArray, &size)) != GRIB_SUCCESS) return err; + if ((err = grib_get_long_array_internal(h, second_, secondArray, &size)) != GRIB_SUCCESS) return err; grib_datetime_to_julian(yearLocal, monthLocal, dayLocal, hourLocal, minuteLocal, secondLocal, &jLocal); for (i = 0; i < size; ++i) { diff --git a/src/accessor/grib_accessor_class_closest_date.h b/src/accessor/grib_accessor_class_closest_date.h index ebd3cb6d4..79c84d291 100644 --- a/src/accessor/grib_accessor_class_closest_date.h +++ b/src/accessor/grib_accessor_class_closest_date.h @@ -16,25 +16,22 @@ 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_closest_date_t() : + grib_accessor_double_t() { class_name_ = "closest_date"; } 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; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +private: + 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_; }; diff --git a/src/accessor/grib_accessor_class_codeflag.cc b/src/accessor/grib_accessor_class_codeflag.cc index 49f291d77..95ca77364 100644 --- a/src/accessor/grib_accessor_class_codeflag.cc +++ b/src/accessor/grib_accessor_class_codeflag.cc @@ -11,17 +11,15 @@ #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; +grib_accessor_codeflag_t _grib_accessor_codeflag{}; +grib_accessor* grib_accessor_codeflag = &_grib_accessor_codeflag; - -void grib_accessor_class_codeflag_t::init(grib_accessor* a, const long len, grib_arguments* param) +void grib_accessor_codeflag_t::init(const long len, grib_arguments* param) { - grib_accessor_class_unsigned_t::init(a, len, 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); + grib_accessor_unsigned_t::init(len, param); + length_ = len; + tablename_ = grib_arguments_get_string(grib_handle_of_accessor(this), param, 0); + Assert(length_ >= 0); } static int test_bit(long a, long b) @@ -33,7 +31,7 @@ static int test_bit(long a, long b) static 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; + FILE* f = NULL; char fname[1024]; char bval[50]; char num[50]; @@ -43,26 +41,26 @@ static int grib_get_codeflag(grib_accessor* a, long code, char* codename) int j = 0; int err = 0; - err = grib_recompose_name(grib_handle_of_accessor(a), NULL, self->tablename, fname, 1); + err = grib_recompose_name(grib_handle_of_accessor(a), NULL, self->tablename_, fname, 1); if (err) { - strncpy(fname, self->tablename, sizeof(fname) - 1); + 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); + 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); + 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); + // strcpy(codename, tablename_ ); // strcat(codename,": "); // j = strlen(codename); @@ -70,7 +68,7 @@ static int grib_get_codeflag(grib_accessor* a, long code, char* codename) sscanf(line, "%49s %49s", num, bval); if (num[0] != '#') { - if ((test_bit(code, a->length * 8 - atol(num)) > 0) == atol(bval)) { + if ((test_bit(code, self->length_ * 8 - atol(num)) > 0) == atol(bval)) { size_t linelen = strlen(line); codename[j++] = '('; codename[j++] = num[0]; @@ -99,24 +97,27 @@ static int grib_get_codeflag(grib_accessor* a, long code, char* codename) return GRIB_SUCCESS; } -int grib_accessor_class_codeflag_t::value_count(grib_accessor* a, long* count) +int grib_accessor_codeflag_t::value_count(long* count) { *count = 1; return 0; } -void grib_accessor_class_codeflag_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_codeflag_t::dump(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,}; + 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_recompose_name(grib_handle_of_accessor(this), NULL, tablename_, fname, 1); + unpack_long(&v, &llen); + grib_get_codeflag(this, v, flagname); - grib_dump_bits(dumper, a, flagname); + grib_dump_bits(dumper, this, flagname); } diff --git a/src/accessor/grib_accessor_class_codeflag.h b/src/accessor/grib_accessor_class_codeflag.h index 82c8cc77b..fa394a650 100644 --- a/src/accessor/grib_accessor_class_codeflag.h +++ b/src/accessor/grib_accessor_class_codeflag.h @@ -16,16 +16,13 @@ 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_codeflag_t() : + grib_accessor_unsigned_t() { class_name_ = "codeflag"; } 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; + int value_count(long*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +public: + const char* tablename_; }; diff --git a/src/accessor/grib_accessor_class_codetable.cc b/src/accessor/grib_accessor_class_codetable.cc index 9a9df9040..884bbfe3b 100644 --- a/src/accessor/grib_accessor_class_codetable.cc +++ b/src/accessor/grib_accessor_class_codetable.cc @@ -11,10 +11,8 @@ #include "grib_accessor_class_codetable.h" #include - -grib_accessor_class_codetable_t _grib_accessor_class_codetable("codetable"); -grib_accessor_class* grib_accessor_class_codetable = &_grib_accessor_class_codetable; - +grib_accessor_codetable_t _grib_accessor_codetable{}; +grib_accessor* grib_accessor_codetable = &_grib_accessor_codetable; #if GRIB_PTHREADS static pthread_once_t once = PTHREAD_ONCE_INIT; @@ -34,7 +32,7 @@ static omp_nest_lock_t mutex1; static void init_mutex() { - GRIB_OMP_CRITICAL(lock_grib_accessor_class_codetable_c) + GRIB_OMP_CRITICAL(lock_grib_accessor_codetable_c) { if (once == 0) { omp_init_nest_lock(&mutex1); @@ -46,16 +44,17 @@ static void init_mutex() static int grib_load_codetable(grib_context* c, const char* filename, const char* recomposed_name, size_t size, grib_codetable* t); -void grib_accessor_class_codetable_t::init(grib_accessor* a, const long len, grib_arguments* params) +void grib_accessor_codetable_t::init(const long len, grib_arguments* params) { - grib_accessor_class_unsigned_t::init(a, len, params); + grib_accessor_unsigned_t::init(len, params); - int n = 0; - long new_len = len; - grib_handle* hand = grib_handle_of_accessor(a); - grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a; - grib_action* act = (grib_action*)(a->creator); - DEBUG_ASSERT(len == self->nbytes); + int n = 0; + long new_len = len; + grib_handle* hand = grib_handle_of_accessor(this); + grib_action* act = (grib_action*)(creator_); + DEBUG_ASSERT(len == nbytes_); + table_ = NULL; + table_loaded_ = 0; if (new_len == 0) { /* ECC-485: When the codetable length is 0, it means we are passing @@ -64,33 +63,33 @@ void grib_accessor_class_codetable_t::init(grib_accessor* a, const long len, gri */ new_len = grib_arguments_get_long(hand, params, n++); if (new_len <= 0) { - grib_context_log(a->context, GRIB_LOG_FATAL, "%s: codetable length must be a positive integer", a->name); + grib_context_log(context_, GRIB_LOG_FATAL, "%s: codetable length must be a positive integer", name_); } - self->nbytes = new_len; + nbytes_ = new_len; } - self->tablename = grib_arguments_get_string(hand, params, n++); - if (self->tablename == NULL) { - grib_context_log(a->context, GRIB_LOG_FATAL, "%s: codetable table is invalid", a->name); + tablename_ = grib_arguments_get_string(hand, params, n++); + if (tablename_ == NULL) { + grib_context_log(context_, GRIB_LOG_FATAL, "%s: codetable table is invalid", name_); } - self->masterDir = grib_arguments_get_name(hand, params, n++); /* can be NULL */ - self->localDir = grib_arguments_get_name(hand, params, n++); /* can be NULL */ + masterDir_ = grib_arguments_get_name(hand, params, n++); /* can be NULL */ + localDir_ = grib_arguments_get_name(hand, params, n++); /* can be NULL */ - /*if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE) - printf("-------- %s type string (%ld)\n",a->name,a->flags);*/ + /*if (flags_ & GRIB_ACCESSOR_FLAG_STRING_TYPE) + printf("-------- %s type string (%ld)\n",a->name,flags_ );*/ #ifdef DEBUG - if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { - grib_context_log(a->context, GRIB_LOG_FATAL, "codetable '%s' has flag can_be_missing!", a->name); + if (flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { + grib_context_log(context_, GRIB_LOG_FATAL, "codetable '%s' has flag can_be_missing!", name_); Assert(!"codetable with can_be_missing?"); } #endif - if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) { - a->length = 0; - if (!a->vvalue) - a->vvalue = (grib_virtual_value*)grib_context_malloc_clear(a->context, sizeof(grib_virtual_value)); - a->vvalue->type = a->get_native_type(); - a->vvalue->length = new_len; + if (flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) { + length_ = 0; + if (!vvalue_) + vvalue_ = (grib_virtual_value*)grib_context_malloc_clear(context_, sizeof(grib_virtual_value)); + vvalue_->type = get_native_type(); + vvalue_->length = new_len; if (act->default_value != NULL) { const char* p = 0; size_t s_len = 1; @@ -103,29 +102,29 @@ void grib_accessor_class_codetable_t::init(grib_accessor* a, const long len, gri switch (type) { case GRIB_TYPE_DOUBLE: grib_expression_evaluate_double(hand, expression, &d); - a->pack_double(&d, &s_len); + pack_double(&d, &s_len); break; case GRIB_TYPE_LONG: - grib_expression_evaluate_long(grib_handle_of_accessor(a), expression, &l); - a->pack_long(&l, &s_len); + grib_expression_evaluate_long(grib_handle_of_accessor(this), expression, &l); + pack_long(&l, &s_len); break; default: s_len = sizeof(tmp); - p = grib_expression_evaluate_string(grib_handle_of_accessor(a), expression, tmp, &s_len, &ret); + p = grib_expression_evaluate_string(grib_handle_of_accessor(this), expression, tmp, &s_len, &ret); if (ret != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_FATAL, - "Unable to evaluate %s as string", a->name); + grib_context_log(context_, GRIB_LOG_FATAL, + "Unable to evaluate %s as string", name_); } s_len = strlen(p) + 1; - pack_string(a, p, &s_len); + pack_string(p, &s_len); break; } } } else { - a->length = new_len; + length_ = new_len; } } @@ -167,40 +166,52 @@ static void dump_codetable(grib_codetable* atable) static grib_codetable* load_table(grib_accessor* a) { grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a; - size_t size = 0; - grib_handle* h = ((grib_accessor*)self)->parent->h; - grib_context* c = h->context; - grib_codetable* t = NULL; - grib_codetable* next = NULL; - char* filename = 0; - char recomposed[1024] = {0,}; - char localRecomposed[1024] = {0,}; + size_t size = 0; + grib_handle* h = ((grib_accessor*)self)->parent_->h; + grib_context* c = h->context; + grib_codetable* t = NULL; + grib_codetable* next = NULL; + char* filename = 0; + char recomposed[1024] = { + 0, + }; + char localRecomposed[1024] = { + 0, + }; char* localFilename = 0; - char masterDir[1024] = {0,}; - char localDir[1024] = {0,}; + char masterDir[1024] = { + 0, + }; + char localDir[1024] = { + 0, + }; size_t len = 1024; - if (self->masterDir != NULL) - grib_get_string(h, self->masterDir, masterDir, &len); + if (self->masterDir_ != NULL) + grib_get_string(h, self->masterDir_, masterDir, &len); len = 1024; - if (self->localDir != NULL) - grib_get_string(h, self->localDir, localDir, &len); + if (self->localDir_ != NULL) + grib_get_string(h, self->localDir_, localDir, &len); if (*masterDir != 0) { - char name[2048] = {0,}; - snprintf(name, sizeof(name), "%s/%s", masterDir, self->tablename); + char name[2048] = { + 0, + }; + snprintf(name, sizeof(name), "%s/%s", masterDir, self->tablename_); grib_recompose_name(h, NULL, name, recomposed, 0); filename = grib_context_full_defs_path(c, recomposed); } else { - grib_recompose_name(h, NULL, self->tablename, recomposed, 0); + grib_recompose_name(h, NULL, self->tablename_, recomposed, 0); filename = grib_context_full_defs_path(c, recomposed); } if (*localDir != 0) { - char localName[2048] = {0,}; - snprintf(localName, sizeof(localName), "%s/%s", localDir, self->tablename); + char localName[2048] = { + 0, + }; + snprintf(localName, sizeof(localName), "%s/%s", localDir, self->tablename_); grib_recompose_name(h, NULL, localName, localRecomposed, 0); localFilename = grib_context_full_defs_path(c, localRecomposed); } @@ -208,7 +219,7 @@ static grib_codetable* load_table(grib_accessor* a) GRIB_MUTEX_INIT_ONCE(&once, &init_mutex); GRIB_MUTEX_LOCK(&mutex1); /* GRIB-930 */ - /*printf("DBG %s: Look in cache: f=%s lf=%s (recomposed=%s)\n", self->att.name, filename, localFilename,recomposed);*/ + /*printf("DBG %s: Look in cache: f=%s lf=%s (recomposed=%s)\n", att_ .name, filename, localFilename,recomposed);*/ if (filename == NULL && localFilename == NULL) { t = NULL; goto the_end; @@ -232,9 +243,9 @@ static grib_codetable* load_table(grib_accessor* a) next = next->next; } - if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) { - Assert(a->vvalue != NULL); - size = a->vvalue->length * 8; + if (self->flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) { + Assert(self->vvalue_ != NULL); + size = self->vvalue_->length * 8; } else { size = ((grib_accessor*)self)->byte_count() * 8; @@ -294,8 +305,12 @@ static int grib_load_codetable(grib_context* c, const char* filename, while (fgets(line, sizeof(line) - 1, f)) { char* p = line; int code = 0; - char abbreviation[1024] = {0,}; - char title[1024] = {0,}; + char abbreviation[1024] = { + 0, + }; + char title[1024] = { + 0, + }; char* pAbbrev = abbreviation; char* pTitle = title; char* units = 0; @@ -421,34 +436,34 @@ void grib_codetable_delete(grib_context* c) int codes_codetable_get_contents_malloc(const grib_handle* h, const char* key, code_table_entry** entries, size_t* num_entries) { - long lvalue = 0; - size_t size = 1; - int err = 0; + long lvalue = 0; + size_t size = 1; + int err = 0; grib_context* c = h->context; grib_accessor* aa = grib_find_accessor(h, key); if (!aa) return GRIB_NOT_FOUND; - if (!STR_EQUAL(aa->cclass->name, "codetable")) { - return GRIB_INVALID_ARGUMENT; // key is not a codetable + if (!STR_EQUAL(aa->class_name_, "codetable")) { + return GRIB_INVALID_ARGUMENT; // key is not a codetable } - const grib_accessor_codetable_t* ca = (const grib_accessor_codetable_t*)aa; // could be dynamic_cast + const grib_accessor_codetable_t* ca = (const grib_accessor_codetable_t*)aa; // could be dynamic_cast // Decode the key itself. This will either fetch it from the cache or place it there if ((err = aa->unpack_long(&lvalue, &size)) != GRIB_SUCCESS) { return err; } - const grib_codetable* table = ca->table; + const grib_codetable* table = ca->table_; if (!table) return GRIB_INTERNAL_ERROR; - grib_codetable* cached_table = c->codetable; // Access the codetable cache + grib_codetable* cached_table = c->codetable; // Access the codetable cache while (cached_table) { if (STR_EQUAL(table->recomposed_name[0], cached_table->recomposed_name[0])) { // Found a cache entry that matches the recomposed name of ours *num_entries = cached_table->size; - *entries = (code_table_entry*)calloc(cached_table->size, sizeof(code_table_entry)); + *entries = (code_table_entry*)calloc(cached_table->size, sizeof(code_table_entry)); if (!*entries) { return GRIB_OUT_OF_MEMORY; } @@ -466,9 +481,9 @@ int codes_codetable_get_contents_malloc(const grib_handle* h, const char* key, c int codes_codetable_check_code_figure(const grib_handle* h, const char* key, long code_figure) { code_table_entry* entries = NULL; - size_t num_entries = 0; - int err = 0; - err = codes_codetable_get_contents_malloc(h, key, &entries, &num_entries); + size_t num_entries = 0; + int err = 0; + err = codes_codetable_get_contents_malloc(h, key, &entries, &num_entries); if (err) return err; if (code_figure < 0 || (size_t)code_figure >= num_entries) { @@ -488,13 +503,13 @@ cleanup: int codes_codetable_check_abbreviation(const grib_handle* h, const char* key, const char* abbreviation) { code_table_entry* entries = NULL; - size_t num_entries = 0; - int err = 0; - err = codes_codetable_get_contents_malloc(h, key, &entries, &num_entries); + size_t num_entries = 0; + int err = 0; + err = codes_codetable_get_contents_malloc(h, key, &entries, &num_entries); if (err) return err; bool found = false; - for (size_t i=0; itable_loaded) { - self->table = load_table(a); /* may return NULL */ - self->table_loaded = 1; + if (!table_loaded_) { + table_ = load_table(this); /* may return NULL */ + table_loaded_ = 1; } - table = self->table; + table = table_; - a->unpack_long(&value, &llen); + unpack_long(&value, &llen); if (value == GRIB_MISSING_LONG) { - if (a->length < 4) { - value = (1L << a->length) - 1; + if (length_ < 4) { + value = (1L << length_) - 1; } } @@ -562,13 +576,12 @@ void grib_accessor_class_codetable_t::dump(grib_accessor* a, grib_dumper* dumper } strcat(comment, ") "); - grib_dump_long(dumper, a, comment); + grib_dump_long(dumper, this, comment); } -int grib_accessor_class_codetable_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) +int grib_accessor_codetable_t::unpack_string(char* buffer, size_t* len) { - grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a; - grib_codetable* table = NULL; + grib_codetable* table = NULL; size_t size = 1; long value; @@ -576,14 +589,14 @@ int grib_accessor_class_codetable_t::unpack_string(grib_accessor* a, char* buffe char tmp[1024]; size_t l = 0; - if ((err = a->unpack_long(&value, &size)) != GRIB_SUCCESS) + if ((err = unpack_long(&value, &size)) != GRIB_SUCCESS) return err; - if (!self->table_loaded) { - self->table = load_table(a); /* may return NULL */ - self->table_loaded = 1; + if (!table_loaded_) { + table_ = load_table(this); /* may return NULL */ + table_loaded_ = 1; } - table = self->table; + table = table_; if (table && (value >= 0) && (value < table->size) && table->entries[value].abbreviation) { strcpy(tmp, table->entries[value].abbreviation); @@ -595,10 +608,10 @@ int grib_accessor_class_codetable_t::unpack_string(grib_accessor* a, char* buffe l = strlen(tmp) + 1; if (*len < l) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, + const char* cclass_name = class_name_; + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, l, *len); + cclass_name, name_, l, *len); *len = l; return GRIB_BUFFER_TOO_SMALL; } @@ -609,7 +622,7 @@ int grib_accessor_class_codetable_t::unpack_string(grib_accessor* a, char* buffe return GRIB_SUCCESS; } -int grib_accessor_class_codetable_t::value_count(grib_accessor* a, long* count) +int grib_accessor_codetable_t::value_count(long* count) { *count = 1; return 0; @@ -632,36 +645,35 @@ bool strings_equal(const char* s1, const char* s2, bool case_sensitive) return (strcmp_nocase(s1, s2) == 0); } -int grib_accessor_class_codetable_t::pack_string(grib_accessor* a, const char* buffer, size_t* len) +int grib_accessor_codetable_t::pack_string(const char* buffer, size_t* len) { long lValue = 0; Assert(buffer); if (is_number(buffer) && string_to_long(buffer, &lValue, 1) == GRIB_SUCCESS) { // ECC-1654: If value is a pure number, just pack as long size_t l = 1; - return a->pack_long(&lValue, &l); + return pack_long(&lValue, &l); } if (STR_EQUAL_NOCASE(buffer, "missing")) { - return pack_missing(a); + return pack_missing(); } - grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a; grib_codetable* table = NULL; - long i = 0; - size_t size = 1; + long i = 0; + size_t size = 1; - if (!self->table_loaded) { - self->table = load_table(a); /* may return NULL */ - self->table_loaded = 1; + if (!table_loaded_) { + table_ = load_table(this); /* may return NULL */ + table_loaded_ = 1; } - table = self->table; + table = table_; if (!table) return GRIB_ENCODING_ERROR; - if (a->set) { - int err = grib_set_string(grib_handle_of_accessor(a), a->set, buffer, len); + if (set_) { + int err = grib_set_string(grib_handle_of_accessor(this), set_, buffer, len); if (err != 0) return err; } @@ -669,48 +681,50 @@ int grib_accessor_class_codetable_t::pack_string(grib_accessor* a, const char* b // If the key has the "lowercase" flag set, then the string comparison // should ignore the case bool case_sensitive = true; - if (a->flags & GRIB_ACCESSOR_FLAG_LOWERCASE) case_sensitive = false; + if (flags_ & GRIB_ACCESSOR_FLAG_LOWERCASE) case_sensitive = false; for (i = 0; i < table->size; i++) { if (table->entries[i].abbreviation) { if (strings_equal(table->entries[i].abbreviation, buffer, case_sensitive)) { - return a->pack_long(&i, &size); + return pack_long(&i, &size); } } } - if (a->flags & GRIB_ACCESSOR_FLAG_NO_FAIL) { - grib_action* act = (grib_action*)(a->creator); + if (flags_ & GRIB_ACCESSOR_FLAG_NO_FAIL) { + grib_action* act = (grib_action*)(creator_); if (act->default_value != NULL) { - const char* p = 0; - size_t s_len = 1; - long l = 0; - int ret = 0; - double d = 0; - char tmp[1024] = {0,}; - grib_expression* expression = grib_arguments_get_expression(grib_handle_of_accessor(a), act->default_value, 0); - int type = grib_expression_native_type(grib_handle_of_accessor(a), expression); + const char* p = 0; + size_t s_len = 1; + long l = 0; + int ret = 0; + double d = 0; + char tmp[1024] = { + 0, + }; + grib_expression* expression = grib_arguments_get_expression(grib_handle_of_accessor(this), act->default_value, 0); + int type = grib_expression_native_type(grib_handle_of_accessor(this), expression); switch (type) { case GRIB_TYPE_DOUBLE: - grib_expression_evaluate_double(grib_handle_of_accessor(a), expression, &d); - a->pack_double(&d, &s_len); + grib_expression_evaluate_double(grib_handle_of_accessor(this), expression, &d); + pack_double(&d, &s_len); break; case GRIB_TYPE_LONG: - grib_expression_evaluate_long(grib_handle_of_accessor(a), expression, &l); - a->pack_long(&l, &s_len); + grib_expression_evaluate_long(grib_handle_of_accessor(this), expression, &l); + pack_long(&l, &s_len); break; default: s_len = sizeof(tmp); - p = grib_expression_evaluate_string(grib_handle_of_accessor(a), expression, tmp, &s_len, &ret); + p = grib_expression_evaluate_string(grib_handle_of_accessor(this), expression, tmp, &s_len, &ret); if (ret != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s: Unable to evaluate default value of %s as string expression", __func__, a->name); + grib_context_log(context_, GRIB_LOG_ERROR, + "%s: Unable to evaluate default value of %s as string expression", __func__, name_); return ret; } s_len = strlen(p) + 1; - pack_string(a, p, &s_len); + pack_string(p, &s_len); break; } return GRIB_SUCCESS; @@ -721,10 +735,10 @@ int grib_accessor_class_codetable_t::pack_string(grib_accessor* a, const char* b for (i = 0; i < table->size; i++) { if (table->entries[i].abbreviation) { if (strcmp_nocase(table->entries[i].abbreviation, buffer) == 0) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: No such code table entry: '%s' " "(Did you mean '%s'?)", - a->name, buffer, table->entries[i].abbreviation); + name_, buffer, table->entries[i].abbreviation); } } } @@ -732,124 +746,122 @@ int grib_accessor_class_codetable_t::pack_string(grib_accessor* a, const char* b return GRIB_ENCODING_ERROR; } -int grib_accessor_class_codetable_t::pack_expression(grib_accessor* a, grib_expression* e) +int grib_accessor_codetable_t::pack_expression(grib_expression* e) { const char* cval = NULL; int ret = 0; long lval = 0; size_t len = 1; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); if (strcmp(e->cclass->name, "long") == 0) { grib_expression_evaluate_long(hand, e, &lval); /* TODO: check return value */ - //if (hand->context->debug) printf("ECCODES DEBUG grib_accessor_class_codetable::pack_expression %s %ld\n", a->name,lval); - ret = a->pack_long(&lval, &len); + // if (hand->context->debug) printf("ECCODES DEBUG grib_accessor_codetable::pack_expression %s %ld\n", name_ ,lval); + ret = pack_long(&lval, &len); } else { char tmp[1024]; len = sizeof(tmp); cval = grib_expression_evaluate_string(hand, e, tmp, &len, &ret); if (ret != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "grib_accessor_codetable.%s: Unable to evaluate string %s to be set in %s", - __func__, grib_expression_get_name(e), a->name); + grib_context_log(context_, GRIB_LOG_ERROR, + "grib_accessor_codetable.%s: Unable to evaluate string %s to be set in %s", + __func__, grib_expression_get_name(e), name_); return ret; } len = strlen(cval) + 1; - //if (hand->context->debug) - // printf("ECCODES DEBUG grib_accessor_class_codetable::pack_expression %s %s\n", a->name, cval); - ret = a->pack_string(cval, &len); + // if (hand->context->debug) + // printf("ECCODES DEBUG grib_accessor_codetable::pack_expression %s %s\n", name_ , cval); + ret = pack_string(cval, &len); } return ret; } -void grib_accessor_class_codetable_t::destroy(grib_context* context, grib_accessor* a) +void grib_accessor_codetable_t::destroy(grib_context* context) { - if (a->vvalue != NULL) { - grib_context_free(context, a->vvalue); - a->vvalue = NULL; + if (vvalue_ != NULL) { + grib_context_free(context, vvalue_); + vvalue_ = NULL; } - grib_accessor_class_unsigned_t::destroy(context, a); + grib_accessor_unsigned_t::destroy(context); } -int grib_accessor_class_codetable_t::get_native_type(grib_accessor* a) +long grib_accessor_codetable_t::get_native_type() { int type = GRIB_TYPE_LONG; /*printf("---------- %s flags=%ld GRIB_ACCESSOR_FLAG_STRING_TYPE=%d\n", - a->name,a->flags,GRIB_ACCESSOR_FLAG_STRING_TYPE);*/ - if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE) + a->name,flags_ ,GRIB_ACCESSOR_FLAG_STRING_TYPE);*/ + if (flags_ & GRIB_ACCESSOR_FLAG_STRING_TYPE) type = GRIB_TYPE_STRING; return type; } -int grib_accessor_class_codetable_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_codetable_t::unpack_long(long* val, size_t* len) { - grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a; long rlen = 0, i = 0; - long pos = a->offset * 8; + long pos = offset_ * 8; grib_handle* hand = NULL; #ifdef DEBUG { - int err = a->value_count(&rlen); + int err = value_count(&rlen); Assert(!err); Assert(rlen == 1); } #endif rlen = 1; /* ECC-480 Performance: avoid func call overhead of grib_value_count */ - if (!self->table_loaded) { - self->table = load_table(a); /* may return NULL */ - self->table_loaded = 1; + if (!table_loaded_) { + table_ = load_table(this); /* may return NULL */ + table_loaded_ = 1; } if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size (%lu) for %s, it contains %ld values", - *len, a->name, rlen); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size (%lu) for %s, it contains %ld values", + *len, name_, rlen); *len = 0; return GRIB_ARRAY_TOO_SMALL; } - if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) { - *val = a->vvalue->lval; + if (flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) { + *val = vvalue_->lval; *len = 1; return GRIB_SUCCESS; } /* ECC-480 Performance: inline the grib_handle_of_accessor here to reduce func call overhead */ - if (a->parent == NULL) - hand = a->h; + if (parent_ == NULL) + hand = h_; else - hand = a->parent->h; + hand = parent_->h; for (i = 0; i < rlen; i++) { - val[i] = (long)grib_decode_unsigned_long(hand->buffer->data, &pos, self->nbytes * 8); + val[i] = (long)grib_decode_unsigned_long(hand->buffer->data, &pos, nbytes_ * 8); } *len = rlen; return GRIB_SUCCESS; } -int grib_accessor_class_codetable_t::pack_missing(grib_accessor* a) +int grib_accessor_codetable_t::pack_missing() { // Many of the code tables do have a 'Missing' entry (all bits = 1) // So it is more user-friendly to allow setting codetable keys to // missing. For tables that do not have such an entry, an error is issued - grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); - const long nbytes = a->length; - const long nbits = nbytes*8; - const long maxVal = (1<name, maxVal); + int err = codes_codetable_check_code_figure(h, name_, maxVal); if (!err) { size_t l = 1; - return a->pack_long(&maxVal, &l); + return pack_long(&maxVal, &l); } - grib_context_log(a->context, GRIB_LOG_ERROR, "There is no 'missing' entry in Code Table %s (%s)", - self->tablename, grib_get_error_message(err)); + grib_context_log(context_, GRIB_LOG_ERROR, "There is no 'missing' entry in Code Table %s (%s)", + tablename_, grib_get_error_message(err)); return err; } diff --git a/src/accessor/grib_accessor_class_codetable.h b/src/accessor/grib_accessor_class_codetable.h index 8a16d9113..644e0c2c7 100644 --- a/src/accessor/grib_accessor_class_codetable.h +++ b/src/accessor/grib_accessor_class_codetable.h @@ -15,27 +15,25 @@ class grib_accessor_codetable_t : public grib_accessor_unsigned_t { -public: - const char* tablename; - const char* masterDir; - const char* localDir; - grib_codetable* table; - int table_loaded; -}; - -class grib_accessor_class_codetable_t : public grib_accessor_class_unsigned_t -{ public: grib_accessor* create_empty_accessor() override { return new grib_accessor_codetable_t{}; } - grib_accessor_class_codetable_t(const char* name) : grib_accessor_class_unsigned_t(name) {} - int get_native_type(grib_accessor*) override; - int pack_missing(grib_accessor*) override; - int pack_string(grib_accessor*, const char*, size_t* len) override; - int pack_expression(grib_accessor*, grib_expression*) 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 destroy(grib_context*, grib_accessor*) override; - void dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + grib_accessor_codetable_t() : + grib_accessor_unsigned_t() { class_name_ = "codetable"; } + long get_native_type() override; + int pack_missing() override; + int pack_string(const char*, size_t* len) override; + int pack_expression(grib_expression*) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + int value_count(long*) override; + void destroy(grib_context*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +public: + grib_codetable* table_; + const char* tablename_; + const char* masterDir_; + const char* localDir_; + int table_loaded_; }; diff --git a/src/accessor/grib_accessor_class_codetable_title.cc b/src/accessor/grib_accessor_class_codetable_title.cc index 2bcdfd215..9894a2d7b 100644 --- a/src/accessor/grib_accessor_class_codetable_title.cc +++ b/src/accessor/grib_accessor_class_codetable_title.cc @@ -12,40 +12,38 @@ #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; +grib_accessor_codetable_title_t _grib_accessor_codetable_title{}; +grib_accessor* grib_accessor_codetable_title = &_grib_accessor_codetable_title; -void grib_accessor_class_codetable_title_t::init(grib_accessor* a, const long len, grib_arguments* params) +void grib_accessor_codetable_title_t::init(const long len, grib_arguments* params) { - grib_accessor_class_gen_t::init(a, len, 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; + grib_accessor_gen_t::init(len, params); + int n = 0; + codetable_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++); + length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_codetable_title_t::get_native_type(grib_accessor* a) +long grib_accessor_codetable_title_t::get_native_type() { return GRIB_TYPE_STRING; } -int grib_accessor_class_codetable_title_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) +int grib_accessor_codetable_title_t::unpack_string(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); + size_t l = 1024; + grib_accessor_codetable_t* ca = (grib_accessor_codetable_t*)grib_find_accessor(grib_handle_of_accessor(this), codetable_); if ((err = ((grib_accessor*)ca)->unpack_long(&value, &size)) != GRIB_SUCCESS) return err; - table = ca->table; + table = ca->table_; if (table && (value >= 0) && (value < table->size) && table->entries[value].title) { strcpy(tmp, table->entries[value].title); @@ -57,10 +55,10 @@ int grib_accessor_class_codetable_title_t::unpack_string(grib_accessor* a, char* l = strlen(tmp) + 1; if (*len < l) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, + const char* cclass_name = class_name_; + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, l, *len); + cclass_name, name_, l, *len); *len = l; return GRIB_BUFFER_TOO_SMALL; } diff --git a/src/accessor/grib_accessor_class_codetable_title.h b/src/accessor/grib_accessor_class_codetable_title.h index f820c585c..2d4da16ed 100644 --- a/src/accessor/grib_accessor_class_codetable_title.h +++ b/src/accessor/grib_accessor_class_codetable_title.h @@ -16,16 +16,13 @@ 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_codetable_title_t() : + grib_accessor_gen_t() { class_name_ = "codetable_title"; } 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; + long get_native_type() override; + int unpack_string(char*, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* codetable_; }; diff --git a/src/accessor/grib_accessor_class_codetable_units.cc b/src/accessor/grib_accessor_class_codetable_units.cc index cc91ae2e2..004510ee3 100644 --- a/src/accessor/grib_accessor_class_codetable_units.cc +++ b/src/accessor/grib_accessor_class_codetable_units.cc @@ -12,41 +12,39 @@ #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; +grib_accessor_codetable_units_t _grib_accessor_codetable_units{}; +grib_accessor* grib_accessor_codetable_units = &_grib_accessor_codetable_units; -void grib_accessor_class_codetable_units_t::init(grib_accessor* a, const long len, grib_arguments* params) +void grib_accessor_codetable_units_t::init(const long len, grib_arguments* params) { - grib_accessor_class_gen_t::init(a, len, params); - grib_accessor_codetable_units_t* self = (grib_accessor_codetable_units_t*)a; + grib_accessor_gen_t::init(len, params); - 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 n = 0; + codetable_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++); + length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_codetable_units_t::get_native_type(grib_accessor* a) +long grib_accessor_codetable_units_t::get_native_type() { return GRIB_TYPE_STRING; } -int grib_accessor_class_codetable_units_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) +int grib_accessor_codetable_units_t::unpack_string(char* buffer, size_t* len) { - grib_accessor_codetable_units_t* self = (grib_accessor_codetable_units_t*)a; - grib_codetable* table = NULL; + 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); + size_t l = sizeof(tmp); + grib_accessor_codetable_t* ca = (grib_accessor_codetable_t*)grib_find_accessor(grib_handle_of_accessor(this), codetable_); if ((err = ((grib_accessor*)ca)->unpack_long(&value, &size)) != GRIB_SUCCESS) return err; - table = ca->table; + table = ca->table_; if (table && (value >= 0) && (value < table->size) && table->entries[value].units) { strcpy(tmp, table->entries[value].units); @@ -58,10 +56,10 @@ int grib_accessor_class_codetable_units_t::unpack_string(grib_accessor* a, char* l = strlen(tmp) + 1; if (*len < l) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, + const char* cclass_name = class_name_; + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, l, *len); + cclass_name, name_, l, *len); *len = l; return GRIB_BUFFER_TOO_SMALL; } diff --git a/src/accessor/grib_accessor_class_codetable_units.h b/src/accessor/grib_accessor_class_codetable_units.h index 0a8c9389d..f2da99da5 100644 --- a/src/accessor/grib_accessor_class_codetable_units.h +++ b/src/accessor/grib_accessor_class_codetable_units.h @@ -16,16 +16,13 @@ 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_codetable_units_t() : + grib_accessor_gen_t() { class_name_ = "codetable_units"; } 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; + long get_native_type() override; + int unpack_string(char*, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* codetable_; }; diff --git a/src/accessor/grib_accessor_class_concept.cc b/src/accessor/grib_accessor_class_concept.cc index 98f0fb35c..cf2562a82 100644 --- a/src/accessor/grib_accessor_class_concept.cc +++ b/src/accessor/grib_accessor_class_concept.cc @@ -11,9 +11,8 @@ #include "grib_accessor_class_concept.h" -grib_accessor_class_concept_t _grib_accessor_class_concept{ "concept" }; -grib_accessor_class* grib_accessor_class_concept = &_grib_accessor_class_concept; - +grib_accessor_concept_t _grib_accessor_concept{}; +grib_accessor* grib_accessor_concept = &_grib_accessor_concept; #define MAX_CONCEPT_STRING_LENGTH 255 @@ -33,15 +32,15 @@ GRIB_INLINE static int grib_inline_strcmp(const char* a, const char* b) return (*a == 0 && *b == 0) ? 0 : 1; } -void grib_accessor_class_concept_t::init(grib_accessor* a, const long len, grib_arguments* args) +void grib_accessor_concept_t::init(const long len, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, len, args); - a->length = 0; + grib_accessor_gen_t::init(len, args); + length_ = 0; } -void grib_accessor_class_concept_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_concept_t::dump(grib_dumper* dumper) { - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); } /* Return 1 (=True) or 0 (=False) */ @@ -137,7 +136,7 @@ static const char* concept_evaluate(grib_accessor* a) grib_concept_value* c = action_concept_get_concept(a); grib_handle* h = grib_handle_of_accessor(a); - // fprintf(stderr, "DEBUG: concept_evaluate: %s %s\n", a->name, c->name); + // fprintf(stderr, "DEBUG: concept_evaluate: %s %s\n", name_ , c->name); while (c) { grib_concept_condition* e = c->conditions; int cnt = 0; @@ -255,7 +254,7 @@ static int grib_concept_apply(grib_accessor* a, const char* name) grib_concept_value* c = NULL; grib_concept_value* concepts = action_concept_get_concept(a); grib_handle* h = grib_handle_of_accessor(a); - grib_action* act = a->creator; + grib_action* act = a->creator_; int nofail = action_concept_get_nofail(a); DEBUG_ASSERT(concepts); @@ -270,7 +269,9 @@ static int grib_concept_apply(grib_accessor* a, const char* name) if (err) { size_t i = 0, concept_count = 0; long dummy = 0, editionNumber = 0; - char centre_s[32] = {0,}; + char centre_s[32] = { + 0, + }; size_t centre_len = sizeof(centre_s); char* all_concept_vals[MAX_NUM_CONCEPT_VALUES] = { NULL, @@ -348,12 +349,12 @@ static int grib_concept_apply(grib_accessor* a, const char* name) return err; } -int grib_accessor_class_concept_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_concept_t::pack_double(const double* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_concept_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_concept_t::pack_long(const long* val, size_t* len) { char buf[80]; size_t s; @@ -363,16 +364,16 @@ int grib_accessor_class_concept_t::pack_long(grib_accessor* a, const long* val, // return GRIB_NOT_IMPLEMENTED; // ECC-1806: GRIB: Change of paramId in conversion from GRIB1 to GRIB2 - if (STR_EQUAL(a->name, "paramId")) { - grib_handle* h = grib_handle_of_accessor(a); + if (STR_EQUAL(name_, "paramId")) { + grib_handle* h = grib_handle_of_accessor(this); long edition = 0; if (grib_get_long(h, "edition", &edition) == GRIB_SUCCESS && edition == 2) { long newParamId = 0; if (grib_get_long(h, "paramIdForConversion", &newParamId) == GRIB_SUCCESS && newParamId > 0) { - if (a->context->debug) { - const char* cclass_name = a->cclass->name; + if (context_->debug) { + const char* cclass_name = class_name_; fprintf(stderr, "ECCODES DEBUG %s::%s: Changing %s from %ld to %ld\n", - cclass_name, __func__, a->name, *val, newParamId); + cclass_name, __func__, name_, *val, newParamId); } snprintf(buf, sizeof(buf), "%ld", newParamId); } @@ -380,10 +381,10 @@ int grib_accessor_class_concept_t::pack_long(grib_accessor* a, const long* val, } s = strlen(buf) + 1; - return pack_string(a, buf, &s); + return pack_string(buf, &s); } -int grib_accessor_class_concept_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_concept_t::unpack_double(double* val, size_t* len) { /* * If we want to have a condition which contains tests for paramId as well @@ -393,20 +394,20 @@ int grib_accessor_class_concept_t::unpack_double(grib_accessor* a, double* val, */ /*return GRIB_NOT_IMPLEMENTED*/ int ret = 0; - if (a->flags & GRIB_ACCESSOR_FLAG_LONG_TYPE) { + if (flags_ & GRIB_ACCESSOR_FLAG_LONG_TYPE) { long lval = 0; - ret = unpack_long(a, &lval, len); + ret = unpack_long(&lval, len); if (ret == GRIB_SUCCESS) { *val = lval; } } - else if (a->flags & GRIB_ACCESSOR_FLAG_DOUBLE_TYPE) { - const char* p = concept_evaluate(a); + else if (flags_ & GRIB_ACCESSOR_FLAG_DOUBLE_TYPE) { + const char* p = concept_evaluate(this); if (!p) { - grib_handle* h = grib_handle_of_accessor(a); - if (a->creator->defaultkey) - return grib_get_double_internal(h, a->creator->defaultkey, val); + grib_handle* h = grib_handle_of_accessor(this); + if (creator_->defaultkey) + return grib_get_double_internal(h, creator_->defaultkey, val); return GRIB_NOT_FOUND; } @@ -416,14 +417,14 @@ int grib_accessor_class_concept_t::unpack_double(grib_accessor* a, double* val, return ret; } -int grib_accessor_class_concept_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_concept_t::unpack_long(long* val, size_t* len) { - const char* p = concept_evaluate(a); + const char* p = concept_evaluate(this); if (!p) { - grib_handle* h = grib_handle_of_accessor(a); - if (a->creator->defaultkey) - return grib_get_long_internal(h, a->creator->defaultkey, val); + grib_handle* h = grib_handle_of_accessor(this); + if (creator_->defaultkey) + return grib_get_long_internal(h, creator_->defaultkey, val); return GRIB_NOT_FOUND; } @@ -441,9 +442,9 @@ int grib_accessor_class_concept_t::unpack_long(grib_accessor* a, long* val, size if (endptr == p || *endptr != '\0') { /* Failed to convert string into integer */ int type = GRIB_TYPE_UNDEFINED; - grib_context_log(a->context, GRIB_LOG_ERROR, "Cannot unpack %s as long", a->name); - if (grib_get_native_type(grib_handle_of_accessor(a), a->name, &type) == GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Try unpacking as %s", grib_get_type_name(type)); + grib_context_log(context_, GRIB_LOG_ERROR, "Cannot unpack %s as long", name_); + if (grib_get_native_type(grib_handle_of_accessor(this), name_, &type) == GRIB_SUCCESS) { + grib_context_log(context_, GRIB_LOG_ERROR, "Hint: Try unpacking as %s", grib_get_type_name(type)); } return GRIB_DECODING_ERROR; } @@ -452,73 +453,73 @@ int grib_accessor_class_concept_t::unpack_long(grib_accessor* a, long* val, size return GRIB_SUCCESS; } -int grib_accessor_class_concept_t::get_native_type(grib_accessor* a) +long grib_accessor_concept_t::get_native_type() { int type = GRIB_TYPE_STRING; - if (a->flags & GRIB_ACCESSOR_FLAG_LONG_TYPE) + if (flags_ & GRIB_ACCESSOR_FLAG_LONG_TYPE) type = GRIB_TYPE_LONG; return type; } -void grib_accessor_class_concept_t::destroy(grib_context* c, grib_accessor* a) +void grib_accessor_concept_t::destroy(grib_context* c) { // grib_accessor_concept_t *self = (grib_accessor_concept_t*)a; - // grib_context_free(c,self->cval); - grib_accessor_class_gen_t::destroy(c, a); + // grib_context_free(c,cval_ ); + grib_accessor_gen_t::destroy(c); } -int grib_accessor_class_concept_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_concept_t::unpack_string(char* val, size_t* len) { size_t slen; - const char* p = concept_evaluate(a); + const char* p = concept_evaluate(this); if (!p) { - grib_handle* h = grib_handle_of_accessor(a); - if (a->creator->defaultkey) - return grib_get_string_internal(h, a->creator->defaultkey, val, len); + grib_handle* h = grib_handle_of_accessor(this); + if (creator_->defaultkey) + return grib_get_string_internal(h, creator_->defaultkey, val, len); return GRIB_NOT_FOUND; } slen = strlen(p) + 1; if (*len < slen) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "Concept unpack_string. Buffer too small for %s, value='%s' which requires %lu bytes (len=%lu)", - a->name, p, slen, *len); + name_, p, slen, *len); *len = slen; return GRIB_BUFFER_TOO_SMALL; } strcpy(val, p); /* NOLINT: CWE-119 clang-analyzer-security.insecureAPI.strcpy */ *len = slen; - // if (a->context->debug==1) { + // if (context_ ->debug==1) { // int err = 0; // char result[1024] = {0,}; - // err = get_concept_condition_string(grib_handle_of_accessor(a), a->name, val, result); - // if (!err) fprintf(stderr, "ECCODES DEBUG concept name=%s, value=%s, conditions=%s\n", a->name, val, result); + // err = get_concept_condition_string(grib_handle_of_accessor(this), name_ , val, result); + // if (!err) fprintf(stderr, "ECCODES DEBUG concept name=%s, value=%s, conditions=%s\n", name_ , val, result); // } return GRIB_SUCCESS; } -int grib_accessor_class_concept_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_concept_t::pack_string(const char* val, size_t* len) { - return grib_concept_apply(a, val); + return grib_concept_apply(this, val); } -size_t grib_accessor_class_concept_t::string_length(grib_accessor* a) +size_t grib_accessor_concept_t::string_length() { return MAX_CONCEPT_STRING_LENGTH; } -int grib_accessor_class_concept_t::value_count(grib_accessor* a, long* count) +int grib_accessor_concept_t::value_count(long* count) { *count = 1; return 0; } -int grib_accessor_class_concept_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_concept_t::compare(grib_accessor* b) { int retval = 0; char* aval = 0; @@ -529,7 +530,7 @@ int grib_accessor_class_concept_t::compare(grib_accessor* a, grib_accessor* b) int err = 0; long count = 0; - err = a->value_count(&count); + err = value_count(&count); if (err) return err; alen = count; @@ -542,10 +543,10 @@ int grib_accessor_class_concept_t::compare(grib_accessor* a, grib_accessor* b) alen = MAX_CONCEPT_STRING_LENGTH; blen = MAX_CONCEPT_STRING_LENGTH; - aval = (char*)grib_context_malloc(a->context, alen * sizeof(char)); - bval = (char*)grib_context_malloc(b->context, blen * sizeof(char)); + aval = (char*)grib_context_malloc(context_, alen * sizeof(char)); + bval = (char*)grib_context_malloc(b->context_, blen * sizeof(char)); - err = a->unpack_string(aval, &alen); + err = unpack_string(aval, &alen); if (err) return err; err = b->unpack_string(bval, &blen); if (err) return err; @@ -554,8 +555,8 @@ int grib_accessor_class_concept_t::compare(grib_accessor* a, grib_accessor* b) if (!aval || !bval || grib_inline_strcmp(aval, bval)) retval = GRIB_STRING_VALUE_MISMATCH; - grib_context_free(a->context, aval); - grib_context_free(b->context, bval); + grib_context_free(context_, aval); + grib_context_free(b->context_, bval); return retval; } diff --git a/src/accessor/grib_accessor_class_concept.h b/src/accessor/grib_accessor_class_concept.h index 7b9ea11d0..b04cc4cb2 100644 --- a/src/accessor/grib_accessor_class_concept.h +++ b/src/accessor/grib_accessor_class_concept.h @@ -16,25 +16,20 @@ 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_concept_t() : + grib_accessor_gen_t() { class_name_ = "concept"; } 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; + long get_native_type() override; + int pack_double(const double* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + int pack_string(const char*, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + int value_count(long*) override; + void destroy(grib_context*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + int compare(grib_accessor*) override; }; diff --git a/src/accessor/grib_accessor_class_constant.cc b/src/accessor/grib_accessor_class_constant.cc index ed30a6365..d7f1354c1 100644 --- a/src/accessor/grib_accessor_class_constant.cc +++ b/src/accessor/grib_accessor_class_constant.cc @@ -10,11 +10,11 @@ #include "grib_accessor_class_constant.h" -grib_accessor_class_constant_t _grib_accessor_class_constant{"constant"}; -grib_accessor_class* grib_accessor_class_constant = &_grib_accessor_class_constant; +grib_accessor_constant_t _grib_accessor_constant{}; +grib_accessor* grib_accessor_constant = &_grib_accessor_constant; -void grib_accessor_class_constant_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_constant_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_variable_t::init(a, len, arg); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + grib_accessor_variable_t::init(len, arg); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } diff --git a/src/accessor/grib_accessor_class_constant.h b/src/accessor/grib_accessor_class_constant.h index 916df88e9..b0e6bda1b 100644 --- a/src/accessor/grib_accessor_class_constant.h +++ b/src/accessor/grib_accessor_class_constant.h @@ -10,12 +10,11 @@ #include "grib_accessor_class_variable.h" -class grib_accessor_constant_t : public grib_accessor_variable_t {}; - -class grib_accessor_class_constant_t : public grib_accessor_class_variable_t +class grib_accessor_constant_t : public grib_accessor_variable_t { public: - grib_accessor_class_constant_t(const char* name) : grib_accessor_class_variable_t(name) {} + grib_accessor_constant_t() : + grib_accessor_variable_t() { class_name_ = "constant"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_constant_t{}; } - void init(grib_accessor*, const long, grib_arguments*) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_count_file.cc b/src/accessor/grib_accessor_class_count_file.cc index 268ba8051..36331c3d9 100644 --- a/src/accessor/grib_accessor_class_count_file.cc +++ b/src/accessor/grib_accessor_class_count_file.cc @@ -11,20 +11,19 @@ #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; +grib_accessor_count_file_t _grib_accessor_count_file{}; +grib_accessor* grib_accessor_count_file = &_grib_accessor_count_file; - -void grib_accessor_class_count_file_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_count_file_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; + grib_accessor_long_t::init(l, c); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + length_ = 0; } -int grib_accessor_class_count_file_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_count_file_t::unpack_long(long* val, size_t* len) { - *val = grib_context_get_handle_file_count(a->context); + *val = grib_context_get_handle_file_count(context_); *len = 1; return 0; } diff --git a/src/accessor/grib_accessor_class_count_file.h b/src/accessor/grib_accessor_class_count_file.h index 25092b0a4..0dec594fb 100644 --- a/src/accessor/grib_accessor_class_count_file.h +++ b/src/accessor/grib_accessor_class_count_file.h @@ -16,14 +16,9 @@ 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_count_file_t() : + grib_accessor_long_t() { class_name_ = "count_file"; } 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; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_count_missing.cc b/src/accessor/grib_accessor_class_count_missing.cc index 7a3232175..b4b841c5f 100644 --- a/src/accessor/grib_accessor_class_count_missing.cc +++ b/src/accessor/grib_accessor_class_count_missing.cc @@ -11,9 +11,8 @@ #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; - +grib_accessor_count_missing_t _grib_accessor_count_missing{}; +grib_accessor* grib_accessor_count_missing = &_grib_accessor_count_missing; static const unsigned char bitsoff[] = { 8, 7, 7, 6, 7, 6, 6, 5, 7, 6, 6, 5, 6, 5, 5, 4, 7, @@ -34,25 +33,24 @@ static const unsigned char bitsoff[] = { 0 }; -void grib_accessor_class_count_missing_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_count_missing_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_long_t::init(a, len, arg); - int n = 0; - 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; - self->bitmap = grib_arguments_get_name(h, arg, n++); - self->unusedBitsInBitmap = grib_arguments_get_name(h, arg, n++); - self->numberOfDataPoints = grib_arguments_get_name(h, arg, n++); - self->missingValueManagementUsed = grib_arguments_get_name(h, arg, n++); /* Can be NULL */ + grib_accessor_long_t::init(len, arg); + int n = 0; + grib_handle* h = grib_handle_of_accessor(this); + length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + bitmap_ = grib_arguments_get_name(h, arg, n++); + unusedBitsInBitmap_ = grib_arguments_get_name(h, arg, n++); + numberOfDataPoints_ = grib_arguments_get_name(h, arg, n++); + missingValueManagementUsed_ = grib_arguments_get_name(h, arg, n++); /* Can be NULL */ } 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 err = 0; + int err = 0; long count_of_missing = 0; size_t vsize = 0, ii = 0; double* values = NULL; @@ -74,24 +72,23 @@ static int get_count_of_missing_values(grib_handle* h, long* p_count_of_missing) return GRIB_SUCCESS; } -int grib_accessor_class_count_missing_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_count_missing_t::unpack_long(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; long offset = 0; long unusedBitsInBitmap = 0; long numberOfDataPoints = 0; - grib_handle* h = grib_handle_of_accessor(a); - grib_accessor* bitmap = grib_find_accessor(h, self->bitmap); + grib_handle* h = grib_handle_of_accessor(this); + grib_accessor* bitmap = grib_find_accessor(h, bitmap_); *val = 0; /* By default assume none are missing */ *len = 1; if (!bitmap) { long mvmu = 0; - if (self->missingValueManagementUsed && - grib_get_long(h, self->missingValueManagementUsed, &mvmu) == GRIB_SUCCESS && mvmu != 0) { + if (missingValueManagementUsed_ && + grib_get_long(h, missingValueManagementUsed_, &mvmu) == GRIB_SUCCESS && mvmu != 0) { /* ECC-523: No bitmap. Missing values are encoded in the Data Section. * So we must decode all the data values and count how many are missing */ @@ -105,15 +102,15 @@ int grib_accessor_class_count_missing_t::unpack_long(grib_accessor* a, long* val 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"); + if (grib_get_long(h, unusedBitsInBitmap_, &unusedBitsInBitmap) != GRIB_SUCCESS) { + if (grib_get_long(h, numberOfDataPoints_, &numberOfDataPoints) != GRIB_SUCCESS) { + grib_context_log(context_, GRIB_LOG_ERROR, "Unable to count missing values"); return GRIB_INTERNAL_ERROR; } unusedBitsInBitmap = size * 8 - numberOfDataPoints; if (unusedBitsInBitmap < 0) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Inconsistent number of bitmap points: Check the bitmap and data sections!"); - grib_context_log(a->context, GRIB_LOG_ERROR, "Bitmap size=%ld, numberOfDataPoints=%ld", size * 8, numberOfDataPoints); + grib_context_log(context_, GRIB_LOG_ERROR, "Inconsistent number of bitmap points: Check the bitmap and data sections!"); + grib_context_log(context_, GRIB_LOG_ERROR, "Bitmap size=%ld, numberOfDataPoints=%ld", size * 8, numberOfDataPoints); return GRIB_DECODING_ERROR; } } @@ -131,7 +128,7 @@ int grib_accessor_class_count_missing_t::unpack_long(grib_accessor* a, long* val return GRIB_SUCCESS; } -int grib_accessor_class_count_missing_t::value_count(grib_accessor* a, long* count) +int grib_accessor_count_missing_t::value_count(long* count) { *count = 1; return 0; diff --git a/src/accessor/grib_accessor_class_count_missing.h b/src/accessor/grib_accessor_class_count_missing.h index 3e2cf7330..78debfeb1 100644 --- a/src/accessor/grib_accessor_class_count_missing.h +++ b/src/accessor/grib_accessor_class_count_missing.h @@ -16,19 +16,16 @@ 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_count_missing_t() : + grib_accessor_long_t() { class_name_ = "count_missing"; } 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; + int unpack_long(long* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* bitmap_; + const char* unusedBitsInBitmap_; + const char* numberOfDataPoints_; + const char* missingValueManagementUsed_; }; diff --git a/src/accessor/grib_accessor_class_count_total.cc b/src/accessor/grib_accessor_class_count_total.cc index dc708b4b6..bc6af55c5 100644 --- a/src/accessor/grib_accessor_class_count_total.cc +++ b/src/accessor/grib_accessor_class_count_total.cc @@ -11,20 +11,19 @@ #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; +grib_accessor_count_total_t _grib_accessor_count_total{}; +grib_accessor* grib_accessor_count_total = &_grib_accessor_count_total; - -void grib_accessor_class_count_total_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_count_total_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; + grib_accessor_long_t::init(l, c); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + length_ = 0; } -int grib_accessor_class_count_total_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_count_total_t::unpack_long(long* val, size_t* len) { - *val = grib_context_get_handle_total_count(a->context); + *val = grib_context_get_handle_total_count(context_); *len = 1; return 0; } diff --git a/src/accessor/grib_accessor_class_count_total.h b/src/accessor/grib_accessor_class_count_total.h index 6fa89df0e..6f4e9020c 100644 --- a/src/accessor/grib_accessor_class_count_total.h +++ b/src/accessor/grib_accessor_class_count_total.h @@ -16,14 +16,9 @@ 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_count_total_t() : + grib_accessor_long_t() { class_name_ = "count_total"; } 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; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_data_apply_bitmap.cc b/src/accessor/grib_accessor_class_data_apply_bitmap.cc index cf3d5f4a5..4913ec146 100644 --- a/src/accessor/grib_accessor_class_data_apply_bitmap.cc +++ b/src/accessor/grib_accessor_class_data_apply_bitmap.cc @@ -11,68 +11,64 @@ #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; +grib_accessor_data_apply_bitmap_t _grib_accessor_data_apply_bitmap{}; +grib_accessor* grib_accessor_data_apply_bitmap = &_grib_accessor_data_apply_bitmap; - -void grib_accessor_class_data_apply_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_apply_bitmap_t::init(const long v, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, v, args); + grib_accessor_gen_t::init(v, args); int n = 0; - 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++); - self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->binary_scale_factor = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->number_of_data_points = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->number_of_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + coded_values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + bitmap_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + missing_value_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + binary_scale_factor_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + number_of_data_points_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + number_of_values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); - a->length = 0; + length_ = 0; } -void grib_accessor_class_data_apply_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_data_apply_bitmap_t::dump(grib_dumper* dumper) { - grib_dump_values(dumper, a); + grib_dump_values(dumper, this); } -int grib_accessor_class_data_apply_bitmap_t::value_count(grib_accessor* a, long* count) +int grib_accessor_data_apply_bitmap_t::value_count(long* count) { - grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a; size_t len = 0; - int ret = GRIB_SUCCESS; + int ret = GRIB_SUCCESS; - if (grib_find_accessor(grib_handle_of_accessor(a), self->bitmap)) - ret = grib_get_size(grib_handle_of_accessor(a), self->bitmap, &len); + if (grib_find_accessor(grib_handle_of_accessor(this), bitmap_)) + ret = grib_get_size(grib_handle_of_accessor(this), bitmap_, &len); else - ret = grib_get_size(grib_handle_of_accessor(a), self->coded_values, &len); + ret = grib_get_size(grib_handle_of_accessor(this), coded_values_, &len); *count = len; return ret; } -int grib_accessor_class_data_apply_bitmap_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_data_apply_bitmap_t::unpack_double_element(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); - size_t i = 0, cidx = 0; + grib_handle* gh = grib_handle_of_accessor(this); + size_t i = 0, cidx = 0; double missing_value = 0; double* bvals = NULL; size_t n_vals = 0; long nn = 0; - int err = a->value_count(&nn); - n_vals = nn; + int err = value_count(&nn); + n_vals = nn; if (err) return err; - if (!grib_find_accessor(gh, self->bitmap)) - return grib_get_double_element_internal(gh, self->coded_values, idx, val); + if (!grib_find_accessor(gh, bitmap_)) + return grib_get_double_element_internal(gh, coded_values_, idx, val); - if ((err = grib_get_double_internal(gh, self->missing_value, &missing_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(gh, missing_value_, &missing_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_element_internal(gh, self->bitmap, idx, val)) != GRIB_SUCCESS) + if ((err = grib_get_double_element_internal(gh, bitmap_, idx, val)) != GRIB_SUCCESS) return err; if (*val == 0) { @@ -80,11 +76,11 @@ int grib_accessor_class_data_apply_bitmap_t::unpack_double_element(grib_accessor return GRIB_SUCCESS; } - bvals = (double*)grib_context_malloc(a->context, n_vals * sizeof(double)); + bvals = (double*)grib_context_malloc(context_, n_vals * sizeof(double)); if (bvals == NULL) return GRIB_OUT_OF_MEMORY; - if ((err = grib_get_double_array_internal(gh, self->bitmap, bvals, &n_vals)) != GRIB_SUCCESS) + if ((err = grib_get_double_array_internal(gh, bitmap_, bvals, &n_vals)) != GRIB_SUCCESS) return err; cidx = 0; @@ -92,15 +88,14 @@ int grib_accessor_class_data_apply_bitmap_t::unpack_double_element(grib_accessor cidx += bvals[i]; } - grib_context_free(a->context, bvals); + grib_context_free(context_, bvals); - return grib_get_double_element_internal(gh, self->coded_values, cidx, val); + return grib_get_double_element_internal(gh, coded_values_, cidx, val); } -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) +int grib_accessor_data_apply_bitmap_t::unpack_double_element_set(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); + grib_handle* gh = grib_handle_of_accessor(this); int err = 0, all_missing = 1; size_t cidx = 0; /* index into the coded_values array */ size_t* cidx_array = NULL; /* array of indexes into the coded_values */ @@ -110,17 +105,17 @@ int grib_accessor_class_data_apply_bitmap_t::unpack_double_element_set(grib_acce size_t n_vals = 0, i = 0, j = 0, idx = 0, count_1s = 0, ci = 0; long nn = 0; - err = a->value_count(&nn); + err = value_count(&nn); n_vals = nn; if (err) return err; - if (!grib_find_accessor(gh, self->bitmap)) - return grib_get_double_element_set_internal(gh, self->coded_values, index_array, len, val_array); + if (!grib_find_accessor(gh, bitmap_)) + return grib_get_double_element_set_internal(gh, coded_values_, index_array, len, val_array); - if ((err = grib_get_double_internal(gh, self->missing_value, &missing_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(gh, missing_value_, &missing_value)) != GRIB_SUCCESS) return err; - err = grib_get_double_element_set_internal(gh, self->bitmap, index_array, len, val_array); + err = grib_get_double_element_set_internal(gh, bitmap_, index_array, len, val_array); if (err) return err; for (i = 0; i < len; i++) { if (val_array[i] == 0) { @@ -139,14 +134,14 @@ int grib_accessor_class_data_apply_bitmap_t::unpack_double_element_set(grib_acce /* At this point val_array contains entries which are either missing_value or 1 */ /* Now we need to dig into the codes values with index array of count_1s */ - bvals = (double*)grib_context_malloc(a->context, n_vals * sizeof(double)); + bvals = (double*)grib_context_malloc(context_, n_vals * sizeof(double)); if (!bvals) return GRIB_OUT_OF_MEMORY; - if ((err = grib_get_double_array_internal(gh, self->bitmap, bvals, &n_vals)) != GRIB_SUCCESS) + if ((err = grib_get_double_array_internal(gh, bitmap_, bvals, &n_vals)) != GRIB_SUCCESS) return err; - cidx_array = (size_t*)grib_context_malloc(a->context, count_1s * sizeof(size_t)); - cval_array = (double*)grib_context_malloc(a->context, count_1s * sizeof(double)); + cidx_array = (size_t*)grib_context_malloc(context_, count_1s * sizeof(size_t)); + cval_array = (double*)grib_context_malloc(context_, count_1s * sizeof(double)); ci = 0; for (i = 0; i < len; i++) { @@ -160,7 +155,7 @@ int grib_accessor_class_data_apply_bitmap_t::unpack_double_element_set(grib_acce cidx_array[ci++] = cidx; } } - err = grib_get_double_element_set_internal(gh, self->coded_values, cidx_array, count_1s, cval_array); + err = grib_get_double_element_set_internal(gh, coded_values_, cidx_array, count_1s, cval_array); if (err) return err; /* Transfer from cval_array to our result val_array */ @@ -171,48 +166,47 @@ int grib_accessor_class_data_apply_bitmap_t::unpack_double_element_set(grib_acce } } - grib_context_free(a->context, bvals); - grib_context_free(a->context, cidx_array); - grib_context_free(a->context, cval_array); + grib_context_free(context_, bvals); + grib_context_free(context_, cidx_array); + grib_context_free(context_, cval_array); return GRIB_SUCCESS; } -int grib_accessor_class_data_apply_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_apply_bitmap_t::pack_double(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; - double* coded_vals = NULL; - long i = 0; - long j = 0; - double missing_value = 0; - grib_handle* hand = grib_handle_of_accessor(a); - grib_context* ctxt = a->context; + int err = 0; + size_t bmaplen = *len; + long coded_n_vals = 0; + double* coded_vals = NULL; + long i = 0; + long j = 0; + double missing_value = 0; + grib_handle* hand = grib_handle_of_accessor(this); + grib_context* ctxt = context_; if (*len == 0) return GRIB_NO_VALUES; - if (!grib_find_accessor(hand, self->bitmap)) { - /*printf("SETTING TOTAL number_of_data_points %s %ld\n",self->number_of_data_points,*len);*/ - if (self->number_of_data_points) - grib_set_long_internal(hand, self->number_of_data_points, *len); + if (!grib_find_accessor(hand, bitmap_)) { + /*printf("SETTING TOTAL number_of_data_points %s %ld\n",number_of_data_points_ ,*len);*/ + if (number_of_data_points_) + grib_set_long_internal(hand, number_of_data_points_, *len); - err = grib_set_double_array_internal(hand, self->coded_values, val, *len); + err = grib_set_double_array_internal(hand, coded_values_, val, *len); return err; } - if ((err = grib_get_double_internal(hand, self->missing_value, &missing_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(hand, missing_value_, &missing_value)) != GRIB_SUCCESS) return err; - if ((err = grib_set_double_array_internal(hand, self->bitmap, val, bmaplen)) != GRIB_SUCCESS) + if ((err = grib_set_double_array_internal(hand, bitmap_, val, bmaplen)) != GRIB_SUCCESS) return err; coded_n_vals = *len; if (coded_n_vals < 1) { - err = grib_set_double_array_internal(hand, self->coded_values, NULL, 0); + err = grib_set_double_array_internal(hand, coded_values_, NULL, 0); return err; } @@ -226,24 +220,23 @@ int grib_accessor_class_data_apply_bitmap_t::pack_double(grib_accessor* a, const } } - err = grib_set_double_array_internal(hand, self->coded_values, coded_vals, j); + err = grib_set_double_array_internal(hand, coded_values_, coded_vals, j); grib_context_free(ctxt, coded_vals); if (j == 0) { - if (self->number_of_values) - err = grib_set_long_internal(hand, self->number_of_values, 0); - if (self->binary_scale_factor) - err = grib_set_long_internal(hand, self->binary_scale_factor, 0); + if (number_of_values_) + err = grib_set_long_internal(hand, number_of_values_, 0); + if (binary_scale_factor_) + err = grib_set_long_internal(hand, binary_scale_factor_, 0); } return err; } - template static int unpack(grib_accessor* a, T* val, size_t* len) { - static_assert(std::is_floating_point::value, "Requires floating point numbers"); grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a; + static_assert(std::is_floating_point::value, "Requires floating point numbers"); size_t i = 0; size_t j = 0; @@ -254,17 +247,17 @@ static int unpack(grib_accessor* a, T* val, size_t* len) double missing_value = 0; int err = a->value_count(&nn); - n_vals = nn; + n_vals = nn; if (err) return err; - if (!grib_find_accessor(grib_handle_of_accessor(a), self->bitmap)) - return grib_get_array(grib_handle_of_accessor(a), self->coded_values, val, len); + if (!grib_find_accessor(grib_handle_of_accessor(a), self->bitmap_)) + return grib_get_array(grib_handle_of_accessor(a), self->coded_values_, val, len); - if ((err = grib_get_size(grib_handle_of_accessor(a), self->coded_values, &coded_n_vals)) != GRIB_SUCCESS) + if ((err = grib_get_size(grib_handle_of_accessor(a), self->coded_values_, &coded_n_vals)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &missing_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value_, &missing_value)) != GRIB_SUCCESS) return err; if (*len < n_vals) { @@ -280,21 +273,21 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_SUCCESS; } - if ((err = grib_get_array_internal(grib_handle_of_accessor(a), self->bitmap, val, &n_vals)) != GRIB_SUCCESS) + if ((err = grib_get_array_internal(grib_handle_of_accessor(a), self->bitmap_, val, &n_vals)) != GRIB_SUCCESS) return err; - coded_vals = (T*)grib_context_malloc(a->context, coded_n_vals * sizeof(T)); + coded_vals = (T*)grib_context_malloc(a->context_, coded_n_vals * sizeof(T)); if (coded_vals == NULL) return GRIB_OUT_OF_MEMORY; - if ((err = grib_get_array(grib_handle_of_accessor(a), self->coded_values, coded_vals, &coded_n_vals)) != GRIB_SUCCESS) { - grib_context_free(a->context, coded_vals); + if ((err = grib_get_array(grib_handle_of_accessor(a), self->coded_values_, coded_vals, &coded_n_vals)) != GRIB_SUCCESS) { + grib_context_free(a->context_, coded_vals); return err; } - grib_context_log(a->context, GRIB_LOG_DEBUG, - "grib_accessor_class_data_apply_bitmap: %s : creating %s, %d values", - __func__, a->name, n_vals); + grib_context_log(a->context_, GRIB_LOG_DEBUG, + "grib_accessor_data_apply_bitmap: %s : creating %s, %d values", + __func__, a->name_, n_vals); for (i = 0; i < n_vals; i++) { if (val[i] == 0) { @@ -303,11 +296,11 @@ static int unpack(grib_accessor* a, T* val, size_t* len) else { val[i] = coded_vals[j++]; if (j > coded_n_vals) { - grib_context_free(a->context, coded_vals); - grib_context_log(a->context, GRIB_LOG_ERROR, - "grib_accessor_class_data_apply_bitmap [%s]:" + grib_context_free(a->context_, coded_vals); + grib_context_log(a->context_, GRIB_LOG_ERROR, + "grib_accessor_data_apply_bitmap [%s]:" " %s : number of coded values does not match bitmap %ld %ld", - a->name, __func__, coded_n_vals, n_vals); + a->name_, __func__, coded_n_vals, n_vals); return GRIB_ARRAY_TOO_SMALL; } @@ -316,28 +309,28 @@ static int unpack(grib_accessor* a, T* val, size_t* len) *len = n_vals; - grib_context_free(a->context, coded_vals); + grib_context_free(a->context_, coded_vals); return err; } -int grib_accessor_class_data_apply_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_apply_bitmap_t::unpack_double(double* val, size_t* len) { - return unpack(a, val, len); + return unpack(this, val, len); } -int grib_accessor_class_data_apply_bitmap_t::unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_data_apply_bitmap_t::unpack_float(float* val, size_t* len) { - return unpack(a, val, len); + return unpack(this, val, len); } -int grib_accessor_class_data_apply_bitmap_t::get_native_type(grib_accessor* a) +long grib_accessor_data_apply_bitmap_t::get_native_type() { // 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_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(this),coded_values_ )); return GRIB_TYPE_DOUBLE; } -int grib_accessor_class_data_apply_bitmap_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_data_apply_bitmap_t::compare(grib_accessor* b) { int retval = GRIB_SUCCESS; double* aval = 0; @@ -348,7 +341,7 @@ int grib_accessor_class_data_apply_bitmap_t::compare(grib_accessor* a, grib_acce int err = 0; long count = 0; - err = a->value_count(&count); + err = value_count(&count); if (err) return err; alen = count; @@ -361,18 +354,18 @@ int grib_accessor_class_data_apply_bitmap_t::compare(grib_accessor* a, grib_acce if (alen != blen) return GRIB_COUNT_MISMATCH; - aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); - bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); + aval = (double*)grib_context_malloc(context_, alen * sizeof(double)); + bval = (double*)grib_context_malloc(b->context_, blen * sizeof(double)); - a->unpack_double(aval, &alen); + 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; } - grib_context_free(a->context, aval); - grib_context_free(b->context, bval); + grib_context_free(context_, aval); + grib_context_free(b->context_, bval); return retval; } diff --git a/src/accessor/grib_accessor_class_data_apply_bitmap.h b/src/accessor/grib_accessor_class_data_apply_bitmap.h index f3bed1166..f91b24750 100644 --- a/src/accessor/grib_accessor_class_data_apply_bitmap.h +++ b/src/accessor/grib_accessor_class_data_apply_bitmap.h @@ -15,28 +15,25 @@ 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_data_apply_bitmap_t() : + grib_accessor_gen_t() { class_name_ = "data_apply_bitmap"; } 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; + long get_native_type() override; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_float(float* val, size_t* len) override; + int value_count(long*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + int compare(grib_accessor*) override; + int unpack_double_element(size_t i, double* val) override; + int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; + +public: + 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_; }; diff --git a/src/accessor/grib_accessor_class_data_apply_boustrophedonic.cc b/src/accessor/grib_accessor_class_data_apply_boustrophedonic.cc index 2569a05cb..5f82ffeb2 100644 --- a/src/accessor/grib_accessor_class_data_apply_boustrophedonic.cc +++ b/src/accessor/grib_accessor_class_data_apply_boustrophedonic.cc @@ -11,53 +11,48 @@ #include "grib_accessor_class_data_apply_boustrophedonic.h" -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; +grib_accessor_data_apply_boustrophedonic_t _grib_accessor_data_apply_boustrophedonic{}; +grib_accessor* grib_accessor_data_apply_boustrophedonic = &_grib_accessor_data_apply_boustrophedonic; - -void grib_accessor_class_data_apply_boustrophedonic_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_apply_boustrophedonic_t::init(const long v, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, v, args); - grib_accessor_data_apply_boustrophedonic_t* self = (grib_accessor_data_apply_boustrophedonic_t*)a; + grib_accessor_gen_t::init(v, args); - int n = 0; - 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++); - self->numberOfColumns = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->numberOfPoints = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->pl = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); + int n = 0; + values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + numberOfRows_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + numberOfColumns_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + numberOfPoints_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + pl_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); - a->length = 0; + length_ = 0; } -void grib_accessor_class_data_apply_boustrophedonic_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_data_apply_boustrophedonic_t::dump(grib_dumper* dumper) { - grib_dump_values(dumper, a); + grib_dump_values(dumper, this); } -int grib_accessor_class_data_apply_boustrophedonic_t::value_count(grib_accessor* a, long* numberOfPoints) +int grib_accessor_data_apply_boustrophedonic_t::value_count(long* numberOfPoints) { - grib_accessor_data_apply_boustrophedonic_t* self = (grib_accessor_data_apply_boustrophedonic_t*)a; - *numberOfPoints = 0; - return grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, numberOfPoints); + return grib_get_long_internal(grib_handle_of_accessor(this), numberOfPoints_, numberOfPoints); } template static 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; - double* values = 0; - double* pvalues = 0; - T* pval = 0; - size_t valuesSize = 0; + size_t plSize = 0; + long* pl = 0; + double* values = 0; + double* pvalues = 0; + T* pval = 0; + size_t valuesSize = 0; long i, j; int ret; long numberOfPoints, numberOfRows, numberOfColumns; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, &numberOfPoints); + ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints_, &numberOfPoints); if (ret) return ret; @@ -66,7 +61,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_ARRAY_TOO_SMALL; } - ret = grib_get_size(grib_handle_of_accessor(a), self->values, &valuesSize); + ret = grib_get_size(grib_handle_of_accessor(a), self->values_, &valuesSize); if (ret) return ret; @@ -75,31 +70,31 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return 0; if (valuesSize != numberOfPoints) { - grib_context_log(a->context, GRIB_LOG_ERROR, "boustrophedonic ordering error: ( %s=%ld ) != (sizeOf(%s)=%ld)", - self->numberOfPoints, numberOfPoints, self->values, (long)valuesSize); + grib_context_log(a->context_, GRIB_LOG_ERROR, "boustrophedonic ordering error: ( %s=%ld ) != (sizeOf(%s)=%ld)", + numberOfPoints, numberOfPoints, self->values_, (long)valuesSize); return GRIB_DECODING_ERROR; } - values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * numberOfPoints); - ret = grib_get_double_array_internal(grib_handle_of_accessor(a), self->values, values, &valuesSize); + values = (double*)grib_context_malloc_clear(a->context_, sizeof(double) * numberOfPoints); + ret = grib_get_double_array_internal(grib_handle_of_accessor(a), self->values_, values, &valuesSize); if (ret) return ret; pvalues = values; pval = val; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfRows, &numberOfRows); + ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfRows_, &numberOfRows); if (ret) return ret; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfColumns, &numberOfColumns); + ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfColumns_, &numberOfColumns); if (ret) return ret; - if (grib_get_size(grib_handle_of_accessor(a), self->pl, &plSize) == GRIB_SUCCESS) { + if (grib_get_size(grib_handle_of_accessor(a), self->pl_, &plSize) == GRIB_SUCCESS) { Assert(plSize == numberOfRows); - pl = (long*)grib_context_malloc_clear(a->context, sizeof(long) * plSize); - ret = grib_get_long_array_internal(grib_handle_of_accessor(a), self->pl, pl, &plSize); + pl = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * plSize); + ret = grib_get_long_array_internal(grib_handle_of_accessor(a), self->pl_, pl, &plSize); if (ret) return ret; @@ -116,7 +111,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) } } - grib_context_free(a->context, pl); + grib_context_free(a->context_, pl); } else { for (j = 0; j < numberOfRows; j++) { @@ -133,52 +128,52 @@ static int unpack(grib_accessor* a, T* val, size_t* len) } } - grib_context_free(a->context, values); + grib_context_free(a->context_, values); return GRIB_SUCCESS; } -int grib_accessor_class_data_apply_boustrophedonic_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_apply_boustrophedonic_t::unpack_double(double* val, size_t* len) { - return unpack(a, val, len); + return unpack(this, val, len); } -int grib_accessor_class_data_apply_boustrophedonic_t::unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_data_apply_boustrophedonic_t::unpack_float(float* val, size_t* len) { - return unpack(a, val, len); + return unpack(this, val, len); } -int grib_accessor_class_data_apply_boustrophedonic_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_data_apply_boustrophedonic_t::unpack_double_element(size_t idx, double* val) { size_t size; double* values; /* GRIB-564: The index idx relates to codedValues NOT values! */ - int err = grib_get_size(a->parent->h, "codedValues", &size); + int err = grib_get_size(parent_->h, "codedValues", &size); if (err) return err; if (idx > size) return GRIB_INVALID_NEAREST; - values = (double*)grib_context_malloc_clear(a->parent->h->context, size * sizeof(double)); - err = grib_get_double_array(a->parent->h, "codedValues", values, &size); + values = (double*)grib_context_malloc_clear(parent_->h->context, size * sizeof(double)); + err = grib_get_double_array(parent_->h, "codedValues", values, &size); if (err) { - grib_context_free(a->parent->h->context, values); + grib_context_free(parent_->h->context, values); return err; } *val = values[idx]; - grib_context_free(a->parent->h->context, values); + grib_context_free(parent_->h->context, values); return GRIB_SUCCESS; } -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) +int grib_accessor_data_apply_boustrophedonic_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) { size_t size = 0, i = 0; double* values; int err = 0; /* GRIB-564: The indexes in index_array relate to codedValues NOT values! */ - err = grib_get_size(grib_handle_of_accessor(a), "codedValues", &size); + err = grib_get_size(grib_handle_of_accessor(this), "codedValues", &size); if (err) return err; @@ -186,23 +181,21 @@ int grib_accessor_class_data_apply_boustrophedonic_t::unpack_double_element_set( if (index_array[i] > size) return GRIB_INVALID_ARGUMENT; } - values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double)); - err = grib_get_double_array(grib_handle_of_accessor(a), "codedValues", values, &size); + values = (double*)grib_context_malloc_clear(context_, size * sizeof(double)); + err = grib_get_double_array(grib_handle_of_accessor(this), "codedValues", values, &size); if (err) { - grib_context_free(a->context, values); + grib_context_free(context_, values); return err; } for (i = 0; i < len; i++) { val_array[i] = values[index_array[i]]; } - grib_context_free(a->context, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } -int grib_accessor_class_data_apply_boustrophedonic_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_apply_boustrophedonic_t::pack_double(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; double* values = 0; @@ -212,7 +205,7 @@ int grib_accessor_class_data_apply_boustrophedonic_t::pack_double(grib_accessor* long i, j; long numberOfPoints, numberOfRows, numberOfColumns; - int ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, &numberOfPoints); + int ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfPoints_, &numberOfPoints); if (ret) return ret; @@ -223,23 +216,23 @@ int grib_accessor_class_data_apply_boustrophedonic_t::pack_double(grib_accessor* valuesSize = numberOfPoints; - values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * numberOfPoints); + values = (double*)grib_context_malloc_clear(context_, sizeof(double) * numberOfPoints); pvalues = values; pval = (double*)val; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfRows, &numberOfRows); + ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfRows_, &numberOfRows); if (ret) return ret; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfColumns, &numberOfColumns); + ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfColumns_, &numberOfColumns); if (ret) return ret; - if (grib_get_size(grib_handle_of_accessor(a), self->pl, &plSize) == GRIB_SUCCESS) { + if (grib_get_size(grib_handle_of_accessor(this), pl_, &plSize) == GRIB_SUCCESS) { Assert(plSize == numberOfRows); - pl = (long*)grib_context_malloc_clear(a->context, sizeof(long) * plSize); - ret = grib_get_long_array_internal(grib_handle_of_accessor(a), self->pl, pl, &plSize); + pl = (long*)grib_context_malloc_clear(context_, sizeof(long) * plSize); + ret = grib_get_long_array_internal(grib_handle_of_accessor(this), pl_, pl, &plSize); if (ret) return ret; @@ -257,7 +250,7 @@ int grib_accessor_class_data_apply_boustrophedonic_t::pack_double(grib_accessor* } } - grib_context_free(a->context, pl); + grib_context_free(context_, pl); } else { for (j = 0; j < numberOfRows; j++) { @@ -273,16 +266,16 @@ int grib_accessor_class_data_apply_boustrophedonic_t::pack_double(grib_accessor* } } } - ret = grib_set_double_array_internal(grib_handle_of_accessor(a), self->values, values, valuesSize); + ret = grib_set_double_array_internal(grib_handle_of_accessor(this), values_, values, valuesSize); if (ret) return ret; - grib_context_free(a->context, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } -int grib_accessor_class_data_apply_boustrophedonic_t::get_native_type(grib_accessor* a) +long grib_accessor_data_apply_boustrophedonic_t::get_native_type() { return GRIB_TYPE_DOUBLE; } diff --git a/src/accessor/grib_accessor_class_data_apply_boustrophedonic.h b/src/accessor/grib_accessor_class_data_apply_boustrophedonic.h index 97987d217..da7898ddf 100644 --- a/src/accessor/grib_accessor_class_data_apply_boustrophedonic.h +++ b/src/accessor/grib_accessor_class_data_apply_boustrophedonic.h @@ -15,26 +15,23 @@ 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_data_apply_boustrophedonic_t() : + grib_accessor_gen_t() { class_name_ = "data_apply_boustrophedonic"; } 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; + long get_native_type() override; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_float(float* val, size_t* len) override; + int value_count(long*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + int unpack_double_element(size_t i, double* val) override; + int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; + +public: + const char* values_; + const char* numberOfRows_; + const char* numberOfColumns_; + const char* numberOfPoints_; + const char* pl_; }; diff --git a/src/accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.cc b/src/accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.cc index 4ff1322d3..a0783f98b 100644 --- a/src/accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.cc +++ b/src/accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.cc @@ -10,54 +10,49 @@ #include "grib_accessor_class_data_apply_boustrophedonic_bitmap.h" -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; +grib_accessor_data_apply_boustrophedonic_bitmap_t _grib_accessor_data_apply_boustrophedonic_bitmap{}; +grib_accessor* grib_accessor_data_apply_boustrophedonic_bitmap = &_grib_accessor_data_apply_boustrophedonic_bitmap; - -void grib_accessor_class_data_apply_boustrophedonic_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_apply_boustrophedonic_bitmap_t::init(const long v, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, v, args); - grib_accessor_data_apply_boustrophedonic_bitmap_t* self = (grib_accessor_data_apply_boustrophedonic_bitmap_t*)a; - grib_handle* gh = grib_handle_of_accessor(a); + grib_accessor_gen_t::init(v, args); + int n = 0; + grib_handle* gh = grib_handle_of_accessor(this); - int n = 0; - self->coded_values = grib_arguments_get_name(gh, args, n++); - self->bitmap = grib_arguments_get_name(gh, args, n++); - self->missing_value = grib_arguments_get_name(gh, args, n++); - self->binary_scale_factor = grib_arguments_get_name(gh, args, n++); + coded_values_ = grib_arguments_get_name(gh, args, n++); + bitmap_ = grib_arguments_get_name(gh, args, n++); + missing_value_ = grib_arguments_get_name(gh, args, n++); + binary_scale_factor_ = grib_arguments_get_name(gh, args, n++); - self->numberOfRows = grib_arguments_get_name(gh, args, n++); - self->numberOfColumns = grib_arguments_get_name(gh, args, n++); - self->numberOfPoints = grib_arguments_get_name(gh, args, n++); + numberOfRows_ = grib_arguments_get_name(gh, args, n++); + numberOfColumns_ = grib_arguments_get_name(gh, args, n++); + numberOfPoints_ = grib_arguments_get_name(gh, args, n++); - a->length = 0; + length_ = 0; } -void grib_accessor_class_data_apply_boustrophedonic_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_data_apply_boustrophedonic_bitmap_t::dump(grib_dumper* dumper) { - grib_dump_values(dumper, a); + grib_dump_values(dumper, this); } -int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::value_count(grib_accessor* a, long* count) +int grib_accessor_data_apply_boustrophedonic_bitmap_t::value_count(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); + grib_handle* gh = grib_handle_of_accessor(this); size_t len = 0; int ret = 0; /* This accessor is for data with a bitmap after all */ - Assert(grib_find_accessor(gh, self->bitmap)); + Assert(grib_find_accessor(gh, bitmap_)); - ret = grib_get_size(gh, self->bitmap, &len); + ret = grib_get_size(gh, bitmap_, &len); *count = len; return ret; } -int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_apply_boustrophedonic_bitmap_t::unpack_double(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); + grib_handle* gh = grib_handle_of_accessor(this); size_t i = 0, j = 0, n_vals = 0, irow = 0; long nn = 0; @@ -67,29 +62,29 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double(grib_ double missing_value = 0; long numberOfPoints, numberOfRows, numberOfColumns; - err = a->value_count(&nn); + err = value_count(&nn); n_vals = nn; if (err) return err; - err = grib_get_long_internal(gh, self->numberOfRows, &numberOfRows); + err = grib_get_long_internal(gh, numberOfRows_, &numberOfRows); if (err) return err; - err = grib_get_long_internal(gh, self->numberOfColumns, &numberOfColumns); + err = grib_get_long_internal(gh, numberOfColumns_, &numberOfColumns); if (err) return err; - err = grib_get_long_internal(gh, self->numberOfPoints, &numberOfPoints); + err = grib_get_long_internal(gh, numberOfPoints_, &numberOfPoints); if (err) return err; Assert(nn == numberOfPoints); - if (!grib_find_accessor(gh, self->bitmap)) - return grib_get_double_array_internal(gh, self->coded_values, val, len); + if (!grib_find_accessor(gh, bitmap_)) + return grib_get_double_array_internal(gh, coded_values_, val, len); - if ((err = grib_get_size(gh, self->coded_values, &coded_n_vals)) != GRIB_SUCCESS) + if ((err = grib_get_size(gh, coded_values_, &coded_n_vals)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(gh, self->missing_value, &missing_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(gh, missing_value_, &missing_value)) != GRIB_SUCCESS) return err; if (*len < n_vals) { @@ -105,21 +100,21 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double(grib_ return GRIB_SUCCESS; } - if ((err = grib_get_double_array_internal(gh, self->bitmap, val, &n_vals)) != GRIB_SUCCESS) + if ((err = grib_get_double_array_internal(gh, bitmap_, val, &n_vals)) != GRIB_SUCCESS) return err; - coded_vals = (double*)grib_context_malloc(a->context, coded_n_vals * sizeof(double)); + coded_vals = (double*)grib_context_malloc(context_, coded_n_vals * sizeof(double)); if (coded_vals == NULL) return GRIB_OUT_OF_MEMORY; - if ((err = grib_get_double_array_internal(gh, self->coded_values, coded_vals, &coded_n_vals)) != GRIB_SUCCESS) { - grib_context_free(a->context, coded_vals); + if ((err = grib_get_double_array_internal(gh, coded_values_, coded_vals, &coded_n_vals)) != GRIB_SUCCESS) { + grib_context_free(context_, coded_vals); return err; } - grib_context_log(a->context, GRIB_LOG_DEBUG, - "grib_accessor_class_data_apply_boustrophedonic_bitmap: unpack_double : creating %s, %d values", - a->name, n_vals); + grib_context_log(context_, GRIB_LOG_DEBUG, + "grib_accessor_data_apply_boustrophedonic_bitmap: unpack_double : creating %s, %d values", + name_, n_vals); /* Boustrophedonic ordering (See GRIB-472): * Values on even rank lines (the initial line scanned having rank 1) are swapped @@ -147,11 +142,11 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double(grib_ else { val[i] = coded_vals[j++]; if (j > coded_n_vals) { - grib_context_free(a->context, coded_vals); - grib_context_log(a->context, GRIB_LOG_ERROR, - "grib_accessor_class_data_apply_boustrophedonic_bitmap [%s]:" + grib_context_free(context_, coded_vals); + grib_context_log(context_, GRIB_LOG_ERROR, + "grib_accessor_data_apply_boustrophedonic_bitmap [%s]:" " unpack_double : number of coded values does not match bitmap %ld %ld", - a->name, coded_n_vals, n_vals); + name_, coded_n_vals, n_vals); return GRIB_ARRAY_TOO_SMALL; } @@ -160,14 +155,13 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double(grib_ *len = n_vals; - grib_context_free(a->context, coded_vals); + grib_context_free(context_, coded_vals); return err; } -int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_data_apply_boustrophedonic_bitmap_t::unpack_double_element(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); + grib_handle* gh = grib_handle_of_accessor(this); int err = 0, i = 0; size_t cidx = 0; double missing_value = 0; @@ -175,18 +169,18 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme size_t n_vals = 0; long nn = 0; - err = a->value_count(&nn); + err = value_count(&nn); n_vals = nn; if (err) return err; - if (!grib_find_accessor(gh, self->bitmap)) - return grib_get_double_element_internal(gh, self->coded_values, idx, val); + if (!grib_find_accessor(gh, bitmap_)) + return grib_get_double_element_internal(gh, coded_values_, idx, val); - if ((err = grib_get_double_internal(gh, self->missing_value, &missing_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(gh, missing_value_, &missing_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_element_internal(gh, self->bitmap, idx, val)) != GRIB_SUCCESS) + if ((err = grib_get_double_element_internal(gh, bitmap_, idx, val)) != GRIB_SUCCESS) return err; if (*val == 0) { @@ -194,11 +188,11 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme return GRIB_SUCCESS; } - bvals = (double*)grib_context_malloc(a->context, n_vals * sizeof(double)); + bvals = (double*)grib_context_malloc(context_, n_vals * sizeof(double)); if (bvals == NULL) return GRIB_OUT_OF_MEMORY; - if ((err = grib_get_double_array_internal(gh, self->bitmap, bvals, &n_vals)) != GRIB_SUCCESS) + if ((err = grib_get_double_array_internal(gh, bitmap_, bvals, &n_vals)) != GRIB_SUCCESS) return err; cidx = 0; @@ -206,15 +200,14 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme cidx += bvals[i]; } - grib_context_free(a->context, bvals); + grib_context_free(context_, bvals); - return grib_get_double_element_internal(gh, self->coded_values, cidx, val); + return grib_get_double_element_internal(gh, coded_values_, cidx, val); } -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) +int grib_accessor_data_apply_boustrophedonic_bitmap_t::unpack_double_element_set(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); + grib_handle* gh = grib_handle_of_accessor(this); int err = 0, all_missing = 1; size_t cidx = 0; /* index into the coded_values array */ size_t* cidx_array = NULL; /* array of indexes into the coded_values */ @@ -224,17 +217,17 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme size_t n_vals = 0, i = 0, j = 0, idx = 0, count_1s = 0, ci = 0; long nn = 0; - err = a->value_count(&nn); + err = value_count(&nn); n_vals = nn; if (err) return err; - if (!grib_find_accessor(gh, self->bitmap)) - return grib_get_double_element_set_internal(gh, self->coded_values, index_array, len, val_array); + if (!grib_find_accessor(gh, bitmap_)) + return grib_get_double_element_set_internal(gh, coded_values_, index_array, len, val_array); - if ((err = grib_get_double_internal(gh, self->missing_value, &missing_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(gh, missing_value_, &missing_value)) != GRIB_SUCCESS) return err; - err = grib_get_double_element_set_internal(gh, self->bitmap, index_array, len, val_array); + err = grib_get_double_element_set_internal(gh, bitmap_, index_array, len, val_array); if (err) return err; for (i = 0; i < len; i++) { if (val_array[i] == 0) { @@ -253,14 +246,14 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme /* At this point val_array contains entries which are either missing_value or 1 */ /* Now we need to dig into the codes values with index array of count_1s */ - bvals = (double*)grib_context_malloc(a->context, n_vals * sizeof(double)); + bvals = (double*)grib_context_malloc(context_, n_vals * sizeof(double)); if (!bvals) return GRIB_OUT_OF_MEMORY; - if ((err = grib_get_double_array_internal(gh, self->bitmap, bvals, &n_vals)) != GRIB_SUCCESS) + if ((err = grib_get_double_array_internal(gh, bitmap_, bvals, &n_vals)) != GRIB_SUCCESS) return err; - cidx_array = (size_t*)grib_context_malloc(a->context, count_1s * sizeof(size_t)); - cval_array = (double*)grib_context_malloc(a->context, count_1s * sizeof(double)); + cidx_array = (size_t*)grib_context_malloc(context_, count_1s * sizeof(size_t)); + cval_array = (double*)grib_context_malloc(context_, count_1s * sizeof(double)); ci = 0; for (i = 0; i < len; i++) { @@ -274,7 +267,7 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme cidx_array[ci++] = cidx; } } - err = grib_get_double_element_set_internal(gh, self->coded_values, cidx_array, count_1s, cval_array); + err = grib_get_double_element_set_internal(gh, coded_values_, cidx_array, count_1s, cval_array); if (err) return err; /* Transfer from cval_array to our result val_array */ @@ -285,18 +278,16 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::unpack_double_eleme } } - grib_context_free(a->context, bvals); - grib_context_free(a->context, cidx_array); - grib_context_free(a->context, cval_array); + grib_context_free(context_, bvals); + grib_context_free(context_, cidx_array); + grib_context_free(context_, cval_array); return GRIB_SUCCESS; } -int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_apply_boustrophedonic_bitmap_t::pack_double(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); + grib_handle* gh = grib_handle_of_accessor(this); int err = 0; size_t bmaplen = *len; size_t irow = 0; @@ -311,30 +302,30 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::pack_double(grib_ac if (*len == 0) return GRIB_NO_VALUES; - if (!grib_find_accessor(gh, self->bitmap)) { - err = grib_set_double_array_internal(gh, self->coded_values, val, *len); - /*printf("SETTING TOTAL number_of_data_points %s %ld\n",self->number_of_data_points,*len);*/ - /*if(self->number_of_data_points) - grib_set_long_internal(gh,self->number_of_data_points,*len);*/ + if (!grib_find_accessor(gh, bitmap_)) { + err = grib_set_double_array_internal(gh, coded_values_, val, *len); + /*printf("SETTING TOTAL number_of_data_points %s %ld\n",number_of_data_points_ ,*len);*/ + /*if(number_of_data_points_ ) + grib_set_long_internal(gh,number_of_data_points_ ,*len);*/ return err; } - if ((err = grib_get_double_internal(gh, self->missing_value, &missing_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(gh, missing_value_, &missing_value)) != GRIB_SUCCESS) return err; - err = grib_get_long_internal(gh, self->numberOfRows, &numberOfRows); + err = grib_get_long_internal(gh, numberOfRows_, &numberOfRows); if (err) return err; - err = grib_get_long_internal(gh, self->numberOfColumns, &numberOfColumns); + err = grib_get_long_internal(gh, numberOfColumns_, &numberOfColumns); if (err) return err; - err = grib_get_long_internal(gh, self->numberOfPoints, &numberOfPoints); + err = grib_get_long_internal(gh, numberOfPoints_, &numberOfPoints); if (err) return err; Assert(numberOfPoints == bmaplen); /* Create a copy of the incoming 'val' array because we're going to change it */ - values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * numberOfPoints); + values = (double*)grib_context_malloc_clear(context_, sizeof(double) * numberOfPoints); if (!values) return GRIB_OUT_OF_MEMORY; for (i = 0; i < numberOfPoints; ++i) { @@ -356,19 +347,19 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::pack_double(grib_ac } } /* Now set the bitmap based on the array with the boustrophedonic ordering */ - if ((err = grib_set_double_array_internal(gh, self->bitmap, values, bmaplen)) != GRIB_SUCCESS) + if ((err = grib_set_double_array_internal(gh, bitmap_, values, bmaplen)) != GRIB_SUCCESS) return err; - grib_context_free(a->context, values); + grib_context_free(context_, values); coded_n_vals = *len; if (coded_n_vals < 1) { - err = grib_set_double_array_internal(gh, self->coded_values, NULL, 0); + err = grib_set_double_array_internal(gh, coded_values_, NULL, 0); return err; } - coded_vals = (double*)grib_context_malloc_clear(a->context, coded_n_vals * sizeof(double)); + coded_vals = (double*)grib_context_malloc_clear(context_, coded_n_vals * sizeof(double)); if (!coded_vals) return GRIB_OUT_OF_MEMORY; @@ -380,23 +371,23 @@ int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::pack_double(grib_ac } } - err = grib_set_double_array_internal(gh, self->coded_values, coded_vals, j); + err = grib_set_double_array_internal(gh, coded_values_, coded_vals, j); if (j == 0) { - /*if (self->number_of_values) - err=grib_set_long_internal(gh,self->number_of_values,0);*/ - if (self->binary_scale_factor) - err = grib_set_long_internal(gh, self->binary_scale_factor, 0); + /*if (number_of_values_ ) + err=grib_set_long_internal(gh,number_of_values_ ,0);*/ + if (binary_scale_factor_) + err = grib_set_long_internal(gh, binary_scale_factor_, 0); } - grib_context_free(a->context, coded_vals); + grib_context_free(context_, coded_vals); return err; } -int grib_accessor_class_data_apply_boustrophedonic_bitmap_t::get_native_type(grib_accessor* a) +long grib_accessor_data_apply_boustrophedonic_bitmap_t::get_native_type() { // 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_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(this),coded_values_ )); return GRIB_TYPE_DOUBLE; } diff --git a/src/accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.h b/src/accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.h index fee603876..f8e9a193f 100644 --- a/src/accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.h +++ b/src/accessor/grib_accessor_class_data_apply_boustrophedonic_bitmap.h @@ -15,27 +15,24 @@ 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_data_apply_boustrophedonic_bitmap_t() : + grib_accessor_gen_t() { class_name_ = "data_apply_boustrophedonic_bitmap"; } 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; + long get_native_type() override; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + int unpack_double_element(size_t i, double* val) override; + int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; + +private: + 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_; }; diff --git a/src/accessor/grib_accessor_class_data_ccsds_packing.cc b/src/accessor/grib_accessor_class_data_ccsds_packing.cc index 5b0813bfd..b26157f46 100644 --- a/src/accessor/grib_accessor_class_data_ccsds_packing.cc +++ b/src/accessor/grib_accessor_class_data_ccsds_packing.cc @@ -18,37 +18,32 @@ #endif #endif +grib_accessor_data_ccsds_packing_t _grib_accessor_data_ccsds_packing{}; +grib_accessor* grib_accessor_data_ccsds_packing = &_grib_accessor_data_ccsds_packing; -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; - - -void grib_accessor_class_data_ccsds_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_ccsds_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_values_t::init(a, v, args); - grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a; + grib_accessor_values_t::init(v, args); - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); + number_of_values_ = grib_arguments_get_name(h, args, carg_++); + reference_value_ = grib_arguments_get_name(h, args, carg_++); + binary_scale_factor_ = grib_arguments_get_name(h, args, carg_++); + decimal_scale_factor_ = grib_arguments_get_name(h, args, carg_++); + optimize_scaling_factor_ = grib_arguments_get_name(h, args, carg_++); + bits_per_value_ = grib_arguments_get_name(h, args, carg_++); + number_of_data_points_ = grib_arguments_get_name(h, args, carg_++); + ccsds_flags_ = grib_arguments_get_name(h, args, carg_++); + ccsds_block_size_ = grib_arguments_get_name(h, args, carg_++); + ccsds_rsi_ = grib_arguments_get_name(h, args, carg_++); - self->number_of_values = grib_arguments_get_name(h, args, self->carg++); - self->reference_value = grib_arguments_get_name(h, args, self->carg++); - self->binary_scale_factor = grib_arguments_get_name(h, args, self->carg++); - self->decimal_scale_factor = grib_arguments_get_name(h, args, self->carg++); - self->optimize_scaling_factor = grib_arguments_get_name(h, args, self->carg++); - self->bits_per_value = grib_arguments_get_name(h, args, self->carg++); - self->number_of_data_points = grib_arguments_get_name(h, args, self->carg++); - self->ccsds_flags = grib_arguments_get_name(h, args, self->carg++); - self->ccsds_block_size = grib_arguments_get_name(h, args, self->carg++); - self->ccsds_rsi = grib_arguments_get_name(h, args, self->carg++); - - a->flags |= GRIB_ACCESSOR_FLAG_DATA; + flags_ |= GRIB_ACCESSOR_FLAG_DATA; } -int grib_accessor_class_data_ccsds_packing_t::value_count(grib_accessor* a, long* count) +int grib_accessor_data_ccsds_packing_t::value_count(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); + return grib_get_long_internal(grib_handle_of_accessor(this), number_of_values_, count); } #if defined(HAVE_LIBAEC) || defined(HAVE_AEC) @@ -90,12 +85,10 @@ 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); } -int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_ccsds_packing_t::pack_double(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; + grib_handle* hand = grib_handle_of_accessor(this); + const char* cclass_name = class_name_; int err = GRIB_SUCCESS; size_t buflen = 0, i = 0; bool is_constant_field = false; @@ -119,34 +112,34 @@ int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, cons struct aec_stream strm; - self->dirty = 1; + dirty_ = 1; n_vals = *len; - if ((err = grib_get_long_internal(hand, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(hand, self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(hand, reference_value_, &reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; - // if ((err = grib_get_long_internal(gh, self->optimize_scaling_factor, &optimize_scaling_factor)) != GRIB_SUCCESS) + // if ((err = grib_get_long_internal(gh, optimize_scaling_factor_ , &optimize_scaling_factor)) != GRIB_SUCCESS) // return err; - if ((err = grib_get_long_internal(hand, self->ccsds_flags, &ccsds_flags)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, ccsds_flags_, &ccsds_flags)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->ccsds_block_size, &ccsds_block_size)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, ccsds_block_size_, &ccsds_block_size)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->ccsds_rsi, &ccsds_rsi)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, ccsds_rsi_, &ccsds_rsi)) != GRIB_SUCCESS) return err; modify_aec_flags(&ccsds_flags); // Special case if (*len == 0) { - grib_buffer_replace(a, NULL, 0, 1, 1); + grib_buffer_replace(this, NULL, 0, 1, 1); return GRIB_SUCCESS; } @@ -174,31 +167,31 @@ int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, cons } if (is_constant_field) { -#ifdef DEBUG + #ifdef DEBUG for (i = 1; i < n_vals; i++) { Assert(val[i] == val[0]); } -#endif - if (grib_get_nearest_smaller_value(hand, self->reference_value, val[0], &reference_value) != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, self->reference_value); + #endif + if (grib_get_nearest_smaller_value(hand, reference_value_, val[0], &reference_value) != GRIB_SUCCESS) { + grib_context_log(context_, GRIB_LOG_ERROR, + "%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, reference_value_); return GRIB_INTERNAL_ERROR; } - if ((err = grib_set_double_internal(hand, self->reference_value, reference_value)) != GRIB_SUCCESS) + if ((err = grib_set_double_internal(hand, reference_value_, reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(hand, self->number_of_values, n_vals)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(hand, number_of_values_, n_vals)) != GRIB_SUCCESS) return err; bits_per_value = 0; // ECC-1387 - if ((err = grib_set_long_internal(hand, self->bits_per_value, bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(hand, bits_per_value_, bits_per_value)) != GRIB_SUCCESS) return err; - grib_buffer_replace(a, NULL, 0, 1, 1); + grib_buffer_replace(this, NULL, 0, 1, 1); return GRIB_SUCCESS; } - if ((err = grib_get_long_internal(hand, self->number_of_data_points, &number_of_data_points)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, number_of_data_points_, &number_of_data_points)) != GRIB_SUCCESS) return err; if (bits_per_value == 0 || (binary_scale_factor == 0 && decimal_scale_factor != 0)) { @@ -206,14 +199,14 @@ int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, cons min *= d; max *= d; - if (grib_get_nearest_smaller_value(hand, self->reference_value, min, &reference_value) != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, self->reference_value); + if (grib_get_nearest_smaller_value(hand, reference_value_, min, &reference_value) != GRIB_SUCCESS) { + grib_context_log(context_, GRIB_LOG_ERROR, + "%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, reference_value_); return GRIB_INTERNAL_ERROR; } if (reference_value > min) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: reference_value=%g min_value=%g diff=%g", cclass_name, __func__, reference_value, min, reference_value - min); DEBUG_ASSERT(reference_value <= min); return GRIB_INTERNAL_ERROR; @@ -251,9 +244,9 @@ int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, cons range = (max - min); } - if (grib_get_nearest_smaller_value(hand, self->reference_value, min, &reference_value) != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, self->reference_value); + if (grib_get_nearest_smaller_value(hand, reference_value_, min, &reference_value) != GRIB_SUCCESS) { + grib_context_log(context_, GRIB_LOG_ERROR, + "%s %s: Unable to find nearest_smaller_value of %g for %s", cclass_name, __func__, min, reference_value_); return GRIB_INTERNAL_ERROR; } d = codes_power(decimal_scale_factor, 10); @@ -267,7 +260,7 @@ int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, cons if (nbytes == 3) nbytes = 4; - encoded = reinterpret_cast(grib_context_buffer_malloc_clear(a->context, nbytes * n_vals)); + encoded = reinterpret_cast(grib_context_buffer_malloc_clear(context_, nbytes * n_vals)); if (!encoded) { err = GRIB_OUT_OF_MEMORY; @@ -309,40 +302,40 @@ int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, cons } break; default: - grib_context_log(a->context, GRIB_LOG_ERROR, "%s pack_double: packing %s, bits_per_value=%ld (max 32)", - cclass_name, a->name, bits_per_value); + grib_context_log(context_, GRIB_LOG_ERROR, "%s pack_double: packing %s, bits_per_value=%ld (max 32)", + cclass_name, name_, bits_per_value); err = GRIB_INVALID_BPV; goto cleanup; } - grib_context_log(a->context, GRIB_LOG_DEBUG, "%s pack_double: packing %s, %zu values", cclass_name, a->name, n_vals); + grib_context_log(context_, GRIB_LOG_DEBUG, "%s pack_double: packing %s, %zu values", cclass_name, name_, n_vals); // ECC-1431: GRIB2: CCSDS encoding failure AEC_STREAM_ERROR buflen = (nbytes * n_vals) * 67 / 64 + 256; - buf = (unsigned char*)grib_context_buffer_malloc_clear(a->context, buflen); + buf = (unsigned char*)grib_context_buffer_malloc_clear(context_, buflen); if (!buf) { err = GRIB_OUT_OF_MEMORY; goto cleanup; } - if ((err = grib_set_double_internal(hand, self->reference_value, reference_value)) != GRIB_SUCCESS) + if ((err = grib_set_double_internal(hand, reference_value_, reference_value)) != GRIB_SUCCESS) return err; { // Make sure we can decode it again double ref = 1e-100; - grib_get_double_internal(hand, self->reference_value, &ref); + grib_get_double_internal(hand, reference_value_, &ref); if (ref != reference_value) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)", - cclass_name, __func__, self->reference_value, ref, reference_value); + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)", + cclass_name, __func__, reference_value_, ref, reference_value); return GRIB_INTERNAL_ERROR; } } - if ((err = grib_set_long_internal(hand, self->binary_scale_factor, binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(hand, binary_scale_factor_, binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(hand, self->decimal_scale_factor, decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(hand, decimal_scale_factor_, decimal_scale_factor)) != GRIB_SUCCESS) return err; strm.flags = ccsds_flags; @@ -361,24 +354,24 @@ int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, cons if (hand->context->debug) print_aec_stream_info(&strm, "pack_double"); if ((err = aec_buffer_encode(&strm)) != AEC_OK) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: aec_buffer_encode error %d (%s)", + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: aec_buffer_encode error %d (%s)", cclass_name, __func__, err, aec_get_error_message(err)); err = GRIB_ENCODING_ERROR; goto cleanup; } buflen = strm.total_out; - grib_buffer_replace(a, buf, buflen, 1, 1); + grib_buffer_replace(this, buf, buflen, 1, 1); cleanup: - grib_context_buffer_free(a->context, buf); - grib_context_buffer_free(a->context, encoded); + grib_context_buffer_free(context_, buf); + grib_context_buffer_free(context_, encoded); if (err == GRIB_SUCCESS) - err = grib_set_long_internal(hand, self->number_of_values, *len); + err = grib_set_long_internal(hand, number_of_values_, *len); if (err == GRIB_SUCCESS) - err = grib_set_long_internal(hand, self->bits_per_value, strm.bits_per_sample); + err = grib_set_long_internal(hand, bits_per_value_, strm.bits_per_sample); return err; } @@ -386,10 +379,10 @@ cleanup: template static int unpack(grib_accessor* a, T* val, size_t* len) { - static_assert(std::is_floating_point::value, "Requires floating point numbers"); 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; + static_assert(std::is_floating_point::value, "Requires floating point numbers"); + grib_handle* hand = grib_handle_of_accessor(a); + const char* cclass_name = a->class_name_; int err = GRIB_SUCCESS, i = 0; size_t buflen = 0; @@ -413,28 +406,28 @@ static int unpack(grib_accessor* a, T* val, size_t* len) long ccsds_rsi; size_t nbytes; - self->dirty = 0; + a->dirty_ = 0; if ((err = a->value_count(&nn)) != GRIB_SUCCESS) return err; n_vals = nn; - if ((err = grib_get_long_internal(hand, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, self->bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(hand, self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(hand, self->reference_value_, &reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; // ECC-477: Don't call grib_get_long_internal to suppress error message being output - if ((err = grib_get_long(hand, self->ccsds_flags, &ccsds_flags)) != GRIB_SUCCESS) + if ((err = grib_get_long(hand, self->ccsds_flags_, &ccsds_flags)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->ccsds_block_size, &ccsds_block_size)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, self->ccsds_block_size_, &ccsds_block_size)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->ccsds_rsi, &ccsds_rsi)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, self->ccsds_rsi_, &ccsds_rsi)) != GRIB_SUCCESS) return err; modify_aec_flags(&ccsds_flags); @@ -454,7 +447,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) bscale = codes_power(binary_scale_factor, 2); dscale = codes_power(-decimal_scale_factor, 10); - buflen = a->byte_count(); + buflen = self->byte_count(); buf = (unsigned char*)hand->buffer->data; buf += a->byte_offset(); strm.flags = ccsds_flags; @@ -470,7 +463,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) nbytes = 4; size = n_vals * nbytes; - decoded = (unsigned char*)grib_context_buffer_malloc_clear(a->context, size); + decoded = (unsigned char*)grib_context_buffer_malloc_clear(a->context_, size); if (!decoded) { err = GRIB_OUT_OF_MEMORY; goto cleanup; @@ -481,7 +474,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) if (hand->context->debug) print_aec_stream_info(&strm, "unpack_*"); if ((err = aec_buffer_decode(&strm)) != AEC_OK) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: aec_buffer_decode error %d (%s)", + grib_context_log(a->context_, GRIB_LOG_ERROR, "%s %s: aec_buffer_decode error %d (%s)", cclass_name, __func__, err, aec_get_error_message(err)); err = GRIB_DECODING_ERROR; goto cleanup; @@ -508,8 +501,8 @@ static int unpack(grib_accessor* a, T* val, size_t* len) } break; default: - grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: unpacking %s, bits_per_value=%ld (max 32)", - cclass_name, __func__, a->name, bits_per_value); + grib_context_log(a->context_, GRIB_LOG_ERROR, "%s %s: unpacking %s, bits_per_value=%ld (max 32)", + cclass_name, __func__, a->name_, bits_per_value); err = GRIB_INVALID_BPV; goto cleanup; } @@ -517,35 +510,33 @@ static int unpack(grib_accessor* a, T* val, size_t* len) *len = n_vals; cleanup: - grib_context_buffer_free(a->context, decoded); + grib_context_buffer_free(a->context_, decoded); return err; } -int grib_accessor_class_data_ccsds_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_ccsds_packing_t::unpack_double(double* val, size_t* len) { - return unpack(a, val, len); + return unpack(this, val, len); } -int grib_accessor_class_data_ccsds_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_data_ccsds_packing_t::unpack_float(float* val, size_t* len) { - return unpack(a, val, len); + return unpack(this, val, len); } -int grib_accessor_class_data_ccsds_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_data_ccsds_packing_t::unpack_double_element(size_t idx, double* val) { // The index idx relates to codedValues NOT values! - const grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a; - - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); int err = 0; size_t size = 0; long bits_per_value = 0; double reference_value = 0; double* values = NULL; - if ((err = grib_get_long_internal(hand, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(hand, self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(hand, reference_value_, &reference_value)) != GRIB_SUCCESS) return err; // Special case of constant field @@ -558,30 +549,29 @@ int grib_accessor_class_data_ccsds_packing_t::unpack_double_element(grib_accesso if (err) return err; if (idx > size) return GRIB_INVALID_ARGUMENT; - values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double)); + values = (double*)grib_context_malloc_clear(context_, size * sizeof(double)); err = grib_get_double_array(hand, "codedValues", values, &size); if (err) { - grib_context_free(a->context, values); + grib_context_free(context_, values); return err; } *val = values[idx]; - grib_context_free(a->context, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } -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) +int grib_accessor_data_ccsds_packing_t::unpack_double_element_set(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); + grib_handle* hand = grib_handle_of_accessor(this); size_t size = 0, i = 0; double* values = NULL; int err = 0; long bits_per_value = 0; double reference_value = 0; - if ((err = grib_get_long_internal(hand, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(hand, self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(hand, reference_value_, &reference_value)) != GRIB_SUCCESS) return err; // Special case of constant field @@ -593,7 +583,7 @@ int grib_accessor_class_data_ccsds_packing_t::unpack_double_element_set(grib_acc } // GRIB-564: The indexes in index_array relate to codedValues NOT values! - err = grib_get_size(grib_handle_of_accessor(a), "codedValues", &size); + err = grib_get_size(grib_handle_of_accessor(this), "codedValues", &size); if (err) return err; @@ -601,17 +591,17 @@ int grib_accessor_class_data_ccsds_packing_t::unpack_double_element_set(grib_acc if (index_array[i] > size) return GRIB_INVALID_ARGUMENT; } - values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double)); - err = grib_get_double_array(grib_handle_of_accessor(a), "codedValues", values, &size); + values = (double*)grib_context_malloc_clear(context_, size * sizeof(double)); + err = grib_get_double_array(grib_handle_of_accessor(this), "codedValues", values, &size); if (err) { - grib_context_free(a->context, values); + grib_context_free(context_, values); return err; } for (i = 0; i < len; i++) { val_array[i] = values[index_array[i]]; } - grib_context_free(a->context, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } @@ -623,29 +613,29 @@ static void print_error_feature_not_enabled(grib_context* c) "CCSDS support not enabled. " "Please rebuild with -DENABLE_AEC=ON (Adaptive Entropy Coding library)"); } -int grib_accessor_class_data_ccsds_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_ccsds_packing_t::pack_double(const double* val, size_t* len) { - print_error_feature_not_enabled(a->context); + print_error_feature_not_enabled(context_); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -int grib_accessor_class_data_ccsds_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_ccsds_packing_t::unpack_double(double* val, size_t* len) { - print_error_feature_not_enabled(a->context); + print_error_feature_not_enabled(context_); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -int grib_accessor_class_data_ccsds_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_data_ccsds_packing_t::unpack_float(float* val, size_t* len) { - print_error_feature_not_enabled(a->context); + print_error_feature_not_enabled(context_); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -int grib_accessor_class_data_ccsds_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_data_ccsds_packing_t::unpack_double_element(size_t idx, double* val) { - print_error_feature_not_enabled(a->context); + print_error_feature_not_enabled(context_); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -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) +int grib_accessor_data_ccsds_packing_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) { - print_error_feature_not_enabled(a->context); + print_error_feature_not_enabled(context_); return GRIB_FUNCTIONALITY_NOT_ENABLED; } diff --git a/src/accessor/grib_accessor_class_data_ccsds_packing.h b/src/accessor/grib_accessor_class_data_ccsds_packing.h index 0f9430232..43ae75b6b 100644 --- a/src/accessor/grib_accessor_class_data_ccsds_packing.h +++ b/src/accessor/grib_accessor_class_data_ccsds_packing.h @@ -16,30 +16,26 @@ 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_data_ccsds_packing_t() : + grib_accessor_values_t() { class_name_ = "data_ccsds_packing"; } 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; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_float(float* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + int unpack_double_element(size_t i, double* val) override; + int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; + +public: + 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_; }; diff --git a/src/accessor/grib_accessor_class_data_complex_packing.cc b/src/accessor/grib_accessor_class_data_complex_packing.cc index 81e402303..3e84613e3 100644 --- a/src/accessor/grib_accessor_class_data_complex_packing.cc +++ b/src/accessor/grib_accessor_class_data_complex_packing.cc @@ -11,53 +11,50 @@ #include "grib_accessor_class_data_complex_packing.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; +grib_accessor_data_complex_packing_t _grib_accessor_data_complex_packing{}; +grib_accessor* grib_accessor_data_complex_packing = &_grib_accessor_data_complex_packing; -void grib_accessor_class_data_complex_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_complex_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_simple_packing_t::init(a, v, args); - grib_accessor_data_complex_packing_t* self = (grib_accessor_data_complex_packing_t*)a; - grib_handle* gh = grib_handle_of_accessor(a); + grib_accessor_data_simple_packing_t::init(v, args); + grib_handle* gh = grib_handle_of_accessor(this); - self->GRIBEX_sh_bug_present = grib_arguments_get_name(gh, args, self->carg++); - self->ieee_floats = grib_arguments_get_name(gh, args, self->carg++); - self->laplacianOperatorIsSet = grib_arguments_get_name(gh, args, self->carg++); - self->laplacianOperator = grib_arguments_get_name(gh, args, self->carg++); - self->sub_j = grib_arguments_get_name(gh, args, self->carg++); - self->sub_k = grib_arguments_get_name(gh, args, self->carg++); - self->sub_m = grib_arguments_get_name(gh, args, self->carg++); - self->pen_j = grib_arguments_get_name(gh, args, self->carg++); - self->pen_k = grib_arguments_get_name(gh, args, self->carg++); - self->pen_m = grib_arguments_get_name(gh, args, self->carg++); + GRIBEX_sh_bug_present_ = grib_arguments_get_name(gh, args, carg_++); + ieee_floats_ = grib_arguments_get_name(gh, args, carg_++); + laplacianOperatorIsSet_ = grib_arguments_get_name(gh, args, carg_++); + laplacianOperator_ = grib_arguments_get_name(gh, args, carg_++); + sub_j_ = grib_arguments_get_name(gh, args, carg_++); + sub_k_ = grib_arguments_get_name(gh, args, carg_++); + sub_m_ = grib_arguments_get_name(gh, args, carg_++); + pen_j_ = grib_arguments_get_name(gh, args, carg_++); + pen_k_ = grib_arguments_get_name(gh, args, carg_++); + pen_m_ = grib_arguments_get_name(gh, args, carg_++); - a->flags |= GRIB_ACCESSOR_FLAG_DATA; + flags_ |= GRIB_ACCESSOR_FLAG_DATA; } -int grib_accessor_class_data_complex_packing_t::value_count(grib_accessor* a, long* count) +int grib_accessor_data_complex_packing_t::value_count(long* count) { - grib_accessor_data_complex_packing_t* self = (grib_accessor_data_complex_packing_t*)a; - int ret = GRIB_SUCCESS; - grib_handle* gh = grib_handle_of_accessor(a); + grib_handle* gh = grib_handle_of_accessor(this); long pen_j = 0; long pen_k = 0; long pen_m = 0; *count = 0; - if (a->length == 0) + if (length_ == 0) return 0; - if ((ret = grib_get_long_internal(gh, self->pen_j, &pen_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, pen_j_, &pen_j)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->pen_k, &pen_k)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, pen_k_, &pen_k)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->pen_m, &pen_m)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, pen_m_, &pen_m)) != GRIB_SUCCESS) return ret; if (pen_j != pen_k || pen_j != pen_m) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Invalid pentagonal resolution parameters"); - grib_context_log(a->context, GRIB_LOG_ERROR, "pen_j=%ld, pen_k=%ld, pen_m=%ld", pen_j, pen_k, pen_m); + grib_context_log(context_, GRIB_LOG_ERROR, "Invalid pentagonal resolution parameters"); + grib_context_log(context_, GRIB_LOG_ERROR, "pen_j=%ld, pen_k=%ld, pen_m=%ld", pen_j, pen_k, pen_m); return GRIB_DECODING_ERROR; } *count = (pen_j + 1) * (pen_j + 2); @@ -169,11 +166,10 @@ double calculate_pfactor(const grib_context* ctx, const double* spectralField, l return pFactor; } -int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_complex_packing_t::pack_double(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; + grib_handle* gh = grib_handle_of_accessor(this); + const char* cclass_name = class_name_; size_t i = 0; int ret = GRIB_SUCCESS; @@ -228,42 +224,42 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co if (*len == 0) return GRIB_NO_VALUES; - if ((ret = grib_get_long_internal(gh, self->offsetdata, &offsetdata)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, offsetdata_, &offsetdata)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->optimize_scaling_factor, &optimize_scaling_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, optimize_scaling_factor_, &optimize_scaling_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->GRIBEX_sh_bug_present, &GRIBEX_sh_bug_present)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, GRIBEX_sh_bug_present_, &GRIBEX_sh_bug_present)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->ieee_floats, &ieee_floats)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, ieee_floats_, &ieee_floats)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->laplacianOperatorIsSet, &laplacianOperatorIsSet)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, laplacianOperatorIsSet_, &laplacianOperatorIsSet)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(gh, self->laplacianOperator, &laplacianOperator)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(gh, laplacianOperator_, &laplacianOperator)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->sub_j, &sub_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, sub_j_, &sub_j)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->sub_k, &sub_k)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, sub_k_, &sub_k)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->sub_m, &sub_m)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, sub_m_, &sub_m)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->pen_j, &pen_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, pen_j_, &pen_j)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->pen_k, &pen_k)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, pen_k_, &pen_k)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->pen_m, &pen_m)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, pen_m_, &pen_m)) != GRIB_SUCCESS) return ret; - self->dirty = 1; + dirty_ = 1; switch (ieee_floats) { case 0: @@ -283,20 +279,20 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co } if (sub_j != sub_k || sub_j != sub_m || pen_j != pen_k || pen_j != pen_m) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Invalid pentagonal resolution parameters", cclass_name); + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Invalid pentagonal resolution parameters", cclass_name); return GRIB_ENCODING_ERROR; } n_vals = (pen_j + 1) * (pen_j + 2); if (*len != n_vals) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Wrong number of values, expected %ld - got %zu", + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Wrong number of values, expected %ld - got %zu", cclass_name, n_vals, *len); return GRIB_INTERNAL_ERROR; } /* Data Quality checks */ - if (a->context->grib_data_quality_checks) { + if (context_->grib_data_quality_checks) { /* First value is the field's average */ double min_val = val[0]; double max_val = min_val; @@ -308,7 +304,7 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co double* values; d = codes_power(decimal_scale_factor, 10); if (d) { - values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * n_vals); + values = (double*)grib_context_malloc_clear(context_, sizeof(double) * n_vals); for (i = 0; i < n_vals; i++) values[i] = val[i] * d; } @@ -316,20 +312,20 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co values = (double*)val; } buflen = n_vals * bytes; - buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen); - grib_ieee_encode_array(a->context, values, n_vals, bytes, buf); + buf = (unsigned char*)grib_context_malloc_clear(context_, buflen); + grib_ieee_encode_array(context_, values, n_vals, bytes, buf); if (d) - grib_context_free(a->context, values); - grib_buffer_replace(a, buf, buflen, 1, 1); - grib_context_free(a->context, buf); + grib_context_free(context_, values); + grib_buffer_replace(this, buf, buflen, 1, 1); + grib_context_free(context_, buf); return 0; } if (!laplacianOperatorIsSet) { - laplacianOperator = calculate_pfactor(a->context, val, pen_j, sub_j); - if ((ret = grib_set_double_internal(gh, self->laplacianOperator, laplacianOperator)) != GRIB_SUCCESS) + laplacianOperator = calculate_pfactor(context_, val, pen_j, sub_j); + if ((ret = grib_set_double_internal(gh, laplacianOperator_, laplacianOperator)) != GRIB_SUCCESS) return ret; - grib_get_double_internal(gh, self->laplacianOperator, &laplacianOperator); + grib_get_double_internal(gh, laplacianOperator_, &laplacianOperator); } hsize = bytes * (sub_k + 1) * (sub_k + 2); @@ -337,7 +333,7 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co buflen = hsize + lsize; - buf = (unsigned char*)grib_context_malloc(a->context, buflen); + buf = (unsigned char*)grib_context_malloc(context_, buflen); hres = buf; lres = buf + hsize; @@ -346,7 +342,7 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co lpos = 0; hpos = 0; - scals = (double*)grib_context_malloc(a->context, maxv * sizeof(double)); + scals = (double*)grib_context_malloc(context_, maxv * sizeof(double)); if (!scals) return GRIB_OUT_OF_MEMORY; scals[0] = 0; @@ -396,23 +392,23 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co } if (optimize_scaling_factor) { - ret = grib_optimize_decimal_factor(a, self->reference_value, + ret = grib_optimize_decimal_factor(this, reference_value_, max, min, bits_per_value, 0, 1, &decimal_scale_factor, &binary_scale_factor, &reference_value); if (ret != GRIB_SUCCESS) { grib_context_log(gh->context, GRIB_LOG_ERROR, - "%s: Unable to find nearest_smaller_value of %g for %s", cclass_name, min, self->reference_value); + "%s: Unable to find nearest_smaller_value of %g for %s", cclass_name, min, reference_value_); return GRIB_INTERNAL_ERROR; } d = codes_power(+decimal_scale_factor, 10); } else { d = codes_power(+decimal_scale_factor, 10); - if (grib_get_nearest_smaller_value(gh, self->reference_value, d * min, &reference_value) != GRIB_SUCCESS) { + if (grib_get_nearest_smaller_value(gh, reference_value_, d * min, &reference_value) != GRIB_SUCCESS) { grib_context_log(gh->context, GRIB_LOG_ERROR, - "%s: Unable to find nearest_smaller_value of %g for %s", cclass_name, d * min, self->reference_value); + "%s: Unable to find nearest_smaller_value of %g for %s", cclass_name, d * min, reference_value_); return GRIB_INTERNAL_ERROR; } binary_scale_factor = grib_get_binary_scale_fact(d * max, reference_value, bits_per_value, &ret); @@ -424,7 +420,7 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co } else { if (ret != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Cannot compute binary_scale_factor", cclass_name); + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Cannot compute binary_scale_factor", cclass_name); return ret; } } @@ -468,13 +464,13 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co for (lcount = hcount; lcount < maxv; lcount++) { current_val = (((((val[i++] * d) * scals[lup]) - reference_value) * s) + 0.5); if (current_val < 0) - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: negative coput before packing (%g)", cclass_name, current_val); grib_encode_unsigned_longb(lres, current_val, &lpos, bits_per_value); current_val = (((((val[i++] * d) * scals[lup]) - reference_value) * s) + 0.5); if (current_val < 0) - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: negative coput before packing (%g)", cclass_name, current_val); grib_encode_unsigned_longb(lres, current_val, &lpos, bits_per_value); lup++; @@ -484,13 +480,13 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co for (lcount = hcount; lcount < maxv; lcount++) { current_val = (((((val[i++] * d) * scals[lup]) - reference_value) * s) + 0.5); if (current_val < 0) - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: negative coput before packing (%g)", cclass_name, current_val); grib_encode_unsigned_long(lres, current_val, &lpos, bits_per_value); current_val = (((((val[i++] * d) * scals[lup]) - reference_value) * s) + 0.5); if (current_val < 0) - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: negative coput before packing (%g)", cclass_name, current_val); grib_encode_unsigned_long(lres, current_val, &lpos, bits_per_value); lup++; @@ -504,36 +500,36 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co } if (((hpos / 8) != hsize) && ((lpos / 8) != lsize)) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Mismatch in packing between high resolution and low resolution part", cclass_name); - grib_context_free(a->context, buf); - grib_context_free(a->context, scals); + grib_context_free(context_, buf); + grib_context_free(context_, scals); return GRIB_INTERNAL_ERROR; } buflen = ((hpos + lpos) / 8); - if ((ret = grib_set_double_internal(gh, self->reference_value, reference_value)) != GRIB_SUCCESS) + if ((ret = grib_set_double_internal(gh, reference_value_, reference_value)) != GRIB_SUCCESS) return ret; { // Make sure we can decode it again double ref = 1e-100; - grib_get_double_internal(gh, self->reference_value, &ref); + grib_get_double_internal(gh, reference_value_, &ref); if (ref != reference_value) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)", - cclass_name, __func__, self->reference_value, ref, reference_value); + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)", + cclass_name, __func__, reference_value_, ref, reference_value); return GRIB_INTERNAL_ERROR; } } - if ((ret = grib_set_long_internal(gh, self->binary_scale_factor, binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(gh, binary_scale_factor_, binary_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(gh, self->decimal_scale_factor, decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(gh, decimal_scale_factor_, decimal_scale_factor)) != GRIB_SUCCESS) return ret; - grib_buffer_replace(a, buf, buflen, 1, 1); - grib_context_free(a->context, buf); - grib_context_free(a->context, scals); + grib_buffer_replace(this, buf, buflen, 1, 1); + grib_context_free(context_, buf); + grib_context_free(context_, scals); return ret; } @@ -541,10 +537,10 @@ int grib_accessor_class_data_complex_packing_t::pack_double(grib_accessor* a, co template static int unpack_real(grib_accessor* a, T* val, size_t* len) { - static_assert(std::is_floating_point::value, "Requires floating point numbers"); 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; + static_assert(std::is_floating_point::value, "Requires floating point numbers"); + grib_handle* gh = grib_handle_of_accessor(a); + const char* cclass_name = a->class_name_; size_t i = 0; int ret = GRIB_SUCCESS; @@ -599,44 +595,44 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len) return GRIB_ARRAY_TOO_SMALL; } - if ((ret = grib_get_long_internal(gh, self->offsetdata, &offsetdata)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->offsetdata_, &offsetdata)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(gh, self->reference_value, &tmp)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(gh, self->reference_value_, &tmp)) != GRIB_SUCCESS) return ret; reference_value = tmp; - if ((ret = grib_get_long_internal(gh, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->GRIBEX_sh_bug_present, &GRIBEX_sh_bug_present)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->GRIBEX_sh_bug_present_, &GRIBEX_sh_bug_present)) != GRIB_SUCCESS) return ret; /* ECC-774: don't use grib_get_long_internal */ - if ((ret = grib_get_long(gh, self->ieee_floats, &ieee_floats)) != GRIB_SUCCESS) + if ((ret = grib_get_long(gh, self->ieee_floats_, &ieee_floats)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(gh, self->laplacianOperator, &tmp)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(gh, self->laplacianOperator_, &tmp)) != GRIB_SUCCESS) return ret; laplacianOperator = tmp; - if ((ret = grib_get_long_internal(gh, self->sub_j, &sub_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->sub_j_, &sub_j)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->sub_k, &sub_k)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->sub_k_, &sub_k)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->sub_m, &sub_m)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->sub_m_, &sub_m)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->pen_j, &pen_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->pen_j_, &pen_j)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->pen_k, &pen_k)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->pen_k_, &pen_k)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->pen_m, &pen_m)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->pen_m_, &pen_m)) != GRIB_SUCCESS) return ret; - self->dirty = 0; + a->dirty_ = 0; switch (ieee_floats) { case 0: @@ -656,7 +652,7 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len) } if (sub_j != sub_k || sub_j != sub_m || pen_j != pen_k || pen_j != pen_m) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Invalid pentagonal resolution parameters", cclass_name); + grib_context_log(a->context_, GRIB_LOG_ERROR, "%s: Invalid pentagonal resolution parameters", cclass_name); return GRIB_DECODING_ERROR; } @@ -672,7 +668,7 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len) n_vals = (pen_j + 1) * (pen_j + 2); d = codes_power(-decimal_scale_factor, 10); - grib_ieee_decode_array(a->context, buf, n_vals, bytes, val); + grib_ieee_decode_array(a->context_, buf, n_vals, bytes, val); if (d) { for (i = 0; i < n_vals; i++) val[i] *= d; @@ -686,7 +682,7 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len) s = codes_power(binary_scale_factor, 2); d = codes_power(-decimal_scale_factor, 10); - scals = (T*)grib_context_malloc(a->context, maxv * sizeof(T)); + scals = (T*)grib_context_malloc(a->context_, maxv * sizeof(T)); if (!scals) return GRIB_OUT_OF_MEMORY; scals[0] = 0; @@ -695,7 +691,7 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len) if (operat != 0) scals[i] = (1.0 / operat); else { - grib_context_log(a->context, GRIB_LOG_WARNING, + grib_context_log(a->context_, GRIB_LOG_WARNING, "%s: Problem with operator div by zero at index %d of %d", cclass_name, i, maxv); scals[i] = 0; } @@ -755,17 +751,17 @@ static int unpack_real(grib_accessor* a, T* val, size_t* len) Assert(*len >= i); *len = i; - grib_context_free(a->context, scals); + grib_context_free(a->context_, scals); return ret; } -int grib_accessor_class_data_complex_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_complex_packing_t::unpack_double(double* val, size_t* len) { - return unpack_real(a, val, len); + return unpack_real(this, val, len); } -int grib_accessor_class_data_complex_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_data_complex_packing_t::unpack_float(float* val, size_t* len) { // TODO(maee): See ECC-1579 // Investigate why results are not bit-identical @@ -773,18 +769,18 @@ int grib_accessor_class_data_complex_packing_t::unpack_float(grib_accessor* a, f // return unpack(a, val, len); size_t size = *len; - double* val8 = (double*)grib_context_malloc(a->context, size * (sizeof(double))); + double* val8 = (double*)grib_context_malloc(context_, size * (sizeof(double))); if (!val8) return GRIB_OUT_OF_MEMORY; - int err = unpack_real(a, val8, len); + int err = unpack_real(this, val8, len); if (err) { - grib_context_free(a->context, val8); + grib_context_free(context_, val8); return err; } for (size_t i = 0; i < size; i++) val[i] = val8[i]; - grib_context_free(a->context, val8); + grib_context_free(context_, val8); return GRIB_SUCCESS; } diff --git a/src/accessor/grib_accessor_class_data_complex_packing.h b/src/accessor/grib_accessor_class_data_complex_packing.h index ee19b195c..6fd4e72ca 100644 --- a/src/accessor/grib_accessor_class_data_complex_packing.h +++ b/src/accessor/grib_accessor_class_data_complex_packing.h @@ -20,27 +20,24 @@ typedef double (*decode_float_proc)(unsigned long); 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_data_complex_packing_t() : + grib_accessor_data_simple_packing_t() { class_name_ = "data_complex_packing"; } 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; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_float(float* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +public: + 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_; }; diff --git a/src/accessor/grib_accessor_class_data_dummy_field.cc b/src/accessor/grib_accessor_class_data_dummy_field.cc index 735ee6766..590fd9138 100644 --- a/src/accessor/grib_accessor_class_data_dummy_field.cc +++ b/src/accessor/grib_accessor_class_data_dummy_field.cc @@ -10,32 +10,29 @@ #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; +grib_accessor_data_dummy_field_t _grib_accessor_data_dummy_field{}; +grib_accessor* grib_accessor_data_dummy_field = &_grib_accessor_data_dummy_field; - -void grib_accessor_class_data_dummy_field_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_dummy_field_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_g1simple_packing_t::init(a, v, 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++); + grib_accessor_data_g1simple_packing_t::init(v, args); + missing_value_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); + numberOfPoints_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); + bitmap_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); } -int grib_accessor_class_data_dummy_field_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_dummy_field_t::unpack_double(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) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), 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) + if ((err = grib_get_double_internal(grib_handle_of_accessor(this), missing_value_, &missing_value)) != GRIB_SUCCESS) return err; if (*len < n_vals) { @@ -46,8 +43,8 @@ int grib_accessor_class_data_dummy_field_t::unpack_double(grib_accessor* a, doub 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) + if (grib_find_accessor(grib_handle_of_accessor(this), bitmap_)) { + if ((err = grib_set_double_array_internal(grib_handle_of_accessor(this), bitmap_, val, n_vals)) != GRIB_SUCCESS) return err; } @@ -55,10 +52,8 @@ int grib_accessor_class_data_dummy_field_t::unpack_double(grib_accessor* a, doub return err; } -int grib_accessor_class_data_dummy_field_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_dummy_field_t::pack_double(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; @@ -69,36 +64,35 @@ int grib_accessor_class_data_dummy_field_t::pack_double(grib_accessor* a, const 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) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), 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); + buf = (unsigned char*)grib_context_malloc_clear(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); + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), half_byte_, half_byte)) != GRIB_SUCCESS) { + grib_context_free(context_, buf); return err; } - grib_buffer_replace(a, buf, buflen, 1, 1); + grib_buffer_replace(this, buf, buflen, 1, 1); - grib_context_free(a->context, buf); + grib_context_free(context_, buf); return GRIB_SUCCESS; } -int grib_accessor_class_data_dummy_field_t::value_count(grib_accessor* a, long* numberOfPoints) +int grib_accessor_data_dummy_field_t::value_count(long* numberOfPoints) { - grib_accessor_data_dummy_field_t* self = (grib_accessor_data_dummy_field_t*)a; - int err = 0; + 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)); + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), numberOfPoints_, numberOfPoints)) != GRIB_SUCCESS) { + grib_context_log(context_, GRIB_LOG_ERROR, "Unable to get count of %s (%s)", name_, grib_get_error_message(err)); } return err; diff --git a/src/accessor/grib_accessor_class_data_dummy_field.h b/src/accessor/grib_accessor_class_data_dummy_field.h index c846abb98..80cf045bc 100644 --- a/src/accessor/grib_accessor_class_data_dummy_field.h +++ b/src/accessor/grib_accessor_class_data_dummy_field.h @@ -15,19 +15,16 @@ 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_data_dummy_field_t() : + grib_accessor_data_g1simple_packing_t() { class_name_ = "data_dummy_field"; } 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; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* missing_value_; + const char* numberOfPoints_; + const char* bitmap_; }; diff --git a/src/accessor/grib_accessor_class_data_g1complex_packing.cc b/src/accessor/grib_accessor_class_data_g1complex_packing.cc index e943d5a6e..c7795e5f1 100644 --- a/src/accessor/grib_accessor_class_data_g1complex_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1complex_packing.cc @@ -10,28 +10,23 @@ #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; +grib_accessor_data_g1complex_packing_t _grib_accessor_data_g1complex_packing{}; +grib_accessor* grib_accessor_data_g1complex_packing = &_grib_accessor_data_g1complex_packing; - -void grib_accessor_class_data_g1complex_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_g1complex_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_complex_packing_t::init(a, v, 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; + grib_accessor_data_complex_packing_t::init(v, args); + half_byte_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); + N_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); + packingType_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); + ieee_packing_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); + precision_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); + edition_ = 1; + flags_ |= GRIB_ACCESSOR_FLAG_DATA; } -int grib_accessor_class_data_g1complex_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_g1complex_packing_t::pack_double(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; @@ -46,17 +41,17 @@ int grib_accessor_class_data_g1complex_packing_t::pack_double(grib_accessor* a, 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; + // if (c->ieee_packing && ieee_packing_ ) { + // grib_handle* h = grib_handle_of_accessor(this); + // grib_context* c = 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); + // size_t lenstr = strlen(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); + // packingType_s = grib_context_strdup(c, packingType_ ); + // ieee_packing_s = grib_context_strdup(c, ieee_packing_ ); + // precision_s = grib_context_strdup(c, precision_ ); // grib_set_string(h, packingType_s, ieee_packing_s, &lenstr); // grib_set_long(h, precision_s, precision); @@ -67,47 +62,47 @@ int grib_accessor_class_data_g1complex_packing_t::pack_double(grib_accessor* a, // 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) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), 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) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), 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) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), sub_m_, &sub_m)) != GRIB_SUCCESS) return ret; - self->dirty = 1; + dirty_ = 1; Assert((sub_j == sub_k) && (sub_m == sub_j)); - ret = grib_accessor_class_data_complex_packing_t::pack_double(a, val, len); + ret = grib_accessor_data_complex_packing_t::pack_double(val, len); if (ret == GRIB_SUCCESS) { - n = a->offset + 4 * ((sub_k + 1) * (sub_k + 2)); + n = 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) + if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), N_, n)) != GRIB_SUCCESS) return ret; - // ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetsection, &offsetsection); + // ret = grib_get_long_internal(grib_handle_of_accessor(this), 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) + // if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), N_ , n - offsetsection)) != GRIB_SUCCESS) // return ret; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value); + ret = grib_get_long_internal(grib_handle_of_accessor(this), 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); + ret = grib_get_long_internal(grib_handle_of_accessor(this), 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) { + if (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); + ret = grib_set_long_internal(grib_handle_of_accessor(this), half_byte_, half_byte); if (ret != GRIB_SUCCESS) return ret; } diff --git a/src/accessor/grib_accessor_class_data_g1complex_packing.h b/src/accessor/grib_accessor_class_data_g1complex_packing.h index 51457e40e..6bf7430e9 100644 --- a/src/accessor/grib_accessor_class_data_g1complex_packing.h +++ b/src/accessor/grib_accessor_class_data_g1complex_packing.h @@ -15,19 +15,16 @@ 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_data_g1complex_packing_t() : + grib_accessor_data_complex_packing_t() { class_name_ = "data_g1complex_packing"; } 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; + int pack_double(const double* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* N_; + const char* half_byte_; + const char* packingType_; + const char* ieee_packing_; + const char* precision_; }; diff --git a/src/accessor/grib_accessor_class_data_g1second_order_constant_width_packing.cc b/src/accessor/grib_accessor_class_data_g1second_order_constant_width_packing.cc index 7aac0e031..e650fb4f0 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_constant_width_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1second_order_constant_width_packing.cc @@ -11,55 +11,51 @@ #include "grib_accessor_class_data_g1second_order_constant_width_packing.h" #include "grib_scaling.h" -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; +grib_accessor_data_g1second_order_constant_width_packing_t _grib_accessor_data_g1second_order_constant_width_packing{}; +grib_accessor* grib_accessor_data_g1second_order_constant_width_packing = &_grib_accessor_data_g1second_order_constant_width_packing; - -void grib_accessor_class_data_g1second_order_constant_width_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_g1second_order_constant_width_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_simple_packing_t::init(a, v, 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); + grib_accessor_data_simple_packing_t::init(v, args); + grib_handle* hand = grib_handle_of_accessor(this); - self->half_byte = grib_arguments_get_name(hand, args, self->carg++); - self->packingType = grib_arguments_get_name(hand, args, self->carg++); - self->ieee_packing = grib_arguments_get_name(hand, args, self->carg++); - self->precision = grib_arguments_get_name(hand, args, self->carg++); - self->widthOfFirstOrderValues = grib_arguments_get_name(hand, args, self->carg++); - self->N1 = grib_arguments_get_name(hand, args, self->carg++); - self->N2 = grib_arguments_get_name(hand, args, self->carg++); - self->numberOfGroups = grib_arguments_get_name(hand, args, self->carg++); - self->numberOfSecondOrderPackedValues = grib_arguments_get_name(hand, args, self->carg++); - self->extraValues = grib_arguments_get_name(hand, args, self->carg++); - self->Ni = grib_arguments_get_name(hand, args, self->carg++); - self->Nj = grib_arguments_get_name(hand, args, self->carg++); - self->pl = grib_arguments_get_name(hand, args, self->carg++); - self->jPointsAreConsecutive = grib_arguments_get_name(hand, args, self->carg++); - self->bitmap = grib_arguments_get_name(hand, args, self->carg++); - self->groupWidth = grib_arguments_get_name(hand, args, self->carg++); - self->edition = 1; - a->flags |= GRIB_ACCESSOR_FLAG_DATA; + half_byte_ = grib_arguments_get_name(hand, args, carg_++); + packingType_ = grib_arguments_get_name(hand, args, carg_++); + ieee_packing_ = grib_arguments_get_name(hand, args, carg_++); + precision_ = grib_arguments_get_name(hand, args, carg_++); + widthOfFirstOrderValues_ = grib_arguments_get_name(hand, args, carg_++); + N1_ = grib_arguments_get_name(hand, args, carg_++); + N2_ = grib_arguments_get_name(hand, args, carg_++); + numberOfGroups_ = grib_arguments_get_name(hand, args, carg_++); + numberOfSecondOrderPackedValues_ = grib_arguments_get_name(hand, args, carg_++); + extraValues_ = grib_arguments_get_name(hand, args, carg_++); + Ni_ = grib_arguments_get_name(hand, args, carg_++); + Nj_ = grib_arguments_get_name(hand, args, carg_++); + pl_ = grib_arguments_get_name(hand, args, carg_++); + jPointsAreConsecutive_ = grib_arguments_get_name(hand, args, carg_++); + bitmap_ = grib_arguments_get_name(hand, args, carg_++); + groupWidth_ = grib_arguments_get_name(hand, args, carg_++); + edition_ = 1; + flags_ |= GRIB_ACCESSOR_FLAG_DATA; } -int grib_accessor_class_data_g1second_order_constant_width_packing_t::value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues) +int grib_accessor_data_g1second_order_constant_width_packing_t::value_count(long* numberOfSecondOrderPackedValues) { - int err = 0; - grib_accessor_data_g1second_order_constant_width_packing_t* self = (grib_accessor_data_g1second_order_constant_width_packing_t*)a; + int err = 0; *numberOfSecondOrderPackedValues = 0; - err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfSecondOrderPackedValues, numberOfSecondOrderPackedValues); + err = grib_get_long_internal(grib_handle_of_accessor(this), numberOfSecondOrderPackedValues_, numberOfSecondOrderPackedValues); return err; } -int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_float(grib_accessor*, float* val, size_t* len) +int grib_accessor_data_g1second_order_constant_width_packing_t::unpack_float(float* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len) +int grib_accessor_data_g1second_order_constant_width_packing_t::unpack_double(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; @@ -69,68 +65,68 @@ int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_dou long pos = 0; long widthOfFirstOrderValues = 0; long jPointsAreConsecutive; - unsigned char* buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; + unsigned char* buf = (unsigned char*)grib_handle_of_accessor(this)->buffer->data; long i, n; double reference_value; long binary_scale_factor; long decimal_scale_factor; double s, d; long* secondaryBitmap; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); - buf += a->byte_offset(); - if ((ret = grib_get_long_internal(hand, self->numberOfGroups, &numberOfGroups)) != GRIB_SUCCESS) + buf += byte_offset(); + if ((ret = grib_get_long_internal(hand, numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->jPointsAreConsecutive, &jPointsAreConsecutive)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, jPointsAreConsecutive_, &jPointsAreConsecutive)) != GRIB_SUCCESS) return ret; if (jPointsAreConsecutive) { - if ((ret = grib_get_long_internal(hand, self->Ni, &numberPerRow)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, Ni_, &numberPerRow)) != GRIB_SUCCESS) return ret; } else { - if ((ret = grib_get_long_internal(hand, self->Nj, &numberPerRow)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, Nj_, &numberPerRow)) != GRIB_SUCCESS) return ret; } - if ((ret = grib_get_long_internal(hand, self->widthOfFirstOrderValues, &widthOfFirstOrderValues)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, widthOfFirstOrderValues_, &widthOfFirstOrderValues)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(hand, self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(hand, reference_value_, &reference_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->numberOfSecondOrderPackedValues, + if ((ret = grib_get_long_internal(hand, numberOfSecondOrderPackedValues_, &numberOfSecondOrderPackedValues)) != GRIB_SUCCESS) return ret; if (*len < numberOfSecondOrderPackedValues) return GRIB_ARRAY_TOO_SMALL; - if ((ret = grib_get_long_internal(hand, self->groupWidth, &groupWidth)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, groupWidth_, &groupWidth)) != GRIB_SUCCESS) return ret; - secondaryBitmap = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfSecondOrderPackedValues); + secondaryBitmap = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfSecondOrderPackedValues); if (!secondaryBitmap) return GRIB_OUT_OF_MEMORY; grib_decode_long_array(buf, &pos, 1, numberOfSecondOrderPackedValues, secondaryBitmap); pos = 8 * ((pos + 7) / 8); - firstOrderValues = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfGroups); + firstOrderValues = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups); if (!firstOrderValues) return GRIB_OUT_OF_MEMORY; grib_decode_long_array(buf, &pos, widthOfFirstOrderValues, numberOfGroups, firstOrderValues); pos = 8 * ((pos + 7) / 8); - X = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfSecondOrderPackedValues); + X = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfSecondOrderPackedValues); if (!X) return GRIB_OUT_OF_MEMORY; @@ -173,23 +169,23 @@ int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_dou } *len = numberOfSecondOrderPackedValues; - grib_context_free(a->context, secondaryBitmap); - grib_context_free(a->context, firstOrderValues); - grib_context_free(a->context, X); + grib_context_free(context_, secondaryBitmap); + grib_context_free(context_, firstOrderValues); + grib_context_free(context_, X); return ret; } -int grib_accessor_class_data_g1second_order_constant_width_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len) +int grib_accessor_data_g1second_order_constant_width_packing_t::pack_double(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__); + const char* cclass_name = class_name_; + grib_context_log(context_, GRIB_LOG_ERROR, "%s: %s: Not implemented", cclass_name, __func__); return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_data_g1second_order_constant_width_packing_t::unpack_double_element(size_t idx, double* val) { - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); size_t size = 0; double* values = NULL; int err = 0; @@ -202,20 +198,20 @@ int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_dou if (idx > size) return GRIB_INVALID_ARGUMENT; - values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double)); + values = (double*)grib_context_malloc_clear(context_, size * sizeof(double)); err = grib_get_double_array(hand, "values", values, &size); if (err) { - grib_context_free(a->context, values); + grib_context_free(context_, values); return err; } *val = values[idx]; - grib_context_free(a->context, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } -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) +int grib_accessor_data_g1second_order_constant_width_packing_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) { - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); size_t size = 0, i = 0; double* values = NULL; int err = 0; @@ -229,15 +225,15 @@ int grib_accessor_class_data_g1second_order_constant_width_packing_t::unpack_dou if (index_array[i] > size) return GRIB_INVALID_ARGUMENT; } - values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double)); + values = (double*)grib_context_malloc_clear(context_, size * sizeof(double)); err = grib_get_double_array(hand, "values", values, &size); if (err) { - grib_context_free(a->context, values); + grib_context_free(context_, values); return err; } for (i = 0; i < len; i++) { val_array[i] = values[index_array[i]]; } - grib_context_free(a->context, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } diff --git a/src/accessor/grib_accessor_class_data_g1second_order_constant_width_packing.h b/src/accessor/grib_accessor_class_data_g1second_order_constant_width_packing.h index 8d2d53f0a..0d42e7c7f 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_constant_width_packing.h +++ b/src/accessor/grib_accessor_class_data_g1second_order_constant_width_packing.h @@ -15,35 +15,32 @@ 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_data_g1second_order_constant_width_packing_t() : + grib_accessor_data_simple_packing_t() { class_name_ = "data_g1second_order_constant_width_packing"; } 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; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_float(float* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + int unpack_double_element(size_t i, double* val) override; + int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; + +private: + 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_; }; diff --git a/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.cc b/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.cc index f78bb1806..8f14bf948 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.cc @@ -12,9 +12,8 @@ #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; - +grib_accessor_data_g1second_order_general_extended_packing_t _grib_accessor_data_g1second_order_general_extended_packing{}; +grib_accessor* grib_accessor_data_g1second_order_general_extended_packing = &_grib_accessor_data_g1second_order_general_extended_packing; #define MAX_NUMBER_OF_GROUPS 65534 #define EFDEBUG 0 @@ -49,54 +48,52 @@ long number_of_bits(grib_handle* h, unsigned long x) if (i >= count) { /*grib_dump_content(h, stdout,"debug", ~0, NULL);*/ grib_context_log(h->context, GRIB_LOG_FATAL, - "grib_accessor_class_data_g1second_order_general_extended_packing: Number out of range: %ld", x); + "grib_accessor_data_g1second_order_general_extended_packing: Number out of range: %ld", x); } } return i; } -void grib_accessor_class_data_g1second_order_general_extended_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_g1second_order_general_extended_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_simple_packing_t::init(a, v, 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); + grib_accessor_data_simple_packing_t::init(v, args); + grib_handle* handle = grib_handle_of_accessor(this); - self->half_byte = grib_arguments_get_name(handle, args, self->carg++); - self->packingType = grib_arguments_get_name(handle, args, self->carg++); - self->ieee_packing = grib_arguments_get_name(handle, args, self->carg++); - self->precision = grib_arguments_get_name(handle, args, self->carg++); - self->widthOfFirstOrderValues = grib_arguments_get_name(handle, args, self->carg++); - self->firstOrderValues = grib_arguments_get_name(handle, args, self->carg++); - self->N1 = grib_arguments_get_name(handle, args, self->carg++); - self->N2 = grib_arguments_get_name(handle, args, self->carg++); - self->numberOfGroups = grib_arguments_get_name(handle, args, self->carg++); - self->codedNumberOfGroups = grib_arguments_get_name(handle, args, self->carg++); - self->numberOfSecondOrderPackedValues = grib_arguments_get_name(handle, args, self->carg++); - self->extraValues = grib_arguments_get_name(handle, args, self->carg++); - self->groupWidths = grib_arguments_get_name(handle, args, self->carg++); - self->widthOfWidths = grib_arguments_get_name(handle, args, self->carg++); - self->groupLengths = grib_arguments_get_name(handle, args, self->carg++); - self->widthOfLengths = grib_arguments_get_name(handle, args, self->carg++); - self->NL = grib_arguments_get_name(handle, args, self->carg++); - self->SPD = grib_arguments_get_name(handle, args, self->carg++); - self->widthOfSPD = grib_arguments_get_name(handle, args, self->carg++); - self->orderOfSPD = grib_arguments_get_name(handle, args, self->carg++); - self->numberOfPoints = grib_arguments_get_name(handle, args, self->carg++); - self->dataFlag = grib_arguments_get_name(handle, args, self->carg++); - self->edition = 1; - self->dirty = 1; - self->dvalues = NULL; - self->fvalues = NULL; - self->double_dirty = self->float_dirty = 1; - self->size = 0; - a->flags |= GRIB_ACCESSOR_FLAG_DATA; + half_byte_ = grib_arguments_get_name(handle, args, carg_++); + packingType_ = grib_arguments_get_name(handle, args, carg_++); + ieee_packing_ = grib_arguments_get_name(handle, args, carg_++); + precision_ = grib_arguments_get_name(handle, args, carg_++); + widthOfFirstOrderValues_ = grib_arguments_get_name(handle, args, carg_++); + firstOrderValues_ = grib_arguments_get_name(handle, args, carg_++); + N1_ = grib_arguments_get_name(handle, args, carg_++); + N2_ = grib_arguments_get_name(handle, args, carg_++); + numberOfGroups_ = grib_arguments_get_name(handle, args, carg_++); + codedNumberOfGroups_ = grib_arguments_get_name(handle, args, carg_++); + numberOfSecondOrderPackedValues_ = grib_arguments_get_name(handle, args, carg_++); + extraValues_ = grib_arguments_get_name(handle, args, carg_++); + groupWidths_ = grib_arguments_get_name(handle, args, carg_++); + widthOfWidths_ = grib_arguments_get_name(handle, args, carg_++); + groupLengths_ = grib_arguments_get_name(handle, args, carg_++); + widthOfLengths_ = grib_arguments_get_name(handle, args, carg_++); + NL_ = grib_arguments_get_name(handle, args, carg_++); + SPD_ = grib_arguments_get_name(handle, args, carg_++); + widthOfSPD_ = grib_arguments_get_name(handle, args, carg_++); + orderOfSPD_ = grib_arguments_get_name(handle, args, carg_++); + numberOfPoints_ = grib_arguments_get_name(handle, args, carg_++); + dataFlag_ = grib_arguments_get_name(handle, args, carg_++); + edition_ = 1; + dirty_ = 1; + dvalues_ = NULL; + fvalues_ = NULL; + double_dirty_ = float_dirty_ = 1; + size_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_DATA; } -int grib_accessor_class_data_g1second_order_general_extended_packing_t::value_count(grib_accessor* a, long* count) +int grib_accessor_data_g1second_order_general_extended_packing_t::value_count(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; + long numberOfCodedValues = 0; + long numberOfGroups = 0; size_t ngroups; long* groupLengths; long orderOfSPD = 0; @@ -105,62 +102,62 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::value_co *count = 0; - err = grib_get_long(grib_handle_of_accessor(a), self->numberOfGroups, &numberOfGroups); + err = grib_get_long(grib_handle_of_accessor(this), numberOfGroups_, &numberOfGroups); if (err) return err; if (numberOfGroups == 0) return 0; - groupLengths = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfGroups); + groupLengths = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups); ngroups = numberOfGroups; - err = grib_get_long_array(grib_handle_of_accessor(a), self->groupLengths, groupLengths, &ngroups); + err = grib_get_long_array(grib_handle_of_accessor(this), groupLengths_, groupLengths, &ngroups); if (err) return err; for (i = 0; i < numberOfGroups; i++) numberOfCodedValues += groupLengths[i]; - grib_context_free(a->context, groupLengths); + grib_context_free(context_, groupLengths); - err = grib_get_long(grib_handle_of_accessor(a), self->orderOfSPD, &orderOfSPD); + err = grib_get_long(grib_handle_of_accessor(this), orderOfSPD_, &orderOfSPD); *count = numberOfCodedValues + orderOfSPD; return err; } -int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_data_g1second_order_general_extended_packing_t::unpack_double_element(size_t idx, double* val) { size_t size; double* values; int err = 0; /* GRIB-564: The index idx relates to codedValues NOT values! */ - err = grib_get_size(grib_handle_of_accessor(a), "codedValues", &size); + err = grib_get_size(grib_handle_of_accessor(this), "codedValues", &size); if (err) return err; if (idx >= size) return GRIB_INVALID_ARGUMENT; - values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double)); - err = grib_get_double_array(grib_handle_of_accessor(a), "codedValues", values, &size); + values = (double*)grib_context_malloc_clear(context_, size * sizeof(double)); + err = grib_get_double_array(grib_handle_of_accessor(this), "codedValues", values, &size); if (err) { - grib_context_free(a->context, values); + grib_context_free(context_, values); return err; } *val = values[idx]; - grib_context_free(a->context, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } -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) +int grib_accessor_data_g1second_order_general_extended_packing_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) { size_t size = 0, i = 0; double* values; int err = 0; /* GRIB-564: The indexes in index_array relate to codedValues NOT values! */ - err = grib_get_size(grib_handle_of_accessor(a), "codedValues", &size); + err = grib_get_size(grib_handle_of_accessor(this), "codedValues", &size); if (err) return err; @@ -168,28 +165,27 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_d if (index_array[i] > size) return GRIB_INVALID_ARGUMENT; } - values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double)); - err = grib_get_double_array(grib_handle_of_accessor(a), "codedValues", values, &size); + values = (double*)grib_context_malloc_clear(context_, size * sizeof(double)); + err = grib_get_double_array(grib_handle_of_accessor(this), "codedValues", values, &size); if (err) { - grib_context_free(a->context, values); + grib_context_free(context_, values); return err; } for (i = 0; i < len; i++) { val_array[i] = values[index_array[i]]; } - grib_context_free(a->context, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } -int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack(grib_accessor* a, double* dvalues, float* fvalues, size_t* len) +int grib_accessor_data_g1second_order_general_extended_packing_t::unpack(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; + int ret = 0; long numberOfGroups, numberOfSecondOrderPackedValues; long* firstOrderValues = 0; long* X = 0; long pos = 0; - grib_handle* handle = grib_handle_of_accessor(a); + grib_handle* handle = grib_handle_of_accessor(this); unsigned char* buf = (unsigned char*)handle->buffer->data; long i, n; double reference_value; @@ -207,33 +203,33 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack(g Assert(!(dvalues && fvalues)); if (dvalues) { - if (!self->double_dirty) { - if (*len < self->size) { + if (!double_dirty_) { + if (*len < size_) { return GRIB_ARRAY_TOO_SMALL; } - for (k = 0; k < self->size; k++) - dvalues[k] = self->dvalues[k]; - *len = self->size; + for (k = 0; k < size_; k++) + dvalues[k] = dvalues_[k]; + *len = size_; return GRIB_SUCCESS; } - self->double_dirty = 0; + double_dirty_ = 0; } if (fvalues) { - if (!self->float_dirty) { - if (*len < self->size) { + if (!float_dirty_) { + if (*len < size_) { return GRIB_ARRAY_TOO_SMALL; } - for (k = 0; k < self->size; k++) - fvalues[k] = self->fvalues[k]; - *len = self->size; + for (k = 0; k < size_; k++) + fvalues[k] = fvalues_[k]; + *len = size_; return GRIB_SUCCESS; } - self->float_dirty = 0; + float_dirty_ = 0; } - buf += a->byte_offset(); - ret = a->value_count(&numberOfValues); + buf += byte_offset(); + ret = value_count(&numberOfValues); if (ret) return ret; @@ -241,51 +237,51 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack(g if (*len < (size_t)numberOfValues) return GRIB_ARRAY_TOO_SMALL; - if ((ret = grib_get_long_internal(handle, self->numberOfGroups, &numberOfGroups)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(handle, numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(handle, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(handle, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return ret; ngroups = numberOfGroups; - groupWidths = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfGroups); - ret = grib_get_long_array(handle, self->groupWidths, groupWidths, &ngroups); + groupWidths = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups); + ret = grib_get_long_array(handle, groupWidths_, groupWidths, &ngroups); if (ret != GRIB_SUCCESS) return ret; - groupLengths = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfGroups); - ret = grib_get_long_array(handle, self->groupLengths, groupLengths, &ngroups); + groupLengths = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups); + ret = grib_get_long_array(handle, groupLengths_, groupLengths, &ngroups); if (ret != GRIB_SUCCESS) return ret; - firstOrderValues = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfGroups); - ret = grib_get_long_array(handle, self->firstOrderValues, firstOrderValues, &ngroups); + firstOrderValues = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups); + ret = grib_get_long_array(handle, firstOrderValues_, firstOrderValues, &ngroups); if (ret != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(handle, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(handle, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(handle, self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(handle, reference_value_, &reference_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(handle, self->numberOfSecondOrderPackedValues, + if ((ret = grib_get_long_internal(handle, numberOfSecondOrderPackedValues_, &numberOfSecondOrderPackedValues)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(handle, self->orderOfSPD, &orderOfSPD)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(handle, orderOfSPD_, &orderOfSPD)) != GRIB_SUCCESS) return ret; if (orderOfSPD) { size_t nSPD = orderOfSPD + 1; - SPD = (long*)grib_context_malloc_clear(a->context, sizeof(long) * nSPD); - ret = grib_get_long_array(handle, self->SPD, SPD, &nSPD); + SPD = (long*)grib_context_malloc_clear(context_, sizeof(long) * nSPD); + ret = grib_get_long_array(handle, SPD_, SPD, &nSPD); bias = SPD[orderOfSPD]; if (ret != GRIB_SUCCESS) return ret; } - X = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfValues); + X = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfValues); n = orderOfSPD; for (i = 0; i < numberOfGroups; i++) { @@ -351,64 +347,64 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack(g } if (dvalues) { // double-precision - if (self->dvalues) { - if (numberOfValues != self->size) { - grib_context_free(a->context, self->dvalues); - self->dvalues = (double*)grib_context_malloc_clear(a->context, sizeof(double) * numberOfValues); + if (dvalues_) { + if (numberOfValues != size_) { + grib_context_free(context_, dvalues_); + dvalues_ = (double*)grib_context_malloc_clear(context_, sizeof(double) * numberOfValues); } } else { - self->dvalues = (double*)grib_context_malloc_clear(a->context, sizeof(double) * numberOfValues); + dvalues_ = (double*)grib_context_malloc_clear(context_, sizeof(double) * numberOfValues); } double s = codes_power(binary_scale_factor, 2); double d = codes_power(-decimal_scale_factor, 10); for (i = 0; i < numberOfValues; i++) { - dvalues[i] = (double)(((X[i] * s) + reference_value) * d); - self->dvalues[i] = dvalues[i]; + dvalues[i] = (double)(((X[i] * s) + reference_value) * d); + dvalues_[i] = dvalues[i]; } } else { // single-precision - if (self->fvalues) { - if (numberOfValues != self->size) { - grib_context_free(a->context, self->fvalues); - self->fvalues = (float*)grib_context_malloc_clear(a->context, sizeof(float) * numberOfValues); + if (fvalues_) { + if (numberOfValues != size_) { + grib_context_free(context_, fvalues_); + fvalues_ = (float*)grib_context_malloc_clear(context_, sizeof(float) * numberOfValues); } } else { - self->fvalues = (float*)grib_context_malloc_clear(a->context, sizeof(float) * numberOfValues); + fvalues_ = (float*)grib_context_malloc_clear(context_, sizeof(float) * numberOfValues); } float s = codes_power(binary_scale_factor, 2); float d = codes_power(-decimal_scale_factor, 10); for (i = 0; i < numberOfValues; i++) { - fvalues[i] = (float)(((X[i] * s) + reference_value) * d); - self->fvalues[i] = fvalues[i]; + fvalues[i] = (float)(((X[i] * s) + reference_value) * d); + fvalues_[i] = fvalues[i]; } } - *len = numberOfValues; - self->size = numberOfValues; + *len = numberOfValues; + size_ = numberOfValues; - grib_context_free(a->context, X); - grib_context_free(a->context, groupWidths); - grib_context_free(a->context, groupLengths); - grib_context_free(a->context, firstOrderValues); + grib_context_free(context_, X); + grib_context_free(context_, groupWidths); + grib_context_free(context_, groupLengths); + grib_context_free(context_, firstOrderValues); if (orderOfSPD) - grib_context_free(a->context, SPD); + grib_context_free(context_, SPD); return ret; } -int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_float(grib_accessor* a, float* values, size_t* len) +int grib_accessor_data_g1second_order_general_extended_packing_t::unpack_float(float* values, size_t* len) { - return unpack(a, NULL, values, len); + return unpack(NULL, values, len); } -int grib_accessor_class_data_g1second_order_general_extended_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len) +int grib_accessor_data_g1second_order_general_extended_packing_t::unpack_double(double* values, size_t* len) { - return unpack(a, values, NULL, len); + return unpack(values, NULL, len); } static void grib_split_long_groups(grib_handle* hand, grib_context* c, long* numberOfGroups, long* lengthOfSecondOrderValues, @@ -543,13 +539,12 @@ 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 +// src/deprecated/grib_accessor_data_g1second_order_general_extended_packing.pack_double.cc // See ECC-441 and ECC-261 -int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_g1second_order_general_extended_packing_t::pack_double(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; + int ret = 0; + int grib2 = 0; long bits_per_value, orderOfSPD, binary_scale_factor; long numberOfValues; double max, min; @@ -587,10 +582,10 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou int computeGroupA = 1; long dataHeadersLength, widthsLength, lengthsLength, firstOrderValuesLength; long decimal_scale_factor; - grib_handle* handle = grib_handle_of_accessor(a); + grib_handle* handle = grib_handle_of_accessor(this); long optimize_scaling_factor = 0; - self->double_dirty = 1; + double_dirty_ = 1; numberOfValues = *len; @@ -603,16 +598,16 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou } /* ECC-1219: packingType conversion from grid_ieee to grid_second_order */ - if ((ret = get_bits_per_value(handle, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((ret = get_bits_per_value(handle, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(handle, self->optimize_scaling_factor, &optimize_scaling_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(handle, optimize_scaling_factor_, &optimize_scaling_factor)) != GRIB_SUCCESS) return ret; if (optimize_scaling_factor) { - const int compat_gribex = handle->context->gribex_mode_on && self->edition == 1; + const int compat_gribex = handle->context->gribex_mode_on && edition_ == 1; const int compat_32bit = 1; - if ((ret = grib_optimize_decimal_factor(a, self->reference_value, + if ((ret = grib_optimize_decimal_factor(this, reference_value_, max, min, bits_per_value, compat_gribex, compat_32bit, &decimal_scale_factor, &binary_scale_factor, &reference_value)) != GRIB_SUCCESS) @@ -623,26 +618,26 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou /*min = min * decimal;*/ /*max = max * decimal;*/ - if ((ret = grib_set_long_internal(handle, self->decimal_scale_factor, decimal_scale_factor)) != + if ((ret = grib_set_long_internal(handle, decimal_scale_factor_, decimal_scale_factor)) != GRIB_SUCCESS) return ret; } else { /* For constant fields set decimal scale factor to 0 (See GRIB-165) */ if (min == max) { - grib_set_long_internal(handle, self->decimal_scale_factor, 0); + grib_set_long_internal(handle, decimal_scale_factor_, 0); } - if ((ret = grib_get_long_internal(handle, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(handle, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; decimal = codes_power(decimal_scale_factor, 10); min = min * decimal; max = max * decimal; - if (grib_get_nearest_smaller_value(handle, self->reference_value, min, &reference_value) != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Unable to find nearest_smaller_value of %g for %s", min, self->reference_value); + if (grib_get_nearest_smaller_value(handle, reference_value_, min, &reference_value) != GRIB_SUCCESS) { + grib_context_log(context_, GRIB_LOG_ERROR, + "Unable to find nearest_smaller_value of %g for %s", min, reference_value_); return GRIB_INTERNAL_ERROR; } binary_scale_factor = grib_get_binary_scale_fact(max, reference_value, bits_per_value, &ret); @@ -650,31 +645,31 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou divisor = codes_power(-binary_scale_factor, 2); } - if ((ret = grib_set_long_internal(handle, self->binary_scale_factor, binary_scale_factor)) != + if ((ret = grib_set_long_internal(handle, binary_scale_factor_, binary_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_double_internal(handle, self->reference_value, reference_value)) != + if ((ret = grib_set_double_internal(handle, reference_value_, reference_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(handle, self->offsetdata, &offsetBeforeData)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(handle, offsetdata_, &offsetBeforeData)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(handle, self->offsetsection, &offsetSection4)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(handle, offsetsection_, &offsetSection4)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(handle, self->orderOfSPD, &orderOfSPD)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(handle, orderOfSPD_, &orderOfSPD)) != GRIB_SUCCESS) return ret; - X = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfValues); + X = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfValues); for (i = 0; i < numberOfValues; i++) { X[i] = (((val[i] * decimal) - reference_value) * divisor) + 0.5; } - groupLengths = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfValues); - groupWidths = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfValues); - firstOrderValues = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfValues); + groupLengths = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfValues); + groupWidths = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfValues); + firstOrderValues = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfValues); /* spatial differencing */ switch (orderOfSPD) { @@ -951,7 +946,7 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou Focus on groups which have been shrank as left groups of an A group taking some of their elements. */ - offsets = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfGroups); + offsets = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups); offsets[0] = orderOfSPD; for (i = 1; i < numberOfGroups; i++) offsets[i] = offsets[i - 1] + groupLengths[i - 1]; @@ -1013,7 +1008,7 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou } } } - grib_context_free(a->context, offsets); + grib_context_free(context_, offsets); } maxWidth = groupWidths[0]; @@ -1026,7 +1021,7 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou } if (maxWidth < 0 || maxLength < 0) { - grib_context_log(a->parent->h->context, GRIB_LOG_ERROR, "Cannot compute parameters for second order packing."); + grib_context_log(parent_->h->context, GRIB_LOG_ERROR, "Cannot compute parameters for second order packing."); return GRIB_ENCODING_ERROR; } widthOfWidths = number_of_bits(handle, maxWidth); @@ -1037,8 +1032,8 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou lengthOfSecondOrderValues += groupLengths[i] * groupWidths[i]; } - if (!a->context->no_big_group_split) { - grib_split_long_groups(handle, a->context, &numberOfGroups, &lengthOfSecondOrderValues, + if (!context_->no_big_group_split) { + grib_split_long_groups(handle, context_, &numberOfGroups, &lengthOfSecondOrderValues, groupLengths, &widthOfLengths, groupWidths, widthOfWidths, firstOrderValues, widthOfFirstOrderValues); } @@ -1054,12 +1049,12 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou /* writing SPD */ if (orderOfSPD) { - if ((ret = grib_set_long_internal(handle, self->widthOfSPD, widthOfSPD)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(handle, widthOfSPD_, widthOfSPD)) != GRIB_SUCCESS) return ret; } /* end writing SPD */ - if ((ret = grib_set_long_internal(handle, self->widthOfFirstOrderValues, widthOfFirstOrderValues)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(handle, widthOfFirstOrderValues_, widthOfFirstOrderValues)) != GRIB_SUCCESS) return ret; dataHeadersLength = 25; @@ -1077,9 +1072,9 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou N2 = N2 > 65535 ? 65535 : N2; N1 = N1 > 65535 ? 65535 : N1; - grib_set_long(handle, self->NL, NL); - grib_set_long(handle, self->N1, N1); - grib_set_long(handle, self->N2, N2); + grib_set_long(handle, NL_, NL); + grib_set_long(handle, N1_, N1); + grib_set_long(handle, N2_, N2); if (numberOfGroups > 65535) { extraValues = numberOfGroups / 65536; @@ -1092,34 +1087,34 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou /* if no extraValues key present it is a GRIB2*/ grib2 = 0; - if ((ret = grib_set_long(handle, self->extraValues, extraValues)) != GRIB_SUCCESS) { + if ((ret = grib_set_long(handle, extraValues_, extraValues)) != GRIB_SUCCESS) { codedNumberOfGroups = numberOfGroups; grib2 = 1; } - if ((ret = grib_set_long_internal(handle, self->codedNumberOfGroups, codedNumberOfGroups)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(handle, codedNumberOfGroups_, codedNumberOfGroups)) != GRIB_SUCCESS) return ret; numberOfSecondOrderPackedValues = numberOfValues - orderOfSPD; if (!grib2 && numberOfSecondOrderPackedValues > 65535) numberOfSecondOrderPackedValues = 65535; - if ((ret = grib_set_long_internal(handle, self->numberOfSecondOrderPackedValues, numberOfSecondOrderPackedValues)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(handle, numberOfSecondOrderPackedValues_, numberOfSecondOrderPackedValues)) != GRIB_SUCCESS) return ret; if (grib2) { - if ((ret = grib_set_long_internal(handle, self->bits_per_value, bits_per_value)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(handle, bits_per_value_, bits_per_value)) != GRIB_SUCCESS) return ret; } else { - if ((ret = grib_set_long_internal(handle, self->bits_per_value, 0)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(handle, bits_per_value_, 0)) != GRIB_SUCCESS) return ret; } - if ((ret = grib_set_long_internal(handle, self->widthOfWidths, widthOfWidths)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(handle, widthOfWidths_, widthOfWidths)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(handle, self->widthOfLengths, widthOfLengths)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(handle, widthOfLengths_, widthOfLengths)) != GRIB_SUCCESS) return ret; lengthOfSecondOrderValues = 0; @@ -1133,10 +1128,10 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou /* padding section 4 to an even number of octets */ size = ((size + offsetBeforeData - offsetSection4) % 2) ? size + 1 : size; half_byte = 8 * size - sizebits; - if ((ret = grib_set_long_internal(handle, self->half_byte, half_byte)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(handle, half_byte_, half_byte)) != GRIB_SUCCESS) return ret; - buffer = (unsigned char*)grib_context_malloc_clear(a->context, size); + buffer = (unsigned char*)grib_context_malloc_clear(context_, size); pos = 0; if (orderOfSPD) { @@ -1148,20 +1143,20 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou for (i = 0; i < orderOfSPD; i++) SPD[i] = X[i]; SPD[orderOfSPD] = bias; - ret = grib_set_long_array_internal(handle, self->SPD, SPD, nSPD); + ret = grib_set_long_array_internal(handle, SPD_, SPD, nSPD); if (ret) return ret; } - ret = grib_set_long_array_internal(handle, self->groupWidths, groupWidths, (size_t)numberOfGroups); + ret = grib_set_long_array_internal(handle, groupWidths_, groupWidths, (size_t)numberOfGroups); if (ret) return ret; - ret = grib_set_long_array_internal(handle, self->groupLengths, groupLengths, (size_t)numberOfGroups); + ret = grib_set_long_array_internal(handle, groupLengths_, groupLengths, (size_t)numberOfGroups); if (ret) return ret; - ret = grib_set_long_array_internal(handle, self->firstOrderValues, firstOrderValues, (size_t)numberOfGroups); + ret = grib_set_long_array_internal(handle, firstOrderValues_, firstOrderValues, (size_t)numberOfGroups); if (ret) return ret; @@ -1189,31 +1184,30 @@ int grib_accessor_class_data_g1second_order_general_extended_packing_t::pack_dou } /* ECC-259: Set correct number of values */ - ret = grib_set_long_internal(a->parent->h, self->number_of_values, *len); + ret = grib_set_long_internal(parent_->h, number_of_values_, *len); if (ret) return ret; - ret = grib_buffer_replace(a, buffer, size, 1, 1); + ret = grib_buffer_replace(this, buffer, size, 1, 1); if (ret) return ret; - grib_context_free(a->context, buffer); - grib_context_free(a->context, X); - grib_context_free(a->context, groupLengths); - grib_context_free(a->context, groupWidths); - grib_context_free(a->context, firstOrderValues); + grib_context_free(context_, buffer); + grib_context_free(context_, X); + grib_context_free(context_, groupLengths); + grib_context_free(context_, groupWidths); + grib_context_free(context_, firstOrderValues); return GRIB_SUCCESS; } -void grib_accessor_class_data_g1second_order_general_extended_packing_t::destroy(grib_context* context, grib_accessor* a) +void grib_accessor_data_g1second_order_general_extended_packing_t::destroy(grib_context* context) { - 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; + if (dvalues_ != NULL) { + grib_context_free(context, dvalues_); + dvalues_ = NULL; } - if (self->fvalues != NULL) { - grib_context_free(context, self->fvalues); - self->fvalues = NULL; + if (fvalues_ != NULL) { + grib_context_free(context, fvalues_); + fvalues_ = NULL; } - grib_accessor_class_data_simple_packing_t::destroy(context, a); + grib_accessor_data_simple_packing_t::destroy(context); } diff --git a/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.h b/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.h index 4bb50ae34..e278080f2 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.h +++ b/src/accessor/grib_accessor_class_data_g1second_order_general_extended_packing.h @@ -15,50 +15,47 @@ 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_data_g1second_order_general_extended_packing_t() : + grib_accessor_data_simple_packing_t() { class_name_ = "data_g1second_order_general_extended_packing"; } 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; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_float(float* val, size_t* len) override; + int value_count(long*) override; + void destroy(grib_context*) override; + void init(const long, grib_arguments*) override; + int unpack_double_element(size_t i, double* val) override; + int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; private: - int unpack(grib_accessor* a, double*, float*, size_t*); + int unpack(double*, float*, size_t*); + +private: + 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_; }; diff --git a/src/accessor/grib_accessor_class_data_g1second_order_general_packing.cc b/src/accessor/grib_accessor_class_data_g1second_order_general_packing.cc index 3ee5f6a4f..400381670 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_general_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1second_order_general_packing.cc @@ -10,42 +10,39 @@ #include "grib_accessor_class_data_g1second_order_general_packing.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; +grib_accessor_data_g1second_order_general_packing_t _grib_accessor_data_g1second_order_general_packing{}; +grib_accessor* grib_accessor_data_g1second_order_general_packing = &_grib_accessor_data_g1second_order_general_packing; - -void grib_accessor_class_data_g1second_order_general_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_g1second_order_general_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_simple_packing_t::init(a, v, 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); + grib_accessor_data_simple_packing_t::init(v, args); + grib_handle* hand = grib_handle_of_accessor(this); - self->half_byte = grib_arguments_get_name(hand, args, self->carg++); - self->packingType = grib_arguments_get_name(hand, args, self->carg++); - self->ieee_packing = grib_arguments_get_name(hand, args, self->carg++); - self->precision = grib_arguments_get_name(hand, args, self->carg++); - self->widthOfFirstOrderValues = grib_arguments_get_name(hand, args, self->carg++); - self->N1 = grib_arguments_get_name(hand, args, self->carg++); - self->N2 = grib_arguments_get_name(hand, args, self->carg++); - self->numberOfGroups = grib_arguments_get_name(hand, args, self->carg++); - self->numberOfSecondOrderPackedValues = grib_arguments_get_name(hand, args, self->carg++); - self->extraValues = grib_arguments_get_name(hand, args, self->carg++); - self->Ni = grib_arguments_get_name(hand, args, self->carg++); - self->Nj = grib_arguments_get_name(hand, args, self->carg++); - self->pl = grib_arguments_get_name(hand, args, self->carg++); - self->jPointsAreConsecutive = grib_arguments_get_name(hand, args, self->carg++); - self->bitmap = grib_arguments_get_name(hand, args, self->carg++); - self->groupWidths = grib_arguments_get_name(hand, args, self->carg++); - self->edition = 1; - a->flags |= GRIB_ACCESSOR_FLAG_DATA; + half_byte_ = grib_arguments_get_name(hand, args, carg_++); + packingType_ = grib_arguments_get_name(hand, args, carg_++); + ieee_packing_ = grib_arguments_get_name(hand, args, carg_++); + precision_ = grib_arguments_get_name(hand, args, carg_++); + widthOfFirstOrderValues_ = grib_arguments_get_name(hand, args, carg_++); + N1_ = grib_arguments_get_name(hand, args, carg_++); + N2_ = grib_arguments_get_name(hand, args, carg_++); + numberOfGroups_ = grib_arguments_get_name(hand, args, carg_++); + numberOfSecondOrderPackedValues_ = grib_arguments_get_name(hand, args, carg_++); + extraValues_ = grib_arguments_get_name(hand, args, carg_++); + Ni_ = grib_arguments_get_name(hand, args, carg_++); + Nj_ = grib_arguments_get_name(hand, args, carg_++); + pl_ = grib_arguments_get_name(hand, args, carg_++); + jPointsAreConsecutive_ = grib_arguments_get_name(hand, args, carg_++); + bitmap_ = grib_arguments_get_name(hand, args, carg_++); + groupWidths_ = grib_arguments_get_name(hand, args, carg_++); + edition_ = 1; + flags_ |= GRIB_ACCESSOR_FLAG_DATA; } -int grib_accessor_class_data_g1second_order_general_packing_t::value_count(grib_accessor* a, long* numberOfSecondOrderPackedValues) +int grib_accessor_data_g1second_order_general_packing_t::value_count(long* numberOfSecondOrderPackedValues) { - grib_accessor_data_g1second_order_general_packing_t* self = (grib_accessor_data_g1second_order_general_packing_t*)a; *numberOfSecondOrderPackedValues = 0; - int err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfSecondOrderPackedValues, numberOfSecondOrderPackedValues); + int err = grib_get_long_internal(grib_handle_of_accessor(this), numberOfSecondOrderPackedValues_, numberOfSecondOrderPackedValues); return err; } @@ -53,8 +50,8 @@ int grib_accessor_class_data_g1second_order_general_packing_t::value_count(grib_ template static int unpack_real(grib_accessor* a, T* values, size_t* len) { - static_assert(std::is_floating_point::value, "Requires floating point numbers"); grib_accessor_data_g1second_order_general_packing_t* self = (grib_accessor_data_g1second_order_general_packing_t*)a; + static_assert(std::is_floating_point::value, "Requires floating point numbers"); int ret = 0; long numberOfGroups, numberOfSecondOrderPackedValues; long* groupWidths = 0; @@ -73,43 +70,43 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) size_t groupWidthsSize; buf += a->byte_offset(); - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfGroups, &numberOfGroups)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->widthOfFirstOrderValues, &widthOfFirstOrderValues)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->widthOfFirstOrderValues_, &widthOfFirstOrderValues)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), self->reference_value_, &reference_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfSecondOrderPackedValues, + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfSecondOrderPackedValues_, &numberOfSecondOrderPackedValues)) != GRIB_SUCCESS) return ret; if (*len < (size_t)numberOfSecondOrderPackedValues) return GRIB_ARRAY_TOO_SMALL; - groupWidths = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfGroups); + groupWidths = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfGroups); groupWidthsSize = numberOfGroups; - if ((ret = grib_get_long_array_internal(grib_handle_of_accessor(a), self->groupWidths, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS) + if ((ret = grib_get_long_array_internal(grib_handle_of_accessor(a), self->groupWidths_, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS) return ret; - secondaryBitmap = (long*)grib_context_malloc_clear(a->context, sizeof(long) * (numberOfSecondOrderPackedValues + 1)); + secondaryBitmap = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * (numberOfSecondOrderPackedValues + 1)); secondaryBitmap[numberOfSecondOrderPackedValues] = 1; grib_decode_long_array(buf, &pos, 1, numberOfSecondOrderPackedValues, secondaryBitmap); pos = 8 * ((pos + 7) / 8); - firstOrderValues = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfGroups); + firstOrderValues = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfGroups); grib_decode_long_array(buf, &pos, widthOfFirstOrderValues, numberOfGroups, firstOrderValues); pos = 8 * ((pos + 7) / 8); - X = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfSecondOrderPackedValues); + X = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfSecondOrderPackedValues); n = 0; i = -1; @@ -146,30 +143,30 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) } *len = numberOfSecondOrderPackedValues; - grib_context_free(a->context, secondaryBitmap); - grib_context_free(a->context, firstOrderValues); - grib_context_free(a->context, X); - grib_context_free(a->context, groupWidths); + grib_context_free(a->context_, secondaryBitmap); + grib_context_free(a->context_, firstOrderValues); + grib_context_free(a->context_, X); + grib_context_free(a->context_, groupWidths); return ret; } -int grib_accessor_class_data_g1second_order_general_packing_t::unpack_float(grib_accessor* a, float* values, size_t* len) +int grib_accessor_data_g1second_order_general_packing_t::unpack_float(float* values, size_t* len) { - return unpack_real(a, values, len); + return unpack_real(this, values, len); } -int grib_accessor_class_data_g1second_order_general_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len) +int grib_accessor_data_g1second_order_general_packing_t::unpack_double(double* values, size_t* len) { - return unpack_real(a, values, len); + return unpack_real(this, values, len); } -int grib_accessor_class_data_g1second_order_general_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len) +int grib_accessor_data_g1second_order_general_packing_t::pack_double(const double* cval, size_t* len) { /* return GRIB_NOT_IMPLEMENTED; */ char type[] = "grid_second_order"; size_t size = strlen(type); - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); int err = grib_set_string(hand, "packingType", type, &size); if (err) diff --git a/src/accessor/grib_accessor_class_data_g1second_order_general_packing.h b/src/accessor/grib_accessor_class_data_g1second_order_general_packing.h index 95295dae1..c04deaa2a 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_general_packing.h +++ b/src/accessor/grib_accessor_class_data_g1second_order_general_packing.h @@ -16,33 +16,30 @@ 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_data_g1second_order_general_packing_t() : + grib_accessor_data_simple_packing_t() { class_name_ = "data_g1second_order_general_packing"; } 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; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_float(float* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +public: + 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_; }; diff --git a/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc b/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc index 7697a3a69..652ad9e4b 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc @@ -10,58 +10,54 @@ #include "grib_accessor_class_data_g1second_order_row_by_row_packing.h" -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; +grib_accessor_data_g1second_order_row_by_row_packing_t _grib_accessor_data_g1second_order_row_by_row_packing{}; +grib_accessor* grib_accessor_data_g1second_order_row_by_row_packing = &_grib_accessor_data_g1second_order_row_by_row_packing; - -void grib_accessor_class_data_g1second_order_row_by_row_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_g1second_order_row_by_row_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_simple_packing_t::init(a, v, 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); + grib_accessor_data_simple_packing_t::init(v, args); + grib_handle* gh = grib_handle_of_accessor(this); - self->half_byte = grib_arguments_get_name(gh, args, self->carg++); - self->packingType = grib_arguments_get_name(gh, args, self->carg++); - self->ieee_packing = grib_arguments_get_name(gh, args, self->carg++); - self->precision = grib_arguments_get_name(gh, args, self->carg++); - self->widthOfFirstOrderValues = grib_arguments_get_name(gh, args, self->carg++); - self->N1 = grib_arguments_get_name(gh, args, self->carg++); - self->N2 = grib_arguments_get_name(gh, args, self->carg++); - self->numberOfGroups = grib_arguments_get_name(gh, args, self->carg++); - self->numberOfSecondOrderPackedValues = grib_arguments_get_name(gh, args, self->carg++); - self->extraValues = grib_arguments_get_name(gh, args, self->carg++); - self->Ni = grib_arguments_get_name(gh, args, self->carg++); - self->Nj = grib_arguments_get_name(gh, args, self->carg++); - self->pl = grib_arguments_get_name(gh, args, self->carg++); - self->jPointsAreConsecutive = grib_arguments_get_name(gh, args, self->carg++); - self->groupWidths = grib_arguments_get_name(gh, args, self->carg++); - self->bitmap = grib_arguments_get_name(gh, args, self->carg++); - self->edition = 1; - a->flags |= GRIB_ACCESSOR_FLAG_DATA; + half_byte_ = grib_arguments_get_name(gh, args, carg_++); + packingType_ = grib_arguments_get_name(gh, args, carg_++); + ieee_packing_ = grib_arguments_get_name(gh, args, carg_++); + precision_ = grib_arguments_get_name(gh, args, carg_++); + widthOfFirstOrderValues_ = grib_arguments_get_name(gh, args, carg_++); + N1_ = grib_arguments_get_name(gh, args, carg_++); + N2_ = grib_arguments_get_name(gh, args, carg_++); + numberOfGroups_ = grib_arguments_get_name(gh, args, carg_++); + numberOfSecondOrderPackedValues_ = grib_arguments_get_name(gh, args, carg_++); + extraValues_ = grib_arguments_get_name(gh, args, carg_++); + Ni_ = grib_arguments_get_name(gh, args, carg_++); + Nj_ = grib_arguments_get_name(gh, args, carg_++); + pl_ = grib_arguments_get_name(gh, args, carg_++); + jPointsAreConsecutive_ = grib_arguments_get_name(gh, args, carg_++); + groupWidths_ = grib_arguments_get_name(gh, args, carg_++); + bitmap_ = grib_arguments_get_name(gh, args, carg_++); + edition_ = 1; + flags_ |= GRIB_ACCESSOR_FLAG_DATA; } -int grib_accessor_class_data_g1second_order_row_by_row_packing_t::value_count(grib_accessor* a, long* count) +int grib_accessor_data_g1second_order_row_by_row_packing_t::value_count(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); + grib_handle* gh = grib_handle_of_accessor(this); long n = 0, i = 0; - long numberOfRows = 0; + long numberOfRows = 0; long jPointsAreConsecutive = 0; long Ni = 0, Nj = 0; int bitmapPresent = 0; size_t plSize = 0; long* pl = 0; int ret = 0; - grib_context* c = a->context; + grib_context* c = context_; - if (self->bitmap) + if (bitmap_) bitmapPresent = 1; - if ((ret = grib_get_long_internal(gh, self->jPointsAreConsecutive, &jPointsAreConsecutive)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, jPointsAreConsecutive_, &jPointsAreConsecutive)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->Ni, &Ni)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, Ni_, &Ni)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->Nj, &Nj)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, Nj_, &Nj)) != GRIB_SUCCESS) return ret; if (jPointsAreConsecutive) { numberOfRows = Ni; @@ -71,10 +67,10 @@ int grib_accessor_class_data_g1second_order_row_by_row_packing_t::value_count(gr } plSize = 0; - ret = grib_get_size(gh, self->pl, &plSize); + ret = grib_get_size(gh, pl_, &plSize); if (ret == GRIB_SUCCESS) { - pl = (long*)grib_context_malloc_clear(a->context, sizeof(long) * plSize); - if ((ret = grib_get_long_array(gh, self->pl, pl, &plSize)) != GRIB_SUCCESS) + pl = (long*)grib_context_malloc_clear(context_, sizeof(long) * plSize); + if ((ret = grib_get_long_array(gh, pl_, pl, &plSize)) != GRIB_SUCCESS) return ret; } ret = 0; @@ -92,13 +88,13 @@ int grib_accessor_class_data_g1second_order_row_by_row_packing_t::value_count(gr else { numberOfPoints = Ni * Nj; } - bitmap = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfPoints); + bitmap = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfPoints); pbitmap = bitmap; - grib_get_long_array(gh, self->bitmap, bitmap, &numberOfPoints); + grib_get_long_array(gh, bitmap_, bitmap, &numberOfPoints); for (i = 0; i < numberOfPoints; i++) n += *(bitmap++); - grib_context_free(a->context, pbitmap); + grib_context_free(context_, pbitmap); } else { if (plSize) { @@ -120,9 +116,8 @@ template static int unpack_real(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; + grib_handle* gh = grib_handle_of_accessor(a); + int ret = 0; long numberOfGroups, numberOfSecondOrderPackedValues; long* groupWidths = 0; long* firstOrderValues = 0; @@ -144,24 +139,24 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) long* pl = 0; buf += a->byte_offset(); - if ((ret = grib_get_long_internal(gh, self->numberOfGroups, &numberOfGroups)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->jPointsAreConsecutive, &jPointsAreConsecutive)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->jPointsAreConsecutive_, &jPointsAreConsecutive)) != GRIB_SUCCESS) return ret; - if (self->bitmap) + if (self->bitmap_) bitmapPresent = 1; - ret = grib_get_size(gh, self->pl, &plSize); + ret = grib_get_size(gh, self->pl_, &plSize); if (ret == GRIB_SUCCESS) { - pl = (long*)grib_context_malloc_clear(a->context, sizeof(long) * plSize); - if ((ret = grib_get_long_array(gh, self->pl, pl, &plSize)) != GRIB_SUCCESS) + pl = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * plSize); + if ((ret = grib_get_long_array(gh, self->pl_, pl, &plSize)) != GRIB_SUCCESS) return ret; } - if ((ret = grib_get_long_internal(gh, self->Ni, &Ni)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->Ni_, &Ni)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->Nj, &Nj)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->Nj_, &Nj)) != GRIB_SUCCESS) return ret; if (jPointsAreConsecutive) { numberOfRows = Ni; @@ -172,7 +167,7 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) numberOfColumns = Ni; } - numbersPerRow = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfRows); + numbersPerRow = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfRows); if (!numbersPerRow) return GRIB_OUT_OF_MEMORY; if (bitmapPresent) { @@ -184,9 +179,9 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) for (i = 0; i < numberOfRows; i++) numberOfPoints += pl[i]; } - bitmap = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfPoints); + bitmap = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfPoints); pbitmap = bitmap; - grib_get_long_array(gh, self->bitmap, bitmap, &numberOfPoints); + grib_get_long_array(gh, self->bitmap_, bitmap, &numberOfPoints); if (plSize && pl) { for (i = 0; i < numberOfRows; i++) { for (j = 0; j < pl[i]; j++) { @@ -203,7 +198,7 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) } } - grib_context_free(a->context, pbitmap); + grib_context_free(a->context_, pbitmap); } else { if (plSize && pl) { @@ -216,28 +211,28 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) } } - if ((ret = grib_get_long_internal(gh, self->widthOfFirstOrderValues, &widthOfFirstOrderValues)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->widthOfFirstOrderValues_, &widthOfFirstOrderValues)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(gh, self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(gh, self->reference_value_, &reference_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->numberOfSecondOrderPackedValues, + if ((ret = grib_get_long_internal(gh, self->numberOfSecondOrderPackedValues_, &numberOfSecondOrderPackedValues)) != GRIB_SUCCESS) return ret; - groupWidths = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfGroups); + groupWidths = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfGroups); groupWidthsSize = numberOfGroups; - if ((ret = grib_get_long_array_internal(gh, self->groupWidths, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS) + if ((ret = grib_get_long_array_internal(gh, self->groupWidths_, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS) return ret; - firstOrderValues = (long*)grib_context_malloc_clear(a->context, sizeof(long) * numberOfGroups); + firstOrderValues = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfGroups); grib_decode_long_array(buf, &pos, widthOfFirstOrderValues, numberOfGroups, firstOrderValues); pos = 8 * ((pos + 7) / 8); @@ -248,7 +243,7 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) if (*len < (size_t)n) return GRIB_ARRAY_TOO_SMALL; - X = (long*)grib_context_malloc_clear(a->context, sizeof(long) * n); + X = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * n); n = 0; k = 0; for (i = 0; i < numberOfGroups; i++) { @@ -273,31 +268,31 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) for (i = 0; i < n; i++) { values[i] = (T)(((X[i] * s) + reference_value) * d); } - grib_context_free(a->context, firstOrderValues); - grib_context_free(a->context, X); - grib_context_free(a->context, groupWidths); + grib_context_free(a->context_, firstOrderValues); + grib_context_free(a->context_, X); + grib_context_free(a->context_, groupWidths); if (plSize) - grib_context_free(a->context, pl); + grib_context_free(a->context_, pl); if (numbersPerRow) - grib_context_free(a->context, numbersPerRow); + grib_context_free(a->context_, numbersPerRow); return ret; } -int grib_accessor_class_data_g1second_order_row_by_row_packing_t::unpack_float(grib_accessor* a, float* values, size_t* len) +int grib_accessor_data_g1second_order_row_by_row_packing_t::unpack_float(float* values, size_t* len) { - return unpack_real(a, values, len); + return unpack_real(this, values, len); } -int grib_accessor_class_data_g1second_order_row_by_row_packing_t::unpack_double(grib_accessor* a, double* values, size_t* len) +int grib_accessor_data_g1second_order_row_by_row_packing_t::unpack_double(double* values, size_t* len) { - return unpack_real(a, values, len); + return unpack_real(this, values, 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 grib_accessor_data_g1second_order_row_by_row_packing_t::pack_double(const double* cval, size_t* len) { int err = 0; - grib_handle* gh = grib_handle_of_accessor(a); + grib_handle* gh = grib_handle_of_accessor(this); char type[] = "grid_second_order"; size_t size = strlen(type); diff --git a/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.h b/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.h index eca551669..af224ab56 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.h +++ b/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.h @@ -16,33 +16,30 @@ 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_data_g1second_order_row_by_row_packing_t() : + grib_accessor_data_simple_packing_t() { class_name_ = "data_g1second_order_row_by_row_packing"; } 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; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_float(float* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +public: + 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_; }; diff --git a/src/accessor/grib_accessor_class_data_g1secondary_bitmap.cc b/src/accessor/grib_accessor_class_data_g1secondary_bitmap.cc index 7b80a1891..289c403ca 100644 --- a/src/accessor/grib_accessor_class_data_g1secondary_bitmap.cc +++ b/src/accessor/grib_accessor_class_data_g1secondary_bitmap.cc @@ -10,30 +10,27 @@ #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; +grib_accessor_data_g1secondary_bitmap_t _grib_accessor_data_g1secondary_bitmap{}; +grib_accessor* grib_accessor_data_g1secondary_bitmap = &_grib_accessor_data_g1secondary_bitmap; - -void grib_accessor_class_data_g1secondary_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_g1secondary_bitmap_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_secondary_bitmap_t::init(a, v, 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); + grib_accessor_data_secondary_bitmap_t::init(v, args); + number_of_ones_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, 4); } -int grib_accessor_class_data_g1secondary_bitmap_t::value_count(grib_accessor* a, long* count) +int grib_accessor_data_g1secondary_bitmap_t::value_count(long* count) { - grib_accessor_data_g1secondary_bitmap_t* self = (grib_accessor_data_g1secondary_bitmap_t*)a; size_t len = 0; - int err = 0; + int err = 0; long expand_by; *count = 0; - err = grib_get_long_internal(grib_handle_of_accessor(a), self->expand_by, &expand_by); + err = grib_get_long_internal(grib_handle_of_accessor(this), expand_by_, &expand_by); if (err) return err; - err = grib_get_size(grib_handle_of_accessor(a), self->primary_bitmap, &len); + err = grib_get_size(grib_handle_of_accessor(this), primary_bitmap_, &len); if (err) return err; @@ -41,10 +38,8 @@ int grib_accessor_class_data_g1secondary_bitmap_t::value_count(grib_accessor* a, return GRIB_SUCCESS; } -int grib_accessor_class_data_g1secondary_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_g1secondary_bitmap_t::pack_double(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; @@ -62,12 +57,12 @@ int grib_accessor_class_data_g1secondary_bitmap_t::pack_double(grib_accessor* a, if (*len == 0) return GRIB_NO_VALUES; - if ((err = grib_get_long(grib_handle_of_accessor(a), self->expand_by, &expand_by)) != GRIB_SUCCESS) + if ((err = grib_get_long(grib_handle_of_accessor(this), 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) + if ((err = grib_get_double_internal(grib_handle_of_accessor(this), missing_value_, &missing_value)) != GRIB_SUCCESS) return err; if (*len % expand_by) { @@ -76,14 +71,14 @@ int grib_accessor_class_data_g1secondary_bitmap_t::pack_double(grib_accessor* a, } primary_len = *len / expand_by; - primary_bitmap = (double*)grib_context_malloc_clear(a->context, primary_len * sizeof(double)); + primary_bitmap = (double*)grib_context_malloc_clear(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)); + secondary_bitmap = (double*)grib_context_malloc_clear(context_, secondary_len * sizeof(double)); if (!secondary_bitmap) { - grib_context_free(a->context, primary_bitmap); + grib_context_free(context_, primary_bitmap); return GRIB_OUT_OF_MEMORY; } @@ -115,15 +110,15 @@ int grib_accessor_class_data_g1secondary_bitmap_t::pack_double(grib_accessor* a, /*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); + err = grib_set_double_array_internal(grib_handle_of_accessor(this), 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); + err = grib_set_double_array_internal(grib_handle_of_accessor(this), secondary_bitmap_, secondary_bitmap, m); - grib_context_free(a->context, primary_bitmap); - grib_context_free(a->context, secondary_bitmap); + grib_context_free(context_, primary_bitmap); + grib_context_free(context_, secondary_bitmap); if (err == GRIB_SUCCESS) - err = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_ones, on); + err = grib_set_long_internal(grib_handle_of_accessor(this), number_of_ones_, on); return err; } diff --git a/src/accessor/grib_accessor_class_data_g1secondary_bitmap.h b/src/accessor/grib_accessor_class_data_g1secondary_bitmap.h index 63ee792ae..0a5d492c8 100644 --- a/src/accessor/grib_accessor_class_data_g1secondary_bitmap.h +++ b/src/accessor/grib_accessor_class_data_g1secondary_bitmap.h @@ -15,16 +15,13 @@ 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_data_g1secondary_bitmap_t() : + grib_accessor_data_secondary_bitmap_t() { class_name_ = "data_g1secondary_bitmap"; } 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; + int pack_double(const double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* number_of_ones_; }; diff --git a/src/accessor/grib_accessor_class_data_g1shsimple_packing.cc b/src/accessor/grib_accessor_class_data_g1shsimple_packing.cc index 0cf00e74c..9243cad52 100644 --- a/src/accessor/grib_accessor_class_data_g1shsimple_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1shsimple_packing.cc @@ -10,32 +10,29 @@ #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; +grib_accessor_data_g1shsimple_packing_t _grib_accessor_data_g1shsimple_packing{}; +grib_accessor* grib_accessor_data_g1shsimple_packing = &_grib_accessor_data_g1shsimple_packing; - -int grib_accessor_class_data_g1shsimple_packing_t::value_count(grib_accessor* a, long* count) +int grib_accessor_data_g1shsimple_packing_t::value_count(long* count) { - grib_accessor_data_g1shsimple_packing_t* self = (grib_accessor_data_g1shsimple_packing_t*)a; - size_t len = 0; - int err = 0; + size_t len = 0; + int err = 0; - err = grib_get_size(grib_handle_of_accessor(a), self->coded_values, &len); + err = grib_get_size(grib_handle_of_accessor(this), 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) +int grib_accessor_data_g1shsimple_packing_t::unpack_double(double* val, size_t* len) { - grib_accessor_data_g1shsimple_packing_t* self = (grib_accessor_data_g1shsimple_packing_t*)a; - int err = GRIB_SUCCESS; + 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) + if ((err = grib_get_size(grib_handle_of_accessor(this), coded_values_, &coded_n_vals)) != GRIB_SUCCESS) return err; n_vals = coded_n_vals + 1; @@ -45,17 +42,17 @@ int grib_accessor_class_data_g1shsimple_packing_t::unpack_double(grib_accessor* return GRIB_ARRAY_TOO_SMALL; } - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->real_part, val)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(grib_handle_of_accessor(this), 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) + if ((err = grib_get_double_array_internal(grib_handle_of_accessor(this), coded_values_, val, &coded_n_vals)) != GRIB_SUCCESS) return err; - grib_context_log(a->context, GRIB_LOG_DEBUG, + grib_context_log(context_, GRIB_LOG_DEBUG, "grib_accessor_data_g1shsimple_packing_t_bitmap : unpack_double : creating %s, %d values", - a->name, n_vals); + name_, n_vals); *len = n_vals; diff --git a/src/accessor/grib_accessor_class_data_g1shsimple_packing.h b/src/accessor/grib_accessor_class_data_g1shsimple_packing.h index c852c7213..54f3c99ad 100644 --- a/src/accessor/grib_accessor_class_data_g1shsimple_packing.h +++ b/src/accessor/grib_accessor_class_data_g1shsimple_packing.h @@ -15,14 +15,9 @@ 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_data_g1shsimple_packing_t() : + grib_accessor_data_shsimple_packing_t() { class_name_ = "data_g1shsimple_packing"; } 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; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; }; diff --git a/src/accessor/grib_accessor_class_data_g1simple_packing.cc b/src/accessor/grib_accessor_class_data_g1simple_packing.cc index 63b403da0..2f0b64134 100644 --- a/src/accessor/grib_accessor_class_data_g1simple_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1simple_packing.cc @@ -11,39 +11,34 @@ #include "grib_accessor_class_data_g1simple_packing.h" #include "grib_scaling.h" -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; +grib_accessor_data_g1simple_packing_t _grib_accessor_data_g1simple_packing{}; +grib_accessor* grib_accessor_data_g1simple_packing = &_grib_accessor_data_g1simple_packing; - -void grib_accessor_class_data_g1simple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_g1simple_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_simple_packing_t::init(a, v, args); - grib_accessor_data_g1simple_packing_t* self = (grib_accessor_data_g1simple_packing_t*)a; + grib_accessor_data_simple_packing_t::init(v, args); - 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++); - 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; + half_byte_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); + packingType_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); + ieee_packing_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); + precision_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); + edition_ = 1; + flags_ |= GRIB_ACCESSOR_FLAG_DATA; } -int grib_accessor_class_data_g1simple_packing_t::value_count(grib_accessor* a, long* number_of_values) +int grib_accessor_data_g1simple_packing_t::value_count(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 */ - /*if(a->length == 0) + /*if(length_ == 0) return 0;*/ - return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, number_of_values); + return grib_get_long_internal(grib_handle_of_accessor(this), number_of_values_, number_of_values); } -int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len) +int grib_accessor_data_g1simple_packing_t::pack_double(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; int ret = 0; @@ -60,8 +55,8 @@ int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, c double divisor = 1; int i; long off = 0; - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); + grib_context* c = context_; + grib_handle* h = grib_handle_of_accessor(this); char* ieee_packing_s = NULL; char* packingType_s = NULL; char* precision_s = NULL; @@ -73,14 +68,14 @@ int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, c int err = 0; if (*len != 0) { - if (self->units_factor && - (grib_get_double_internal(grib_handle_of_accessor(a), self->units_factor, &units_factor) == GRIB_SUCCESS)) { - grib_set_double_internal(grib_handle_of_accessor(a), self->units_factor, 1.0); + if (units_factor_ && + (grib_get_double_internal(grib_handle_of_accessor(this), units_factor_, &units_factor) == GRIB_SUCCESS)) { + grib_set_double_internal(grib_handle_of_accessor(this), units_factor_, 1.0); } - if (self->units_bias && - (grib_get_double_internal(grib_handle_of_accessor(a), self->units_bias, &units_bias) == GRIB_SUCCESS)) { - grib_set_double_internal(grib_handle_of_accessor(a), self->units_bias, 0.0); + if (units_bias_ && + (grib_get_double_internal(grib_handle_of_accessor(this), units_bias_, &units_bias) == GRIB_SUCCESS)) { + grib_set_double_internal(grib_handle_of_accessor(this), units_bias_, 0.0); } if (units_factor != 1.0) { @@ -101,15 +96,15 @@ int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, c } } - if (c->ieee_packing && self->ieee_packing) { + if (c->ieee_packing && ieee_packing_) { long precision = 0; /* Either 1(=32 bits) or 2(=64 bits) */ - size_t lenstr = strlen(self->ieee_packing); + size_t lenstr = strlen(ieee_packing_); if ((ret = codes_check_grib_ieee_packing_value(c->ieee_packing)) != GRIB_SUCCESS) return ret; - 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); + packingType_s = grib_context_strdup(c, packingType_); + ieee_packing_s = grib_context_strdup(c, ieee_packing_); + precision_s = grib_context_strdup(c, precision_); precision = c->ieee_packing == 32 ? 1 : 2; if ((ret = grib_set_string(h, packingType_s, ieee_packing_s, &lenstr)) != GRIB_SUCCESS) @@ -124,62 +119,62 @@ int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, c } } - ret = grib_accessor_class_data_simple_packing_t::pack_double(a, val, len); + ret = grib_accessor_data_simple_packing_t::pack_double(val, len); switch (ret) { case GRIB_CONSTANT_FIELD: - ret = grib_get_long(grib_handle_of_accessor(a), "constantFieldHalfByte", &constantFieldHalfByte); + ret = grib_get_long(grib_handle_of_accessor(this), "constantFieldHalfByte", &constantFieldHalfByte); if (ret) constantFieldHalfByte = 0; - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->half_byte, constantFieldHalfByte)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), half_byte_, constantFieldHalfByte)) != GRIB_SUCCESS) return ret; - ret = grib_buffer_replace(a, NULL, 0, 1, 1); + ret = grib_buffer_replace(this, NULL, 0, 1, 1); if (ret != GRIB_SUCCESS) return ret; return GRIB_SUCCESS; case GRIB_NO_VALUES: - ret = grib_get_long(grib_handle_of_accessor(a), "constantFieldHalfByte", &constantFieldHalfByte); + ret = grib_get_long(grib_handle_of_accessor(this), "constantFieldHalfByte", &constantFieldHalfByte); if (ret) constantFieldHalfByte = 0; /* TODO move to def file */ - grib_get_double(grib_handle_of_accessor(a), "missingValue", &missingValue); - if ((err = grib_set_double_internal(grib_handle_of_accessor(a), self->reference_value, missingValue)) != + grib_get_double(grib_handle_of_accessor(this), "missingValue", &missingValue); + if ((err = grib_set_double_internal(grib_handle_of_accessor(this), reference_value_, missingValue)) != GRIB_SUCCESS) return err; - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->binary_scale_factor, binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), binary_scale_factor_, binary_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->half_byte, constantFieldHalfByte)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), half_byte_, constantFieldHalfByte)) != GRIB_SUCCESS) return ret; - ret = grib_buffer_replace(a, NULL, 0, 1, 1); + ret = grib_buffer_replace(this, NULL, 0, 1, 1); if (ret != GRIB_SUCCESS) return ret; return GRIB_SUCCESS; case GRIB_INVALID_BPV: - grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to compute packing parameters. Invalid bits per value"); + grib_context_log(context_, GRIB_LOG_ERROR, "Unable to compute packing parameters. Invalid bits per value"); return ret; case GRIB_SUCCESS: break; default: - grib_context_log(a->context, GRIB_LOG_ERROR, "GRIB1 simple packing: unable to set values (%s)", grib_get_error_message(ret)); + grib_context_log(context_, GRIB_LOG_ERROR, "GRIB1 simple packing: unable to set values (%s)", grib_get_error_message(ret)); return ret; } - if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(grib_handle_of_accessor(this), reference_value_, &reference_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetdata, &offsetdata)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetdata_, &offsetdata)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetsection, &offsetsection)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetsection_, &offsetsection)) != GRIB_SUCCESS) return ret; decimal = codes_power(decimal_scale_factor, 10); @@ -189,32 +184,32 @@ int grib_accessor_class_data_g1simple_packing_t::pack_double(grib_accessor* a, c if ((buflen + (offsetdata - offsetsection)) % 2) { buflen++; /* - a->length++; - grib_handle_of_accessor(a)->buffer->ulength++; + length_ ++; + grib_handle_of_accessor(this)->buffer->ulength++; */ } half_byte = (buflen * 8) - ((*len) * bits_per_value); - grib_context_log(a->context, GRIB_LOG_DEBUG, + grib_context_log(context_, GRIB_LOG_DEBUG, "HALF byte: buflen=%d bits_per_value=%ld len=%d half_byte=%ld\n", buflen, bits_per_value, *len, half_byte); Assert(half_byte <= 0x0f); - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->half_byte, half_byte)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), half_byte_, half_byte)) != GRIB_SUCCESS) return ret; - buf = (unsigned char*)grib_context_buffer_malloc_clear(a->context, buflen); + buf = (unsigned char*)grib_context_buffer_malloc_clear(context_, buflen); encoded = buf; 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_t : pack_double : packing %s, %d values", a->name, n_vals); + grib_context_log(context_, GRIB_LOG_DEBUG, + "grib_accessor_data_g1simple_packing_t : pack_double : packing %s, %d values", name_, n_vals); - ret = grib_buffer_replace(a, buf, buflen, 1, 1); + ret = grib_buffer_replace(this, buf, buflen, 1, 1); if (ret != GRIB_SUCCESS) return ret; - grib_context_buffer_free(a->context, buf); + grib_context_buffer_free(context_, buf); return GRIB_SUCCESS; } diff --git a/src/accessor/grib_accessor_class_data_g1simple_packing.h b/src/accessor/grib_accessor_class_data_g1simple_packing.h index c82532361..4fdcc1241 100644 --- a/src/accessor/grib_accessor_class_data_g1simple_packing.h +++ b/src/accessor/grib_accessor_class_data_g1simple_packing.h @@ -15,19 +15,16 @@ 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_data_g1simple_packing_t() : + grib_accessor_data_simple_packing_t() { class_name_ = "data_g1simple_packing"; } 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; + int pack_double(const double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +public: + const char* half_byte_; + const char* packingType_; + const char* ieee_packing_; + const char* precision_; }; diff --git a/src/accessor/grib_accessor_class_data_g22order_packing.cc b/src/accessor/grib_accessor_class_data_g22order_packing.cc index aefef16c8..48c7c1ade 100644 --- a/src/accessor/grib_accessor_class_data_g22order_packing.cc +++ b/src/accessor/grib_accessor_class_data_g22order_packing.cc @@ -10,39 +10,37 @@ #include "grib_accessor_class_data_g22order_packing.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; +grib_accessor_data_g22order_packing_t _grib_accessor_data_g22order_packing{}; +grib_accessor* grib_accessor_data_g22order_packing = &_grib_accessor_data_g22order_packing; - -void grib_accessor_class_data_g22order_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_g22order_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_values_t::init(a, v, args); - grib_accessor_data_g22order_packing_t* self = reinterpret_cast(a); - grib_handle* gh = grib_handle_of_accessor(a); + grib_accessor_values_t::init(v, args); + grib_handle* gh = grib_handle_of_accessor(this); - self->numberOfValues = grib_arguments_get_name(gh, args, self->carg++); - self->bits_per_value = grib_arguments_get_name(gh, args, self->carg++); - self->reference_value = grib_arguments_get_name(gh, args, self->carg++); - self->binary_scale_factor = grib_arguments_get_name(gh, args, self->carg++); - self->decimal_scale_factor = grib_arguments_get_name(gh, args, self->carg++); - self->optimize_scale_factor = grib_arguments_get_name(gh, args, self->carg++); + numberOfValues_ = grib_arguments_get_name(gh, args, carg_++); + bits_per_value_ = grib_arguments_get_name(gh, args, carg_++); + reference_value_ = grib_arguments_get_name(gh, args, carg_++); + binary_scale_factor_ = grib_arguments_get_name(gh, args, carg_++); + decimal_scale_factor_ = grib_arguments_get_name(gh, args, carg_++); + optimize_scale_factor_ = grib_arguments_get_name(gh, args, carg_++); - self->typeOfOriginalFieldValues = grib_arguments_get_name(gh, args, self->carg++); - self->groupSplittingMethodUsed = grib_arguments_get_name(gh, args, self->carg++); - self->missingValueManagementUsed = grib_arguments_get_name(gh, args, self->carg++); - self->primaryMissingValueSubstitute = grib_arguments_get_name(gh, args, self->carg++); - self->secondaryMissingValueSubstitute = grib_arguments_get_name(gh, args, self->carg++); - self->numberOfGroupsOfDataValues = grib_arguments_get_name(gh, args, self->carg++); - self->referenceForGroupWidths = grib_arguments_get_name(gh, args, self->carg++); - self->numberOfBitsUsedForTheGroupWidths = grib_arguments_get_name(gh, args, self->carg++); - self->referenceForGroupLengths = grib_arguments_get_name(gh, args, self->carg++); - self->lengthIncrementForTheGroupLengths = grib_arguments_get_name(gh, args, self->carg++); - self->trueLengthOfLastGroup = grib_arguments_get_name(gh, args, self->carg++); - self->numberOfBitsUsedForTheScaledGroupLengths = grib_arguments_get_name(gh, args, self->carg++); + typeOfOriginalFieldValues_ = grib_arguments_get_name(gh, args, carg_++); + groupSplittingMethodUsed_ = grib_arguments_get_name(gh, args, carg_++); + missingValueManagementUsed_ = grib_arguments_get_name(gh, args, carg_++); + primaryMissingValueSubstitute_ = grib_arguments_get_name(gh, args, carg_++); + secondaryMissingValueSubstitute_ = grib_arguments_get_name(gh, args, carg_++); + numberOfGroupsOfDataValues_ = grib_arguments_get_name(gh, args, carg_++); + referenceForGroupWidths_ = grib_arguments_get_name(gh, args, carg_++); + numberOfBitsUsedForTheGroupWidths_ = grib_arguments_get_name(gh, args, carg_++); + referenceForGroupLengths_ = grib_arguments_get_name(gh, args, carg_++); + lengthIncrementForTheGroupLengths_ = grib_arguments_get_name(gh, args, carg_++); + trueLengthOfLastGroup_ = grib_arguments_get_name(gh, args, carg_++); + numberOfBitsUsedForTheScaledGroupLengths_ = grib_arguments_get_name(gh, args, carg_++); - self->orderOfSpatialDifferencing = grib_arguments_get_name(gh, args, self->carg++); - self->numberOfOctetsExtraDescriptors = grib_arguments_get_name(gh, args, self->carg++); - a->flags |= GRIB_ACCESSOR_FLAG_DATA; + orderOfSpatialDifferencing_ = grib_arguments_get_name(gh, args, carg_++); + numberOfOctetsExtraDescriptors_ = grib_arguments_get_name(gh, args, carg_++); + flags_ |= GRIB_ACCESSOR_FLAG_DATA; } #define ONES (~(int)0) @@ -87,7 +85,7 @@ void add_many_bitstream(bitstream_context* ctx, grib_accessor* a, int* t, int n, const int max_numbits = 25; if (n_bits > max_numbits) { - grib_context_log(a->context, GRIB_LOG_FATAL, "grid_complex packing: n_bits=%d exceeds the maximum=%d", n_bits, max_numbits); + grib_context_log(a->context_, GRIB_LOG_FATAL, "grid_complex packing: n_bits=%d exceeds the maximum=%d", n_bits, max_numbits); } jmask = (1 << n_bits) - 1; @@ -114,7 +112,7 @@ void add_bitstream(bitstream_context* ctx, grib_accessor* a, int t, int n_bits) n_bits = 16; } if (n_bits > max_numbits) { - grib_context_log(a->context, GRIB_LOG_FATAL, "grid_complex packing: n_bits=%d exceeds the maximum=%d", n_bits, max_numbits); + grib_context_log(a->context_, GRIB_LOG_FATAL, "grid_complex packing: n_bits=%d exceeds the maximum=%d", n_bits, max_numbits); } jmask = (1 << n_bits) - 1; ctx->rbits += n_bits; @@ -256,9 +254,9 @@ static int min_max_array(double* data, unsigned int n, double* min, double* max) // } // if (i == nn) { /* all defined values, no need for bms */ -// bms = reinterpret_cast(grib_context_malloc(a->context, 6)); +// bms = reinterpret_cast(grib_context_malloc(context_ , 6)); // if (bms == NULL) -// grib_context_log(a->context, GRIB_LOG_ERROR, "mk_bms: memory allocation problem", ""); +// grib_context_log(context_ , GRIB_LOG_ERROR, "mk_bms: memory allocation problem", ""); // uint_char(6, bms); // length of section 6 // bms[4] = 6; // section 6 // bms[5] = 255; // no bitmap @@ -266,9 +264,9 @@ static int min_max_array(double* data, unsigned int n, double* min, double* max) // } // bms_size = 6 + (nn + 7) / 8; -// bms = reinterpret_cast(grib_context_malloc(a->context, bms_size)); +// bms = reinterpret_cast(grib_context_malloc(context_ , bms_size)); // if (bms == NULL) -// grib_context_log(a->context, GRIB_LOG_ERROR, "mk_bms: memory allocation problem", ""); +// grib_context_log(context_ , GRIB_LOG_ERROR, "mk_bms: memory allocation problem", ""); // uint_char(bms_size, bms); // length of section 6 // bms[4] = 6; // section 6 @@ -774,11 +772,10 @@ static void merge_j(struct section* h, int ref_bits, int width_bits, int has_und } } -int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_g22order_packing_t::pack_double(const double* val, size_t* len) { - grib_accessor_data_g22order_packing_t* self = reinterpret_cast(a); - grib_handle* gh = grib_handle_of_accessor(a); - const char* cclass_name = a->cclass->name; + grib_handle* gh = grib_handle_of_accessor(this); + const char* cclass_name = class_name_; int err = 0; @@ -786,7 +783,7 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c // long nvals_per_group = 0; // long nbits_per_group_val = 0; - long binary_scale_factor, decimal_scale_factor, typeOfOriginalFieldValues; + long binary_scale_factor, decimal_scale_factor, typeOfOriginalFieldValues, optimize_scale_factor; // long groupSplittingMethodUsed, numberOfGroupsOfDataValues, referenceForGroupWidths; long missingValueManagementUsed, primaryMissingValueSubstitute, secondaryMissingValueSubstitute; long numberOfBitsUsedForTheGroupWidths, numberOfBitsUsedForTheScaledGroupLengths, orderOfSpatialDifferencing; @@ -810,30 +807,33 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c if (*len == 0) return GRIB_NO_VALUES; - if ((err = grib_get_long_internal(gh, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; - int use_scale = 1; + if ((err = grib_get_long_internal(gh, self->optimize_scale_factor, &optimize_scale_factor)) != GRIB_SUCCESS) + return err; - if ((err = grib_get_long_internal(gh, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + int use_scale = !optimize_scale_factor; + + if ((err = grib_get_long_internal(gh, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->typeOfOriginalFieldValues, &typeOfOriginalFieldValues)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, typeOfOriginalFieldValues_, &typeOfOriginalFieldValues)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->missingValueManagementUsed, &missingValueManagementUsed)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, missingValueManagementUsed_, &missingValueManagementUsed)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->primaryMissingValueSubstitute, &primaryMissingValueSubstitute)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, primaryMissingValueSubstitute_, &primaryMissingValueSubstitute)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->secondaryMissingValueSubstitute, &secondaryMissingValueSubstitute)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, secondaryMissingValueSubstitute_, &secondaryMissingValueSubstitute)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->numberOfBitsUsedForTheGroupWidths, &numberOfBitsUsedForTheGroupWidths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, numberOfBitsUsedForTheGroupWidths_, &numberOfBitsUsedForTheGroupWidths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->numberOfBitsUsedForTheScaledGroupLengths, &numberOfBitsUsedForTheScaledGroupLengths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, numberOfBitsUsedForTheScaledGroupLengths_, &numberOfBitsUsedForTheScaledGroupLengths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->orderOfSpatialDifferencing, &orderOfSpatialDifferencing)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, orderOfSpatialDifferencing_, &orderOfSpatialDifferencing)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->numberOfOctetsExtraDescriptors, &numberOfOctetsExtraDescriptors)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, numberOfOctetsExtraDescriptors_, &numberOfOctetsExtraDescriptors)) != GRIB_SUCCESS) return err; if ((err = grib_get_long_internal(gh, "bitmapPresent", &bitmap_present)) != GRIB_SUCCESS) return err; @@ -860,37 +860,37 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c size_t packing_type_len = strlen(packing_type); grib_set_string_internal(gh, "packingType", packing_type, &packing_type_len); - if ((err = grib_set_double_internal(gh, self->reference_value, grib_ieee_to_long(0.0))) != GRIB_SUCCESS) + if ((err = grib_set_double_internal(gh, reference_value_, grib_ieee_to_long(0.0))) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->binary_scale_factor, 0)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, binary_scale_factor_, 0)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->decimal_scale_factor, 0)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, decimal_scale_factor_, 0)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->bits_per_value, 8)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, bits_per_value_, 8)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->typeOfOriginalFieldValues, 0)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, typeOfOriginalFieldValues_, 0)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->groupSplittingMethodUsed, 1)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, groupSplittingMethodUsed_, 1)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->missingValueManagementUsed, 1)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, missingValueManagementUsed_, 1)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->primaryMissingValueSubstitute, grib_ieee_to_long(static_cast(9.999e20)))) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, primaryMissingValueSubstitute_, grib_ieee_to_long(static_cast(9.999e20)))) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->secondaryMissingValueSubstitute, 0xFFFFFFFF)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, secondaryMissingValueSubstitute_, 0xFFFFFFFF)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->numberOfGroupsOfDataValues, 1)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, numberOfGroupsOfDataValues_, 1)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->referenceForGroupWidths, grib_ieee_to_long(0.0))) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, referenceForGroupWidths_, grib_ieee_to_long(0.0))) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->numberOfBitsUsedForTheGroupWidths, 8)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, numberOfBitsUsedForTheGroupWidths_, 8)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->referenceForGroupLengths, *len)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, referenceForGroupLengths_, *len)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->lengthIncrementForTheGroupLengths, 1)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, lengthIncrementForTheGroupLengths_, 1)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->trueLengthOfLastGroup, *len)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, trueLengthOfLastGroup_, *len)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->numberOfBitsUsedForTheScaledGroupLengths, 8)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, numberOfBitsUsedForTheScaledGroupLengths_, 8)) != GRIB_SUCCESS) return err; // Section 6 @@ -899,14 +899,14 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c // Section 7 constexpr size_t sec7_size = 3; unsigned char empty_sec7[sec7_size] = { 255, 0, 0 }; // group reference, group width, group length - grib_buffer_replace(a, empty_sec7, sec7_size, 1, 1); + grib_buffer_replace(this, empty_sec7, sec7_size, 1, 1); return GRIB_SUCCESS; } size_t ndata = *len; - double* data = reinterpret_cast(grib_context_malloc_clear(a->context, ndata * sizeof(double))); + double* data = reinterpret_cast(grib_context_malloc_clear(context_, ndata * sizeof(double))); if (data == NULL) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: unable to allocate %zu bytes", cclass_name, ndata * sizeof(double)); + grib_context_log(context_, GRIB_LOG_ERROR, "%s packing: unable to allocate %zu bytes", cclass_name, ndata * sizeof(double)); return GRIB_OUT_OF_MEMORY; } memcpy(data, val, sizeof(*data) * ndata); @@ -924,13 +924,13 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c nndata = use_bitmap ? ndef : ndata; has_undef = use_bitmap ? 0 : ndata != ndef; - v = reinterpret_cast(grib_context_malloc(a->context, nndata * sizeof(int))); + v = reinterpret_cast(grib_context_malloc(context_, nndata * sizeof(int))); if (v == NULL) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: unable to allocate %zu bytes", cclass_name, nndata * sizeof(int)); + grib_context_log(context_, GRIB_LOG_ERROR, "%s packing: unable to allocate %zu bytes", cclass_name, nndata * sizeof(int)); return GRIB_OUT_OF_MEMORY; } if (min_max_array(data, ndata, &mn, &mx) != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: failed to get min max of data", cclass_name); + grib_context_log(context_, GRIB_LOG_ERROR, "%s packing: failed to get min max of data", cclass_name); return GRIB_ENCODING_ERROR; } min_val = mn; @@ -1087,7 +1087,7 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c } #ifdef DEBUG - grib_context_log(a->context, GRIB_LOG_DEBUG, "COMPLEX: 2: vmx %d vmn %d nbits %d", vmx, vmn, + grib_context_log(context_, GRIB_LOG_DEBUG, "COMPLEX: 2: vmx %d vmn %d nbits %d", vmx, vmn, find_nbits(vmx - vmn + has_undef)); #endif @@ -1107,9 +1107,9 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c } } - list = reinterpret_cast(grib_context_malloc_clear(a->context, nstruct * sizeof(section))); + list = reinterpret_cast(grib_context_malloc_clear(context_, nstruct * sizeof(section))); if (list == NULL) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: memory allocation of list failed", cclass_name); + grib_context_log(context_, GRIB_LOG_ERROR, "%s packing: memory allocation of list failed", cclass_name); return GRIB_OUT_OF_MEMORY; } @@ -1139,7 +1139,7 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c start.tail = &list[0]; if (nstruct != ii + 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: nstruct=%zu wanted %zu", cclass_name, nstruct, ii + 1); + grib_context_log(context_, GRIB_LOG_ERROR, "%s packing: nstruct=%zu wanted %zu", cclass_name, nstruct, ii + 1); return GRIB_ENCODING_ERROR; } for (i = 1; i < nstruct; i++) { @@ -1157,7 +1157,7 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c LEN_SEC_MAX); #ifdef DEBUG j = size_all(start.tail, vbits, LEN_BITS + est_group_width, has_undef); - grib_context_log(a->context, GRIB_LOG_DEBUG, "COMPLEX: complex start %d %d bytes", k, j); + grib_context_log(context_, GRIB_LOG_DEBUG, "COMPLEX: complex start %d %d bytes", k, j); #endif k = 2 * k + 1 + has_undef; } @@ -1165,16 +1165,16 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c // try making segment sizes larger // 12/2015 need to segment size less 25 bits, bitstream software limitation - list_backup = reinterpret_cast(grib_context_malloc(a->context, nstruct * sizeof(section))); + list_backup = reinterpret_cast(grib_context_malloc(context_, nstruct * sizeof(section))); if (list_backup == NULL) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: memory allocation of list_backup failed", cclass_name); + grib_context_log(context_, GRIB_LOG_ERROR, "%s packing: memory allocation of list_backup failed", cclass_name); return GRIB_OUT_OF_MEMORY; } j = size_all(start.tail, vbits, LEN_BITS + est_group_width, has_undef); j0 = j + 1; #ifdef DEBUG - grib_context_log(a->context, GRIB_LOG_DEBUG, "COMPLEX: complex start inc segments size0 %d segsize %d", j, LEN_SEC_MAX); + grib_context_log(context_, GRIB_LOG_DEBUG, "COMPLEX: complex start inc segments size0 %d segsize %d", j, LEN_SEC_MAX); #endif while (j < j0 && LEN_BITS < 25) { j0 = j; @@ -1185,7 +1185,7 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c LEN_SEC_MAX); j = size_all(start.tail, vbits, LEN_BITS + est_group_width, has_undef); #ifdef DEBUG - grib_context_log(a->context, GRIB_LOG_DEBUG, + grib_context_log(context_, GRIB_LOG_DEBUG, "COMPLEX: complex inc segments size size0 %d size1 %d segsize %d " "LEN_BITS=%d", j0, j, LEN_SEC_MAX, LEN_BITS); @@ -1196,19 +1196,19 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c LEN_SEC_MAX = (LEN_SEC_MAX - 1) / 2; } } - grib_context_free(a->context, list_backup); + grib_context_free(context_, list_backup); exchange(start.tail, v, has_undef, LEN_SEC_MAX); #ifdef DEBUG j = size_all(start.tail, vbits, LEN_BITS + est_group_width, has_undef); - grib_context_log(a->context, GRIB_LOG_DEBUG, "COMPLEX: exchange %d bytes", j); + grib_context_log(context_, GRIB_LOG_DEBUG, "COMPLEX: exchange %d bytes", j); #endif merge_j(start.tail, vbits, LEN_BITS + est_group_width, has_undef, vmx, LEN_SEC_MAX); #ifdef DEBUG j = size_all(start.tail, vbits, LEN_BITS + est_group_width, has_undef); - grib_context_log(a->context, GRIB_LOG_DEBUG, "COMPLEX: complex start %d %d bytes", vmx, j); + grib_context_log(context_, GRIB_LOG_DEBUG, "COMPLEX: complex start %d %d bytes", vmx, j); #endif // finished making segments @@ -1240,14 +1240,14 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c s = s->tail; } - lens = reinterpret_cast(grib_context_malloc(a->context, ngroups * sizeof(int))); - widths = reinterpret_cast(grib_context_malloc(a->context, ngroups * sizeof(int))); - refs = reinterpret_cast(grib_context_malloc(a->context, ngroups * sizeof(int))); - itmp = reinterpret_cast(grib_context_malloc(a->context, ngroups * sizeof(int))); - itmp2 = reinterpret_cast(grib_context_malloc(a->context, ngroups * sizeof(int))); + lens = reinterpret_cast(grib_context_malloc(context_, ngroups * sizeof(int))); + widths = reinterpret_cast(grib_context_malloc(context_, ngroups * sizeof(int))); + refs = reinterpret_cast(grib_context_malloc(context_, ngroups * sizeof(int))); + itmp = reinterpret_cast(grib_context_malloc(context_, ngroups * sizeof(int))); + itmp2 = reinterpret_cast(grib_context_malloc(context_, ngroups * sizeof(int))); if (lens == NULL || widths == NULL || refs == NULL || itmp == NULL || itmp2 == NULL) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s packing: memory alloc of lens/widths/refs/itmp/itmp2 failed", cclass_name); + grib_context_log(context_, GRIB_LOG_ERROR, "%s packing: memory alloc of lens/widths/refs/itmp/itmp2 failed", cclass_name); return GRIB_OUT_OF_MEMORY; } @@ -1307,38 +1307,38 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c bits_per_value = find_nbits(grefmx + has_undef); numberOfBitsUsedForTheGroupWidths = find_nbits(gwidmx - gwidmn + has_undef); - if ((err = grib_set_long_internal(gh, self->bits_per_value, bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, bits_per_value_, bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_set_double_internal(gh, self->reference_value, static_cast(ref))) != GRIB_SUCCESS) + if ((err = grib_set_double_internal(gh, reference_value_, static_cast(ref))) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->binary_scale_factor, binary_scale)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, binary_scale_factor_, binary_scale)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->decimal_scale_factor, -dec_scale)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, decimal_scale_factor_, -dec_scale)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->typeOfOriginalFieldValues, 0)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, typeOfOriginalFieldValues_, 0)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->groupSplittingMethodUsed, 1)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, groupSplittingMethodUsed_, 1)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->missingValueManagementUsed, has_undef)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, missingValueManagementUsed_, has_undef)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->primaryMissingValueSubstitute, grib_ieee_to_long(static_cast(9.999e20)))) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, primaryMissingValueSubstitute_, grib_ieee_to_long(static_cast(9.999e20)))) != GRIB_SUCCESS) return err; - // if ((err = grib_set_long_internal(gh, self->secondaryMissingValueSubstitute, 0xFFFFFFFF)) != GRIB_SUCCESS) return err; + // if ((err = grib_set_long_internal(gh, secondaryMissingValueSubstitute_ , 0xFFFFFFFF)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->numberOfGroupsOfDataValues, ngroups)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, numberOfGroupsOfDataValues_, ngroups)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->referenceForGroupWidths, gwidmn)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, referenceForGroupWidths_, gwidmn)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->numberOfBitsUsedForTheGroupWidths, find_nbits(gwidmx - gwidmn + has_undef))) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, numberOfBitsUsedForTheGroupWidths_, find_nbits(gwidmx - gwidmn + has_undef))) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->referenceForGroupLengths, glenmn)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, referenceForGroupLengths_, glenmn)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->lengthIncrementForTheGroupLengths, 1)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, lengthIncrementForTheGroupLengths_, 1)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->trueLengthOfLastGroup, len_last)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, trueLengthOfLastGroup_, len_last)) != GRIB_SUCCESS) return err; numberOfBitsUsedForTheScaledGroupLengths = find_nbits(glenmx - glenmn); - if ((err = grib_set_long_internal(gh, self->numberOfBitsUsedForTheScaledGroupLengths, numberOfBitsUsedForTheScaledGroupLengths)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, numberOfBitsUsedForTheScaledGroupLengths_, numberOfBitsUsedForTheScaledGroupLengths)) != GRIB_SUCCESS) return err; size_sec7 = 5; @@ -1350,9 +1350,9 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c size_sec7 += 3 * numberOfOctetsExtraDescriptors; } if (orderOfSpatialDifferencing > 0) { - if ((err = grib_set_long_internal(gh, self->orderOfSpatialDifferencing, orderOfSpatialDifferencing)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, orderOfSpatialDifferencing_, orderOfSpatialDifferencing)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->numberOfOctetsExtraDescriptors, numberOfOctetsExtraDescriptors)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, numberOfOctetsExtraDescriptors_, numberOfOctetsExtraDescriptors)) != GRIB_SUCCESS) return err; } @@ -1380,9 +1380,9 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c } size_sec7 += (k >> 3) + ((k & 7) ? 1 : 0); - unsigned char* sec7 = reinterpret_cast(grib_context_malloc(a->context, size_sec7)); + unsigned char* sec7 = reinterpret_cast(grib_context_malloc(context_, size_sec7)); if (sec7 == NULL) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Unable to allocate %d bytes", cclass_name, size_sec7); + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Unable to allocate %d bytes", cclass_name, size_sec7); return GRIB_OUT_OF_MEMORY; } @@ -1390,32 +1390,32 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c bitstream_context ctx; init_bitstream(&ctx, sec7); - add_bitstream(&ctx, a, size_sec7 >> 16, 16); - add_bitstream(&ctx, a, size_sec7, 16); - add_bitstream(&ctx, a, 7, 8); + add_bitstream(&ctx, this, size_sec7 >> 16, 16); + add_bitstream(&ctx, this, size_sec7, 16); + add_bitstream(&ctx, this, 7, 8); // write extra octets if (orderOfSpatialDifferencing == 1 || orderOfSpatialDifferencing == 2) { - add_bitstream(&ctx, a, extra_0, 8 * numberOfOctetsExtraDescriptors); - if (orderOfSpatialDifferencing == 2) add_bitstream(&ctx, a, extra_1, 8 * numberOfOctetsExtraDescriptors); + add_bitstream(&ctx, this, extra_0, 8 * numberOfOctetsExtraDescriptors); + if (orderOfSpatialDifferencing == 2) add_bitstream(&ctx, this, extra_1, 8 * numberOfOctetsExtraDescriptors); k = vmn; if (k < 0) { k = -vmn | (1 << (8 * numberOfOctetsExtraDescriptors - 1)); } - add_bitstream(&ctx, a, k, 8 * numberOfOctetsExtraDescriptors); + add_bitstream(&ctx, this, k, 8 * numberOfOctetsExtraDescriptors); finish_bitstream(&ctx); } // write the group reference values - add_many_bitstream(&ctx, a, refs, ngroups, bits_per_value); + add_many_bitstream(&ctx, this, refs, ngroups, bits_per_value); finish_bitstream(&ctx); // write the group widths - add_many_bitstream(&ctx, a, itmp, ngroups, numberOfBitsUsedForTheGroupWidths); + add_many_bitstream(&ctx, this, itmp, ngroups, numberOfBitsUsedForTheGroupWidths); finish_bitstream(&ctx); // write the group lengths - add_many_bitstream(&ctx, a, itmp2, ngroups, numberOfBitsUsedForTheScaledGroupLengths); + add_many_bitstream(&ctx, this, itmp2, ngroups, numberOfBitsUsedForTheScaledGroupLengths); finish_bitstream(&ctx); s = start.tail; @@ -1435,26 +1435,26 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c } for (i = 0; i < ngroups; i++) { if (widths[i]) { - add_many_bitstream(&ctx, a, v + itmp[i], lens[i], widths[i]); + add_many_bitstream(&ctx, this, v + itmp[i], lens[i], widths[i]); } } finish_bitstream(&ctx); - grib_buffer_replace(a, sec7 + 5, size_sec7 - 5, 1, 1); + grib_buffer_replace(this, sec7 + 5, size_sec7 - 5, 1, 1); - grib_context_free(a->context, sec7); - grib_context_free(a->context, list); - grib_context_free(a->context, v); - grib_context_free(a->context, lens); - grib_context_free(a->context, widths); - grib_context_free(a->context, refs); - grib_context_free(a->context, itmp); - grib_context_free(a->context, itmp2); - grib_context_free(a->context, data); + grib_context_free(context_, sec7); + grib_context_free(context_, list); + grib_context_free(context_, v); + grib_context_free(context_, lens); + grib_context_free(context_, widths); + grib_context_free(context_, refs); + grib_context_free(context_, itmp); + grib_context_free(context_, itmp2); + grib_context_free(context_, data); // ECC-259: Set correct number of values - if ((err = grib_set_long_internal(gh, self->numberOfValues, *len)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, numberOfValues_, *len)) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; @@ -1463,10 +1463,10 @@ int grib_accessor_class_data_g22order_packing_t::pack_double(grib_accessor* a, c template static int unpack(grib_accessor* a, T* val, const size_t* len) { - static_assert(std::is_floating_point::value, "Requires floating points numbers"); grib_accessor_data_g22order_packing_t* self = reinterpret_cast(a); - const char* cclass_name = a->cclass->name; - grib_handle* gh = grib_handle_of_accessor(a); + static_assert(std::is_floating_point::value, "Requires floating points numbers"); + const char* cclass_name = a->class_name_; + grib_handle* gh = grib_handle_of_accessor(a); size_t i = 0; size_t j = 0; @@ -1518,56 +1518,56 @@ static int unpack(grib_accessor* a, T* val, const size_t* len) if (*len < static_cast(n_vals)) return GRIB_ARRAY_TOO_SMALL; - if ((err = grib_get_long_internal(gh, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(gh, self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(gh, self->reference_value_, &reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->typeOfOriginalFieldValues, &typeOfOriginalFieldValues)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->typeOfOriginalFieldValues_, &typeOfOriginalFieldValues)) != GRIB_SUCCESS) return err; // Don't call grib_get_long_internal to suppress error message being output - if ((err = grib_get_long(gh, self->groupSplittingMethodUsed, &groupSplittingMethodUsed)) != GRIB_SUCCESS) + if ((err = grib_get_long(gh, self->groupSplittingMethodUsed_, &groupSplittingMethodUsed)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->missingValueManagementUsed, &missingValueManagementUsed)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->missingValueManagementUsed_, &missingValueManagementUsed)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->primaryMissingValueSubstitute, &primaryMissingValueSubstitute)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->primaryMissingValueSubstitute_, &primaryMissingValueSubstitute)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->secondaryMissingValueSubstitute, &secondaryMissingValueSubstitute)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->secondaryMissingValueSubstitute_, &secondaryMissingValueSubstitute)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->numberOfGroupsOfDataValues, &numberOfGroupsOfDataValues)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->numberOfGroupsOfDataValues_, &numberOfGroupsOfDataValues)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->referenceForGroupWidths, &referenceForGroupWidths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->referenceForGroupWidths_, &referenceForGroupWidths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->numberOfBitsUsedForTheGroupWidths, &numberOfBitsUsedForTheGroupWidths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->numberOfBitsUsedForTheGroupWidths_, &numberOfBitsUsedForTheGroupWidths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->referenceForGroupLengths, &referenceForGroupLengths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->referenceForGroupLengths_, &referenceForGroupLengths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->lengthIncrementForTheGroupLengths, &lengthIncrementForTheGroupLengths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->lengthIncrementForTheGroupLengths_, &lengthIncrementForTheGroupLengths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->trueLengthOfLastGroup, &trueLengthOfLastGroup)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->trueLengthOfLastGroup_, &trueLengthOfLastGroup)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->numberOfBitsUsedForTheScaledGroupLengths, &numberOfBitsUsedForTheScaledGroupLengths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->numberOfBitsUsedForTheScaledGroupLengths_, &numberOfBitsUsedForTheScaledGroupLengths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->orderOfSpatialDifferencing, &orderOfSpatialDifferencing)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->orderOfSpatialDifferencing_, &orderOfSpatialDifferencing)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->numberOfOctetsExtraDescriptors, &numberOfOctetsExtraDescriptors)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->numberOfOctetsExtraDescriptors_, &numberOfOctetsExtraDescriptors)) != GRIB_SUCCESS) return err; if ((err = grib_get_double_internal(gh, "missingValue", &missingValue)) != GRIB_SUCCESS) return err; - self->dirty = 0; + a->dirty_ = 0; - sec_val = (long*)grib_context_malloc(a->context, (n_vals) * sizeof(long)); + sec_val = (long*)grib_context_malloc(a->context_, (n_vals) * sizeof(long)); if (!sec_val) return GRIB_OUT_OF_MEMORY; memset(sec_val, 0, (n_vals) * sizeof(long)); // See SUP-718 - buf_ref = buf + a->offset; + buf_ref = buf + a->offset_; ref_p = (numberOfGroupsOfDataValues * bits_per_value); @@ -1680,7 +1680,7 @@ static int unpack(grib_accessor* a, T* val, const size_t* len) // For Complex packing, order == 0 // For Complex packing and spatial differencing, order == 1 or 2 (code table 5.6) if (orderOfSpatialDifferencing != 1 && orderOfSpatialDifferencing != 2) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(a->context_, GRIB_LOG_ERROR, "%s unpacking: Unsupported order of spatial differencing %ld", cclass_name, orderOfSpatialDifferencing); return GRIB_INTERNAL_ERROR; } @@ -1691,8 +1691,8 @@ static int unpack(grib_accessor* a, T* val, const size_t* len) bias = grib_decode_signed_longb(buf_ref, &ref_p, numberOfOctetsExtraDescriptors * 8); - post_process(a->context, sec_val, n_vals, orderOfSpatialDifferencing, bias, extras); - // de_spatial_difference (a->context, sec_val, n_vals, orderOfSpatialDifferencing, bias); + post_process(a->context_, sec_val, n_vals, orderOfSpatialDifferencing, bias, extras); + // de_spatial_difference (context_ , sec_val, n_vals, orderOfSpatialDifferencing, bias); } binary_s = (T)codes_power(binary_scale_factor, 2); @@ -1707,49 +1707,49 @@ static int unpack(grib_accessor* a, T* val, const size_t* len) } } - grib_context_free(a->context, sec_val); + grib_context_free(a->context_, sec_val); return err; } -int grib_accessor_class_data_g22order_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_g22order_packing_t::unpack_double(double* val, size_t* len) { - return unpack(a, val, len); + return unpack(this, val, len); } -int grib_accessor_class_data_g22order_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_data_g22order_packing_t::unpack_float(float* val, size_t* len) { - return unpack(a, val, len); + return unpack(this, val, len); } -int grib_accessor_class_data_g22order_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_data_g22order_packing_t::unpack_double_element(size_t idx, double* val) { size_t size = 0; double* values = NULL; - int err = grib_get_size(grib_handle_of_accessor(a), "codedValues", &size); + int err = grib_get_size(grib_handle_of_accessor(this), "codedValues", &size); if (err) return err; if (idx > size) return GRIB_INVALID_ARGUMENT; - values = reinterpret_cast(grib_context_malloc_clear(a->context, size * sizeof(double))); - err = grib_get_double_array(grib_handle_of_accessor(a), "codedValues", values, &size); + values = reinterpret_cast(grib_context_malloc_clear(context_, size * sizeof(double))); + err = grib_get_double_array(grib_handle_of_accessor(this), "codedValues", values, &size); if (err) { - grib_context_free(a->context, values); + grib_context_free(context_, values); return err; } *val = values[idx]; - grib_context_free(a->context, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } -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) +int grib_accessor_data_g22order_packing_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) { size_t size = 0, i = 0; double* values; int err = 0; // GRIB-564: The indexes in index_array relate to codedValues NOT values! - err = grib_get_size(grib_handle_of_accessor(a), "codedValues", &size); + err = grib_get_size(grib_handle_of_accessor(this), "codedValues", &size); if (err) return err; @@ -1757,22 +1757,21 @@ int grib_accessor_class_data_g22order_packing_t::unpack_double_element_set(grib_ if (index_array[i] > size) return GRIB_INVALID_ARGUMENT; } - values = reinterpret_cast(grib_context_malloc_clear(a->context, size * sizeof(double))); - err = grib_get_double_array(grib_handle_of_accessor(a), "codedValues", values, &size); + values = reinterpret_cast(grib_context_malloc_clear(context_, size * sizeof(double))); + err = grib_get_double_array(grib_handle_of_accessor(this), "codedValues", values, &size); if (err) { - grib_context_free(a->context, values); + grib_context_free(context_, values); return err; } for (i = 0; i < len; i++) { val_array[i] = values[index_array[i]]; } - grib_context_free(a->context, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } -int grib_accessor_class_data_g22order_packing_t::value_count(grib_accessor* a, long* count) +int grib_accessor_data_g22order_packing_t::value_count(long* count) { - grib_accessor_data_g22order_packing_t* self = reinterpret_cast(a); *count = 0; - return grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfValues, count); + return grib_get_long_internal(grib_handle_of_accessor(this), numberOfValues_, count); } diff --git a/src/accessor/grib_accessor_class_data_g22order_packing.h b/src/accessor/grib_accessor_class_data_g22order_packing.h index 329823633..cbb396f62 100644 --- a/src/accessor/grib_accessor_class_data_g22order_packing.h +++ b/src/accessor/grib_accessor_class_data_g22order_packing.h @@ -16,39 +16,36 @@ 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_data_g22order_packing_t() : + grib_accessor_values_t() { class_name_ = "data_g22order_packing"; } 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; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_float(float* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + int unpack_double_element(size_t i, double* val) override; + int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; + +public: + 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_; }; diff --git a/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc b/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc index c159ceeea..066744538 100644 --- a/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc +++ b/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc @@ -12,44 +12,41 @@ #include "grib_scaling.h" #include -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; - +grib_accessor_data_g2bifourier_packing_t _grib_accessor_data_g2bifourier_packing{}; +grib_accessor* grib_accessor_data_g2bifourier_packing = &_grib_accessor_data_g2bifourier_packing; typedef unsigned long (*encode_float_proc)(double); typedef double (*decode_float_proc)(unsigned long); -void grib_accessor_class_data_g2bifourier_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_g2bifourier_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_simple_packing_t::init(a, v, args); - grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a; - grib_handle* gh = grib_handle_of_accessor(a); + grib_accessor_data_simple_packing_t::init(v, args); + grib_handle* gh = grib_handle_of_accessor(this); - self->ieee_floats = grib_arguments_get_name(gh, args, self->carg++); - self->laplacianOperatorIsSet = grib_arguments_get_name(gh, args, self->carg++); - self->laplacianOperator = grib_arguments_get_name(gh, args, self->carg++); - self->biFourierTruncationType = grib_arguments_get_name(gh, args, self->carg++); - self->sub_i = grib_arguments_get_name(gh, args, self->carg++); - self->sub_j = grib_arguments_get_name(gh, args, self->carg++); - self->bif_i = grib_arguments_get_name(gh, args, self->carg++); - self->bif_j = grib_arguments_get_name(gh, args, self->carg++); - self->biFourierSubTruncationType = grib_arguments_get_name(gh, args, self->carg++); - self->biFourierDoNotPackAxes = grib_arguments_get_name(gh, args, self->carg++); - self->biFourierMakeTemplate = grib_arguments_get_name(gh, args, self->carg++); - self->totalNumberOfValuesInUnpackedSubset = grib_arguments_get_name(gh, args, self->carg++); - /*self->numberOfValues = grib_arguments_get_name(gh,args,self->carg++);*/ + ieee_floats_ = grib_arguments_get_name(gh, args, carg_++); + laplacianOperatorIsSet_ = grib_arguments_get_name(gh, args, carg_++); + laplacianOperator_ = grib_arguments_get_name(gh, args, carg_++); + biFourierTruncationType_ = grib_arguments_get_name(gh, args, carg_++); + sub_i_ = grib_arguments_get_name(gh, args, carg_++); + sub_j_ = grib_arguments_get_name(gh, args, carg_++); + bif_i_ = grib_arguments_get_name(gh, args, carg_++); + bif_j_ = grib_arguments_get_name(gh, args, carg_++); + biFourierSubTruncationType_ = grib_arguments_get_name(gh, args, carg_++); + biFourierDoNotPackAxes_ = grib_arguments_get_name(gh, args, carg_++); + biFourierMakeTemplate_ = grib_arguments_get_name(gh, args, carg_++); + totalNumberOfValuesInUnpackedSubset_ = grib_arguments_get_name(gh, args, carg_++); + /*numberOfValues = grib_arguments_get_name(gh,args,carg_ ++);*/ - a->flags |= GRIB_ACCESSOR_FLAG_DATA; - self->dirty = 1; + flags_ |= GRIB_ACCESSOR_FLAG_DATA; + dirty_ = 1; } -int grib_accessor_class_data_g2bifourier_packing_t::value_count(grib_accessor* a, long* numberOfValues) +int grib_accessor_data_g2bifourier_packing_t::value_count(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; + grib_handle* gh = grib_handle_of_accessor(this); + *numberOfValues = 0; - return grib_get_long_internal(gh, self->number_of_values, numberOfValues); + return grib_get_long_internal(gh, number_of_values_, numberOfValues); } static void ellipse(long ni, long nj, long itrunc[], long jtrunc[]) @@ -132,7 +129,6 @@ static void diamond(long ni, long nj, long itrunc[], long jtrunc[]) #define scals(i, j) pow((double)((i) * (i) + (j) * (j)), bt->laplacianOperator) - #define for_ij() \ for (j = 0; j <= bt->bif_j; j++) \ for (i = 0; i <= bt->itruncation_bif[j]; i++) @@ -368,38 +364,37 @@ static bif_trunc_t* new_bif_trunc(grib_accessor* a) memset(bt, 0, sizeof(bif_trunc_t)); - if ((ret = grib_get_double_internal(gh, self->reference_value, &bt->reference_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(gh, self->reference_value_, &bt->reference_value)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->bits_per_value, &bt->bits_per_value)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->bits_per_value_, &bt->bits_per_value)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->binary_scale_factor, &bt->binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->binary_scale_factor_, &bt->binary_scale_factor)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->decimal_scale_factor, &bt->decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->decimal_scale_factor_, &bt->decimal_scale_factor)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->ieee_floats, &bt->ieee_floats)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->ieee_floats_, &bt->ieee_floats)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->laplacianOperatorIsSet, &bt->laplacianOperatorIsSet)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->laplacianOperatorIsSet_, &bt->laplacianOperatorIsSet)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_double_internal(gh, self->laplacianOperator, &bt->laplacianOperator)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(gh, self->laplacianOperator_, &bt->laplacianOperator)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->sub_i, &bt->sub_i)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->sub_i_, &bt->sub_i)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->sub_j, &bt->sub_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->sub_j_, &bt->sub_j)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->bif_i, &bt->bif_i)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->bif_i_, &bt->bif_i)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->bif_j, &bt->bif_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->bif_j_, &bt->bif_j)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->biFourierTruncationType, &bt->biFourierTruncationType)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->biFourierTruncationType_, &bt->biFourierTruncationType)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->biFourierSubTruncationType, &bt->biFourierSubTruncationType)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->biFourierSubTruncationType_, &bt->biFourierSubTruncationType)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->biFourierDoNotPackAxes, &bt->keepaxes)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->biFourierDoNotPackAxes_, &bt->keepaxes)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->biFourierMakeTemplate, &bt->maketemplate)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, self->biFourierMakeTemplate_, &bt->maketemplate)) != GRIB_SUCCESS) goto cleanup; - switch (bt->ieee_floats) { case 0: bt->decode_float = grib_long_to_ibm; @@ -472,10 +467,9 @@ cleanup: return NULL; } -int grib_accessor_class_data_g2bifourier_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_g2bifourier_packing_t::unpack_double(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); + grib_handle* gh = grib_handle_of_accessor(this); unsigned char* buf = NULL; unsigned char* hres = NULL; @@ -498,10 +492,10 @@ int grib_accessor_class_data_g2bifourier_packing_t::unpack_double(grib_accessor* int ret = GRIB_SUCCESS; int i, j, k; - if ((ret = a->value_count(&count)) != GRIB_SUCCESS) + if ((ret = value_count(&count)) != GRIB_SUCCESS) goto cleanup; - bt = new_bif_trunc(a); + bt = new_bif_trunc(this); if (bt == NULL) { ret = GRIB_INTERNAL_ERROR; @@ -513,7 +507,7 @@ int grib_accessor_class_data_g2bifourier_packing_t::unpack_double(grib_accessor* goto cleanup; } - if ((ret = grib_get_long_internal(gh, self->offsetdata, &offsetdata)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, offsetdata_, &offsetdata)) != GRIB_SUCCESS) goto cleanup; if (*len < bt->n_vals_bif) { *len = (long)bt->n_vals_bif; @@ -521,10 +515,10 @@ int grib_accessor_class_data_g2bifourier_packing_t::unpack_double(grib_accessor* goto cleanup; } - self->dirty = 0; + dirty_ = 0; buf = (unsigned char*)gh->buffer->data; - buf += a->byte_offset(); + buf += byte_offset(); s = codes_power(bt->binary_scale_factor, 2); d = codes_power(-bt->decimal_scale_factor, 10); @@ -534,7 +528,7 @@ int grib_accessor_class_data_g2bifourier_packing_t::unpack_double(grib_accessor* hres = buf; lres = buf; - packed_offset = a->byte_offset() + bt->bytes * bt->n_vals_sub; + packed_offset = byte_offset() + bt->bytes * bt->n_vals_sub; lpos = 8 * (packed_offset - offsetdata); hpos = 0; @@ -565,16 +559,15 @@ int grib_accessor_class_data_g2bifourier_packing_t::unpack_double(grib_accessor* cleanup: - free_bif_trunc(bt, a); + free_bif_trunc(bt, this); return ret; } -int grib_accessor_class_data_g2bifourier_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_g2bifourier_packing_t::pack_double(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; + grib_handle* gh = grib_handle_of_accessor(this); + const char* cclass_name = class_name_; size_t buflen = 0; size_t hsize = 0; @@ -601,11 +594,11 @@ int grib_accessor_class_data_g2bifourier_packing_t::pack_double(grib_accessor* a goto cleanup; } - bt = new_bif_trunc(a); + bt = new_bif_trunc(this); if (bt == NULL) { long makeTemplate = 0; - if ((ret = grib_get_long_internal(gh, self->biFourierMakeTemplate, &makeTemplate)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, biFourierMakeTemplate_, &makeTemplate)) != GRIB_SUCCESS) goto cleanup; if (!makeTemplate) { ret = GRIB_INTERNAL_ERROR; @@ -618,7 +611,7 @@ int grib_accessor_class_data_g2bifourier_packing_t::pack_double(grib_accessor* a } } - self->dirty = 1; + dirty_ = 1; if (*len != bt->n_vals_bif) { grib_context_log(gh->context, GRIB_LOG_ERROR, "BIFOURIER_PACKING: wrong number of values, expected %lu - got %lu", @@ -630,10 +623,10 @@ int grib_accessor_class_data_g2bifourier_packing_t::pack_double(grib_accessor* a if (!bt->laplacianOperatorIsSet) { bt->laplacianOperator = laplam(bt, val); - if ((ret = grib_set_double_internal(gh, self->laplacianOperator, bt->laplacianOperator)) != GRIB_SUCCESS) + if ((ret = grib_set_double_internal(gh, laplacianOperator_, bt->laplacianOperator)) != GRIB_SUCCESS) goto cleanup; - grib_get_double_internal(gh, self->laplacianOperator, &bt->laplacianOperator); + grib_get_double_internal(gh, laplacianOperator_, &bt->laplacianOperator); } /* @@ -667,7 +660,7 @@ int grib_accessor_class_data_g2bifourier_packing_t::pack_double(grib_accessor* a } if (bt->n_vals_bif != bt->n_vals_sub) { - ret = grib_optimize_decimal_factor(a, self->reference_value, + ret = grib_optimize_decimal_factor(this, reference_value_, max, min, bt->bits_per_value, 0, 1, &bt->decimal_scale_factor, &bt->binary_scale_factor, @@ -739,36 +732,36 @@ int grib_accessor_class_data_g2bifourier_packing_t::pack_double(grib_accessor* a buflen = ((hpos + lpos) / 8); - if ((ret = grib_set_double_internal(gh, self->reference_value, bt->reference_value)) != GRIB_SUCCESS) + if ((ret = grib_set_double_internal(gh, reference_value_, bt->reference_value)) != GRIB_SUCCESS) goto cleanup; { // Make sure we can decode it again double ref = 1e-100; - grib_get_double_internal(gh, self->reference_value, &ref); + grib_get_double_internal(gh, reference_value_, &ref); if (ref != bt->reference_value) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)", - cclass_name, __func__, self->reference_value, ref, bt->reference_value); + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)", + cclass_name, __func__, reference_value_, ref, bt->reference_value); return GRIB_INTERNAL_ERROR; } } - if ((ret = grib_set_long_internal(gh, self->binary_scale_factor, bt->binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(gh, binary_scale_factor_, bt->binary_scale_factor)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_set_long_internal(gh, self->decimal_scale_factor, bt->decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(gh, decimal_scale_factor_, bt->decimal_scale_factor)) != GRIB_SUCCESS) goto cleanup; - grib_buffer_replace(a, buf, buflen, 1, 1); + grib_buffer_replace(this, buf, buflen, 1, 1); - if ((ret = grib_set_long_internal(gh, self->totalNumberOfValuesInUnpackedSubset, bt->n_vals_sub)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(gh, totalNumberOfValuesInUnpackedSubset_, bt->n_vals_sub)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_set_long_internal(gh, self->number_of_values, bt->n_vals_bif)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(gh, number_of_values_, bt->n_vals_bif)) != GRIB_SUCCESS) goto cleanup; cleanup: - free_bif_trunc(bt, a); + free_bif_trunc(bt, this); if (buf != NULL) grib_context_free(gh->context, buf); diff --git a/src/accessor/grib_accessor_class_data_g2bifourier_packing.h b/src/accessor/grib_accessor_class_data_g2bifourier_packing.h index 2fd7378a5..22449fb93 100644 --- a/src/accessor/grib_accessor_class_data_g2bifourier_packing.h +++ b/src/accessor/grib_accessor_class_data_g2bifourier_packing.h @@ -15,29 +15,26 @@ 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_data_g2bifourier_packing_t() : + grib_accessor_data_simple_packing_t() { class_name_ = "data_g2bifourier_packing"; } 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; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +public: + 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_; }; diff --git a/src/accessor/grib_accessor_class_data_g2complex_packing.cc b/src/accessor/grib_accessor_class_data_g2complex_packing.cc index 079d14193..7b50a410d 100644 --- a/src/accessor/grib_accessor_class_data_g2complex_packing.cc +++ b/src/accessor/grib_accessor_class_data_g2complex_packing.cc @@ -10,40 +10,36 @@ #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; +grib_accessor_data_g2complex_packing_t _grib_accessor_data_g2complex_packing{}; +grib_accessor* grib_accessor_data_g2complex_packing = &_grib_accessor_data_g2complex_packing; - -void grib_accessor_class_data_g2complex_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_g2complex_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_complex_packing_t::init(a, v, 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; + grib_accessor_data_complex_packing_t::init(v, args); + numberOfValues_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); + edition_ = 2; - a->flags |= GRIB_ACCESSOR_FLAG_DATA; + flags_ |= GRIB_ACCESSOR_FLAG_DATA; } -int grib_accessor_class_data_g2complex_packing_t::value_count(grib_accessor* a, long* numberOfValues) +int grib_accessor_data_g2complex_packing_t::value_count(long* numberOfValues) { - grib_accessor_data_g2complex_packing_t* self = (grib_accessor_data_g2complex_packing_t*)a; - *numberOfValues = 0; + *numberOfValues = 0; - return grib_get_long(grib_handle_of_accessor(a), self->numberOfValues, numberOfValues); + return grib_get_long(grib_handle_of_accessor(this), numberOfValues_, numberOfValues); } -int grib_accessor_class_data_g2complex_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_g2complex_packing_t::pack_double(const double* val, size_t* len) { - grib_accessor_data_g2complex_packing_t* self = (grib_accessor_data_g2complex_packing_t*)a; - int ret = GRIB_SUCCESS; + int ret = GRIB_SUCCESS; if (*len == 0) return GRIB_NO_VALUES; - ret = grib_accessor_class_data_complex_packing_t::pack_double(a, val, len); + ret = grib_accessor_data_complex_packing_t::pack_double(val, len); if (ret == GRIB_SUCCESS) - ret = grib_set_long_internal(grib_handle_of_accessor(a), self->numberOfValues, *len); + ret = grib_set_long_internal(grib_handle_of_accessor(this), numberOfValues_, *len); return ret; } diff --git a/src/accessor/grib_accessor_class_data_g2complex_packing.h b/src/accessor/grib_accessor_class_data_g2complex_packing.h index 49f33a711..75a9195fd 100644 --- a/src/accessor/grib_accessor_class_data_g2complex_packing.h +++ b/src/accessor/grib_accessor_class_data_g2complex_packing.h @@ -15,16 +15,13 @@ 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_data_g2complex_packing_t() : + grib_accessor_data_complex_packing_t() { class_name_ = "data_g2complex_packing"; } 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; + int pack_double(const double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* numberOfValues_; }; diff --git a/src/accessor/grib_accessor_class_data_g2secondary_bitmap.cc b/src/accessor/grib_accessor_class_data_g2secondary_bitmap.cc index d5f9ad174..e12c570c6 100644 --- a/src/accessor/grib_accessor_class_data_g2secondary_bitmap.cc +++ b/src/accessor/grib_accessor_class_data_g2secondary_bitmap.cc @@ -10,28 +10,24 @@ #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; +grib_accessor_data_g2secondary_bitmap_t _grib_accessor_data_g2secondary_bitmap{}; +grib_accessor* grib_accessor_data_g2secondary_bitmap = &_grib_accessor_data_g2secondary_bitmap; - -void grib_accessor_class_data_g2secondary_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_g2secondary_bitmap_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_secondary_bitmap_t::init(a, v, 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); + grib_accessor_data_secondary_bitmap_t::init(v, args); + number_of_values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, 4); } -int grib_accessor_class_data_g2secondary_bitmap_t::value_count(grib_accessor* a, long* len) +int grib_accessor_data_g2secondary_bitmap_t::value_count(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); + *len = 0; + return grib_get_long_internal(grib_handle_of_accessor(this), number_of_values_, len); } -int grib_accessor_class_data_g2secondary_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_g2secondary_bitmap_t::pack_double(const double* val, size_t* len) { - grib_accessor_data_g2secondary_bitmap_t* self = (grib_accessor_data_g2secondary_bitmap_t*)a; - int err = 0; + int err = 0; long primary_len = 0, secondary_len = 0; double* primary_bitmap = NULL; @@ -43,12 +39,12 @@ int grib_accessor_class_data_g2secondary_bitmap_t::pack_double(grib_accessor* a, if (*len == 0) return GRIB_NO_VALUES; - if ((err = grib_get_long(grib_handle_of_accessor(a), self->expand_by, &expand_by)) != GRIB_SUCCESS) + if ((err = grib_get_long(grib_handle_of_accessor(this), 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) + if ((err = grib_get_double_internal(grib_handle_of_accessor(this), missing_value_, &missing_value)) != GRIB_SUCCESS) return err; if (*len % expand_by) { @@ -57,14 +53,14 @@ int grib_accessor_class_data_g2secondary_bitmap_t::pack_double(grib_accessor* a, } primary_len = *len / expand_by; - primary_bitmap = (double*)grib_context_malloc_clear(a->context, primary_len * sizeof(double)); + primary_bitmap = (double*)grib_context_malloc_clear(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)); + secondary_bitmap = (double*)grib_context_malloc_clear(context_, secondary_len * sizeof(double)); if (!secondary_bitmap) { - grib_context_free(a->context, primary_bitmap); + grib_context_free(context_, primary_bitmap); return GRIB_OUT_OF_MEMORY; } @@ -95,15 +91,15 @@ int grib_accessor_class_data_g2secondary_bitmap_t::pack_double(grib_accessor* a, Assert(k == primary_len); - err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->primary_bitmap, primary_bitmap, k); + err = grib_set_double_array_internal(grib_handle_of_accessor(this), 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); + err = grib_set_double_array_internal(grib_handle_of_accessor(this), secondary_bitmap_, secondary_bitmap, m); - grib_context_free(a->context, primary_bitmap); - grib_context_free(a->context, secondary_bitmap); + grib_context_free(context_, primary_bitmap); + grib_context_free(context_, secondary_bitmap); if (err == GRIB_SUCCESS) - err = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_values, *len * expand_by); + err = grib_set_long_internal(grib_handle_of_accessor(this), number_of_values_, *len * expand_by); return err; } diff --git a/src/accessor/grib_accessor_class_data_g2secondary_bitmap.h b/src/accessor/grib_accessor_class_data_g2secondary_bitmap.h index f981e1e6c..85c441891 100644 --- a/src/accessor/grib_accessor_class_data_g2secondary_bitmap.h +++ b/src/accessor/grib_accessor_class_data_g2secondary_bitmap.h @@ -15,16 +15,13 @@ 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_data_g2secondary_bitmap_t() : + grib_accessor_data_secondary_bitmap_t() { class_name_ = "data_g2secondary_bitmap"; } 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; + int pack_double(const double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* number_of_values_; }; diff --git a/src/accessor/grib_accessor_class_data_g2shsimple_packing.cc b/src/accessor/grib_accessor_class_data_g2shsimple_packing.cc index 5dde644fa..9e90ef67e 100644 --- a/src/accessor/grib_accessor_class_data_g2shsimple_packing.cc +++ b/src/accessor/grib_accessor_class_data_g2shsimple_packing.cc @@ -10,38 +10,34 @@ #include "grib_accessor_class_data_g2shsimple_packing.h" -grib_accessor_class_data_g2shsimple_packing_t _grib_accessor_class_data_g2shsimple_packing{ "data_g2shsimple_packing" }; -grib_accessor_class* grib_accessor_class_data_g2shsimple_packing = &_grib_accessor_class_data_g2shsimple_packing; +grib_accessor_data_g2shsimple_packing_t _grib_accessor_data_g2shsimple_packing{}; +grib_accessor* grib_accessor_data_g2shsimple_packing = &_grib_accessor_data_g2shsimple_packing; - -void grib_accessor_class_data_g2shsimple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_g2shsimple_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_shsimple_packing_t::init(a, v, args); - grib_accessor_data_g2shsimple_packing_t* self = (grib_accessor_data_g2shsimple_packing_t*)a; + grib_accessor_data_shsimple_packing_t::init(v, args); - self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), args, 2); - self->numberOfDataPoints = grib_arguments_get_name(grib_handle_of_accessor(a), args, 3); - a->flags |= GRIB_ACCESSOR_FLAG_DATA; + numberOfValues_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, 2); + numberOfDataPoints_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, 3); + flags_ |= GRIB_ACCESSOR_FLAG_DATA; } -int grib_accessor_class_data_g2shsimple_packing_t::value_count(grib_accessor* a, long* len) +int grib_accessor_data_g2shsimple_packing_t::value_count(long* len) { - grib_accessor_data_g2shsimple_packing_t* self = (grib_accessor_data_g2shsimple_packing_t*)a; - *len = 0; - return grib_get_long(grib_handle_of_accessor(a), self->numberOfValues, len); + *len = 0; + return grib_get_long(grib_handle_of_accessor(this), numberOfValues_, len); } -int grib_accessor_class_data_g2shsimple_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_g2shsimple_packing_t::unpack_double(double* val, size_t* len) { - grib_accessor_data_g2shsimple_packing_t* self = (grib_accessor_data_g2shsimple_packing_t*)a; - int err = GRIB_SUCCESS; + int err = GRIB_SUCCESS; size_t n_vals = 0; - if ((err = grib_get_size(grib_handle_of_accessor(a), self->coded_values, &n_vals)) != GRIB_SUCCESS) + if ((err = grib_get_size(grib_handle_of_accessor(this), coded_values_, &n_vals)) != GRIB_SUCCESS) return err; - self->dirty = 0; + dirty_ = 0; /* n_vals = coded_n_vals+1; */ @@ -50,12 +46,12 @@ int grib_accessor_class_data_g2shsimple_packing_t::unpack_double(grib_accessor* return GRIB_ARRAY_TOO_SMALL; } - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->real_part, val)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(grib_handle_of_accessor(this), real_part_, val)) != GRIB_SUCCESS) return err; val++; - if ((err = grib_get_double_array_internal(grib_handle_of_accessor(a), self->coded_values, val, &n_vals)) != GRIB_SUCCESS) + if ((err = grib_get_double_array_internal(grib_handle_of_accessor(this), coded_values_, val, &n_vals)) != GRIB_SUCCESS) return err; *len = n_vals; @@ -63,10 +59,9 @@ int grib_accessor_class_data_g2shsimple_packing_t::unpack_double(grib_accessor* return err; } -int grib_accessor_class_data_g2shsimple_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_g2shsimple_packing_t::pack_double(const double* val, size_t* len) { - grib_accessor_data_g2shsimple_packing_t* self = (grib_accessor_data_g2shsimple_packing_t*)a; - int err = GRIB_SUCCESS; + int err = GRIB_SUCCESS; size_t coded_n_vals = *len - 1; size_t n_vals = *len; @@ -74,21 +69,21 @@ int grib_accessor_class_data_g2shsimple_packing_t::pack_double(grib_accessor* a, if (*len == 0) return GRIB_NO_VALUES; - self->dirty = 1; + dirty_ = 1; - if ((err = grib_set_double_internal(grib_handle_of_accessor(a), self->real_part, *val)) != GRIB_SUCCESS) + if ((err = grib_set_double_internal(grib_handle_of_accessor(this), real_part_, *val)) != GRIB_SUCCESS) return err; val++; - if ((err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->coded_values, val, coded_n_vals)) != GRIB_SUCCESS) + if ((err = grib_set_double_array_internal(grib_handle_of_accessor(this), coded_values_, val, coded_n_vals)) != GRIB_SUCCESS) return err; *len = n_vals; - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->numberOfValues, (long)n_vals)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), numberOfValues_, (long)n_vals)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->numberOfDataPoints, (long)n_vals)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), numberOfDataPoints_, (long)n_vals)) != GRIB_SUCCESS) return err; return err; diff --git a/src/accessor/grib_accessor_class_data_g2shsimple_packing.h b/src/accessor/grib_accessor_class_data_g2shsimple_packing.h index 02da8345e..9b24febca 100644 --- a/src/accessor/grib_accessor_class_data_g2shsimple_packing.h +++ b/src/accessor/grib_accessor_class_data_g2shsimple_packing.h @@ -15,18 +15,15 @@ class grib_accessor_data_g2shsimple_packing_t : public grib_accessor_data_shsimple_packing_t { public: - /* Members defined in data_g2shsimple_packing */ - const char* numberOfValues; - const char* numberOfDataPoints; -}; - -class grib_accessor_class_data_g2shsimple_packing_t : public grib_accessor_class_data_shsimple_packing_t -{ -public: - grib_accessor_class_data_g2shsimple_packing_t(const char* name) : grib_accessor_class_data_shsimple_packing_t(name) {} + grib_accessor_data_g2shsimple_packing_t() : + grib_accessor_data_shsimple_packing_t() { class_name_ = "data_g2shsimple_packing"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g2shsimple_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; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* numberOfValues_; + const char* numberOfDataPoints_; }; diff --git a/src/accessor/grib_accessor_class_data_g2simple_packing.cc b/src/accessor/grib_accessor_class_data_g2simple_packing.cc index c4491e82f..4c167e0cf 100644 --- a/src/accessor/grib_accessor_class_data_g2simple_packing.cc +++ b/src/accessor/grib_accessor_class_data_g2simple_packing.cc @@ -11,29 +11,25 @@ #include "grib_accessor_class_data_g2simple_packing.h" #include "grib_scaling.h" -grib_accessor_class_data_g2simple_packing_t _grib_accessor_class_data_g2simple_packing{ "data_g2simple_packing" }; -grib_accessor_class* grib_accessor_class_data_g2simple_packing = &_grib_accessor_class_data_g2simple_packing; +grib_accessor_data_g2simple_packing_t _grib_accessor_data_g2simple_packing{}; +grib_accessor* grib_accessor_data_g2simple_packing = &_grib_accessor_data_g2simple_packing; - -void grib_accessor_class_data_g2simple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_g2simple_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_simple_packing_t::init(a, v, args); - grib_accessor_data_g2simple_packing_t* self = (grib_accessor_data_g2simple_packing_t*)a; - a->flags |= GRIB_ACCESSOR_FLAG_DATA; - self->edition = 2; + grib_accessor_data_simple_packing_t::init(v, args); + flags_ |= GRIB_ACCESSOR_FLAG_DATA; + edition_ = 2; } -int grib_accessor_class_data_g2simple_packing_t::value_count(grib_accessor* a, long* n_vals) +int grib_accessor_data_g2simple_packing_t::value_count(long* n_vals) { - grib_accessor_data_g2simple_packing_t* self = (grib_accessor_data_g2simple_packing_t*)a; - *n_vals = 0; - return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals); + *n_vals = 0; + return grib_get_long_internal(grib_handle_of_accessor(this), number_of_values_, n_vals); } -int grib_accessor_class_data_g2simple_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len) +int grib_accessor_data_g2simple_packing_t::pack_double(const double* cval, size_t* len) { - grib_accessor_data_g2simple_packing_t* self = (grib_accessor_data_g2simple_packing_t*)a; - // grib_accessor_class* super = *(a->cclass->super); + // grib_accessor* super = *(cclass_ ->super); size_t n_vals = *len; double reference_value = 0; long binary_scale_factor = 0; @@ -50,27 +46,27 @@ int grib_accessor_class_data_g2simple_packing_t::pack_double(grib_accessor* a, c double units_bias = 0.0; double* val = (double*)cval; int i; - grib_context* c = a->context; + grib_context* c = context_; if (*len == 0) { - grib_buffer_replace(a, NULL, 0, 1, 1); + grib_buffer_replace(this, NULL, 0, 1, 1); return GRIB_SUCCESS; } if (ret == GRIB_SUCCESS) - ret = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_values, *len); + ret = grib_set_long_internal(grib_handle_of_accessor(this), number_of_values_, *len); if (ret != GRIB_SUCCESS) return ret; - if (self->units_factor && - (grib_get_double_internal(grib_handle_of_accessor(a), self->units_factor, &units_factor) == GRIB_SUCCESS)) { - grib_set_double_internal(grib_handle_of_accessor(a), self->units_factor, 1.0); + if (units_factor_ && + (grib_get_double_internal(grib_handle_of_accessor(this), units_factor_, &units_factor) == GRIB_SUCCESS)) { + grib_set_double_internal(grib_handle_of_accessor(this), units_factor_, 1.0); } - if (self->units_bias && - (grib_get_double_internal(grib_handle_of_accessor(a), self->units_bias, &units_bias) == GRIB_SUCCESS)) { - grib_set_double_internal(grib_handle_of_accessor(a), self->units_bias, 0.0); + if (units_bias_ && + (grib_get_double_internal(grib_handle_of_accessor(this), units_bias_, &units_bias) == GRIB_SUCCESS)) { + grib_set_double_internal(grib_handle_of_accessor(this), units_bias_, 0.0); } if (units_factor != 1.0) { @@ -93,7 +89,7 @@ int grib_accessor_class_data_g2simple_packing_t::pack_double(grib_accessor* a, c /* IEEE packing */ if (c->ieee_packing) { - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); long precision = 0; /* Either 1(=32 bits) or 2(=64 bits) */ size_t lenstr = 10; if ((ret = codes_check_grib_ieee_packing_value(c->ieee_packing)) != GRIB_SUCCESS) @@ -107,52 +103,52 @@ int grib_accessor_class_data_g2simple_packing_t::pack_double(grib_accessor* a, c return grib_set_double_array(h, "values", val, *len); } - ret = grib_accessor_class_data_simple_packing_t::pack_double(a, cval, len); + ret = grib_accessor_data_simple_packing_t::pack_double(cval, len); switch (ret) { case GRIB_CONSTANT_FIELD: - grib_buffer_replace(a, NULL, 0, 1, 1); + grib_buffer_replace(this, NULL, 0, 1, 1); return GRIB_SUCCESS; case GRIB_SUCCESS: break; default: - grib_context_log(a->context, GRIB_LOG_ERROR, "GRIB2 simple packing: unable to set values (%s)", grib_get_error_message(ret)); + grib_context_log(context_, GRIB_LOG_ERROR, "GRIB2 simple packing: unable to set values (%s)", grib_get_error_message(ret)); return ret; } - if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(grib_handle_of_accessor(this), reference_value_, &reference_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; decimal = codes_power(decimal_scale_factor, 10); divisor = codes_power(-binary_scale_factor, 2); buflen = (((bits_per_value * n_vals) + 7) / 8) * sizeof(unsigned char); - buf = (unsigned char*)grib_context_buffer_malloc_clear(a->context, buflen); + buf = (unsigned char*)grib_context_buffer_malloc_clear(context_, buflen); encoded = buf; 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_g2simple_packing_t : pack_double : packing %s, %d values", a->name, n_vals); + grib_context_log(context_, GRIB_LOG_DEBUG, + "grib_accessor_data_g2simple_packing_t : pack_double : packing %s, %d values", name_, n_vals); - grib_buffer_replace(a, buf, buflen, 1, 1); + grib_buffer_replace(this, buf, buflen, 1, 1); - grib_context_buffer_free(a->context, buf); + grib_context_buffer_free(context_, buf); return ret; } -int grib_accessor_class_data_g2simple_packing_t::pack_bytes(grib_accessor* a, const unsigned char* val, size_t* len) +int grib_accessor_data_g2simple_packing_t::pack_bytes(const unsigned char* val, size_t* len) { size_t length = *len; - grib_buffer_replace(a, val, length, 1, 1); + grib_buffer_replace(this, val, length, 1, 1); return GRIB_SUCCESS; } diff --git a/src/accessor/grib_accessor_class_data_g2simple_packing.h b/src/accessor/grib_accessor_class_data_g2simple_packing.h index a88cccac0..3c3a445ef 100644 --- a/src/accessor/grib_accessor_class_data_g2simple_packing.h +++ b/src/accessor/grib_accessor_class_data_g2simple_packing.h @@ -12,15 +12,14 @@ #include "grib_accessor_class_data_simple_packing.h" -class grib_accessor_data_g2simple_packing_t : public grib_accessor_data_simple_packing_t {}; - -class grib_accessor_class_data_g2simple_packing_t : public grib_accessor_class_data_simple_packing_t +class grib_accessor_data_g2simple_packing_t : public grib_accessor_data_simple_packing_t { public: - grib_accessor_class_data_g2simple_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {} + grib_accessor_data_g2simple_packing_t() : + grib_accessor_data_simple_packing_t() { class_name_ = "data_g2simple_packing"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g2simple_packing_t{}; } - int pack_bytes(grib_accessor*, const unsigned char*, size_t* len) override; - 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; + int pack_bytes(const unsigned char*, size_t* len) override; + int pack_double(const double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc b/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc index fc87df231..62188cdf9 100644 --- a/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc +++ b/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.cc @@ -13,25 +13,22 @@ #define DIRECT 0 #define INVERSE 1 -grib_accessor_class_data_g2simple_packing_with_preprocessing_t _grib_accessor_class_data_g2simple_packing_with_preprocessing{ "data_g2simple_packing_with_preprocessing" }; -grib_accessor_class* grib_accessor_class_data_g2simple_packing_with_preprocessing = &_grib_accessor_class_data_g2simple_packing_with_preprocessing; +grib_accessor_data_g2simple_packing_with_preprocessing_t _grib_accessor_data_g2simple_packing_with_preprocessing{}; +grib_accessor* grib_accessor_data_g2simple_packing_with_preprocessing = &_grib_accessor_data_g2simple_packing_with_preprocessing; - -void grib_accessor_class_data_g2simple_packing_with_preprocessing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_g2simple_packing_with_preprocessing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_g2simple_packing_t::init(a, v, args); - grib_accessor_data_g2simple_packing_with_preprocessing_t* self = (grib_accessor_data_g2simple_packing_with_preprocessing_t*)a; - self->pre_processing = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); - self->pre_processing_parameter = grib_arguments_get_name(grib_handle_of_accessor(a), args, self->carg++); - a->flags |= GRIB_ACCESSOR_FLAG_DATA; + grib_accessor_data_g2simple_packing_t::init(v, args); + pre_processing_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); + pre_processing_parameter_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); + flags_ |= GRIB_ACCESSOR_FLAG_DATA; } -int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::value_count(grib_accessor* a, long* n_vals) +int grib_accessor_data_g2simple_packing_with_preprocessing_t::value_count(long* n_vals) { - grib_accessor_data_g2simple_packing_with_preprocessing_t* self = (grib_accessor_data_g2simple_packing_with_preprocessing_t*)a; *n_vals = 0; - return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals); + return grib_get_long_internal(grib_handle_of_accessor(this), number_of_values_, n_vals); } static int pre_processing_func(double* values, long length, long pre_processing, @@ -98,10 +95,8 @@ static int pre_processing_func(double* values, long length, long pre_processing, return ret; } -int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_g2simple_packing_with_preprocessing_t::unpack_double(double* val, size_t* len) { - grib_accessor_data_g2simple_packing_with_preprocessing_t* self = (grib_accessor_data_g2simple_packing_with_preprocessing_t*)a; - size_t n_vals = 0; long nn = 0; int err = 0; @@ -109,7 +104,7 @@ int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::unpack_doubl long pre_processing; double pre_processing_parameter; - err = a->value_count(&nn); + err = value_count(&nn); n_vals = nn; if (err) return err; @@ -119,17 +114,17 @@ int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::unpack_doubl return GRIB_SUCCESS; } - self->dirty = 0; + dirty_ = 0; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->pre_processing, &pre_processing)) != GRIB_SUCCESS) { + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), pre_processing_, &pre_processing)) != GRIB_SUCCESS) { return err; } - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->pre_processing_parameter, &pre_processing_parameter)) != GRIB_SUCCESS) { + if ((err = grib_get_double_internal(grib_handle_of_accessor(this), pre_processing_parameter_, &pre_processing_parameter)) != GRIB_SUCCESS) { return err; } - err = grib_accessor_class_data_simple_packing_t::unpack_double(a, val, &n_vals); + err = grib_accessor_data_simple_packing_t::unpack_double(val, &n_vals); if (err != GRIB_SUCCESS) return err; @@ -142,33 +137,31 @@ int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::unpack_doubl return err; } -int grib_accessor_class_data_g2simple_packing_with_preprocessing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_g2simple_packing_with_preprocessing_t::pack_double(const double* val, size_t* len) { - grib_accessor_data_g2simple_packing_with_preprocessing_t* self = (grib_accessor_data_g2simple_packing_with_preprocessing_t*)a; - size_t n_vals = *len; int err = 0; long pre_processing = 0; double pre_processing_parameter = 0; - self->dirty = 1; + dirty_ = 1; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->pre_processing, &pre_processing)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), pre_processing_, &pre_processing)) != GRIB_SUCCESS) return err; err = pre_processing_func((double*)val, n_vals, pre_processing, &pre_processing_parameter, DIRECT); if (err != GRIB_SUCCESS) return err; - err = grib_accessor_class_data_g2simple_packing_t::pack_double(a, val, len); + err = grib_accessor_data_g2simple_packing_t::pack_double(val, len); if (err != GRIB_SUCCESS) return err; - if ((err = grib_set_double_internal(grib_handle_of_accessor(a), self->pre_processing_parameter, pre_processing_parameter)) != GRIB_SUCCESS) + if ((err = grib_set_double_internal(grib_handle_of_accessor(this), pre_processing_parameter_, pre_processing_parameter)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), number_of_values_, n_vals)) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.h b/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.h index 4e2437e8b..e1f8c5e99 100644 --- a/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.h +++ b/src/accessor/grib_accessor_class_data_g2simple_packing_with_preprocessing.h @@ -15,18 +15,15 @@ class grib_accessor_data_g2simple_packing_with_preprocessing_t : public grib_accessor_data_g2simple_packing_t { public: - /* Members defined in data_g2simple_packing_with_preprocessing */ - const char* pre_processing; - const char* pre_processing_parameter; -}; - -class grib_accessor_class_data_g2simple_packing_with_preprocessing_t : public grib_accessor_class_data_g2simple_packing_t -{ -public: - grib_accessor_class_data_g2simple_packing_with_preprocessing_t(const char* name) : grib_accessor_class_data_g2simple_packing_t(name) {} + grib_accessor_data_g2simple_packing_with_preprocessing_t() : + grib_accessor_data_g2simple_packing_t() { class_name_ = "data_g2simple_packing_with_preprocessing"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_data_g2simple_packing_with_preprocessing_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; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* pre_processing_; + const char* pre_processing_parameter_; }; diff --git a/src/accessor/grib_accessor_class_data_jpeg2000_packing.cc b/src/accessor/grib_accessor_class_data_jpeg2000_packing.cc index 1860737d1..65893b8f1 100644 --- a/src/accessor/grib_accessor_class_data_jpeg2000_packing.cc +++ b/src/accessor/grib_accessor_class_data_jpeg2000_packing.cc @@ -10,50 +10,48 @@ #include "grib_accessor_class_data_jpeg2000_packing.h" -grib_accessor_class_data_jpeg2000_packing_t _grib_accessor_class_data_jpeg2000_packing{ "data_jpeg2000_packing" }; -grib_accessor_class* grib_accessor_class_data_jpeg2000_packing = &_grib_accessor_class_data_jpeg2000_packing; - +grib_accessor_data_jpeg2000_packing_t _grib_accessor_data_jpeg2000_packing{}; +grib_accessor* grib_accessor_data_jpeg2000_packing = &_grib_accessor_data_jpeg2000_packing; static int first = 1; #define JASPER_LIB 1 #define OPENJPEG_LIB 2 -void grib_accessor_class_data_jpeg2000_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_jpeg2000_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_simple_packing_t::init(a, v, args); - const char* user_lib = NULL; - grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_accessor_data_simple_packing_t::init(v, args); + const char* user_lib = NULL; + grib_handle* hand = grib_handle_of_accessor(this); - self->jpeg_lib = 0; - self->type_of_compression_used = grib_arguments_get_name(hand, args, self->carg++); - self->target_compression_ratio = grib_arguments_get_name(hand, args, self->carg++); - self->ni = grib_arguments_get_name(hand, args, self->carg++); - self->nj = grib_arguments_get_name(hand, args, self->carg++); - self->list_defining_points = grib_arguments_get_name(hand, args, self->carg++); - self->number_of_data_points = grib_arguments_get_name(hand, args, self->carg++); - self->scanning_mode = grib_arguments_get_name(hand, args, self->carg++); - self->edition = 2; - a->flags |= GRIB_ACCESSOR_FLAG_DATA; + jpeg_lib_ = 0; + type_of_compression_used_ = grib_arguments_get_name(hand, args, carg_++); + target_compression_ratio_ = grib_arguments_get_name(hand, args, carg_++); + ni_ = grib_arguments_get_name(hand, args, carg_++); + nj_ = grib_arguments_get_name(hand, args, carg_++); + list_defining_points_ = grib_arguments_get_name(hand, args, carg_++); + number_of_data_points_ = grib_arguments_get_name(hand, args, carg_++); + scanning_mode_ = grib_arguments_get_name(hand, args, carg_++); + edition_ = 2; + flags_ |= GRIB_ACCESSOR_FLAG_DATA; #if HAVE_LIBJASPER - self->jpeg_lib = JASPER_LIB; + jpeg_lib_ = JASPER_LIB; #elif HAVE_LIBOPENJPEG - self->jpeg_lib = OPENJPEG_LIB; + jpeg_lib_ = OPENJPEG_LIB; #endif if ((user_lib = codes_getenv("ECCODES_GRIB_JPEG")) != NULL) { if (!strcmp(user_lib, "jasper")) { - self->jpeg_lib = JASPER_LIB; + jpeg_lib_ = JASPER_LIB; } else if (!strcmp(user_lib, "openjpeg")) { - self->jpeg_lib = OPENJPEG_LIB; + jpeg_lib_ = OPENJPEG_LIB; } } - if (a->context->debug) { - switch (self->jpeg_lib) { + if (context_->debug) { + switch (jpeg_lib_) { case 0: fprintf(stderr, "ECCODES DEBUG jpeg2000_packing: jpeg_lib not set!\n"); break; @@ -69,38 +67,35 @@ void grib_accessor_class_data_jpeg2000_packing_t::init(grib_accessor* a, const l } } - self->dump_jpg = codes_getenv("ECCODES_GRIB_DUMP_JPG_FILE"); - if (self->dump_jpg) { + dump_jpg_ = codes_getenv("ECCODES_GRIB_DUMP_JPG_FILE"); + if (dump_jpg_) { if (first) { - printf("GRIB JPEG dumping to %s\n", self->dump_jpg); + printf("GRIB JPEG dumping to %s\n", dump_jpg_); first = 0; } } } -int grib_accessor_class_data_jpeg2000_packing_t::value_count(grib_accessor* a, long* n_vals) +int grib_accessor_data_jpeg2000_packing_t::value_count(long* n_vals) { - grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a; - *n_vals = 0; + *n_vals = 0; - return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals); + return grib_get_long_internal(grib_handle_of_accessor(this), number_of_values_, n_vals); } #define EXTRA_BUFFER_SIZE 10240 #if HAVE_JPEG -int grib_accessor_class_data_jpeg2000_packing_t::unpack_float(grib_accessor*, float* val, size_t* len) +int grib_accessor_data_jpeg2000_packing_t::unpack_float(float* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_data_jpeg2000_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_jpeg2000_packing_t::unpack_double(double* val, size_t* len) { - grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a; - int err = GRIB_SUCCESS; size_t i = 0; - size_t buflen = a->byte_count(); + size_t buflen = byte_count(); double bscale = 0; double dscale = 0; unsigned char* buf = NULL; @@ -115,28 +110,27 @@ int grib_accessor_class_data_jpeg2000_packing_t::unpack_double(grib_accessor* a, double units_bias = 0.0; n_vals = 0; - err = a->value_count(&nn); + err = value_count(&nn); n_vals = nn; if (err) return err; - if (self->units_factor) - grib_get_double_internal(grib_handle_of_accessor(a), self->units_factor, &units_factor); + if (units_factor_) + grib_get_double_internal(grib_handle_of_accessor(this), units_factor_, &units_factor); - if (self->units_bias) - grib_get_double_internal(grib_handle_of_accessor(a), self->units_bias, &units_bias); + if (units_bias_) + grib_get_double_internal(grib_handle_of_accessor(this), units_bias_, &units_bias); - - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(grib_handle_of_accessor(this), reference_value_, &reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; - self->dirty = 0; + dirty_ = 0; bscale = codes_power(binary_scale_factor, 2); dscale = codes_power(-decimal_scale_factor, 10); @@ -154,19 +148,19 @@ int grib_accessor_class_data_jpeg2000_packing_t::unpack_double(grib_accessor* a, return GRIB_SUCCESS; } - buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; - buf += a->byte_offset(); - switch (self->jpeg_lib) { + buf = (unsigned char*)grib_handle_of_accessor(this)->buffer->data; + buf += byte_offset(); + switch (jpeg_lib_) { case OPENJPEG_LIB: - if ((err = grib_openjpeg_decode(a->context, buf, &buflen, val, &n_vals)) != GRIB_SUCCESS) + if ((err = grib_openjpeg_decode(context_, buf, &buflen, val, &n_vals)) != GRIB_SUCCESS) return err; break; case JASPER_LIB: - if ((err = grib_jasper_decode(a->context, buf, &buflen, val, &n_vals)) != GRIB_SUCCESS) + if ((err = grib_jasper_decode(context_, buf, &buflen, val, &n_vals)) != GRIB_SUCCESS) return err; break; default: - grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to unpack. Invalid JPEG library.\n"); + grib_context_log(context_, GRIB_LOG_ERROR, "Unable to unpack. Invalid JPEG library.\n"); return GRIB_DECODING_ERROR; } @@ -196,11 +190,10 @@ int grib_accessor_class_data_jpeg2000_packing_t::unpack_double(grib_accessor* a, return err; } -int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, const double* cval, size_t* len) +int grib_accessor_data_jpeg2000_packing_t::pack_double(const double* cval, size_t* len) { - grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a; - size_t n_vals = *len; - int err = 0; + size_t n_vals = *len; + int err = 0; int i; double reference_value = 0; long binary_scale_factor = 0; @@ -224,23 +217,23 @@ int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, c double units_factor = 1.0; double units_bias = 0.0; double* val = (double*)cval; - const char* cclass_name = a->cclass->name; + const char* cclass_name = class_name_; - self->dirty = 1; + dirty_ = 1; if (*len == 0) { - grib_buffer_replace(a, NULL, 0, 1, 1); + grib_buffer_replace(this, NULL, 0, 1, 1); return GRIB_SUCCESS; } - if (self->units_factor && - (grib_get_double_internal(grib_handle_of_accessor(a), self->units_factor, &units_factor) == GRIB_SUCCESS)) { - grib_set_double_internal(grib_handle_of_accessor(a), self->units_factor, 1.0); + if (units_factor_ && + (grib_get_double_internal(grib_handle_of_accessor(this), units_factor_, &units_factor) == GRIB_SUCCESS)) { + grib_set_double_internal(grib_handle_of_accessor(this), units_factor_, 1.0); } - if (self->units_bias && - (grib_get_double_internal(grib_handle_of_accessor(a), self->units_bias, &units_bias) == GRIB_SUCCESS)) { - grib_set_double_internal(grib_handle_of_accessor(a), self->units_bias, 0.0); + if (units_bias_ && + (grib_get_double_internal(grib_handle_of_accessor(this), units_bias_, &units_bias) == GRIB_SUCCESS)) { + grib_set_double_internal(grib_handle_of_accessor(this), units_bias_, 0.0); } if (units_factor != 1.0) { @@ -255,56 +248,56 @@ int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, c for (i = 0; i < n_vals; i++) val[i] += units_bias; - ret = grib_accessor_class_data_simple_packing_t::pack_double(a, val, len); + ret = grib_accessor_data_simple_packing_t::pack_double(val, len); switch (ret) { case GRIB_CONSTANT_FIELD: - grib_buffer_replace(a, NULL, 0, 1, 1); - err = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_values, *len); + grib_buffer_replace(this, NULL, 0, 1, 1); + err = grib_set_long_internal(grib_handle_of_accessor(this), number_of_values_, *len); return err; case GRIB_SUCCESS: break; default: - grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: Unable to compute packing parameters", cclass_name, __func__); + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: Unable to compute packing parameters", cclass_name, __func__); return ret; } - if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(grib_handle_of_accessor(this), reference_value_, &reference_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; decimal = codes_power(decimal_scale_factor, 10); divisor = codes_power(-binary_scale_factor, 2); simple_packing_size = (((bits_per_value * n_vals) + 7) / 8) * sizeof(unsigned char); - buf = (unsigned char*)grib_context_malloc_clear(a->context, simple_packing_size + EXTRA_BUFFER_SIZE); + buf = (unsigned char*)grib_context_malloc_clear(context_, simple_packing_size + EXTRA_BUFFER_SIZE); if (!buf) { err = GRIB_OUT_OF_MEMORY; goto cleanup; } - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->ni, &ni)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), ni_, &ni)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->nj, &nj)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), nj_, &nj)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->type_of_compression_used, &type_of_compression_used)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), type_of_compression_used_, &type_of_compression_used)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->target_compression_ratio, &target_compression_ratio)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), target_compression_ratio_, &target_compression_ratio)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->scanning_mode, &scanning_mode)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), scanning_mode_, &scanning_mode)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->list_defining_points, &list_defining_points)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), list_defining_points_, &list_defining_points)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_data_points, &number_of_data_points)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), number_of_data_points_, &number_of_data_points)) != GRIB_SUCCESS) return err; width = ni; @@ -329,7 +322,7 @@ int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, c } if (width * height != *len) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: width=%ld height=%ld len=%zu. width*height should equal len!", cclass_name, __func__, width, height, *len); /* ECC-802: We cannot bomb out here as the user might have changed Ni/Nj and the packingType @@ -337,16 +330,16 @@ int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, c * So issue a warning but proceed. */ /*return GRIB_INTERNAL_ERROR;*/ - grib_context_free(a->context, buf); + grib_context_free(context_, buf); return GRIB_SUCCESS; } switch (type_of_compression_used) { case 0: // Lossless if (target_compression_ratio != 255) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: When %s=0 (Lossless), %s must be set to 255", - cclass_name, __func__, self->type_of_compression_used, self->target_compression_ratio); + cclass_name, __func__, type_of_compression_used, target_compression_ratio_); return GRIB_ENCODING_ERROR; } helper.compression = 0; @@ -354,9 +347,9 @@ int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, c case 1: // Lossy if (target_compression_ratio == 255 || target_compression_ratio == 0) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: When %s=1 (Lossy), %s must be specified", - cclass_name, __func__, self->type_of_compression_used, self->target_compression_ratio); + cclass_name, __func__, type_of_compression_used, target_compression_ratio_); return GRIB_ENCODING_ERROR; } Assert(target_compression_ratio != 255); @@ -376,9 +369,9 @@ int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, c /* See GRIB-438 */ if (bits_per_value == 0) { const long bits_per_value_adjusted = 1; - grib_context_log(a->context, GRIB_LOG_DEBUG, + grib_context_log(context_, GRIB_LOG_DEBUG, "%s (%s) : bits per value was zero, changed to %ld", - cclass_name, self->jpeg_lib == OPENJPEG_LIB ? "openjpeg" : "jasper", bits_per_value_adjusted); + cclass_name, jpeg_lib_ == OPENJPEG_LIB ? "openjpeg" : "jasper", bits_per_value_adjusted); bits_per_value = bits_per_value_adjusted; } helper.bits_per_value = bits_per_value; @@ -391,45 +384,45 @@ int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, c helper.decimal = decimal; helper.jpeg_length = 0; - switch (self->jpeg_lib) { + switch (jpeg_lib_) { case OPENJPEG_LIB: - if ((err = grib_openjpeg_encode(a->context, &helper)) != GRIB_SUCCESS) + if ((err = grib_openjpeg_encode(context_, &helper)) != GRIB_SUCCESS) goto cleanup; break; case JASPER_LIB: - if ((err = grib_jasper_encode(a->context, &helper)) != GRIB_SUCCESS) + if ((err = grib_jasper_encode(context_, &helper)) != GRIB_SUCCESS) goto cleanup; break; } if (helper.jpeg_length > simple_packing_size) - grib_context_log(a->context, GRIB_LOG_WARNING, + grib_context_log(context_, GRIB_LOG_WARNING, "%s (%s) : jpeg data (%ld) larger than input data (%ld)", - cclass_name, self->jpeg_lib == OPENJPEG_LIB ? "openjpeg" : "jasper", + cclass_name, jpeg_lib_ == OPENJPEG_LIB ? "openjpeg" : "jasper", helper.jpeg_length, simple_packing_size); Assert(helper.jpeg_length <= helper.buffer_size); - if (self->dump_jpg) { - FILE* f = fopen(self->dump_jpg, "w"); + if (dump_jpg_) { + FILE* f = fopen(dump_jpg_, "w"); if (f) { if (fwrite(helper.jpeg_buffer, helper.jpeg_length, 1, f) != 1) - perror(self->dump_jpg); + perror(dump_jpg_); if (fclose(f) != 0) - perror(self->dump_jpg); + perror(dump_jpg_); } else - perror(self->dump_jpg); + perror(dump_jpg_); } - grib_buffer_replace(a, helper.jpeg_buffer, helper.jpeg_length, 1, 1); + grib_buffer_replace(this, helper.jpeg_buffer, helper.jpeg_length, 1, 1); cleanup: - grib_context_free(a->context, buf); + grib_context_free(context_, buf); if (err == GRIB_SUCCESS) - err = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_values, *len); + err = grib_set_long_internal(grib_handle_of_accessor(this), number_of_values_, *len); return err; } #else @@ -439,38 +432,37 @@ static void print_error_feature_not_enabled(grib_context* c) grib_context_log(c, GRIB_LOG_ERROR, "JPEG support not enabled. Please rebuild with -DENABLE_JPG=ON"); } -int grib_accessor_class_data_jpeg2000_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_data_jpeg2000_packing_t::unpack_float(float* val, size_t* len) { - print_error_feature_not_enabled(a->context); + print_error_feature_not_enabled(context_); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -int grib_accessor_class_data_jpeg2000_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_jpeg2000_packing_t::unpack_double(double* val, size_t* len) { - print_error_feature_not_enabled(a->context); + print_error_feature_not_enabled(context_); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -int grib_accessor_class_data_jpeg2000_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_jpeg2000_packing_t::pack_double(const double* val, size_t* len) { - print_error_feature_not_enabled(a->context); + print_error_feature_not_enabled(context_); return GRIB_FUNCTIONALITY_NOT_ENABLED; } #endif -int grib_accessor_class_data_jpeg2000_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_data_jpeg2000_packing_t::unpack_double_element(size_t idx, double* val) { - grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - size_t size = 0; - double* values = NULL; - int err = 0; - double reference_value = 0; - long bits_per_value = 0; + grib_handle* hand = grib_handle_of_accessor(this); + size_t size = 0; + double* values = NULL; + int err = 0; + double reference_value = 0; + long bits_per_value = 0; - if ((err = grib_get_long_internal(hand, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(hand, self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(hand, reference_value_, &reference_value)) != GRIB_SUCCESS) return err; /* Special case of constant field */ @@ -486,30 +478,29 @@ int grib_accessor_class_data_jpeg2000_packing_t::unpack_double_element(grib_acce if (idx > size) return GRIB_INVALID_ARGUMENT; - values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double)); + values = (double*)grib_context_malloc_clear(context_, size * sizeof(double)); err = grib_get_double_array(hand, "codedValues", values, &size); if (err) { - grib_context_free(a->context, values); + grib_context_free(context_, values); return err; } *val = values[idx]; - grib_context_free(a->context, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } -int grib_accessor_class_data_jpeg2000_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) +int grib_accessor_data_jpeg2000_packing_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) { - grib_accessor_data_jpeg2000_packing_t* self = (grib_accessor_data_jpeg2000_packing_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); size_t size = 0, i = 0; double* values = NULL; int err = 0; double reference_value = 0; long bits_per_value = 0; - if ((err = grib_get_long_internal(hand, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(hand, self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(hand, reference_value_, &reference_value)) != GRIB_SUCCESS) return err; /* Special case of constant field */ @@ -527,15 +518,15 @@ int grib_accessor_class_data_jpeg2000_packing_t::unpack_double_element_set(grib_ if (index_array[i] > size) return GRIB_INVALID_ARGUMENT; } - values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double)); + values = (double*)grib_context_malloc_clear(context_, size * sizeof(double)); err = grib_get_double_array(hand, "codedValues", values, &size); if (err) { - grib_context_free(a->context, values); + grib_context_free(context_, values); return err; } for (i = 0; i < len; i++) { val_array[i] = values[index_array[i]]; } - grib_context_free(a->context, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } diff --git a/src/accessor/grib_accessor_class_data_jpeg2000_packing.h b/src/accessor/grib_accessor_class_data_jpeg2000_packing.h index 54dcc457c..f6b4da513 100644 --- a/src/accessor/grib_accessor_class_data_jpeg2000_packing.h +++ b/src/accessor/grib_accessor_class_data_jpeg2000_packing.h @@ -15,28 +15,25 @@ class grib_accessor_data_jpeg2000_packing_t : public grib_accessor_data_simple_packing_t { public: - /* Members defined in data_jpeg2000_packing */ - const char* type_of_compression_used; - const char* target_compression_ratio; - const char* ni; - const char* nj; - const char* list_defining_points; - const char* number_of_data_points; - const char* scanning_mode; - int jpeg_lib; - const char* dump_jpg; -}; - -class grib_accessor_class_data_jpeg2000_packing_t : public grib_accessor_class_data_simple_packing_t -{ -public: - grib_accessor_class_data_jpeg2000_packing_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {} + grib_accessor_data_jpeg2000_packing_t() : + grib_accessor_data_simple_packing_t() { class_name_ = "data_jpeg2000_packing"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_data_jpeg2000_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; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_float(float* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + int unpack_double_element(size_t i, double* val) override; + int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; + +private: + const char* type_of_compression_used_; + const char* target_compression_ratio_; + const char* ni_; + const char* nj_; + const char* list_defining_points_; + const char* number_of_data_points_; + const char* scanning_mode_; + int jpeg_lib_; + const char* dump_jpg_; }; diff --git a/src/accessor/grib_accessor_class_data_png_packing.cc b/src/accessor/grib_accessor_class_data_png_packing.cc index 999722f36..fb3d4bc58 100644 --- a/src/accessor/grib_accessor_class_data_png_packing.cc +++ b/src/accessor/grib_accessor_class_data_png_packing.cc @@ -13,34 +13,31 @@ #define PNG_ANYBITS -grib_accessor_class_data_png_packing_t _grib_accessor_class_data_png_packing{ "data_png_packing" }; -grib_accessor_class* grib_accessor_class_data_png_packing = &_grib_accessor_class_data_png_packing; +grib_accessor_data_png_packing_t _grib_accessor_data_png_packing{}; +grib_accessor* grib_accessor_data_png_packing = &_grib_accessor_data_png_packing; - -void grib_accessor_class_data_png_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_png_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_values_t::init(a, v, args); - grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_values_t::init(v, args); + grib_handle* h = grib_handle_of_accessor(this); - self->number_of_values = grib_arguments_get_name(h, args, self->carg++); - self->reference_value = grib_arguments_get_name(h, args, self->carg++); - self->binary_scale_factor = grib_arguments_get_name(h, args, self->carg++); - self->decimal_scale_factor = grib_arguments_get_name(h, args, self->carg++); - self->bits_per_value = grib_arguments_get_name(h, args, self->carg++); - self->ni = grib_arguments_get_name(h, args, self->carg++); - self->nj = grib_arguments_get_name(h, args, self->carg++); - self->list_defining_points = grib_arguments_get_name(h, args, self->carg++); - self->number_of_data_points = grib_arguments_get_name(h, args, self->carg++); - self->scanning_mode = grib_arguments_get_name(h, args, self->carg++); - a->flags |= GRIB_ACCESSOR_FLAG_DATA; + number_of_values_ = grib_arguments_get_name(h, args, carg_++); + reference_value_ = grib_arguments_get_name(h, args, carg_++); + binary_scale_factor_ = grib_arguments_get_name(h, args, carg_++); + decimal_scale_factor_ = grib_arguments_get_name(h, args, carg_++); + bits_per_value_ = grib_arguments_get_name(h, args, carg_++); + ni_ = grib_arguments_get_name(h, args, carg_++); + nj_ = grib_arguments_get_name(h, args, carg_++); + list_defining_points_ = grib_arguments_get_name(h, args, carg_++); + number_of_data_points_ = grib_arguments_get_name(h, args, carg_++); + scanning_mode_ = grib_arguments_get_name(h, args, carg_++); + flags_ |= GRIB_ACCESSOR_FLAG_DATA; } -int grib_accessor_class_data_png_packing_t::value_count(grib_accessor* a, long* n_vals) +int grib_accessor_data_png_packing_t::value_count(long* n_vals) { - grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a; - *n_vals = 0; - return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals); + *n_vals = 0; + return grib_get_long_internal(grib_handle_of_accessor(this), number_of_values_, n_vals); } #if HAVE_LIBPNG @@ -81,13 +78,11 @@ static void png_flush_callback(png_structp png) /* Empty */ } -int grib_accessor_class_data_png_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_png_packing_t::unpack_double(double* val, size_t* len) { - grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a; - int err = GRIB_SUCCESS; int i, j; - size_t buflen = a->byte_count(); + size_t buflen = byte_count(); double bscale = 0; double dscale = 0; unsigned char* buf = NULL; @@ -109,19 +104,19 @@ int grib_accessor_class_data_png_packing_t::unpack_double(grib_accessor* a, doub png_read_callback_data callback_data; - self->dirty = 0; + dirty_ = 0; - err = a->value_count(&nn); + err = value_count(&nn); n_vals = nn; if (err) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(grib_handle_of_accessor(this), reference_value_, &reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; bscale = codes_power(binary_scale_factor, 2); @@ -140,13 +135,12 @@ int grib_accessor_class_data_png_packing_t::unpack_double(grib_accessor* a, doub return GRIB_SUCCESS; } - buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; - buf += a->byte_offset(); + buf = (unsigned char*)grib_handle_of_accessor(this)->buffer->data; + buf += byte_offset(); if (png_sig_cmp(buf, 0, 8) != 0) return GRIB_INVALID_MESSAGE; - png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png) { @@ -191,7 +185,6 @@ int grib_accessor_class_data_png_packing_t::unpack_double(grib_accessor* a, doub &compression, &filter); - if (colour == PNG_COLOR_TYPE_RGB) depth = 24; if (colour == PNG_COLOR_TYPE_RGB_ALPHA) @@ -240,10 +233,9 @@ static bool is_constant(const double* values, size_t n_vals) return isConstant; } -int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_png_packing_t::pack_double(const double* val, size_t* len) { - grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a; - const char* cclass_name = a->cclass->name; + const char* cclass_name = class_name_; int err = GRIB_SUCCESS; bool is_constant_field = false; @@ -278,22 +270,22 @@ int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const long list_defining_points; long number_of_data_points; - self->dirty = 1; + dirty_ = 1; n_vals = *len; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(grib_handle_of_accessor(this), reference_value_, &reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; /* Special case */ if (*len == 0) { - grib_buffer_replace(a, NULL, 0, 1, 1); + grib_buffer_replace(this, NULL, 0, 1, 1); return GRIB_SUCCESS; } @@ -309,41 +301,41 @@ int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const Assert(val[i] == val[0]); } #endif - if ((err = grib_set_double_internal(grib_handle_of_accessor(a), self->reference_value, val[0])) != GRIB_SUCCESS) + if ((err = grib_set_double_internal(grib_handle_of_accessor(this), reference_value_, val[0])) != GRIB_SUCCESS) return err; { // Make sure we can decode it again double ref = 1e-100; - grib_get_double_internal(grib_handle_of_accessor(a), self->reference_value, &ref); + grib_get_double_internal(grib_handle_of_accessor(this), reference_value_, &ref); if (ref != reference_value) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)", - cclass_name, __func__, self->reference_value, ref, reference_value); + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)", + cclass_name, __func__, reference_value_, ref, reference_value); return GRIB_INTERNAL_ERROR; } } - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), number_of_values_, n_vals)) != GRIB_SUCCESS) return err; - grib_buffer_replace(a, NULL, 0, 1, 1); + grib_buffer_replace(this, NULL, 0, 1, 1); return GRIB_SUCCESS; } - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->ni, &ni)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), ni_, &ni)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->nj, &nj)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), nj_, &nj)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->scanning_mode, &scanning_mode)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), scanning_mode_, &scanning_mode)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->list_defining_points, &list_defining_points)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), list_defining_points_, &list_defining_points)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_data_points, &number_of_data_points)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), number_of_data_points_, &number_of_data_points)) != GRIB_SUCCESS) return err; width = ni; @@ -369,7 +361,7 @@ int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const } if (width * height != *len) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: width=%ld height=%ld len=%ld. width*height should equal len!", cclass_name, __func__, (long)width, (long)height, (long)*len); /* ECC-802: We cannot bomb out here as the user might have changed Ni/Nj and the packingType @@ -392,14 +384,14 @@ int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const min *= d; max *= d; - if (grib_get_nearest_smaller_value(grib_handle_of_accessor(a), self->reference_value, min, &reference_value) != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Unable to find nearest_smaller_value of %g for %s", min, self->reference_value); + if (grib_get_nearest_smaller_value(grib_handle_of_accessor(this), reference_value_, min, &reference_value) != GRIB_SUCCESS) { + grib_context_log(context_, GRIB_LOG_ERROR, + "Unable to find nearest_smaller_value of %g for %s", min, reference_value_); return GRIB_INTERNAL_ERROR; } if (reference_value > min) { - grib_context_log(a->context, GRIB_LOG_ERROR, "reference_value=%g min_value=%g diff=%g", + grib_context_log(context_, GRIB_LOG_ERROR, "reference_value=%g min_value=%g diff=%g", reference_value, min, reference_value - min); return GRIB_INTERNAL_ERROR; } @@ -411,7 +403,7 @@ int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const Assert(bits_per_value % 8 == 0); #endif bits8 = (bits_per_value + 7) / 8 * 8; - encoded = (unsigned char*)grib_context_buffer_malloc_clear(a->context, bits8 / 8 * n_vals); + encoded = (unsigned char*)grib_context_buffer_malloc_clear(context_, bits8 / 8 * n_vals); if (!encoded) { err = GRIB_OUT_OF_MEMORY; goto cleanup; @@ -430,38 +422,38 @@ int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const } } /* buflen = n_vals*(bits_per_value/8); */ - grib_context_log(a->context, GRIB_LOG_DEBUG, - "grib_accessor_data_png_packing_t : pack_double : packing %s, %d values", a->name, n_vals); - buf = (unsigned char*)grib_context_buffer_malloc_clear(a->context, buflen); + grib_context_log(context_, GRIB_LOG_DEBUG, + "grib_accessor_data_png_packing_t : pack_double : packing %s, %d values", name_, n_vals); + buf = (unsigned char*)grib_context_buffer_malloc_clear(context_, buflen); if (!buf) { err = GRIB_OUT_OF_MEMORY; goto cleanup; } - if ((err = grib_set_double_internal(grib_handle_of_accessor(a), self->reference_value, reference_value)) != GRIB_SUCCESS) + if ((err = grib_set_double_internal(grib_handle_of_accessor(this), reference_value_, reference_value)) != GRIB_SUCCESS) return err; { // Make sure we can decode it again double ref = 1e-100; - grib_get_double_internal(grib_handle_of_accessor(a), self->reference_value, &ref); + grib_get_double_internal(grib_handle_of_accessor(this), reference_value_, &ref); if (ref != reference_value) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)", - cclass_name, __func__, self->reference_value, ref, reference_value); + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)", + cclass_name, __func__, reference_value_, ref, reference_value); return GRIB_INTERNAL_ERROR; } } - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->binary_scale_factor, binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), binary_scale_factor_, binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor, decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), decimal_scale_factor_, decimal_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->ni, &ni)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), ni_, &ni)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->nj, &nj)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), nj_, &nj)) != GRIB_SUCCESS) return err; png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); @@ -507,7 +499,7 @@ int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const /*bytes=bit_depth/8;*/ bytes = bits8 / 8; - rows = (png_bytepp)grib_context_buffer_malloc_clear(a->context, sizeof(png_bytep) * height); + rows = (png_bytepp)grib_context_buffer_malloc_clear(context_, sizeof(png_bytep) * height); if (!rows) { err = GRIB_OUT_OF_MEMORY; goto cleanup; @@ -522,36 +514,35 @@ int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const Assert(callback_data.offset <= callback_data.length); - grib_buffer_replace(a, buf, callback_data.offset, 1, 1); + grib_buffer_replace(this, buf, callback_data.offset, 1, 1); cleanup: if (png) png_destroy_write_struct(&png, info ? &info : NULL); - grib_context_buffer_free(a->context, buf); - grib_context_buffer_free(a->context, encoded); - grib_context_buffer_free(a->context, rows); + grib_context_buffer_free(context_, buf); + grib_context_buffer_free(context_, encoded); + grib_context_buffer_free(context_, rows); if (err == GRIB_SUCCESS) - err = grib_set_long_internal(grib_handle_of_accessor(a), self->number_of_values, *len); + err = grib_set_long_internal(grib_handle_of_accessor(this), number_of_values_, *len); return err; } -int grib_accessor_class_data_png_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_data_png_packing_t::unpack_double_element(size_t idx, double* val) { /* The index idx relates to codedValues NOT values! */ - grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int err = 0; - size_t size = 0; - double reference_value = 0; - long bits_per_value = 0; - double* values = NULL; + grib_handle* hand = grib_handle_of_accessor(this); + int err = 0; + size_t size = 0; + double reference_value = 0; + long bits_per_value = 0; + double* values = NULL; - if ((err = grib_get_long_internal(hand, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(hand, self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(hand, reference_value_, &reference_value)) != GRIB_SUCCESS) return err; /* Special case of constant field */ @@ -563,31 +554,30 @@ int grib_accessor_class_data_png_packing_t::unpack_double_element(grib_accessor* if (err) return err; if (idx > size) return GRIB_INVALID_ARGUMENT; - values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double)); + values = (double*)grib_context_malloc_clear(context_, size * sizeof(double)); err = grib_get_double_array(hand, "codedValues", values, &size); if (err) { - grib_context_free(a->context, values); + grib_context_free(context_, values); return err; } *val = values[idx]; - grib_context_free(a->context, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } -int grib_accessor_class_data_png_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) +int grib_accessor_data_png_packing_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) { /* The index idx relates to codedValues NOT values! */ - grib_accessor_data_png_packing_t* self = (grib_accessor_data_png_packing_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int err = 0; + grib_handle* hand = grib_handle_of_accessor(this); + int err = 0; size_t size = 0, i = 0; double reference_value = 0; long bits_per_value = 0; double* values = NULL; - if ((err = grib_get_long_internal(hand, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(hand, self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(hand, reference_value_, &reference_value)) != GRIB_SUCCESS) return err; /* Special case of constant field */ @@ -598,7 +588,7 @@ int grib_accessor_class_data_png_packing_t::unpack_double_element_set(grib_acces return GRIB_SUCCESS; } - err = grib_get_size(grib_handle_of_accessor(a), "codedValues", &size); + err = grib_get_size(grib_handle_of_accessor(this), "codedValues", &size); if (err) return err; @@ -606,16 +596,16 @@ int grib_accessor_class_data_png_packing_t::unpack_double_element_set(grib_acces if (index_array[i] > size) return GRIB_INVALID_ARGUMENT; } - values = (double*)grib_context_malloc_clear(a->context, size * sizeof(double)); - err = grib_get_double_array(grib_handle_of_accessor(a), "codedValues", values, &size); + values = (double*)grib_context_malloc_clear(context_, size * sizeof(double)); + err = grib_get_double_array(grib_handle_of_accessor(this), "codedValues", values, &size); if (err) { - grib_context_free(a->context, values); + grib_context_free(context_, values); return err; } for (i = 0; i < len; i++) { val_array[i] = values[index_array[i]]; } - grib_context_free(a->context, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } @@ -627,24 +617,24 @@ static void print_error_feature_not_enabled(grib_context* c) "PNG support not enabled. Please rebuild with -DENABLE_PNG=ON"); } -int grib_accessor_class_data_png_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_png_packing_t::unpack_double(double* val, size_t* len) { - print_error_feature_not_enabled(a->context); + print_error_feature_not_enabled(context_); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -int grib_accessor_class_data_png_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_png_packing_t::pack_double(const double* val, size_t* len) { - print_error_feature_not_enabled(a->context); + print_error_feature_not_enabled(context_); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -int grib_accessor_class_data_png_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_data_png_packing_t::unpack_double_element(size_t idx, double* val) { - print_error_feature_not_enabled(a->context); + print_error_feature_not_enabled(context_); return GRIB_FUNCTIONALITY_NOT_ENABLED; } -int grib_accessor_class_data_png_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) +int grib_accessor_data_png_packing_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) { - print_error_feature_not_enabled(a->context); + print_error_feature_not_enabled(context_); return GRIB_FUNCTIONALITY_NOT_ENABLED; } diff --git a/src/accessor/grib_accessor_class_data_png_packing.h b/src/accessor/grib_accessor_class_data_png_packing.h index 841ed9d31..031def2ed 100644 --- a/src/accessor/grib_accessor_class_data_png_packing.h +++ b/src/accessor/grib_accessor_class_data_png_packing.h @@ -15,27 +15,25 @@ class grib_accessor_data_png_packing_t : public grib_accessor_values_t { public: - const char* number_of_values; - const char* reference_value; - const char* binary_scale_factor; - const char* decimal_scale_factor; - const char* bits_per_value; - const char* ni; - const char* nj; - const char* list_defining_points; - const char* number_of_data_points; - const char* scanning_mode; -}; - -class grib_accessor_class_data_png_packing_t : public grib_accessor_class_values_t -{ -public: - grib_accessor_class_data_png_packing_t(const char* name) : grib_accessor_class_values_t(name) {} + grib_accessor_data_png_packing_t() : + grib_accessor_values_t() { class_name_ = "data_png_packing"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_data_png_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; - 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; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + int unpack_double_element(size_t i, double* val) override; + int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; + +private: + const char* number_of_values_; + const char* reference_value_; + const char* binary_scale_factor_; + const char* decimal_scale_factor_; + const char* bits_per_value_; + const char* ni_; + const char* nj_; + const char* list_defining_points_; + const char* number_of_data_points_; + const char* scanning_mode_; }; diff --git a/src/accessor/grib_accessor_class_data_raw_packing.cc b/src/accessor/grib_accessor_class_data_raw_packing.cc index 8cf92e0a9..916029045 100644 --- a/src/accessor/grib_accessor_class_data_raw_packing.cc +++ b/src/accessor/grib_accessor_class_data_raw_packing.cc @@ -11,45 +11,41 @@ #include "grib_accessor_class_data_raw_packing.h" #include "grib_ieeefloat.h" -grib_accessor_class_data_raw_packing_t _grib_accessor_class_data_raw_packing{ "data_raw_packing" }; -grib_accessor_class* grib_accessor_class_data_raw_packing = &_grib_accessor_class_data_raw_packing; +grib_accessor_data_raw_packing_t _grib_accessor_data_raw_packing{}; +grib_accessor* grib_accessor_data_raw_packing = &_grib_accessor_data_raw_packing; - -void grib_accessor_class_data_raw_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_raw_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_values_t::init(a, v, args); - grib_accessor_data_raw_packing_t* self = (grib_accessor_data_raw_packing_t*)a; + grib_accessor_values_t::init(v, args); - self->number_of_values = 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++); - a->flags |= GRIB_ACCESSOR_FLAG_DATA; + number_of_values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); + precision_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, carg_++); + flags_ |= GRIB_ACCESSOR_FLAG_DATA; } -int grib_accessor_class_data_raw_packing_t::value_count(grib_accessor* a, long* n_vals) +int grib_accessor_data_raw_packing_t::value_count(long* n_vals) { - grib_accessor_data_raw_packing_t* self = (grib_accessor_data_raw_packing_t*)a; - *n_vals = 0; - return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, n_vals); + *n_vals = 0; + return grib_get_long_internal(grib_handle_of_accessor(this), number_of_values_, n_vals); } -int grib_accessor_class_data_raw_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_raw_packing_t::unpack_double(double* val, size_t* len) { - grib_accessor_data_raw_packing_t* self = (grib_accessor_data_raw_packing_t*)a; - unsigned char* buf = NULL; - int bytes = 0; - size_t nvals = 0; - long inlen = a->byte_count(); - long precision = 0; + unsigned char* buf = NULL; + int bytes = 0; + size_t nvals = 0; + long inlen = byte_count(); + long precision = 0; int code = GRIB_SUCCESS; - if ((code = grib_get_long(grib_handle_of_accessor(a), self->precision, &precision)) != GRIB_SUCCESS) + if ((code = grib_get_long(grib_handle_of_accessor(this), precision_, &precision)) != GRIB_SUCCESS) return code; - self->dirty = 0; + dirty_ = 0; - buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; - buf += a->byte_offset(); + buf = (unsigned char*)grib_handle_of_accessor(this)->buffer->data; + buf += byte_offset(); switch (precision) { case 1: bytes = 4; @@ -66,17 +62,15 @@ int grib_accessor_class_data_raw_packing_t::unpack_double(grib_accessor* a, doub if (*len < nvals) return GRIB_ARRAY_TOO_SMALL; - code = grib_ieee_decode_array(a->context, buf, nvals, bytes, val); + code = grib_ieee_decode_array(context_, buf, nvals, bytes, val); *len = nvals; return code; } -int grib_accessor_class_data_raw_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_raw_packing_t::pack_double(const double* val, size_t* len) { - grib_accessor_data_raw_packing_t* self = (grib_accessor_data_raw_packing_t*)a; - int bytes = 0; unsigned char* buffer = NULL; @@ -95,10 +89,10 @@ int grib_accessor_class_data_raw_packing_t::pack_double(grib_accessor* a, const if (*len == 0) return GRIB_NO_VALUES; - if ((code = grib_get_long_internal(grib_handle_of_accessor(a), self->precision, &precision)) != GRIB_SUCCESS) + if ((code = grib_get_long_internal(grib_handle_of_accessor(this), precision_, &precision)) != GRIB_SUCCESS) return code; - self->dirty = 1; + dirty_ = 1; switch (precision) { case 1: @@ -116,14 +110,14 @@ int grib_accessor_class_data_raw_packing_t::pack_double(grib_accessor* a, const bufsize = bytes * inlen; - buffer = (unsigned char*)grib_context_malloc(a->context, bufsize); + buffer = (unsigned char*)grib_context_malloc(context_, bufsize); if (!buffer) { code = GRIB_OUT_OF_MEMORY; goto clean_up; } - code = grib_ieee_encode_array(a->context, values, inlen, bytes, buffer); + code = grib_ieee_encode_array(context_, values, inlen, bytes, buffer); clean_up: /*if (free_buffer) @@ -132,12 +126,12 @@ clean_up: * free(values); */ - grib_buffer_replace(a, buffer, bufsize, 1, 1); + grib_buffer_replace(this, buffer, bufsize, 1, 1); - grib_context_buffer_free(a->context, buffer); + grib_context_buffer_free(context_, buffer); if (code == GRIB_SUCCESS) { - code = grib_set_long(grib_handle_of_accessor(a), self->number_of_values, inlen); + code = grib_set_long(grib_handle_of_accessor(this), number_of_values_, inlen); if (code == GRIB_READ_ONLY) code = 0; } @@ -145,24 +139,23 @@ clean_up: return code; } -int grib_accessor_class_data_raw_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_data_raw_packing_t::unpack_double_element(size_t idx, double* val) { - int ret = 0; - grib_accessor_data_raw_packing_t* self = (grib_accessor_data_raw_packing_t*)a; - unsigned char* buf = NULL; - int bytes = 0; - size_t nvals = 0; - long inlen = a->byte_count(); - long pos = 0; - long precision = 0; + int ret = 0; + unsigned char* buf = NULL; + int bytes = 0; + size_t nvals = 0; + long inlen = byte_count(); + long pos = 0; + long precision = 0; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->precision, &precision)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), precision_, &precision)) != GRIB_SUCCESS) return ret; - self->dirty = 0; + dirty_ = 0; - buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; - buf += a->byte_offset(); + buf = (unsigned char*)grib_handle_of_accessor(this)->buffer->data; + buf += byte_offset(); switch (precision) { case 1: bytes = 4; @@ -183,17 +176,17 @@ int grib_accessor_class_data_raw_packing_t::unpack_double_element(grib_accessor* nvals = 1; buf += pos; - ret = grib_ieee_decode_array(a->context, buf, nvals, bytes, val); + ret = grib_ieee_decode_array(context_, buf, nvals, bytes, val); return ret; } -int grib_accessor_class_data_raw_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) +int grib_accessor_data_raw_packing_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) { int err = 0; size_t i = 0; for (i = 0; i < len; ++i) { - if ((err = unpack_double_element(a, index_array[i], val_array + i)) != GRIB_SUCCESS) + if ((err = unpack_double_element(index_array[i], val_array + i)) != GRIB_SUCCESS) return err; } return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_data_raw_packing.h b/src/accessor/grib_accessor_class_data_raw_packing.h index b84650f28..e61f15d1a 100644 --- a/src/accessor/grib_accessor_class_data_raw_packing.h +++ b/src/accessor/grib_accessor_class_data_raw_packing.h @@ -15,20 +15,17 @@ class grib_accessor_data_raw_packing_t : public grib_accessor_values_t { public: - /* Members defined in data_raw_packing */ - const char* number_of_values; - const char* precision; -}; - -class grib_accessor_class_data_raw_packing_t : public grib_accessor_class_values_t -{ -public: - grib_accessor_class_data_raw_packing_t(const char* name) : grib_accessor_class_values_t(name) {} + grib_accessor_data_raw_packing_t() : + grib_accessor_values_t() { class_name_ = "data_raw_packing"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_data_raw_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; - 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; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + int unpack_double_element(size_t i, double* val) override; + int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; + +private: + const char* number_of_values_; + const char* precision_; }; diff --git a/src/accessor/grib_accessor_class_data_run_length_packing.cc b/src/accessor/grib_accessor_class_data_run_length_packing.cc index 5a9ae0e9b..ed40266cc 100644 --- a/src/accessor/grib_accessor_class_data_run_length_packing.cc +++ b/src/accessor/grib_accessor_class_data_run_length_packing.cc @@ -11,37 +11,33 @@ #include "grib_accessor_class_data_run_length_packing.h" #include "grib_scaling.h" -grib_accessor_class_data_run_length_packing_t _grib_accessor_class_data_run_length_packing{ "data_run_length_packing" }; -grib_accessor_class* grib_accessor_class_data_run_length_packing = &_grib_accessor_class_data_run_length_packing; +grib_accessor_data_run_length_packing_t _grib_accessor_data_run_length_packing{}; +grib_accessor* grib_accessor_data_run_length_packing = &_grib_accessor_data_run_length_packing; - -void grib_accessor_class_data_run_length_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_run_length_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_values_t::init(a, v, args); - grib_accessor_data_run_length_packing_t* self = (grib_accessor_data_run_length_packing_t*)a; - grib_handle* gh = grib_handle_of_accessor(a); - self->number_of_values = grib_arguments_get_name(gh, args, self->carg++); - self->bits_per_value = grib_arguments_get_name(gh, args, self->carg++); - self->max_level_value = grib_arguments_get_name(gh, args, self->carg++); - self->number_of_level_values = grib_arguments_get_name(gh, args, self->carg++); - self->decimal_scale_factor = grib_arguments_get_name(gh, args, self->carg++); - self->level_values = grib_arguments_get_name(gh, args, self->carg++); - a->flags |= GRIB_ACCESSOR_FLAG_DATA; + grib_accessor_values_t::init(v, args); + grib_handle* gh = grib_handle_of_accessor(this); + number_of_values_ = grib_arguments_get_name(gh, args, carg_++); + bits_per_value_ = grib_arguments_get_name(gh, args, carg_++); + max_level_value_ = grib_arguments_get_name(gh, args, carg_++); + number_of_level_values_ = grib_arguments_get_name(gh, args, carg_++); + decimal_scale_factor_ = grib_arguments_get_name(gh, args, carg_++); + level_values_ = grib_arguments_get_name(gh, args, carg_++); + flags_ |= GRIB_ACCESSOR_FLAG_DATA; } -int grib_accessor_class_data_run_length_packing_t::value_count(grib_accessor* a, long* number_of_values) +int grib_accessor_data_run_length_packing_t::value_count(long* number_of_values) { - grib_accessor_data_run_length_packing_t* self = (grib_accessor_data_run_length_packing_t*)a; - *number_of_values = 0; - return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, number_of_values); + *number_of_values = 0; + return grib_get_long_internal(grib_handle_of_accessor(this), number_of_values_, number_of_values); } -int grib_accessor_class_data_run_length_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_run_length_packing_t::unpack_double(double* val, size_t* len) { - grib_accessor_data_run_length_packing_t* self = (grib_accessor_data_run_length_packing_t*)a; - grib_handle* gh = grib_handle_of_accessor(a); - const char* cclass_name = a->cclass->name; - int err = GRIB_SUCCESS; + grib_handle* gh = grib_handle_of_accessor(this); + const char* cclass_name = class_name_; + int err = GRIB_SUCCESS; long seclen, number_of_values, bits_per_value, max_level_value, number_of_level_values, decimal_scale_factor; long* level_values = NULL; size_t level_values_size = 0; @@ -53,24 +49,24 @@ int grib_accessor_class_data_run_length_packing_t::unpack_double(grib_accessor* unsigned char* buf = NULL; double missingValue = 9999.0; - if ((err = grib_get_long_internal(gh, self->seclen, &seclen)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, seclen_, &seclen)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->number_of_values, &number_of_values)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, number_of_values_, &number_of_values)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->max_level_value, &max_level_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, max_level_value_, &max_level_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->number_of_level_values, &number_of_level_values)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, number_of_level_values_, &number_of_level_values)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; if ((err = grib_get_double(gh, "missingValue", &missingValue)) != GRIB_SUCCESS) return err; - level_values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * number_of_level_values); + level_values = (long*)grib_context_malloc_clear(context_, sizeof(long) * number_of_level_values); level_values_size = number_of_level_values; - if ((err = grib_get_long_array_internal(gh, self->level_values, level_values, &level_values_size)) != GRIB_SUCCESS) + if ((err = grib_get_long_array_internal(gh, level_values_, level_values, &level_values_size)) != GRIB_SUCCESS) return err; *len = number_of_values; i = 0; @@ -83,7 +79,7 @@ int grib_accessor_class_data_run_length_packing_t::unpack_double(grib_accessor* } range = (1 << bits_per_value) - 1 - max_level_value; if ((max_level_value <= 0) || (number_of_level_values <= 0) || (max_level_value > number_of_level_values) || (range <= 0)) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: parameters are invalid: max_level_value=%ld(>0, <=number_of_level_values), " "number_of_level_values=%ld(>0, >=max_level_value), range=%ld(>0)", cclass_name, max_level_value, number_of_level_values, range); @@ -93,14 +89,14 @@ int grib_accessor_class_data_run_length_packing_t::unpack_double(grib_accessor* decimal_scale_factor = -(decimal_scale_factor - 128); } level_scale_factor = codes_power(-decimal_scale_factor, 10.0); - levels = (double*)grib_context_malloc_clear(a->context, sizeof(double) * (number_of_level_values + 1)); + levels = (double*)grib_context_malloc_clear(context_, sizeof(double) * (number_of_level_values + 1)); levels[0] = missingValue; for (i = 0; i < number_of_level_values; i++) { levels[i + 1] = level_values[i] * level_scale_factor; } - compressed_values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * number_of_compressed_values); - buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; - offsetBeforeData = a->byte_offset(); + compressed_values = (long*)grib_context_malloc_clear(context_, sizeof(long) * number_of_compressed_values); + buf = (unsigned char*)grib_handle_of_accessor(this)->buffer->data; + offsetBeforeData = byte_offset(); buf += offsetBeforeData; pos = 0; grib_decode_long_array(buf, &pos, bits_per_value, number_of_compressed_values, compressed_values); @@ -108,7 +104,7 @@ int grib_accessor_class_data_run_length_packing_t::unpack_double(grib_accessor* i = 0; while (i < number_of_compressed_values) { if (compressed_values[i] > max_level_value) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: numberOfValues mismatch: i=%ld, " "compressed_values[i]=%ld, max_level_value=%ld", cclass_name, i, compressed_values[i], max_level_value); @@ -123,7 +119,7 @@ int grib_accessor_class_data_run_length_packing_t::unpack_double(grib_accessor* i++; } if (n > number_of_values) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s: numberOfValues mismatch: n=%ld, number_of_values=%ld", + grib_context_log(context_, GRIB_LOG_ERROR, "%s: numberOfValues mismatch: n=%ld, number_of_values=%ld", cclass_name, n, number_of_values); break; } @@ -131,23 +127,22 @@ int grib_accessor_class_data_run_length_packing_t::unpack_double(grib_accessor* val[j++] = levels[v]; } } - grib_context_free(a->context, level_values); - grib_context_free(a->context, levels); - grib_context_free(a->context, compressed_values); + grib_context_free(context_, level_values); + grib_context_free(context_, levels); + grib_context_free(context_, compressed_values); if (j != number_of_values) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s: numberOfValues mismatch: j=%ld, number_of_values=%ld", + grib_context_log(context_, GRIB_LOG_ERROR, "%s: numberOfValues mismatch: j=%ld, number_of_values=%ld", cclass_name, j, number_of_values); return GRIB_DECODING_ERROR; } return err; } -int grib_accessor_class_data_run_length_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_run_length_packing_t::pack_double(const double* val, size_t* len) { - grib_accessor_data_run_length_packing_t* self = (grib_accessor_data_run_length_packing_t*)a; - grib_handle* gh = grib_handle_of_accessor(a); - const char* cclass_name = a->cclass->name; - int err = GRIB_SUCCESS; + grib_handle* gh = grib_handle_of_accessor(this); + const char* cclass_name = class_name_; + int err = GRIB_SUCCESS; long number_of_values, bits_per_value, max_level_value, number_of_level_values, decimal_scale_factor; long* level_values = NULL; size_t level_values_size = 0; @@ -157,21 +152,21 @@ int grib_accessor_class_data_run_length_packing_t::pack_double(grib_accessor* a, double missingValue = 9999.0; size_t n_vals = *len; - if ((err = grib_get_long_internal(gh, self->number_of_values, &number_of_values)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, number_of_values_, &number_of_values)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->max_level_value, &max_level_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, max_level_value_, &max_level_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->number_of_level_values, &number_of_level_values)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, number_of_level_values_, &number_of_level_values)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; if ((err = grib_get_double(gh, "missingValue", &missingValue)) != GRIB_SUCCESS) return err; if (n_vals != number_of_values) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Parameters are invalid: n_vals=%ld(==number_of_values), number_of_values=%ld(==n_vals)", + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Parameters are invalid: n_vals=%ld(==number_of_values), number_of_values=%ld(==n_vals)", cclass_name, n_vals, number_of_values); return GRIB_ENCODING_ERROR; } @@ -181,9 +176,9 @@ int grib_accessor_class_data_run_length_packing_t::pack_double(grib_accessor* a, return GRIB_SUCCESS; } - level_values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * number_of_level_values); + level_values = (long*)grib_context_malloc_clear(context_, sizeof(long) * number_of_level_values); level_values_size = number_of_level_values; - if ((err = grib_get_long_array_internal(gh, self->level_values, level_values, &level_values_size)) != GRIB_SUCCESS) + if ((err = grib_get_long_array_internal(gh, level_values_, level_values, &level_values_size)) != GRIB_SUCCESS) return err; if (decimal_scale_factor > 127) { decimal_scale_factor = -(decimal_scale_factor - 128); @@ -192,20 +187,20 @@ int grib_accessor_class_data_run_length_packing_t::pack_double(grib_accessor* a, missingValueLong = (long)(round(missingValue / level_scale_factor)); for (i = 0; i < number_of_level_values; i++) { if (missingValueLong == level_values[i]) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Parameters are invalid: level_values[%ld]=%ld, missingValueLong=%ld", + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Parameters are invalid: level_values[%ld]=%ld, missingValueLong=%ld", cclass_name, i, level_values[i], missingValueLong); return GRIB_ENCODING_ERROR; } } range = (1 << bits_per_value) - 1 - max_level_value; if ((max_level_value <= 0) || (number_of_level_values <= 0) || (max_level_value > number_of_level_values) || (range <= 0)) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Parameters are invalid: max_level_value=%ld(>0, <=number_of_level_values), " "number_of_level_values=%ld(>0, >=max_level_value), range=%ld(>0)", cclass_name, max_level_value, number_of_level_values, range); return GRIB_ENCODING_ERROR; } - buf = (unsigned char*)grib_context_malloc(a->context, 2 * number_of_values); + buf = (unsigned char*)grib_context_malloc(context_, 2 * number_of_values); for (i = 0; i < number_of_values; i++) { k = (long)(round(val[i] / level_scale_factor)); err = GRIB_ENCODING_ERROR; @@ -223,7 +218,7 @@ int grib_accessor_class_data_run_length_packing_t::pack_double(grib_accessor* a, } } if (err != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Values and/or parameters are invalid: val[%ld]=%lf, level_value=%ld, max_level_value=%ld", cclass_name, i, val[i], k, max_level_value); return GRIB_ENCODING_ERROR; @@ -275,8 +270,8 @@ int grib_accessor_class_data_run_length_packing_t::pack_double(grib_accessor* a, } l = k; } - grib_context_free(a->context, level_values); - grib_buffer_replace(a, buf, pos / 8, 1, 1); - grib_context_buffer_free(a->context, buf); + grib_context_free(context_, level_values); + grib_buffer_replace(this, buf, pos / 8, 1, 1); + grib_context_buffer_free(context_, buf); return err; } diff --git a/src/accessor/grib_accessor_class_data_run_length_packing.h b/src/accessor/grib_accessor_class_data_run_length_packing.h index 5a69a7ba0..b489c7d9b 100644 --- a/src/accessor/grib_accessor_class_data_run_length_packing.h +++ b/src/accessor/grib_accessor_class_data_run_length_packing.h @@ -15,22 +15,19 @@ class grib_accessor_data_run_length_packing_t : public grib_accessor_values_t { public: - /* Members defined in data_run_length_packing */ - const char* number_of_values; - const char* bits_per_value; - const char* max_level_value; - const char* number_of_level_values; - const char* decimal_scale_factor; - const char* level_values; -}; - -class grib_accessor_class_data_run_length_packing_t : public grib_accessor_class_values_t -{ -public: - grib_accessor_class_data_run_length_packing_t(const char* name) : grib_accessor_class_values_t(name) {} + grib_accessor_data_run_length_packing_t() : + grib_accessor_values_t() { class_name_ = "data_run_length_packing"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_data_run_length_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; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +public: + const char* number_of_values_; + const char* bits_per_value_; + const char* max_level_value_; + const char* number_of_level_values_; + const char* decimal_scale_factor_; + const char* level_values_; }; diff --git a/src/accessor/grib_accessor_class_data_secondary_bitmap.cc b/src/accessor/grib_accessor_class_data_secondary_bitmap.cc index 8e8f2b626..705ca6c80 100644 --- a/src/accessor/grib_accessor_class_data_secondary_bitmap.cc +++ b/src/accessor/grib_accessor_class_data_secondary_bitmap.cc @@ -10,31 +10,27 @@ #include "grib_accessor_class_data_secondary_bitmap.h" -grib_accessor_class_data_secondary_bitmap_t _grib_accessor_class_data_secondary_bitmap{ "data_secondary_bitmap" }; -grib_accessor_class* grib_accessor_class_data_secondary_bitmap = &_grib_accessor_class_data_secondary_bitmap; +grib_accessor_data_secondary_bitmap_t _grib_accessor_data_secondary_bitmap{}; +grib_accessor* grib_accessor_data_secondary_bitmap = &_grib_accessor_data_secondary_bitmap; - -void grib_accessor_class_data_secondary_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_secondary_bitmap_t::init(const long v, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, v, args); - grib_accessor_data_secondary_bitmap_t* self = (grib_accessor_data_secondary_bitmap_t*)a; - self->primary_bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, 0); - self->secondary_bitmap = grib_arguments_get_name(grib_handle_of_accessor(a), args, 1); - self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, 2); - self->expand_by = grib_arguments_get_name(grib_handle_of_accessor(a), args, 3); + grib_accessor_gen_t::init(v, args); + primary_bitmap_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, 0); + secondary_bitmap_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, 1); + missing_value_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, 2); + expand_by_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, 3); - a->length = 0; + length_ = 0; } -void grib_accessor_class_data_secondary_bitmap_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_data_secondary_bitmap_t::dump(grib_dumper* dumper) { - grib_dump_values(dumper, a); + grib_dump_values(dumper, this); } -int grib_accessor_class_data_secondary_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_secondary_bitmap_t::unpack_double(double* val, size_t* len) { - grib_accessor_data_secondary_bitmap_t* self = (grib_accessor_data_secondary_bitmap_t*)a; - size_t i = 0; size_t j = 0; size_t k = 0; @@ -47,7 +43,7 @@ int grib_accessor_class_data_secondary_bitmap_t::unpack_double(grib_accessor* a, size_t secondary_len; double* primary_vals; double* secondary_vals; - err = a->value_count(&nn); + err = value_count(&nn); n_vals = nn; if (err) return err; @@ -57,34 +53,34 @@ int grib_accessor_class_data_secondary_bitmap_t::unpack_double(grib_accessor* a, return GRIB_ARRAY_TOO_SMALL; } - if ((err = grib_get_long(grib_handle_of_accessor(a), self->expand_by, &expand_by)) != GRIB_SUCCESS) + if ((err = grib_get_long(grib_handle_of_accessor(this), expand_by_, &expand_by)) != GRIB_SUCCESS) return err; - if ((err = grib_get_size(grib_handle_of_accessor(a), self->primary_bitmap, &primary_len)) != GRIB_SUCCESS) + if ((err = grib_get_size(grib_handle_of_accessor(this), primary_bitmap_, &primary_len)) != GRIB_SUCCESS) return err; - if ((err = grib_get_size(grib_handle_of_accessor(a), self->secondary_bitmap, &secondary_len)) != GRIB_SUCCESS) + if ((err = grib_get_size(grib_handle_of_accessor(this), secondary_bitmap_, &secondary_len)) != GRIB_SUCCESS) return err; - primary_vals = (double*)grib_context_malloc(a->context, primary_len * sizeof(double)); + primary_vals = (double*)grib_context_malloc(context_, primary_len * sizeof(double)); if (!primary_vals) return GRIB_OUT_OF_MEMORY; - secondary_vals = (double*)grib_context_malloc(a->context, secondary_len * sizeof(double)); + secondary_vals = (double*)grib_context_malloc(context_, secondary_len * sizeof(double)); if (!secondary_vals) { - grib_context_free(a->context, primary_vals); + grib_context_free(context_, primary_vals); return GRIB_OUT_OF_MEMORY; } - if ((err = grib_get_double_array_internal(grib_handle_of_accessor(a), self->primary_bitmap, primary_vals, &primary_len)) != GRIB_SUCCESS) { - grib_context_free(a->context, secondary_vals); - grib_context_free(a->context, primary_vals); + if ((err = grib_get_double_array_internal(grib_handle_of_accessor(this), primary_bitmap_, primary_vals, &primary_len)) != GRIB_SUCCESS) { + grib_context_free(context_, secondary_vals); + grib_context_free(context_, primary_vals); return err; } - if ((err = grib_get_double_array_internal(grib_handle_of_accessor(a), self->secondary_bitmap, secondary_vals, &secondary_len)) != GRIB_SUCCESS) { - grib_context_free(a->context, secondary_vals); - grib_context_free(a->context, primary_vals); + if ((err = grib_get_double_array_internal(grib_handle_of_accessor(this), secondary_bitmap_, secondary_vals, &secondary_len)) != GRIB_SUCCESS) { + grib_context_free(context_, secondary_vals); + grib_context_free(context_, primary_vals); return err; } @@ -109,14 +105,14 @@ int grib_accessor_class_data_secondary_bitmap_t::unpack_double(grib_accessor* a, *len = n_vals; - grib_context_free(a->context, primary_vals); - grib_context_free(a->context, secondary_vals); + grib_context_free(context_, primary_vals); + grib_context_free(context_, secondary_vals); return err; } -int grib_accessor_class_data_secondary_bitmap_t::get_native_type(grib_accessor* a) +long grib_accessor_data_secondary_bitmap_t::get_native_type() { // grib_accessor_data_secondary_bitmap_t* self = (grib_accessor_data_secondary_bitmap_t*)a; - // return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(a),self->coded_values)); + // return grib_accessor_get_native_type(grib_find_accessor(grib_handle_of_accessor(this),coded_values_ )); return GRIB_TYPE_DOUBLE; } diff --git a/src/accessor/grib_accessor_class_data_secondary_bitmap.h b/src/accessor/grib_accessor_class_data_secondary_bitmap.h index a24772be4..6ddacd3c0 100644 --- a/src/accessor/grib_accessor_class_data_secondary_bitmap.h +++ b/src/accessor/grib_accessor_class_data_secondary_bitmap.h @@ -15,20 +15,17 @@ class grib_accessor_data_secondary_bitmap_t : public grib_accessor_gen_t { public: - /* Members defined in data_secondary_bitmap */ - const char* primary_bitmap; - const char* secondary_bitmap; - const char* missing_value; - const char* expand_by; -}; - -class grib_accessor_class_data_secondary_bitmap_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_data_secondary_bitmap_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_data_secondary_bitmap_t() : + grib_accessor_gen_t() { class_name_ = "data_secondary_bitmap"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_data_secondary_bitmap_t{}; } - int get_native_type(grib_accessor*) override; - int unpack_double(grib_accessor*, double* val, size_t* len) override; - void dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int unpack_double(double* val, size_t* len) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +public: + const char* primary_bitmap_; + const char* secondary_bitmap_; + const char* missing_value_; + const char* expand_by_; }; diff --git a/src/accessor/grib_accessor_class_data_sh_packed.cc b/src/accessor/grib_accessor_class_data_sh_packed.cc index e1d3044f7..561c705eb 100644 --- a/src/accessor/grib_accessor_class_data_sh_packed.cc +++ b/src/accessor/grib_accessor_class_data_sh_packed.cc @@ -11,40 +11,37 @@ #include "grib_accessor_class_data_sh_packed.h" #include "grib_scaling.h" -grib_accessor_class_data_sh_packed_t _grib_accessor_class_data_sh_packed{ "data_sh_packed" }; -grib_accessor_class* grib_accessor_class_data_sh_packed = &_grib_accessor_class_data_sh_packed; - +grib_accessor_data_sh_packed_t _grib_accessor_data_sh_packed{}; +grib_accessor* grib_accessor_data_sh_packed = &_grib_accessor_data_sh_packed; typedef unsigned long (*encode_float_proc)(double); typedef double (*decode_float_proc)(unsigned long); -void grib_accessor_class_data_sh_packed_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_sh_packed_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_simple_packing_t::init(a, v, args); - grib_accessor_data_sh_packed_t* self = (grib_accessor_data_sh_packed_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_accessor_data_simple_packing_t::init(v, args); + grib_handle* hand = grib_handle_of_accessor(this); - self->GRIBEX_sh_bug_present = grib_arguments_get_name(hand, args, self->carg++); - self->ieee_floats = grib_arguments_get_name(hand, args, self->carg++); - self->laplacianOperatorIsSet = grib_arguments_get_name(hand, args, self->carg++); - self->laplacianOperator = grib_arguments_get_name(hand, args, self->carg++); - self->sub_j = grib_arguments_get_name(hand, args, self->carg++); - self->sub_k = grib_arguments_get_name(hand, args, self->carg++); - self->sub_m = grib_arguments_get_name(hand, args, self->carg++); - self->pen_j = grib_arguments_get_name(hand, args, self->carg++); - self->pen_k = grib_arguments_get_name(hand, args, self->carg++); - self->pen_m = grib_arguments_get_name(hand, args, self->carg++); + GRIBEX_sh_bug_present_ = grib_arguments_get_name(hand, args, carg_++); + ieee_floats_ = grib_arguments_get_name(hand, args, carg_++); + laplacianOperatorIsSet_ = grib_arguments_get_name(hand, args, carg_++); + laplacianOperator_ = grib_arguments_get_name(hand, args, carg_++); + sub_j_ = grib_arguments_get_name(hand, args, carg_++); + sub_k_ = grib_arguments_get_name(hand, args, carg_++); + sub_m_ = grib_arguments_get_name(hand, args, carg_++); + pen_j_ = grib_arguments_get_name(hand, args, carg_++); + pen_k_ = grib_arguments_get_name(hand, args, carg_++); + pen_m_ = grib_arguments_get_name(hand, args, carg_++); - a->flags |= GRIB_ACCESSOR_FLAG_DATA; - a->length = 0; + flags_ |= GRIB_ACCESSOR_FLAG_DATA; + length_ = 0; } -int grib_accessor_class_data_sh_packed_t::value_count(grib_accessor* a, long* count) +int grib_accessor_data_sh_packed_t::value_count(long* count) { - grib_accessor_data_sh_packed_t* self = (grib_accessor_data_sh_packed_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int ret = 0; - const char* cclass_name = a->cclass->name; + grib_handle* hand = grib_handle_of_accessor(this); + int ret = 0; + const char* cclass_name = class_name_; long sub_j = 0; long sub_k = 0; @@ -53,22 +50,22 @@ int grib_accessor_class_data_sh_packed_t::value_count(grib_accessor* a, long* co long pen_k = 0; long pen_m = 0; - if ((ret = grib_get_long_internal(hand, self->sub_j, &sub_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, sub_j_, &sub_j)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->sub_k, &sub_k)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, sub_k_, &sub_k)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->sub_m, &sub_m)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, sub_m_, &sub_m)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->pen_j, &pen_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, pen_j_, &pen_j)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->pen_k, &pen_k)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, pen_k_, &pen_k)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->pen_m, &pen_m)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, pen_m_, &pen_m)) != GRIB_SUCCESS) return ret; if (pen_j != pen_k || pen_j != pen_m) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s: pen_j=%ld, pen_k=%ld, pen_m=%ld\n", + grib_context_log(context_, GRIB_LOG_ERROR, "%s: pen_j=%ld, pen_k=%ld, pen_m=%ld\n", cclass_name, pen_j, pen_k, pen_m); return GRIB_DECODING_ERROR; } @@ -76,10 +73,8 @@ int grib_accessor_class_data_sh_packed_t::value_count(grib_accessor* a, long* co return ret; } -int grib_accessor_class_data_sh_packed_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_sh_packed_t::unpack_double(double* val, size_t* len) { - grib_accessor_data_sh_packed_t* self = (grib_accessor_data_sh_packed_t*)a; - size_t i = 0; int ret = GRIB_SUCCESS; // long lup = 0; @@ -112,7 +107,7 @@ int grib_accessor_class_data_sh_packed_t::unpack_double(grib_accessor* a, double decode_float_proc decode_float = NULL; n_vals = 0; - err = a->value_count(&n_vals); + err = value_count(&n_vals); if (err) return err; @@ -121,40 +116,40 @@ int grib_accessor_class_data_sh_packed_t::unpack_double(grib_accessor* a, double return GRIB_ARRAY_TOO_SMALL; } - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetdata, &offsetdata)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetdata_, &offsetdata)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(grib_handle_of_accessor(this), reference_value_, &reference_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->GRIBEX_sh_bug_present, &GRIBEX_sh_bug_present)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), GRIBEX_sh_bug_present_, &GRIBEX_sh_bug_present)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->ieee_floats, &ieee_floats)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), ieee_floats_, &ieee_floats)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), self->laplacianOperator, &laplacianOperator)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(grib_handle_of_accessor(this), laplacianOperator_, &laplacianOperator)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_j, &sub_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), 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) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), 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) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), sub_m_, &sub_m)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->pen_j, &pen_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), pen_j_, &pen_j)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->pen_k, &pen_k)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), pen_k_, &pen_k)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->pen_m, &pen_m)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), pen_m_, &pen_m)) != GRIB_SUCCESS) return ret; - self->dirty = 0; + dirty_ = 0; switch (ieee_floats) { case 0: @@ -178,7 +173,7 @@ int grib_accessor_class_data_sh_packed_t::unpack_double(grib_accessor* a, double Assert(pen_j == pen_k); Assert(pen_j == pen_m); - buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; + buf = (unsigned char*)grib_handle_of_accessor(this)->buffer->data; maxv = pen_j + 1; @@ -193,7 +188,7 @@ int grib_accessor_class_data_sh_packed_t::unpack_double(grib_accessor* a, double s = codes_power(binary_scale_factor, 2); d = codes_power(-decimal_scale_factor, 10); - scals = (double*)grib_context_malloc(a->context, maxv * sizeof(double)); + scals = (double*)grib_context_malloc(context_, maxv * sizeof(double)); if (!scals) return GRIB_OUT_OF_MEMORY; scals[0] = 0; @@ -212,7 +207,6 @@ int grib_accessor_class_data_sh_packed_t::unpack_double(grib_accessor* a, double // lup = mmax; if (sub_k >= 0) { for (hcount = 0; hcount < sub_k + 1; hcount++) { - decode_float(grib_decode_unsigned_long(hres, &hpos, 8 * bytes)); decode_float(grib_decode_unsigned_long(hres, &hpos, 8 * bytes)); // lup++; } @@ -242,7 +236,7 @@ int grib_accessor_class_data_sh_packed_t::unpack_double(grib_accessor* a, double Assert(*len >= i); *len = n_vals; - grib_context_free(a->context, scals); + grib_context_free(context_, scals); return ret; } diff --git a/src/accessor/grib_accessor_class_data_sh_packed.h b/src/accessor/grib_accessor_class_data_sh_packed.h index bbe3caafe..71d54b411 100644 --- a/src/accessor/grib_accessor_class_data_sh_packed.h +++ b/src/accessor/grib_accessor_class_data_sh_packed.h @@ -15,25 +15,22 @@ class grib_accessor_data_sh_packed_t : public grib_accessor_data_simple_packing_t { public: - /* Members defined in data_sh_packed */ - 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_sh_packed_t : public grib_accessor_class_data_simple_packing_t -{ -public: - grib_accessor_class_data_sh_packed_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {} + grib_accessor_data_sh_packed_t() : + grib_accessor_data_simple_packing_t() { class_name_ = "data_sh_packed"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_data_sh_packed_t{}; } - 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; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + 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_; }; diff --git a/src/accessor/grib_accessor_class_data_sh_unpacked.cc b/src/accessor/grib_accessor_class_data_sh_unpacked.cc index 6a95eebb1..dfbd55465 100644 --- a/src/accessor/grib_accessor_class_data_sh_unpacked.cc +++ b/src/accessor/grib_accessor_class_data_sh_unpacked.cc @@ -11,62 +11,57 @@ #include "grib_accessor_class_data_sh_unpacked.h" #include "grib_scaling.h" -grib_accessor_class_data_sh_unpacked_t _grib_accessor_class_data_sh_unpacked{ "data_sh_unpacked" }; -grib_accessor_class* grib_accessor_class_data_sh_unpacked = &_grib_accessor_class_data_sh_unpacked; - +grib_accessor_data_sh_unpacked_t _grib_accessor_data_sh_unpacked{}; +grib_accessor* grib_accessor_data_sh_unpacked = &_grib_accessor_data_sh_unpacked; typedef unsigned long (*encode_float_proc)(double); typedef double (*decode_float_proc)(unsigned long); -void grib_accessor_class_data_sh_unpacked_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_sh_unpacked_t::init(const long v, grib_arguments* args) { - grib_accessor_class_data_simple_packing_t::init(a, v, args); - grib_accessor_data_sh_unpacked_t* self = (grib_accessor_data_sh_unpacked_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_accessor_data_simple_packing_t::init(v, args); + grib_handle* hand = grib_handle_of_accessor(this); - self->GRIBEX_sh_bug_present = grib_arguments_get_name(hand, args, self->carg++); - self->ieee_floats = grib_arguments_get_name(hand, args, self->carg++); - self->laplacianOperatorIsSet = grib_arguments_get_name(hand, args, self->carg++); - self->laplacianOperator = grib_arguments_get_name(hand, args, self->carg++); - self->sub_j = grib_arguments_get_name(hand, args, self->carg++); - self->sub_k = grib_arguments_get_name(hand, args, self->carg++); - self->sub_m = grib_arguments_get_name(hand, args, self->carg++); - self->pen_j = grib_arguments_get_name(hand, args, self->carg++); - self->pen_k = grib_arguments_get_name(hand, args, self->carg++); - self->pen_m = grib_arguments_get_name(hand, args, self->carg++); + GRIBEX_sh_bug_present_ = grib_arguments_get_name(hand, args, carg_++); + ieee_floats_ = grib_arguments_get_name(hand, args, carg_++); + laplacianOperatorIsSet_ = grib_arguments_get_name(hand, args, carg_++); + laplacianOperator_ = grib_arguments_get_name(hand, args, carg_++); + sub_j_ = grib_arguments_get_name(hand, args, carg_++); + sub_k_ = grib_arguments_get_name(hand, args, carg_++); + sub_m_ = grib_arguments_get_name(hand, args, carg_++); + pen_j_ = grib_arguments_get_name(hand, args, carg_++); + pen_k_ = grib_arguments_get_name(hand, args, carg_++); + pen_m_ = grib_arguments_get_name(hand, args, carg_++); - a->flags |= GRIB_ACCESSOR_FLAG_DATA; - a->length = 0; + flags_ |= GRIB_ACCESSOR_FLAG_DATA; + length_ = 0; } -int grib_accessor_class_data_sh_unpacked_t::value_count(grib_accessor* a, long* count) +int grib_accessor_data_sh_unpacked_t::value_count(long* count) { - grib_accessor_data_sh_unpacked_t* self = (grib_accessor_data_sh_unpacked_t*)a; - int ret = 0; + int ret = 0; long sub_j = 0; long sub_k = 0; long sub_m = 0; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_j, &sub_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), 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) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), 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) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), sub_m_, &sub_m)) != GRIB_SUCCESS) return ret; if (sub_j != sub_k || sub_j != sub_m) { - grib_context_log(a->context, GRIB_LOG_ERROR, "sub_j=%ld, sub_k=%ld, sub_m=%ld\n", sub_j, sub_k, sub_m); + grib_context_log(context_, GRIB_LOG_ERROR, "sub_j=%ld, sub_k=%ld, sub_m=%ld\n", sub_j, sub_k, sub_m); Assert((sub_j == sub_k) && (sub_j == sub_m)); } *count = (sub_j + 1) * (sub_j + 2); return ret; } -int grib_accessor_class_data_sh_unpacked_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_sh_unpacked_t::unpack_double(double* val, size_t* len) { - grib_accessor_data_sh_unpacked_t* self = (grib_accessor_data_sh_unpacked_t*)a; - size_t i = 0; int ret = GRIB_SUCCESS; long hcount = 0; @@ -112,7 +107,7 @@ int grib_accessor_class_data_sh_unpacked_t::unpack_double(grib_accessor* a, doub decode_float_proc decode_float = NULL; n_vals = 0; - err = a->value_count(&n_vals); + err = value_count(&n_vals); if (err) return err; @@ -121,29 +116,29 @@ int grib_accessor_class_data_sh_unpacked_t::unpack_double(grib_accessor* a, doub return GRIB_ARRAY_TOO_SMALL; } - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetdata, &offsetdata)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetdata_, &offsetdata)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->GRIBEX_sh_bug_present, &GRIBEX_sh_bug_present)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), GRIBEX_sh_bug_present_, &GRIBEX_sh_bug_present)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->ieee_floats, &ieee_floats)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), ieee_floats_, &ieee_floats)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->sub_j, &sub_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), 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) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), 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) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), sub_m_, &sub_m)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->pen_j, &pen_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), pen_j_, &pen_j)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->pen_k, &pen_k)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), pen_k_, &pen_k)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->pen_m, &pen_m)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), pen_m_, &pen_m)) != GRIB_SUCCESS) return ret; - self->dirty = 0; + dirty_ = 0; switch (ieee_floats) { case 0: @@ -167,7 +162,7 @@ int grib_accessor_class_data_sh_unpacked_t::unpack_double(grib_accessor* a, doub Assert(pen_j == pen_k); Assert(pen_j == pen_m); - buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; + buf = (unsigned char*)grib_handle_of_accessor(this)->buffer->data; maxv = pen_j + 1; @@ -182,9 +177,9 @@ int grib_accessor_class_data_sh_unpacked_t::unpack_double(grib_accessor* a, doub s = codes_power(binary_scale_factor, 2); d = codes_power(-decimal_scale_factor, 10); - scals = (double*)grib_context_malloc(a->context, maxv * sizeof(double)); + scals = (double*)grib_context_malloc(context_, maxv * sizeof(double)); Assert(scals); - if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), self->laplacianOperator, &laplacianOperator)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(grib_handle_of_accessor(this), laplacianOperator_, &laplacianOperator)) != GRIB_SUCCESS) return ret; scals[0] = 0; @@ -204,7 +199,6 @@ int grib_accessor_class_data_sh_unpacked_t::unpack_double(grib_accessor* a, doub if (sub_k >= 0) { for (hcount = 0; hcount < sub_k + 1; hcount++) { val[i++] = decode_float(grib_decode_unsigned_long(hres, &hpos, 8 * bytes)); - val[i++] = decode_float(grib_decode_unsigned_long(hres, &hpos, 8 * bytes)); if (GRIBEX_sh_bug_present && hcount == sub_k) { /* bug in ecmwf data, last row (K+1)is scaled but should not */ @@ -233,7 +227,7 @@ int grib_accessor_class_data_sh_unpacked_t::unpack_double(grib_accessor* a, doub Assert(*len >= i); *len = n_vals; - grib_context_free(a->context, scals); + grib_context_free(context_, scals); return ret; } diff --git a/src/accessor/grib_accessor_class_data_sh_unpacked.h b/src/accessor/grib_accessor_class_data_sh_unpacked.h index 7907b8c68..29c283084 100644 --- a/src/accessor/grib_accessor_class_data_sh_unpacked.h +++ b/src/accessor/grib_accessor_class_data_sh_unpacked.h @@ -15,25 +15,22 @@ class grib_accessor_data_sh_unpacked_t : public grib_accessor_data_simple_packing_t { public: - /* Members defined in data_sh_unpacked */ - 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_sh_unpacked_t : public grib_accessor_class_data_simple_packing_t -{ -public: - grib_accessor_class_data_sh_unpacked_t(const char* name) : grib_accessor_class_data_simple_packing_t(name) {} + grib_accessor_data_sh_unpacked_t() : + grib_accessor_data_simple_packing_t() { class_name_ = "data_sh_unpacked"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_data_sh_unpacked_t{}; } - 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; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + 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_; }; diff --git a/src/accessor/grib_accessor_class_data_shsimple_packing.cc b/src/accessor/grib_accessor_class_data_shsimple_packing.cc index 7f8b60e14..ae909b6c2 100644 --- a/src/accessor/grib_accessor_class_data_shsimple_packing.cc +++ b/src/accessor/grib_accessor_class_data_shsimple_packing.cc @@ -10,46 +10,43 @@ #include "grib_accessor_class_data_shsimple_packing.h" -grib_accessor_class_data_shsimple_packing_t _grib_accessor_class_data_shsimple_packing{ "data_shsimple_packing" }; -grib_accessor_class* grib_accessor_class_data_shsimple_packing = &_grib_accessor_class_data_shsimple_packing; +grib_accessor_data_shsimple_packing_t _grib_accessor_data_shsimple_packing{}; +grib_accessor* grib_accessor_data_shsimple_packing = &_grib_accessor_data_shsimple_packing; - -void grib_accessor_class_data_shsimple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_shsimple_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, v, args); - grib_accessor_data_shsimple_packing_t* self = (grib_accessor_data_shsimple_packing_t*)a; + grib_accessor_gen_t::init(v, args); - self->coded_values = grib_arguments_get_name(grib_handle_of_accessor(a), args, 0); - self->real_part = grib_arguments_get_name(grib_handle_of_accessor(a), args, 1); - a->flags |= GRIB_ACCESSOR_FLAG_DATA; + coded_values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, 0); + real_part_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, 1); + flags_ |= GRIB_ACCESSOR_FLAG_DATA; - a->length = 0; + length_ = 0; } -void grib_accessor_class_data_shsimple_packing_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_data_shsimple_packing_t::dump(grib_dumper* dumper) { - grib_dump_values(dumper, a); + grib_dump_values(dumper, this); } -int grib_accessor_class_data_shsimple_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_shsimple_packing_t::pack_double(const double* val, size_t* len) { - grib_accessor_data_shsimple_packing_t* self = (grib_accessor_data_shsimple_packing_t*)a; - int err = GRIB_SUCCESS; + int err = GRIB_SUCCESS; size_t coded_n_vals = *len - 1; size_t n_vals = *len; - self->dirty = 1; + dirty_ = 1; if (*len == 0) return GRIB_NO_VALUES; - if ((err = grib_set_double_internal(grib_handle_of_accessor(a), self->real_part, *val)) != GRIB_SUCCESS) + if ((err = grib_set_double_internal(grib_handle_of_accessor(this), real_part_, *val)) != GRIB_SUCCESS) return err; val++; - if ((err = grib_set_double_array_internal(grib_handle_of_accessor(a), self->coded_values, val, coded_n_vals)) != GRIB_SUCCESS) + if ((err = grib_set_double_array_internal(grib_handle_of_accessor(this), coded_values_, val, coded_n_vals)) != GRIB_SUCCESS) return err; *len = n_vals; @@ -57,7 +54,7 @@ int grib_accessor_class_data_shsimple_packing_t::pack_double(grib_accessor* a, c return err; } -int grib_accessor_class_data_shsimple_packing_t::get_native_type(grib_accessor* a) +long grib_accessor_data_shsimple_packing_t::get_native_type() { return GRIB_TYPE_DOUBLE; } diff --git a/src/accessor/grib_accessor_class_data_shsimple_packing.h b/src/accessor/grib_accessor_class_data_shsimple_packing.h index 7b1620141..841ce9056 100644 --- a/src/accessor/grib_accessor_class_data_shsimple_packing.h +++ b/src/accessor/grib_accessor_class_data_shsimple_packing.h @@ -15,19 +15,17 @@ class grib_accessor_data_shsimple_packing_t : public grib_accessor_gen_t { public: - /* Members defined in data_shsimple_packing */ - const char* coded_values; - const char* real_part; - int dirty; -}; - -class grib_accessor_class_data_shsimple_packing_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_data_shsimple_packing_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_data_shsimple_packing_t() : + grib_accessor_gen_t() { class_name_ = "data_shsimple_packing"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_data_shsimple_packing_t{}; } - int get_native_type(grib_accessor*) override; - int pack_double(grib_accessor*, const double* val, size_t* len) override; - void dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int pack_double(const double* val, size_t* len) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +public: + const char* coded_values_; + const char* real_part_; + // TODO(maee): dirty_ shadowed by the derived class + // int dirty_; }; diff --git a/src/accessor/grib_accessor_class_data_simple_packing.cc b/src/accessor/grib_accessor_class_data_simple_packing.cc index 591e89526..1de1595b9 100644 --- a/src/accessor/grib_accessor_class_data_simple_packing.cc +++ b/src/accessor/grib_accessor_class_data_simple_packing.cc @@ -15,26 +15,24 @@ #include #include -grib_accessor_class_data_simple_packing_t _grib_accessor_class_data_simple_packing{ "data_simple_packing" }; -grib_accessor_class* grib_accessor_class_data_simple_packing = &_grib_accessor_class_data_simple_packing; +grib_accessor_data_simple_packing_t _grib_accessor_data_simple_packing{}; +grib_accessor* grib_accessor_data_simple_packing = &_grib_accessor_data_simple_packing; - -void grib_accessor_class_data_simple_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_data_simple_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_values_t::init(a, v, args); - grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; - grib_handle* gh = grib_handle_of_accessor(a); - self->units_factor = grib_arguments_get_name(gh, args, self->carg++); - self->units_bias = grib_arguments_get_name(gh, args, self->carg++); - self->changing_precision = grib_arguments_get_name(gh, args, self->carg++); - self->number_of_values = grib_arguments_get_name(gh, args, self->carg++); - self->bits_per_value = grib_arguments_get_name(gh, args, self->carg++); - self->reference_value = grib_arguments_get_name(gh, args, self->carg++); - self->binary_scale_factor = grib_arguments_get_name(gh, args, self->carg++); - self->decimal_scale_factor = grib_arguments_get_name(gh, args, self->carg++); - self->optimize_scaling_factor = grib_arguments_get_name(gh, args, self->carg++); - a->flags |= GRIB_ACCESSOR_FLAG_DATA; - self->dirty = 1; + grib_accessor_values_t::init(v, args); + grib_handle* gh = grib_handle_of_accessor(this); + units_factor_ = grib_arguments_get_name(gh, args, carg_++); + units_bias_ = grib_arguments_get_name(gh, args, carg_++); + changing_precision_ = grib_arguments_get_name(gh, args, carg_++); + number_of_values_ = grib_arguments_get_name(gh, args, carg_++); + bits_per_value_ = grib_arguments_get_name(gh, args, carg_++); + reference_value_ = grib_arguments_get_name(gh, args, carg_++); + binary_scale_factor_ = grib_arguments_get_name(gh, args, carg_++); + decimal_scale_factor_ = grib_arguments_get_name(gh, args, carg_++); + optimize_scaling_factor_ = grib_arguments_get_name(gh, args, carg_++); + flags_ |= GRIB_ACCESSOR_FLAG_DATA; + dirty_ = 1; } static const unsigned long nbits[32] = { @@ -61,48 +59,46 @@ static int number_of_bits(unsigned long x, long* result) return GRIB_SUCCESS; } -int grib_accessor_class_data_simple_packing_t::value_count(grib_accessor* a, long* number_of_values) +int grib_accessor_data_simple_packing_t::value_count(long* number_of_values) { - grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; *number_of_values = 0; - return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_values, number_of_values); + return grib_get_long_internal(grib_handle_of_accessor(this), number_of_values_, number_of_values); } -int grib_accessor_class_data_simple_packing_t::unpack_double_element(grib_accessor* a, size_t idx, double* val) +int grib_accessor_data_simple_packing_t::unpack_double_element(size_t idx, double* val) { - grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; - const char* cclass_name = a->cclass->name; + const char* cclass_name = class_name_; - long n_vals = 0; - int err = 0; - grib_handle* gh = grib_handle_of_accessor(a); + long n_vals = 0; + int err = 0; + grib_handle* gh = grib_handle_of_accessor(this); double reference_value; long binary_scale_factor; long bits_per_value; long decimal_scale_factor; unsigned char* buf = (unsigned char*)gh->buffer->data; - double s = 0; - double d = 0; - long pos = 0; + double s = 0; + double d = 0; + long pos = 0; - err = a->value_count(&n_vals); + err = value_count(&n_vals); if (err) return err; - if ((err = grib_get_long_internal(gh, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - self->dirty = 0; + dirty_ = 0; - if ((err = grib_get_double_internal(gh, self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(gh, reference_value_, &reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; /* Special case */ @@ -115,15 +111,15 @@ int grib_accessor_class_data_simple_packing_t::unpack_double_element(grib_access s = codes_power(binary_scale_factor, 2); d = codes_power(-decimal_scale_factor, 10); - grib_context_log(a->context, GRIB_LOG_DEBUG, + grib_context_log(context_, GRIB_LOG_DEBUG, "%s: %s: creating %s, %ld values (idx=%zu)", - cclass_name, __func__, a->name, n_vals, idx); + cclass_name, __func__, name_, n_vals, idx); - buf += a->byte_offset(); + buf += byte_offset(); /*Assert(((bits_per_value*n_vals)/8) < (1<<29));*/ /* See GRIB-787 */ if (bits_per_value % 8) { - grib_context_log(a->context, GRIB_LOG_DEBUG, + grib_context_log(context_, GRIB_LOG_DEBUG, "%s: calling outline function : bpv %ld, rv: %g, bsf: %ld, dsf: %ld ", cclass_name, bits_per_value, reference_value, binary_scale_factor, decimal_scale_factor); pos = idx * bits_per_value; @@ -151,12 +147,12 @@ int grib_accessor_class_data_simple_packing_t::unpack_double_element(grib_access return err; } -int grib_accessor_class_data_simple_packing_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) +int grib_accessor_data_simple_packing_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) { int err = 0; size_t i = 0; for (i = 0; i < len; ++i) { - if ((err = unpack_double_element(a, index_array[i], val_array + i)) != GRIB_SUCCESS) + if ((err = unpack_double_element(index_array[i], val_array + i)) != GRIB_SUCCESS) return err; } return GRIB_SUCCESS; @@ -165,10 +161,10 @@ int grib_accessor_class_data_simple_packing_t::unpack_double_element_set(grib_ac template static int unpack(grib_accessor* a, T* val, size_t* len) { + grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; static_assert(std::is_floating_point::value, "Requires floating point numbers"); - grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; - const char* cclass_name = a->cclass->name; + const char* cclass_name = a->class_name_; grib_handle* gh = grib_handle_of_accessor(a); unsigned char* buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; @@ -198,7 +194,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_ARRAY_TOO_SMALL; } - if ((err = grib_get_long_internal(gh, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; /* @@ -209,14 +205,14 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_INVALID_BPV; } - if (self->units_factor && - (grib_get_double_internal(gh, self->units_factor, &units_factor) == GRIB_SUCCESS)) { - grib_set_double_internal(gh, self->units_factor, 1.0); + if (self->units_factor_ && + (grib_get_double_internal(gh, self->units_factor_, &units_factor) == GRIB_SUCCESS)) { + grib_set_double_internal(gh, self->units_factor_, 1.0); } - if (self->units_bias && - (grib_get_double_internal(gh, self->units_bias, &units_bias) == GRIB_SUCCESS)) { - grib_set_double_internal(gh, self->units_bias, 0.0); + if (self->units_bias_ && + (grib_get_double_internal(gh, self->units_bias_, &units_bias) == GRIB_SUCCESS)) { + grib_set_double_internal(gh, self->units_bias_, 0.0); } if (n_vals == 0) { @@ -224,15 +220,15 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_SUCCESS; } - self->dirty = 0; + a->dirty_ = 0; - if ((err = grib_get_double_internal(gh, self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(gh, self->reference_value_, &reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; /* Special case */ @@ -247,8 +243,8 @@ static int unpack(grib_accessor* a, T* val, size_t* len) s = codes_power(binary_scale_factor, 2); d = codes_power(-decimal_scale_factor, 10); - grib_context_log(a->context, GRIB_LOG_DEBUG, - "%s %s: Creating %s, %zu values", cclass_name, __func__, a->name, n_vals); + grib_context_log(a->context_, GRIB_LOG_DEBUG, + "%s %s: Creating %s, %zu values", cclass_name, __func__, a->name_, n_vals); offsetBeforeData = a->byte_offset(); buf += offsetBeforeData; @@ -256,14 +252,14 @@ static int unpack(grib_accessor* a, T* val, size_t* len) /*Assert(((bits_per_value*n_vals)/8) < (1<<29));*/ /* See GRIB-787 */ /* ECC-941 */ - if (!a->context->ieee_packing) { + if (!a->context_->ieee_packing) { /* Must turn off this check when the environment variable ECCODES_GRIB_IEEE_PACKING is on */ long offsetAfterData = 0; err = grib_get_long(gh, "offsetAfterData", &offsetAfterData); if (!err && offsetAfterData > offsetBeforeData) { const long valuesSize = (bits_per_value * n_vals) / 8; /*in bytes*/ if (offsetBeforeData + valuesSize > offsetAfterData) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(a->context_, GRIB_LOG_ERROR, "%s: Data section size mismatch: " "offset before data=%ld, offset after data=%ld (num values=%zu, bits per value=%ld)", cclass_name, offsetBeforeData, offsetAfterData, n_vals, bits_per_value); @@ -279,7 +275,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) // } } - grib_context_log(a->context, GRIB_LOG_DEBUG, + grib_context_log(a->context_, GRIB_LOG_DEBUG, "%s %s: calling outline function: bpv: %ld, rv: %g, bsf: %ld, dsf: %ld", cclass_name, __func__, bits_per_value, reference_value, binary_scale_factor, decimal_scale_factor); grib_decode_array(buf, &pos, bits_per_value, reference_value, s, d, n_vals, val); @@ -306,21 +302,21 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return err; } -int grib_accessor_class_data_simple_packing_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_data_simple_packing_t::unpack_double(double* val, size_t* len) { - return unpack(a, val, len); + return unpack(this, val, len); } -int grib_accessor_class_data_simple_packing_t::unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_data_simple_packing_t::unpack_float(float* val, size_t* len) { - return unpack(a, val, len); + return unpack(this, val, len); } static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned char* buf, long pos, size_t n_vals) { grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; grib_handle* gh = grib_handle_of_accessor(a); - const char* cclass_name = a->cclass->name; + const char* cclass_name = a->class_name_; size_t i = 0; int err = 0; @@ -340,7 +336,7 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c return GRIB_ARRAY_TOO_SMALL; } - if ((err = grib_get_long_internal(gh, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; /* @@ -351,14 +347,14 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c return GRIB_INVALID_BPV; } - if (self->units_factor && - (grib_get_double_internal(gh, self->units_factor, &units_factor) == GRIB_SUCCESS)) { - grib_set_double_internal(gh, self->units_factor, 1.0); + if (self->units_factor_ && + (grib_get_double_internal(gh, self->units_factor_, &units_factor) == GRIB_SUCCESS)) { + grib_set_double_internal(gh, self->units_factor_, 1.0); } - if (self->units_bias && - (grib_get_double_internal(gh, self->units_bias, &units_bias) == GRIB_SUCCESS)) { - grib_set_double_internal(gh, self->units_bias, 0.0); + if (self->units_bias_ && + (grib_get_double_internal(gh, self->units_bias_, &units_bias) == GRIB_SUCCESS)) { + grib_set_double_internal(gh, self->units_bias_, 0.0); } if (n_vals == 0) { @@ -366,15 +362,15 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c return GRIB_SUCCESS; } - self->dirty = 0; + a->dirty_ = 0; - if ((err = grib_get_double_internal(gh, self->reference_value, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(gh, self->reference_value_, &reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; /* Special case */ @@ -389,8 +385,8 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c s = codes_power(binary_scale_factor, 2); d = codes_power(-decimal_scale_factor, 10); - grib_context_log(a->context, GRIB_LOG_DEBUG, - "%s %s: Creating %s, %zu values", cclass_name, __func__, a->name, n_vals); + grib_context_log(a->context_, GRIB_LOG_DEBUG, + "%s %s: Creating %s, %zu values", cclass_name, __func__, a->name_, n_vals); offsetBeforeData = a->byte_offset(); buf += offsetBeforeData; @@ -398,14 +394,14 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c /*Assert(((bits_per_value*n_vals)/8) < (1<<29));*/ /* See GRIB-787 */ /* ECC-941 */ - if (!a->context->ieee_packing) { + if (!a->context_->ieee_packing) { /* Must turn off this check when the environment variable ECCODES_GRIB_IEEE_PACKING is on */ long offsetAfterData = 0; err = grib_get_long(gh, "offsetAfterData", &offsetAfterData); if (!err && offsetAfterData > offsetBeforeData) { const long valuesSize = (bits_per_value * n_vals) / 8; /*in bytes*/ if (offsetBeforeData + valuesSize > offsetAfterData) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(a->context_, GRIB_LOG_ERROR, "Data section size mismatch: offset before data=%ld, offset after data=%ld (num values=%ld, bits per value=%ld)", offsetBeforeData, offsetAfterData, n_vals, bits_per_value); return GRIB_DECODING_ERROR; @@ -421,7 +417,7 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c // } } - grib_context_log(a->context, GRIB_LOG_DEBUG, + grib_context_log(a->context_, GRIB_LOG_DEBUG, "unpack_double: calling outline function : bpv %d, rv : %g, sf : %d, dsf : %d ", bits_per_value, reference_value, binary_scale_factor, decimal_scale_factor); grib_decode_array(buf, &pos, bits_per_value, reference_value, s, d, n_vals, val); @@ -443,31 +439,28 @@ static int _unpack_double(grib_accessor* a, double* val, size_t* len, unsigned c return err; } -int grib_accessor_class_data_simple_packing_t::unpack_double_subarray(grib_accessor* a, double* val, size_t start, size_t len) +int grib_accessor_data_simple_packing_t::unpack_double_subarray(double* val, size_t start, size_t len) { - grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; - - unsigned char* buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; - size_t nvals = len; - size_t* plen = &len; + unsigned char* buf = (unsigned char*)grib_handle_of_accessor(this)->buffer->data; + size_t nvals = len; + size_t* plen = &len; long bits_per_value = 0; - long pos = 0; - int err = GRIB_SUCCESS; + long pos = 0; + int err = GRIB_SUCCESS; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->bits_per_value, &bits_per_value)) != + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; buf += (start * bits_per_value) / 8; pos = start * bits_per_value % 8; - return _unpack_double(a, val, plen, buf, pos, nvals); + return _unpack_double(this, val, plen, buf, pos, nvals); } -int grib_accessor_class_data_simple_packing_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_data_simple_packing_t::pack_double(const double* val, size_t* len) { - grib_accessor_data_simple_packing_t* self = (grib_accessor_data_simple_packing_t*)a; - grib_handle* gh = grib_handle_of_accessor(a); - const char* cclass_name = a->cclass->name; + grib_handle* gh = grib_handle_of_accessor(this); + const char* cclass_name = class_name_; size_t i = 0; size_t n_vals = *len; @@ -487,7 +480,7 @@ int grib_accessor_class_data_simple_packing_t::pack_double(grib_accessor* a, con double range = 0; double minrange = 0, maxrange = 0; long changing_precision = 0; - grib_context* c = a->context; + grib_context* c = context_; decimal_scale_factor = 0; @@ -495,15 +488,15 @@ int grib_accessor_class_data_simple_packing_t::pack_double(grib_accessor* a, con return GRIB_NO_VALUES; } - if ((err = grib_get_long_internal(gh, self->bits_per_value, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; if (*len == 0) return GRIB_SUCCESS; - if ((err = grib_get_long_internal(gh, self->decimal_scale_factor, &decimal_scale_factor_get)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, decimal_scale_factor_, &decimal_scale_factor_get)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->optimize_scaling_factor, &optimize_scaling_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, optimize_scaling_factor_, &optimize_scaling_factor)) != GRIB_SUCCESS) return err; /* check we don't encode bpv > max(ulong)-1 as it is not currently supported by the algorithm */ @@ -511,7 +504,7 @@ int grib_accessor_class_data_simple_packing_t::pack_double(grib_accessor* a, con return GRIB_INVALID_BPV; } - self->dirty = 1; + dirty_ = 1; max = val[0]; min = max; @@ -529,34 +522,34 @@ int grib_accessor_class_data_simple_packing_t::pack_double(grib_accessor* a, con /* constant field only reference_value is set and bits_per_value=0 */ if (max == min) { int large_constant_fields = 0; - if (grib_get_nearest_smaller_value(gh, self->reference_value, val[0], &reference_value) != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to find nearest_smaller_value of %g for %s", min, self->reference_value); + if (grib_get_nearest_smaller_value(gh, reference_value_, val[0], &reference_value) != GRIB_SUCCESS) { + grib_context_log(context_, GRIB_LOG_ERROR, "Unable to find nearest_smaller_value of %g for %s", min, reference_value_); return GRIB_INTERNAL_ERROR; } - if ((err = grib_set_double_internal(gh, self->reference_value, reference_value)) != GRIB_SUCCESS) + if ((err = grib_set_double_internal(gh, reference_value_, reference_value)) != GRIB_SUCCESS) return err; { /* Make sure we can decode it again */ double ref = 1e-100; - grib_get_double_internal(gh, self->reference_value, &ref); + grib_get_double_internal(gh, reference_value_, &ref); if (ref != reference_value) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)", - cclass_name, __func__, self->reference_value, ref, reference_value); + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: %s (ref=%.10e != reference_value=%.10e)", + cclass_name, __func__, reference_value_, ref, reference_value); return GRIB_INTERNAL_ERROR; } } - large_constant_fields = grib_producing_large_constant_fields(gh, self->edition); + large_constant_fields = grib_producing_large_constant_fields(gh, edition_); if (large_constant_fields) { - if ((err = grib_set_long_internal(gh, self->binary_scale_factor, 0)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, binary_scale_factor_, 0)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->decimal_scale_factor, 0)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, decimal_scale_factor_, 0)) != GRIB_SUCCESS) return err; if (bits_per_value == 0) { - if ((err = grib_set_long_internal(gh, self->bits_per_value, 16)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, bits_per_value_, 16)) != GRIB_SUCCESS) return err; } @@ -564,29 +557,29 @@ int grib_accessor_class_data_simple_packing_t::pack_double(grib_accessor* a, con } else { bits_per_value = 0; - if ((err = grib_set_long_internal(gh, self->bits_per_value, bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, bits_per_value_, bits_per_value)) != GRIB_SUCCESS) return err; return GRIB_CONSTANT_FIELD; } } - if ((err = grib_get_long_internal(gh, self->binary_scale_factor, &binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->changing_precision, &changing_precision)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, changing_precision_, &changing_precision)) != GRIB_SUCCESS) return err; /* the packing parameters are not properly defined, this is a safe way of fixing the problem */ if (changing_precision == 0 && bits_per_value == 0 && decimal_scale_factor_get == 0) { - grib_context_log(a->context, GRIB_LOG_WARNING, + grib_context_log(context_, GRIB_LOG_WARNING, "%s==0 and %s==0 (setting %s=24)", - self->bits_per_value, - self->decimal_scale_factor, - self->bits_per_value); + bits_per_value_, + decimal_scale_factor_, + bits_per_value_); bits_per_value = 24; - if ((err = grib_set_long_internal(gh, self->bits_per_value, bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, bits_per_value_, bits_per_value)) != GRIB_SUCCESS) return err; } @@ -602,38 +595,38 @@ int grib_accessor_class_data_simple_packing_t::pack_double(grib_accessor* a, con /* See GRIB-540 for why we use ceil */ err = number_of_bits((unsigned long)ceil(fabs(max - min)), &bits_per_value); if (err) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: Range of values too large. Try a smaller value for decimal precision (less than %ld)", cclass_name, __func__, decimal_scale_factor); return err; } - if ((err = grib_set_long_internal(gh, self->bits_per_value, bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, bits_per_value_, bits_per_value)) != GRIB_SUCCESS) return err; - if (grib_get_nearest_smaller_value(gh, self->reference_value, min, &reference_value) != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Unable to find nearest_smaller_value of %g for %s", min, self->reference_value); + if (grib_get_nearest_smaller_value(gh, reference_value_, min, &reference_value) != GRIB_SUCCESS) { + grib_context_log(context_, GRIB_LOG_ERROR, + "Unable to find nearest_smaller_value of %g for %s", min, reference_value_); return GRIB_INTERNAL_ERROR; } /* divisor=1; */ } else { int last = 127; /* 'last' should be a parameter coming from a definitions file */ - if (c->gribex_mode_on && self->edition == 1) + if (c->gribex_mode_on && edition_ == 1) last = 99; /* bits_per_value is given and decimal_scale_factor and binary_scale_factor are calcualated */ if (max == min) { binary_scale_factor = 0; /* divisor=1; */ - if (grib_get_nearest_smaller_value(gh, self->reference_value, min, &reference_value) != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Unable to find nearest_smaller_value of %g for %s", min, self->reference_value); + if (grib_get_nearest_smaller_value(gh, reference_value_, min, &reference_value) != GRIB_SUCCESS) { + grib_context_log(context_, GRIB_LOG_ERROR, + "Unable to find nearest_smaller_value of %g for %s", min, reference_value_); return GRIB_INTERNAL_ERROR; } } else if (optimize_scaling_factor) { - int compat_gribex = c->gribex_mode_on && self->edition == 1; - if ((err = grib_optimize_decimal_factor(a, self->reference_value, + int compat_gribex = c->gribex_mode_on && edition_ == 1; + if ((err = grib_optimize_decimal_factor(this, reference_value_, max, min, bits_per_value, compat_gribex, 1, &decimal_scale_factor, &binary_scale_factor, &reference_value)) != GRIB_SUCCESS) @@ -664,9 +657,9 @@ int grib_accessor_class_data_simple_packing_t::pack_double(grib_accessor* a, con range = (max - min); } - if (grib_get_nearest_smaller_value(gh, self->reference_value, + if (grib_get_nearest_smaller_value(gh, reference_value_, min, &reference_value) != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to find nearest_smaller_value of %g for %s", min, self->reference_value); + grib_context_log(context_, GRIB_LOG_ERROR, "Unable to find nearest_smaller_value of %g for %s", min, reference_value_); return GRIB_INTERNAL_ERROR; } @@ -675,13 +668,13 @@ int grib_accessor_class_data_simple_packing_t::pack_double(grib_accessor* a, con } } - if ((err = grib_set_double_internal(gh, self->reference_value, reference_value)) != GRIB_SUCCESS) + if ((err = grib_set_double_internal(gh, reference_value_, reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->changing_precision, 0)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, changing_precision_, 0)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->binary_scale_factor, binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, binary_scale_factor_, binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(gh, self->decimal_scale_factor, decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(gh, decimal_scale_factor_, decimal_scale_factor)) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_data_simple_packing.h b/src/accessor/grib_accessor_class_data_simple_packing.h index 3e50239a0..6de820ebc 100644 --- a/src/accessor/grib_accessor_class_data_simple_packing.h +++ b/src/accessor/grib_accessor_class_data_simple_packing.h @@ -16,30 +16,27 @@ class grib_accessor_data_simple_packing_t : public grib_accessor_values_t { public: - /* 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; -}; - -class grib_accessor_class_data_simple_packing_t : public grib_accessor_class_values_t -{ -public: - grib_accessor_class_data_simple_packing_t(const char* name) : grib_accessor_class_values_t(name) {} + grib_accessor_data_simple_packing_t() : + grib_accessor_values_t() { class_name_ = "data_simple_packing"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_data_simple_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; - int unpack_double_subarray(grib_accessor*, double* val, size_t start, size_t len) override; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_float(float* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + int unpack_double_element(size_t i, double* val) override; + int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; + int unpack_double_subarray(double* val, size_t start, size_t len) override; + +public: + 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_; }; diff --git a/src/accessor/grib_accessor_class_decimal_precision.cc b/src/accessor/grib_accessor_class_decimal_precision.cc index 05d156ad1..cff70e669 100644 --- a/src/accessor/grib_accessor_class_decimal_precision.cc +++ b/src/accessor/grib_accessor_class_decimal_precision.cc @@ -10,57 +10,52 @@ #include "grib_accessor_class_decimal_precision.h" -grib_accessor_class_decimal_precision_t _grib_accessor_class_decimal_precision{ "decimal_precision" }; -grib_accessor_class* grib_accessor_class_decimal_precision = &_grib_accessor_class_decimal_precision; +grib_accessor_decimal_precision_t _grib_accessor_decimal_precision{}; +grib_accessor* grib_accessor_decimal_precision = &_grib_accessor_decimal_precision; - -void grib_accessor_class_decimal_precision_t::init(grib_accessor* a, const long l, grib_arguments* args) +void grib_accessor_decimal_precision_t::init(const long l, grib_arguments* args) { - grib_accessor_class_long_t::init(a, l, args); - grib_accessor_decimal_precision_t* self = (grib_accessor_decimal_precision_t*)a; - + grib_accessor_long_t::init(l, args); int n = 0; - self->bits_per_value = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->decimal_scale_factor = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->changing_precision = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; + bits_per_value_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + decimal_scale_factor_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + changing_precision_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + length_ = 0; } -int grib_accessor_class_decimal_precision_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_decimal_precision_t::unpack_long(long* val, size_t* len) { - grib_accessor_decimal_precision_t* self = (grib_accessor_decimal_precision_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + int ret = 0; + grib_handle* h = grib_handle_of_accessor(this); - int ret = GRIB_SUCCESS; - if ((ret = grib_get_long_internal(h, self->decimal_scale_factor, val)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, decimal_scale_factor_, val)) != GRIB_SUCCESS) return ret; *len = 1; return ret; } -int grib_accessor_class_decimal_precision_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_decimal_precision_t::pack_long(const long* val, size_t* len) { - grib_accessor_decimal_precision_t* self = (grib_accessor_decimal_precision_t*)a; - long bitsPerValue = 0; double* values = NULL; size_t size = 0; int ret = 0; - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); + grib_context* c = context_; + grib_handle* h = grib_handle_of_accessor(this); - if (!self->values) { - if ((ret = grib_set_long_internal(h, self->bits_per_value, 0)) != GRIB_SUCCESS) + if (!values_) { + if ((ret = grib_set_long_internal(h, bits_per_value_, 0)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(h, self->decimal_scale_factor, *val)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(h, decimal_scale_factor_, *val)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(h, self->changing_precision, 1)) != GRIB_SUCCESS) { + if ((ret = grib_set_long_internal(h, changing_precision_, 1)) != GRIB_SUCCESS) { grib_context_free(c, values); return ret; } @@ -68,34 +63,34 @@ int grib_accessor_class_decimal_precision_t::pack_long(grib_accessor* a, const l return GRIB_SUCCESS; } - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + if ((ret = grib_get_size(h, 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) { + if ((ret = grib_get_double_array_internal(h, values_, values, &size)) != GRIB_SUCCESS) { grib_context_buffer_free(c, values); return ret; } - if ((ret = grib_set_long_internal(h, self->decimal_scale_factor, *val)) != GRIB_SUCCESS) { + if ((ret = grib_set_long_internal(h, decimal_scale_factor_, *val)) != GRIB_SUCCESS) { grib_context_buffer_free(c, values); return ret; } - if ((ret = grib_set_long_internal(h, self->bits_per_value, bitsPerValue)) != GRIB_SUCCESS) { + if ((ret = grib_set_long_internal(h, bits_per_value_, bitsPerValue)) != GRIB_SUCCESS) { grib_context_free(c, values); return ret; } - if ((ret = grib_set_long_internal(h, self->changing_precision, 1)) != GRIB_SUCCESS) { + if ((ret = grib_set_long_internal(h, changing_precision_, 1)) != GRIB_SUCCESS) { grib_context_free(c, values); return ret; } - if ((ret = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) { + if ((ret = grib_set_double_array_internal(h, values_, values, size)) != GRIB_SUCCESS) { grib_context_buffer_free(c, values); return ret; } diff --git a/src/accessor/grib_accessor_class_decimal_precision.h b/src/accessor/grib_accessor_class_decimal_precision.h index a6b6d4839..493bb500a 100644 --- a/src/accessor/grib_accessor_class_decimal_precision.h +++ b/src/accessor/grib_accessor_class_decimal_precision.h @@ -15,19 +15,16 @@ class grib_accessor_decimal_precision_t : public grib_accessor_long_t { public: - /* Members defined in decimal_precision */ - const char* values; - const char* bits_per_value; - const char* changing_precision; - const char* decimal_scale_factor; -}; - -class grib_accessor_class_decimal_precision_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_decimal_precision_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_decimal_precision_t() : + grib_accessor_long_t() { class_name_ = "decimal_precision"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_decimal_precision_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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* values_; + const char* bits_per_value_; + const char* changing_precision_; + const char* decimal_scale_factor_; }; diff --git a/src/accessor/grib_accessor_class_dictionary.cc b/src/accessor/grib_accessor_class_dictionary.cc index 617bc8a75..bdaf20eb7 100644 --- a/src/accessor/grib_accessor_class_dictionary.cc +++ b/src/accessor/grib_accessor_class_dictionary.cc @@ -11,24 +11,22 @@ #include "grib_accessor_class_dictionary.h" -grib_accessor_class_dictionary_t _grib_accessor_class_dictionary{ "dictionary" }; -grib_accessor_class* grib_accessor_class_dictionary = &_grib_accessor_class_dictionary; +grib_accessor_dictionary_t _grib_accessor_dictionary{}; +grib_accessor* grib_accessor_dictionary = &_grib_accessor_dictionary; - -void grib_accessor_class_dictionary_t::init(grib_accessor* a, const long len, grib_arguments* params) +void grib_accessor_dictionary_t::init(const long len, grib_arguments* params) { - grib_accessor_class_gen_t::init(a, len, params); - int n = 0; - grib_accessor_dictionary_t* self = (grib_accessor_dictionary_t*)a; + grib_accessor_gen_t::init(len, params); + int n = 0; - self->dictionary = grib_arguments_get_string(grib_handle_of_accessor(a), params, n++); - self->key = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); - self->column = grib_arguments_get_long(grib_handle_of_accessor(a), params, n++); - self->masterDir = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); - self->localDir = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); + dictionary_ = grib_arguments_get_string(grib_handle_of_accessor(this), params, n++); + key_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++); + column_ = grib_arguments_get_long(grib_handle_of_accessor(this), params, n++); + masterDir_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++); + localDir_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } static grib_trie* load_dictionary(grib_accessor* a, int* err) @@ -36,11 +34,21 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err) grib_accessor_dictionary_t* self = (grib_accessor_dictionary_t*)a; char* filename = NULL; - char line[1024] = {0,}; - char key[1024] = {0,}; - char masterDir[1024] = {0,}; - char localDir[1024] = {0,}; - char dictName[1024] = {0,}; + char line[1024] = { + 0, + }; + char key[1024] = { + 0, + }; + char masterDir[1024] = { + 0, + }; + char localDir[1024] = { + 0, + }; + char dictName[1024] = { + 0, + }; char* localFilename = 0; char* list = 0; size_t len = 1024; @@ -48,32 +56,40 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err) FILE* f = NULL; int i = 0; grib_handle* h = grib_handle_of_accessor(a); - grib_context* c = a->context; + grib_context* c = a->context_; *err = GRIB_SUCCESS; len = 1024; - if (self->masterDir != NULL) - grib_get_string(h, self->masterDir, masterDir, &len); + if (self->masterDir_ != NULL) + grib_get_string(h, self->masterDir_, masterDir, &len); len = 1024; - if (self->localDir != NULL) - grib_get_string(h, self->localDir, localDir, &len); + if (self->localDir_ != NULL) + grib_get_string(h, self->localDir_, localDir, &len); if (*masterDir != 0) { - char name[2048] = {0,}; - char recomposed[2048] = {0,}; - snprintf(name, sizeof(name), "%s/%s", masterDir, self->dictionary); + char name[2048] = { + 0, + }; + char recomposed[2048] = { + 0, + }; + snprintf(name, sizeof(name), "%s/%s", masterDir, self->dictionary_); grib_recompose_name(h, NULL, name, recomposed, 0); filename = grib_context_full_defs_path(c, recomposed); } else { - filename = grib_context_full_defs_path(c, self->dictionary); + filename = grib_context_full_defs_path(c, self->dictionary_); } if (*localDir != 0) { - char localName[2048] = {0,}; - char localRecomposed[1024] = {0,}; - snprintf(localName, sizeof(localName), "%s/%s", localDir, self->dictionary); + char localName[2048] = { + 0, + }; + char localRecomposed[1024] = { + 0, + }; + snprintf(localName, sizeof(localName), "%s/%s", localDir, self->dictionary_); grib_recompose_name(h, NULL, localName, localRecomposed, 0); localFilename = grib_context_full_defs_path(c, localRecomposed); snprintf(dictName, sizeof(dictName), "%s:%s", localFilename, filename); @@ -83,7 +99,7 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err) } if (!filename) { - grib_context_log(c, GRIB_LOG_ERROR, "Unable to find def file %s", self->dictionary); + grib_context_log(c, GRIB_LOG_ERROR, "Unable to find def file %s", self->dictionary_); *err = GRIB_FILE_NOT_FOUND; return NULL; } @@ -92,11 +108,11 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err) } dictionary = (grib_trie*)grib_trie_get(c->lists, dictName); if (dictionary) { - grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from cache", self->dictionary); + grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from cache", self->dictionary_); return dictionary; } else { - grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from file %s", self->dictionary, filename); + grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from file %s", self->dictionary_, filename); } f = codes_fopen(filename, "r"); @@ -140,33 +156,33 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err) grib_trie_insert(dictionary, key, list); } - fclose(f); } grib_trie_insert(c->lists, filename, dictionary); return dictionary; } -void grib_accessor_class_dictionary_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_dictionary_t::dump(grib_dumper* dumper) { - switch (get_native_type(a)) { + switch (get_native_type()) { case GRIB_TYPE_STRING: - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); break; case GRIB_TYPE_LONG: - grib_dump_long(dumper, a, NULL); + grib_dump_long(dumper, this, NULL); break; case GRIB_TYPE_DOUBLE: - grib_dump_double(dumper, a, NULL); + grib_dump_double(dumper, this, NULL); break; } } -int grib_accessor_class_dictionary_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) +int grib_accessor_dictionary_t::unpack_string(char* buffer, size_t* len) { - grib_accessor_dictionary_t* self = (grib_accessor_dictionary_t*)a; - int err = GRIB_SUCCESS; - char key[1024] = {0,}; + int err = GRIB_SUCCESS; + char key[1024] = { + 0, + }; size_t size = 1024; char* list = NULL; char* start = NULL; @@ -174,11 +190,11 @@ int grib_accessor_class_dictionary_t::unpack_string(grib_accessor* a, char* buff size_t rsize = 0; int i = 0; - grib_trie* dictionary = load_dictionary(a, &err); + grib_trie* dictionary = load_dictionary(this, &err); if (err) return err; - if ((err = grib_get_string_internal(grib_handle_of_accessor(a), self->key, key, &size)) != GRIB_SUCCESS) { + if ((err = grib_get_string_internal(grib_handle_of_accessor(this), key_, key, &size)) != GRIB_SUCCESS) { /* grib_trie_delete(dictionary); */ return err; } @@ -190,7 +206,7 @@ int grib_accessor_class_dictionary_t::unpack_string(grib_accessor* a, char* buff } end = list; - for (i = 0; i <= self->column; i++) { + for (i = 0; i <= column_; i++) { start = end; while (*end != '|' && *end != 0) end++; @@ -217,29 +233,31 @@ int grib_accessor_class_dictionary_t::unpack_string(grib_accessor* a, char* buff return err; } -int grib_accessor_class_dictionary_t::value_count(grib_accessor* a, long* count) +int grib_accessor_dictionary_t::value_count(long* count) { *count = 1; return 0; } -int grib_accessor_class_dictionary_t::get_native_type(grib_accessor* a) +long grib_accessor_dictionary_t::get_native_type() { int type = GRIB_TYPE_DOUBLE; - if (a->flags & GRIB_ACCESSOR_FLAG_LONG_TYPE) + if (flags_ & GRIB_ACCESSOR_FLAG_LONG_TYPE) type = GRIB_TYPE_LONG; - if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE) + if (flags_ & GRIB_ACCESSOR_FLAG_STRING_TYPE) type = GRIB_TYPE_STRING; return type; } -int grib_accessor_class_dictionary_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_dictionary_t::unpack_long(long* val, size_t* len) { int err = 0; - char buffer[1024] = {0,}; + char buffer[1024] = { + 0, + }; size_t size = 1024; - err = unpack_string(a, buffer, &size); + err = unpack_string(buffer, &size); if (err) return err; @@ -249,13 +267,15 @@ int grib_accessor_class_dictionary_t::unpack_long(grib_accessor* a, long* val, s return GRIB_SUCCESS; } -int grib_accessor_class_dictionary_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_dictionary_t::unpack_double(double* val, size_t* len) { int err = 0; - char buffer[1024] = {0,}; + char buffer[1024] = { + 0, + }; size_t size = 1024; - err = unpack_string(a, buffer, &size); + err = unpack_string(buffer, &size); if (err) return err; diff --git a/src/accessor/grib_accessor_class_dictionary.h b/src/accessor/grib_accessor_class_dictionary.h index 8dc976e51..dd1fba934 100644 --- a/src/accessor/grib_accessor_class_dictionary.h +++ b/src/accessor/grib_accessor_class_dictionary.h @@ -15,24 +15,21 @@ class grib_accessor_dictionary_t : public grib_accessor_gen_t { public: - /* Members defined in dictionary */ - const char* dictionary; - const char* key; - long column; - const char* masterDir; - const char* localDir; -}; - -class grib_accessor_class_dictionary_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_dictionary_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_dictionary_t() : + grib_accessor_gen_t() { class_name_ = "dictionary"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_dictionary_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 dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + int value_count(long*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +public: + const char* dictionary_; + const char* key_; + long column_; + const char* masterDir_; + const char* localDir_; }; diff --git a/src/accessor/grib_accessor_class_dirty.cc b/src/accessor/grib_accessor_class_dirty.cc index 80c51835e..f743957f3 100644 --- a/src/accessor/grib_accessor_class_dirty.cc +++ b/src/accessor/grib_accessor_class_dirty.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,42 +10,39 @@ #include "grib_accessor_class_dirty.h" -grib_accessor_class_dirty_t _grib_accessor_class_dirty{ "dirty" }; -grib_accessor_class* grib_accessor_class_dirty = &_grib_accessor_class_dirty; +grib_accessor_dirty_t _grib_accessor_dirty{}; +grib_accessor* grib_accessor_dirty = &_grib_accessor_dirty; - -void grib_accessor_class_dirty_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_dirty_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_dirty_t* self = (grib_accessor_dirty_t*)a; - self->accessor = grib_arguments_get_name(grib_handle_of_accessor(a), c, 0); - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; - a->length = 0; + grib_accessor_long_t::init(l, c); + accessor_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, 0); + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + flags_ |= GRIB_ACCESSOR_FLAG_HIDDEN; + length_ = 0; } -int grib_accessor_class_dirty_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_dirty_t::pack_long(const long* val, size_t* len) { - grib_accessor_dirty_t* self = (grib_accessor_dirty_t*)a; - grib_accessor* x = grib_find_accessor(grib_handle_of_accessor(a), self->accessor); + grib_accessor* x = grib_find_accessor(grib_handle_of_accessor(this), accessor_); + + if (x) + x->dirty_ = *val; - if (x) { - //printf("\ngrib_accessor_class_dirty_t::pack_long: Setting dirty to %ld on %s\n", *val, x->name); - x->dirty = *val; - } return GRIB_SUCCESS; } -int grib_accessor_class_dirty_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_dirty_t::unpack_long(long* val, size_t* len) { - grib_accessor_dirty_t* self = (grib_accessor_dirty_t*)a; - grib_accessor* x = grib_find_accessor(grib_handle_of_accessor(a), self->accessor); + grib_accessor* x = grib_find_accessor(grib_handle_of_accessor(this), accessor_); if (x) { - //printf("\ngrib_accessor_class_dirty_t::unpack_long: Getting dirty for %s\n", x->name); - *val = x->dirty; - } else { + // printf("\ngrib_accessor_class_dirty_t::unpack_long: Getting dirty for %s\n", x->name); + *val = x->dirty_; + } + else { *val = 1; } + return GRIB_SUCCESS; } diff --git a/src/accessor/grib_accessor_class_dirty.h b/src/accessor/grib_accessor_class_dirty.h index b024b69f7..ff10e8a5f 100644 --- a/src/accessor/grib_accessor_class_dirty.h +++ b/src/accessor/grib_accessor_class_dirty.h @@ -15,16 +15,13 @@ class grib_accessor_dirty_t : public grib_accessor_long_t { public: - /* Members defined in dirty */ - const char* accessor; -}; - -class grib_accessor_class_dirty_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_dirty_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_dirty_t() : + grib_accessor_long_t() { class_name_ = "dirty"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_dirty_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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* accessor_; }; diff --git a/src/accessor/grib_accessor_class_divdouble.cc b/src/accessor/grib_accessor_class_divdouble.cc index 49e675230..a2edac314 100644 --- a/src/accessor/grib_accessor_class_divdouble.cc +++ b/src/accessor/grib_accessor_class_divdouble.cc @@ -11,34 +11,31 @@ #include "grib_accessor_class_divdouble.h" -grib_accessor_class_divdouble_t _grib_accessor_class_divdouble{ "divdouble" }; -grib_accessor_class* grib_accessor_class_divdouble = &_grib_accessor_class_divdouble; +grib_accessor_divdouble_t _grib_accessor_divdouble{}; +grib_accessor* grib_accessor_divdouble = &_grib_accessor_divdouble; - -void grib_accessor_class_divdouble_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_divdouble_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_divdouble_t* self = (grib_accessor_divdouble_t*)a; + grib_accessor_double_t::init(l, c); int n = 0; - self->val = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->divisor = grib_arguments_get_double(grib_handle_of_accessor(a), c, n++); + val_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + divisor_ = grib_arguments_get_double(grib_handle_of_accessor(this), c, n++); } -int grib_accessor_class_divdouble_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_divdouble_t::unpack_double(double* val, size_t* len) { - const grib_accessor_divdouble_t* self = (grib_accessor_divdouble_t*)a; - int ret = GRIB_SUCCESS; + int ret = GRIB_SUCCESS; double value = 0; - ret = grib_get_double_internal(grib_handle_of_accessor(a), self->val, &value); + ret = grib_get_double_internal(grib_handle_of_accessor(this), val_, &value); if (ret != GRIB_SUCCESS) return ret; - if (self->divisor == 0) { + if (divisor_ == 0) { return GRIB_INVALID_ARGUMENT; } - *val = value / self->divisor; + *val = value / divisor_; *len = 1; return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_divdouble.h b/src/accessor/grib_accessor_class_divdouble.h index 9408b073a..ea4a344e4 100644 --- a/src/accessor/grib_accessor_class_divdouble.h +++ b/src/accessor/grib_accessor_class_divdouble.h @@ -15,16 +15,13 @@ class grib_accessor_divdouble_t : public grib_accessor_double_t { public: - /* Members defined in divdouble */ - const char* val; - double divisor; -}; - -class grib_accessor_class_divdouble_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_divdouble_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_divdouble_t() : + grib_accessor_double_t() { class_name_ = "divdouble"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_divdouble_t{}; } - int unpack_double(grib_accessor*, double* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_double(double* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* val_; + double divisor_; }; diff --git a/src/accessor/grib_accessor_class_double.cc b/src/accessor/grib_accessor_class_double.cc index 2a78446bc..c77242efb 100644 --- a/src/accessor/grib_accessor_class_double.cc +++ b/src/accessor/grib_accessor_class_double.cc @@ -11,26 +11,25 @@ #include "grib_accessor_class_double.h" -grib_accessor_class_double_t _grib_accessor_class_double{ "double" }; -grib_accessor_class* grib_accessor_class_double = &_grib_accessor_class_double; +grib_accessor_double_t _grib_accessor_double{}; +grib_accessor* grib_accessor_double = &_grib_accessor_double; - -int grib_accessor_class_double_t::get_native_type(grib_accessor* a) +long grib_accessor_double_t::get_native_type() { return GRIB_TYPE_DOUBLE; } -int grib_accessor_class_double_t::unpack_string(grib_accessor* a, char* v, size_t* len) +int grib_accessor_double_t::unpack_string(char* v, size_t* len) { double val = 0; size_t l = 1; char repres[1024]; char format[32] = "%g"; - grib_handle* h = grib_handle_of_accessor(a); - const char* cclass_name = a->cclass->name; + grib_handle* h = grib_handle_of_accessor(this); + const char* cclass_name = class_name_; - a->unpack_double(&val, &l); - if ((val == GRIB_MISSING_DOUBLE) && ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0)) { + unpack_double(&val, &l); + if ((val == GRIB_MISSING_DOUBLE) && ((flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0)) { snprintf(repres, sizeof(repres), "MISSING"); } else { @@ -42,13 +41,13 @@ int grib_accessor_class_double_t::unpack_string(grib_accessor* a, char* v, size_ l = strlen(repres) + 1; if (l > *len) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, l, *len); + cclass_name, name_, l, *len); *len = l; return GRIB_BUFFER_TOO_SMALL; } - grib_context_log(a->context, GRIB_LOG_DEBUG, "grib_accessor_long: Casting double %s to string ", a->name); + grib_context_log(context_, GRIB_LOG_DEBUG, "grib_accessor_long: Casting double %s to string ", name_); *len = l; @@ -56,12 +55,12 @@ int grib_accessor_class_double_t::unpack_string(grib_accessor* a, char* v, size_ return GRIB_SUCCESS; } -void grib_accessor_class_double_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_double_t::dump(grib_dumper* dumper) { - grib_dump_values(dumper, a); + grib_dump_values(dumper, this); } -int grib_accessor_class_double_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_double_t::compare(grib_accessor* b) { int retval = 0; double* aval = 0; @@ -72,7 +71,7 @@ int grib_accessor_class_double_t::compare(grib_accessor* a, grib_accessor* b) long count = 0; int err = 0; - err = a->value_count(&count); + err = value_count(&count); if (err) return err; alen = count; @@ -85,10 +84,10 @@ int grib_accessor_class_double_t::compare(grib_accessor* a, grib_accessor* b) if (alen != blen) return GRIB_COUNT_MISMATCH; - aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); - bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); + aval = (double*)grib_context_malloc(context_, alen * sizeof(double)); + bval = (double*)grib_context_malloc(b->context_, blen * sizeof(double)); - a->unpack_double(aval, &alen); + unpack_double(aval, &alen); b->unpack_double(bval, &blen); retval = GRIB_SUCCESS; while (alen != 0) { @@ -97,18 +96,18 @@ int grib_accessor_class_double_t::compare(grib_accessor* a, grib_accessor* b) alen--; } - grib_context_free(a->context, aval); - grib_context_free(b->context, bval); + grib_context_free(context_, aval); + grib_context_free(b->context_, bval); return retval; } -int grib_accessor_class_double_t::pack_missing(grib_accessor* a) +int grib_accessor_double_t::pack_missing() { size_t len = 1; double value = GRIB_MISSING_DOUBLE; - if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) - return a->pack_double(&value, &len); + if (flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) + return pack_double(&value, &len); return GRIB_VALUE_CANNOT_BE_MISSING; } diff --git a/src/accessor/grib_accessor_class_double.h b/src/accessor/grib_accessor_class_double.h index 7ad9771c2..539d550ee 100644 --- a/src/accessor/grib_accessor_class_double.h +++ b/src/accessor/grib_accessor_class_double.h @@ -12,16 +12,15 @@ #include "grib_accessor_class_gen.h" -class grib_accessor_double_t : public grib_accessor_gen_t {}; - -class grib_accessor_class_double_t : public grib_accessor_class_gen_t +class grib_accessor_double_t : public grib_accessor_gen_t { public: - grib_accessor_class_double_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_double_t() : + grib_accessor_gen_t() { class_name_ = "double"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_double_t{}; } - int get_native_type(grib_accessor*) override; - int pack_missing(grib_accessor*) override; - int unpack_string(grib_accessor*, char*, size_t* len) override; - void dump(grib_accessor*, grib_dumper*) override; - int compare(grib_accessor*, grib_accessor*) override; + long get_native_type() override; + int pack_missing() override; + int unpack_string(char*, size_t* len) override; + void dump(grib_dumper*) override; + int compare(grib_accessor*) override; }; diff --git a/src/accessor/grib_accessor_class_element.cc b/src/accessor/grib_accessor_class_element.cc index 3d150d79e..dbfd0164d 100644 --- a/src/accessor/grib_accessor_class_element.cc +++ b/src/accessor/grib_accessor_class_element.cc @@ -11,19 +11,17 @@ #include "grib_accessor_class_element.h" -grib_accessor_class_element_t _grib_accessor_class_element{"element"}; -grib_accessor_class* grib_accessor_class_element = &_grib_accessor_class_element; +grib_accessor_element_t _grib_accessor_element{}; +grib_accessor* grib_accessor_element = &_grib_accessor_element; - -void grib_accessor_class_element_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_element_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_element_t* self = (grib_accessor_element_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_accessor_long_t::init(l, c); + grib_handle* hand = grib_handle_of_accessor(this); - int n = 0; - self->array = grib_arguments_get_name(hand, c, n++); - self->element = grib_arguments_get_long(hand, c, n++); + int n = 0; + array_ = grib_arguments_get_name(hand, c, n++); + element_ = grib_arguments_get_long(hand, c, n++); } static int check_element_index(const char* func, const char* array_name, long index, size_t size) @@ -31,28 +29,27 @@ static int check_element_index(const char* func, const char* array_name, long in const grib_context* c = grib_context_get_default(); if (index < 0 || index >= size) { grib_context_log(c, GRIB_LOG_ERROR, "%s: Invalid element index %ld for array '%s'. Value must be between 0 and %zu", - func, index, array_name, size - 1); + func, index, array_name, size - 1); return GRIB_INVALID_ARGUMENT; } return GRIB_SUCCESS; } -int grib_accessor_class_element_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_element_t::unpack_long(long* val, size_t* len) { - grib_accessor_element_t* self = (grib_accessor_element_t*)a; - int ret = 0; - size_t size = 0; - long* ar = NULL; - const grib_context* c = a->context; - grib_handle* hand = grib_handle_of_accessor(a); - long index = self->element; + int ret = 0; + size_t size = 0; + long* ar = NULL; + const grib_context* c = context_; + grib_handle* hand = grib_handle_of_accessor(this); + long index = element_; if (*len < 1) { ret = GRIB_ARRAY_TOO_SMALL; return ret; } - if ((ret = grib_get_size(hand, self->array, &size)) != GRIB_SUCCESS) + if ((ret = grib_get_size(hand, array_, &size)) != GRIB_SUCCESS) return ret; ar = (long*)grib_context_malloc_clear(c, size * sizeof(long)); @@ -61,7 +58,7 @@ int grib_accessor_class_element_t::unpack_long(grib_accessor* a, long* val, size return GRIB_OUT_OF_MEMORY; } - if ((ret = grib_get_long_array_internal(hand, self->array, ar, &size)) != GRIB_SUCCESS) + if ((ret = grib_get_long_array_internal(hand, array_, ar, &size)) != GRIB_SUCCESS) return ret; // An index of -x means the xth item from the end of the list, so ar[-1] means the last item in ar @@ -69,7 +66,7 @@ int grib_accessor_class_element_t::unpack_long(grib_accessor* a, long* val, size index = size + index; } - if ((ret = check_element_index(__func__, self->array, index, size)) != GRIB_SUCCESS) { + if ((ret = check_element_index(__func__, array_, index, size)) != GRIB_SUCCESS) { goto the_end; } @@ -80,22 +77,21 @@ the_end: return ret; } -int grib_accessor_class_element_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_element_t::pack_long(const long* val, size_t* len) { - grib_accessor_element_t* self = (grib_accessor_element_t*)a; - int ret = 0; - size_t size = 0; - long* ar = NULL; - const grib_context* c = a->context; - grib_handle* hand = grib_handle_of_accessor(a); - long index = self->element; + int ret = 0; + size_t size = 0; + long* ar = NULL; + const grib_context* c = context_; + grib_handle* hand = grib_handle_of_accessor(this); + long index = element_; if (*len < 1) { ret = GRIB_ARRAY_TOO_SMALL; return ret; } - if ((ret = grib_get_size(hand, self->array, &size)) != GRIB_SUCCESS) + if ((ret = grib_get_size(hand, array_, &size)) != GRIB_SUCCESS) return ret; ar = (long*)grib_context_malloc_clear(c, size * sizeof(long)); @@ -104,7 +100,7 @@ int grib_accessor_class_element_t::pack_long(grib_accessor* a, const long* val, return GRIB_OUT_OF_MEMORY; } - if ((ret = grib_get_long_array_internal(hand, self->array, ar, &size)) != GRIB_SUCCESS) + if ((ret = grib_get_long_array_internal(hand, array_, ar, &size)) != GRIB_SUCCESS) return ret; // An index of -x means the xth item from the end of the list, so ar[-1] means the last item in ar @@ -112,7 +108,7 @@ int grib_accessor_class_element_t::pack_long(grib_accessor* a, const long* val, index = size + index; } - if ((ret = check_element_index(__func__, self->array, index, size)) != GRIB_SUCCESS) { + if ((ret = check_element_index(__func__, array_, index, size)) != GRIB_SUCCESS) { goto the_end; } @@ -120,7 +116,7 @@ int grib_accessor_class_element_t::pack_long(grib_accessor* a, const long* val, Assert(index < size); ar[index] = *val; - if ((ret = grib_set_long_array_internal(hand, self->array, ar, size)) != GRIB_SUCCESS) + if ((ret = grib_set_long_array_internal(hand, array_, ar, size)) != GRIB_SUCCESS) goto the_end; the_end: @@ -128,22 +124,21 @@ the_end: return ret; } -int grib_accessor_class_element_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_element_t::unpack_double(double* val, size_t* len) { - grib_accessor_element_t* self = (grib_accessor_element_t*)a; - int ret = 0; - size_t size = 0; - double* ar = NULL; - const grib_context* c = a->context; - const grib_handle* hand = grib_handle_of_accessor(a); - long index = self->element; + int ret = 0; + size_t size = 0; + double* ar = NULL; + const grib_context* c = context_; + const grib_handle* hand = grib_handle_of_accessor(this); + long index = element_; if (*len < 1) { ret = GRIB_ARRAY_TOO_SMALL; return ret; } - if ((ret = grib_get_size(hand, self->array, &size)) != GRIB_SUCCESS) + if ((ret = grib_get_size(hand, array_, &size)) != GRIB_SUCCESS) return ret; ar = (double*)grib_context_malloc_clear(c, size * sizeof(double)); @@ -152,7 +147,7 @@ int grib_accessor_class_element_t::unpack_double(grib_accessor* a, double* val, return GRIB_OUT_OF_MEMORY; } - if ((ret = grib_get_double_array_internal(hand, self->array, ar, &size)) != GRIB_SUCCESS) + if ((ret = grib_get_double_array_internal(hand, array_, ar, &size)) != GRIB_SUCCESS) return ret; // An index of -x means the xth item from the end of the list, so ar[-1] means the last item in ar @@ -160,7 +155,7 @@ int grib_accessor_class_element_t::unpack_double(grib_accessor* a, double* val, index = size + index; } - if ((ret = check_element_index(__func__, self->array, index, size)) != GRIB_SUCCESS) { + if ((ret = check_element_index(__func__, array_, index, size)) != GRIB_SUCCESS) { goto the_end; } diff --git a/src/accessor/grib_accessor_class_element.h b/src/accessor/grib_accessor_class_element.h index 220b8ff84..4d8d17199 100644 --- a/src/accessor/grib_accessor_class_element.h +++ b/src/accessor/grib_accessor_class_element.h @@ -15,18 +15,15 @@ class grib_accessor_element_t : public grib_accessor_long_t { public: - /* Members defined in element */ - const char* array; - long element; -}; - -class grib_accessor_class_element_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_element_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_element_t() : + grib_accessor_long_t() { class_name_ = "element"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_element_t{}; } - int pack_long(grib_accessor*, const long* val, 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; - void init(grib_accessor*, const long, grib_arguments*) override; + int pack_long(const long* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* array_; + long element_; }; diff --git a/src/accessor/grib_accessor_class_evaluate.cc b/src/accessor/grib_accessor_class_evaluate.cc index 0312107a4..235d2aa9b 100644 --- a/src/accessor/grib_accessor_class_evaluate.cc +++ b/src/accessor/grib_accessor_class_evaluate.cc @@ -11,24 +11,21 @@ #include "grib_accessor_class_evaluate.h" -grib_accessor_class_evaluate_t _grib_accessor_class_evaluate{ "evaluate" }; -grib_accessor_class* grib_accessor_class_evaluate = &_grib_accessor_class_evaluate; +grib_accessor_evaluate_t _grib_accessor_evaluate{}; +grib_accessor* grib_accessor_evaluate = &_grib_accessor_evaluate; - -void grib_accessor_class_evaluate_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_evaluate_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_evaluate_t* self = (grib_accessor_evaluate_t*)a; - self->arg = c; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + grib_accessor_long_t::init(l, c); + arg_ = c; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_evaluate_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_evaluate_t::unpack_long(long* val, size_t* len) { - grib_accessor_evaluate_t* self = (grib_accessor_evaluate_t*)a; - grib_expression* e = grib_arguments_get_expression(grib_handle_of_accessor(a), self->arg, 0); + grib_expression* e = grib_arguments_get_expression(grib_handle_of_accessor(this), arg_, 0); - int ret = grib_expression_evaluate_long(grib_handle_of_accessor(a), e, val); + int ret = grib_expression_evaluate_long(grib_handle_of_accessor(this), e, val); *len = 1; return ret; diff --git a/src/accessor/grib_accessor_class_evaluate.h b/src/accessor/grib_accessor_class_evaluate.h index 0e40cf206..3156a683d 100644 --- a/src/accessor/grib_accessor_class_evaluate.h +++ b/src/accessor/grib_accessor_class_evaluate.h @@ -15,15 +15,12 @@ class grib_accessor_evaluate_t : public grib_accessor_long_t { public: - /* Members defined in evaluate */ - grib_arguments* arg; -}; - -class grib_accessor_class_evaluate_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_evaluate_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_evaluate_t() : + grib_accessor_long_t() { class_name_ = "evaluate"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_evaluate_t{}; } - int unpack_long(grib_accessor*, long* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +public: + grib_arguments* arg_; }; diff --git a/src/accessor/grib_accessor_class_expanded_descriptors.cc b/src/accessor/grib_accessor_class_expanded_descriptors.cc index b30e745a9..8a3501769 100644 --- a/src/accessor/grib_accessor_class_expanded_descriptors.cc +++ b/src/accessor/grib_accessor_class_expanded_descriptors.cc @@ -12,11 +12,10 @@ #include "grib_accessor_class_expanded_descriptors.h" #include "grib_scaling.h" -grib_accessor_class_expanded_descriptors_t _grib_accessor_class_expanded_descriptors{"expanded_descriptors"}; -grib_accessor_class* grib_accessor_class_expanded_descriptors = &_grib_accessor_class_expanded_descriptors; +grib_accessor_expanded_descriptors_t _grib_accessor_expanded_descriptors{}; +grib_accessor* grib_accessor_expanded_descriptors = &_grib_accessor_expanded_descriptors; - -#define MYDEBUG 0 +#define MYDEBUG 0 #define DESC_SIZE_INIT 400 /* Initial size for grib_bufr_descriptors_array_new */ #define DESC_SIZE_INCR 400 /* Increment size for grib_bufr_descriptors_array_new */ @@ -41,32 +40,33 @@ typedef struct change_coding_params result = grib_bufr_descriptors_array_pop_front(array); \ } -void grib_accessor_class_expanded_descriptors_t::init(grib_accessor* a, const long len, grib_arguments* args) +void grib_accessor_expanded_descriptors_t::init(const long len, grib_arguments* args) { - grib_accessor_class_long_t::init(a, len, args); - grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; - int n = 0; - grib_handle* hand = grib_handle_of_accessor(a); - self->tablesAccessorName = grib_arguments_get_name(hand, args, n++); - self->expandedName = grib_arguments_get_name(hand, args, n++); - self->rank = grib_arguments_get_long(hand, args, n++); - if (self->rank != 0) { - self->expandedAccessor = grib_find_accessor(hand, self->expandedName); + grib_accessor_long_t::init(len, args); + int n = 0; + grib_handle* hand = grib_handle_of_accessor(this); + tablesAccessorName_ = grib_arguments_get_name(hand, args, n++); + expandedName_ = grib_arguments_get_name(hand, args, n++); + rank_ = grib_arguments_get_long(hand, args, n++); + if (rank_ != 0) { + expandedAccessor_ = grib_find_accessor(hand, expandedName_); } else { - self->expandedAccessor = 0; + expandedAccessor_ = 0; } - self->unexpandedDescriptors = grib_arguments_get_name(hand, args, n++); - self->sequence = grib_arguments_get_name(hand, args, n++); - self->do_expand = 1; - self->expanded = 0; - a->length = 0; + unexpandedDescriptors_ = grib_arguments_get_name(hand, args, n++); + sequence_ = grib_arguments_get_name(hand, args, n++); + do_expand_ = 1; + expanded_ = 0; + length_ = 0; + + tablesAccessor_ = NULL; } static bufr_descriptors_array* do_expand(grib_accessor* a, bufr_descriptors_array* unexpanded, change_coding_params* ccp, int* err); #define BUFR_DESCRIPTORS_ARRAY_USED_SIZE(v) ((v)->n) -#define SILENT 1 +#define SILENT 1 #if MYDEBUG static int global_depth = -1; @@ -74,15 +74,24 @@ static int global_depth = -1; static char* descriptor_type_name(int dtype) { switch (dtype) { - case BUFR_DESCRIPTOR_TYPE_STRING: return "string"; - case BUFR_DESCRIPTOR_TYPE_LONG: return "long"; - case BUFR_DESCRIPTOR_TYPE_DOUBLE: return "double"; - case BUFR_DESCRIPTOR_TYPE_TABLE: return "table"; - case BUFR_DESCRIPTOR_TYPE_FLAG: return "flag"; - case BUFR_DESCRIPTOR_TYPE_UNKNOWN: return "unknown"; - case BUFR_DESCRIPTOR_TYPE_REPLICATION: return "replication"; - case BUFR_DESCRIPTOR_TYPE_OPERATOR: return "operator"; - case BUFR_DESCRIPTOR_TYPE_SEQUENCE: return "sequence"; + case BUFR_DESCRIPTOR_TYPE_STRING: + return "string"; + case BUFR_DESCRIPTOR_TYPE_LONG: + return "long"; + case BUFR_DESCRIPTOR_TYPE_DOUBLE: + return "double"; + case BUFR_DESCRIPTOR_TYPE_TABLE: + return "table"; + case BUFR_DESCRIPTOR_TYPE_FLAG: + return "flag"; + case BUFR_DESCRIPTOR_TYPE_UNKNOWN: + return "unknown"; + case BUFR_DESCRIPTOR_TYPE_REPLICATION: + return "replication"; + case BUFR_DESCRIPTOR_TYPE_OPERATOR: + return "operator"; + case BUFR_DESCRIPTOR_TYPE_SEQUENCE: + return "sequence"; } Assert(!"bufr_descriptor_type_name failed"); return "unknown"; @@ -91,19 +100,22 @@ static char* descriptor_type_name(int dtype) static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_descriptors_array* expanded, change_coding_params* ccp, int* err) { - int k, j, i; grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; - size_t size = 0; - long* v_array = NULL; - bufr_descriptor* u = NULL; - bufr_descriptor* vv = NULL; + + int k, j, i; + size_t size = 0; + long* v_array = NULL; + bufr_descriptor* u = NULL; + bufr_descriptor* vv = NULL; /* ECC-1422: 'ur' is the array of bufr_descriptor pointers for replications. * Its max size is X (from FXY) which is 6 bits so no need for malloc */ - bufr_descriptor* ur[65] = {0,}; + bufr_descriptor* ur[65] = { + 0, + }; bufr_descriptor* urc = NULL; size_t idx = 0; bufr_descriptor* u0 = NULL; - grib_context* c = a->context; + grib_context* c = a->context_; bufr_descriptor* us = NULL; bufr_descriptors_array* inner_expanded = NULL; bufr_descriptors_array* inner_unexpanded = NULL; @@ -115,7 +127,7 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_ if (BUFR_DESCRIPTORS_ARRAY_USED_SIZE(unexpanded) == 0) return; - us = grib_bufr_descriptor_clone(grib_bufr_descriptors_array_get(unexpanded, 0)); + us = grib_bufr_descriptor_clone(grib_bufr_descriptors_array_get(unexpanded, 0)); us->context = c; *err = 0; @@ -134,19 +146,19 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_ printf("+++ pop %06ld [%s]\n", u->code, descriptor_type_name(u->type)); #endif /*this is to get the sequence elements of the sequence unexpanded[i] */ - *err = grib_set_long(hand, self->sequence, u->code); - *err = grib_get_size(hand, self->sequence, &size); + *err = grib_set_long(hand, self->sequence_, u->code); + *err = grib_get_size(hand, self->sequence_, &size); grib_bufr_descriptor_delete(u); if (*err) goto cleanup; v_array = (long*)grib_context_malloc_clear(c, sizeof(long) * size); - *err = grib_get_long_array(hand, self->sequence, v_array, &size); + *err = grib_get_long_array(hand, self->sequence_, v_array, &size); if (*err) goto cleanup; inner_unexpanded = grib_bufr_descriptors_array_new(c, DESC_SIZE_INIT, DESC_SIZE_INCR); for (i = 0; i < size; i++) { - vv = grib_bufr_descriptor_new(self->tablesAccessor, v_array[i], !SILENT, err); + vv = grib_bufr_descriptor_new(self->tablesAccessor_, v_array[i], !SILENT, err); inner_unexpanded = grib_bufr_descriptors_array_push(inner_unexpanded, vv); } grib_context_free(c, v_array); @@ -161,7 +173,7 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_ printf("+++ push %06ld\n", inner_expanded->v[i]->code); } #endif - size = BUFR_DESCRIPTORS_ARRAY_USED_SIZE(inner_expanded); + size = BUFR_DESCRIPTORS_ARRAY_USED_SIZE(inner_expanded); grib_bufr_descriptors_array_append(expanded, inner_expanded); break; @@ -217,7 +229,8 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_ if (size > 100) { grib_context_log(c, GRIB_LOG_ERROR, "Delayed replication %06ld: Too many elements (%lu). " - "Hint: This may be due to associated field descriptors", uidx->code, size); + "Hint: This may be due to associated field descriptors", + uidx->code, size); *err = GRIB_DECODING_ERROR; return; } @@ -268,7 +281,7 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_ printf("+++ push %06ld\n", inner_expanded->v[i]->code); } #endif - size = BUFR_DESCRIPTORS_ARRAY_USED_SIZE(inner_expanded); + size = BUFR_DESCRIPTORS_ARRAY_USED_SIZE(inner_expanded); grib_bufr_descriptors_array_append(expanded, inner_expanded); } break; @@ -277,7 +290,7 @@ static void __expand(grib_accessor* a, bufr_descriptors_array* unexpanded, bufr_ DESCRIPTORS_POP_FRONT_OR_RETURN(unexpanded, u); size = 1; if (ccp->associatedFieldWidth && u->X != 31) { - bufr_descriptor* au = grib_bufr_descriptor_new(self->tablesAccessor, 999999, !SILENT, err); + bufr_descriptor* au = grib_bufr_descriptor_new(self->tablesAccessor_, 999999, !SILENT, err); au->width = ccp->associatedFieldWidth; grib_bufr_descriptor_set_scale(au, 0); strcpy(au->shortName, "associatedField"); @@ -405,8 +418,9 @@ cleanup: static bufr_descriptors_array* do_expand(grib_accessor* a, bufr_descriptors_array* unexpanded, change_coding_params* ccp, int* err) { - bufr_descriptors_array* expanded = NULL; - grib_context* c = a->context; + grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; + bufr_descriptors_array* expanded = NULL; + grib_context* c = a->context_; #if MYDEBUG int idepth; global_depth++; @@ -468,36 +482,38 @@ static bufr_descriptors_array* do_expand(grib_accessor* a, bufr_descriptors_arra static int expand(grib_accessor* a) { grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; - int err = 0; - size_t unexpandedSize = 0; + int err = 0; + size_t unexpandedSize = 0; /* grib_iarray* unexp=0; */ int i; long* u = 0; - char key[50] = {0,}; + char key[50] = { + 0, + }; long centre, masterTablesVersionNumber, localTablesVersionNumber, masterTablesNumber; change_coding_params ccp; bufr_descriptors_array* unexpanded = NULL; bufr_descriptors_array* unexpanded_copy = NULL; bufr_descriptors_array* expanded = NULL; - grib_context* c = a->context; + grib_context* c = a->context_; const grib_handle* h = grib_handle_of_accessor(a); int operator206yyy_width = 0; /* width specified by operator 206YYY */ - if (!self->do_expand) { + if (!self->do_expand_) { return err; } - self->do_expand = 0; - if (self->rank != 0) { - err = expand(self->expandedAccessor); - self->expanded = ((grib_accessor_expanded_descriptors_t*)self->expandedAccessor)->expanded; + self->do_expand_ = 0; + if (self->rank_ != 0) { + err = expand(self->expandedAccessor_); + self->expanded_ = ((grib_accessor_expanded_descriptors_t*)self->expandedAccessor_)->expanded_; return err; } - err = grib_get_size(h, self->unexpandedDescriptors, &unexpandedSize); + err = grib_get_size(h, self->unexpandedDescriptors_, &unexpandedSize); if (err) return err; if (unexpandedSize == 0) { - grib_context_log(c, GRIB_LOG_ERROR, "%s: Unexpanded size is zero!", a->name); + grib_context_log(c, GRIB_LOG_ERROR, "%s: Unexpanded size is zero!", a->name_); return GRIB_DECODING_ERROR; } @@ -506,7 +522,7 @@ static int expand(grib_accessor* a) err = GRIB_OUT_OF_MEMORY; return err; } - err = grib_get_long_array(h, self->unexpandedDescriptors, u, &unexpandedSize); + err = grib_get_long_array(h, self->unexpandedDescriptors_, u, &unexpandedSize); if (err) return err; @@ -526,14 +542,14 @@ static int expand(grib_accessor* a) snprintf(key, sizeof(key), "%ld_%ld_%ld_%ld_%ld", centre, masterTablesVersionNumber, localTablesVersionNumber, masterTablesNumber, u[0]); expanded = grib_context_expanded_descriptors_list_get(c, key, u, unexpandedSize); if (expanded) { - self->expanded = expanded; + self->expanded_ = expanded; grib_context_free(c, u); return GRIB_SUCCESS; } - if (!self->tablesAccessor) { - self->tablesAccessor = grib_find_accessor(h, self->tablesAccessorName); - Assert(self->tablesAccessor); + if (!self->tablesAccessor_) { + self->tablesAccessor_ = grib_find_accessor(h, self->tablesAccessorName_); + Assert(self->tablesAccessor_); } unexpanded = grib_bufr_descriptors_array_new(c, unexpandedSize, DESC_SIZE_INCR); @@ -542,10 +558,10 @@ static int expand(grib_accessor* a) for (i = 0; i < unexpandedSize; i++) { bufr_descriptor *aDescriptor1, *aDescriptor2; /* ECC-1274: clear error and only issue msg once */ - err = 0; - aDescriptor1 = grib_bufr_descriptor_new(self->tablesAccessor, u[i], SILENT, &err); - err = 0; - aDescriptor2 = grib_bufr_descriptor_new(self->tablesAccessor, u[i], !SILENT, &err); + err = 0; + aDescriptor1 = grib_bufr_descriptor_new(self->tablesAccessor_, u[i], SILENT, &err); + err = 0; + aDescriptor2 = grib_bufr_descriptor_new(self->tablesAccessor_, u[i], !SILENT, &err); /* ECC-433: Operator 206YYY */ if (aDescriptor1->F == 2 && aDescriptor1->X == 6) { @@ -576,173 +592,172 @@ static int expand(grib_accessor* a) ccp.referenceFactor = 1; ccp.associatedFieldWidth = 0; ccp.newStringWidth = 0; - self->expanded = do_expand(a, unexpanded, &ccp, &err); + self->expanded_ = do_expand(a, unexpanded, &ccp, &err); if (err) { grib_bufr_descriptors_array_delete(unexpanded); grib_bufr_descriptors_array_delete(unexpanded_copy); return err; } - grib_context_expanded_descriptors_list_push(c, key, self->expanded, unexpanded_copy); + grib_context_expanded_descriptors_list_push(c, key, self->expanded_, unexpanded_copy); grib_bufr_descriptors_array_delete(unexpanded); return err; } -int grib_accessor_class_expanded_descriptors_set_do_expand(grib_accessor* a, long do_expand) +int grib_accessor_expanded_descriptors_set_do_expand(grib_accessor* a, long do_expand) { grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; - self->do_expand = do_expand; + self->do_expand_ = do_expand; return 0; } -bufr_descriptors_array* grib_accessor_class_expanded_descriptors_get_expanded(grib_accessor* a, int* err) +bufr_descriptors_array* grib_accessor_expanded_descriptors_get_expanded(grib_accessor* a, int* err) { const grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; - *err = expand(a); - return self->expanded; + *err = expand(a); + return self->expanded_; } -int grib_accessor_class_expanded_descriptors_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_expanded_descriptors_t::unpack_double(double* val, size_t* len) { - grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; - int ret = 0; + int ret = 0; size_t i = 0; size_t expandedSize; - if (self->rank != 2) { - long* lval = (long*)grib_context_malloc_clear(a->context, *len * sizeof(long)); - ret = unpack_long(a, lval, len); + if (rank_ != 2) { + long* lval = (long*)grib_context_malloc_clear(context_, *len * sizeof(long)); + ret = unpack_long(lval, len); if (ret) return ret; for (i = 0; i < *len; i++) val[i] = (double)lval[i]; - grib_context_free(a->context, lval); + grib_context_free(context_, lval); } else { - ret = expand(a); + ret = expand(this); if (ret) return ret; - expandedSize = BUFR_DESCRIPTORS_ARRAY_USED_SIZE(self->expanded); + expandedSize = BUFR_DESCRIPTORS_ARRAY_USED_SIZE(expanded_); if (*len < expandedSize) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Wrong size (%ld) for %s, it contains %lu values", *len, a->name, expandedSize); + grib_context_log(context_, GRIB_LOG_ERROR, + "Wrong size (%ld) for %s, it contains %lu values", *len, name_, expandedSize); *len = 0; return GRIB_ARRAY_TOO_SMALL; } *len = expandedSize; for (i = 0; i < *len; i++) - val[i] = self->expanded->v[i]->reference; + val[i] = expanded_->v[i]->reference; } return ret; } -int grib_accessor_class_expanded_descriptors_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_expanded_descriptors_t::unpack_long(long* val, size_t* len) { - grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; int ret = 0; size_t rlen = 0; size_t i = 0; - ret = expand(a); + ret = expand(this); if (ret) return ret; - if (!self->expanded) + if (!expanded_) return GRIB_DECODING_ERROR; - rlen = BUFR_DESCRIPTORS_ARRAY_USED_SIZE(self->expanded); + rlen = BUFR_DESCRIPTORS_ARRAY_USED_SIZE(expanded_); if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Wrong size (%ld) for %s, it contains %lu values", *len, a->name, rlen); + grib_context_log(context_, GRIB_LOG_ERROR, + "Wrong size (%ld) for %s, it contains %lu values", *len, name_, rlen); *len = 0; return GRIB_ARRAY_TOO_SMALL; } *len = rlen; - switch (self->rank) { + switch (rank_) { case 0: for (i = 0; i < *len; i++) - val[i] = self->expanded->v[i]->code; + val[i] = expanded_->v[i]->code; break; case 1: for (i = 0; i < *len; i++) - val[i] = self->expanded->v[i]->scale; + val[i] = expanded_->v[i]->scale; break; case 2: return GRIB_INVALID_TYPE; case 3: for (i = 0; i < *len; i++) - val[i] = self->expanded->v[i]->width; + val[i] = expanded_->v[i]->width; break; case 4: for (i = 0; i < *len; i++) - val[i] = self->expanded->v[i]->type; + val[i] = expanded_->v[i]->type; break; } return GRIB_SUCCESS; } -int grib_accessor_class_expanded_descriptors_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len) +int grib_accessor_expanded_descriptors_t::unpack_string_array(char** buffer, size_t* len) { - int err = 0; - long* v = NULL; - char buf[25] = {0,}; + int err = 0; + long* v = NULL; + char buf[25] = { + 0, + }; long llen = 0; size_t i = 0, size = 0; - const grib_context* c = a->context; + const grib_context* c = context_; - err = a->value_count(&llen); if (err) return err; + err = value_count(&llen); + if (err) return err; size = llen; - v = (long*)grib_context_malloc_clear(c, sizeof(long) * size); - err = a->unpack_long(v, &size); if (err) return err; + v = (long*)grib_context_malloc_clear(c, sizeof(long) * size); + err = unpack_long(v, &size); + if (err) return err; for (i = 0; i < size; i++) { snprintf(buf, sizeof(buf), "%06ld", v[i]); buffer[i] = grib_context_strdup(c, buf); } *len = size; - grib_context_free(c,v); + grib_context_free(c, v); return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_expanded_descriptors_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_expanded_descriptors_t::pack_long(const long* val, size_t* len) { - grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; - self->do_expand = 1; + do_expand_ = 1; return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_expanded_descriptors_t::value_count(grib_accessor* a, long* rlen) +int grib_accessor_expanded_descriptors_t::value_count(long* rlen) { - grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; int err = 0; *rlen = 0; - err = expand(a); + err = expand(this); if (err) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s unable to compute size", a->name); - grib_bufr_descriptors_array_delete(self->expanded); + grib_context_log(context_, GRIB_LOG_ERROR, "%s unable to compute size", name_); + grib_bufr_descriptors_array_delete(expanded_); return err; } - *rlen = BUFR_DESCRIPTORS_ARRAY_USED_SIZE(self->expanded); + *rlen = BUFR_DESCRIPTORS_ARRAY_USED_SIZE(expanded_); return err; } -void grib_accessor_class_expanded_descriptors_t::destroy(grib_context* c, grib_accessor* a) +void grib_accessor_expanded_descriptors_t::destroy(grib_context* c) { - grib_accessor_class_long_t::destroy(c, a); + grib_accessor_long_t::destroy(c); // grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; - // if (self->rank==0 && self->expanded) - // grib_bufr_descriptors_array_delete(self->expanded); + // if (rank==0 && expanded_ ) + // grib_bufr_descriptors_array_delete(expanded_ ); } -int grib_accessor_class_expanded_descriptors_t::get_native_type(grib_accessor* a) +long grib_accessor_expanded_descriptors_t::get_native_type() { - grib_accessor_expanded_descriptors_t* self = (grib_accessor_expanded_descriptors_t*)a; - if (self->rank == 2) + if (rank_ == 2) return GRIB_TYPE_DOUBLE; else return GRIB_TYPE_LONG; diff --git a/src/accessor/grib_accessor_class_expanded_descriptors.h b/src/accessor/grib_accessor_class_expanded_descriptors.h index 7e42ad28c..682f62105 100644 --- a/src/accessor/grib_accessor_class_expanded_descriptors.h +++ b/src/accessor/grib_accessor_class_expanded_descriptors.h @@ -15,29 +15,29 @@ class grib_accessor_expanded_descriptors_t : public grib_accessor_long_t { public: - /* Members defined in expanded_descriptors */ - const char* unexpandedDescriptors; - const char* sequence; - const char* expandedName; - const char* tablesAccessorName; - bufr_descriptors_array* expanded; - int rank; - grib_accessor* expandedAccessor; - int do_expand; - grib_accessor* tablesAccessor; + grib_accessor_expanded_descriptors_t() : + grib_accessor_long_t() { class_name_ = "expanded_descriptors"; } + grib_accessor* create_empty_accessor() override { return new grib_accessor_expanded_descriptors_t{}; } + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string_array(char**, size_t* len) override; + int value_count(long*) override; + void destroy(grib_context*) override; + void init(const long, grib_arguments*) override; + +public: + const char* unexpandedDescriptors_; + const char* sequence_; + const char* expandedName_; + const char* tablesAccessorName_; + bufr_descriptors_array* expanded_; + int rank_; + grib_accessor* expandedAccessor_; + int do_expand_; + grib_accessor* tablesAccessor_; }; -class grib_accessor_class_expanded_descriptors_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_expanded_descriptors_t(const char* name) : grib_accessor_class_long_t(name) {} - grib_accessor* create_empty_accessor() override { return new grib_accessor_expanded_descriptors_t{}; } - int get_native_type(grib_accessor*) override; - int pack_long(grib_accessor*, const long* val, 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_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; -}; +int grib_accessor_expanded_descriptors_set_do_expand(grib_accessor* a, long do_expand); +bufr_descriptors_array* grib_accessor_expanded_descriptors_get_expanded(grib_accessor* a, int* err); diff --git a/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.cc b/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.cc index f2c598f8f..e8471e32f 100644 --- a/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.cc +++ b/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.cc @@ -11,112 +11,107 @@ #include "grib_accessor_class_from_scale_factor_scaled_value.h" -grib_accessor_class_from_scale_factor_scaled_value_t _grib_accessor_class_from_scale_factor_scaled_value{ "from_scale_factor_scaled_value" }; -grib_accessor_class* grib_accessor_class_from_scale_factor_scaled_value = &_grib_accessor_class_from_scale_factor_scaled_value; +grib_accessor_from_scale_factor_scaled_value_t _grib_accessor_from_scale_factor_scaled_value{}; +grib_accessor* grib_accessor_from_scale_factor_scaled_value = &_grib_accessor_from_scale_factor_scaled_value; - -void grib_accessor_class_from_scale_factor_scaled_value_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_from_scale_factor_scaled_value_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_from_scale_factor_scaled_value_t* self = (grib_accessor_from_scale_factor_scaled_value_t*)a; - int n = 0; - grib_handle* hand = grib_handle_of_accessor(a); + grib_accessor_double_t::init(l, c); + int n = 0; + grib_handle* hand = grib_handle_of_accessor(this); - self->scaleFactor = grib_arguments_get_name(hand, c, n++); - self->scaledValue = grib_arguments_get_name(hand, c, n++); // Can be scalar or array + scaleFactor_ = grib_arguments_get_name(hand, c, n++); + scaledValue_ = grib_arguments_get_name(hand, c, n++); // Can be scalar or array // ECC-979: Allow user to encode - // a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + // flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_from_scale_factor_scaled_value_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_from_scale_factor_scaled_value_t::pack_double(const double* val, size_t* len) { // See ECC-979 and ECC-1416 - // Evaluate self->scaleFactor and self->scaledValue from input double '*val' - grib_accessor_from_scale_factor_scaled_value_t* self = (grib_accessor_from_scale_factor_scaled_value_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - - int err = 0; - int64_t factor = 0; - int64_t value = 0; - double exact = *val; // the input + // Evaluate scaleFactor and scaledValue_ from input double '*val' + grib_handle* hand = grib_handle_of_accessor(this); + int err = 0; + int64_t factor = 0; + int64_t value = 0; + double exact = *val; // the input int64_t maxval_value, maxval_factor; // maximum allowable values int value_accessor_num_bits = 0, factor_accessor_num_bits = 0; grib_accessor *factor_accessor, *value_accessor; if (exact == 0) { - if ((err = grib_set_long_internal(hand, self->scaleFactor, 0)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(hand, scaleFactor_, 0)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(hand, self->scaledValue, 0)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(hand, scaledValue_, 0)) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; } if (exact == GRIB_MISSING_DOUBLE) { - if ((err = grib_set_missing(hand, self->scaleFactor)) != GRIB_SUCCESS) + if ((err = grib_set_missing(hand, scaleFactor_)) != GRIB_SUCCESS) return err; - if ((err = grib_set_missing(hand, self->scaledValue)) != GRIB_SUCCESS) + if ((err = grib_set_missing(hand, scaledValue_)) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; } - factor_accessor = grib_find_accessor(hand, self->scaleFactor); - value_accessor = grib_find_accessor(hand, self->scaledValue); + factor_accessor = grib_find_accessor(hand, scaleFactor_); + value_accessor = grib_find_accessor(hand, scaledValue_); if (!factor_accessor || !value_accessor) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Could not access keys %s and %s", self->scaleFactor, self->scaledValue); + grib_context_log(context_, GRIB_LOG_ERROR, "Could not access keys %s and %s", scaleFactor_, scaledValue_); return GRIB_ENCODING_ERROR; } - value_accessor_num_bits = value_accessor->length * 8; - factor_accessor_num_bits = factor_accessor->length * 8; + value_accessor_num_bits = value_accessor->length_ * 8; + factor_accessor_num_bits = factor_accessor->length_ * 8; maxval_value = (1UL << value_accessor_num_bits) - 2; // exclude missing maxval_factor = (1UL << factor_accessor_num_bits) - 2; // exclude missing - if (strcmp(factor_accessor->cclass->name, "signed") == 0) { + if (strcmp(factor_accessor->class_name_, "signed") == 0) { maxval_factor = (1UL << (factor_accessor_num_bits - 1)) - 1; } err = compute_scaled_value_and_scale_factor(exact, maxval_value, maxval_factor, &value, &factor); if (err) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Failed to compute %s and %s from %g", self->scaleFactor, self->scaledValue, exact); + grib_context_log(context_, GRIB_LOG_ERROR, "Failed to compute %s and %s from %g", scaleFactor_, scaledValue_, exact); return err; } - if ((err = grib_set_long_internal(hand, self->scaleFactor, factor)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(hand, scaleFactor_, factor)) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(hand, self->scaledValue, value)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(hand, scaledValue_, value)) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; } -int grib_accessor_class_from_scale_factor_scaled_value_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_from_scale_factor_scaled_value_t::unpack_double(double* val, size_t* len) { - grib_accessor_from_scale_factor_scaled_value_t* self = (grib_accessor_from_scale_factor_scaled_value_t*)a; - int err = 0; + int err = 0; long scaleFactor = 0, scaledValue = 0; - grib_handle* hand = grib_handle_of_accessor(a); - grib_context* c = a->context; + grib_handle* hand = grib_handle_of_accessor(this); + grib_context* c = context_; size_t vsize = 0; - if ((err = grib_get_long_internal(hand, self->scaleFactor, &scaleFactor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, scaleFactor_, &scaleFactor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_size(hand, self->scaledValue, &vsize)) != GRIB_SUCCESS) + if ((err = grib_get_size(hand, scaledValue_, &vsize)) != GRIB_SUCCESS) return err; if (vsize == 1) { - if ((err = grib_get_long_internal(hand, self->scaledValue, &scaledValue)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, scaledValue_, &scaledValue)) != GRIB_SUCCESS) return err; - if (grib_is_missing(hand, self->scaledValue, &err) && err == GRIB_SUCCESS) { + if (grib_is_missing(hand, scaledValue_, &err) && err == GRIB_SUCCESS) { *val = GRIB_MISSING_DOUBLE; *len = 1; return GRIB_SUCCESS; } else { // ECC-966: If scale factor is missing, print error and treat it as zero (as a fallback) - if (grib_is_missing(hand, self->scaleFactor, &err) && err == GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "unpack_double for %s: %s is missing! Using zero instead", a->name, self->scaleFactor); + if (grib_is_missing(hand, scaleFactor_, &err) && err == GRIB_SUCCESS) { + grib_context_log(context_, GRIB_LOG_ERROR, + "unpack_double for %s: %s is missing! Using zero instead", name_, scaleFactor_); scaleFactor = 0; } } @@ -143,7 +138,7 @@ int grib_accessor_class_from_scale_factor_scaled_value_t::unpack_double(grib_acc long* lvalues = (long*)grib_context_malloc(c, vsize * sizeof(long)); if (!lvalues) return GRIB_OUT_OF_MEMORY; - if ((err = grib_get_long_array_internal(hand, self->scaledValue, lvalues, &vsize)) != GRIB_SUCCESS) { + if ((err = grib_get_long_array_internal(hand, scaledValue_, lvalues, &vsize)) != GRIB_SUCCESS) { grib_context_free(c, lvalues); return err; } @@ -166,30 +161,28 @@ int grib_accessor_class_from_scale_factor_scaled_value_t::unpack_double(grib_acc return err; } -int grib_accessor_class_from_scale_factor_scaled_value_t::is_missing(grib_accessor* a) +int grib_accessor_from_scale_factor_scaled_value_t::is_missing() { - grib_accessor_from_scale_factor_scaled_value_t* self = (grib_accessor_from_scale_factor_scaled_value_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int err = 0; + grib_handle* hand = grib_handle_of_accessor(this); + int err = 0; long scaleFactor = 0, scaledValue = 0; - if ((err = grib_get_long_internal(hand, self->scaleFactor, &scaleFactor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, scaleFactor_, &scaleFactor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->scaledValue, &scaledValue)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, scaledValue_, &scaledValue)) != GRIB_SUCCESS) return err; return ((scaleFactor == GRIB_MISSING_LONG) || (scaledValue == GRIB_MISSING_LONG)); } -int grib_accessor_class_from_scale_factor_scaled_value_t::value_count(grib_accessor* a, long* len) +int grib_accessor_from_scale_factor_scaled_value_t::value_count(long* len) { - grib_accessor_from_scale_factor_scaled_value_t* self = (grib_accessor_from_scale_factor_scaled_value_t*)a; - int err = 0; - grib_handle* hand = grib_handle_of_accessor(a); - size_t vsize = 0; + int err = 0; + grib_handle* hand = grib_handle_of_accessor(this); + size_t vsize; - if ((err = grib_get_size(hand, self->scaledValue, &vsize)) != GRIB_SUCCESS) + if ((err = grib_get_size(hand, scaledValue_, &vsize)) != GRIB_SUCCESS) return err; *len = (long)vsize; return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.h b/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.h index d8dc1bcb8..7398083fa 100644 --- a/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.h +++ b/src/accessor/grib_accessor_class_from_scale_factor_scaled_value.h @@ -16,19 +16,16 @@ class grib_accessor_from_scale_factor_scaled_value_t : public grib_accessor_double_t { public: - /* Members defined in from_scale_factor_scaled_value */ - const char* scaleFactor; - const char* scaledValue; -}; - -class grib_accessor_class_from_scale_factor_scaled_value_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_from_scale_factor_scaled_value_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_from_scale_factor_scaled_value_t() : + grib_accessor_double_t() { class_name_ = "from_scale_factor_scaled_value"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_from_scale_factor_scaled_value_t{}; } - int is_missing(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 init(grib_accessor*, const long, grib_arguments*) override; + int is_missing() override; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* scaleFactor_; + const char* scaledValue_; }; diff --git a/src/accessor/grib_accessor_class_g1_half_byte_codeflag.cc b/src/accessor/grib_accessor_class_g1_half_byte_codeflag.cc index f73a146dc..22f74e766 100644 --- a/src/accessor/grib_accessor_class_g1_half_byte_codeflag.cc +++ b/src/accessor/grib_accessor_class_g1_half_byte_codeflag.cc @@ -11,55 +11,54 @@ #include "grib_accessor_class_g1_half_byte_codeflag.h" -grib_accessor_class_g1_half_byte_codeflag_t _grib_accessor_class_g1_half_byte_codeflag{ "g1_half_byte_codeflag" }; -grib_accessor_class* grib_accessor_class_g1_half_byte_codeflag = &_grib_accessor_class_g1_half_byte_codeflag; +grib_accessor_g1_half_byte_codeflag_t _grib_accessor_g1_half_byte_codeflag{}; +grib_accessor* grib_accessor_g1_half_byte_codeflag = &_grib_accessor_g1_half_byte_codeflag; - -void grib_accessor_class_g1_half_byte_codeflag_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_g1_half_byte_codeflag_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + grib_accessor_gen_t::init(len, arg); + length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; } -void grib_accessor_class_g1_half_byte_codeflag_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_g1_half_byte_codeflag_t::dump(grib_dumper* dumper) { - grib_dump_long(dumper, a, NULL); + grib_dump_long(dumper, this, NULL); } -int grib_accessor_class_g1_half_byte_codeflag_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g1_half_byte_codeflag_t::unpack_long(long* val, size_t* len) { unsigned char dat = 0; if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", name_, 1); *len = 0; return GRIB_ARRAY_TOO_SMALL; } - dat = grib_handle_of_accessor(a)->buffer->data[a->offset] & 0x0f; + dat = grib_handle_of_accessor(this)->buffer->data[offset_] & 0x0f; *val = dat; *len = 1; return GRIB_SUCCESS; } -int grib_accessor_class_g1_half_byte_codeflag_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_g1_half_byte_codeflag_t::pack_long(const long* val, size_t* len) { int ret = 0; if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", name_, 1); *len = 0; return GRIB_ARRAY_TOO_SMALL; } - /* printf("HALF BYTE pack long %ld %02x\n",*val,grib_handle_of_accessor(a)->buffer->data[a->offset]);*/ - grib_handle_of_accessor(a)->buffer->data[a->offset] = (a->parent->h->buffer->data[a->offset] & 0xf0) | (*val & 0x0f); - /* printf("HALF BYTE pack long %ld %02x\n",*val,grib_handle_of_accessor(a)->buffer->data[a->offset]);*/ + /* printf("HALF BYTE pack long %ld %02x\n",*val,grib_handle_of_accessor(this)->buffer->data[offset_ ]);*/ + grib_handle_of_accessor(this)->buffer->data[offset_] = (parent_->h->buffer->data[offset_] & 0xf0) | (*val & 0x0f); + /* printf("HALF BYTE pack long %ld %02x\n",*val,grib_handle_of_accessor(this)->buffer->data[offset_ ]);*/ *len = 1; return ret; } -int grib_accessor_class_g1_half_byte_codeflag_t::get_native_type(grib_accessor* a) +long grib_accessor_g1_half_byte_codeflag_t::get_native_type() { return GRIB_TYPE_LONG; } diff --git a/src/accessor/grib_accessor_class_g1_half_byte_codeflag.h b/src/accessor/grib_accessor_class_g1_half_byte_codeflag.h index 662a75569..b751be642 100644 --- a/src/accessor/grib_accessor_class_g1_half_byte_codeflag.h +++ b/src/accessor/grib_accessor_class_g1_half_byte_codeflag.h @@ -16,17 +16,12 @@ class grib_accessor_g1_half_byte_codeflag_t : public grib_accessor_gen_t { public: - /* Members defined in g1_half_byte_codeflag */ -}; - -class grib_accessor_class_g1_half_byte_codeflag_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_g1_half_byte_codeflag_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_g1_half_byte_codeflag_t() : + grib_accessor_gen_t() { class_name_ = "g1_half_byte_codeflag"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g1_half_byte_codeflag_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 dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_g1_message_length.cc b/src/accessor/grib_accessor_class_g1_message_length.cc index af06d2e98..088e8c34c 100644 --- a/src/accessor/grib_accessor_class_g1_message_length.cc +++ b/src/accessor/grib_accessor_class_g1_message_length.cc @@ -11,15 +11,13 @@ #include "grib_accessor_class_g1_message_length.h" -grib_accessor_class_g1_message_length_t _grib_accessor_class_g1_message_length{ "g1_message_length" }; -grib_accessor_class* grib_accessor_class_g1_message_length = &_grib_accessor_class_g1_message_length; +grib_accessor_g1_message_length_t _grib_accessor_g1_message_length{}; +grib_accessor* grib_accessor_g1_message_length = &_grib_accessor_g1_message_length; - -void grib_accessor_class_g1_message_length_t::init(grib_accessor* a, const long len, grib_arguments* args) +void grib_accessor_g1_message_length_t::init(const long len, grib_arguments* args) { - grib_accessor_class_section_length_t::init(a, len, args); - grib_accessor_g1_message_length_t* self = (grib_accessor_g1_message_length_t*)a; - self->sec4_length = grib_arguments_get_name(grib_handle_of_accessor(a), args, 0); + grib_accessor_section_length_t::init(len, args); + sec4_length_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, 0); } int grib_get_g1_message_size(grib_handle* h, grib_accessor* tl, grib_accessor* s4, @@ -32,16 +30,16 @@ int grib_get_g1_message_size(grib_handle* h, grib_accessor* tl, grib_accessor* s return GRIB_NOT_FOUND; if (!s4) { *sec4_len = 0; - off = tl->offset * 8; - *total_length = grib_decode_unsigned_long(h->buffer->data, &off, tl->length * 8); + off = tl->offset_ * 8; + *total_length = grib_decode_unsigned_long(h->buffer->data, &off, tl->length_ * 8); return GRIB_SUCCESS; } - off = tl->offset * 8; - tlen = grib_decode_unsigned_long(h->buffer->data, &off, tl->length * 8); + off = tl->offset_ * 8; + tlen = grib_decode_unsigned_long(h->buffer->data, &off, tl->length_ * 8); - off = s4->offset * 8; - slen = grib_decode_unsigned_long(h->buffer->data, &off, s4->length * 8); + off = s4->offset_ * 8; + slen = grib_decode_unsigned_long(h->buffer->data, &off, s4->length_ * 8); /* printf("\nlarge grib tlen=%ld slen=%ld diff=%ld\n",tlen&0x7fffff,slen,tlen-slen); */ @@ -52,7 +50,7 @@ int grib_get_g1_message_size(grib_handle* h, grib_accessor* tl, grib_accessor* s tlen -= slen; tlen += 4; - slen = tlen - s4->offset - 4; /* 4 is for 7777 */ + slen = tlen - s4->offset_ - 4; /* 4 is for 7777 */ } *total_length = tlen; @@ -61,28 +59,27 @@ int grib_get_g1_message_size(grib_handle* h, grib_accessor* tl, grib_accessor* s return GRIB_SUCCESS; } -int grib_accessor_class_g1_message_length_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_g1_message_length_t::pack_long(const long* val, size_t* len) { - grib_accessor_g1_message_length_t* self = (grib_accessor_g1_message_length_t*)a; - /*grib_accessor_class* super = *(a->cclass->super);*/ + /*grib_accessor* super = *(cclass_ ->super);*/ /* Here we assume that the totalLength will be coded AFTER the section4 length, and the section4 length will be overwritten by the totalLength accessor for large GRIBs */ - grib_accessor* s4 = grib_find_accessor(grib_handle_of_accessor(a), self->sec4_length); + grib_accessor* s4 = grib_find_accessor(grib_handle_of_accessor(this), sec4_length_); long tlen, slen; long t120; int ret; tlen = *val; - if ((tlen < 0x800000 || !a->context->gribex_mode_on) && tlen < 0xFFFFFF) { + if ((tlen < 0x800000 || !context_->gribex_mode_on) && tlen < 0xFFFFFF) { /* printf("ENCODING small grib total = %ld\n",tlen); */ /*return super->pack_long(a,val,len);*/ /* Do not directly call pack_long on base class */ /* because in this special case we want to skip the checks. */ /* So we call the helper function which has an extra argument */ - return pack_long_unsigned_helper(a, val, len, /*check=*/0); + return pack_long_unsigned_helper(this, val, len, /*check=*/0); } if (!s4) @@ -100,23 +97,23 @@ int grib_accessor_class_g1_message_length_t::pack_long(grib_accessor* a, const l *len = 1; /* Do not do the length checks in this special case */ - if ((ret = pack_long_unsigned_helper(a, &tlen, len, /*check=*/0)) != GRIB_SUCCESS) + if ((ret = pack_long_unsigned_helper(this, &tlen, len, /*check=*/0)) != GRIB_SUCCESS) return ret; // if((ret = super->pack_long(a,&tlen,len)) != GRIB_SUCCESS) return ret; { long total_length = -1, sec4_length = -1; - grib_get_g1_message_size(grib_handle_of_accessor(a), a, - grib_find_accessor(grib_handle_of_accessor(a), self->sec4_length), + grib_get_g1_message_size(grib_handle_of_accessor(this), this, + grib_find_accessor(grib_handle_of_accessor(this), sec4_length_), &total_length, &sec4_length); if (total_length != *val) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, + const char* cclass_name = class_name_; + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: Failed to set GRIB1 message length to %ld" " (actual length=%ld)", cclass_name, __func__, *val, total_length); - grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Try encoding as GRIB2\n"); + grib_context_log(context_, GRIB_LOG_ERROR, "Hint: Try encoding as GRIB2\n"); return GRIB_ENCODING_ERROR; } } @@ -124,14 +121,13 @@ int grib_accessor_class_g1_message_length_t::pack_long(grib_accessor* a, const l return GRIB_SUCCESS; } -int grib_accessor_class_g1_message_length_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g1_message_length_t::unpack_long(long* val, size_t* len) { - grib_accessor_g1_message_length_t* self = (grib_accessor_g1_message_length_t*)a; int ret; long total_length, sec4_length; - if ((ret = grib_get_g1_message_size(grib_handle_of_accessor(a), a, - grib_find_accessor(grib_handle_of_accessor(a), self->sec4_length), + if ((ret = grib_get_g1_message_size(grib_handle_of_accessor(this), this, + grib_find_accessor(grib_handle_of_accessor(this), sec4_length_), &total_length, &sec4_length)) != GRIB_SUCCESS) { return ret; } diff --git a/src/accessor/grib_accessor_class_g1_message_length.h b/src/accessor/grib_accessor_class_g1_message_length.h index 9a24e3213..226fabf3a 100644 --- a/src/accessor/grib_accessor_class_g1_message_length.h +++ b/src/accessor/grib_accessor_class_g1_message_length.h @@ -16,16 +16,13 @@ class grib_accessor_g1_message_length_t : public grib_accessor_section_length_t { public: - /* Members defined in g1_message_length */ - const char *sec4_length; -}; - -class grib_accessor_class_g1_message_length_t : public grib_accessor_class_section_length_t -{ -public: - grib_accessor_class_g1_message_length_t(const char* name) : grib_accessor_class_section_length_t(name) {} + grib_accessor_g1_message_length_t() : + grib_accessor_section_length_t() { class_name_ = "g1_message_length"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g1_message_length_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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* sec4_length_; }; diff --git a/src/accessor/grib_accessor_class_g1_section4_length.cc b/src/accessor/grib_accessor_class_g1_section4_length.cc index fe80e70e8..24d63eb70 100644 --- a/src/accessor/grib_accessor_class_g1_section4_length.cc +++ b/src/accessor/grib_accessor_class_g1_section4_length.cc @@ -11,40 +11,37 @@ #include "grib_accessor_class_g1_section4_length.h" -grib_accessor_class_g1_section4_length_t _grib_accessor_class_g1_section4_length{ "g1_section4_length" }; -grib_accessor_class* grib_accessor_class_g1_section4_length = &_grib_accessor_class_g1_section4_length; +grib_accessor_g1_section4_length_t _grib_accessor_g1_section4_length{}; +grib_accessor* grib_accessor_g1_section4_length = &_grib_accessor_g1_section4_length; - -void grib_accessor_class_g1_section4_length_t::init(grib_accessor* a, const long len, grib_arguments* args) +void grib_accessor_g1_section4_length_t::init(const long len, grib_arguments* args) { - grib_accessor_class_section_length_t::init(a, len, args); - grib_accessor_g1_section4_length_t* self = (grib_accessor_g1_section4_length_t*)a; - self->total_length = grib_arguments_get_name(grib_handle_of_accessor(a), args, 0); + grib_accessor_section_length_t::init(len, args); + total_length_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, 0); } -int grib_accessor_class_g1_section4_length_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_g1_section4_length_t::pack_long(const long* val, size_t* len) { // Old implementation: // Here we assume that the totalLength will be coded AFTER the section4 length, and // the section4 length will be overwritten by the totalLength accessor for large GRIBs - // grib_accessor_class* super = *(a->cclass->super); + // grib_accessor* super = *(cclass_ ->super); // return super->pack_long(a,val,len); // Note: Do not directly call pack_long on base class // because in this special case we want to skip the checks. // So we call the helper function which has an extra argument - return pack_long_unsigned_helper(a, val, len, /*check=*/0); + return pack_long_unsigned_helper(this, val, len, /*check=*/0); } -int grib_accessor_class_g1_section4_length_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g1_section4_length_t::unpack_long(long* val, size_t* len) { - grib_accessor_g1_section4_length_t* self = (grib_accessor_g1_section4_length_t*)a; - int ret = 0; + int ret = 0; long total_length = 0, sec4_length = 0; - if ((ret = grib_get_g1_message_size(grib_handle_of_accessor(a), - grib_find_accessor(grib_handle_of_accessor(a), self->total_length), - a, + if ((ret = grib_get_g1_message_size(grib_handle_of_accessor(this), + grib_find_accessor(grib_handle_of_accessor(this), total_length_), + this, &total_length, &sec4_length)) != GRIB_SUCCESS) { return ret; diff --git a/src/accessor/grib_accessor_class_g1_section4_length.h b/src/accessor/grib_accessor_class_g1_section4_length.h index 9e805985c..a7407d063 100644 --- a/src/accessor/grib_accessor_class_g1_section4_length.h +++ b/src/accessor/grib_accessor_class_g1_section4_length.h @@ -16,16 +16,13 @@ class grib_accessor_g1_section4_length_t : public grib_accessor_section_length_t { public: - /* Members defined in g1_section4_length */ - const char* total_length; -}; - -class grib_accessor_class_g1_section4_length_t : public grib_accessor_class_section_length_t -{ -public: - grib_accessor_class_g1_section4_length_t(const char* name) : grib_accessor_class_section_length_t(name) {} + grib_accessor_g1_section4_length_t() : + grib_accessor_section_length_t() { class_name_ = "g1_section4_length"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g1_section4_length_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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* total_length_; }; diff --git a/src/accessor/grib_accessor_class_g1bitmap.cc b/src/accessor/grib_accessor_class_g1bitmap.cc index 331b800c5..6c9e6461f 100644 --- a/src/accessor/grib_accessor_class_g1bitmap.cc +++ b/src/accessor/grib_accessor_class_g1bitmap.cc @@ -10,20 +10,17 @@ #include "grib_accessor_class_g1bitmap.h" -grib_accessor_class_g1bitmap_t _grib_accessor_class_g1bitmap{ "g1bitmap" }; -grib_accessor_class* grib_accessor_class_g1bitmap = &_grib_accessor_class_g1bitmap; +grib_accessor_g1bitmap_t _grib_accessor_g1bitmap{}; +grib_accessor* grib_accessor_g1bitmap = &_grib_accessor_g1bitmap; - -void grib_accessor_class_g1bitmap_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_g1bitmap_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_bitmap_t::init(a, len, arg); - grib_accessor_g1bitmap_t* self = (grib_accessor_g1bitmap_t*)a; - self->unusedBits = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 4); + grib_accessor_bitmap_t::init(len, arg); + unusedBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, 4); } -int grib_accessor_class_g1bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_g1bitmap_t::pack_double(const double* val, size_t* len) { - grib_accessor_g1bitmap_t* self = (grib_accessor_g1bitmap_t*)a; size_t tlen; unsigned char* buf = NULL; @@ -35,10 +32,10 @@ int grib_accessor_class_g1bitmap_t::pack_double(grib_accessor* a, const double* double miss_values = 0; tlen = ((*len + bit_padding - 1) / bit_padding * bit_padding) / 8; - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &miss_values)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(grib_handle_of_accessor(this), missing_value_, &miss_values)) != GRIB_SUCCESS) return err; - buf = (unsigned char*)grib_context_malloc_clear(a->context, tlen); + buf = (unsigned char*)grib_context_malloc_clear(context_, tlen); if (!buf) return GRIB_OUT_OF_MEMORY; pos = 0; @@ -51,47 +48,45 @@ int grib_accessor_class_g1bitmap_t::pack_double(grib_accessor* a, const double* } } - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->unusedBits, tlen * 8 - *len)) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), unusedBits_, tlen * 8 - *len)) != GRIB_SUCCESS) return err; - err = grib_buffer_replace(a, buf, tlen, 1, 1); + err = grib_buffer_replace(this, buf, tlen, 1, 1); if (err) return err; - grib_context_free(a->context, buf); + grib_context_free(context_, buf); return GRIB_SUCCESS; } -int grib_accessor_class_g1bitmap_t::value_count(grib_accessor* a, long* count) +int grib_accessor_g1bitmap_t::value_count(long* count) { - grib_accessor_g1bitmap_t* self = (grib_accessor_g1bitmap_t*)a; long tlen; int err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->unusedBits, &tlen)) != GRIB_SUCCESS) - grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_class_bitmap.value_count : cannot get %s err=%d", self->unusedBits, err); + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), unusedBits_, &tlen)) != GRIB_SUCCESS) + grib_context_log(context_, GRIB_LOG_ERROR, "grib_accessor_bitmap.value_count : cannot get %s err=%d", unusedBits_, err); - *count = (a->length * 8) - tlen; + *count = (length_ * 8) - tlen; return err; } -int grib_accessor_class_g1bitmap_t::unpack_bytes(grib_accessor* a, unsigned char* val, size_t* len) +int grib_accessor_g1bitmap_t::unpack_bytes(unsigned char* val, size_t* len) { - unsigned char* buf = grib_handle_of_accessor(a)->buffer->data; - grib_accessor_g1bitmap_t* self = (grib_accessor_g1bitmap_t*)a; + unsigned char* buf = grib_handle_of_accessor(this)->buffer->data; long tlen; int err; - long length = a->byte_count(); - long offset = a->byte_offset(); + long length = byte_count(); + long offset = byte_offset(); if (*len < (size_t)length) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it is %ld bytes long\n", a->name, length); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s it is %ld bytes long\n", name_, length); *len = length; return GRIB_ARRAY_TOO_SMALL; } - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->unusedBits, &tlen)) != GRIB_SUCCESS) - grib_context_log(a->context, GRIB_LOG_ERROR, - "grib_accessor_class_bitmap.unpack_bytes : cannot get %s err=%d", self->unusedBits, err); + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), unusedBits_, &tlen)) != GRIB_SUCCESS) + grib_context_log(context_, GRIB_LOG_ERROR, + "grib_accessor_bitmap.unpack_bytes : cannot get %s err=%d", unusedBits_, err); length -= tlen / 8; memcpy(val, buf + offset, length); diff --git a/src/accessor/grib_accessor_class_g1bitmap.h b/src/accessor/grib_accessor_class_g1bitmap.h index 28914c591..7c509662c 100644 --- a/src/accessor/grib_accessor_class_g1bitmap.h +++ b/src/accessor/grib_accessor_class_g1bitmap.h @@ -16,17 +16,14 @@ class grib_accessor_g1bitmap_t : public grib_accessor_bitmap_t { public: - /* Members defined in g1bitmap */ - const char* unusedBits; -}; - -class grib_accessor_class_g1bitmap_t : public grib_accessor_class_bitmap_t -{ -public: - grib_accessor_class_g1bitmap_t(const char* name) : grib_accessor_class_bitmap_t(name) {} + grib_accessor_g1bitmap_t() : + grib_accessor_bitmap_t() { class_name_ = "g1bitmap"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g1bitmap_t{}; } - int pack_double(grib_accessor*, const double* val, size_t* len) override; - int unpack_bytes(grib_accessor*, unsigned char*, size_t* len) override; - int value_count(grib_accessor*, long*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int pack_double(const double* val, size_t* len) override; + int unpack_bytes(unsigned char*, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* unusedBits_; }; diff --git a/src/accessor/grib_accessor_class_g1date.cc b/src/accessor/grib_accessor_class_g1date.cc index c9a3055dd..167265361 100644 --- a/src/accessor/grib_accessor_class_g1date.cc +++ b/src/accessor/grib_accessor_class_g1date.cc @@ -10,38 +10,35 @@ #include "grib_accessor_class_g1date.h" -grib_accessor_class_g1date_t _grib_accessor_class_g1date{ "g1date" }; -grib_accessor_class* grib_accessor_class_g1date = &_grib_accessor_class_g1date; +grib_accessor_g1date_t _grib_accessor_g1date{}; +grib_accessor* grib_accessor_g1date = &_grib_accessor_g1date; - -void grib_accessor_class_g1date_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g1date_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_g1date_t* self = (grib_accessor_g1date_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_long_t::init(l, c); + grib_handle* hand = grib_handle_of_accessor(this); + int n = 0; - self->century = grib_arguments_get_name(hand, c, n++); - self->year = grib_arguments_get_name(hand, c, n++); - self->month = grib_arguments_get_name(hand, c, n++); - self->day = grib_arguments_get_name(hand, c, n++); + century_ = grib_arguments_get_name(hand, c, n++); + year_ = grib_arguments_get_name(hand, c, n++); + month_ = grib_arguments_get_name(hand, c, n++); + day_ = grib_arguments_get_name(hand, c, n++); } -int grib_accessor_class_g1date_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g1date_t::unpack_long(long* val, size_t* len) { - grib_accessor_g1date_t* self = (grib_accessor_g1date_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); int ret = 0; long year = 0, century = 0, month = 0, day = 0; - if ((ret = grib_get_long_internal(hand, self->century, ¢ury)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, century_, ¢ury)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->day, &day)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, day_, &day)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->month, &month)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, month_, &month)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->year, &year)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, year_, &year)) != GRIB_SUCCESS) return ret; if (*len < 1) @@ -60,10 +57,9 @@ int grib_accessor_class_g1date_t::unpack_long(grib_accessor* a, long* val, size_ return GRIB_SUCCESS; } -int grib_accessor_class_g1date_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_g1date_t::pack_long(const long* val, size_t* len) { - grib_accessor_g1date_t* self = (grib_accessor_g1date_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); int ret = 0; long v = val[0]; @@ -74,7 +70,7 @@ int grib_accessor_class_g1date_t::pack_long(grib_accessor* a, const long* val, s long d = grib_julian_to_date(grib_date_to_julian(v)); if (v != d) { - grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_g1date_t: pack_long invalid date %ld, changed to %ld", v, d); + grib_context_log(context_, GRIB_LOG_ERROR, "grib_accessor_g1date_t: pack_long invalid date %ld, changed to %ld", v, d); return GRIB_ENCODING_ERROR; } @@ -91,13 +87,13 @@ int grib_accessor_class_g1date_t::pack_long(grib_accessor* a, const long* val, s else century++; - if ((ret = grib_set_long_internal(hand, self->century, century)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, century_, century)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(hand, self->day, day)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, day_, day)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(hand, self->month, month)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, month_, month)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(hand, self->year, year)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, year_, year)) != GRIB_SUCCESS) return ret; return GRIB_SUCCESS; @@ -118,22 +114,21 @@ static const char* months[] = { "dec", }; -int grib_accessor_class_g1date_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_g1date_t::unpack_string(char* val, size_t* len) { - grib_accessor_g1date_t* self = (grib_accessor_g1date_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); int ret = 0; char tmp[1024]; long year = 0, century = 0, month = 0, day = 0; - if ((ret = grib_get_long_internal(hand, self->century, ¢ury)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, century_, ¢ury)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->day, &day)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, day_, &day)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->month, &month)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, month_, &month)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->year, &year)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, year_, &year)) != GRIB_SUCCESS) return ret; if (*len < 1) @@ -162,7 +157,7 @@ int grib_accessor_class_g1date_t::unpack_string(grib_accessor* a, char* val, siz return GRIB_SUCCESS; } -int grib_accessor_class_g1date_t::value_count(grib_accessor* a, long* count) +int grib_accessor_g1date_t::value_count(long* count) { *count = 1; return 0; diff --git a/src/accessor/grib_accessor_class_g1date.h b/src/accessor/grib_accessor_class_g1date.h index 1195ac01c..87aab7b6d 100644 --- a/src/accessor/grib_accessor_class_g1date.h +++ b/src/accessor/grib_accessor_class_g1date.h @@ -16,21 +16,18 @@ class grib_accessor_g1date_t : public grib_accessor_long_t { public: - /* Members defined in g1date */ - const char* century; - const char* year; - const char* month; - const char* day; -}; - -class grib_accessor_class_g1date_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_g1date_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_g1date_t() : + grib_accessor_long_t() { class_name_ = "g1date"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g1date_t{}; } - int pack_long(grib_accessor*, const long* 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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +public: + const char* century_; + const char* year_; + const char* month_; + const char* day_; }; diff --git a/src/accessor/grib_accessor_class_g1day_of_the_year_date.cc b/src/accessor/grib_accessor_class_g1day_of_the_year_date.cc index 9ca30593b..ba77d0cf0 100644 --- a/src/accessor/grib_accessor_class_g1day_of_the_year_date.cc +++ b/src/accessor/grib_accessor_class_g1day_of_the_year_date.cc @@ -10,26 +10,24 @@ #include "grib_accessor_class_g1day_of_the_year_date.h" -grib_accessor_class_g1day_of_the_year_date_t _grib_accessor_class_g1day_of_the_year_date{ "g1day_of_the_year_date" }; -grib_accessor_class* grib_accessor_class_g1day_of_the_year_date = &_grib_accessor_class_g1day_of_the_year_date; +grib_accessor_g1day_of_the_year_date_t _grib_accessor_g1day_of_the_year_date{}; +grib_accessor* grib_accessor_g1day_of_the_year_date = &_grib_accessor_g1day_of_the_year_date; - -void grib_accessor_class_g1day_of_the_year_date_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g1day_of_the_year_date_t::init(const long l, grib_arguments* c) { - grib_accessor_class_g1date_t::init(a, l, c); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + grib_accessor_g1date_t::init(l, c); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -void grib_accessor_class_g1day_of_the_year_date_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_g1day_of_the_year_date_t::dump(grib_dumper* dumper) { - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); } -int grib_accessor_class_g1day_of_the_year_date_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_g1day_of_the_year_date_t::unpack_string(char* val, size_t* len) { /* special clim case where each mont have 30 days.. to comply with mars*/ - grib_accessor_g1day_of_the_year_date_t* self = (grib_accessor_g1day_of_the_year_date_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); char tmp[1024]; long year = 0; @@ -39,10 +37,10 @@ int grib_accessor_class_g1day_of_the_year_date_t::unpack_string(grib_accessor* a long fullyear = 0; long fake_day_of_year = 0; - grib_get_long_internal(hand, self->century, ¢ury); - grib_get_long_internal(hand, self->day, &day); - grib_get_long_internal(hand, self->month, &month); - grib_get_long_internal(hand, self->year, &year); + grib_get_long_internal(hand, century_, ¢ury); + grib_get_long_internal(hand, day_, &day); + grib_get_long_internal(hand, month_, &month); + grib_get_long_internal(hand, year_, &year); fullyear = ((century - 1) * 100 + year); fake_day_of_year = ((month - 1) * 30) + day; diff --git a/src/accessor/grib_accessor_class_g1day_of_the_year_date.h b/src/accessor/grib_accessor_class_g1day_of_the_year_date.h index 5e484686c..b2ea10c49 100644 --- a/src/accessor/grib_accessor_class_g1day_of_the_year_date.h +++ b/src/accessor/grib_accessor_class_g1day_of_the_year_date.h @@ -16,15 +16,10 @@ class grib_accessor_g1day_of_the_year_date_t : public grib_accessor_g1date_t { public: - /* Members defined in g1day_of_the_year_date */ -}; - -class grib_accessor_class_g1day_of_the_year_date_t : public grib_accessor_class_g1date_t -{ -public: - grib_accessor_class_g1day_of_the_year_date_t(const char* name) : grib_accessor_class_g1date_t(name) {} + grib_accessor_g1day_of_the_year_date_t() : + grib_accessor_g1date_t() { class_name_ = "g1day_of_the_year_date"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g1day_of_the_year_date_t{}; } - int unpack_string(grib_accessor*, char*, size_t* len) override; - void dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_string(char*, size_t* len) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_g1end_of_interval_monthly.cc b/src/accessor/grib_accessor_class_g1end_of_interval_monthly.cc index 3bf953598..994eda701 100644 --- a/src/accessor/grib_accessor_class_g1end_of_interval_monthly.cc +++ b/src/accessor/grib_accessor_class_g1end_of_interval_monthly.cc @@ -10,33 +10,30 @@ #include "grib_accessor_class_g1end_of_interval_monthly.h" -grib_accessor_class_g1end_of_interval_monthly_t _grib_accessor_class_g1end_of_interval_monthly{ "g1end_of_interval_monthly" }; -grib_accessor_class* grib_accessor_class_g1end_of_interval_monthly = &_grib_accessor_class_g1end_of_interval_monthly; +grib_accessor_g1end_of_interval_monthly_t _grib_accessor_g1end_of_interval_monthly{}; +grib_accessor* grib_accessor_g1end_of_interval_monthly = &_grib_accessor_g1end_of_interval_monthly; - -void grib_accessor_class_g1end_of_interval_monthly_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g1end_of_interval_monthly_t::init(const long l, grib_arguments* c) { - grib_accessor_class_abstract_vector_t::init(a, l, c); - grib_accessor_g1end_of_interval_monthly_t* self = (grib_accessor_g1end_of_interval_monthly_t*)a; - int n = 0; + grib_accessor_abstract_vector_t::init(l, c); + int n = 0; - self->verifyingMonth = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; + verifyingMonth_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + flags_ |= GRIB_ACCESSOR_FLAG_HIDDEN; - self->number_of_elements = 6; - self->v = (double*)grib_context_malloc(a->context, sizeof(double) * self->number_of_elements); + number_of_elements_ = 6; + v_ = (double*)grib_context_malloc(context_, sizeof(double) * number_of_elements_); - a->length = 0; - a->dirty = 1; + length_ = 0; + dirty_ = 1; } -int grib_accessor_class_g1end_of_interval_monthly_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_g1end_of_interval_monthly_t::unpack_double(double* val, size_t* len) { - grib_accessor_g1end_of_interval_monthly_t* self = (grib_accessor_g1end_of_interval_monthly_t*)a; - int ret = 0; - char verifyingMonth[7] = { + int ret = 0; + char verifyingMonth[7] = { 0, }; size_t slen = 7; @@ -44,13 +41,13 @@ int grib_accessor_class_g1end_of_interval_monthly_t::unpack_double(grib_accessor const long mdays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; long days = 0; - if (!a->dirty) + if (!dirty_) return GRIB_SUCCESS; - if (*len != (size_t)self->number_of_elements) + if (*len != (size_t)number_of_elements_) return GRIB_ARRAY_TOO_SMALL; - if ((ret = grib_get_string(grib_handle_of_accessor(a), self->verifyingMonth, verifyingMonth, &slen)) != GRIB_SUCCESS) + if ((ret = grib_get_string(grib_handle_of_accessor(this), verifyingMonth_, verifyingMonth, &slen)) != GRIB_SUCCESS) return ret; date = atoi(verifyingMonth); @@ -68,41 +65,39 @@ int grib_accessor_class_g1end_of_interval_monthly_t::unpack_double(grib_accessor if (month < 1 || month > 12) return GRIB_INVALID_ARGUMENT; days = mdays[month - 1]; } - self->v[0] = year; - self->v[1] = month; + v_[0] = year; + v_[1] = month; - self->v[2] = days; - self->v[3] = 24; - self->v[4] = 00; - self->v[5] = 00; + v_[2] = days; + v_[3] = 24; + v_[4] = 00; + v_[5] = 00; - a->dirty = 0; + dirty_ = 0; - val[0] = self->v[0]; - val[1] = self->v[1]; - val[2] = self->v[2]; - val[3] = self->v[3]; - val[4] = self->v[4]; - val[5] = self->v[5]; + val[0] = v_[0]; + val[1] = v_[1]; + val[2] = v_[2]; + val[3] = v_[3]; + val[4] = v_[4]; + val[5] = v_[5]; return ret; } -int grib_accessor_class_g1end_of_interval_monthly_t::value_count(grib_accessor* a, long* count) +int grib_accessor_g1end_of_interval_monthly_t::value_count(long* count) { - grib_accessor_g1end_of_interval_monthly_t* self = (grib_accessor_g1end_of_interval_monthly_t*)a; - *count = self->number_of_elements; + *count = number_of_elements_; return 0; } -void grib_accessor_class_g1end_of_interval_monthly_t::destroy(grib_context* c, grib_accessor* a) +void grib_accessor_g1end_of_interval_monthly_t::destroy(grib_context* c) { - grib_accessor_g1end_of_interval_monthly_t* self = (grib_accessor_g1end_of_interval_monthly_t*)a; - grib_context_free(c, self->v); - grib_accessor_class_abstract_vector_t::destroy(c, a); + grib_context_free(c, v_); + grib_accessor_abstract_vector_t::destroy(c); } -int grib_accessor_class_g1end_of_interval_monthly_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_g1end_of_interval_monthly_t::compare(grib_accessor* b) { int retval = GRIB_SUCCESS; double* aval = 0; @@ -113,7 +108,7 @@ int grib_accessor_class_g1end_of_interval_monthly_t::compare(grib_accessor* a, g size_t blen = 0; int err = 0; - err = a->value_count(&count); + err = value_count(&count); if (err) return err; alen = count; @@ -126,20 +121,20 @@ int grib_accessor_class_g1end_of_interval_monthly_t::compare(grib_accessor* a, g if (alen != blen) return GRIB_COUNT_MISMATCH; - aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); - bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); + aval = (double*)grib_context_malloc(context_, alen * sizeof(double)); + bval = (double*)grib_context_malloc(b->context_, blen * sizeof(double)); - b->dirty = 1; - a->dirty = 1; + b->dirty_ = 1; + dirty_ = 1; - err = a->unpack_double(aval, &alen); + err = unpack_double(aval, &alen); err = b->unpack_double(bval, &blen); for (size_t i = 0; i < alen && retval == GRIB_SUCCESS; ++i) { if (aval[i] != bval[i]) retval = GRIB_DOUBLE_VALUE_MISMATCH; } - grib_context_free(a->context, aval); - grib_context_free(b->context, bval); + grib_context_free(context_, aval); + grib_context_free(b->context_, bval); return retval; } diff --git a/src/accessor/grib_accessor_class_g1end_of_interval_monthly.h b/src/accessor/grib_accessor_class_g1end_of_interval_monthly.h index baaea5320..462fb7c8f 100644 --- a/src/accessor/grib_accessor_class_g1end_of_interval_monthly.h +++ b/src/accessor/grib_accessor_class_g1end_of_interval_monthly.h @@ -16,18 +16,15 @@ class grib_accessor_g1end_of_interval_monthly_t : public grib_accessor_abstract_vector_t { public: - /* Members defined in g1end_of_interval_monthly */ - const char* verifyingMonth; -}; - -class grib_accessor_class_g1end_of_interval_monthly_t : public grib_accessor_class_abstract_vector_t -{ -public: - grib_accessor_class_g1end_of_interval_monthly_t(const char* name) : grib_accessor_class_abstract_vector_t(name) {} + grib_accessor_g1end_of_interval_monthly_t() : + grib_accessor_abstract_vector_t() { class_name_ = "g1end_of_interval_monthly"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g1end_of_interval_monthly_t{}; } - int unpack_double(grib_accessor*, double* 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 compare(grib_accessor*, grib_accessor*) override; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void destroy(grib_context*) override; + void init(const long, grib_arguments*) override; + int compare(grib_accessor*) override; + +private: + const char* verifyingMonth_; }; diff --git a/src/accessor/grib_accessor_class_g1fcperiod.cc b/src/accessor/grib_accessor_class_g1fcperiod.cc index 454a684d0..29de64124 100644 --- a/src/accessor/grib_accessor_class_g1fcperiod.cc +++ b/src/accessor/grib_accessor_class_g1fcperiod.cc @@ -10,16 +10,15 @@ #include "grib_accessor_class_g1fcperiod.h" -grib_accessor_class_g1fcperiod_t _grib_accessor_class_g1fcperiod{ "g1fcperiod" }; -grib_accessor_class* grib_accessor_class_g1fcperiod = &_grib_accessor_class_g1fcperiod; +grib_accessor_g1fcperiod_t _grib_accessor_g1fcperiod{}; +grib_accessor* grib_accessor_g1fcperiod = &_grib_accessor_g1fcperiod; - -int grib_accessor_class_g1fcperiod_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_g1fcperiod_t::unpack_string(char* val, size_t* len) { long start = 0, theEnd = 0; char tmp[1024]; const size_t tmpLen = sizeof(tmp); - int err = grib_g1_step_get_steps(a, &start, &theEnd); + int err = grib_g1_step_get_steps(this, &start, &theEnd); size_t l = 0; if (err) diff --git a/src/accessor/grib_accessor_class_g1fcperiod.h b/src/accessor/grib_accessor_class_g1fcperiod.h index 1b5b8dc7e..e609853b9 100644 --- a/src/accessor/grib_accessor_class_g1fcperiod.h +++ b/src/accessor/grib_accessor_class_g1fcperiod.h @@ -16,13 +16,8 @@ class grib_accessor_g1fcperiod_t : public grib_accessor_g1step_range_t { public: - /* Members defined in g1fcperiod */ -}; - -class grib_accessor_class_g1fcperiod_t : public grib_accessor_class_g1step_range_t -{ -public: - grib_accessor_class_g1fcperiod_t(const char* name) : grib_accessor_class_g1step_range_t(name) {} + grib_accessor_g1fcperiod_t() : + grib_accessor_g1step_range_t() { class_name_ = "g1fcperiod"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g1fcperiod_t{}; } - int unpack_string(grib_accessor*, char*, size_t* len) override; + int unpack_string(char*, size_t* len) override; }; diff --git a/src/accessor/grib_accessor_class_g1forecastmonth.cc b/src/accessor/grib_accessor_class_g1forecastmonth.cc index c7745cfa7..e6a73aeab 100644 --- a/src/accessor/grib_accessor_class_g1forecastmonth.cc +++ b/src/accessor/grib_accessor_class_g1forecastmonth.cc @@ -10,30 +10,28 @@ #include "grib_accessor_class_g1forecastmonth.h" -grib_accessor_class_g1forecastmonth_t _grib_accessor_class_g1forecastmonth{ "g1forecastmonth" }; -grib_accessor_class* grib_accessor_class_g1forecastmonth = &_grib_accessor_class_g1forecastmonth; +grib_accessor_g1forecastmonth_t _grib_accessor_g1forecastmonth{}; +grib_accessor* grib_accessor_g1forecastmonth = &_grib_accessor_g1forecastmonth; - -void grib_accessor_class_g1forecastmonth_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g1forecastmonth_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_g1forecastmonth_t* self = (grib_accessor_g1forecastmonth_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_long_t::init(l, c); + grib_handle* h = grib_handle_of_accessor(this); + int n = 0; const int count = grib_arguments_get_count(c); if (count == 6) { /* GRIB1 case -- this needs to be refactored */ - self->verification_yearmonth = grib_arguments_get_name(h, c, n++); - self->base_date = grib_arguments_get_name(h, c, n++); - self->day = grib_arguments_get_name(h, c, n++); - self->hour = grib_arguments_get_name(h, c, n++); - self->fcmonth = grib_arguments_get_name(h, c, n++); - self->check = grib_arguments_get_name(h, c, n++); + verification_yearmonth_ = grib_arguments_get_name(h, c, n++); + base_date_ = grib_arguments_get_name(h, c, n++); + day_ = grib_arguments_get_name(h, c, n++); + hour_ = grib_arguments_get_name(h, c, n++); + fcmonth_ = grib_arguments_get_name(h, c, n++); + check_ = grib_arguments_get_name(h, c, n++); } } -void grib_accessor_class_g1forecastmonth_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_g1forecastmonth_t::dump(grib_dumper* dumper) { - grib_dump_long(dumper, a, NULL); + grib_dump_long(dumper, this, NULL); } static int calculate_fcmonth(grib_accessor* a, long verification_yearmonth, long base_date, long day, long hour, long* result) @@ -62,8 +60,9 @@ static int calculate_fcmonth(grib_accessor* a, long verification_yearmonth, long static int unpack_long_edition2(grib_accessor* a, long* val, size_t* len) { - int err = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_g1forecastmonth_t* self = (grib_accessor_g1forecastmonth_t*)a; + int err = 0; + grib_handle* h = grib_handle_of_accessor(a); long dataDate, verification_yearmonth; long year, month, day, hour, minute, second; long year2, month2, day2, hour2, minute2, second2; @@ -85,7 +84,7 @@ static int unpack_long_edition2(grib_accessor* a, long* val, size_t* len) if ((err = grib_get_long_internal(h, "indicatorOfUnitOfTimeRange", &indicatorOfUnitOfTimeRange)) != GRIB_SUCCESS) return err; if (indicatorOfUnitOfTimeRange != 1) { /* must be hour */ - grib_context_log(a->context, GRIB_LOG_ERROR, "indicatorOfUnitOfTimeRange must be 1 (hour)"); + grib_context_log(a->context_, GRIB_LOG_ERROR, "indicatorOfUnitOfTimeRange must be 1 (hour)"); return GRIB_DECODING_ERROR; } @@ -107,8 +106,8 @@ static int unpack_long_edition2(grib_accessor* a, long* val, size_t* len) static int unpack_long_edition1(grib_accessor* a, long* val, size_t* len) { - int err = 0; grib_accessor_g1forecastmonth_t* self = (grib_accessor_g1forecastmonth_t*)a; + int err = 0; long verification_yearmonth = 0; long base_date = 0; @@ -119,17 +118,17 @@ static int unpack_long_edition1(grib_accessor* a, long* val, size_t* len) long fcmonth = 0; if ((err = grib_get_long_internal(grib_handle_of_accessor(a), - self->verification_yearmonth, &verification_yearmonth)) != GRIB_SUCCESS) + self->verification_yearmonth_, &verification_yearmonth)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->base_date, &base_date)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->base_date_, &base_date)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->day, &day)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->day_, &day)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->hour, &hour)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->hour_, &hour)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->fcmonth, &gribForecastMonth)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->fcmonth_, &gribForecastMonth)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->check, &check)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->check_, &check)) != GRIB_SUCCESS) return err; if ((err = calculate_fcmonth(a, verification_yearmonth, base_date, day, hour, val)) != GRIB_SUCCESS) @@ -139,8 +138,8 @@ static int unpack_long_edition1(grib_accessor* a, long* val, size_t* len) fcmonth = *val; if (gribForecastMonth != 0 && gribForecastMonth != fcmonth) { if (check) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s=%ld (%s-%s)=%ld", self->fcmonth, - gribForecastMonth, self->base_date, self->verification_yearmonth, fcmonth); + grib_context_log(a->context_, GRIB_LOG_ERROR, "%s=%ld (%s-%s)=%ld", self->fcmonth_, + gribForecastMonth, base_date, self->verification_yearmonth_, fcmonth); Assert(gribForecastMonth == fcmonth); } else { @@ -152,26 +151,25 @@ static int unpack_long_edition1(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -int grib_accessor_class_g1forecastmonth_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g1forecastmonth_t::unpack_long(long* val, size_t* len) { int err = 0; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); long edition = 0; if ((err = grib_get_long(hand, "edition", &edition)) != GRIB_SUCCESS) return err; if (edition == 1) - return unpack_long_edition1(a, val, len); + return unpack_long_edition1(this, val, len); if (edition == 2) - return unpack_long_edition2(a, val, len); + return unpack_long_edition2(this, val, len); return GRIB_UNSUPPORTED_EDITION; } /* TODO: Check for a valid date */ -int grib_accessor_class_g1forecastmonth_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_g1forecastmonth_t::pack_long(const long* val, size_t* len) { - grib_accessor_g1forecastmonth_t* self = (grib_accessor_g1forecastmonth_t*)a; - return grib_set_long_internal(grib_handle_of_accessor(a), self->fcmonth, *val); + return grib_set_long_internal(grib_handle_of_accessor(this), fcmonth_, *val); } diff --git a/src/accessor/grib_accessor_class_g1forecastmonth.h b/src/accessor/grib_accessor_class_g1forecastmonth.h index cd3a6d5f6..c19be2f31 100644 --- a/src/accessor/grib_accessor_class_g1forecastmonth.h +++ b/src/accessor/grib_accessor_class_g1forecastmonth.h @@ -16,22 +16,19 @@ class grib_accessor_g1forecastmonth_t : public grib_accessor_long_t { public: - /* Members defined in g1forecastmonth */ - const char* verification_yearmonth; - const char* base_date; - const char* day; - const char* hour; - const char* fcmonth; - const char* check; -}; - -class grib_accessor_class_g1forecastmonth_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_g1forecastmonth_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_g1forecastmonth_t() : + grib_accessor_long_t() { class_name_ = "g1forecastmonth"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g1forecastmonth_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 dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +public: + const char* verification_yearmonth_; + const char* base_date_; + const char* day_; + const char* hour_; + const char* fcmonth_; + const char* check_; }; diff --git a/src/accessor/grib_accessor_class_g1monthlydate.cc b/src/accessor/grib_accessor_class_g1monthlydate.cc index 04ee6c5f3..851f27988 100644 --- a/src/accessor/grib_accessor_class_g1monthlydate.cc +++ b/src/accessor/grib_accessor_class_g1monthlydate.cc @@ -10,26 +10,23 @@ #include "grib_accessor_class_g1monthlydate.h" -grib_accessor_class_g1monthlydate_t _grib_accessor_class_g1monthlydate{ "g1monthlydate" }; -grib_accessor_class* grib_accessor_class_g1monthlydate = &_grib_accessor_class_g1monthlydate; +grib_accessor_g1monthlydate_t _grib_accessor_g1monthlydate{}; +grib_accessor* grib_accessor_g1monthlydate = &_grib_accessor_g1monthlydate; - -void grib_accessor_class_g1monthlydate_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g1monthlydate_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_g1monthlydate_t* self = (grib_accessor_g1monthlydate_t*)a; + grib_accessor_long_t::init(l, c); + int n = 0; - self->date = grib_arguments_get_name(grib_handle_of_accessor(a), c, 0); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + date_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_g1monthlydate_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g1monthlydate_t::unpack_long(long* val, size_t* len) { - grib_accessor_g1monthlydate_t* self = (grib_accessor_g1monthlydate_t*)a; - long date = 0; - grib_get_long_internal(grib_handle_of_accessor(a), self->date, &date); + grib_get_long_internal(grib_handle_of_accessor(this), date_, &date); date /= 100; date *= 100; diff --git a/src/accessor/grib_accessor_class_g1monthlydate.h b/src/accessor/grib_accessor_class_g1monthlydate.h index 8503fa0af..8c904c524 100644 --- a/src/accessor/grib_accessor_class_g1monthlydate.h +++ b/src/accessor/grib_accessor_class_g1monthlydate.h @@ -16,15 +16,12 @@ class grib_accessor_g1monthlydate_t : public grib_accessor_long_t { public: - /* Members defined in g1monthlydate */ - const char* date; -}; - -class grib_accessor_class_g1monthlydate_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_g1monthlydate_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_g1monthlydate_t() : + grib_accessor_long_t() { class_name_ = "g1monthlydate"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g1monthlydate_t{}; } - int unpack_long(grib_accessor*, long* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* date_; }; diff --git a/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.cc b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.cc index 012b3e6a4..e77e85bd1 100644 --- a/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.cc +++ b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.cc @@ -10,57 +10,52 @@ #include "grib_accessor_class_g1number_of_coded_values_sh_complex.h" -grib_accessor_class_g1number_of_coded_values_sh_complex_t _grib_accessor_class_g1number_of_coded_values_sh_complex{ "g1number_of_coded_values_sh_complex" }; -grib_accessor_class* grib_accessor_class_g1number_of_coded_values_sh_complex = &_grib_accessor_class_g1number_of_coded_values_sh_complex; +grib_accessor_g1number_of_coded_values_sh_complex_t _grib_accessor_g1number_of_coded_values_sh_complex{}; +grib_accessor* grib_accessor_g1number_of_coded_values_sh_complex = &_grib_accessor_g1number_of_coded_values_sh_complex; - -void grib_accessor_class_g1number_of_coded_values_sh_complex_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g1number_of_coded_values_sh_complex_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_g1number_of_coded_values_sh_complex_t* self = (grib_accessor_g1number_of_coded_values_sh_complex_t*)a; - - int n = 0; - self->bitsPerValue = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->offsetBeforeData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->offsetAfterData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->unusedBits = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->JS = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->KS = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->MS = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; + grib_accessor_long_t::init(l, c); + int n = 0; + bitsPerValue_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + offsetBeforeData_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + offsetAfterData_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + unusedBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + numberOfValues_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + JS_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + KS_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + MS_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + length_ = 0; } -int grib_accessor_class_g1number_of_coded_values_sh_complex_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g1number_of_coded_values_sh_complex_t::unpack_long(long* val, size_t* len) { int ret = GRIB_SUCCESS; long bpv = 0; long offsetBeforeData = 0, offsetAfterData = 0, unusedBits = 0, numberOfValues; long JS = 0, KS = 0, MS = 0, NS = 0; - grib_accessor_g1number_of_coded_values_sh_complex_t* self = (grib_accessor_g1number_of_coded_values_sh_complex_t*)a; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bitsPerValue, &bpv)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), bitsPerValue_, &bpv)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetBeforeData, &offsetBeforeData)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetBeforeData_, &offsetBeforeData)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetAfterData, &offsetAfterData)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetAfterData_, &offsetAfterData)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->unusedBits, &unusedBits)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), unusedBits_, &unusedBits)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->JS, &JS)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), JS_, &JS)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->KS, &KS)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), KS_, &KS)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->MS, &MS)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), MS_, &MS)) != GRIB_SUCCESS) return ret; if (JS != KS || KS != MS) @@ -73,7 +68,7 @@ int grib_accessor_class_g1number_of_coded_values_sh_complex_t::unpack_long(grib_ *val = ((offsetAfterData - offsetBeforeData) * 8 - unusedBits + NS * (bpv - 32)) / bpv; } else { - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfValues, &numberOfValues)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfValues_, &numberOfValues)) != GRIB_SUCCESS) return ret; *val = numberOfValues; diff --git a/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.h b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.h index 97379631d..f14604d8f 100644 --- a/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.h +++ b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_complex.h @@ -16,22 +16,19 @@ class grib_accessor_g1number_of_coded_values_sh_complex_t : public grib_accessor_long_t { public: - /* Members defined in g1number_of_coded_values_sh_complex */ - const char* numberOfValues; - const char* bitsPerValue; - const char* offsetBeforeData; - const char* offsetAfterData; - const char* unusedBits; - const char* JS; - const char* KS; - const char* MS; -}; - -class grib_accessor_class_g1number_of_coded_values_sh_complex_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_g1number_of_coded_values_sh_complex_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_g1number_of_coded_values_sh_complex_t() : + grib_accessor_long_t() { class_name_ = "g1number_of_coded_values_sh_complex"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g1number_of_coded_values_sh_complex_t{}; } - int unpack_long(grib_accessor*, long* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* numberOfValues_; + const char* bitsPerValue_; + const char* offsetBeforeData_; + const char* offsetAfterData_; + const char* unusedBits_; + const char* JS_; + const char* KS_; + const char* MS_; }; diff --git a/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.cc b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.cc index 4e6f4fe7b..8821f6020 100644 --- a/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.cc +++ b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.cc @@ -10,44 +10,39 @@ #include "grib_accessor_class_g1number_of_coded_values_sh_simple.h" -grib_accessor_class_g1number_of_coded_values_sh_simple_t _grib_accessor_class_g1number_of_coded_values_sh_simple{ "g1number_of_coded_values_sh_simple" }; -grib_accessor_class* grib_accessor_class_g1number_of_coded_values_sh_simple = &_grib_accessor_class_g1number_of_coded_values_sh_simple; +grib_accessor_g1number_of_coded_values_sh_simple_t _grib_accessor_g1number_of_coded_values_sh_simple{}; +grib_accessor* grib_accessor_g1number_of_coded_values_sh_simple = &_grib_accessor_g1number_of_coded_values_sh_simple; - -void grib_accessor_class_g1number_of_coded_values_sh_simple_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g1number_of_coded_values_sh_simple_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_g1number_of_coded_values_sh_simple_t* self = (grib_accessor_g1number_of_coded_values_sh_simple_t*)a; - - int n = 0; - self->bitsPerValue = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->offsetBeforeData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->offsetAfterData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->unusedBits = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; + grib_accessor_long_t::init(l, c); + int n = 0; + bitsPerValue_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + offsetBeforeData_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + offsetAfterData_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + unusedBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + numberOfValues_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + length_ = 0; } -int grib_accessor_class_g1number_of_coded_values_sh_simple_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g1number_of_coded_values_sh_simple_t::unpack_long(long* val, size_t* len) { - int ret = GRIB_SUCCESS; - long bpv = 0; + int ret = GRIB_SUCCESS; + long bpv = 0; long offsetBeforeData = 0, offsetAfterData = 0, unusedBits = 0, numberOfValues; - grib_accessor_g1number_of_coded_values_sh_simple_t* self = (grib_accessor_g1number_of_coded_values_sh_simple_t*)a; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bitsPerValue, &bpv)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), bitsPerValue_, &bpv)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetBeforeData, &offsetBeforeData)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetBeforeData_, &offsetBeforeData)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetAfterData, &offsetAfterData)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetAfterData_, &offsetAfterData)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->unusedBits, &unusedBits)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), unusedBits_, &unusedBits)) != GRIB_SUCCESS) return ret; if (bpv != 0) { @@ -55,7 +50,7 @@ int grib_accessor_class_g1number_of_coded_values_sh_simple_t::unpack_long(grib_a *val = ((offsetAfterData - offsetBeforeData) * 8 - unusedBits) / bpv; } else { - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfValues, &numberOfValues)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfValues_, &numberOfValues)) != GRIB_SUCCESS) return ret; *val = numberOfValues; diff --git a/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.h b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.h index 4dafe6b15..0619a72dd 100644 --- a/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.h +++ b/src/accessor/grib_accessor_class_g1number_of_coded_values_sh_simple.h @@ -16,19 +16,16 @@ class grib_accessor_g1number_of_coded_values_sh_simple_t : public grib_accessor_long_t { public: - /* Members defined in g1number_of_coded_values_sh_simple */ - const char* numberOfValues; - const char* bitsPerValue; - const char* offsetBeforeData; - const char* offsetAfterData; - const char* unusedBits; -}; - -class grib_accessor_class_g1number_of_coded_values_sh_simple_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_g1number_of_coded_values_sh_simple_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_g1number_of_coded_values_sh_simple_t() : + grib_accessor_long_t() { class_name_ = "g1number_of_coded_values_sh_simple"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g1number_of_coded_values_sh_simple_t{}; } - int unpack_long(grib_accessor*, long* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* numberOfValues_; + const char* bitsPerValue_; + const char* offsetBeforeData_; + const char* offsetAfterData_; + const char* unusedBits_; }; diff --git a/src/accessor/grib_accessor_class_g1step_range.cc b/src/accessor/grib_accessor_class_g1step_range.cc index 0c8c886dc..d3f0aa0ce 100644 --- a/src/accessor/grib_accessor_class_g1step_range.cc +++ b/src/accessor/grib_accessor_class_g1step_range.cc @@ -10,38 +10,35 @@ #include "grib_accessor_class_g1step_range.h" -grib_accessor_class_g1step_range_t _grib_accessor_class_g1step_range{ "g1step_range" }; -grib_accessor_class* grib_accessor_class_g1step_range = &_grib_accessor_class_g1step_range; +grib_accessor_g1step_range_t _grib_accessor_g1step_range{}; +grib_accessor* grib_accessor_g1step_range = &_grib_accessor_g1step_range; - -void grib_accessor_class_g1step_range_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g1step_range_t::init(const long l, grib_arguments* c) { - grib_accessor_class_abstract_long_vector_t::init(a, l, c); - grib_accessor_g1step_range_t* self = (grib_accessor_g1step_range_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_abstract_long_vector_t::init(l, c); + grib_handle* h = grib_handle_of_accessor(this); + int n = 0; + p1_ = grib_arguments_get_name(h, c, n++); + p2_ = grib_arguments_get_name(h, c, n++); + timeRangeIndicator_ = grib_arguments_get_name(h, c, n++); + unit_ = grib_arguments_get_name(h, c, n++); + step_unit_ = grib_arguments_get_name(h, c, n++); + stepType_ = grib_arguments_get_name(h, c, n++); + patch_fp_precip_ = grib_arguments_get_name(h, c, n++); + error_on_units_ = 1; - int n = 0; - self->p1 = grib_arguments_get_name(h, c, n++); - self->p2 = grib_arguments_get_name(h, c, n++); - self->timeRangeIndicator = grib_arguments_get_name(h, c, n++); - self->unit = grib_arguments_get_name(h, c, n++); - self->step_unit = grib_arguments_get_name(h, c, n++); - self->stepType = grib_arguments_get_name(h, c, n++); - self->patch_fp_precip = grib_arguments_get_name(h, c, n++); - self->error_on_units = 1; + number_of_elements_ = 2; + v_ = (long*)grib_context_malloc_clear(h->context, + sizeof(long) * number_of_elements_); + pack_index_ = -1; + dirty_ = 1; - self->number_of_elements = 2; - self->v = (long*)grib_context_malloc_clear(h->context, - sizeof(long) * self->number_of_elements); - self->pack_index = -1; - a->dirty = 1; - - a->length = 0; + length_ = 0; } -void grib_accessor_class_g1step_range_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_g1step_range_t::dump(grib_dumper* dumper) { - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); } static const int u2s1[] = { @@ -86,42 +83,43 @@ static const int u2s[] = { 1800 /* (15) 30 minutes */ }; - int grib_g1_step_get_steps(grib_accessor* a, long* start, long* theEnd) { grib_accessor_g1step_range_t* self = (grib_accessor_g1step_range_t*)a; int err = 0; long p1 = 0, p2 = 0, unit = 0, timeRangeIndicator = 0, timeRangeIndicatorFromStepRange = 0; long step_unit = 1; - char stepType[20] = {0,}; + char stepType[20] = { + 0, + }; size_t stepTypeLen = 20; long newstart, newend; int factor = 1; long u2sf, u2sf_step_unit; grib_handle* hand = grib_handle_of_accessor(a); - if (self->step_unit != NULL) - grib_get_long_internal(hand, self->step_unit, &step_unit); + if (self->step_unit_ != NULL) + grib_get_long_internal(hand, self->step_unit_, &step_unit); if (err != GRIB_SUCCESS) return err; - err = grib_get_long_internal(hand, self->unit, &unit); + err = grib_get_long_internal(hand, self->unit_, &unit); if (err) return err; if (unit == 254) { unit = 15; /* See ECC-316: WMO says 254 is for 'seconds' but we use 15! */ } - err = grib_get_long_internal(hand, self->p1, &p1); + err = grib_get_long_internal(hand, self->p1_, &p1); if (err) return err; - err = grib_get_long_internal(hand, self->p2, &p2); + err = grib_get_long_internal(hand, self->p2_, &p2); if (err) return err; - err = grib_get_long_internal(hand, self->timeRangeIndicator, &timeRangeIndicator); + err = grib_get_long_internal(hand, self->timeRangeIndicator_, &timeRangeIndicator); if (err) return err; @@ -132,8 +130,8 @@ int grib_g1_step_get_steps(grib_accessor* a, long* start, long* theEnd) if (timeRangeIndicatorFromStepRange == 10) timeRangeIndicator = timeRangeIndicatorFromStepRange; - if (self->stepType) { - err = grib_get_string_internal(hand, self->stepType, stepType, &stepTypeLen); + if (self->stepType_) { + err = grib_get_string_internal(hand, self->stepType_, stepType, &stepTypeLen); if (err) return err; } @@ -184,47 +182,48 @@ int grib_g1_step_get_steps(grib_accessor* a, long* start, long* theEnd) return 0; } -int grib_accessor_class_g1step_range_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_g1step_range_t::unpack_string(char* val, size_t* len) { - grib_accessor_g1step_range_t* self = (grib_accessor_g1step_range_t*)a; char buf[100]; size_t size = 0; long start = 0, theEnd = 0; long timeRangeIndicator = 0; long unit; int err = 0; - char stepType[20] = {0,}; + char stepType[20] = { + 0, + }; size_t stepTypeLen = 20; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); - if ((err = grib_g1_step_get_steps(a, &start, &theEnd)) != GRIB_SUCCESS) { + if ((err = grib_g1_step_get_steps(this, &start, &theEnd)) != GRIB_SUCCESS) { size_t step_unit_string_len = 10; char step_unit_string[10]; - if (self->step_unit != NULL) - grib_get_string(hand, self->step_unit, step_unit_string, &step_unit_string_len); + if (step_unit_ != NULL) + grib_get_string(hand, step_unit_, step_unit_string, &step_unit_string_len); else snprintf(step_unit_string, sizeof(step_unit_string), "h"); - if (self->error_on_units) { - grib_get_long_internal(hand, self->unit, &unit); + if (error_on_units_) { + grib_get_long_internal(hand, unit_, &unit); if (unit == 254) { unit = 15; /* See ECC-316 */ } - grib_set_long_internal(hand, self->step_unit, unit); - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_set_long_internal(hand, step_unit_, unit); + grib_context_log(context_, GRIB_LOG_ERROR, "unable to represent the step in %s\n Hint: try changing the step units", step_unit_string); } return err; } - err = grib_get_long_internal(hand, self->timeRangeIndicator, &timeRangeIndicator); + err = grib_get_long_internal(hand, timeRangeIndicator_, &timeRangeIndicator); if (err) return err; - if (self->stepType) { - err = grib_get_string_internal(hand, self->stepType, stepType, &stepTypeLen); + if (stepType_) { + err = grib_get_string_internal(hand, stepType_, stepType, &stepTypeLen); if (err) return err; } @@ -232,7 +231,7 @@ int grib_accessor_class_g1step_range_t::unpack_string(grib_accessor* a, char* va snprintf(stepType, sizeof(stepType), "unknown"); /* Patch for old forecast probabilities */ - if (self->patch_fp_precip) { + if (patch_fp_precip_) { start += 24; } @@ -265,7 +264,7 @@ int grib_accessor_class_g1step_range_t::unpack_string(grib_accessor* a, char* va } } else { - grib_context_log(a->context, GRIB_LOG_ERROR, "Unknown stepType=[%s] timeRangeIndicator=[%ld]", stepType, timeRangeIndicator); + grib_context_log(context_, GRIB_LOG_ERROR, "Unknown stepType=[%s] timeRangeIndicator=[%ld]", stepType, timeRangeIndicator); return GRIB_NOT_IMPLEMENTED; } @@ -336,21 +335,22 @@ static int grib_g1_step_apply_units( return GRIB_WRONG_STEP; } -int grib_accessor_class_g1step_range_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_g1step_range_t::pack_string(const char* val, size_t* len) { - grib_accessor_g1step_range_t* self = (grib_accessor_g1step_range_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); long timeRangeIndicator = 0, P1 = 0, P2 = 0; long start = 0, theEnd = -1, unit = 0, ounit = 0, step_unit = 1; int ret = 0; long end_sec, start_sec; char *p = NULL, *q = NULL; int instant = 0; - char stepType[20] = {0,}; + char stepType[20] = { + 0, + }; size_t stepTypeLen = 20; - if (self->stepType) { - ret = grib_get_string_internal(h, self->stepType, stepType, &stepTypeLen); + if (stepType_) { + ret = grib_get_string_internal(h, stepType_, stepType, &stepTypeLen); if (ret) return ret; } @@ -361,18 +361,18 @@ int grib_accessor_class_g1step_range_t::pack_string(grib_accessor* a, const char return ret; /* don't change timeRangeIndicator when setting step EXCEPT IF instant*/ - if ((ret = grib_get_long_internal(h, self->timeRangeIndicator, &timeRangeIndicator))) + if ((ret = grib_get_long_internal(h, timeRangeIndicator_, &timeRangeIndicator))) return ret; instant = (strcmp(stepType, "instant") == 0) ? 1 : 0; - if ((ret = grib_get_long_internal(h, self->unit, &unit))) + if ((ret = grib_get_long_internal(h, unit_, &unit))) return ret; if (unit == 254) { unit = 15; /* See ECC-316 */ } - if (self->step_unit != NULL && (ret = grib_get_long_internal(h, self->step_unit, &step_unit))) + if (step_unit_ != NULL && (ret = grib_get_long_internal(h, step_unit_, &step_unit))) return ret; ounit = unit; @@ -383,9 +383,9 @@ int grib_accessor_class_g1step_range_t::pack_string(grib_accessor* a, const char theEnd = strtol(++p, &q, 10); if (start == 0 && theEnd == 0) { - if ((ret = grib_set_long_internal(h, self->p1, start)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(h, p1_, start)) != GRIB_SUCCESS) return ret; - ret = grib_set_long_internal(h, self->p2, theEnd); + ret = grib_set_long_internal(h, p2_, theEnd); return ret; } end_sec = theEnd * u2s[step_unit]; @@ -394,7 +394,7 @@ int grib_accessor_class_g1step_range_t::pack_string(grib_accessor* a, const char if ((end_sec > 918000 || start_sec > 918000) && h->context->gribex_mode_on && instant) { timeRangeIndicator = 10; - if ((ret = grib_set_long_internal(h, self->timeRangeIndicator, 10))) + if ((ret = grib_set_long_internal(h, timeRangeIndicator_, 10))) return ret; /* TODO move to the def file*/ if ((ret = grib_set_long_internal(h, "timeRangeIndicatorFromStepRange", 10))) @@ -411,38 +411,38 @@ int grib_accessor_class_g1step_range_t::pack_string(grib_accessor* a, const char if (h->context->gribex_mode_on == 0) { grib_context_log(h->context, GRIB_LOG_ERROR, "Unable to set %s: end must be equal to start when timeRangeIndicator=10", - a->name); + name_); return GRIB_WRONG_STEP; } else start = theEnd; } if ((ret = grib_g1_step_apply_units(&start, &theEnd, &step_unit, &P1, &P2, &unit, 65535, instant)) != GRIB_SUCCESS) { - grib_context_log(h->context, GRIB_LOG_ERROR, "unable to find units to set %s=%s", a->name, val); + grib_context_log(h->context, GRIB_LOG_ERROR, "unable to find units to set %s=%s", name_, val); return ret; } - p1_accessor = grib_find_accessor(grib_handle_of_accessor(a), self->p1); + p1_accessor = grib_find_accessor(grib_handle_of_accessor(this), p1_); if (p1_accessor == NULL) { - grib_context_log(h->context, GRIB_LOG_ERROR, "unable to find accessor %s", self->p1); + grib_context_log(h->context, GRIB_LOG_ERROR, "unable to find accessor %s", p1_); return GRIB_NOT_FOUND; } - off = p1_accessor->offset * 8; + off = p1_accessor->offset_ * 8; /* Note: here we assume the key P2 is one octet and immediately follows P1. Hence 16 bits */ - ret = grib_encode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, P1, &off, 16); + ret = grib_encode_unsigned_long(grib_handle_of_accessor(this)->buffer->data, P1, &off, 16); if (ret != 0) return ret; if (h->context->debug) { long dp1, dp2; - grib_get_long(h, self->p1, &dp1); - grib_get_long(h, self->p2, &dp2); + grib_get_long(h, p1_, &dp1); + grib_get_long(h, p2_, &dp2); fprintf(stderr, "ECCODES DEBUG pack_string: P1=%ld P2=%ld (as two octets => %ld)\n", dp1, dp2, P1); } if (ounit != unit) - ret = grib_set_long_internal(h, self->unit, unit); + ret = grib_set_long_internal(h, unit_, unit); return ret; } @@ -451,7 +451,7 @@ int grib_accessor_class_g1step_range_t::pack_string(grib_accessor* a, const char if (instant || h->context->gribex_mode_on) { long off = 0; grib_accessor* p1_accessor = NULL; - if ((ret = grib_set_long_internal(h, self->timeRangeIndicator, 10))) + if ((ret = grib_set_long_internal(h, timeRangeIndicator_, 10))) return ret; /* TODO move to the def file*/ if ((ret = grib_set_long_internal(h, "timeRangeIndicatorFromStepRange", 10))) @@ -459,110 +459,110 @@ int grib_accessor_class_g1step_range_t::pack_string(grib_accessor* a, const char if (theEnd != start && !h->context->gribex_mode_on) { grib_context_log(h->context, GRIB_LOG_ERROR, "Unable to set %s: end must be equal to start when timeRangeIndicator=10", - a->name); + name_); return GRIB_WRONG_STEP; } else start = theEnd; if ((ret = grib_g1_step_apply_units(&start, &theEnd, &step_unit, &P1, &P2, &unit, 65535, instant)) != GRIB_SUCCESS) { - grib_context_log(h->context, GRIB_LOG_ERROR, "unable to find units to set %s=%s", a->name, val); + grib_context_log(h->context, GRIB_LOG_ERROR, "unable to find units to set %s=%s", name_, val); return ret; } - p1_accessor = grib_find_accessor(grib_handle_of_accessor(a), self->p1); + p1_accessor = grib_find_accessor(grib_handle_of_accessor(this), p1_); if (p1_accessor == NULL) { - grib_context_log(h->context, GRIB_LOG_ERROR, "unable to find accessor %s", self->p1); + grib_context_log(h->context, GRIB_LOG_ERROR, "unable to find accessor %s", p1_); return GRIB_NOT_FOUND; } - off = p1_accessor->offset * 8; + off = p1_accessor->offset_ * 8; /* Note: case for timeRangeIndicator of 10 * We assume the key P2 is one octet and immediately follows P1. Hence 16 bits */ - ret = grib_encode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, P1, &off, 16); + ret = grib_encode_unsigned_long(grib_handle_of_accessor(this)->buffer->data, P1, &off, 16); if (ret != 0) return ret; if (h->context->debug) { long dp1, dp2; - grib_get_long(h, self->p1, &dp1); - grib_get_long(h, self->p2, &dp2); + grib_get_long(h, p1_, &dp1); + grib_get_long(h, p2_, &dp2); fprintf(stderr, "ECCODES DEBUG pack_string: P1=%ld P2=%ld (as two octets => %ld)\n", dp1, dp2, P1); } if (ounit != unit) - ret = grib_set_long_internal(h, self->unit, unit); + ret = grib_set_long_internal(h, unit_, unit); } if (ret == GRIB_WRONG_STEP) { grib_context_log(h->context, GRIB_LOG_ERROR, - "Failed to set %s=%s: Keys P1 and P2 are one octet each (Range 0 to 255)", a->name, val); + "Failed to set %s=%s: Keys P1 and P2 are one octet each (Range 0 to 255)", name_, val); } return ret; } if (ounit != unit) - if ((ret = grib_set_long_internal(h, self->unit, unit)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(h, unit_, unit)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(h, self->p1, P1)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(h, p1_, P1)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(h, self->p2, P2)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(h, p2_, P2)) != GRIB_SUCCESS) return ret; - self->v[0] = start; - self->v[1] = theEnd; - a->dirty = 0; + v_[0] = start; + v_[1] = theEnd; + dirty_ = 0; return 0; } -int grib_accessor_class_g1step_range_t::value_count(grib_accessor* a, long* count) +int grib_accessor_g1step_range_t::value_count(long* count) { *count = 1; return 0; } -size_t grib_accessor_class_g1step_range_t::string_length(grib_accessor* a) +size_t grib_accessor_g1step_range_t::string_length() { return 255; } -int grib_accessor_class_g1step_range_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_g1step_range_t::pack_long(const long* val, size_t* len) { - grib_accessor_g1step_range_t* self = (grib_accessor_g1step_range_t*)a; - - char buff[256] = {0,}; + char buff[256]; size_t bufflen = 100; char sval[100] = { 0 }; char* p = sval; size_t svallen = 100; - char stepType[20] = {0,}; + char stepType[20] = { + 0, + }; size_t stepTypeLen = 20; long step_unit = 0; int err = 0; - if (self->stepType) { - err = grib_get_string_internal(grib_handle_of_accessor(a), self->stepType, stepType, &stepTypeLen); + if (stepType_) { + err = grib_get_string_internal(grib_handle_of_accessor(this), stepType_, stepType, &stepTypeLen); if (err) return err; } else snprintf(stepType, sizeof(stepType), "unknown"); - if (self->step_unit != NULL && (err = grib_get_long_internal(grib_handle_of_accessor(a), self->step_unit, &step_unit))) + if (step_unit_ != NULL && (err = grib_get_long_internal(grib_handle_of_accessor(this), step_unit_, &step_unit))) return err; - switch (self->pack_index) { + switch (pack_index_) { case -1: - self->pack_index = -1; + pack_index_ = -1; snprintf(buff, sizeof(buff), "%ld", *val); - return pack_string(a, buff, &bufflen); + return pack_string(buff, &bufflen); case 0: - self->pack_index = -1; - self->error_on_units = 0; - unpack_string(a, sval, &svallen); - self->error_on_units = 1; + pack_index_ = -1; + error_on_units_ = 0; + unpack_string(sval, &svallen); + error_on_units_ = 1; while (*p != '-' && *p != '\0') p++; if (*p == '-') { @@ -576,12 +576,12 @@ int grib_accessor_class_g1step_range_t::pack_long(grib_accessor* a, const long* snprintf(buff, sizeof(buff), "%ld", *val); } } - return pack_string(a, buff, &bufflen); + return pack_string(buff, &bufflen); case 1: - self->pack_index = -1; - self->error_on_units = 0; - unpack_string(a, sval, &svallen); - self->error_on_units = 1; + pack_index_ = -1; + error_on_units_ = 0; + unpack_string(sval, &svallen); + error_on_units_ = 1; while (*p != '-' && *p != '\0') p++; if (*p == '-') { @@ -596,18 +596,17 @@ int grib_accessor_class_g1step_range_t::pack_long(grib_accessor* a, const long* snprintf(buff, sizeof(buff), "%ld", *val); } } - return pack_string(a, buff, &bufflen); + return pack_string(buff, &bufflen); default: - Assert(self->pack_index < 2); + Assert(pack_index_ < 2); break; } return GRIB_INTERNAL_ERROR; } -int grib_accessor_class_g1step_range_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g1step_range_t::unpack_long(long* val, size_t* len) { - grib_accessor_g1step_range_t* self = (grib_accessor_g1step_range_t*)a; char buff[100]; size_t bufflen = 100; long start, theEnd; @@ -616,7 +615,7 @@ int grib_accessor_class_g1step_range_t::unpack_long(grib_accessor* a, long* val, int err = 0; /*TODO implement dirty*/ - if ((err = unpack_string(a, buff, &bufflen)) != GRIB_SUCCESS) + if ((err = unpack_string(buff, &bufflen)) != GRIB_SUCCESS) return err; start = strtol(buff, &p, 10); @@ -624,26 +623,25 @@ int grib_accessor_class_g1step_range_t::unpack_long(grib_accessor* a, long* val, if (*p != 0) theEnd = strtol(++p, &q, 10); - if (self->pack_index == 1) + if (pack_index_ == 1) *val = start; else *val = theEnd; - self->v[0] = start; - self->v[1] = theEnd; - a->dirty = 0; + v_[0] = start; + v_[1] = theEnd; + dirty_ = 0; return 0; } -int grib_accessor_class_g1step_range_t::get_native_type(grib_accessor* a) +long grib_accessor_g1step_range_t::get_native_type() { return GRIB_TYPE_STRING; } -void grib_accessor_class_g1step_range_t::destroy(grib_context* c, grib_accessor* a) +void grib_accessor_g1step_range_t::destroy(grib_context* c) { - grib_accessor_g1step_range_t* self = (grib_accessor_g1step_range_t*)a; - grib_context_free(c, self->v); - grib_accessor_class_abstract_long_vector_t::destroy(c, a); + grib_context_free(c, v_); + grib_accessor_abstract_long_vector_t::destroy(c); } diff --git a/src/accessor/grib_accessor_class_g1step_range.h b/src/accessor/grib_accessor_class_g1step_range.h index 7ca19cb08..d0de789a9 100644 --- a/src/accessor/grib_accessor_class_g1step_range.h +++ b/src/accessor/grib_accessor_class_g1step_range.h @@ -16,30 +16,27 @@ class grib_accessor_g1step_range_t : public grib_accessor_abstract_long_vector_t { public: - /* Members defined in g1step_range */ - const char* p1; - const char* p2; - const char* timeRangeIndicator; - const char *unit; - const char *step_unit; - const char *stepType; - const char *patch_fp_precip; - int error_on_units; -}; - -class grib_accessor_class_g1step_range_t : public grib_accessor_class_abstract_long_vector_t -{ -public: - grib_accessor_class_g1step_range_t(const char* name) : grib_accessor_class_abstract_long_vector_t(name) {} + grib_accessor_g1step_range_t() : + grib_accessor_abstract_long_vector_t() { class_name_ = "g1step_range"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g1step_range_t{}; } - int get_native_type(grib_accessor*) 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_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; + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + int pack_string(const char*, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + int value_count(long*) override; + void destroy(grib_context*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +public: + const char* p1_; + const char* p2_; + const char* timeRangeIndicator_; + const char* unit_; + const char* step_unit_; + const char* stepType_; + const char* patch_fp_precip_; + int error_on_units_; }; diff --git a/src/accessor/grib_accessor_class_g1verificationdate.cc b/src/accessor/grib_accessor_class_g1verificationdate.cc index 3d45de3ed..9cfa720d6 100644 --- a/src/accessor/grib_accessor_class_g1verificationdate.cc +++ b/src/accessor/grib_accessor_class_g1verificationdate.cc @@ -10,27 +10,23 @@ #include "grib_accessor_class_g1verificationdate.h" -grib_accessor_class_g1verificationdate_t _grib_accessor_class_g1verificationdate{ "g1verificationdate" }; -grib_accessor_class* grib_accessor_class_g1verificationdate = &_grib_accessor_class_g1verificationdate; +grib_accessor_g1verificationdate_t _grib_accessor_g1verificationdate{}; +grib_accessor* grib_accessor_g1verificationdate = &_grib_accessor_g1verificationdate; - -void grib_accessor_class_g1verificationdate_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g1verificationdate_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_g1verificationdate_t* self = (grib_accessor_g1verificationdate_t*)a; + grib_accessor_long_t::init(l, c); int n = 0; - self->date = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->time = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->step = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + date_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + time_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + step_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_g1verificationdate_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g1verificationdate_t::unpack_long(long* val, size_t* len) { - grib_accessor_g1verificationdate_t* self = (grib_accessor_g1verificationdate_t*)a; - int ret = 0; long date = 0; long time = 0; @@ -40,11 +36,11 @@ int grib_accessor_class_g1verificationdate_t::unpack_long(grib_accessor* a, long long vdate = 0; long vd = 0; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->date, &date)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), date_, &date)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->time, &time)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), time_, &time)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->step, &step)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), step_, &step)) != GRIB_SUCCESS) return ret; time /= 100; @@ -54,7 +50,7 @@ int grib_accessor_class_g1verificationdate_t::unpack_long(grib_accessor* a, long vd = vtime / 24; vdate = grib_julian_to_date(vd); - //printf("\n********\n date %d, time %d, step %d, vdate: %d, cdate %d, vd %d\n********\n", date, time, step, vdate, cdate, vd); + // printf("\n********\n date %d, time %d, step %d, vdate: %d, cdate %d, vd %d\n********\n", date, time, step, vdate, cdate, vd); if (*len < 1) return GRIB_ARRAY_TOO_SMALL; diff --git a/src/accessor/grib_accessor_class_g1verificationdate.h b/src/accessor/grib_accessor_class_g1verificationdate.h index 0e0469926..5e1f0ac24 100644 --- a/src/accessor/grib_accessor_class_g1verificationdate.h +++ b/src/accessor/grib_accessor_class_g1verificationdate.h @@ -16,17 +16,14 @@ class grib_accessor_g1verificationdate_t : public grib_accessor_long_t { public: - /* Members defined in g1verificationdate */ - const char* date; - const char* time; - const char* step; -}; - -class grib_accessor_class_g1verificationdate_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_g1verificationdate_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_g1verificationdate_t() : + grib_accessor_long_t() { class_name_ = "g1verificationdate"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g1verificationdate_t{}; } - int unpack_long(grib_accessor*, long* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* date_; + const char* time_; + const char* step_; }; diff --git a/src/accessor/grib_accessor_class_g2_aerosol.cc b/src/accessor/grib_accessor_class_g2_aerosol.cc index 4240b74e9..a941f0c30 100644 --- a/src/accessor/grib_accessor_class_g2_aerosol.cc +++ b/src/accessor/grib_accessor_class_g2_aerosol.cc @@ -11,29 +11,26 @@ #include "grib_accessor_class_g2_aerosol.h" -grib_accessor_class_g2_aerosol_t _grib_accessor_class_g2_aerosol{ "g2_aerosol" }; -grib_accessor_class* grib_accessor_class_g2_aerosol = &_grib_accessor_class_g2_aerosol; +grib_accessor_g2_aerosol_t _grib_accessor_g2_aerosol{}; +grib_accessor* grib_accessor_g2_aerosol = &_grib_accessor_g2_aerosol; - -void grib_accessor_class_g2_aerosol_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g2_aerosol_t::init(const long l, grib_arguments* c) { - grib_accessor_class_unsigned_t::init(a, l, c); - grib_accessor_g2_aerosol_t* self = (grib_accessor_g2_aerosol_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_unsigned_t::init(l, c); + grib_handle* hand = grib_handle_of_accessor(this); + int n = 0; - self->productDefinitionTemplateNumber = grib_arguments_get_name(hand, c, n++); - self->stepType = grib_arguments_get_name(hand, c, n++); - self->optical = grib_arguments_get_long(hand, c, n++); + productDefinitionTemplateNumber_ = grib_arguments_get_name(hand, c, n++); + stepType_ = grib_arguments_get_name(hand, c, n++); + optical_ = grib_arguments_get_long(hand, c, n++); } -int grib_accessor_class_g2_aerosol_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g2_aerosol_t::unpack_long(long* val, size_t* len) { - grib_accessor_g2_aerosol_t* self = (grib_accessor_g2_aerosol_t*)a; long productDefinitionTemplateNumber = 0; - grib_get_long(grib_handle_of_accessor(a), self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber); + grib_get_long(grib_handle_of_accessor(this), productDefinitionTemplateNumber_, &productDefinitionTemplateNumber); - if (self->optical) + if (optical_) *val = grib2_is_PDTN_AerosolOptical(productDefinitionTemplateNumber); else *val = grib2_is_PDTN_Aerosol(productDefinitionTemplateNumber); @@ -41,28 +38,31 @@ int grib_accessor_class_g2_aerosol_t::unpack_long(grib_accessor* a, long* val, s return GRIB_SUCCESS; } -int grib_accessor_class_g2_aerosol_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_g2_aerosol_t::pack_long(const long* val, size_t* len) { - grib_accessor_g2_aerosol_t* self = (grib_accessor_g2_aerosol_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); long productDefinitionTemplateNumber = -1; long productDefinitionTemplateNumberNew = -1; - //long type=-1; - //long stream=-1; + // long type=-1; + // long stream=-1; long eps = -1; - char stepType[15] = {0,}; + char stepType[15] = { + 0, + }; size_t slen = 15; - //int aerosol = *val; + // int aerosol = *val; int isInstant = 0; - //long derivedForecast=-1; + // long derivedForecast=-1; int ret = 0; - if (grib_get_long(hand, self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber) != GRIB_SUCCESS) + if (grib_get_long(hand, productDefinitionTemplateNumber_, &productDefinitionTemplateNumber) != GRIB_SUCCESS) return GRIB_SUCCESS; - // grib_get_long(hand, self->type,&type); - // grib_get_long(hand, self->stream,&stream); - ret = grib_get_string(hand, self->stepType, stepType, &slen); + /* + grib_get_long(hand, type_ ,&type); + grib_get_long(hand, stream_ ,&stream); + */ + ret = grib_get_string(hand, stepType_, stepType, &slen); Assert(ret == GRIB_SUCCESS); // eps = grib2_is_PDTN_EPS(productDefinitionTemplateNumber); @@ -82,14 +82,14 @@ int grib_accessor_class_g2_aerosol_t::pack_long(grib_accessor* a, const long* va } else { if (isInstant) { - productDefinitionTemplateNumberNew = 48; // 44 is deprecated + productDefinitionTemplateNumberNew = 48; // 44 is deprecated } else { productDefinitionTemplateNumberNew = 46; } } - if (self->optical) { + if (optical_) { // Note: There is no interval based template for optical properties of aerosol! if (eps) productDefinitionTemplateNumberNew = 49; @@ -102,14 +102,14 @@ int grib_accessor_class_g2_aerosol_t::pack_long(grib_accessor* a, const long* va } if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) { - grib_set_long(hand, self->productDefinitionTemplateNumber, productDefinitionTemplateNumberNew); - // if (derivedForecast>=0) grib_set_long(hand, self->derivedForecast,derivedForecast); + grib_set_long(hand, productDefinitionTemplateNumber_, productDefinitionTemplateNumberNew); + // if (derivedForecast>=0) grib_set_long(hand, derivedForecast_ ,derivedForecast); } return 0; } -int grib_accessor_class_g2_aerosol_t::value_count(grib_accessor* a, long* count) +int grib_accessor_g2_aerosol_t::value_count(long* count) { *count = 1; return 0; diff --git a/src/accessor/grib_accessor_class_g2_aerosol.h b/src/accessor/grib_accessor_class_g2_aerosol.h index 9fbd0c79b..f50542862 100644 --- a/src/accessor/grib_accessor_class_g2_aerosol.h +++ b/src/accessor/grib_accessor_class_g2_aerosol.h @@ -16,19 +16,16 @@ class grib_accessor_g2_aerosol_t : public grib_accessor_unsigned_t { public: - /* Members defined in g2_aerosol */ - const char* productDefinitionTemplateNumber; - const char* stepType; - int optical; -}; - -class grib_accessor_class_g2_aerosol_t : public grib_accessor_class_unsigned_t -{ -public: - grib_accessor_class_g2_aerosol_t(const char* name) : grib_accessor_class_unsigned_t(name) {} + grib_accessor_g2_aerosol_t() : + grib_accessor_unsigned_t() { class_name_ = "g2_aerosol"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g2_aerosol_t{}; } - int pack_long(grib_accessor*, const long* val, size_t* len) override; - 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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* productDefinitionTemplateNumber_; + const char* stepType_; + int optical_; }; diff --git a/src/accessor/grib_accessor_class_g2_chemical.cc b/src/accessor/grib_accessor_class_g2_chemical.cc index 7b7484ecf..58ed9e55c 100644 --- a/src/accessor/grib_accessor_class_g2_chemical.cc +++ b/src/accessor/grib_accessor_class_g2_chemical.cc @@ -11,37 +11,34 @@ #include "grib_accessor_class_g2_chemical.h" -grib_accessor_class_g2_chemical_t _grib_accessor_class_g2_chemical{ "g2_chemical" }; -grib_accessor_class* grib_accessor_class_g2_chemical = &_grib_accessor_class_g2_chemical; +grib_accessor_g2_chemical_t _grib_accessor_g2_chemical{}; +grib_accessor* grib_accessor_g2_chemical = &_grib_accessor_g2_chemical; - -void grib_accessor_class_g2_chemical_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g2_chemical_t::init(const long l, grib_arguments* c) { - grib_accessor_class_unsigned_t::init(a, l, c); - grib_accessor_g2_chemical_t* self = (grib_accessor_g2_chemical_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_unsigned_t::init(l, c); + grib_handle* hand = grib_handle_of_accessor(this); + int n = 0; - self->productDefinitionTemplateNumber = grib_arguments_get_name(hand, c, n++); - self->stepType = grib_arguments_get_name(hand, c, n++); - self->chemical_type = grib_arguments_get_long(hand, c, n++); + productDefinitionTemplateNumber_ = grib_arguments_get_name(hand, c, n++); + stepType_ = grib_arguments_get_name(hand, c, n++); + chemical_type_ = grib_arguments_get_long(hand, c, n++); } -int grib_accessor_class_g2_chemical_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g2_chemical_t::unpack_long(long* val, size_t* len) { - grib_accessor_g2_chemical_t* self = (grib_accessor_g2_chemical_t*)a; long productDefinitionTemplateNumber = 0; - grib_get_long(grib_handle_of_accessor(a), self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber); + grib_get_long(grib_handle_of_accessor(this), productDefinitionTemplateNumber_, &productDefinitionTemplateNumber); // Meaning of self->chemical_type: // 0 = atmospheric chemical constituents // 1 = atmospheric chemical constituents based on a distribution function // 2 = atmospheric chemical constituents with source or sink // - Assert(self->chemical_type == 0 || self->chemical_type == 1 || self->chemical_type == 2); - if (self->chemical_type == 1) + Assert(chemical_type_ == 0 || chemical_type_ == 1 || chemical_type_ == 2); + if (chemical_type_ == 1) *val = grib2_is_PDTN_ChemicalDistFunc(productDefinitionTemplateNumber); - else if (self->chemical_type == 2) + else if (chemical_type_ == 2) *val = grib2_is_PDTN_ChemicalSourceSink(productDefinitionTemplateNumber); else *val = grib2_is_PDTN_Chemical(productDefinitionTemplateNumber); @@ -49,28 +46,29 @@ int grib_accessor_class_g2_chemical_t::unpack_long(grib_accessor* a, long* val, return GRIB_SUCCESS; } -int grib_accessor_class_g2_chemical_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_g2_chemical_t::pack_long(const long* val, size_t* len) { - grib_accessor_g2_chemical_t* self = (grib_accessor_g2_chemical_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); long productDefinitionTemplateNumber = -1; long productDefinitionTemplateNumberNew = -1; // long type=-1; // long stream=-1; long eps = -1; - char stepType[15] = {0,}; + char stepType[15] = { + 0, + }; size_t slen = 15; // int chemical = *val; int isInstant = 0; // long derivedForecast=-1; int ret = 0; - if (grib_get_long(hand, self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber) != GRIB_SUCCESS) + if (grib_get_long(hand, productDefinitionTemplateNumber_, &productDefinitionTemplateNumber) != GRIB_SUCCESS) return GRIB_SUCCESS; - // grib_get_long(hand, self->type,&type); - // grib_get_long(hand, self->stream,&stream); - ret = grib_get_string(hand, self->stepType, stepType, &slen); + // grib_get_long(hand, type_ ,&type); + // grib_get_long(hand, stream_ ,&stream); + ret = grib_get_string(hand, stepType_, stepType, &slen); Assert(ret == GRIB_SUCCESS); eps = grib_is_defined(hand, "perturbationNumber"); @@ -84,55 +82,55 @@ int grib_accessor_class_g2_chemical_t::pack_long(grib_accessor* a, const long* v // 1 = atmospheric chemical constituents based on a distribution function // 2 = atmospheric chemical constituents with source or sink // - Assert(self->chemical_type == 0 || self->chemical_type == 1 || self->chemical_type == 2); + Assert(chemical_type_ == 0 || chemical_type_ == 1 || chemical_type_ == 2); if (eps == 1) { if (isInstant) { - if (self->chemical_type == 0) + if (chemical_type_ == 0) productDefinitionTemplateNumberNew = 41; - else if (self->chemical_type == 1) + else if (chemical_type_ == 1) productDefinitionTemplateNumberNew = 58; - else if (self->chemical_type == 2) + else if (chemical_type_ == 2) productDefinitionTemplateNumberNew = 77; } else { - if (self->chemical_type == 0) + if (chemical_type_ == 0) productDefinitionTemplateNumberNew = 43; - else if (self->chemical_type == 1) + else if (chemical_type_ == 1) productDefinitionTemplateNumberNew = 68; - else if (self->chemical_type == 2) + else if (chemical_type_ == 2) productDefinitionTemplateNumberNew = 79; } } else { // deterministic if (isInstant) { - if (self->chemical_type == 0) + if (chemical_type_ == 0) productDefinitionTemplateNumberNew = 40; - else if (self->chemical_type == 1) + else if (chemical_type_ == 1) productDefinitionTemplateNumberNew = 57; - else if (self->chemical_type == 2) + else if (chemical_type_ == 2) productDefinitionTemplateNumberNew = 76; } else { - if (self->chemical_type == 0) + if (chemical_type_ == 0) productDefinitionTemplateNumberNew = 42; - else if (self->chemical_type == 1) + else if (chemical_type_ == 1) productDefinitionTemplateNumberNew = 67; - else if (self->chemical_type == 2) + else if (chemical_type_ == 2) productDefinitionTemplateNumberNew = 78; } } if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) { - grib_set_long(hand, self->productDefinitionTemplateNumber, productDefinitionTemplateNumberNew); - //if (derivedForecast>=0) grib_set_long(hand, self->derivedForecast,derivedForecast); + grib_set_long(hand, productDefinitionTemplateNumber_, productDefinitionTemplateNumberNew); + /*if (derivedForecast>=0) grib_set_long(hand, derivedForecast_ ,derivedForecast);*/ } return 0; } -int grib_accessor_class_g2_chemical_t::value_count(grib_accessor* a, long* count) +int grib_accessor_g2_chemical_t::value_count(long* count) { *count = 1; return 0; diff --git a/src/accessor/grib_accessor_class_g2_chemical.h b/src/accessor/grib_accessor_class_g2_chemical.h index 66bf945aa..68d7ece7c 100644 --- a/src/accessor/grib_accessor_class_g2_chemical.h +++ b/src/accessor/grib_accessor_class_g2_chemical.h @@ -16,19 +16,16 @@ class grib_accessor_g2_chemical_t : public grib_accessor_unsigned_t { public: - /* Members defined in g2_chemical */ - const char* productDefinitionTemplateNumber; - const char* stepType; - int chemical_type; -}; - -class grib_accessor_class_g2_chemical_t : public grib_accessor_class_unsigned_t -{ -public: - grib_accessor_class_g2_chemical_t(const char* name) : grib_accessor_class_unsigned_t(name) {} + grib_accessor_g2_chemical_t() : + grib_accessor_unsigned_t() { class_name_ = "g2_chemical"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g2_chemical_t{}; } - int pack_long(grib_accessor*, const long* val, size_t* len) override; - 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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* productDefinitionTemplateNumber_; + const char* stepType_; + int chemical_type_; }; diff --git a/src/accessor/grib_accessor_class_g2_eps.cc b/src/accessor/grib_accessor_class_g2_eps.cc index 9a8199053..a9f49a60a 100644 --- a/src/accessor/grib_accessor_class_g2_eps.cc +++ b/src/accessor/grib_accessor_class_g2_eps.cc @@ -11,31 +11,28 @@ #include "grib_accessor_class_g2_eps.h" -grib_accessor_class_g2_eps_t _grib_accessor_class_g2_eps{ "g2_eps" }; -grib_accessor_class* grib_accessor_class_g2_eps = &_grib_accessor_class_g2_eps; +grib_accessor_g2_eps_t _grib_accessor_g2_eps{}; +grib_accessor* grib_accessor_g2_eps = &_grib_accessor_g2_eps; - -void grib_accessor_class_g2_eps_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g2_eps_t::init(const long l, grib_arguments* c) { - grib_accessor_class_unsigned_t::init(a, l, c); - grib_accessor_g2_eps_t* self = (grib_accessor_g2_eps_t*)a; - int n = 0; + grib_accessor_unsigned_t::init(l, c); + int n = 0; - self->productDefinitionTemplateNumber = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->type = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->stream = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->stepType = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->derivedForecast = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + productDefinitionTemplateNumber_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + type_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + stream_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + stepType_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + derivedForecast_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); } -int grib_accessor_class_g2_eps_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g2_eps_t::unpack_long(long* val, size_t* len) { - grib_accessor_g2_eps_t* self = (grib_accessor_g2_eps_t*)a; long productDefinitionTemplateNumber = 0; int err = 0; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); - err = grib_get_long(hand, self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber); + err = grib_get_long(hand, productDefinitionTemplateNumber_, &productDefinitionTemplateNumber); if (err) return err; *val = 0; @@ -48,35 +45,35 @@ int grib_accessor_class_g2_eps_t::unpack_long(grib_accessor* a, long* val, size_ return GRIB_SUCCESS; } -int grib_accessor_class_g2_eps_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_g2_eps_t::pack_long(const long* val, size_t* len) { - grib_accessor_g2_eps_t* self = (grib_accessor_g2_eps_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - + grib_handle* hand = grib_handle_of_accessor(this); long productDefinitionTemplateNumber = -1; long productDefinitionTemplateNumberNew = -1; long type = -1; long stream = -1; long chemical = -1; long aerosol = -1; - char stepType[15] = {0,}; + char stepType[15] = { + 0, + }; size_t slen = 15; int eps = *val; int isInstant = 0; long derivedForecast = -1; - if (grib_get_long(hand, self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber) != GRIB_SUCCESS) + if (grib_get_long(hand, productDefinitionTemplateNumber_, &productDefinitionTemplateNumber) != GRIB_SUCCESS) return GRIB_SUCCESS; - grib_get_long(hand, self->type, &type); - grib_get_long(hand, self->stream, &stream); - grib_get_string(hand, self->stepType, stepType, &slen); + grib_get_long(hand, type_, &type); + grib_get_long(hand, stream_, &stream); + grib_get_string(hand, stepType_, stepType, &slen); if (!strcmp(stepType, "instant")) isInstant = 1; grib_get_long(hand, "is_chemical", &chemical); grib_get_long(hand, "is_aerosol", &aerosol); if (chemical == 1 && aerosol == 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Parameter cannot be both chemical and aerosol!"); + grib_context_log(context_, GRIB_LOG_ERROR, "Parameter cannot be both chemical and aerosol!"); return GRIB_ENCODING_ERROR; } @@ -93,7 +90,7 @@ int grib_accessor_class_g2_eps_t::pack_long(grib_accessor* a, const long* val, s derivedForecast = 4; } else { - //productDefinitionTemplateNumberNew = 1; + // productDefinitionTemplateNumberNew = 1; productDefinitionTemplateNumberNew = grib2_choose_PDTN(productDefinitionTemplateNumber, false, isInstant); } } @@ -123,16 +120,16 @@ int grib_accessor_class_g2_eps_t::pack_long(grib_accessor* a, const long* val, s // } } - if (productDefinitionTemplateNumberNew >=0 && productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) { - grib_set_long(hand, self->productDefinitionTemplateNumber, productDefinitionTemplateNumberNew); + if (productDefinitionTemplateNumberNew >= 0 && productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) { + grib_set_long(hand, productDefinitionTemplateNumber_, productDefinitionTemplateNumberNew); if (derivedForecast >= 0) - grib_set_long(hand, self->derivedForecast, derivedForecast); + grib_set_long(hand, derivedForecast_, derivedForecast); } return 0; } -int grib_accessor_class_g2_eps_t::value_count(grib_accessor* a, long* count) +int grib_accessor_g2_eps_t::value_count(long* count) { *count = 1; return 0; diff --git a/src/accessor/grib_accessor_class_g2_eps.h b/src/accessor/grib_accessor_class_g2_eps.h index 8453387fa..a4bfb818b 100644 --- a/src/accessor/grib_accessor_class_g2_eps.h +++ b/src/accessor/grib_accessor_class_g2_eps.h @@ -16,21 +16,18 @@ class grib_accessor_g2_eps_t : public grib_accessor_unsigned_t { public: - /* Members defined in g2_eps */ - const char* productDefinitionTemplateNumber; - const char* stream; - const char* type; - const char* stepType; - const char* derivedForecast; -}; - -class grib_accessor_class_g2_eps_t : public grib_accessor_class_unsigned_t -{ -public: - grib_accessor_class_g2_eps_t(const char* name) : grib_accessor_class_unsigned_t(name) {} + grib_accessor_g2_eps_t() : + grib_accessor_unsigned_t() { class_name_ = "g2_eps"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g2_eps_t{}; } - int pack_long(grib_accessor*, const long* val, size_t* len) override; - 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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* productDefinitionTemplateNumber_; + const char* stream_; + const char* type_; + const char* stepType_; + const char* derivedForecast_; }; diff --git a/src/accessor/grib_accessor_class_g2_mars_labeling.cc b/src/accessor/grib_accessor_class_g2_mars_labeling.cc index 5e2e73f64..8e8ffa131 100644 --- a/src/accessor/grib_accessor_class_g2_mars_labeling.cc +++ b/src/accessor/grib_accessor_class_g2_mars_labeling.cc @@ -10,83 +10,81 @@ #include "grib_accessor_class_g2_mars_labeling.h" -grib_accessor_class_g2_mars_labeling_t _grib_accessor_class_g2_mars_labeling{ "g2_mars_labeling" }; -grib_accessor_class* grib_accessor_class_g2_mars_labeling = &_grib_accessor_class_g2_mars_labeling; +grib_accessor_g2_mars_labeling_t _grib_accessor_g2_mars_labeling{}; +grib_accessor* grib_accessor_g2_mars_labeling = &_grib_accessor_g2_mars_labeling; - -void grib_accessor_class_g2_mars_labeling_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g2_mars_labeling_t::init(const long l, grib_arguments* c) { - grib_accessor_class_gen_t::init(a, l, c); - grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; - int n = 0; - grib_handle* hand = grib_handle_of_accessor(a); + grib_accessor_gen_t::init(l, c); + int n = 0; + grib_handle* hand = grib_handle_of_accessor(this); - self->index = grib_arguments_get_long(hand, c, n++); - self->the_class = grib_arguments_get_name(hand, c, n++); - self->type = grib_arguments_get_name(hand, c, n++); - self->stream = grib_arguments_get_name(hand, c, n++); - self->expver = grib_arguments_get_name(hand, c, n++); - self->typeOfProcessedData = grib_arguments_get_name(hand, c, n++); - self->productDefinitionTemplateNumber = grib_arguments_get_name(hand, c, n++); - self->stepType = grib_arguments_get_name(hand, c, n++); - self->derivedForecast = grib_arguments_get_name(hand, c, n++); - self->typeOfGeneratingProcess = grib_arguments_get_name(hand, c, n++); + index_ = grib_arguments_get_long(hand, c, n++); + the_class_ = grib_arguments_get_name(hand, c, n++); + type_ = grib_arguments_get_name(hand, c, n++); + stream_ = grib_arguments_get_name(hand, c, n++); + expver_ = grib_arguments_get_name(hand, c, n++); + typeOfProcessedData_ = grib_arguments_get_name(hand, c, n++); + productDefinitionTemplateNumber_ = grib_arguments_get_name(hand, c, n++); + stepType_ = grib_arguments_get_name(hand, c, n++); + derivedForecast_ = grib_arguments_get_name(hand, c, n++); + typeOfGeneratingProcess_ = grib_arguments_get_name(hand, c, n++); } -int grib_accessor_class_g2_mars_labeling_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g2_mars_labeling_t::unpack_long(long* val, size_t* len) { - grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; - char* key = NULL; - - switch (self->index) { - case 0: - key = (char*)self->the_class; - break; - case 1: - key = (char*)self->type; - break; - case 2: - key = (char*)self->stream; - break; - default: - grib_context_log(a->context, GRIB_LOG_ERROR, - "invalid first argument of g2_mars_labeling in %s", a->name); - return GRIB_INTERNAL_ERROR; - } - - return grib_get_long(grib_handle_of_accessor(a), key, val); -} - -int grib_accessor_class_g2_mars_labeling_t::unpack_string(grib_accessor* a, char* val, size_t* len) -{ - grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; char* key = NULL; - switch (self->index) { + switch (index_) { case 0: - key = (char*)self->the_class; + key = (char*)the_class_; break; case 1: - key = (char*)self->type; + key = (char*)type_; break; case 2: - key = (char*)self->stream; + key = (char*)stream_; break; default: - grib_context_log(a->context, GRIB_LOG_ERROR, - "invalid first argument of g2_mars_labeling in %s", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, + "invalid first argument of g2_mars_labeling in %s", name_); return GRIB_INTERNAL_ERROR; } - return grib_get_string(grib_handle_of_accessor(a), key, val, len); + return grib_get_long(grib_handle_of_accessor(this), key, val); +} + +int grib_accessor_g2_mars_labeling_t::unpack_string(char* val, size_t* len) +{ + char* key = NULL; + + switch (index_) { + case 0: + key = (char*)the_class_; + break; + case 1: + key = (char*)type_; + break; + case 2: + key = (char*)stream_; + break; + default: + grib_context_log(context_, GRIB_LOG_ERROR, + "invalid first argument of g2_mars_labeling in %s", name_); + return GRIB_INTERNAL_ERROR; + } + + return grib_get_string(grib_handle_of_accessor(this), key, val, len); } static int extra_set(grib_accessor* a, long val) { - int ret = 0; grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; + int ret = 0; grib_handle* hand = grib_handle_of_accessor(a); - char stepType[30] = {0,}; + char stepType[30] = { + 0, + }; size_t stepTypelen = 30; long derivedForecast = -1; long productDefinitionTemplateNumberNew = -1; @@ -110,7 +108,7 @@ static int extra_set(grib_accessor* a, long val) const int is_wave = grib_is_defined(hand, "waveDirectionNumber"); const int is_wave_prange = grib_is_defined(hand, "typeOfWavePeriodInterval"); - switch (self->index) { + switch (self->index_) { case 0: /* class */ return ret; @@ -164,7 +162,7 @@ static int extra_set(grib_accessor* a, long val) break; case 17: /* Ensemble mean (em) */ derivedForecast = 0; - grib_get_string(hand, self->stepType, stepType, &stepTypelen); + grib_get_string(hand, self->stepType_, stepType, &stepTypelen); if (!strcmp(stepType, "instant")) { productDefinitionTemplateNumberNew = 2; } @@ -176,7 +174,7 @@ static int extra_set(grib_accessor* a, long val) break; case 18: /* Ensemble standard deviation (es) */ derivedForecast = 4; - grib_get_string(hand, self->stepType, stepType, &stepTypelen); + grib_get_string(hand, self->stepType_, stepType, &stepTypelen); if (!strcmp(stepType, "instant")) { productDefinitionTemplateNumberNew = 2; } @@ -260,7 +258,7 @@ static int extra_set(grib_accessor* a, long val) typeOfGeneratingProcess = 255; break; default: - grib_context_log(a->context, GRIB_LOG_WARNING, "g2_mars_labeling: unknown mars.type %d", (int)val); + grib_context_log(a->context_, GRIB_LOG_WARNING, "g2_mars_labeling: unknown mars.type %d", (int)val); /*return GRIB_ENCODING_ERROR;*/ } break; @@ -271,7 +269,7 @@ static int extra_set(grib_accessor* a, long val) case 1249: /* elda */ case 1250: /* ewla */ is_eps = 1; /* These streams are all for ensembles */ - grib_get_string(hand, self->stepType, stepType, &stepTypelen); + grib_get_string(hand, self->stepType_, stepType, &stepTypelen); is_instant = (strcmp(stepType, "instant") == 0); productDefinitionTemplateNumberNew = grib2_select_PDTN( is_eps, is_instant, @@ -284,8 +282,8 @@ static int extra_set(grib_accessor* a, long val) } break; default: - grib_context_log(a->context, GRIB_LOG_ERROR, - "invalid first argument of g2_mars_labeling in %s", a->name); + grib_context_log(a->context_, GRIB_LOG_ERROR, + "invalid first argument of g2_mars_labeling in %s", a->name_); return GRIB_INTERNAL_ERROR; } @@ -295,118 +293,115 @@ static int extra_set(grib_accessor* a, long val) } if (productDefinitionTemplateNumberNew >= 0) { - grib_get_long(hand, self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber); + grib_get_long(hand, self->productDefinitionTemplateNumber_, &productDefinitionTemplateNumber); if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) - grib_set_long(hand, self->productDefinitionTemplateNumber, productDefinitionTemplateNumberNew); + grib_set_long(hand, self->productDefinitionTemplateNumber_, productDefinitionTemplateNumberNew); } if (derivedForecast >= 0) { - grib_set_long(hand, self->derivedForecast, derivedForecast); + grib_set_long(hand, self->derivedForecast_, derivedForecast); } if (typeOfProcessedData > 0) - grib_set_long(hand, self->typeOfProcessedData, typeOfProcessedData); + grib_set_long(hand, self->typeOfProcessedData_, typeOfProcessedData); if (typeOfGeneratingProcess > 0) - grib_set_long(hand, self->typeOfGeneratingProcess, typeOfGeneratingProcess); + grib_set_long(hand, self->typeOfGeneratingProcess_, typeOfGeneratingProcess); return ret; } -int grib_accessor_class_g2_mars_labeling_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_g2_mars_labeling_t::pack_string(const char* val, size_t* len) { - grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; char* key = NULL; int ret = 0; long lval = 0; - switch (self->index) { + switch (index_) { case 0: - key = (char*)self->the_class; + key = (char*)the_class_; break; case 1: - key = (char*)self->type; + key = (char*)type_; break; case 2: - key = (char*)self->stream; + key = (char*)stream_; break; default: - grib_context_log(a->context, GRIB_LOG_ERROR, - "invalid first argument of g2_mars_labeling in %s", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, + "invalid first argument of g2_mars_labeling in %s", name_); return GRIB_INTERNAL_ERROR; } - ret = grib_set_string(grib_handle_of_accessor(a), key, val, len); + ret = grib_set_string(grib_handle_of_accessor(this), key, val, len); if (ret) return ret; /* failed */ - ret = grib_get_long(grib_handle_of_accessor(a), key, &lval); + ret = grib_get_long(grib_handle_of_accessor(this), key, &lval); if (ret) return ret; /* failed */ - return extra_set(a, lval); + return extra_set(this, lval); } -int grib_accessor_class_g2_mars_labeling_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_g2_mars_labeling_t::pack_long(const long* val, size_t* len) { - grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; char* key = NULL; int ret = 0; - switch (self->index) { + switch (index_) { case 0: - key = (char*)self->the_class; + key = (char*)the_class_; break; case 1: - key = (char*)self->type; + key = (char*)type_; break; case 2: - key = (char*)self->stream; + key = (char*)stream_; break; default: - grib_context_log(a->context, GRIB_LOG_ERROR, - "invalid first argument of g2_mars_labeling in %s", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, + "invalid first argument of g2_mars_labeling in %s", name_); return GRIB_INTERNAL_ERROR; } - ret = grib_set_long(grib_handle_of_accessor(a), key, *val); + ret = grib_set_long(grib_handle_of_accessor(this), key, *val); if (ret) return ret; /* failed */ - return extra_set(a, *val); + return extra_set(this, *val); } -int grib_accessor_class_g2_mars_labeling_t::value_count(grib_accessor* a, long* count) +int grib_accessor_g2_mars_labeling_t::value_count(long* count) { *count = 1; return 0; } -int grib_accessor_class_g2_mars_labeling_t::get_native_type(grib_accessor* a) +long grib_accessor_g2_mars_labeling_t::get_native_type() { - grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; char* key = NULL; int ret = 0; int type = 0; - switch (self->index) { + switch (index_) { case 0: - key = (char*)self->the_class; + key = (char*)the_class_; break; case 1: - key = (char*)self->type; + key = (char*)type_; break; case 2: - key = (char*)self->stream; + key = (char*)stream_; break; default: - grib_context_log(a->context, GRIB_LOG_ERROR, - "invalid first argument of g2_mars_labeling in %s", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, + "invalid first argument of g2_mars_labeling in %s", name_); return GRIB_INTERNAL_ERROR; } - ret = grib_get_native_type(grib_handle_of_accessor(a), key, &type); + ret = grib_get_native_type(grib_handle_of_accessor(this), key, &type); if (ret) - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "unable to get native type for %s", key); return type; } diff --git a/src/accessor/grib_accessor_class_g2_mars_labeling.h b/src/accessor/grib_accessor_class_g2_mars_labeling.h index d47848565..fa9e816e5 100644 --- a/src/accessor/grib_accessor_class_g2_mars_labeling.h +++ b/src/accessor/grib_accessor_class_g2_mars_labeling.h @@ -16,29 +16,26 @@ class grib_accessor_g2_mars_labeling_t : public grib_accessor_gen_t { public: - /* Members defined in g2_mars_labeling */ - int index; - const char* the_class; - const char* stream; - const char* type; - const char* expver; - const char* typeOfProcessedData; - const char* productDefinitionTemplateNumber; - const char* stepType; - const char* derivedForecast; - const char* typeOfGeneratingProcess; -}; - -class grib_accessor_class_g2_mars_labeling_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_g2_mars_labeling_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_g2_mars_labeling_t() : + grib_accessor_gen_t() { class_name_ = "g2_mars_labeling"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g2_mars_labeling_t{}; } - int get_native_type(grib_accessor*) 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_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; + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + int pack_string(const char*, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +public: + int index_; + const char* the_class_; + const char* stream_; + const char* type_; + const char* expver_; + const char* typeOfProcessedData_; + const char* productDefinitionTemplateNumber_; + const char* stepType_; + const char* derivedForecast_; + const char* typeOfGeneratingProcess_; }; diff --git a/src/accessor/grib_accessor_class_g2bitmap.cc b/src/accessor/grib_accessor_class_g2bitmap.cc index 7b1783d9a..ed5a8d773 100644 --- a/src/accessor/grib_accessor_class_g2bitmap.cc +++ b/src/accessor/grib_accessor_class_g2bitmap.cc @@ -11,16 +11,14 @@ #include "grib_accessor_class_g2bitmap.h" -grib_accessor_class_g2bitmap_t _grib_accessor_class_g2bitmap{ "g2bitmap" }; -grib_accessor_class* grib_accessor_class_g2bitmap = &_grib_accessor_class_g2bitmap; +grib_accessor_g2bitmap_t _grib_accessor_g2bitmap{}; +grib_accessor* grib_accessor_g2bitmap = &_grib_accessor_g2bitmap; - -void grib_accessor_class_g2bitmap_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_g2bitmap_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_bitmap_t::init(a, len, arg); - grib_accessor_g2bitmap_t* self = (grib_accessor_g2bitmap_t*)a; + grib_accessor_bitmap_t::init(len, arg); - self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 4); + numberOfValues_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, 4); } // For speed use a local static function @@ -31,22 +29,20 @@ static GRIB_INLINE void set_bit_on(unsigned char* p, long* bitp) (*bitp)++; } -int grib_accessor_class_g2bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_g2bitmap_t::pack_double(const double* val, size_t* len) { - grib_accessor_g2bitmap_t* self = (grib_accessor_g2bitmap_t*)a; - unsigned char* buf = NULL; size_t i; int err = 0; long pos = 0; // long bmaplen = 0; double miss_values = 0; - size_t tlen = (*len + 7) / 8; + size_t tlen = (*len + 7) / 8; - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value, &miss_values)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(grib_handle_of_accessor(this), missing_value_, &miss_values)) != GRIB_SUCCESS) return err; - buf = (unsigned char*)grib_context_malloc_clear(a->context, tlen); + buf = (unsigned char*)grib_context_malloc_clear(context_, tlen); if (!buf) return GRIB_OUT_OF_MEMORY; pos = 0; @@ -59,25 +55,23 @@ int grib_accessor_class_g2bitmap_t::pack_double(grib_accessor* a, const double* } } - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->numberOfValues, *len)) != GRIB_SUCCESS) { - grib_context_free(a->context, buf); + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), numberOfValues_, *len)) != GRIB_SUCCESS) { + grib_context_free(context_, buf); return err; } - grib_buffer_replace(a, buf, tlen, 1, 1); + grib_buffer_replace(this, buf, tlen, 1, 1); - grib_context_free(a->context, buf); + grib_context_free(context_, buf); return GRIB_SUCCESS; } - -int grib_accessor_class_g2bitmap_t::value_count(grib_accessor* a, long* tlen) +int grib_accessor_g2bitmap_t::value_count(long* tlen) { - grib_accessor_g2bitmap_t* self = (grib_accessor_g2bitmap_t*)a; int err; *tlen = 0; - err = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfValues, tlen); + err = grib_get_long_internal(grib_handle_of_accessor(this), numberOfValues_, tlen); return err; } diff --git a/src/accessor/grib_accessor_class_g2bitmap.h b/src/accessor/grib_accessor_class_g2bitmap.h index 2276b702c..c305fb494 100644 --- a/src/accessor/grib_accessor_class_g2bitmap.h +++ b/src/accessor/grib_accessor_class_g2bitmap.h @@ -16,16 +16,13 @@ class grib_accessor_g2bitmap_t : public grib_accessor_bitmap_t { public: - /* Members defined in g2bitmap */ - const char* numberOfValues; -}; - -class grib_accessor_class_g2bitmap_t : public grib_accessor_class_bitmap_t -{ -public: - grib_accessor_class_g2bitmap_t(const char* name) : grib_accessor_class_bitmap_t(name) {} + grib_accessor_g2bitmap_t() : + grib_accessor_bitmap_t() { class_name_ = "g2bitmap"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g2bitmap_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; + int pack_double(const double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* numberOfValues_; }; diff --git a/src/accessor/grib_accessor_class_g2bitmap_present.cc b/src/accessor/grib_accessor_class_g2bitmap_present.cc index 3ba7f6c99..385c70ec8 100644 --- a/src/accessor/grib_accessor_class_g2bitmap_present.cc +++ b/src/accessor/grib_accessor_class_g2bitmap_present.cc @@ -11,28 +11,24 @@ #include "grib_accessor_class_g2bitmap_present.h" -grib_accessor_class_g2bitmap_present_t _grib_accessor_class_g2bitmap_present{ "g2bitmap_present" }; -grib_accessor_class* grib_accessor_class_g2bitmap_present = &_grib_accessor_class_g2bitmap_present; +grib_accessor_g2bitmap_present_t _grib_accessor_g2bitmap_present{}; +grib_accessor* grib_accessor_g2bitmap_present = &_grib_accessor_g2bitmap_present; - -void grib_accessor_class_g2bitmap_present_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g2bitmap_present_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - int n = 0; - grib_accessor_g2bitmap_present_t* self = (grib_accessor_g2bitmap_present_t*)a; - self->bitmapIndicator = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + grib_accessor_long_t::init(l, c); + int n = 0; + bitmapIndicator_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - a->length = 0; + length_ = 0; } -int grib_accessor_class_g2bitmap_present_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g2bitmap_present_t::unpack_long(long* val, size_t* len) { int ret = GRIB_SUCCESS; long bitmapIndicator = 0; - grib_accessor_g2bitmap_present_t* self = (grib_accessor_g2bitmap_present_t*)a; - - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bitmapIndicator, &bitmapIndicator); + ret = grib_get_long_internal(grib_handle_of_accessor(this), bitmapIndicator_, &bitmapIndicator); if (ret) { if (ret == GRIB_NOT_FOUND) { *val = 0; @@ -50,13 +46,12 @@ int grib_accessor_class_g2bitmap_present_t::unpack_long(grib_accessor* a, long* return ret; } -int grib_accessor_class_g2bitmap_present_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_g2bitmap_present_t::pack_long(const long* val, size_t* len) { - grib_accessor_g2bitmap_present_t* self = (grib_accessor_g2bitmap_present_t*)a; - long bitmapIndicator = 0; + long bitmapIndicator = 0; if (*val == 0) bitmapIndicator = 255; - return grib_set_long(grib_handle_of_accessor(a), self->bitmapIndicator, bitmapIndicator); + return grib_set_long(grib_handle_of_accessor(this), bitmapIndicator_, bitmapIndicator); } diff --git a/src/accessor/grib_accessor_class_g2bitmap_present.h b/src/accessor/grib_accessor_class_g2bitmap_present.h index 87d603f54..a70765c35 100644 --- a/src/accessor/grib_accessor_class_g2bitmap_present.h +++ b/src/accessor/grib_accessor_class_g2bitmap_present.h @@ -16,16 +16,13 @@ class grib_accessor_g2bitmap_present_t : public grib_accessor_long_t { public: - /* Members defined in g2bitmap_present */ - const char* bitmapIndicator; -}; - -class grib_accessor_class_g2bitmap_present_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_g2bitmap_present_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_g2bitmap_present_t() : + grib_accessor_long_t() { class_name_ = "g2bitmap_present"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g2bitmap_present_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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* bitmapIndicator_; }; diff --git a/src/accessor/grib_accessor_class_g2date.cc b/src/accessor/grib_accessor_class_g2date.cc index 827df44df..23b2e99cd 100644 --- a/src/accessor/grib_accessor_class_g2date.cc +++ b/src/accessor/grib_accessor_class_g2date.cc @@ -11,34 +11,31 @@ #include "grib_accessor_class_g2date.h" -grib_accessor_class_g2date_t _grib_accessor_class_g2date{ "g2date" }; -grib_accessor_class* grib_accessor_class_g2date = &_grib_accessor_class_g2date; +grib_accessor_g2date_t _grib_accessor_g2date{}; +grib_accessor* grib_accessor_g2date = &_grib_accessor_g2date; -void grib_accessor_class_g2date_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g2date_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_g2date_t* self = (grib_accessor_g2date_t*)a; + grib_accessor_long_t::init(l, c); 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++); + year_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + month_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + day_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); } -int grib_accessor_class_g2date_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g2date_t::unpack_long(long* val, size_t* len) { - const grib_accessor_g2date_t* self = (grib_accessor_g2date_t*)a; - int ret = 0; 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) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), day_, &day)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->month, &month)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), month_, &month)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->year, &year)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), year_, &year)) != GRIB_SUCCESS) return ret; if (*len < 1) @@ -49,10 +46,8 @@ int grib_accessor_class_g2date_t::unpack_long(grib_accessor* a, long* val, size_ return GRIB_SUCCESS; } -int grib_accessor_class_g2date_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_g2date_t::pack_long(const long* val, size_t* len) { - const grib_accessor_g2date_t* self = (grib_accessor_g2date_t*)a; - int ret = GRIB_SUCCESS; long v = val[0]; long year = 0; @@ -71,14 +66,14 @@ int grib_accessor_class_g2date_t::pack_long(grib_accessor* a, const long* val, s if (!is_date_valid(year, month, day, 0, 0, 0)) { // ECC-1777: For now just a warning. Will later change to an error fprintf(stderr, "ECCODES WARNING : %s:%s: Date is not valid! year=%ld month=%ld day=%ld\n", - a->cclass->name, __func__, year, month, day); + class_name_, __func__, year, month, day); } - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->day, day)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), day_, day)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->month, month)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), month_, month)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->year, year)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), year_, year)) != GRIB_SUCCESS) return ret; return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_g2date.h b/src/accessor/grib_accessor_class_g2date.h index e6981665c..2ebf738ed 100644 --- a/src/accessor/grib_accessor_class_g2date.h +++ b/src/accessor/grib_accessor_class_g2date.h @@ -16,19 +16,16 @@ class grib_accessor_g2date_t : public grib_accessor_long_t { public: - /* Members defined in g2date */ - const char* century; - const char* year; - const char* month; - const char* day; -}; - -class grib_accessor_class_g2date_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_g2date_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_g2date_t() : + grib_accessor_long_t() { class_name_ = "g2date"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g2date_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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* century_; + const char* year_; + const char* month_; + const char* day_; }; diff --git a/src/accessor/grib_accessor_class_g2end_step.cc b/src/accessor/grib_accessor_class_g2end_step.cc index b4a3a2a25..36cd03f5b 100644 --- a/src/accessor/grib_accessor_class_g2end_step.cc +++ b/src/accessor/grib_accessor_class_g2end_step.cc @@ -14,51 +14,53 @@ #include "step_utilities.h" #include -grib_accessor_class_g2end_step_t _grib_accessor_class_g2end_step{ "g2end_step" }; -grib_accessor_class* grib_accessor_class_g2end_step = &_grib_accessor_class_g2end_step; +grib_accessor_g2end_step_t _grib_accessor_g2end_step{}; +grib_accessor* grib_accessor_g2end_step = &_grib_accessor_g2end_step; - -void grib_accessor_class_g2end_step_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g2end_step_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - int n = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_long_t::init(l, c); + int n = 0; + grib_handle* h = grib_handle_of_accessor(this); - self->start_step_value = grib_arguments_get_name(h, c, n++); - self->step_units = grib_arguments_get_name(h, c, n++); + start_step_value_ = grib_arguments_get_name(h, c, n++); + step_units_ = grib_arguments_get_name(h, c, n++); - self->year = grib_arguments_get_name(h, c, n++); - self->month = grib_arguments_get_name(h, c, n++); - self->day = grib_arguments_get_name(h, c, n++); - self->hour = grib_arguments_get_name(h, c, n++); - self->minute = grib_arguments_get_name(h, c, n++); - self->second = grib_arguments_get_name(h, c, n++); + year_ = grib_arguments_get_name(h, c, n++); + month_ = grib_arguments_get_name(h, c, n++); + day_ = grib_arguments_get_name(h, c, n++); + hour_ = grib_arguments_get_name(h, c, n++); + minute_ = grib_arguments_get_name(h, c, n++); + second_ = grib_arguments_get_name(h, c, n++); - self->year_of_end_of_interval = grib_arguments_get_name(h, c, n++); - self->month_of_end_of_interval = grib_arguments_get_name(h, c, n++); - self->day_of_end_of_interval = grib_arguments_get_name(h, c, n++); - self->hour_of_end_of_interval = grib_arguments_get_name(h, c, n++); - self->minute_of_end_of_interval = grib_arguments_get_name(h, c, n++); - self->second_of_end_of_interval = grib_arguments_get_name(h, c, n++); + year_of_end_of_interval_ = grib_arguments_get_name(h, c, n++); + month_of_end_of_interval_ = grib_arguments_get_name(h, c, n++); + day_of_end_of_interval_ = grib_arguments_get_name(h, c, n++); + hour_of_end_of_interval_ = grib_arguments_get_name(h, c, n++); + minute_of_end_of_interval_ = grib_arguments_get_name(h, c, n++); + second_of_end_of_interval_ = grib_arguments_get_name(h, c, n++); - self->time_range_unit = grib_arguments_get_name(h, c, n++); - self->time_range_value = grib_arguments_get_name(h, c, n++); - self->typeOfTimeIncrement = grib_arguments_get_name(h, c, n++); - self->numberOfTimeRanges = grib_arguments_get_name(h, c, n++); + time_range_unit_ = grib_arguments_get_name(h, c, n++); + time_range_value_ = grib_arguments_get_name(h, c, n++); + typeOfTimeIncrement_ = grib_arguments_get_name(h, c, n++); + numberOfTimeRanges_ = grib_arguments_get_name(h, c, n++); } -void grib_accessor_class_g2end_step_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_g2end_step_t::dump(grib_dumper* dumper) { - grib_dump_double(dumper, a, NULL); + grib_dump_double(dumper, this, NULL); } // See GRIB-488 bool is_special_expver(const grib_handle* h) { int ret = 0; - char strMarsExpVer[50] = {0,}; - char strMarsClass[50] = {0,}; + char strMarsExpVer[50] = { + 0, + }; + char strMarsClass[50] = { + 0, + }; size_t slen = 50; ret = grib_get_string(h, "mars.class", strMarsClass, &slen); if (ret == GRIB_SUCCESS && STR_EQUAL(strMarsClass, "em")) { @@ -97,7 +99,8 @@ static int convert_time_range_long_( static int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len) { grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - int err = 0; + + int err = 0; long start_step_value; long step_units; long time_range_unit; @@ -106,15 +109,15 @@ static int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len) grib_handle* h = grib_handle_of_accessor(a); - if ((err = grib_get_long_internal(h, self->start_step_value, &start_step_value))) + if ((err = grib_get_long_internal(h, self->start_step_value_, &start_step_value))) return err; - if ((err = grib_get_long_internal(h, self->step_units, &step_units))) + if ((err = grib_get_long_internal(h, self->step_units_, &step_units))) return err; - if ((err = grib_get_long_internal(h, self->time_range_unit, &time_range_unit))) + if ((err = grib_get_long_internal(h, self->time_range_unit_, &time_range_unit))) return err; - if ((err = grib_get_long_internal(h, self->time_range_value, &time_range_value))) + if ((err = grib_get_long_internal(h, self->time_range_value_, &time_range_value))) return err; - if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement, &typeOfTimeIncrement))) + if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement_, &typeOfTimeIncrement))) return err; err = convert_time_range_long_(h, step_units, time_range_unit, &time_range_value); @@ -157,17 +160,17 @@ static int unpack_one_time_range_double_(grib_accessor* a, double* val, size_t* grib_handle* h = grib_handle_of_accessor(a); - if ((err = grib_get_double_internal(h, self->start_step_value, &start_step_value))) + if ((err = grib_get_double_internal(h, self->start_step_value_, &start_step_value))) return err; if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit))) return err; - if ((err = grib_get_long_internal(h, self->step_units, &step_units))) + if ((err = grib_get_long_internal(h, self->step_units_, &step_units))) return err; - if ((err = grib_get_long_internal(h, self->time_range_unit, &time_range_unit))) + if ((err = grib_get_long_internal(h, self->time_range_unit_, &time_range_unit))) return err; - if ((err = grib_get_double_internal(h, self->time_range_value, &time_range_value))) + if ((err = grib_get_double_internal(h, self->time_range_value_, &time_range_value))) return err; - if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement, &typeOfTimeIncrement))) + if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement_, &typeOfTimeIncrement))) return err; eccodes::Step start_step{ start_step_value, start_step_unit }; @@ -200,7 +203,7 @@ static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t { grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; int i = 0, err = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(a); long numberOfTimeRanges = 0, step_units = 0, start_step_value = 0; size_t count = 0; @@ -214,11 +217,11 @@ static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t 0, }; - if ((err = grib_get_long_internal(h, self->start_step_value, &start_step_value))) + if ((err = grib_get_long_internal(h, self->start_step_value_, &start_step_value))) return err; - if ((err = grib_get_long_internal(h, self->step_units, &step_units))) + if ((err = grib_get_long_internal(h, self->step_units_, &step_units))) return err; - if ((err = grib_get_long_internal(h, self->numberOfTimeRanges, &numberOfTimeRanges))) + if ((err = grib_get_long_internal(h, self->numberOfTimeRanges_, &numberOfTimeRanges))) return err; if (numberOfTimeRanges > MAX_NUM_TIME_RANGES) { grib_context_log(h->context, GRIB_LOG_ERROR, "Too many time range specifications!"); @@ -227,11 +230,11 @@ static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t count = numberOfTimeRanges; /* Get the arrays for the N time ranges */ - if ((err = grib_get_long_array(h, self->typeOfTimeIncrement, arr_typeOfTimeIncrement, &count))) + if ((err = grib_get_long_array(h, self->typeOfTimeIncrement_, arr_typeOfTimeIncrement, &count))) return err; - if ((err = grib_get_long_array(h, self->time_range_unit, arr_coded_unit, &count))) + if ((err = grib_get_long_array(h, self->time_range_unit_, arr_coded_unit, &count))) return err; - if ((err = grib_get_long_array(h, self->time_range_value, arr_coded_time_range, &count))) + if ((err = grib_get_long_array(h, self->time_range_value_, arr_coded_time_range, &count))) return err; /* Look in the array of typeOfTimeIncrements for first entry whose typeOfTimeIncrement == 2 */ @@ -276,17 +279,17 @@ static int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, si 0, }; - if ((err = grib_get_long_internal(h, self->start_step_value, &start_step_value))) + if ((err = grib_get_long_internal(h, self->start_step_value_, &start_step_value))) return err; if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit))) return err; eccodes::Step start_step{ start_step_value, start_step_unit }; - if ((err = grib_get_long_internal(h, self->step_units, &step_units))) + if ((err = grib_get_long_internal(h, self->step_units_, &step_units))) return err; - if ((err = grib_get_long_internal(h, self->numberOfTimeRanges, &numberOfTimeRanges))) + if ((err = grib_get_long_internal(h, self->numberOfTimeRanges_, &numberOfTimeRanges))) return err; if (numberOfTimeRanges > MAX_NUM_TIME_RANGES) { grib_context_log(h->context, GRIB_LOG_ERROR, "Too many time range specifications!"); @@ -295,11 +298,11 @@ static int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, si count = numberOfTimeRanges; /* Get the arrays for the N time ranges */ - if ((err = grib_get_long_array(h, self->typeOfTimeIncrement, arr_typeOfTimeIncrement, &count))) + if ((err = grib_get_long_array(h, self->typeOfTimeIncrement_, arr_typeOfTimeIncrement, &count))) return err; - if ((err = grib_get_long_array(h, self->time_range_unit, arr_coded_unit, &count))) + if ((err = grib_get_long_array(h, self->time_range_unit_, arr_coded_unit, &count))) return err; - if ((err = grib_get_long_array(h, self->time_range_value, arr_coded_time_range, &count))) + if ((err = grib_get_long_array(h, self->time_range_value_, arr_coded_time_range, &count))) return err; /* Look in the array of typeOfTimeIncrements for first entry whose typeOfTimeIncrement == 2 */ @@ -309,7 +312,7 @@ static int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, si long the_coded_unit = arr_coded_unit[i]; long the_coded_time_range = arr_coded_time_range[i]; - eccodes::Step time_range{the_coded_time_range, the_coded_unit}; + eccodes::Step time_range{ the_coded_time_range, the_coded_unit }; *val = (start_step + time_range).value(eccodes::Unit(step_units)); return GRIB_SUCCESS; @@ -322,41 +325,40 @@ static int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, si } // For the old implementation of unpack_long, see -// src/deprecated/grib_accessor_class_g2end_step.unpack_long.cc +// src/deprecated/grib_accessor_g2end_step.unpack_long.cc // -int grib_accessor_class_g2end_step_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g2end_step_t::unpack_long(long* val, size_t* len) { - grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; - long start_step_value = 0; - long start_step_unit = 0; + grib_handle* h = grib_handle_of_accessor(this); + int ret = 0; + long start_step_value = 0; + long start_step_unit = 0; long numberOfTimeRanges = 0; - if ((ret = grib_get_long_internal(h, self->start_step_value, &start_step_value))) + if ((ret = grib_get_long_internal(h, start_step_value_, &start_step_value))) return ret; if ((ret = grib_get_long_internal(h, "startStepUnit", &start_step_unit))) return ret; /* point in time */ - if (self->year == NULL) { + if (year_ == NULL) { *val = start_step_value; if ((ret = grib_set_long_internal(h, "endStepUnit", start_step_unit))) return ret; return 0; } - Assert(self->numberOfTimeRanges); - if ((ret = grib_get_long_internal(h, self->numberOfTimeRanges, &numberOfTimeRanges))) + Assert(numberOfTimeRanges_); + if ((ret = grib_get_long_internal(h, numberOfTimeRanges_, &numberOfTimeRanges))) return ret; Assert(numberOfTimeRanges == 1 || numberOfTimeRanges == 2); try { if (numberOfTimeRanges == 1) { - ret = unpack_one_time_range_long_(a, val, len); + ret = unpack_one_time_range_long_(this, val, len); } else { - ret = unpack_multiple_time_ranges_long_(a, val, len); + ret = unpack_multiple_time_ranges_long_(this, val, len); } } catch (std::exception& e) { @@ -367,39 +369,38 @@ int grib_accessor_class_g2end_step_t::unpack_long(grib_accessor* a, long* val, s return ret; } -int grib_accessor_class_g2end_step_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_g2end_step_t::unpack_double(double* val, size_t* len) { - grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; + grib_handle* h = grib_handle_of_accessor(this); + int ret = 0; long start_step_value; long start_step_unit; long numberOfTimeRanges; - if ((ret = grib_get_long_internal(h, self->start_step_value, &start_step_value))) + if ((ret = grib_get_long_internal(h, start_step_value_, &start_step_value))) return ret; if ((ret = grib_get_long_internal(h, "startStepUnit", &start_step_unit))) return ret; /* point in time */ - if (self->year == NULL) { + if (year_ == NULL) { *val = start_step_value; if ((ret = grib_set_long_internal(h, "endStepUnit", start_step_unit))) return ret; return 0; } - Assert(self->numberOfTimeRanges); - if ((ret = grib_get_long_internal(h, self->numberOfTimeRanges, &numberOfTimeRanges))) + Assert(numberOfTimeRanges_); + if ((ret = grib_get_long_internal(h, numberOfTimeRanges_, &numberOfTimeRanges))) return ret; Assert(numberOfTimeRanges == 1 || numberOfTimeRanges == 2); try { if (numberOfTimeRanges == 1) { - ret = unpack_one_time_range_double_(a, val, len); + ret = unpack_one_time_range_double_(this, val, len); } else { - ret = unpack_multiple_time_ranges_double_(a, val, len); + ret = unpack_multiple_time_ranges_double_(this, val, len); } } catch (std::exception& e) { @@ -413,8 +414,8 @@ int grib_accessor_class_g2end_step_t::unpack_double(grib_accessor* a, double* va static int pack_long_(grib_accessor* a, const long end_step_value, const long end_step_unit) { grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int err = 0; + grib_handle* h = grib_handle_of_accessor(a); + int err = 0; long year; long month; @@ -435,34 +436,34 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en long typeOfTimeIncrement; double dend, dstep; - const int show_units_for_hours = a->context->grib_hourly_steps_with_units; + const int show_units_for_hours = a->context_->grib_hourly_steps_with_units; eccodes::Step end_step{ end_step_value, end_step_unit }; /*point in time */ - if (self->year == NULL) { + if (self->year_ == NULL) { if ((err = grib_set_long_internal(h, "startStepUnit", end_step.unit().value())) != GRIB_SUCCESS) return err; - err = grib_set_long_internal(h, self->start_step_value, end_step.value()); + err = grib_set_long_internal(h, self->start_step_value_, end_step.value()); return err; } - if ((err = grib_get_long_internal(h, self->time_range_unit, &time_range_unit))) + if ((err = grib_get_long_internal(h, self->time_range_unit_, &time_range_unit))) return err; - if ((err = grib_get_long_internal(h, self->year, &year))) + if ((err = grib_get_long_internal(h, self->year_, &year))) return err; - if ((err = grib_get_long_internal(h, self->month, &month))) + if ((err = grib_get_long_internal(h, self->month_, &month))) return err; - if ((err = grib_get_long_internal(h, self->day, &day))) + if ((err = grib_get_long_internal(h, self->day_, &day))) return err; - if ((err = grib_get_long_internal(h, self->hour, &hour))) + if ((err = grib_get_long_internal(h, self->hour_, &hour))) return err; - if ((err = grib_get_long_internal(h, self->minute, &minute))) + if ((err = grib_get_long_internal(h, self->minute_, &minute))) return err; - if ((err = grib_get_long_internal(h, self->second, &second))) + if ((err = grib_get_long_internal(h, self->second_, &second))) return err; - if ((err = grib_get_long_internal(h, self->start_step_value, &start_step_value))) + if ((err = grib_get_long_internal(h, self->start_step_value_, &start_step_value))) return err; if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit))) return err; @@ -477,7 +478,7 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en return GRIB_WRONG_STEP_UNIT; } - if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement, &typeOfTimeIncrement))) + if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement_, &typeOfTimeIncrement))) return err; eccodes::Step start_step{ start_step_value, start_step_unit }; @@ -491,10 +492,11 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en return GRIB_WRONG_STEP; } - if (!is_date_valid(year, month, day, hour, minute, second)) { // ECC-1866 - grib_context_log(h->context, GRIB_LOG_ERROR, "%s:%s: Date/Time is not valid! " - "year=%ld month=%ld day=%ld hour=%ld minute=%ld second=%ld", - a->cclass->name, __func__, year, month, day, hour, minute, second); + if (!is_date_valid(year, month, day, hour, minute, second)) { // ECC-1866 + grib_context_log(h->context, GRIB_LOG_ERROR, + "%s:%s: Date/Time is not valid! " + "year=%ld month=%ld day=%ld hour=%ld minute=%ld second=%ld", + a->class_name_, __func__, year, month, day, hour, minute, second); return GRIB_DECODING_ERROR; } @@ -511,17 +513,17 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en if (err != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(h, self->year_of_end_of_interval, year_of_end_of_interval))) + if ((err = grib_set_long_internal(h, self->year_of_end_of_interval_, year_of_end_of_interval))) return err; - if ((err = grib_set_long_internal(h, self->month_of_end_of_interval, month_of_end_of_interval))) + if ((err = grib_set_long_internal(h, self->month_of_end_of_interval_, month_of_end_of_interval))) return err; - if ((err = grib_set_long_internal(h, self->day_of_end_of_interval, day_of_end_of_interval))) + if ((err = grib_set_long_internal(h, self->day_of_end_of_interval_, day_of_end_of_interval))) return err; - if ((err = grib_set_long_internal(h, self->hour_of_end_of_interval, hour_of_end_of_interval))) + if ((err = grib_set_long_internal(h, self->hour_of_end_of_interval_, hour_of_end_of_interval))) return err; - if ((err = grib_set_long_internal(h, self->minute_of_end_of_interval, minute_of_end_of_interval))) + if ((err = grib_set_long_internal(h, self->minute_of_end_of_interval_, minute_of_end_of_interval))) return err; - if ((err = grib_set_long_internal(h, self->second_of_end_of_interval, second_of_end_of_interval))) + if ((err = grib_set_long_internal(h, self->second_of_end_of_interval_, second_of_end_of_interval))) return err; const char* forecast_time_value_key = "forecastTime"; @@ -536,9 +538,9 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en time_range_opt = eccodes::Step{ time_range.value(eccodes::Unit{ force_step_units }), eccodes::Unit{ force_step_units } }; } - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->time_range_value, time_range_opt.value())) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->time_range_value_, time_range_opt.value())) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->time_range_unit, time_range_opt.unit().value())) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->time_range_unit_, time_range_opt.unit().value())) != GRIB_SUCCESS) return err; if ((err = grib_set_long_internal(grib_handle_of_accessor(a), forecast_time_value_key, forecast_time_opt.value())) != GRIB_SUCCESS) return err; @@ -548,21 +550,20 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en return GRIB_SUCCESS; } -int grib_accessor_class_g2end_step_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_g2end_step_t::unpack_string(char* val, size_t* len) { - grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; - char fp_format[128] = "%g"; - size_t fp_format_len = sizeof(fp_format); - size_t step_len = 0; + grib_handle* h = grib_handle_of_accessor(this); + int ret = 0; + char fp_format[128] = "%g"; + size_t fp_format_len = sizeof(fp_format); + size_t step_len = 0; long step_value; long step_units; - const int show_units_for_hours = a->context->grib_hourly_steps_with_units; + const int show_units_for_hours = context_->grib_hourly_steps_with_units; - if ((ret = unpack_long(a, &step_value, &step_len)) != GRIB_SUCCESS) + if ((ret = unpack_long(&step_value, &step_len)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(h, self->step_units, &step_units)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, step_units_, &step_units)) != GRIB_SUCCESS) return ret; if ((ret = grib_get_string(h, "formatForDoubles", fp_format, &fp_format_len)) != GRIB_SUCCESS) return ret; @@ -592,9 +593,9 @@ int grib_accessor_class_g2end_step_t::unpack_string(grib_accessor* a, char* val, return GRIB_SUCCESS; } -int grib_accessor_class_g2end_step_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_g2end_step_t::pack_long(const long* val, size_t* len) { - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); int ret; long force_step_units; @@ -613,7 +614,7 @@ int grib_accessor_class_g2end_step_t::pack_long(grib_accessor* a, const long* va else { end_step_unit = force_step_units; } - ret = pack_long_(a, *val, end_step_unit); + ret = pack_long_(this, *val, end_step_unit); } catch (std::exception& e) { grib_context_log(h->context, GRIB_LOG_ERROR, "grib_accessor_g2end_step_t::pack_long: %s", e.what()); @@ -622,9 +623,9 @@ int grib_accessor_class_g2end_step_t::pack_long(grib_accessor* a, const long* va return ret; } -int grib_accessor_class_g2end_step_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_g2end_step_t::pack_string(const char* val, size_t* len) { - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); int ret = 0; long force_step_units; if ((ret = grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS) @@ -637,7 +638,7 @@ int grib_accessor_class_g2end_step_t::pack_string(grib_accessor* a, const char* if ((ret = grib_set_long_internal(h, "endStepUnit", end_step.unit().value())) != GRIB_SUCCESS) return ret; - if ((ret = pack_long_(a, end_step.value(), end_step.unit().value())) != GRIB_SUCCESS) + if ((ret = pack_long_(this, end_step.value(), end_step.unit().value())) != GRIB_SUCCESS) return ret; } catch (std::exception& e) { @@ -647,10 +648,10 @@ int grib_accessor_class_g2end_step_t::pack_string(grib_accessor* a, const char* return GRIB_SUCCESS; } -int grib_accessor_class_g2end_step_t::get_native_type(grib_accessor* a) +long grib_accessor_g2end_step_t::get_native_type() { - grib_handle* h = grib_handle_of_accessor(a); - const int show_units_for_hours = a->context->grib_hourly_steps_with_units; + grib_handle* h = grib_handle_of_accessor(this); + const int show_units_for_hours = context_->grib_hourly_steps_with_units; if (!show_units_for_hours) { long step_units = 0; diff --git a/src/accessor/grib_accessor_class_g2end_step.h b/src/accessor/grib_accessor_class_g2end_step.h index 2a39aa1dd..9bd3461d4 100644 --- a/src/accessor/grib_accessor_class_g2end_step.h +++ b/src/accessor/grib_accessor_class_g2end_step.h @@ -16,38 +16,35 @@ class grib_accessor_g2end_step_t : public grib_accessor_long_t { public: - /* Members defined in g2end_step */ - const char* start_step_value; - const char* step_units; - const char* year; - const char* month; - const char* day; - const char* hour; - const char* minute; - const char* second; - const char* year_of_end_of_interval; - const char* month_of_end_of_interval; - const char* day_of_end_of_interval; - const char* hour_of_end_of_interval; - const char* minute_of_end_of_interval; - const char* second_of_end_of_interval; - const char* time_range_unit; - const char* time_range_value; - const char* typeOfTimeIncrement; - const char* numberOfTimeRanges; -}; - -class grib_accessor_class_g2end_step_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_g2end_step_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_g2end_step_t() : + grib_accessor_long_t() { class_name_ = "g2end_step"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g2end_step_t{}; } - int get_native_type(grib_accessor*) 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; - void dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + int pack_string(const char*, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +public: + const char* start_step_value_; + const char* step_units_; + const char* year_; + const char* month_; + const char* day_; + const char* hour_; + const char* minute_; + const char* second_; + const char* year_of_end_of_interval_; + const char* month_of_end_of_interval_; + const char* day_of_end_of_interval_; + const char* hour_of_end_of_interval_; + const char* minute_of_end_of_interval_; + const char* second_of_end_of_interval_; + const char* time_range_unit_; + const char* time_range_value_; + const char* typeOfTimeIncrement_; + const char* numberOfTimeRanges_; }; diff --git a/src/accessor/grib_accessor_class_g2grid.cc b/src/accessor/grib_accessor_class_g2grid.cc index 3bc0a9a22..61788ee68 100644 --- a/src/accessor/grib_accessor_class_g2grid.cc +++ b/src/accessor/grib_accessor_class_g2grid.cc @@ -11,32 +11,30 @@ #include "grib_accessor_class_g2grid.h" -grib_accessor_class_g2grid_t _grib_accessor_class_g2grid{ "g2grid" }; -grib_accessor_class* grib_accessor_class_g2grid = &_grib_accessor_class_g2grid; +grib_accessor_g2grid_t _grib_accessor_g2grid{}; +grib_accessor* grib_accessor_g2grid = &_grib_accessor_g2grid; - -void grib_accessor_class_g2grid_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g2grid_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_g2grid_t* self = (grib_accessor_g2grid_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_double_t::init(l, c); + grib_handle* hand = grib_handle_of_accessor(this); + int n = 0; - self->latitude_first = grib_arguments_get_name(hand, c, n++); - self->longitude_first = grib_arguments_get_name(hand, c, n++); - self->latitude_last = grib_arguments_get_name(hand, c, n++); - self->longitude_last = grib_arguments_get_name(hand, c, n++); - self->i_increment = grib_arguments_get_name(hand, c, n++); - self->j_increment = grib_arguments_get_name(hand, c, n++); - self->basic_angle = grib_arguments_get_name(hand, c, n++); - self->sub_division = grib_arguments_get_name(hand, c, n++); + latitude_first_ = grib_arguments_get_name(hand, c, n++); + longitude_first_ = grib_arguments_get_name(hand, c, n++); + latitude_last_ = grib_arguments_get_name(hand, c, n++); + longitude_last_ = grib_arguments_get_name(hand, c, n++); + i_increment_ = grib_arguments_get_name(hand, c, n++); + j_increment_ = grib_arguments_get_name(hand, c, n++); + basic_angle_ = grib_arguments_get_name(hand, c, n++); + sub_division_ = grib_arguments_get_name(hand, c, n++); - a->flags |= + flags_ |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC | GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_g2grid_t::value_count(grib_accessor* a, long* count) +int grib_accessor_g2grid_t::value_count(long* count) { *count = 6; return 0; @@ -45,15 +43,14 @@ int grib_accessor_class_g2grid_t::value_count(grib_accessor* a, long* count) // GRIB edition 2 uses microdegrees #define ANGLE_SUBDIVISIONS (1000 * 1000) -int grib_accessor_class_g2grid_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_g2grid_t::unpack_double(double* val, size_t* len) { - grib_accessor_g2grid_t* self = (grib_accessor_g2grid_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int ret = 0; + grib_handle* hand = grib_handle_of_accessor(this); + int ret = 0; long basic_angle = 0; long sub_division = 0; - int n = 0; + int n = 0; long v[6]; if (*len < 6) { @@ -61,13 +58,12 @@ int grib_accessor_class_g2grid_t::unpack_double(grib_accessor* a, double* val, s return ret; } - if ((ret = grib_get_long_internal(hand, self->basic_angle, &basic_angle)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, basic_angle_, &basic_angle)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->sub_division, &sub_division)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, sub_division_, &sub_division)) != GRIB_SUCCESS) return ret; - if (sub_division == GRIB_MISSING_LONG || sub_division == 0) sub_division = ANGLE_SUBDIVISIONS; @@ -75,28 +71,28 @@ int grib_accessor_class_g2grid_t::unpack_double(grib_accessor* a, double* val, s basic_angle = 1; n = 0; - if ((ret = grib_get_long_internal(hand, self->latitude_first, &v[n++])) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, latitude_first_, &v[n++])) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->longitude_first, &v[n++])) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, longitude_first_, &v[n++])) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->latitude_last, &v[n++])) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, latitude_last_, &v[n++])) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->longitude_last, &v[n++])) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, longitude_last_, &v[n++])) != GRIB_SUCCESS) return ret; - if (!self->i_increment) + if (!i_increment_) v[n++] = GRIB_MISSING_LONG; - else if ((ret = grib_get_long_internal(hand, self->i_increment, &v[n++])) != GRIB_SUCCESS) + else if ((ret = grib_get_long_internal(hand, i_increment_, &v[n++])) != GRIB_SUCCESS) return ret; - if (!self->j_increment) { + if (!j_increment_) { v[n++] = GRIB_MISSING_LONG; } else { - if ((ret = grib_get_long_internal(hand, self->j_increment, &v[n++])) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, j_increment_, &v[n++])) != GRIB_SUCCESS) return ret; } for (int i = 0; i < n; i++) @@ -178,10 +174,9 @@ static int trial(const double* val, long v[6], long* basic_angle, long* sub_divi return is_ok(val, v, *basic_angle, *sub_division); } -int grib_accessor_class_g2grid_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_g2grid_t::pack_double(const double* val, size_t* len) { - grib_accessor_g2grid_t* self = (grib_accessor_g2grid_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); int ret; long v[6]; int n; @@ -205,7 +200,7 @@ int grib_accessor_class_g2grid_t::pack_double(grib_accessor* a, const double* va sub_division = ANGLE_SUBDIVISIONS; if (!is_ok(val, v, basic_angle, sub_division)) - grib_context_log(a->context, GRIB_LOG_DEBUG, "Grid cannot be coded with any loss of precision"); + grib_context_log(context_, GRIB_LOG_DEBUG, "Grid cannot be coded with any loss of precision"); } if (basic_angle == 1 && sub_division == ANGLE_SUBDIVISIONS) { @@ -213,33 +208,33 @@ int grib_accessor_class_g2grid_t::pack_double(grib_accessor* a, const double* va sub_division = GRIB_MISSING_LONG; } - if ((ret = grib_set_long_internal(hand, self->basic_angle, basic_angle)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, basic_angle_, basic_angle)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(hand, self->sub_division, sub_division)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, sub_division_, sub_division)) != GRIB_SUCCESS) return ret; n = 0; - if ((ret = grib_set_long_internal(hand, self->latitude_first, v[n++])) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, latitude_first_, v[n++])) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(hand, self->longitude_first, v[n++])) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, longitude_first_, v[n++])) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(hand, self->latitude_last, v[n++])) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, latitude_last_, v[n++])) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(hand, self->longitude_last, v[n++])) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, longitude_last_, v[n++])) != GRIB_SUCCESS) return ret; - if (!self->i_increment) + if (!i_increment_) n++; - else if ((ret = grib_set_long_internal(hand, self->i_increment, v[n++])) != GRIB_SUCCESS) + else if ((ret = grib_set_long_internal(hand, i_increment_, v[n++])) != GRIB_SUCCESS) return ret; - if (!self->j_increment) + if (!j_increment_) n++; - else if ((ret = grib_set_long_internal(hand, self->j_increment, v[n++])) != GRIB_SUCCESS) + else if ((ret = grib_set_long_internal(hand, j_increment_, v[n++])) != GRIB_SUCCESS) return ret; return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_g2grid.h b/src/accessor/grib_accessor_class_g2grid.h index 07c9f9862..07fc48fc0 100644 --- a/src/accessor/grib_accessor_class_g2grid.h +++ b/src/accessor/grib_accessor_class_g2grid.h @@ -16,24 +16,21 @@ class grib_accessor_g2grid_t : public grib_accessor_double_t { public: - /* Members defined in g2grid */ - const char* latitude_first; - const char* longitude_first; - const char* latitude_last; - const char* longitude_last; - const char* i_increment; - const char* j_increment; - const char* basic_angle; - const char* sub_division; -}; - -class grib_accessor_class_g2grid_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_g2grid_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_g2grid_t() : + grib_accessor_double_t() { class_name_ = "g2grid"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g2grid_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; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* latitude_first_; + const char* longitude_first_; + const char* latitude_last_; + const char* longitude_last_; + const char* i_increment_; + const char* j_increment_; + const char* basic_angle_; + const char* sub_division_; }; diff --git a/src/accessor/grib_accessor_class_g2latlon.cc b/src/accessor/grib_accessor_class_g2latlon.cc index afb3a2f7a..14ba5f5c5 100644 --- a/src/accessor/grib_accessor_class_g2latlon.cc +++ b/src/accessor/grib_accessor_class_g2latlon.cc @@ -11,24 +11,21 @@ #include "grib_accessor_class_g2latlon.h" -grib_accessor_class_g2latlon_t _grib_accessor_class_g2latlon{ "g2latlon" }; -grib_accessor_class* grib_accessor_class_g2latlon = &_grib_accessor_class_g2latlon; +grib_accessor_g2latlon_t _grib_accessor_g2latlon{}; +grib_accessor* grib_accessor_g2latlon = &_grib_accessor_g2latlon; - -void grib_accessor_class_g2latlon_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g2latlon_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_g2latlon_t* self = (grib_accessor_g2latlon_t*)a; + grib_accessor_double_t::init(l, c); int n = 0; - self->grid = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->index = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); - self->given = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + grid_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + index_ = grib_arguments_get_long(grib_handle_of_accessor(this), c, n++); + given_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); } -int grib_accessor_class_g2latlon_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_g2latlon_t::unpack_double(double* val, size_t* len) { - grib_accessor_g2latlon_t* self = (grib_accessor_g2latlon_t*)a; int ret = 0; long given = 1; @@ -40,8 +37,8 @@ int grib_accessor_class_g2latlon_t::unpack_double(grib_accessor* a, double* val, return ret; } - if (self->given) - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->given, &given)) != GRIB_SUCCESS) + if (given_) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), given_, &given)) != GRIB_SUCCESS) return ret; if (!given) { @@ -49,41 +46,40 @@ int grib_accessor_class_g2latlon_t::unpack_double(grib_accessor* a, double* val, return GRIB_SUCCESS; } - if ((ret = grib_get_double_array_internal(grib_handle_of_accessor(a), self->grid, grid, &size)) != GRIB_SUCCESS) + if ((ret = grib_get_double_array_internal(grib_handle_of_accessor(this), grid_, grid, &size)) != GRIB_SUCCESS) return ret; - *val = grid[self->index]; + *val = grid[index_]; return GRIB_SUCCESS; } -int grib_accessor_class_g2latlon_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_g2latlon_t::pack_double(const double* val, size_t* len) { - grib_accessor_g2latlon_t* self = (grib_accessor_g2latlon_t*)a; int ret = 0; double grid[6]; size_t size = 6; double new_val = *val; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); if (*len < 1) { ret = GRIB_ARRAY_TOO_SMALL; return ret; } - if (self->given) { + if (given_) { long given = *val != GRIB_MISSING_DOUBLE; - if ((ret = grib_set_long_internal(hand, self->given, given)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, given_, given)) != GRIB_SUCCESS) return ret; } - if ((ret = grib_get_double_array_internal(hand, self->grid, grid, &size)) != GRIB_SUCCESS) + if ((ret = grib_get_double_array_internal(hand, grid_, grid, &size)) != GRIB_SUCCESS) return ret; /* index 1 is longitudeOfFirstGridPointInDegrees * index 3 is longitudeOfLastGridPointInDegrees */ - if ((self->index == 1 || self->index == 3)) { + if ((index_ == 1 || index_ == 3)) { /* WMO regulation for GRIB edition 2: * The longitude values shall be limited to the range 0 to 360 degrees inclusive */ new_val = normalise_longitude_in_degrees(*val); @@ -91,30 +87,28 @@ int grib_accessor_class_g2latlon_t::pack_double(grib_accessor* a, const double* fprintf(stderr, "ECCODES DEBUG pack_double g2latlon: normalise longitude %g -> %g\n", *val, new_val); } } - grid[self->index] = new_val; + grid[index_] = new_val; - return grib_set_double_array_internal(hand, self->grid, grid, size); + return grib_set_double_array_internal(hand, grid_, grid, size); } -int grib_accessor_class_g2latlon_t::pack_missing(grib_accessor* a) +int grib_accessor_g2latlon_t::pack_missing() { - grib_accessor_g2latlon_t* self = (grib_accessor_g2latlon_t*)a; - double missing = GRIB_MISSING_DOUBLE; - size_t size = 1; + double missing = GRIB_MISSING_DOUBLE; + size_t size = 1; - if (!self->given) + if (!given_) return GRIB_NOT_IMPLEMENTED; - return pack_double(a, &missing, &size); + return pack_double(&missing, &size); } -int grib_accessor_class_g2latlon_t::is_missing(grib_accessor* a) +int grib_accessor_g2latlon_t::is_missing() { - grib_accessor_g2latlon_t* self = (grib_accessor_g2latlon_t*)a; - long given = 1; + long given = 1; - if (self->given) - grib_get_long_internal(grib_handle_of_accessor(a), self->given, &given); + if (given_) + grib_get_long_internal(grib_handle_of_accessor(this), given_, &given); return !given; } diff --git a/src/accessor/grib_accessor_class_g2latlon.h b/src/accessor/grib_accessor_class_g2latlon.h index f4733757e..2bcd564b7 100644 --- a/src/accessor/grib_accessor_class_g2latlon.h +++ b/src/accessor/grib_accessor_class_g2latlon.h @@ -16,20 +16,17 @@ class grib_accessor_g2latlon_t : public grib_accessor_double_t { public: - /* Members defined in g2latlon */ - const char* grid; - int index; - const char* given; -}; - -class grib_accessor_class_g2latlon_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_g2latlon_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_g2latlon_t() : + grib_accessor_double_t() { class_name_ = "g2latlon"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g2latlon_t{}; } - 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 unpack_double(grib_accessor*, double* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int pack_missing() override; + int is_missing() override; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* grid_; + int index_; + const char* given_; }; diff --git a/src/accessor/grib_accessor_class_g2level.cc b/src/accessor/grib_accessor_class_g2level.cc index 8da0be27f..5c8370996 100644 --- a/src/accessor/grib_accessor_class_g2level.cc +++ b/src/accessor/grib_accessor_class_g2level.cc @@ -11,24 +11,22 @@ #include "grib_accessor_class_g2level.h" -grib_accessor_class_g2level_t _grib_accessor_class_g2level{ "g2level" }; -grib_accessor_class* grib_accessor_class_g2level = &_grib_accessor_class_g2level; +grib_accessor_g2level_t _grib_accessor_g2level{}; +grib_accessor* grib_accessor_g2level = &_grib_accessor_g2level; - -void grib_accessor_class_g2level_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g2level_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_g2level_t* self = (grib_accessor_g2level_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_long_t::init(l, c); + grib_handle* hand = grib_handle_of_accessor(this); + int n = 0; - self->type_first = grib_arguments_get_name(hand, c, n++); - self->scale_first = grib_arguments_get_name(hand, c, n++); - self->value_first = grib_arguments_get_name(hand, c, n++); - self->pressure_units = grib_arguments_get_name(hand, c, n++); + type_first_ = grib_arguments_get_name(hand, c, n++); + scale_first_ = grib_arguments_get_name(hand, c, n++); + value_first_ = grib_arguments_get_name(hand, c, n++); + pressure_units_ = grib_arguments_get_name(hand, c, n++); // See ECC-1644 - a->flags |= GRIB_ACCESSOR_FLAG_COPY_IF_CHANGING_EDITION; + flags_ |= GRIB_ACCESSOR_FLAG_COPY_IF_CHANGING_EDITION; } bool is_tigge(grib_handle* h) @@ -39,28 +37,29 @@ bool is_tigge(grib_handle* h) return (productionStatus == 4 || productionStatus == 5); } -int grib_accessor_class_g2level_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_g2level_t::unpack_double(double* val, size_t* len) { - int ret = 0; - grib_accessor_g2level_t* self = (grib_accessor_g2level_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + int ret = 0; + grib_handle* hand = grib_handle_of_accessor(this); long type_first = 0; long scale_first = 0; long value_first = 0; - char pressure_units[10] = {0,}; + char pressure_units[10] = { + 0, + }; size_t pressure_units_len = 10; bool tigge = is_tigge(hand); double v; - if ((ret = grib_get_long_internal(hand, self->type_first, &type_first)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, type_first_, &type_first)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->scale_first, &scale_first)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, scale_first_, &scale_first)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->value_first, &value_first)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, value_first_, &value_first)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_string_internal(hand, self->pressure_units, pressure_units, &pressure_units_len)) != GRIB_SUCCESS) + if ((ret = grib_get_string_internal(hand, pressure_units_, pressure_units, &pressure_units_len)) != GRIB_SUCCESS) return ret; if (value_first == GRIB_MISSING_LONG) { @@ -103,7 +102,7 @@ int grib_accessor_class_g2level_t::unpack_double(grib_accessor* a, double* val, // Switch to Pa instead of hPa as the value is less than a hectoPascal char pa[] = "Pa"; size_t lpa = strlen(pa); - if ((ret = grib_set_string_internal(hand, self->pressure_units, pa, &lpa)) != GRIB_SUCCESS) + if ((ret = grib_set_string_internal(hand, pressure_units_, pa, &lpa)) != GRIB_SUCCESS) return ret; } else { @@ -118,39 +117,40 @@ int grib_accessor_class_g2level_t::unpack_double(grib_accessor* a, double* val, return GRIB_SUCCESS; } -int grib_accessor_class_g2level_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g2level_t::unpack_long(long* val, size_t* len) { double dval = 0; - int ret = unpack_double(a, &dval, len); + int ret = unpack_double(&dval, len); if (ret == GRIB_SUCCESS) { *val = (long)(dval + 0.5); // round up } return ret; } -int grib_accessor_class_g2level_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_g2level_t::pack_double(const double* val, size_t* len) { - grib_accessor_g2level_t* self = (grib_accessor_g2level_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int ret = 0; - double value_first = *val; + grib_handle* hand = grib_handle_of_accessor(this); + int ret = 0; + double value_first = *val; // long scale_first = 0; long type_first = 0; - char pressure_units[10] = {0,}; + char pressure_units[10] = { + 0, + }; size_t pressure_units_len = 10; const long lval = (long)value_first; if (value_first == lval) { // input is a whole number; process it as an integer - return pack_long(a, &lval, len); + return pack_long(&lval, len); } if (*len != 1) return GRIB_WRONG_ARRAY_SIZE; - if ((ret = grib_get_long_internal(hand, self->type_first, &type_first)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, type_first_, &type_first)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_string_internal(hand, self->pressure_units, pressure_units, &pressure_units_len)) != GRIB_SUCCESS) + if ((ret = grib_get_string_internal(hand, pressure_units_, pressure_units, &pressure_units_len)) != GRIB_SUCCESS) return ret; switch (type_first) { @@ -176,51 +176,52 @@ int grib_accessor_class_g2level_t::pack_double(grib_accessor* a, const double* v ret = compute_scaled_value_and_scale_factor(value_first, scaled_value_max, scale_factor_max, &lscaled_value, &lscale_factor); if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Key %s (unpack_double): Failed to compute %s and %s from %g", - a->name, self->scale_first, self->value_first, value_first); + grib_context_log(context_, GRIB_LOG_ERROR, "Key %s (unpack_double): Failed to compute %s and %s from %g", + name_, scale_first_, value_first_, value_first); return ret; } if (type_first > 9) { - if ((ret = grib_set_long_internal(hand, self->scale_first, (long)lscale_factor)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, scale_first_, (long)lscale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(hand, self->value_first, (long)lscaled_value)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, value_first_, (long)lscaled_value)) != GRIB_SUCCESS) return ret; } return GRIB_SUCCESS; } -int grib_accessor_class_g2level_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_g2level_t::pack_long(const long* val, size_t* len) { int ret = 0; long value_first = *val; long scale_first = 0; long type_first = 0; - char pressure_units[10] = {0,}; + char pressure_units[10] = { + 0, + }; size_t pressure_units_len = 10; - grib_accessor_g2level_t* self = (grib_accessor_g2level_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int change_scale_and_value = 1; - bool tigge = is_tigge(hand); + grib_handle* hand = grib_handle_of_accessor(this); + int change_scale_and_value = 1; + bool tigge = is_tigge(hand); if (*len != 1) return GRIB_WRONG_ARRAY_SIZE; // Not sure if this is necessary // if (value_first == GRIB_MISSING_LONG) { - // if ((ret=grib_set_missing(hand, self->scale_first)) != GRIB_SUCCESS) + // if ((ret=grib_set_missing(hand, scale_first_ )) != GRIB_SUCCESS) // return ret; - // if ((ret=grib_set_missing(hand, self->value_first)) != GRIB_SUCCESS) + // if ((ret=grib_set_missing(hand, value_first_ )) != GRIB_SUCCESS) // return ret; // return GRIB_SUCCESS; // } - if ((ret = grib_get_long_internal(hand, self->type_first, &type_first)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, type_first_, &type_first)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_string_internal(hand, self->pressure_units, pressure_units, &pressure_units_len)) != GRIB_SUCCESS) + if ((ret = grib_get_string_internal(hand, pressure_units_, pressure_units, &pressure_units_len)) != GRIB_SUCCESS) return ret; switch (type_first) { @@ -257,9 +258,9 @@ int grib_accessor_class_g2level_t::pack_long(grib_accessor* a, const long* val, if (change_scale_and_value) { if (type_first > 9) { - if ((ret = grib_set_long_internal(hand, self->scale_first, scale_first)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, scale_first_, scale_first)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(hand, self->value_first, value_first)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, value_first_, value_first)) != GRIB_SUCCESS) return ret; } } @@ -267,13 +268,12 @@ int grib_accessor_class_g2level_t::pack_long(grib_accessor* a, const long* val, return GRIB_SUCCESS; } -int grib_accessor_class_g2level_t::is_missing(grib_accessor* a) +int grib_accessor_g2level_t::is_missing() { - grib_accessor_g2level_t* self = (grib_accessor_g2level_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int err = 0; + grib_handle* hand = grib_handle_of_accessor(this); + int err = 0; - int ret = grib_is_missing(hand, self->scale_first, &err) + - grib_is_missing(hand, self->value_first, &err); + int ret = grib_is_missing(hand, scale_first_, &err) + + grib_is_missing(hand, value_first_, &err); return ret; } diff --git a/src/accessor/grib_accessor_class_g2level.h b/src/accessor/grib_accessor_class_g2level.h index 55511b8f0..e51fef38d 100644 --- a/src/accessor/grib_accessor_class_g2level.h +++ b/src/accessor/grib_accessor_class_g2level.h @@ -16,22 +16,19 @@ class grib_accessor_g2level_t : public grib_accessor_long_t { public: - /* Members defined in g2level */ - const char* type_first; - const char* scale_first; - const char* value_first; - const char* pressure_units; -}; - -class grib_accessor_class_g2level_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_g2level_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_g2level_t() : + grib_accessor_long_t() { class_name_ = "g2level"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g2level_t{}; } - 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 unpack_double(grib_accessor*, double* 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; + int is_missing() override; + int pack_double(const double* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* type_first_; + const char* scale_first_; + const char* value_first_; + const char* pressure_units_; }; diff --git a/src/accessor/grib_accessor_class_g2lon.cc b/src/accessor/grib_accessor_class_g2lon.cc index b7cb43d03..63b6d8e6a 100644 --- a/src/accessor/grib_accessor_class_g2lon.cc +++ b/src/accessor/grib_accessor_class_g2lon.cc @@ -11,26 +11,23 @@ #include "grib_accessor_class_g2lon.h" -grib_accessor_class_g2lon_t _grib_accessor_class_g2lon{ "g2lon" }; -grib_accessor_class* grib_accessor_class_g2lon = &_grib_accessor_class_g2lon; +grib_accessor_g2lon_t _grib_accessor_g2lon{}; +grib_accessor* grib_accessor_g2lon = &_grib_accessor_g2lon; - -void grib_accessor_class_g2lon_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g2lon_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_g2lon_t* self = (grib_accessor_g2lon_t*)a; + grib_accessor_double_t::init(l, c); int n = 0; - self->longitude = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + longitude_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); } -int grib_accessor_class_g2lon_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_g2lon_t::unpack_double(double* val, size_t* len) { - grib_accessor_g2lon_t* self = (grib_accessor_g2lon_t*)a; int ret = 0; long longitude; - if ((ret = grib_get_long(grib_handle_of_accessor(a), self->longitude, &longitude)) != GRIB_SUCCESS) + if ((ret = grib_get_long(grib_handle_of_accessor(this), longitude_, &longitude)) != GRIB_SUCCESS) return ret; if (longitude == GRIB_MISSING_LONG) { @@ -43,9 +40,8 @@ int grib_accessor_class_g2lon_t::unpack_double(grib_accessor* a, double* val, si return GRIB_SUCCESS; } -int grib_accessor_class_g2lon_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_g2lon_t::pack_double(const double* val, size_t* len) { - grib_accessor_g2lon_t* self = (grib_accessor_g2lon_t*)a; long longitude; double value = *val; @@ -57,5 +53,5 @@ int grib_accessor_class_g2lon_t::pack_double(grib_accessor* a, const double* val value += 360; longitude = (long)(value * 1000000); } - return grib_set_long(grib_handle_of_accessor(a), self->longitude, longitude); + return grib_set_long(grib_handle_of_accessor(this), longitude_, longitude); } diff --git a/src/accessor/grib_accessor_class_g2lon.h b/src/accessor/grib_accessor_class_g2lon.h index d3f5bd8ff..b78cab8dc 100644 --- a/src/accessor/grib_accessor_class_g2lon.h +++ b/src/accessor/grib_accessor_class_g2lon.h @@ -16,16 +16,13 @@ class grib_accessor_g2lon_t : public grib_accessor_double_t { public: - /* Members defined in g2lon */ - const char* longitude; -}; - -class grib_accessor_class_g2lon_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_g2lon_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_g2lon_t() : + grib_accessor_double_t() { class_name_ = "g2lon"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g2lon_t{}; } - int pack_double(grib_accessor*, const double* val, size_t* len) override; - int unpack_double(grib_accessor*, double* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* longitude_; }; diff --git a/src/accessor/grib_accessor_class_g2step_range.cc b/src/accessor/grib_accessor_class_g2step_range.cc index 0c1b49e21..adf08b7d1 100644 --- a/src/accessor/grib_accessor_class_g2step_range.cc +++ b/src/accessor/grib_accessor_class_g2step_range.cc @@ -13,22 +13,19 @@ #include "step_utilities.h" #include +grib_accessor_g2step_range_t _grib_accessor_g2step_range{}; +grib_accessor* grib_accessor_g2step_range = &_grib_accessor_g2step_range; -grib_accessor_class_g2step_range_t _grib_accessor_class_g2step_range{ "g2step_range" }; -grib_accessor_class* grib_accessor_class_g2step_range = &_grib_accessor_class_g2step_range; - - -void grib_accessor_class_g2step_range_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_g2step_range_t::init(const long l, grib_arguments* c) { - grib_accessor_class_gen_t::init(a, l, c); - grib_accessor_g2step_range_t* self = (grib_accessor_g2step_range_t*)a; + grib_accessor_gen_t::init(l, c); int n = 0; - self->start_step = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->end_step = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + start_step_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + end_step_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - a->length = 0; + length_ = 0; } // static void dump(grib_accessor* a, grib_dumper* dumper) @@ -36,19 +33,18 @@ void grib_accessor_class_g2step_range_t::init(grib_accessor* a, const long l, gr // grib_dump_string(dumper, a, NULL); //} -int grib_accessor_class_g2step_range_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_g2step_range_t::unpack_string(char* val, size_t* len) { - grib_accessor_g2step_range_t* self = (grib_accessor_g2step_range_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; - size_t size = 0; - double start_step_value = 0; - double end_step_value = 0; + grib_handle* h = grib_handle_of_accessor(this); + int ret = 0; + size_t size = 0; + double start_step_value = 0; + double end_step_value = 0; long step_units; - int show_hours = a->context->grib_hourly_steps_with_units; + int show_hours = context_->grib_hourly_steps_with_units; - if ((ret = grib_get_double_internal(h, self->start_step, &start_step_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(h, start_step_, &start_step_value)) != GRIB_SUCCESS) return ret; if ((ret = grib_get_long_internal(h, "stepUnits", &step_units)) != GRIB_SUCCESS) return ret; @@ -65,11 +61,11 @@ int grib_accessor_class_g2step_range_t::unpack_string(grib_accessor* a, char* va std::stringstream ss; eccodes::Step start_step{ start_step_value, step_units }; - if (self->end_step == NULL) { + if (end_step_ == NULL) { ss << start_step.value(fp_format, show_hours); } else { - if ((ret = grib_get_double_internal(h, self->end_step, &end_step_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(h, end_step_, &end_step_value)) != GRIB_SUCCESS) return ret; eccodes::Step end_step{ end_step_value, step_units }; @@ -92,7 +88,7 @@ int grib_accessor_class_g2step_range_t::unpack_string(grib_accessor* a, char* va memcpy(val, ss.str().c_str(), size); } catch (std::exception& e) { - grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_g2step_range_t::unpack_string: %s", e.what()); + grib_context_log(context_, GRIB_LOG_ERROR, "grib_accessor_g2step_range_t::unpack_string: %s", e.what()); return GRIB_DECODING_ERROR; } @@ -103,11 +99,10 @@ int grib_accessor_class_g2step_range_t::unpack_string(grib_accessor* a, char* va // and can be in different units // stepRange="X" in instantaneous field is equivalent to set step=X // stepRange="X" in accumulated field is equivalent to startStep=X, endStep=startStep -int grib_accessor_class_g2step_range_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_g2step_range_t::pack_string(const char* val, size_t* len) { - grib_accessor_g2step_range_t* self = (grib_accessor_g2step_range_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; + grib_handle* h = grib_handle_of_accessor(this); + int ret = 0; long force_step_units; if ((ret = grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS) @@ -126,7 +121,7 @@ int grib_accessor_class_g2step_range_t::pack_string(grib_accessor* a, const char try { std::vector steps = parse_range(val, eccodes::Unit{ force_step_units }); if (steps.size() == 0) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Could not parse step range: %s", val); + grib_context_log(context_, GRIB_LOG_ERROR, "Could not parse step range: %s", val); return GRIB_INVALID_ARGUMENT; } @@ -150,58 +145,57 @@ int grib_accessor_class_g2step_range_t::pack_string(grib_accessor* a, const char if ((ret = set_step(h, "forecastTime", "indicatorOfUnitOfTimeRange", step_0)) != GRIB_SUCCESS) return ret; - if (self->end_step != NULL) { + if (end_step_ != NULL) { if (steps.size() > 1) { if ((ret = grib_set_long_internal(h, "endStepUnit", step_1.unit().value()))) return ret; - if ((ret = grib_set_long_internal(h, self->end_step, step_1.value()))) + if ((ret = grib_set_long_internal(h, end_step_, step_1.value()))) return ret; } else { if ((ret = grib_set_long_internal(h, "endStepUnit", step_0.unit().value()))) return ret; - if ((ret = grib_set_long_internal(h, self->end_step, step_0.value()))) + if ((ret = grib_set_long_internal(h, end_step_, step_0.value()))) return ret; } } } catch (std::exception& e) { - grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_class_g2step_range::pack_string: %s", e.what()); + grib_context_log(context_, GRIB_LOG_ERROR, "grib_accessor_g2step_range::pack_string: %s", e.what()); return GRIB_INVALID_ARGUMENT; } return GRIB_SUCCESS; } -int grib_accessor_class_g2step_range_t::value_count(grib_accessor* a, long* count) +int grib_accessor_g2step_range_t::value_count(long* count) { *count = 1; return 0; } -size_t grib_accessor_class_g2step_range_t::string_length(grib_accessor* a) +size_t grib_accessor_g2step_range_t::string_length() { return 255; } -int grib_accessor_class_g2step_range_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_g2step_range_t::pack_long(const long* val, size_t* len) { char buff[100]; size_t bufflen = 100; snprintf(buff, sizeof(buff), "%ld", *val); - return pack_string(a, buff, &bufflen); + return pack_string(buff, &bufflen); } -int grib_accessor_class_g2step_range_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g2step_range_t::unpack_long(long* val, size_t* len) { - grib_accessor_g2step_range_t* self = (grib_accessor_g2step_range_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; - long end_start_value = 0; - long end_step_value = 0; - long step_units = 0; + grib_handle* h = grib_handle_of_accessor(this); + int ret = 0; + long end_start_value = 0; + long end_step_value = 0; + long step_units = 0; - if ((ret = grib_get_long_internal(h, self->start_step, &end_start_value)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, start_step_, &end_start_value)) != GRIB_SUCCESS) return ret; try { if ((ret = grib_get_long_internal(h, "stepUnits", &step_units)) != GRIB_SUCCESS) @@ -212,34 +206,33 @@ int grib_accessor_class_g2step_range_t::unpack_long(grib_accessor* a, long* val, } eccodes::Step start_step{ end_start_value, step_units }; - if (self->end_step == NULL) { + if (end_step_ == NULL) { *val = start_step.value(); } else { - if ((ret = grib_get_long_internal(h, self->end_step, &end_step_value)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, end_step_, &end_step_value)) != GRIB_SUCCESS) return ret; eccodes::Step end_step{ end_step_value, step_units }; *val = end_step.value(); } } catch (std::exception& e) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Failed to unpack step range: %s", e.what()); + grib_context_log(context_, GRIB_LOG_ERROR, "Failed to unpack step range: %s", e.what()); return GRIB_DECODING_ERROR; } return GRIB_SUCCESS; } -int grib_accessor_class_g2step_range_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_g2step_range_t::unpack_double(double* val, size_t* len) { - grib_accessor_g2step_range_t* self = (grib_accessor_g2step_range_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = 0; - double end_start_value = 0; - double end_step_value = 0; - long step_units = 0; + grib_handle* h = grib_handle_of_accessor(this); + int ret = 0; + double end_start_value = 0; + double end_step_value = 0; + long step_units = 0; - if ((ret = grib_get_double_internal(h, self->start_step, &end_start_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(h, start_step_, &end_start_value)) != GRIB_SUCCESS) return ret; if ((ret = grib_get_long_internal(h, "stepUnits", &step_units)) != GRIB_SUCCESS) throw std::runtime_error("Failed to get stepUnits"); @@ -251,25 +244,25 @@ int grib_accessor_class_g2step_range_t::unpack_double(grib_accessor* a, double* } eccodes::Step start_step{ end_start_value, step_units }; - if (self->end_step == NULL) { + if (end_step_ == NULL) { *val = start_step.value(); } else { - if ((ret = grib_get_double_internal(h, self->end_step, &end_step_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(h, end_step_, &end_step_value)) != GRIB_SUCCESS) return ret; eccodes::Step end_step{ end_step_value, step_units }; *val = end_step.value(); } } catch (std::exception& e) { - grib_context_log(a->context, GRIB_LOG_ERROR, "grid_accessor_g2step_range::unpack_double: %s", e.what()); + grib_context_log(context_, GRIB_LOG_ERROR, "grid_accessor_g2step_range::unpack_double: %s", e.what()); return GRIB_DECODING_ERROR; } return GRIB_SUCCESS; } -int grib_accessor_class_g2step_range_t::get_native_type(grib_accessor* a) +long grib_accessor_g2step_range_t::get_native_type() { return GRIB_TYPE_STRING; } diff --git a/src/accessor/grib_accessor_class_g2step_range.h b/src/accessor/grib_accessor_class_g2step_range.h index ec44546b3..ffc1faf42 100644 --- a/src/accessor/grib_accessor_class_g2step_range.h +++ b/src/accessor/grib_accessor_class_g2step_range.h @@ -15,23 +15,20 @@ class grib_accessor_g2step_range_t : public grib_accessor_gen_t { public: - /* Members defined in g2step_range */ - const char* start_step; - const char* end_step; -}; - -class grib_accessor_class_g2step_range_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_g2step_range_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_g2step_range_t() : + grib_accessor_gen_t() { class_name_ = "g2step_range"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_g2step_range_t{}; } - int get_native_type(grib_accessor*) 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 init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + int pack_string(const char*, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* start_step_; + const char* end_step_; }; diff --git a/src/accessor/grib_accessor_class_gaussian_grid_name.cc b/src/accessor/grib_accessor_class_gaussian_grid_name.cc index f6b79e794..80c0e68fe 100644 --- a/src/accessor/grib_accessor_class_gaussian_grid_name.cc +++ b/src/accessor/grib_accessor_class_gaussian_grid_name.cc @@ -11,49 +11,47 @@ #include "grib_accessor_class_gaussian_grid_name.h" -grib_accessor_class_gaussian_grid_name_t _grib_accessor_class_gaussian_grid_name{ "gaussian_grid_name" }; -grib_accessor_class* grib_accessor_class_gaussian_grid_name = &_grib_accessor_class_gaussian_grid_name; +grib_accessor_gaussian_grid_name_t _grib_accessor_gaussian_grid_name{}; +grib_accessor* grib_accessor_gaussian_grid_name = &_grib_accessor_gaussian_grid_name; - -void grib_accessor_class_gaussian_grid_name_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_gaussian_grid_name_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - grib_accessor_gaussian_grid_name_t* self = (grib_accessor_gaussian_grid_name_t*)a; - int n = 0; + grib_accessor_gen_t::init(len, arg); + int n = 0; - self->N = grib_arguments_get_name(a->parent->h, arg, n++); - self->Ni = grib_arguments_get_name(a->parent->h, arg, n++); - self->isOctahedral = grib_arguments_get_name(a->parent->h, arg, n++); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + N_ = grib_arguments_get_name(parent_->h, arg, n++); + Ni_ = grib_arguments_get_name(parent_->h, arg, n++); + isOctahedral_ = grib_arguments_get_name(parent_->h, arg, n++); + length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; } -int grib_accessor_class_gaussian_grid_name_t::get_native_type(grib_accessor* a) +long grib_accessor_gaussian_grid_name_t::get_native_type() { return GRIB_TYPE_STRING; } #define MAX_GRIDNAME_LEN 16 -int grib_accessor_class_gaussian_grid_name_t::unpack_string(grib_accessor* a, char* v, size_t* len) +int grib_accessor_gaussian_grid_name_t::unpack_string(char* v, size_t* len) { - grib_accessor_gaussian_grid_name_t* self = (grib_accessor_gaussian_grid_name_t*)a; - long N = 0, Ni = 0; - char tmp[MAX_GRIDNAME_LEN] = {0,}; + char tmp[MAX_GRIDNAME_LEN] = { + 0, + }; size_t length = 0; int ret = GRIB_SUCCESS; - if ((ret = grib_get_long_internal(a->parent->h, self->N, &N)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(parent_->h, N_, &N)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(a->parent->h, self->Ni, &Ni)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(parent_->h, Ni_, &Ni)) != GRIB_SUCCESS) return ret; if (Ni == GRIB_MISSING_LONG) { /* Reduced gaussian grid */ long isOctahedral = 0; - if ((ret = grib_get_long_internal(a->parent->h, self->isOctahedral, &isOctahedral)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(parent_->h, isOctahedral_, &isOctahedral)) != GRIB_SUCCESS) return ret; if (isOctahedral == 1) { snprintf(tmp, sizeof(tmp), "O%ld", N); @@ -69,10 +67,10 @@ int grib_accessor_class_gaussian_grid_name_t::unpack_string(grib_accessor* a, ch length = strlen(tmp) + 1; if (*len < length) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, + const char* cclass_name = class_name_; + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, length, *len); + cclass_name, name_, length, *len); *len = length; return GRIB_BUFFER_TOO_SMALL; } @@ -82,7 +80,7 @@ int grib_accessor_class_gaussian_grid_name_t::unpack_string(grib_accessor* a, ch return GRIB_SUCCESS; } -size_t grib_accessor_class_gaussian_grid_name_t::string_length(grib_accessor* a) +size_t grib_accessor_gaussian_grid_name_t::string_length() { return MAX_GRIDNAME_LEN; } diff --git a/src/accessor/grib_accessor_class_gaussian_grid_name.h b/src/accessor/grib_accessor_class_gaussian_grid_name.h index d67f80aa5..5508e6db4 100644 --- a/src/accessor/grib_accessor_class_gaussian_grid_name.h +++ b/src/accessor/grib_accessor_class_gaussian_grid_name.h @@ -16,19 +16,16 @@ class grib_accessor_gaussian_grid_name_t : public grib_accessor_gen_t { public: - /* Members defined in gaussian_grid_name */ - const char* N; - const char* Ni; - const char* isOctahedral; -}; - -class grib_accessor_class_gaussian_grid_name_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_gaussian_grid_name_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_gaussian_grid_name_t() : + grib_accessor_gen_t() { class_name_ = "gaussian_grid_name"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_gaussian_grid_name_t{}; } - int get_native_type(grib_accessor*) override; - int unpack_string(grib_accessor*, char*, size_t* len) override; - size_t string_length(grib_accessor*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + void init(const long, grib_arguments*) override; + +private: + const char* N_; + const char* Ni_; + const char* isOctahedral_; }; diff --git a/src/accessor/grib_accessor_class_gds_is_present.cc b/src/accessor/grib_accessor_class_gds_is_present.cc index b568b9bdd..3d93cedae 100644 --- a/src/accessor/grib_accessor_class_gds_is_present.cc +++ b/src/accessor/grib_accessor_class_gds_is_present.cc @@ -11,62 +11,58 @@ #include "grib_accessor_class_gds_is_present.h" -grib_accessor_class_gds_is_present_t _grib_accessor_class_gds_is_present{ "gds_is_present" }; -grib_accessor_class* grib_accessor_class_gds_is_present = &_grib_accessor_class_gds_is_present; +grib_accessor_gds_is_present_t _grib_accessor_gds_is_present{}; +grib_accessor* grib_accessor_gds_is_present = &_grib_accessor_gds_is_present; - -void grib_accessor_class_gds_is_present_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_gds_is_present_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - int n = 0; - grib_accessor_gds_is_present_t* self = (grib_accessor_gds_is_present_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - self->gds_present = grib_arguments_get_name(h, c, n++); - self->grid_definition = grib_arguments_get_name(h, c, n++); - self->bitmap_present = grib_arguments_get_name(h, c, n++); - self->values = grib_arguments_get_name(h, c, n++); + grib_accessor_long_t::init(l, c); + int n = 0; + grib_handle* h = grib_handle_of_accessor(this); + gds_present_ = grib_arguments_get_name(h, c, n++); + grid_definition_ = grib_arguments_get_name(h, c, n++); + bitmap_present_ = grib_arguments_get_name(h, c, n++); + values_ = grib_arguments_get_name(h, c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; - a->length = 0; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + flags_ |= GRIB_ACCESSOR_FLAG_HIDDEN; + length_ = 0; } -int grib_accessor_class_gds_is_present_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_gds_is_present_t::pack_long(const long* val, size_t* len) { - grib_accessor_gds_is_present_t* self = (grib_accessor_gds_is_present_t*)a; - long missing = 255; - int ret = 0; - size_t size = 0; - double* values = NULL; - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); + long missing = 255; + int ret = 0; + size_t size = 0; + double* values = NULL; + grib_context* c = context_; + grib_handle* h = grib_handle_of_accessor(this); if (*val != 1) return GRIB_NOT_IMPLEMENTED; - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + if ((ret = grib_get_size(h, 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) { + if ((ret = grib_get_double_array_internal(h, values_, values, &size)) != GRIB_SUCCESS) { grib_context_free(c, values); return ret; } - if ((ret = grib_set_long_internal(h, self->gds_present, *val)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(h, gds_present_, *val)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(h, self->bitmap_present, *val)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(h, bitmap_present_, *val)) != GRIB_SUCCESS) return ret; - - if ((ret = grib_set_long_internal(h, self->grid_definition, missing)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(h, grid_definition_, missing)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) + if ((ret = grib_set_double_array_internal(h, values_, values, size)) != GRIB_SUCCESS) return ret; grib_context_free(c, values); @@ -74,13 +70,12 @@ int grib_accessor_class_gds_is_present_t::pack_long(grib_accessor* a, const long return GRIB_SUCCESS; } -int grib_accessor_class_gds_is_present_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_gds_is_present_t::unpack_long(long* val, size_t* len) { - int ret = 0; - grib_handle* h = grib_handle_of_accessor(a); - grib_accessor_gds_is_present_t* self = (grib_accessor_gds_is_present_t*)a; + int ret = 0; + grib_handle* h = grib_handle_of_accessor(this); - if ((ret = grib_get_long_internal(h, self->gds_present, val)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, gds_present_, val)) != GRIB_SUCCESS) return ret; *len = 1; diff --git a/src/accessor/grib_accessor_class_gds_is_present.h b/src/accessor/grib_accessor_class_gds_is_present.h index d69619d44..36fe2ddf2 100644 --- a/src/accessor/grib_accessor_class_gds_is_present.h +++ b/src/accessor/grib_accessor_class_gds_is_present.h @@ -16,19 +16,16 @@ class grib_accessor_gds_is_present_t : public grib_accessor_long_t { public: - /* Members defined in gds_is_present */ - const char* gds_present; - const char* grid_definition; - const char* bitmap_present; - const char* values; -}; - -class grib_accessor_class_gds_is_present_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_gds_is_present_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_gds_is_present_t() : + grib_accessor_long_t() { class_name_ = "gds_is_present"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_gds_is_present_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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* gds_present_; + const char* grid_definition_; + const char* bitmap_present_; + const char* values_; }; diff --git a/src/accessor/grib_accessor_class_gds_not_present_bitmap.cc b/src/accessor/grib_accessor_class_gds_not_present_bitmap.cc index 976f7e5b7..f42438b97 100644 --- a/src/accessor/grib_accessor_class_gds_not_present_bitmap.cc +++ b/src/accessor/grib_accessor_class_gds_not_present_bitmap.cc @@ -10,36 +10,32 @@ #include "grib_accessor_class_gds_not_present_bitmap.h" -grib_accessor_class_gds_not_present_bitmap_t _grib_accessor_class_gds_not_present_bitmap{ "gds_not_present_bitmap" }; -grib_accessor_class* grib_accessor_class_gds_not_present_bitmap = &_grib_accessor_class_gds_not_present_bitmap; +grib_accessor_gds_not_present_bitmap_t _grib_accessor_gds_not_present_bitmap{}; +grib_accessor* grib_accessor_gds_not_present_bitmap = &_grib_accessor_gds_not_present_bitmap; - -void grib_accessor_class_gds_not_present_bitmap_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_gds_not_present_bitmap_t::init(const long v, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, v, args); - int n = 0; - grib_accessor_gds_not_present_bitmap_t* self = (grib_accessor_gds_not_present_bitmap_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_accessor_gen_t::init(v, args); + int n = 0; + grib_handle* hand = grib_handle_of_accessor(this); - self->missing_value = grib_arguments_get_name(hand, args, n++); - self->number_of_values = grib_arguments_get_name(hand, args, n++); - self->number_of_points = grib_arguments_get_name(hand, args, n++); - self->latitude_of_first_point = grib_arguments_get_name(hand, args, n++); - self->ni = grib_arguments_get_name(hand, args, n++); - a->length = 0; + missing_value_ = grib_arguments_get_name(hand, args, n++); + number_of_values_ = grib_arguments_get_name(hand, args, n++); + number_of_points_ = grib_arguments_get_name(hand, args, n++); + latitude_of_first_point_ = grib_arguments_get_name(hand, args, n++); + ni_ = grib_arguments_get_name(hand, args, n++); + length_ = 0; } -int grib_accessor_class_gds_not_present_bitmap_t::value_count(grib_accessor* a, long* number_of_points) +int grib_accessor_gds_not_present_bitmap_t::value_count(long* number_of_points) { - grib_accessor_gds_not_present_bitmap_t* self = (grib_accessor_gds_not_present_bitmap_t*)a; - *number_of_points = 0; - return grib_get_long_internal(grib_handle_of_accessor(a), self->number_of_points, number_of_points); + *number_of_points = 0; + return grib_get_long_internal(grib_handle_of_accessor(this), number_of_points_, number_of_points); } -int grib_accessor_class_gds_not_present_bitmap_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_gds_not_present_bitmap_t::unpack_double(double* val, size_t* len) { - grib_accessor_gds_not_present_bitmap_t* self = (grib_accessor_gds_not_present_bitmap_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); long number_of_points = 0, number_of_values = 0, ni = 0; long latitude_of_first_point = 0; @@ -49,24 +45,24 @@ int grib_accessor_class_gds_not_present_bitmap_t::unpack_double(grib_accessor* a long missing_value; double* coded_vals = NULL; - int err = a->value_count(&nn); + int err = value_count(&nn); n_vals = nn; if (err) return err; - if ((err = grib_get_long(hand, self->number_of_points, &number_of_points)) != GRIB_SUCCESS) + if ((err = grib_get_long(hand, number_of_points_, &number_of_points)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long(hand, self->number_of_values, &number_of_values)) != GRIB_SUCCESS) + if ((err = grib_get_long(hand, number_of_values_, &number_of_values)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long(hand, self->latitude_of_first_point, &latitude_of_first_point)) != GRIB_SUCCESS) + if ((err = grib_get_long(hand, latitude_of_first_point_, &latitude_of_first_point)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long(hand, self->missing_value, &missing_value)) != GRIB_SUCCESS) + if ((err = grib_get_long(hand, missing_value_, &missing_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long(hand, self->ni, &ni)) != GRIB_SUCCESS) + if ((err = grib_get_long(hand, ni_, &ni)) != GRIB_SUCCESS) return err; if (*len < number_of_points) { @@ -75,7 +71,7 @@ int grib_accessor_class_gds_not_present_bitmap_t::unpack_double(grib_accessor* a } if (number_of_values > 0) { - coded_vals = (double*)grib_context_malloc(a->context, number_of_values * sizeof(double)); + coded_vals = (double*)grib_context_malloc(context_, number_of_values * sizeof(double)); if (coded_vals == NULL) return GRIB_OUT_OF_MEMORY; @@ -96,18 +92,18 @@ int grib_accessor_class_gds_not_present_bitmap_t::unpack_double(grib_accessor* a *len = number_of_points; - grib_context_free(a->context, coded_vals); + grib_context_free(context_, coded_vals); return err; } -int grib_accessor_class_gds_not_present_bitmap_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_gds_not_present_bitmap_t::pack_double(const double* val, size_t* len) { - // See deprecated/grib_accessor_class_gds_not_present_bitmap.cc for + // See deprecated/grib_accessor_gds_not_present_bitmap.cc for // a possible implementation return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_gds_not_present_bitmap_t::get_native_type(grib_accessor* a) +long grib_accessor_gds_not_present_bitmap_t::get_native_type() { return GRIB_TYPE_DOUBLE; } diff --git a/src/accessor/grib_accessor_class_gds_not_present_bitmap.h b/src/accessor/grib_accessor_class_gds_not_present_bitmap.h index bf9c0c012..0894e410e 100644 --- a/src/accessor/grib_accessor_class_gds_not_present_bitmap.h +++ b/src/accessor/grib_accessor_class_gds_not_present_bitmap.h @@ -16,22 +16,19 @@ class grib_accessor_gds_not_present_bitmap_t : public grib_accessor_gen_t { public: - /* Members defined in gds_not_present_bitmap */ - const char* missing_value; - const char* number_of_values; - const char* number_of_points; - const char* latitude_of_first_point; - const char* ni; -}; - -class grib_accessor_class_gds_not_present_bitmap_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_gds_not_present_bitmap_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_gds_not_present_bitmap_t() : + grib_accessor_gen_t() { class_name_ = "gds_not_present_bitmap"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_gds_not_present_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 init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* missing_value_; + const char* number_of_values_; + const char* number_of_points_; + const char* latitude_of_first_point_; + const char* ni_; }; diff --git a/src/accessor/grib_accessor_class_gen.cc b/src/accessor/grib_accessor_class_gen.cc index 3a721f196..c78240ea9 100644 --- a/src/accessor/grib_accessor_class_gen.cc +++ b/src/accessor/grib_accessor_class_gen.cc @@ -8,215 +8,28 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -#include "grib_accessor.h" +#include "grib_accessor_class.h" #include "grib_accessor_class_gen.h" #include -// ======================== grib_accessor_gen ======================== -void grib_accessor_gen_t::dump(grib_dumper* f) -{ - return cclass->dump(this, f); -} -int grib_accessor_gen_t::pack_missing() -{ - // grib_context_log(a->context, GRIB_LOG_DEBUG, "(%s)%s is packing (double) %g",(a->parent->owner)?(a->parent->owner->name):"root", a->name ,v?(*v):0); - return cclass->pack_missing(this); -} -// int grib_accessor_gen_t::pack_zero(grib_accessor* a) -// { -// return cclass->clear(a); -// } -int grib_accessor_gen_t::is_missing_internal() -{ - return cclass->is_missing(this); -} - -int grib_accessor_gen_t::pack_double(const double* v, size_t* len) -{ - return cclass->pack_double(this, v, len); -} - -int grib_accessor_gen_t::pack_float(const float* v, size_t* len) -{ - return cclass->pack_float(this, v, len); -} - -int grib_accessor_gen_t::pack_expression(grib_expression* e) -{ - return cclass->pack_expression(this, e); -} - -int grib_accessor_gen_t::pack_string(const char* v, size_t* len) -{ - return cclass->pack_string(this, v, len); -} - -int grib_accessor_gen_t::pack_string_array(const char** v, size_t* len) -{ - return cclass->pack_string_array(this, v, len); -} - -int grib_accessor_gen_t::pack_long(const long* v, size_t* len) -{ - return cclass->pack_long(this, v, len); -} - -int grib_accessor_gen_t::pack_bytes(const unsigned char* v, size_t* len) -{ - return cclass->pack_bytes(this, v, len); -} - -int grib_accessor_gen_t::unpack_bytes(unsigned char* v, size_t* len) -{ - return cclass->unpack_bytes(this, v, len); -} - -int grib_accessor_gen_t::unpack_double_subarray(double* v, size_t start, size_t len) -{ - return cclass->unpack_double_subarray(this, v, start, len); -} - -int grib_accessor_gen_t::unpack_double(double* v, size_t* len) -{ - return cclass->unpack_double(this, v, len); -} - -int grib_accessor_gen_t::unpack_float(float* v, size_t* len) -{ - return cclass->unpack_float(this, v, len); -} - -int grib_accessor_gen_t::unpack_double_element(size_t i, double* v) -{ - return cclass->unpack_double_element(this, i, v); -} - -int grib_accessor_gen_t::unpack_float_element(size_t i, float* v) -{ - // return cclass->unpack_float_element(this, i, v); - return GRIB_NOT_IMPLEMENTED; -} - -int grib_accessor_gen_t::unpack_long(long* v, size_t* len) -{ - return cclass->unpack_long(this, v, len); -} - -long grib_accessor_gen_t::get_native_type() -{ - return cclass->get_native_type(this); -} - -long grib_accessor_gen_t::get_next_position_offset() -{ - return cclass->next_offset(this); -} - -long grib_accessor_gen_t::string_length() -{ - return cclass->string_length(this); -} - -long grib_accessor_gen_t::byte_offset() -{ - return cclass->byte_offset(this); -} - -long grib_accessor_gen_t::byte_count() -{ - return cclass->byte_count(this); -} - -int grib_accessor_gen_t::value_count(long* count) -{ - return cclass->value_count(this, count); -} - -int grib_accessor_gen_t::notify_change(grib_accessor* changed) -{ - return cclass->notify_change(this, changed); -} - -// Get the values for the indices passed in. -// The length of the 'index_array' argument should be 'len' and 'val_array' should also contain at least 'len' elements -int grib_accessor_gen_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) -{ - return cclass->unpack_double_element_set(this, index_array, len, val_array); -} -int grib_accessor_gen_t::unpack_float_element_set(const size_t* index_array, size_t len, float* val_array) -{ - throw std::runtime_error("grib_unpack_float_element_set not implemented"); -} -int grib_accessor_gen_t::unpack_string(char* v, size_t* len) -{ - return cclass->unpack_string(this, v, len); -} -int grib_accessor_gen_t::unpack_string_array(char** v, size_t* len) -{ - return cclass->unpack_string_array(this, v, len); -} +grib_accessor_gen_t _grib_accessor_gen = grib_accessor_gen_t{}; +grib_accessor* grib_accessor_gen = &_grib_accessor_gen; void grib_accessor_gen_t::init_accessor(const long len, grib_arguments* args) { - this->cclass->init(this, len, args); + init(len, args); } -grib_accessor* grib_accessor_gen_t::clone(grib_section* s, int* err) +void grib_accessor_gen_t::init(const long len, grib_arguments* param) { - grib_context* ct = this->context; - grib_context_log(ct, GRIB_LOG_DEBUG, "clone %s ==> %s", cclass->name, this->name); - return cclass->make_clone(this, s, err); -} - -void grib_accessor_gen_t::update_size(size_t len) -{ - cclass->update_size(this, len); -} - -int grib_accessor_gen_t::nearest_smaller_value(double val, double* nearest) -{ - return cclass->nearest_smaller_value(this, val, nearest); -} - -size_t grib_accessor_gen_t::preferred_size(int from_handle) -{ - return cclass->preferred_size(this, from_handle); -} - -grib_accessor* grib_accessor_gen_t::next_accessor() -{ - return cclass->next(this, 1); -} - -void grib_accessor_gen_t::resize(size_t new_size) -{ - cclass->resize(this, new_size); -} - -// For this one, ALL destroy are called -void grib_accessor_gen_t::destroy(grib_context* ct) -{ - cclass->destroy(ct, this); - delete this; -} - - -// ======================== grib_accessor_class_gen ======================== - - -grib_accessor_class_gen_t _grib_accessor_class_gen = grib_accessor_class_gen_t("gen"); -grib_accessor_class* grib_accessor_class_gen = &_grib_accessor_class_gen; - -void grib_accessor_class_gen_t::init(grib_accessor* a, const long len, grib_arguments* param) -{ - grib_action* act = (grib_action*)(a->creator); - if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) { - a->length = 0; - if (!a->vvalue) - a->vvalue = (grib_virtual_value*)grib_context_malloc_clear(a->context, sizeof(grib_virtual_value)); - a->vvalue->type = a->get_native_type(); - a->vvalue->length = len; + grib_action* act = (grib_action*)(creator_); + if (flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) { + length_ = 0; + if (!vvalue_) + vvalue_ = (grib_virtual_value*)grib_context_malloc_clear(context_, sizeof(grib_virtual_value)); + vvalue_->type = get_native_type(); + vvalue_->length = len; if (act->default_value != NULL) { const char* p = 0; size_t s_len = 1; @@ -224,98 +37,98 @@ void grib_accessor_class_gen_t::init(grib_accessor* a, const long len, grib_argu int ret = 0; double d; char tmp[1024]; - grib_expression* expression = grib_arguments_get_expression(grib_handle_of_accessor(a), act->default_value, 0); - int type = grib_expression_native_type(grib_handle_of_accessor(a), expression); + grib_expression* expression = grib_arguments_get_expression(grib_handle_of_accessor(this), act->default_value, 0); + int type = grib_expression_native_type(grib_handle_of_accessor(this), expression); switch (type) { // TODO(maee): add single-precision case case GRIB_TYPE_DOUBLE: - grib_expression_evaluate_double(grib_handle_of_accessor(a), expression, &d); - a->pack_double(&d, &s_len); + grib_expression_evaluate_double(grib_handle_of_accessor(this), expression, &d); + pack_double(&d, &s_len); break; case GRIB_TYPE_LONG: - grib_expression_evaluate_long(grib_handle_of_accessor(a), expression, &l); - a->pack_long(&l, &s_len); + grib_expression_evaluate_long(grib_handle_of_accessor(this), expression, &l); + pack_long(&l, &s_len); break; default: s_len = sizeof(tmp); - p = grib_expression_evaluate_string(grib_handle_of_accessor(a), expression, tmp, &s_len, &ret); + p = grib_expression_evaluate_string(grib_handle_of_accessor(this), expression, tmp, &s_len, &ret); if (ret != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to evaluate %s as string", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, "Unable to evaluate %s as string", name_); Assert(0); } s_len = strlen(p) + 1; - a->pack_string(p, &s_len); + pack_string(p, &s_len); break; } } } else { - a->length = len; + length_ = len; } } -void grib_accessor_class_gen_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_gen_t::dump(grib_dumper* dumper) { - const int type = a->get_native_type(); + const int type = get_native_type(); switch (type) { case GRIB_TYPE_STRING: - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); break; case GRIB_TYPE_DOUBLE: - grib_dump_double(dumper, a, NULL); + grib_dump_double(dumper, this, NULL); break; case GRIB_TYPE_LONG: - grib_dump_long(dumper, a, NULL); + grib_dump_long(dumper, this, NULL); break; default: - grib_dump_bytes(dumper, a, NULL); + grib_dump_bytes(dumper, this, NULL); } } -long grib_accessor_class_gen_t::next_offset(grib_accessor* a) +long grib_accessor_gen_t::next_offset() { - return a->offset + a->length; + return offset_ + length_; } -int grib_accessor_class_gen_t::value_count(grib_accessor* a, long* count) +int grib_accessor_gen_t::value_count(long* count) { *count = 1; return 0; } -size_t grib_accessor_class_gen_t::string_length(grib_accessor* a) +size_t grib_accessor_gen_t::string_length() { return 1024; } -long grib_accessor_class_gen_t::byte_count(grib_accessor* a) +long grib_accessor_gen_t::byte_count() { - return a->length; + return length_; } -int grib_accessor_class_gen_t::get_native_type(grib_accessor* a) +long grib_accessor_gen_t::get_native_type() { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Accessor %s [%s] must implement 'get_native_type'", a->name, a->cclass->name); + grib_context_log(context_, GRIB_LOG_ERROR, + "Accessor %s [%s] must implement 'get_native_type'", name_, class_name_); return GRIB_TYPE_UNDEFINED; } -long grib_accessor_class_gen_t::byte_offset(grib_accessor* a) +long grib_accessor_gen_t::byte_offset() { - return a->offset; + return offset_; } -int grib_accessor_class_gen_t::unpack_bytes(grib_accessor* a, unsigned char* val, size_t* len) +int grib_accessor_gen_t::unpack_bytes(unsigned char* val, size_t* len) { - unsigned char* buf = grib_handle_of_accessor(a)->buffer->data; - const long length = a->byte_count(); - const long offset = a->byte_offset(); + unsigned char* buf = grib_handle_of_accessor(this)->buffer->data; + const long length = byte_count(); + const long offset = byte_offset(); if (*len < length) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it is %ld bytes long", a->name, length); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s, it is %ld bytes long", name_, length); *len = length; return GRIB_ARRAY_TOO_SMALL; } @@ -326,31 +139,31 @@ int grib_accessor_class_gen_t::unpack_bytes(grib_accessor* a, unsigned char* val return GRIB_SUCCESS; } -int grib_accessor_class_gen_t::clear(grib_accessor* a) +int grib_accessor_gen_t::clear() { - unsigned char* buf = grib_handle_of_accessor(a)->buffer->data; - const long length = a->byte_count(); - const long offset = a->byte_offset(); + unsigned char* buf = grib_handle_of_accessor(this)->buffer->data; + const long length = byte_count(); + const long offset = byte_offset(); memset(buf + offset, 0, length); return GRIB_SUCCESS; } -int grib_accessor_class_gen_t::unpack_long(grib_accessor* a, long* v, size_t* len) +int grib_accessor_gen_t::unpack_long(long* v, size_t* len) { is_overridden_[UNPACK_LONG] = 0; int type = GRIB_TYPE_UNDEFINED; if (is_overridden_[UNPACK_DOUBLE] == 1) { double val = 0.0; size_t l = 1; - a->unpack_double(&val, &l); + unpack_double(&val, &l); if (is_overridden_[UNPACK_DOUBLE] == 1) { if (val == GRIB_MISSING_DOUBLE) *v = GRIB_MISSING_LONG; else *v = (long)val; - grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting double %s to long", a->name); + grib_context_log(context_, GRIB_LOG_DEBUG, "Casting double %s to long", name_); return GRIB_SUCCESS; } } @@ -359,36 +172,36 @@ int grib_accessor_class_gen_t::unpack_long(grib_accessor* a, long* v, size_t* le char val[1024]; size_t l = sizeof(val); char* last = NULL; - a->unpack_string(val, &l); + unpack_string(val, &l); if (is_overridden_[UNPACK_STRING] == 1) { *v = strtol(val, &last, 10); if (*last == 0) { - grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting string %s to long", a->name); + grib_context_log(context_, GRIB_LOG_DEBUG, "Casting string %s to long", name_); return GRIB_SUCCESS; } } } - grib_context_log(a->context, GRIB_LOG_ERROR, "Cannot unpack key '%s' as long", a->name); - if (grib_get_native_type(grib_handle_of_accessor(a), a->name, &type) == GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Try unpacking as %s", grib_get_type_name(type)); + grib_context_log(context_, GRIB_LOG_ERROR, "Cannot unpack key '%s' as long", name_); + if (grib_get_native_type(grib_handle_of_accessor(this), name_, &type) == GRIB_SUCCESS) { + grib_context_log(context_, GRIB_LOG_ERROR, "Hint: Try unpacking as %s", grib_get_type_name(type)); } return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_gen_t::unpack_double(grib_accessor* a, double* v, size_t* len) +int grib_accessor_gen_t::unpack_double(double* v, size_t* len) { - return unpack_helper(a, v, len); + return unpack_helper(this, v, len); } -int grib_accessor_class_gen_t::unpack_float(grib_accessor* a, float* v, size_t* len) +int grib_accessor_gen_t::unpack_float(float* v, size_t* len) { - return unpack_helper(a, v, len); + return unpack_helper(this, v, len); } -int grib_accessor_class_gen_t::unpack_string(grib_accessor* a, char* v, size_t* len) +int grib_accessor_gen_t::unpack_string(char* v, size_t* len) { is_overridden_[UNPACK_STRING] = 0; @@ -396,12 +209,12 @@ int grib_accessor_class_gen_t::unpack_string(grib_accessor* a, char* v, size_t* if (is_overridden_[UNPACK_DOUBLE] == 1) { double val = 0.0; size_t l = 1; - err = a->unpack_double(&val, &l); + err = unpack_double(&val, &l); if (is_overridden_[UNPACK_DOUBLE] == 1) { if (err) return err; snprintf(v, 64, "%g", val); *len = strlen(v); - grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting double %s to string", a->name); + grib_context_log(context_, GRIB_LOG_DEBUG, "Casting double %s to string", name_); return GRIB_SUCCESS; } } @@ -409,12 +222,12 @@ int grib_accessor_class_gen_t::unpack_string(grib_accessor* a, char* v, size_t* if (is_overridden_[UNPACK_LONG] == 1) { long val = 0; size_t l = 1; - err = a->unpack_long(&val, &l); + err = unpack_long(&val, &l); if (is_overridden_[UNPACK_LONG] == 1) { if (err) return err; snprintf(v, 64, "%ld", val); *len = strlen(v); - grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting long %s to string\n", a->name); + grib_context_log(context_, GRIB_LOG_DEBUG, "Casting long %s to string\n", name_); return GRIB_SUCCESS; } } @@ -422,28 +235,28 @@ int grib_accessor_class_gen_t::unpack_string(grib_accessor* a, char* v, size_t* return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_gen_t::unpack_string_array(grib_accessor* a, char** v, size_t* len) +int grib_accessor_gen_t::unpack_string_array(char** v, size_t* len) { size_t length = 0; - int err = grib_get_string_length_acc(a, &length); + int err = grib_get_string_length_acc(this, &length); if (err) return err; - v[0] = (char*)grib_context_malloc_clear(a->context, length); - a->unpack_string(v[0], &length); // TODO(masn): check return value + v[0] = (char*)grib_context_malloc_clear(context_, length); + unpack_string(v[0], &length); // TODO(masn): check return value *len = 1; return GRIB_SUCCESS; } -int grib_accessor_class_gen_t::pack_expression(grib_accessor* a, grib_expression* e) +int grib_accessor_gen_t::pack_expression(grib_expression* e) { size_t len = 1; long lval = 0; double dval = 0; const char* cval = NULL; int ret = 0; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); // Use the native type of the expression not the accessor switch (grib_expression_native_type(hand, e)) { @@ -451,26 +264,26 @@ int grib_accessor_class_gen_t::pack_expression(grib_accessor* a, grib_expression len = 1; ret = grib_expression_evaluate_long(hand, e, &lval); if (ret != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to set %s as long (from %s)", - a->name, e->cclass->name); + grib_context_log(context_, GRIB_LOG_ERROR, "Unable to set %s as long (from %s)", + name_, e->cclass->name); return ret; } /*if (hand->context->debug) - printf("ECCODES DEBUG grib_accessor_class_gen_t::pack_expression %s %ld\n", a->name,lval);*/ - return a->pack_long(&lval, &len); + printf("ECCODES DEBUG grib_accessor_gen_t::pack_expression %s %ld\n", name,lval);*/ + return pack_long(&lval, &len); } case GRIB_TYPE_DOUBLE: { len = 1; ret = grib_expression_evaluate_double(hand, e, &dval); if (ret != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to set %s as double (from %s)", - a->name, e->cclass->name); + grib_context_log(context_, GRIB_LOG_ERROR, "Unable to set %s as double (from %s)", + name_, e->cclass->name); return ret; } /*if (hand->context->debug) - printf("ECCODES DEBUG grib_accessor_class_gen_t::pack_expression %s %g\n", a->name, dval);*/ - return a->pack_double(&dval, &len); + printf("ECCODES DEBUG grib_accessor_gen_t::pack_expression %s %g\n", name, dval);*/ + return pack_double(&dval, &len); } case GRIB_TYPE_STRING: { @@ -478,24 +291,24 @@ int grib_accessor_class_gen_t::pack_expression(grib_accessor* a, grib_expression len = sizeof(tmp); cval = grib_expression_evaluate_string(hand, e, tmp, &len, &ret); if (ret != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to set %s as string (from %s)", - a->name, e->cclass->name); + grib_context_log(context_, GRIB_LOG_ERROR, "Unable to set %s as string (from %s)", + name_, e->cclass->name); return ret; } len = strlen(cval); /*if (hand->context->debug) - printf("ECCODES DEBUG grib_accessor_class_gen_t::pack_expression %s %s\n", a->name, cval);*/ - return a->pack_string(cval, &len); + printf("ECCODES DEBUG grib_accessor_gen_t::pack_expression %s %s\n", name, cval);*/ + return pack_string(cval, &len); } } return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_gen_t::pack_long(grib_accessor* a, const long* v, size_t* len) +int grib_accessor_gen_t::pack_long(const long* v, size_t* len) { is_overridden_[PACK_LONG] = 0; - grib_context* c = a->context; + grib_context* c = context_; if (is_overridden_[PACK_DOUBLE]) { double* val = (double*)grib_context_malloc(c, *len * (sizeof(double))); if (!val) { @@ -504,14 +317,14 @@ int grib_accessor_class_gen_t::pack_long(grib_accessor* a, const long* v, size_t } for (size_t i = 0; i < *len; i++) val[i] = v[i]; - int ret = a->pack_double(val, len); + int ret = pack_double(val, len); grib_context_free(c, val); if (is_overridden_[PACK_DOUBLE]) { return ret; } } - grib_context_log(c, GRIB_LOG_ERROR, "Should not pack '%s' as an integer", a->name); + grib_context_log(c, GRIB_LOG_ERROR, "Should not pack '%s' as an integer", name_); if (is_overridden_[PACK_STRING]) { grib_context_log(c, GRIB_LOG_ERROR, "Try packing as a string"); } @@ -521,7 +334,7 @@ int grib_accessor_class_gen_t::pack_long(grib_accessor* a, const long* v, size_t int pack_double_array_as_long(grib_accessor* a, const double* v, size_t* len) { - grib_context* c = a->context; + grib_context* c = a->context_; int ret = GRIB_SUCCESS; size_t numBytes = *len * (sizeof(long)); long* lValues = (long*)grib_context_malloc(c, numBytes); @@ -536,30 +349,30 @@ int pack_double_array_as_long(grib_accessor* a, const double* v, size_t* len) return ret; } -int grib_accessor_class_gen_t::pack_double(grib_accessor* a, const double* v, size_t* len) +int grib_accessor_gen_t::pack_double(const double* v, size_t* len) { is_overridden_[PACK_DOUBLE] = 0; - grib_context* c = a->context; + grib_context* c = context_; - if (is_overridden_[PACK_LONG] || strcmp(a->cclass->name, "codetable") == 0) { + if (is_overridden_[PACK_LONG] || strcmp(class_name_, "codetable") == 0) { /* ECC-648: Special case of codetable */ - return pack_double_array_as_long(a, v, len); + return pack_double_array_as_long(this, v, len); } - grib_context_log(c, GRIB_LOG_ERROR, "Should not pack '%s' as a double", a->name); + grib_context_log(c, GRIB_LOG_ERROR, "Should not pack '%s' as a double", name_); if (is_overridden_[PACK_STRING]) { grib_context_log(c, GRIB_LOG_ERROR, "Try packing as a string"); } return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_gen_t::pack_string_array(grib_accessor* a, const char** v, size_t* len) +int grib_accessor_gen_t::pack_string_array(const char** v, size_t* len) { int err = 0; size_t length = 0; grib_accessor* as = 0; - as = a; + as = this; long i = (long)*len - 1; while (as && i >= 0) { length = strlen(v[i]); @@ -567,12 +380,12 @@ int grib_accessor_class_gen_t::pack_string_array(grib_accessor* a, const char** if (err) return err; --i; - as = as->same; + as = as->same_; } return GRIB_SUCCESS; } -int grib_accessor_class_gen_t::pack_string(grib_accessor* a, const char* v, size_t* len) +int grib_accessor_gen_t::pack_string(const char* v, size_t* len) { is_overridden_[PACK_STRING] = 0; if (is_overridden_[PACK_DOUBLE]) { @@ -580,113 +393,124 @@ int grib_accessor_class_gen_t::pack_string(grib_accessor* a, const char* v, size char* endPtr = NULL; /* for error handling */ double val = strtod(v, &endPtr); if (*endPtr) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Invalid value (%s) for key '%s'. String cannot be converted to a double", - __func__, v, a->name); + __func__, v, name_); return GRIB_WRONG_TYPE; } - return a->pack_double(&val, &l); + return pack_double(&val, &l); } if (is_overridden_[PACK_LONG]) { size_t l = 1; long val = atol(v); - int err = a->pack_long(&val, &l); + int err = pack_long(&val, &l); if (is_overridden_[PACK_LONG]) { return err; } } - grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack '%s' as string", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, "Should not pack '%s' as string", name_); return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_gen_t::pack_bytes(grib_accessor* a, const unsigned char* val, size_t* len) +int grib_accessor_gen_t::pack_bytes(const unsigned char* val, size_t* len) { const size_t length = *len; - if (length != a->length) { - grib_context_log(a->context, GRIB_LOG_ERROR, + if (length_ != length) { + grib_context_log(context_, GRIB_LOG_ERROR, "pack_bytes: Wrong size (%zu) for %s. It is %ld bytes long", - length, a->name, a->length); + length, name_, length_); return GRIB_BUFFER_TOO_SMALL; } - grib_buffer_replace(a, val, length, 1, 1); + grib_buffer_replace(this, val, length, 1, 1); return GRIB_SUCCESS; } -void grib_accessor_class_gen_t::destroy(grib_context* ct, grib_accessor* a) +void grib_accessor_gen_t::destroy(grib_context* ct) { - grib_dependency_remove_observed(a); - grib_dependency_remove_observer(a); - if (a->vvalue != NULL) { - grib_context_free(ct, a->vvalue); - a->vvalue = NULL; + grib_dependency_remove_observed(this); + grib_dependency_remove_observer(this); + if (vvalue_ != NULL) { + grib_context_free(ct, vvalue_); + vvalue_ = NULL; } + delete this; /*grib_context_log(ct,GRIB_LOG_DEBUG,"address=%p",a);*/ } -grib_section* grib_accessor_class_gen_t::sub_section(grib_accessor* a) +grib_section* grib_accessor_gen_t::sub_section() { return NULL; } -int grib_accessor_class_gen_t::notify_change(grib_accessor* self, grib_accessor* observed) +int grib_accessor_gen_t::notify_change(grib_accessor* observed) { /* Default behaviour is to notify creator */ - return grib_action_notify_change(self->creator, self, observed); + return grib_action_notify_change(creator_, this, observed); } -void grib_accessor_class_gen_t::update_size(grib_accessor* a, size_t s) +void grib_accessor_gen_t::update_size(size_t s) { - grib_context_log(a->context, GRIB_LOG_FATAL, - "Accessor %s [%s] must implement 'update_size'", a->name, a->cclass->name); + grib_context_log(context_, GRIB_LOG_FATAL, + "Accessor %s [%s] must implement 'update_size'", name_, class_name_); } -grib_accessor* grib_accessor_class_gen_t::next(grib_accessor* a, int mod) +grib_accessor* grib_accessor_gen_t::next_accessor() +{ + return next(this, 1); +} + +grib_accessor* grib_accessor_gen_t::next(grib_accessor* a, int mod) { grib_accessor* next = NULL; if (a->next_) { next = a->next_; } else { - if (a->parent->owner) - next = a->parent->owner->cclass->next(a->parent->owner, 0); + if (a->parent_->owner) + next = a->parent_->owner->next(a->parent_->owner, 0); } return next; } -int grib_accessor_class_gen_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_gen_t::compare(grib_accessor* b) { return GRIB_NOT_IMPLEMENTED; } /* Redefined in all padding */ -size_t grib_accessor_class_gen_t::preferred_size(grib_accessor* a, int from_handle) +size_t grib_accessor_gen_t::preferred_size(int from_handle) { - return a->length; + return length_; } -int grib_accessor_class_gen_t::is_missing(grib_accessor* a) +int grib_accessor_gen_t::is_missing_internal() +{ + return is_missing(); +} + +int grib_accessor_gen_t::is_missing() { int i = 0; int is_missing = 1; unsigned char ones = 0xff; unsigned char* v = NULL; - if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) { - if (a->vvalue == NULL) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s internal error (flags=0x%lX)", a->name, a->flags); - Assert(!"grib_accessor_class_gen_t::is_missing(): a->vvalue == NULL"); + if (flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) { + if (vvalue_ == NULL) { + grib_context_log(context_, GRIB_LOG_ERROR, "%s internal error (flags=0x%lX)", name_, flags_); + Assert(!"grib_accessor_gen_t::is_missing(): vvalue == NULL"); return 0; } - return a->vvalue->missing; + return vvalue_->missing; } - Assert(a->length >= 0); + Assert(length_ >= 0); - v = grib_handle_of_accessor(a)->buffer->data + a->offset; + v = grib_handle_of_accessor(this)->buffer->data + offset_; - for (i = 0; i < a->length; i++) { + for (i = 0; i < length_; i++) { if (*v != ones) { is_missing = 0; break; @@ -697,59 +521,71 @@ int grib_accessor_class_gen_t::is_missing(grib_accessor* a) return is_missing; } -int grib_accessor_class_gen_t::unpack_double_element(grib_accessor* a, size_t i, double* val) +int grib_accessor_gen_t::unpack_double_element(size_t i, double* val) { return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_gen_t::unpack_double_element_set(grib_accessor* a, const size_t* index_array, size_t len, double* val_array) +int grib_accessor_gen_t::unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) { return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_gen_t::unpack_double_subarray(grib_accessor* a, double* val, size_t start, size_t len) +int grib_accessor_gen_t::unpack_double_subarray(double* val, size_t start, size_t len) { return GRIB_NOT_IMPLEMENTED; } -grib_accessor* grib_accessor_class_gen_t::make_clone(grib_accessor* a, grib_section* s, int* err) + +grib_accessor* grib_accessor_gen_t::clone(grib_section* s, int* err) +{ + grib_context* ct = context_; + grib_context_log(ct, GRIB_LOG_DEBUG, "clone %s ==> %s", class_name_, name_); + return make_clone(s, err); +} + +grib_accessor* grib_accessor_gen_t::make_clone(grib_section* s, int* err) { *err = GRIB_NOT_IMPLEMENTED; return NULL; } +long grib_accessor_gen_t::get_next_position_offset() +{ + return next_offset(); +} -grib_accessor_class_gen_t::~grib_accessor_class_gen_t() {}; +grib_accessor_gen_t::~grib_accessor_gen_t(){}; -void grib_accessor_class_gen_t::post_init(grib_accessor*) +void grib_accessor_gen_t::post_init() { return; -}; -int grib_accessor_class_gen_t::pack_missing(grib_accessor*) +} +int grib_accessor_gen_t::pack_missing() { - throw std::runtime_error("grib_accessor_class_gen_t::pack_missing not implemented"); -}; -int grib_accessor_class_gen_t::pack_float(grib_accessor*, const float*, size_t* len) + throw std::runtime_error("grib_accessor_gen_t::pack_missing not implemented"); +} +int grib_accessor_gen_t::pack_float(const float*, size_t* len) { - throw std::runtime_error("grib_accessor_class_gen_t::pack_float not implemented"); -}; -void grib_accessor_class_gen_t::resize(grib_accessor*, size_t) + throw std::runtime_error("grib_accessor_gen_t::pack_float not implemented"); +} +void grib_accessor_gen_t::resize(size_t) { - throw std::runtime_error("grib_accessor_class_gen_t::resize not implemented"); -}; -int grib_accessor_class_gen_t::nearest_smaller_value(grib_accessor*, double, double*) + throw std::runtime_error("grib_accessor_gen_t::resize not implemented"); +} +int grib_accessor_gen_t::nearest_smaller_value(double, double*) { - throw std::runtime_error("grib_accessor_class_gen_t::nearest_smaller_value not implemented"); -}; -int grib_accessor_class_gen_t::unpack_float_element(grib_accessor*, size_t, float*) + throw std::runtime_error("grib_accessor_gen_t::nearest_smaller_value not implemented"); +} +int grib_accessor_gen_t::unpack_float_element(size_t, float*) { - throw std::runtime_error("grib_accessor_class_gen_t::unpack_float_element not implemented"); -}; -int unpack_element_set(grib_accessor*, const size_t*, size_t, double*) + throw std::runtime_error("grib_accessor_gen_t::unpack_float_element not implemented"); +} +int unpack_element_set(const size_t*, size_t, double*) { - throw std::runtime_error("grib_accessor_class_gen_t::unpack_element_set not implemented"); -}; -int grib_accessor_class_gen_t::unpack_float_element_set(grib_accessor*, const size_t*, size_t, float*) + throw std::runtime_error("grib_accessor_gen_t::unpack_element_set not implemented"); +} +int grib_accessor_gen_t::unpack_float_element_set(const size_t*, size_t, float*) { - throw std::runtime_error("grib_accessor_class_gen_t::unpack_float_element_set not implemented"); -}; + throw std::runtime_error("grib_accessor_gen_t::unpack_float_element_set not implemented"); +} diff --git a/src/accessor/grib_accessor_class_gen.h b/src/accessor/grib_accessor_class_gen.h index deba6cad2..407841dd2 100644 --- a/src/accessor/grib_accessor_class_gen.h +++ b/src/accessor/grib_accessor_class_gen.h @@ -14,99 +14,68 @@ #include "grib_accessor.h" #include -class grib_accessor_gen_t : public grib_accessor { - void init_accessor(const long, grib_arguments*) override; - void dump(grib_dumper* f) override; - int pack_missing() override; - //int grib_pack_zero(grib_accessor* a) override; - int is_missing_internal() override; - int pack_double(const double* v, size_t* len) override; - int pack_float(const float* v, size_t* len) override; - int pack_expression(grib_expression* e) override; - int pack_string(const char* v, size_t* len) override; - int pack_string_array(const char** v, size_t* len) override; - int pack_long(const long* v, size_t* len) override; - int pack_bytes(const unsigned char* v, size_t* len) override; - int unpack_bytes(unsigned char* v, size_t* len) override; - int unpack_double_subarray(double* v, size_t start, size_t len) override; - int unpack_double(double* v, size_t* len) override; - int unpack_float(float* v, size_t* len) override; - int unpack_double_element(size_t i, double* v) override; - int unpack_float_element(size_t i, float* v) override; - int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; - int unpack_float_element_set(const size_t* index_array, size_t len, float* val_array) override; - int unpack_string(char* v, size_t* len) override; - int unpack_string_array(char** v, size_t* len) override; - int unpack_long(long* v, size_t* len) override; - long get_native_type() override; - long get_next_position_offset() override; - long string_length() override; - long byte_offset() override; - long byte_count() override; - int value_count(long* count) override; - int notify_change(grib_accessor* changed) override; - grib_accessor* clone(grib_section* s, int* err) override; - void update_size(size_t len) override; - int nearest_smaller_value(double val, double* nearest) override; - size_t preferred_size(int from_handle) override; - grib_accessor* next_accessor() override; - void resize(size_t new_size) override; - void destroy(grib_context* ct) override; -}; -class grib_accessor_class_gen_t : public grib_accessor_class +class grib_accessor_gen_t : public grib_accessor { public: - grib_accessor_class_gen_t(const char* name) : grib_accessor_class{name} {} - ~grib_accessor_class_gen_t(); + grib_accessor_gen_t() : + grib_accessor{} { class_name_ = "gen"; } + ~grib_accessor_gen_t(); - grib_accessor* create_empty_accessor() override{ return new grib_accessor_gen_t(); } - grib_section* sub_section(grib_accessor* a) override; - int get_native_type(grib_accessor*) override; - int pack_missing(grib_accessor*) override; - int is_missing(grib_accessor*) override; - int pack_bytes(grib_accessor*, const unsigned char*, size_t* len) override; - int pack_double(grib_accessor*, const double* val, size_t* len) override; - int pack_float(grib_accessor*, const float* 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 pack_expression(grib_accessor*, grib_expression*) 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_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; - int unpack_string_array(grib_accessor*, char**, size_t* len) override; - size_t string_length(grib_accessor*) 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; - void post_init(grib_accessor*) override; - int notify_change(grib_accessor*, grib_accessor*) override; - void update_size(grib_accessor*, size_t) override; - size_t preferred_size(grib_accessor*, int) override; - void resize(grib_accessor*, size_t) override; - int nearest_smaller_value(grib_accessor*, double, double*) override; + void init_accessor(const long, grib_arguments*) override; // TODO: Implement + grib_accessor* create_empty_accessor() override { return new grib_accessor_gen_t{}; } + grib_section* sub_section() override; + long get_native_type() override; + int pack_missing() override; + int is_missing() override; + int is_missing_internal() override; // TODO: Implement + int pack_bytes(const unsigned char*, size_t* len) override; + int pack_double(const double* val, size_t* len) override; + int pack_float(const float* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + int pack_string(const char*, size_t* len) override; + int pack_string_array(const char**, size_t* len) override; + int pack_expression(grib_expression*) override; + int unpack_bytes(unsigned char*, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_float(float* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + int unpack_string_array(char**, size_t* len) override; + size_t string_length() override; + long byte_count() override; + long byte_offset() override; + long get_next_position_offset() override; // TODO: Implement + long next_offset() override; + int value_count(long*) override; + void destroy(grib_context*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + void post_init() override; + int notify_change(grib_accessor* changed) override; + void update_size(size_t) override; + size_t preferred_size(int) override; + void resize(size_t) override; + int nearest_smaller_value(double, double*) override; grib_accessor* next(grib_accessor*, int) override; - int compare(grib_accessor*, grib_accessor*) override; - int unpack_double_element(grib_accessor*, size_t i, double* val) override; - int unpack_float_element(grib_accessor*, size_t i, float* val) override; - int unpack_double_element_set(grib_accessor*, const size_t* index_array, size_t len, double* val_array) override; - int unpack_float_element_set(grib_accessor*, const size_t* index_array, size_t len, float* val_array) override; - int unpack_double_subarray(grib_accessor*, double* val, size_t start, size_t len) override; - int clear(grib_accessor*) override; - grib_accessor* make_clone(grib_accessor*, grib_section*, int*) override; + int compare(grib_accessor* a) override; + int unpack_double_element(size_t i, double* val) override; + int unpack_float_element(size_t i, float* val) override; + int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; + int unpack_float_element_set(const size_t* index_array, size_t len, float* val_array) override; + int unpack_double_subarray(double* val, size_t start, size_t len) override; + int clear() override; + grib_accessor* clone(grib_section* s, int* err) override; // TODO: Implement + grib_accessor* make_clone(grib_section*, int*) override; + grib_accessor* next_accessor() override; // TODO: Implement + template int unpack_helper(grib_accessor* a, T* v, size_t* len); private: - enum { + enum + { PACK_DOUBLE, PACK_FLOAT, PACK_LONG, @@ -121,10 +90,10 @@ private: template -int grib_accessor_class_gen_t::unpack_helper(grib_accessor* a, T* v, size_t* len) +int grib_accessor_gen_t::unpack_helper(grib_accessor* a, T* v, size_t* len) { static_assert(std::is_floating_point::value, "Requires floating point numbers"); - int type = GRIB_TYPE_UNDEFINED; + int type = GRIB_TYPE_UNDEFINED; const char* Tname = type_to_string(*v); if constexpr (std::is_same_v) { @@ -140,7 +109,7 @@ int grib_accessor_class_gen_t::unpack_helper(grib_accessor* a, T* v, size_t* len a->unpack_long(&val, &l); if (is_overridden_[UNPACK_LONG]) { *v = val; - grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting long %s to %s", a->name, Tname); + grib_context_log(a->context_, GRIB_LOG_DEBUG, "Casting long %s to %s", a->name_, Tname); return GRIB_SUCCESS; } } @@ -153,15 +122,15 @@ int grib_accessor_class_gen_t::unpack_helper(grib_accessor* a, T* v, size_t* len if (is_overridden_[UNPACK_STRING]) { *v = strtod(val, &last); if (*last == 0) { /* conversion of string to double worked */ - grib_context_log(a->context, GRIB_LOG_DEBUG, "Casting string %s to %s", a->name, Tname); + grib_context_log(a->context_, GRIB_LOG_DEBUG, "Casting string %s to %s", a->name_, Tname); return GRIB_SUCCESS; } } } - grib_context_log(a->context, GRIB_LOG_ERROR, "Cannot unpack key '%s' as %s", a->name, Tname); - if (grib_get_native_type(grib_handle_of_accessor(a), a->name, &type) == GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Try unpacking as %s", grib_get_type_name(type)); + grib_context_log(a->context_, GRIB_LOG_ERROR, "Cannot unpack key '%s' as %s", a->name_, Tname); + if (grib_get_native_type(grib_handle_of_accessor(a), a->name_, &type) == GRIB_SUCCESS) { + grib_context_log(a->context_, GRIB_LOG_ERROR, "Hint: Try unpacking as %s", grib_get_type_name(type)); } return GRIB_NOT_IMPLEMENTED; diff --git a/src/accessor/grib_accessor_class_getenv.cc b/src/accessor/grib_accessor_class_getenv.cc index a6d6f9c72..244acdf32 100644 --- a/src/accessor/grib_accessor_class_getenv.cc +++ b/src/accessor/grib_accessor_class_getenv.cc @@ -10,57 +10,54 @@ #include "grib_accessor_class_getenv.h" -grib_accessor_class_getenv_t _grib_accessor_class_getenv{ "getenv" }; -grib_accessor_class* grib_accessor_class_getenv = &_grib_accessor_class_getenv; +grib_accessor_getenv_t _grib_accessor_getenv{}; +grib_accessor* grib_accessor_getenv = &_grib_accessor_getenv; - -void grib_accessor_class_getenv_t::init(grib_accessor* a, const long l, grib_arguments* args) +void grib_accessor_getenv_t::init(const long l, grib_arguments* args) { - grib_accessor_class_ascii_t::init(a, l, args); - grib_accessor_getenv_t* self = (grib_accessor_getenv_t*)a; - static char undefined[] = "undefined"; + grib_accessor_ascii_t::init(l, args); + static char undefined[] = "undefined"; - self->name = grib_arguments_get_string(grib_handle_of_accessor(a), args, 0); - self->default_value = grib_arguments_get_string(grib_handle_of_accessor(a), args, 1); - if (!self->default_value) - self->default_value = undefined; - self->value = 0; + name_ = grib_arguments_get_string(grib_handle_of_accessor(this), args, 0); + default_value_ = grib_arguments_get_string(grib_handle_of_accessor(this), args, 1); + if (!default_value_) + default_value_ = undefined; + value_ = 0; } -int grib_accessor_class_getenv_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_getenv_t::pack_string(const char* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_getenv_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_getenv_t::unpack_string(char* val, size_t* len) { - grib_accessor_getenv_t* self = (grib_accessor_getenv_t*)a; - char* v = 0; + char* v = 0; size_t l = 0; - if (!self->value) { - v = getenv(self->name); + if (!value_) { + v = getenv(name_); if (!v) - v = (char*)self->default_value; - self->value = v; + v = (char*)default_value_; + value_ = v; } - l = strlen(self->value); + l = strlen(value_); if (*len < l) return GRIB_BUFFER_TOO_SMALL; - snprintf(val, 1024, "%s", self->value); - *len = strlen(self->value); + snprintf(val, 1024, "%s", value_); + *len = strlen(value_); return GRIB_SUCCESS; } -int grib_accessor_class_getenv_t::value_count(grib_accessor* a, long* count) +int grib_accessor_getenv_t::value_count(long* count) { *count = 1; return 0; } -size_t grib_accessor_class_getenv_t::string_length(grib_accessor* a) +size_t grib_accessor_getenv_t::string_length() { return 1024; } diff --git a/src/accessor/grib_accessor_class_getenv.h b/src/accessor/grib_accessor_class_getenv.h index b04c58a4d..219c71eae 100644 --- a/src/accessor/grib_accessor_class_getenv.h +++ b/src/accessor/grib_accessor_class_getenv.h @@ -15,20 +15,18 @@ class grib_accessor_getenv_t : public grib_accessor_ascii_t { public: - const char* name; - char* value; - const char* default_value; -}; - -class grib_accessor_class_getenv_t : public grib_accessor_class_ascii_t -{ -public: - grib_accessor_class_getenv_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor_getenv_t() : + grib_accessor_ascii_t() { class_name_ = "getenv"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_getenv_t{}; } - int pack_string(grib_accessor*, const char*, 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 init(grib_accessor*, const long, grib_arguments*) override; -}; + int pack_string(const char*, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; +private: + // TODO(maee): shadows name_? + const char* name_; + char* value_; + const char* default_value_; +}; diff --git a/src/accessor/grib_accessor_class_global_gaussian.cc b/src/accessor/grib_accessor_class_global_gaussian.cc index 7fa8c96e6..55511c7e8 100644 --- a/src/accessor/grib_accessor_class_global_gaussian.cc +++ b/src/accessor/grib_accessor_class_global_gaussian.cc @@ -10,33 +10,30 @@ #include "grib_accessor_class_global_gaussian.h" -grib_accessor_class_global_gaussian_t _grib_accessor_class_global_gaussian{ "global_gaussian" }; -grib_accessor_class* grib_accessor_class_global_gaussian = &_grib_accessor_class_global_gaussian; +grib_accessor_global_gaussian_t _grib_accessor_global_gaussian{}; +grib_accessor* grib_accessor_global_gaussian = &_grib_accessor_global_gaussian; - -void grib_accessor_class_global_gaussian_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_global_gaussian_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_global_gaussian_t* self = (grib_accessor_global_gaussian_t*)a; - int n = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_long_t::init(l, c); + int n = 0; + grib_handle* h = grib_handle_of_accessor(this); - self->N = grib_arguments_get_name(h, c, n++); - self->Ni = grib_arguments_get_name(h, c, n++); - self->di = grib_arguments_get_name(h, c, n++); - self->latfirst = grib_arguments_get_name(h, c, n++); - self->lonfirst = grib_arguments_get_name(h, c, n++); - self->latlast = grib_arguments_get_name(h, c, n++); - self->lonlast = grib_arguments_get_name(h, c, n++); - self->plpresent = grib_arguments_get_name(h, c, n++); - self->pl = grib_arguments_get_name(h, c, n++); - self->basic_angle = grib_arguments_get_name(h, c, n++); - self->subdivision = grib_arguments_get_name(h, c, n++); + N_ = grib_arguments_get_name(h, c, n++); + Ni_ = grib_arguments_get_name(h, c, n++); + di_ = grib_arguments_get_name(h, c, n++); + latfirst_ = grib_arguments_get_name(h, c, n++); + lonfirst_ = grib_arguments_get_name(h, c, n++); + latlast_ = grib_arguments_get_name(h, c, n++); + lonlast_ = grib_arguments_get_name(h, c, n++); + plpresent_ = grib_arguments_get_name(h, c, n++); + pl_ = grib_arguments_get_name(h, c, n++); + basic_angle_ = grib_arguments_get_name(h, c, n++); + subdivision_ = grib_arguments_get_name(h, c, n++); } -int grib_accessor_class_global_gaussian_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_global_gaussian_t::unpack_long(long* val, size_t* len) { - grib_accessor_global_gaussian_t* self = (grib_accessor_global_gaussian_t*)a; int ret = GRIB_SUCCESS; long latfirst, latlast, lonfirst, lonlast, basic_angle, subdivision, N, Ni; double dlatfirst, dlatlast, dlonfirst, dlonlast; @@ -44,15 +41,15 @@ int grib_accessor_class_global_gaussian_t::unpack_long(grib_accessor* a, long* v double* lats = NULL; long factor = 1000, plpresent = 0; long max_pl = 0; /* max. element of pl array */ - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); + grib_context* c = context_; + grib_handle* h = grib_handle_of_accessor(this); - if (self->basic_angle && self->subdivision) { + if (basic_angle_ && subdivision_) { factor = 1000000; - if ((ret = grib_get_long_internal(h, self->basic_angle, &basic_angle)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, basic_angle_, &basic_angle)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(h, self->subdivision, &subdivision)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, subdivision_, &subdivision)) != GRIB_SUCCESS) return ret; if ((basic_angle != 0 && basic_angle != GRIB_MISSING_LONG) || @@ -66,25 +63,25 @@ int grib_accessor_class_global_gaussian_t::unpack_long(grib_accessor* a, long* v } angular_precision = 1.0 / factor; - if ((ret = grib_get_long_internal(h, self->N, &N)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, N_, &N)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(h, self->Ni, &Ni)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, Ni_, &Ni)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(h, self->latfirst, &latfirst)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, latfirst_, &latfirst)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(h, self->lonfirst, &lonfirst)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, lonfirst_, &lonfirst)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(h, self->latlast, &latlast)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, latlast_, &latlast)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(h, self->lonlast, &lonlast)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, lonlast_, &lonlast)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(h, self->plpresent, &plpresent)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, plpresent_, &plpresent)) != GRIB_SUCCESS) return ret; dlatfirst = ((double)latfirst) / factor; @@ -93,14 +90,14 @@ int grib_accessor_class_global_gaussian_t::unpack_long(grib_accessor* a, long* v dlonlast = ((double)lonlast) / factor; if (N == 0) { - grib_context_log(c, GRIB_LOG_ERROR, "Key %s (unpack_long): N cannot be 0!", a->name); + grib_context_log(c, GRIB_LOG_ERROR, "Key %s (unpack_long): N cannot be 0!", name_); return GRIB_WRONG_GRID; } lats = (double*)grib_context_malloc(c, sizeof(double) * N * 2); if (!lats) { grib_context_log(c, GRIB_LOG_ERROR, - "Key %s (unpack_long): Memory allocation error: %zu bytes", a->name, sizeof(double) * N * 2); + "Key %s (unpack_long): Memory allocation error: %zu bytes", name_, sizeof(double) * N * 2); return GRIB_OUT_OF_MEMORY; } if ((ret = grib_get_gaussian_latitudes(N, lats)) != GRIB_SUCCESS) @@ -111,11 +108,11 @@ int grib_accessor_class_global_gaussian_t::unpack_long(grib_accessor* a, long* v if (plpresent) { size_t plsize = 0, i = 0; long* pl = NULL; /* pl array */ - if ((ret = grib_get_size(h, self->pl, &plsize)) != GRIB_SUCCESS) + if ((ret = grib_get_size(h, pl_, &plsize)) != GRIB_SUCCESS) return ret; Assert(plsize); pl = (long*)grib_context_malloc_clear(c, sizeof(long) * plsize); - grib_get_long_array_internal(h, self->pl, pl, &plsize); + grib_get_long_array_internal(h, pl_, pl, &plsize); max_pl = pl[0]; for (i = 1; i < plsize; i++) { @@ -141,58 +138,57 @@ int grib_accessor_class_global_gaussian_t::unpack_long(grib_accessor* a, long* v return ret; } -int grib_accessor_class_global_gaussian_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_global_gaussian_t::pack_long(const long* val, size_t* len) { - grib_accessor_global_gaussian_t* self = (grib_accessor_global_gaussian_t*)a; - int ret = GRIB_SUCCESS; + int ret = GRIB_SUCCESS; long latfirst, latlast, lonfirst, lonlast, di, diold, basic_angle = 0, N, Ni; long factor; double* lats; double ddi, dlonlast; double dfactor, dNi; long plpresent = 0; - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); + grib_context* c = context_; + grib_handle* h = grib_handle_of_accessor(this); if (*val == 0) return ret; - if (self->basic_angle) { + if (basic_angle_) { factor = 1000000; - if ((ret = grib_set_missing(h, self->subdivision)) != GRIB_SUCCESS) + if ((ret = grib_set_missing(h, subdivision_)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(h, self->basic_angle, basic_angle)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(h, basic_angle_, basic_angle)) != GRIB_SUCCESS) return ret; } else factor = 1000; - if ((ret = grib_get_long_internal(h, self->N, &N)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, N_, &N)) != GRIB_SUCCESS) return ret; if (N == 0) return ret; - if ((ret = grib_get_long_internal(h, self->Ni, &Ni)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, Ni_, &Ni)) != GRIB_SUCCESS) return ret; if (Ni == GRIB_MISSING_LONG) Ni = N * 4; if (Ni == 0) return ret; - if ((ret = grib_get_long_internal(h, self->di, &diold)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, di_, &diold)) != GRIB_SUCCESS) return ret; lats = (double*)grib_context_malloc(c, sizeof(double) * N * 2); if (!lats) { grib_context_log(c, GRIB_LOG_ERROR, - "Key %s (pack_long): Memory allocation error: %zu bytes", a->name, sizeof(double) * N * 2); + "Key %s (pack_long): Memory allocation error: %zu bytes", name_, sizeof(double) * N * 2); return GRIB_OUT_OF_MEMORY; } if ((ret = grib_get_gaussian_latitudes(N, lats)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(h, self->plpresent, &plpresent)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, plpresent_, &plpresent)) != GRIB_SUCCESS) return ret; /* GRIB-854: For octahedral grids, get max of pl array */ @@ -201,11 +197,11 @@ int grib_accessor_class_global_gaussian_t::pack_long(grib_accessor* a, const lon long* pl = NULL; /* pl array */ long max_pl = 0; /* max. element of pl array */ - if ((ret = grib_get_size(h, self->pl, &plsize)) != GRIB_SUCCESS) + if ((ret = grib_get_size(h, pl_, &plsize)) != GRIB_SUCCESS) return ret; Assert(plsize); pl = (long*)grib_context_malloc_clear(c, sizeof(long) * plsize); - grib_get_long_array_internal(h, self->pl, pl, &plsize); + grib_get_long_array_internal(h, pl_, pl, &plsize); max_pl = pl[0]; for (i = 1; i < plsize; i++) { @@ -231,20 +227,20 @@ int grib_accessor_class_global_gaussian_t::pack_long(grib_accessor* a, const lon grib_context_free(c, lats); - if ((ret = grib_set_long_internal(h, self->latfirst, latfirst)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(h, latfirst_, latfirst)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(h, self->lonfirst, lonfirst)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(h, lonfirst_, lonfirst)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(h, self->latlast, latlast)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(h, latlast_, latlast)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(h, self->lonlast, lonlast)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(h, lonlast_, lonlast)) != GRIB_SUCCESS) return ret; if (diold != GRIB_MISSING_LONG) - if ((ret = grib_set_long_internal(h, self->di, di)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(h, di_, di)) != GRIB_SUCCESS) return ret; return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_global_gaussian.h b/src/accessor/grib_accessor_class_global_gaussian.h index 1d49c0c32..ebb59b6b6 100644 --- a/src/accessor/grib_accessor_class_global_gaussian.h +++ b/src/accessor/grib_accessor_class_global_gaussian.h @@ -16,26 +16,23 @@ class grib_accessor_global_gaussian_t : public grib_accessor_long_t { public: - /* Members defined in global_gaussian */ - const char* N; - const char* Ni; - const char* di; - const char* latfirst; - const char* lonfirst; - const char* latlast; - const char* lonlast; - const char* plpresent; - const char* pl; - const char* basic_angle; - const char* subdivision; -}; - -class grib_accessor_class_global_gaussian_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_global_gaussian_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_global_gaussian_t() : + grib_accessor_long_t() { class_name_ = "global_gaussian"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_global_gaussian_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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* N_; + const char* Ni_; + const char* di_; + const char* latfirst_; + const char* lonfirst_; + const char* latlast_; + const char* lonlast_; + const char* plpresent_; + const char* pl_; + const char* basic_angle_; + const char* subdivision_; }; diff --git a/src/accessor/grib_accessor_class_group.cc b/src/accessor/grib_accessor_class_group.cc index 74051d17d..d605d5aea 100644 --- a/src/accessor/grib_accessor_class_group.cc +++ b/src/accessor/grib_accessor_class_group.cc @@ -10,31 +10,29 @@ #include "grib_accessor_class_group.h" -grib_accessor_class_group_t _grib_accessor_class_group{ "group" }; -grib_accessor_class* grib_accessor_class_group = &_grib_accessor_class_group; +grib_accessor_group_t _grib_accessor_group{}; +grib_accessor* grib_accessor_group = &_grib_accessor_group; - -void grib_accessor_class_group_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_group_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - grib_buffer* buffer = grib_handle_of_accessor(a)->buffer; - grib_accessor_group_t* self = (grib_accessor_group_t*)a; + grib_accessor_gen_t::init(len, arg); + grib_buffer* buffer = grib_handle_of_accessor(this)->buffer; size_t i = 0; unsigned char* v; - const char* s = grib_arguments_get_string(grib_handle_of_accessor(a), arg, 0); + const char* s = grib_arguments_get_string(grib_handle_of_accessor(this), arg, 0); if (s && strlen(s) > 1) { - grib_context_log(a->context, GRIB_LOG_WARNING, - "Using only first character as group end of %s not the string %s", a->name, s); + grib_context_log(context_, GRIB_LOG_WARNING, + "Using only first character as group end of %s not the string %s", name_, s); } - self->endCharacter = s ? s[0] : 0; + endCharacter_ = s ? s[0] : 0; - v = buffer->data + a->offset; + v = buffer->data + offset_; i = 0; if (s) { - while (*v != self->endCharacter && i <= buffer->ulength) { + while (*v != endCharacter_ && i <= buffer->ulength) { if (*v > 126) *v = 32; v++; @@ -47,60 +45,62 @@ void grib_accessor_class_group_t::init(grib_accessor* a, const long len, grib_ar i++; } } - a->length = i; + length_ = i; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_group_t::value_count(grib_accessor* a, long* count) +int grib_accessor_group_t::value_count(long* count) { *count = 1; return 0; } -size_t grib_accessor_class_group_t::string_length(grib_accessor* a) +size_t grib_accessor_group_t::string_length() { - return a->length; + return length_; } -void grib_accessor_class_group_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_group_t::dump(grib_dumper* dumper) { - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); } -int grib_accessor_class_group_t::get_native_type(grib_accessor* a) +long grib_accessor_group_t::get_native_type() { return GRIB_TYPE_STRING; } -int grib_accessor_class_group_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_group_t::unpack_string(char* val, size_t* len) { long i = 0; - size_t l = a->length + 1; - grib_handle* h = grib_handle_of_accessor(a); + size_t l = length_ + 1; + grib_handle* h = grib_handle_of_accessor(this); if (*len < l) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - a->cclass->name, a->name, l, *len); + class_name_, name_, l, *len); *len = l; return GRIB_ARRAY_TOO_SMALL; } - for (i = 0; i < a->length; i++) - val[i] = h->buffer->data[a->offset + i]; + for (i = 0; i < length_; i++) + val[i] = h->buffer->data[offset_ + i]; val[i] = 0; *len = i; return GRIB_SUCCESS; } -int grib_accessor_class_group_t::unpack_long(grib_accessor* a, long* v, size_t* len) +int grib_accessor_group_t::unpack_long(long* v, size_t* len) { - char val[1024] = {0,}; + char val[1024] = { + 0, + }; size_t l = sizeof(val); size_t i = 0; char* last = NULL; - int err = a->unpack_string(val, &l); + int err = unpack_string(val, &l); if (err) return err; @@ -117,29 +117,29 @@ int grib_accessor_class_group_t::unpack_long(grib_accessor* a, long* v, size_t* *v = strtol(val, &last, 10); - grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name); + grib_context_log(context_, GRIB_LOG_DEBUG, " Casting string %s to long", name_); return GRIB_SUCCESS; } -int grib_accessor_class_group_t::unpack_double(grib_accessor* a, double* v, size_t* len) +int grib_accessor_group_t::unpack_double(double* v, size_t* len) { char val[1024]; size_t l = sizeof(val); char* last = NULL; - a->unpack_string(val, &l); + unpack_string(val, &l); *v = strtod(val, &last); if (*last == 0) { - grib_context_log(a->context, GRIB_LOG_DEBUG, " Casting string %s to long", a->name); + grib_context_log(context_, GRIB_LOG_DEBUG, " Casting string %s to long", name_); return GRIB_SUCCESS; } return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_group_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_group_t::compare(grib_accessor* b) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s:%s not implemented", __func__, a->name); + grib_context_log(context_, GRIB_LOG_ERROR, "%s:%s not implemented", __func__, name_); return GRIB_NOT_IMPLEMENTED; // int retval = 0; @@ -149,21 +149,21 @@ int grib_accessor_class_group_t::compare(grib_accessor* a, grib_accessor* b) // size_t alen = 0; // size_t blen = 0; // long count = 0; - // err = a->value_count(&count); // if (err) return err; + // err = value_count(&count); // if (err) return err; // alen = count; // err = b->value_count(&count); // if (err) return err; // blen = count; // if (alen != blen) return GRIB_COUNT_MISMATCH; - // aval = (char*)grib_context_malloc(a->context, alen * sizeof(char)); + // aval = (char*)grib_context_malloc(context , alen * sizeof(char)); // bval = (char*)grib_context_malloc(b->context, blen * sizeof(char)); - // a->unpack_string(aval, &alen); // b->unpack_string(bval, &blen); // retval = GRIB_SUCCESS; + // unpack_string(aval, &alen); // b->unpack_string(bval, &blen); // retval = GRIB_SUCCESS; // if (strcmp(aval, bval)) retval = GRIB_STRING_VALUE_MISMATCH; - // grib_context_free(a->context, aval); + // grib_context_free(context , aval); // grib_context_free(b->context, bval); // return retval; } -long grib_accessor_class_group_t::next_offset(grib_accessor* a) +long grib_accessor_group_t::next_offset() { - return a->offset + a->length; + return offset_ + length_; } diff --git a/src/accessor/grib_accessor_class_group.h b/src/accessor/grib_accessor_class_group.h index 9f1c31a81..dc6bb1822 100644 --- a/src/accessor/grib_accessor_class_group.h +++ b/src/accessor/grib_accessor_class_group.h @@ -16,23 +16,20 @@ class grib_accessor_group_t : public grib_accessor_gen_t { public: - /* Members defined in group */ - char endCharacter; -}; - -class grib_accessor_class_group_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_group_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_group_t() : + grib_accessor_gen_t() { class_name_ = "group"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_group_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; - size_t string_length(grib_accessor*) override; - long next_offset(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; + long get_native_type() override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + long next_offset() override; + int value_count(long*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + int compare(grib_accessor*) override; + +private: + char endCharacter_; }; diff --git a/src/accessor/grib_accessor_class_gts_header.cc b/src/accessor/grib_accessor_class_gts_header.cc index 5b158c6d1..5889f18af 100644 --- a/src/accessor/grib_accessor_class_gts_header.cc +++ b/src/accessor/grib_accessor_class_gts_header.cc @@ -10,27 +10,24 @@ #include "grib_accessor_class_gts_header.h" -grib_accessor_class_gts_header_t _grib_accessor_class_gts_header{ "gts_header" }; -grib_accessor_class* grib_accessor_class_gts_header = &_grib_accessor_class_gts_header; +grib_accessor_gts_header_t _grib_accessor_gts_header{}; +grib_accessor* grib_accessor_gts_header = &_grib_accessor_gts_header; - -void grib_accessor_class_gts_header_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_gts_header_t::init(const long l, grib_arguments* c) { - grib_accessor_class_ascii_t::init(a, l, c); - grib_accessor_gts_header_t* self = (grib_accessor_gts_header_t*)a; - self->gts_offset = -1; - self->gts_length = -1; - self->gts_offset = grib_arguments_get_long(grib_handle_of_accessor(a), c, 0); - self->gts_length = grib_arguments_get_long(grib_handle_of_accessor(a), c, 1); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + grib_accessor_ascii_t::init(l, c); + gts_offset_ = -1; + gts_length_ = -1; + gts_offset_ = grib_arguments_get_long(grib_handle_of_accessor(this), c, 0); + gts_length_ = grib_arguments_get_long(grib_handle_of_accessor(this), c, 1); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_gts_header_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_gts_header_t::unpack_string(char* val, size_t* len) { - grib_accessor_gts_header_t* self = (grib_accessor_gts_header_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int offset = 0; - size_t length = 0; + grib_handle* h = grib_handle_of_accessor(this); + int offset = 0; + size_t length = 0; if (h->gts_header == NULL || h->gts_header_len < 8) { if (*len < 8) @@ -41,8 +38,8 @@ int grib_accessor_class_gts_header_t::unpack_string(grib_accessor* a, char* val, if (*len < h->gts_header_len) return GRIB_BUFFER_TOO_SMALL; - offset = self->gts_offset > 0 ? self->gts_offset : 0; - length = self->gts_length > 0 ? self->gts_length : h->gts_header_len; + offset = gts_offset_ > 0 ? gts_offset_ : 0; + length = gts_length_ > 0 ? gts_length_ : h->gts_header_len; memcpy(val, h->gts_header + offset, length); @@ -51,14 +48,14 @@ int grib_accessor_class_gts_header_t::unpack_string(grib_accessor* a, char* val, return GRIB_SUCCESS; } -int grib_accessor_class_gts_header_t::value_count(grib_accessor* a, long* count) +int grib_accessor_gts_header_t::value_count(long* count) { *count = 1; return 0; } -size_t grib_accessor_class_gts_header_t::string_length(grib_accessor* a) +size_t grib_accessor_gts_header_t::string_length() { - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); return h->gts_header_len; } diff --git a/src/accessor/grib_accessor_class_gts_header.h b/src/accessor/grib_accessor_class_gts_header.h index 8072986a7..81a58ba4b 100644 --- a/src/accessor/grib_accessor_class_gts_header.h +++ b/src/accessor/grib_accessor_class_gts_header.h @@ -16,18 +16,15 @@ class grib_accessor_gts_header_t : public grib_accessor_ascii_t { public: - /* Members defined in gts_header */ - int gts_offset; - int gts_length; -}; - -class grib_accessor_class_gts_header_t : public grib_accessor_class_ascii_t -{ -public: - grib_accessor_class_gts_header_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor_gts_header_t() : + grib_accessor_ascii_t() { class_name_ = "gts_header"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_gts_header_t{}; } - 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 init(grib_accessor*, const long, grib_arguments*) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + int gts_offset_; + int gts_length_; }; diff --git a/src/accessor/grib_accessor_class_hash_array.cc b/src/accessor/grib_accessor_class_hash_array.cc index 7f29ce9bc..789102ad9 100644 --- a/src/accessor/grib_accessor_class_hash_array.cc +++ b/src/accessor/grib_accessor_class_hash_array.cc @@ -10,59 +10,56 @@ #include "grib_accessor_class_hash_array.h" -grib_accessor_class_hash_array_t _grib_accessor_class_hash_array{ "hash_array" }; -grib_accessor_class* grib_accessor_class_hash_array = &_grib_accessor_class_hash_array; - +grib_accessor_hash_array_t _grib_accessor_hash_array{}; +grib_accessor* grib_accessor_hash_array = &_grib_accessor_hash_array; #define MAX_HASH_ARRAY_STRING_LENGTH 255 -void grib_accessor_class_hash_array_t::init(grib_accessor* a, const long len, grib_arguments* args) +void grib_accessor_hash_array_t::init(const long len, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, len, args); - grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; - a->length = 0; - self->key = 0; - self->ha = NULL; + grib_accessor_gen_t::init(len, args); + length_ = 0; + key_ = 0; + ha_ = NULL; } -void grib_accessor_class_hash_array_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_hash_array_t::dump(grib_dumper* dumper) { - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); } -int grib_accessor_class_hash_array_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_hash_array_t::pack_double(const double* val, size_t* len) { - grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; - - char s[200] = {0,}; + char s[200] = { + 0, + }; snprintf(s, sizeof(s), "%g", *val); - self->key = grib_context_strdup(a->context, s); - self->ha = 0; + key_ = grib_context_strdup(context_, s); + ha_ = 0; return GRIB_SUCCESS; } -int grib_accessor_class_hash_array_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_hash_array_t::pack_long(const long* val, size_t* len) { - grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; - - char s[200] = {0,}; + char s[200] = { + 0, + }; snprintf(s, sizeof(s), "%ld", *val); - if (self->key) - grib_context_free(a->context, self->key); - self->key = grib_context_strdup(a->context, s); - self->ha = 0; + if (key_) + grib_context_free(context_, key_); + key_ = grib_context_strdup(context_, s); + ha_ = 0; return GRIB_SUCCESS; } -int grib_accessor_class_hash_array_t::pack_string(grib_accessor* a, const char* v, size_t* len) +int grib_accessor_hash_array_t::pack_string(const char* v, size_t* len) { - grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; - self->key = grib_context_strdup(a->context, v); - self->ha = 0; + key_ = grib_context_strdup(context_, v); + ha_ = 0; return GRIB_SUCCESS; } -int grib_accessor_class_hash_array_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_hash_array_t::unpack_double(double* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } @@ -73,10 +70,10 @@ static grib_hash_array_value* find_hash_value(grib_accessor* a, int* err) grib_hash_array_value* ha_ret = 0; grib_hash_array_value* ha = NULL; - ha = get_hash_array(grib_handle_of_accessor(a), a->creator); + ha = get_hash_array(grib_handle_of_accessor(a), self->creator_); if (!ha) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "unable to get hash value for %s", a->creator->name); + grib_context_log(a->context_, GRIB_LOG_ERROR, + "unable to get hash value for %s", self->creator_->name); *err = GRIB_HASH_ARRAY_NO_MATCH; return NULL; } @@ -84,54 +81,53 @@ static grib_hash_array_value* find_hash_value(grib_accessor* a, int* err) *err = GRIB_SUCCESS; Assert(ha != NULL); - if (!self->key) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "unable to get hash value for %s, set before getting", a->creator->name); + if (!self->key_) { + grib_context_log(a->context_, GRIB_LOG_ERROR, + "unable to get hash value for %s, set before getting", self->creator_->name); *err = GRIB_HASH_ARRAY_NO_MATCH; return NULL; } - ha_ret = (grib_hash_array_value*)grib_trie_get(ha->index, self->key); + ha_ret = (grib_hash_array_value*)grib_trie_get(ha->index, self->key_); if (!ha_ret) ha_ret = (grib_hash_array_value*)grib_trie_get(ha->index, "default"); if (!ha_ret) { *err = GRIB_HASH_ARRAY_NO_MATCH; - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(a->context_, GRIB_LOG_ERROR, "hash_array: no match for %s=%s", - a->creator->name, self->key); - const char* full_path = get_hash_array_full_path(a->creator); + self->creator_->name, self->key_); + const char* full_path = get_hash_array_full_path(self->creator_); if (full_path) { - grib_context_log(a->context, GRIB_LOG_ERROR, "hash_array: file path = %s", full_path); + grib_context_log(a->context_, GRIB_LOG_ERROR, "hash_array: file path = %s", full_path); } - grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Check the key 'masterTablesVersionNumber'"); + grib_context_log(a->context_, GRIB_LOG_ERROR, "Hint: Check the key 'masterTablesVersionNumber'"); return NULL; } return ha_ret; } -int grib_accessor_class_hash_array_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_hash_array_t::unpack_long(long* val, size_t* len) { - grib_hash_array_value* ha = 0; - grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; - int err = 0; - size_t i = 0; + grib_hash_array_value* ha = 0; + int err = 0; + size_t i = 0; - if (!self->ha) { - ha = find_hash_value(a, &err); + if (!ha_) { + ha = find_hash_value(this, &err); if (err) return err; - self->ha = ha; + ha_ = ha; } - switch (self->ha->type) { + switch (ha_->type) { case GRIB_HASH_ARRAY_TYPE_INTEGER: - if (*len < self->ha->iarray->n) { + if (*len < ha_->iarray->n) { return GRIB_ARRAY_TOO_SMALL; } - *len = self->ha->iarray->n; + *len = ha_->iarray->n; for (i = 0; i < *len; i++) - val[i] = self->ha->iarray->v[i]; + val[i] = ha_->iarray->v[i]; break; default: @@ -141,51 +137,49 @@ int grib_accessor_class_hash_array_t::unpack_long(grib_accessor* a, long* val, s return GRIB_SUCCESS; } -int grib_accessor_class_hash_array_t::get_native_type(grib_accessor* a) +long grib_accessor_hash_array_t::get_native_type() { int type = GRIB_TYPE_STRING; - if (a->flags & GRIB_ACCESSOR_FLAG_LONG_TYPE) + if (flags_ & GRIB_ACCESSOR_FLAG_LONG_TYPE) type = GRIB_TYPE_LONG; return type; } -void grib_accessor_class_hash_array_t::destroy(grib_context* c, grib_accessor* a) +void grib_accessor_hash_array_t::destroy(grib_context* c) { - grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; - if (self->key) - grib_context_free(c, self->key); - grib_accessor_class_gen_t::destroy(c, a); + if (key_) + grib_context_free(c, key_); + grib_accessor_gen_t::destroy(c); } -int grib_accessor_class_hash_array_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_hash_array_t::unpack_string(char* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -size_t grib_accessor_class_hash_array_t::string_length(grib_accessor* a) +size_t grib_accessor_hash_array_t::string_length() { return MAX_HASH_ARRAY_STRING_LENGTH; } -int grib_accessor_class_hash_array_t::value_count(grib_accessor* a, long* count) +int grib_accessor_hash_array_t::value_count(long* count) { - int err = 0; - grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; - grib_hash_array_value* ha = 0; + int err = 0; + grib_hash_array_value* ha = 0; - if (!self->ha) { - ha = find_hash_value(a, &err); + if (!ha_) { + ha = find_hash_value(this, &err); if (err) return err; - self->ha = ha; + ha_ = ha; } - *count = self->ha->iarray->n; + *count = ha_->iarray->n; return err; } -int grib_accessor_class_hash_array_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_hash_array_t::compare(grib_accessor* b) { return GRIB_NOT_IMPLEMENTED; } diff --git a/src/accessor/grib_accessor_class_hash_array.h b/src/accessor/grib_accessor_class_hash_array.h index fa2732cac..7819dbc8b 100644 --- a/src/accessor/grib_accessor_class_hash_array.h +++ b/src/accessor/grib_accessor_class_hash_array.h @@ -16,27 +16,24 @@ class grib_accessor_hash_array_t : public grib_accessor_gen_t { public: - /* Members defined in hash_array */ - char* key; - grib_hash_array_value* ha; -}; - -class grib_accessor_class_hash_array_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_hash_array_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_hash_array_t() : + grib_accessor_gen_t() { class_name_ = "hash_array"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_hash_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 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; + long get_native_type() override; + int pack_double(const double* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + int pack_string(const char*, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + int value_count(long*) override; + void destroy(grib_context*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + int compare(grib_accessor*) override; + +public: + char* key_; + grib_hash_array_value* ha_; }; diff --git a/src/accessor/grib_accessor_class_headers_only.cc b/src/accessor/grib_accessor_class_headers_only.cc index 4b70ecd2f..7d747bf91 100644 --- a/src/accessor/grib_accessor_class_headers_only.cc +++ b/src/accessor/grib_accessor_class_headers_only.cc @@ -10,26 +10,25 @@ #include "grib_accessor_class_headers_only.h" -grib_accessor_class_headers_only_t _grib_accessor_class_headers_only{ "headers_only" }; -grib_accessor_class* grib_accessor_class_headers_only = &_grib_accessor_class_headers_only; +grib_accessor_headers_only_t _grib_accessor_headers_only{}; +grib_accessor* grib_accessor_headers_only = &_grib_accessor_headers_only; - -void grib_accessor_class_headers_only_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_headers_only_t::init(const long l, grib_arguments* c) { - grib_accessor_class_gen_t::init(a, l, c); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; - a->length = 0; + grib_accessor_gen_t::init(l, c); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_HIDDEN; + length_ = 0; } -int grib_accessor_class_headers_only_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_headers_only_t::unpack_long(long* val, size_t* len) { - *val = grib_handle_of_accessor(a)->partial; + *val = grib_handle_of_accessor(this)->partial; *len = 1; return 0; } -int grib_accessor_class_headers_only_t::get_native_type(grib_accessor* a) +long grib_accessor_headers_only_t::get_native_type() { return GRIB_TYPE_LONG; } diff --git a/src/accessor/grib_accessor_class_headers_only.h b/src/accessor/grib_accessor_class_headers_only.h index a7dc81891..3ca33f2a6 100644 --- a/src/accessor/grib_accessor_class_headers_only.h +++ b/src/accessor/grib_accessor_class_headers_only.h @@ -16,15 +16,10 @@ class grib_accessor_headers_only_t : public grib_accessor_gen_t { public: - /* Members defined in headers_only */ -}; - -class grib_accessor_class_headers_only_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_headers_only_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_headers_only_t() : + grib_accessor_gen_t() { class_name_ = "headers_only"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_headers_only_t{}; } - int get_native_type(grib_accessor*) override; - int unpack_long(grib_accessor*, long* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_ibmfloat.cc b/src/accessor/grib_accessor_class_ibmfloat.cc index c5766db01..f63c2d67b 100644 --- a/src/accessor/grib_accessor_class_ibmfloat.cc +++ b/src/accessor/grib_accessor_class_ibmfloat.cc @@ -11,32 +11,30 @@ #include "grib_accessor_class_ibmfloat.h" -grib_accessor_class_ibmfloat_t _grib_accessor_class_ibmfloat{ "ibmfloat" }; -grib_accessor_class* grib_accessor_class_ibmfloat = &_grib_accessor_class_ibmfloat; +grib_accessor_ibmfloat_t _grib_accessor_ibmfloat{}; +grib_accessor* grib_accessor_ibmfloat = &_grib_accessor_ibmfloat; - -void grib_accessor_class_ibmfloat_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_ibmfloat_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_double_t::init(a, len, arg); - grib_accessor_ibmfloat_t* self = (grib_accessor_ibmfloat_t*)a; - long count = 0; + grib_accessor_double_t::init(len, arg); + long count = 0; - self->arg = arg; - a->value_count(&count); - a->length = 4 * count; - Assert(a->length >= 0); + arg_ = arg; + value_count(&count); + length_ = 4 * count; + Assert(length_ >= 0); } - template static int unpack(grib_accessor* a, T* val, size_t* len) { + grib_accessor_ibmfloat_t* self = (grib_accessor_ibmfloat_t*)a; static_assert(std::is_floating_point::value, "Requires floating point numbers"); unsigned long rlen = 0; long count = 0; int err = 0; unsigned long i = 0; - long bitp = a->offset * 8; + long bitp = a->offset_ * 8; grib_handle* hand = grib_handle_of_accessor(a); err = a->value_count(&count); @@ -45,7 +43,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) rlen = count; if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size (%zu) for %s, it contains %lu values", *len, a->name, rlen); + grib_context_log(a->context_, GRIB_LOG_ERROR, "Wrong size (%zu) for %s, it contains %lu values", *len, a->name_, rlen); *len = 0; return GRIB_ARRAY_TOO_SMALL; } @@ -57,20 +55,18 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_SUCCESS; } -int grib_accessor_class_ibmfloat_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_ibmfloat_t::unpack_double(double* val, size_t* len) { - return unpack(a, val, len); + return unpack(this, val, len); } -int grib_accessor_class_ibmfloat_t::unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_ibmfloat_t::unpack_float(float* val, size_t* len) { - return unpack(a, val, len); + return unpack(this, val, len); } -int grib_accessor_class_ibmfloat_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_ibmfloat_t::pack_double(const double* val, size_t* len) { - grib_accessor_ibmfloat_t* self = (grib_accessor_ibmfloat_t*)a; - int ret = 0; unsigned long i = 0; unsigned long rlen = *len; @@ -79,7 +75,7 @@ int grib_accessor_class_ibmfloat_t::pack_double(grib_accessor* a, const double* long off = 0; if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it packs at least 1 value", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s, it packs at least 1 value", name_); *len = 0; return GRIB_ARRAY_TOO_SMALL; } @@ -90,11 +86,11 @@ int grib_accessor_class_ibmfloat_t::pack_double(grib_accessor* a, const double* // double y = grib_long_to_ibm(grib_ibm_to_long(val[0])); // printf("IBMFLOAT val=%.20f nearest_smaller_ibm_float=%.20f long_to_ibm=%.20f\n",val[0],x ,y); - off = a->byte_offset() * 8; - ret = grib_encode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, grib_ibm_to_long(val[0]), &off, 32); + off = byte_offset() * 8; + ret = grib_encode_unsigned_long(grib_handle_of_accessor(this)->buffer->data, grib_ibm_to_long(val[0]), &off, 32); if (*len > 1) - grib_context_log(a->context, GRIB_LOG_WARNING, "ibmfloat: Trying to pack %zu values in a scalar %s, packing first value", - *len, a->name); + grib_context_log(context_, GRIB_LOG_WARNING, "ibmfloat: Trying to pack %zu values in a scalar %s, packing first value", + *len, name_); if (ret == GRIB_SUCCESS) len[0] = 1; return ret; @@ -102,63 +98,62 @@ int grib_accessor_class_ibmfloat_t::pack_double(grib_accessor* a, const double* buflen = rlen * 4; - buf = (unsigned char*)grib_context_malloc(a->context, buflen); + buf = (unsigned char*)grib_context_malloc(context_, buflen); for (i = 0; i < rlen; i++) { grib_encode_unsigned_longb(buf, grib_ibm_to_long(val[i]), &off, 32); } - ret = grib_set_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), rlen); + ret = grib_set_long_internal(grib_handle_of_accessor(this), grib_arguments_get_name(parent_->h, arg_, 0), rlen); if (ret == GRIB_SUCCESS) - grib_buffer_replace(a, buf, buflen, 1, 1); + grib_buffer_replace(this, buf, buflen, 1, 1); else *len = 0; - grib_context_free(a->context, buf); + grib_context_free(context_, buf); - a->length = a->byte_count(); + length_ = byte_count(); return ret; } -long grib_accessor_class_ibmfloat_t::byte_count(grib_accessor* a) +long grib_accessor_ibmfloat_t::byte_count() { - return a->length; + return length_; } -int grib_accessor_class_ibmfloat_t::value_count(grib_accessor* a, long* len) +int grib_accessor_ibmfloat_t::value_count(long* len) { - grib_accessor_ibmfloat_t* self = (grib_accessor_ibmfloat_t*)a; *len = 0; - if (!self->arg) { + if (!arg_) { *len = 1; return 0; } - return grib_get_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), len); + return grib_get_long_internal(grib_handle_of_accessor(this), grib_arguments_get_name(parent_->h, arg_, 0), len); } -long grib_accessor_class_ibmfloat_t::byte_offset(grib_accessor* a) +long grib_accessor_ibmfloat_t::byte_offset() { - return a->offset; + return offset_; } -void grib_accessor_class_ibmfloat_t::update_size(grib_accessor* a, size_t s) +void grib_accessor_ibmfloat_t::update_size(size_t s) { - a->length = (long)s; - Assert(a->length >= 0); + length_ = (long)s; + Assert(length_ >= 0); } -long grib_accessor_class_ibmfloat_t::next_offset(grib_accessor* a) +long grib_accessor_ibmfloat_t::next_offset() { - return a->byte_offset() + a->byte_count(); + return byte_offset() + byte_count(); } -int grib_accessor_class_ibmfloat_t::nearest_smaller_value(grib_accessor* a, double val, double* nearest) +int grib_accessor_ibmfloat_t::nearest_smaller_value(double val, double* nearest) { int ret = 0; if (grib_nearest_smaller_ibm_float(val, nearest) == GRIB_INTERNAL_ERROR) { - grib_context_log(a->context, GRIB_LOG_ERROR, "ibm_float:nearest_smaller_value overflow value=%g", val); - grib_dump_content(grib_handle_of_accessor(a), stderr, "wmo", GRIB_DUMP_FLAG_HEXADECIMAL, 0); + grib_context_log(context_, GRIB_LOG_ERROR, "ibm_float:nearest_smaller_value overflow value=%g", val); + grib_dump_content(grib_handle_of_accessor(this), stderr, "wmo", GRIB_DUMP_FLAG_HEXADECIMAL, 0); ret = GRIB_INTERNAL_ERROR; } return ret; diff --git a/src/accessor/grib_accessor_class_ibmfloat.h b/src/accessor/grib_accessor_class_ibmfloat.h index 66bd01132..4ea6ee337 100644 --- a/src/accessor/grib_accessor_class_ibmfloat.h +++ b/src/accessor/grib_accessor_class_ibmfloat.h @@ -15,23 +15,20 @@ class grib_accessor_ibmfloat_t : public grib_accessor_double_t { public: - /* Members defined in ibmfloat */ - grib_arguments* arg; -}; - -class grib_accessor_class_ibmfloat_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_ibmfloat_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_ibmfloat_t() : + grib_accessor_double_t() { class_name_ = "ibmfloat"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_ibmfloat_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; - 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 init(grib_accessor*, const long, grib_arguments*) override; - void update_size(grib_accessor*, size_t) override; - int nearest_smaller_value(grib_accessor*, double, double*) override; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_float(float* val, size_t* len) override; + long byte_count() override; + long byte_offset() override; + long next_offset() override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + void update_size(size_t) override; + int nearest_smaller_value(double, double*) override; + +private: + grib_arguments* arg_; }; diff --git a/src/accessor/grib_accessor_class_ieeefloat.cc b/src/accessor/grib_accessor_class_ieeefloat.cc index 64b08fe50..dc242b72a 100644 --- a/src/accessor/grib_accessor_class_ieeefloat.cc +++ b/src/accessor/grib_accessor_class_ieeefloat.cc @@ -11,37 +11,32 @@ #include "grib_accessor_class_ieeefloat.h" -grib_accessor_class_ieeefloat_t _grib_accessor_class_ieeefloat{ "ieeefloat" }; -grib_accessor_class* grib_accessor_class_ieeefloat = &_grib_accessor_class_ieeefloat; +grib_accessor_ieeefloat_t _grib_accessor_ieeefloat{}; +grib_accessor* grib_accessor_ieeefloat = &_grib_accessor_ieeefloat; - -void grib_accessor_class_ieeefloat_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_ieeefloat_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_double_t::init(a, len, arg); - grib_accessor_ieeefloat_t* self = (grib_accessor_ieeefloat_t*)a; + grib_accessor_double_t::init(len, arg); long count = 0; - self->arg = arg; - a->value_count(&count); - a->length = 4 * count; - Assert(a->length >= 0); + arg_ = arg; + value_count(&count); + length_ = 4 * count; + Assert(length_ >= 0); } -int grib_accessor_class_ieeefloat_t::value_count(grib_accessor* a, long* len) +int grib_accessor_ieeefloat_t::value_count(long* len) { - grib_accessor_ieeefloat_t* self = (grib_accessor_ieeefloat_t*)a; *len = 0; - if (!self->arg) { + if (!arg_) { *len = 1; return 0; } - return grib_get_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), len); + return grib_get_long_internal(grib_handle_of_accessor(this), grib_arguments_get_name(parent_->h, arg_, 0), len); } -int grib_accessor_class_ieeefloat_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_ieeefloat_t::pack_double(const double* val, size_t* len) { - grib_accessor_ieeefloat_t* self = (grib_accessor_ieeefloat_t*)a; - int ret = 0; unsigned long i = 0; unsigned long rlen = (unsigned long)*len; @@ -50,17 +45,17 @@ int grib_accessor_class_ieeefloat_t::pack_double(grib_accessor* a, const double* long off = 0; if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it packs at least 1 value", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s, it packs at least 1 value", name_); *len = 0; return GRIB_ARRAY_TOO_SMALL; } if (rlen == 1) { - off = a->offset * 8; - ret = grib_encode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, grib_ieee_to_long(val[0]), &off, 32); + off = offset_ * 8; + ret = grib_encode_unsigned_long(grib_handle_of_accessor(this)->buffer->data, grib_ieee_to_long(val[0]), &off, 32); if (*len > 1) - grib_context_log(a->context, GRIB_LOG_WARNING, "ieeefloat: Trying to pack %zu values in a scalar %s, packing first value", - *len, a->name); + grib_context_log(context_, GRIB_LOG_WARNING, "ieeefloat: Trying to pack %zu values in a scalar %s, packing first value", + *len, name_); if (ret == GRIB_SUCCESS) len[0] = 1; return ret; @@ -68,24 +63,23 @@ int grib_accessor_class_ieeefloat_t::pack_double(grib_accessor* a, const double* buflen = rlen * 4; - buf = (unsigned char*)grib_context_malloc(a->context, buflen); + buf = (unsigned char*)grib_context_malloc(context_, buflen); for (i = 0; i < rlen; i++) { grib_encode_unsigned_longb(buf, grib_ieee_to_long(val[i]), &off, 32); } - ret = grib_set_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), rlen); + ret = grib_set_long_internal(grib_handle_of_accessor(this), grib_arguments_get_name(parent_->h, arg_, 0), rlen); if (ret == GRIB_SUCCESS) - grib_buffer_replace(a, buf, buflen, 1, 1); + grib_buffer_replace(this, buf, buflen, 1, 1); else *len = 0; - grib_context_free(a->context, buf); + grib_context_free(context_, buf); return ret; } - template static int unpack(grib_accessor* a, T* val, size_t* len) { @@ -94,7 +88,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) long rlen = 0; int err = 0; long i = 0; - long bitp = a->offset * 8; + long bitp = a->offset_ * 8; grib_handle* hand = grib_handle_of_accessor(a); err = a->value_count(&rlen); @@ -102,7 +96,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return err; if (*len < (size_t)rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size (%zu) for %s, it contains %ld values", *len, a->name, rlen); + grib_context_log(a->context_, GRIB_LOG_ERROR, "Wrong size (%zu) for %s, it contains %ld values", *len, a->name_, rlen); *len = 0; return GRIB_ARRAY_TOO_SMALL; } @@ -114,23 +108,23 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_SUCCESS; } -int grib_accessor_class_ieeefloat_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_ieeefloat_t::unpack_double(double* val, size_t* len) { - return unpack(a, val, len); + return unpack(this, val, len); } -int grib_accessor_class_ieeefloat_t::unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_ieeefloat_t::unpack_float(float* val, size_t* len) { - return unpack(a, val, len); + return unpack(this, val, len); } -void grib_accessor_class_ieeefloat_t::update_size(grib_accessor* a, size_t s) +void grib_accessor_ieeefloat_t::update_size(size_t s) { - a->length = (long)s; - Assert(a->length >= 0); + length_ = (long)s; + Assert(length_ >= 0); } -int grib_accessor_class_ieeefloat_t::nearest_smaller_value(grib_accessor* a, double val, double* nearest) +int grib_accessor_ieeefloat_t::nearest_smaller_value(double val, double* nearest) { return grib_nearest_smaller_ieee_float(val, nearest); } diff --git a/src/accessor/grib_accessor_class_ieeefloat.h b/src/accessor/grib_accessor_class_ieeefloat.h index 27536169f..a82f7cce7 100644 --- a/src/accessor/grib_accessor_class_ieeefloat.h +++ b/src/accessor/grib_accessor_class_ieeefloat.h @@ -16,19 +16,17 @@ class grib_accessor_ieeefloat_t : public grib_accessor_double_t { public: - grib_arguments* arg; -}; - -class grib_accessor_class_ieeefloat_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_ieeefloat_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_ieeefloat_t() : + grib_accessor_double_t() { class_name_ = "ieeefloat"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_ieeefloat_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; - void update_size(grib_accessor*, size_t) override; - int nearest_smaller_value(grib_accessor* a, double val, double* nearest) override; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_float(float* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + void update_size(size_t) override; + int nearest_smaller_value(double val, double* nearest) override; + +private: + grib_arguments* arg_; }; diff --git a/src/accessor/grib_accessor_class_ifs_param.cc b/src/accessor/grib_accessor_class_ifs_param.cc index 02d6342ef..a1ba7aef3 100644 --- a/src/accessor/grib_accessor_class_ifs_param.cc +++ b/src/accessor/grib_accessor_class_ifs_param.cc @@ -10,27 +10,24 @@ #include "grib_accessor_class_ifs_param.h" -grib_accessor_class_ifs_param_t _grib_accessor_class_ifs_param{ "ifs_param" }; -grib_accessor_class* grib_accessor_class_ifs_param = &_grib_accessor_class_ifs_param; +grib_accessor_ifs_param_t _grib_accessor_ifs_param{}; +grib_accessor* grib_accessor_ifs_param = &_grib_accessor_ifs_param; - -void grib_accessor_class_ifs_param_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_ifs_param_t::init(const long l, grib_arguments* c) { - grib_accessor_class_gen_t::init(a, l, c); - grib_accessor_ifs_param_t* self = (grib_accessor_ifs_param_t*)a; - int n = 0; + grib_accessor_gen_t::init(l, c); + int n = 0; - self->paramId = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->type = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + paramId_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + type_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); } -int grib_accessor_class_ifs_param_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_ifs_param_t::unpack_long(long* val, size_t* len) { - grib_accessor_ifs_param_t* self = (grib_accessor_ifs_param_t*)a; - int ret = 0; - long paramId = 0; + int ret = 0; + long paramId = 0; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->paramId, ¶mId)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), paramId_, ¶mId)) != GRIB_SUCCESS) return ret; if (paramId > 129000 && paramId < 129999) @@ -45,15 +42,14 @@ int grib_accessor_class_ifs_param_t::unpack_long(grib_accessor* a, long* val, si return ret; } -int grib_accessor_class_ifs_param_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_ifs_param_t::pack_long(const long* val, size_t* len) { - grib_accessor_ifs_param_t* self = (grib_accessor_ifs_param_t*)a; - long type = 0; - long table = 128; - long paramId = *val; + long type = 0; + long table = 128; + long paramId = *val; long param; - grib_get_long(grib_handle_of_accessor(a), self->type, &type); + grib_get_long(grib_handle_of_accessor(this), type_, &type); if (type == 33 || type == 35) { if (paramId > 1000) { @@ -87,10 +83,10 @@ int grib_accessor_class_ifs_param_t::pack_long(grib_accessor* a, const long* val } } - return grib_set_long_internal(grib_handle_of_accessor(a), self->paramId, paramId); + return grib_set_long_internal(grib_handle_of_accessor(this), paramId_, paramId); } -int grib_accessor_class_ifs_param_t::get_native_type(grib_accessor* a) +long grib_accessor_ifs_param_t::get_native_type() { return GRIB_TYPE_LONG; } diff --git a/src/accessor/grib_accessor_class_ifs_param.h b/src/accessor/grib_accessor_class_ifs_param.h index 2beb90925..f59fe3bc0 100644 --- a/src/accessor/grib_accessor_class_ifs_param.h +++ b/src/accessor/grib_accessor_class_ifs_param.h @@ -16,18 +16,15 @@ class grib_accessor_ifs_param_t : public grib_accessor_gen_t { public: - /* Members defined in ifs_param */ - const char* paramId; - const char* type; -}; - -class grib_accessor_class_ifs_param_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_ifs_param_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_ifs_param_t() : + grib_accessor_gen_t() { class_name_ = "ifs_param"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_ifs_param_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; + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* paramId_; + const char* type_; }; diff --git a/src/accessor/grib_accessor_class_iterator.cc b/src/accessor/grib_accessor_class_iterator.cc index 27c2b4242..96e490b62 100644 --- a/src/accessor/grib_accessor_class_iterator.cc +++ b/src/accessor/grib_accessor_class_iterator.cc @@ -10,37 +10,36 @@ #include "grib_accessor_class_iterator.h" -grib_accessor_class_iterator_t _grib_accessor_class_iterator{"iterator"}; -grib_accessor_class* grib_accessor_class_iterator = &_grib_accessor_class_iterator; +grib_accessor_iterator_t _grib_accessor_iterator{}; +grib_accessor* grib_accessor_iterator = &_grib_accessor_iterator; -void grib_accessor_class_iterator_t::init(grib_accessor* a, const long l, grib_arguments* args) +void grib_accessor_iterator_t::init(const long l, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, l, args); - grib_accessor_iterator_t* self = (grib_accessor_iterator_t*)a; - self->args = args; + grib_accessor_gen_t::init(l, args); + args_ = args; } -void grib_accessor_class_iterator_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_iterator_t::dump(grib_dumper* dumper) { /* TODO: pass args */ - grib_dump_label(dumper, a, NULL); + grib_dump_label(dumper, this, NULL); } #if defined(HAVE_GEOGRAPHY) grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int* error) { - grib_handle* h = (grib_handle*)ch; - grib_accessor* a = NULL; + grib_handle* h = (grib_handle*)ch; + grib_accessor* a = NULL; grib_accessor_iterator_t* ita = NULL; - grib_iterator* iter = NULL; - *error = GRIB_NOT_IMPLEMENTED; - a = grib_find_accessor(h, "ITERATOR"); - ita = (grib_accessor_iterator_t*)a; + grib_iterator* iter = NULL; + *error = GRIB_NOT_IMPLEMENTED; + a = grib_find_accessor(h, "ITERATOR"); + ita = (grib_accessor_iterator_t*)a; if (!a) return NULL; - iter = grib_iterator_factory(h, ita->args, flags, error); + iter = grib_iterator_factory(h, ita->args_, flags, error); if (iter) *error = GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_iterator.h b/src/accessor/grib_accessor_class_iterator.h index 03fbdf5b6..dba32e6e5 100644 --- a/src/accessor/grib_accessor_class_iterator.h +++ b/src/accessor/grib_accessor_class_iterator.h @@ -15,16 +15,14 @@ class grib_accessor_iterator_t : public grib_accessor_gen_t { public: - grib_arguments* args; -}; - -class grib_accessor_class_iterator_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_iterator_t(const char* name) : grib_accessor_class_gen_t(name) {}; + grib_accessor_iterator_t() : + grib_accessor_gen_t() { class_name_ = "iterator"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_iterator_t{}; } - void init(grib_accessor* a, const long l, grib_arguments* args) override; - void dump(grib_accessor* a, grib_dumper* dumper) override; + void init(const long l, grib_arguments* args) override; + void dump(grib_dumper* dumper) override; + +public: + grib_arguments* args_; }; -//grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int* error) +// grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int* error) diff --git a/src/accessor/grib_accessor_class_julian_date.cc b/src/accessor/grib_accessor_class_julian_date.cc index 945f4e803..4f7e430d2 100644 --- a/src/accessor/grib_accessor_class_julian_date.cc +++ b/src/accessor/grib_accessor_class_julian_date.cc @@ -10,82 +10,79 @@ #include "grib_accessor_class_julian_date.h" -grib_accessor_class_julian_date_t _grib_accessor_class_julian_date{ "julian_date" }; -grib_accessor_class* grib_accessor_class_julian_date = &_grib_accessor_class_julian_date; +grib_accessor_julian_date_t _grib_accessor_julian_date{}; +grib_accessor* grib_accessor_julian_date = &_grib_accessor_julian_date; - -void grib_accessor_class_julian_date_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_julian_date_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_julian_date_t* self = (grib_accessor_julian_date_t*)a; - int n = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_double_t::init(l, c); + int n = 0; + grib_handle* h = grib_handle_of_accessor(this); - self->year = grib_arguments_get_name(h, c, n++); - self->month = grib_arguments_get_name(h, c, n++); + year_ = grib_arguments_get_name(h, c, n++); + month_ = grib_arguments_get_name(h, c, n++); - self->day = grib_arguments_get_name(h, c, n++); - if (self->day == NULL) { - self->hour = 0; - self->minute = 0; - self->second = 0; - self->ymd = self->year; - self->hms = self->month; - self->year = 0; - self->month = 0; + day_ = grib_arguments_get_name(h, c, n++); + if (day_ == NULL) { + hour_ = 0; + minute_ = 0; + second_ = 0; + ymd_ = year_; + hms_ = month_; + year_ = 0; + month_ = 0; } else { - self->ymd = 0; - self->hms = 0; - self->hour = grib_arguments_get_name(h, c, n++); - self->minute = grib_arguments_get_name(h, c, n++); - self->second = grib_arguments_get_name(h, c, n++); + ymd_ = 0; + hms_ = 0; + hour_ = grib_arguments_get_name(h, c, n++); + minute_ = grib_arguments_get_name(h, c, n++); + second_ = grib_arguments_get_name(h, c, n++); } - self->sep[0] = ' '; - self->sep[1] = 0; - self->sep[2] = 0; - self->sep[3] = 0; - self->sep[4] = 0; + sep_[0] = ' '; + sep_[1] = 0; + sep_[2] = 0; + sep_[3] = 0; + sep_[4] = 0; - a->length = 0; + length_ = 0; } -void grib_accessor_class_julian_date_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_julian_date_t::dump(grib_dumper* dumper) { - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); } -int grib_accessor_class_julian_date_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_julian_date_t::unpack_double(double* val, size_t* len) { int ret = 0; long hour, minute, second; long year, month, day, ymd, hms; - grib_handle* h = grib_handle_of_accessor(a); - grib_accessor_julian_date_t* self = (grib_accessor_julian_date_t*)a; + grib_handle* h = grib_handle_of_accessor(this); - if (self->ymd == NULL) { - ret = grib_get_long(h, self->year, &year); + if (ymd_ == NULL) { + ret = grib_get_long(h, year_, &year); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long(h, self->month, &month); + ret = grib_get_long(h, month_, &month); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long(h, self->day, &day); + ret = grib_get_long(h, day_, &day); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long(h, self->hour, &hour); + ret = grib_get_long(h, hour_, &hour); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long(h, self->minute, &minute); + ret = grib_get_long(h, minute_, &minute); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long(h, self->second, &second); + ret = grib_get_long(h, second_, &second); if (ret != GRIB_SUCCESS) return ret; } else { - ret = grib_get_long(h, self->ymd, &ymd); + ret = grib_get_long(h, ymd_, &ymd); if (ret != GRIB_SUCCESS) return ret; year = ymd / 10000; @@ -94,7 +91,7 @@ int grib_accessor_class_julian_date_t::unpack_double(grib_accessor* a, double* v ymd %= 100; day = ymd; - ret = grib_get_long(h, self->hms, &hms); + ret = grib_get_long(h, hms_, &hms); if (ret != GRIB_SUCCESS) return ret; hour = hms / 10000; @@ -109,50 +106,48 @@ int grib_accessor_class_julian_date_t::unpack_double(grib_accessor* a, double* v return ret; } -int grib_accessor_class_julian_date_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_julian_date_t::pack_double(const double* val, size_t* len) { - grib_accessor_julian_date_t* self = (grib_accessor_julian_date_t*)a; - int ret = 0; long hour = 0; long minute = 0; long second = 0; long ymd = 0, hms = 0; long year, month, day; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); ret = grib_julian_to_datetime(*val, &year, &month, &day, &hour, &minute, &second); if (ret != 0) return ret; - if (self->ymd == NULL) { - ret = grib_set_long(h, self->year, year); + if (ymd_ == NULL) { + ret = grib_set_long(h, year_, year); if (ret != 0) return ret; - ret = grib_set_long(h, self->month, month); + ret = grib_set_long(h, month_, month); if (ret != 0) return ret; - ret = grib_set_long(h, self->day, day); + ret = grib_set_long(h, day_, day); if (ret != 0) return ret; - ret = grib_set_long(h, self->hour, hour); + ret = grib_set_long(h, hour_, hour); if (ret != 0) return ret; - ret = grib_set_long(h, self->minute, minute); + ret = grib_set_long(h, minute_, minute); if (ret != 0) return ret; - ret = grib_set_long(h, self->second, second); + ret = grib_set_long(h, second_, second); if (ret != 0) return ret; } else { ymd = year * 10000 + month * 100 + day; - ret = grib_set_long(h, self->ymd, ymd); + ret = grib_set_long(h, ymd_, ymd); if (ret != 0) return ret; hms = hour * 10000 + minute * 100 + second; - ret = grib_set_long(h, self->hms, hms); + ret = grib_set_long(h, hms_, hms); if (ret != 0) return ret; } @@ -160,41 +155,40 @@ int grib_accessor_class_julian_date_t::pack_double(grib_accessor* a, const doubl return ret; } -int grib_accessor_class_julian_date_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_julian_date_t::unpack_string(char* val, size_t* len) { int ret = 0; long hour, minute, second; long year, month, day, ymd, hms; - grib_accessor_julian_date_t* self = (grib_accessor_julian_date_t*)a; - char* sep = self->sep; - grib_handle* h = grib_handle_of_accessor(a); + char* sep = sep_; + grib_handle* h = grib_handle_of_accessor(this); if (*len < 15) return GRIB_BUFFER_TOO_SMALL; - if (self->ymd == NULL) { - ret = grib_get_long(h, self->year, &year); + if (ymd_ == NULL) { + ret = grib_get_long(h, year_, &year); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long(h, self->month, &month); + ret = grib_get_long(h, month_, &month); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long(h, self->day, &day); + ret = grib_get_long(h, day_, &day); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long(h, self->hour, &hour); + ret = grib_get_long(h, hour_, &hour); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long(h, self->minute, &minute); + ret = grib_get_long(h, minute_, &minute); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long(h, self->second, &second); + ret = grib_get_long(h, second_, &second); if (ret != GRIB_SUCCESS) return ret; } else { - ret = grib_get_long(h, self->ymd, &ymd); + ret = grib_get_long(h, ymd_, &ymd); if (ret != GRIB_SUCCESS) return ret; year = ymd / 10000; @@ -203,7 +197,7 @@ int grib_accessor_class_julian_date_t::unpack_string(grib_accessor* a, char* val ymd %= 100; day = ymd; - ret = grib_get_long(h, self->hms, &hms); + ret = grib_get_long(h, hms_, &hms); if (ret != GRIB_SUCCESS) return ret; hour = hms / 10000; @@ -227,14 +221,13 @@ int grib_accessor_class_julian_date_t::unpack_string(grib_accessor* a, char* val return ret; } -int grib_accessor_class_julian_date_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_julian_date_t::pack_string(const char* val, size_t* len) { int ret = 0; long hour, minute, second; long year, month, day, ymd, hms; - grib_accessor_julian_date_t* self = (grib_accessor_julian_date_t*)a; - char* sep = self->sep; - grib_handle* h = grib_handle_of_accessor(a); + char* sep = sep_; + grib_handle* h = grib_handle_of_accessor(this); ret = sscanf(val, "%04ld%c%02ld%c%02ld%c%02ld%c%02ld%c%02ld", &year, &sep[0], &month, &sep[1], &day, &sep[2], &hour, &sep[3], &minute, &sep[4], &second); @@ -264,34 +257,34 @@ int grib_accessor_class_julian_date_t::pack_string(grib_accessor* a, const char* } } - if (self->ymd == NULL) { - ret = grib_set_long(h, self->year, year); + if (ymd_ == NULL) { + ret = grib_set_long(h, year_, year); if (ret != 0) return ret; - ret = grib_set_long(h, self->month, month); + ret = grib_set_long(h, month_, month); if (ret != 0) return ret; - ret = grib_set_long(h, self->day, day); + ret = grib_set_long(h, day_, day); if (ret != 0) return ret; - ret = grib_set_long(h, self->hour, hour); + ret = grib_set_long(h, hour_, hour); if (ret != 0) return ret; - ret = grib_set_long(h, self->minute, minute); + ret = grib_set_long(h, minute_, minute); if (ret != 0) return ret; - ret = grib_set_long(h, self->second, second); + ret = grib_set_long(h, second_, second); if (ret != 0) return ret; } else { ymd = year * 10000 + month * 100 + day; - ret = grib_set_long(h, self->ymd, ymd); + ret = grib_set_long(h, ymd_, ymd); if (ret != 0) return ret; hms = hour * 10000 + minute * 100 + second; - ret = grib_set_long(h, self->hms, hms); + ret = grib_set_long(h, hms_, hms); if (ret != 0) return ret; } @@ -299,45 +292,45 @@ int grib_accessor_class_julian_date_t::pack_string(grib_accessor* a, const char* return ret; } -int grib_accessor_class_julian_date_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_julian_date_t::unpack_long(long* val, size_t* len) { - grib_context_log(a->context, GRIB_LOG_ERROR, " Cannot unpack %s as long", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, " Cannot unpack %s as long", name_); return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_julian_date_t::pack_long(grib_accessor* a, const long* v, size_t* len) +int grib_accessor_julian_date_t::pack_long(const long* v, size_t* len) { - grib_context_log(a->context, GRIB_LOG_ERROR, " Cannot pack %s as long", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, " Cannot pack %s as long", name_); return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_julian_date_t::pack_expression(grib_accessor* a, grib_expression* e) +int grib_accessor_julian_date_t::pack_expression(grib_expression* e) { size_t len = 1; long lval = 0; double dval = 0; const char* cval = NULL; int ret = 0; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); switch (grib_expression_native_type(hand, e)) { case GRIB_TYPE_LONG: { len = 1; ret = grib_expression_evaluate_long(hand, e, &lval); if (ret != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to set %s as long", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, "Unable to set %s as long", name_); return ret; } /*if (hand->context->debug) - printf("ECCODES DEBUG grib_accessor_class_gen::pack_expression %s %ld\n", a->name,lval);*/ - return a->pack_long(&lval, &len); + printf("ECCODES DEBUG grib_accessor_gen::pack_expression %s %ld\n", name_ ,lval);*/ + return pack_long(&lval, &len); } case GRIB_TYPE_DOUBLE: { len = 1; ret = grib_expression_evaluate_double(hand, e, &dval); /*if (hand->context->debug) - printf("ECCODES DEBUG grib_accessor_class_gen::pack_expression %s %g\n", a->name, dval);*/ - return a->pack_double(&dval, &len); + printf("ECCODES DEBUG grib_accessor_gen::pack_expression %s %g\n", name_ , dval);*/ + return pack_double(&dval, &len); } case GRIB_TYPE_STRING: { @@ -345,13 +338,13 @@ int grib_accessor_class_julian_date_t::pack_expression(grib_accessor* a, grib_ex len = sizeof(tmp); cval = grib_expression_evaluate_string(hand, e, tmp, &len, &ret); if (ret != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to set %s as string", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, "Unable to set %s as string", name_); return ret; } len = strlen(cval); /*if (hand->context->debug) - printf("ECCODES DEBUG grib_accessor_class_gen::pack_expression %s %s\n", a->name, cval);*/ - return a->pack_string(cval, &len); + printf("ECCODES DEBUG grib_accessor_gen::pack_expression %s %s\n", name_ , cval);*/ + return pack_string(cval, &len); } } diff --git a/src/accessor/grib_accessor_class_julian_date.h b/src/accessor/grib_accessor_class_julian_date.h index c52380e10..58ee82d16 100644 --- a/src/accessor/grib_accessor_class_julian_date.h +++ b/src/accessor/grib_accessor_class_julian_date.h @@ -16,30 +16,27 @@ class grib_accessor_julian_date_t : public grib_accessor_double_t { public: - /* Members defined in julian_date */ - const char *year; - const char *month; - const char *day; - const char *hour; - const char *minute; - const char *second; - const char *ymd; - const char *hms; - char sep[5]; -}; - -class grib_accessor_class_julian_date_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_julian_date_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_julian_date_t() : + grib_accessor_double_t() { class_name_ = "julian_date"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_julian_date_t{}; } - 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_expression(grib_accessor*, grib_expression*) 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; - void dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int pack_double(const double* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + int pack_string(const char*, size_t* len) override; + int pack_expression(grib_expression*) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +private: + const char* year_; + const char* month_; + const char* day_; + const char* hour_; + const char* minute_; + const char* second_; + const char* ymd_; + const char* hms_; + char sep_[5]; }; diff --git a/src/accessor/grib_accessor_class_julian_day.cc b/src/accessor/grib_accessor_class_julian_day.cc index a27772e6b..3183ef60a 100644 --- a/src/accessor/grib_accessor_class_julian_day.cc +++ b/src/accessor/grib_accessor_class_julian_day.cc @@ -10,39 +10,35 @@ #include "grib_accessor_class_julian_day.h" -grib_accessor_class_julian_day_t _grib_accessor_class_julian_day{ "julian_day" }; -grib_accessor_class* grib_accessor_class_julian_day = &_grib_accessor_class_julian_day; +grib_accessor_julian_day_t _grib_accessor_julian_day{}; +grib_accessor* grib_accessor_julian_day = &_grib_accessor_julian_day; - -void grib_accessor_class_julian_day_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_julian_day_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_julian_day_t* self = (grib_accessor_julian_day_t*)a; - int n = 0; + grib_accessor_double_t::init(l, c); + int n = 0; - self->date = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->hour = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->minute = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->second = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + date_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + hour_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + minute_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + second_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - a->length = 0; + length_ = 0; } -void grib_accessor_class_julian_day_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_julian_day_t::dump(grib_dumper* dumper) { - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); } -int grib_accessor_class_julian_day_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_julian_day_t::pack_long(const long* val, size_t* len) { const double v = *val; - return pack_double(a, &v, len); + return pack_double(&v, len); } -int grib_accessor_class_julian_day_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_julian_day_t::pack_double(const double* val, size_t* len) { - grib_accessor_julian_day_t* self = (grib_accessor_julian_day_t*)a; - int ret = 0; long hour = 0; long minute = 0; @@ -56,47 +52,47 @@ int grib_accessor_class_julian_day_t::pack_double(grib_accessor* a, const double date = year * 10000 + month * 100 + day; - ret = grib_set_long_internal(grib_handle_of_accessor(a), self->date, date); + ret = grib_set_long_internal(grib_handle_of_accessor(this), date_, date); if (ret != 0) return ret; - ret = grib_set_long_internal(grib_handle_of_accessor(a), self->hour, hour); + ret = grib_set_long_internal(grib_handle_of_accessor(this), hour_, hour); if (ret != 0) return ret; - ret = grib_set_long_internal(grib_handle_of_accessor(a), self->minute, minute); + ret = grib_set_long_internal(grib_handle_of_accessor(this), minute_, minute); if (ret != 0) return ret; - ret = grib_set_long_internal(grib_handle_of_accessor(a), self->second, second); + ret = grib_set_long_internal(grib_handle_of_accessor(this), second_, second); return ret; } -int grib_accessor_class_julian_day_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_julian_day_t::unpack_long(long* val, size_t* len) { + int ret = 0; double v = 0; - int ret = unpack_double(a, &v, len); + ret = unpack_double(&v, len); *val = (long)v; return ret; } -int grib_accessor_class_julian_day_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_julian_day_t::unpack_double(double* val, size_t* len) { int ret = 0; long date, hour, minute, second; long year, month, day; - grib_accessor_julian_day_t* self = (grib_accessor_julian_day_t*)a; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->date, &date); + ret = grib_get_long_internal(grib_handle_of_accessor(this), date_, &date); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->hour, &hour); + ret = grib_get_long_internal(grib_handle_of_accessor(this), hour_, &hour); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->minute, &minute); + ret = grib_get_long_internal(grib_handle_of_accessor(this), minute_, &minute); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->second, &second); + ret = grib_get_long_internal(grib_handle_of_accessor(this), second_, &second); if (ret != GRIB_SUCCESS) return ret; diff --git a/src/accessor/grib_accessor_class_julian_day.h b/src/accessor/grib_accessor_class_julian_day.h index 5d06753b0..eddcf1509 100644 --- a/src/accessor/grib_accessor_class_julian_day.h +++ b/src/accessor/grib_accessor_class_julian_day.h @@ -16,22 +16,19 @@ class grib_accessor_julian_day_t : public grib_accessor_double_t { public: - /* Members defined in julian_day */ - const char *date; - const char *hour; - const char *minute; - const char *second; -}; - -class grib_accessor_class_julian_day_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_julian_day_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_julian_day_t() : + grib_accessor_double_t() { class_name_ = "julian_day"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_julian_day_t{}; } - 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; - 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; + int pack_double(const double* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +private: + const char* date_; + const char* hour_; + const char* minute_; + const char* second_; }; diff --git a/src/accessor/grib_accessor_class_ksec1expver.cc b/src/accessor/grib_accessor_class_ksec1expver.cc index 98cf2a400..bd981bc07 100644 --- a/src/accessor/grib_accessor_class_ksec1expver.cc +++ b/src/accessor/grib_accessor_class_ksec1expver.cc @@ -10,36 +10,35 @@ #include "grib_accessor_class_ksec1expver.h" -grib_accessor_class_ksec1expver_t _grib_accessor_class_ksec1expver{ "ksec1expver" }; -grib_accessor_class* grib_accessor_class_ksec1expver = &_grib_accessor_class_ksec1expver; +grib_accessor_ksec1expver_t _grib_accessor_ksec1expver{}; +grib_accessor* grib_accessor_ksec1expver = &_grib_accessor_ksec1expver; - -void grib_accessor_class_ksec1expver_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_ksec1expver_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_ascii_t::init(a, len, arg); - a->length = len; - Assert(a->length >= 0); + grib_accessor_ascii_t::init(len, arg); + length_ = len; + Assert(length_ >= 0); } -int grib_accessor_class_ksec1expver_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_ksec1expver_t::unpack_long(long* val, size_t* len) { long value = 0; - long pos = a->offset * 8; + long pos = offset_ * 8; char* intc = NULL; char* pTemp = NULL; char expver[5]; char refexpver[5]; - size_t llen = a->length + 1; - Assert(a->length == 4); + size_t llen = length_ + 1; + Assert(length_ == 4); if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", name_, 1); *len = 0; return GRIB_ARRAY_TOO_SMALL; } - value = grib_decode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, &pos, a->length * 8); + value = grib_decode_unsigned_long(grib_handle_of_accessor(this)->buffer->data, &pos, length_ * 8); - a->unpack_string(refexpver, &llen); + unpack_string(refexpver, &llen); /* test for endian */ intc = (char*)&value; pTemp = intc; @@ -69,30 +68,32 @@ int grib_accessor_class_ksec1expver_t::unpack_long(grib_accessor* a, long* val, return GRIB_SUCCESS; } -int grib_accessor_class_ksec1expver_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_ksec1expver_t::pack_string(const char* val, size_t* len) { int i = 0; if (len[0] != 4) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong length for %s. It has to be 4", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong length for %s. It has to be 4", name_); return GRIB_INVALID_KEY_VALUE; } - if (len[0] > (a->length) + 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "pack_string: Wrong size (%lu) for %s, it contains %ld values", - len[0], a->name, a->length + 1); + if (len[0] > (length_) + 1) { + grib_context_log(context_, GRIB_LOG_ERROR, "pack_string: Wrong size (%lu) for %s, it contains %ld values", + len[0], name_, length_ + 1); len[0] = 0; return GRIB_BUFFER_TOO_SMALL; } - for (i = 0; i < a->length; i++) - grib_handle_of_accessor(a)->buffer->data[a->offset + i] = val[i]; + for (i = 0; i < length_; i++) + grib_handle_of_accessor(this)->buffer->data[offset_ + i] = val[i]; return GRIB_SUCCESS; } -int grib_accessor_class_ksec1expver_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_ksec1expver_t::pack_long(const long* val, size_t* len) { - char sval[5] = {0,}; + char sval[5] = { + 0, + }; size_t slen = 4; snprintf(sval, sizeof(sval), "%04d", (int)(*val)); - return pack_string(a, sval, &slen); + return pack_string(sval, &slen); } diff --git a/src/accessor/grib_accessor_class_ksec1expver.h b/src/accessor/grib_accessor_class_ksec1expver.h index 098a40a14..4105a94fd 100644 --- a/src/accessor/grib_accessor_class_ksec1expver.h +++ b/src/accessor/grib_accessor_class_ksec1expver.h @@ -16,16 +16,11 @@ class grib_accessor_ksec1expver_t : public grib_accessor_ascii_t { public: - /* Members defined in ksec1expver */ -}; - -class grib_accessor_class_ksec1expver_t : public grib_accessor_class_ascii_t -{ -public: - grib_accessor_class_ksec1expver_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor_ksec1expver_t() : + grib_accessor_ascii_t() { class_name_ = "ksec1expver"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_ksec1expver_t{}; } - 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_long(grib_accessor*, long* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int pack_long(const long* val, size_t* len) override; + int pack_string(const char*, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_label.cc b/src/accessor/grib_accessor_class_label.cc index 58749ea43..01b58141b 100644 --- a/src/accessor/grib_accessor_class_label.cc +++ b/src/accessor/grib_accessor_class_label.cc @@ -10,34 +10,33 @@ #include "grib_accessor_class_label.h" -grib_accessor_class_label_t _grib_accessor_class_label{ "label" }; -grib_accessor_class* grib_accessor_class_label = &_grib_accessor_class_label; +grib_accessor_label_t _grib_accessor_label{}; +grib_accessor* grib_accessor_label = &_grib_accessor_label; - -void grib_accessor_class_label_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_label_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; - a->length = 0; + grib_accessor_gen_t::init(len, arg); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + length_ = 0; } -void grib_accessor_class_label_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_label_t::dump(grib_dumper* dumper) { - grib_dump_label(dumper, a, NULL); + grib_dump_label(dumper, this, NULL); } -int grib_accessor_class_label_t::get_native_type(grib_accessor* a) +long grib_accessor_label_t::get_native_type() { return GRIB_TYPE_LABEL; } -int grib_accessor_class_label_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_label_t::unpack_string(char* val, size_t* len) { - size_t vlen = strlen(a->name); + size_t vlen = strlen(name_); if (vlen > *len) return GRIB_BUFFER_TOO_SMALL; *len = vlen; - strcpy(val, a->name); + strcpy(val, name_); return GRIB_SUCCESS; } diff --git a/src/accessor/grib_accessor_class_label.h b/src/accessor/grib_accessor_class_label.h index 59590e77c..4f1f01797 100644 --- a/src/accessor/grib_accessor_class_label.h +++ b/src/accessor/grib_accessor_class_label.h @@ -16,16 +16,11 @@ class grib_accessor_label_t : public grib_accessor_gen_t { public: - /* Members defined in label */ -}; - -class grib_accessor_class_label_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_label_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_label_t() : + grib_accessor_gen_t() { class_name_ = "label"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_label_t{}; } - int get_native_type(grib_accessor*) override; - int unpack_string(grib_accessor*, char*, size_t* len) override; - void dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int unpack_string(char*, size_t* len) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_latitudes.cc b/src/accessor/grib_accessor_class_latitudes.cc index d67d9f257..53a37c2a6 100644 --- a/src/accessor/grib_accessor_class_latitudes.cc +++ b/src/accessor/grib_accessor_class_latitudes.cc @@ -11,8 +11,8 @@ #include "grib_accessor_class_latitudes.h" -grib_accessor_class_latitudes_t _grib_accessor_class_latitudes{ "latitudes" }; -grib_accessor_class* grib_accessor_class_latitudes = &_grib_accessor_class_latitudes; +grib_accessor_latitudes_t _grib_accessor_latitudes{}; +grib_accessor* grib_accessor_latitudes = &_grib_accessor_latitudes; static int get_distinct(grib_accessor* a, double** val, long* len); static int compare_doubles(const void* a, const void* b, int ascending) @@ -22,11 +22,11 @@ static int compare_doubles(const void* a, const void* b, int ascending) const double* arg2 = (double*)b; if (ascending) { if (*arg1 < *arg2) - return -1; // Smaller values come before larger ones + return -1; // Smaller values come before larger ones } else { if (*arg1 > *arg2) - return -1; // Larger values come before smaller ones + return -1; // Larger values come before smaller ones } if (*arg1 == *arg2) return 0; @@ -44,58 +44,56 @@ static int compare_doubles_descending(const void* a, const void* b) return compare_doubles(a, b, 0); } -void grib_accessor_class_latitudes_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_latitudes_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_latitudes_t* self = (grib_accessor_latitudes_t*)a; + grib_accessor_double_t::init(l, c); int n = 0; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->distinct = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); - self->save = 0; + values_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + distinct_ = grib_arguments_get_long(grib_handle_of_accessor(this), c, n++); + save_ = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_latitudes_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_latitudes_t::unpack_double(double* val, size_t* len) { - grib_context* c = a->context; - grib_accessor_latitudes_t* self = (grib_accessor_latitudes_t*)a; - int ret = 0; - double* v = val; - double dummyLon = 0; - size_t size = 0; - long count = 0; - grib_iterator* iter = NULL; + grib_context* c = context_; + int ret = 0; + double* v = val; + double dummyLon = 0; + size_t size = 0; + long count = 0; + grib_iterator* iter = NULL; - self->save = 1; - ret = value_count(a, &count); + save_ = 1; + ret = value_count(&count); if (ret) return ret; size = count; if (*len < size) { - // self->lats are computed in value_count so must free - if (self->lats) { - grib_context_free(c, self->lats); - self->lats = NULL; + // lats_ are computed in value_count so must free + if (lats_) { + grib_context_free(c, lats_); + lats_ = NULL; } return GRIB_ARRAY_TOO_SMALL; } - self->save = 0; + save_ = 0; - // self->lats are computed in value_count - if (self->lats) { + // lats_ are computed in value_count + if (lats_) { int i; - *len = self->size; + *len = size_; for (i = 0; i < size; i++) - val[i] = self->lats[i]; - grib_context_free(c, self->lats); - self->lats = NULL; - self->size = 0; + val[i] = lats_[i]; + grib_context_free(c, lats_); + lats_ = NULL; + size_ = 0; return GRIB_SUCCESS; } // ECC-1525 Performance: We do not need the values to be decoded - iter = grib_iterator_new(grib_handle_of_accessor(a), GRIB_GEOITERATOR_NO_VALUES, &ret); + iter = grib_iterator_new(grib_handle_of_accessor(this), GRIB_GEOITERATOR_NO_VALUES, &ret); if (ret != GRIB_SUCCESS) { grib_iterator_delete(iter); grib_context_log(c, GRIB_LOG_ERROR, "latitudes: Unable to create iterator"); @@ -110,18 +108,17 @@ int grib_accessor_class_latitudes_t::unpack_double(grib_accessor* a, double* val return ret; } -int grib_accessor_class_latitudes_t::value_count(grib_accessor* a, long* len) +int grib_accessor_latitudes_t::value_count(long* len) { - grib_accessor_latitudes_t* self = (grib_accessor_latitudes_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - grib_context* c = a->context; - double* val = NULL; + grib_handle* h = grib_handle_of_accessor(this); + grib_context* c = context_; + double* val = NULL; int ret; size_t size; *len = 0; - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) { - grib_context_log(h->context, GRIB_LOG_ERROR, "latitudes: Unable to get size of %s", self->values); + if ((ret = grib_get_size(h, values_, &size)) != GRIB_SUCCESS) { + grib_context_log(h->context, GRIB_LOG_ERROR, "latitudes: Unable to get size of %s", values_); return ret; } *len = size; @@ -133,13 +130,13 @@ int grib_accessor_class_latitudes_t::value_count(grib_accessor* a, long* len) *len = numberOfDataPoints; } - if (self->distinct) { - ret = get_distinct(a, &val, len); + if (distinct_) { + ret = get_distinct(this, &val, len); if (ret != GRIB_SUCCESS) return ret; - if (self->save) { - self->lats = val; - self->size = *len; + if (save_) { + lats_ = val; + size_ = *len; } else { grib_context_free(c, val); @@ -156,11 +153,11 @@ static int get_distinct(grib_accessor* a, double** val, long* len) double* v = NULL; double* v1 = NULL; double dummyLon = 0; - int ret = GRIB_SUCCESS; + int ret = GRIB_SUCCESS; int i; - long jScansPositively = 0; // default: north to south + long jScansPositively = 0; // default: north to south size_t size = *len; - grib_context* c = a->context; + grib_context* c = a->context_; // Performance: We do not need the values to be decoded grib_iterator* iter = grib_iterator_new(grib_handle_of_accessor(a), GRIB_GEOITERATOR_NO_VALUES, &ret); @@ -185,12 +182,12 @@ static int get_distinct(grib_accessor* a, double** val, long* len) return ret; if (jScansPositively) { if (!is_sorted_ascending(v, size)) { - qsort(v, *len, sizeof(double), &compare_doubles_ascending); //South to North + qsort(v, *len, sizeof(double), &compare_doubles_ascending); // South to North } } else { if (!is_sorted_descending(v, size)) { - qsort(v, *len, sizeof(double), &compare_doubles_descending); //North to South + qsort(v, *len, sizeof(double), &compare_doubles_descending); // North to South } } @@ -207,7 +204,7 @@ static int get_distinct(grib_accessor* a, double** val, long* len) for (i = 1; i < *len; i++) { if (v[i] != prev) { prev = v[i]; - v1[count] = prev; // Value different from previous so store it + v1[count] = prev; // Value different from previous so store it count++; } } diff --git a/src/accessor/grib_accessor_class_latitudes.h b/src/accessor/grib_accessor_class_latitudes.h index cb1f6ada8..cdf852cbd 100644 --- a/src/accessor/grib_accessor_class_latitudes.h +++ b/src/accessor/grib_accessor_class_latitudes.h @@ -16,20 +16,17 @@ class grib_accessor_latitudes_t : public grib_accessor_double_t { public: - /* Members defined in latitudes */ - const char* values; - long distinct; - double* lats; - long size; - int save; -}; - -class grib_accessor_class_latitudes_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_latitudes_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_latitudes_t() : + grib_accessor_double_t() { class_name_ = "latitudes"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_latitudes_t{}; } - 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; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* values_; + long distinct_; + double* lats_ = nullptr; + long size_; + int save_; }; diff --git a/src/accessor/grib_accessor_class_latlon_increment.cc b/src/accessor/grib_accessor_class_latlon_increment.cc index 3ab3a07a0..ead5d04da 100644 --- a/src/accessor/grib_accessor_class_latlon_increment.cc +++ b/src/accessor/grib_accessor_class_latlon_increment.cc @@ -10,33 +10,30 @@ #include "grib_accessor_class_latlon_increment.h" -grib_accessor_class_latlon_increment_t _grib_accessor_class_latlon_increment{ "latlon_increment" }; -grib_accessor_class* grib_accessor_class_latlon_increment = &_grib_accessor_class_latlon_increment; +grib_accessor_latlon_increment_t _grib_accessor_latlon_increment{}; +grib_accessor* grib_accessor_latlon_increment = &_grib_accessor_latlon_increment; - -void grib_accessor_class_latlon_increment_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_latlon_increment_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_latlon_increment_t* self = (grib_accessor_latlon_increment_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_accessor_double_t::init(l, c); + int n = 0; + grib_handle* hand = grib_handle_of_accessor(this); - int n = 0; - self->directionIncrementGiven = grib_arguments_get_name(hand, c, n++); - self->directionIncrement = grib_arguments_get_name(hand, c, n++); - self->scansPositively = grib_arguments_get_name(hand, c, n++); - self->first = grib_arguments_get_name(hand, c, n++); - self->last = grib_arguments_get_name(hand, c, n++); - self->numberOfPoints = grib_arguments_get_name(hand, c, n++); - self->angleMultiplier = grib_arguments_get_name(hand, c, n++); - self->angleDivisor = grib_arguments_get_name(hand, c, n++); - self->isLongitude = grib_arguments_get_long(hand, c, n++); + directionIncrementGiven_ = grib_arguments_get_name(hand, c, n++); + directionIncrement_ = grib_arguments_get_name(hand, c, n++); + scansPositively_ = grib_arguments_get_name(hand, c, n++); + first_ = grib_arguments_get_name(hand, c, n++); + last_ = grib_arguments_get_name(hand, c, n++); + numberOfPoints_ = grib_arguments_get_name(hand, c, n++); + angleMultiplier_ = grib_arguments_get_name(hand, c, n++); + angleDivisor_ = grib_arguments_get_name(hand, c, n++); + isLongitude_ = grib_arguments_get_long(hand, c, n++); } -int grib_accessor_class_latlon_increment_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_latlon_increment_t::unpack_double(double* val, size_t* len) { - grib_accessor_latlon_increment_t* self = (grib_accessor_latlon_increment_t*)a; - int ret = GRIB_SUCCESS; - grib_handle* hand = grib_handle_of_accessor(a); + int ret = 0; + grib_handle* hand = grib_handle_of_accessor(this); long directionIncrementGiven = 0; long directionIncrement = 0; @@ -50,31 +47,31 @@ int grib_accessor_class_latlon_increment_t::unpack_double(grib_accessor* a, doub if (*len < 1) return GRIB_ARRAY_TOO_SMALL; - if ((ret = grib_get_long_internal(hand, self->directionIncrementGiven, &directionIncrementGiven)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, directionIncrementGiven_, &directionIncrementGiven)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->scansPositively, &scansPositively)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, scansPositively_, &scansPositively)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->directionIncrement, &directionIncrement)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, directionIncrement_, &directionIncrement)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(hand, self->first, &first)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(hand, first_, &first)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(hand, self->last, &last)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(hand, last_, &last)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->numberOfPoints, &numberOfPoints)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, numberOfPoints_, &numberOfPoints)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->angleMultiplier, &angleMultiplier)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, angleMultiplier_, &angleMultiplier)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->angleDivisor, &angleDivisor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, angleDivisor_, &angleDivisor)) != GRIB_SUCCESS) return ret; - if (self->isLongitude) { + if (isLongitude_) { if (last < first && scansPositively) last += 360; /*if (last > first && !scansPositively) first-=360;*/ @@ -83,7 +80,7 @@ int grib_accessor_class_latlon_increment_t::unpack_double(grib_accessor* a, doub if (!directionIncrementGiven && numberOfPoints != GRIB_MISSING_LONG) { if (numberOfPoints < 2) { /* We cannot compute the increment if we don't have enough points! */ - grib_context_log(a->parent->h->context, GRIB_LOG_ERROR, + grib_context_log(parent_->h->context, GRIB_LOG_ERROR, "Cannot compute lat/lon increments. Not enough points!"); return GRIB_GEOCALCULUS_PROBLEM; } @@ -119,12 +116,11 @@ int grib_accessor_class_latlon_increment_t::unpack_double(grib_accessor* a, doub return ret; } -int grib_accessor_class_latlon_increment_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_latlon_increment_t::pack_double(const double* val, size_t* len) { - grib_accessor_latlon_increment_t* self = (grib_accessor_latlon_increment_t*)a; - int ret = GRIB_SUCCESS; - long codedNumberOfPoints = 0; - grib_handle* hand = grib_handle_of_accessor(a); + int ret = 0; + long codedNumberOfPoints = 0; + grib_handle* hand = grib_handle_of_accessor(this); long directionIncrementGiven = 0; long directionIncrement = 0; @@ -137,30 +133,30 @@ int grib_accessor_class_latlon_increment_t::pack_double(grib_accessor* a, const long scansPositively = 0; double directionIncrementDouble = 0; - ret = grib_get_double_internal(hand, self->first, &first); + ret = grib_get_double_internal(hand, first_, &first); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_double_internal(hand, self->last, &last); + ret = grib_get_double_internal(hand, last_, &last); if (ret != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->directionIncrementGiven, &directionIncrementGiven)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, directionIncrementGiven_, &directionIncrementGiven)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->numberOfPoints, &numberOfPoints)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, numberOfPoints_, &numberOfPoints)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->scansPositively, &scansPositively)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, scansPositively_, &scansPositively)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->angleMultiplier, &angleMultiplier)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, angleMultiplier_, &angleMultiplier)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->angleDivisor, &angleDivisor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, angleDivisor_, &angleDivisor)) != GRIB_SUCCESS) return ret; - if (self->isLongitude) { + if (isLongitude_) { if (last < first && scansPositively) last += 360; if (last > first && !scansPositively) @@ -184,16 +180,16 @@ int grib_accessor_class_latlon_increment_t::pack_double(grib_accessor* a, const } } - // ret = grib_set_long_internal(hand, self->numberOfPoints,numberOfPoints); - // if(ret) grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s cannot pack value for %s error %d \n", a->name, self->numberOfPoints, ret); + // ret = grib_set_long_internal(hand, numberOfPoints_ ,numberOfPoints); + // if(ret) grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s cannot pack value for %s error %d \n", a->name, numberOfPoints_ , ret); - grib_get_long_internal(hand, self->numberOfPoints, &codedNumberOfPoints); + grib_get_long_internal(hand, numberOfPoints_, &codedNumberOfPoints); - ret = grib_set_long_internal(hand, self->directionIncrement, directionIncrement); + ret = grib_set_long_internal(hand, directionIncrement_, directionIncrement); if (ret) return ret; - ret = grib_set_long_internal(hand, self->directionIncrementGiven, directionIncrementGiven); + ret = grib_set_long_internal(hand, directionIncrementGiven_, directionIncrementGiven); if (ret) return ret; @@ -203,12 +199,12 @@ int grib_accessor_class_latlon_increment_t::pack_double(grib_accessor* a, const return GRIB_SUCCESS; } -int grib_accessor_class_latlon_increment_t::is_missing(grib_accessor* a) +int grib_accessor_latlon_increment_t::is_missing() { size_t len = 1; double val = 0; - unpack_double(a, &val, &len); + unpack_double(&val, &len); return (val == GRIB_MISSING_DOUBLE); } diff --git a/src/accessor/grib_accessor_class_latlon_increment.h b/src/accessor/grib_accessor_class_latlon_increment.h index 8dfa7cb93..b9de0ca54 100644 --- a/src/accessor/grib_accessor_class_latlon_increment.h +++ b/src/accessor/grib_accessor_class_latlon_increment.h @@ -16,25 +16,22 @@ class grib_accessor_latlon_increment_t : public grib_accessor_double_t { public: - /* Members defined in latlon_increment */ - const char* directionIncrementGiven; - const char* directionIncrement; - const char* scansPositively; - const char* first; - const char* last; - const char* numberOfPoints; - const char* angleMultiplier; - const char* angleDivisor; - long isLongitude; -}; - -class grib_accessor_class_latlon_increment_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_latlon_increment_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_latlon_increment_t() : + grib_accessor_double_t() { class_name_ = "latlon_increment"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_latlon_increment_t{}; } - int is_missing(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; - void init(grib_accessor*, const long, grib_arguments*) override; + int is_missing() override; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* directionIncrementGiven_; + const char* directionIncrement_; + const char* scansPositively_; + const char* first_; + const char* last_; + const char* numberOfPoints_; + const char* angleMultiplier_; + const char* angleDivisor_; + long isLongitude_; }; diff --git a/src/accessor/grib_accessor_class_latlonvalues.cc b/src/accessor/grib_accessor_class_latlonvalues.cc index 4b80ca32a..5dd250272 100644 --- a/src/accessor/grib_accessor_class_latlonvalues.cc +++ b/src/accessor/grib_accessor_class_latlonvalues.cc @@ -11,37 +11,35 @@ #include "grib_accessor_class_latlonvalues.h" -grib_accessor_class_latlonvalues_t _grib_accessor_class_latlonvalues{ "latlonvalues" }; -grib_accessor_class* grib_accessor_class_latlonvalues = &_grib_accessor_class_latlonvalues; +grib_accessor_latlonvalues_t _grib_accessor_latlonvalues{}; +grib_accessor* grib_accessor_latlonvalues = &_grib_accessor_latlonvalues; - -void grib_accessor_class_latlonvalues_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_latlonvalues_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_latlonvalues_t* self = (grib_accessor_latlonvalues_t*)a; + grib_accessor_double_t::init(l, c); int n = 0; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + values_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_latlonvalues_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_latlonvalues_t::unpack_double(double* val, size_t* len) { - grib_context* c = a->context; + grib_context* c = context_; int err = 0; double* v = val; double lat, lon, value; size_t size = 0; long count = 0; - grib_iterator* iter = grib_iterator_new(grib_handle_of_accessor(a), 0, &err); + grib_iterator* iter = grib_iterator_new(grib_handle_of_accessor(this), 0, &err); if (err) { grib_iterator_delete(iter); grib_context_log(c, GRIB_LOG_ERROR, "latlonvalues: Unable to create iterator"); return err; } - err = value_count(a, &count); + err = value_count(&count); if (err) return err; size = count; @@ -63,14 +61,13 @@ int grib_accessor_class_latlonvalues_t::unpack_double(grib_accessor* a, double* return GRIB_SUCCESS; } -int grib_accessor_class_latlonvalues_t::value_count(grib_accessor* a, long* count) +int grib_accessor_latlonvalues_t::value_count(long* count) { - grib_accessor_latlonvalues_t* self = (grib_accessor_latlonvalues_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = GRIB_SUCCESS; + grib_handle* h = grib_handle_of_accessor(this); + int ret = GRIB_SUCCESS; size_t size; - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) { - grib_context_log(h->context, GRIB_LOG_ERROR, "latlonvalues: Unable to get size of %s", self->values); + if ((ret = grib_get_size(h, values_, &size)) != GRIB_SUCCESS) { + grib_context_log(h->context, GRIB_LOG_ERROR, "latlonvalues: Unable to get size of %s", values_); return ret; } diff --git a/src/accessor/grib_accessor_class_latlonvalues.h b/src/accessor/grib_accessor_class_latlonvalues.h index 7328688c6..0fb9d8621 100644 --- a/src/accessor/grib_accessor_class_latlonvalues.h +++ b/src/accessor/grib_accessor_class_latlonvalues.h @@ -16,16 +16,13 @@ class grib_accessor_latlonvalues_t : public grib_accessor_double_t { public: - /* Members defined in latlonvalues */ - const char* values; -}; - -class grib_accessor_class_latlonvalues_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_latlonvalues_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_latlonvalues_t() : + grib_accessor_double_t() { class_name_ = "latlonvalues"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_latlonvalues_t{}; } - 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; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* values_; }; diff --git a/src/accessor/grib_accessor_class_library_version.cc b/src/accessor/grib_accessor_class_library_version.cc index e0f1ee1da..0a31d1df3 100644 --- a/src/accessor/grib_accessor_class_library_version.cc +++ b/src/accessor/grib_accessor_class_library_version.cc @@ -10,13 +10,14 @@ #include "grib_accessor_class_library_version.h" -grib_accessor_class_library_version_t _grib_accessor_class_library_version{ "library_version" }; -grib_accessor_class* grib_accessor_class_library_version = &_grib_accessor_class_library_version; +grib_accessor_library_version_t _grib_accessor_library_version{}; +grib_accessor* grib_accessor_library_version = &_grib_accessor_library_version; - -int grib_accessor_class_library_version_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_library_version_t::unpack_string(char* val, size_t* len) { - char result[30] = {0,}; + char result[30] = { + 0, + }; size_t size = 0; int major = ECCODES_MAJOR_VERSION; @@ -35,13 +36,13 @@ int grib_accessor_class_library_version_t::unpack_string(grib_accessor* a, char* return GRIB_SUCCESS; } -int grib_accessor_class_library_version_t::value_count(grib_accessor* a, long* count) +int grib_accessor_library_version_t::value_count(long* count) { *count = 1; return 0; } -size_t grib_accessor_class_library_version_t::string_length(grib_accessor* a) +size_t grib_accessor_library_version_t::string_length() { return 255; } diff --git a/src/accessor/grib_accessor_class_library_version.h b/src/accessor/grib_accessor_class_library_version.h index cb2a45f04..659bf283f 100644 --- a/src/accessor/grib_accessor_class_library_version.h +++ b/src/accessor/grib_accessor_class_library_version.h @@ -16,15 +16,10 @@ class grib_accessor_library_version_t : public grib_accessor_ascii_t { public: - /* Members defined in library_version */ -}; - -class grib_accessor_class_library_version_t : public grib_accessor_class_ascii_t -{ -public: - grib_accessor_class_library_version_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor_library_version_t() : + grib_accessor_ascii_t() { class_name_ = "library_version"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_library_version_t{}; } - int unpack_string(grib_accessor*, char*, size_t* len) override; - size_t string_length(grib_accessor*) override; - int value_count(grib_accessor*, long*) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + int value_count(long*) override; }; diff --git a/src/accessor/grib_accessor_class_local_definition.cc b/src/accessor/grib_accessor_class_local_definition.cc index 833bc8f08..e8da63455 100644 --- a/src/accessor/grib_accessor_class_local_definition.cc +++ b/src/accessor/grib_accessor_class_local_definition.cc @@ -10,40 +10,34 @@ #include "grib_accessor_class_local_definition.h" -grib_accessor_class_local_definition_t _grib_accessor_class_local_definition{ "local_definition" }; -grib_accessor_class* grib_accessor_class_local_definition = &_grib_accessor_class_local_definition; +grib_accessor_local_definition_t _grib_accessor_local_definition{}; +grib_accessor* grib_accessor_local_definition = &_grib_accessor_local_definition; - -void grib_accessor_class_local_definition_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_local_definition_t::init(const long l, grib_arguments* c) { - grib_accessor_class_unsigned_t::init(a, l, c); - grib_accessor_local_definition_t* self = (grib_accessor_local_definition_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_unsigned_t::init(l, c); + grib_handle* hand = grib_handle_of_accessor(this); + int n = 0; - self->grib2LocalSectionNumber = grib_arguments_get_name(hand, c, n++); - self->productDefinitionTemplateNumber = grib_arguments_get_name(hand, c, n++); - self->productDefinitionTemplateNumberInternal = grib_arguments_get_name(hand, c, n++); - self->type = grib_arguments_get_name(hand, c, n++); - self->stream = grib_arguments_get_name(hand, c, n++); - self->the_class = grib_arguments_get_name(hand, c, n++); - self->eps = grib_arguments_get_name(hand, c, n++); - self->stepType = grib_arguments_get_name(hand, c, n++); - self->derivedForecast = grib_arguments_get_name(hand, c, n++); + grib2LocalSectionNumber_ = grib_arguments_get_name(hand, c, n++); + productDefinitionTemplateNumber_ = grib_arguments_get_name(hand, c, n++); + productDefinitionTemplateNumberInternal_ = grib_arguments_get_name(hand, c, n++); + type_ = grib_arguments_get_name(hand, c, n++); + stream_ = grib_arguments_get_name(hand, c, n++); + the_class_ = grib_arguments_get_name(hand, c, n++); + eps_ = grib_arguments_get_name(hand, c, n++); + stepType_ = grib_arguments_get_name(hand, c, n++); + derivedForecast_ = grib_arguments_get_name(hand, c, n++); } -int grib_accessor_class_local_definition_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_local_definition_t::unpack_long(long* val, size_t* len) { - grib_accessor_local_definition_t* self = (grib_accessor_local_definition_t*)a; - - return grib_get_long(grib_handle_of_accessor(a), self->grib2LocalSectionNumber, val); + return grib_get_long(grib_handle_of_accessor(this), grib2LocalSectionNumber_, val); } -int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_local_definition_t::pack_long(const long* val, size_t* len) { - grib_accessor_local_definition_t* self = (grib_accessor_local_definition_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - + grib_handle* hand = grib_handle_of_accessor(this); long productDefinitionTemplateNumber = -1; long productDefinitionTemplateNumberInternal = -1; long productDefinitionTemplateNumberNew = -1; @@ -54,7 +48,9 @@ int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const lo long eps = -1; long chemical = -1; long aerosol = -1; - char stepType[15] = {0,}; + char stepType[15] = { + 0, + }; size_t slen = 15; int localDefinitionNumber = *val; int isInstant = 0; @@ -66,22 +62,22 @@ int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const lo Assert(editionNumber != 1); } - if (grib_get_long(hand, self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber) != GRIB_SUCCESS) + if (grib_get_long(hand, productDefinitionTemplateNumber_, &productDefinitionTemplateNumber) != GRIB_SUCCESS) tooEarly = 1; - grib_get_long(hand, self->productDefinitionTemplateNumberInternal, &productDefinitionTemplateNumberInternal); - grib_get_long(hand, self->type, &type); - grib_get_long(hand, self->stream, &stream); - grib_get_long(hand, self->the_class, &the_class); - grib_get_long(hand, self->eps, &eps); - grib_get_string(hand, self->stepType, stepType, &slen); + grib_get_long(hand, productDefinitionTemplateNumberInternal_, &productDefinitionTemplateNumberInternal); + grib_get_long(hand, type_, &type); + grib_get_long(hand, stream_, &stream); + grib_get_long(hand, the_class_, &the_class); + grib_get_long(hand, eps_, &eps); + grib_get_string(hand, stepType_, stepType, &slen); if (!strcmp(stepType, "instant")) isInstant = 1; - grib_get_long(hand, self->grib2LocalSectionNumber, &grib2LocalSectionNumber); + grib_get_long(hand, grib2LocalSectionNumber_, &grib2LocalSectionNumber); grib_get_long(hand, "is_chemical", &chemical); grib_get_long(hand, "is_aerosol", &aerosol); if (chemical == 1 && aerosol == 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Parameter cannot be both chemical and aerosol!"); + grib_context_log(context_, GRIB_LOG_ERROR, "Parameter cannot be both chemical and aerosol!"); return GRIB_ENCODING_ERROR; } @@ -100,7 +96,7 @@ int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const lo break; case 300: - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "Invalid localDefinitionNumber %d. This local definition has been deprecated.", localDefinitionNumber); return GRIB_ENCODING_ERROR; @@ -205,7 +201,7 @@ int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const lo default: #ifdef DEBUG // In test & development mode, fail so we remember to adjust PDTN - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "grib_accessor_local_definition_t: Invalid localDefinitionNumber %d", localDefinitionNumber); return GRIB_ENCODING_ERROR; #endif @@ -219,25 +215,25 @@ int grib_accessor_class_local_definition_t::pack_long(grib_accessor* a, const lo productDefinitionTemplateNumberNew = -1; // disable PDT selection } - if (productDefinitionTemplateNumberNew >=0 && productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) { - if (a->context->debug) { - fprintf(stderr, "ECCODES DEBUG %s %s: ldNumber=%d, newPDTN=%ld\n", a->cclass->name, __func__, + if (productDefinitionTemplateNumberNew >= 0 && productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) { + if (context_->debug) { + fprintf(stderr, "ECCODES DEBUG grib_accessor_local_definition_t: ldNumber=%d, newPDTN=%ld\n", localDefinitionNumber, productDefinitionTemplateNumberNew); } if (tooEarly) - grib_set_long(hand, self->productDefinitionTemplateNumberInternal, productDefinitionTemplateNumberNew); + grib_set_long(hand, productDefinitionTemplateNumberInternal_, productDefinitionTemplateNumberNew); else - grib_set_long(hand, self->productDefinitionTemplateNumber, productDefinitionTemplateNumberNew); + grib_set_long(hand, productDefinitionTemplateNumber_, productDefinitionTemplateNumberNew); } if (derivedForecast >= 0) - grib_set_long(hand, self->derivedForecast, derivedForecast); + grib_set_long(hand, derivedForecast_, derivedForecast); - grib_set_long(hand, self->grib2LocalSectionNumber, *val); + grib_set_long(hand, grib2LocalSectionNumber_, *val); return 0; } -int grib_accessor_class_local_definition_t::value_count(grib_accessor* a, long* count) +int grib_accessor_local_definition_t::value_count(long* count) { *count = 1; return 0; diff --git a/src/accessor/grib_accessor_class_local_definition.h b/src/accessor/grib_accessor_class_local_definition.h index f91ebbef4..a665a8f88 100644 --- a/src/accessor/grib_accessor_class_local_definition.h +++ b/src/accessor/grib_accessor_class_local_definition.h @@ -16,25 +16,22 @@ class grib_accessor_local_definition_t : public grib_accessor_unsigned_t { public: - /* Members defined in local_definition */ - const char* productDefinitionTemplateNumber; - const char* productDefinitionTemplateNumberInternal; - const char* grib2LocalSectionNumber; - const char* type; - const char* stream; - const char* the_class; - const char* eps; - const char* stepType; - const char* derivedForecast; -}; - -class grib_accessor_class_local_definition_t : public grib_accessor_class_unsigned_t -{ -public: - grib_accessor_class_local_definition_t(const char* name) : grib_accessor_class_unsigned_t(name) {} + grib_accessor_local_definition_t() : + grib_accessor_unsigned_t() { class_name_ = "local_definition"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_local_definition_t{}; } - int pack_long(grib_accessor*, const long* val, size_t* len) override; - 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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* productDefinitionTemplateNumber_; + const char* productDefinitionTemplateNumberInternal_; + const char* grib2LocalSectionNumber_; + const char* type_; + const char* stream_; + const char* the_class_; + const char* eps_; + const char* stepType_; + const char* derivedForecast_; }; diff --git a/src/accessor/grib_accessor_class_long.cc b/src/accessor/grib_accessor_class_long.cc index 04f6908be..5fcf00106 100644 --- a/src/accessor/grib_accessor_class_long.cc +++ b/src/accessor/grib_accessor_class_long.cc @@ -10,39 +10,40 @@ #include "grib_accessor_class_long.h" -grib_accessor_class_long_t _grib_accessor_class_long{"long"}; -grib_accessor_class* grib_accessor_class_long = &_grib_accessor_class_long; +grib_accessor_long_t _grib_accessor_long{}; +grib_accessor* grib_accessor_long = &_grib_accessor_long; -void grib_accessor_class_long_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_long_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); + grib_accessor_gen_t::init(len, arg); } -int grib_accessor_class_long_t::get_native_type(grib_accessor* a) +long grib_accessor_long_t::get_native_type() { return GRIB_TYPE_LONG; } -void grib_accessor_class_long_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_long_t::dump(grib_dumper* dumper) { - grib_dump_long(dumper, a, NULL); + grib_dump_long(dumper, this, NULL); } -int grib_accessor_class_long_t::unpack_string(grib_accessor* a, char* v, size_t* len) +int grib_accessor_long_t::unpack_string(char* v, size_t* len) { long val = 0; size_t l = 1; char repres[1024]; char format[32] = "%ld"; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); - a->unpack_long(&val, &l); + unpack_long(&val, &l); /* TODO: We should catch all errors but in this case the test ERA_Gen.sh will fail * as the output from grib_ls will be different */ - if ((val == GRIB_MISSING_LONG) && ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0)) { + if ((val == GRIB_MISSING_LONG) && ((flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0)) { snprintf(repres, sizeof(repres), "MISSING"); - } else { + } + else { size_t size = sizeof(format); grib_get_string(h, "formatForLongs", format, &size); snprintf(repres, sizeof(repres), format, val); @@ -51,14 +52,14 @@ int grib_accessor_class_long_t::unpack_string(grib_accessor* a, char* v, size_t* l = strlen(repres) + 1; if (*len < l) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, + const char* cclass_name = class_name_; + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, l, *len); + cclass_name, name_, l, *len); *len = l; return GRIB_BUFFER_TOO_SMALL; } - /*grib_context_log(a->context,GRIB_LOG_DEBUG, "grib_accessor_long: Casting long %s to string ", a->name);*/ + /*grib_context_log(a->context,GRIB_LOG_DEBUG, "grib_accessor_long: Casting long %s to string ", name_ );*/ *len = l; @@ -66,18 +67,18 @@ int grib_accessor_class_long_t::unpack_string(grib_accessor* a, char* v, size_t* return GRIB_SUCCESS; } -int grib_accessor_class_long_t::pack_missing(grib_accessor* a) +int grib_accessor_long_t::pack_missing() { size_t len = 1; long value = GRIB_MISSING_LONG; - if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) - return a->pack_long(&value, &len); + if (flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) + return pack_long(&value, &len); return GRIB_VALUE_CANNOT_BE_MISSING; } -int grib_accessor_class_long_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_long_t::unpack_double(double* val, size_t* len) { size_t rlen = 0; long count = 0; @@ -86,19 +87,19 @@ int grib_accessor_class_long_t::unpack_double(grib_accessor* a, double* val, siz long oneval = 0; int ret = GRIB_SUCCESS; - ret = a->value_count(&count); + ret = value_count(&count); if (ret) return ret; rlen = count; if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %lu values", a->name, rlen); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s, it contains %lu values", name_, rlen); *len = 0; return GRIB_ARRAY_TOO_SMALL; } if (rlen == 1) { - ret = a->unpack_long(&oneval, &rlen); + ret = unpack_long(&oneval, &rlen); if (ret != GRIB_SUCCESS) return ret; *val = oneval; @@ -106,25 +107,25 @@ int grib_accessor_class_long_t::unpack_double(grib_accessor* a, double* val, siz return GRIB_SUCCESS; } - values = (long*)grib_context_malloc(a->context, rlen * sizeof(long)); + values = (long*)grib_context_malloc(context_, rlen * sizeof(long)); if (!values) return GRIB_OUT_OF_MEMORY; - ret = a->unpack_long(values, &rlen); + ret = unpack_long(values, &rlen); if (ret != GRIB_SUCCESS) { - grib_context_free(a->context, values); + grib_context_free(context_, values); return ret; } for (i = 0; i < rlen; i++) val[i] = values[i]; - grib_context_free(a->context, values); + grib_context_free(context_, values); *len = rlen; return GRIB_SUCCESS; } -int grib_accessor_class_long_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_long_t::compare(grib_accessor* b) { int retval = 0; long* aval = 0; @@ -135,7 +136,7 @@ int grib_accessor_class_long_t::compare(grib_accessor* a, grib_accessor* b) size_t blen = 0; int err = 0; - err = a->value_count(&count); + err = value_count(&count); if (err) return err; alen = count; @@ -148,36 +149,36 @@ int grib_accessor_class_long_t::compare(grib_accessor* a, grib_accessor* b) if (alen != blen) return GRIB_COUNT_MISMATCH; - aval = (long*)grib_context_malloc(a->context, alen * sizeof(long)); - bval = (long*)grib_context_malloc(b->context, blen * sizeof(long)); + aval = (long*)grib_context_malloc(context_, alen * sizeof(long)); + bval = (long*)grib_context_malloc(b->context_, blen * sizeof(long)); - a->unpack_long(aval, &alen); + unpack_long(aval, &alen); b->unpack_long(bval, &blen); retval = GRIB_SUCCESS; - for (size_t i=0; icontext, aval); - grib_context_free(b->context, bval); + grib_context_free(context_, aval); + grib_context_free(b->context_, bval); return retval; } -int grib_accessor_class_long_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_long_t::pack_string(const char* val, size_t* len) { long v = 0; /* The converted value */ // ECC-1722 if (STR_EQUAL_NOCASE(val, "missing")) { - return pack_missing(a); + return pack_missing(); } if (string_to_long(val, &v, 1) != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Trying to pack \"%s\" as long. String cannot be converted to an integer", val); + grib_context_log(context_, GRIB_LOG_ERROR, + "Trying to pack \"%s\" as long. String cannot be converted to an integer", val); return GRIB_WRONG_TYPE; } - return a->pack_long(&v, len); + return pack_long(&v, len); } diff --git a/src/accessor/grib_accessor_class_long.h b/src/accessor/grib_accessor_class_long.h index 72a67a8e5..98f54ee09 100644 --- a/src/accessor/grib_accessor_class_long.h +++ b/src/accessor/grib_accessor_class_long.h @@ -13,19 +13,17 @@ #include "grib_accessor_class_gen.h" class grib_accessor_long_t : public grib_accessor_gen_t -{}; - -class grib_accessor_class_long_t : public grib_accessor_class_gen_t { public: - grib_accessor_class_long_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_long_t() : + grib_accessor_gen_t() { class_name_ = "long"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_long_t{}; } - void init(grib_accessor* a, const long len, grib_arguments* arg) override; - int get_native_type(grib_accessor* a) override; - int pack_missing(grib_accessor* a) override; - int pack_string(grib_accessor* a, const char*, size_t* len) override; - int unpack_double(grib_accessor* a, double* val, size_t* len) override; - int unpack_string(grib_accessor* a, char*, size_t* len) override; - void dump(grib_accessor* a, grib_dumper*) override; - int compare(grib_accessor* a, grib_accessor*) override; + void init(const long len, grib_arguments* arg) override; + long get_native_type() override; + int pack_missing() override; + int pack_string(const char*, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + void dump(grib_dumper*) override; + int compare(grib_accessor*) override; }; diff --git a/src/accessor/grib_accessor_class_long_vector.cc b/src/accessor/grib_accessor_class_long_vector.cc index 6759ea799..d8c004e90 100644 --- a/src/accessor/grib_accessor_class_long_vector.cc +++ b/src/accessor/grib_accessor_class_long_vector.cc @@ -11,90 +11,85 @@ #include "grib_accessor_class_long_vector.h" #include "grib_accessor_class_abstract_long_vector.h" -grib_accessor_class_long_vector_t _grib_accessor_class_long_vector{ "long_vector" }; -grib_accessor_class* grib_accessor_class_long_vector = &_grib_accessor_class_long_vector; +grib_accessor_long_vector_t _grib_accessor_long_vector{}; +grib_accessor* grib_accessor_long_vector = &_grib_accessor_long_vector; - -void grib_accessor_class_long_vector_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_long_vector_t::init(const long l, grib_arguments* c) { - grib_accessor_class_abstract_long_vector_t::init(a, l, c); - grib_accessor_long_vector_t* self = (grib_accessor_long_vector_t*)a; + grib_accessor_abstract_long_vector_t::init(l, c); grib_accessor* va = NULL; grib_accessor_abstract_long_vector_t* v = NULL; - int n = 0; + int n = 0; - self->vector = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a), self->vector); - v = (grib_accessor_abstract_long_vector_t*)va; + vector_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(this), vector_); + v = (grib_accessor_abstract_long_vector_t*)va; - self->index = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); + index_ = grib_arguments_get_long(grib_handle_of_accessor(this), c, n++); - /* check self->index on init and never change it */ - Assert(self->index < v->number_of_elements && self->index >= 0); + /* check index_ on init and never change it */ + Assert(index_ < v->number_of_elements_ && index_ >= 0); - a->length = 0; + length_ = 0; } -int grib_accessor_class_long_vector_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_long_vector_t::unpack_long(long* val, size_t* len) { size_t size = 0; int err = 0; long* vector; - grib_accessor_long_vector_t* self = (grib_accessor_long_vector_t*)a; grib_accessor* va = NULL; grib_accessor_abstract_long_vector_t* v = NULL; - va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a), self->vector); + va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(this), vector_); v = (grib_accessor_abstract_long_vector_t*)va; /*TODO implement the dirty mechanism to avoid to unpack every time */ - err = grib_get_size(grib_handle_of_accessor(a), self->vector, &size); + err = grib_get_size(grib_handle_of_accessor(this), vector_, &size); if (err) return err; DEBUG_ASSERT(size > 0); - vector = (long*)grib_context_malloc(a->context, sizeof(long) * size); + vector = (long*)grib_context_malloc(context_, sizeof(long) * size); err = va->unpack_long(vector, &size); - grib_context_free(a->context, vector); + grib_context_free(context_, vector); if (err) return err; - *val = v->v[self->index]; + *val = v->v_[index_]; return GRIB_SUCCESS; } -int grib_accessor_class_long_vector_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_long_vector_t::unpack_double(double* val, size_t* len) { long lval = 0; int err = 0; - grib_accessor_long_vector_t* self = (grib_accessor_long_vector_t*)a; grib_accessor* va = NULL; grib_accessor_abstract_long_vector_t* v = NULL; - va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a), self->vector); - v = (grib_accessor_abstract_long_vector_t*)va; + va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(this), vector_); + v = (grib_accessor_abstract_long_vector_t*)va; - err = unpack_long(a, &lval, len); + err = unpack_long(&lval, len); - *val = (double)v->v[self->index]; + *val = (double)v->v_[index_]; return err; } -int grib_accessor_class_long_vector_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_long_vector_t::pack_long(const long* val, size_t* len) { int err = 0; - grib_accessor_long_vector_t* self = (grib_accessor_long_vector_t*)a; grib_accessor* va = NULL; grib_accessor_abstract_long_vector_t* v = NULL; - va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a), self->vector); + va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(this), vector_); v = (grib_accessor_abstract_long_vector_t*)va; - v->pack_index = self->index; + v->pack_index_ = index_; err = va->pack_long(val, len); return err; } -int grib_accessor_class_long_vector_t::get_native_type(grib_accessor* a) +long grib_accessor_long_vector_t::get_native_type() { return GRIB_TYPE_LONG; } diff --git a/src/accessor/grib_accessor_class_long_vector.h b/src/accessor/grib_accessor_class_long_vector.h index 010a4ed7e..0d000df45 100644 --- a/src/accessor/grib_accessor_class_long_vector.h +++ b/src/accessor/grib_accessor_class_long_vector.h @@ -16,19 +16,16 @@ class grib_accessor_long_vector_t : public grib_accessor_abstract_long_vector_t { public: - /* Members defined in long_vector */ - const char* vector; - int index; -}; - -class grib_accessor_class_long_vector_t : public grib_accessor_class_abstract_long_vector_t -{ -public: - grib_accessor_class_long_vector_t(const char* name) : grib_accessor_class_abstract_long_vector_t(name) {} + grib_accessor_long_vector_t() : + grib_accessor_abstract_long_vector_t() { class_name_ = "long_vector"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_long_vector_t{}; } - int get_native_type(grib_accessor*) override; - int pack_long(grib_accessor*, const long* val, 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; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* vector_; + int index_; }; diff --git a/src/accessor/grib_accessor_class_longitudes.cc b/src/accessor/grib_accessor_class_longitudes.cc index 1b40cbcc7..b262079c1 100644 --- a/src/accessor/grib_accessor_class_longitudes.cc +++ b/src/accessor/grib_accessor_class_longitudes.cc @@ -1,4 +1,3 @@ - /* * (C) Copyright 2005- ECMWF. * @@ -11,31 +10,27 @@ #include "grib_accessor_class_longitudes.h" -grib_accessor_class_longitudes_t _grib_accessor_class_longitudes{ "longitudes" }; -grib_accessor_class* grib_accessor_class_longitudes = &_grib_accessor_class_longitudes; - +grib_accessor_longitudes_t _grib_accessor_longitudes{}; +grib_accessor* grib_accessor_longitudes = &_grib_accessor_longitudes; static int get_distinct(grib_accessor* a, double** val, long* len); - -void grib_accessor_class_longitudes_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_longitudes_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_longitudes_t* self = (grib_accessor_longitudes_t*)a; + grib_accessor_double_t::init(l, c); int n = 0; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->distinct = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); - self->save = 0; - self->lons = 0; + values_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + distinct_ = grib_arguments_get_long(grib_handle_of_accessor(this), c, n++); + save_ = 0; + lons_ = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_longitudes_t::unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_longitudes_t* self = (grib_accessor_longitudes_t*)a; - grib_context* c = a->context; +int grib_accessor_longitudes_t::unpack_double(double* val, size_t* len) +{ + grib_context* c = context_; int ret = 0; double* v = val; double dummyLat = 0; @@ -43,35 +38,35 @@ int grib_accessor_class_longitudes_t::unpack_double(grib_accessor* a, double* va long count = 0; grib_iterator* iter = NULL; - self->save = 1; - ret = value_count(a, &count); + save_ = 1; + ret = value_count(&count); if (ret) return ret; size = count; if (*len < size) { - /* self->lons are computed in value_count*/ - if (self->lons) { - grib_context_free(c, self->lons); - self->lons = NULL; + /* lons_ are computed in value_count*/ + if (lons_) { + grib_context_free(c, lons_); + lons_ = NULL; } return GRIB_ARRAY_TOO_SMALL; } - self->save = 0; + save_ = 0; - /* self->lons are computed in value_count*/ - if (self->lons) { + /* lons_ are computed in value_count*/ + if (lons_) { int i; - *len = self->size; + *len = size_; for (i = 0; i < size; i++) - val[i] = self->lons[i]; - grib_context_free(c, self->lons); - self->lons = NULL; - self->size = 0; + val[i] = lons_[i]; + grib_context_free(c, lons_); + lons_ = NULL; + size_ = 0; return GRIB_SUCCESS; } // ECC-1525 Performance: We do not need the values to be decoded - iter = grib_iterator_new(grib_handle_of_accessor(a), GRIB_GEOITERATOR_NO_VALUES, &ret); + iter = grib_iterator_new(grib_handle_of_accessor(this), GRIB_GEOITERATOR_NO_VALUES, &ret); if (ret != GRIB_SUCCESS) { grib_iterator_delete(iter); grib_context_log(c, GRIB_LOG_ERROR, "longitudes: Unable to create iterator"); @@ -86,17 +81,16 @@ int grib_accessor_class_longitudes_t::unpack_double(grib_accessor* a, double* va return ret; } -int grib_accessor_class_longitudes_t::value_count(grib_accessor* a, long* len) +int grib_accessor_longitudes_t::value_count(long* len) { - grib_accessor_longitudes_t* self = (grib_accessor_longitudes_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - grib_context* c = a->context; - double* val = NULL; + grib_handle* h = grib_handle_of_accessor(this); + grib_context* c = context_; + double* val = NULL; int ret; size_t size; *len = 0; - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) { - grib_context_log(h->context, GRIB_LOG_ERROR, "longitudes: Unable to get size of %s", self->values); + if ((ret = grib_get_size(h, values_, &size)) != GRIB_SUCCESS) { + grib_context_log(h->context, GRIB_LOG_ERROR, "longitudes: Unable to get size of %s", values_); return ret; } *len = size; @@ -108,13 +102,13 @@ int grib_accessor_class_longitudes_t::value_count(grib_accessor* a, long* len) *len = numberOfDataPoints; } - if (self->distinct) { - ret = get_distinct(a, &val, len); + if (distinct_) { + ret = get_distinct(this, &val, len); if (ret != GRIB_SUCCESS) return ret; - if (self->save) { - self->lons = val; - self->size = *len; + if (save_) { + lons_ = val; + size_ = *len; } else { grib_context_free(c, val); @@ -145,7 +139,7 @@ static int get_distinct(grib_accessor* a, double** val, long* len) double dummyLat = 0; int ret = 0; size_t size = *len; - grib_context* c = a->context; + grib_context* c = a->context_; // Performance: We do not need the values to be decoded grib_iterator* iter = grib_iterator_new(grib_handle_of_accessor(a), GRIB_GEOITERATOR_NO_VALUES, &ret); diff --git a/src/accessor/grib_accessor_class_longitudes.h b/src/accessor/grib_accessor_class_longitudes.h index def174a74..814aeb304 100644 --- a/src/accessor/grib_accessor_class_longitudes.h +++ b/src/accessor/grib_accessor_class_longitudes.h @@ -16,20 +16,17 @@ class grib_accessor_longitudes_t : public grib_accessor_double_t { public: - /* Members defined in longitudes */ - const char* values; - long distinct; - double* lons; - long size; - int save; -}; - -class grib_accessor_class_longitudes_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_longitudes_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_longitudes_t() : + grib_accessor_double_t() { class_name_ = "longitudes"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_longitudes_t{}; } - 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; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* values_; + long distinct_; + double* lons_; + long size_; + int save_; }; diff --git a/src/accessor/grib_accessor_class_lookup.cc b/src/accessor/grib_accessor_class_lookup.cc index e58162ccb..470aaa833 100644 --- a/src/accessor/grib_accessor_class_lookup.cc +++ b/src/accessor/grib_accessor_class_lookup.cc @@ -10,40 +10,39 @@ #include "grib_accessor_class_lookup.h" -grib_accessor_class_lookup_t _grib_accessor_class_lookup{ "lookup" }; -grib_accessor_class* grib_accessor_class_lookup = &_grib_accessor_class_lookup; +grib_accessor_lookup_t _grib_accessor_lookup{}; +grib_accessor* grib_accessor_lookup = &_grib_accessor_lookup; - -void grib_accessor_class_lookup_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_lookup_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_long_t::init(a, len, arg); - grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; - - a->length = 0; - self->llength = len; - self->loffset = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 0); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - self->real_name = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, 1); + grib_accessor_long_t::init(len, arg); + length_ = 0; + llength_ = len; + loffset_ = grib_arguments_get_long(grib_handle_of_accessor(this), arg, 0); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + real_name_ = grib_arguments_get_expression(grib_handle_of_accessor(this), arg, 1); } -void grib_accessor_class_lookup_t::post_init(grib_accessor* a) +void grib_accessor_lookup_t::post_init() { - grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; - if (self->real_name) { - grib_dependency_observe_expression(a, self->real_name); + if (real_name_) { + grib_dependency_observe_expression(this, real_name_); } } -void grib_accessor_class_lookup_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_lookup_t::dump(grib_dumper* dumper) { - grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; - unsigned char bytes[1024] = {0,}; - char msg[1024] = {0,}; + unsigned char bytes[1024] = { + 0, + }; + char msg[1024] = { + 0, + }; char buf[2048]; unsigned long v = 0; - size_t llen = self->llength; - a->unpack_bytes(bytes, &llen); + size_t llen = llength_; + unpack_bytes(bytes, &llen); bytes[llen] = 0; for (size_t i = 0; i < llen; i++) { msg[i] = isprint(bytes[i]) ? bytes[i] : '?'; @@ -53,18 +52,20 @@ void grib_accessor_class_lookup_t::dump(grib_accessor* a, grib_dumper* dumper) msg[llen] = 0; - snprintf(buf, sizeof(buf), "%s %lu %ld-%ld", msg, v, (long)a->offset + self->loffset, (long)self->llength); + snprintf(buf, sizeof(buf), "%s %lu %ld-%ld", msg, v, (long)offset_ + loffset_, (long)llength_); - grib_dump_long(dumper, a, buf); + grib_dump_long(dumper, this, buf); } -int grib_accessor_class_lookup_t::unpack_string(grib_accessor* a, char* v, size_t* len) +int grib_accessor_lookup_t::unpack_string(char* v, size_t* len) { - grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; - unsigned char bytes[1024] = {0,}; + unsigned char bytes[1024] = { + 0, + }; + int i; - size_t llen = self->llength; - a->unpack_bytes(bytes, &llen); + size_t llen = llength_; + unpack_bytes(bytes, &llen); bytes[llen] = 0; for (size_t i = 0; i < llen; i++) { @@ -76,7 +77,7 @@ int grib_accessor_class_lookup_t::unpack_string(grib_accessor* a, char* v, size_ /* Try unpack as long */ size_t length = 10; long lval = 0; - int err = unpack_long(a, &lval, &length); + int err = unpack_long(&lval, &length); if (!err) { char str[5]; int conv = snprintf(str, sizeof(str), "%ld", lval); @@ -89,15 +90,14 @@ int grib_accessor_class_lookup_t::unpack_string(grib_accessor* a, char* v, size_ return GRIB_SUCCESS; } -int grib_accessor_class_lookup_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_lookup_t::unpack_long(long* val, size_t* len) { - grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); - long pos = (a->offset + self->loffset) * 8; + long pos = (offset_ + loffset_) * 8; if (len[0] < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", name_, 1); len[0] = 0; return GRIB_ARRAY_TOO_SMALL; } @@ -105,36 +105,34 @@ int grib_accessor_class_lookup_t::unpack_long(grib_accessor* a, long* val, size_ /* This is used when reparsing or rebuilding */ if (h->loader) { Assert(*len == 1); - return h->loader->lookup_long(h->context, h->loader, a->name, val); + return h->loader->lookup_long(h->context, h->loader, name_, val); } - val[0] = grib_decode_unsigned_long(h->buffer->data, &pos, self->llength * 8); + val[0] = grib_decode_unsigned_long(h->buffer->data, &pos, llength_ * 8); len[0] = 1; - /*printf("###########lookup unpack_long: %s %ld %ld\n",a->name, pos/8, val[0]);*/ + /*printf("###########lookup unpack_long: %s %ld %ld\n",name_ , pos/8, val[0]);*/ return GRIB_SUCCESS; } -int grib_accessor_class_lookup_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_lookup_t::pack_long(const long* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -long grib_accessor_class_lookup_t::byte_count(grib_accessor* a) +long grib_accessor_lookup_t::byte_count() { - grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; - return self->llength; + return llength_; } -long grib_accessor_class_lookup_t::byte_offset(grib_accessor* a) +long grib_accessor_lookup_t::byte_offset() { - grib_accessor_lookup_t* self = (grib_accessor_lookup_t*)a; - return self->loffset; + return loffset_; } -int grib_accessor_class_lookup_t::notify_change(grib_accessor* self, grib_accessor* changed) +int grib_accessor_lookup_t::notify_change(grib_accessor* changed) { /* Forward changes */ - return grib_dependency_notify_change(self); + return grib_dependency_notify_change(this); } diff --git a/src/accessor/grib_accessor_class_lookup.h b/src/accessor/grib_accessor_class_lookup.h index be1663ae7..cbc0bd39c 100644 --- a/src/accessor/grib_accessor_class_lookup.h +++ b/src/accessor/grib_accessor_class_lookup.h @@ -16,23 +16,21 @@ class grib_accessor_lookup_t : public grib_accessor_long_t { public: - long llength; - long loffset; - grib_expression* real_name; -}; - -class grib_accessor_class_lookup_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_lookup_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_lookup_t() : + grib_accessor_long_t() { class_name_ = "lookup"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_lookup_t{}; } - int pack_long(grib_accessor*, const long* 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; - long byte_offset(grib_accessor*) override; - void dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; - void post_init(grib_accessor*) override; - int notify_change(grib_accessor*, grib_accessor*) override; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + long byte_count() override; + long byte_offset() override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + void post_init() override; + int notify_change(grib_accessor*) override; + +private: + long llength_; + long loffset_; + grib_expression* real_name_; }; diff --git a/src/accessor/grib_accessor_class_mars_param.cc b/src/accessor/grib_accessor_class_mars_param.cc index 77c59a0bc..b9b0d2c2c 100644 --- a/src/accessor/grib_accessor_class_mars_param.cc +++ b/src/accessor/grib_accessor_class_mars_param.cc @@ -10,37 +10,33 @@ #include "grib_accessor_class_mars_param.h" -grib_accessor_class_mars_param_t _grib_accessor_class_mars_param{ "mars_param" }; -grib_accessor_class* grib_accessor_class_mars_param = &_grib_accessor_class_mars_param; +grib_accessor_mars_param_t _grib_accessor_mars_param{}; +grib_accessor* grib_accessor_mars_param = &_grib_accessor_mars_param; - -void grib_accessor_class_mars_param_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_mars_param_t::init(const long l, grib_arguments* c) { - grib_accessor_class_ascii_t::init(a, l, c); - grib_accessor_mars_param_t* self = (grib_accessor_mars_param_t*)a; - - int n = 0; - self->paramId = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->table = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->param = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + grib_accessor_ascii_t::init(l, c); + int n = 0; + paramId_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + table_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + param_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); } // For an implementation of pack_string, see -// src/deprecated/grib_accessor_class_mars_param.cc +// src/deprecated/grib_accessor_mars_param.cc // For an alternative implementation of unpack_string, see -// src/deprecated/grib_accessor_class_mars_param.cc +// src/deprecated/grib_accessor_mars_param.cc // -int grib_accessor_class_mars_param_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_mars_param_t::unpack_string(char* val, size_t* len) { - grib_accessor_mars_param_t* self = (grib_accessor_mars_param_t*)a; - long param = 0; - long table = 0; - int ret = 0; + long param = 0; + long table = 0; + int ret = 0; - if (self->table != NULL && (ret = grib_get_long_internal(grib_handle_of_accessor(a), self->table, &table)) != GRIB_SUCCESS) + if (table_ != NULL && (ret = grib_get_long_internal(grib_handle_of_accessor(this), table_, &table)) != GRIB_SUCCESS) return ret; - if (self->param != NULL && (ret = grib_get_long_internal(grib_handle_of_accessor(a), self->param, ¶m)) != GRIB_SUCCESS) + if (param_ != NULL && (ret = grib_get_long_internal(grib_handle_of_accessor(this), param_, ¶m)) != GRIB_SUCCESS) return ret; /*if (table==200) table=128;*/ @@ -50,7 +46,7 @@ int grib_accessor_class_mars_param_t::unpack_string(grib_accessor* a, char* val, return GRIB_SUCCESS; } -size_t grib_accessor_class_mars_param_t::string_length(grib_accessor* a) +size_t grib_accessor_mars_param_t::string_length() { return 7; } diff --git a/src/accessor/grib_accessor_class_mars_param.h b/src/accessor/grib_accessor_class_mars_param.h index 1eab50fb6..fc8394f06 100644 --- a/src/accessor/grib_accessor_class_mars_param.h +++ b/src/accessor/grib_accessor_class_mars_param.h @@ -16,18 +16,15 @@ class grib_accessor_mars_param_t : public grib_accessor_ascii_t { public: - /* Members defined in mars_param */ - const char* paramId; - const char* table; - const char* param; -}; - -class grib_accessor_class_mars_param_t : public grib_accessor_class_ascii_t -{ -public: - grib_accessor_class_mars_param_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor_mars_param_t() : + grib_accessor_ascii_t() { class_name_ = "mars_param"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_mars_param_t{}; } - int unpack_string(grib_accessor*, char*, size_t* len) override; - size_t string_length(grib_accessor*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + void init(const long, grib_arguments*) override; + +private: + const char* paramId_; + const char* table_; + const char* param_; }; diff --git a/src/accessor/grib_accessor_class_mars_step.cc b/src/accessor/grib_accessor_class_mars_step.cc index 8fd9f9dfa..b36a98f46 100644 --- a/src/accessor/grib_accessor_class_mars_step.cc +++ b/src/accessor/grib_accessor_class_mars_step.cc @@ -11,34 +11,33 @@ #include "grib_accessor_class_mars_step.h" -grib_accessor_class_mars_step_t _grib_accessor_class_mars_step{ "mars_step" }; -grib_accessor_class* grib_accessor_class_mars_step = &_grib_accessor_class_mars_step; +grib_accessor_mars_step_t _grib_accessor_mars_step{}; +grib_accessor* grib_accessor_mars_step = &_grib_accessor_mars_step; - -void grib_accessor_class_mars_step_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_mars_step_t::init(const long l, grib_arguments* c) { - grib_accessor_class_ascii_t::init(a, l, c); - int n = 0; - grib_accessor_mars_step_t* self = (grib_accessor_mars_step_t*)a; - self->stepRange = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->stepType = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + grib_accessor_ascii_t::init(l, c); + int n = 0; + stepRange_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + stepType_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); } -int grib_accessor_class_mars_step_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_mars_step_t::pack_string(const char* val, size_t* len) { char stepType[100]; size_t stepTypeLen = 100; - char buf[100] = {0,}; + char buf[100] = { + 0, + }; int ret; - grib_accessor_mars_step_t* self = (grib_accessor_mars_step_t*)a; - grib_accessor* stepRangeAcc = grib_find_accessor(grib_handle_of_accessor(a), self->stepRange); + grib_accessor* stepRangeAcc = grib_find_accessor(grib_handle_of_accessor(this), stepRange_); if (!stepRangeAcc) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s not found", self->stepRange); + grib_context_log(context_, GRIB_LOG_ERROR, "%s not found", stepRange_); return GRIB_NOT_FOUND; } - if ((ret = grib_get_string(grib_handle_of_accessor(a), self->stepType, stepType, &stepTypeLen)) != GRIB_SUCCESS) + if ((ret = grib_get_string(grib_handle_of_accessor(this), stepType_, stepType, &stepTypeLen)) != GRIB_SUCCESS) return ret; if (!strcmp(stepType, "instant")) @@ -49,20 +48,20 @@ int grib_accessor_class_mars_step_t::pack_string(grib_accessor* a, const char* v return stepRangeAcc->pack_string(buf, len); } -int grib_accessor_class_mars_step_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_mars_step_t::unpack_string(char* val, size_t* len) { - grib_accessor_mars_step_t* self = (grib_accessor_mars_step_t*)a; - int ret = 0; - char buf[100] = {0,}; + char buf[100] = { + 0, + }; char* p = NULL; size_t buflen = 100; long step; - grib_accessor* stepRangeAcc = grib_find_accessor(grib_handle_of_accessor(a), self->stepRange); - const char* cclass_name = a->cclass->name; + grib_accessor* stepRangeAcc = grib_find_accessor(grib_handle_of_accessor(this), stepRange_); + const char* cclass_name = class_name_; if (!stepRangeAcc) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s: %s not found", cclass_name, self->stepRange); + grib_context_log(context_, GRIB_LOG_ERROR, "%s: %s not found", cclass_name, stepRange_); return GRIB_NOT_FOUND; } @@ -70,9 +69,9 @@ int grib_accessor_class_mars_step_t::unpack_string(grib_accessor* a, char* val, return ret; if (*len < buflen) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, buflen, *len); + cclass_name, name_, buflen, *len); *len = buflen; return GRIB_BUFFER_TOO_SMALL; } @@ -88,20 +87,21 @@ int grib_accessor_class_mars_step_t::unpack_string(grib_accessor* a, char* val, return ret; } -int grib_accessor_class_mars_step_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_mars_step_t::pack_long(const long* val, size_t* len) { - char buff[100] = {0,}; + char buff[100] = { + 0, + }; size_t bufflen = 100; snprintf(buff, sizeof(buff), "%ld", *val); - return pack_string(a, buff, &bufflen); + return pack_string(buff, &bufflen); } -int grib_accessor_class_mars_step_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_mars_step_t::unpack_long(long* val, size_t* len) { - grib_accessor_mars_step_t* self = (grib_accessor_mars_step_t*)a; - grib_accessor* stepRangeAcc = grib_find_accessor(grib_handle_of_accessor(a), self->stepRange); + grib_accessor* stepRangeAcc = grib_find_accessor(grib_handle_of_accessor(this), stepRange_); if (!stepRangeAcc) return GRIB_NOT_FOUND; @@ -109,18 +109,18 @@ int grib_accessor_class_mars_step_t::unpack_long(grib_accessor* a, long* val, si return stepRangeAcc->unpack_long(val, len); } -int grib_accessor_class_mars_step_t::value_count(grib_accessor* a, long* count) +int grib_accessor_mars_step_t::value_count(long* count) { *count = 1; return 0; } -size_t grib_accessor_class_mars_step_t::string_length(grib_accessor* a) +size_t grib_accessor_mars_step_t::string_length() { return 16; } -int grib_accessor_class_mars_step_t::get_native_type(grib_accessor* a) +long grib_accessor_mars_step_t::get_native_type() { return GRIB_TYPE_LONG; } diff --git a/src/accessor/grib_accessor_class_mars_step.h b/src/accessor/grib_accessor_class_mars_step.h index 8a49f56a6..4d0dd0ec3 100644 --- a/src/accessor/grib_accessor_class_mars_step.h +++ b/src/accessor/grib_accessor_class_mars_step.h @@ -16,22 +16,19 @@ class grib_accessor_mars_step_t : public grib_accessor_ascii_t { public: - /* Members defined in mars_step */ - const char* stepRange; - const char* stepType; -}; - -class grib_accessor_class_mars_step_t : public grib_accessor_class_ascii_t -{ -public: - grib_accessor_class_mars_step_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor_mars_step_t() : + grib_accessor_ascii_t() { class_name_ = "mars_step"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_mars_step_t{}; } - int get_native_type(grib_accessor*) 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_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 init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + int pack_string(const char*, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* stepRange_; + const char* stepType_; }; diff --git a/src/accessor/grib_accessor_class_md5.cc b/src/accessor/grib_accessor_class_md5.cc index 40cbae672..ad4caa1a4 100644 --- a/src/accessor/grib_accessor_class_md5.cc +++ b/src/accessor/grib_accessor_class_md5.cc @@ -12,27 +12,25 @@ #include "grib_accessor_class_md5.h" #include "md5.h" -grib_accessor_class_md5_t _grib_accessor_class_md5{ "md5" }; -grib_accessor_class* grib_accessor_class_md5 = &_grib_accessor_class_md5; +grib_accessor_md5_t _grib_accessor_md5{}; +grib_accessor* grib_accessor_md5 = &_grib_accessor_md5; - -void grib_accessor_class_md5_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_md5_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - grib_accessor_md5_t* self = (grib_accessor_md5_t*)a; + grib_accessor_gen_t::init(len, arg); char* b = 0; int n = 0; grib_string_list* current = 0; - grib_context* context = a->context; + grib_context* context = context_; - self->offset = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); - self->length = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, n++); - self->blocklist = NULL; - while ((b = (char*)grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++)) != NULL) { - if (!self->blocklist) { - self->blocklist = (grib_string_list*)grib_context_malloc_clear(context, sizeof(grib_string_list)); - self->blocklist->value = grib_context_strdup(context, b); - current = self->blocklist; + offset_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, n++); + length_ = grib_arguments_get_expression(grib_handle_of_accessor(this), arg, n++); + blocklist_ = NULL; + while ((b = (char*)grib_arguments_get_name(grib_handle_of_accessor(this), arg, n++)) != NULL) { + if (!blocklist_) { + blocklist_ = (grib_string_list*)grib_context_malloc_clear(context, sizeof(grib_string_list)); + blocklist_->value = grib_context_strdup(context, b); + current = blocklist_; } else { Assert(current); @@ -43,17 +41,18 @@ void grib_accessor_class_md5_t::init(grib_accessor* a, const long len, grib_argu } } } - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + // TODO(maee): Is this necessary? + grib_accessor::length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; } -int grib_accessor_class_md5_t::get_native_type(grib_accessor* a) +long grib_accessor_md5_t::get_native_type() { return GRIB_TYPE_STRING; } -int grib_accessor_class_md5_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_md5_t::compare(grib_accessor* b) { int retval = GRIB_SUCCESS; @@ -62,7 +61,7 @@ int grib_accessor_class_md5_t::compare(grib_accessor* a, grib_accessor* b) int err = 0; long count = 0; - err = a->value_count(&count); + err = value_count(&count); if (err) return err; alen = count; @@ -78,50 +77,49 @@ int grib_accessor_class_md5_t::compare(grib_accessor* a, grib_accessor* b) return retval; } -int grib_accessor_class_md5_t::unpack_string(grib_accessor* a, char* v, size_t* len) +int grib_accessor_md5_t::unpack_string(char* v, size_t* len) { - grib_accessor_md5_t* self = (grib_accessor_md5_t*)a; unsigned mess_len; unsigned char* mess; unsigned char* p; long offset = 0, length = 0; grib_string_list* blocklist = NULL; - int ret = GRIB_SUCCESS; - long i = 0; + int ret = GRIB_SUCCESS; + long i = 0; struct grib_md5_state md5c; if (*len < 32) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, + const char* cclass_name = class_name_; + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %d bytes long (len=%zu)", - cclass_name, a->name, 32, *len); + cclass_name, name_, 32, *len); *len = 32; return GRIB_BUFFER_TOO_SMALL; } - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offset, &offset)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offset_, &offset)) != GRIB_SUCCESS) return ret; - if ((ret = grib_expression_evaluate_long(grib_handle_of_accessor(a), self->length, &length)) != GRIB_SUCCESS) + if ((ret = grib_expression_evaluate_long(grib_handle_of_accessor(this), length_, &length)) != GRIB_SUCCESS) return ret; - mess = (unsigned char*)grib_context_malloc(a->context, length); - memcpy(mess, grib_handle_of_accessor(a)->buffer->data + offset, length); + mess = (unsigned char*)grib_context_malloc(context_, length); + memcpy(mess, grib_handle_of_accessor(this)->buffer->data + offset, length); mess_len = length; - blocklist = a->context->blocklist; + blocklist = context_->blocklist; /* passed blocklist overrides context blocklist. Consider to modify following line to extend context blocklist. */ - if (self->blocklist) - blocklist = self->blocklist; + if (blocklist_) + blocklist = blocklist_; while (blocklist && blocklist->value) { - const grib_accessor* b = grib_find_accessor(grib_handle_of_accessor(a), blocklist->value); + const grib_accessor* b = grib_find_accessor(grib_handle_of_accessor(this), blocklist->value); if (!b) { - grib_context_free(a->context, mess); + grib_context_free(context_, mess); return GRIB_NOT_FOUND; } - p = mess + b->offset - offset; - for (i = 0; i < b->length; i++) + p = mess + b->offset_ - offset; + for (i = 0; i < b->length_; i++) *(p++) = 0; blocklist = blocklist->next; @@ -130,17 +128,16 @@ int grib_accessor_class_md5_t::unpack_string(grib_accessor* a, char* v, size_t* grib_md5_init(&md5c); grib_md5_add(&md5c, mess, mess_len); grib_md5_end(&md5c, v); - grib_context_free(a->context, mess); + grib_context_free(context_, mess); *len = strlen(v) + 1; return ret; } -void grib_accessor_class_md5_t::destroy(grib_context* c, grib_accessor* a) +void grib_accessor_md5_t::destroy(grib_context* c) { - grib_accessor_md5_t* self = (grib_accessor_md5_t*)a; - if (self->blocklist) { - grib_string_list* next = self->blocklist; + if (blocklist_) { + grib_string_list* next = blocklist_; grib_string_list* cur = NULL; while (next) { cur = next; @@ -149,10 +146,10 @@ void grib_accessor_class_md5_t::destroy(grib_context* c, grib_accessor* a) grib_context_free(c, cur); } } - grib_accessor_class_gen_t::destroy(c, a); + grib_accessor_gen_t::destroy(c); } -int grib_accessor_class_md5_t::value_count(grib_accessor* a, long* count) +int grib_accessor_md5_t::value_count(long* count) { *count = 1; /* ECC-1475 */ return 0; diff --git a/src/accessor/grib_accessor_class_md5.h b/src/accessor/grib_accessor_class_md5.h index ae66f397f..efe065547 100644 --- a/src/accessor/grib_accessor_class_md5.h +++ b/src/accessor/grib_accessor_class_md5.h @@ -16,21 +16,18 @@ class grib_accessor_md5_t : public grib_accessor_gen_t { public: - /* Members defined in md5 */ - const char* offset; - grib_expression* length; - grib_string_list* blocklist; -}; - -class grib_accessor_class_md5_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_md5_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_md5_t() : + grib_accessor_gen_t() { class_name_ = "md5"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_md5_t{}; } - int get_native_type(grib_accessor*) override; - int unpack_string(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; - int compare(grib_accessor*, grib_accessor*) override; + long get_native_type() override; + int unpack_string(char*, size_t* len) override; + int value_count(long*) override; + void destroy(grib_context*) override; + void init(const long, grib_arguments*) override; + int compare(grib_accessor*) override; + +private: + const char* offset_; + grib_expression* length_; + grib_string_list* blocklist_; }; diff --git a/src/accessor/grib_accessor_class_message.cc b/src/accessor/grib_accessor_class_message.cc index c49c5b20a..a8b7e1996 100644 --- a/src/accessor/grib_accessor_class_message.cc +++ b/src/accessor/grib_accessor_class_message.cc @@ -10,70 +10,69 @@ #include "grib_accessor_class_message.h" -grib_accessor_class_message_t _grib_accessor_class_message{ "message" }; -grib_accessor_class* grib_accessor_class_message = &_grib_accessor_class_message; +grib_accessor_message_t _grib_accessor_message{}; +grib_accessor* grib_accessor_message = &_grib_accessor_message; - -void grib_accessor_class_message_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_message_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_bytes_t::init(a, len, arg); - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = grib_handle_of_accessor(a)->buffer->ulength - len - a->offset; + grib_accessor_bytes_t::init(len, arg); + flags_ |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + length_ = grib_handle_of_accessor(this)->buffer->ulength - len - offset_; } // static int compare(grib_accessor* a, grib_accessor* b) // { -// if (a->length != b->length) +// if (length_ != b->length) // return GRIB_COUNT_MISMATCH; // return GRIB_SUCCESS; // } -void grib_accessor_class_message_t::update_size(grib_accessor* a, size_t new_size) +void grib_accessor_message_t::update_size(size_t new_size) { - a->length = new_size; + length_ = new_size; } -void grib_accessor_class_message_t::resize(grib_accessor* a, size_t new_size) +void grib_accessor_message_t::resize(size_t new_size) { - grib_context_log(a->context, GRIB_LOG_FATAL, "%s %s: Not supported", a->cclass->name, __func__); + grib_context_log(context_, GRIB_LOG_FATAL, "%s %s: Not supported", class_name_, __func__); - // void* zero = grib_context_malloc_clear(a->context, new_size); + // void* zero = grib_context_malloc_clear(context_ , new_size); // grib_buffer_replace(a, (const unsigned char*)zero, new_size, 1, 0); - // grib_context_free(a->context, zero); - // grib_context_log(a->context, GRIB_LOG_DEBUG, "resize: grib_accessor_class_message %ld %ld %s %s", - // (long)new_size, (long)a->length, a->cclass->name, a->name); - // Assert(new_size == a->length); + // grib_context_free(context_ , zero); + // grib_context_log(context_ , GRIB_LOG_DEBUG, "resize: grib_accessor_message %ld %ld %s %s", + // (long)new_size, (long)a->length, a->cclass->name, name_ ); + // Assert(new_size == length_ ); } -int grib_accessor_class_message_t::value_count(grib_accessor* a, long* count) +int grib_accessor_message_t::value_count(long* count) { *count = 1; return 0; } -int grib_accessor_class_message_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_message_t::unpack_string(char* val, size_t* len) { long i = 0; - size_t l = string_length(a) + 1; - grib_handle* h = grib_handle_of_accessor(a); + size_t l = string_length() + 1; + grib_handle* h = grib_handle_of_accessor(this); if (*len < l) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - a->cclass->name, a->name, l, *len); + class_name_, name_, l, *len); *len = l; return GRIB_BUFFER_TOO_SMALL; } - for (i = 0; i < a->length; i++) - val[i] = h->buffer->data[a->offset + i]; + for (i = 0; i < length_; i++) + val[i] = h->buffer->data[offset_ + i]; val[i] = 0; *len = i; return GRIB_SUCCESS; } -size_t grib_accessor_class_message_t::string_length(grib_accessor* a) +size_t grib_accessor_message_t::string_length() { - return a->length; + return length_; } diff --git a/src/accessor/grib_accessor_class_message.h b/src/accessor/grib_accessor_class_message.h index 2e29d6ebd..c2bb71fee 100644 --- a/src/accessor/grib_accessor_class_message.h +++ b/src/accessor/grib_accessor_class_message.h @@ -16,18 +16,13 @@ class grib_accessor_message_t : public grib_accessor_bytes_t { public: - /* Members defined in message */ -}; - -class grib_accessor_class_message_t : public grib_accessor_class_bytes_t -{ -public: - grib_accessor_class_message_t(const char* name) : grib_accessor_class_bytes_t(name) {} + grib_accessor_message_t() : + grib_accessor_bytes_t() { class_name_ = "message"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_message_t{}; } - 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 init(grib_accessor*, const long, grib_arguments*) override; - void update_size(grib_accessor*, size_t) override; - void resize(grib_accessor*,size_t) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + void update_size(size_t) override; + void resize(size_t) override; }; diff --git a/src/accessor/grib_accessor_class_message_copy.cc b/src/accessor/grib_accessor_class_message_copy.cc index 43b7fb42d..ca38698ba 100644 --- a/src/accessor/grib_accessor_class_message_copy.cc +++ b/src/accessor/grib_accessor_class_message_copy.cc @@ -10,42 +10,41 @@ #include "grib_accessor_class_message_copy.h" -grib_accessor_class_message_copy_t _grib_accessor_class_message_copy{ "message_copy" }; -grib_accessor_class* grib_accessor_class_message_copy = &_grib_accessor_class_message_copy; +grib_accessor_message_copy_t _grib_accessor_message_copy{}; +grib_accessor* grib_accessor_message_copy = &_grib_accessor_message_copy; - -void grib_accessor_class_message_copy_t::init(grib_accessor* a, const long length, grib_arguments* args) +void grib_accessor_message_copy_t::init(const long length, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, length, args); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; + grib_accessor_gen_t::init(length, args); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + length_ = 0; } -void grib_accessor_class_message_copy_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_message_copy_t::dump(grib_dumper* dumper) { - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); } -int grib_accessor_class_message_copy_t::get_native_type(grib_accessor* a) +long grib_accessor_message_copy_t::get_native_type() { return GRIB_TYPE_STRING; } -int grib_accessor_class_message_copy_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_message_copy_t::unpack_string(char* val, size_t* len) { - size_t slen = grib_handle_of_accessor(a)->buffer->ulength; + size_t slen = grib_handle_of_accessor(this)->buffer->ulength; size_t i; unsigned char* v = 0; if (*len < slen) { return GRIB_ARRAY_TOO_SMALL; } - v = grib_handle_of_accessor(a)->buffer->data; + v = grib_handle_of_accessor(this)->buffer->data; /* replace unprintable characters with space */ for (i = 0; i < slen; i++) if (v[i] > 126) v[i] = 32; - memcpy(val, grib_handle_of_accessor(a)->buffer->data, slen); + memcpy(val, grib_handle_of_accessor(this)->buffer->data, slen); val[i] = 0; *len = slen; @@ -53,12 +52,12 @@ int grib_accessor_class_message_copy_t::unpack_string(grib_accessor* a, char* va return GRIB_SUCCESS; } -size_t grib_accessor_class_message_copy_t::string_length(grib_accessor* a) +size_t grib_accessor_message_copy_t::string_length() { - return grib_handle_of_accessor(a)->buffer->ulength; + return grib_handle_of_accessor(this)->buffer->ulength; } -long grib_accessor_class_message_copy_t::byte_count(grib_accessor* a) +long grib_accessor_message_copy_t::byte_count() { - return a->length; + return length_; } diff --git a/src/accessor/grib_accessor_class_message_copy.h b/src/accessor/grib_accessor_class_message_copy.h index 608817a93..23810fa6e 100644 --- a/src/accessor/grib_accessor_class_message_copy.h +++ b/src/accessor/grib_accessor_class_message_copy.h @@ -16,18 +16,13 @@ class grib_accessor_message_copy_t : public grib_accessor_gen_t { public: - /* Members defined in message_copy */ -}; - -class grib_accessor_class_message_copy_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_message_copy_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_message_copy_t() : + grib_accessor_gen_t() { class_name_ = "message_copy"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_message_copy_t{}; } - int get_native_type(grib_accessor*) override; - int unpack_string(grib_accessor*, char*, size_t* len) override; - size_t string_length(grib_accessor*) override; - long byte_count(grib_accessor*) override; - void dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + long byte_count() override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_multdouble.cc b/src/accessor/grib_accessor_class_multdouble.cc index c86539190..f610cbfc5 100644 --- a/src/accessor/grib_accessor_class_multdouble.cc +++ b/src/accessor/grib_accessor_class_multdouble.cc @@ -10,31 +10,28 @@ #include "grib_accessor_class_multdouble.h" -grib_accessor_class_multdouble_t _grib_accessor_class_multdouble{ "multdouble" }; -grib_accessor_class* grib_accessor_class_multdouble = &_grib_accessor_class_multdouble; +grib_accessor_multdouble_t _grib_accessor_multdouble{}; +grib_accessor* grib_accessor_multdouble = &_grib_accessor_multdouble; - -void grib_accessor_class_multdouble_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_multdouble_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_multdouble_t* self = (grib_accessor_multdouble_t*)a; + grib_accessor_double_t::init(l, c); int n = 0; - self->val = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->multiplier = grib_arguments_get_double(grib_handle_of_accessor(a), c, n++); + val_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + multiplier_ = grib_arguments_get_double(grib_handle_of_accessor(this), c, n++); } -int grib_accessor_class_multdouble_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_multdouble_t::unpack_double(double* val, size_t* len) { - const grib_accessor_multdouble_t* self = (grib_accessor_multdouble_t*)a; int ret = GRIB_SUCCESS; double value = 0; - ret = grib_get_double_internal(grib_handle_of_accessor(a), self->val, &value); + ret = grib_get_double_internal(grib_handle_of_accessor(this), val_, &value); if (ret != GRIB_SUCCESS) return ret; - *val = value * self->multiplier; + *val = value * multiplier_; *len = 1; return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_multdouble.h b/src/accessor/grib_accessor_class_multdouble.h index 025daf903..85f125565 100644 --- a/src/accessor/grib_accessor_class_multdouble.h +++ b/src/accessor/grib_accessor_class_multdouble.h @@ -16,16 +16,13 @@ class grib_accessor_multdouble_t : public grib_accessor_double_t { public: - /* Members defined in multdouble */ - const char* val; - double multiplier; -}; - -class grib_accessor_class_multdouble_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_multdouble_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_multdouble_t() : + grib_accessor_double_t() { class_name_ = "multdouble"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_multdouble_t{}; } - int unpack_double(grib_accessor*, double* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_double(double* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* val_; + double multiplier_; }; diff --git a/src/accessor/grib_accessor_class_nearest.cc b/src/accessor/grib_accessor_class_nearest.cc index a958c5092..f8d97d00a 100644 --- a/src/accessor/grib_accessor_class_nearest.cc +++ b/src/accessor/grib_accessor_class_nearest.cc @@ -10,38 +10,36 @@ #include "grib_accessor_class_nearest.h" -grib_accessor_class_nearest_t _grib_accessor_class_nearest{"nearest"}; -grib_accessor_class* grib_accessor_class_nearest = &_grib_accessor_class_nearest; +grib_accessor_nearest_t _grib_accessor_nearest{}; +grib_accessor* grib_accessor_nearest = &_grib_accessor_nearest; - -void grib_accessor_class_nearest_t::init(grib_accessor* a, const long l, grib_arguments* args) +void grib_accessor_nearest_t::init(const long l, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, l, args); - grib_accessor_nearest_t* self = (grib_accessor_nearest_t*)a; - self->args = args; + grib_accessor_gen_t::init(l, args); + args_ = args; } -void grib_accessor_class_nearest_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_nearest_t::dump(grib_dumper* dumper) { /* TODO: pass args */ - grib_dump_label(dumper, a, NULL); + grib_dump_label(dumper, this, NULL); } #if defined(HAVE_GEOGRAPHY) grib_nearest* grib_nearest_new(const grib_handle* ch, int* error) { - grib_handle* h = (grib_handle*)ch; - grib_accessor* a = NULL; + grib_handle* h = (grib_handle*)ch; + grib_accessor* a = NULL; grib_accessor_nearest_t* na = NULL; - grib_nearest* n = NULL; - *error = GRIB_NOT_IMPLEMENTED; - a = grib_find_accessor(h, "NEAREST"); - na = (grib_accessor_nearest_t*)a; + grib_nearest* n = NULL; + *error = GRIB_NOT_IMPLEMENTED; + a = grib_find_accessor(h, "NEAREST"); + na = (grib_accessor_nearest_t*)a; if (!a) return NULL; - n = grib_nearest_factory(h, na->args, error); + n = grib_nearest_factory(h, na->args_, error); if (n) *error = GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_nearest.h b/src/accessor/grib_accessor_class_nearest.h index 3ac4fdae2..3d6280743 100644 --- a/src/accessor/grib_accessor_class_nearest.h +++ b/src/accessor/grib_accessor_class_nearest.h @@ -15,17 +15,14 @@ class grib_accessor_nearest_t : public grib_accessor_gen_t { public: - grib_arguments* args; -}; - - -class grib_accessor_class_nearest_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_nearest_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_nearest_t() : + grib_accessor_gen_t() { class_name_ = "nearest"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_nearest_t{}; } - void init(grib_accessor* a, const long l, grib_arguments* args) override; - void dump(grib_accessor* a, grib_dumper* dumper) override; + void init(const long l, grib_arguments* args) override; + void dump(grib_dumper* dumper) override; + +public: + grib_arguments* args_; }; -//grib_nearest* grib_nearest_new(const grib_handle* ch, int* error); +// grib_nearest* grib_nearest_new(const grib_handle* ch, int* error); diff --git a/src/accessor/grib_accessor_class_non_alpha.cc b/src/accessor/grib_accessor_class_non_alpha.cc index 7e434dfb6..2d69ff53c 100644 --- a/src/accessor/grib_accessor_class_non_alpha.cc +++ b/src/accessor/grib_accessor_class_non_alpha.cc @@ -10,76 +10,77 @@ #include "grib_accessor_class_non_alpha.h" -grib_accessor_class_non_alpha_t _grib_accessor_class_non_alpha{ "non_alpha" }; -grib_accessor_class* grib_accessor_class_non_alpha = &_grib_accessor_class_non_alpha; +grib_accessor_non_alpha_t _grib_accessor_non_alpha{}; +grib_accessor* grib_accessor_non_alpha = &_grib_accessor_non_alpha; - -void grib_accessor_class_non_alpha_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_non_alpha_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - grib_buffer* buffer = grib_handle_of_accessor(a)->buffer; + grib_accessor_gen_t::init(len, arg); + grib_buffer* buffer = grib_handle_of_accessor(this)->buffer; size_t i = 0; unsigned char* v; - v = buffer->data + a->offset; + v = buffer->data + offset_; i = 0; while ((*v < 33 || *v > 126) && i <= buffer->ulength) { v++; i++; } - a->length = i; + length_ = i; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_non_alpha_t::value_count(grib_accessor* a, long* count) +int grib_accessor_non_alpha_t::value_count(long* count) { *count = 1; return 0; } -size_t grib_accessor_class_non_alpha_t::string_length(grib_accessor* a) +size_t grib_accessor_non_alpha_t::string_length() { - return a->length; + return length_; } -void grib_accessor_class_non_alpha_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_non_alpha_t::dump(grib_dumper* dumper) { - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); } -int grib_accessor_class_non_alpha_t::get_native_type(grib_accessor* a) +long grib_accessor_non_alpha_t::get_native_type() { return GRIB_TYPE_STRING; } -int grib_accessor_class_non_alpha_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_non_alpha_t::unpack_string(char* val, size_t* len) { - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); long i = 0; - if (*len < (a->length + 1)) { - grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s, it contains %ld values", - *len, a->name, a->length + 1); - *len = a->length + 1; + if (*len < (length_ + 1)) { + grib_context_log(context_, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s, it contains %ld values", + *len, name_, length_ + 1); + *len = length_ + 1; return GRIB_BUFFER_TOO_SMALL; } - for (i = 0; i < a->length; i++) { - val[i] = hand->buffer->data[a->offset + i]; + for (i = 0; i < length_; i++) { + val[i] = hand->buffer->data[offset_ + i]; } val[i] = 0; *len = i; return GRIB_SUCCESS; } -int grib_accessor_class_non_alpha_t::unpack_long(grib_accessor* a, long* v, size_t* len) +int grib_accessor_non_alpha_t::unpack_long(long* v, size_t* len) { - char val[1024] = {0,}; + char val[1024] = { + 0, + }; size_t l = sizeof(val); size_t i = 0; char* last = NULL; - int err = a->unpack_string(val, &l); + int err = unpack_string(val, &l); if (err) return err; @@ -99,12 +100,12 @@ int grib_accessor_class_non_alpha_t::unpack_long(grib_accessor* a, long* v, size return GRIB_SUCCESS; } -int grib_accessor_class_non_alpha_t::unpack_double(grib_accessor* a, double* v, size_t* len) +int grib_accessor_non_alpha_t::unpack_double(double* v, size_t* len) { char val[1024]; size_t l = sizeof(val); char* last = NULL; - a->unpack_string(val, &l); + unpack_string(val, &l); *v = strtod(val, &last); if (*last == 0) { @@ -114,7 +115,7 @@ int grib_accessor_class_non_alpha_t::unpack_double(grib_accessor* a, double* v, return GRIB_NOT_IMPLEMENTED; } -long grib_accessor_class_non_alpha_t::next_offset(grib_accessor* a) +long grib_accessor_non_alpha_t::next_offset() { - return a->offset + a->length; + return offset_ + length_; } diff --git a/src/accessor/grib_accessor_class_non_alpha.h b/src/accessor/grib_accessor_class_non_alpha.h index 83b1ca9ba..d1de79562 100644 --- a/src/accessor/grib_accessor_class_non_alpha.h +++ b/src/accessor/grib_accessor_class_non_alpha.h @@ -16,21 +16,16 @@ class grib_accessor_non_alpha_t : public grib_accessor_gen_t { public: - /* Members defined in non_alpha */ -}; - -class grib_accessor_class_non_alpha_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_non_alpha_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_non_alpha_t() : + grib_accessor_gen_t() { class_name_ = "non_alpha"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_non_alpha_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; - size_t string_length(grib_accessor*) override; - long next_offset(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; + long get_native_type() override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + long next_offset() override; + int value_count(long*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_number_of_coded_values.cc b/src/accessor/grib_accessor_class_number_of_coded_values.cc index a4410d75d..36a699516 100644 --- a/src/accessor/grib_accessor_class_number_of_coded_values.cc +++ b/src/accessor/grib_accessor_class_number_of_coded_values.cc @@ -10,56 +10,49 @@ #include "grib_accessor_class_number_of_coded_values.h" -grib_accessor_class_number_of_coded_values_t _grib_accessor_class_number_of_coded_values{ "number_of_coded_values" }; -grib_accessor_class* grib_accessor_class_number_of_coded_values = &_grib_accessor_class_number_of_coded_values; +grib_accessor_number_of_coded_values_t _grib_accessor_number_of_coded_values{}; +grib_accessor* grib_accessor_number_of_coded_values = &_grib_accessor_number_of_coded_values; - -void grib_accessor_class_number_of_coded_values_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_number_of_coded_values_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_number_of_coded_values_t* self = (grib_accessor_number_of_coded_values_t*)a; - - int n = 0; - self->bitsPerValue = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->offsetBeforeData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->offsetAfterData = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->unusedBits = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->numberOfValues = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; + grib_accessor_long_t::init(l, c); + int n = 0; + bitsPerValue_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + offsetBeforeData_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + offsetAfterData_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + unusedBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + numberOfValues_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + length_ = 0; } -int grib_accessor_class_number_of_coded_values_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_number_of_coded_values_t::unpack_long(long* val, size_t* len) { int ret = GRIB_SUCCESS; long bpv = 0; long offsetBeforeData = 0, offsetAfterData = 0, unusedBits = 0, numberOfValues; - grib_accessor_number_of_coded_values_t* self = (grib_accessor_number_of_coded_values_t*)a; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bitsPerValue, &bpv)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), bitsPerValue_, &bpv)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetBeforeData, &offsetBeforeData)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetBeforeData_, &offsetBeforeData)) != GRIB_SUCCESS) return ret; - - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetAfterData, &offsetAfterData)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), offsetAfterData_, &offsetAfterData)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->unusedBits, &unusedBits)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), unusedBits_, &unusedBits)) != GRIB_SUCCESS) return ret; if (bpv != 0) { - grib_context_log(a->context, GRIB_LOG_DEBUG, - "grib_accessor_number_of_coded_values_t: offsetAfterData=%ld offsetBeforeData=%ld unusedBits=%ld bpv=%ld\n", - offsetAfterData, offsetBeforeData, unusedBits, bpv); + grib_context_log(context_, GRIB_LOG_DEBUG, "grib_accessor_number_of_coded_values_t: offsetAfterData=%ld offsetBeforeData=%ld unusedBits=%ld bpv=%ld\n", + offsetAfterData, offsetBeforeData, unusedBits, bpv); DEBUG_ASSERT(offsetAfterData > offsetBeforeData); *val = ((offsetAfterData - offsetBeforeData) * 8 - unusedBits) / bpv; } else { - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfValues, &numberOfValues)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfValues_, &numberOfValues)) != GRIB_SUCCESS) return ret; *val = numberOfValues; diff --git a/src/accessor/grib_accessor_class_number_of_coded_values.h b/src/accessor/grib_accessor_class_number_of_coded_values.h index 6578e1dcf..f4df0413d 100644 --- a/src/accessor/grib_accessor_class_number_of_coded_values.h +++ b/src/accessor/grib_accessor_class_number_of_coded_values.h @@ -16,19 +16,16 @@ class grib_accessor_number_of_coded_values_t : public grib_accessor_long_t { public: - /* Members defined in number_of_coded_values */ - const char* numberOfValues; - const char* bitsPerValue; - const char* offsetBeforeData; - const char* offsetAfterData; - const char* unusedBits; -}; - -class grib_accessor_class_number_of_coded_values_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_number_of_coded_values_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_number_of_coded_values_t() : + grib_accessor_long_t() { class_name_ = "number_of_coded_values"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_number_of_coded_values_t{}; } - int unpack_long(grib_accessor*, long* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* numberOfValues_; + const char* bitsPerValue_; + const char* offsetBeforeData_; + const char* offsetAfterData_; + const char* unusedBits_; }; diff --git a/src/accessor/grib_accessor_class_number_of_points.cc b/src/accessor/grib_accessor_class_number_of_points.cc index 53fcf6fbe..3fae3d9f0 100644 --- a/src/accessor/grib_accessor_class_number_of_points.cc +++ b/src/accessor/grib_accessor_class_number_of_points.cc @@ -10,56 +10,51 @@ #include "grib_accessor_class_number_of_points.h" -grib_accessor_class_number_of_points_t _grib_accessor_class_number_of_points{ "number_of_points" }; -grib_accessor_class* grib_accessor_class_number_of_points = &_grib_accessor_class_number_of_points; +grib_accessor_number_of_points_t _grib_accessor_number_of_points{}; +grib_accessor* grib_accessor_number_of_points = &_grib_accessor_number_of_points; - -void grib_accessor_class_number_of_points_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_number_of_points_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - int n = 0; - grib_handle* hand = grib_handle_of_accessor(a); + grib_accessor_long_t::init(l, c); + int n = 0; + grib_handle* hand = grib_handle_of_accessor(this); - grib_accessor_number_of_points_t* self = (grib_accessor_number_of_points_t*)a; - - self->ni = grib_arguments_get_name(hand, c, n++); - self->nj = grib_arguments_get_name(hand, c, n++); - self->plpresent = grib_arguments_get_name(hand, c, n++); - self->pl = grib_arguments_get_name(hand, c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; + ni_ = grib_arguments_get_name(hand, c, n++); + nj_ = grib_arguments_get_name(hand, c, n++); + plpresent_ = grib_arguments_get_name(hand, c, n++); + pl_ = grib_arguments_get_name(hand, c, n++); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + length_ = 0; } -int grib_accessor_class_number_of_points_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_number_of_points_t::unpack_long(long* val, size_t* len) { - grib_accessor_number_of_points_t* self = (grib_accessor_number_of_points_t*)a; - int ret = GRIB_SUCCESS; long ni = 0, nj = 0, plpresent = 0; size_t plsize = 0; long* pl = NULL; int i = 0; - grib_context* c = a->context; - grib_handle* hand = grib_handle_of_accessor(a); + grib_context* c = context_; + grib_handle* hand = grib_handle_of_accessor(this); - if ((ret = grib_get_long_internal(hand, self->ni, &ni)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, ni_, &ni)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->nj, &nj)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, nj_, &nj)) != GRIB_SUCCESS) return ret; - if (self->plpresent && - ((ret = grib_get_long_internal(hand, self->plpresent, &plpresent)) != GRIB_SUCCESS)) + if (plpresent_ && + ((ret = grib_get_long_internal(hand, plpresent_, &plpresent)) != GRIB_SUCCESS)) return ret; - if (grib_is_missing(hand, self->nj, &ret) && ret == GRIB_SUCCESS) { - grib_context_log(c, GRIB_LOG_ERROR, "grib_accessor_class_number_of_points: Key %s cannot be 'missing'!", self->nj); + if (grib_is_missing(hand, nj_, &ret) && ret == GRIB_SUCCESS) { + grib_context_log(c, GRIB_LOG_ERROR, "grib_accessor_number_of_points: Key %s cannot be 'missing'!", nj_); return GRIB_GEOCALCULUS_PROBLEM; } if (nj == 0) { - grib_context_log(c, GRIB_LOG_ERROR, "grib_accessor_class_number_of_points: Key %s cannot be 0!", self->nj); + grib_context_log(c, GRIB_LOG_ERROR, "grib_accessor_number_of_points: Key %s cannot be 0!", nj_); return GRIB_GEOCALCULUS_PROBLEM; } @@ -67,7 +62,7 @@ int grib_accessor_class_number_of_points_t::unpack_long(grib_accessor* a, long* /*reduced*/ plsize = nj; pl = (long*)grib_context_malloc(c, sizeof(long) * plsize); - grib_get_long_array_internal(hand, self->pl, pl, &plsize); + grib_get_long_array_internal(hand, pl_, pl, &plsize); *val = 0; for (i = 0; i < plsize; i++) *val += pl[i]; diff --git a/src/accessor/grib_accessor_class_number_of_points.h b/src/accessor/grib_accessor_class_number_of_points.h index f55d9bbeb..fd9a16550 100644 --- a/src/accessor/grib_accessor_class_number_of_points.h +++ b/src/accessor/grib_accessor_class_number_of_points.h @@ -16,18 +16,15 @@ class grib_accessor_number_of_points_t : public grib_accessor_long_t { public: - /* Members defined in number_of_points */ - const char* ni; - const char* nj; - const char* plpresent; - const char* pl; -}; - -class grib_accessor_class_number_of_points_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_number_of_points_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_number_of_points_t() : + grib_accessor_long_t() { class_name_ = "number_of_points"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_number_of_points_t{}; } - int unpack_long(grib_accessor*, long* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* ni_; + const char* nj_; + const char* plpresent_; + const char* pl_; }; diff --git a/src/accessor/grib_accessor_class_number_of_points_gaussian.cc b/src/accessor/grib_accessor_class_number_of_points_gaussian.cc index cf8fa8db0..a62d8bf30 100644 --- a/src/accessor/grib_accessor_class_number_of_points_gaussian.cc +++ b/src/accessor/grib_accessor_class_number_of_points_gaussian.cc @@ -10,36 +10,34 @@ #include "grib_accessor_class_number_of_points_gaussian.h" -grib_accessor_class_number_of_points_gaussian_t _grib_accessor_class_number_of_points_gaussian{ "number_of_points_gaussian" }; -grib_accessor_class* grib_accessor_class_number_of_points_gaussian = &_grib_accessor_class_number_of_points_gaussian; - +grib_accessor_number_of_points_gaussian_t _grib_accessor_number_of_points_gaussian{}; +grib_accessor* grib_accessor_number_of_points_gaussian = &_grib_accessor_number_of_points_gaussian; #define EFDEBUG 0 -void grib_accessor_class_number_of_points_gaussian_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_number_of_points_gaussian_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - int n = 0; - grib_handle* h = grib_handle_of_accessor(a); - grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; + grib_accessor_long_t::init(l, c); + int n = 0; + grib_handle* h = grib_handle_of_accessor(this); - self->ni = grib_arguments_get_name(h, c, n++); - self->nj = grib_arguments_get_name(h, c, n++); - self->plpresent = grib_arguments_get_name(h, c, n++); - self->pl = grib_arguments_get_name(h, c, n++); - self->order = grib_arguments_get_name(h, c, n++); - self->lat_first = grib_arguments_get_name(h, c, n++); - self->lon_first = grib_arguments_get_name(h, c, n++); - self->lat_last = grib_arguments_get_name(h, c, n++); - self->lon_last = grib_arguments_get_name(h, c, n++); - self->support_legacy = grib_arguments_get_name(h, c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; + ni_ = grib_arguments_get_name(h, c, n++); + nj_ = grib_arguments_get_name(h, c, n++); + plpresent_ = grib_arguments_get_name(h, c, n++); + pl_ = grib_arguments_get_name(h, c, n++); + order_ = grib_arguments_get_name(h, c, n++); + lat_first_ = grib_arguments_get_name(h, c, n++); + lon_first_ = grib_arguments_get_name(h, c, n++); + lat_last_ = grib_arguments_get_name(h, c, n++); + lon_last_ = grib_arguments_get_name(h, c, n++); + support_legacy_ = grib_arguments_get_name(h, c, n++); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + length_ = 0; } // Old implementation of num_points_reduced_gauss_old -// See src/deprecated/grib_accessor_class_number_of_points_gaussian.cc +// See src/deprecated/grib_accessor_number_of_points_gaussian.cc // static int angleApproximatelyEqual(double A, double B, double angular_precision) { @@ -114,27 +112,27 @@ static int get_number_of_data_values(grib_handle* h, size_t* numDataValues) static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* len); static int unpack_long_new(grib_accessor* a, long* val, size_t* len); -int grib_accessor_class_number_of_points_gaussian_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_number_of_points_gaussian_t::unpack_long(long* val, size_t* len) { - int err = GRIB_SUCCESS; - long support_legacy = 1; - grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + int err = GRIB_SUCCESS; + long support_legacy = 1; + grib_handle* h = grib_handle_of_accessor(this); - if ((err = grib_get_long_internal(h, self->support_legacy, &support_legacy)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, support_legacy_, &support_legacy)) != GRIB_SUCCESS) return err; if (support_legacy == 1) - return unpack_long_with_legacy_support(a, val, len); + return unpack_long_with_legacy_support(this, val, len); else - return unpack_long_new(a, val, len); + return unpack_long_new(this, val, len); } /* New algorithm */ static int unpack_long_new(grib_accessor* a, long* val, size_t* len) { - int err = GRIB_SUCCESS; - int is_global = 0; + grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; + int err = GRIB_SUCCESS; + int is_global = 0; long ni = 0, nj = 0, plpresent = 0, order = 0; size_t plsize = 0; double lat_first, lat_last, lon_first, lon_last; @@ -146,16 +144,15 @@ static int unpack_long_new(grib_accessor* a, long* val, size_t* len) long angleSubdivisions = 0; grib_handle* h = grib_handle_of_accessor(a); - grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((err = grib_get_long_internal(h, self->ni, &ni)) != GRIB_SUCCESS) + 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) + if ((err = grib_get_long_internal(h, self->nj_, &nj)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->plpresent, &plpresent)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, self->plpresent_, &plpresent)) != GRIB_SUCCESS) return err; if (nj == 0) @@ -172,23 +169,23 @@ static int unpack_long_new(grib_accessor* a, long* val, size_t* len) // double lon_first_row = 0, lon_last_row = 0; /*reduced*/ - if ((err = grib_get_long_internal(h, self->order, &order)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, self->order_, &order)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lat_first, &lat_first)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, self->lat_first_, &lat_first)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lon_first, &lon_first)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, self->lon_first_, &lon_first)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lat_last, &lat_last)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, self->lat_last_, &lat_last)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lon_last, &lon_last)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, self->lon_last_, &lon_last)) != GRIB_SUCCESS) return err; - if ((err = grib_get_size(h, self->pl, &plsize)) != GRIB_SUCCESS) + if ((err = grib_get_size(h, self->pl_, &plsize)) != GRIB_SUCCESS) return err; pl = (long*)grib_context_malloc_clear(c, sizeof(long) * plsize); plsave = pl; - grib_get_long_array_internal(h, self->pl, pl, &plsize); + grib_get_long_array_internal(h, self->pl_, pl, &plsize); if (lon_last < 0) lon_last += 360; @@ -242,8 +239,9 @@ static int unpack_long_new(grib_accessor* a, long* val, size_t* len) /* With Legacy support */ static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* len) { - int err = GRIB_SUCCESS; - int is_global = 0; + grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; + int err = GRIB_SUCCESS; + int is_global = 0; long ni = 0, nj = 0, plpresent = 0, order = 0; size_t plsize = 0; double lat_first, lat_last, lon_first, lon_last; @@ -256,16 +254,15 @@ static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* grib_handle* h = grib_handle_of_accessor(a); size_t numDataValues = 0; - grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((err = grib_get_long_internal(h, self->ni, &ni)) != GRIB_SUCCESS) + 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) + if ((err = grib_get_long_internal(h, self->nj_, &nj)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->plpresent, &plpresent)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, self->plpresent_, &plpresent)) != GRIB_SUCCESS) return err; if (nj == 0) @@ -282,23 +279,23 @@ static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* // double lon_first_row = 0, lon_last_row = 0; /*reduced*/ - if ((err = grib_get_long_internal(h, self->order, &order)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, self->order_, &order)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lat_first, &lat_first)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, self->lat_first_, &lat_first)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lon_first, &lon_first)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, self->lon_first_, &lon_first)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lat_last, &lat_last)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, self->lat_last_, &lat_last)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lon_last, &lon_last)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, self->lon_last_, &lon_last)) != GRIB_SUCCESS) return err; - if ((err = grib_get_size(h, self->pl, &plsize)) != GRIB_SUCCESS) + if ((err = grib_get_size(h, self->pl_, &plsize)) != GRIB_SUCCESS) return err; pl = (long*)grib_context_malloc_clear(c, sizeof(long) * plsize); plsave = pl; - grib_get_long_array_internal(h, self->pl, pl, &plsize); + grib_get_long_array_internal(h, self->pl_, pl, &plsize); if (lon_last < 0) lon_last += 360; diff --git a/src/accessor/grib_accessor_class_number_of_points_gaussian.h b/src/accessor/grib_accessor_class_number_of_points_gaussian.h index d00fb5b6e..6b47f7a0e 100644 --- a/src/accessor/grib_accessor_class_number_of_points_gaussian.h +++ b/src/accessor/grib_accessor_class_number_of_points_gaussian.h @@ -16,24 +16,21 @@ class grib_accessor_number_of_points_gaussian_t : public grib_accessor_long_t { public: - /* Members defined in number_of_points_gaussian */ - const char* ni; - const char* nj; - const char* plpresent; - const char* pl; - const char* order; - const char* lat_first; - const char* lon_first; - const char* lat_last; - const char* lon_last; - const char* support_legacy; -}; - -class grib_accessor_class_number_of_points_gaussian_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_number_of_points_gaussian_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_number_of_points_gaussian_t() : + grib_accessor_long_t() { class_name_ = "number_of_points_gaussian"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_number_of_points_gaussian_t{}; } - int unpack_long(grib_accessor*, long* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +public: + const char* ni_; + const char* nj_; + const char* plpresent_; + const char* pl_; + const char* order_; + const char* lat_first_; + const char* lon_first_; + const char* lat_last_; + const char* lon_last_; + const char* support_legacy_; }; diff --git a/src/accessor/grib_accessor_class_number_of_values.cc b/src/accessor/grib_accessor_class_number_of_values.cc index 80cd39f85..28fbef50d 100644 --- a/src/accessor/grib_accessor_class_number_of_values.cc +++ b/src/accessor/grib_accessor_class_number_of_values.cc @@ -10,46 +10,44 @@ #include "grib_accessor_class_number_of_values.h" -grib_accessor_class_number_of_values_t _grib_accessor_class_number_of_values{ "number_of_values" }; -grib_accessor_class* grib_accessor_class_number_of_values = &_grib_accessor_class_number_of_values; +grib_accessor_number_of_values_t _grib_accessor_number_of_values{}; +grib_accessor* grib_accessor_number_of_values = &_grib_accessor_number_of_values; - -void grib_accessor_class_number_of_values_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_number_of_values_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - int n = 0; - grib_accessor_number_of_values_t* self = (grib_accessor_number_of_values_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_accessor_long_t::init(l, c); + int n = 0; + grib_handle* hand = grib_handle_of_accessor(this); - self->values = grib_arguments_get_name(hand, c, n++); - self->bitsPerValue = grib_arguments_get_name(hand, c, n++); - self->numberOfPoints = grib_arguments_get_name(hand, c, n++); - self->bitmapPresent = grib_arguments_get_name(hand, c, n++); - self->bitmap = grib_arguments_get_name(hand, c, n++); - self->numberOfCodedValues = grib_arguments_get_name(hand, c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + values_ = grib_arguments_get_name(hand, c, n++); + bitsPerValue_ = grib_arguments_get_name(hand, c, n++); + numberOfPoints_ = grib_arguments_get_name(hand, c, n++); + bitmapPresent_ = grib_arguments_get_name(hand, c, n++); + bitmap_ = grib_arguments_get_name(hand, c, n++); + numberOfCodedValues_ = grib_arguments_get_name(hand, c, n++); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; + length_ = 0; } -int grib_accessor_class_number_of_values_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_number_of_values_t::unpack_long(long* val, size_t* len) { - grib_accessor_number_of_values_t* self = (grib_accessor_number_of_values_t*)a; - int ret = GRIB_SUCCESS; + int ret = GRIB_SUCCESS, i; long npoints = 0, bitmap_present = 0; size_t size = 0; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints, &npoints)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfPoints_, &npoints)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->bitmapPresent, &bitmap_present)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), bitmapPresent_, &bitmap_present)) != GRIB_SUCCESS) return ret; if (bitmap_present) { - size = npoints; - double* bitmap = (double*)grib_context_malloc(a->context, sizeof(double) * size); - if ((ret = grib_get_double_array_internal(grib_handle_of_accessor(a), self->bitmap, bitmap, &size)) != GRIB_SUCCESS) { - grib_context_free(a->context, bitmap); + double* bitmap; + size = npoints; + bitmap = (double*)grib_context_malloc(context_, sizeof(double) * size); + if ((ret = grib_get_double_array_internal(grib_handle_of_accessor(this), bitmap_, bitmap, &size)) != GRIB_SUCCESS) { + grib_context_free(context_, bitmap); return ret; } *val = 0; @@ -59,7 +57,7 @@ int grib_accessor_class_number_of_values_t::unpack_long(grib_accessor* a, long* } } - grib_context_free(a->context, bitmap); + grib_context_free(context_, bitmap); } else { *val = npoints; diff --git a/src/accessor/grib_accessor_class_number_of_values.h b/src/accessor/grib_accessor_class_number_of_values.h index 895669f34..ab9848b18 100644 --- a/src/accessor/grib_accessor_class_number_of_values.h +++ b/src/accessor/grib_accessor_class_number_of_values.h @@ -16,20 +16,17 @@ class grib_accessor_number_of_values_t : public grib_accessor_long_t { public: - /* Members defined in number_of_values */ - const char* values; - const char* bitsPerValue; - const char* numberOfPoints; - const char* bitmapPresent; - const char* bitmap; - const char* numberOfCodedValues; -}; - -class grib_accessor_class_number_of_values_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_number_of_values_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_number_of_values_t() : + grib_accessor_long_t() { class_name_ = "number_of_values"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_number_of_values_t{}; } - int unpack_long(grib_accessor*, long* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* values_; + const char* bitsPerValue_; + const char* numberOfPoints_; + const char* bitmapPresent_; + const char* bitmap_; + const char* numberOfCodedValues_; }; diff --git a/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.cc b/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.cc index c443e7c24..e76eb4197 100644 --- a/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.cc +++ b/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.cc @@ -10,36 +10,32 @@ #include "grib_accessor_class_number_of_values_data_raw_packing.h" -grib_accessor_class_number_of_values_data_raw_packing_t _grib_accessor_class_number_of_values_data_raw_packing{ "number_of_values_data_raw_packing" }; -grib_accessor_class* grib_accessor_class_number_of_values_data_raw_packing = &_grib_accessor_class_number_of_values_data_raw_packing; +grib_accessor_number_of_values_data_raw_packing_t _grib_accessor_number_of_values_data_raw_packing{}; +grib_accessor* grib_accessor_number_of_values_data_raw_packing = &_grib_accessor_number_of_values_data_raw_packing; - -void grib_accessor_class_number_of_values_data_raw_packing_t::init(grib_accessor* a, const long v, grib_arguments* args) +void grib_accessor_number_of_values_data_raw_packing_t::init(const long v, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, v, args); - grib_accessor_number_of_values_data_raw_packing_t* self = (grib_accessor_number_of_values_data_raw_packing_t*)a; - + grib_accessor_gen_t::init(v, args); int n = 0; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->precision = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; + + values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + precision_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + length_ = 0; } -int grib_accessor_class_number_of_values_data_raw_packing_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_number_of_values_data_raw_packing_t::unpack_long(long* val, size_t* len) { - grib_accessor_number_of_values_data_raw_packing_t* self = (grib_accessor_number_of_values_data_raw_packing_t*)a; - int err = 0; grib_accessor* adata = NULL; long precision = 0; int bytes = 0; long byte_count = 0; - adata = grib_find_accessor(grib_handle_of_accessor(a), self->values); + adata = grib_find_accessor(grib_handle_of_accessor(this), values_); Assert(adata != NULL); byte_count = adata->byte_count(); - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->precision, &precision)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), precision_, &precision)) != GRIB_SUCCESS) return err; switch (precision) { @@ -60,7 +56,7 @@ int grib_accessor_class_number_of_values_data_raw_packing_t::unpack_long(grib_ac return err; } -int grib_accessor_class_number_of_values_data_raw_packing_t::get_native_type(grib_accessor* a) +long grib_accessor_number_of_values_data_raw_packing_t::get_native_type() { return GRIB_TYPE_LONG; } diff --git a/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.h b/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.h index 798f428f5..0a6d4567a 100644 --- a/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.h +++ b/src/accessor/grib_accessor_class_number_of_values_data_raw_packing.h @@ -16,17 +16,14 @@ class grib_accessor_number_of_values_data_raw_packing_t : public grib_accessor_gen_t { public: - /* Members defined in number_of_values_data_raw_packing */ - const char* values; - const char* precision; -}; - -class grib_accessor_class_number_of_values_data_raw_packing_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_number_of_values_data_raw_packing_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_number_of_values_data_raw_packing_t() : + grib_accessor_gen_t() { class_name_ = "number_of_values_data_raw_packing"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_number_of_values_data_raw_packing_t{}; } - int get_native_type(grib_accessor*) override; - int unpack_long(grib_accessor*, long* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* values_; + const char* precision_; }; diff --git a/src/accessor/grib_accessor_class_octahedral_gaussian.cc b/src/accessor/grib_accessor_class_octahedral_gaussian.cc index 69074bef3..bffe8b1b0 100644 --- a/src/accessor/grib_accessor_class_octahedral_gaussian.cc +++ b/src/accessor/grib_accessor_class_octahedral_gaussian.cc @@ -10,21 +10,19 @@ #include "grib_accessor_class_octahedral_gaussian.h" -grib_accessor_class_octahedral_gaussian_t _grib_accessor_class_octahedral_gaussian{ "octahedral_gaussian" }; -grib_accessor_class* grib_accessor_class_octahedral_gaussian = &_grib_accessor_class_octahedral_gaussian; +grib_accessor_octahedral_gaussian_t _grib_accessor_octahedral_gaussian{}; +grib_accessor* grib_accessor_octahedral_gaussian = &_grib_accessor_octahedral_gaussian; - -void grib_accessor_class_octahedral_gaussian_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_octahedral_gaussian_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_octahedral_gaussian_t* self = (grib_accessor_octahedral_gaussian_t*)a; - int n = 0; - grib_handle* hand = grib_handle_of_accessor(a); + grib_accessor_long_t::init(l, c); + int n = 0; + grib_handle* hand = grib_handle_of_accessor(this); - self->N = grib_arguments_get_name(hand, c, n++); - self->Ni = grib_arguments_get_name(hand, c, n++); - self->plpresent = grib_arguments_get_name(hand, c, n++); - self->pl = grib_arguments_get_name(hand, c, n++); + N_ = grib_arguments_get_name(hand, c, n++); + Ni_ = grib_arguments_get_name(hand, c, n++); + plpresent_ = grib_arguments_get_name(hand, c, n++); + pl_ = grib_arguments_get_name(hand, c, n++); } /* Returns 1 (=true) if input pl array is Octahedral, 0 otherwise. @@ -70,19 +68,18 @@ static int is_pl_octahedral(const long pl[], size_t size) return 1; /* it's octahedral */ } -int grib_accessor_class_octahedral_gaussian_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_octahedral_gaussian_t::unpack_long(long* val, size_t* len) { - grib_accessor_octahedral_gaussian_t* self = (grib_accessor_octahedral_gaussian_t*)a; int ret = GRIB_SUCCESS; long Ni; long plpresent = 0; long* pl = NULL; /* pl array */ size_t plsize = 0; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); - grib_context* c = a->context; + grib_context* c = context_; - if ((ret = grib_get_long_internal(hand, self->Ni, &Ni)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, Ni_, &Ni)) != GRIB_SUCCESS) return ret; /* If Ni is not missing, then this is a plain gaussian grid and not reduced. */ @@ -92,14 +89,14 @@ int grib_accessor_class_octahedral_gaussian_t::unpack_long(grib_accessor* a, lon return GRIB_SUCCESS; } - if ((ret = grib_get_long_internal(hand, self->plpresent, &plpresent)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, plpresent_, &plpresent)) != GRIB_SUCCESS) return ret; if (!plpresent) { *val = 0; /* Not octahedral */ return GRIB_SUCCESS; } - if ((ret = grib_get_size(hand, self->pl, &plsize)) != GRIB_SUCCESS) + if ((ret = grib_get_size(hand, pl_, &plsize)) != GRIB_SUCCESS) return ret; Assert(plsize); /* pl array must have at least one element */ @@ -107,7 +104,7 @@ int grib_accessor_class_octahedral_gaussian_t::unpack_long(grib_accessor* a, lon if (!pl) { return GRIB_OUT_OF_MEMORY; } - if ((ret = grib_get_long_array_internal(hand, self->pl, pl, &plsize)) != GRIB_SUCCESS) + if ((ret = grib_get_long_array_internal(hand, pl_, pl, &plsize)) != GRIB_SUCCESS) return ret; /* pl[0] is guaranteed to exist. Have already asserted previously */ @@ -117,7 +114,7 @@ int grib_accessor_class_octahedral_gaussian_t::unpack_long(grib_accessor* a, lon return ret; } -int grib_accessor_class_octahedral_gaussian_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_octahedral_gaussian_t::pack_long(const long* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } diff --git a/src/accessor/grib_accessor_class_octahedral_gaussian.h b/src/accessor/grib_accessor_class_octahedral_gaussian.h index cc7f52a25..280788d91 100644 --- a/src/accessor/grib_accessor_class_octahedral_gaussian.h +++ b/src/accessor/grib_accessor_class_octahedral_gaussian.h @@ -16,19 +16,16 @@ class grib_accessor_octahedral_gaussian_t : public grib_accessor_long_t { public: - /* Members defined in octahedral_gaussian */ - const char* N; - const char* Ni; - const char* plpresent; - const char* pl; -}; - -class grib_accessor_class_octahedral_gaussian_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_octahedral_gaussian_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_octahedral_gaussian_t() : + grib_accessor_long_t() { class_name_ = "octahedral_gaussian"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_octahedral_gaussian_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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* N_; + const char* Ni_; + const char* plpresent_; + const char* pl_; }; diff --git a/src/accessor/grib_accessor_class_octet_number.cc b/src/accessor/grib_accessor_class_octet_number.cc index 354a39820..e54117420 100644 --- a/src/accessor/grib_accessor_class_octet_number.cc +++ b/src/accessor/grib_accessor_class_octet_number.cc @@ -10,29 +10,28 @@ #include "grib_accessor_class_octet_number.h" -grib_accessor_class_octet_number_t _grib_accessor_class_octet_number{ "octet_number" }; -grib_accessor_class* grib_accessor_class_octet_number = &_grib_accessor_class_octet_number; +grib_accessor_octet_number_t _grib_accessor_octet_number{}; +grib_accessor* grib_accessor_octet_number = &_grib_accessor_octet_number; - -void grib_accessor_class_octet_number_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_octet_number_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_octet_number_t* self = (grib_accessor_octet_number_t*)a; + grib_accessor_long_t::init(l, c); - int n = 0; - self->left = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->right = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); + int n = 0; + left_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + right_ = grib_arguments_get_long(grib_handle_of_accessor(this), c, n++); - a->length = 0; + length_ = 0; } -int grib_accessor_class_octet_number_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_octet_number_t::unpack_long(long* val, size_t* len) { - grib_accessor_octet_number_t* self = (grib_accessor_octet_number_t*)a; int ret = GRIB_SUCCESS; - long offset = a->offset + self->right; + long offset; - if ((ret = grib_set_long_internal(grib_handle_of_accessor(a), self->left, offset)) != GRIB_SUCCESS) + offset = offset_ + right_; + + if ((ret = grib_set_long_internal(grib_handle_of_accessor(this), left_, offset)) != GRIB_SUCCESS) return ret; *val = offset; @@ -41,7 +40,7 @@ int grib_accessor_class_octet_number_t::unpack_long(grib_accessor* a, long* val, return ret; } -int grib_accessor_class_octet_number_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_octet_number_t::pack_long(const long* val, size_t* len) { return GRIB_SUCCESS; } diff --git a/src/accessor/grib_accessor_class_octet_number.h b/src/accessor/grib_accessor_class_octet_number.h index 691dcb564..e8d200818 100644 --- a/src/accessor/grib_accessor_class_octet_number.h +++ b/src/accessor/grib_accessor_class_octet_number.h @@ -16,17 +16,14 @@ class grib_accessor_octet_number_t : public grib_accessor_long_t { public: - /* Members defined in octet_number */ - const char* left; - long right; -}; - -class grib_accessor_class_octet_number_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_octet_number_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_octet_number_t() : + grib_accessor_long_t() { class_name_ = "octet_number"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_octet_number_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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* left_; + long right_; }; diff --git a/src/accessor/grib_accessor_class_offset_file.cc b/src/accessor/grib_accessor_class_offset_file.cc index 8c06bfb78..599ab7d8d 100644 --- a/src/accessor/grib_accessor_class_offset_file.cc +++ b/src/accessor/grib_accessor_class_offset_file.cc @@ -10,46 +10,47 @@ #include "grib_accessor_class_offset_file.h" -grib_accessor_class_offset_file_t _grib_accessor_class_offset_file{ "offset_file" }; -grib_accessor_class* grib_accessor_class_offset_file = &_grib_accessor_class_offset_file; +grib_accessor_offset_file_t _grib_accessor_offset_file{}; +grib_accessor* grib_accessor_offset_file = &_grib_accessor_offset_file; - -void grib_accessor_class_offset_file_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_offset_file_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; + grib_accessor_double_t::init(l, c); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + length_ = 0; } -int grib_accessor_class_offset_file_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_offset_file_t::unpack_double(double* val, size_t* len) { - *val = (double)grib_handle_of_accessor(a)->offset; + *val = (double)grib_handle_of_accessor(this)->offset; *len = 1; return GRIB_SUCCESS; } -int grib_accessor_class_offset_file_t::unpack_string(grib_accessor* a, char* v, size_t* len) +int grib_accessor_offset_file_t::unpack_string(char* v, size_t* len) { - double val = 0; - size_t l = 1; - char repres[1024] = {0,}; - int err = 0; - const char* cclass_name = a->cclass->name; + double val = 0; + size_t l = 1; + char repres[1024] = { + 0, + }; + int err = 0; + const char* cclass_name = class_name_; - err = a->unpack_double(&val, &l); + err = unpack_double(&val, &l); if (err) return err; snprintf(repres, sizeof(repres), "%.0f", val); l = strlen(repres) + 1; if (l > *len) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, l, *len); + cclass_name, name_, l, *len); *len = l; return GRIB_BUFFER_TOO_SMALL; } - grib_context_log(a->context, GRIB_LOG_DEBUG, "%s: Casting double %s to string", __func__, a->name); + grib_context_log(context_, GRIB_LOG_DEBUG, "%s: Casting double %s to string", __func__, name_); *len = l; diff --git a/src/accessor/grib_accessor_class_offset_file.h b/src/accessor/grib_accessor_class_offset_file.h index 6cb25b864..6d532e55d 100644 --- a/src/accessor/grib_accessor_class_offset_file.h +++ b/src/accessor/grib_accessor_class_offset_file.h @@ -16,15 +16,10 @@ class grib_accessor_offset_file_t : public grib_accessor_double_t { public: - /* Members defined in offset_file */ -}; - -class grib_accessor_class_offset_file_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_offset_file_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_offset_file_t() : + grib_accessor_double_t() { class_name_ = "offset_file"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_offset_file_t{}; } - int unpack_double(grib_accessor*, double* val, size_t* len) override; - int unpack_string(grib_accessor*, char*, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_double(double* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_offset_values.cc b/src/accessor/grib_accessor_class_offset_values.cc index 1219d0030..a2f94d8c5 100644 --- a/src/accessor/grib_accessor_class_offset_values.cc +++ b/src/accessor/grib_accessor_class_offset_values.cc @@ -10,22 +10,20 @@ #include "grib_accessor_class_offset_values.h" -grib_accessor_class_offset_values_t _grib_accessor_class_offset_values{ "offset_values" }; -grib_accessor_class* grib_accessor_class_offset_values = &_grib_accessor_class_offset_values; +grib_accessor_offset_values_t _grib_accessor_offset_values{}; +grib_accessor* grib_accessor_offset_values = &_grib_accessor_offset_values; - -void grib_accessor_class_offset_values_t::init(grib_accessor* a, const long l, grib_arguments* args) +void grib_accessor_offset_values_t::init(const long l, grib_arguments* args) { - grib_accessor_class_double_t::init(a, l, args); - int n = 0; - grib_accessor_offset_values_t* self = (grib_accessor_offset_values_t*)a; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->missingValue = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; + grib_accessor_double_t::init(l, args); + int n = 0; + values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + missingValue_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + length_ = 0; } -int grib_accessor_class_offset_values_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_offset_values_t::unpack_double(double* val, size_t* len) { int ret = 0; *val = 0; @@ -33,35 +31,34 @@ int grib_accessor_class_offset_values_t::unpack_double(grib_accessor* a, double* return ret; } -int grib_accessor_class_offset_values_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_offset_values_t::pack_double(const double* val, size_t* len) { double* values = NULL; size_t size = 0; double missingValue = 0; long missingValuesPresent = 0; int ret = 0, i = 0; - grib_accessor_offset_values_t* self = (grib_accessor_offset_values_t*)a; - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); + grib_context* c = context_; + grib_handle* h = grib_handle_of_accessor(this); if (*val == 0) return GRIB_SUCCESS; - if ((ret = grib_get_double_internal(h, self->missingValue, &missingValue)) != GRIB_SUCCESS) { + if ((ret = grib_get_double_internal(h, missingValue_, &missingValue)) != GRIB_SUCCESS) { return ret; } if ((ret = grib_get_long_internal(h, "missingValuesPresent", &missingValuesPresent)) != GRIB_SUCCESS) { return ret; } - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + if ((ret = grib_get_size(h, 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) { + if ((ret = grib_get_double_array_internal(h, values_, values, &size)) != GRIB_SUCCESS) { grib_context_free(c, values); return ret; } @@ -76,7 +73,7 @@ int grib_accessor_class_offset_values_t::pack_double(grib_accessor* a, const dou } } - if ((ret = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) + if ((ret = grib_set_double_array_internal(h, values_, values, size)) != GRIB_SUCCESS) return ret; grib_context_free(c, values); diff --git a/src/accessor/grib_accessor_class_offset_values.h b/src/accessor/grib_accessor_class_offset_values.h index 702e48da7..c1ee0f11f 100644 --- a/src/accessor/grib_accessor_class_offset_values.h +++ b/src/accessor/grib_accessor_class_offset_values.h @@ -16,17 +16,14 @@ class grib_accessor_offset_values_t : public grib_accessor_double_t { public: - /* Members defined in offset_values */ - const char* values; - const char* missingValue; -}; - -class grib_accessor_class_offset_values_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_offset_values_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_offset_values_t() : + grib_accessor_double_t() { class_name_ = "offset_values"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_offset_values_t{}; } - int pack_double(grib_accessor*, const double* val, size_t* len) override; - int unpack_double(grib_accessor*, double* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* values_; + const char* missingValue_; }; diff --git a/src/accessor/grib_accessor_class_optimal_step_units.cc b/src/accessor/grib_accessor_class_optimal_step_units.cc index e6ff3fe73..31e12212f 100644 --- a/src/accessor/grib_accessor_class_optimal_step_units.cc +++ b/src/accessor/grib_accessor_class_optimal_step_units.cc @@ -12,70 +12,67 @@ #include "step.h" #include "step_utilities.h" -grib_accessor_class_optimal_step_units_t _grib_accessor_class_optimal_step_units{ "optimal_step_units" }; -grib_accessor_class* grib_accessor_class_optimal_step_units = &_grib_accessor_class_optimal_step_units; +grib_accessor_optimal_step_units_t _grib_accessor_optimal_step_units{}; +grib_accessor* grib_accessor_optimal_step_units = &_grib_accessor_optimal_step_units; - -void grib_accessor_class_optimal_step_units_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_optimal_step_units_t::init(const long l, grib_arguments* c) { - grib_accessor_class_gen_t::init(a, l, c); - grib_accessor_optimal_step_units_t* self = (grib_accessor_optimal_step_units_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_gen_t::init(l, c); + grib_handle* hand = grib_handle_of_accessor(this); + int n = 0; - self->forecast_time_value = grib_arguments_get_name(hand, c, n++); - self->forecast_time_unit = grib_arguments_get_name(hand, c, n++); - self->time_range_value = grib_arguments_get_name(hand, c, n++); - self->time_range_unit = grib_arguments_get_name(hand, c, n++); - a->length = 0; - self->overwriteStepUnits = eccodes::Unit{ eccodes::Unit::Value::MISSING }.value(); + forecast_time_value_ = grib_arguments_get_name(hand, c, n++); + forecast_time_unit_ = grib_arguments_get_name(hand, c, n++); + time_range_value_ = grib_arguments_get_name(hand, c, n++); + time_range_unit_ = grib_arguments_get_name(hand, c, n++); + length_ = 0; + overwriteStepUnits_ = eccodes::Unit{ eccodes::Unit::Value::MISSING }.value(); } -void grib_accessor_class_optimal_step_units_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_optimal_step_units_t::dump(grib_dumper* dumper) { - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); } -size_t grib_accessor_class_optimal_step_units_t::string_length(grib_accessor* a) +size_t grib_accessor_optimal_step_units_t::string_length() { return 255; } -int grib_accessor_class_optimal_step_units_t::pack_expression(grib_accessor* a, grib_expression* e) +int grib_accessor_optimal_step_units_t::pack_expression(grib_expression* e) { const char* cval = NULL; int ret = 0; long lval = 0; size_t len = 1; - grib_handle* hand = grib_handle_of_accessor(a); - const char* cclass_name = a->cclass->name; + grib_handle* hand = grib_handle_of_accessor(this); + const char* cclass_name = class_name_; if (strcmp(e->cclass->name, "long") == 0) { - grib_expression_evaluate_long(hand, e, &lval); // TODO: check return value - ret = a->pack_long(&lval, &len); + grib_expression_evaluate_long(hand, e, &lval); /* TODO: check return value */ + ret = pack_long(&lval, &len); } else { char tmp[1024]; len = sizeof(tmp); cval = grib_expression_evaluate_string(hand, e, tmp, &len, &ret); if (ret != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s.%s: Unable to evaluate string %s to be set in %s", - cclass_name, __func__, grib_expression_get_name(e), a->name); + cclass_name, __func__, grib_expression_get_name(e), name_); return ret; } len = strlen(cval) + 1; // if (hand->context->debug) - // printf("ECCODES DEBUG grib_accessor_class_codetable::pack_expression %s %s\n", a->name, cval); - ret = a->pack_string(cval, &len); + // printf("ECCODES DEBUG grib_accessor_codetable::pack_expression %s %s\n", name_ , cval); + ret = pack_string(cval, &len); } return ret; } -int grib_accessor_class_optimal_step_units_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_optimal_step_units_t::pack_long(const long* val, size_t* len) { - grib_handle* h = grib_handle_of_accessor(a); - grib_accessor_optimal_step_units_t* self = (grib_accessor_optimal_step_units_t*)a; + grib_handle* h = grib_handle_of_accessor(this); long start_step = 0; long start_step_unit = 0; @@ -99,7 +96,7 @@ int grib_accessor_class_optimal_step_units_t::pack_long(grib_accessor* a, const std::string msg = std::string{ "Invalid unit: " } + std::to_string(*val) + " (" + e.what() + ")" + ". Available units are: " + supported_units_str; - grib_context_log(a->context, GRIB_LOG_ERROR, "%s", msg.c_str()); + grib_context_log(context_, GRIB_LOG_ERROR, "%s", msg.c_str()); return GRIB_INVALID_ARGUMENT; } @@ -107,7 +104,7 @@ int grib_accessor_class_optimal_step_units_t::pack_long(grib_accessor* a, const // "grib-set -s stepUnits=m in.grib out.grib", the following code initiates an indirect update // of the low-level keys: forecastTime,indicatorOfUnitOfTimeRange,indicatorOfUnitForTimeRange,lengthOfTimeRange - self->overwriteStepUnits = *val; + overwriteStepUnits_ = *val; if ((ret = grib_set_long_internal(h, "forceStepUnits", *val)) != GRIB_SUCCESS) return ret; @@ -137,31 +134,30 @@ int grib_accessor_class_optimal_step_units_t::pack_long(grib_accessor* a, const } catch (std::exception& e) { std::string msg = std::string{ "Failed to convert steps to: " } + std::to_string(*val) + " (" + e.what() + ")"; - grib_context_log(a->context, GRIB_LOG_ERROR, "%s", msg.c_str()); + grib_context_log(context_, GRIB_LOG_ERROR, "%s", msg.c_str()); return GRIB_INTERNAL_ERROR; } return GRIB_SUCCESS; } -int grib_accessor_class_optimal_step_units_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_optimal_step_units_t::unpack_long(long* val, size_t* len) { - const grib_accessor_optimal_step_units_t* self = (grib_accessor_optimal_step_units_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); try { - if (eccodes::Unit{ self->overwriteStepUnits } != eccodes::Unit{ eccodes::Unit::Value::MISSING }) { - *val = self->overwriteStepUnits; + if (eccodes::Unit{ overwriteStepUnits_ } != eccodes::Unit{ eccodes::Unit::Value::MISSING }) { + *val = overwriteStepUnits_; return GRIB_SUCCESS; } - auto forecast_time_opt = get_step(h, self->forecast_time_value, self->forecast_time_unit); - auto time_range_opt = get_step(h, self->time_range_value, self->time_range_unit); + auto forecast_time_opt = get_step(h, forecast_time_value_, forecast_time_unit_); + auto time_range_opt = get_step(h, time_range_value_, time_range_unit_); if (forecast_time_opt && time_range_opt) { auto [step_a, step_b] = find_common_units(forecast_time_opt.value().optimize_unit(), (forecast_time_opt.value() + time_range_opt.value()).optimize_unit()); - *val = step_a.unit().value(); + *val = step_a.unit().value(); } else if (forecast_time_opt && !time_range_opt) { *val = forecast_time_opt.value().optimize_unit().unit().value(); @@ -174,18 +170,18 @@ int grib_accessor_class_optimal_step_units_t::unpack_long(grib_accessor* a, long } } catch (std::exception& e) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s", e.what()); + grib_context_log(context_, GRIB_LOG_ERROR, "%s", e.what()); return GRIB_INTERNAL_ERROR; } return GRIB_SUCCESS; } -int grib_accessor_class_optimal_step_units_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_optimal_step_units_t::pack_string(const char* val, size_t* len) { try { long unit = eccodes::Unit{ val }.value(); - pack_long(a, &unit, len); + pack_long(&unit, len); } catch (std::exception& e) { auto supported_units = eccodes::Unit::list_supported_units(); @@ -195,19 +191,19 @@ int grib_accessor_class_optimal_step_units_t::pack_string(grib_accessor* a, cons supported_units_str.pop_back(); std::string msg = "Invalid unit: " + std::string(val) + " (" + e.what() + ")" + ". Available units are: " + supported_units_str; - grib_context_log(a->context, GRIB_LOG_ERROR, "%s", msg.c_str()); + grib_context_log(context_, GRIB_LOG_ERROR, "%s", msg.c_str()); return GRIB_INVALID_ARGUMENT; } return GRIB_SUCCESS; } -int grib_accessor_class_optimal_step_units_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_optimal_step_units_t::unpack_string(char* val, size_t* len) { int ret = 0; long unit = 0; size_t unit_len = 0; - if ((ret = unpack_long(a, &unit, &unit_len)) != GRIB_SUCCESS) + if ((ret = unpack_long(&unit, &unit_len)) != GRIB_SUCCESS) return ret; *len = snprintf(val, *len, "%s", eccodes::Unit{ unit }.value().c_str()); return GRIB_SUCCESS; @@ -215,12 +211,12 @@ int grib_accessor_class_optimal_step_units_t::unpack_string(grib_accessor* a, ch // Step units are never missing // If the user does not specify a step unit, we default to hours -int grib_accessor_class_optimal_step_units_t::is_missing(grib_accessor* a) +int grib_accessor_optimal_step_units_t::is_missing() { return 0; } -int grib_accessor_class_optimal_step_units_t::get_native_type(grib_accessor* a) +long grib_accessor_optimal_step_units_t::get_native_type() { return GRIB_TYPE_LONG; } diff --git a/src/accessor/grib_accessor_class_optimal_step_units.h b/src/accessor/grib_accessor_class_optimal_step_units.h index e7aa35247..0d248204e 100644 --- a/src/accessor/grib_accessor_class_optimal_step_units.h +++ b/src/accessor/grib_accessor_class_optimal_step_units.h @@ -16,27 +16,24 @@ class grib_accessor_optimal_step_units_t : public grib_accessor_gen_t { public: - /* Members defined in optimal_step_units */ - const char* forecast_time_value; - const char* forecast_time_unit; - const char* time_range_value; - const char* time_range_unit; - long overwriteStepUnits; -}; - -class grib_accessor_class_optimal_step_units_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_optimal_step_units_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_optimal_step_units_t() : + grib_accessor_gen_t() { class_name_ = "optimal_step_units"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_optimal_step_units_t{}; } - int get_native_type(grib_accessor*) override; - int is_missing(grib_accessor*) 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_expression(grib_accessor*, grib_expression*) 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; - void dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int is_missing() override; + int pack_long(const long* val, size_t* len) override; + int pack_string(const char*, size_t* len) override; + int pack_expression(grib_expression*) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +private: + const char* forecast_time_value_; + const char* forecast_time_unit_; + const char* time_range_value_; + const char* time_range_unit_; + long overwriteStepUnits_; }; diff --git a/src/accessor/grib_accessor_class_pack_bufr_values.cc b/src/accessor/grib_accessor_class_pack_bufr_values.cc index 810287614..a80d9735f 100644 --- a/src/accessor/grib_accessor_class_pack_bufr_values.cc +++ b/src/accessor/grib_accessor_class_pack_bufr_values.cc @@ -10,73 +10,67 @@ #include "grib_accessor_class_pack_bufr_values.h" -grib_accessor_class_pack_bufr_values_t _grib_accessor_class_pack_bufr_values{ "pack_bufr_values" }; -grib_accessor_class* grib_accessor_class_pack_bufr_values = &_grib_accessor_class_pack_bufr_values; +grib_accessor_pack_bufr_values_t _grib_accessor_pack_bufr_values{}; +grib_accessor* grib_accessor_pack_bufr_values = &_grib_accessor_pack_bufr_values; - -void grib_accessor_class_pack_bufr_values_t::init(grib_accessor* a, const long len, grib_arguments* params) +void grib_accessor_pack_bufr_values_t::init(const long len, grib_arguments* params) { - grib_accessor_class_gen_t::init(a, len, params); + grib_accessor_gen_t::init(len, params); char* key; - grib_accessor_pack_bufr_values_t* self = (grib_accessor_pack_bufr_values_t*)a; - key = (char*)grib_arguments_get_name(grib_handle_of_accessor(a), params, 0); - self->data_accessor = grib_find_accessor(grib_handle_of_accessor(a), key); + key = (char*)grib_arguments_get_name(grib_handle_of_accessor(this), params, 0); + data_accessor_ = grib_find_accessor(grib_handle_of_accessor(this), key); - a->length = 0; + length_ = 0; } -void grib_accessor_class_pack_bufr_values_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_pack_bufr_values_t::dump(grib_dumper* dumper) { } -int grib_accessor_class_pack_bufr_values_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len) +int grib_accessor_pack_bufr_values_t::unpack_string_array(char** buffer, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_pack_bufr_values_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) +int grib_accessor_pack_bufr_values_t::unpack_string(char* buffer, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_pack_bufr_values_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_pack_bufr_values_t::unpack_long(long* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_pack_bufr_values_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_pack_bufr_values_t::unpack_double(double* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_pack_bufr_values_t::value_count(grib_accessor* a, long* count) +int grib_accessor_pack_bufr_values_t::value_count(long* count) { *count = 1; return 0; } -void grib_accessor_class_pack_bufr_values_t::destroy(grib_context* context, grib_accessor* a) +void grib_accessor_pack_bufr_values_t::destroy(grib_context* context) { - grib_accessor_class_gen_t::destroy(context, a); + grib_accessor_gen_t::destroy(context); } -int grib_accessor_class_pack_bufr_values_t::get_native_type(grib_accessor* a) +long grib_accessor_pack_bufr_values_t::get_native_type() { return GRIB_TYPE_LONG; } -int grib_accessor_class_pack_bufr_values_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_pack_bufr_values_t::pack_long(const long* val, size_t* len) { - grib_accessor_pack_bufr_values_t* self = (grib_accessor_pack_bufr_values_t*)a; - grib_accessor* data = (grib_accessor*)self->data_accessor; - + grib_accessor* data = (grib_accessor*)data_accessor_; return data->pack_double(0, 0); } -int grib_accessor_class_pack_bufr_values_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_pack_bufr_values_t::pack_double(const double* val, size_t* len) { - grib_accessor_pack_bufr_values_t* self = (grib_accessor_pack_bufr_values_t*)a; - grib_accessor* data = (grib_accessor*)self->data_accessor; - + grib_accessor* data = (grib_accessor*)data_accessor_; return data->pack_double(0, 0); } diff --git a/src/accessor/grib_accessor_class_pack_bufr_values.h b/src/accessor/grib_accessor_class_pack_bufr_values.h index 0a59a5141..3aeaf7750 100644 --- a/src/accessor/grib_accessor_class_pack_bufr_values.h +++ b/src/accessor/grib_accessor_class_pack_bufr_values.h @@ -16,24 +16,21 @@ class grib_accessor_pack_bufr_values_t : public grib_accessor_gen_t { public: - /* Members defined in pack_bufr_values */ - grib_accessor* data_accessor; -}; - -class grib_accessor_class_pack_bufr_values_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_pack_bufr_values_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_pack_bufr_values_t() : + grib_accessor_gen_t() { class_name_ = "pack_bufr_values"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_pack_bufr_values_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; - 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; + long get_native_type() override; + int pack_double(const double* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + int unpack_string_array(char**, size_t* len) override; + int value_count(long*) override; + void destroy(grib_context*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +private: + grib_accessor* data_accessor_; }; diff --git a/src/accessor/grib_accessor_class_packing_type.cc b/src/accessor/grib_accessor_class_packing_type.cc index 50ac9540d..1abc8d5ef 100644 --- a/src/accessor/grib_accessor_class_packing_type.cc +++ b/src/accessor/grib_accessor_class_packing_type.cc @@ -10,58 +10,54 @@ #include "grib_accessor_class_packing_type.h" -grib_accessor_class_packing_type_t _grib_accessor_class_packing_type{ "packing_type" }; -grib_accessor_class* grib_accessor_class_packing_type = &_grib_accessor_class_packing_type; +grib_accessor_packing_type_t _grib_accessor_packing_type{}; +grib_accessor* grib_accessor_packing_type = &_grib_accessor_packing_type; - -void grib_accessor_class_packing_type_t::init(grib_accessor* a, const long l, grib_arguments* args) +void grib_accessor_packing_type_t::init(const long l, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, l, args); - int n = 0; - grib_accessor_packing_type_t* self = (grib_accessor_packing_type_t*)a; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->packing_type = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; + grib_accessor_gen_t::init(l, args); + int n = 0; + values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + packing_type_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + length_ = 0; } -size_t grib_accessor_class_packing_type_t::string_length(grib_accessor* a) +size_t grib_accessor_packing_type_t::string_length() { return 1024; } -int grib_accessor_class_packing_type_t::get_native_type(grib_accessor* a) +long grib_accessor_packing_type_t::get_native_type() { return GRIB_TYPE_STRING; } -int grib_accessor_class_packing_type_t::pack_string(grib_accessor* a, const char* sval, size_t* len) +int grib_accessor_packing_type_t::pack_string(const char* sval, size_t* len) { - grib_accessor_packing_type_t* self = (grib_accessor_packing_type_t*)a; - - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); double* values = NULL; - grib_context* c = a->context; + grib_context* c = context_; size_t size = 0; int err = 0; - if ((err = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + if ((err = grib_get_size(h, values_, &size)) != GRIB_SUCCESS) return err; 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) { + if ((err = grib_get_double_array_internal(h, values_, values, &size)) != GRIB_SUCCESS) { grib_context_free(c, values); return err; } - if ((err = grib_set_string_internal(h, self->packing_type, sval, len)) != GRIB_SUCCESS) { + if ((err = grib_set_string_internal(h, packing_type_, sval, len)) != GRIB_SUCCESS) { grib_context_free(c, values); return err; } - if ((err = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) { + if ((err = grib_set_double_array_internal(h, values_, values, size)) != GRIB_SUCCESS) { grib_context_free(c, values); return err; } @@ -70,10 +66,9 @@ int grib_accessor_class_packing_type_t::pack_string(grib_accessor* a, const char return GRIB_SUCCESS; } -int grib_accessor_class_packing_type_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_packing_type_t::unpack_string(char* val, size_t* len) { - grib_accessor_packing_type_t* self = (grib_accessor_packing_type_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); - return grib_get_string(h, self->packing_type, val, len); + return grib_get_string(h, packing_type_, val, len); } diff --git a/src/accessor/grib_accessor_class_packing_type.h b/src/accessor/grib_accessor_class_packing_type.h index 7deb8f4cf..46590b565 100644 --- a/src/accessor/grib_accessor_class_packing_type.h +++ b/src/accessor/grib_accessor_class_packing_type.h @@ -16,19 +16,16 @@ class grib_accessor_packing_type_t : public grib_accessor_gen_t { public: - /* Members defined in packing_type */ - const char* values; - const char* packing_type; -}; - -class grib_accessor_class_packing_type_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_packing_type_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_packing_type_t() : + grib_accessor_gen_t() { class_name_ = "packing_type"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_packing_type_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; - size_t string_length(grib_accessor*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int pack_string(const char*, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + void init(const long, grib_arguments*) override; + +private: + const char* values_; + const char* packing_type_; }; diff --git a/src/accessor/grib_accessor_class_pad.cc b/src/accessor/grib_accessor_class_pad.cc index df83c4d5e..dbc151288 100644 --- a/src/accessor/grib_accessor_class_pad.cc +++ b/src/accessor/grib_accessor_class_pad.cc @@ -10,25 +10,22 @@ #include "grib_accessor_class_pad.h" -grib_accessor_class_pad_t _grib_accessor_class_pad{ "pad" }; -grib_accessor_class* grib_accessor_class_pad = &_grib_accessor_class_pad; +grib_accessor_pad_t _grib_accessor_pad{}; +grib_accessor* grib_accessor_pad = &_grib_accessor_pad; - -void grib_accessor_class_pad_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_pad_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_padding_t::init(a, len, arg); - grib_accessor_pad_t* self = (grib_accessor_pad_t*)a; + grib_accessor_padding_t::init(len, arg); - self->expression = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, 0); - a->length = preferred_size(a, 1); + expression_ = grib_arguments_get_expression(grib_handle_of_accessor(this), arg, 0); + length_ = preferred_size(1); } -size_t grib_accessor_class_pad_t::preferred_size(grib_accessor* a, int from_handle) +size_t grib_accessor_pad_t::preferred_size(int from_handle) { - grib_accessor_pad_t* self = (grib_accessor_pad_t*)a; long length = 0; - grib_expression_evaluate_long(grib_handle_of_accessor(a), self->expression, &length); + grib_expression_evaluate_long(grib_handle_of_accessor(this), expression_, &length); return length > 0 ? length : 0; } diff --git a/src/accessor/grib_accessor_class_pad.h b/src/accessor/grib_accessor_class_pad.h index 5234e73a5..72b85d8fe 100644 --- a/src/accessor/grib_accessor_class_pad.h +++ b/src/accessor/grib_accessor_class_pad.h @@ -16,16 +16,12 @@ class grib_accessor_pad_t : public grib_accessor_padding_t { public: - /* Members defined in padding */ - /* Members defined in pad */ - grib_expression* expression; -}; - -class grib_accessor_class_pad_t : public grib_accessor_class_padding_t -{ -public: - grib_accessor_class_pad_t(const char* name) : grib_accessor_class_padding_t(name) {} + grib_accessor_pad_t() : + grib_accessor_padding_t() { class_name_ = "pad"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_pad_t{}; } - void init(grib_accessor*, const long, grib_arguments*) override; - size_t preferred_size(grib_accessor*, int) override; + void init(const long, grib_arguments*) override; + size_t preferred_size(int) override; + +private: + grib_expression* expression_; }; diff --git a/src/accessor/grib_accessor_class_padding.cc b/src/accessor/grib_accessor_class_padding.cc index 226e4b75b..e70c93147 100644 --- a/src/accessor/grib_accessor_class_padding.cc +++ b/src/accessor/grib_accessor_class_padding.cc @@ -10,55 +10,54 @@ #include "grib_accessor_class_padding.h" -grib_accessor_class_padding_t _grib_accessor_class_padding{ "padding" }; -grib_accessor_class* grib_accessor_class_padding = &_grib_accessor_class_padding; +grib_accessor_padding_t _grib_accessor_padding{}; +grib_accessor* grib_accessor_padding = &_grib_accessor_padding; - -void grib_accessor_class_padding_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_padding_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_bytes_t::init(a, len, arg); - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + grib_accessor_bytes_t::init(len, arg); + flags_ |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_padding_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_padding_t::compare(grib_accessor* b) { - if (a->length != b->length) + if (length_ != b->length_) return GRIB_COUNT_MISMATCH; return GRIB_SUCCESS; } -void grib_accessor_class_padding_t::update_size(grib_accessor* a, size_t new_size) +void grib_accessor_padding_t::update_size(size_t new_size) { - a->length = new_size; + length_ = new_size; } -void grib_accessor_class_padding_t::resize(grib_accessor* a, size_t new_size) +void grib_accessor_padding_t::resize(size_t new_size) { - void* zero = grib_context_malloc_clear(a->context, new_size); + void* zero = grib_context_malloc_clear(context_, new_size); - grib_buffer_replace(a, (const unsigned char*)zero, new_size, + grib_buffer_replace(this, (const unsigned char*)zero, new_size, /*update_lengths=*/1, /*update_paddings=*/0); - grib_context_free(a->context, zero); + grib_context_free(context_, zero); - grib_context_log(a->context, GRIB_LOG_DEBUG, - "grib_accessor_class_padding::resize new_size=%zu a->length=%ld %s %s", - new_size, a->length, a->cclass->name, a->name); - Assert(new_size == a->length); + grib_context_log(context_, GRIB_LOG_DEBUG, + "grib_accessor_padding::resize new_size=%zu length_ =%ld %s %s", + new_size, length_, class_name_, name_); + Assert(new_size == length_); } -int grib_accessor_class_padding_t::value_count(grib_accessor* a, long* c) +int grib_accessor_padding_t::value_count(long* c) { - *c = a->length; + *c = length_; return 0; } -long grib_accessor_class_padding_t::byte_count(grib_accessor* a) +long grib_accessor_padding_t::byte_count() { - return a->length; + return length_; } -size_t grib_accessor_class_padding_t::string_length(grib_accessor* a) +size_t grib_accessor_padding_t::string_length() { - return (size_t)a->length; + return (size_t)length_; } diff --git a/src/accessor/grib_accessor_class_padding.h b/src/accessor/grib_accessor_class_padding.h index 6d4175de3..5b3e64f2b 100644 --- a/src/accessor/grib_accessor_class_padding.h +++ b/src/accessor/grib_accessor_class_padding.h @@ -16,19 +16,14 @@ class grib_accessor_padding_t : public grib_accessor_bytes_t { public: - /* Members defined in padding */ -}; - -class grib_accessor_class_padding_t : public grib_accessor_class_bytes_t -{ -public: - grib_accessor_class_padding_t(const char* name) : grib_accessor_class_bytes_t(name) {} + grib_accessor_padding_t() : + grib_accessor_bytes_t() { class_name_ = "padding"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_padding_t{}; } - size_t string_length(grib_accessor*) override; - long byte_count(grib_accessor*) override; - int value_count(grib_accessor*, long*) override; - void init(grib_accessor*, const long, grib_arguments*) override; - void update_size(grib_accessor*, size_t) override; - void resize(grib_accessor*,size_t) override; - int compare(grib_accessor*, grib_accessor*) override; + size_t string_length() override; + long byte_count() override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + void update_size(size_t) override; + void resize(size_t) override; + int compare(grib_accessor*) override; }; diff --git a/src/accessor/grib_accessor_class_padto.cc b/src/accessor/grib_accessor_class_padto.cc index 4fa523acd..2f496e640 100644 --- a/src/accessor/grib_accessor_class_padto.cc +++ b/src/accessor/grib_accessor_class_padto.cc @@ -10,36 +10,32 @@ #include "grib_accessor_class_padto.h" -grib_accessor_class_padto_t _grib_accessor_class_padto{ "padto" }; -grib_accessor_class* grib_accessor_class_padto = &_grib_accessor_class_padto; +grib_accessor_padto_t _grib_accessor_padto{}; +grib_accessor* grib_accessor_padto = &_grib_accessor_padto; - -size_t grib_accessor_class_padto_t::preferred_size(grib_accessor* a, int from_handle) +size_t grib_accessor_padto_t::preferred_size(int from_handle) { - grib_accessor_padto_t* self = (grib_accessor_padto_t*)a; - long length = 0; long theEnd; - grib_expression_evaluate_long(grib_handle_of_accessor(a), self->expression, &theEnd); + grib_expression_evaluate_long(grib_handle_of_accessor(this), expression_, &theEnd); - length = theEnd - a->offset; + length = theEnd - offset_; - //printf("preferred_size: prefered: %ld current:%ld %s %s %ld\n", (long)length,(long)a->length,a->cclass->name,a->name,(long)a->offset); + /* printf("preferred_size: prefered: %ld current:%ld %s %s %ld\n", (long)length,(long)a->length,a->cclass->name,a->name,(long)offset_ ); */ return length > 0 ? length : 0; } -void grib_accessor_class_padto_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_padto_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_padding_t::init(a, len, arg); - grib_accessor_padto_t* self = (grib_accessor_padto_t*)a; + grib_accessor_padding_t::init(len, arg); - self->expression = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, 0); - a->length = preferred_size(a, 1); + expression_ = grib_arguments_get_expression(grib_handle_of_accessor(this), arg, 0); + length_ = preferred_size(1); } -void grib_accessor_class_padto_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_padto_t::dump(grib_dumper* dumper) { - //grib_dump_string(dumper,a,NULL); + /*grib_dump_string(dumper,a,NULL);*/ } diff --git a/src/accessor/grib_accessor_class_padto.h b/src/accessor/grib_accessor_class_padto.h index a1b7b398a..84ecd9623 100644 --- a/src/accessor/grib_accessor_class_padto.h +++ b/src/accessor/grib_accessor_class_padto.h @@ -16,16 +16,13 @@ class grib_accessor_padto_t : public grib_accessor_padding_t { public: - /* Members defined in padto */ - grib_expression* expression; -}; - -class grib_accessor_class_padto_t : public grib_accessor_class_padding_t -{ -public: - grib_accessor_class_padto_t(const char* name) : grib_accessor_class_padding_t(name) {} + grib_accessor_padto_t() : + grib_accessor_padding_t() { class_name_ = "padto"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_padto_t{}; } - void dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; - size_t preferred_size(grib_accessor*, int) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + size_t preferred_size(int) override; + +private: + grib_expression* expression_; }; diff --git a/src/accessor/grib_accessor_class_padtoeven.cc b/src/accessor/grib_accessor_class_padtoeven.cc index b91a9fb51..af1865173 100644 --- a/src/accessor/grib_accessor_class_padtoeven.cc +++ b/src/accessor/grib_accessor_class_padtoeven.cc @@ -10,40 +10,37 @@ #include "grib_accessor_class_padtoeven.h" -grib_accessor_class_padtoeven_t _grib_accessor_class_padtoeven{ "padtoeven" }; -grib_accessor_class* grib_accessor_class_padtoeven = &_grib_accessor_class_padtoeven; +grib_accessor_padtoeven_t _grib_accessor_padtoeven{}; +grib_accessor* grib_accessor_padtoeven = &_grib_accessor_padtoeven; - -size_t grib_accessor_class_padtoeven_t::preferred_size(grib_accessor* a, int from_handle) +size_t grib_accessor_padtoeven_t::preferred_size(int from_handle) { - grib_accessor_padtoeven_t* self = (grib_accessor_padtoeven_t*)a; - long offset = 0; - long length = 0; + long offset = 0; + long length = 0; long seclen; - grib_get_long_internal(grib_handle_of_accessor(a), self->section_offset, &offset); - grib_get_long_internal(grib_handle_of_accessor(a), self->section_length, &length); + grib_get_long_internal(grib_handle_of_accessor(this), section_offset_, &offset); + grib_get_long_internal(grib_handle_of_accessor(this), section_length_, &length); if ((length % 2) && from_handle) { - // grib_context_log(a->context, + // grib_context_log(context_ , // GRIB_LOG_ERROR,"GRIB message has an odd length section (%ld, %s)", - // (long)length,a->name); + // (long)length,name_ ); return 0; } - // printf("EVEN %ld %ld\n",(long) a->offset,(long) offset); - seclen = a->offset - offset; + /* printf("EVEN %ld %ld\n",(long) offset_ ,(long) offset);*/ + seclen = offset_ - offset; return (seclen % 2) ? 1 : 0; } -void grib_accessor_class_padtoeven_t::init(grib_accessor* a, const long len, grib_arguments* args) +void grib_accessor_padtoeven_t::init(const long len, grib_arguments* args) { - grib_accessor_class_padding_t::init(a, len, args); - grib_accessor_padtoeven_t* self = (grib_accessor_padtoeven_t*)a; + grib_accessor_padding_t::init(len, args); - self->section_offset = grib_arguments_get_name(grib_handle_of_accessor(a), args, 0); - self->section_length = grib_arguments_get_name(grib_handle_of_accessor(a), args, 1); + section_offset_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, 0); + section_length_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, 1); - a->length = preferred_size(a, 1); + length_ = preferred_size(1); } diff --git a/src/accessor/grib_accessor_class_padtoeven.h b/src/accessor/grib_accessor_class_padtoeven.h index 9f42f5880..e9415a3b5 100644 --- a/src/accessor/grib_accessor_class_padtoeven.h +++ b/src/accessor/grib_accessor_class_padtoeven.h @@ -16,16 +16,13 @@ class grib_accessor_padtoeven_t : public grib_accessor_padding_t { public: - /* Members defined in padtoeven */ - const char* section_offset; - const char* section_length; -}; - -class grib_accessor_class_padtoeven_t : public grib_accessor_class_padding_t -{ -public: - grib_accessor_class_padtoeven_t(const char* name) : grib_accessor_class_padding_t(name) {} + grib_accessor_padtoeven_t() : + grib_accessor_padding_t() { class_name_ = "padtoeven"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_padtoeven_t{}; } - void init(grib_accessor*, const long, grib_arguments*) override; - size_t preferred_size(grib_accessor*, int) override; + void init(const long, grib_arguments*) override; + size_t preferred_size(int) override; + +private: + const char* section_offset_; + const char* section_length_; }; diff --git a/src/accessor/grib_accessor_class_padtomultiple.cc b/src/accessor/grib_accessor_class_padtomultiple.cc index b76c1d78a..0888c526c 100644 --- a/src/accessor/grib_accessor_class_padtomultiple.cc +++ b/src/accessor/grib_accessor_class_padtomultiple.cc @@ -10,32 +10,29 @@ #include "grib_accessor_class_padtomultiple.h" -grib_accessor_class_padtomultiple_t _grib_accessor_class_padtomultiple{ "padtomultiple" }; -grib_accessor_class* grib_accessor_class_padtomultiple = &_grib_accessor_class_padtomultiple; +grib_accessor_padtomultiple_t _grib_accessor_padtomultiple{}; +grib_accessor* grib_accessor_padtomultiple = &_grib_accessor_padtomultiple; - -size_t grib_accessor_class_padtomultiple_t::preferred_size(grib_accessor* a, int from_handle) +size_t grib_accessor_padtomultiple_t::preferred_size(int from_handle) { - grib_accessor_padtomultiple_t* self = (grib_accessor_padtomultiple_t*)a; long padding = 0; long begin = 0; long multiple = 0; - grib_expression_evaluate_long(grib_handle_of_accessor(a), self->begin, &begin); - grib_expression_evaluate_long(grib_handle_of_accessor(a), self->multiple, &multiple); + grib_expression_evaluate_long(grib_handle_of_accessor(this), begin_, &begin); + grib_expression_evaluate_long(grib_handle_of_accessor(this), multiple_, &multiple); - padding = a->offset - begin; + padding = offset_ - begin; padding = ((padding + multiple - 1) / multiple) * multiple - padding; return padding == 0 ? multiple : padding; } -void grib_accessor_class_padtomultiple_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_padtomultiple_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_padding_t::init(a, len, arg); - grib_accessor_padtomultiple_t* self = (grib_accessor_padtomultiple_t*)a; + grib_accessor_padding_t::init(len, arg); - self->begin = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, 0); - self->multiple = grib_arguments_get_expression(grib_handle_of_accessor(a), arg, 1); - a->length = preferred_size(a, 1); + begin_ = grib_arguments_get_expression(grib_handle_of_accessor(this), arg, 0); + multiple_ = grib_arguments_get_expression(grib_handle_of_accessor(this), arg, 1); + length_ = preferred_size(1); } diff --git a/src/accessor/grib_accessor_class_padtomultiple.h b/src/accessor/grib_accessor_class_padtomultiple.h index 1de8e4059..1ba26bf8a 100644 --- a/src/accessor/grib_accessor_class_padtomultiple.h +++ b/src/accessor/grib_accessor_class_padtomultiple.h @@ -16,16 +16,13 @@ class grib_accessor_padtomultiple_t : public grib_accessor_padding_t { public: - /* Members defined in padtomultiple */ - grib_expression* begin; - grib_expression* multiple; -}; - -class grib_accessor_class_padtomultiple_t : public grib_accessor_class_padding_t -{ -public: - grib_accessor_class_padtomultiple_t(const char* name) : grib_accessor_class_padding_t(name) {} + grib_accessor_padtomultiple_t() : + grib_accessor_padding_t() { class_name_ = "padtomultiple"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_padtomultiple_t{}; } - void init(grib_accessor*, const long, grib_arguments*) override; - size_t preferred_size(grib_accessor*, int) override; + void init(const long, grib_arguments*) override; + size_t preferred_size(int) override; + +private: + grib_expression* begin_; + grib_expression* multiple_; }; diff --git a/src/accessor/grib_accessor_class_position.cc b/src/accessor/grib_accessor_class_position.cc index a2c3daacd..148bb11ce 100644 --- a/src/accessor/grib_accessor_class_position.cc +++ b/src/accessor/grib_accessor_class_position.cc @@ -11,44 +11,43 @@ #include "grib_accessor_class_position.h" -grib_accessor_class_position_t _grib_accessor_class_position{ "position" }; -grib_accessor_class* grib_accessor_class_position = &_grib_accessor_class_position; +grib_accessor_position_t _grib_accessor_position{}; +grib_accessor* grib_accessor_position = &_grib_accessor_position; - -void grib_accessor_class_position_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_position_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + grib_accessor_gen_t::init(len, arg); + length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_HIDDEN; + flags_ |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; } -int grib_accessor_class_position_t::get_native_type(grib_accessor* a) +long grib_accessor_position_t::get_native_type() { return GRIB_TYPE_LONG; } -void grib_accessor_class_position_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_position_t::dump(grib_dumper* dumper) { - grib_dump_long(dumper, a, NULL); + grib_dump_long(dumper, this, NULL); } -int grib_accessor_class_position_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_position_t::unpack_long(long* val, size_t* len) { if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values ", a->name, 1); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values ", name_, 1); *len = 0; return GRIB_ARRAY_TOO_SMALL; } - *val = a->offset; + *val = offset_; *len = 1; return GRIB_SUCCESS; } // static int compare(grib_accessor* a, grib_accessor* b) // { -// if (a->offset != b->offset) +// if (offset_ != b->offset) // return GRIB_OFFSET_MISMATCH; // return GRIB_SUCCESS; // } diff --git a/src/accessor/grib_accessor_class_position.h b/src/accessor/grib_accessor_class_position.h index 58e5beb24..5f20b1ae6 100644 --- a/src/accessor/grib_accessor_class_position.h +++ b/src/accessor/grib_accessor_class_position.h @@ -16,16 +16,11 @@ class grib_accessor_position_t : public grib_accessor_gen_t { public: - /* Members defined in position */ -}; - -class grib_accessor_class_position_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_position_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_position_t() : + grib_accessor_gen_t() { class_name_ = "position"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_position_t{}; } - int get_native_type(grib_accessor*) 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; + long get_native_type() override; + int unpack_long(long* val, size_t* len) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_proj_string.cc b/src/accessor/grib_accessor_class_proj_string.cc index 03866753d..87471f054 100644 --- a/src/accessor/grib_accessor_class_proj_string.cc +++ b/src/accessor/grib_accessor_class_proj_string.cc @@ -11,24 +11,22 @@ #include "grib_accessor_class_proj_string.h" -grib_accessor_class_proj_string_t _grib_accessor_class_proj_string{ "proj_string" }; -grib_accessor_class* grib_accessor_class_proj_string = &_grib_accessor_class_proj_string; +grib_accessor_proj_string_t _grib_accessor_proj_string{}; +grib_accessor* grib_accessor_proj_string = &_grib_accessor_proj_string; - -void grib_accessor_class_proj_string_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_proj_string_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - grib_accessor_proj_string_t* self = (grib_accessor_proj_string_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_gen_t::init(len, arg); + grib_handle* h = grib_handle_of_accessor(this); - self->grid_type = grib_arguments_get_name(h, arg, 0); - self->endpoint = grib_arguments_get_long(h, arg, 1); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + grid_type_ = grib_arguments_get_name(h, arg, 0); + endpoint_ = grib_arguments_get_long(h, arg, 1); + length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; } -int grib_accessor_class_proj_string_t::get_native_type(grib_accessor* a) +long grib_accessor_proj_string_t::get_native_type() { return GRIB_TYPE_STRING; } @@ -105,7 +103,9 @@ static int proj_equatorial_azimuthal_equidistant(grib_handle* h, char* result) static int proj_lambert_conformal(grib_handle* h, char* result) { int err = 0; - char shape[128] = {0,}; + char shape[128] = { + 0, + }; double LoVInDegrees = 0, LaDInDegrees = 0, Latin1InDegrees = 0, Latin2InDegrees = 0; if ((err = get_earth_shape(h, shape)) != GRIB_SUCCESS) @@ -126,7 +126,9 @@ static int proj_lambert_conformal(grib_handle* h, char* result) static int proj_lambert_azimuthal_equal_area(grib_handle* h, char* result) { int err = 0; - char shape[128] = {0,}; + char shape[128] = { + 0, + }; double standardParallel = 0, centralLongitude = 0; if ((err = get_earth_shape(h, shape)) != GRIB_SUCCESS) @@ -146,7 +148,9 @@ static int proj_polar_stereographic(grib_handle* h, char* result) double centralLongitude = 0, centralLatitude = 0; int has_northPole = 0; long projectionCentreFlag = 0; - char shape[128] = {0,}; + char shape[128] = { + 0, + }; if ((err = get_earth_shape(h, shape)) != GRIB_SUCCESS) return err; @@ -179,7 +183,9 @@ static int proj_mercator(grib_handle* h, char* result) { int err = 0; double LaDInDegrees = 0; - char shape[128] = {0,}; + char shape[128] = { + 0, + }; if ((err = grib_get_double_internal(h, "LaDInDegrees", &LaDInDegrees)) != GRIB_SUCCESS) return err; @@ -208,28 +214,29 @@ static proj_mapping proj_mappings[] = { #define ENDPOINT_SOURCE 0 #define ENDPOINT_TARGET 1 -int grib_accessor_class_proj_string_t::unpack_string(grib_accessor* a, char* v, size_t* len) +int grib_accessor_proj_string_t::unpack_string(char* v, size_t* len) { - grib_accessor_proj_string_t* self = (grib_accessor_proj_string_t*)a; int err = 0, found = 0; size_t i = 0; - char grid_type[64] = {0,}; - grib_handle* h = grib_handle_of_accessor(a); + char grid_type[64] = { + 0, + }; + grib_handle* h = grib_handle_of_accessor(this); size_t size = sizeof(grid_type) / sizeof(*grid_type); - Assert(self->endpoint == ENDPOINT_SOURCE || self->endpoint == ENDPOINT_TARGET); + Assert(endpoint_ == ENDPOINT_SOURCE || endpoint_ == ENDPOINT_TARGET); size_t l = 100; // Safe bet if (*len < l) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, + const char* cclass_name = class_name_; + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is at least %zu bytes long (len=%zu)", - cclass_name, a->name, l, *len); + cclass_name, name_, l, *len); *len = l; return GRIB_BUFFER_TOO_SMALL; } - err = grib_get_string(h, self->grid_type, grid_type, &size); + err = grib_get_string(h, grid_type_, grid_type, &size); if (err) return err; const size_t num_proj_mappings = sizeof(proj_mappings) / sizeof(proj_mappings[0]); @@ -237,7 +244,7 @@ int grib_accessor_class_proj_string_t::unpack_string(grib_accessor* a, char* v, proj_mapping pm = proj_mappings[i]; if (strcmp(grid_type, pm.gridType) == 0) { found = 1; - if (self->endpoint == ENDPOINT_SOURCE) { + if (endpoint_ == ENDPOINT_SOURCE) { snprintf(v, 64, "EPSG:4326"); } else { diff --git a/src/accessor/grib_accessor_class_proj_string.h b/src/accessor/grib_accessor_class_proj_string.h index e214c32a9..47d5b41c1 100644 --- a/src/accessor/grib_accessor_class_proj_string.h +++ b/src/accessor/grib_accessor_class_proj_string.h @@ -16,17 +16,14 @@ class grib_accessor_proj_string_t : public grib_accessor_gen_t { public: - /* Members defined in proj_string */ - const char* grid_type; - int endpoint; -}; - -class grib_accessor_class_proj_string_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_proj_string_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_proj_string_t() : + grib_accessor_gen_t() { class_name_ = "proj_string"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_proj_string_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; + long get_native_type() override; + int unpack_string(char*, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* grid_type_; + int endpoint_; }; diff --git a/src/accessor/grib_accessor_class_raw.cc b/src/accessor/grib_accessor_class_raw.cc index cf1f502c7..11b434678 100644 --- a/src/accessor/grib_accessor_class_raw.cc +++ b/src/accessor/grib_accessor_class_raw.cc @@ -11,49 +11,46 @@ #include "grib_accessor_class_raw.h" -grib_accessor_class_raw_t _grib_accessor_class_raw{ "raw" }; -grib_accessor_class* grib_accessor_class_raw = &_grib_accessor_class_raw; +grib_accessor_raw_t _grib_accessor_raw{}; +grib_accessor* grib_accessor_raw = &_grib_accessor_raw; - -void grib_accessor_class_raw_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_raw_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); + grib_accessor_gen_t::init(len, arg); int n = 0; int err = 0; long sectionLength; - grib_accessor_raw_t* self = (grib_accessor_raw_t*)a; grib_expression* e; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); - a->length = 0; - self->totalLength = grib_arguments_get_name(hand, arg, n++); - self->sectionLength = grib_arguments_get_name(hand, arg, n++); + length_ = 0; + totalLength_ = grib_arguments_get_name(hand, arg, n++); + sectionLength_ = grib_arguments_get_name(hand, arg, n++); e = grib_arguments_get_expression(hand, arg, n++); - err = grib_expression_evaluate_long(hand, e, &(self->relativeOffset)); + err = grib_expression_evaluate_long(hand, e, &(relativeOffset_)); if (err) grib_context_log(hand->context, GRIB_LOG_ERROR, "Unable to evaluate relativeOffset"); - grib_get_long(hand, self->sectionLength, §ionLength); + grib_get_long(hand, sectionLength_, §ionLength); - a->length = sectionLength - self->relativeOffset; - if (a->length < 0) - a->length = 0; + length_ = sectionLength - relativeOffset_; + if (length_ < 0) + length_ = 0; - /* Assert(a->length>=0); */ + /* Assert(length_ >=0); */ } -int grib_accessor_class_raw_t::get_native_type(grib_accessor* a) +long grib_accessor_raw_t::get_native_type() { return GRIB_TYPE_BYTES; } - -int grib_accessor_class_raw_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_raw_t::compare(grib_accessor* b) { int retval = GRIB_SUCCESS; - size_t alen = (size_t)a->byte_count(); + size_t alen = (size_t)byte_count(); size_t blen = (size_t)b->byte_count(); if (alen != blen) return GRIB_COUNT_MISMATCH; @@ -61,66 +58,65 @@ int grib_accessor_class_raw_t::compare(grib_accessor* a, grib_accessor* b) return retval; } -long grib_accessor_class_raw_t::byte_count(grib_accessor* a) +long grib_accessor_raw_t::byte_count() { - return a->length; + return length_; } -int grib_accessor_class_raw_t::value_count(grib_accessor* a, long* len) +int grib_accessor_raw_t::value_count(long* len) { - *len = a->length; + *len = length_; return 0; } -int grib_accessor_class_raw_t::unpack_bytes(grib_accessor* a, unsigned char* buffer, size_t* len) +int grib_accessor_raw_t::unpack_bytes(unsigned char* buffer, size_t* len) { - if (*len < a->length) { - *len = a->length; + if (*len < length_) { + *len = length_; return GRIB_ARRAY_TOO_SMALL; } - *len = a->length; + *len = length_; - memcpy(buffer, grib_handle_of_accessor(a)->buffer->data + a->offset, *len); + memcpy(buffer, grib_handle_of_accessor(this)->buffer->data + offset_, *len); return GRIB_SUCCESS; } -void grib_accessor_class_raw_t::update_size(grib_accessor* a, size_t s) +void grib_accessor_raw_t::update_size(size_t s) { - grib_context_log(a->context, GRIB_LOG_DEBUG, "updating size of %s old %ld new %ld", a->name, a->length, s); - a->length = s; - Assert(a->length >= 0); + grib_context_log(context_, GRIB_LOG_DEBUG, "updating size of %s old %ld new %ld", name_, length_, s); + length_ = s; + Assert(length_ >= 0); } void accessor_raw_set_length(grib_accessor* a, size_t len) { - a->length = len; + a->length_ = len; } long accessor_raw_get_offset(grib_accessor* a) { - return a->offset; + return a->offset_; } -int grib_accessor_class_raw_t::pack_bytes(grib_accessor* a, const unsigned char* val, size_t* len) +int grib_accessor_raw_t::pack_bytes(const unsigned char* val, size_t* len) { size_t length = *len; long totalLength; long sectionLength; - grib_handle* h = grib_handle_of_accessor(a); - grib_accessor_raw_t* self = (grib_accessor_raw_t*)a; - long dlen = length - a->length; + grib_handle* h = grib_handle_of_accessor(this); + long dlen = length - length_; - grib_get_long(h, self->totalLength, &totalLength); + grib_get_long(h, totalLength_, &totalLength); totalLength += dlen; - grib_get_long(h, self->sectionLength, §ionLength); + grib_get_long(h, sectionLength_, §ionLength); sectionLength += dlen; - grib_buffer_replace(a, val, length, 1, 1); + grib_buffer_replace(this, val, length, 1, 1); - grib_set_long(h, self->totalLength, totalLength); - grib_set_long(h, self->sectionLength, sectionLength); - a->length = length; + grib_set_long(h, totalLength_, totalLength); + grib_set_long(h, sectionLength_, sectionLength); + length_ = length; return GRIB_SUCCESS; } diff --git a/src/accessor/grib_accessor_class_raw.h b/src/accessor/grib_accessor_class_raw.h index 8a588ac61..e933a63be 100644 --- a/src/accessor/grib_accessor_class_raw.h +++ b/src/accessor/grib_accessor_class_raw.h @@ -16,23 +16,20 @@ class grib_accessor_raw_t : public grib_accessor_gen_t { public: - /* Members defined in raw */ - const char* totalLength; - const char* sectionLength; - long relativeOffset; -}; - -class grib_accessor_class_raw_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_raw_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_raw_t() : + grib_accessor_gen_t() { class_name_ = "raw"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_raw_t{}; } - int get_native_type(grib_accessor*) override; - int pack_bytes(grib_accessor*, const unsigned char*, size_t* len) override; - int unpack_bytes(grib_accessor*, unsigned char*, size_t* len) override; - long byte_count(grib_accessor*) override; - int value_count(grib_accessor*, long*) override; - void init(grib_accessor*, const long, grib_arguments*) override; - void update_size(grib_accessor*, size_t) override; - int compare(grib_accessor*, grib_accessor*) override; + long get_native_type() override; + int pack_bytes(const unsigned char*, size_t* len) override; + int unpack_bytes(unsigned char*, size_t* len) override; + long byte_count() override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + void update_size(size_t) override; + int compare(grib_accessor*) override; + +private: + const char* totalLength_; + const char* sectionLength_; + long relativeOffset_; }; diff --git a/src/accessor/grib_accessor_class_rdbtime_guess_date.cc b/src/accessor/grib_accessor_class_rdbtime_guess_date.cc index f4b317daa..55c545eec 100644 --- a/src/accessor/grib_accessor_class_rdbtime_guess_date.cc +++ b/src/accessor/grib_accessor_class_rdbtime_guess_date.cc @@ -11,42 +11,39 @@ #include "grib_accessor_class_rdbtime_guess_date.h" -grib_accessor_class_rdbtime_guess_date_t _grib_accessor_class_rdbtime_guess_date{"rdbtime_guess_date"}; -grib_accessor_class* grib_accessor_class_rdbtime_guess_date = &_grib_accessor_class_rdbtime_guess_date; +grib_accessor_rdbtime_guess_date_t _grib_accessor_rdbtime_guess_date{}; +grib_accessor* grib_accessor_rdbtime_guess_date = &_grib_accessor_rdbtime_guess_date; - -void grib_accessor_class_rdbtime_guess_date_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_rdbtime_guess_date_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_rdbtime_guess_date_t* self = (grib_accessor_rdbtime_guess_date_t*)a; + grib_accessor_long_t::init(l, c); int n = 0; - self->typicalYear = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->typicalMonth = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->typicalDay = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->rdbDay = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->yearOrMonth = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); + typicalYear_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + typicalMonth_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + typicalDay_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + rdbDay_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + yearOrMonth_ = grib_arguments_get_long(grib_handle_of_accessor(this), c, n++); - /* a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; */ + /* flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; */ } -int grib_accessor_class_rdbtime_guess_date_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_rdbtime_guess_date_t::unpack_long(long* val, size_t* len) { - grib_accessor_rdbtime_guess_date_t* self = (grib_accessor_rdbtime_guess_date_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); long typicalYear, typicalMonth, typicalDay, rdbDay; long rdbYear, rdbMonth; - int ret = grib_get_long(h, self->typicalYear, &typicalYear); + int ret = grib_get_long(h, typicalYear_, &typicalYear); if (ret) return ret; - ret = grib_get_long(h, self->typicalMonth, &typicalMonth); + ret = grib_get_long(h, typicalMonth_, &typicalMonth); if (ret) return ret; - ret = grib_get_long(h, self->typicalDay, &typicalDay); + ret = grib_get_long(h, typicalDay_, &typicalDay); if (ret) return ret; - ret = grib_get_long(h, self->rdbDay, &rdbDay); + ret = grib_get_long(h, rdbDay_, &rdbDay); if (ret) return ret; @@ -65,13 +62,13 @@ int grib_accessor_class_rdbtime_guess_date_t::unpack_long(grib_accessor* a, long rdbMonth = typicalMonth; } - *val = self->yearOrMonth == 1 ? rdbYear : rdbMonth; + *val = yearOrMonth_ == 1 ? rdbYear : rdbMonth; *len = 1; return GRIB_SUCCESS; } -int grib_accessor_class_rdbtime_guess_date_t::pack_long(grib_accessor* a, const long* v, size_t* len) +int grib_accessor_rdbtime_guess_date_t::pack_long(const long* v, size_t* len) { /* do nothing*/ return GRIB_SUCCESS; diff --git a/src/accessor/grib_accessor_class_rdbtime_guess_date.h b/src/accessor/grib_accessor_class_rdbtime_guess_date.h index 739c95e8d..999913b3b 100644 --- a/src/accessor/grib_accessor_class_rdbtime_guess_date.h +++ b/src/accessor/grib_accessor_class_rdbtime_guess_date.h @@ -16,20 +16,17 @@ class grib_accessor_rdbtime_guess_date_t : public grib_accessor_long_t { public: - /* Members defined in rdbtime_guess_date */ - const char* typicalYear; - const char* typicalMonth; - const char* typicalDay; - const char* rdbDay; - long yearOrMonth; -}; - -class grib_accessor_class_rdbtime_guess_date_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_rdbtime_guess_date_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_rdbtime_guess_date_t() : + grib_accessor_long_t() { class_name_ = "rdbtime_guess_date"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_rdbtime_guess_date_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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* typicalYear_; + const char* typicalMonth_; + const char* typicalDay_; + const char* rdbDay_; + long yearOrMonth_; }; diff --git a/src/accessor/grib_accessor_class_reference_value_error.cc b/src/accessor/grib_accessor_class_reference_value_error.cc index fbf1a1c1b..923b9e95b 100644 --- a/src/accessor/grib_accessor_class_reference_value_error.cc +++ b/src/accessor/grib_accessor_class_reference_value_error.cc @@ -11,36 +11,33 @@ #include "grib_accessor_class_reference_value_error.h" -grib_accessor_class_reference_value_error_t _grib_accessor_class_reference_value_error{ "reference_value_error" }; -grib_accessor_class* grib_accessor_class_reference_value_error = &_grib_accessor_class_reference_value_error; +grib_accessor_reference_value_error_t _grib_accessor_reference_value_error{}; +grib_accessor* grib_accessor_reference_value_error = &_grib_accessor_reference_value_error; - -void grib_accessor_class_reference_value_error_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_reference_value_error_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_reference_value_error_t* self = (grib_accessor_reference_value_error_t*)a; + grib_accessor_double_t::init(l, c); int n = 0; - self->referenceValue = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->floatType = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + referenceValue_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + floatType_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + length_ = 0; } -int grib_accessor_class_reference_value_error_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_reference_value_error_t::unpack_double(double* val, size_t* len) { - grib_accessor_reference_value_error_t* self = (grib_accessor_reference_value_error_t*)a; - int ret = GRIB_SUCCESS; + int ret = GRIB_SUCCESS; double referenceValue = 0; - if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), - self->referenceValue, &referenceValue)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(grib_handle_of_accessor(this), + referenceValue_, &referenceValue)) != GRIB_SUCCESS) return ret; - if (!strcmp(self->floatType, "ibm")) + if (!strcmp(floatType_, "ibm")) *val = grib_ibmfloat_error(referenceValue); - else if (!strcmp(self->floatType, "ieee")) + else if (!strcmp(floatType_, "ieee")) *val = grib_ieeefloat_error(referenceValue); else Assert(1 == 0); diff --git a/src/accessor/grib_accessor_class_reference_value_error.h b/src/accessor/grib_accessor_class_reference_value_error.h index 2a470562e..401714ddb 100644 --- a/src/accessor/grib_accessor_class_reference_value_error.h +++ b/src/accessor/grib_accessor_class_reference_value_error.h @@ -16,16 +16,13 @@ class grib_accessor_reference_value_error_t : public grib_accessor_double_t { public: - /* Members defined in reference_value_error */ - const char* referenceValue; - const char* floatType; -}; - -class grib_accessor_class_reference_value_error_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_reference_value_error_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_reference_value_error_t() : + grib_accessor_double_t() { class_name_ = "reference_value_error"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_reference_value_error_t{}; } - int unpack_double(grib_accessor*, double* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_double(double* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* referenceValue_; + const char* floatType_; }; diff --git a/src/accessor/grib_accessor_class_round.cc b/src/accessor/grib_accessor_class_round.cc index e1d6aaeda..80b0f601d 100644 --- a/src/accessor/grib_accessor_class_round.cc +++ b/src/accessor/grib_accessor_class_round.cc @@ -11,14 +11,26 @@ #include "grib_accessor_class_round.h" -grib_accessor_class_round_t _grib_accessor_class_round{ "round" }; -grib_accessor_class* grib_accessor_class_round = &_grib_accessor_class_round; +grib_accessor_round_t _grib_accessor_round{}; +grib_accessor* grib_accessor_round = &_grib_accessor_round; - -int grib_accessor_class_round_t::unpack_double(grib_accessor* a, double* val, size_t* len) +void grib_accessor_round_t::init(const long l, grib_arguments* arg) { - grib_accessor_round_t* self = (grib_accessor_round_t*)a; + grib_accessor_evaluate_t::init(l, arg); +} +void grib_accessor_round_t::destroy(grib_context* c) +{ + grib_accessor_evaluate_t::destroy(c); +} + +void grib_accessor_round_t::dump(grib_dumper* dumper) +{ + grib_accessor_evaluate_t::dump(dumper); +} + +int grib_accessor_round_t::unpack_double(double* val, size_t* len) +{ int ret = GRIB_SUCCESS; size_t replen = 0; @@ -27,12 +39,12 @@ int grib_accessor_class_round_t::unpack_double(grib_accessor* a, double* val, si double toround = 0; const char* oval = NULL; - oval = grib_arguments_get_name(grib_handle_of_accessor(a), self->arg, 0); + oval = grib_arguments_get_name(grib_handle_of_accessor(this), arg_, 0); - if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), oval, &toround)) != 0) + if ((ret = grib_get_double_internal(grib_handle_of_accessor(this), oval, &toround)) != 0) return ret; - rounding_precision = grib_arguments_get_long(grib_handle_of_accessor(a), self->arg, 1); + rounding_precision = grib_arguments_get_long(grib_handle_of_accessor(this), arg_, 1); rounded = floor(rounding_precision * toround + 0.5) / rounding_precision; @@ -43,7 +55,7 @@ int grib_accessor_class_round_t::unpack_double(grib_accessor* a, double* val, si return ret; } -int grib_accessor_class_round_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_round_t::unpack_string(char* val, size_t* len) { char result[1024]; int ret = GRIB_SUCCESS; @@ -51,7 +63,7 @@ int grib_accessor_class_round_t::unpack_string(grib_accessor* a, char* val, size double value = 0; - ret = unpack_double(a, &value, &replen); + ret = unpack_double(&value, &replen); snprintf(result, sizeof(result), "%.3f", value); diff --git a/src/accessor/grib_accessor_class_round.h b/src/accessor/grib_accessor_class_round.h index 364e24b34..d918c4a38 100644 --- a/src/accessor/grib_accessor_class_round.h +++ b/src/accessor/grib_accessor_class_round.h @@ -16,14 +16,12 @@ class grib_accessor_round_t : public grib_accessor_evaluate_t { public: - /* Members defined in round */ -}; - -class grib_accessor_class_round_t : public grib_accessor_class_evaluate_t -{ -public: - grib_accessor_class_round_t(const char* name) : grib_accessor_class_evaluate_t(name) {} + grib_accessor_round_t() : + grib_accessor_evaluate_t() { class_name_ = "round"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_round_t{}; } - int unpack_double(grib_accessor*, double* val, size_t* len) override; - int unpack_string(grib_accessor*, char*, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + void init(const long, grib_arguments*) override; + void destroy(grib_context*) override; + void dump(grib_dumper*) override; }; diff --git a/src/accessor/grib_accessor_class_scale.cc b/src/accessor/grib_accessor_class_scale.cc index 59ab7bfb4..284a9ed51 100644 --- a/src/accessor/grib_accessor_class_scale.cc +++ b/src/accessor/grib_accessor_class_scale.cc @@ -11,45 +11,42 @@ #include "grib_accessor_class_scale.h" -grib_accessor_class_scale_t _grib_accessor_class_scale{ "scale" }; -grib_accessor_class* grib_accessor_class_scale = &_grib_accessor_class_scale; +grib_accessor_scale_t _grib_accessor_scale{}; +grib_accessor* grib_accessor_scale = &_grib_accessor_scale; - -void grib_accessor_class_scale_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_scale_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_scale_t* self = (grib_accessor_scale_t*)a; + grib_accessor_double_t::init(l, c); int n = 0; - self->value = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->multiplier = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->divisor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->truncating = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + value_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + multiplier_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + divisor_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + truncating_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); } -int grib_accessor_class_scale_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_scale_t::unpack_double(double* val, size_t* len) { - grib_accessor_scale_t* self = (grib_accessor_scale_t*)a; - int ret = 0; - long value = 0; - long multiplier = 0; - long divisor = 0; + int ret = 0; + long value = 0; + long multiplier = 0; + long divisor = 0; if (*len < 1) { ret = GRIB_ARRAY_TOO_SMALL; - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "Accessor %s cannot gather value for %s and/or %s", - a->name, self->multiplier, self->divisor); + name_, multiplier, divisor_); return ret; } - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->divisor, &divisor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), divisor_, &divisor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->multiplier, &multiplier)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), multiplier_, &multiplier)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->value, &value)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), value_, &value)) != GRIB_SUCCESS) return ret; if (value == GRIB_MISSING_LONG) @@ -63,15 +60,14 @@ int grib_accessor_class_scale_t::unpack_double(grib_accessor* a, double* val, si return ret; } -int grib_accessor_class_scale_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_scale_t::pack_long(const long* val, size_t* len) { const double dval = (double)*val; - return pack_double(a, &dval, len); + return pack_double(&dval, len); } -int grib_accessor_class_scale_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_scale_t::pack_double(const double* val, size_t* len) { - grib_accessor_scale_t* self = (grib_accessor_scale_t*)a; int ret = 0; long value = 0; @@ -80,20 +76,20 @@ int grib_accessor_class_scale_t::pack_double(grib_accessor* a, const double* val long truncating = 0; double x; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->divisor, &divisor); + ret = grib_get_long_internal(grib_handle_of_accessor(this), divisor_, &divisor); if (ret != GRIB_SUCCESS) return ret; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->multiplier, &multiplier); + ret = grib_get_long_internal(grib_handle_of_accessor(this), multiplier_, &multiplier); if (ret != GRIB_SUCCESS) return ret; - if (self->truncating) { - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->truncating, &truncating); + if (truncating_) { + ret = grib_get_long_internal(grib_handle_of_accessor(this), truncating_, &truncating); if (ret != GRIB_SUCCESS) return ret; } if (multiplier == 0) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s: cannot divide by a zero multiplier %s", - a->name, self->multiplier); + grib_context_log(context_, GRIB_LOG_ERROR, "Accessor %s: cannot divide by a zero multiplier %s", + name_, multiplier_); return GRIB_ENCODING_ERROR; } @@ -107,11 +103,11 @@ int grib_accessor_class_scale_t::pack_double(grib_accessor* a, const double* val value = x > 0 ? (long)(x + 0.5) : (long)(x - 0.5); } - ret = grib_set_long_internal(grib_handle_of_accessor(a), self->value, value); + ret = grib_set_long_internal(grib_handle_of_accessor(this), value_, value); if (ret) - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "Accessor %s: cannot pack value for %s (%s)\n", - a->name, self->value, grib_get_error_message(ret)); + name_, value_, grib_get_error_message(ret)); if (ret == GRIB_SUCCESS) *len = 1; @@ -119,20 +115,19 @@ int grib_accessor_class_scale_t::pack_double(grib_accessor* a, const double* val return ret; } -int grib_accessor_class_scale_t::is_missing(grib_accessor* a) +int grib_accessor_scale_t::is_missing() { - grib_accessor_scale_t* self = (grib_accessor_scale_t*)a; - grib_accessor* av = grib_find_accessor(grib_handle_of_accessor(a), self->value); + grib_accessor* av = grib_find_accessor(grib_handle_of_accessor(this), value_); if (!av) return GRIB_NOT_FOUND; return av->is_missing_internal(); // int ret=0; // long value=0; - // if((ret = grib_get_long_internal(grib_handle_of_accessor(a),self->value, &value))!= GRIB_SUCCESS){ - // grib_context_log(a->context, GRIB_LOG_ERROR, - // "Accessor %s cannot gather value for %s error %d \n", a->name, - // self->value, ret); + // if((ret = grib_get_long_internal(grib_handle_of_accessor(this),value_ , &value))!= GRIB_SUCCESS){ + // grib_context_log(context_ , GRIB_LOG_ERROR, + // "Accessor %s cannot gather value for %s error %d \n", name_ , + // value_ , ret); // return 0; // } // return (value == GRIB_MISSING_LONG); diff --git a/src/accessor/grib_accessor_class_scale.h b/src/accessor/grib_accessor_class_scale.h index 29b65f34b..074b87778 100644 --- a/src/accessor/grib_accessor_class_scale.h +++ b/src/accessor/grib_accessor_class_scale.h @@ -16,21 +16,18 @@ class grib_accessor_scale_t : public grib_accessor_double_t { public: - /* Members defined in scale */ - const char* value; - const char* multiplier; - const char* divisor; - const char* truncating; -}; - -class grib_accessor_class_scale_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_scale_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_scale_t() : + grib_accessor_double_t() { class_name_ = "scale"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_scale_t{}; } - 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 unpack_double(grib_accessor*, double* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int is_missing() override; + int pack_double(const double* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* value_; + const char* multiplier_; + const char* divisor_; + const char* truncating_; }; diff --git a/src/accessor/grib_accessor_class_scale_values.cc b/src/accessor/grib_accessor_class_scale_values.cc index 03072311d..651603254 100644 --- a/src/accessor/grib_accessor_class_scale_values.cc +++ b/src/accessor/grib_accessor_class_scale_values.cc @@ -11,22 +11,20 @@ #include "grib_accessor_class_scale_values.h" -grib_accessor_class_scale_values_t _grib_accessor_class_scale_values{ "scale_values" }; -grib_accessor_class* grib_accessor_class_scale_values = &_grib_accessor_class_scale_values; +grib_accessor_scale_values_t _grib_accessor_scale_values{}; +grib_accessor* grib_accessor_scale_values = &_grib_accessor_scale_values; - -void grib_accessor_class_scale_values_t::init(grib_accessor* a, const long l, grib_arguments* args) +void grib_accessor_scale_values_t::init(const long l, grib_arguments* args) { - grib_accessor_class_double_t::init(a, l, args); - int n = 0; - grib_accessor_scale_values_t* self = (grib_accessor_scale_values_t*)a; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->missingValue = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; + grib_accessor_double_t::init(l, args); + int n = 0; + values_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + missingValue_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + length_ = 0; } -int grib_accessor_class_scale_values_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_scale_values_t::unpack_double(double* val, size_t* len) { int ret = GRIB_SUCCESS; *val = 1; @@ -34,35 +32,34 @@ int grib_accessor_class_scale_values_t::unpack_double(grib_accessor* a, double* return ret; } -int grib_accessor_class_scale_values_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_scale_values_t::pack_double(const double* val, size_t* len) { double* values = NULL; double missingValue = 0; long missingValuesPresent = 0; size_t size = 0; int ret = 0, i = 0; - grib_accessor_scale_values_t* self = (grib_accessor_scale_values_t*)a; - const grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); + const grib_context* c = context_; + grib_handle* h = grib_handle_of_accessor(this); if (*val == 1) return GRIB_SUCCESS; - if ((ret = grib_get_double_internal(h, self->missingValue, &missingValue)) != GRIB_SUCCESS) { + if ((ret = grib_get_double_internal(h, missingValue_, &missingValue)) != GRIB_SUCCESS) { return ret; } if ((ret = grib_get_long_internal(h, "missingValuesPresent", &missingValuesPresent)) != GRIB_SUCCESS) { return ret; } - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + if ((ret = grib_get_size(h, 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) { + if ((ret = grib_get_double_array_internal(h, values_, values, &size)) != GRIB_SUCCESS) { grib_context_free(c, values); return ret; } @@ -77,7 +74,7 @@ int grib_accessor_class_scale_values_t::pack_double(grib_accessor* a, const doub } } - if ((ret = grib_set_double_array_internal(h, self->values, values, size)) != GRIB_SUCCESS) { + if ((ret = grib_set_double_array_internal(h, values_, values, size)) != GRIB_SUCCESS) { grib_context_free(c, values); return ret; } diff --git a/src/accessor/grib_accessor_class_scale_values.h b/src/accessor/grib_accessor_class_scale_values.h index f004db30e..bfed5b5fc 100644 --- a/src/accessor/grib_accessor_class_scale_values.h +++ b/src/accessor/grib_accessor_class_scale_values.h @@ -16,17 +16,14 @@ class grib_accessor_scale_values_t : public grib_accessor_double_t { public: - /* Members defined in scale_values */ - const char* values; - const char* missingValue; -}; - -class grib_accessor_class_scale_values_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_scale_values_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_scale_values_t() : + grib_accessor_double_t() { class_name_ = "scale_values"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_scale_values_t{}; } - int pack_double(grib_accessor*, const double* val, size_t* len) override; - int unpack_double(grib_accessor*, double* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int pack_double(const double* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* values_; + const char* missingValue_; }; diff --git a/src/accessor/grib_accessor_class_second_order_bits_per_value.cc b/src/accessor/grib_accessor_class_second_order_bits_per_value.cc index 8d5f4b99f..1cdad1545 100644 --- a/src/accessor/grib_accessor_class_second_order_bits_per_value.cc +++ b/src/accessor/grib_accessor_class_second_order_bits_per_value.cc @@ -11,9 +11,8 @@ #include "grib_accessor_class_second_order_bits_per_value.h" #include "grib_scaling.h" -grib_accessor_class_second_order_bits_per_value_t _grib_accessor_class_second_order_bits_per_value{ "second_order_bits_per_value" }; -grib_accessor_class* grib_accessor_class_second_order_bits_per_value = &_grib_accessor_class_second_order_bits_per_value; - +grib_accessor_second_order_bits_per_value_t _grib_accessor_second_order_bits_per_value{}; +grib_accessor* grib_accessor_second_order_bits_per_value = &_grib_accessor_second_order_bits_per_value; static const size_t nbits[64] = { 0x1, 0x2, 0x4, 0x8, @@ -38,7 +37,7 @@ static int number_of_bits(size_t x, long* result) { const size_t* n = nbits; const int count = sizeof(nbits) / sizeof(nbits[0]); - *result = 0; + *result = 0; while (x >= *n) { n++; (*result)++; @@ -49,29 +48,27 @@ static int number_of_bits(size_t x, long* result) return GRIB_SUCCESS; } -void grib_accessor_class_second_order_bits_per_value_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_second_order_bits_per_value_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - int n = 0; - grib_accessor_second_order_bits_per_value_t* self = (grib_accessor_second_order_bits_per_value_t*)a; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->binaryScaleFactor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->decimalScaleFactor = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->bitsPerValue = 0; + grib_accessor_long_t::init(l, c); + int n = 0; + values_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + binaryScaleFactor_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + decimalScaleFactor_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + bitsPerValue_ = 0; - a->length = 0; + length_ = 0; } -int grib_accessor_class_second_order_bits_per_value_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_second_order_bits_per_value_t::pack_long(const long* val, size_t* len) { - grib_accessor_second_order_bits_per_value_t* self = (grib_accessor_second_order_bits_per_value_t*)a; - self->bitsPerValue = (long)*val; - *len = 1; + bitsPerValue_ = (long)*val; + *len = 1; return GRIB_SUCCESS; } -int grib_accessor_class_second_order_bits_per_value_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_second_order_bits_per_value_t::unpack_long(long* val, size_t* len) { int ret = GRIB_SUCCESS; size_t size = 0; @@ -80,29 +77,28 @@ int grib_accessor_class_second_order_bits_per_value_t::unpack_long(grib_accessor double* values = 0; long binaryScaleFactor, decimalScaleFactor; - grib_accessor_second_order_bits_per_value_t* self = (grib_accessor_second_order_bits_per_value_t*)a; - if (self->bitsPerValue) { - *val = self->bitsPerValue; + if (bitsPerValue_) { + *val = bitsPerValue_; return GRIB_SUCCESS; } - if ((ret = grib_get_size(grib_handle_of_accessor(a), self->values, &size)) != GRIB_SUCCESS) { - *val = self->bitsPerValue; + if ((ret = grib_get_size(grib_handle_of_accessor(this), values_, &size)) != GRIB_SUCCESS) { + *val = bitsPerValue_; return GRIB_SUCCESS; } - if ((ret = grib_get_long(grib_handle_of_accessor(a), self->binaryScaleFactor, &binaryScaleFactor)) != GRIB_SUCCESS) + if ((ret = grib_get_long(grib_handle_of_accessor(this), binaryScaleFactor_, &binaryScaleFactor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->decimalScaleFactor, &decimalScaleFactor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), decimalScaleFactor_, &decimalScaleFactor)) != GRIB_SUCCESS) return ret; - values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * size); + values = (double*)grib_context_malloc_clear(context_, sizeof(double) * size); if (!values) { - grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Memory allocation error: %zu bytes", a->name, size); + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Memory allocation error: %zu bytes", name_, size); return GRIB_OUT_OF_MEMORY; } - if ((ret = grib_get_double_array_internal(grib_handle_of_accessor(a), self->values, values, &size)) != GRIB_SUCCESS) + if ((ret = grib_get_double_array_internal(grib_handle_of_accessor(this), values_, values, &size)) != GRIB_SUCCESS) return ret; max = values[0]; @@ -117,14 +113,14 @@ int grib_accessor_class_second_order_bits_per_value_t::unpack_long(grib_accessor d = codes_power(decimalScaleFactor, 10); b = codes_power(-binaryScaleFactor, 2); - /* self->bitsPerValue=(long)ceil(log((double)((max-min)*d+1))/log(2.0))-binaryScaleFactor; */ + /* bitsPerValue_ =(long)ceil(log((double)((max-min)*d+1))/log(2.0))-binaryScaleFactor; */ /* See GRIB-540 for why we use ceil */ - ret = number_of_bits((size_t)ceil((fabs(max - min) * b * d)), &(self->bitsPerValue)); + ret = number_of_bits((size_t)ceil((fabs(max - min) * b * d)), &(bitsPerValue_)); if (ret != GRIB_SUCCESS) return ret; - *val = self->bitsPerValue; + *val = bitsPerValue_; - grib_context_free(a->context, values); + grib_context_free(context_, values); return ret; } diff --git a/src/accessor/grib_accessor_class_second_order_bits_per_value.h b/src/accessor/grib_accessor_class_second_order_bits_per_value.h index c3459db41..5bfac2932 100644 --- a/src/accessor/grib_accessor_class_second_order_bits_per_value.h +++ b/src/accessor/grib_accessor_class_second_order_bits_per_value.h @@ -16,19 +16,16 @@ class grib_accessor_second_order_bits_per_value_t : public grib_accessor_long_t { public: - /* Members defined in second_order_bits_per_value */ - const char* values; - const char* binaryScaleFactor; - const char* decimalScaleFactor; - long bitsPerValue; -}; - -class grib_accessor_class_second_order_bits_per_value_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_second_order_bits_per_value_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_second_order_bits_per_value_t() : + grib_accessor_long_t() { class_name_ = "second_order_bits_per_value"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_second_order_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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* values_; + const char* binaryScaleFactor_; + const char* decimalScaleFactor_; + long bitsPerValue_; }; diff --git a/src/accessor/grib_accessor_class_section.cc b/src/accessor/grib_accessor_class_section.cc index 8abb7aa01..7835eefce 100644 --- a/src/accessor/grib_accessor_class_section.cc +++ b/src/accessor/grib_accessor_class_section.cc @@ -10,84 +10,84 @@ #include "grib_accessor_class_section.h" -grib_accessor_class_section_t _grib_accessor_class_section{ "section" }; -grib_accessor_class* grib_accessor_class_section = &_grib_accessor_class_section; +grib_accessor_section_t _grib_accessor_section{}; +grib_accessor* grib_accessor_section = &_grib_accessor_section; - -void grib_accessor_class_section_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_section_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - a->sub_section = grib_section_create(grib_handle_of_accessor(a), a); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + grib_accessor_gen_t::init(len, arg); + sub_section_ = grib_section_create(grib_handle_of_accessor(this), this); + length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -void grib_accessor_class_section_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_section_t::dump(grib_dumper* dumper) { - grib_dump_section(dumper, a, a->sub_section->block); + grib_dump_section(dumper, this, sub_section_->block); } -long grib_accessor_class_section_t::byte_count(grib_accessor* a) +long grib_accessor_section_t::byte_count() { - if (!a->length || grib_handle_of_accessor(a)->loader) { - if (a->name[1] == '_') + if (!length_ || grib_handle_of_accessor(this)->loader) { + if (name_[1] == '_') return 0; - //printf("adjusting sizes SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); - grib_section_adjust_sizes(a->sub_section, grib_handle_of_accessor(a)->loader != NULL, 0); - //printf(" SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)a->length); + /* printf("adjusting sizes SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)length_ ); */ + grib_section_adjust_sizes(sub_section_, grib_handle_of_accessor(this)->loader != NULL, 0); + /* printf(" SECTION %s is %ld %ld\n",a->name,(long)a->offset,(long)length_ ); */ } - // printf("SECTION %s is %ld %d\n",a->name,a->length,a->sub_section->aclength != NULL); - return a->length; + /* printf("SECTION %s is %ld %d\n",a->name,a->length,sub_section_ ->aclength != NULL); */ + return length_; } -long grib_accessor_class_section_t::next_offset(grib_accessor* a) +long grib_accessor_section_t::next_offset() { - return a->offset + a->byte_count(); + return offset_ + byte_count(); } -void grib_accessor_class_section_t::destroy(grib_context* ct, grib_accessor* a) +void grib_accessor_section_t::destroy(grib_context* ct) { - grib_section_delete(ct, a->sub_section); - grib_accessor_class_gen_t::destroy(ct, a); + grib_section_delete(ct, sub_section_); + grib_accessor_gen_t::destroy(ct); } -int grib_accessor_class_section_t::get_native_type(grib_accessor* a) +long grib_accessor_section_t::get_native_type() { return GRIB_TYPE_SECTION; } -grib_section* grib_accessor_class_section_t::sub_section(grib_accessor* a) +grib_section* grib_accessor_section_t::sub_section() { - return a->sub_section; + return sub_section_; } -void grib_accessor_class_section_t::update_size(grib_accessor* a, size_t length) +void grib_accessor_section_t::update_size(size_t length) { size_t size = 1; long len = length; Assert(length <= 0x7fffffff); - if (a->sub_section->aclength) { - int e = a->sub_section->aclength->pack_long(&len, &size); + if (sub_section_->aclength) { + int e = sub_section_->aclength->pack_long(&len, &size); Assert(e == GRIB_SUCCESS); - // printf("update_length %s %ld %ld\n", a->sub_section->aclength->name, - // (long)a->sub_section->aclength->offset, - // (long)a->sub_section->aclength->length); + // printf("update_length %s %ld %ld\n", sub_section_ ->aclength->name, + // (long)sub_section_ ->aclength->offset, + // (long)sub_section_ ->aclength->length); } - a->sub_section->length = a->length = length; - a->sub_section->padding = 0; + sub_section_->length = length_ = length; + sub_section_->padding = 0; - // printf("update_size %s %ld\n", a->name, a->length); - Assert(a->length >= 0); + // printf("update_size %s %ld\n", a->name, length_ ); + + Assert(length_ >= 0); } -grib_accessor* grib_accessor_class_section_t::next(grib_accessor* a, int explore) +grib_accessor* grib_accessor_section_t::next(grib_accessor* a, int explore) { grib_accessor* next = NULL; if (explore) { - next = a->sub_section->block->first; + next = a->sub_section_->block->first; if (!next) next = a->next_; } @@ -95,8 +95,9 @@ grib_accessor* grib_accessor_class_section_t::next(grib_accessor* a, int explore next = a->next_; } if (!next) { - if (a->parent->owner) - next = a->parent->owner->cclass->next(a->parent->owner, 0); + if (a->parent_->owner) + // TODO(maee): check the owner of the parent + next = a->parent_->owner->next(a->parent_->owner, 0); } return next; } diff --git a/src/accessor/grib_accessor_class_section.h b/src/accessor/grib_accessor_class_section.h index 8dbd831cc..92bc2dc29 100644 --- a/src/accessor/grib_accessor_class_section.h +++ b/src/accessor/grib_accessor_class_section.h @@ -13,20 +13,19 @@ #include "grib_accessor_class_gen.h" -class grib_accessor_section_t : public grib_accessor_gen_t {}; - -class grib_accessor_class_section_t : public grib_accessor_class_gen_t +class grib_accessor_section_t : public grib_accessor_gen_t { public: - grib_accessor_class_section_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_section_t() : + grib_accessor_gen_t() { class_name_ = "section"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_section_t{}; } - int get_native_type(grib_accessor*) override; - long byte_count(grib_accessor*) override; - long next_offset(grib_accessor*) override; - void destroy(grib_context*, 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; - grib_section* sub_section(grib_accessor*) override; + long get_native_type() override; + long byte_count() override; + long next_offset() override; + void destroy(grib_context*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + void update_size(size_t) override; + grib_section* sub_section() override; grib_accessor* next(grib_accessor*, int) override; }; diff --git a/src/accessor/grib_accessor_class_section_length.cc b/src/accessor/grib_accessor_class_section_length.cc index 8be4cad56..209a0e872 100644 --- a/src/accessor/grib_accessor_class_section_length.cc +++ b/src/accessor/grib_accessor_class_section_length.cc @@ -10,26 +10,25 @@ #include "grib_accessor_class_section_length.h" -grib_accessor_class_section_length_t _grib_accessor_class_section_length{ "section_length" }; -grib_accessor_class* grib_accessor_class_section_length = &_grib_accessor_class_section_length; +grib_accessor_section_length_t _grib_accessor_section_length{}; +grib_accessor* grib_accessor_section_length = &_grib_accessor_section_length; - -void grib_accessor_class_section_length_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_section_length_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_unsigned_t::init(a, len, arg); - a->parent->aclength = a; - a->length = len; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; - Assert(a->length >= 0); + grib_accessor_unsigned_t::init(len, arg); + parent_->aclength = this; + length_ = len; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + Assert(length_ >= 0); } -void grib_accessor_class_section_length_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_section_length_t::dump(grib_dumper* dumper) { - grib_dump_long(dumper, a, NULL); + grib_dump_long(dumper, this, NULL); } -int grib_accessor_class_section_length_t::value_count(grib_accessor* a, long* c) +int grib_accessor_section_length_t::value_count(long* c) { *c = 1; return 0; diff --git a/src/accessor/grib_accessor_class_section_length.h b/src/accessor/grib_accessor_class_section_length.h index e7965b9b1..adbf355da 100644 --- a/src/accessor/grib_accessor_class_section_length.h +++ b/src/accessor/grib_accessor_class_section_length.h @@ -16,15 +16,10 @@ class grib_accessor_section_length_t : public grib_accessor_unsigned_t { public: - /* Members defined in section_length */ -}; - -class grib_accessor_class_section_length_t : public grib_accessor_class_unsigned_t -{ -public: - grib_accessor_class_section_length_t(const char* name) : grib_accessor_class_unsigned_t(name) {} + grib_accessor_section_length_t() : + grib_accessor_unsigned_t() { class_name_ = "section_length"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_section_length_t{}; } - int value_count(grib_accessor*, long*) override; - void dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int value_count(long*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_section_padding.cc b/src/accessor/grib_accessor_class_section_padding.cc index f811313d6..a1972fe55 100644 --- a/src/accessor/grib_accessor_class_section_padding.cc +++ b/src/accessor/grib_accessor_class_section_padding.cc @@ -10,31 +10,28 @@ #include "grib_accessor_class_section_padding.h" -grib_accessor_class_section_padding_t _grib_accessor_class_section_padding{ "section_padding" }; -grib_accessor_class* grib_accessor_class_section_padding = &_grib_accessor_class_section_padding; +grib_accessor_section_padding_t _grib_accessor_section_padding{}; +grib_accessor* grib_accessor_section_padding = &_grib_accessor_section_padding; - -size_t grib_accessor_class_section_padding_t::preferred_size(grib_accessor* a, int from_handle) +size_t grib_accessor_section_padding_t::preferred_size(int from_handle) { - grib_accessor_section_padding_t* self = (grib_accessor_section_padding_t*)a; - - grib_accessor* b = a; + grib_accessor* b = this; grib_accessor* section_length = 0; long length = 0; size_t size = 1; long alength = 0; if (!from_handle) { - if (self->preserve) - return a->length; + if (preserve_) + return length_; else return 0; } /* The section length should be a parameter */ while (section_length == NULL && b != NULL) { - section_length = b->parent->aclength; - b = b->parent->owner; + section_length = b->parent_->aclength; + b = b->parent_->owner; } if (!section_length) { @@ -44,16 +41,16 @@ size_t grib_accessor_class_section_padding_t::preferred_size(grib_accessor* a, i if (section_length->unpack_long(&length, &size) == GRIB_SUCCESS) { if (length) - alength = length - a->offset + section_length->parent->owner->offset; + alength = length - offset_ + section_length->parent_->owner->offset_; else alength = 0; - /*Assert(a->length>=0);*/ + /*Assert(length_ >=0);*/ if (alength < 0) alength = 0; - /* printf("PADDING is %ld\n",a->length); */ + /* printf("PADDING is %ld\n",length_ ); */ } else { /* printf("PADDING unpack fails\n"); */ @@ -62,10 +59,9 @@ size_t grib_accessor_class_section_padding_t::preferred_size(grib_accessor* a, i return alength; } -void grib_accessor_class_section_padding_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_section_padding_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_padding_t::init(a, len, arg); - grib_accessor_section_padding_t* self = (grib_accessor_section_padding_t*)a; - self->preserve = 1; /* This should be a parameter */ - a->length = preferred_size(a, 1); + grib_accessor_padding_t::init(len, arg); + preserve_ = 1; /* This should be a parameter */ + length_ = preferred_size(1); } diff --git a/src/accessor/grib_accessor_class_section_padding.h b/src/accessor/grib_accessor_class_section_padding.h index f35da4977..6b87449b9 100644 --- a/src/accessor/grib_accessor_class_section_padding.h +++ b/src/accessor/grib_accessor_class_section_padding.h @@ -16,15 +16,12 @@ class grib_accessor_section_padding_t : public grib_accessor_padding_t { public: - /* Members defined in section_padding */ - int preserve; -}; - -class grib_accessor_class_section_padding_t : public grib_accessor_class_padding_t -{ -public: - grib_accessor_class_section_padding_t(const char* name) : grib_accessor_class_padding_t(name) {} + grib_accessor_section_padding_t() : + grib_accessor_padding_t() { class_name_ = "section_padding"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_section_padding_t{}; } - void init(grib_accessor*, const long, grib_arguments*) override; - size_t preferred_size(grib_accessor*, int) override; + void init(const long, grib_arguments*) override; + size_t preferred_size(int) override; + +private: + int preserve_; }; diff --git a/src/accessor/grib_accessor_class_section_pointer.cc b/src/accessor/grib_accessor_class_section_pointer.cc index c7735d504..c584bf7c3 100644 --- a/src/accessor/grib_accessor_class_section_pointer.cc +++ b/src/accessor/grib_accessor_class_section_pointer.cc @@ -10,88 +10,84 @@ #include "grib_accessor_class_section_pointer.h" -grib_accessor_class_section_pointer_t _grib_accessor_class_section_pointer{ "section_pointer" }; -grib_accessor_class* grib_accessor_class_section_pointer = &_grib_accessor_class_section_pointer; +grib_accessor_section_pointer_t _grib_accessor_section_pointer{}; +grib_accessor* grib_accessor_section_pointer = &_grib_accessor_section_pointer; - -void grib_accessor_class_section_pointer_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_section_pointer_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - grib_accessor_section_pointer_t* self = (grib_accessor_section_pointer_t*)a; + grib_accessor_gen_t::init(len, arg); - int n = 0; - self->sectionOffset = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); - self->sectionLength = grib_arguments_get_name(grib_handle_of_accessor(a), arg, n++); - self->sectionNumber = grib_arguments_get_long(grib_handle_of_accessor(a), arg, n++); + int n = 0; + sectionOffset_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, n++); + sectionLength_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, n++); + sectionNumber_ = grib_arguments_get_long(grib_handle_of_accessor(this), arg, n++); - Assert(self->sectionNumber < MAX_NUM_SECTIONS); + Assert(sectionNumber_ < MAX_NUM_SECTIONS); - grib_handle_of_accessor(a)->section_offset[self->sectionNumber] = (char*)self->sectionOffset; - grib_handle_of_accessor(a)->section_length[self->sectionNumber] = (char*)self->sectionLength; + grib_handle_of_accessor(this)->section_offset[sectionNumber_] = (char*)sectionOffset_; + grib_handle_of_accessor(this)->section_length[sectionNumber_] = (char*)sectionLength_; - // printf("++++++++++++++ creating section_pointer%d %s %s\n", - // self->sectionNumber,self->sectionLength,self->sectionLength); + /* printf("++++++++++++++ GRIB_API: creating section_pointer%d %s %s\n", */ + /* sectionNumber,sectionLength,sectionLength_ ); */ - if (grib_handle_of_accessor(a)->sections_count < self->sectionNumber) - grib_handle_of_accessor(a)->sections_count = self->sectionNumber; + if (grib_handle_of_accessor(this)->sections_count < sectionNumber_) + grib_handle_of_accessor(this)->sections_count = sectionNumber_; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->flags |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; - a->length = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_HIDDEN; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + flags_ |= GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC; + length_ = 0; } -int grib_accessor_class_section_pointer_t::get_native_type(grib_accessor* a) +long grib_accessor_section_pointer_t::get_native_type() { return GRIB_TYPE_BYTES; } -int grib_accessor_class_section_pointer_t::unpack_string(grib_accessor* a, char* v, size_t* len) +int grib_accessor_section_pointer_t::unpack_string(char* v, size_t* len) { // unsigned char* p=NULL; // char* s=v; // int i; - // long length=a->byte_count(); + // long length=byte_count(); // if (*len < length) return GRIB_ARRAY_TOO_SMALL; - - // p = grib_handle_of_accessor(a)->buffer->data + a->byte_offset(); + // + // p = grib_handle_of_accessor(this)->buffer->data + byte_offset(); // for (i = 0; i < length; i++) { // snprintf (s,64,"%02x", *(p++)); // s+=2; // } // *len=length; - snprintf(v, 64, "%ld_%ld", a->byte_offset(), a->byte_count()); + snprintf(v, 64, "%ld_%ld", byte_offset(), byte_count()); return GRIB_SUCCESS; } -long grib_accessor_class_section_pointer_t::byte_count(grib_accessor* a) +long grib_accessor_section_pointer_t::byte_count() { - grib_accessor_section_pointer_t* self = (grib_accessor_section_pointer_t*)a; long sectionLength = 0; - int err = grib_get_long(grib_handle_of_accessor(a), self->sectionLength, §ionLength); - if (err) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "grib_accessor_class_section_pointer_t::byte_count: Unable to get %s %s", - self->sectionLength, grib_get_error_message(err)); + int ret = grib_get_long(grib_handle_of_accessor(this), sectionLength_, §ionLength); + if (ret) { + grib_context_log(context_, GRIB_LOG_ERROR, + "Unable to get %s %s", + sectionLength_, grib_get_error_message(ret)); return -1; } return sectionLength; } -long grib_accessor_class_section_pointer_t::byte_offset(grib_accessor* a) +long grib_accessor_section_pointer_t::byte_offset() { - grib_accessor_section_pointer_t* self = (grib_accessor_section_pointer_t*)a; long sectionOffset = 0; - int err = grib_get_long(grib_handle_of_accessor(a), self->sectionOffset, §ionOffset); - if (err) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "grib_accessor_class_section_pointer_t::byte_offset: Unable to get %s (%s)", - self->sectionOffset, grib_get_error_message(err)); + int ret = grib_get_long(grib_handle_of_accessor(this), sectionOffset_, §ionOffset); + if (ret) { + grib_context_log(context_, GRIB_LOG_ERROR, + "Unable to get %s %s", + sectionOffset_, grib_get_error_message(ret)); return -1; } diff --git a/src/accessor/grib_accessor_class_section_pointer.h b/src/accessor/grib_accessor_class_section_pointer.h index 569e20201..221a66eb4 100644 --- a/src/accessor/grib_accessor_class_section_pointer.h +++ b/src/accessor/grib_accessor_class_section_pointer.h @@ -16,20 +16,17 @@ class grib_accessor_section_pointer_t : public grib_accessor_gen_t { public: - /* Members defined in section_pointer */ - const char* sectionOffset; - const char* sectionLength; - long sectionNumber; -}; - -class grib_accessor_class_section_pointer_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_section_pointer_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_section_pointer_t() : + grib_accessor_gen_t() { class_name_ = "section_pointer"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_section_pointer_t{}; } - int get_native_type(grib_accessor*) override; - int unpack_string(grib_accessor*, char*, size_t* len) override; - long byte_count(grib_accessor*) override; - long byte_offset(grib_accessor*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int unpack_string(char*, size_t* len) override; + long byte_count() override; + long byte_offset() override; + void init(const long, grib_arguments*) override; + +private: + const char* sectionOffset_; + const char* sectionLength_; + long sectionNumber_; }; diff --git a/src/accessor/grib_accessor_class_select_step_template.cc b/src/accessor/grib_accessor_class_select_step_template.cc index d2c5eeb6a..4b5a2c28b 100644 --- a/src/accessor/grib_accessor_class_select_step_template.cc +++ b/src/accessor/grib_accessor_class_select_step_template.cc @@ -10,39 +10,36 @@ #include "grib_accessor_class_select_step_template.h" -grib_accessor_class_select_step_template_t _grib_accessor_class_select_step_template{ "select_step_template" }; -grib_accessor_class* grib_accessor_class_select_step_template = &_grib_accessor_class_select_step_template; +grib_accessor_select_step_template_t _grib_accessor_select_step_template{}; +grib_accessor* grib_accessor_select_step_template = &_grib_accessor_select_step_template; - -void grib_accessor_class_select_step_template_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_select_step_template_t::init(const long l, grib_arguments* c) { - grib_accessor_class_unsigned_t::init(a, l, c); - grib_accessor_select_step_template_t* self = (grib_accessor_select_step_template_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_unsigned_t::init(l, c); + grib_handle* hand = grib_handle_of_accessor(this); + int n = 0; - self->productDefinitionTemplateNumber = grib_arguments_get_name(hand, c, n++); - self->instant = grib_arguments_get_long(hand, c, n++); + productDefinitionTemplateNumber_ = grib_arguments_get_name(hand, c, n++); + instant_ = grib_arguments_get_long(hand, c, n++); } -int grib_accessor_class_select_step_template_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_select_step_template_t::unpack_long(long* val, size_t* len) { *val = 1; return GRIB_SUCCESS; } -int grib_accessor_class_select_step_template_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_select_step_template_t::pack_long(const long* val, size_t* len) { - grib_accessor_select_step_template_t* self = (grib_accessor_select_step_template_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - long productDefinitionTemplateNumber = 0; - long productDefinitionTemplateNumberNew = 0; + grib_handle* hand = grib_handle_of_accessor(this); + long productDefinitionTemplateNumber = 0; + long productDefinitionTemplateNumberNew = 0; - grib_get_long(hand, self->productDefinitionTemplateNumber, &productDefinitionTemplateNumber); + grib_get_long(hand, productDefinitionTemplateNumber_, &productDefinitionTemplateNumber); // DET = deterministic i.e., not ensemble // ENS = ensemble system - if (self->instant) { + if (instant_) { // Going from continuous or non-continuous interval to a point-in-time (instantaneous) switch (productDefinitionTemplateNumber) { case 8: @@ -168,13 +165,13 @@ int grib_accessor_class_select_step_template_t::pack_long(grib_accessor* a, cons } if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) { - grib_set_long(hand, self->productDefinitionTemplateNumber, productDefinitionTemplateNumberNew); + grib_set_long(hand, productDefinitionTemplateNumber_, productDefinitionTemplateNumberNew); } return GRIB_SUCCESS; } -int grib_accessor_class_select_step_template_t::value_count(grib_accessor* a, long* c) +int grib_accessor_select_step_template_t::value_count(long* c) { *c = 1; return 0; diff --git a/src/accessor/grib_accessor_class_select_step_template.h b/src/accessor/grib_accessor_class_select_step_template.h index e327a99da..8dfe2b828 100644 --- a/src/accessor/grib_accessor_class_select_step_template.h +++ b/src/accessor/grib_accessor_class_select_step_template.h @@ -16,18 +16,15 @@ class grib_accessor_select_step_template_t : public grib_accessor_unsigned_t { public: - /* Members defined in select_step_template */ - const char* productDefinitionTemplateNumber; - int instant; -}; - -class grib_accessor_class_select_step_template_t : public grib_accessor_class_unsigned_t -{ -public: - grib_accessor_class_select_step_template_t(const char* name) : grib_accessor_class_unsigned_t(name) {} + grib_accessor_select_step_template_t() : + grib_accessor_unsigned_t() { class_name_ = "select_step_template"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_select_step_template_t{}; } - int pack_long(grib_accessor*, const long* val, size_t* len) override; - 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; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* productDefinitionTemplateNumber_; + int instant_; }; diff --git a/src/accessor/grib_accessor_class_sexagesimal2decimal.cc b/src/accessor/grib_accessor_class_sexagesimal2decimal.cc index c43c7269c..a95cd4fe9 100644 --- a/src/accessor/grib_accessor_class_sexagesimal2decimal.cc +++ b/src/accessor/grib_accessor_class_sexagesimal2decimal.cc @@ -10,44 +10,43 @@ #include "grib_accessor_class_sexagesimal2decimal.h" -grib_accessor_class_sexagesimal2decimal_t _grib_accessor_class_sexagesimal2decimal{ "sexagesimal2decimal" }; -grib_accessor_class* grib_accessor_class_sexagesimal2decimal = &_grib_accessor_class_sexagesimal2decimal; +grib_accessor_sexagesimal2decimal_t _grib_accessor_sexagesimal2decimal{}; +grib_accessor* grib_accessor_sexagesimal2decimal = &_grib_accessor_sexagesimal2decimal; - -void grib_accessor_class_sexagesimal2decimal_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_sexagesimal2decimal_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_to_double_t::init(a, len, arg); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + grib_accessor_to_double_t::init(len, arg); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -void grib_accessor_class_sexagesimal2decimal_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_sexagesimal2decimal_t::dump(grib_dumper* dumper) { - grib_dump_double(dumper, a, NULL); + grib_dump_double(dumper, this, NULL); } -int grib_accessor_class_sexagesimal2decimal_t::get_native_type(grib_accessor* a) +long grib_accessor_sexagesimal2decimal_t::get_native_type() { return GRIB_TYPE_DOUBLE; } -int grib_accessor_class_sexagesimal2decimal_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_sexagesimal2decimal_t::unpack_string(char* val, size_t* len) { - grib_accessor_sexagesimal2decimal_t* self = (grib_accessor_sexagesimal2decimal_t*)a; - int err = 0; - char buff[512] = {0,}; + char buff[512] = { + 0, + }; size_t length = 0; size_t size = sizeof(buff); - char* p = 0; - char* q = 0; + char* p = 0; + char* q = 0; double dd, mm = 0, ss = 0; int dd_sign = 1; - err = grib_get_string(grib_handle_of_accessor(a), self->key, buff, &size); + err = grib_get_string(grib_handle_of_accessor(this), key_, buff, &size); if (err) return err; - q = buff + self->start; - if (self->length) + q = buff + start_; + if (length_) q[length] = 0; p = q; @@ -137,8 +136,8 @@ int grib_accessor_class_sexagesimal2decimal_t::unpack_string(grib_accessor* a, c length = strlen(buff); if (len[0] < length + 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s, it contains %ld values", - len[0], a->name, a->length + 1); + grib_context_log(context_, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s, it contains %ld values", + len[0], name_, length_ + 1); len[0] = 0; return GRIB_ARRAY_TOO_SMALL; } diff --git a/src/accessor/grib_accessor_class_sexagesimal2decimal.h b/src/accessor/grib_accessor_class_sexagesimal2decimal.h index d9051bca9..080f721ff 100644 --- a/src/accessor/grib_accessor_class_sexagesimal2decimal.h +++ b/src/accessor/grib_accessor_class_sexagesimal2decimal.h @@ -16,16 +16,11 @@ class grib_accessor_sexagesimal2decimal_t : public grib_accessor_to_double_t { public: - /* Members defined in sexagesimal2decimal */ -}; - -class grib_accessor_class_sexagesimal2decimal_t : public grib_accessor_class_to_double_t -{ -public: - grib_accessor_class_sexagesimal2decimal_t(const char* name) : grib_accessor_class_to_double_t(name) {} + grib_accessor_sexagesimal2decimal_t() : + grib_accessor_to_double_t() { class_name_ = "sexagesimal2decimal"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_sexagesimal2decimal_t{}; } - int get_native_type(grib_accessor*) override; - int unpack_string(grib_accessor*, char*, size_t* len) override; - void dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int unpack_string(char*, size_t* len) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; }; diff --git a/src/accessor/grib_accessor_class_signed.cc b/src/accessor/grib_accessor_class_signed.cc index 36c20bd59..1a4e12c3f 100644 --- a/src/accessor/grib_accessor_class_signed.cc +++ b/src/accessor/grib_accessor_class_signed.cc @@ -11,31 +11,29 @@ #include "grib_accessor_class_signed.h" -grib_accessor_class_signed_t _grib_accessor_class_signed{ "signed" }; -grib_accessor_class* grib_accessor_class_signed = &_grib_accessor_class_signed; +grib_accessor_signed_t _grib_accessor_signed{}; +grib_accessor* grib_accessor_signed = &_grib_accessor_signed; - -void grib_accessor_class_signed_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_signed_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_long_t::init(a, len, arg); - grib_accessor_signed_t* self = (grib_accessor_signed_t*)a; - long count = 0; + grib_accessor_long_t::init(len, arg); + long count = 0; - self->arg = arg; - a->value_count(&count); - a->length = len * count; - self->nbytes = len; - Assert(a->length >= 0); + arg_ = arg; + value_count(&count); + length_ = len * count; + nbytes_ = len; + Assert(length_ >= 0); } -void grib_accessor_class_signed_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_signed_t::dump(grib_dumper* dumper) { long rlen = 0; - a->value_count(&rlen); + value_count(&rlen); if (rlen == 1) - grib_dump_long(dumper, a, NULL); + grib_dump_long(dumper, this, NULL); else - grib_dump_values(dumper, a); + grib_dump_values(dumper, this); } static const long ones[] = { @@ -46,49 +44,46 @@ static const long ones[] = { -0x7fffffff, }; -int grib_accessor_class_signed_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_signed_t::unpack_long(long* val, size_t* len) { - grib_accessor_signed_t* self = (grib_accessor_signed_t*)a; - unsigned long rlen = 0; - int err = 0; - long count = 0; - unsigned long i = 0; - grib_handle* hand = grib_handle_of_accessor(a); - long pos = a->offset; - long missing = 0; + unsigned long rlen = 0; + int err = 0; + long count = 0; + unsigned long i = 0; + grib_handle* hand = grib_handle_of_accessor(this); + long pos = offset_; + long missing = 0; - err = a->value_count(&count); + err = value_count(&count); if (err) return err; rlen = count; if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %lu values", a->name, rlen); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s, it contains %lu values", name_, rlen); *len = 0; return GRIB_ARRAY_TOO_SMALL; } - if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { - Assert(self->nbytes <= 4); - missing = ones[self->nbytes]; + if (flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { + Assert(nbytes_ <= 4); + missing = ones[nbytes_]; } for (i = 0; i < rlen; i++) { - val[i] = (long)grib_decode_signed_long(hand->buffer->data, pos, self->nbytes); + val[i] = (long)grib_decode_signed_long(hand->buffer->data, pos, nbytes_); if (missing) if (val[i] == missing) val[i] = GRIB_MISSING_LONG; - pos += self->nbytes; + pos += nbytes_; } *len = rlen; return GRIB_SUCCESS; } -int grib_accessor_class_signed_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_signed_t::pack_long(const long* val, size_t* len) { - grib_accessor_signed_t* self = (grib_accessor_signed_t*)a; - int ret = 0; long off = 0; unsigned long rlen = 0; @@ -98,20 +93,20 @@ int grib_accessor_class_signed_t::pack_long(grib_accessor* a, const long* val, s unsigned long i = 0; long missing = 0; - int err = a->value_count(&count); + int err = value_count(&count); if (err) return err; rlen = count; if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values", a->name, 1); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values", name_, 1); len[0] = 0; return GRIB_ARRAY_TOO_SMALL; } - if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { - Assert(self->nbytes <= 4); - missing = ones[self->nbytes]; + if (flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { + Assert(nbytes_ <= 4); + missing = ones[nbytes_]; } if (rlen == 1) { @@ -122,94 +117,93 @@ int grib_accessor_class_signed_t::pack_long(grib_accessor* a, const long* val, s } else { // ECC-1605: Check overflow/underflow - const int nbits = self->nbytes * 8; + const int nbits = nbytes_ * 8; const long minval = -(1L << (nbits - 1)) + 1; const long maxval = (1L << (nbits - 1)) - 1; - // printf(" key=%s: v=%ld (minval=%ld maxval=%ld)\n", a->name, v, minval, maxval); + // printf(" key=%s: v=%ld (minval=%ld maxval=%ld)\n", name_ , v, minval, maxval); if (v > maxval || v < minval) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "Key \"%s\": Trying to encode value of %ld but the allowable range is %ld to %ld (number of bits=%d)", - a->name, v, minval, maxval, nbits); + name_, v, minval, maxval, nbits); return GRIB_ENCODING_ERROR; } } - off = a->offset; - ret = grib_encode_signed_long(grib_handle_of_accessor(a)->buffer->data, v, off, a->length); + off = offset_; + ret = grib_encode_signed_long(grib_handle_of_accessor(this)->buffer->data, v, off, length_); if (ret == GRIB_SUCCESS) len[0] = 1; if (*len > 1) - grib_context_log(a->context, GRIB_LOG_WARNING, "grib_accessor_signed_t : Trying to pack %d values in a scalar %s, packing first value", *len, a->name); + grib_context_log(context_, GRIB_LOG_WARNING, "grib_accessor_signed_t : Trying to pack %d values in a scalar %s, packing first value", *len, name_); len[0] = 1; return ret; } /* TODO: We assume that there are no missing values if there are more that 1 value */ - buflen = *len * a->length; + buflen = *len * length_; - buf = (unsigned char*)grib_context_malloc(a->context, buflen); + buf = (unsigned char*)grib_context_malloc(context_, buflen); for (i = 0; i < *len; i++) { - grib_encode_signed_long(buf, val[i], off, a->length); - off += a->length; + grib_encode_signed_long(buf, val[i], off, length_); + off += length_; } - ret = grib_set_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), *len); + ret = grib_set_long_internal(grib_handle_of_accessor(this), grib_arguments_get_name(parent_->h, arg_, 0), *len); if (ret == GRIB_SUCCESS) - grib_buffer_replace(a, buf, buflen, 1, 1); + grib_buffer_replace(this, buf, buflen, 1, 1); else *len = 0; - grib_context_free(a->context, buf); + grib_context_free(context_, buf); return ret; } -long grib_accessor_class_signed_t::byte_count(grib_accessor* a) +long grib_accessor_signed_t::byte_count() { - return a->length; + return length_; } -int grib_accessor_class_signed_t::value_count(grib_accessor* a, long* len) +int grib_accessor_signed_t::value_count(long* len) { - grib_accessor_signed_t* self = (grib_accessor_signed_t*)a; *len = 0; - if (!self->arg) { + if (!arg_) { *len = 1; return 0; } - return grib_get_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), len); + return grib_get_long_internal(grib_handle_of_accessor(this), grib_arguments_get_name(parent_->h, arg_, 0), len); } -long grib_accessor_class_signed_t::byte_offset(grib_accessor* a) +long grib_accessor_signed_t::byte_offset() { - return a->offset; + return offset_; } -void grib_accessor_class_signed_t::update_size(grib_accessor* a, size_t s) +void grib_accessor_signed_t::update_size(size_t s) { - a->length = s; - Assert(a->length >= 0); + length_ = s; + Assert(length_ >= 0); } -long grib_accessor_class_signed_t::next_offset(grib_accessor* a) +long grib_accessor_signed_t::next_offset() { - return a->byte_offset() + a->byte_count(); + return byte_offset() + byte_count(); } -int grib_accessor_class_signed_t::is_missing(grib_accessor* a) +int grib_accessor_signed_t::is_missing() { int i = 0; unsigned char ff = 0xff; - unsigned long offset = a->offset; - grib_handle* hand = grib_handle_of_accessor(a); + unsigned long offset = offset_; + grib_handle* hand = grib_handle_of_accessor(this); - if (a->length == 0) { - Assert(a->vvalue != NULL); - return a->vvalue->missing; + if (length_ == 0) { + Assert(vvalue_ != NULL); + return vvalue_->missing; } - for (i = 0; i < a->length; i++) { + for (i = 0; i < length_; i++) { if (hand->buffer->data[offset] != ff) return 0; offset++; diff --git a/src/accessor/grib_accessor_class_signed.h b/src/accessor/grib_accessor_class_signed.h index 9fbb6f8d2..4565dc8ec 100644 --- a/src/accessor/grib_accessor_class_signed.h +++ b/src/accessor/grib_accessor_class_signed.h @@ -16,24 +16,21 @@ class grib_accessor_signed_t : public grib_accessor_long_t { public: - /* Members defined in signed */ - grib_arguments* arg; - int nbytes; -}; - -class grib_accessor_class_signed_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_signed_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_signed_t() : + grib_accessor_long_t() { class_name_ = "signed"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_signed_t{}; } - int is_missing(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; - 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 dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; - void update_size(grib_accessor*, size_t) override; + int is_missing() override; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + long byte_count() override; + long byte_offset() override; + long next_offset() override; + int value_count(long*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + void update_size(size_t) override; + +private: + grib_arguments* arg_; + int nbytes_; }; diff --git a/src/accessor/grib_accessor_class_signed_bits.cc b/src/accessor/grib_accessor_class_signed_bits.cc index b205cc9f7..2c2587338 100644 --- a/src/accessor/grib_accessor_class_signed_bits.cc +++ b/src/accessor/grib_accessor_class_signed_bits.cc @@ -10,13 +10,12 @@ #include "grib_accessor_class_signed_bits.h" -grib_accessor_class_signed_bits_t _grib_accessor_class_signed_bits{ "signed_bits" }; -grib_accessor_class* grib_accessor_class_signed_bits = &_grib_accessor_class_signed_bits; +grib_accessor_signed_bits_t _grib_accessor_signed_bits{}; +grib_accessor* grib_accessor_signed_bits = &_grib_accessor_signed_bits; - -long grib_accessor_class_signed_bits_t::byte_count(grib_accessor* a) +long grib_accessor_signed_bits_t::byte_count() { - return a->length; + return length_; } static long compute_byte_count(grib_accessor* a) @@ -26,41 +25,39 @@ static long compute_byte_count(grib_accessor* a) long numberOfElements; int ret = 0; - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits_, &numberOfBits); if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name, self->numberOfBits); + grib_context_log(a->context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", a->name_, self->numberOfBits_); return 0; } - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, &numberOfElements); + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements_, &numberOfElements); if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name, self->numberOfElements); + grib_context_log(a->context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", a->name_, self->numberOfElements_); return 0; } return (numberOfBits * numberOfElements + 7) / 8; } -void grib_accessor_class_signed_bits_t::init(grib_accessor* a, const long len, grib_arguments* args) +void grib_accessor_signed_bits_t::init(const long len, grib_arguments* args) { - grib_accessor_class_long_t::init(a, len, args); - grib_accessor_signed_bits_t* self = (grib_accessor_signed_bits_t*)a; - int n = 0; - self->numberOfBits = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->numberOfElements = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - a->length = compute_byte_count(a); + grib_accessor_long_t::init(len, args); + int n = 0; + numberOfBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + numberOfElements_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + length_ = compute_byte_count(this); } -int grib_accessor_class_signed_bits_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_signed_bits_t::unpack_long(long* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; #if 0 - grib_accessor_signed_bits_t* self = (grib_accessor_signed_bits_t*)a; int i; int ret = 0; - long pos = a->offset * 8; + long pos = offset_ * 8; long rlen = 0; long numberOfBits = 0; @@ -69,13 +66,13 @@ int grib_accessor_class_signed_bits_t::unpack_long(grib_accessor* a, long* val, return ret; if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Wrong size (%ld) for %s it contains %ld values", *len, a->name, rlen); + grib_context_log(context_ , GRIB_LOG_ERROR, + "Wrong size (%ld) for %s it contains %ld values", *len, name_ , rlen); *len = 0; return GRIB_ARRAY_TOO_SMALL; } - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfBits_ , &numberOfBits); if (ret) return ret; @@ -86,7 +83,7 @@ int grib_accessor_class_signed_bits_t::unpack_long(grib_accessor* a, long* val, } for (i = 0; i < rlen; i++) - val[i] = grib_decode_signed_longb(grib_handle_of_accessor(a)->buffer->data, &pos, numberOfBits); + val[i] = grib_decode_signed_longb(grib_handle_of_accessor(this)->buffer->data, &pos, numberOfBits); *len = rlen; @@ -94,11 +91,10 @@ int grib_accessor_class_signed_bits_t::unpack_long(grib_accessor* a, long* val, #endif } -int grib_accessor_class_signed_bits_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_signed_bits_t::pack_long(const long* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; #if 0 - grib_accessor_signed_bits_t* self = (grib_accessor_signed_bits_t*)a; int ret = 0; long off = 0; long numberOfBits = 0; @@ -113,48 +109,47 @@ int grib_accessor_class_signed_bits_t::pack_long(grib_accessor* a, const long* v return ret; rlen = count; if (*len != rlen) { - ret = grib_set_long(grib_handle_of_accessor(a), self->numberOfElements, rlen); + ret = grib_set_long(grib_handle_of_accessor(this), numberOfElements_ , rlen); if (ret) return ret; } - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfBits_ , &numberOfBits); if (ret) return ret; buflen = compute_byte_count(a); - buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen + sizeof(long)); + buf = (unsigned char*)grib_context_malloc_clear(context_ , buflen + sizeof(long)); for (i = 0; i < rlen; i++) grib_encode_signed_longb(buf, val[i], &off, numberOfBits); grib_buffer_replace(a, buf, buflen, 1, 1); - grib_context_free(a->context, buf); + grib_context_free(context_ , buf); return ret; #endif } -int grib_accessor_class_signed_bits_t::value_count(grib_accessor* a, long* numberOfElements) +int grib_accessor_signed_bits_t::value_count(long* numberOfElements) { - grib_accessor_signed_bits_t* self = (grib_accessor_signed_bits_t*)a; - *numberOfElements = 0; + *numberOfElements = 0; - return grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, numberOfElements); + return grib_get_long(grib_handle_of_accessor(this), numberOfElements_, numberOfElements); } -long grib_accessor_class_signed_bits_t::byte_offset(grib_accessor* a) +long grib_accessor_signed_bits_t::byte_offset() { - return a->offset; + return offset_; } -void grib_accessor_class_signed_bits_t::update_size(grib_accessor* a, size_t s) +void grib_accessor_signed_bits_t::update_size(size_t s) { - a->length = s; + length_ = s; } -long grib_accessor_class_signed_bits_t::next_offset(grib_accessor* a) +long grib_accessor_signed_bits_t::next_offset() { - return a->byte_offset() + a->byte_count(); + return byte_offset() + byte_count(); } diff --git a/src/accessor/grib_accessor_class_signed_bits.h b/src/accessor/grib_accessor_class_signed_bits.h index dd49c5c75..9d37550f4 100644 --- a/src/accessor/grib_accessor_class_signed_bits.h +++ b/src/accessor/grib_accessor_class_signed_bits.h @@ -16,22 +16,19 @@ class grib_accessor_signed_bits_t : public grib_accessor_long_t { public: - /* Members defined in signed_bits */ - const char* numberOfBits; - const char* numberOfElements; -}; - -class grib_accessor_class_signed_bits_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_signed_bits_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_signed_bits_t() : + grib_accessor_long_t() { class_name_ = "signed_bits"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_signed_bits_t{}; } - int pack_long(grib_accessor*, const long* val, size_t* len) override; - int unpack_long(grib_accessor*, long* 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 init(grib_accessor*, const long, grib_arguments*) override; - void update_size(grib_accessor*, size_t) override; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + long byte_count() override; + long byte_offset() override; + long next_offset() override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + void update_size(size_t) override; + +public: + const char* numberOfBits_; + const char* numberOfElements_; }; diff --git a/src/accessor/grib_accessor_class_simple_packing_error.cc b/src/accessor/grib_accessor_class_simple_packing_error.cc index 5bdd21553..063d4bd84 100644 --- a/src/accessor/grib_accessor_class_simple_packing_error.cc +++ b/src/accessor/grib_accessor_class_simple_packing_error.cc @@ -11,52 +11,48 @@ #include "grib_accessor_class_simple_packing_error.h" #include "grib_scaling.h" -grib_accessor_class_simple_packing_error_t _grib_accessor_class_simple_packing_error{ "simple_packing_error" }; -grib_accessor_class* grib_accessor_class_simple_packing_error = &_grib_accessor_class_simple_packing_error; +grib_accessor_simple_packing_error_t _grib_accessor_simple_packing_error{}; +grib_accessor* grib_accessor_simple_packing_error = &_grib_accessor_simple_packing_error; - -void grib_accessor_class_simple_packing_error_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_simple_packing_error_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_simple_packing_error_t* self = (grib_accessor_simple_packing_error_t*)a; - int n = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_double_t::init(l, c); + int n = 0; + grib_handle* h = grib_handle_of_accessor(this); - self->bitsPerValue = grib_arguments_get_name(h, c, n++); - self->binaryScaleFactor = grib_arguments_get_name(h, c, n++); - self->decimalScaleFactor = grib_arguments_get_name(h, c, n++); - self->referenceValue = grib_arguments_get_name(h, c, n++); - self->floatType = grib_arguments_get_name(h, c, n++); + bitsPerValue_ = grib_arguments_get_name(h, c, n++); + binaryScaleFactor_ = grib_arguments_get_name(h, c, n++); + decimalScaleFactor_ = grib_arguments_get_name(h, c, n++); + referenceValue_ = grib_arguments_get_name(h, c, n++); + floatType_ = grib_arguments_get_name(h, c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + length_ = 0; } -int grib_accessor_class_simple_packing_error_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_simple_packing_error_t::unpack_double(double* val, size_t* len) { - grib_accessor_simple_packing_error_t* self = (grib_accessor_simple_packing_error_t*)a; - int ret = 0; long binaryScaleFactor = 0; long bitsPerValue = 0; long decimalScaleFactor = 0; double referenceValue = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); - if ((ret = grib_get_long_internal(h, self->binaryScaleFactor, &binaryScaleFactor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, binaryScaleFactor_, &binaryScaleFactor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(h, self->bitsPerValue, &bitsPerValue)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, bitsPerValue_, &bitsPerValue)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(h, self->decimalScaleFactor, &decimalScaleFactor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(h, decimalScaleFactor_, &decimalScaleFactor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(h, self->referenceValue, &referenceValue)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(h, referenceValue_, &referenceValue)) != GRIB_SUCCESS) return ret; - if (!strcmp(self->floatType, "ibm")) + if (!strcmp(floatType_, "ibm")) *val = grib_ibmfloat_error(referenceValue); - else if (!strcmp(self->floatType, "ieee")) + else if (!strcmp(floatType_, "ieee")) *val = grib_ieeefloat_error(referenceValue); else Assert(1 == 0); diff --git a/src/accessor/grib_accessor_class_simple_packing_error.h b/src/accessor/grib_accessor_class_simple_packing_error.h index f0c005e03..25bc3b3b4 100644 --- a/src/accessor/grib_accessor_class_simple_packing_error.h +++ b/src/accessor/grib_accessor_class_simple_packing_error.h @@ -16,19 +16,16 @@ class grib_accessor_simple_packing_error_t : public grib_accessor_double_t { public: - /* Members defined in simple_packing_error */ - const char* binaryScaleFactor; - const char* bitsPerValue; - const char* decimalScaleFactor; - const char* referenceValue; - const char* floatType; -}; - -class grib_accessor_class_simple_packing_error_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_simple_packing_error_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_simple_packing_error_t() : + grib_accessor_double_t() { class_name_ = "simple_packing_error"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_simple_packing_error_t{}; } - int unpack_double(grib_accessor*, double* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_double(double* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* binaryScaleFactor_; + const char* bitsPerValue_; + const char* decimalScaleFactor_; + const char* referenceValue_; + const char* floatType_; }; diff --git a/src/accessor/grib_accessor_class_size.cc b/src/accessor/grib_accessor_class_size.cc index 71c0dd947..41a2e1078 100644 --- a/src/accessor/grib_accessor_class_size.cc +++ b/src/accessor/grib_accessor_class_size.cc @@ -11,27 +11,23 @@ #include "grib_accessor_class_size.h" -grib_accessor_class_size_t _grib_accessor_class_size{ "size" }; -grib_accessor_class* grib_accessor_class_size = &_grib_accessor_class_size; +grib_accessor_size_t _grib_accessor_size{}; +grib_accessor* grib_accessor_size = &_grib_accessor_size; - -void grib_accessor_class_size_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_size_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_size_t* self = (grib_accessor_size_t*)a; - self->accessor = grib_arguments_get_name(grib_handle_of_accessor(a), c, 0); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; + grib_accessor_long_t::init(l, c); + accessor_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, 0); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + length_ = 0; } -int grib_accessor_class_size_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_size_t::unpack_long(long* val, size_t* len) { - grib_accessor_size_t* self = (grib_accessor_size_t*)a; - size_t size = 0; - int ret = grib_get_size(grib_handle_of_accessor(a), self->accessor, &size); - *val = (long)size; - *len = 1; + int ret = grib_get_size(grib_handle_of_accessor(this), accessor_, &size); + *val = (long)size; + *len = 1; return ret; } diff --git a/src/accessor/grib_accessor_class_size.h b/src/accessor/grib_accessor_class_size.h index 9901c479e..e7689ccc5 100644 --- a/src/accessor/grib_accessor_class_size.h +++ b/src/accessor/grib_accessor_class_size.h @@ -16,15 +16,12 @@ class grib_accessor_size_t : public grib_accessor_long_t { public: - /* Members defined in size */ - const char* accessor; -}; - -class grib_accessor_class_size_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_size_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_size_t() : + grib_accessor_long_t() { class_name_ = "size"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_size_t{}; } - int unpack_long(grib_accessor*, long* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* accessor_; }; diff --git a/src/accessor/grib_accessor_class_smart_table.cc b/src/accessor/grib_accessor_class_smart_table.cc index 8be64d9d5..f628fba79 100644 --- a/src/accessor/grib_accessor_class_smart_table.cc +++ b/src/accessor/grib_accessor_class_smart_table.cc @@ -11,8 +11,8 @@ #include "grib_accessor_class_smart_table.h" #include -grib_accessor_class_smart_table_t _grib_accessor_class_smart_table{"smart_table"}; -grib_accessor_class* grib_accessor_class_smart_table = &_grib_accessor_class_smart_table; +grib_accessor_smart_table_t _grib_accessor_smart_table{}; +grib_accessor* grib_accessor_smart_table = &_grib_accessor_smart_table; #if GRIB_PTHREADS static pthread_once_t once = PTHREAD_ONCE_INIT; @@ -32,7 +32,7 @@ static omp_nest_lock_t mutex; static void init_mutex() { - GRIB_OMP_CRITICAL(lock_grib_accessor_class_smart_table_c) + GRIB_OMP_CRITICAL(lock_grib_accessor_smart_table_c) { if (once == 0) { omp_init_nest_lock(&mutex); @@ -44,83 +44,99 @@ static void init_mutex() static int grib_load_smart_table(grib_context* c, const char* filename, const char* recomposed_name, size_t size, grib_smart_table* t); -void grib_accessor_class_smart_table_t::init(grib_accessor* a, const long len, grib_arguments* params) +void grib_accessor_smart_table_t::init(const long len, grib_arguments* params) { - grib_accessor_class_unsigned_t::init(a, len, params); + int n = 0; + grib_handle* hand = grib_handle_of_accessor(this); - int n = 0; - grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + values_ = grib_arguments_get_name(hand, params, n++); + tablename_ = grib_arguments_get_string(hand, params, n++); + masterDir_ = grib_arguments_get_name(hand, params, n++); + localDir_ = grib_arguments_get_name(hand, params, n++); + widthOfCode_ = grib_arguments_get_long(hand, params, n++); + extraDir_ = grib_arguments_get_name(hand, params, n++); + extraTable_ = grib_arguments_get_string(hand, params, n++); - self->values = grib_arguments_get_name(hand, params, n++); - self->tablename = grib_arguments_get_string(hand, params, n++); - self->masterDir = grib_arguments_get_name(hand, params, n++); - self->localDir = grib_arguments_get_name(hand, params, n++); - self->widthOfCode = grib_arguments_get_long(hand, params, n++); - self->extraDir = grib_arguments_get_name(hand, params, n++); - self->extraTable = grib_arguments_get_string(hand, params, n++); - - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - self->dirty = 1; - self->tableCodesSize = 0; - self->tableCodes = 0; + grib_accessor_unsigned_t::length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + dirty_ = 1; + tableCodesSize_ = 0; + tableCodes_ = 0; + table_ = NULL; } grib_smart_table* load_table(grib_accessor* a) { grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; - size_t size = 0; - grib_handle* h = ((grib_accessor*)self)->parent->h; - grib_context* c = h->context; - grib_smart_table* t = NULL; - grib_smart_table* next = NULL; - char* filename = 0; - char recomposed[1024] = {0,}; - char localRecomposed[1024] = {0,}; - char* localFilename = 0; - char extraRecomposed[1024] = {0,}; - char* extraFilename = 0; - char masterDir[1024] = {0,}; - char localDir[1024] = {0,}; - char extraDir[1024] = {0,}; + size_t size = 0; + grib_handle* h = ((grib_accessor*)self)->parent_->h; + grib_context* c = h->context; + grib_smart_table* t = NULL; + grib_smart_table* next = NULL; + char* filename = 0; + char recomposed[1024] = { + 0, + }; + char localRecomposed[1024] = { + 0, + }; + char* localFilename = 0; + char extraRecomposed[1024] = { + 0, + }; + char* extraFilename = 0; + char masterDir[1024] = { + 0, + }; + char localDir[1024] = { + 0, + }; + char extraDir[1024] = { + 0, + }; size_t len = 1024; - if (self->masterDir != NULL) { - grib_get_string(h, self->masterDir, masterDir, &len); + if (self->masterDir_ != NULL) { + grib_get_string(h, self->masterDir_, masterDir, &len); } len = 1024; - if (self->localDir != NULL) { - grib_get_string(h, self->localDir, localDir, &len); + if (self->localDir_ != NULL) { + grib_get_string(h, self->localDir_, localDir, &len); } len = 1024; - if (self->extraDir != NULL && self->extraTable != NULL) { - grib_get_string(h, self->extraDir, extraDir, &len); + if (self->extraDir_ != NULL && self->extraTable_ != NULL) { + grib_get_string(h, self->extraDir_, extraDir, &len); } if (*masterDir != 0) { - char name[2048] = {0,}; - snprintf(name, sizeof(name), "%s/%s", masterDir, self->tablename); + char name[2048] = { + 0, + }; + snprintf(name, sizeof(name), "%s/%s", masterDir, self->tablename_); grib_recompose_name(h, NULL, name, recomposed, 0); filename = grib_context_full_defs_path(c, recomposed); } else { - grib_recompose_name(h, NULL, self->tablename, recomposed, 0); + grib_recompose_name(h, NULL, self->tablename_, recomposed, 0); filename = grib_context_full_defs_path(c, recomposed); } if (*localDir != 0) { - char localName[2048] = {0,}; - snprintf(localName, sizeof(localName), "%s/%s", localDir, self->tablename); + char localName[2048] = { + 0, + }; + snprintf(localName, sizeof(localName), "%s/%s", localDir, self->tablename_); grib_recompose_name(h, NULL, localName, localRecomposed, 0); localFilename = grib_context_full_defs_path(c, localRecomposed); } if (*extraDir != 0) { - char extraTable[2048] = {0,}; - snprintf(extraTable, sizeof(extraTable), "%s/%s", extraDir, self->extraTable); + char extraTable[2048] = { + 0, + }; + snprintf(extraTable, sizeof(extraTable), "%s/%s", extraDir, self->extraTable_); grib_recompose_name(h, NULL, extraTable, extraRecomposed, 0); extraFilename = grib_context_full_defs_path(c, extraRecomposed); } @@ -136,13 +152,13 @@ grib_smart_table* load_table(grib_accessor* a) next = next->next; } - // Note: self->widthOfCode is chosen so that 2^width is bigger than the maximum descriptor code, + // Note: widthOfCode_ is chosen so that 2^width is bigger than the maximum descriptor code, // which for BUFR4 is the Table C operator 243255 // - size = (1ULL << self->widthOfCode); // = 2^self->widthOfCode (as a 64 bit number) + size = (1ULL << self->widthOfCode_); // = 2^widthOfCode_ (as a 64 bit number) - t = (grib_smart_table*)grib_context_malloc_clear_persistent(c, sizeof(grib_smart_table)); - t->entries = (grib_smart_table_entry*)grib_context_malloc_clear_persistent(c, size * sizeof(grib_smart_table_entry)); + t = (grib_smart_table*)grib_context_malloc_clear_persistent(c, sizeof(grib_smart_table)); + t->entries = (grib_smart_table_entry*)grib_context_malloc_clear_persistent(c, size * sizeof(grib_smart_table_entry)); t->numberOfEntries = size; if (filename != 0) @@ -165,7 +181,9 @@ grib_smart_table* load_table(grib_accessor* a) static int grib_load_smart_table(grib_context* c, const char* filename, const char* recomposed_name, size_t size, grib_smart_table* t) { - char line[1024] = {0,}; + char line[1024] = { + 0, + }; FILE* f = NULL; // int lineNumber; int numberOfColumns, code; @@ -179,21 +197,21 @@ static int grib_load_smart_table(grib_context* c, const char* filename, Assert(t != NULL); if (t->filename[0] == NULL) { - t->filename[0] = grib_context_strdup_persistent(c, filename); + t->filename[0] = grib_context_strdup_persistent(c, filename); t->recomposed_name[0] = grib_context_strdup_persistent(c, recomposed_name); - t->next = c->smart_table; - t->numberOfEntries = size; + t->next = c->smart_table; + t->numberOfEntries = size; GRIB_MUTEX_INIT_ONCE(&once, &init_mutex); GRIB_MUTEX_LOCK(&mutex); c->smart_table = t; GRIB_MUTEX_UNLOCK(&mutex); } else if (t->filename[1] == NULL) { - t->filename[1] = grib_context_strdup_persistent(c, filename); + t->filename[1] = grib_context_strdup_persistent(c, filename); t->recomposed_name[1] = grib_context_strdup_persistent(c, recomposed_name); } else { - t->filename[2] = grib_context_strdup_persistent(c, filename); + t->filename[2] = grib_context_strdup_persistent(c, filename); t->recomposed_name[2] = grib_context_strdup_persistent(c, recomposed_name); } @@ -231,7 +249,7 @@ static int grib_load_smart_table(grib_context* c, const char* filename, DEBUG_ASSERT(code < t->numberOfEntries); while (*s) { char* tcol = t->entries[code].column[numberOfColumns]; - if ( tcol ) grib_context_free_persistent(c, tcol); + if (tcol) grib_context_free_persistent(c, tcol); t->entries[code].column[numberOfColumns] = grib_context_strdup_persistent(c, s); numberOfColumns++; DEBUG_ASSERT(numberOfColumns < MAX_SMART_TABLE_COLUMNS); @@ -280,14 +298,13 @@ void grib_smart_table_delete(grib_context* c) } } -void grib_accessor_class_smart_table_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_smart_table_t::dump(grib_dumper* dumper) { - grib_dump_long(dumper, a, NULL); + grib_dump_long(dumper, this, NULL); } -int grib_accessor_class_smart_table_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) +int grib_accessor_smart_table_t::unpack_string(char* buffer, size_t* len) { - grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; grib_smart_table* table = NULL; size_t size = 1; @@ -296,12 +313,12 @@ int grib_accessor_class_smart_table_t::unpack_string(grib_accessor* a, char* buf char tmp[1024]; size_t l = 0; - if ((err = a->unpack_long(&value, &size)) != GRIB_SUCCESS) + if ((err = unpack_long(&value, &size)) != GRIB_SUCCESS) return err; - if (!self->table) - self->table = load_table(a); - table = self->table; + if (!table_) + table_ = load_table(this); + table = table_; if (table && (value >= 0) && (value < table->numberOfEntries) && table->entries[value].abbreviation) { strcpy(tmp, table->entries[value].abbreviation); @@ -318,8 +335,8 @@ int grib_accessor_class_smart_table_t::unpack_string(grib_accessor* a, char* buf } strcpy(buffer, tmp); - *len = l; - self->dirty = 0; + *len = l; + dirty_ = 0; return GRIB_SUCCESS; } @@ -327,116 +344,113 @@ int grib_accessor_class_smart_table_t::unpack_string(grib_accessor* a, char* buf static int get_table_codes(grib_accessor* a) { grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; - size_t size = 0; - long* v = 0; - int err = 0; + size_t size = 0; + long* v = 0; + int err = 0; int count, j; size_t i; int table_size; - if (!self->dirty) + if (!a->dirty_) return 0; - table_size = (1 << self->widthOfCode); // 2 ^ self->widthOfCode + table_size = (1 << self->widthOfCode_); // 2 ^ widthOfCode_ - if (!self->table) - self->table = load_table(a); + if (!self->table_) + self->table_ = load_table(a); - err = grib_get_size(grib_handle_of_accessor(a), self->values, &size); + err = grib_get_size(grib_handle_of_accessor(a), self->values_, &size); if (err) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "unable to get size of %s", a->name); + grib_context_log(a->context_, GRIB_LOG_ERROR, + "unable to get size of %s", a->name_); return err; } - v = (long*)grib_context_malloc_clear(a->context, size * sizeof(long)); + v = (long*)grib_context_malloc_clear(a->context_, size * sizeof(long)); - grib_get_long_array(grib_handle_of_accessor(a), self->values, v, &size); + grib_get_long_array(grib_handle_of_accessor(a), self->values_, v, &size); count = 0; for (i = 0; i < size; i++) { if (v[i] < table_size) count++; } - if (self->tableCodes) - grib_context_free(a->context, self->tableCodes); - self->tableCodes = (long*)grib_context_malloc_clear(a->context, count * sizeof(long)); - j = 0; + if (self->tableCodes_) + grib_context_free(a->context_, self->tableCodes_); + self->tableCodes_ = (long*)grib_context_malloc_clear(a->context_, count * sizeof(long)); + j = 0; for (i = 0; i < size; i++) { if (v[i] < table_size) - self->tableCodes[j++] = v[i]; + self->tableCodes_[j++] = v[i]; } - grib_context_free(a->context, v); + grib_context_free(a->context_, v); - self->tableCodesSize = count; - self->dirty = 0; + self->tableCodesSize_ = count; + a->dirty_ = 0; return 0; } -int grib_accessor_class_smart_table_t::value_count(grib_accessor* a, long* count) +int grib_accessor_smart_table_t::value_count(long* count) { int err = 0; - grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; - *count = 0; + *count = 0; - if (!self->values) + if (!values_) return 0; - err = get_table_codes(a); + err = get_table_codes(this); if (err) return err; - *count = self->tableCodesSize; + *count = tableCodesSize_; return GRIB_SUCCESS; } -void grib_accessor_class_smart_table_t::destroy(grib_context* context, grib_accessor* a) +void grib_accessor_smart_table_t::destroy(grib_context* context) { - grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; - if (a->vvalue != NULL) { - grib_context_free(context, a->vvalue); - a->vvalue = NULL; + if (vvalue_ != NULL) { + grib_context_free(context, vvalue_); + vvalue_ = NULL; } - if (self->tableCodes) - grib_context_free(a->context, self->tableCodes); + if (tableCodes_) + grib_context_free(context_, tableCodes_); - grib_accessor_class_unsigned_t::destroy(context, a); + grib_accessor_unsigned_t::destroy(context); } -int grib_accessor_class_smart_table_t::get_native_type(grib_accessor* a) +long grib_accessor_smart_table_t::get_native_type() { int type = GRIB_TYPE_LONG; - //printf("---------- %s flags=%ld GRIB_ACCESSOR_FLAG_STRING_TYPE=%d\n", - // a->name,a->flags,GRIB_ACCESSOR_FLAG_STRING_TYPE); - if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE) + // printf("---------- %s flags=%ld GRIB_ACCESSOR_FLAG_STRING_TYPE=%d\n", + // a->name,flags_ ,GRIB_ACCESSOR_FLAG_STRING_TYPE); + if (flags_ & GRIB_ACCESSOR_FLAG_STRING_TYPE) type = GRIB_TYPE_STRING; return type; } -int grib_accessor_class_smart_table_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_smart_table_t::unpack_long(long* val, size_t* len) { int err = 0; - grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; size_t i; - if (!self->values) + if (!values_) return 0; - err = get_table_codes(a); + err = get_table_codes(this); if (err) return 0; - if (*len < self->tableCodesSize) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Wrong size (%zu) for %s, it contains %zu values", *len, a->name, self->tableCodesSize); - *len = self->tableCodesSize; + if (*len < tableCodesSize_) { + grib_context_log(context_, GRIB_LOG_ERROR, + "Wrong size (%zu) for %s, it contains %zu values", *len, name_, tableCodesSize_); + *len = tableCodesSize_; return GRIB_ARRAY_TOO_SMALL; } - for (i = 0; i < self->tableCodesSize; i++) - val[i] = self->tableCodes[i]; + for (i = 0; i < tableCodesSize_; i++) + val[i] = tableCodes_[i]; return err; } diff --git a/src/accessor/grib_accessor_class_smart_table.h b/src/accessor/grib_accessor_class_smart_table.h index c7aaf0827..28664b1e5 100644 --- a/src/accessor/grib_accessor_class_smart_table.h +++ b/src/accessor/grib_accessor_class_smart_table.h @@ -16,29 +16,28 @@ class grib_accessor_smart_table_t : public grib_accessor_unsigned_t { public: - const char* values; - const char* tablename; - const char* masterDir; - const char* localDir; - const char* extraDir; - const char* extraTable; - int widthOfCode; - long* tableCodes; - size_t tableCodesSize; - grib_smart_table* table; - int dirty; -}; - -class grib_accessor_class_smart_table_t : public grib_accessor_class_unsigned_t -{ -public: - grib_accessor_class_smart_table_t(const char* name) : grib_accessor_class_unsigned_t(name) {} + grib_accessor_smart_table_t() : + grib_accessor_unsigned_t() { class_name_ = "smart_table"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_smart_table_t{}; } - int get_native_type(grib_accessor*) 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 destroy(grib_context*, grib_accessor*) override; - void dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + int value_count(long*) override; + void destroy(grib_context*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +public: + const char* values_; + const char* tablename_; + const char* masterDir_; + const char* localDir_; + const char* extraDir_; + const char* extraTable_; + int widthOfCode_; + long* tableCodes_; + size_t tableCodesSize_; + grib_smart_table* table_; + // TODO(maee): dirty_ shadowed by the derived class + // int dirty_; }; diff --git a/src/accessor/grib_accessor_class_smart_table_column.cc b/src/accessor/grib_accessor_class_smart_table_column.cc index d9d44bc49..9602f9ea0 100644 --- a/src/accessor/grib_accessor_class_smart_table_column.cc +++ b/src/accessor/grib_accessor_class_smart_table_column.cc @@ -12,97 +12,95 @@ #include "grib_accessor_class_smart_table_column.h" #include "grib_accessor_class_smart_table.h" -grib_accessor_class_smart_table_column_t _grib_accessor_class_smart_table_column{ "smart_table_column" }; -grib_accessor_class* grib_accessor_class_smart_table_column = &_grib_accessor_class_smart_table_column; +grib_accessor_smart_table_column_t _grib_accessor_smart_table_column{}; +grib_accessor* grib_accessor_smart_table_column = &_grib_accessor_smart_table_column; - -void grib_accessor_class_smart_table_column_t::init(grib_accessor* a, const long len, grib_arguments* params) +void grib_accessor_smart_table_column_t::init(const long len, grib_arguments* params) { - grib_accessor_class_gen_t::init(a, len, params); + grib_accessor_gen_t::init(len, params); int n = 0; - grib_accessor_smart_table_column_t* self = (grib_accessor_smart_table_column_t*)a; - self->smartTable = grib_arguments_get_name(grib_handle_of_accessor(a), params, n++); - self->index = grib_arguments_get_long(grib_handle_of_accessor(a), params, n++); + smartTable_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, n++); + index_ = grib_arguments_get_long(grib_handle_of_accessor(this), params, n++); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -void grib_accessor_class_smart_table_column_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_smart_table_column_t::dump(grib_dumper* dumper) { - int type = get_native_type(a); + int type = get_native_type(); switch (type) { case GRIB_TYPE_LONG: - grib_dump_long(dumper, a, NULL); + grib_dump_long(dumper, this, NULL); break; case GRIB_TYPE_STRING: - grib_dump_string_array(dumper, a, NULL); + grib_dump_string_array(dumper, this, NULL); break; } } -int grib_accessor_class_smart_table_column_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len) +int grib_accessor_smart_table_column_t::unpack_string_array(char** buffer, size_t* len) { - grib_accessor_smart_table_column_t* self = (grib_accessor_smart_table_column_t*)a; grib_accessor_smart_table_t* tableAccessor = NULL; - grib_smart_table* table = NULL; + grib_smart_table* table = NULL; size_t size = 1; long* code; - int err = GRIB_SUCCESS; - char tmp[1024] = {0,}; + int err = GRIB_SUCCESS; + char tmp[1024] = { + 0, + }; int i = 0; - tableAccessor = (grib_accessor_smart_table_t*)grib_find_accessor(grib_handle_of_accessor(a), self->smartTable); + tableAccessor = (grib_accessor_smart_table_t*)grib_find_accessor(grib_handle_of_accessor(this), smartTable_); if (!tableAccessor) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Unable to find accessor %s", self->smartTable); + grib_context_log(context_, GRIB_LOG_ERROR, + "Unable to find accessor %s", smartTable_); return GRIB_NOT_FOUND; } - err = grib_get_size_acc(grib_handle_of_accessor(a), (grib_accessor*)tableAccessor, &size); + err = grib_get_size_acc(grib_handle_of_accessor(this), (grib_accessor*)tableAccessor, &size); if (err) return err; if (*len < size) { return GRIB_BUFFER_TOO_SMALL; } - code = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + code = (long*)grib_context_malloc_clear(context_, sizeof(long) * size); if (!code) { - grib_context_log(a->context, GRIB_LOG_FATAL, "%s: Memory allocation error: %zu bytes", a->name, size); + grib_context_log(context_, GRIB_LOG_FATAL, "%s: Memory allocation error: %zu bytes", name_, size); return GRIB_OUT_OF_MEMORY; } if ((err = ((grib_accessor*)tableAccessor)->unpack_long(code, &size)) != GRIB_SUCCESS) return err; - table = tableAccessor->table; + table = tableAccessor->table_; for (i = 0; i < size; i++) { if (table && (code[i] >= 0) && (code[i] < table->numberOfEntries) && - table->entries[code[i]].column[self->index]) { - strcpy(tmp, table->entries[code[i]].column[self->index]); + table->entries[code[i]].column[index_]) { + strcpy(tmp, table->entries[code[i]].column[index_]); } else { snprintf(tmp, sizeof(tmp), "%d", (int)code[i]); } - buffer[i] = grib_context_strdup(a->context, tmp); + buffer[i] = grib_context_strdup(context_, tmp); } *len = size; - grib_context_free(a->context, code); + grib_context_free(context_, code); return GRIB_SUCCESS; } -int grib_accessor_class_smart_table_column_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_smart_table_column_t::unpack_long(long* val, size_t* len) { - grib_accessor_smart_table_column_t* self = (grib_accessor_smart_table_column_t*)a; grib_accessor_smart_table_t* tableAccessor = NULL; - grib_smart_table* table = NULL; + grib_smart_table* table = NULL; size_t size = 1; long* code; @@ -112,74 +110,73 @@ int grib_accessor_class_smart_table_column_t::unpack_long(grib_accessor* a, long for (i = 0; i < *len; i++) val[i] = GRIB_MISSING_LONG; - tableAccessor = (grib_accessor_smart_table_t*)grib_find_accessor(grib_handle_of_accessor(a), self->smartTable); + tableAccessor = (grib_accessor_smart_table_t*)grib_find_accessor(grib_handle_of_accessor(this), smartTable_); if (!tableAccessor) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Unable to find accessor %s", self->smartTable); + grib_context_log(context_, GRIB_LOG_ERROR, + "Unable to find accessor %s", smartTable_); return GRIB_NOT_FOUND; } - err = grib_get_size_acc(grib_handle_of_accessor(a), (grib_accessor*)tableAccessor, &size); + err = grib_get_size_acc(grib_handle_of_accessor(this), (grib_accessor*)tableAccessor, &size); if (err) return err; if (*len < size) { return GRIB_BUFFER_TOO_SMALL; } - code = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + code = (long*)grib_context_malloc_clear(context_, sizeof(long) * size); if (!code) return GRIB_OUT_OF_MEMORY; if ((err = ((grib_accessor*)tableAccessor)->unpack_long(code, &size)) != GRIB_SUCCESS) { - grib_context_free(a->context, code); + grib_context_free(context_, code); return err; } - table = tableAccessor->table; + table = tableAccessor->table_; for (i = 0; i < size; i++) { if (table && (code[i] >= 0) && (code[i] < table->numberOfEntries) && - table->entries[code[i]].column[self->index]) { - val[i] = atol(table->entries[code[i]].column[self->index]); + table->entries[code[i]].column[index_]) { + val[i] = atol(table->entries[code[i]].column[index_]); } } *len = size; - grib_context_free(a->context, code); + grib_context_free(context_, code); return GRIB_SUCCESS; } -int grib_accessor_class_smart_table_column_t::value_count(grib_accessor* a, long* count) +int grib_accessor_smart_table_column_t::value_count(long* count) { - grib_accessor_smart_table_column_t* self = (grib_accessor_smart_table_column_t*)a; size_t size = 0; int err = 0; *count = 0; - if (!self->smartTable) + if (!smartTable_) return 0; - err = grib_get_size(grib_handle_of_accessor(a), self->smartTable, &size); + err = grib_get_size(grib_handle_of_accessor(this), smartTable_, &size); *count = size; return err; } -void grib_accessor_class_smart_table_column_t::destroy(grib_context* context, grib_accessor* a) +void grib_accessor_smart_table_column_t::destroy(grib_context* context) { - if (a->vvalue != NULL) { - grib_context_free(context, a->vvalue); - a->vvalue = NULL; + if (vvalue_ != NULL) { + grib_context_free(context, vvalue_); + vvalue_ = NULL; } - grib_accessor_class_gen_t::destroy(context, a); + grib_accessor_gen_t::destroy(context); } -int grib_accessor_class_smart_table_column_t::get_native_type(grib_accessor* a) +long grib_accessor_smart_table_column_t::get_native_type() { int type = GRIB_TYPE_LONG; /*printf("---------- %s flags=%ld GRIB_ACCESSOR_FLAG_STRING_TYPE=%d\n", - a->name,a->flags,GRIB_ACCESSOR_FLAG_STRING_TYPE);*/ - if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE) + a->name,flags_ ,GRIB_ACCESSOR_FLAG_STRING_TYPE);*/ + if (flags_ & GRIB_ACCESSOR_FLAG_STRING_TYPE) type = GRIB_TYPE_STRING; return type; } diff --git a/src/accessor/grib_accessor_class_smart_table_column.h b/src/accessor/grib_accessor_class_smart_table_column.h index 9e1edcd2a..86b035fb1 100644 --- a/src/accessor/grib_accessor_class_smart_table_column.h +++ b/src/accessor/grib_accessor_class_smart_table_column.h @@ -16,20 +16,18 @@ class grib_accessor_smart_table_column_t : public grib_accessor_gen_t { public: - const char* smartTable; - int index; -}; - -class grib_accessor_class_smart_table_column_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_smart_table_column_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_smart_table_column_t() : + grib_accessor_gen_t() { class_name_ = "smart_table_column"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_smart_table_column_t{}; } - int get_native_type(grib_accessor*) override; - 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 dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int unpack_long(long* val, size_t* len) override; + int unpack_string_array(char**, size_t* len) override; + int value_count(long*) override; + void destroy(grib_context*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +private: + const char* smartTable_; + int index_; }; diff --git a/src/accessor/grib_accessor_class_spd.cc b/src/accessor/grib_accessor_class_spd.cc index 212b4a36e..ae746cc7f 100644 --- a/src/accessor/grib_accessor_class_spd.cc +++ b/src/accessor/grib_accessor_class_spd.cc @@ -10,13 +10,12 @@ #include "grib_accessor_class_spd.h" -grib_accessor_class_spd_t _grib_accessor_class_spd{ "spd" }; -grib_accessor_class* grib_accessor_class_spd = &_grib_accessor_class_spd; +grib_accessor_spd_t _grib_accessor_spd{}; +grib_accessor* grib_accessor_spd = &_grib_accessor_spd; - -long grib_accessor_class_spd_t::byte_count(grib_accessor* a) +long grib_accessor_spd_t::byte_count() { - return a->length; + return length_; } static long compute_byte_count(grib_accessor* a) @@ -25,17 +24,17 @@ static long compute_byte_count(grib_accessor* a) long numberOfBits = 0; long numberOfElements = 0; - int ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + int ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits_, &numberOfBits); if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name, self->numberOfBits); + grib_context_log(a->context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", a->name_, self->numberOfBits_); return 0; } - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, &numberOfElements); + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements_, &numberOfElements); if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name, self->numberOfElements); + grib_context_log(a->context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", a->name_, self->numberOfElements_); return 0; } numberOfElements++; @@ -43,78 +42,75 @@ static long compute_byte_count(grib_accessor* a) return (numberOfBits * numberOfElements + 7) / 8; } -void grib_accessor_class_spd_t::init(grib_accessor* a, const long len, grib_arguments* args) +void grib_accessor_spd_t::init(const long len, grib_arguments* args) { - grib_accessor_class_long_t::init(a, len, args); - grib_accessor_spd_t* self = (grib_accessor_spd_t*)a; - int n = 0; - self->numberOfBits = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->numberOfElements = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - a->length = compute_byte_count(a); + grib_accessor_long_t::init(len, args); + int n = 0; + numberOfBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + numberOfElements_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + length_ = compute_byte_count(this); } -int grib_accessor_class_spd_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_spd_t::unpack_long(long* val, size_t* len) { - grib_accessor_spd_t* self = (grib_accessor_spd_t*)a; - long pos = a->offset * 8; - long rlen = 0; - long numberOfBits = 0; + long pos = offset_ * 8; + long rlen = 0; + long numberOfBits = 0; - int ret = value_count(a, &rlen); + int ret = value_count(&rlen); if (ret) return ret; if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Wrong size (%zu) for %s, it contains %ld values", *len, a->name, rlen); + grib_context_log(context_, GRIB_LOG_ERROR, + "Wrong size (%zu) for %s, it contains %ld values", *len, name_, rlen); *len = rlen; return GRIB_ARRAY_TOO_SMALL; } - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfBits_, &numberOfBits); if (ret) return ret; if (numberOfBits > 64) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Invalid number of bits: %ld", numberOfBits); + grib_context_log(context_, GRIB_LOG_ERROR, "Invalid number of bits: %ld", numberOfBits); return GRIB_DECODING_ERROR; } for (long i = 0; i < rlen - 1; i++) - val[i] = grib_decode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, &pos, numberOfBits); + val[i] = grib_decode_unsigned_long(grib_handle_of_accessor(this)->buffer->data, &pos, numberOfBits); - val[rlen - 1] = grib_decode_signed_longb(grib_handle_of_accessor(a)->buffer->data, &pos, numberOfBits); + val[rlen - 1] = grib_decode_signed_longb(grib_handle_of_accessor(this)->buffer->data, &pos, numberOfBits); *len = rlen; return GRIB_SUCCESS; } -int grib_accessor_class_spd_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_spd_t::pack_long(const long* val, size_t* len) { - grib_accessor_spd_t* self = (grib_accessor_spd_t*)a; - int ret = 0; - long off = 0; - long numberOfBits = 0; - size_t buflen = 0; - unsigned char* buf = NULL; - unsigned long i = 0; - long rlen = 0; + int ret = 0; + long off = 0; + long numberOfBits = 0; + size_t buflen = 0; + unsigned char* buf = NULL; + unsigned long i = 0; + long rlen = 0; - ret = value_count(a, &rlen); + ret = value_count(&rlen); if (ret) return ret; if (*len != rlen) { - ret = grib_set_long(grib_handle_of_accessor(a), self->numberOfElements, (*len) - 1); + ret = grib_set_long(grib_handle_of_accessor(this), numberOfElements_, (*len) - 1); if (ret) return ret; } - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfBits_, &numberOfBits); if (ret) return ret; - buflen = compute_byte_count(a); - buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen); + buflen = compute_byte_count(this); + buf = (unsigned char*)grib_context_malloc_clear(context_, buflen); for (i = 0; i < rlen - 1; i++) { grib_encode_unsigned_longb(buf, val[i], &off, numberOfBits); @@ -122,24 +118,23 @@ int grib_accessor_class_spd_t::pack_long(grib_accessor* a, const long* val, size grib_encode_signed_longb(buf, val[rlen - 1], &off, numberOfBits); - grib_buffer_replace(a, buf, buflen, 1, 1); + grib_buffer_replace(this, buf, buflen, 1, 1); - grib_context_free(a->context, buf); + grib_context_free(context_, buf); *len = rlen; return ret; } -int grib_accessor_class_spd_t::value_count(grib_accessor* a, long* numberOfElements) +int grib_accessor_spd_t::value_count(long* numberOfElements) { - grib_accessor_spd_t* self = (grib_accessor_spd_t*)a; int ret; *numberOfElements = 0; - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, numberOfElements); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfElements_, numberOfElements); if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name, self->numberOfElements); + grib_context_log(context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", name_, numberOfElements_); return ret; } (*numberOfElements)++; @@ -147,17 +142,17 @@ int grib_accessor_class_spd_t::value_count(grib_accessor* a, long* numberOfEleme return ret; } -long grib_accessor_class_spd_t::byte_offset(grib_accessor* a) +long grib_accessor_spd_t::byte_offset() { - return a->offset; + return offset_; } -void grib_accessor_class_spd_t::update_size(grib_accessor* a, size_t s) +void grib_accessor_spd_t::update_size(size_t s) { - a->length = s; + length_ = s; } -long grib_accessor_class_spd_t::next_offset(grib_accessor* a) +long grib_accessor_spd_t::next_offset() { - return a->byte_offset() + a->length; + return byte_offset() + length_; } diff --git a/src/accessor/grib_accessor_class_spd.h b/src/accessor/grib_accessor_class_spd.h index ee4fa5d12..06114dc09 100644 --- a/src/accessor/grib_accessor_class_spd.h +++ b/src/accessor/grib_accessor_class_spd.h @@ -16,22 +16,19 @@ class grib_accessor_spd_t : public grib_accessor_long_t { public: - /* Members defined in spd */ - const char* numberOfBits; - const char* numberOfElements; -}; - -class grib_accessor_class_spd_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_spd_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_spd_t() : + grib_accessor_long_t() { class_name_ = "spd"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_spd_t{}; } - int pack_long(grib_accessor*, const long* val, size_t* len) override; - int unpack_long(grib_accessor*, long* 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 init(grib_accessor*, const long, grib_arguments*) override; - void update_size(grib_accessor*, size_t) override; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + long byte_count() override; + long byte_offset() override; + long next_offset() override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + void update_size(size_t) override; + +public: + const char* numberOfBits_; + const char* numberOfElements_; }; diff --git a/src/accessor/grib_accessor_class_spectral_truncation.cc b/src/accessor/grib_accessor_class_spectral_truncation.cc index fda29784c..a7c2c0a5d 100644 --- a/src/accessor/grib_accessor_class_spectral_truncation.cc +++ b/src/accessor/grib_accessor_class_spectral_truncation.cc @@ -10,41 +10,38 @@ #include "grib_accessor_class_spectral_truncation.h" -grib_accessor_class_spectral_truncation_t _grib_accessor_class_spectral_truncation{ "spectral_truncation" }; -grib_accessor_class* grib_accessor_class_spectral_truncation = &_grib_accessor_class_spectral_truncation; +grib_accessor_spectral_truncation_t _grib_accessor_spectral_truncation{}; +grib_accessor* grib_accessor_spectral_truncation = &_grib_accessor_spectral_truncation; - -void grib_accessor_class_spectral_truncation_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_spectral_truncation_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_spectral_truncation_t* self = (grib_accessor_spectral_truncation_t*)a; + grib_accessor_long_t::init(l, c); int n = 0; - self->J = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->K = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->M = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->T = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + J_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + K_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + M_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + T_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_spectral_truncation_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_spectral_truncation_t::unpack_long(long* val, size_t* len) { - grib_accessor_spectral_truncation_t* self = (grib_accessor_spectral_truncation_t*)a; - int ret = GRIB_SUCCESS; + int ret = 0; long J, K, M, T, Tc; if (*len < 1) return GRIB_ARRAY_TOO_SMALL; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->J, &J)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), J_, &J)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->K, &K)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), K_, &K)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->M, &M)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), M_, &M)) != GRIB_SUCCESS) return ret; Tc = -1; @@ -62,17 +59,17 @@ int grib_accessor_class_spectral_truncation_t::unpack_long(grib_accessor* a, lon } *val = Tc; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->T, &T)) != GRIB_SUCCESS) { + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), T_, &T)) != GRIB_SUCCESS) { if (Tc == -1) - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s. Spectral Truncation Type Unknown: %s=%ld %s=%ld %s=%ld", - a->name, self->J, J, self->K, K, self->M, M); + name_, J, J, K, K, M_, M); Tc = 0; - grib_set_long(grib_handle_of_accessor(a), self->T, Tc); + grib_set_long(grib_handle_of_accessor(this), T_, Tc); } else { if (Tc != -1 && Tc != T) - grib_set_long(grib_handle_of_accessor(a), self->T, Tc); + grib_set_long(grib_handle_of_accessor(this), T_, Tc); } if (ret == GRIB_SUCCESS) diff --git a/src/accessor/grib_accessor_class_spectral_truncation.h b/src/accessor/grib_accessor_class_spectral_truncation.h index c9f85b9f8..e30f7185f 100644 --- a/src/accessor/grib_accessor_class_spectral_truncation.h +++ b/src/accessor/grib_accessor_class_spectral_truncation.h @@ -16,18 +16,15 @@ class grib_accessor_spectral_truncation_t : public grib_accessor_long_t { public: - /* Members defined in spectral_truncation */ - const char* J; - const char* K; - const char* M; - const char* T; -}; - -class grib_accessor_class_spectral_truncation_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_spectral_truncation_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_spectral_truncation_t() : + grib_accessor_long_t() { class_name_ = "spectral_truncation"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_spectral_truncation_t{}; } - int unpack_long(grib_accessor*, long* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* J_; + const char* K_; + const char* M_; + const char* T_; }; diff --git a/src/accessor/grib_accessor_class_sprintf.cc b/src/accessor/grib_accessor_class_sprintf.cc index 533d66d7a..075596edb 100644 --- a/src/accessor/grib_accessor_class_sprintf.cc +++ b/src/accessor/grib_accessor_class_sprintf.cc @@ -10,21 +10,18 @@ #include "grib_accessor_class_sprintf.h" -grib_accessor_class_sprintf_t _grib_accessor_class_sprintf{ "sprintf" }; -grib_accessor_class* grib_accessor_class_sprintf = &_grib_accessor_class_sprintf; +grib_accessor_sprintf_t _grib_accessor_sprintf{}; +grib_accessor* grib_accessor_sprintf = &_grib_accessor_sprintf; - -void grib_accessor_class_sprintf_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_sprintf_t::init(const long l, grib_arguments* c) { - grib_accessor_class_ascii_t::init(a, l, c); - grib_accessor_sprintf_t* self = (grib_accessor_sprintf_t*)a; - self->args = c; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + grib_accessor_ascii_t::init(l, c); + args_ = c; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_sprintf_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_sprintf_t::unpack_string(char* val, size_t* len) { - grib_accessor_sprintf_t* self = (grib_accessor_sprintf_t*)a; char result[1024]; char tempBuffer[2048]; char sres[1024]; @@ -39,7 +36,7 @@ int grib_accessor_class_sprintf_t::unpack_string(grib_accessor* a, char* val, si const char* tempname = NULL; size_t uname_len = 0; - uname = grib_arguments_get_string(grib_handle_of_accessor(a), self->args, carg++); + uname = grib_arguments_get_string(grib_handle_of_accessor(this), args_, carg++); snprintf(result, sizeof(result), "%s", ""); uname_len = strlen(uname); @@ -57,12 +54,12 @@ int grib_accessor_class_sprintf_t::unpack_string(grib_accessor* a, char* val, si } switch (uname[i]) { case 'd': - tempname = grib_arguments_get_name(grib_handle_of_accessor(a), self->args, carg++); + tempname = grib_arguments_get_name(grib_handle_of_accessor(this), args_, carg++); - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), tempname, &ires)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), tempname, &ires)) != GRIB_SUCCESS) return ret; /* Bug GRIB-56: Check to see if the key is missing */ - is_missing = grib_is_missing(grib_handle_of_accessor(a), tempname, &ret); + is_missing = grib_is_missing(grib_handle_of_accessor(this), tempname, &ret); if (ret != GRIB_SUCCESS) return ret; if (is_missing) { @@ -83,8 +80,8 @@ int grib_accessor_class_sprintf_t::unpack_string(grib_accessor* a, char* val, si break; case 'g': - tempname = grib_arguments_get_name(grib_handle_of_accessor(a), self->args, carg++); - if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), tempname, &dres)) != GRIB_SUCCESS) + tempname = grib_arguments_get_name(grib_handle_of_accessor(this), args_, carg++); + if ((ret = grib_get_double_internal(grib_handle_of_accessor(this), tempname, &dres)) != GRIB_SUCCESS) return ret; snprintf(tempBuffer, sizeof(tempBuffer), "%s%g", result, dres); strcpy(result, tempBuffer); @@ -92,8 +89,8 @@ int grib_accessor_class_sprintf_t::unpack_string(grib_accessor* a, char* val, si break; case 's': - tempname = grib_arguments_get_name(grib_handle_of_accessor(a), self->args, carg++); - if ((ret = grib_get_string_internal(grib_handle_of_accessor(a), tempname, sres, &replen)) != GRIB_SUCCESS) + tempname = grib_arguments_get_name(grib_handle_of_accessor(this), args_, carg++); + if ((ret = grib_get_string_internal(grib_handle_of_accessor(this), tempname, sres, &replen)) != GRIB_SUCCESS) return ret; snprintf(tempBuffer, sizeof(tempBuffer), "%s%s", result, sres); strcpy(result, tempBuffer); @@ -119,13 +116,13 @@ int grib_accessor_class_sprintf_t::unpack_string(grib_accessor* a, char* val, si return GRIB_SUCCESS; } -int grib_accessor_class_sprintf_t::value_count(grib_accessor* a, long* count) +int grib_accessor_sprintf_t::value_count(long* count) { *count = 1; return 0; } -size_t grib_accessor_class_sprintf_t::string_length(grib_accessor* a) +size_t grib_accessor_sprintf_t::string_length() { return 1024; } diff --git a/src/accessor/grib_accessor_class_sprintf.h b/src/accessor/grib_accessor_class_sprintf.h index 36d5f3e10..f64f9601e 100644 --- a/src/accessor/grib_accessor_class_sprintf.h +++ b/src/accessor/grib_accessor_class_sprintf.h @@ -16,17 +16,14 @@ class grib_accessor_sprintf_t : public grib_accessor_ascii_t { public: - /* Members defined in sprintf */ - grib_arguments* args; -}; - -class grib_accessor_class_sprintf_t : public grib_accessor_class_ascii_t -{ -public: - grib_accessor_class_sprintf_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor_sprintf_t() : + grib_accessor_ascii_t() { class_name_ = "sprintf"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_sprintf_t{}; } - 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 init(grib_accessor*, const long, grib_arguments*) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + grib_arguments* args_; }; diff --git a/src/accessor/grib_accessor_class_statistics.cc b/src/accessor/grib_accessor_class_statistics.cc index 7e4a4eca8..33259b45a 100644 --- a/src/accessor/grib_accessor_class_statistics.cc +++ b/src/accessor/grib_accessor_class_statistics.cc @@ -11,55 +11,53 @@ #include "grib_accessor_class_statistics.h" -grib_accessor_class_statistics_t _grib_accessor_class_statistics{ "statistics" }; -grib_accessor_class* grib_accessor_class_statistics = &_grib_accessor_class_statistics; +grib_accessor_statistics_t _grib_accessor_statistics{}; +grib_accessor* grib_accessor_statistics = &_grib_accessor_statistics; - -void grib_accessor_class_statistics_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_statistics_t::init(const long l, grib_arguments* c) { - grib_accessor_class_abstract_vector_t::init(a, l, c); - grib_accessor_statistics_t* self = (grib_accessor_statistics_t*)a; + grib_accessor_abstract_vector_t::init(l, c); int n = 0; - self->missing_value = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; + missing_value_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + values_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + flags_ |= GRIB_ACCESSOR_FLAG_HIDDEN; - self->number_of_elements = 8; - self->v = (double*)grib_context_malloc(a->context, sizeof(double) * self->number_of_elements); + number_of_elements_ = 8; + v_ = (double*)grib_context_malloc(context_, + sizeof(double) * number_of_elements_); - a->length = 0; - a->dirty = 1; + length_ = 0; + dirty_ = 1; } -int grib_accessor_class_statistics_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_statistics_t::unpack_double(double* val, size_t* len) { - grib_accessor_statistics_t* self = (grib_accessor_statistics_t*)a; - int ret = 0; + int ret = 0; double* values = NULL; size_t i = 0, size = 0, real_size = 0; double max, min, avg, sd, value, skew, kurt, m2 = 0, m3 = 0, m4 = 0; - double missing = 0; + double missing = 0; long missingValuesPresent = 0; size_t number_of_missing = 0; - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); + grib_context* c = context_; + grib_handle* h = grib_handle_of_accessor(this); - if (!a->dirty) + if (!dirty_) return GRIB_SUCCESS; - if (*len != self->number_of_elements) + if (*len != number_of_elements_) return GRIB_ARRAY_TOO_SMALL; - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + if ((ret = grib_get_size(h, values_, &size)) != GRIB_SUCCESS) return ret; - grib_context_log(a->context, GRIB_LOG_DEBUG, + grib_context_log(context_, GRIB_LOG_DEBUG, "grib_accessor_statistics_t: computing statistics for %d values", size); - if ((ret = grib_get_double(h, self->missing_value, &missing)) != GRIB_SUCCESS) + if ((ret = grib_get_double(h, missing_value_, &missing)) != GRIB_SUCCESS) return ret; if ((ret = grib_get_long_internal(h, "missingValuesPresent", &missingValuesPresent)) != GRIB_SUCCESS) return ret; @@ -68,7 +66,7 @@ int grib_accessor_class_statistics_t::unpack_double(grib_accessor* a, double* va if (!values) return GRIB_OUT_OF_MEMORY; - if ((ret = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { + if ((ret = grib_get_double_array_internal(h, values_, values, &size)) != GRIB_SUCCESS) { grib_context_free(c, values); return ret; } @@ -148,42 +146,39 @@ int grib_accessor_class_statistics_t::unpack_double(grib_accessor* a, double* va skew = m3 / (sd * sd * sd); kurt = m4 / (m2 * m2) - 3.0; } - - //printf("\ngrib_accessor_class_statistics_t::unpack_double Computed. So setting dirty to 0....... \n"); - a->dirty = 0; + // printf("\ngrib_accessor_class_statistics_t::unpack_double Computed. So setting dirty to 0....... \n"); + dirty_ = 0; grib_context_free(c, values); - self->v[0] = max; - self->v[1] = min; - self->v[2] = avg; - self->v[3] = number_of_missing; - self->v[4] = sd; - self->v[5] = skew; - self->v[6] = kurt; - self->v[7] = sd == 0 ? 1 : 0; + v_[0] = max; + v_[1] = min; + v_[2] = avg; + v_[3] = number_of_missing; + v_[4] = sd; + v_[5] = skew; + v_[6] = kurt; + v_[7] = sd == 0 ? 1 : 0; - for (i = 0; i < self->number_of_elements; i++) - val[i] = self->v[i]; + for (i = 0; i < number_of_elements_; i++) + val[i] = v_[i]; return ret; } -int grib_accessor_class_statistics_t::value_count(grib_accessor* a, long* count) +int grib_accessor_statistics_t::value_count(long* count) { - grib_accessor_statistics_t* self = (grib_accessor_statistics_t*)a; - *count = self->number_of_elements; + *count = number_of_elements_; return 0; } -void grib_accessor_class_statistics_t::destroy(grib_context* c, grib_accessor* a) +void grib_accessor_statistics_t::destroy(grib_context* c) { - grib_accessor_statistics_t* self = (grib_accessor_statistics_t*)a; - grib_context_free(c, self->v); - grib_accessor_class_abstract_vector_t::destroy(c, a); + grib_context_free(c, v_); + grib_accessor_abstract_vector_t::destroy(c); } -int grib_accessor_class_statistics_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_statistics_t::compare(grib_accessor* b) { int retval = GRIB_SUCCESS; double* aval = 0; @@ -194,7 +189,7 @@ int grib_accessor_class_statistics_t::compare(grib_accessor* a, grib_accessor* b int err = 0; long count = 0; - err = a->value_count(&count); + err = value_count(&count); if (err) return err; alen = count; @@ -207,26 +202,26 @@ int grib_accessor_class_statistics_t::compare(grib_accessor* a, grib_accessor* b if (alen != blen) return GRIB_COUNT_MISMATCH; - aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); - bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); + aval = (double*)grib_context_malloc(context_, alen * sizeof(double)); + bval = (double*)grib_context_malloc(b->context_, blen * sizeof(double)); - b->dirty = 1; - a->dirty = 1; + b->dirty_ = 1; + dirty_ = 1; - a->unpack_double(aval, &alen); + 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; } - grib_context_free(a->context, aval); - grib_context_free(b->context, bval); + grib_context_free(context_, aval); + grib_context_free(b->context_, bval); return retval; } -int grib_accessor_class_statistics_t::unpack_string(grib_accessor* a, char* v, size_t* len) +int grib_accessor_statistics_t::unpack_string(char* v, size_t* len) { return GRIB_NOT_IMPLEMENTED; } diff --git a/src/accessor/grib_accessor_class_statistics.h b/src/accessor/grib_accessor_class_statistics.h index 63d7cbc00..b64185268 100644 --- a/src/accessor/grib_accessor_class_statistics.h +++ b/src/accessor/grib_accessor_class_statistics.h @@ -16,20 +16,17 @@ class grib_accessor_statistics_t : public grib_accessor_abstract_vector_t { public: - /* Members defined in statistics */ - const char* values; - const char* missing_value; -}; - -class grib_accessor_class_statistics_t : public grib_accessor_class_abstract_vector_t -{ -public: - grib_accessor_class_statistics_t(const char* name) : grib_accessor_class_abstract_vector_t(name) {} + grib_accessor_statistics_t() : + grib_accessor_abstract_vector_t() { class_name_ = "statistics"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_statistics_t{}; } - int unpack_double(grib_accessor*, double* val, size_t* len) override; - int unpack_string(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; - int compare(grib_accessor*, grib_accessor*) override; + int unpack_double(double* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + int value_count(long*) override; + void destroy(grib_context*) override; + void init(const long, grib_arguments*) override; + int compare(grib_accessor*) override; + +private: + const char* values_; + const char* missing_value_; }; diff --git a/src/accessor/grib_accessor_class_statistics_spectral.cc b/src/accessor/grib_accessor_class_statistics_spectral.cc index b4c17db03..61902529d 100644 --- a/src/accessor/grib_accessor_class_statistics_spectral.cc +++ b/src/accessor/grib_accessor_class_statistics_spectral.cc @@ -11,59 +11,57 @@ #include "grib_accessor_class_statistics_spectral.h" -grib_accessor_class_statistics_spectral_t _grib_accessor_class_statistics_spectral{ "statistics_spectral" }; -grib_accessor_class* grib_accessor_class_statistics_spectral = &_grib_accessor_class_statistics_spectral; +grib_accessor_statistics_spectral_t _grib_accessor_statistics_spectral{}; +grib_accessor* grib_accessor_statistics_spectral = &_grib_accessor_statistics_spectral; - -void grib_accessor_class_statistics_spectral_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_statistics_spectral_t::init(const long l, grib_arguments* c) { - grib_accessor_class_abstract_vector_t::init(a, l, c); - grib_accessor_statistics_spectral_t* self = (grib_accessor_statistics_spectral_t*)a; + grib_accessor_abstract_vector_t::init(l, c); int n = 0; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->J = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->K = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->M = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->JS = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); + values_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + J_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + K_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + M_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + JS_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; - self->number_of_elements = 4; - self->v = (double*)grib_context_malloc(a->context, sizeof(double) * self->number_of_elements); + number_of_elements_ = 4; + v_ = (double*)grib_context_malloc(context_, + sizeof(double) * number_of_elements_); - a->length = 0; - a->dirty = 1; + length_ = 0; + dirty_ = 1; } -int grib_accessor_class_statistics_spectral_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_statistics_spectral_t::unpack_double(double* val, size_t* len) { - grib_accessor_statistics_spectral_t* self = (grib_accessor_statistics_spectral_t*)a; int ret = 0, i = 0; double* values; size_t size = 0; long J, K, M, N; double avg, enorm, sd; - grib_context* c = a->context; - grib_handle* h = grib_handle_of_accessor(a); + grib_context* c = context_; + grib_handle* h = grib_handle_of_accessor(this); - if (!a->dirty) + if (!dirty_) return GRIB_SUCCESS; - if (*len != self->number_of_elements) + if (*len != number_of_elements_) return GRIB_ARRAY_TOO_SMALL; - if ((ret = grib_get_size(h, self->values, &size)) != GRIB_SUCCESS) + if ((ret = grib_get_size(h, values_, &size)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long(grib_handle_of_accessor(a), self->J, &J)) != GRIB_SUCCESS) + if ((ret = grib_get_long(grib_handle_of_accessor(this), J_, &J)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long(grib_handle_of_accessor(a), self->K, &K)) != GRIB_SUCCESS) + if ((ret = grib_get_long(grib_handle_of_accessor(this), K_, &K)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long(grib_handle_of_accessor(a), self->M, &M)) != GRIB_SUCCESS) + if ((ret = grib_get_long(grib_handle_of_accessor(this), M_, &M)) != GRIB_SUCCESS) return ret; if (J != M || M != K) @@ -72,7 +70,7 @@ int grib_accessor_class_statistics_spectral_t::unpack_double(grib_accessor* a, d N = (M + 1) * (M + 2) / 2; if (2 * N != size) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "wrong number of components for spherical harmonics %ld != %ld", 2 * N, size); return GRIB_WRONG_ARRAY_SIZE; } @@ -81,7 +79,7 @@ int grib_accessor_class_statistics_spectral_t::unpack_double(grib_accessor* a, d if (!values) return GRIB_OUT_OF_MEMORY; - if ((ret = grib_get_double_array_internal(h, self->values, values, &size)) != GRIB_SUCCESS) { + if ((ret = grib_get_double_array_internal(h, values_, values, &size)) != GRIB_SUCCESS) { grib_context_free(c, values); return ret; } @@ -100,36 +98,34 @@ int grib_accessor_class_statistics_spectral_t::unpack_double(grib_accessor* a, d sd = sqrt(sd); enorm = sqrt(enorm); - a->dirty = 0; + dirty_ = 0; grib_context_free(c, values); - self->v[0] = avg; - self->v[1] = enorm; - self->v[2] = sd; - self->v[3] = sd == 0 ? 1 : 0; + v_[0] = avg; + v_[1] = enorm; + v_[2] = sd; + v_[3] = sd == 0 ? 1 : 0; - for (i = 0; i < self->number_of_elements; i++) - val[i] = self->v[i]; + for (i = 0; i < number_of_elements_; i++) + val[i] = v_[i]; return ret; } -int grib_accessor_class_statistics_spectral_t::value_count(grib_accessor* a, long* count) +int grib_accessor_statistics_spectral_t::value_count(long* count) { - grib_accessor_statistics_spectral_t* self = (grib_accessor_statistics_spectral_t*)a; - *count = self->number_of_elements; + *count = number_of_elements_; return 0; } -void grib_accessor_class_statistics_spectral_t::destroy(grib_context* c, grib_accessor* a) +void grib_accessor_statistics_spectral_t::destroy(grib_context* c) { - grib_accessor_statistics_spectral_t* self = (grib_accessor_statistics_spectral_t*)a; - grib_context_free(c, self->v); - grib_accessor_class_abstract_vector_t::destroy(c, a); + grib_context_free(c, v_); + grib_accessor_abstract_vector_t::destroy(c); } -int grib_accessor_class_statistics_spectral_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_statistics_spectral_t::compare(grib_accessor* b) { int retval = GRIB_SUCCESS; double* aval = 0; @@ -140,7 +136,7 @@ int grib_accessor_class_statistics_spectral_t::compare(grib_accessor* a, grib_ac int err = 0; long count = 0; - err = a->value_count(&count); + err = value_count(&count); if (err) return err; alen = count; @@ -153,21 +149,21 @@ int grib_accessor_class_statistics_spectral_t::compare(grib_accessor* a, grib_ac if (alen != blen) return GRIB_COUNT_MISMATCH; - aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); - bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); + aval = (double*)grib_context_malloc(context_, alen * sizeof(double)); + bval = (double*)grib_context_malloc(b->context_, blen * sizeof(double)); - b->dirty = 1; - a->dirty = 1; + b->dirty_ = 1; + dirty_ = 1; - a->unpack_double(aval, &alen); + 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; } - grib_context_free(a->context, aval); - grib_context_free(b->context, bval); + grib_context_free(context_, aval); + grib_context_free(b->context_, bval); return retval; } diff --git a/src/accessor/grib_accessor_class_statistics_spectral.h b/src/accessor/grib_accessor_class_statistics_spectral.h index 41846c5c7..15f883f54 100644 --- a/src/accessor/grib_accessor_class_statistics_spectral.h +++ b/src/accessor/grib_accessor_class_statistics_spectral.h @@ -16,22 +16,19 @@ class grib_accessor_statistics_spectral_t : public grib_accessor_abstract_vector_t { public: - /* Members defined in statistics_spectral */ - const char* values; - const char* J; - const char* K; - const char* M; - const char* JS; -}; - -class grib_accessor_class_statistics_spectral_t : public grib_accessor_class_abstract_vector_t -{ -public: - grib_accessor_class_statistics_spectral_t(const char* name) : grib_accessor_class_abstract_vector_t(name) {} + grib_accessor_statistics_spectral_t() : + grib_accessor_abstract_vector_t() { class_name_ = "statistics_spectral"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_statistics_spectral_t{}; } - int unpack_double(grib_accessor*, double* 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 compare(grib_accessor*, grib_accessor*) override; + int unpack_double(double* val, size_t* len) override; + int value_count(long*) override; + void destroy(grib_context*) override; + void init(const long, grib_arguments*) override; + int compare(grib_accessor*) override; + +private: + const char* values_; + const char* J_; + const char* K_; + const char* M_; + const char* JS_; }; diff --git a/src/accessor/grib_accessor_class_step_human_readable.cc b/src/accessor/grib_accessor_class_step_human_readable.cc index 18dec9c14..5789d7af4 100644 --- a/src/accessor/grib_accessor_class_step_human_readable.cc +++ b/src/accessor/grib_accessor_class_step_human_readable.cc @@ -11,24 +11,22 @@ #include "grib_accessor_class_step_human_readable.h" -grib_accessor_class_step_human_readable_t _grib_accessor_class_step_human_readable{ "step_human_readable" }; -grib_accessor_class* grib_accessor_class_step_human_readable = &_grib_accessor_class_step_human_readable; +grib_accessor_step_human_readable_t _grib_accessor_step_human_readable{}; +grib_accessor* grib_accessor_step_human_readable = &_grib_accessor_step_human_readable; - -void grib_accessor_class_step_human_readable_t::init(grib_accessor* a, const long len, grib_arguments* params) +void grib_accessor_step_human_readable_t::init(const long len, grib_arguments* params) { - grib_accessor_class_gen_t::init(a, len, params); - grib_accessor_step_human_readable_t* self = (grib_accessor_step_human_readable_t*)a; - int n = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_gen_t::init(len, params); + int n = 0; + grib_handle* h = grib_handle_of_accessor(this); - self->stepUnits = grib_arguments_get_name(h, params, n++); - self->step = grib_arguments_get_name(h, params, n++); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + stepUnits_ = grib_arguments_get_name(h, params, n++); + step_ = grib_arguments_get_name(h, params, n++); + length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_step_human_readable_t::get_native_type(grib_accessor* a) +long grib_accessor_step_human_readable_t::get_native_type() { return GRIB_TYPE_STRING; } @@ -66,22 +64,20 @@ static int get_step_human_readable(grib_handle* h, char* result, size_t* length) return GRIB_SUCCESS; } -int grib_accessor_class_step_human_readable_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) +int grib_accessor_step_human_readable_t::unpack_string(char* buffer, size_t* len) { - grib_accessor_step_human_readable_t* self = (grib_accessor_step_human_readable_t*)a; - - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); long stepUnits = 0; int err = 0; /* Save the current value of stepUnits */ - err = grib_get_long_internal(h, self->stepUnits, &stepUnits); + err = grib_get_long_internal(h, stepUnits_, &stepUnits); if (err) return err; /* This will change stepUnits to seconds for its calculation */ err = get_step_human_readable(h, buffer, len); /* Restore stepUnits */ - grib_set_long(h, self->stepUnits, stepUnits); + grib_set_long(h, stepUnits_, stepUnits); return err; } diff --git a/src/accessor/grib_accessor_class_step_human_readable.h b/src/accessor/grib_accessor_class_step_human_readable.h index cbd61ed31..789a4b333 100644 --- a/src/accessor/grib_accessor_class_step_human_readable.h +++ b/src/accessor/grib_accessor_class_step_human_readable.h @@ -16,17 +16,14 @@ class grib_accessor_step_human_readable_t : public grib_accessor_gen_t { public: - /* Members defined in step_human_readable */ - const char* stepUnits; - const char* step; -}; - -class grib_accessor_class_step_human_readable_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_step_human_readable_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_step_human_readable_t() : + grib_accessor_gen_t() { class_name_ = "step_human_readable"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_step_human_readable_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; + long get_native_type() override; + int unpack_string(char*, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* stepUnits_; + const char* step_; }; diff --git a/src/accessor/grib_accessor_class_step_in_units.cc b/src/accessor/grib_accessor_class_step_in_units.cc index e5fd32b8f..651e4dfa1 100644 --- a/src/accessor/grib_accessor_class_step_in_units.cc +++ b/src/accessor/grib_accessor_class_step_in_units.cc @@ -12,50 +12,48 @@ #include "step_utilities.h" #include -grib_accessor_class_step_in_units_t _grib_accessor_class_step_in_units{"step_in_units"}; -grib_accessor_class* grib_accessor_class_step_in_units = &_grib_accessor_class_step_in_units; +grib_accessor_step_in_units_t _grib_accessor_step_in_units{}; +grib_accessor* grib_accessor_step_in_units = &_grib_accessor_step_in_units; -void grib_accessor_class_step_in_units_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_step_in_units_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_step_in_units_t* self = (grib_accessor_step_in_units_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_long_t::init(l, c); + grib_handle* hand = grib_handle_of_accessor(this); + int n = 0; - self->forecast_time_value = grib_arguments_get_name(hand, c, n++); - self->forecast_time_unit = grib_arguments_get_name(hand, c, n++); - self->step_units = grib_arguments_get_name(hand, c, n++); - self->time_range_unit = grib_arguments_get_name(hand, c, n++); - self->time_range_value = grib_arguments_get_name(hand, c, n++); + forecast_time_value_ = grib_arguments_get_name(hand, c, n++); + forecast_time_unit_ = grib_arguments_get_name(hand, c, n++); + step_units_ = grib_arguments_get_name(hand, c, n++); + time_range_unit_ = grib_arguments_get_name(hand, c, n++); + time_range_value_ = grib_arguments_get_name(hand, c, n++); } -void grib_accessor_class_step_in_units_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_step_in_units_t::dump(grib_dumper* dumper) { - grib_dump_double(dumper, a, NULL); + grib_dump_double(dumper, this, NULL); } -int grib_accessor_class_step_in_units_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_step_in_units_t::unpack_long(long* val, size_t* len) { - const grib_accessor_step_in_units_t* self = (grib_accessor_step_in_units_t*)a; int err = 0; long forecast_time_value, forecast_time_unit, step_units; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); - if ((err= grib_get_long_internal(h, "stepUnits", &step_units)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, "stepUnits", &step_units)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->forecast_time_unit, &forecast_time_unit))) + if ((err = grib_get_long_internal(h, forecast_time_unit_, &forecast_time_unit))) return err; - if ((err = grib_get_long_internal(h, self->forecast_time_value, &forecast_time_value))) + if ((err = grib_get_long_internal(h, forecast_time_value_, &forecast_time_value))) return err; try { - eccodes::Step step{forecast_time_value, forecast_time_unit}; + eccodes::Step step{ forecast_time_value, forecast_time_unit }; step.optimize_unit(); - if ((err = grib_set_long_internal(h, "startStepUnit", eccodes::Unit{step_units}.value())) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(h, "startStepUnit", eccodes::Unit{ step_units }.value())) != GRIB_SUCCESS) return err; - *val = step.value(eccodes::Unit{step_units}); + *val = step.value(eccodes::Unit{ step_units }); } catch (std::exception& e) { grib_context_log(h->context, GRIB_LOG_ERROR, "step_in_units: %s", e.what()); @@ -65,27 +63,26 @@ int grib_accessor_class_step_in_units_t::unpack_long(grib_accessor* a, long* val return GRIB_SUCCESS; } -int grib_accessor_class_step_in_units_t::unpack_double(grib_accessor* a, double * val, size_t* len) +int grib_accessor_step_in_units_t::unpack_double(double* val, size_t* len) { - const grib_accessor_step_in_units_t* self = (grib_accessor_step_in_units_t*)a; int err = 0; long forecast_time_value, forecast_time_unit, step_units; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); - if ((err= grib_get_long_internal(h, "stepUnits", &step_units)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, "stepUnits", &step_units)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->forecast_time_unit, &forecast_time_unit))) + if ((err = grib_get_long_internal(h, forecast_time_unit_, &forecast_time_unit))) return err; - if ((err = grib_get_long_internal(h, self->forecast_time_value, &forecast_time_value))) + if ((err = grib_get_long_internal(h, forecast_time_value_, &forecast_time_value))) return err; try { - eccodes::Step step{forecast_time_value, forecast_time_unit}; + eccodes::Step step{ forecast_time_value, forecast_time_unit }; - if ((err = grib_set_long_internal(h, "startStepUnit", eccodes::Unit{step_units}.value())) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(h, "startStepUnit", eccodes::Unit{ step_units }.value())) != GRIB_SUCCESS) return err; - *val = step.value(eccodes::Unit{step_units}); + *val = step.value(eccodes::Unit{ step_units }); } catch (std::exception& e) { grib_context_log(h->context, GRIB_LOG_ERROR, "step_in_units: %s", e.what()); @@ -98,14 +95,14 @@ int grib_accessor_class_step_in_units_t::unpack_double(grib_accessor* a, double static int pack_long_new_(grib_accessor* a, const long start_step_value, const long start_step_unit, const long force_step_units) { const grib_accessor_step_in_units_t* self = (grib_accessor_step_in_units_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int err = 0; + grib_handle* h = grib_handle_of_accessor(a); + int err = 0; long forecast_time_unit; long start_step_value_old; long start_step_unit_old; size_t len = 0; - if ((err = grib_get_long_internal(h, self->forecast_time_unit, &forecast_time_unit)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, self->forecast_time_unit_, &forecast_time_unit)) != GRIB_SUCCESS) return err; if ((err = a->unpack_long(&start_step_value_old, &len)) != GRIB_SUCCESS) return err; @@ -116,39 +113,39 @@ static int pack_long_new_(grib_accessor* a, const long start_step_value, const l eccodes::Step forecast_time(start_step_value, start_step_unit); eccodes::Step time_range_new{}; - auto time_range_opt = get_step(h, self->time_range_value, self->time_range_unit); + auto time_range_opt = get_step(h, self->time_range_value_, self->time_range_unit_); if (time_range_opt) { auto time_range = time_range_opt.value(); - time_range = time_range - (forecast_time - start_step_old); + time_range = time_range - (forecast_time - start_step_old); if (time_range.value() < 0) - time_range = eccodes::Step{0l, time_range.unit()}; + time_range = eccodes::Step{ 0l, time_range.unit() }; auto [sa, sb] = find_common_units(forecast_time.optimize_unit(), time_range.optimize_unit()); - if ((err = set_step(h, self->forecast_time_value, self->forecast_time_unit, sa)) != GRIB_SUCCESS) + if ((err = set_step(h, self->forecast_time_value_, self->forecast_time_unit_, sa)) != GRIB_SUCCESS) return err; if ((err = grib_set_long_internal(h, "startStepUnit", forecast_time.unit().value())) != GRIB_SUCCESS) return err; - if ((err = set_step(h, self->time_range_value, self->time_range_unit, sb)) != GRIB_SUCCESS) + if ((err = set_step(h, self->time_range_value_, self->time_range_unit_, sb)) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; } - if (eccodes::Unit{force_step_units} == eccodes::Unit{eccodes::Unit::Value::MISSING}) { + if (eccodes::Unit{ force_step_units } == eccodes::Unit{ eccodes::Unit::Value::MISSING }) { forecast_time.optimize_unit(); } if ((err = grib_set_long_internal(h, "startStepUnit", forecast_time.unit().value())) != GRIB_SUCCESS) return err; - if ((err = set_step(h, self->forecast_time_value, self->forecast_time_unit, forecast_time)) != GRIB_SUCCESS) + if ((err = set_step(h, self->forecast_time_value_, self->forecast_time_unit_, forecast_time)) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; } -int grib_accessor_class_step_in_units_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_step_in_units_t::pack_long(const long* val, size_t* len) { - grib_handle* h = grib_handle_of_accessor(a); - int ret = GRIB_SUCCESS; + grib_handle* h = grib_handle_of_accessor(this); + int ret = GRIB_SUCCESS; long force_step_units; if ((ret = grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS) @@ -156,12 +153,12 @@ int grib_accessor_class_step_in_units_t::pack_long(grib_accessor* a, const long* long start_step_unit; try { - if (eccodes::Unit{force_step_units} == eccodes::Unit{eccodes::Unit::Value::MISSING}) { + if (eccodes::Unit{ force_step_units } == eccodes::Unit{ eccodes::Unit::Value::MISSING }) { if ((ret = grib_get_long_internal(h, "startStepUnit", &start_step_unit)) != GRIB_SUCCESS) return ret; - if (eccodes::Unit{start_step_unit} == eccodes::Unit{eccodes::Unit::Value::MISSING}) - start_step_unit = eccodes::Unit{eccodes::Unit::Value::HOUR}.value(); + if (eccodes::Unit{ start_step_unit } == eccodes::Unit{ eccodes::Unit::Value::MISSING }) + start_step_unit = eccodes::Unit{ eccodes::Unit::Value::HOUR }.value(); } else { start_step_unit = force_step_units; @@ -172,56 +169,55 @@ int grib_accessor_class_step_in_units_t::pack_long(grib_accessor* a, const long* return GRIB_DECODING_ERROR; } - ret = pack_long_new_(a, *val, start_step_unit, force_step_units); + ret = pack_long_new_(this, *val, start_step_unit, force_step_units); return ret; } -int grib_accessor_class_step_in_units_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_step_in_units_t::pack_string(const char* val, size_t* len) { - grib_handle* h = grib_handle_of_accessor(a); - //long force_step_units = eccodes::Unit(eccodes::Unit::Value::MISSING).value(); + grib_handle* h = grib_handle_of_accessor(this); + // long force_step_units = eccodes::Unit(eccodes::Unit::Value::MISSING).value(); int ret = GRIB_SUCCESS; long force_step_units; if ((ret = grib_get_long_internal(h, "forceStepUnits", &force_step_units)) != GRIB_SUCCESS) return ret; try { - eccodes::Step step = step_from_string(val, eccodes::Unit{force_step_units}); - if ((ret = pack_long_new_(a, step.value(), step.unit().value(), force_step_units)) != GRIB_SUCCESS) + eccodes::Step step = step_from_string(val, eccodes::Unit{ force_step_units }); + if ((ret = pack_long_new_(this, step.value(), step.unit().value(), force_step_units)) != GRIB_SUCCESS) return ret; } catch (std::exception& e) { - grib_context_log(a->context, GRIB_LOG_ERROR, "step_in_units: %s", e.what()); + grib_context_log(context_, GRIB_LOG_ERROR, "step_in_units: %s", e.what()); return GRIB_DECODING_ERROR; } return GRIB_SUCCESS; } -int grib_accessor_class_step_in_units_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_step_in_units_t::unpack_string(char* val, size_t* len) { - const grib_accessor_step_in_units_t* self = (grib_accessor_step_in_units_t*)a; - grib_handle* h = grib_handle_of_accessor(a); - int ret = GRIB_SUCCESS; + grib_handle* h = grib_handle_of_accessor(this); + int ret = GRIB_SUCCESS; long start_step_value = 0; - long start_step_unit = 0; - long step_units = 0; - char fp_format[128] = "%g"; - size_t fp_format_len = sizeof(fp_format); - int show_hours = a->context->grib_hourly_steps_with_units; + long start_step_unit = 0; + long step_units = 0; + char fp_format[128] = "%g"; + size_t fp_format_len = sizeof(fp_format); + int show_hours = context_->grib_hourly_steps_with_units; if ((ret = grib_get_long_internal(h, "startStep", &start_step_value)) != GRIB_SUCCESS) return ret; if ((ret = grib_get_long_internal(h, "startStepUnit", &start_step_unit)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(h, self->step_units, &step_units))) + if ((ret = grib_get_long_internal(h, step_units_, &step_units))) return ret; if ((ret = grib_get_string_internal(h, "formatForDoubles", fp_format, &fp_format_len)) != GRIB_SUCCESS) return ret; try { - eccodes::Step step{start_step_value, start_step_unit}; + eccodes::Step step{ start_step_value, start_step_unit }; std::stringstream ss; ss << step.value(fp_format, show_hours); @@ -243,16 +239,16 @@ int grib_accessor_class_step_in_units_t::unpack_string(grib_accessor* a, char* v return GRIB_SUCCESS; } -int grib_accessor_class_step_in_units_t::get_native_type(grib_accessor* a) +long grib_accessor_step_in_units_t::get_native_type() { - grib_handle* h = grib_handle_of_accessor(a); - const int show_units_for_hours = a->context->grib_hourly_steps_with_units; + grib_handle* h = grib_handle_of_accessor(this); + const int show_units_for_hours = context_->grib_hourly_steps_with_units; if (!show_units_for_hours) { long step_units = 0; if (grib_get_long_internal(h, "stepUnits", &step_units) == GRIB_SUCCESS) { - if (eccodes::Unit{step_units} == eccodes::Unit::Value::HOUR) { - return GRIB_TYPE_LONG; // For backward compatibility + if (eccodes::Unit{ step_units } == eccodes::Unit::Value::HOUR) { + return GRIB_TYPE_LONG; // For backward compatibility } } } diff --git a/src/accessor/grib_accessor_class_step_in_units.h b/src/accessor/grib_accessor_class_step_in_units.h index 66f4b2b44..74c71a0af 100644 --- a/src/accessor/grib_accessor_class_step_in_units.h +++ b/src/accessor/grib_accessor_class_step_in_units.h @@ -16,25 +16,22 @@ class grib_accessor_step_in_units_t : public grib_accessor_long_t { public: - /* Members defined in step_in_units */ - const char* forecast_time_value; - const char* forecast_time_unit; - const char* step_units; - const char* time_range_unit; - const char* time_range_value; -}; - -class grib_accessor_class_step_in_units_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_step_in_units_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_step_in_units_t() : + grib_accessor_long_t() { class_name_ = "step_in_units"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_step_in_units_t{}; } - int get_native_type(grib_accessor*) 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; - void dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + int pack_string(const char*, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +public: + const char* forecast_time_value_; + const char* forecast_time_unit_; + const char* step_units_; + const char* time_range_unit_; + const char* time_range_value_; }; diff --git a/src/accessor/grib_accessor_class_sum.cc b/src/accessor/grib_accessor_class_sum.cc index 5eb3882d1..d23706077 100644 --- a/src/accessor/grib_accessor_class_sum.cc +++ b/src/accessor/grib_accessor_class_sum.cc @@ -10,63 +10,27 @@ #include "grib_accessor_class_sum.h" -grib_accessor_class_sum_t _grib_accessor_class_sum{ "sum" }; -grib_accessor_class* grib_accessor_class_sum = &_grib_accessor_class_sum; +grib_accessor_sum_t _grib_accessor_sum{}; +grib_accessor* grib_accessor_sum = &_grib_accessor_sum; - -void grib_accessor_class_sum_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_sum_t::init(const long l, grib_arguments* c) { - grib_accessor_class_double_t::init(a, l, c); - grib_accessor_sum_t* self = (grib_accessor_sum_t*)a; - int n = 0; - self->values = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + grib_accessor_double_t::init(l, c); + int n = 0; + values_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_sum_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_sum_t::unpack_long(long* val, size_t* len) { - grib_accessor_sum_t* self = (grib_accessor_sum_t*)a; int ret = 0; size_t size = 0; long* values = 0; - size_t i = 0; - long count = 0; - - ret = value_count(a, &count); - if (ret) - return ret; - size = count; - - if (size == 0) { - *val = 0; - return GRIB_SUCCESS; - } - values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); - if (!values) - return GRIB_OUT_OF_MEMORY; - - grib_get_long_array(grib_handle_of_accessor(a), self->values, values, &size); - - *val = 0; - for (i = 0; i < size; i++) - *val += values[i]; - - grib_context_free(a->context, values); - - return GRIB_SUCCESS; -} - -int grib_accessor_class_sum_t::unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_sum_t* self = (grib_accessor_sum_t*)a; - int ret = 0; - size_t size = 0; - double* values = 0; - size_t i = 0; + long i; long count = 0; - ret = value_count(a, &count); + ret = value_count(&count); if (ret) return ret; size = count; @@ -75,36 +39,67 @@ int grib_accessor_class_sum_t::unpack_double(grib_accessor* a, double* val, size *val = 0; return GRIB_SUCCESS; } - values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * size); + values = (long*)grib_context_malloc_clear(context_, sizeof(long) * size); if (!values) return GRIB_OUT_OF_MEMORY; - ret = grib_get_double_array(grib_handle_of_accessor(a), self->values, values, &size); + grib_get_long_array(grib_handle_of_accessor(this), values_, values, &size); + + *val = 0; + for (i = 0; i < size; i++) + *val += values[i]; + + grib_context_free(context_, values); + + return GRIB_SUCCESS; +} + +int grib_accessor_sum_t::unpack_double(double* val, size_t* len) +{ + int ret = 0; + size_t size = 0; + double* values = 0; + long i; + long count = 0; + + ret = value_count(&count); + if (ret) + return ret; + size = count; + + if (size == 0) { + *val = 0; + return GRIB_SUCCESS; + } + values = (double*)grib_context_malloc_clear(context_, sizeof(double) * size); + if (!values) + return GRIB_OUT_OF_MEMORY; + + ret = grib_get_double_array(grib_handle_of_accessor(this), values_, values, &size); if (ret) { - grib_context_free(a->context, values); + grib_context_free(context_, values); return ret; } *val = 0; for (i = 0; i < size; i++) *val += values[i]; - grib_context_free(a->context, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } -int grib_accessor_class_sum_t::value_count(grib_accessor* a, long* count) +int grib_accessor_sum_t::value_count(long* count) { - grib_accessor_sum_t* self = (grib_accessor_sum_t*)a; size_t n = 0; int ret = GRIB_SUCCESS; - ret = grib_get_size(grib_handle_of_accessor(a), self->values, &n); + ret = grib_get_size(grib_handle_of_accessor(this), values_, &n); *count = n; if (ret) - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s is unable to get size of %s", a->name, self->values); + grib_context_log(context_, GRIB_LOG_ERROR, + "%s is unable to get size of %s", name_, values_); return ret; } diff --git a/src/accessor/grib_accessor_class_sum.h b/src/accessor/grib_accessor_class_sum.h index 5667d8da9..1ea5dfeed 100644 --- a/src/accessor/grib_accessor_class_sum.h +++ b/src/accessor/grib_accessor_class_sum.h @@ -16,17 +16,14 @@ class grib_accessor_sum_t : public grib_accessor_double_t { public: - /* Members defined in sum */ - const char* values; -}; - -class grib_accessor_class_sum_t : public grib_accessor_class_double_t -{ -public: - grib_accessor_class_sum_t(const char* name) : grib_accessor_class_double_t(name) {} + grib_accessor_sum_t() : + grib_accessor_double_t() { class_name_ = "sum"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_sum_t{}; } - int unpack_double(grib_accessor*, double* val, size_t* len) override; - 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; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +private: + const char* values_; }; diff --git a/src/accessor/grib_accessor_class_suppressed.cc b/src/accessor/grib_accessor_class_suppressed.cc index 7cc05c5e1..29a78cc1b 100644 --- a/src/accessor/grib_accessor_class_suppressed.cc +++ b/src/accessor/grib_accessor_class_suppressed.cc @@ -10,62 +10,60 @@ #include "grib_accessor_class_suppressed.h" -grib_accessor_class_suppressed_t _grib_accessor_class_suppressed{ "suppressed" }; -grib_accessor_class* grib_accessor_class_suppressed = &_grib_accessor_class_suppressed; +grib_accessor_suppressed_t _grib_accessor_suppressed{}; +grib_accessor* grib_accessor_suppressed = &_grib_accessor_suppressed; - -void grib_accessor_class_suppressed_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_suppressed_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_suppressed_t* self = (grib_accessor_suppressed_t*)a; - self->args = c; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; + grib_accessor_long_t::init(l, c); + args_ = c; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + length_ = 0; } static void log_message(grib_accessor* a) { grib_accessor_suppressed_t* self = (grib_accessor_suppressed_t*)a; - int i = 0; - grib_handle* hand = grib_handle_of_accessor(a); + int i = 0; + grib_handle* hand = grib_handle_of_accessor(a); - grib_context_log(a->context, GRIB_LOG_ERROR, - "key '%s' is unavailable in this version.", a->name); - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(a->context_, GRIB_LOG_ERROR, + "key '%s' is unavailable in this version.", a->name_); + grib_context_log(a->context_, GRIB_LOG_ERROR, "Please use the following key(s):"); - while (grib_arguments_get_name(hand, self->args, i)) { - grib_context_log(a->context, GRIB_LOG_ERROR, "\t- %s", - grib_arguments_get_name(hand, self->args, i)); + while (grib_arguments_get_name(hand, self->args_, i)) { + grib_context_log(a->context_, GRIB_LOG_ERROR, "\t- %s", + grib_arguments_get_name(hand, self->args_, i)); i++; } } -int grib_accessor_class_suppressed_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_suppressed_t::unpack_string(char* val, size_t* len) { - log_message(a); + log_message(this); return GRIB_NOT_FOUND; } -int grib_accessor_class_suppressed_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_suppressed_t::unpack_long(long* val, size_t* len) { - log_message(a); + log_message(this); return GRIB_NOT_FOUND; } -int grib_accessor_class_suppressed_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_suppressed_t::unpack_double(double* val, size_t* len) { - log_message(a); + log_message(this); return GRIB_NOT_FOUND; } -int grib_accessor_class_suppressed_t::value_count(grib_accessor* a, long* count) +int grib_accessor_suppressed_t::value_count(long* count) { *count = 1; return 0; } -int grib_accessor_class_suppressed_t::get_native_type(grib_accessor* a) +long grib_accessor_suppressed_t::get_native_type() { return GRIB_TYPE_STRING; } diff --git a/src/accessor/grib_accessor_class_suppressed.h b/src/accessor/grib_accessor_class_suppressed.h index 5d764be35..9c4f0a243 100644 --- a/src/accessor/grib_accessor_class_suppressed.h +++ b/src/accessor/grib_accessor_class_suppressed.h @@ -16,19 +16,16 @@ class grib_accessor_suppressed_t : public grib_accessor_long_t { public: - /* Members defined in suppressed */ - grib_arguments* args; -}; - -class grib_accessor_class_suppressed_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_suppressed_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_suppressed_t() : + grib_accessor_long_t() { class_name_ = "suppressed"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_suppressed_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; + long get_native_type() override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + +public: + grib_arguments* args_; }; diff --git a/src/accessor/grib_accessor_class_time.cc b/src/accessor/grib_accessor_class_time.cc index 921114465..ce647581b 100644 --- a/src/accessor/grib_accessor_class_time.cc +++ b/src/accessor/grib_accessor_class_time.cc @@ -10,41 +10,37 @@ #include "grib_accessor_class_time.h" -grib_accessor_class_time_t _grib_accessor_class_time{ "time" }; -grib_accessor_class* grib_accessor_class_time = &_grib_accessor_class_time; +grib_accessor_time_t _grib_accessor_time{}; +grib_accessor* grib_accessor_time = &_grib_accessor_time; - -void grib_accessor_class_time_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_time_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_time_t* self = (grib_accessor_time_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_long_t::init(l, c); + grib_handle* hand = grib_handle_of_accessor(this); + int n = 0; - self->hour = grib_arguments_get_name(hand, c, n++); - self->minute = grib_arguments_get_name(hand, c, n++); - self->second = grib_arguments_get_name(hand, c, n++); + hour_ = grib_arguments_get_name(hand, c, n++); + minute_ = grib_arguments_get_name(hand, c, n++); + second_ = grib_arguments_get_name(hand, c, n++); } -int grib_accessor_class_time_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_time_t::unpack_long(long* val, size_t* len) { - const grib_accessor_time_t* self = (grib_accessor_time_t*)a; - int ret = 0; long hour = 0, minute = 0, second = 0; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); - if ((ret = grib_get_long_internal(hand, self->hour, &hour)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, hour_, &hour)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->minute, &minute)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, minute_, &minute)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->second, &second)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, second_, &second)) != GRIB_SUCCESS) return ret; /* We ignore the 'seconds' in our time calculation! */ if (second != 0) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Key %s (%s): Truncating time: non-zero seconds(%ld) ignored", a->name, __func__, second); + grib_context_log(context_, GRIB_LOG_ERROR, + "Key %s (%s): Truncating time: non-zero seconds(%ld) ignored", name_, __func__, second); } if (*len < 1) @@ -61,13 +57,11 @@ int grib_accessor_class_time_t::unpack_long(grib_accessor* a, long* val, size_t* return GRIB_SUCCESS; } -int grib_accessor_class_time_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_time_t::pack_long(const long* val, size_t* len) { - const grib_accessor_time_t* self = (grib_accessor_time_t*)a; - - int ret = 0; - long v = val[0]; - grib_handle* hand = grib_handle_of_accessor(a); + int ret = 0; + long v = val[0]; + grib_handle* hand = grib_handle_of_accessor(this); long hour = 0, minute = 0, second = 0; if (*len != 1) @@ -76,7 +70,7 @@ int grib_accessor_class_time_t::pack_long(grib_accessor* a, const long* val, siz if (!is_time_valid(v)) { // ECC-1777: For now just a warning. Will later change to an error fprintf(stderr, "ECCODES WARNING : %s:%s: Time is not valid! hour=%ld min=%ld sec=%ld\n", - a->cclass->name, __func__, hour, minute, second); + class_name_, __func__, hour, minute, second); // return GRIB_ENCODING_ERROR; } @@ -84,27 +78,27 @@ int grib_accessor_class_time_t::pack_long(grib_accessor* a, const long* val, siz minute = v % 100; second = 0; /* We ignore the 'seconds' in our time calculation! */ - if ((ret = grib_set_long_internal(hand, self->hour, hour)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, hour_, hour)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(hand, self->minute, minute)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, minute_, minute)) != GRIB_SUCCESS) return ret; - if ((ret = grib_set_long_internal(hand, self->second, second)) != GRIB_SUCCESS) + if ((ret = grib_set_long_internal(hand, second_, second)) != GRIB_SUCCESS) return ret; return GRIB_SUCCESS; } -int grib_accessor_class_time_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_time_t::unpack_string(char* val, size_t* len) { - long v = 0; + long v = 0; size_t lsize = 1, lmin = 5; - unpack_long(a, &v, &lsize); + unpack_long(&v, &lsize); if (*len < lmin) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - a->cclass->name, a->name, lmin, *len); + class_name_, name_, lmin, *len); *len = lmin; return GRIB_BUFFER_TOO_SMALL; } diff --git a/src/accessor/grib_accessor_class_time.h b/src/accessor/grib_accessor_class_time.h index dee0325a9..d73427a84 100644 --- a/src/accessor/grib_accessor_class_time.h +++ b/src/accessor/grib_accessor_class_time.h @@ -16,19 +16,16 @@ class grib_accessor_time_t : public grib_accessor_long_t { public: - /* Members defined in time */ - const char* hour; - const char* minute; - const char* second; -}; - -class grib_accessor_class_time_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_time_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_time_t() : + grib_accessor_long_t() { class_name_ = "time"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_time_t{}; } - int pack_long(grib_accessor*, const long* 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; - void init(grib_accessor*, const long, grib_arguments*) override; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* hour_; + const char* minute_; + const char* second_; }; diff --git a/src/accessor/grib_accessor_class_to_double.cc b/src/accessor/grib_accessor_class_to_double.cc index afe26f2a1..a0e8675fc 100644 --- a/src/accessor/grib_accessor_class_to_double.cc +++ b/src/accessor/grib_accessor_class_to_double.cc @@ -10,76 +10,72 @@ #include "grib_accessor_class_to_double.h" -grib_accessor_class_to_double_t _grib_accessor_class_to_double{ "to_double" }; -grib_accessor_class* grib_accessor_class_to_double = &_grib_accessor_class_to_double; +grib_accessor_to_double_t _grib_accessor_to_double{}; +grib_accessor* grib_accessor_to_double = &_grib_accessor_to_double; - -void grib_accessor_class_to_double_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_to_double_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - grib_accessor_to_double_t* self = (grib_accessor_to_double_t*)a; + grib_accessor_gen_t::init(len, arg); - self->key = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 0); - self->start = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1); - self->length = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 2); - self->scale = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 3); - if (!self->scale) - self->scale = 1; + key_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, 0); + start_ = grib_arguments_get_long(grib_handle_of_accessor(this), arg, 1); + length_ = grib_arguments_get_long(grib_handle_of_accessor(this), arg, 2); + scale_ = grib_arguments_get_long(grib_handle_of_accessor(this), arg, 3); + if (!scale_) + scale_ = 1; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; + grib_accessor::flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + grib_accessor::length_ = 0; } -int grib_accessor_class_to_double_t::value_count(grib_accessor* a, long* count) +int grib_accessor_to_double_t::value_count(long* count) { - grib_accessor_to_double_t* self = (grib_accessor_to_double_t*)a; size_t size = 0; - int err = grib_get_size(grib_handle_of_accessor(a), self->key, &size); + int err = grib_get_size(grib_handle_of_accessor(this), key_, &size); *count = size; return err; } -size_t grib_accessor_class_to_double_t::string_length(grib_accessor* a) +size_t grib_accessor_to_double_t::string_length() { - grib_accessor_to_double_t* self = (grib_accessor_to_double_t*)a; size_t size = 0; - if (self->length) - return self->length; + if (length_) + return length_; - grib_get_string_length_acc(a, &size); + grib_get_string_length_acc(this, &size); return size; } -void grib_accessor_class_to_double_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_to_double_t::dump(grib_dumper* dumper) { - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); } -int grib_accessor_class_to_double_t::get_native_type(grib_accessor* a) +long grib_accessor_to_double_t::get_native_type() { return GRIB_TYPE_LONG; } -int grib_accessor_class_to_double_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_to_double_t::unpack_string(char* val, size_t* len) { - grib_accessor_to_double_t* self = (grib_accessor_to_double_t*)a; - - int err = 0; - char buff[512] = {0,}; + int err = 0; + char buff[512] = { + 0, + }; size_t size = 512; - size_t length = string_length(a); + size_t length = string_length(); if (*len < length + 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s, it contains %ld values", - *len, a->name, a->length + 1); + grib_context_log(context_, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s, it contains %ld values", + *len, name_, grib_accessor::length_ + 1); *len = length + 1; return GRIB_ARRAY_TOO_SMALL; } - err = grib_get_string(grib_handle_of_accessor(a), self->key, buff, &size); + err = grib_get_string(grib_handle_of_accessor(this), key_, buff, &size); if (err) return err; if (length > size) { @@ -87,20 +83,21 @@ int grib_accessor_class_to_double_t::unpack_string(grib_accessor* a, char* val, length = size; } - memcpy(val, buff + self->start, length); + memcpy(val, buff + start_, length); val[length] = 0; - *len = length; + *len = length; return err; } -int grib_accessor_class_to_double_t::unpack_long(grib_accessor* a, long* v, size_t* len) +int grib_accessor_to_double_t::unpack_long(long* v, size_t* len) { - grib_accessor_to_double_t* self = (grib_accessor_to_double_t*)a; - char val[1024] = {0,}; + char val[1024] = { + 0, + }; size_t l = sizeof(val); char* last = NULL; - int err = a->unpack_string(val, &l); + int err = unpack_string(val, &l); if (err) return err; @@ -108,18 +105,19 @@ int grib_accessor_class_to_double_t::unpack_long(grib_accessor* a, long* v, size if (*last) { err = GRIB_WRONG_CONVERSION; } - *v /= self->scale; + *v /= scale_; return err; } -int grib_accessor_class_to_double_t::unpack_double(grib_accessor* a, double* v, size_t* len) +int grib_accessor_to_double_t::unpack_double(double* v, size_t* len) { - grib_accessor_to_double_t* self = (grib_accessor_to_double_t*)a; - char val[1024] = {0,}; + char val[1024] = { + 0, + }; size_t l = sizeof(val); char* last = NULL; - int err = a->unpack_string(val, &l); + int err = unpack_string(val, &l); if (err) return err; @@ -127,12 +125,12 @@ int grib_accessor_class_to_double_t::unpack_double(grib_accessor* a, double* v, if (*last) { err = GRIB_WRONG_CONVERSION; } - *v /= self->scale; + *v /= scale_; return err; } -long grib_accessor_class_to_double_t::next_offset(grib_accessor* a) +long grib_accessor_to_double_t::next_offset() { - return a->offset + a->length; + return offset_ + grib_accessor::length_; } diff --git a/src/accessor/grib_accessor_class_to_double.h b/src/accessor/grib_accessor_class_to_double.h index c8755c90f..0c5a99d58 100644 --- a/src/accessor/grib_accessor_class_to_double.h +++ b/src/accessor/grib_accessor_class_to_double.h @@ -16,25 +16,22 @@ class grib_accessor_to_double_t : public grib_accessor_gen_t { public: - /* Members defined in to_double */ - const char* key; - long start; - size_t length; - long scale; -}; - -class grib_accessor_class_to_double_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_to_double_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_to_double_t() : + grib_accessor_gen_t() { class_name_ = "to_double"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_to_double_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; - size_t string_length(grib_accessor*) override; - long next_offset(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; + long get_native_type() override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + long next_offset() override; + int value_count(long*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +public: + const char* key_; + long start_; + size_t length_; + long scale_; }; diff --git a/src/accessor/grib_accessor_class_to_integer.cc b/src/accessor/grib_accessor_class_to_integer.cc index 827812db8..93b13ffef 100644 --- a/src/accessor/grib_accessor_class_to_integer.cc +++ b/src/accessor/grib_accessor_class_to_integer.cc @@ -10,76 +10,72 @@ #include "grib_accessor_class_to_integer.h" -grib_accessor_class_to_integer_t _grib_accessor_class_to_integer{ "to_integer" }; -grib_accessor_class* grib_accessor_class_to_integer = &_grib_accessor_class_to_integer; +grib_accessor_to_integer_t _grib_accessor_to_integer{}; +grib_accessor* grib_accessor_to_integer = &_grib_accessor_to_integer; - -void grib_accessor_class_to_integer_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_to_integer_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - grib_accessor_to_integer_t* self = (grib_accessor_to_integer_t*)a; + grib_accessor_gen_t::init(len, arg); - self->key = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 0); - self->start = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1); - self->length = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 2); + key_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, 0); + start_ = grib_arguments_get_long(grib_handle_of_accessor(this), arg, 1); + length_ = grib_arguments_get_long(grib_handle_of_accessor(this), arg, 2); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + length_ = 0; } -int grib_accessor_class_to_integer_t::value_count(grib_accessor* a, long* count) +int grib_accessor_to_integer_t::value_count(long* count) { - grib_accessor_to_integer_t* self = (grib_accessor_to_integer_t*)a; size_t size = 0; - int err = grib_get_size(grib_handle_of_accessor(a), self->key, &size); + int err = grib_get_size(grib_handle_of_accessor(this), key_, &size); *count = size; return err; } -size_t grib_accessor_class_to_integer_t::string_length(grib_accessor* a) +size_t grib_accessor_to_integer_t::string_length() { - grib_accessor_to_integer_t* self = (grib_accessor_to_integer_t*)a; size_t size = 0; - if (self->length) - return self->length; + if (length_) + return length_; - grib_get_string_length(grib_handle_of_accessor(a), self->key, &size); + grib_get_string_length(grib_handle_of_accessor(this), key_, &size); return size; } -void grib_accessor_class_to_integer_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_to_integer_t::dump(grib_dumper* dumper) { - grib_dump_long(dumper, a, NULL); + grib_dump_long(dumper, this, NULL); } -int grib_accessor_class_to_integer_t::get_native_type(grib_accessor* a) +long grib_accessor_to_integer_t::get_native_type() { return GRIB_TYPE_LONG; } -int grib_accessor_class_to_integer_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_to_integer_t::unpack_string(char* val, size_t* len) { - grib_accessor_to_integer_t* self = (grib_accessor_to_integer_t*)a; - - int err = 0; - char buff[512] = {0,}; + int err = 0; + char buff[512] = { + 0, + }; size_t size = 512; - size_t length = string_length(a); + size_t length = string_length(); if (*len < length + 1) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, + const char* cclass_name = class_name_; + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, length + 1, *len); + cclass_name, name_, length + 1, *len); *len = length + 1; return GRIB_BUFFER_TOO_SMALL; } - err = grib_get_string(grib_handle_of_accessor(a), self->key, buff, &size); + err = grib_get_string(grib_handle_of_accessor(this), key_, buff, &size); if (err) return err; if (length > size) { @@ -87,36 +83,38 @@ int grib_accessor_class_to_integer_t::unpack_string(grib_accessor* a, char* val, length = size; } - memcpy(val, buff + self->start, length); + memcpy(val, buff + start_, length); val[length] = 0; - *len = length; + *len = length; return GRIB_SUCCESS; } -int grib_accessor_class_to_integer_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_to_integer_t::pack_string(const char* val, size_t* len) { return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_to_integer_t::pack_long(grib_accessor* a, const long* v, size_t* len) +int grib_accessor_to_integer_t::pack_long(const long* v, size_t* len) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as an integer", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, "Should not pack %s as an integer", name_); return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_to_integer_t::pack_double(grib_accessor* a, const double* v, size_t* len) +int grib_accessor_to_integer_t::pack_double(const double* v, size_t* len) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as a double", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, "Should not pack %s as a double", name_); return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_to_integer_t::unpack_long(grib_accessor* a, long* v, size_t* len) +int grib_accessor_to_integer_t::unpack_long(long* v, size_t* len) { - char val[1024] = {0,}; + char val[1024] = { + 0, + }; size_t l = sizeof(val); char* last = NULL; - int err = unpack_string(a, val, &l); + int err = unpack_string(val, &l); if (err) return err; @@ -127,17 +125,17 @@ int grib_accessor_class_to_integer_t::unpack_long(grib_accessor* a, long* v, siz return GRIB_SUCCESS; } -int grib_accessor_class_to_integer_t::unpack_double(grib_accessor* a, double* v, size_t* len) +int grib_accessor_to_integer_t::unpack_double(double* v, size_t* len) { size_t l = 1; long val = 0; - int err = unpack_long(a, &val, &l); + int err = unpack_long(&val, &l); *v = (double)val; return err; } -long grib_accessor_class_to_integer_t::next_offset(grib_accessor* a) +long grib_accessor_to_integer_t::next_offset() { - return a->offset + a->length; + return offset_ + length_; } diff --git a/src/accessor/grib_accessor_class_to_integer.h b/src/accessor/grib_accessor_class_to_integer.h index da8334e4f..f8426dd59 100644 --- a/src/accessor/grib_accessor_class_to_integer.h +++ b/src/accessor/grib_accessor_class_to_integer.h @@ -16,27 +16,24 @@ class grib_accessor_to_integer_t : public grib_accessor_gen_t { public: - /* Members defined in to_integer */ - const char* key; - long start; - size_t length; -}; - -class grib_accessor_class_to_integer_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_to_integer_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_to_integer_t() : + grib_accessor_gen_t() { class_name_ = "to_integer"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_to_integer_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; - long next_offset(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; + long get_native_type() override; + int pack_double(const double* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + int pack_string(const char*, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + long next_offset() override; + int value_count(long*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +private: + const char* key_; + long start_; + size_t length_; }; diff --git a/src/accessor/grib_accessor_class_to_string.cc b/src/accessor/grib_accessor_class_to_string.cc index c6b093a5f..09642825f 100644 --- a/src/accessor/grib_accessor_class_to_string.cc +++ b/src/accessor/grib_accessor_class_to_string.cc @@ -10,76 +10,71 @@ #include "grib_accessor_class_to_string.h" -grib_accessor_class_to_string_t _grib_accessor_class_to_string{ "to_string" }; -grib_accessor_class* grib_accessor_class_to_string = &_grib_accessor_class_to_string; +grib_accessor_to_string_t _grib_accessor_to_string{}; +grib_accessor* grib_accessor_to_string = &_grib_accessor_to_string; - -void grib_accessor_class_to_string_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_to_string_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - grib_accessor_to_string_t* self = (grib_accessor_to_string_t*)a; + grib_accessor_gen_t::init(len, arg); - self->key = grib_arguments_get_name(grib_handle_of_accessor(a), arg, 0); - self->start = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 1); - self->length = grib_arguments_get_long(grib_handle_of_accessor(a), arg, 2); + key_ = grib_arguments_get_name(grib_handle_of_accessor(this), arg, 0); + start_ = grib_arguments_get_long(grib_handle_of_accessor(this), arg, 1); + length_ = grib_arguments_get_long(grib_handle_of_accessor(this), arg, 2); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->length = 0; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + grib_accessor_gen_t::length_ = 0; } -int grib_accessor_class_to_string_t::value_count(grib_accessor* a, long* count) +int grib_accessor_to_string_t::value_count(long* count) { - grib_accessor_to_string_t* self = (grib_accessor_to_string_t*)a; size_t size = 0; - int err = grib_get_size(grib_handle_of_accessor(a), self->key, &size); + int err = grib_get_size(grib_handle_of_accessor(this), key_, &size); *count = size; return err; } -size_t grib_accessor_class_to_string_t::string_length(grib_accessor* a) +size_t grib_accessor_to_string_t::string_length() { - grib_accessor_to_string_t* self = (grib_accessor_to_string_t*)a; - - if (self->length) - return self->length; + if (length_) + return length_; size_t size = 0; - grib_get_string_length(grib_handle_of_accessor(a), self->key, &size); + grib_get_string_length(grib_handle_of_accessor(this), key_, &size); return size; } -void grib_accessor_class_to_string_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_to_string_t::dump(grib_dumper* dumper) { - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); } -int grib_accessor_class_to_string_t::get_native_type(grib_accessor* a) +long grib_accessor_to_string_t::get_native_type() { return GRIB_TYPE_STRING; } -int grib_accessor_class_to_string_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_to_string_t::unpack_string(char* val, size_t* len) { - grib_accessor_to_string_t* self = (grib_accessor_to_string_t*)a; + int err = 0; + char buff[512] = { + 0, + }; - int err = 0; - char buff[512] = {0,}; - - size_t length = string_length(a); + size_t length = string_length(); if (*len < length + 1) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, + const char* cclass_name = class_name_; + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, length + 1, *len); + cclass_name, name_, length + 1, *len); *len = length + 1; return GRIB_BUFFER_TOO_SMALL; } size_t size = sizeof(buff); - err = grib_get_string(grib_handle_of_accessor(a), self->key, buff, &size); + err = grib_get_string(grib_handle_of_accessor(this), key_, buff, &size); if (err) return err; if (length > size) { @@ -87,19 +82,21 @@ int grib_accessor_class_to_string_t::unpack_string(grib_accessor* a, char* val, length = size; } - memcpy(val, buff + self->start, length); + memcpy(val, buff + start_, length); val[length] = 0; - *len = length; + *len = length; return GRIB_SUCCESS; } -int grib_accessor_class_to_string_t::unpack_long(grib_accessor* a, long* v, size_t* len) +int grib_accessor_to_string_t::unpack_long(long* v, size_t* len) { - char val[1024] = {0,}; + char val[1024] = { + 0, + }; size_t l = sizeof(val); char* last = NULL; - int err = unpack_string(a, val, &l); + int err = unpack_string(val, &l); if (err) return err; @@ -112,17 +109,17 @@ int grib_accessor_class_to_string_t::unpack_long(grib_accessor* a, long* v, size return err; } -int grib_accessor_class_to_string_t::unpack_double(grib_accessor* a, double* v, size_t* len) +int grib_accessor_to_string_t::unpack_double(double* v, size_t* len) { size_t l = 1; long val = 0; - int err = unpack_long(a, &val, &l); + int err = unpack_long(&val, &l); *v = (double)val; return err; } -long grib_accessor_class_to_string_t::next_offset(grib_accessor* a) +long grib_accessor_to_string_t::next_offset() { - return a->offset + a->length; + return offset_ + grib_accessor_gen_t::length_; } diff --git a/src/accessor/grib_accessor_class_to_string.h b/src/accessor/grib_accessor_class_to_string.h index ea6981276..c4a9b6cb9 100644 --- a/src/accessor/grib_accessor_class_to_string.h +++ b/src/accessor/grib_accessor_class_to_string.h @@ -16,24 +16,21 @@ class grib_accessor_to_string_t : public grib_accessor_gen_t { public: - /* Members defined in to_string */ - const char* key; - long start; - size_t length; -}; - -class grib_accessor_class_to_string_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_to_string_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_to_string_t() : + grib_accessor_gen_t() { class_name_ = "to_string"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_to_string_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; - size_t string_length(grib_accessor*) override; - long next_offset(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; + long get_native_type() override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + long next_offset() override; + int value_count(long*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +private: + const char* key_; + long start_; + size_t length_; }; diff --git a/src/accessor/grib_accessor_class_transient.cc b/src/accessor/grib_accessor_class_transient.cc index d40fdc9cc..0a7aca1ed 100644 --- a/src/accessor/grib_accessor_class_transient.cc +++ b/src/accessor/grib_accessor_class_transient.cc @@ -10,11 +10,10 @@ #include "grib_accessor_class_transient.h" -grib_accessor_class_transient_t _grib_accessor_class_transient{ "transient" }; -grib_accessor_class* grib_accessor_class_transient = &_grib_accessor_class_transient; +grib_accessor_transient_t _grib_accessor_transient{}; +grib_accessor* grib_accessor_transient = &_grib_accessor_transient; - -void grib_accessor_class_transient_t::init(grib_accessor* a, const long l, grib_arguments* args) +void grib_accessor_transient_t::init(const long l, grib_arguments* args) { - grib_accessor_class_variable_t::init(a, l, args); + grib_accessor_variable_t::init(l, args); } diff --git a/src/accessor/grib_accessor_class_transient.h b/src/accessor/grib_accessor_class_transient.h index e330ad686..8e04802ae 100644 --- a/src/accessor/grib_accessor_class_transient.h +++ b/src/accessor/grib_accessor_class_transient.h @@ -12,14 +12,11 @@ #include "grib_accessor_class_variable.h" -class grib_accessor_transient_t : public grib_accessor_variable_t { +class grib_accessor_transient_t : public grib_accessor_variable_t +{ public: -}; - -class grib_accessor_class_transient_t : public grib_accessor_class_variable_t { -public: - void init(grib_accessor* a, const long l, grib_arguments* args) override; - grib_accessor_class_transient_t(const char* name) : grib_accessor_class_variable_t(name) {}; + void init(const long l, grib_arguments* args) override; + grib_accessor_transient_t() : + grib_accessor_variable_t() { class_name_ = "transient"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_transient_t{}; } }; - diff --git a/src/accessor/grib_accessor_class_transient_darray.cc b/src/accessor/grib_accessor_class_transient_darray.cc index 3766bb218..6fda795d8 100644 --- a/src/accessor/grib_accessor_class_transient_darray.cc +++ b/src/accessor/grib_accessor_class_transient_darray.cc @@ -10,111 +10,100 @@ #include "grib_accessor_class_transient_darray.h" -grib_accessor_class_transient_darray_t _grib_accessor_class_transient_darray{ "transient_darray" }; -grib_accessor_class* grib_accessor_class_transient_darray = &_grib_accessor_class_transient_darray; +grib_accessor_transient_darray_t _grib_accessor_transient_darray{}; +grib_accessor* grib_accessor_transient_darray = &_grib_accessor_transient_darray; - -void grib_accessor_class_transient_darray_t::init(grib_accessor* a, const long length, grib_arguments* args) +void grib_accessor_transient_darray_t::init(const long length, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, length, args); - grib_accessor_transient_darray_t* self = (grib_accessor_transient_darray_t*)a; - self->arr = NULL; - self->type = GRIB_TYPE_DOUBLE; - a->length = 0; + grib_accessor_gen_t::init(length, args); + arr_ = NULL; + type_ = GRIB_TYPE_DOUBLE; + length_ = 0; } -void grib_accessor_class_transient_darray_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_transient_darray_t::dump(grib_dumper* dumper) { - grib_dump_double(dumper, a, NULL); + grib_dump_double(dumper, this, NULL); } -int grib_accessor_class_transient_darray_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_transient_darray_t::pack_double(const double* val, size_t* len) { - grib_accessor_transient_darray_t* self = (grib_accessor_transient_darray_t*)a; - - if (self->arr) - grib_darray_delete(a->context, self->arr); - self->arr = grib_darray_new(a->context, *len, 10); + if (arr_) + grib_darray_delete(context_, arr_); + arr_ = grib_darray_new(context_, *len, 10); for (size_t i = 0; i < *len; i++) - grib_darray_push(a->context, self->arr, val[i]); + grib_darray_push(context_, arr_, val[i]); return GRIB_SUCCESS; } -int grib_accessor_class_transient_darray_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_transient_darray_t::pack_long(const long* val, size_t* len) { - grib_accessor_transient_darray_t* self = (grib_accessor_transient_darray_t*)a; - - if (self->arr) - grib_darray_delete(a->context, self->arr); - self->arr = grib_darray_new(a->context, *len, 10); + if (arr_) + grib_darray_delete(context_, arr_); + arr_ = grib_darray_new(context_, *len, 10); for (size_t i = 0; i < *len; i++) - grib_darray_push(a->context, self->arr, (double)val[i]); + grib_darray_push(context_, arr_, (double)val[i]); return GRIB_SUCCESS; } -int grib_accessor_class_transient_darray_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_transient_darray_t::unpack_double(double* val, size_t* len) { - grib_accessor_transient_darray_t* self = (grib_accessor_transient_darray_t*)a; long count = 0; - value_count(a, &count); + value_count(&count); if (*len < count) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s (setting %ld, required %ld) ", a->name, *len, count); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s (setting %ld, required %ld) ", name_, *len, count); return GRIB_ARRAY_TOO_SMALL; } *len = count; for (size_t i = 0; i < *len; i++) - val[i] = self->arr->v[i]; + val[i] = arr_->v[i]; return GRIB_SUCCESS; } -int grib_accessor_class_transient_darray_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_transient_darray_t::unpack_long(long* val, size_t* len) { - grib_accessor_transient_darray_t* self = (grib_accessor_transient_darray_t*)a; long count = 0; - value_count(a, &count); + value_count(&count); if (*len < count) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s (setting %ld, required %ld) ", a->name, *len, count); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s (setting %ld, required %ld) ", name_, *len, count); return GRIB_ARRAY_TOO_SMALL; } *len = count; for (size_t i = 0; i < *len; i++) - val[i] = (long)self->arr->v[i]; + val[i] = (long)arr_->v[i]; return GRIB_SUCCESS; } -void grib_accessor_class_transient_darray_t::destroy(grib_context* c, grib_accessor* a) +void grib_accessor_transient_darray_t::destroy(grib_context* c) { - grib_accessor_transient_darray_t* self = (grib_accessor_transient_darray_t*)a; - if (self->arr) - grib_darray_delete(a->context, self->arr); - grib_accessor_class_gen_t::destroy(c, a); + if (arr_) + grib_darray_delete(context_, arr_); + grib_accessor_gen_t::destroy(c); } -int grib_accessor_class_transient_darray_t::value_count(grib_accessor* a, long* count) +int grib_accessor_transient_darray_t::value_count(long* count) { - grib_accessor_transient_darray_t* self = (grib_accessor_transient_darray_t*)a; - if (self->arr) - *count = grib_darray_used_size(self->arr); + if (arr_) + *count = grib_darray_used_size(arr_); else *count = 0; return 0; } -int grib_accessor_class_transient_darray_t::get_native_type(grib_accessor* a) +long grib_accessor_transient_darray_t::get_native_type() { - const grib_accessor_transient_darray_t* self = (grib_accessor_transient_darray_t*)a; - return self->type; + return type_; } diff --git a/src/accessor/grib_accessor_class_transient_darray.h b/src/accessor/grib_accessor_class_transient_darray.h index 230dfa1a1..9c30fb7a0 100644 --- a/src/accessor/grib_accessor_class_transient_darray.h +++ b/src/accessor/grib_accessor_class_transient_darray.h @@ -16,23 +16,20 @@ class grib_accessor_transient_darray_t : public grib_accessor_gen_t { public: - /* Members defined in transient_darray */ - grib_darray* arr; - int type; -}; - -class grib_accessor_class_transient_darray_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_transient_darray_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_transient_darray_t() : + grib_accessor_gen_t() { class_name_ = "transient_darray"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_transient_darray_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; - int unpack_long(grib_accessor*, long* val, 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; + long get_native_type() override; + int pack_double(const double* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int value_count(long*) override; + void destroy(grib_context*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +private: + grib_darray* arr_; + int type_; }; diff --git a/src/accessor/grib_accessor_class_trim.cc b/src/accessor/grib_accessor_class_trim.cc index 4d4fb733d..4d6ee6c4c 100644 --- a/src/accessor/grib_accessor_class_trim.cc +++ b/src/accessor/grib_accessor_class_trim.cc @@ -10,71 +10,72 @@ #include "grib_accessor_class_trim.h" -grib_accessor_class_trim_t _grib_accessor_class_trim{ "trim" }; -grib_accessor_class* grib_accessor_class_trim = &_grib_accessor_class_trim; +grib_accessor_trim_t _grib_accessor_trim{}; +grib_accessor* grib_accessor_trim = &_grib_accessor_trim; - -void grib_accessor_class_trim_t::init(grib_accessor* a, const long l, grib_arguments* arg) +void grib_accessor_trim_t::init(const long l, grib_arguments* arg) { - grib_accessor_class_ascii_t::init(a, l, arg); - int n = 0; - grib_accessor_trim_t* self = (grib_accessor_trim_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_accessor_ascii_t::init(l, arg); + int n = 0; + grib_handle* h = grib_handle_of_accessor(this); - self->input = grib_arguments_get_name(h, arg, n++); - self->trim_left = grib_arguments_get_long(h, arg, n++); - self->trim_right = grib_arguments_get_long(h, arg, n++); - DEBUG_ASSERT(self->trim_left == 0 || self->trim_left == 1); - DEBUG_ASSERT(self->trim_right == 0 || self->trim_right == 1); + input_ = grib_arguments_get_name(h, arg, n++); + trim_left_ = grib_arguments_get_long(h, arg, n++); + trim_right_ = grib_arguments_get_long(h, arg, n++); + DEBUG_ASSERT(trim_left_ == 0 || trim_left_ == 1); + DEBUG_ASSERT(trim_right_ == 0 || trim_right_ == 1); } -int grib_accessor_class_trim_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_trim_t::unpack_string(char* val, size_t* len) { - grib_accessor_trim_t* self = (grib_accessor_trim_t*)a; - int err = 0; - grib_handle* h = grib_handle_of_accessor(a); - char input[256] = {0,}; + grib_handle* h = grib_handle_of_accessor(this); + char input[256] = { + 0, + }; size_t size = sizeof(input) / sizeof(*input); char* pInput = input; - err = grib_get_string(h, self->input, input, &size); + err = grib_get_string(h, input_, input, &size); if (err) return err; - string_lrtrim(&pInput, self->trim_left, self->trim_right); + string_lrtrim(&pInput, trim_left_, trim_right_); snprintf(val, 1024, "%s", pInput); size = strlen(val); *len = size + 1; return GRIB_SUCCESS; } -int grib_accessor_class_trim_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_trim_t::pack_string(const char* val, size_t* len) { - char input[256] = {0,}; + char input[256] = { + 0, + }; size_t inputLen = 256; - char buf[256] = {0,}; + char buf[256] = { + 0, + }; char* pBuf = NULL; int err; - grib_handle* h = grib_handle_of_accessor(a); - grib_accessor_trim_t* self = (grib_accessor_trim_t*)a; - grib_accessor* inputAccesstor = grib_find_accessor(h, self->input); + grib_handle* h = grib_handle_of_accessor(this); + grib_accessor* inputAccesstor = grib_find_accessor(h, input_); if (!inputAccesstor) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor for %s not found", self->input); + grib_context_log(context_, GRIB_LOG_ERROR, "Accessor for %s not found", input_); return GRIB_NOT_FOUND; } - if ((err = grib_get_string(h, self->input, input, &inputLen)) != GRIB_SUCCESS) + if ((err = grib_get_string(h, input_, input, &inputLen)) != GRIB_SUCCESS) return err; snprintf(buf, sizeof(buf), "%s", val); pBuf = buf; - string_lrtrim(&pBuf, self->trim_left, self->trim_right); + string_lrtrim(&pBuf, trim_left_, trim_right_); return inputAccesstor->pack_string(pBuf, len); } -size_t grib_accessor_class_trim_t::string_length(grib_accessor* a) +size_t grib_accessor_trim_t::string_length() { return 1024; } diff --git a/src/accessor/grib_accessor_class_trim.h b/src/accessor/grib_accessor_class_trim.h index d5c029a78..f0a0a552a 100644 --- a/src/accessor/grib_accessor_class_trim.h +++ b/src/accessor/grib_accessor_class_trim.h @@ -16,19 +16,16 @@ class grib_accessor_trim_t : public grib_accessor_ascii_t { public: - /* Members defined in trim */ - const char* input; - int trim_left; - int trim_right; -}; - -class grib_accessor_class_trim_t : public grib_accessor_class_ascii_t -{ -public: - grib_accessor_class_trim_t(const char* name) : grib_accessor_class_ascii_t(name) {} + grib_accessor_trim_t() : + grib_accessor_ascii_t() { class_name_ = "trim"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_trim_t{}; } - int pack_string(grib_accessor*, const char*, size_t* len) override; - int unpack_string(grib_accessor*, char*, size_t* len) override; - size_t string_length(grib_accessor*) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int pack_string(const char*, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + void init(const long, grib_arguments*) override; + +private: + const char* input_; + int trim_left_; + int trim_right_; }; diff --git a/src/accessor/grib_accessor_class_uint16.cc b/src/accessor/grib_accessor_class_uint16.cc index b17aa37cf..a045bdb15 100644 --- a/src/accessor/grib_accessor_class_uint16.cc +++ b/src/accessor/grib_accessor_class_uint16.cc @@ -10,15 +10,14 @@ #include "grib_accessor_class_uint16.h" -grib_accessor_class_uint16_t _grib_accessor_class_uint16{ "uint16" }; -grib_accessor_class* grib_accessor_class_uint16 = &_grib_accessor_class_uint16; +grib_accessor_uint16_t _grib_accessor_uint16{}; +grib_accessor* grib_accessor_uint16 = &_grib_accessor_uint16; - -int grib_accessor_class_uint16_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_uint16_t::unpack_long(long* val, size_t* len) { long value = 0; - /*long pos = a->offset;*/ - /*unsigned char* data = grib_handle_of_accessor(a)->buffer->data;*/ + /*long pos = offset_ ;*/ + /*unsigned char* data = grib_handle_of_accessor(this)->buffer->data;*/ if (*len < 1) { return GRIB_ARRAY_TOO_SMALL; @@ -29,7 +28,7 @@ int grib_accessor_class_uint16_t::unpack_long(grib_accessor* a, long* val, size_ return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_uint16_t::get_native_type(grib_accessor* a) +long grib_accessor_uint16_t::get_native_type() { return GRIB_TYPE_LONG; } diff --git a/src/accessor/grib_accessor_class_uint16.h b/src/accessor/grib_accessor_class_uint16.h index 05818ebbd..16ef19839 100644 --- a/src/accessor/grib_accessor_class_uint16.h +++ b/src/accessor/grib_accessor_class_uint16.h @@ -16,14 +16,9 @@ class grib_accessor_uint16_t : public grib_accessor_gen_t { public: - /* Members defined in uint16 */ -}; - -class grib_accessor_class_uint16_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_uint16_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_uint16_t() : + grib_accessor_gen_t() { class_name_ = "uint16"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_uint16_t{}; } - int get_native_type(grib_accessor*) override; - int unpack_long(grib_accessor*, long* val, size_t* len) override; + long get_native_type() override; + int unpack_long(long* val, size_t* len) override; }; diff --git a/src/accessor/grib_accessor_class_uint32.cc b/src/accessor/grib_accessor_class_uint32.cc index 015646cbb..eb77df508 100644 --- a/src/accessor/grib_accessor_class_uint32.cc +++ b/src/accessor/grib_accessor_class_uint32.cc @@ -10,15 +10,14 @@ #include "grib_accessor_class_uint32.h" -grib_accessor_class_uint32_t _grib_accessor_class_uint32{ "uint32" }; -grib_accessor_class* grib_accessor_class_uint32 = &_grib_accessor_class_uint32; +grib_accessor_uint32_t _grib_accessor_uint32{}; +grib_accessor* grib_accessor_uint32 = &_grib_accessor_uint32; - -int grib_accessor_class_uint32_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_uint32_t::unpack_long(long* val, size_t* len) { long value = 0; - /* long pos = a->offset; */ - /* unsigned char* data = grib_handle_of_accessor(a)->buffer->data; */ + /* long pos = offset_ ; */ + /* unsigned char* data = grib_handle_of_accessor(this)->buffer->data; */ if (*len < 1) { return GRIB_ARRAY_TOO_SMALL; @@ -29,7 +28,7 @@ int grib_accessor_class_uint32_t::unpack_long(grib_accessor* a, long* val, size_ return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_uint32_t::get_native_type(grib_accessor* a) +long grib_accessor_uint32_t::get_native_type() { return GRIB_TYPE_LONG; } diff --git a/src/accessor/grib_accessor_class_uint32.h b/src/accessor/grib_accessor_class_uint32.h index 143dfc809..cdc89ee98 100644 --- a/src/accessor/grib_accessor_class_uint32.h +++ b/src/accessor/grib_accessor_class_uint32.h @@ -16,14 +16,9 @@ class grib_accessor_uint32_t : public grib_accessor_gen_t { public: - /* Members defined in uint32 */ -}; - -class grib_accessor_class_uint32_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_uint32_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_uint32_t() : + grib_accessor_gen_t() { class_name_ = "uint32"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_uint32_t{}; } - int get_native_type(grib_accessor*) override; - int unpack_long(grib_accessor*, long* val, size_t* len) override; + long get_native_type() override; + int unpack_long(long* val, size_t* len) override; }; diff --git a/src/accessor/grib_accessor_class_uint32_little_endian.cc b/src/accessor/grib_accessor_class_uint32_little_endian.cc index fa8aeb03a..a85e7167c 100644 --- a/src/accessor/grib_accessor_class_uint32_little_endian.cc +++ b/src/accessor/grib_accessor_class_uint32_little_endian.cc @@ -10,15 +10,14 @@ #include "grib_accessor_class_uint32_little_endian.h" -grib_accessor_class_uint32_little_endian_t _grib_accessor_class_uint32_little_endian{ "uint32_little_endian" }; -grib_accessor_class* grib_accessor_class_uint32_little_endian = &_grib_accessor_class_uint32_little_endian; +grib_accessor_uint32_little_endian_t _grib_accessor_uint32_little_endian{}; +grib_accessor* grib_accessor_uint32_little_endian = &_grib_accessor_uint32_little_endian; - -int grib_accessor_class_uint32_little_endian_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_uint32_little_endian_t::unpack_long(long* val, size_t* len) { long value = 0; - /* long pos = a->offset; */ - /* unsigned char* data = grib_handle_of_accessor(a)->buffer->data; */ + /* long pos = offset_ ; */ + /* unsigned char* data = grib_handle_of_accessor(this)->buffer->data; */ if (*len < 1) { return GRIB_ARRAY_TOO_SMALL; @@ -29,7 +28,7 @@ int grib_accessor_class_uint32_little_endian_t::unpack_long(grib_accessor* a, lo return GRIB_NOT_IMPLEMENTED; } -int grib_accessor_class_uint32_little_endian_t::get_native_type(grib_accessor* a) +long grib_accessor_uint32_little_endian_t::get_native_type() { return GRIB_TYPE_LONG; } diff --git a/src/accessor/grib_accessor_class_uint32_little_endian.h b/src/accessor/grib_accessor_class_uint32_little_endian.h index 83e808bc5..fd1d3b842 100644 --- a/src/accessor/grib_accessor_class_uint32_little_endian.h +++ b/src/accessor/grib_accessor_class_uint32_little_endian.h @@ -16,14 +16,9 @@ class grib_accessor_uint32_little_endian_t : public grib_accessor_gen_t { public: - /* Members defined in uint32_little_endian */ -}; - -class grib_accessor_class_uint32_little_endian_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_uint32_little_endian_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_uint32_little_endian_t() : + grib_accessor_gen_t() { class_name_ = "uint32_little_endian"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_uint32_little_endian_t{}; } - int get_native_type(grib_accessor*) override; - int unpack_long(grib_accessor*, long* val, size_t* len) override; + long get_native_type() override; + int unpack_long(long* val, size_t* len) override; }; diff --git a/src/accessor/grib_accessor_class_uint64.cc b/src/accessor/grib_accessor_class_uint64.cc index a800a4630..d3eb032dd 100644 --- a/src/accessor/grib_accessor_class_uint64.cc +++ b/src/accessor/grib_accessor_class_uint64.cc @@ -10,15 +10,14 @@ #include "grib_accessor_class_uint64.h" -grib_accessor_class_uint64_t _grib_accessor_class_uint64{ "uint64" }; -grib_accessor_class* grib_accessor_class_uint64 = &_grib_accessor_class_uint64; +grib_accessor_uint64_t _grib_accessor_uint64{}; +grib_accessor* grib_accessor_uint64 = &_grib_accessor_uint64; - -int grib_accessor_class_uint64_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_uint64_t::unpack_long(long* val, size_t* len) { long value = 0; - long pos = a->offset; - unsigned char* data = grib_handle_of_accessor(a)->buffer->data; + long pos = offset_; + unsigned char* data = grib_handle_of_accessor(this)->buffer->data; unsigned long long result = 0, tmp; int i; @@ -36,7 +35,7 @@ int grib_accessor_class_uint64_t::unpack_long(grib_accessor* a, long* val, size_ /* Result does not fit in long */ if (tmp != result) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Value for %s cannot be decoded as a 'long' (%llu)", a->name, result); + grib_context_log(context_, GRIB_LOG_ERROR, "Value for %s cannot be decoded as a 'long' (%llu)", name_, result); return GRIB_DECODING_ERROR; } @@ -45,7 +44,7 @@ int grib_accessor_class_uint64_t::unpack_long(grib_accessor* a, long* val, size_ return GRIB_SUCCESS; } -int grib_accessor_class_uint64_t::get_native_type(grib_accessor* a) +long grib_accessor_uint64_t::get_native_type() { return GRIB_TYPE_LONG; } diff --git a/src/accessor/grib_accessor_class_uint64.h b/src/accessor/grib_accessor_class_uint64.h index d442b736d..e4ae74f2e 100644 --- a/src/accessor/grib_accessor_class_uint64.h +++ b/src/accessor/grib_accessor_class_uint64.h @@ -16,14 +16,9 @@ class grib_accessor_uint64_t : public grib_accessor_gen_t { public: - /* Members defined in uint64 */ -}; - -class grib_accessor_class_uint64_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_uint64_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_uint64_t() : + grib_accessor_gen_t() { class_name_ = "uint64"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_uint64_t{}; } - int get_native_type(grib_accessor*) override; - int unpack_long(grib_accessor*, long* val, size_t* len) override; + long get_native_type() override; + int unpack_long(long* val, size_t* len) override; }; diff --git a/src/accessor/grib_accessor_class_uint64_little_endian.cc b/src/accessor/grib_accessor_class_uint64_little_endian.cc index 25e537dbe..dd2048bb1 100644 --- a/src/accessor/grib_accessor_class_uint64_little_endian.cc +++ b/src/accessor/grib_accessor_class_uint64_little_endian.cc @@ -10,15 +10,14 @@ #include "grib_accessor_class_uint64_little_endian.h" -grib_accessor_class_uint64_little_endian_t _grib_accessor_class_uint64_little_endian{ "uint64_little_endian" }; -grib_accessor_class* grib_accessor_class_uint64_little_endian = &_grib_accessor_class_uint64_little_endian; +grib_accessor_uint64_little_endian_t _grib_accessor_uint64_little_endian{}; +grib_accessor* grib_accessor_uint64_little_endian = &_grib_accessor_uint64_little_endian; - -int grib_accessor_class_uint64_little_endian_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_uint64_little_endian_t::unpack_long(long* val, size_t* len) { long value = 0; - long pos = a->offset; - unsigned char* data = grib_handle_of_accessor(a)->buffer->data; + long pos = offset_; + unsigned char* data = grib_handle_of_accessor(this)->buffer->data; unsigned long long result = 0, tmp; int i; @@ -36,7 +35,7 @@ int grib_accessor_class_uint64_little_endian_t::unpack_long(grib_accessor* a, lo /* Result does not fit in long */ if (tmp != result) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Value for %s cannot be decoded as a 'long' (%llu)", a->name, result); + grib_context_log(context_, GRIB_LOG_ERROR, "Value for %s cannot be decoded as a 'long' (%llu)", name_, result); return GRIB_DECODING_ERROR; } @@ -45,7 +44,7 @@ int grib_accessor_class_uint64_little_endian_t::unpack_long(grib_accessor* a, lo return GRIB_SUCCESS; } -int grib_accessor_class_uint64_little_endian_t::get_native_type(grib_accessor* a) +long grib_accessor_uint64_little_endian_t::get_native_type() { return GRIB_TYPE_LONG; } diff --git a/src/accessor/grib_accessor_class_uint64_little_endian.h b/src/accessor/grib_accessor_class_uint64_little_endian.h index 9e8f4327e..a5cc9ad73 100644 --- a/src/accessor/grib_accessor_class_uint64_little_endian.h +++ b/src/accessor/grib_accessor_class_uint64_little_endian.h @@ -16,14 +16,9 @@ class grib_accessor_uint64_little_endian_t : public grib_accessor_gen_t { public: - /* Members defined in uint64_little_endian */ -}; - -class grib_accessor_class_uint64_little_endian_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_uint64_little_endian_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_uint64_little_endian_t() : + grib_accessor_gen_t() { class_name_ = "uint64_little_endian"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_uint64_little_endian_t{}; } - int get_native_type(grib_accessor*) override; - int unpack_long(grib_accessor*, long* val, size_t* len) override; + long get_native_type() override; + int unpack_long(long* val, size_t* len) override; }; diff --git a/src/accessor/grib_accessor_class_uint8.cc b/src/accessor/grib_accessor_class_uint8.cc index 90236aa50..ec764243d 100644 --- a/src/accessor/grib_accessor_class_uint8.cc +++ b/src/accessor/grib_accessor_class_uint8.cc @@ -10,15 +10,14 @@ #include "grib_accessor_class_uint8.h" -grib_accessor_class_uint8_t _grib_accessor_class_uint8{ "uint8" }; -grib_accessor_class* grib_accessor_class_uint8 = &_grib_accessor_class_uint8; +grib_accessor_uint8_t _grib_accessor_uint8{}; +grib_accessor* grib_accessor_uint8 = &_grib_accessor_uint8; - -int grib_accessor_class_uint8_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_uint8_t::unpack_long(long* val, size_t* len) { - long value = 0; - long pos = a->offset; - unsigned char* data = grib_handle_of_accessor(a)->buffer->data; + long value = 0; + long pos = offset_; + unsigned char* data = grib_handle_of_accessor(this)->buffer->data; if (*len < 1) { return GRIB_ARRAY_TOO_SMALL; @@ -31,7 +30,7 @@ int grib_accessor_class_uint8_t::unpack_long(grib_accessor* a, long* val, size_t return GRIB_SUCCESS; } -int grib_accessor_class_uint8_t::get_native_type(grib_accessor* a) +long grib_accessor_uint8_t::get_native_type() { return GRIB_TYPE_LONG; } diff --git a/src/accessor/grib_accessor_class_uint8.h b/src/accessor/grib_accessor_class_uint8.h index 8a58b27f3..948f75d9e 100644 --- a/src/accessor/grib_accessor_class_uint8.h +++ b/src/accessor/grib_accessor_class_uint8.h @@ -16,14 +16,9 @@ class grib_accessor_uint8_t : public grib_accessor_gen_t { public: - /* Members defined in uint8 */ -}; - -class grib_accessor_class_uint8_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_uint8_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_uint8_t() : + grib_accessor_gen_t() { class_name_ = "uint8"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_uint8_t{}; } - int get_native_type(grib_accessor*) override; - int unpack_long(grib_accessor*, long* val, size_t* len) override; + long get_native_type() override; + int unpack_long(long* val, size_t* len) override; }; diff --git a/src/accessor/grib_accessor_class_unexpanded_descriptors.cc b/src/accessor/grib_accessor_class_unexpanded_descriptors.cc index 36e7112a6..15adc675e 100644 --- a/src/accessor/grib_accessor_class_unexpanded_descriptors.cc +++ b/src/accessor/grib_accessor_class_unexpanded_descriptors.cc @@ -8,51 +8,48 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ +#include "grib_accessor_class_expanded_descriptors.h" #include "grib_accessor_class_unexpanded_descriptors.h" -grib_accessor_class_unexpanded_descriptors_t _grib_accessor_class_unexpanded_descriptors{ "unexpanded_descriptors" }; -grib_accessor_class* grib_accessor_class_unexpanded_descriptors = &_grib_accessor_class_unexpanded_descriptors; +grib_accessor_unexpanded_descriptors_t _grib_accessor_unexpanded_descriptors{}; +grib_accessor* grib_accessor_unexpanded_descriptors = &_grib_accessor_unexpanded_descriptors; - -void grib_accessor_class_unexpanded_descriptors_t::init(grib_accessor* a, const long len, grib_arguments* args) +void grib_accessor_unexpanded_descriptors_t::init(const long len, grib_arguments* args) { - grib_accessor_class_long_t::init(a, len, args); - grib_accessor_unexpanded_descriptors_t* self = (grib_accessor_unexpanded_descriptors_t*)a; + grib_accessor_long_t::init(len, args); - int n = 0; - grib_handle* hand = grib_handle_of_accessor(a); - self->unexpandedDescriptorsEncoded = grib_find_accessor(hand, grib_arguments_get_name(hand, args, n++)); - self->createNewData = grib_arguments_get_name(hand, args, n++); - a->length = 0; + int n = 0; + grib_handle* hand = grib_handle_of_accessor(this); + unexpandedDescriptorsEncoded_ = grib_find_accessor(hand, grib_arguments_get_name(hand, args, n++)); + createNewData_ = grib_arguments_get_name(hand, args, n++); + length_ = 0; } -int grib_accessor_class_unexpanded_descriptors_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_unexpanded_descriptors_t::unpack_long(long* val, size_t* len) { - grib_accessor_unexpanded_descriptors_t* self = (grib_accessor_unexpanded_descriptors_t*)a; - int ret = 0; long pos = 0; long rlen = 0; long f, x, y; long* v = val; long i; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); - pos = accessor_raw_get_offset(self->unexpandedDescriptorsEncoded) * 8; + pos = accessor_raw_get_offset(unexpandedDescriptorsEncoded_) * 8; - ret = value_count(a, &rlen); + ret = value_count(&rlen); if (ret) return ret; if (rlen == 0) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "No descriptors in section 3. Malformed message."); return GRIB_MESSAGE_MALFORMED; } if (*len < rlen) { - /* grib_context_log(a->context, GRIB_LOG_ERROR, */ - /* " wrong size (%ld) for %s it contains %d values ",*len, a->name , rlen); */ + /* grib_context_log(context_ , GRIB_LOG_ERROR, */ + /* " wrong size (%ld) for %s it contains %d values ",*len, name_ , rlen); */ *len = 0; return GRIB_ARRAY_TOO_SMALL; } @@ -67,22 +64,21 @@ int grib_accessor_class_unexpanded_descriptors_t::unpack_long(grib_accessor* a, return GRIB_SUCCESS; } -int grib_accessor_class_unexpanded_descriptors_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_unexpanded_descriptors_t::pack_long(const long* val, size_t* len) { - grib_accessor_unexpanded_descriptors_t* self = (grib_accessor_unexpanded_descriptors_t*)a; - int ret = 0; - long pos = 0; + int ret = 0; + long pos = 0; unsigned long f, x, y; unsigned char* buf = NULL; grib_accessor* expanded = NULL; size_t buflen = *len * 2; size_t i = 0, length = *len; long createNewData = 1; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); - grib_get_long(hand, self->createNewData, &createNewData); + grib_get_long(hand, createNewData_, &createNewData); - buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen); + buf = (unsigned char*)grib_context_malloc_clear(context_, buflen); for (i = 0; i < length; i++) { const long tmp = val[i] % 100000; @@ -94,7 +90,7 @@ int grib_accessor_class_unexpanded_descriptors_t::pack_long(grib_accessor* a, co grib_encode_unsigned_longb(buf, y, &pos, 8); } - self->unexpandedDescriptorsEncoded->pack_bytes(buf, &buflen); + unexpandedDescriptorsEncoded_->pack_bytes(buf, &buflen); grib_context_free(hand->context, buf); if (createNewData == 0) @@ -102,7 +98,7 @@ int grib_accessor_class_unexpanded_descriptors_t::pack_long(grib_accessor* a, co expanded = grib_find_accessor(hand, "expandedCodes"); Assert(expanded != NULL); - ret = grib_accessor_class_expanded_descriptors_set_do_expand(expanded, 1); + ret = grib_accessor_expanded_descriptors_set_do_expand(expanded, 1); if (ret != GRIB_SUCCESS) return ret; @@ -115,28 +111,27 @@ int grib_accessor_class_unexpanded_descriptors_t::pack_long(grib_accessor* a, co return ret; } -int grib_accessor_class_unexpanded_descriptors_t::value_count(grib_accessor* a, long* numberOfUnexpandedDescriptors) +int grib_accessor_unexpanded_descriptors_t::value_count(long* numberOfUnexpandedDescriptors) { - grib_accessor_unexpanded_descriptors_t* self = (grib_accessor_unexpanded_descriptors_t*)a; long n = 0; - self->unexpandedDescriptorsEncoded->value_count(&n); + unexpandedDescriptorsEncoded_->value_count(&n); *numberOfUnexpandedDescriptors = n / 2; return 0; } -long grib_accessor_class_unexpanded_descriptors_t::byte_offset(grib_accessor* a) +long grib_accessor_unexpanded_descriptors_t::byte_offset() { - return a->offset; + return offset_; } -void grib_accessor_class_unexpanded_descriptors_t::update_size(grib_accessor* a, size_t s) +void grib_accessor_unexpanded_descriptors_t::update_size(size_t s) { - a->length = s; + length_ = s; } -long grib_accessor_class_unexpanded_descriptors_t::next_offset(grib_accessor* a) +long grib_accessor_unexpanded_descriptors_t::next_offset() { - return a->byte_offset() + a->length; + return byte_offset() + length_; } diff --git a/src/accessor/grib_accessor_class_unexpanded_descriptors.h b/src/accessor/grib_accessor_class_unexpanded_descriptors.h index f9a016c1e..6aed3eb8e 100644 --- a/src/accessor/grib_accessor_class_unexpanded_descriptors.h +++ b/src/accessor/grib_accessor_class_unexpanded_descriptors.h @@ -16,21 +16,18 @@ class grib_accessor_unexpanded_descriptors_t : public grib_accessor_long_t { public: - /* Members defined in unexpanded_descriptors */ - grib_accessor* unexpandedDescriptorsEncoded; - const char* createNewData; -}; - -class grib_accessor_class_unexpanded_descriptors_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_unexpanded_descriptors_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_unexpanded_descriptors_t() : + grib_accessor_long_t() { class_name_ = "unexpanded_descriptors"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_unexpanded_descriptors_t{}; } - int pack_long(grib_accessor*, const long* val, size_t* len) override; - int unpack_long(grib_accessor*, long* val, size_t* len) override; - long byte_offset(grib_accessor*) override; - long next_offset(grib_accessor*) override; - int value_count(grib_accessor*, long*) override; - void init(grib_accessor*, const long, grib_arguments*) override; - void update_size(grib_accessor*, size_t) override; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + long byte_offset() override; + long next_offset() override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + void update_size(size_t) override; + +private: + grib_accessor* unexpandedDescriptorsEncoded_; + const char* createNewData_; }; diff --git a/src/accessor/grib_accessor_class_unpack_bufr_values.cc b/src/accessor/grib_accessor_class_unpack_bufr_values.cc index 9f6495989..0b90ede64 100644 --- a/src/accessor/grib_accessor_class_unpack_bufr_values.cc +++ b/src/accessor/grib_accessor_class_unpack_bufr_values.cc @@ -11,70 +11,63 @@ #include "grib_accessor_class_unpack_bufr_values.h" #include "grib_accessor_class_bufr_data_array.h" -grib_accessor_class_unpack_bufr_values_t _grib_accessor_class_unpack_bufr_values{ "unpack_bufr_values" }; -grib_accessor_class* grib_accessor_class_unpack_bufr_values = &_grib_accessor_class_unpack_bufr_values; +grib_accessor_unpack_bufr_values_t _grib_accessor_unpack_bufr_values{}; +grib_accessor* grib_accessor_unpack_bufr_values = &_grib_accessor_unpack_bufr_values; -void grib_accessor_class_unpack_bufr_values_t::init(grib_accessor* a, const long len, grib_arguments* params) +void grib_accessor_unpack_bufr_values_t::init(const long len, grib_arguments* params) { - grib_accessor_class_gen_t::init(a, len, params); + grib_accessor_gen_t::init(len, params); char* key; - grib_accessor_unpack_bufr_values_t* self = (grib_accessor_unpack_bufr_values_t*)a; - key = (char*)grib_arguments_get_name(grib_handle_of_accessor(a), params, 0); - self->data_accessor = grib_find_accessor(grib_handle_of_accessor(a), key); + key = (char*)grib_arguments_get_name(grib_handle_of_accessor(this), params, 0); + data_accessor_ = grib_find_accessor(grib_handle_of_accessor(this), key); - a->length = 0; + length_ = 0; } -void grib_accessor_class_unpack_bufr_values_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_unpack_bufr_values_t::dump(grib_dumper* dumper) { } -int grib_accessor_class_unpack_bufr_values_t::unpack_string_array(grib_accessor* a, char** buffer, size_t* len) +int grib_accessor_unpack_bufr_values_t::unpack_string_array(char** buffer, size_t* len) { - grib_accessor_unpack_bufr_values_t* self = (grib_accessor_unpack_bufr_values_t*)a; - grib_accessor* data = (grib_accessor*)self->data_accessor; - + grib_accessor* data = (grib_accessor*)data_accessor_; return data->unpack_double(0, 0); } -int grib_accessor_class_unpack_bufr_values_t::unpack_string(grib_accessor* a, char* buffer, size_t* len) +int grib_accessor_unpack_bufr_values_t::unpack_string(char* buffer, size_t* len) { - grib_accessor_unpack_bufr_values_t* self = (grib_accessor_unpack_bufr_values_t*)a; - grib_accessor* data = (grib_accessor*)self->data_accessor; + grib_accessor* data = (grib_accessor*)data_accessor_; strcpy(buffer, "0"); *len = 1; return data->unpack_double(0, 0); } -int grib_accessor_class_unpack_bufr_values_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_unpack_bufr_values_t::unpack_long(long* val, size_t* len) { - grib_accessor_unpack_bufr_values_t* self = (grib_accessor_unpack_bufr_values_t*)a; - grib_accessor* data = (grib_accessor*)self->data_accessor; + grib_accessor* data = (grib_accessor*)data_accessor_; + return data->unpack_double(0, 0); +} + +int grib_accessor_unpack_bufr_values_t::unpack_double(double* val, size_t* len) +{ + grib_accessor* data = (grib_accessor*)data_accessor_; return data->unpack_double(0, 0); } -int grib_accessor_class_unpack_bufr_values_t::unpack_double(grib_accessor* a, double* val, size_t* len) -{ - grib_accessor_unpack_bufr_values_t* self = (grib_accessor_unpack_bufr_values_t*)a; - grib_accessor* data = (grib_accessor*)self->data_accessor; - - return data->unpack_double(0, 0); -} - -int grib_accessor_class_unpack_bufr_values_t::value_count(grib_accessor* a, long* count) +int grib_accessor_unpack_bufr_values_t::value_count(long* count) { *count = 1; return 0; } -void grib_accessor_class_unpack_bufr_values_t::destroy(grib_context* context, grib_accessor* a) +void grib_accessor_unpack_bufr_values_t::destroy(grib_context* context) { - grib_accessor_class_gen_t::destroy(context, a); + grib_accessor_gen_t::destroy(context); } -int grib_accessor_class_unpack_bufr_values_t::get_native_type(grib_accessor* a) +long grib_accessor_unpack_bufr_values_t::get_native_type() { return GRIB_TYPE_LONG; } @@ -87,26 +80,21 @@ int grib_accessor_class_unpack_bufr_values_t::get_native_type(grib_accessor* a) // return "unknown proc flag"; // } -int grib_accessor_class_unpack_bufr_values_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_unpack_bufr_values_t::pack_long(const long* val, size_t* len) { int unpackMode = CODES_BUFR_UNPACK_STRUCTURE; - grib_accessor_unpack_bufr_values_t* self = (grib_accessor_unpack_bufr_values_t*)a; - grib_accessor* data = (grib_accessor*)self->data_accessor; if (*val == 2) unpackMode = CODES_BUFR_UNPACK_FLAT; if (*val == 3) unpackMode = CODES_BUFR_NEW_DATA; - accessor_bufr_data_array_set_unpackMode(data, unpackMode); + accessor_bufr_data_array_set_unpackMode(data_accessor_, unpackMode); - return data->unpack_double(0, 0); + return data_accessor_->unpack_double(0, 0); } -int grib_accessor_class_unpack_bufr_values_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_unpack_bufr_values_t::pack_double(const double* val, size_t* len) { - grib_accessor_unpack_bufr_values_t* self = (grib_accessor_unpack_bufr_values_t*)a; - grib_accessor* data = (grib_accessor*)self->data_accessor; - - return data->unpack_double(0, 0); + return data_accessor_->unpack_double(0, 0); } diff --git a/src/accessor/grib_accessor_class_unpack_bufr_values.h b/src/accessor/grib_accessor_class_unpack_bufr_values.h index 46dd91ec5..2d0425af1 100644 --- a/src/accessor/grib_accessor_class_unpack_bufr_values.h +++ b/src/accessor/grib_accessor_class_unpack_bufr_values.h @@ -16,24 +16,21 @@ class grib_accessor_unpack_bufr_values_t : public grib_accessor_gen_t { public: - /* Members defined in unpack_bufr_values */ - grib_accessor* data_accessor; -}; - -class grib_accessor_class_unpack_bufr_values_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_unpack_bufr_values_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_unpack_bufr_values_t() : + grib_accessor_gen_t() { class_name_ = "unpack_bufr_values"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_unpack_bufr_values_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; - 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; + long get_native_type() override; + int pack_double(const double* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + int unpack_string_array(char**, size_t* len) override; + int value_count(long*) override; + void destroy(grib_context*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + +private: + grib_accessor* data_accessor_; }; diff --git a/src/accessor/grib_accessor_class_unsigned.cc b/src/accessor/grib_accessor_class_unsigned.cc index 14ca831a3..c56047f60 100644 --- a/src/accessor/grib_accessor_class_unsigned.cc +++ b/src/accessor/grib_accessor_class_unsigned.cc @@ -10,41 +10,39 @@ #include "grib_accessor_class_unsigned.h" -grib_accessor_class_unsigned_t _grib_accessor_class_unsigned("unsigned"); -grib_accessor_class* grib_accessor_class_unsigned = &_grib_accessor_class_unsigned; +grib_accessor_unsigned_t _grib_accessor_unsigned{}; +grib_accessor* grib_accessor_unsigned = &_grib_accessor_unsigned; - -void grib_accessor_class_unsigned_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_unsigned_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_long_t::init(a, len, arg); - grib_accessor_unsigned_t* self = (grib_accessor_unsigned_t*)a; - self->arg = arg; - self->nbytes = len; + grib_accessor_long_t::init(len, arg); + nbytes_ = len; + arg_ = arg; - if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) { - a->length = 0; - if (!a->vvalue) - a->vvalue = (grib_virtual_value*)grib_context_malloc_clear(a->context, sizeof(grib_virtual_value)); - a->vvalue->type = GRIB_TYPE_LONG; - a->vvalue->length = len; + if (flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) { + length_ = 0; + if (!vvalue_) + vvalue_ = (grib_virtual_value*)grib_context_malloc_clear(context_, sizeof(grib_virtual_value)); + vvalue_->type = GRIB_TYPE_LONG; + vvalue_->length = len; } else { long count = 0; - a->value_count(&count); + value_count(&count); - a->length = len * count; - a->vvalue = NULL; + length_ = len * count; + vvalue_ = NULL; } } -void grib_accessor_class_unsigned_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_unsigned_t::dump(grib_dumper* dumper) { long rlen = 0; - a->value_count(&rlen); + value_count(&rlen); if (rlen == 1) - grib_dump_long(dumper, a, NULL); + grib_dump_long(dumper, this, NULL); else - grib_dump_values(dumper, a); + grib_dump_values(dumper, this); } static const unsigned long ones[] = { @@ -80,24 +78,24 @@ int pack_long_unsigned_helper(grib_accessor* a, const long* val, size_t* len, in if (err) return err; - if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { - Assert(self->nbytes <= 4); - missing = ones[self->nbytes]; + if (a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { + Assert(self->nbytes_ <= 4); + missing = ones[self->nbytes_]; } - if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) { - a->vvalue->lval = val[0]; + if (self->flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) { + self->vvalue_->lval = val[0]; if (missing && val[0] == GRIB_MISSING_LONG) - a->vvalue->missing = 1; + self->vvalue_->missing = 1; else - a->vvalue->missing = 0; + self->vvalue_->missing = 0; return GRIB_SUCCESS; } if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1); + grib_context_log(a->context_, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name_, 1); len[0] = 0; return GRIB_ARRAY_TOO_SMALL; } @@ -112,90 +110,88 @@ int pack_long_unsigned_helper(grib_accessor* a, const long* val, size_t* len, in /* Check if value fits into number of bits */ if (check) { if (val[0] < 0) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Key \"%s\": Trying to encode a negative value of %ld for key of type unsigned", a->name, val[0]); + grib_context_log(a->context_, GRIB_LOG_ERROR, + "Key \"%s\": Trying to encode a negative value of %ld for key of type unsigned", a->name_, val[0]); return GRIB_ENCODING_ERROR; } /* See GRIB-23 and GRIB-262 */ if (!value_is_missing(v)) { - const long nbits = self->nbytes * 8; + const long nbits = self->nbytes_ * 8; if (nbits < 33) { unsigned long maxval = (1UL << nbits) - 1; if (maxval > 0 && v > maxval) { /* See ECC-1002 */ - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(a->context_, GRIB_LOG_ERROR, "Key \"%s\": Trying to encode value of %ld but the maximum allowable value is %lu (number of bits=%ld)", - a->name, v, maxval, nbits); + a->name_, v, maxval, nbits); return GRIB_ENCODING_ERROR; } } } } - off = a->offset * 8; - ret = grib_encode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, v, &off, self->nbytes * 8); + off = a->offset_ * 8; + ret = grib_encode_unsigned_long(grib_handle_of_accessor(a)->buffer->data, v, &off, self->nbytes_ * 8); if (ret == GRIB_SUCCESS) len[0] = 1; if (*len > 1) - grib_context_log(a->context, GRIB_LOG_WARNING, "grib_accessor_unsigned : Trying to pack %d values in a scalar %s, packing first value", *len, a->name); + grib_context_log(a->context_, GRIB_LOG_WARNING, "grib_accessor_unsigned : Trying to pack %d values in a scalar %s, packing first value", *len, a->name_); len[0] = 1; return ret; } /* TODO: We assume that there are no missing values if there are more that 1 value */ - buflen = *len * self->nbytes; + buflen = *len * self->nbytes_; - buf = (unsigned char*)grib_context_malloc(a->context, buflen); + buf = (unsigned char*)grib_context_malloc(a->context_, buflen); for (i = 0; i < *len; i++) - grib_encode_unsigned_long(buf, val[i], &off, self->nbytes * 8); + grib_encode_unsigned_long(buf, val[i], &off, self->nbytes_ * 8); - ret = grib_set_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), *len); + ret = grib_set_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent_->h, self->arg_, 0), *len); if (ret == GRIB_SUCCESS) grib_buffer_replace(a, buf, buflen, 1, 1); else *len = 0; - grib_context_free(a->context, buf); + grib_context_free(a->context_, buf); return ret; } -int grib_accessor_class_unsigned_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_unsigned_t::unpack_long(long* val, size_t* len) { - grib_accessor_unsigned_t* self = (grib_accessor_unsigned_t*)a; - long rlen = 0; unsigned long i = 0; unsigned long missing = 0; long count = 0; int err = 0; - long pos = a->offset * 8; - grib_handle* hand = grib_handle_of_accessor(a); + long pos = offset_ * 8; + grib_handle* hand = grib_handle_of_accessor(this); - err = a->value_count(&count); + err = value_count(&count); if (err) return err; rlen = count; if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size (%ld) for %s, it contains %ld values", *len, a->name, rlen); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size (%ld) for %s, it contains %ld values", *len, name_, rlen); *len = 0; return GRIB_ARRAY_TOO_SMALL; } - if (a->flags & GRIB_ACCESSOR_FLAG_TRANSIENT) { - *val = a->vvalue->lval; + if (flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) { + *val = vvalue_->lval; *len = 1; return GRIB_SUCCESS; } - if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { - Assert(self->nbytes <= 4); - missing = ones[self->nbytes]; + if (flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { + Assert(nbytes_ <= 4); + missing = ones[nbytes_]; } for (i = 0; i < rlen; i++) { - val[i] = (long)grib_decode_unsigned_long(hand->buffer->data, &pos, self->nbytes * 8); + val[i] = (long)grib_decode_unsigned_long(hand->buffer->data, &pos, nbytes_ * 8); if (missing) if (val[i] == missing) val[i] = GRIB_MISSING_LONG; @@ -205,54 +201,53 @@ int grib_accessor_class_unsigned_t::unpack_long(grib_accessor* a, long* val, siz return GRIB_SUCCESS; } -int grib_accessor_class_unsigned_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_unsigned_t::pack_long(const long* val, size_t* len) { /* See GRIB-262 as example of why we do the checks */ - return pack_long_unsigned_helper(a, val, len, /*check=*/1); + return pack_long_unsigned_helper(this, val, len, /*check=*/1); } -long grib_accessor_class_unsigned_t::byte_count(grib_accessor* a) +long grib_accessor_unsigned_t::byte_count() { - return a->length; + return length_; } -int grib_accessor_class_unsigned_t::value_count(grib_accessor* a, long* len) +int grib_accessor_unsigned_t::value_count(long* len) { - grib_accessor_unsigned_t* self = (grib_accessor_unsigned_t*)a; - if (!self->arg) { + if (!arg_) { *len = 1; return 0; } - return grib_get_long_internal(grib_handle_of_accessor(a), grib_arguments_get_name(a->parent->h, self->arg, 0), len); + return grib_get_long_internal(grib_handle_of_accessor(this), grib_arguments_get_name(parent_->h, arg_, 0), len); } -long grib_accessor_class_unsigned_t::byte_offset(grib_accessor* a) +long grib_accessor_unsigned_t::byte_offset() { - return a->offset; + return offset_; } -void grib_accessor_class_unsigned_t::update_size(grib_accessor* a, size_t s) +void grib_accessor_unsigned_t::update_size(size_t s) { - a->length = s; + length_ = s; } -long grib_accessor_class_unsigned_t::next_offset(grib_accessor* a) +long grib_accessor_unsigned_t::next_offset() { - return a->byte_offset() + a->byte_count(); + return byte_offset() + byte_count(); } -int grib_accessor_class_unsigned_t::is_missing(grib_accessor* a) +int grib_accessor_unsigned_t::is_missing() { - const unsigned char ff = 0xff; - unsigned long offset = a->offset; - grib_handle* hand = grib_handle_of_accessor(a); + unsigned char ff = 0xff; + unsigned long offset = offset_; + grib_handle* hand = grib_handle_of_accessor(this); - if (a->length == 0) { - Assert(a->vvalue != NULL); - return a->vvalue->missing; + if (length_ == 0) { + Assert(vvalue_ != NULL); + return vvalue_->missing; } - for (long i = 0; i < a->length; i++) { + for (long i = 0; i < length_; i++) { if (hand->buffer->data[offset] != ff) { return 0; } @@ -261,10 +256,11 @@ int grib_accessor_class_unsigned_t::is_missing(grib_accessor* a) return 1; } -void grib_accessor_class_unsigned_t::destroy(grib_context* context, grib_accessor* a) +void grib_accessor_unsigned_t::destroy(grib_context* context) { - grib_context_free(context, a->vvalue); - a->vvalue = NULL; + if (vvalue_ != NULL) + grib_context_free(context, vvalue_); - grib_accessor_class_long_t::destroy(context, a); + vvalue_ = NULL; + grib_accessor_long_t::destroy(context); } diff --git a/src/accessor/grib_accessor_class_unsigned.h b/src/accessor/grib_accessor_class_unsigned.h index 50f3cfb16..9afcbdf56 100644 --- a/src/accessor/grib_accessor_class_unsigned.h +++ b/src/accessor/grib_accessor_class_unsigned.h @@ -15,25 +15,23 @@ class grib_accessor_unsigned_t : public grib_accessor_long_t { public: - long nbytes; - grib_arguments* arg; -}; - - -class grib_accessor_class_unsigned_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_unsigned_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_unsigned_t() : + grib_accessor_long_t() { class_name_ = "None"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_unsigned_t{}; } - void init(grib_accessor* a, const long len, grib_arguments* arg) override; - void dump(grib_accessor* a, grib_dumper* dumper) override; - int unpack_long(grib_accessor* a, long* val, size_t* len) override; - int pack_long(grib_accessor* a, const long* val, size_t* len) override; - long byte_count(grib_accessor* a) override; - int value_count(grib_accessor* a, long* len) override; - long byte_offset(grib_accessor* a) override; - void update_size(grib_accessor* a, size_t s) override; - long next_offset(grib_accessor* a) override; - int is_missing(grib_accessor* a) override; - void destroy(grib_context* context, grib_accessor* a) override; + void init(const long len, grib_arguments* arg) override; + void dump(grib_dumper* dumper) override; + int unpack_long(long* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + long byte_count() override; + int value_count(long* len) override; + long byte_offset() override; + void update_size(size_t s) override; + long next_offset() override; + int is_missing() override; + void destroy(grib_context* context) override; + + // TODO(maee): make members private +public: + long nbytes_; + grib_arguments* arg_; }; diff --git a/src/accessor/grib_accessor_class_unsigned_bits.cc b/src/accessor/grib_accessor_class_unsigned_bits.cc index 4e6f058fe..edaa9bbe1 100644 --- a/src/accessor/grib_accessor_class_unsigned_bits.cc +++ b/src/accessor/grib_accessor_class_unsigned_bits.cc @@ -10,9 +10,8 @@ #include "grib_accessor_class_unsigned_bits.h" -grib_accessor_class_unsigned_bits_t _grib_accessor_class_unsigned_bits{ "unsigned_bits" }; -grib_accessor_class* grib_accessor_class_unsigned_bits = &_grib_accessor_class_unsigned_bits; - +grib_accessor_unsigned_bits_t _grib_accessor_unsigned_bits{}; +grib_accessor* grib_accessor_unsigned_bits = &_grib_accessor_unsigned_bits; static long compute_byte_count(grib_accessor* a) { @@ -21,54 +20,51 @@ static long compute_byte_count(grib_accessor* a) long numberOfElements; int ret = 0; - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits_, &numberOfBits); if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name, self->numberOfBits); + grib_context_log(a->context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", a->name_, self->numberOfBits_); return 0; } - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, &numberOfElements); + ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements_, &numberOfElements); if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name, self->numberOfElements); + grib_context_log(a->context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", a->name_, self->numberOfElements_); return 0; } return (numberOfBits * numberOfElements + 7) / 8; } -void grib_accessor_class_unsigned_bits_t::init(grib_accessor* a, const long len, grib_arguments* args) +void grib_accessor_unsigned_bits_t::init(const long len, grib_arguments* args) { - grib_accessor_class_long_t::init(a, len, args); - grib_accessor_unsigned_bits_t* self = (grib_accessor_unsigned_bits_t*)a; - - int n = 0; - self->numberOfBits = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - self->numberOfElements = grib_arguments_get_name(grib_handle_of_accessor(a), args, n++); - a->length = compute_byte_count(a); + grib_accessor_long_t::init(len, args); + int n = 0; + numberOfBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + numberOfElements_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); + length_ = compute_byte_count(this); } -int grib_accessor_class_unsigned_bits_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_unsigned_bits_t::unpack_long(long* val, size_t* len) { - grib_accessor_unsigned_bits_t* self = (grib_accessor_unsigned_bits_t*)a; - - long pos = a->offset * 8; + int ret = 0; + long pos = offset_ * 8; long rlen = 0; long numberOfBits = 0; - int ret = value_count(a, &rlen); + ret = value_count(&rlen); if (ret) return ret; if (*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Wrong size (%ld) for %s, it contains %ld values", *len, a->name, rlen); + grib_context_log(context_, GRIB_LOG_ERROR, + "Wrong size (%ld) for %s, it contains %ld values", *len, name_, rlen); *len = rlen; return GRIB_ARRAY_TOO_SMALL; } - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfBits_, &numberOfBits); if (ret) return ret; if (numberOfBits == 0) { @@ -78,89 +74,87 @@ int grib_accessor_class_unsigned_bits_t::unpack_long(grib_accessor* a, long* val return GRIB_SUCCESS; } - grib_decode_long_array(grib_handle_of_accessor(a)->buffer->data, &pos, numberOfBits, rlen, val); + grib_decode_long_array(grib_handle_of_accessor(this)->buffer->data, &pos, numberOfBits, rlen, val); *len = rlen; return GRIB_SUCCESS; } -int grib_accessor_class_unsigned_bits_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_unsigned_bits_t::pack_long(const long* val, size_t* len) { - grib_accessor_unsigned_bits_t* self = (grib_accessor_unsigned_bits_t*)a; - + int ret = 0; long off = 0; long numberOfBits = 0; size_t buflen = 0; unsigned char* buf = NULL; unsigned long i = 0; long rlen = 0; - int ret = value_count(a, &rlen); + ret = value_count(&rlen); if (ret) return ret; /* if(*len < rlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "Wrong size for %s it contains %d values ", a->name , rlen ); + grib_context_log(context_ , GRIB_LOG_ERROR, + "Wrong size for %s it contains %d values ", name_ , rlen ); return GRIB_ARRAY_TOO_SMALL; } */ if (*len != rlen) - ret = grib_set_long(grib_handle_of_accessor(a), self->numberOfElements, *len); + ret = grib_set_long(grib_handle_of_accessor(this), numberOfElements_, *len); if (ret) return ret; - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits, &numberOfBits); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfBits_, &numberOfBits); if (ret) return ret; if (numberOfBits == 0) { - grib_buffer_replace(a, NULL, 0, 1, 1); + grib_buffer_replace(this, NULL, 0, 1, 1); return GRIB_SUCCESS; } - buflen = compute_byte_count(a); - buf = (unsigned char*)grib_context_malloc_clear(a->context, buflen + sizeof(long)); + buflen = compute_byte_count(this); + buf = (unsigned char*)grib_context_malloc_clear(context_, buflen + sizeof(long)); for (i = 0; i < *len; i++) grib_encode_unsigned_longb(buf, val[i], &off, numberOfBits); - grib_buffer_replace(a, buf, buflen, 1, 1); + grib_buffer_replace(this, buf, buflen, 1, 1); - grib_context_free(a->context, buf); + grib_context_free(context_, buf); return ret; } -long grib_accessor_class_unsigned_bits_t::byte_count(grib_accessor* a) +long grib_accessor_unsigned_bits_t::byte_count() { - return a->length; + return length_; } -int grib_accessor_class_unsigned_bits_t::value_count(grib_accessor* a, long* numberOfElements) +int grib_accessor_unsigned_bits_t::value_count(long* numberOfElements) { - grib_accessor_unsigned_bits_t* self = (grib_accessor_unsigned_bits_t*)a; int ret; *numberOfElements = 0; - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements, numberOfElements); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfElements_, numberOfElements); if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name, self->numberOfElements); + grib_context_log(context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", name_, numberOfElements_); } return ret; } -long grib_accessor_class_unsigned_bits_t::byte_offset(grib_accessor* a) +long grib_accessor_unsigned_bits_t::byte_offset() { - return a->offset; + return offset_; } -void grib_accessor_class_unsigned_bits_t::update_size(grib_accessor* a, size_t s) +void grib_accessor_unsigned_bits_t::update_size(size_t s) { - a->length = s; + length_ = s; } -long grib_accessor_class_unsigned_bits_t::next_offset(grib_accessor* a) +long grib_accessor_unsigned_bits_t::next_offset() { - return a->byte_offset() + a->length; + return byte_offset() + length_; } diff --git a/src/accessor/grib_accessor_class_unsigned_bits.h b/src/accessor/grib_accessor_class_unsigned_bits.h index 52528ab83..66512187f 100644 --- a/src/accessor/grib_accessor_class_unsigned_bits.h +++ b/src/accessor/grib_accessor_class_unsigned_bits.h @@ -16,22 +16,19 @@ class grib_accessor_unsigned_bits_t : public grib_accessor_long_t { public: - /* Members defined in unsigned_bits */ - const char* numberOfBits; - const char* numberOfElements; -}; - -class grib_accessor_class_unsigned_bits_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_unsigned_bits_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_unsigned_bits_t() : + grib_accessor_long_t() { class_name_ = "unsigned_bits"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_unsigned_bits_t{}; } - int pack_long(grib_accessor*, const long* val, size_t* len) override; - int unpack_long(grib_accessor*, long* 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 init(grib_accessor*, const long, grib_arguments*) override; - void update_size(grib_accessor*, size_t) override; + int pack_long(const long* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + long byte_count() override; + long byte_offset() override; + long next_offset() override; + int value_count(long*) override; + void init(const long, grib_arguments*) override; + void update_size(size_t) override; + +public: + const char* numberOfBits_; + const char* numberOfElements_; }; diff --git a/src/accessor/grib_accessor_class_validity_date.cc b/src/accessor/grib_accessor_class_validity_date.cc index 99e0eb47a..c9b89d42b 100644 --- a/src/accessor/grib_accessor_class_validity_date.cc +++ b/src/accessor/grib_accessor_class_validity_date.cc @@ -10,61 +10,59 @@ #include "grib_accessor_class_validity_date.h" -grib_accessor_class_validity_date_t _grib_accessor_class_validity_date{ "validity_date" }; -grib_accessor_class* grib_accessor_class_validity_date = &_grib_accessor_class_validity_date; +grib_accessor_validity_date_t _grib_accessor_validity_date{}; +grib_accessor* grib_accessor_validity_date = &_grib_accessor_validity_date; -void grib_accessor_class_validity_date_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_validity_date_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_validity_date_t* self = (grib_accessor_validity_date_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int n = 0; + grib_accessor_long_t::init(l, c); + grib_handle* hand = grib_handle_of_accessor(this); + int n = 0; - self->date = grib_arguments_get_name(hand, c, n++); - self->time = grib_arguments_get_name(hand, c, n++); - self->step = grib_arguments_get_name(hand, c, n++); - self->stepUnits = grib_arguments_get_name(hand, c, n++); - self->year = grib_arguments_get_name(hand, c, n++); - self->month = grib_arguments_get_name(hand, c, n++); - self->day = grib_arguments_get_name(hand, c, n++); + date_ = grib_arguments_get_name(hand, c, n++); + time_ = grib_arguments_get_name(hand, c, n++); + step_ = grib_arguments_get_name(hand, c, n++); + stepUnits_ = grib_arguments_get_name(hand, c, n++); + year_ = grib_arguments_get_name(hand, c, n++); + month_ = grib_arguments_get_name(hand, c, n++); + day_ = grib_arguments_get_name(hand, c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_validity_date_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_validity_date_t::unpack_long(long* val, size_t* len) { - grib_accessor_validity_date_t* self = (grib_accessor_validity_date_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int ret = 0; - long date = 0; - long time = 0; - long step = 0; - long stepUnits = 0; + grib_handle* hand = grib_handle_of_accessor(this); + int ret = 0; + long date = 0; + long time = 0; + long step = 0; + long stepUnits = 0; long hours = 0, minutes = 0, step_mins = 0, tmp, tmp_hrs; - if (self->year) { + if (year_) { long year, month, day; - if ((ret = grib_get_long_internal(hand, self->year, &year)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, year_, &year)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->month, &month)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, month_, &month)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->day, &day)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, day_, &day)) != GRIB_SUCCESS) return ret; *val = year * 10000 + month * 100 + day; return GRIB_SUCCESS; } - if ((ret = grib_get_long_internal(hand, self->date, &date)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, date_, &date)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->time, &time)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, time_, &time)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long(hand, self->step, &step)) != GRIB_SUCCESS) { + if ((ret = grib_get_long(hand, step_, &step)) != GRIB_SUCCESS) { if ((ret = grib_get_long_internal(hand, "endStep", &step)) != GRIB_SUCCESS) { return ret; /* See ECC-817 */ } } - if (self->stepUnits) { - if ((ret = grib_get_long_internal(hand, self->stepUnits, &stepUnits)) != GRIB_SUCCESS) + if (stepUnits_) { + if ((ret = grib_get_long_internal(hand, stepUnits_, &stepUnits)) != GRIB_SUCCESS) return ret; step_mins = convert_to_minutes(step, stepUnits); } diff --git a/src/accessor/grib_accessor_class_validity_date.h b/src/accessor/grib_accessor_class_validity_date.h index ca87b3282..1a95d78fd 100644 --- a/src/accessor/grib_accessor_class_validity_date.h +++ b/src/accessor/grib_accessor_class_validity_date.h @@ -16,21 +16,18 @@ class grib_accessor_validity_date_t : public grib_accessor_long_t { public: - /* Members defined in validity_date */ - const char* date; - const char* time; - const char* step; - const char* stepUnits; - const char* year; - const char* month; - const char* day; -}; - -class grib_accessor_class_validity_date_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_validity_date_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_validity_date_t() : + grib_accessor_long_t() { class_name_ = "validity_date"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_validity_date_t{}; } - int unpack_long(grib_accessor*, long* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_long(long* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* date_; + const char* time_; + const char* step_; + const char* stepUnits_; + const char* year_; + const char* month_; + const char* day_; }; diff --git a/src/accessor/grib_accessor_class_validity_time.cc b/src/accessor/grib_accessor_class_validity_time.cc index 6f692e154..2e2ead2ab 100644 --- a/src/accessor/grib_accessor_class_validity_time.cc +++ b/src/accessor/grib_accessor_class_validity_time.cc @@ -10,59 +10,56 @@ #include "grib_accessor_class_validity_time.h" -grib_accessor_class_validity_time_t _grib_accessor_class_validity_time{ "validity_time" }; -grib_accessor_class* grib_accessor_class_validity_time = &_grib_accessor_class_validity_time; +grib_accessor_validity_time_t _grib_accessor_validity_time{}; +grib_accessor* grib_accessor_validity_time = &_grib_accessor_validity_time; - -void grib_accessor_class_validity_time_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_validity_time_t::init(const long l, grib_arguments* c) { - grib_accessor_class_long_t::init(a, l, c); - grib_accessor_validity_time_t* self = (grib_accessor_validity_time_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); + grib_accessor_long_t::init(l, c); + grib_handle* hand = grib_handle_of_accessor(this); + int n = 0; - int n = 0; - self->date = grib_arguments_get_name(hand, c, n++); - self->time = grib_arguments_get_name(hand, c, n++); - self->step = grib_arguments_get_name(hand, c, n++); - self->stepUnits = grib_arguments_get_name(hand, c, n++); - self->hours = grib_arguments_get_name(hand, c, n++); - self->minutes = grib_arguments_get_name(hand, c, n++); + date_ = grib_arguments_get_name(hand, c, n++); + time_ = grib_arguments_get_name(hand, c, n++); + step_ = grib_arguments_get_name(hand, c, n++); + stepUnits_ = grib_arguments_get_name(hand, c, n++); + hours_ = grib_arguments_get_name(hand, c, n++); + minutes_ = grib_arguments_get_name(hand, c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -int grib_accessor_class_validity_time_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_validity_time_t::unpack_long(long* val, size_t* len) { - grib_accessor_validity_time_t* self = (grib_accessor_validity_time_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - int ret = 0; - long date = 0; - long time = 0; - long step = 0; - long stepUnits = 0; + grib_handle* hand = grib_handle_of_accessor(this); + int ret = 0; + long date = 0; + long time = 0; + long step = 0; + long stepUnits = 0; long hours = 0, minutes = 0, step_mins = 0, tmp, tmp_hrs, tmp_mins; - if (self->hours) { - if ((ret = grib_get_long_internal(hand, self->hours, &hours)) != GRIB_SUCCESS) + if (hours_) { + if ((ret = grib_get_long_internal(hand, hours_, &hours)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->minutes, &minutes)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, minutes_, &minutes)) != GRIB_SUCCESS) return ret; *val = hours * 100 + minutes; return GRIB_SUCCESS; } - if ((ret = grib_get_long_internal(hand, self->date, &date)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, date_, &date)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(hand, self->time, &time)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(hand, time_, &time)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long(hand, self->step, &step)) != GRIB_SUCCESS) { + if ((ret = grib_get_long(hand, step_, &step)) != GRIB_SUCCESS) { if ((ret = grib_get_long_internal(hand, "endStep", &step)) != GRIB_SUCCESS) { return ret; /* See ECC-817 */ } } /* Seconds will always be zero. So convert to minutes */ - if (self->stepUnits) { - if ((ret = grib_get_long_internal(hand, self->stepUnits, &stepUnits)) != GRIB_SUCCESS) + if (stepUnits_) { + if ((ret = grib_get_long_internal(hand, stepUnits_, &stepUnits)) != GRIB_SUCCESS) return ret; step_mins = convert_to_minutes(step, stepUnits); } @@ -92,20 +89,20 @@ int grib_accessor_class_validity_time_t::unpack_long(grib_accessor* a, long* val return GRIB_SUCCESS; } -int grib_accessor_class_validity_time_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_validity_time_t::unpack_string(char* val, size_t* len) { int err = 0; long v = 0; size_t lsize = 1, lmin = 5; - err = unpack_long(a, &v, &lsize); + err = unpack_long(&v, &lsize); if (err) return err; if (*len < lmin) { - const char* cclass_name = a->cclass->name; - grib_context_log(a->context, GRIB_LOG_ERROR, + const char* cclass_name = class_name_; + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - cclass_name, a->name, lmin, *len); + cclass_name, name_, lmin, *len); *len = lmin; return GRIB_BUFFER_TOO_SMALL; } diff --git a/src/accessor/grib_accessor_class_validity_time.h b/src/accessor/grib_accessor_class_validity_time.h index 023c3e30a..f3e8cb608 100644 --- a/src/accessor/grib_accessor_class_validity_time.h +++ b/src/accessor/grib_accessor_class_validity_time.h @@ -16,21 +16,18 @@ class grib_accessor_validity_time_t : public grib_accessor_long_t { public: - /* Members defined in validity_time */ - const char* date; - const char* time; - const char* step; - const char* stepUnits; - const char* hours; - const char* minutes; -}; - -class grib_accessor_class_validity_time_t : public grib_accessor_class_long_t -{ -public: - grib_accessor_class_validity_time_t(const char* name) : grib_accessor_class_long_t(name) {} + grib_accessor_validity_time_t() : + grib_accessor_long_t() { class_name_ = "validity_time"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_validity_time_t{}; } - int unpack_long(grib_accessor*, long* val, size_t* len) override; - int unpack_string(grib_accessor*, char*, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* date_; + const char* time_; + const char* step_; + const char* stepUnits_; + const char* hours_; + const char* minutes_; }; diff --git a/src/accessor/grib_accessor_class_values.cc b/src/accessor/grib_accessor_class_values.cc index c8afd7787..489c7a4dd 100644 --- a/src/accessor/grib_accessor_class_values.cc +++ b/src/accessor/grib_accessor_class_values.cc @@ -10,19 +10,19 @@ #include "grib_accessor_class_values.h" -grib_accessor_class_values_t _grib_accessor_class_values{"values"}; -grib_accessor_class* grib_accessor_class_values = &_grib_accessor_class_values; +grib_accessor_values_t _grib_accessor_values{}; +grib_accessor* grib_accessor_values = &_grib_accessor_values; long init_length(grib_accessor* a) { grib_accessor_values_t* self = (grib_accessor_values_t*)a; - int ret = 0; + int ret = 0; long seclen = 0; long offsetsection = 0; long offsetdata = 0; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->seclen, &seclen))) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->seclen_, &seclen))) return ret; if (seclen == 0) { @@ -30,10 +30,10 @@ long init_length(grib_accessor* a) return 0; } - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetsection, &offsetsection))) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetsection_, &offsetsection))) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetdata, &offsetdata))) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->offsetdata_, &offsetdata))) return ret; /* When reparsing */ @@ -46,55 +46,54 @@ long init_length(grib_accessor* a) return seclen - (offsetdata - offsetsection); } -void grib_accessor_class_values_t::init(grib_accessor* a, const long v, grib_arguments* params) +void grib_accessor_values_t::init(const long v, grib_arguments* params) { - grib_accessor_class_gen_t::init(a, v, params); - grib_accessor_values_t* self = (grib_accessor_values_t*)a; - self->carg = 0; + grib_accessor_gen_t::init(v, params); + carg_ = 0; - self->seclen = grib_arguments_get_name(grib_handle_of_accessor(a), params, self->carg++); - self->offsetdata = grib_arguments_get_name(grib_handle_of_accessor(a), params, self->carg++); - self->offsetsection = grib_arguments_get_name(grib_handle_of_accessor(a), params, self->carg++); - self->dirty = 1; + seclen_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, carg_++); + offsetdata_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, carg_++); + offsetsection_ = grib_arguments_get_name(grib_handle_of_accessor(this), params, carg_++); + dirty_ = 1; - a->length = init_length(a); - /* Assert(a->length>=0); */ + length_ = init_length(this); + /* Assert(length_ >=0); */ } -int grib_accessor_class_values_t::get_native_type(grib_accessor* a) +long grib_accessor_values_t::get_native_type() { return GRIB_TYPE_DOUBLE; } -void grib_accessor_class_values_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_values_t::dump(grib_dumper* dumper) { - grib_dump_values(dumper, a); + grib_dump_values(dumper, this); } -long grib_accessor_class_values_t::byte_count(grib_accessor* a) +long grib_accessor_values_t::byte_count() { - grib_context_log(a->context, GRIB_LOG_DEBUG, "byte_count of %s = %ld", a->name, a->length); - return a->length; + grib_context_log(context_, GRIB_LOG_DEBUG, "byte_count of %s = %ld", name_, length_); + return length_; } -long grib_accessor_class_values_t::byte_offset(grib_accessor* a) +long grib_accessor_values_t::byte_offset() { - return a->offset; + return offset_; } -long grib_accessor_class_values_t::next_offset(grib_accessor* a) +long grib_accessor_values_t::next_offset() { - return a->offset + a->length; + return offset_ + length_; } -void grib_accessor_class_values_t::update_size(grib_accessor* a, size_t s) +void grib_accessor_values_t::update_size(size_t s) { - grib_context_log(a->context, GRIB_LOG_DEBUG, "updating size of %s old %ld new %ld", a->name, a->length, s); - a->length = s; - Assert(a->length >= 0); + grib_context_log(context_, GRIB_LOG_DEBUG, "updating size of %s old %ld new %ld", name_, length_, s); + length_ = s; + Assert(length_ >= 0); } -int grib_accessor_class_values_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_values_t::compare(grib_accessor* b) { int retval = 0; double* aval = 0; @@ -105,44 +104,46 @@ int grib_accessor_class_values_t::compare(grib_accessor* a, grib_accessor* b) int err = 0; long count = 0; - err = a->value_count(&count); if (err) + err = value_count(&count); + if (err) return err; alen = count; - err = b->value_count(&count); if (err) + err = b->value_count(&count); + if (err) return err; blen = count; if (alen != blen) return GRIB_COUNT_MISMATCH; - aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); - bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); + aval = (double*)grib_context_malloc(context_, alen * sizeof(double)); + bval = (double*)grib_context_malloc(b->context_, blen * sizeof(double)); - a->unpack_double(aval, &alen); b->unpack_double(bval, &blen); + unpack_double(aval, &alen); + b->unpack_double(bval, &blen); retval = GRIB_SUCCESS; - for (size_t i=0; icontext, aval); - grib_context_free(b->context, bval); + grib_context_free(context_, aval); + grib_context_free(b->context_, bval); return retval; } -int grib_accessor_class_values_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_values_t::pack_long(const long* val, size_t* len) { - grib_accessor_values_t* self = (grib_accessor_values_t*)a; - double* dval = (double*)grib_context_malloc(a->context, *len * sizeof(double)); + double* dval = (double*)grib_context_malloc(context_, *len * sizeof(double)); for (size_t i = 0; i < *len; i++) dval[i] = (double)val[i]; - int ret = a->pack_double(dval, len); - grib_context_free(a->context, dval); + int ret = pack_double(dval, len); + grib_context_free(context_, dval); - self->dirty = 1; + dirty_ = 1; return ret; } diff --git a/src/accessor/grib_accessor_class_values.h b/src/accessor/grib_accessor_class_values.h index 5de50f2bd..b7743205e 100644 --- a/src/accessor/grib_accessor_class_values.h +++ b/src/accessor/grib_accessor_class_values.h @@ -15,25 +15,23 @@ class grib_accessor_values_t : public grib_accessor_gen_t { public: - int carg; - const char* seclen; - const char* offsetdata; - const char* offsetsection; - int dirty; -}; - -class grib_accessor_class_values_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_values_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_values_t() : + grib_accessor_gen_t() { class_name_ = "values"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_values_t{}; } - int get_native_type(grib_accessor*) override; - int pack_long(grib_accessor*, const long* val, size_t* len) override; - long byte_count(grib_accessor*) override; - long byte_offset(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 compare(grib_accessor*, grib_accessor*) override; + long get_native_type() override; + int pack_long(const long* val, size_t* len) override; + long byte_count() override; + long byte_offset() override; + long next_offset() override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + void update_size(size_t) override; + int compare(grib_accessor*) override; + +public: + int carg_; + const char* seclen_; + const char* offsetdata_; + const char* offsetsection_; + int dirty_; }; diff --git a/src/accessor/grib_accessor_class_variable.cc b/src/accessor/grib_accessor_class_variable.cc index b87798663..35b6ea0d0 100644 --- a/src/accessor/grib_accessor_class_variable.cc +++ b/src/accessor/grib_accessor_class_variable.cc @@ -11,9 +11,8 @@ #include "grib_accessor_class_variable.h" #include - -grib_accessor_class_variable_t _grib_accessor_class_variable{"variable"}; -grib_accessor_class* grib_accessor_class_variable = &_grib_accessor_class_variable; +grib_accessor_variable_t _grib_accessor_variable{}; +grib_accessor* grib_accessor_variable = &_grib_accessor_variable; // // This accessor is used for: @@ -23,33 +22,36 @@ grib_accessor_class* grib_accessor_class_variable = &_grib_accessor_class_variab #define MAX_VARIABLE_STRING_LENGTH 255 -void grib_accessor_class_variable_t::init(grib_accessor* a, const long length, grib_arguments* args) +void grib_accessor_variable_t::init(const long length, grib_arguments* args) { - grib_accessor_class_gen_t::init(a, length, args); + grib_accessor_gen_t::init(length, args); - grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; - grib_handle* hand = grib_handle_of_accessor(a); - grib_expression* expression = grib_arguments_get_expression(hand, args, 0); - const char* p = 0; - size_t len = 1; - long l = 0; - int ret = 0; - double d = 0; - self->cname = NULL; + grib_handle* hand = grib_handle_of_accessor(this); + grib_expression* expression = grib_arguments_get_expression(hand, args, 0); + const char* p = 0; + size_t len = 1; + long l = 0; + int ret = 0; + double d = 0; + cname_ = NULL; + dval_ = 0; + fval_ = 0; + cval_ = NULL; + type_ = GRIB_TYPE_UNDEFINED; - a->length = 0; - if (self->type == GRIB_TYPE_UNDEFINED && expression) { - self->type = grib_expression_native_type(hand, expression); + length_ = 0; + if (type_ == GRIB_TYPE_UNDEFINED && expression) { + type_ = grib_expression_native_type(hand, expression); - switch (self->type) { + switch (type_) { case GRIB_TYPE_DOUBLE: grib_expression_evaluate_double(hand, expression, &d); - a->pack_double(&d, &len); + pack_double(&d, &len); break; case GRIB_TYPE_LONG: grib_expression_evaluate_long(hand, expression, &l); - a->pack_long(&l, &len); + pack_long(&l, &len); break; default: { @@ -57,12 +59,12 @@ void grib_accessor_class_variable_t::init(grib_accessor* a, const long length, g len = sizeof(tmp); p = grib_expression_evaluate_string(hand, expression, tmp, &len, &ret); if (ret != GRIB_SUCCESS) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Unable to evaluate %s as string: %s", - a->name, grib_get_error_message(ret)); + grib_context_log(context_, GRIB_LOG_ERROR, "Unable to evaluate %s as string: %s", + name_, grib_get_error_message(ret)); return; } len = strlen(p) + 1; - a->pack_string(p, &len); + pack_string(p, &len); break; } } @@ -72,176 +74,161 @@ void grib_accessor_class_variable_t::init(grib_accessor* a, const long length, g void accessor_variable_set_type(grib_accessor* a, int type) { grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; - self->type = type; + self->type_ = type; } -void grib_accessor_class_variable_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_variable_t::dump(grib_dumper* dumper) { - const grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; - switch (self->type) { + switch (type_) { case GRIB_TYPE_DOUBLE: - grib_dump_double(dumper, a, NULL); + grib_dump_double(dumper, this, NULL); break; case GRIB_TYPE_LONG: - grib_dump_long(dumper, a, NULL); + grib_dump_long(dumper, this, NULL); break; default: - grib_dump_string(dumper, a, NULL); + grib_dump_string(dumper, this, NULL); break; } } -int grib_accessor_class_variable_t::pack_double(grib_accessor* a, const double* val, size_t* len) +int grib_accessor_variable_t::pack_double(const double* val, size_t* len) { - grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; const double dval = *val; if (*len != 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains 1 value", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s, it contains 1 value", name_); *len = 1; return GRIB_ARRAY_TOO_SMALL; } - //if (std::isnan(dval)) { - // grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Invalid number for %s: %g", __func__, a->name, dval); - // return GRIB_INVALID_ARGUMENT; - //} + // if (std::isnan(dval)) { + // grib_context_log(a->context, GRIB_LOG_ERROR, "%s: Invalid number for %s: %g", __func__, name_ , dval); + // return GRIB_INVALID_ARGUMENT; + // } - self->dval = dval; + dval_ = dval; if (dval < (double)LONG_MIN || dval > (double)LONG_MAX) - self->type = GRIB_TYPE_DOUBLE; + type_ = GRIB_TYPE_DOUBLE; else - self->type = ((long)dval == dval) ? GRIB_TYPE_LONG : GRIB_TYPE_DOUBLE; + type_ = ((long)dval == dval) ? GRIB_TYPE_LONG : GRIB_TYPE_DOUBLE; return GRIB_SUCCESS; } -int grib_accessor_class_variable_t::pack_float(grib_accessor* a, const float* val, size_t* len) +int grib_accessor_variable_t::pack_float(const float* val, size_t* len) { - grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; const double fval = *val; if (*len != 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains 1 value", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s, it contains 1 value", name_); *len = 1; return GRIB_ARRAY_TOO_SMALL; } - self->fval = fval; + fval_ = fval; if (fval < (float)LONG_MIN || fval > (float)LONG_MAX) - self->type = GRIB_TYPE_DOUBLE; + type_ = GRIB_TYPE_DOUBLE; else - self->type = ((long)fval == fval) ? GRIB_TYPE_LONG : GRIB_TYPE_DOUBLE; + type_ = ((long)fval == fval) ? GRIB_TYPE_LONG : GRIB_TYPE_DOUBLE; return GRIB_SUCCESS; } -int grib_accessor_class_variable_t::pack_long(grib_accessor* a, const long* val, size_t* len) +int grib_accessor_variable_t::pack_long(const long* val, size_t* len) { - grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; - if (*len != 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains 1 value", a->name); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s it contains 1 value", name_); *len = 1; return GRIB_ARRAY_TOO_SMALL; } - self->dval = *val; - self->fval = *val; - self->type = GRIB_TYPE_LONG; + dval_ = *val; + fval_ = *val; + type_ = GRIB_TYPE_LONG; return GRIB_SUCCESS; } -int grib_accessor_class_variable_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_variable_t::unpack_double(double* val, size_t* len) { - const grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; - if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values", a->name, 1); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values", name_, 1); *len = 0; return GRIB_ARRAY_TOO_SMALL; } - *val = self->dval; + *val = dval_; *len = 1; return GRIB_SUCCESS; } -int grib_accessor_class_variable_t::unpack_float(grib_accessor* a, float* val, size_t* len) +int grib_accessor_variable_t::unpack_float(float* val, size_t* len) { - const grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; - if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values", a->name, 1); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s, it contains %d values", name_, 1); *len = 0; return GRIB_ARRAY_TOO_SMALL; } - *val = self->fval; + *val = fval_; *len = 1; return GRIB_SUCCESS; } -int grib_accessor_class_variable_t::unpack_long(grib_accessor* a, long* val, size_t* len) +int grib_accessor_variable_t::unpack_long(long* val, size_t* len) { - const grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; - if (*len < 1) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", a->name, 1); + grib_context_log(context_, GRIB_LOG_ERROR, "Wrong size for %s it contains %d values ", name_, 1); *len = 0; return GRIB_ARRAY_TOO_SMALL; } - *val = (long)self->dval; + *val = (long)dval_; *len = 1; return GRIB_SUCCESS; } -int grib_accessor_class_variable_t::get_native_type(grib_accessor* a) +long grib_accessor_variable_t::get_native_type() { - const grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; - return self->type; + return type_; } -void grib_accessor_class_variable_t::destroy(grib_context* c, grib_accessor* a) +void grib_accessor_variable_t::destroy(grib_context* c) { - grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; - int i = 0; + int i = 0; - grib_context_free(c, self->cval); - if (self->cname) - grib_context_free(c, self->cname); /* ECC-765 */ + grib_context_free(c, cval_); + if (cname_) + grib_context_free(c, cname_); /* ECC-765 */ /* Note: BUFR operator descriptors are variables and have attributes so need to free them */ - while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { - a->attributes[i]->destroy(c); - a->attributes[i] = NULL; + while (i < MAX_ACCESSOR_ATTRIBUTES && attributes_[i]) { + attributes_[i]->destroy(c); + attributes_[i] = NULL; ++i; } - grib_accessor_class_gen_t::destroy(c, a); + grib_accessor_gen_t::destroy(c); } -int grib_accessor_class_variable_t::unpack_string(grib_accessor* a, char* val, size_t* len) +int grib_accessor_variable_t::unpack_string(char* val, size_t* len) { - grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; - char buf[80]; - char* p = buf; + char* p = buf; size_t slen = 0; - if (self->type == GRIB_TYPE_STRING) { - p = self->cval; + if (type_ == GRIB_TYPE_STRING) { + p = cval_; } else { - snprintf(p, 64, "%g", self->dval); + snprintf(p, 64, "%g", dval_); } slen = strlen(p) + 1; if (*len < slen) { - grib_context_log(a->context, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s: Buffer too small for %s. It is %zu bytes long (len=%zu)", - a->cclass->name, a->name, slen, *len); + class_name_, name_, slen, *len); *len = slen; return GRIB_BUFFER_TOO_SMALL; } @@ -251,41 +238,39 @@ int grib_accessor_class_variable_t::unpack_string(grib_accessor* a, char* val, s return GRIB_SUCCESS; } -int grib_accessor_class_variable_t::pack_string(grib_accessor* a, const char* val, size_t* len) +int grib_accessor_variable_t::pack_string(const char* val, size_t* len) { - grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; - const grib_context* c = a->context; + const grib_context* c = context_; - grib_context_free(c, self->cval); - self->cval = grib_context_strdup(c, val); - self->dval = atof(val); - self->fval = atof(val); - self->type = GRIB_TYPE_STRING; - self->cname = NULL; + grib_context_free(c, cval_); + cval_ = grib_context_strdup(c, val); + dval_ = atof(val); + fval_ = atof(val); + type_ = GRIB_TYPE_STRING; + cname_ = NULL; return GRIB_SUCCESS; } -int grib_accessor_class_variable_t::value_count(grib_accessor* a, long* count) +int grib_accessor_variable_t::value_count(long* count) { *count = 1; return 0; } -size_t grib_accessor_class_variable_t::string_length(grib_accessor* a) +size_t grib_accessor_variable_t::string_length() { - const grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; - if (self->type == GRIB_TYPE_STRING) - return strlen(self->cval); + if (type_ == GRIB_TYPE_STRING) + return strlen(cval_); else return MAX_VARIABLE_STRING_LENGTH; } -long grib_accessor_class_variable_t::byte_count(grib_accessor* a) +long grib_accessor_variable_t::byte_count() { - return a->length; + return length_; } -int grib_accessor_class_variable_t::compare(grib_accessor* a, grib_accessor* b) +int grib_accessor_variable_t::compare(grib_accessor* b) { int retval = GRIB_SUCCESS; double* aval = 0; @@ -296,7 +281,7 @@ int grib_accessor_class_variable_t::compare(grib_accessor* a, grib_accessor* b) int err = 0; long count = 0; - err = a->value_count(&count); + err = value_count(&count); if (err) return err; alen = count; @@ -309,50 +294,50 @@ int grib_accessor_class_variable_t::compare(grib_accessor* a, grib_accessor* b) if (alen != blen) return GRIB_COUNT_MISMATCH; - aval = (double*)grib_context_malloc(a->context, alen * sizeof(double)); - bval = (double*)grib_context_malloc(b->context, blen * sizeof(double)); + aval = (double*)grib_context_malloc(context_, alen * sizeof(double)); + bval = (double*)grib_context_malloc(b->context_, blen * sizeof(double)); - a->unpack_double(aval, &alen); + unpack_double(aval, &alen); b->unpack_double(bval, &blen); retval = GRIB_SUCCESS; - retval = GRIB_SUCCESS; - for (size_t i=0; icontext, aval); - grib_context_free(b->context, bval); + grib_context_free(context_, aval); + grib_context_free(b->context_, bval); return retval; } -grib_accessor* grib_accessor_class_variable_t::make_clone(grib_accessor* a, grib_section* s, int* err) +grib_accessor* grib_accessor_variable_t::make_clone(grib_section* s, int* err) { - grib_accessor* the_clone = NULL; - const grib_accessor_variable_t* self = (grib_accessor_variable_t*)a; + grib_accessor* the_clone = NULL; grib_accessor_variable_t* variableAccessor = NULL; - grib_action creator = {0,}; - creator.op = (char*)"variable"; + grib_action creator = { + 0, + }; + creator.op = (char*)"variable"; creator.name_space = (char*)""; - creator.set = 0; + creator.set = 0; - creator.name = grib_context_strdup(a->context, a->name); - the_clone = grib_accessor_factory(s, &creator, 0, NULL); - the_clone->parent = NULL; - the_clone->h = s->h; - the_clone->flags = a->flags; - variableAccessor = (grib_accessor_variable_t*)the_clone; - variableAccessor->cname = creator.name; /* ECC-765: Store for later freeing memory */ + creator.name = grib_context_strdup(context_, name_); + the_clone = grib_accessor_factory(s, &creator, 0, NULL); + the_clone->parent_ = NULL; + the_clone->h_ = s->h; + the_clone->flags_ = flags_; + variableAccessor = (grib_accessor_variable_t*)the_clone; + variableAccessor->cname_ = creator.name; /* ECC-765: Store for later freeing memory */ - *err = 0; - variableAccessor->type = self->type; - if (self->type == GRIB_TYPE_STRING && self->cval != NULL) { - variableAccessor->cval = grib_context_strdup(a->context, self->cval); + *err = 0; + variableAccessor->type_ = type_; + if (type_ == GRIB_TYPE_STRING && cval_ != NULL) { + variableAccessor->cval_ = grib_context_strdup(context_, cval_); } else { - variableAccessor->dval = self->dval; - variableAccessor->fval = self->fval; + variableAccessor->dval_ = dval_; + variableAccessor->fval_ = fval_; } return the_clone; diff --git a/src/accessor/grib_accessor_class_variable.h b/src/accessor/grib_accessor_class_variable.h index 90ff71238..3051ab58f 100644 --- a/src/accessor/grib_accessor_class_variable.h +++ b/src/accessor/grib_accessor_class_variable.h @@ -13,37 +13,34 @@ #include "grib_accessor.h" #include "grib_accessor_class_gen.h" - class grib_accessor_variable_t : public grib_accessor_gen_t { public: - double dval; - float fval; - char* cval; - char* cname; - int type; -}; - -class grib_accessor_class_variable_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_variable_t(const char* name) : grib_accessor_class_gen_t(name) {}; + grib_accessor_variable_t() : + grib_accessor_gen_t() { class_name_ = "variable"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_variable_t{}; } - int get_native_type(grib_accessor*) override; - int pack_double(grib_accessor*, const double* val, size_t* len) override; - int pack_float(grib_accessor*, const float* 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_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 byte_count(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; - grib_accessor* make_clone(grib_accessor*, grib_section*, int*) override; + long get_native_type() override; + int pack_double(const double* val, size_t* len) override; + int pack_float(const float* val, size_t* len) override; + int pack_long(const long* val, size_t* len) override; + int pack_string(const char*, size_t* len) override; + int unpack_double(double* val, size_t* len) override; + int unpack_float(float* val, size_t* len) override; + int unpack_long(long* val, size_t* len) override; + int unpack_string(char*, size_t* len) override; + size_t string_length() override; + long byte_count() override; + int value_count(long*) override; + void destroy(grib_context*) override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + int compare(grib_accessor*) override; + grib_accessor* make_clone(grib_section*, int*) override; + +public: + double dval_; + float fval_; + char* cval_; + char* cname_; + int type_; }; diff --git a/src/accessor/grib_accessor_class_vector.cc b/src/accessor/grib_accessor_class_vector.cc index d9ae76406..1c0526641 100644 --- a/src/accessor/grib_accessor_class_vector.cc +++ b/src/accessor/grib_accessor_class_vector.cc @@ -11,53 +11,50 @@ #include "grib_accessor_class_vector.h" #include "grib_accessor_class_abstract_vector.h" -grib_accessor_class_vector_t _grib_accessor_class_vector{ "vector" }; -grib_accessor_class* grib_accessor_class_vector = &_grib_accessor_class_vector; +grib_accessor_vector_t _grib_accessor_vector{}; +grib_accessor* grib_accessor_vector = &_grib_accessor_vector; - -void grib_accessor_class_vector_t::init(grib_accessor* a, const long l, grib_arguments* c) +void grib_accessor_vector_t::init(const long l, grib_arguments* c) { - grib_accessor_class_abstract_vector_t::init(a, l, c); - grib_accessor_vector_t* self = (grib_accessor_vector_t*)a; + grib_accessor_abstract_vector_t::init(l, c); int n = 0; - self->vector = grib_arguments_get_name(grib_handle_of_accessor(a), c, n++); - self->index = grib_arguments_get_long(grib_handle_of_accessor(a), c, n++); - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; - a->flags |= GRIB_ACCESSOR_FLAG_FUNCTION; - a->length = 0; + vector_ = grib_arguments_get_name(grib_handle_of_accessor(this), c, n++); + index_ = grib_arguments_get_long(grib_handle_of_accessor(this), c, n++); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; + flags_ |= GRIB_ACCESSOR_FLAG_FUNCTION; + length_ = 0; } -int grib_accessor_class_vector_t::unpack_double(grib_accessor* a, double* val, size_t* len) +int grib_accessor_vector_t::unpack_double(double* val, size_t* len) { int err = 0; size_t size = 0; double* stat; - grib_accessor_vector_t* self = (grib_accessor_vector_t*)a; - grib_accessor* va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(a), self->vector); + grib_accessor* va = (grib_accessor*)grib_find_accessor(grib_handle_of_accessor(this), vector_); grib_accessor_abstract_vector_t* v = (grib_accessor_abstract_vector_t*)va; - Assert(self->index >= 0); + Assert(index_ >= 0); - if (self->index >= v->number_of_elements) { - grib_context_log(a->context, GRIB_LOG_FATAL, "index=%d number_of_elements=%d for %s", self->index, v->number_of_elements, a->name); - Assert(self->index < v->number_of_elements); + if (index_ >= v->number_of_elements_) { + grib_context_log(context_, GRIB_LOG_FATAL, "index=%d number_of_elements=%d for %s", index_, v->number_of_elements_, name_); + Assert(index_ < v->number_of_elements_); } - if (va->dirty) { - //printf("\ngrib_accessor_class_vector_t::unpack_double accessor=%s is DIRTY\n",a->name); - grib_get_size(grib_handle_of_accessor(a), self->vector, &size); - stat = (double*)grib_context_malloc_clear(a->context, sizeof(double) * size); + if (va->dirty_) { + // printf("\ngrib_accessor_class_vector_t::unpack_double accessor=%s is DIRTY\n", name_); + grib_get_size(grib_handle_of_accessor(this), vector_, &size); + stat = (double*)grib_context_malloc_clear(context_, sizeof(double) * size); err = va->unpack_double(stat, &size); - grib_context_free(a->context, stat); + grib_context_free(context_, stat); if (err) return err; } else { - //printf("\ngrib_accessor_class_vector_t::unpack_double accessor=%s is CLEAN\n",a->name); + // printf("\ngrib_accessor_class_vector_t::unpack_double accessor=%s is CLEAN\n",a->name); } - *val = v->v[self->index]; + *val = v->v_[index_]; return err; } diff --git a/src/accessor/grib_accessor_class_vector.h b/src/accessor/grib_accessor_class_vector.h index 92dc6a13e..64d598954 100644 --- a/src/accessor/grib_accessor_class_vector.h +++ b/src/accessor/grib_accessor_class_vector.h @@ -16,16 +16,13 @@ class grib_accessor_vector_t : public grib_accessor_abstract_vector_t { public: - /* Members defined in vector */ - const char* vector; - int index; -}; - -class grib_accessor_class_vector_t : public grib_accessor_class_abstract_vector_t -{ -public: - grib_accessor_class_vector_t(const char* name) : grib_accessor_class_abstract_vector_t(name) {} + grib_accessor_vector_t() : + grib_accessor_abstract_vector_t() { class_name_ = "vector"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_vector_t{}; } - int unpack_double(grib_accessor*, double* val, size_t* len) override; - void init(grib_accessor*, const long, grib_arguments*) override; + int unpack_double(double* val, size_t* len) override; + void init(const long, grib_arguments*) override; + +private: + const char* vector_; + int index_; }; diff --git a/src/accessor/grib_accessor_class_when.cc b/src/accessor/grib_accessor_class_when.cc index a17f111ea..ecbd7b4db 100644 --- a/src/accessor/grib_accessor_class_when.cc +++ b/src/accessor/grib_accessor_class_when.cc @@ -10,29 +10,28 @@ #include "grib_accessor_class_when.h" -grib_accessor_class_when_t _grib_accessor_class_when{ "when" }; -grib_accessor_class* grib_accessor_class_when = &_grib_accessor_class_when; +grib_accessor_when_t _grib_accessor_when{}; +grib_accessor* grib_accessor_when = &_grib_accessor_when; - -void grib_accessor_class_when_t::init(grib_accessor* a, const long len, grib_arguments* arg) +void grib_accessor_when_t::init(const long len, grib_arguments* arg) { - grib_accessor_class_gen_t::init(a, len, arg); - a->length = 0; - a->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; - a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; + grib_accessor_gen_t::init(len, arg); + length_ = 0; + flags_ |= GRIB_ACCESSOR_FLAG_HIDDEN; + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -void grib_accessor_class_when_t::dump(grib_accessor* a, grib_dumper* dumper) +void grib_accessor_when_t::dump(grib_dumper* dumper) { /* grib_dump_when(dumper,a,NULL); */ } -int grib_accessor_class_when_t::notify_change(grib_accessor* a, grib_accessor* changed) +int grib_accessor_when_t::notify_change(grib_accessor* changed) { - return grib_action_notify_change(a->creator, a, changed); + return grib_action_notify_change(creator_, this, changed); } -int grib_accessor_class_when_t::get_native_type(grib_accessor* a) +long grib_accessor_when_t::get_native_type() { return GRIB_TYPE_UNDEFINED; } diff --git a/src/accessor/grib_accessor_class_when.h b/src/accessor/grib_accessor_class_when.h index 515afb4b1..b330a9246 100644 --- a/src/accessor/grib_accessor_class_when.h +++ b/src/accessor/grib_accessor_class_when.h @@ -16,16 +16,11 @@ class grib_accessor_when_t : public grib_accessor_gen_t { public: - /* Members defined in when */ -}; - -class grib_accessor_class_when_t : public grib_accessor_class_gen_t -{ -public: - grib_accessor_class_when_t(const char* name) : grib_accessor_class_gen_t(name) {} + grib_accessor_when_t() : + grib_accessor_gen_t() { class_name_ = "when"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_when_t{}; } - int get_native_type(grib_accessor*) override; - void dump(grib_accessor*, grib_dumper*) override; - void init(grib_accessor*, const long, grib_arguments*) override; - int notify_change(grib_accessor*, grib_accessor*) override; + long get_native_type() override; + void dump(grib_dumper*) override; + void init(const long, grib_arguments*) override; + int notify_change(grib_accessor* changed) override; }; diff --git a/src/accessor/grib_accessors_list.cc b/src/accessor/grib_accessors_list.cc index 173077e69..47b6e47ba 100644 --- a/src/accessor/grib_accessors_list.cc +++ b/src/accessor/grib_accessors_list.cc @@ -27,8 +27,8 @@ void grib_accessors_list_delete(grib_context* c, grib_accessors_list* al) int grib_accessors_list::value_count(size_t* count) { - long lcount = 0; - *count = 0; + long lcount = 0; + *count = 0; grib_accessors_list* al = this; while (al) { al->accessor->value_count(&lcount); @@ -41,7 +41,7 @@ int grib_accessors_list::value_count(size_t* count) void grib_accessors_list::push(grib_accessor* a, int rank) { grib_accessors_list* last; - const grib_context* c = a->context; + const grib_context* c = a->context_; last = this->last(); if (last && last->accessor) { diff --git a/src/accessor/grib_accessors_list.h b/src/accessor/grib_accessors_list.h index e136d955a..cc6eafee2 100644 --- a/src/accessor/grib_accessors_list.h +++ b/src/accessor/grib_accessors_list.h @@ -28,10 +28,11 @@ public: int rank() const { return rank_; } - grib_accessor* accessor = nullptr; + grib_accessor* accessor = nullptr; grib_accessors_list* next_ = nullptr; grib_accessors_list* prev_ = nullptr; grib_accessors_list* last_ = nullptr; + private: int rank_ = 0; }; diff --git a/src/action_class_alias.cc b/src/action_class_alias.cc index 014a3f47c..49ef35e43 100644 --- a/src/action_class_alias.cc +++ b/src/action_class_alias.cc @@ -10,7 +10,6 @@ /*************************************************************************** * Jean Baptiste Filippi - 01.11.2005 * - * Enrico Fucile * ***************************************************************************/ #include "grib_api_internal.h" /* @@ -138,19 +137,19 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) return GRIB_SUCCESS; } - if (x->name_space == NULL) - x->name_space = act->name_space; + if (x->name_space_ == NULL) + x->name_space_ = act->name_space; grib_context_log(p->h->context, GRIB_LOG_DEBUG, "alias: add only namespace: %s.%s", act->name_space, act->name); i = 0; while (i < MAX_ACCESSOR_NAMES) { - if (x->all_names[i] != NULL && !grib_inline_strcmp(x->all_names[i], act->name)) { - if (x->all_name_spaces[i] == NULL) { - x->all_name_spaces[i] = act->name_space; + if (x->all_names_[i] != NULL && !grib_inline_strcmp(x->all_names_[i], act->name)) { + if (x->all_name_spaces_[i] == NULL) { + x->all_name_spaces_[i] = act->name_space; return GRIB_SUCCESS; } - else if (!grib_inline_strcmp(x->all_name_spaces[i], act->name_space)) { + else if (!grib_inline_strcmp(x->all_name_spaces_[i], act->name_space)) { return GRIB_SUCCESS; } } @@ -158,9 +157,9 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) } i = 0; while (i < MAX_ACCESSOR_NAMES) { - if (x->all_names[i] == NULL) { - x->all_names[i] = act->name; - x->all_name_spaces[i] = act->name_space; + if (x->all_names_[i] == NULL) { + x->all_names_[i] = act->name; + x->all_name_spaces_[i] = act->name_space; return GRIB_SUCCESS; } i++; @@ -176,20 +175,20 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) /* delete old alias if already defined */ if (y != NULL) { i = 0; - while (i < MAX_ACCESSOR_NAMES && y->all_names[i]) { - if (same(y->all_names[i], act->name) && same(y->all_name_spaces[i], act->name_space)) { + while (i < MAX_ACCESSOR_NAMES && y->all_names_[i]) { + if (same(y->all_names_[i], act->name) && same(y->all_name_spaces_[i], act->name_space)) { grib_context_log(p->h->context, GRIB_LOG_DEBUG, "alias %s.%s already defined for %s. Deleting old alias", - act->name_space, act->name, y->name); - /* printf("[%s %s]\n",y->all_names[i], y->all_name_spaces[i]); */ + act->name_space, act->name, y->name_); + /* printf("[%s %s]\n",y->all_names_[i], y->all_name_spaces_[i]); */ while (i < MAX_ACCESSOR_NAMES - 1) { - y->all_names[i] = y->all_names[i + 1]; - y->all_name_spaces[i] = y->all_name_spaces[i + 1]; + y->all_names_[i] = y->all_names_[i + 1]; + y->all_name_spaces_[i] = y->all_name_spaces_[i + 1]; i++; } - y->all_names[MAX_ACCESSOR_NAMES - 1] = NULL; - y->all_name_spaces[MAX_ACCESSOR_NAMES - 1] = NULL; + y->all_names_[MAX_ACCESSOR_NAMES - 1] = NULL; + y->all_name_spaces_[MAX_ACCESSOR_NAMES - 1] = NULL; break; } @@ -214,7 +213,7 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) hand = grib_handle_of_accessor(x); if (hand->use_trie) { - id = grib_hash_keys_get_id(x->context->keys, act->name); + id = grib_hash_keys_get_id(x->context_->keys, act->name); hand->accessors[id] = x; /* @@ -227,19 +226,19 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) i = 0; while (i < MAX_ACCESSOR_NAMES) { - if (x->all_names[i] == NULL) { + if (x->all_names_[i] == NULL) { /* Only add entries if not already there */ int found = 0; for (j = 0; j < i && !found; ++j) { - int nameSame = same(x->all_names[j], act->name); - int namespaceSame = same(x->all_name_spaces[j], act->name_space); + int nameSame = same(x->all_names_[j], act->name); + int namespaceSame = same(x->all_name_spaces_[j], act->name_space); if (nameSame && namespaceSame) { found = 1; } } if (!found) { /* Not there. So add them */ - x->all_names[i] = act->name; - x->all_name_spaces[i] = act->name_space; + x->all_names_[i] = act->name; + x->all_name_spaces_[i] = act->name_space; grib_context_log(p->h->context, GRIB_LOG_DEBUG, "alias %s.%s added (%s)", act->name_space, act->name, self->target); } @@ -250,7 +249,7 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) for (i = 0; i < MAX_ACCESSOR_NAMES; i++) grib_context_log(p->h->context, GRIB_LOG_ERROR, "alias %s= ( %s already bound to %s )", - act->name, self->target, x->all_names[i]); + act->name, self->target, x->all_names_[i]); return GRIB_SUCCESS; } diff --git a/src/action_class_assert.cc b/src/action_class_assert.cc index 66cf04f56..b19330505 100644 --- a/src/action_class_assert.cc +++ b/src/action_class_assert.cc @@ -8,9 +8,6 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/*************************************************************************** - * Enrico Fucile * - ***************************************************************************/ #include "grib_api_internal.h" /* diff --git a/src/action_class_close.cc b/src/action_class_close.cc index 3c8d51900..dfe635890 100644 --- a/src/action_class_close.cc +++ b/src/action_class_close.cc @@ -91,18 +91,17 @@ grib_action* grib_action_create_close(grib_context* context, char* filename) static int execute(grib_action* act, grib_handle* h) { - char filename[2048] = {0,}; - size_t len = 2048; grib_action_close* self = (grib_action_close*)act; - int err = 0; - grib_file* file = 0; - err = grib_get_string(h, self->filename, filename, &len); + char filename[2048] = {0,}; + size_t len = sizeof(filename); + + int err = grib_get_string(h, self->filename, filename, &len); /* fprintf(stderr,"++++ name %s\n",filename); */ if (err) return err; /* grib_file_close(filename,1,&err); */ - file = grib_get_file(filename, &err); + grib_file* file = grib_get_file(filename, &err); if (err) return err; if (file) diff --git a/src/action_class_concept.cc b/src/action_class_concept.cc index b88600887..eea243888 100644 --- a/src/action_class_concept.cc +++ b/src/action_class_concept.cc @@ -10,7 +10,6 @@ /*************************************************************************** * Jean Baptiste Filippi - 01.11.2005 * - * Enrico Fucile * ***************************************************************************/ #include "grib_api_internal.h" /* @@ -123,12 +122,12 @@ static grib_concept_value* get_concept(grib_handle* h, grib_action_concept* self grib_concept_value* action_concept_get_concept(grib_accessor* a) { - return get_concept(grib_handle_of_accessor(a), (grib_action_concept*)a->creator); + return get_concept(grib_handle_of_accessor(a), (grib_action_concept*)a->creator_); } int action_concept_get_nofail(grib_accessor* a) { - const grib_action_concept* self = (grib_action_concept*)a->creator; + const grib_action_concept* self = (grib_action_concept*)a->creator_; return self->nofail; } @@ -317,10 +316,10 @@ static grib_concept_value* get_concept(grib_handle* h, grib_action_concept* self static int concept_condition_expression_true(grib_handle* h, grib_concept_condition* c, char* exprVal) { - long lval; - long lres = 0; - int ok = 0; - int err = 0; + long lval = 0; + long lres = 0; + int ok = 0; + int err = 0; const int type = grib_expression_native_type(h, c->expression); switch (type) { diff --git a/src/action_class_gen.cc b/src/action_class_gen.cc index 722391c7f..a4a95b438 100644 --- a/src/action_class_gen.cc +++ b/src/action_class_gen.cc @@ -140,7 +140,7 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* loade grib_push_accessor(ga, p->block); - if (ga->flags & GRIB_ACCESSOR_FLAG_CONSTRAINT) + if (ga->flags_ & GRIB_ACCESSOR_FLAG_CONSTRAINT) grib_dependency_observe_arguments(ga, act->default_value); if (loader == NULL) diff --git a/src/action_class_hash_array.cc b/src/action_class_hash_array.cc index fd1e52976..9a61f9e56 100644 --- a/src/action_class_hash_array.cc +++ b/src/action_class_hash_array.cc @@ -8,9 +8,6 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/*************************************************************************** - * Enrico Fucile 2012 * - ***************************************************************************/ #include "grib_api_internal.h" /* This is used by make_class.pl @@ -231,7 +228,6 @@ static grib_hash_array_value* get_hash_array_impl(grib_handle* h, grib_action* a char key[4096] = {0,}; char* full = 0; int id; - int err; grib_action_hash_array* self = (grib_action_hash_array*)a; grib_context* context = ((grib_action*)self)->context; @@ -245,7 +241,7 @@ static grib_hash_array_value* get_hash_array_impl(grib_handle* h, grib_action* a snprintf(buf, 4096, "%s/%s", masterDir, self->basename); - err = grib_recompose_name(h, NULL, buf, master, 1); + int err = grib_recompose_name(h, NULL, buf, master, 1); if (err) { grib_context_log(context, GRIB_LOG_ERROR, "unable to build name of directory %s", self->masterDir); diff --git a/src/action_class_if.cc b/src/action_class_if.cc index ec99ba315..c9c7d9d48 100644 --- a/src/action_class_if.cc +++ b/src/action_class_if.cc @@ -10,7 +10,6 @@ /*************************************************************************** * Jean Baptiste Filippi - 01.11.2005 * - * Enrico Fucile * ***************************************************************************/ #include "grib_api_internal.h" /* @@ -142,7 +141,7 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) as = grib_accessor_factory(p, act, 0, NULL); if (!as) return GRIB_INTERNAL_ERROR; - gs = as->sub_section; + gs = as->sub_section_; grib_push_accessor(as, p->block); if ((ret = grib_expression_evaluate_long(p->h, a->expression, &lres)) != GRIB_SUCCESS) @@ -270,7 +269,7 @@ static grib_action* reparse(grib_action* a, grib_accessor* acc, int* doit) /* printf("reparse %s %s\n",a->name,acc->name); */ if ((ret = grib_expression_evaluate_long(grib_handle_of_accessor(acc), self->expression, &lres)) != GRIB_SUCCESS) - grib_context_log(acc->context, + grib_context_log(acc->context_, GRIB_LOG_ERROR, "action_class_if::reparse: grib_expression_evaluate_long failed: %s", grib_get_error_message(ret)); diff --git a/src/action_class_list.cc b/src/action_class_list.cc index 163a6da55..3441a6a39 100644 --- a/src/action_class_list.cc +++ b/src/action_class_list.cc @@ -115,8 +115,8 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) ga = grib_accessor_factory(p, act, 0, NULL); if (!ga) return GRIB_BUFFER_TOO_SMALL; - gs = ga->sub_section; - ga->loop = val; + gs = ga->sub_section_; + ga->loop_ = val; grib_push_accessor(ga, p->block); @@ -164,11 +164,11 @@ static grib_action* reparse(grib_action* a, grib_accessor* acc, int* doit) int ret = grib_expression_evaluate_long(grib_handle_of_accessor(acc), self->expression, &val); if (ret != GRIB_SUCCESS) { - grib_context_log(acc->context, GRIB_LOG_ERROR, - "List %s creating %ld values: Unable to evaluate long", acc->name, val); + grib_context_log(acc->context_, GRIB_LOG_ERROR, + "List %s creating %ld values: Unable to evaluate long", acc->name_, val); } - *doit = (val != acc->loop); + *doit = (val != acc->loop_); return self->block_list; } diff --git a/src/action_class_modify.cc b/src/action_class_modify.cc index cc5795559..e707d2d46 100644 --- a/src/action_class_modify.cc +++ b/src/action_class_modify.cc @@ -102,7 +102,7 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) ga = grib_find_accessor(p->h, a->name); if (ga) { - ga->flags = a->flags; + ga->flags_ = a->flags; } else { grib_context_log(act->context, GRIB_LOG_ERROR, "action_class_modify: %s: No accessor named %s to modify", diff --git a/src/action_class_remove.cc b/src/action_class_remove.cc index eff91cdce..9764bd8c8 100644 --- a/src/action_class_remove.cc +++ b/src/action_class_remove.cc @@ -96,10 +96,10 @@ static void remove_accessor(grib_accessor* a) if (!a || !a->previous_) return; - s = a->parent; + s = a->parent_; - if (grib_handle_of_accessor(a)->use_trie && *(a->all_names[0]) != '_') { - id = grib_hash_keys_get_id(a->context->keys, a->all_names[0]); + if (grib_handle_of_accessor(a)->use_trie && *(a->all_names_[0]) != '_') { + id = grib_hash_keys_get_id(a->context_->keys, a->all_names_[0]); grib_handle_of_accessor(a)->accessors[id] = NULL; } diff --git a/src/action_class_rename.cc b/src/action_class_rename.cc index 3fb65a704..1f3744b46 100644 --- a/src/action_class_rename.cc +++ b/src/action_class_rename.cc @@ -95,17 +95,17 @@ grib_action* grib_action_create_rename(grib_context* context, char* the_old, cha static void rename_accessor(grib_accessor* a, char* name) { int id; - char* the_old = (char*)a->all_names[0]; + char* the_old = (char*)a->all_names_[0]; - if (grib_handle_of_accessor(a)->use_trie && *(a->all_names[0]) != '_') { - id = grib_hash_keys_get_id(a->context->keys, a->all_names[0]); + if (grib_handle_of_accessor(a)->use_trie && *(a->all_names_[0]) != '_') { + id = grib_hash_keys_get_id(a->context_->keys, a->all_names_[0]); grib_handle_of_accessor(a)->accessors[id] = NULL; - id = grib_hash_keys_get_id(a->context->keys, name); + id = grib_hash_keys_get_id(a->context_->keys, name); grib_handle_of_accessor(a)->accessors[id] = a; } - a->all_names[0] = grib_context_strdup_persistent(a->context, name); - a->name = a->all_names[0]; - grib_context_log(a->context, GRIB_LOG_DEBUG, "Renaming %s to %s", the_old, name); + a->all_names_[0] = grib_context_strdup_persistent(a->context_, name); + a->name_ = a->all_names_[0]; + grib_context_log(a->context_, GRIB_LOG_DEBUG, "Renaming %s to %s", the_old, name); /* grib_context_free(a->context,the_old); */ } diff --git a/src/action_class_section.cc b/src/action_class_section.cc index 9dda3dc30..fb9fe690d 100644 --- a/src/action_class_section.cc +++ b/src/action_class_section.cc @@ -76,7 +76,7 @@ static void init_class(grib_action_class* c) // while(a) // { // Assert(grib_handle_of_accessor(a) == h); -// check_sections(a->sub_section,h); +// check_sections(a->sub_section_,h); // a = a->next; // } // } @@ -103,11 +103,11 @@ static int notify_change(grib_action* act, grib_accessor* notified, } grib_context_log(h->context, GRIB_LOG_DEBUG, "------------- SECTION action %s (%s) is triggered by [%s]%s", - act->name, notified->name, changed->name, debug_str); + act->name, notified->name_, changed->name_, debug_str); } la = grib_action_reparse(act, notified, &doit); - old_section = notified->sub_section; + old_section = notified->sub_section_; if (!old_section) return GRIB_INTERNAL_ERROR; Assert(old_section->h == h); @@ -123,14 +123,14 @@ static int notify_change(grib_action* act, grib_accessor* notified, if (!doit) { if (la != NULL || old_section->branch != NULL) if (la == old_section->branch) { - grib_context_log(h->context, GRIB_LOG_DEBUG, "IGNORING TRIGGER action %s (%s) is triggered %p", act->name, notified->name, (void*)la); + grib_context_log(h->context, GRIB_LOG_DEBUG, "IGNORING TRIGGER action %s (%s) is triggered %p", act->name, notified->name_, (void*)la); return GRIB_SUCCESS; } } loader.list_is_resized = (la == old_section->branch); - if (!strcmp(changed->name, "GRIBEditionNumber")) + if (!strcmp(changed->name_, "GRIBEditionNumber")) loader.changing_edition = 1; else loader.changing_edition = 0; @@ -159,7 +159,7 @@ static int notify_change(grib_action* act, grib_accessor* notified, h->kid = tmp_handle; /* printf("tmp_handle- main %p %p\n",(void*)tmp_handle,(void*)h); */ - grib_context_log(h->context, GRIB_LOG_DEBUG, "------------- CREATE TMP BLOCK act=%s notified=%s", act->name, notified->name); + grib_context_log(h->context, GRIB_LOG_DEBUG, "------------- CREATE TMP BLOCK act=%s notified=%s", act->name, notified->name_); tmp_handle->root = grib_section_create(tmp_handle, NULL); tmp_handle->use_trie = 1; @@ -198,7 +198,7 @@ static int notify_change(grib_action* act, grib_accessor* notified, Assert(tmp_handle->root->block->first != NULL); grib_swap_sections(old_section, - tmp_handle->root->block->first->sub_section); + tmp_handle->root->block->first->sub_section_); Assert(tmp_handle->dependencies == NULL); /* printf("grib_handle_delete %p\n",(void*)tmp_handle); */ diff --git a/src/action_class_template.cc b/src/action_class_template.cc index 79fd2aeaf..9b715fb0a 100644 --- a/src/action_class_template.cc +++ b/src/action_class_template.cc @@ -161,8 +161,8 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h) else la = grib_parse_file(p->h->context, fpath); } - as->flags |= GRIB_ACCESSOR_FLAG_HIDDEN; - gs = as->sub_section; + as->flags_ |= GRIB_ACCESSOR_FLAG_HIDDEN; + gs = as->sub_section_; gs->branch = la; /* Will be used to prevent unnecessary reparse */ grib_push_accessor(as, p->block); @@ -195,9 +195,9 @@ static grib_action* reparse(grib_action* a, grib_accessor* acc, int* doit) char fname[1024]; grib_recompose_name(grib_handle_of_accessor(acc), NULL, self->arg, fname, 1); - if ((fpath = grib_context_full_defs_path(acc->context, fname)) == NULL) { + if ((fpath = grib_context_full_defs_path(acc->context_, fname)) == NULL) { if (!self->nofail) { - grib_context_log(acc->context, GRIB_LOG_ERROR, + grib_context_log(acc->context_, GRIB_LOG_ERROR, "Unable to find template %s from %s ", a->name, fname); return NULL; } @@ -205,7 +205,7 @@ static grib_action* reparse(grib_action* a, grib_accessor* acc, int* doit) } /* printf("REPARSE %s\n",fpath); */ - return grib_parse_file(acc->context, fpath); + return grib_parse_file(acc->context_, fpath); } return NULL; diff --git a/src/action_class_transient_darray.cc b/src/action_class_transient_darray.cc index 276dcf3fa..b70924251 100644 --- a/src/action_class_transient_darray.cc +++ b/src/action_class_transient_darray.cc @@ -114,7 +114,7 @@ static int execute(grib_action* act, grib_handle* h) grib_push_accessor(a, p->block); - if (a->flags & GRIB_ACCESSOR_FLAG_CONSTRAINT) + if (a->flags_ & GRIB_ACCESSOR_FLAG_CONSTRAINT) grib_dependency_observe_arguments(a, act->default_value); return a->pack_double(self->darray->v, &len); diff --git a/src/action_class_when.cc b/src/action_class_when.cc index 640e75aab..9627d2b7d 100644 --- a/src/action_class_when.cc +++ b/src/action_class_when.cc @@ -8,9 +8,6 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/*************************************************************************** - * Enrico Fucile * - ***************************************************************************/ #include "grib_api_internal.h" /* This is used by make_class.pl @@ -205,8 +202,8 @@ static int notify_change(grib_action* a, grib_accessor* observer, grib_accessor* if (hand->context->debug > 0) { grib_context_log(hand->context, GRIB_LOG_DEBUG, "------------- SECTION action %s is triggered by [%s] (%s)", - a->name, observed->name, a->debug_info ? a->debug_info : "no debug info"); - grib_expression_print(observed->context, self->expression, 0, stderr); + a->name, observed->name_, a->debug_info ? a->debug_info : "no debug info"); + grib_expression_print(observed->context_, self->expression, 0, stderr); fprintf(stderr, "\n"); } diff --git a/src/bufr_keys_iterator.cc b/src/bufr_keys_iterator.cc index d22b0349b..09cf69e66 100644 --- a/src/bufr_keys_iterator.cc +++ b/src/bufr_keys_iterator.cc @@ -91,15 +91,15 @@ int codes_bufr_keys_iterator_rewind(bufr_keys_iterator* ki) static int skip(bufr_keys_iterator* kiter) { - if (kiter->current->sub_section) + if (kiter->current->sub_section_) return 1; - if (kiter->current->flags & kiter->accessor_flags_skip) { + if (kiter->current->flags_ & kiter->accessor_flags_skip) { return 1; } - if (kiter->accessor_flags_only == (kiter->current->flags & kiter->accessor_flags_only)) { - mark_seen(kiter, kiter->current->name); + if (kiter->accessor_flags_only == (kiter->current->flags_ & kiter->accessor_flags_only)) { + mark_seen(kiter, kiter->current->name_); return 0; } else { @@ -114,24 +114,24 @@ static int next_attribute(bufr_keys_iterator* kiter) if (!kiter->current) return 0; if (!kiter->attributes) { - kiter->attributes = kiter->current->attributes; + kiter->attributes = kiter->current->attributes_; kiter->prefix = 0; kiter->i_curr_attribute = 0; } i_curr_attribute = kiter->i_curr_attribute - 1; while (kiter->i_curr_attribute < MAX_ACCESSOR_ATTRIBUTES && kiter->attributes[kiter->i_curr_attribute]) { - if ((kiter->attributes[kiter->i_curr_attribute]->flags & GRIB_ACCESSOR_FLAG_DUMP) != 0 && (kiter->attributes[kiter->i_curr_attribute]->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) == 0) + if ((kiter->attributes[kiter->i_curr_attribute]->flags_ & GRIB_ACCESSOR_FLAG_DUMP) != 0 && (kiter->attributes[kiter->i_curr_attribute]->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) == 0) break; kiter->i_curr_attribute++; } if (kiter->attributes[kiter->i_curr_attribute]) { if (!kiter->prefix) { - const size_t prefixLenMax = strlen(kiter->current->name) + 10; - kiter->prefix = (char*)grib_context_malloc_clear(kiter->current->context, prefixLenMax); - r = (int*)grib_trie_get(kiter->seen, kiter->current->name); - snprintf(kiter->prefix, prefixLenMax, "#%d#%s", *r, kiter->current->name); + const size_t prefixLenMax = strlen(kiter->current->name_) + 10; + kiter->prefix = (char*)grib_context_malloc_clear(kiter->current->context_, prefixLenMax); + r = (int*)grib_trie_get(kiter->seen, kiter->current->name_); + snprintf(kiter->prefix, prefixLenMax, "#%d#%s", *r, kiter->current->name_); } kiter->i_curr_attribute++; return 1; @@ -141,18 +141,18 @@ static int next_attribute(bufr_keys_iterator* kiter) if (!kiter->prefix) return 0; if (!kiter->attributes[i_curr_attribute]) { - grib_context_free(kiter->current->context, kiter->prefix); + grib_context_free(kiter->current->context_, kiter->prefix); kiter->prefix = 0; return 0; } - prefix = (char*)grib_context_malloc_clear(kiter->current->context, strlen(kiter->prefix) + strlen(kiter->attributes[i_curr_attribute]->name) + 3); + prefix = (char*)grib_context_malloc_clear(kiter->current->context_, strlen(kiter->prefix) + strlen(kiter->attributes[i_curr_attribute]->name_) + 3); /*sprintf(prefix,"%s->%s",kiter->prefix,kiter->attributes[i_curr_attribute]->name);*/ strcpy(prefix, kiter->prefix); /* strcpy and strcat here are much faster than sprintf */ strcat(prefix, "->"); - strcat(prefix, kiter->attributes[i_curr_attribute]->name); - grib_context_free(kiter->current->context, kiter->prefix); + strcat(prefix, kiter->attributes[i_curr_attribute]->name_); + grib_context_free(kiter->current->context_, kiter->prefix); kiter->prefix = prefix; - kiter->attributes = kiter->attributes[i_curr_attribute]->attributes; + kiter->attributes = kiter->attributes[i_curr_attribute]->attributes_; kiter->i_curr_attribute = 0; return next_attribute(kiter); } @@ -179,7 +179,7 @@ int codes_bufr_keys_iterator_next(bufr_keys_iterator* kiter) kiter->current = kiter->current->next_accessor(); kiter->attributes = 0; if (kiter->prefix) { - grib_context_free(kiter->current->context, kiter->prefix); + grib_context_free(kiter->current->context_, kiter->prefix); kiter->prefix = 0; } kiter->i_curr_attribute = 0; @@ -204,22 +204,22 @@ char* codes_bufr_keys_iterator_get_name(const bufr_keys_iterator* ckiter) if (kiter->prefix) { int iattribute = kiter->i_curr_attribute - 1; - ret = (char*)grib_context_malloc_clear(c, strlen(kiter->prefix) + strlen(kiter->attributes[iattribute]->name) + 10); + ret = (char*)grib_context_malloc_clear(c, strlen(kiter->prefix) + strlen(kiter->attributes[iattribute]->name_) + 10); /*sprintf(ret,"%s->%s",kiter->prefix,kiter->attributes[iattribute]->name);*/ strcpy(ret, kiter->prefix); /* strcpy and strcat here are much faster than sprintf */ strcat(ret, "->"); - strcat(ret, kiter->attributes[iattribute]->name); + strcat(ret, kiter->attributes[iattribute]->name_); } else { - const size_t retMaxLen = strlen(kiter->current->name) + 10; + const size_t retMaxLen = strlen(kiter->current->name_) + 10; ret = (char*)grib_context_malloc_clear(c, retMaxLen); - if (kiter->current->flags & GRIB_ACCESSOR_FLAG_BUFR_DATA) { - r = (int*)grib_trie_get(kiter->seen, kiter->current->name); - snprintf(ret, retMaxLen, "#%d#%s", *r, kiter->current->name); + if (kiter->current->flags_ & GRIB_ACCESSOR_FLAG_BUFR_DATA) { + r = (int*)grib_trie_get(kiter->seen, kiter->current->name_); + snprintf(ret, retMaxLen, "#%d#%s", *r, kiter->current->name_); } else { - strcpy(ret, kiter->current->name); + strcpy(ret, kiter->current->name_); } } diff --git a/src/bufr_util.cc b/src/bufr_util.cc index 56a4977c0..a930f06b3 100644 --- a/src/bufr_util.cc +++ b/src/bufr_util.cc @@ -1113,7 +1113,7 @@ int codes_bufr_key_is_header(const grib_handle* h, const char* key, int* err) return 0; } *err = GRIB_SUCCESS; - return ((acc->flags & GRIB_ACCESSOR_FLAG_BUFR_DATA) == 0); + return ((acc->flags_ & GRIB_ACCESSOR_FLAG_BUFR_DATA) == 0); } // Returns 1 if the BUFR key is a coordinate descriptor @@ -1125,7 +1125,7 @@ int codes_bufr_key_is_coordinate(const grib_handle* h, const char* key, int* err return 0; } *err = GRIB_SUCCESS; - return ((acc->flags & GRIB_ACCESSOR_FLAG_BUFR_COORD) != 0); + return ((acc->flags_ & GRIB_ACCESSOR_FLAG_BUFR_COORD) != 0); } int codes_bufr_key_exclude_from_dump(const char* key) diff --git a/src/eccodes.cc b/src/eccodes.cc index 9ec6d8073..779690790 100644 --- a/src/eccodes.cc +++ b/src/eccodes.cc @@ -585,6 +585,11 @@ void codes_context_set_samples_path(grib_context* c, const char* path) grib_context_set_samples_path(c, path); } +void codes_context_set_debug(grib_context* c, int mode) +{ + grib_context_set_debug(c, mode); +} + void codes_context_set_memory_proc(grib_context* c, grib_malloc_proc p_malloc, grib_free_proc p_free, grib_realloc_proc p_realloc) { grib_context_set_memory_proc(c, p_malloc, p_free, p_realloc); diff --git a/src/eccodes.h b/src/eccodes.h index f0b110b86..0c8f7193c 100644 --- a/src/eccodes.h +++ b/src/eccodes.h @@ -1174,6 +1174,8 @@ void codes_context_set_definitions_path(codes_context* c, const char* path); */ void codes_context_set_samples_path(codes_context* c, const char* path); +void codes_context_set_debug(grib_context* c, int mode); + /** * Sets memory procedures of the context * diff --git a/src/grib_accessor_class.cc b/src/grib_accessor_class.cc index de7f8dc47..ff30662dc 100644 --- a/src/grib_accessor_class.cc +++ b/src/grib_accessor_class.cc @@ -129,38 +129,42 @@ static GRIB_INLINE grib_accessor_class* get_class(grib_context* c, char* type) grib_accessor* grib_accessor_factory(grib_section* p, grib_action* creator, const long len, grib_arguments* params) { - grib_accessor_class* c = NULL; + //grib_accessor_class* c = NULL; grib_accessor* a = NULL; size_t size = 0; +// TODO(maee): Replace this with an accessor_factory #ifdef ACCESSOR_FACTORY_USE_TRIE - c = get_class(p->h->context, creator->op); + //c = get_class(p->h->context, creator->op); #else /* Use the hash table built with gperf (See make_accessor_class_hash.sh) */ - c = *((grib_accessor_classes_hash(creator->op, strlen(creator->op)))->cclass); + //c = *((grib_accessor_classes_hash(creator->op, strlen(creator->op)))->cclass); #endif - a = c->create_empty_accessor(); + auto a_tmp = *((grib_accessor_hash(creator->op, strlen(creator->op)))->cclass); - a->name = creator->name; - a->name_space = creator->name_space; + a = a_tmp->create_empty_accessor(); + //a = c->create_empty_accessor(); - a->all_names[0] = creator->name; - a->all_name_spaces[0] = creator->name_space; + a->name_ = creator->name; + a->name_space_ = creator->name_space; - a->creator = creator; - a->context = p->h->context; - a->h = NULL; + a->all_names_[0] = creator->name; + a->all_name_spaces_[0] = creator->name_space; + + a->creator_ = creator; + a->context_ = p->h->context; + a->h_ = NULL; a->next_ = NULL; a->previous_ = NULL; - a->parent = p; - a->length = 0; - a->offset = 0; - a->flags = creator->flags; - a->set = creator->set; + a->parent_ = p; + a->length_ = 0; + a->offset_ = 0; + a->flags_ = creator->flags; + a->set_ = creator->set; if (p->block->last) { - a->offset = p->block->last->get_next_position_offset(); + a->offset_ = p->block->last->get_next_position_offset(); //printf("offset: p->block->last %s %s %ld %ld\n", // p->block->last->cclass->name, @@ -169,13 +173,13 @@ grib_accessor* grib_accessor_factory(grib_section* p, grib_action* creator, } else { if (p->owner) { - a->offset = p->owner->offset; + a->offset_ = p->owner->offset_; } else - a->offset = 0; + a->offset_ = 0; } - a->cclass = c; + //a->cclass_ = c; a->init_accessor(len, params); size = a->get_next_position_offset(); @@ -185,9 +189,9 @@ grib_accessor* grib_accessor_factory(grib_section* p, grib_action* creator, if (!p->h->partial) grib_context_log(p->h->context, GRIB_LOG_ERROR, "Creating (%s)%s of %s at offset %ld-%ld over message boundary (%lu)", - p->owner ? p->owner->name : "", a->name, - creator->op, a->offset, - a->offset + a->length, + p->owner ? p->owner->name_ : "", a->name_, + creator->op, a->offset_, + a->offset_ + a->length_, p->h->buffer->ulength); a->destroy(p->h->context); @@ -196,7 +200,7 @@ grib_accessor* grib_accessor_factory(grib_section* p, grib_action* creator, else { grib_context_log(p->h->context, GRIB_LOG_DEBUG, "CREATE: name=%s class=%s offset=%ld length=%ld action=", - a->name, a->cclass->name, a->offset, a->length); + a->name_, a->class_name_, a->offset_, a->length_); grib_grow_buffer(p->h->context, p->h->buffer, size); p->h->buffer->ulength = size; @@ -207,11 +211,11 @@ grib_accessor* grib_accessor_factory(grib_section* p, grib_action* creator, if (p->owner) grib_context_log(p->h->context, GRIB_LOG_DEBUG, "Creating (%s)%s of %s at offset %d [len=%d]", - p->owner->name, a->name, creator->op, a->offset, len, p->block); + p->owner->name_, a->name_, creator->op, a->offset_, len, p->block); else grib_context_log(p->h->context, GRIB_LOG_DEBUG, "Creating root %s of %s at offset %d [len=%d]", - a->name, creator->op, a->offset, len, p->block); + a->name_, creator->op, a->offset_, len, p->block); } return a; @@ -226,10 +230,10 @@ static void link_same_attributes(grib_accessor* a, grib_accessor* b) return; if (!b->has_attributes()) return; - while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { - bAttribute = b->get_attribute_index(a->attributes[i]->name, &idx); + while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes_[i]) { + bAttribute = b->get_attribute_index(a->attributes_[i]->name_, &idx); if (bAttribute) - a->attributes[i]->same = bAttribute; + a->attributes_[i]->same_ = bAttribute; i++; } } @@ -247,19 +251,20 @@ void grib_push_accessor(grib_accessor* a, grib_block_of_accessors* l) l->last = a; if (hand->use_trie) { - DEBUG_ASSERT( a->all_names[0] ); - if (*(a->all_names[0]) != '_') { - id = grib_hash_keys_get_id(a->context->keys, a->all_names[0]); + DEBUG_ASSERT( a->all_names_[0] ); + if (*(a->all_names_[0]) != '_') { + id = grib_hash_keys_get_id(a->context_->keys, a->all_names_[0]); DEBUG_ASSERT(id >= 0 && id < ACCESSORS_ARRAY_SIZE); - a->same = hand->accessors[id]; - link_same_attributes(a, a->same); + a->same_ = hand->accessors[id]; + link_same_attributes(a, a->same_); hand->accessors[id] = a; - if (a->same == a) { - fprintf(stderr, "---> %s\n", a->name); - Assert(a->same != a); + + if (a->same_ && (a->same_ == a)) { + fprintf(stderr, "---> %s\n", a->name_); + Assert(a->same_ != a); } } } @@ -270,11 +275,12 @@ void grib_section_post_init(grib_section* s) grib_accessor* a = s ? s->block->first : NULL; while (a) { - grib_accessor_class* c = a->cclass; - c->post_init(a); + //grib_accessor_class* c = a->cclass; + //c->post_init(a); + a->post_init(); - if (a->sub_section) - grib_section_post_init(a->sub_section); + if (a->sub_section_) + grib_section_post_init(a->sub_section_); a = a->next_; } } @@ -284,25 +290,25 @@ int grib_section_adjust_sizes(grib_section* s, int update, int depth) int err = 0; grib_accessor* a = s ? s->block->first : NULL; size_t length = update ? 0 : (s ? s->padding : 0); - size_t offset = (s && s->owner) ? s->owner->offset : 0; + size_t offset = (s && s->owner) ? s->owner->offset_ : 0; int force_update = update > 1; while (a) { long l; /* grib_section_adjust_sizes(grib_get_sub_section(a),update,depth+1); */ - err = grib_section_adjust_sizes(a->sub_section, update, depth + 1); + err = grib_section_adjust_sizes(a->sub_section_, update, depth + 1); if (err) return err; /*grib_context_log(a->context,GRIB_LOG_DEBUG,"grib_section_adjust_sizes: %s %ld [len=%ld] (depth=%d)",a->name,(long)a->offset,(long)a->length,depth);*/ - l = a->length; + l = a->length_; - if (offset != a->offset) { - grib_context_log(a->context, GRIB_LOG_ERROR, + if (offset != a->offset_) { + grib_context_log(a->context_, GRIB_LOG_ERROR, "Offset mismatch accessor=%s: accessor's offset=%ld, but actual offset=%ld", - a->name, (long)a->offset, (long)offset); - grib_context_log(a->context, GRIB_LOG_ERROR, "Hint: Check section lengths are in sync with their contents"); - a->offset = offset; + a->name_, (long)a->offset_, (long)offset); + grib_context_log(a->context_, GRIB_LOG_ERROR, "Hint: Check section lengths are in sync with their contents"); + a->offset_ = offset; return GRIB_DECODING_ERROR; } length += l; @@ -330,7 +336,7 @@ int grib_section_adjust_sizes(grib_section* s, int update, int depth) if (length >= plen) { if (s->owner) { grib_context_log(s->h->context, GRIB_LOG_ERROR, "Invalid size %ld found for %s, assuming %ld", - (long)plen, s->owner->name, (long)length); + (long)plen, s->owner->name_, (long)length); } plen = length; } @@ -343,7 +349,7 @@ int grib_section_adjust_sizes(grib_section* s, int update, int depth) if (s->owner) { /*grib_context_log(s->owner->context,GRIB_LOG_DEBUG,"grib_section_adjust_sizes: updating owner (%s->length old=%ld new=%ld)",s->owner->name,(long)s->owner->length,(long)length);*/ - s->owner->length = length; + s->owner->length_ = length; } s->length = length; } @@ -394,11 +400,11 @@ grib_accessor* find_paddings(grib_section* s) while (a) { /* grib_accessor* p = find_paddings(grib_get_sub_section(a)); */ - grib_accessor* p = find_paddings(a->sub_section); + grib_accessor* p = find_paddings(a->sub_section_); if (p) return p; - if (a->preferred_size(0) != a->length) + if (a->preferred_size(0) != a->length_) return a; a = a->next_; diff --git a/src/grib_accessor_class.h b/src/grib_accessor_class.h index a3ddf6b21..edf01f1a2 100644 --- a/src/grib_accessor_class.h +++ b/src/grib_accessor_class.h @@ -1,208 +1,208 @@ #include "grib_api_internal.h" -extern grib_accessor_class* grib_accessor_class_abstract_long_vector; -extern grib_accessor_class* grib_accessor_class_abstract_vector; -extern grib_accessor_class* grib_accessor_class_ascii; -extern grib_accessor_class* grib_accessor_class_bit; -extern grib_accessor_class* grib_accessor_class_bitmap; -extern grib_accessor_class* grib_accessor_class_bits; -extern grib_accessor_class* grib_accessor_class_bits_per_value; -extern grib_accessor_class* grib_accessor_class_blob; -extern grib_accessor_class* grib_accessor_class_budgdate; -extern grib_accessor_class* grib_accessor_class_bufr_data_array; -extern grib_accessor_class* grib_accessor_class_bufr_data_element; -extern grib_accessor_class* grib_accessor_class_bufr_elements_table; -extern grib_accessor_class* grib_accessor_class_bufr_extract_area_subsets; -extern grib_accessor_class* grib_accessor_class_bufr_extract_datetime_subsets; -extern grib_accessor_class* grib_accessor_class_bufr_extract_subsets; -extern grib_accessor_class* grib_accessor_class_bufr_group; -extern grib_accessor_class* grib_accessor_class_bufr_simple_thinning; -extern grib_accessor_class* grib_accessor_class_bufr_string_values; -extern grib_accessor_class* grib_accessor_class_bufrdc_expanded_descriptors; -extern grib_accessor_class* grib_accessor_class_bytes; -extern grib_accessor_class* grib_accessor_class_cf_var_name; -extern grib_accessor_class* grib_accessor_class_change_alternative_row_scanning; -extern grib_accessor_class* grib_accessor_class_change_scanning_direction; -extern grib_accessor_class* grib_accessor_class_check_internal_version; -extern grib_accessor_class* grib_accessor_class_closest_date; -extern grib_accessor_class* grib_accessor_class_codeflag; -extern grib_accessor_class* grib_accessor_class_codetable; -extern grib_accessor_class* grib_accessor_class_codetable_title; -extern grib_accessor_class* grib_accessor_class_codetable_units; -extern grib_accessor_class* grib_accessor_class_concept; -extern grib_accessor_class* grib_accessor_class_constant; -extern grib_accessor_class* grib_accessor_class_count_file; -extern grib_accessor_class* grib_accessor_class_count_missing; -extern grib_accessor_class* grib_accessor_class_count_total; -extern grib_accessor_class* grib_accessor_class_data_apply_bitmap; -extern grib_accessor_class* grib_accessor_class_data_apply_boustrophedonic; -extern grib_accessor_class* grib_accessor_class_data_apply_boustrophedonic_bitmap; -extern grib_accessor_class* grib_accessor_class_data_ccsds_packing; -extern grib_accessor_class* grib_accessor_class_data_complex_packing; -extern grib_accessor_class* grib_accessor_class_data_dummy_field; -extern grib_accessor_class* grib_accessor_class_data_g1complex_packing; -extern grib_accessor_class* grib_accessor_class_data_g1second_order_constant_width_packing; -extern grib_accessor_class* grib_accessor_class_data_g1second_order_general_extended_packing; -extern grib_accessor_class* grib_accessor_class_data_g1second_order_general_packing; -extern grib_accessor_class* grib_accessor_class_data_g1second_order_row_by_row_packing; -extern grib_accessor_class* grib_accessor_class_data_g1secondary_bitmap; -extern grib_accessor_class* grib_accessor_class_data_g1shsimple_packing; -extern grib_accessor_class* grib_accessor_class_data_g1simple_packing; -extern grib_accessor_class* grib_accessor_class_data_g22order_packing; -extern grib_accessor_class* grib_accessor_class_data_g2bifourier_packing; -extern grib_accessor_class* grib_accessor_class_data_g2complex_packing; -extern grib_accessor_class* grib_accessor_class_data_g2secondary_bitmap; -extern grib_accessor_class* grib_accessor_class_data_g2shsimple_packing; -extern grib_accessor_class* grib_accessor_class_data_g2simple_packing; -extern grib_accessor_class* grib_accessor_class_data_g2simple_packing_with_preprocessing; -extern grib_accessor_class* grib_accessor_class_data_jpeg2000_packing; -extern grib_accessor_class* grib_accessor_class_data_png_packing; -extern grib_accessor_class* grib_accessor_class_data_raw_packing; -extern grib_accessor_class* grib_accessor_class_data_run_length_packing; -extern grib_accessor_class* grib_accessor_class_data_secondary_bitmap; -extern grib_accessor_class* grib_accessor_class_data_sh_packed; -extern grib_accessor_class* grib_accessor_class_data_sh_unpacked; -extern grib_accessor_class* grib_accessor_class_data_shsimple_packing; -extern grib_accessor_class* grib_accessor_class_data_simple_packing; -extern grib_accessor_class* grib_accessor_class_decimal_precision; -extern grib_accessor_class* grib_accessor_class_dictionary; -extern grib_accessor_class* grib_accessor_class_dirty; -extern grib_accessor_class* grib_accessor_class_divdouble; -extern grib_accessor_class* grib_accessor_class_double; -extern grib_accessor_class* grib_accessor_class_element; -extern grib_accessor_class* grib_accessor_class_evaluate; -extern grib_accessor_class* grib_accessor_class_expanded_descriptors; -extern grib_accessor_class* grib_accessor_class_from_scale_factor_scaled_value; -extern grib_accessor_class* grib_accessor_class_g1_half_byte_codeflag; -extern grib_accessor_class* grib_accessor_class_g1_message_length; -extern grib_accessor_class* grib_accessor_class_g1_section4_length; -extern grib_accessor_class* grib_accessor_class_g1bitmap; -extern grib_accessor_class* grib_accessor_class_g1date; -extern grib_accessor_class* grib_accessor_class_g1day_of_the_year_date; -extern grib_accessor_class* grib_accessor_class_g1end_of_interval_monthly; -extern grib_accessor_class* grib_accessor_class_g1fcperiod; -extern grib_accessor_class* grib_accessor_class_g1forecastmonth; -extern grib_accessor_class* grib_accessor_class_g1monthlydate; -extern grib_accessor_class* grib_accessor_class_g1number_of_coded_values_sh_complex; -extern grib_accessor_class* grib_accessor_class_g1number_of_coded_values_sh_simple; -extern grib_accessor_class* grib_accessor_class_g1step_range; -extern grib_accessor_class* grib_accessor_class_g1verificationdate; -extern grib_accessor_class* grib_accessor_class_g2_aerosol; -extern grib_accessor_class* grib_accessor_class_g2_chemical; -extern grib_accessor_class* grib_accessor_class_g2_eps; -extern grib_accessor_class* grib_accessor_class_g2_mars_labeling; -extern grib_accessor_class* grib_accessor_class_g2bitmap; -extern grib_accessor_class* grib_accessor_class_g2bitmap_present; -extern grib_accessor_class* grib_accessor_class_g2date; -extern grib_accessor_class* grib_accessor_class_g2end_step; -extern grib_accessor_class* grib_accessor_class_g2grid; -extern grib_accessor_class* grib_accessor_class_g2latlon; -extern grib_accessor_class* grib_accessor_class_g2level; -extern grib_accessor_class* grib_accessor_class_g2lon; -extern grib_accessor_class* grib_accessor_class_g2step_range; -extern grib_accessor_class* grib_accessor_class_gaussian_grid_name; -extern grib_accessor_class* grib_accessor_class_gds_is_present; -extern grib_accessor_class* grib_accessor_class_gds_not_present_bitmap; -extern grib_accessor_class* grib_accessor_class_gen; -extern grib_accessor_class* grib_accessor_class_getenv; -extern grib_accessor_class* grib_accessor_class_global_gaussian; -extern grib_accessor_class* grib_accessor_class_group; -extern grib_accessor_class* grib_accessor_class_group_copy; -extern grib_accessor_class* grib_accessor_class_gts_header; -extern grib_accessor_class* grib_accessor_class_hash_array; -extern grib_accessor_class* grib_accessor_class_headers_only; -extern grib_accessor_class* grib_accessor_class_ibmfloat; -extern grib_accessor_class* grib_accessor_class_ieeefloat; -extern grib_accessor_class* grib_accessor_class_ifs_param; -extern grib_accessor_class* grib_accessor_class_iterator; -extern grib_accessor_class* grib_accessor_class_julian_date; -extern grib_accessor_class* grib_accessor_class_julian_day; -extern grib_accessor_class* grib_accessor_class_ksec1expver; -extern grib_accessor_class* grib_accessor_class_label; -extern grib_accessor_class* grib_accessor_class_latitudes; -extern grib_accessor_class* grib_accessor_class_latlon_increment; -extern grib_accessor_class* grib_accessor_class_latlonvalues; -extern grib_accessor_class* grib_accessor_class_library_version; -extern grib_accessor_class* grib_accessor_class_local_definition; -extern grib_accessor_class* grib_accessor_class_long; -extern grib_accessor_class* grib_accessor_class_long_vector; -extern grib_accessor_class* grib_accessor_class_longitudes; -extern grib_accessor_class* grib_accessor_class_lookup; -extern grib_accessor_class* grib_accessor_class_mars_param; -extern grib_accessor_class* grib_accessor_class_mars_step; -extern grib_accessor_class* grib_accessor_class_md5; -extern grib_accessor_class* grib_accessor_class_message; -extern grib_accessor_class* grib_accessor_class_message_copy; -extern grib_accessor_class* grib_accessor_class_multdouble; -extern grib_accessor_class* grib_accessor_class_nearest; -extern grib_accessor_class* grib_accessor_class_non_alpha; -extern grib_accessor_class* grib_accessor_class_number_of_coded_values; -extern grib_accessor_class* grib_accessor_class_number_of_points; -extern grib_accessor_class* grib_accessor_class_number_of_points_gaussian; -extern grib_accessor_class* grib_accessor_class_number_of_values; -extern grib_accessor_class* grib_accessor_class_number_of_values_data_raw_packing; -extern grib_accessor_class* grib_accessor_class_octahedral_gaussian; -extern grib_accessor_class* grib_accessor_class_octet_number; -extern grib_accessor_class* grib_accessor_class_offset_file; -extern grib_accessor_class* grib_accessor_class_offset_values; -extern grib_accessor_class* grib_accessor_class_optimal_step_units; -extern grib_accessor_class* grib_accessor_class_pack_bufr_values; -extern grib_accessor_class* grib_accessor_class_packing_type; -extern grib_accessor_class* grib_accessor_class_pad; -extern grib_accessor_class* grib_accessor_class_padding; -extern grib_accessor_class* grib_accessor_class_padto; -extern grib_accessor_class* grib_accessor_class_padtoeven; -extern grib_accessor_class* grib_accessor_class_padtomultiple; -extern grib_accessor_class* grib_accessor_class_position; -extern grib_accessor_class* grib_accessor_class_proj_string; -extern grib_accessor_class* grib_accessor_class_raw; -extern grib_accessor_class* grib_accessor_class_rdbtime_guess_date; -extern grib_accessor_class* grib_accessor_class_reference_value_error; -extern grib_accessor_class* grib_accessor_class_round; -extern grib_accessor_class* grib_accessor_class_scale; -extern grib_accessor_class* grib_accessor_class_scale_values; -extern grib_accessor_class* grib_accessor_class_second_order_bits_per_value; -extern grib_accessor_class* grib_accessor_class_section; -extern grib_accessor_class* grib_accessor_class_section_length; -extern grib_accessor_class* grib_accessor_class_section_padding; -extern grib_accessor_class* grib_accessor_class_section_pointer; -extern grib_accessor_class* grib_accessor_class_select_step_template; -extern grib_accessor_class* grib_accessor_class_sexagesimal2decimal; -extern grib_accessor_class* grib_accessor_class_signed; -extern grib_accessor_class* grib_accessor_class_signed_bits; -extern grib_accessor_class* grib_accessor_class_simple_packing_error; -extern grib_accessor_class* grib_accessor_class_size; -extern grib_accessor_class* grib_accessor_class_smart_table; -extern grib_accessor_class* grib_accessor_class_smart_table_column; -extern grib_accessor_class* grib_accessor_class_spd; -extern grib_accessor_class* grib_accessor_class_spectral_truncation; -extern grib_accessor_class* grib_accessor_class_sprintf; -extern grib_accessor_class* grib_accessor_class_statistics; -extern grib_accessor_class* grib_accessor_class_statistics_spectral; -extern grib_accessor_class* grib_accessor_class_step_human_readable; -extern grib_accessor_class* grib_accessor_class_step_in_units; -extern grib_accessor_class* grib_accessor_class_sum; -extern grib_accessor_class* grib_accessor_class_suppressed; -extern grib_accessor_class* grib_accessor_class_time; -extern grib_accessor_class* grib_accessor_class_to_double; -extern grib_accessor_class* grib_accessor_class_to_integer; -extern grib_accessor_class* grib_accessor_class_to_string; -extern grib_accessor_class* grib_accessor_class_transient; -extern grib_accessor_class* grib_accessor_class_transient_darray; -extern grib_accessor_class* grib_accessor_class_trim; -extern grib_accessor_class* grib_accessor_class_uint16; -extern grib_accessor_class* grib_accessor_class_uint32; -extern grib_accessor_class* grib_accessor_class_uint32_little_endian; -extern grib_accessor_class* grib_accessor_class_uint64; -extern grib_accessor_class* grib_accessor_class_uint64_little_endian; -extern grib_accessor_class* grib_accessor_class_uint8; -extern grib_accessor_class* grib_accessor_class_unexpanded_descriptors; -extern grib_accessor_class* grib_accessor_class_unpack_bufr_values; -extern grib_accessor_class* grib_accessor_class_unsigned; -extern grib_accessor_class* grib_accessor_class_unsigned_bits; -extern grib_accessor_class* grib_accessor_class_validity_date; -extern grib_accessor_class* grib_accessor_class_validity_time; -extern grib_accessor_class* grib_accessor_class_values; -extern grib_accessor_class* grib_accessor_class_variable; -extern grib_accessor_class* grib_accessor_class_vector; -extern grib_accessor_class* grib_accessor_class_when; +extern grib_accessor* grib_accessor_abstract_long_vector; +extern grib_accessor* grib_accessor_abstract_vector; +extern grib_accessor* grib_accessor_ascii; +extern grib_accessor* grib_accessor_bit; +extern grib_accessor* grib_accessor_bitmap; +extern grib_accessor* grib_accessor_bits; +extern grib_accessor* grib_accessor_bits_per_value; +extern grib_accessor* grib_accessor_blob; +extern grib_accessor* grib_accessor_budgdate; +extern grib_accessor* grib_accessor_bufr_data_array; +extern grib_accessor* grib_accessor_bufr_data_element; +extern grib_accessor* grib_accessor_bufr_elements_table; +extern grib_accessor* grib_accessor_bufr_extract_area_subsets; +extern grib_accessor* grib_accessor_bufr_extract_datetime_subsets; +extern grib_accessor* grib_accessor_bufr_extract_subsets; +extern grib_accessor* grib_accessor_bufr_group; +extern grib_accessor* grib_accessor_bufr_simple_thinning; +extern grib_accessor* grib_accessor_bufr_string_values; +extern grib_accessor* grib_accessor_bufrdc_expanded_descriptors; +extern grib_accessor* grib_accessor_bytes; +extern grib_accessor* grib_accessor_change_alternative_row_scanning; +extern grib_accessor* grib_accessor_change_scanning_direction; +extern grib_accessor* grib_accessor_check_internal_version; +extern grib_accessor* grib_accessor_closest_date; +extern grib_accessor* grib_accessor_codeflag; +extern grib_accessor* grib_accessor_codetable; +extern grib_accessor* grib_accessor_codetable_title; +extern grib_accessor* grib_accessor_codetable_units; +extern grib_accessor* grib_accessor_concept; +extern grib_accessor* grib_accessor_constant; +extern grib_accessor* grib_accessor_count_file; +extern grib_accessor* grib_accessor_count_missing; +extern grib_accessor* grib_accessor_count_total; +extern grib_accessor* grib_accessor_data_apply_bitmap; +extern grib_accessor* grib_accessor_data_apply_boustrophedonic; +extern grib_accessor* grib_accessor_data_apply_boustrophedonic_bitmap; +extern grib_accessor* grib_accessor_data_ccsds_packing; +extern grib_accessor* grib_accessor_data_complex_packing; +extern grib_accessor* grib_accessor_data_dummy_field; +extern grib_accessor* grib_accessor_data_g1complex_packing; +extern grib_accessor* grib_accessor_data_g1second_order_constant_width_packing; +extern grib_accessor* grib_accessor_data_g1second_order_general_extended_packing; +extern grib_accessor* grib_accessor_data_g1second_order_general_packing; +extern grib_accessor* grib_accessor_data_g1second_order_row_by_row_packing; +extern grib_accessor* grib_accessor_data_g1secondary_bitmap; +extern grib_accessor* grib_accessor_data_g1shsimple_packing; +extern grib_accessor* grib_accessor_data_g1simple_packing; +extern grib_accessor* grib_accessor_data_g22order_packing; +extern grib_accessor* grib_accessor_data_g2bifourier_packing; +extern grib_accessor* grib_accessor_data_g2complex_packing; +extern grib_accessor* grib_accessor_data_g2secondary_bitmap; +extern grib_accessor* grib_accessor_data_g2shsimple_packing; +extern grib_accessor* grib_accessor_data_g2simple_packing; +extern grib_accessor* grib_accessor_data_g2simple_packing_with_preprocessing; +extern grib_accessor* grib_accessor_data_jpeg2000_packing; +extern grib_accessor* grib_accessor_data_png_packing; +extern grib_accessor* grib_accessor_data_raw_packing; +extern grib_accessor* grib_accessor_data_run_length_packing; +extern grib_accessor* grib_accessor_data_secondary_bitmap; +extern grib_accessor* grib_accessor_data_sh_packed; +extern grib_accessor* grib_accessor_data_sh_unpacked; +extern grib_accessor* grib_accessor_data_shsimple_packing; +extern grib_accessor* grib_accessor_data_simple_packing; +extern grib_accessor* grib_accessor_decimal_precision; +extern grib_accessor* grib_accessor_dictionary; +extern grib_accessor* grib_accessor_dirty; +extern grib_accessor* grib_accessor_divdouble; +extern grib_accessor* grib_accessor_double; +extern grib_accessor* grib_accessor_element; +extern grib_accessor* grib_accessor_evaluate; +extern grib_accessor* grib_accessor_expanded_descriptors; +extern grib_accessor* grib_accessor_from_scale_factor_scaled_value; +extern grib_accessor* grib_accessor_g1_half_byte_codeflag; +extern grib_accessor* grib_accessor_g1_message_length; +extern grib_accessor* grib_accessor_g1_section4_length; +extern grib_accessor* grib_accessor_g1bitmap; +extern grib_accessor* grib_accessor_g1date; +extern grib_accessor* grib_accessor_g1day_of_the_year_date; +extern grib_accessor* grib_accessor_g1end_of_interval_monthly; +extern grib_accessor* grib_accessor_g1fcperiod; +extern grib_accessor* grib_accessor_g1forecastmonth; +extern grib_accessor* grib_accessor_g1monthlydate; +extern grib_accessor* grib_accessor_g1number_of_coded_values_sh_complex; +extern grib_accessor* grib_accessor_g1number_of_coded_values_sh_simple; +extern grib_accessor* grib_accessor_g1step_range; +extern grib_accessor* grib_accessor_g1verificationdate; +extern grib_accessor* grib_accessor_g2_aerosol; +extern grib_accessor* grib_accessor_g2_chemical; +extern grib_accessor* grib_accessor_g2_eps; +extern grib_accessor* grib_accessor_g2_mars_labeling; +extern grib_accessor* grib_accessor_g2bitmap; +extern grib_accessor* grib_accessor_g2bitmap_present; +extern grib_accessor* grib_accessor_g2date; +extern grib_accessor* grib_accessor_g2end_step; +extern grib_accessor* grib_accessor_g2grid; +extern grib_accessor* grib_accessor_g2latlon; +extern grib_accessor* grib_accessor_g2level; +extern grib_accessor* grib_accessor_g2lon; +extern grib_accessor* grib_accessor_g2step_range; +extern grib_accessor* grib_accessor_gaussian_grid_name; +extern grib_accessor* grib_accessor_gds_is_present; +extern grib_accessor* grib_accessor_gds_not_present_bitmap; +extern grib_accessor* grib_accessor_gen; +extern grib_accessor* grib_accessor_getenv; +extern grib_accessor* grib_accessor_global_gaussian; +extern grib_accessor* grib_accessor_group; +extern grib_accessor* grib_accessor_group_copy; +extern grib_accessor* grib_accessor_gts_header; +extern grib_accessor* grib_accessor_hash_array; +extern grib_accessor* grib_accessor_headers_only; +extern grib_accessor* grib_accessor_ibmfloat; +extern grib_accessor* grib_accessor_ieeefloat; +extern grib_accessor* grib_accessor_ifs_param; +extern grib_accessor* grib_accessor_iterator; +extern grib_accessor* grib_accessor_julian_date; +extern grib_accessor* grib_accessor_julian_day; +extern grib_accessor* grib_accessor_ksec1expver; +extern grib_accessor* grib_accessor_label; +extern grib_accessor* grib_accessor_latitudes; +extern grib_accessor* grib_accessor_latlon_increment; +extern grib_accessor* grib_accessor_latlonvalues; +extern grib_accessor* grib_accessor_library_version; +extern grib_accessor* grib_accessor_local_definition; +extern grib_accessor* grib_accessor_long; +extern grib_accessor* grib_accessor_long_vector; +extern grib_accessor* grib_accessor_longitudes; +extern grib_accessor* grib_accessor_lookup; +extern grib_accessor* grib_accessor_mars_param; +extern grib_accessor* grib_accessor_mars_step; +extern grib_accessor* grib_accessor_md5; +extern grib_accessor* grib_accessor_message; +extern grib_accessor* grib_accessor_message_copy; +extern grib_accessor* grib_accessor_multdouble; +extern grib_accessor* grib_accessor_nearest; +extern grib_accessor* grib_accessor_non_alpha; +extern grib_accessor* grib_accessor_number_of_coded_values; +extern grib_accessor* grib_accessor_number_of_points; +extern grib_accessor* grib_accessor_number_of_points_gaussian; +extern grib_accessor* grib_accessor_number_of_values; +extern grib_accessor* grib_accessor_number_of_values_data_raw_packing; +extern grib_accessor* grib_accessor_octahedral_gaussian; +extern grib_accessor* grib_accessor_octet_number; +extern grib_accessor* grib_accessor_offset_file; +extern grib_accessor* grib_accessor_offset_values; +extern grib_accessor* grib_accessor_optimal_step_units; +extern grib_accessor* grib_accessor_pack_bufr_values; +extern grib_accessor* grib_accessor_packing_type; +extern grib_accessor* grib_accessor_pad; +extern grib_accessor* grib_accessor_padding; +extern grib_accessor* grib_accessor_padto; +extern grib_accessor* grib_accessor_padtoeven; +extern grib_accessor* grib_accessor_padtomultiple; +extern grib_accessor* grib_accessor_position; +extern grib_accessor* grib_accessor_proj_string; +extern grib_accessor* grib_accessor_raw; +extern grib_accessor* grib_accessor_rdbtime_guess_date; +extern grib_accessor* grib_accessor_reference_value_error; +extern grib_accessor* grib_accessor_round; +extern grib_accessor* grib_accessor_scale; +extern grib_accessor* grib_accessor_scale_values; +extern grib_accessor* grib_accessor_second_order_bits_per_value; +extern grib_accessor* grib_accessor_section; +extern grib_accessor* grib_accessor_section_length; +extern grib_accessor* grib_accessor_section_padding; +extern grib_accessor* grib_accessor_section_pointer; +extern grib_accessor* grib_accessor_select_step_template; +extern grib_accessor* grib_accessor_sexagesimal2decimal; +extern grib_accessor* grib_accessor_signed; +extern grib_accessor* grib_accessor_signed_bits; +extern grib_accessor* grib_accessor_simple_packing_error; +extern grib_accessor* grib_accessor_size; +extern grib_accessor* grib_accessor_smart_table; +extern grib_accessor* grib_accessor_smart_table_column; +extern grib_accessor* grib_accessor_spd; +extern grib_accessor* grib_accessor_spectral_truncation; +extern grib_accessor* grib_accessor_sprintf; +extern grib_accessor* grib_accessor_statistics; +extern grib_accessor* grib_accessor_statistics_spectral; +extern grib_accessor* grib_accessor_step_human_readable; +extern grib_accessor* grib_accessor_step_in_units; +extern grib_accessor* grib_accessor_sum; +extern grib_accessor* grib_accessor_suppressed; +extern grib_accessor* grib_accessor_time; +extern grib_accessor* grib_accessor_to_double; +extern grib_accessor* grib_accessor_to_integer; +extern grib_accessor* grib_accessor_to_string; +extern grib_accessor* grib_accessor_transient; +extern grib_accessor* grib_accessor_transient_darray; +extern grib_accessor* grib_accessor_trim; +extern grib_accessor* grib_accessor_uint16; +extern grib_accessor* grib_accessor_uint32; +extern grib_accessor* grib_accessor_uint32_little_endian; +extern grib_accessor* grib_accessor_uint64; +extern grib_accessor* grib_accessor_uint64_little_endian; +extern grib_accessor* grib_accessor_uint8; +extern grib_accessor* grib_accessor_unexpanded_descriptors; +extern grib_accessor* grib_accessor_unpack_bufr_values; +extern grib_accessor* grib_accessor_unsigned; +extern grib_accessor* grib_accessor_unsigned_bits; +extern grib_accessor* grib_accessor_validity_date; +extern grib_accessor* grib_accessor_validity_time; +extern grib_accessor* grib_accessor_values; +extern grib_accessor* grib_accessor_variable; +extern grib_accessor* grib_accessor_vector; +extern grib_accessor* grib_accessor_when; +extern grib_accessor* grib_accessor_cf_var_name; diff --git a/src/grib_accessor_classes_hash.cc b/src/grib_accessor_classes_hash.cc index d9e78851b..ec9a693c1 100644 --- a/src/grib_accessor_classes_hash.cc +++ b/src/grib_accessor_classes_hash.cc @@ -1,5 +1,5 @@ /* ANSI-C code produced by gperf version 3.1 */ -/* Command-line: gperf -C -W classes -t -G -H grib_accessor_classes_get_id -N grib_accessor_classes_hash -m 1 -j 1 accessor_class_list.gperf */ +/* Command-line: gperf -C -W classes -t -G -H grib_accessor_classes_get_id -N grib_accessor_hash -m 1 -j 1 accessor_class_list.gperf */ /* Computed positions: -k'1-2,5,7,11' */ #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ @@ -35,7 +35,7 @@ #include "grib_accessor_class.h" #line 6 "accessor_class_list.gperf" -struct accessor_class_hash { const char *name; grib_accessor_class **cclass;}; +struct accessor_class_hash { const char *name; grib_accessor **cclass;}; #define TOTAL_KEYWORDS 206 #define MIN_WORD_LENGTH 1 @@ -51,7 +51,8 @@ struct accessor_class_hash { const char *name; grib_accessor_class **cclass;}; #endif #endif -static unsigned int grib_accessor_classes_get_id (const char *str, size_t len) +static unsigned int +grib_accessor_classes_get_id (const char *str, size_t len) { static const unsigned short asso_values[] = { @@ -117,530 +118,531 @@ static const struct accessor_class_hash classes[] = #line 9 "accessor_class_list.gperf" {" "}, {""}, {""}, {""}, {""}, -#line 180 "accessor_class_list.gperf" - {"size", &grib_accessor_class_size}, +#line 179 "accessor_class_list.gperf" + {"size", &grib_accessor_size}, #line 12 "accessor_class_list.gperf" - {"ascii", &grib_accessor_class_ascii}, -#line 177 "accessor_class_list.gperf" - {"signed", &grib_accessor_class_signed}, -#line 157 "accessor_class_list.gperf" - {"pad", &grib_accessor_class_pad}, -#line 183 "accessor_class_list.gperf" - {"spd", &grib_accessor_class_spd}, - {""}, {""}, {""}, -#line 178 "accessor_class_list.gperf" - {"signed_bits", &grib_accessor_class_signed_bits}, - {""}, -#line 67 "accessor_class_list.gperf" - {"data_raw_packing", &grib_accessor_class_data_raw_packing}, -#line 76 "accessor_class_list.gperf" - {"dirty", &grib_accessor_class_dirty}, - {""}, {""}, -#line 73 "accessor_class_list.gperf" - {"data_simple_packing", &grib_accessor_class_data_simple_packing}, -#line 69 "accessor_class_list.gperf" - {"data_secondary_bitmap", &grib_accessor_class_data_secondary_bitmap}, -#line 171 "accessor_class_list.gperf" - {"section", &grib_accessor_class_section}, -#line 44 "accessor_class_list.gperf" - {"data_apply_bitmap", &grib_accessor_class_data_apply_bitmap}, - {""}, -#line 75 "accessor_class_list.gperf" - {"dictionary", &grib_accessor_class_dictionary}, - {""}, -#line 113 "accessor_class_list.gperf" - {"gen", &grib_accessor_class_gen}, -#line 65 "accessor_class_list.gperf" - {"data_jpeg2000_packing", &grib_accessor_class_data_jpeg2000_packing}, -#line 66 "accessor_class_list.gperf" - {"data_png_packing", &grib_accessor_class_data_png_packing}, -#line 173 "accessor_class_list.gperf" - {"section_padding", &grib_accessor_class_section_padding}, -#line 174 "accessor_class_list.gperf" - {"section_pointer", &grib_accessor_class_section_pointer}, -#line 45 "accessor_class_list.gperf" - {"data_apply_boustrophedonic", &grib_accessor_class_data_apply_boustrophedonic}, - {""}, {""}, {""}, {""}, {""}, -#line 158 "accessor_class_list.gperf" - {"padding", &grib_accessor_class_padding}, -#line 46 "accessor_class_list.gperf" - {"data_apply_boustrophedonic_bitmap", &grib_accessor_class_data_apply_boustrophedonic_bitmap}, -#line 111 "accessor_class_list.gperf" - {"gds_is_present", &grib_accessor_class_gds_is_present}, -#line 170 "accessor_class_list.gperf" - {"second_order_bits_per_value", &grib_accessor_class_second_order_bits_per_value}, -#line 172 "accessor_class_list.gperf" - {"section_length", &grib_accessor_class_section_length}, -#line 114 "accessor_class_list.gperf" - {"getenv", &grib_accessor_class_getenv}, -#line 58 "accessor_class_list.gperf" - {"data_g22order_packing", &grib_accessor_class_data_g22order_packing}, -#line 192 "accessor_class_list.gperf" - {"time", &grib_accessor_class_time}, - {""}, -#line 62 "accessor_class_list.gperf" - {"data_g2shsimple_packing", &grib_accessor_class_data_g2shsimple_packing}, - {""}, + {"ascii", &grib_accessor_ascii}, +#line 176 "accessor_class_list.gperf" + {"signed", &grib_accessor_signed}, #line 156 "accessor_class_list.gperf" - {"packing_type", &grib_accessor_class_packing_type}, -#line 63 "accessor_class_list.gperf" - {"data_g2simple_packing", &grib_accessor_class_data_g2simple_packing}, -#line 60 "accessor_class_list.gperf" - {"data_g2complex_packing", &grib_accessor_class_data_g2complex_packing}, - {""}, {""}, -#line 105 "accessor_class_list.gperf" - {"g2grid", &grib_accessor_class_g2grid}, + {"pad", &grib_accessor_pad}, +#line 182 "accessor_class_list.gperf" + {"spd", &grib_accessor_spd}, {""}, {""}, {""}, -#line 104 "accessor_class_list.gperf" - {"g2end_step", &grib_accessor_class_g2end_step}, -#line 99 "accessor_class_list.gperf" - {"g2_eps", &grib_accessor_class_g2_eps}, -#line 143 "accessor_class_list.gperf" - {"nearest", &grib_accessor_class_nearest}, -#line 81 "accessor_class_list.gperf" - {"expanded_descriptors", &grib_accessor_class_expanded_descriptors}, -#line 159 "accessor_class_list.gperf" - {"padto", &grib_accessor_class_padto}, -#line 190 "accessor_class_list.gperf" - {"sum", &grib_accessor_class_sum}, +#line 177 "accessor_class_list.gperf" + {"signed_bits", &grib_accessor_signed_bits}, {""}, -#line 108 "accessor_class_list.gperf" - {"g2lon", &grib_accessor_class_g2lon}, -#line 204 "accessor_class_list.gperf" - {"uint8", &grib_accessor_class_uint8}, - {""}, -#line 189 "accessor_class_list.gperf" - {"step_in_units", &grib_accessor_class_step_in_units}, -#line 64 "accessor_class_list.gperf" - {"data_g2simple_packing_with_preprocessing", &grib_accessor_class_data_g2simple_packing_with_preprocessing}, -#line 202 "accessor_class_list.gperf" - {"uint64", &grib_accessor_class_uint64}, -#line 48 "accessor_class_list.gperf" - {"data_complex_packing", &grib_accessor_class_data_complex_packing}, -#line 200 "accessor_class_list.gperf" - {"uint32", &grib_accessor_class_uint32}, -#line 13 "accessor_class_list.gperf" - {"bit", &grib_accessor_class_bit}, -#line 15 "accessor_class_list.gperf" - {"bits", &grib_accessor_class_bits}, -#line 49 "accessor_class_list.gperf" - {"data_dummy_field", &grib_accessor_class_data_dummy_field}, -#line 14 "accessor_class_list.gperf" - {"bitmap", &grib_accessor_class_bitmap}, -#line 125 "accessor_class_list.gperf" - {"julian_day", &grib_accessor_class_julian_day}, -#line 124 "accessor_class_list.gperf" - {"julian_date", &grib_accessor_class_julian_date}, -#line 144 "accessor_class_list.gperf" - {"non_alpha", &grib_accessor_class_non_alpha}, +#line 66 "accessor_class_list.gperf" + {"data_raw_packing", &grib_accessor_data_raw_packing}, +#line 75 "accessor_class_list.gperf" + {"dirty", &grib_accessor_dirty}, {""}, {""}, +#line 72 "accessor_class_list.gperf" + {"data_simple_packing", &grib_accessor_data_simple_packing}, #line 68 "accessor_class_list.gperf" - {"data_run_length_packing", &grib_accessor_class_data_run_length_packing}, -#line 109 "accessor_class_list.gperf" - {"g2step_range", &grib_accessor_class_g2step_range}, -#line 16 "accessor_class_list.gperf" - {"bits_per_value", &grib_accessor_class_bits_per_value}, + {"data_secondary_bitmap", &grib_accessor_data_secondary_bitmap}, +#line 170 "accessor_class_list.gperf" + {"section", &grib_accessor_section}, +#line 43 "accessor_class_list.gperf" + {"data_apply_bitmap", &grib_accessor_data_apply_bitmap}, {""}, -#line 29 "accessor_class_list.gperf" - {"bytes", &grib_accessor_class_bytes}, - {""}, {""}, {""}, -#line 168 "accessor_class_list.gperf" - {"scale", &grib_accessor_class_scale}, +#line 74 "accessor_class_list.gperf" + {"dictionary", &grib_accessor_dictionary}, {""}, -#line 186 "accessor_class_list.gperf" - {"statistics", &grib_accessor_class_statistics}, -#line 103 "accessor_class_list.gperf" - {"g2date", &grib_accessor_class_g2date}, -#line 146 "accessor_class_list.gperf" - {"number_of_points", &grib_accessor_class_number_of_points}, -#line 101 "accessor_class_list.gperf" - {"g2bitmap", &grib_accessor_class_g2bitmap}, +#line 112 "accessor_class_list.gperf" + {"gen", &grib_accessor_gen}, +#line 64 "accessor_class_list.gperf" + {"data_jpeg2000_packing", &grib_accessor_data_jpeg2000_packing}, +#line 65 "accessor_class_list.gperf" + {"data_png_packing", &grib_accessor_data_png_packing}, +#line 172 "accessor_class_list.gperf" + {"section_padding", &grib_accessor_section_padding}, +#line 173 "accessor_class_list.gperf" + {"section_pointer", &grib_accessor_section_pointer}, +#line 44 "accessor_class_list.gperf" + {"data_apply_boustrophedonic", &grib_accessor_data_apply_boustrophedonic}, + {""}, {""}, {""}, {""}, {""}, +#line 157 "accessor_class_list.gperf" + {"padding", &grib_accessor_padding}, +#line 45 "accessor_class_list.gperf" + {"data_apply_boustrophedonic_bitmap", &grib_accessor_data_apply_boustrophedonic_bitmap}, +#line 110 "accessor_class_list.gperf" + {"gds_is_present", &grib_accessor_gds_is_present}, +#line 169 "accessor_class_list.gperf" + {"second_order_bits_per_value", &grib_accessor_second_order_bits_per_value}, +#line 171 "accessor_class_list.gperf" + {"section_length", &grib_accessor_section_length}, +#line 113 "accessor_class_list.gperf" + {"getenv", &grib_accessor_getenv}, +#line 57 "accessor_class_list.gperf" + {"data_g22order_packing", &grib_accessor_data_g22order_packing}, +#line 191 "accessor_class_list.gperf" + {"time", &grib_accessor_time}, {""}, #line 61 "accessor_class_list.gperf" - {"data_g2secondary_bitmap", &grib_accessor_class_data_g2secondary_bitmap}, + {"data_g2shsimple_packing", &grib_accessor_data_g2shsimple_packing}, + {""}, +#line 155 "accessor_class_list.gperf" + {"packing_type", &grib_accessor_packing_type}, +#line 62 "accessor_class_list.gperf" + {"data_g2simple_packing", &grib_accessor_data_g2simple_packing}, #line 59 "accessor_class_list.gperf" - {"data_g2bifourier_packing", &grib_accessor_class_data_g2bifourier_packing}, -#line 112 "accessor_class_list.gperf" - {"gds_not_present_bitmap", &grib_accessor_class_gds_not_present_bitmap}, -#line 123 "accessor_class_list.gperf" - {"iterator", &grib_accessor_class_iterator}, -#line 187 "accessor_class_list.gperf" - {"statistics_spectral", &grib_accessor_class_statistics_spectral}, -#line 47 "accessor_class_list.gperf" - {"data_ccsds_packing", &grib_accessor_class_data_ccsds_packing}, -#line 147 "accessor_class_list.gperf" - {"number_of_points_gaussian", &grib_accessor_class_number_of_points_gaussian}, -#line 207 "accessor_class_list.gperf" - {"unsigned", &grib_accessor_class_unsigned}, -#line 139 "accessor_class_list.gperf" - {"md5", &grib_accessor_class_md5}, + {"data_g2complex_packing", &grib_accessor_data_g2complex_packing}, {""}, {""}, -#line 97 "accessor_class_list.gperf" - {"g2_aerosol", &grib_accessor_class_g2_aerosol}, -#line 140 "accessor_class_list.gperf" - {"message", &grib_accessor_class_message}, -#line 208 "accessor_class_list.gperf" - {"unsigned_bits", &grib_accessor_class_unsigned_bits}, -#line 175 "accessor_class_list.gperf" - {"select_step_template", &grib_accessor_class_select_step_template}, -#line 137 "accessor_class_list.gperf" - {"mars_param", &grib_accessor_class_mars_param}, -#line 205 "accessor_class_list.gperf" - {"unexpanded_descriptors", &grib_accessor_class_unexpanded_descriptors}, -#line 194 "accessor_class_list.gperf" - {"to_integer", &grib_accessor_class_to_integer}, -#line 179 "accessor_class_list.gperf" - {"simple_packing_error", &grib_accessor_class_simple_packing_error}, +#line 104 "accessor_class_list.gperf" + {"g2grid", &grib_accessor_g2grid}, {""}, {""}, {""}, -#line 188 "accessor_class_list.gperf" - {"step_human_readable", &grib_accessor_class_step_human_readable}, -#line 141 "accessor_class_list.gperf" - {"message_copy", &grib_accessor_class_message_copy}, -#line 164 "accessor_class_list.gperf" - {"raw", &grib_accessor_class_raw}, - {""}, {""}, +#line 103 "accessor_class_list.gperf" + {"g2end_step", &grib_accessor_g2end_step}, +#line 98 "accessor_class_list.gperf" + {"g2_eps", &grib_accessor_g2_eps}, +#line 142 "accessor_class_list.gperf" + {"nearest", &grib_accessor_nearest}, +#line 80 "accessor_class_list.gperf" + {"expanded_descriptors", &grib_accessor_expanded_descriptors}, +#line 158 "accessor_class_list.gperf" + {"padto", &grib_accessor_padto}, +#line 189 "accessor_class_list.gperf" + {"sum", &grib_accessor_sum}, + {""}, +#line 107 "accessor_class_list.gperf" + {"g2lon", &grib_accessor_g2lon}, #line 203 "accessor_class_list.gperf" - {"uint64_little_endian", &grib_accessor_class_uint64_little_endian}, + {"uint8", &grib_accessor_uint8}, {""}, +#line 188 "accessor_class_list.gperf" + {"step_in_units", &grib_accessor_step_in_units}, +#line 63 "accessor_class_list.gperf" + {"data_g2simple_packing_with_preprocessing", &grib_accessor_data_g2simple_packing_with_preprocessing}, #line 201 "accessor_class_list.gperf" - {"uint32_little_endian", &grib_accessor_class_uint32_little_endian}, -#line 115 "accessor_class_list.gperf" - {"global_gaussian", &grib_accessor_class_global_gaussian}, - {""}, {""}, -#line 77 "accessor_class_list.gperf" - {"divdouble", &grib_accessor_class_divdouble}, - {""}, -#line 176 "accessor_class_list.gperf" - {"sexagesimal2decimal", &grib_accessor_class_sexagesimal2decimal}, -#line 100 "accessor_class_list.gperf" - {"g2_mars_labeling", &grib_accessor_class_g2_mars_labeling}, -#line 79 "accessor_class_list.gperf" - {"element", &grib_accessor_class_element}, -#line 161 "accessor_class_list.gperf" - {"padtomultiple", &grib_accessor_class_padtomultiple}, -#line 128 "accessor_class_list.gperf" - {"latitudes", &grib_accessor_class_latitudes}, -#line 165 "accessor_class_list.gperf" - {"rdbtime_guess_date", &grib_accessor_class_rdbtime_guess_date}, - {""}, {""}, {""}, -#line 195 "accessor_class_list.gperf" - {"to_string", &grib_accessor_class_to_string}, -#line 133 "accessor_class_list.gperf" - {"long", &grib_accessor_class_long}, -#line 19 "accessor_class_list.gperf" - {"bufr_data_array", &grib_accessor_class_bufr_data_array}, -#line 78 "accessor_class_list.gperf" - {"double", &grib_accessor_class_double}, -#line 20 "accessor_class_list.gperf" - {"bufr_data_element", &grib_accessor_class_bufr_data_element}, -#line 106 "accessor_class_list.gperf" - {"g2latlon", &grib_accessor_class_g2latlon}, - {""}, {""}, -#line 26 "accessor_class_list.gperf" - {"bufr_simple_thinning", &grib_accessor_class_bufr_simple_thinning}, - {""}, -#line 138 "accessor_class_list.gperf" - {"mars_step", &grib_accessor_class_mars_step}, - {""}, -#line 116 "accessor_class_list.gperf" - {"group", &grib_accessor_class_group}, - {""}, -#line 28 "accessor_class_list.gperf" - {"bufrdc_expanded_descriptors", &grib_accessor_class_bufrdc_expanded_descriptors}, -#line 162 "accessor_class_list.gperf" - {"position", &grib_accessor_class_position}, - {""}, {""}, {""}, -#line 17 "accessor_class_list.gperf" - {"blob", &grib_accessor_class_blob}, -#line 110 "accessor_class_list.gperf" - {"gaussian_grid_name", &grib_accessor_class_gaussian_grid_name}, -#line 198 "accessor_class_list.gperf" - {"trim", &grib_accessor_class_trim}, - {""}, {""}, -#line 120 "accessor_class_list.gperf" - {"ibmfloat", &grib_accessor_class_ibmfloat}, - {""}, {""}, -#line 196 "accessor_class_list.gperf" - {"transient", &grib_accessor_class_transient}, -#line 56 "accessor_class_list.gperf" - {"data_g1shsimple_packing", &grib_accessor_class_data_g1shsimple_packing}, - {""}, {""}, -#line 57 "accessor_class_list.gperf" - {"data_g1simple_packing", &grib_accessor_class_data_g1simple_packing}, -#line 50 "accessor_class_list.gperf" - {"data_g1complex_packing", &grib_accessor_class_data_g1complex_packing}, -#line 167 "accessor_class_list.gperf" - {"round", &grib_accessor_class_round}, -#line 197 "accessor_class_list.gperf" - {"transient_darray", &grib_accessor_class_transient_darray}, -#line 18 "accessor_class_list.gperf" - {"budgdate", &grib_accessor_class_budgdate}, -#line 211 "accessor_class_list.gperf" - {"values", &grib_accessor_class_values}, -#line 145 "accessor_class_list.gperf" - {"number_of_coded_values", &grib_accessor_class_number_of_coded_values}, -#line 127 "accessor_class_list.gperf" - {"label", &grib_accessor_class_label}, - {""}, {""}, -#line 39 "accessor_class_list.gperf" - {"concept", &grib_accessor_class_concept}, - {""}, -#line 184 "accessor_class_list.gperf" - {"spectral_truncation", &grib_accessor_class_spectral_truncation}, - {""}, {""}, -#line 84 "accessor_class_list.gperf" - {"g1_message_length", &grib_accessor_class_g1_message_length}, - {""}, -#line 191 "accessor_class_list.gperf" - {"suppressed", &grib_accessor_class_suppressed}, - {""}, {""}, {""}, {""}, -#line 181 "accessor_class_list.gperf" - {"smart_table", &grib_accessor_class_smart_table}, - {""}, -#line 40 "accessor_class_list.gperf" - {"constant", &grib_accessor_class_constant}, - {""}, {""}, -#line 163 "accessor_class_list.gperf" - {"proj_string", &grib_accessor_class_proj_string}, -#line 151 "accessor_class_list.gperf" - {"octet_number", &grib_accessor_class_octet_number}, -#line 182 "accessor_class_list.gperf" - {"smart_table_column", &grib_accessor_class_smart_table_column}, - {""}, -#line 136 "accessor_class_list.gperf" - {"lookup", &grib_accessor_class_lookup}, - {""}, -#line 95 "accessor_class_list.gperf" - {"g1step_range", &grib_accessor_class_g1step_range}, -#line 74 "accessor_class_list.gperf" - {"decimal_precision", &grib_accessor_class_decimal_precision}, - {""}, -#line 135 "accessor_class_list.gperf" - {"longitudes", &grib_accessor_class_longitudes}, - {""}, -#line 27 "accessor_class_list.gperf" - {"bufr_string_values", &grib_accessor_class_bufr_string_values}, + {"uint64", &grib_accessor_uint64}, +#line 47 "accessor_class_list.gperf" + {"data_complex_packing", &grib_accessor_data_complex_packing}, #line 199 "accessor_class_list.gperf" - {"uint16", &grib_accessor_class_uint16}, + {"uint32", &grib_accessor_uint32}, +#line 13 "accessor_class_list.gperf" + {"bit", &grib_accessor_bit}, +#line 15 "accessor_class_list.gperf" + {"bits", &grib_accessor_bits}, +#line 48 "accessor_class_list.gperf" + {"data_dummy_field", &grib_accessor_data_dummy_field}, +#line 14 "accessor_class_list.gperf" + {"bitmap", &grib_accessor_bitmap}, +#line 124 "accessor_class_list.gperf" + {"julian_day", &grib_accessor_julian_day}, +#line 123 "accessor_class_list.gperf" + {"julian_date", &grib_accessor_julian_date}, +#line 143 "accessor_class_list.gperf" + {"non_alpha", &grib_accessor_non_alpha}, + {""}, {""}, +#line 67 "accessor_class_list.gperf" + {"data_run_length_packing", &grib_accessor_data_run_length_packing}, +#line 108 "accessor_class_list.gperf" + {"g2step_range", &grib_accessor_g2step_range}, +#line 16 "accessor_class_list.gperf" + {"bits_per_value", &grib_accessor_bits_per_value}, + {""}, +#line 29 "accessor_class_list.gperf" + {"bytes", &grib_accessor_bytes}, {""}, {""}, {""}, -#line 87 "accessor_class_list.gperf" - {"g1date", &grib_accessor_class_g1date}, - {""}, -#line 86 "accessor_class_list.gperf" - {"g1bitmap", &grib_accessor_class_g1bitmap}, - {""}, -#line 55 "accessor_class_list.gperf" - {"data_g1secondary_bitmap", &grib_accessor_class_data_g1secondary_bitmap}, -#line 193 "accessor_class_list.gperf" - {"to_double", &grib_accessor_class_to_double}, -#line 102 "accessor_class_list.gperf" - {"g2bitmap_present", &grib_accessor_class_g2bitmap_present}, - {""}, -#line 214 "accessor_class_list.gperf" - {"when", &grib_accessor_class_when}, -#line 209 "accessor_class_list.gperf" - {"validity_date", &grib_accessor_class_validity_date}, -#line 210 "accessor_class_list.gperf" - {"validity_time", &grib_accessor_class_validity_time}, +#line 167 "accessor_class_list.gperf" + {"scale", &grib_accessor_scale}, {""}, #line 185 "accessor_class_list.gperf" - {"sprintf", &grib_accessor_class_sprintf}, -#line 213 "accessor_class_list.gperf" - {"vector", &grib_accessor_class_vector}, -#line 85 "accessor_class_list.gperf" - {"g1_section4_length", &grib_accessor_class_g1_section4_length}, -#line 142 "accessor_class_list.gperf" - {"multdouble", &grib_accessor_class_multdouble}, -#line 53 "accessor_class_list.gperf" - {"data_g1second_order_general_packing", &grib_accessor_class_data_g1second_order_general_packing}, -#line 131 "accessor_class_list.gperf" - {"library_version", &grib_accessor_class_library_version}, - {""}, -#line 54 "accessor_class_list.gperf" - {"data_g1second_order_row_by_row_packing", &grib_accessor_class_data_g1second_order_row_by_row_packing}, - {""}, {""}, -#line 160 "accessor_class_list.gperf" - {"padtoeven", &grib_accessor_class_padtoeven}, -#line 51 "accessor_class_list.gperf" - {"data_g1second_order_constant_width_packing", &grib_accessor_class_data_g1second_order_constant_width_packing}, - {""}, -#line 52 "accessor_class_list.gperf" - {"data_g1second_order_general_extended_packing", &grib_accessor_class_data_g1second_order_general_extended_packing}, -#line 71 "accessor_class_list.gperf" - {"data_sh_unpacked", &grib_accessor_class_data_sh_unpacked}, - {""}, {""}, {""}, {""}, -#line 72 "accessor_class_list.gperf" - {"data_shsimple_packing", &grib_accessor_class_data_shsimple_packing}, -#line 21 "accessor_class_list.gperf" - {"bufr_elements_table", &grib_accessor_class_bufr_elements_table}, - {""}, {""}, {""}, {""}, -#line 155 "accessor_class_list.gperf" - {"pack_bufr_values", &grib_accessor_class_pack_bufr_values}, -#line 36 "accessor_class_list.gperf" - {"codetable", &grib_accessor_class_codetable}, -#line 132 "accessor_class_list.gperf" - {"local_definition", &grib_accessor_class_local_definition}, - {""}, -#line 25 "accessor_class_list.gperf" - {"bufr_group", &grib_accessor_class_bufr_group}, - {""}, -#line 89 "accessor_class_list.gperf" - {"g1end_of_interval_monthly", &grib_accessor_class_g1end_of_interval_monthly}, -#line 148 "accessor_class_list.gperf" - {"number_of_values", &grib_accessor_class_number_of_values}, -#line 24 "accessor_class_list.gperf" - {"bufr_extract_subsets", &grib_accessor_class_bufr_extract_subsets}, -#line 121 "accessor_class_list.gperf" - {"ieeefloat", &grib_accessor_class_ieeefloat}, -#line 152 "accessor_class_list.gperf" - {"offset_file", &grib_accessor_class_offset_file}, -#line 34 "accessor_class_list.gperf" - {"closest_date", &grib_accessor_class_closest_date}, -#line 154 "accessor_class_list.gperf" - {"optimal_step_units", &grib_accessor_class_optimal_step_units}, -#line 22 "accessor_class_list.gperf" - {"bufr_extract_area_subsets", &grib_accessor_class_bufr_extract_area_subsets}, -#line 212 "accessor_class_list.gperf" - {"variable", &grib_accessor_class_variable}, -#line 134 "accessor_class_list.gperf" - {"long_vector", &grib_accessor_class_long_vector}, -#line 169 "accessor_class_list.gperf" - {"scale_values", &grib_accessor_class_scale_values}, -#line 23 "accessor_class_list.gperf" - {"bufr_extract_datetime_subsets", &grib_accessor_class_bufr_extract_datetime_subsets}, - {""}, {""}, -#line 129 "accessor_class_list.gperf" - {"latlon_increment", &grib_accessor_class_latlon_increment}, - {""}, {""}, {""}, -#line 149 "accessor_class_list.gperf" - {"number_of_values_data_raw_packing", &grib_accessor_class_number_of_values_data_raw_packing}, - {""}, -#line 80 "accessor_class_list.gperf" - {"evaluate", &grib_accessor_class_evaluate}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, -#line 11 "accessor_class_list.gperf" - {"abstract_vector", &grib_accessor_class_abstract_vector}, - {""}, {""}, {""}, {""}, -#line 42 "accessor_class_list.gperf" - {"count_missing", &grib_accessor_class_count_missing}, -#line 206 "accessor_class_list.gperf" - {"unpack_bufr_values", &grib_accessor_class_unpack_bufr_values}, -#line 117 "accessor_class_list.gperf" - {"gts_header", &grib_accessor_class_gts_header}, - {""}, -#line 30 "accessor_class_list.gperf" - {"cf_var_name", &grib_accessor_class_cf_var_name}, - {""}, {""}, {""}, -#line 37 "accessor_class_list.gperf" - {"codetable_title", &grib_accessor_class_codetable_title}, - {""}, {""}, {""}, -#line 90 "accessor_class_list.gperf" - {"g1fcperiod", &grib_accessor_class_g1fcperiod}, - {""}, {""}, {""}, {""}, {""}, -#line 126 "accessor_class_list.gperf" - {"ksec1expver", &grib_accessor_class_ksec1expver}, - {""}, {""}, -#line 107 "accessor_class_list.gperf" - {"g2level", &grib_accessor_class_g2level}, -#line 43 "accessor_class_list.gperf" - {"count_total", &grib_accessor_class_count_total}, - {""}, {""}, {""}, -#line 70 "accessor_class_list.gperf" - {"data_sh_packed", &grib_accessor_class_data_sh_packed}, -#line 38 "accessor_class_list.gperf" - {"codetable_units", &grib_accessor_class_codetable_units}, -#line 119 "accessor_class_list.gperf" - {"headers_only", &grib_accessor_class_headers_only}, - {""}, -#line 130 "accessor_class_list.gperf" - {"latlonvalues", &grib_accessor_class_latlonvalues}, - {""}, -#line 153 "accessor_class_list.gperf" - {"offset_values", &grib_accessor_class_offset_values}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {"statistics", &grib_accessor_statistics}, +#line 102 "accessor_class_list.gperf" + {"g2date", &grib_accessor_g2date}, +#line 145 "accessor_class_list.gperf" + {"number_of_points", &grib_accessor_number_of_points}, +#line 100 "accessor_class_list.gperf" + {"g2bitmap", &grib_accessor_g2bitmap}, {""}, +#line 60 "accessor_class_list.gperf" + {"data_g2secondary_bitmap", &grib_accessor_data_g2secondary_bitmap}, +#line 58 "accessor_class_list.gperf" + {"data_g2bifourier_packing", &grib_accessor_data_g2bifourier_packing}, +#line 111 "accessor_class_list.gperf" + {"gds_not_present_bitmap", &grib_accessor_gds_not_present_bitmap}, #line 122 "accessor_class_list.gperf" - {"ifs_param", &grib_accessor_class_ifs_param}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, -#line 10 "accessor_class_list.gperf" - {"abstract_long_vector", &grib_accessor_class_abstract_long_vector}, -#line 35 "accessor_class_list.gperf" - {"codeflag", &grib_accessor_class_codeflag}, - {""}, {""}, {""}, -#line 118 "accessor_class_list.gperf" - {"hash_array", &grib_accessor_class_hash_array}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, -#line 31 "accessor_class_list.gperf" - {"change_alternative_row_scanning", &grib_accessor_class_change_alternative_row_scanning}, - {""}, {""}, {""}, {""}, {""}, {""}, -#line 32 "accessor_class_list.gperf" - {"change_scanning_direction", &grib_accessor_class_change_scanning_direction}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, -#line 150 "accessor_class_list.gperf" - {"octahedral_gaussian", &grib_accessor_class_octahedral_gaussian}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, -#line 41 "accessor_class_list.gperf" - {"count_file", &grib_accessor_class_count_file}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, -#line 92 "accessor_class_list.gperf" - {"g1monthlydate", &grib_accessor_class_g1monthlydate}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, -#line 83 "accessor_class_list.gperf" - {"g1_half_byte_codeflag", &grib_accessor_class_g1_half_byte_codeflag}, - {""}, -#line 82 "accessor_class_list.gperf" - {"from_scale_factor_scaled_value", &grib_accessor_class_from_scale_factor_scaled_value}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, -#line 166 "accessor_class_list.gperf" - {"reference_value_error", &grib_accessor_class_reference_value_error}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, -#line 33 "accessor_class_list.gperf" - {"check_internal_version", &grib_accessor_class_check_internal_version}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, -#line 98 "accessor_class_list.gperf" - {"g2_chemical", &grib_accessor_class_g2_chemical}, - {""}, {""}, {""}, {""}, {""}, -#line 88 "accessor_class_list.gperf" - {"g1day_of_the_year_date", &grib_accessor_class_g1day_of_the_year_date}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, -#line 91 "accessor_class_list.gperf" - {"g1forecastmonth", &grib_accessor_class_g1forecastmonth}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, -#line 94 "accessor_class_list.gperf" - {"g1number_of_coded_values_sh_simple", &grib_accessor_class_g1number_of_coded_values_sh_simple}, -#line 93 "accessor_class_list.gperf" - {"g1number_of_coded_values_sh_complex", &grib_accessor_class_g1number_of_coded_values_sh_complex}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, - {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {"iterator", &grib_accessor_iterator}, +#line 186 "accessor_class_list.gperf" + {"statistics_spectral", &grib_accessor_statistics_spectral}, +#line 46 "accessor_class_list.gperf" + {"data_ccsds_packing", &grib_accessor_data_ccsds_packing}, +#line 146 "accessor_class_list.gperf" + {"number_of_points_gaussian", &grib_accessor_number_of_points_gaussian}, +#line 206 "accessor_class_list.gperf" + {"unsigned", &grib_accessor_unsigned}, +#line 138 "accessor_class_list.gperf" + {"md5", &grib_accessor_md5}, {""}, {""}, #line 96 "accessor_class_list.gperf" - {"g1verificationdate", &grib_accessor_class_g1verificationdate} + {"g2_aerosol", &grib_accessor_g2_aerosol}, +#line 139 "accessor_class_list.gperf" + {"message", &grib_accessor_message}, +#line 207 "accessor_class_list.gperf" + {"unsigned_bits", &grib_accessor_unsigned_bits}, +#line 174 "accessor_class_list.gperf" + {"select_step_template", &grib_accessor_select_step_template}, +#line 136 "accessor_class_list.gperf" + {"mars_param", &grib_accessor_mars_param}, +#line 204 "accessor_class_list.gperf" + {"unexpanded_descriptors", &grib_accessor_unexpanded_descriptors}, +#line 193 "accessor_class_list.gperf" + {"to_integer", &grib_accessor_to_integer}, +#line 178 "accessor_class_list.gperf" + {"simple_packing_error", &grib_accessor_simple_packing_error}, + {""}, {""}, {""}, +#line 187 "accessor_class_list.gperf" + {"step_human_readable", &grib_accessor_step_human_readable}, +#line 140 "accessor_class_list.gperf" + {"message_copy", &grib_accessor_message_copy}, +#line 163 "accessor_class_list.gperf" + {"raw", &grib_accessor_raw}, + {""}, {""}, +#line 202 "accessor_class_list.gperf" + {"uint64_little_endian", &grib_accessor_uint64_little_endian}, + {""}, +#line 200 "accessor_class_list.gperf" + {"uint32_little_endian", &grib_accessor_uint32_little_endian}, +#line 114 "accessor_class_list.gperf" + {"global_gaussian", &grib_accessor_global_gaussian}, + {""}, {""}, +#line 76 "accessor_class_list.gperf" + {"divdouble", &grib_accessor_divdouble}, + {""}, +#line 175 "accessor_class_list.gperf" + {"sexagesimal2decimal", &grib_accessor_sexagesimal2decimal}, +#line 99 "accessor_class_list.gperf" + {"g2_mars_labeling", &grib_accessor_g2_mars_labeling}, +#line 78 "accessor_class_list.gperf" + {"element", &grib_accessor_element}, +#line 160 "accessor_class_list.gperf" + {"padtomultiple", &grib_accessor_padtomultiple}, +#line 127 "accessor_class_list.gperf" + {"latitudes", &grib_accessor_latitudes}, +#line 164 "accessor_class_list.gperf" + {"rdbtime_guess_date", &grib_accessor_rdbtime_guess_date}, + {""}, {""}, {""}, +#line 194 "accessor_class_list.gperf" + {"to_string", &grib_accessor_to_string}, +#line 132 "accessor_class_list.gperf" + {"long", &grib_accessor_long}, +#line 19 "accessor_class_list.gperf" + {"bufr_data_array", &grib_accessor_bufr_data_array}, +#line 77 "accessor_class_list.gperf" + {"double", &grib_accessor_double}, +#line 20 "accessor_class_list.gperf" + {"bufr_data_element", &grib_accessor_bufr_data_element}, +#line 105 "accessor_class_list.gperf" + {"g2latlon", &grib_accessor_g2latlon}, + {""}, {""}, +#line 26 "accessor_class_list.gperf" + {"bufr_simple_thinning", &grib_accessor_bufr_simple_thinning}, + {""}, +#line 137 "accessor_class_list.gperf" + {"mars_step", &grib_accessor_mars_step}, + {""}, +#line 115 "accessor_class_list.gperf" + {"group", &grib_accessor_group}, + {""}, +#line 28 "accessor_class_list.gperf" + {"bufrdc_expanded_descriptors", &grib_accessor_bufrdc_expanded_descriptors}, +#line 161 "accessor_class_list.gperf" + {"position", &grib_accessor_position}, + {""}, {""}, {""}, +#line 17 "accessor_class_list.gperf" + {"blob", &grib_accessor_blob}, +#line 109 "accessor_class_list.gperf" + {"gaussian_grid_name", &grib_accessor_gaussian_grid_name}, +#line 197 "accessor_class_list.gperf" + {"trim", &grib_accessor_trim}, + {""}, {""}, +#line 119 "accessor_class_list.gperf" + {"ibmfloat", &grib_accessor_ibmfloat}, + {""}, {""}, +#line 195 "accessor_class_list.gperf" + {"transient", &grib_accessor_transient}, +#line 55 "accessor_class_list.gperf" + {"data_g1shsimple_packing", &grib_accessor_data_g1shsimple_packing}, + {""}, {""}, +#line 56 "accessor_class_list.gperf" + {"data_g1simple_packing", &grib_accessor_data_g1simple_packing}, +#line 49 "accessor_class_list.gperf" + {"data_g1complex_packing", &grib_accessor_data_g1complex_packing}, +#line 166 "accessor_class_list.gperf" + {"round", &grib_accessor_round}, +#line 196 "accessor_class_list.gperf" + {"transient_darray", &grib_accessor_transient_darray}, +#line 18 "accessor_class_list.gperf" + {"budgdate", &grib_accessor_budgdate}, +#line 210 "accessor_class_list.gperf" + {"values", &grib_accessor_values}, +#line 144 "accessor_class_list.gperf" + {"number_of_coded_values", &grib_accessor_number_of_coded_values}, +#line 126 "accessor_class_list.gperf" + {"label", &grib_accessor_label}, + {""}, {""}, +#line 38 "accessor_class_list.gperf" + {"concept", &grib_accessor_concept}, + {""}, +#line 183 "accessor_class_list.gperf" + {"spectral_truncation", &grib_accessor_spectral_truncation}, + {""}, {""}, +#line 83 "accessor_class_list.gperf" + {"g1_message_length", &grib_accessor_g1_message_length}, + {""}, +#line 190 "accessor_class_list.gperf" + {"suppressed", &grib_accessor_suppressed}, + {""}, {""}, {""}, {""}, +#line 180 "accessor_class_list.gperf" + {"smart_table", &grib_accessor_smart_table}, + {""}, +#line 39 "accessor_class_list.gperf" + {"constant", &grib_accessor_constant}, + {""}, {""}, +#line 162 "accessor_class_list.gperf" + {"proj_string", &grib_accessor_proj_string}, +#line 150 "accessor_class_list.gperf" + {"octet_number", &grib_accessor_octet_number}, +#line 181 "accessor_class_list.gperf" + {"smart_table_column", &grib_accessor_smart_table_column}, + {""}, +#line 135 "accessor_class_list.gperf" + {"lookup", &grib_accessor_lookup}, + {""}, +#line 94 "accessor_class_list.gperf" + {"g1step_range", &grib_accessor_g1step_range}, +#line 73 "accessor_class_list.gperf" + {"decimal_precision", &grib_accessor_decimal_precision}, + {""}, +#line 134 "accessor_class_list.gperf" + {"longitudes", &grib_accessor_longitudes}, + {""}, +#line 27 "accessor_class_list.gperf" + {"bufr_string_values", &grib_accessor_bufr_string_values}, +#line 198 "accessor_class_list.gperf" + {"uint16", &grib_accessor_uint16}, + {""}, {""}, {""}, +#line 86 "accessor_class_list.gperf" + {"g1date", &grib_accessor_g1date}, + {""}, +#line 85 "accessor_class_list.gperf" + {"g1bitmap", &grib_accessor_g1bitmap}, + {""}, +#line 54 "accessor_class_list.gperf" + {"data_g1secondary_bitmap", &grib_accessor_data_g1secondary_bitmap}, +#line 192 "accessor_class_list.gperf" + {"to_double", &grib_accessor_to_double}, +#line 101 "accessor_class_list.gperf" + {"g2bitmap_present", &grib_accessor_g2bitmap_present}, + {""}, +#line 213 "accessor_class_list.gperf" + {"when", &grib_accessor_when}, +#line 208 "accessor_class_list.gperf" + {"validity_date", &grib_accessor_validity_date}, +#line 209 "accessor_class_list.gperf" + {"validity_time", &grib_accessor_validity_time}, + {""}, +#line 184 "accessor_class_list.gperf" + {"sprintf", &grib_accessor_sprintf}, +#line 212 "accessor_class_list.gperf" + {"vector", &grib_accessor_vector}, +#line 84 "accessor_class_list.gperf" + {"g1_section4_length", &grib_accessor_g1_section4_length}, +#line 141 "accessor_class_list.gperf" + {"multdouble", &grib_accessor_multdouble}, +#line 52 "accessor_class_list.gperf" + {"data_g1second_order_general_packing", &grib_accessor_data_g1second_order_general_packing}, +#line 130 "accessor_class_list.gperf" + {"library_version", &grib_accessor_library_version}, + {""}, +#line 53 "accessor_class_list.gperf" + {"data_g1second_order_row_by_row_packing", &grib_accessor_data_g1second_order_row_by_row_packing}, + {""}, {""}, +#line 159 "accessor_class_list.gperf" + {"padtoeven", &grib_accessor_padtoeven}, +#line 50 "accessor_class_list.gperf" + {"data_g1second_order_constant_width_packing", &grib_accessor_data_g1second_order_constant_width_packing}, + {""}, +#line 51 "accessor_class_list.gperf" + {"data_g1second_order_general_extended_packing", &grib_accessor_data_g1second_order_general_extended_packing}, +#line 70 "accessor_class_list.gperf" + {"data_sh_unpacked", &grib_accessor_data_sh_unpacked}, + {""}, {""}, {""}, {""}, +#line 71 "accessor_class_list.gperf" + {"data_shsimple_packing", &grib_accessor_data_shsimple_packing}, +#line 21 "accessor_class_list.gperf" + {"bufr_elements_table", &grib_accessor_bufr_elements_table}, + {""}, {""}, {""}, {""}, +#line 154 "accessor_class_list.gperf" + {"pack_bufr_values", &grib_accessor_pack_bufr_values}, +#line 35 "accessor_class_list.gperf" + {"codetable", &grib_accessor_codetable}, +#line 131 "accessor_class_list.gperf" + {"local_definition", &grib_accessor_local_definition}, + {""}, +#line 25 "accessor_class_list.gperf" + {"bufr_group", &grib_accessor_bufr_group}, + {""}, +#line 88 "accessor_class_list.gperf" + {"g1end_of_interval_monthly", &grib_accessor_g1end_of_interval_monthly}, +#line 147 "accessor_class_list.gperf" + {"number_of_values", &grib_accessor_number_of_values}, +#line 24 "accessor_class_list.gperf" + {"bufr_extract_subsets", &grib_accessor_bufr_extract_subsets}, +#line 120 "accessor_class_list.gperf" + {"ieeefloat", &grib_accessor_ieeefloat}, +#line 151 "accessor_class_list.gperf" + {"offset_file", &grib_accessor_offset_file}, +#line 33 "accessor_class_list.gperf" + {"closest_date", &grib_accessor_closest_date}, +#line 153 "accessor_class_list.gperf" + {"optimal_step_units", &grib_accessor_optimal_step_units}, +#line 22 "accessor_class_list.gperf" + {"bufr_extract_area_subsets", &grib_accessor_bufr_extract_area_subsets}, +#line 211 "accessor_class_list.gperf" + {"variable", &grib_accessor_variable}, +#line 133 "accessor_class_list.gperf" + {"long_vector", &grib_accessor_long_vector}, +#line 168 "accessor_class_list.gperf" + {"scale_values", &grib_accessor_scale_values}, +#line 23 "accessor_class_list.gperf" + {"bufr_extract_datetime_subsets", &grib_accessor_bufr_extract_datetime_subsets}, + {""}, {""}, +#line 128 "accessor_class_list.gperf" + {"latlon_increment", &grib_accessor_latlon_increment}, + {""}, {""}, {""}, +#line 148 "accessor_class_list.gperf" + {"number_of_values_data_raw_packing", &grib_accessor_number_of_values_data_raw_packing}, + {""}, +#line 79 "accessor_class_list.gperf" + {"evaluate", &grib_accessor_evaluate}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, +#line 11 "accessor_class_list.gperf" + {"abstract_vector", &grib_accessor_abstract_vector}, + {""}, {""}, {""}, {""}, +#line 41 "accessor_class_list.gperf" + {"count_missing", &grib_accessor_count_missing}, +#line 205 "accessor_class_list.gperf" + {"unpack_bufr_values", &grib_accessor_unpack_bufr_values}, +#line 116 "accessor_class_list.gperf" + {"gts_header", &grib_accessor_gts_header}, + {""}, +#line 214 "accessor_class_list.gperf" + {"cf_var_name", &grib_accessor_cf_var_name}, + {""}, {""}, {""}, +#line 36 "accessor_class_list.gperf" + {"codetable_title", &grib_accessor_codetable_title}, + {""}, {""}, {""}, +#line 89 "accessor_class_list.gperf" + {"g1fcperiod", &grib_accessor_g1fcperiod}, + {""}, {""}, {""}, {""}, {""}, +#line 125 "accessor_class_list.gperf" + {"ksec1expver", &grib_accessor_ksec1expver}, + {""}, {""}, +#line 106 "accessor_class_list.gperf" + {"g2level", &grib_accessor_g2level}, +#line 42 "accessor_class_list.gperf" + {"count_total", &grib_accessor_count_total}, + {""}, {""}, {""}, +#line 69 "accessor_class_list.gperf" + {"data_sh_packed", &grib_accessor_data_sh_packed}, +#line 37 "accessor_class_list.gperf" + {"codetable_units", &grib_accessor_codetable_units}, +#line 118 "accessor_class_list.gperf" + {"headers_only", &grib_accessor_headers_only}, + {""}, +#line 129 "accessor_class_list.gperf" + {"latlonvalues", &grib_accessor_latlonvalues}, + {""}, +#line 152 "accessor_class_list.gperf" + {"offset_values", &grib_accessor_offset_values}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, +#line 121 "accessor_class_list.gperf" + {"ifs_param", &grib_accessor_ifs_param}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, +#line 10 "accessor_class_list.gperf" + {"abstract_long_vector", &grib_accessor_abstract_long_vector}, +#line 34 "accessor_class_list.gperf" + {"codeflag", &grib_accessor_codeflag}, + {""}, {""}, {""}, +#line 117 "accessor_class_list.gperf" + {"hash_array", &grib_accessor_hash_array}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, +#line 30 "accessor_class_list.gperf" + {"change_alternative_row_scanning", &grib_accessor_change_alternative_row_scanning}, + {""}, {""}, {""}, {""}, {""}, {""}, +#line 31 "accessor_class_list.gperf" + {"change_scanning_direction", &grib_accessor_change_scanning_direction}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, +#line 149 "accessor_class_list.gperf" + {"octahedral_gaussian", &grib_accessor_octahedral_gaussian}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, {""}, +#line 40 "accessor_class_list.gperf" + {"count_file", &grib_accessor_count_file}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, +#line 91 "accessor_class_list.gperf" + {"g1monthlydate", &grib_accessor_g1monthlydate}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, {""}, {""}, {""}, {""}, {""}, +#line 82 "accessor_class_list.gperf" + {"g1_half_byte_codeflag", &grib_accessor_g1_half_byte_codeflag}, + {""}, +#line 81 "accessor_class_list.gperf" + {"from_scale_factor_scaled_value", &grib_accessor_from_scale_factor_scaled_value}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, +#line 165 "accessor_class_list.gperf" + {"reference_value_error", &grib_accessor_reference_value_error}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, +#line 32 "accessor_class_list.gperf" + {"check_internal_version", &grib_accessor_check_internal_version}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, {""}, {""}, {""}, {""}, {""}, +#line 97 "accessor_class_list.gperf" + {"g2_chemical", &grib_accessor_g2_chemical}, + {""}, {""}, {""}, {""}, {""}, +#line 87 "accessor_class_list.gperf" + {"g1day_of_the_year_date", &grib_accessor_g1day_of_the_year_date}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, {""}, {""}, {""}, {""}, {""}, +#line 90 "accessor_class_list.gperf" + {"g1forecastmonth", &grib_accessor_g1forecastmonth}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, +#line 93 "accessor_class_list.gperf" + {"g1number_of_coded_values_sh_simple", &grib_accessor_g1number_of_coded_values_sh_simple}, +#line 92 "accessor_class_list.gperf" + {"g1number_of_coded_values_sh_complex", &grib_accessor_g1number_of_coded_values_sh_complex}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, + {""}, {""}, +#line 95 "accessor_class_list.gperf" + {"g1verificationdate", &grib_accessor_g1verificationdate} }; -static const struct accessor_class_hash* grib_accessor_classes_hash(const char *str, size_t len) +const struct accessor_class_hash * +grib_accessor_hash (const char *str, size_t len) +{ + if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) { unsigned int key = grib_accessor_classes_get_id (str, len); -#ifdef DEBUG + if (key <= MAX_HASH_VALUE) { - const char *s; - Assert( len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH ); - Assert( key <= MAX_HASH_VALUE ); - s = classes[key].name; - Assert( *str == *s && strcmp(str + 1, s + 1)==0 ); - } -#endif + const char *s = classes[key].name; + if (*str == *s && !strcmp (str + 1, s + 1)) return &classes[key]; + } + } + return 0; } diff --git a/src/grib_accessor_factory.h b/src/grib_accessor_factory.h index 13716e28f..524458c58 100644 --- a/src/grib_accessor_factory.h +++ b/src/grib_accessor_factory.h @@ -1,206 +1,205 @@ /* This file is automatically generated by ./make_class.pl, do not edit */ -{ "abstract_long_vector", &grib_accessor_class_abstract_long_vector, }, -{ "abstract_vector", &grib_accessor_class_abstract_vector, }, -{ "ascii", &grib_accessor_class_ascii, }, -{ "bit", &grib_accessor_class_bit, }, -{ "bitmap", &grib_accessor_class_bitmap, }, -{ "bits", &grib_accessor_class_bits, }, -{ "bits_per_value", &grib_accessor_class_bits_per_value, }, -{ "blob", &grib_accessor_class_blob, }, -{ "budgdate", &grib_accessor_class_budgdate, }, -{ "bufr_data_array", &grib_accessor_class_bufr_data_array, }, -{ "bufr_data_element", &grib_accessor_class_bufr_data_element, }, -{ "bufr_elements_table", &grib_accessor_class_bufr_elements_table, }, -{ "bufr_extract_area_subsets", &grib_accessor_class_bufr_extract_area_subsets, }, -{ "bufr_extract_datetime_subsets", &grib_accessor_class_bufr_extract_datetime_subsets, }, -{ "bufr_extract_subsets", &grib_accessor_class_bufr_extract_subsets, }, -{ "bufr_group", &grib_accessor_class_bufr_group, }, -{ "bufr_simple_thinning", &grib_accessor_class_bufr_simple_thinning, }, -{ "bufr_string_values", &grib_accessor_class_bufr_string_values, }, -{ "bufrdc_expanded_descriptors", &grib_accessor_class_bufrdc_expanded_descriptors, }, -{ "bytes", &grib_accessor_class_bytes, }, -{ "cf_var_name", &grib_accessor_class_cf_var_name, }, -{ "change_alternative_row_scanning", &grib_accessor_class_change_alternative_row_scanning, }, -{ "change_scanning_direction", &grib_accessor_class_change_scanning_direction, }, -{ "check_internal_version", &grib_accessor_class_check_internal_version, }, -{ "closest_date", &grib_accessor_class_closest_date, }, -{ "codeflag", &grib_accessor_class_codeflag, }, -{ "codetable", &grib_accessor_class_codetable, }, -{ "codetable_title", &grib_accessor_class_codetable_title, }, -{ "codetable_units", &grib_accessor_class_codetable_units, }, -{ "concept", &grib_accessor_class_concept, }, -{ "constant", &grib_accessor_class_constant, }, -{ "count_file", &grib_accessor_class_count_file, }, -{ "count_missing", &grib_accessor_class_count_missing, }, -{ "count_total", &grib_accessor_class_count_total, }, -{ "data_apply_bitmap", &grib_accessor_class_data_apply_bitmap, }, -{ "data_apply_boustrophedonic", &grib_accessor_class_data_apply_boustrophedonic, }, -{ "data_apply_boustrophedonic_bitmap", &grib_accessor_class_data_apply_boustrophedonic_bitmap, }, -{ "data_ccsds_packing", &grib_accessor_class_data_ccsds_packing, }, -{ "data_complex_packing", &grib_accessor_class_data_complex_packing, }, -{ "data_dummy_field", &grib_accessor_class_data_dummy_field, }, -{ "data_g1complex_packing", &grib_accessor_class_data_g1complex_packing, }, -{ "data_g1second_order_constant_width_packing", &grib_accessor_class_data_g1second_order_constant_width_packing, }, -{ "data_g1second_order_general_extended_packing", &grib_accessor_class_data_g1second_order_general_extended_packing, }, -{ "data_g1second_order_general_packing", &grib_accessor_class_data_g1second_order_general_packing, }, -{ "data_g1second_order_row_by_row_packing", &grib_accessor_class_data_g1second_order_row_by_row_packing, }, -{ "data_g1secondary_bitmap", &grib_accessor_class_data_g1secondary_bitmap, }, -{ "data_g1shsimple_packing", &grib_accessor_class_data_g1shsimple_packing, }, -{ "data_g1simple_packing", &grib_accessor_class_data_g1simple_packing, }, -{ "data_g22order_packing", &grib_accessor_class_data_g22order_packing, }, -{ "data_g2bifourier_packing", &grib_accessor_class_data_g2bifourier_packing, }, -{ "data_g2complex_packing", &grib_accessor_class_data_g2complex_packing, }, -{ "data_g2secondary_bitmap", &grib_accessor_class_data_g2secondary_bitmap, }, -{ "data_g2shsimple_packing", &grib_accessor_class_data_g2shsimple_packing, }, -{ "data_g2simple_packing", &grib_accessor_class_data_g2simple_packing, }, -{ "data_g2simple_packing_with_preprocessing", &grib_accessor_class_data_g2simple_packing_with_preprocessing, }, -{ "data_jpeg2000_packing", &grib_accessor_class_data_jpeg2000_packing, }, -{ "data_png_packing", &grib_accessor_class_data_png_packing, }, -{ "data_raw_packing", &grib_accessor_class_data_raw_packing, }, -{ "data_run_length_packing", &grib_accessor_class_data_run_length_packing, }, -{ "data_secondary_bitmap", &grib_accessor_class_data_secondary_bitmap, }, -{ "data_sh_packed", &grib_accessor_class_data_sh_packed, }, -{ "data_sh_unpacked", &grib_accessor_class_data_sh_unpacked, }, -{ "data_shsimple_packing", &grib_accessor_class_data_shsimple_packing, }, -{ "data_simple_packing", &grib_accessor_class_data_simple_packing, }, -{ "decimal_precision", &grib_accessor_class_decimal_precision, }, -{ "dictionary", &grib_accessor_class_dictionary, }, -{ "dirty", &grib_accessor_class_dirty, }, -{ "divdouble", &grib_accessor_class_divdouble, }, -{ "double", &grib_accessor_class_double, }, -{ "element", &grib_accessor_class_element, }, -{ "evaluate", &grib_accessor_class_evaluate, }, -{ "expanded_descriptors", &grib_accessor_class_expanded_descriptors, }, -{ "from_scale_factor_scaled_value", &grib_accessor_class_from_scale_factor_scaled_value, }, -{ "g1_half_byte_codeflag", &grib_accessor_class_g1_half_byte_codeflag, }, -{ "g1_message_length", &grib_accessor_class_g1_message_length, }, -{ "g1_section4_length", &grib_accessor_class_g1_section4_length, }, -{ "g1bitmap", &grib_accessor_class_g1bitmap, }, -{ "g1date", &grib_accessor_class_g1date, }, -{ "g1day_of_the_year_date", &grib_accessor_class_g1day_of_the_year_date, }, -{ "g1end_of_interval_monthly", &grib_accessor_class_g1end_of_interval_monthly, }, -{ "g1fcperiod", &grib_accessor_class_g1fcperiod, }, -{ "g1forecastmonth", &grib_accessor_class_g1forecastmonth, }, -{ "g1monthlydate", &grib_accessor_class_g1monthlydate, }, -{ "g1number_of_coded_values_sh_complex", &grib_accessor_class_g1number_of_coded_values_sh_complex, }, -{ "g1number_of_coded_values_sh_simple", &grib_accessor_class_g1number_of_coded_values_sh_simple, }, -{ "g1step_range", &grib_accessor_class_g1step_range, }, -{ "g1verificationdate", &grib_accessor_class_g1verificationdate, }, -{ "g2_aerosol", &grib_accessor_class_g2_aerosol, }, -{ "g2_chemical", &grib_accessor_class_g2_chemical, }, -{ "g2_eps", &grib_accessor_class_g2_eps, }, -{ "g2_mars_labeling", &grib_accessor_class_g2_mars_labeling, }, -{ "g2bitmap", &grib_accessor_class_g2bitmap, }, -{ "g2bitmap_present", &grib_accessor_class_g2bitmap_present, }, -{ "g2date", &grib_accessor_class_g2date, }, -{ "g2end_step", &grib_accessor_class_g2end_step, }, -{ "g2grid", &grib_accessor_class_g2grid, }, -{ "g2latlon", &grib_accessor_class_g2latlon, }, -{ "g2level", &grib_accessor_class_g2level, }, -{ "g2lon", &grib_accessor_class_g2lon, }, -{ "g2step_range", &grib_accessor_class_g2step_range, }, -{ "gaussian_grid_name", &grib_accessor_class_gaussian_grid_name, }, -{ "gds_is_present", &grib_accessor_class_gds_is_present, }, -{ "gds_not_present_bitmap", &grib_accessor_class_gds_not_present_bitmap, }, -{ "gen", &grib_accessor_class_gen, }, -{ "getenv", &grib_accessor_class_getenv, }, -{ "global_gaussian", &grib_accessor_class_global_gaussian, }, -{ "group", &grib_accessor_class_group, }, -{ "gts_header", &grib_accessor_class_gts_header, }, -{ "hash_array", &grib_accessor_class_hash_array, }, -{ "headers_only", &grib_accessor_class_headers_only, }, -{ "ibmfloat", &grib_accessor_class_ibmfloat, }, -{ "ieeefloat", &grib_accessor_class_ieeefloat, }, -{ "ifs_param", &grib_accessor_class_ifs_param, }, -{ "iterator", &grib_accessor_class_iterator, }, -{ "julian_date", &grib_accessor_class_julian_date, }, -{ "julian_day", &grib_accessor_class_julian_day, }, -{ "ksec1expver", &grib_accessor_class_ksec1expver, }, -{ "label", &grib_accessor_class_label, }, -{ "latitudes", &grib_accessor_class_latitudes, }, -{ "latlon_increment", &grib_accessor_class_latlon_increment, }, -{ "latlonvalues", &grib_accessor_class_latlonvalues, }, -{ "library_version", &grib_accessor_class_library_version, }, -{ "local_definition", &grib_accessor_class_local_definition, }, -{ "long", &grib_accessor_class_long, }, -{ "long_vector", &grib_accessor_class_long_vector, }, -{ "longitudes", &grib_accessor_class_longitudes, }, -{ "lookup", &grib_accessor_class_lookup, }, -{ "mars_param", &grib_accessor_class_mars_param, }, -{ "mars_step", &grib_accessor_class_mars_step, }, -{ "md5", &grib_accessor_class_md5, }, -{ "message", &grib_accessor_class_message, }, -{ "message_copy", &grib_accessor_class_message_copy, }, -{ "multdouble", &grib_accessor_class_multdouble, }, -{ "nearest", &grib_accessor_class_nearest, }, -{ "non_alpha", &grib_accessor_class_non_alpha, }, -{ "number_of_coded_values", &grib_accessor_class_number_of_coded_values, }, -{ "number_of_points", &grib_accessor_class_number_of_points, }, -{ "number_of_points_gaussian", &grib_accessor_class_number_of_points_gaussian, }, -{ "number_of_values", &grib_accessor_class_number_of_values, }, -{ "number_of_values_data_raw_packing", &grib_accessor_class_number_of_values_data_raw_packing, }, -{ "octahedral_gaussian", &grib_accessor_class_octahedral_gaussian, }, -{ "octet_number", &grib_accessor_class_octet_number, }, -{ "offset_file", &grib_accessor_class_offset_file, }, -{ "offset_values", &grib_accessor_class_offset_values, }, -{ "optimal_step_units", &grib_accessor_class_optimal_step_units, }, -{ "pack_bufr_values", &grib_accessor_class_pack_bufr_values, }, -{ "packing_type", &grib_accessor_class_packing_type, }, -{ "pad", &grib_accessor_class_pad, }, -{ "padding", &grib_accessor_class_padding, }, -{ "padto", &grib_accessor_class_padto, }, -{ "padtoeven", &grib_accessor_class_padtoeven, }, -{ "padtomultiple", &grib_accessor_class_padtomultiple, }, -{ "position", &grib_accessor_class_position, }, -{ "proj_string", &grib_accessor_class_proj_string, }, -{ "raw", &grib_accessor_class_raw, }, -{ "rdbtime_guess_date", &grib_accessor_class_rdbtime_guess_date, }, -{ "reference_value_error", &grib_accessor_class_reference_value_error, }, -{ "round", &grib_accessor_class_round, }, -{ "scale", &grib_accessor_class_scale, }, -{ "scale_values", &grib_accessor_class_scale_values, }, -{ "second_order_bits_per_value", &grib_accessor_class_second_order_bits_per_value, }, -{ "section", &grib_accessor_class_section, }, -{ "section_length", &grib_accessor_class_section_length, }, -{ "section_padding", &grib_accessor_class_section_padding, }, -{ "section_pointer", &grib_accessor_class_section_pointer, }, -{ "select_step_template", &grib_accessor_class_select_step_template, }, -{ "sexagesimal2decimal", &grib_accessor_class_sexagesimal2decimal, }, -{ "signed", &grib_accessor_class_signed, }, -{ "signed_bits", &grib_accessor_class_signed_bits, }, -{ "simple_packing_error", &grib_accessor_class_simple_packing_error, }, -{ "size", &grib_accessor_class_size, }, -{ "smart_table", &grib_accessor_class_smart_table, }, -{ "smart_table_column", &grib_accessor_class_smart_table_column, }, -{ "spd", &grib_accessor_class_spd, }, -{ "spectral_truncation", &grib_accessor_class_spectral_truncation, }, -{ "sprintf", &grib_accessor_class_sprintf, }, -{ "statistics", &grib_accessor_class_statistics, }, -{ "statistics_spectral", &grib_accessor_class_statistics_spectral, }, -{ "step_human_readable", &grib_accessor_class_step_human_readable, }, -{ "step_in_units", &grib_accessor_class_step_in_units, }, -{ "sum", &grib_accessor_class_sum, }, -{ "suppressed", &grib_accessor_class_suppressed, }, -{ "time", &grib_accessor_class_time, }, -{ "to_double", &grib_accessor_class_to_double, }, -{ "to_integer", &grib_accessor_class_to_integer, }, -{ "to_string", &grib_accessor_class_to_string, }, -{ "transient", &grib_accessor_class_transient, }, -{ "transient_darray", &grib_accessor_class_transient_darray, }, -{ "trim", &grib_accessor_class_trim, }, -{ "uint16", &grib_accessor_class_uint16, }, -{ "uint32", &grib_accessor_class_uint32, }, -{ "uint32_little_endian", &grib_accessor_class_uint32_little_endian, }, -{ "uint64", &grib_accessor_class_uint64, }, -{ "uint64_little_endian", &grib_accessor_class_uint64_little_endian, }, -{ "uint8", &grib_accessor_class_uint8, }, -{ "unexpanded_descriptors", &grib_accessor_class_unexpanded_descriptors, }, -{ "unpack_bufr_values", &grib_accessor_class_unpack_bufr_values, }, -{ "unsigned", &grib_accessor_class_unsigned, }, -{ "unsigned_bits", &grib_accessor_class_unsigned_bits, }, -{ "validity_date", &grib_accessor_class_validity_date, }, -{ "validity_time", &grib_accessor_class_validity_time, }, -{ "values", &grib_accessor_class_values, }, -{ "variable", &grib_accessor_class_variable, }, -{ "vector", &grib_accessor_class_vector, }, -{ "when", &grib_accessor_class_when, }, +{ "abstract_long_vector", &grib_accessor_abstract_long_vector, }, +{ "abstract_vector", &grib_accessor_abstract_vector, }, +{ "ascii", &grib_accessor_ascii, }, +{ "bit", &grib_accessor_bit, }, +{ "bitmap", &grib_accessor_bitmap, }, +{ "bits", &grib_accessor_bits, }, +{ "bits_per_value", &grib_accessor_bits_per_value, }, +{ "blob", &grib_accessor_blob, }, +{ "budgdate", &grib_accessor_budgdate, }, +{ "bufr_data_array", &grib_accessor_bufr_data_array, }, +{ "bufr_data_element", &grib_accessor_bufr_data_element, }, +{ "bufr_elements_table", &grib_accessor_bufr_elements_table, }, +{ "bufr_extract_area_subsets", &grib_accessor_bufr_extract_area_subsets, }, +{ "bufr_extract_datetime_subsets", &grib_accessor_bufr_extract_datetime_subsets, }, +{ "bufr_extract_subsets", &grib_accessor_bufr_extract_subsets, }, +{ "bufr_group", &grib_accessor_bufr_group, }, +{ "bufr_simple_thinning", &grib_accessor_bufr_simple_thinning, }, +{ "bufr_string_values", &grib_accessor_bufr_string_values, }, +{ "bufrdc_expanded_descriptors", &grib_accessor_bufrdc_expanded_descriptors, }, +{ "bytes", &grib_accessor_bytes, }, +{ "change_alternative_row_scanning", &grib_accessor_change_alternative_row_scanning, }, +{ "change_scanning_direction", &grib_accessor_change_scanning_direction, }, +{ "check_internal_version", &grib_accessor_check_internal_version, }, +{ "closest_date", &grib_accessor_closest_date, }, +{ "codeflag", &grib_accessor_codeflag, }, +{ "codetable", &grib_accessor_codetable, }, +{ "codetable_title", &grib_accessor_codetable_title, }, +{ "codetable_units", &grib_accessor_codetable_units, }, +{ "concept", &grib_accessor_concept, }, +{ "constant", &grib_accessor_constant, }, +{ "count_file", &grib_accessor_count_file, }, +{ "count_missing", &grib_accessor_count_missing, }, +{ "count_total", &grib_accessor_count_total, }, +{ "data_apply_bitmap", &grib_accessor_data_apply_bitmap, }, +{ "data_apply_boustrophedonic", &grib_accessor_data_apply_boustrophedonic, }, +{ "data_apply_boustrophedonic_bitmap", &grib_accessor_data_apply_boustrophedonic_bitmap, }, +{ "data_ccsds_packing", &grib_accessor_data_ccsds_packing, }, +{ "data_complex_packing", &grib_accessor_data_complex_packing, }, +{ "data_dummy_field", &grib_accessor_data_dummy_field, }, +{ "data_g1complex_packing", &grib_accessor_data_g1complex_packing, }, +{ "data_g1second_order_constant_width_packing", &grib_accessor_data_g1second_order_constant_width_packing, }, +{ "data_g1second_order_general_extended_packing", &grib_accessor_data_g1second_order_general_extended_packing, }, +{ "data_g1second_order_general_packing", &grib_accessor_data_g1second_order_general_packing, }, +{ "data_g1second_order_row_by_row_packing", &grib_accessor_data_g1second_order_row_by_row_packing, }, +{ "data_g1secondary_bitmap", &grib_accessor_data_g1secondary_bitmap, }, +{ "data_g1shsimple_packing", &grib_accessor_data_g1shsimple_packing, }, +{ "data_g1simple_packing", &grib_accessor_data_g1simple_packing, }, +{ "data_g22order_packing", &grib_accessor_data_g22order_packing, }, +{ "data_g2bifourier_packing", &grib_accessor_data_g2bifourier_packing, }, +{ "data_g2complex_packing", &grib_accessor_data_g2complex_packing, }, +{ "data_g2secondary_bitmap", &grib_accessor_data_g2secondary_bitmap, }, +{ "data_g2shsimple_packing", &grib_accessor_data_g2shsimple_packing, }, +{ "data_g2simple_packing", &grib_accessor_data_g2simple_packing, }, +{ "data_g2simple_packing_with_preprocessing", &grib_accessor_data_g2simple_packing_with_preprocessing, }, +{ "data_jpeg2000_packing", &grib_accessor_data_jpeg2000_packing, }, +{ "data_png_packing", &grib_accessor_data_png_packing, }, +{ "data_raw_packing", &grib_accessor_data_raw_packing, }, +{ "data_run_length_packing", &grib_accessor_data_run_length_packing, }, +{ "data_secondary_bitmap", &grib_accessor_data_secondary_bitmap, }, +{ "data_sh_packed", &grib_accessor_data_sh_packed, }, +{ "data_sh_unpacked", &grib_accessor_data_sh_unpacked, }, +{ "data_shsimple_packing", &grib_accessor_data_shsimple_packing, }, +{ "data_simple_packing", &grib_accessor_data_simple_packing, }, +{ "decimal_precision", &grib_accessor_decimal_precision, }, +{ "dictionary", &grib_accessor_dictionary, }, +{ "dirty", &grib_accessor_dirty, }, +{ "divdouble", &grib_accessor_divdouble, }, +{ "double", &grib_accessor_double, }, +{ "element", &grib_accessor_element, }, +{ "evaluate", &grib_accessor_evaluate, }, +{ "expanded_descriptors", &grib_accessor_expanded_descriptors, }, +{ "from_scale_factor_scaled_value", &grib_accessor_from_scale_factor_scaled_value, }, +{ "g1_half_byte_codeflag", &grib_accessor_g1_half_byte_codeflag, }, +{ "g1_message_length", &grib_accessor_g1_message_length, }, +{ "g1_section4_length", &grib_accessor_g1_section4_length, }, +{ "g1bitmap", &grib_accessor_g1bitmap, }, +{ "g1date", &grib_accessor_g1date, }, +{ "g1day_of_the_year_date", &grib_accessor_g1day_of_the_year_date, }, +{ "g1end_of_interval_monthly", &grib_accessor_g1end_of_interval_monthly, }, +{ "g1fcperiod", &grib_accessor_g1fcperiod, }, +{ "g1forecastmonth", &grib_accessor_g1forecastmonth, }, +{ "g1monthlydate", &grib_accessor_g1monthlydate, }, +{ "g1number_of_coded_values_sh_complex", &grib_accessor_g1number_of_coded_values_sh_complex, }, +{ "g1number_of_coded_values_sh_simple", &grib_accessor_g1number_of_coded_values_sh_simple, }, +{ "g1step_range", &grib_accessor_g1step_range, }, +{ "g1verificationdate", &grib_accessor_g1verificationdate, }, +{ "g2_aerosol", &grib_accessor_g2_aerosol, }, +{ "g2_chemical", &grib_accessor_g2_chemical, }, +{ "g2_eps", &grib_accessor_g2_eps, }, +{ "g2_mars_labeling", &grib_accessor_g2_mars_labeling, }, +{ "g2bitmap", &grib_accessor_g2bitmap, }, +{ "g2bitmap_present", &grib_accessor_g2bitmap_present, }, +{ "g2date", &grib_accessor_g2date, }, +{ "g2end_step", &grib_accessor_g2end_step, }, +{ "g2grid", &grib_accessor_g2grid, }, +{ "g2latlon", &grib_accessor_g2latlon, }, +{ "g2level", &grib_accessor_g2level, }, +{ "g2lon", &grib_accessor_g2lon, }, +{ "g2step_range", &grib_accessor_g2step_range, }, +{ "gaussian_grid_name", &grib_accessor_gaussian_grid_name, }, +{ "gds_is_present", &grib_accessor_gds_is_present, }, +{ "gds_not_present_bitmap", &grib_accessor_gds_not_present_bitmap, }, +{ "gen", &grib_accessor_gen, }, +{ "getenv", &grib_accessor_getenv, }, +{ "global_gaussian", &grib_accessor_global_gaussian, }, +{ "group", &grib_accessor_group, }, +{ "gts_header", &grib_accessor_gts_header, }, +{ "hash_array", &grib_accessor_hash_array, }, +{ "headers_only", &grib_accessor_headers_only, }, +{ "ibmfloat", &grib_accessor_ibmfloat, }, +{ "ieeefloat", &grib_accessor_ieeefloat, }, +{ "ifs_param", &grib_accessor_ifs_param, }, +{ "iterator", &grib_accessor_iterator, }, +{ "julian_date", &grib_accessor_julian_date, }, +{ "julian_day", &grib_accessor_julian_day, }, +{ "ksec1expver", &grib_accessor_ksec1expver, }, +{ "label", &grib_accessor_label, }, +{ "latitudes", &grib_accessor_latitudes, }, +{ "latlon_increment", &grib_accessor_latlon_increment, }, +{ "latlonvalues", &grib_accessor_latlonvalues, }, +{ "library_version", &grib_accessor_library_version, }, +{ "local_definition", &grib_accessor_local_definition, }, +{ "long", &grib_accessor_long, }, +{ "long_vector", &grib_accessor_long_vector, }, +{ "longitudes", &grib_accessor_longitudes, }, +{ "lookup", &grib_accessor_lookup, }, +{ "mars_param", &grib_accessor_mars_param, }, +{ "mars_step", &grib_accessor_mars_step, }, +{ "md5", &grib_accessor_md5, }, +{ "message", &grib_accessor_message, }, +{ "message_copy", &grib_accessor_message_copy, }, +{ "multdouble", &grib_accessor_multdouble, }, +{ "nearest", &grib_accessor_nearest, }, +{ "non_alpha", &grib_accessor_non_alpha, }, +{ "number_of_coded_values", &grib_accessor_number_of_coded_values, }, +{ "number_of_points", &grib_accessor_number_of_points, }, +{ "number_of_points_gaussian", &grib_accessor_number_of_points_gaussian, }, +{ "number_of_values", &grib_accessor_number_of_values, }, +{ "number_of_values_data_raw_packing", &grib_accessor_number_of_values_data_raw_packing, }, +{ "octahedral_gaussian", &grib_accessor_octahedral_gaussian, }, +{ "octet_number", &grib_accessor_octet_number, }, +{ "offset_file", &grib_accessor_offset_file, }, +{ "offset_values", &grib_accessor_offset_values, }, +{ "optimal_step_units", &grib_accessor_optimal_step_units, }, +{ "pack_bufr_values", &grib_accessor_pack_bufr_values, }, +{ "packing_type", &grib_accessor_packing_type, }, +{ "pad", &grib_accessor_pad, }, +{ "padding", &grib_accessor_padding, }, +{ "padto", &grib_accessor_padto, }, +{ "padtoeven", &grib_accessor_padtoeven, }, +{ "padtomultiple", &grib_accessor_padtomultiple, }, +{ "position", &grib_accessor_position, }, +{ "proj_string", &grib_accessor_proj_string, }, +{ "raw", &grib_accessor_raw, }, +{ "rdbtime_guess_date", &grib_accessor_rdbtime_guess_date, }, +{ "reference_value_error", &grib_accessor_reference_value_error, }, +{ "round", &grib_accessor_round, }, +{ "scale", &grib_accessor_scale, }, +{ "scale_values", &grib_accessor_scale_values, }, +{ "second_order_bits_per_value", &grib_accessor_second_order_bits_per_value, }, +{ "section", &grib_accessor_section, }, +{ "section_length", &grib_accessor_section_length, }, +{ "section_padding", &grib_accessor_section_padding, }, +{ "section_pointer", &grib_accessor_section_pointer, }, +{ "select_step_template", &grib_accessor_select_step_template, }, +{ "sexagesimal2decimal", &grib_accessor_sexagesimal2decimal, }, +{ "signed", &grib_accessor_signed, }, +{ "signed_bits", &grib_accessor_signed_bits, }, +{ "simple_packing_error", &grib_accessor_simple_packing_error, }, +{ "size", &grib_accessor_size, }, +{ "smart_table", &grib_accessor_smart_table, }, +{ "smart_table_column", &grib_accessor_smart_table_column, }, +{ "spd", &grib_accessor_spd, }, +{ "spectral_truncation", &grib_accessor_spectral_truncation, }, +{ "sprintf", &grib_accessor_sprintf, }, +{ "statistics", &grib_accessor_statistics, }, +{ "statistics_spectral", &grib_accessor_statistics_spectral, }, +{ "step_human_readable", &grib_accessor_step_human_readable, }, +{ "step_in_units", &grib_accessor_step_in_units, }, +{ "sum", &grib_accessor_sum, }, +{ "suppressed", &grib_accessor_suppressed, }, +{ "time", &grib_accessor_time, }, +{ "to_double", &grib_accessor_to_double, }, +{ "to_integer", &grib_accessor_to_integer, }, +{ "to_string", &grib_accessor_to_string, }, +{ "transient", &grib_accessor_transient, }, +{ "transient_darray", &grib_accessor_transient_darray, }, +{ "trim", &grib_accessor_trim, }, +{ "uint16", &grib_accessor_uint16, }, +{ "uint32", &grib_accessor_uint32, }, +{ "uint32_little_endian", &grib_accessor_uint32_little_endian, }, +{ "uint64", &grib_accessor_uint64, }, +{ "uint64_little_endian", &grib_accessor_uint64_little_endian, }, +{ "uint8", &grib_accessor_uint8, }, +{ "unexpanded_descriptors", &grib_accessor_unexpanded_descriptors, }, +{ "unpack_bufr_values", &grib_accessor_unpack_bufr_values, }, +{ "unsigned", &grib_accessor_unsigned, }, +{ "unsigned_bits", &grib_accessor_unsigned_bits, }, +{ "validity_date", &grib_accessor_validity_date, }, +{ "validity_time", &grib_accessor_validity_time, }, +{ "values", &grib_accessor_values, }, +{ "variable", &grib_accessor_variable, }, +{ "vector", &grib_accessor_vector, }, +{ "when", &grib_accessor_when, }, diff --git a/src/grib_accessor_factory_hash_list b/src/grib_accessor_factory_hash_list index ebb16f62f..1530448d4 100644 --- a/src/grib_accessor_factory_hash_list +++ b/src/grib_accessor_factory_hash_list @@ -1,207 +1,207 @@ /* This file is automatically generated by ./make_class.pl, do not edit */ -abstract_long_vector, &grib_accessor_class_abstract_long_vector -abstract_vector, &grib_accessor_class_abstract_vector -ascii, &grib_accessor_class_ascii -bit, &grib_accessor_class_bit -bitmap, &grib_accessor_class_bitmap -bits, &grib_accessor_class_bits -bits_per_value, &grib_accessor_class_bits_per_value -blob, &grib_accessor_class_blob -budgdate, &grib_accessor_class_budgdate -bufr_data_array, &grib_accessor_class_bufr_data_array -bufr_data_element, &grib_accessor_class_bufr_data_element -bufr_elements_table, &grib_accessor_class_bufr_elements_table -bufr_extract_area_subsets, &grib_accessor_class_bufr_extract_area_subsets -bufr_extract_datetime_subsets, &grib_accessor_class_bufr_extract_datetime_subsets -bufr_extract_subsets, &grib_accessor_class_bufr_extract_subsets -bufr_group, &grib_accessor_class_bufr_group -bufr_simple_thinning, &grib_accessor_class_bufr_simple_thinning -bufr_string_values, &grib_accessor_class_bufr_string_values -bufrdc_expanded_descriptors, &grib_accessor_class_bufrdc_expanded_descriptors -bytes, &grib_accessor_class_bytes -cf_var_name, &grib_accessor_class_cf_var_name -change_alternative_row_scanning, &grib_accessor_class_change_alternative_row_scanning -change_scanning_direction, &grib_accessor_class_change_scanning_direction -check_internal_version, &grib_accessor_class_check_internal_version -closest_date, &grib_accessor_class_closest_date -codeflag, &grib_accessor_class_codeflag -codetable, &grib_accessor_class_codetable -codetable_title, &grib_accessor_class_codetable_title -codetable_units, &grib_accessor_class_codetable_units -concept, &grib_accessor_class_concept -constant, &grib_accessor_class_constant -count_file, &grib_accessor_class_count_file -count_missing, &grib_accessor_class_count_missing -count_total, &grib_accessor_class_count_total -data_apply_bitmap, &grib_accessor_class_data_apply_bitmap -data_apply_boustrophedonic, &grib_accessor_class_data_apply_boustrophedonic -data_apply_boustrophedonic_bitmap, &grib_accessor_class_data_apply_boustrophedonic_bitmap -data_ccsds_packing, &grib_accessor_class_data_ccsds_packing -data_complex_packing, &grib_accessor_class_data_complex_packing -data_dummy_field, &grib_accessor_class_data_dummy_field -data_g1complex_packing, &grib_accessor_class_data_g1complex_packing -data_g1second_order_constant_width_packing, &grib_accessor_class_data_g1second_order_constant_width_packing -data_g1second_order_general_extended_packing, &grib_accessor_class_data_g1second_order_general_extended_packing -data_g1second_order_general_packing, &grib_accessor_class_data_g1second_order_general_packing -data_g1second_order_row_by_row_packing, &grib_accessor_class_data_g1second_order_row_by_row_packing -data_g1secondary_bitmap, &grib_accessor_class_data_g1secondary_bitmap -data_g1shsimple_packing, &grib_accessor_class_data_g1shsimple_packing -data_g1simple_packing, &grib_accessor_class_data_g1simple_packing -data_g22order_packing, &grib_accessor_class_data_g22order_packing -data_g2bifourier_packing, &grib_accessor_class_data_g2bifourier_packing -data_g2complex_packing, &grib_accessor_class_data_g2complex_packing -data_g2secondary_bitmap, &grib_accessor_class_data_g2secondary_bitmap -data_g2shsimple_packing, &grib_accessor_class_data_g2shsimple_packing -data_g2simple_packing, &grib_accessor_class_data_g2simple_packing -data_g2simple_packing_with_preprocessing, &grib_accessor_class_data_g2simple_packing_with_preprocessing -data_jpeg2000_packing, &grib_accessor_class_data_jpeg2000_packing -data_png_packing, &grib_accessor_class_data_png_packing -data_raw_packing, &grib_accessor_class_data_raw_packing -data_run_length_packing, &grib_accessor_class_data_run_length_packing -data_secondary_bitmap, &grib_accessor_class_data_secondary_bitmap -data_sh_packed, &grib_accessor_class_data_sh_packed -data_sh_unpacked, &grib_accessor_class_data_sh_unpacked -data_shsimple_packing, &grib_accessor_class_data_shsimple_packing -data_simple_packing, &grib_accessor_class_data_simple_packing -decimal_precision, &grib_accessor_class_decimal_precision -dictionary, &grib_accessor_class_dictionary -dirty, &grib_accessor_class_dirty -divdouble, &grib_accessor_class_divdouble -double, &grib_accessor_class_double -element, &grib_accessor_class_element -evaluate, &grib_accessor_class_evaluate -expanded_descriptors, &grib_accessor_class_expanded_descriptors -from_scale_factor_scaled_value, &grib_accessor_class_from_scale_factor_scaled_value -g1_half_byte_codeflag, &grib_accessor_class_g1_half_byte_codeflag -g1_message_length, &grib_accessor_class_g1_message_length -g1_section4_length, &grib_accessor_class_g1_section4_length -g1bitmap, &grib_accessor_class_g1bitmap -g1date, &grib_accessor_class_g1date -g1day_of_the_year_date, &grib_accessor_class_g1day_of_the_year_date -g1end_of_interval_monthly, &grib_accessor_class_g1end_of_interval_monthly -g1fcperiod, &grib_accessor_class_g1fcperiod -g1forecastmonth, &grib_accessor_class_g1forecastmonth -g1monthlydate, &grib_accessor_class_g1monthlydate -g1number_of_coded_values_sh_complex, &grib_accessor_class_g1number_of_coded_values_sh_complex -g1number_of_coded_values_sh_simple, &grib_accessor_class_g1number_of_coded_values_sh_simple -g1step_range, &grib_accessor_class_g1step_range -g1verificationdate, &grib_accessor_class_g1verificationdate -g2_aerosol, &grib_accessor_class_g2_aerosol -g2_chemical, &grib_accessor_class_g2_chemical -g2_eps, &grib_accessor_class_g2_eps -g2_mars_labeling, &grib_accessor_class_g2_mars_labeling -g2bitmap, &grib_accessor_class_g2bitmap -g2bitmap_present, &grib_accessor_class_g2bitmap_present -g2date, &grib_accessor_class_g2date -g2end_step, &grib_accessor_class_g2end_step -g2grid, &grib_accessor_class_g2grid -g2latlon, &grib_accessor_class_g2latlon -g2level, &grib_accessor_class_g2level -g2lon, &grib_accessor_class_g2lon -g2step_range, &grib_accessor_class_g2step_range -gaussian_grid_name, &grib_accessor_class_gaussian_grid_name -gds_is_present, &grib_accessor_class_gds_is_present -gds_not_present_bitmap, &grib_accessor_class_gds_not_present_bitmap -gen, &grib_accessor_class_gen -getenv, &grib_accessor_class_getenv -global_gaussian, &grib_accessor_class_global_gaussian -group, &grib_accessor_class_group -gts_header, &grib_accessor_class_gts_header -hash_array, &grib_accessor_class_hash_array -headers_only, &grib_accessor_class_headers_only -ibmfloat, &grib_accessor_class_ibmfloat -ieeefloat, &grib_accessor_class_ieeefloat -ifs_param, &grib_accessor_class_ifs_param -iterator, &grib_accessor_class_iterator -julian_date, &grib_accessor_class_julian_date -julian_day, &grib_accessor_class_julian_day -ksec1expver, &grib_accessor_class_ksec1expver -label, &grib_accessor_class_label -latitudes, &grib_accessor_class_latitudes -latlon_increment, &grib_accessor_class_latlon_increment -latlonvalues, &grib_accessor_class_latlonvalues -library_version, &grib_accessor_class_library_version -local_definition, &grib_accessor_class_local_definition -long, &grib_accessor_class_long -long_vector, &grib_accessor_class_long_vector -longitudes, &grib_accessor_class_longitudes -lookup, &grib_accessor_class_lookup -mars_param, &grib_accessor_class_mars_param -mars_step, &grib_accessor_class_mars_step -md5, &grib_accessor_class_md5 -message, &grib_accessor_class_message -message_copy, &grib_accessor_class_message_copy -multdouble, &grib_accessor_class_multdouble -nearest, &grib_accessor_class_nearest -non_alpha, &grib_accessor_class_non_alpha -number_of_coded_values, &grib_accessor_class_number_of_coded_values -number_of_points, &grib_accessor_class_number_of_points -number_of_points_gaussian, &grib_accessor_class_number_of_points_gaussian -number_of_values, &grib_accessor_class_number_of_values -number_of_values_data_raw_packing, &grib_accessor_class_number_of_values_data_raw_packing -octahedral_gaussian, &grib_accessor_class_octahedral_gaussian -octet_number, &grib_accessor_class_octet_number -offset_file, &grib_accessor_class_offset_file -offset_values, &grib_accessor_class_offset_values -optimal_step_units, &grib_accessor_class_optimal_step_units -pack_bufr_values, &grib_accessor_class_pack_bufr_values -packing_type, &grib_accessor_class_packing_type -pad, &grib_accessor_class_pad -padding, &grib_accessor_class_padding -padto, &grib_accessor_class_padto -padtoeven, &grib_accessor_class_padtoeven -padtomultiple, &grib_accessor_class_padtomultiple -position, &grib_accessor_class_position -proj_string, &grib_accessor_class_proj_string -raw, &grib_accessor_class_raw -rdbtime_guess_date, &grib_accessor_class_rdbtime_guess_date -reference_value_error, &grib_accessor_class_reference_value_error -round, &grib_accessor_class_round -scale, &grib_accessor_class_scale -scale_values, &grib_accessor_class_scale_values -second_order_bits_per_value, &grib_accessor_class_second_order_bits_per_value -section, &grib_accessor_class_section -section_length, &grib_accessor_class_section_length -section_padding, &grib_accessor_class_section_padding -section_pointer, &grib_accessor_class_section_pointer -select_step_template, &grib_accessor_class_select_step_template -sexagesimal2decimal, &grib_accessor_class_sexagesimal2decimal -signed, &grib_accessor_class_signed -signed_bits, &grib_accessor_class_signed_bits -simple_packing_error, &grib_accessor_class_simple_packing_error -size, &grib_accessor_class_size -smart_table, &grib_accessor_class_smart_table -smart_table_column, &grib_accessor_class_smart_table_column -spd, &grib_accessor_class_spd -spectral_truncation, &grib_accessor_class_spectral_truncation -sprintf, &grib_accessor_class_sprintf -statistics, &grib_accessor_class_statistics -statistics_spectral, &grib_accessor_class_statistics_spectral -step_human_readable, &grib_accessor_class_step_human_readable -step_in_units, &grib_accessor_class_step_in_units -sum, &grib_accessor_class_sum -suppressed, &grib_accessor_class_suppressed -time, &grib_accessor_class_time -to_double, &grib_accessor_class_to_double -to_integer, &grib_accessor_class_to_integer -to_string, &grib_accessor_class_to_string -transient, &grib_accessor_class_transient -transient_darray, &grib_accessor_class_transient_darray -trim, &grib_accessor_class_trim -uint16, &grib_accessor_class_uint16 -uint32, &grib_accessor_class_uint32 -uint32_little_endian, &grib_accessor_class_uint32_little_endian -uint64, &grib_accessor_class_uint64 -uint64_little_endian, &grib_accessor_class_uint64_little_endian -uint8, &grib_accessor_class_uint8 -unexpanded_descriptors, &grib_accessor_class_unexpanded_descriptors -unpack_bufr_values, &grib_accessor_class_unpack_bufr_values -unsigned, &grib_accessor_class_unsigned -unsigned_bits, &grib_accessor_class_unsigned_bits -validity_date, &grib_accessor_class_validity_date -validity_time, &grib_accessor_class_validity_time -values, &grib_accessor_class_values -variable, &grib_accessor_class_variable -vector, &grib_accessor_class_vector -when, &grib_accessor_class_when +abstract_long_vector, &grib_accessor_abstract_long_vector +abstract_vector, &grib_accessor_abstract_vector +ascii, &grib_accessor_ascii +bit, &grib_accessor_bit +bitmap, &grib_accessor_bitmap +bits, &grib_accessor_bits +bits_per_value, &grib_accessor_bits_per_value +blob, &grib_accessor_blob +budgdate, &grib_accessor_budgdate +bufr_data_array, &grib_accessor_bufr_data_array +bufr_data_element, &grib_accessor_bufr_data_element +bufr_elements_table, &grib_accessor_bufr_elements_table +bufr_extract_area_subsets, &grib_accessor_bufr_extract_area_subsets +bufr_extract_datetime_subsets, &grib_accessor_bufr_extract_datetime_subsets +bufr_extract_subsets, &grib_accessor_bufr_extract_subsets +bufr_group, &grib_accessor_bufr_group +bufr_simple_thinning, &grib_accessor_bufr_simple_thinning +bufr_string_values, &grib_accessor_bufr_string_values +bufrdc_expanded_descriptors, &grib_accessor_bufrdc_expanded_descriptors +bytes, &grib_accessor_bytes +change_alternative_row_scanning, &grib_accessor_change_alternative_row_scanning +change_scanning_direction, &grib_accessor_change_scanning_direction +check_internal_version, &grib_accessor_check_internal_version +closest_date, &grib_accessor_closest_date +codeflag, &grib_accessor_codeflag +codetable, &grib_accessor_codetable +codetable_title, &grib_accessor_codetable_title +codetable_units, &grib_accessor_codetable_units +concept, &grib_accessor_concept +constant, &grib_accessor_constant +count_file, &grib_accessor_count_file +count_missing, &grib_accessor_count_missing +count_total, &grib_accessor_count_total +data_apply_bitmap, &grib_accessor_data_apply_bitmap +data_apply_boustrophedonic, &grib_accessor_data_apply_boustrophedonic +data_apply_boustrophedonic_bitmap, &grib_accessor_data_apply_boustrophedonic_bitmap +data_ccsds_packing, &grib_accessor_data_ccsds_packing +data_complex_packing, &grib_accessor_data_complex_packing +data_dummy_field, &grib_accessor_data_dummy_field +data_g1complex_packing, &grib_accessor_data_g1complex_packing +data_g1second_order_constant_width_packing, &grib_accessor_data_g1second_order_constant_width_packing +data_g1second_order_general_extended_packing, &grib_accessor_data_g1second_order_general_extended_packing +data_g1second_order_general_packing, &grib_accessor_data_g1second_order_general_packing +data_g1second_order_row_by_row_packing, &grib_accessor_data_g1second_order_row_by_row_packing +data_g1secondary_bitmap, &grib_accessor_data_g1secondary_bitmap +data_g1shsimple_packing, &grib_accessor_data_g1shsimple_packing +data_g1simple_packing, &grib_accessor_data_g1simple_packing +data_g22order_packing, &grib_accessor_data_g22order_packing +data_g2bifourier_packing, &grib_accessor_data_g2bifourier_packing +data_g2complex_packing, &grib_accessor_data_g2complex_packing +data_g2secondary_bitmap, &grib_accessor_data_g2secondary_bitmap +data_g2shsimple_packing, &grib_accessor_data_g2shsimple_packing +data_g2simple_packing, &grib_accessor_data_g2simple_packing +data_g2simple_packing_with_preprocessing, &grib_accessor_data_g2simple_packing_with_preprocessing +data_jpeg2000_packing, &grib_accessor_data_jpeg2000_packing +data_png_packing, &grib_accessor_data_png_packing +data_raw_packing, &grib_accessor_data_raw_packing +data_run_length_packing, &grib_accessor_data_run_length_packing +data_secondary_bitmap, &grib_accessor_data_secondary_bitmap +data_sh_packed, &grib_accessor_data_sh_packed +data_sh_unpacked, &grib_accessor_data_sh_unpacked +data_shsimple_packing, &grib_accessor_data_shsimple_packing +data_simple_packing, &grib_accessor_data_simple_packing +decimal_precision, &grib_accessor_decimal_precision +dictionary, &grib_accessor_dictionary +dirty, &grib_accessor_dirty +divdouble, &grib_accessor_divdouble +double, &grib_accessor_double +element, &grib_accessor_element +evaluate, &grib_accessor_evaluate +expanded_descriptors, &grib_accessor_expanded_descriptors +from_scale_factor_scaled_value, &grib_accessor_from_scale_factor_scaled_value +g1_half_byte_codeflag, &grib_accessor_g1_half_byte_codeflag +g1_message_length, &grib_accessor_g1_message_length +g1_section4_length, &grib_accessor_g1_section4_length +g1bitmap, &grib_accessor_g1bitmap +g1date, &grib_accessor_g1date +g1day_of_the_year_date, &grib_accessor_g1day_of_the_year_date +g1end_of_interval_monthly, &grib_accessor_g1end_of_interval_monthly +g1fcperiod, &grib_accessor_g1fcperiod +g1forecastmonth, &grib_accessor_g1forecastmonth +g1monthlydate, &grib_accessor_g1monthlydate +g1number_of_coded_values_sh_complex, &grib_accessor_g1number_of_coded_values_sh_complex +g1number_of_coded_values_sh_simple, &grib_accessor_g1number_of_coded_values_sh_simple +g1step_range, &grib_accessor_g1step_range +g1verificationdate, &grib_accessor_g1verificationdate +g2_aerosol, &grib_accessor_g2_aerosol +g2_chemical, &grib_accessor_g2_chemical +g2_eps, &grib_accessor_g2_eps +g2_mars_labeling, &grib_accessor_g2_mars_labeling +g2bitmap, &grib_accessor_g2bitmap +g2bitmap_present, &grib_accessor_g2bitmap_present +g2date, &grib_accessor_g2date +g2end_step, &grib_accessor_g2end_step +g2grid, &grib_accessor_g2grid +g2latlon, &grib_accessor_g2latlon +g2level, &grib_accessor_g2level +g2lon, &grib_accessor_g2lon +g2step_range, &grib_accessor_g2step_range +gaussian_grid_name, &grib_accessor_gaussian_grid_name +gds_is_present, &grib_accessor_gds_is_present +gds_not_present_bitmap, &grib_accessor_gds_not_present_bitmap +gen, &grib_accessor_gen +getenv, &grib_accessor_getenv +global_gaussian, &grib_accessor_global_gaussian +group, &grib_accessor_group +gts_header, &grib_accessor_gts_header +hash_array, &grib_accessor_hash_array +headers_only, &grib_accessor_headers_only +ibmfloat, &grib_accessor_ibmfloat +ieeefloat, &grib_accessor_ieeefloat +ifs_param, &grib_accessor_ifs_param +iterator, &grib_accessor_iterator +julian_date, &grib_accessor_julian_date +julian_day, &grib_accessor_julian_day +ksec1expver, &grib_accessor_ksec1expver +label, &grib_accessor_label +latitudes, &grib_accessor_latitudes +latlon_increment, &grib_accessor_latlon_increment +latlonvalues, &grib_accessor_latlonvalues +library_version, &grib_accessor_library_version +local_definition, &grib_accessor_local_definition +long, &grib_accessor_long +long_vector, &grib_accessor_long_vector +longitudes, &grib_accessor_longitudes +lookup, &grib_accessor_lookup +mars_param, &grib_accessor_mars_param +mars_step, &grib_accessor_mars_step +md5, &grib_accessor_md5 +message, &grib_accessor_message +message_copy, &grib_accessor_message_copy +multdouble, &grib_accessor_multdouble +nearest, &grib_accessor_nearest +non_alpha, &grib_accessor_non_alpha +number_of_coded_values, &grib_accessor_number_of_coded_values +number_of_points, &grib_accessor_number_of_points +number_of_points_gaussian, &grib_accessor_number_of_points_gaussian +number_of_values, &grib_accessor_number_of_values +number_of_values_data_raw_packing, &grib_accessor_number_of_values_data_raw_packing +octahedral_gaussian, &grib_accessor_octahedral_gaussian +octet_number, &grib_accessor_octet_number +offset_file, &grib_accessor_offset_file +offset_values, &grib_accessor_offset_values +optimal_step_units, &grib_accessor_optimal_step_units +pack_bufr_values, &grib_accessor_pack_bufr_values +packing_type, &grib_accessor_packing_type +pad, &grib_accessor_pad +padding, &grib_accessor_padding +padto, &grib_accessor_padto +padtoeven, &grib_accessor_padtoeven +padtomultiple, &grib_accessor_padtomultiple +position, &grib_accessor_position +proj_string, &grib_accessor_proj_string +raw, &grib_accessor_raw +rdbtime_guess_date, &grib_accessor_rdbtime_guess_date +reference_value_error, &grib_accessor_reference_value_error +round, &grib_accessor_round +scale, &grib_accessor_scale +scale_values, &grib_accessor_scale_values +second_order_bits_per_value, &grib_accessor_second_order_bits_per_value +section, &grib_accessor_section +section_length, &grib_accessor_section_length +section_padding, &grib_accessor_section_padding +section_pointer, &grib_accessor_section_pointer +select_step_template, &grib_accessor_select_step_template +sexagesimal2decimal, &grib_accessor_sexagesimal2decimal +signed, &grib_accessor_signed +signed_bits, &grib_accessor_signed_bits +simple_packing_error, &grib_accessor_simple_packing_error +size, &grib_accessor_size +smart_table, &grib_accessor_smart_table +smart_table_column, &grib_accessor_smart_table_column +spd, &grib_accessor_spd +spectral_truncation, &grib_accessor_spectral_truncation +sprintf, &grib_accessor_sprintf +statistics, &grib_accessor_statistics +statistics_spectral, &grib_accessor_statistics_spectral +step_human_readable, &grib_accessor_step_human_readable +step_in_units, &grib_accessor_step_in_units +sum, &grib_accessor_sum +suppressed, &grib_accessor_suppressed +time, &grib_accessor_time +to_double, &grib_accessor_to_double +to_integer, &grib_accessor_to_integer +to_string, &grib_accessor_to_string +transient, &grib_accessor_transient +transient_darray, &grib_accessor_transient_darray +trim, &grib_accessor_trim +uint16, &grib_accessor_uint16 +uint32, &grib_accessor_uint32 +uint32_little_endian, &grib_accessor_uint32_little_endian +uint64, &grib_accessor_uint64 +uint64_little_endian, &grib_accessor_uint64_little_endian +uint8, &grib_accessor_uint8 +unexpanded_descriptors, &grib_accessor_unexpanded_descriptors +unpack_bufr_values, &grib_accessor_unpack_bufr_values +unsigned, &grib_accessor_unsigned +unsigned_bits, &grib_accessor_unsigned_bits +validity_date, &grib_accessor_validity_date +validity_time, &grib_accessor_validity_time +values, &grib_accessor_values +variable, &grib_accessor_variable +vector, &grib_accessor_vector +when, &grib_accessor_when +cf_var_name, &grib_accessor_cf_var_name diff --git a/src/grib_api.h b/src/grib_api.h index 84566b108..09601899f 100644 --- a/src/grib_api.h +++ b/src/grib_api.h @@ -1169,6 +1169,8 @@ void grib_context_set_definitions_path(grib_context* c, const char* path); */ void grib_context_set_samples_path(grib_context* c, const char* path); +void grib_context_set_debug(grib_context* c, int mode); + /** * Sets memory procedures of the context * diff --git a/src/grib_buffer.cc b/src/grib_buffer.cc index cb313141c..ca84ce7bb 100644 --- a/src/grib_buffer.cc +++ b/src/grib_buffer.cc @@ -118,9 +118,9 @@ void grib_buffer_set_ulength(const grib_context* c, grib_buffer* b, size_t lengt static void update_offsets(grib_accessor* a, long len) { while (a) { - grib_section* s = a->sub_section; - a->offset += len; - grib_context_log(a->context, GRIB_LOG_DEBUG, "::::: grib_buffer : accessor %s is moving by %d bytes to %ld", a->name, len, a->offset); + grib_section* s = a->sub_section_; + a->offset_ += len; + grib_context_log(a->context_, GRIB_LOG_DEBUG, "::::: grib_buffer : accessor %s is moving by %d bytes to %ld", a->name_, len, a->offset_); if (s) update_offsets(s->block->first, len); a = a->next_; @@ -131,7 +131,7 @@ static void update_offsets_after(grib_accessor* a, long len) { while (a) { update_offsets(a->next_, len); - a = a->parent->owner; + a = a->parent_->owner; } } @@ -198,18 +198,18 @@ static void update_offsets_after(grib_accessor* a, long len) int grib_buffer_replace(grib_accessor* a, const unsigned char* data, size_t newsize, int update_lengths, int update_paddings) { - size_t offset = a->offset; + size_t offset = a->offset_; long oldsize = a->get_next_position_offset() - offset; long increase = (long)newsize - (long)oldsize; grib_buffer* buffer = grib_handle_of_accessor(a)->buffer; size_t message_length = buffer->ulength; - grib_context_log(a->context, GRIB_LOG_DEBUG, + grib_context_log(a->context_, GRIB_LOG_DEBUG, "grib_buffer_replace %s offset=%ld oldsize=%ld newsize=%ld message_length=%ld update_paddings=%d", - a->name, (long)offset, oldsize, (long)newsize, (long)message_length, update_paddings); + a->name_, (long)offset, oldsize, (long)newsize, (long)message_length, update_paddings); - grib_buffer_set_ulength(a->context, + grib_buffer_set_ulength(a->context_, buffer, buffer->ulength + increase); diff --git a/src/grib_bufr_descriptor.cc b/src/grib_bufr_descriptor.cc index 6b7f2b3ce..3f83f6ec7 100644 --- a/src/grib_bufr_descriptor.cc +++ b/src/grib_bufr_descriptor.cc @@ -17,7 +17,7 @@ bufr_descriptor* grib_bufr_descriptor_new(grib_accessor* tables_accessor, int co { bufr_descriptor* ret = accessor_bufr_elements_table_get_descriptor(tables_accessor, code, err); if (!silent && *err) - grib_context_log(tables_accessor->context, GRIB_LOG_ERROR, + grib_context_log(tables_accessor->context_, GRIB_LOG_ERROR, "unable to get descriptor %06d from table", code); return ret; } diff --git a/src/grib_dependency.cc b/src/grib_dependency.cc index 37c89dbbf..268ffa315 100644 --- a/src/grib_dependency.cc +++ b/src/grib_dependency.cc @@ -15,11 +15,11 @@ grib_handle* grib_handle_of_accessor(const grib_accessor* a) { - if (a->parent == NULL) { - return a->h; + if (a->parent_ == NULL) { + return a->h_; } else { - return a->parent->h; + return a->parent_->h; } } @@ -31,10 +31,10 @@ static grib_handle* handle_of(grib_accessor* observed) /* printf("+++++ %s = %p\n",observed->name,observed); */ /* printf("+++++ h=%p\n",observed->h); */ /* special case for BUFR attributes parentless */ - if (observed->parent == NULL) { - return observed->h; + if (observed->parent_ == NULL) { + return observed->h_; } - h = observed->parent->h; + h = observed->parent_->h; while (h->main) h = h->main; return h; diff --git a/src/grib_dumper.cc b/src/grib_dumper.cc index 1a8be288b..bfebdc2d3 100644 --- a/src/grib_dumper.cc +++ b/src/grib_dumper.cc @@ -8,9 +8,6 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/************************************** - * Enrico Fucile - **************************************/ #include "grib_api_internal.h" #if GRIB_PTHREADS diff --git a/src/grib_dumper_class_bufr_decode_C.cc b/src/grib_dumper_class_bufr_decode_C.cc index 6811cdf94..f1c1515e4 100644 --- a/src/grib_dumper_class_bufr_decode_C.cc +++ b/src/grib_dumper_class_bufr_decode_C.cc @@ -144,10 +144,10 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int r = 0; long count = 0; char* sval; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -168,19 +168,19 @@ static void dump_values(grib_dumper* d, grib_accessor* a) depth -= 2; - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, " CODES_CHECK(codes_get_double_array(h, \"#%d#%s\",dValues, &size), 0);\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, " CODES_CHECK(codes_get_double_array(h, \"#%d#%s\",dValues, &size), 0);\n", r, a->name_); else - fprintf(self->dumper.out, " CODES_CHECK(codes_get_double_array(h, \"%s\", dValues, &size), 0);\n", a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_get_double_array(h, \"%s\", dValues, &size), 0);\n", a->name_); } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (!grib_is_missing_double(a, value)) { sval = dval_to_string(c, value); if (r != 0) - fprintf(self->dumper.out, " CODES_CHECK(codes_get_double(h, \"#%d#%s\", &dVal), 0);\n", r, a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_get_double(h, \"#%d#%s\", &dVal), 0);\n", r, a->name_); else - fprintf(self->dumper.out, " CODES_CHECK(codes_get_double(h, \"%s\", &dVal), 0);\n", a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_get_double(h, \"%s\", &dVal), 0);\n", a->name_); grib_context_free(c, sval); } @@ -191,12 +191,12 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -215,9 +215,9 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* int err = 0; long count = 0; char* sval; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -238,13 +238,13 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* depth -= 2; - fprintf(self->dumper.out, " CODES_CHECK(codes_get_double_array(h, \"%s->%s\", dValues, &size), 0);\n", prefix, a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_get_double_array(h, \"%s->%s\", dValues, &size), 0);\n", prefix, a->name_); } else { - /* int r=compute_bufr_key_rank(h,self->keys,a->name); */ + /* int r=compute_bufr_key_rank(h,self->keys,a->name_); */ if (!grib_is_missing_double(a, value)) { sval = dval_to_string(c, value); - fprintf(self->dumper.out, " CODES_CHECK(codes_get_double(h, \"%s->%s\", &dVal), 0);\n", prefix, a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_get_double(h, \"%s->%s\", &dVal), 0);\n", prefix, a->name_); grib_context_free(c, sval); } @@ -253,8 +253,8 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* if (self->isLeaf == 0) { char* prefix1; - prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + strlen(prefix) + 5)); - snprintf(prefix1, 1024, "%s->%s", prefix, a->name); + prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + strlen(prefix) + 5)); + snprintf(prefix1, 1024, "%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -273,28 +273,28 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int err = 0; int r = 0; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; a->value_count(&count); size = count; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { if (self->isLeaf == 0) { char* prefix; int dofree = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -319,19 +319,19 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) depth -= 2; - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, " CODES_CHECK(codes_get_long_array(h, \"#%d#%s\", iValues, &size), 0);\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, " CODES_CHECK(codes_get_long_array(h, \"#%d#%s\", iValues, &size), 0);\n", r, a->name_); else - fprintf(self->dumper.out, " CODES_CHECK(codes_get_long_array(h, \"%s\", iValues, &size), 0);\n", a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_get_long_array(h, \"%s\", iValues, &size), 0);\n", a->name_); } else { - r = compute_bufr_key_rank(h, self->keys, a->name); - if (!codes_bufr_key_exclude_from_dump(a->name)) { + r = compute_bufr_key_rank(h, self->keys, a->name_); + if (!codes_bufr_key_exclude_from_dump(a->name_)) { if (!grib_is_missing_long(a, value)) { if (r != 0) - fprintf(self->dumper.out, " CODES_CHECK(codes_get_long(h, \"#%d#%s\", &iVal), 0);\n", r, a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_get_long(h, \"#%d#%s\", &iVal), 0);\n", r, a->name_); else - fprintf(self->dumper.out, " CODES_CHECK(codes_get_long(h, \"%s\", &iVal), 0);\n", a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_get_long(h, \"%s\", &iVal), 0);\n", a->name_); } } } @@ -341,12 +341,12 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -363,9 +363,9 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr size_t size = 0; int err = 0; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -386,13 +386,13 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr depth -= 2; - fprintf(self->dumper.out, " CODES_CHECK(codes_get_long_array(h, \"%s->%s\", iValues, &size), 0);\n", prefix, a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_get_long_array(h, \"%s->%s\", iValues, &size), 0);\n", prefix, a->name_); } else { - /* int r=compute_bufr_key_rank(h,self->keys,a->name); */ + /* int r=compute_bufr_key_rank(h,self->keys,a->name_); */ if (!codes_bufr_key_exclude_from_dump(prefix)) { if (!grib_is_missing_long(a, value)) { - fprintf(self->dumper.out, " CODES_CHECK(codes_get_long(h, \"%s->%s\", &iVal), 0);\n", prefix, a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_get_long(h, \"%s->%s\", &iVal), 0);\n", prefix, a->name_); } } } @@ -400,8 +400,8 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr if (self->isLeaf == 0) { char* prefix1; - prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + strlen(prefix) + 5)); - snprintf(prefix1, 1024, "%s->%s", prefix, a->name); + prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + strlen(prefix) + 5)); + snprintf(prefix1, 1024, "%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -425,19 +425,19 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) grib_handle* h = grib_handle_of_accessor(a); grib_context* c = h->context; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->unpack_double(&value, &size); self->empty = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (!grib_is_missing_double(a, value)) { sval = dval_to_string(c, value); if (r != 0) - fprintf(self->dumper.out, " CODES_CHECK(codes_get_double(h, \"#%d#%s\", &dVal), 0);\n", r, a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_get_double(h, \"#%d#%s\", &dVal), 0);\n", r, a->name_); else - fprintf(self->dumper.out, " CODES_CHECK(codes_get_double(h, \"%s\", &dVal), 0);\n", a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_get_double(h, \"%s\", &dVal), 0);\n", a->name_); grib_context_free(c, sval); } @@ -447,12 +447,12 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -472,9 +472,9 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm int r = 0; grib_handle* h = grib_handle_of_accessor(a); - c = a->context; + c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -500,10 +500,10 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm err = a->unpack_string_array(values, &size); if (self->isLeaf == 0) { - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, " codes_get_string_array(h, \"#%d#%s\", sValues, &size);\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, " codes_get_string_array(h, \"#%d#%s\", sValues, &size);\n", r, a->name_); else - fprintf(self->dumper.out, " codes_get_string_array(h, \"%s\", sValues, &size);\n", a->name); + fprintf(self->dumper.out, " codes_get_string_array(h, \"%s\", sValues, &size);\n", a->name_); } if (self->isLeaf == 0) { @@ -511,12 +511,12 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -536,18 +536,18 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */ size_t size = MAX_STRING_SIZE; char* p = NULL; - grib_context* c = a->context; + grib_context* c = a->context_; int r = 0, err = 0; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; self->empty = 0; err = a->unpack_string(value, &size); p = value; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (grib_is_missing_string(a, (unsigned char*)value, size)) { return; } @@ -562,9 +562,9 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) if (self->isLeaf == 0) { depth += 2; if (r != 0) - fprintf(self->dumper.out, " CODES_CHECK(codes_get_string(h, \"#%d#%s\", sVal, &size), 0);\n", r, a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_get_string(h, \"#%d#%s\", sVal, &size), 0);\n", r, a->name_); else - fprintf(self->dumper.out, " CODES_CHECK(codes_get_string(h, \"%s\", sVal, &size), 0);\n", a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_get_string(h, \"%s\", sVal, &size), 0);\n", a->name_); } if (self->isLeaf == 0) { @@ -572,12 +572,12 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -613,9 +613,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key) static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_decode_C* self = (grib_dumper_bufr_decode_C*)d; - if (strcmp(a->name, "BUFR")==0 || - strcmp(a->name, "GRIB")==0 || - strcmp(a->name, "META")==0) { + if (strcmp(a->name_, "BUFR")==0 || + strcmp(a->name_, "GRIB")==0 || + strcmp(a->name_, "META")==0) { grib_handle* h = grib_handle_of_accessor(a); depth = 2; self->empty = 1; @@ -629,8 +629,8 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); depth -= 2; } - else if (strcmp(a->name, "groupNumber")==0) { - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + else if (strcmp(a->name_, "groupNumber")==0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->empty = 1; depth += 2; @@ -647,26 +647,26 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix int i = 0; grib_dumper_bufr_decode_C* self = (grib_dumper_bufr_decode_C*)d; unsigned long flags; - while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { + while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes_[i]) { self->isAttribute = 1; - if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes[i]->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { + if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes_[i]->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) { i++; continue; } - self->isLeaf = a->attributes[i]->attributes[0] == NULL ? 1 : 0; - flags = a->attributes[i]->flags; - a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (a->attributes[i]->get_native_type()) { + self->isLeaf = a->attributes_[i]->attributes_[0] == NULL ? 1 : 0; + flags = a->attributes_[i]->flags_; + a->attributes_[i]->flags_ |= GRIB_ACCESSOR_FLAG_DUMP; + switch (a->attributes_[i]->get_native_type()) { case GRIB_TYPE_LONG: - dump_long_attribute(d, a->attributes[i], prefix); + dump_long_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_DOUBLE: - dump_values_attribute(d, a->attributes[i], prefix); + dump_values_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_STRING: break; } - a->attributes[i]->flags = flags; + a->attributes_[i]->flags_ = flags; i++; } self->isLeaf = 0; diff --git a/src/grib_dumper_class_bufr_decode_filter.cc b/src/grib_dumper_class_bufr_decode_filter.cc index 87cb0e2fe..3c8811320 100644 --- a/src/grib_dumper_class_bufr_decode_filter.cc +++ b/src/grib_dumper_class_bufr_decode_filter.cc @@ -134,10 +134,10 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int err = 0; int r; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -151,18 +151,18 @@ static void dump_values(grib_dumper* d, grib_accessor* a) self->empty = 0; if (size > 1) { - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, "print \"#%d#%s=[#%d#%s]\";\n", r, a->name, r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, "print \"#%d#%s=[#%d#%s]\";\n", r, a->name_, r, a->name_); else - fprintf(self->dumper.out, "print \"%s=[%s]\";\n", a->name, a->name); + fprintf(self->dumper.out, "print \"%s=[%s]\";\n", a->name_, a->name_); } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (!grib_is_missing_double(a, value)) { if (r != 0) - fprintf(self->dumper.out, "print \"#%d#%s=[#%d#%s]\";\n", r, a->name, r, a->name); + fprintf(self->dumper.out, "print \"#%d#%s=[#%d#%s]\";\n", r, a->name_, r, a->name_); else - fprintf(self->dumper.out, "print \"%s=[%s]\";\n", a->name, a->name); + fprintf(self->dumper.out, "print \"%s=[%s]\";\n", a->name_, a->name_); } } @@ -171,12 +171,12 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -194,9 +194,9 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* size_t size = 0; int err = 0; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -209,17 +209,17 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* self->empty = 0; if (size > 1) { - fprintf(self->dumper.out, "print \"%s->%s = [%s->%s]\";\n", prefix, a->name, prefix, a->name); + fprintf(self->dumper.out, "print \"%s->%s = [%s->%s]\";\n", prefix, a->name_, prefix, a->name_); } else { if (!grib_is_missing_double(a, value)) { - fprintf(self->dumper.out, "print \"%s->%s = [%s->%s]\";\n", prefix, a->name, prefix, a->name); + fprintf(self->dumper.out, "print \"%s->%s = [%s->%s]\";\n", prefix, a->name_, prefix, a->name_); } } if (self->isLeaf == 0) { - char* prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + strlen(prefix) + 5)); - snprintf(prefix1, 1024, "%s->%s", prefix, a->name); + char* prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + strlen(prefix) + 5)); + snprintf(prefix1, 1024, "%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -238,28 +238,28 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int err = 0; int r = 0; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; a->value_count(&count); size = count; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { if (self->isLeaf == 0) { char* prefix; int dofree = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -277,18 +277,18 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) self->empty = 0; if (size > 1) { - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, "print \"#%d#%s=[#%d#%s]\";\n", r, a->name, r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, "print \"#%d#%s=[#%d#%s]\";\n", r, a->name_, r, a->name_); else - fprintf(self->dumper.out, "print \"%s=[%s]\";\n", a->name, a->name); + fprintf(self->dumper.out, "print \"%s=[%s]\";\n", a->name_, a->name_); } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (!grib_is_missing_long(a, value)) { if (r != 0) - fprintf(self->dumper.out, "print \"#%d#%s=[#%d#%s]\";\n", r, a->name, r, a->name); + fprintf(self->dumper.out, "print \"#%d#%s=[#%d#%s]\";\n", r, a->name_, r, a->name_); else - fprintf(self->dumper.out, "print \"%s=[%s]\";\n", a->name, a->name); + fprintf(self->dumper.out, "print \"%s=[%s]\";\n", a->name_, a->name_); } } @@ -297,12 +297,12 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -316,18 +316,18 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr { grib_dumper_bufr_decode_filter* self = (grib_dumper_bufr_decode_filter*)d; int err = 0; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; self->empty = 0; if (!codes_bufr_key_exclude_from_dump(prefix)) { - fprintf(self->dumper.out, "print \"%s->%s = [%s->%s]\";\n", prefix, a->name, prefix, a->name); + fprintf(self->dumper.out, "print \"%s->%s = [%s->%s]\";\n", prefix, a->name_, prefix, a->name_); } if (self->isLeaf == 0) { - char* prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + strlen(prefix) + 5)); - snprintf(prefix1, 1024, "%s->%s", prefix, a->name); + char* prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + strlen(prefix) + 5)); + snprintf(prefix1, 1024, "%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -350,19 +350,19 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) grib_handle* h = grib_handle_of_accessor(a); grib_context* c = h->context; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->unpack_double(&value, &size); self->begin = 0; self->empty = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (!grib_is_missing_double(a, value)) { if (r != 0) - fprintf(self->dumper.out, "print \"#%d#%s=[#%d#%s]\";\n", r, a->name, r, a->name); + fprintf(self->dumper.out, "print \"#%d#%s=[#%d#%s]\";\n", r, a->name_, r, a->name_); else - fprintf(self->dumper.out, "print \"%s=[%s]\";\n", a->name, a->name); + fprintf(self->dumper.out, "print \"%s=[%s]\";\n", a->name_, a->name_); } if (self->isLeaf == 0) { @@ -370,12 +370,12 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -394,9 +394,9 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm int r = 0; grib_handle* h = grib_handle_of_accessor(a); - c = a->context; + c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -410,10 +410,10 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm if (self->isLeaf == 0) { depth += 2; - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, "print \"#%d#%s=[#%d#%s]\";\n", r, a->name, r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, "print \"#%d#%s=[#%d#%s]\";\n", r, a->name_, r, a->name_); else - fprintf(self->dumper.out, "print \"%s=[%s]\";\n", a->name, a->name); + fprintf(self->dumper.out, "print \"%s=[%s]\";\n", a->name_, a->name_); } self->empty = 0; @@ -423,12 +423,12 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -446,11 +446,11 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */ size_t size = MAX_STRING_SIZE; char* p = NULL; - grib_context* c = a->context; + grib_context* c = a->context_; int r =0, err = 0; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; self->begin = 0; @@ -459,7 +459,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) err = a->unpack_string(value, &size); p = value; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (grib_is_missing_string(a, (unsigned char*)value, size)) { return; } @@ -473,9 +473,9 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) if (self->isLeaf == 0) { depth += 2; if (r != 0) - fprintf(self->dumper.out, "print \"#%d#%s=[#%d#%s]\";\n", r, a->name, r, a->name); + fprintf(self->dumper.out, "print \"#%d#%s=[#%d#%s]\";\n", r, a->name_, r, a->name_); else - fprintf(self->dumper.out, "print \"%s=[%s]\";\n", a->name, a->name); + fprintf(self->dumper.out, "print \"%s=[%s]\";\n", a->name_, a->name_); } if (self->isLeaf == 0) { @@ -483,12 +483,12 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -521,9 +521,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key) static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_decode_filter* self = (grib_dumper_bufr_decode_filter*)d; - if (strcmp(a->name, "BUFR")==0 || - strcmp(a->name, "GRIB")==0 || - strcmp(a->name, "META")==0) { + if (strcmp(a->name_, "BUFR")==0 || + strcmp(a->name_, "GRIB")==0 || + strcmp(a->name_, "META")==0) { grib_handle* h = grib_handle_of_accessor(a); depth = 2; self->begin = 1; @@ -538,8 +538,8 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); depth -= 2; } - else if (strcmp(a->name, "groupNumber")==0) { - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + else if (strcmp(a->name_, "groupNumber")==0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->begin = 1; self->empty = 1; @@ -557,29 +557,29 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix int i = 0; grib_dumper_bufr_decode_filter* self = (grib_dumper_bufr_decode_filter*)d; unsigned long flags; - while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { + while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes_[i]) { self->isAttribute = 1; - if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes[i]->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { + if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes_[i]->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) { i++; continue; } - self->isLeaf = a->attributes[i]->attributes[0] == NULL ? 1 : 0; + self->isLeaf = a->attributes_[i]->attributes_[0] == NULL ? 1 : 0; /* fprintf(self->dumper.out,","); */ /* fprintf(self->dumper.out,"\n%-*s",depth," "); */ - /* fprintf(out,"\"%s\" : ",a->attributes[i]->name); */ - flags = a->attributes[i]->flags; - a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (a->attributes[i]->get_native_type()) { + /* fprintf(out,"\"%s\" : ",a->attributes_[i]->name); */ + flags = a->attributes_[i]->flags_; + a->attributes_[i]->flags_ |= GRIB_ACCESSOR_FLAG_DUMP; + switch (a->attributes_[i]->get_native_type()) { case GRIB_TYPE_LONG: - dump_long_attribute(d, a->attributes[i], prefix); + dump_long_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_DOUBLE: - dump_values_attribute(d, a->attributes[i], prefix); + dump_values_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_STRING: break; } - a->attributes[i]->flags = flags; + a->attributes_[i]->flags_ = flags; i++; } self->isLeaf = 0; diff --git a/src/grib_dumper_class_bufr_decode_fortran.cc b/src/grib_dumper_class_bufr_decode_fortran.cc index dbc4ed271..10570df50 100644 --- a/src/grib_dumper_class_bufr_decode_fortran.cc +++ b/src/grib_dumper_class_bufr_decode_fortran.cc @@ -136,10 +136,10 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int err = 0; int r = 0; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -154,18 +154,18 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if (size > 1) { depth -= 2; - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, " call codes_get(ibufr, '#%d#%s', rValues)\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, " call codes_get(ibufr, '#%d#%s', rValues)\n", r, a->name_); else - fprintf(self->dumper.out, " call codes_get(ibufr, '%s', rValues)\n", a->name); + fprintf(self->dumper.out, " call codes_get(ibufr, '%s', rValues)\n", a->name_); } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (!grib_is_missing_double(a, value)) { if (r != 0) - fprintf(self->dumper.out, " call codes_get(ibufr, '#%d#%s', rVal)\n", r, a->name); + fprintf(self->dumper.out, " call codes_get(ibufr, '#%d#%s', rVal)\n", r, a->name_); else - fprintf(self->dumper.out, " call codes_get(ibufr, '%s', rVal)\n", a->name); + fprintf(self->dumper.out, " call codes_get(ibufr, '%s', rVal)\n", a->name_); } } @@ -174,12 +174,12 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -197,9 +197,9 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* size_t size = 0; int err = 0; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -212,19 +212,19 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* self->empty = 0; if (size > 1) { - fprintf(self->dumper.out, " call codes_get(ibufr, '%s->%s', rValues)\n", prefix, a->name); + fprintf(self->dumper.out, " call codes_get(ibufr, '%s->%s', rValues)\n", prefix, a->name_); } else { if (!grib_is_missing_double(a, value)) { - fprintf(self->dumper.out, " call codes_get(ibufr, '%s->%s', rVal)\n", prefix, a->name); + fprintf(self->dumper.out, " call codes_get(ibufr, '%s->%s', rVal)\n", prefix, a->name_); } } if (self->isLeaf == 0) { char* prefix1; - prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + strlen(prefix) + 5)); - snprintf(prefix1, 1024, "%s->%s", prefix, a->name); + prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + strlen(prefix) + 5)); + snprintf(prefix1, 1024, "%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -243,28 +243,28 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int err = 0; int r = 0; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; a->value_count(&count); size = count; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { if (self->isLeaf == 0) { char* prefix; int dofree = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -284,18 +284,18 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) depth -= 2; fprintf(self->dumper.out, " if(allocated(iValues)) deallocate(iValues)\n"); - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, " call codes_get(ibufr, '#%d#%s', iValues)\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, " call codes_get(ibufr, '#%d#%s', iValues)\n", r, a->name_); else - fprintf(self->dumper.out, " call codes_get(ibufr, '%s', iValues)\n", a->name); + fprintf(self->dumper.out, " call codes_get(ibufr, '%s', iValues)\n", a->name_); } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (!grib_is_missing_long(a, value)) { if (r != 0) - fprintf(self->dumper.out, " call codes_get(ibufr, '#%d#%s', iVal)\n", r, a->name); + fprintf(self->dumper.out, " call codes_get(ibufr, '#%d#%s', iVal)\n", r, a->name_); else - fprintf(self->dumper.out, " call codes_get(ibufr, '%s', iVal)\n", a->name); + fprintf(self->dumper.out, " call codes_get(ibufr, '%s', iVal)\n", a->name_); } } @@ -304,12 +304,12 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024,"#%d#%s", r, a->name); + snprintf(prefix, 1024,"#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -326,9 +326,9 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr size_t size = 0; int err = 0; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -344,12 +344,12 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr depth -= 2; fprintf(self->dumper.out, " if(allocated(iValues)) deallocate(iValues)\n"); - fprintf(self->dumper.out, " call codes_get(ibufr, '%s->%s', iValues)\n", prefix, a->name); + fprintf(self->dumper.out, " call codes_get(ibufr, '%s->%s', iValues)\n", prefix, a->name_); } else { if (!codes_bufr_key_exclude_from_dump(prefix)) { if (!grib_is_missing_long(a, value)) { - fprintf(self->dumper.out, " call codes_get(ibufr, '%s->%s', iVal)\n", prefix, a->name); + fprintf(self->dumper.out, " call codes_get(ibufr, '%s->%s', iVal)\n", prefix, a->name_); } } } @@ -357,8 +357,8 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr if (self->isLeaf == 0) { char* prefix1; - prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + strlen(prefix) + 5)); - snprintf(prefix1, 1024,"%s->%s", prefix, a->name); + prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + strlen(prefix) + 5)); + snprintf(prefix1, 1024,"%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -381,18 +381,18 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) grib_handle* h = grib_handle_of_accessor(a); grib_context* c = h->context; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->unpack_double(&value, &size); self->empty = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (!grib_is_missing_double(a, value)) { if (r != 0) - fprintf(self->dumper.out, " call codes_get(ibufr,'#%d#%s', rVal)\n", r, a->name); + fprintf(self->dumper.out, " call codes_get(ibufr,'#%d#%s', rVal)\n", r, a->name_); else - fprintf(self->dumper.out, " call codes_get(ibufr,'%s', rVal)\n", a->name); + fprintf(self->dumper.out, " call codes_get(ibufr,'%s', rVal)\n", a->name_); } if (self->isLeaf == 0) { @@ -400,12 +400,12 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -424,9 +424,9 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm int r = 0; grib_handle* h = grib_handle_of_accessor(a); - c = a->context; + c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -442,10 +442,10 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm self->empty = 0; if (self->isLeaf == 0) { - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, " call codes_get_string_array(ibufr,'#%d#%s',sValues)\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, " call codes_get_string_array(ibufr,'#%d#%s',sValues)\n", r, a->name_); else - fprintf(self->dumper.out, " call codes_get_string_array(ibufr,'%s',sValues)\n", a->name); + fprintf(self->dumper.out, " call codes_get_string_array(ibufr,'%s',sValues)\n", a->name_); } if (self->isLeaf == 0) { @@ -453,12 +453,12 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -476,18 +476,18 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */ size_t size = MAX_STRING_SIZE; char* p = NULL; - grib_context* c = a->context; + grib_context* c = a->context_; int r = 0, err = 0; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; self->empty = 0; err = a->unpack_string(value, &size); p = value; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (grib_is_missing_string(a, (unsigned char*)value, size)) { return; } @@ -501,9 +501,9 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) if (self->isLeaf == 0) { depth += 2; if (r != 0) - fprintf(self->dumper.out, " call codes_get(ibufr, '#%d#%s', sVal)\n", r, a->name); + fprintf(self->dumper.out, " call codes_get(ibufr, '#%d#%s', sVal)\n", r, a->name_); else - fprintf(self->dumper.out, " call codes_get(ibufr, '%s', sVal)\n", a->name); + fprintf(self->dumper.out, " call codes_get(ibufr, '%s', sVal)\n", a->name_); } /*fprintf(self->dumper.out,"\'%s\')\n",value);*/ @@ -513,12 +513,12 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -552,9 +552,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key) static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_decode_fortran* self = (grib_dumper_bufr_decode_fortran*)d; - if (strcmp(a->name, "BUFR")==0 || - strcmp(a->name, "GRIB")==0 || - strcmp(a->name, "META")==0) { + if (strcmp(a->name_, "BUFR")==0 || + strcmp(a->name_, "GRIB")==0 || + strcmp(a->name_, "META")==0) { grib_handle* h = grib_handle_of_accessor(a); depth = 2; self->empty = 1; @@ -568,8 +568,8 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); depth -= 2; } - else if (strcmp(a->name, "groupNumber")==0) { - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + else if (strcmp(a->name_, "groupNumber")==0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->empty = 1; depth += 2; @@ -586,26 +586,26 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix int i = 0; grib_dumper_bufr_decode_fortran* self = (grib_dumper_bufr_decode_fortran*)d; unsigned long flags; - while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { + while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes_[i]) { self->isAttribute = 1; - if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes[i]->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { + if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes_[i]->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) { i++; continue; } - self->isLeaf = a->attributes[i]->attributes[0] == NULL ? 1 : 0; - flags = a->attributes[i]->flags; - a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (a->attributes[i]->get_native_type()) { + self->isLeaf = a->attributes_[i]->attributes_[0] == NULL ? 1 : 0; + flags = a->attributes_[i]->flags_; + a->attributes_[i]->flags_ |= GRIB_ACCESSOR_FLAG_DUMP; + switch (a->attributes_[i]->get_native_type()) { case GRIB_TYPE_LONG: - dump_long_attribute(d, a->attributes[i], prefix); + dump_long_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_DOUBLE: - dump_values_attribute(d, a->attributes[i], prefix); + dump_values_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_STRING: break; } - a->attributes[i]->flags = flags; + a->attributes_[i]->flags_ = flags; i++; } self->isLeaf = 0; diff --git a/src/grib_dumper_class_bufr_decode_python.cc b/src/grib_dumper_class_bufr_decode_python.cc index 3e2edc70a..0ab837040 100644 --- a/src/grib_dumper_class_bufr_decode_python.cc +++ b/src/grib_dumper_class_bufr_decode_python.cc @@ -144,10 +144,10 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int r = 0; long count = 0; char* sval = NULL; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -161,19 +161,19 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if (size > 1) { depth -= 2; - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, " dVals = codes_get_array(ibufr, '#%d#%s')\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, " dVals = codes_get_array(ibufr, '#%d#%s')\n", r, a->name_); else - fprintf(self->dumper.out, " dVals = codes_get_array(ibufr, '%s')\n", a->name); + fprintf(self->dumper.out, " dVals = codes_get_array(ibufr, '%s')\n", a->name_); } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (!grib_is_missing_double(a, value)) { sval = dval_to_string(c, value); if (r != 0) - fprintf(self->dumper.out, " dVal = codes_get(ibufr, '#%d#%s')\n", r, a->name); + fprintf(self->dumper.out, " dVal = codes_get(ibufr, '#%d#%s')\n", r, a->name_); else - fprintf(self->dumper.out, " dVal = codes_get(ibufr, '%s')\n", a->name); + fprintf(self->dumper.out, " dVal = codes_get(ibufr, '%s')\n", a->name_); grib_context_free(c, sval); } @@ -184,12 +184,12 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -208,9 +208,9 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* int err = 0; long count = 0; char* sval; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -224,13 +224,13 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* if (size > 1) { depth -= 2; - fprintf(self->dumper.out, " dVals = codes_get_array(ibufr, '%s->%s')\n", prefix, a->name); + fprintf(self->dumper.out, " dVals = codes_get_array(ibufr, '%s->%s')\n", prefix, a->name_); } else { - /* int r=compute_bufr_key_rank(h,self->keys,a->name); */ + /* int r=compute_bufr_key_rank(h,self->keys,a->name_); */ if (!grib_is_missing_double(a, value)) { sval = dval_to_string(c, value); - fprintf(self->dumper.out, " dVal = codes_get(ibufr, '%s->%s')\n", prefix, a->name); + fprintf(self->dumper.out, " dVal = codes_get(ibufr, '%s->%s')\n", prefix, a->name_); grib_context_free(c, sval); } @@ -239,8 +239,8 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* if (self->isLeaf == 0) { char* prefix1; - prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + strlen(prefix) + 5)); - snprintf(prefix1, 1024, "%s->%s", prefix, a->name); + prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + strlen(prefix) + 5)); + snprintf(prefix1, 1024, "%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -259,28 +259,28 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int err = 0; int r = 0; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; a->value_count(&count); size = count; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { if (self->isLeaf == 0) { char* prefix; int dofree = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -298,18 +298,18 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if (size > 1) { depth -= 2; - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, " iValues = codes_get_array(ibufr, '#%d#%s')\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, " iValues = codes_get_array(ibufr, '#%d#%s')\n", r, a->name_); else - fprintf(self->dumper.out, " iValues = codes_get_array(ibufr, '%s')\n", a->name); + fprintf(self->dumper.out, " iValues = codes_get_array(ibufr, '%s')\n", a->name_); } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (!grib_is_missing_long(a, value)) { if (r != 0) - fprintf(self->dumper.out, " iVal = codes_get(ibufr, '#%d#%s')\n", r, a->name); + fprintf(self->dumper.out, " iVal = codes_get(ibufr, '#%d#%s')\n", r, a->name_); else - fprintf(self->dumper.out, " iVal = codes_get(ibufr, '%s')\n", a->name); + fprintf(self->dumper.out, " iVal = codes_get(ibufr, '%s')\n", a->name_); } } @@ -318,12 +318,12 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -340,9 +340,9 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr size_t size = 0; int err = 0; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -356,12 +356,12 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr if (size > 1) { depth -= 2; - fprintf(self->dumper.out, " iVals = codes_get_array(ibufr, '%s->%s')\n", prefix, a->name); + fprintf(self->dumper.out, " iVals = codes_get_array(ibufr, '%s->%s')\n", prefix, a->name_); } else { if (!codes_bufr_key_exclude_from_dump(prefix)) { if (!grib_is_missing_long(a, value)) { - fprintf(self->dumper.out, " iVal = codes_get(ibufr, '%s->%s')\n", prefix, a->name); + fprintf(self->dumper.out, " iVal = codes_get(ibufr, '%s->%s')\n", prefix, a->name_); } } } @@ -369,8 +369,8 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr if (self->isLeaf == 0) { char* prefix1; - prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + strlen(prefix) + 5)); - snprintf(prefix1, 1024, "%s->%s", prefix, a->name); + prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + strlen(prefix) + 5)); + snprintf(prefix1, 1024, "%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -394,19 +394,19 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) grib_handle* h = grib_handle_of_accessor(a); grib_context* c = h->context; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->unpack_double(&value, &size); self->empty = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (!grib_is_missing_double(a, value)) { sval = dval_to_string(c, value); if (r != 0) - fprintf(self->dumper.out, " dVal = codes_get(ibufr, '#%d#%s')\n", r, a->name); + fprintf(self->dumper.out, " dVal = codes_get(ibufr, '#%d#%s')\n", r, a->name_); else - fprintf(self->dumper.out, " dVal = codes_get(ibufr, '%s')\n", a->name); + fprintf(self->dumper.out, " dVal = codes_get(ibufr, '%s')\n", a->name_); grib_context_free(c, sval); } @@ -416,12 +416,12 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -440,9 +440,9 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm int r = 0; grib_handle* h = grib_handle_of_accessor(a); - c = a->context; + c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -455,10 +455,10 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm self->empty = 0; if (self->isLeaf == 0) { - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, " sVals = codes_get_string_array(ibufr, '#%d#%s')\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, " sVals = codes_get_string_array(ibufr, '#%d#%s')\n", r, a->name_); else - fprintf(self->dumper.out, " sVals = codes_get_string_array(ibufr, '%s')\n", a->name); + fprintf(self->dumper.out, " sVals = codes_get_string_array(ibufr, '%s')\n", a->name_); } if (self->isLeaf == 0) { @@ -466,12 +466,12 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -489,18 +489,18 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */ char* p = NULL; size_t size = MAX_STRING_SIZE; - grib_context* c = a->context; + grib_context* c = a->context_; int r = 0, err = 0; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; self->empty = 0; err = a->unpack_string(value, &size); p = value; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (grib_is_missing_string(a, (unsigned char*)value, size)) { return; } @@ -514,9 +514,9 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) if (self->isLeaf == 0) { depth += 2; if (r != 0) - fprintf(self->dumper.out, " sVal = codes_get(ibufr, '#%d#%s')\n", r, a->name); + fprintf(self->dumper.out, " sVal = codes_get(ibufr, '#%d#%s')\n", r, a->name_); else - fprintf(self->dumper.out, " sVal = codes_get(ibufr, '%s')\n", a->name); + fprintf(self->dumper.out, " sVal = codes_get(ibufr, '%s')\n", a->name_); } if (self->isLeaf == 0) { @@ -524,12 +524,12 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -562,9 +562,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key) static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_decode_python* self = (grib_dumper_bufr_decode_python*)d; - if (strcmp(a->name, "BUFR")==0 || - strcmp(a->name, "GRIB")==0 || - strcmp(a->name, "META")==0) { + if (strcmp(a->name_, "BUFR")==0 || + strcmp(a->name_, "GRIB")==0 || + strcmp(a->name_, "META")==0) { grib_handle* h = grib_handle_of_accessor(a); depth = 2; self->empty = 1; @@ -578,8 +578,8 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); depth -= 2; } - else if (strcmp(a->name, "groupNumber")==0) { - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + else if (strcmp(a->name_, "groupNumber")==0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->empty = 1; depth += 2; @@ -596,26 +596,26 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix int i = 0; grib_dumper_bufr_decode_python* self = (grib_dumper_bufr_decode_python*)d; unsigned long flags; - while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { + while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes_[i]) { self->isAttribute = 1; - if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes[i]->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { + if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes_[i]->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) { i++; continue; } - self->isLeaf = a->attributes[i]->attributes[0] == NULL ? 1 : 0; - flags = a->attributes[i]->flags; - a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (a->attributes[i]->get_native_type()) { + self->isLeaf = a->attributes_[i]->attributes_[0] == NULL ? 1 : 0; + flags = a->attributes_[i]->flags_; + a->attributes_[i]->flags_ |= GRIB_ACCESSOR_FLAG_DUMP; + switch (a->attributes_[i]->get_native_type()) { case GRIB_TYPE_LONG: - dump_long_attribute(d, a->attributes[i], prefix); + dump_long_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_DOUBLE: - dump_values_attribute(d, a->attributes[i], prefix); + dump_values_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_STRING: break; } - a->attributes[i]->flags = flags; + a->attributes_[i]->flags_ = flags; i++; } self->isLeaf = 0; diff --git a/src/grib_dumper_class_bufr_encode_C.cc b/src/grib_dumper_class_bufr_encode_C.cc index 915649814..7813ec140 100644 --- a/src/grib_dumper_class_bufr_encode_C.cc +++ b/src/grib_dumper_class_bufr_encode_C.cc @@ -162,10 +162,10 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int cols = 2; long count = 0; char* sval; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -186,7 +186,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) fprintf(self->dumper.out, " free(rvalues); rvalues = NULL;\n\n"); fprintf(self->dumper.out, " size = %lu;\n", (unsigned long)size); fprintf(self->dumper.out, " rvalues = (double*)malloc(size * sizeof(double));\n"); - fprintf(self->dumper.out, " if (!rvalues) { fprintf(stderr, \"Failed to allocate memory (%s).\\n\"); return 1; }", a->name); + fprintf(self->dumper.out, " if (!rvalues) { fprintf(stderr, \"Failed to allocate memory (%s).\\n\"); return 1; }", a->name_); icount = 0; for (i = 0; i < size - 1; ++i) { @@ -210,18 +210,18 @@ static void dump_values(grib_dumper* d, grib_accessor* a) fprintf(self->dumper.out, "\n"); grib_context_free(c, values); - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, " CODES_CHECK(codes_set_double_array(h, \"#%d#%s\",rvalues, size), 0);\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, " CODES_CHECK(codes_set_double_array(h, \"#%d#%s\",rvalues, size), 0);\n", r, a->name_); else - fprintf(self->dumper.out, " CODES_CHECK(codes_set_double_array(h, \"%s\", rvalues, size), 0);\n", a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_set_double_array(h, \"%s\", rvalues, size), 0);\n", a->name_); } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); sval = dval_to_string(c, value); if (r != 0) - fprintf(self->dumper.out, " CODES_CHECK(codes_set_double(h, \"#%d#%s\", %s), 0);\n", r, a->name, sval); + fprintf(self->dumper.out, " CODES_CHECK(codes_set_double(h, \"#%d#%s\", %s), 0);\n", r, a->name_, sval); else - fprintf(self->dumper.out, " CODES_CHECK(codes_set_double(h, \"%s\", %s), 0);\n", a->name, sval); + fprintf(self->dumper.out, " CODES_CHECK(codes_set_double(h, \"%s\", %s), 0);\n", a->name_, sval); grib_context_free(c, sval); } @@ -230,13 +230,13 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int dofree = 0; if (r != 0) { - const size_t prefixMaxLen = strlen(a->name) + 10; + const size_t prefixMaxLen = strlen(a->name_) + 10; prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * prefixMaxLen); dofree = 1; - snprintf(prefix, prefixMaxLen, "#%d#%s", r, a->name); + snprintf(prefix, prefixMaxLen, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -259,9 +259,9 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* int cols = 2; long count = 0; char* sval; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -282,7 +282,7 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* fprintf(self->dumper.out, " free(rvalues); rvalues = NULL;\n"); fprintf(self->dumper.out, " size = %lu;\n", (unsigned long)size); fprintf(self->dumper.out, " rvalues = (double*)malloc(size * sizeof(double));\n"); - fprintf(self->dumper.out, " if (!rvalues) { fprintf(stderr, \"Failed to allocate memory (%s).\\n\"); return 1; }", a->name); + fprintf(self->dumper.out, " if (!rvalues) { fprintf(stderr, \"Failed to allocate memory (%s).\\n\"); return 1; }", a->name_); icount = 0; for (i = 0; i < size - 1; ++i) { @@ -306,18 +306,18 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* fprintf(self->dumper.out, "\n"); grib_context_free(c, values); - fprintf(self->dumper.out, " CODES_CHECK(codes_set_double_array(h, \"%s->%s\", rvalues, size), 0);\n", prefix, a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_set_double_array(h, \"%s->%s\", rvalues, size), 0);\n", prefix, a->name_); } else { sval = dval_to_string(c, value); - fprintf(self->dumper.out, " CODES_CHECK(codes_set_double(h, \"%s->%s\", %s), 0);\n", prefix, a->name, sval); + fprintf(self->dumper.out, " CODES_CHECK(codes_set_double(h, \"%s->%s\", %s), 0);\n", prefix, a->name_, sval); grib_context_free(c, sval); } if (self->isLeaf == 0) { - const size_t prefix1MaxLen = strlen(a->name) + strlen(prefix) + 5; + const size_t prefix1MaxLen = strlen(a->name_) + strlen(prefix) + 5; char* prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * prefix1MaxLen); - snprintf(prefix1, prefix1MaxLen, "%s->%s", prefix, a->name); + snprintf(prefix1, prefix1MaxLen, "%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -330,7 +330,7 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* static int is_hidden(grib_accessor* a) { - return ( (a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ); + return ( (a->flags_ & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ); } static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) @@ -345,35 +345,35 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int cols = 4; long count = 0; char* sval = NULL; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); int doing_unexpandedDescriptors = 0; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { /* key does not have the dump attribute */ + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) { /* key does not have the dump attribute */ int skip = 1; /* See ECC-1107 */ - if (!is_hidden(a) && strcmp(a->name, "messageLength") == 0) skip = 0; + if (!is_hidden(a) && strcmp(a->name_, "messageLength") == 0) skip = 0; if (skip) return; } - doing_unexpandedDescriptors = (strcmp(a->name, "unexpandedDescriptors") == 0); + doing_unexpandedDescriptors = (strcmp(a->name_, "unexpandedDescriptors") == 0); a->value_count(&count); size = size2 = count; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { if (self->isLeaf == 0) { char* prefix; int dofree = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (r != 0) { - const size_t prefixMaxLen = strlen(a->name) + 10; + const size_t prefixMaxLen = strlen(a->name_) + 10; prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * prefixMaxLen); dofree = 1; - snprintf(prefix, prefixMaxLen, "#%d#%s", r, a->name); + snprintf(prefix, prefixMaxLen, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -384,7 +384,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } if (size > 1) { - values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + values = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * size); err = a->unpack_long(values, &size2); } else { @@ -398,7 +398,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, " free(ivalues); ivalues = NULL;\n\n"); fprintf(self->dumper.out, " size = %lu;\n", (unsigned long)size); fprintf(self->dumper.out, " ivalues = (long*)malloc(size * sizeof(long));\n"); - fprintf(self->dumper.out, " if (!ivalues) { fprintf(stderr, \"Failed to allocate memory (%s).\\n\"); return 1; }", a->name); + fprintf(self->dumper.out, " if (!ivalues) { fprintf(stderr, \"Failed to allocate memory (%s).\\n\"); return 1; }", a->name_); icount = 0; for (i = 0; i < size - 1; i++) { @@ -416,33 +416,33 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) depth -= 2; fprintf(self->dumper.out, "\n"); - grib_context_free(a->context, values); + grib_context_free(a->context_, values); - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) { - fprintf(self->dumper.out, " CODES_CHECK(codes_set_long_array(h, \"#%d#%s\", ivalues, size), 0);\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) { + fprintf(self->dumper.out, " CODES_CHECK(codes_set_long_array(h, \"#%d#%s\", ivalues, size), 0);\n", r, a->name_); } else { if (doing_unexpandedDescriptors) { fprintf(self->dumper.out, "\n /* Create the structure of the data section */\n"); /* fprintf(self->dumper.out," CODES_CHECK(codes_set_long(h, \"skipExtraKeyAttributes\", 1), 0);\n"); */ } - fprintf(self->dumper.out, " CODES_CHECK(codes_set_long_array(h, \"%s\", ivalues, size), 0);\n", a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_set_long_array(h, \"%s\", ivalues, size), 0);\n", a->name_); if (doing_unexpandedDescriptors) fprintf(self->dumper.out, "\n"); } } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); sval = lval_to_string(c, value); if (r != 0) { - fprintf(self->dumper.out, " CODES_CHECK(codes_set_long(h, \"#%d#%s\", ", r, a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_set_long(h, \"#%d#%s\", ", r, a->name_); } else { if (doing_unexpandedDescriptors) { fprintf(self->dumper.out, "\n /* Create the structure of the data section */\n"); /* fprintf(self->dumper.out," CODES_CHECK(codes_set_long(h, \"skipExtraKeyAttributes\", 1), 0);\n"); */ } - fprintf(self->dumper.out, " CODES_CHECK(codes_set_long(h, \"%s\", ", a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_set_long(h, \"%s\", ", a->name_); } fprintf(self->dumper.out, "%s), 0);\n", sval); @@ -456,13 +456,13 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - const size_t prefixMaxLen = strlen(a->name) + 10; + const size_t prefixMaxLen = strlen(a->name_) + 10; prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * prefixMaxLen); dofree = 1; - snprintf(prefix, prefixMaxLen, "#%d#%s", r, a->name); + snprintf(prefix, prefixMaxLen, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -483,16 +483,16 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr int i, icount; int cols = 4; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); size = size2 = count; if (size > 1) { - values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + values = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * size); err = a->unpack_long(values, &size2); } else { @@ -506,7 +506,7 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr fprintf(self->dumper.out, " free(ivalues); ivalues = NULL;\n"); fprintf(self->dumper.out, " size = %lu;\n", (unsigned long)size); fprintf(self->dumper.out, " ivalues = (long*)malloc(size * sizeof(long));\n"); - fprintf(self->dumper.out, " if (!ivalues) { fprintf(stderr, \"Failed to allocate memory (%s).\\n\"); return 1; }", a->name); + fprintf(self->dumper.out, " if (!ivalues) { fprintf(stderr, \"Failed to allocate memory (%s).\\n\"); return 1; }", a->name_); icount = 0; for (i = 0; i < size - 1; i++) { @@ -524,23 +524,23 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr depth -= 2; fprintf(self->dumper.out, "\n"); - grib_context_free(a->context, values); + grib_context_free(a->context_, values); - fprintf(self->dumper.out, " CODES_CHECK(codes_set_long_array(h, \"%s->%s\", ivalues, size), 0);\n", prefix, a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_set_long_array(h, \"%s->%s\", ivalues, size), 0);\n", prefix, a->name_); } else { if (!codes_bufr_key_exclude_from_dump(prefix)) { char* sval = lval_to_string(c, value); - fprintf(self->dumper.out, " CODES_CHECK(codes_set_long(h, \"%s->%s\", ", prefix, a->name); + fprintf(self->dumper.out, " CODES_CHECK(codes_set_long(h, \"%s->%s\", ", prefix, a->name_); fprintf(self->dumper.out, "%s), 0);\n", sval); grib_context_free(c, sval); } } if (self->isLeaf == 0) { - const size_t prefix1MaxLen = strlen(a->name) + strlen(prefix) + 5; + const size_t prefix1MaxLen = strlen(a->name_) + strlen(prefix) + 5; char* prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * prefix1MaxLen); - snprintf(prefix1, prefix1MaxLen, "%s->%s", prefix, a->name); + snprintf(prefix1, prefix1MaxLen, "%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -565,19 +565,19 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) grib_handle* h = grib_handle_of_accessor(a); grib_context* c = h->context; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->unpack_double(&value, &size); self->empty = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); sval = dval_to_string(c, value); if (r != 0) - fprintf(self->dumper.out, " CODES_CHECK(codes_set_double(h, \"#%d#%s\", %s), 0);\n", r, a->name, sval); + fprintf(self->dumper.out, " CODES_CHECK(codes_set_double(h, \"#%d#%s\", %s), 0);\n", r, a->name_, sval); else - fprintf(self->dumper.out, " CODES_CHECK(codes_set_double(h, \"%s\", %s), 0);\n", a->name, sval); + fprintf(self->dumper.out, " CODES_CHECK(codes_set_double(h, \"%s\", %s), 0);\n", a->name_, sval); grib_context_free(c, sval); if (self->isLeaf == 0) { @@ -585,13 +585,13 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - const size_t prefixMaxLen = strlen(a->name) + 10; + const size_t prefixMaxLen = strlen(a->name_) + 10; prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * prefixMaxLen); dofree = 1; - snprintf(prefix, prefixMaxLen, "#%d#%s", r, a->name); + snprintf(prefix, prefixMaxLen, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -605,13 +605,13 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm grib_dumper_bufr_encode_C* self = (grib_dumper_bufr_encode_C*)d; char** values; size_t size = 0, i = 0; - grib_context* c = a->context; + grib_context* c = a->context_; int err = 0; long count = 0; int r = 0; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -624,7 +624,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm fprintf(self->dumper.out, " free(svalues);\n"); fprintf(self->dumper.out, " size = %lu;\n", (unsigned long)size); fprintf(self->dumper.out, " svalues = (char**)malloc(size * sizeof(char*));\n"); - fprintf(self->dumper.out, " if (!svalues) { fprintf(stderr, \"Failed to allocate memory (%s).\\n\"); return 1; }\n", a->name); + fprintf(self->dumper.out, " if (!svalues) { fprintf(stderr, \"Failed to allocate memory (%s).\\n\"); return 1; }\n", a->name_); self->empty = 0; values = (char**)grib_context_malloc_clear(c, size * sizeof(char*)); @@ -640,10 +640,10 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm fprintf(self->dumper.out, " svalues[%lu]=\"%s\";\n", (unsigned long)i, values[i]); if (self->isLeaf == 0) { - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, " codes_set_string_array(h, \"#%d#%s\", (const char **)svalues, size);\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, " codes_set_string_array(h, \"#%d#%s\", (const char **)svalues, size);\n", r, a->name_); else - fprintf(self->dumper.out, " codes_set_string_array(h, \"%s\", (const char **)svalues, size);\n", a->name); + fprintf(self->dumper.out, " codes_set_string_array(h, \"%s\", (const char **)svalues, size);\n", a->name_); } if (self->isLeaf == 0) { @@ -651,13 +651,13 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm int dofree = 0; if (r != 0) { - const size_t prefixMaxLen = strlen(a->name) + 10; + const size_t prefixMaxLen = strlen(a->name_) + 10; prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * prefixMaxLen); dofree = 1; - snprintf(prefix, prefixMaxLen, "#%d#%s", r, a->name); + snprintf(prefix, prefixMaxLen, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -677,16 +677,16 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) char* value = NULL; char* p = NULL; size_t size = 0; - grib_context* c = a->context; + grib_context* c = a->context_; int r = 0, err = 0; grib_handle* h = grib_handle_of_accessor(a); - const char* acc_name = a->name; + const char* acc_name = a->name_; grib_get_string_length_acc(a, &size); if (size == 0) return; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; value = (char*)grib_context_malloc_clear(c, size); @@ -791,9 +791,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_encode_C* self = (grib_dumper_bufr_encode_C*)d; - if (strcmp(a->name, "BUFR")==0 || - strcmp(a->name, "GRIB")==0 || - strcmp(a->name, "META")==0) { + if (strcmp(a->name_, "BUFR")==0 || + strcmp(a->name_, "GRIB")==0 || + strcmp(a->name_, "META")==0) { grib_handle* h = grib_handle_of_accessor(a); depth = 2; self->empty = 1; @@ -806,8 +806,8 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); depth -= 2; } - else if (strcmp(a->name, "groupNumber")==0) { - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + else if (strcmp(a->name_, "groupNumber")==0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->empty = 1; depth += 2; @@ -824,26 +824,26 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix int i = 0; grib_dumper_bufr_encode_C* self = (grib_dumper_bufr_encode_C*)d; unsigned long flags; - while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { + while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes_[i]) { self->isAttribute = 1; - if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes[i]->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { + if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes_[i]->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) { i++; continue; } - self->isLeaf = a->attributes[i]->attributes[0] == NULL ? 1 : 0; - flags = a->attributes[i]->flags; - a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (a->attributes[i]->get_native_type()) { + self->isLeaf = a->attributes_[i]->attributes_[0] == NULL ? 1 : 0; + flags = a->attributes_[i]->flags_; + a->attributes_[i]->flags_ |= GRIB_ACCESSOR_FLAG_DUMP; + switch (a->attributes_[i]->get_native_type()) { case GRIB_TYPE_LONG: - dump_long_attribute(d, a->attributes[i], prefix); + dump_long_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_DOUBLE: - dump_values_attribute(d, a->attributes[i], prefix); + dump_values_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_STRING: break; } - a->attributes[i]->flags = flags; + a->attributes_[i]->flags_ = flags; i++; } self->isLeaf = 0; diff --git a/src/grib_dumper_class_bufr_encode_filter.cc b/src/grib_dumper_class_bufr_encode_filter.cc index a90ab0f56..6ccee0088 100644 --- a/src/grib_dumper_class_bufr_encode_filter.cc +++ b/src/grib_dumper_class_bufr_encode_filter.cc @@ -138,10 +138,10 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int i, r; int cols = 9; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -162,10 +162,10 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if (size > 1) { int icount = 0; - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, "set #%d#%s=", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, "set #%d#%s=", r, a->name_); else - fprintf(self->dumper.out, "set %s=", a->name); + fprintf(self->dumper.out, "set %s=", a->name_); fprintf(self->dumper.out, "{"); @@ -187,12 +187,12 @@ static void dump_values(grib_dumper* d, grib_accessor* a) grib_context_free(c, values); } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (!grib_is_missing_double(a, value)) { if (r != 0) - fprintf(self->dumper.out, "set #%d#%s=", r, a->name); + fprintf(self->dumper.out, "set #%d#%s=", r, a->name_); else - fprintf(self->dumper.out, "set %s=", a->name); + fprintf(self->dumper.out, "set %s=", a->name_); fprintf(self->dumper.out, "%.18e;\n", value); } @@ -203,12 +203,12 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -229,9 +229,9 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* int i, icount; int cols = 2; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -249,7 +249,7 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* self->empty = 0; if (size > 1) { - fprintf(self->dumper.out, "set %s->%s = {", prefix, a->name); + fprintf(self->dumper.out, "set %s->%s = {", prefix, a->name_); icount = 0; for (i = 0; i < size - 1; ++i) { if (icount > cols || i == 0) { @@ -269,17 +269,17 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* grib_context_free(c, values); } else { - /* int r=compute_bufr_key_rank(h,self->keys,a->name); */ + /* int r=compute_bufr_key_rank(h,self->keys,a->name_); */ if (!grib_is_missing_double(a, value)) { - fprintf(self->dumper.out, "set %s->%s = %.18e;\n", prefix, a->name, value); + fprintf(self->dumper.out, "set %s->%s = %.18e;\n", prefix, a->name_, value); } } if (self->isLeaf == 0) { char* prefix1; - prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + strlen(prefix) + 5)); - snprintf(prefix1, 1024, "%s->%s", prefix, a->name); + prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + strlen(prefix) + 5)); + snprintf(prefix1, 1024, "%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -300,28 +300,28 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int i, r, icount; int cols = 9; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; a->value_count(&count); size = size2 = count; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { if (self->isLeaf == 0) { char* prefix; int dofree = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -332,7 +332,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } if (size > 1) { - values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + values = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * size); err = a->unpack_long(values, &size2); } else { @@ -345,10 +345,10 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if (size > 1) { icount = 0; - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, "set #%d#%s=", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, "set #%d#%s=", r, a->name_); else - fprintf(self->dumper.out, "set %s=", a->name); + fprintf(self->dumper.out, "set %s=", a->name_); fprintf(self->dumper.out, "{"); @@ -367,15 +367,15 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) depth -= 2; fprintf(self->dumper.out, "};\n"); - grib_context_free(a->context, values); + grib_context_free(a->context_, values); } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (!grib_is_missing_long(a, value)) { if (r != 0) - fprintf(self->dumper.out, "set #%d#%s=", r, a->name); + fprintf(self->dumper.out, "set #%d#%s=", r, a->name_); else - fprintf(self->dumper.out, "set %s=", a->name); + fprintf(self->dumper.out, "set %s=", a->name_); fprintf(self->dumper.out, "%ld;\n", value); } @@ -386,12 +386,12 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -411,16 +411,16 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr int i, icount; int cols = 4; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); size = size2 = count; if (size > 1) { - values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + values = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * size); err = a->unpack_long(values, &size2); } else { @@ -431,7 +431,7 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr self->empty = 0; if (size > 1) { - fprintf(self->dumper.out, "set %s->%s = {", prefix, a->name); + fprintf(self->dumper.out, "set %s->%s = {", prefix, a->name_); icount = 0; for (i = 0; i < size - 1; i++) { if (icount > cols || i == 0) { @@ -447,13 +447,13 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr fprintf(self->dumper.out, "%ld ", values[i]); depth -= 2; fprintf(self->dumper.out, "};\n"); - grib_context_free(a->context, values); + grib_context_free(a->context_, values); } else { - /* int r=compute_bufr_key_rank(h,self->keys,a->name); */ + /* int r=compute_bufr_key_rank(h,self->keys,a->name_); */ if (!codes_bufr_key_exclude_from_dump(prefix)) { if (!grib_is_missing_long(a, value)) { - fprintf(self->dumper.out, "set %s->%s = ", prefix, a->name); + fprintf(self->dumper.out, "set %s->%s = ", prefix, a->name_); fprintf(self->dumper.out, "%ld ;\n", value); } } @@ -462,8 +462,8 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr if (self->isLeaf == 0) { char* prefix1; - prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + strlen(prefix) + 5)); - snprintf(prefix1, 1024, "%s->%s", prefix, a->name); + prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + strlen(prefix) + 5)); + snprintf(prefix1, 1024, "%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -486,19 +486,19 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) grib_handle* h = grib_handle_of_accessor(a); grib_context* c = h->context; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->unpack_double(&value, &size); self->begin = 0; self->empty = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (!grib_is_missing_double(a, value)) { if (r != 0) - fprintf(self->dumper.out, "set #%d#%s=", r, a->name); + fprintf(self->dumper.out, "set #%d#%s=", r, a->name_); else - fprintf(self->dumper.out, "set %s=", a->name); + fprintf(self->dumper.out, "set %s=", a->name_); fprintf(self->dumper.out, "%.18e;\n", value); } @@ -508,12 +508,12 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -533,9 +533,9 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm int r = 0; grib_handle* h = grib_handle_of_accessor(a); - c = a->context; + c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -549,10 +549,10 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm if (self->isLeaf == 0) { depth += 2; - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, "set #%d#%s=", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, "set #%d#%s=", r, a->name_); else - fprintf(self->dumper.out, "set %s=", a->name); + fprintf(self->dumper.out, "set %s=", a->name_); } self->empty = 0; @@ -581,12 +581,12 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -604,11 +604,11 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) char* value = NULL; char* p = NULL; size_t size = 0; - grib_context* c = a->context; + grib_context* c = a->context_; int r = 0, err = 0; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; grib_get_string_length_acc(a, &size); @@ -626,7 +626,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) err = a->unpack_string(value, &size); p = value; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (grib_is_missing_string(a, (unsigned char*)value, size)) { strcpy(value, ""); /* Empty string means MISSING string */ } @@ -642,9 +642,9 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) if (self->isLeaf == 0) { depth += 2; if (r != 0) - fprintf(self->dumper.out, "set #%d#%s=", r, a->name); + fprintf(self->dumper.out, "set #%d#%s=", r, a->name_); else - fprintf(self->dumper.out, "set %s=", a->name); + fprintf(self->dumper.out, "set %s=", a->name_); } fprintf(self->dumper.out, "\"%s\";\n", value); @@ -654,12 +654,12 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -712,9 +712,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_encode_filter* self = (grib_dumper_bufr_encode_filter*)d; - if (strcmp(a->name, "BUFR")==0 || - strcmp(a->name, "GRIB")==0 || - strcmp(a->name, "META")==0) { + if (strcmp(a->name_, "BUFR")==0 || + strcmp(a->name_, "GRIB")==0 || + strcmp(a->name_, "META")==0) { grib_handle* h = grib_handle_of_accessor(a); depth = 2; self->begin = 1; @@ -728,8 +728,8 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); depth -= 2; } - else if (strcmp(a->name, "groupNumber")==0) { - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + else if (strcmp(a->name_, "groupNumber")==0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->begin = 1; self->empty = 1; @@ -747,29 +747,29 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix int i = 0; grib_dumper_bufr_encode_filter* self = (grib_dumper_bufr_encode_filter*)d; unsigned long flags; - while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { + while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes_[i]) { self->isAttribute = 1; - if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes[i]->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { + if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes_[i]->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) { i++; continue; } - self->isLeaf = a->attributes[i]->attributes[0] == NULL ? 1 : 0; + self->isLeaf = a->attributes_[i]->attributes_[0] == NULL ? 1 : 0; /* fprintf(self->dumper.out,","); */ /* fprintf(self->dumper.out,"\n%-*s",depth," "); */ - /* fprintf(out,"\"%s\" : ",a->attributes[i]->name); */ - flags = a->attributes[i]->flags; - a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (a->attributes[i]->get_native_type()) { + /* fprintf(out,"\"%s\" : ",a->attributes_[i]->name); */ + flags = a->attributes_[i]->flags_; + a->attributes_[i]->flags_ |= GRIB_ACCESSOR_FLAG_DUMP; + switch (a->attributes_[i]->get_native_type()) { case GRIB_TYPE_LONG: - dump_long_attribute(d, a->attributes[i], prefix); + dump_long_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_DOUBLE: - dump_values_attribute(d, a->attributes[i], prefix); + dump_values_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_STRING: break; } - a->attributes[i]->flags = flags; + a->attributes_[i]->flags_ = flags; i++; } self->isLeaf = 0; diff --git a/src/grib_dumper_class_bufr_encode_fortran.cc b/src/grib_dumper_class_bufr_encode_fortran.cc index 1e6cd3bd7..5c3004696 100644 --- a/src/grib_dumper_class_bufr_encode_fortran.cc +++ b/src/grib_dumper_class_bufr_encode_fortran.cc @@ -211,10 +211,10 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int cols = 2; long count = 0; char* sval; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -259,18 +259,18 @@ static void dump_values(grib_dumper* d, grib_accessor* a) fprintf(self->dumper.out, "/)\n"); grib_context_free(c, values); - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, " call codes_set(ibufr,'#%d#%s',rvalues)\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, " call codes_set(ibufr,'#%d#%s',rvalues)\n", r, a->name_); else - fprintf(self->dumper.out, " call codes_set(ibufr,'%s',rvalues)\n", a->name); + fprintf(self->dumper.out, " call codes_set(ibufr,'%s',rvalues)\n", a->name_); } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); sval = dval_to_string(c, value); if (r != 0) - fprintf(self->dumper.out, " call codes_set(ibufr,'#%d#%s',%s)\n", r, a->name, sval); + fprintf(self->dumper.out, " call codes_set(ibufr,'#%d#%s',%s)\n", r, a->name_, sval); else - fprintf(self->dumper.out, " call codes_set(ibufr,'%s',%s)\n", a->name, sval); + fprintf(self->dumper.out, " call codes_set(ibufr,'%s',%s)\n", a->name_, sval); grib_context_free(c, sval); } @@ -279,12 +279,12 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -307,9 +307,9 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* int cols = 2; long count = 0; char* sval; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -354,19 +354,19 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* fprintf(self->dumper.out, "/)\n"); grib_context_free(c, values); - fprintf(self->dumper.out, " call codes_set(ibufr,'%s->%s' &\n,rvalues)\n", prefix, a->name); + fprintf(self->dumper.out, " call codes_set(ibufr,'%s->%s' &\n,rvalues)\n", prefix, a->name_); } else { sval = dval_to_string(c, value); - fprintf(self->dumper.out, " call codes_set(ibufr,'%s->%s' &\n,%s)\n", prefix, a->name, sval); + fprintf(self->dumper.out, " call codes_set(ibufr,'%s->%s' &\n,%s)\n", prefix, a->name_, sval); grib_context_free(c, sval); } if (self->isLeaf == 0) { char* prefix1; - prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + strlen(prefix) + 5)); - snprintf(prefix1, 1024, "%s->%s", prefix, a->name); + prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + strlen(prefix) + 5)); + snprintf(prefix1, 1024, "%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -379,7 +379,7 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* static int is_hidden(grib_accessor* a) { - return ( (a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ); + return ( (a->flags_ & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ); } static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) @@ -394,34 +394,34 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int cols = 4; long count = 0; char* sval = NULL; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); int doing_unexpandedDescriptors = 0; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { /* key does not have the dump attribute */ + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) { /* key does not have the dump attribute */ int skip = 1; /* See ECC-1107 */ - if (!is_hidden(a) && strcmp(a->name, "messageLength") == 0) skip = 0; + if (!is_hidden(a) && strcmp(a->name_, "messageLength") == 0) skip = 0; if (skip) return; } - doing_unexpandedDescriptors = (strcmp(a->name, "unexpandedDescriptors") == 0); + doing_unexpandedDescriptors = (strcmp(a->name_, "unexpandedDescriptors") == 0); a->value_count(&count); size = size2 = count; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { if (self->isLeaf == 0) { char* prefix; int dofree = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -432,7 +432,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } if (size > 1) { - values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + values = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * size); err = a->unpack_long(values, &size2); } else { @@ -463,33 +463,33 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) depth -= 2; fprintf(self->dumper.out, "/)\n"); - grib_context_free(a->context, values); + grib_context_free(a->context_, values); - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) { - fprintf(self->dumper.out, " call codes_set(ibufr,'#%d#%s',ivalues)\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) { + fprintf(self->dumper.out, " call codes_set(ibufr,'#%d#%s',ivalues)\n", r, a->name_); } else { if (doing_unexpandedDescriptors) { fprintf(self->dumper.out, "\n ! Create the structure of the data section\n"); /* fprintf(self->dumper.out," call codes_set(ibufr,'skipExtraKeyAttributes',1)\n"); */ } - fprintf(self->dumper.out, " call codes_set(ibufr,'%s',ivalues)\n", a->name); + fprintf(self->dumper.out, " call codes_set(ibufr,'%s',ivalues)\n", a->name_); if (doing_unexpandedDescriptors) fprintf(self->dumper.out, "\n"); } } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); sval = lval_to_string(c, value); if (r != 0) { - fprintf(self->dumper.out, " call codes_set(ibufr,'#%d#%s',", r, a->name); + fprintf(self->dumper.out, " call codes_set(ibufr,'#%d#%s',", r, a->name_); } else { if (doing_unexpandedDescriptors) { fprintf(self->dumper.out, "\n ! Create the structure of the data section\n"); /* fprintf(self->dumper.out," call codes_set(ibufr,'skipExtraKeyAttributes',1)\n"); */ } - fprintf(self->dumper.out, " call codes_set(ibufr,'%s',", a->name); + fprintf(self->dumper.out, " call codes_set(ibufr,'%s',", a->name_); } fprintf(self->dumper.out, "%s)\n", sval); @@ -503,12 +503,12 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -530,16 +530,16 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr int cols = 4; long count = 0; char* pref = NULL; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); size = size2 = count; if (size > 1) { - values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + values = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * size); err = a->unpack_long(values, &size2); } else { @@ -574,14 +574,14 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr depth -= 2; fprintf(self->dumper.out, "/)\n"); - grib_context_free(a->context, values); + grib_context_free(a->context_, values); - fprintf(self->dumper.out, " call codes_set(ibufr,'%s->%s' &\n,ivalues)\n", pref, a->name); + fprintf(self->dumper.out, " call codes_set(ibufr,'%s->%s' &\n,ivalues)\n", pref, a->name_); } else { if (!codes_bufr_key_exclude_from_dump(prefix)) { char* sval = lval_to_string(c, value); - fprintf(self->dumper.out, " call codes_set(ibufr,'%s->%s'&\n,", pref, a->name); + fprintf(self->dumper.out, " call codes_set(ibufr,'%s->%s'&\n,", pref, a->name_); fprintf(self->dumper.out, "%s)\n", sval); grib_context_free(c, sval); } @@ -590,8 +590,8 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr if (self->isLeaf == 0) { char* prefix1; - prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + strlen(pref) + 5)); - snprintf(prefix1, 1024, "%s->%s", pref, a->name); + prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + strlen(pref) + 5)); + snprintf(prefix1, 1024, "%s->%s", pref, a->name_); dump_attributes(d, a, prefix1); @@ -617,19 +617,19 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) grib_handle* h = grib_handle_of_accessor(a); grib_context* c = h->context; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->unpack_double(&value, &size); self->empty = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); sval = dval_to_string(c, value); if (r != 0) - fprintf(self->dumper.out, " call codes_set(ibufr,'#%d#%s',%s)\n", r, a->name, sval); + fprintf(self->dumper.out, " call codes_set(ibufr,'#%d#%s',%s)\n", r, a->name_, sval); else - fprintf(self->dumper.out, " call codes_set(ibufr,'%s',%s)\n", a->name, sval); + fprintf(self->dumper.out, " call codes_set(ibufr,'%s',%s)\n", a->name_, sval); grib_context_free(c, sval); if (self->isLeaf == 0) { @@ -637,12 +637,12 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -656,13 +656,13 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d; char** values; size_t size = 0, i = 0; - grib_context* c = a->context; + grib_context* c = a->context_; int err = 0; long count = 0; int r = 0; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -696,18 +696,18 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm char* prefix; int dofree = 0; - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, " call codes_set_string_array(ibufr,'#%d#%s',svalues)\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, " call codes_set_string_array(ibufr,'#%d#%s',svalues)\n", r, a->name_); else - fprintf(self->dumper.out, " call codes_set_string_array(ibufr,'%s',svalues)\n", a->name); + fprintf(self->dumper.out, " call codes_set_string_array(ibufr,'%s',svalues)\n", a->name_); if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -726,17 +726,17 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) char* value = NULL; char* p = NULL; size_t size = 0; - grib_context* c = a->context; + grib_context* c = a->context_; int r; int err = 0; grib_handle* h = grib_handle_of_accessor(a); - const char* acc_name = a->name; + const char* acc_name = a->name_; grib_get_string_length_acc(a, &size); if (size == 0) return; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; value = (char*)grib_context_malloc_clear(c, size); @@ -838,9 +838,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d; - if (strcmp(a->name, "BUFR")==0 || - strcmp(a->name, "GRIB")==0 || - strcmp(a->name, "META")==0) { + if (strcmp(a->name_, "BUFR")==0 || + strcmp(a->name_, "GRIB")==0 || + strcmp(a->name_, "META")==0) { grib_handle* h = grib_handle_of_accessor(a); depth = 2; self->empty = 1; @@ -853,8 +853,8 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); depth -= 2; } - else if (strcmp(a->name, "groupNumber")==0) { - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + else if (strcmp(a->name_, "groupNumber")==0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->empty = 1; depth += 2; @@ -871,26 +871,26 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix int i = 0; grib_dumper_bufr_encode_fortran* self = (grib_dumper_bufr_encode_fortran*)d; unsigned long flags; - while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { + while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes_[i]) { self->isAttribute = 1; - if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes[i]->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { + if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes_[i]->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) { i++; continue; } - self->isLeaf = a->attributes[i]->attributes[0] == NULL ? 1 : 0; - flags = a->attributes[i]->flags; - a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (a->attributes[i]->get_native_type()) { + self->isLeaf = a->attributes_[i]->attributes_[0] == NULL ? 1 : 0; + flags = a->attributes_[i]->flags_; + a->attributes_[i]->flags_ |= GRIB_ACCESSOR_FLAG_DUMP; + switch (a->attributes_[i]->get_native_type()) { case GRIB_TYPE_LONG: - dump_long_attribute(d, a->attributes[i], prefix); + dump_long_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_DOUBLE: - dump_values_attribute(d, a->attributes[i], prefix); + dump_values_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_STRING: break; } - a->attributes[i]->flags = flags; + a->attributes_[i]->flags_ = flags; i++; } self->isLeaf = 0; diff --git a/src/grib_dumper_class_bufr_encode_python.cc b/src/grib_dumper_class_bufr_encode_python.cc index 565bc34ac..48494fb06 100644 --- a/src/grib_dumper_class_bufr_encode_python.cc +++ b/src/grib_dumper_class_bufr_encode_python.cc @@ -158,10 +158,10 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int cols = 2; long count = 0; char* sval; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -207,18 +207,18 @@ static void dump_values(grib_dumper* d, grib_accessor* a) fprintf(self->dumper.out, ",)\n"); grib_context_free(c, values); - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, " codes_set_array(ibufr, '#%d#%s', rvalues)\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, " codes_set_array(ibufr, '#%d#%s', rvalues)\n", r, a->name_); else - fprintf(self->dumper.out, " codes_set_array(ibufr, '%s', rvalues)\n", a->name); + fprintf(self->dumper.out, " codes_set_array(ibufr, '%s', rvalues)\n", a->name_); } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); sval = dval_to_string(c, value); if (r != 0) - fprintf(self->dumper.out, " codes_set(ibufr, '#%d#%s', %s)\n", r, a->name, sval); + fprintf(self->dumper.out, " codes_set(ibufr, '#%d#%s', %s)\n", r, a->name_, sval); else - fprintf(self->dumper.out, " codes_set(ibufr, '%s', %s)\n", a->name, sval); + fprintf(self->dumper.out, " codes_set(ibufr, '%s', %s)\n", a->name_, sval); grib_context_free(c, sval); } @@ -227,12 +227,12 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -253,9 +253,9 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* int cols = 2; long count = 0; char* sval; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -301,19 +301,19 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* fprintf(self->dumper.out, ",)\n"); grib_context_free(c, values); - fprintf(self->dumper.out, " codes_set_array(ibufr, '%s->%s' \n, rvalues)\n", prefix, a->name); + fprintf(self->dumper.out, " codes_set_array(ibufr, '%s->%s' \n, rvalues)\n", prefix, a->name_); } else { sval = dval_to_string(c, value); - fprintf(self->dumper.out, " codes_set(ibufr, '%s->%s' \n,%s)\n", prefix, a->name, sval); + fprintf(self->dumper.out, " codes_set(ibufr, '%s->%s' \n,%s)\n", prefix, a->name_, sval); grib_context_free(c, sval); } if (self->isLeaf == 0) { char* prefix1; - prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + strlen(prefix) + 5)); - snprintf(prefix1, 1024, "%s->%s", prefix, a->name); + prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + strlen(prefix) + 5)); + snprintf(prefix1, 1024, "%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -326,7 +326,7 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* static int is_hidden(grib_accessor* a) { - return ( (a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ); + return ( (a->flags_ & GRIB_ACCESSOR_FLAG_HIDDEN) != 0 ); } static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) @@ -339,34 +339,34 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int cols = 4; long count = 0; char* sval = NULL; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); int doing_unexpandedDescriptors = 0; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { /* key does not have the dump attribute */ + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) { /* key does not have the dump attribute */ int skip = 1; /* See ECC-1107 */ - if (!is_hidden(a) && strcmp(a->name, "messageLength") == 0) skip = 0; + if (!is_hidden(a) && strcmp(a->name_, "messageLength") == 0) skip = 0; if (skip) return; } - doing_unexpandedDescriptors = (strcmp(a->name, "unexpandedDescriptors") == 0); + doing_unexpandedDescriptors = (strcmp(a->name_, "unexpandedDescriptors") == 0); a->value_count(&count); size = size2 = count; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { if (self->isLeaf == 0) { char* prefix; int dofree = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -377,7 +377,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } if (size > 1) { - values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + values = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * size); err = a->unpack_long(values, &size2); } else { @@ -409,33 +409,33 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, ",) # %lu values\n", (unsigned long)size); else fprintf(self->dumper.out, ",)\n"); - grib_context_free(a->context, values); + grib_context_free(a->context_, values); - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) { - fprintf(self->dumper.out, " codes_set_array(ibufr, '#%d#%s', ivalues)\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) { + fprintf(self->dumper.out, " codes_set_array(ibufr, '#%d#%s', ivalues)\n", r, a->name_); } else { if (doing_unexpandedDescriptors) { fprintf(self->dumper.out, "\n # Create the structure of the data section\n"); /* fprintf(self->dumper.out," codes_set(ibufr, 'skipExtraKeyAttributes', 1)\n"); */ } - fprintf(self->dumper.out, " codes_set_array(ibufr, '%s', ivalues)\n", a->name); + fprintf(self->dumper.out, " codes_set_array(ibufr, '%s', ivalues)\n", a->name_); if (doing_unexpandedDescriptors) fprintf(self->dumper.out, "\n"); } } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); sval = lval_to_string(c, value); if (r != 0) { - fprintf(self->dumper.out, " codes_set(ibufr, '#%d#%s', ", r, a->name); + fprintf(self->dumper.out, " codes_set(ibufr, '#%d#%s', ", r, a->name_); } else { if (doing_unexpandedDescriptors) { fprintf(self->dumper.out, "\n # Create the structure of the data section\n"); /* fprintf(self->dumper.out," codes_set(ibufr, 'skipExtraKeyAttributes', 1)\n"); */ } - fprintf(self->dumper.out, " codes_set(ibufr, '%s', ", a->name); + fprintf(self->dumper.out, " codes_set(ibufr, '%s', ", a->name_); } fprintf(self->dumper.out, "%s)\n", sval); @@ -449,12 +449,12 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -473,16 +473,16 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr int err = 0, i = 0, icount = 0; int cols = 4; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); size = size2 = count; if (size > 1) { - values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + values = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * size); err = a->unpack_long(values, &size2); } else { @@ -514,14 +514,14 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr fprintf(self->dumper.out, ",) # %lu values\n", (unsigned long)size); else fprintf(self->dumper.out, ",)\n"); - grib_context_free(a->context, values); + grib_context_free(a->context_, values); - fprintf(self->dumper.out, " codes_set_array(ibufr, '%s->%s', ivalues)\n", prefix, a->name); + fprintf(self->dumper.out, " codes_set_array(ibufr, '%s->%s', ivalues)\n", prefix, a->name_); } else { if (!codes_bufr_key_exclude_from_dump(prefix)) { char* sval = lval_to_string(c, value); - fprintf(self->dumper.out, " codes_set(ibufr, '%s->%s', ", prefix, a->name); + fprintf(self->dumper.out, " codes_set(ibufr, '%s->%s', ", prefix, a->name_); fprintf(self->dumper.out, "%s)\n", sval); grib_context_free(c, sval); } @@ -530,8 +530,8 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr if (self->isLeaf == 0) { char* prefix1; - prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + strlen(prefix) + 5)); - snprintf(prefix1, 1024, "%s->%s", prefix, a->name); + prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + strlen(prefix) + 5)); + snprintf(prefix1, 1024, "%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -555,19 +555,19 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) grib_handle* h = grib_handle_of_accessor(a); grib_context* c = h->context; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->unpack_double(&value, &size); self->empty = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); sval = dval_to_string(c, value); if (r != 0) - fprintf(self->dumper.out, " codes_set(ibufr, '#%d#%s', %s)\n", r, a->name, sval); + fprintf(self->dumper.out, " codes_set(ibufr, '#%d#%s', %s)\n", r, a->name_, sval); else - fprintf(self->dumper.out, " codes_set(ibufr, '%s', %s)\n", a->name, sval); + fprintf(self->dumper.out, " codes_set(ibufr, '%s', %s)\n", a->name_, sval); grib_context_free(c, sval); if (self->isLeaf == 0) { @@ -575,12 +575,12 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -594,13 +594,13 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm grib_dumper_bufr_encode_python* self = (grib_dumper_bufr_encode_python*)d; char** values; size_t size = 0, i = 0; - grib_context* c = a->context; + grib_context* c = a->context_; int err = 0; long count = 0; int r = 0; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -631,18 +631,18 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm char* prefix; int dofree = 0; - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, " codes_set_array(ibufr, '#%d#%s', svalues)\n", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, " codes_set_array(ibufr, '#%d#%s', svalues)\n", r, a->name_); else - fprintf(self->dumper.out, " codes_set_array(ibufr, '%s', svalues)\n", a->name); + fprintf(self->dumper.out, " codes_set_array(ibufr, '%s', svalues)\n", a->name_); if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -660,16 +660,16 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) char* value = NULL; char* p = NULL; size_t size = 0; - grib_context* c = a->context; + grib_context* c = a->context_; int r = 0, err = 0; grib_handle* h = grib_handle_of_accessor(a); - const char* acc_name = a->name; + const char* acc_name = a->name_; grib_get_string_length_acc(a, &size); if (size == 0) return; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; value = (char*)grib_context_malloc_clear(c, size); @@ -772,9 +772,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key, const cha static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_encode_python* self = (grib_dumper_bufr_encode_python*)d; - if (strcmp(a->name, "BUFR")==0 || - strcmp(a->name, "GRIB")==0 || - strcmp(a->name, "META")==0) { + if (strcmp(a->name_, "BUFR")==0 || + strcmp(a->name_, "GRIB")==0 || + strcmp(a->name_, "META")==0) { grib_handle* h = grib_handle_of_accessor(a); depth = 2; self->empty = 1; @@ -787,8 +787,8 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); depth -= 2; } - else if (strcmp(a->name, "groupNumber")==0) { - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + else if (strcmp(a->name_, "groupNumber")==0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->empty = 1; depth += 2; @@ -805,26 +805,26 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix int i = 0; grib_dumper_bufr_encode_python* self = (grib_dumper_bufr_encode_python*)d; unsigned long flags; - while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { + while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes_[i]) { self->isAttribute = 1; - if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes[i]->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { + if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes_[i]->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) { i++; continue; } - self->isLeaf = a->attributes[i]->attributes[0] == NULL ? 1 : 0; - flags = a->attributes[i]->flags; - a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (a->attributes[i]->get_native_type()) { + self->isLeaf = a->attributes_[i]->attributes_[0] == NULL ? 1 : 0; + flags = a->attributes_[i]->flags_; + a->attributes_[i]->flags_ |= GRIB_ACCESSOR_FLAG_DUMP; + switch (a->attributes_[i]->get_native_type()) { case GRIB_TYPE_LONG: - dump_long_attribute(d, a->attributes[i], prefix); + dump_long_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_DOUBLE: - dump_values_attribute(d, a->attributes[i], prefix); + dump_values_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_STRING: break; } - a->attributes[i]->flags = flags; + a->attributes_[i]->flags_ = flags; i++; } self->isLeaf = 0; diff --git a/src/grib_dumper_class_bufr_simple.cc b/src/grib_dumper_class_bufr_simple.cc index 868b81ba5..eb9206cef 100644 --- a/src/grib_dumper_class_bufr_simple.cc +++ b/src/grib_dumper_class_bufr_simple.cc @@ -135,10 +135,10 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int i, r; int cols = 9; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -158,10 +158,10 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if (size > 1) { int icount = 0; - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, "#%d#%s=", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, "#%d#%s=", r, a->name_); else - fprintf(self->dumper.out, "%s=", a->name); + fprintf(self->dumper.out, "%s=", a->name_); fprintf(self->dumper.out, "{"); @@ -182,11 +182,11 @@ static void dump_values(grib_dumper* d, grib_accessor* a) grib_context_free(c, values); } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (r != 0) - fprintf(self->dumper.out, "#%d#%s=", r, a->name); + fprintf(self->dumper.out, "#%d#%s=", r, a->name_); else - fprintf(self->dumper.out, "%s=", a->name); + fprintf(self->dumper.out, "%s=", a->name_); if (!grib_is_missing_double(a, value)) { fprintf(self->dumper.out, "%g\n", value); @@ -201,12 +201,12 @@ static void dump_values(grib_dumper* d, grib_accessor* a) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -226,9 +226,9 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* int i, icount; int cols = 9; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -246,7 +246,7 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* self->empty = 0; if (size > 1) { - fprintf(self->dumper.out, "%s->%s = {", prefix, a->name); + fprintf(self->dumper.out, "%s->%s = {", prefix, a->name_); icount = 0; for (i = 0; i < size - 1; ++i) { if (icount > cols || i == 0) { @@ -265,20 +265,20 @@ static void dump_values_attribute(grib_dumper* d, grib_accessor* a, const char* grib_context_free(c, values); } else { - /* int r=compute_bufr_key_rank(h,self->keys,a->name); */ + /* int r=compute_bufr_key_rank(h,self->keys,a->name_); */ if (!grib_is_missing_double(a, value)) { - fprintf(self->dumper.out, "%s->%s = %g\n", prefix, a->name, value); + fprintf(self->dumper.out, "%s->%s = %g\n", prefix, a->name_, value); } else { - fprintf(self->dumper.out, "%s->%s = MISSING\n", prefix, a->name); + fprintf(self->dumper.out, "%s->%s = MISSING\n", prefix, a->name_); } } if (self->isLeaf == 0) { char* prefix1; - prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + strlen(prefix) + 5)); - snprintf(prefix1, 1024, "%s->%s", prefix, a->name); + prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + strlen(prefix) + 5)); + snprintf(prefix1, 1024, "%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -298,38 +298,38 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int i, r, icount; int cols = 9; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; a->value_count(&count); size = size2 = count; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { if (self->isLeaf == 0) { char* prefix; int dofree = 0; /* Note: the "subsetNumber" key is only there for UNCOMPRESSED BUFR messages */ - if (self->numberOfSubsets > 1 && strcmp(a->name, "subsetNumber") == 0) { + if (self->numberOfSubsets > 1 && strcmp(a->name_, "subsetNumber") == 0) { err = a->unpack_long(&value, &size); DEBUG_ASSERT(!err); - fprintf(self->dumper.out, "%s=%ld\n", a->name, value); + fprintf(self->dumper.out, "%s=%ld\n", a->name_, value); DEBUG_ASSERT(!grib_is_missing_long(a, value)); (void)err; return; } - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -339,7 +339,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } if (size > 1) { - values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + values = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * size); err = a->unpack_long(values, &size2); } else { @@ -352,13 +352,13 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if (size > 1) { int doing_unexpandedDescriptors = 0; icount = 0; - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, "#%d#%s=", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, "#%d#%s=", r, a->name_); else - fprintf(self->dumper.out, "%s=", a->name); + fprintf(self->dumper.out, "%s=", a->name_); fprintf(self->dumper.out, "{"); - if (strcmp(a->name, "unexpandedDescriptors") == 0) + if (strcmp(a->name_, "unexpandedDescriptors") == 0) doing_unexpandedDescriptors = 1; for (i = 0; i < size - 1; i++) { @@ -381,14 +381,14 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, "%ld ", values[i]); fprintf(self->dumper.out, "}\n"); - grib_context_free(a->context, values); + grib_context_free(a->context_, values); } else { - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (r != 0) - fprintf(self->dumper.out, "#%d#%s=", r, a->name); + fprintf(self->dumper.out, "#%d#%s=", r, a->name_); else - fprintf(self->dumper.out, "%s=", a->name); + fprintf(self->dumper.out, "%s=", a->name_); if (!grib_is_missing_long(a, value)) { fprintf(self->dumper.out, "%ld\n", value); @@ -403,12 +403,12 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -427,16 +427,16 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr int i, icount; int cols = 9; long count = 0; - grib_context* c = a->context; + grib_context* c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); size = size2 = count; if (size > 1) { - values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + values = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * size); err = a->unpack_long(values, &size2); } else { @@ -447,7 +447,7 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr self->empty = 0; if (size > 1) { - fprintf(self->dumper.out, "%s->%s = {", prefix, a->name); + fprintf(self->dumper.out, "%s->%s = {", prefix, a->name_); icount = 0; for (i = 0; i < size - 1; i++) { if (icount > cols || i == 0) { @@ -462,24 +462,24 @@ static void dump_long_attribute(grib_dumper* d, grib_accessor* a, const char* pr } fprintf(self->dumper.out, "%ld ", values[i]); fprintf(self->dumper.out, "}\n"); - grib_context_free(a->context, values); + grib_context_free(a->context_, values); } else { - /* int r=compute_bufr_key_rank(h,self->keys,a->name); */ + /* int r=compute_bufr_key_rank(h,self->keys,a->name_); */ if (!codes_bufr_key_exclude_from_dump(prefix)) { if (!grib_is_missing_long(a, value)) { - fprintf(self->dumper.out, "%s->%s = ", prefix, a->name); + fprintf(self->dumper.out, "%s->%s = ", prefix, a->name_); fprintf(self->dumper.out, "%ld\n", value); } else { - fprintf(self->dumper.out, "%s->%s = MISSING\n", prefix, a->name); + fprintf(self->dumper.out, "%s->%s = MISSING\n", prefix, a->name_); } } } if (self->isLeaf == 0) { - char* prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + strlen(prefix) + 5)); - snprintf(prefix1, 1024, "%s->%s", prefix, a->name); + char* prefix1 = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + strlen(prefix) + 5)); + snprintf(prefix1, 1024, "%s->%s", prefix, a->name_); dump_attributes(d, a, prefix1); @@ -501,18 +501,18 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) grib_handle* h = grib_handle_of_accessor(a); grib_context* c = h->context; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->unpack_double(&value, &size); self->empty = 0; - r = compute_bufr_key_rank(h, self->keys, a->name); + r = compute_bufr_key_rank(h, self->keys, a->name_); if (r != 0) - fprintf(self->dumper.out, "#%d#%s=", r, a->name); + fprintf(self->dumper.out, "#%d#%s=", r, a->name_); else - fprintf(self->dumper.out, "%s=", a->name); + fprintf(self->dumper.out, "%s=", a->name_); if (!grib_is_missing_double(a, value)) { fprintf(self->dumper.out, "%g\n", value); @@ -526,12 +526,12 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -544,14 +544,14 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm grib_dumper_bufr_simple* self = (grib_dumper_bufr_simple*)d; char** values = NULL; size_t size = 0, i = 0; - grib_context* c = a->context; + grib_context* c = a->context_; int err = 0; int is_missing = 0; long count = 0; int r = 0; grib_handle* h = grib_handle_of_accessor(a); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) return; a->value_count(&count); @@ -562,10 +562,10 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm } if (self->isLeaf == 0) { - if ((r = compute_bufr_key_rank(h, self->keys, a->name)) != 0) - fprintf(self->dumper.out, "#%d#%s=", r, a->name); + if ((r = compute_bufr_key_rank(h, self->keys, a->name_)) != 0) + fprintf(self->dumper.out, "#%d#%s=", r, a->name_); else - fprintf(self->dumper.out, "%s=", a->name); + fprintf(self->dumper.out, "%s=", a->name_); } self->empty = 0; @@ -595,12 +595,12 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm int dofree = 0; if (r != 0) { - prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name) + 10)); + prefix = (char*)grib_context_malloc_clear(c, sizeof(char) * (strlen(a->name_) + 10)); dofree = 1; - snprintf(prefix, 1024, "#%d#%s", r, a->name); + snprintf(prefix, 1024, "#%d#%s", r, a->name_); } else - prefix = (char*)a->name; + prefix = (char*)a->name_; dump_attributes(d, a, prefix); if (dofree) @@ -618,14 +618,14 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) char value[MAX_STRING_SIZE] = {0,}; /* See ECC-710 */ char* p = NULL; size_t size = MAX_STRING_SIZE; - grib_context* c = a->context; + grib_context* c = a->context_; int r = 0; int is_missing = 0; int err = 0; grib_handle* h = grib_handle_of_accessor(a); - const char* acc_name = a->name; + const char* acc_name = a->name_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0 || (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { return; } @@ -723,9 +723,9 @@ static void _dump_long_array(grib_handle* h, FILE* f, const char* key) static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_bufr_simple* self = (grib_dumper_bufr_simple*)d; - if (strcmp(a->name, "BUFR")==0 || - strcmp(a->name, "GRIB")==0 || - strcmp(a->name, "META")==0) { + if (strcmp(a->name_, "BUFR")==0 || + strcmp(a->name_, "GRIB")==0 || + strcmp(a->name_, "META")==0) { int err = 0; grib_handle* h = grib_handle_of_accessor(a); self->empty = 1; @@ -740,8 +740,8 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso /*_dump_long_array(h,self->dumper.out,"inputOverriddenReferenceValues","inputOverriddenReferenceValues");*/ grib_dump_accessors_block(d, block); } - else if (strcmp(a->name, "groupNumber")==0) { - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + else if (strcmp(a->name_, "groupNumber")==0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; self->empty = 1; grib_dump_accessors_block(d, block); @@ -756,29 +756,29 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a, const char* prefix int i = 0; grib_dumper_bufr_simple* self = (grib_dumper_bufr_simple*)d; unsigned long flags; - while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { + while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes_[i]) { self->isAttribute = 1; - if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes[i]->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { + if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes_[i]->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) { i++; continue; } - self->isLeaf = a->attributes[i]->attributes[0] == NULL ? 1 : 0; + self->isLeaf = a->attributes_[i]->attributes_[0] == NULL ? 1 : 0; /* fprintf(self->dumper.out,","); */ /* fprintf(self->dumper.out,"\n%-*s",depth," "); */ - /* fprintf(out,"\"%s\" : ",a->attributes[i]->name); */ - flags = a->attributes[i]->flags; - a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (a->attributes[i]->get_native_type()) { + /* fprintf(out,"\"%s\" : ",a->attributes_[i]->name); */ + flags = a->attributes_[i]->flags_; + a->attributes_[i]->flags_ |= GRIB_ACCESSOR_FLAG_DUMP; + switch (a->attributes_[i]->get_native_type()) { case GRIB_TYPE_LONG: - dump_long_attribute(d, a->attributes[i], prefix); + dump_long_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_DOUBLE: - dump_values_attribute(d, a->attributes[i], prefix); + dump_values_attribute(d, a->attributes_[i], prefix); break; case GRIB_TYPE_STRING: break; } - a->attributes[i]->flags = flags; + a->attributes_[i]->flags_ = flags; i++; } self->isLeaf = 0; diff --git a/src/grib_dumper_class_debug.cc b/src/grib_dumper_class_debug.cc index ead1c7cf4..6f97c0c54 100644 --- a/src/grib_dumper_class_debug.cc +++ b/src/grib_dumper_class_debug.cc @@ -103,7 +103,7 @@ static int destroy(grib_dumper* d) static void default_long_value(grib_dumper* d, grib_accessor* a, long actualValue) { grib_dumper_debug* self = (grib_dumper_debug*)d; - grib_action* act = a->creator; + grib_action* act = a->creator_; if (act->default_value == NULL) return; @@ -127,7 +127,7 @@ static void default_long_value(grib_dumper* d, grib_accessor* a, long actualValu // static void default_string_value(grib_dumper* d, grib_accessor* a, const char* actualValue) // { // grib_dumper_debug* self = (grib_dumper_debug*)d; -// grib_action* act = a->creator; +// grib_action* act = a->creator_; // if (act->default_value == NULL) // return; @@ -154,16 +154,16 @@ static void aliases(grib_dumper* d, grib_accessor* a) int i; grib_dumper_debug* self = (grib_dumper_debug*)d; - if (a->all_names[1]) { + if (a->all_names_[1]) { const char* sep = ""; fprintf(self->dumper.out, " ["); for (i = 1; i < MAX_ACCESSOR_NAMES; i++) { - if (a->all_names[i]) { - if (a->all_name_spaces[i]) - fprintf(self->dumper.out, "%s%s.%s", sep, a->all_name_spaces[i], a->all_names[i]); + if (a->all_names_[i]) { + if (a->all_name_spaces_[i]) + fprintf(self->dumper.out, "%s%s.%s", sep, a->all_name_spaces_[i], a->all_names_[i]); else - fprintf(self->dumper.out, "%s%s", sep, a->all_names[i]); + fprintf(self->dumper.out, "%s%s", sep, a->all_names_[i]); } sep = ", "; } @@ -181,17 +181,17 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) long count = 0; int err = 0, i = 0; - if (a->length == 0 && (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) + if (a->length_ == 0 && (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) return; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0) return; a->value_count(&count); size = count; if (size > 1) { - values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + values = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * size); err = a->unpack_long(values, &size); } else { @@ -204,7 +204,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, " "); if (size > 1) { - fprintf(self->dumper.out, "%ld-%ld %s %s = {\n", self->begin, self->theEnd, a->creator->op, a->name); + fprintf(self->dumper.out, "%ld-%ld %s %s = {\n", self->begin, self->theEnd, a->creator_->op, a->name_); if (values) { int k = 0; if (size > 100) { @@ -229,22 +229,22 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) } for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "} # %s %s \n", a->creator->op, a->name); - grib_context_free(a->context, values); + fprintf(self->dumper.out, "} # %s %s \n", a->creator_->op, a->name_); + grib_context_free(a->context_, values); } } else { - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) - fprintf(self->dumper.out, "%ld-%ld %s %s = MISSING", self->begin, self->theEnd, a->creator->op, a->name); + if (((a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) + fprintf(self->dumper.out, "%ld-%ld %s %s = MISSING", self->begin, self->theEnd, a->creator_->op, a->name_); else - fprintf(self->dumper.out, "%ld-%ld %s %s = %ld", self->begin, self->theEnd, a->creator->op, a->name, value); + fprintf(self->dumper.out, "%ld-%ld %s %s = %ld", self->begin, self->theEnd, a->creator_->op, a->name_, value); if (comment) fprintf(self->dumper.out, " [%s]", comment); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) fprintf(self->dumper.out, " (%s)", grib_get_type_name(a->get_native_type())); - if ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) fprintf(self->dumper.out, " %s", "(can be missing)"); - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) fprintf(self->dumper.out, " %s", "(read-only)"); } if (err) @@ -269,7 +269,7 @@ static void dump_bits(grib_dumper* d, grib_accessor* a, const char* comment) int err = a->unpack_long(&value, &size); int i; - if (a->length == 0 && + if (a->length_ == 0 && (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) return; @@ -277,10 +277,10 @@ static void dump_bits(grib_dumper* d, grib_accessor* a, const char* comment) for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "%ld-%ld %s %s = %ld [", self->begin, self->theEnd, a->creator->op, a->name, value); + fprintf(self->dumper.out, "%ld-%ld %s %s = %ld [", self->begin, self->theEnd, a->creator_->op, a->name_, value); - for (i = 0; i < (a->length * 8); i++) { - if (test_bit(value, a->length * 8 - i - 1)) + for (i = 0; i < (a->length_ * 8); i++) { + if (test_bit(value, a->length_ * 8 - i - 1)) fprintf(self->dumper.out, "1"); else fprintf(self->dumper.out, "0"); @@ -306,7 +306,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) int err = a->unpack_double(&value, &size); int i; - if (a->length == 0 && + if (a->length_ == 0 && (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) return; @@ -315,10 +315,10 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) - fprintf(self->dumper.out, "%ld-%ld %s %s = MISSING", self->begin, self->theEnd, a->creator->op, a->name); + if (((a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) + fprintf(self->dumper.out, "%ld-%ld %s %s = MISSING", self->begin, self->theEnd, a->creator_->op, a->name_); else - fprintf(self->dumper.out, "%ld-%ld %s %s = %g", self->begin, self->theEnd, a->creator->op, a->name, value); + fprintf(self->dumper.out, "%ld-%ld %s %s = %g", self->begin, self->theEnd, a->creator_->op, a->name_, value); if (comment) fprintf(self->dumper.out, " [%s]", comment); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) @@ -338,7 +338,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) char* value = NULL; char* p = NULL; - if (a->length == 0 && (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) + if (a->length_ == 0 && (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) return; grib_get_string_length_acc(a, &size); @@ -347,7 +347,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) size = 10; /* big enough to hold the string "missing" */ } - value = (char*)grib_context_malloc_clear(a->context, size); + value = (char*)grib_context_malloc_clear(a->context_, size); if (!value) return; err = a->unpack_string(value, &size); @@ -367,7 +367,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "%ld-%ld %s %s = %s", self->begin, self->theEnd, a->creator->op, a->name, value); + fprintf(self->dumper.out, "%ld-%ld %s %s = %s", self->begin, self->theEnd, a->creator_->op, a->name_, value); if (comment) fprintf(self->dumper.out, " [%s]", comment); @@ -379,7 +379,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) aliases(d, a); fprintf(self->dumper.out, "\n"); - grib_context_free(a->context, value); + grib_context_free(a->context_, value); } static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) @@ -387,10 +387,10 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) grib_dumper_debug* self = (grib_dumper_debug*)d; int i, k, err = 0; size_t more = 0; - size_t size = a->length; + size_t size = a->length_; unsigned char* buf = (unsigned char*)grib_context_malloc(d->context, size); - if (a->length == 0 && + if (a->length_ == 0 && (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) return; @@ -398,7 +398,7 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "%ld-%ld %s %s = %ld", self->begin, self->theEnd, a->creator->op, a->name, a->length); + fprintf(self->dumper.out, "%ld-%ld %s %s = %ld", self->begin, self->theEnd, a->creator_->op, a->name_, a->length_); aliases(d, a); fprintf(self->dumper.out, " {"); @@ -446,7 +446,7 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "} # %s %s \n", a->creator->op, a->name); + fprintf(self->dumper.out, "} # %s %s \n", a->creator_->op, a->name_); grib_context_free(d->context, buf); } @@ -459,7 +459,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) size_t size = 0; long count = 0; - if (a->length == 0 && + if (a->length_ == 0 && (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) return; @@ -475,7 +475,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "%ld-%ld %s %s = (%ld,%ld)", self->begin, self->theEnd, a->creator->op, a->name, (long)size, a->length); + fprintf(self->dumper.out, "%ld-%ld %s %s = (%ld,%ld)", self->begin, self->theEnd, a->creator_->op, a->name_, (long)size, a->length_); aliases(d, a); fprintf(self->dumper.out, " {"); @@ -521,7 +521,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "} # %s %s \n", a->creator->op, a->name); + fprintf(self->dumper.out, "} # %s %s \n", a->creator_->op, a->name_); grib_context_free(d->context, buf); } @@ -531,7 +531,7 @@ static void dump_label(grib_dumper* d, grib_accessor* a, const char* comment) int i; for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "----> %s %s %s\n", a->creator->op, a->name, comment ? comment : ""); + fprintf(self->dumper.out, "----> %s %s %s\n", a->creator_->op, a->name_, comment ? comment : ""); } static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) @@ -539,19 +539,19 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dumper_debug* self = (grib_dumper_debug*)d; int i; /* grib_section* s = grib_get_sub_section(a); */ - grib_section* s = a->sub_section; + grib_section* s = a->sub_section_; - if (a->name[0] == '_') { + if (a->name_[0] == '_') { grib_dump_accessors_block(d, block); return; } for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "======> %s %s (%ld,%ld,%ld)\n", a->creator->op, - a->name, a->length, (long)s->length, (long)s->padding); - if (!strncmp(a->name, "section", 7)) - self->section_offset = a->offset; + fprintf(self->dumper.out, "======> %s %s (%ld,%ld,%ld)\n", a->creator_->op, + a->name_, a->length_, (long)s->length, (long)s->padding); + if (!strncmp(a->name_, "section", 7)) + self->section_offset = a->offset_; /*printf("------------- section_offset = %ld\n",self->section_offset);*/ d->depth += 3; grib_dump_accessors_block(d, block); @@ -559,18 +559,18 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "<===== %s %s\n", a->creator->op, a->name); + fprintf(self->dumper.out, "<===== %s %s\n", a->creator_->op, a->name_); } static void set_begin_end(grib_dumper* d, grib_accessor* a) { grib_dumper_debug* self = (grib_dumper_debug*)d; if ((d->option_flags & GRIB_DUMP_FLAG_OCTET) != 0) { - self->begin = a->offset - self->section_offset + 1; + self->begin = a->offset_ - self->section_offset + 1; self->theEnd = a->get_next_position_offset() - self->section_offset; } else { - self->begin = a->offset; + self->begin = a->offset_; self->theEnd = a->get_next_position_offset(); } } diff --git a/src/grib_dumper_class_default.cc b/src/grib_dumper_class_default.cc index 819344cbe..476517e62 100644 --- a/src/grib_dumper_class_default.cc +++ b/src/grib_dumper_class_default.cc @@ -8,11 +8,6 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/************************************** - * Enrico Fucile - **************************************/ - - #include "grib_api_internal.h" #include /* @@ -116,17 +111,17 @@ static void aliases(grib_dumper* d, grib_accessor* a) if ((d->option_flags & GRIB_DUMP_FLAG_ALIASES) == 0) return; - if (a->all_names[1]) { + if (a->all_names_[1]) { const char* sep = ""; fprintf(self->dumper.out, " "); fprintf(self->dumper.out, "# ALIASES: "); for (i = 1; i < MAX_ACCESSOR_NAMES; i++) { - if (a->all_names[i]) { - if (a->all_name_spaces[i]) - fprintf(self->dumper.out, "%s%s.%s", sep, a->all_name_spaces[i], a->all_names[i]); + if (a->all_names_[i]) { + if (a->all_name_spaces_[i]) + fprintf(self->dumper.out, "%s%s.%s", sep, a->all_name_spaces_[i], a->all_names_[i]); else - fprintf(self->dumper.out, "%s%s", sep, a->all_names[i]); + fprintf(self->dumper.out, "%s%s", sep, a->all_names_[i]); } sep = ", "; } @@ -144,7 +139,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int i; long count = 0; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; a->value_count(&count); @@ -154,11 +149,11 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) { fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "# type %s (int)\n", a->creator->op); + fprintf(self->dumper.out, "# type %s (int)\n", a->creator_->op); } if (size > 1) { - values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + values = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * size); err = a->unpack_long(values, &size2); } else { @@ -172,7 +167,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, "# %s \n", comment); } - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) { + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) { fprintf(self->dumper.out, " "); fprintf(self->dumper.out, "#-READ ONLY- "); } @@ -182,7 +177,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) if (size > 1) { int cols = 19; int icount = 0; - fprintf(self->dumper.out, "%s = { \t", a->name); + fprintf(self->dumper.out, "%s = { \t", a->name_); for (i = 0; i < size; i++) { if (icount > cols) { fprintf(self->dumper.out, "\n\t\t\t\t"); @@ -192,13 +187,13 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) icount++; } fprintf(self->dumper.out, "}\n"); - grib_context_free(a->context, values); + grib_context_free(a->context_, values); } else { - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) - fprintf(self->dumper.out, "%s = MISSING;", a->name); + if (((a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) + fprintf(self->dumper.out, "%s = MISSING;", a->name_); else - fprintf(self->dumper.out, "%s = %ld;", a->name, value); + fprintf(self->dumper.out, "%s = %ld;", a->name_, value); } if (err) { @@ -236,14 +231,14 @@ static void dump_bits(grib_dumper* d, grib_accessor* a, const char* comment) break; } - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; print_offset(self->dumper.out, d, a); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) { fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "# type %s \n", a->creator->op); + fprintf(self->dumper.out, "# type %s \n", a->creator_->op); } aliases(d, a); @@ -254,28 +249,28 @@ static void dump_bits(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, " "); fprintf(self->dumper.out, "# flags: "); - for (i = 0; i < (a->length * 8); i++) { - if (test_bit(lvalue, a->length * 8 - i - 1)) + for (i = 0; i < (a->length_ * 8); i++) { + if (test_bit(lvalue, a->length_ * 8 - i - 1)) fprintf(self->dumper.out, "1"); else fprintf(self->dumper.out, "0"); } fprintf(self->dumper.out, "\n"); - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) { + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) { fprintf(self->dumper.out, " "); fprintf(self->dumper.out, "#-READ ONLY- "); } else fprintf(self->dumper.out, " "); - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) - fprintf(self->dumper.out, "%s = MISSING;", a->name); + if (((a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) + fprintf(self->dumper.out, "%s = MISSING;", a->name_); else { if (isDouble) - fprintf(self->dumper.out, "%s = %g;", a->name, dvalue); + fprintf(self->dumper.out, "%s = %g;", a->name_, dvalue); else - fprintf(self->dumper.out, "%s = %ld;", a->name, lvalue); + fprintf(self->dumper.out, "%s = %ld;", a->name_, lvalue); } @@ -294,14 +289,14 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) size_t size = 1; int err = a->unpack_double(&value, &size); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; print_offset(self->dumper.out, d, a); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) { fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "# type %s (double)\n", a->creator->op); + fprintf(self->dumper.out, "# type %s (double)\n", a->creator_->op); } aliases(d, a); @@ -311,17 +306,17 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) } - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) { + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) { fprintf(self->dumper.out, " "); fprintf(self->dumper.out, "#-READ ONLY- "); } else fprintf(self->dumper.out, " "); - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) - fprintf(self->dumper.out, "%s = MISSING;", a->name); + if (((a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) + fprintf(self->dumper.out, "%s = MISSING;", a->name_); else - fprintf(self->dumper.out, "%s = %g;", a->name, value); + fprintf(self->dumper.out, "%s = %g;", a->name_, value); if (err) { fprintf(self->dumper.out, " "); @@ -336,7 +331,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm grib_dumper_default* self = (grib_dumper_default*)d; char** values; size_t size = 0, i = 0; - grib_context* c = a->context; + grib_context* c = a->context_; int err = 0; int tab = 0; long count = 0; @@ -356,14 +351,14 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm err = a->unpack_string_array(values, &size); - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; print_offset(self->dumper.out, d, a); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) { fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "# type %s (str)\n", a->creator->op); + fprintf(self->dumper.out, "# type %s (str)\n", a->creator_->op); } aliases(d, a); @@ -372,7 +367,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm fprintf(self->dumper.out, "# %s \n", comment); } - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) { + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) { fprintf(self->dumper.out, " "); fprintf(self->dumper.out, "#-READ ONLY- "); tab = 13; @@ -382,9 +377,9 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm } tab++; - fprintf(self->dumper.out, "%s = {\n", a->name); + fprintf(self->dumper.out, "%s = {\n", a->name_); for (i = 0; i < size; i++) { - fprintf(self->dumper.out, "%-*s\"%s\",\n", (int)(tab + strlen(a->name) + 4), " ", values[i]); + fprintf(self->dumper.out, "%-*s\"%s\",\n", (int)(tab + strlen(a->name_) + 4), " ", values[i]); } fprintf(self->dumper.out, " }"); @@ -403,10 +398,10 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) char* value = NULL; char* p = NULL; size_t size = 0; - grib_context* c = a->context; + grib_context* c = a->context_; int err = 0; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) { return; } @@ -433,7 +428,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) { fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "# type %s (str)\n", a->creator->op); + fprintf(self->dumper.out, "# type %s (str)\n", a->creator_->op); } aliases(d, a); @@ -442,17 +437,17 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, "# %s \n", comment); } - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) { + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) { fprintf(self->dumper.out, " "); fprintf(self->dumper.out, "#-READ ONLY- "); } else fprintf(self->dumper.out, " "); - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) - fprintf(self->dumper.out, "%s = MISSING;", a->name); + if (((a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) + fprintf(self->dumper.out, "%s = MISSING;", a->name_); else - fprintf(self->dumper.out, "%s = %s;", a->name, value); + fprintf(self->dumper.out, "%s = %s;", a->name_, value); if (err) { @@ -469,22 +464,22 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) // grib_dumper_default *self = (grib_dumper_default*)d; // int i,k,err =0; // size_t more = 0; -// size_t size = a->length; +// size_t size = a->length_; // unsigned char* buf = grib_context_malloc(d->context,size); -// if ( (a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) +// if ( (a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) // return; -// if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) +// if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) // fprintf(self->dumper.out,"-READ ONLY- "); // /*for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," ");*/ // /*print_offset(self->dumper.out,self->begin,self->theEnd);*/ // if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) -// fprintf(self->dumper.out,"%s ",a->creator->op); +// fprintf(self->dumper.out,"%s ",a->creator_->op); -// fprintf(self->dumper.out,"%s = %ld",a->name,a->length); +// fprintf(self->dumper.out,"%s = %ld",a->name_,a->length_); // aliases(d,a); // fprintf(self->dumper.out," {"); @@ -533,7 +528,7 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) // } // for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); -// fprintf(self->dumper.out,"} # %s %s \n",a->creator->op, a->name); +// fprintf(self->dumper.out,"} # %s %s \n",a->creator_->op, a->name_); // grib_context_free(d->context,buf); } @@ -546,7 +541,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) size_t size = 0; long count = 0; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; a->value_count(&count); @@ -570,19 +565,19 @@ static void dump_values(grib_dumper* d, grib_accessor* a) else if (native_type == GRIB_TYPE_STRING) strcpy(type_name, "(str)"); fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "# type %s %s\n", a->creator->op, type_name); + fprintf(self->dumper.out, "# type %s %s\n", a->creator_->op, type_name); } aliases(d, a); - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) { + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) { fprintf(self->dumper.out, " "); fprintf(self->dumper.out, "#-READ ONLY- "); } else fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "%s(%zu) = ", a->name, size); + fprintf(self->dumper.out, "%s(%zu) = ", a->name_, size); aliases(d, a); fprintf(self->dumper.out, " {"); @@ -635,7 +630,7 @@ static void dump_label(grib_dumper* d, grib_accessor* a, const char* comment) /*grib_dumper_default *self = (grib_dumper_default*)d; for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); - fprintf(self->dumper.out,"----> %s %s %s\n",a->creator->op, a->name,comment?comment:"");*/ + fprintf(self->dumper.out,"----> %s %s %s\n",a->creator_->op, a->name_,comment?comment:"");*/ } static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) @@ -645,9 +640,9 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso int is_default_section = 0; char* upper = NULL; char *p = NULL, *q = NULL; - if (!strncmp(a->name, "section", 7)) + if (!strncmp(a->name_, "section", 7)) is_default_section = 1; - if (!strcmp(a->creator->op, "bufr_group")) { + if (!strcmp(a->creator_->op, "bufr_group")) { dump_long(d, a, NULL); } @@ -655,9 +650,9 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso if (is_default_section) { /* char tmp[512]; */ /* grib_section* s = a->sub_section; */ - upper = (char*)malloc(strlen(a->name) + 1); + upper = (char*)malloc(strlen(a->name_) + 1); Assert(upper); - p = (char*)a->name; + p = (char*)a->name_; q = upper; while (*p != '\0') { *q = toupper(*p); @@ -669,7 +664,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso /* snprintf(tmp, sizeof(tmp), "%s ( length=%ld, padding=%ld )", upper, (long)s->length, (long)s->padding); */ /* fprintf(self->dumper.out,"#============== %-38s ==============\n",tmp); */ free(upper); - self->section_offset = a->offset; + self->section_offset = a->offset_; } /*printf("------------- section_offset = %ld\n",self->section_offset);*/ @@ -677,7 +672,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso grib_dump_accessors_block(d, block); d->depth -= 3; /*for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," ");*/ - /*fprintf(self->dumper.out,"<===== %s %s\n",a->creator->op, a->name);*/ + /*fprintf(self->dumper.out,"<===== %s %s\n",a->creator_->op, a->name_);*/ } static void print_offset(FILE* out, grib_dumper* d, grib_accessor* a) @@ -689,10 +684,10 @@ static void print_offset(FILE* out, grib_dumper* d, grib_accessor* a) grib_dumper_default* self = (grib_dumper_default*)d; grib_handle* h = grib_handle_of_accessor(a); - theBegin = a->offset - self->section_offset + 1; + theBegin = a->offset_ - self->section_offset + 1; theEnd = a->get_next_position_offset() - self->section_offset; - if ((d->option_flags & GRIB_DUMP_FLAG_HEXADECIMAL) != 0 && a->length != 0) { + if ((d->option_flags & GRIB_DUMP_FLAG_HEXADECIMAL) != 0 && a->length_ != 0) { if (theBegin == theEnd) { fprintf(self->dumper.out, " "); fprintf(out, "# Octet: "); @@ -704,7 +699,7 @@ static void print_offset(FILE* out, grib_dumper* d, grib_accessor* a) fprintf(out, "%ld-%ld", theBegin, theEnd); } fprintf(out, " = "); - size = a->length; + size = a->length_; if (!(d->option_flags & GRIB_DUMP_FLAG_ALL_DATA) && size > 112) { more = size - 112; @@ -713,7 +708,7 @@ static void print_offset(FILE* out, grib_dumper* d, grib_accessor* a) k = 0; while (k < size) { - offset = a->offset; + offset = a->offset_; for (i = 0; i < 14 && k < size; i++, k++) { fprintf(out, " 0x%.2X", h->buffer->data[offset]); offset++; diff --git a/src/grib_dumper_class_grib_encode_C.cc b/src/grib_dumper_class_grib_encode_C.cc index 5c41e11a0..208f7bc90 100644 --- a/src/grib_dumper_class_grib_encode_C.cc +++ b/src/grib_dumper_class_grib_encode_C.cc @@ -132,19 +132,19 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) size_t size = 1; int err = a->unpack_long(&value, &size); - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY)) return; if (comment) pcomment(self->dumper.out, value, comment); - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && (value == GRIB_MISSING_LONG)) - fprintf(self->dumper.out, " GRIB_CHECK(grib_set_missing(h,\"%s\"),%d);\n", a->name, 0); + if (((a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && (value == GRIB_MISSING_LONG)) + fprintf(self->dumper.out, " GRIB_CHECK(grib_set_missing(h,\"%s\"),%d);\n", a->name_, 0); else - fprintf(self->dumper.out, " GRIB_CHECK(grib_set_long(h,\"%s\",%ld),%d);\n", a->name, value, 0); + fprintf(self->dumper.out, " GRIB_CHECK(grib_set_long(h,\"%s\",%ld),%d);\n", a->name_, value, 0); if (err) - fprintf(self->dumper.out, " /* Error accessing %s (%s) */", a->name, grib_get_error_message(err)); + fprintf(self->dumper.out, " /* Error accessing %s (%s) */", a->name_, grib_get_error_message(err)); if (comment) fprintf(self->dumper.out, "\n"); @@ -166,16 +166,16 @@ static void dump_bits(grib_dumper* d, grib_accessor* a, const char* comment) char buf[1024]; - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) return; - if (a->length == 0) + if (a->length_ == 0) return; buf[0] = 0; - for (i = 0; i < (a->length * 8); i++) { - if (test_bit(value, a->length * 8 - i - 1)) + for (i = 0; i < (a->length_ * 8); i++) { + if (test_bit(value, a->length_ * 8 - i - 1)) strcat(buf, "1"); else strcat(buf, "0"); @@ -189,9 +189,9 @@ static void dump_bits(grib_dumper* d, grib_accessor* a, const char* comment) pcomment(self->dumper.out, value, buf); if (err) - fprintf(self->dumper.out, " /* Error accessing %s (%s) */", a->name, grib_get_error_message(err)); + fprintf(self->dumper.out, " /* Error accessing %s (%s) */", a->name_, grib_get_error_message(err)); else - fprintf(self->dumper.out, " GRIB_CHECK(grib_set_long(h,\"%s\",%ld),%d);\n", a->name, value, 0); + fprintf(self->dumper.out, " GRIB_CHECK(grib_set_long(h,\"%s\",%ld),%d);\n", a->name_, value, 0); fprintf(self->dumper.out, "\n"); } @@ -202,18 +202,18 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) double value; size_t size = 1; int err = a->unpack_double(&value, &size); - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) return; - if (a->length == 0) + if (a->length_ == 0) return; //if(comment) fprintf(self->dumper.out,"/* %s */\n",comment); - fprintf(self->dumper.out, " GRIB_CHECK(grib_set_double(h,\"%s\",%g),%d);\n", a->name, value, 0); + fprintf(self->dumper.out, " GRIB_CHECK(grib_set_double(h,\"%s\",%g),%d);\n", a->name_, value, 0); if (err) - fprintf(self->dumper.out, " /* Error accessing %s (%s) */", a->name, grib_get_error_message(err)); + fprintf(self->dumper.out, " /* Error accessing %s (%s) */", a->name_, grib_get_error_message(err)); } static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) @@ -223,10 +223,10 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) size_t size = sizeof(value); int err = a->unpack_string(value, &size); - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) return; - if (a->length == 0) + if (a->length_ == 0) return; if (comment) @@ -234,20 +234,20 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, " p = \"%s\";\n", value); fprintf(self->dumper.out, " size = strlen(p);\n"); - fprintf(self->dumper.out, " GRIB_CHECK(grib_set_string(h,\"%s\",p,&size),%d);\n", a->name, 0); + fprintf(self->dumper.out, " GRIB_CHECK(grib_set_string(h,\"%s\",p,&size),%d);\n", a->name_, 0); if (err) - fprintf(self->dumper.out, " /* Error accessing %s (%s) */", a->name, grib_get_error_message(err)); + fprintf(self->dumper.out, " /* Error accessing %s (%s) */", a->name_, grib_get_error_message(err)); } static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) { grib_dumper_grib_encode_C* self = (grib_dumper_grib_encode_C*)d; int err = 0; - size_t size = a->length; + size_t size = a->length_; unsigned char* buf; - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) return; if (size == 0) @@ -256,7 +256,7 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) buf = (unsigned char*)grib_context_malloc(d->context, size); if (!buf) { - fprintf(self->dumper.out, "/* %s: cannot malloc(%zu) */\n", a->name, size); + fprintf(self->dumper.out, "/* %s: cannot malloc(%zu) */\n", a->name_, size); return; } @@ -302,7 +302,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) stype[0] = '\0'; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) || ((a->flags & GRIB_ACCESSOR_FLAG_DATA) && (d->option_flags & GRIB_DUMP_FLAG_NO_DATA))) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) || ((a->flags_ & GRIB_ACCESSOR_FLAG_DATA) && (d->option_flags & GRIB_DUMP_FLAG_NO_DATA))) return; a->value_count(&count); @@ -327,7 +327,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) buf = (double*)grib_context_malloc(d->context, size * sizeof(double)); if (!buf) { - fprintf(self->dumper.out, "/* %s: cannot malloc(%zu) */\n", a->name, size); + fprintf(self->dumper.out, "/* %s: cannot malloc(%zu) */\n", a->name_, size); return; } @@ -335,7 +335,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if (err) { grib_context_free(d->context, buf); - fprintf(self->dumper.out, " /* Error accessing %s (%s) */", a->name, grib_get_error_message(err)); + fprintf(self->dumper.out, " /* Error accessing %s (%s) */", a->name_, grib_get_error_message(err)); return; } @@ -358,7 +358,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) if (size % 4) fprintf(self->dumper.out, "\n"); fprintf(self->dumper.out, "\n"); - fprintf(self->dumper.out, " GRIB_CHECK(grib_set_%s_array(h,\"%s\",v%s,size),%d);\n", stype, a->name, stype, 0); + fprintf(self->dumper.out, " GRIB_CHECK(grib_set_%s_array(h,\"%s\",v%s,size),%d);\n", stype, a->name_, stype, 0); fprintf(self->dumper.out, " free(v%s);\n", stype); grib_context_free(d->context, buf); @@ -367,7 +367,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) static void dump_label(grib_dumper* d, grib_accessor* a, const char* comment) { grib_dumper_grib_encode_C* self = (grib_dumper_grib_encode_C*)d; - fprintf(self->dumper.out, "\n /* %s */\n\n", a->name); + fprintf(self->dumper.out, "\n /* %s */\n\n", a->name_); } static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) diff --git a/src/grib_dumper_class_json.cc b/src/grib_dumper_class_json.cc index dd0210521..c7cdbbe80 100644 --- a/src/grib_dumper_class_json.cc +++ b/src/grib_dumper_class_json.cc @@ -125,7 +125,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) double missing_value = GRIB_MISSING_DOUBLE; grib_handle* h = NULL; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; h = grib_handle_of_accessor(a); @@ -133,7 +133,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) size = size2 = count; if (size > 1) { - values = (double*)grib_context_malloc_clear(a->context, sizeof(double) * size); + values = (double*)grib_context_malloc_clear(a->context_, sizeof(double) * size); err = a->unpack_double(values, &size2); } else { @@ -153,7 +153,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) fprintf(self->dumper.out, "\n%-*s{\n", depth, " "); depth += 2; fprintf(self->dumper.out, "%-*s", depth, " "); - fprintf(self->dumper.out, "\"key\" : \"%s\",\n", a->name); + fprintf(self->dumper.out, "\"key\" : \"%s\",\n", a->name_); } err = grib_set_double(h, "missingValue", missing_value); @@ -185,8 +185,8 @@ static void dump_values(grib_dumper* d, grib_accessor* a) depth -= 2; fprintf(self->dumper.out, "\n%-*s]", depth, " "); - /* if (a->attributes[0]) fprintf(self->dumper.out,","); */ - grib_context_free(a->context, values); + /* if (a->attributes_[0]) fprintf(self->dumper.out,","); */ + grib_context_free(a->context_, values); } else { if (self->isLeaf == 0) { @@ -219,14 +219,14 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int cols = 9; long count = 0; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; a->value_count(&count); size = size2 = count; if (size > 1) { - values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + values = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * size); err = a->unpack_long(values, &size2); } else { @@ -245,7 +245,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, "\n%-*s{\n", depth, " "); depth += 2; fprintf(self->dumper.out, "%-*s", depth, " "); - fprintf(self->dumper.out, "\"key\" : \"%s\",\n", a->name); + fprintf(self->dumper.out, "\"key\" : \"%s\",\n", a->name_); } if (size > 1) { @@ -258,7 +258,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, "%-*s[", depth, " "); /* See ECC-637: unfortunately json_xs says: * malformed number (leading zero must not be followed by another digit - if (strcmp(a->name, "unexpandedDescriptors")==0) + if (strcmp(a->name_, "unexpandedDescriptors")==0) doing_unexpandedDescriptors = 1; */ depth += 2; @@ -291,8 +291,8 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) depth -= 2; fprintf(self->dumper.out, "\n%-*s]", depth, " "); - /* if (a->attributes[0]) fprintf(self->dumper.out,","); */ - grib_context_free(a->context, values); + /* if (a->attributes_[0]) fprintf(self->dumper.out,","); */ + grib_context_free(a->context_, values); } else { if (self->isLeaf == 0) { @@ -303,7 +303,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, "null"); else fprintf(self->dumper.out, "%ld", value); - /* if (a->attributes[0]) fprintf(self->dumper.out,","); */ + /* if (a->attributes_[0]) fprintf(self->dumper.out,","); */ } if (self->isLeaf == 0) { @@ -324,7 +324,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) double value = 0; size_t size = 1; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; a->unpack_double(&value, &size); @@ -340,7 +340,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, "%-*s{\n", depth, " "); depth += 2; fprintf(self->dumper.out, "%-*s", depth, " "); - fprintf(self->dumper.out, "\"key\" : \"%s\",\n", a->name); + fprintf(self->dumper.out, "\"key\" : \"%s\",\n", a->name_); fprintf(self->dumper.out, "%-*s", depth, " "); fprintf(self->dumper.out, "\"value\" : "); @@ -351,7 +351,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) else fprintf(self->dumper.out, "%g", value); - /* if (a->attributes[0]) fprintf(self->dumper.out,","); */ + /* if (a->attributes_[0]) fprintf(self->dumper.out,","); */ if (self->isLeaf == 0) { dump_attributes(d, a); @@ -369,9 +369,9 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm int err = 0; int is_missing = 0; long count = 0; - c = a->context; + c = a->context_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; a->value_count(&count); @@ -390,7 +390,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm fprintf(self->dumper.out, "\n%-*s{\n", depth, " "); depth += 2; fprintf(self->dumper.out, "%-*s", depth, " "); - fprintf(self->dumper.out, "\"key\" : \"%s\",\n", a->name); + fprintf(self->dumper.out, "\"key\" : \"%s\",\n", a->name_); } self->empty = 0; @@ -421,7 +421,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm depth -= 2; fprintf(self->dumper.out, "\n%-*s]", depth, " "); - /* if (a->attributes[0]) fprintf(self->dumper.out,","); */ + /* if (a->attributes_[0]) fprintf(self->dumper.out,","); */ if (self->isLeaf == 0) { dump_attributes(d, a); @@ -445,9 +445,9 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) char* p = NULL; int is_missing = 0; int err = 0; - const char* acc_name = a->name; + const char* acc_name = a->name_; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) { return; } @@ -456,9 +456,9 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) * Specially for BUFR elements */ /* err = grib_get_string_length_acc(a,&size); * if (size==0) return; - * value=(char*)grib_context_malloc_clear(a->context,size); + * value=(char*)grib_context_malloc_clear(a->context_,size); * if (!value) { - * grib_context_log(a->context,GRIB_LOG_ERROR,"Unable to allocate %zu bytes",size); + * grib_context_log(a->context_,GRIB_LOG_ERROR,"Unable to allocate %zu bytes",size); * return; * } */ @@ -473,7 +473,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) err = a->unpack_string(value, &size); if (err) { snprintf(value, sizeof(value), " *** ERR=%d (%s) [dump_string on '%s']", - err, grib_get_error_message(err), a->name); + err, grib_get_error_message(err), a->name_); } else { Assert(size < MAX_STRING_SIZE); } @@ -503,7 +503,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) else fprintf(self->dumper.out, "\"%s\"", value); - /* if (a->attributes[0]) fprintf(self->dumper.out,","); */ + /* if (a->attributes_[0]) fprintf(self->dumper.out,","); */ if (self->isLeaf == 0) { dump_attributes(d, a); @@ -511,7 +511,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, "\n%-*s}", depth, " "); } - /* grib_context_free(a->context,value); */ + /* grib_context_free(a->context_,value); */ (void)err; /* TODO */ } @@ -526,9 +526,9 @@ static void dump_label(grib_dumper* d, grib_accessor* a, const char* comment) static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_json* self = (grib_dumper_json*)d; - if (strcmp(a->name, "BUFR")==0 || - strcmp(a->name, "GRIB")==0 || - strcmp(a->name, "META")==0) { + if (strcmp(a->name_, "BUFR")==0 || + strcmp(a->name_, "GRIB")==0 || + strcmp(a->name_, "META")==0) { depth = 2; fprintf(self->dumper.out, "%-*s", depth, " "); fprintf(self->dumper.out, "[\n"); @@ -539,8 +539,8 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso depth -= 2; fprintf(self->dumper.out, "\n]\n"); } - else if (strcmp(a->name, "groupNumber")==0) { - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + else if (strcmp(a->name_, "groupNumber")==0) { + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; if (!self->empty) fprintf(self->dumper.out, ",\n"); @@ -570,30 +570,30 @@ static void dump_attributes(grib_dumper* d, grib_accessor* a) grib_dumper_json* self = (grib_dumper_json*)d; FILE* out = self->dumper.out; unsigned long flags; - while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { + while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes_[i]) { self->isAttribute = 1; - if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes[i]->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { + if ((d->option_flags & GRIB_DUMP_FLAG_ALL_ATTRIBUTES) == 0 && (a->attributes_[i]->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) { i++; continue; } - self->isLeaf = a->attributes[i]->attributes[0] == NULL ? 1 : 0; + self->isLeaf = a->attributes_[i]->attributes_[0] == NULL ? 1 : 0; fprintf(self->dumper.out, ","); fprintf(self->dumper.out, "\n%-*s", depth, " "); - fprintf(out, "\"%s\" : ", a->attributes[i]->name); - flags = a->attributes[i]->flags; - a->attributes[i]->flags |= GRIB_ACCESSOR_FLAG_DUMP; - switch (a->attributes[i]->get_native_type()) { + fprintf(out, "\"%s\" : ", a->attributes_[i]->name_); + flags = a->attributes_[i]->flags_; + a->attributes_[i]->flags_ |= GRIB_ACCESSOR_FLAG_DUMP; + switch (a->attributes_[i]->get_native_type()) { case GRIB_TYPE_LONG: - dump_long(d, a->attributes[i], 0); + dump_long(d, a->attributes_[i], 0); break; case GRIB_TYPE_DOUBLE: - dump_values(d, a->attributes[i]); + dump_values(d, a->attributes_[i]); break; case GRIB_TYPE_STRING: - dump_string_array(d, a->attributes[i], 0); + dump_string_array(d, a->attributes_[i], 0); break; } - a->attributes[i]->flags = flags; + a->attributes_[i]->flags_ = flags; i++; } self->isLeaf = 0; diff --git a/src/grib_dumper_class_serialize.cc b/src/grib_dumper_class_serialize.cc index 57f10cee0..11844997e 100644 --- a/src/grib_dumper_class_serialize.cc +++ b/src/grib_dumper_class_serialize.cc @@ -7,10 +7,6 @@ * 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. */ -/************************************** - * Enrico Fucile - **************************************/ - #include "grib_api_internal.h" #include @@ -104,21 +100,21 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) size_t size = 1; int err = a->unpack_long(&value, &size); - if ((a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) return; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0 && - (strcmp(a->cclass->name, "lookup") != 0)) + (strcmp(a->class_name_, "lookup") != 0)) return; - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && (value == GRIB_MISSING_LONG)) - fprintf(self->dumper.out, "%s = MISSING", a->name); + if (((a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && (value == GRIB_MISSING_LONG)) + fprintf(self->dumper.out, "%s = MISSING", a->name_); else - fprintf(self->dumper.out, "%s = %ld", a->name, value); + fprintf(self->dumper.out, "%s = %ld", a->name_, value); - if (((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) && - (strcmp(a->cclass->name, "lookup") != 0)) + if (((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) && + (strcmp(a->class_name_, "lookup") != 0)) fprintf(self->dumper.out, " (read_only)"); //if(comment) fprintf(self->dumper.out," [%s]",comment); @@ -138,18 +134,18 @@ static void dump_bits(grib_dumper* d, grib_accessor* a, const char* comment) size_t size = 1; int err = a->unpack_long(&value, &size); - if ((a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) return; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0) return; - fprintf(self->dumper.out, "%s = %ld ", a->name, value); + fprintf(self->dumper.out, "%s = %ld ", a->name_, value); // fprintf(self->dumper.out,"["); - // for(i=0;i<(a->length*8);i++) { - // if(test_bit(value,a->length*8-i-1)) + // for(i=0;i<(a->length_*8);i++) { + // if(test_bit(value,a->length_*8-i-1)) // fprintf(self->dumper.out,"1"); // else // fprintf(self->dumper.out,"0"); @@ -173,19 +169,19 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) size_t size = 1; int err = a->unpack_double(&value, &size); - if ((a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) return; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0) return; - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && (value == GRIB_MISSING_DOUBLE)) - fprintf(self->dumper.out, "%s = MISSING", a->name); + if (((a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && (value == GRIB_MISSING_DOUBLE)) + fprintf(self->dumper.out, "%s = MISSING", a->name_); else - fprintf(self->dumper.out, "%s = %g", a->name, value); + fprintf(self->dumper.out, "%s = %g", a->name_, value); - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) fprintf(self->dumper.out, " (read_only)"); //if (comment) fprintf(self->dumper.out," [%s]",comment); @@ -205,10 +201,10 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) char* p = value; - if ((a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) return; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0) return; @@ -221,8 +217,8 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "%s = %s", a->name, value); - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) + fprintf(self->dumper.out, "%s = %s", a->name_, value); + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) fprintf(self->dumper.out, " (read_only)"); // if(comment) fprintf(self->dumper.out," [%s]",comment); @@ -237,19 +233,19 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) grib_dumper_serialize* self = (grib_dumper_serialize*)d; int i, k, err = 0; size_t more = 0; - size_t size = a->length; + size_t size = a->length_; unsigned char* buf = (unsigned char*)grib_context_malloc(d->context, size); - if ((a->flags & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_HIDDEN) != 0) return; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0) return; for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "%s = (%ld) {", a->name, a->length); + fprintf(self->dumper.out, "%s = (%ld) {", a->name_, a->length_); if (!buf) { if (size == 0) @@ -295,7 +291,7 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "} # %s %s \n", a->creator->op, a->name); + fprintf(self->dumper.out, "} # %s %s \n", a->creator_->op, a->name_); grib_context_free(d->context, buf); } @@ -316,7 +312,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) long count = 0; values_format = default_format; - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY)) return; a->value_count(&count); @@ -364,7 +360,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) buf = (double*)grib_context_malloc(d->context, size * sizeof(double)); - fprintf(self->dumper.out, "%s (%zu) {", a->name, size); + fprintf(self->dumper.out, "%s (%zu) {", a->name_, size); if (!buf) { if (size == 0) @@ -403,7 +399,7 @@ static void dump_label(grib_dumper* d, grib_accessor* a, const char* comment) // grib_dumper_serialize *self = (grib_dumper_serialize*)d; // int i; // for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); - // fprintf(self->dumper.out,"----> %s %s %s\n",a->creator->op, a->name,comment?comment:""); + // fprintf(self->dumper.out,"----> %s %s %s\n",a->creator_->op, a->name_,comment?comment:""); } static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) @@ -413,15 +409,15 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso size_t len = strlen(secstr); - if (a->name[0] == '_') { + if (a->name_[0] == '_') { grib_dump_accessors_block(d, block); return; } - if (strncmp(secstr, a->name, len) == 0) - fprintf(self->dumper.out, "#------ %s -------\n", a->name); + if (strncmp(secstr, a->name_, len) == 0) + fprintf(self->dumper.out, "#------ %s -------\n", a->name_); grib_dump_accessors_block(d, block); - //fprintf(self->dumper.out,"<------ %s %s\n",a->creator->op, a->name); + //fprintf(self->dumper.out,"<------ %s %s\n",a->creator_->op, a->name_); } diff --git a/src/grib_dumper_class_wmo.cc b/src/grib_dumper_class_wmo.cc index 3949e97a2..6c7803da1 100644 --- a/src/grib_dumper_class_wmo.cc +++ b/src/grib_dumper_class_wmo.cc @@ -122,16 +122,16 @@ static void aliases(grib_dumper* d, grib_accessor* a) if ((d->option_flags & GRIB_DUMP_FLAG_ALIASES) == 0) return; - if (a->all_names[1]) { + if (a->all_names_[1]) { const char* sep = ""; fprintf(self->dumper.out, " ["); for (i = 1; i < MAX_ACCESSOR_NAMES; i++) { - if (a->all_names[i]) { - if (a->all_name_spaces[i]) - fprintf(self->dumper.out, "%s%s.%s", sep, a->all_name_spaces[i], a->all_names[i]); + if (a->all_names_[i]) { + if (a->all_name_spaces_[i]) + fprintf(self->dumper.out, "%s%s.%s", sep, a->all_name_spaces_[i], a->all_names_[i]); else - fprintf(self->dumper.out, "%s%s", sep, a->all_names[i]); + fprintf(self->dumper.out, "%s%s", sep, a->all_names_[i]); } sep = ", "; } @@ -148,7 +148,7 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) int err = 0, i = 0; long count = 0; - if (a->length == 0 && + if (a->length_ == 0 && (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) return; @@ -156,14 +156,14 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) size = count; if (size > 1) { - values = (long*)grib_context_malloc_clear(a->context, sizeof(long) * size); + values = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * size); err = a->unpack_long(values, &size); } else { err = a->unpack_long(&value, &size); } - if ((a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && + if ((a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0 && (d->option_flags & GRIB_DUMP_FLAG_READ_ONLY) == 0) return; @@ -172,12 +172,12 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) print_offset(self->dumper.out, self->begin, self->theEnd); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) - fprintf(self->dumper.out, "%s (int) ", a->creator->op); + fprintf(self->dumper.out, "%s (int) ", a->creator_->op); if (size > 1) { int cols = 19; int icount = 0; - fprintf(self->dumper.out, "%s = { \t", a->name); + fprintf(self->dumper.out, "%s = { \t", a->name_); if (values) { for (i = 0; i < size; i++) { if (icount > cols) { @@ -188,14 +188,14 @@ static void dump_long(grib_dumper* d, grib_accessor* a, const char* comment) icount++; } fprintf(self->dumper.out, "}\n"); - grib_context_free(a->context, values); + grib_context_free(a->context_, values); } } else { - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) - fprintf(self->dumper.out, "%s = MISSING", a->name); + if (((a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) + fprintf(self->dumper.out, "%s = MISSING", a->name_); else - fprintf(self->dumper.out, "%s = %ld", a->name, value); + fprintf(self->dumper.out, "%s = %ld", a->name_, value); print_hexadecimal(self->dumper.out, d->option_flags, a); @@ -224,7 +224,7 @@ static void dump_bits(grib_dumper* d, grib_accessor* a, const char* comment) size_t size = 1; int err = 0; - if (a->length == 0 && + if (a->length_ == 0 && (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) return; @@ -234,11 +234,11 @@ static void dump_bits(grib_dumper* d, grib_accessor* a, const char* comment) //for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); print_offset(self->dumper.out, self->begin, self->theEnd); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) - fprintf(self->dumper.out, "%s (int) ", a->creator->op); + fprintf(self->dumper.out, "%s (int) ", a->creator_->op); - fprintf(self->dumper.out, "%s = %ld [", a->name, value); - for (i = 0; i < (a->length * 8); i++) { - if (test_bit(value, a->length * 8 - i - 1)) + fprintf(self->dumper.out, "%s = %ld [", a->name_, value); + for (i = 0; i < (a->length_ * 8); i++) { + if (test_bit(value, a->length_ * 8 - i - 1)) fprintf(self->dumper.out, "1"); else fprintf(self->dumper.out, "0"); @@ -270,7 +270,7 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) size_t size = 1; int err = 0; - if (a->length == 0 && + if (a->length_ == 0 && (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) return; @@ -281,12 +281,12 @@ static void dump_double(grib_dumper* d, grib_accessor* a, const char* comment) print_offset(self->dumper.out, self->begin, self->theEnd); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) - fprintf(self->dumper.out, "%s (double) ", a->creator->op); + fprintf(self->dumper.out, "%s (double) ", a->creator_->op); - if (((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) - fprintf(self->dumper.out, "%s = MISSING", a->name); + if (((a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) != 0) && a->is_missing_internal()) + fprintf(self->dumper.out, "%s = MISSING", a->name_); else - fprintf(self->dumper.out, "%s = %g", a->name, value); + fprintf(self->dumper.out, "%s = %g", a->name_, value); // if(comment) fprintf(self->dumper.out," [%s]",comment); if (err == 0) @@ -306,15 +306,15 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) char* p = NULL; int err = 0; - if (a->length == 0 && + if (a->length_ == 0 && (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) { return; } grib_get_string_length_acc(a, &size); - value = (char*)grib_context_malloc_clear(a->context, size); + value = (char*)grib_context_malloc_clear(a->context_, size); if (!value) { - grib_context_log(a->context, GRIB_LOG_ERROR, "unable to allocate %zu bytes", size); + grib_context_log(a->context_, GRIB_LOG_ERROR, "unable to allocate %zu bytes", size); return; } err = a->unpack_string(value, &size); @@ -331,9 +331,9 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) //for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); print_offset(self->dumper.out, self->begin, self->theEnd); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) - fprintf(self->dumper.out, "%s (str) ", a->creator->op); + fprintf(self->dumper.out, "%s (str) ", a->creator_->op); - fprintf(self->dumper.out, "%s = %s", a->name, value); + fprintf(self->dumper.out, "%s = %s", a->name_, value); if (err == 0) print_hexadecimal(self->dumper.out, d->option_flags, a); @@ -343,7 +343,7 @@ static void dump_string(grib_dumper* d, grib_accessor* a, const char* comment) fprintf(self->dumper.out, " *** ERR=%d (%s) [grib_dumper_wmo::dump_string]", err, grib_get_error_message(err)); aliases(d, a); fprintf(self->dumper.out, "\n"); - grib_context_free(a->context, value); + grib_context_free(a->context_, value); } static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) @@ -351,10 +351,10 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) grib_dumper_wmo* self = (grib_dumper_wmo*)d; int i, k, err = 0; size_t more = 0; - size_t size = a->length; + size_t size = a->length_; unsigned char* buf = (unsigned char*)grib_context_malloc(d->context, size); - if (a->length == 0 && + if (a->length_ == 0 && (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) return; @@ -363,9 +363,9 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) // for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); print_offset(self->dumper.out, self->begin, self->theEnd); if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) - fprintf(self->dumper.out, "%s ", a->creator->op); + fprintf(self->dumper.out, "%s ", a->creator_->op); - fprintf(self->dumper.out, "%s = %ld", a->name, a->length); + fprintf(self->dumper.out, "%s = %ld", a->name_, a->length_); aliases(d, a); fprintf(self->dumper.out, " {"); @@ -415,7 +415,7 @@ static void dump_bytes(grib_dumper* d, grib_accessor* a, const char* comment) for (i = 0; i < d->depth; i++) fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "} # %s %s \n", a->creator->op, a->name); + fprintf(self->dumper.out, "} # %s %s \n", a->creator_->op, a->name_); grib_context_free(d->context, buf); } @@ -429,7 +429,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) long count = 0; int is_char = 0; - if (a->length == 0 && + if (a->length_ == 0 && (d->option_flags & GRIB_DUMP_FLAG_CODED) != 0) return; @@ -445,7 +445,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) set_begin_end(d, a); // For the DIAG pseudo GRIBs. Key charValues uses 1-byte integers to represent a character - if (a->flags & GRIB_ACCESSOR_FLAG_STRING_TYPE) { + if (a->flags_ & GRIB_ACCESSOR_FLAG_STRING_TYPE) { is_char = 1; } @@ -459,10 +459,10 @@ static void dump_values(grib_dumper* d, grib_accessor* a) strcpy(type_name, "(double)"); else if (native_type == GRIB_TYPE_STRING) strcpy(type_name, "(str)"); - fprintf(self->dumper.out, "%s %s ", a->creator->op, type_name); + fprintf(self->dumper.out, "%s %s ", a->creator_->op, type_name); } - fprintf(self->dumper.out, "%s = (%ld,%ld)", a->name, (long)size, a->length); + fprintf(self->dumper.out, "%s = (%ld,%ld)", a->name_, (long)size, a->length_); aliases(d, a); fprintf(self->dumper.out, " {"); @@ -511,7 +511,7 @@ static void dump_values(grib_dumper* d, grib_accessor* a) fprintf(self->dumper.out, "... %lu more values\n", (unsigned long)more); } - fprintf(self->dumper.out, "} # %s %s \n", a->creator->op, a->name); + fprintf(self->dumper.out, "} # %s %s \n", a->creator_->op, a->name_); grib_context_free(d->context, buf); } @@ -519,24 +519,24 @@ static void dump_label(grib_dumper* d, grib_accessor* a, const char* comment) { // grib_dumper_wmo *self = (grib_dumper_wmo*)d; // for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); -// fprintf(self->dumper.out,"----> %s %s %s\n",a->creator->op, a->name,comment?comment:""); +// fprintf(self->dumper.out,"----> %s %s %s\n",a->creator_->op, a->name_,comment?comment:""); } static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accessors* block) { grib_dumper_wmo* self = (grib_dumper_wmo*)d; - grib_section* s = a->sub_section; + grib_section* s = a->sub_section_; int is_wmo_section = 0; char* upper = NULL; char tmp[512]; char *p = NULL, *q = NULL; - if (!strncmp(a->name, "section", 7)) + if (!strncmp(a->name_, "section", 7)) is_wmo_section = 1; if (is_wmo_section) { - upper = (char*)malloc(strlen(a->name) + 1); + upper = (char*)malloc(strlen(a->name_) + 1); Assert(upper); - p = (char*)a->name; + p = (char*)a->name_; q = upper; while (*p != '\0') { *q = toupper(*p); @@ -547,7 +547,7 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso snprintf(tmp, sizeof(tmp), "%s ( length=%ld, padding=%ld )", upper, (long)s->length, (long)s->padding); fprintf(self->dumper.out, "====================== %-35s ======================\n", tmp); free(upper); - self->section_offset = a->offset; + self->section_offset = a->offset_; } else { } @@ -558,18 +558,18 @@ static void dump_section(grib_dumper* d, grib_accessor* a, grib_block_of_accesso d->depth -= 3; //for(i = 0; i < d->depth ; i++) fprintf(self->dumper.out," "); - //fprintf(self->dumper.out,"<===== %s %s\n",a->creator->op, a->name); + //fprintf(self->dumper.out,"<===== %s %s\n",a->creator_->op, a->name_); } static void set_begin_end(grib_dumper* d, grib_accessor* a) { grib_dumper_wmo* self = (grib_dumper_wmo*)d; if ((d->option_flags & GRIB_DUMP_FLAG_OCTET) != 0) { - self->begin = a->offset - self->section_offset + 1; + self->begin = a->offset_ - self->section_offset + 1; self->theEnd = a->get_next_position_offset() - self->section_offset; } else { - self->begin = a->offset; + self->begin = a->offset_; self->theEnd = a->get_next_position_offset(); } } @@ -579,10 +579,10 @@ static void print_hexadecimal(FILE* out, unsigned long flags, grib_accessor* a) int i = 0; unsigned long offset = 0; grib_handle* h = grib_handle_of_accessor(a); - if ((flags & GRIB_DUMP_FLAG_HEXADECIMAL) != 0 && a->length != 0) { + if ((flags & GRIB_DUMP_FLAG_HEXADECIMAL) != 0 && a->length_ != 0) { fprintf(out, " ("); - offset = a->offset; - for (i = 0; i < a->length; i++) { + offset = a->offset_; + for (i = 0; i < a->length_; i++) { fprintf(out, " 0x%.2X", h->buffer->data[offset]); offset++; } @@ -600,10 +600,10 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm int tab = 0; long count = 0; - if ((a->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if ((a->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) return; - c = a->context; + c = a->context_; a->value_count(&count); if (count == 0) return; @@ -626,7 +626,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm if ((d->option_flags & GRIB_DUMP_FLAG_TYPE) != 0) { fprintf(self->dumper.out, " "); - fprintf(self->dumper.out, "# type %s (str) \n", a->creator->op); + fprintf(self->dumper.out, "# type %s (str) \n", a->creator_->op); } aliases(d, a); @@ -634,7 +634,7 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm fprintf(self->dumper.out, " "); fprintf(self->dumper.out, "# %s \n", comment); } - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) { + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) { fprintf(self->dumper.out, " "); fprintf(self->dumper.out, "#-READ ONLY- "); tab = 13; @@ -643,9 +643,9 @@ static void dump_string_array(grib_dumper* d, grib_accessor* a, const char* comm fprintf(self->dumper.out, " "); tab++; - fprintf(self->dumper.out, "%s = {\n", a->name); + fprintf(self->dumper.out, "%s = {\n", a->name_); for (i = 0; i < size; i++) { - fprintf(self->dumper.out, "%-*s\"%s\",\n", (int)(tab + strlen(a->name) + 4), " ", values[i]); + fprintf(self->dumper.out, "%-*s\"%s\",\n", (int)(tab + strlen(a->name_) + 4), " ", values[i]); } fprintf(self->dumper.out, " }"); diff --git a/src/grib_expression_class_functor.cc b/src/grib_expression_class_functor.cc index 332d219ce..0f1d80214 100644 --- a/src/grib_expression_class_functor.cc +++ b/src/grib_expression_class_functor.cc @@ -98,9 +98,9 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) { grib_expression_functor* e = (grib_expression_functor*)g; - if (STR_EQUAL(e->name, "lookup")) { - return GRIB_SUCCESS; - } + // if (STR_EQUAL(e->name, "lookup")) { + // return GRIB_SUCCESS; + // } if (STR_EQUAL(e->name, "new")) { *lres = h->loader != NULL; @@ -128,6 +128,14 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres) return GRIB_INVALID_ARGUMENT; } + if (STR_EQUAL(e->name, "debug_mode")) { + const int n = grib_arguments_get_count(e->args); + if (n != 1) return GRIB_INVALID_ARGUMENT; + const int dmode = grib_arguments_get_long(h, e->args, 0); + grib_context_set_debug(0, dmode); + return GRIB_SUCCESS; + } + if (STR_EQUAL(e->name, "missing")) { const char* keyName = grib_arguments_get_name(h, e->args, 0); if (keyName) { diff --git a/src/grib_handle.cc b/src/grib_handle.cc index a1801650a..830b97723 100644 --- a/src/grib_handle.cc +++ b/src/grib_handle.cc @@ -51,9 +51,9 @@ static void update_sections(grib_section* s, grib_handle* h, long offset) if (s) s->h = h; while (a) { - a->offset += offset; + a->offset_ += offset; /* update_sections ( grib_get_sub_section ( a ),h,offset ); */ - update_sections(a->sub_section, h, offset); + update_sections(a->sub_section_, h, offset); a = a->next_; } } @@ -73,11 +73,11 @@ void grib_swap_sections(grib_section* the_old, grib_section* the_new) a = the_old->block->first; while (a) { - a->parent = the_old; + a->parent_ = the_old; a = a->next_; } - update_sections(the_old, the_old->h, the_old->owner->offset); + update_sections(the_old, the_old->h, the_old->owner->offset_); /* update_sections(new,new->h,new->owner->offset); */ /* printf("SWAPPING -----\n"); grib_dump_section_content(old,stdout); */ @@ -95,9 +95,9 @@ void grib_empty_section(grib_context* c, grib_section* b) while (current) { grib_accessor* next = current->next_; - if (current->sub_section) { - grib_section_delete(c, current->sub_section); - current->sub_section = 0; + if (current->sub_section_) { + grib_section_delete(c, current->sub_section_); + current->sub_section_ = 0; } current->destroy(c); current = next; diff --git a/src/grib_iterator_class_gaussian.cc b/src/grib_iterator_class_gaussian.cc index 20807be96..714aa4d35 100644 --- a/src/grib_iterator_class_gaussian.cc +++ b/src/grib_iterator_class_gaussian.cc @@ -7,9 +7,6 @@ * 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. */ -/************************************** - * Enrico Fucile - **************************************/ #include "grib_api_internal.h" #include diff --git a/src/grib_iterator_class_latlon_reduced.cc b/src/grib_iterator_class_latlon_reduced.cc index c27dcb2d1..53252dd88 100644 --- a/src/grib_iterator_class_latlon_reduced.cc +++ b/src/grib_iterator_class_latlon_reduced.cc @@ -8,11 +8,6 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/************************************** - * Enrico Fucile - **************************************/ - - #include "grib_api_internal.h" #include diff --git a/src/grib_keys_iterator.cc b/src/grib_keys_iterator.cc index 06c112c04..103f98591 100644 --- a/src/grib_keys_iterator.cc +++ b/src/grib_keys_iterator.cc @@ -110,31 +110,31 @@ static int skip(grib_keys_iterator* kiter) { /* TODO: set the section to hidden, to speed up that */ /* if(grib_get_sub_section(kiter->current)) */ - if (kiter->current->sub_section) + if (kiter->current->sub_section_) return 1; - if (kiter->current->flags & GRIB_ACCESSOR_FLAG_HIDDEN) + if (kiter->current->flags_ & GRIB_ACCESSOR_FLAG_HIDDEN) return 1; - if (kiter->current->flags & kiter->accessor_flags_skip) + if (kiter->current->flags_ & kiter->accessor_flags_skip) return 1; - if ((kiter->filter_flags & GRIB_KEYS_ITERATOR_SKIP_COMPUTED) && kiter->current->length == 0) + if ((kiter->filter_flags & GRIB_KEYS_ITERATOR_SKIP_COMPUTED) && kiter->current->length_ == 0) return 1; - if ((kiter->filter_flags & GRIB_KEYS_ITERATOR_SKIP_CODED) && kiter->current->length != 0) + if ((kiter->filter_flags & GRIB_KEYS_ITERATOR_SKIP_CODED) && kiter->current->length_ != 0) return 1; if (kiter->name_space) { kiter->match = 0; while (kiter->match < MAX_ACCESSOR_NAMES) { - if (kiter->current->all_name_spaces[kiter->match] != NULL) { - if (grib_inline_strcmp(kiter->current->all_name_spaces[kiter->match], kiter->name_space) == 0) { + if (kiter->current->all_name_spaces_[kiter->match] != NULL) { + if (grib_inline_strcmp(kiter->current->all_name_spaces_[kiter->match], kiter->name_space) == 0) { if (kiter->seen) { - if (was_seen(kiter, kiter->current->all_names[kiter->match])) + if (was_seen(kiter, kiter->current->all_names_[kiter->match])) return 1; - mark_seen(kiter, kiter->current->all_names[kiter->match]); + mark_seen(kiter, kiter->current->all_names_[kiter->match]); } return 0; } @@ -146,13 +146,13 @@ static int skip(grib_keys_iterator* kiter) } if (kiter->seen) { - if (was_seen(kiter, kiter->current->name)) + if (was_seen(kiter, kiter->current->name_)) return 1; - mark_seen(kiter, kiter->current->name); + mark_seen(kiter, kiter->current->name_); } /* ECC-1410 */ - if (kiter->current->all_names[0] == NULL) + if (kiter->current->all_names_[0] == NULL) return 1; return 0; @@ -178,7 +178,7 @@ const char* grib_keys_iterator_get_name(const grib_keys_iterator* kiter) { /* if(kiter->name_space) */ Assert(kiter->current); - return kiter->current->all_names[kiter->match]; + return kiter->current->all_names_[kiter->match]; } grib_accessor* grib_keys_iterator_get_accessor(grib_keys_iterator* kiter) diff --git a/src/grib_loader_from_handle.cc b/src/grib_loader_from_handle.cc index f26c68c21..ea85b0310 100644 --- a/src/grib_loader_from_handle.cc +++ b/src/grib_loader_from_handle.cc @@ -20,9 +20,9 @@ static int copy_values(grib_handle* h, grib_accessor* ga) /* printf("copy_values stack is %ld\n",(long)h->values_stack);*/ for (j = 0; j < h->values_stack; j++) { for (i = 0; i < h->values_count[j]; i++) { - for (k = 0; (k < MAX_ACCESSOR_NAMES) && (ga->all_names[k] != NULL); k++) { + for (k = 0; (k < MAX_ACCESSOR_NAMES) && (ga->all_names_[k] != NULL); k++) { /*printf("copy_values: %s %s\n",h->values[j][i].name,ga->all_names[k]);*/ - if (strcmp(h->values[j][i].name, ga->all_names[k]) == 0) { + if (strcmp(h->values[j][i].name, ga->all_names_[k]) == 0) { size_t len = 1; /*printf("SET VALUES %s\n",h->values[j][i].name);*/ switch (h->values[j][i].type) { @@ -75,21 +75,21 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_ grib_handle* g; grib_accessor* ao = NULL; int e, pack_missing = 0; - grib_context_log(h->context, GRIB_LOG_DEBUG, "XXXXX Copying %s", ga->name); + grib_context_log(h->context, GRIB_LOG_DEBUG, "XXXXX Copying %s", ga->name_); if (default_value) { grib_context_log(h->context, GRIB_LOG_DEBUG, "Copying: setting %s to default value", - ga->name); + ga->name_); ga->pack_expression(grib_arguments_get_expression(h, default_value, 0)); } - if ((ga->flags & GRIB_ACCESSOR_FLAG_NO_COPY) || - ((ga->flags & GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC) && + if ((ga->flags_ & GRIB_ACCESSOR_FLAG_NO_COPY) || + ((ga->flags_ & GRIB_ACCESSOR_FLAG_EDITION_SPECIFIC) && loader->changing_edition) || - (ga->flags & GRIB_ACCESSOR_FLAG_FUNCTION) || - ((ga->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) && - !(ga->flags & GRIB_ACCESSOR_FLAG_COPY_OK))) { - grib_context_log(h->context, GRIB_LOG_DEBUG, "Copying %s ignored", ga->name); + (ga->flags_ & GRIB_ACCESSOR_FLAG_FUNCTION) || + ((ga->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) && + !(ga->flags_ & GRIB_ACCESSOR_FLAG_COPY_OK))) { + grib_context_log(h->context, GRIB_LOG_DEBUG, "Copying %s ignored", ga->name_); return GRIB_SUCCESS; } @@ -111,7 +111,7 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_ g = h; while (g) { if (copy_values(g, ga) == GRIB_SUCCESS) { - grib_context_log(h->context, GRIB_LOG_DEBUG, "Copying: setting %s to multi-set-value", ga->name); + grib_context_log(h->context, GRIB_LOG_DEBUG, "Copying: setting %s to multi-set-value", ga->name_); return GRIB_SUCCESS; } g = g->main; @@ -121,12 +121,12 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_ /* Check if the same name exists in the original message ... */ k = 0; while ((k < MAX_ACCESSOR_NAMES) && - ((name = ga->all_names[k]) != NULL) && + ((name = ga->all_names_[k]) != NULL) && ((ret = grib_get_size(h, name, &len)) != GRIB_SUCCESS)) k++; if (ret != GRIB_SUCCESS) { - name = ga->name; + name = ga->name_; #ifdef MY_DEBUG if (first) { missing = codes_getenv("ECCODES_PRINT_MISSING"); @@ -152,16 +152,16 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_ return GRIB_SUCCESS; } - if ((ga->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) && grib_is_missing(h, name, &e) && e == GRIB_SUCCESS && len == 1) { + if ((ga->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) && grib_is_missing(h, name, &e) && e == GRIB_SUCCESS && len == 1) { ga->pack_missing(); pack_missing = 1; } const long ga_type = ga->get_native_type(); - if ((ga->flags & GRIB_ACCESSOR_FLAG_COPY_IF_CHANGING_EDITION) && !loader->changing_edition) { + if ((ga->flags_ & GRIB_ACCESSOR_FLAG_COPY_IF_CHANGING_EDITION) && !loader->changing_edition) { // See ECC-1560 and ECC-1644 - grib_context_log(h->context, GRIB_LOG_DEBUG, "Skipping %s (only copied if changing edition)", ga->name); + grib_context_log(h->context, GRIB_LOG_DEBUG, "Skipping %s (only copied if changing edition)", ga->name_); return GRIB_SUCCESS; } @@ -184,8 +184,8 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_ ret = grib_get_long_array_internal(h, name, lval, &len); if (ret == GRIB_SUCCESS) { grib_context_log(h->context, GRIB_LOG_DEBUG, "Copying %d long(s) %d to %s", len, lval[0], name); - if (ga->same) { - ret = grib_set_long_array(grib_handle_of_accessor(ga), ga->name, lval, len); + if (ga->same_) { + ret = grib_set_long_array(grib_handle_of_accessor(ga), ga->name_, lval, len); /* Allow for lists to be resized */ if ((ret == GRIB_WRONG_ARRAY_SIZE || ret == GRIB_ARRAY_TOO_SMALL) && loader->list_is_resized) @@ -198,7 +198,7 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_ } else { /* If we have just one key of type long which has one octet, then do not exceed maximum value */ - const long num_octets = ga->length; + const long num_octets = ga->length_; if (len == 1 && num_octets == 1 && *lval > 255) { *lval = 0; /* Reset to a reasonable value */ } @@ -216,8 +216,8 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_ ret = grib_get_double_array(h, name, dval, &len); /* GRIB-898 */ if (ret == GRIB_SUCCESS) { grib_context_log(h->context, GRIB_LOG_DEBUG, "Copying %d double(s) %g to %s", len, dval[0], name); - if (ga->same) { - ret = grib_set_double_array(grib_handle_of_accessor(ga), ga->name, dval, len); + if (ga->same_) { + ret = grib_set_double_array(grib_handle_of_accessor(ga), ga->name_, dval, len); /* Allow for lists to be resized */ if ((ret == GRIB_WRONG_ARRAY_SIZE || ret == GRIB_ARRAY_TOO_SMALL) && loader->list_is_resized) @@ -251,7 +251,7 @@ int grib_init_accessor_from_handle(grib_loader* loader, grib_accessor* ga, grib_ default: grib_context_log(h->context, GRIB_LOG_ERROR, - "Copying %s, cannot establish type %ld [%s]", name, ga->get_native_type(), ga->creator->cclass->name); + "Copying %s, cannot establish type %ld [%s]", name, ga->get_native_type(), ga->creator_->cclass->name); break; } diff --git a/src/grib_parse_utils.cc b/src/grib_parse_utils.cc index ed65572d5..f348516da 100644 --- a/src/grib_parse_utils.cc +++ b/src/grib_parse_utils.cc @@ -10,8 +10,6 @@ /*************************************************************************** * Jean Baptiste Filippi - 01.11.2005 * - * Enrico Fucile - * * ***************************************************************************/ #include "grib_api_internal.h" @@ -412,7 +410,7 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha grib_context_free(h->context, lval); break; case GRIB_TYPE_BYTES: - replen = a->length; + replen = a->length_; bval = (unsigned char*)grib_context_malloc(h->context, replen * sizeof(unsigned char)); ret = al->accessor->unpack_bytes(bval, &replen); for (j = 0; j < replen; j++) { @@ -423,7 +421,7 @@ int grib_accessors_list_print(grib_handle* h, grib_accessors_list* al, const cha break; default: grib_context_log(h->context, GRIB_LOG_WARNING, - "Accessor print: Problem printing \"%s\", invalid type %d", a->name, grib_get_type_name(type)); + "Accessor print: Problem printing \"%s\", invalid type %d", a->name_, grib_get_type_name(type)); } return ret; } diff --git a/src/grib_query.cc b/src/grib_query.cc index a1209efaf..398d24887 100644 --- a/src/grib_query.cc +++ b/src/grib_query.cc @@ -8,11 +8,9 @@ * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. */ -/*************************************************************************** - * Enrico Fucile +/************************************************************************** * Jean Baptiste Filippi - 01.11.2005 * - * * - ***************************************************************************/ + **************************************************************************/ #include "grib_api_internal.h" #include "accessor/grib_accessor_class_bufr_data_array.h" @@ -33,12 +31,12 @@ static int matching(grib_accessor* a, const char* name, const char* name_space) { int i = 0; while (i < MAX_ACCESSOR_NAMES) { - if (a->all_names[i] == 0) + if (a->all_names_[i] == 0) return 0; - if ((grib_inline_strcmp(name, a->all_names[i]) == 0) && - ((name_space == NULL) || (a->all_name_spaces[i] != NULL && - grib_inline_strcmp(a->all_name_spaces[i], name_space) == 0))) + if ((grib_inline_strcmp(name, a->all_names_[i]) == 0) && + ((name_space == NULL) || (a->all_name_spaces_[i] != NULL && + grib_inline_strcmp(a->all_name_spaces_[i], name_space) == 0))) return 1; i++; } @@ -56,7 +54,7 @@ static grib_accessor* search(grib_section* s, const char* name, const char* name return NULL; while (a) { - grib_section* sub = a->sub_section; + grib_section* sub = a->sub_section_; if (matching(a, name, name_space)) match = a; @@ -75,21 +73,21 @@ static void rebuild_hash_keys(grib_handle* h, grib_section* s) grib_accessor* a = s ? s->block->first : NULL; while (a) { - grib_section* sub = a->sub_section; + grib_section* sub = a->sub_section_; int i = 0; int id = -1; const char* p; DEBUG_ASSERT(h == grib_handle_of_accessor(a)); - while (i < MAX_ACCESSOR_NAMES && ((p = a->all_names[i]) != NULL)) { + while (i < MAX_ACCESSOR_NAMES && ((p = a->all_names_[i]) != NULL)) { if (*p != '_') { - id = grib_hash_keys_get_id(a->context->keys, p); + id = grib_hash_keys_get_id(a->context_->keys, p); - if (a->same != a && i == 0) { + if (a->same_ != a && i == 0) { grib_handle* hand = grib_handle_of_accessor(a); - a->same = hand->accessors[id]; + a->same_ = hand->accessors[id]; hand->accessors[id] = a; - DEBUG_ASSERT(a->same != a); + DEBUG_ASSERT(a->same_ != a); } } i++; @@ -225,7 +223,7 @@ static grib_accessor* _search_by_rank(grib_accessor* a,const char* name,long ran grib_accessors_list* al=accessor_bufr_data_array_get_dataAccessors(a); while (al) { - if (!grib_inline_strcmp(al->accessor->name,name)) { + if (!grib_inline_strcmp(al->accessor->name_,name)) { if (r==rank) return al->accessor; r++; } @@ -253,7 +251,7 @@ static grib_accessor* search_by_rank(grib_handle* h, const char* name, int rank, static int get_single_long_val(grib_accessor* a, long* result) { - grib_context* c = a->context; + grib_context* c = a->context_; int err = 0; size_t size = 1; if (c->bufr_multi_element_constant_arrays) { @@ -292,7 +290,7 @@ static int get_single_long_val(grib_accessor* a, long* result) } static int get_single_double_val(grib_accessor* a, double* result) { - grib_context* c = a->context; + grib_context* c = a->context_; int err = 0; size_t size = 1; if (c->bufr_multi_element_constant_arrays) { @@ -369,14 +367,14 @@ static void search_from_accessors_list(grib_accessors_list* al, const grib_acces { char attribute_name[200] = {0,}; grib_accessor* accessor_result = 0; - grib_context* c = al->accessor->context; + grib_context* c = al->accessor->context_; int doFree = 1; char* accessor_name = grib_split_name_attribute(c, name, attribute_name); if (*attribute_name == 0) doFree = 0; while (al && al != end && al->accessor) { - if (grib_inline_strcmp(al->accessor->name, accessor_name) == 0) { + if (grib_inline_strcmp(al->accessor->name_, accessor_name) == 0) { if (attribute_name[0]) { accessor_result = al->accessor->get_attribute(attribute_name); } @@ -390,7 +388,7 @@ static void search_from_accessors_list(grib_accessors_list* al, const grib_acces al = al->next_; } if (al == end && al->accessor) { - if (grib_inline_strcmp(al->accessor->name, accessor_name) == 0) { + if (grib_inline_strcmp(al->accessor->name_, accessor_name) == 0) { if (attribute_name[0]) { accessor_result = al->accessor->get_attribute(attribute_name); } @@ -411,7 +409,7 @@ static void search_accessors_list_by_condition(grib_accessors_list* al, const ch grib_accessors_list* end = NULL; while (al) { - if (!grib_inline_strcmp(al->accessor->name, condition->left)) { + if (!grib_inline_strcmp(al->accessor->name_, condition->left)) { if (start == NULL && condition_true(al->accessor, condition)) start = al; if (start && !condition_true(al->accessor, condition)) @@ -438,7 +436,7 @@ static grib_accessors_list* search_by_condition(grib_handle* h, const char* name al = accessor_bufr_data_array_get_dataAccessors(data); if (!al) return NULL; - result = (grib_accessors_list*)grib_context_malloc_clear(al->accessor->context, sizeof(grib_accessors_list)); + result = (grib_accessors_list*)grib_context_malloc_clear(al->accessor->context_, sizeof(grib_accessors_list)); search_accessors_list_by_condition(al, name, condition, result); if (!result->accessor) { grib_accessors_list_delete(h->context, result); @@ -452,7 +450,7 @@ static grib_accessors_list* search_by_condition(grib_handle* h, const char* name static void grib_find_same_and_push(grib_accessors_list* al, grib_accessor* a) { if (a) { - grib_find_same_and_push(al, a->same); + grib_find_same_and_push(al, a->same_); al->push(a, al->rank()); } } diff --git a/src/grib_value.cc b/src/grib_value.cc index e68ea72e0..4b5b71ec7 100644 --- a/src/grib_value.cc +++ b/src/grib_value.cc @@ -80,7 +80,7 @@ int grib_set_expression(grib_handle* h, const char* name, grib_expression* e) int ret = GRIB_SUCCESS; if (a) { - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) return GRIB_READ_ONLY; ret = a->pack_expression(e); @@ -130,13 +130,13 @@ int grib_set_long(grib_handle* h, const char* name, long val) if (a) { if (h->context->debug) { - if (strcmp(name, a->name)!=0) - fprintf(stderr, "ECCODES DEBUG grib_set_long h=%p %s=%ld (a->name=%s)\n", (void*)h, name, val, a->name); + if (strcmp(name, a->name_)!=0) + fprintf(stderr, "ECCODES DEBUG grib_set_long h=%p %s=%ld (a->name_=%s)\n", (void*)h, name, val, a->name_); else fprintf(stderr, "ECCODES DEBUG grib_set_long h=%p %s=%ld\n", (void*)h, name, val); } - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) return GRIB_READ_ONLY; ret = a->pack_long(&val, &l); @@ -247,7 +247,7 @@ int grib_copy_namespace(grib_handle* dest, const char* name, grib_handle* src) continue; } - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) { + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) { key_err->err = GRIB_SUCCESS; key_err = key_err->next; continue; @@ -362,13 +362,13 @@ int grib_set_double(grib_handle* h, const char* name, double val) if (a) { if (h->context->debug) { - if (strcmp(name, a->name)!=0) - fprintf(stderr, "ECCODES DEBUG grib_set_double h=%p %s=%.10g (a->name=%s)\n", (void*)h, name, val, a->name); + if (strcmp(name, a->name_)!=0) + fprintf(stderr, "ECCODES DEBUG grib_set_double h=%p %s=%.10g (a->name_=%s)\n", (void*)h, name, val, a->name_); else fprintf(stderr, "ECCODES DEBUG grib_set_double h=%p %s=%.10g\n", (void*)h, name, val); } - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) return GRIB_READ_ONLY; ret = a->pack_double(&val, &l); @@ -494,13 +494,13 @@ int grib_set_string(grib_handle* h, const char* name, const char* val, size_t* l if (a) { if (h->context->debug) { - if (strcmp(name, a->name)!=0) - fprintf(stderr, "ECCODES DEBUG grib_set_string h=%p %s=|%s| (a->name=%s)\n", (void*)h, name, val, a->name); + if (strcmp(name, a->name_)!=0) + fprintf(stderr, "ECCODES DEBUG grib_set_string h=%p %s=|%s| (a->name_=%s)\n", (void*)h, name, val, a->name_); else fprintf(stderr, "ECCODES DEBUG grib_set_string h=%p %s=|%s|\n", (void*)h, name, val); } - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) return GRIB_READ_ONLY; ret = a->pack_string(val, length); @@ -530,7 +530,7 @@ int grib_set_string_array(grib_handle* h, const char* name, const char** val, si } if (a) { - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) return GRIB_READ_ONLY; ret = a->pack_string_array(val, &length); @@ -566,7 +566,7 @@ int grib_set_bytes(grib_handle* h, const char* name, const unsigned char* val, s grib_accessor* a = grib_find_accessor(h, name); if (a) { - /* if(a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) */ + /* if(a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) */ /* return GRIB_READ_ONLY; */ ret = a->pack_bytes(val, length); @@ -584,7 +584,7 @@ int grib_set_bytes(grib_handle* h, const char* name, const unsigned char* val, s // grib_accessor* a = NULL; // a = grib_find_accessor(h, name); // if (a) { -// if (a->length == 0) +// if (a->length_ == 0) // return 0; // if ((ret = a->grib_pack_zero()) != GRIB_SUCCESS) // grib_context_log(h->context, GRIB_LOG_ERROR, "Unable to clear %s (%s)", @@ -603,7 +603,7 @@ int grib_set_missing(grib_handle* h, const char* name) a = grib_find_accessor(h, name); if (a) { - if (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) + if (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) return GRIB_READ_ONLY; if (grib_accessor_can_be_missing(a, &ret)) { @@ -628,12 +628,12 @@ int grib_set_missing(grib_handle* h, const char* name) int grib_is_missing_long(grib_accessor* a, long x) { - int ret = (a == NULL || (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING)) && (x == GRIB_MISSING_LONG) ? 1 : 0; + int ret = (a == NULL || (a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING)) && (x == GRIB_MISSING_LONG) ? 1 : 0; return ret; } int grib_is_missing_double(grib_accessor* a, double x) { - int ret = (a == NULL || (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING)) && (x == GRIB_MISSING_DOUBLE) ? 1 : 0; + int ret = (a == NULL || (a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING)) && (x == GRIB_MISSING_DOUBLE) ? 1 : 0; return ret; } @@ -657,7 +657,7 @@ int grib_is_missing_string(grib_accessor* a, const unsigned char* x, size_t len) if (!a) return ret; - ret = ( ((a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) && ret == 1) ) ? 1 : 0; + ret = ( ((a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) && ret == 1) ) ? 1 : 0; return ret; } @@ -665,7 +665,7 @@ int grib_accessor_is_missing(grib_accessor* a, int* err) { *err = GRIB_SUCCESS; if (a) { - if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) + if (a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) return a->is_missing_internal(); else return 0; @@ -678,10 +678,10 @@ int grib_accessor_is_missing(grib_accessor* a, int* err) int grib_accessor_can_be_missing(grib_accessor* a, int* err) { - if (a->flags & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { + if (a->flags_ & GRIB_ACCESSOR_FLAG_CAN_BE_MISSING) { return 1; } - if (STR_EQUAL(a->cclass->name, "codetable")) { + if (STR_EQUAL(a->class_name_, "codetable")) { // Special case of Code Table keys // The vast majority have a 'Missing' entry return 1; @@ -709,7 +709,7 @@ int grib_set_flag(grib_handle* h, const char* name, unsigned long flag) if (!a) return GRIB_NOT_FOUND; - a->flags |= flag; + a->flags_ |= flag; return GRIB_SUCCESS; } @@ -718,9 +718,9 @@ static int _grib_set_double_array_internal(grib_handle* h, grib_accessor* a, const double* val, size_t buffer_len, size_t* encoded_length, int check) { if (a) { - int err = _grib_set_double_array_internal(h, a->same, val, buffer_len, encoded_length, check); + int err = _grib_set_double_array_internal(h, a->same_, val, buffer_len, encoded_length, check); - if (check && (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)) + if (check && (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY)) return GRIB_READ_ONLY; if (err == GRIB_SUCCESS) { @@ -734,7 +734,7 @@ static int _grib_set_double_array_internal(grib_handle* h, grib_accessor* a, } } else { - grib_get_size(h, a->name, encoded_length); + grib_get_size(h, a->name_, encoded_length); err = GRIB_WRONG_ARRAY_SIZE; } } @@ -756,7 +756,7 @@ static int _grib_set_double_array(grib_handle* h, const char* name, if (!a) return GRIB_NOT_FOUND; if (name[0] == '/' || name[0] == '#') { - if (check && (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)) + if (check && (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY)) return GRIB_READ_ONLY; err = a->pack_double(val, &length); encoded = length; @@ -894,9 +894,9 @@ int grib_set_float_array(grib_handle* h, const char* name, const float* val, siz static int _grib_set_long_array_internal(grib_handle* h, grib_accessor* a, const long* val, size_t buffer_len, size_t* encoded_length, int check) { if (a) { - int err = _grib_set_long_array_internal(h, a->same, val, buffer_len, encoded_length, check); + int err = _grib_set_long_array_internal(h, a->same_, val, buffer_len, encoded_length, check); - if (check && (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)) + if (check && (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY)) return GRIB_READ_ONLY; if (err == GRIB_SUCCESS) { @@ -906,7 +906,7 @@ static int _grib_set_long_array_internal(grib_handle* h, grib_accessor* a, const *encoded_length += len; } else { - grib_get_size(h, a->name, encoded_length); + grib_get_size(h, a->name_, encoded_length); err = GRIB_WRONG_ARRAY_SIZE; } } @@ -942,7 +942,7 @@ static int _grib_set_long_array(grib_handle* h, const char* name, const long* va } if (name[0] == '/' || name[0] == '#') { - if (check && (a->flags & GRIB_ACCESSOR_FLAG_READ_ONLY)) + if (check && (a->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY)) return GRIB_READ_ONLY; err = a->pack_long(val, &length); encoded = length; @@ -989,7 +989,7 @@ int grib_get_long_internal(grib_handle* h, const char* name, long* val) // int grib_is_in_dump(const grib_handle* h, const char* name) // { // const grib_accessor* a = grib_find_accessor(h, name); -// if (a != NULL && (a->flags & GRIB_ACCESSOR_FLAG_DUMP)) +// if (a != NULL && (a->flags_ & GRIB_ACCESSOR_FLAG_DUMP)) // return 1; // else // return 0; @@ -999,7 +999,7 @@ int grib_get_long_internal(grib_handle* h, const char* name, long* val) // { // if (a) { // *size = 0; -// while (a->attributes[*size] != NULL) { +// while (a->attributes_[*size] != NULL) { // (*size)++; // } // return GRIB_SUCCESS; @@ -1304,7 +1304,7 @@ static int _grib_get_array_internal(const grib_handle* h, grib_accessor* a, T* v { static_assert(std::is_floating_point::value, "Requires floating point numbers"); if (a) { - int err = _grib_get_array_internal(h, a->same, val, buffer_len, decoded_length); + int err = _grib_get_array_internal(h, a->same_, val, buffer_len, decoded_length); if (err == GRIB_SUCCESS) { size_t len = buffer_len - *decoded_length; @@ -1401,7 +1401,7 @@ int grib_get_string_length_acc(grib_accessor* a, size_t* size) s = a->string_length(); if (s > *size) *size = s; - a = a->same; + a = a->same_; } (*size) += 1; @@ -1446,7 +1446,7 @@ int grib_get_size_acc(const grib_handle* h, grib_accessor* a, size_t* size) return err; *size += count; } - a = a->same; + a = a->same_; } return GRIB_SUCCESS; } @@ -1495,7 +1495,7 @@ int grib_get_length(const grib_handle* h, const char* name, size_t* length) // *size = 0; // while (a) { // (*size)++; -// a = a->same; +// a = a->same_; // } // return GRIB_SUCCESS; // } @@ -1514,7 +1514,7 @@ int grib_get_offset(const grib_handle* ch, const char* key, size_t* val) static int grib_get_string_array_internal_(const grib_handle* h, grib_accessor* a, char** val, size_t buffer_len, size_t* decoded_length) { if (a) { - int err = grib_get_string_array_internal_(h, a->same, val, buffer_len, decoded_length); + int err = grib_get_string_array_internal_(h, a->same_, val, buffer_len, decoded_length); if (err == GRIB_SUCCESS) { size_t len = buffer_len - *decoded_length; @@ -1561,7 +1561,7 @@ int grib_get_string_array(const grib_handle* h, const char* name, char** val, si static int _grib_get_long_array_internal(const grib_handle* h, grib_accessor* a, long* val, size_t buffer_len, size_t* decoded_length) { if (a) { - int err = _grib_get_long_array_internal(h, a->same, val, buffer_len, decoded_length); + int err = _grib_get_long_array_internal(h, a->same_, val, buffer_len, decoded_length); if (err == GRIB_SUCCESS) { size_t len = buffer_len - *decoded_length; diff --git a/src/make_accessor_class_hash.sh b/src/make_accessor_class_hash.sh index 72955ae4a..a211fb321 100755 --- a/src/make_accessor_class_hash.sh +++ b/src/make_accessor_class_hash.sh @@ -6,7 +6,7 @@ cat > accessor_class_list.gperf <> accessor_class_list.gp gperf --version echo -gperf -C -W classes -t -G -H grib_accessor_classes_get_id -N grib_accessor_classes_hash -m 1 -j 1 accessor_class_list.gperf |\ +gperf -C -W classes -t -G -H grib_accessor_classes_get_id -N grib_accessor_hash -m 1 -j 1 accessor_class_list.gperf |\ sed s/__inline//g | sed s/inline//g | sed 's/register //g' > grib_accessor_classes_hash.cc rm -f accessor_class_list.gperf diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b6194fc61..dfb3799b5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -30,7 +30,6 @@ list(APPEND test_c_bins grib_keys_iter grib_keys_iter_skip grib_geo_iter - gauss_sub grib_nearest_test grib_util_set_spec grib_util_set_spec2 @@ -61,7 +60,6 @@ list(APPEND test_c_bins codes_codetable codes_get_string grib_sh_ieee64 - grib_ieee grib_set_bytes grib_copy_message grib_packing_order diff --git a/tests/bufr_check_descriptors.sh b/tests/bufr_check_descriptors.sh index 091d6f373..6fad71125 100755 --- a/tests/bufr_check_descriptors.sh +++ b/tests/bufr_check_descriptors.sh @@ -10,7 +10,80 @@ . ./include.ctest.sh +label="bufr_check_descriptors_test" +tempInput=temp.$label.table +tempText=temp.$label.txt + for file in `find ${ECCODES_DEFINITION_PATH}/bufr/ -name 'element.table' -print` do ${test_dir}/bufr_check_descriptors $file done + +# Check we detect bad inputs +# --------------------------- +echo "abc" > $tempInput +set +e +${test_dir}/bufr_check_descriptors $tempInput >$tempText 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "Number of columns .* required miniumum" $tempText + + +echo "a|b|c|d|e|f|g|h" > $tempInput +set +e +${test_dir}/bufr_check_descriptors $tempInput >$tempText 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "descriptor code .* is not numeric" $tempText + + +echo "1234567|b|c|d|e|f|g|h" > $tempInput +set +e +${test_dir}/bufr_check_descriptors $tempInput >$tempText 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "descriptor code .* is not 6 digits" $tempText + + +echo "010192|depthOfRoots|rubbish|DEPTH OF ROOTS|m|2|0|10" > $tempInput +set +e +${test_dir}/bufr_check_descriptors $tempInput >$tempText 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "descriptor key type .* is not valid" $tempText +rm -f $tempText + +echo "010192|depthOfRoots|double|DEPTH OF ROOTS|m|x|0|0" > $tempInput +set +e +${test_dir}/bufr_check_descriptors $tempInput >$tempText 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "descriptor scale .* is not numeric" $tempText + + +echo "010192|depthOfRoots|double|DEPTH OF ROOTS|m|0|a|0" > $tempInput +set +e +${test_dir}/bufr_check_descriptors $tempInput >$tempText 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "descriptor reference .* is not numeric" $tempText + + +echo "010192|depthOfRoots|double|DEPTH OF ROOTS|m|0|0|p" > $tempInput +set +e +${test_dir}/bufr_check_descriptors $tempInput >$tempText 2>&1 +status=$? +set -e +[ $status -ne 0 ] +cat $tempText +grep -q "descriptor width" $tempText + + +# Clean up +rm -f $tempInput $tempText diff --git a/tests/grib2_templates.sh b/tests/grib2_templates.sh index 64b43e4ad..bb295b73a 100755 --- a/tests/grib2_templates.sh +++ b/tests/grib2_templates.sh @@ -26,7 +26,7 @@ latestOfficial=`${tools_dir}/grib_get -p tablesVersionLatestOfficial $sample2` latest_codetable_file=$ECCODES_DEFINITION_PATH/grib2/tables/$latestOfficial/4.0.table awk '$1 !~ /#/ && $1 < 65000 {print $1}' $latest_codetable_file | while read pdtn; do - if [ ! -f "$ECCODES_DEFINITION_PATH/grib2/template.4.$pdtn.def" ]; then + if [ ! -f "$ECCODES_DEFINITION_PATH/grib2/templates/template.4.$pdtn.def" ]; then echo "GRIB2 template for product definition $pdtn does not exist!" exit 1 fi diff --git a/tests/grib_bitmap.sh b/tests/grib_bitmap.sh index 36ba2cf4d..e78ccc897 100755 --- a/tests/grib_bitmap.sh +++ b/tests/grib_bitmap.sh @@ -127,6 +127,8 @@ ${tools_dir}/grib_copy -r $infile $temp2 ${tools_dir}/grib_compare -R all=0.3 -c data:n $infile $temp2 grib_check_key_equals $temp2 bitsPerValue 9 # Note: The input file has bpv=9 +${tools_dir}/grib_set -rs optimizeScaleFactor=1 $infile $temp2 +${tools_dir}/grib_compare $infile $temp2 # Simple to grid_complex tempComplex=temp.grib_bitmap.complex.grib diff --git a/tests/grib_filter.sh b/tests/grib_filter.sh index 4f4ab00be..fce1a6f0b 100755 --- a/tests/grib_filter.sh +++ b/tests/grib_filter.sh @@ -301,6 +301,23 @@ ${tools_dir}/grib_filter $tempFilt $input cd .. rm -rf $tempDir +# Use of debug_mode functor +cat >$tempFilt < $tempOut 2>&1 +# 2m temperature has typeOfFirstFixedSurface of 103 +grep -q "ECCODES DEBUG about to set key/value pair: typeOfFirstFixedSurface=103" $tempOut +grep -q "grib_set_long_internal .* year=1999" $tempOut + + # Use of 'defined' functor cat >$tempFilt < $tempOut - ${tools_dir}/grib_list_keys $ECCODES_DEFINITION_PATH/grib2/template.4.2000.def > $tempOut - ${tools_dir}/grib_list_keys $ECCODES_DEFINITION_PATH/grib2/template.3.0.def > $tempOut - ${tools_dir}/grib_list_keys $ECCODES_DEFINITION_PATH/grib2/template.3.120.def > $tempOut + ${tools_dir}/grib_list_keys $ECCODES_DEFINITION_PATH/grib2/templates/template.4.2000.def > $tempOut + ${tools_dir}/grib_list_keys $ECCODES_DEFINITION_PATH/grib2/templates/template.3.0.def > $tempOut + ${tools_dir}/grib_list_keys $ECCODES_DEFINITION_PATH/grib2/templates/template.3.120.def > $tempOut fi fi diff --git a/tests/unit_tests.cc b/tests/unit_tests.cc index 22a394548..d1575301a 100644 --- a/tests/unit_tests.cc +++ b/tests/unit_tests.cc @@ -742,10 +742,36 @@ void test_codes_get_error_message() Assert( STR_EQUAL(errmsg, "Unknown error -6666")); } +void test_codes_context_set_debug() +{ + printf("Running %s ...\n", __func__); + grib_context* context = NULL; + int err = 0; + + printf("\tEnable debugging...\n"); + grib_context_set_debug(context, -1); + + grib_handle* h = grib_handle_new_from_samples(context, "GRIB2"); + err = grib_set_long(h, "paramId", 167); + Assert(!err); + + printf("\tDisable debugging...\n"); + grib_context_set_debug(context, 0); + + err = grib_set_long(h, "edition", 1); + Assert(!err); + printf("\tEnable debugging again (verbose)...\n"); + grib_context_set_debug(context, 1); + grib_handle_delete(h); + + grib_context_set_debug(context, 0); +} + int main(int argc, char** argv) { printf("Doing unit tests. ecCodes version = %ld\n", grib_get_api_version()); + test_codes_context_set_debug(); test_codes_get_error_message(); test_iarray(); diff --git a/tools/bufr_compare.cc b/tools/bufr_compare.cc index 325c67cd3..92e268e77 100644 --- a/tools/bufr_compare.cc +++ b/tools/bufr_compare.cc @@ -348,7 +348,7 @@ int grib_tool_init(grib_runtime_options* options) if (path_is_directory(infile->name)) { /* Take the filename of the 1st file and append to dir */ char bufr[2048] = {0,}; - /* options->infile_extra->name is the 1st file */ + /* options->infile_extra->name_ is the 1st file */ snprintf(bufr, sizeof(bufr), "%s%c%s", infile->name, get_dir_separator_char(), @@ -1089,22 +1089,22 @@ static int compare_attributes(grib_handle* handle1, grib_handle* handle2, grib_r grib_accessor* a, const char* prefix, int* err) { int i = 0, ret = 0; - while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes[i]) { + while (i < MAX_ACCESSOR_ATTRIBUTES && a->attributes_[i]) { /*long native_type = 0;*/ grib_accessor* aa = NULL; - if ((a->attributes[i]->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) { + if ((a->attributes_[i]->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) { ++i; /* next attribute if accessor is not for dumping */ continue; } - if ((a->attributes[i]->flags & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { + if ((a->attributes_[i]->flags_ & GRIB_ACCESSOR_FLAG_READ_ONLY) != 0) { ++i; /* next attribute if accessor is read-only */ continue; } - aa = a->attributes[i]; + aa = a->attributes_[i]; /*native_type = grib_accessor_get_native_type(aa); TODO: read only check? */ - isLeafKey = aa->attributes[0] == NULL ? 1 : 0; /* update global variable */ + isLeafKey = aa->attributes_[0] == NULL ? 1 : 0; /* update global variable */ if (compare_attribute(handle1, handle2, options, aa, prefix, err)) { (*err)++; @@ -1122,9 +1122,9 @@ static int compare_attribute(grib_handle* handle1, grib_handle* handle2, grib_ru { int ret = 0; grib_context* c = handle1->context; - const size_t fullnameMaxLen = strlen(a->name) + strlen(prefix) + 5; + const size_t fullnameMaxLen = strlen(a->name_) + strlen(prefix) + 5; char* fullname = (char*)grib_context_malloc_clear(c, sizeof(char) * fullnameMaxLen); - snprintf(fullname, fullnameMaxLen, "%s->%s", prefix, a->name); + snprintf(fullname, fullnameMaxLen, "%s->%s", prefix, a->name_); if (compare_values(options, handle1, handle2, fullname, GRIB_TYPE_UNDEFINED)) { (*err)++; ret = 1; @@ -1181,19 +1181,19 @@ static int compare_all_dump_keys(grib_handle* handle1, grib_handle* handle2, gri name = grib_keys_iterator_get_name(iter); if (blocklisted(name)) continue; - if (xa == NULL || (xa->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if (xa == NULL || (xa->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) continue; /* Get full name of key, e.g. '#2#windSpeed' or 'blockNumber' */ - rank = compute_bufr_key_rank(handle1, keys_list, xa->name); + rank = compute_bufr_key_rank(handle1, keys_list, xa->name_); if (rank != 0) { - const size_t prefixMaxLen = strlen(xa->name) + 10; + const size_t prefixMaxLen = strlen(xa->name_) + 10; prefix = (char*)grib_context_malloc_clear(context, sizeof(char) * prefixMaxLen); dofree = 1; - snprintf(prefix, prefixMaxLen, "#%d#%s", rank, xa->name); + snprintf(prefix, prefixMaxLen, "#%d#%s", rank, xa->name_); } else { - prefix = (char*)xa->name; + prefix = (char*)xa->name_; } if (blocklisted(prefix)) { diff --git a/tools/bufr_compare_dir b/tools/bufr_compare_dir index 33adb21b6..f7ba8763b 100755 --- a/tools/bufr_compare_dir +++ b/tools/bufr_compare_dir @@ -1,30 +1,30 @@ -#!/bin/ksh +#!/bin/sh keys="md5Structure,md5Data,typicalDate,typicalTime,rdbType,rdbSubtype,ident,satelliteID,localLatitude,localLongitude,localLatitude1,localLongitude1,localLatitude2,localLongitude2" opt="" -if [[ $# -eq 3 ]] +if [ $# -eq 3 ] then opt=$1 dir1=$2 dir2=$3 fi -if [[ $# -eq 2 ]] +if [ $# -eq 2 ] then dir1=$1 dir2=$2 fi -if [[ $# -gt 3 ]] || [[ $# -lt 2 ]] +if [ $# -gt 3 ] || [ $# -lt 2 ] then echo usage: [bufr_compare options] bufr_compare_dir directory1 directory2 exit 1 fi -bufr_index_build -k $keys -o 1.idx $dir1/* > /dev/null -bufr_index_build -k $keys -o 2.idx $dir2/* > /dev/null +bufr_index_build -k $keys -o 1.idx "$dir1"/* > /dev/null +bufr_index_build -k $keys -o 2.idx "$dir2"/* > /dev/null bufr_compare -f $opt 1.idx 2.idx rm -f 1.idx 2.idx diff --git a/tools/grib_compare.cc b/tools/grib_compare.cc index 330f218e0..5138ea762 100644 --- a/tools/grib_compare.cc +++ b/tools/grib_compare.cc @@ -647,9 +647,9 @@ static int test_bit(long a, long b) /* If the accessor represents a codeflag key, then return its binary rep in 'result' */ static int codeflag_to_bitstr(grib_accessor* a, long val, char* result) { - if (a && grib_inline_strcmp(a->cclass->name, "codeflag") == 0) { + if (a && grib_inline_strcmp(a->class_name_, "codeflag") == 0) { long i; - const long bytelen = a->length * 8; + const long bytelen = a->length_ * 8; for (i = 0; i < bytelen; i++) { if (test_bit(val, bytelen - i - 1)) *result = '1'; diff --git a/tools/grib_to_netcdf.cc b/tools/grib_to_netcdf.cc index 0dad044ab..920942e66 100644 --- a/tools/grib_to_netcdf.cc +++ b/tools/grib_to_netcdf.cc @@ -139,7 +139,7 @@ static bool eq_time(const char* l, const char* r) static value* new_value(const char* name) { - value* v = (value*)calloc(sizeof(value), 1); + value* v = (value*)calloc(1, sizeof(value)); Assert(v); v->name = grib_context_strdup(ctx, name); return v; @@ -281,7 +281,7 @@ static bool is_number(const char* name) } static parameter* new_parameter(char* name, value* v) { - parameter* p = (parameter*)calloc(sizeof(parameter), 1); + parameter* p = (parameter*)calloc(1, sizeof(parameter)); Assert(p); p->name = grib_context_strdup(ctx, name); p->values = v; @@ -703,7 +703,7 @@ typedef struct fieldset #define MISSING_FIELD(f) ((f)->missing) #define FIELD_HAS_BITMAP(f) ((f)->bitmap) - #define FASTNEW(type) (type*)calloc(sizeof(type),1) + #define FASTNEW(type) (type*)calloc(1, sizeof(type)) #define grib_context_free(ctx,x) grib_context_free(ctx,x) */ @@ -719,7 +719,7 @@ static int ecc_cube_position(const hypercube* h, const request* r, bool remove_h static value* clone_one_value(const value* p) { - value* q = (value*)calloc(sizeof(value), 1); + value* q = (value*)calloc(1, sizeof(value)); Assert(q); q->next = NULL; q->name = grib_context_strdup(ctx, p->name); @@ -739,7 +739,7 @@ static value* clone_all_values(const value* p) static parameter* clone_one_parameter(const parameter* p) { - parameter* q = (parameter*)calloc(sizeof(parameter), 1); + parameter* q = (parameter*)calloc(1, sizeof(parameter)); Assert(q); q->next = NULL; q->name = grib_context_strdup(ctx, p->name); @@ -760,7 +760,7 @@ static parameter* clone_all_parameters(const parameter* p) static request* clone_one_request(const request* r) { if (r) { - request* p = (request*)calloc(sizeof(request), 1); + request* p = (request*)calloc(1, sizeof(request)); Assert(p); p->name = grib_context_strdup(ctx, r->name); @@ -773,7 +773,7 @@ static request* clone_one_request(const request* r) static request* new_request(const char* name, parameter* p) { - request* r = (request*)calloc(sizeof(request), 1); + request* r = (request*)calloc(1, sizeof(request)); Assert(r); r->name = grib_context_strdup(ctx, name); r->params = p; @@ -879,7 +879,7 @@ static void grow_fieldset(fieldset* v, int n) static fieldset* new_fieldset(int n) { - fieldset* f = (fieldset*)calloc(sizeof(fieldset), 1); + fieldset* f = (fieldset*)calloc(1, sizeof(fieldset)); Assert(f); grow_fieldset(f, n); return f; @@ -1546,7 +1546,7 @@ static void reserve_index_cache(hypercube* h, int size) if (h->index_cache != 0) grib_context_free(ctx, h->index_cache); grib_context_log(ctx, GRIB_LOG_DEBUG, "grib_to_netcdf: Allocating hypercube index_cache: %d entries", size); - h->index_cache = (int*)calloc(sizeof(int), size); + h->index_cache = (int*)calloc(size, sizeof(int)); Assert(h->index_cache); h->index_cache_size = size; } @@ -1663,7 +1663,7 @@ static void cube_indexes( static hypercube* new_hypercube(const request* r) { - hypercube* h = (hypercube*)calloc(sizeof(hypercube), 1); + hypercube* h = (hypercube*)calloc(1, sizeof(hypercube)); int total = 0, count = 0; size_t n = 0; const char* val = 0; @@ -1770,7 +1770,7 @@ static hypercube* new_hypercube_from_mars_request(const request* r) n = count_values(s.c->cube, "axis"); if (n) { - s.c->compare = (namecmp*)calloc(sizeof(namecmp), n); + s.c->compare = (namecmp*)calloc(n, sizeof(namecmp)); Assert(s.c->compare); } @@ -1797,7 +1797,7 @@ static hypercube* new_simple_hypercube_from_mars_request(const request* r) free_one_request(s.r); n = count_values(s.c->cube, "axis"); if (n) { - s.c->compare = (namecmp*)calloc(sizeof(namecmp), n); + s.c->compare = (namecmp*)calloc(n, sizeof(namecmp)); Assert(s.c->compare); } @@ -2899,7 +2899,7 @@ static void set_always_a_time(hypercube* h, request* data_r) int i = 0; int n = count_values(h->cube, "axis"); if (n) { - h->compare = (namecmp*)calloc(sizeof(namecmp), n); + h->compare = (namecmp*)calloc(n, sizeof(namecmp)); Assert(h->compare); } @@ -3623,7 +3623,7 @@ static int split_fieldset(fieldset* fs, request* data_r, dataset_t** subsets, co free_all_requests(s); - filters = (dataset_t*)calloc(sizeof(dataset_t), count); + filters = (dataset_t*)calloc(count, sizeof(dataset_t)); Assert(filters); s = u; diff --git a/tools/grib_tools.cc b/tools/grib_tools.cc index cde99abac..7b83cd293 100644 --- a/tools/grib_tools.cc +++ b/tools/grib_tools.cc @@ -800,7 +800,7 @@ static void grib_tools_set_print_keys(grib_runtime_options* options, grib_handle grib_accessor* anAccessor = h->accessors[i]; if (anAccessor) { for (j = 0; j < MAX_ACCESSOR_NAMES; j++) { - const char* a_namespace = anAccessor->all_name_spaces[j]; + const char* a_namespace = anAccessor->all_name_spaces_[j]; if (a_namespace) { all_namespace_vals[k++] = a_namespace; ns_count++; diff --git a/tools/gts_compare.cc b/tools/gts_compare.cc index 3a084893d..bd98965b4 100644 --- a/tools/gts_compare.cc +++ b/tools/gts_compare.cc @@ -577,7 +577,7 @@ static int compare_all_dump_keys(grib_handle* h1, grib_handle* h2, grib_runtime_ if (blocklisted(name)) continue; - if (xa == NULL || (xa->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if (xa == NULL || (xa->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) continue; if (compare_values(options, h1, h2, name, GRIB_TYPE_UNDEFINED)) { (*pErr)++; diff --git a/tools/metar_compare.cc b/tools/metar_compare.cc index 6ffc5db5a..127ed56c5 100644 --- a/tools/metar_compare.cc +++ b/tools/metar_compare.cc @@ -730,7 +730,7 @@ static int compare_all_dump_keys(grib_handle* h1, grib_handle* h2, grib_runtime_ if (blocklisted(name)) continue; - if (xa == NULL || (xa->flags & GRIB_ACCESSOR_FLAG_DUMP) == 0) + if (xa == NULL || (xa->flags_ & GRIB_ACCESSOR_FLAG_DUMP) == 0) continue; if (compare_values(options, h1, h2, name, GRIB_TYPE_UNDEFINED)) { (*pErr)++;