Skip to content

Commit 672c83c

Browse files
Merge pull request #510 from AlexanderRichert-NOAA/crtm_wgrib2
Update crtm(-fix), wgrib2
2 parents cb171b7 + 1c3d3d5 commit 672c83c

File tree

3 files changed

+159
-82
lines changed

3 files changed

+159
-82
lines changed

var/spack/repos/builtin/packages/crtm-fix/package.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
2-
# Spack Project Developers. See the top-level COPYRIGHT file for details.
1+
# Copyright Spack Project Developers. See COPYRIGHT file for details.
32
#
43
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
54

@@ -18,6 +17,7 @@ class CrtmFix(Package):
1817
"BenjaminTJohnson", "edwardhartnett", "AlexanderRichert-NOAA", "Hang-Lei-NOAA", "climbfuji"
1918
)
2019

20+
version("3.1.1.2", sha256="c2e289f690d82a3aa82d2239cbb567cd514fa0f476a8b498ceba11670685ca66")
2121
version(
2222
"2.4.0.1_emc", sha256="6e4005b780435c8e280d6bfa23808d8f12609dfd72f77717d046d4795cac0457"
2323
)
@@ -27,6 +27,7 @@ class CrtmFix(Package):
2727
variant("big_endian", default=True, description="Install big_endian fix files")
2828
variant("little_endian", default=False, description="Install little endian fix files")
2929
variant("netcdf", default=True, description="Install netcdf fix files")
30+
variant("testfiles", default=False, description="Install test files", when="@3:")
3031

3132
conflicts("+big_endian", when="+little_endian", msg="big_endian and little_endian conflict")
3233

@@ -52,7 +53,11 @@ def install(self, spec, prefix):
5253

5354
fix_files = []
5455
for d in endian_dirs:
55-
fix_files = fix_files + find(".", "*/{}/*".format(d))
56+
fix_files = fix_files + find(".", "*/{}/*".format(d), recursive=False)
57+
fix_files = fix_files + find(".", "*/*/{}/*".format(d), recursive=False)
58+
if self.spec.satisfies("~testfiles"):
59+
fix_files = [f for f in fix_files if "/fix/test_data/" not in f]
60+
fix_files = [f for f in fix_files if os.path.isfile(f)]
5661

5762
# Big_Endian amsua_metop-c.SpcCoeff.bin is incorrect
5863
# Little_Endian amsua_metop-c_v2.SpcCoeff.bin is what it's supposed to be.

var/spack/repos/builtin/packages/crtm/package.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Crtm(CMakePackage):
4141
depends_on("crtm-fix@2.3.0_emc", when="@2.3.0 +fix")
4242
depends_on("crtm-fix@2.4.0_emc", when="@=2.4.0 +fix")
4343
depends_on("crtm-fix@2.4.0.1_emc", when="@2.4.0.1 +fix")
44+
depends_on("crtm-fix@3.1.1", when="@3.1.1 +fix")
4445

4546
depends_on("ecbuild", type=("build"), when="@v2.3-jedi.4")
4647
depends_on("ecbuild", type=("build"), when="@v2.4-jedi.1")
@@ -51,6 +52,9 @@ class Crtm(CMakePackage):
5152

5253
license("CC0-1.0")
5354

