0001 function nwb = nwbRead(filename, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 ignorecache = ~isempty(varargin) && ischar(varargin{1}) &&...
0018 strcmp('ignorecache', varargin{1});
0019 if ischar(filename)
0020 validateattributes(filename, {'char'}, {'scalartext', 'nonempty'});
0021 info = h5info(filename);
0022 try
0023
0024 fid = H5F.open(filename);
0025 attr_id = H5A.open(fid, '.specloc');
0026 ref_data = H5A.read(attr_id);
0027 blacklist = H5R.get_name(attr_id, 'H5R_OBJECT', ref_data);
0028 if ~ignorecache
0029 generateSpec(fid, h5info(filename, blacklist));
0030 rehash();
0031 end
0032 info.Attributes(strcmp('.specloc', {info.Attributes.Name})) = [];
0033 H5A.close(attr_id);
0034 H5F.close(fid);
0035 catch ME
0036 if ~strcmp(ME.identifier, 'MATLAB:imagesci:hdf5lib:libraryError')
0037 rethrow(ME);
0038 end
0039 blacklist = '';
0040 end
0041 nwb = io.parseGroup(filename, info, blacklist);
0042 return;
0043 elseif isstring(filename)
0044 validateattributes(filename, {'string'}, {'nonempty'});
0045 else
0046 validateattributes(filename, {'cell'}, {'nonempty'});
0047 assert(iscellstr(filename));
0048 end
0049 nwb = NwbFile.empty(length(filename), 0);
0050 isStringArray = isstring(filename);
0051 for i=1:length(filename)
0052 if isStringArray
0053 fnm = filename(i);
0054 else
0055 fnm = filename{i};
0056 end
0057 info = h5info(fnm);
0058 nwb(i) = io.parseGroup(fnm, info);
0059 end
0060 end
0061
0062 function generateSpec(fid, specinfo)
0063 schema = spec.loadSchema();
0064
0065 for i=1:length(specinfo.Groups)
0066 location = specinfo.Groups(i).Groups(1);
0067
0068 namespace_name = split(specinfo.Groups(i).Name, '/');
0069 namespace_name = namespace_name{end};
0070
0071 filenames = {location.Datasets.Name};
0072 if ~any(strcmp('namespace', filenames))
0073 warning('MATNWB:INVALIDCACHE',...
0074 'Couldn''t find a `namespace` in namespace `%s`. Skipping cache generation.',...
0075 namespace_name);
0076 return;
0077 end
0078 source_names = {location.Datasets.Name};
0079 file_loc = strcat(location.Name, '/', source_names);
0080 schema_map = containers.Map;
0081 for j=1:length(file_loc)
0082 did = H5D.open(fid, file_loc{j});
0083 if strcmp('namespace', source_names{j})
0084 namespace_map = schema.read(H5D.read(did));
0085 else
0086 schema_map(source_names{j}) = H5D.read(did);
0087 end
0088 H5D.close(did);
0089 end
0090
0091 spec.generate(namespace_map, schema_map);
0092 end
0093 end