%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PURPOSE: Plot HS2 data.
% AUTHOR:  Rob McEwen
% DATE:    08/10/7
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%

%  if(exist('hydroscatlog.log') ~= 2) 
%    disp('hydroscatlog.log is not present.')
%    return;
%  end

  if(exist('printsetup') ~= 1) printsetup = 0;end
  if(exist('titleStr') == 0) titleStr = [];end
  str = [' ',titleStr,' Plotted on ',myDate];
  PaperPosn = [.5 .5 3.75 2.5];
  FigurePosn = [5 30 815 760];
  i = 0;
  if( exist('fontsize') == 0), fontsize = 20; end
  if( fontsize ==12 ), linewidth = .5;end
  fontweight = 'normal';
  if( exist('position') ~= 1 ) position = [3 59 1213 1070]; end

  if( exist('startTime') ~= 1 ) 
    hydroscatlog(:,1) = hydroscatlog(:,1) - hydroscatlog(1,1);
    if(  (exist('asp') == 1) & (length(asp.data) > 0) )
      asp.data(:,1) = asp.data(:,1) - asp.data(1,1);
    end
    startTime = 0;
  end

  if exist( 'hs2Fig' ) ~= 1
    hs2Fig = figure;
    figure(hs2Fig);
%   winpos( position(1,:) );
  else
    figure(hs2Fig);
  end
  set( hs2Fig, 'Name', 'HS2 Plot', 'DeleteFcn', 'clear hs2Fig' );
  set(gcf,'position',position)
if( printsetup )
  set(gcf, 'PaperPositionMode', 'manual');
  set(gcf, 'PaperUnits', 'inches');
  set(gcf, 'PaperOrientation', 'landscape');
  set(gcf, 'PaperPosition', [.25 .25 10.5 8]);
end
  lstr = {};
%
  subplot(2,1,1);
  set(gca,'fontsize',fontsize,'fontweigh',fontweight)
  han1=plot(hydroscatlog(:,1),hydroscatlog(:,fl676u),'.');
  lstr(length(lstr)+1,1) = { 'fl676u' };
  set(gca,'ylim',[0 .01]);
  grid on;
  hold on;
  if(exist('dataNav')==1) 
    han2=plot(dataNav(:,1),.003-dataNav(:,mDepth)/1e4,'r');
    lstr(length(lstr)+1,1) = { '.003-depth*1e-4' };
  end
% gulph = interp1(hydroscatlog(:,1), hydroscatlog(:,fl676u), gulper.data(:,1));
  plot(asp.data(:,1), asp.data(:,asp.fl676bkgnd),'mh','linewidth',3');
  plot(asp.data(:,1), asp.data(:,asp.peakbaseline),'gh','linewidth',3);
  xlabel('Seconds');
  ylabel('Units');
  title([ 'Chlorophyll Fluorescence', str ]);
  if( (exist('asp') == 1) & isfield(asp,'newdata' ) )
    han3=plot(asp.newdata(:,1)-startTime,asp.newdata(:,2),'kh','linewidth',3);
    lstr(length(lstr)+1,1) = { 'Gulp' };
  elseif( (exist('asp') == 1) & isfield(asp,'fl676' ) & (length(asp.data > 0)) )
    han3=plot(asp.data(:,1),asp.data(:,asp.fl676),'kh','linewidth',3);
    lstr(length(lstr)+1,1) = { 'Gulp' };
  end
  legend(lstr);

  spptr = subplot(2,1,2);
  set(gca,'fontsize',fontsize,'fontweigh',fontweight);
  indx = find(hydroscatlog(:,bb470)>1);
  if( ~isempty(indx) ) fprintf('Bad bb470 data; %d points.\n',length(indx));end
  hydroscatlog(indx,bb470) = ones(length(indx),1)*NaN;
  indx = find(hydroscatlog(:,bb676)>1);
  if( ~isempty(indx) ) fprintf('Bad bb676 data; %d points.\n',length(indx));end
  hydroscatlog(indx,bb676) = ones(length(indx),1)*NaN;
  han6=plot(hydroscatlog(:,1),hydroscatlog(:,[bb470 bb676]),'.');
  hold on
  if( (exist('asp') == 1) & isfield(asp,'bb470' ) )
    han7=plot(asp.data(:,1),asp.data(:,asp.bb470),'kh','linewidth',3);
    %lstr(length(lstr)+1,1) = { 'Gulp' };
  end
  xlabel('Seconds');
  ylabel('Units');
  title('Backscatter');
  grid on
  set(spptr,'ylim',[0 .08])

  linkaxes(get(gcf,'children'),'x')
  
  if( (exist('asp') == 1) & (exist('dataNav') == 1) )

  if exist( 'hs2Fig2' ) ~= 1
    hs2Fig2 = figure;
    figure(hs2Fig2);
%   winpos( position(1,:) );
  else
    figure(hs2Fig2);
  end
  set( hs2Fig2, 'Name', 'HS2 Plot', 'DeleteFcn', 'clear hs2Fig2' );
  set(gcf,'position',position)
if( printsetup )
  set(gcf, 'PaperPositionMode', 'manual');
  set(gcf, 'PaperUnits', 'inches');
  set(gcf, 'PaperOrientation', 'landscape');
  set(gcf, 'PaperPosition', [.25 .25 10.5 8]);
end
  set(gca,'fontsize',fontsize,'fontweigh',fontweight)
  han4=plot( dataNav(:,1), dataNav(:,mDepth) );
  hold on;
  grid on;
  if( (exist('asp') == 1) & isfield(asp,'newdata' ) )
    gulpd = interp1(dataNav(:,1),dataNav(:,mDepth), asp.newdata(:,1)-startTime);
    han5=plot(asp.newdata(:,1)-startTime,gulpd,'kh','linewidth',3);
  else
    gulpd = interp1(dataNav(:,1),dataNav(:,mDepth), asp.data(:,1));
    han5=plot(asp.data(:,1),gulpd,'kh','linewidth',3);
  end
  %gulpd(1) = NaN;
  set( gca, 'ydir', 'reverse' );
  set( gca,'ylim',[0 35]);
  xlabel('Seconds');
  ylabel('Meters');
  title('Depth')
  end

  
  return
%
% Still working on this!
%
  if exist( 'hs2Fig3' ) ~= 1
    hs2Fig3 = figure;
    figure(hs2Fig3);
%   winpos( position(1,:) );
  else
    figure(hs2Fig3);
  end
  set( hs2Fig3, 'Name', 'HS2 Plot', 'DeleteFcn', 'clear hs2Fig3' );
  set(gcf,'position',position)
  set(gca,'fontsize',fontsize,'fontweigh',fontweight)

  dxNav = [0; diff(posx)];
  dyNav = [0; diff(posy)];
  distnav = cumsum(sqrt(dxNav.^2 + dyNav.^2));	% in m

  posxHs2 = interp1(dataNav(:,1), posx, hydroscatlog(:,1));
  posyHs2 = interp1(dataNav(:,1), posy, hydroscatlog(:,1));
  poszHs2 = interp1(dataNav(:,1), dataNav(:,mDepth), ...
		    hydroscatlog(:,1));
  
  dxHs2 = [0; diff(posxHs2)];
  dyHs2 = [0; diff(posyHs2)];
  distHs2 = cumsum(sqrt(dxHs2.^2 + dyHs2.^2));	% in m

  

  fl676mesh = griddata(distHs2, poszHs2, hydroscatlog(:,fl676u),...
		       distHs2, poszHs2);
  
  contourf(distHs2, poszHs2, fl676mesh);
  hold on;
  grid on;
