function [filename_base, ext]=file_extension(filename)
% % This program separates the filename from the extension.  For example a
% % file with the name data_file1.txt.  Has an etension txt and a filename
% % base of data_file1.  
% % 
% Example='';
% filename='data_file1.txt';
%
% [filename_base, ext]=file_extension(filename);
% % 
% % Output Variables
% % filename_base is the part of the filename before the extension 
% % 
% % ext is the file anem extension for example 'txt'.
% % 
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% % Program Written by Edward L. Zechmann 
% %                date 5 August 2007
% %            modified 27 December 2007
% %                     added a description and an example
% %                     updated comments
% %                     
% %  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % 
% % Please feel free to modify this code.
% % 

k = strfind(filename, '.');

if ~isempty(k)
    if length(k(1)) > 0
        ext=filename((k(1)+1):end);
        filename_base=filename(1:(k(1)-1));
    else
        ext='';
        filename_base=filename;
    end
else
    ext='';
    filename_base=filename;
end
    
    
    
    