% Jan 2008
% This matlab code reads in the true anchor/sensor Cartesian coordinates from  
% the binary file  Prob1.mat  
% It then perturbs the sensor positions and writes the perturbed sensor coordinates
% to the ascii file  sensorprob.dat  
% The latter is needed to run the Fortran code  sensor_esdp.f

  clear

% read in  n  m dim  x nd d head tail
  load Prob
  fprintf(' %g pts,  %g anchors \n',n,m);
  pert = input(' enter deviation of init soln from true soln (.2) ');

% Initial estimate of sensor locations.
  sol(:,n-m+1:n) = x(:,n-m+1:n);
  sol(:,1:n-m) = x(:,1:n-m) + 2*(rand(dim,n-m)-0.5*ones(dim,n-m))*pert;

  fid = fopen('sensorprob.dat','w');
  fprintf(fid,'%8.0f%8.0f%8.0f%8.0f\n',n,m,dim,nd);
  for k = 1:nd
    fprintf(fid,'%8.0f%8.0f%12.8f\n',head(k),tail(k),d(k));
  end
  for i = 1:n
    fprintf(fid,'%12.8f%12.8f\n',sol(1,i),sol(2,i));
  end
  fclose(fid);
  fprintf(' finish writing to sensorprob.dat \n');
%  save 'sensorprob.dat' n m dim nd head tail d sol -ASCII


