function ep_lookOneDay2(infile, Date1)
% ep_lookOneDay2 - QC plot of derived products for an eqpac mooring
% 
% use as: ep_lookOneDay2(infile, Date1)
%
% Inputs: infile = a netcdf object of an eqpac data file
%         Date1 = the date of data to plot

% Brian Schlining
% 17 Aug 2000;

warning off
ep_ini;                             % Load the header of each column of data (ColumnS) and the units (UnitS)
modelColor = [.8 .75 0];
irradColor = [.98 .44 .12];
radColor2  = [.2 1 .2];
radColor1 =  [.212 .544 .1];
waterColor = [0 0 1];
PaperPosition = [.25 2.5 4.5 3.25];

if nargin < 2
   Date1 = now;
end

% Set the path to the data file depending on what type of machine this function is run from
id = infile.mooring(:);
switch lower(id)
case 'ep1'
   loc = '0 155W';
   FileName = 'ep1_specprr_full.nc';
   lon = -155;
   dat = ep1;
case 'ep2'
   loc = '2S 170W';
   FileName = 'ep2_specprr_full.nc';
   lon = -170;
   dat = ep2;
otherwise
   loc = [];
   return
end

sdn     = nctime(infile);
good    = near(sdn, Date1);
eLambda = [412 443 490 510 555 656];
lLambda = [412 443 490 510 555 670 683];
Es = [infile{'Ed412_0_1'}(good) ...   % Surface radiance
      infile{'Ed443_0_2'}(good) ...
      infile{'Ed490_0_3'}(good) ...
      infile{'Ed510_0_4'}(good) ...
      infile{'Ed555_0_5'}(good) ...
      infile{'Ed656_0_6'}(good)];
Es(find(Es == -999)) = NaN;
Ed = [infile{'Ed412_2_1'}(good) ...   % 20m irradiance
      infile{'Ed443_2_2'}(good) ...
      infile{'Ed490_2_3'}(good) ...
      infile{'Ed510_2_4'}(good) ...
      infile{'Ed555_2_5'}(good) ...
      infile{'Ed656_2_6'}(good)];
Ed(find(Ed == -999)) = NaN;
Lu1 = [infile{'Lu412_1_1'}(good) ...   % 20m radiance
      infile{'Lu443_1_2'}(good) ...
      infile{'Lu490_1_3'}(good) ...
      infile{'Lu510_1_4'}(good) ...
      infile{'Lu555_1_5'}(good) ...
      infile{'Lu670_1_6'}(good) ...
      infile{'Lu683_1_7'}(good)];
Lu1(find(Lu1 == -999)) = NaN;
Lu20 = [infile{'Lu412_3_1'}(good) ...   % 20m radiance
      infile{'Lu443_3_2'}(good) ...
      infile{'Lu490_3_3'}(good) ...
      infile{'Lu510_3_4'}(good) ...
      infile{'Lu555_3_5'}(good) ...
      infile{'Lu670_3_6'}(good) ...
      infile{'Lu683_3_7'}(good)];
Lu20(find(Lu20 == -999)) = NaN;

Position = get(0, 'ScreenSize');
Position = [Position(1:3) Position(4) - Position(4)*.1];

%==========================
% First Figure: Ed, Lu, Es
%==========================
figure
mA = subplot('position', [0.1300 0.11 .20 .65]);
plot(eLambda, Ed, 'Color', radColor1)
hold on
plot(eLambda, Ed, '.', 'Color', radColor1)
title('Downwelled Irradiance');
xlabel('Wavelength [nm]')
ylabel('E_d [\muW cm^-^2 nm^-^1]')
set(gca, 'YLim', [0.01 100], 'YScale', 'log', 'XLim', [300 700], 'YGrid', 'on')

% Es plot
subplot('position', [0.6922 0.11 .20 .65])
h = [NaN NaN NaN];
h(3) = plot(eLambda, Es, 'Color', irradColor);
hold on
plot(eLambda, Es, '.', 'Color', irradColor)
set(gca, 'YLim', [10 1000], 'YScale', 'log', 'XLim', [300 700], 'YGrid', 'on')
title('Surface Irradiance');
xlabel('Wavelength [nm]')
ylabel('E_s [\muW cm^-^2 nm^-^1]')

% Add Frouins Model
lambdaEf = [412 443 490 510 555 670];
Ef = frouin(sdn(good), dat.north_latitude, dat.west_longitude);
h(4) = plot(lambdaEf, Ef, 'Color', modelColor);
plot(lambdaEf, Ef, 'k.','Color', modelColor);
hold off

