0001 function status = GE_convertVolume(inDir,runnum,outName)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 status = 1;
0022
0023 if (nargin < 3)
0024 error('Not enough input arguments.')
0025 return
0026 end
0027
0028
0029 firstfile = fullfile(inDir,'I.001');
0030
0031
0032
0033 if ~exist(firstfile)
0034 new_first = fullfile(inDir,'i.001');
0035 if exist(new_first)
0036 fprintf('Expected I.001, found i.001. Using i.001\n');
0037 firstfile = new_first;
0038 else
0039 error(sprintf('Could not locate first file in image: %s\n', firstfile));
0040 end
0041 end
0042
0043
0044 [header, orient, im_offset, adwcount] = GE_createSPMHeader(firstfile);
0045 volSize = [header.dim(2) header.dim(3) header.dim(4)];
0046
0047 header = GE_reorientHeader(header, orient);
0048
0049
0050 [imageVol, lastfile] = GE_readVolume(inDir, runnum, volSize, header.bitpix, im_offset);
0051
0052
0053 imageVol = GE_reorientImage(imageVol, orient);
0054
0055
0056 outFile = strcat(outName,'.hdr');
0057 status = GE_writeSPMHeader(outFile,header);
0058
0059
0060 outFile = [outName sprintf('.img')];
0061 [fid,message] = fopen(outFile,'w');
0062 if (fid == -1)
0063 fprintf('Cannot Open %s for writing.\n',outFile);
0064 error(message);
0065 end
0066
0067 fwrite(fid,reshape(imageVol,1,prod(size(imageVol))),'int16');
0068 status = fclose(fid);
0069
0070
0071 fprintf('Wrote %s.img.\n',outName);
0072
0073
0074 fprintf('\nConversion Finished. \n');
0075
0076 return