m_confmap.F90 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. module m_confmap
  2. implicit none
  3. logical :: confmap_initialised = .false.
  4. real :: pi_1
  5. real :: pi_2
  6. real :: deg
  7. real :: rad
  8. real :: theta_a
  9. real :: phi_a
  10. real :: theta_b
  11. real :: phi_b
  12. real :: di
  13. real :: dj
  14. complex :: imagone
  15. complex :: ac
  16. complex :: bc
  17. complex :: cmna
  18. complex :: cmnb
  19. real :: mu_s
  20. real :: psi_s
  21. real :: epsil
  22. logical :: mercator
  23. real :: lat_a, lon_a
  24. real :: lat_b, lon_b
  25. real :: wlim, elim
  26. real :: slim, nlim
  27. real :: mercfac
  28. integer :: ires, jres
  29. contains
  30. ! This routine initializes constants used in the conformal mapping
  31. ! and must be called before the routines 'oldtonew' and 'newtoold'
  32. ! are called. The arguments of this routine are the locations of
  33. ! the two poles in the old coordiante system.
  34. !
  35. subroutine confmap_init(nx, ny)
  36. integer, intent(in) :: nx, ny
  37. real :: cx, cy, cz, theta_c, phi_c
  38. complex :: c, w
  39. logical :: ass, lold
  40. ! Read info file
  41. open(unit = 10, file = 'grid.info', form = 'formatted')
  42. read(10, *) lat_a, lon_a
  43. read(10, *) lat_b,lon_b
  44. read(10, *) wlim, elim, ires
  45. read(10, *) slim, nlim, jres
  46. read(10, *) ass
  47. read(10, *) ass
  48. read(10, *) ass
  49. read(10, *) mercator
  50. read(10, *) mercfac, lold
  51. close(10)
  52. if (ires /= nx .and. jres /= ny) then
  53. print *, 'initconfmap: WARNING -- the dimensions in grid.info are not'
  54. print *, 'initconfmap: WARNING -- consistent with nx and ny'
  55. print *, 'initconfmap: WARNING -- IGNORE IF RUNNING CURVIINT'
  56. stop '(initconfmap)'
  57. endif
  58. ! some constants
  59. !
  60. pi_1 = 3.14159265358979323846
  61. pi_2 = 0.5 * pi_1
  62. deg = 180.0 / pi_1
  63. rad = 1.0 / deg
  64. epsil = 1.0d-9
  65. di = (elim - wlim) / real(ires - 1) ! delta lon'
  66. dj = (nlim - slim) / real(jres - 1) ! delta lat' for spherical grid
  67. if (mercator) then
  68. dj = di
  69. if (lold) then
  70. print *, 'initconfmap: lold'
  71. slim = -mercfac * jres * dj
  72. else
  73. print *, 'initconfmap: not lold'
  74. slim = mercfac
  75. endif
  76. endif
  77. ! transform to spherical coordinates
  78. !
  79. theta_a = lon_a * rad
  80. phi_a = pi_2 - lat_a * rad
  81. theta_b = lon_b * rad
  82. phi_b = pi_2 - lat_b * rad
  83. ! find the angles of a vector pointing at a point located exactly
  84. ! between the poles
  85. !
  86. cx = cos(theta_a) * sin(phi_a) + cos(theta_b) * sin(phi_b)
  87. cy = sin(theta_a) * sin(phi_a) + sin(theta_b) * sin(phi_b)
  88. cz = cos(phi_a) + cos(phi_b)
  89. theta_c = atan2(cy, cx)
  90. phi_c = pi_2 - atan2(cz, sqrt(cx * cx + cy * cy))
  91. ! initialize constants used in the conformal mapping
  92. !
  93. imagone = (0.0, 1.0)
  94. ac = tan(0.5 * phi_a) * exp(imagone * theta_a)
  95. bc = tan(0.5 * phi_b) * exp(imagone * theta_b)
  96. c = tan(0.5 * phi_c) * exp(imagone * theta_c)
  97. cmna = c - ac
  98. cmnb = c - bc
  99. w = cmnb / cmna
  100. mu_s = atan2(aimag(w), real(w))
  101. psi_s = 2.0 * atan(abs(w))
  102. confmap_initialised = .true.
  103. end subroutine confmap_init
  104. end module m_confmap