예제 #1
0
        /// <summary>
        /// 从文件中读取相应气动力数据
        /// <para>可连续读取多个文件,则把所有参数都赋值给类内部参数List<>...)</para>
        /// </summary>
        /// <param name="filename">气动力数据文件名</param>
        private void ReadFrom(string filename)
        {
            string line = string.Empty;

            try
            {
                SplineInterp spline;

                //打开文件
                StreamReader sr = new StreamReader(filename, Encoding.GetEncoding("gb2312"));

                while (true)
                {
                    //读取一行数据(忽略空行和注释行)
                    line = FileIO.ReadSkipCommentSpaceLine(sr);

                    //读到文件结尾则退出
                    if (line == null)
                    {
                        break;
                    }

                    //读取1维插值表
                    if (line.ToUpper().Contains("BEGIN DATA1D"))
                    {
                        spline = new SplineInterp();
                        spline.ReadData1D(sr);

                        if (data1D == null)
                        {
                            data1D = new List <SplineInterp>();
                        }
                        data1D.Add(spline);
                    }
                    //读取2维插值表
                    else if (line.ToUpper().Contains("BEGIN DATA2D"))
                    {
                        spline = new SplineInterp();
                        spline.ReadData2D(sr);

                        if (data2D == null)
                        {
                            data2D = new List <SplineInterp>();
                        }
                        data2D.Add(spline);
                    }
                }
                //关闭文件
                sr.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message + "\n" + "此行数据错误: " + line + "\n"
                                    + "文件读取错误,文件名: " + filename);
            }
        }
예제 #2
0
        //#####################################################################
        /// <summary>
        /// 静态函数: 读取插值表数据文件(全是1维数组插值表)
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static List <SplineInterp> ReadFromFile1D(string fileName)
        {
            List <SplineInterp> tables = new List <SplineInterp>();
            SplineInterp        table;

            string line = string.Empty;

            try
            {
                if (fileName == null)
                {
                    throw new Exception("输入文件名为空!");
                }

                //打开文件
                StreamReader sr = new StreamReader(fileName, Encoding.GetEncoding("gb2312"));

                while (true)
                {
                    //读取一行数据(忽略空行和注释行)
                    line = FileIO.ReadSkipCommentSpaceLine(sr);

                    //读到文件结尾则退出
                    if (line == null)
                    {
                        break;
                    }

                    //读取发动机数据
                    if (line.ToUpper().Contains("BEGIN"))
                    {
                        table = new SplineInterp();
                        table.ReadData1D(sr);
                        tables.Add(table);
                    }
                }
                //关闭文件
                sr.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message + "\n" + "此行数据错误: " + line);
            }
            return(tables);
        }