source: CPL/oasis3/trunk/src/lib/scrip/src/distance.f @ 1677

Last change on this file since 1677 was 1677, checked in by aclsce, 12 years ago

Imported oasis3 (tag ipslcm5a) from cvs server to svn server (igcmg project).

File size: 2.8 KB
Line 
1       FUNCTION distance (lon1, lat1, lon2, lat2)
2C****
3C               *****************************
4C               * OASIS ROUTINE  -  LEVEL ? *
5C               * -------------     ------- *
6C               *****************************
7C
8C**** *distance*  - calculate the distance between two points on a sphere
9C
10C     Purpose:
11C     -------
12C     Calculation of the distance between two points on a sphere
13C       1. Transformation to x,y,z-coordinates
14C       2. Calculating the distance
15C       3. Calculating the distance on the sphere
16C
17C**   Interface:
18C     ---------
19C       *CALL*  *distance*(lon1, lat1, lon2, lat2)
20C
21C     Input:
22C     -----
23C          lon1              : longitude of first point (rad)
24C          lat1              : latitude of first point (rad)
25C          lon2              : longitude of second point (rad)
26C          lat2              : latitude of second point (rad)
27C
28C     Output:
29C     ------
30C          distance          : distance
31CC
32C     History:
33C     -------
34C       Version   Programmer     Date        Description
35C       -------   ----------     ----        ----------- 
36C       2.5       V. Gayler      2001/09/20  created
37C
38C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39      USE constants
40      USE kinds_mod
41
42      IMPLICIT NONE
43!-----------------------------------------------------------------------
44!     INTENT(IN)
45!-----------------------------------------------------------------------
46      REAL (kind=real_kind), INTENT(IN) :: 
47     $     lon1,                ! longitude of first point (rad)
48     $     lon2,                ! longitude of second point (rad)
49     $     lat1,                ! latitude of first point (rad)
50     $     lat2                 ! latitude of second point (rad)
51
52!-----------------------------------------------------------------------
53!     LOKAL VARIABLES
54!-----------------------------------------------------------------------
55      REAL (kind=real_kind) ::
56     $     x1, y1, z1,          ! coordinates of the first point
57     $     x2, y2, z2,          ! coordinates of the second point
58     $     distance             ! distance between the points (rad)
59
60!-----------------------------------------------------------------------
61
62!     Transformation to x,y,z-coordinates
63!     -----------------------------------
64      x1 = cos(lat1)*cos(lon1)
65      y1 = cos(lat1)*sin(lon1)
66      z1 = sin(lat1)
67
68      x2 = cos(lat2)*cos(lon2)
69      y2 = cos(lat2)*sin(lon2)
70      z2 = sin(lat2)
71
72!     Calculation of the distance
73!     ---------------------------
74!     direct distance:
75      distance = SQRT((x2-x1)**2 + (y2-y1)**2 + (z2-z1)**2)
76
77!     distance along the surface:
78      distance = 2*ASIN(distance/2)
79
80!-----------------------------------------------------------------------
81      RETURN
82      END FUNCTION distance
83
Note: See TracBrowser for help on using the repository browser.