%close all
%clear all


mag = (u{1}.^2+v{1}.^2).^.5;
ang = atan2(u{1},v{1});
z = dpth{1};

mean_mag = nanmean(mag,2);

max_mag = nanmax(mag,[],2);

std_mag = nanstd(mag,0,2);

energy = trapz(z,mag);

energy_of_mean = trapz(z,mean_mag);
energy_of_max_observed = trapz(z,max_mag);
energy_of_stat_max = trapz(z,mean_mag+4*std_mag);

profile_z = [0 -5 -10 -20 -40 -60 -80 -102];
mean_profile = [17 17 17 15.5 12.5 10 9 9];
max_obs_profile = [92 92 92 75 65 65 65 65];

figure('Position',[1000 125 1049 1373])

subplot(4,1,[1 3])
plot(mean_mag,-z,'k','LineWidth',2.5);
hold all
plot(max_mag,-z,'r','LineWidth',2.5);
plot(std_mag,-z,'b','LineWidth',2.5);
plot(mean_mag+4*std_mag,-z,'g','LineWidth',2.5);
legend('Mean Magnitude','Maximum Observed Magnitude','Std Deviation of Magnitude','Mean+4*StdDev');
plot(mag,-z);
plot(mean_mag,-z,'k','LineWidth',2.5);
plot(max_mag,-z,'r','LineWidth',2.5);
plot(std_mag,-z,'b','LineWidth',2.5);
plot(mean_mag+4*std_mag,-z,'g','LineWidth',2.5);

%plot(mean_profile,profile_z,'-kx');
%plot(max_obs_profile,profile_z,'-kx');
title([num2str(length(tim{1})) ' Current Magnitude Observations: ' datestr(tim{1}(1)) ' - '  datestr(tim{1}(end))]);
xlabel('Current Magnitude (cm/s)');
ylabel('Depth (m)');

subplot(4,1,4)
plot([energy_of_mean energy_of_mean],[20000 20000],'LineWidth',2.5,'Color','k');
hold all
hist(energy,[0:100:5000])
xlim([0 5000]);
xlabel('Energy (m^2/s)');
foo = axis;
line([energy_of_mean energy_of_mean],[foo(3) foo(4)],'LineWidth',2.5,'Color','k');
legend('Energy of Mean Profile');

print('-dpdf','CurrentProfiles.pdf');
print('-dpng','CurrentProfiles.png');
