function varargout=dopSaveDirBase(dop)
% dopOSCCI Mark II: dopSaveDirBase ~ 11-11-2010 (last edit)
%
% creates an original summary specific folder name for the doppler summary
% and makes the directory
%

% -------------------------------------------------------------------------
%     'dopOSCCI' summarises functional transcranial Doppler ultrasonography
%     (fTCD) data.  The primary function of the software is to assess the
%     hemispheric lateralization of cognitive function.
%
%     Copyright (C) 2011 the Chancellor, Masters and Scholars of the
%     University of Oxford.
% 
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
% 
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
% 
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/> 
%     or write to the Free Software Foundation, Inc., 51 Franklin Street,
%     Fifth Floor, Boston, MA 02110-1301, USA.
%
%     Authors: Nic Badcock, Georgina Holt, Anneka Holden, & Dorothy Bishop.
%       contact: nicholas.badcock@gmail.com
%
%     Type 'dopOSCCIlicense' for license details or see dopOSCCIlicense.txt
%
try
    fprintf('\n%s\n',['Running ',mfilename]);
    %% Set: set descriptives name
    % want to describe data files and folders based on setup information
    dop.tmp.sumDescrip=dop.def.sumDescrip;
    if isempty(dop.def.sumDescrip)
        dop.tmp.sumDescrip=dopSaveDirDescription('def',dop.def,dop.def.sumDescripSet{1:end}); %'epoch','base','poi')
    end
    
    %% >> set base save location
    dop.tmp.bsd=dop.def.saveDirBase; % base save directory
    if isempty(dop.tmp.bsd)
        dop.tmp.bsd=[fileparts(which('dopOSCCI')),'Data\',dop.def.taskName,'\'];
    end
    
    dop.tmp.bsdPlus=[dop.tmp.bsd,dop.tmp.sumDescrip,'\'];
    % adjust to make original
    dop.tmp.o=[]; % original
    while exist(dop.tmp.bsdPlus,'dir')==7
        dop.tmp.o=[dop.tmp.o '+'];
        dop.tmp.bsdPlus=[dop.tmp.bsd,dop.tmp.sumDescrip,dop.tmp.o,'\'];
    end
    dop.def.saveDir=dop.tmp.bsdPlus;
    % fprintf('\t%s\n\t%s\n','Making save directory:',dop.def.saveDirBase);
    % mkdir(dop.def.saveDirBase);
    fprintf('\t%s\n',dop.tmp.bsdPlus);
    %% set outputs
    varargout{1}=dop.tmp.bsdPlus; % original directory
    varargout{2}=dop.tmp.sumDescrip; % summary description
    varargout{3}=dop.tmp.bsd; % base directory
    %% remove tmp field from dop
    % keep it tidy
    % dop=rmfield(dop,'tmp');
    clear dop
catch err
    save(dopOSCCIdebug(mfilename));throw(err); 
end