Пример #1
0
        public DataSerie1D Aggregate(int countStep)
        {
            DataSerie1D result_ds = null;

            if (countStep < 1)
            {
                return(null);
            }
            if (Equals(mData, null))
            {
                return(null);
            }
            if (Count < 1)
            {
                return(null);
            }

            result_ds = new DataSerie1D();
            int    count = Count;
            double summ  = 0;

            if (count <= countStep)
            {
                for (int i = 0; i < count; i++)
                {
                    summ += mData[i].X_Value;
                }
                result_ds.Add("1", summ);
            }
            else
            {
                summ = 0;
                int rest        = 0;
                int aggregCount = 1;

                for (int i = 0; i < count; i++)
                {
                    summ += mData[i].X_Value;

                    aggregCount = Math.DivRem((i + 1), countStep, out rest);

                    if (rest == 0)
                    {
                        result_ds.Add(aggregCount.ToString(), summ);
                        summ = 0;
                    }
                }

                summ        = 0;
                aggregCount = Math.DivRem(count, countStep, out rest);

                for (int i = (count - rest); i < count; i++)
                {
                    summ += mData[i].X_Value;
                }

                result_ds.Add((aggregCount + 1).ToString(), summ);
            }
            return(result_ds);
        }
Пример #2
0
        public DataSerie1D Read_DS1()
        {
            DataSerie1D ds1 = null;

            try
            {
                if (File.Exists(this.mFileName))
                {
                    ds1 = new DataSerie1D();

                    using (FileStream fs = File.Open(this.mFileName, FileMode.Open))
                    {
                        using (StreamReader sReader = new StreamReader(fs))
                        {
                            ds1.Name        = sReader.ReadLine().Replace(";", "");
                            ds1.Description = sReader.ReadLine().Replace(";", "");
                            string   title  = sReader.ReadLine();
                            string[] titles = title.Split(';');
                            if (titles.Count() == 2)
                            {
                                ds1.Title   = titles[0];
                                ds1.X_Title = titles[1];
                            }
                            double xx;
                            bool   tryResult = true;

                            while (sReader.EndOfStream == false)
                            {
                                title  = sReader.ReadLine();
                                titles = title.Split(';');

                                if (titles.Count() == 2)
                                {
                                    //xx = double.Parse(titles[1]);
                                    xx        = double.NaN;
                                    tryResult = double.TryParse(titles[1], out xx);
                                    if (tryResult)
                                    {
                                        ds1.Add(titles[0], xx);
                                    }
                                    else
                                    {
                                        ds1.Add("$Err$", Double.NaN);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(ds1);
        }
Пример #3
0
        public List <DataSerie1D> Read_DS1List()
        {
            List <DataSerie1D> ds1List = null;

            try
            {
                if (File.Exists(this.mFileName))
                {
                    ds1List = new List <DataSerie1D>();

                    using (FileStream fs = File.Open(this.mFileName, FileMode.Open))
                    {
                        using (StreamReader sReader = new StreamReader(fs))
                        {
                            string   header  = sReader.ReadLine();
                            string[] headers = header.Split(';');
                            //----------data
                            string   xLineValue;
                            string[] xValues;

                            double xValue = 0;

                            while (sReader.EndOfStream == false)
                            {
                                xLineValue = sReader.ReadLine();

                                xValues = xLineValue.Split(';');

                                if (xValues.Count() > 2)
                                {
                                    DataSerie1D ds1 = new DataSerie1D();
                                    ds1.Name        = xValues[0];
                                    ds1.Description = xValues[1];
                                    for (int j = 2; j < (xValues.Count()); j++)
                                    {
                                        xValue = double.Parse(xValues[j]);
                                        ds1.Add(headers[j], xValue);
                                    }
                                    ds1List.Add(ds1);
                                }
                            }

                            sReader.Close();
                            int ss = ds1List.Count();
                            header     = null;
                            headers    = null;
                            xLineValue = null;
                            xValues    = null;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(ds1List);
        }
Пример #4
0
        public DataSerie1D ConvertToDS1()
        {
            if (object.Equals(mData, null))
            {
                return(null);
            }
            DataSerie1D ds1 = new DataSerie1D();

            foreach (DataItemTD itm in this.Data)
            {
                ds1.Add(itm.Title, itm.List[0]);
            }
            return(ds1);
        }
Пример #5
0
        public DataSerie1D Read_DS1(string fileName)
        {
            DataSerie1D ds = new DataSerie1D();

            try
            {
                if (fileName == string.Empty)
                {
                    return(null);
                }

                if (File.Exists(fileName))
                {
                    FileStream   fs         = File.Open(fileName, FileMode.Open);
                    BinaryReader bnryReader = new BinaryReader(fs);
                    int          dCount     = 0;
                    ds.Name        = bnryReader.ReadString();
                    ds.Description = bnryReader.ReadString();
                    ds.X_Title     = bnryReader.ReadString();

                    dCount = bnryReader.ReadInt32();

                    if (dCount > 0)
                    {
                        double x, y;
                        string z;
                        for (int i = 0; i < dCount; i++)
                        {
                            z = bnryReader.ReadString();
                            x = bnryReader.ReadDouble();

                            ds.Add(z, x);
                        }
                    }
                    bnryReader.Close();
                    fs.Close();
                }
                else
                {
                    throw new FileNotFoundException("File not found", fileName);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(ds);
        }
Пример #6
0
        public static DataSerie1D Convert(double[] source)
        {
            if (Equals(source, null))
            {
                return(null);
            }
            DataSerie1D result = new DataSerie1D();
            int         iCount = source.GetLength(0);

            if (iCount > 0)
            {
                for (int i = 0; i < iCount; i++)
                {
                    result.Add(i.ToString(), source[i]);
                }
            }
            return(result);
        }
Пример #7
0
        public void ReadXML(string filepath)
        {
            try
            {
                XDocument xdoc        = XDocument.Load(filepath);
                var       prj         = xdoc.Root;
                string    version     = (string)prj.Attribute("Version");
                string    fileVersion = (string)prj.Attribute("FileVersion");
                this.Name        = (string)prj.Attribute("ProjectName");
                this.Description = (string)prj.Attribute("Description");
                this.CreateDate  = (DateTime)prj.Attribute("CreateDate");

                if (fileVersion == "1.0")
                {
                    this.Reservoir = new IOReservoir();
                    var resrvr = prj.Element("Reservoir");

                    this.Reservoir.Name        = (string)resrvr.Attribute("Name");
                    this.Reservoir.Description = (string)resrvr.Attribute("Description");
                    this.Reservoir.MinCapacity = (double)resrvr.Attribute("MinCapacity");
                    this.Reservoir.MaxCapacity = (double)resrvr.Attribute("MaxCapacity");
                    this.Reservoir.MinRelease  = (double)resrvr.Attribute("MinRelease");
                    this.Reservoir.MaxRelease  = (double)resrvr.Attribute("MaxRelease");

                    //-- Elevation_Area-------------------------------------------------------
                    DataSerie2D ds2   = new DataSerie2D();
                    var         xhs   = resrvr.Element("Curve_Elevation_Area");
                    int         count = (int)xhs.Attribute("Count");
                    if (count > 0)
                    {
                        ds2.Name        = (string)xhs.Attribute("Name");
                        ds2.Description = (string)xhs.Attribute("Description");
                        ds2.Title       = (string)xhs.Attribute("Title");
                        ds2.X_Title     = (string)xhs.Attribute("X_Title");
                        ds2.Y_Title     = (string)xhs.Attribute("Y_Title");

                        // Data :
                        var items = from dt in xhs.Elements()
                                    select new
                        {
                            T = (string)dt.Attribute("Title"),
                            x = (double)dt.Attribute("x"),
                            y = (double)dt.Attribute("y")
                        };
                        foreach (var dt in items)
                        {
                            ds2.Add(dt.T, dt.x, dt.y);
                        }
                    }
                    this.Reservoir.Elevation_Area = ds2;


                    //-- Curve_Elevation_Volume : -------------------------------------------------------
                    ds2 = new DataSerie2D();
                    var xvs = resrvr.Element("Curve_Elevation_Volume");
                    count = (int)xvs.Attribute("Count");
                    if (count > 0)
                    {
                        ds2.Name        = (string)xvs.Attribute("Name");
                        ds2.Description = (string)xvs.Attribute("Description");
                        ds2.Title       = (string)xvs.Attribute("Title");
                        ds2.X_Title     = (string)xvs.Attribute("X_Title");
                        ds2.Y_Title     = (string)xvs.Attribute("Y_Title");

                        // Data :
                        var items = from dt in xvs.Elements()
                                    select new
                        {
                            T = (string)dt.Attribute("Title"),
                            x = (double)dt.Attribute("x"),
                            y = (double)dt.Attribute("y")
                        };
                        foreach (var dt in items)
                        {
                            ds2.Add(dt.T, dt.x, dt.y);
                        }
                    }
                    this.Reservoir.Elevation_Volume = ds2;

                    //---------Evaporation :
                    ds2 = new DataSerie2D();
                    var xev = resrvr.Element("Evaporation");
                    count = (int)xev.Attribute("Count");
                    if (count > 0)
                    {
                        ds2.Name        = (string)xev.Attribute("Name");
                        ds2.Description = (string)xev.Attribute("Description");
                        ds2.Title       = (string)xev.Attribute("Title");
                        ds2.X_Title     = (string)xev.Attribute("X_Title");
                        ds2.Y_Title     = (string)xev.Attribute("Y_Title");

                        // Data :
                        var items = from dt in xev.Elements()
                                    select new
                        {
                            T = (string)dt.Attribute("Title"),
                            x = (double)dt.Attribute("x"),
                            y = (double)dt.Attribute("y")
                        };
                        foreach (var dt in items)
                        {
                            ds2.Add(dt.T, dt.x, dt.y);
                        }
                    }
                    this.Reservoir.Evaporation = ds2;

                    //---------Infiltration :
                    ds2 = new DataSerie2D();
                    var xinf = resrvr.Element("Infiltration");
                    count = (int)xinf.Attribute("Count");
                    if (count > 0)
                    {
                        ds2.Name        = (string)xinf.Attribute("Name");
                        ds2.Description = (string)xinf.Attribute("Description");
                        ds2.Title       = (string)xinf.Attribute("Title");
                        ds2.X_Title     = (string)xinf.Attribute("X_Title");
                        ds2.Y_Title     = (string)xinf.Attribute("Y_Title");

                        // Data :
                        var items = from dt in xinf.Elements()
                                    select new
                        {
                            T = (string)dt.Attribute("Title"),
                            x = (double)dt.Attribute("x"),
                            y = (double)dt.Attribute("y")
                        };
                        foreach (var dt in items)
                        {
                            ds2.Add(dt.T, dt.x, dt.y);
                        }
                    }
                    this.Reservoir.Infiltration = ds2;

                    //------------Inflow :
                    DataSerie1D ds1 = new DataSerie1D();
                    var         xq  = resrvr.Element("Inflow");
                    count = (int)xq.Attribute("Count");
                    if (count > 0)
                    {
                        ds1.Name        = (string)xq.Attribute("Name");
                        ds1.Description = (string)xq.Attribute("Description");
                        ds1.Title       = (string)xq.Attribute("Title");
                        ds1.X_Title     = (string)xq.Attribute("X_Title");

                        // Data :
                        var items = from dt in xq.Elements()
                                    select new
                        {
                            T = (string)dt.Attribute("Title"),
                            x = (double)dt.Attribute("x"),
                        };
                        foreach (var dt in items)
                        {
                            ds1.Add(dt.T, dt.x);
                        }
                    }
                    this.Reservoir.Inflow = ds1;

                    //-------------------------Downstream :

                    ds1 = new DataSerie1D();
                    var xd = resrvr.Element("Downstream");
                    count = (int)xd.Attribute("Count");
                    if (count > 0)
                    {
                        ds1.Name        = (string)xd.Attribute("Name");
                        ds1.Description = (string)xd.Attribute("Description");
                        ds1.Title       = (string)xd.Attribute("Title");
                        ds1.X_Title     = (string)xd.Attribute("X_Title");

                        // Data :
                        var items = from dt in xd.Elements()
                                    select new
                        {
                            T = (string)dt.Attribute("Title"),
                            x = (double)dt.Attribute("x"),
                        };
                        foreach (var dt in items)
                        {
                            ds1.Add(dt.T, dt.x);
                        }
                    }
                    this.Reservoir.Downstream = ds1;
                }
            }
            catch (Exception ex) { throw ex; }
            this.FileName = filepath;
        }