% generate data

tol = 1e-8;
maxiter = inf;
freq = inf;
repeat = 50;

randn('seed',100);
rand('seed',100);

fprintf('version 9\n')
fid = fopen('DRDR_raw.txt','w');

for m = 100:100:500
  for n = 4000:1000:6000
  
    k = ceil(m/5);
  
    fDRmax = 0; fDRmin = inf;
    fDRrawmax = 0; fDRrawmin = inf;
    timeDR = 0; timeDRraw = 0;
    iterDR = 0; iterDRraw = 0;
    successDR = 0; successDRraw = 0;
    failDR = 0; failDRraw = 0;
  
    for ii = 1:repeat
    
      A = randn(m,n);
      x0 = randn(k,1);
      x1 = zeros(n,1);
      I = randperm(n); x1(I(1:k)) = x0;
      b = A*x1;
    
      fprintf(' Start DR\n')
      tDR = tic;
      [fval,z,x,y,iter] = DR_proj(A,b,k,tol,maxiter,freq);
      timeDR = timeDR + toc(tDR);
      iterDR = iterDR + iter;
      fDRmax = max(fDRmax,fval);
      fDRmin = min(fDRmin,fval);
      if fval < 1e-12
        successDR = successDR + 1;
      end
      if fval > 1e-6
        failDR = failDR + 1;
      end
    
      fprintf(' Start DRraw\n')
      tDRraw = tic;
      [fval2,z2,x2,y2,iter2] = DR_proj_raw(A,b,k,tol,19999,freq);
      timeDRraw = timeDRraw + toc(tDRraw);
      iterDRraw = iterDRraw + iter2;
      fDRrawmax = max(fDRrawmax,fval2);
      fDRrawmin = min(fDRrawmin,fval2);
      if fval2 < 1e-12
        successDRraw = successDRraw + 1;
      end
      if fval2 > 1e-6
        failDRraw = failDRraw + 1;
      end
    
    end
  
    fprintf(fid,' %5d & %5d & %8.2f & %6.0f & %1.0e & %1.0e & %2.0f & %2.0f & %8.2f & %6.0f & %1.0e & %1.0e & %2.0f & %2.0f\n',...
      m, n, timeDR/repeat, iterDR/repeat, fDRmax, fDRmin, successDR, failDR, timeDRraw/repeat, iterDRraw/repeat, fDRrawmax, fDRrawmin, successDRraw, failDRraw);
  end

end

fclose(fid);