From bb4f7e447daf3076271e3059b54b92fe024cf57b Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Mon, 8 Apr 2024 17:41:25 +0200 Subject: [PATCH] fix --- src/Mapping.m | 103 +++++++++++++------------------ src/utils/prepare_for_printing.m | 8 ++- 2 files changed, 48 insertions(+), 63 deletions(-) diff --git a/src/Mapping.m b/src/Mapping.m index 062b744..90e3e3e 100644 --- a/src/Mapping.m +++ b/src/Mapping.m @@ -170,39 +170,36 @@ function print_mapping(obj, filename) obj = flatten_mapping(obj); - % print to screen be default; - output_is_json = false; + if nargin > 1 && strcmp(bids.internal.file_utils(filename, 'ext'), 'json') + output_is_json = true; + content = {}; + for i = 1:size(obj.mapping, 1) + input = obj.mapping(i); + input = rmfield(input, 'name_spec'); + content{i, 1} = struct('input', input, ... + 'output', obj.mapping(i).name_spec); + end + bids.util.jsonencode(filename, content); + return + end + + % print to screen by default + fid = 1; % what to separate input and output with left = ' '; separator = ' --> '; right = ' '; - if nargin < 2 - - fid = 1; - - elseif ~strcmp(bids.internal.file_utils(filename, 'ext'), 'json') - + if nargin > 1 fid = fopen(filename, 'Wt'); if fid == -1 error('Unable to write file %s.', filename); end - + % markdown table separators left = '| '; separator = ' | '; right = ' |'; - - elseif strcmp(bids.internal.file_utils(filename, 'ext'), 'json') - - output_is_json = true; - - content = {}; - - else - - fid = 1; - end header = ['