function varargout=dopSkipNotes(varargin)
% dopOSCCI Mark II: dopSkipNotes~ 04-Nov-2011 (last edit)
%
% get a text file record of which files are skipped and why
%
% called in dopGenSetup & dopSumReport
%
%
% dopGetData
% dopEventData
%
fprintf('\n%s\n\t%s\n',['Running ',mfilename],...
    'Updating skip notes file:');
try
    %% setGetInputs
    dsn=[];
    inputs.varargin=varargin;
    %     inputs.turnOn={'fileL'};
    inputs.defaults=struct('fileTxt','dopOSCCIskipRecord',...);% default file text (.txt extention)
        'foundFileList',[],... % list of files in data folder
        'sumFileList',[],... % list of files to be summarised
        'fileSel',0,... % is single file selected?
        'skip',0,... % are we skipping current file
        'skipReason',[],...
        'skipList',[],...
        'saveDir',[],...
        'fileNameLoc',[],...
        'saveNotes',1,...
        'addAnum',1,...); % adding 'A' and number to start of particicular files to influence sorting order for all notes file
        'saveData',1); % whether or not data are being saved - modify notes save based on this...
    dsn=setGetInputsStruct(inputs);
    %     %% data saving?
    %     if ~dsn.saveData && dsn.saveNotes
    %         fprintf('\t%s\n','Data not being saved, neither will notes.');
    %         dsn.saveNotes=0;
    %     end
    %% check save location
    if dsn.saveData && dsn.saveNotes
        %     if dsn.saveNotes
        dsn.translation='dop skip notes';
        dsn.abb='dsn';
        %% finish
        % save of the available notes files into single file
        if ~isempty(dsn.foundFileList) && ~isempty(dsn.sumFileList)
            fprintf('\t%s\n','Examining folder list versus summary list:');
            dsn.skipList=[];
            for i=1:numel(dsn.foundFileList)
                dsn.iOkay=0;
                for j=1:numel(dsn.sumFileList)
                    if strcmp(dsn.foundFileList{i},dsn.sumFileList{j})
                        dsn.iOkay=1;
                        break
                    end
                end
                if ~dsn.iOkay
                    dsn.skipList{end+1}=dsn.foundFileList{i};
                end
            end
            if ~isempty(dsn.skipList)
                
                dsn.skip=ones(numel(dsn.skipList),1);
                dsn.skipReason='Not included in group or session selection';
                if exist(dsn.fileSel{1},'file')==2
                    dsn.skipReason='File Selection on and this was not the file';
                end
            end
        end
        
        if dsn.skip(1) % any skipping to be done?
            %% check save location
            if isempty(dsn.saveDir) && isempty(dsn.fileNameLoc)
                % get the location of the dopOSCCI function - should be on matlab path
                dsn.dfl=which('dopOSCCI'); % dopOSCCI file location
                dsn.dl=fileparts(dsn.dfl); % dopOSCCI location
                dsn.saveDir=[dsn.dl,'Data\notes\'];
            end
            if isempty(dsn.saveDir) && ~isempty(dsn.fileNameLoc)
                dsn.saveDir=[fileparts(dsn.fileNameLoc),'/'];
            end
            if ~exist(dsn.saveDir,'dir');
                mkdir(dsn.saveDir);
            end
            
            %% set filename
            if isempty(dsn.fileNameLoc)
                dsn.fileName=[dsn.fileTxt,'.txt'];
                dsn.fileNameLoc=[dsn.saveDir,dsn.fileName];
            end
            
            %% report
            fprintf('\n\t%s\n\t\t%s\n\t\t%s\n','dopOSCCI file skip report:',...
                ['File Name = ',dsn.fileName],['Directory = ',dsn.saveDir]);
            dsn.fid=fopen(dsn.fileNameLoc,'a');
            for i=1:numel(dsn.skip) % usually just 1 accept for first check
                fprintf('\t%s\n\t\t%s\n',...
                    ['Skipped File = ',dsn.skipList{i}],...
                    ['Reason = ',dsn.skipReason]);
                fprintf(dsn.fid,'%s\t%s\n',...
                    dsn.skipList{i},dsn.skipReason);
            end
            fclose(dsn.fid);
        end
    else
        %         if ~dsn.finish
        fprintf('\n\t%s\n','Skip Notes set NOT to be saved (see dopOSCCIdef)');
        %         end
    end
    %% set output
    varargout{1}=dsn.fileNameLoc;
    
catch err
%% catch dopOSCCI error
    % 
save(dopOSCCIdebug(mfilename));rethrow(err); 
%     dopOSCCIcrash(err,dsn,mfilename);
end
fprintf('\n%s\n','Done');
clear dsn


