Skip to content

Commit

Permalink
progress with g2f_inq_prod()
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhartnett committed Dec 23, 2024
1 parent df8798a commit 6579ede
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/g2c_interface.F90
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ end function g2c_inq_msg_time
function g2c_inq_prod(g2id, msg_num, prod_num, pds_template_len, pds_template, gds_template_len, &
gds_template, drs_template_len, drs_template) bind(c)
use iso_c_binding
integer(c_int), value :: g2id
integer(c_int), value :: msg_num
integer(c_int), intent(out) :: prod_num, pds_template_len
integer(c_int), value :: g2id, msg_num, prod_num
integer(c_int), intent(out) :: pds_template_len
integer(c_long_long), intent(out) :: pds_template(*)
integer(c_int), intent(out) :: gds_template_len
integer(c_long_long), intent(out) :: gds_template(*)
Expand Down
24 changes: 15 additions & 9 deletions src/g2cf.F90
Original file line number Diff line number Diff line change
Expand Up @@ -355,17 +355,23 @@ function g2cf_inq_prod(g2id, msg_num, prod_num, pds_template_len, pds_template,

! Copy output params to Fortran types.
pds_template_len = cpds_template_len
do i = 1, pds_template_len
pds_template(i) = cpds_template(i)
end do
if (pds_template_len .gt. 0) then
do i = 1, pds_template_len
pds_template(i) = cpds_template(i)
end do
endif
gds_template_len = cgds_template_len
do i = 1, gds_template_len
gds_template(i) = cgds_template(i)
end do
if (gds_template_len .gt. 0) then
do i = 1, gds_template_len
gds_template(i) = cgds_template(i)
end do
endif
drs_template_len = cdrs_template_len
do i = 1, drs_template_len
drs_template(i) = cdrs_template(i)
end do
if (drs_template_len .gt. 0) then
do i = 1, drs_template_len
drs_template(i) = cdrs_template(i)
end do
endif
status = cstatus

end function g2cf_inq_prod
Expand Down
31 changes: 30 additions & 1 deletion tests/test_g2cf.F90
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ program test_g2cf
integer(kind = 1) :: master_version, local_version
integer(kind = 1) :: sig_ref_time
integer(kind = 2) :: year
integer(kind = 1) :: month, day, hour, minute, second
integer(kind = 1) :: month, day, hour, minute, second
integer :: pds_template_len, gds_template_len, drs_template_len
integer(kind = 8) :: pds_template(G2_MAX_PDS_TEMPLATE_LEN), gds_template(G2_MAX_GDS_TEMPLATE_LEN), &
drs_template(G2_MAX_DRS_TEMPLATE_LEN)
integer(kind = 8) :: expected_pds_template(15) = (/ 2, 1, 2, 0, 11, 0, 0, 1, &
0, 1, 0, 1, 255, 0, 0 /)
integer(kind = 8) :: expected_gds_template(19) = (/ 6, 0, 0, 0, 0, 0, 0, 241, &
151, 0, 0, 50000000, 210000000, 48, 25000000, 250000000, 166667, 166667, 0 /)
integer(kind = 8) :: expected_drs_template(7) = (/ 1092616192, 0, 2, 11, 0, 0, 255 /)
integer :: i
integer :: ierr

print *, 'Testing g2cf API...'
Expand All @@ -40,10 +49,30 @@ program test_g2cf
! Check the time of the last message.
ierr = g2cf_inq_msg_time(g2id, 19, sig_ref_time, year, &
month, day, hour, minute, second)
if (ierr .ne. 0) stop 200
!print *, sig_ref_time, year, month, day, hour, minute, second
if (sig_ref_time .ne. 1 .or. year .ne. 2021 .or. month .ne. 11 .or. day .ne. 30 .or. &
hour .ne. 0 .or. minute .ne. 0 .or. second .ne. 0) stop 101

! Learn about the first product in the last message.
ierr = g2cf_inq_prod(g2id, 1, 1, pds_template_len, pds_template, gds_template_len, &
gds_template, drs_template_len, drs_template)
if (ierr .ne. 0) stop 300
!print *, pds_template_len, gds_template_len, drs_template_len
if (pds_template_len .ne. 15 .or. gds_template_len .ne. 19 .or. drs_template_len .ne.7) stop 301
!print *, pds_template
do i = 1, pds_template_len
if (pds_template(i) .ne. expected_pds_template(i)) stop 302
end do
!print *, gds_template
do i = 1, gds_template_len
if (gds_template(i) .ne. expected_gds_template(i)) stop 302
end do
!print *, drs_template
do i = 1, drs_template_len
if (drs_template(i) .ne. expected_drs_template(i)) stop 302
end do

! Close the file.
ierr = g2cf_close(g2id)
if (ierr .ne. 0) stop 20
Expand Down

0 comments on commit 6579ede

Please sign in to comment.