Currently, I am importing a csv file into MaxMSP and running it through a javascript object. The process involves the following steps: 1) Removing the header line from the file 2) Transforming the csv file into an array 3) Converting elements from the array into floats (including dates) 4) Adding an index number in front of each line (as required by the coll object in MaxMSP) One issue I'm facing is that the data in the csv file is in reverse chronological order. I need to rearrange the data chronologically. It seems logical to read the file backwards line by line (after removing the header). You can find the link to the app and the csvfile here. Simply double-click on the js object to view the code. Once you drop a csv file on the hotspot, double-click on the coll object to see its contents.
Below is the Javascript code snippet:
function import(filename)
{
var f = new File(filename);
if (f.open) {
var i = 0;
outlet(0, "clear");
f.readline();
while (f.position < f.eof)
{
var str = f.readline();
var a = str.split(","); // convert strings to array (elements are delimited by a comma)
// a[5] /= 1000; // uncomment to divide the 6th column by 1000
var date = Date.parse(a[0]);
var date = parseFloat(date);
var open = parseFloat(a[1]);
var high = parseFloat(a[2]);
var low = parseFloat(a[3]);
var close = parseFloat(a[4]);
var volume = parseFloat(a[5]);
var adjusted_close = parseFloat(a[6]);
outlet(0, i++, date,open,high,low,close,volume,adjusted_close); // store in the coll
}
f.close();
} else {
error("couldn't find the file ("+ filename +")\n");
}
}