I'm comparing the speed and accuracy of several coordinate transformation algorithms and find that the functionDATAN2D doubles the execution time ofthe whole program over and above that when using DATAN2. These two functions should really only differ by a multiplication operation (i.e. 57.3 deg/rad). Anybody have any ideas?
I use VS 2008, IVF 11.1.035, x64 platform,IDE environment.
This code illustrates the problem:
program main ! Compute longitude in equatorial xy plane.
real*8 :: x, y, w, dw, LON, LonDeg, LonRad, t1, err, mx, t2
real*8,parameter :: delt = 1.d0/360.d0, rpd = datan(1.d0)/45.,&
drad = delt * rpd, dpr = 1./rpd
integer*4 :: i,j
write (*,'("computing longitude")')
mx = 0.d0
w = 6000000.d0
call cpu_time (t1)
do i = 1, 10000
w = w + 10. ! increment by 10 m
do j = 1, 32000
LonDeg = j * delt ! 1/360 deg to 88.9 degrees
LonRad = j * drad ! same thing in radians
x = w * dcos (LonRad)
y = w * dsin (LonRad) ! call datan2 to recover Long.
LON = dpr * datan2(y, x) ! this way takes 11.3 sec
! LON = datan2d (y, x) ! this way takes 22.7 sec <------
err = dabs (LON - LonDeg) ! error in degrees
if (err > mx) mx = err ! max err, degrees
enddo
enddo
call cpu_time(t2)
write (*,'("max error:",f20.14," degrees")') mx
write (*,'("time: ",f20.1," seconds")') t2-t1
end program main





