summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgfplots/util/pgfplotscolormap.code.tex
blob: 464f05359fbbf6dc5ec8b43f3873c4070db667cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
%--------------------------------------------
% $Header: /cvsroot/pgfplots/pgfplots/generic/pgfplots/util/pgfplotscolormap.code.tex,v 1.15 2009/07/21 18:18:48 ludewich Exp $
%
% Package pgfplots
%
% Provides a user-friendly interface to create function plots (normal
% plots, semi-logplots and double-logplots).
%
% It is based on Till Tantau's PGF package.
%
% Copyright 2007-2013 by Christian Feuersänger.
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program 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 General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program.  If not, see <http://www.gnu.org/licenses/>.
%
%--------------------------------------------

\input pgfplotscolor.code.tex

\pgfkeyssetvalue{/pgfplots/colormap default colorspace}{auto}

% preset for '/pgfplots/colormap uniform=always
% This is only used for the colormap predefined in this very file.
\def\pgfplots@colormap@uniform@choice{0}%

% This package relies on pgfplots temporary registers and its array
% data structure.

% Internal structure:
% the colormap data structure consists of
% - an array 'pgfpl@cm@#1' of RGB color triples,
% - numbers 'pgfpl@cm@#1@h' and 'pgfpl@cm@#1@invh' for the mesh width
%   and inverse mesh width.

