Oasis3 4.0.2
|
00001 FUNCTION distance (lon1, lat1, lon2, lat2) 00002 C**** 00003 C ***************************** 00004 C * OASIS ROUTINE - LEVEL ? * 00005 C * ------------- ------- * 00006 C ***************************** 00007 C 00008 C**** *distance* - calculate the distance between two points on a sphere 00009 C 00010 C Purpose: 00011 C ------- 00012 C Calculation of the distance between two points on a sphere 00013 C 1. Transformation to x,y,z-coordinates 00014 C 2. Calculating the distance 00015 C 3. Calculating the distance on the sphere 00016 C 00017 C** Interface: 00018 C --------- 00019 C *CALL* *distance*(lon1, lat1, lon2, lat2) 00020 C 00021 C Input: 00022 C ----- 00023 C lon1 : longitude of first point (rad) 00024 C lat1 : latitude of first point (rad) 00025 C lon2 : longitude of second point (rad) 00026 C lat2 : latitude of second point (rad) 00027 C 00028 C Output: 00029 C ------ 00030 C distance : distance 00031 CC 00032 C History: 00033 C ------- 00034 C Version Programmer Date Description 00035 C ------- ---------- ---- ----------- 00036 C 2.5 V. Gayler 2001/09/20 created 00037 C 00038 C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00039 USE constants 00040 USE kinds_mod 00041 00042 IMPLICIT NONE 00043 !----------------------------------------------------------------------- 00044 ! INTENT(IN) 00045 !----------------------------------------------------------------------- 00046 REAL (kind=real_kind), INTENT(IN) :: 00047 $ lon1, ! longitude of first point (rad) 00048 $ lon2, ! longitude of second point (rad) 00049 $ lat1, ! latitude of first point (rad) 00050 $ lat2 ! latitude of second point (rad) 00051 00052 !----------------------------------------------------------------------- 00053 ! LOKAL VARIABLES 00054 !----------------------------------------------------------------------- 00055 REAL (kind=real_kind) :: 00056 $ x1, y1, z1, ! coordinates of the first point 00057 $ x2, y2, z2, ! coordinates of the second point 00058 $ distance ! distance between the points (rad) 00059 00060 !----------------------------------------------------------------------- 00061 00062 ! Transformation to x,y,z-coordinates 00063 ! ----------------------------------- 00064 x1 = cos(lat1)*cos(lon1) 00065 y1 = cos(lat1)*sin(lon1) 00066 z1 = sin(lat1) 00067 00068 x2 = cos(lat2)*cos(lon2) 00069 y2 = cos(lat2)*sin(lon2) 00070 z2 = sin(lat2) 00071 00072 ! Calculation of the distance 00073 ! --------------------------- 00074 ! direct distance: 00075 distance = SQRT((x2-x1)**2 + (y2-y1)**2 + (z2-z1)**2) 00076 00077 ! distance along the surface: 00078 distance = 2*ASIN(distance/2) 00079 00080 !----------------------------------------------------------------------- 00081 RETURN 00082 END FUNCTION distance 00083