Skip to content

Commit

Permalink
more g2c API
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhartnett committed Dec 21, 2024
1 parent 5960bd7 commit 6b41681
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/g2c_interface.F90
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function g2c_inq_msg(g2id, msg_num, discipline, num_fields, &
num_local, center, subcenter, master_version, local_version) bind(c)
use iso_c_binding
integer(c_int), value :: g2id
integer(c_int), intent(in) :: msg_num
integer(c_int), value :: msg_num
integer(c_signed_char), intent(out) :: discipline
integer(c_int), intent(out) :: num_fields, num_local
integer(c_short), intent(out) :: center, subcenter
Expand Down
10 changes: 6 additions & 4 deletions src/g2cf.F90
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ end function g2cf_inq
!> Learn about a message are in a GRIB2 file.
!>
!> @param[in] g2id The ID of the open file
!> @param[in] msg_num The number of message to learn about.
!> @param[in] msg_num The number of message to learn about. The
!> first message in the file is number 1.
!> @param[out] discipline The discipline of the message.
!> @param[out] num_fields Number of fields in the message.
!> @param[out] num_local Number of local sections in the message.
Expand All @@ -179,10 +180,10 @@ function g2cf_inq_msg(g2id, msg_num, discipline, num_fields, &
implicit none

integer, intent(in) :: g2id, msg_num
integer, intent(out) :: discipline
integer(kind = 1), intent(out) :: discipline
integer, intent(out) :: num_fields, num_local
integer(kind = 2), intent(out) :: center, subcenter
integer(kind = 2), intent(out) :: master_version, local_version
integer(kind = 1), intent(out) :: master_version, local_version
integer :: status

integer(c_int) :: cg2id, cmsg_num, cstatus
Expand All @@ -192,7 +193,8 @@ function g2cf_inq_msg(g2id, msg_num, discipline, num_fields, &
integer(c_signed_char) :: cmaster_version, clocal_version

cg2id = g2id
cmsg_num = msg_num
! Subtract 1 because C is zero-based.
cmsg_num = msg_num - 1
cstatus = g2c_inq_msg(cg2id, cmsg_num, cdiscipline, cnum_fields, &
cnum_local, ccenter, csubcenter, cmaster_version, clocal_version)
discipline = cdiscipline
Expand Down
4 changes: 3 additions & 1 deletion tests/test_g2cf.F90
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ program test_g2cf
integer :: ierr

print *, 'Testing g2cf API...'
ierr = g2cf_set_log_level(1)
!ierr = g2cf_set_log_level(1)

! Open the test file.
ierr = g2cf_open(fileName, 0, g2cid)
Expand All @@ -29,6 +29,8 @@ program test_g2cf
! Check the last message.
ierr = g2cf_inq_msg(g2cid, 19, discipline, num_fields, num_local, center, subcenter, &
master_version, local_version)
if (ierr .ne. 0) stop 100
!print *, discipline, num_fields, num_local, center, subcenter, master_version, local_version
if (discipline .ne. 10 .or. num_fields .ne. 1 .or. num_local .ne. 0 .or. center .ne. 7 .or. &
subcenter .ne. 0 .or. master_version .ne. 2 .or. local_version .ne. 1) stop 12

Expand Down

0 comments on commit 6b41681

Please sign in to comment.