Skip to content

Commit 057b759

Browse files
committed
make some functions shut up if we ask them
1 parent f620894 commit 057b759

File tree

2 files changed

+175
-159
lines changed

2 files changed

+175
-159
lines changed

createFilename.m

Lines changed: 62 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@
1111
%
1212
%
1313
% See test_createFilename in the test folder for more details on how to use it.
14-
14+
1515
cfg = checkCFG(cfg);
16-
16+
1717
cfg.fileName.pattern = ['%0' num2str(cfg.fileName.zeroPadding) '.0f'];
1818
cfg.fileName.date = datestr(now, cfg.fileName.dateFormat);
19-
19+
2020
if ~isfield(cfg, 'task')
2121
error('createFilename: missing a task name. i.e cfg.task.name');
2222
end
23-
23+
2424
cfg = getModality(cfg);
25-
25+
2626
cfg = createDirectories(cfg);
27-
27+
2828
cfg = setSuffixes(cfg);
29-
29+
3030
cfg = setFilenames(cfg);
31-
31+
3232
talkToMe(cfg);
33-
33+
3434
cfg = orderfields(cfg);
3535
cfg.fileName = orderfields(cfg.fileName);
3636
cfg.dir = orderfields(cfg.dir);
37-
37+
3838
end
3939

4040
function cfg = getModality(cfg)
41-
41+
4242
switch lower(cfg.testingDevice)
4343
case 'pc'
4444
modality = 'beh';
@@ -53,52 +53,52 @@
5353
otherwise
5454
modality = 'beh';
5555
end
56-
56+
5757
cfg.fileName.modality = modality;
58-
58+
5959
end
6060

6161
function [subjectGrp, subjectNb, sessionNb, modality, taskName] = extractInput(cfg)
62-
62+
6363
subjectGrp = cfg.subject.subjectGrp;
6464
subjectNb = cfg.subject.subjectNb;
6565
sessionNb = cfg.subject.sessionNb;
6666
modality = cfg.fileName.modality;
6767
taskName = cfg.fileName.task;
68-
68+
6969
if isempty(sessionNb)
7070
sessionNb = 1;
7171
end
72-
72+
7373
end
7474

7575
function cfg = createDirectories(cfg)
76-
76+
7777
[subjectGrp, subjectNb, sessionNb, modality] = extractInput(cfg);
78-
78+
7979
pattern = cfg.fileName.pattern;
80-
80+
8181
% output dir
8282
cfg.dir.outputSubject = fullfile ( ...
8383
cfg.dir.output, ...
8484
'source', ...
8585
['sub-' subjectGrp, sprintf(pattern, subjectNb)], ...
8686
['ses-', sprintf(pattern, sessionNb)]);
87-
87+
8888
[~, ~, ~] = mkdir(cfg.dir.output);
8989
[~, ~, ~] = mkdir(cfg.dir.outputSubject);
9090
[~, ~, ~] = mkdir(fullfile(cfg.dir.outputSubject, modality));
91-
91+
9292
if cfg.eyeTracker.do
9393
[~, ~, ~] = mkdir(fullfile(cfg.dir.outputSubject, 'eyetracker'));
9494
end
95-
95+
9696
end
9797

9898
function cfg = setSuffixes(cfg)
99-
99+
100100
cfg.fileName.suffix.run = ['_run-' sprintf(cfg.fileName.pattern, cfg.subject.runNb)];
101-
101+
102102
% set values for the suffixes for the different fields in the BIDS name
103103
fields2Check = { ...
104104
'contrastEnhancement', ...
@@ -107,7 +107,7 @@
107107
'echo', ...
108108
'acquisition'
109109
};
110-
110+
111111
for iField = 1:numel(fields2Check)
112112
if isempty (cfg.mri.(fields2Check{iField})) %#ok<*GFLD>
113113
cfg.fileName.suffix.mri.(fields2Check{iField}) = ''; %#ok<*SFLD>
@@ -116,81 +116,85 @@
116116
['_' fields2Check{iField} '-' getfield(cfg.mri, fields2Check{iField})];
117117
end
118118
end
119-
119+
120120
cfg.fileName.suffix = orderfields(cfg.fileName.suffix);
121-
121+
122122
end
123123

