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

converted some index values to 8-byte #660

Merged
merged 25 commits into from
May 10, 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
2 changes: 1 addition & 1 deletion .github/workflows/Linux_options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ jobs:
uses: actions/cache@v3
with:
path: ~/data
key: data-4
key: data-5

- name: build
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Linux_shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ jobs:
uses: actions/cache@v3
with:
path: ~/data
key: data-4
key: data-5

- name: build
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Linux_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ jobs:
uses: actions/cache@v3
with:
path: ~/data
key: data-4
key: data-5

- name: build
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/developer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
uses: actions/cache@v4
with:
path: ~/data
key: data-developer-1
key: data-developer-2

- name: asan
if: matrix.config == 'asan/code coverage'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/grib_utils.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

strategy:
matrix:
grib_util-branch: [develop]
grib_util-branch: [ejh_fix]
jasper-version: [2.0.33, 3.0.5, 4.0.0]

steps:
Expand Down
40 changes: 27 additions & 13 deletions src/g2getgb2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ subroutine getgb2l2(lugb, idxver, cindex, gfld, iret)
integer, intent(out) :: iret

integer :: lskip, skip2
integer (kind = 8) :: lskip8, iskip8, lread8, ilen8
integer (kind = 8) :: lskip8, iskip8, lread8, ilen8, skip28
character(len = 1):: csize(4)
character(len = 1), allocatable :: ctemp(:)
integer :: ilen, iofst, ierr
Expand All @@ -379,20 +379,30 @@ end subroutine gf_unpack2
! Get info.
nullify(gfld%local)
iret = 0
mypos = INT4_BITS
mypos = INT4_BITS ! Skip length of index record.

! These are all 4-byte ints in index format 1, and 8-byte ints in
! index version 2.
if (idxver .eq. 1) then
! Read bytes to skip in file before message.
call g2_gbytec(cindex, lskip, mypos, INT4_BITS)
mypos = mypos + INT4_BITS
lskip8 = lskip
! Read bytes to skip in msg before local use.
call g2_gbytec(cindex, skip2, mypos, INT4_BITS)
skip28 = skip2
else
! Read bytes to skip in file before message.
call g2_gbytec8(cindex, lskip8, mypos, INT8_BITS)
mypos = mypos + INT8_BITS
! Read bytes to skip in msg before local use.
call g2_gbytec8(cindex, skip28, mypos, INT8_BITS)
mypos = mypos + INT8_BITS
endif
call g2_gbytec(cindex, skip2, mypos, INT4_BITS)

! Read and unpack local use section, if present.
if (skip2 .ne. 0) then
iskip8 = lskip8 + skip2
if (skip28 .ne. 0) then
iskip8 = lskip8 + skip28

! Get length of section.
call bareadl(lugb, iskip8, 4_8, lread8, csize)
Expand Down Expand Up @@ -811,7 +821,7 @@ end subroutine gf_unpack7
call g2_gbytec(cindex, lskip, INT4_BITS, INT4_BITS)
lskip8 = lskip
else
inc = 4
inc = 12
call g2_gbytec8(cindex, lskip8, INT4_BITS, INT8_BITS)
lskip = int(lskip8, kind(4))
endif
Expand Down Expand Up @@ -999,6 +1009,7 @@ subroutine getgb2rp2(lugb, idxver, cindex, extract, gribm, leng, iret)
integer :: lencur, len0, ibmap = 0, ipos, iskip
integer :: len7 = 0, len8 = 0, len3 = 0, len4 = 0, len5 = 0, len6 = 0, len1 = 0, len2 = 0
integer :: iskp2, iskp6, iskp7
integer (kind = 8) :: iskp2_8
integer :: INT1_BITS, INT2_BITS, INT4_BITS, INT8_BITS
parameter(INT1_BITS = 8, INT2_BITS = 16, INT4_BITS = 32, INT8_BITS = 64)
integer :: mypos, inc = 0
Expand All @@ -1015,20 +1026,23 @@ subroutine getgb2rp2(lugb, idxver, cindex, extract, gribm, leng, iret)
call g2_gbytec(cindex, iskip, mypos, INT4_BITS) ! bytes to skip in file
mypos = mypos + INT4_BITS
iskip8 = iskip
call g2_gbytec(cindex, iskp2, mypos, INT4_BITS) ! bytes to skip for section 2
mypos = mypos + INT4_BITS
iskp2_8 = iskp2
else
inc = 4
inc = 12
call g2_gbytec8(cindex, iskip8, mypos, INT8_BITS) ! bytes to skip in file
mypos = mypos + INT8_BITS
iskip = int(iskip8, kind(4))
call g2_gbytec8(cindex, iskp2_8, mypos, INT8_BITS) ! bytes to skip for section 2
mypos = mypos + INT8_BITS
endif
call g2_gbytec(cindex, iskp2, mypos, INT4_BITS) ! bytes to skip for section 2
mypos = mypos + INT4_BITS
if (iskp2 .gt. 0) then
call bareadl(lugb, iskip8 + iskp2, 4_8, lread8, ctemp)
if (iskp2_8 .gt. 0) then
call bareadl(lugb, iskip8 + iskp2_8, 4_8, lread8, ctemp)
call g2_gbytec(ctemp, len2, 0, INT4_BITS) ! length of section 2
allocate(csec2(len2))
len2_8 = len2
call bareadl(lugb, iskip8 + iskp2, len2_8, lread8, csec2)
call bareadl(lugb, iskip8 + iskp2_8, len2_8, lread8, csec2)
else
len2 = 0
endif
Expand Down Expand Up @@ -1090,7 +1104,7 @@ subroutine getgb2rp2(lugb, idxver, cindex, extract, gribm, leng, iret)
ipos = 44 + inc + len1

