private static void PreprocessSortByTrackPosition(string FileName, bool IsRW, double[] UnitFactors, ref Expression[] Expressions) { System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture; PositionedExpression[] p = new PositionedExpression[Expressions.Length]; int n = 0; double a = -1.0; bool NumberCheck = !IsRW; for (int i = 0; i < Expressions.Length; i++) { if (IsRW) { // only check for track positions in the railway section for RW routes if (Expressions[i].Text.StartsWith("[", StringComparison.Ordinal) & Expressions[i].Text.EndsWith("]", StringComparison.Ordinal)) { string s = Expressions[i].Text.Substring(1, Expressions[i].Text.Length - 2).Trim(); if (string.Compare(s, "Railway", StringComparison.OrdinalIgnoreCase) == 0) { NumberCheck = true; } else { NumberCheck = false; } } } double x; if (NumberCheck && Interface.TryParseDouble(Expressions[i].Text, UnitFactors, out x)) { x += Expressions[i].TrackPositionOffset; if (x >= 0.0) { a = x; } else { Interface.AddMessage(Interface.MessageType.Error, false, "Negative track position encountered at line " + Expressions[i].Line.ToString(Culture) + ", column " + Expressions[i].Column.ToString(Culture) + " in file " + Expressions[i].File); } } else { p[n].TrackPosition = a; p[n].Expression = Expressions[i]; int j = n; n++; while (j > 0) { if (p[j].TrackPosition < p[j - 1].TrackPosition) { PositionedExpression t = p[j]; p[j] = p[j - 1]; p[j - 1] = t; j--; } else { break; } } } } a = -1.0; Expression[] e = new Expression[Expressions.Length]; int m = 0; for (int i = 0; i < n; i++) { if (p[i].TrackPosition != a) { a = p[i].TrackPosition; e[m] = new Expression(); e[m].Text = (a / UnitFactors[UnitFactors.Length - 1]).ToString(Culture); e[m].Line = -1; e[m].Column = -1; m++; } e[m] = p[i].Expression; m++; } Array.Resize<Expression>(ref e, m); Expressions = e; }
private static void PreprocessSortByTrackPosition(string FileName, double[] UnitFactors, ref Expression[] Expressions) { bool IsRW = string.Equals(System.IO.Path.GetExtension(FileName), ".rw", StringComparison.OrdinalIgnoreCase); System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture; PositionedExpression[] p = new PositionedExpression[Expressions.Length]; int n = 0; double a = -1.0; bool NumberCheck = !IsRW; for (int i = 0; i < Expressions.Length; i++) { if (IsRW) { // only check for track positions in the railway section for RW routes if (Expressions[i].Text.StartsWith("[", StringComparison.Ordinal) & Expressions[i].Text.EndsWith("]", StringComparison.Ordinal)) { string s = Expressions[i].Text.Substring(1, Expressions[i].Text.Length - 2).Trim(); if (string.Compare(s, "Railway", StringComparison.OrdinalIgnoreCase) == 0) { NumberCheck = true; } else { NumberCheck = false; } } } double x; if (NumberCheck && Interface.TryParseDouble(Expressions[i].Text, UnitFactors, out x)) { a = x; } else { p[n].TrackPosition = a; p[n].Expression = Expressions[i]; int j = n; n++; while (j > 0) { if (p[j].TrackPosition < p[j - 1].TrackPosition) { PositionedExpression t = p[j]; p[j] = p[j - 1]; p[j - 1] = t; j--; } else break; } } } a = -1.0; Expression[] e = new Expression[Expressions.Length]; int m = 0; for (int i = 0; i < n; i++) { if (p[i].TrackPosition != a) { a = p[i].TrackPosition; e[m] = new Expression(); e[m].Text = a.ToString(Culture); e[m].Line = -1; e[m].Column = -1; m++; } e[m] = p[i].Expression; m++; } Array.Resize<Expression>(ref e, m); Expressions = e; }
private static void PreprocessSortByTrackPosition(bool IsRW, double[] UnitFactors, ref Expression[] Expressions) { System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture; PositionedExpression[] p = new PositionedExpression[Expressions.Length]; int n = 0; double a = -1.0; bool NumberCheck = !IsRW; for (int i = 0; i < Expressions.Length; i++) { if (IsRW) { // only check for track positions in the railway section for RW routes if (Expressions[i].Text.StartsWith("[", StringComparison.Ordinal) & Expressions[i].Text.EndsWith("]", StringComparison.Ordinal)) { string s = Expressions[i].Text.Substring(1, Expressions[i].Text.Length - 2).Trim(); if (string.Compare(s, "Railway", StringComparison.OrdinalIgnoreCase) == 0) { NumberCheck = true; } else { NumberCheck = false; } } } double x; if (NumberCheck && NumberFormats.TryParseDouble(Expressions[i].Text, UnitFactors, out x)) { x += Expressions[i].TrackPositionOffset; if (x >= 0.0) { if (Interface.CurrentOptions.EnableBveTsHacks) { switch (System.IO.Path.GetFileName(Expressions[i].File.ToLowerInvariant())) { case "balloch - dumbarton central special nighttime run.csv": case "balloch - dumbarton central summer 2004 morning run.csv": if (x != 0 || a != 4125) { //Misplaced comma in the middle of the line causes this to be interpreted as a track position a = x; } break; default: a = x; break; } } else { a = x; } } else { Interface.AddMessage(MessageType.Error, false, "Negative track position encountered at line " + Expressions[i].Line.ToString(Culture) + ", column " + Expressions[i].Column.ToString(Culture) + " in file " + Expressions[i].File); } } else { p[n].TrackPosition = a; p[n].Expression = Expressions[i]; int j = n; n++; while (j > 0) { if (p[j].TrackPosition < p[j - 1].TrackPosition) { PositionedExpression t = p[j]; p[j] = p[j - 1]; p[j - 1] = t; j--; } else { break; } } } } a = -1.0; Expression[] e = new Expression[Expressions.Length]; int m = 0; for (int i = 0; i < n; i++) { if (p[i].TrackPosition != a) { a = p[i].TrackPosition; e[m] = new Expression { Text = (a / UnitFactors[UnitFactors.Length - 1]).ToString(Culture), Line = -1, Column = -1 }; m++; } e[m] = p[i].Expression; m++; } Array.Resize <Expression>(ref e, m); Expressions = e; }
private static void PreprocessSortByTrackPosition(string FileName, bool IsRW, double[] UnitFactors, ref Expression[] Expressions) { System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture; PositionedExpression[] p = new PositionedExpression[Expressions.Length]; int n = 0; double a = -1.0; bool NumberCheck = !IsRW; for (int i = 0; i < Expressions.Length; i++) { if (IsRW) { // only check for track positions in the railway section for RW routes if (Expressions[i].Text.StartsWith("[", StringComparison.Ordinal) & Expressions[i].Text.EndsWith("]", StringComparison.Ordinal)) { string s = Expressions[i].Text.Substring(1, Expressions[i].Text.Length - 2).Trim(); if (string.Compare(s, "Railway", StringComparison.OrdinalIgnoreCase) == 0) { NumberCheck = true; } else { NumberCheck = false; } } } double x; if (NumberCheck && Interface.TryParseDouble(Expressions[i].Text, UnitFactors, out x)) { x += Expressions[i].TrackPositionOffset; if (x >= 0.0) { a = x; } else { Interface.AddMessage(Interface.MessageType.Error, false, "Negative track position encountered at line " + Expressions[i].Line.ToString(Culture) + ", column " + Expressions[i].Column.ToString(Culture) + " in file " + Expressions[i].File); } } else { p[n].TrackPosition = a; p[n].Expression = Expressions[i]; int j = n; n++; while (j > 0) { if (p[j].TrackPosition < p[j - 1].TrackPosition) { PositionedExpression t = p[j]; p[j] = p[j - 1]; p[j - 1] = t; j--; } else { break; } } } } a = -1.0; Expression[] e = new Expression[Expressions.Length]; int m = 0; bool fpf = false; for (int i = 0; i < n; i++) { if (p[i].TrackPosition != a) { a = p[i].TrackPosition; e[m] = new Expression(); e[m].Text = (a / UnitFactors[UnitFactors.Length - 1]).ToString(Culture); e[m].Line = -1; e[m].Column = -1; m++; } e[m] = p[i].Expression; m++; //Finds the first non-default track position if(p[i].TrackPosition != -1 && fpf == false) { //We know that the withTrack section starts with the first NON -1 element //**APPEARS TO ALWAYS BE ZERO** //Subsequent declarations in the same block add 1 to this index //Thus, the first 'actual' user set track position is somewhere ~5 elements ahead //Of course the route can also start at zero, which means it could be a little further on! int j = i; while (j < p.Length) { j++; if (p[j].TrackPosition != p[i].TrackPosition) { //First track position found! Program.MinimumJumpToPositionValue = p[j].TrackPosition; fpf = true; //Break out the while loop break; } } } } Array.Resize<Expression>(ref e, m); Expressions = e; }