m_oldtonew.F90 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. module m_oldtonew
  2. use m_confmap
  3. implicit none
  4. contains
  5. ! this routine performes a conformal mapping of the old to the new
  6. ! coordinate system
  7. !
  8. subroutine oldtonew(lat_o, lon_o, lat_n, lon_n)
  9. real(8), intent(in) :: lat_o, lon_o
  10. real(8), intent(out) :: lat_n, lon_n
  11. real :: theta, phi, psi, mu
  12. complex :: z, w
  13. if (.not. confmap_initialised) then
  14. print *, 'ERROR: oldtonew(): confmap not initialised'
  15. stop
  16. end if
  17. ! transform to spherical coordinates
  18. !
  19. theta = mod(lon_o * rad + 3.0 * pi_1, 2.0 * pi_1) - pi_1
  20. phi = pi_2 - lat_o * rad
  21. ! transform to the new coordinate system
  22. !
  23. if (abs(phi - pi_1) < epsil) then
  24. mu = mu_s
  25. psi = psi_s
  26. elseif (abs(phi - phi_b) < epsil .and. abs(theta - theta_b) < epsil) then
  27. mu = 0.0
  28. psi = pi_1
  29. else
  30. z = tan(0.5 * phi) * exp(imagone * theta)
  31. w = (z - ac) * cmnb / ((z - bc) * cmna)
  32. mu = atan2(aimag(w), real(w))
  33. psi = 2.0 * atan(abs(w))
  34. endif
  35. ! transform to lat/lon coordinates
  36. !
  37. lat_n = (pi_2 - psi) * deg
  38. lon_n = mu * deg
  39. end subroutine oldtonew
  40. end module m_oldtonew