예제 #1
0
        public void ValidateTest()
        {
            var table = new Table1D(new[] { 3.0, 4.0, 5.0 },
                                    new[] { 8.0, -7.5, 1.35 });

            table.Validate();
        }
예제 #2
0
파일: LCBox.cs 프로젝트: arneb89/Mapper
        public Table1D[] GetAssignetLightCurves()
        {
            int masSize = 0;

            for (int i = 0; i < this.lcNum; i++)
            {
                if (this.usingSignature[i])
                {
                    masSize = masSize + 1;
                }
            }

            Table1D[] lc = new Table1D[masSize];

            int k = 0;

            for (int i = 0; i < this.lcNum; i++)
            {
                if (this.usingSignature[i])
                {
                    lc[k] = this.lcMas[i];
                    k++;
                }
            }

            return(lc);
        }
예제 #3
0
        public void AddLightCurve(string file)
        {
            Table1D table = new Table1D(file);

            if (this.lightCurvesNumber > 0)
            {
                LightCurve[] lcCache = this.lc;

                this.lightCurvesNumber++;

                this.lc = new LightCurve[this.lightCurvesNumber];

                for (int i = 0; i < this.lightCurvesNumber - 1; i++)
                {
                    this.lc[i] = lcCache[i];
                }

                this.lc[this.lightCurvesNumber - 1]        = new LightCurve();
                this.lc[this.lightCurvesNumber - 1].Fluxes = table.FMas;
                this.lc[this.lightCurvesNumber - 1].Phases = table.XMas;
                this.lc[this.lightCurvesNumber - 1].Band   = table.Info;
            }

            else
            {
                this.lightCurvesNumber = 1;

                this.lc           = new LightCurve[this.lightCurvesNumber];
                this.lc[0]        = new LightCurve();
                this.lc[0].Fluxes = table.FMas;
                this.lc[0].Phases = table.XMas;
                this.lc[0].Band   = table.Info;
            }
        }
예제 #4
0
        public void TruncateRepeatedX()
        {
            double[] x = { 3.0, 3.0, 3.0 };
            double[] f = { -5.0, 12.0, -9.0 };

            var table = new Table1D(x, f).TruncateInvalidXValues();

            Assert.IsTrue(table.x.SequenceEqual(x.Take(1)));
            Assert.IsTrue(table.f.SequenceEqual(f.Take(1)));
        }
예제 #5
0
        public void TruncateDecreasingX()
        {
            double[] x = { -1.0, -2.0, -3.0, -3.0 };
            double[] f = { -5.0, 12.0, -9.0, 6.0 };

            var table = new Table1D(x, f).TruncateInvalidXValues();

            Assert.IsTrue(table.x.SequenceEqual(x.Take(3)));
            Assert.IsTrue(table.f.SequenceEqual(f.Take(3)));
        }
예제 #6
0
        public void Truncate1Element()
        {
            double[] x = { 1.0 };
            double[] f = { -5.0 };

            var table = new Table1D(x, f).TruncateInvalidXValues();

            Assert.IsTrue(table.x.SequenceEqual(x));
            Assert.IsTrue(table.f.SequenceEqual(f));
        }
예제 #7
0
        private void AssertTable(string source)
        {
            var table = TableReader1D.Read(source);

            var expected = new Table1D(
                new [] { 1500.0, 1600.0, 1800.0 },
                new [] { 51.2, 52.8, 55.9 });

            Assert.IsTrue(table.Equals(expected, delta));
        }
예제 #8
0
        public void TableTooSmallNotValid()
        {
            Assert.Throws <ArgumentException>(() =>
            {
                var table = new Table1D(
                    new[] { 3.0, 4.0, 5.0 },
                    new[] { 8.0, -7.5 });

                table.Validate();
            });
        }
예제 #9
0
        // 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)));
        }
예제 #10
0
        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);
        }
예제 #11
0
        public void ReadCustomParser()
        {
            string s =
                @"10 3
                  15 9";

            Func <string, double> customParser = (str) =>
            {
                var x = double.Parse(str);
                return(x * x);
            };

            var result = TableReader1D.Read(s, double.Parse, customParser);

            var expected = new Table1D(
                new [] { 10.0, 15.0 },
                new [] { 9.0, 81.0 });

            Assert.IsTrue(result.Equals(expected, delta));
        }
