robotorigin = map(:,1:2);
offsetrot = exp(i*map(:,3)*pi/180);
sonarreadings = map(:,4:end);						% raw
sonarsamples = sonar2mm(sonarreadings,coeff);	% adjusted by coeff
zorigin = robotorigin(:,1)+robotorigin(:,2)*i;
colindex2rad = ([0:15]*22.5+11.25)*pi/180;
colindex2rot = exp(i*colindex2rad);
[rows,cols] = size(sonarsamples);

zoriglong = [];
zpos = [];
zdirs = [];
sonars = [];
for r=1:rows,
   validsonars = find((sonarreadings(r,:)>200) & (sonarreadings(r,:)<16000));
   if (~isempty(validsonars)),
      vtheta = offsetrot(r) * colindex2rot(validsonars);
      zdirs = [zdirs vtheta];
      vpos = zorigin(r) + vtheta .* sonarsamples(r,validsonars);
      zpos = [zpos vpos];
      sonars = [sonars sonarsamples(r,validsonars)];
  	 	zoriglong = [zoriglong ones(1,length(validsonars))*zorigin(r)];   
   end
end

% sort by distance from origin so that a test point found using strip.m
% will be preceded by map data only closer to the origin
[ zoriglong, sindices ] = sort(zoriglong);
zpos = zpos(sindices);
zdirs = zdirs(sindices);
sonars = sonars(sindices);

% find the unique set of observation points which we could use as
% test sets.
zuniq = unique(zorigin);
