Exemplo n.º 1
0
        /// <summary>
        /// Does simple factor math on all or selected time steps and items in a dfs-file.
        /// </summary>
        /// <param name="OperationData"></param>
        public static void FactorMath(XElement OperationData)
        {
            DFS3.MaxEntriesInBuffer = 1;
            DFS2.MaxEntriesInBuffer = 1;

            string File1 = OperationData.Element("DFSFileName").Value;

            //DFSOutputFileName is optional. If it exists the input file is copied to this filename
            var outfile = OperationData.Element("DFSOutputFileName");

            if (outfile != null && outfile.Value != "")
            {
                if (File1.ToLower() != outfile.Value.ToLower())
                {
                    File.Copy(File1, outfile.Value, true);
                }
                File1 = OperationData.Element("DFSOutputFileName").Value;
            }

            DFSBase dfs = DfsFileFactory.OpenFile(File1);

            int[] Items     = ParseString(OperationData.Element("Items").Value, 1, dfs.Items.Count());
            int[] TimeSteps = ParseString(OperationData.Element("TimeSteps").Value, 0, dfs.NumberOfTimeSteps - 1);

            string Operator = OperationData.Element("MathOperation").Value;
            double Factor   = double.Parse(OperationData.Element("Factor").Value);

            foreach (int j in TimeSteps)
            {
                foreach (int i in Items)
                {
                    switch (Operator)
                    {
                    case "+":
                        dfs.AddToItemTimeStep(j, i, Factor);
                        break;

                    case "-":
                        dfs.AddToItemTimeStep(j, i, -Factor);
                        break;

                    case "*":
                        dfs.MultiplyItemTimeStep(j, i, Factor);
                        break;

                    case "/":
                        dfs.MultiplyItemTimeStep(j, i, 1.0 / Factor);
                        break;

                    default:
                        break;
                    }
                }
            }
            dfs.Dispose();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Does simple factor math on all time steps and of selected items in a dfs-file.
        /// A different factor can be used for each month
        /// </summary>
        /// <param name="OperationData"></param>
        public static void MonthlyMath(XElement OperationData)
        {
            DFS3.MaxEntriesInBuffer = 1;
            DFS2.MaxEntriesInBuffer = 1;

            string File1 = OperationData.Element("DFSFileName").Value;

            string Operator = OperationData.Element("MathOperation").Value;

            string[] FactorStrings = OperationData.Element("MonthlyValues").Value.Split(new string[] { ",", ";" }, StringSplitOptions.RemoveEmptyEntries);

            var outfile = OperationData.Element("DFSOutputFileName");

            if (outfile != null && outfile.Value != "")
            {
                if (File1.ToLower() != outfile.Value.ToLower())
                {
                    File.Copy(File1, outfile.Value, true);
                }
                File1 = OperationData.Element("DFSOutputFileName").Value;
            }

            DFSBase dfs = DfsFileFactory.OpenFile(File1);

            int[] Items     = ParseString(OperationData.Element("Items").Value, 1, dfs.Items.Count());
            int[] TimeSteps = ParseString(OperationData.Element("TimeSteps").Value, 0, dfs.NumberOfTimeSteps - 1);

            double[] Factors = new double[12];
            for (int i = 0; i < 12; i++)
            {
                Factors[i] = double.Parse(FactorStrings[i]);
            }

            foreach (var j in TimeSteps)
            {
                double Factor = Factors[dfs.TimeSteps[j].Month - 1];
                foreach (int i in Items)
                {
                    switch (Operator)
                    {
                    case "+":
                        dfs.AddToItemTimeStep(j, i, Factor);
                        break;

                    case "-":
                        dfs.AddToItemTimeStep(j, i, -Factor);
                        break;

                    case "*":
                        dfs.MultiplyItemTimeStep(j, i, Factor);
                        break;

                    case "/":
                        dfs.MultiplyItemTimeStep(j, i, 1.0 / Factor);
                        break;

                    default:
                        break;
                    }
                }
            }
            dfs.Dispose();
        }