grib-rs icon indicating copy to clipboard operation
grib-rs copied to clipboard

consider making SubMessage.identification into a pub fn

Open ejd opened this issue 1 year ago • 0 comments

Motivation

It would be very useful to have access to the SubMessage::identification method. I'd like to use Identification.ref_time in a program I'm writing. I want to compute the absolute time of a submessage by adding the submessage's forecast_time to the ref_time.

Proposed Solution

Change the signature of SubMessage::identification from fn identification(&self) -> &Identification to pub fn identification(&self) -> &Identification.

Additional Context

I'm using grib-rs to extract weather data from grib files published by NOAA. The program uses grib-rs to load a subset of the files produced by a forecast model run. Once loaded, the program allows the user to retrieve weather at arbitrary points inside the data cube (indexed by time, lat, lon, and altitude) using interpolation. I need the ref_time to know the time of validity for the submessage's data.

Currently, I'm doing something like this to get ref_time:

let f = File::open(path_to_grib_file)?;
let r = BufReader::new(f);
let g = grib::from_reader(r)?;

for (_index, submessage) in g.iter() {
    let ref_time = if let Some(SectionBody::Section1(id)) = &submessage.1.body.body {
        id.ref_time()?
    } else {
        continue;
    };

    ...
}

ejd avatar Dec 04 '24 19:12 ejd