Skip to content

update ungrib to handle files larger than 2GB - #3

Merged
guoqing-noaa merged 1 commit into
NOAA-GSL:rrfsfrom
guoqing-noaa:64bits
Apr 7, 2026
Merged

update ungrib to handle files larger than 2GB#3
guoqing-noaa merged 1 commit into
NOAA-GSL:rrfsfrom
guoqing-noaa:64bits

Conversation

@guoqing-noaa

@guoqing-noaa guoqing-noaa commented Apr 6, 2026

Copy link
Copy Markdown
Collaborator
  1. Update byte offset variables (start/newpos in C, IB/JB in Fortran, iseek/lskip/KS in callers) to use 64-bit
  2. Byte count variables (NB/lgrib/no/size/nactual) remain 32-bit, assuming individual GRIB messages are under 2GB
  3. Use long long C type to match Fortran's INTEGER(KIND=8)
  4. Chang seekret from int to off_t (matches lseek() return type)

Tested both situations with files smaller than or larger than 2GB and the new ungrib.x generates identical intermediate binary files.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to enable ungrib to process GRIB2 files larger than 2GB by widening seek/skip offsets to 64-bit and updating the underlying BACIO C/Fortran interface to support large file offsets.

Changes:

  • Switch GRIB2 reader seek/skip variables (lskip, iseek) to 64-bit integers.
  • Update BACIO Fortran and C interfaces to pass 64-bit start/newpos offsets and use 64-bit file offsets in lseek.
  • Update GRIB message scanning (SKGB) to use 64-bit seek/skip arithmetic.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ungrib/src/rd_grib2.F Uses 64-bit lskip/iseek to avoid overflow when scanning large GRIB2 files.
ungrib/src/g2print.F Mirrors the 64-bit lskip/iseek changes for the GRIB2 printing utility.
ungrib/src/ngl/w3/baciof.f Changes BACIO Fortran wrappers (e.g., BAREAD/BAWRITE) to use 64-bit offsets when calling into C.
ungrib/src/ngl/w3/bacio.v1.3.c Updates ba_cio/banio to accept 64-bit offsets and uses 64-bit off_t/lseek.
ungrib/src/ngl/g2/skgb.f Updates GRIB scan routine to use 64-bit ISEEK/LSKIP and avoids 32-bit offset overflow.
Comments suppressed due to low confidence (1)

ungrib/src/ngl/g2/skgb.f:46

  • SKGB now declares dummy args ISEEK and LSKIP as INTEGER(KIND=8). Several existing callers in this repo (e.g., ungrib/src/ngl/w3/getgir.f and ungrib/src/ngl/g2/getg2ir.f) pass implicitly-typed variables (ISEEK default INTEGER, LSKIP implicit REAL), so this changes the calling ABI and will cause incorrect argument interpretation at runtime. Please update all SKGB call sites (and their declarations) to use consistent INTEGER(KIND=8) types for ISEEK/LSKIP, or provide a separate SKGB64 wrapper / explicit interface (module or INTERFACE block) so mismatches are caught at compile time.
      INTEGER(KIND=8) :: ISEEK, LSKIP, KS, KS2
C - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      LGRIB=0
      KS=ISEEK
      KN=MIN(LSEEK,MSEEK)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ungrib/src/ngl/w3/baciof.f
Comment thread ungrib/src/ngl/w3/baciof.f

@EricJames-NOAA EricJames-NOAA left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks for your work on this.

@guoqing-noaa
guoqing-noaa merged commit 0f5497f into NOAA-GSL:rrfs Apr 7, 2026
4 checks passed
@guoqing-noaa
guoqing-noaa deleted the 64bits branch April 7, 2026 18:53
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.

3 participants