static void Main(string[] args) { var str = @"240000 260000 280000 300000 320000 340000 360000 380000 400000 420000 440000 460000 800 14100 14900 15800 16700 17500 18500 19500 20400 21500 22700 23900 25100 1200 19800 20900 22200 23600 24800 26200 27600 28900 30400 32100 33900 35500 1600 25400 26800 28500 30300 31900 33700 35600 37300 39200 41300 43500 45700 2000 30900 32700 34700 36900 38900 41000 43300 45500 47700 50200 52900 55600 2400 36400 38400 40700 43300 45800 48200 50900 53500 56100 59000 62100 65200 2800 41700 44000 46600 49500 52400 55200 58300 61300 64400 67600 71000 74600 3200 47000 49500 52400 55600 58900 62000 65500 68900 72400 76000 79800 83700 3600 52100 55000 58100 61700 65300 68900 72600 76300 80200 84200 88300 92600 4000 57200 60300 63800 67600 71500 75500 79600 83600 87800 92200 96700 101300 4400 62300 65600 69300 73400 77600 81900 86400 90800 95300 100000 104900 109800 4800 67300 70800 74800 79100 83500 88200 93100 97800 102600 107700 112900 118200 5200 72300 75900 80100 84700 89400 94400 99500 104700 109700 115100 120700 126400 5600 77100 80900 85400 90200 95200 100400 105900 111300 116800 122400 128400 134300 6000 82000 86000 90600 95600 100900 106300 112100 117900 123700 129600 135800 142100 6400 86700 91000 95700 101000 106400 112200 118200 124200 130400 136600 143100 149700 6800 91300 95900 100700 106300 111900 117900 124100 130500 136900 143500 150200 157100 7200 95900 100700 105800 111400 117300 123500 130000 136600 143300 150300 157300 164400 7600 100400 105500 110800 116500 122700 129100 135700 142600 149600 156800 164200 171500 8000 104900 110100 115700 121600 127900 134500 141400 148500 155700 163200 170900 178500" ; var table = TableReader2D.Read(str); var table1Ds = new List <Table1D>(); for (int i = 0; i < table.x.Length; i++) { var x = table.y.ArrayCopy(); var f = table.f[i].ArrayCopy(); for (int j = 0; j < table.y.Length; j++) { x[j] -= f[j]; } var table1D = new Table1D(x, f); for (int k = 0; k < table.y.Length; k++) { table.f[i][k] = table1D.ValueAt(table.y[k]); } } var result = str.Lines()[0] + "\n" + string.Join("\n", table.x.Select(x => x.ToString()) .Zip(table.f.Select(row => string.Join(" ", row.Select(d => d.ToString("F0")))), (s1, s2) => s1 + " " + s2)); File.WriteAllText("result.txt", result); }
// Convert to Boeing format. static string Convert() { string[] Split(string s, string splitters) { return(s.Split(splitters.ToCharArray(), StringSplitOptions.RemoveEmptyEntries) .Where(x => !x.All(c => c == ' ' || c == '\t')) .ToArray()); } var landingWtsKg = new[] { 40000, 50000, 60000, 70000 }; var doc = XDocument.Load("./profile/A319_100_CFM.xml"); var tableOutputs = doc.Root.Elements("Table").Select(t => { var landingWtKg = double.Parse(t.Attribute("landing_weight").Value); var str = t.Value; var lines = Split(str, "\r\n"); var firstLine = lines[0].Split('|') .Select(s => Split(s, " \t").Select(double.Parse)) .ToList(); var x1 = firstLine[0].ToArray(); var x2 = firstLine[1].ToArray(); // Ignore lines with time. We do not need them. var linesFuel = lines.Where((_, ind) => ind % 2 == 1); var f = linesFuel.Select(line => { var words = Split(line, " \t"); var nums = words.Select(s => s == "NoValue" ? double.PositiveInfinity : double.Parse(s)).ToList(); var dis = nums[0]; var f1 = nums.Skip(1).Take(x1.Length).ToArray(); var f2 = nums.Skip(1 + x1.Length).ToArray(); var tablesf2 = new Table1D(x2, f2); var minFuel = landingWtsKg.Select(wt => f1.Select((x, ind) => x + (wt - landingWtKg) / 1000 * tablesf2.ValueAt(x1[ind])) .Min() ); return(new double[] { dis }.Concat(minFuel)); }); var outputLines = f.Select(x => string.Join(" ", x)); return(string.Join("\n", outputLines)); }); var landingWtsStr = string.Join(" ", landingWtsKg); return(string.Join("\n", new string[] { landingWtsStr }.Concat(tableOutputs))); }