Commit fbecb31f authored by jayd1860's avatar jayd1860
Browse files

v1.42.2

-- Fix error when loading snirf with corrupt stim data. Added error checking to flag bad stim data. Then add file with bad stim data and discard bad stims while displaying warning.
-- Improve warning reporting for files that were allowed to load but with warnings.
-- Fix matlab error in backward compatability code when derived output folder is same as root group folder
parent 2cde4dea
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -472,28 +472,34 @@ classdef DataFilesClass < handle
                if obj.files(ii).isdir
                    continue;
                end
                filename = [obj.files(ii).rootdir, obj.files(ii).name];
                filename = obj.files(ii).name;
                eval( sprintf('o = %s(filename);', constructor) );
                if  o.GetError() < 0
                    obj.logger.Write('DataFilesClass.ErrorCheck:   FAILED error check - %s will not be added to data set\n', filename);
                    obj.logger.Write('DataFilesClass.ErrorCheck - ERROR: In file "%s" %s. File will not be added to data set\n', filename, o.GetErrorMsg());
                    errorIdxs = [errorIdxs, ii]; %#ok<AGROW>
                elseif  contains(o.GetErrorMsg(), '''data'' corrupt and unusable')                    
                    obj.logger.Write('DataFilesClass.ErrorCheck:   WARNING data is unusable - %s will not be added to data set\n', filename);
                elseif  contains(o.GetErrorMsg(), '''data'' field corrupt and unusable')                    
                    obj.logger.Write('DataFilesClass.ErrorCheck - WARNING: In file "%s" %s. File will not be added to data set\n', filename, o.GetErrorMsg());
                    errorIdxs = [errorIdxs, ii]; %#ok<AGROW>
                elseif  contains(o.GetErrorMsg(), '''data'' is invalid')                    
                    obj.logger.Write('DataFilesClass.ErrorCheck:   WARNING data is unusable - %s will not be added to data set\n', filename);
                elseif  contains(o.GetErrorMsg(), '''data'' field is invalid')                    
                    obj.logger.Write('DataFilesClass.ErrorCheck - WARNING: In file "%s" %s. File will not be added to data set\n', filename, o.GetErrorMsg());
                    errorIdxs = [errorIdxs, ii]; %#ok<AGROW>
                elseif ~isempty(o.GetErrorMsg())
                    obj.logger.Write('DataFilesClass.ErrorCheck - WARNING: In file  "%s"  %s. File will be added anyway.\n', filename, o.GetErrorMsg());
                    dataflag = true;
                else
                    dataflag = true;
                end
                if ~isempty(o.GetErrorMsg())
                    obj.files(ii).SetError(o.GetErrorMsg());
                end
                hwait = waitbar_improved(ii/length(obj.files), hwait, msg);
            end
            
            if dataflag==false
                obj.files = FileClass.empty();
            else
                for jj = 1:length(errorIdxs)
                    obj.filesErr(end+1) = obj.files(errorIdxs(jj)).copy;
                    obj.filesErr(end).SetError('Invalid Data Format');
                end
            	obj.files(errorIdxs) = [];
                obj.nfiles = obj.nfiles - length(errorIdxs);
+7 −10
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ classdef FileClass < matlab.mixin.Copyable
        rootdir
        err
        logger
        errmsgs
        errmsg
    end
    
    methods
@@ -38,9 +38,9 @@ classdef FileClass < matlab.mixin.Copyable
            obj.filename   = '';
            obj.map2group  = struct('iGroup',0, 'iSubj',0, 'iSess',0, 'iRun',0);
            obj.rootdir    = '';
            obj.err        = -1;          % Assume file is not loadable
            obj.errmsg     = '';          % Assume file is not loadable
            obj.logger     = InitLogger(logger);            
            obj.errmsgs    = {'Invalid Data Format','Invalid File Name'};
            obj.errmsg    = '';
            
            
            if nargin==0
@@ -538,22 +538,19 @@ classdef FileClass < matlab.mixin.Copyable
        
        % -----------------------------------------------------
        function err = GetError(obj)
            err = obj.err;
            err = ~isempty(obj.errmsg);
        end
        
        
        % -----------------------------------------------------
        function err = SetError(obj, err)
            if ischar(err)
                err = find(strcmp(obj.errmsgs, err));
            end
            obj.err = err;
        function SetError(obj, errmsg)
            obj.errmsg = errmsg;
        end
        
        
        % -----------------------------------------------------
        function msg = GetErrorMsg(obj)
            msg = obj.errmsgs{abs(obj.err)};
            msg = obj.errmsg;
        end
        
    end
+19 −7
Original line number Diff line number Diff line
@@ -269,12 +269,12 @@ classdef SnirfClass < AcqDataClass & FileLoadSaveClass
            obj.errmsgs = {
                'MATLAB could not load the file.'
                '''formatVersion'' is invalid.'
                '''metaDataTags'' is invalid.'
                '''data'' is invalid.'
                '''stim'' is invalid and could not be loaded'
                '''probe'' is invalid.'
                '''aux'' is invalid and could not be loaded'
                'WARNING: ''data'' corrupt and unusable'
                '''metaDataTags'' field is invalid.'
                '''data'' field is invalid.'
                '''stim'' field has corrupt data. Some or all stims could not be loaded'
                '''probe'' field is invalid.'
                '''aux'' field is invalid and could not be loaded'
                'WARNING: ''data'' field corrupt and unusable'
                };
        end
        
@@ -450,6 +450,18 @@ classdef SnirfClass < AcqDataClass & FileLoadSaveClass
                    obj.stim(ii).delete();
                    obj.stim(ii) = [];
                    break;
                else
                    for kk = 1:ii-1
                        if strcmp(obj.stim(kk).name, obj.stim(ii).name)
                            obj.stim(ii).delete();
                            obj.stim(ii) = [];
                            err = err-6;
                            break
                        end
                    end
                    if err ~= 0
                        break;
                    end
                end
                ii=ii+1;
            end
+9 −7
Original line number Diff line number Diff line
@@ -268,12 +268,14 @@ classdef StimClass < FileLoadSaveClass
            err = 0;
            
            % According to SNIRF spec, stim data is invalid if it has > 0 AND < 3 columns
            if isempty(obj.data)
                return;
            if isempty(obj.name)
                err = -3;
            end
            if ~isempty(obj.data) && size(obj.data,2)<3
                err = err-4;
                if size(obj.data, 2) ~= length(obj.dataLabels)
                    err = err-5;
                end
            if size(obj.data, 2)<3
                err = -2;
                return;
            end
        end
        
+46 −1
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@ classdef DataTreeClass < handle
        logger
        warningflag
        dataStorageScheme
        warnings
        errorStats
    end
    
    
@@ -32,7 +34,8 @@ classdef DataTreeClass < handle
            obj.currElem            = TreeNodeClass().empty();
            obj.reg                 = RegistriesClass().empty();
            obj.dirnameGroups       = {};
            
            obj.warnings            = '';
            obj.errorStats        = [0,0,0];
            
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            % Parse args
@@ -494,6 +497,30 @@ classdef DataTreeClass < handle
        
        % ----------------------------------------------------------
        function ErrorCheckLoadedFiles(obj)
            maxWarningsDisplay = 25;
            for iF = 1:length(obj.files)
                if ~isempty(obj.files(iF).GetErrorMsg())
                    if obj.errorStats(2) > maxWarningsDisplay
                        continue
                    end
                    if isempty(obj.warnings)
                        obj.warnings = sprintf('%s:   %s\n\n', obj.files(iF).name, obj.files(iF).GetErrorMsg());
                    elseif obj.errorStats(2) < maxWarningsDisplay-1
                        obj.warnings = sprintf('%s%s:   %s\n\n', obj.warnings, obj.files(iF).name, obj.files(iF).GetErrorMsg());
                    elseif obj.errorStats(2) == maxWarningsDisplay-1
                        obj.warnings = sprintf('%s  . . . Reached maximum number of warnings to display\n\n', obj.warnings);                        
                    end
                    if obj.files(iF).IsFile()
                        obj.errorStats(2) = obj.errorStats(2)+1;
                    end
                else
                    if obj.files(iF).IsFile()
                        obj.errorStats(1) = obj.errorStats(1)+1;
                    end
                end
            end
            obj.errorStats(3) = length(obj.filesErr);

            if isempty(obj.filesErr)
                return
            end
@@ -506,6 +533,24 @@ classdef DataTreeClass < handle
        end
        
        
        % ----------------------------------------------------------
        function w = GetWarningsReport(obj)
            [nFileSuccess, nFilesWarning, nFilesFailed] = obj.GetErrorStats();
            if ~isempty(obj.warnings)
                obj.warnings = sprintf('The following %d files were loaded with warnings:\n=========================================\n%s', nFilesWarning, obj.warnings);
            end
            w = obj.warnings;
        end
        
        
        % ----------------------------------------------------------
        function [nFileSuccess, nFilesWarning, nFilesFailed] = GetErrorStats(obj)
            nFileSuccess = obj.errorStats(1);
            nFilesWarning = obj.errorStats(2);
            nFilesFailed = obj.errorStats(3);
        end
        
        
        % ----------------------------------------------------------------------------------
        function list = DepthFirstTraversalList(obj)
            list = {};
Loading