pswaves.m


"pswaves.m" is a Matlab "m" file that generates P and S wavefronts in a homogeneous wholespace.  The user can then pick points on each wavefront and examine the relative horizontal and vertical displacements for an assumed wave time history.

This program demonstrates how to set up a push button menu, how to define time series, and pick points from an existing graph with the mouse.



 
 
pswaves.m
More comments
function pswaves(action)
%function pswaves
% pswaves - compute P and S wavefronts, examine particle motions
%   
% Input:
%   vp - P wave velocity
%   vs - S wave velocity
%   boxsize - size of box containing source (km)
%                                 source is at the center
%   time - travel time of the wave(s)

% C.A. Langston 9/19/99
%       modified 3/20/01 to represent a vertical (+y) point force
%
global ui_v1t ui_v2t ui_b1t ui_t1t
global f1 f2 f3
global lenp lens

if nargin < 1; action = 'initialize'; end;

if strcmp(action,'initialize')

%----------Create Initialization input window -------------------

f1=figure('position',[10 170 280 230],'name','Parameter Input');
clf;

ui_v1=uicontrol('style','pushbutton','position', ...
 [10 40 80 20],'string','vp');
ui_v1t=uicontrol('style','edit','position', ...
 [110 40 100 20]);
ui_vun1=uicontrol('style','pushbutton','position', ...
 [230 40 50 20],'string','km/s');

ui_v2=uicontrol('style','pushbutton','position', ...
 [10 70 80 20],'string','vs');
ui_v2t=uicontrol('style','edit','position', ...
 [110 70 100 20]);
ui_vun2=uicontrol('style','pushbutton','position', ...
 [230 70 50 20],'string','km/s');

ui_b1=uicontrol('style','pushbutton','position', ...
 [10 100 80 20],'string','boxsize');
ui_b1t=uicontrol('style','edit','position', ...
 [110 100 100 20]);
ui_vun1=uicontrol('style','pushbutton','position', ...
 [230 100 50 20],'string','km');

ui_t1=uicontrol('style','pushbutton','position', ...
 [10 130 80 20],'string','travel time');
ui_t1t=uicontrol('style','edit','position', ...
 [110 130 100 20]);
ui_tun1=uicontrol('style','pushbutton','position', ...
 [230 130 50 20],'string','sec');

ui_calc=uicontrol('style','pushbutton','position', ...
 [55 0 150 30],'callback','pswaves(''wavepict'')', ...
 'string','Compute Wavefront Diagram');

elseif strcmp(action,'wavepict')

f2=figure('name','Wavefront Diagram');
clf; 
d=str2num(get(ui_b1t,'string'));
axes('DataAspectRatio',[1 1 1]);
axis([-d/2 d/2 -d/2 d/2]);
line([0],[0],'linestyle','*');
xlabel('Horizontal Distance, km');
ylabel('Depth, km');
np=180;
theta=linspace(0,2*pi,np);
%
tt=abs(str2num(get(ui_t1t,'string')));
vp=str2num(get(ui_v1t,'string'));
vs=str2num(get(ui_v2t,'string'));
lenp=tt*vp;
lens=tt*vs;
xp=lenp*cos(theta);
zp=lenp*sin(theta);
xs=lens*cos(theta);
zs=lens*sin(theta);
% plot wavefronts
line(xp,zp,'Color','r');
line(xs,zs,'Color','y');
%
%  Set up a wave pick
%
ui_pick=uicontrol('style','pushbutton','position', ...
 [10 0 150 30],'callback','pswaves(''wavepick'')', ...
 'string','Pick on a Wavefront');

elseif strcmp(action,'wavepick')

%
%  Pick a point on the wavefront and construct particle motion plots
%
figure(f2);
[x,y]=ginput(1)

f3=figure('name','Particle Motions for Wave Pick');

t=linspace(0,3,50);
f=t.*exp(-3.0.*t);
rlen=sqrt(x*x + y*y);
if rlen > 0.90*lenp;
%   P waves
 fx=(x*y/rlen^3)*f;
 fy=(y*y/rlen^3)*f;
else;
%  s waves
 fx=-(x*y/rlen^3)*f;
 fy=(x*x/rlen^3)*f;
end;

plot(t,fy,'b',t,fx,'r');
xlabel('time, sec');
ylabel('Vertical Displacement (Blue), Horizontal (Red), microns');

end;
 

Define the function.  "action" is a text string which controls what part of
  of the program is used at a time.
This part can be seen using "help" pswaves while in the Matlab command
  window.
 
 
 
 
 
 
 
 
 

equivalent to a fortran common block, needed to save variables values
  after invoking other functions
 
 
 
 
 
 
 

Make the first interactive menu
 

define pushbuttons
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

"callback" sends everything back to the beginning to do something else.
In this case, we will now compute the wavefront diagram.
 
 

Construct the wavefront diagram
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Define circular wavefronts and plot them.
 
 
 
 
 
 
 
 
 
 

"callback" to setup picking points on each wavefront.
 
 
 
 
 
 

"ginput(1)" takes one point from the plot after a mouse button is pushed.
 
 

Make a simple time function to represent the wavefront.
 
 
 
 
 
 
 
 
 
 
 

Plot the displacements in another figure.
 
 
 
 
 



Here are examples of the plots that were made with this routine.

Here is the input pushbutton interface with parameters that have been input:
 

Here is the wavefront diagram with the process of interactively picking a point on the P wavefront:

Here are resulting P wave motions from this point:



Matlab WebSite: http://www.mathworks.com/



 

Back