%function [] = cms_map(positions, data, style, export, exportname);
%
% takes data from a position_list.dat file as first argument,
% and quality output matrix from polbasecall as second argument,
% and displays a map of the sum quality for all cycles, frame by frame
%
% function should be called with style==1 and export==0, which will
% display a solid surface and not export the image to a file
%
% Written by Greg Porreca (Church Lab), 01-19-2006
%
function [] = signal_vs_position(positions, data, export, exportname);

figure;

style=1;

for(i=1:max(positions(:,1))+1)
    qsum(i) = sum(sum(data(find(data(:,1)==i),8:end)')');
end
qsum = qsum';


xlin = linspace(min(positions(:,1)), max(positions(:,1)));
ylin = linspace(min(positions(:,2)), max(positions(:,2)));

[X, Y] = meshgrid(xlin, ylin);

z = griddata(double(positions(:,1)), double(positions(:,2)), double(qsum), X, Y, 'cubic');

if(style==0)
  mesh(X, Y, z);  
else
  surf(X,Y,z,'FaceColor','interp','EdgeColor','none','FaceLighting','phong');
  axis tight;
  camlight left;
end

if(export==1)
  X = getframe(gcf);
  if isempty(X.colormap)
    imwrite(X.cdata, [exportname '.tif']);
  else
    imwrite(X.cdata, X.colormap, [exportname '.tif']);
  end
  close
end

  
  
