forked from arnodelorme/mffmatlabio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmff_importinfon.m
129 lines (106 loc) · 4.13 KB
/
mff_importinfon.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
% mff_importinfon - import information from MFF 'info.xml' file
%
% Usage:
% info = mff_exportsignal(mffFile);
%
% Inputs:
% mffFile - filename/foldername for the MFF file
%
% Output:
% info - 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 infoN = mff_importinfon(mffFile, index)
infon = [ 'info' int2str(index) ];
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');
mfffactorydelegate = javaObject('com.egi.services.mff.api.LocalMFFFactoryDelegate');
mfffactory = javaObject('com.egi.services.mff.api.MFFFactory', mfffactorydelegate);
infotype = javaObject('com.egi.services.mff.api.MFFResourceType', javaMethod('valueOf', 'com.egi.services.mff.api.MFFResourceType$MFFResourceTypes', 'kMFF_RT_InfoN'));
if exist(fullfile(mffFile, [infon '.xml']))
check_rewrite_file( fullfile(mffFile, [infon '.xml']) );
end
info = mfffactory.openResourceAtURI( fullfile(mffFile, [infon '.xml']), infotype);
infoN = [];
if ~isempty(info) && exist(fullfile(mffFile, [infon '.xml']))
if info.loadResource() == true
tmp = info.getInfoNFileType;
infoN.infoNFileType.value = tmp.getValue;
tmp = info.getInfoNFileTypeInformation;
try
if ~isempty(char(tmp.getMontageName))
infoN.infoNFileTypeInformation.montageName = char(tmp.getMontageName);
end
if ~isempty(char(tmp.getSensorLayoutName))
infoN.infoNFileTypeInformation.sensorLayoutName = char(tmp.getSensorLayoutName);
end
if ~isempty(char(tmp.referenceScheme))
infoN.infoNFileTypeInformation.referenceScheme = char(tmp.getReferenceScheme);
end
catch
end
try
infoN.infoNFileTypeInformation.pnsSetName = char(tmp.getPNSSetName);
catch
end
calibAll = info.getCalibrations;
if ~isempty(calibAll)
for iCalType = 1:calibAll.size
calibList = calibAll.get(iCalType-1); % first on the list is Gain
if strcmpi(char(calibList.getType()), 'GCAL');
if ~isempty(calibList)
calibValues = [];
channels = calibList.getChannels;
for iCalib = 1:channels.size
chan = channels.get(iCalib-1);
calibValues(iCalib) = str2num(chan.getChannelData());
end
infoN.calibration = calibValues;
end
end
end
end
else
fprintf( 'Error: Could not load Info resource; file might be corrupted.\n');
end
end
mfffactory.closeResource(info);
% rewrite info file for for hardware filter issue in Java library
function check_rewrite_file( fileName )
fid = fopen(fileName, 'r');
txt = {};
modified = false;
while ~feof(fid)
txt{end+1} = fgetl(fid);
posStr = strfind(txt{end}, 'd">true');
if ~isempty(posStr)
modified = true;
txt{end}(posStr) = [];
end
end
fclose(fid);
if modified
fid = fopen(fileName, 'w');
if fid == -1
error('Cannot modify original file to make it compatible with Java import librairy');
end
for iTxt = 1:length(txt)
fprintf(fid, '%s\n', txt{iTxt});
end
fclose(fid);
end