NeurodataWithoutBorders / matnwb

A Matlab interface for reading and writing NWB files
BSD 2-Clause "Simplified" License
49 stars 32 forks source link

[Bug]: Multiple nwbRead() and nwbExport() actions will cause the error of 'nwb.file_create_date' #544

Closed chenhongbiao closed 9 months ago

chenhongbiao commented 9 months ago

What happened?

Multiple nwbRead() and nwbExport() actions will cause the error of 'nwb.file_create_date'.

To fix it, replace the code Line30-36 in the file NwbFile.m calldef NwbFile < types.core.NWBFile with

% fix the bug when nwbRead and nwbExport more than 2 times
if isempty(obj.file_create_date)
    obj.file_create_date = num2cell(current_time);
elseif iscell(obj.file_create_date)
    obj.file_create_date(end+1) = num2cell(current_time);
else
    % obj.file_create_date could be a datetime array 
    obj.file_create_date = num2cell(obj.file_create_date);
    obj.file_create_date(end+1) = num2cell(current_time);
end

The file location: Codefile

The old code: Old code

The new code: Fixed code

Steps to Reproduce

To reproduce the error, run

nwb1 = NwbFile;
nwbExport(nwb1,'nwb1.nwb');

nwb2 = nwbRead('nwb1.nwb');
nwbExport(nwb2,'nwb2.nwb');

nwb3 = nwbRead('nwb2.nwb');
nwbExport(nwb3,'nwb3.nwb');

nwb4 = nwbRead('nwb3.nwb');

Error Message

Error using assert
Timestamp `22002233--0099--2222TT1155::1189::4552..318807953506++0022::0000` is not a valid ISO8601 subset for NWB:
  YMD should be in the form YYYY-mm-dd or YYYYmmdd

Error in io.timestamp2datetime>detectDatetime (line 37)
        assert(length(ymdStamp) == 10, errorId, errorMessage);

Error in io.timestamp2datetime (line 15)
                Datetime = detectDatetime(timestampString);

Error in types.util.correctType (line 29)
                val = formatDatetime(io.timestamp2datetime(val));

Error in types.util.checkDtype (line 126)
correctedValue = types.util.correctType(value, typeDescriptor);

Error in types.core.NWBFile/validate_file_create_date (line 335)
        val = types.util.checkDtype('file_create_date', 'datetime', val);

Error in types.core.NWBFile/set.file_create_date (line 187)
        obj.file_create_date = obj.validate_file_create_date(val);

Error in types.core.NWBFile (line 127)
        obj.file_create_date = p.Results.file_create_date;

Error in NwbFile (line 16)
            obj = obj@types.core.NWBFile(varargin{:});

Error in io.parseGroup (line 76)
            parsed = NwbFile(kwargs{:});

Error in nwbRead (line 79)
    nwb = io.parseGroup(filename, h5info(filename), Blacklist);

Operating System

Windows 10 Pro

Matlab Version

R2023a

Code of Conduct