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

clear
close

load wave1_d;
size(wave1_d)
nob=wave1_d(1,1)
nt=wave1_d(1,2)
dt=wave1_d(1,3)

for j=1:nt,
  time_dat(j)=dt*(j-1);
end
f=max(time_dat);

amaxx=0.0;
amaxy=0.0;
amaxz=0.0;
for i=1:nob,
  for j=1:nt,
    axx=abs(wave1_d(nt*(i-1)+1+j,1));
    if axx > amaxx amaxx=axx; end
    ayy=abs(wave1_d(nt*(i-1)+1+j,2));
    if ayy > amaxy amaxy=ayy; end
    azz=abs(wave1_d(nt*(i-1)+1+j,2));
    if azz > amaxz amaxz=azz; end
  end
end
amaxx=amaxx*3.5
amaxy=amaxy*3.5
amaxz=amaxz*1
ax=amaxx/2
bx=amaxx/2
ay=amaxy/2
by=amaxy/2
az=amaxz/2
bz=amaxz/2

subplot(1,3,1)
hold on
for i=1:nob,
  for j=1:nt,
    x(j)=wave1_d(nt*(i-1)+1+j,1)+ax+amaxx*(i-1)/2;
  end
  plot(time_dat,x)
end
hold off
title('NS')
set(gca, 'box','on')
axis([0 f 0 ax+bx+amaxx*(nob-1)/2])
ylabel('velocity')
xlabel('time (sec)')

subplot(1,3,2)
hold on
for i=1:nob,
  for j=1:nt,
    y(j)=wave1_d(nt*(i-1)+1+j,2)+ay+amaxy*(i-1)/2;
  end
  plot(time_dat,y)
end
hold off
title('EW')
set(gca, 'box','on')
axis([0 f 0 ay+by+amaxy*(nob-1)/2])
xlabel('time (sec)')

subplot(1,3,3)
hold on
for i=1:nob,
  for j=1:nt,
    z(j)=wave1_d(nt*(i-1)+1+j,3)+az+amaxz*(i-1)/2;
  end
  plot(time_dat,z)
end
hold off
title('UD')
set(gca, 'box','on')
axis([0 f 0 az+bz+amaxz*(nob-1)/2])
xlabel('time (sec)')

print grfltwv1.ps


