diff --git a/src/g2c_interface.F90 b/src/g2c_interface.F90 index 05c145ca..e9e838fc 100644 --- a/src/g2c_interface.F90 +++ b/src/g2c_interface.F90 @@ -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 diff --git a/src/g2cf.F90 b/src/g2cf.F90 index 4e7a3962..a35a1194 100644 --- a/src/g2cf.F90 +++ b/src/g2cf.F90 @@ -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. @@ -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 @@ -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 diff --git a/tests/test_g2cf.F90 b/tests/test_g2cf.F90 index 474d3da9..d0c205a9 100644 --- a/tests/test_g2cf.F90 +++ b/tests/test_g2cf.F90 @@ -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) @@ -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