Beispiel #1
0
        /// <summary>
        /// Creates modsim TimeSeries and sets Units and VariesByYear
        /// </summary>
        /// <param name="tstype"></param>
        /// <param name="n"></param>
        public static void CreateModsimTimeSeries(TimeSeriesType tstype, Node n, bool variesByYear, ModsimUnits units)
        {
            var ts = new Csu.Modsim.ModsimModel.TimeSeries(tstype);

            switch (tstype)
            {
            case TimeSeriesType.Demand:
                n.m.adaDemandsM = ts;
                break;

            case TimeSeriesType.NonStorage:
                n.m.adaInflowsM = ts;
                break;

            case TimeSeriesType.Targets:
                n.m.adaTargetsM = ts;
                break;

            case TimeSeriesType.Evaporation:
                n.m.adaEvaporationsM = ts;
                break;

            case TimeSeriesType.Forecast:
                n.m.adaForecastsM = ts;
                break;

            default:
                throw new Exception("Only NonStorage, Demand, Targets, Forecast, and Evaporation supported");
            }

            ts.VariesByYear = variesByYear;
            ts.MultiColumn  = !variesByYear;
            ts.units        = units;
        }
Beispiel #2
0
        private Csu.Modsim.ModsimModel.TimeSeries FindModsimTimeSeries(string modsimName)
        {
            _isOutput = false;
            Csu.Modsim.ModsimModel.TimeSeries ts = null;

            Csu.Modsim.ModsimModel.Node n = m_mi.FindNode(modsimName);

            if (n == null)
            {
                string msg = "the node '" + modsimName + "' does not exist in " + m_mi.fname;
                Console.WriteLine(msg);
                Logger.WriteLine(msg);
                this.Appearance.LegendText = msg;
                return(ts);
            }
            switch (timeSeriesName)
            {
            case "adaDemandsM":
                ts = n.m.adaDemandsM;
                break;

            case "adaEvaporationsM":
                ts           = n.m.adaEvaporationsM;
                _isReservoir = true;
                break;

            case "adaForecastsM":
                ts           = n.m.adaForecastsM;
                _isReservoir = true;
                break;

            case "adaGeneratingHrsM":
                ts           = n.m.adaGeneratingHrsM;
                _isReservoir = true;
                break;

            case "adaInfiltrationsM":
                ts = n.m.adaInfiltrationsM;
                break;

            case "adaInflowsM":
                ts = n.m.adaInflowsM;
                break;

            case "adaTargetsM":
                ts           = n.m.adaTargetsM;
                _isReservoir = true;
                break;

            default:
                string msg = "the timeSeriesName '" + timeSeriesName + "' is not implemented";
                Console.WriteLine(msg);
                Logger.WriteLine(msg);
                throw new NotImplementedException(msg);
            }
            return(ts);
        }