예제 #12
0
        public static AirbusPerfTable GetTable()
        {
            var headwind = new Table1D(Arr(4920.0, 5740), Arr(21.32, 22.96));
            var tailwind = new Table1D(Arr(4920.0, 5740), Arr(74.62, 80.36));
            var up       = new Table1D(Arr(4920.0, 5740), Arr(524.8, 705.2));
            var down     = new Table1D(Arr(4920.0, 5740), Arr(55.76, 75.44));

            var t0 = new Table2D(Arr(0.0, 2000), Arr(4000.0, 5000), Arr(Arr(139.0, 152), Arr(132.0, 146)));
            var t1 = new Table2D(Arr(0.0, 2000), Arr(4000.0, 4350), Arr(Arr(132.0, 137), Arr(127.0, 132)));


            var tables = List(
                new TableDataNode()
            {
                Table = t0, Flaps = "1+F", IsaOffset = 0
            },
                new TableDataNode()
            {
                Table = t1, Flaps = "1+F", IsaOffset = 15
            }
                );

            var wet = new Table1D(Arr(8000.0, 10000), Arr(2.273, 2.273));

            return(new AirbusPerfTable()
            {
                HeadwindCorrectionTable = headwind,
                TailwindCorrectionTable = tailwind,
                UphillCorrectionTable = up,
                DownHillCorrectionTable = down,
                Tables = tables,
                WetCorrectionTable = wet,
                EngineAICorrection = 0.5556,
                AllAICorrection = 1.6667,
                PacksOnCorrection = 4.8889
            });
        }
예제 #13
0
파일: LCBox.cs 프로젝트: arneb89/Mapper
        public void AddLightCurve(string path)
        {
            Table1D lc = new Table1D(path);

            //

            if (this.lcNum > 0)
            {
                Table1D[] lcMasCopy          = this.lcMas;
                bool[]    usingSignatureCopy = this.usingSignature;
                string[]  filterCopy         = this.filter;
                int[]     volumeCopy         = this.volume;
                double[]  ldXCopy            = this.ldX;
                double[]  ldYCopy            = this.ldY;
                double[]  sigmaCopy          = this.sigma;

                this.lcNum++;

                this.lcMas          = new Table1D[this.lcNum];
                this.usingSignature = new bool[this.lcNum];
                this.filter         = new string[this.lcNum];
                this.volume         = new int[this.lcNum];
                this.ldX            = new double[this.lcNum];
                this.ldY            = new double[this.lcNum];
                this.sigma          = new double[this.lcNum];

                for (int i = 0; i < this.lcNum - 1; i++)
                {
                    this.lcMas[i]          = lcMasCopy[i];
                    this.usingSignature[i] = usingSignatureCopy[i];
                    this.filter[i]         = filterCopy[i];
                    this.volume[i]         = volumeCopy[i];
                    this.ldX[i]            = ldXCopy[i];
                    this.ldY[i]            = ldYCopy[i];
                    this.sigma[i]          = sigmaCopy[i];
                }

                this.lcMas[this.lcNum - 1]          = lc;
                this.usingSignature[this.lcNum - 1] = true;
                this.filter[this.lcNum - 1]         = lc.Info;
                this.volume[this.lcNum - 1]         = lc.XMas.Length;
                this.ldX[this.lcNum - 1]            = 0.0;
                this.ldY[this.lcNum - 1]            = 0.0;
                this.sigma[this.lcNum - 1]          = 0.0;
            }

            else
            {
                this.lcNum = 1;

                this.lcMas          = new Table1D[this.lcNum];
                this.usingSignature = new bool[this.lcNum];
                this.filter         = new string[this.lcNum];
                this.volume         = new int[this.lcNum];
                this.ldMod          = 1;
                this.ldX            = new double[this.lcNum];
                this.ldY            = new double[this.lcNum];
                this.sigma          = new double[this.lcNum];

                this.lcMas[0]          = lc;
                this.usingSignature[0] = true;
                this.filter[0]         = lc.Info;
                this.volume[0]         = lc.XMas.Length;
                this.ldX[0]            = 0.0;
                this.ldY[0]            = 0.0;
                this.sigma[0]          = 0.0;
            }
        }