NOAA-EMC / NCEPLIBS-g2c

This library contains C decoder/encoder routines for GRIB edition 2.
Other
18 stars 11 forks source link

A better way to handle GRIB codes? #282

Open edwardhartnett opened 2 years ago

edwardhartnett commented 2 years ago

Here we can find XML versions of the GRIB codes: https://community.wmo.int/activity-areas/wis/latest-version

Here's a sample:

    <GRIB2_CodeFlag_en>
        <Title_en>Code table 0.0 - Discipline of processed data in the GRIB message, number of GRIB Master table</Title_en>
        <CodeFlag>0</CodeFlag>
        <MeaningParameterDescription_en>Meteorological products</MeaningParameterDescription_en>
        <Status>Operational</Status>
    </GRIB2_CodeFlag_en>
    <GRIB2_CodeFlag_en>
        <Title_en>Code table 0.0 - Discipline of processed data in the GRIB message, number of GRIB Master table</Title_en>
        <CodeFlag>1</CodeFlag>
        <MeaningParameterDescription_en>Hydrological products</MeaningParameterDescription_en>
        <Status>Operational</Status>
    </GRIB2_CodeFlag_en>
    <GRIB2_CodeFlag_en>
        <Title_en>Code table 0.0 - Discipline of processed data in the GRIB message, number of GRIB Master table</Title_en>
        <CodeFlag>2</CodeFlag>
        <MeaningParameterDescription_en>Land surface products</MeaningParameterDescription_en>
        <Status>Operational</Status>
    </GRIB2_CodeFlag_en>

So we can download these XML files (there are 2 for GRIB2) in the repo. Then we can find and use an XML parser library. Then g2c could read the XML and serve up all the code information. This would be very helpful for g2c, and for other applications using g2c.

In a further refactor, the g2tmpl project could just call the g2c library to get the codes, instead of maintaining them in Fortran code.

One problem is that we seem to have also defined our own "keys" which have to be maintained as well. I'm not sure yet how to cope with that.

The advantage is that we could use the WMO XML files directly, getting their updates and changes whenever they make them, automatically.

We would also still have to support any local codes as well.

@BoiVuong-NOAA @Hang-Lei-NOAA any comments on this idea?

BoiVuong-NOAA commented 2 years ago

This is good idea to use XML files in the repo. But, I do not know how UPP code use the g2tmpl lib in GFS, NAM, RRFS, and UFS models. You need to check with developers.

edwardhartnett commented 2 years ago

g2tmpl users will not see any change.

After ingesting the codes into g2c, the g2tmpl Fortran functions can be changed to get their results from the g2c library.

Users of g2tmpl would not see any difference, but the codes would move to the C library and be served from there to any other software that needs them, including g2tmpl.

BoiVuong-NOAA commented 2 years ago

That is great.

DusanJovic-NOAA commented 2 years ago

I do not like the fact that this requires external library to parse xml files. I think this just adds unnecessary complexity. Why do we need to read xml files instead of equivalent text files.

edwardhartnett commented 2 years ago

What equivalent text files?

DusanJovic-NOAA commented 2 years ago

These two, available from the same place the xml files are available from (WMO).

Template.txt

CodeFlag.txt

edwardhartnett commented 2 years ago

Those links take me to a sharepoint site for which I do not have permissions. Are these documents on the web?

edwardhartnett commented 2 years ago

I see the text versions are available here: https://wmoomm.sharepoint.com/sites/wmocpdb/eve_activityarea/Forms/AllItems.aspx?id=%2Fsites%2Fwmocpdb%2Feve%5Factivityarea%2FWMO%20Codes%2FWMO306%5FvI2%2FAllVERSIONS%2F2022%2D05%2D15%2FGRIB2%2D29%2E1&p=true&ga=1

I will ponder...

DusanJovic-NOAA commented 2 years ago

Or here: https://github.com/wmo-im/GRIB2/tree/master/txt

edwardhartnett commented 5 months ago

This is related to #345