Exemplo n.º 1
0
        private ForecastTerm CreateTerm(TextFile tf, int idx)
        {
            var s = tf[idx].Split(',')[1].Trim();


            ForecastTerm rval = null;

            if (s == "Antecedent Runoff")
            {
                rval = new AntecedentRunoffForecastTerm();
            }
            else if (s == "Precipitation")
            {
                rval = new PrecipitationForecastTerm();
            }
            else if (s == "Snow")
            {
                rval = new SnowForecastTerm();
            }
            else if (s == "Runoff")
            {
                rval = new RunoffForecastTerm();
            }
            else
            {
                throw new NotImplementedException();
            }


            rval.Number = Convert.ToInt32(tf[idx].Split(',')[0].Substring(1, 1));// X1, Y1, X2...
            return(rval);
        }
Exemplo n.º 2
0
        private void ReadFromFile(string filename)
        {
            var tf = new TextFile(filename);

            Name      = ReadStringToken(tf, "Name");
            StartYear = Convert.ToInt32(ReadStringToken(tf, "StartYear"));
            EndYear   = Convert.ToInt32(ReadStringToken(tf, "EndYear"));
            this.aveargeFlowStation = ReadStringToken(tf, "AverageRunoff");

            this.coefficients = ReadCoefficients(tf);


            string pattern = @"(X|Y)[0-9]{1}[A-Za-z]?\s*,";
            int    idx     = tf.IndexOfRegex(pattern);

            while (idx > 0)
            {
                var term = CreateTerm(tf, idx);

                term.MonthNames = ReadDateRange(tf, idx);
                var isYterm = tf[idx].IndexOf("Y") == 0;
                if (isYterm)
                {
                    YTerm = (RunoffForecastTerm)term;
                }
                else
                {
                    XTerms.Add(term);
                }

                idx++;
                while (idx < tf.Length && !Regex.IsMatch(tf[idx], pattern))
                {
                    if (tf[idx].Length > 0 && tf[idx].IndexOf("#") == 0 || tf[idx].IndexOf("\"#") == 0)
                    {// comment line
                        idx++;
                        continue;
                    }
                    var tokens = CsvFile.ParseCSV(tf[idx]);
                    if (tokens.Length <= 0)
                    {
                        break;
                    }
                    if (tokens[0].Trim() == "")
                    {
                        break;
                    }

                    term.siteNames.Add(tokens[0]);
                    // remove any extra space between cbtt and pcode
                    var tmp = TextFile.Split(tokens[1].Trim());
                    if (tmp.Length != 2)
                    {// might be an equation...
                        term.cbttPodes.Add(tokens[1].Trim());
                    }
                    else
                    {
                        term.cbttPodes.Add(tmp[0].Trim().ToUpper() + " " + tmp[1].Trim().ToUpper());
                    }
                    term.siteWeights.Add(Convert.ToDouble(tokens[2]));
                    if (isYterm)
                    {// y-term should not be weighted... put in 1's
                        double[] w = Array.ConvertAll(term.MonthNames.ToArray(), s => 1.0);
                        term.MonthlyWeights.Clear();
                        term.MonthlyWeights.AddRange(w);
                    }
                    else
                    {
                        term.MonthlyWeights = ReadDoubles(tokens, 3, term.MonthNames.Count);
                    }
                    idx++;
                }

                if (idx >= tf.Length)
                {
                    break;
                }
                idx = tf.IndexOfRegex(pattern, idx);
            }
        }