Home > rest_20090422 > rest_spm5_files > @create_file_array > private > dtype.m

dtype

PURPOSE ^

Format

SYNOPSIS ^

function varargout = dtype(varargin)

DESCRIPTION ^

 Format
 For getting the value
 dat = dtype(obj)

 For setting the value
 obj = dtype(obj,dat)
 _______________________________________________________________________
 Copyright (C) 2005 Wellcome Department of Imaging Neuroscience

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

dtype.m

SOURCE CODE ^

0001 function varargout = dtype(varargin)
0002 % Format
0003 % For getting the value
0004 % dat = dtype(obj)
0005 %
0006 % For setting the value
0007 % obj = dtype(obj,dat)
0008 % _______________________________________________________________________
0009 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
0010 
0011 %
0012 % $Id: dtype.m 253 2005-10-13 15:31:34Z guillaume $
0013 
0014 
0015 
0016 if nargin==2,
0017     varargout{1} = asgn(varargin{:});
0018 elseif nargin==1,
0019     varargout{1} = ref(varargin{:});
0020 else
0021     error('Wring number of arguments.');
0022 end;
0023 return;
0024 
0025 function t = ref(obj)
0026 d   = datatypes;
0027 mch = find(cat(1,d.code)==obj.dtype);
0028 if isempty(mch), t = 'UNKNOWN'; else t = d(mch).label; end;
0029 if obj.be, t = [t '-BE']; else t = [t '-LE']; end;
0030 return;
0031 
0032 function obj = asgn(obj,dat)
0033 d   = datatypes;
0034 if isnumeric(dat)
0035     if numel(dat)>=1,
0036         mch = find(cat(1,d.code)==dat(1));
0037         if isempty(mch) || mch==0,
0038             disp('First part of datatype should be of one of the following');
0039             disp(sortrows([num2str(cat(1,d.code)) ...
0040                 repmat(' ',numel(d),2) strvcat(d.label)]));
0041             error(['Invalid datatype (' num2str(dat(1)) ').']);
0042         end;
0043         obj.dtype = double(dat(1));
0044     end;
0045     if numel(dat)>=2,
0046         obj.be = double(dat(2)~=0);
0047     end;
0048     if numel(dat)>2,
0049         error('Too many elements in numeric datatype.');
0050     end;
0051 elseif ischar(dat),
0052     dat1 = lower(dat);
0053     sep  = find(dat1=='-' | dat1=='/');
0054     sep  = sep(sep~=1);
0055     if ~isempty(sep),
0056         c1 = dat1(1:(sep(1)-1));
0057         c2 = dat1((sep(1)+1):end);
0058     else
0059         c1 = dat1;
0060         c2 = '';
0061     end;
0062     mch = find(strcmpi(c1,lower({d.label})));
0063     if isempty(mch),
0064         disp('First part of datatype should be of one of the following');
0065         disp(sortrows([num2str(cat(1,d.code)) ...
0066             repmat(' ',numel(d),2) strvcat(d.label)]));
0067         error(['Invalid datatype (' c1 ').']);
0068     else
0069         obj.dtype = double(d(mch(1)).code);
0070     end;
0071     if any(c2=='b'),
0072         if any(c2=='l'), error('Cannot be both big and little endian.'); end;
0073         obj.be = 1;
0074     elseif any(c2=='l'),
0075         obj.be = 0;
0076     end;
0077 else
0078     error('Invalid datatype.');
0079 end;
0080 return;
0081

Generated on Wed 29-Apr-2009 01:06:38 by m2html © 2005