0001 function corrected_bvec_file = ecc_bvecs(ecclog,bvecsfile)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 bvecs = load(bvecsfile);
0013 if(size(bvecs,2)==3 && size(bvecs,1)>3)
0014 bvecs = bvecs';
0015 end
0016 ecclog_tmp_file = tempname;
0017
0018
0019 [stat,ret] = unix(['cat ' ecclog ' | grep Final -A 4 | sed s/"Final result:"//g | sed s/--//g > ' ecclog_tmp_file]);
0020 if stat ~= 0
0021 error(['error occured', ret]);
0022 end
0023 mat = load(ecclog_tmp_file);
0024
0025
0026 rotbvecs = zeros(size(bvecs));
0027 for i = 1:size(bvecs,2)
0028 M = mat((i-1)*4+1:i*4,:);
0029 M = M(1:3,1:3);
0030
0031
0032 [u,s,v] = svd(M*M');
0033 R = inv(u*sqrt(s)*v')*M;
0034
0035 rotbvecs(:,i) = R*bvecs(:,i);
0036 end
0037
0038
0039 corrected_bvec_file = tempname;
0040 saveascii(rotbvecs,corrected_bvec_file,14);
0041
0042