Bug of vector wave output error fixed.
[Faustine.git] / documentation / code_VALMain.write_output_txt.html
1 <html><head>
2 <link rel="stylesheet" href="style.css" type="text/css">
3 <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
4 <link rel="Start" href="index.html">
5 <link title="Index of types" rel=Appendix href="index_types.html">
6 <link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
7 <link title="Index of values" rel=Appendix href="index_values.html">
8 <link title="Index of modules" rel=Appendix href="index_modules.html">
9 <link title="Types" rel="Chapter" href="Types.html">
10 <link title="Parser" rel="Chapter" href="Parser.html">
11 <link title="Lexer" rel="Chapter" href="Lexer.html">
12 <link title="Value" rel="Chapter" href="Value.html">
13 <link title="Signal" rel="Chapter" href="Signal.html">
14 <link title="Faustexp" rel="Chapter" href="Faustexp.html">
15 <link title="Interpreter" rel="Chapter" href="Interpreter.html">
16 <link title="Preprocess" rel="Chapter" href="Preprocess.html">
17 <link title="Main" rel="Chapter" href="Main.html"><title>Main.write_output_txt</title>
18 </head>
19 <body>
20 <code class="code"><span class="keyword">let</span>&nbsp;write_output_txt&nbsp;=&nbsp;<span class="keyword">fun</span>&nbsp;channel_int_list&nbsp;<span class="keywordsign">-&gt;</span>&nbsp;<span class="keyword">fun</span>&nbsp;data_float_array_list&nbsp;<span class="keywordsign">-&gt;</span><br>
21 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;()&nbsp;=&nbsp;print_endline(<span class="string">"Making&nbsp;output&nbsp;txt&nbsp;files..."</span>)&nbsp;<span class="keyword">in</span><br>
22 <br>
23 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">(*&nbsp;make&nbsp;output&nbsp;txt&nbsp;file&nbsp;names&nbsp;:&nbsp;output0,&nbsp;output1,&nbsp;...&nbsp;*)</span><br>
24 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;n_output&nbsp;=&nbsp;<span class="constructor">List</span>.length&nbsp;data_float_array_list&nbsp;<span class="keyword">in</span><br>
25 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;n_array&nbsp;=&nbsp;<span class="constructor">Array</span>.init&nbsp;n_output&nbsp;(<span class="keyword">fun</span>&nbsp;n&nbsp;<span class="keywordsign">-&gt;</span>&nbsp;n)&nbsp;<span class="keyword">in</span><br>
26 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;make_file_name&nbsp;i&nbsp;=&nbsp;<span class="string">"output"</span>&nbsp;^&nbsp;(string_of_int&nbsp;i)&nbsp;^&nbsp;<span class="string">".csv"</span>&nbsp;<span class="keyword">in</span><br>
27 <br>
28 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">(*&nbsp;make&nbsp;output&nbsp;wave&nbsp;file&nbsp;routes&nbsp;*)</span><br>
29 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;make_chemin&nbsp;s&nbsp;=&nbsp;io_macro_to_string&nbsp;<span class="constructor">Output_Route_string</span>&nbsp;^&nbsp;s&nbsp;<span class="keyword">in</span><br>
30 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;file_name_string_array&nbsp;=&nbsp;<span class="constructor">Array</span>.map&nbsp;make_file_name&nbsp;n_array&nbsp;<span class="keyword">in</span><br>
31 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;file_chemin_string_array&nbsp;=&nbsp;<span class="constructor">Array</span>.map&nbsp;make_chemin&nbsp;file_name_string_array&nbsp;<span class="keyword">in</span><br>
32 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;file_chemin_string_list&nbsp;=&nbsp;<span class="constructor">Array</span>.to_list&nbsp;file_chemin_string_array&nbsp;<span class="keyword">in</span><br>
33 <br>
34 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="comment">(*&nbsp;open&nbsp;output&nbsp;channels&nbsp;*)</span><br>
35 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;file_list&nbsp;=&nbsp;<span class="constructor">List</span>.map&nbsp;open_out&nbsp;file_chemin_string_list&nbsp;<span class="keyword">in</span><br>
36 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;array_to_string&nbsp;=&nbsp;<span class="keyword">fun</span>&nbsp;data_float_array&nbsp;<span class="keywordsign">-&gt;</span>&nbsp;<span class="keyword">fun</span>&nbsp;channel_int&nbsp;<span class="keywordsign">-&gt;</span><br>
37 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;data_length&nbsp;=&nbsp;<span class="constructor">Array</span>.length&nbsp;data_float_array&nbsp;<span class="keyword">in</span><br>
38 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;<span class="keyword">rec</span>&nbsp;to_string_rec&nbsp;=&nbsp;<br>
39 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">fun</span>&nbsp;data&nbsp;<span class="keywordsign">-&gt;</span>&nbsp;<span class="keyword">fun</span>&nbsp;channel&nbsp;<span class="keywordsign">-&gt;</span>&nbsp;<span class="keyword">fun</span>&nbsp;n&nbsp;<span class="keywordsign">-&gt;</span>&nbsp;<span class="keyword">fun</span>&nbsp;i&nbsp;<span class="keywordsign">-&gt;</span>&nbsp;<span class="keyword">fun</span>&nbsp;column&nbsp;<span class="keywordsign">-&gt;</span><br>
40 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">if</span>&nbsp;i&nbsp;&lt;&nbsp;n&nbsp;<span class="keyword">then</span>&nbsp;<br>
41 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(<br>
42 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;element&nbsp;=&nbsp;string_of_float&nbsp;(data.(i))&nbsp;<span class="keyword">in</span><br>
43 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">if</span>&nbsp;column&nbsp;&lt;&nbsp;(channel&nbsp;-&nbsp;1)&nbsp;<span class="keyword">then</span>&nbsp;<br>
44 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;element&nbsp;^&nbsp;<span class="string">","</span>&nbsp;^&nbsp;(to_string_rec&nbsp;data&nbsp;channel&nbsp;n&nbsp;(i&nbsp;+&nbsp;1)&nbsp;(column&nbsp;+&nbsp;1))<br>
45 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">else</span>&nbsp;<span class="keyword">if</span>&nbsp;column&nbsp;=&nbsp;(channel&nbsp;-&nbsp;1)&nbsp;<span class="keyword">then</span><br>
46 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;element&nbsp;^&nbsp;<span class="string">"\n"</span>&nbsp;^&nbsp;(to_string_rec&nbsp;data&nbsp;channel&nbsp;n&nbsp;(i&nbsp;+&nbsp;1)&nbsp;0)<br>
47 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">else</span>&nbsp;raise&nbsp;(<span class="constructor">Invalid_argument</span>&nbsp;<span class="string">"write_output_txt."</span>)<br>
48 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;)<br>
49 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">else</span>&nbsp;<span class="string">""</span>&nbsp;<span class="keyword">in</span><br>
50 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to_string_rec&nbsp;data_float_array&nbsp;channel_int&nbsp;data_length&nbsp;0&nbsp;0&nbsp;<span class="keyword">in</span><br>
51 <br>
52 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;data_string_list&nbsp;=&nbsp;<span class="constructor">List</span>.map2&nbsp;array_to_string&nbsp;data_float_array_list&nbsp;channel_int_list&nbsp;<span class="keyword">in</span><br>
53 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;_&nbsp;=&nbsp;<span class="constructor">List</span>.map2&nbsp;output_string&nbsp;file_list&nbsp;data_string_list&nbsp;<span class="keyword">in</span><br>
54 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">let</span>&nbsp;_&nbsp;=&nbsp;<span class="constructor">List</span>.map&nbsp;close_out&nbsp;file_list&nbsp;<span class="keyword">in</span><br>
55 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print_endline(<span class="string">"Success"</span>)</code></body></html>