function [sa, sigma] = AS_1997_horiz(M, r_rup, T, is_soil, fault_type, HW, arb);
% by Jack Baker, 2/1/05, modified 1/12/2010
% Stanford University
% bakerjw@stanford.edu
%
% Compute the Abrahamson and Silva ground motion prediction (1997
% Seismological Research Letters, Vol 68, No 1, p94).
%
% This script has been modified to include standard deviations for either
% arbitrary or average components of ground motion. See Baker, JW, and
% Cornell, CA (2006). "Which spectral acceleration are you using?"
% Earthquake Spectra, 22(2), 293-312.
%
% This script has also been modified to correct an error in the function
% f_3 that occured in the printed version of the model.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% INPUT
%
% M = earthquake magnitude
% R = closest distance to fault rupture
% T = period of vibration
% is_soil = 1 for soil prediction
% = 0 for rock
% fault_type = 1 for Reverse
% = 0.5 for reverse/oblique
% = 0 otherwise
% HW = 1 for Hanging Wall sites
% = 0 otherwise
% arb = 1 for arbitrary component sigma
% = 0 for average component sigma
%
% OUTPUT
%
% sa = median spectral acceleration prediction
% sigma = logarithmic standard deviation of spectral acceleration
% prediction FOR AN ARBITRARY OR AVERAGE COMPONENT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% for the given period T, get the index for the constants
period = [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.075, 0.09, 0.1, 0.12, 0.15, 0.17, 0.2, 0.24, 0.3, 0.36, 0.4, 0.46, 0.5, 0.6, 0.75, 0.85, 1, 1.5, 2, 3, 4, 5];
% fill in missing input parameters with default values
if (nargin < 4) % no soil type supplied
is_soil = 1;
end
if (nargin < 5) % no fault type supplied
fault_type = 0;
end
if (nargin < 6) % no Hanging wall indicator supplied
HW = 0;
end
if (nargin < 7) % arbitrary/average component not supplied
arb = 1;
end
% interpolate between periods if neccesary
if (length(find(period == T)) == 0)
index_low = sum(period