0001 function varargout=subsref(obj,subs)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 if isempty(subs)
0012 return;
0013 end;
0014
0015 if ~strcmp(subs(1).type,'()'),
0016 if strcmp(subs(1).type,'.'),
0017
0018
0019
0020
0021
0022 varargout = access_fields(obj,subs);
0023 return;
0024 end;
0025 if strcmp(subs.type,'{}'), error('Cell contents reference from a non-cell array object.'); end;
0026 end;
0027
0028 if numel(subs)~=1, error('Expression too complicated');end;
0029
0030 dim = [size(obj) ones(1,16)];
0031 nd = max(find(dim>1))-1;
0032 sobj = struct(obj);
0033
0034 if length(subs.subs) < nd,
0035 l = length(subs.subs);
0036 dim = [dim(1:(l-1)) prod(dim(l:end))];
0037 if numel(sobj) ~= 1,
0038 error('Can only reshape simple create_file_array objects.');
0039 else
0040 if numel(sobj.scl_slope)>1 || numel(sobj.scl_inter)>1,
0041 error('Can not reshape create_file_array objects with multiple slopes and intercepts.');
0042 end;
0043 sobj.dim = dim;
0044 end;
0045 end;
0046
0047 do = ones(16,1);
0048 args = {};
0049 for i=1:length(subs.subs),
0050 if ischar(subs.subs{i}),
0051 if ~strcmp(subs.subs{i},':'), error('This shouldn''t happen....'); end;
0052 args{i} = int32(1:dim(i));
0053 else
0054 args{i} = int32(subs.subs{i});
0055 end;
0056 do(i) = length(args{i});
0057 end;
0058
0059 if length(sobj)==1,
0060 t = subfun(sobj,args{:});
0061 else
0062 t = zeros(do');
0063 for j=1:length(sobj),
0064 ps = [sobj(j).pos ones(1,length(args))];
0065 dm = [sobj(j).dim ones(1,length(args))];
0066 for i=1:length(args),
0067 msk = find(args{i}>=ps(i) & args{i}<(ps(i)+dm(i)));
0068 args2{i} = msk;
0069 args3{i} = int32(double(args{i}(msk))-ps(i)+1);
0070 end;
0071
0072 t = subsasgn(t,struct('type','()','subs',{args2}),subfun(sobj(j),args3{:}));
0073 end
0074 end
0075 varargout = {t};
0076 return;
0077
0078 function t = subfun(sobj,varargin)
0079
0080 t = file2mat(sobj,varargin{:});
0081 if ~isempty(sobj.scl_slope) || ~isempty(sobj.scl_inter)
0082 slope = 1;
0083 inter = 0;
0084 if ~isempty(sobj.scl_slope), slope = sobj.scl_slope; end;
0085 if ~isempty(sobj.scl_inter), inter = sobj.scl_inter; end;
0086 if numel(slope)>1,
0087 slope = resize_scales(slope,sobj.dim,varargin);
0088 t = double(t).*slope;
0089 else
0090 t = double(t)*slope;
0091 end;
0092 if numel(inter)>1,
0093 inter = resize_scales(inter,sobj.dim,varargin);
0094 end;
0095 t = t + inter;
0096 end;
0097 return;
0098
0099 function c = access_fields(obj,subs)
0100
0101
0102
0103
0104 c = {};
0105 sobj = struct(obj);
0106 for i=1:numel(sobj),
0107
0108 obj = sobj(i);
0109 switch(subs(1).subs)
0110 case 'fname', t = fname(obj);
0111 case 'dtype', t = dtype(obj);
0112 case 'offset', t = offset(obj);
0113 case 'dim', t = dim(obj);
0114 case 'scl_slope', t = scl_slope(obj);
0115 case 'scl_inter', t = scl_inter(obj);
0116 otherwise, error(['Reference to non-existent field "' subs(1).type '".']);
0117 end;
0118 if numel(subs)>1,
0119 t = subsref(t,subs(2:end));
0120 end;
0121 c{i} = t;
0122 end;
0123 return;
0124