Distance Calculation Program

Distance Calculation program

Updated 08/12/04

The following program was written to determine the distance to the epicenter from each site in a data file (sites.dat). After the distance is calculated, it determines the time difference between the p and s wave as well as the amplitude in mm. This information, along with some amplitude modification data is printed to a data file (info.dat)

The sites.dat file contained the latitude and longitude of each participating site as well as factors which are used by the next program to add or subtract from the p waves amplitude based on the relative location of the epicenter to the site. A sample sites.dat file is listed after the program.


% Program to calculate distance between epicenter of quake and
% each participating MVHS site.  Create seismic data and print
% to file

clear

disp('Input the latitude and longitude of the epicenter as prompted')
disp('Lat and Long should be in degrees (convert minutes and seconds)')
disp('Use negative degrees for west and south')

lat1 = input ('Latitude epicenter: ');
lon1 = input ('Longitude epicenter: ');

M=input('What magnitude for the quake? ');

load sites.dat

lat2 = sites(:,1);
lon2 = sites(:,2);
nsamp = sites(:,3);
ewamp = sites(:,4);

%Convert to radians

latrad1 = lat1*pi/180;
lonrad1 = lon1*pi/180;
latrad2 = lat2*pi/180;
lonrad2 = lon2*pi/180;

londif = abs(lonrad2-lonrad1);

% Calculates the radial distance between the epicenter and each site

raddis = acos(sin(latrad1)*sin(latrad2)+ cos(latrad1)*cos(latrad2) .*cos(londif));

% Convert to statute km
nautdis = raddis * 3437.74677;
stdiskm = nautdis * 1.852;

% Time between s and p
tdiff=stdiskm/8;

% Total time = time difference + 1 sec before + 20 sec after
ttot=tdiff+1+20;

% Gives amp in mm

amp=10 .^(M+2.92-3*(log10(stdiskm)));

info(1,:)=reshape(lat2,1,12);
info(2,:)=reshape(lon2,1,12);
info(3,:)=reshape(amp,1,12);
info(4,:)=reshape(nsamp,1,12);
info(5,:)=reshape(ewamp,1,12);
info(6,:)=reshape(tdiff,1,12);
info(7,:)=reshape(ttot,1,12);

% Print information to a data file for next program

fid=fopen('info.dat','w');
fprintf(fid,'%3.2f  %3.2f  %3.2f  %3.2f  %3.2f  %3.2f  %3.2f\n',info);
fclose(fid);



Example sites.dat file

39.62 -79.32 0 1
39.33 -76.60 0 1
39.05 -76.07 0 1
39.00 -76.69 1 0
39.07 -76.68 1 0
39.55 -76.10 0.5 0.5
38.60 -77.17 1 0
39.60 -75.94 0.5 0.5
38.37 -75.60 1 0
39.01 -77.03 1 0
39.65 -77.56 0.5 0.5
39.60 -77.82 0 0.5