forcolormap Module

The Colormap class and the colormaps_list.


Uses

  • module~~forcolormap~~UsesGraph module~forcolormap forcolormap module~colormap_parameters colormap_parameters module~forcolormap->module~colormap_parameters module~matplotlib_colormaps matplotlib_colormaps module~forcolormap->module~matplotlib_colormaps module~miscellaneous_colormaps miscellaneous_colormaps module~forcolormap->module~miscellaneous_colormaps module~scientific_colour_maps scientific_colour_maps module~forcolormap->module~scientific_colour_maps iso_fortran_env iso_fortran_env module~colormap_parameters->iso_fortran_env module~matplotlib_colormaps->module~colormap_parameters module~miscellaneous_colormaps->module~colormap_parameters module~scientific_colour_maps->module~colormap_parameters

Used by

  • module~~forcolormap~~UsedByGraph module~forcolormap forcolormap program~create create program~create->module~forcolormap program~demo demo program~demo->module~forcolormap program~demo_reverse demo_reverse program~demo_reverse->module~forcolormap program~example1 example1 program~example1->module~forcolormap program~extract extract program~extract->module~forcolormap program~modify modify program~modify->module~forcolormap

Variables

Type Visibility Attributes Name Initial
character(len=*), public, parameter, dimension(6+222+4) :: colormaps_list = [character(colormap_name_length)::miscellaneous_colormaps_list, scientific_colour_maps_list, matplotlib_colormaps_list]

List of built-in colormaps:


Derived Types

type, public ::  Colormap

The Colormap class (attributes are encapsulated):

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
procedure, public :: compute_RGB
procedure, public :: create
procedure, public :: create_bezier
procedure, public :: create_lagrange
procedure, public :: extract
procedure, public :: finalize
procedure, public :: get_RGB
procedure, public :: get_levels
procedure, public :: get_name
procedure, public :: get_zmax
procedure, public :: get_zmin
procedure, public :: load
procedure, public :: print
procedure, public :: reverse
procedure, public :: set
procedure, public :: shift
procedure, private :: check

Functions

private pure function bezier(colors, levels) result(map)

Create colormap from continuous Bezier interpolation of control colors

Arguments

Type IntentOptional Attributes Name
integer, intent(in), dimension(:,:) :: colors
integer, intent(in), optional :: levels

Return Value integer, dimension(:,:), allocatable

private pure function factorial(n) result(result)

Factorial function used for Bezier interpolation

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: n

Return Value integer

private pure function get_levels(self) result(levels)

Arguments

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

Return Value integer

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)

private pure function get_zmax(self) result(zmax)

Arguments

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

Return Value real(kind=wp)

private pure function get_zmin(self) result(zmin)

Arguments

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

Return Value real(kind=wp)

private pure function lagrange(colors, levels) result(map)

Create colormap from Lagrange interpolation of control colors

Arguments

Type IntentOptional Attributes Name
integer, intent(in), dimension(:,:) :: colors
integer, intent(in), optional :: levels

Return Value integer, dimension(:,:), allocatable

private pure function lagrange_poly(t, n) result(B)

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: t
integer, intent(in) :: n

order + 1

Return Value real(kind=wp), allocatable, (:)

private pure function scale_real_int(real_array, a, b) result(int_scaled_array)

Scale the input real array to the integer RGB range [a, b]

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: real_array
integer, intent(in) :: a
integer, intent(in) :: b

Return Value integer, dimension(size(real_array))

private pure function scale_real_real(real_array, a, b) result(real_scaled_array)

Normalize the input real array to the range [0, 1]

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: real_array
real(kind=wp), intent(in) :: a
real(kind=wp), intent(in) :: b

Return Value real(kind=wp), dimension(size(real_array))


Subroutines

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

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

Most of the time you will just give z to obtain RGB values:

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

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

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

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

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

Extracts colors from the colormap based on specified number of levels (nl)

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

private pure subroutine finalize(self)

A finalizer procedure for memory cleanup:

Arguments

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

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

But you can also obtain RGB by giving directly a level number:

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

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

Load a .txt colormap with RGB integers separated by spaces on each line. Remark: if no path is indicated in filename, the .txt must be present at the root of the fpm project of the user.

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

private impure subroutine print(self)

Useful for testing and debugging:

Arguments

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

private pure subroutine reverse(self, name)

Reverse the colormap

Arguments

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

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

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

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