Skip to content

Commit 46909bf

Browse files
committed
SPM8 r4667
1 parent 9dc2598 commit 46909bf

File tree

714 files changed

+41167
-12051
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

714 files changed

+41167
-12051
lines changed

@gifti/private/base64decode.m

-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222

2323
% Modified by Guillaume Flandin, May 2008
2424

25-
% check number of input arguments
26-
%--------------------------------------------------------------------------
27-
28-
error(nargchk(1, 1, nargin));
2925

3026
% Perform the following mapping
3127
%--------------------------------------------------------------------------

@gifti/private/base64encode.m

-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
4444
% URL: http://home.online.no/~pjacklam
4545

46-
% check number of input arguments
47-
error(nargchk(1, 2, nargin));
4846

4947
% make sure we have the EOL value
5048
if nargin < 2

@gifti/private/getdict.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
55

66
% Guillaume Flandin
7-
% $Id: getdict.m 2271 2008-09-30 21:19:47Z guillaume $
7+
% $Id: getdict.m 4613 2012-01-08 12:04:11Z guillaume $
88

99
persistent dict;
1010
if ~isempty(dict)
@@ -15,7 +15,8 @@
1515
table = {...
1616
'NIFTI_TYPE_UINT8', 'uint8', '%d', @uint8, 'uint8'
1717
'NIFTI_TYPE_INT32', 'int32', '%d', @int32, 'int32'
18-
'NIFTI_TYPE_FLOAT32', 'float32', '%f', @single, 'single'};
18+
'NIFTI_TYPE_FLOAT32', 'float32', '%f', @single, 'single'
19+
'NIFTI_TYPE_FLOAT64', 'float64', '%f', @double, 'double'};
1920

