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

More testing for getg2i2r() #685

Merged
merged 25 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
1 change: 0 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ if(FTP_TEST_FILES)
create_test(test_getgb2s ${kind})
create_test(test_getgb2p ${kind})
create_test(test_getgb2r ${kind})
create_test(test_getgb2ir ${kind})
create_test(test_file_blend ${kind})
create_test(test_aqm ${kind})
create_test(test_create_index_gdas ${kind})
Expand Down
177 changes: 177 additions & 0 deletions tests/g2_test_util.F90
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,180 @@ subroutine write_grib2_file(filename)
call baclose(1, ierr)

end subroutine write_grib2_file

! Pull the values out of an index record.
!
! Edward Hartnett, 5/11/24
subroutine read_index(cbuf, idxver, index_rec_len, b2s_message8, b2s_lus8, &
b2s_gds8, b2s_pds8, b2s_drs8, b2s_bms8, b2s_data8, total_bytes8, &
grib_version, discipline, field_number, sec1, lengds, gds, lenpds, pds, &
lendrs, drs, bms, iret)
implicit none

character(len=1), pointer, dimension(:), intent(in) :: cbuf(:)
integer, intent(in) :: idxver
integer, intent(out) :: index_rec_len
integer (kind = 8), intent(out) :: b2s_message8, b2s_lus8, b2s_gds8, b2s_pds8, b2s_drs8, b2s_bms8, b2s_data8
integer (kind = 8), intent(out) :: total_bytes8
integer, intent(out) :: grib_version, discipline, field_number
character, intent(out) :: sec1(21)
integer, intent(inout) :: lengds
character, intent(out) :: gds(:)
integer, intent(inout) :: lenpds
character, intent(out) :: pds(:)
integer, intent(inout) :: lendrs
character, intent(out) :: drs(:)
character, intent(out) :: bms(:)
integer, intent(out) :: iret

integer :: lensec1

integer :: b2s_message, b2s_lus, b2s_gds, b2s_pds, b2s_drs, b2s_bms, b2s_data
integer :: inc, mypos = 0
integer :: i
integer :: INT1_BITS, INT2_BITS, INT4_BITS, INT8_BITS
parameter(INT1_BITS = 8, INT2_BITS = 16, INT4_BITS = 32, INT8_BITS = 64)
integer (kind = 8) :: INT8_BITS8
parameter(INT8_BITS8 = 64_8)
integer :: BMS_LEN
parameter (BMS_LEN = 6)

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
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
end interface

! Get the index record len (4 byte int).
call g2_gbytec1(cbuf, index_rec_len, 0, INT4_BITS)
!print *, 'read_index(): index_rec_len', index_rec_len
mypos = INT4_BITS

if (idxver .eq. 1) then
inc = 0
call g2_gbytec1(cbuf, b2s_message, mypos, INT4_BITS)
!print '(i3, a12, z4)', mypos/8, ' b2s_message', b2s_message
mypos = mypos + INT4_BITS
b2s_message8 = b2s_message
call g2_gbytec1(cbuf, b2s_lus, mypos, INT4_BITS)
!print '(i3, a8, z4)', mypos/8, ' b2s_lus', b2s_lus
mypos = mypos + INT4_BITS
b2s_lus8 = b2s_lus
call g2_gbytec1(cbuf, b2s_gds, mypos, INT4_BITS)
!print '(i3, a8, z4)', mypos/8, ' b2s_gds', b2s_gds
mypos = mypos + INT4_BITS
b2s_gds8 = b2s_gds
else
inc = 12
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)
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
call g2_gbytec1(cbuf, b2s_bms, mypos, INT4_BITS)
mypos = mypos + INT4_BITS
b2s_bms8 = b2s_bms
call g2_gbytec1(cbuf, b2s_data, mypos, INT4_BITS)
mypos = mypos + INT4_BITS
b2s_data8 = b2s_data
call g2_gbytec81(cbuf, total_bytes8, mypos, INT8_BITS)
mypos = mypos + INT8_BITS
call g2_gbytec1(cbuf, grib_version, mypos, INT1_BITS)
mypos = mypos + INT1_BITS
call g2_gbytec1(cbuf, discipline, mypos, INT1_BITS)
mypos = mypos + INT1_BITS
call g2_gbytec1(cbuf, field_number, mypos, INT2_BITS)
mypos = mypos + INT2_BITS

! Find the length of sec1. It should be 21.
call g2_gbytec1(cbuf, lensec1, mypos, INT4_BITS)
!mypos = mypos + INT4_BITS

! Copy section 1 from the index record to output parameter. (mypos
! is in bits, but i is in bytes.)
!print *, 'copying sec1', mypos/8
do i = 1, lensec1
sec1(i) = cbuf(mypos/8 + 1)
mypos = mypos + INT1_BITS
end do

! Find the length of gds. It should be 72.
call g2_gbytec1(cbuf, lengds, mypos, INT4_BITS)

! Copy GDS from the index record to output parameter. (mypos
! is in bits, but i is in bytes.)
!print *, 'copying gds', lengds, mypos/8
do i = 1, lengds
gds(i) = cbuf(mypos/8 + 1)
mypos = mypos + INT1_BITS
end do

! Find the length of pds. It should be 72.
call g2_gbytec1(cbuf, lenpds, mypos, INT4_BITS)

! Copy PDS from the index record to output parameter. (mypos
! is in bits, but i is in bytes.)
!print *, 'copying pds', lenpds, mypos/8
do i = 1, lenpds
pds(i) = cbuf(mypos/8 + 1)
!print *, ichar(pds(i)), ','
mypos = mypos + INT1_BITS
end do

! Find the length of drs. It should be 72.
call g2_gbytec1(cbuf, lendrs, mypos, INT4_BITS)

! Copy DRS from the index record to output parameter. (mypos
! is in bits, but i is in bytes.)
!print *, 'copying drs', lendrs, mypos/8
do i = 1, lendrs
drs(i) = cbuf(mypos/8 + 1)
!print *, ichar(drs(i)), ','
mypos = mypos + INT1_BITS
end do

! Copy the 6 bytes of bms from the index record to output
! parameter. (mypos is in bits, but i is in bytes.)
!print *, 'copying bms', mypos/8
do i = 1, BMS_LEN
bms(i) = cbuf(mypos/8 + 1)
!print *, ichar(bms(i)), ','
mypos = mypos + INT1_BITS
end do

! Return success.
iret = 0
end subroutine read_index

Loading
Loading