UNPKG

@xogeny/mat-parser

Version:

A parser for MATLAB v4 files

120 lines 4.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const parser_1 = require("../parser"); function trim(a) { let buf = new Buffer(a); let str = buf.toString('ascii'); str = str.replace(/\0/g, ""); return str.trim(); } class DymolaSignalExtractor extends parser_1.NullHandler { constructor() { super(...arguments); this.columns = {}; this.descriptions = {}; } column(name, colnum, format, column, last) { if (name == "name") { let str = trim(column); this.columns[colnum] = str; } if (name == "description") { let name = this.columns[colnum]; let desc = trim(column); this.descriptions[name] = desc; } } end(name) { if (name == "description") { return true; } return false; } } exports.DymolaSignalExtractor = DymolaSignalExtractor; class DymolaResultsExtractor extends parser_1.NullHandler { constructor(trajPredicate, finalPredicate) { super(); this.trajPredicate = trajPredicate; this.finalPredicate = finalPredicate; this.tdets = {}; this.fdets = {}; this.tcols = {}; this.fcols = {}; this.trajectories = {}; this.finals = {}; } column(name, colnum, format, column, last) { if (name == "name") { let str = trim(column); if (this.trajPredicate(str)) { this.tdets[str] = { varnum: colnum, }; this.tcols[colnum] = str; this.trajectories[str] = []; } if (this.finalPredicate(str)) { this.fdets[str] = { varnum: colnum, }; this.fcols[colnum] = str; this.finals[str] = null; } } if (name == "description") { if (this.tcols.hasOwnProperty(colnum)) { let name = this.tcols[colnum]; let str = trim(column); this.tdets[name].description = str; } if (this.fcols.hasOwnProperty(colnum)) { let name = this.fcols[colnum]; let str = trim(column); this.fdets[name].description = str; } } if (name == "dataInfo") { if (this.tcols.hasOwnProperty(colnum)) { let key = this.tcols[colnum]; this.tdets[key].constant = column[0] == 1; this.tdets[key].column = Math.abs(column[1]) - 1; this.tdets[key].scale = column[1] >= 0 ? 1 : -1; } if (this.fcols.hasOwnProperty(colnum)) { let key = this.fcols[colnum]; this.fdets[key].constant = column[0] == 1; this.fdets[key].column = Math.abs(column[1]) - 1; this.fdets[key].scale = column[1] >= 0 ? 1 : -1; } } if (name == "data_1") { Object.keys(this.tdets).forEach((key) => { if (this.tdets[key].constant) { this.trajectories[key] = this.tdets[key].scale * column[this.tdets[key].column]; } }); Object.keys(this.fdets).forEach((key) => { if (this.fdets[key].constant) { this.finals[key] = this.fdets[key].scale * column[this.fdets[key].column]; } }); } if (name == "data_2") { Object.keys(this.tdets).forEach((key) => { if (!this.tdets[key].constant) { this.trajectories[key].push(this.tdets[key].scale * column[this.tdets[key].column]); } }); if (last) { Object.keys(this.fdets).forEach((key) => { if (!this.fdets[key].constant) { this.finals[key] = this.fdets[key].scale * column[this.fdets[key].column]; } }); } } } } exports.DymolaResultsExtractor = DymolaResultsExtractor; //# sourceMappingURL=dsres.js.map