function out = cal_epi(stla,stlo,evla,evlo)

%CAL_EPI  Epicentral distance in degree on spherical Earth.
%   CAL_EPI(stla,stlo,evla,evlo) is the epicentral distances 
%   between locations of stations and events. For N stations 
%   and M events, the CAL_EPI produces N by M matrix.


aa=pi/180;
stlo=mod(stlo,360);
evlo=mod(evlo,360);
   
num_st = length(stla);
num_ev = length(evla);

out = zeros(num_st,num_ev);

for i = 1 : num_st
   for j = 1 : num_ev
      tstlo = stlo(i);
      tevlo = evlo(j);
	  tbig1 = max(tstlo,tevlo);
	  tbig2 = min(tstlo,tevlo);
      biga = tbig1 - tbig2;
      c = 90 - stla(i);
      b = 90 - evla(j);
      if biga >= 180
         biga = 360 - tbig1 + tbig2;
      end   
      
	  dd = cos(b*aa)*cos(c*aa) + sin(b*aa)*sin(c*aa)*cos(biga*aa);
	  out(i,j) = acos(dd)/aa;
   end
end  
      

	