public static Interpolator2D CreateInterpolator2D(this STFReader stf) { List <double> xlist = new List <double>(); List <Interpolator> ilist = new List <Interpolator>(); stf.MustMatchBlockStart(); while (!stf.EndOfBlock()) { xlist.Add(stf.ReadFloat(STFReader.Units.Any, null)); ilist.Add(stf.CreateInterpolator()); } stf.SkipRestOfBlock(); int n = xlist.Count; if (n < 2) { STFException.TraceWarning(stf, "Interpolator must have at least two x values."); } double[] xArray = new double[n]; Interpolator[] yArray = new Interpolator[n]; for (int i = 0; i < n; i++) { xArray[i] = xlist[i]; yArray[i] = ilist[i]; if (i > 0 && xArray[i - 1] >= xArray[i]) { STFException.TraceWarning(stf, " Interpolator x values must be increasing."); } } return(new Interpolator2D(xArray, yArray)); }
internal Route(STFReader stf) { stf.MustMatchBlockStart(); stf.ParseBlock(new STFReader.TokenProcessor[] { new STFReader.TokenProcessor("routeid", () => { RouteID = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("name", () => { Name = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("filename", () => { FileName = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("description", () => { Description = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("maxlinevoltage", () => { MaxLineVoltage = stf.ReadFloatBlock(STFReader.Units.None, null); }), new STFReader.TokenProcessor("routestart", () => { RouteStart = new RouteStart(stf); }), new STFReader.TokenProcessor("environment", () => { Environment = new Environment(stf); }), new STFReader.TokenProcessor("milepostunitskilometers", () => { MilepostUnitsMetric = true; }), new STFReader.TokenProcessor("electrified", () => { Electrified = stf.ReadBoolBlock(false); }), new STFReader.TokenProcessor("overheadwireheight", () => { OverheadWireHeight = stf.ReadFloatBlock(STFReader.Units.Distance, 6.0f); }), new STFReader.TokenProcessor("speedlimit", () => { SpeedLimit = stf.ReadFloatBlock(STFReader.Units.Speed, 500.0f); }), new STFReader.TokenProcessor("defaultcrossingsms", () => { DefaultCrossingSMS = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("defaultcoaltowersms", () => { DefaultCoalTowerSMS = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("defaultdieseltowersms", () => { DefaultDieselTowerSMS = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("defaultwatertowersms", () => { DefaultWaterTowerSMS = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("defaultsignalsms", () => { DefaultSignalSMS = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("temprestrictedspeed", () => { TempRestrictedSpeed = stf.ReadFloatBlock(STFReader.Units.Speed, -1f); }), // values for tunnel operation new STFReader.TokenProcessor("ortssingletunnelarea", () => { SingleTunnelAreaM2 = stf.ReadFloatBlock(STFReader.Units.AreaDefaultFT2, null); }), new STFReader.TokenProcessor("ortssingletunnelperimeter", () => { SingleTunnelPerimeterM = stf.ReadFloatBlock(STFReader.Units.Distance, null); }), new STFReader.TokenProcessor("ortsdoubletunnelarea", () => { DoubleTunnelAreaM2 = stf.ReadFloatBlock(STFReader.Units.AreaDefaultFT2, null); }), new STFReader.TokenProcessor("ortsdoubletunnelperimeter", () => { DoubleTunnelPerimeterM = stf.ReadFloatBlock(STFReader.Units.Distance, null); }), // if > 0 indicates distance from track without forest trees new STFReader.TokenProcessor("ortsuserpreferenceforestcleardistance", () => { ForestClearDistance = stf.ReadFloatBlock(STFReader.Units.Distance, 0); }), // if true removes forest trees also from roads new STFReader.TokenProcessor("ortsuserpreferenceremoveforesttreesfromroads", () => { RemoveForestTreesFromRoads = stf.ReadBoolBlock(false); }), // values for superelevation new STFReader.TokenProcessor("ortstracksuperelevation", () => { SuperElevationHgtpRadiusM = stf.CreateInterpolator(); }), // images new STFReader.TokenProcessor("graphic", () => { Thumbnail = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("loadingscreen", () => { LoadingScreen = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("ortsloadingscreenwide", () => { LoadingScreenWide = stf.ReadStringBlock(null); }), // values for OHLE new STFReader.TokenProcessor("ortsdoublewireenabled", () => { DoubleWireEnabled = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("ortsdoublewireheight", () => { DoubleWireHeight = stf.ReadFloatBlock(STFReader.Units.Distance, null); }), new STFReader.TokenProcessor("ortstriphaseenabled", () => { TriphaseEnabled = stf.ReadStringBlock(null); }), new STFReader.TokenProcessor("ortstriphasewidth", () => { TriphaseWidth = stf.ReadFloatBlock(STFReader.Units.Distance, null); }), // default sms file for turntables and transfertables new STFReader.TokenProcessor("ortsdefaultturntablesms", () => { DefaultTurntableSMS = stf.ReadStringBlock(null); }), // sms file number in Ttype.dat when train over switch new STFReader.TokenProcessor("ortsswitchsmsnumber", () => { SwitchSMSNumber = stf.ReadIntBlock(null); }), new STFReader.TokenProcessor("ortscurvesmsnumber", () => { CurveSMSNumber = stf.ReadIntBlock(null); }), new STFReader.TokenProcessor("ortscurveswitchsmsnumber", () => { CurveSwitchSMSNumber = stf.ReadIntBlock(null); }), new STFReader.TokenProcessor("ortsopendoorsinaitrains", () => { OpenDoorsInAITrains = stf.ReadBoolBlock(false); }), }); //TODO This should be changed to STFException.TraceError() with defaults values created if (RouteID == null) { throw new STFException(stf, "Missing RouteID"); } if (Name == null) { throw new STFException(stf, "Missing Name"); } if (Description == null) { throw new STFException(stf, "Missing Description"); } if (RouteStart == null) { throw new STFException(stf, "Missing RouteStart"); } if (ForestClearDistance == 0 && RemoveForestTreesFromRoads) { Trace.TraceWarning("You must define also ORTSUserPreferenceForestClearDistance to avoid trees on roads"); } }
public static Interpolator2D CreateInterpolator2D(this STFReader stf, bool tab) { List <double> xlist = new List <double>(); List <Interpolator> ilist = new List <Interpolator>(); bool errorFound = false; if (tab) { stf.MustMatchBlockStart(); int numOfRows = stf.ReadInt(0); if (numOfRows < 2) { STFException.TraceWarning(stf, "Interpolator must have at least two rows."); errorFound = true; } int numOfColumns = stf.ReadInt(0); string header = stf.ReadString().ToLower(); if (header == "throttle") { stf.MustMatchBlockStart(); int numOfThrottleValues = 0; while (!stf.EndOfBlock()) { xlist.Add(stf.ReadFloat(STFReader.Units.None, 0f)); ilist.Add(new Interpolator(numOfRows)); numOfThrottleValues++; } if (numOfThrottleValues != (numOfColumns - 1)) { STFException.TraceWarning(stf, "Interpolator throttle vs. num of columns mismatch."); errorFound = true; } if (numOfColumns < 3) { STFException.TraceWarning(stf, "Interpolator must have at least three columns."); errorFound = true; } int numofData = 0; string tableLabel = stf.ReadString().ToLower(); if (tableLabel == "table") { stf.MustMatchBlockStart(); for (int i = 0; i < numOfRows; i++) { float x = stf.ReadFloat(STFReader.Units.SpeedDefaultMPH, 0); numofData++; for (int j = 0; j < numOfColumns - 1; j++) { if (j >= ilist.Count) { STFException.TraceWarning(stf, "Interpolator throttle vs. num of columns mismatch. (missing some throttle values)"); errorFound = true; } ilist[j][x] = stf.ReadFloat(STFReader.Units.Force, 0); numofData++; } } stf.SkipRestOfBlock(); } else { STFException.TraceWarning(stf, "Interpolator didn't find a table to load."); errorFound = true; } //check the table for inconsistencies foreach (Interpolator checkMe in ilist) { if (checkMe.Size != numOfRows) { STFException.TraceWarning(stf, "Interpolator has found a mismatch between num of rows declared and num of rows given."); errorFound = true; } double dx = (checkMe.MaxX() - checkMe.MinX()) * 0.1f; if (dx <= 0f) { STFException.TraceWarning(stf, "Interpolator has found X data error - x values must be increasing. (Possible row number mismatch)"); errorFound = true; } else { for (double x = checkMe.MinX(); x <= checkMe.MaxX(); x += dx) { if (double.IsNaN(checkMe[x])) { STFException.TraceWarning(stf, "Interpolator has found X data error - x values must be increasing. (Possible row number mismatch)"); errorFound = true; break; } } } } if (numofData != (numOfRows * numOfColumns)) { STFException.TraceWarning(stf, "Interpolator has found a mismatch: num of data doesn't fit the header information."); errorFound = true; } } else { STFException.TraceWarning(stf, "Interpolator must have a 'throttle' header row."); errorFound = true; } stf.SkipRestOfBlock(); } else { stf.MustMatchBlockStart(); while (!stf.EndOfBlock()) { xlist.Add(stf.ReadFloat(STFReader.Units.Any, null)); ilist.Add(stf.CreateInterpolator()); } } int n = xlist.Count; if (n < 2) { STFException.TraceWarning(stf, "Interpolator must have at least two x values."); errorFound = true; } double[] xArray = new double[n]; Interpolator[] yArray = new Interpolator[n]; for (int i = 0; i < n; i++) { xArray[i] = xlist[i]; yArray[i] = ilist[i]; if (i > 0 && xArray[i - 1] >= xArray[i]) { STFException.TraceWarning(stf, "Interpolator x values must be increasing."); } } if (errorFound) { STFException.TraceWarning(stf, "Errors found in the Interpolator definition!!! The Interpolator will not work correctly!"); } Interpolator2D result = new Interpolator2D(xArray, yArray); return(result); }