interp Subroutine

private pure subroutine interp(tab, x, r, g, b)

Interpolate sampled-colormap anchors linearly at x.

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in) :: tab(3,NANCHOR)

Anchor colours, RGB in [0, 1].

real(kind=real64), intent(in) :: x

Position along map, in [0, 1].

real(kind=real64), intent(out) :: r

Red, in [0, 1].

real(kind=real64), intent(out) :: g

Green, in [0, 1].

real(kind=real64), intent(out) :: b

Blue, in [0, 1].


Source Code

   pure subroutine interp(tab, x, r, g, b)
      !! Interpolate sampled-colormap anchors linearly at `x`.
      ! Arguments
      real(real64), intent(in) :: tab(3, NANCHOR)
         !! Anchor colours, RGB in [0, 1].
      real(real64), intent(in) :: x
         !! Position along map, in [0, 1].
      real(real64), intent(out) :: r
         !! Red, in [0, 1].
      real(real64), intent(out) :: g
         !! Green, in [0, 1].
      real(real64), intent(out) :: b
         !! Blue, in [0, 1].
      real(real64) :: xx, u
      integer(int32) :: k
      xx = x*real(NANCHOR - 1, real64)
      k = min(int(xx) + 1, NANCHOR - 1)
      u = xx - real(k - 1, real64)
      r = tab(1, k) + u*(tab(1, k + 1) - tab(1, k))
      g = tab(2, k) + u*(tab(2, k + 1) - tab(2, k))
      b = tab(3, k) + u*(tab(3, k + 1) - tab(3, k))
   end subroutine interp