@@ -30,14 +30,44 @@ function createJson(varargin)
30
30
% - :``*.json``: (jsonfile) The file name corresponds to the run + suffix depending
31
31
% on the arguments passed in.
32
32
%
33
- % .. TODO:
34
- %
35
- % - use input parser for this one
36
33
%
37
34
% (C) Copyright 2020 CPP_BIDS developers
38
35
39
- [cfg , modality , extraInfo ] = checkInput(varargin );
36
+ %% Parse inputs
37
+ % modality is either given as a string by user or guessed from cfg.fileName
38
+ % extraInfo must be a structure
39
+
40
+ args = inputParser ;
41
+
42
+ default_modality = ' ' ;
43
+ default_extraInfo = struct([]);
44
+
45
+ charOrStruct = @(x ) isstruct(x ) || ischar(x );
46
+
47
+ args .addRequired(' input' , @isstruct );
48
+ args .addOptional(' modality' , default_modality , charOrStruct );
49
+ args .addOptional(' extraInfo' , default_extraInfo , @isstruct );
50
+
51
+ args .parse(varargin{: });
52
+
53
+ cfg = args .Results .input ;
54
+ modality = args .Results .modality ;
55
+ extraInfo = args .Results .extraInfo ;
40
56
57
+ if ischar(modality ) && strcmp(modality , default_modality ) && isfield(cfg .fileName , ' modality' )
58
+ modality = cfg .fileName .modality ;
59
+ end
60
+
61
+ if isstruct(modality ) && isfield(cfg .fileName , ' modality' )
62
+ extraInfo = modality ;
63
+ modality = cfg .fileName .modality ;
64
+ end
65
+
66
+ if ~ischar(modality ) || all(~strcmpi(modality , {' beh' , ' func' , ' eeg' , ' ieeg' , ' meg' }))
67
+ errorCreateJson(' wrongModalityInput' , modality );
68
+ end
69
+
70
+ % adapt depending on input
41
71
if strcmp(modality , ' func' )
42
72
fileName = strrep(cfg .fileName .events , ' _events' , ' _bold' );
43
73
jsonContent = cfg .bids .mri ;
@@ -61,66 +91,10 @@ function createJson(varargin)
61
91
62
92
end
63
93
64
- function [cfg , modality , extraInfo ] = checkInput(varargin )
65
-
66
- % trying to parse inputs
67
- % modality is either given as a string by user or guessed from cfg.fileName
68
- % extraInfo must be a structure
69
-
70
- input = varargin{1 };
71
-
72
- modality = ' ' ;
73
- extraInfo = struct();
74
-
75
- switch numel(input )
76
-
77
- case 0
78
- errorCreateJson(' notEnoughInput' );
79
-
80
- case 1
81
- cfg = input{1 };
82
- if isfield(cfg .fileName , ' modality' )
83
- modality = cfg .fileName .modality ;
84
- end
85
-
86
- case 2
87
- cfg = input{1 };
88
- if ischar(input{2 })
89
- modality = input{2 };
90
- elseif isstruct(input{2 })
91
- modality = cfg .fileName .modality ;
92
- extraInfo = input{2 };
93
- else
94
- errorCreateJson(' wrongInputType' );
95
- end
96
-
97
- otherwise
98
- cfg = input{1 };
99
- modality = input{2 };
100
- extraInfo = input{3 };
101
-
102
- end
103
-
104
- if ~ischar(modality ) || ...
105
- all(~strcmpi(modality , {' beh' , ' func' , ' eeg' , ' ieeg' , ' meg' }))
106
- errorCreateJson(' wrongModalityInput' , modality );
107
- end
108
-
109
- if ~isstruct(extraInfo )
110
- warning(' Additional info added to a json file must be a structure.' );
111
- end
112
-
113
- end
114
-
115
94
function errorCreateJson(identifier , varargin )
116
95
117
96
switch identifier
118
- case ' notEnoughInput'
119
- errorStruct.message = ' First input must be a valid cfg structure.' ;
120
97
121
- case ' wrongInputType'
122
- errorStruct.message = [' The second input must be a string (modality)' ...
123
- ' or a structure (extraInfo)' ];
124
98
case ' wrongModalityInput'
125
99
errorStruct.message = sprintf([' The given modality is not valid: %s .\n ' , ...
126
100
' Only the following string are accepted: ' ...
0 commit comments