[2218] | 1 | module fxhyp_m |
---|
[524] | 2 | |
---|
[2218] | 3 | IMPLICIT NONE |
---|
[524] | 4 | |
---|
[2218] | 5 | contains |
---|
[524] | 6 | |
---|
[2218] | 7 | SUBROUTINE fxhyp(xprimm025, rlonv, xprimv, rlonu, xprimu, xprimp025) |
---|
[524] | 8 | |
---|
[2218] | 9 | ! From LMDZ4/libf/dyn3d/fxhyp.F, version 1.2, 2005/06/03 09:11:32 |
---|
| 10 | ! Author: P. Le Van, from formulas by R. Sadourny |
---|
[524] | 11 | |
---|
[2218] | 12 | ! Calcule les longitudes et dérivées dans la grille du GCM pour |
---|
| 13 | ! une fonction f(x) à dérivée tangente hyperbolique. |
---|
[524] | 14 | |
---|
[2218] | 15 | ! Il vaut mieux avoir : grossismx \times dzoom < pi |
---|
[524] | 16 | |
---|
[2218] | 17 | ! Le premier point scalaire pour une grille regulière (grossismx = |
---|
| 18 | ! 1., taux=0., clon=0.) est à - 180 degrés. |
---|
[524] | 19 | |
---|
[2218] | 20 | use arth_m, only: arth |
---|
| 21 | use invert_zoom_x_m, only: invert_zoom_x, nmax |
---|
[2228] | 22 | use nrtype, only: pi, pi_d, twopi, twopi_d, k8 |
---|
[2218] | 23 | use principal_cshift_m, only: principal_cshift |
---|
[2598] | 24 | use serre_mod, only: clon, grossismx, dzoomx, taux |
---|
[5271] | 25 | USE dimensions_mod, ONLY: iim, jjm, llm, ndm |
---|
[524] | 26 | |
---|
[2218] | 27 | REAL, intent(out):: xprimm025(:), rlonv(:), xprimv(:) ! (iim + 1) |
---|
| 28 | real, intent(out):: rlonu(:), xprimu(:), xprimp025(:) ! (iim + 1) |
---|
[524] | 29 | |
---|
[2218] | 30 | ! Local: |
---|
| 31 | real rlonm025(iim + 1), rlonp025(iim + 1) |
---|
| 32 | REAL dzoom, step |
---|
| 33 | real d_rlonv(iim) |
---|
[2228] | 34 | REAL(K8) xtild(0:2 * nmax) |
---|
| 35 | REAL(K8) fhyp(nmax:2 * nmax), ffdx, beta, Xprimt(0:2 * nmax) |
---|
| 36 | REAL(K8) Xf(0:2 * nmax), xxpr(2 * nmax) |
---|
| 37 | REAL(K8) fa, fb |
---|
[2218] | 38 | INTEGER i, is2 |
---|
[2228] | 39 | REAL(K8) xmoy, fxm |
---|
[1674] | 40 | |
---|
[2218] | 41 | !---------------------------------------------------------------------- |
---|
[1674] | 42 | |
---|
[2218] | 43 | print *, "Call sequence information: fxhyp" |
---|
[1674] | 44 | |
---|
[2218] | 45 | test_iim: if (iim==1) then |
---|
| 46 | rlonv(1)=0. |
---|
| 47 | rlonu(1)=pi |
---|
| 48 | rlonv(2)=rlonv(1)+twopi |
---|
| 49 | rlonu(2)=rlonu(1)+twopi |
---|
[1674] | 50 | |
---|
[2218] | 51 | xprimm025(:)=1. |
---|
| 52 | xprimv(:)=1. |
---|
| 53 | xprimu(:)=1. |
---|
| 54 | xprimp025(:)=1. |
---|
| 55 | else test_iim |
---|
| 56 | test_grossismx: if (grossismx == 1.) then |
---|
| 57 | step = twopi / iim |
---|
[524] | 58 | |
---|
[2218] | 59 | xprimm025(:iim) = step |
---|
| 60 | xprimp025(:iim) = step |
---|
| 61 | xprimv(:iim) = step |
---|
| 62 | xprimu(:iim) = step |
---|
[524] | 63 | |
---|
[2218] | 64 | rlonv(:iim) = arth(- pi + clon / 180. * pi, step, iim) |
---|
| 65 | rlonm025(:iim) = rlonv(:iim) - 0.25 * step |
---|
| 66 | rlonp025(:iim) = rlonv(:iim) + 0.25 * step |
---|
| 67 | rlonu(:iim) = rlonv(:iim) + 0.5 * step |
---|
| 68 | else test_grossismx |
---|
| 69 | dzoom = dzoomx * twopi_d |
---|
| 70 | xtild = arth(- pi_d, pi_d / nmax, 2 * nmax + 1) |
---|
[524] | 71 | |
---|
[2218] | 72 | ! Compute fhyp: |
---|
| 73 | DO i = nmax, 2 * nmax |
---|
| 74 | fa = taux * (dzoom / 2. - xtild(i)) |
---|
| 75 | fb = xtild(i) * (pi_d - xtild(i)) |
---|
[524] | 76 | |
---|
[2218] | 77 | IF (200. * fb < - fa) THEN |
---|
| 78 | fhyp(i) = - 1. |
---|
| 79 | ELSE IF (200. * fb < fa) THEN |
---|
| 80 | fhyp(i) = 1. |
---|
| 81 | ELSE |
---|
| 82 | IF (ABS(fa) < 1e-13 .AND. ABS(fb) < 1e-13) THEN |
---|
| 83 | IF (200. * fb + fa < 1e-10) THEN |
---|
| 84 | fhyp(i) = - 1. |
---|
| 85 | ELSE IF (200. * fb - fa < 1e-10) THEN |
---|
| 86 | fhyp(i) = 1. |
---|
| 87 | END IF |
---|
| 88 | ELSE |
---|
| 89 | fhyp(i) = TANH(fa / fb) |
---|
| 90 | END IF |
---|
| 91 | END IF |
---|
[524] | 92 | |
---|
[2218] | 93 | IF (xtild(i) == 0.) fhyp(i) = 1. |
---|
| 94 | IF (xtild(i) == pi_d) fhyp(i) = -1. |
---|
| 95 | END DO |
---|
[524] | 96 | |
---|
[2218] | 97 | ! Calcul de beta |
---|
[524] | 98 | |
---|
[2218] | 99 | ffdx = 0. |
---|
[524] | 100 | |
---|
[2218] | 101 | DO i = nmax + 1, 2 * nmax |
---|
| 102 | xmoy = 0.5 * (xtild(i-1) + xtild(i)) |
---|
| 103 | fa = taux * (dzoom / 2. - xmoy) |
---|
| 104 | fb = xmoy * (pi_d - xmoy) |
---|
[524] | 105 | |
---|
[2218] | 106 | IF (200. * fb < - fa) THEN |
---|
| 107 | fxm = - 1. |
---|
| 108 | ELSE IF (200. * fb < fa) THEN |
---|
| 109 | fxm = 1. |
---|
| 110 | ELSE |
---|
| 111 | IF (ABS(fa) < 1e-13 .AND. ABS(fb) < 1e-13) THEN |
---|
| 112 | IF (200. * fb + fa < 1e-10) THEN |
---|
| 113 | fxm = - 1. |
---|
| 114 | ELSE IF (200. * fb - fa < 1e-10) THEN |
---|
| 115 | fxm = 1. |
---|
| 116 | END IF |
---|
| 117 | ELSE |
---|
| 118 | fxm = TANH(fa / fb) |
---|
| 119 | END IF |
---|
| 120 | END IF |
---|
[524] | 121 | |
---|
[2218] | 122 | IF (xmoy == 0.) fxm = 1. |
---|
| 123 | IF (xmoy == pi_d) fxm = -1. |
---|
[524] | 124 | |
---|
[2218] | 125 | ffdx = ffdx + fxm * (xtild(i) - xtild(i-1)) |
---|
| 126 | END DO |
---|
[524] | 127 | |
---|
[2218] | 128 | print *, "ffdx = ", ffdx |
---|
| 129 | beta = (grossismx * ffdx - pi_d) / (ffdx - pi_d) |
---|
| 130 | print *, "beta = ", beta |
---|
[524] | 131 | |
---|
[2218] | 132 | IF (2. * beta - grossismx <= 0.) THEN |
---|
| 133 | print *, 'Bad choice of grossismx, taux, dzoomx.' |
---|
| 134 | print *, 'Decrease dzoomx or grossismx.' |
---|
| 135 | STOP 1 |
---|
| 136 | END IF |
---|
[524] | 137 | |
---|
[2218] | 138 | ! calcul de Xprimt |
---|
| 139 | Xprimt(nmax:2 * nmax) = beta + (grossismx - beta) * fhyp |
---|
| 140 | xprimt(:nmax - 1) = xprimt(2 * nmax:nmax + 1:- 1) |
---|
[524] | 141 | |
---|
[2218] | 142 | ! Calcul de Xf |
---|
[524] | 143 | |
---|
[2218] | 144 | DO i = nmax + 1, 2 * nmax |
---|
| 145 | xmoy = 0.5 * (xtild(i-1) + xtild(i)) |
---|
| 146 | fa = taux * (dzoom / 2. - xmoy) |
---|
| 147 | fb = xmoy * (pi_d - xmoy) |
---|
[524] | 148 | |
---|
[2218] | 149 | IF (200. * fb < - fa) THEN |
---|
| 150 | fxm = - 1. |
---|
| 151 | ELSE IF (200. * fb < fa) THEN |
---|
| 152 | fxm = 1. |
---|
| 153 | ELSE |
---|
| 154 | fxm = TANH(fa / fb) |
---|
| 155 | END IF |
---|
[524] | 156 | |
---|
[2218] | 157 | IF (xmoy == 0.) fxm = 1. |
---|
| 158 | IF (xmoy == pi_d) fxm = -1. |
---|
| 159 | xxpr(i) = beta + (grossismx - beta) * fxm |
---|
| 160 | END DO |
---|
[524] | 161 | |
---|
[2218] | 162 | xxpr(:nmax) = xxpr(2 * nmax:nmax + 1:- 1) |
---|
[524] | 163 | |
---|
[2218] | 164 | Xf(0) = - pi_d |
---|
[524] | 165 | |
---|
[2218] | 166 | DO i=1, 2 * nmax - 1 |
---|
| 167 | Xf(i) = Xf(i-1) + xxpr(i) * (xtild(i) - xtild(i-1)) |
---|
| 168 | END DO |
---|
[524] | 169 | |
---|
[2218] | 170 | Xf(2 * nmax) = pi_d |
---|
[524] | 171 | |
---|
[2218] | 172 | call invert_zoom_x(xf, xtild, Xprimt, rlonm025(:iim), & |
---|
[2228] | 173 | xprimm025(:iim), xuv = - 0.25_k8) |
---|
[2218] | 174 | call invert_zoom_x(xf, xtild, Xprimt, rlonv(:iim), xprimv(:iim), & |
---|
[2228] | 175 | xuv = 0._k8) |
---|
[2218] | 176 | call invert_zoom_x(xf, xtild, Xprimt, rlonu(:iim), xprimu(:iim), & |
---|
[2228] | 177 | xuv = 0.5_k8) |
---|
[2218] | 178 | call invert_zoom_x(xf, xtild, Xprimt, rlonp025(:iim), & |
---|
[2228] | 179 | xprimp025(:iim), xuv = 0.25_k8) |
---|
[2218] | 180 | end if test_grossismx |
---|
[524] | 181 | |
---|
[2218] | 182 | is2 = 0 |
---|
[524] | 183 | |
---|
[2218] | 184 | IF (MINval(rlonm025(:iim)) < - pi - 0.1 & |
---|
| 185 | .or. MAXval(rlonm025(:iim)) > pi + 0.1) THEN |
---|
| 186 | IF (clon <= 0.) THEN |
---|
| 187 | is2 = 1 |
---|
[524] | 188 | |
---|
[2218] | 189 | do while (rlonm025(is2) < - pi .and. is2 < iim) |
---|
| 190 | is2 = is2 + 1 |
---|
| 191 | end do |
---|
[524] | 192 | |
---|
[2218] | 193 | if (rlonm025(is2) < - pi) then |
---|
| 194 | print *, 'Rlonm025 plus petit que - pi !' |
---|
| 195 | STOP 1 |
---|
| 196 | end if |
---|
| 197 | ELSE |
---|
| 198 | is2 = iim |
---|
[524] | 199 | |
---|
[2218] | 200 | do while (rlonm025(is2) > pi .and. is2 > 1) |
---|
| 201 | is2 = is2 - 1 |
---|
| 202 | end do |
---|
[524] | 203 | |
---|
[2218] | 204 | if (rlonm025(is2) > pi) then |
---|
| 205 | print *, 'Rlonm025 plus grand que pi !' |
---|
| 206 | STOP 1 |
---|
| 207 | end if |
---|
| 208 | END IF |
---|
| 209 | END IF |
---|
[524] | 210 | |
---|
[2218] | 211 | call principal_cshift(is2, rlonm025, xprimm025) |
---|
| 212 | call principal_cshift(is2, rlonv, xprimv) |
---|
| 213 | call principal_cshift(is2, rlonu, xprimu) |
---|
| 214 | call principal_cshift(is2, rlonp025, xprimp025) |
---|
[524] | 215 | |
---|
[2218] | 216 | forall (i = 1: iim) d_rlonv(i) = rlonv(i + 1) - rlonv(i) |
---|
| 217 | print *, "Minimum longitude step:", MINval(d_rlonv) * 180. / pi, & |
---|
| 218 | "degrees" |
---|
| 219 | print *, "Maximum longitude step:", MAXval(d_rlonv) * 180. / pi, & |
---|
| 220 | "degrees" |
---|
[524] | 221 | |
---|
[2218] | 222 | ! Check that rlonm025 <= rlonv <= rlonp025 <= rlonu: |
---|
| 223 | DO i = 1, iim + 1 |
---|
| 224 | IF (rlonp025(i) < rlonv(i)) THEN |
---|
| 225 | print *, 'rlonp025(', i, ') = ', rlonp025(i) |
---|
| 226 | print *, "< rlonv(", i, ") = ", rlonv(i) |
---|
| 227 | STOP 1 |
---|
| 228 | END IF |
---|
[524] | 229 | |
---|
[2218] | 230 | IF (rlonv(i) < rlonm025(i)) THEN |
---|
| 231 | print *, 'rlonv(', i, ') = ', rlonv(i) |
---|
| 232 | print *, "< rlonm025(", i, ") = ", rlonm025(i) |
---|
| 233 | STOP 1 |
---|
| 234 | END IF |
---|
[524] | 235 | |
---|
[2218] | 236 | IF (rlonp025(i) > rlonu(i)) THEN |
---|
| 237 | print *, 'rlonp025(', i, ') = ', rlonp025(i) |
---|
| 238 | print *, "> rlonu(", i, ") = ", rlonu(i) |
---|
| 239 | STOP 1 |
---|
| 240 | END IF |
---|
| 241 | END DO |
---|
| 242 | end if test_iim |
---|
[524] | 243 | |
---|
[2218] | 244 | END SUBROUTINE fxhyp |
---|
[524] | 245 | |
---|
[2218] | 246 | end module fxhyp_m |
---|