% Lu Plot
subplot('position', [0.4111 0.11 .20 .65])
h(1) = plot(lLambda, Lu20, 'Color', radColor1);
hold on
plot(lLambda, Lu20, '.', 'Color', radColor1)
h(2) = plot(lLambda, Lu1, 'Color', radColor2);
plot(lLambda, Lu1, '.', 'Color', radColor2)
set(gca, 'YLim', [0.001 10], 'YScale', 'log', 'XLim', [300 700], 'YGrid', 'on')
hold off
title('Upwelled Radiance');
xlabel('Wavelength [nm]')
ylabel('L_u [\muW cm^-^2 nm^-^1  sr^-^1]')
lh = legend(h, '20m', '1.5m', 'Surface', 'model' ,0);
Pos = get(lh, 'Position');
set(lh, 'Position', [0.6922 0.8 Pos(3) Pos(4)])

set(gcf, 'CurrentAxes', mA)
text(300, 925, ['Position: ' loc]);
text(300, 400, ['Date: ' datestr(nanmean(sdn(good)) + gmtoffset(dat.east_longitude)) ' [GMT]'])
setfontsize(7)

set(gcf,'PaperPosition',PaperPosition);

%===============================
% Second Figure: K, Kchl, Lw
%===============================
figure

% First plot: Ke, Kl, Kw, Km
mA = subplot('position', [0.1300 0.11 .20 .65]);

h = [NaN NaN NaN NaN];
% Ke - Downwelled
Ke = calc_k(Es, Ed, 20);
h(1) = plot(eLambda, Ke, 'Color', irradColor);
hold on
plot(eLambda, Ke, '.', 'Color', irradColor)

% Kl - Upwelled
Kl = calc_k(Lu1, Lu20, 18.5);
h(2) = plot(lLambda, Kl, 'Color', radColor1);
plot(lLambda, Kl, '.', 'Color', radColor1)

% Km - Modeled based on morel uisng [CHL] from morel K490
Chl = morel_chl2(Ke(3), 490);
Km = morel_k(Chl, eLambda);
h(3) = plot(eLambda, Km, 'Color', modelColor);
plot(eLambda, Km, '.', 'Color', modelColor)

% Kw - Pure water based on Morel
Kw = morel_k(0, lLambda);
h(4) = plot(lLambda, Kw, 'Color', waterColor);
plot(lLambda, Kw, '.', 'Color', waterColor)

title('Attenuation');
xlabel('Wavelength [nm]')
ylabel('K [m^-^1]')
set(gca, 'YLim', [-.2 1], 'XLim', [300 700],'YGrid', 'on')
lh = legend(h, 'From E_s and E_d','From L_u[1m] and L_u[20m]', 'Modeled', 'Pure Water');
Pos = get(lh, 'Position');
set(lh, 'Position', [ 0.6922 .80 Pos(3) Pos(4)])


% Second Plot Kw-K
subplot('position', [0.4111 0.11 .20 .65])
% Es
Kw1 = morel_k(0, eLambda);
Ce = Ke - Kw1;
plot(eLambda, Ce, 'Color', irradColor);
hold on
plot(eLambda, Ce, '.', 'Color', irradColor)
%Lu
Kw = morel_k(0, lLambda);
Cl = Kl - Kw;
plot(lLambda, Cl, 'Color', radColor1);
plot(lLambda, Cl, '.', 'Color', radColor1)
% Modeled
Cm = Km - Kw1;
plot(eLambda, Cm, 'Color', modelColor);
plot(eLambda, Cm, 'Color', modelColor)
set(gca, 'YLim', [-.2 .2], 'XLim', [300 700], 'YGrid', 'on')
title('K - K_{pure water} ')
xlabel('Wavelength [nm]')
ylabel('K [m^-^1]')

% Third plot: Lw
subplot('position', [0.6922 0.11 .20 .65])
lambda = [412 443 490 510 555];
Lwe = calc_lw(Lu20(1:5), Ke(1:5), 20);
Lwl = calc_lw(Lu20(1:5), Kl(1:5), 20);
Lwm = calc_lw(Lu20(1:5), Km(1:5), 20);

plot(lambda, Lwe, 'Color', irradColor)
hold on
plot(lambda, Lwe, '.','Color', irradColor)
plot(lambda, Lwl, 'Color', radColor1)
plot(lambda, Lwl, '.', 'Color', radColor1)
plot(lambda, Lwm, 'Color', modelColor)
plot(lambda, Lwm, '.', 'Color', modelColor)
set(gca, 'YLim', [0.1 10], 'YScale', 'log', 'XLim', [300 700], 'YGrid', 'on')
title('Water Leaving Radiance')
xlabel('Wavelength [nm]')
ylabel('L_w [\muW cm^-^2 nm^-^1 sr^-^1]')

set(gcf, 'CurrentAxes', mA)
text(300, 1.3, ['Position: ' loc]);
text(300, 1.2, ['Date: ' datestr(nanmean(sdn(good)) + gmtoffset(dat.east_longitude)) ' [GMT]'])
set(gcf,'PaperPosition',PaperPosition);
setfontsize(7)

