-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun.js
72 lines (53 loc) · 1.71 KB
/
run.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// CommonJS
var fs = require("fs");
var evalmodule = require("./evaluator.js");
var filename = 'modellen/model.xml';
function main() {
var N = 1e6; // aantal iteraties
var Nresults = 1e2; // write Nresults
var model = new evalmodule.Model();
model.readBogusXMLFile(filename);
console.log(model);
var evaluator = new evalmodule.ModelregelsEvaluator(model, true);
var results = evaluator.run(N);
console.log('DEBUG: finished running, returned!');
// Debug output
console.log(evaluator.namespace.varNames[0]+"["+Nresults+"]= ", results[Nresults-1][0]);
console.log(evaluator.namespace.varNames[1]+"["+Nresults+"]= ", results[Nresults-1][1]);
//writeCSV("output.csv", res, Nresults);
//bogusTable(res, Nresults);
}
// make a bogusTable to implement and test "table making" in the browser
function bogusTable(results, Nresults) {
// print all vars in Results class.
var i,j;
var varNames = results.namespace.varNames;
// table header
var header = '';
for (i = 0; i < varNames.length; i++) {
header += varNames[i]+'\t';
}
header += '\n';
console.log(header);
// rows
var row = '';
for (i = 0; i < Nresults; i++) {
for (j = 0, len = varNames.length; j < len; j++) {
row += results[i][j]+'\t';
}
row += '\n';
console.log(row);
row = '';
}
}
function writeCSV(filename, result, Nresults) {
var stream = fs.createWriteStream(filename);
stream.once('open', function() {
stream.write("t; x; y\n");
for (var i=0; i<Nresults; i++) {
stream.write(result.t[i]+"; "+result.x[i]+"; "+result.y[i]+"\n");
}
stream.end();
});
}
main();