-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
1 lines (1 loc) · 4.97 KB
/
index.js
1
'use strict';var _createClass=function(){function a(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,'value'in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}();function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}var fs=require('fs'),math=require('mathjs');module.exports=function(){function a(b,c){return _classCallCheck(this,a),privMeths.new.call(this,b,c),this}return _createClass(a,[{key:'ReIm',value:function c(a){var b=[];if(4==this.params)switch(a){case 11:b=this.p11;break;case 21:b=this.p21;break;case 12:b=this.p12;break;case 22:b=this.p22;break;default:}else switch(a){case 11:b=this.p11;break;case 21:b=this.p21;break;default:}return b}},{key:'LogMag',value:function c(a){var b=[];if(4==this.params)switch(a){case 11:b=privMeths.logmag.call(this,this.p11);break;case 21:b=privMeths.logmag.call(this,this.p21);break;case 12:b=privMeths.logmag.call(this,this.p12);break;case 22:b=privMeths.logmag.call(this,this.p22);break;default:}else switch(a){case 11:b=privMeths.logmag.call(this,this.p11);break;case 21:b=privMeths.logmag.call(this,this.p21);break;default:}return b}},{key:'LinMag',value:function c(a){var b=[];if(4==this.params)switch(a){case 11:b=privMeths.linmag.call(this,this.p11);break;case 21:b=privMeths.linmag.call(this,this.p21);break;case 12:b=privMeths.linmag.call(this,this.p12);break;case 22:b=privMeths.linmag.call(this,this.p22);break;default:}else switch(a){case 11:b=privMeths.linmag.call(this,this.p11);break;case 21:b=privMeths.linmag.call(this,this.p21);break;default:}return b}},{key:'LinAngle',value:function c(a){var b=[];if(4==this.params)switch(a){case 11:b=privMeths.linang.call(this,this.p11);break;case 21:b=privMeths.linang.call(this,this.p21);break;case 12:b=privMeths.linang.call(this,this.p12);break;case 22:b=privMeths.linang.call(this,this.p22);break;default:}else switch(a){case 11:b=privMeths.linang.call(this,this.p11);break;case 21:b=privMeths.linang.call(this,this.p21);break;default:}return b}},{key:'VSWR',value:function a(){return privMeths.vswr.call(this,this.p11)}},{key:'ZIN',value:function a(){return privMeths.zin.call(this,this.p11)}},{key:'searchFreq',value:function d(c,a){var b=privMeths.closestFreq.call(this,c);switch(a){case 11:return this.p11[b];break;case 21:return this.p21[b];break;case'RL':return privMeths.logmag.call(this,this.p11)[b];break;case'VSWR':return this.p11(b);break;default:return this.freq[b];}}},{key:'save',value:function b(a){fs.writeFileSync('./results/'+a,JSON.stringify(this),'utf8',function(a){return a?void console.error(a):void console.log('Saved JSON Object to File')})}}]),a}();var privMeths={new:function f(a,b){var c=this,d=void 0;a?d=fs.readFileSync(__dirname+a,'utf8').split('\n').filter(function(a){return'!'!=a.charAt(0)}):b&&(d=b);var e=d[0].replace(/\s/g,' ').split(' ').filter(Boolean);this.fscale=3*['HZ','KHZ','MHZ','GHZ','THZ'].indexOf(e[1].toUpperCase()),this.format=e[3].toUpperCase(),this.load=e[5],this.freq=[],this.p11=[],this.p21=[],this.p12=[],this.p22=[],d.splice(d.length-1,1),d=d.forEach(function(a){var b=Math.sin,d=Math.cos,f=Math.PI,g=Math.pow;a=a.replace(/\s/g,' ').split(' ').filter(Boolean),a.forEach(function(b,c){b=b.toUpperCase().split('E').filter(Boolean),a[c]=2<=b.length?math.round(parseFloat(b[0]*g(10,parseFloat(b[1]))),3):math.round(parseFloat(b[0]),3)}),c.freq.push(Math.round(a[0])),'DB'==c.format?a.forEach(function(c,e){0==(e-1)%2&&(a[e]=math.round(g(10,c/20)*d(a[e+1]*f/180),3),a[e+1]=math.round(g(10,c/20)*b(a[e+1]*f/180),3))}):'MA'==c.format&&a.forEach(function(c,e){0==(e-1)%2&&(a[e]=math.round(c*d(a[e+1]*f/180),3),a[e+1]=math.round(c*b(a[e+1]*f/180),3))}),c.p11.push({x:a[1],y:a[2]}),c.p21.push({x:a[3],y:a[4]}),c.p12.push({x:a[5],y:a[6]}),c.p22.push({x:a[7],y:a[8]})}),this.freq.splice(0,1),this.p11.splice(0,1),this.p21.splice(0,1),this.p12.splice(0,1),this.p22.splice(0,1),privMeths.findEmpty.call(this)?this.params=4:(this.params=2,delete this.p12,delete this.p22)},findEmpty:function c(){var b=0;return this.p12.forEach(function(a){b+=a.x+a.y}),0<b},logmag:function c(a){var b=[];return a.forEach(function(c){var d=math.complex(c.x,c.y);b.push(math.round(20*math.log10(math.abs(d)),3))}),b},vswr:function c(a){var b=[];return a.forEach(function(c){var d=math.abs(math.complex(c.x,c.y));b.push(math.round((1+d)/(1-d),3))}),b},linmag:function c(a){var b=[];return a.forEach(function(c){var d=math.abs(math.complex(math.round(c.x,3),math.round(c.y,3)));b.push(math.round(d,3))}),b},linang:function c(a){var b=[];return a.forEach(function(c){var d=math.complex(c.x,c.y);math.round(d,3),d=d.toPolar(),b.push({r:math.round(d.r,3),phi:math.round(d.phi,3)})}),b},zin:function c(a){var d=[],b=this.lo;return a.forEach(function(e){var f=math.complex(e.x,e.y),a=math.add(f,1),b=math.subtract(f,1);d.push(math.round(math.divide(a,b),3))}),d},closestFreq:function d(a){var b=Number.MAX_SAFE_INTEGER,c=0;return this.freq.forEach(function(d,e){var f=Math.abs(a-d);f<b&&(c=e,b=f)}),c}};