-
Notifications
You must be signed in to change notification settings - Fork 6
HDF5 and NETCDF4 Installation on Mac
UPDATED: 2024-04-24, MacBook Pro, Apple M3 Pro, Mac OS Sonoma 14.4.1
For ELM model, NETCDF for FORTRAN is required. NETCDF4 is preferred and requires HDF5. HDF5 is required by PFLOTRAN. For those two libraries, parallel-enabled building is required, so they must be compiled with MPI compilers. Here is how to build them with [MPICH-4.1.6 built with GCC-14.x] (https://github.com/fmyuan/E3SM/wiki/GCC-Installation-on-Mac).
Here, as example, HDF5-12.3 is going to build, as following:
./configure --prefix=/usr/local/gcc-x/mpich-x-gcc/hdf5-1.12-parallel --enable-unsupported \
--enable-parallel --enable-cxx --enable-fortran --enable-shared --enable-static \
CC=/usr/local/gcc-x/mpich-x-gcc/mpich-4.x/bin/mpicc \
CPPFLAGS=" -DgFortran -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/local/gcc-x/mpich-x-gcc/mpich-4.x/include -I/usr/local/gcc-x/gcc-x-clang/include" \
CFLAGS=" -I/usr/local/gcc-x/mpich-x-gcc/mpich-4.x/include -I/usr/local/gcc-x/gcc-x-clang/include" \
CXX=/usr/local/gcc-x/mpich-x-gcc/mpich-4.x/bin/mpicxx \
CXXFLAGS=" -I/usr/local/gcc-x/mpich-x-gcc/mpich-4.x/include -I/usr/local/gcc-x/gcc-x-clang/include" \
FC=/usr/local/gcc-x/mpich-x-gcc/mpich-4.x/bin/mpifort \
FCFLAGS=" -I/usr/local/gcc-x/mpich-x-gcc/mpich-4.x/include -I/usr/local/gcc-x/gcc-x-clang/include" \
LDFLAGS=" -L/usr/local/gcc-x/mpich-x-gcc/mpich-4.x/lib -L/usr/local/gcc-x/gcc-x-clang/lib"
make all
make check
sudo make install
(1) Here C, CXX and FORTRAN compilers are needed, for ELM, PFLOTRAN or ATS.
(2) '--enable-unsupported' is necessary for both '--enable-cxx' and '--enable-parallel' to work.
(3) IF using OPENMPI, '-Wl,-ld_classic' in LDFLAGS is a must to fix an error in OPENMPI fortran wrapper. See discussion on openmpi.
(4) The make check
takes some time to finish, but is necessary and a good chance to observe if GCC/OPENMPI built before is workable.
The installation folder contains a bin folder, in which a few handy HDF5 tools are useful, e.g. h5dump
- a simple tool to convert .h5 files to ascii txt for a quick look of your data.
Until netcdf-4.1.3, all libraries of NETCDF are in one package. So the recent packages are separated and then have to build them one by one, with C library first.
./configure --prefix=/usr/local/gcc-x/mpich-x-gcc/netcdf-4.x-hdf5-parallel \
--enable-netcdf4 --enable-shared --enable-static --disable-doxygen --disable-dap \
CC=/usr/local/gcc-x/mpich-x-gcc/mpich-4.x/bin/mpicc \
CPPFLAGS=" -DgFortran -I/usr/local/gcc-x/mpich-x-gcc/hdf5-1.12-parallel/include " \
CFLAGS=" -I/usr/local/gcc-x/mpich-x-gcc/hdf5-1.12-parallel/include" \
LDFLAGS=" -L/usr/local/gcc-x/mpich-x-gcc/hdf5-1.12-parallel/lib"
NOTE:
(1) --disable-doxygen
means no user guide or alike. It's optional.
(2) --disalbe-dap
relevant to remote access data. It's optional.
Then, do building and installation:
make all
make check
sudo make install
For building C++ library, C library is required.
./configure --prefix=/usr/local/gcc-x/mpich-x-gcc/netcdf-4.x-hdf5-parallel --enable-shared --enable-static \
CC=/usr/local/gcc-x/mpich-x-gcc/mpich-4.x/bin/mpicc \
CXX=/usr/local/gcc-x/mpich-x-gcc/mpich-4.x/bin/mpicxx \
CPPFLAGS=" -DgFortran -I/usr/local/gcc-x/mpich-x-gcc/netcdf-4.x-hdf5-parallel/include -I/usr/local/gcc-x/mpich-x-gcc/hdf5-1.12-parallel/include" \
CFLAGS=" -I/usr/local/gcc-x/mpich-x-gcc/netcdf-4.x-hdf5-parallel/include -I/usr/local/gcc-x/mpich-x-gcc/hdf5-1.12-parallel/include" \
CXXFLAGS=" -I/usr/local/gcc-x/mpich-x-gcc/netcdf-4.x-hdf5-parallel/include -I/usr/local/gcc-x/mpich-x-gcc/hdf5-1.12-parallel/include" \
LDFLAGS=" -L/usr/local/gcc-x/mpich-x-gcc/netcdf-4.x-hdf5-parallel/lib -lnetcdf -L/usr/local/gcc-x/mpich-x-gcc/hdf5-1.12-parallel/lib -lhdf5_hl -lhdf5"
Then,
make all
make check
sudo make install
Similarly as C++ library, C library is required.
./configure --prefix=/usr/local/gcc-x/mpich-x-gcc/netcdf-4.x-hdf5-parallel --enable-shared --enable-static \
CC=/usr/local/gcc-x/mpich-x-gcc/mpich-4.x/bin/mpicc \
FC=/usr/local/gcc-x/mpich-x-gcc/mpich-4.x/bin/mpifort \
F77=/usr/local/gcc-x/mpich-x-gcc/mpich-4.x/bin/mpif77 \
CPPFLAGS=" -DgFortran -I/usr/local/gcc-x/mpich-x-gcc/netcdf-4.x-hdf5-parallel/include -I/usr/local/gcc-x/mpich-x-gcc/hdf5-1.12-parallel/include" \
CFLAGS=" -I/usr/local/gcc-x/mpich-x-gcc/netcdf-4.x-hdf5-parallel/include" \
FCFLAGS=" -I/usr/local/gcc-x/mpich-x-gcc/netcdf-4.x-hdf5-parallel/include" \
FFLAGS=" -I/usr/local/gcc-x/mpich-x-gcc/netcdf-4.x-hdf5-parallel/include" \
LDFLAGS=" -L/usr/local/gcc-x/mpich-x-gcc/netcdf-4.x-hdf5-parallel/lib"
Then,
make all
make check
sudo make install
NOTE: all libraries of NetCDF are installed in ONE place, so that they can be accessed for different languages.