def detect_filetype(filename):
    """Simple method for quickly determining filetype of a given input file.

    Parameters
    ----------
    filename : str
        File path

    Returns
    -------
    filetype : str
        The filetype of the given input file

    """
    if filename[-3:].lower() == 'nxs':
        return 'grasp'
    elif filename[-4:].lower() == 'iexy' or filename[-3:].lower(
        ) == 'spe' or filename[-3:].lower() == 'xye' or filename[-4:
        ] == 'xyie':
        return 'dcs_mslice'
    elif filename[-2:].lower() == 'h5' or filename[-3:].lower() == 'npy':
        return 'neutronpy'
    else:
        with open(filename) as f:
            first_line = f.readline()
            second_line = f.readline()
            if '#ICE' in first_line:
                return 'ice'
            elif '# scan' in first_line:
                return 'spice'
            elif 'GRASP' in first_line.upper():
                return 'grasp'
            elif 'Filename' in second_line:
                return 'icp'
            elif 'RRR' in first_line or 'AAA' in first_line or 'VVV' in first_line:
                return 'mad'
            elif 'NeutronPy' in first_line:
                return 'neutronpy'
            else:
                raise ValueError('Unknown filetype.')
