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

Rest of index v2 changes #610

Merged
merged 71 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
7f5d2d7
more index progress
edwardhartnett Feb 7, 2024
2204d38
more index progress
edwardhartnett Feb 7, 2024
d71e4ae
more index progress
edwardhartnett Feb 7, 2024
86508f4
more index work
edwardhartnett Feb 7, 2024
0866db4
more index work
edwardhartnett Feb 7, 2024
9598dfa
more index work
edwardhartnett Feb 7, 2024
05a6c3c
more index work
edwardhartnett Feb 7, 2024
07900a9
more
edwardhartnett Feb 7, 2024
56cdb8e
more index changes
edwardhartnett Feb 8, 2024
fd288ee
more index changes
edwardhartnett Feb 8, 2024
014b00e
more index changes
edwardhartnett Feb 8, 2024
ee4841d
more index work
edwardhartnett Feb 8, 2024
68a0f33
more index work
edwardhartnett Feb 8, 2024
aa92f1c
documentation update
edwardhartnett Feb 8, 2024
e1bca4e
more index work
edwardhartnett Feb 8, 2024
0354849
more index work
edwardhartnett Feb 8, 2024
3d6dc5c
more index work
edwardhartnett Feb 8, 2024
7431200
more index work
edwardhartnett Feb 8, 2024
6f0a3b9
more index work
edwardhartnett Feb 8, 2024
9941703
more index work
edwardhartnett Feb 9, 2024
6919c61
more index progress
edwardhartnett Feb 9, 2024
cb2df97
more progress
edwardhartnett Feb 9, 2024
16f2561
more index work
edwardhartnett Feb 9, 2024
6e968e8
more index work
edwardhartnett Feb 9, 2024
36e2828
documentation fix
edwardhartnett Feb 9, 2024
7df5672
more index work
edwardhartnett Feb 11, 2024
7b3f7f3
Merge branch 'develop' into ejh_index_0209
edwardhartnett Feb 11, 2024
1a707bf
working on index testing
edwardhartnett Feb 11, 2024
a0318ed
working on index testing
edwardhartnett Feb 11, 2024
78c4cd5
more work on index
edwardhartnett Feb 12, 2024
7088a65
more index work
edwardhartnett Feb 12, 2024
e931cf9
added small data file
edwardhartnett Feb 12, 2024
dcaad64
clean up
edwardhartnett Feb 12, 2024
8fa40b4
more index development
edwardhartnett Feb 12, 2024
3b4e0c8
more index work
edwardhartnett Feb 12, 2024
6dbd19f
combined source files
edwardhartnett Feb 12, 2024
2de5fee
more index development
edwardhartnett Feb 12, 2024
2face2c
more index development
edwardhartnett Feb 12, 2024
afb91c3
more index work
edwardhartnett Feb 13, 2024
8405853
more index work
edwardhartnett Feb 13, 2024
aa3fd66
more index work
edwardhartnett Feb 13, 2024
01fcb5a
more index work
edwardhartnett Feb 13, 2024
834ac80
more index work
edwardhartnett Feb 13, 2024
2da05fe
rolled back some changes
edwardhartnett Feb 13, 2024
ddc802f
more index work
edwardhartnett Feb 13, 2024
1d5f000
more index work
edwardhartnett Feb 13, 2024
fbe506e
more index work
edwardhartnett Feb 13, 2024
bd0a39a
more index work
edwardhartnett Feb 13, 2024
624d770
reverted test
edwardhartnett Feb 13, 2024
fdc37ca
added new test
edwardhartnett Feb 13, 2024
9611323
Merge branch 'develop' into ejh_index_0213
edwardhartnett Feb 13, 2024
494f37f
more index work
edwardhartnett Feb 13, 2024
a3dabe5
more index work
edwardhartnett Feb 13, 2024
f548cdd
more index work
edwardhartnett Feb 13, 2024
e0f596c
more index work
edwardhartnett Feb 13, 2024
990d412
more index work
edwardhartnett Feb 13, 2024
b11987d
more index progress
edwardhartnett Feb 13, 2024
34a6be5
more index progress
edwardhartnett Feb 13, 2024
3928e99
more index progress
edwardhartnett Feb 13, 2024
3e23e42
turning off memory checking for a test
edwardhartnett Feb 14, 2024
4ffc636
turning off memcheck for test_getgb2p_gdas
edwardhartnett Feb 14, 2024
fd1b1c3
working on getgb2r.F90
edwardhartnett Feb 14, 2024
12d4ed6
working on getgb2r.F90
edwardhartnett Feb 14, 2024
e84872f
working on getgb2r.F90
edwardhartnett Feb 14, 2024
2ac1af1
working on getgb2r.F90 documentation
edwardhartnett Feb 14, 2024
62b5337
working on getgb2r.F90 documentation
edwardhartnett Feb 14, 2024
5567a00
converting to bareadl()
edwardhartnett Feb 14, 2024
4ab5fac
converting to bareadl()
edwardhartnett Feb 14, 2024
03d0db3
converting to bareadl()
edwardhartnett Feb 14, 2024
07d13db
converting to bareadl()
edwardhartnett Feb 14, 2024
15a6a76
done with index v2 changes
edwardhartnett Feb 14, 2024
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
12 changes: 10 additions & 2 deletions src/getgb2.F90
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,19 @@ subroutine getgb2l2(lugb, idxver, cindex, gfld, iret)
type(gribfield) :: gfld
integer, intent(out) :: iret
end subroutine getgb2l2
subroutine getgb2r2(lugb, idxver, cindex, gfld, iret)
use grib_mod
implicit none
integer, intent(in) :: lugb, idxver
character(len=1), intent(in) :: cindex(*)
type(gribfield) :: gfld
integer, intent(out) :: iret
end subroutine getgb2r2
end interface

