forked from arnodelorme/mffmatlabio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmff_importcategories.m
88 lines (75 loc) · 3.48 KB
/
mff_importcategories.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
% mff_importcategories - import information from MFF 'categories.xml' file
%
% Usage:
% cat = mff_exportcategories(mffFile, version);
%
% Inputs:
% mffFile - filename/foldername for the MFF file
% vesion - file version (optional - default is 3)
%
% Output:
% cat - Matlab structure containing informations contained in the MFF file.
% This file is part of mffmatlabio.
%
% mffmatlabio is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% mffmatlabio is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with mffmatlabio. If not, see <https://www.gnu.org/licenses/>.
function cat = mff_importcategories(mffFile, version)
cat = [];
p = fileparts(which('mff_importsignal.m'));
warning('off', 'MATLAB:Java:DuplicateClass');
javaaddpath(fullfile(p, 'MFF-1.2.2-jar-with-dependencies.jar'));
warning('on', 'MATLAB:Java:DuplicateClass');
if nargin < 2
version = 3;
end
if version == 0
divider = 1000;
else
divider = 1;
end
% Create a factory.
mfffactorydelegate = javaObject('com.egi.services.mff.api.LocalMFFFactoryDelegate');
mfffactory = javaObject('com.egi.services.mff.api.MFFFactory', mfffactorydelegate);
%% create Segment to load time
categoriesRType = javaObject('com.egi.services.mff.api.MFFResourceType', javaMethod('valueOf', 'com.egi.services.mff.api.MFFResourceType$MFFResourceTypes', 'kMFF_RT_Categories'));
catURI = [ mffFile filesep 'categories.xml' ];
catsResource = mfffactorydelegate.openResourceAtURI(catURI, categoriesRType);
if ~isempty(catsResource)
if catsResource.loadResource()
categories = catsResource.getCategories();
fprintf('Importing categories.xml ressource: %d categories\n', categories.size);
for iCat = 1:categories.size
category = categories.get(iCat-1);
cat(iCat).name = char(category.getName());
% Get the list of segments for this category.
segments = category.getSegments();
fprintf('Category %s, %d trials\n', char(category.getName()), segments.size);
if ~isempty(segments)
for iSeg = 1:segments.size
segment = segments.get(iSeg-1);
cat(iCat).trials(iSeg).name = char(segment.getName());
cat(iCat).trials(iSeg).status = char(segment.getStatus());
cat(iCat).trials(iSeg).begintime = segment.getBeginTime()/divider;
cat(iCat).trials(iSeg).endtime = segment.getEndTime()/divider;
cat(iCat).trials(iSeg).eventbegin = segment.getEventBegin()/divider;
cat(iCat).trials(iSeg).eventend = segment.getEventEnd()/divider;
keylist = segment.getKeys();
cat(iCat).trials = mff_importkeys(cat(iCat).trials, iSeg, keylist, true);
if segment.getClockStartTimePresent()
cat(iCat).trials(iSeg).clockstarttime = char(segment.getClockStartTime());
end
end
end
end
end
end