public static void FillDataSetWithRequest(DataSet ds, ClimateParameter parameter, double[] latmin, double[] latmax, double[] lonmin, double[] lonmax, int[] starthour, int[] stophour, int[] startday, int[] stopday, int[] startyear, int[] stopyear, FetchingOptions options)
        {
            ds.IsAutocommitEnabled = false;

            ds.Metadata[Namings.metadataNameParameter] = Namings.GetParameterName(parameter);
            ds.Metadata[Namings.metadataNameCoverage] = Namings.GetCoverageName(parameter);
            ds.Metadata[Namings.metadataNameProvenanceHint] = options.FetchClimateProvenanceControlStr;

            if (!ds.Variables.Contains(Namings.VarNameLatMax))
                ds.AddVariable<double>(Namings.VarNameLatMax, Namings.dimNameCells);
            if (!ds.Variables.Contains(Namings.VarNameLatMin))
                ds.AddVariable<double>(Namings.VarNameLatMin, Namings.dimNameCells);
            if (!ds.Variables.Contains(Namings.VarNameLonMax))
                ds.AddVariable<double>(Namings.VarNameLonMax, Namings.dimNameCells);
            if (!ds.Variables.Contains(Namings.VarNameLonMin))
                ds.AddVariable<double>(Namings.VarNameLonMin, Namings.dimNameCells);
            if (!ds.Variables.Contains(Namings.VarNameDayMax))
                ds.AddVariable<int>(Namings.VarNameDayMax, Namings.dimNameCells);
            if (!ds.Variables.Contains(Namings.VarNameDayMin))
                ds.AddVariable<int>(Namings.VarNameDayMin, Namings.dimNameCells);
            if (!ds.Variables.Contains(Namings.VarNameHourMax))
                ds.AddVariable<int>(Namings.VarNameHourMax, Namings.dimNameCells);
            if (!ds.Variables.Contains(Namings.VarNameHourMin))
                ds.AddVariable<int>(Namings.VarNameHourMin, Namings.dimNameCells);
            if (!ds.Variables.Contains(Namings.VarNameYearMax))
                ds.AddVariable<int>(Namings.VarNameYearMax, Namings.dimNameCells);
            if (!ds.Variables.Contains(Namings.VarNameYearMin))
                ds.AddVariable<int>(Namings.VarNameYearMin, Namings.dimNameCells);

            ds.Variables[Namings.VarNameDayMax].Append(stopday);
            ds.Variables[Namings.VarNameDayMin].Append(startday);
            ds.Variables[Namings.VarNameHourMax].Append(stophour);
            ds.Variables[Namings.VarNameHourMin].Append(starthour);
            ds.Variables[Namings.VarNameYearMax].Append(stopyear);
            ds.Variables[Namings.VarNameYearMin].Append(startyear);
            ds.Variables[Namings.VarNameLonMax].Append(lonmax);
            ds.Variables[Namings.VarNameLonMin].Append(lonmin);
            ds.Variables[Namings.VarNameLatMax].Append(latmax);
            ds.Variables[Namings.VarNameLatMin].Append(latmin);

            ds.Commit();
        }
        public FetchClimateGridResponce FetchClimateGrid(ClimateParameter parameter, double latmin, double latmax, double lonmin, double lonmax, int hourmin, int hourmax, int daymin, int daymax, int yearmin, int yearmax, double dlat, double dlon, FetchingOptions options)
        {
            int nlat = (int)Math.Round((latmax - latmin) / dlat);
            int nlon = (int)Math.Round((lonmax - lonmin) / dlon);
            double[] latsGrid = new double[nlat + 1];
            double[] lonsGrid = new double[nlon + 1];
            for (int i = 0; i < latsGrid.Length; i++)
                latsGrid[i] = latmin + i * dlat;
            for (int i = 0; i < lonsGrid.Length; i++)
                lonsGrid[i] = lonmin + i * dlon;
            int[] hourmins = new int[nlat * nlon];
            int[] hourmaxs = new int[nlat * nlon];
            int[] daymins = new int[nlat * nlon];
            int[] daymaxs = new int[nlat * nlon];
            int[] yearmins = new int[nlat * nlon];
            int[] yearmaxs = new int[nlat * nlon];
            double[] latmins = new double[nlat * nlon];
            double[] latmaxs = new double[nlat * nlon];
            double[] lonmins = new double[nlat * nlon];
            double[] lonmaxs = new double[nlat * nlon];
            int rowIndex, colIndex;
            for (int i = 0; i < nlat * nlon; i++)
            {
                rowIndex = i / nlon;
                colIndex = i % nlon;

                lonmins[i] = lonsGrid[colIndex];
                lonmaxs[i] = lonsGrid[colIndex + 1];
                latmins[i] = latsGrid[rowIndex];
                latmaxs[i] = latsGrid[rowIndex + 1];

                hourmins[i] = hourmin;
                hourmaxs[i] = hourmax;
                daymins[i] = daymin;
                daymaxs[i] = daymax;
                yearmins[i] = yearmin;
                yearmaxs[i] = yearmax;
            }

            var resB = FetchClimate(parameter, latmins, latmaxs, lonmins, lonmaxs, hourmins, hourmaxs, daymins, daymaxs, yearmins, yearmaxs, options, ResearchVariationType.Spatial);

            ClimateParameterValue[] result = resB.Values;
            ClimateParameterValue[,] result2D = new ClimateParameterValue[nlat, nlon];
            for (int i = 0; i < nlat * nlon; i++)
            {
                rowIndex = i / nlon;
                colIndex = i % nlon;
                result2D[rowIndex, colIndex] = result[i];
            }
            FetchClimateGridResponce res = new FetchClimateGridResponce();
            res.Values = result2D;
            res.ServiceVersion = resB.ServiceVersion;
            return res;
        }
        private FetchClimateBatchResponce FetchClimateTimeSeries(ClimateParameter p, double latmin, double latmax, double lonmin, double lonmax, int hourmin, int hourmax, int daymin, int daymax, int yearmin, int yearmax, int divider, IntervalToSplit intervalToSplit, FetchingOptions options)
        {
            int n;
            if (hourmax == GlobalConsts.DefaultValue)
                hourmax = 24;
            if (hourmin == GlobalConsts.DefaultValue)
                hourmin = 0;
            bool isReplaceDayMaxWithDefVal = (yearmax!=yearmin && (daymax==GlobalConsts.DefaultValue || daymax==365));            
            if (daymin == GlobalConsts.DefaultValue)
                daymin = 1;
            int effDayMax = daymax;
            if (effDayMax == GlobalConsts.DefaultValue)
                effDayMax = (yearmin == yearmax) ? (DateTime.IsLeapYear(yearmin) ? 366 : 365) : 365;
            ResearchVariationType rvt = ResearchVariationType.Auto;
            switch (intervalToSplit)
            {
                case IntervalToSplit.Years: n = (int)Math.Ceiling((yearmax - yearmin + 1) / (double)divider); rvt = ResearchVariationType.Yearly; break;
                case IntervalToSplit.Days: n = (int)Math.Ceiling((effDayMax - daymin + 1) / (double)divider); rvt = ResearchVariationType.Seasonly; break;
                case IntervalToSplit.Hours: n = (int)Math.Ceiling((hourmax - hourmin + 1) / (double)divider); rvt = ResearchVariationType.Hourly; break;
                default: throw new NotImplementedException();
            }
            double[] latmaxs = new double[n];
            double[] latmins = new double[n];
            double[] lonmaxs = new double[n];
            double[] lonmins = new double[n];
            int[] hourmins = new int[n];
            int[] hourmaxs = new int[n];
            int[] daymins = new int[n];
            int[] daymaxs = new int[n];
            int[] yearmins = new int[n];
            int[] yearmaxs = new int[n];

            int yi = (intervalToSplit == IntervalToSplit.Years) ? 1 : 0;
            int di = (intervalToSplit == IntervalToSplit.Days) ? 1 : 0;
            int hi = (intervalToSplit == IntervalToSplit.Hours) ? 1 : 0;

            for (int i = 0; i < n; i++)
            {
                latmaxs[i] = latmax;
                latmins[i] = latmin;
                lonmaxs[i] = lonmax;
                lonmins[i] = lonmin;
                hourmins[i] = Math.Min((hi==0)?hourmin:(hourmin + hi * i * divider),24);
                hourmaxs[i] = Math.Min((hi == 0) ? hourmax : (hourmin + hi * ((i + 1) * divider-1)), 24);
                yearmins[i] = (yi == 0) ? yearmin : (yearmin + yi * i * divider);
                yearmaxs[i] = (yi == 0) ? yearmax:(yearmin + yi * ((i + 1) * divider-1));
                daymins[i] = Math.Min((di==0)?daymin:(daymin + di *(i * divider)),(yearmins[i]==yearmaxs[i] && DateTime.IsLeapYear(yearmins[i]))?366:365);
                if (isReplaceDayMaxWithDefVal && intervalToSplit!=IntervalToSplit.Days)                                    
                    daymaxs[i] = GlobalConsts.DefaultValue;
                else
                    daymaxs[i] = Math.Min((di == 0) ? daymax : (daymin + di * ((i + 1) * divider - 1)), (yearmins[i] == yearmaxs[i] && DateTime.IsLeapYear(yearmins[i])) ? 366 : 365);
                
            }
            return FetchClimate(p, latmins, latmaxs, lonmins, lonmaxs, hourmins, hourmaxs, daymins, daymaxs, yearmins, yearmaxs, options,rvt);
        }
 public FetchClimateBatchResponce FetchClimateHourly(ClimateParameter p, double latmin, double latmax, double lonmin, double lonmax, int hourmin, int hourmax, int daymin, int daymax, int yearmin, int yearmax, int dhour, FetchingOptions options)
 {
     AssertFcParameters(latmin, latmax, lonmin, lonmax, hourmin, hourmax, daymin, daymax, yearmin, yearmax);
     return FetchClimateTimeSeries(p, latmin, latmax, lonmin, lonmax, hourmin, hourmax, daymin, daymax, yearmin, yearmax, dhour, IntervalToSplit.Hours, options);
 }
        public FetchClimateBatchResponce FetchClimate(ClimateParameter parameter, double[] latmin, double[] latmax, double[] lonmin, double[] lonmax, int[] starthour, int[] stophour, int[] startday, int[] stopday, int[] startyear, int[] stopyear, FetchingOptions options, ResearchVariationType variationType)
        {
            if (startday == null)
                startday = Enumerable.Repeat(GlobalConsts.DefaultValue, latmin.Length).ToArray();
            if (stopday == null)
                stopday = Enumerable.Repeat(GlobalConsts.DefaultValue, latmin.Length).ToArray();
            if (starthour == null)
                starthour = Enumerable.Repeat(GlobalConsts.DefaultValue, latmin.Length).ToArray();
            if (stophour == null)
                stophour = Enumerable.Repeat(GlobalConsts.DefaultValue, latmin.Length).ToArray();
            if (startyear == null)
                startyear = Enumerable.Repeat(GlobalConsts.StartYear, latmin.Length).ToArray();
            if (stopyear == null)
                stopyear = Enumerable.Repeat(GlobalConsts.EndYear, latmin.Length).ToArray();

            for (int i = 0; i < latmin.Length; i++)
                AssertFcParameters(latmin[i], latmax[i], lonmin[i], lonmax[i], starthour[i], stophour[i], startday[i], stopday[i], startyear[i], stopyear[i]);
            
            using (var requestDs = DataSet.Open("msds:memory"))
            {
                FetchClimateRequestBuilder.FillDataSetWithRequest(requestDs, parameter, latmin, latmax, lonmin, lonmax, starthour, stophour, startday, stopday, startyear, stopyear, options);
                requestDs.Metadata[Namings.metadataNameVariationType]=variationType.ToString();
                requestDs.Commit();
                using (var result = ServerProcess(requestDs))
                {
                    return FetchClimateRequestBuilder.BuildBatchResult(result);
                }
            }
        }
 public FetchClimateSingleResponce FetchClimate(ClimateParameter parameter, double latmin, double latmax, double lonmin, double lonmax, int starthour, int stophour, int startday, int stopday, int startyear, int stopyear, FetchingOptions options)
 {
     AssertFcParameters(latmin, latmax, lonmin, lonmax, starthour, stophour, startday, stopday, startyear, stopyear);
     using (var requestDs = DataSet.Open("msds:memory"))
     {
         FetchClimateRequestBuilder.FillDataSetWithRequest(requestDs, parameter, latmin, latmax, lonmin, lonmax, starthour, stophour, startday, stopday, startyear, stopyear, options);
         using (var result = ServerProcess(requestDs))
         {
             return FetchClimateRequestBuilder.BuildSingleCellResult(result);
         }
     }
 }
