# updated to version 2.0.6, based on the previous 2.0.5 version
# J. Sassmannshausen (Imperial College London, UK)
# Alex Domingo (Vrije Universiteit Brussel, BE)
# Maxim Masterov (SURF, NL)

easyblock = 'ConfigureMake'

name = 'CDO'
version = '2.2.2'

homepage = 'https://code.zmaw.de/projects/cdo'
description = """CDO is a collection of command line Operators to manipulate and analyse Climate and NWP model Data."""

toolchain = {'name': 'gompi', 'version': '2022b'}
toolchainopts = {'cstd': 'c++17', 'usempi': True}

source_urls = ['https://code.mpimet.mpg.de/attachments/download/28882/']
sources = [SOURCELOWER_TAR_GZ]
checksums = ['419c77315244019af41a296c05066f474cccbf94debfaae9e2106da51bc7c937']

builddependencies = [
    ('pkgconf', '1.9.3'),
]

dependencies = [
    ('cURL', '7.86.0'),
    ('ecCodes', '2.31.0'),
    ('FFTW', '3.3.10'),
    ('HDF5', '1.14.0'),
    ('libxml2', '2.10.3'),
    ('netCDF', '4.9.0'),
    ('PROJ', '9.1.1'),
    ('Szip', '2.1.1'),
    ('UDUNITS', '2.2.28'),
    ('util-linux', '2.38.1'),
]

# Build libcdi
configopts = "--enable-cdi-lib "

# Use dependencies from EasyBuild
configopts += "--with-curl=$EBROOTCURL --with-eccodes=$EBROOTECCODES --with-fftw3 --with-hdf5=$EBROOTHDF5 "
configopts += "--with-netcdf=$EBROOTNETCDF --with-proj=$EBROOTPROJ --with-szlib=$EBROOTSZIP "
configopts += "--with-udunits2=$EBROOTUDUNITS --with-util-linux-uuid=$EBROOTUTILMINLINUX "

# Make sure that right Fortran compiler is used, also on non-x86_64 architectures
configopts += 'CPPFLAGS="$CPPFLAGS -DgFortran" '

sanity_check_paths = {
    'files': ['bin/cdo', 'lib/libcdi.a', 'lib/libcdi.%s' % SHLIB_EXT],
    'dirs': ['include'],
}

sanity_check_commands = ["cdo --version  2>&1 | grep 'Climate Data Operators version %(version)s'"]

moduleclass = 'data'
