Smarter basename computation

Smarter basename, to handle dots in file names, and composite extensions like nii.gz.

Fixes #200