##############################
# reopen the BUFR file as test
##############################

print('*'*50)

input_bufr_file = output_bufr_file
bufr = BUFRReader(input_bufr_file, warn_about_bufr_size=False)
bufr.setup_tables(table_b_to_use='B'+table_name,
                  table_d_to_use='D'+table_name)

for msg in bufr:
    print('num_subsets = ', msg.get_num_subsets())
    for subs, msg_or_subset_data in enumerate(msg):
        list_of_names = msg_or_subset_data.names
        list_of_units = msg_or_subset_data.units
        data = msg_or_subset_data.data
        print('"subset nr"'+','+','.join(list_of_names))
        print('""'+','+','.join(list_of_units))
        print(str(subs+1)+','+','.join(str(val) for val in data[:]))

bufr.close()

# NOTE:
# currently, decoding data with delayed repetation does not work
# as expected for default ECMWF library bufrex decoding.
# ECMWF has not implemented this in its library.
# The ECMWF library does have a special (workaround) routine called
# buget_opera_image to handle this kind of data.
# This one is accessible in the low level pybufr_ecmwf.ecmwfbufr module,
Exemple #2
0
# open the file for writing
bf1.open(output_bufr_file, 'wb')
# write the encoded BUFR message
bf1.write_raw_bufr_msg(bufr.encoded_message)
# close the file
bf1.close()

##############################
# reopen the BUFR file as test
##############################

print('*' * 50)

input_bufr_file = output_bufr_file
bufr = BUFRReader(input_bufr_file, warn_about_bufr_size=False)
bufr.setup_tables(table_b_to_use='B' + table_name,
                  table_d_to_use='D' + table_name)

# just 1 msg in this test file, so no looping needed
for msg in bufr:
    print('num_subsets = ', msg.get_num_subsets())
    for subs, msg_or_subset_data in enumerate(msg):
        list_of_names = msg_or_subset_data.names
        list_of_units = msg_or_subset_data.units
        data = msg_or_subset_data.data
        print('"subset nr"' + ',' + ','.join(list_of_names))
        print('""' + ',' + ','.join(list_of_units))
        print(str(subs + 1) + ',' + ','.join(str(val) for val in data[:]))

bufr.close()