///-------------------------------------------------------------------------------------------------
        /// <summary> Grab parameter base data.</summary>
        ///
        /// <remarks> Quay, 3/1/2018.</remarks>
        ///
        /// <param name="SimResults"> The simulation results.</param>
        /// <param name="ParmType">   Type of the parameter.</param>
        /// <param name="index">      Zero-based index of the.</param>
        ///
        /// <returns> An int if parmtype and index are correct, else returns int.minvalue .</returns>
        ///-------------------------------------------------------------------------------------------------

        public int grabParmBaseData(AnnualSimulationResults SimResults, modelParamtype ParmType, int index)
        {
            // check if index is 0 or greater
            if (index >= 0)
            {
                // check if this is a provider parameter
                if ((ParmType == modelParamtype.mptInputBase) || (ParmType == modelParamtype.mptOutputBase))
                {
                    switch (ParmType)
                    {
                    case modelParamtype.mptInputBase:
                        if (index < SimResults.Inputs.BaseInput.Values.Length)
                        {
                            return(SimResults.Inputs.BaseInput.Values[index]);
                        }
                        break;

                    case modelParamtype.mptOutputBase:
                        if (index < SimResults.Outputs.BaseOutput.Values.Length)
                        {
                            return(SimResults.Outputs.BaseOutput.Values[index]);
                        }
                        break;

                    default:
                    {
                        break;
                    }
                    }
                }
            }
            return(int.MinValue);
        }