2021
for i=1:size(table,1)
2122
dict.(table{i,1}) = cell2struct({table{i,2:end}},...

@gifti/private/isintent.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
1010

1111
% Guillaume Flandin
12-
% $Id: isintent.m 3999 2010-07-19 10:54:18Z guillaume $
12+
% $Id: isintent.m 4382 2011-07-06 14:59:41Z guillaume $
1313

1414
a = [];
1515
b = [];
@@ -51,11 +51,11 @@
5151
fprintf('Intent %s is ignored.\n',this.data{i}.attributes.Intent);
5252
end
5353
end
54-
[d,i] = unique(a,'first');
54+
[d,i] = unique(a);
5555
if length(d) < length(a)
56-
%warning('Several fields match intent type. Using first.');
56+
warning('Several fields match intent type. Using first.');
5757
a = a(i);
58-
%b = b(i);
58+
b = b(i);
5959
end
6060

6161
function c = cdata

@gifti/private/read_gifti_file.m

+36-12
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
88

99
% Guillaume Flandin
10-
% $Id: read_gifti_file.m 4013 2010-07-22 17:12:45Z guillaume $
10+
% $Id: read_gifti_file.m 4613 2012-01-08 12:04:11Z guillaume $
1111

1212
% Import XML-based GIfTI file
1313
%--------------------------------------------------------------------------
@@ -64,11 +64,26 @@
6464

6565
%==========================================================================
6666
function s = gifti_LabelTable(t,uid)
67-
s = struct('name',{}, 'index',[]);
67+
s = struct('name',{}, 'key',[], 'rgba',[]);
6868
c = children(t,uid);
6969
for i=1:length(c)
7070
a = attributes(t,'get',c(i));
71-
s(1).index(i) = str2double(a.val);
71+
s(1).rgba(i,1:4) = NaN;
72+
for j=1:numel(a)
73+
switch lower(a{j}.key)
74+
case {'key','index'}
75+
s(1).key(i) = str2double(a{j}.val);
76+
case 'red'
77+
s(1).rgba(i,1) = str2double(a{j}.val);
78+
case 'green'
79+
s(1).rgba(i,2) = str2double(a{j}.val);
80+
case 'blue'
81+
s(1).rgba(i,3) = str2double(a{j}.val);
82+
case 'alpha'
83+
s(1).rgba(i,4) = str2double(a{j}.val);
84+
otherwise
85+
end
86+
end
7287
s(1).name{i} = get(t,children(t,c(i)),'value');
7388
end
7489

@@ -90,10 +105,10 @@
90105
s(1).attributes = rmfield(s(1).attributes,f);
91106
end
92107
s(1).attributes = rmfield(s(1).attributes,'Dimensionality');
93-
try
108+
if isfield(s(1).attributes,'ExternalFileName') && ...
109+
~isempty(s(1).attributes.ExternalFileName)
94110
s(1).attributes.ExternalFileName = fullfile(fileparts(filename),...
95111
s(1).attributes.ExternalFileName);
96-
catch
97112
end
98113

99114
c = children(t,uid);
@@ -149,14 +164,23 @@
149164
d = typecast(dunzip(sb(base64decode(get(t,children(t,uid),'value')))), tp.cast);
150165

151166
case 'ExternalFileBinary'
152-
fid = fopen(s.ExternalFileName,'r');
153-
if fid == -1
154-
error('[GIFTI] Unable to read binary file %s.',s.ExternalFileName);
167+
[p,f,e] = fileparts(s.ExternalFileName);
168+
if isempty(p)
169+
s.ExternalFileName = fullfile(pwd,[f e]);
155170
end
156-
fseek(fid,str2double(s.ExternalFileOffset),0);
157-
d = sb(fread(fid,prod(s.Dim),['*' tp.class]));
158-
fclose(fid);
159-
171+
if true
172+
fid = fopen(s.ExternalFileName,'r');
173+
if fid == -1
174+
error('[GIFTI] Unable to read binary file %s.',s.ExternalFileName);
175+
end
176+
fseek(fid,str2double(s.ExternalFileOffset),0);
177+
d = sb(fread(fid,prod(s.Dim),['*' tp.class]));
178+
fclose(fid);
179+
else
180+
d = file_array(s.ExternalFileName, s.Dim, tp.class, ...
181+
str2double(s.ExternalFileOffset),1,0,'ro');
182+
end
183+
160184
otherwise
161185
error('[GIFTI] Unknown data encoding: %s.',s.Encoding);
162186
end

@gifti/save.m

+24-9
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ function save(this,filename,encoding)
22
% Save GIfTI object in a GIfTI format file
33
% FORMAT save(this,filename)
44
% this - GIfTI object
5-
% filename - name of GIfTI file that will be created
5+
% filename - name of GIfTI file to be created [Default: 'untitled.gii']
66
% encoding - optional argument to specify encoding format, among
77
% ASCII, Base64Binary, GZipBase64Binary, ExternalFileBinary,
8-
% Collada (.dae), IDTF (.idtf).
8+
% Collada (.dae), IDTF (.idtf). [Default: 'GZipBase64Binary']
99
%__________________________________________________________________________
1010
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
1111

1212
% Guillaume Flandin
13-
% $Id: save.m 4022 2010-07-28 12:50:20Z guillaume $
13+
% $Id: save.m 4613 2012-01-08 12:04:11Z guillaume $
1414

15-
error(nargchk(1,3,nargin));
1615

1716
% Check filename and file format
1817
%--------------------------------------------------------------------------
@@ -155,9 +154,15 @@ function save(this,filename,encoding)
155154
fprintf(fid,'/>\n');
156155
else
157156
fprintf(fid,'>\n');
158-
for i=1:length(this.label)
159-
fprintf(fid,'%s<Label Index="%"><![CDATA[%s]]></Label>\n',o(2),...
160-
this.label.index(i), this.label.name{i});
157+
for i=1:length(this.label.name)
158+
if ~all(isnan(this.label.rgba(i,:)))
159+
label_rgba = sprintf(' Red="%f" Green="%f" Blue="%f" Alpha="%f"',...
160+
this.label.rgba(i,:));
161+
else
162+
label_rgba = '';
163+
end
164+
fprintf(fid,'%s<Label Key="%d"%s><![CDATA[%s]]></Label>\n',o(2),...
165+
this.label.key(i), label_rgba, this.label.name{i});
161166
end
162167
fprintf(fid,'%s</LabelTable>\n',o(1));
163168
end
@@ -172,8 +177,14 @@ function save(this,filename,encoding)
172177
fn = sort(fieldnames(this.data{i}.attributes));
173178
oo = repmat({o(5) '\n'},length(fn),1); oo{1} = ' '; oo{end} = '';
174179
for j=1:length(fn)
180+
if strcmp(fn{j},'ExternalFileName')
181+
[p,f,e] = fileparts(this.data{i}.attributes.(fn{j}));
182+
attval = [f e];
183+
else
184+
attval = this.data{i}.attributes.(fn{j});
185+
end
175186
fprintf(fid,'%s%s="%s"%s',oo{j,1},...
176-
fn{j},this.data{i}.attributes.(fn{j}),sprintf(oo{j,2}));
187+
fn{j},attval,sprintf(oo{j,2}));
177188
end
178189
fprintf(fid,'>\n');
179190

