public void WriteInterpolation(string outTotal, string outRev, string outDirect) { StringBuilder sb = new StringBuilder(); bool isReverse = (interpolation[1].Time - interpolation[0].Time) < 0; for (int i = 0; i < interpolation.Count; i++) { OutRecord r = interpolation[i]; string str = string.Format(format_interp, r.XCenter, r.Time, Math.Abs(r.Offset), r.Offset, x0); sb.Append(str).AppendLine(); if (r.Time == 0) { if (isReverse) { string result = sb.ToString(); File.AppendAllText(outTotal, result); File.AppendAllText(outRev, result); sb.Clear(); } else if (i > 0) { throw new InvalidDataException( string.Format("File: {0}.\nRecord {1}\nGetting zero time in the DIRECT hodographs", SourceFile, r)); } } } File.AppendAllText(outDirect, sb.ToString()); File.AppendAllText(outTotal, sb.ToString()); }
public override void Interpolate(double timeDelta) { if (records.Count <= 1) { MessageBox.Show("Не было выделено записей! Проверьте, всё ли настроено правильно."); return; } interpolation.Clear(); // determining the time point 'tempTime' we are going to start interpolating from LinkedListNode <Record> temp = records.First; int sign = Math.Sign(temp.Next.Value.Time - temp.Value.Time); double N = Math.Floor(temp.Value.Time / timeDelta) + (sign > 0 ? 1 : 0); double tempTime = timeDelta * N; double delta, xCenter, offset; // while-loop iteraring through all extracted lines do { Record r = temp.Value; Record rNext = temp.Next.Value; sign = Math.Sign(rNext.Time - r.Time); delta = timeDelta * sign; while (sign * (rNext.Time - tempTime) > 0) { OutRecord rOut; if (0 <= tempTime && tempTime <= 0.00001) { rOut = new OutRecord() { XCenter = r.Distance, Time = r.Time }; interpolation.Add(rOut); } else if (0 <= tempTime) { xCenter = getDist(tempTime, r.Time, rNext.Time, r.XCenter, rNext.XCenter); offset = getDist(tempTime, r.Time, rNext.Time, r.Projection, rNext.Projection); rOut = new OutRecord() { XCenter = xCenter, Time = tempTime, Offset = offset }; interpolation.Add(rOut); } tempTime += delta; } temp = temp.Next; } while (temp.Next != null); }
public void Interpolate(double timeDelta) { records.Clear(); records.AddRange(sortedRecords.Values); if (records.Count <= 1) { MessageBox.Show(string.Format("{0}\n\t{1}\n{2}", "Не было выделено записей при обработке файла", SourceFile, "Проверьте, штатная ли это ситуация."), "Предупреждение"); return; } int sign; double temp, delta, xCenter, offset; bool flag = false; for (int k = 1; k < records.Count; k++) { Record r = records[k - 1]; Record rNext = records[k]; sign = Math.Sign(rNext.Time - r.Time); delta = timeDelta * sign; // okay, we got to mess here with dem 'flags' and 'signs'. // 'flag' equalling 'TRUE' here means that 'r.Time' value is a multiple of 'timeDelta' value // AND has been already saved in 'interpolation' list, so we need to make one step further (i.e. add 'timeDelta') // in order to not duplicate an interpolation node. // 'sign' temp = flag ? (r.Time + delta) : timeDelta * (Math.Floor(r.Time / timeDelta) + (sign > 0 ? 1 : 0)); flag = false; while (true) { OutRecord outR; if (Math.Abs(rNext.Time - temp) <= 0.00001) { outR = new OutRecord() { XCenter = rNext.XCenter, Time = rNext.Time, Offset = rNext.Projection }; interpolation.Add(outR); flag = true; break; } if (sign * (rNext.Time - temp) < 0) { break; } else { xCenter = getDist(temp, r.Time, rNext.Time, r.XCenter, rNext.XCenter); offset = getDist(temp, r.Time, rNext.Time, r.Projection, rNext.Projection); outR = new OutRecord() { XCenter = xCenter, Time = temp, Offset = offset }; interpolation.Add(outR); temp += delta; } } } }