数据尺度转换 (累积/求均值)
例如,将小时数据转换成逐日的
static void hourToDaily(string inputFile, int timeStepLen, bool isToAverage, string outputFile, string split, string format)
{
StreamReader reader = new StreamReader(inputFile);
StreamWriter writer = new StreamWriter(outputFile);
int rows = 0;
double divide = isToAverage ? timeStepLen : 1.0;
double[] data = null;
while (!reader.EndOfStream)
{
string[] content = Regex.Split(reader.ReadLine().Trim(), split);
int colNumber = content.Length;
if (rows % timeStepLen == 0) data = new double[colNumber]; //清零数组
for (int i = 0; i < content.Length; i++)
{
data[i] += double.Parse(content[i]); //求和
}
if ((rows + 1) % timeStepLen == 0) //大时段末输出累计(平均)结果
{
for (int i = 0; i < data.Length; i++) { writer.Write((data[i] / divide).ToString(format) + split); }
writer.Write("\n");
writer.Flush();
}
rows++;
}
writer.Close();
reader.Close();
}