precess entire file from pnp format and back

This commit is contained in:
Morgan 'ARR\!' Allen 2017-04-09 21:14:50 -07:00
parent 817ef57379
commit 6caddeddcc
2 changed files with 38 additions and 22 deletions

View file

@ -11,8 +11,6 @@ module.exports = function(input, output, feedFile, opts) {
var section = -1; var section = -1;
var sections = [[], [], [], []]; var sections = [[], [], [], []];
console.log("processing sections");
fs.createReadStream(feedFile) fs.createReadStream(feedFile)
.on("data", function(data) { .on("data", function(data) {
buf += data.toString(); buf += data.toString();
@ -27,10 +25,10 @@ module.exports = function(input, output, feedFile, opts) {
if(line.slice(0, 2) === "%,") { if(line.slice(0, 2) === "%,") {
section++; section++;
continue;
} }
if(section === 3 && sections[3].length > 0) continue;
if(section === -1) { // input can be either just the CSV section or the entire pnp file if(section === -1) { // input can be either just the CSV section or the entire pnp file
sections[1].push(line); sections[1].push(line);
} else { } else {
@ -42,8 +40,6 @@ module.exports = function(input, output, feedFile, opts) {
next(null, sections); next(null, sections);
}) })
}, function(sections, next) { }, function(sections, next) {
console.log("associating parts");
var components = []; var components = [];
var len = sections[1].length; var len = sections[1].length;
@ -58,15 +54,12 @@ module.exports = function(input, output, feedFile, opts) {
} }
} }
next(null, components); next(null, components, sections);
}, function(feeds, next) { }, function(feeds, sections, next) {
var rs = fs.createReadStream(input);
var ws = fs.createWriteStream(output);
var wsCsv = csv.createWriteStream();
var data = ""; var data = "";
var seq = 0; var seq = 0;
var tr = through.obj(function(chunk, enc, done) { var tr = through(function(chunk, enc, done) {
data += chunk.toString(); data += chunk.toString();
var lines = data.split("\n"); var lines = data.split("\n");
@ -90,13 +83,25 @@ module.exports = function(input, output, feedFile, opts) {
var feed = feeds[p]; var feed = feeds[p];
this.push([ 0, seq++, feed.slot, x, y, r ].join(",") + "\n"); this.push([ 0, seq++, feed.slot, x, y, r, 0.50, 0, 100, null, null, null ].join(",") + "\n");
}; };
done(); done();
}); });
next(null, tr, sections);
}], function(err, tr, sections) {
var rs = fs.createReadStream(input);
var ws = fs.createWriteStream(output);
var i = 0;
async.forEachSeries(sections, function(section, next) {
ws.write(section.join("\n") + (++i < 4 ? "\n\n" : "\n"), next);
}, function() {
rs.pipe(tr); rs.pipe(tr);
tr.pipe(ws); tr.pipe(ws).on("close", function() {
}]); });
});
});
} }

View file

@ -1,6 +1,17 @@
0,0,1,237.8710,-103.0732,270.0000 %,section 1
0,1,1,213.8680,-99.4156,270.0000 65535,0,0.00,0.00
0,2,3,219.3061,-52.4408,210.0000
0,3,3,219.9640,-55.0062,180.0000 %,section 2
0,4,3,223.6470,-55.5840,90.0000 65535,1,1,0.00,0.00,4.00,100nF,
0,5,3,214.8840,-60.2615,90.0000 65535,1,3,-0.25,0.00,4.00,0.1uF,
%,section 3
65535,3,0.00,0.00,
%,section 4
0,0,1,237.8710,-103.0732,270.0000,0.5,0,100,,,
0,1,1,213.8680,-99.4156,270.0000,0.5,0,100,,,
0,2,3,219.3061,-52.4408,210.0000,0.5,0,100,,,
0,3,3,219.9640,-55.0062,180.0000,0.5,0,100,,,
0,4,3,223.6470,-55.5840,90.0000,0.5,0,100,,,
0,5,3,214.8840,-60.2615,90.0000,0.5,0,100,,,

1 0 %,section 1 0 1 237.8710 -103.0732 270.0000
2 0 65535,0,0.00,0.00 1 1 213.8680 -99.4156 270.0000
3 0 %,section 2 2 3 219.3061 -52.4408 210.0000
4 0 65535,1,1,0.00,0.00,4.00,100nF, 3 3 219.9640 -55.0062 180.0000
5 0 65535,1,3,-0.25,0.00,4.00,0.1uF, 4 3 223.6470 -55.5840 90.0000
6 0 %,section 3 5 3 214.8840 -60.2615 90.0000
7 65535,3,0.00,0.00,
8 %,section 4
9 0,0,1,237.8710,-103.0732,270.0000,0.5,0,100,,,
10 0,1,1,213.8680,-99.4156,270.0000,0.5,0,100,,,
11 0,2,3,219.3061,-52.4408,210.0000,0.5,0,100,,,
12 0,3,3,219.9640,-55.0062,180.0000,0.5,0,100,,,
13 0,4,3,223.6470,-55.5840,90.0000,0.5,0,100,,,
14 0,5,3,214.8840,-60.2615,90.0000,0.5,0,100,,,
15
16
17