From 92c9d86df773543e0ee709904269c6c990bc28fa Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 21 Dec 2024 04:54:15 -0700 Subject: [PATCH 01/12] changing package file --- spack/package.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spack/package.py b/spack/package.py index f3830d88..079699f3 100644 --- a/spack/package.py +++ b/spack/package.py @@ -1,4 +1,4 @@ -# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other +# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) @@ -29,6 +29,9 @@ class G2(CMakePackage): version("3.4.5", sha256="c18e991c56964953d778632e2d74da13c4e78da35e8d04cb742a2ca4f52737b6") version("3.4.3", sha256="679ea99b225f08b168cbf10f4b29f529b5b011232f298a5442ce037ea84de17c") + depends_on("c", type="build") + depends_on("fortran", type="build") + variant("pic", default=True, description="Build with position-independent-code") variant( "precision", From 118f53d91ff91c1288013ad043600d922035053e Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 21 Dec 2024 05:52:03 -0700 Subject: [PATCH 02/12] changing package file --- spack/package.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spack/package.py b/spack/package.py index 079699f3..369e2c3e 100644 --- a/spack/package.py +++ b/spack/package.py @@ -43,9 +43,9 @@ class G2(CMakePackage): ) variant("w3emc", default=True, description="Enable GRIB1 through w3emc", when="@3.4.6:") variant("aec", default=True, description="Use AEC library", when="@develop") - variant("shared", default="False", when="@3.4.7:") - variant("openmp", default=False, description="Use OpenMP multithreading") - variant("utils", default=False, description="Build grib utilities") + variant("shared", default="False", description="Build shared library", when="@3.4.7:") + variant("openmp", default=False, description="Use OpenMP multithreading", when="@develop") + variant("utils", default=False, description="Build grib utilities", when="@develop") variant("g2c_compare", default=False, description="Enable copygb2 tests using g2c_compare") depends_on("jasper@:2.0.32", when="@:3.4.7") From 0124dabeb5d798b3f070e4dccee7142004be7987 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 21 Dec 2024 06:04:10 -0700 Subject: [PATCH 03/12] changing package file --- spack/package.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spack/package.py b/spack/package.py index 369e2c3e..118fcf03 100644 --- a/spack/package.py +++ b/spack/package.py @@ -46,7 +46,12 @@ class G2(CMakePackage): variant("shared", default="False", description="Build shared library", when="@3.4.7:") variant("openmp", default=False, description="Use OpenMP multithreading", when="@develop") variant("utils", default=False, description="Build grib utilities", when="@develop") - variant("g2c_compare", default=False, description="Enable copygb2 tests using g2c_compare") + variant( + "g2c_compare", + default=False, + description="Enable copygb2 tests using g2c_compare", + when="@2.0.0:", + ) depends_on("jasper@:2.0.32", when="@:3.4.7") depends_on("jasper") From e4c745c38e04a9e444bf0c5f18ba0a8979b2fc9e Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 21 Dec 2024 06:12:06 -0700 Subject: [PATCH 04/12] changing package file --- spack/package.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spack/package.py b/spack/package.py index 118fcf03..cede9213 100644 --- a/spack/package.py +++ b/spack/package.py @@ -58,10 +58,10 @@ class G2(CMakePackage): depends_on("g2c@2.0.0:", when="@develop") depends_on("g2c@2.0.0 +aec", when="+aec") depends_on("libpng") - depends_on("zlib-api") + depends_on("zlib-api", when="@develop") depends_on("bacio", when="@3.4.6:") - depends_on("ip") - depends_on("ip precision=d", when="^ip@4.1:") + depends_on("ip", when="@develop") + requires("^ip precision=d", when="^ip@4.1:") depends_on("sp", when="^ip@:4") depends_on("sp precision=d", when="^ip@:4 ^sp@2.4:") depends_on("g2c@2.0: +utils", when="+g2c_compare") From 122e7496ce221b6491e8ad382b0654c66c09ddb3 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 21 Dec 2024 06:18:27 -0700 Subject: [PATCH 05/12] changing package file --- spack/package.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/spack/package.py b/spack/package.py index cede9213..f6e2e814 100644 --- a/spack/package.py +++ b/spack/package.py @@ -92,10 +92,15 @@ def setup_run_environment(self, env): self.spec.variants["precision"].value if self.spec.satisfies("@3.4.6:") else ("4", "d") ) for suffix in precisions: - lib = find_libraries("libg2_" + suffix, root=self.prefix, shared=self.spec.satisfies("+shared"), recursive=True) + lib = find_libraries( + "libg2_" + suffix, + root=self.prefix, + shared=self.spec.satisfies("+shared"), + recursive=True, + ) env.set("G2_LIB" + suffix, lib[0]) env.set("G2_INC" + suffix, join_path(self.prefix, "include_" + suffix)) def check(self): - with working_dir(self.builder.build_directory): + with working_dir(self.build_directory): make("test") From fc5a725aaaacb370d39944a8762c726d5dd88f2e Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 21 Dec 2024 06:21:09 -0700 Subject: [PATCH 06/12] changing package file --- spack/package.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/spack/package.py b/spack/package.py index f6e2e814..cede9213 100644 --- a/spack/package.py +++ b/spack/package.py @@ -92,15 +92,10 @@ def setup_run_environment(self, env): self.spec.variants["precision"].value if self.spec.satisfies("@3.4.6:") else ("4", "d") ) for suffix in precisions: - lib = find_libraries( - "libg2_" + suffix, - root=self.prefix, - shared=self.spec.satisfies("+shared"), - recursive=True, - ) + lib = find_libraries("libg2_" + suffix, root=self.prefix, shared=self.spec.satisfies("+shared"), recursive=True) env.set("G2_LIB" + suffix, lib[0]) env.set("G2_INC" + suffix, join_path(self.prefix, "include_" + suffix)) def check(self): - with working_dir(self.build_directory): + with working_dir(self.builder.build_directory): make("test") From 77fd1dde5e34287531bea36ef17cae562dae05cf Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 21 Dec 2024 06:27:56 -0700 Subject: [PATCH 07/12] changing package file --- spack/package.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spack/package.py b/spack/package.py index cede9213..0b78d919 100644 --- a/spack/package.py +++ b/spack/package.py @@ -92,7 +92,12 @@ def setup_run_environment(self, env): self.spec.variants["precision"].value if self.spec.satisfies("@3.4.6:") else ("4", "d") ) for suffix in precisions: - lib = find_libraries("libg2_" + suffix, root=self.prefix, shared=self.spec.satisfies("+shared"), recursive=True) + lib = find_libraries( + "libg2_" + suffix, + root=self.prefix, + shared=self.spec.satisfies("+shared"), + recursive=True, + ) env.set("G2_LIB" + suffix, lib[0]) env.set("G2_INC" + suffix, join_path(self.prefix, "include_" + suffix)) From c125b429c63fb821fc4ec3f9c91c6b28a28a0e1d Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 21 Dec 2024 07:45:18 -0700 Subject: [PATCH 08/12] fortran wrapper for g2c_inq() --- src/g2c_interface.F90 | 8 ++++++++ src/g2cf.F90 | 24 ++++++++++++++++++++++++ tests/test_g2cf.F90 | 8 ++++---- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/g2c_interface.F90 b/src/g2c_interface.F90 index b97d3737..8418a99f 100644 --- a/src/g2c_interface.F90 +++ b/src/g2c_interface.F90 @@ -23,6 +23,13 @@ function g2c_open_index(data_file, index_file, mode, g2cid) bind(c) integer(c_int) :: g2c_open_index end function g2c_open_index + function g2c_inq(g2id, num_msg) bind(c) + use iso_c_binding + integer(c_int), value :: g2id + integer(c_int), intent(out) :: num_msg + integer(c_int) :: g2c_inq + end function g2c_inq + ! int g2c_inq(int g2cid, int *num_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, @@ -32,6 +39,7 @@ function g2c_close(g2id) bind(c) integer(c_int), value :: g2id integer(c_int) :: g2c_close end function g2c_close + function g2c_set_log_level(log_level) bind(c) use iso_c_binding integer(c_int), intent(in) :: log_level diff --git a/src/g2cf.F90 b/src/g2cf.F90 index faf96440..ee318fec 100644 --- a/src/g2cf.F90 +++ b/src/g2cf.F90 @@ -132,6 +132,30 @@ function g2cf_open_index(data_file, index_file, mode, g2cid) result (status) status = cstatus end function g2cf_open_index + !> Close a GRIB2 file. + !> + !> @param g2id The ID of the open file + !> + !> @return 0 for success, error code otherwise. + !> + !> @author Edward Hartnett @date 2024-06-12 + function g2cf_inq(g2id, num_msg) result(status) + use iso_c_binding + use g2c_interface + implicit none + + integer, intent(in) :: g2id + integer(c_int), intent(out) :: num_msg + 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 + !> Close a GRIB2 file. !> !> @param g2id The ID of the open file diff --git a/tests/test_g2cf.F90 b/tests/test_g2cf.F90 index 0e284f1a..cb6e2aa0 100644 --- a/tests/test_g2cf.F90 +++ b/tests/test_g2cf.F90 @@ -21,10 +21,10 @@ program test_g2cf ierr = g2cf_open(fileName, 0, g2cid) if (ierr .ne. 0) stop 2 - ! ! Check number of messages. - ! ierr = g2cf_inq(g2cid, num_msg) - ! if (ierr .ne. 0) stop 10 - ! if (num_msg .ne. 19) stop 11 + ! Check number of messages. + ierr = g2cf_inq(g2cid, num_msg) + if (ierr .ne. 0) stop 10 + if (num_msg .ne. 19) stop 11 ! ! Check the last message. ! ierr = g2cf_inq_msg(g2cid, 19, discipline, num_fields, num_local, center, subcenter, & From df1cf259fa43a6cfb2b752155d572aa5faaf8166 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 21 Dec 2024 08:27:02 -0700 Subject: [PATCH 09/12] fortran wrapper for g2c_inq() --- src/g2cf.F90 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/g2cf.F90 b/src/g2cf.F90 index ee318fec..a46d3add 100644 --- a/src/g2cf.F90 +++ b/src/g2cf.F90 @@ -132,13 +132,14 @@ function g2cf_open_index(data_file, index_file, mode, g2cid) result (status) status = cstatus end function g2cf_open_index - !> Close a GRIB2 file. + !> Learn how many messages are in a GRIB2 file. !> !> @param g2id The ID of the open file + !> @param num_msg The number of messages in the file. !> !> @return 0 for success, error code otherwise. !> - !> @author Edward Hartnett @date 2024-06-12 + !> @author Edward Hartnett @date 2024-12-21 function g2cf_inq(g2id, num_msg) result(status) use iso_c_binding use g2c_interface From cd05c3da86c053c2848d8ddc8138286a2e84e83e Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 21 Dec 2024 08:40:56 -0700 Subject: [PATCH 10/12] 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 From 5960bd7d6158c0732c85b5cba9567bccd61ca5dd Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 21 Dec 2024 09:43:29 -0700 Subject: [PATCH 11/12] more progress --- src/g2cf.F90 | 33 ++++++++++++++++++++++----------- tests/test_g2cf.F90 | 10 +++++----- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/g2cf.F90 b/src/g2cf.F90 index 816e20bf..4e7a3962 100644 --- a/src/g2cf.F90 +++ b/src/g2cf.F90 @@ -146,7 +146,7 @@ function g2cf_inq(g2id, num_msg) result(status) implicit none integer, intent(in) :: g2id - integer(c_int), intent(out) :: num_msg + integer, intent(out) :: num_msg integer :: status integer(c_int) :: cg2id, cnum_msg, cstatus @@ -178,19 +178,30 @@ function g2cf_inq_msg(g2id, msg_num, discipline, num_fields, & 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, intent(in) :: g2id, msg_num + integer, 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 :: status - - integer(c_int) :: cg2id, cnum_msg, cstatus + + integer(c_int) :: cg2id, cmsg_num, cstatus + integer(c_signed_char) :: cdiscipline + integer(c_int) :: cnum_fields, cnum_local + integer(c_short) :: ccenter, csubcenter + integer(c_signed_char) :: cmaster_version, clocal_version cg2id = g2id - cstatus = g2c_inq(cg2id, cnum_msg) - !num_msg = cnum_msg + cmsg_num = msg_num + cstatus = g2c_inq_msg(cg2id, cmsg_num, cdiscipline, cnum_fields, & + cnum_local, ccenter, csubcenter, cmaster_version, clocal_version) + discipline = cdiscipline + num_fields = cnum_fields + num_local = cnum_local + center = ccenter + subcenter = csubcenter + master_version = cmaster_version + local_version = clocal_version status = cstatus end function g2cf_inq_msg diff --git a/tests/test_g2cf.F90 b/tests/test_g2cf.F90 index cb6e2aa0..474d3da9 100644 --- a/tests/test_g2cf.F90 +++ b/tests/test_g2cf.F90 @@ -26,11 +26,11 @@ program test_g2cf if (ierr .ne. 0) stop 10 if (num_msg .ne. 19) stop 11 - ! ! Check the last message. - ! ierr = g2cf_inq_msg(g2cid, 19, 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 + ! Check the last message. + ierr = g2cf_inq_msg(g2cid, 19, 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 ! Close the file. ierr = g2cf_close(g2cid) From 6b416813286d36cf7e9d27930671c6e5d9404334 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sat, 21 Dec 2024 09:58:21 -0700 Subject: [PATCH 12/12] more g2c API --- src/g2c_interface.F90 | 2 +- src/g2cf.F90 | 10 ++++++---- tests/test_g2cf.F90 | 4 +++- 3 files changed, 10 insertions(+), 6 deletions(-) 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