Skip to content

Commit 290ecc5

Browse files
authored
[metapackages] NetCDF (#1120)
2 parents 7535cab + 7fbaac1 commit 290ecc5

File tree

7 files changed

+136
-18
lines changed

7 files changed

+136
-18
lines changed

.github/workflows/meta.yml

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ on:
44
# On push, only run if any of the metapackage files has changed
55
push:
66
paths:
7-
- 'src/*meta*.f90'
7+
- 'src/*meta*.f90'
88
- 'src/fpm/*meta*.f90'
99
- 'src/fpm/manifest/*meta*.f90'
1010
- 'src/ci/meta_tests.sh'
1111
- 'src/.github/workflows/meta.yml'
12-
# Always run on PR or release
12+
# Always run on PR or release
1313
pull_request:
1414
release:
1515
types: [published]
1616
# Allow manual triggering
17-
workflow_dispatch:
17+
workflow_dispatch:
1818

1919
env:
2020
CI: "ON" # We can detect this in the build system and other vendors implement it
@@ -51,7 +51,7 @@ jobs:
5151

5252
- name: (Ubuntu/macOS) setup gcc version
5353
if: contains(matrix.os,'ubuntu') || contains(matrix.os,'macos')
54-
run: |
54+
run: |
5555
echo "GCC_V=14" >> $GITHUB_ENV
5656
5757
- name: (Windows) Install MSYS2
@@ -67,6 +67,8 @@ jobs:
6767
unzip
6868
curl
6969
hdf5
70+
netcdf
71+
netcdf-fortran
7072
7173
- name: (Windows) Setup VS Build environment
7274
if: contains(matrix.os,'windows') && contains(matrix.mpi,'intel')
@@ -84,7 +86,7 @@ jobs:
8486
Remove-Item "oneAPI" -Force -Recurse
8587
8688
- name: (Ubuntu) Install gfortran
87-
if: contains(matrix.os,'ubuntu')
89+
if: contains(matrix.os,'ubuntu')
8890
run: |
8991
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_V} 100 \
9092
--slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${GCC_V} \
@@ -94,13 +96,15 @@ jobs:
9496
if: contains(matrix.os,'ubuntu') && contains(matrix.mpi,'openmpi')
9597
run: |
9698
sudo apt-get update
97-
sudo apt install -y -q openmpi-bin libopenmpi-dev hwloc fabric libhdf5-dev libhdf5-fortran-102
99+
sudo apt install -y -q openmpi-bin libopenmpi-dev hwloc fabric libhdf5-dev \
100+
libhdf5-fortran-102 libnetcdf-dev libnetcdff-dev
98101
99102
- name: (Ubuntu) Install MPICH
100103
if: contains(matrix.os,'ubuntu') && contains(matrix.mpi,'mpich')
101104
run: |
102105
sudo apt-get update
103-
sudo apt install -y -q mpich hwloc fabric libhdf5-dev libhdf5-fortran-102
106+
sudo apt install -y -q mpich hwloc fabric libhdf5-dev libhdf5-fortran-102 \
107+
libnetcdf-dev libnetcdff-dev
104108
105109
- name: (Ubuntu) Retrieve Intel toolchain
106110
if: contains(matrix.os,'ubuntu') && contains(matrix.mpi,'intel')
@@ -115,16 +119,16 @@ jobs:
115119
uses: fortran-lang/[email protected]
116120
id: setup-fortran
117121
with:
118-
compiler: intel
119-
version: 2024.1.0
122+
compiler: intel
123+
version: 2024.1.0
120124