124124
function cfg = setFilenames(cfg)
125-
125+
126126
[subjectGrp, subjectNb, sessionNb, modality, taskName] = extractInput(cfg);
127-
127+
128128
pattern = cfg.fileName.pattern;
129-
129+
130130
runSuffix = cfg.fileName.suffix.run;
131131
acqSuffix = cfg.fileName.suffix.mri.acquisition ;
132132
ceSuffix = cfg.fileName.suffix.mri.contrastEnhancement ;
133133
dirSuffix = cfg.fileName.suffix.mri.phaseEncodingDirection ;
134134
recSuffix = cfg.fileName.suffix.mri.reconstruction ;
135135
echoSuffix = cfg.fileName.suffix.mri.echo;
136-
136+
137137
thisDate = cfg.fileName.date;
138-
138+
139139
cfg.fileName.datasetDescription = fullfile ( ...
140140
cfg.dir.output, ...
141141
'dataset_description.json');
142-
142+
143143
% create base fileName
144144
fileNameBase = ...
145145
['sub-', subjectGrp, sprintf(pattern, subjectNb), ...
146146
'_ses-', sprintf(pattern, sessionNb), ...
147147
'_task-', taskName];
148148
cfg.fileName.base = fileNameBase;
149-
149+
150150
switch modality
151-
151+
152152
case 'func'
153-
153+
154154
cfg.fileName.events = ...
155155
[fileNameBase, ...
156156
acqSuffix, ceSuffix, ...
157157
dirSuffix, recSuffix, ...
158158
runSuffix, echoSuffix, ...
159159
'_events_date-' thisDate '.tsv'];
160-
160+
161161
otherwise
162-
162+
163163
cfg.fileName.events = ...
164164
[fileNameBase, runSuffix, '_events_date-' thisDate '.tsv'];
165-
165+
166166
end
167-
167+
168168
cfg.fileName.stim = strrep(cfg.fileName.events, 'events', 'stim');
169-
169+
170170
if cfg.eyeTracker.do
171171
cfg.fileName.eyetracker = ...
172172
[fileNameBase, acqSuffix, ...
173173
runSuffix, '_eyetrack_date-' thisDate '.edf'];
174174
end
175-
175+
176176
end
177177

178178
function talkToMe(cfg)
179-
180-
fprintf(1, '\nData will be saved in this directory:\n\t%s\n', ...
181-
fullfile(cfg.dir.outputSubject, cfg.fileName.modality));
182-
183-
fprintf(1, '\nData will be saved in this file:\n\t%s\n', ...
184-
cfg.fileName.events);
185-
186-
if cfg.eyeTracker.do
187-
188-
fprintf(1, '\nEyetracking data will be saved in this directory:\n\t%s\n', ...
189-
fullfile(cfg.dir.outputSubject, 'eyetracker'));
190-
191-
fprintf(1, '\nEyetracking data will be saved in this file:\n\t%s\n', ...
192-
cfg.fileName.eyetracker);
193-
179+
180+
if cfg.verbose
181+
182+
fprintf(1, '\nData will be saved in this directory:\n\t%s\n', ...
183+
fullfile(cfg.dir.outputSubject, cfg.fileName.modality));
184+
185+
fprintf(1, '\nData will be saved in this file:\n\t%s\n', ...
186+
cfg.fileName.events);
187+
188+
if cfg.eyeTracker.do
189+
190+
fprintf(1, '\nEyetracking data will be saved in this directory:\n\t%s\n', ...
191+
fullfile(cfg.dir.outputSubject, 'eyetracker'));
192+
193+
fprintf(1, '\nEyetracking data will be saved in this file:\n\t%s\n', ...
194+
cfg.fileName.eyetracker);
195+
196+
end
197+
194198
end
195-
199+
196200
end

0 commit comments

Comments
 (0)