/// <summary>
        /// 光谱基线校正
        /// </summary>
        /// <param name="xyDataList">第一项是X,后面是Y</param>
        /// <param name="method">基线校正方法.</param>
        /// <returns></returns>
        public static List <double[]> BaselineCorrect(List <double[]> xyDataList, BaseLineMethod method)
        {
            if (xyDataList.Count < 2)
            {
                ErrorString = "Invalid parameters";
                return(null);
            }

            var xyDatas = CommonMethod.CombineSpectrumDatas(xyDataList);

            if (xyDatas == null)
            {
                ErrorString = CommonMethod.ErrorString;
                return(null);
            }

            if (BaselineCorrect(xyDatas, xyDataList.Count, xyDataList[0].Length, method) == false)
            {
                return(null);
            }

            return(CommonMethod.SplitSpectrumDatas(xyDatas, xyDataList.Count));
        }
        /// <summary>
        /// AdvancedIdentify定性分析(光谱的数据点数量必须相同, X轴也必须相同)
        /// </summary>
        /// <param name="apiList">API原始光谱插值后,一列X轴,一列Y轴</param>
        /// <param name="inferList">干扰组分原光谱插值后,一列X轴,多列Y轴</param>
        /// <param name="sampleList">待分析物原始光谱插值后,一列X轴,一列Y轴</param>
        /// <param name="coefMethod">相关方法,0为标准,1为增强</param>
        /// <param name="baseline">基线校正方法</param>
        /// <param name="derivatives">导数平滑方法(有基线校正,忽略导数平滑)</param>
        /// <param name="smoothPoints">平滑窗口大小(5-99)</param>
        /// <param name="polyDegree">导数的阶数,2,3,4</param>
        /// <param name="firstX">起始计算X轴,-1表示使用API光谱的firstX</param>
        /// <param name="lastX">结束计算X轴,-1表示使用API光谱的lastX</param>
        /// <returns></returns>
        public static double Identify(List <double[]> apiList, List <double[]> inferList, List <double[]> sampleList, CoefficientMethod coefMethod,
                                      BaseLineMethod baseline = BaseLineMethod.None, DerivativeMethod derivatives = DerivativeMethod.None,
                                      int smoothPoints        = 7, int polyDegree = 2, double firstX = double.MinValue, double lastX = double.MaxValue)
        {
            if (apiList.Count != 2 || inferList.Count < 2 || sampleList.Count != 2)
            {
                ErrorString = "Invalid parameters";
                return(0);
            }

            if (smoothPoints > 99 || smoothPoints < 2 || polyDegree < 2 || polyDegree > 4)
            {
                ErrorString = "Invalid parameters";
                return(0);
            }

            //需要截取一部分光谱区间
            if (firstX != double.MinValue && lastX != double.MaxValue)
            {
                apiList    = CommonMethod.GetRangeData(apiList, firstX, lastX);
                inferList  = CommonMethod.GetRangeData(inferList, firstX, lastX);
                sampleList = CommonMethod.GetRangeData(sampleList, firstX, lastX);
            }

            firstX = apiList[0][0];
            lastX  = apiList[0][apiList[0].Length - 1];
            int dataCount = apiList[0].Length;

            //格式不相同,全部兼容到api光谱
            if (!CommonMethod.IsSameXDatas(inferList[0], firstX, lastX, dataCount))
            {
                inferList = Ai.Hong.Algorithm.PreProcessor.SplineCubicInterpolation(inferList, firstX, lastX, dataCount);
            }
            if (!CommonMethod.IsSameXDatas(sampleList[0], firstX, lastX, dataCount))
            {
                sampleList = Ai.Hong.Algorithm.PreProcessor.SplineCubicInterpolation(sampleList, firstX, lastX, dataCount);
            }

            //限定2种计算系数的方法,1=无权重, 2=强度
            coefMethod = coefMethod != CoefficientMethod.Normal ? CoefficientMethod.Weight : coefMethod;

            //拷贝为数组,好在Ai.Hong.Algorithm中处理
            var srcApiDatas = Ai.Hong.Algorithm.CommonMethod.CombineSpectrumDatas(apiList);
            var apiDatas    = Ai.Hong.Algorithm.CommonMethod.CombineSpectrumDatas(apiList);
            var inferDatas  = Ai.Hong.Algorithm.CommonMethod.CombineSpectrumDatas(inferList);
            var sampleDatas = Ai.Hong.Algorithm.CommonMethod.CombineSpectrumDatas(sampleList);

            if (apiDatas == null || inferDatas == null || sampleDatas == null)
            {
                ErrorString = CommonMethod.ErrorString;
                return(0);
            }

            //需要基线校正
            if (baseline != BaseLineMethod.None)
            {
                BaselineCorrect(apiDatas, apiList.Count, dataCount, baseline);
                BaselineCorrect(inferDatas, inferList.Count, dataCount, baseline);
                BaselineCorrect(sampleDatas, sampleList.Count, dataCount, baseline);
            }
            else if (derivatives != DerivativeMethod.None)                                                         //导数平滑
            {
                coefMethod = coefMethod == CoefficientMethod.Normal ? coefMethod : CoefficientMethod.SquareWeight; //纪南的程序里面,导数后,增强方法计算系数的方式不一样(使用强度平方)

                PreProcessor.SGSmoothAndDerivative(apiDatas, apiList.Count, dataCount, smoothPoints, polyDegree, (int)derivatives);
                PreProcessor.SGSmoothAndDerivative(inferDatas, inferList.Count, dataCount, smoothPoints, polyDegree, (int)derivatives);
                PreProcessor.SGSmoothAndDerivative(sampleDatas, sampleList.Count, dataCount, smoothPoints, polyDegree, (int)derivatives);

                //纪南的导数没有除以X轴步长
                double stepx = apiDatas[1] - apiDatas[0];
                for (int i = dataCount; i < apiDatas.Length; i++)
                {
                    apiDatas[i] *= stepx;
                }

                stepx = inferDatas[1] - inferDatas[0];
                for (int i = dataCount; i < inferDatas.Length; i++)
                {
                    inferDatas[i] *= stepx;
                }

                stepx = sampleDatas[1] - sampleDatas[0];
                for (int i = dataCount; i < sampleDatas.Length; i++)
                {
                    sampleDatas[i] *= stepx;
                }
            }

            return(Identify(srcApiDatas, apiDatas, inferDatas, inferList.Count, sampleDatas, coefMethod));
        }
        /// <summary>
        /// 光谱基线校正
        /// </summary>
        /// <param name="spectrumDatas">第一行为X数据,后面几行为Y数据</param>
        /// <param name="specRows">数据的行数</param>
        /// <param name="specCols">数据的列数</param>
        /// <param name="method">基线校正方法</param>
        /// <returns></returns>
        public static bool BaselineCorrect(double[] spectrumDatas, int specRows, int specCols, BaseLineMethod method)
        {
            if (spectrumDatas == null || spectrumDatas.Length != specRows * specCols)
            {
                ErrorString = "Invalid parameters";
                return(false);
            }

            if (method == BaseLineMethod.None)
            {
                return(true);
            }

            try
            {
                if (CommonMethod.Is64BitVersion())
                {
                    return(ADBaselineCorrect64(spectrumDatas, specRows, specCols, (int)method));
                }
                else
                {
                    return(ADBaselineCorrect32(spectrumDatas, specRows, specCols, (int)method));
                }
            }
            catch (Exception ex)
            {
                ErrorString = ex.Message;
                return(false);
            }
        }