% A "m" file for Matlab. After making a "wave_dat" file from "grfft.f", you
% can plot waveforms using Matlab. A post script data is stored in the 
% "wave.ps" file.

clear
close

%fig=figure('Units','centimeters','Position',[0.0 0.0 21.0 29.5]...
%,'PaperUnits','centimeters','PaperPosition',[0.0 0.0 21.0 29.5]);

fig=figure('Units','centimeters','Position',[0.0 0.0 21.0 26.0]...
,'PaperUnits','centimeters','PaperPosition',[0.0 0.0 21.0 26.0]);

load wave1_dat;
size(wave1_dat)
load amp1_dat;
size(amp1_dat)
nt=size(wave1_dat,1);
nf=size(amp1_dat,1);

%x0=wave1_dat(1,2);
%y0=wave1_dat(1,3);
%z0=wave1_dat(1,4);
%for i=2:nt,
%t(i)=wave1_dat(i,1);
%x(i)=wave1_dat(i,2)-x0;
%y(i)=wave1_dat(i,3)-y0;
%z(i)=wave1_dat(i,4)-z0;
%end

for i=1:nt,
t(i)=wave1_dat(i,1);
x(i)=wave1_dat(i,2);
y(i)=wave1_dat(i,3);
z(i)=wave1_dat(i,4);
end
xmax=max(x);ymax=max(y);zmax=max(z);
xmin=min(x);ymin=min(y);zmin=min(z);

for i=1:nf,
f(i)=amp1_dat(i,1)/3.141592654/2;
xr(i)=amp1_dat(i,2);
xi(i)=amp1_dat(i,3);
xa(i)=sqrt(xr(i)*xr(i)+xi(i)*xi(i));
end


dt=t(2)-t(1);
dx(1)=0.0;
for i=2:nt,
dx(i)=dx(i-1)+(x(i)+x(i-1))*dt/2;
end
dmax=max(dx); 

subplot(3,1,1)
plot(t,dx)
%title(['NS (max=',num2str(dmax),', min=',0,')'])
title(['NS (max=',num2str(dmax),')'])
ylabel('Displacement (cm)')
xlabel('time (sec)')
%axis([0 dur -amax amax])

subplot(3,1,2)
plot(t,x)
title(['NS (max=',num2str(xmax),', min=',num2str(xmin),')'])
ylabel('Velocity (cm/s)')
%axis([0 dur -amax amax])

subplot(3,1,3)
plot(f,xa)
title(['Fourier Amplitudes (NS)'])
xlabel('frequency (Hz)')
%axis([0 dur -amax amax])

print wave.ps
