3

I want to use Asymptote for making some pictures in Latex. These pictures are to be generated using input files which are in csv format. The files have variable columns and typically look like this (shortened for clarity)

"A", 1, 2, 3
"B", 5, 2, 1, 6, 6
"C", 3, 8
...

Is it possible to read the file line-by-line, assimilating the data in each row into data-structures inside Asymptote code?

  • Yes, it seems to be possible, see e.g. tex.stackexchange.com/a/226235, where you can find the line file in1=input(filename1).line().csv(); which seems to be doing what you are asking. Of course, if you have a specific task that is to be done with the data one may more easily write an explicit answer. – user194703 Oct 11 '19 at 2:35
3

You can read your data file sample.dat into a two-dimensional array of strings s with the following code.

file f = input("sample.dat").line().csv(); 
string[][] s;
while(!eof(f)) { s.push(f.line()); }

write(s[0]);
write();
write(s);

The write commands output the following text, demonstrating that the file reading was successful.

0:  A
1:   1
2:   2
3:   3

A    1   2   3
B    5   2   1   6   6
C    3   8
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.