function [bvals, bvecs] = cbu_diffusion_params(input_files)
% Find bvals and bvecs from DICOM directory

if nargin < 1
  input_files = spm_select(Inf, '^.*\.dcm$', 'Select DICOM files');
end

hdr = spm_dicom_headers(input_files);
n = length(hdr);
bvals = zeros(n, 1);
bvecs = zeros(n, 3);

for i = 1:n
  H = hdr{i};
  bvals(i) = str2num(H.CSAImageHeaderInfo(7).item(1).val);
  if bvals(i) == 0 % no gradient
    continue
  end
  d_info = H.CSAImageHeaderInfo(22).item;
  for D = 1:3
    bvecs(i,D)= str2num(d_info(D).val);
  end
end
