%DIRNAME = GETDIR(TITLE)
%    Asks the user for a dirname using a dialog box.

% (C) Copyright 1999-2008               Pattern Recognition Group
%     All rights reserved               Faculty of Applied Physics
%                                       Delft University of Technology
%                                       Lorentzweg 1
%                                       2628 CJ Delft
%                                       The Netherlands
%
% Bernd Rieger & Cris Luengo, oktober 2004

function dirname = getdir(title)

if nargin ~= 1 | ~ischar(title)
   error('Invalid input.')
end

defdir = dipgetpref('CurrentImageFileDir');
if isempty(defdir)
   % Go to first directory specified in path.
   defdir = convertpath(dipgetpref('imagefilepath'));
   if ~isempty(defdir) & ~isempty(defdir{1})
      defdir = defdir{1};
   else
      defdir = '';
   end
end
dirname = uigetdir(defdir,title);
if ~ischar(dirname)
   % uigetdir returns 0 when the user presses CANCEL.
   dirname = '';
else
   dipsetpref('CurrentImageFileDir',dirname);
end
