| 48 |  | !!           spline parameters. | 
| 49 |  | !! | 
| 50 |  | !! @author Charles F. Vardeman II | 
| 51 | < | !! @version $Id: interpolation.F90,v 1.4 2006-04-14 21:49:54 gezelter Exp $ | 
| 51 | > | !! @version $Id: interpolation.F90,v 1.6 2006-04-17 21:49:12 gezelter Exp $ | 
| 52 |  |  | 
| 53 |  |  | 
| 54 | < | module  INTERPOLATION | 
| 54 | > | module interpolation | 
| 55 |  | use definitions | 
| 56 |  | use status | 
| 57 |  | implicit none | 
| 60 |  | character(len = statusMsgSize) :: errMSG | 
| 61 |  |  | 
| 62 |  | type, public :: cubicSpline | 
| 63 | – | private | 
| 63 |  | logical :: isUniform = .false. | 
| 64 |  | integer :: np = 0 | 
| 65 |  | real(kind=dp) :: dx_i | 
| 69 |  |  | 
| 70 |  | public :: newSpline | 
| 71 |  | public :: deleteSpline | 
| 72 | < | public :: lookup_spline | 
| 73 | < | public :: lookup_uniform_spline | 
| 74 | < | public :: lookup_nonuniform_spline | 
| 72 | > | public :: lookupSpline | 
| 73 | > | public :: lookupUniformSpline | 
| 74 | > | public :: lookupNonuniformSpline | 
| 75 | > | public :: lookupUniformSpline1d | 
| 76 |  |  | 
| 77 |  | contains | 
| 78 |  |  | 
| 219 |  | cs%dx_i = 1.0_DP / dx | 
| 220 |  |  | 
| 221 |  | return | 
| 222 | < | end subroutine newSplineWithoutDerivs | 
| 222 | > | end subroutine newSpline | 
| 223 |  |  | 
| 224 |  | subroutine deleteSpline(this) | 
| 225 |  |  | 
| 238 |  |  | 
| 239 |  | end subroutine deleteSpline | 
| 240 |  |  | 
| 241 | < | subroutine lookup_nonuniform_spline(cs, xval, yval) | 
| 241 | > | subroutine lookupNonuniformSpline(cs, xval, yval) | 
| 242 |  |  | 
| 243 |  | !************************************************************************* | 
| 244 |  | ! | 
| 245 | < | ! lookup_nonuniform_spline evaluates a piecewise cubic Hermite interpolant. | 
| 245 | > | ! lookupNonuniformSpline evaluates a piecewise cubic Hermite interpolant. | 
| 246 |  | ! | 
| 247 |  | !  Discussion: | 
| 248 |  | ! | 
| 291 |  | yval = cs%c(1,j) + dx * ( cs%c(2,j) + dx * ( cs%c(3,j) + dx * cs%c(4,j) ) ) | 
| 292 |  |  | 
| 293 |  | return | 
| 294 | < | end subroutine lookup_nonuniform_spline | 
| 294 | > | end subroutine lookupNonuniformSpline | 
| 295 |  |  | 
| 296 | < | subroutine lookup_uniform_spline(cs, xval, yval) | 
| 296 | > | subroutine lookupUniformSpline(cs, xval, yval) | 
| 297 |  |  | 
| 298 |  | !************************************************************************* | 
| 299 |  | ! | 
| 300 | < | ! lookup_uniform_spline evaluates a piecewise cubic Hermite interpolant. | 
| 300 | > | ! lookupUniformSpline evaluates a piecewise cubic Hermite interpolant. | 
| 301 |  | ! | 
| 302 |  | !  Discussion: | 
| 303 |  | ! | 
| 322 |  | type (cubicSpline), intent(in) :: cs | 
| 323 |  | real( kind = DP ), intent(in)  :: xval | 
| 324 |  | real( kind = DP ), intent(out) :: yval | 
| 325 | < | real( kind = DP ) :: dx | 
| 325 | > | real( kind = DP ) :: a, b, c, d, dx | 
| 326 |  | integer :: i, j | 
| 327 |  | ! | 
| 328 |  | !  Find the interval J = [ cs%x(J), cs%x(J+1) ] that contains | 
| 332 |  |  | 
| 333 |  | dx = xval - cs%x(j) | 
| 334 |  |  | 
| 335 | < | yval = cs%c(1,j) + dx * ( cs%c(2,j) + dx * ( cs%c(3,j) + dx * cs%c(4,j) ) ) | 
| 335 | > | a = cs%c(1,j) | 
| 336 | > | b = cs%c(2,j) | 
| 337 | > | c = cs%c(3,j) | 
| 338 | > | d = cs%c(4,j) | 
| 339 | > |  | 
| 340 | > | yval = c + dx * d | 
| 341 | > | yval = b + dx * yval | 
| 342 | > | yval = a + dx * yval | 
| 343 |  |  | 
| 344 |  | return | 
| 345 | < | end subroutine lookup_uniform_spline | 
| 345 | > | end subroutine lookupUniformSpline | 
| 346 |  |  | 
| 347 | < | subroutine lookup_spline(cs, xval, yval) | 
| 347 | > | subroutine lookupUniformSpline1d(cs, xval, yval, dydx) | 
| 348 | > |  | 
| 349 | > | implicit none | 
| 350 |  |  | 
| 351 |  | type (cubicSpline), intent(in) :: cs | 
| 352 | + | real( kind = DP ), intent(in)  :: xval | 
| 353 | + | real( kind = DP ), intent(out) :: yval, dydx | 
| 354 | + | real( kind = DP ) :: a, b, c, d, dx | 
| 355 | + | integer :: i, j | 
| 356 | + |  | 
| 357 | + | !  Find the interval J = [ cs%x(J), cs%x(J+1) ] that contains | 
| 358 | + | !  or is nearest to xval. | 
| 359 | + |  | 
| 360 | + | j = MAX(1, MIN(cs%np, idint((xval-cs%x(1)) * cs%dx_i) + 1)) | 
| 361 | + |  | 
| 362 | + | dx = xval - cs%x(j) | 
| 363 | + |  | 
| 364 | + | a = cs%c(1,j) | 
| 365 | + | b = cs%c(2,j) | 
| 366 | + | c = cs%c(3,j) | 
| 367 | + | d = cs%c(4,j) | 
| 368 | + |  | 
| 369 | + | yval = c + dx * d | 
| 370 | + | yval = b + dx * yval | 
| 371 | + | yval = a + dx * yval | 
| 372 | + |  | 
| 373 | + | dydx = 2.0d0 * c + 3.0d0 * d * dx | 
| 374 | + | dydx = b + dx * dydx | 
| 375 | + |  | 
| 376 | + | return | 
| 377 | + | end subroutine lookupUniformSpline1d | 
| 378 | + |  | 
| 379 | + | subroutine lookupSpline(cs, xval, yval) | 
| 380 | + |  | 
| 381 | + | type (cubicSpline), intent(in) :: cs | 
| 382 |  | real( kind = DP ), intent(inout) :: xval | 
| 383 |  | real( kind = DP ), intent(inout) :: yval | 
| 384 |  |  | 
| 385 |  | if (cs%isUniform) then | 
| 386 | < | call lookup_uniform_spline(cs, xval, yval) | 
| 386 | > | call lookupUniformSpline(cs, xval, yval) | 
| 387 |  | else | 
| 388 | < | call lookup_nonuniform_spline(cs, xval, yval) | 
| 388 | > | call lookupNonuniformSpline(cs, xval, yval) | 
| 389 |  | endif | 
| 390 |  |  | 
| 391 |  | return | 
| 392 | < | end subroutine lookup_spline | 
| 392 | > | end subroutine lookupSpline | 
| 393 |  |  | 
| 394 | < | end module INTERPOLATION | 
| 394 | > | end module interpolation |