distance.f 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. IMPLICIT NONE
  42. !-----------------------------------------------------------------------
  43. ! INTENT(IN)
  44. !-----------------------------------------------------------------------
  45. REAL (kind=real_kind), INTENT(IN) ::
  46. $ 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. ! LOKAL VARIABLES
  52. !-----------------------------------------------------------------------
  53. REAL (kind=real_kind) ::
  54. $ x1, y1, z1, ! coordinates of the first point
  55. $ x2, y2, z2, ! coordinates of the second point
  56. $ distance ! distance between the points (rad)
  57. !-----------------------------------------------------------------------
  58. ! Transformation to x,y,z-coordinates
  59. ! -----------------------------------
  60. x1 = cos(lat1)*cos(lon1)
  61. y1 = cos(lat1)*sin(lon1)
  62. z1 = sin(lat1)
  63. x2 = cos(lat2)*cos(lon2)
  64. y2 = cos(lat2)*sin(lon2)
  65. z2 = sin(lat2)
  66. ! Calculation of the distance
  67. ! ---------------------------
  68. ! direct distance:
  69. distance = SQRT((x2-x1)**2 + (y2-y1)**2 + (z2-z1)**2)
  70. ! distance along the surface:
  71. distance = 2*ASIN(distance/2)
  72. !-----------------------------------------------------------------------
  73. RETURN
  74. END FUNCTION distance