Home > fmri > utils > write_dir.m

write_dir

PURPOSE ^

write_dir(V,dirname,fstub);

SYNOPSIS ^

function write_dir(V,dirname,fstub)

DESCRIPTION ^

 write_dir(V,dirname,fstub);

 Writes image volume time series data from V into directory dirname
 fstub -- root of individual filenames.  Final file names are

    fstub_i0001.img, fstub_i0002.img, etc.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function write_dir(V,dirname,fstub)
0002 % write_dir(V,dirname,fstub);
0003 %
0004 % Writes image volume time series data from V into directory dirname
0005 % fstub -- root of individual filenames.  Final file names are
0006 %
0007 %    fstub_i0001.img, fstub_i0002.img, etc.
0008 %
0009 
0010 % 5/18/00 PJ
0011 
0012 % Check to see if dirname exists
0013 
0014 if ~exist(dirname,'dir')
0015   disp(sprintf('Creating directory: %s', dirname))
0016   unix(['mkdir ' dirname]);
0017 end
0018 
0019 dims = size(V);
0020 nvol = dims(4);
0021 
0022 disp(sprintf('Writing %d volumes ...', nvol))
0023 
0024 for ivol = 1:nvol
0025   outfname = sprintf('%s/%s_i%04d.img', dirname, fstub, ivol);
0026   
0027   fid = fopen(outfname, 'wb', 'l');
0028   if fid == -1
0029     error(sprintf('Failed to open file %s for writing', outfname))
0030   end
0031   
0032   count = fwrite(fid,V(:,:,:,ivol),'integer*2');
0033   if count ~= prod(dims(1:3))
0034     error(sprintf('Failed to write all data for file %s', outfname))
0035   end
0036     
0037   fclose(fid);
0038 end % for ivol=

Generated on Sun 19-May-2019 04:00:51 by m2html © 2003