cmaps.f90 Source File


Source Code

! kippy - Kippenhahn diagram viewer
! Copyright (C) 2026 the kippy authors (see AUTHORS)
!
! This file is part of kippy.
!
! kippy is free software: you can redistribute it and/or modify
! it under the terms of the GNU Lesser General Public License as
! published by the Free Software Foundation, either version 3 of the
! License, or (at your option) any later version.
!
! kippy is distributed in the hope that it will be useful, but WITHOUT
! ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
! FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
! License for more details.
!
! You should have received a copy of the GNU Lesser General Public
! License along with kippy. If not, see <https://www.gnu.org/licenses/>.

! cmaps.f90 -- colour-field colormaps
module cmaps
   !! Colormaps of colour fields.
   !!
   !! `teal`, `blue`, `gray` analytic; rest sampled from matplotlib 3.10.8 at `NANCHOR` anchors
   !! (`cmap(linspace(0, 1, 33))`, 4 decimals), linearly interpolated to within 6/255. `Greys` to
   !! `Oranges` and `RdBu` are ColorBrewer (Cynthia Brewer, Apache-style licence), `coolwarm` is
   !! Kenneth Moreland's diverging map.

   use typedef, only: int32, real64

   implicit none
   private

   integer(int32), parameter :: NANCHOR = 33
      !! Number of anchors per sampled colormap.
   integer(int32), parameter, public :: NCMAPS = 17
      !! Number of colormaps.
   character(len=8), parameter, public :: CMAP_NAMES(NCMAPS) = [character(len=8) :: &
      'teal', 'blue', 'gray', 'viridis', 'plasma', 'inferno', &
      'magma', 'cividis', 'Greys', 'Blues', 'Greens', 'Reds', &
      'Purples', 'Oranges', 'coolwarm', 'RdBu', 'turbo']
      !! Colormap names as `cmap` command takes them (docs/commands.md).

   real(real64), parameter :: VIRIDIS(3, NANCHOR) = reshape([ &
      0.2670d0, 0.0049d0, 0.3294d0, 0.2770d0, 0.0503d0, 0.3757d0, 0.2823d0, 0.0950d0, 0.4173d0, &
      0.2829d0, 0.1359d0, 0.4534d0, 0.2788d0, 0.1755d0, 0.4834d0, 0.2706d0, 0.2141d0, 0.5071d0, &
      0.2590d0, 0.2515d0, 0.5247d0, 0.2450d0, 0.2877d0, 0.5373d0, 0.2297d0, 0.3224d0, 0.5457d0, &
      0.2143d0, 0.3556d0, 0.5512d0, 0.1994d0, 0.3876d0, 0.5546d0, 0.1856d0, 0.4186d0, 0.5568d0, &
      0.1727d0, 0.4488d0, 0.5579d0, 0.1607d0, 0.4785d0, 0.5581d0, 0.1490d0, 0.5081d0, 0.5573d0, &
      0.1378d0, 0.5375d0, 0.5549d0, 0.1276d0, 0.5669d0, 0.5506d0, 0.1206d0, 0.5964d0, 0.5436d0, &
      0.1206d0, 0.6258d0, 0.5335d0, 0.1323d0, 0.6550d0, 0.5197d0, 0.1579d0, 0.6838d0, 0.5017d0, &
      0.1966d0, 0.7118d0, 0.4792d0, 0.2461d0, 0.7389d0, 0.4520d0, 0.3041d0, 0.7647d0, 0.4199d0, &
      0.3692d0, 0.7889d0, 0.3829d0, 0.4401d0, 0.8111d0, 0.3410d0, 0.5160d0, 0.8312d0, 0.2943d0, &
      0.5958d0, 0.8487d0, 0.2433d0, 0.6785d0, 0.8637d0, 0.1895d0, 0.7624d0, 0.8764d0, 0.1371d0, &
      0.8456d0, 0.8873d0, 0.0997d0, 0.9261d0, 0.8973d0, 0.1041d0, 0.9932d0, 0.9062d0, 0.1439d0], [3, NANCHOR])
      !! Anchors of matplotlib `viridis`, RGB in [0, 1].

   real(real64), parameter :: PLASMA(3, NANCHOR) = reshape([ &
      0.0504d0, 0.0298d0, 0.5280d0, 0.1324d0, 0.0223d0, 0.5633d0, 0.1934d0, 0.0184d0, 0.5903d0, &
      0.2480d0, 0.0144d0, 0.6129d0, 0.2999d0, 0.0096d0, 0.6316d0, 0.3502d0, 0.0044d0, 0.6463d0, &
      0.3994d0, 0.0009d0, 0.6561d0, 0.4477d0, 0.0021d0, 0.6602d0, 0.4949d0, 0.0120d0, 0.6579d0, &
      0.5406d0, 0.0350d0, 0.6486d0, 0.5844d0, 0.0686d0, 0.6328d0, 0.6260d0, 0.1033d0, 0.6113d0, &
      0.6651d0, 0.1386d0, 0.5856d0, 0.7018d0, 0.1740d0, 0.5573d0, 0.7360d0, 0.2094d0, 0.5279d0, &
      0.7681d0, 0.2448d0, 0.4985d0, 0.7982d0, 0.2802d0, 0.4695d0, 0.8266d0, 0.3157d0, 0.4413d0, &
      0.8533d0, 0.3516d0, 0.4137d0, 0.8784d0, 0.3879d0, 0.3866d0, 0.9018d0, 0.4251d0, 0.3597d0, &
      0.9233d0, 0.4633d0, 0.3328d0, 0.9426d0, 0.5026d0, 0.3058d0, 0.9594d0, 0.5434d0, 0.2787d0, &
      0.9734d0, 0.5858d0, 0.2515d0, 0.9842d0, 0.6297d0, 0.2246d0, 0.9914d0, 0.6754d0, 0.1985d0, &
      0.9945d0, 0.7227d0, 0.1744d0, 0.9930d0, 0.7717d0, 0.1548d0, 0.9865d0, 0.8224d0, 0.1436d0, &
      0.9744d0, 0.8746d0, 0.1441d0, 0.9568d0, 0.9282d0, 0.1524d0, 0.9400d0, 0.9752d0, 0.1313d0], [3, NANCHOR])
      !! Anchors of matplotlib `plasma`, RGB in [0, 1].

   real(real64), parameter :: INFERNO(3, NANCHOR) = reshape([ &
      0.0015d0, 0.0005d0, 0.0139d0, 0.0140d0, 0.0112d0, 0.0719d0, 0.0423d0, 0.0281d0, 0.1411d0, &
      0.0820d0, 0.0433d0, 0.2153d0, 0.1293d0, 0.0473d0, 0.2908d0, 0.1834d0, 0.0403d0, 0.3550d0, &
      0.2383d0, 0.0366d0, 0.3964d0, 0.2908d0, 0.0456d0, 0.4186d0, 0.3415d0, 0.0623d0, 0.4294d0, &
      0.3915d0, 0.0809d0, 0.4331d0, 0.4412d0, 0.0993d0, 0.4316d0, 0.4910d0, 0.1172d0, 0.4256d0, &
      0.5409d0, 0.1347d0, 0.4151d0, 0.5907d0, 0.1526d0, 0.4003d0, 0.6401d0, 0.1714d0, 0.3811d0, &
      0.6887d0, 0.1922d0, 0.3576d0, 0.7357d0, 0.2159d0, 0.3302d0, 0.7805d0, 0.2433d0, 0.2995d0, &
      0.8224d0, 0.2752d0, 0.2661d0, 0.8605d0, 0.3119d0, 0.2306d0, 0.8943d0, 0.3534d0, 0.1936d0, &
      0.9232d0, 0.3994d0, 0.1552d0, 0.9470d0, 0.4492d0, 0.1153d0, 0.9654d0, 0.5022d0, 0.0739d0, &
      0.9784d0, 0.5579d0, 0.0349d0, 0.9860d0, 0.6158d0, 0.0256d0, 0.9879d0, 0.6753d0, 0.0653d0, &
      0.9841d0, 0.7361d0, 0.1295d0, 0.9746d0, 0.7977d0, 0.2063d0, 0.9606d0, 0.8591d0, 0.2980d0, &
      0.9476d0, 0.9174d0, 0.4107d0, 0.9545d0, 0.9659d0, 0.5404d0, 0.9884d0, 0.9984d0, 0.6449d0], [3, NANCHOR])
      !! Anchors of matplotlib `inferno`, RGB in [0, 1].

   real(real64), parameter :: MAGMA(3, NANCHOR) = reshape([ &
      0.0015d0, 0.0005d0, 0.0139d0, 0.0137d0, 0.0118d0, 0.0687d0, 0.0396d0, 0.0311d0, 0.1335d0, &
      0.0743d0, 0.0520d0, 0.2027d0, 0.1131d0, 0.0655d0, 0.2768d0, 0.1590d0, 0.0684d0, 0.3527d0, &
      0.2117d0, 0.0620d0, 0.4186d0, 0.2654d0, 0.0602d0, 0.4618d0, 0.3167d0, 0.0717d0, 0.4854d0, &
      0.3660d0, 0.0903d0, 0.4980d0, 0.4147d0, 0.1104d0, 0.5047d0, 0.4635d0, 0.1299d0, 0.5077d0, &
      0.5128d0, 0.1482d0, 0.5076d0, 0.5629d0, 0.1654d0, 0.5047d0, 0.6136d0, 0.1818d0, 0.4985d0, &
      0.6649d0, 0.1981d0, 0.4888d0, 0.7164d0, 0.2150d0, 0.4753d0, 0.7674d0, 0.2337d0, 0.4578d0, &
      0.8169d0, 0.2559d0, 0.4365d0, 0.8633d0, 0.2837d0, 0.4124d0, 0.9043d0, 0.3196d0, 0.3881d0, &
      0.9372d0, 0.3649d0, 0.3686d0, 0.9609d0, 0.4183d0, 0.3596d0, 0.9767d0, 0.4762d0, 0.3645d0, &
      0.9867d0, 0.5356d0, 0.3822d0, 0.9928d0, 0.5949d0, 0.4103d0, 0.9961d0, 0.6537d0, 0.4462d0, &
      0.9973d0, 0.7118d0, 0.4882d0, 0.9969d0, 0.7696d0, 0.5349d0, 0.9951d0, 0.8271d0, 0.5857d0, &
      0.9924d0, 0.8843d0, 0.6401d0, 0.9894d0, 0.9415d0, 0.6975d0, 0.9871d0, 0.9914d0, 0.7495d0], [3, NANCHOR])
      !! Anchors of matplotlib `magma`, RGB in [0, 1].

   real(real64), parameter :: CIVIDIS(3, NANCHOR) = reshape([ &
      0.0000d0, 0.1351d0, 0.3048d0, 0.0000d0, 0.1579d0, 0.3575d0, 0.0000d0, 0.1788d0, 0.4148d0, &
      0.0179d0, 0.1985d0, 0.4412d0, 0.1034d0, 0.2204d0, 0.4358d0, 0.1543d0, 0.2425d0, 0.4301d0, &
      0.1951d0, 0.2644d0, 0.4259d0, 0.2309d0, 0.2861d0, 0.4235d0, 0.2637d0, 0.3078d0, 0.4228d0, &
      0.2947d0, 0.3295d0, 0.4237d0, 0.3242d0, 0.3513d0, 0.4263d0, 0.3529d0, 0.3732d0, 0.4302d0, &
      0.3808d0, 0.3952d0, 0.4357d0, 0.4082d0, 0.4174d0, 0.4426d0, 0.4352d0, 0.4398d0, 0.4511d0, &
      0.4616d0, 0.4624d0, 0.4620d0, 0.4887d0, 0.4853d0, 0.4710d0, 0.5179d0, 0.5085d0, 0.4727d0, &
      0.5478d0, 0.5319d0, 0.4717d0, 0.5782d0, 0.5557d0, 0.4687d0, 0.6091d0, 0.5798d0, 0.4636d0, &
      0.6404d0, 0.6044d0, 0.4568d0, 0.6720d0, 0.6293d0, 0.4480d0, 0.7040d0, 0.6547d0, 0.4371d0, &
      0.7365d0, 0.6806d0, 0.4240d0, 0.7694d0, 0.7070d0, 0.4085d0, 0.8027d0, 0.7340d0, 0.3902d0, &
      0.8364d0, 0.7615d0, 0.3687d0, 0.8707d0, 0.7896d0, 0.3433d0, 0.9056d0, 0.8183d0, 0.3129d0, &
      0.9411d0, 0.8475d0, 0.2758d0, 0.9778d0, 0.8773d0, 0.2280d0, 0.9957d0, 0.9093d0, 0.2178d0], [3, NANCHOR])
      !! Anchors of matplotlib `cividis`, RGB in [0, 1].

   real(real64), parameter :: GREYS(3, NANCHOR) = reshape([ &
      1.0000d0, 1.0000d0, 1.0000d0, 0.9852d0, 0.9852d0, 0.9852d0, 0.9705d0, 0.9705d0, 0.9705d0, &
      0.9557d0, 0.9557d0, 0.9557d0, 0.9408d0, 0.9408d0, 0.9408d0, 0.9182d0, 0.9182d0, 0.9182d0, &
      0.8955d0, 0.8955d0, 0.8955d0, 0.8729d0, 0.8729d0, 0.8729d0, 0.8501d0, 0.8501d0, 0.8501d0, &
      0.8226d0, 0.8226d0, 0.8226d0, 0.7950d0, 0.7950d0, 0.7950d0, 0.7674d0, 0.7674d0, 0.7674d0, &
      0.7394d0, 0.7394d0, 0.7394d0, 0.7010d0, 0.7010d0, 0.7010d0, 0.6626d0, 0.6626d0, 0.6626d0, &
      0.6242d0, 0.6242d0, 0.6242d0, 0.5861d0, 0.5861d0, 0.5861d0, 0.5516d0, 0.5516d0, 0.5516d0, &
      0.5172d0, 0.5172d0, 0.5172d0, 0.4827d0, 0.4827d0, 0.4827d0, 0.4484d0, 0.4484d0, 0.4484d0, &
      0.4160d0, 0.4160d0, 0.4160d0, 0.3835d0, 0.3835d0, 0.3835d0, 0.3510d0, 0.3510d0, 0.3510d0, &
      0.3174d0, 0.3174d0, 0.3174d0, 0.2731d0, 0.2731d0, 0.2731d0, 0.2288d0, 0.2288d0, 0.2288d0, &
      0.1845d0, 0.1845d0, 0.1845d0, 0.1411d0, 0.1411d0, 0.1411d0, 0.1047d0, 0.1047d0, 0.1047d0, &
      0.0683d0, 0.0683d0, 0.0683d0, 0.0319d0, 0.0319d0, 0.0319d0, 0.0000d0, 0.0000d0, 0.0000d0], [3, NANCHOR])
      !! Anchors of ColorBrewer `Greys`, RGB in [0, 1].

   real(real64), parameter :: BLUES(3, NANCHOR) = reshape([ &
      0.9686d0, 0.9843d0, 1.0000d0, 0.9440d0, 0.9686d0, 0.9921d0, 0.9194d0, 0.9528d0, 0.9843d0, &
      0.8948d0, 0.9371d0, 0.9764d0, 0.8702d0, 0.9213d0, 0.9685d0, 0.8466d0, 0.9056d0, 0.9606d0, &
      0.8230d0, 0.8898d0, 0.9528d0, 0.7994d0, 0.8741d0, 0.9449d0, 0.7752d0, 0.8583d0, 0.9368d0, &
      0.7359d0, 0.8416d0, 0.9230d0, 0.6965d0, 0.8248d0, 0.9093d0, 0.6571d0, 0.8081d0, 0.8955d0, &
      0.6173d0, 0.7909d0, 0.8818d0, 0.5671d0, 0.7633d0, 0.8710d0, 0.5169d0, 0.7357d0, 0.8602d0, &
      0.4667d0, 0.7082d0, 0.8494d0, 0.4171d0, 0.6806d0, 0.8382d0, 0.3767d0, 0.6531d0, 0.8225d0, &
      0.3364d0, 0.6255d0, 0.8067d0, 0.2960d0, 0.5980d0, 0.7910d0, 0.2563d0, 0.5700d0, 0.7752d0, &
      0.2238d0, 0.5375d0, 0.7584d0, 0.1913d0, 0.5051d0, 0.7417d0, 0.1588d0, 0.4726d0, 0.7250d0, &
      0.1271d0, 0.4402d0, 0.7075d0, 0.1025d0, 0.4087d0, 0.6829d0, 0.0779d0, 0.3772d0, 0.6583d0, &
      0.0533d0, 0.3457d0, 0.6337d0, 0.0314d0, 0.3141d0, 0.6065d0, 0.0314d0, 0.2816d0, 0.5583d0, &
      0.0314d0, 0.2491d0, 0.5100d0, 0.0314d0, 0.2167d0, 0.4618d0, 0.0314d0, 0.1882d0, 0.4196d0], [3, NANCHOR])
      !! Anchors of ColorBrewer `Blues`, RGB in [0, 1].

   real(real64), parameter :: GREENS(3, NANCHOR) = reshape([ &
      0.9686d0, 0.9882d0, 0.9608d0, 0.9509d0, 0.9813d0, 0.9401d0, 0.9332d0, 0.9745d0, 0.9194d0, &
      0.9155d0, 0.9676d0, 0.8988d0, 0.8976d0, 0.9606d0, 0.8779d0, 0.8681d0, 0.9488d0, 0.8464d0, &
      0.8385d0, 0.9370d0, 0.8149d0, 0.8090d0, 0.9252d0, 0.7835d0, 0.7792d0, 0.9132d0, 0.7518d0, &
      0.7418d0, 0.8975d0, 0.7154d0, 0.7044d0, 0.8817d0, 0.6790d0, 0.6670d0, 0.8660d0, 0.6426d0, &
      0.6293d0, 0.8500d0, 0.6061d0, 0.5850d0, 0.8293d0, 0.5697d0, 0.5407d0, 0.8087d0, 0.5333d0, &
      0.4964d0, 0.7880d0, 0.4969d0, 0.4518d0, 0.7671d0, 0.4612d0, 0.4016d0, 0.7425d0, 0.4366d0, &
      0.3514d0, 0.7179d0, 0.4120d0, 0.3012d0, 0.6933d0, 0.3874d0, 0.2526d0, 0.6681d0, 0.3629d0, &
      0.2231d0, 0.6366d0, 0.3392d0, 0.1935d0, 0.6051d0, 0.3156d0, 0.1640d0, 0.5736d0, 0.2920d0, &
      0.1340d0, 0.5423d0, 0.2683d0, 0.0996d0, 0.5128d0, 0.2437d0, 0.0651d0, 0.4833d0, 0.2191d0, &
      0.0307d0, 0.4537d0, 0.1945d0, 0.0000d0, 0.4230d0, 0.1707d0, 0.0000d0, 0.3827d0, 0.1540d0, &
      0.0000d0, 0.3423d0, 0.1373d0, 0.0000d0, 0.3020d0, 0.1205d0, 0.0000d0, 0.2667d0, 0.1059d0], [3, NANCHOR])
      !! Anchors of ColorBrewer `Greens`, RGB in [0, 1].

   real(real64), parameter :: REDS(3, NANCHOR) = reshape([ &
      1.0000d0, 0.9608d0, 0.9412d0, 0.9990d0, 0.9401d0, 0.9116d0, 0.9980d0, 0.9194d0, 0.8821d0, &
      0.9970d0, 0.8988d0, 0.8526d0, 0.9960d0, 0.8779d0, 0.8228d0, 0.9941d0, 0.8414d0, 0.7745d0, &
      0.9921d0, 0.8050d0, 0.7263d0, 0.9901d0, 0.7686d0, 0.6781d0, 0.9882d0, 0.7321d0, 0.6299d0, &
      0.9882d0, 0.6917d0, 0.5837d0, 0.9882d0, 0.6514d0, 0.5374d0, 0.9882d0, 0.6110d0, 0.4911d0, &
      0.9882d0, 0.5707d0, 0.4452d0, 0.9872d0, 0.5313d0, 0.4058d0, 0.9862d0, 0.4920d0, 0.3665d0, &
      0.9852d0, 0.4526d0, 0.3271d0, 0.9836d0, 0.4128d0, 0.2884d0, 0.9718d0, 0.3665d0, 0.2588d0, &
      0.9600d0, 0.3203d0, 0.2293d0, 0.9481d0, 0.2740d0, 0.1998d0, 0.9345d0, 0.2287d0, 0.1714d0, &
      0.8991d0, 0.1942d0, 0.1566d0, 0.8636d0, 0.1598d0, 0.1419d0, 0.8282d0, 0.1253d0, 0.1271d0, &
      0.7926d0, 0.0933d0, 0.1130d0, 0.7552d0, 0.0844d0, 0.1051d0, 0.7178d0, 0.0756d0, 0.0972d0, &
      0.6804d0, 0.0667d0, 0.0894d0, 0.6404d0, 0.0572d0, 0.0815d0, 0.5794d0, 0.0424d0, 0.0736d0, &
      0.5183d0, 0.0277d0, 0.0657d0, 0.4573d0, 0.0129d0, 0.0579d0, 0.4039d0, 0.0000d0, 0.0510d0], [3, NANCHOR])
      !! Anchors of ColorBrewer `Reds`, RGB in [0, 1].

   real(real64), parameter :: PURPLES(3, NANCHOR) = reshape([ &
      0.9882d0, 0.9843d0, 0.9922d0, 0.9754d0, 0.9705d0, 0.9843d0, 0.9626d0, 0.9568d0, 0.9764d0, &
      0.9499d0, 0.9430d0, 0.9685d0, 0.9369d0, 0.9291d0, 0.9606d0, 0.9163d0, 0.9104d0, 0.9508d0, &
      0.8956d0, 0.8917d0, 0.9409d0, 0.8749d0, 0.8730d0, 0.9311d0, 0.8540d0, 0.8540d0, 0.9211d0, &
      0.8245d0, 0.8255d0, 0.9063d0, 0.7949d0, 0.7969d0, 0.8916d0, 0.7654d0, 0.7684d0, 0.8768d0, &
      0.7359d0, 0.7396d0, 0.8618d0, 0.7063d0, 0.7051d0, 0.8421d0, 0.6768d0, 0.6707d0, 0.8225d0, &
      0.6473d0, 0.6362d0, 0.8028d0, 0.6178d0, 0.6021d0, 0.7835d0, 0.5882d0, 0.5736d0, 0.7697d0, &
      0.5587d0, 0.5451d0, 0.7559d0, 0.5292d0, 0.5165d0, 0.7421d0, 0.5003d0, 0.4868d0, 0.7276d0, &
      0.4786d0, 0.4435d0, 0.7050d0, 0.4570d0, 0.4002d0, 0.6824d0, 0.4353d0, 0.3569d0, 0.6597d0, &
      0.4137d0, 0.3138d0, 0.6374d0, 0.3920d0, 0.2724d0, 0.6177d0, 0.3703d0, 0.2311d0, 0.5980d0, &
      0.3487d0, 0.1898d0, 0.5783d0, 0.3272d0, 0.1487d0, 0.5588d0, 0.3065d0, 0.1104d0, 0.5411d0, &
      0.2858d0, 0.0720d0, 0.5234d0, 0.2651d0, 0.0336d0, 0.5057d0, 0.2471d0, 0.0000d0, 0.4902d0], [3, NANCHOR])
      !! Anchors of ColorBrewer `Purples`, RGB in [0, 1].

   real(real64), parameter :: ORANGES(3, NANCHOR) = reshape([ &
      1.0000d0, 0.9608d0, 0.9216d0, 0.9990d0, 0.9460d0, 0.8930d0, 0.9980d0, 0.9313d0, 0.8645d0, &
      0.9970d0, 0.9165d0, 0.8359d0, 0.9961d0, 0.9016d0, 0.8072d0, 0.9951d0, 0.8800d0, 0.7639d0, &
      0.9941d0, 0.8583d0, 0.7206d0, 0.9931d0, 0.8367d0, 0.6772d0, 0.9922d0, 0.8146d0, 0.6336d0, &
      0.9922d0, 0.7812d0, 0.5795d0, 0.9922d0, 0.7477d0, 0.5253d0, 0.9922d0, 0.7142d0, 0.4712d0, &
      0.9922d0, 0.6808d0, 0.4174d0, 0.9922d0, 0.6484d0, 0.3712d0, 0.9922d0, 0.6159d0, 0.3249d0, &
      0.9922d0, 0.5834d0, 0.2787d0, 0.9914d0, 0.5507d0, 0.2328d0, 0.9796d0, 0.5153d0, 0.1924d0, &
      0.9678d0, 0.4799d0, 0.1521d0, 0.9560d0, 0.4444d0, 0.1117d0, 0.9433d0, 0.4092d0, 0.0731d0, &
      0.9196d0, 0.3767d0, 0.0554d0, 0.8960d0, 0.3443d0, 0.0377d0, 0.8724d0, 0.3118d0, 0.0200d0, &
      0.8463d0, 0.2807d0, 0.0041d0, 0.7961d0, 0.2630d0, 0.0061d0, 0.7459d0, 0.2453d0, 0.0080d0, &
      0.6957d0, 0.2275d0, 0.0100d0, 0.6468d0, 0.2101d0, 0.0119d0, 0.6084d0, 0.1954d0, 0.0129d0, &
      0.5700d0, 0.1806d0, 0.0138d0, 0.5316d0, 0.1659d0, 0.0148d0, 0.4980d0, 0.1529d0, 0.0157d0], [3, NANCHOR])
      !! Anchors of ColorBrewer `Oranges`, RGB in [0, 1].

   real(real64), parameter :: COOLWARM(3, NANCHOR) = reshape([ &
      0.2298d0, 0.2987d0, 0.7537d0, 0.2664d0, 0.3533d0, 0.8016d0, 0.3042d0, 0.4069d0, 0.8453d0, &
      0.3433d0, 0.4594d0, 0.8841d0, 0.3837d0, 0.5102d0, 0.9178d0, 0.4252d0, 0.5591d0, 0.9461d0, &
      0.4677d0, 0.6056d0, 0.9685d0, 0.5108d0, 0.6494d0, 0.9851d0, 0.5543d0, 0.6901d0, 0.9955d0, &
      0.5978d0, 0.7273d0, 0.9998d0, 0.6408d0, 0.7608d0, 0.9978d0, 0.6831d0, 0.7900d0, 0.9898d0, &
      0.7240d0, 0.8149d0, 0.9757d0, 0.7634d0, 0.8351d0, 0.9557d0, 0.8006d0, 0.8504d0, 0.9300d0, &
      0.8353d0, 0.8605d0, 0.8990d0, 0.8674d0, 0.8644d0, 0.8626d0, 0.8995d0, 0.8475d0, 0.8178d0, &
      0.9256d0, 0.8255d0, 0.7711d0, 0.9455d0, 0.7986d0, 0.7231d0, 0.9595d0, 0.7670d0, 0.6741d0, &
      0.9675d0, 0.7308d0, 0.6247d0, 0.9697d0, 0.6905d0, 0.5751d0, 0.9660d0, 0.6461d0, 0.5259d0, &
      0.9567d0, 0.5980d0, 0.4773d0, 0.9417d0, 0.5464d0, 0.4297d0, 0.9214d0, 0.4914d0, 0.3834d0, &
      0.8959d0, 0.4331d0, 0.3387d0, 0.8654d0, 0.3711d0, 0.2958d0, 0.8302d0, 0.3047d0, 0.2549d0, &
      0.7906d0, 0.2314d0, 0.2162d0, 0.7468d0, 0.1400d0, 0.1800d0, 0.7057d0, 0.0156d0, 0.1502d0], [3, NANCHOR])
      !! Anchors of Moreland's `coolwarm`, RGB in [0, 1].

   real(real64), parameter :: RDBU(3, NANCHOR) = reshape([ &
      0.4039d0, 0.0000d0, 0.1216d0, 0.4962d0, 0.0295d0, 0.1363d0, 0.5885d0, 0.0591d0, 0.1511d0, &
      0.6807d0, 0.0886d0, 0.1659d0, 0.7340d0, 0.1661d0, 0.2026d0, 0.7783d0, 0.2547d0, 0.2444d0, &
      0.8226d0, 0.3433d0, 0.2863d0, 0.8623d0, 0.4295d0, 0.3427d0, 0.8992d0, 0.5144d0, 0.4079d0, &
      0.9361d0, 0.5993d0, 0.4731d0, 0.9617d0, 0.6761d0, 0.5469d0, 0.9728d0, 0.7426d0, 0.6318d0, &
      0.9839d0, 0.8090d0, 0.7167d0, 0.9903d0, 0.8674d0, 0.7952d0, 0.9829d0, 0.9019d0, 0.8542d0, &
      0.9755d0, 0.9363d0, 0.9133d0, 0.9657d0, 0.9672d0, 0.9681d0, 0.9190d0, 0.9451d0, 0.9595d0, &
      0.8722d0, 0.9230d0, 0.9509d0, 0.8255d0, 0.9008d0, 0.9423d0, 0.7518d0, 0.8636d0, 0.9218d0, &
      0.6743d0, 0.8242d0, 0.8997d0, 0.5968d0, 0.7849d0, 0.8775d0, 0.5057d0, 0.7303d0, 0.8478d0, &
      0.4085d0, 0.6687d0, 0.8145d0, 0.3113d0, 0.6072d0, 0.7813d0, 0.2418d0, 0.5488d0, 0.7506d0, &
      0.2000d0, 0.4934d0, 0.7223d0, 0.1582d0, 0.4381d0, 0.6940d0, 0.1186d0, 0.3792d0, 0.6457d0, &
      0.0842d0, 0.3128d0, 0.5534d0, 0.0498d0, 0.2464d0, 0.4611d0, 0.0196d0, 0.1882d0, 0.3804d0], [3, NANCHOR])
      !! Anchors of ColorBrewer `RdBu`, RGB in [0, 1].

   real(real64), parameter :: TURBO(3, NANCHOR) = reshape([ &
      0.1900d0, 0.0718d0, 0.2322d0, 0.2250d0, 0.1635d0, 0.4510d0, 0.2511d0, 0.2524d0, 0.6337d0, &
      0.2682d0, 0.3382d0, 0.7805d0, 0.2763d0, 0.4212d0, 0.8912d0, 0.2754d0, 0.5011d0, 0.9659d0, &
      0.2586d0, 0.5796d0, 0.9988d0, 0.2138d0, 0.6589d0, 0.9796d0, 0.1584d0, 0.7355d0, 0.9231d0, &
      0.1117d0, 0.8057d0, 0.8452d0, 0.0927d0, 0.8655d0, 0.7623d0, 0.1201d0, 0.9119d0, 0.6866d0, &
      0.1966d0, 0.9490d0, 0.5947d0, 0.3051d0, 0.9770d0, 0.4899d0, 0.4278d0, 0.9942d0, 0.3857d0, &
      0.5466d0, 0.9991d0, 0.2958d0, 0.6436d0, 0.9900d0, 0.2336d0, 0.7260d0, 0.9647d0, 0.2064d0, &
      0.8047d0, 0.9245d0, 0.2046d0, 0.8753d0, 0.8727d0, 0.2155d0, 0.9330d0, 0.8124d0, 0.2267d0, &
      0.9732d0, 0.7468d0, 0.2254d0, 0.9931d0, 0.6741d0, 0.2035d0, 0.9959d0, 0.5870d0, 0.1690d0, &
      0.9836d0, 0.4929d0, 0.1285d0, 0.9580d0, 0.3996d0, 0.0883d0, 0.9211d0, 0.3149d0, 0.0548d0, &
      0.8742d0, 0.2453d0, 0.0330d0, 0.8161d0, 0.1846d0, 0.0181d0, 0.7462d0, 0.1310d0, 0.0085d0, &
      0.6645d0, 0.0844d0, 0.0042d0, 0.5710d0, 0.0447d0, 0.0053d0, 0.4796d0, 0.0158d0, 0.0106d0], [3, NANCHOR])
      !! Anchors of matplotlib `turbo`, RGB in [0, 1].

   public :: cmap_rgb

