Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recipe for gen_domain tools from CIME #26334

Merged
merged 1 commit into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions recipes/gen_domain/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 3.18)
project(
cime_gen_domain
VERSION $ENV{PKG_VERSION}
LANGUAGES Fortran)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

include("${CMAKE_SOURCE_DIR}/cmake_macros/gnu.cmake")

find_package(NETCDF REQUIRED)

message(STATUS "netcdf_f_incdir=${netcdf_f_incdir}")
message(STATUS "netcdf_f_libs=${netcdf_f_libs}")

SET(SRC ${CMAKE_SOURCE_DIR}/tools/mapping/gen_domain_files/src)

include_directories(${netcdf_f_incdir})
add_definitions(-DLINUX)
add_executable(gen_domain ${SRC}/gen_domain.F90)
target_link_libraries(gen_domain ${netcdf_f_libs})

install(TARGETS gen_domain DESTINATION bin)
17 changes: 17 additions & 0 deletions recipes/gen_domain/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -x
set -e

cp -r ${RECIPE_DIR}/cmake ${RECIPE_DIR}/cmake_macros ${RECIPE_DIR}/CMakeLists.txt .

rm -rf build
mkdir build
cd build
cmake \
-D CMAKE_INSTALL_PREFIX="${PREFIX}" \
-D NETCDF_PATH="${PREFIX}" \
-D CMAKE_BUILD_TYPE=Release \
..
cmake --build .
cmake --install .
79 changes: 79 additions & 0 deletions recipes/gen_domain/cmake/FindNETCDF.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# - Try to find Netcdf

function(get_netcdf_libs ncpath nfpath)

set(ncconfig ${ncpath}/bin/nc-config)
set(nfconfig ${nfpath}/bin/nf-config)

