%
%
%Reads wamit output files frc.1(added and damping coefficients for surge,
%heave and pitch(dof 1, 3, 5) and frc.3(exciting forces from diffraction
%potential(direct integration of hydrodynamic forces))
%
%
clear all
close all

filenm = 'ESP_drifter';

filenm1 = '_IR.1';filenm1 = strcat(filenm,filenm1);

s1 = load(filenm1);

N = length(s1(:,1));

tim = zeros(N/10,1);
sint= zeros(N/10,10);

for i = 1:10:N-9;
    
    k = i-1;
    k=k/10 +1;
    tim(k,1) = s1(i,1);
    sint(k,1) = s1(i,5);
end
for i = 2:10:N-8;
    
    k = i-2;
    k=k/10 +1;

    sint(k,2) = s1(i,5);
end
for i = 3:10:N-7;

    k = i-3;
    k=k/10 +1;

    sint(k,3) = s1(i,5);
end
for i = 4:10:N-6;

    k = i-4;
    k=k/10 +1;

    sint(k,4) = s1(i,5);
end
for i = 5:10:N-5;

    k = i-5;
    k=k/10 +1;

    sint(k,5) = s1(i,5);
end
for i = 6:10:N-4;

    k = i-6;
    k=k/10 +1;

    sint(k,6) = s1(i,5);
end
for i = 7:10:N-3;

    k = i-7;
    k=k/10 +1;

    sint(k,7) = s1(i,5);
end
for i = 8:10:N-2;

    k = i-8;
    k=k/10 +1;

    sint(k,8) = s1(i,5);
end
for i = 9:10:N-1;

    k = i-9;
    k=k/10 +1;

    sint(k,9) = s1(i,5);
end
for i = 10:10:N;

    k = i-10;
    k=k/10 +1;

    sint(k,10) = s1(i,5);
end

figure('Position', [100 100 1000 800])
set(gcf,'color','white');

for i=1:10;
sint(:,i) = 1025*sint(:,i);
end



plot(tim,sint(:,1),tim,sint(:,5),tim,sint(:,9));

ylabel('Non-Dim Radiation IRF Lij-sine transf')
legend('surge(m)','heave(m)','pitch(rad)');


grid on

filenm3 = '_JR.3';filenm3 = strcat(filenm,filenm3);

kij = load(filenm3);

rhog = 1025*9.80665;

kij(:,2)= rhog*kij(:,2);
kij(:,4)= rhog*kij(:,4);
kij(:,6)= rhog*kij(:,6);


ts= kij(:,1);
xlabel('time (s)')

figure('Position', [100 100 1000 800])
set(gcf,'color','white');

plot(ts,kij(:,2),ts,kij(:,4),ts,kij(:,6));
ylabel('Diffraction IRF (Kij)')
legend('surge(m)','heave(m)','pitch(rad)');


xlabel('Non-Dim time (s)')












