forked from fieldtrip/fieldtrip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fieldtrip2ctf.m
94 lines (82 loc) · 3.32 KB
/
fieldtrip2ctf.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
function fieldtrip2ctf(filename, data, varargin)
% FIELDTRIP2CTF saves a FieldTrip data structures to a corresponding CTF file. The
% file to which the data is exported depends on the input data structure that you
% provide.
%
% Use as
% fieldtrip2ctf(filename, data, ...)
% where "filename" is a string, "data" is a FieldTrip data structure, and
% additional options can be specified as key-value pairs.
%
% The FieldTrip "montage" structure (see FT_APPLY_MONTAGE and the cfg.montage
% option in FT_PREPROCESSING) can be exported to a CTF "Virtual Channels" file.
%
% At this moment the support for other FieldTrip structures and CTF fileformats is
% still limited, but this function serves as a placeholder for future improvements.
%
% See also FT_VOLUMEWRITE, FT_SOURCEWRITE, FT_WRITE_DATA
% Copyright (C) 2015, Robert Oostenveld
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% for the documentation and details.
%
% FieldTrip 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.
%
% FieldTrip 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 FieldTrip. If not, see <http://www.gnu.org/licenses/>.
%
% $Id$
type = ft_datatype(data);
switch type
case 'montage'
% Virtual channels are weighted linear combinations of real channels collected
% by the CTF MEG System
% rename it for convenience
montage = data; clear data;
fid = fopen(filename, 'wt');
assert(fid>0, 'could not open file for writing');
fprintf(fid, '// Virtual channel configuration\n');
for i=1:length(montage.labelnew)
sel = find(montage.tra(i,:) ~= 0);
fprintf(fid, '\n');
fprintf(fid, 'VirtualChannel\n');
fprintf(fid, '{\n');
fprintf(fid, 'Name:\t%s\n', montage.labelnew{i});
fprintf(fid, 'Unit:\n');
for j=1:numel(sel)
fprintf(fid, 'Ref:\t%s,%f\n', montage.labelorg{sel(j)}, montage.tra(i,sel(j)));
end
fprintf(fid, '}\n');
end
% case 'event'
% if ~ft_filetype(filename, 'ctf_ds')
% error('you should specify the directory name of a CTF dataset to which the MarkerFile.mrk will be added');
% end
%
% The MarkerFile.mrk file requires exact line spacing, otherwise the software
% will fail to read the it properly. Two blank lines must be present between
% sections and three blank lines must be present at the end of the file.
% case 'raw'
% this should be written with FT_WRITE_DATA
% case 'timelock'
% this should be written as a single trial with FT_WRITE_DATA
% case 'volume'
% this could be supported for singlesphere and localspheres
% for the following representations of processed data there is no suitable CTF file format
% case 'freq'
% case 'source'
% case 'comp'
% case 'spike'
% case 'source'
% case 'dip'
otherwise
error('unsuported data structure "%s" for exporting to CTF', type);
end