Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

final round of 8-byte index changes #704

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/g2getgb2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ subroutine getgb2r2(lugb, idxver, cindex, gfld, iret)
character(len=1):: csize(4)
character(len=1), allocatable :: ctemp(:)
real, pointer, dimension(:) :: newfld
integer :: n, j, iskip, iofst, ilen, ierr, idum
integer :: n, j, iofst, ilen, ierr, idum
integer (kind = 8) :: lskip8, lread8, ilen8, iskip8
! Bytes to skip in (version 1 and 2) index record to get to bms.
integer :: IXBMS1, IXBMS2
Expand Down Expand Up @@ -944,11 +944,10 @@ end subroutine g2_gbytec81
skip68 = skip6
else
call g2_gbytec81(cindex, skip68, IXBMS2 * INT1_BITS, INT8_BITS)
skip6 = int(skip68, kind(4))
endif

#ifdef LOGGING
write(g2_log_msg, *) ' getgb2r2: skip6', skip6
write(g2_log_msg, *) ' getgb2r2: skip68', skip68
call g2_log(1)
#endif

Expand All @@ -967,8 +966,7 @@ end subroutine g2_gbytec81

! Read and unpack bit_map, if present.
if (gfld%ibmap .eq. 0 .or. gfld%ibmap .eq. 254) then
iskip = lskip + skip6
iskip8 = lskip8 + skip6
iskip8 = lskip8 + skip68

! Get length of bitmap section.
call bareadl(lugb, iskip8, 4_8, lread8, csize)
Expand Down Expand Up @@ -996,7 +994,6 @@ end subroutine g2_gbytec81
endif

! Read and unpack data field.
iskip = lskip + skip7
iskip8 = lskip8 + skip7

! Get length of data section.
Expand Down Expand Up @@ -1216,7 +1213,6 @@ end subroutine g2_gbytec81
inc = 28
call g2_gbytec81(cindex, iskip8, mypos, INT8_BITS) ! bytes to skip in file
mypos = mypos + INT8_BITS
iskip = int(iskip8, kind(4))
call g2_gbytec81(cindex, iskp2_8, mypos, INT8_BITS) ! bytes to skip for section 2
mypos = mypos + INT8_BITS

Expand Down Expand Up @@ -1286,23 +1282,23 @@ end subroutine g2_gbytec81
! Read the location of section 7 from the index.
if (idxver .eq. 1) then
call g2_gbytec1(cindex, iskp7, IXDS1 * INT1_BITS, INT4_BITS) ! bytes to skip for section 7
iskp78 = iskp7
else
call g2_gbytec81(cindex, iskp78, IXDS2 * INT1_BITS, INT8_BITS) ! bytes to skip for section 7
iskp7 = int(iskp78, kind(4))
endif
#ifdef LOGGING
write(g2_log_msg, *) 'getgb2rp2: iskp7', iskp7, 'IXDS2', IXDS2
write(g2_log_msg, *) 'getgb2rp2: iskp78', iskp78, 'IXDS2', IXDS2
call g2_log(2)
#endif

! Read in the length of section 7 from the data file.
call bareadl(lugb, iskip8 + iskp7, 4_8, lread8, ctemp)
call bareadl(lugb, iskip8 + iskp78, 4_8, lread8, ctemp)
call g2_gbytec1(ctemp, len7, 0, INT4_BITS) ! length of section 7

! Now read in section 7.
allocate(csec7(len7))
len7_8 = len7
call bareadl(lugb, iskip8 + iskp7, len7_8, lread8, csec7)
call bareadl(lugb, iskip8 + iskp78, len7_8, lread8, csec7)

