easyblock = 'MakeCp'

name = 'CDFTOOLS'
version = '4.0.0'

homepage = 'https://github.com/meom-group/CDFTOOLS'
description = """CDFTOOLS is a diagnostic package written in Fortran 90 
for the analysis of NEMO model output."""

# Using the intel toolchain (Intel Compilers + Intel MPI + Intel MKL)
toolchain = {'name': 'intel', 'version': '2024a'}

source_urls = ['https://github.com/meom-group/CDFTOOLS/archive/']
sources = ['v%(version)s.tar.gz']
checksums = ['97c88789452b9945af8c165852f1a1b8a9af2394ca9aa758693e196d78e9d6f4']

dependencies = [
    ('netCDF', '4.9.2'),
    ('netCDF-Fortran', '4.6.1'), 
]

# Move into the source directory
start_dir = 'src'

# CDFTOOLS requires a make.macro file in the src directory.
# We create one that points to the EasyBuild-managed NetCDF paths.
#prebuildopts = 'NC_CONFIG="$EBROOTNETCDF/bin/nc-config" && '
prebuildopts = 'NF_CONFIG="$EBROOTNETCDFMINFORTRAN/bin/nf-config" && '
prebuildopts += 'echo "F90 = $($NF_CONFIG --fc) $($NF_CONFIG --fflags) $($NF_CONFIG --flibs)" > make.macro && '
prebuildopts += 'echo "FFLAGS = -O3 -fno-alias" >> make.macro && '
prebuildopts += 'echo "LIBS =" >> make.macro && '
prebuildopts += 'echo "NC4 = -Dkey_netcdf4" >> make.macro && '

# Build command execution
buildopts = ""

# Files to copy after build
files_to_copy = [
    (['../bin/*'], 'bin'),
    (['*.mod'], 'include'),
]

sanity_check_paths = {
    'files': ['bin/cdfmoc', 'bin/cdfpsi', 'bin/cdfmaxmoc'],
    'dirs': ['bin', 'include'],
}

moduleclass = 'phys'
