My task is to take the data from http://services.swpc.noaa.gov/text/ace-swepam.txt and split/sort it into something useful. To start with, I'm trying to split the data into categories, so that I can use in chart.js or something later on, but when I try and print a field, it just comes up as [].
var options = {
host: 'services.swpc.noaa.gov',
path: '/text/ace-swepam.txt',
port: 80,
method: 'POST'
};
var req = http.request(options, function (res) {
res.on('data', function (chunk) {
// console.log('BODY: ' + chunk);
results += chunk.toString();
//split results into an array by each new line
lines = results.split("\n");
//delete header lines
lines.splice(0, 18);
if (lines.length <= 20) {
return;
}
console.log(lines);
});
res.on('end', function (e) {
callback();
});
});
req.on('error', function (e) {
console.log('problem with request: ' + e.message);
});
req.end();
function callback() {
for (var line in lines) {
var x = [];
x = lines[line].split(" ");
var statuscode = x[14];
if (statuscode == 0) {
if (lines[line].indexOf('-') === -1) {
year.push(x[0]);
month.push(x[1]);
day.push(x[2]);
time.push(x[4]);
statusno.push(statuscode);
proton.push(x[22]);
bulksp.push(x[28]);
iontemp.push(x[33]);
}
}
}
// console.log(year, month, day, time, statusno, proton, bulksp, iontemp)
}