Beispiel #7
0
        public static void FillDataSetWithRequest(DataSet ds, ClimateParameter parameter, double[] latmin, double[] latmax, double[] lonmin, double[] lonmax, int[] starthour, int[] stophour, int[] startday, int[] stopday, int[] startyear, int[] stopyear, FetchingOptions options)
        {
            ds.IsAutocommitEnabled = false;

            ds.Metadata[Namings.metadataNameParameter]      = Namings.GetParameterName(parameter);
            ds.Metadata[Namings.metadataNameCoverage]       = Namings.GetCoverageName(parameter);
            ds.Metadata[Namings.metadataNameProvenanceHint] = options.FetchClimateProvenanceControlStr;

            if (!ds.Variables.Contains(Namings.VarNameLatMax))
            {
                ds.AddVariable <double>(Namings.VarNameLatMax, Namings.dimNameCells);
            }
            if (!ds.Variables.Contains(Namings.VarNameLatMin))
            {
                ds.AddVariable <double>(Namings.VarNameLatMin, Namings.dimNameCells);
            }
            if (!ds.Variables.Contains(Namings.VarNameLonMax))
            {
                ds.AddVariable <double>(Namings.VarNameLonMax, Namings.dimNameCells);
            }
            if (!ds.Variables.Contains(Namings.VarNameLonMin))
            {
                ds.AddVariable <double>(Namings.VarNameLonMin, Namings.dimNameCells);
            }
            if (!ds.Variables.Contains(Namings.VarNameDayMax))
            {
                ds.AddVariable <int>(Namings.VarNameDayMax, Namings.dimNameCells);
            }
            if (!ds.Variables.Contains(Namings.VarNameDayMin))
            {
                ds.AddVariable <int>(Namings.VarNameDayMin, Namings.dimNameCells);
            }
            if (!ds.Variables.Contains(Namings.VarNameHourMax))
            {
                ds.AddVariable <int>(Namings.VarNameHourMax, Namings.dimNameCells);
            }
            if (!ds.Variables.Contains(Namings.VarNameHourMin))
            {
                ds.AddVariable <int>(Namings.VarNameHourMin, Namings.dimNameCells);
            }
            if (!ds.Variables.Contains(Namings.VarNameYearMax))
            {
                ds.AddVariable <int>(Namings.VarNameYearMax, Namings.dimNameCells);
            }
            if (!ds.Variables.Contains(Namings.VarNameYearMin))
            {
                ds.AddVariable <int>(Namings.VarNameYearMin, Namings.dimNameCells);
            }

            ds.Variables[Namings.VarNameDayMax].Append(stopday);
            ds.Variables[Namings.VarNameDayMin].Append(startday);
            ds.Variables[Namings.VarNameHourMax].Append(stophour);
            ds.Variables[Namings.VarNameHourMin].Append(starthour);
            ds.Variables[Namings.VarNameYearMax].Append(stopyear);
            ds.Variables[Namings.VarNameYearMin].Append(startyear);
            ds.Variables[Namings.VarNameLonMax].Append(lonmax);
            ds.Variables[Namings.VarNameLonMin].Append(lonmin);
            ds.Variables[Namings.VarNameLatMax].Append(latmax);
            ds.Variables[Namings.VarNameLatMin].Append(latmin);

            ds.Commit();
        }
