function HRplot(HR,plottype)
% HRplot - Plots calibrated HR data passed from oasisHR2plot
% 
% Usage:  HRplot(HR,plottype)
%     HR          - data conforming to format specified below
%     plottype    - 2D or 3D plotting flag ( 0 for 2D, 1 for 3D)
% 
% Variable HR data format. Created by oasisHR2plot
%   HR(i).tStamp
%   HR(i).lambda
%   HR(i).RawTime
%   HR(i).Temp
%   HR(i).Voltage
%   HR(i).Depth
%   HR(i).Process
%   HR(i).N
%   HR(i).Scale
%   HR(i).Do
%   HR(i).Dt
%   HR(i).IntTime
%   HR(i).FirstPix
%   HR(i).PixInc
%   HR(i).PixCount
%   HR(i).pixels
   
% Daniel Cosgrove
% 16 Apr 2002 

%-----------------------------------------------------------------------------
%Plots HR data as a scrolling 2D spectra
%-----------------------------------------------------------------------------
[r c] = size(HR);

if plottype == 0
    fprintf('Plotting 2D...');
    for k = 1:c-1
        set(0,'DefaultFigurePosition',[100,100,800,500]);
        plot(HR(k).lambda(:), HR(k).eu(:),'y');
        xlabel('Wavelentgh');
        ylabel('W/m^2/nm');
        starttime = datestr(jul2date(HR(k).tStamp(1),2002) - gmtoffset(121.8),14);
        title([datestr(jul2date(HR(k).tStamp(1),2002),1) ' ' starttime ' (Local)']); 
        legend(datestr(jul2date(HR(k).tStamp(1),2002) - gmtoffset(121.8),14));
        pause;
    end
    fprintf('done\n\n');
end

%-----------------------------------------------------------------------------
%Plots HR data as a 3D surface contour
%-----------------------------------------------------------------------------
if plottype == 1
    fprintf('Plotting surface contour...');
    cmap = colormap(jet(330));
    k = 1;
    while(k < c)
        Y(k,1:length(HR(k).lambda)) = HR(k).lambda;
        j = 1;
        while(j <= length(HR(k).lambda))
            X(k,j) = jul2date(HR(k).tStamp(1),2002) - gmtoffset(121.8);
            for m = 1:3
                C(k,j,m) = cmap(j,m);
            end
            j = j + 1;
        end
        Z(k,1:length(HR(k).eu)) = HR(k).eu;
        k = k + 1;
    end
    
    X(find(X == 0)) = NaN;
    Y(find(Y == 0)) = NaN;
    Z(find(Z == 0)) = NaN;
    
    HRsurf = surf(X,Y,Z,'FaceColor','interp','FaceLighting','phong');
    cmin = min(Z(:));
    cmax = max(Z(:));
    camlight right
    set(HRsurf,'LineStyle','none');
    datetick('x');
%     title(['HR' num2str(ChNum) ' EP' num2str(mooring) ': ' datestr(jul2date(HR(1).tStamp(1),2002),1)]); 
    xlabel('Time (local)');
    ylabel('Wavelentgh');
    zlabel('W/m^2/nm');
    alpha(0.90);
    set(HRsurf,'CData',C);
    view(-68.50,44);
    fprintf('done\n\n');
    
    x = X(:,1);
   
    Yy(1,:) = find(Y(1,:) > 411.5 & Y(1,:) < 413);
    Yy(2,:) = find(Y(1,:) > 442.5 & Y(1,:) < 443.9);
    Yy(3,:) = find(Y(1,:) > 489.5 & Y(1,:) < 491);
    Yy(4,:) = find(Y(1,:) > 509.5 & Y(1,:) < 511);
    Yy(5,:) = find(Y(1,:) > 554.5 & Y(1,:) < 556);
    
    y(:,1) = Y(:,Yy(1,1)); 
    z(:,1) = Z(:,Yy(1,1));
    y(:,2) = Y(:,Yy(2,1)); 
    z(:,2) = Z(:,Yy(2,1));
    y(:,3) = Y(:,Yy(3,1)); 
    z(:,3) = Z(:,Yy(3,1));
    y(:,4) = Y(:,Yy(4,1)); 
    z(:,4) = Z(:,Yy(4,1));
    y(:,5) = Y(:,Yy(5,1)); 
    z(:,5) = Z(:,Yy(5,1));
        
    hold on
    line(x(:,1),y(:,1),z(:,1),'LineWidth',2);
    line(x(:,1),y(:,2),z(:,2),'LineWidth',2);
    line(x(:,1),y(:,3),z(:,3),'LineWidth',2);
    line(x(:,1),y(:,4),z(:,4),'LineWidth',2);
    line(x(:,1),y(:,5),z(:,5),'LineWidth',2);
    hold off
       
end