%clear; close all;

  
  co = [0 0 1;
        0 0.5 0;
        1 0 0;
        0 0.75 0.75;
        0.75 0 0.75;
        0.75 0.75 0;
        0.25 0.25 0.25];
  set(groot,'defaultAxesColorOrder',co)

  MonitorPositions = get(0,'MonitorPositions');
  nMon = size(MonitorPositions);
  nMon = nMon(1);
  %Select widest monitor
  position = MonitorPositions(1,:);
  if( nMon > 1 && MonitorPositions(2,3) > MonitorPositions(1,3) )  
    position =  MonitorPositions(2,:); 
  end
 
  %position = get(0,'screensize');
  npposition(1:2) = position(1:2) + round([position(3)*.02 position(4)*.04]);
  npposition(3:4) = round([position(3)*.95 position(4)*.90]);
  position = npposition;


%if( ~exist('scan') )  load radarData200516.mat, end
if( ~exist('scan') )  load radarData200554.mat, end

length(scan)

for m = 1:length(scan)
    
    pulses = scan(m).pulse;

    %if exist( 'scanFigPtr' ) ~= 1
    if(1)
      scanFigPtr= figure;
      set( scanFigPtr, 'Name', 'LR Scan', 'DeleteFcn', 'clear scanFigPtr' );
      set(gcf,'position',position)
      if(exist('fontsize')) 
	scanFontsize=fontsize;
      else
	scanFontsize=22;
      end
      scanFontweight='normal';
      set(gca,'fontsize',scanFontsize,'fontweigh',scanFontweight)
      set(gcf,'defaultaxesfontsize',scanFontsize,'defaulttextfontsize', ...
	  scanFontsize)
    else
      figure(scanFigPtr);
    end

    fprintf('Got here!\n');
    
    for n = 1:length(pulses)
        pulse = pulses(n);
        
        % angle comes either from azimuth or pointing angle, in radians
        azimuth = ones(1, length(pulse.radarVideo))* pulse.azimuth * pi/180;
        
        % range is self described, convert to array
        range = linspace(pulse.startRange, pulse.endRange, length(pulse.radarVideo));
        
        % convert to cartesian
        [x, y] = pol2cart(azimuth, range);

        % plot and map colors to values
        %scatter3(x,y,pulse.radarVideo,3,pulse.radarVideo);
        scatter(x,y,3,pulse.radarVideo);
        hold on;
    end
    fprintf('Got here %d!\n',n);
    title(['Scan ' num2str(m)]);
    axis equal;

    pause
    %break;
end
