foresight_palette
foresight_palette, gnuplot color palettes: gray levels (0 to 1) to colors, for images and color boxes.
As gnuplot 6.0 (values checked against its test palette tables): rgbformulae R,G,B (the default 7,5,15: sqrt, cube, sin 2pi) with gnuplot's 37 formulae, a negative number meaning the formula of 1 - gray; defined (v1 c1, ...) interpolating linearly in RGB between colors (#rrggbb or a gnuplot color name) at increasing values (the script's file palettes too, through palette_gradient); gray (gray to the power 1/1.5, gnuplot's gamma); viridis; negative reverses the gray axis; maxcolors N quantizes: band k = floor(gray N) takes the color of gray k / (N - 1). Channels are rounded to 8 bits. color (after gray, say) restores the last palette set by rgbformulae, defined or a name, else the default. cubehelix [start S] [cycles C] [saturation S] (gnuplot's defaults 0.5, -1.5, 1 at each cubehelix): Green's helix, angle 2pi (S/3 + C gray), lightness gray^(1/1.5) (gamma 1.5), amplitude saturation lightness (1 - lightness)/2. Beyond gnuplot, any named palette of foresight_colormaps (batlow, vik, magma, cividis, ..., viridis), matched case-insensitively: a 256-color table, gray g taking its color nint(255 g), so maxcolors N gives the N colors nint(255 k / (N - 1)), Crameri's discrete palettes.
Source: src/lib/foresight_palette.F90
Dependencies
Contents
- palette_object
- named_color
- gnuplot_color
- palette_words
- palette_gradient
- is_default
- rgb
- rgb1
- hsv_rgb
- hex_color
- color_index
- hex_channels
- formula
- abbreviates
Variables
| Name | Type | Attributes | Description |
|---|---|---|---|
PAL_FORMULAE | integer(kind=I4P) | parameter | rgbformulae. |
PAL_DEFINED | integer(kind=I4P) | parameter | defined. |
PAL_GRAY | integer(kind=I4P) | parameter | gray. |
PAL_TABLE | integer(kind=I4P) | parameter | A named palette of foresight_colormaps (viridis, batlow, ...). |
PAL_CUBEHELIX | integer(kind=I4P) | parameter | cubehelix. |
CUBEHELIX_DEFAULT | real(kind=R8P) | parameter | gnuplot's start, cycles, saturation. |
PI | real(kind=R8P) | parameter | Pi. |
COLOR_NAMES_COUNT | integer(kind=I4P) | parameter | gnuplot's predefined colors (show colornames). |
COLOR_NAMES | character(len=17) | parameter | gnuplot 6.0 color names. |
COLOR_VALUES | character(len=6) | parameter | Their RRGGBB values. |
Derived Types
palette_object
Color palette.
Components
| Name | Type | Attributes | Description |
|---|---|---|---|
mode | integer(kind=I4P) | Palette kind. | |
formulae | integer(kind=I4P) | gnuplot rgbformulae, R, G, B. | |
negative | logical | Gray axis reversed. | |
maxcolors | integer(kind=I4P) | Colors of a quantized palette, 0 for continuous. | |
hsv | logical | model HSV: the components are hue, saturation, value. | |
cmy | logical | model CMY: the components are cyan, magenta, yellow. | |
table | integer(kind=I4P) | Named palette (foresight_colormaps index), PAL_TABLE. | |
cubehelix | real(kind=R8P) | cubehelix start, cycles, saturation. | |
gamma | real(kind=R8P) | Gamma of the gray and cubehelix palettes (gamma G). | |
color_mode | integer(kind=I4P) | Mode color restores: the last set by rgbformulae, defined or a name (as gnuplot's last gradient or formulae). | |
positions | real(kind=R8P) | allocatable | defined positions, increasing. |
colors | real(kind=R8P) | allocatable | defined colors (RGB 0..1, position). |
Type-Bound Procedures
| Name | Attributes | Description |
|---|---|---|
is_default | pass(self) | Whether the palette is gnuplot's default. |
rgb | pass(self) | Color of a gray level, 8-bit channels. |
rgb1 | pass(self) | Color of a gray level, channels 0..1. |
Subroutines
named_color
Channels of a palette color, as gnuplot set palette defined: #rrggbb, 0xrrggbb or one of gnuplot's 111 color names (show colornames: red, dark-green, gray90, ..., case sensitive).
Attributes: pure
subroutine named_color(name, c, ok)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
name | character(len=*) | in | Color. | |
c | integer(kind=I4P) | out | Red, green, blue, 0..255. | |
ok | logical | out | Color known. |
Call graph
gnuplot_color
SVG color of a gnuplot color string, as lc rgb "spec": one of gnuplot's 111 color names (show colornames, case sensitive, trailing blanks allowed) as its #rrggbb, black and white kept as names (the themes restyle them); or # or 0x and 1 to 8 hexadecimal digits, read as gnuplot does as the number 0xAARRGGBB (#0f0 is 0x0000f0): #rrggbb, or with an alpha A (0 opaque, 255 transparent) #rrggbbaa, aa = 255 - A.
Attributes: pure
subroutine gnuplot_color(spec, color, ok)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
spec | character(len=*) | in | gnuplot color. | |
color | character(len=:) | out | allocatable | SVG color, empty if not a color. |
ok | logical | out | A color. |
Call graph
palette_words
Update palette from gnuplot set palette words: none (the default), rgbformulae R , G , B (rgb), defined (v c, ...), cubehelix [start S] [cycles C] [saturation S], gray/grey, color, positive, negative, maxcolors N, model RGB, and a palette name of foresight_colormaps (viridis, batlow, ..., case-insensitive); bad is the first word not understood.
subroutine palette_words(words, palette, bad)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
words | character(len=*) | in | Words, blank separated (a defined list one word). | |
palette | type(palette_object) | inout | Palette. | |
bad | character(len=:) | out | allocatable | First word not understood, empty if none. |
Call graph
palette_gradient
Make palette the gradient of colors (RGB 0..1, clipped) at positions, increasing (equal ones make a sharp step), mapped to 0..1, as gnuplot defined and file palettes; bad says why not, empty if done.
Attributes: pure
subroutine palette_gradient(palette, positions, colors, bad)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
palette | type(palette_object) | inout | Palette. | |
positions | real(kind=R8P) | in | Positions. | |
colors | real(kind=R8P) | in | Colors (RGB, position). | |
bad | character(len=:) | out | allocatable | Problem, empty if none. |
Call graph
Functions
is_default
Whether the palette has gnuplot's default colors: rgbformulae 7,5,15, positive (quantized or not).
Attributes: elemental
Returns: logical
function is_default(self) result(yes)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(palette_object) | in | Palette. |
Call graph
rgb
Color of the gray level gray (clamped to 0..1), 8-bit channels (rgb1 rounded).
Attributes: pure
Returns: integer(kind=I4P)
function rgb(self, gray) result(c)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(palette_object) | in | Palette. | |
gray | real(kind=R8P) | in | Gray level. |
Call graph
rgb1
Color of the gray level gray (clamped to 0..1), channels from 0 to 1 (gnuplot's rgb1_from_gray).
Attributes: pure
Returns: real(kind=R8P)
function rgb1(self, gray) result(f)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
self | class(palette_object) | in | Palette. | |
gray | real(kind=R8P) | in | Gray level. |
Call graph
hsv_rgb
Red, green, blue (0..1) of hsv, hue 0..1 (not degrees), as gnuplot's HSV_2_RGB.
Attributes: pure
Returns: real(kind=R8P)
function hsv_rgb(hsv) result(f)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
hsv | real(kind=R8P) | in | Hue, saturation, value. |
Call graph
hex_color
#rrggbb of the 8-bit channels c.
Attributes: pure
Returns: character(len=7)
function hex_color(c) result(hex)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
c | integer(kind=I4P) | in | Red, green, blue. |
Call graph
color_index
Index of gnuplot's color name (trailing blanks allowed), 0 if none: an exact match, else the first name of the table that begins name, as gnuplot's lookup_table_nth (grey75 is grey).
Attributes: pure
Returns: integer(kind=I4P)
function color_index(name) result(k)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
name | character(len=*) | in | Color name. |
Call graph
hex_channels
Channels of rrggbb (0..255, as reals).
Attributes: pure
Returns: real(kind=R8P)
function hex_channels(hex) result(c)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
hex | character(len=6) | in | Hexadecimal color. |
Call graph
formula
gnuplot rgbformula n (-36..36, negative for the formula of 1 - x) at x, clamped to 0..1.
Attributes: pure
Returns: real(kind=R8P)
function formula(n, x) result(f)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
n | integer(kind=I4P) | in | Formula number. | |
x | real(kind=R8P) | in | Gray level. |
Call graph
abbreviates
Whether word is full or an abbreviation of it of shortest characters at least (gnuplot's almost_equals).
Attributes: pure
Returns: logical
function abbreviates(word, full, shortest) result(yes)Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
word | character(len=*) | in | Word read. | |
full | character(len=*) | in | Full keyword. | |
shortest | integer | in | Shortest abbreviation. |