0001 function convert_format_v2(sinfo, inpath, outpath, scan_offset)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 nsub = length(sinfo);
0041
0042 if nargin < 2
0043 inpath = './';
0044 outpath = './';
0045 elseif nargin < 3
0046 outpath = './';
0047 end
0048
0049 if nargin < 4
0050 scan_offset = 0;
0051 end
0052
0053 if isempty(outpath)
0054 outpath = './';
0055 end
0056
0057 if isempty(inpath)
0058 inpath = './';
0059 end
0060
0061 for isub = 1:nsub
0062
0063 s = sinfo(isub);
0064 subj_root = s.id;
0065
0066
0067 subpath = fullfile(outpath, subj_root);
0068 check_dir(subpath);
0069
0070
0071 nsess = length(s.sessinfo);
0072
0073 for isess = 1:nsess
0074 sessinfo = s.sessinfo(isess);
0075
0076 if ~sessinfo.use_session
0077 continue
0078 end
0079
0080 sesspath = fullfile(subpath, sessinfo.id);
0081
0082
0083 series = sessinfo.series_mappings;
0084 nseries= size(series,1);
0085
0086 num_epi = 0;
0087 nexams = sessinfo.nexams;
0088
0089 for mapping_idx = 1:nseries
0090
0091 series_type = series{mapping_idx,2};
0092
0093
0094
0095 if nexams > 1
0096 exam_idx = series(mapping_idx,3);
0097 else
0098 exam_idx = 1;
0099 end
0100
0101 exam_root = sprintf('%05d', sessinfo.exam_ids(exam_idx));
0102 exampath = fullfile(sesspath, exam_root);
0103
0104 srcdir = fullfile(exampath, char(series(mapping_idx,1)));
0105
0106
0107 if ~exist(srcdir)
0108 fprintf('Could not locate input directory: %s (skipping ...)\n', srcdir);
0109 continue
0110 end
0111
0112 switch series_type
0113 case {'epi','epi1','epi2','epi3','epi4','epi_12','epi_34'}
0114 epidir = fullfile(sesspath, series_type);
0115 check_dir(epidir)
0116
0117
0118
0119
0120
0121 epi_runcol = 4;
0122 if size(series,2) == epi_runcol
0123 nruns = length(series{mapping_idx, epi_runcol});
0124 multi_epi_series = 1;
0125 else
0126 nruns = length(sessinfo.cond_order);
0127 multi_epi_series = 0;
0128 end
0129
0130 for irun = 1:nruns
0131 num_epi = num_epi+1;
0132
0133 outdir = fullfile(epidir, sprintf('run%d', num_epi));
0134
0135
0136 check_dir(outdir)
0137
0138 nvol = sessinfo.nvol(num_epi);
0139
0140 if multi_epi_series
0141
0142
0143 [dummy, vol_idx] = intersect(1:length(sessinfo.cond_order), ...
0144 series{mapping_idx,epi_runcol}(1:irun));
0145 run_offset = sum(sessinfo.nvol(vol_idx)) - sessinfo.nvol(vol_idx(irun));
0146 else
0147 run_offset = sum(sessinfo.nvol(1:num_epi))-sessinfo.nvol(num_epi);
0148 end
0149
0150 start_num = run_offset+2+scan_offset;
0151
0152
0153 outstub = fullfile(outdir, sprintf('%s_%s_r%d',sessinfo.id, char(series(mapping_idx,1)), num_epi));
0154 status = GE_convertADW(srcdir, outstub, start_num, nvol-scan_offset);
0155
0156 if status
0157 disp(sprintf('Error in converting run %d, series %s, exam %s', irun, char(series(mapping_idx,1)), exam_root))
0158
0159
0160
0161
0162
0163
0164 unix(['rmdir ' outdir]);
0165 num_epi = num_epi - 1;
0166 break
0167 end
0168 end
0169
0170 otherwise
0171 outdir = fullfile(sesspath, series_type);
0172 check_dir(outdir)
0173
0174 outstub = fullfile(outdir, [subj_root '_' char(series(mapping_idx,1))]);
0175 disp(sprintf('Source: %s; Destination: %s', srcdir, outdir))
0176
0177 switch series_type
0178 case {'hires_T2_PD'}
0179 GE_convertT2PD(srcdir,outstub);
0180 otherwise
0181 GE_convertVolume(srcdir,1,outstub);
0182 end
0183 end
0184 end
0185 end
0186 end