source: Roms_tools/Preprocessing_tools/spheric_dist.m @ 2

Last change on this file since 2 was 1, checked in by cholod, 13 years ago

import Roms_Agrif

File size: 1.8 KB
Line 
1 
2function dist=spheric_dist(lat1,lat2,lon1,lon2)
3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4%
5%  function dist=spheric_dist(lat1,lat2,lon1,lon2)
6%
7% compute distances for a simple spheric earth
8%
9%   input:
10%
11%  lat1 : latitude of first point (matrix)
12%  lon1 : longitude of first point (matrix)
13%  lat2 : latitude of second point (matrix)
14%  lon2 : longitude of second point (matrix)
15%
16%   output:
17%  dist : distance from first point to second point (matrix)
18%
19%  Further Information: 
20%  http://www.brest.ird.fr/Roms_tools/
21
22%  This file is part of ROMSTOOLS
23%
24%  ROMSTOOLS is free software; you can redistribute it and/or modify
25%  it under the terms of the GNU General Public License as published
26%  by the Free Software Foundation; either version 2 of the License,
27%  or (at your option) any later version.
28%
29%  ROMSTOOLS is distributed in the hope that it will be useful, but
30%  WITHOUT ANY WARRANTY; without even the implied warranty of
31%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32%  GNU General Public License for more details.
33%
34%  You should have received a copy of the GNU General Public License
35%  along with this program; if not, write to the Free Software
36%  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
37%  MA  02111-1307  USA
38%
39%  Copyright (c) 2001-2006 by Pierrick Penven
40%  e-mail:Pierrick.Penven@ird.fr 
41%
42%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43%
44% Earth radius
45%
46R=6367442.76;
47%
48%  Determine proper longitudinal shift.
49%
50l=abs(lon2-lon1);
51l(l>=180)=360-l(l>=180);
52%                 
53%  Convert Decimal degrees to radians.
54%
55deg2rad=pi/180;
56lat1=lat1*deg2rad;
57lat2=lat2*deg2rad;
58l=l*deg2rad;
59%
60%  Compute the distances
61%
62dist=R*asin(sqrt(((sin(l).*cos(lat2)).^2)+(((sin(lat2).*cos(lat1))-...
63         (sin(lat1).*cos(lat2).*cos(l))).^2)));
64return
Note: See TracBrowser for help on using the repository browser.