# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup python    1.0
PortGroup compilers 1.0

name                py-nio
version             1.3.0b1
revision            30
categories-append   science
license             PyNIO
maintainers         {petr @petrrr} openmaintainer

description         Python I/O library for scientific data formats
long_description \
    PyNIO is a Python package that allows read and/or write access to \
    a variety of data formats using an interface modeled on netCDF. \
    PyNIO is composed of a C library called libnio along with a Python module \
    based on and with an interface similar to the Scientific.IO.NetCDF module \
    written by Konrad Hinsen.

homepage            http://www.pyngl.ucar.edu/Nio.shtml
distname            PyNIO-${version}

master_sites        "https://www.earthsystemgrid.org/download/fileDownload.htm?logicalFileId=e328ec94-306e-11df-8e89-00c0f03d5b7c&dummy="

checksums           rmd160  b33d00041783ba259ae95f772c7fde0cf37d7303 \
                    sha256  b9aa2f22db6a31196a465bb3a036fd248f68148e8ada1e1054106e6925cab7bf \
                    size    71262

python.versions     27

if {${name} ne ${subport}} {
    depends_lib-append  port:szip port:zlib \
                        path:include/turbojpeg.h:libjpeg-turbo port:jasper port:libpng \
                        port:hdf4 port:hdfeos port:hdf5 port:netcdf \
                        port:ncarg \
                        port:py${python.version}-numpy

    # ncarg is not universal, thus py-nio is neither
    universal_variant   no

    patch {
        reinplace "s|__init__(obj)|__init__()|" ${worksrcpath}/Nio.py
    }

    build.env-append    HAS_GRIB2=1  GRIB2_PREFIX=${prefix} \
                        HAS_HDFEOS=1 HDFEOS_PREFIX=${prefix} \
                        HAS_NETCDF4=1 NETCDF4_PREFIX=${prefix} \
                        NCARG_ROOT=${prefix} CC=${configure.cc}

    destroot.env        NCARG_ROOT=${prefix}

    compilers.choose    fc f77 f90
    compilers.setup     require_fortran

    if {[gcc_variant_isset]} {
        build.env-append    F2CLIBS=gfortran \
                            F2CLIBS_PREFIX=${prefix}/lib/[gcc_variant_name]
    } else {
        # g95
        configure.fflags-append -fno-second-underscore

        build.env-append    F2CLIBS=f95 \
                            F2CLIBS_PREFIX=${prefix}/lib/
    }

   livecheck.type   none
} else {
    livecheck.type  regex
    livecheck.url   http://www.pyngl.ucar.edu/Download/
    livecheck.regex {of PyNIO is ([0-9]\.[0-9]\.[0-9]+)}
}
