Hello
I am struggling with JS code. I am using it in conjunction with MaxMSP. Basically whay I do is load a csv file that gets converted to be stored in a coll object (in Max). What I understand from the code is:
1) it reads the csv file line by line and splits the string into arrays
2) it outputs the array.
What is wrong:
1) I need an index number before every line.
2) I want the values as floats (except the date which can be a symbol)
3) I need to get rid of the first line which contains the variables names
4) Finally the lines should be reversed so what is at the last line in the csv comes first
3 and 4 I can do in Max itself but 1 and 2 I cannot. I can read the JS code and I understand what it does but I do not know how to take it further. I hope somebody here can help me. Here goes the JS code:
[CODE]function import(filename)
{
var f = new File(filename);
if (f.open) {
outlet(0, “clear”);
while (f.position < f.eof) {
var str = f.readline();
var a = str.split(“,”); // conver strings to array (elements are delimited by a coma)
a[5] /= 1000; // uncomment to devide the 6th column by 1000
outlet(0, “store”, a); // store in the coll
}
f.close();
} else {
error(“couldn’t find the file (“+ filename +”)n”);
}
}