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] 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