public void ExportSnpFile(SParam sparamData, string FolderName, string FileName, string Unit, int iChn)
        {
            string[] OutputData;
            string   OutputFileName;

            if (!Directory.Exists(FolderName))
            {
                Directory.CreateDirectory(FolderName);
            }


            OutputFileName = FolderName + "Unit" + Unit + "_Chan" + (iChn).ToString() + "_" + FileName;
            OutputData     = new string[sparamData.Freq.Length + 3];
            OutputData[0]  = "#\tHZ\tS\tdB\tR 50";
            OutputData[1]  = "!\t" + DateTime.Now.ToShortDateString() + "\t" + DateTime.Now.ToLongTimeString();
            OutputData[2]  = "!Freq\t";

            for (int i = 0; i < sparamData.SParamData.Length; i++)
            {
                OutputData[2] += sparamData.SParamData[i].SParamDef.ToString() + "\t\t";
                for (int iPoint = 0; iPoint < sparamData.SParamData[i].SParam.Length; iPoint++)
                {
                    if (i == 0)
                    {
                        OutputData[iPoint + 3] += sparamData.Freq[iPoint].ToString();
                    }
                    OutputData[iPoint + 3] += "\t" + sparamData.SParamData[i].SParam[iPoint].DB +
                                              "\t" + sparamData.SParamData[i].SParam[iPoint].Phase;
                }
            }
            System.IO.File.WriteAllLines(OutputFileName + ".snp", OutputData);
        }
        public void RunTest(ref ATFReturnResult results)
        {
            string strError = string.Empty;
            // ReSharper disable once JoinDeclarationAndInitializer
            long testTime;

            TestCount = 0; //reset to start
            _speedo.Reset();
            _speedo.Start();

            foreach (SparamTestCase.TestCaseAbstract tc in objFBar.TestCases)
            {
                tc.RunTest();
                tc.BuildResults();
            }

            #region Create FmTrace file
            if (SnpFile.FileOutputEnable & TmpUnitNo <= SnpFile.FileOutputCount)
            {
                for (int i = 0; i < objFBar.SparamRaw.Length; i++)
                {
                    if (SnpFile.ADSFormat)
                    {
                        LibEqmtDriver.NA.SParam tsSparam = _eqNa.ConvertTourchStone(_traceSetting[i], objFBar.SparamRaw[i]);
                        _eqNa.ExportSnpFile(tsSparam, SnpFile.FileSourcePath, SnpFile.FileOutputFileName, TmpUnitNo.ToString(), i + 1);
                    }
                    else
                    {
                        _eqNa.ExportSnpFile(objFBar.SparamRaw[i], SnpFile.FileSourcePath, SnpFile.FileOutputFileName, TmpUnitNo.ToString(), i + 1);
                    }
                }
            }
            #endregion

            #region Add Result to Clotho
            for (int i = 0; i < objFBar.Result.Length; i++)
            {
                if (objFBar.Result[i].Enable)
                {
                    for (int iRst = 0; iRst < objFBar.Result[i].Header.Length; iRst++)
                    {
                        ATFResultBuilder.AddResult(ref results, objFBar.Result[i].Header[iRst], "", objFBar.Result[i].Result[iRst]);
                    }
                }
            }
            #endregion

            _speedo.Stop();
            testTime = _speedo.ElapsedMilliseconds;

            ATFResultBuilder.AddResult(ref results, "SparamTestTime", "mS", testTime);
        }
        public SParam ConvertTourchStone(STraceMatching TraceMatch, SParam sParamData)
        {
            SParam tsSparam = new SParam();

            int totalport = TraceMatch.NoPorts;
            int totalsparam = 1;
            int iCount = 0, i, x;

            //for (int counter = 1 ;counter <= totalport;counter ++)
            //{
            totalsparam = totalport * totalport;
            //}

            tsSparam.SParamData = new SParamData[totalsparam];
            tsSparam.Freq       = sParamData.Freq;
            tsSparam.NoPoints   = sParamData.NoPoints;

            for (i = 1; i <= totalport; i++)
            {
                for (x = 1; x <= totalport; x++)
                {
                    tsSparam.SParamData[iCount].SParamDef = (naEnum.ESParametersDef)
                                                            Enum.Parse(typeof(naEnum.ESParametersDef), "S" + i + x);
                    tsSparam.SParamData[iCount].SParam = new LibMath.MathLib.DataType[tsSparam.Freq.Length];
                    iCount++;
                }
            }

            for (i = 0; i < sParamData.SParamData.Length; i++)
            {
                for (x = 0; x < tsSparam.SParamData.Length; x++)
                {
                    if (tsSparam.SParamData[x].SParamDef == sParamData.SParamData[i].SParamDef)
                    {
                        tsSparam.SParamData[x].SParam = sParamData.SParamData[i].SParam;
                    }
                }
            }

            return(tsSparam);
        }
        public SParam GrabSParamRiData(int channelNumber)
        {
            int    offSet = 0;
            int    sParamDef;
            string tmpVar;

            string[] arrTrace, traces;
            string[] traceMap;
            double[] rawData;
            SParam   sparamData = new SParam();

            naEnum.ESFormat traceFormat;

            rawData = GrabRealImagData(channelNumber);

            tmpVar   = GetTraceInfo(channelNumber);
            tmpVar   = tmpVar.Replace("'", "").Replace("\n", "").Trim();
            arrTrace = tmpVar.Split(new char[] { ',' });

            //Get only odd number
            traces   = arrTrace.Where((item, index) => index % 2 != 0).ToArray();
            traceMap = arrTrace.Where((item, index) => index % 2 == 0).ToArray(); //new int[traces.Length];


            double[] fList = GetFreqList(channelNumber);
            sparamData.Freq     = fList;
            sparamData.NoPoints = fList.Length;
            int Basepoint = fList.Length;

            sparamData.SParamData = new SParamData[traces.Length];

            for (int i = 0; i < traces.Length; i++)
            {
                sParamDef   = (int.Parse(traceMap[i].Replace("Trc", "")) - 1);
                traceFormat = GetTraceFormat(channelNumber, sParamDef + 1);
                offSet      = i * Basepoint * 2;

                sparamData.SParamData[i].SParam    = new LibMath.MathLib.DataType[Basepoint];
                sparamData.SParamData[i].Format    = traceFormat;
                sparamData.SParamData[i].SParamDef = (naEnum.ESParametersDef)Enum.Parse(typeof(naEnum.ESParametersDef), traces[i]);

                for (int iPts = 0; iPts < Basepoint; iPts++)
                {
                    if (traceFormat == naEnum.ESFormat.GDEL)
                    {
                        sparamData.SParamData[i].SParam[iPts].DB    = rawData[offSet + iPts];
                        sparamData.SParamData[i].SParam[iPts].Phase = 0;
                    }
                    else
                    {
                        objMathData.Real = rawData[offSet + (iPts * 2)];
                        objMathData.Imag = rawData[offSet + (iPts * 2) + 1];

                        objMath.conv_RealImag_to_dBAngle(ref objMathData);

                        sparamData.SParamData[i].SParam[iPts].Real  = objMathData.Real;
                        sparamData.SParamData[i].SParam[iPts].Imag  = objMathData.Imag;
                        sparamData.SParamData[i].SParam[iPts].DB    = objMathData.DB;
                        sparamData.SParamData[i].SParam[iPts].Mag   = objMathData.Mag;
                        sparamData.SParamData[i].SParam[iPts].Phase = objMathData.Phase;
                    }
                }
            }
            return(sparamData);
        }