contains

   pure subroutine cmap_rgb(name, t, r, g, b)
      !! Return colour of colormap `name` at `t`.
      !!
      !! `t` clamped to [0, 1], unknown names fall back to `teal`. `_r` reversal is done by
      !! `axes%colormap`, not here.
      ! Arguments
      character(len=*), intent(in) :: name
         !! Colormap name, a `CMAP_NAMES` entry.
      real(real64), intent(in) :: t
         !! Position along map, 0 at low end, 1 at high end.
      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) :: x
      x = min(max(t, 0.d0), 1.d0)
      select case (name)
      case ('blue')                         ! the exact epsnuc gain ramp
         r = 1.d0 - 0.85d0*x; g = r; b = 1.d0
      case ('gray')
         r = 1.d0 - x; g = r; b = r
      case ('viridis')
         call interp(VIRIDIS, x, r, g, b)
      case ('plasma')
         call interp(PLASMA, x, r, g, b)
      case ('inferno')
         call interp(INFERNO, x, r, g, b)
      case ('magma')
         call interp(MAGMA, x, r, g, b)
      case ('cividis')
         call interp(CIVIDIS, x, r, g, b)
      case ('Greys')
         call interp(GREYS, x, r, g, b)
      case ('Blues')
         call interp(BLUES, x, r, g, b)
      case ('Greens')
         call interp(GREENS, x, r, g, b)
      case ('Reds')
         call interp(REDS, x, r, g, b)
      case ('Purples')
         call interp(PURPLES, x, r, g, b)
      case ('Oranges')
         call interp(ORANGES, x, r, g, b)
      case ('coolwarm')
         call interp(COOLWARM, x, r, g, b)
      case ('RdBu')
         call interp(RDBU, x, r, g, b)
      case ('turbo')
         call interp(TURBO, x, r, g, b)
      case default                          ! 'teal': white -> teal-blue
         r = 1.d0 + x*(0.09d0 - 1.d0)
         g = 1.d0 + x*(0.42d0 - 1.d0)
         b = 1.d0 + x*(0.67d0 - 1.d0)
      end select
   end subroutine cmap_rgb

   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

end module cmaps