From cd05c3da86c053c2848d8ddc8138286a2e84e83e Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 21 Dec 2024 08:40:56 -0700 Subject: [PATCH] more progress --- src/g2c_interface.F90 | 13 ++++++++++++- src/g2cf.F90 | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/g2c_interface.F90 b/src/g2c_interface.F90 index 8418a99f..05c145ca 100644 --- a/src/g2c_interface.F90 +++ b/src/g2c_interface.F90 @@ -30,7 +30,18 @@ function g2c_inq(g2id, num_msg) bind(c) integer(c_int) :: g2c_inq end function g2c_inq - ! int g2c_inq(int g2cid, int *num_msg); + 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_signed_char), intent(out) :: discipline + integer(c_int), intent(out) :: num_fields, num_local + integer(c_short), intent(out) :: center, subcenter + integer(c_signed_char), intent(out) :: master_version, local_version + integer(c_int) :: g2c_inq_msg + end function g2c_inq_msg + ! int g2c_inq_msg(int g2cid, int msg_num, unsigned char *discipline, int *num_fields, ! int *num_local, short *center, short *subcenter, unsigned char *master_version, ! unsigned char *local_version); diff --git a/src/g2cf.F90 b/src/g2cf.F90 index a46d3add..816e20bf 100644 --- a/src/g2cf.F90 +++ b/src/g2cf.F90 @@ -157,6 +157,43 @@ function g2cf_inq(g2id, num_msg) result(status) status = cstatus 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[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. + !> @param[out] center Originating center. + !> @param[out] subcenter Originating sub-center. + !> @param[out] master_version Master version. + !> @param[out] local_version Local version. + !> + !> @return 0 for success, error code otherwise. + !> + !> @author Edward Hartnett @date 2024-12-21 + function g2cf_inq_msg(g2id, msg_num, discipline, num_fields, & + num_local, center, subcenter, master_version, local_version) result(status) + use iso_c_binding + use g2c_interface + implicit none + + integer, intent(in) :: g2id + integer(c_int), intent(in) :: 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 + integer(c_signed_char), intent(out) :: master_version, local_version + integer :: status + + integer(c_int) :: cg2id, cnum_msg, cstatus + + cg2id = g2id + cstatus = g2c_inq(cg2id, cnum_msg) + !num_msg = cnum_msg + status = cstatus + end function g2cf_inq_msg + !> Close a GRIB2 file. !> !> @param g2id The ID of the open file