function [pth,nam,ext,patid,date]= GetPatientID(filename)
% for i=1:length(filenames)
%     if iscell(filenames(i))
%         filename=filenames{i}
%     else
%         filename=filenames(i,:)
%     end
[pth,nam,ext] = fileparts(filename)
    % get the patient ID from the filename
    j1  = find(nam == '_')
    if length(j1)<=3
        pid=nam(j1(end)+1:end) % we assume the filename is of the form: 
    elseif length(j1)>=4
        pid =nam(j1(end-2)+1:j1(end-1)-1);
	date = nam(j1(end-1)+1:j1(end)-1);
%     elseif length(j1)==3
%         pid =nam(j1(end)+1:end);
    end
    trim = strfind(pid,'norm');
    if trim
        pid(trim:trim+3)=[];
    end
    patid=pid;
% end
