polymorphism: better names for .binaryValue and .booleanValue are .asInteger and...
[supercollider.git] / Help / Files / TabFileReader.html
blob5a9f77c4acdf7c663877db7a38119356609b886c
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="949.43">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #0000bf}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060; min-height: 12.0px}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
19 p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
20 p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
21 p.p12 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #0000bf}
22 span.s1 {font: 18.0px Helvetica}
23 span.s2 {color: #000000}
24 span.s3 {color: #0000bf}
25 span.s4 {color: #0000bf}
26 span.s5 {color: #0000bf}
27 span.s6 {color: #606060}
28 span.s7 {color: #bf0000}
29 span.Apple-tab-span {white-space:pre}
30 </style>
31 </head>
32 <body>
33 <p class="p1"><span class="s1"><b>TabFileReader<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></span><b>file reader for tab separated data</b></p>
34 <p class="p2"><br></p>
35 <p class="p3"><span class="s2"><b>Inherits from: </b><a href="../Core/Object.html"><b>Object</b></a></span><b> </b><span class="s2"><b>: </b><a href="../Core/Kernel/AbstractFunction.html"><b>AbstractFunction</b></a></span><b> : </b><a href="../Streams-Patterns-Events/Stream.html"><b>Stream</b></a><b> : </b><a href="FileReader.html"><b>FileReader</b></a></p>
36 <p class="p2"><br></p>
37 <p class="p1"><b>TabFileReader reads tab/return delimited files into 2D arrays.</b></p>
38 <p class="p2"><br></p>
39 <p class="p1">For comma-separated files, use: <a href="CSVFileReader.html"><span class="s3">CSVFileReader</span></a>.</p>
40 <p class="p1">For space-delimited files, or custom delimiters, use: <a href="FileReader.html"><span class="s3">FileReader</span></a></p>
41 <p class="p2"><br></p>
42 <p class="p1"><b>*read(path, skipEmptyLines)</b></p>
43 <p class="p4">(</p>
44 <p class="p5">// write a test file:</p>
45 <p class="p6"><span class="s2">f = </span><span class="s4">File</span><span class="s2">(</span>"TabDelTest.sc"<span class="s2">, </span>"w"<span class="s2">);</span></p>
46 <p class="p4">f.write(</p>
47 <p class="p6">"Some<span class="Apple-tab-span"> </span>tab-<span class="Apple-tab-span"> </span>delimited<span class="Apple-tab-span"> </span>items<span class="Apple-tab-span"> </span>in<span class="Apple-tab-span"> </span>line<span class="Apple-tab-span"> </span>1</p>
48 <p class="p7"><br></p>
49 <p class="p6">and<span class="Apple-tab-span"> </span>then<span class="Apple-tab-span"> </span>some<span class="Apple-tab-span"> </span>more<span class="Apple-tab-span"> </span>in<span class="Apple-tab-span"> </span>line<span class="Apple-tab-span"> </span>3</p>
50 <p class="p6">"</p>
51 <p class="p4">);</p>
52 <p class="p4">f.close;<span class="Apple-converted-space"> </span></p>
53 <p class="p4">)</p>
54 <p class="p8"><br></p>
55 <p class="p9"><br></p>
56 <p class="p10"><span class="s2"><span class="Apple-tab-span"> </span></span>// open file, read and put strings into array, close file.<span class="Apple-converted-space"> </span></p>
57 <p class="p11">x = <span class="s5">TabFileReader</span>.read(<span class="s6">"TabDelTest.sc"</span>).postcs;</p>
58 <p class="p9"><br></p>
59 <p class="p10"><span class="s2"><span class="Apple-tab-span"> </span></span>// can skip empty lines:<span class="Apple-converted-space"> </span></p>
60 <p class="p11">x = <span class="s5">TabFileReader</span>.read(<span class="s6">"TabDelTest.sc"</span>, <span class="s5">true</span>).postcs;</p>
61 <p class="p9"><span class="Apple-tab-span"> </span></p>
62 <p class="p10"><span class="s2"><span class="Apple-tab-span"> </span></span>// do file open/close by hand if you prefer:</p>
63 <p class="p11">f = <span class="s5">File</span>(<span class="s6">"TabDelTest.sc"</span>, <span class="s6">"r"</span>); f.isOpen;</p>
64 <p class="p12"><span class="s2">t = </span>TabFileReader<span class="s2">(f);<span class="Apple-tab-span"> </span></span></p>
65 <p class="p11">t.read;</p>
66 <p class="p11">f.close;</p>
67 <p class="p9"><br></p>
68 <p class="p11">(</p>
69 <p class="p10">// write a test file with numbers:</p>
70 <p class="p6"><span class="s2">f = </span><span class="s5">File</span><span class="s2">(</span>"TabDelTestNum.sc"<span class="s2">, </span>"w"<span class="s2">);</span></p>
71 <p class="p9"><br></p>
72 <p class="p11">(1..10).do { <span class="s5">|n|</span> f.write(n.asString ++ <span class="s5">Char</span>.tab); };</p>
73 <p class="p11">f.close;<span class="Apple-converted-space"> </span></p>
74 <p class="p11">)</p>
75 <p class="p9"><br></p>
76 <p class="p11">x = <span class="s5">TabFileReader</span>.read(<span class="s6">"TabDelTestNum.sc"</span>).postcs;</p>
77 <p class="p11">x.collect(<span class="s5">_</span>.collect(<span class="s5">_</span>.interpret));<span class="Apple-tab-span"> </span><span class="s7">// convert to numbers.</span></p>
78 <p class="p9"><br></p>
79 <p class="p10"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// or you can do it immediately:</p>
80 <p class="p11">x = <span class="s5">TabFileReader</span>.readInterpret(<span class="s6">"TabDelTestNum.sc"</span>).postcs;</p>
81 <p class="p9"><br></p>
82 <p class="p11">(</p>
83 <p class="p10">// write a test file with numbers:</p>
84 <p class="p6"><span class="s2">f = </span><span class="s5">File</span><span class="s2">(</span>"TabDelTestNum.sc"<span class="s2">, </span>"w"<span class="s2">);</span></p>
85 <p class="p9"><br></p>
86 <p class="p11">(1..100).do { <span class="s5">|n|</span><span class="Apple-converted-space"> </span></p>
87 <p class="p11"><span class="Apple-tab-span"> </span>f.write(n.asString ++ if (n % 10 != 0, <span class="s5">Char</span>.tab, <span class="s5">Char</span>.nl)); };</p>
88 <p class="p11">f.close;<span class="Apple-converted-space"> </span></p>
89 <p class="p11">)</p>
90 <p class="p9"><br></p>
91 <p class="p9"><br></p>
92 <p class="p11">x = <span class="s5">TabFileReader</span>.readInterpret(<span class="s6">"TabDelTestNum.sc"</span>).postln;</p>
93 <p class="p9"><br></p>
94 </body>
95 </html>