コード例 #1
0
ファイル: IOModule.cs プロジェクト: liuhahayue/Coupling1DBF
        public static List <ClotDscr> readClotFile(string filename)
        {
            string text = File.ReadAllText(filename);

            string[]        lines  = text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            Regex           regex  = new Regex(@"^(\d+)\s+DG:(0.\d+)$", RegexOptions.IgnoreCase);
            List <ClotDscr> result = new List <ClotDscr>();

            for (int i = 0; i < lines.GetLength(0); i++)
            {
                Match clot_match = regex.Match(lines[i]);
                if (clot_match.Groups.Count != 3)
                {
                    continue;
                }

                int      id = int.Parse(clot_match.Groups[1].Value);
                double   DG = double.Parse(clot_match.Groups[2].Value);
                ClotDscr cd = new ClotDscr();
                cd.node_id = id;
                cd.degree  = (float)DG;
                result.Add(cd);
            }

            return(result);
        }
コード例 #2
0
ファイル: IOModule.cs プロジェクト: liuhahayue/Coupling1DBF
        public static string readTaskFile(string filename, ref string top_filename, ref string par_filename, ref List <Tuple <int, string> > inlet_data, ref List <ClotDscr> task, ref string out_filename, ref int Coupled_Nodes_N)
        {
            string text = File.ReadAllText(filename);

            string[] lines = text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            string[] path_tmp = filename.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);

            //        string base_path = "";
            //        for (int i = 0; i < path_tmp.GetLength(0) - 1; i++)
            //base_path += path_tmp[i] + Path.DirectorySeparatorChar;

            int    filenamelength = path_tmp.Last().Length;
            string base_path      = filename.Substring(0, filename.Length - filenamelength);
            //modelling parameters
            string modelling_parameter_file = base_path + "Model_parameters.txt";

            ReadModellingParameters(modelling_parameter_file);

            Regex regex = new Regex(@"^<(\w+)>$", RegexOptions.IgnoreCase);

            int line_counter;

            for (line_counter = 0; line_counter < lines.GetLength(0); line_counter++)
            {
                Match name_match = regex.Match(lines[line_counter]);
                if (name_match.Groups.Count != 2)
                {
                    line_counter++;
                    continue;
                }
                out_filename = name_match.Groups[1].Value + ".out";
                line_counter++;
                break;
            }

            regex = new Regex(@"^Topology:\s*(\w+.*)$", RegexOptions.IgnoreCase);
            for (int i = line_counter; i < lines.GetLength(0); i++)
            {
                Match top_match = regex.Match(lines[i]);
                if (top_match.Groups.Count != 2)
                {
                    continue;
                }

                top_filename = top_match.Groups[1].Value;
                break;
            }

            regex = new Regex(@"^InletFlux:\s+(.+)$", RegexOptions.IgnoreCase);
            for (int i = line_counter; i < lines.GetLength(0); i++)
            {
                Match inlet_match = regex.Match(lines[i]);
                if (inlet_match.Groups.Count != 2)
                {
                    continue;
                }

                string[] inlets = inlet_match.Groups[1].Value.Split(',');
                foreach (var inlt in inlets)
                {
                    string[]            s      = inlt.Trim().Split(' ');
                    Tuple <int, string> in_tlp = new Tuple <int, string>(int.Parse(s[0]), s[1].Trim());
                    inlet_data.Add(in_tlp);
                }

                //  inlet_filename = inlet_match.Groups[1].Value;
                break;
            }

            regex = new Regex(@"^OutletParams:\s*(\w+.*)$", RegexOptions.IgnoreCase);
            for (int i = line_counter; i < lines.GetLength(0); i++)
            {
                Match par_match = regex.Match(lines[i]);
                if (par_match.Groups.Count != 2)
                {
                    continue;
                }

                par_filename = par_match.Groups[1].Value;
                break;
            }

            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(localization);

            regex = new Regex(@"^Task:\s*(.+)$", RegexOptions.IgnoreCase);
            for (int i = line_counter; i < lines.GetLength(0); i++)
            {
                Match task_match = regex.Match(lines[i]);
                if (task_match.Groups.Count != 2)
                {
                    continue;
                }

                string[] stenosis = task_match.Groups[1].Value.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var st in stenosis)
                {
                    string [] id_dergee = st.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                    ClotDscr  dscr      = new ClotDscr();
                    dscr.node_id = int.Parse(id_dergee[0]);
                    dscr.degree  = float.Parse(id_dergee[1]);
                    task.Add(dscr);
                }
            }

            regex = new Regex(@"^NumberCoupledPoints:\s*(.+)$", RegexOptions.IgnoreCase);
            for (int i = line_counter; i < lines.GetLength(0); i++)
            {
                Match par_match = regex.Match(lines[i]);
                if (par_match.Groups.Count != 2)
                {
                    continue;
                }

                //Console.WriteLine(par_match.Groups[1].Value);
                Coupled_Nodes_N = int.Parse(par_match.Groups[1].Value);
                break;
            }

            return(base_path);
        }