Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


GE_readVolume.m

Go to the documentation of this file.
00001 function [imageVol, lastfile] = GE_readVolume(startDir, passnum, volSize, depth, im_offset)
00002 %
00003 %GE_readVolume
00004 % 
00005 % [imageVol, lastfile] = GE_readVolume(startDir, passnum, [nX nY nZ], depth, im_offset)
00006 %
00007 % reads the volume for passnum from the series which is stored
00008 % starting in startDir and returns the name of the last file read
00009 %
00010 % Souheil J. Inati
00011 % Dartmouth College
00012 % May 2000
00013 % souheil.inati@dartmouth.edu
00014 %
00015 
00016 % initialize some variables
00017 nX = volSize(1);
00018 nY = volSize(2);
00019 nZ = volSize(3);
00020 sliceSize = nX*nY;
00021 imageVol = zeros(nX, nY, nZ);
00022 [path_stem, path_start] = fileparts(startDir);
00023 
00024 for i = 1:nZ
00025         % Make the filename
00026         filenum = (passnum-1)*nZ + i;   % file no.
00027         filep = ceil(filenum/999) - 1;
00028         filen = filenum - 999*filep;
00029         path_num = str2num(path_start) + 20*filep;
00030         path_now = sprintf('00%d',path_num);
00031         path_now = path_now(length(path_now)-2:length(path_now));
00032         path = fullfile(path_stem, path_now);
00033         stub = sprintf('00%d',filen);
00034         stub = stub(length(stub)-2:length(stub));
00035         imageFile = fullfile(path,['I.' stub]);
00036 
00037         % Open the file
00038         [fid,message] = fopen(imageFile,'r','b');
00039         if (fid == -1)
00040           fprintf('Cannot Open %s.\n',imageFile);
00041           passnum
00042           break
00043         end
00044 
00045         % Skip to the data
00046         fseek(fid,im_offset,-1);
00047         % Read the slice
00048         buffer = fread(fid,sliceSize,sprintf('int%d',depth));
00049         % append the slice to the imageSet
00050         imageVol(:,:,i) = reshape(buffer, nX, nY);
00051 
00052         % Close the file
00053         status = fclose(fid);
00054 
00055         % Set the lastfile
00056         lastfile = imageFile;
00057 end
00058 
00059 return
 

Powered by Plone

This site conforms to the following standards: