diff --git a/.gitignore b/.gitignore index 699721864..a966f1436 100644 --- a/.gitignore +++ b/.gitignore @@ -178,6 +178,13 @@ ehthumbs.db Thumbs.db .directory +src/tags + +data/exp +data/bufr/*.ref +data/bufr/*.test +data/bufr/*.json +data/bufr/*.no data/.downloaded data/budg data/*.grib @@ -185,6 +192,7 @@ data/*.grib2 data/*.grib1 data/tigge/tigge*.grib data/bufr/*.bufr +data/exp/ CMakeLists.txt.user* diff --git a/data/bufr/make_bufrdc_ref.ksh b/data/bufr/make_bufrdc_ref.ksh new file mode 100755 index 000000000..d3a73d808 --- /dev/null +++ b/data/bufr/make_bufrdc_ref.ksh @@ -0,0 +1,9 @@ +#!/bin/ksh +set -ex + +decode=/var/tmp/mac/p4/bufrdc/releases/000402/examples/bufr_decode_data + +for f in *.bufr +do + $decode -i $f | sed 's/MISSING/-1.00000000000000e+100/g' | sed -e '/ECMWF/,+8d' > $f.ref +done diff --git a/definitions/bufr/section.3.def b/definitions/bufr/section.3.def index 6e7afd9fc..bad6f73fd 100644 --- a/definitions/bufr/section.3.def +++ b/definitions/bufr/section.3.def @@ -10,6 +10,7 @@ constant defaultSequence=0; constant tablesMasterDir="bufr/tables/[masterTableNumber]/wmo/[masterTablesVersionNumber]" : hidden; constant tablesLocalDir="bufr/tables/[masterTableNumber]/local/[localTablesVersionNumber]/[centre:l]/[subCentre]" : hidden; +constant rootTablesDir="bufr/tables" : hidden; transient tableNumber=0; codetable[24] codeTablesMaster '[tablesMasterDir]/codetables/[tableNumber].table' : string_type,transient; @@ -68,31 +69,18 @@ meta unexpandedDescriptors unexpanded_descriptors(numberOfUnexpandedDescriptors) meta expandedDescriptors expanded_descriptors(unexpandedDescriptors,sequences) ; -#smart_table NAME (VALUES,FILE_NAME,MASTER_DIRECTORY,LOCAL_DIRECTORY,WIDTH_OF_CODE_IN_BITS); -smart_table elements (expandedDescriptors,"element.table",tablesMasterDir,tablesLocalDir,16) ; -meta abbreviation smart_table_column(elements,0,1) : string_type; -meta type smart_table_column(elements,1,0) : string_type; -meta name smart_table_column(elements,2,0) : string_type; -meta unit smart_table_column(elements,3,0) : string_type; -meta scale smart_table_column(elements,4,0) : long_type; -meta reference smart_table_column(elements,5,0) : long_type; -meta width smart_table_column(elements,6,0) : long_type; -meta crex_unit smart_table_column(elements,7,0) : long_type; -meta crex_scale smart_table_column(elements,8,0) : long_type; -meta crex_width smart_table_column(elements,9,0) : long_type; - -meta expandedDescriptorsAfterOperators apply_operators(expandedDescriptors,abbreviation,type,name,unit,scale,reference,width,0) : read_only; -meta scaleAfterOperators apply_operators(expandedDescriptors,abbreviation,type,name,unit,scale,reference,width,1) :read_only; -meta referenceAfterOperators apply_operators(expandedDescriptors,abbreviation,type,name,unit,scale,reference,width,2) :read_only; -meta widthAfterOperators apply_operators(expandedDescriptors,abbreviation,type,name,unit,scale,reference,width,3) :read_only; -meta bitmapNumber apply_operators(expandedDescriptors,abbreviation,type,name,unit,scale,reference,width,4) :read_only; -meta associatedBitmapNumber apply_operators(expandedDescriptors,abbreviation,type,name,unit,scale,reference,width,5) :read_only; -meta associatedBitmapIndex apply_operators(expandedDescriptors,abbreviation,type,name,unit,scale,reference,width,6) :read_only; -meta abbreviationAfterOperators apply_operators(expandedDescriptors,abbreviation,type,name,unit,scale,reference,width,7) :read_only,string_type; -meta typeAfterOperators apply_operators(expandedDescriptors,abbreviation,type,name,unit,scale,reference,width,8) :read_only,string_type; -meta nameAfterOperators apply_operators(expandedDescriptors,abbreviation,type,name,unit,scale,reference,width,9) :read_only,string_type; -meta unitAfterOperators apply_operators(expandedDescriptors,abbreviation,type,name,unit,scale,reference,width,10) :read_only,string_type; -meta associatedInfoNumber apply_operators(expandedDescriptors,abbreviation,type,name,unit,scale,reference,width,11) :read_only; +#smart_table NAME (VALUES,FILE_NAME,MASTER_DIRECTORY,LOCAL_DIRECTORY,WIDTH_OF_CODE_IN_BITS,EXTRA_DIRECTORY,EXTRA_FILE_NAME); +smart_table expanded (expandedDescriptors,"element.table",tablesMasterDir,tablesLocalDir,18,rootTablesDir,"operators.table") ; +meta abbreviation smart_table_column(expanded,0,1) : string_type; +meta type smart_table_column(expanded,1,0) : string_type; +meta name smart_table_column(expanded,2,0) : string_type; +meta unit smart_table_column(expanded,3,0) : string_type; +meta scale smart_table_column(expanded,4,0) : long_type; +meta reference smart_table_column(expanded,5,0) : long_type; +meta width smart_table_column(expanded,6,0) : long_type; +meta crex_unit smart_table_column(expanded,7,0) : long_type; +meta crex_scale smart_table_column(expanded,8,0) : long_type; +meta crex_width smart_table_column(expanded,9,0) : long_type; meta hasDelayedReplication bufr_has_delayed_replication(expandedDescriptorsAfterOperators); diff --git a/definitions/bufr/section.4.def b/definitions/bufr/section.4.def index f4109e062..57a51b5f9 100644 --- a/definitions/bufr/section.4.def +++ b/definitions/bufr/section.4.def @@ -17,22 +17,15 @@ meta selectGroupNumber bufr_group_number(); transient subsetNumber=0; if (compressedData) { - meta values bufr_data(offsetSection4,offsetBeforeData,offsetEndSection4,section4Length, - numberOfDataSubsets,subsetNumber, - expandedDescriptorsAfterOperators,abbreviationAfterOperators, - typeAfterOperators,nameAfterOperators,unitAfterOperators, - referenceAfterOperators,scaleAfterOperators,widthAfterOperators,codeFlags, - bitmapNumber,associatedBitmapNumber,associatedBitmapIndex,associatedInfoNumber) : dump; +meta numericValues bufr_data_array(offsetSection4,offsetBeforeData,offsetEndSection4,section4Length, + numberOfDataSubsets,subsetNumber, + expandedDescriptors,type,reference,scale,width, + stringValues,elementsFXY,compressedData) ; } else { - meta values bufr_uncompressed_data(offsetSection4,offsetBeforeData,offsetEndSection4,section4Length, - numberOfDataSubsets,subsetNumber, - expandedDescriptorsAfterOperators,abbreviationAfterOperators, - typeAfterOperators,nameAfterOperators,unitAfterOperators, - referenceAfterOperators,scaleAfterOperators,widthAfterOperators,codeFlags, - bitmapNumber,associatedBitmapNumber,associatedBitmapIndex) : dump; + assert(0); } -meta unpack unpack_bufr_values(values); +meta unpack unpack_bufr_values(numericValues); section_padding section4Padding; position offsetEndSection4; diff --git a/definitions/bufr/tables/operators.table b/definitions/bufr/tables/operators.table new file mode 100644 index 000000000..7e11594de --- /dev/null +++ b/definitions/bufr/tables/operators.table @@ -0,0 +1,15 @@ +#code|abbreviation|type|name|unit|scale|reference|width|crex_unit|crex_scale|crex_width +222000|qualityInformationFollows|long|The values of class 33 elements which follow relate to the data defined by the data present bit-map|OPERATOR|0|0|0|0|0| +223000|substitutedValuesOperator|long|The substituted values which follow relate to the data defined by the data present bit-map|OPERATOR|0|0|0|0|0| +223255|substitutedValuesMarkerOperator|long|This operator shall signify a data item containing a substituted value; the element descriptor for the substituted value is obtained by the application of the data present bit-map associated with the substituted values operator|OPERATOR|0|0|0|0|0| +224000|firstOrderStatisticalValuesFollow|long|The statistical values which follow relate to the data defined by the data present bit-map|OPERATOR|0|0|0|0|0| +224555|firstOrderStatisticalValuesMarkerOperator|long|This operator shall signify a data item containing a first-order statistical value of the type indicated by the preceding 0 08 023 element descriptor; the element descriptor to which the fi-rosrtder statistic relates is obtained by the application of the data present bit-map associated with the first-order statistical values follow operator; first-order statistical values shall be represented as defined by this element descriptor |OPERATOR|0|0|0|0|0| +225000|differenceStatisticalValuesFollow|long|The statistical values which follow relate to the data defined by the data present bit-map|OPERATOR|0|0|0|0|0| +225255|differenceStatisticalValuesMarkerOperator|long|This operator shall signify a data item containing a difference statistical value of the type indicated by the preceding 0 08 024 element descriptor; the element descriptor to which the difference statistical value relates is obtained by the application of the data present bit-map associated with the difference statistical values follow operator; difference statistical values shall be represented as defined by this element descriptor, but with a reference value of –2n and a data width of (n+1), where n is the data width given by the original descriptor. This special reference value allows the statistical difference values to be centred around zero|OPERATOR|0|0|0|0|0| +232000|replacedRetainedValuesFollow|long|The replaced/retained values which follow relate to the data defined by the data present bit-map|OPERATOR|0|0|0|0|0| +232255|replacedRetainedValuesMarkerOperator|long|This operator shall signify a data item containing the original of an element which has been replaced by a substituted value. The element descriptor for the retained value is obtained by the application of the data present bit-map associated with the substituted values operator|OPERATOR|0|0|0|0|0| +236000|defineDataPresentBitmap|long|This operator defines the data present bit-map which follows for possible re-use; only one data present bitmap may be defined between this operator and the cancel use defined data present bit-map operator|OPERATOR|0|0|0|0|0| +236000|defineDataPresentBitmap|long|This operator defines the data present bit-map which follows for possible re-use; only one data present bitmap may be defined between this operator and the cancel use defined data present bit-map operator |OPERATOR|0|0|0|0|0| +237000|useDefinedDataPresentBitmap|long|This operator causes the defined data present bit-map to be used again|OPERATOR|0|0|0|0|0| +237255|cancelUseDefinedDataPresentBitmap|long|This operator cancels the re-use of the defined data present bit-map|OPERATOR|0|0|0|0|0| +001192|modelVersionNumber|long|MODEL VERSION NUMBER|CODE TABLE 1192|0|0|8|0|0| diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6f3ddde17..92d17e1ee 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,347 @@ list( APPEND grib_api_srcs +<<<<<<< HEAD + grib_api.h + action.c + action_class_alias.c + action_class_gen.c + action_class_if.c + action_class_switch.c + grib_accessor_class_g1fcperiod.c + grib_accessor_class_g1end_of_interval_monthly.c + grib_accessor_class_mars_param.c + action_class_section.c + action_class_list.c + action_class_while.c + action_class_put.c + action_class_meta.c + action_class_remove.c + action_class_rename.c + action_class_assert.c + action_class_template.c + action_class_trigger.c + action_class_when.c + action_class_concept.c + action_class_hash_array.c + action_class_assert.c + action_class_template.c + action_class_trigger.c + action_class_when.c + action_class_hash_array.c + action_class_set.c + action_class_set_darray.c + action_class_set_iarray.c + action_class_noop.c + action_class_write.c + action_class_print.c + action_class_close.c + action_class_variable.c + action_class_modify.c + grib_accessor.c + grib_concept.c + grib_hash_array.c + grib_darray.c + grib_vdarray.c + grib_sarray.c + grib_vsarray.c + grib_iarray.c + grib_viarray.c + grib_accessor_class_array.c + grib_accessor_class_assert.c + grib_accessor_class_ascii.c + grib_accessor_class_bit.c + grib_accessor_class_bitmap.c + grib_accessor_class_bits.c + grib_accessor_class_bits_per_value.c + grib_accessor_class_bufr_data.c + grib_accessor_class_bufr_data_element.c + grib_accessor_class_bufr_group.c + grib_accessor_class_unpack_bufr_values.c + grib_accessor_class_bufr_uncompressed_data.c + grib_accessor_class_bufr_element.c + grib_accessor_class_bufr_has_delayed_replication.c + grib_accessor_class_bufr_subset_number.c + grib_accessor_class_bufr_group_number.c + grib_accessor_class_apply_operators.c + grib_accessor_class_group.c + grib_accessor_class_non_alpha.c + grib_accessor_class_g1bitmap.c + grib_accessor_class_g2bitmap.c + grib_accessor_class_concept.c + grib_accessor_class_hash_array.c + grib_accessor_class_decimal_precision.c + grib_accessor_class_divdouble.c + grib_accessor_class_budgdate.c + grib_accessor_class_validity_date.c + grib_accessor_class_validity_time.c + grib_accessor_class_bytes.c + grib_accessor_class.c + grib_accessor_class_change_scanning_direction.c + grib_accessor_class_codeflag.c + grib_accessor_class_smart_table.c + grib_accessor_class_smart_table_column.c + grib_accessor_class_codetable.c + grib_accessor_class_codetable_units.c + grib_accessor_class_codetable_title.c + grib_accessor_class_count_file.c + grib_accessor_class_count_total.c + grib_accessor_class_double.c + grib_accessor_class_element.c + grib_accessor_class_evaluate.c + grib_accessor_class_g1area.c + grib_accessor_class_g1date.c + grib_accessor_class_g1monthlydate.c + grib_accessor_class_library_version.c + grib_accessor_class_when.c + grib_accessor_class_g1verificationdate.c + grib_accessor_class_g1day_of_the_year_date.c + grib_accessor_class_g1_half_byte_codeflag.c + grib_accessor_class_g1forecastmonth.c + grib_accessor_class_g1step_range.c + grib_accessor_class_g2step_range.c + grib_accessor_class_data_g22order_packing.c + grib_accessor_class_mars_step.c + grib_accessor_class_message_copy.c + grib_accessor_class_dictionary.c + grib_accessor_class_g1param.c + grib_accessor_class_g1p1p2.c + grib_accessor_class_g1_increment.c + grib_accessor_class_latlon_increment.c + grib_accessor_class_g2date.c + grib_accessor_class_g2level.c + grib_accessor_class_g2step.c + grib_accessor_class_g2end_step.c + grib_accessor_class_g2latlon.c + grib_accessor_class_g2lon.c + grib_accessor_class_global_gaussian.c + grib_accessor_class_gen.c + grib_accessor_class_getenv.c + grib_accessor_class_gts_header.c + grib_accessor_class_ifs_param.c + grib_accessor_class_julian_day.c + grib_accessor_class_latlonvalues.c + grib_accessor_class_latitudes.c + grib_accessor_class_longitudes.c + grib_accessor_class_missing.c + grib_accessor_class_offset_file.c + grib_accessor_class_scale.c + grib_accessor_class_from_scale_factor_scaled_value.c + grib_accessor_class_times.c + grib_accessor_class_forward.c + grib_accessor_class_g2bitmap_present.c + grib_accessor_class_ibmfloat.c + grib_accessor_class_ieeefloat.c + grib_accessor_class_constant.c + grib_accessor_class_iterator.c + grib_accessor_class_message.c + grib_accessor_class_nearest.c + grib_accessor_class_box.c + grib_accessor_class_ksec1expver.c + grib_accessor_class_laplacian.c + grib_accessor_class_label.c + grib_accessor_class_long.c + grib_accessor_class_lookup.c + grib_accessor_class_octect_number.c + grib_accessor_class_headers_only.c + grib_accessor_class_padding.c + grib_accessor_class_pad.c + grib_accessor_class_padto.c + grib_accessor_class_padtoeven.c + grib_accessor_class_padtomultiple.c + grib_accessor_class_section_padding.c + grib_accessor_class_section_pointer.c + grib_accessor_class_position.c + grib_accessor_class_signed.c + grib_accessor_class_signed_bits.c + grib_accessor_class_section.c + grib_accessor_class_step_in_units.c + grib_accessor_class_section_length.c + grib_accessor_class_g1_message_length.c + grib_accessor_class_g1_section4_length.c + grib_accessor_class_size.c + grib_accessor_class_scale_values.c + grib_accessor_class_offset_values.c + grib_accessor_class_sprintf.c + grib_accessor_class_round.c + grib_accessor_class_spectral_truncation.c + grib_accessor_class_time.c + grib_accessor_class_transient.c + grib_accessor_class_g1_half_byte_codeflag.c + grib_accessor_class_values.c + grib_accessor_class_simple_packing_error.c + grib_accessor_class_data_simple_packing.c + grib_accessor_class_count_missing.c + grib_accessor_class_data_sh_packed.c + grib_accessor_class_data_sh_unpacked.c + grib_accessor_class_number_of_values_data_raw_packing.c + grib_accessor_class_data_g1simple_packing.c + grib_accessor_class_data_g1shsimple_packing.c + grib_accessor_class_data_shsimple_packing.c + grib_accessor_class_data_constant_field.c + grib_accessor_class_data_dummy_field.c + grib_2order_packer_simple.c + grib_accessor_class_variable.c + grib_accessor_class_second_order_bits_per_value.c + grib_accessor_class_data_g2simple_packing.c + grib_accessor_class_data_g2simple_packing_with_preprocessing.c + grib_accessor_class_data_g2shsimple_packing.c + grib_accessor_class_data_g2complex_packing.c + grib_accessor_class_data_2order_packing.c + grib_accessor_class_data_2order_packing_count.c + grib_accessor_class_data_g1second_order_row_by_row_packing.c + grib_accessor_class_data_g1second_order_constant_width_packing.c + grib_accessor_class_data_g1second_order_general_packing.c + grib_accessor_class_data_g1second_order_general_extended_packing.c + grib_accessor_class_g2grid.c + grib_accessor_class_unexpanded_descriptors.c + grib_accessor_class_expanded_descriptors.c + grib_accessor_class_data_apply_bitmap.c + grib_accessor_class_data_apply_boustrophedonic.c + grib_accessor_class_data_apply_boustrophedonic_bitmap.c + grib_accessor_class_data_secondary_bitmap.c + grib_accessor_class_data_g1secondary_bitmap.c + grib_accessor_class_data_g2secondary_bitmap.c + grib_accessor_class_data_jpeg2000_packing.c + grib_accessor_class_data_png_packing.c + grib_accessor_class_data_szip_packing.c + grib_accessor_class_data_raw_packing.c + grib_accessor_class_data_complex_packing.c + grib_accessor_class_data_g1complex_packing.c + grib_accessor_class_gds_not_present_bitmap.c + grib_accessor_class_data_apply_gdsnotpresent.c + grib_accessor_class_gds_is_present.c + grib_accessor_class_select_step_template.c + grib_accessor_class_local_definition.c + grib_accessor_class_g2_eps.c + grib_accessor_class_g2_chemical.c + grib_accessor_class_g2_mars_labeling.c + grib_accessor_class_md5.c + grib_jasper_encoding.c + grib_openjpeg_encoding.c + action_class_set_missing.c + grib_accessor_class_number_of_points.c + grib_accessor_class_suppressed.c + grib_index.c + grib_accessor_class_number_of_points_gaussian.c + grib_accessor_class_number_of_values.c + grib_accessor_class_number_of_coded_values.c + grib_accessor_class_g1number_of_coded_values_sh_complex.c + grib_accessor_class_g1number_of_coded_values_sh_simple.c + grib_accessor_class_dirty.c + grib_accessor_class_statistics.c + grib_accessor_class_statistics_spectral.c + grib_accessor_class_unsigned.c + grib_accessor_class_unsigned_bits.c + grib_accessor_class_spd.c + grib_accessor_class_sum.c + grib_accessor_class_to_integer.c + grib_accessor_class_to_double.c + grib_accessor_class_to_string.c + grib_accessor_class_sexagesimal2decimal.c + grib_accessor_class_vector.c + grib_accessor_class_long_vector.c + grib_gaussian_reduced.c + grib_accessor_class_abstract_vector.c + grib_accessor_class_abstract_long_vector.c + grib_loader_from_handle.c + grib_bits.c + grib_timer.c + grib_ibmfloat.c + grib_ieeefloat.c + grib_accessor_class_reference_value_error.c + grib_memory.c + grib_buffer.c + grib_dumper.c + grib_dumper_class_serialize.c + grib_dumper_class_debug.c + grib_dumper_class_default.c + grib_dumper_class_keys.c + grib_dumper_class_json.c + grib_dumper_class_xml.c + grib_dumper_class_c_code.c + grib_dumper_class_wmo.c + grib_dumper_class.c + grib_context.c + grib_date.c + grib_fieldset.c + grib_filepool.c + grib_geography.c + grib_handle.c + grib_header_compute.c + grib_hash_keys.c + grib_io.c + grib_trie.c + grib_itrie.c + grib_rules.c + grib_keys_iterator.c + grib_parse_utils.c + grib_query.c + grib_scaling.c + grib_templates.c + grib_dependency.c + grib_value.c + grib_errors.c + grib_expression_class_binop.c + grib_expression_class_is_in_dict.c + grib_expression_class_true.c + grib_expression_class_string_compare.c + grib_expression_class_unop.c + grib_expression_class_functor.c + grib_expression_class_accessor.c + grib_expression_class_is_in_list.c + grib_expression_class_is_integer.c + grib_expression_class_length.c + grib_expression_class_long.c + grib_expression_class_double.c + grib_expression_class_string.c + grib_expression_class_sub_string.c + grib_box.c + grib_box_class.c + grib_box_class_gen.c + grib_box_class_regular_gaussian.c + grib_box_class_reduced_gaussian.c + grib_nearest.c + grib_nearest_class.c + grib_nearest_class_gen.c + grib_nearest_class_regular.c + grib_nearest_class_reduced.c + grib_nearest_class_latlon_reduced.c + grib_nearest_class_sh.c + grib_nearest_class_lambert_conformal.c + grib_iterator_class_polar_stereographic.c + grib_iterator_class_lambert_azimuthal_equal_area.c + grib_iterator_class_lambert_conformal.c + grib_iterator.c + grib_iterator_class.c + grib_iterator_class_gaussian.c + grib_iterator_class_gaussian_reduced.c + grib_iterator_class_latlon_reduced.c + grib_iterator_class_gen.c + grib_iterator_class_latlon.c + grib_iterator_class_regular.c + grib_expression.c + grib_util.c + compile.c + functions.c + grib_accessor_class.h + grib_accessor_factory.h + grib_api.h + grib_api_internal.h + grib_api_prototypes.h + grib_box_class.h + grib_box_factory.h + grib_dumper_class.h + grib_dumper_factory.h + grib_emoslib.h + grib_expression.h + grib_iterator_class.h + grib_iterator_factory.h + grib_nearest_class.h + grib_nearest_factory.h + grib_templates.h + grib_yacc.h + md5.h + md5.c +======= grib_api.h action.c action_class_alias.c @@ -338,6 +681,7 @@ list( APPEND grib_api_srcs grib_yacc.h md5.h md5.c +>>>>>>> 25e8f0ed91902a8ccb113de6b71a09ecc73f8e01 # Ship our generated lex/yacc C files grib_yacc.c grib_lex.c grib_windef.h diff --git a/src/Makefile.am b/src/Makefile.am index 35733001b..25cd3d84c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -50,6 +50,9 @@ libgrib_api_la_prototypes= \ grib_darray.c \ grib_sarray.c \ grib_iarray.c \ + grib_vdarray.c \ + grib_vsarray.c \ + grib_viarray.c \ grib_accessor_class_array.c \ grib_accessor_class_assert.c \ grib_accessor_class_ascii.c \ diff --git a/src/grib_accessor_class_bufr_data_array.c b/src/grib_accessor_class_bufr_data_array.c index 9c59c31a3..aa1835d82 100644 --- a/src/grib_accessor_class_bufr_data_array.c +++ b/src/grib_accessor_class_bufr_data_array.c @@ -32,34 +32,26 @@ MEMBERS= const char* numberOfDataSubsetsName MEMBERS= const char* subsetNumberName MEMBERS= const char* expandedDescriptorsName - MEMBERS= const char* abbreviationName MEMBERS= const char* typeName - MEMBERS= const char* nameName - MEMBERS= const char* unitName MEMBERS= const char* referenceName MEMBERS= const char* scaleName MEMBERS= const char* widthName - MEMBERS= const char* codeFlags - MEMBERS= const char* bitmapNumberName - MEMBERS= const char* associatedBitmapNumberName - MEMBERS= const char* associatedBitmapIndexName - MEMBERS= const char* associatedInfoNumberName + MEMBERS= const char* stringValuesName + MEMBERS= const char* elementsFXYName + MEMBERS= const char* compressedDataName MEMBERS= long* expandedDescriptors - MEMBERS= char** abbreviation MEMBERS= char** type - MEMBERS= char** names - MEMBERS= char** units MEMBERS= long* reference MEMBERS= double* factor MEMBERS= long* width - MEMBERS= long* bitmapNumber - MEMBERS= long* associatedBitmapNumber - MEMBERS= long* associatedBitmapIndex - MEMBERS= long* associatedInfoNumber - MEMBERS= long numberOfElements + MEMBERS= long subsetNumber MEMBERS= long numberOfDataSubsets + MEMBERS= long compressedData MEMBERS= size_t numberOfDescriptors - MEMBERS= int do_compute + MEMBERS= grib_vdarray* numericValues + MEMBERS= grib_vsarray* stringValues + MEMBERS= grib_viarray* elementsFXY + MEMBERS= int do_decode END_CLASS_DEF @@ -101,34 +93,26 @@ typedef struct grib_accessor_bufr_data_array { const char* numberOfDataSubsetsName; const char* subsetNumberName; const char* expandedDescriptorsName; - const char* abbreviationName; const char* typeName; - const char* nameName; - const char* unitName; const char* referenceName; const char* scaleName; const char* widthName; - const char* codeFlags; - const char* bitmapNumberName; - const char* associatedBitmapNumberName; - const char* associatedBitmapIndexName; - const char* associatedInfoNumberName; + const char* stringValuesName; + const char* elementsFXYName; + const char* compressedDataName; long* expandedDescriptors; - char** abbreviation; char** type; - char** names; - char** units; long* reference; double* factor; long* width; - long* bitmapNumber; - long* associatedBitmapNumber; - long* associatedBitmapIndex; - long* associatedInfoNumber; - long numberOfElements; + long subsetNumber; long numberOfDataSubsets; + long compressedData; size_t numberOfDescriptors; - int do_compute; + grib_vdarray* numericValues; + grib_vsarray* stringValues; + grib_viarray* elementsFXY; + int do_decode; } grib_accessor_bufr_data_array; extern grib_accessor_class* grib_accessor_class_gen; @@ -205,32 +189,12 @@ static void init_class(grib_accessor_class* c) /* END_CLASS_IMP */ -typedef struct grib_accessor_constant { - grib_accessor att; -/* Members defined in gen */ -/* Members defined in variable */ - double dval; - char* cval; - int type; -/* Members defined in constant */ -} grib_accessor_constant; - -typedef struct grib_accessor_bufr_data_element { - grib_accessor att; -/* Members defined in gen */ -/* Members defined in bufr_data_element */ - int type; - size_t numberOfValues; - double* dvalues; - long* lvalues; - grib_sarray* svalues; - int isConstant; -} grib_accessor_bufr_data_element; - #define IS_QUALIFIER(a) (a==8 || a==1 || a==2) #define NUMBER_OF_QUALIFIERS_PER_CATEGORY 256 #define NUMBER_OF_QUALIFIERS_CATEGORIES 3 +<<<<<<< HEAD +======= static int number_of_qualifiers=NUMBER_OF_QUALIFIERS_PER_CATEGORY*NUMBER_OF_QUALIFIERS_CATEGORIES; static GRIB_INLINE int significanceQualifierIndex(int X,int Y) { @@ -238,6 +202,7 @@ static GRIB_INLINE int significanceQualifierIndex(int X,int Y) { return Y+a[X]*NUMBER_OF_QUALIFIERS_PER_CATEGORY; } +>>>>>>> 25e8f0ed91902a8ccb113de6b71a09ecc73f8e01 static long init_length(grib_accessor* a) { grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; @@ -250,8 +215,6 @@ static long init_length(grib_accessor* a) return section4Length-4; } -static int get_elements_and_decode(grib_accessor* a); - static void init(grib_accessor* a,const long v, grib_arguments* params) { grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; @@ -266,14 +229,18 @@ static void init(grib_accessor* a,const long v, grib_arguments* params) self->numberOfDataSubsetsName = grib_arguments_get_name(a->parent->h,params,n++); self->subsetNumberName = grib_arguments_get_name(a->parent->h,params,n++); self->expandedDescriptorsName = grib_arguments_get_name(a->parent->h,params,n++); - self->abbreviationName = grib_arguments_get_name(a->parent->h,params,n++); self->typeName = grib_arguments_get_name(a->parent->h,params,n++); - self->nameName = grib_arguments_get_name(a->parent->h,params,n++); - self->unitName = grib_arguments_get_name(a->parent->h,params,n++); self->referenceName = grib_arguments_get_name(a->parent->h,params,n++); self->scaleName = grib_arguments_get_name(a->parent->h,params,n++); self->widthName = grib_arguments_get_name(a->parent->h,params,n++); - self->do_compute=1; + self->stringValuesName = grib_arguments_get_name(a->parent->h,params,n++); + self->elementsFXYName = grib_arguments_get_name(a->parent->h,params,n++); + self->compressedDataName = grib_arguments_get_name(a->parent->h,params,n++); + self->do_decode=1; + self->elementsFXY=0; + self->numericValues=0; + self->stringValues=0; + a->parent->h->unpacked=0; a->length = init_length(a); @@ -283,22 +250,12 @@ static void init(grib_accessor* a,const long v, grib_arguments* params) static void self_clear(grib_context* c,grib_accessor_bufr_data_array* self) { int i=0; for (i=0;inumberOfDescriptors;i++) { - grib_context_free(c,self->abbreviation[i]); grib_context_free(c,self->type[i]); - grib_context_free(c,self->names[i]); - grib_context_free(c,self->units[i]); } grib_context_free(c,self->expandedDescriptors); - grib_context_free(c,self->abbreviation); grib_context_free(c,self->type); - grib_context_free(c,self->names); - grib_context_free(c,self->units); grib_context_free(c,self->reference); grib_context_free(c,self->width); - grib_context_free(c,self->bitmapNumber); - grib_context_free(c,self->associatedBitmapNumber); - grib_context_free(c,self->associatedBitmapIndex); - grib_context_free(c,self->associatedInfoNumber); grib_context_free(c,self->factor); } static int get_native_type(grib_accessor* a){ @@ -332,7 +289,8 @@ static int compare(grib_accessor* a, grib_accessor* b) { static int pack_long(grib_accessor* a, const long* val, size_t *len) { grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; - self->do_compute=1; + self->do_decode=1; + a->parent->h->unpacked=0; return GRIB_NOT_IMPLEMENTED; } @@ -340,7 +298,8 @@ static int pack_long(grib_accessor* a, const long* val, size_t *len) static int pack_double(grib_accessor* a, const double* val, size_t *len) { grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; - self->do_compute=1; + self->do_decode=1; + a->parent->h->unpacked=0; return GRIB_NOT_IMPLEMENTED; } @@ -373,109 +332,107 @@ static int get_descriptors(grib_accessor* a) { return GRIB_OUT_OF_MEMORY; } + size=self->numberOfDescriptors; if( (err = grib_unpack_long(expandedDescriptors,self->expandedDescriptors,&(self->numberOfDescriptors))) != GRIB_SUCCESS) return err; size=self->numberOfDescriptors; - self->abbreviation=(char**)grib_context_malloc_clear(c,size*sizeof(char*)); - err=grib_get_string_array(h,self->abbreviationName,self->abbreviation,&size); - self->type=(char**)grib_context_malloc_clear(c,size*sizeof(char*)); err=grib_get_string_array(h,self->typeName,self->type,&size); - self->names=(char**)grib_context_malloc_clear(c,size*sizeof(char*)); - err=grib_get_string_array(h,self->nameName,self->names,&size); - - self->units=(char**)grib_context_malloc_clear(c,size*sizeof(char*)); - err=grib_get_string_array(h,self->unitName,self->units,&size); - + size=self->numberOfDescriptors; self->reference=grib_context_malloc_clear(c,size*sizeof(long)); err=grib_get_long_array(h,self->referenceName,self->reference,&size); + size=self->numberOfDescriptors; scale=grib_context_malloc_clear(c,size*sizeof(long)); factor=grib_context_malloc_clear(c,size*sizeof(double)); err=grib_get_long_array(h,self->scaleName,scale,&size); for (i=0;iexpandedDescriptors[i]<100000) { grib_context_log(c,GRIB_LOG_FATAL,"Missing table entry for descriptor %ld",self->expandedDescriptors[i]); return GRIB_MISSING_BUFR_ENTRY; } - factor[i]=grib_power(-scale[i],10); + if (scale[i]!=GRIB_MISSING_LONG) factor[i]=grib_power(-scale[i],10); } self->factor=factor; grib_context_free(c,scale); + size=self->numberOfDescriptors; self->width=grib_context_malloc_clear(c,size*sizeof(long)); err=grib_get_long_array(h,self->widthName,self->width,&size); - self->bitmapNumber=grib_context_malloc_clear(c,size*sizeof(long)); - err=grib_get_long_array(h,self->bitmapNumberName,self->bitmapNumber,&size); - - self->associatedBitmapNumber=grib_context_malloc_clear(c,size*sizeof(long)); - err=grib_get_long_array(h,self->associatedBitmapNumberName,self->associatedBitmapNumber,&size); - - self->associatedBitmapIndex=grib_context_malloc_clear(c,size*sizeof(long)); - err=grib_get_long_array(h,self->associatedBitmapIndexName,self->associatedBitmapIndex,&size); - - self->associatedInfoNumber=grib_context_malloc_clear(c,size*sizeof(long)); - err=grib_get_long_array(h,self->associatedInfoNumberName,self->associatedInfoNumber,&size); - err=grib_get_long(h,self->numberOfDataSubsetsName,&(self->numberOfDataSubsets)); + err=grib_get_long(h,self->compressedDataName,&(self->compressedData)); + err=grib_get_long(h,self->subsetNumberName,&(self->subsetNumber)); return err; } +static grib_sarray* decode_string_array(grib_context* c,unsigned char* data,long* pos, int i, + grib_accessor_bufr_data_array* self, + int extraWidth,int extraScale,double referenceFactor,int associatedFieldWidth,int localDescriptorWidth) { + grib_sarray* ret=NULL; + char* sval=0; + int j,modifiedWidth,modifiedReference,width; + double modifiedFactor; + modifiedWidth= extraWidth ? self->width[i]+extraWidth : self->width[i]; + modifiedReference= referenceFactor ? self->reference[i]*referenceFactor : self->reference[i]; + modifiedFactor= extraScale ? self->factor[i]*grib_power(-extraScale,10) : self->factor[i]; -static void push_units_accessor(grib_section* section,grib_accessor* a,long groupNumber,long i) { - char buf[1024]={0,}; - grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; - grib_accessor* gaUnits=0; - grib_action creatorUnits = {0, }; - grib_context* c=a->parent->h->context; - - if (self->units[i][0]=='C' && ( !strcmp(self->units[i],"CCITTIA5") || - !strncmp(self->units[i],"COMMON",6)) ) - return; - if (self->units[i][0]=='N' && !strcmp(self->units[i],"NUMERIC") ) - return; - - creatorUnits.op = "variable"; - creatorUnits.name_space = ""; - creatorUnits.set = 0; - creatorUnits.flags = GRIB_ACCESSOR_FLAG_DUMP; - - sprintf(buf,"%sUnits",self->abbreviation[i]); - creatorUnits.name=buf; - gaUnits = grib_accessor_factory(section, &creatorUnits, 0, NULL); - gaUnits->bufr_group_number=groupNumber; - ((grib_accessor_constant*)gaUnits)->type=GRIB_TYPE_STRING; - - if ((self->units[i][0]=='C' && !strncmp(self->units[i],"CODE",4)) || - ( self->units[i][0]=='F' && !strncmp(self->units[i],"FLAG",4) ) ) { - sprintf(buf,"codetable %ld",self->expandedDescriptors[i]); - ((grib_accessor_constant*)gaUnits)->cval=grib_context_strdup(c,buf); + ret=grib_sarray_new(c,10,10); + sval=grib_context_malloc_clear(c,modifiedWidth/8+1); + grib_decode_string(data,pos,modifiedWidth/8,sval); + width=grib_decode_unsigned_long(data,pos,6); + ret=grib_sarray_new(c,10,10); + if (width) { + grib_context_free(c,sval); + for (j=1;jnumberOfDataSubsets;j++) { + sval=grib_context_malloc_clear(c,width/8+1); + grib_decode_string(data,pos,width/8,sval); + grib_sarray_push(c,ret,sval); + } } else { - ((grib_accessor_constant*)gaUnits)->cval=grib_context_strdup(c,self->units[i]); + grib_sarray_push(c,ret,sval); } - grib_push_accessor(gaUnits,section->block); + return ret; } -static long computeBitmapStartElement(grib_accessor_bufr_data_array* self,long length, grib_iarray* index) { - int i,startIndex; - int idx; +static grib_darray* decode_double_array(grib_context* c,unsigned char* data,long* pos,int i, + grib_accessor_bufr_data_array* self,int canBeMissing, + int extraWidth,int extraScale,double referenceFactor,int associatedFieldWidth,int localDescriptorWidth) { + grib_darray* ret=NULL; + int j; + long lval; + long localReference; + int width,modifiedWidth,modifiedReference; + double modifiedFactor,dval; + modifiedReference= self->reference[i]*referenceFactor; + modifiedFactor= extraScale ? self->factor[i]*grib_power(-extraScale,10) : self->factor[i]; - startIndex=index->n-1; - /* printf("======== BITMAP\n"); */ - for (i=0;iexpandedDescriptors[idx]/100000!=2) { - startIndex--; - /* printf("==> %d %.6ld %s\n",startIndex,self->expandedDescriptors[idx],self->abbreviation[idx]); */ - } + if (localDescriptorWidth) { + modifiedWidth=localDescriptorWidth; + } else { + modifiedWidth= self->width[i]+extraWidth; } +<<<<<<< HEAD + lval=grib_decode_unsigned_long(data,pos,modifiedWidth); + localReference=lval+modifiedReference; + width=grib_decode_unsigned_long(data,pos,6); + ret=grib_darray_new(c,100,100); + if (width) { + for (j=0;jnumberOfDataSubsets;j++) { + lval=grib_decode_unsigned_long(data,pos,width); + if (grib_is_all_bits_one(lval,width) && canBeMissing) { + dval=GRIB_MISSING_DOUBLE; + } else { + dval=(lval+localReference)*modifiedFactor; + } + grib_darray_push(c,ret,dval); +======= startIndex++; return startIndex; } @@ -501,344 +458,241 @@ static GRIB_INLINE void reset_deeper_qualifiers(grib_accessor* significanceQuali for (i=0;idepth) { significanceQualifierGroup[i]=0; +>>>>>>> 25e8f0ed91902a8ccb113de6b71a09ecc73f8e01 } + } else { + if (grib_is_all_bits_one(lval,modifiedWidth) && canBeMissing) { + dval=GRIB_MISSING_DOUBLE; + } else { + dval=localReference*modifiedFactor; + } + grib_darray_push(c,ret,dval); } + /* + switch (width) { + case 0: + if (!grib_is_all_bits_one(lval,modifiedWidth) || self->expandedDescriptors[i]==31031) { + dval=localReference*modifiedFactor; + } else dval=GRIB_MISSING_DOUBLE; + grib_darray_push(c,ret,dval); + break; + case 1: + for (j=0;jnumberOfDataSubsets;j++) { + lval=grib_decode_unsigned_long(data,pos,width); + if (self->expandedDescriptors[i]!=31031 && lval==1) { + dval=GRIB_MISSING_DOUBLE; + } else { + dval=localReference*modifiedFactor; + } + grib_darray_push(c,ret,dval); + } + break; + default : + for (j=0;jnumberOfDataSubsets;j++) { + lval=grib_decode_unsigned_long(data,pos,width); + if (!grib_is_all_bits_one(lval,modifiedWidth)) { + dval=(lval+localReference)*modifiedFactor; + } else { + dval=GRIB_MISSING_DOUBLE; + } + grib_darray_push(c,ret,dval); + } + } + */ + + return ret; } +static int can_be_missing(int F,int X,int Y) { + int ret=1; + if (F==0 && X==31 && Y==31) ret=0; + return ret; +} static int decode_elements(grib_accessor* a) { - int err=0; - grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; - unsigned char* data =NULL; - int forceGroupClosure=0,forceOneLevelClosure=0; - long i=0,k=0,jj=0; - long pos=0; - long localReference=0,width,j; - long totalNumberOfValues,numberOfValuesPerElement; - double* dvalues; - grib_sarray* svalues = NULL; - size_t n,nn; - int *F,*X,*Y; - char* sval; - long lval = 0; - long groupNumber; - int numberOfElementsToRepeat=0,numberOfRepetitions=0; - int startRepetition=0; - int depth; - int bitmapIndex[10]; - long bitmapLength[10]={0,}; - long bitmapStartElement[10]={0,}; - grib_section* section=0; - grib_section* sectionUp=0; - grib_section* groupSection=0; - grib_iarray* index=0; - grib_iarray* bitmap=0; - /* int count; */ - long indexOfReferringElement; - long indexOfGroupNumber; - grib_accessor* gaGroup=0; - grib_action creatorGroup = {0, }; - grib_iarray* groupNumberIndex=0; - grib_section* groupNumberSection[1000]={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,}; + int err=0; + int *F=0,*X=0,*Y=0; + int extraWidth,extraScale=0,associatedFieldWidth=0,localDescriptorWidth=0; + double referenceFactor=1; + int nn; + int numberOfElementsToRepeat=0,numberOfRepetitions=0; + int startRepetition=0; + unsigned char* data=0; + int i,canBeMissing=1; + grib_sarray* sval=0; + grib_darray* dval; + grib_iarray* elementsFXY=0; + long localReference=0,width,pos=0; + int index,sval_size,ii; - grib_handle* h=a->parent->h; - grib_context* c=h->context; + grib_vdarray* dvalues = NULL; + grib_vsarray* svalues = NULL; + grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; - grib_accessor* ga=0; - grib_action creator = {0, }; - creator.op = "bufr_data_element"; - creator.name_space = ""; - creator.flags = GRIB_ACCESSOR_FLAG_DUMP; - creator.set = 0; + grib_handle* h=a->parent->h; + grib_context* c=h->context; - creatorGroup.op = "bufr_group"; - creatorGroup.name="groupNumber"; - creatorGroup.name_space = ""; - creatorGroup.flags = GRIB_ACCESSOR_FLAG_DUMP; - creatorGroup.set = 0; + if (!self->do_decode) return 0; + self->do_decode=0; + a->parent->h->unpacked=1; - data = (unsigned char*)h->buffer->data; - pos=a->offset*8; + data = (unsigned char*)h->buffer->data; + pos=a->offset*8; - for (i=0;i<10;i++) bitmapIndex[i]=-1; + err=get_descriptors(a); + if (err) return err; - err=get_descriptors(a); - if (err) return err; + F=grib_context_malloc_clear(c,sizeof(int)*self->numberOfDescriptors); + X=grib_context_malloc_clear(c,sizeof(int)*self->numberOfDescriptors); + Y=grib_context_malloc_clear(c,sizeof(int)*self->numberOfDescriptors); + for (i=0;inumberOfDescriptors;i++) { + F[i]=self->expandedDescriptors[i]/100000; + X[i]=(self->expandedDescriptors[i]-F[i]*100000)/1000; + Y[i]=(self->expandedDescriptors[i]-F[i]*100000)%1000; + } - index=grib_iarray_new(c,self->numberOfDescriptors,100); - groupNumberIndex=grib_iarray_new(c,self->numberOfDescriptors,100); - bitmap=grib_iarray_new(c,self->numberOfDescriptors,100); + dvalues=grib_vdarray_new(c,100,100); + svalues=grib_vsarray_new(c,10,10); + extraWidth=0; + extraScale=0; + referenceFactor=1; - totalNumberOfValues=self->numberOfDescriptors*self->numberOfDataSubsets; - numberOfValuesPerElement=self->numberOfDataSubsets; - - F=grib_context_malloc_clear(c,sizeof(int)*self->numberOfDescriptors); - X=grib_context_malloc_clear(c,sizeof(int)*self->numberOfDescriptors); - Y=grib_context_malloc_clear(c,sizeof(int)*self->numberOfDescriptors); - for (i=0;inumberOfDescriptors;i++) { - F[i]=self->expandedDescriptors[i]/100000; - X[i]=(self->expandedDescriptors[i]-F[i]*100000)/1000; - Y[i]=(self->expandedDescriptors[i]-F[i]*100000)%1000; - } - - nn=0; - k=-1; - groupNumber=1; - - gaGroup = grib_accessor_factory(a->sub_section, &creatorGroup, 0, NULL); - gaGroup->bufr_group_number=groupNumber; - gaGroup->sub_section=grib_section_create(a->parent->h,gaGroup); - section=gaGroup->sub_section; - sectionUp=a->sub_section; - ((grib_accessor_constant*)gaGroup)->type=GRIB_TYPE_LONG; - ((grib_accessor_constant*)gaGroup)->dval=groupNumber; - grib_push_accessor(gaGroup,a->sub_section->block); - - forceGroupClosure=0; - indexOfGroupNumber=0; - depth=0; - /* count=1; */ - /* printf("=================================\n"); */ - for (i=0;inumberOfDescriptors;i++) { - - if (F[i]==0 && IS_QUALIFIER(X[i]) && self->associatedInfoNumber[i]==0) { - int idx=significanceQualifierIndex(X[i],Y[i]); - groupNumber++; - - if (significanceQualifierGroup[idx]) { - groupSection=significanceQualifierGroup[idx]->parent; - depth=significanceQualifierDepth[idx]; - reset_deeper_qualifiers(significanceQualifierGroup,significanceQualifierDepth,depth); - forceGroupClosure=0; - } else { - if (forceGroupClosure) { - groupSection=sectionUp; - forceGroupClosure=0; - forceOneLevelClosure=1; - depth=0; - } else { - groupSection=section; - depth++; - } + if (self->elementsFXY) grib_viarray_delete(c,self->elementsFXY); + self->elementsFXY=grib_viarray_new(c,100,100); + elementsFXY=grib_iarray_new(c,100,100); + for (i=0;inumberOfDescriptors;i++) { + canBeMissing=can_be_missing(F[i],X[i],Y[i]); + switch(F[i]) { + case 0: + /* Table B element */ + grib_iarray_push(elementsFXY,self->expandedDescriptors[i]); + if (*(self->type[i])=='s') { + /* string */ + sval=decode_string_array(c,data,&pos,i,self,extraWidth,extraScale,referenceFactor,associatedFieldWidth,localDescriptorWidth); + grib_vsarray_push(c,svalues,sval); + index=grib_vsarray_used_size(svalues)-1; + sval_size=grib_sarray_used_size(sval); + dval=grib_darray_new(c,sval_size,10); + for (ii=0;iiv[ii]); + grib_darray_push(c,dval,x); } + grib_vdarray_push(c,dvalues,dval); - gaGroup = grib_accessor_factory(groupSection, &creatorGroup, 0, NULL); - a->parent->h->groups[groupNumber]=gaGroup; - gaGroup->sub_section=grib_section_create(a->parent->h,gaGroup); - gaGroup->bufr_group_number=groupNumber; - ((grib_accessor_constant*)gaGroup)->type=GRIB_TYPE_LONG; - ((grib_accessor_constant*)gaGroup)->dval=groupNumber; - grib_push_accessor(gaGroup,groupSection->block); - - section=gaGroup->sub_section; - sectionUp=gaGroup->parent; - - significanceQualifierGroup[idx]=gaGroup; - significanceQualifierDepth[idx]=depth; - } - - if (F[i]==1) { - /* delayed replication */ - if (! IS_QUALIFIER(X[i-1])) { - forceGroupClosure=1; - reset_qualifiers(significanceQualifierGroup); - } - numberOfElementsToRepeat=X[i]; - nn=numberOfElementsToRepeat; - i++; - localReference=grib_decode_unsigned_long(data,&pos,self->width[i])+self->reference[i]; - width=grib_decode_unsigned_long(data,&pos,6); - if (width) { - /* delayed replication number is not constant. NOT IMPLEMENTED */ - Assert(0); - } else { - numberOfRepetitions=localReference*self->factor[i]; - startRepetition=i; - } - if (self->bitmapNumber[i+1]) { - bitmapLength[self->bitmapNumber[i+1]]=numberOfRepetitions; - bitmapStartElement[self->bitmapNumber[i+1]]=computeBitmapStartElement(self,numberOfRepetitions,index); - } - grib_iarray_push(index,i); - grib_iarray_push(groupNumberIndex,groupNumber); - groupNumberSection[groupNumber]=section; - indexOfGroupNumber=0; - continue; - } - - if (self->bitmapNumber[i]) { - /* bitmap extraction */ - lval=grib_decode_unsigned_long(data,&pos,1); - width=grib_decode_unsigned_long(data,&pos,6); - if (width) {Assert(0);} - - if(bitmapIndex[self->bitmapNumber[i]]==-1) - bitmapIndex[self->bitmapNumber[i]]=grib_iarray_get_used_size(bitmap); - grib_iarray_push(index,i); - grib_iarray_push(groupNumberIndex,groupNumber); - groupNumberSection[groupNumber]=section; - grib_iarray_push(bitmap,lval) ; - k=-1; - jj=0; - } else if (self->associatedBitmapNumber[i]) { - /* bitmap application */ - char name[1024]={0,}; - - if (k==-1) { - k=bitmapIndex[self->associatedBitmapNumber[i]]; - jj=bitmapStartElement[self->associatedBitmapNumber[i]]; - } else { - k++; - } - - indexOfReferringElement=grib_iarray_get(index,jj); - indexOfGroupNumber=grib_iarray_get(groupNumberIndex,jj); - sprintf(name,"%sOf-%s",self->abbreviation[i],self->abbreviation[indexOfReferringElement]); - jj++; - if (grib_iarray_get(bitmap,k)==0) { - creator.name = name; - ga = grib_accessor_factory(section, &creator, 0, NULL); - ga->bufr_group_number=indexOfGroupNumber; - ((grib_accessor_bufr_data_element*)ga)->type=GRIB_TYPE_DOUBLE; - lval=grib_decode_unsigned_long(data,&pos,self->width[indexOfReferringElement]); - localReference=lval+self->reference[indexOfReferringElement]; - width=grib_decode_unsigned_long(data,&pos,6); - if (width) { - ((grib_accessor_bufr_data_element*)ga)->isConstant=0; - n=numberOfValuesPerElement; - } else { - ((grib_accessor_bufr_data_element*)ga)->isConstant=1; - n=1; - } - dvalues=grib_context_malloc_clear(c,sizeof(double)*n); - if (((grib_accessor_bufr_data_element*)ga)->isConstant) { - if (!grib_is_all_bits_one(lval,self->width[indexOfReferringElement])) { - dvalues[0]=localReference*self->factor[indexOfReferringElement]; - } else dvalues[0]=GRIB_MISSING_DOUBLE; - } else { - for (j=0;jfactor[indexOfReferringElement]; - } else dvalues[j]=GRIB_MISSING_DOUBLE; - } - } - ((grib_accessor_bufr_data_element*)ga)->type=GRIB_TYPE_DOUBLE; - ((grib_accessor_bufr_data_element*)ga)->dvalues=dvalues; - ((grib_accessor_bufr_data_element*)ga)->numberOfValues=numberOfValuesPerElement; - - grib_iarray_push(index,i); - grib_iarray_push(groupNumberIndex,ga->bufr_group_number); - grib_push_accessor(ga,groupNumberSection[ga->bufr_group_number]->block); - } else { - i--; - continue; - } } else { - - if (*(self->type[i])=='s') { - svalues=grib_sarray_new(c,numberOfValuesPerElement,100); - sval=grib_context_malloc_clear(c,self->width[i]/8+1); - grib_decode_string(data,&pos,self->width[i]/8,sval); - grib_sarray_push(c,svalues,sval); - } else { - lval=grib_decode_unsigned_long(data,&pos,self->width[i]); - localReference=lval+self->reference[i]; - } - - width=grib_decode_unsigned_long(data,&pos,6); - creator.name = self->abbreviation[i]; - ga = grib_accessor_factory(section, &creator, 0, NULL); - ga->bufr_group_number=groupNumber; - ((grib_accessor_bufr_data_element*)ga)->numberOfValues=numberOfValuesPerElement; - - - if (width) { - ((grib_accessor_bufr_data_element*)ga)->isConstant=0; - n=numberOfValuesPerElement; - } else { - ((grib_accessor_bufr_data_element*)ga)->isConstant=1; - n=1; - } - if (*(self->type[i])=='s') { - /* string element */ - if (!width) { - width=self->width[i]; - n=1; - } - for (j=1;jtype=GRIB_TYPE_STRING; - ((grib_accessor_bufr_data_element*)ga)->svalues=svalues; - } else { - dvalues=grib_context_malloc_clear(c,sizeof(double)*n); - if (((grib_accessor_bufr_data_element*)ga)->isConstant) { - if (!grib_is_all_bits_one(lval,self->width[i])) { - dvalues[0]=localReference*self->factor[i]; - } else dvalues[0]=GRIB_MISSING_DOUBLE; + /* numeric */ + dval=decode_double_array(c,data,&pos,i,self,canBeMissing,extraWidth,extraScale,referenceFactor,associatedFieldWidth,localDescriptorWidth); + grib_vdarray_push(c,dvalues,dval); + } + break; + case 1: + /* Delayed replication */ + numberOfElementsToRepeat=X[i]; + nn=numberOfElementsToRepeat; + i++; + localReference=grib_decode_unsigned_long(data,&pos,self->width[i])+self->reference[i]; + width=grib_decode_unsigned_long(data,&pos,6); + if (width) { + /* delayed replication number is not constant. NOT IMPLEMENTED */ + Assert(0); + } else { + numberOfRepetitions=localReference*self->factor[i]; + startRepetition=i; + } + continue; + case 2: + /* Operator */ + associatedFieldWidth=0; + localDescriptorWidth=0; + switch(X[i]) { + case 1: + extraWidth = Y[i] ? Y[i]-128 : 0; + break; + case 2: + extraScale = Y[i] ? Y[i]-128 : 0; + break; + /* case 4: */ + /* associated field*/ + /* associatedFieldWidth=Y[i]; */ + /* break; */ + case 6: + /*signify data width*/ + localDescriptorWidth=Y[i]; + break; + case 7: + if (Y) { + extraScale = Y[i]; + referenceFactor=grib_power(Y[i],10); + extraWidth=((10*Y[i])+2)/3; } else { - for (j=0;jfactor[i]; - } else dvalues[j]=GRIB_MISSING_DOUBLE; - } + extraWidth=0; + extraScale=0; + referenceFactor=1; } - ((grib_accessor_bufr_data_element*)ga)->type=GRIB_TYPE_DOUBLE; - ((grib_accessor_bufr_data_element*)ga)->dvalues=dvalues; - if (*(self->type[i])=='l') - ((grib_accessor_bufr_data_element*)ga)->type=GRIB_TYPE_LONG; - } - grib_iarray_push(index,i); - grib_iarray_push(groupNumberIndex,groupNumber); - groupNumberSection[groupNumber]=section; - /* printf("==== %s %ld\n",ga->name,ga->bufr_group_number); */ - if (self->associatedInfoNumber[i]) { - grib_section* sectionOfAssociatedGroup=find_section_of_associated_group(groupNumberSection, - bitmapStartElement,groupNumberIndex,self->associatedInfoNumber[i]); - if (!sectionOfAssociatedGroup) sectionOfAssociatedGroup=section; - push_units_accessor(sectionOfAssociatedGroup,a,sectionOfAssociatedGroup->block->first->bufr_group_number,i); - ga->bufr_group_number=sectionOfAssociatedGroup->block->first->bufr_group_number; - grib_push_accessor(ga,sectionOfAssociatedGroup->block); - } else { - push_units_accessor(section,a,groupNumber,i); - grib_push_accessor(ga,section->block); - } - - k=-1; - jj=0; - } - - /* delayed repetition check */ - if (numberOfRepetitions) { - if (nn>1) { - nn--; - } else { - nn=numberOfElementsToRepeat; - numberOfRepetitions--; - if (numberOfRepetitions) i=startRepetition; - } - } - + break; + case 22: + case 23: + case 24: + case 25: + case 26: + case 27: + case 29: + case 30: + case 31: + case 32: + case 33: + case 34: + case 35: + case 36: + case 37: + case 38: + case 39: + case 40: + case 41: + case 42: + grib_iarray_push(elementsFXY,self->expandedDescriptors[i]); + dval=grib_darray_new(c,1,100); + grib_darray_push(c,dval,0); + grib_vdarray_push(c,dvalues,dval); + break; + default : + grib_context_log(c,GRIB_LOG_ERROR,"unsupported operator %d\n",X[i]); + return GRIB_INTERNAL_ERROR; + } + break; + default: + err=GRIB_INTERNAL_ERROR; + return err; } - grib_iarray_delete(index); - grib_iarray_delete(bitmap); - grib_iarray_delete(groupNumberIndex); - grib_context_free(c,F); - grib_context_free(c,X); - grib_context_free(c,Y); - return err; + + /* delayed repetition check */ + if (numberOfRepetitions) { + if (nn>1) { + nn--; + } else { + nn=numberOfElementsToRepeat; + numberOfRepetitions--; + if (numberOfRepetitions) i=startRepetition; + } + } + + } + grib_viarray_push(c,self->elementsFXY,elementsFXY); + + if (self->numericValues) { + grib_vdarray_delete_content(c,dvalues); + grib_vdarray_delete(c,dvalues); + grib_vsarray_delete_content(c,svalues); + grib_vsarray_delete(c,svalues); + } + self->numericValues=dvalues; + self->stringValues=svalues; + return err; } static void dump(grib_accessor* a, grib_dumper* dumper) { - get_elements_and_decode(a); - a->parent->h->unpacked=1; + decode_elements(a); grib_dump_section(dumper,a,a->sub_section->block); @@ -847,38 +701,60 @@ static void dump(grib_accessor* a, grib_dumper* dumper) static int value_count(grib_accessor* a,long* count) { - int err=0; + int err=0,l; + long numberOfSubsets=0,subsetNumber=0; grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; - grib_handle* h=a->parent->h; - err=get_descriptors(a); - if (err) return err; + err=decode_elements(a); + if (err) return err; - grib_get_long(h,self->numberOfDataSubsetsName,&(self->numberOfDataSubsets)); + err=grib_get_long(a->parent->h,self->subsetNumberName,&subsetNumber); + if (err) return err; + + l=grib_vdarray_used_size(self->numericValues); + + *count=l; + if (subsetNumber<=0) { + err=grib_get_long(a->parent->h,self->numberOfDataSubsetsName,&numberOfSubsets); + if (err) return err; + *count *= numberOfSubsets; + } - *count=self->numberOfElements*self->numberOfDataSubsets; return err; } static int unpack_double(grib_accessor* a, double* val, size_t *len) { - int err=0; + int err=0,i,k,ii; + long n=0; + size_t l=0; + long numberOfSubsets=0; + grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; - err=get_elements_and_decode(a); + err=decode_elements(a); if (err) return err; - a->parent->h->unpacked=1; + if (!val) return err; - if (!val) return GRIB_SUCCESS; - else return GRIB_NOT_IMPLEMENTED; -} + l=grib_vdarray_used_size(self->numericValues); + err=grib_get_long(a->parent->h,self->subsetNumberName,&n); + if (err) return err; -static int get_elements_and_decode(grib_accessor* a) { - grib_accessor_bufr_data_array *self =(grib_accessor_bufr_data_array*)a; - int err=0; - if (self->do_compute) { - err=decode_elements(a); - self->do_compute=0; - } - return err; + if (n>0) { + for (i=0;inumericValues->v[i]->n > 1 ? self->numericValues->v[i]->v[n-1] : self->numericValues->v[i]->v[0]; + } + } else { + err=grib_get_long(a->parent->h,self->numberOfDataSubsetsName,&numberOfSubsets); + if (err) return err; + + ii=0; + for (k=0;knumericValues->v[i]->n > 1 ? self->numericValues->v[i]->v[k] : self->numericValues->v[i]->v[0]; + } + } + } + + return GRIB_SUCCESS; } static void destroy(grib_context* c,grib_accessor* a) { diff --git a/src/grib_accessor_class_smart_table.c b/src/grib_accessor_class_smart_table.c index dae324543..67ae79c57 100644 --- a/src/grib_accessor_class_smart_table.c +++ b/src/grib_accessor_class_smart_table.c @@ -27,6 +27,8 @@ MEMBERS = const char* tablename MEMBERS = const char* masterDir MEMBERS = const char* localDir + MEMBERS = const char* extraDir + MEMBERS = const char* extraTable MEMBERS = int widthOfCode MEMBERS = long* tableCodes MEMBERS = size_t tableCodesSize @@ -67,6 +69,8 @@ typedef struct grib_accessor_smart_table { const char* tablename; const char* masterDir; const char* localDir; + const char* extraDir; + const char* extraTable; int widthOfCode; long* tableCodes; size_t tableCodesSize; @@ -181,6 +185,8 @@ static void init(grib_accessor* a, const long len, grib_arguments* params) { self->masterDir = grib_arguments_get_name(a->parent->h,params,n++); self->localDir = grib_arguments_get_name(a->parent->h,params,n++); self->widthOfCode = grib_arguments_get_long(a->parent->h,params,n++); + self->extraDir = grib_arguments_get_name(a->parent->h,params,n++); + self->extraTable = grib_arguments_get_string(a->parent->h,params,n++); a->length = 0; a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY; @@ -202,17 +208,28 @@ static grib_smart_table* load_table(grib_accessor_smart_table* self) char recomposed[1024]={0,}; char localRecomposed[1024]={0,}; char *localFilename=0; + char extraRecomposed[1024]={0,}; + char *extraFilename=0; char localName[1024]={0,}; char masterDir[1024]={0,}; char localDir[1024]={0,}; + char extraDir[1024]={0,}; + char extraTable[1024]={0,}; size_t len=1024; - if (self->masterDir != NULL) + if (self->masterDir != NULL) { grib_get_string(h,self->masterDir,masterDir,&len); + } len=1024; - if (self->localDir != NULL) + 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 (*masterDir!=0) { sprintf(name,"%s/%s",masterDir,self->tablename); @@ -229,6 +246,12 @@ static grib_smart_table* load_table(grib_accessor_smart_table* self) localFilename=grib_context_full_defs_path(c,localRecomposed); } + if (*extraDir!=0) { + sprintf(extraTable,"%s/%s",extraDir,self->extraTable); + grib_recompose_name(h, NULL,extraTable, extraRecomposed,0); + extraFilename=grib_context_full_defs_path(c,extraRecomposed); + } + next=c->smart_table; while(next) { if((filename && next->filename[0] && strcmp(filename,next->filename[0]) == 0) && @@ -249,6 +272,8 @@ static grib_smart_table* load_table(grib_accessor_smart_table* self) if (localFilename!=0) grib_load_smart_table(c,localFilename,localRecomposed,size,t); + if (extraFilename!=0) grib_load_smart_table(c,extraFilename,extraRecomposed,size,t); + if (t->filename[0]==NULL && t->filename[1]==NULL) { grib_context_free_persistent(c,t); return NULL; diff --git a/src/grib_accessor_class_smart_table_column.c b/src/grib_accessor_class_smart_table_column.c index d1cf3ce5b..51421c916 100644 --- a/src/grib_accessor_class_smart_table_column.c +++ b/src/grib_accessor_class_smart_table_column.c @@ -148,6 +148,8 @@ typedef struct grib_accessor_smart_table { const char* tablename; const char* masterDir; const char* localDir; + const char* extraDir; + const char* extraTable; int widthOfCode; long* tableCodes; size_t tableCodesSize; diff --git a/src/grib_api.h b/src/grib_api.h index 6b7677c30..ad5ace19f 100644 --- a/src/grib_api.h +++ b/src/grib_api.h @@ -202,6 +202,9 @@ typedef struct grib_where grib_where; typedef struct grib_sarray grib_sarray; typedef struct grib_darray grib_darray; typedef struct grib_iarray grib_iarray; +typedef struct grib_vdarray grib_vdarray; +typedef struct grib_vsarray grib_vsarray; +typedef struct grib_viarray grib_viarray; grib_fieldset *grib_fieldset_new_from_files(grib_context *c, char *filenames[], int nfiles, char **keys, int nkeys, char *where_string, char *order_by_string, int *err); diff --git a/src/grib_api_internal.h b/src/grib_api_internal.h index 846f727d5..c1690e57a 100644 --- a/src/grib_api_internal.h +++ b/src/grib_api_internal.h @@ -714,6 +714,29 @@ struct grib_iarray { grib_context* context; } ; +struct grib_vdarray { + grib_darray** v; + size_t size; + size_t n; + size_t incsize; + grib_context* context; +} ; + +struct grib_vsarray { + grib_sarray** v; + size_t size; + size_t n; + size_t incsize; + grib_context* context; +} ; + +struct grib_viarray { + grib_iarray** v; + size_t size; + size_t n; + size_t incsize; + grib_context* context; +} ; #define MAX_SET_VALUES 10 #define MAX_ACCESSOR_CACHE 100 diff --git a/src/grib_api_prototypes.h b/src/grib_api_prototypes.h index e2060222c..b96838bd7 100644 --- a/src/grib_api_prototypes.h +++ b/src/grib_api_prototypes.h @@ -150,12 +150,17 @@ grib_darray *grib_darray_new(grib_context *c, size_t size, size_t incsize); grib_darray *grib_darray_resize(grib_context *c, grib_darray *v); grib_darray *grib_darray_push(grib_context *c, grib_darray *v, double val); void grib_darray_delete(grib_context *c, grib_darray *v); +double *grib_darray_get_array(grib_context *c, grib_darray *v); +size_t grib_darray_used_size(grib_darray *v); /* grib_sarray.c */ grib_sarray *grib_sarray_new(grib_context *c, size_t size, size_t incsize); grib_sarray *grib_sarray_resize(grib_context *c, grib_sarray *v); grib_sarray *grib_sarray_push(grib_context *c, grib_sarray *v, char *val); void grib_sarray_delete(grib_context *c, grib_sarray *v); +void grib_sarray_delete_content(grib_context *c, grib_sarray *v); +char **grib_sarray_get_array(grib_context *c, grib_sarray *v); +size_t grib_sarray_used_size(grib_sarray *v); /* grib_iarray.c */ grib_iarray *grib_iarray_new_from_array(grib_context *c, long *a, size_t size); @@ -174,6 +179,33 @@ void grib_iarray_delete_array(grib_iarray *v); long *grib_iarray_get_array(grib_iarray *v); size_t grib_iarray_get_used_size(grib_iarray *v); +/* grib_vdarray.c */ +grib_vdarray *grib_vdarray_new(grib_context *c, size_t size, size_t incsize); +grib_vdarray *grib_vdarray_resize(grib_context *c, grib_vdarray *v); +grib_vdarray *grib_vdarray_push(grib_context *c, grib_vdarray *v, grib_darray *val); +void grib_vdarray_delete(grib_context *c, grib_vdarray *v); +void grib_vdarray_delete_content(grib_context *c, grib_vdarray *v); +grib_darray **grib_vdarray_get_array(grib_context *c, grib_vdarray *v); +size_t grib_vdarray_used_size(grib_vdarray *v); + +/* grib_vsarray.c */ +grib_vsarray *grib_vsarray_new(grib_context *c, size_t size, size_t incsize); +grib_vsarray *grib_vsarray_resize(grib_context *c, grib_vsarray *v); +grib_vsarray *grib_vsarray_push(grib_context *c, grib_vsarray *v, grib_sarray *val); +void grib_vsarray_delete(grib_context *c, grib_vsarray *v); +void grib_vsarray_delete_content(grib_context *c, grib_vsarray *v); +grib_sarray **grib_vsarray_get_array(grib_context *c, grib_vsarray *v); +size_t grib_vsarray_used_size(grib_vsarray *v); + +/* grib_viarray.c */ +grib_viarray *grib_viarray_new(grib_context *c, size_t size, size_t incsize); +grib_viarray *grib_viarray_resize(grib_context *c, grib_viarray *v); +grib_viarray *grib_viarray_push(grib_context *c, grib_viarray *v, grib_iarray *val); +void grib_viarray_delete(grib_context *c, grib_viarray *v); +void grib_viarray_delete_content(grib_context *c, grib_viarray *v); +grib_iarray **grib_viarray_get_array(grib_context *c, grib_viarray *v); +size_t grib_viarray_used_size(grib_viarray *v); + /* grib_accessor_class_array.c */ /* grib_accessor_class_assert.c */ @@ -190,6 +222,8 @@ size_t grib_iarray_get_used_size(grib_iarray *v); /* grib_accessor_class_bufr_data.c */ +/* grib_accessor_class_bufr_data_array.c */ + /* grib_accessor_class_bufr_data_element.c */ /* grib_accessor_class_bufr_group.c */ diff --git a/src/grib_darray.c b/src/grib_darray.c index 2824e72c7..9be66f272 100644 --- a/src/grib_darray.c +++ b/src/grib_darray.c @@ -70,3 +70,13 @@ void grib_darray_delete(grib_context* c,grib_darray* v) { grib_context_free(c,v); } +double* grib_darray_get_array(grib_context* c,grib_darray* v) { + double* ret; + int i; + if (!v) return NULL; + ret=grib_context_malloc_clear(c,sizeof(double)*v->n); + for (i=0;in;i++) ret[i]=v->v[i]; + return ret; +} + +size_t grib_darray_used_size(grib_darray* v) { return v->n;} diff --git a/src/grib_sarray.c b/src/grib_sarray.c index 002aa81f9..21ad1a322 100644 --- a/src/grib_sarray.c +++ b/src/grib_sarray.c @@ -70,3 +70,25 @@ void grib_sarray_delete(grib_context* c,grib_sarray* v) { grib_context_free(c,v); } +void grib_sarray_delete_content(grib_context* c,grib_sarray* v) { + int i; + if (!v | !v->v) return; + if (!c) grib_context_get_default(); + for (i=0;in;i++) { + grib_context_free(c,v->v[i]); + v->v[i]=0; + } + v->n=0; +} + + +char** grib_sarray_get_array(grib_context* c,grib_sarray* v) { + char** ret; + int i; + if (!v) return NULL; + ret=grib_context_malloc_clear(c,sizeof(char*)*v->n); + for (i=0;in;i++) ret[i]=v->v[i]; + return ret; +} + +size_t grib_sarray_used_size(grib_sarray* v) { return v->n;} diff --git a/src/grib_vdarray.c b/src/grib_vdarray.c new file mode 100644 index 000000000..acbde11dc --- /dev/null +++ b/src/grib_vdarray.c @@ -0,0 +1,93 @@ +/* + * Copyright 2005-2014 ECMWF. + * + * This software is licensed under the terms of the Apache Licence Version 2.0 + * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + * + * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by + * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. + */ + +/*************************************************************************** + * + * Enrico Fucile + * + ***************************************************************************/ + +#include "grib_api_internal.h" + +grib_vdarray* grib_vdarray_new(grib_context* c,size_t size,size_t incsize) { + grib_vdarray* v=NULL; + if (!c) c=grib_context_get_default(); + v=(grib_vdarray*)grib_context_malloc_clear(c,sizeof(grib_vdarray)); + if (!v) { + grib_context_log(c,GRIB_LOG_ERROR, + "grib_vdarray_new unable to allocate %d bytes\n",sizeof(grib_vdarray)); + return NULL; + } + v->size=size; + v->n=0; + v->incsize=incsize; + v->v=(grib_darray**)grib_context_malloc_clear(c,sizeof(grib_darray*)*size); + if (!v->v) { + grib_context_log(c,GRIB_LOG_ERROR, + "grib_vdarray_new unable to allocate %d bytes\n",sizeof(grib_darray*)*size); + return NULL; + } + return v; +} + +grib_vdarray* grib_vdarray_resize(grib_context* c,grib_vdarray* v) { + int newsize=v->incsize+v->size; + + if (!c) c=grib_context_get_default(); + + v->v=grib_context_realloc(c,v->v,newsize*sizeof(grib_darray*)); + v->size=newsize; + if (!v->v) { + grib_context_log(c,GRIB_LOG_ERROR, + "grib_vdarray_resize unable to allocate %d bytes\n",sizeof(grib_darray*)*newsize); + return NULL; + } + return v; +} + +grib_vdarray* grib_vdarray_push(grib_context* c,grib_vdarray* v,grib_darray* val) { + size_t start_size=100; + size_t start_incsize=100; + if (!v) v=grib_vdarray_new(c,start_size,start_incsize); + + if (v->n >= v->size) v=grib_vdarray_resize(c,v); + v->v[v->n]=val; + v->n++; + return v; +} + +void grib_vdarray_delete(grib_context* c,grib_vdarray* v) { + if (!v) return; + if (!c) grib_context_get_default(); + if (v->v) grib_context_free(c,v->v); + grib_context_free(c,v); +} + +void grib_vdarray_delete_content(grib_context* c,grib_vdarray* v) { + int i; + if (!v | !v->v) return; + if (!c) grib_context_get_default(); + for (i=0;in;i++) { + grib_darray_delete(c,v->v[i]); + v->v[i]=0; + } + v->n=0; +} + +grib_darray** grib_vdarray_get_array(grib_context* c,grib_vdarray* v) { + grib_darray** ret; + int i; + if (!v) return NULL; + ret=grib_context_malloc_clear(c,sizeof(grib_darray*)*v->n); + for (i=0;in;i++) ret[i]=v->v[i]; + return ret; +} + +size_t grib_vdarray_used_size(grib_vdarray* v) { return v->n;} diff --git a/src/grib_viarray.c b/src/grib_viarray.c new file mode 100644 index 000000000..375213929 --- /dev/null +++ b/src/grib_viarray.c @@ -0,0 +1,93 @@ +/* + * Copyright 2005-2014 ECMWF. + * + * This software is licensed under the terms of the Apache Licence Version 2.0 + * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + * + * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by + * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. + */ + +/*************************************************************************** + * + * Enrico Fucile + * + ***************************************************************************/ + +#include "grib_api_internal.h" + +grib_viarray* grib_viarray_new(grib_context* c,size_t size,size_t incsize) { + grib_viarray* v=NULL; + if (!c) c=grib_context_get_default(); + v=(grib_viarray*)grib_context_malloc_clear(c,sizeof(grib_viarray)); + if (!v) { + grib_context_log(c,GRIB_LOG_ERROR, + "grib_viarray_new unable to allocate %d bytes\n",sizeof(grib_viarray)); + return NULL; + } + v->size=size; + v->n=0; + v->incsize=incsize; + v->v=(grib_iarray**)grib_context_malloc_clear(c,sizeof(grib_iarray*)*size); + if (!v->v) { + grib_context_log(c,GRIB_LOG_ERROR, + "grib_viarray_new unable to allocate %d bytes\n",sizeof(grib_iarray*)*size); + return NULL; + } + return v; +} + +grib_viarray* grib_viarray_resize(grib_context* c,grib_viarray* v) { + int newsize=v->incsize+v->size; + + if (!c) c=grib_context_get_default(); + + v->v=grib_context_realloc(c,v->v,newsize*sizeof(grib_iarray*)); + v->size=newsize; + if (!v->v) { + grib_context_log(c,GRIB_LOG_ERROR, + "grib_viarray_resize unable to allocate %d bytes\n",sizeof(grib_iarray*)*newsize); + return NULL; + } + return v; +} + +grib_viarray* grib_viarray_push(grib_context* c,grib_viarray* v,grib_iarray* val) { + size_t start_size=100; + size_t start_incsize=100; + if (!v) v=grib_viarray_new(c,start_size,start_incsize); + + if (v->n >= v->size) v=grib_viarray_resize(c,v); + v->v[v->n]=val; + v->n++; + return v; +} + +void grib_viarray_delete(grib_context* c,grib_viarray* v) { + if (!v) return; + if (!c) grib_context_get_default(); + if (v->v) grib_context_free(c,v->v); + grib_context_free(c,v); +} + +void grib_viarray_delete_content(grib_context* c,grib_viarray* v) { + int i; + if (!v | !v->v) return; + if (!c) grib_context_get_default(); + for (i=0;in;i++) { + grib_iarray_delete(v->v[i]); + v->v[i]=0; + } + v->n=0; +} + +grib_iarray** grib_viarray_get_array(grib_context* c,grib_viarray* v) { + grib_iarray** ret; + int i; + if (!v) return NULL; + ret=grib_context_malloc_clear(c,sizeof(grib_iarray*)*v->n); + for (i=0;in;i++) ret[i]=v->v[i]; + return ret; +} + +size_t grib_viarray_used_size(grib_viarray* v) { return v->n;} diff --git a/src/grib_vsarray.c b/src/grib_vsarray.c new file mode 100644 index 000000000..c55a2f3c0 --- /dev/null +++ b/src/grib_vsarray.c @@ -0,0 +1,94 @@ +/* + * Copyright 2005-2014 ECMWF. + * + * This software is licensed under the terms of the Apache Licence Version 2.0 + * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + * + * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by + * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. + */ + +/*************************************************************************** + * + * Enrico Fucile + * + ***************************************************************************/ + +#include "grib_api_internal.h" + +grib_vsarray* grib_vsarray_new(grib_context* c,size_t size,size_t incsize) { + grib_vsarray* v=NULL; + if (!c) c=grib_context_get_default(); + v=(grib_vsarray*)grib_context_malloc_clear(c,sizeof(grib_vsarray)); + if (!v) { + grib_context_log(c,GRIB_LOG_ERROR, + "grib_vsarray_new unable to allocate %d bytes\n",sizeof(grib_vsarray)); + return NULL; + } + v->size=size; + v->n=0; + v->incsize=incsize; + v->v=(grib_sarray**)grib_context_malloc_clear(c,sizeof(grib_sarray*)*size); + if (!v->v) { + grib_context_log(c,GRIB_LOG_ERROR, + "grib_vsarray_new unable to allocate %d bytes\n",sizeof(grib_sarray*)*size); + return NULL; + } + return v; +} + +grib_vsarray* grib_vsarray_resize(grib_context* c,grib_vsarray* v) { + int newsize=v->incsize+v->size; + + if (!c) c=grib_context_get_default(); + + v->v=grib_context_realloc(c,v->v,newsize*sizeof(grib_sarray*)); + v->size=newsize; + if (!v->v) { + grib_context_log(c,GRIB_LOG_ERROR, + "grib_vsarray_resize unable to allocate %d bytes\n",sizeof(grib_sarray*)*newsize); + return NULL; + } + return v; +} + +grib_vsarray* grib_vsarray_push(grib_context* c,grib_vsarray* v,grib_sarray* val) { + size_t start_size=100; + size_t start_incsize=100; + if (!v) v=grib_vsarray_new(c,start_size,start_incsize); + + if (v->n >= v->size) v=grib_vsarray_resize(c,v); + v->v[v->n]=val; + v->n++; + return v; +} + +void grib_vsarray_delete(grib_context* c,grib_vsarray* v) { + if (!v) return; + if (!c) grib_context_get_default(); + if (v->v) grib_context_free(c,v->v); + grib_context_free(c,v); +} + +void grib_vsarray_delete_content(grib_context* c,grib_vsarray* v) { + int i; + if (!v | !v->v) return; + if (!c) grib_context_get_default(); + for (i=0;in;i++) { + grib_sarray_delete_content(c,v->v[i]); + grib_sarray_delete(c,v->v[i]); + v->v[i]=0; + } + v->n=0; +} + +grib_sarray** grib_vsarray_get_array(grib_context* c,grib_vsarray* v) { + grib_sarray** ret; + int i; + if (!v) return NULL; + ret=grib_context_malloc_clear(c,sizeof(grib_sarray*)*v->n); + for (i=0;in;i++) ret[i]=v->v[i]; + return ret; +} + +size_t grib_vsarray_used_size(grib_vsarray* v) { return v->n;} diff --git a/tests/Makefile.am b/tests/Makefile.am index 2bee06442..6e8a9eed1 100755 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -9,7 +9,7 @@ TESTS = definitions.sh \ bitmap.sh list.sh second_order.sh \ multi_from_message.sh change_scanning.sh \ julian.sh statistics.sh tigge.sh tigge_conversions.sh \ - read_any.sh padding.sh lamb_az_eq_area.sh grib_to_netcdf.sh bufr_dump.sh debug.sh $(JPEG_TEST) + read_any.sh padding.sh lamb_az_eq_area.sh grib_to_netcdf.sh bufrdc_ref.sh bufr_dump.sh debug.sh $(JPEG_TEST) noinst_PROGRAMS = packing_check gauss_sub read_any double_cmp packing pack_unpack \ multi_from_message julian read_index index gribex_perf\ diff --git a/tests/bufrdc_ref.sh b/tests/bufrdc_ref.sh new file mode 100755 index 000000000..a447fbf50 --- /dev/null +++ b/tests/bufrdc_ref.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# Copyright 2005-2014 ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# +# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by +# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. +# + + +. ./include.sh + +REDIRECT=/dev/null + +cat > bufrdc_ref.filter< $REDIRECT > $file.test + + numdiff $file.ref $file.test + + +done +