private void TryToCircle(ref NonUniformDataSource2D <double> nfield) { double[] lons = nfield.X; if (lons.Length <= 2) { return; } if (lons[0] > lons[1]) { return; // we're supporting now only increaing values } double delta0 = lons[1] - lons[0]; double delta1 = 360.0 - (lons[lons.Length - 1] - lons[0]); if (delta1 > 0 && (delta1 <= 1.2 * delta0)) { // Hooray! Circling it.... double[] lats = nfield.Y; double[,] data = new double[nfield.Width + 1, nfield.Height]; double[,] sdata = nfield.Data; Array.Resize(ref lons, lons.Length + 1); lons[lons.Length - 1] = lons[0] + 360.0; int i; for (i = 0; i < lons.Length - 1; i++) { for (int j = 0; j < lats.Length; j++) { data[i, j] = sdata[i, j]; } } for (int j = 0; j < lats.Length; j++) { data[i, j] = sdata[0, j]; } nfield = new NonUniformDataSource2D <double>(data, lats, lons); } }
private object AnalyzeData(object sourceData) { if (sourceData is NonUniformDataSource2D <double> ) { NonUniformDataSource2D <double> field = sourceData as NonUniformDataSource2D <double>; double[] lats = new double[field.Height]; double[] lons = new double[field.Width]; double[,] data = new double[field.Width, field.Height]; if (field.X[field.Width - 1] < field.X[0]) { if (field.Y[field.Height - 1] < field.Y[0]) { for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { lats[j] = field.Y[field.Height - 1 - j]; lons[i] = field.X[field.Width - 1 - i]; data[i, j] = field.Data[field.Width - 1 - i, field.Height - 1 - j]; } } field = new NonUniformDataSource2D <double>(data, lats, lons); } else { for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { lats[j] = field.Y[j]; lons[i] = field.X[field.Width - 1 - i]; data[i, j] = field.Data[field.Width - 1 - i, j]; } } field = new NonUniformDataSource2D <double>(data, lats, lons); } } else { if (field.Y[field.Height - 1] < field.Y[0]) { for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { lats[j] = field.Y[field.Height - 1 - j]; lons[i] = field.X[i]; data[i, j] = field.Data[i, field.Height - 1 - j]; } } field = new NonUniformDataSource2D <double>(data, lats, lons); } } int workIndex = field.Width; for (int i = 0; i < field.Width; i++) { if (field.X[i] > 180) { workIndex = i; break; } } if (workIndex < field.Width) { double[] lats2 = new double[field.Height]; double[] lons2 = new double[field.Width]; double[,] data2 = new double[field.Width, field.Height]; for (int i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { if (i < field.Width + 1 - workIndex) { lons2[i] = field.X[workIndex + i - 1] - 360; lats2[j] = field.Y[j]; data2[i, j] = field.Data[workIndex + i - 1, j]; } else { lons2[i] = field.X[i - (field.Width + 1 - workIndex)]; lats2[j] = field.Y[j]; data2[i, j] = field.Data[i - (field.Width + 1 - workIndex), j]; } } } field = new NonUniformDataSource2D <double>(data2, lats2, lons2); TryToCircle(ref field); } return(field); } else { return(sourceData); } }