! Copy Section 2, if necessary
if (iskp2 .gt. 0) then
if (iskp2_8 .gt. 0) then
gribm(lencur + 1:lencur + len2) = csec2(1:len2)
lencur = lencur + len2
endif
Expand Down
30 changes: 19 additions & 11 deletions src/g2index.F90
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ end subroutine ix2gb2
lgrib4 = int(lgrib, kind(4))
call ix2gb2(lugb, lskip, idxver, lgrib, cbuftmp, numfld, nbytes, iret1)
if (iret1 .ne. 0) print *, ' SAGT ', numfld, nbytes, iret1
if((nbytes + nlen) .gt. mbuf) then ! Allocate more space, if necessary.
if (nbytes + nlen .gt. mbuf) then ! Allocate more space, if necessary.
newsize = max(mbuf + next, mbuf + nbytes)
call realloc(cbuf, nlen, newsize, istat)
if (istat .ne. 0) then
Expand Down Expand Up @@ -964,13 +964,13 @@ end subroutine gf_unpack5
if (idxver .eq. 1) then
inc = 0
else
! Add the extra 4 bytes in the version 2 index record, starting
! Add the extra 8 bytes in the version 2 index record, starting
! at byte 9.
inc = 4
inc = 12
endif

! Search for request.
do while(iret .ne. 0 .and. k .lt. nnum)
do while (iret .ne. 0 .and. k .lt. nnum)
k = k + 1
! Get length of current index record.
call g2_gbytec(cbuf, inlen, ipos * 8, 4 * 8)
Expand Down Expand Up @@ -1221,7 +1221,8 @@ subroutine ix2gb2(lugb, lskip8, idxver, lgrib8, cbuf, numfld, mlen, iret)

character cver, cdisc
character(len = 4) :: ctemp
integer loclus, locgds, locbms
integer (kind = 8) :: loclus8, locgds8
integer locgds, locbms, loclus
integer :: indbmp, numsec, next, newsize, g2_mova2i, mbuf, lindex
integer :: linmax, ixskp
integer :: mxspd, mxskp, mxsgd, mxsdr, mxsbm, mxlus
Expand All @@ -1248,10 +1249,11 @@ subroutine ix2gb2(lugb, lskip8, idxver, lgrib8, cbuf, numfld, mlen, iret)
else
! Add the extra 4 bytes in the version 2 index record, starting
! at byte 9.
inc = 4
inc = 12
endif

loclus = 0
loclus8 = 0
iret = 0
mlen = 0
numfld = 0
Expand Down Expand Up @@ -1295,6 +1297,7 @@ subroutine ix2gb2(lugb, lskip8, idxver, lgrib8, cbuf, numfld, mlen, iret)
call g2_gbytec(cbread, numsec, INT4_BITS, INT1_BITS)

if (numsec .eq. 2) then ! save local use location
loclus8 = ibskip8 - lskip8
loclus = int(ibskip8 - lskip8, kind(4))
elseif (numsec .eq. 3) then ! save gds info
lengds8 = lensec
Expand All @@ -1305,21 +1308,26 @@ subroutine ix2gb2(lugb, lskip8, idxver, lgrib8, cbuf, numfld, mlen, iret)
return
endif
locgds = int(ibskip8 - lskip8, kind(4))
locgds8 = ibskip8 - lskip8
elseif (numsec .eq. 4) then ! found pds
cindex = char(0)
mypos = INT4_BITS
if (idxver .eq. 1) then
lskip = int(lskip8, kind(4))
call g2_sbytec(cindex, lskip, mypos, INT4_BITS) ! bytes to skip
mypos = mypos + INT4_BITS
call g2_sbytec(cindex, loclus, mypos, INT4_BITS) ! location of local use
mypos = mypos + INT4_BITS
call g2_sbytec(cindex, locgds, mypos, INT4_BITS) ! location of gds
mypos = mypos + INT4_BITS
else
call g2_sbytec8(cindex, lskip8, mypos, INT8_BITS) ! bytes to skip
mypos = mypos + INT8_BITS
call g2_sbytec8(cindex, loclus8, mypos, INT8_BITS) ! location of local use
mypos = mypos + INT8_BITS
call g2_sbytec8(cindex, locgds8, mypos, INT8_BITS) ! location of gds
mypos = mypos + INT8_BITS
endif
call g2_sbytec(cindex, loclus, mypos, INT4_BITS) ! location of local use
mypos = mypos + INT4_BITS
call g2_sbytec(cindex, locgds, mypos, INT4_BITS) ! location of gds
mypos = mypos + INT4_BITS
call g2_sbytec(cindex, int(ibskip8 - lskip8, kind(4)), mypos, INT4_BITS) ! location of pds
mypos = mypos + INT4_BITS * 4 ! skip ahead in cbuf
call g2_sbytec8(cindex, lgrib8, mypos, INT8_BITS) ! len of grib2
Expand Down Expand Up @@ -1371,7 +1379,7 @@ subroutine ix2gb2(lugb, lskip8, idxver, lgrib8, cbuf, numfld, mlen, iret)
mypos = (ixds + inc) * INT1_BITS
call g2_sbytec(cindex, int(ibskip8 - lskip8, kind(4)), mypos, INT4_BITS) ! loc. of data sec.
numfld = numfld + 1
if ((lindex + mlen) .gt. mbuf) then ! allocate more space if necessary
if (lindex + mlen .gt. mbuf) then ! allocate more space if necessary
newsize = max(mbuf + next, mbuf + lindex)
call realloc(cbuf, mlen, newsize, istat)
if (istat .ne. 0) then
Expand Down
Binary file modified tests/ref_gdaswave.t00z.wcoast.0p16.f000.grb2index2
Binary file not shown.
4 changes: 3 additions & 1 deletion tests/test_create_index.F90
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ end subroutine g2_create_index
!print *, myidxver, nlen, nnum, iret
if (myidxver .ne. idxver) stop 79
if (idxver .eq. 1) then
print *, nlen
if (nlen .ne. 3800) stop 80
else
if (nlen .ne. 3876) stop 80
print *, nlen
if (nlen .ne. 4028) stop 80
endif
if (nnum .ne. 19 .or. iret .ne. 0) stop 81

Expand Down
5 changes: 4 additions & 1 deletion tests/test_create_index_fv3.F90
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ end subroutine g2_create_index
! Read the index file.
call getg2i2(lugi, cbuf, myidxver, nlen, nnum, iret)
print *, myidxver, nlen, nnum, iret
if (nlen .ne. 259722) stop 80
if (nlen .ne. 268370) then
print *, nlen
stop 80
endif
if (nnum .ne. 1081 .or. iret .ne. 0) stop 81

! Close the index file.
Expand Down
5 changes: 4 additions & 1 deletion tests/test_create_index_gdas.F90
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ end subroutine g2_create_index
if (idxver .eq. 1) then
if (nlen .ne. 452) stop 80
else
if (nlen .ne. 460) stop 80
if (nlen .ne. 476) then
print *, nlen
stop 80
endif
endif
if (nnum .ne. 2 .or. iret .ne. 0) stop 81