% Creates a new colormap.
%
% #1 : the name of the color map as string (not as macro).
% #2 : a <color specification> as is expected for a shading spec of
% pgf. However, the format allows a little bit more freedom:
% 	- it supports 'rgb255' in addition to pgf,
% 	- the length is not required (defaults to 1cm for the first and to
% 	the last length+h for all others).
% 	- the semicolons can be omitted.
%
% Example:
% \pgfplotscreatecolormap{my map}{rgb(0cm)=(1,0,0); rgb(1cm)=(0,1,0); rgb255(1.5cm)=(128,5,255); rgb(2cm)=(0,0,1); gray(3cm)=(3);  color(4cm)=(green); }
% \pgfplotscreatecolormap{my map}{color=(green); color=(red); color=(blue); color=(yellow)}
\def\pgfplotscreatecolormap#{\pgfplots@createcolormap}%
\def\pgfplots@createcolormap#1#2{%
	\pgfkeysinterruptkeyfilter
	\edef\pgfplots@createcolormap@name{pgfpl@cm@#1}%
	\expandafter\pgfplotsarraynewempty\expandafter{\pgfplots@createcolormap@name}%
	\pgfplotsapplistXnewempty\pgfplots@createcolormap@X
	%
	% '0' = is not uniform
	% '1' = is uniform
	% '2' = is FORCED to be uniform, i.e. will be reinterpolated
	\ifcase\pgfplots@colormap@uniform@choice\relax
		% colormap uniform=always (due to compatibility requirements)
		\def\b@pgfplotscreatecolormap@isuniform{2}%
	\or
		% colormap uniform=if requested
		\def\b@pgfplotscreatecolormap@isuniform{1}%
	\fi
	\def\pgfplots@createcolormap@MIN{}% To be computed.
	\def\pgfplots@createcolormap@MAX{}% To be computed.
	\def\b@pgfplots@createcolormap@pos@mode{a}% [a]uto or [m]anual
	\pgfplots@createcolormap@initcolorspace
	\let\pgfplots@createcolormap@LAST=\pgfplots@createcolormap@MIN
	% PARSE IT:
	\let\pgfplots@createcolormap@context=\pgfutil@empty
	%%%%%%%%%%%%%%%%%%
	% this does also init @H:
	\pgflibraryfpuifactive{%
		\def\pgfplots@createcolormap@restore@fpu{}%
	}{%
		\def\pgfplots@createcolormap@restore@fpu{\pgfkeys{/pgf/fpu=false}}%
		\pgfkeys{/pgf/fpu=true}%
	}%
	%\edef\pgfplots@loc@TMPa{#2}% XXX this fails for active chars and
	%if key/value options are too special
	\def\pgfplots@loc@TMPa{#2}%
	\expandafter\pgfplots@createcolormap@startloop\pgfplots@loc@TMPa\pgfplots@EOI
	%
	\pgfplots@createcolormap@restore@fpu
	%
	%%%%%%%%%%%%%%%%%%
	%
	\expandafter\pgfplotsarraycheckempty\expandafter{\pgfplots@createcolormap@name}%
	% sanity checking:
	\expandafter\pgfplotsarraysizetomacro\expandafter{\pgfplots@createcolormap@name}\to\pgfplots@loc@TMPa
	\ifcase\pgfplots@loc@TMPa\relax
		\pgfplots@error{Sorry, you need to provide at least two points of a colormap.}%
	\or
		\pgfplots@error{Sorry, you need to provide at least two points of a colormap.}%
	\fi
	% Map the input range [MIN,MAX] linearly to [0,1000]
	\pgfmathfloatsubtract@{\pgfplots@createcolormap@MAX}{\pgfplots@createcolormap@MIN}%
	\let\pgfplots@loc@TMPb=\pgfmathresult
	\pgfmathfloatdivide@{\pgfplotscolormaprange@float}{\pgfplots@loc@TMPb}%
	\let\pgfplots@loc@TMPb=\pgfmathresult
	\pgfmathfloatmultiply@{\pgfplots@loc@TMPb}{\pgfplots@createcolormap@H}%
	\let\pgfplots@loc@TMPd=\pgfmathresult
	\pgfplots@createcolormap@normalize{\pgfmathresult}%
	\expandafter\let\csname\pgfplots@createcolormap@name @h\endcsname=\pgfmathresult
	%
	\pgfmathfloatreciprocal@{\pgfplots@loc@TMPd}%
	\pgfplots@createcolormap@normalize{\pgfmathresult}%
	\expandafter\let\csname\pgfplots@createcolormap@name @invh\endcsname=\pgfmathresult
	%
	% ... and set up the X coordinates if the grid is not uniform:
	\expandafter\pgfplotsarraynewempty\expandafter{\pgfplots@createcolormap@name @X}%
	\if0\b@pgfplotscreatecolormap@isuniform
		% Uncomment the '\iftrue' for testing purposes (to see if a uniform map changes if
		% processed as non-uniform):
%	\iftrue
		\pgfplotsapplistXlet\pgfplots@loc@TMPc=\pgfplots@createcolormap@X
		\expandafter\pgfplotsutilforeachcommasep\expandafter{\pgfplots@loc@TMPc}\as\pgfplots@loc@TMPc{%
			\ifx\pgfplots@loc@TMPc\pgfutil@empty
			\else
				% apply the trafo [MIN,MAX] -> [0,1000] here as well:
				\pgfmathfloatsubtract@{\pgfplots@loc@TMPc}{\pgfplots@createcolormap@MIN}%
				\expandafter\pgfmathfloatmultiply@\expandafter{\pgfmathresult}{\pgfplots@loc@TMPb}%
				\pgfplots@createcolormap@normalize{\pgfmathresult}%
				\expandafter\pgfplotsarraypushback\expandafter{\pgfmathresult}\to{pgfpl@cm@#1@X}%
			\fi
		}%
		%
		\pgfplotscolormapsetadditionalintervalwidth@{#1}%
	\else
		\expandafter\let\csname\pgfplots@createcolormap@name @X@scale@order@z\endcsname=\pgfutil@empty
	\fi
	% clear temporary list:
	\pgfplotsapplistXnewempty\pgfplots@createcolormap@X
	%
	\if m\b@pgfplots@createcolormap@pos@mode
		% Ah - we have manually provided positions!
		% DISABLE the extra interval. You have to enable it explicitly
		% by means of 'colormap access/extra interval width=0.1'
		\expandafter\def\csname\pgfplots@createcolormap@name @X@scale@order@z\endcsname{0}%
	\fi
	%
	\endpgfplotscolornormalizesequence%
	\expandafter\let\csname\pgfplots@createcolormap@name @colspace\endcsname=\pgfplotsretval
	\expandafter\let\csname\pgfplots@createcolormap@name @col@comps\endcsname=\pgfplotsretvalb
	\c@pgf@counta=\expandafter\pgfplotsarraysizeof\expandafter{\pgfplots@createcolormap@name}\relax
	\advance\c@pgf@counta by-1 %
	\expandafter\edef\csname\pgfplots@createcolormap@name @lastindex\endcsname{\the\c@pgf@counta}%
%\pgfplots@colormap@showdebuginfofor{#1}%
	\pgfplots@colormap@LUA@new{#1}%
	\endpgfkeysinterruptkeyfilter
}

\def\pgfplots@createcolormap@normalize#1{%
	\pgfmathfloattofixed{#1}%
	\pgf@xa=\pgfmathresult pt %
	\edef\pgfmathresult{\pgf@sys@tonumber\pgf@xa}% normalize number.
}%

% Allows to customize the width of the additional interval used for
% 'colormap access=piecewise constant'.
%
% #1 colormap name
% #2 the additional interval width for this colormap. Use '0' to disable the additional
% interval. The value is relative to the total width and must be in
% the range 0<=#2<=0.9
\def\pgfplotscolormapsetadditionalintervalwidth#1#2{%
	\edef\pgfplots@loc@TMPd{#2}%
	\def\pgfplots@loc@TMPc{h}%
	\ifx\pgfplots@loc@TMPd\pgfplots@loc@TMPc
		% 'h' means: mesh width:
		\pgfplotscolormapifisuniform{#1}{%
			\expandafter\let\csname pgfpl@cm@#1@X@scale@order@z\endcsname\pgfutil@empty%
		}{%
			\pgfplotscolormapsetadditionalintervalwidth@{#1}%
		}%
	\else
		\pgfmathparse{#2}%
		\pgfplotscolormapifisuniform{#1}{%
			\ifdim\pgfmathresult pt>0pt
				\pgfplots@error{Uniform colormaps support no configuration of the additional interval width for a colormap (although you can use 0 to turn it off). Please use a non-uniform colormap.}%
			\else
				% DISABLE the extra interval!
				\expandafter\def\csname pgfpl@cm@#1@X@scale@order@z\endcsname{0}%
			\fi
		}{%
			\ifdim\pgfmathresult pt>0pt
				\ifdim\pgfmathresult pt>0.9pt
					\pgfplots@error{Expected a number 0< X <= 0.9, not \pgfmathresult}%
				\else
					% compute the 'h'.
					%
					% Note that 's:=#2' is a fraction 0<x<1 of the RESULTING
					% range, i.e. s * 1000 = H where 0<=H<=1000.
					% but H = 1000/(1000+h) * 1000, and we need the 'h'.
					%
					% -> h = 1000/s - 1000.
					%  regarding the '1-#2': I did some mistake in my
					%  computation and that fixed it :-/
					\pgfmathparse{1000/(1-#2)-1000}%
					\expandafter\let\csname pgfpl@cm@#1@h\endcsname=\pgfmathresult
					\expandafter\let\csname pgfpl@cm@#1@invh\endcsname=\pgfutil@empty% unused!
					\pgfplotscolormapsetadditionalintervalwidth@{#1}%
				\fi
			\else
				% DISABLE the extra interval!
				\expandafter\def\csname pgfpl@cm@#1@X@scale@order@z\endcsname{0}%
			\fi
		}%
	\fi
	%
	\ifpgfplots@LUA@supported
		\pgfplotsutil@directlua{%
			pgfplots.texColorMapSetScaleOrderZ("#1", "\csname pgfpl@cm@#1@X@scale@order@z\endcsname")
		}%
	\fi
}%

% see \pgfplotscolormapsetadditionalintervalwidth
\def\pgfplotscolormapsetadditionalintervalwidth@#1{%
	% 'colormap access=piecewise constant' (order 0) requires a
	% special scaling factor. See its consumers for details +
	% documentation
	\pgfmathparse{1000/(1000+\csname pgfpl@cm@#1@h\endcsname)}%
	\expandafter\let\csname pgfpl@cm@#1@X@scale@order@z\endcsname=\pgfmathresult
}%

\def\pgfplots@createcolormap@initcolorspace{%
	\pgfplotscolornormalizesequence[
		colorspace=\pgfkeysvalueof{/pgfplots/colormap default colorspace},
		context message=\pgfplots@createcolormap@context\pgfplots@createcolormap@trace,
	]%
}%
\def\pgfplots@createcolormap@seth[#1]{%
	\def\pgfplots@createcolormap@context{[#1]}%
	\pgfmathparse{#1}%
	\let\pgfplots@createcolormap@H=\pgfmathresult
	% request for a uniform colormap:
	\def\b@pgfplotscreatecolormap@isuniform{3}%
	\pgfplots@createcolormap@
}%

\def\pgfplots@createcolormap@startloop{%
	\pgfutil@ifnextchar[%
		{\pgfplots@createcolormap@seth}%
		{%
			\let\pgfplots@createcolormap@H=\pgfutil@empty
		 	\pgfplots@createcolormap@
		}%
}%
\def\pgfplots@createcolormap@{%
	\pgfutil@ifnextchar\pgfplots@EOI{\pgfutil@gobble}%done!
	{%
		\pgfutil@ifnextchar;{\pgfplots@createcolormap@grabsemicolon}%
		{%
			\pgfutil@ifnextchar,{\pgfplots@createcolormap@grabcomma}%
			{%
				\expandafter\pgfutil@ifnextchar\pgfplots@activesemicolon{\pgfplots@createcolormap@grabsemicolon@active}%
				{%
					\pgfplots@createcolormap@grabnext
				}%
			}%
		}%
	}%
}

% Executes '#1' if there are more tokens and '#2' if not.
\def\pgfplots@createcolormap@ifhasmorecolors#1#2{%
	\pgfutil@ifnextchar\pgfplots@EOI{%
		#2% no more tokens.
	}{%
		\pgfutil@ifnextchar;{\pgfplots@createcolormap@grabsemicolon@hasnext{#1}{#2}}%
		{%
			\pgfutil@ifnextchar,{\pgfplots@createcolormap@grabcomma@hasnext{#1}{#2}}%
			{%
				\expandafter\pgfutil@ifnextchar\pgfplots@activesemicolon{\pgfplots@createcolormap@grabsemicolon@active@hasnext{#1}{#2}}%
				{%
					#1% has more.
				}%
			}%
		}%
	}%
}%

\def\pgfplots@createcolormap@error#1#2\pgfplots@EOI{%
	{%
		\t@pgfplots@toka={#1#2}%
		\t@pgfplots@tokb={#1}%
		\pgfplots@error{Illformed colormap specification: I could not read the substring `\the\t@pgfplots@toka' starting at `\the\t@pgfplots@tokb'\pgfplots@createcolormap@trace}%
	}%
}%

\def\pgfplots@createcolormap@trace{%
	\space(color no \expandafter\pgfplotsarraysizeof\expandafter{\pgfplots@createcolormap@name})
}

\def\pgfplots@createcolormap@grabnext#1={%
	\pgfutil@ifnextchar({\pgfplots@createcolormap@grabnext@round{#1}=}{%
		\pgfutil@ifnextchar\bgroup{\pgfplots@createcolormap@grabnext@curly{#1}=}{%
			\pgfplots@createcolormap@error#1=%
		}%
	}%
}
\def\pgfplots@createcolormap@grabnext@round#1=(#2){%
	\pgfplots@createcolormap@grabnext@@{#1}={#2}%
}%
\def\pgfplots@createcolormap@grabnext@curly#1=#2{%
	\pgfplots@createcolormap@grabnext@@{#1}={#2}%
}%
\def\pgfplots@createcolormap@grabnext@@#1=#2{%
	\pgfutil@in@({#1}%
	\ifpgfutil@in@
		% Ah. We have something like 'color(1cm)' before the equal sign.
		\pgfplots@createcolormap@grabnext@read@pos#1\pgfplots@EOI%
		% now:
		%\pgfplots@loc@TMPa = colorspace
		%\pgfplots@loc@TMPb = position
		%
	\else
		% Ah. we do not have a position, i.e. we have
		%   color=(green)
		% or something like this.
		%
		% this here defines \pgfplots@loc@TMPa to contain the
		% colorspace:
		\pgfkeys@spdef\pgfplots@loc@TMPa{#1}%
		%
		\pgfplots@createcolormap@grabnext@computenextposition
		\let\pgfplots@loc@TMPb=\pgfmathresult% position
	\fi
	\def\pgfplots@loc@TMPc{#2}%
	\pgfplots@createcolormap@grabnext@complete
}%

\def\pgfplots@createcolormap@grabnext@read@pos#1({%
	\pgfkeys@spdef\pgfplots@loc@TMPa{#1}% colorspace
	\pgfplots@createcolormap@grabnext@read@pos@
}%
\def\pgfplots@createcolormap@grabnext@read@pos@#1){%
	\def\pgfplots@loc@TMPb{#1}% position
	\def\b@pgfplots@createcolormap@pos@mode{m}% [m]anual
	\pgfutil@ifnextchar\pgfplots@EOI{%
		% OK
		\pgfplots@gobble@until@EOI
	}{%
		\pgfplots@createcolormap@error#1)%
	}%
}%

%%%%%%%%%%

% Splits '<argument> of <source name>*' into (\pgfplotsretval,
% \pgfplotsretvalb).
%
% The 'of' part is optional. If it is missing, '\pgfplotsretval'
% contains the entire argument and '\pgfplotsretvalb' is the current
% colormap.
%
% Note that '<source name>*' is typically just a colormap name (i.e. without
% '*'), but it _may_ contain key-value lists! They will be returned as-is.
% #1: the string to split
% #2: '1' if '#1' may contain ',' and '0' otherwise
\def\pgfplots@createcolormap@special@split#1#2{%
	\pgfutil@in@{of }{#1}%
	\ifpgfutil@in@
		\pgfplots@createcolormap@special@split@#1\pgfplots@EOI
	\else
		\if1#2\relax
			% do not check it -- commas are allowed here!
			\pgfutil@in@false
		\else
			\pgfutil@in@{,}{#1}%
		\fi
		\ifpgfutil@in@
			% ah - might be something like '5, target pos={1,2,3}'.
			% -> define \pgfplotsretval='5' and
			%  \pgfplotsretvalb='<colormap name>, target pos={1,2,3}':
			%
			\pgfplots@createcolormap@special@split@command#1\pgfplots@EOI
			\t@pgfplots@tokb=\expandafter{\pgfplotsretvalb}%
			\pgfkeysgetvalue{/pgfplots/colormap name}\pgfplotsretvalb
			\edef\pgfplotsretvalb{\pgfplotsretvalb,\the\t@pgfplots@tokb}%
		\else
			\pgfkeys@spdef\pgfplotsretval{#1}%
			\pgfkeysgetvalue{/pgfplots/colormap name}\pgfplotsretvalb
		\fi
	\fi
%\message{Split (#1) --> '\pgfplotsretval', '\pgfplotsretvalb'^^J}%
}%
\def\pgfplots@createcolormap@special@split@#1of #2\pgfplots@EOI{%
	\pgfkeys@spdef\pgfplotsretval{#1}%
	\pgfkeys@spdef\pgfplotsretvalb{#2}%
}
\def\pgfplots@createcolormap@special@split@command#1,#2\pgfplots@EOI{%
	\pgfkeys@spdef\pgfplotsretval{#1}%
	\pgfkeys@spdef\pgfplotsretvalb{#2}%
}

% Output: \pgfplotsretval will be populated with the resulting
% colormap name.
\def\pgfplots@createcolormap@special@ensure@source@cm#1{%
	\edef\pgfplotsretval{#1}%
	\pgfplotscolormapifdefined{#1}{}{%
		% hm... the colormap does not exist? Perhaps someone used
		% style 'colormap/cool'. Try to define it!
		\pgfkeysifdefined{/pgfplots/#1/.@cmd}{%
			\pgfkeysgetvalue{/pgfplots/colormap name}\pgfplots@color@of@colormap@name@old
			\pgfplotsset{#1}%
			\pgfkeysgetvalue{/pgfplots/colormap name}\pgfplotsretval
			\pgfkeyslet{/pgfplots/colormap name}\pgfplots@color@of@colormap@name@old
		}{%
			\pgfplots@error{The argument '#1' is no valid colormap.}%
		}%
	}%
}%

\newif\ifpgfplots@createcolormap@target@pos@includes@limits@min
\newif\ifpgfplots@createcolormap@target@pos@includes@limits@max

% these keys are only evaluated inside of
% \pgfplots@of@colormap@getresult :
\pgfqkeys{/pgfplots/of colormap}{%
	source name/.initial=,
	target pos/.initial=,
	target pos min/.initial=,
	target pos min/insert/.is if=pgfplots@createcolormap@target@pos@includes@limits@min,
	target pos min*/.style={%
		/pgfplots/of colormap/target pos min={#1},
		/pgfplots/of colormap/target pos min/insert=true,
	},%
	target pos max/.initial=,
	target pos max*/.style={%
		/pgfplots/of colormap/target pos max={#1},
		/pgfplots/of colormap/target pos max/insert=true,
	},%
	target pos max/insert/.is if=pgfplots@createcolormap@target@pos@includes@limits@max,
	source pos/.initial=,
	source pos/.set if not empty/.code={%
		\edef\pgfplots@loc@TMPa{#1}%
		\ifx\pgfplots@loc@TMPa\pgfutil@empty
		\else
			\pgfkeyslet{/pgfplots/of colormap/source pos}\pgfplots@loc@TMPa
		\fi
	},
	%
	@define/.code={%
		\pgfplots@error{Please write 'single color' or 'color list' such that pgfplots knows how to interprete values}%
		\let\pgfplotsretval=\pgfutil@empty
	},
	single color/.style={%
		/pgfplots/of colormap/@define/.code={%
			\pgfplots@createcolormap@special@process@single
		},
	},
	color list/.style={%
		/pgfplots/of colormap/@define/.code={%
			\pgfplots@createcolormap@special@process@list%
		},
	},
	color list,
	%
	of colormap/.style={#1},
	%
	% 'color of colormap={#1}' is a style which boils down to
	% '@delegate to@ of colormap={color}{#1}'.
	% The same is true for
	%   colors of colormap
	%   index of colormap
	%   indices of colormap
	%   samples of colormap
	%
	% All use this implementation:
	% #1: how to interprete results. /pgfplots/of colormap/#1 must be
	% a valid key (like 'color').
	% #2: the argument which can be '<source pos> of <source name>' or '<source pos>'.
	% #3: '1' if the source pos may contain ',' and '0' otherwise
	@delegate to@ of colormap/.code args={#1#2#3}{%
		% Convert 'color of colormap={...}' and its variants into
		% 'of colormap={<list of keys>}':
		\pgfplots@createcolormap@special@split{#2}{#3}%
		\edef\pgfplots@loc@TMPa{%
			#1,%
			source pos={\pgfplotsretval},%
			% \pgfplotsretvalb will contain the colormap name
			% --- but it _can_ also contain further key-value pairs!
			% Do not add braces here such that further key-value pairs
			% can be found:
			source name=\pgfplotsretvalb,%
		}%
		\expandafter\pgfkeysalso\expandafter{\pgfplots@loc@TMPa}%
	},
	%
	color/.style={%
		/pgfplots/of colormap/colormap access=map,
		/pgfplots/of colormap/single color,
		/pgfplots/of colormap/source pos/.set if not empty={#1},
	},
	const color/.style={%
		/pgfplots/of colormap/colormap access=piecewise constant,
		/pgfplots/of colormap/single color,
		/pgfplots/of colormap/source pos/.set if not empty={#1},
	},
	index/.style={%
		/pgfplots/of colormap/colormap access=direct,
		/pgfplots/of colormap/single color,
		/pgfplots/of colormap/source pos/.set if not empty={#1},
	},
	colors/.style={%
		/pgfplots/of colormap/colormap access=map,
		/pgfplots/of colormap/color list,
		/pgfplots/of colormap/source pos/.set if not empty={#1},
	},
	samples/.style={%
		/pgfplots/of colormap/colormap access=map,% can be overridden if needed.
		/pgfplots/of colormap/@define/.code={%
			\pgfplots@createcolormap@special@process@list@sampled%
		},
		/pgfplots/of colormap/source pos/.set if not empty={#1},
	},%
	%
	const colors/.style={%
		/pgfplots/of colormap/colormap access=piecewise constant,
		/pgfplots/of colormap/color list,
		/pgfplots/of colormap/source pos/.set if not empty={#1},
	},
	indices/.style={%
		/pgfplots/of colormap/colormap access=direct,
		/pgfplots/of colormap/color list,
		/pgfplots/of colormap/source pos/.set if not empty={#1},
	},
	colormap access/.style={/pgfplots/colormap access={#1}},
	source range/.initial=0:1000,
	%
	sample for/.is choice,
	sample for/default/.code={\def\pgfplots@ofcolorbar@sample@for@choice{m}},
	sample for/const/.code={\def\pgfplots@ofcolorbar@sample@for@choice{c}},
	sample for=default,
	%
	/pgfplots/of colormap/.unknown/.code={%
		\pgfplotsutilifstringequal{#1}{\pgfkeysnovalue}{%
			% This here allows to write 'of colormap={initial}'
			\pgfplotscolormapifdefined{\pgfkeyscurrentname}{%
				\edef\pgfplots@loc@TMPa{%
					\noexpand\pgfkeysalso{%
						/pgfplots/of colormap/source name={\pgfkeyscurrentname},
					}%
				}%
				\pgfplots@loc@TMPa
			}{%
				\pgfplots@error{Unknown key '\pgfkeyscurrentname'. Is this a colormap name? Maybe you need to write \string\pgfplotsset{\pgfkeyscurrentname} first?}%
			}%
		}{%
			\pgfkeysgetvalue{/handlers/.unknown/.@cmd}{\pgfkeys@code}%
			\expandafter\pgfkeys@code\pgfkeyscurrentvalue\pgfeov%
		}%
	},
	%
	% allow something like 'of colormap={colormap/PuBuGn}':
	/pgfplots/of colormap/colormap/.unknown/.code={%
		\edef\pgfplots@loc@TMPa{\noexpand\pgfplotsset{colormap/\pgfkeyscurrentname}}%
		\pgfplots@loc@TMPa
	},%
}
\pgfplotsinvokeforeach{%
	color,% defines 'color of colormap'
	index,% defines 'index of colormap'
	const color,% defines 'const color of colormap'
	samples,% defines 'samples of colormap'
}{%
	\def\pgfplots@glob@TMPa{#1}%
	\ifx\pgfplots@glob@TMPa\pgfutil@empty
	\else
		\pgfkeysdef{/pgfplots/of colormap/#1 of colormap}{%
			\pgfkeysalso{/pgfplots/of colormap/@delegate to@ of colormap={#1}{##1}{0}}%
		}%
	\fi
}%
\pgfplotsinvokeforeach{%
	indices,% defines 'indices of colormap'
	colors,% defines 'colors of colormap'
	const colors,% defines 'const colors of colormap'
}{%
	\def\pgfplots@glob@TMPa{#1}%
	\ifx\pgfplots@glob@TMPa\pgfutil@empty
	\else
		\pgfkeysdef{/pgfplots/of colormap/#1 of colormap}{%
			\pgfkeysalso{/pgfplots/of colormap/@delegate to@ of colormap={#1}{##1}{1}}%
		}%
	\fi
}%

% This is the main implementation of 'of colormap'. It is shared by
% both cycle lists and colormaps.
%
\def\pgfplots@of@colormap@getresult#1{%
	\pgfkeysinterruptkeyfilter
	\pgfqkeys{/pgfplots/of colormap}{%
		% ensure that this here is not inherited from the axis'
		% configuration -- reset it:
		colormap access=map,%
		#1}%
	\pgfkeysgetvalue{/pgfplots/of colormap/source name}\pgfplots@loc@TMPa
	\edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa}%
	\ifx\pgfplots@loc@TMPa\pgfutil@empty
	\else
		\pgfkeyslet{/pgfplots/colormap name}\pgfplots@loc@TMPa
	\fi
	\pgfplots@createcolormap@special@ensure@source@cm{\pgfkeysvalueof{/pgfplots/colormap name}}%
	\pgfkeyslet{/pgfplots/colormap name}\pgfplotsretval
	%
	\pgfqkeys{/pgfplots/of colormap}{@define}%
	\endpgfkeysinterruptkeyfilter
}%


\def\pgfplots@createcolormap@special@process@single@error{%
	\pgfplots@error{Did not find a suitable input source pos in a 'of colormap' specification. Did you forget the 'source pos'? It can be given as 'colors of colormap=(source pos of name)' or 'of colormap=(source pos=...,..)'}%
	\pgfkeyssetvalue{/pgfplots/of colormap/source pos}{0}%
}%
\def\pgfplots@createcolormap@special@process@single@error@comma{%
	\pgfplots@error{Found an unexpected comma in 'source pos=\pgfkeysvalueof{/pgfplots/of colormap/source pos}'. Please use one of the styles 'colors', 'indices', or 'const colors' in order to process more than one position}%
	\pgfkeyssetvalue{/pgfplots/of colormap/source pos}{0}%
}%
\def\pgfplots@createcolormap@special@process@single{%
	\begingroup
	\let\pgfplots@color@of@colormap@access=\pgfplots@colormap@access
	\pgfkeysgetvalue{/pgfplots/of colormap/source range}\pgfplotspointmetatransformedrange
	\ifx\pgfplotspointmetatransformedrange\pgfutil@empty
		% evaluated by \pgfplots@color@of@colormap@define...
		\let\pgfplotspointmetatransformedrange=\pgfplotscolormaprange
	\fi
	%
	\pgfkeysgetvalue{/pgfplots/of colormap/source pos}\pgfplots@loc@TMPa
	\edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa}%
	\ifx\pgfplots@loc@TMPa\pgfutil@empty
		\pgfplots@createcolormap@special@process@single@error
	\else
		\edef\pgfplots@loc@TMPa{%
			\noexpand\pgfutil@in@{,}{\pgfplots@loc@TMPa}%
		}%
		\pgfplots@loc@TMPa
		\ifpgfutil@in@
			\pgfplots@createcolormap@special@process@single@error@comma
		\else
			\pgfmathparse{\pgfkeysvalueof{/pgfplots/of colormap/source pos}}%
			\pgfkeyslet{/pgfplots/of colormap/source pos}\pgfmathresult
		\fi
	\fi
	%
	\pgflibraryfpuifactive{\pgfkeys{/pgf/fpu=false}}{}%
	%
	\edef\pgfplots@loc@TMPa{%
		\noexpand\pgfplots@color@of@colormap@define{\pgfkeysvalueof{/pgfplots/of colormap/source pos}}%
	}%
	\pgfplots@loc@TMPa
	%
	\pgfplots@createcolormap@special@process@single@define
	\pgfmath@smuggleone\pgfplotsretval
	\endgroup
}%

\def\pgfplots@createcolormap@special@process@single@define{%
	\pgfkeysgetvalue{/pgfplots/of colormap/target pos}\pgfplots@temp@pos
	\ifx\pgfplots@temp@pos\pgfutil@empty
	\else
		\edef\pgfplots@temp@pos{(\pgfplots@temp@pos)}%
	\fi
	%
	\edef\pgfplotsretval{%
		\csname pgfpl@cm@\pgfkeysvalueof{/pgfplots/colormap name}@colspace\endcsname\pgfplots@temp@pos=(\pgfmathresult)%
	}%
}%
\let\pgfplots@createcolormap@special@process@single@define@CM=\pgfplots@createcolormap@special@process@single@define%

\def\pgfplots@createcolormap@special@process@list@sanitize@selection{%
	\pgfkeysgetvalue{/pgfplots/of colormap/source pos}\pgfplots@loc@TMPa
	\edef\pgfplots@loc@TMPa{\pgfplots@loc@TMPa}%
	\ifx\pgfplots@loc@TMPa\pgfutil@empty
		% default to a suitable source pos.
		\ifnum\pgfplots@pos@size<2
			% We have either 0 positions or 1 position.
			% This is clearly insufficient and we assume that this
			% position argument merely gives the start point for the
			% list.
			%
			% Select all of the input colormap:
			\edef\pgfplots@loc@TMPa{%
				\noexpand\pgfkeysalso{%
					/pgfplots/of colormap/source pos={0,...,\pgfplotscolormaplastindexof{\pgfkeysvalueof{/pgfplots/colormap name}}},%
					/pgfplots/of colormap/indices,
				}%
			}%
			\pgfplots@loc@TMPa
		\else
			% hm... we have no source pos, but we have positions! In
			% this case, we _sample_ source pos uniformly with one
			% sample for each position!
			\pgfkeyslet{/pgfplots/of colormap/source pos}\pgfplots@pos@size
			\pgfplots@createcolormap@special@process@list@sampled@define{P}%
		\fi
	\fi
}
\def\pgfplots@createcolormap@special@process@list@limits{%
	\begingroup
	%
	\pgfkeysgetvalue{/pgfplots/of colormap/target pos}\pgfplots@target
	\ifx\pgfplots@target\pgfutil@empty
	\else
		\pgfkeys{/pgf/fpu=true}%
		\pgfkeysgetvalue{/pgfplots/of colormap/target pos min}\pgfplots@target@min
		\pgfkeysgetvalue{/pgfplots/of colormap/target pos max}\pgfplots@target@max
		\pgfplots@loc@tmpfalse
		\ifx\pgfplots@target@min\pgfutil@empty
		\else
			\pgfmathparse\pgfplots@target@min
			\let\pgfplots@target@min=\pgfmathresult
			\pgfplots@loc@tmptrue
		\fi
		\ifx\pgfplots@target@max\pgfutil@empty
		\else
			\pgfmathparse\pgfplots@target@max
			\let\pgfplots@target@max=\pgfmathresult
			\pgfplots@loc@tmptrue
		\fi
		\ifpgfplots@loc@tmp
			% Ah - we _have_ limit constraints! Enforce them:
			\def\b@pgfplots@isfirst{1}%
			\pgfmathfloatcreate{1}{1.0}{324}%
			\let\pgfplots@firstpos\pgfmathresult%
			\let\pgfplots@lastpos\pgfmathresult%
			\pgfplotsapplistXnewempty\pgfplots@createcolormap@trg@accum
			\def\pgfplots@loc@TMPa{\pgfplotsforeachungrouped \x in}%
			\expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@target}{%
				\ifx\x\pgfutil@empty
				\else
					\pgfmathparse{\x}%
					\let\x=\pgfmathresult
					\ifx\pgfplots@target@min\pgfutil@empty
					\else
						\pgfmathfloatlessthan{\x}{\pgfplots@target@min}%
						\ifpgfmathfloatcomparison
							\let\x=\pgfutil@empty
						\fi
					\fi
					\ifx\pgfplots@target@max\pgfutil@empty
					\else
						\ifx\x\pgfutil@empty
						\else
							\pgfmathfloatlessthan{\pgfplots@target@max}{\x}%
							\ifpgfmathfloatcomparison
								\let\x=\pgfutil@empty
							\fi
						\fi
					\fi
					%
					\ifx\x\pgfutil@empty
					\else
						\let\pgfplots@lastpos=\x
						\if1\b@pgfplots@isfirst
							\let\pgfplots@firstpos=\x
							\def\b@pgfplots@isfirst{0}%
						\else
							\edef\x{,\x}%
						\fi
						\expandafter\pgfplotsapplistXpushback\expandafter{\x}\to\pgfplots@createcolormap@trg@accum
					\fi
				\fi
			}%
			%
			\ifpgfplots@createcolormap@target@pos@includes@limits@max
				\ifx\pgfplots@target@max\pgfutil@empty
				\else
					\pgfmathfloatifapproxequalrel{\pgfplots@lastpos}{\pgfplots@target@max}{%
					}{%
						\let\x=\pgfplots@target@max
						\if1\b@pgfplots@isfirst
							\def\b@pgfplots@isfirst{0}%
						\else
							\edef\x{,\x}%
						\fi
						\expandafter\pgfplotsapplistXpushback\expandafter{\x}\to\pgfplots@createcolormap@trg@accum
					}%
				\fi
			\fi
			%
			\pgfplotsapplistXlet\pgfplots@target=\pgfplots@createcolormap@trg@accum
			%
			\ifpgfplots@createcolormap@target@pos@includes@limits@min
				\ifx\pgfplots@target@min\pgfutil@empty
				\else
					\pgfmathfloatifapproxequalrel{\pgfplots@firstpos}{\pgfplots@target@min}{%
					}{%
						\let\x=\pgfplots@target@min
						\if1\b@pgfplots@isfirst
							\let\pgfplots@target=\x
						\else
							\edef\pgfplots@target{\x,\pgfplots@target}%
						\fi
					}%
				\fi
			\fi
		\fi
	\fi
	%
	\global\let\pgfplots@glob@TMPb=\pgfplots@target
	\endgroup
%\message{limit application: \pgfkeysvalueof{/pgfplots/of colormap/target pos} ^^J -->\pgfplots@glob@TMPb^^J}%
	\pgfkeyslet{/pgfplots/of colormap/target pos}\pgfplots@glob@TMPb
}%

\def\pgfplots@createcolormap@special@process@list@define@target@array{%
	\pgfplots@createcolormap@special@process@list@limits%
	%
	\pgfkeysgetvalue{/pgfplots/of colormap/target pos}\pgfplots@loc@TMP
	\expandafter\pgfplotsarraynew\expandafter\pgfplots@pos@array\expandafter{\pgfplots@loc@TMP}%
	%
	\pgfplotsarraysizetomacro\pgfplots@pos@array\to\pgfplots@pos@size
}%

% PRECONDITION: Must be invoked within \pgfplots@of@colormap@getresult
\def\pgfplots@createcolormap@special@process@list{%
	\begingroup
	\pgfkeys{/pgf/fpu=true}%
	\pgfplots@createcolormap@special@process@list@define@target@array
	%
	\pgfplotsapplistXnewempty\pgfplots@createcolormap@special@process@result
	%
	\gdef\c@pgfplots@elem{0}%
	%
	\def\pgfplots@createcolormap@special@process@list@append{%
		\pgfplots@createcolormap@special@process@single
		%
		% append separator
		\t@pgfplots@toka=\expandafter{\pgfplotsretval}%
		\t@pgfplots@tokb=\expandafter{\pgfplots@createcolormap@special@process@list@separator}%
		\edef\pgfplotsretval{\the\t@pgfplots@toka\the\t@pgfplots@tokb}%
		%
		\expandafter\pgfplotsapplistXpushback\pgfplotsretval\to\pgfplots@createcolormap@special@process@result
	}%
	%
	\pgfplots@createcolormap@special@process@list@sanitize@selection
	%
	\pgfkeysgetvalue{/pgfplots/of colormap/source pos}\pgfplots@source
	%
	\def\pgfplots@loc@TMPa{\pgfplotsforeachungrouped \x in }%
	\expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@source}{%
		%
		\pgfkeyslet{/pgfplots/of colormap/source pos}\x
		%
		\ifnum\c@pgfplots@elem<\pgfplots@pos@size\relax
			\pgfplotsarrayselect\c@pgfplots@elem\of\pgfplots@pos@array\to\pgfplots@loc@TMPa
			\pgfkeyslet{/pgfplots/of colormap/target pos}\pgfplots@loc@TMPa
		\else
			% auto-position:
			\pgfkeyslet{/pgfplots/of colormap/target pos}\pgfutil@empty
		\fi
		%
		\pgfplots@createcolormap@special@process@list@append
		%
		\pgfplotsutil@advancestringcounter@global\c@pgfplots@elem
	}%
	%
	\pgfutil@loop
	\ifnum\c@pgfplots@elem<\pgfplots@pos@size\relax
		\pgfplotsarrayselect\c@pgfplots@elem\of\pgfplots@pos@array\to\pgfplots@loc@TMPa
		\pgfkeysgetvalue{/pgfplots/of colormap/source pos}\x
		\pgfplotswarning{too many colormap positions}{index \c@pgfplots@elem\space (value \pgfplots@loc@TMPa)}\pgfeov%
		\pgfplotsutil@advancestringcounter@global\c@pgfplots@elem
		%
	\pgfutil@repeat
	%
	\pgfplotsapplistXlet\pgfplotsretval=\pgfplots@createcolormap@special@process@result
	\global\let\pgfplots@glob@TMPa=\pgfplotsretval
	\endgroup
	\let\pgfplotsretval=\pgfplots@glob@TMPa
%\message{of colormap with list functionality results in \meaning\pgfplotsretval^^J}%
}%
\def\pgfplots@createcolormap@special@process@list@sampled{%
	\begingroup
	\pgfkeys{/pgf/fpu=true}%
	\pgfplots@createcolormap@special@process@list@define@target@array
	%
	% no need to reapply it in \pgfplots@createcolormap@special@process@list:
	\let\pgfplots@createcolormap@special@process@list@define@target@array=\relax
	%
	\pgfplots@createcolormap@special@process@list@sampled@define{S}%
	\pgfplots@createcolormap@special@process@list
	\global\let\pgfplots@glob@TMPa=\pgfplotsretval
	\endgroup
	\let\pgfplotsretval=\pgfplots@glob@TMPa
}

% Defines
% * 'source range',
% * 'source pos',
% in a way such that it implements 'samples of colormap'
% #1: 'S' if it _must_ satisfy the number of samples and 'P' if it
% _must_ satisfy the positions
\def\pgfplots@createcolormap@special@process@list@sampled@define#1{%
	\begingroup
	\pgfkeysgetvalue{/pgfplots/of colormap/source pos}\pgfplots@source
	%
	\def\b@pgfplots@special@interval{0}%
	\def\b@pgfplots@special@interval@additional{0}%
	\if c\pgfplots@ofcolorbar@sample@for@choice%
		% or colormap/sample for=const:
		% sample one less and replicate the last color. This
		% is to compensate for 'colormap access/extra interval width=0'
		% (which is the default for colormaps with positions)
		\ifnum\pgfplots@pos@size>1
			% ah - we have at least 2 positions and 'extra interval width=0' applies!
			\if S#1%
				\c@pgf@counta=\pgfplots@source\relax
				\advance\c@pgf@counta by1 %
				\ifnum\pgfplots@pos@size=\c@pgf@counta
				\else
					\pgfplotsthrow{too few colormap positions}{\pgfplots@pos@size}{There is an unexpected number of arguments to 'target pos' for 'samples of colormap=(\pgfplots@source)'. Please provide \the\c@pgf@counta\space positions, not \pgfplots@pos@size}\pgfeov%
				\fi
			\fi
			\if S#1%
				% this is the case
				%   samples of colormap={5, target pos={<6 positions>}}
				% -> we need to replicate the last color such that we see the rightmost color of the input map
				\def\b@pgfplots@special@interval{1}%
				% -> we also need one more sample point (one for each position):
				\def\b@pgfplots@special@interval@additional{1}%
			\else
				% we have pgfplots@pos@size=pgfplots@source.
				\if1\b@pgfplots@createcolormap@found@more@colors
					% there are more positions/colors!? Ok, no need to
					% apply it here:
					\def\b@pgfplots@special@interval{0}%
				\else
					\def\b@pgfplots@special@interval{1}%
				\fi
			\fi
		\else
			\def\b@pgfplots@special@interval{0}%
		\fi
	\else
		\def\b@pgfplots@special@interval{0}%
		\ifnum\pgfplots@pos@size>1
			% ah - we have at least 2 positions
			\if S#1%
				\ifnum\pgfplots@pos@size=\pgfplots@source
				\else
					\pgfplotsthrow{too few colormap positions}{\pgfplots@pos@size}{There is an unexpected number of arguments to 'target pos' for 'samples of colormap=(\pgfplots@source)'. Please provide \pgfplots@source\space positions, not \pgfplots@pos@size}\pgfeov%
				\fi
			\fi
		\fi
	\fi
	%
	\if1\b@pgfplots@special@interval@additional
		\c@pgf@counta=\pgfplots@source\relax
		\advance\c@pgf@counta by+1
		\edef\pgfplots@source{\the\c@pgf@counta}%
	\fi
	\if1\b@pgfplots@special@interval
		\begingroup
		\c@pgf@counta=\pgfplots@source\relax
		\advance\c@pgf@counta by-1
		%
		\pgfplotsapplistXnewempty\pgfplots@createcolormap@trg@accum
		\ifnum\c@pgf@counta<2
			\pgfmathfloatcreate{0}{0.0}{0}%
			\expandafter\pgfplotsapplistXpushback\expandafter{\pgfmathresult,}\to\pgfplots@createcolormap@trg@accum
		\else
			\edef\pgfplots@source{\the\c@pgf@counta}%
			\pgfplots@domain@to@foreach 0:1000\relax{\pgfplots@source}%
			%
			\def\pgfplots@loc@TMPa{\pgfplotsforeachungrouped \x in}%
			\expandafter\pgfplots@loc@TMPa\expandafter{\pgfplotsretval}{%
				\expandafter\pgfplotsapplistXpushback\expandafter{\x,}\to\pgfplots@createcolormap@trg@accum
			}%
		\fi
		%
		\pgfmathfloatcreate{1}{1.0}{3}%
		\expandafter\pgfplotsapplistXpushback\expandafter{\pgfmathresult}\to\pgfplots@createcolormap@trg@accum
		%
		\pgfplotsapplistXlet\pgfplots@target=\pgfplots@createcolormap@trg@accum
		\global\let\pgfplots@glob@TMPa=\pgfplots@target
		\endgroup
		%
		\let\pgfplotsretval=\pgfplots@glob@TMPa
	\else
		\pgfplots@domain@to@foreach 0:1000\relax{\pgfplots@source}%
	\fi
	\pgfmath@smuggleone\pgfplotsretval
	\endgroup
	\pgfkeyslet{/pgfplots/of colormap/source pos}\pgfplotsretval
	\pgfqkeys{/pgfplots/of colormap}{%
		source range=0:1000,%
	}%
%\message{define sample positions(#1) = \pgfplotsretval^^J}%
}%


\def\pgfplots@createcolormap@special@process@list@separator@CM{ }%
\let\pgfplots@createcolormap@special@process@list@separator=\pgfplots@createcolormap@special@process@list@separator@CM
%%%%%%%%%%

\def\b@pgfplots@createcolormap@found@more@colors{0}%

\def\pgfplots@createcolormap@grabnext@complete{%
	\edef\pgfplots@loc@TMPd{%
		\noexpand\pgfutil@in@{of color}{\pgfplots@loc@TMPa}%
	}%
	\pgfplots@loc@TMPd
	\ifpgfutil@in@
		\def\pgfplots@loc@TMPd{%
			\pgfplots@createcolormap@ifhasmorecolors{%
				\def\b@pgfplots@createcolormap@found@more@colors{1}%
				\pgfplots@createcolormap@grabnext@complete@of@colormap
			}{%
				\def\b@pgfplots@createcolormap@found@more@colors{0}%
				\pgfplots@createcolormap@grabnext@complete@of@colormap
			}%
		}%
	\else
		% ok, this is a 'normal' color specification with position,
		% colorspace, and color data.
		%
		\edef\pgfplots@loc@TMPa{%
			{\pgfplots@loc@TMPb}% position
			{%
			\pgfplots@loc@TMPa% colorspace
			=\pgfplots@loc@TMPc% color data
			}%
		}%
		\expandafter\pgfplots@createcolormap@nextcolor\pgfplots@loc@TMPa
		%
		% continue loop:
		\def\pgfplots@loc@TMPd{\pgfplots@createcolormap@}%
	\fi
	%
	%
	% continue loop:
	\pgfplots@loc@TMPd
}%

\def\pgfplots@createcolormap@grabnext@complete@of@colormap{%
	% ah - a special one based on another colormap!
	% convert it into the standard format:
	\begingroup
	\let\pgfplotscolormap@at=\pgfplots@loc@TMPb
	\let\pgfplotscolormap@argument=\pgfplots@loc@TMPc
	\let\pgfplotscolormap@key=\pgfplots@loc@TMPa
	%
	\pgfplots@createcolormap@grabnext@complete@ofcolormap
	\pgfmath@smuggleone\pgfplotsretval
	\endgroup
	%
	\expandafter\pgfplots@createcolormap@\pgfplotsretval
}%

% INPUT:
%		\pgfplotscolormap@at
%		\pgfplotscolormap@argument
%		\pgfplotscolormap@key
% OUTPUT:
% 		The result of /pgfplots/of colormap/@define.
% 		For the normal colormap definition, it populates
% 		\pgfplotsretval with the color specifications as they should
% 		be processed by the colormap definition code.
\def\pgfplots@createcolormap@grabnext@complete@ofcolormap{%
	\t@pgfplots@tokb=\expandafter{\pgfplotscolormap@argument}%
	\edef\pgfplotscolormap@keyvalue{%
		\if m\b@pgfplots@createcolormap@pos@mode
			% ah - we have had manually provided positions before.
			% Well, keep them. Otherwise, we will stay at the default
			% placement.
			target pos={\pgfplotscolormap@at},%
		\fi
		% ... but can be overriden here:
		\pgfplotscolormap@key={\the\t@pgfplots@tokb},%
	}%
	%
	\let\pgfplots@createcolormap@special@process@single@define=\pgfplots@createcolormap@special@process@single@define@CM
	\let\pgfplots@createcolormap@special@process@list@separator=\pgfplots@createcolormap@special@process@list@separator@CM
	%
	% finally, process the keys:
	\expandafter\pgfplots@of@colormap@getresult\expandafter{%
		\pgfplotscolormap@keyvalue,
	}%
%\message{\pgfplotscolormap@key={\pgfplotscolormap@argument} -> '\pgfplotscolormap@keyvalue' -> \pgfplotsretval^^J}%
}%

\def\pgfplots@createcolormap@grabnext@computenextposition{%
	% determine next step size automatically:
	\expandafter\pgfplotsarraycheckempty\expandafter{\pgfplots@createcolormap@name}%
	\ifpgfplotsarrayempty
		% first: just use 0.
		\pgfmathfloatcreate{0}{0.0}{0}%
	\else
		% not first:
		\ifx\pgfplots@createcolormap@H\pgfutil@empty
			% ah; we really have to deduce something. We are at the
			% second node:
			%\def\pgfmathresult{1cm}%
			\pgfmathfloatcreate{1}{2.845274}{1}% 1cm=28.45274pt . Backw compat
		\else
			\pgfmathfloatadd@\pgfplots@createcolormap@LAST\pgfplots@createcolormap@H
		\fi
	\fi
}%

\def\pgfplots@createcolormap@grabsemicolon;{\pgfplots@createcolormap@}%
\def\pgfplots@createcolormap@grabcomma,{\pgfplots@createcolormap@}%

\def\pgfplots@createcolormap@grabsemicolon@hasnext#1#2;{\pgfplots@createcolormap@ifhasmorecolors{#1}{#2}}%
\def\pgfplots@createcolormap@grabcomma@hasnext#1#2,{\pgfplots@createcolormap@ifhasmorecolors{#1}{#2}}%

{
	\catcode`\;=13
	\gdef\pgfplots@createcolormap@grabsemicolon@active;{\pgfplots@createcolormap@}%
	\gdef\pgfplots@createcolormap@grabsemicolon@active@hasnext#1#2;{\pgfplots@createcolormap@ifhasmorecolors{#1}{#2}}%
}

\def\pgfplots@createcolormap@nextcolor@tostring#1=#2\pgfplots@EOI#3{%
	#1(#3)=(#2)%
}%

% #1: h
% #2: a compound element of the form
% '<colorspace>=<comma-separated-color-components>'
%  The format is chosen such that it can be forwarded directly to
%  \pgfplotscolornormalizesequencenext
%
% see  \pgfplotscolornormalizesequencenext for details
\def\pgfplots@createcolormap@nextcolor#1#2{%
	\def\pgfplots@createcolormap@context{\pgfplots@createcolormap@nextcolor@tostring#2\pgfplots@EOI{#1}\pgfplots@createcolormap@trace}%
	%
	\pgfplotscolornormalizesequencenext{#2}%
	\let\pgfplots@createcolormap@col@comps=\pgfplotsretvalb
	%
	\edef\pgfplots@loc@TMPa{{#1}{\pgfplotsretval}}%
	\expandafter\pgfplots@createcolormap@nextcolor@\pgfplots@loc@TMPa%
}%
\def\pgfplots@createcolormap@nextcolor@#1#2{%
%\message{processing color #1=(#2)^^J}%
	% compute 'h':
	\pgfmathparse{#1}%
	\let\pgfplots@createcolormap@MAX=\pgfmathresult
	%
	\ifx\pgfplots@createcolormap@MIN\pgfutil@empty
		% it is the first.
		\let\pgfplots@createcolormap@MIN=\pgfmathresult
		\let\pgfplots@createcolormap@LAST=\pgfmathresult
	\fi
	%
	\expandafter\pgfmathfloatsubtract@\expandafter{\pgfmathresult}{\pgfplots@createcolormap@LAST}%
	\let\pgfplots@createcolormap@H@cur=\pgfmathresult
	\pgfplots@createcolormap@check@increasing@mesh@width
	\let\pgfplots@createcolormap@LAST=\pgfplots@createcolormap@MAX
	\ifx\pgfplots@createcolormap@H\pgfutil@empty
		\expandafter\pgfplotsarraycheckempty\expandafter{\pgfplots@createcolormap@name}%
		\ifpgfplotsarrayempty
		\else
			\let\pgfplots@createcolormap@H=\pgfplots@createcolormap@H@cur
		\fi
	\else
		\pgfplots@createcolormap@compute@equalto{\pgfplots@createcolormap@H}{\pgfplots@createcolormap@H@cur}%
		\ifpgfmathfloatcomparison
		\else
			\ifnum\b@pgfplotscreatecolormap@isuniform>1
				% force reinterpolation:
				\pgfplotscreatecolormap@reinterpolate{#2}%
			\else
				% it is NOT uniform!
				\def\b@pgfplotscreatecolormap@isuniform{0}%
				%
				\pgfmathfloatmintwo{\pgfplots@createcolormap@H@cur}{\pgfplots@createcolormap@H}%
				\let\pgfplots@createcolormap@H=\pgfmathresult
			\fi
		\fi
	\fi
	%\message{found current H@cur  = \pgfplots@createcolormap@H@cur\space (\pgfplots@createcolormap@LAST) -> H=\pgfplots@createcolormap@H^^J}%
	%
	% remember positions:
	\expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@createcolormap@MAX,}\to\pgfplots@createcolormap@X
	%
	\edef\pgfplots@loc@TMPa{\noexpand\pgfplotsarraypushback{#2}\noexpand\to}%
	\expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@createcolormap@name}%
	\edef\pgfplots@createcolormap@last{#2}%
}%

\def\pgfplots@createcolormap@check@increasing@mesh@width{%
	\expandafter\pgfplotsarraycheckempty\expandafter{\pgfplots@createcolormap@name}%
	\ifpgfplotsarrayempty
	\else
		\pgfmathfloatifflags{\pgfplots@createcolormap@H@cur}{1}{%
			% ok, H>0
		}{%
			\pgfmathfloattofixed{\pgfplots@createcolormap@H@cur}%
			\pgfplots@error{Colormaps must have increasing positions. The provided colormap has mesh width '\pgfmathresult' at \pgfplots@createcolormap@context. Please assign increasing positions}%
		}%
	\fi
}%
\def\pgfplots@createcolormap@compute@equalto#1#2{%
	%\begingroup
	%\pgfmathfloatcreate{1}{1.0}{-4}%
	%\let\pgfmathfloat@relthresh=\pgfmathresult
	\pgfmathfloatequalto@{#1}{#2}%
	%\xdef\pgfplots@glob@TMPa{%
	%	\noexpand\def\noexpand\pgfmathresult{\pgfmathresult}%
	%	\ifpgfmathfloatcomparison
	%		\noexpand\pgfmathfloatcomparisontrue
	%	\else
	%		\noexpand\pgfmathfloatcomparisonfalse
	%	\fi
	%}%
	%\endgroup
	%\pgfplots@glob@TMPa
	%\message{equalto (#1,#2) = \pgfmathresult^^J}%
}%
\def\pgfplotscreatecolormap@reinterpolate#1{%
	\pgfmathfloatdivide@{\pgfplots@createcolormap@H@cur}{\pgfplots@createcolormap@H}%
	% after this group, \pgfmathresult is
	% - empty if no reinterpolation is possible,
	% - non-empty if reinterpolation IS possible. In this
	%   case, it contains the integer multiple of H.
	\begingroup
		\pgfmathfloattofixed{\pgfmathresult}%
		\afterassignment\pgfplots@createcolormap@nextRGB@consider@reinterpolation
		\c@pgf@counta=\pgfmathresult\relax
		\pgfmath@smuggleone\pgfmathresult
	\endgroup
	\ifx\pgfmathresult\pgfutil@empty
		% I can't do that yet.
	\else
		\let\pgfplots@createcolormap@loop@end=\pgfmathresult
		% interpolate missing values using the already fixed H.
		% This interpolation procedure is stupid because it works
		% only in forward direction - but it works at least.
		% For the backwards direction, you can provide the
		% meshwidth explicitly at
		% \pgfplotscreatecolormap{}{[1pt]}
		\pgfplotsforeachungrouped \c@pgfplots@createcolormap in {1,2,...,\pgfplots@createcolormap@loop@end} {%
			\pgfmathfloatequalto@{\c@pgfplots@createcolormap}{\pgfplots@createcolormap@loop@end}%
			\ifpgfmathfloatcomparison
				% omit the last.
			\else
				\pgfmathparse{\c@pgfplots@createcolormap/\pgfplots@createcolormap@loop@end}%
				\let\pgfplots@createcolormap@scale@current=\pgfmathresult
				\pgfmathparse{1-\pgfplots@createcolormap@scale@current}%
				\let\pgfplots@createcolormap@scale@last=\pgfmathresult
				%
				\pgfmathfloattofixed\pgfplots@createcolormap@scale@current
				\let\pgfplots@createcolormap@scale@current=\pgfmathresult
				\pgfmathfloattofixed\pgfplots@createcolormap@scale@last
				\let\pgfplots@createcolormap@scale@last=\pgfmathresult
				%
				\pgfplotscolornormalizesequencezero
				\pgfplotscolornormalizesequenceaddweighted
					{\pgfplotsretval}%
					{\pgfplots@createcolormap@scale@current}%
					{#1}%
				\pgfplotscolornormalizesequenceaddweighted
					{\pgfplotsretval}%
					{\pgfplots@createcolormap@scale@last}%
					{\pgfplots@createcolormap@last}%
				%
%\message{interpolation step \c@pgfplots@createcolormap = \pgfplotsretval^^J}%
				\edef\pgfplots@loc@TMPa{%
					\noexpand\pgfplotsarraypushback{\pgfplotsretval}%
					\noexpand\to}%
				\expandafter\pgfplots@loc@TMPa\expandafter{\pgfplots@createcolormap@name}%
			\fi
		}%
	\fi
}%
\def\pgfplots@createcolormap@nextRGB@consider@reinterpolation#1\relax{%
	\pgf@xa=#1pt
	\ifdim\pgf@xa>0.5pt % we have something like 99.995 or so.
		% round up and compute 1 - #1:
		\advance\c@pgf@counta by1
		\pgf@xa=1pt \advance\pgf@xa by-#1pt
	\fi
	%
	% compute relative error:
	\pgf@xb=\the\c@pgf@counta pt
	\divide\pgf@xb by10000
%\message{Checking  H/h = \pgfplots@createcolormap@H@cur pt/\pgfplots@createcolormap@H pt = \the\c@pgf@counta+-\pgf@sys@tonumber\pgf@xa\space:  \the\pgf@xa > \the\pgf@xb\space (relative to \the\c@pgf@counta)?}%
	%
	\ifdim\pgf@xa>\pgf@xb
		\begingroup
		\if2\b@pgfplotscreatecolormap@isuniform
			\pgfplots@error{Non-uniform colormaps are only supported if you write 'compat=1.14' (or higher). Please adopt the compatibility level and retry. The error occured near '\pgfplots@createcolormap@context'}%
		\else
			\pgfmathfloattofixed{\pgfplots@createcolormap@H}%
			\let\pgfplots@createcolormap@H=\pgfmathresult
			\pgfmathfloattofixed{\pgfplots@createcolormap@H@cur}%
			\let\pgfplots@createcolormap@H@cur=\pgfmathresult
			\pgfplots@error{The provided colormap positions are not multiples of the prescribed mesh width h=\pgfplots@createcolormap@H\space (found one with H/h = \pgfplots@createcolormap@H@cur/\pgfplots@createcolormap@H = \the\c@pgf@counta+-\pgf@sys@tonumber\pgf@xa\space which is no integer). The error occured near `\pgfplots@createcolormap@context'}%
		\fi
		\endgroup
		\let\pgfmathresult=\pgfutil@empty
	\else
		\ifnum\c@pgf@counta=0
			\let\pgfmathresult=\pgfutil@empty
		\else
			\edef\pgfmathresult{\the\c@pgf@counta}%
		\fi
	\fi
}%

\def\pgfplots@colormap@LUA@new#1{%
	\ifpgfplots@LUA@supported
		\begingroup
		\pgfplotscolormapserializecomponentstomacro{#1}\pgfplots@values
		\pgfplotscolormapserializeXtomacro{#1}\pgfplots@pos
		\pgfplotsutil@directlua{%
			local colorspace =^^J%
				pgfplots.\csname pgfpl@cm@#1@colspace\endcsname;^^J%
			if colorspace then^^J%
				pgfplots.ColorMaps["#1"] = pgfplots.ColorMap.new(^^J%
					\csname pgfpl@cm@#1@h\endcsname,^^J%
					colorspace,^^J%
					{ \pgfplots@values },^^J
					{ \pgfplots@pos },^^J
					"\csname pgfpl@cm@#1@X@scale@order@z\endcsname"^^J
				);^^J%
			else^^J%
				io.write("There is no LUA colorspace for '\csname pgfpl@cm@#1@colspace\endcsname' - skipping LUA color map definition of #1\string\n");^^J%
			end^^J%
		}%
		\endgroup
	\fi
}%

% Executes '#2' if the colormap named '#1' has a uniform grid and '#3'
% if not.
\def\pgfplotscolormapifisuniform#1#2#3{%
	\ifnum0=\pgfplotsarraysizeof{pgfpl@cm@#1@X}\relax
		#2\relax
	\else
		#3\relax
	\fi
}%

% Shows debug info about colormap #1 into the console.
\def\pgfplots@colormap@showdebuginfofor#1{%
	\message{Debug info for color map '#1':^^J}%
	\message{(Transformed) Range: [0:\pgfplotscolormaprange];  ^^J}%
	\message{H: \csname pgfpl@cm@#1@h\endcsname;    ^^J}%
	\message{H:^{-1}: \csname pgfpl@cm@#1@invh\endcsname;    ^^J}%
	\pgfplotsarraysizetomacro{pgfpl@cm@#1}\to\pgfplots@loc@TMPa
	\message{Size: \pgfplots@loc@TMPa;    ^^J}%
	\message{Colorspace: \csname pgfpl@cm@#1@colspace\endcsname^^JValues (\csname pgfpl@cm@#1@col@comps\endcsname\space components each): ^^J}%
	\begingroup
	\c@pgf@counta=0
	\pgfplotscolormapifisuniform{#1}{%
		\pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\elem{%
			\pgfmath@basic@multiply@{\the\c@pgf@counta}{\csname pgfpl@cm@#1@h\endcsname}%
			\message{\#\the\c@pgf@counta=(\pgfmathresult)=(\elem);^^J}%
			\advance\c@pgf@counta by1 %
		}%
	}{%
		\pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\elem{%
			\pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#1@X}\to\pgfmathresult
			\message{\#\the\c@pgf@counta=(\pgfmathresult)=(\elem);^^J}%
			\advance\c@pgf@counta by1 %
		}%
	}%
	\message{^^J}%
	\endgroup
}

% #1: comma-separated list of values for the current entry
% #2: color map name
% #3: the current index into the colormap
% #4: the "x coordinate", i.e. the offset within the colormap
%
% Defines \pgfplotsretval
%
% Example:
% \pgfplotscolormaptodatafile[
%		output each nth=1,
%		output format=csv,
%	]{viridis}
%	{viridis.dat}
\def\pgfplotscolormaptodatafile@elem#1#2#3#4{%
	\let\pgfplotsretval=\pgfutil@empty
}%

\begingroup
\catcode`\[=1
\catcode`\]=2
\catcode`\{=12
\catcode`\}=12
\xdef\pgfplots@lbrace[{]%
\xdef\pgfplots@rbrace[}]%
\endgroup


\pgfkeys{
	/pgfplots/colormap/output each nth/.initial=1,
	/pgfplots/colormap/output format/.is choice,
	/pgfplots/colormap/output format/csv/.code={%
		\def\pgfplotscolormaptodatafile@head##1{%
			\let\pgfplotsretval=\pgfutil@empty
		}%
		\def\pgfplotscolormaptodatafile@elem##1##2##3##4{%
			\edef\pgfplotsretval{##4,##1}%
		}%
		\def\pgfplotscolormaptodatafile@foot##1{%
			\let\pgfplotsretval=\pgfutil@empty
		}%
	},
	/pgfplots/colormap/output format/native/.code={%
		\def\pgfplotscolormaptodatafile@head##1{%
			\edef\pgfplotsretval{\string\pgfplotsset\pgfplots@lbrace colormap={##1}\pgfplots@lbrace}%
		}%
		\def\pgfplotscolormaptodatafile@elem##1##2##3##4{%
			\edef\pgfplotsretval{\csname pgfpl@cm@##2@colspace\endcsname=(##1)}%
		}%
		\def\pgfplotscolormaptodatafile@foot##1{%
			\edef\pgfplotsretval{\pgfplots@rbrace\pgfplots@rbrace}%
		}%
	},
	/pgfplots/colormap/output format=csv,
}


% An export of a color map.
% #1: options. Can use 'output each nth=2' and 'output format=csv|native'
% #2: a color map
% #3: a data file
\def\pgfplotscolormaptodatafile{\pgfutil@ifnextchar[{\pgfplotscolormaptodatafile@}{\pgfplotscolormaptodatafile@[]}}%
\def\pgfplotscolormaptodatafile@[#1]#2#3{%
	\begingroup
	\pgfqkeys{/pgfplots/colormap}{#1}%
	\pgfkeysgetvalue{/pgfplots/colormap/output each nth}{\pgfplots@eachnth}%
	\immediate\openout\w@pgf@writea=#3\relax
	\pgfplotscolormaptodatafile@head{#2}%
	\ifx\pgfplotsretval\pgfutil@empty
	\else
		\immediate\write\w@pgf@writea{%
			\pgfplotsretval
		}%
	\fi
	\gdef\pgfplots@eachnth@cur{0}%
	\pgfplotsarrayforeach{pgfpl@cm@#2}\as\elem{%
		\ifnum\pgfplots@eachnth@cur=0\relax
			\gdef\pgfplots@eachnth@cur{0}%
			\pgfplotscolormapifisuniform{#2}{%
				\pgfmath@basic@multiply@{\pgfplotsarrayforeachindex}{\csname pgfpl@cm@#2@h\endcsname}%
			}{%
				\pgfplotsarrayselect\pgfplotsarrayforeachindex\of{pgfpl@cm@#1@X}\to\pgfmathresult
			}%
			\edef\pgfplots@loc@TMPa{{\elem}{#2}{\pgfplotsarrayforeachindex}{\pgfmathresult}}%
			\expandafter\pgfplotscolormaptodatafile@elem\pgfplots@loc@TMPa
			\ifx\pgfplotsretval\pgfutil@empty
			\else
				\immediate\write\w@pgf@writea{%
					\pgfplotsretval
				}%
			\fi
		\fi
		\pgfplotsutil@advancestringcounter@global\pgfplots@eachnth@cur%
		\ifnum\pgfplots@eachnth@cur=\pgfplots@eachnth\relax
			\gdef\pgfplots@eachnth@cur{0}%
		\fi
	}%
	\pgfplotscolormaptodatafile@foot{#2}%
	\ifx\pgfplotsretval\pgfutil@empty
	\else
		\immediate\write\w@pgf@writea{%
			\pgfplotsretval
		}%
	\fi
	\immediate\closeout\w@pgf@writea
	\endgroup
}

% Defines \pgfplotsretval to contain the mesh width of colormap #1.
% If the color map has a non-uniform grid, it returns the SMALLEST
% encountered mesh width.
\def\pgfplotscolormapgetmeshwidth#1{%
	\expandafter\let\expandafter\pgfplotsretval\csname pgfpl@cm@#1@h\endcsname%
}%

% defines macro #2 to contain a serialized variant of the color
% components (only the color components!)
\def\pgfplotscolormapserializecomponentstomacro#1#2{%
	\pgfplotscolormapserialize@to@macro{pgfpl@cm@#1}{#2}%
}
\def\pgfplotscolormapserialize@to@macro#1#2{%
	\pgfplotsapplistXnewempty\pgfplots@serialize@list@
	\pgfplots@loc@tmptrue
	\expandafter\pgfplotsarrayforeachungrouped\expandafter{#1}\as\elem{%
		\ifpgfplots@loc@tmp
			\expandafter\pgfplotsapplistXpushback\expandafter{\expandafter{\elem}}\to\pgfplots@serialize@list@
			\pgfplots@loc@tmpfalse
		\else
			\expandafter\pgfplotsapplistXpushback\expandafter,\expandafter{\elem}\to\pgfplots@serialize@list@
		\fi
	}%
	\pgfplotsapplistXlet#2=\pgfplots@serialize@list@
}%

\def\pgfplotscolormapserialize@to@macro@nobraces#1#2{%
	\pgfplotsapplistXnewempty\pgfplots@serialize@list@
	\pgfplots@loc@tmptrue
	\expandafter\pgfplotsarrayforeachungrouped\expandafter{#1}\as\elem{%
		\ifpgfplots@loc@tmp
			\expandafter\pgfplotsapplistXpushback\elem\to\pgfplots@serialize@list@
			\pgfplots@loc@tmpfalse
		\else
			\expandafter\pgfplotsapplistXpushback\expandafter,\elem\to\pgfplots@serialize@list@
		\fi
	}%
	\pgfplotsapplistXlet#2=\pgfplots@serialize@list@
}%
\def\pgfplotscolormapserializeXtomacro#1#2{%
	\pgfplotscolormapserialize@to@macro@nobraces{pgfpl@cm@#1@X}{#2}%
}%

% Copies the contents of the colormap named '#1' into a macro '#2'.
% Invocation of the macro will then re-create the colormap.
%
% #1: color map name
% #2: a macro name
\def\pgfplotscolormapserializetomacro#1#2{%
	\begingroup
		\pgfplotscolormapserializecomponentstomacro{#1}\pgfplots@serialize@list
		\pgfplotscolormapserializeXtomacro{#1}\pgfplots@serialize@list@X
		\toks0={\expandafter\def\csname pgfpl@cm@#1@h\endcsname}%
		\toks1={\expandafter\def\csname pgfpl@cm@#1@invh\endcsname}%
		\toks2={%
			\pgfplotsarraynewempty{pgfpl@cm@#1}%
			\expandafter\pgfplotsutilforeachcommasep\pgfplots@loc@TMPa\as\pgfplots@loc@TMPb{%
				\ifx\pgfplots@loc@TMPb\pgfutil@empty
				\else
					\expandafter\pgfplotsarraypushback\pgfplots@loc@TMPb\to{pgfpl@cm@#1}%
				\fi
			}%
		}%
		\toks3=\expandafter{\pgfplots@serialize@list}%
		\toks4=\expandafter{\expandafter\def\csname pgfpl@cm@#1@colspace\endcsname}%
		\toks5=\expandafter{\expandafter\def\csname pgfpl@cm@#1@col@comps\endcsname}%
		\toks6=\expandafter{\expandafter\def\csname pgfpl@cm@#1@lastindex\endcsname}%
		\toks7={%
			\pgfplotsarraynewempty{pgfpl@cm@#1@X}%
			\expandafter\pgfplotsutilforeachcommasep\pgfplots@loc@TMPa\as\pgfplots@loc@TMPb{%
				\ifx\pgfplots@loc@TMPb\pgfutil@empty
				\else
					\expandafter\pgfplotsarraypushback\pgfplots@loc@TMPb\to{pgfpl@cm@#1@X}%
				\fi
			}%
		}%
		\toks8=\expandafter{\pgfplots@serialize@list@X}%
		\xdef\pgfplots@glob@TMPa{%
			\the\toks0 {\csname pgfpl@cm@#1@h\endcsname}%
			\the\toks1 {\csname pgfpl@cm@#1@invh\endcsname}%
			\noexpand\def\noexpand\pgfplots@loc@TMPa{\the\toks3 }%
			\the\toks2
			\the\toks4 {\csname pgfpl@cm@#1@colspace\endcsname}%
			\the\toks5 {\csname pgfpl@cm@#1@col@comps\endcsname}%
			\the\toks6 {\csname pgfpl@cm@#1@lastindex\endcsname}%
			\noexpand\def\noexpand\pgfplots@loc@TMPa{\the\toks8 }%
			\the\toks7
			\def\expandafter\noexpand\csname pgfpl@cm@#1@X@scale@order@z\endcsname{\csname pgfpl@cm@#1@X@scale@order@z\endcsname}%
		}%
	\endgroup
	\let#2=\pgfplots@glob@TMPa
}%

% Defines \pgfplotsretval to contain an argument for use in \foreachlist
% which results in all the positions.
%
% [#1:#2] : the desired output domain. The smallest position will be
% mapped to #1, the largest to #2, and all in-between will be mapped
% accordingly.
% #3: the colormap name.
%
% Note that this switch depends on the current value of 'colormap
% access': piecewise constant may use different positions.
%
% On output, \pgfplotsretval will contain the result.
\def\pgfplotscolormapgetpositions[#1:#2]#3{%
	\begingroup
	\if d\pgfplots@colormap@access
		\edef\pgfplotsretval{0,1,...,\pgfplotscolormaplastindexof{#3}}%
	\else
		\if m\pgfplots@colormap@access
			\def\b@pgfplots@extra@interval{0}%
			\edef\pgfplots@H{\csname pgfpl@cm@#3@h\endcsname}%
		\else
			\if c\pgfplots@colormap@access
				\pgfplotscolormap@piecewiseconst@prepare@scale{#3}%
				\edef\pgfplots@H{\pgf@sys@tonumber\pgf@x}%
			\fi
		\fi
		%
		\pgfkeys{/pgf/fpu}%
		\pgfplotsapplistXnewempty\pgfplots@resultaccum
		\pgfplotscolormapifisuniform{#3}{%
			\pgfmathparse{#1 + (#2-#1) * \pgfplots@H/1000}%
			\let\next=\pgfmathresult
			\pgfmathparse{#2}% + (#2-#1)/1000}%
			%
			\def\b@pgfplots@isfirst{1}%
			\edef\pgfplots@loc@TMPa{\noexpand\pgfplotsforeachungrouped\noexpand \x in {#1,\next,...,\pgfmathresult}}%
			\pgfplots@loc@TMPa{%
				\if0\b@pgfplots@isfirst
					\pgfplotsapplistXpushback,\to\pgfplots@resultaccum
				\fi
				\expandafter\pgfplotsapplistXpushback\expandafter{\x}\to\pgfplots@resultaccum
				\def\b@pgfplots@isfirst{0}%
			}%
		}{%
			\pgfmathparse{(#2-#1)/1000}%
			\let\pgfplots@scale=\pgfmathresult
			\pgfplotsarrayforeachungrouped{pgfpl@cm@#3@X}\as\pgfplots@loc@TMPc{%
				\if m\pgfplots@colormap@access
					% colormap access=map
					\pgfmathparse{#1 + \pgfplots@loc@TMPc * \pgfplots@scale}%
				\else
					\if1\b@pgfplots@extra@interval
						\pgfmathparse{#1 + \pgfplots@loc@TMPc * \pgfplots@H* \pgfplots@scale}%
					\else
						% DISABLE additional interval!
						% Means: use the input position as usual:
						\pgfmathparse{#1 + \pgfplots@loc@TMPc * \pgfplots@scale}%
					\fi
				\fi
				\ifnum\pgfplotsarrayforeachindex>0
					\pgfplotsapplistXpushback,\to\pgfplots@resultaccum
				\fi
				\expandafter\pgfmathfloattofixed\expandafter{\pgfmathresult}%
				\expandafter\pgfplotsapplistXpushback\expandafter{\pgfmathresult}\to\pgfplots@resultaccum
			}%
			\if1\b@pgfplots@extra@interval
				\pgfmathparse{#2}%
				\pgfplotsapplistXpushback,\to\pgfplots@resultaccum
				\expandafter\pgfmathfloattofixed\expandafter{\pgfmathresult}%
				\expandafter\pgfplotsapplistXpushback\expandafter{\pgfmathresult}\to\pgfplots@resultaccum
			\fi
		}%
		\pgfplotsapplistXlet\pgfplotsretval=\pgfplots@resultaccum
	\fi
	\pgfmath@smuggleone\pgfplotsretval
	\endgroup
}%

% this is a CONSTANT! Do NOT change it!
% Just read it -- just in case \pgfplotscolormaptopdffunction will use
% a different upper bound in the future.
\def\pgfplotscolormappdfmax{1000}%
\def\pgfplotscolormappdfmax@inv{1}%

% Expands to the size of colormap #1 .
\def\pgfplotscolormapsizeof#1{%
	\pgfplotscolormapifdefined{#1}{%
		\pgfplotsarraysizeof{pgfpl@cm@#1}%
	}{%
		0%
	}%
}%

% Defines \pgfplotsretval to contain the color of color map '#1' at
% index '#2'
\def\pgfplotscolormapgetcolor#1#2{%
	\pgfplotsarrayselect{#2}\of{pgfpl@cm@#1}\to\pgfplotsretval
}%

% Expands to the last index of colormap #1 (or -1)
\def\pgfplotscolormaplastindexof#1{%
	\pgfplotscolormapifdefined{#1}{%
		\csname pgfpl@cm@#1@lastindex\endcsname%
	}{%
		-1%
	}%
}%

% POSTCONDITION:
% 1. for uniform #1:
%  \pgf@x contains the MODIFIED mesh width
%  \b@pgfplots@extra@interval is 1 if and only if an extra interval
%  should be added
% 2. for non-uniform #1:
% 	\pgf@x is a scaling factor to map input positions to MODIFIED
% 	positions
%  \b@pgfplots@extra@interval is 1 if and only if an extra interval
\def\pgfplotscolormap@piecewiseconst@prepare@scale#1{%
	% advance the number of intervals by 1.
	\pgfplotscolormapifisuniform{#1}{%
		% To this end, we have to compute
		% N = n+1
		% and
		% H = 1000 / (N-1) = 1000/n.
		% Store H in \pgf@x:
		\expandafter\ifx\csname pgfpl@cm@#1@X@scale@order@z\endcsname\pgfutil@empty%
			\c@pgf@countd=\pgfplotscolormapsizeof{#1}\relax
			%
			\global\pgf@x=1000pt %
			\global\divide\pgf@x by\c@pgf@countd
			\def\b@pgfplots@extra@interval{1}%
		\else
			% DISABLE the extra interval!
			\global\pgf@x=\csname pgfpl@cm@#1@h\endcsname pt %
			\def\b@pgfplots@extra@interval{0}%
		\fi
	}{%
		% the very same idea as for uniform colormaps applies
		% for non-uniform maps as well: we create an
		% artificial interval at the rightmost end.
		% The idea is to think of a temporary map in the range
		% [0,1000+ h] where h is the current colormap's
		% mesh width.
		% Since the domain is [0,1000], we map [0,1000+h]
		% linearly into [0,1000].
		%
		% This here is the scaling factor:
		\global\pgf@x=\csname pgfpl@cm@#1@X@scale@order@z\endcsname pt %
		% see also
		% \pgfplotscolormapfindpiecewiseconst@precomputed for
		% comments
		\ifdim\pgf@x>0sp %
			\def\b@pgfplots@extra@interval{1}%
		\else
			% disable it
			\def\b@pgfplots@extra@interval{0}%
		\fi
	}%
}%

% #1: colormap name
% #2: yes code
% #3: no code
\def\pgfplotscolormapifrequiresextrainterval#1#2#3{%
	\if c\pgfplots@colormap@access
		\pgfplotscolormapifisuniform{#1}{%
			\expandafter\ifx\csname pgfpl@cm@#1@X@scale@order@z\endcsname\pgfutil@empty%
				% no...
				#3\relax%
			\else
				% yes:
				#2\relax%
			\fi
		}{%
			\ifdim\csname pgfpl@cm@#1@X@scale@order@z\endcsname pt>0pt
				% yes:
				#2\relax%
			\else
				% no:
				#3\relax%
			\fi
		}%
	\else
		% no:
		#3\relax%
	\fi
}%
% #1: colormap name
% #2: yes code
% #3: no code
\def\pgfplotscolormapifdrawslastcolor#1#2#3{%
	\pgfplotscolormapifrequiresextrainterval{#1}{%
		#2\relax%
	}{%
		\if c\pgfplots@colormap@access
			#3\relax%
		\else
			#2\relax%
		\fi
	}%
}%

% Writes a PDF function of /FunctionType 3 to \pgfplotsretval
%
% The /Domain argument will be set to [ 0 \pgfplotscolormappdfmax ] and bounds will be
% computed accordingly.
%
% Note that the value depends on 'colormap access'
%
% #1: the colormap
\def\pgfplotscolormaptopdffunction#1{%
	\begingroup
	\pgfplotscolormapassertexists{#1}%
	\pgfplotsapplistXnewempty\pgfplots@resultaccum
	\pgfplotsapplistXpushback{
		<<
			/FunctionType 3
			/Domain [0 \pgfplotscolormappdfmax]
			/Functions [
	}\to\pgfplots@resultaccum%
	\c@pgf@counta=0
	\c@pgf@countb=\pgfplotsarraysizeof{pgfpl@cm@#1} %
	\advance\c@pgf@countb by-1
	\def\pgfplots@loc@TMPa{}%
	\pgfplotsapplistXnewempty\pgfplots@bounds@accum%
	\pgfplotsapplistXnewempty\pgfplots@encode@accum
	\ifnum\csname pgfpl@cm@#1@col@comps\endcsname>4
		\pgfplots@error{Sorry, processing more than 4 color components (as required for color map #1) is unsupported in this context}%
	\fi
	%
	\def\b@pgfplots@extra@interval{0}%
	\if m\pgfplots@colormap@access
		% colormap access=map
		\def\pgfplots@order{1}%
		\global\pgf@x=\csname pgfpl@cm@#1@h\endcsname pt %
		\def\pgfplots@C@left{C0}%
		\def\pgfplots@C@right{C1}%
	\else
		\if c\pgfplots@colormap@access
			% colormap access=piecewise constant
			% This has a dedicated special interval at the rightmost
			% end.
			% See comments in pgfplotscolormapfindpiecewiseconst@precomputed@
			\def\pgfplots@order{0}%
			%
			\pgfplotscolormap@piecewiseconst@prepare@scale{#1}%
			%
			% interchange the sequence in the PDF function as it is
			% defined as
			% y = C0 + x^0 * (C1 - C0) = C1
			% -> we want the left interval boundary.
			\def\pgfplots@C@left{C1}%
			\def\pgfplots@C@right{C0}%
		\else
			% colormap access=direct
			\pgfplots@error{This should never happen}%
			% ?
			\def\pgfplots@order{0}%
			\global\pgf@x=\csname pgfpl@cm@#1@h\endcsname pt %
			\def\pgfplots@C@left{C0}%
			\def\pgfplots@C@right{C1}%
		\fi
	\fi
	%
	\pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\cdata{%
		\edef\cdata{%
			\expandafter
			\expandafter
			\csname pgfplotscolormaptopdffunction@convertcdata@\csname pgfpl@cm@#1@col@comps\endcsname\endcsname
			\cdata\relax
		}%
		\ifnum\c@pgf@counta>0
			\edef\pgfplots@loc@TMPd{%
				<<
					/FunctionType 2
					/Domain [0 \pgfplotscolormappdfmax]
					/\pgfplots@C@left\space [\pgfplots@loc@TMPa] /\pgfplots@C@right\space [\cdata]
					/N \pgfplots@order
				>>
			}%
			\expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@loc@TMPd}\to\pgfplots@resultaccum
			\ifnum\c@pgf@counta<\c@pgf@countb\relax
				\pgfplotscolormapifisuniform{#1}{%
					\pgf@xa=\pgf@x
					\multiply\pgf@xa by\c@pgf@counta\relax
				}{%
					\pgfplotsarrayselect{\c@pgf@counta}\of{pgfpl@cm@#1@X}\to\pgfplots@loc@TMPc
					\if m\pgfplots@colormap@access
						% colormap access=map
						\pgf@xa=\pgfplots@loc@TMPc pt %
					\else
						\if1\b@pgfplots@extra@interval
							\pgf@xa=\pgfplots@loc@TMPc\pgf@x%
						\else
							% DISABLE additional interval!
							% Means: use the input position as usual:
							\pgf@xa=\pgfplots@loc@TMPc pt %
						\fi
					\fi
				}%
				\divide\pgf@xa by\pgfplotscolormappdfmax@inv\relax% we want [ 0 1 ] not [0 1000] as domain XXX : why!?
				\edef\pgfplots@loc@TMPc{ \pgf@sys@tonumber\pgf@xa}%
				\expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@loc@TMPc}\to\pgfplots@bounds@accum%
			\fi
			\pgfplotsapplistXpushback{ 0 1}\to\pgfplots@encode@accum%
		\fi
		\let\pgfplots@loc@TMPa=\cdata
		\advance\c@pgf@counta by1
	}%
	\if1\b@pgfplots@extra@interval
		% add an artificial interval.
		\edef\pgfplots@loc@TMPd{%
			<<
				/FunctionType 2
				/Domain [0 \pgfplotscolormappdfmax]
				/\pgfplots@C@left\space [\cdata] /\pgfplots@C@right\space [\cdata]
				/N \pgfplots@order
			>>
		}%
		\expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@loc@TMPd}\to\pgfplots@resultaccum
		\advance\c@pgf@counta by-1 %
		\pgfplotscolormapifisuniform{#1}{%
			\pgf@xa=\pgf@x
			\multiply\pgf@xa by\c@pgf@counta\relax
		}{%
			\pgfplotsarrayselect{\c@pgf@counta}\of{pgfpl@cm@#1@X}\to\pgfplots@loc@TMPc
			\pgf@xa=\pgfplots@loc@TMPc\pgf@x%
		}%
		\divide\pgf@xa by\pgfplotscolormappdfmax@inv\relax% we want [ 0 1 ] not [0 1000] as domain XXX : why!?
		\edef\pgfplots@loc@TMPc{ \pgf@sys@tonumber\pgf@xa}%
		\expandafter\pgfplotsapplistXpushback\expandafter{\pgfplots@loc@TMPc}\to\pgfplots@bounds@accum%
		\pgfplotsapplistXpushback{ 0 1}\to\pgfplots@encode@accum%
	\fi
	\pgfplotsapplistXlet\pgfplotsretval=\pgfplots@resultaccum
	\pgfplotsapplistXlet\pgfplotsbounds=\pgfplots@bounds@accum
	\pgfplotsapplistXlet\pgfplotsencode=\pgfplots@encode@accum
	\t@pgfplots@toka=\expandafter{\pgfplotsretval}%
	\t@pgfplots@tokb=\expandafter{\pgfplotsbounds}%
	\t@pgfplots@tokc=\expandafter{\pgfplotsencode}%
	\xdef\pgfplots@glob@TMPa{%
			\the\t@pgfplots@toka
			]
			/Bounds [\the\t@pgfplots@tokb]
			/Encode [\the\t@pgfplots@tokc]
		>>
	}%
	\endgroup
	\let\pgfplotsretval=\pgfplots@glob@TMPa
}%
\expandafter\def\csname pgfplotscolormaptopdffunction@convertcdata@1\endcsname#1\relax{#1}%
\expandafter\def\csname pgfplotscolormaptopdffunction@convertcdata@2\endcsname#1,#2\relax{#1 #2}%
\expandafter\def\csname pgfplotscolormaptopdffunction@convertcdata@3\endcsname#1,#2,#3\relax{#1 #2 #3}%
\expandafter\def\csname pgfplotscolormaptopdffunction@convertcdata@4\endcsname#1,#2,#3,#4\relax{#1 #2 #3 #4}%

% Invokes '#2' if a color map named '#1' exists and '#3' if no such color map exists.
\def\pgfplotscolormapifdefined#1#2#3{\pgfplotsarrayifdefined{pgfpl@cm@#1}{#2}{#3}}%

\def\pgfplotscolormapassertexists#1{%
	\pgfplotscolormapifdefined{#1}{}{%
		\pgfutil@ifundefined{pgfplotscolormap@errorissued@#1}{%
			\pgfplots@error{The colormap `#1' is undefined! Maybe you misspelled it?}%
		}{}%
		\expandafter\gdef\csname pgfplotscolormap@errorissued@#1\endcsname{1}%
		\pgfplotscreatecolormap{#1}{color(0cm)=(blue); color(1cm)=(yellow)}%
	}%
}

% Convert a colormap into a PGF shading's color specification for use
% in \pgfdeclare*shading.
%
% #1: the colormap's name.
% #2: the PGF "size" of the shading. It is used to set the right end
% of the color specification.
% #3: a macro which will be filled with the result.
%
% Example:
% \pgfplotscolormaptoshadingspec{my colormap}{4cm}{\output}
% \def\tempb{\pgfdeclarehorizontalshading{myshadingA}{1cm}}
% \expandafter\tempb\expandafter{\temp}
%
% \pgfuseshading{myshadingA}
\def\pgfplotscolormaptoshadingspec#1#2#3{%
	\pgfplotscolormapassertexists{#1}%
	\begingroup
	\def\pgfplots@rgb{rgb}%
	\pgfmathparse{#2}%
	\expandafter\pgfmathdivide@\expandafter{\pgfmathresult}{\pgfplotscolormaprange}%
	\let\pgfplots@loc@TMPb=\pgfmathresult
	\pgfmathmultiply@{\csname pgfpl@cm@#1@h\endcsname}{\pgfplots@loc@TMPb}%
	\pgf@ya=\pgfmathresult pt
	\c@pgf@counta=0
	\let#3=\pgfutil@empty
	\pgfplotsarrayforeachungrouped{pgfpl@cm@#1}\as\pgfplotscolormaptoshadingspec@TMP{%
		\pgfplotscolormapifisuniform{#1}{%
			\pgf@yb=\c@pgf@counta\pgf@ya
		}{%
			\pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#1@X}\to\pgfplots@loc@TMPd
			\pgfmathmultiply@{\pgfplots@loc@TMPd}{\pgfplots@loc@TMPb}%
			\pgf@yb=\pgfmathresult pt %
		}%
		\edef\pgfplots@colspace{\csname pgfpl@cm@#1@colspace\endcsname}%
		% FIXME : PGF shadings accept only RGB!
		\if1\pgfplotscolormaptoshadingspectorgb
			\ifx\pgfplots@colspace\pgfplots@rgb
			\else
				\pgfutil@ifundefined{pgfpl@cm@#1@warned}{%
					\expandafter\gdef\csname pgfpl@cm@#1@warned\endcsname{1}%
					\pgfplotswarning{lossy colormap rgb conversion}{#1}{\pgfplots@colspace}\pgfeov%
				}{%
				}%
				\edef\pgf@tempcolor{{\pgfplots@colspace}{\pgfplotscolormaptoshadingspec@TMP}}%
				\expandafter\pgfutil@convertcolorspec\pgf@tempcolor{rgb}{\pgfplotscolormaptoshadingspec@TMP}%
				\def\pgfplots@colspace{rgb}%
			\fi
		\fi
		\edef\pgfplots@loc@TMPc{\pgfplots@colspace(\the\pgf@yb)=(\pgfplotscolormaptoshadingspec@TMP)}%
		\ifx#3\pgfutil@empty
			\t@pgfplots@toka={}%
		\else
			\t@pgfplots@toka=\expandafter{#3; }%
		\fi
		\t@pgfplots@tokb=\expandafter{\pgfplots@loc@TMPc}%
		\edef#3{\the\t@pgfplots@toka \the\t@pgfplots@tokb }%
		\advance\c@pgf@counta by1
	}%
	\pgfmath@smuggleone#3%
	\endgroup
}%
\def\pgfplotscolormaptoshadingspectorgb{1}%

% The same as \pgfplotscolormaptoshadingspec, but this here yields the
% *reversed* sequence.
\def\pgfplotscolormapreversedtoshadingspec#1#2#3{%
	\begingroup
	\let\pgfplotsarrayforeachungrouped=\pgfplotsarrayforeachreversedungrouped
	\pgfplotscolormaptoshadingspec{#1}{#2}{#3}%
	\pgfmath@smuggleone#3%
	\endgroup
}%


% Expands to the transformed range's right end of every colormap. The left
% end is fixed to '0'.
\def\pgfplotscolormaprange{1000}
\pgfmathfloatcreate{1}{1.0}{3}%
\let\pgfplotscolormaprange@float=\pgfmathresult

\def\pgfplotscolormapgetcolorspace#1{%
	\edef\pgfplotsretval{\csname pgfpl@cm@#1@colspace\endcsname}%
}%
\def\pgfplotscolormapgetcolorcomps#1{%
	\edef\pgfplotsretval{\csname pgfpl@cm@#1@col@comps\endcsname}%
}%
\def\pgfplotscolormapcolorspaceof#1{%
	\csname pgfpl@cm@#1@colspace\endcsname%
}%
\def\pgfplotscolormapcolorcompsof#1{%
	\csname pgfpl@cm@#1@col@comps\endcsname%
}%


% Linearly maps the number #4 into the colormap #5 and returns the
% interpolated colors into \pgfmathresult. The result will be a triple
% for an RGB colormap and it will contain four numbers for CMYK. The
% components of the result will be in the range [0:1].
%
% [#1:#2]  the number range of the data source (i.e. of #4). This is required to
%          map into the colormap.
% [#3]     (optional) the quantity
% 			 s := \pgfplotscolormaprange / (#2-#1).
% 		   Precomputing this quantity may save a lot of time because
% 		   divisions are expensive in TeX. You can omit [#3] or
% 		   provide an empty string here.
% #4       the number to map.
% #5       the colormap's name. Must be defined with
%          \pgfplotscreatecolormap before.
%
% Example:
% \pgfplotscolormapfind[-1:1]{0.2}{my colormap}
\def\pgfplotscolormapfind[#1:#2]{%
	\pgfutil@ifnextchar[{%
		\pgfplotscolormapfind@precomputed[#1:#2]%
	}{%
		\pgfplotscolormapfind@precomputed[#1:#2][]%
	}%
}%
\def\pgfplotscolormapfind@precomputed[#1:#2][#3]#4#5{%
	\ifpgfplots@LUA@supported
		\pgfplotscolormapifisuniform{#5}{%
			\edef\pgfmathresult{%
				\pgfplotsutil@directlua{%
					pgfplots.texColorMapPrecomputed("#5", "#1","#2","#4")
				}%
			}%
			\ifx\pgfmathresult\pgfutil@empty
				\pgfplotscolormapfind@precomputed@warn@LUA{#5}%
				\pgfplotscolormapfind@precomputed@[#1:#2][#3]{#4}{#5}%
			\else
				%\message{LUA colormapfind[#1:#2](#4)(#5) = \pgfmathresult^^J}%
			\fi
		}{%
			% FIXME : implement LUA for non-uniform colormaps
			\pgfplotscolormapfind@precomputed@[#1:#2][#3]{#4}{#5}%
		}%
	\else
		\pgfplotscolormapfind@precomputed@[#1:#2][#3]{#4}{#5}%
	\fi
}

\def\pgfplotscolormapfind@precomputed@warn@LUA#1{%
	\expandafter\ifx\csname pgfplotscolormapfind@precomputed@warn@LUA@#1\endcsname\relax
		\pgfplotswarning{lua colormap unavailable}{#1}\pgfeov%
		\expandafter\gdef\csname pgfplotscolormapfind@precomputed@warn@LUA@#1\endcsname{1}%
	\fi
}%
\def\pgfplotscolormapfind@transform[#1:#2][#3]#4#5{%
	\edef\pgfplots@loc@TMPa{#1:#2}%
	\edef\pgfplots@loc@samerange{0:\pgfplotscolormaprange}%
	\ifx\pgfplots@loc@TMPa\pgfplots@loc@samerange
		% we have phi(#4) = #4  because #4 in [0:1000].
		\pgfmathfloatparsenumber{#4}%
		\pgfmathfloattofixed\pgfmathresult
	\else
		% Step 0: compute #3 if it is missing and write it into \pgfplots@loc@TMPa.
%\message{mapping '#4' into colormap '#5' with range [#1:#2] ... ^^J}%
		\pgfmathfloatparsenumber{#1}%
		\let\pgfplots@L=\pgfmathresult
		%
		\def\pgfplots@loc@TMPa{#3}%
		\ifx\pgfplots@loc@TMPa\pgfutil@empty
			\pgfmathfloatparsenumber{#2}%
			\let\pgfplots@R=\pgfmathresult
			\pgfmathfloatsubtract@{\pgfplots@R}{\pgfplots@L}%
			\let\pgfplots@loc@TMPb=\pgfmathresult
			\pgfmathfloatdivide@{\pgfplotscolormaprange@float}{\pgfplots@loc@TMPb}%
		\else
			\pgfmathfloatparsenumber{#3}%
		\fi
		\let\pgfplots@loc@TMPa=\pgfmathresult
		%
		% Step 1: perform lookup. Map #4 into the colormap's range
		% using the linear trafo
		% phi(#4) = ( #4 - #1 ) / (#2-#1) * colormaprange(#5).
		% This, determine the INTERVAL number into which #4 falls.
		\pgfmathfloatparsenumber{#4}%
		\let\pgfplots@V=\pgfmathresult
		\pgfmathfloatsubtract@{\pgfplots@V}{\pgfplots@L}%
		\expandafter\pgfmathfloatmultiply@\expandafter{\pgfmathresult}{\pgfplots@loc@TMPa}%
		\pgfmathfloattofixed\pgfmathresult
	\fi
	\ifdim\pgfmathresult pt<0pt %
		\def\pgfmathresult{0}%
	\else
		\ifdim\pgfmathresult pt>1000pt %
			\def\pgfmathresult{1000}%
		\fi
	\fi
}%
\def\pgfplotscolormapfind@precomputed@[#1:#2][#3]#4#5{%
	\pgfplotscolormapassertexists{#5}%
	\begingroup
	\pgfplotscolormapfind@transform[#1:#2][#3]{#4}{#5}%
	\let\pgfplotscolormapfind@transformedx=\pgfmathresult
	%
	% Now, we have it in [0,1000]. Find the correct interval:
	\pgfplotscolormapifisuniform{#5}{%
		\pgfmathmultiply@{\pgfplotscolormapfind@transformedx}{\csname pgfpl@cm@#5@invh\endcsname}%
		\let\pgfplotscolormapfind@transformedx@divh=\pgfmathresult
		% assign \pgfplotscolormapfind@intervalno := \pgfmathresult
		% without '.0' suffix:
		\expandafter\pgfplotscolormap@floor@unforgiving\pgfmathresult\relax
		% Step 2: interpolate the desired RGB value using vector valued
		% interpolation on the identified interval.
		\c@pgf@counta=\pgfplotscolormapfind@intervalno\relax
		% color^m(x) = ( (x-x_i)/(x_{i+1} - x_i) ) * (c_{i+1}^m - c_i^m ) + c_i^m
		%            = ( x/h - i ) * ( c_{i+1}^m - c_{i}^m ) + c_i^m
		%            = s * c_{i+1}^m  + S * c_i^m
		%
		%  s= x_h / h -i
		\pgfmathsubtract@{\pgfplotscolormapfind@transformedx@divh}{\pgfplotscolormapfind@intervalno}%
		\let\pgfplots@loc@factor=\pgfmathresult
	}{%
		\pgfplotsarraybinarysearch{pgfpl@cm@#5@X}{\pgfplotscolormapfind@transformedx}{0}{\pgfplotscolormapsizeof{#5}}%
		\c@pgf@counta=\pgfplotsretval\relax
		\ifnum\c@pgf@counta<0
			% as per definition of \pgfplotsarraybinarysearch, a
			% negative result indicates the "insertion point" ...
			\c@pgf@counta=-\c@pgf@counta
			% ... plus one.
			\advance\c@pgf@counta by-1
			%
			% But we do not WANT the insertion point! We want the LEFT
			% interval boundary!
			\advance\c@pgf@counta by-1
		\fi
		%
		% color^m(x) = ( (x-x_i)/(x_{i+1} - x_i) ) * (c_{i+1}^m - c_i^m ) + c_i^m
		%            = s * c_{i+1}^m  + S * c_i^m
		%
		%  s = (x - x_i) / (x_{i+1} - x_i)
		\begingroup
		\pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5@X}\to\pgfplotscolormapfind@rgb@X@left
		\advance\c@pgf@counta by1
		\ifnum\c@pgf@counta<\pgfplotsarraysizeof{pgfpl@cm@#5} %
			% ok, we really have an interval
			\pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5@X}\to\pgfplotscolormapfind@rgb@X@right
			%
			\pgfmathsubtract@{\pgfplotscolormapfind@rgb@X@right}{\pgfplotscolormapfind@rgb@X@left}%
			\let\pgfplotscolormapfind@h=\pgfmathresult
			\pgfmathsubtract@{\pgfplotscolormapfind@transformedx}{\pgfplotscolormapfind@rgb@X@left}%
			\let\pgfplots@loc@TMPa=\pgfmathresult
			\pgfmathdivide@{\pgfplots@loc@TMPa}{\pgfplotscolormapfind@h}%
			\let\pgfplots@loc@factor=\pgfmathresult
		\else
			% irrelevant (not used)
			\def\pgfplots@loc@factor{1}%
		\fi
		\pgfmath@smuggleone\pgfplots@loc@factor
		\endgroup
	}%
	% POSTCONDITION: \c@pgf@counta is the index of the LEFT interval
	%                and \pgfplots@loc@factor is the factor for the linear interpolation.
	%
%\message{mapping [#1,#2] -> [0,\pgfplotscolormaprange]  yielded phi(#4) = \pgfplotscolormapfind@transformedx, situated in interval no \the\c@pgf@counta.^^J}%
	\pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5}\to\pgfplotscolormapfind@rgb@LEFT
	%
	% do the stuff which is specific to linear interpolation:
	%
	%  S = 1 - s
	\pgfmathsubtract@{1}{\pgfplots@loc@factor}%
	\let\pgfplots@loc@factor@two=\pgfmathresult
	%
	\advance\c@pgf@counta by1 %
	\ifnum\c@pgf@counta<\pgfplotsarraysizeof{pgfpl@cm@#5} %
		% Ah: (selected index < length)  . That means: we have an interval.
		\pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5}\to\pgfplotscolormapfind@rgb@RIGHT
%\message{After lookup: the corresponding RGB interval boundaries are [\pgfplotscolormapfind@rgb@LEFT: \pgfplotscolormapfind@rgb@RIGHT].^^J}%
		%
		%
		\pgfplotscolorzero{\csname pgfpl@cm@#5@col@comps\endcsname}%
		\pgfplotscoloraddweighted
			{\csname pgfpl@cm@#5@col@comps\endcsname}%
			{\pgfplotsretval}%
			{\pgfplots@loc@factor@two}%
			{\pgfplotscolormapfind@rgb@LEFT}%
		\pgfplotscoloraddweighted
			{\csname pgfpl@cm@#5@col@comps\endcsname}%
			{\pgfplotsretval}%
			{\pgfplots@loc@factor}%
			{\pgfplotscolormapfind@rgb@RIGHT}%
		\let\pgfmathresult=\pgfplotsretval
	\else
		% Ah: selected index = last index. Use the rightmost color!
		\let\pgfmathresult=\pgfplotscolormapfind@rgb@LEFT
	\fi
	\pgfmath@smuggleone\pgfmathresult
	\endgroup
%\message{-> got finally mapping(#4, #5) = RGB'\pgfmathresult'.}%
}%


% Maps the number #4 into the colormap #5 using piecewise constant
% interpolation. It returns the interpolated colors into \pgfmathresult. The result will be a triple
% for an RGB colormap and it will contain four numbers for CMYK. The
% components of the result will be in the range [0:1].
%
% [#1:#2]  the number range of the data source (i.e. of #4). This is required to
%          map into the colormap.
% [#3]     (optional) the quantity
% 			 s := \pgfplotscolormaprange / (#2-#1).
% 		   Precomputing this quantity may save a lot of time because
% 		   divisions are expensive in TeX. You can omit [#3] or
% 		   provide an empty string here.
% #4       the number to map.
% #5       the colormap's name. Must be defined with
%          \pgfplotscreatecolormap before.
%
% Example:
% \pgfplotscolormapfindpiecewiseconst[-1:1]{0.2}{my colormap}
\def\pgfplotscolormapfindpiecewiseconst[#1:#2]{%
	\pgfutil@ifnextchar[{%
		\pgfplotscolormapfindpiecewiseconst@precomputed[#1:#2]%
	}{%
		\pgfplotscolormapfindpiecewiseconst@precomputed[#1:#2][]%
	}%
}%
\def\pgfplotscolormapfindpiecewiseconst@precomputed[#1:#2][#3]#4#5{%
	\ifpgfplots@LUA@supported
		\pgfplotscolormapifisuniform{#5}{%
			\edef\pgfmathresult{%
				\pgfplotsutil@directlua{%
					pgfplots.texColorMapFindPiecewiseConst("#5", #1,#2,#4)
				}%
			}%
			\ifx\pgfmathresult\pgfutil@empty
				\pgfplotscolormapfindpiecewiseconst@precomputed@warn@LUA{#5}%
				\pgfplotscolormapfindpiecewiseconst@precomputed@[#1:#2][#3]{#4}{#5}%
			\else
				%\message{LUA colormapfindpiecewiseconst[#1:#2](#4)(#5) = \pgfmathresult^^J}%
			\fi
		}{%
			% FIXME : implement LUA for non-uniform colormaps
			\pgfplotscolormapfindpiecewiseconst@precomputed@[#1:#2][#3]{#4}{#5}%
		}%
	\else
		\pgfplotscolormapfindpiecewiseconst@precomputed@[#1:#2][#3]{#4}{#5}%
	\fi
}

\def\pgfplotscolormapfindpiecewiseconst@precomputed@warn@LUA#1{%
	\expandafter\ifx\csname pgfplotscolormapfindpiecewiseconst@precomputed@warn@LUA@#1\endcsname\relax
		\pgfplotswarning{lua colormap unavailable}{#1}\pgfeov%
		\expandafter\gdef\csname pgfplotscolormapfindpiecewiseconst@precomputed@warn@LUA@#1\endcsname{1}%
	\fi
}%

\def\pgfplotscolormapfindpiecewiseconst@precomputed@[#1:#2][#3]#4#5{%
	\pgfplotscolormapassertexists{#5}%
	\begingroup
	\pgfplotscolormapfind@transform[#1:#2][#3]{#4}{#5}%
	\let\pgfplotscolormapfind@transformedx=\pgfmathresult
	%
	% Now, we have it in [0,1000]. Find the correct interval:
	% In principle, we could easily find the correct interval. But the
	% native approach has one distinct disadvantage: we will never
	% assign the rightmost color unless #4=1000! That means that our
	% colormap is not used entirely.
	%
	% I decided to enlarge the colormap artificially such that the
	% rightmost color receives its own interval.
	%
	% To this end, I recompute the coordinates at which colors "live".
	% The operations sounds more involved than it is: I simply need a NEW mesh width locally
	% inside of this function. The new mesh width H can be computed as
	% follows, assuming that the OLD colormap has mesh width h.
	%
	% H := 1000/ (N-1)
	%
	% N := n+1
	% n := 1000/h + 1 = \pgfplotscolormapsizeof{#5}
	%
	% what I really need is:
	%  1/H = N/1000 = (1000 h^{-1} +1)/ 1000 = h^{-1} + 1/1000
	%
	\pgfplotscolormapifisuniform{#5}{%
		%
		\expandafter\ifx\csname pgfpl@cm@#5@X@scale@order@z\endcsname\pgfutil@empty%
			% compute 1/H here:
			\pgfmathadd@{\csname pgfpl@cm@#5@invh\endcsname}{0.001}%
			\let\pgfplots@piecewiseconst@invh=\pgfmathresult%
		\else
			% disable the extra interval
			\expandafter\let\expandafter\pgfplots@piecewiseconst@invh\csname pgfpl@cm@#5@invh\endcsname
		\fi
		\pgfmathmultiply@{\pgfplotscolormapfind@transformedx}{\pgfplots@piecewiseconst@invh}%
		\let\pgfplotscolormapfind@transformedx@divh=\pgfmathresult
		% assign \pgfplotscolormapfind@intervalno := \pgfmathresult
		% without '.0' suffix:
		\expandafter\pgfplotscolormap@floor\pgfmathresult\relax
		% Step 2: interpolate the desired RGB value using vector valued
		% interpolation on the identified interval.
		\c@pgf@counta=\pgfplotscolormapfind@intervalno\relax
	}{%
		% the same idea can also be applied to non-uniform grids.
		% However, it is more involved here.
		%
		% My idea is that I add an extra interval of length 'h' at the right end of
		% the domain, i.e. I enlarge the domain to [0,1000+h].
		%
		% To this end, I map the input number linearly from
		%  [0,1000] -> [0,1000+h]
		% using k(t) = (1000+h)/1000 * t
		%
		% Note that k(t) = 1/ pgfpl@cm@#5@X@scale@order@z
		%
		% and search in the existing X coordinates of the colormap.
		% Note that these X coordinates actually do not contain the
		% artifical rightmost boundary point at 1000+h. But that is
		% ok, we plan to assign COLOR(1000+h) := COLOR(1000) anyway.
		%
		% Naturally, some values 'k(t)' will be BEYOND '1000'. In this
		% case, we simply use the rightmost interval and are done with
		% it.
		%
		% compute k(t):
		\ifdim\csname pgfpl@cm@#5@X@scale@order@z\endcsname pt>0pt
			\pgfmathadd@{1000}{\csname pgfpl@cm@#5@h\endcsname}%
			\pgf@xa=\pgfmathresult pt %
			\divide\pgf@xa by1000 %
			\edef\pgfplotscolormapfind@map@to@extra@interval{\pgf@sys@tonumber\pgf@xa}%
			%
			\pgfmathmultiply@{\pgfplotscolormapfind@transformedx}{\pgfplotscolormapfind@map@to@extra@interval}%
			\let\pgfplotscolormapfind@transformedx@=\pgfmathresult
		\else
			% disable the extra interval
			\let\pgfplotscolormapfind@transformedx@=\pgfplotscolormapfind@transformedx
		\fi
		%
		% search k(t) in the original X values.
		\pgfplotsarraybinarysearch{pgfpl@cm@#5@X}{\pgfplotscolormapfind@transformedx@}{0}{\pgfplotscolormapsizeof{#5}}%
		\c@pgf@counta=\pgfplotsretval\relax
		\ifnum\c@pgf@counta<0
			% as per definition of \pgfplotsarraybinarysearch, a
			% negative result indicates the "insertion point" ...
			\c@pgf@counta=-\c@pgf@counta
			% ... plus one.
			\advance\c@pgf@counta by-1
			%
			% But we do not WANT the insertion point! We want the LEFT
			% interval boundary!
			\advance\c@pgf@counta by-1
		\fi
%\pgfplotscolormapserializeXtomacro{#5}\XXX
%\message{k(\pgfplotscolormapfind@transformedx) = \pgfplotscolormapfind@transformedx@. Searching for value in X=(\XXX) resulted in \pgfplotsretval, and the index to use is \the\c@pgf@counta.^^J}%
	}%
	%
	\ifnum\c@pgf@counta=\pgfplotscolormapsizeof{#5}\relax
		% we have artificially increased the "h" (see the comments
		% above) -- meaning that this 'if' can happen.
		% ->Map the rightmost point to the rightmost interval:
		\advance\c@pgf@counta by-1
	\fi
	%
%\message{mapping [#1,#2] -> [0,\pgfplotscolormaprange]  yielded phi = \pgfplotscolormapfind@transformedx, situated in interval no \the\c@pgf@counta/\pgfplotsarraysizeof{pgfpl@cm@#5}.^^J}%
	\pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#5}\to\pgfplotscolormapfind@rgb@LEFT
	\let\pgfmathresult=\pgfplotscolormapfind@rgb@LEFT
	\pgfmath@smuggleone\pgfmathresult
	\endgroup
}

\def\pgfplotscolormap@floor#1.#2\relax{%
	\ifdim0.#2pt>0.999pt
		% ok, it is ALMOST one more! Take this as rounding inaccuracy
		\c@pgf@counta=#1\relax
		\advance\c@pgf@counta by1
		\edef\pgfplotscolormapfind@intervalno{\the\c@pgf@counta}%
	\else
		\def\pgfplotscolormapfind@intervalno{#1}%
	\fi
}%

\def\pgfplotscolormap@floor@unforgiving#1.#2\relax{%
	\def\pgfplotscolormapfind@intervalno{#1}%
}%

% Performs a direct color access into color map '#2' using an index
% '#1'.
%
% #1: an index in the range 0 ... len(#2)-1.
%  If it does not match, it will be pruned. If #1 is a real number, it
%  will be truncated.
% #2: a color map name.
%
% The resulting RGB value will be written to \pgfmathresult.
\def\pgfplotscolormapgetindex#1#2{%
	\pgfplotscolormapassertexists{#2}%
	\begingroup
	\pgfmathfloatparsenumber{#1}%
	\expandafter\pgfmathfloattoint\expandafter{\pgfmathresult}%
	%\afterassignment\pgfplots@gobble@until@relax
	\c@pgf@counta=\pgfmathresult\relax
	\ifnum\c@pgf@counta<0
		\c@pgf@counta=0
	\else
		\pgfplotsarraysizetomacro{pgfpl@cm@#2}\to\pgfplotscolormapgetindex@
		\ifnum\c@pgf@counta<\pgfplotscolormapgetindex@\relax
		\else
			\c@pgf@counta=\pgfplotscolormapgetindex@\relax
			\advance\c@pgf@counta by-1
		\fi
	\fi
	\pgfplotsarrayselect\c@pgf@counta\of{pgfpl@cm@#2}\to\pgfmathresult
	\pgfmath@smuggleone\pgfmathresult
	\endgroup
}

% Invokes one of \pgfplotscolormapfind,
% \pgfplotscolormapfindpiecewiseconst, or \pgfplotscolormapgetindex,
% depending on the value of '/pgfplots/colormap access'.
\def\pgfplotscolormapaccess[#1:#2]{%
	\pgfutil@ifnextchar[{%
		\pgfplotscolormapaccess@precomputed[#1:#2]%
	}{%
		\pgfplotscolormapaccess@precomputed[#1:#2][]%
	}%
}
\def\pgfplotscolormapaccess@precomputed[#1:#2][#3]#4#5{%
	\if m\pgfplots@colormap@access
		% colormap access=map
		\pgfplotscolormapfind@precomputed[#1:#2][#3]{#4}{#5}%
	\else
		\if c\pgfplots@colormap@access
			% colormap access=piecewise constant
			\pgfplotscolormapfindpiecewiseconst@precomputed[#1:#2][#3]{#4}{#5}%
		\else
			% colormap access=direct
			\pgfplotscolormapgetindex{#4}{#5}%
		\fi
	\fi
}%

\pgfutil@definecolor{mapped color}{rgb}{0,0,0}% make sure this color exists. It will be overwritten if needed.
% ATTENTION: replicated in pgfplots.code.tex :
\pgfplotscreatecolormap{hot}{color(0cm)=(blue); color(1cm)=(yellow); color(2cm)=(orange); color(3cm)=(red)}


\def\pgfplotspointmetatransformedrange{0:1000}

% Defines the 'mapped color' on the basis of
% the current color map.
%
% #1: is the value which should be mapped into the color map; it
% is expected in the range [0,1000] (like point meta).
\def\pgfplotscolormapdefinemappedcolor#1{%
	\expandafter\pgfplotscolormapaccess\expandafter[\pgfplotspointmetatransformedrange]%
		[1.0]%
		{#1}%
		{\pgfkeysvalueof{/pgfplots/colormap name}}%
%\message{Color for current point is RGB '\pgfmathresult' (determined using meta 'phi(\pgfplotspointmeta) = \pgfplotspointmetatransformed')^^J}%
	\def\pgfplots@loc@TMPb{\pgfutil@definecolor{mapped color}{\csname pgfpl@cm@\pgfkeysvalueof{/pgfplots/colormap name}@colspace\endcsname}}%
	\expandafter\pgfplots@loc@TMPb\expandafter{\pgfmathresult}%
}%