Beispiel #8
0
 /// <summary>
 /// Split requested area into spatial grid and returns mean values of the requested parameter for its cells. Takes additional paramter to control the process of calculation. Returns object that contains additional information about calculated result.
 /// </summary>
 /// <param name="parameter">A climate parameter that will be evaluated for mean value</param>
 /// <param name="latmin">Minimum latitude of the requested area</param>
 /// <param name="lonmin">Mimimun longatude of the requested area</param>
 /// <param name="latmax">Maximum latitude of the requesed area </param>
 /// <param name="lonmax">Maximum longatude of the requesed area</param>
 /// <param name="yearmin">The first year that will be used to form time intervals of the request</param>
 /// <param name="daymin">The first day of the year (1..365) that will be used to form time intervals of the request</param>
 /// <param name="hourmin">The time in hours of the day (0..24) that will be used as a lower inclusive bound to form time intervals of the request. Use -999 or 0 to specify the begining of the day</param>
 /// <param name="yearmax">The last year(inclusivly) that will be used to form time intervals for request</param>
 /// <param name="daymax">The last day of the year(inclusivly) that will be used to form time intervals of the request. Use -999 to specify the last day of the year.</param>
 /// <param name="hourmax">The time in hours of the day (0..24) that will be used as an upper inclusive bound to form time intervals of the request. Use -999 or 24 to specify the end of the day</param>
 /// <param name="dlat">A step along latitude that will be used to split requested area into grid</param>
 /// <param name="dlon">A step along longatude that will be used to split requested areia into grid</param>
 /// <param name="options">An information about how to perform the calculation</param>        
 internal static FetchClimateGridResponce FetchClimateGridEx(ClimateParameter parameter, FetchingOptions options, double latmin, double latmax, double lonmin, double lonmax, double dlat, double dlon, int hourmin = 0, int hourmax = 24, int daymin = 1, int daymax = GlobalConsts.DefaultValue, int yearmin = 1961, int yearmax = 1990)
 {
     return ClientInstance.FetchClimateGrid(parameter, latmin, latmax, lonmin, lonmax, hourmin, hourmax, daymin, daymax, yearmin, yearmax, dlat, dlon, options);
 }
