Colormap Derived Type

type, public :: Colormap


Components

Type Visibility Attributes Name Initial
integer, private :: levels
integer, private, dimension(:, :), allocatable :: map
character(len=colormap_name_length), private :: name
real(kind=wp), private :: zmax
real(kind=wp), private :: zmin

Type-Bound Procedures

procedure, public :: colorbar => write_ppm_colorbar

  • private impure subroutine write_ppm_colorbar(self, filename, width, height, encoding)

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(inout) :: self
    character(len=*), intent(in) :: filename
    integer, intent(in), optional :: width
    integer, intent(in), optional :: height
    character(len=*), intent(in), optional :: encoding

procedure, public :: compute_RGB

  • private pure subroutine compute_RGB(self, z, red, green, blue)

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(inout) :: self
    real(kind=wp), intent(in) :: z
    integer, intent(out) :: red
    integer, intent(out) :: green
    integer, intent(out) :: blue

procedure, public :: create

  • private pure subroutine create(self, name, zmin, zmax, map, reverse)

    You can create a custom colormap from a "map" array.

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(inout) :: self
    character(len=*), intent(in) :: name
    real(kind=wp), intent(in) :: zmin
    real(kind=wp), intent(in) :: zmax
    integer, intent(in), dimension(:, :) :: map
    logical, intent(in), optional :: reverse

procedure, public :: create_bezier

  • private pure subroutine create_bezier(self, name, zmin, zmax, colors, levels, reverse)

    You can create a custom colormap using Bezier interpolation:

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(inout) :: self
    character(len=*), intent(in) :: name
    real(kind=wp), intent(in) :: zmin
    real(kind=wp), intent(in) :: zmax
    integer, intent(in), dimension(:, :) :: colors
    integer, intent(in) :: levels
    logical, intent(in), optional :: reverse

procedure, public :: create_lagrange

  • private pure subroutine create_lagrange(self, name, zmin, zmax, colors, levels, reverse)

    You can create a custom colormap using Lagrange interpolation:

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(inout) :: self
    character(len=*), intent(in) :: name
    real(kind=wp), intent(in) :: zmin
    real(kind=wp), intent(in) :: zmax
    integer, intent(in), dimension(:, :) :: colors
    integer, intent(in) :: levels
    logical, intent(in), optional :: reverse

procedure, public :: extract

  • private pure subroutine extract(self, extractedLevels, name, zmin, zmax, reverse)

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(inout) :: self
    integer, intent(in) :: extractedLevels
    character(len=*), intent(in), optional :: name
    real(kind=wp), intent(in), optional :: zmin
    real(kind=wp), intent(in), optional :: zmax
    logical, intent(in), optional :: reverse

procedure, public :: finalize

  • private pure subroutine finalize(self)

    A finalizer procedure for memory cleanup:

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(inout) :: self

procedure, public :: get_RGB

  • private pure subroutine get_RGB(self, level, red, green, blue)

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(inout) :: self
    integer, intent(in) :: level
    integer, intent(out) :: red
    integer, intent(out) :: green
    integer, intent(out) :: blue

procedure, public :: get_levels

  • private pure function get_levels(self) result(levels)

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(in) :: self

    Return Value integer

procedure, public :: get_name

  • private pure function get_name(self) result(name)

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(in) :: self

    Return Value character(len=colormap_name_length)

procedure, public :: get_zmax

  • private pure function get_zmax(self) result(zmax)

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(in) :: self

    Return Value real(kind=wp)

procedure, public :: get_zmin

  • private pure function get_zmin(self) result(zmin)

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(in) :: self

    Return Value real(kind=wp)

procedure, public :: load

  • private impure subroutine load(self, filename, zmin, zmax, reverse)

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(inout) :: self
    character(len=*), intent(in) :: filename
    real(kind=wp), intent(in) :: zmin
    real(kind=wp), intent(in) :: zmax
    logical, intent(in), optional :: reverse

procedure, public :: print

  • private impure subroutine print(self)

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(inout) :: self

procedure, public :: reverse

  • private pure subroutine reverse(self, name)

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(inout) :: self
    character(len=*), intent(in), optional :: name

procedure, public :: set

  • private pure subroutine set(self, name, zmin, zmax, levels, varargs, reverse)

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(inout) :: self
    character(len=*), intent(in) :: name
    real(kind=wp), intent(in) :: zmin
    real(kind=wp), intent(in) :: zmax
    integer, intent(in), optional :: levels
    real(kind=wp), intent(in), optional, dimension(:) :: varargs
    logical, intent(in), optional :: reverse

procedure, public :: shift

  • private pure subroutine shift(self, sh)

    Apply a circular shift to the colormap (left is +, right is -)

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(inout) :: self
    integer, intent(in) :: sh

    The shift

procedure, private :: check

  • private pure subroutine check(self, check_name, check_bounds, check_levels)

    Check validity of the colormap and fix it if necessary

    Arguments

    Type IntentOptional Attributes Name
    class(Colormap), intent(inout) :: self
    logical, intent(in), optional :: check_name
    logical, intent(in), optional :: check_bounds
    logical, intent(in), optional :: check_levels

Source Code

    type, public :: Colormap
        character(colormap_name_length), private :: name
        integer, private  :: levels         ! Number of levels
        real(wp), private :: zmin, zmax     ! z range
        ! An array containing for each level the associated RGB values:
        integer, dimension(:, :), allocatable, private :: map
    contains
        procedure :: set
        procedure :: finalize
        procedure :: create
        procedure :: create_lagrange
        procedure :: create_bezier
        procedure :: load
        procedure :: get_RGB
        procedure :: compute_RGB
        procedure :: get_name
        procedure :: get_levels
        procedure :: get_zmin
        procedure :: get_zmax
        procedure :: print
        procedure :: colorbar => write_ppm_colorbar
        procedure :: reverse
        procedure :: shift
        procedure :: extract
        procedure, private :: check
    end type Colormap