! Determine whether index buffer needs to be initialized.
irgi = 0
idxver = 1
idxver = 2
call getidx2(lugb, lugi, idxver, cbuf, nlen, nnum, irgi)
if (irgi .gt. 1) then
iret = 96
Expand All @@ -170,7 +178,7 @@ end subroutine getgb2l2

! Read and unpack grib record.
if (unpack) then
call getgb2r(lugb, cbuf(lpos), gfld, iret)
call getgb2r2(lugb, idxver, cbuf(lpos), gfld, iret)
endif
k = jk
end subroutine getgb2
Expand Down
218 changes: 147 additions & 71 deletions src/getgb2r.F90
Original file line number Diff line number Diff line change
@@ -1,18 +1,76 @@
!> @file
!> @brief Read and unpack sections 6 and 7 from a GRIB2 message.
!> @brief Read and unpack sections 6 and 7 from a GRIB2 message using
!> an index record.
!> @author Stephen Gilbert @date 2002-01-11

!> Read and unpack sections 6 and 7 from a GRIB2 message.
!> Read and unpack sections 6 and 7 from a GRIB2 message using a
!> version 1 index record.
!>
!> It assumes that the metadata for this field already exists in
!> derived type @ref grib_mod::gribfield. Specifically, it requires
!> gfld\%ibmap, gfld\%ngrdpts, gfld\%idrtnum, gfld\%idrtmpl, and
!> gfld\%ndpts.
!> This function is maintained for backward compatibility. New code
!> should use getgb2r2(), which can handle both version 1 and version
!> 2 index records.
!>
!> It decodes information for the selected grib field and returns it
!> in a derived type variable, gfld, of type @ref
!> grib_mod::gribfield. Users of this routine will need to include the
!> line "use grib_mod" in their calling routine.
!> Metadata for the field must already exists in derived type @ref
!> grib_mod::gribfield. Specifically, it requires gfld\%ibmap,
!> gfld\%ngrdpts, gfld\%idrtnum, gfld\%idrtmpl, and gfld\%ndpts.
!>
!> The field data is returned in derived type variable, gfld, of type
!> @ref grib_mod::gribfield. Users of this routine will need to
!> include the line "use grib_mod" in their calling routine.
!>
!> This subprogram is intended for private use by getgb2()
!> routines only.
!>
!> Derived type gribfield contains pointers to many arrays of
!> data. Users must free this memory by calling gf_free().
!>
!> @param[in] lugb integer unit of the unblocked grib data file.
!> File must be opened with [baopen() or baopenr()]
!> (https://noaa-emc.github.io/NCEPLIBS-bacio/) before calling
!> this routine.
!> @param[in] cindex version 1 index record of the field (see
!> subroutine ix2gb2() for description of an index record.)
!> @param[out] gfld derived type @ref grib_mod::gribfield.
!> @param[out] iret Return code:
!> - 0 all ok
!> - 97 error reading grib file
!> - other gf_getfld grib2 unpacker return code
!>
!> @author Stephen Gilbert, Ed Hartnett @date 2002-01-11
subroutine getgb2r(lugb, cindex, gfld, iret)
use grib_mod
implicit none

integer, intent(in) :: lugb
character(len=1), intent(in) :: cindex(*)
type(gribfield) :: gfld
integer, intent(out) :: iret

interface
subroutine getgb2r2(lugb, idxver, cindex, gfld, iret)
use grib_mod
implicit none
integer, intent(in) :: lugb, idxver
character(len=1), intent(in) :: cindex(*)
type(gribfield) :: gfld
integer, intent(out) :: iret
end subroutine getgb2r2
end interface

call getgb2r2(lugb, 1, cindex, gfld, iret)

end subroutine getgb2r

!> Read and unpack sections 6 and 7 from a GRIB2 message using a
!> version 1 or version 2 index record.
!>
!> Metadata for the field must already exists in derived type @ref
!> grib_mod::gribfield. Specifically, it requires gfld\%ibmap,
!> gfld\%ngrdpts, gfld\%idrtnum, gfld\%idrtmpl, and gfld\%ndpts.
!>
!> The field data is returned in derived type variable, gfld, of type
!> @ref grib_mod::gribfield. Users of this routine will need to
!> include the line "use grib_mod" in their calling routine.
!>
!> This subprogram is intended for private use by getgb2()
!> routines only.
Expand All @@ -23,33 +81,39 @@
!> @note Do not engage the same logical unit from more than one
!> processor.
!>
!> @param[in] LUGB integer unit of the unblocked grib data file.
!> @param[in] lugb integer unit of the unblocked grib data file.
!> File must be opened with [baopen() or baopenr()]
!> (https://noaa-emc.github.io/NCEPLIBS-bacio/) before calling
!> this routine.
!> @param[in] CINDEX index record of the grib field (see
!> subroutine ixgb2() for description of an index record.)
!> @param[out] GFLD derived type @ref grib_mod::gribfield.
!> @param[out] IRET integer return code
!> @param[in] idxver Index version, 1 for legacy, 2 if file may be >
!> 2 GB.
!> @param[in] cindex version 1 or 2 index record of the grib field
!> (see subroutine ixgb2() for description of an index record.)
!> @param[out] gfld derived type @ref grib_mod::gribfield.
!> @param[out] iret Return code:
!> - 0 all ok
!> - 97 error reading grib file
!> - other gf_getfld grib2 unpacker return code
!>
!> @author Stephen Gilbert @date 2002-01-11
SUBROUTINE GETGB2R(LUGB, CINDEX, GFLD, IRET)
!> @author Ed Hartnett, Stephen Gilbert @date Feb 14, 2024
subroutine getgb2r2(lugb, idxver, cindex, gfld, iret)
use grib_mod
implicit none

INTEGER, INTENT(IN) :: LUGB
CHARACTER(LEN=1), INTENT(IN) :: CINDEX(*)
TYPE(GRIBFIELD) :: GFLD
INTEGER, INTENT(OUT) :: IRET
integer, intent(in) :: lugb, idxver
character(len=1), intent(in) :: cindex(*)
type(gribfield) :: gfld
integer, intent(out) :: iret

INTEGER :: LSKIP, SKIP6, SKIP7
CHARACTER(LEN=1):: CSIZE(4)
CHARACTER(LEN=1), ALLOCATABLE :: CTEMP(:)
integer :: lskip, skip6, skip7
character(len=1):: csize(4)
character(len=1), allocatable :: ctemp(:)
real, pointer, dimension(:) :: newfld
integer :: n, lread, j, iskip, iofst, ilen, ierr, idum
integer :: inc
integer (kind = 8) :: lskip8, lread8, ilen8, iskip8
integer :: INT1_BITS, INT2_BITS, INT4_BITS, INT8_BITS
parameter(INT1_BITS = 8, INT2_BITS = 16, INT4_BITS = 32, INT8_BITS = 64)

interface
subroutine gf_unpack6(cgrib, lcgrib, iofst, ngpts, ibmap, bmap, ierr)
Expand All @@ -72,63 +136,75 @@ end subroutine gf_unpack7
end interface

! Get info.
NULLIFY(gfld%bmap, gfld%fld)
IRET = 0
CALL G2_GBYTEC(CINDEX, LSKIP, 4*8, 4*8)
CALL G2_GBYTEC(CINDEX, SKIP6, 24*8, 4*8)
CALL G2_GBYTEC(CINDEX, SKIP7, 28*8, 4*8)
nullify(gfld%bmap, gfld%fld)
iret = 0
inc = 0
if (idxver .eq. 1) then
call g2_gbytec(cindex, lskip, INT4_BITS, INT4_BITS)
lskip8 = lskip
else
inc = 4
call g2_gbytec8(cindex, lskip8, INT4_BITS, INT8_BITS)
lskip = int(lskip8, kind(4))
endif
call g2_gbytec(cindex, skip6, (24 + inc) * INT1_BITS, INT4_BITS)
call g2_gbytec(cindex, skip7, (28 + inc) * INT1_BITS, INT4_BITS)

! Read and unpack bit_map, if present.
IF (gfld%ibmap .eq. 0 .OR. gfld%ibmap .eq. 254) THEN
ISKIP = LSKIP + SKIP6
if (gfld%ibmap .eq. 0 .or. gfld%ibmap .eq. 254) then
iskip = lskip + skip6
iskip8 = lskip8 + skip6

! Get length of section.
CALL BAREAD(LUGB, ISKIP, 4, LREAD, CSIZE)
CALL G2_GBYTEC(CSIZE, ILEN, 0, 32)
ALLOCATE(CTEMP(ILEN))

! Read in section.
CALL BAREAD(LUGB, ISKIP, ILEN, LREAD, CTEMP)
IF (ILEN .NE. LREAD) THEN
IRET = 97
DEALLOCATE(CTEMP)
RETURN
ENDIF
IOFST = 0
CALL GF_UNPACK6(CTEMP, ILEN, IOFST, gfld%ngrdpts, idum, gfld%bmap, ierr)
IF (IERR .NE. 0) THEN
IRET = 98
DEALLOCATE(CTEMP)
RETURN
ENDIF
DEALLOCATE(CTEMP)
ENDIF
! get length of section.
call bareadl(lugb, iskip8, 4_8, lread8, csize)
call g2_gbytec(csize, ilen, 0, 32)
allocate(ctemp(ilen))
ilen8 = ilen

! read in section.
call bareadl(lugb, iskip8, ilen8, lread8, ctemp)
if (ilen8 .ne. lread8) then
iret = 97
deallocate(ctemp)
return
endif
iofst = 0
call gf_unpack6(ctemp, ilen, iofst, gfld%ngrdpts, idum, gfld%bmap, ierr)
if (ierr .ne. 0) then
iret = 98
deallocate(ctemp)
return
endif
deallocate(ctemp)
endif

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

! Get length of section.
CALL BAREAD(LUGB, ISKIP, 4, LREAD, CSIZE)
CALL G2_GBYTEC(CSIZE, ILEN, 0, 32)
call bareadl(lugb, iskip8, 4_8, lread8, csize)
call g2_gbytec(csize, ilen, 0, 32)
if (ilen .lt. 6) ilen = 6
ALLOCATE(CTEMP(ILEN))
allocate(ctemp(ilen))
ilen8 = ilen

! Read in section.
CALL BAREAD(LUGB, ISKIP, ILEN, LREAD, CTEMP)
IF (ILEN .NE. LREAD) THEN
IRET = 97
DEALLOCATE(CTEMP)
RETURN
ENDIF
IOFST = 0
CALL GF_UNPACK7(CTEMP, ILEN, IOFST, gfld%igdtnum, gfld%igdtmpl, &
call bareadl(lugb, iskip8, ilen8, lread8, ctemp)
if (ilen8 .ne. lread8) then
iret = 97
deallocate(ctemp)
return
endif
iofst = 0
call gf_unpack7(ctemp, ilen, iofst, gfld%igdtnum, gfld%igdtmpl, &
gfld%idrtnum, gfld%idrtmpl, gfld%ndpts, gfld%fld, ierr)
IF (IERR .NE. 0) THEN
IRET = 98
DEALLOCATE(CTEMP)
RETURN
ENDIF
DEALLOCATE(CTEMP)
if (ierr .ne. 0) then
iret = 98
deallocate(ctemp)
return
endif
deallocate(ctemp)

! If bitmap is used with this field, expand data field
! to grid, if possible.
Expand All @@ -149,4 +225,4 @@ end subroutine gf_unpack7
else
gfld%expanded = .true.
endif
END SUBROUTINE GETGB2R
end subroutine getgb2r2
Loading
Loading