本文整理汇总了C#中Series.WithinRange方法的典型用法代码示例。如果您正苦于以下问题:C# Series.WithinRange方法的具体用法?C# Series.WithinRange怎么用?C# Series.WithinRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Series
的用法示例。
在下文中一共展示了Series.WithinRange方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Interpolate
/// <summary>
/// Interpolate value at specified time.
/// </summary>
/// <param name="s">Series containing values to interpolate from</param>
/// <param name="t">DateTime to interpolate at</param>
/// <param name="AllowExtrapolate">Allow extrapolation outside Series s</param>
/// <param name="index">index to t or next index in series</param>
/// <returns></returns>
public static double Interpolate(Series s, DateTime t, bool AllowExtrapolate, int index)
{
if (!s.WithinRange(t) && !AllowExtrapolate)
{
string msg = "can not interpolate outside range (" + s.MinDateTime + " --> " + s.MaxDateTime
+ ")\n requested date is " + t;
throw new ArgumentOutOfRangeException(msg);
}
int currentIndex = 0;
if (index >= 0) // use input index to save lookup.
{
currentIndex = index;
}
else
{
currentIndex = s.LookupIndex(t);
}
int i = currentIndex;
if (i < 0)
{ // must allow [i-1]
// this should not happen since we called WithinRange() above
throw new Exception("cannot interpolate with outside array bounds. error#2");
}
Point point = s[i];
// first test for exact match.
if (point.DateTime == t)
{
return point.Value;
}
Point pointM1 = s[i - 1];
if (point.IsMissing || pointM1.IsMissing)
{
throw new Exception("Error: cannot interpolate when point is marked as missing");
}
if (point.DateTime >= t)
{
if (point.DateTime == t)
{
return point.Value;
}
// interpolate.
double y2 = System.Convert.ToDouble(point.Value);
double y1 = System.Convert.ToDouble(pointM1.Value);
DateTime date1 = System.Convert.ToDateTime(pointM1.DateTime);
double rval = Interpolate(t, date1, point.DateTime, y1, y2);
return rval;
}
if (true)
{
Console.WriteLine("Error: cannot interpolate");
throw new Exception("cannot interpolate error #3 did not find proper time. ");
}
// return 0;
}