summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/crtm-fix/package.py
blob: ef46e99df00eaf40df35cdac9927ef914e58df71 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 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)

import os

from spack.package import *


class CrtmFix(Package):
    """CRTM coefficient files"""

    homepage = "https://github.com/NOAA-EMC/crtm"
    url = "ftp://ftp.ssec.wisc.edu/pub/s4/CRTM/fix_REL-2.3.0_emc.tgz"

    maintainers(
        "BenjaminTJohnson", "edwardhartnett", "AlexanderRichert-NOAA", "Hang-Lei-NOAA", "climbfuji"
    )

    version("2.4.0_emc", sha256="d0f1b2ae2905457f4c3731746892aaa8f6b84ee0691f6228dfbe48917df1e85e")
    version("2.3.0_emc", sha256="1452af2d1d11d57ef3c57b6b861646541e7042a9b0f3c230f9a82854d7e90924")

    variant("big_endian", default=True, description="Install big_endian fix files")
    variant("little_endian", default=False, description="Install little endian fix files")
    variant("netcdf", default=True, description="Install netcdf fix files")

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

    def url_for_version(self, version):
        url = "ftp://ftp.ssec.wisc.edu/pub/s4/CRTM/fix_REL-{}.tgz"
        return url.format(version)

    def install(self, spec, prefix):
        spec = self.spec
        mkdir(self.prefix.fix)

        endian_dirs = []
        if "+big_endian" in spec:
            endian_dirs.append("Big_Endian")
        elif "+little_endian" in spec:
            endian_dirs.append("Little_Endian")

        if "+netcdf" in spec:
            endian_dirs.extend(["netcdf", "netCDF"])

        fix_files = []
        for d in endian_dirs:
            fix_files = fix_files + find(".", "*/{}/*".format(d))

        # Big_Endian amsua_metop-c.SpcCoeff.bin is incorrect
        # Little_Endian amsua_metop-c_v2.SpcCoeff.bin is what it's supposed to be.
        # Remove the incorrect file, and install it as noACC,, then install
        # correct file under new name.
        if "+big_endian" in spec and spec.version == Version("2.4.0_emc"):
            remove_path = join_path(
                os.getcwd(), "fix", "SpcCoeff", "Big_Endian", "amsua_metop-c.SpcCoeff.bin"
            )
            fix_files.remove(remove_path)

            # This file is incorrect, install it as a different name.
            install(
                join_path("fix", "SpcCoeff", "Big_Endian", "amsua_metop-c.SpcCoeff.bin"),
                join_path(self.prefix.fix, "amsua_metop-c.SpcCoeff.noACC.bin"),
            )

            # This "Little_Endian" file is actually the correct one.
            install(
                join_path("fix", "SpcCoeff", "Little_Endian", "amsua_metop-c_v2.SpcCoeff.bin"),
                join_path(self.prefix.fix, "amsua_metop-c.SpcCoeff.bin"),
            )

        for f in fix_files:
            install(f, self.prefix.fix)

    def setup_run_environment(self, env):
        env.set("CRTM_FIX", self.prefix.fix)