Exemplo n.º 1
0
        /// <summary>
        /// Parse the parameters and returns filled MultiRequestStructure
        /// </summary>
        /// <param name="args">A paramters to parse</param>
        /// <param name="regDelimiter">A delimiter in the latitude values (start:step:stop - ':' is a delimiter)</param>
        /// <returns></returns>
        public static MultipleRequestDescriptor Parse(string[] args, char regDelimiter = ':')
        {
            List <SpatialGrid> queries    = new List <SpatialGrid>();
            ClimateParameter   parameter  = ClimateParameter.FC_TEMPERATURE;
            Tuple <int, int>   days       = new Tuple <int, int>(GlobalConsts.DefaultValue, GlobalConsts.DefaultValue);
            Tuple <int, int>   hours      = new Tuple <int, int>(GlobalConsts.DefaultValue, GlobalConsts.DefaultValue);
            Tuple <int, int>   years      = Tuple.Create(GlobalConsts.StartYear, GlobalConsts.EndYear);
            FetchingTimeModes  activeMode = FetchingTimeModes.Single;
            int currentArgNum             = 0;
            int timeStep             = 1;
            int paramsEnteredCounter = 0;

            while (currentArgNum != args.Length)
            {
                switch (args[currentArgNum++].ToLower()) //  <---- moves the cursor!!!
                {
                case "/ty":
                    if (!int.TryParse(args[currentArgNum++], out timeStep))
                    {
                        throw new ArgumentException("Years step is not an integer in the yearly timeseries specification. Syntax is [/ty YearsStep]");
                    }
                    activeMode = FetchingTimeModes.TsYearly;
                    continue;

                case "/ts":
                    if (!int.TryParse(args[currentArgNum++], out timeStep))
                    {
                        throw new ArgumentException("Days step is not an integer in the seasonly timeseries specification. Syntax is [/ts DaysStep]");
                    }
                    activeMode = FetchingTimeModes.TsSeasonly;
                    continue;

                case "/th":
                    if (!int.TryParse(args[currentArgNum++], out timeStep))
                    {
                        throw new ArgumentException("Hourss step is not an integer in the hourly timeseries specification. Syntax is [/th HoursStep]");
                    }
                    activeMode = FetchingTimeModes.TsHourly;
                    continue;

                case "/years":
                    years = ParseYears(ref currentArgNum, args);
                    continue;

                case "/days":
                    days = ParseDays(ref currentArgNum, args);
                    continue;

                case "/hours":
                    hours = ParseHours(ref currentArgNum, args);
                    continue;

                default:
                    currentArgNum--;     // <---- false cursor moving, moving it back
                    break;
                }
                if (paramsEnteredCounter == 0)
                {
                    parameter = ParseParam(ref currentArgNum, args);
                    paramsEnteredCounter++;
                    continue;
                }
                if (paramsEnteredCounter == 1)
                {
                    queries.Add(ParseRegion(ref currentArgNum, args));
                    paramsEnteredCounter++;
                    continue;
                }
                queries.Add(ParseRegion(ref currentArgNum, args));
            }
            if (paramsEnteredCounter < 1)
            {
                throw new ArgumentException("Climate variable is not set.");
            }
            MultipleRequestDescriptor mrd = new MultipleRequestDescriptor(parameter, new TimeBounds()
            {
                MinDay = days.Item1, MaxDay = days.Item2, MinYear = years.Item1, MaxYear = years.Item2, MinHour = hours.Item1, MaxHour = hours.Item2
            }, activeMode);

            foreach (var q in queries)
            {
                mrd.AddRegion(q);
            }
            mrd.TimeStep = timeStep;
            return(mrd);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Parse the parameters and returns filled MultiRequestStructure
 /// </summary>
 /// <param name="args">A paramters to parse</param>
 /// <param name="regDelimiter">A delimiter in the latitude values (start:step:stop - ':' is a delimiter)</param>
 /// <returns></returns>
 public static MultipleRequestDescriptor Parse(string[] args,char regDelimiter=':')
 {
     List<SpatialGrid> queries = new List<SpatialGrid>();
     ClimateParameter parameter = ClimateParameter.FC_TEMPERATURE;
     Tuple<int, int> days = new Tuple<int, int>(GlobalConsts.DefaultValue, GlobalConsts.DefaultValue);
     Tuple<int, int> hours = new Tuple<int, int>(GlobalConsts.DefaultValue, GlobalConsts.DefaultValue);
     Tuple<int, int> years = Tuple.Create(GlobalConsts.StartYear, GlobalConsts.EndYear);
     FetchingTimeModes activeMode = FetchingTimeModes.Single;
     int currentArgNum = 0;
     int timeStep = 1;
     int paramsEnteredCounter = 0;
     while (currentArgNum != args.Length)
     {
         switch (args[currentArgNum++].ToLower()) //  <---- moves the cursor!!!
         {
             
             case "/ty":
                 if (!int.TryParse(args[currentArgNum++], out timeStep))
                     throw new ArgumentException("Years step is not an integer in the yearly timeseries specification. Syntax is [/ty YearsStep]");
                 activeMode = FetchingTimeModes.TsYearly;
                 continue;
             case "/ts":
                 if (!int.TryParse(args[currentArgNum++], out timeStep))
                     throw new ArgumentException("Days step is not an integer in the seasonly timeseries specification. Syntax is [/ts DaysStep]");
                 activeMode = FetchingTimeModes.TsSeasonly;
                 continue;
             case "/th":
                 if (!int.TryParse(args[currentArgNum++], out timeStep))
                     throw new ArgumentException("Hourss step is not an integer in the hourly timeseries specification. Syntax is [/th HoursStep]");
                 activeMode = FetchingTimeModes.TsHourly;
                 continue;
             case "/years":
                 years = ParseYears(ref currentArgNum, args);
                 continue;
             case "/days":
                 days = ParseDays(ref currentArgNum, args);
                 continue;
             case "/hours":
                 hours = ParseHours(ref currentArgNum, args);
                 continue;
             default:
                 currentArgNum--; // <---- false cursor moving, moving it back
                 break;
         }
         if (paramsEnteredCounter == 0)
         {
             parameter = ParseParam(ref currentArgNum, args);
             paramsEnteredCounter++;
             continue;
         }
         if (paramsEnteredCounter == 1)
         {
             queries.Add(ParseRegion(ref currentArgNum, args));
             paramsEnteredCounter++;
             continue;
         }
         queries.Add(ParseRegion(ref currentArgNum, args));
     }
     if (paramsEnteredCounter < 1)
         throw new ArgumentException("Climate variable is not set.");
     MultipleRequestDescriptor mrd = new MultipleRequestDescriptor(parameter, new TimeBounds() { MinDay = days.Item1, MaxDay = days.Item2, MinYear = years.Item1, MaxYear = years.Item2, MinHour = hours.Item1, MaxHour = hours.Item2 }, activeMode);
     foreach (var q in queries)
         mrd.AddRegion(q);
     mrd.TimeStep = timeStep;
     return mrd;
 }