function varargout=dopScrnFileCreate(dataDir,varargin)
%% dopManScrnCreate (20-5-10)
%
% create basic manual screening file that can be editted for dopOSCCI
% manual screening.
%
% requires a list of .TX file names which will be placed in a tab delimited
% .txt file with no screening (i.e., 'none') for each file.
%
% this can then be editted manually.
%
% - preference is to have a gui to do this with but I'm still trying to
% figure out the best way to do this in matlab and this is a helpful start.
%
% for gui:
% dg.tmp.scrnFileReport=dopScrnFileCreate(dg.dopdef.dataDir,'taskName',dg.dopdef.taskName)

% -------------------------------------------------------------------------
%     '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
%
global dms
try
fprintf('\n%s\n',['Running ',mfilename]);
%% setGetInputs
inputs.turnOn={'test'};
inputs.turnOff={};
inputs.defaults=struct('saveDir',[],...
    'taskName','default','epochs','none');

inputs.varargin=varargin;
dms=setGetInputsStruct(inputs);

dms.translation='dopOSCCI manual screen';
dms.dataDir=dataDir; clear dataDir
%% get list
if exist(dms.dataDir,'dir')==7
    [dms.list dms.fileReport]=dopOSCCIgetFileList(dms.dataDir,1);
    
%% set basic info
%% > save directory
dms.suffix='Man';
if isempty(dms.saveDir)
    dms.saveDir=[fileparts(which('dopOSCCI')),'\taskData\']; %cd([dms.saveDir,'..']);
end
% make the directory if it's not there
if ~exist(dms.saveDir,'dir')
    mkdir(dms.saveDir);
end
% cd(dms.saveDir); % change directory
% with changing the directory, can create a hyperlink to the folder easily
% to open a windows explorer window to it for easy access.
fprintf('\t%s\n\t\t%s\n','Save Direcotry:',dms.saveDir);
%% > file name location
% count up until get original number
dms.tmp.fileExt='.txt';
dms.fileName=[dms.taskName,dms.suffix,dms.tmp.fileExt];
dms.tmp.tc=0; % temp counter
while exist(dms.fileName,'file')
    dms.tmp.tc=dms.tmp.tc+1;
    dms.tmp.tn=num2str(dms.tmp.tc); % text number
    if length(dms.tmp.tn)<2
        % add a zero so that the order works out nicely
        % don't expect people to go beyond 99...
        dms.tmp.tn=['0',num2str(dms.tmp.tc)];
    end
    dms.fileName=[dms.taskName,dms.suffix,num2str(dms.tmp.tc),dms.tmp.fileExt];
end
fprintf('\t%s\n\t\t%s\n','File Name:',dms.fileName);
dms.fileNameLoc=[dms.saveDir,dms.fileName]; % file name location

%% write to the file
%% > headers
fprintf('\t%s\n','Data Headers:');
dms.headers={'fileName' 'epochScreen'};
dms.fid=fopen(dms.fileNameLoc,'w');
for i=1:length(dms.headers)
    fprintf(dms.fid,'%s\t',dms.headers{i});
    fprintf('\t\t%s\n',dms.headers{i});
end
fprintf(dms.fid,'\n'); % new line

%% > list & screening
fprintf('\t%s\n','File Names & Epoch Screening:');
for i=1:length(dms.list)
    fprintf(dms.fid,'%s\t%s\n',dms.list{i},dms.epochs);
    fprintf('\t\t%s\t%s\n',dms.list{i},dms.epochs);
end
fclose(dms.fid);

%% report:
dms.report=sprintf('\n%s\n\t%s\n\t%s\n',...
    [dms.translation, ' file ready to edit:'],...
    [' - file name = ',dms.fileName],...
    [' - save directory = ',dms.saveDir]);
disp(dms.report);
disp(['<a href="matlab:dos(''explorer.exe /e, ' dms.saveDir,...
        ' &'');">Open Windows Explorer to save directory</a>']);
fprintf('\n\n');
else
dms.report=sprintf('%s\n','Data Dir (',dms.dataDir,') does not exist.');
disp(dms.report);
end


%% set output:
varargout{1}=dms.report;
catch err
    %% catch dopOSCCI error
    save(dopOSCCIdebug(mfilename));rethrow(err);
end

%% clear globals
if dms.test
    fprintf('\n%s\n\t%s\n','Test procedure is on, global variables available: ''inputs'' ''dms''',...
        'To view type: global inputs dms; inputs; dms');
else
    clear global dms inputs
    clear dms inputs
end