noritada / grib-rs

GRIB format parser for Rust
Apache License 2.0
56 stars 9 forks source link

Iterating submessages produces incorrect message sizes. #37

Closed LafeWessel closed 1 year ago

LafeWessel commented 1 year ago

Simple Description on the Bug

When iterating through submessages, the size indicated by submessage.indicator() is constant whereas iterating through the sections shows different sizes for each submessage.

Steps to Reproduce

fn test_read_grib_file() {
    let f = std::fs::File::open(GRIB_TEST_FILE).unwrap();
    let rd = std::io::BufReader::new(f);
    let gr = grib::from_reader(rd).unwrap();

    // NOTE the submessage sizes indicated by the Section0 sections
    for s in gr.sections() {
        println!("{:?}", s);
    }

    // set up decoder
    for lyr in gr.iter() {
        let ((i, j), fm) = lyr;
        println!(
            "{}, {}\n{}\n{:?}\n{:?}\n{:?}\n{:?}\n{:?}",
            i,
            j,
            fm.describe(),
            // NOTE the submessage sizes indicated by indicator()
            fm.indicator(),
            fm.grid_def(),
            fm.prod_def(),
            fm.grid_def(),
            fm.repr_def()
        );
    }
}

Expected Behavior

submessage.indicator() shows the proper size of the message.

Actual Behavior

A constant size is shown for all submessages.

Additional Context

I used the GRIB file found here.

noritada commented 1 year ago

@LafeWessel Thank you very much for always catching and reporting bugs. I appreciate it.

The code was left over from the days when the data was processed with the assumption that only one message was read.

It was easy to fix, but I didn't write a test and am sorry for the delay.