grid_tools  1.5.0
 All Data Structures Files Functions Variables
pfun.f90
Go to the documentation of this file.
1 
4 
11 module pfun
12 !=============================================================================
13 use pkind, only: sp,dp
14 implicit none
15 private
18 
19 interface gd; module procedure gd_s, gd_d; end interface
20 interface gdi; module procedure gdi_s, gdi_d; end interface
21 interface hav; module procedure hav_s, hav_d; end interface
22 interface havh; module procedure havh_s, havh_d; end interface
23 interface ahav; module procedure ahav_s, ahav_d; end interface
24 interface ahavh; module procedure ahavh_s, ahavh_d; end interface
25 interface atanh; module procedure atanh_s, atanh_d; end interface
26 interface sech; module procedure sech_s, sech_d; end interface
27 interface sechs; module procedure sechs_s, sechs_d; end interface
28 interface sinoxm; module procedure sinoxm_d; end interface
29 interface sinox; module procedure sinox_d; end interface
30 interface sinhoxm; module procedure sinhoxm_d;end interface
31 interface sinhox; module procedure sinhox_d; end interface
32 
33 contains
34 
40 function gd_s(x) result(y)! [gd]
41 ! Gudermannian function
42 implicit none
43 real(sp),intent(in ):: x
44 real(sp) :: y
45 y=atan(sinh(x))
46 end function gd_s
47 
53 function gd_d(x) result(y)! [gd]
54 implicit none
55 real(dp),intent(in ):: x
56 real(dp) :: y
57 y=atan(sinh(x))
58 end function gd_d
59 
65 function gdi_s(y) result(x)! [gdi]
66 implicit none
67 real(sp),intent(in ):: y
68 real(sp) :: x
69 x=atanh(sin(y))
70 end function gdi_s
71 
77 function gdi_d(y) result(x)! [gdi]
78 implicit none
79 real(dp),intent(in ):: y
80 real(dp) :: x
81 x=atanh(sin(y))
82 end function gdi_d
83 
89 function hav_s(t) result(a)! [hav]
90 use pietc_s, only: o2
91 implicit none
92 real(sp),intent(in ):: t
93 real(sp) :: a
94 a=(sin(t*o2))**2
95 end function hav_s
96 
102 function hav_d(t) result(a)! [hav]
103 use pietc, only: o2
104 implicit none
105 real(dp),intent(in ):: t
106 real(dp) :: a
107 a=(sin(t*o2))**2
108 end function hav_d
109 
117 function havh_s(t) result(a)! [havh]
118 use pietc_s, only: o2
119 implicit none
120 real(sp),intent(in ):: t
121 real(sp) :: a
122 a=-(sinh(t*o2))**2
123 end function havh_s
124 
130 function havh_d(t) result(a)! [havh]
131 use pietc, only: o2
132 implicit none
133 real(dp),intent(in ):: t
134 real(dp) :: a
135 a=-(sinh(t*o2))**2
136 end function havh_d
137 
143 function ahav_s(a) result(t)! [ahav]
144 use pietc_s, only: u2
145 implicit none
146 real(sp),intent(in ):: a
147 real(sp) :: t
148 t=u2*asin(sqrt(a))
149 end function ahav_s
150 
156 function ahav_d(a) result(t)! [ahav]
157 use pietc, only: u2
158 implicit none
159 real(dp),intent(in ):: a
160 real(dp) :: t
161 t=u2*asin(sqrt(a))
162 end function ahav_d
163 
171 function ahavh_s(a) result(t)! [ahavh]
172 use pietc_s, only: u2
173 implicit none
174 real(sp),intent(in ):: a
175 real(sp) :: t
176 t=u2*asinh(sqrt(-a))
177 end function ahavh_s
178 
184 function ahavh_d(a) result(t)! [ahavh]
185 use pietc, only: u2
186 implicit none
187 real(dp),intent(in ):: a
188 real(dp) :: t
189 t=u2*asinh(sqrt(-a))
190 end function ahavh_d
191 
197 function atanh_s(t) result(a)! [atanh]
198 use pietc_s, only: u1,o2,o3,o5
199 implicit none
200 real(sp),intent(IN ):: t
201 real(sp) :: a,tt
202 real(sp),parameter :: o7=u1/7_sp,o9=u1/9_sp
203 !=============================================================================
204 if(abs(t)>=u1)stop 'In atanh; no solution'
205 if(abs(t)>1.e-3_sp)then; a=log((u1+t)/(u1-t))*o2
206 else; tt=t*t; a=t*(u1+tt*(o3+tt*(o5+tt*(o7+tt*o9))))
207 endif
208 end function atanh_s
209 
215 function atanh_d(t) result(a)! [atanh]
216 use pietc, only: u1,o2,o3,o5
217 implicit none
218 real(dp),intent(IN ):: t
219 real(dp) :: a,tt
220 real(dp),parameter :: o7=u1/7_dp,o9=u1/9_dp
221 !=============================================================================
222 if(abs(t)>=u1)stop 'In atanh; no solution'
223 if(abs(t)>1.e-3_dp)then; a=log((u1+t)/(u1-t))*o2
224 else; tt=t*t; a=t*(u1+tt*(o3+tt*(o5+tt*(o7+tt*o9))))
225 endif
226 end function atanh_d
227 
233 function sech_s(x)result(r)! [sech]
234 ! This indirect way of computing 1/cosh(x) avoids overflows at large x
235 use pietc_s, only: u1,u2
236 implicit none
237 real(sp),intent(in ):: x
238 real(sp) :: r
239 real(sp) :: e,ax
240 ax=abs(x)
241 e=exp(-ax)
242 r=e*u2/(u1+e*e)
243 end function sech_s
244 
250 function sech_d(x)result(r)! [sech]
251 use pietc, only: u1,u2
252 implicit none
253 real(dp),intent(in ):: x
254 real(dp) :: r
255 real(dp) :: e,ax
256 ax=abs(x)
257 e=exp(-ax)
258 r=e*u2/(u1+e*e)
259 end function sech_d
260 
266 function sechs_s(x)result(r)! [sechs]
267 implicit none
268 real(sp),intent(in ):: x
269 real(sp) :: r
270 r=sech(x)**2
271 end function sechs_s
272 
278 function sechs_d(x)result(r)! [sechs]
279 implicit none
280 real(dp),intent(in ):: x
281 real(dp) :: r
282 r=sech(x)**2
283 end function sechs_d
284 
290 function sinoxm_d(x) result(r)! [sinoxm]
291 use pietc, only: u1
292 implicit none
293 real(dp),intent(in ):: x
294 real(dp) :: r
295 !-----------------------------------------------------------------------------
296 real(dp):: xx
297 !=============================================================================
298 xx=x*x
299 if(xx > .05_dp)then; r=sin(x)/x-u1
300 else ; r=-xx*(u1-xx*(u1-xx*(u1-xx*(u1-xx*(u1-xx/&
301  156._dp)/110._dp)/72._dp)/42._dp)/20._dp)/6._dp
302 endif
303 end function sinoxm_d
304 
310 function sinox_d(x) result(r)! [sinox]
311 use pietc, only: u1
312 implicit none
313 real(dp),intent(in ):: x
314 real(dp) :: r
315 !=============================================================================
316 r=sinoxm(x)+u1
317 end function sinox_d
318 
324 function sinhoxm_d(x) result(r)! [sinhoxm]
325 use pietc, only: u1
326 implicit none
327 real(dp),intent(in ):: x
328 real(dp) :: r
329 !-----------------------------------------------------------------------------
330 real(dp):: xx
331 !=============================================================================
332 xx=x*x
333 if(xx > .05_dp)then; r=sinh(x)/x-u1
334 else; r=xx*(u1+xx*(u1+xx*(u1+xx*(u1+xx*(u1+xx/&
335  156._dp)/110._dp)/72._dp)/42._dp)/20._dp)/6._dp
336 endif
337 end function sinhoxm_d
338 
344 function sinhox_d(x) result(r)! [sinhox]
345 use pietc, only: u1
346 implicit none
347 real(dp),intent(in ):: x
348 real(dp) :: r
349 !=============================================================================
350 r=sinhoxm(x)+u1
351 end function sinhox_d
352 
353 end module pfun
real(sp) function havh_s(t)
Hyperbolic-haversine for single precision real (for pseudosphere geometry).
Definition: pfun.f90:117
real(dp) function sinhox_d(x)
Evaluate the symmetric real function sinh(x)/x.
Definition: pfun.f90:344
real(dp) function hav_d(t)
Haversine function for double precision real (for geometry on the sphere).
Definition: pfun.f90:102
real(dp) function sinox_d(x)
Evaluate the symmetric real function sin(x)/x.
Definition: pfun.f90:310
real(dp) function ahav_d(a)
Arc-haversine function for double precision real.
Definition: pfun.f90:156
real(dp) function sech_d(x)
Hyperbolic secant for double precision real.
Definition: pfun.f90:250
real(sp) function gd_s(x)
Gudermannian function (related to Mercator map projections)
Definition: pfun.f90:40
real(sp) function atanh_s(t)
Hyperbolic arc-tangent for single precision real.
Definition: pfun.f90:197
real(sp) function hav_s(t)
Haversine function for single precision real (for geometry on the sphere).
Definition: pfun.f90:89
real(dp) function atanh_d(t)
Hyperbolic arc-tangent for double precision real.
Definition: pfun.f90:215
This module is for evaluating several useful real-valued functions that are not always available in F...
Definition: pfun.f90:11
real(dp) function sinhoxm_d(x)
Evaluate the symmetric real function sinh(x)/x-1.
Definition: pfun.f90:324
Standard integer, real, and complex single and double precision kinds.
Definition: pkind.f90:7
Some of the commonly used constants (pi etc) mainly for double-precision subroutines.
Definition: pietc.f90:14
real(sp) function ahavh_s(a)
Hyperbolic arc-haversine for single precision real.
Definition: pfun.f90:171
real(dp) function sinoxm_d(x)
Evaluate the symmetric real function sin(x)/x-1, still accurate near x=0.
Definition: pfun.f90:290
real(sp) function sechs_s(x)
Hyperbolic secant-squared function (logistic distribution).
Definition: pfun.f90:266
real(dp) function sechs_d(x)
Hyperbolic secant-squared function (logistic distribution).
Definition: pfun.f90:278
real(dp) function havh_d(t)
Hyperbolic-haversine for double precision real (for pseudosphere geometry).
Definition: pfun.f90:130
real(dp) function gdi_d(y)
Inverse Gudermannian function for double precision real.
Definition: pfun.f90:77
real(dp) function ahavh_d(a)
Hyperbolic arc-haversine for double precision real.
Definition: pfun.f90:184
real(sp) function sech_s(x)
Hyperbolic secant for single precision real.
Definition: pfun.f90:233
real(dp) function gd_d(x)
Gudermannian function (related to Mercator map projections)
Definition: pfun.f90:53
real(sp) function gdi_s(y)
Inverse Gudermannian function for single precision real.
Definition: pfun.f90:65
real(sp) function ahav_s(a)
Arc-haversine function for single precision real.
Definition: pfun.f90:143