コード例 #2
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>   Initializes the data. </summary>
        /// <param name="Years">                The years. </param>
        /// <param name="StartYear">            the AnnualSimulationResults . </param>
        /// <param name="SimResults">           The simulation results. </param>
        /// <param name="IncludeAggregates">    true to include, false to exclude the aggregates. </param>
        ///-------------------------------------------------------------------------------------------------

        internal void initializeData(int Years, int StartYear, ref SimulationResults SimResults, bool IncludeAggregates)
        {
            if ((SimResults != null) && (Years == (SimResults.LastYear - SimResults.StartYear) + 1))
            // if not new then zero it out from last use  Added 5 22 12
            {
                // Only supporting Aggregates in Output right now
                ProviderIntArray OutBlank = new ProviderIntArray(0, IncludeAggregates);
                ProviderIntArray InBlank  = new ProviderIntArray(0, false);

                for (int yr = 0; yr < Years; yr++)
                {
                    AnnualSimulationResults TheASR = SimResults[yr];

                    int cnt = 0;
                    cnt = ParamManager.NumberOfParameters(modelParamtype.mptOutputBase);
                    for (int parmi = 0; parmi < cnt; parmi++)
                    {
                        TheASR.Outputs.BaseOutput[parmi]           = 0;
                        TheASR.Outputs.BaseOutputModelParam[parmi] = -1;
                    }
                    cnt = 0;
                    cnt = ParamManager.NumberOfParameters(modelParamtype.mptOutputProvider);
                    for (int parmi = 0; parmi < cnt; parmi++)
                    {
                        TheASR.Outputs.ProviderOutput[parmi]           = OutBlank;
                        TheASR.Outputs.ProviderOutputModelParam[parmi] = -1;
                    }
                    cnt = 0;
                    cnt = ParamManager.NumberOfParameters(modelParamtype.mptInputBase);
                    for (int parmi = 0; parmi < cnt; parmi++)
                    {
                        TheASR.Inputs.BaseInput[parmi]           = 0;
                        TheASR.Inputs.BaseInputModelParam[parmi] = -1;
                    }
                    cnt = 0;
                    cnt = ParamManager.NumberOfParameters(modelParamtype.mptInputProvider);
                    for (int parmi = 0; parmi < cnt; parmi++)
                    {
                        TheASR.Inputs.ProviderInput[parmi]           = InBlank;
                        TheASR.Inputs.ProviderInputModelParam[parmi] = -1;
                    }
                }
            }
            else
            {
                SimResults = new SimulationResults(Years, StartYear,
                                                   ParamManager.NumberOfParameters(modelParamtype.mptOutputBase),
                                                   ParamManager.NumberOfParameters(modelParamtype.mptOutputProvider),
                                                   ParamManager.NumberOfParameters(modelParamtype.mptInputBase),
                                                   ParamManager.NumberOfParameters(modelParamtype.mptInputProvider),
                                                   IncludeAggregates);
            }
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary> Constructor. </summary>
        /// <param name="AChart">     The chart. </param>
        /// <param name="ChartTitle"> The chart title. </param>
        ///-------------------------------------------------------------------------------------------------



        ///-------------------------------------------------------------------------------------------------
        /// <summary> Grab parameter provider data.</summary>
        ///
        /// <remarks> Quay, 3/1/2018.</remarks>
        ///
        /// <param name="SimResults"> The simulation results.</param>
        /// <param name="ParmType">   Type of the parameter.</param>
        /// <param name="index">      Zero-based index of the.</param>
        ///
        /// <returns> An int[] if parmtype an index are correct, else returns a null</returns>
        ///-------------------------------------------------------------------------------------------------

        public int[] grabParmProviderData(AnnualSimulationResults SimResults, modelParamtype ParmType, int index)
        {
            // check if index is 0 or greater
            if (index >= 0)
            {
                // check if this is a provider parameter
                if ((ParmType == modelParamtype.mptInputProvider) || (ParmType == modelParamtype.mptOutputProvider))
                {
                    switch (ParmType)
                    {
                    case modelParamtype.mptInputProvider:
                        if (index < SimResults.Inputs.ProviderInput.Length)
                        {
                            {
                                return(SimResults.Inputs.ProviderInput.Values[index].Values);
                            }
                        }
                        break;

                    case modelParamtype.mptOutputProvider:
                        if (index < SimResults.Outputs.ProviderOutput.Length)
                        {
                            {
                                return(SimResults.Outputs.ProviderOutput.Values[index].Values);
                            }
                        }
                        break;

                    default:
                    {
                        break;
                    }
                    }
                }
            }
            return(null);
        }
コード例 #4
0
ファイル: FileOutputs.cs プロジェクト: DavidARS/WaterSim_5
        /// <summary>
        ///
        /// </summary>
        /// <param name="SR"></param>
        /// <param name="SW"></param>
        /// <returns></returns>
        public bool WriteHeader(SimulationResults SR, myVariables mine, System.IO.StreamWriter SW)
        {
            bool result    = false;
            int  FirstYear = SR.StartYear;
            AnnualSimulationResults ASR = SR.ByYear(FirstYear);
            string BaseStr = "ID,BUILD,SCN_NAME,SIMYEAR";

            //FileOutputsBase fob = this.FOB;

            // now loop through base outputs and set those
            try
            {
                int index = 0;
                foreach (int emp in ASR.Outputs.BaseOutputModelParam)
                {
                    // check if this is one of the output fields
                    if (isOutPutParam(mine, emp))
                    {
                        ModelParameterClass MP = wsim.ParamManager.Model_Parameter(emp);

                        BaseStr += "," + MP.Fieldname;
                    }
                    index++;
                }
                // lopp through base inputs
                index = 0;
                foreach (int emp in ASR.Inputs.BaseInputModelParam)
                {
                    if (isOutPutParam(mine, emp))
                    {
                        ModelParameterClass MP = wsim.ParamManager.Model_Parameter(emp);

                        BaseStr += "," + MP.Fieldname;
                    }
                    index++;
                }
                BaseStr += ",PRVDCODE";
                // loop through provider outputs
                index = 0;
                foreach (int emp in ASR.Outputs.ProviderOutputModelParam)
                {
                    // check if for output
                    if (isOutPutParam(mine, emp))
                    {
                        ModelParameterClass MP = wsim.ParamManager.Model_Parameter(emp);

                        BaseStr += "," + MP.Fieldname;
                    }
                    index++;
                }
                // loop through provider inputs
                index = 0;
                foreach (int emp in ASR.Inputs.ProviderInputModelParam)
                {
                    // check if for output
                    if (isOutPutParam(mine, emp))
                    {
                        ModelParameterClass MP = wsim.ParamManager.Model_Parameter(emp);

                        BaseStr += "," + MP.Fieldname;
                    }
                    index++;
                }

                SW.WriteLine(BaseStr);
                result = true;
            }
            finally
            {
                SW.Flush();
            }
            return(result);
        }
コード例 #5
0
ファイル: FileOutputs.cs プロジェクト: DavidARS/WaterSim_5
        public bool WriteResults(SimulationResults SR, string ScenarioName, myVariables mine, System.IO.StreamWriter SW)
        {
            bool   result = false;
            string IDS    = "";
            string build  = wsim.ModelBuild;
            // get the start year
            int FirstYear = SR.StartYear;

            // loop through all years in SR
            for (int yeari = 0; yeari < SR.Length; yeari++)
            {
                // Set the calender year
                int ThisYear = FirstYear + yeari;
                if (ThisYear < 2060)
                {
                    // get results for this year
                    AnnualSimulationResults ASR = SR.ByYear(ThisYear);

                    // set the key, the scenario name and the year
                    string BaseStr = RecCount.ToString() + "," + '"' + build + '"' + "," + ScenarioName + ThisYear.ToString();
                    // now loop through base outputs and set those
                    int index = 0;
                    foreach (int emp in ASR.Outputs.BaseOutputModelParam)
                    {
                        // check if this is one of the output fields
                        if (isOutPutParam(mine, emp))
                        {
                            BaseStr += "," + ASR.Outputs.BaseOutput.Values[index].ToString();
                        }
                        index++;
                    }
                    // lopp through base inputs
                    index = 0;
                    foreach (int emp in ASR.Inputs.BaseInputModelParam)
                    {
                        if (isOutPutParam(mine, emp))
                        {
                            BaseStr += "," + ASR.Inputs.BaseInput.Values[index].ToString();
                        }
                        index++;
                    }
                    // OK, have all base stuff, now loop through providers
                    eProvider ep = eProvider.Regional;
                    //foreach (eProvider ep in ProviderClass.providersAll())
                    {
                        // Increment the rec count
                        RecCount++;
                        // set the base string
                        IDS = BaseStr + "," + '"' + ProviderClass.FieldName(ep) + '"';
                        // loop through provider outputs
                        index = 0;
                        foreach (int emp in ASR.Outputs.ProviderOutputModelParam)
                        {
                            // check if for output
                            if (isOutPutParam(mine, emp))
                            {
                                if ((ep < eProvider.Regional) || (ASR.Outputs.ProviderOutput[index].IncludesAggregates))
                                {
                                    IDS += "," + ASR.Outputs.ProviderOutput[index].Values[ProviderClass.index(ep, true)].ToString();
                                }
                                else
                                {
                                    IDS += "," + SpecialValues.MissingIntValue.ToString();
                                }
                            }
                            index++;
                        }
                        // loop through provider inputs
                        index = 0;
                        foreach (int emp in ASR.Inputs.ProviderInputModelParam)
                        {
                            // check if for output
                            if (isOutPutParam(mine, emp))
                            {
                                if ((ep < eProvider.Regional) || (ASR.Inputs.ProviderInput[index].IncludesAggregates))
                                {
                                    IDS += "," + ASR.Inputs.ProviderInput[index].Values[ProviderClass.index(ep, true)].ToString();
                                }
                                else
                                {
                                    IDS += "," + SpecialValues.MissingIntValue.ToString();
                                }
                            }
                            index++;
                        }
                        // ok write it out
                        SW.WriteLine(IDS);
                    } // provider
                }
            }         // year
            SW.Flush();
            result = true;
            return(result);
        }
コード例 #6
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>   Fetches a data. </summary>
        ///
        /// <param name="year">     The year. </param>
        /// <param name="TheASR">   [in,out] the AnnualSimulationResults </param>
        ///-------------------------------------------------------------------------------------------------

        internal void fetchData(int year, ref SimulationResults SimResults)
        {
            int datai = 0;

            int index = year - Sim_StartYear; // changed 7 26 11 _SimulationDB_Start_Year;

            if ((index >= 0) & (index < SimResults.Length))
            {
                int BaseOutputSize     = ParamManager.NumberOfParameters(modelParamtype.mptOutputBase);
                int ProviderOutputSize = ParamManager.NumberOfParameters(modelParamtype.mptOutputProvider);
                int BaseInputSize      = ParamManager.NumberOfParameters(modelParamtype.mptInputBase);
                int ProviderInputSize  = ParamManager.NumberOfParameters(modelParamtype.mptInputProvider);

                datai = 0;
                AnnualSimulationResults TheASR = new AnnualSimulationResults(BaseOutputSize, ProviderOutputSize, BaseInputSize, ProviderInputSize, FIncludeAggregates);

                try
                {
                    foreach (ModelParameterClass MP in ParamManager.BaseOutputs())
                    {
                        TheASR.Outputs.BaseOutput[datai]           = MP.Value;
                        TheASR.Outputs.BaseOutputModelParam[datai] = MP.ModelParam;
                        datai++;
                    }
                }
                catch (Exception ex)
                {
                    bool check = true;
                }

                datai = 0;
                foreach (ModelParameterClass MP in ParamManager.BaseInputs())
                {
                    TheASR.Inputs.BaseInput[datai]           = MP.Value;
                    TheASR.Inputs.BaseInputModelParam[datai] = MP.ModelParam;
                    datai++;
                }

                datai = 0;
                foreach (ModelParameterClass MP in ParamManager.ProviderOutputs())
                {
                    // OK this is a bit complicated becuase of Aggregates
                    if ((!TheASR.Outputs.AggregatesIncluded) || (MP.ProviderProperty.AggregateMode == eProviderAggregateMode.agNone))
                    {
                        TheASR.Outputs.ProviderOutput[datai] = MP.ProviderProperty.getvalues();
                    }
                    else
                    {
                        for (int i = 0; i < TheASR.Outputs.ProviderOutput[datai].Length; i++)
                        {
                            int tempVal = MP.ProviderProperty[i];
                            TheASR.Outputs.ProviderOutput[datai].Values[i] = tempVal;
                        }
                    }

                    TheASR.Outputs.ProviderOutputModelParam[datai] = MP.ModelParam;
                    datai++;
                }
                datai = 0;
                foreach (ModelParameterClass MP in ParamManager.ProviderInputs())
                {
                    // OK this is a bit complicated becuase of Aggregates
                    if ((!TheASR.Inputs.AggregatesIncluded) || (MP.ProviderProperty.AggregateMode == eProviderAggregateMode.agNone))
                    {
                        TheASR.Inputs.ProviderInput[datai] = MP.ProviderProperty.getvalues();
                    }
                    else
                    {
                        TheASR.Inputs.ProviderInput.Values[datai] = MP.ProviderProperty.getvalues();

                        //for (int i = 0; i < TheASR.Inputs.ProviderInput[datai].Length; i++)
                        //{
                        //    int tempVal = MP.ProviderProperty[i];
                        //    TheASR.Inputs.ProviderInput[datai].Values[i] = tempVal;
                        //}
                    }
                    //TheASR.Inputs.ProviderInput[datai] = MP.ProviderProperty.getvalues();
                    TheASR.Inputs.ProviderInputModelParam[datai] = MP.ModelParam;
                    datai++;
                }
                TheASR.year       = year;
                SimResults[index] = TheASR;
            }
        }