Skip to content

AFNI/NIfTI Server

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

Doxygen Source Code Documentation


GE_get_volsperrun.m

Go to the documentation of this file.
00001 function [ volsperrun ] = GE_get_volsperrun(inDir)
00002 %
00003 % [ volsperrun ] = GE_get_volsperrun(inDir)
00004 %
00005 % A utility to find the number of volumes per run in an ADW scan.
00006 % inDir is the starting directory for the I.* files.
00007 %
00008 % Souheil J. Inati  
00009 % Dartmouth College
00010 % July 2001
00011 % souheil.inati@dartmouth.edu
00012 %
00013 
00014 % Get series ID number
00015 ser_idstr = inDir(end);
00016 ser_idnum = str2num(ser_idstr);
00017 
00018 % Strip tailing directory
00019 GE_data_root = inDir(1:max(findstr('/',inDir))-1);
00020 
00021 % List directories and extract those corresponding to the desired series
00022 d = dir(GE_data_root);
00023 
00024 dir_idx = find(cat(d.isdir));
00025 ndir = length(dir_idx);
00026 
00027 dirmat = char(d.name);
00028 
00029 good_idx = find((dirmat(:,3) == ser_idstr) & isspace(dirmat(:,4)));
00030 
00031 ser_dirnames = char(d(good_idx).name);
00032 
00033 ndir = size(ser_dirnames,1);
00034 
00035 byte_align = 0;
00036 
00037 % Open the first file and get the number of slices
00038 firstfile = fullfile(GE_data_root, ser_dirnames(1,:), 'I.001');
00039 [su_hdr,ex_hdr,se_hdr,im_hdr,pix_hdr,im_offset] = GE_readHeader(firstfile);
00040 nslices = im_hdr.slquant;
00041 
00042 nimg = 0;
00043 
00044 for idir = 1:ndir
00045   curdir = fullfile(GE_data_root, ser_dirnames(idir,:));
00046   subd = dir(curdir);
00047   
00048   dirmat = char(subd.name);
00049   good_idx = strmatch('I.', dirmat);
00050   nfiles = length(good_idx);
00051   
00052   disp(sprintf('Found %d image files in directory %s', nfiles, curdir))
00053   
00054   flist = sort(cellstr(char(subd(good_idx).name)));
00055 
00056   % Loop through and read the run number from the header of each file
00057   for ifile = 1:nfiles
00058     imageFile = fullfile(curdir, flist{ifile});
00059     nimg = nimg+1;
00060     fid = fopen(imageFile,'r','b');
00061     fseek(fid,4936,'bof');
00062     runnum(nimg) =  fread(fid,1,'float32'); % im_hdr.user17
00063     imagename{nimg} = imageFile;
00064     fclose(fid);
00065   end
00066 end
00067 
00068 % Output the results to the screen
00069 [B,I,J] = unique(runnum);
00070 
00071 imperrun = [I(1) diff(I)];
00072 
00073 volsperrun = imperrun/nslices;
00074 
00075 %numrun = length(B);
00076 %fprintf('There are %d functionals runs.\n',numrun)
00077 
00078 %for i = 1:numrun
00079 %  fprintf('run %d consists of %d images = %d volumes\n',B(i),imperrun(i),imperrun(i)/nslices)
00080 %end
00081 
00082 return
00083 
00084 
00085 
00086     %    im_rawrunnum(nimg) = im_hdr.rawrunnum;
00087     %    im_datetime(nimg) = im_hdr.im_datetime;
00088     %    im_actual_dt(nimg) = im_hdr.im_actual_dt;
00089     %    im_lastmod(nimg) = im_hdr.im_lastmod;
00090     %    im_checksum(nimg) = im_hdr.im_checksum;
00091     %    im_scanactno(nimg) = im_hdr.scanactno;
00092 
00093 
 

Powered by Plone

This site conforms to the following standards: