1 | FUNCTION distance (lon1, lat1, lon2, lat2) |
---|
2 | C**** |
---|
3 | C ***************************** |
---|
4 | C * OASIS ROUTINE - LEVEL ? * |
---|
5 | C * ------------- ------- * |
---|
6 | C ***************************** |
---|
7 | C |
---|
8 | C**** *distance* - calculate the distance between two points on a sphere |
---|
9 | C |
---|
10 | C Purpose: |
---|
11 | C ------- |
---|
12 | C Calculation of the distance between two points on a sphere |
---|
13 | C 1. Transformation to x,y,z-coordinates |
---|
14 | C 2. Calculating the distance |
---|
15 | C 3. Calculating the distance on the sphere |
---|
16 | C |
---|
17 | C** Interface: |
---|
18 | C --------- |
---|
19 | C *CALL* *distance*(lon1, lat1, lon2, lat2) |
---|
20 | C |
---|
21 | C Input: |
---|
22 | C ----- |
---|
23 | C lon1 : longitude of first point (rad) |
---|
24 | C lat1 : latitude of first point (rad) |
---|
25 | C lon2 : longitude of second point (rad) |
---|
26 | C lat2 : latitude of second point (rad) |
---|
27 | C |
---|
28 | C Output: |
---|
29 | C ------ |
---|
30 | C distance : distance |
---|
31 | CC |
---|
32 | C History: |
---|
33 | C ------- |
---|
34 | C Version Programmer Date Description |
---|
35 | C ------- ---------- ---- ----------- |
---|
36 | C 2.5 V. Gayler 2001/09/20 created |
---|
37 | C |
---|
38 | C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
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 | |
---|