Beispiel #9
0
 /// <summary>
 /// Time series request (splitting hourmin-hourmax interval by dyear value). Takes additional paramter to control the process of calculation. Returns object that contains additional information about calculated result.
 /// </summary>
 /// <param name="p">A climate parameter that will be evaluated for mean value</param>
 /// <param name="latmin">Minimum latitude of the requested area</param>
 /// <param name="lonmin">Mimimun longatude of the requested area</param>
 /// <param name="latmax">Maximum latitude of the requesed area </param>
 /// <param name="lonmax">Maximum longatude of the requesed area</param>
 /// <param name="yearmin">The first year that will be used to form time intervals of the request</param>
 /// <param name="daymin">The first day of the year (1..365) that will be used to form time intervals of the request</param>
 /// <param name="hourmin">The time in hours of the day (0..24) that will be used as a lower inclusive bound to form time intervals of the request. Use -999 or 0 to specify the begining of the day</param>
 /// <param name="yearmax">The last year(inclusivly) that will be used to form time intervals for request</param>
 /// <param name="daymax">The last day of the year(inclusivly) that will be used to form time intervals of the request. Use -999 to specify the last day of the year.</param>
 /// <param name="hourmax">The time in hours of the day (0..24) that will be used as an upper inclusive bound to form time intervals of the request. Use -999 or 24 to specify the end of the day</param>
 /// <param name="dyear">The step that will be used to spit [hourmin,hourmax] interval into a separate intervals. The default value is 1</param>
 /// <param name="options">An information about how to perform the calculation</param>        
 internal static FetchClimateBatchResponce FetchClimateHourlyEx(ClimateParameter p, FetchingOptions options, double latmin, double latmax, double lonmin, double lonmax, int hourmin = 0, int hourmax = 24, int daymin = 1, int daymax = GlobalConsts.DefaultValue, int yearmin = 1961, int yearmax = 1990, int dhour = 1)
 {
     return ClientInstance.FetchClimateHourly(p, latmin, latmax, lonmin, lonmax, hourmin, hourmax, daymin, daymax, yearmin, yearmax, dhour, options);
 }