Beispiel #3
0
        /// <summary>
        /// Reads Modsim Input time series data
        /// </summary>
        private void ModsimInput(string modsimName, DateTime t1, DateTime t2 /*, string timeSeriesName*/)
        {
            try
            {
                if (modsimName.IndexOf(",") >= 0)
                {
                    Series   total = new Series();
                    string[] nodes = modsimName.Split(',');
                    for (int i = 0; i < nodes.Length; i++)
                    {
                        Csu.Modsim.ModsimModel.TimeSeries mts = FindModsimTimeSeries(nodes[i]);
                        DataTable mtbl = mts.GetTable();

                        var s = new Reclamation.TimeSeries.Series(mtbl, Units, TimeInterval);
                        s.ReadOnly = true;
                        s.HasFlags = false;

                        ModsimUtilities.FillModsimStyle(m_mi, s, m_mi.TimeStepManager.dataStartDate,
                                                        m_mi.TimeStepManager.dataEndDate);
                        //DataTable publicTable = CopyModsimDataTableConvertingIntToDouble(rawModsimTable);
                        if (i == 0)
                        {
                            total = s;
                        }
                        else
                        {
                            if (total.Count != s.Count)
                            {
                                string msg = "the node '" + nodes[i] + "' is of different length than " + nodes[i - 1] + " cannot add";
                                Console.WriteLine(msg);
                                Logger.WriteLine(msg);
                                this.Appearance.LegendText = msg;
                                throw new System.DataMisalignedException(msg);
                            }
                            total = total + s;
                        }
                    }
                    // TO-DO: Use Pisces t1 & t2
                    //int timeStartIndex = total.IndexOf(t1);
                    //int timeEndIndex = total.IndexOf(t2)+1;
                    //int modelEndIndex = total.IndexOf(m_mi.TimeStepManager.dataEndDate);
                    //for (int i = 0; i < timeStartIndex; i++)
                    //{
                    //    total.RemoveAt(i);
                    //}
                    //for (int i = timeEndIndex; i <= modelEndIndex; i++)
                    //{
                    //    total.RemoveAt(i);
                    //}
                    InitTimeSeries(total.Table, Units, TimeInterval, true);
                }

                else
                {
                    Csu.Modsim.ModsimModel.TimeSeries ts = FindModsimTimeSeries(modsimName);

                    if (ts != null)
                    {
                        _modsimSeries = ts;
                        // Name = timeSeriesName;
                        // SiteName = modsimName;
                        //CheckVariesByYear();
                        DataTable rawModsimTable = ts.GetTable();
                        var       s = new Reclamation.TimeSeries.Series(rawModsimTable, Units, TimeInterval);
                        s.HasFlags = false;
                        s.ReadOnly = true;
                        ModsimUtilities.FillModsimStyle(m_mi, s, m_mi.TimeStepManager.dataStartDate,
                                                        m_mi.TimeStepManager.dataEndDate);
                        //DataTable publicTable = CopyModsimDataTableConvertingIntToDouble(rawModsimTable);

                        // TO-DO: Use Pisces t1 & t2
                        //int timeStartIndex = s.LookupIndex(t1);
                        //int timeEndIndex = s.LookupIndex(t2,false) + 1;
                        //var a = m_mi.TimeStepManager.Date2Index(m_mi.TimeStepManager.dataEndDate,"TypeIndex????");
                        //int modelEndIndex = s.LookupIndex(m_mi.TimeStepManager.endingDate);
                        //for (int i = 0; i < timeStartIndex; i++)
                        //{
                        //    s.RemoveAt(i);
                        //}
                        //for (int i = timeEndIndex; i <= modelEndIndex; i++)
                        //{
                        //    s.RemoveAt(i);
                        //}
                        InitTimeSeries(s.Table, Units, TimeInterval, true);
                    }
                }

                ApplyDisplayScaling();
                // publicTable.RowChanged += new DataRowChangeEventHandler(tbl_RowChanged);
                this.Table.Columns[1].ColumnName = modsimName + " " + timeSeriesName;
                Appearance = new Reclamation.TimeSeries.TimeSeriesAppearance();
            }
            catch (Exception ex)
            {
                string msg = "Error reading xy file data " + Name + " " + m_mi.fname + "\n" + ex.Message + "\n"
                             + ex.StackTrace;
                throw new Exception(msg);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Reads Modsim Input time series data
        /// </summary>
        private void ModsimInput(string modsimName, DateTime t1, DateTime t2/*, string timeSeriesName*/)
        {
            try
            {
                if (modsimName.IndexOf(",") >= 0)
                {
                    Series total = new Series();
                    string[] nodes = modsimName.Split(',');
                    for (int i = 0; i < nodes.Length; i++)
                    {
                        Csu.Modsim.ModsimModel.TimeSeries mts = FindModsimTimeSeries(nodes[i]);
                        DataTable mtbl = mts.GetTable();

                        var s = new Reclamation.TimeSeries.Series(mtbl, Units, TimeInterval);
                        s.ReadOnly = true;
                        s.HasFlags = false;

                        ModsimUtilities.FillModsimStyle(m_mi, s, m_mi.TimeStepManager.dataStartDate,
                                                        m_mi.TimeStepManager.dataEndDate);
                        //DataTable publicTable = CopyModsimDataTableConvertingIntToDouble(rawModsimTable);
                        if (i == 0)
                        {
                            total = s;
                        }
                        else
                        {
                            if (total.Count != s.Count)
                            {
                                string msg = "the node '" + nodes[i] + "' is of different length than " + nodes[i-1]+ " cannot add";
                                Console.WriteLine(msg);
                                Logger.WriteLine(msg);
                                this.Appearance.LegendText = msg;
                                throw new System.DataMisalignedException(msg);
                            }
                            total = total + s;
                        }

                    }
                    // TO-DO: Use Pisces t1 & t2
                    //int timeStartIndex = total.IndexOf(t1);
                    //int timeEndIndex = total.IndexOf(t2)+1;
                    //int modelEndIndex = total.IndexOf(m_mi.TimeStepManager.dataEndDate);
                    //for (int i = 0; i < timeStartIndex; i++)
                    //{
                    //    total.RemoveAt(i);
                    //}
                    //for (int i = timeEndIndex; i <= modelEndIndex; i++)
                    //{
                    //    total.RemoveAt(i);
                    //}
                    InitTimeSeries(total.Table, Units, TimeInterval, true);
                }

                else
                {
                    Csu.Modsim.ModsimModel.TimeSeries ts = FindModsimTimeSeries(modsimName);

                    if (ts != null)
                    {
                        _modsimSeries = ts;
                       // Name = timeSeriesName;
                       // SiteName = modsimName;
                        //CheckVariesByYear();
                        DataTable rawModsimTable = ts.GetTable();
                        var s = new Reclamation.TimeSeries.Series(rawModsimTable, Units, TimeInterval);
                        s.HasFlags = false;
                        s.ReadOnly = true;
                        ModsimUtilities.FillModsimStyle(m_mi, s, m_mi.TimeStepManager.dataStartDate,
                                                        m_mi.TimeStepManager.dataEndDate);
                        //DataTable publicTable = CopyModsimDataTableConvertingIntToDouble(rawModsimTable);

                        // TO-DO: Use Pisces t1 & t2
                        //int timeStartIndex = s.LookupIndex(t1);
                        //int timeEndIndex = s.LookupIndex(t2,false) + 1;
                        //var a = m_mi.TimeStepManager.Date2Index(m_mi.TimeStepManager.dataEndDate,"TypeIndex????");
                        //int modelEndIndex = s.LookupIndex(m_mi.TimeStepManager.endingDate);
                        //for (int i = 0; i < timeStartIndex; i++)
                        //{
                        //    s.RemoveAt(i);
                        //}
                        //for (int i = timeEndIndex; i <= modelEndIndex; i++)
                        //{
                        //    s.RemoveAt(i);
                        //}
                        InitTimeSeries(s.Table, Units, TimeInterval,true);
                    }
                }

                ApplyDisplayScaling();
                // publicTable.RowChanged += new DataRowChangeEventHandler(tbl_RowChanged);
                this.Table.Columns[1].ColumnName = modsimName + " " + timeSeriesName;
                Appearance = new Reclamation.TimeSeries.TimeSeriesAppearance();
            }
            catch (Exception ex)
            {
                string msg = "Error reading xy file data " + Name + " " + m_mi.fname + "\n" + ex.Message + "\n"
                + ex.StackTrace;
                throw new Exception(msg);
            }
        }