Data rows are not displayed with tab delimiters. I expect them to be of fixed length.
Here is the first line I get. "2015 08 18 1708 57252 61680 0 2.6 45"
Instead of trying to break this line into a tab.
fields = line.split("\t");
Create an array of the lengths of each field and split it using the substring method.
Here is the complete code to analyze the returned data. It gives 119 lines or 6-7 has the status! = 0 (and therefore is skipped). Then your variables each have 112 entries.
res.on('data', function (chunk) { var fieldLengths = [0, 4, 7, 10, 16, 24, 32, 37, 48, 59, 72]; // console.log('BODY: ' + chunk); results += chunk.toString(); //split results into an array by each new line lines = results.split("\n"); // for me, the first "chunk" is incomplete. Throw it away and just use the second chunk. if (lines.length <= 20) { return; } //delete header lines lines.splice(0, 18); for (var line in lines) { console.log("entry: " + lines[line]); //split into data fields var lineText = lines[line]; var fields = []; for (var i = 0; i <= fieldLengths.length -1; i++) { fields.push(lineText.substring(fieldLengths[i], fieldLengths[i + 1])); } //if there are no problems (status code 0) //add the data to their respective fields if (fields[6] == 0) { year.push(fields[0]); month.push(fields[1]); day.push(fields[2]); time.push(fields[3]); statusno.push(fields[6]); proton.push(fields[7]); bulksp.push(fields[8]); iontemp.push(fields[9]); } } }); res.on('end', function (e) { console.log(year); });
});
This is easy to debug if you are using Visual Studio (the free community version will work) and add node tools for visual studio.
Let me know if the data is not entirely correct. I understand what you are trying to do, and you can customize the code if necessary.
source share