-
Notifications
You must be signed in to change notification settings - Fork 5
/
save_nii_ext.m
38 lines (28 loc) · 1015 Bytes
/
save_nii_ext.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
% Save NIFTI header extension.
%
% Usage: save_nii_ext(ext, fid)
%
% ext - struct with NIFTI header extension fields.
%
% NIFTI data format can be found on: http://nifti.nimh.nih.gov
%
% - Jimmy Shen (jimmy@rotman-baycrest.on.ca)
%
function save_nii_ext(ext, fid)
if ~exist('ext','var') | ~exist('fid','var')
error('Usage: save_nii_ext(ext, fid)');
end
if ~isfield(ext,'extension') | ~isfield(ext,'section') | ~isfield(ext,'num_ext')
error('Wrong header extension');
end
write_ext(ext, fid);
return; % save_nii_ext
%---------------------------------------------------------------------
function write_ext(ext, fid)
fwrite(fid, ext.extension, 'uchar');
for i=1:ext.num_ext
fwrite(fid, ext.section(i).esize, 'int32');
fwrite(fid, ext.section(i).ecode, 'int32');
fwrite(fid, ext.section(i).edata, 'uchar');
end
return; % write_ext