function [fid file] = queryfid(directory,filetype)
%QUERYFID queries the user for a choice of files from a given directory
%   directory = directory you want to get a file from
%   filetype = extenstion of the file you are looking for (default: .mat)

if nargin < 2 || isempty(filetype)
    dirdat = dir(directory);
else
    dirdat = dir(strcat([directory '\*.' filetype]));
end

% Display available files and ask user what he/she wants
disp(strcat(['Available files in ' directory ' are:']));
for i = 1:size(dirdat,1)
    disp(strcat(['[' num2str(i) ']: ' dirdat(i).name]));
end
reply = input('Which Record do you want? [Enter a number]: ');
if isempty(reply)
    reply = 1;
end

file = dirdat(reply).name;
fid = strcat([directory '\' file]);

end

