11function test_saveEventsFileSave()
2-
2+
33 %% write things in it
44 clear ;
5-
5+
66 outputDir = fullfile(fileparts(mfilename(' fullpath' )), ' ..' , ' output' );
7-
7+
88 % %% set up
9-
10- cfg.subjectNb = 1 ;
11- cfg.runNb = 1 ;
12- cfg.task = ' testtask' ;
13- cfg.outputDir = outputDir ;
14-
9+
10+ cfg.subject. subjectNb = 1 ;
11+ cfg.subject. runNb = 1 ;
12+ cfg.task.name = ' testtask' ;
13+ cfg.dir.output = outputDir ;
14+
1515 cfg.testingDevice = ' mri' ;
16-
17- cfg = createFilename(cfg );
18-
16+
17+ cfg = createFilename(cfg );
18+
1919 logFile.extraColumns.Speed.length = 1 ;
2020 logFile.extraColumns.LHL24.length = 12 ;
2121 logFile.extraColumns.is_Fixation.length = 1 ;
22-
22+
2323 % create the events file and header
2424 logFile = saveEventsFile(' open' , cfg , logFile );
25-
25+
2626 % %% do stuff
27-
27+
2828 % ROW 2: normal events : all info is there
2929 logFile(1 , 1 ).onset = 2 ;
3030 logFile(end , 1 ).trial_type = ' motion_up' ;
3131 logFile(end , 1 ).duration = 3 ;
3232 logFile(end , 1 ).Speed = 2 ;
3333 logFile(end , 1 ).is_Fixation = true ;
3434 logFile(end , 1 ).LHL24 = 1 : 12 ;
35-
35+
3636 logFile = saveEventsFile(' save' , cfg , logFile );
37-
37+
3838 % ROW 3: missing info (speed, LHL24)
3939 logFile(1 , 1 ).onset = 3 ;
4040 logFile(end , 1 ).trial_type = ' static' ;
4141 logFile(end , 1 ).duration = 4 ;
4242 logFile(end , 1 ).is_Fixation = false ;
43-
43+
4444 % ROW 4: missing info (duration is missing and speed is empty)
4545 logFile(2 , 1 ).onset = 4 ;
4646 logFile(end , 1 ).trial_type = ' motion_up' ;
4747 logFile(end , 1 ).Speed = [];
4848 logFile(end , 1 ).is_Fixation = true ;
4949 logFile(end , 1 ).LHL24 = 1 : 12 ;
50-
50+
5151 % empty events
5252 logFile(3 , 1 ).onset = [];
5353 logFile(end , 1 ).trial_type = [];
5454 logFile(end , 1 ).duration = 3 ;
55-
55+
5656 logFile(4 , 1 ).onset = 1 ;
5757 logFile(end , 1 ).trial_type = ' ' ;
58-
58+
5959 % ROW 5: missing info (array is too short)
6060 logFile(5 , 1 ).onset = 5 ;
6161 logFile(end , 1 ).trial_type = ' jazz' ;
6262 logFile(end , 1 ).duration = 3 ;
6363 logFile(end , 1 ).LHL24 = rand(1 , 10 );
64-
64+
6565 % ROW 6: too much info (array is too long)
6666 % logFile(5, 1).onset = 5;
6767 % logFile(end, 1).trial_type = 'blues';
6868 % logFile(end, 1).duration = 3;
6969 % logFile(end, 1).LHL24 = rand(1, 15);
70-
70+
7171 saveEventsFile(' save' , cfg , logFile );
72-
72+
7373 % close the file
7474 saveEventsFile(' close' , cfg , logFile );
75-
75+
7676 % %% test section
77-
77+
7878 % check the extra columns of the header and some of the content
7979 nbExtraCol = ...
8080 logFile(1 ).extraColumns.Speed.length + ...
8181 logFile(1 ).extraColumns.LHL24.length + ...
8282 logFile(1 ).extraColumns.is_Fixation.length;
83- FID = fopen(fullfile( ...
84- cfg .subjectOutputDir , ...
85- cfg .modality , ...
86- cfg .fileName .events ), ...
87- ' r' );
83+
84+ funcDir = fullfile(cfg .dir .outputSubject , cfg .fileName .modality );
85+ eventFilename = cfg .fileName .events ;
86+ FID = fopen(fullfile(funcDir , eventFilename ), ' r' );
8887 C = textscan(FID , repmat(' %s ' , 1 , nbExtraCol + 3 ), ' Delimiter' , ' \t ' , ' EndOfLine' , ' \n ' );
89-
88+
9089 % event 1/ ROW 2: check that values are entered correctly
9190 assert(isequal(C{1 }{2 }, sprintf(' %f ' , 2 )));
9291 assert(isequal(C{3 }{2 }, ' motion_up' ));
@@ -95,22 +94,22 @@ function test_saveEventsFileSave()
9594 assert(isequal(C{5 }{2 }, sprintf(' %f ' , 1 )));
9695 assert(isequal(C{16 }{2 }, sprintf(' %f ' , 12 )));
9796 assert(isequal(C{17 }{2 }, ' true' ));
98-
97+
9998 % event 2 / ROW 3: missing info replaced by nans
10099 assert(isequal(C{4 }{3 }, ' n/a' ));
101100 assert(isequal(C{5 }{3 }, ' n/a' ));
102101 assert(isequal(C{16 }{3 }, ' n/a' ));
103102 assert(isequal(C{17 }{3 }, ' false' ));
104-
103+
105104 % event 3 / ROW 4: missing info (duration is missing and speed is empty)
106105 assert(isequal(C{2 }{4 }, ' n/a' ));
107106 assert(isequal(C{4 }{4 }, ' n/a' ));
108-
107+
109108 % event 4-5 / ROW 5-6: skip empty events
110109 assert(~isequal(C{1 }{5 }, ' n/a' ));
111-
110+
112111 % check values entered properly
113112 assert(isequal(C{15 }{5 }, ' n/a' ));
114113 assert(isequal(C{16 }{5 }, ' n/a' ));
115-
114+
116115end
0 commit comments