%
% Relys on idt.northings, eastings and Psi.  These are computed and added to
% the idt struct in deltaT.m. 
% 
  lstr={};
  if exist( 'bergFigPtr' ) ~= 1
    bergFigPtr= figure;
    set( bergFigPtr, 'Name', 'Estimated Berg Location', 'DeleteFcn', 'clear bergFigPtr' );
    set(gcf,'position',position)
    bergFontsize=20;
    bergFontweight='normal';
    set(gca,'fontsize',bergFontsize,'fontweigh',bergFontweight)
    set(gcf,'defaultaxesfontsize',bergFontsize,'defaulttextfontsize', ...
	    bergFontsize)
    bergAxesPtr = gca;
  else
    figure(bergFigPtr);
  end
%
% Filter out all the time points from the WaypointWallLog that are not
% strictly increasing.  This happens each time a new WaypointWall starts. 
%
  bergIndx = find(diff(wpw.data(:,1)));

  bergPlotPtrVeh = plot3(wpw.data(:,wpw.eastings), wpw.data(:,wpw.northings),...
			 wpw.data(:,wpw.depth), 'b.');
  hold on
  grid on
  lstr(length(lstr)+1,1) = {'Vehicle'};

  beamAngle_B = (wpw.data(:,wpw.beamIndxMin) - 150)*pi/180;
  beamAngle_N = beamAngle_B + wpw.data(:,wpw.psi);
  
   bergPlotPtrW = ...
       plot3( sin( beamAngle_N ) .* wpw.data(:,wpw.minBeamRange)  +  ...
	      wpw.data(:,wpw.eastings),...
              cos( beamAngle_N ) .* wpw.data(:,wpw.minBeamRange)  +  ...
	      wpw.data(:,wpw.northings),...
	      wpw.data(:,wpw.depth), 'r.');
   set(gca,'zdir','reverse');
  lstr(length(lstr)+1,1) = {'Minimum Range'};

  beamAngle_B = (wpw.data(:,wpw.beamIndxLS) - 150)*pi/180;
  beamAngle_N = beamAngle_B + wpw.data(:,wpw.psi);

   bergPlotPtrWLS = ...
      plot3( sin( beamAngle_N ) .* wpw.data(:,wpw.rangeLS)  +  ...
	     wpw.data(:,wpw.eastings),...
             cos( beamAngle_N ) .* wpw.data(:,wpw.rangeLS)  +  ...
	     wpw.data(:,wpw.northings),...
             wpw.data(:,wpw.depth),'g.');
  lstr(length(lstr)+1,1) = {'Least Squares'};

  beamAngle_B = (wpw.data(:,wpw.beamIndxLSMedian) - 150)*pi/180;
  beamAngle_N = beamAngle_B + wpw.data(:,wpw.psi);

  bergEastings = sin( beamAngle_N ) .* ...
      wpw.data(:,wpw.rangeLSMedian) +  wpw.data(:,wpw.eastings);
  bergNorthings = cos( beamAngle_N ) .* ...
      wpw.data(:,wpw.rangeLSMedian) + wpw.data(:,wpw.northings);

   bergPlotPtrWLSM = ...
      plot3( bergEastings, bergNorthings, wpw.data(:,wpw.depth),'m.');
      lstr(length(lstr)+1,1) = {'Least Squares with Median Filter'};
  
  legend(lstr, 'location','best')

    set(gca,'xticklabel',cellstr(num2str(get(gca,'xtick')','%d')))
    set(gca,'yticklabel',cellstr(num2str(get(gca,'ytick')','%d')))
  % if( strcmp(idt.dataSource,'DynamicControlLog') & ~idt.computeValues ) 
  %   northingsWall = idt.northings + cos(idt.Psi)
  %   bergPlotPtr = plot(dataDC(:,1), dataDC(:,rangeToWall),'x');
  % else
  %   fprintf('wallPlot: Post-processing not implemented.\n');
  % end
  grid on
  xlabel('Eastings, meters');
  ylabel('Northings, meters');
  zlabel('Depth, meters')
  title(['Estimates of Berg Location ', titleStr]);

  lstr={};
  if exist( 'bergFigPtr2' ) ~= 1
    bergFigPtr2= figure;
    set( bergFigPtr2, 'Name', 'Estimated Berg Location With Interpolation', 'DeleteFcn', 'clear bergFigPtr2' );
    set(gcf,'position',position)
    bergFontsize=20;
    bergFontweight='normal';
    set(gca,'fontsize',bergFontsize,'fontweigh',bergFontweight)
    set(gcf,'defaultaxesfontsize',bergFontsize,'defaulttextfontsize', ...
	    bergFontsize)
    bergAxesPtr = gca;
  else
    figure(bergFigPtr2);
  end

  grdEastings  = [min(bergEastings):max(bergEastings)]';
  grdNorthings = [min(bergNorthings):max(bergNorthings)]';
  [grdE grdN] = meshgrid(grdEastings, grdNorthings);
  F = scatteredInterpolant(bergEastings, bergNorthings, ...
			   wpw.data(:,wpw.depth),...
			   'linear','none');
  grdZ = F(grdE, grdN);
  surf( grdE, grdN, grdZ);

  set(gca,'xticklabel',cellstr(num2str(get(gca,'xtick')','%d')))
  set(gca,'yticklabel',cellstr(num2str(get(gca,'ytick')','%d')))
  set(gca,'zdir','reverse');
  % if( strcmp(idt.dataSource,'DynamicControlLog') & ~idt.computeValues ) 
  %   northingsWall = idt.northings + cos(idt.Psi)
  %   bergPlotPtr = plot(dataDC(:,1), dataDC(:,rangeToWall),'x');
  % else
  %   fprintf('wallPlot: Post-processing not implemented.\n');
  % end
  grid on
  xlabel('Eastings, meters');
  ylabel('Northings, meters');
  zlabel('Depth, meters')
  title(['Estimates of Berg Location ', titleStr]);

  
