Home > rest_20090422 > rest_spm5_files > nic_spm_type.m

nic_spm_type

PURPOSE ^

translates data type specifiers between SPM & Matlab representations

SYNOPSIS ^

function T = spm_type(x, arg)

DESCRIPTION ^

 translates data type specifiers between SPM & Matlab representations
 FORMAT T = spm_type(x, arg)
 x    - specifier
 T    - type
 arg  - optional string argument, can be
     - 'maxval'  - return maximum allowed value.
     - 'minval'  - return minimum allowed value.
     - 'nanrep'  - return 1 if there is a NaN representation.
     - 'bits'    - return the number of bits per voxel.
     - 'intt'    - return 1 if values rounded to nearest integer.
_______________________________________________________________________

 Format specifiers are based on NIFTI-1.  If the input is
 a number then the corresponding matlab string is returned by default.
 If the input is a string then the appropriate TYPE is returned.
 However, if the optional arg argument is supplied then other
 information will be returned instead.

 With no arguments, a list of data types is returned.
_______________________________________________________________________
 Copyright (C) 2005 Wellcome Department of Imaging Neuroscienic_e

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

nic_spm_type.m

SOURCE CODE ^

0001 function T = spm_type(x, arg)
0002 % translates data type specifiers between SPM & Matlab representations
0003 % FORMAT T = spm_type(x, arg)
0004 % x    - specifier
0005 % T    - type
0006 % arg  - optional string argument, can be
0007 %     - 'maxval'  - return maximum allowed value.
0008 %     - 'minval'  - return minimum allowed value.
0009 %     - 'nanrep'  - return 1 if there is a NaN representation.
0010 %     - 'bits'    - return the number of bits per voxel.
0011 %     - 'intt'    - return 1 if values rounded to nearest integer.
0012 %_______________________________________________________________________
0013 %
0014 % Format specifiers are based on NIFTI-1.  If the input is
0015 % a number then the corresponding matlab string is returned by default.
0016 % If the input is a string then the appropriate TYPE is returned.
0017 % However, if the optional arg argument is supplied then other
0018 % information will be returned instead.
0019 %
0020 % With no arguments, a list of data types is returned.
0021 %_______________________________________________________________________
0022 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscienic_e
0023 
0024 % John Ashburner & Andrew Holmes
0025 % $Id: spm_type.m 112 2005-05-04 18:20:52Z john $
0026 
0027 
0028 
0029 prec = char('uint8','int16','int32','float32','float64','int8','uint16','uint32');
0030 types   = [    2      4      8   16   64   256    512    768];
0031 maxval  = [2^8-1 2^15-1 2^31-1  Inf  Inf 2^7-1 2^16-1 2^32-1];
0032 minval  = [    0  -2^15  -2^31 -Inf -Inf  -2^7      0      0];
0033 nanrep  = [    0      0      0    1    1     0      0      0];
0034 bits    = [    8     16     32   32   64     8     16     32];
0035 intt    = [    1      1      1    0    0     1      1      1];
0036 
0037 if nargin==0,
0038     T=types;
0039     return;
0040 end;
0041 
0042 if ischar(x),
0043     sel = [];
0044     for i=1:numel(types),
0045         if strcmpi(deblank(prec(i,:)),deblank(x)), 
0046             sel = i;
0047             break;
0048         end;
0049     end;
0050 else,
0051     sel = find(types == x);
0052 end;
0053 if nargin == 1,
0054     if ischar(x),
0055         if isempty(sel), T = NaN;
0056         else, T = types(sel); end;
0057     else,
0058         if isempty(sel), T = 'unknown';
0059         else, T = deblank(prec(sel,:)); end;
0060     end;
0061 elseif isempty(sel),
0062     T = NaN;
0063 else,
0064     switch lower(arg)
0065     case 'maxval',  T = maxval(sel);
0066     case 'minval',  T = minval(sel);
0067     case 'nanrep',  T = nanrep(sel);
0068     case 'bits',    T = bits(sel);
0069     case 'intt',    T = intt(sel);
0070     otherwise,      T = NaN;
0071     end;
0072 end;

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