感谢版主指点,按照版主文中使用mdatas[mIndex] = DataMath.Average(mList, false);来计算格点数据的平均值,省了把每个格点循环的工作。方便好用!
- NetCDFDataInfo aDataInfo = new NetCDFDataInfo();
- string aFile = Application.StartupPath + "\\Sample\\Hadisst_obs_1949-2010_T106_BCC_AGCM2.1.nc";
- //读取nc文件
- aDataInfo.ReadDataInfo(aFile);
- var t = aDataInfo.times;
- List<GridData>[] datas = new List<GridData>[12];
- int sYear = aDataInfo.times[0].Year;
- int eYear = aDataInfo.times[aDataInfo.times.Count - 1].Year;
- int yIndex = 0;
- GridData gData = new GridData();
- //循环年份
- for (int startYear = 1961; startYear < eYear; startYear++)
- {
- yIndex = startYear - sYear;
- //将每年12个月的数据都摆在相应月份的数组里
- for (int mIndex = 0; mIndex < 12; mIndex++)
- {
- List<GridData> mList = datas[mIndex];
-
- if (mList == null)
- {
- mList = new List<GridData>();
- }
- mList.Add(aDataInfo.GetGridData_LonLat(yIndex * 12 + mIndex, 3, 0));
- datas[mIndex] = mList;
- }
- }
- GridData[] mdatas = new GridData[12];
- //对每个月份的数据计算平均值
- for (int mIndex = 0; mIndex < 12; mIndex++)
- {
- List<GridData> mList = datas[mIndex];
- mdatas[mIndex] = DataMath.Average(mList, false);
- }
|