%%%%%%%%%%%%%%%%
% accumulate.m %
%%%%%%%%%%%%%%%%

loadf;
more off;
batchk = 1000;
filename = ['/tmp/' fname '.acc'];
fp = fopen(filename, 'a');
fprintf (1, 'Accumulate k samples to file ''%s''...\n', filename);
fmt = repmat('%e ', 1, 1+npa);
fmt(size(fmt,2)) = '\'; 
fmt(size(fmt,2)+1) = 'n';
A = zeros(npa,3*npa);
for n = 1 : npa,
  A(n, 3*n-2:3*n) = [1 1 1];
end;
kbatch = 0;
while(1)
  for m = 1 : batchk,
    k = rand(1,3)-0.5;
    [w2,V] = dk(k);
    if (sum(w2 < 0) > 0)
      fprintf(1, '** (%f %f %f)\n', k);
      fprintf(1, '# [%f %f %f]\n', k * [-2 2 2; 2 -2 2; 2 2 -2]);
      break;
    end;
    fprintf(fp, fmt, [w2'; A*(V.*conj(V))]);
  end;
  kbatch = kbatch + 1;
  fprintf(1, 'Batch %d x %d k\n', kbatch, batchk);
end;
