public bool Run(string[] args) { var mo = new MiniOption(); AddOptionData(mo); if (!mo.Parse(args)) { return(false); } if (mo.Files.Count < 1) { Usage(); return(false); } InputFilename = mo.Files[0]; if (!CheckOption(mo)) { return(false); } // 拡張子判別 if (RunMode == RunModeType.None) { var e = Path.GetExtension(InputFilename); var IsWavFile = (string.IsNullOrEmpty(e) || e.ToLower() == ".wav"); RunMode = IsWavFile ? RunModeType.Read : RunMode = RunModeType.Write; } if (string.IsNullOrEmpty(OutputFilename)) { OutputFilename = "output." + (RunMode == RunModeType.Read ? "txt" : "wav"); } Console.WriteLine("Output : " + OutputFilename); if (RunMode != RunModeType.Read) { Console.WriteLine("Write WAV File From Text..."); if (!OutputDataWave()) { return(false); } } else { Console.WriteLine("Write Text From WAV File ..."); if (!OutputDataText()) { return(false); } } Console.WriteLine("Done"); return(true); }
public bool CheckOption(MiniOption miniopt) { foreach (var o in miniopt.Result) { switch (o.Type) { case (int)OptionType.Read: RunMode = RunModeType.Read; break; case (int)OptionType.Write: RunMode = RunModeType.Write; break; case (int)OptionType.OutputFile: OutputFilename = o.Value; break; case (int)OptionType.StartPosition: Console.WriteLine("Start:" + o.Value); RecordStart = Convert.ToInt32(o.Value); break; case (int)OptionType.RecordLength: Console.WriteLine("End:" + o.Value); RecordLength = Convert.ToInt32(o.Value); break; case (int)OptionType.LongPulseWidth: Console.WriteLine("LongPulseWidth:" + o.Value); LongPulseWidth = Convert.ToInt32(o.Value); break; case (int)OptionType.DebugRough: DebugFlag = true; break; case (int)OptionType.DebugDetail: DebugDetail = true; break; case (int)OptionType.Help: Usage(); return(false); } } return(true); }
public OutSet storeOutVar(ViewParams viewParams) { // use predictive equations OutSet outSet = new OutSet(inParams); OutCell[][] outCells; Axes axes; Comp comp; OutComp outComp; OutComp outCompt = null; float pos, pos0, post; float totposu, totposl; float timepos; float maxtime0; float eepos = 0; float intAmount = 0; float sigma, sigma0; float timesigma = 0; float con, maxcon; float amp0; float div0; float maxposu = 0; float maxposl = 0; float mindrawpos = 0; float maxdrawpos = 0; float range; float stepsize; int ncomps = inParams.comps.Count; int nsize = 1000; float k; PhaseType phase = new PhaseType(); KdefType kdef = inParams.kDefinition; RunModeType runMode = inParams.runMode; QuantityType natUnits = inParams.natUnits; float injectPos = 0; float lf = inParams.lf; float uf = inParams.uf; float px = inParams.px; float fu = 0; float fl = 0; float fnormu = 0; float fnorml = 0; float vc = 0; float mixspeed = 0; float efficiency = 0; bool allincol = true; bool timeMode = (inParams.viewUnits == QuantityType.Time); bool eeMode = (inParams.eeMode != EEModeType.None); bool intMode = (inParams.runMode == RunModeType.Intermittent); bool intCompMode = (inParams.intMode == IntModeType.Component); int intit; bool eluted; float elutable; eeDone = false; if (inParams.model == ModelType.CCD) { // [steps] vc = inParams.column; injectPos = inParams.getInjectPosNorm(); if (runMode == RunModeType.CoCurrent) { injectPos = (inParams.column - 1) - injectPos; } fnormu = inParams.fnormu; fnorml = inParams.fnorml; // always use normalised flows fu = fnormu; fl = fnorml; mixspeed = 1; efficiency = Equations.calcEff1(inParams.efficiency); } else if (inParams.model == ModelType.Probabilistic) { // [volume] vc = inParams.vc; injectPos = inParams.getInjectPosNorm(); fu = inParams.fu; fl = inParams.fl; // normalise flow fnormu = inParams.fnormu; fnorml = inParams.fnorml; if (fnorml > fnormu) { fnormu /= fnorml; fnorml = 1; } else { fnorml /= fnormu; fnormu = 1; } mixspeed = inParams.mixSpeed; efficiency = Equations.calcEff1(inParams.efficiency); } else if (inParams.model == ModelType.Transport) { // [time] natUnits = QuantityType.Time; vc = inParams.vc; injectPos = inParams.getInjectPosNorm(); fu = inParams.fu; fl = inParams.fl; // normalise flow fnormu = fu / uf; fnorml = fl / lf; if (fnorml > fnormu) { fnormu /= fnorml; fnorml = 1; } else { fnorml /= fnormu; fnormu = 1; } mixspeed = 1; efficiency = (float)Math.Sqrt(inParams.ka * 10); // **** make correct for f? dx? dt? } if (runMode != RunModeType.CoCurrent) { fl = -fl; fnorml = -fnorml; } // Set maxpos for (int compi = 0; compi < ncomps; compi++) { comp = inParams.comps[compi]; outComp = outSet.comps[compi]; elutable = Equations.calcElutable(kdef, fu, fl, outComp.k); outComp.willElute = (elutable > 0.01); if (outComp.willElute) { outCompt = calcNewPos(comp, fu, fl, vc, injectPos, natUnits); // outcomp is reassigned outComp = outSet.comps[compi]; // overwrite comp outComp.willElute = true; // restore willElute if (comp.elute) { if (outCompt.retention < 0) { phase = PhaseType.Lower; if (Math.Abs(outCompt.retention) > maxposl) { maxposl = Math.Abs(outCompt.retention); } } else { phase = PhaseType.Upper; if (Math.Abs(outCompt.retention) > maxposu) { maxposu = Math.Abs(outCompt.retention); } } sigma = Equations.calcSigma(kdef, fnormu, fnorml, comp.k * px, outCompt.retentionTime, mixspeed, efficiency); if (runMode == RunModeType.DualMode && inParams.model != ModelType.Transport) { sigma *= 2; } sigma = inParams.convertUnit(sigma, QuantityType.Time, natUnits, phase); } } else { if (intMode && inParams.intFinalElute) { outComp.willElute = true; } } } if (intMode && !intCompMode) { intamountu = inParams.convertUnit(inParams.intUpSwitch, (QuantityType)inParams.intMode, natUnits, PhaseType.Upper); intamountl = inParams.convertUnit(inParams.intLpSwitch, (QuantityType)inParams.intMode, natUnits, PhaseType.Lower); if (inParams.model == ModelType.CCD) { intamountut = intamountu; } else { intamountut = inParams.convertUnit(inParams.intUpSwitch, (QuantityType)inParams.intMode, QuantityType.Time, PhaseType.Upper); } if (inParams.model == ModelType.CCD) { intamountlt = intamountl; } else { intamountlt = inParams.convertUnit(inParams.intLpSwitch, (QuantityType)inParams.intMode, QuantityType.Time, PhaseType.Lower); } } if (inParams.model == ModelType.CCD) { pos0 = vc / inParams.uf * inParams.maxIt; // in reality [steps] } else { pos0 = vc * inParams.maxIt; } if (inParams.doMaxIt && maxposu > pos0) { maxposu = pos0; } if (inParams.model == ModelType.CCD) { pos0 = vc / inParams.lf * inParams.maxIt; // in reality [steps] } else { pos0 = vc * inParams.maxIt; } if (inParams.doMaxIt && maxposl > pos0) { maxposl = pos0; } // init estmax [time/steps] previewParams.estmaxtime = 0; previewParams.estmaxstep = 0; // Set peaks // *** improve int mode: loop for [intit] with inner loop for [comps]: enable compmode and time scale correction for (int i = 0; i < ncomps; i++) { comp = inParams.comps[i]; outComp = outSet.comps[i]; k = comp.k; post = 0; // Calculate pos if (intMode) { // Int mode intit = 0; eluted = false; totposu = 0; totposl = 0; timepos = 0; pos = injectPos; phase = inParams.intStartPhase; while (intit / 2 < inParams.intMaxIt && !eluted) { if (phase == PhaseType.Upper) { if (!intCompMode) { if (natUnits == QuantityType.Steps) { intAmount = intamountu; } else { intAmount = intamountut; } } outCompt = calcNewPos(comp, fu, 0, vc, pos, natUnits, !intCompMode, intAmount, QuantityType.Time); } else { if (!intCompMode) { if (natUnits == QuantityType.Steps) { intAmount = intamountl; } else { intAmount = intamountlt; } } outCompt = calcNewPos(comp, 0, fl, vc, pos, natUnits, !intCompMode, intAmount, QuantityType.Time); } eluted = outCompt.eluted; if (!eluted) { post += Math.Abs(outCompt.retention - pos); pos = outCompt.retention; if (phase == PhaseType.Upper) { totposu += intamountu; timepos += intamountut; } else { totposl += intamountl; timepos += intamountlt; } // prepare for next iteration/phase if (phase == PhaseType.Upper) { phase = PhaseType.Lower; } else { phase = PhaseType.Upper; } intit++; } } if (inParams.intFinalElute && !eluted) { // elute if (phase == PhaseType.Upper) { outCompt = calcNewPos(comp, fu, 0, vc, pos, natUnits); } else { outCompt = calcNewPos(comp, fl, 0, vc, pos, natUnits); } eluted = outCompt.eluted; } if (eluted) { // timepos is always positive //timepos+= inparams.convertUnit(Math::Abs(outCompt.ret),natUnits,UnitsType.Time,phase); timepos += Math.Abs(outCompt.retentionTime); if (timeMode) { // use timepos to calc pos if (inParams.model == ModelType.CCD) { pos = timepos; } else { pos = inParams.convertUnit(timepos, QuantityType.Time, natUnits, phase); } // correct negative pos if (phase == PhaseType.Lower) { pos = -Math.Abs(pos); } } else if (phase == PhaseType.Upper) { pos = totposu + outCompt.retention0; } else { pos = -totposl + outCompt.retention0; } } outComp.intIt = (float)intit / 2; outComp.intItSet = true; } else { // Normal (not Int) mode outCompt = calcNewPos(comp, fu, fl, vc, injectPos, natUnits, true, Math.Max(maxposu, maxposl), QuantityType.Volume); pos = outCompt.retention; post += Math.Abs(pos - injectPos); timepos = Math.Abs(outCompt.retentionTime); eluted = outCompt.eluted; } outComp.eluted = eluted; outComp.outCol = eluted; pos0 = pos; if (!eluted && eeMode) { // EE mode eeDone = true; if (inParams.isPosEEdir()) { eepos = inParams.convertUnit(maxposu, natUnits, inParams.viewUnits, phase); if (!timeMode) { eepos += (vc - pos0); } else { eepos = 0; } pos = maxposu + (vc - pos0); outCompt.phase = PhaseType.Upper; } else { eepos = inParams.convertUnit(maxposl, natUnits, inParams.viewUnits, phase); if (!timeMode) { eepos += pos0; } else { eepos = 0; } pos = -maxposl - pos0; outCompt.phase = PhaseType.Lower; } outComp.outCol = true; } phase = outCompt.phase; // Calculate sigma if (outComp.outCol || outComp.willElute) { // include ee outcol timesigma = Equations.calcSigma(kdef, fnormu, fnorml, k * px, Math.Abs(timepos), mixspeed, efficiency); if (runMode == RunModeType.DualMode) { timesigma *= 2; } if (natUnits == QuantityType.Steps) { // [steps] sigma = timesigma; } else { // [volume] if (!outComp.eluted) { sigma = inParams.convertColUnit(timesigma, QuantityType.Time, natUnits); } else { sigma = inParams.convertUnit(timesigma, QuantityType.Time, natUnits, phase); } } if (!outComp.eluted) { // calc col sigma also for EE outcol // [volume] or [steps] sigma0 = sigma; sigma = Equations.calcColSigma(sigma0, outCompt.retention0, post, vc); } if (outComp.eluted) { if (phase == PhaseType.Lower) { pos0 = pos - 3 * sigma; if (pos0 < mindrawpos) { mindrawpos = pos0; } } else { pos0 = pos + 3 * sigma; if (pos0 > maxdrawpos) { maxdrawpos = pos0; } } } } else { sigma = 1; phase = PhaseType.None; } outComp.sigma = sigma; outComp.phase = phase; // set estmax [time] if (outComp.outCol) { maxtime0 = Math.Abs(timepos) + 3 * timesigma; if (maxtime0 > previewParams.estmaxtime) { previewParams.estmaxtime = maxtime0; } } if (outComp.outCol) { if (outComp.eluted) { outComp.retention = inParams.convertUnit(Math.Abs(pos), natUnits, viewParams.viewUnits, phase); outComp.width = inParams.convertUnit(4 * sigma, natUnits, viewParams.viewUnits, phase); } else { // not eluted but outcol (by EE) outComp.retention = eepos; outComp.width = 4 * sigma; } } else { outComp.retention = inParams.convertColUnit(Math.Abs(pos), natUnits, viewParams.viewUnits); outComp.width = inParams.convertColUnit(4 * sigma, natUnits, viewParams.viewUnits); } outComp.drawPosition = pos; // convert to real value later // Calculate height if (float.IsInfinity(k) || sigma == 0) { outComp.height = 1; } else { outComp.height = Equations.calcHeight(sigma); // [volume] } outComp.height *= comp.m; } // set estmax [steps] if (inParams.doMaxIt) { // overwrite if maxit is set pos0 = 0; if (fu != 0) { pos0 = inParams.convertUnit(inParams.maxIt * vc, QuantityType.Volume, QuantityType.Time, PhaseType.Upper); } if (fl != 0) { pos0 = Math.Max(pos0, inParams.convertUnit(inParams.maxIt * vc, QuantityType.Volume, QuantityType.Time, PhaseType.Lower)); } if (previewParams.estmaxtime > pos0) { previewParams.estmaxtime = pos0; } } if (previewParams.estmaxtime == 0) { previewParams.estmaxtime = inParams.Tmnorm; previewParams.estmaxstep = inParams.column; } else { if (natUnits == QuantityType.Steps) { // CCD mode: time units are actually step units previewParams.estmaxstep = previewParams.estmaxtime; } else { previewParams.estmaxstep = inParams.convertUnit(previewParams.estmaxtime, QuantityType.Time, QuantityType.Steps, phase); } } if (maxdrawpos == 0 && mindrawpos == 0) { if (inParams.doMaxIt) { maxdrawpos = maxposu; mindrawpos = -maxposl; } } if (eeMode) { if (inParams.isPosEEdir()) { maxdrawpos += vc; } else { mindrawpos -= vc; } } range = maxdrawpos - mindrawpos + vc; // Correct drawpos for (int i = 0; i < ncomps; i++) { outComp = outSet.comps[i]; pos0 = outComp.drawPosition; if (outComp.outCol) { if (outComp.phase == PhaseType.Upper) { pos0 = maxdrawpos - pos0 + vc; } else { pos0 = mindrawpos - pos0; } allincol = false; } outComp.drawPosition = convModelToReal(pos0, mindrawpos); } // Set Axes axes = outSet.axes; axes.rangex = range; //inparams->convertUnit(drawrange,UnitsType::Time,viewparams->viewUnits,PhaseType::Up); axes.showCol = true; axes.colstart = convModelToReal(0, mindrawpos); axes.colend = convModelToReal(vc, mindrawpos); axes.scaleminulabel = 0; axes.scalemaxulabel = inParams.convertUnit(maxdrawpos, natUnits, inParams.natUnits, PhaseType.Upper); axes.scaleminllabel = 0; axes.scalemaxllabel = inParams.convertUnit(-mindrawpos, natUnits, inParams.natUnits, PhaseType.Lower); axes.scaleminu = convModelToReal(maxdrawpos + vc, mindrawpos); axes.scalemaxu = convModelToReal(vc, mindrawpos); axes.scaleminl = convModelToReal(mindrawpos, mindrawpos); axes.scalemaxl = convModelToReal(0, mindrawpos); axes.logScale = (viewParams.yScale == YScaleType.Logarithmic); axes.update(); // init outcells outCells = new OutCell[ncomps][]; for (int compi = 0; compi < ncomps; compi++) { outCells[compi] = new OutCell[nsize]; } axes.maxcon = new List <float>(ncomps); // Store outcells for (int compi = 0; compi < ncomps; compi++) { comp = inParams.comps[compi]; outComp = outSet.comps[compi]; // Pre-calcs to improve performance pos0 = outComp.drawPosition; sigma = outComp.sigma; if (sigma == 0) { sigma = 1; } amp0 = comp.m * Equations.calcHeight(sigma); div0 = 2 * (float)Math.Pow(sigma, 2); stepsize = range / nsize; maxcon = 0; for (int i = 0; i < nsize; i++) { pos = i * stepsize; // Real position // make sure peak top gets drawn: if (Math.Abs(pos - pos0) <= stepsize) { con = amp0; } else { con = amp0 * (float)Math.Exp(-Math.Pow(pos - pos0, 2) / div0); } if (con > maxcon && (outComp.outCol || allincol)) { maxcon = con; } outCells[compi][i] = new OutCell(pos, con); } axes.maxcon.Add(maxcon); // Correct sigma: outComp.sigma = outComp.width / 4; } outSet.outCells = outCells; return(outSet); }
public void reset() { comps = new List <Comp>(); profile = ProfileType.CCC; model = ModelType.Probabilistic; runMode = RunModeType.UpperPhase; eeMode = EEModeType.None; vc = 100; uf = 0.5f; lf = 1 - uf; fu = 1; fl = 0; column = 100; probUnits = 10000; densitySteps = 200; mixSpeed = 1; efficiency = 1; ka = 0.01f; doMaxIt = false; maxIt = 10; autoFilter = true; vdeadUnits = QuantityType.Volume; vdeadInEnabled = false; vdeadOutEnabled = false; vdeadInjectEnabled = false; vdeadIn = 0; vdeadOut = 0; vdeadInject = 0; injectMode = InjectModeType.Instant; injectPhase = PhaseType.Upper; injectPos = 0; injectVolume = 1; injectFeedUnits = QuantityType.Volume; injectFeed = 0; intMode = IntModeType.Time; intStartPhase = PhaseType.Upper; intUpSwitch = 0; intLpSwitch = 0; intUpComp = -1; intLpComp = -1; intMaxIt = 10; intFinalElute = true; ptransMode = false; ptransu = 1; ptransl = 1; kDefinition = KdefType.U_L; viewUnits = QuantityType.Volume; volUnits = VolUnitsType.ml; massUnits = MassUnitsType.mg; timeUnits = TimeUnitsType.min; advancedMode = false; }