close all
figure(1)
hold on
grid on

current = .01:.01:.8 ;
theta = zeros(size(current));

Fp = 0.0;

V = 0.05;
a = .25;
L = 1.0;
mu = 0.1;
rho = 1025.0;
Cdt = .75;
Cds = 0.5;

Fw = 0.5*4.46; % .5lbs
theta_last = 45.0*pi/180.0;
for n = 1:length(current)
 theta(n) = angle(Fp,Fw,current(n),V,a,L,mu,rho,Cdt,Cds,theta_last);
 theta_last = theta(n);
end
p1 = plot(100*current,theta*180/pi,'-rx','MarkerSize',5);

Fw = 1.0*4.46; % .5lbs
theta_last = 45.0*pi/180.0;
for n = 1:length(current)
 theta(n) = angle(Fp,Fw,current(n),V,a,L,mu,rho,Cdt,Cds,theta_last);
 theta_last = theta(n);
end
p2 = plot(100*current,theta*180/pi,'-gx','MarkerSize',5);

Fw = 2.5*4.46; % .5lb
theta_last = 45.0*pi/180.0;
for n = 1:length(current)
 theta(n) = angle(Fp,Fw,current(n),V,a,L,mu,rho,Cdt,Cds,theta_last);
 theta_last = theta(n);
end
p3 = plot(100*current,theta*180/pi,'-bx','MarkerSize',5);

ylim([0 45]);


current = 0.075:.025:.8;
theta = zeros(size(current));

for n = 1 : length(current)
    
matfilenm = ['..\..\MOOS-Cable-Runs\CurrentProfiles\MOOS-Mooring-',num2str(current(n)),'.mat']; 

load(matfilenm)

p4 = plot(100*current(n),phi(240)*180/pi,'-ko','MarkerSize',2);
p5 = plot(100*current(n),phi(220)*180/pi,'-ko','MarkerSize',2);
p6 = plot(100*current(n),phi(200)*180/pi,'-ko','MarkerSize',2);
p7 = plot(100*current(n),phi(180)*180/pi,'-ko','MarkerSize',2);
theta(n) = phi(200);
end


text(80,5.5,'depth = 20 m','EdgeColor','black','BackgroundColor','white','FontSize',8,'HorizontalAlignment','left');
text(80,13.1,'depth = 200 m','EdgeColor','black','BackgroundColor','white','FontSize',8,'HorizontalAlignment','left');
text(80,21.1,'depth = 400 m','EdgeColor','black','BackgroundColor','white','FontSize',8,'HorizontalAlignment','left');
text(80,29,'depth = 600 m','EdgeColor','black','BackgroundColor','white','FontSize',8,'HorizontalAlignment','left');
xlabel('Current Speed (cm/s)');
ylabel('Cable Angle from Vertical (degrees)');

legend([p1,p2,p3,p4],'.5 lb Bouyancy','1 lb Bouyancy','2.5 lb Bouyancy','Slope of MOOS Test Mooring');

print -dpsc2 hold_angles
print -dpng hold_angles


figure(2)
grid on
hold on
%title('Energy Required for round trip profile (per 100 meters)');
xlabel('Current Speed (cm/s)');
ylabel('Energy per 100 meter round trip (W-Hr)');

energy = zeros(size(current));


V = 0.05;
for n = 1:length(current)
energy(n) = 2*Cdt*rho*pi*a*a*(realpow(current(n)*sin(theta(n)),2)+V*V)+2*mu*Cds*rho*a*L*realpow(current(n)*cos(theta(n)),2);
end
p1 = plot(100*current,100*energy/3600,'-rx','MarkerSize',5);

V = 0.10;
for n = 1:length(current)
energy(n) = 2*Cdt*rho*pi*a*a*(realpow(current(n)*sin(theta(n)),2)+V*V)+2*mu*Cds*rho*a*L*realpow(current(n)*cos(theta(n)),2);
end
p2 = plot(100*current,100*energy/3600,'-gx','MarkerSize',5);

V = 0.15;
for n = 1:length(current)
energy(n) = 2*Cdt*rho*pi*a*a*(realpow(current(n)*sin(theta(n)),2)+V*V)+2*mu*Cds*rho*a*L*realpow(current(n)*cos(theta(n)),2);
end 
p3 = plot(100*current,100*energy/3600,'-bx','MarkerSize',5);

V = 0.20;
for n = 1:length(current)
energy(n) = 2*Cdt*rho*pi*a*a*(realpow(current(n)*sin(theta(n)),2)+V*V)+2*mu*Cds*rho*a*L*realpow(current(n)*cos(theta(n)),2);
end 
p4 = plot(100*current,100*energy/3600,'-yx','MarkerSize',5);

V = 0.25;
for n = 1:length(current)
energy(n) = 2*Cdt*rho*pi*a*a*(realpow(current(n)*sin(theta(n)),2)+V*V)+2*mu*Cds*rho*a*L*realpow(current(n)*cos(theta(n)),2);
end 
p4 = plot(100*current,100*energy/3600,'-kx','MarkerSize',5);


ylim([0 1.6]);

legend('5 cm/s','10 cm/s','15 cm/s','20 cm/s','25 cm/s',2);

print -dpsc2 energy-200m
print -dpng energy-200m