@@ -223,6 +234,10 @@ function save(this,filename,encoding)
223234
% uses native machine format
224235
case 'ExternalFileBinary'
225236
extfilename = this.data{i}.attributes.ExternalFileName;
237+
dat = this.data{i}.data;
238+
if isa(dat,'file_array')
239+
dat = subsref(dat,substruct('()',repmat({':'},1,numel(dat.dim))));
240+
end
226241
if ~def.offset
227242
fide = fopen(extfilename,'w'); % uses native machine format
228243
else
@@ -232,7 +247,7 @@ function save(this,filename,encoding)
232247
error('Unable to write file %s: permission denied.',extfilename);
233248
end
234249
fseek(fide,0,1);
235-
fwrite(fide,this.data{i}.data,tp.class);
250+
fwrite(fide,dat,tp.class);
236251
def.offset = ftell(fide);
237252
fclose(fide);
238253
otherwise

@meeg/badchannels.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
66

77
% Stefan Kiebel
8-
% $Id: badchannels.m 4040 2010-08-20 23:25:46Z vladimir $
8+
% $Id: badchannels.m 4329 2011-05-19 20:54:36Z christophe $
99

1010

1111

@@ -18,7 +18,7 @@
1818

1919
if numel(varargin) >= 1 && ~isempty(varargin{1})
2020
if ~(all(varargin{1} >= 1) && all(varargin{1} <= nchannels(this)))
21-
error('Channel number of out range.');
21+
error('Channel number out of range.');
2222
end
2323
end
2424

@meeg/conditions.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
66

77
% Vladimir Litvak
8-
% $Id: conditions.m 1373 2008-04-11 14:24:03Z spm $
8+
% $Id: conditions.m 4310 2011-04-18 16:07:35Z guillaume $
99

1010
res = getset(this, 'trials', 'label', varargin{:});
1111

12-
if nargin ==1 & ~iscell(res)
12+
if nargin == 1 && ~iscell(res)
1313
res = {res};
1414
end

@meeg/coor2D.m

+9-5
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@
55
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
66

77
% Vladimir Litvak, Laurence Hunt
8-
% $Id: coor2D.m 3335 2009-08-25 16:37:02Z vladimir $
8+
% $Id: coor2D.m 4372 2011-06-21 21:26:46Z vladimir $
99

1010

1111
megind = strmatch('MEG', chantype(this));
1212
eegind = strmatch('EEG', chantype(this), 'exact');
1313
otherind = setdiff(1:nchannels(this), [megind; eegind]);
1414

1515
if nargin==1 || isempty(ind)
16-
if ~isempty(megind)
17-
ind = megind;
18-
elseif ~isempty(eegind)
19-
ind = eegind;
16+
if nargin<3 || (size(val, 2)<nchannels(this))
17+
if ~isempty(megind)
18+
ind = megind;
19+
elseif ~isempty(eegind)
20+
ind = eegind;
21+
else
22+
ind = 1:nchannels(this);
23+
end
2024
else
2125
ind = 1:nchannels(this);
2226
end

@meeg/private/checkmeeg.m

+37-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
1010

1111
% Vladimir Litvak
12-
% $Id: checkmeeg.m 4207 2011-02-22 10:48:36Z christophe $
12+
% $Id: checkmeeg.m 4437 2011-08-23 13:09:24Z vladimir $
1313

1414
if nargin==1
1515
option = 'basic';
@@ -191,6 +191,12 @@
191191
end
192192
end
193193

