From 2ab01dd3a558f4c1870022fc78ec1e9a2ec56d29 Mon Sep 17 00:00:00 2001 From: Edward Hartnett <38856240+edwardhartnett@users.noreply.github.com> Date: Fri, 17 May 2024 07:59:51 +0200 Subject: [PATCH 1/2] no more large ftp testing for memcheck workflow, adding interface statements (#688) * no more large ftp testing for memcheck workflow * interface work * more interface work * more interface work --- .github/workflows/developer.yml | 5 -- .github/workflows/memcheck.yml | 4 +- CMakeLists.txt | 2 +- src/g2bytes.F90 | 86 +++++++++++++++++++++++++++++++++ src/g2get.F90 | 18 +++++-- src/g2getgb2.F90 | 22 +++++++-- src/g2index.F90 | 43 +++++++++++------ tests/g2_test_util.F90 | 12 ++--- tests/test_getgb2p_2.F90 | 5 +- 9 files changed, 153 insertions(+), 44 deletions(-) diff --git a/.github/workflows/developer.yml b/.github/workflows/developer.yml index 791a7277..12a5f6fd 100644 --- a/.github/workflows/developer.yml +++ b/.github/workflows/developer.yml @@ -13,11 +13,6 @@ on: branches: - develop -# Cancel in-progress workflows when pushing to a branch -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - jobs: developer: runs-on: ubuntu-latest diff --git a/.github/workflows/memcheck.yml b/.github/workflows/memcheck.yml index 9adf9566..6e7e2624 100644 --- a/.github/workflows/memcheck.yml +++ b/.github/workflows/memcheck.yml @@ -97,14 +97,14 @@ jobs: uses: actions/cache@v4 with: path: ~/data - key: data-developer-4 + key: data-memcheck-1 - name: memcheck run: | cd g2 mkdir build cd build - cmake -DFTP_LARGE_TEST_FILES=ON -DJasper_ROOT=~/Jasper -DCMAKE_PREFIX_PATH="~/bacio;~/w3emc" -DCMAKE_Fortran_FLAGS="-g -O0" -DCMAKE_C_FLAGS="-g -O0" -DFTP_TEST_FILES=ON -DTEST_FILE_DIR=/home/runner/data -DCMAKE_BUILD_TYPE=Debug .. + cmake -DJasper_ROOT=~/Jasper -DCMAKE_PREFIX_PATH="~/bacio;~/w3emc" -DCMAKE_Fortran_FLAGS="-g -O0" -DCMAKE_C_FLAGS="-g -O0" -DFTP_TEST_FILES=ON -DTEST_FILE_DIR=/home/runner/data -DCMAKE_BUILD_TYPE=Debug .. make -j2 VERBOSE=1 - name: test_memcheck diff --git a/CMakeLists.txt b/CMakeLists.txt index cf91a7ab..368ae6f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,7 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$") set(CMAKE_C_FLAGS "-g ${CMAKE_C_FLAGS}") set(CMAKE_C_FLAGS_DEBUG "-ggdb -Wall") set(CMAKE_Fortran_FLAGS "-g -funroll-loops ${CMAKE_Fortran_FLAGS}") - set(CMAKE_Fortran_FLAGS_DEBUG "-ggdb -Wall") + set(CMAKE_Fortran_FLAGS_DEBUG "-ggdb -Wall -Wimplicit-interface") set(fortran_d_flags "-fdefault-real-8") endif() diff --git a/src/g2bytes.F90 b/src/g2bytes.F90 index 5aa73e58..0f954829 100644 --- a/src/g2bytes.F90 +++ b/src/g2bytes.F90 @@ -23,6 +23,15 @@ subroutine g2_gbytec(in, iout, iskip, nbits) character*1, intent(in) :: in(*) integer, intent(inout) :: iout(*) integer, intent(in) :: iskip, nbits + + interface + subroutine g2_gbytesc(in, iout, iskip, nbits, nskip, n) + character*1, intent(in) :: in(*) + integer, intent(out) :: iout(*) + integer, intent(in) :: iskip, nbits, nskip, n + end subroutine g2_gbytesc + end interface + call g2_gbytesc(in, iout, iskip, nbits, 0, 1) end subroutine g2_gbytec @@ -46,6 +55,14 @@ subroutine g2_gbytec1(in, siout, iskip, nbits) integer, intent(inout) :: siout integer, intent(in) :: iskip, nbits integer (kind = 4) :: iout(1) + + interface + subroutine g2_gbytesc(in, iout, iskip, nbits, nskip, n) + character*1, intent(in) :: in(*) + integer, intent(out) :: iout(*) + integer, intent(in) :: iskip, nbits, nskip, n + end subroutine g2_gbytesc + end interface call g2_gbytesc(in, iout, iskip, nbits, 0, 1) siout = iout(1) @@ -71,6 +88,14 @@ subroutine g2_gbytescr(in, rout, iskip, nbits, nskip, n) integer, intent(in) :: iskip, nbits, nskip, n integer (kind = 4) :: iout(n) + interface + subroutine g2_gbytesc(in, iout, iskip, nbits, nskip, n) + character*1, intent(in) :: in(*) + integer, intent(out) :: iout(*) + integer, intent(in) :: iskip, nbits, nskip, n + end subroutine g2_gbytesc + end interface + ! Unpack into integer array. call g2_gbytesc(in, iout, iskip, nbits, nskip, n) @@ -154,6 +179,15 @@ subroutine g2_gbytec8(in, iout, iskip, nbits) character*1, intent(in) :: in(*) integer (kind = 8), intent(inout) :: iout(*) integer, intent(in) :: iskip, nbits + + interface + subroutine g2_gbytesc8(in, iout, iskip, nbits, nskip, n) + character*1, intent(in) :: in(*) + integer (kind = 8), intent(out) :: iout(*) + integer, intent(in) :: iskip, nbits, nskip, n + end subroutine g2_gbytesc8 + end interface + call g2_gbytesc8(in, iout, iskip, nbits, 0, 1) end subroutine g2_gbytec8 @@ -177,6 +211,14 @@ subroutine g2_gbytec81(in, siout, iskip, nbits) integer (kind = 8), intent(inout) :: siout integer, intent(in) :: iskip, nbits integer (kind = 8) :: iout(1) + + interface + subroutine g2_gbytesc8(in, iout, iskip, nbits, nskip, n) + character*1, intent(in) :: in(*) + integer (kind = 8), intent(out) :: iout(*) + integer, intent(in) :: iskip, nbits, nskip, n + end subroutine g2_gbytesc8 + end interface call g2_gbytesc8(in, iout, iskip, nbits, 0, 1) siout = iout(1) @@ -200,6 +242,7 @@ subroutine g2_gbytesc8(in, iout, iskip, nbits, nskip, n) character*1, intent(in) :: in(*) integer (kind = 8), intent(out) :: iout(*) integer, intent(in) :: iskip, nbits, nskip, n + integer :: tbit, bitcnt integer, parameter :: ones(8) = (/ 1, 3, 7, 15, 31, 63, 127, 255 /) @@ -264,6 +307,15 @@ subroutine g2_sbytec(out, in, iskip, nbits) character*1, intent(inout) :: out(*) integer, intent(in) :: in(*) integer, intent(in) :: iskip, nbits + + interface + subroutine g2_sbytesc(out, in, iskip, nbits, nskip, n) + character*1, intent(out) :: out(*) + integer, intent(in) :: in(n) + integer, intent(in) :: iskip, nbits, nskip, n + end subroutine g2_sbytesc + end interface + call g2_sbytesc(out, in, iskip, nbits, 0, 1) end subroutine g2_sbytec @@ -287,6 +339,15 @@ subroutine g2_sbytec1(out, in, iskip, nbits) integer, intent(in) :: in integer, intent(in) :: iskip, nbits integer :: ain(1) + + interface + subroutine g2_sbytesc(out, in, iskip, nbits, nskip, n) + character*1, intent(out) :: out(*) + integer, intent(in) :: in(n) + integer, intent(in) :: iskip, nbits, nskip, n + end subroutine g2_sbytesc + end interface + ain(1) = in call g2_sbytesc(out, ain, iskip, nbits, 0, 1) end subroutine g2_sbytec1 @@ -309,6 +370,14 @@ subroutine g2_sbytescr(out, rin, iskip, nbits, nskip, n) integer, intent(in) :: iskip, nbits, nskip, n integer :: in(n) + interface + subroutine g2_sbytesc(out, in, iskip, nbits, nskip, n) + character*1, intent(out) :: out(*) + integer, intent(in) :: in(n) + integer, intent(in) :: iskip, nbits, nskip, n + end subroutine g2_sbytesc + end interface + ! Transfer real array to integer array. in(1:n) = transfer(rin, in(1:n), n) @@ -405,6 +474,15 @@ subroutine g2_sbytec8(out, in, iskip, nbits) character*1, intent(inout) :: out(*) integer (kind = 8), intent(in) :: in(*) integer, intent(in) :: iskip, nbits + + interface + subroutine g2_sbytesc8(out, in, iskip, nbits, nskip, n) + character*1, intent(out) :: out(*) + integer (kind = 8), intent(in) :: in(n) + integer, intent(in) :: iskip, nbits, nskip, n + end subroutine g2_sbytesc8 + end interface + call g2_sbytesc8(out, in, iskip, nbits, 0, 1) end subroutine g2_sbytec8 @@ -497,6 +575,14 @@ subroutine rdieeec(cieee, a, num) integer, intent(in) :: num real (kind = 4) :: rieee(num) + interface + subroutine rdieee(rieee, a, num) + real(4), intent(in) :: rieee(num) + real, intent(out) :: a(num) + integer, intent(in) :: num + end subroutine rdieee + end interface + rieee(1:num) = transfer(cieee(1:num * 4), rieee, num) call rdieee(rieee, a, num) end subroutine rdieeec diff --git a/src/g2get.F90 b/src/g2get.F90 index 1752ee51..1cc7311c 100644 --- a/src/g2get.F90 +++ b/src/g2get.F90 @@ -1514,6 +1514,14 @@ subroutine gettemplates(cgrib, lcgrib, ifldnum, igds, igdstmpl, & logical have3, have4 integer :: igdslen, ipdslen, ipos, isecnum, j, jerr, lengrib, lensec, lensec0, numfld + interface + subroutine g2_gbytec1(in, siout, iskip, nbits) + character*1, intent(in) :: in(*) + integer, intent(inout) :: siout + integer, intent(in) :: iskip, nbits + end subroutine g2_gbytec1 + end interface + have3 = .false. have4 = .false. ierr = 0 @@ -1543,12 +1551,12 @@ subroutine gettemplates(cgrib, lcgrib, ifldnum, igds, igdstmpl, & ! Unpack Section 0 - Indicator Section. iofst = 8 * (istart + 5) - call g2_gbytec(cgrib, listsec0(1), iofst, 8) ! Discipline + call g2_gbytec1(cgrib, listsec0(1), iofst, 8) ! Discipline iofst = iofst + 8 - call g2_gbytec(cgrib, listsec0(2), iofst, 8) ! GRIB edition number + call g2_gbytec1(cgrib, listsec0(2), iofst, 8) ! GRIB edition number iofst = iofst + 8 iofst = iofst + 32 - call g2_gbytec(cgrib, lengrib, iofst, 32) ! Length of GRIB message + call g2_gbytec1(cgrib, lengrib, iofst, 32) ! Length of GRIB message iofst = iofst + 32 lensec0 = 16 ipos = istart + lensec0 @@ -1578,9 +1586,9 @@ subroutine gettemplates(cgrib, lcgrib, ifldnum, igds, igdstmpl, & endif ! Get length of Section and Section number. iofst = (ipos - 1) * 8 - call g2_gbytec(cgrib, lensec, iofst, 32) ! Get Length of Section + call g2_gbytec1(cgrib, lensec, iofst, 32) ! Get Length of Section iofst = iofst + 32 - call g2_gbytec(cgrib, isecnum, iofst, 8) ! Get Section number + call g2_gbytec1(cgrib, isecnum, iofst, 8) ! Get Section number iofst = iofst + 8 !print *, ' lensec = ', lensec, ' secnum = ', isecnum diff --git a/src/g2getgb2.F90 b/src/g2getgb2.F90 index bd997242..85a477d3 100644 --- a/src/g2getgb2.F90 +++ b/src/g2getgb2.F90 @@ -374,6 +374,17 @@ subroutine getgb2l2(lugb, idxver, cindex, gfld, iret) integer :: mypos interface + subroutine g2_gbytec1(in, siout, iskip, nbits) + character*1, intent(in) :: in(*) + integer, intent(inout) :: siout + integer, intent(in) :: iskip, nbits + end subroutine g2_gbytec1 + subroutine g2_gbytec81(in, siout, iskip, nbits) + character*1, intent(in) :: in(*) + integer (kind = 8), intent(inout) :: siout + integer, intent(in) :: iskip, nbits + integer (kind = 8) :: iout(1) + end subroutine g2_gbytec81 subroutine gf_unpack2(cgrib, lcgrib, iofst, lencsec2, csec2, ierr) character(len = 1), intent(in) :: cgrib(lcgrib) integer, intent(in) :: lcgrib @@ -384,6 +395,7 @@ subroutine gf_unpack2(cgrib, lcgrib, iofst, lencsec2, csec2, ierr) end subroutine gf_unpack2 end interface + #ifdef LOGGING write(g2_log_msg, '(a, i2, a, i1)') 'getgb2l2: lugb ', lugb, ' idxver ', idxver call g2_log(1) @@ -398,18 +410,18 @@ end subroutine gf_unpack2 ! index version 2. if (idxver .eq. 1) then ! Read bytes to skip in file before message. - call g2_gbytec(cindex, lskip, mypos, INT4_BITS) + call g2_gbytec1(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) + call g2_gbytec1(cindex, skip2, mypos, INT4_BITS) skip28 = skip2 else ! Read bytes to skip in file before message. - call g2_gbytec8(cindex, lskip8, mypos, INT8_BITS) + call g2_gbytec81(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) + call g2_gbytec81(cindex, skip28, mypos, INT8_BITS) mypos = mypos + INT8_BITS endif @@ -419,7 +431,7 @@ end subroutine gf_unpack2 ! Get length of section. call bareadl(lugb, iskip8, 4_8, lread8, csize) - call g2_gbytec(csize, ilen, 0, 32) + call g2_gbytec1(csize, ilen, 0, 32) allocate(ctemp(ilen)) ilen8 = ilen diff --git a/src/g2index.F90 b/src/g2index.F90 index d76fe9c4..35b50601 100644 --- a/src/g2index.F90 +++ b/src/g2index.F90 @@ -294,8 +294,6 @@ subroutine getg2i2(lugi, cbuf, idxver, nlen, nnum, iret) character(len=1), pointer, dimension(:) :: cbuf integer, intent(out) :: idxver, nlen, nnum, iret end subroutine getg2i2 - end interface - interface subroutine getg2i2r(lugb, msk1, msk2, mnum, idxver, cbuf, & nlen, nnum, nmess, iret) integer, intent(in) :: lugb @@ -942,6 +940,11 @@ subroutine getgb2s2(cbuf, idxver, nlen, nnum, j, jdisc, jids, jpdtn, jpdt, jgdtn integer :: i, icnd, inlen, iof, ipos, jpos, lsec1, lsec3, lsec4, lsec5, numgdt, numpdt, inc interface + subroutine g2_gbytec1(in, siout, iskip, nbits) + character*1, intent(in) :: in(*) + integer, intent(inout) :: siout + integer, intent(in) :: iskip, nbits + end subroutine g2_gbytec1 subroutine gf_unpack1(cgrib, lcgrib, iofst, ids, idslen, ierr) character(len = 1), intent(in) :: cgrib(lcgrib) integer, intent(in) :: lcgrib @@ -1006,14 +1009,14 @@ end subroutine gf_unpack5 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) + call g2_gbytec1(cbuf, inlen, ipos * 8, 4 * 8) if (k .le. j) then ! skip this index ipos = ipos + inlen cycle endif ! Check if grib2 discipline is a match. - call g2_gbytec(cbuf, gfld%discipline, (ipos + inc + 41) * 8, 1 * 8) + call g2_gbytec1(cbuf, gfld%discipline, (ipos + inc + 41) * 8, 1 * 8) if (jdisc .ne. -1 .and. jdisc .ne. gfld%discipline) then ipos = ipos + inlen cycle @@ -1022,7 +1025,7 @@ end subroutine gf_unpack5 ! Check if identification section is a match. match1 = .false. ! Get length of ids. - call g2_gbytec(cbuf, lsec1, (ipos + inc + 44) * 8, 4 * 8) + call g2_gbytec1(cbuf, lsec1, (ipos + inc + 44) * 8, 4 * 8) iof = 0 call gf_unpack1(cbuf(ipos + inc + 45), lsec1, iof, gfld%idsect, gfld%idsectlen, icnd) if (icnd .eq. 0) then @@ -1043,11 +1046,11 @@ end subroutine gf_unpack5 ! Check if grid definition template is a match. jpos = ipos + 44 + inc + lsec1 match3 = .false. - call g2_gbytec(cbuf, lsec3, jpos * 8, 4 * 8) ! get length of gds + call g2_gbytec1(cbuf, lsec3, jpos * 8, 4 * 8) ! get length of gds if (jgdtn .eq. -1) then match3 = .true. else - call g2_gbytec(cbuf, numgdt, (jpos + 12) * 8, 2 * 8) ! get gdt template no. + call g2_gbytec1(cbuf, numgdt, (jpos + 12) * 8, 2 * 8) ! get gdt template no. if (jgdtn .eq. numgdt) then iof = 0 call gf_unpack3(cbuf(jpos + 1), lsec3, iof, kgds, gfld%igdtmpl, & @@ -1082,12 +1085,12 @@ end subroutine gf_unpack5 match4 = .false. ! Get length of pds. - call g2_gbytec(cbuf, lsec4, jpos * 8, 4 * 8) + call g2_gbytec1(cbuf, lsec4, jpos * 8, 4 * 8) if (jpdtn .eq. -1) then match4 = .true. else ! Get pdt template no. - call g2_gbytec(cbuf, numpdt, (jpos + 7) * 8, 2 * 8) + call g2_gbytec1(cbuf, numpdt, (jpos + 7) * 8, 2 * 8) if (jpdtn .eq. numpdt) then iof = 0 call gf_unpack4(cbuf(jpos + 1), lsec4, iof, gfld%ipdtnum, & @@ -1112,8 +1115,8 @@ end subroutine gf_unpack5 ! If request is found set values for derived type gfld and return. if (match1 .and. match3 .and. match4) then lpos = ipos + 1 - call g2_gbytec(cbuf, gfld%version, (ipos + inc + 40) * 8, 1 * 8) - call g2_gbytec(cbuf, gfld%ifldnum, (ipos + inc + 42) * 8, 2 * 8) + call g2_gbytec1(cbuf, gfld%version, (ipos + inc + 40) * 8, 1 * 8) + call g2_gbytec1(cbuf, gfld%ifldnum, (ipos + inc + 42) * 8, 2 * 8) gfld%unpacked = .false. jpos = ipos + 44 + inc + lsec1 if (jgdtn .eq. -1) then ! unpack gds, if not done before @@ -1133,12 +1136,12 @@ end subroutine gf_unpack5 gfld%ipdtmpl, gfld%ipdtlen, gfld%coord_list, gfld%num_coord, icnd) endif jpos = jpos + lsec4 - call g2_gbytec(cbuf, lsec5, jpos * 8, 4 * 8) ! get length of drs + call g2_gbytec1(cbuf, lsec5, jpos * 8, 4 * 8) ! get length of drs iof = 0 call gf_unpack5(cbuf(jpos + 1), lsec5, iof, gfld%ndpts, & gfld%idrtnum, gfld%idrtmpl, gfld%idrtlen, icnd) jpos = jpos + lsec5 - call g2_gbytec(cbuf, gfld%ibmap, (jpos + 5) * 8, 1 * 8) ! get ibmap + call g2_gbytec1(cbuf, gfld%ibmap, (jpos + 5) * 8, 1 * 8) ! get ibmap iret = 0 else ! pdt did not match ipos = ipos + inlen @@ -1298,6 +1301,14 @@ subroutine ix2gb2(lugb, lskip8, idxver, lgrib8, cbuf, numfld, mlen, iret) character cbread(LINMAX), cindex(LINMAX) character cids(LINMAX), cgds(LINMAX) + interface + subroutine g2_gbytec1(in, siout, iskip, nbits) + character*1, intent(in) :: in(*) + integer, intent(inout) :: siout + integer, intent(in) :: iskip, nbits + end subroutine g2_gbytec1 + end interface + #ifdef LOGGING ! Log results for debugging. write(g2_log_msg, *) 'ix2gb2: lugb ', lugb, ' lskip8 ', lskip8, & @@ -1354,7 +1365,7 @@ subroutine ix2gb2(lugb, lskip8, idxver, lgrib8, cbuf, numfld, mlen, iret) cdisc = cbread(7) ! Read the length of section 1 from the file data buffer. - call g2_gbytec(cbread, lensec1, 16 * 8, INT4_BITS) + call g2_gbytec1(cbread, lensec1, 16 * 8, INT4_BITS) lensec1 = min(lensec1, int(ibread8, kind(lensec1))) ! Copy section 1 values into cids array. @@ -1387,8 +1398,8 @@ subroutine ix2gb2(lugb, lskip8, idxver, lgrib8, cbuf, numfld, mlen, iret) ! Read the 4-byte section length, and then the 1-byte section ! number. - call g2_gbytec(cbread, lensec, 0, INT4_BITS) - call g2_gbytec(cbread, numsec, INT4_BITS, INT1_BITS) + call g2_gbytec1(cbread, lensec, 0, INT4_BITS) + call g2_gbytec1(cbread, numsec, INT4_BITS, INT1_BITS) ! Based on the section number, generate index data for each ! section. diff --git a/tests/g2_test_util.F90 b/tests/g2_test_util.F90 index 2e94c5e0..b4585262 100644 --- a/tests/g2_test_util.F90 +++ b/tests/g2_test_util.F90 @@ -156,27 +156,27 @@ subroutine g2_gbytec1(in, siout, iskip, nbits) integer, intent(inout) :: siout integer, intent(in) :: iskip, nbits end subroutine g2_gbytec1 - end interface - interface subroutine g2_gbytec(in, iout, iskip, nbits) character*1, intent(in) :: in(*) integer, intent(inout) :: iout(*) integer, intent(in) :: iskip, nbits end subroutine g2_gbytec - end interface - interface subroutine g2_gbytesc(in, iout, iskip, nbits, nskip, n) character*1, intent(in) :: in(*) integer, intent(out) :: iout(*) integer, intent(in) :: iskip, nbits, nskip, n end subroutine g2_gbytesc - end interface - interface subroutine g2_gbytec8(in, iout, iskip, nbits) character*1, intent(in) :: in(*) integer (kind = 8), intent(inout) :: iout(*) integer, intent(in) :: iskip, nbits end subroutine g2_gbytec8 + subroutine g2_gbytec81(in, siout, iskip, nbits) + character*1, intent(in) :: in(*) + integer (kind = 8), intent(inout) :: siout + integer, intent(in) :: iskip, nbits + integer (kind = 8) :: iout(1) + end subroutine g2_gbytec81 end interface ! Get the index record len (4 byte int). diff --git a/tests/test_getgb2p_2.F90 b/tests/test_getgb2p_2.F90 index d98bef21..2dc2aafd 100755 --- a/tests/test_getgb2p_2.F90 +++ b/tests/test_getgb2p_2.F90 @@ -53,8 +53,7 @@ END SUBROUTINE GETGB2P fileo='test_tocgrib2.output.grib2' call baopenw(lugo,fileo,iret1) if (iret1 .ne. 0) then - write(6,fmt='(" Error opening output transmission file: ", & - A200)') fileo + write(6,fmt='(" Error opening output transmission file: ", A200)') fileo write(6,fmt='(" baopenw error = ",I5)') iret1 stop 20 endif @@ -84,8 +83,6 @@ END SUBROUTINE GETGB2P nrec = nrec + 1 ! Echo input record - WRITE(6,FMT='(/,''***********************************'', & - ''********************************************'')') write(6,'(A,I0)') ' Start new record no. = ',nrec write(6,'(73A)') ' DESC=',DESC(1:73) write(6,'(11A)') ' WMOHEAD=',WMOHEAD(1:11) From e81a6273f5c5f8112cd263605c8906b1e35d65b0 Mon Sep 17 00:00:00 2001 From: Edward Hartnett <38856240+edwardhartnett@users.noreply.github.com> Date: Fri, 17 May 2024 15:34:42 +0200 Subject: [PATCH 2/2] Make the pds section location in the file an 8-byte value in the index (#689) * fixed warning * changed pds location to 8-bytes in index * removed large FTP file test to allow passing GitHub CI * make test less sensitive to index version 1 vs. 2 * fixed docs --- CMakeLists.txt | 2 +- src/g2getgb2.F90 | 4 +- src/g2index.F90 | 47 +++++++++++------- tests/CMakeLists.txt | 7 +-- tests/g2_test_util.F90 | 11 ++-- ..._gdaswave.t00z.wcoast.0p16.f000.grb2index2 | Bin 4190 -> 4266 bytes tests/test_create_index.F90 | 4 +- tests/test_create_index_fv3.F90 | 2 +- tests/test_create_index_gdas.F90 | 2 +- tests/test_create_index_gfsprs.F90 | 1 - tests/test_create_index_seaice.F90 | 2 +- tests/test_g1.F90 | 15 +++--- tests/test_getg2i2r.F90 | 6 +-- tests/test_getgb2p_2.F90 | 3 +- tests/test_getidx.F90 | 13 +++-- tests/test_ix2gb2.F90 | 8 +-- 16 files changed, 73 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 368ae6f7..cf91a7ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,7 @@ elseif(CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$") set(CMAKE_C_FLAGS "-g ${CMAKE_C_FLAGS}") set(CMAKE_C_FLAGS_DEBUG "-ggdb -Wall") set(CMAKE_Fortran_FLAGS "-g -funroll-loops ${CMAKE_Fortran_FLAGS}") - set(CMAKE_Fortran_FLAGS_DEBUG "-ggdb -Wall -Wimplicit-interface") + set(CMAKE_Fortran_FLAGS_DEBUG "-ggdb -Wall") set(fortran_d_flags "-fdefault-real-8") endif() diff --git a/src/g2getgb2.F90 b/src/g2getgb2.F90 index 85a477d3..cc1f8a55 100644 --- a/src/g2getgb2.F90 +++ b/src/g2getgb2.F90 @@ -852,7 +852,7 @@ end subroutine gf_unpack7 call g2_gbytec(cindex, lskip, INT4_BITS, INT4_BITS) lskip8 = lskip else - inc = 12 + inc = 16 call g2_gbytec8(cindex, lskip8, INT4_BITS, INT8_BITS) lskip = int(lskip8, kind(4)) endif @@ -1075,7 +1075,7 @@ subroutine getgb2rp2(lugb, idxver, cindex, extract, gribm, leng8, iret) iskp2_8 = iskp2 mypos = mypos + 32 * INT1_BITS ! skip ahead in the cindex else - inc = 12 + inc = 16 call g2_gbytec8(cindex, iskip8, mypos, INT8_BITS) ! bytes to skip in file mypos = mypos + INT8_BITS iskip = int(iskip8, kind(4)) diff --git a/src/g2index.F90 b/src/g2index.F90 index 35b50601..f4c311b8 100644 --- a/src/g2index.F90 +++ b/src/g2index.F90 @@ -474,15 +474,15 @@ end subroutine getg2i !> 005 - 008 | 005 - 012 | bytes to skip in data file before grib message (4/8 bytes) !> 009 - 012 | 013 - 020 | bytes to skip in message before lus (local use) set = 0, if no local section. (4/8 bytes) !> 013 - 016 | 021 - 028 | bytes to skip in message before gds (4/8 bytes) -!> 017 - 020 | 029 - 032 | bytes to skip in message before pds (4 bytes) -!> 021 - 024 | 033 - 036 | bytes to skip in message before drs (4 bytes) -!> 025 - 028 | 037 - 040 | bytes to skip in message before bms (4 bytes) -!> 029 - 032 | 041 - 044 | bytes to skip in message before data section (4 bytes) -!> 033 - 040 | 045 - 052 | bytes total in the message (8 bytes) -!> 041 - 041 | 053 - 053 | grib version number (always 2) (1 byte) -!> 042 - 042 | 054 - 054 | message discipline (1 byte) -!> 043 - 044 | 055 - 056 | field number within grib2 message (2 bytes) -!> 045 - ii | 057 - ii | identification section (ids) (character) +!> 017 - 020 | 029 - 036 | bytes to skip in message before pds (4/8 bytes) +!> 021 - 024 | 037 - 040 | bytes to skip in message before drs (4 bytes) +!> 025 - 028 | 041 - 044 | bytes to skip in message before bms (4 bytes) +!> 029 - 032 | 045 - 048 | bytes to skip in message before data section (4 bytes) +!> 033 - 040 | 049 - 056 | bytes total in the message (8 bytes) +!> 041 - 041 | 057 - 057 | grib version number (always 2) (1 byte) +!> 042 - 042 | 058 - 058 | message discipline (1 byte) +!> 043 - 044 | 059 - 060 | field number within grib2 message (2 bytes) +!> 045 - ii | 061 - ii | identification section (ids) (character) !> ii+1- jj | ii+1- jj | grid definition section (gds) (character) !> jj+1- kk | jj+1- kk | product definition section (pds) (character) !> kk+1- ll | kk+1- ll | the data representation section (drs) (character) @@ -1002,7 +1002,7 @@ end subroutine gf_unpack5 else ! Add the extra 8 bytes in the version 2 index record, starting ! at byte 9. - inc = 12 + inc = 16 endif ! Search for request. @@ -1311,8 +1311,7 @@ end subroutine g2_gbytec1 #ifdef LOGGING ! Log results for debugging. - write(g2_log_msg, *) 'ix2gb2: lugb ', lugb, ' lskip8 ', lskip8, & - ' idxver ', idxver + write(g2_log_msg, *) 'ix2gb2: lugb ', lugb, ' lskip8 ', lskip8, ' idxver ', idxver call g2_log(1) #endif @@ -1326,7 +1325,7 @@ end subroutine g2_gbytec1 ! changed from 4-byte ints to 8-byte ints. This is the total ! extra bytes that were added to the beginning of the index ! record in version 2. - inc = 12 + inc = 16 endif ! Initialize values and allocate buffer (at the user-provided cbuf @@ -1445,8 +1444,16 @@ end subroutine g2_gbytec1 call g2_sbytec(cindex, locgds, mypos, INT4_BITS) ! location of gds !print '(i3, a8, i4)', mypos/8, ' locgds ', locgds mypos = mypos + INT4_BITS + call g2_sbytec(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(2) +#endif + !print '(i3, a8, i4)', mypos/8, ' locpds ', int(ibskip8 - lskip8, kind(4)) + mypos = mypos + INT4_BITS else - inc = 12 + inc = 16 call g2_sbytec8(cindex, lskip8, mypos, INT8_BITS) ! bytes to skip !print '(i3, a7, i4)', mypos/8, ' lskip ', lskip mypos = mypos + INT8_BITS @@ -1456,14 +1463,18 @@ end subroutine g2_gbytec1 call g2_sbytec8(cindex, locgds8, mypos, INT8_BITS) ! location of gds !print '(i3, a8, i4)', mypos/8, ' locgds ', locgds mypos = mypos + INT8_BITS + call g2_sbytec8(cindex, ibskip8 - lskip8, mypos, INT8_BITS) ! location of pds + !print '(i3, a8, i4)', mypos/8, ' locpds ', int(ibskip8 - lskip8, kind(4)) +#ifdef LOGGING + write(g2_log_msg, *) ' writing pds location to index: mypos/8 ', mypos/8, & + ' loc ', ibskip8 - lskip8 + call g2_log(2) +#endif + mypos = mypos + INT8_BITS endif ! These ints are the same size in index version 1 and 2. The ! mypos variable contains the proper offset, which is - ! different for index version 1 and 2. - call g2_sbytec(cindex, int(ibskip8 - lskip8, kind(4)), mypos, INT4_BITS) ! location of pds - !print '(i3, a8, i4)', mypos/8, ' locpds ', int(ibskip8 - lskip8, kind(4)) - mypos = mypos + INT4_BITS mypos = mypos + INT4_BITS * 3 ! skip ahead in cbuf call g2_sbytec8(cindex, lgrib8, mypos, INT8_BITS) ! len of grib2 !print '(i3, a8, i4)', mypos/8, ' lgrib8 ', lgrib8 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b9aa0b68..45def016 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -91,12 +91,13 @@ if(FTP_TEST_FILES) # User may also ask for large test file. if(FTP_LARGE_TEST_FILES) - set(FTP_FILES ${FTP_FILES} fv3lam.t00z.prslev.f000.grib2 rrfs.t12z.prslevfaa.f010.na3km.grib2 grib2.awips.rrfs.010) + set(FTP_FILES ${FTP_FILES} fv3lam.t00z.prslev.f000.grib2) endif() # User may also ask for extra large test files. if(FTP_EXTRA_TEST_FILES) - set(FTP_FILES ${FTP_FILES} GFSPRS.GrbF06 rrfs.t18z.prslev.f000.grib2) + set(FTP_FILES ${FTP_FILES} GFSPRS.GrbF06 rrfs.t18z.prslev.f000.grib2 + rrfs.t12z.prslevfaa.f010.na3km.grib2 grib2.awips.rrfs.010) endif() message(STATUS "Getting these files from FTP: ${FTP_FILES}.") @@ -135,9 +136,9 @@ if(FTP_TEST_FILES) create_test(test_fv3 ${kind}) create_test(test_create_index_fv3 ${kind}) create_test(test_files_fv3 ${kind}) - create_test(test_getgb2p_2 ${kind}) endif() if(FTP_EXTRA_TEST_FILES) + create_test(test_getgb2p_2 ${kind}) create_test(test_create_index_gfsprs ${kind}) endif() endforeach() diff --git a/tests/g2_test_util.F90 b/tests/g2_test_util.F90 index b4585262..8141085d 100644 --- a/tests/g2_test_util.F90 +++ b/tests/g2_test_util.F90 @@ -198,19 +198,20 @@ end subroutine g2_gbytec81 !print '(i3, a8, z4)', mypos/8, ' b2s_gds', b2s_gds mypos = mypos + INT4_BITS b2s_gds8 = b2s_gds + call g2_gbytec1(cbuf, b2s_pds, mypos, INT4_BITS) + mypos = mypos + INT4_BITS + b2s_pds8 = b2s_pds else - inc = 12 + inc = 16 call g2_gbytec81(cbuf, b2s_message8, 8 * 4, INT8_BITS) mypos = mypos + INT8_BITS call g2_gbytec81(cbuf, b2s_lus8, 8 * 12, INT8_BITS) mypos = mypos + INT8_BITS call g2_gbytec81(cbuf, b2s_gds8, 8 * 20, INT8_BITS) mypos = mypos + INT8_BITS - ! call g2_gbytec(cbuf, b2s_pds, 8 * 16, INT8_BITS) + call g2_gbytec81(cbuf, b2s_pds8, mypos, INT8_BITS) + mypos = mypos + INT8_BITS endif - call g2_gbytec1(cbuf, b2s_pds, mypos, INT4_BITS) - mypos = mypos + INT4_BITS - b2s_pds8 = b2s_pds call g2_gbytec1(cbuf, b2s_drs, mypos, INT4_BITS) mypos = mypos + INT4_BITS b2s_drs8 = b2s_drs diff --git a/tests/ref_gdaswave.t00z.wcoast.0p16.f000.grb2index2 b/tests/ref_gdaswave.t00z.wcoast.0p16.f000.grb2index2 index e3578578089391703f7bf2ddca227de52db4269c..8cf3365ea70f1374eb2dea666ee1b806d2b57bc4 100644 GIT binary patch delta 495 zcmcbouu5@)EVrS#f`Orxp|O>z=|l}DWFoHv4AW&#R4_;2MfrOd8|$pIcWN||+nZXUR#Eu8b&EbJr!mRidmn9Coa77{0u_>DTj~8UgE