help([[
loads UFS Model prerequisites on Cactus and Dogwood
]])

-- First, look for libraries in "prod" space
PrgEnv_intel_ver=os.getenv("PrgEnv_intel_ver") or "8.1.0"
load(pathJoin("PrgEnv-intel", PrgEnv_intel_ver))

intel_ver=os.getenv("intel_ver") or "19.1.3.304"
load(pathJoin("intel", intel_ver))

craype_ver=os.getenv("craype_ver") or "2.7.13"
load(pathJoin("craype", craype_ver))

cray_mpich_ver=os.getenv("cray_mpich_ver") or "8.1.12"
load(pathJoin("cray-mpich", cray_mpich_ver))

cmake_ver=os.getenv("cmake_ver") or "3.20.2"
load(pathJoin("cmake", cmake_ver))

local ufs_modules = {
  {["jasper"]      = "2.0.25"},
  {["zlib"]        = "1.2.11"},
  {["libpng"]      = "1.6.37"},
  {["hdf5-D"]      = "1.14.0"},
  {["netcdf-D"]    = "4.9.2"},
  {["pio-D"]       = "2.5.10"},
  {["esmf-D"]      = "8.8.0"},
  {["fms-D"]       = "2024.01"},
  {["bacio"]       = "2.4.1"},
  {["crtm"]        = "2.4.0"},
  {["g2"]          = "3.5.1"},
  {["g2tmpl"]      = "1.13.0"},
  {["ip"]          = "4.0.0"},
  {["sp"]          = "2.3.3"},
  {["w3emc"]       = "2.12.0"},
  {["gftl-shared"] = "1.6.1"},
  {["mapl-D"]      = "2.53.0"},
  {["pnetcdf-D"]   = "1.12.2"},
  {["scotch"]      = "7.0.4"},
  {["zstd"]        = "1.5.0"},
}

for i = 1, #ufs_modules do
  for name, default_version in pairs(ufs_modules[i]) do
    local env_version_name = string.gsub(name, "-", "_") .. "_ver"
    load(pathJoin(name, os.getenv(env_version_name) or default_version))
  end
end

setenv("CC", "cc")
setenv("CXX", "CC")
setenv("FC", "ftn")
setenv("CMAKE_Platform", "wcoss2")

whatis("Description: UFS build environment")