Beispiel #10
0
 /// <summary>
 /// Returns mean value of specified climate parameter for the given geographical area at the given time of the day, season and year interval. Takes additional paramter to control the process of calculation. Returns object that contains additional information about calculated result.
 /// </summary>
 /// <param name="parameter">A climate variable that will be evaluated for mean value</param>
 /// <param name="latmin">Minimum latitude of the requested region</param>
 /// <param name="lonmin">Mimimun longatude of the requested region</param>
 /// <param name="latmax">Maximum latitude of the requesed region </param>
 /// <param name="lonmax">Maximum longatude of the requesed region</param>
 /// <param name="startyear">The first year that will be used to form time intervals of the request. Default value is 1961</param>
 /// <param name="startday">The first day of the year (1..365) that will be used to form time intervals of the request. Default value is 1</param>
 /// <param name="starthour">The time in hours of the day (0..24) that will be used as a lower inclusive bound to form time intervals of the request. Default value is 0</param>
 /// <param name="stopyear">The last year(inclusivly) that will be used to form time intervals for request. Default value is 1990</param>
 /// <param name="stopday">The last day of the year(inclusivly) that will be used to form time intervals of the request. Use GlobalConsts.DefaultValue to specify the last day of the year. Default value is "the last day of the year"</param>
 /// <param name="stophour">The time in hours of the day (0..24) that will be used as an upper inclusive bound to form time intervals of the request. Use 24 to specify the end of the day. Default value is 24</param>
 /// <param name="options">An information about how to perform the calculation</param>        
 internal static FetchClimateSingleResponce FetchClimateEx(ClimateParameter parameter, FetchingOptions options, double latmin, double latmax, double lonmin, double lonmax, int starthour = 0, int stophour = 24, int startday = 1, int stopday = GlobalConsts.DefaultValue, int startyear = 1961, int stopyear = 1990)
 {
     return ClientInstance.FetchClimate(parameter, latmin, latmax, lonmin, lonmax, starthour, stophour, startday, stopday, startyear, stopyear, options);
 }