55+
version(
56+
"v3.1.1-build1", sha256="1ed49e594da5d3769cbaa52cc7fc19c1bb0325ee6324f6057227c31e2d95ca67"
57+
)
5458
version(
5559
"v3.1.0-skylabv8",
5660
sha256="a475c8a444072aef1e8c2babba3d12f13ab0fb6c7ecab88edad57130839e29ff",
@@ -81,8 +85,9 @@ class Crtm(CMakePackage):
8185
depends_on("fortran", type="build") # generated
8286

8387
def url_for_version(self, version):
84-
if self.spec.satisfies("@v3") or version >= Version("3.0.0"):
85-
return f"https://github.com/JCSDA/crtmv3/archive/refs/tags/{version}.tar.gz"
88+
if version > Version("v3") or version >= Version("3"):
89+
fmtversion = str(version).replace("-build", "+build")
90+
return f"https://github.com/JCSDA/CRTMv3/archive/refs/tags/{fmtversion}.tar.gz"
8691
else:
8792
return f"https://github.com/JCSDA/crtm/archive/refs/tags/{version}.tar.gz"
8893

Lines changed: 144 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,68 @@
1-
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
2-
# Spack Project Developers. See the top-level COPYRIGHT file for details.
1+
# Copyright Spack Project Developers. See COPYRIGHT file for details.
32
#
43
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
54

6-
import os
75
import re
86

7+
import spack.build_systems.cmake
8+
import spack.build_systems.makefile
99
from spack.package import *
1010

11-
12-
class Wgrib2(MakefilePackage):
11+
variant_map_common = {
12+
"netcdf3": "USE_NETCDF3",
13+
"netcdf4": "USE_NETCDF4",
14+
"mysql": "USE_MYSQL",
15+
"udf": "USE_UDF",
16+
"regex": "USE_REGEX",
17+
"tigge": "USE_TIGGE",
18+
"proj4": "USE_PROJ4",
19+
"aec": "USE_AEC",
20+
"g2c": "USE_G2CLIB",
21+
"png": "USE_PNG",
22+
"jasper": "USE_JASPER",
23+
"openmp": "USE_OPENMP",
24+
"wmo_validation": "USE_WMO_VALIDATION",
25+
"ipolates": "USE_IPOLATES",
26+
"disable_alarm": "DISABLE_ALARM",
27+
"fortran_api": "MAKE_FTN_API",
28+
"disable_stat": "DISABLE_STAT",
29+
"openjpeg": "USE_OPENJPEG",
30+
}
31+
32+
variant_map_makefile = {"spectral": "USE_SPECTRAL"}
33+
34+
variant_map_cmake = {
35+
"netcdf": "USE_NETCDF",
36+
"disable_timezone": "DISABLE_TIMEZONE",
37+
"enable_docs": "ENABLE_DOCS",
38+
}
39+
40+
variant_map_makefile.update(variant_map_common)
41+
variant_map_cmake.update(variant_map_common)
42+
43+
44+
class Wgrib2(MakefilePackage, CMakePackage):
1345
"""Utility for interacting with GRIB2 files"""
1446

1547
homepage = "https://www.cpc.ncep.noaa.gov/products/wesley/wgrib2"
1648
url = "https://www.ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz.v2.0.8"
49+
git = "https://github.com/NOAA-EMC/wgrib2"
1750

18-
maintainers("t-brown", "AlexanderRichert-NOAA", "Hang-Lei-NOAA", "edwardhartnett")
19-
20-
version(
21-
"3.1.1",
22-
sha256="9236f6afddad76d868c2cfdf5c4227f5bdda5e85ae40c18bafb37218e49bc04a",
23-
extension="tar.gz",
51+
maintainers(
52+
"AlysonStahl-NOAA", "t-brown", "AlexanderRichert-NOAA", "Hang-Lei-NOAA", "edwardhartnett"
2453
)
25-
version(
26-
"3.1.0",
27-
sha256="5757ef9016b19ae87491918e0853dce2d3616b14f8c42efe3b2f41219c16b78f",
28-
extension="tar.gz",
54+
55+
build_system(
56+
conditional("cmake", when="@3.2:"), conditional("makefile", when="@:3.1"), default="cmake"
2957
)
58+
59+
version("develop", branch="develop")
60+
version("3.5.0", sha256="b27b48228442a08bddc3d511d0c6335afca47252ae9f0e41ef6948f804afa3a1")
61+
version("3.4.0", sha256="ecbce2209c09bd63f1bca824f58a60aa89db6762603bda7d7d3fa2148b4a0536")
62+
version("3.3.0", sha256="010827fba9c31f05807e02375240950927e9e51379e1444388153284f08f58e2")
63+
version("3.2.0", sha256="ac3ace77a32c2809cbc4538608ad64aabda2c9c1e44e7851da79764a6eb3c369")
64+
version("3.1.1", sha256="9236f6afddad76d868c2cfdf5c4227f5bdda5e85ae40c18bafb37218e49bc04a")
65+
version("3.1.0", sha256="5757ef9016b19ae87491918e0853dce2d3616b14f8c42efe3b2f41219c16b78f")
3066
version(
3167
"2.0.8",
3268
sha256="5e6a0d6807591aa2a190d35401606f7e903d5485719655aea1c4866cc2828160",
@@ -38,27 +74,48 @@ class Wgrib2(MakefilePackage):
3874
extension="tar.gz",
3975
)
4076

41-
depends_on("c", type="build") # generated
42-
depends_on("fortran", type="build") # generated
77+
def url_for_version(self, version):
78+
if version >= Version("3.2.0"):
79+
url_fmt = "https://github.com/NOAA-EMC/wgrib2/archive/refs/tags/v{0}.tar.gz"
80+
else:
81+
url_fmt = "https://www.ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz.v{0}"
82+
return url_fmt.format(version)
4383

44-
variant("netcdf3", default=True, description="Link in netcdf3 library to write netcdf3 files")
4584
variant(
46-
"netcdf4", default=False, description="Link in netcdf4 library to write netcdf3/4 files"
85+
"netcdf3",
86+
default=True,
87+
description="Link in netcdf3 library to write netcdf3 files",
88+
when="@:3.1",
4789
)
4890
variant(
49-
"ipolates",
50-
default="3",
51-
description="Use to interpolate to new grids (0 = OFF, 1 = ip, 3 = ip2)",
52-
values=("0", "1", "3"),
91+
"netcdf4",
92+
default=False,
93+
description="Link in netcdf4 library to write netcdf3/4 files",
94+
when="@:3.3",
5395
)
54-
variant("spectral", default=False, description="Spectral interpolation in -new_grid")
96+
variant(
97+
"netcdf",
98+
default=False,
99+
description="Link in netcdf4 library to write netcdf3/4 files",
100+
when="@3.4:",
101+
)
102+
variant("ipolates", default=False, description="Use to interpolate to new grids")
103+
variant(
104+
"spectral", default=False, description="Spectral interpolation in -new_grid", when="@:3.1"
105+
)
106+
# Not currently working for @3.2:
55107
variant(
56108
"fortran_api",
57109
default=True,
58110
description="Make wgrib2api which allows fortran code to read/write grib2",
59111
)
112+
# Not currently working for @3.2:
113+
# variant("lib", default=True, description="Build library", when="@3.2:")
60114
variant(
61-
"mysql", default=False, description="Link in interface to MySQL to write to mysql database"
115+
"mysql",
116+
default=False,
117+
description="Link in interface to MySQL to write to mysql database",
118+
when="@:3.1",
62119
)
63120
variant(
64121
"udf",
@@ -67,11 +124,21 @@ class Wgrib2(MakefilePackage):
67124
)
68125
variant("regex", default=True, description="Use regular expression library (POSIX-2)")
69126
variant("tigge", default=True, description="Ability for TIGGE-like variable names")
70-
variant("proj4", default=False, description="The proj4 library is used to verify gctpc.")
127+
variant(
128+
"proj4",
129+
default=False,
130+
description="The proj4 library is used to verify gctpc.",
131+
when="@:3.1",
132+
)
71133
variant(
72134
"aec", default=True, description="Use the libaec library for packing with GRIB2 template"
73135
)
74-
variant("g2c", default=False, description="Include NCEP g2clib (mainly for testing purposes)")
136+
variant(
137+
"g2c",
138+
default=False,
139+
description="Include NCEP g2clib (mainly for testing purposes)",
140+
when="@:3.1",
141+
)
75142
variant(
76143
"disable_timezone", default=False, description="Some machines do not support timezones"
77144
)
@@ -84,62 +151,73 @@ class Wgrib2(MakefilePackage):
84151
variant("jasper", default=True, description="JPEG compression using Jasper")
85152
variant("openmp", default=True, description="OpenMP parallelization")
86153
variant("wmo_validation", default=False, description="WMO validation")
154+
# variant("shared", default=False, description="Enable shared library", when="+lib")
155+
variant("disable_stat", default=False, description="Disable POSIX feature", when="@:3.1")
156+
variant("openjpeg", default=False, description="Enable OpenJPEG")
157+
variant(
158+
"enable_docs", default=False, description="Build doxygen documentation", when="@3.4.0:"
159+
)
87160

88161
conflicts("+netcdf3", when="+netcdf4")
162+
conflicts("+netcdf3", when="+netcdf")
89163
conflicts("+openmp", when="%apple-clang")
90164

91-
depends_on("wget", type=("build"), when="+netcdf4")
92-
# makefile behavior with shell commands/character escapes breaks with gmake@4.3:
93-
depends_on("gmake@:4.2")
94-
95-
variant_map = {
96-
"netcdf3": "USE_NETCDF3",
97-
"netcdf4": "USE_NETCDF4",
98-
"spectral": "USE_SPECTRAL",
99-
"mysql": "USE_MYSQL",
100-
"udf": "USE_UDF",
101-
"regex": "USE_REGEX",
102-
"tigge": "USE_TIGGE",
103-
"proj4": "USE_PROJ4",
104-
"aec": "USE_AEC",
105-
"g2c": "USE_G2CLIB",
106-
"png": "USE_PNG",
107-
"jasper": "USE_JASPER",
108-
"openmp": "USE_OPENMP",
109-
"wmo_validation": "USE_WMO_VALIDATION",
110-
"ipolates": "USE_IPOLATES",
111-
"disable_timezone": "DISABLE_TIMEZONE",
112-
"disable_alarm": "DISABLE_ALARM",
113-
"fortran_api": "MAKE_FTN_API",
114-
}
115-
116-
# Disable parallel build
117-
parallel = False
165+
depends_on("ip@5.1:", when="@3.5: +ipolates")
166+
depends_on("lapack", when="@3.5: +ipolates")
167+
depends_on("libaec@1.0.6:", when="@3.2: +aec")
168+
depends_on("netcdf-c", when="@3.2: +netcdf4")
169+
depends_on("jasper@:2", when="@3.2:3.4 +jasper")
170+
depends_on("g2c", when="@3.5: +jasper")
171+
depends_on("zlib-api", when="@3.2: +png")
172+
depends_on("libpng", when="@3.2: +png")
173+
depends_on("openjpeg", when="@3.2:3.4 +openjpeg")
174+
depends_on("g2c +openjpeg", when="@3.5: +openjpeg")
175+
requires("^g2c@1.9:", when="@3.5: ^g2c")
176+
177+
@when("@:2 ^gmake@4.2:")
178+
def patch(self):
179+
filter_file(r"\\#define", "#define", "makefile")
118180

119181
# Use Spack compiler wrapper flags
120182
def inject_flags(self, name, flags):
121-
spec = self.spec
122183
if name == "cflags":
123-
if spec.satisfies("%apple-clang"):
184+
if self.spec.compiler.name == "apple-clang":
124185
flags.append("-Wno-error=implicit-function-declaration")
125186

126187
# When mixing Clang/gfortran need to link to -lgfortran
127188
# Find this by searching for gfortran/../lib
128-
if spec.satisfies("%apple-clang") or spec.satisfies("%clang"):
189+
if self.spec.compiler.name in ["apple-clang", "clang"]:
129190
if "gfortran" in self.compiler.fc:
130191
output = Executable(self.compiler.fc)("-###", output=str, error=str)
131192
libdir = re.search("--libdir=(.+?) ", output).group(1)
132193
flags.append("-L{}".format(libdir))
133194

134195
return (flags, None, None)
135196

197+
198+
class CMakeBuilder(spack.build_systems.cmake.CMakeBuilder):
199+
# Disable parallel build
200+
parallel = False
201+
202+
def cmake_args(self):
203+
args = [self.define_from_variant(variant_map_cmake[k], k) for k in variant_map_cmake]
204+
# args.append(self.define_from_variant("BUILD_LIB", "lib"))
205+
# args.append(self.define_from_variant("BUILD_SHARED_LIB", "shared"))
206+
207+
return args
208+
209+
210+
class MakefileBuilder(spack.build_systems.makefile.MakefileBuilder):
211+
# Disable parallel build
212+
parallel = False
213+
136214
flag_handler = inject_flags
137215

138216
def url_for_version(self, version):
139217
url = "https://www.ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz.v{}"
140218
return url.format(version)
141219

142-
def edit(self, spec, prefix):
220+
def edit(self, pkg, spec, prefix):
143221
makefile = FileFilter("makefile")
144222

145223
# ifort no longer accepts -openmp
@@ -151,31 +229,20 @@ def edit(self, spec, prefix):
151229
if spec.satisfies("%clang") or spec.satisfies("%apple-clang"):
152230
makefile.filter(r"--fast-math", "-ffast-math")
153231

154-
for variant_name, makefile_option in self.variant_map.items():
232+
for variant_name, makefile_option in variant_map_makefile.items():
155233
value = int(spec.variants[variant_name].value)
156234
makefile.filter(r"^%s=.*" % makefile_option, "{}={}".format(makefile_option, value))
157235

158236
def setup_build_environment(self, env):
159-
spec = self.spec
160-
if spec.satisfies("%oneapi") or spec.satisfies("%intel"):
237+
if self.spec.compiler.name in ["oneapi", "intel"]:
161238
comp_sys = "intel_linux"
162-
elif spec.satisfies("%gcc") or spec.satisfies("%clang") or spec.satisfies("%apple-clang"):
239+
elif self.spec.compiler.name in ["gcc", "clang", "apple-clang"]:
163240
comp_sys = "gnu_linux"
164241

165242
env.set("COMP_SYS", comp_sys)
166243

167-
def build(self, spec, prefix):
168-
# Get source files for netCDF4 builds
169-
if self.spec.satisfies("+netcdf4"):
170-
with working_dir(self.build_directory):
171-
os.system(
172-
"wget https://downloads.unidata.ucar.edu/netcdf-c/4.8.1/netcdf-c-4.8.1.tar.gz"
173-
)
174-
os.system(
175-
"wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.12/hdf5-1.12.1/src/hdf5-1.12.1.tar.gz"
176-
)
177-
178-
make()
244+
def build(self, pkg, spec, prefix):
245+
make("-j1")
179246

180247
# Move wgrib2 executable to a tempoary directory
181248
mkdir("install")
@@ -190,7 +257,7 @@ def build(self, spec, prefix):
190257
makefile = FileFilter("makefile")
191258

192259
# Disable all options
193-
for variant_name, makefile_option in self.variant_map.items():
260+
for variant_name, makefile_option in variant_map_makefile.items():
194261
value = 0
195262
makefile.filter(
196263
r"^%s=.*" % makefile_option, "{}={}".format(makefile_option, value)
@@ -199,13 +266,13 @@ def build(self, spec, prefix):
199266
# Need USE_REGEX in addition to MAKE_FTN_API to build lib
200267
makefile.filter(r"^MAKE_FTN_API=.*", "MAKE_FTN_API=1")
201268
makefile.filter(r"^USE_REGEX=.*", "USE_REGEX=1")
202-
make("lib")
269+
make("lib", "-j1")
203270
mkdir(join_path("install", "lib"))
204271
mkdir(join_path("install", "include"))
205272

206273
move(join_path("lib", "libwgrib2.a"), join_path("install", "lib"))
207274
move(join_path("lib", "wgrib2api.mod"), join_path("install", "include"))
208275
move(join_path("lib", "wgrib2lowapi.mod"), join_path("install", "include"))
209276

210-
def install(self, spec, prefix):
277+
def install(self, pkg, spec, prefix):
211278
install_tree("install/", prefix)

0 commit comments

Comments
 (0)