121-
- name: (Ubuntu) finalize oneAPI environment
125+
- name: (Ubuntu) finalize oneAPI environment
122126
if: contains(matrix.os,'ubuntu') && contains(matrix.mpi,'intel')
123127
run: |
124128
# Install MPI
125-
sudo apt-get install -y -q intel-oneapi-mpi-devel ninja-build cmake
129+
sudo apt-get install -y -q intel-oneapi-mpi-devel ninja-build cmake libcurl4-gnutls-dev
126130
source /opt/intel/oneapi/setvars.sh --force
127-
printenv >> $GITHUB_ENV
131+
printenv >> $GITHUB_ENV
128132
# To run HDF5 with oneAPI, we need to build it from source. Use CMake to generate pkg-config info
129133
curl -O -L https://github.com/HDFGroup/hdf5/archive/refs/tags/snapshot-1.14.tar.gz
130134
tar zxf snapshot-1.14.tar.gz
@@ -133,6 +137,17 @@ jobs:
133137
cd build
134138
make -j
135139
sudo make install
140+
curl -L https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.2.tar.gz -o - | tar xz
141+
cd netcdf-c-4.9.2
142+
CC=icx CXX=icpx FC=ifx ./configure --prefix=/usr --with-hdf5=/usr
143+
CC=icx CXX=icpx FC=ifx make -j
144+
sudo make install
145+
curl -L https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.6.1.tar.gz -o - | tar xz
146+
cd netcdf-fortran-4.6.1
147+
cmake -B build -DCMAKE_Fortran_COMPILER=ifx -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DCMAKE_INSTALL_PREFIX=/usr
148+
cd build
149+
make -j
150+
sudo make install
136151
137152
- name: (Windows) Put MSYS2_MinGW64 on PATH
138153
if: contains(matrix.os,'windows') && (!contains(matrix.mpi,'intel'))
@@ -214,8 +229,14 @@ jobs:
214229
215230
- name: (macOS) Install homebrew HDF5
216231
if: contains(matrix.os,'macos')
217-
run: |
218-
brew install hdf5
232+
run: |
233+
brew install hdf5
234+
235+
- name: (macOS) Install homebrew NetCDF
236+
if: contains(matrix.os,'macos')
237+
run: |
238+
brew install netcdf
239+
brew install netcdf-fortran
219240
220241
# Phase 1: Bootstrap fpm with existing version
221242
- name: Install fpm

ci/meta_tests.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,22 @@ pushd metapackage_minpack
3333
popd
3434

3535
pushd metapackage_mpi
36-
"$fpm" build --verbose
36+
"$fpm" build --verbose
3737
"$fpm" run --verbose
3838
popd
3939

4040
pushd metapackage_mpi_c
41-
"$fpm" build --verbose
41+
"$fpm" build --verbose
4242
"$fpm" run --verbose
4343
popd
4444

4545
pushd metapackage_hdf5
46-
"$fpm" build --verbose
46+
"$fpm" build --verbose
47+
"$fpm" run --verbose
48+
popd
49+
50+
pushd metapackage_netcdf
51+
"$fpm" build --verbose
4752
"$fpm" run --verbose
4853
popd
4954

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
program metapackage_netcdf
2+
use netcdf4_f03
3+
implicit none
4+
5+
integer(c_int) :: ncid, retval
6+
7+
retval = nf_create("dummy.nc", NF_INMEMORY, ncid)
8+
if (retval /= nf_noerr) error stop nf_strerror(retval)
9+
stop 0
10+
end program metapackage_netcdf
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name = "metapackage_netcdf"
2+
dependencies.netcdf="*"

src/fpm/manifest/meta.f90

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ module fpm_manifest_metapackages
5252
!> HDF5
5353
type(metapackage_request_t) :: hdf5
5454

55+
!> NetCDF
56+
type(metapackage_request_t) :: netcdf
57+
5558
end type metapackage_config_t
5659

5760

@@ -203,6 +206,9 @@ subroutine new_meta_config(self, table, meta_allowed, error)
203206
call new_meta_request(self%hdf5, "hdf5", table, meta_allowed, error)
204207
if (allocated(error)) return
205208

209+
call new_meta_request(self%netcdf, "netcdf", table, meta_allowed, error)
210+
if (allocated(error)) return
211+
206212
end subroutine new_meta_config
207213

208214
!> Check local schema for allowed entries
@@ -214,7 +220,7 @@ logical function is_meta_package(key)
214220
select case (key)
215221

216222
!> Supported metapackages
217-
case ("openmp","stdlib","mpi","minpack","hdf5")
223+
case ("openmp","stdlib","mpi","minpack","hdf5","netcdf")
218224
is_meta_package = .true.
219225

220226
case default

