m_confmap.f90 3.2 KB

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