0001 function run_info = get_GE_timestamps(sinfo,dataroot,nslice_per_vol)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 nsub = length(sinfo);
0012
0013 if nargin < 2
0014 dataroot = './';
0015 end
0016
0017 if nargin < 3
0018 error(['Please specify the number of expected slices per volume and try' ...
0019 ' again.'])
0020 end
0021
0022 for isub = 1:nsub
0023 s = sinfo(isub);
0024 subj_root = s.id;
0025
0026 total_epi_series = 0;
0027 for iexam = 1:s.nexams
0028 exam_root = sprintf('%05d', s.exam_nums(iexam));
0029 datapath = fullfile(dataroot, subj_root, exam_root);
0030
0031 series=s.series_mappings{iexam};
0032 epi_idx = strmatch('epi', char(series{:,2}));
0033
0034 nser=length(epi_idx);
0035 if ~nser
0036 fprintf('Found no EPI series. Subject %s. Exam %d\n', s.id, iexam);
0037 else
0038 for iser = 1:nser
0039 total_epi_series = total_epi_series + 1;
0040
0041
0042 inDir = fullfile(datapath, series{epi_idx(iser),1});
0043 ser_idstr = inDir(end);
0044 ser_idnum = str2num(ser_idstr);
0045
0046
0047 GE_data_root = inDir(1:max(findstr('/',inDir))-1);
0048
0049
0050 if ~exist(GE_data_root)
0051 fprintf('Directory (%s) does not exist\n', GE_data_root);
0052 break
0053 end
0054
0055
0056 d = dir(GE_data_root);
0057
0058 dir_idx = find(cat(1,d.isdir));
0059 ndir = length(dir_idx);
0060
0061 dirmat = char(d.name);
0062
0063 good_idx = find((dirmat(:,3) == ser_idstr) & isspace(dirmat(:,4)));
0064
0065 ser_dirnames = char(d(good_idx).name);
0066
0067 ndir = size(ser_dirnames,1);
0068
0069 nimg = 0;
0070 im_user17 = [];
0071 for idir = 1:ndir
0072 curdir = fullfile(GE_data_root, ser_dirnames(idir,:));
0073 subd = dir(curdir);
0074
0075 dirmat = char(subd.name);
0076 good_idx = strmatch('I.', dirmat);
0077 nfiles = length(good_idx);
0078
0079 disp(sprintf('Found %d image files in directory %s', nfiles, curdir))
0080
0081 flist = char(subd(good_idx).name);
0082
0083
0084
0085 for ifile = 1:nfiles
0086 nimg = nimg+1;
0087 imageFile = fullfile(curdir, flist(ifile,:));
0088
0089 fid = fopen(imageFile,'r','b');
0090 fseek(fid,4936,'bof');
0091 im_user17(nimg) = fread(fid,1,'float32');
0092 fclose(fid);
0093 end
0094 end
0095 run_info.id_vect{isub,total_epi_series} = im_user17;
0096 run_ids = unique(im_user17);
0097 nrun = length(run_ids);
0098 for irun = 1:nrun
0099 run_info.nvol{isub,total_epi_series}(irun) = sum(im_user17 == ...
0100 run_ids(irun))/nslice_per_vol;
0101 end
0102 end
0103 end
0104 end
0105 end