From 853cba4070318cc00085a3ee70e83c61e660be21 Mon Sep 17 00:00:00 2001 From: Edward Hartnett <38856240+edwardhartnett@users.noreply.github.com> Date: Thu, 9 May 2024 22:55:56 -0600 Subject: [PATCH] converted some index values to 8-byte (#660) * changing some values to 8-byte ints * fixed doxygen * more work * removed no-range-check flag for gfortran * constant type * fixed constants * removed doxygen * more fixes * more progress * more progress * more progress * cache refresh * more fixes * more progress * changed grib_utils workflow to use branch ejh_fix * fixes * more * more progress * more progress --- .github/workflows/Linux_options.yml | 2 +- .github/workflows/Linux_shared.yml | 2 +- .github/workflows/Linux_versions.yml | 2 +- .github/workflows/developer.yml | 2 +- .github/workflows/grib_utils.yml | 2 +- src/g2getgb2.F90 | 40 ++++++++++++------ src/g2index.F90 | 30 ++++++++----- ..._gdaswave.t00z.wcoast.0p16.f000.grb2index2 | Bin 4038 -> 4190 bytes tests/test_create_index.F90 | 4 +- tests/test_create_index_fv3.F90 | 5 ++- tests/test_create_index_gdas.F90 | 5 ++- tests/test_create_index_seaice.F90 | 5 ++- tests/test_g1.F90 | 31 +++++++++----- tests/test_getidx.F90 | 32 ++++++++++---- 14 files changed, 110 insertions(+), 52 deletions(-) diff --git a/.github/workflows/Linux_options.yml b/.github/workflows/Linux_options.yml index 85d78ba8..33eb692d 100644 --- a/.github/workflows/Linux_options.yml +++ b/.github/workflows/Linux_options.yml @@ -147,7 +147,7 @@ jobs: uses: actions/cache@v3 with: path: ~/data - key: data-4 + key: data-5 - name: build run: | diff --git a/.github/workflows/Linux_shared.yml b/.github/workflows/Linux_shared.yml index 8916a353..720550bb 100644 --- a/.github/workflows/Linux_shared.yml +++ b/.github/workflows/Linux_shared.yml @@ -147,7 +147,7 @@ jobs: uses: actions/cache@v3 with: path: ~/data - key: data-4 + key: data-5 - name: build run: | diff --git a/.github/workflows/Linux_versions.yml b/.github/workflows/Linux_versions.yml index 33c2f5f7..a0bf1e42 100644 --- a/.github/workflows/Linux_versions.yml +++ b/.github/workflows/Linux_versions.yml @@ -139,7 +139,7 @@ jobs: uses: actions/cache@v3 with: path: ~/data - key: data-4 + key: data-5 - name: build run: | diff --git a/.github/workflows/developer.yml b/.github/workflows/developer.yml index 2df9d26c..4df37c1d 100644 --- a/.github/workflows/developer.yml +++ b/.github/workflows/developer.yml @@ -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' diff --git a/.github/workflows/grib_utils.yml b/.github/workflows/grib_utils.yml index 4a6a1621..c02e88b1 100644 --- a/.github/workflows/grib_utils.yml +++ b/.github/workflows/grib_utils.yml @@ -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: diff --git a/src/g2getgb2.F90 b/src/g2getgb2.F90 index 6f8b4703..b1fbf05e 100644 --- a/src/g2getgb2.F90 +++ b/src/g2getgb2.F90 @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/g2index.F90 b/src/g2index.F90 index 4f16fba8..703cbb83 100644 --- a/src/g2index.F90 +++ b/src/g2index.F90 @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 @@ -1305,6 +1308,7 @@ 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 @@ -1312,14 +1316,18 @@ subroutine ix2gb2(lugb, lskip8, idxver, lgrib8, cbuf, numfld, mlen, iret) 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 @@ -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 diff --git a/tests/ref_gdaswave.t00z.wcoast.0p16.f000.grb2index2 b/tests/ref_gdaswave.t00z.wcoast.0p16.f000.grb2index2 index 1d4ffbce527c156079e92cfe18a9e268c10e1cdf..e3578578089391703f7bf2ddca227de52db4269c 100644 GIT binary patch delta 390 zcmX>me@|h8G_R?yfw_W#p_PHDm4V4b4MzbJ10xFsC@{2CP?%V&A_(GgF)%P(0b($i zxa>41lw&<@;xe_#GZ>e`1g3C;1X7sb0+*B~E>oXu$h<@lqJ@$71k9Yt_m~eu^)Z@N zf%KhVf$3vRSpyQ7!U`8y{ud;Wz_t`-(D65LgZS9t27Pw`Df__=)5oM{01`OD0T&3^ z0uq?O2{VYPo8N?hi9d1w_FU%n3 VxvxRWBKTkiF@Kp35>Vk^1OOa&WOV=l delta 360 zcmcboa7=!JG_SF)k%5Atk(IH5m5Jp<4M!1U3v)9CC@{2CP$)`Gi=SAj!pgQU=a~MxX9esV38LHkuTFH I&*MJ;0Il<2j{pDw diff --git a/tests/test_create_index.F90 b/tests/test_create_index.F90 index b45025f4..dff05b6a 100644 --- a/tests/test_create_index.F90 +++ b/tests/test_create_index.F90 @@ -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 diff --git a/tests/test_create_index_fv3.F90 b/tests/test_create_index_fv3.F90 index 00aaac71..cce4b866 100644 --- a/tests/test_create_index_fv3.F90 +++ b/tests/test_create_index_fv3.F90 @@ -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. diff --git a/tests/test_create_index_gdas.F90 b/tests/test_create_index_gdas.F90 index 8c42f4b6..324c2dc8 100644 --- a/tests/test_create_index_gdas.F90 +++ b/tests/test_create_index_gdas.F90 @@ -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 diff --git a/tests/test_create_index_seaice.F90 b/tests/test_create_index_seaice.F90 index 1b7d8ba9..ef8e0a24 100644 --- a/tests/test_create_index_seaice.F90 +++ b/tests/test_create_index_seaice.F90 @@ -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 diff --git a/tests/test_g1.F90 b/tests/test_g1.F90 index 493db6dd..e5be964f 100644 --- a/tests/test_g1.F90 +++ b/tests/test_g1.F90 @@ -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 @@ -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) @@ -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 @@ -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 diff --git a/tests/test_getidx.F90 b/tests/test_getidx.F90 index 5d0db320..a65f0541 100644 --- a/tests/test_getidx.F90 +++ b/tests/test_getidx.F90 @@ -21,6 +21,7 @@ program test_getidx 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 (kind = 8) :: b2s_lus8, b2s_gds8 integer :: total_bytes, grib_version, discipline, field_number, i, idxver integer (kind = 8) :: b2s_message8 @@ -67,7 +68,10 @@ end subroutine getidx2 if (i .eq. 1) then if (nlen .ne. 137600) stop 22 else - if (nlen .ne. 140352) stop 23 + if (nlen .ne. 145856) then + print *, nlen + stop 23 + endif endif ! Break out the index record into component values and check them for correctness. @@ -77,24 +81,34 @@ 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) + call g2_gbytec(cbuf, b2s_message, mypos, INT4_BITS) ! msg length if (b2s_message .ne. 202) stop 31 mypos = mypos + INT4_BITS b2s_message8 = b2s_message + call g2_gbytec(cbuf, b2s_lus, mypos, INT4_BITS) ! skip to local + if (b2s_lus .ne. 0) stop 33 + mypos = mypos + INT4_BITS + call g2_gbytec(cbuf, b2s_gds, mypos, INT4_BITS) + mypos = mypos + INT4_BITS else - call g2_gbytec8(cbuf, b2s_message8, mypos, INT8_BITS) + call g2_gbytec8(cbuf, b2s_message8, mypos, INT8_BITS) ! msg length if (b2s_message8 .ne. 202) stop 32 mypos = mypos + INT8_BITS + call g2_gbytec8(cbuf, b2s_lus8, mypos, INT8_BITS) ! skip to local + if (b2s_lus8 .ne. 0) stop 33 + mypos = mypos + INT8_BITS + b2s_lus = int(b2s_lus8, kind(4)) + call g2_gbytec8(cbuf, b2s_gds8, mypos, INT8_BITS) + mypos = mypos + INT8_BITS + b2s_gds = int(b2s_gds8, kind(4)) 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 call g2_gbytec(cbuf, b2s_pds, mypos, INT4_BITS) if (b2s_pds .ne. 109) stop 35 mypos = mypos + INT4_BITS