source: CONFIG_DEVT/IPSLCM6.5_work_ENSEMBLES/oasis3-mct/examples/spoc/spoc_regridding/distance_rad.f90 @ 5725

Last change on this file since 5725 was 5725, checked in by aclsce, 3 years ago

Added new oasis3-MCT version to be used to handle ensembles simulations with XIOS.

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