#ifdef LOGGING
write(g2_log_msg, *) 'getgb2rp2: len0 ', len0, 'len1', len1, 'len2', len2 , 'len3', len3
Expand Down
38 changes: 3 additions & 35 deletions src/g2index.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ subroutine ix2gb2(lugb, lskip8, idxver, lgrib8, cbuf, numfld, mlen, iret)
character cver, cdisc
character(len = 4) :: ctemp
integer (kind = 8) :: loclus8, locgds8, locbms8
integer locgds, loclus, locbms
integer locbms
integer :: indbmp, numsec, newsize, g2_mova2i, mbuf, lindex
integer :: lskip
integer :: ilndrs, ilnpds, istat
Expand Down Expand Up @@ -1351,7 +1351,6 @@ end subroutine g2_sbytec1
! Initialize values and allocate buffer (at the user-provided cbuf
! pointer) where the index data will be written. When subroutine is
! complete, cbuf will hold either version 1 or 2 index data.
loclus = 0
loclus8 = 0
iret = 0
mlen = 0
Expand Down Expand Up @@ -1425,7 +1424,6 @@ end subroutine g2_sbytec1
if (numsec .eq. 2) then
! Save the location of the local use section in the message.
loclus8 = ibskip8 - lskip8
loclus = int(ibskip8 - lskip8, kind(4))
elseif (numsec .eq. 3) then
! For the GDS section, read the whole section into the cgds
! buffer.
Expand All @@ -1437,7 +1435,6 @@ end subroutine g2_sbytec1
return
endif
! Remember the GDS location in the message.
locgds = int(ibskip8 - lskip8, kind(4))
locgds8 = ibskip8 - lskip8
elseif (numsec .eq. 4) then
! Having found the PDS, we write the beginning of the index
Expand All @@ -1456,35 +1453,27 @@ end subroutine g2_sbytec1
inc = 0
lskip = int(lskip8, kind(4))
call g2_sbytec1(cindex, lskip, mypos, INT4_BITS) ! bytes to skip
!print '(i3, a7, i4)', mypos/8, ' lskip ', lskip, mypos
mypos = mypos + INT4_BITS
call g2_sbytec1(cindex, loclus, mypos, INT4_BITS) ! location of local use
!print '(i3, a8, i4)', mypos/8, ' loclus ', loclus
call g2_sbytec1(cindex, int(loclus8, kind(4)), mypos, INT4_BITS) ! location of local use
mypos = mypos + INT4_BITS
call g2_sbytec1(cindex, locgds, mypos, INT4_BITS) ! location of gds
!print '(i3, a8, i4)', mypos/8, ' locgds ', locgds
call g2_sbytec1(cindex, int(locgds8, kind(4)), mypos, INT4_BITS) ! location of gds
mypos = mypos + INT4_BITS
call g2_sbytec1(cindex, int(ibskip8 - lskip8, kind(4)), mypos, INT4_BITS) ! location of pds
#ifdef LOGGING
write(g2_log_msg, *) ' writing pds location to index: mypos/8 ', mypos/8, &
' loc ', int(ibskip8 - lskip8, kind(4))
call g2_log(4)
#endif
!print '(i3, a8, i4)', mypos/8, ' locpds ', int(ibskip8 - lskip8, kind(4))
mypos = mypos + INT4_BITS * 4 ! skip ahead in cbuf
else
inc = 28
call g2_sbytec81(cindex, lskip8, mypos, INT8_BITS) ! bytes to skip
!print '(i3, a7, i4)', mypos/8, ' lskip ', lskip
mypos = mypos + INT8_BITS
call g2_sbytec81(cindex, loclus8, mypos, INT8_BITS) ! location of local use
!print '(i3, a8, i4)', mypos/8, ' loclus ', loclus
mypos = mypos + INT8_BITS
call g2_sbytec81(cindex, locgds8, mypos, INT8_BITS) ! location of gds
!print '(i3, a8, i4)', mypos/8, ' locgds ', locgds
mypos = mypos + INT8_BITS
call g2_sbytec81(cindex, ibskip8 - lskip8, mypos, INT8_BITS) ! location of pds
!print '(i3, a8, i4)', mypos/8, ' locpds ', int(ibskip8 - lskip8, kind(4))
mypos = mypos + INT8_BITS * 4 ! skip ahead in cbuf
endif

Expand All @@ -1495,34 +1484,21 @@ end subroutine g2_sbytec1
! These ints are the same size in index version 1 and 2. The
! mypos variable contains the proper offset, which is
call g2_sbytec81(cindex, lgrib8, mypos, INT8_BITS) ! length of grib2
!print '(i3, a8, i4)', mypos/8, ' lgrib8 ', lgrib8
mypos = mypos + INT8_BITS
cindex((mypos / 8) + 1) = cver
!print '(i3, a6, z1)', mypos/8, ' cver ', cver
mypos = mypos + INT1_BITS
cindex((mypos / 8) + 1) = cdisc
!print '(i3, a7, z2)', mypos/8, ' cdisc ', cdisc
mypos = mypos + INT1_BITS
call g2_sbytec1(cindex, numfld + 1, mypos, INT2_BITS) ! field num
!print '(i3, a8, i4)', mypos/8, ' numfld ', numfld + 1
mypos = mypos + INT2_BITS

! Copy the section 1 values into the cindex buffer.
cindex(IXIDS + 1 + inc:IXIDS + lensec1 + inc) = cids(1:lensec1)
lindex = IXIDS + lensec1 + inc
! print *, 'section 1:', IXIDS + inc, IXIDS + lensec1 + inc
! do i=1, lensec1
! print *, i, ichar(cids(i))
! end do

! Copy the GDS values into the cindex buffer.
cindex(lindex + 1:lindex + lengds8) = cgds(1:lengds8)
!print *, 'gds:', lindex, lindex + lengds8
lindex = lindex + int(lengds8, kind(lindex))
! print *, 'gds:', lindex, lengds8
! do i=1, lengds8
! print *, i, ichar(cgds(i))
! end do

! Now read the PDS values from the file directly into cindex.
ilnpds = lensec
Expand All @@ -1532,7 +1508,6 @@ end subroutine g2_sbytec1
iret = 2
return
endif
!print *, 'pds:', lindex, lindex + ilnpds
lindex = lindex + ilnpds
mypos = mypos + ilnpds
#ifdef LOGGING
Expand All @@ -1552,7 +1527,6 @@ end subroutine g2_sbytec1
else
call g2_sbytec81(cindex, ibskip8 - lskip8, IXDRS2 * INT1_BITS, INT8_BITS) ! location of drs
endif
!print '(i3, a8, i5)', mypos/8, ' locdrs ', int(ibskip8 - lskip8, kind(4))

! Read the DRS section directly into the cindex buffer.
ilndrs = lensec
Expand All @@ -1562,7 +1536,6 @@ end subroutine g2_sbytec1
iret = 2
return
endif
!print *, 'drs:', lindex, lindex + ilndrs
lindex = lindex + ilndrs
elseif (numsec .eq. 6) then
! Write the location of the BMS section in the message into
Expand Down Expand Up @@ -1601,16 +1574,11 @@ end subroutine g2_sbytec1

! Copy 6 bytes of the BMS from data buffer to the cindex buffer.
cindex(lindex + 1:lindex + MXBMS) = cbread(1:MXBMS)
! print *, 'bms:', lindex, lindex + MXBMS
! do i=1, MXBMS
! print *, i, ichar(cindex(lindex + i))
! end do
lindex = lindex + MXBMS

! The size of the index record is now known, so write it to
! the cindex buffer.
call g2_sbytec1(cindex, lindex, 0, INT4_BITS) ! num bytes in index record
!print '(i3, a8, i5)', 0, ' lindex ', lindex
elseif (numsec .eq. 7) then ! found data section

#ifdef LOGGING
Expand Down
Loading