194+
if isfield(meegstruct, 'path')
195+
filepath = meegstruct.path;
196+
else
197+
filepath = pwd;
198+
end
199+
194200
if ~isfield(meegstruct, 'data') && (Nsamples~=0)
195201
disp('checkmeeg: no data field');
196202
return;
@@ -201,7 +207,9 @@
201207
disp('checkmeeg: data file name missing');
202208
return;
203209
else
204-
[junk, fnamedat, ext] = fileparts(meegstruct.data.fnamedat);
210+
fname = meegstruct.data.fnamedat;
211+
if ~ispc, fname = strrep(fname,'\',filesep); end
212+
[junk, fnamedat, ext] = fileparts(fname);
205213
if isempty(ext)
206214
meegstruct.data.fnamedat = [fnamedat '.dat'];
207215
else
@@ -220,11 +228,19 @@
220228
if isa(meegstruct.data.y, 'file_array')
221229
% catching up (unlikely case) where filearray.fname is
222230
% different from data.fnamedat -> set data.fnamedat
223-
[junk, yfname, yext] = fileparts(meegstruct.data.y.fname);
224-
[junk, dfname, dext] = fileparts(meegstruct.data.fnamedat);
231+
fname = meegstruct.data.y.fname;
232+
if ~ispc, fname = strrep(fname,'\',filesep); end
233+
[junk, yfname, yext] = fileparts(fname);
234+
235+
fnamedat = meegstruct.data.fnamedat;
236+
if ~ispc, fnamedat = strrep(fnamedat,'\',filesep); end
237+
[junk, dfname, dext] = fileparts(fnamedat);
225238
if ~strcmp([yfname yext],[dfname dext])
226239
meegstruct.data.fnamedat = [yfname yext];
227240
end
241+
242+
meegstruct.data.y.fname = fullfile(filepath, [yfname yext]);
243+
228244
% save original file_array scale & offset, just in case
229245
sav_sc = meegstruct.data.y.scl_slope;
230246
sav_os = meegstruct.data.y.offset;
@@ -236,14 +252,15 @@
236252
end
237253
end
238254

255+
if isa(meegstruct.data.y, 'file_array')
256+
fn = meegstruct.data.y.fname;
257+
if ~ispc, fn = strrep(fn,'\',filesep); end
258+
else
259+
fn = '';
260+
end
239261
if ~isa(meegstruct.data.y, 'file_array') ...
240-
|| isempty(fileparts(meegstruct.data.y.fname)) ...
262+
|| isempty(fileparts(fn)) ...
241263
|| ~exist(meegstruct.data.y.fname, 'file')
242-
if isfield(meegstruct, 'path')
243-
filepath = meegstruct.path;
244-
else
245-
filepath = pwd;
246-
end
247264
switch(meegstruct.transform.ID)
248265
case 'time'
249266
meegstruct.data.y = file_array(fullfile(filepath, meegstruct.data.fnamedat), ...
@@ -318,15 +335,19 @@
318335
end
319336

320337
try
321-
[pdat, fdat] = fileparts(meegstruct.data.y.fname);
338+
fname = meegstruct.data.y.fname;
339+
if ~ispc, fname = strrep(fname,'\',filesep); end
340+
[pdat, fdat] = fileparts(fname);
322341
catch
323342
fdat = 'spm8';
324343
end
325344

326345
if ~isfield(meegstruct, 'fname')
327346
meegstruct.fname = [fdat '.mat'];
328347
else
329-
[p, f] = fileparts(meegstruct.fname);
348+
fname = meegstruct.fname;
349+
if ~ispc, fname = strrep(fname,'\',filesep); end
350+
[p, f] = fileparts(fname);
330351
if isempty(f)
331352
f = fdat;
332353
end
@@ -335,7 +356,9 @@
335356

336357
if ~isfield(meegstruct, 'path')
337358
try
338-
meegstruct.path = fileparts(meegstruct.data.y.fname);
359+
fname = meegstruct.data.y.fname;
360+
if ~ispc, fname = strrep(fname,'\',filesep); end
361+
meegstruct.path = fileparts(fname);
339362
catch
340363
meegstruct.path = pwd;
341364
end
@@ -440,7 +463,7 @@
440463

441464
% Allow DCM on a pure LFP dataset
442465
if strcmp(option, 'dcm') && isempty([eegind(:); megind(:)])...
443-
&& ~isempty(lfpind)&& strcmp(meegstruct.transform.ID, 'time')
466+
&& ~isempty(lfpind) && ismember(meegstruct.transform.ID, {'time', 'TF'})
444467
result = 1;
445468
return;
446469
end

0 commit comments

Comments
 (0)