1{ fetchurl, stdenv,
2 cmake, netcdf, gfortran, jasper, libpng,
3 enablePython ? false, pythonPackages }:
4
5stdenv.mkDerivation rec{
6 name = "grib-api-${version}";
7 version = "1.24.0";
8
9 src = fetchurl {
10 url = "https://software.ecmwf.int/wiki/download/attachments/3473437/grib_api-${version}-Source.tar.gz";
11 sha256 = "1kbvyzaghbn1bqn97sslskmb6k3ki1dnr0g5abk5sb40n0y483bb";
12 };
13
14 preConfigure = ''
15 # Fix "no member named 'inmem_' in 'jas_image_t'"
16 substituteInPlace "src/grib_jasper_encoding.c" --replace "image.inmem_ = 1;" ""
17 '';
18
19 buildInputs = [ cmake
20 netcdf
21 gfortran
22 jasper
23 libpng
24 ] ++ stdenv.lib.optionals enablePython [
25 pythonPackages.python
26 ];
27
28 propagatedBuildInputs = stdenv.lib.optionals enablePython [
29 pythonPackages.numpy
30 ];
31
32 cmakeFlags = [ "-DENABLE_PYTHON=${if enablePython then "ON" else "OFF"}"
33 "-DENABLE_PNG=ON"
34 "-DENABLE_FORTRAN=ON"
35 ];
36
37 enableParallelBuilding = true;
38
39 doCheck = true;
40
41 # Only do tests that don't require downloading 120MB of testdata
42 # We fix the darwin checkPhase, which searches for libgrib_api.dylib
43 # in /nix/store by setting DYLD_LIBRARY_PATH
44 checkPhase = stdenv.lib.optionalString (stdenv.isDarwin) ''
45 substituteInPlace "tests/include.sh" --replace "set -ea" "set -ea; export DYLD_LIBRARY_PATH=$(pwd)/lib"
46 '' + ''
47 ctest -R "t_definitions|t_calendar|t_unit_tests" -VV
48 '';
49
50
51 meta = with stdenv.lib; {
52 homepage = https://software.ecmwf.int/wiki/display/GRIB/Home;
53 license = licenses.asl20;
54 platforms = with platforms; linux ++ darwin;
55 description = "ECMWF Library for the GRIB file format";
56 longDescription = ''
57 The ECMWF GRIB API is an application program interface accessible from C,
58 FORTRAN and Python programs developed for encoding and decoding WMO FM-92
59 GRIB edition 1 and edition 2 messages.
60 '';
61 maintainers = with maintainers; [ knedlsepp ];
62 };
63}
64