142 lines
5 KiB
Ruby
142 lines
5 KiB
Ruby
class Netcdf < Formula
|
|
desc "Libraries and data formats for array-oriented scientific data"
|
|
homepage "https://www.unidata.ucar.edu/software/netcdf"
|
|
url "https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-4.6.0.tar.gz"
|
|
mirror "https://www.gfd-dennou.org/library/netcdf/unidata-mirror/netcdf-4.6.0.tar.gz"
|
|
sha256 "4bf05818c1d858224942ae39bfd9c4f1330abec57f04f58b9c3c152065ab3825"
|
|
|
|
bottle do
|
|
sha256 "a3c393c2a8bab002e8570c9c3d6d04a62396f88a05da2030979fe80c1cd57f0d" => :high_sierra
|
|
sha256 "9882c5ed2bbdf0bebffc27ca03481194dd3637b06b6aaccb936eb78eb344e4fd" => :sierra
|
|
sha256 "cbefb57d4fe56331e5bd7216f57c9f39b69c5489cda775543d007d1034d7fca7" => :el_capitan
|
|
end
|
|
|
|
depends_on "cmake" => :build
|
|
depends_on "hdf5"
|
|
depends_on "gcc" # for gfortran
|
|
|
|
resource "cxx" do
|
|
url "https://github.com/Unidata/netcdf-cxx4/archive/v4.3.0.tar.gz"
|
|
sha256 "25da1c97d7a01bc4cee34121c32909872edd38404589c0427fefa1301743f18f"
|
|
end
|
|
|
|
resource "cxx-compat" do
|
|
url "https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-cxx-4.2.tar.gz"
|
|
mirror "https://www.gfd-dennou.org/arch/netcdf/unidata-mirror/netcdf-cxx-4.2.tar.gz"
|
|
sha256 "95ed6ab49a0ee001255eac4e44aacb5ca4ea96ba850c08337a3e4c9a0872ccd1"
|
|
end
|
|
|
|
resource "fortran" do
|
|
url "https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-fortran-4.4.4.tar.gz"
|
|
mirror "https://www.gfd-dennou.org/arch/netcdf/unidata-mirror/netcdf-fortran-4.4.4.tar.gz"
|
|
sha256 "b2d395175f8d283e68c8be516e231a96b191ade67ad0caafaf7fa01b1e6b5d75"
|
|
end
|
|
|
|
def install
|
|
ENV.deparallelize
|
|
|
|
common_args = std_cmake_args << "-DBUILD_TESTING=OFF"
|
|
|
|
mkdir "build" do
|
|
args = common_args.dup
|
|
args << "-DENABLE_TESTS=OFF"
|
|
args << "-DNC_EXTRA_DEPS=-lmpi" if Tab.for_name("hdf5").with? "mpi"
|
|
args << "-DENABLE_DAP_AUTH_TESTS=OFF" << "-DENABLE_NETCDF_4=ON" << "-DENABLE_DOXYGEN=OFF"
|
|
|
|
system "cmake", "..", "-DBUILD_SHARED_LIBS=ON", *args
|
|
system "make", "install"
|
|
system "make", "clean"
|
|
system "cmake", "..", "-DBUILD_SHARED_LIBS=OFF", *args
|
|
system "make"
|
|
lib.install "liblib/libnetcdf.a"
|
|
end
|
|
|
|
# Add newly created installation to paths so that binding libraries can
|
|
# find the core libs.
|
|
args = common_args.dup << "-DNETCDF_C_LIBRARY=#{lib}"
|
|
|
|
cxx_args = args.dup
|
|
cxx_args << "-DNCXX_ENABLE_TESTS=OFF"
|
|
resource("cxx").stage do
|
|
mkdir "build-cxx" do
|
|
system "cmake", "..", "-DBUILD_SHARED_LIBS=ON", *cxx_args
|
|
system "make", "install"
|
|
system "make", "clean"
|
|
system "cmake", "..", "-DBUILD_SHARED_LIBS=OFF", *cxx_args
|
|
system "make"
|
|
lib.install "cxx4/libnetcdf-cxx4.a"
|
|
end
|
|
end
|
|
|
|
fortran_args = args.dup
|
|
fortran_args << "-DENABLE_TESTS=OFF"
|
|
resource("fortran").stage do
|
|
mkdir "build-fortran" do
|
|
system "cmake", "..", "-DBUILD_SHARED_LIBS=ON", *fortran_args
|
|
system "make", "install"
|
|
system "make", "clean"
|
|
system "cmake", "..", "-DBUILD_SHARED_LIBS=OFF", *fortran_args
|
|
system "make"
|
|
lib.install "fortran/libnetcdff.a"
|
|
end
|
|
end
|
|
|
|
ENV.prepend "CPPFLAGS", "-I#{include}"
|
|
ENV.prepend "LDFLAGS", "-L#{lib}"
|
|
resource("cxx-compat").stage do
|
|
system "./configure", "--disable-dependency-tracking",
|
|
"--enable-shared",
|
|
"--enable-static",
|
|
"--prefix=#{prefix}"
|
|
system "make"
|
|
system "make", "install"
|
|
end
|
|
|
|
# SIP causes system Python not to play nicely with @rpath
|
|
libnetcdf = (lib/"libnetcdf.dylib").readlink
|
|
%w[libnetcdf-cxx4.dylib libnetcdf_c++.dylib].each do |f|
|
|
macho = MachO.open("#{lib}/#{f}")
|
|
macho.change_dylib("@rpath/#{libnetcdf}",
|
|
"#{lib}/#{libnetcdf}")
|
|
macho.write!
|
|
end
|
|
end
|
|
|
|
test do
|
|
(testpath/"test.c").write <<~EOS
|
|
#include <stdio.h>
|
|
#include "netcdf_meta.h"
|
|
int main()
|
|
{
|
|
printf(NC_VERSION);
|
|
return 0;
|
|
}
|
|
EOS
|
|
system ENV.cc, "test.c", "-L#{lib}", "-I#{include}", "-lnetcdf",
|
|
"-o", "test"
|
|
assert_equal `./test`, version.to_s
|
|
|
|
(testpath/"test.f90").write <<~EOS
|
|
program test
|
|
use netcdf
|
|
integer :: ncid, varid, dimids(2)
|
|
integer :: dat(2,2) = reshape([1, 2, 3, 4], [2, 2])
|
|
call check( nf90_create("test.nc", NF90_CLOBBER, ncid) )
|
|
call check( nf90_def_dim(ncid, "x", 2, dimids(2)) )
|
|
call check( nf90_def_dim(ncid, "y", 2, dimids(1)) )
|
|
call check( nf90_def_var(ncid, "data", NF90_INT, dimids, varid) )
|
|
call check( nf90_enddef(ncid) )
|
|
call check( nf90_put_var(ncid, varid, dat) )
|
|
call check( nf90_close(ncid) )
|
|
contains
|
|
subroutine check(status)
|
|
integer, intent(in) :: status
|
|
if (status /= nf90_noerr) call abort
|
|
end subroutine check
|
|
end program test
|
|
EOS
|
|
system "gfortran", "test.f90", "-L#{lib}", "-I#{include}", "-lnetcdff",
|
|
"-o", "testf"
|
|
system "./testf"
|
|
end
|
|
end
|