Skip to content

Feature/add grib#10

Merged
koldunovn merged 5 commits intomainfrom
feature/add-grib
Feb 8, 2026
Merged

Feature/add grib#10
koldunovn merged 5 commits intomainfrom
feature/add-grib

Conversation

@sebastianbeyer
Copy link
Collaborator

Add support for reading grib files. Requires eccodes as additional dependency.
I hope I got it correct with mapping the variables/levels etc. to depth, but the destine data that I used for testing works.

This is the ampcode thread where the work was done:
https://ampcode.com/threads/T-019c39ce-9bad-76bb-806b-42a4701c39de

  Root cause

  The multifile code path in ushow.c only checked for Zarr, then fell through to NetCDF — never checking for GRIB files. And file_grib.c had no fileset functions.

  src/file_grib.h — Added fileset function declarations

  - grib_open_fileset(), grib_open_glob(), grib_fileset_map_time(), grib_read_slice_fileset(), grib_fileset_total_times(), grib_get_dim_info_fileset(), grib_close_fileset(),
  grib_read_timeseries_fileset()

  src/file_grib.c — Implemented fileset functions

  - grib_open_fileset: Opens multiple GRIB files, sorts by name, counts unique time values in each file to build time_offsets
  - grib_open_glob: Expands glob pattern, delegates to grib_open_fileset
  - grib_read_slice_fileset: Maps virtual time to (file_idx, local_time), lazily scans variables for non-first files, then reads the correct slice
  - grib_get_dim_info_fileset: Returns concatenated time values across all files
  - grib_read_timeseries_fileset: Reads and concatenates time series across files
  - Uses a lazy variable scanning pattern — variables for non-first files are scanned on first access using the shared mesh

  src/ushow.c — Updated dispatch in 7 locations

  1. File opening: Added GRIB detection for both glob patterns and explicit multiple files (checks grib_is_grib_file() on first matched file)
  2. Dim info dispatch (2 places): GRIB fileset → grib_get_dim_info_fileset()
  3. Timeseries dispatch: GRIB fileset → grib_read_timeseries_fileset()
  4. Error cleanup (2 places): Added GRIB fileset handling
  5. Final cleanup: grib_close_fileset() for GRIB filesets
  6. Fixed pre-existing bug: FILE_TYPE_GRIB used outside #ifdef HAVE_GRIB guards

  src/view.c — Updated read dispatch

  - Added GRIB fileset check before single-file GRIB check in view_update()
@koldunovn
Copy link
Collaborator

  • Added multi file support, now you can use ./uterm --delay 100 -r 0.5 /pool/data/ERA5/E1/sf/fc/1M/159/E1sf12_1M_*_159.grb
  • Add support for compilation on DKRZ with spack, that has more or less recent eccodes (2.44.0, and the latest version is 2.45.0).

@koldunovn
Copy link
Collaborator

Thanks a lot, Sebastian, merging!

@koldunovn koldunovn merged commit 4d4fdff into main Feb 8, 2026
1 check passed
@sebastianbeyer sebastianbeyer deleted the feature/add-grib branch February 20, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants