|
1 | 1 | function varargout=subsref(obj,subs)
|
2 | 2 | % SUBSREF Subscripted reference
|
3 | 3 | % An overloaded function...
|
4 |
| -% _________________________________________________________________________________ |
| 4 | +%__________________________________________________________________________ |
5 | 5 | % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
|
6 | 6 |
|
7 | 7 | %
|
8 |
| -% $Id: subsref.m 2781 2009-02-24 17:56:05Z guillaume $ |
| 8 | +% $Id: subsref.m 3418 2009-09-25 11:06:39Z guillaume $ |
9 | 9 |
|
10 | 10 |
|
11 |
| -if isempty(subs) |
12 |
| - return; |
13 |
| -end; |
14 |
| - |
15 |
| -if ~strcmp(subs(1).type,'()'), |
16 |
| - if strcmp(subs(1).type,'.'), |
17 |
| - %error('Attempt to reference field of non-structure array.'); |
18 |
| - %if numel(struct(obj))~=1, |
19 |
| - % error('Can only access the fields of simple file_array objects.'); |
20 |
| - %end; |
| 11 | +if isempty(subs), return; end |
21 | 12 |
|
| 13 | +switch subs(1).type |
| 14 | + case '{}' |
| 15 | + error('Cell contents reference from a non-cell array object.'); |
| 16 | + case '.' |
22 | 17 | varargout = access_fields(obj,subs);
|
23 | 18 | return;
|
24 |
| - end; |
25 |
| - if strcmp(subs.type,'{}'), error('Cell contents reference from a non-cell array object.'); end; |
26 |
| -end; |
| 19 | +end |
27 | 20 |
|
28 |
| -if numel(subs)~=1, error('Expression too complicated');end; |
| 21 | +if numel(subs)~=1, error('Expression too complicated'); end; |
29 | 22 |
|
30 | 23 | dim = [size(obj) ones(1,16)];
|
31 |
| -nd = max(find(dim>1))-1; |
| 24 | +nd = find(dim>1,1,'last')-1; |
32 | 25 | sobj = struct(obj);
|
33 | 26 |
|
34 |
| -if length(subs.subs) < nd, |
| 27 | +if ~numel(subs.subs) |
| 28 | + [subs.subs{1:nd+1}] = deal(':'); |
| 29 | +elseif length(subs.subs) < nd |
35 | 30 | l = length(subs.subs);
|
36 | 31 | dim = [dim(1:(l-1)) prod(dim(l:end))];
|
37 |
| - if numel(sobj) ~= 1, |
| 32 | + if numel(sobj) ~= 1 |
38 | 33 | error('Can only reshape simple file_array objects.');
|
39 | 34 | else
|
40 |
| - if numel(sobj.scl_slope)>1 || numel(sobj.scl_inter)>1, |
| 35 | + if numel(sobj.scl_slope)>1 || numel(sobj.scl_inter)>1 |
41 | 36 | error('Can not reshape file_array objects with multiple slopes and intercepts.');
|
42 |
| - end; |
| 37 | + end |
43 | 38 | sobj.dim = dim;
|
44 |
| - end; |
45 |
| -end; |
| 39 | + end |
| 40 | +end |
46 | 41 |
|
47 | 42 | do = ones(16,1);
|
48 |
| -args = {}; |
49 |
| -for i=1:length(subs.subs), |
50 |
| - if ischar(subs.subs{i}), |
51 |
| - if ~strcmp(subs.subs{i},':'), error('This shouldn''t happen....'); end; |
52 |
| - args{i} = 1:dim(i); |
| 43 | +args = cell(1,length(subs.subs)); |
| 44 | +for i=1:length(subs.subs) |
| 45 | + if ischar(subs.subs{i}) |
| 46 | + if ~strcmp(subs.subs{i},':'), error('This shouldn''t happen....'); end |
| 47 | + if length(subs.subs) == 1 |
| 48 | + args{i} = 1:prod(dim); % possible overflow when int32() |
| 49 | + k = 0; |
| 50 | + for j=1:length(sobj) |
| 51 | + sobj(j).dim = [prod(sobj(j).dim) 1]; |
| 52 | + sobj(j).pos = [k+1 1]; |
| 53 | + k = k + sobj(j).dim(1); |
| 54 | + end |
| 55 | + else |
| 56 | + args{i} = 1:dim(i); |
| 57 | + end |
53 | 58 | else
|
54 | 59 | args{i} = subs.subs{i};
|
55 |
| - end; |
| 60 | + end |
56 | 61 | do(i) = length(args{i});
|
57 |
| -end; |
| 62 | +end |
58 | 63 |
|
59 |
| -if length(sobj)==1, |
| 64 | +if length(sobj)==1 |
60 | 65 | t = subfun(sobj,args{:});
|
61 | 66 | else
|
62 |
| - t = zeros(do'); |
63 |
| - for j=1:length(sobj), |
| 67 | + dt = datatypes; |
| 68 | + dt = dt([dt.code]==sobj(1).dtype); % assuming identical datatypes |
| 69 | + t = zeros(do',func2str(dt.conv)); |
| 70 | + for j=1:length(sobj) |
64 | 71 | ps = [sobj(j).pos ones(1,length(args))];
|
65 | 72 | dm = [sobj(j).dim ones(1,length(args))];
|
66 |
| - for i=1:length(args), |
| 73 | + for i=1:length(args) |
67 | 74 | msk = find(args{i}>=ps(i) & args{i}<(ps(i)+dm(i)));
|
68 | 75 | args2{i} = msk;
|
69 | 76 | args3{i} = double(args{i}(msk))-ps(i)+1;
|
70 |
| - end; |
| 77 | + end |
71 | 78 |
|
72 | 79 | t = subsasgn(t,struct('type','()','subs',{args2}),subfun(sobj(j),args3{:}));
|
73 | 80 | end
|
74 | 81 | end
|
75 | 82 | varargout = {t};
|
76 |
| -return; |
77 | 83 |
|
| 84 | + |
| 85 | +%========================================================================== |
| 86 | +% function t = subfun(sobj,varargin) |
| 87 | +%========================================================================== |
78 | 88 | function t = subfun(sobj,varargin)
|
| 89 | + |
79 | 90 | %sobj.dim = [sobj.dim ones(1,16)];
|
80 | 91 | try
|
81 | 92 | args = cell(size(varargin));
|
|
89 | 100 | if ~isempty(sobj.scl_slope) || ~isempty(sobj.scl_inter)
|
90 | 101 | slope = 1;
|
91 | 102 | inter = 0;
|
92 |
| - if ~isempty(sobj.scl_slope), slope = sobj.scl_slope; end; |
93 |
| - if ~isempty(sobj.scl_inter), inter = sobj.scl_inter; end; |
94 |
| - if numel(slope)>1, |
| 103 | + if ~isempty(sobj.scl_slope), slope = sobj.scl_slope; end |
| 104 | + if ~isempty(sobj.scl_inter), inter = sobj.scl_inter; end |
| 105 | + if numel(slope)>1 |
95 | 106 | slope = resize_scales(slope,sobj.dim,varargin);
|
96 | 107 | t = double(t).*slope;
|
97 | 108 | else
|
98 | 109 | t = double(t)*slope;
|
99 |
| - end; |
100 |
| - if numel(inter)>1, |
| 110 | + end |
| 111 | + if numel(inter)>1 |
101 | 112 | inter = resize_scales(inter,sobj.dim,varargin);
|
102 | 113 | end;
|
103 | 114 | t = t + inter;
|
104 |
| -end; |
105 |
| -return; |
| 115 | +end |
| 116 | + |
106 | 117 |
|
| 118 | +%========================================================================== |
| 119 | +% function c = access_fields(obj,subs) |
| 120 | +%========================================================================== |
107 | 121 | function c = access_fields(obj,subs)
|
108 |
| -%error('Attempt to reference field of non-structure array.'); |
109 |
| -%if numel(struct(obj))~=1, |
110 |
| -% error('Can only access the fields of simple file_array objects.'); |
111 |
| -%end; |
112 |
| -c = {}; |
| 122 | + |
113 | 123 | sobj = struct(obj);
|
114 |
| -for i=1:numel(sobj), |
| 124 | +c = cell(1,numel(sobj)); |
| 125 | +for i=1:numel(sobj) |
115 | 126 | %obj = class(sobj(i),'file_array');
|
116 | 127 | obj = sobj(i);
|
117 | 128 | switch(subs(1).subs)
|
118 |
| - case 'fname', t = fname(obj); |
119 |
| - case 'dtype', t = dtype(obj); |
120 |
| - case 'offset', t = offset(obj); |
121 |
| - case 'dim', t = dim(obj); |
122 |
| - case 'scl_slope', t = scl_slope(obj); |
123 |
| - case 'scl_inter', t = scl_inter(obj); |
124 |
| - case 'permission',t = permission(obj); |
125 |
| - otherwise, error(['Reference to non-existent field "' subs(1).subs '".']); |
126 |
| - end; |
127 |
| - if numel(subs)>1, |
| 129 | + case 'fname', t = fname(obj); |
| 130 | + case 'dtype', t = dtype(obj); |
| 131 | + case 'offset', t = offset(obj); |
| 132 | + case 'dim', t = dim(obj); |
| 133 | + case 'scl_slope', t = scl_slope(obj); |
| 134 | + case 'scl_inter', t = scl_inter(obj); |
| 135 | + case 'permission', t = permission(obj); |
| 136 | + otherwise |
| 137 | + error(['Reference to non-existent field "' subs(1).subs '".']); |
| 138 | + end |
| 139 | + if numel(subs)>1 |
128 | 140 | t = subsref(t,subs(2:end));
|
129 |
| - end; |
| 141 | + end |
130 | 142 | c{i} = t;
|
131 |
| -end; |
132 |
| -return; |
| 143 | +end |
133 | 144 |
|
| 145 | + |
| 146 | +%========================================================================== |
| 147 | +% function val = multifile2mat(sobj,varargin) |
| 148 | +%========================================================================== |
134 | 149 | function val = multifile2mat(sobj,varargin)
|
| 150 | + |
135 | 151 | % Convert subscripts into linear index
|
136 |
| -[indx2{1:length(varargin)}] = ndgrid(varargin{:}); |
| 152 | +[indx2{1:length(varargin)}] = ndgrid(varargin{:},1); |
137 | 153 | ind = sub2ind(sobj.dim,indx2{:});
|
138 | 154 |
|
139 | 155 | % Work out the partition
|
140 | 156 | dt = datatypes;
|
141 |
| -sz = dt([dt.code]==sobj.dtype).size; |
| 157 | +dt = dt([dt.code]==sobj.dtype); |
| 158 | +sz = dt.size; |
142 | 159 | mem = 400*1024*1024; % in bytes, has to be a multiple of 16 (max([dt.size]))
|
143 | 160 | s = ceil(prod(sobj.dim) * sz / mem);
|
144 | 161 |
|
|
149 | 166 |
|
150 | 167 | % Read data in relevant partitions
|
151 | 168 | obj = sobj;
|
152 |
| -val = zeros(1,length(x)); |
| 169 | +val = zeros(length(x),1,func2str(dt.conv)); |
153 | 170 | for i=reshape(find(c),1,[])
|
154 | 171 | obj.offset = sobj.offset + mem*(i-1);
|
155 | 172 | obj.dim = [1 min(mem/sz, prod(sobj.dim)-(i-1)*mem/sz)];
|
156 | 173 | val(cc(i)+1:cc(i+1)) = file2mat(obj,int32(1),int32(x(y==i)));
|
157 | 174 | end
|
158 |
| -val = reshape(val,cellfun('length',varargin)); |
| 175 | +r = cellfun('length',varargin); |
| 176 | +if numel(r) == 1, r = [r 1]; end |
| 177 | +val = reshape(val,r); |
0 commit comments