#!/usr/bin/env fslpython
#
# Call an appropriate variant of mmorf based on
# what is installed, and whether we have a GPU.


import sys
import os

from fsl.utils.run import runfsl


def main():
    """Call an appropriate variant of mmorf based on what is installed, and
    whether a CUDA driver is available.
    """

    # find_cuda_exe will give us the
    # path to mmorf_cuda or mmorf_cpu
    mmorf_exe = runfsl('find_cuda_exe mmorf_cuda mmorf_cpu', silent=True)
    mmorf_exe = mmorf_exe.strip()
    fsldir    = os.environ['FSLDIR']

    if mmorf_exe == '':
        print(f'Cannot find suitable mmorf executable in {fsldir}/bin/!')
        sys.exit(1)

    os.execl(mmorf_exe, mmorf_exe, *sys.argv[1:])


if __name__ == '__main__':
    main()