Expand Down
5 changes: 4 additions & 1 deletion tests/test_create_index_seaice.F90
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ end subroutine g2_create_index
if (idxver .eq. 1) then
if (nlen .ne. 200) stop 80
else
if (nlen .ne. 204) stop 81
if (nlen .ne. 212) then
print *, nlen
stop 81
endif
endif
if (nnum .ne. 1 .or. iret .ne. 0) stop 83

Expand Down
31 changes: 21 additions & 10 deletions tests/test_g1.F90
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ program test_g1
character(len=1), pointer, dimension(:) :: cbuf(:)
integer :: lugb = 3
integer :: nlen, nnum, iret
integer :: index_rec_len, b2s_message, b2s_lus, b2s_gds, b2s_pds, b2s_drs, b2s_bms, b2s_data
integer :: index_rec_len, b2s_message, b2s_gds, b2s_pds, b2s_drs, b2s_bms, b2s_data, b2s_lus
integer (kind = 8) :: b2s_lus8, b2s_gds8
integer :: total_bytes, grib_version, discipline, field_number, i, idxver
integer (kind = 8) :: b2s_message8

Expand Down Expand Up @@ -56,7 +57,8 @@ end subroutine getidx2
if (i .eq. 1) then
if (nlen .ne. 200) stop 22
else
if (nlen .ne. 204) stop 23
print *, nlen
if (nlen .ne. 212) stop 23
endif
! do j = 1, nlen
! print '(i3, x, z2.2)', j, cbuf(j)
Expand All @@ -69,24 +71,33 @@ end subroutine getidx2
if (i .eq. 1) then
if (index_rec_len .ne. 200) stop 30
else
if (index_rec_len .ne. 204) stop 30
if (index_rec_len .ne. 212) then
print *, index_rec_len
stop 30
endif
endif
if (i .eq. 1) then
call g2_gbytec(cbuf, b2s_message, mypos, INT4_BITS)
if (b2s_message .ne. 0) stop 31
mypos = mypos + INT4_BITS
b2s_message8 = b2s_message
call g2_gbytec(cbuf, b2s_lus, mypos, INT4_BITS)
mypos = mypos + INT4_BITS
b2s_lus8 = b2s_lus
call g2_gbytec(cbuf, b2s_gds, mypos, INT4_BITS)
mypos = mypos + INT4_BITS
b2s_gds8 = b2s_gds
else
call g2_gbytec8(cbuf, b2s_message8, mypos, INT8_BITS)
if (b2s_message8 .ne. 0) stop 32
mypos = mypos + INT8_BITS
call g2_gbytec8(cbuf, b2s_lus8, mypos, INT8_BITS)
mypos = mypos + INT8_BITS
call g2_gbytec8(cbuf, b2s_gds8, mypos, INT8_BITS)
mypos = mypos + INT8_BITS
endif
call g2_gbytec(cbuf, b2s_lus, mypos, INT4_BITS)
if (b2s_lus .ne. 0) stop 33
mypos = mypos + INT4_BITS
call g2_gbytec(cbuf, b2s_gds, mypos, INT4_BITS)
if (b2s_gds .ne. 37) stop 34
mypos = mypos + INT4_BITS
if (b2s_lus8 .ne. 0) stop 33
if (b2s_gds8 .ne. 37) stop 34
call g2_gbytec(cbuf, b2s_pds, mypos, INT4_BITS)
if (b2s_pds .ne. 109) stop 35
mypos = mypos + INT4_BITS
Expand Down Expand Up @@ -115,7 +126,7 @@ end subroutine getidx2
call g2_gbytec(cbuf, field_number, mypos, INT2_BITS)
if (field_number .ne. 1) stop 42
print *, 'index_rec_len = ', index_rec_len, ' b2s_message8 = ', b2s_message8
print *, 'b2s_lus, b2s_gds, b2s_pds, b2s_drs, b2s_bms, b2s_data: ', b2s_lus, b2s_gds, b2s_pds, b2s_drs, b2s_bms, b2s_data
print *, 'b2s_lus8, b2s_gds8, b2s_pds, b2s_drs, b2s_bms, b2s_data: ', b2s_lus8, b2s_gds8, b2s_pds, b2s_drs, b2s_bms, b2s_data
print *, 'total_bytes, grib_version, discipline, field_number: ', total_bytes, grib_version, discipline, field_number

! Clean up. Call gf_finalize or else index will be found in
Expand Down
Loading
Loading