source: CPL/oasis3/trunk/src/mod/oasis3/src/sqdis.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: 3.3 KB
Line 
1      FUNCTION sqdis (px1, py1, px2, py2)
2C****
3C               ******************************
4C               * OASIS FUNCTION  -  LEVEL T *
5C               * --------------     ------- *
6C               ******************************
7C
8C**** *sqdis*  - Arithmetic function
9C
10C     Purpose:
11C     -------
12C     Calculate the distance squared between 2 points on a spheric grid
13C
14C**   Interface:
15C     ---------
16C       *zs =*  *sqdis (px1, py1, px2, py2)*
17C
18C     Input:
19C     -----
20C                px1    : longitude of first point 
21C                py1    : latitude of first point
22C                px2    : longitude of second point
23C                py2    : latitude of second point
24C
25C     NB: the coordinates must be in degrees
26C
27C     Output:
28C     ------
29C     None
30C
31C     Workspace:
32C     ---------
33C     None
34C
35C     Externals:
36C     ---------
37C     None
38C
39C     Reference:
40C     ---------
41C     See OASIS manual (1995)
42C
43C     History:
44C     -------
45C       Version   Programmer     Date      Description
46C       -------   ----------     ----      ----------- 
47C       2.0       L. Terray      95/09/01  created
48C
49C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50C
51C* ---------------------------- Include files ---------------------------
52C
53      USE mod_kinds_oasis
54      USE mod_unit
55C
56C* ---------------------------- Function declarations -------------------
57C
58      REAL (kind=ip_realwp_p) sqdis, fast
59      fast(x,y,z) = cos(x)*cos(y)*z + sin(x)*sin(y)
60C
61C* ---------------------------- Poema verses ----------------------------
62C
63C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64C
65C*    1. Calculate distance
66C        ------------------
67C
68C* Degree to radians --> zcon = 2. pi / 360.
69C 
70      zconv = 1.74532925199432957692e-2 
71      zfi1 = px1 * zconv
72      zth1 = py1 * zconv
73      zfi2 = px2 * zconv
74      zth2 = py2 * zconv
75C
76C* Scalar product
77C
78      ztp1 = fast(zfi1, zfi2, 1.)
79      zsca = fast(zth1, zth2, ztp1)
80C
81C* Angular distance
82C
83      IF (zsca .GT. 1.) THEN
84          WRITE(UNIT = nulan,FMT = *) 
85     $        ' Scalar product is greater than 1 '
86          WRITE(UNIT = nulan,FMT = *) 
87     $        ' for point 1 -->  longitude = ', px1
88          WRITE(UNIT = nulan,FMT = *) 
89     $        '             -->  latitude  = ', py1
90          WRITE(UNIT = nulan,FMT = *) 
91     $        ' and point 2 -->  longitude = ', px2
92          WRITE(UNIT = nulan,FMT = *) 
93     $        '             -->  latitude  = ', py2
94          WRITE(UNIT = nulan,FMT = *) 
95     $        ' Scalar product  zsca = ', zsca
96          zsca =1.
97      ENDIF
98      IF (zsca .LT. -1.) THEN
99          WRITE(UNIT = nulan,FMT = *) 
100     $        ' Scalar product is less than -1 '
101          WRITE(UNIT = nulan,FMT = *) 
102     $        ' for point 1 -->  longitude = ', px1
103          WRITE(UNIT = nulan,FMT = *) 
104     $        '             -->  latitude  = ', py1
105          WRITE(UNIT = nulan,FMT = *) 
106     $        ' and point 2 -->  longitude = ', px2
107          WRITE(UNIT = nulan,FMT = *) 
108     $        '             -->  latitude  = ', py2
109          WRITE(UNIT = nulan,FMT = *) 
110     $        ' Scalar product  zsca = ', zsca
111          zsca = -1.
112      ENDIF
113C
114C* Get the distance
115C             
116      zalp = acos(zsca)
117      sqdis = zalp * zalp
118C
119C* End of function
120C
121      RETURN
122      END
Note: See TracBrowser for help on using the repository browser.