Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Aug 5, 2023
1 parent 0c745a3 commit 092cc9e
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions +bids/+internal/get_metadata.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function meta = get_metadata(metafile)
%
% Read a BIDS's file metadata according to the inheritance principle
% Read a BIDS's file metadata according to the inheritance principle.
%
% USAGE::
%
Expand All @@ -11,21 +11,20 @@
%
% :returns: - :meta: metadata structure
%

% .. todo
%
% add explanation on how the inheritance principle is implemented.
%
%

% (C) Copyright 2011-2018 Guillaume Flandin, Wellcome Centre for Human Neuroimaging
%

% (C) Copyright 2018 BIDS-MATLAB developers

meta = struct();
metafile = cellstr(metafile);

for i = 1:numel(metafile)
% assumes files are read from root level files to deeper files
if bids.internal.ends_with(metafile{i}, '.json')
meta = update_metadata(meta, bids.util.jsondecode(metafile{i}), metafile{i});
else
Expand All @@ -35,7 +34,12 @@
end

if isempty(meta)
warning('No metadata for %s', metafile);
bids.internal.error_handling( ...
mfilename(), ...
'NoMetadata', ...
sprintf('No metadata for:%s', ...
bids.internal.create_unordered_list(metafile)), ...
true, true);
end

end
Expand All @@ -47,8 +51,14 @@
if isempty(struct_two)
return
elseif ~isstruct(struct_two)
error('Metadata file contents were neither struct nor empty. File: %s', file);
bids.internal.error_handling( ...
mfilename(), ...
'WrongInputType', ...
sprintf('Input was neither struct nor empty for file:\n%s', ...
file), ...
false);
end

fn = fieldnames(struct_two);
for i = 1:numel(fn)
if ~isfield(struct_one, fn{i})
Expand Down

0 comments on commit 092cc9e

Please sign in to comment.