Beispiel #11
0
 /// <summary>
 /// Batch version of single fetch climate request. The parameteras are passed as a seperate arrays. Takes additional paramter to control the process of calculation. Returns object that contains additional information about calculated result.
 /// </summary>
 /// <param name="parameter">A climate parameter that will be evaluated for mean value</param>
 /// <param name="latmin">Minimum latitude of the requested region</param>
 /// <param name="lonmin">Mimimun longatude of the requested region</param>
 /// <param name="latmax">Maximum latitude of the requesed region </param>
 /// <param name="lonmax">Maximum longatude of the requesed region</param>
 /// <param name="startyear">The first year that will be used to form time intervals of the request. The null value means 1961 (default)</param>
 /// <param name="startday">The first day of the year (1..365) that will be used to form time intervals of the request. The null value means 1</param>
 /// <param name="starthour">The time in hours of the day (0..24) that will be used as a lower inclusive bound to form time intervals of the request. The null value means 0</param>
 /// <param name="stopyear">The last year(inclusivly) that will be used to form time intervals for request. The null value means 1990</param>
 /// <param name="stopday">The last day of the year(inclusivly) that will be used to form time intervals of the request. Use GlobalConsts.DefaultValue to specify the last day of the year. The null value means "the last day of the year"</param>
 /// <param name="stophour">The time in hours of the day (0..24) that will be used as an upper inclusive bound to form time intervals of the request. Use 24 to specify the end of the day. The null value means 24</param>
 /// <param name="options">An information about how to perform the calculation</param>
 internal static FetchClimateBatchResponce FetchClimateEx(ClimateParameter parameter, FetchingOptions options, double[] latmin, double[] latmax, double[] lonmin, double[] lonmax, int[] starthour = null, int[] stophour = null, int[] startday = null, int[] stopday = null, int[] startyear = null, int[] stopyear = null)
 {
     int len = latmin.Length;
     return ClientInstance.FetchClimate(parameter, latmin, latmax, lonmin, lonmax,
         (starthour!=null)?(starthour):(Enumerable.Repeat(0,len).ToArray()),
         (stophour!=null)?(stophour):(Enumerable.Repeat(24,len).ToArray()),
         (startday != null) ? (startday) : (Enumerable.Repeat(1, len).ToArray()),
         (stopday != null) ? (stopday) : (Enumerable.Repeat(GlobalConsts.DefaultValue, len).ToArray()),
         (startyear != null) ? (startyear) : (Enumerable.Repeat(GlobalConsts.StartYear, len).ToArray()),
         (stopyear != null) ? (stopyear) : (Enumerable.Repeat(GlobalConsts.EndYear, len).ToArray()),
         options,ResearchVariationType.Auto);
 }
        public FetchClimateGridResponce FetchClimateGrid(ClimateParameter parameter, double latmin, double latmax, double lonmin, double lonmax, int hourmin, int hourmax, int daymin, int daymax, int yearmin, int yearmax, double dlat, double dlon, FetchingOptions options)
        {
            int nlat = (int)Math.Round((latmax - latmin) / dlat);
            int nlon = (int)Math.Round((lonmax - lonmin) / dlon);

            double[] latsGrid = new double[nlat + 1];
            double[] lonsGrid = new double[nlon + 1];
            for (int i = 0; i < latsGrid.Length; i++)
            {
                latsGrid[i] = latmin + i * dlat;
            }
            for (int i = 0; i < lonsGrid.Length; i++)
            {
                lonsGrid[i] = lonmin + i * dlon;
            }
            int[]    hourmins = new int[nlat * nlon];
            int[]    hourmaxs = new int[nlat * nlon];
            int[]    daymins = new int[nlat * nlon];
            int[]    daymaxs = new int[nlat * nlon];
            int[]    yearmins = new int[nlat * nlon];
            int[]    yearmaxs = new int[nlat * nlon];
            double[] latmins = new double[nlat * nlon];
            double[] latmaxs = new double[nlat * nlon];
            double[] lonmins = new double[nlat * nlon];
            double[] lonmaxs = new double[nlat * nlon];
            int      rowIndex, colIndex;

            for (int i = 0; i < nlat * nlon; i++)
            {
                rowIndex = i / nlon;
                colIndex = i % nlon;

                lonmins[i] = lonsGrid[colIndex];
                lonmaxs[i] = lonsGrid[colIndex + 1];
                latmins[i] = latsGrid[rowIndex];
                latmaxs[i] = latsGrid[rowIndex + 1];

                hourmins[i] = hourmin;
                hourmaxs[i] = hourmax;
                daymins[i]  = daymin;
                daymaxs[i]  = daymax;
                yearmins[i] = yearmin;
                yearmaxs[i] = yearmax;
            }

            var resB = FetchClimate(parameter, latmins, latmaxs, lonmins, lonmaxs, hourmins, hourmaxs, daymins, daymaxs, yearmins, yearmaxs, options, ResearchVariationType.Spatial);

            ClimateParameterValue[] result = resB.Values;
            ClimateParameterValue[,] result2D = new ClimateParameterValue[nlat, nlon];
            for (int i = 0; i < nlat * nlon; i++)
            {
                rowIndex = i / nlon;
                colIndex = i % nlon;
                result2D[rowIndex, colIndex] = result[i];
            }
            FetchClimateGridResponce res = new FetchClimateGridResponce();

            res.Values         = result2D;
            res.ServiceVersion = resB.ServiceVersion;
            return(res);
        }
        private FetchClimateBatchResponce FetchClimateTimeSeries(ClimateParameter p, double latmin, double latmax, double lonmin, double lonmax, int hourmin, int hourmax, int daymin, int daymax, int yearmin, int yearmax, int divider, IntervalToSplit intervalToSplit, FetchingOptions options)
        {
            int n;

            if (hourmax == GlobalConsts.DefaultValue)
            {
                hourmax = 24;
            }
            if (hourmin == GlobalConsts.DefaultValue)
            {
                hourmin = 0;
            }
            bool isReplaceDayMaxWithDefVal = (yearmax != yearmin && (daymax == GlobalConsts.DefaultValue || daymax == 365));

            if (daymin == GlobalConsts.DefaultValue)
            {
                daymin = 1;
            }
            int effDayMax = daymax;

            if (effDayMax == GlobalConsts.DefaultValue)
            {
                effDayMax = (yearmin == yearmax) ? (DateTime.IsLeapYear(yearmin) ? 366 : 365) : 365;
            }
            ResearchVariationType rvt = ResearchVariationType.Auto;

            switch (intervalToSplit)
            {
            case IntervalToSplit.Years: n = (int)Math.Ceiling((yearmax - yearmin + 1) / (double)divider); rvt = ResearchVariationType.Yearly; break;

            case IntervalToSplit.Days: n = (int)Math.Ceiling((effDayMax - daymin + 1) / (double)divider); rvt = ResearchVariationType.Seasonly; break;

            case IntervalToSplit.Hours: n = (int)Math.Ceiling((hourmax - hourmin + 1) / (double)divider); rvt = ResearchVariationType.Hourly; break;

            default: throw new NotImplementedException();
            }
            double[] latmaxs  = new double[n];
            double[] latmins  = new double[n];
            double[] lonmaxs  = new double[n];
            double[] lonmins  = new double[n];
            int[]    hourmins = new int[n];
            int[]    hourmaxs = new int[n];
            int[]    daymins  = new int[n];
            int[]    daymaxs  = new int[n];
            int[]    yearmins = new int[n];
            int[]    yearmaxs = new int[n];

            int yi = (intervalToSplit == IntervalToSplit.Years) ? 1 : 0;
            int di = (intervalToSplit == IntervalToSplit.Days) ? 1 : 0;
            int hi = (intervalToSplit == IntervalToSplit.Hours) ? 1 : 0;

            for (int i = 0; i < n; i++)
            {
                latmaxs[i]  = latmax;
                latmins[i]  = latmin;
                lonmaxs[i]  = lonmax;
                lonmins[i]  = lonmin;
                hourmins[i] = Math.Min((hi == 0)?hourmin:(hourmin + hi * i * divider), 24);
                hourmaxs[i] = Math.Min((hi == 0) ? hourmax : (hourmin + hi * ((i + 1) * divider - 1)), 24);
                yearmins[i] = (yi == 0) ? yearmin : (yearmin + yi * i * divider);
                yearmaxs[i] = (yi == 0) ? yearmax:(yearmin + yi * ((i + 1) * divider - 1));
                daymins[i]  = Math.Min((di == 0)?daymin:(daymin + di * (i * divider)), (yearmins[i] == yearmaxs[i] && DateTime.IsLeapYear(yearmins[i]))?366:365);
                if (isReplaceDayMaxWithDefVal && intervalToSplit != IntervalToSplit.Days)
                {
                    daymaxs[i] = GlobalConsts.DefaultValue;
                }
                else
                {
                    daymaxs[i] = Math.Min((di == 0) ? daymax : (daymin + di * ((i + 1) * divider - 1)), (yearmins[i] == yearmaxs[i] && DateTime.IsLeapYear(yearmins[i])) ? 366 : 365);
                }
            }
            return(FetchClimate(p, latmins, latmaxs, lonmins, lonmaxs, hourmins, hourmaxs, daymins, daymaxs, yearmins, yearmaxs, options, rvt));
        }
 public FetchClimateBatchResponce FetchClimateHourly(ClimateParameter p, double latmin, double latmax, double lonmin, double lonmax, int hourmin, int hourmax, int daymin, int daymax, int yearmin, int yearmax, int dhour, FetchingOptions options)
 {
     AssertFcParameters(latmin, latmax, lonmin, lonmax, hourmin, hourmax, daymin, daymax, yearmin, yearmax);
     return(FetchClimateTimeSeries(p, latmin, latmax, lonmin, lonmax, hourmin, hourmax, daymin, daymax, yearmin, yearmax, dhour, IntervalToSplit.Hours, options));
 }
        public FetchClimateBatchResponce FetchClimate(ClimateParameter parameter, double[] latmin, double[] latmax, double[] lonmin, double[] lonmax, int[] starthour, int[] stophour, int[] startday, int[] stopday, int[] startyear, int[] stopyear, FetchingOptions options, ResearchVariationType variationType)
        {
            if (startday == null)
            {
                startday = Enumerable.Repeat(GlobalConsts.DefaultValue, latmin.Length).ToArray();
            }
            if (stopday == null)
            {
                stopday = Enumerable.Repeat(GlobalConsts.DefaultValue, latmin.Length).ToArray();
            }
            if (starthour == null)
            {
                starthour = Enumerable.Repeat(GlobalConsts.DefaultValue, latmin.Length).ToArray();
            }
            if (stophour == null)
            {
                stophour = Enumerable.Repeat(GlobalConsts.DefaultValue, latmin.Length).ToArray();
            }
            if (startyear == null)
            {
                startyear = Enumerable.Repeat(GlobalConsts.StartYear, latmin.Length).ToArray();
            }
            if (stopyear == null)
            {
                stopyear = Enumerable.Repeat(GlobalConsts.EndYear, latmin.Length).ToArray();
            }

            for (int i = 0; i < latmin.Length; i++)
            {
                AssertFcParameters(latmin[i], latmax[i], lonmin[i], lonmax[i], starthour[i], stophour[i], startday[i], stopday[i], startyear[i], stopyear[i]);
            }

            using (var requestDs = DataSet.Open("msds:memory"))
            {
                FetchClimateRequestBuilder.FillDataSetWithRequest(requestDs, parameter, latmin, latmax, lonmin, lonmax, starthour, stophour, startday, stopday, startyear, stopyear, options);
                requestDs.Metadata[Namings.metadataNameVariationType] = variationType.ToString();
                requestDs.Commit();
                using (var result = ServerProcess(requestDs))
                {
                    return(FetchClimateRequestBuilder.BuildBatchResult(result));
                }
            }
        }
 public FetchClimateSingleResponce FetchClimate(ClimateParameter parameter, double latmin, double latmax, double lonmin, double lonmax, int starthour, int stophour, int startday, int stopday, int startyear, int stopyear, FetchingOptions options)
 {
     AssertFcParameters(latmin, latmax, lonmin, lonmax, starthour, stophour, startday, stopday, startyear, stopyear);
     using (var requestDs = DataSet.Open("msds:memory"))
     {
         FetchClimateRequestBuilder.FillDataSetWithRequest(requestDs, parameter, latmin, latmax, lonmin, lonmax, starthour, stophour, startday, stopday, startyear, stopyear, options);
         using (var result = ServerProcess(requestDs))
         {
             return(FetchClimateRequestBuilder.BuildSingleCellResult(result));
         }
     }
 }