function [path,name,base,filetype]=getbase(filename);
%function [path,name,base,filetype]=getbase(filename);
%
% Given a full path and file name, extracts file path, file name
% the file name without its .xxx extension 
% and the file type its . extension (filetype)

% ---------------------------------
% Copyright (c) 2003 Serge Dumoulin and Gareth Barnes
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License version 2
% as published by the Free Software Foundation.
% ---------------------------------

if nargin < 1,
   help(mfilename);
   return;
end;

path=[];
name=[];
base=[];
filetype=[];
for n=1:size(filename,1),
   divider=filesep;
   
   dividers=findstr(filename(n,:),divider);
   if length(dividers>0),
      lastpath=dividers(length(dividers));
   else,
      lastpath=0;
   end;
   path=strvcat(path,filename(n,1:lastpath));
   name=strvcat(name,filename(n,lastpath+1:length(deblank(filename(n,:)))));

   % handles .gz extensions as filetype
   startext=findstr(lower(name(n,:)),'.');
   if (startext>0),
      if startext>1,
         startext=startext(length(startext));
      end;
      base=strvcat(base,name(n,1:startext-1));
      filetype=strvcat(filetype,name(n,startext+1:length(deblank(name(n,:)))));
   else,
%      disp(sprintf('File (%s) has no extension',filename(n,:)));
      base=strvcat(base,deblank(name(n,:)));
      filetype=strvcat(filetype,0);
   end;
end;






