Skip to content

Commit f6948ff

Browse files
committed
SPM12 r6225
0 parents  commit f6948ff

File tree

4,218 files changed

+599693
-0
lines changed

Some content is hidden

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

4,218 files changed

+599693
-0
lines changed

@file_array/Contents.m

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
% File Array Object
2+
%
3+
% file_array - create a file_array
4+
% horzcat - horizontal concatenation
5+
% vertcat - vertical concatenation
6+
% size - size of array
7+
% length - length of longest dimension
8+
% subsref - subscripted reference
9+
% end - last index in an indexing expression
10+
% resize - resize (but only of simple file_array structures)
11+
%
12+
% other operations are unlikely to work.
13+
%
14+
% Example usage.
15+
%
16+
% % Create a file array object by mapping test_le.img
17+
% % to a 256x256x100 array, of datatype float32, stored
18+
% % in a little-endian way starting at byte 0.
19+
% fa0 = file_array('test_le.img',[256 256 100], 'FLOAT32-LE',0)
20+
%
21+
% % Creating an object from test_be.img, but skipping
22+
% % the first plane of data. Data stored as big-endian
23+
% fa1 = file_array('test_be.img',[256 256 99], 'FLOAT32-BE',4*256*256)
24+
%
25+
% % Reshape procedure
26+
% fa2 = reshape(fa1,[128 2 256 99])
27+
%
28+
% % Concatenation
29+
% fa3 = [[fa0 fa0]; [fa0 fa0]]
30+
% fa4 = cat(3,fa0,fa1)
31+
%
32+
% % Note that reshape will not work on the above
33+
% % concatenated objects
34+
%
35+
% % Accessing values from the objects
36+
% img = fa1(:,:,40);
37+
% pixval = fa4(50,50,:);
38+
% small = fa1(1:2:end,1:2:end,40);
39+
%
40+
% % Determining dimensions
41+
% size(fa4)
42+
% size(fa2)
43+
% length(fa0)
44+
% _________________________________________________________________________
45+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
46+
47+
%
48+
% $Id: Contents.m 2696 2009-02-05 20:29:48Z guillaume $
49+
50+

@file_array/cat.m

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function o = cat(dr,varargin)
2+
% Concatenate file_array objects. The result is a non-simple object
3+
% that can no longer be reshaped.
4+
% _______________________________________________________________________
5+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
6+
7+
%
8+
% $Id: cat.m 4136 2010-12-09 22:22:28Z guillaume $
9+
10+
11+
if dr>32 || dr<0, error('Unknown command option.'); end;
12+
dr = max(round(dr),1);
13+
d = ones(nargin-1,16);
14+
tmp = {};
15+
dpos = 0;
16+
for i=1:nargin-1,
17+
vi = varargin{i};
18+
if strcmp(class(vi),'file_array')
19+
sz = size(vi);
20+
d(i,1:length(sz)) = sz;
21+
svi = struct(vi);
22+
svi = svi(:);
23+
for j=1:length(svi(:)),
24+
if length(svi(j).pos)<dr
25+
svi(j).pos((length(svi(j).pos)+1):dr) = 1;
26+
end
27+
svi(j).pos(dr)= svi(j).pos(dr) + dpos;
28+
end;
29+
dpos = dpos + d(i,dr);
30+
tmp{i} = svi;
31+
else
32+
error(['Conversion to file_array from ' class(vi) ' is not possible.']);
33+
end;
34+
end;
35+
if any(diff(d(:,[1:(dr-1) (dr+1):end]),1,1))
36+
error('All matrices on a row in the bracketed expression must have the same number of rows.');
37+
else
38+
o = vertcat(tmp{:});
39+
o = file_array(o);
40+
end;

@file_array/ctranspose.m

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function varargout = ctranspose(varargin)
2+
% Transposing not allowed
3+
% _______________________________________________________________________
4+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
5+
6+
%
7+
% $Id: ctranspose.m 1143 2008-02-07 19:33:33Z spm $
8+
9+
error('file_array objects can not be transposed.');

@file_array/disp.m

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function disp(obj)
2+
% Display a file_array object
3+
% _______________________________________________________________________
4+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
5+
6+
%
7+
% $Id: disp.m 4136 2010-12-09 22:22:28Z guillaume $
8+
9+
10+
if numel(struct(obj))>1,
11+
fprintf(' %s object: ', class(obj));
12+
sz = size(obj);
13+
if length(sz)>4,
14+
fprintf('%d-D\n',length(sz));
15+
else
16+
for i=1:(length(sz)-1),
17+
fprintf('%d-by-',sz(i));
18+
end;
19+
fprintf('%d\n',sz(end));
20+
end;
21+
else
22+
disp(mystruct(obj))
23+
end;
24+
return;
25+
%=======================================================================
26+
27+
%=======================================================================
28+
function t = mystruct(obj)
29+
fn = fieldnames(obj);
30+
for i=1:length(fn)
31+
t.(fn{i}) = subsref(obj,struct('type','.','subs',fn{i}));
32+
end;
33+
return;
34+
%=======================================================================

@file_array/display.m

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function display(obj)
2+
% Display a file_array object
3+
% _______________________________________________________________________
4+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
5+
6+
%
7+
% $Id: display.m 1143 2008-02-07 19:33:33Z spm $
8+
9+
10+
disp(' ');
11+
disp([inputname(1),' = '])
12+
disp(' ');
13+
disp(obj)
14+
disp(' ')

@file_array/double.m

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function out = double(fa)
2+
% Convert to double precision
3+
% FORMAT double(fa)
4+
% fa - a file_array
5+
% _______________________________________________________________________
6+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
7+
8+
%
9+
% $Id: double.m 1143 2008-02-07 19:33:33Z spm $
10+
11+
out = double(numeric(fa));
12+

@file_array/end.m

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function en = end(a,k,n)
2+
% Overloaded end function for file_array objects.
3+
% _______________________________________________________________________
4+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
5+
6+
%
7+
% $Id: end.m 1143 2008-02-07 19:33:33Z spm $
8+
9+
dim = size(a);
10+
if k>length(dim)
11+
en = 1;
12+
else
13+
if n<length(dim),
14+
dim = [dim(1:(n-1)) prod(dim(n:end))];
15+
end;
16+
en = dim(k);
17+
end;

@file_array/fieldnames.m

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function t = fieldnames(obj)
2+
% Fieldnames of a file-array object
3+
% _______________________________________________________________________
4+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
5+
6+
%
7+
% $Id: fieldnames.m 1143 2008-02-07 19:33:33Z spm $
8+
9+
t = {...
10+
'fname'
11+
'dim'
12+
'dtype'
13+
'offset'
14+
'scl_slope'
15+
'scl_inter'
16+
};

@file_array/file_array.m

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function a = file_array(varargin)
2+
% Function for creating file_array objects.
3+
% FORMAT a = file_array(fname,dim,dtype,offset,scl_slope,scl_inter,permission)
4+
% a - file_array object
5+
% fname - filename
6+
% dim - dimensions (default = [0 0] )
7+
% dtype - datatype (default = 'uint8-le')
8+
% offset - offset into file (default = 0)
9+
% scl_slope - scalefactor (default = 1)
10+
% scl_inter - DC offset, such that dat = raw*scale + inter (default = 0)
11+
% permission - Write permission, either 'rw' or 'ro' (default = 'rw')
12+
% _______________________________________________________________________
13+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
14+
15+
%
16+
% $Id: file_array.m 4136 2010-12-09 22:22:28Z guillaume $
17+
18+
19+
if nargin==1
20+
if isstruct(varargin{1}),
21+
a = class(varargin{1},'file_array');
22+
return;
23+
elseif isa(varargin{1},'file_array'),
24+
a = varargin{1};
25+
return;
26+
end;
27+
end;
28+
a = struct('fname','','dim',[0 0],'dtype',2,...
29+
'be',0,'offset',0,'pos',[],'scl_slope',[],'scl_inter',[], 'permission','rw');
30+
%a = class(a,'file_array');
31+
32+
if nargin>=1, a = fname(a,varargin{1}); end;
33+
if nargin>=2, a = dim(a,varargin{2}); end;
34+
if nargin>=3, a = dtype(a,varargin{3}); end;
35+
if nargin>=4, a = offset(a,varargin{4}); end;
36+
if nargin>=5, a = scl_slope(a,varargin{5}); end;
37+
if nargin>=6, a = scl_inter(a,varargin{6}); end;
38+
if nargin>=7, a = permission(a,varargin{7}); end;
39+
40+
a.pos = ones(size(a.dim));
41+
a = file_array(a);
42+

@file_array/horzcat.m

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function o = horzcat(varargin)
2+
% Horizontal concatenation of file_array objects
3+
% _______________________________________________________________________
4+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
5+
6+
%
7+
% $Id: horzcat.m 1143 2008-02-07 19:33:33Z spm $
8+
9+
o = cat(2,varargin{:});
10+
return;
11+

@file_array/initialise.m

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function initialise(fa)
2+
% Initialise file on disk
3+
%
4+
% This creates a file on disk with the appropriate size by explicitly
5+
% writing data to prevent a sparse file.
6+
%__________________________________________________________________________
7+
% Copyright (C) 2013 Wellcome Trust Centre for Neuroimaging
8+
9+
%
10+
% $Id: initialise.m 5458 2013-05-01 14:32:23Z guillaume $
11+
12+
13+
% first approach
14+
% fa = subsasgn(fa, substruct('()',num2cell(size(fa))), 0);
15+
16+
% second approach
17+
% fa = subsasgn(fa, substruct('()',repmat({':'},1,ndims(fa))), 0);
18+
19+
% third approach (problem if n > intmax('int32'))
20+
% bs = 2^20;
21+
% n = prod(size(fa)); %#ok<PSIZE>
22+
% fa = reshape(fa,n,1);
23+
% for i=1:ceil(n/bs)
24+
% ii = ((((i-1)*bs)+1):min((i*bs),n))';
25+
% fa = subsasgn(fa,struct('type','()','subs',{{ii}}),zeros(numel(ii),1));
26+
% end
27+
28+
d = datatypes;
29+
dt = find(cat(1,d.code)==fa.dtype);
30+
if isempty(dt), error('Unknown datatype.'); end
31+
d = d(dt);
32+
nbytes = d.nelem * d.size * prod(size(fa)); %#ok<PSIZE>
33+
init(fa.fname, nbytes, struct('offset',fa.offset));

@file_array/isnan.m

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function out = isnan(fa)
2+
% Convert to numeric form
3+
% FORMAT isnan(fa)
4+
% fa - a file_array
5+
% _______________________________________________________________________
6+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
7+
8+
%
9+
% $Id: isnan.m 1301 2008-04-03 13:21:44Z john $
10+
11+
bs = 10240;
12+
m = size(fa);
13+
fa = reshape(fa,prod(m),1);
14+
n = prod(m);
15+
out = false(m);
16+
for i=1:ceil(n/bs),
17+
ii = ((((i-1)*bs)+1):min((i*bs),n))';
18+
tmp = subsref(fa,struct('type','()','subs',{{ii}}));
19+
out(ii) = isnan(tmp);
20+
end
21+

@file_array/length.m

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function l = length(x)
2+
% Overloaded length function for file_array objects
3+
% _______________________________________________________________________
4+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
5+
6+
%
7+
% $Id: length.m 1143 2008-02-07 19:33:33Z spm $
8+
9+
10+
l = max(size(x));
11+

@file_array/loadobj.m

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function b = loadobj(a)
2+
% loadobj for file_array class
3+
% _______________________________________________________________________
4+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
5+
6+
%
7+
% $Id: loadobj.m 1544 2008-05-06 10:34:36Z guillaume $
8+
9+
if isa(a,'file_array')
10+
b = a;
11+
else
12+
a = permission(a, 'rw');
13+
b = file_array(a);
14+
end

@file_array/ndims.m

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function out = ndims(fa)
2+
% Number of dimensions
3+
%_______________________________________________________________________
4+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
5+
6+
%
7+
% $Id: ndims.m 1143 2008-02-07 19:33:33Z spm $
8+
9+
10+
out = size(fa);
11+
out = length(out);
12+

@file_array/numel.m

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function t = numel(obj)
2+
% Number of simple file arrays involved.
3+
% _______________________________________________________________________
4+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
5+
6+
%
7+
% $Id: numel.m 1143 2008-02-07 19:33:33Z spm $
8+
9+
10+
% Should be this, but it causes problems when accessing
11+
% obj as a structure.
12+
%t = prod(size(obj));
13+
14+
t = numel(struct(obj));

@file_array/numeric.m

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function out = numeric(fa)
2+
% Convert to numeric form
3+
% FORMAT numeric(fa)
4+
% fa - a file_array
5+
% _______________________________________________________________________
6+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
7+
8+
%
9+
% $Id: numeric.m 1143 2008-02-07 19:33:33Z spm $
10+
11+
12+
[vo{1:ndims(fa)}] = deal(':');
13+
out = subsref(fa,struct('type','()','subs',{vo}));
14+

@file_array/permute.m

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function varargout = permute(varargin)
2+
% Can not be permuted.
3+
% _______________________________________________________________________
4+
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
5+
6+
%
7+
% $Id: permute.m 1143 2008-02-07 19:33:33Z spm $
8+
9+
10+
error('file_array objects can not be permuted.');

0 commit comments

Comments
 (0)