function  [h_prof,h_point,plotmeanx,plotmeany] = drawcrosspeakranges(crosspeakranges,indices,allprofiles,allprofiles_offset,bombres,h_prof,h_point,plotmeanx,plotmeany);

hold on
for i = indices
  rangepoints = crosspeakranges(i,3): crosspeakranges(i,4);
  bestbombindex = find(bombres == crosspeakranges(i,1));
  xmax = crosspeakranges(i,5);
  if crosspeakranges(i,6) == 1
    colorprof = 'r';
  else
    colorprof = [0.5 0.5 1.0];
  end

  goodpixels = [];
  if ~isempty(bestbombindex )
    goodpixels = find( allprofiles(rangepoints,bestbombindex)>0);
  end
  
  if ~isempty(goodpixels)
    h_prof(i) = ...
	  plot(rangepoints(goodpixels), allprofiles_offset(rangepoints(goodpixels), bestbombindex),'color',colorprof,'linewidth',2);
      h_point(i) = ...
	  plot(xmax, ...
	     0.1+allprofiles_offset(xmax, ...
				    bestbombindex),'o','color',colorprof);
      plotmeanx(i) = mean(rangepoints(goodpixels));
      plotmeany(i) = mean(allprofiles_offset(rangepoints(goodpixels),bestbombindex)); 
  else
    h_prof(i) = plot(0,0);
    h_point(i) = plot(0,0);
    plotmeanx(i) = 0;
    plotmeany(i) = 0;
  end
end
hold off
