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
|
%--------------------------------------------
%
% Package pgfplotstable
%
% Provides support to read and work with abstact numeric tables of the
% form
%
% COLUMN1 COLUMN2 COLUMN3
% 1 2 3
% 4 4 552
% 1e124 0.00001 1.2345e-12
% ...
%
% Copyright 2007-2010 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/>.
%
%--------------------------------------------
% This file provides a high-level table manipulation and typesetting
% package.
%
%
% ---------------------------------------------
% Implementation notes for programmers:
% ---------------------------------------------
%
% The table data structure consists of
% 1. A name which must be a valid TeX macro like '\table'
% 2. A column list in the \pgfplotslist format.
% In fact, the column list is stored in the table's name:
% \pgfplotslistnewempty\table
% 3. A "file name" stored in
% \csname\string<\namemacro>@@table@name\endcsname
% 4. A "scan line length" number stored in
% \csname\string<\namemacro>@@table@scanline\endcsname
% It contains the value of \pgfplotsscanlinelength which has
% been identified right after \pgfplotstableread.
% 5. foreach column, there is a list of row-values (a row-vector) in
% the \pgfplotslist format named
% \csname\string<\namemacro>@<column name>\endcsname
%
\newif\ifpgfplotstable@search@header
\newif\ifpgfplotstable@firstline@is@header
\newcount\c@pgfplotstable@counta
\newtoks\t@pgfplotstable@a
\newif\ifpgfplots@addplotimpl@readcompletely
% should always be false; use only in grouped internal macros
\newif\ifpgfplots@table@options@areset
\newif\ifpgfplots@tableread@to@listener
\newif\ifpgfplots@tableread@use@begingroup
\newif\ifpgfplotstable@trimcells
\newif\ifpgfplotstable@percent@is@letter
\newif\ifpgfplotstable@search@path@implicit@CWD
\pgfkeys{%
/pgfplots/table/every table/.style={},
/pgfplots/table/.unknown/.code={%
\pgfplotstable@error@pkg{Sorry, I do not know the key `\pgfkeyscurrentkeyRAW' and I am going to ignore it. Perhaps you need \string\usepackage{pgfplotstable}? (The table typesetting parts are a separate package)}%
},%
/pgfplots/table/header/.is choice,
/pgfplots/table/header/true/.code={\pgfplotstable@firstline@is@headerfalse\pgfplotstable@search@headertrue},
/pgfplots/table/header/false/.code={\pgfplotstable@firstline@is@headerfalse\pgfplotstable@search@headerfalse},
/pgfplots/table/header/has colnames/.code={\pgfplotstable@firstline@is@headertrue\pgfplotstable@search@headerfalse},
/pgfplots/table/header=true,
/pgfplots/table/search path/.initial=.,
/pgfplots/table/search path/implicit ./.is if=pgfplotstable@search@path@implicit@CWD,
/pgfplots/table/search path/implicit .=true,
/pgfplots/table/x index/.initial=0,
/pgfplots/table/x/.initial=,
/pgfplots/table/x expr/.initial=,
/pgfplots/table/y index/.initial=1,
/pgfplots/table/y/.initial=,
/pgfplots/table/y expr/.initial=,
/pgfplots/table/z index/.initial=2,
/pgfplots/table/z/.initial=,
/pgfplots/table/z expr/.initial=,
/pgfplots/table/meta index/.initial=,
/pgfplots/table/meta/.initial=,
/pgfplots/table/meta expr/.initial=,
/pgfplots/table/x error index/.style={
x error plus index={#1},%
x error minus index={#1}%
},
/pgfplots/table/y error index/.style={
y error plus index={#1},%
y error minus index={#1}%
},
/pgfplots/table/z error index/.style={
z error plus index={#1},%
z error minus index={#1}%
},
/pgfplots/table/x error/.style={
x error plus={#1},%
x error minus={#1}%
},
/pgfplots/table/y error/.style={
y error plus={#1},%
y error minus={#1}%
},
/pgfplots/table/z error/.style={
z error plus={#1},%
z error minus={#1}%
},
/pgfplots/table/x error expr/.style={
x error plus expr={#1},%
x error minus expr={#1}%
},
/pgfplots/table/y error expr/.style={
y error plus expr={#1},%
y error minus expr={#1}%
},
/pgfplots/table/z error expr/.style={
z error plus expr={#1},%
z error minus expr={#1}%
},
/pgfplots/table/x error plus index/.initial=,
/pgfplots/table/y error plus index/.initial=,
/pgfplots/table/z error plus index/.initial=,
/pgfplots/table/x error plus/.initial=,
/pgfplots/table/y error plus/.initial=,
/pgfplots/table/z error plus/.initial=,
/pgfplots/table/x error plus expr/.initial=,
/pgfplots/table/y error plus expr/.initial=,
/pgfplots/table/z error plus expr/.initial=,
/pgfplots/table/x error minus index/.initial=,
/pgfplots/table/y error minus index/.initial=,
/pgfplots/table/z error minus index/.initial=,
/pgfplots/table/x error minus/.initial=,
/pgfplots/table/y error minus/.initial=,
/pgfplots/table/z error minus/.initial=,
/pgfplots/table/x error minus expr/.initial=,
/pgfplots/table/y error minus expr/.initial=,
/pgfplots/table/z error minus expr/.initial=,
/pgfplots/table/ignore chars/.initial=,
/pgfplots/table/white space chars/.initial=,
/pgfplots/table/text special chars/.initial=,
/pgfplots/table/percent is letter/.is if=pgfplotstable@percent@is@letter,
/pgfplots/table/comment chars/.initial=,
/pgfplots/table/skip first n/.initial=0,
/pgfplots/table/trim cells/.is if=pgfplotstable@trimcells,
/pgfplots/table/trim cells/.default=true,
/pgfplots/table/read completely/.is choice,
/pgfplots/table/read completely/true/.code= \pgfplots@addplotimpl@readcompletelytrue\def\pgfplots@addplotimpl@readcompletely@auto{0},
/pgfplots/table/read completely/false/.code=\pgfplots@addplotimpl@readcompletelyfalse\def\pgfplots@addplotimpl@readcompletely@auto{0},
/pgfplots/table/read completely/auto/.code=\pgfplots@addplotimpl@readcompletelyfalse\def\pgfplots@addplotimpl@readcompletely@auto{1},
/pgfplots/table/read completely/.default=true,
/pgfplots/table/read completely=auto,
/pgfplots/table/text indicator/.initial=,
/pgfplots/table/col sep/.is choice,
/pgfplots/table/col sep/space/.code = {\def\pgfplotstableread@COLSEP@CASE{0}},
/pgfplots/table/col sep/comma/.code = {\def\pgfplotstableread@COLSEP@CASE{1}},
/pgfplots/table/col sep/semicolon/.code = {\def\pgfplotstableread@COLSEP@CASE{2}},
/pgfplots/table/col sep/colon/.code = {\def\pgfplotstableread@COLSEP@CASE{3}},
/pgfplots/table/col sep/braces/.code = {\def\pgfplotstableread@COLSEP@CASE{4}},
/pgfplots/table/col sep/tab/.code = {\def\pgfplotstableread@COLSEP@CASE{5}},
/pgfplots/table/col sep/&/.code = {\def\pgfplotstableread@COLSEP@CASE{6}\pgfplotstable@trimcellstrue},
/pgfplots/table/col sep/ampersand/.code = {\def\pgfplotstableread@COLSEP@CASE{6}\pgfplotstable@trimcellstrue},
/pgfplots/table/col sep=space,
/pgfplots/table/format/.is choice,
/pgfplots/table/format/auto/.code = {\def\pgfplotstableread@FORMAT@CASE{0}},
/pgfplots/table/format/inline/.code = {\def\pgfplotstableread@FORMAT@CASE{1}},
/pgfplots/table/format/file/.code = {\def\pgfplotstableread@FORMAT@CASE{2}},
/pgfplots/table/format=auto,
/pgfplots/table/row sep/.code={%
\pgfplotsutilifstringequal{#1}{\\}{%
\def\pgfplotstableread@ROWSEP@CASE{1}%
}{%
\pgfplotsutilifstringequal{#1}{crcr}{%
\def\pgfplotstableread@ROWSEP@CASE{1}%
}{%
\pgfplotsutilifstringequal{#1}{newline}{%
\def\pgfplotstableread@ROWSEP@CASE{0}%
}{%
{%
\t@pgfplots@tokc={#1}%
\pgfplotsthrow{invalid argument}{\pgfplots@loc@TMPa}{Sorry, the choice `row sep=\the\t@pgfplots@tokc' is not known. Maybe you misspelled it? Try `\string\\' or `newline'.}\pgfeov%
}%
}%
}%
}%
},%
/pgfplots/table/row sep=newline,
}
\pgfkeys{
% #1: the argument which should have been assigned.
% #2: an error message.
/pgfplots/exception/non unique colname/.code 2 args={%
\ifx\pgfplotsexceptionmsg\relax
\pgfplots@error{#2}%
\else
\pgfplots@error{\pgfplotsexceptionmsg}%
\fi
\let#1=\pgfutil@empty
},%
/pgfplots/exception/table columns unbalanced/.code={%
\ifx\pgfplotsexceptionmsg\relax
\pgfplots@error{#1}%
\else
\pgfplots@error{\pgfplotsexceptionmsg}%
\fi
},
}
% \pgfplotstableread[OPTIONS] {FILE} to \name
%
% This method reads a table from FILE to macro \name.
%
% FILE is something like
% G Basis dof L2 A Lmax cgiter maxlevel eps
% 5 5 5 8.31160034e-02 0.00000000e+00 1.80007647e-01 2 2 -1
% 17 17 17 2.54685628e-02 0.00000000e+00 3.75580565e-02 5 3 -1
% ...
%
% A number format line is also understood:
% G Basis dof L2 A Lmax cgiter maxlevel eps
% $flags int int int sci:8 sci:8 sci:8 int int std:8
% 5 5 5 8.31160034e-02 0.00000000e+00 1.80007647e-01 2 2 -1
%
% or a three-column-gnuplot file with 2 comment headers like
% #Curve 0, 20 points
% #x y type
% 0.00000 0.00000 i
% 0.52632 0.50235 i
%
% The table data is stored columnwise in lists and can be accessed
% with the other methods of this package.
%
% \pgfplotstableread[<options>]{<file>}{<\macro>}
% \pgfplotstableread[<options>]{<file>} to listener{<\macro>}
% \pgfplotstableread* ...
%
% The '*' does not protect its local variables with TeX groups,
% everything is added to the current scope (useful to the 'to
% listener' thing.
%
% The 'to listener' variant does NOT assemble a table data structure.
% Instead, it processes the input table row-wise and invokes <\macro>
% after each complete row. During the evaluation of <\macro>, the
% following methods can be used to query values:
% \pgfplotstablereadgetcolindex{<index>}{<\macro>}
% \pgfplotstablereadgetcolname{<name>}{<\macro>}
% \pgfplotstablereadvalueofcolname{<name>}
% \pgfplotstablereadvalueofcolindex{<index>}
% \thisrow{<name>} (equivalent to \pgfplotstablereadvalueofcolname)
% \getthisrow{<name>}{<\macro>} (equivalent to \pgfplotstablereadgetcolname)
% \thisrowno{<index>} (equivalent to \pgfplotstablereadvalueofcolindex)
% \getthisrowno{<index>}{<\macro>}
% \pgfplotstableforeachcolumn\as{<\iteratemacro>}{<loop body>}
% (the '\as' is required directly after
% \pgfplotstableforeachcolumn in this context)
% Attention: 'to listener' is scoped by TeX groups, so any assignments
% need to be done globally (or with aftergroup magic).
%
% More remarks about scoping:
% \pgfplotstableread to listener works as follows:
% \begingroup
% // load table
% while file has more lines:
% load line, read every column;
% invoke listener;
% repeat
% \endgroup
%
% In short: all invocations of listener have the same level of
% scoping: they are inside of one TeX group. But single listener
% invocations as such are not scoped. Make sure you don't
% accidentally overwrite one of the internals in listener. And: make
% sure you don't change temporary registers without scoping them!
%
% Note: this command also updates \pgfplotsscanlinelength.
\def\pgfplotstableread{%
\pgfutil@ifnextchar*{%
\pgfplots@tableread@use@begingroupfalse
\pgfplotstableread@impl@star
}{%
\pgfplots@tableread@use@begingrouptrue
\pgfplotstableread@impl@star*%
}%
}%
\def\pgfplotstableread@impl@star*{%
\pgfutil@ifnextchar[{%
\pgfplotstableread@impl
}{%
\pgfplotstableread@impl[]%
}%
}
% BACKWARDS COMPATIBILITY
\let\pgfnumtableread=\pgfplotstableread
% Invokes #2 if '#1' is an already loaded table and #3 if not.
\long\def\pgfplotstable@isloadedtable#1#2#3{%
\ifcase\pgfplotstableread@ROWSEP@CASE\relax
% row sep=newline
\let\pgfplots@loc@TMPa=\pgfplotstableread@NL@other%
\or
% row sep=crcr
\def\pgfplots@loc@TMPa{\\}%
\fi
%
\expandafter\pgfutil@in@\expandafter{\pgfplots@loc@TMPa}{#1}%
\ifpgfutil@in@
% Hah! it contains the row separator! This is NO macro name!
% -> it is an inline table definition. Don't try to
% assemble a macro name (may run into out-of-memory)
#3\relax%
\else
% ok, the early-out was not met. Make check:
\pgfplotsutil@ifdefinedui@withsuffix{#1}{@@table@name}{#2}{#3}%
\fi
}%
% If the colum name `#1' is a `create on use' speicifcation, #2 is
% invoked, #3 otherwise.
\long\def\pgfplotstableifiscreateonuse#1#2#3{%
\pgfkeysifdefined{/pgfplots/table/create on use/#1/.@cmd}{#2}{%
\pgfutil@in@{create col/}{#1}%
\ifpgfutil@in@
#2%
\else
#3%
\fi
}%
}%
% Defines \pgfplotsretval to be a column name which does not already
% occur in the column names of table #1.
\def\pgfplotstablegenerateuniquecolnamefor#1{%
\begingroup
\c@pgf@countd=0
\pgfplotstableforeachcolumn{#1}\as\pgfplots@loc@TMPa{%
\def\pgfplots@loc@TMPa{\pgfplots@loc@TMPa}%
\edef\pgfplots@loc@TMPb{autocol\the\c@pgf@countd}%
\ifx\pgfplots@loc@TMPa\pgfplots@loc@TMPb
\advance\c@pgf@countd by1
\fi
}%
\edef\pgfplotsretval{autocol\the\c@pgf@countd}%
\pgfmath@smuggleone\pgfplotsretval
\endgroup
}
% Returns a column vector in form of \pgfplotslist
% into #3.
%
% #1: the column name (not a macro)
% #2: the table structure
% #3: the output macro name.
%
% @throw `no such element' on error
\def\pgfplotstablegetcolumnbyname#1\of#2\to#3{%
\let#3=\pgfutil@empty% just for sanity checking.
\pgfplotstable@getcol{#1}\of{#2}\to{#3}\getcolmethod{STD}%
}
% Declares a new getcolmethod class #1.
% The argument '#1' can then be used as argument for
% \pgfplotstable@getcol...\getcolmethod{#1}.
%
% #2: a set of keys which redefine the behavior.
% See below for available choices.
\def\pgfplotstable@definegetcolmethod#1#2{%
\edef\pgfplotstable@definegetcolmethod@{#1}%
\pgfqkeys{/pgfplots/table/@getcol}{%
% Checks if column '#1' exists in table `#2' and invokes `#3' if that
% is the case and `#4' if not.
%
% Note that the check is only for physically existent colums, no alias
% or create on use is checked here.
% #1: colname
% #2: table struct
% #3: true code
% #4: false code
% FIXME : THIS IS BUGGY: the macro may exist, but is it
% (still) part of the table!? Currently, there is a workaround
% such that \pgfplotstablenew cleans up and avoids that case..
% and we have no "drop column" currently.
ifexists =\pgfutil@ifundefined{\string##2@##1}{##4}{##3},
%
% Low level method to return (the actual content) of column #1 of
% table #2 to macro #3.
% #1: colname
% #2: table struct
% #3: result macro
getexisting =\expandafter\let\expandafter##3\csname\string##2@##1\endcsname,
%
% no arguments, the value is a boolean (0 or 1)
createonuse =1,
%
% error handling.
% #1: colname
% #2: table struct
% #3: result macro
lazyforbidden=\pgfplotstablegetcolumnbyname@impl@createonuseforbidden{##1}\of{##2}\to{##3},
noalias =\pgfplotstablegetcolumnbyname@impl@nosuchalias{##1}\of{##2}\to{##3},
nocol =\pgfplotstablegetcolumnbyname@impl@nocolumn{##1}\of{##2}\to{##3},
#2%
}%
}%
\pgfqkeys{/pgfplots/table/@getcol}{%
ifexists/.code ={\expandafter\def\csname pgfplotstable@getcol@ifexists@\pgfplotstable@definegetcolmethod@\endcsname##1\of##2##3##4{#1}},%
getexisting/.code ={\expandafter\def\csname pgfplotstable@getcol@getexisting@\pgfplotstable@definegetcolmethod@\endcsname##1\of##2\to##3{#1}},%
createonuse/.code ={\expandafter\def\csname pgfplotstable@getcol@createonuse@\pgfplotstable@definegetcolmethod@\endcsname{#1}},%
lazyforbidden/.code ={\expandafter\def\csname pgfplotstable@getcol@lazyforbidden@\pgfplotstable@definegetcolmethod@\endcsname##1\of##2\to##3{#1}},%
noalias/.code ={\expandafter\def\csname pgfplotstable@getcol@noalias@\pgfplotstable@definegetcolmethod@\endcsname##1\of##2\to##3{#1}},%
nocol/.code ={\expandafter\def\csname pgfplotstable@getcol@nocol@\pgfplotstable@definegetcolmethod@\endcsname##1\of##2\to##3{#1}},%
}%
\pgfplotstable@definegetcolmethod{STD}{}%
\pgfplotstable@definegetcolmethod{getptr}{%
ifexists =\pgfutil@ifundefined{pgfplotstblread@colindex@for@name#1}{#4}{#3},%
getexisting =\edef#3{\csname pgfplotstblread@colindex@for@name#1\endcsname},%
}
\pgfplotstable@definegetcolmethod{resolvename}{%
getexisting =\edef#3{#1},%
}
% The low level implementation of \pgfplotstablegetcolumnbyname.
%
% #4: is a getcolmethod declared with \pgfplotstable@definegetcolmethod
%
% ATTENTION: this macro should be expandable! It is also used inside
% of \thisrow{}.
\def\pgfplotstable@getcol#1\of#2\to#3\getcolmethod#4{%
\csname pgfplotstable@getcol@ifexists@#4\endcsname{#1}\of{#2}{%
\csname pgfplotstable@getcol@getexisting@#4\endcsname{#1}\of{#2}\to#3%
}{%
% Oh, there is no column '#1' in table '#2'!
%
% Ok, then check for special features.
%
% 1. 'create col/...'
% 2. 'create on use'
% 3. 'alias'
%
% WARNING : this code has been REPLICATED in
% *** \pgfplotstablereadvalueofcolname ***
\if1\csname pgfplotstable@getcol@createonuse@#4\endcsname%
\pgfutil@in@{create col/}{#1}%
\ifpgfutil@in@
\pgfplotstablegenerateuniquecolnamefor{#2}%
\def\pgfplotstable@loc@TMPa##1{%
\pgfkeysdef{/pgfplots/table/create on use/##1}{\pgfkeysalso{#1}}%
\pgfplotstablecreatecol[/pgfplots/table/create on use/##1]{##1}{#2}%
% and return the newly generated col:
\csname pgfplotstable@getcol@getexisting@#4\endcsname{##1}\of{#2}\to#3%
}%
\expandafter\pgfplotstable@loc@TMPa\expandafter{\pgfplotsretval}%
\else
\pgfplotstable@getcol@next{#1}\of{#2}\to{#3}\getcolmethod{#4}%
\fi
\else
\pgfplotstable@getcol@next{#1}\of{#2}\to{#3}\getcolmethod{#4}%
\fi
}%
}%
\def\pgfplotstable@getcol@next#1\of#2\to#3\getcolmethod#4{%
\pgfkeysifdefined{/pgfplots/table/create on use/#1/.@cmd}{%
% aah - a 'create on use' style exists. Apply it!
\if1\csname pgfplotstable@getcol@createonuse@#4\endcsname%
\pgfplotstablecreatecol[/pgfplots/table/create on use/#1]{#1}{#2}%
% and return the newly generated col:
\csname pgfplotstable@getcol@getexisting@#4\endcsname{#1}\of{#2}\to#3%
\else
\csname pgfplotstable@getcol@lazyforbidden@#4\endcsname{#1}\of{#2}\to#3%
\fi
}{%
% ok, then it is either an alias or it simply doesn't exist
\pgfkeysifdefined{/pgfplots/table/alias/#1}{%
\csname pgfplotstable@getcol@ifexists@#4\endcsname{\pgfkeysvalueof{/pgfplots/table/alias/#1}}\of{#2}{%
\csname pgfplotstable@getcol@getexisting@#4\endcsname{\pgfkeysvalueof{/pgfplots/table/alias/#1}}\of{#2}\to#3%
}{%
\csname pgfplotstable@getcol@noalias@#4\endcsname{#1}\of{#2}\to{#3}%
}%
}{%
\csname pgfplotstable@getcol@nocol@#4\endcsname{#1}\of{#2}\to{#3}%
}%
}%
}
\def\pgfplotstablegetcolumnbyname@impl@createonuseforbidden#1\of#2\to#3{%
\pgfplotstablegetcolumnbyname@impl@nocolumn@{#1}\of{#2}\to{#3}\pgfplotstablegetcolumnbyname@impl@createonuseforbiddentext@
}
\def\pgfplotstablegetcolumnbyname@impl@createonuseforbiddentext@#1{%
\space Note that I found a 'create on use/#1' style, but unfortunately, I can't evaluate it in this context. Please use the 'read completely' key such that it is processed earlier (see the manual for details)%
}%
\def\pgfplotstablegetcolumnbyname@impl@createonuseforbiddentext@disable#1{}%
\def\pgfplotstablegetcolumnbyname@impl@nosuchalias#1\of#2\to#3{
\pgfplotstablegetcolumnbyname@impl@nosuchalias@{#1}\of{#2}\to{#3}\pgfplotstablegetcolumnbyname@impl@createonuseforbiddentext@disable
}%
\def\pgfplotstablegetcolumnbyname@impl@nosuchalias@#1\of#2\to#3#4{%
\pgfplotsthrow{no such element}{#3}{Sorry, could not retrieve aliased column '\pgfkeysvalueof{/pgfplots/table/alias/#1}' from table '\pgfplotstablenameof{#2}'. The original request was for '#1', which does not exist either.#4{#1}}\pgfeov%
}%
\def\pgfplotstablegetcolumnbyname@impl@nocolumn#1\of#2\to#3{%
\pgfplotstablegetcolumnbyname@impl@nocolumn@{#1}\of{#2}\to{#3}\pgfplotstablegetcolumnbyname@impl@createonuseforbiddentext@disable
}%
\def\pgfplotstablegetcolumnbyname@impl@nocolumn@#1\of#2\to#3#4{%
\pgfplotsthrow{no such element}{#3}{Sorry, could not retrieve column '#1' from table '\pgfplotstablenameof{#2}'. Please check spelling (or introduce name aliases).#4{#1}}\pgfeov%
}%
% Retrieves the column *NAME* '#1' of table #2 and writes it into
% '#3'.
%
% If there is no such column, column aliases will be checked. Finally
% if there are no aliases, the command fails with an error.
%
% The 'create on use' statements can't be used in this context.
% @see \pgfplotstablegetcolumnbyname
%
% #1: a column name (not a macro)
% #2: the table structure
% #3: a macro name which will be filled with the (probably modified)
% column name into #2.
\def\pgfplotstableresolvecolname#1\of#2\to#3{%
\let#3=\pgfutil@empty% just for sanity checking.
\pgfplotstable@getcol{#1}\of{#2}\to{#3}\getcolmethod{resolvename}%
}
% Invokes either \pgfplotstablegetcolumnbyindex or
% \pgfplotstablegetcolumnbyname.
%
% #1: either a column name, alias or create on use specification, or
% [index]<integer> denoting a column index.
% #2: either a loaded table or a table macro.
% #3: a macro name which will be filled with the column, in the format
% accepted of \pgfplotslist...
\long\def\pgfplotstablegetcolumn#1\of#2\to#3{%
\begingroup
\pgfplotstable@isloadedtable{#2}{%
\pgfplotstablegetcolumnfromstruct{#1}\of{#2}\to{#3}%
}{%
\pgfplotstableread{#2}\pgfplotstable@tmptbl
\pgfplotstablegetcolumnfromstruct{#1}\of\pgfplotstable@tmptbl\to{#3}%
}%
\pgfmath@smuggleone#3%
\endgroup
}%
\def\pgfplotstablegetcolumnfromstruct#1\of#2\to#3{%
\def\pgfplotstable@loc@TMPc{#1}%
\pgfplotstable@is@colname{\pgfplotstable@loc@TMPc}%%
\ifpgfplotstableread@foundcolnames
\else
\expandafter\pgfplotstablegetcolumnnamebyindex\pgfplotstable@loc@TMPc\of{#2}\to\pgfplotstable@loc@TMPc
\fi
\expandafter\pgfplotstablegetcolumnbyname\pgfplotstable@loc@TMPc\of#2\to{#3}%
}%
% Defines #3 to be the column name of the column with index '#1'.
%
% #1: a column index (starting with 0)
% #2: a loaded table structure
% #3: an output macro name.
\def\pgfplotstablegetcolumnnamebyindex#1\of#2\to#3{%
\pgfplotslistselect#1\of#2\to#3\relax
}%
% Defines #3 to be the column index of the column with name '#1'.
%
% #1: a column name
% #2: a loaded table structure
% #3: an output macro name which will be filled with the index (or -1
% if there is no such index)
\def\pgfplotstablegetcolumnindexforname#1\of#2\to#3{%
\def#3{-1}%
\edef\pgfplotstablegetcolumnindexforname@@{#1}%
\pgfplotstableforeachcolumn{#2}\as\pgfplotstablegetcolumnindexforname@{%
\relax
\ifx\pgfplotstablegetcolumnindexforname@\pgfplotstablegetcolumnindexforname@@
\edef#3{\pgfplotstablecol}%
\fi
}%
}%
\def\pgfplotstablegetcolumnbyindex#1\of#2\to#3{%
\pgfplotslistselect#1\of#2\to#3\relax
\expandafter\pgfplotstablegetcolumnbyname#3\of#2\to{#3}%
}
\def\pgfplotstablecopy#1\to#2{%
\let#2=#1%
\pgfplotstablegetname#1\pgfplotstable@loc@TMPa
\expandafter\let\csname\string#2@@table@name\endcsname=\pgfplotstable@loc@TMPa
\expandafter\edef\csname\string#2@@table@scanline\endcsname{\pgfplotstablescanlinelengthof{#1}}%
\pgfplotslistforeachungrouped#1\as\pgfplotstable@loc@TMPa{%
\def\pgfplotstable@loc@TMPb{%
\expandafter\let\csname\string#2@\pgfplotstable@loc@TMPa\endcsname}%
\expandafter\pgfplotstable@loc@TMPb\csname\string#1@\pgfplotstable@loc@TMPa\endcsname
}%
}
% Returns the file name of table '#1' into macro #2.
\def\pgfplotstablegetname#1#2{%
\expandafter\let\expandafter#2\csname\string#1@@table@name\endcsname
}
% expands to the table file name of table '#1'
\def\pgfplotstablenameof#1{%
\csname\string#1@@table@name\endcsname
}
% Returns the value of \pgfplotsscanlinelength for table '#1' into
% macro #2.
\def\pgfplotstablegetscanlinelength#1#2{%
\expandafter\let\expandafter#2\csname\string#1@@table@scanline\endcsname
}%
% Expands to the scan line length of table '#1'.
\def\pgfplotstablescanlinelengthof#1{\csname\string#1@@table@scanline\endcsname}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IMPLEMENTATION
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newif\ifpgfplotstableread@curline@contains@colnames
\newif\ifpgfplotstableread@foundcolnames
\newif\ifpgfplotstableread@skipline
% A method which is necessary to work with inline table data.
%
% It does nothing if format=file.
%
% It needs to be invoked BEFORE the inline table data has been
% seen the first time. "Seen" means collected as argument!
%
% The macro changes \catcodes in order to implement the 'row sep=newline',
% some special 'col sep' choices and the 'ignore chars' features.
%
% ATTENTION: this changes the processing of ALL following newline
% characters.
% @see \pgfplotstablecollectoneargwithpreparecatcodes
\def\pgfplotstablereadpreparecatcodes{%
\ifx\pgfplotstablereadrestorecatcodes\relax
\edef\pgfplotstablereadrestorecatcodes{%
\noexpand\pgfplotstableuninstallignorechars
\noexpand\catcode`\noexpand\^^M=\the\catcode`\^^M\noexpand\space
\noexpand\catcode`\noexpand\ =\the\catcode`\ \noexpand\space
\noexpand\catcode`\noexpand\;=\the\catcode`\;\noexpand\space
\noexpand\catcode`\noexpand\:=\the\catcode`\:\noexpand\space
\noexpand\catcode`\noexpand\%=\the\catcode`\%\noexpand\space
\noexpand\catcode`\noexpand\^^I=\the\catcode`\^^I\noexpand\space
\noexpand\let\noexpand\pgfplotstablereadrestorecatcodes=\noexpand\relax
}%
\ifcase\pgfplotstableread@FORMAT@CASE\relax
% format=auto
\pgfplotstablereadpreparecatcodes@
\or
% format=inline
\pgfplotstablereadpreparecatcodes@
\fi
\fi
}
\let\pgfplotstablereadrestorecatcodes=\relax
% ATTENTION: the following catcodes are ONLY useful for <inline tables>!
% tables read from file need catcode adaptions as well; this is done
% elsewhere!
\def\pgfplotstablereadpreparecatcodes@{%
\if0\pgfplotstableread@ROWSEP@CASE\relax
% row sep = newline
\catcode`\^^M=12
\fi
\ifcase\pgfplotstableread@COLSEP@CASE\relax
% col sep=space:
\catcode`\ =10
\or
% col sep=comma:
\or
% col sep=semicolon:
\catcode`\;=12
\or
% col sep=colon:
\catcode`\:=12
\or
% col sep=brace:
\or
% col sep=tab:
\catcode`\^^I=12
\fi
\pgfplotstableinstallignorechars
}%
% Logically, this routine does
% \pgfplotstablereadpreparecatcodes
% #1
% and that's all. However, It makes sure that any white space
% characters (especially newlines) between '#1' and the following
% argument are gobbled!
%
% To show the problem, consider
% \pgfplotstabletypeset[<options>]
% \loadedtable
%
% and we want to set the catcodes *before* \loadedtable is seen.
% Well, there is a newline character after ']'! If we change the
% catcodes, this newline will be considered as character and will make
% up the first argument, the \loadedtable will be ignored.
%
% \pgfplotstablecollectoneargwithpreparecatcodes avoids this problem
% by gobbling all space (newline) characters *before* collecting the
% directly following argument token. Furthermore, it restores the
% catcodes directly after the argument has been collected.
%
% @see \pgfplotstablecollectoneargwithpreparecatcodesnorestore
\long\def\pgfplotstablecollectoneargwithpreparecatcodes#1{%
\begingroup
\t@pgfplotstable@a{{#1}}% this allows '#' characters in '#1'
\def\pgfplotstablecollectoneargwithpreparecatcodes@@{%
\pgfplotstablereadpreparecatcodes
\expandafter\pgfplotstablecollectoneargwithpreparecatcodes@end\the\t@pgfplotstable@a%
}%
% equivalent to
%\let\pgfplotstable@loc@TMPa=<next token>\pgfplotstablecollectoneargwithpreparecatcodes@@<next token>
\futurelet\pgfplotstable@loc@TMPa\pgfplotstablecollectoneargwithpreparecatcodes@@
% this employs a side effect: \futurelet gobbles any spaces
% (including newlines).
}%
\long\def\pgfplotstablecollectoneargwithpreparecatcodes@end#1#2{%
\endgroup
#1{#2}%
}%
% An overloaded method of
% \pgfplotstablecollectoneargwithpreparecatcodes which does not
% restore the catcodes after collecting one arg.
\long\def\pgfplotstablecollectoneargwithpreparecatcodesnorestore#1{%
\t@pgfplotstable@a{{#1}}%
\def\pgfplotstablecollectoneargwithpreparecatcodes@@{%
\expandafter\pgfplotstablereadpreparecatcodes\t@pgfplotstable@a
}%
% equivalent to
%\let\pgfplotstable@loc@TMPa=<next token>\pgfplotstablecollectoneargwithpreparecatcodes@@<next token>
\futurelet\pgfplotstable@loc@TMPa\pgfplotstablecollectoneargwithpreparecatcodes@@
}%
% Accept one of
% \pgfplotstableread[#1]{<file>}{<\macro>}
% \pgfplotstableread[#1]{<file>} to listener{<\macro>}
% or
% \pgfplotstableread[#1]{<file>} to {<\macro>} (DEPRECATED)
\long\def\pgfplotstableread@impl[#1]{%
\ifpgfplots@tableread@use@begingroup
\begingroup
\def\endgroup@@pgfplotstableread{\endgroup}%
\else
\let\endgroup@@pgfplotstableread=\relax%
\fi
% set options here, although we can't evaluate 'every table' yet
% (the file name is not yet known).
% But #1 may contain input format specifiers which are important
% for \catcodes, BEFORE we have read the second argument:
\pgfplotstableset{#1}%
%
\pgfplotstablecollectoneargwithpreparecatcodes{%
\pgfplotstableread@impl@collectfirstarg{#1}%
}%
}%
\long\def\pgfplotstableread@impl@collectfirstarg#1#2{%
\pgfplotsutil@ifnextchar t{%
\pgfplotstableread@impl@@{#1}{#2}%
}{%
\pgfplotstableread@impl@{#1}{#2}%
}%
}%
% I don't know why; but I started with
% >> \pgfplotstableread[]{file} to \macro
% That ' to ' is really ugly. This here is for backwards
% compatibility:
\long\def\pgfplotstableread@impl@@#1#2to {%
\pgfutil@ifnextchar l{%
\pgfplotstableread@impl@@listener{#1}{#2}%
}{%
\pgfplotstableread@impl@{#1}{#2}%
}%
}%
\long\def\pgfplotstableread@impl@@listener#1#2listener#3{%
\pgfplots@tableread@to@listenertrue
\pgfplotstableread@impl@{#1}{#2}{#3}%
\pgfplots@tableread@to@listenerfalse
}%
\newif\ifpgfplotstableread@inline
\long\def\pgfplotstableread@checkinlineformat@CRCR#1\\#2\pgfplotstable@EOI{%
\def\pgfplotstable@loc@TMPa{#2}%
\ifx\pgfplotstable@loc@TMPa\pgfutil@empty
\pgfplotstableread@inlinefalse
\else
\pgfplotstableread@inlinetrue
\let\pgfplotstableread@loop@next=\pgfplotstableread@loop@next@CRCR
\fi
}%
\long\def\pgfplotstableread@loop@next@CRCR#1\\{%
\long\def\pgfplotstable@LINE{#1}%
\pgfplotstableread@loop@processnextline
\pgfplotstableread@loop@over@lines
}%
\begingroup
\catcode`\^^M=12\relax%
\gdef\pgfplotstableread@NL@other{^^M}%
\long\gdef\pgfplotstableread@checkinlineformat@NL@#1^^M#2\pgfplotstable@EOI{%
\def\pgfplotstable@loc@TMPa{#2}%
\ifx\pgfplotstable@loc@TMPa\pgfutil@empty%
\pgfplotstableread@inlinefalse%
\else%
\pgfplotstableread@inlinetrue%
\let\pgfplotstableread@loop@next=\pgfplotstableread@loop@next@NL%
\fi%
}%
\long\gdef\pgfplotstableread@checkinlineformat@NL#1{%
\pgfplotstableread@checkinlineformat@NL@ #1^^M\pgfplotstable@EOI%
}%
\long\gdef\pgfplotstableread@loop@next@NL#1^^M{%
\long\def\pgfplotstable@LINE{#1}%
\pgfplotstableread@loop@processnextline%
\pgfplotstableread@loop@over@lines%
}%
\endgroup
% #1: options.
% #2: the table content (file name or inline data)
% #3: the result macro.
\long\def\pgfplotstableread@impl@#1#2#3{%
\ifcase\pgfplotstableread@FORMAT@CASE\relax
% format=auto
\ifcase\pgfplotstableread@ROWSEP@CASE\relax
% row sep=newline
\pgfplotstableread@checkinlineformat@NL{#2}%
\or
% row sep=crcr
\pgfplotstableread@checkinlineformat@CRCR #2\\\pgfplotstable@EOI
\fi
\or
% format=inline
\pgfplotstableread@inlinetrue
\ifcase\pgfplotstableread@ROWSEP@CASE\relax
% row sep=newline
\let\pgfplotstableread@loop@next=\pgfplotstableread@loop@next@NL
\or
% row sep=crcr
\let\pgfplotstableread@loop@next=\pgfplotstableread@loop@next@CRCR
\fi
\or
\pgfplotstableread@inlinefalse
\fi
%
\ifpgfplotstableread@inline
\else
\if1\pgfplotstableread@ROWSEP@CASE
% row sep=crcr
\pgfplotsthrow{unsupported operation}{Sorry, the choice 'row sep=crcr' is currently only available for inline tables, not for external files}\pgfeov
\fi
\fi
%
% optimizations:
\pgfkeysgetvalue{/pgfplots/table/comment chars}\pgfplots@loc@TMPd
\ifx\pgfplots@loc@TMPd\pgfutil@empty
\let\pgfplotstableread@checkspecial@line@default=\relax
\fi
\pgfkeysgetvalue{/pgfplots/table/skip first n}\pgfplots@loc@TMPd
\ifx\pgfplots@loc@TMPd\pgfutil@empty \let\pgfplotstableread@check@skipfirstn=\relax \fi
\ifnum\pgfplots@loc@TMPd=0 \let\pgfplotstableread@check@skipfirstn=\relax \fi
%
\ifpgfplotstableread@inline
\def\pgfplotstableread@impl@fCLOSE{}%
\let\pgfplotstableread@loop@over@lines=\pgfplotstableread@loop@over@lines@frominline%
\long\def\pgfplotstableread@start@loop{%
\pgfplotstableread@loop@over@lines #2\pgfplotstable@EOI
}%
\def\pgfplotstableread@ready{1}%
\def\pgfplotstableread@filename{<inline_table>}%
\else
\def\pgfplotstableread@ready{1}%
\def\pgfplotstableread@filename{#2}%
\pgfplotstableread@openfile
\def\pgfplotstableread@impl@fCLOSE{%
\closein\r@pgfplots@reada
}%
\let\pgfplotstableread@loop@over@lines=\pgfplotstableread@loop@over@lines@fromfile%
\def\pgfplotstableread@start@loop{\pgfplotstableread@loop@over@lines}%
\pgfplotstableinstallignorechars
\fi
\edef\pgfplotstableread@oldendlinechar{\the\endlinechar}%
\endlinechar=-1 % do not append a white space after each line for file input
%\pgfplots@message{ATTEMPTING TO READ \pgfplotstableread@filename}%
%
\def\pgfplots@loc@TMPa{\pgfplotstableread@impl@prepare{#1}}%
\expandafter\pgfplots@loc@TMPa\expandafter{\pgfplotstableread@filename}{#3}%
%
\if1\pgfplotstableread@ready
\pgfplotstableread@start@loop
%
\pgfplotstableread@impl@fCLOSE%
%
\pgfplotstableread@finish
%
\fi
\endlinechar=\pgfplotstableread@oldendlinechar
\pgfplotsscanlinelengthcleanup
\expandafter\pgfplotstable@copy@to@globalbuffers@simple\expandafter{\pgfplotstableread@filename}%
\endgroup@@pgfplotstableread
\ifpgfplots@tableread@to@listener
% there are no data structures in this case.
\let\pgfplotsscanlinelength=\pgfplotstable@glob@buf@scanline
\else
% Now, we can access the global variables!
% copy them to #3.
\pgfplotstable@copy@globalbuffers@to#3%
\fi
}
{\catcode`\"=12 \gdef\pgfplots@dquote{"}}
% gets the search path (after applying some basic sanity checks)
\def\pgfplotstable@get@search@path{%
\pgfkeysgetvalue{/pgfplots/table/search path}\pgfplotsretval
\ifx\pgfplotsretval\pgfutil@empty
\def\pgfplotsretval{.}%
\pgfkeyslet{/pgfplots/table/search path}\pgfplotsretval
\fi
%
\ifpgfplotstable@search@path@implicit@CWD
\def\b@pgfplotstable@search@contains@cwd{0}%
\def\pgfplotstable@loc@TMPd{.}%
\def\pgfplotstable@loc@TMPc{./}%
\expandafter\pgfplotsutilforeachcommasep\expandafter{\pgfplotsretval}\as\pgfplotstable@loc@TMPa{%
\ifx\pgfplotstable@loc@TMPa\pgfplotstable@loc@TMPd
\def\b@pgfplotstable@search@contains@cwd{1}%
\fi
\ifx\pgfplotstable@loc@TMPa\pgfplotstable@loc@TMPc
\def\b@pgfplotstable@search@contains@cwd{1}%
\fi
}%
%
\if0\b@pgfplotstable@search@contains@cwd
\t@pgfplotstable@a=\expandafter{\pgfplotsretval}%
\edef\pgfplotsretval{.,\the\t@pgfplotstable@a}%
\pgfkeyslet{/pgfplots/table/search path}\pgfplotsretval
\fi
\fi
}
\def\pgfplotstable@search@path@add@slash#1{%
\def\pgfplotsretval{#1/}%
\def\pgfplotstable@loc@TMPd{./}%
\def\pgfplotstable@loc@TMPc{.//}%
\ifx\pgfplotsretval\pgfplotstable@loc@TMPd
% Ah -- we have #1='.' Do NOT use a slash at all in order to
% not disable the processing of TEXINPUTS (if pdftex finds ./
% , it will NOT evaluated TEXINPUTS as it seems)
\let\pgfplotsretval=\pgfutil@empty
\fi
\ifx\pgfplotsretval\pgfplotstable@loc@TMPc
\let\pgfplotsretval=\pgfutil@empty
\fi
}%
%
% POSTCONDITION:
% - \r@pgfplots@reada is the opened result file (or eof if there is no
% such file).
% - \pgfplotstableread@filename is the first found file path.
\def\pgfplotstable@search@and@open@file{%
\pgfplotstable@get@search@path
%
\let\pgfplotstableread@filename@name=\pgfplotstableread@filename
%
\def\b@pgfplotstable@search@done{0}%
\expandafter\pgfplotsutilforeachcommasep\expandafter{\pgfplotsretval}\as\pgfplotstable@loc@TMPa{%
\ifx\pgfplotstable@loc@TMPa\pgfutil@empty
% silently skip empty entries in the list.
\else
\if0\b@pgfplotstable@search@done
%
\expandafter\pgfplotstable@search@path@add@slash\expandafter{\pgfplotstable@loc@TMPa}%
%
\t@pgfplotstable@a=\expandafter{\pgfplotsretval}%
\t@pgfplots@tokc=\expandafter{\pgfplotstableread@filename@name}%
\edef\pgfplotstableread@filename{\the\t@pgfplotstable@a\the\t@pgfplots@tokc}%
%
\openin\r@pgfplots@reada=\pgfplotstableread@filename.tex
\ifeof\r@pgfplots@reada
\openin\r@pgfplots@reada=\pgfplotstableread@filename\relax
\else
\pgfplots@warning{%
You requested to open table '\pgfplotstableread@filename', but there is also a '\pgfplotstableread@filename.tex'.
TeX will automatically append the suffix '.tex', so I will now open '\pgfplotstableread@filename.tex'.
Please make sure you don't accidentally load TeX files - this may produce unrecoverable errors.}%
\closein\r@pgfplots@reada
\openin\r@pgfplots@reada=\pgfplotstableread@filename\relax
\fi
%
\ifeof\r@pgfplots@reada
\else
\def\b@pgfplotstable@search@done{1}%
\fi
\fi
\fi
}%
%
\if0\b@pgfplotstable@search@done
\let\pgfplotstableread@filename=\pgfplotstableread@filename@name
\fi
}%
% Opens \pgfplotstableread@filename.
\def\pgfplotstableread@openfile{%
\def\pgfplotstable@loc@TMPa{\pgfutil@in@{ }}%
\expandafter\pgfplotstable@loc@TMPa\expandafter{\pgfplotstableread@filename}%
\ifpgfutil@in@
\t@pgfplots@toka=\expandafter{\pgfplotstableread@filename}%
\edef\pgfplotstableread@filename{\pgfplots@dquote\the\t@pgfplots@toka\pgfplots@dquote}%
\fi
\let\pgfplotstableread@old@crcr=\\%
\def\\{\string\\}% just to make sure we don't try to open inline table data...
%
\pgfplotstable@search@and@open@file
%
\ifeof\r@pgfplots@reada
\pgfplotsthrow{no such table file}{\pgfplots@loc@TMPa}{\pgfplotstableread@filename}{Could not read table file '\pgfplotstableread@filename' in 'search path=\pgfkeysvalueof{/pgfplots/table/search path}'. In case you intended to provide inline data: maybe TeX screwed up your end-of-lines? Try `row sep=crcr' and terminate your lines with `\string\\' (refer to the pgfplotstable manual for details)}\pgfeov%
\global\let\pgfplotstable@colnames@glob=\pgfplots@loc@TMPa
\def\pgfplotstableread@ready{0}%
\fi
\pgfplots@logfileopen{\pgfplotstableread@filename}%
\let\\=\pgfplotstableread@old@crcr
}
\def\pgfplotstableinstallignorechars{%
\ifx\pgfplotstableuninstallignorechars\pgfutil@empty
\pgfkeysgetvalue{/pgfplots/table/ignore chars}\pgfplotstable@loc@TMPa
\ifx\pgfplotstable@loc@TMPa\pgfutil@empty
\else
\pgfplotstableinstallignorechars@\pgfplotstable@loc@TMPa{9}%
\fi
\pgfkeysgetvalue{/pgfplots/table/white space chars}\pgfplotstable@loc@TMPa
\ifx\pgfplotstable@loc@TMPa\pgfutil@empty
\else
\pgfplotstableinstallignorechars@\pgfplotstable@loc@TMPa{10}%
\fi
\pgfkeysgetvalue{/pgfplots/table/text special chars}\pgfplotstable@loc@TMPa
\ifx\pgfplotstable@loc@TMPa\pgfutil@empty
\else
\pgfplotstableinstallignorechars@\pgfplotstable@loc@TMPa{12}%
\fi
\ifpgfplotstable@percent@is@letter
\def\pgfplotstable@loc@TMPa{\%}%
\pgfplotstableinstallignorechars@\pgfplotstable@loc@TMPa{12}%
\fi
\ifx\pgfplotstableuninstallignorechars\pgfutil@empty
\else
\expandafter\def\expandafter\pgfplotstableuninstallignorechars\expandafter{%
\pgfplotstableuninstallignorechars
\let\pgfplotstableuninstallignorechars=\pgfutil@empty
}%
\fi
\fi
}%
\let\pgfplotstableuninstallignorechars\pgfutil@empty%
% #1 macro containing the characters as comma-separated list
% #2 the catcode to assign
\def\pgfplotstableinstallignorechars@#1#2{%
\expandafter\pgfplotsutilforeachcommasep\expandafter{#1}\as\pgfplotstable@loc@TMPa{%
\t@pgfplots@toka=\expandafter{\pgfplotstableuninstallignorechars}%
\edef\pgfplotstableuninstallignorechars{%
\the\t@pgfplots@toka
\noexpand\catcode`\expandafter\noexpand\pgfplotstable@loc@TMPa=\expandafter\the\expandafter\catcode\expandafter`\pgfplotstable@loc@TMPa\noexpand\space
}%
\expandafter\catcode\expandafter`\pgfplotstable@loc@TMPa=#2\relax
}%
}%
% #1: any options to set (respect \ifpgfplots@table@options@areset )
% #2: the file name (if any)
% #3: the output macro (or listener)
\def\pgfplotstableread@impl@prepare#1#2#3{%
\ifpgfplots@table@options@areset
\else
\pgfplotstableset@every@table{#2}{#1}%
\fi
%
\def\pgfplotstablename{\pgfplotstable@colnames@glob}% provide the name of the actual table struct (during \pgfplotstableread, only partial functionality is available!)
%
% local counter definitions:
\ifpgfplots@tableread@use@begingroup
\let\pgfplotstableread@lineno=\c@pgf@counta
\let\pgfplotstableread@numcols=\c@pgf@countb
\let\pgfplotstableread@curcol=\c@pgf@countc
\let\pgfplotstableread@usablelineno=\c@pgf@countd
\def\thepgfplotstableread@lineno{\the\pgfplotstableread@lineno}%
\def\thepgfplotstableread@usablelineno{\the\pgfplotstableread@usablelineno}%
\def\thepgfplotstableread@curcol{\the\pgfplotstableread@curcol}%
\def\thepgfplotstableread@numcols{\the\pgfplotstableread@numcols}%
\def\pgfplotstableread@countreset##1{##1=0 }%
\def\pgfplotstableread@countset##1##2{##1=##2\relax}%
\def\pgfplotstableread@countadvance##1{\advance##1 by1 }%
\else
% don't re-use integers! We have no protecting scopes!
\def\thepgfplotstableread@lineno{\pgfplotstableread@lineno}%
\def\thepgfplotstableread@usablelineno{\pgfplotstableread@usablelineno}%
\def\thepgfplotstableread@curcol{\pgfplotstableread@curcol}%
\def\thepgfplotstableread@numcols{\pgfplotstableread@numcols}%
\def\pgfplotstableread@countreset##1{\def##1{0}}%
\def\pgfplotstableread@countset##1##2{\def##1{##2}}%
\def\pgfplotstableread@countadvance##1{\pgfplotsutil@advancestringcounter{##1}}%
\fi
\pgfplotstableread@countreset\pgfplotstableread@lineno
\pgfplotstableread@countreset\pgfplotstableread@usablelineno
\pgfplotstableread@countreset\pgfplotstableread@numcols
\pgfplotstableread@countreset\pgfplotstableread@curcol
%
\pgfplotstableread@impl@prepare@DO
\pgfplotstableread@impl@prepare@DO@textindicator
%
\def\pgfplotstableread@isgnuplotformat{0}%
\global\pgfplotslistnewempty\pgfplotstable@colnames@glob
\pgfplotsscanlinelengthinitzero
\ifpgfplots@tableread@to@listener
\def\pgfplotstablerow{\thepgfplotstableread@usablelineno}%
\def\pgfplotstablelineno{\thepgfplotstableread@lineno}%
\let\pgfplotstable@listener=#3%
\let\pgfplotstableread@impl@nextrow@NEXT=\pgfplotstableread@impl@nextrow@NEXT@listener
\let\pgfplotstablereadgetcolindex=\pgfplotstablereadgetcolindex@
\let\pgfplotstablereadgetcolname=\pgfplotstablereadgetcolname@
\let\pgfplotstablereadgetptrtocolname=\pgfplotstablereadgetptrtocolname@
\let\pgfplotstablereadgetptrtocolindex=\pgfplotstablereadgetptrtocolindex@
\let\pgfplotstablereadevalptr=\pgfplotstablereadevalptr@
\let\pgfplotstablereadvalueofptr=\pgfplotstablereadvalueofptr@
\let\pgfplotstableforeachcolumn=\pgfplotstableforeachcolumn@listener
\let\pgfplotstablereadvalueofcolname=\pgfplotstablereadvalueofcolname@
\let\pgfplotstablereadvalueofcolindex=\pgfplotstablereadvalueofcolindex@
\let\getthisrow=\pgfplotstablereadgetcolname
\let\thisrow=\pgfplotstablereadvalueofcolname
\let\thisrowno=\pgfplotstablereadvalueofcolindex
\let\getthisrowno=\pgfplotstablereadgetcolindex
\fi
}%
% Copies the table column list and the column vectors of #1 to global buffers.
% @see \pgfplotstable@copy@globalbuffers@to
%
% Use these two methods to avoid scoping problems.
%
% #1: the <\macro> name of the table which is to be copied to global buffers.
% #2: the table file name.
\def\pgfplotstable@copy@to@globalbuffers#1#2{%
\global\let\pgfplotstable@colnames@glob=#1\relax
\c@pgfplotstable@counta=0\relax%
\pgfplotslistforeachungrouped\pgfplotstable@colnames@glob\as\pgfplotstable@loc@TMPa{%
\def\pgfplotstable@loc@TMPb{%
\expandafter\global\expandafter\let\csname pgfp@numtable@glob@col@\the\c@pgfplotstable@counta\endcsname%
}%
\expandafter\pgfplotstable@loc@TMPb\csname\string#1@\pgfplotstable@loc@TMPa\endcsname
\advance\c@pgfplotstable@counta by1\relax
}%
\pgfplotstable@copy@to@globalbuffers@simple{#2}%
}%
% A variant of \pgfplotstable@copy@to@globalbuffers which copies only
% the member variables of a loaded table (the name and scanline length) to
% global buffers.
%
% #1: the table's file name.
%
% @PRECONDITION: any other variables and cell data of the table are already stored
% in global buffers.
\def\pgfplotstable@copy@to@globalbuffers@simple#1{%
\gdef\pgfplotstable@glob@buf@name{#1}%
\global\let\pgfplotstable@glob@buf@scanline=\pgfplotsscanlinelength
}%
% copies the global column list and the global column vectors to #1
% (NOT the table file name).
% @see \pgfplotstable@copy@to@globalbuffers
%
% @PRECONDITION the global buffers contain all members of a table.
%
% @POSTCONDITION The table '#1' is be initialised to these members.
% Furthermore, \pgfplotsscanlinelength is set.
\def\pgfplotstable@copy@globalbuffers@to#1{%
\let#1=\pgfplotstable@colnames@glob
\c@pgfplotstable@counta=0\relax%
\pgfplotslistforeachungrouped\pgfplotstable@colnames@glob\as\pgfplotstable@loc@TMPa{%
\def\pgfplotstable@loc@TMPb{%
\expandafter\let\csname\string#1@\pgfplotstable@loc@TMPa\endcsname}%
\expandafter\pgfplotstable@loc@TMPb\csname pgfp@numtable@glob@col@\the\c@pgfplotstable@counta\endcsname
%\message{Column '\pgfplotstable@loc@TMPa' has entries: \expandafter\meaning\csname pgfp@numtable@glob@col@\the\c@pgfplotstable@counta\endcsname}%
\expandafter\global\expandafter\let\csname pgfp@numtable@glob@col@\the\c@pgfplotstable@counta\endcsname=\pgfutil@empty
\advance\c@pgfplotstable@counta by1\relax
}%
\global\let\pgfplotstable@colnames@glob=\pgfutil@empty
\expandafter\let\csname\string#1@@table@scanline\endcsname=\pgfplotstable@glob@buf@scanline
\expandafter\let\csname\string#1@@table@name\endcsname=\pgfplotstable@glob@buf@name
\let\pgfplotsscanlinelength=\pgfplotstable@glob@buf@scanline
}%
\def\pgfplotstableread@finish{%
\pgfplotsscanlinecomplete
\ifpgfplots@tableread@to@listener
\else
\ifpgfplotstableread@foundcolnames
\else
\pgfplotstableread@create@column@names@with@numbers
\fi
\pgfplotstableread@countreset\pgfplotstableread@curcol%
\pgfutil@loop
\ifnum\pgfplotstableread@curcol<\pgfplotstableread@numcols\relax
\expandafter\pgfplotsapplistXflushbuffers\csname pgfp@numtable@glob@col@\thepgfplotstableread@curcol\endcsname
\pgfplotstableread@countadvance\pgfplotstableread@curcol
\pgfutil@repeat
\fi
}
\def\pgfplotstableread@loop@over@lines@fromfile{%
\ifeof\r@pgfplots@reada
%\pgfplots@message{EOF}%
\else
\read\r@pgfplots@reada to\pgfplotstable@LINE
%\message{read with \the\catcode`\%: \meaning\pgfplotstable@LINE^^J}%
\ifeof\r@pgfplots@reada
\else
\pgfplotstableread@loop@processnextline
\fi
\expandafter\pgfplotstableread@loop@over@lines
\fi
}%
\def\pgfplotstableread@loop@over@lines@frominline{%
\pgfutil@ifnextchar\pgfplotstable@EOI{%
\pgfutil@gobble
}{%
\pgfplotstableread@loop@next
}%
}%
\def\pgfplotstableread@check@skipfirstn{%
\ifnum\pgfplotstableread@lineno<\pgfkeysvalueof{/pgfplots/table/skip first n} %
\pgfplotstableread@skiplinetrue
\fi
}%
% PRECONDITION:
% \pgfplotstable@LINE contains the current input line.
\def\pgfplotstableread@loop@processnextline{%
\expandafter\pgfplotstableread@checkspecial@line\pgfplotstable@LINE\pgfplotstable@EOI
\pgfplotstableread@check@skipfirstn
\ifpgfplotstableread@skipline
\def\pgfplotstableread@gnuplotcheck{####x y type}%
\ifx\pgfplotstableread@gnuplotcheck\pgfplotstable@LINE
\def\pgfplotstableread@isgnuplotformat{1}%
\fi
\def\pgfplotstableread@gnuplotcheck{####x y z type}%
\ifx\pgfplotstableread@gnuplotcheck\pgfplotstable@LINE
\def\pgfplotstableread@isgnuplotformat{1}%
\fi
\else
%--------------------------------------------------
% \ifnum\pgfplotstableread@lineno=0
% \let\pgfplotstable@firstline=\pgfplotstable@LINE
% \fi
%--------------------------------------------------
%\pgfplots@message{READING LINE \thepgfplotstableread@lineno: '\meaning\pgfplotstable@LINE'.}%
\pgfplotstableread@curline@contains@colnamesfalse
\ifnum\pgfplotstableread@numcols=0\relax
% STEP 0: initialise
% - count columns
% - find header data
\pgfplotstableread@countreset\pgfplotstableread@curcol
\ifpgfplotstable@firstline@is@header
\pgfplotstableread@curline@contains@colnamestrue
\fi
\pgfplotstableread@impl@DO\pgfplotstableread@impl@countcols@and@identifynames@NEXT\pgfplotstable@LINE
\pgfplotstableread@countset\pgfplotstableread@numcols{\pgfplotstableread@curcol}%
\edef\pgfplotstablecols{\thepgfplotstableread@numcols}%
\pgfplotstableread@countreset\pgfplotstableread@curcol
% Create empty column lists:
\pgfplotstableread@create@column@lists
%
\ifnum\pgfplotstableread@usablelineno=0\relax
\if1\pgfplotstableread@isgnuplotformat%
% The file started with
% #...
% #x y type
% X Y i
% -> thats a gnuplot file!
\pgfplotstableread@curline@contains@colnamesfalse
\fi
\fi
% Now, read the first line.
% It contains either
% - column names,
% - numerical data,
% - nothing (comments).
\ifpgfplotstableread@curline@contains@colnames
\pgfplotstableread@foundcolnamestrue
\pgfplotstableread@countreset\pgfplotstableread@curcol
\pgfplotstableread@impl@DO\pgfplotstableread@impl@collectcolnames@NEXT\pgfplotstable@LINE
\else
\pgfplotsscanlinelengthincrease
\pgfplotstableread@foundcolnamesfalse
\pgfplotstableread@countreset\pgfplotstableread@curcol
% Leave column name lists empty...
\pgfplotstableread@impl@DO\pgfplotstableread@impl@nextrow@NEXT\pgfplotstable@LINE
\fi
%\pgfplots@message{After reading first row: found '\thepgfplotstableread@numcols' columns; column name list='\meaning\pgfplotstable@colnames@glob'}%
\else
\pgfplotsscanlinelengthincrease
\pgfplotstableread@countreset\pgfplotstableread@curcol
\pgfplotstableread@impl@DO\pgfplotstableread@impl@nextrow@NEXT\pgfplotstable@LINE
\fi
\ifnum\pgfplotstableread@curcol=\pgfplotstableread@numcols\relax
\else
\begingroup
\t@pgfplots@tokc=\expandafter{\pgfplotstable@LINE}%
\pgfplotsthrow{table columns unbalanced}{input table '\pgfplotstableread@filename' has an unbalanced number of columns in row '\thepgfplotstableread@lineno' (expected '\thepgfplotstableread@numcols' cols; got '\thepgfplotstableread@curcol'). Maybe the input table is corrupted? If you need unbalanced data, consider using 'nan' in empty cells (perhaps combined with 'unbounded coords=jump'). The offending line is \the\t@pgfplots@tokc}\pgfeov%
\endgroup
\fi
\ifpgfplots@tableread@to@listener
\ifpgfplotstableread@curline@contains@colnames
\else
% report row!
\pgfplotstable@listener
\fi
\fi
\pgfplotstableread@countadvance\pgfplotstableread@usablelineno
\fi
\pgfplotstableread@countadvance\pgfplotstableread@lineno
}%
% WARNING: this routine is also used in pgfplots.code.tex ...
\def\pgfplotstableread@checkspecial@line{%
\futurelet\pgfplotstableread@tmp\pgfplotstableread@checkspecial@line@
}%
\def\pgfplotstableread@checkspecial@line@{%
\pgfplotstableread@skiplinefalse
\let\pgfplotstableread@checkspecial@line@@\pgfplotstableread@impl@gobble%
%
\let\pgfplotstableread@tmpb=##%
\ifx\pgfplotstableread@tmp\pgfplotstableread@tmpb
\pgfplotstableread@skiplinetrue
\else
\let\pgfplotstableread@tmpb=$%
\let\pgfplotstableread@tmpb=\pgfplotstable@EOI%
\ifx\pgfplotstableread@tmp\pgfplotstableread@tmpb
\pgfplotstableread@skiplinetrue
\pgfplotsscanlinecomplete% the line is empty; same as \par!
\else
\let\pgfplotstableread@tmpb=\par%
\ifx\pgfplotstableread@tmp\pgfplotstableread@tmpb
\pgfplotstableread@skiplinetrue
\pgfplotsscanlinecomplete% the line is empty;
\else
\pgfplotstableread@checkspecial@line@default%
\fi
\fi
\fi
\pgfplotstableread@checkspecial@line@@
}%
\def\pgfplotstableread@checkspecial@line@default{%
% this routine can be optimized away
\pgfkeysgetvalue{/pgfplots/table/comment chars}\pgfplots@loc@TMPd
\ifx\pgfplots@loc@TMPd\pgfutil@empty
\else
\expandafter\pgfplotsutilforeachcommasep\expandafter{\pgfplots@loc@TMPd}\as\pgfplots@loc@TMPd{%
\expandafter\let\expandafter\pgfplotstableread@tmpb\pgfplots@loc@TMPd
\ifx\pgfplotstableread@tmp\pgfplotstableread@tmpb
\pgfplotstableread@skiplinetrue
\fi
}%
\fi
}%
%--------------------------------------------------
% \def\pgfplotstableread@checkspecial@line{%
% \pgfutil@ifnextchar##{%
% \pgfplotstableread@skiplinetrue
% \pgfplotstableread@impl@gobble
% }{%
% \pgfutil@ifnextchar${%
% \pgfplotstableread@process@flags@line
% }{%
% \pgfutil@ifnextchar\pgfplotstable@EOI{%
% \pgfplotstableread@skiplinetrue
% \pgfplotsscanlinecomplete% the line is empty; same as \par!
% \pgfplotstableread@impl@gobble
% }{%
% \pgfutil@ifnextchar\par{%
% \pgfplotstableread@skiplinetrue
% \pgfplotsscanlinecomplete
% \pgfplotstableread@impl@gobble
% }{%
% \pgfplotstableread@skiplinefalse
% \pgfplotstableread@impl@gobble
% }%
% }%
% }%
% }%
% }
%--------------------------------------------------
\def\pgfplotstableread@create@column@lists{%
\pgfutil@loop
\ifnum\pgfplotstableread@curcol<\pgfplotstableread@numcols\relax
\def\pgfplots@loc@TMPa{\pgfplotsapplistXnewempty[to global]}%
\expandafter\pgfplots@loc@TMPa\csname pgfp@numtable@glob@col@\thepgfplotstableread@curcol\endcsname
\pgfplotstableread@countadvance\pgfplotstableread@curcol
\pgfutil@repeat
}
\def\pgfplotstableread@create@column@names@with@numbers{%
\pgfplotstableread@countreset\pgfplotstableread@curcol
\pgfutil@loop
\ifnum\pgfplotstableread@curcol<\pgfplotstableread@numcols\relax
\edef\pgfplotstable@loc@TMPb{\thepgfplotstableread@curcol}%
\expandafter\pgfplotslistpushbackglobal\pgfplotstable@loc@TMPb\to\pgfplotstable@colnames@glob
\pgfplotstableread@countadvance\pgfplotstableread@curcol
\pgfutil@repeat
}
\long\def\pgfplotstableread@impl@gobble#1\pgfplotstable@EOI{}%
\def\pgfplotstable@EOI{\pgfplotstable@EOI}%
% A loop command which processes every single entry in a raw data row #2
% and invokes the macro #1{<arg>} for each found column entry.
%
% Columns are separated by the /pgfplots/table/col sep character.
%
% #1: a command which takes precisely one argument. It will be called
% for each found column entry
%
% #2: a macro containing a raw data line with <col sep> separated
% entries.
\long\def\pgfplotstableread@impl@DO#1#2{%
\ifpgfplotstable@trimcells
\long\def\pgfplotstableread@impl@ITERATE@NEXT@##1{%
\pgfkeys@spdef\pgfplotstableread@impl@ITERATE@NEXT@@@{##1}%
\expandafter#1\expandafter{\pgfplotstableread@impl@ITERATE@NEXT@@@}%
}%
\else
\let\pgfplotstableread@impl@ITERATE@NEXT@=#1\relax
\fi
%
\expandafter\pgfplotstableread@impl@DO@\expandafter{#2}%
}
{%
\catcode`\ =10
\catcode`\;=12
\catcode`\:=12
\gdef\pgfplotstableread@impl@prepare@DO{%
\ifcase\pgfplotstableread@COLSEP@CASE\relax
% col sep=space:
\catcode`\ =10
\long\def\pgfplotstableread@impl@DO@##1{\pgfplotstableread@impl@ITERATE##1 \pgfplotstable@EOI}%
\or
% col sep=comma:
\let\pgfplotstableread@impl@ITERATE@NEXT=\pgfplotstableread@impl@ITERATE@NEXT@COMMA
\long\def\pgfplotstableread@impl@DO@##1{\pgfplotstableread@impl@ITERATE##1,\pgfplotstable@EOI}%
\or
% col sep=semicolon:
\catcode`\;=12
\let\pgfplotstableread@impl@ITERATE@NEXT=\pgfplotstableread@impl@ITERATE@NEXT@SEMICOLON
\long\def\pgfplotstableread@impl@DO@##1{\pgfplotstableread@impl@ITERATE##1;\pgfplotstable@EOI}%
\or
% col sep=colon:
\catcode`\:=12
\let\pgfplotstableread@impl@ITERATE@NEXT=\pgfplotstableread@impl@ITERATE@NEXT@COLON
\long\def\pgfplotstableread@impl@DO@##1{\pgfplotstableread@impl@ITERATE##1:\pgfplotstable@EOI}%
\or
% col sep=brace:
% allow multi line cells:
\endlinechar=\pgfplotstableread@oldendlinechar\relax
\let\pgfplotstableread@impl@ITERATE@NEXT=\pgfplotstableread@impl@ITERATE@NEXT@BRACE
\long\def\pgfplotstableread@impl@DO@##1{\pgfplotstableread@impl@ITERATE##1\pgfplotstable@EOI}%
\or
% col sep=tab:
\catcode`\^^I=12
\let\pgfplotstableread@impl@ITERATE@NEXT=\pgfplotstableread@impl@ITERATE@NEXT@TAB
\long\edef\pgfplotstableread@impl@DO@##1{\noexpand\pgfplotstableread@impl@ITERATE##1\pgfplotstableread@tab\noexpand\pgfplotstable@EOI}%
\or
% col sep=&:
\let\pgfplotstableread@impl@ITERATE@NEXT=\pgfplotstableread@impl@ITERATE@NEXT@AMPERSAND
\long\def\pgfplotstableread@impl@DO@##1{\pgfplotstableread@impl@ITERATE##1&\pgfplotstable@EOI}%
\fi
}%
}%
\def\pgfplotstableread@impl@prepare@DO@textindicator{%
%
\pgfkeysgetvalue{/pgfplots/table/text indicator}\pgfplots@loc@TMPa
\ifx\pgfplots@loc@TMPa\pgfutil@empty
% ok, nothing special.
\else
% protect the text indicator such that it won't be expanded:
\t@pgfplots@tokc=\expandafter{\pgfplots@loc@TMPa}%
%
% compile macros which handle 'text indicator':
\let\pgfplotstableread@impl@ITERATE@NEXT@aftertextindicator=\pgfplotstableread@impl@ITERATE@NEXT
\edef\pgfplotstableread@impl@ITERATE@NEXT{%
% check if the cell starts with a text indicator:
\noexpand\pgfplotstableread@impl@ITERATE@NEXT@checkindicator{\the\t@pgfplots@tokc}%
}%
\edef\pgfplots@loc@TMPb{%
% compile this macro which reads everything up to the next
% text indicator char:
\noexpand\def\noexpand\pgfplotstableread@impl@ITERATE@NEXT@collect@text####1\the\t@pgfplots@tokc{%
% append. we assume that 'tokc' has been reset before
% starting to collect the cell content.
\t@pgfplots@tokc=\noexpand\expandafter{\noexpand\the\t@pgfplots@tokc####1}%
\noexpand\pgfutil@ifnextchar{\the\t@pgfplots@tokc}{%
% ah - a doubled text indicator. gobble this one
% and collect the following one!
\noexpand\pgfplotstableread@impl@ITERATE@NEXT@collect@text@collect@one
}{%
% ok, we found the entire cell content.
\noexpand\pgfplotstableread@impl@ITERATE@NEXT@collect@text@finish
}%
}%
}%
\pgfplots@loc@TMPb
%
\ifcase\pgfplotstableread@COLSEP@CASE\relax
\let\pgfplotstableread@impl@ITERATE@NEXT@collect@text@finish=\pgfplotstableread@impl@ITERATE@NEXT@collect@text@finish@APPENDSPACE
\fi
\fi
}
\def\pgfplotstableread@impl@ITERATE@NEXT@collect@text@collect@one#1{%
\t@pgfplots@tokc=\expandafter{\the\t@pgfplots@tokc#1}%
\pgfplotstableread@impl@ITERATE@NEXT@collect@text
}%
\def\pgfplotstableread@impl@ITERATE@NEXT@collect@text@finish{%
% enclose the collected items into curly braces. This suppresses
% interpretation of extra chars:
\expandafter\pgfplotstableread@impl@ITERATE@NEXT@aftertextindicator\expandafter{\expandafter{\the\t@pgfplots@tokc}}%
}%
\def\pgfplotstableread@impl@ITERATE@NEXT@collect@text@finish@APPENDSPACE{%
% enclose the collected items into curly braces. This suppresses
% interpretation of extra chars:
\expandafter\pgfplotstableread@impl@ITERATE@NEXT@aftertextindicator\expandafter{\expandafter{\the\t@pgfplots@tokc}} %
}%
\long\def\pgfplotstableread@impl@ITERATE{%
\pgfutil@ifnextchar\pgfplotstable@EOI{%
\pgfplotstableread@impl@gobble
}{%
\pgfplotstableread@impl@ITERATE@NEXT
}%
}%
\def\pgfplotstableread@impl@ITERATE@NEXT@checkindicator#1{%
\pgfutil@ifnextchar{#1}{%
% Ah! Our cell starts with a text indicator! Assume it is
% enclosed by text indicators.
\pgfplotstableread@impl@ITERATE@NEXT@checkindicator@gobble@one%
}{%
% ok, Cell does not start with a text indicator. collect
% as-is, assuming that a text indicator does not simply occur
% within a cell which is not enclosed by text indicators:
\pgfplotstableread@impl@ITERATE@NEXT@aftertextindicator
}%
}%
\def\pgfplotstableread@impl@ITERATE@NEXT@checkindicator@gobble@one#1{%
\t@pgfplots@tokc={}%
\pgfplotstableread@impl@ITERATE@NEXT@collect@text%
}%
\long\def\pgfplotstableread@impl@ITERATE@NEXT#1 {%
\pgfplotstableread@impl@ITERATE@NEXT@{#1}%
\pgfplotstableread@impl@ITERATE
}%
\long\def\pgfplotstableread@impl@ITERATE@NEXT@COMMA#1,{%
\pgfplotstableread@impl@ITERATE@NEXT@{#1}%
\pgfplotstableread@impl@ITERATE
}%
\long\def\pgfplotstableread@impl@ITERATE@NEXT@SEMICOLON#1;{%
\pgfplotstableread@impl@ITERATE@NEXT@{#1}%
\pgfplotstableread@impl@ITERATE
}%
\long\def\pgfplotstableread@impl@ITERATE@NEXT@COLON#1:{%
\pgfplotstableread@impl@ITERATE@NEXT@{#1}%
\pgfplotstableread@impl@ITERATE
}%
\long\def\pgfplotstableread@impl@ITERATE@NEXT@BRACE#1{%
\pgfplotstableread@impl@ITERATE@NEXT@{#1}%
\pgfplotstableread@impl@ITERATE
}%
\long\def\pgfplotstableread@impl@ITERATE@NEXT@AMPERSAND#1&{%
\pgfplotstableread@impl@ITERATE@NEXT@{#1}%
\pgfplotstableread@impl@ITERATE
}%
\begingroup
\catcode`\^^I=12
\gdef\pgfplotstableread@tab{^^I}%
\long\gdef\pgfplotstableread@impl@ITERATE@NEXT@TAB#1^^I{% the following white spaces are SPACES, not tabs:
\pgfplotstableread@impl@ITERATE@NEXT@{#1}%
\pgfplotstableread@impl@ITERATE
}%
\endgroup
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% these values are only usable for a read-listener, that means:
% when using
%
% \pgfplotstableread{<file>} to listener<\macro>
%
% -> <\macro> can than use the methods
%
% \pgfplotstablereadgetcolindex{<index>}{<\content>}
% performs \let\content=<content of column no <index> >
\def\pgfplotstablereadgetcolindex@#1#2{%
\pgfutil@ifundefined{pgfplotstblread@colcontent@no#1}{%
\pgfplotsthrow{no such element}{#2}{Sorry, the requested column number '#1' in table '\pgfplotstableread@filename' does not exist!? Please verify you used the correct index 0 <= i < N.}\pgfeov%
}{%
\expandafter\let\expandafter#2\csname pgfplotstblread@colcontent@no#1\endcsname
}%
}%
\pgfkeysdef{/pgfplots/table/@undefined column text}{#1__column_not_found.}%
\def\pgfplotstable@undefinedtext#1{\pgfkeysvalueof{/pgfplots/table/@undefined column text/.@cmd}#1\pgfeov}%
% As \pgfplotstablereadgetcolindex, but
% \pgfplotstablereadvalueofcolindex{<index>}
% directly expands to the value stored in the desired column.
%
% Example:
% \pgfplotstablereadvalueofcolindex{3} -> expands to '42' if '42' is
% written in column no 3.
%
% Column indexing starts at 0.
%
% @ATTENTION: since such a command may occur within an \edef or an
% \csname, it can't perform sanity checking. Proving an invalid index
% expands to \pgfkeysvalueof{/pgfplots/table/@undefined column text}.
\def\pgfplotstablereadvalueofcolindex@#1{%
\pgfutil@ifundefined{pgfplotstblread@colcontent@no#1}{%
\pgfplotstable@undefinedtext{colindex#1}%
}{%
\csname pgfplotstblread@colcontent@no#1\endcsname
}%
}
% \pgfplotstablereadgetcolname{<name>}{<\content>}
% performs \let\content=<content of column named <name> >
\def\pgfplotstablereadgetcolname@#1#2{%
\pgfplotstablereadgetptrtocolname{#1}{\pgfplots@loc@TMPa}%
\pgfplotstablereadevalptr\pgfplots@loc@TMPa{#2}%
}%
% This here is the implementation of \pgfplotstablereadvalueofcolname
% (and \thisrow{<colname>}) for use inside of the 'read to listener'
% framework.
%
% Like \pgfplotstablereadgetcolname, but this one expands directly to
% the value of the desired column.
%
% #1: a column name or a column alias.
%
% @ATTENTION: since such a command may occur within an \edef or an
% \csname, it can't perform sanity checking. Proving an invalid index
% expands to \pgfkeysvalueof{/pgfplots/table/@undefined column text}.
\def\pgfplotstablereadvalueofcolname@#1{%
\pgfplotstable@thisrow@impl{#1}{pgfplotstblread@colindex@for@name}{\pgfplotstable@thisrow@impl@read}%
}%
\def\pgfplotstable@thisrow@impl@read#1{\csname pgfplotstblread@colcontent@no#1\endcsname}%
% This implements \thisrow in different contexts.
%
% Usage:
% \def\thisrow#1{\pgfplotstable@thisrow@impl{#1}{macroprefix@}{\pgfplotstable@thisrow@impl@}}
%
% Then, \thisrow{existingcol}
% will expand to
% -> \pgfplotstable@thisrow@impl@{\csname macroprefix@existingcol\endcsname}
% -> \csname macroprefix@existingcol\endcsname
%
% Furthermore, if '#1' is no existing col and there exists /pgfplots/table/alias/#1,
% \thisrow{aliased}
% will expand to
% -> \pgfplotstable@thisrow@impl@{\csname macroprefix@\pgfkeysvalueof{/pgfplots/table/alias/aliased}\endcsname}
% -> \csname macroprefix@\pgfkeysvalueof{/pgfplots/table/alias/aliased}\endcsname
%
% #1: the argument for \thisrow{#1}
% #2: a macro prefix such that \csname #2<colname>\endcsname contains
% the value of the current row for (physical) column <colname>
% #3: the name of a one-argument-macro which will get \csname #2<colname>\endcsname
% as argument. This is the last step of \thisrow. It allows indirect
% access by translating colnames to col indices in '\pgfplotstableread to listener'
\def\pgfplotstable@thisrow@impl#1#2#3{%
\pgfutil@ifundefined{#2#1}%
{%
% WARNING : this code has been REPLICATED in
% *** \pgfplotstablereadgetptrtocolname ***
% *** \pgfplotstablegetcolumnbyname ***
% *** \pgfplotstableresolvecolname ***
% *** \pgfplotstablereadvalueofcolname ***
\pgfkeysifdefined{/pgfplots/table/alias/#1}{%
\pgfutil@ifundefined{#2\pgfkeysvalueof{/pgfplots/table/alias/#1}}{%
\pgfplotstable@undefinedtext{\pgfkeysvalueof{/pgfplots/table/alias/#1}}%
}{%
#3{\csname #2\pgfkeysvalueof{/pgfplots/table/alias/#1}\endcsname}%
}%
}{%
\pgfplotstable@undefinedtext{#1}%
}%
}%
{%
#3{\csname #2#1\endcsname}%
}%
}%
\def\pgfplotstable@thisrow@impl@#1{#1}%
% \pgfplotstablereadgetptrtocolname{<name>}{\ptr}
% Creates some sort of "pointer" to the column named <name>. This
% pointer can than be used every time a new line has been reported to
% the listener. It works like this:
%
% \let\ptr=\pgfutil@empty
% \def\macro{%
% \ifx\ptr\empty
% \pgfplotstablereadgetptrtocolname{<my col>}{\ptr}%
% \fi
% \pgfplotstablereadevalptr{\ptr}{\content}%
% -> do something with \content!
% }
%
% \pgfplotstableread{<file>} to listener<\macro>
%
% -> will evaluate \macro foreach row.
%
% The advantage of such a prepared pointer over \thisrow{#1} or
% \getthisrow{#1} is simply efficiency and sanity checking: the checks
% are done at the time of pointer creation, dereferencing the pointer
% is fast.
\def\pgfplotstablereadgetptrtocolname@#1#2{%
\def#2{0}%
\pgfplotstable@getcol{#1}\of{\pgfplotstableread@filename}\to{#2}\getcolmethod{getptr}%
}%
% As \pgfplotstablereadgetptrtocolname, but this here accesses columns
% by index.
\def\pgfplotstablereadgetptrtocolindex@#1#2{\edef#2{#1}}%
% \pgfplotstablereadevalptr{<\ptr>}{<\content}
% writes the current value of <\ptr> to <\content>. The pointer <\ptr>
% must be initialised with \pgfplotstablereadgetptrtocolname
\let\pgfplotstablereadevalptr@=\pgfplotstablereadgetcolindex@
% \pgfplotstablereadvalueofptr{<\ptr>} -> expands to the pointers value.
%
% The pointer \ptr must be initialised with
% \pgfplotstablereadgetptrtocolname.
\let\pgfplotstablereadvalueofptr@=\pgfplotstablereadvalueofcolindex@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\long\def\pgfplotstableread@impl@nextrow@NEXT@listener#1{%
\expandafter\def\csname pgfplotstblread@colcontent@no\thepgfplotstableread@curcol\endcsname{#1}%
\pgfplotstableread@countadvance\pgfplotstableread@curcol
}
\long\def\pgfplotstableread@impl@nextrow@NEXT#1{%
%\pgfplots@message{Inserting '#1' at (\thepgfplotstableread@lineno, \thepgfplotstableread@curcol).}%
\ifnum\pgfplotstableread@curcol<\pgfplotstableread@numcols\relax
\pgfplotslist@assembleentry{#1}\into\t@pgfplots@tokc
\def\pgfplotstableread@TMP{\expandafter\pgfplotsapplistXpushback\expandafter{\the\t@pgfplots@tokc}\to}%
\expandafter\pgfplotstableread@TMP\csname pgfp@numtable@glob@col@\thepgfplotstableread@curcol\endcsname
\pgfplotstableread@countadvance\pgfplotstableread@curcol
\else
\begingroup
\t@pgfplots@tokc={#1}%
\pgfplotsthrow{table columns unbalanced}{Table '\pgfplotstableread@filename' appears to have too many columns in line \thepgfplotstableread@lineno: Ignoring '\the\t@pgfplots@tokc'. PGFPlots found that the number of columns is larger than the previously determined number of columns. Please verify that every cell entry is separated correctly (use braces {<cell entry>} if necessary. Also verify that column names are plain ASCII.). This error is not critical}\pgfeov%
\endgroup
\fi
}
\long\def\pgfplotstableread@impl@collectcolnames@NEXT#1{%
\edef\pgfplotstable@loc@TMPa{#1}%
\ifx\pgfplotstable@loc@TMPa\pgfutil@empty
\edef\pgfplotstable@loc@TMPa{\thepgfplotstableread@curcol}%
\pgfplotswarning{empty column name}{\pgfplotstableread@filename}{\pgfplotstable@loc@TMPa'}\pgfeov%
\fi
\expandafter\pgfplotstableread@impl@collectcolnames@NEXT@\expandafter{\pgfplotstable@loc@TMPa}%
}
\long\def\pgfplotstableread@impl@collectcolnames@NEXT@#1{%
%\pgfplots@message{Got column name no \thepgfplotstableread@curcol\ as '#1'}%
\pgfutil@ifundefined{pgfplotstableread@impl@COLNAME@#1}{%
\def\pgfplotstable@loc@TMPa{#1}%
}{% generate unique column names warning:
\pgfplots@warning{Table '\pgfplotstableread@filename' has non-unique column name '#1'. Only the first occurence can be accessed via column names.}%
\edef\pgfplotstable@loc@TMPa{#1--index\thepgfplotstableread@curcol}%
}%
\expandafter\def\csname pgfplotstableread@impl@COLNAME@#1\endcsname{foo}% remember this name.
\expandafter\pgfplotslistpushbackglobal\expandafter{\pgfplotstable@loc@TMPa}\to\pgfplotstable@colnames@glob
\ifpgfplots@tableread@to@listener
% create an associative container colindex -> colname
% for use in a listener.
\expandafter\edef\csname pgfplotstblread@colindex@for@name#1\endcsname{\thepgfplotstableread@curcol}%
\fi
\pgfplotstableread@countadvance\pgfplotstableread@curcol
}
\long\def\pgfplotstableread@impl@countcols@and@identifynames@NEXT#1{%
\pgfplotstableread@countadvance\pgfplotstableread@curcol
\ifpgfplotstable@search@header
\ifpgfplotstableread@curline@contains@colnames
\else
\def\pgfplotstableread@CURTOK{#1}%
% can we safely use the \pgfmathfloatparsenumber here? I
% doubt it -- what if the header contains macros?
%
% there is no (simple) expandable "to lower case". check
% for the most common forms here.
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@nan
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@NaN
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@NAN
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@inf
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@Inf
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@INF
\else
\pgfplotstableread@isnumber@ITERATE#1\pgfplotstable@EOI
\fi\fi\fi\fi\fi\fi
%\ifpgfplotstableread@curline@contains@colnames\pgfplots@message{'#1' is a column name!}\else\pgfplots@message{'#1' is NO column name!}\fi
\fi
\fi
}
\def\pgfplotstableread@isnumber@nan{nan}
\def\pgfplotstableread@isnumber@NaN{NaN}
\def\pgfplotstableread@isnumber@NAN{NAN}
\def\pgfplotstableread@isnumber@inf{inf}
\def\pgfplotstableread@isnumber@INF{INF}
\def\pgfplotstableread@isnumber@Inf{Inf}
\def\pgfplotstableread@isnumber@plus{+}
\def\pgfplotstableread@isnumber@minus{-}
\def\pgfplotstableread@isnumber@zero{0}
\def\pgfplotstableread@isnumber@one{1}
\def\pgfplotstableread@isnumber@two{2}
\def\pgfplotstableread@isnumber@three{3}
\def\pgfplotstableread@isnumber@four{4}
\def\pgfplotstableread@isnumber@five{5}
\def\pgfplotstableread@isnumber@six{6}
\def\pgfplotstableread@isnumber@seven{7}
\def\pgfplotstableread@isnumber@eight{8}
\def\pgfplotstableread@isnumber@nine{9}
\def\pgfplotstableread@isnumber@e{e}
\def\pgfplotstableread@isnumber@E{E}
\def\pgfplotstableread@isnumber@period{.}
\def\pgfplotstableread@isnumber@ITERATE#1{%
\def\pgfplotstableread@CURTOK{#1}%
\ifx\pgfplotstableread@CURTOK\pgfplotstable@EOI
\def\pgfplotstableread@NEXT{}%
\else
\def\pgfplotstableread@NEXT{\pgfplotstableread@isnumber@ITERATE}%
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@plus
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@minus
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@zero
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@one
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@two
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@three
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@four
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@five
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@six
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@seven
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@eight
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@nine
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@e
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@E
\else
\ifx\pgfplotstableread@CURTOK\pgfplotstableread@isnumber@period
\else
%\message{NO ITS NOT! Token: '\meaning\pgfplotstableread@CURTOK'}%
% it's no number, so it is a column name.
\pgfplotstableread@curline@contains@colnamestrue
\def\pgfplotstableread@NEXT{\pgfplotstableread@impl@gobble}%
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
\fi
\pgfplotstableread@NEXT
}
\def\pgfplotstable@error#1{\pgfplotsthrow{unsupported operation}{#1}\pgfeov}%
\def\pgfplotstableset{%
\pgfqkeys{/pgfplots/table}%
}%
% Accepts a macro #1 which contains an argument denoting a column
% name.
%
% It checks whether #1 starts with '[index]', indicating that it is actually
% a column INDEX. If that is the case,
% \ifpgfplotstableread@foundcolnames is set to false and the index is
% returned into #1.
%
% Otherwise, \ifpgfplotstableread@foundcolnames is set to true.
\def\pgfplotstable@is@colname#1{%
\expandafter\pgfplotstabletypeset@is@colname@#1\pgfplotstable@EOI
\ifpgfplotstableread@foundcolnames
\else
\let#1=\pgfplotstable@loc@TMPa
\fi
}%
\def\pgfplotstabletypeset@is@colname@{%
\pgfutil@ifnextchar[{%
\pgfplotstabletypeset@is@colname@index
}{%
\pgfplotstableread@foundcolnamestrue
\pgfplotstabletypeset@is@colname@name
}%
}
\def\pgfplotstabletypeset@is@colname@index@@{index}%
\def\pgfplotstabletypeset@is@colname@index[#1]#2\pgfplotstable@EOI{%
\def\pgfplotstable@loc@TMPa{#1}%
\ifx\pgfplotstable@loc@TMPa\pgfplotstabletypeset@is@colname@index@@
\pgfplotstableread@foundcolnamesfalse
\edef\pgfplotstable@loc@TMPa{#2}%
\else
\pgfplotstableread@foundcolnamestrue
\fi
}%
\def\pgfplotstabletypeset@is@colname@name#1\pgfplotstable@EOI{}%
% calls \pgfplotstableset{every table={#1}} where '#1' is the table
% file name.
%
% Note that 'every table' is usually set *AFTER* any other option. In
% other words: settings in 'every table' have higher precedence than
% those provided, for example, at
% \pgfplotstabletypeset[<options>]{...}.
%
% Why? Well, the <options> need to be set *before* the file name
% argument is read. After all, it might contain an inline table for
% which \catcodes need to be adjusted -- and <options> might explain
% how.
%
% REMARK: An early attempt to change the precendence for 'every table'
% was to set <options> again after 'every table'. But that is
% incompatible with, for example '/.add={}{}' key handlers.
%
% This macro does nothing if 'every table' is empty.
%
% #1: the table name (argument to 'every table')
% #2: The <options> which have already been set.
\long\def\pgfplotstableset@every@table#1#2{%
\pgfkeysgetvalue{/pgfplots/table/every table/.@cmd}\pgfplotstable@loc@TMPa
\ifx\pgfplotstable@loc@TMPa\pgfplots@empty@style@key
\else
\pgfplotstableset{/pgfplots/table/every table={#1}}%,#2}%
\fi
}%
\def\pgfplotstabletypeset{%
\pgfutil@ifnextchar[{%
\pgfplotstabletypeset@opt
}{%
\pgfplotstabletypeset@opt[]%
}%
}
\long\def\pgfplotstabletypeset@opt[#1]#2{%
\pgfplotstable@error@pkg{Please load \string\usepackage{pgfplotstable} before using \string\pgfplotstabletypeset}%
}
\let\pgfplotstabletypesetfile=\pgfplotstabletypeset
\def\pgfplotstablecreatecol{%
\pgfutil@ifnextchar[{%
\pgfplotstablecreatecol@opt
}{%
\pgfplotstablecreatecol@opt[]%
}%
}%
\def\pgfplotstablecreatecol@opt[#1]#2#3{%
\pgfplotstable@error@pkg{Please load \string\usepackage{pgfplotstable} before using \string\pgfplotstablecreatecol}%
}%
% Iterates through every column of table '#1' and invokes the code
% '#3' for each column. The current column name will be available as
% '#2' and the current column index as |\pgfplotstablecol| (starting
% with 0).
%
% Example:
% \pgfplotstableforeachcolumn{\table}\as\colname{%
% The column name is `\colname'; its index \pgfplotstablecol.\par
% }%
%
% REMARK: this routine does NOT introduce TeX groups.
\long\def\pgfplotstableforeachcolumn#1\as#2#3{%
\def\pgfplotstablecol{0}%
\pgfplotslistforeachungrouped#1\as#2{%
#3\relax%
\pgfplotsutil@advancestringcounter\pgfplotstablecol
}%
\let\pgfplotstablecol=\relax
}%
\let\pgfplotstableforeachcolumn@orig=\pgfplotstableforeachcolumn
% A variant of \pgfplotstableforeachcolumn which is used inside of
% \pgfplotstableread to listener.
%
% It is used as \pgfplotstableforeachcolumn\as\cur{<do something with \cur>}
\long\def\pgfplotstableforeachcolumn@listener#1\as#2#3{%
\pgfplotstableforeachcolumn@orig\pgfplotstable@colnames@glob\as{#2}{#3}%
}%
% Reports every element t_{ij} for a fixed column j (in read-only
% mode).
%
% For every cell, the code '#4' will be executed where '#3' will
% contain the cell's value. During code '#4', the macro
% \pgfplotstablerow will contain the current row index.
%
% #1: either a column name or the string '[index]' followed by a
% number denoting a column index Access by column name is much faster..
% #2: the table (macro or file name)
% #3: the macro in which the cell values shall be written
% #4: the code to execute.
%
% Example:
% \pgfplotstableforeachcolumnelement{colname}\of\table\as\cellelem{%
% I have now cell element `\cellelem' at row index
% `\pgfplotstablerow'.
% \par
% }
%
% REMARK: this routine does NOT introduce TeX groups.
\long\def\pgfplotstableforeachcolumnelement#1\of#2\as#3#4{%
\def\pgfplotstablerow{0}%
\pgfplotstablegetcolumn{#1}\of{#2}\to\pgfplotstableforeachcolumnelement@list
\pgfplotslistforeachungrouped\pgfplotstableforeachcolumnelement@list\as#3{%
% allow nesting by copying the old value of \pgfplotstablerow:
\expandafter\pgfplotstableforeachcolumnelement@\expandafter{\pgfplotstablerow}{#4}%
}%
\let\pgfplotstablerow=\relax
}%
% helper method to allow nesting. It copies \pgfplotstablerow.
% #1: the expanded value of \pgfplotstablerow.
\long\def\pgfplotstableforeachcolumnelement@#1#2{%
#2\relax
\def\pgfplotstablerow{#1}% restore to old value.
% advance.
\pgfplotsutil@advancestringcounter\pgfplotstablerow
}%
% A routine which is similar to \pgfplotstableforeachcolumnelement,
% but this here checks for changes in \pgfplotsretval and writes them
% back into the respected cell.
%
% The runtime is quadratic in the number of rows.
\long\def\pgfplotstablemodifyeachcolumnelement#1\of#2\as#3#4{%
\def\pgfplotstablerow{0}%
%
% Step 0: get the REAL column name for '#1'.
% This needs modifications if '#1' is [index]<integer>.
% -> store the colname to \pgfplotstable@loc@TMPc:
\def\pgfplotstable@loc@TMPc{#1}%
\pgfplotstable@is@colname{\pgfplotstable@loc@TMPc}%%
\ifpgfplotstableread@foundcolnames
\else
\expandafter\pgfplotstablegetcolumnnamebyindex\pgfplotstable@loc@TMPc\of{#2}\to\pgfplotstable@loc@TMPc
\fi
% Step 0.1: prepare a command which re-assembles column '#1'
% (using the real column name).
% The re-assemblation command will be invoked at the end of each
% iteration. This complicated macro preparation allows nested
% calls to \pgfplotstablemodifyeachcolumnelement.
\t@pgfplots@toka={\expandafter\pgfplotslistpushback\expandafter{#3}\to}%
\edef\pgfplotstable@loc@TMPd{%
\the\t@pgfplots@toka{\expandafter\noexpand\csname\string#2@\pgfplotstable@loc@TMPc\endcsname}}%
% Step 1: copy the column data to \pgfplotstable@loc@TMPb
\expandafter\pgfplotstablegetcolumnbyname\pgfplotstable@loc@TMPc\of#2\to\pgfplotstable@loc@TMPb%
%
% clear the original column:
\expandafter\pgfplotslistnewempty\csname\string#2@\pgfplotstable@loc@TMPc\endcsname
%
% Call loop. The prepared re-assemble macro will be provided as macro argument
% to allow nested calls:
\expandafter\pgfplotstablemodifyeachcolumnelement@\expandafter{\pgfplotstable@loc@TMPd}
{\pgfplotstable@loc@TMPb}{#3}{#4}%
\let\pgfplotstablerow=\relax
}%
% #1: post-iteration code
% #2: the row list
% #3: the loop macro to assign
% #4: the loop body
\long\def\pgfplotstablemodifyeachcolumnelement@#1#2#3#4{%
\pgfplotslistforeachungrouped{#2}\as#3{%
% allow nesting by copying the old value of \pgfplotstablerow:
\expandafter\pgfplotstableforeachcolumnelement@\expandafter{\pgfplotstablerow}{#4}%
#1%
}%
}
% Selects a single table element at row #1 and column #2 from table
% #3.
%
% #1: a row index.
% #2: a column name or the string '[index]' followed by a number
% denoting a column index. Access by column name is much faster.
% #3: the table (macro or file name).
%
% The cell value will be written into the macro \pgfplotsretval.
%
% REMARK:
% this routine is supposed to be very slow: it needs time O(N) where N
% is the number of rows. This may change in future versions.
%
% Example:
% \pgfplotstablegetelem{0}{[index]2}\of\table
% The elem is `\pgfplotsretval'.
\def\pgfplotstablegetelem#1#2\of#3{%
\begingroup
\pgfplotstablegetcolumn{#2}\of{#3}\to\pgfplotstable@loc@TMPa
\def\pgfplotsexceptionmsg{Sorry, row `#1' does not exist in table \pgfplotstablenameof{#3}}%
\pgfplotslistselect#1\of\pgfplotstable@loc@TMPa\to\pgfplotsretval
\pgfmath@smuggleone\pgfplotsretval
\endgroup
}%
\def\pgfplotstablegetcolumnlist#1\to#2{\let#2=#1}
% Defines \pgfmathresult (and now also \pgfplotsretval) to be the number of rows in table #1.
%
% #1 may be either a loaded table structure (a macro name) or a table
% file name. In the latter case, the file will be loaded temporarily.
\long\def\pgfplotstablegetrowsof#1{%
\pgfplotstable@isloadedtable{#1}{%
% ah - it is an already loaded table!
\begingroup
\pgfplotslistfront#1\to\pgfplotstablegetrows@@
\expandafter\pgfplotslistsize\csname\string#1@\pgfplotstablegetrows@@\endcsname\to\c@pgfplotstable@counta
\edef\pgfmathresult{\the\c@pgfplotstable@counta}%
\pgfmath@smuggleone\pgfmathresult
\endgroup
}{%
% ah - it is a file name.
\begingroup
\pgfplotstableread{#1}\pgfplotstablegetrows@
\pgfplotstablegetrowsof{\pgfplotstablegetrows@}%
\pgfmath@smuggleone\pgfmathresult
\endgroup
}%
\let\pgfplotsretval=\pgfmathresult
}%
% Defines \pgfplotsretval to contain the number of columns in table
% #1.
%
% #1 may be either a loaded table structure (a macro name) or a table
% file name. In the latter case, the file will be loaded temporarily.
\long\def\pgfplotstablegetcolsof#1{%
\pgfplotstable@isloadedtable{#1}{%
% ah - it is an already loaded table!
\begingroup
\pgfplotslistsize#1\to\c@pgfplotstable@counta
\edef\pgfplotsretval{\the\c@pgfplotstable@counta}%
\pgfmath@smuggleone\pgfplotsretval
\endgroup
}{%
% ah - it is a file name.
\begingroup
\pgfplotstableread{#1}\pgfplots@table
\pgfplotstablegetcolsof{\pgfplots@table}%
\pgfmath@smuggleone\pgfplotsretval
\endgroup
}%
\let\pgfmathresult=\pgfplotsretval
}
|