Пример #1
0
        /// <summary>
        /// Read the point source data from the file "point.dat" and create and fill the point source arrays
        /// </summary>
        public static void Read()
        {
            List <SourceData> PQ = new List <SourceData>();

            double totalemission    = 0;
            int    countrealsources = 0;

            double[] emission_sourcegroup = new double[101];

            PQ.Add(new SourceData());

            if (Program.IMQ.Count == 0)
            {
                Program.IMQ.Add(0);
            }

            Deposition Dep = new Deposition();

            StreamReader read = new StreamReader("point.dat");

            try
            {
                string[] text = new string[1];
                string   text1;
                text1 = read.ReadLine();
                text1 = read.ReadLine();
                while ((text1 = read.ReadLine()) != null)
                {
                    text = text1.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
                    if (text.Length > 9)
                    {
                        double xsi = Convert.ToDouble(text[0].Replace(".", Program.Decsep)) - Program.IKOOAGRAL;
                        double eta = Convert.ToDouble(text[1].Replace(".", Program.Decsep)) - Program.JKOOAGRAL;
                        double dia = Convert.ToDouble(text[8].Replace(".", Program.Decsep));

                        //excluding all point sources outside GRAL domain
                        if (((eta - dia * 0.5) > Program.EtaMinGral) && ((xsi - dia * 0.5) > Program.XsiMinGral) && ((eta + dia * 0.5) < Program.EtaMaxGral) && ((xsi + dia * 0.5) < Program.XsiMaxGral))
                        {
                            //excluding all point sources with undesired source groups
                            {
                                Int16 SG       = Convert.ToInt16(text[10]);
                                int   SG_index = Program.Get_Internal_SG_Number(SG); // get internal SG number

                                if (SG_index >= 0)
                                {
                                    SourceData sd = new SourceData();
                                    sd.X1          = Convert.ToDouble(text[0].Replace(".", Program.Decsep));
                                    sd.Y1          = Convert.ToDouble(text[1].Replace(".", Program.Decsep));
                                    sd.Z1          = Convert.ToSingle(text[2].Replace(".", Program.Decsep));
                                    sd.ER          = Convert.ToDouble(text[3].Replace(".", Program.Decsep));
                                    sd.V           = Convert.ToSingle(text[7].Replace(".", Program.Decsep));
                                    sd.D           = Convert.ToSingle(text[8].Replace(".", Program.Decsep));
                                    sd.T           = Convert.ToSingle(text[9].Replace(".", Program.Decsep));
                                    sd.SG          = Convert.ToInt16(text[10]);
                                    sd.Mode        = 0; // standard mode = concentration only
                                    totalemission += sd.ER;
                                    emission_sourcegroup[SG_index] += sd.ER;
                                    countrealsources++;

                                    sd.TimeSeriesTemperature = GetTransientTimeSeriesIndex.GetIndex(Program.PS_TimeSerTempValues, "Temp@_", text);
                                    sd.TimeSeriesVelocity    = GetTransientTimeSeriesIndex.GetIndex(Program.PS_TimeSerVelValues, "Vel@_", text);

                                    if (text.Length > 15)         // deposition data available
                                    {
                                        Dep.Dep_Start_Index = 11; // start index for point sources
                                        Dep.SD         = sd;
                                        Dep.SourceData = PQ;
                                        Dep.Text       = text;
                                        if (Dep.Compute() == false)
                                        {
                                            throw new IOException();
                                        }
                                    }
                                    else // no depositon
                                    {
                                        PQ.Add(sd);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                string err = "Error when reading file point.dat in line " + (countrealsources + 3).ToString() + " Execution stopped: press ESC to stop";
                Console.WriteLine(err);
                ProgramWriters.LogfileProblemreportWrite(err);

                if (Program.IOUTPUT <= 0 && Program.WaitForConsoleKey) // not for Soundplan or no keystroke
                {
                    while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape))
                    {
                        ;
                    }
                }
                Environment.Exit(0);
            }
            read.Close();
            read.Dispose();

            int counter = PQ.Count + 1;

            Program.PS_Count += PQ.Count - 1;

            // Copy Lists to global arrays
            Array.Resize(ref Program.PS_ER, counter);
            Array.Resize(ref Program.PS_X, counter);
            Array.Resize(ref Program.PS_Y, counter);
            Array.Resize(ref Program.PS_Z, counter);
            Array.Resize(ref Program.PS_V, counter);
            Array.Resize(ref Program.PS_D, counter);
            Array.Resize(ref Program.PS_T, counter);
            Array.Resize(ref Program.PS_SG, counter);
            Array.Resize(ref Program.PS_PartNumb, counter);
            Array.Resize(ref Program.PS_Mode, counter);
            Array.Resize(ref Program.PS_V_Dep, counter);
            Array.Resize(ref Program.PS_V_sed, counter);
            Array.Resize(ref Program.PS_ER_Dep, counter);
            Array.Resize(ref Program.PS_Absolute_Height, counter);
            Array.Resize(ref Program.PS_TimeSeriesTemperature, counter);
            Array.Resize(ref Program.PS_TimeSeriesVelocity, counter);

            for (int i = 1; i < PQ.Count; i++)
            {
                Program.PS_ER[i] = PQ[i].ER;
                Program.PS_X[i]  = PQ[i].X1;
                Program.PS_Y[i]  = PQ[i].Y1;

                if (PQ[i].Z1 < 0) // negative value = absolute height
                {
                    Program.PS_Absolute_Height[i] = true;
                    if (Program.Topo != 1)
                    {
                        string err = "You are using absolute coordinates but flat terrain  - ESC = Exit";
                        Console.WriteLine(err);
                        ProgramWriters.LogfileProblemreportWrite(err);

                        if (Program.IOUTPUT <= 0 && Program.WaitForConsoleKey) // not for Soundplan or no keystroke
                        {
                            while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape))
                            {
                                ;
                            }
                        }
                        Environment.Exit(0);
                    }
                }
                else
                {
                    Program.PS_Absolute_Height[i] = false;
                }

                Program.PS_Z[i]      = (float)Math.Abs(PQ[i].Z1);
                Program.PS_V[i]      = PQ[i].V;
                Program.PS_D[i]      = PQ[i].D;
                Program.PS_T[i]      = PQ[i].T;
                Program.PS_SG[i]     = (byte)PQ[i].SG;
                Program.PS_V_Dep[i]  = PQ[i].Vdep;
                Program.PS_V_sed[i]  = PQ[i].Vsed;
                Program.PS_Mode[i]   = PQ[i].Mode;
                Program.PS_ER_Dep[i] = (float)(PQ[i].ER_dep);
                Program.PS_TimeSeriesTemperature[i] = PQ[i].TimeSeriesTemperature;
                Program.PS_TimeSeriesVelocity[i]    = PQ[i].TimeSeriesVelocity;
            }

            string info = "Total number of point sources: " + countrealsources.ToString();

            Console.WriteLine(info);
            ProgramWriters.LogfileGralCoreWrite(info);

            string unit = "[kg/h]: ";

            if (Program.Odour == true)
            {
                unit = "[MOU/h]: ";
            }

            info = "Total emission " + unit + (totalemission).ToString("0.000");
            Console.Write(info);
            ProgramWriters.LogfileGralCoreWrite(info);

            Console.Write(" (");
            for (int im = 0; im < Program.SourceGroups.Count; im++)
            {
                info = "  SG " + Program.SourceGroups[im] + unit + emission_sourcegroup[im].ToString("0.000");
                Console.Write(info);
                ProgramWriters.LogfileGralCoreWrite(info);
            }
            Console.WriteLine(" )");

            Program.PS_effqu = new float[Program.PS_Count + 1];

            PQ  = null;
            Dep = null;
        }
Пример #2
0
        /// <summary>
        /// Read Portal Sources from the file "portal.dat"
        /// </summary>
        public static void Read()
        {
            List <SourceData> TQ = new List <SourceData>();
            CultureInfo       ic = CultureInfo.InvariantCulture;

            double totalemission    = 0;
            int    countrealsources = 0;

            double[] emission_sourcegroup = new double[101];

            TQ.Add(new SourceData());

            if (Program.IMQ.Count == 0)
            {
                Program.IMQ.Add(0);
            }

            Deposition Dep = new Deposition();

            StreamReader read = new StreamReader("portals.dat");

            try
            {
                string[] text = new string[1];
                string   text1;
                text1 = read.ReadLine();
                text1 = read.ReadLine();
                while ((text1 = read.ReadLine()) != null)
                {
                    text = text1.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

                    double xsi1 = Convert.ToDouble(text[0], ic) - Program.IKOOAGRAL;
                    double eta1 = Convert.ToDouble(text[1], ic) - Program.JKOOAGRAL;
                    double xsi2 = Convert.ToDouble(text[2], ic) - Program.IKOOAGRAL;
                    double eta2 = Convert.ToDouble(text[3], ic) - Program.JKOOAGRAL;

                    //excluding all tunnel portals outside GRAL domain
                    if ((eta1 > Program.EtaMinGral) && (xsi1 > Program.XsiMinGral) && (eta1 < Program.EtaMaxGral) && (xsi1 < Program.XsiMaxGral) &&
                        (eta2 > Program.EtaMinGral) && (xsi2 > Program.XsiMinGral) && (eta2 < Program.EtaMaxGral) && (xsi2 < Program.XsiMaxGral))
                    {
                        //excluding all tunnel portals with undesired source groups
                        if (text.Length > 9)
                        {
                            Int16 SG       = Convert.ToInt16(text[10]);
                            int   SG_index = Program.Get_Internal_SG_Number(SG); // get internal SG number

                            if (SG_index >= 0)
                            {
                                SourceData sd = new SourceData();
                                sd.X1   = Convert.ToDouble(text[0], ic);
                                sd.Y1   = Convert.ToDouble(text[1], ic);
                                sd.X2   = Convert.ToDouble(text[2], ic);
                                sd.Y2   = Convert.ToDouble(text[3], ic);
                                sd.Z1   = Convert.ToSingle(text[4], ic);
                                sd.Z2   = Convert.ToSingle(text[5], ic);
                                sd.ER   = Convert.ToDouble(text[6], ic);
                                sd.SG   = Convert.ToInt16(text[10]);
                                sd.Mode = 0; // standard mode

                                totalemission += sd.ER;
                                emission_sourcegroup[SG_index] += sd.ER;
                                countrealsources++;

                                sd.TimeSeriesTemperature = GetTransientTimeSeriesIndex.GetIndex(Program.TS_TimeSerTempValues, "Temp@_", text);
                                sd.TimeSeriesVelocity    = GetTransientTimeSeriesIndex.GetIndex(Program.TS_TimeSerVelValues, "Vel@_", text);

                                if (text.Length > 17)         // deposition data available
                                {
                                    Dep.Dep_Start_Index = 11; // start index for portal sources
                                    if (text.Length > 20)
                                    {
                                        sd.T = Convert.ToSingle(text[19], ic);
                                        sd.V = Convert.ToSingle(text[20], ic);
                                    }
                                    Dep.SD         = sd;
                                    Dep.SourceData = TQ;
                                    Dep.Text       = text;
                                    if (Dep.Compute() == false)
                                    {
                                        throw new IOException();
                                    }
                                }
                                else // no depositon
                                {
                                    if (text.Length > 12) // DeltaT and ExitVel available
                                    {
                                        sd.T = Convert.ToSingle(text[11], ic);
                                        sd.V = Convert.ToSingle(text[12], ic);
                                    }
                                    TQ.Add(sd);
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                string err = "Error when reading file Portals.dat in line " + (countrealsources + 3).ToString() + " Execution stopped: press ESC to stop";
                Console.WriteLine(err);
                ProgramWriters.LogfileProblemreportWrite(err);

                if (Program.IOUTPUT <= 0 && Program.WaitForConsoleKey) // not for Soundplan or no keystroke
                {
                    while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape))
                    {
                        ;
                    }
                }

                Environment.Exit(0);
            }
            read.Close();
            read.Dispose();

            int counter = TQ.Count + 1;

            Program.TS_Count = TQ.Count - 1;

            // Copy Lists to global arrays
            Array.Resize(ref Program.TS_X1, counter);
            Array.Resize(ref Program.TS_Y1, counter);
            Array.Resize(ref Program.TS_X2, counter);
            Array.Resize(ref Program.TS_Y2, counter);
            Array.Resize(ref Program.TS_Z1, counter);
            Array.Resize(ref Program.TS_Z2, counter);
            Array.Resize(ref Program.TS_ER, counter);
            Array.Resize(ref Program.TS_SG, counter);
            Array.Resize(ref Program.TS_PartNumb, counter);
            Array.Resize(ref Program.TS_Mode, counter);
            Array.Resize(ref Program.TS_V_Dep, counter);
            Array.Resize(ref Program.TS_V_sed, counter);
            Array.Resize(ref Program.TS_ER_Dep, counter);
            Array.Resize(ref Program.TS_Absolute_Height, counter);
            Array.Resize(ref Program.TS_T, counter);
            Array.Resize(ref Program.TS_V, counter);
            Array.Resize(ref Program.TS_TimeSeriesTemperature, counter);
            Array.Resize(ref Program.TS_TimeSeriesVelocity, counter);

            for (int i = 1; i < TQ.Count; i++)
            {
                Program.TS_X1[i] = TQ[i].X1;
                Program.TS_Y1[i] = TQ[i].Y1;
                Program.TS_X2[i] = TQ[i].X2;
                Program.TS_Y2[i] = TQ[i].Y2;

                if (TQ[i].Z1 < 0 && TQ[i].Z2 < 0) // negative values = absolute heights
                {
                    Program.TS_Absolute_Height[i] = true;
                    if (Program.Topo != 1)
                    {
                        string err = "You are using absolute coordinates but flat terrain  - ESC = Exit";
                        Console.WriteLine(err);
                        ProgramWriters.LogfileProblemreportWrite(err);

                        if (Program.IOUTPUT <= 0 && Program.WaitForConsoleKey) // not for Soundplan or no keystroke
                        {
                            while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape))
                            {
                                ;
                            }
                        }
                        Environment.Exit(0);
                    }
                }
                else
                {
                    Program.TS_Absolute_Height[i] = false;
                }

                Program.TS_Z1[i]     = (float)Math.Abs(TQ[i].Z1);
                Program.TS_Z2[i]     = (float)Math.Abs(TQ[i].Z2);
                Program.TS_ER[i]     = TQ[i].ER;
                Program.TS_SG[i]     = (byte)TQ[i].SG;
                Program.TS_V_Dep[i]  = TQ[i].Vdep;
                Program.TS_V_sed[i]  = TQ[i].Vsed;
                Program.TS_Mode[i]   = TQ[i].Mode;
                Program.TS_ER_Dep[i] = (float)(TQ[i].ER_dep);
                Program.TS_T[i]      = TQ[i].T;
                Program.TS_V[i]      = TQ[i].V;
                Program.TS_TimeSeriesTemperature[i] = TQ[i].TimeSeriesTemperature;
                Program.TS_TimeSeriesVelocity[i]    = TQ[i].TimeSeriesVelocity;
            }

            string info = "Total number of tunnel portals: " + countrealsources.ToString();

            Console.WriteLine(info);
            ProgramWriters.LogfileGralCoreWrite(info);

            string unit = "[kg/h]: ";

            if (Program.Odour == true)
            {
                unit = "[MOU/h]: ";
            }

            info = "Total emission " + unit + (totalemission).ToString("0.000");
            Console.Write(info);
            ProgramWriters.LogfileGralCoreWrite(info);

            Console.Write(" (");
            for (int im = 0; im < Program.SourceGroups.Count; im++)
            {
                info = "  SG " + Program.SourceGroups[im] + unit + emission_sourcegroup[im].ToString("0.000");
                Console.Write(info);
                ProgramWriters.LogfileGralCoreWrite(info);
            }
            Console.WriteLine(" )");

            Program.TS_Area     = new float[Program.TS_Count + 1];
            Program.TS_Width    = new float[Program.TS_Count + 1];
            Program.TS_Height   = new float[Program.TS_Count + 1];
            Program.TS_cosalpha = new float[Program.TS_Count + 1];
            Program.TS_sinalpha = new float[Program.TS_Count + 1];

            TQ  = null;
            Dep = null;
        }