0001 function o = niftistruc
0002
0003
0004
0005
0006
0007
0008
0009
0010 persistent org;
0011 if ~isempty(org),
0012 o = org;
0013 return;
0014 end;
0015 t = struct('conv',{ @char , @uint8 , @int16 , @int32 , @single },...
0016 'prec',{'uint8', 'uint8', 'int16', 'int32', 'single'},...
0017 'size',{ 1, 1, 2, 4, 4 });
0018 c = t(1);
0019 b = t(2);
0020 s = t(3);
0021 i = t(4);
0022 f = t(5);
0023
0024 table = {...
0025 i, 1,'sizeof_hdr',348
0026 c,10,'data_type',[]
0027 c,18,'db_name',[]
0028 i, 1,'extents',[]
0029 s, 1,'session_error',[]
0030 c, 1,'regular','r'
0031 b, 1,'dim_info',[]
0032 s, 8,'dim',[3 0 0 0 1 1 1 1 1]
0033 f, 1,'intent_p1',0
0034 f, 1,'intent_p2',0
0035 f, 1,'intent_p3',0
0036 s, 1,'intent_code',0
0037 s, 1,'datatype',2
0038 s, 1,'bitpix',8
0039 s, 1,'slice_start',[]
0040 f, 8,'pixdim',[0 1 1 1]
0041 f, 1,'vox_offset',0
0042 f, 1,'scl_slope',1
0043 f, 1,'scl_inter',0
0044 s, 1,'slice_end',[]
0045 b, 1,'slice_code',[]
0046 b, 1,'xyzt_units',10
0047 f, 1,'cal_max',[]
0048 f, 1,'cal_min',[]
0049 f, 1,'slice_duration',[]
0050 f, 1,'toffset',[]
0051 i, 1,'glmax',[]
0052 i, 1,'glmin',[]
0053 c,80,'descrip','NIFTI-1 Image'
0054 c,24,'aux_file',''
0055 s, 1,'qform_code',0
0056 s, 1,'sform_code',0
0057 f, 1,'quatern_b',0
0058 f, 1,'quatern_c',0
0059 f, 1,'quatern_d',0
0060 f, 1,'qoffset_x',0
0061 f, 1,'qoffset_y',0
0062 f, 1,'qoffset_z',0
0063 f, 4,'srow_x',[1 0 0 0]
0064 f, 4,'srow_y',[0 1 0 0]
0065 f, 4,'srow_z',[0 0 1 0]
0066 c,16,'intent_name',''
0067 c, 4,'magic','ni1'};
0068 org = struct('label',table(:,3),'dtype',table(:,1),'len',table(:,2),...
0069 'offset',0,'def',table(:,4));
0070 os = 0;
0071 for j=1:length(org)
0072 os = os + org(j).dtype.size*ceil(os/org(j).dtype.size);
0073 fun = org(j).dtype.conv;
0074 def = [org(j).def zeros(1,org(j).len-length(org(j).def))];
0075 org(j).def = feval(fun,def);
0076 org(j).offset = os;
0077 os = os + org(j).len*org(j).dtype.size;
0078 end;
0079 o = org;
0080 return;
0081