src/fpm_meta.f90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module fpm_meta
3030
use fpm_meta_minpack, only: init_minpack
3131
use fpm_meta_mpi, only: init_mpi
3232
use fpm_meta_hdf5, only: init_hdf5
33+
use fpm_meta_netcdf, only: init_netcdf
3334

3435
use shlex_module, only: shlex_split => split
3536
use regex_module, only: regex
@@ -61,6 +62,7 @@ subroutine init_from_name(this,name,compiler,error)
6162
case("minpack"); call init_minpack(this,compiler,error)
6263
case("mpi"); call init_mpi (this,compiler,error)
6364
case("hdf5"); call init_hdf5 (this,compiler,error)
65+
case("netcdf"); call init_netcdf (this,compiler,error)
6466
case default
6567
call syntax_error(error, "Package "//name//" is not supported in [metapackages]")
6668
return
@@ -153,6 +155,12 @@ subroutine resolve_metapackage_model(model,package,settings,error)
153155
if (allocated(error)) return
154156
endif
155157

158+
! netcdf
159+
if (package%meta%netcdf%on) then
160+
call add_metapackage_model(model,package,settings,"netcdf",error)
161+
if (allocated(error)) return
162+
endif
163+
156164
end subroutine resolve_metapackage_model
157165

158166
end module fpm_meta

src/metapackage/fpm_meta_netcdf.f90

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
module fpm_meta_netcdf
2+
use fpm_compiler, only: compiler_t, get_include_flag
3+
use fpm_meta_base, only: metapackage_t, destroy
4+
use fpm_meta_util, only: add_pkg_config_compile_options
5+
use fpm_pkg_config, only: assert_pkg_config, pkgcfg_has_package
6+
use fpm_strings, only: string_t
7+
use fpm_error, only: error_t, fatal_error
8+
9+
implicit none
10+
11+
private
12+
13+
public :: init_netcdf
14+
15+
contains
16+
17+
!> Initialize NetCDF metapackage for the current system
18+
subroutine init_netcdf(this, compiler, error)
19+
class(metapackage_t), intent(inout) :: this
20+
type(compiler_t), intent(in) :: compiler
21+
type(error_t), allocatable, intent(out) :: error
22+
23+
logical :: s
24+
character(len=:), allocatable :: include_flag, libdir
25+
26+
include_flag = get_include_flag(compiler, "")
27+
28+
!> Cleanup
29+
call destroy(this)
30+
allocate (this % link_libs(0), this % incl_dirs(0), this % external_modules(0))
31+
this % link_flags = string_t("")
32+
this % flags = string_t("")
33+
34+
!> Assert pkg-config is installed
35+
if (.not. assert_pkg_config()) then
36+
call fatal_error(error, 'netcdf metapackage requires pkg-config')
37+
return
38+
end if
39+
40+
if (.not. pkgcfg_has_package('netcdf')) then
41+
call fatal_error(error, 'pkg-config could not find a suitable netcdf package.')
42+
end if
43+
call add_pkg_config_compile_options(this, 'netcdf', include_flag, libdir, error)
44+
if (allocated(error)) return
45+
46+
if (.not. pkgcfg_has_package('netcdf-fortran')) then
47+
call fatal_error(error, &
48+
'pkg-config could not find a suitable netcdf-fortran package.')
49+
end if
50+
call add_pkg_config_compile_options(this, 'netcdf-fortran', include_flag, libdir, error)
51+
if (allocated(error)) return
52+
53+
!> Add NetCDF modules as external
54+
this % has_external_modules = .true.
55+
this % external_modules = [string_t('netcdf'), &
56+
string_t('netcdf4_f03'), &
57+
string_t('netcdf4_nc_interfaces'), &
58+
string_t('netcdf4_nf_interfaces'), &
59+
string_t('netcdf_f03'), &
60+
string_t('netcdf_fortv2_c_interfaces'), &
61+
string_t('netcdf_nc_data'), &
62+
string_t('netcdf_nc_interfaces'), &
63+
string_t('netcdf_nf_data'), &
64+
string_t('netcdf_nf_interfaces')]
65+
end subroutine init_netcdf
66+
end module fpm_meta_netcdf

0 commit comments

Comments
 (0)