Example #1
0
        static void Main(string[] args)
        {
            /*Process.Start("../../RunParamics.bat");
             * Console.WriteLine("Press return to continue:");
             * Console.Read();*/


            string NetName = @"C:\Documents and Settings\Siemens\Desktop\Andrew's Work\Paramics Models\Simple Crossroads\Simple Crossroads";

            ParamicsPuppetMaster.EditNodes EN  = new ParamicsPuppetMaster.EditNodes(NetName);
            ReadTurningIntention           RTI = new ReadTurningIntention();

            double dist = EN.NodeList[4].DistToNode(EN.NodeList[3]);
            //Console.WriteLine(dist);
            double X = EN.NodeList[1].X;
            double Y = EN.NodeList[1].Y;
            string ResultTurningIntention;

            ResultTurningIntention = RTI.NextLinkNumber("4", "0", "2");

            //string ResultStageNumber;
            //ResultStageNumber = RTI.StageRequired("3", "4");
            //string ResultNextTurningIntention = RTI.NextNextLinkNumber(ResultTurningIntention, "0");

            Console.WriteLine(X);
            Console.WriteLine(Y);
            Console.WriteLine(ResultTurningIntention);
            //Console.WriteLine(ResultStageNumber);
            //Console.WriteLine(ResultNextTurningIntention);
            Console.Read();
        }
        //constructor function
        private void ConstructorFunction()
        {
            try
            {
                DirectoryInfo        LogDirI                  = new DirectoryInfo(LogDir);
                FileInfo[]           snaplist                 = LogDirI.GetFiles("snap*");
                DateTime             TimeNow                  = new DateTime();
                DateTime             ZeroHour                 = DateTime.Parse("00:00:00");
                LinkID               LinkNow                  = new LinkID();
                ReadTurningIntention RTI                      = new ReadTurningIntention();
                string               TempVariableNextLink     = "";
                string               TempVariableNextNextLink = "";
                string               TempVariableNextTurn     = "";
                string               TempVariableNextNextTurn = "";


                FileInfo snapfile = snaplist[snaplist.Length - 1];
                using (StreamReader ReadFile = new StreamReader(snapfile.FullName))
                {
                    string FileLine;
                    while ((FileLine = ReadFile.ReadLine()) != null)
                    {
                        if (FileLine.Contains("snapshot at time"))
                        {
                            string[] splitline = FileLine.Split(new char[] { ' ' });
                            double   TimeSecs  = Convert.ToDouble(splitline[3]);
                            TimeNow = ZeroHour.AddSeconds(TimeSecs);
                        }
                        else if (FileLine.Contains("on link"))
                        {
                            string[] splitline = FileLine.Split(new char[] { ' ', ':' });
                            LinkNow = new LinkID(splitline[2], splitline[3]);
                            //ApproachNode = splitline[2];
                            //JunctionNode = splitline[3];
                        }
                        else if (FileLine.Contains("type "))
                        {
                            FileData TempDat = new FileData();

                            if (FileLine.Contains("path"))
                            {
                                string[] splitline = FileLine.Split(new char[] { ' ', '"' });
                                TempDat.Vtype       = Convert.ToInt32(splitline[1]) + 1;
                                TempDat.Origin      = Convert.ToInt32(splitline[15]) + 1;
                                TempDat.Destination = Convert.ToInt32(splitline[16]) + 1;
                                TempDat.Vspeed      = Convert.ToDouble(splitline[13]);
                                TempDat.LinkDist    = Convert.ToDouble(splitline[8]);
                                TempDat.RouteName   = splitline[6];
                                TempDat.OnLink      = LinkNow;
                                TempDat.AtTime      = TimeNow;
                                double bornsecs = Convert.ToDouble(splitline[17]);
                                TempDat.BornTime      = ZeroHour.AddSeconds(bornsecs);
                                TempDat.MagicNumbers  = ("[" + splitline[10]);
                                TempDat.MagicNumbers += ("," + splitline[20] + "]");    //This needs to be checked

                                Fdata.Add(TempDat);
                            }
                            else
                            {
                                string[] splitline = FileLine.Split(new char[] { ' ' });
                                TempDat.Vtype       = (Convert.ToInt32(splitline[1])) + 1;
                                TempDat.Origin      = (Convert.ToInt32(splitline[10])) + 1;
                                TempDat.Destination = (Convert.ToInt32(splitline[11])) + 1;
                                TempDat.Lane        = (Convert.ToInt32(splitline[7]));

                                TempDat.Vspeed   = Convert.ToDouble(splitline[8]);
                                TempDat.LinkDist = Convert.ToDouble(splitline[3]);
                                TempDat.OnLink   = LinkNow;
                                TempDat.AtTime   = TimeNow;
                                double bornsecs = Convert.ToDouble(splitline[12]);
                                TempDat.BornTime      = ZeroHour.AddSeconds(bornsecs);
                                TempDat.MagicNumbers  = ("[" + splitline[5]);
                                TempDat.MagicNumbers += ("," + splitline[15] + "]");
                                TempVariableNextLink  = RTI.NextLinkNumber(LinkNow.StartNode, LinkNow.EndNode, splitline[13]);
                                if (TempVariableNextLink == "null")
                                {
                                    TempDat.NextLink     = "99999";           //TODO 99999 could be a next link number!
                                    TempDat.NextNextLink = "99999";
                                }
                                else
                                {
                                    TempDat.NextLink = TempVariableNextLink;
                                }
                                TempVariableNextNextLink = RTI.NextLinkNumber(LinkNow.EndNode, TempVariableNextLink, splitline[14]);
                                if (TempVariableNextNextLink == "null")
                                {
                                    TempDat.NextNextLink = "99999";
                                }
                                else
                                {
                                    TempDat.NextNextLink = TempVariableNextNextLink;
                                }
                                TempVariableNextTurn = RTI.NextTurnDirection(LinkNow.StartNode, LinkNow.EndNode, splitline[13]);
                                if (TempVariableNextTurn == "null")
                                {
                                    TempDat.NextTurn     = "None";           //99999 shows an error
                                    TempDat.NextNextTurn = "None";
                                }
                                else
                                {
                                    TempDat.NextTurn = TempVariableNextTurn;
                                }
                                TempVariableNextNextTurn = RTI.NextTurnDirection(LinkNow.EndNode, TempVariableNextLink, splitline[14]);
                                if (TempVariableNextNextTurn == "null")
                                {
                                    TempDat.NextNextTurn = "None";          //99999 shows an error
                                }
                                else
                                {
                                    TempDat.NextNextTurn = TempVariableNextNextTurn;
                                }
                                //TempDat.NextTurn = "Null10";
                                //TempDat.NextNextTurn = "Null10";
                                Fdata.Add(TempDat);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Let the user know what went wrong.
                Console.WriteLine("Error reading snapfiles:");
                Console.WriteLine(e.Message);
            }
        }