# Get C libs
if (EXISTS ${ncconfig})
execute_process(COMMAND ${ncconfig} --libs OUTPUT_VARIABLE nclibs OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()

# Fall back to find_library
if (NOT nclibs)
find_library(nclibs_temp netcdf REQUIRED HINTS ${ncpath}/lib ${ncpath}/lib64)
set(nclibs ${nclibs_temp})
endif()

# Get fortran libs
if (EXISTS ${nfconfig})
execute_process(COMMAND ${nfconfig} --flibs OUTPUT_VARIABLE nflibs OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()

if (NOT nflibs)
find_library(nflibs_temp netcdff REQUIRED HINTS ${nfpath}/lib ${nfpath}/lib64)
set(nflibs ${nflibs_temp})
endif()

set(netcdf_c_libs ${nclibs} PARENT_SCOPE)
set(netcdf_f_libs ${nflibs} PARENT_SCOPE)
endfunction()

function(create_netcdf_target)

# Grab things from env
set(NETCDF_PATH $ENV{NETCDF_PATH})
set(NETCDF_C_PATH $ENV{NETCDF_C_PATH})
set(NETCDF_FORTRAN_PATH $ENV{NETCDF_FORTRAN_PATH})

if (NETCDF_C_PATH)
# Sanity checks
if (NOT NETCDF_FORTRAN_PATH)
message(FATAL_ERROR "NETCDF_C_PATH specified without NETCDF_FORTRAN_PATH")
endif()
if (NOT EXISTS ${NETCDF_C_PATH}/lib AND NOT EXISTS ${NETCDF_C_PATH}/lib64)
message(FATAL_ERROR "NETCDF_C_PATH does not contain a lib or lib64 directory")
endif ()
if (NOT EXISTS ${NETCDF_FORTRAN_PATH}/lib AND NOT EXISTS ${NETCDF_FORTRAN_PATH}/lib64)
message(FATAL_ERROR "NETCDF_FORTRAN_PATH does not contain a lib or lib64 directory")
endif ()

get_netcdf_libs(${NETCDF_C_PATH} ${NETCDF_FORTRAN_PATH})
find_path (netcdf_c_incdir netcdf.h REQUIRED HINTS ${NETCDF_C_PATH}/include)
find_path (netcdf_f_incdir netcdf.inc REQUIRED HINTS ${NETCDF_FORTRAN_PATH}/include)

elseif (NETCDF_FORTRAN_PATH)
message(FATAL_ERROR "NETCDF_FORTRAN_PATH specified without NETCDF_C_PATH")

elseif (NETCDF_PATH)
# Sanity checks
if (NOT EXISTS ${NETCDF_PATH}/lib AND NOT EXISTS ${NETCDF_PATH}/lib64)
message(FATAL_ERROR "NETCDF_PATH does not contain a lib or lib64 directory")
endif ()

get_netcdf_libs(${NETCDF_PATH} ${NETCDF_PATH})
find_path(netcdf_c_incdir netcdf.h REQUIRED HINTS ${NETCDF_PATH}/include)
find_path(netcdf_f_incdir netcdf.inc REQUIRED HINTS ${NETCDF_PATH}/include)

else()
message(FATAL_ERROR "NETCDF not found: Define NETCDF_PATH or NETCDF_C_PATH and NETCDF_FORTRAN_PATH in config_machines.xml or config_compilers.xml")
endif()

set(netcdf_c_incdir ${netcdf_c_incdir})
set(netcdf_f_incdir ${netcdf_f_incdir})
set(netcdf_c_libs ${netcdf_c_libs} PARENT_SCOPE)
set(netcdf_f_libs ${netcdf_f_libs} PARENT_SCOPE)
endfunction()

create_netcdf_target()
6 changes: 6 additions & 0 deletions recipes/gen_domain/cmake_macros/gnu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
string(APPEND CMAKE_Fortran_FLAGS " -fconvert=big-endian -ffree-line-length-none -ffixed-line-length-none")
if (CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
string(APPEND CMAKE_Fortran_FLAGS " -fallow-argument-mismatch")
endif()
string(APPEND CMAKE_Fortran_FORMAT_FIXED_FLAG " -ffixed-form")
string(APPEND CMAKE_Fortran_FORMAT_FREE_FLAG " -ffree-form")
51 changes: 51 additions & 0 deletions recipes/gen_domain/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{% set name = "cime_gen_domain" %}
{% set version = "6.0.234" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
- url: https://github.com/ESMCI/cime/archive/refs/tags/cime{{ version }}.tar.gz
sha256: 9596339ac0dcec4d2b2817d526ea8eabc27bdfcd6903bd58a14add21f2f1afcd

build:
skip: true # [not linux]
number: 0

requirements:
build:
- {{ compiler('fortran') }}
- {{ stdlib("c") }}
- cmake
- make
host:
- netcdf-fortran
- netcdf-fortran * nompi_*

test:
requires:
- curl
- nccmp
commands:
- curl -O https://web.lcrc.anl.gov/public/e3sm/inputdata/cpl/gridmaps/IcoswISC30E3r5/map_IcoswISC30E3r5_to_ne30pg2_traave.20231121.nc
- curl -O https://web.lcrc.anl.gov/public/e3sm/inputdata/share/domains/domain.ocn.IcoswISC30E3r5.231121.nc
- curl -O https://web.lcrc.anl.gov/public/e3sm/inputdata/share/domains/domain.lnd.ne30pg2_IcoswISC30E3r5.231121.nc
- curl -O https://web.lcrc.anl.gov/public/e3sm/inputdata/share/domains/domain.ocn.ne30pg2_IcoswISC30E3r5.231121.nc
- gen_domain -o IcoswISC30E3r5 -l ne30pg2 -m map_IcoswISC30E3r5_to_ne30pg2_traave.20231121.nc
- nccmp -d -T 0.0 domain.ocn.IcoswISC30E3r5.*.nc
- nccmp -d -T 0.0 domain.lnd.ne30pg2_IcoswISC30E3r5.*.nc
- nccmp -d -T 0.0 domain.ocn.ne30pg2_IcoswISC30E3r5.*.nc

about:
home: https://github.com/ESMCI/cime
license: NCSA
license_family: OTHER
license_file: LICENSE.TXT
summary: The gen_domain tool from Common Infrastructure for Modeling the Earth (CIME)
doc_url: http://esmci.github.io/cime
dev_url: https://github.com/ESMCI/cime

extra:
recipe-maintainers:
- xylar