function [clipped] = dir_clip (directory,length)
% dir_clip: clips a directory name so that only a specified length is displayed
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% clip directory names

j01=findstr(directory,'\');
j02=size(directory,2);
if ((size(j01,2)<=1)|(j02<=length))
   clipped=directory;
   return;
else
   if (j02~=j01(end))
      directory=strcat(directory,'\');
   end;
   j01=findstr(directory,'\');
   j02=size(directory,2);
   if (size(j01,2)<=1)
      clipped=directory;
   else
      j03=length-j01(1)-3-(j01(end)-j01);
      j04=find(j03>=0);
      if (j01(j04(1))==j01(end))
         j04(1)=size(j01,2)-1;
      end;
      clipped=strcat(directory(1:j01(1)),'...',directory(j01(j04(1)):j01(end)));
   end;
end;

if (strcmp(clipped(end),'\')==1)
   clipped=clipped(1:(end-1));
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return;
