0001 function BRIK2MGH(fname,xdim,ydim,zdim,timepoints,type,foutstem)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 disp(' ')
0014 disp('**********************************')
0015 disp(' ')
0016 disp('BRIK2MGH: reading raw data . . . .')
0017 fid = fopen(fname, 'rb');
0018 data = fread(fid, [xdim * ydim * zdim * timepoints], type);
0019 disp(['max: ' num2str(max(data(:))) ', min: ' num2str(min(data(:))) ])
0020 fclose(fid);
0021 disp('BRIK2MGH: done reading raw data !')
0022 disp(' ')
0023
0024 disp('BRIK2MGH: reshaping raw data to 3D+time matrix . . . .')
0025 V = reshape(data,xdim,ydim,zdim,timepoints);
0026 disp('BRIK2MGH: done reshaping raw data to 3D+time matrix !')
0027 disp(' ')
0028
0029 disp('BRIK2MGH: writing MGH-style image files . . . .')
0030 disp(' ')
0031
0032 bfile = zeros(xdim,ydim,timepoints);
0033
0034
0035
0036
0037 for i = 1:zdim
0038
0039
0040 bfile(:,:,:) = V(:,:,i,:);
0041
0042
0043 suffix = ['.b' type];
0044 outfname = sprintf('%s%03d%s%s',foutstem,i-1,suffix);
0045
0046
0047
0048 disp(['BRIK2MGH: writing file ' num2str(outfname) ', max: ' num2str(max(bfile(:))) ', min: ' num2str(min(bfile(:))) ])
0049 fid = fopen(outfname, 'w');
0050 fwrite(fid, bfile(:), type);
0051 fclose(fid);
0052
0053
0054 hdrfname = sprintf('%s%03d%s',foutstem,i-1,'.hdr');
0055 fid = fopen(hdrfname,'w');
0056 fprintf(fid,'%d %d %d 0\n',xdim, ydim, timepoints);
0057 fclose(fid);
0058
0059 end
0060
0061 disp(' ')
0062 disp('Done!')
0063
0064
0065
0066
0067
0068
0069
0070