Ejemplo n.º 1
0
 /// <summary>Given a Header return an appropriate datum.</summary>
 internal static Data DataFactory(Header hdr)
 {
     if (ImageHDU.IsHeader(hdr))
     {
         return(ImageHDU.ManufactureData(hdr));
     }
     else if (RandomGroupsHDU.IsHeader(hdr))
     {
         return(RandomGroupsHDU.ManufactureData(hdr));
     }
     else if (useAsciiTables && AsciiTableHDU.IsHeader(hdr))
     {
         return(AsciiTableHDU.ManufactureData(hdr));
     }
     else if (BinaryTableHDU.IsHeader(hdr))
     {
         return(BinaryTableHDU.ManufactureData(hdr));
     }
     else if (UndefinedHDU.IsHeader(hdr))
     {
         return(UndefinedHDU.ManufactureData(hdr));
     }
     else
     {
         throw new FitsException("Unrecognizable header in dataFactory");
     }
 }
Ejemplo n.º 2
0
        public void TestDegenerate()
        {
            String[] sa = new String[10];
            int[,] ia = new int[10, 0];
            Fits f = new Fits();

            for (int i = 0; i < sa.Length; i += 1)
            {
                sa[i] = "";
            }

            Object[]       data = new Object[] { sa, ia };
            BinaryTableHDU bhdu = (BinaryTableHDU)Fits.MakeHDU(data);
            Header         hdr  = bhdu.Header;

            f.AddHDU(bhdu);
            BufferedFile bf = new BufferedFile("bt7.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bf);
            bf.Close();

            Assertion.AssertEquals("degen1", 2, hdr.GetIntValue("TFIELDS"));
            Assertion.AssertEquals("degen2", 10, hdr.GetIntValue("NAXIS2"));
            Assertion.AssertEquals("degen3", 0, hdr.GetIntValue("NAXIS1"));

            f    = new Fits("bt7.fits");
            bhdu = (BinaryTableHDU)f.GetHDU(1);

            hdr = bhdu.Header;
            Assertion.AssertEquals("degen4", 2, hdr.GetIntValue("TFIELDS"));
            Assertion.AssertEquals("degen5", 10, hdr.GetIntValue("NAXIS2"));
            Assertion.AssertEquals("degen6", 0, hdr.GetIntValue("NAXIS1"));
            f.Close();
        }
Ejemplo n.º 3
0
        public void TestVar()
        {
            Object[] data = new Object[] { floats, vf, vs, vd, shorts, vbool };
            Fits     f    = new Fits();

            f.AddHDU(Fits.MakeHDU(data));

            //BufferedDataStream bdos = new BufferedDataStream(new FileStream("bt2.fits", FileMode.Open, FileAccess.ReadWrite));
            BufferedFile bdos = new BufferedFile("bt2.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bdos);
            bdos.Close();

            f = new Fits("bt2.fits", FileAccess.Read);
            f.Read();
            BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);
            Header         hdr  = bhdu.Header;

            Assertion.AssertEquals("var1", true, hdr.GetIntValue("PCOUNT") > 0);
            Assertion.AssertEquals("var2", 6, hdr.GetIntValue("TFIELDS"));

            for (int i = 0; i < data.Length; i += 1)
            {
                Assertion.AssertEquals("vardata(" + i + ")", true, ArrayFuncs.ArrayEquals(data[i], bhdu.GetColumn(i)));
            }
        }
Ejemplo n.º 4
0
        public void TestRowDelete()
        {
            Fits f = null;

            try
            {
                f = new Fits(
                    TestFileSetup.GetTargetFilename(
                        TestFileSetup.GetTargetFilename("bt1.fits")));
                f.Read();

                BinaryTableHDU thdu = (BinaryTableHDU)f.GetHDU(1);

                Assert.AreEqual(50, thdu.NRows);
                thdu.DeleteRows(10, 20);
                Assert.AreEqual(30, thdu.NRows);

                double[] dbl = (double[])thdu.GetColumn(6);
                Assert.AreEqual(dbl[9], doubles[9]);
                Assert.AreEqual(dbl[10], doubles[30]);

                BufferedFile bf =
                    new BufferedFile(
                        TestFileSetup.GetTargetFilename("bt1x.fits"),
                        FileAccess.ReadWrite,
                        FileShare.ReadWrite);

                f.Write(bf);
                bf.Close();
                bf.Dispose();
                f.Close();

                f = new Fits(TestFileSetup.GetTargetFilename("bt1x.fits"));
                f.Read();
                thdu = (BinaryTableHDU)f.GetHDU(1);
                dbl  = (double[])thdu.GetColumn(6);
                Assert.AreEqual(30, thdu.NRows);
                Assert.AreEqual(9, thdu.NCols);
                Assert.AreEqual(dbl[9], doubles[9]);
                Assert.AreEqual(dbl[10], doubles[30]);

                thdu.DeleteRows(20);
                Assert.AreEqual(20, thdu.NRows);
                dbl = (double[])thdu.GetColumn(6);
                Assert.AreEqual(20, dbl.Length);
                Assert.AreEqual(dbl[0], doubles[0]);
                Assert.AreEqual(dbl[19], doubles[39]);
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
Ejemplo n.º 5
0
        public void TestObj()
        {
            FitsFactory.UseAsciiTables = false;

            /*** Create a binary table from an Object[][] array */
            Object[][] x = new Object[5][];
            for (int i = 0; i < 5; i += 1)
            {
                x[i] = new Object[3];

                x[i][0] = new float[] { i };

                string temp = string.Concat("AString", i);
                x[i][1] = new string[] { temp };

                int[][] t = new int[2][];
                for (int j = 0; j < 2; j++)
                {
                    t[j]    = new int[2];
                    t[j][0] = j * i;
                    t[j][1] = (j + 2) * i;
                }
                x[i][2] = t;
            }

            Fits     f   = new Fits();
            BasicHDU hdu = Fits.MakeHDU(x);

            f.AddHDU(hdu);
            BufferedFile bf = new BufferedFile("bt5.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bf);
            bf.Close();


            /* Now get rid of some columns */
            BinaryTableHDU xhdu = (BinaryTableHDU)hdu;

            // First column
            Assertion.AssertEquals("delcol1", 3, xhdu.NCols);
            xhdu.DeleteColumnsIndexOne(1, 1);
            Assertion.AssertEquals("delcol2", 2, xhdu.NCols);

            xhdu.DeleteColumnsIndexZero(1, 1);
            Assertion.AssertEquals("delcol3", 1, xhdu.NCols);

            bf = new BufferedFile("bt6.fits", FileAccess.ReadWrite, FileShare.ReadWrite);
            f.Write(bf);
            bf.Close();

            f = new Fits("bt6.fits");

            xhdu = (BinaryTableHDU)f.GetHDU(1);
            Assertion.AssertEquals("delcol4", 1, xhdu.NCols);
            f.Close();
        }
Ejemplo n.º 6
0
        public void TestSimpleIO()
        {
            FitsFactory.UseAsciiTables = false;

            Fits f = new Fits();

            Object[] data = new Object[] { bytes, bits, bools, shorts, ints,
                                           floats, doubles, longs, strings };
            f.AddHDU(Fits.MakeHDU(data));

            BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);

            bhdu.SetColumnName(0, "bytes", null);
            bhdu.SetColumnName(1, "bits", "bits later on");
            bhdu.SetColumnName(6, "doubles", null);
            bhdu.SetColumnName(5, "floats", "4 x 4 array");

            BufferedFile bf = new BufferedFile("bt1.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bf);
            bf.Flush();
            bf.Close();

            f = new Fits("bt1.fits");
            f.Read();

            Assertion.AssertEquals("NHDU", 2, f.NumberOfHDUs);


            BinaryTableHDU thdu = (BinaryTableHDU)f.GetHDU(1);
            Header         hdr  = thdu.Header;

            Assertion.AssertEquals("HDR1", 9, hdr.GetIntValue("TFIELDS"));
            Assertion.AssertEquals("HDR2", 2, hdr.GetIntValue("NAXIS"));
            Assertion.AssertEquals("HDR3", 8, hdr.GetIntValue("BITPIX"));
            Assertion.AssertEquals("HDR4", "BINTABLE", hdr.GetStringValue("XTENSION"));
            Assertion.AssertEquals("HDR5", "bytes", hdr.GetStringValue("TTYPE1"));
            Assertion.AssertEquals("HDR6", "doubles", hdr.GetStringValue("TTYPE7"));

            for (int i = 0; i < data.Length; i += 1)
            {
                Object col = thdu.GetColumn(i);
                if (i == 8)
                {
                    String[] st = (String[])col;

                    for (int j = 0; j < st.Length; j += 1)
                    {
                        st[j] = st[j].Trim();
                    }
                }
                Assertion.AssertEquals("Data" + i, true, ArrayFuncs.ArrayEquals(data[i], col));
            }
            f.Close();
        }
Ejemplo n.º 7
0
        public void BuildByColumn()
        {
            Fits f = null;

            try
            {
                BinaryTable btab = new BinaryTable();

                btab.AddColumn(floats);
                btab.AddColumn(vf);
                btab.AddColumn(strings);
                btab.AddColumn(vbool);
                btab.AddColumn(ints);

                f = new Fits();
                f.AddHDU(Fits.MakeHDU(btab));

                BufferedFile bdos =
                    new BufferedFile(
                        TestFileSetup.GetTargetFilename("bt3.fits"),
                        FileAccess.ReadWrite,
                        FileShare.ReadWrite);
                f.Write(bdos);
                bdos.Close();
                bdos.Dispose();
                f.Close();

                f = new Fits(TestFileSetup.GetTargetFilename("bt3.fits"));
                BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);
                btab = (BinaryTable)bhdu.Data;

                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(floats, bhdu.GetColumn(0)));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(vf, bhdu.GetColumn(1))); // problem is here only

                String[] col = (String[])bhdu.GetColumn(2);
                for (int i = 0; i < col.Length; i += 1)
                {
                    col[i] = col[i].Trim();
                }

                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(strings, col));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(vbool, bhdu.GetColumn(3)));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(ints, bhdu.GetColumn(4)));
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
Ejemplo n.º 8
0
        public void TestDegen2()
        {
            FitsFactory.UseAsciiTables = false;

            Object[] data = new Object[] {
                new String[] { "a", "b", "c", "d", "e", "f" },
                new int[]   { 1, 2, 3, 4, 5, 6 },
                new float[] { 1f, 2f, 3f, 4f, 5f, 6f },
                new String[] { "", "", "", "", "", "" },
                new String[] { "a", "", "c", "", "e", "f" },
                new String[] { "", "b", "c", "d", "e", "f" },
                new String[] { "a", "b", "c", "d", "e", "" },
                new String[] { null, null, null, null, null, null },
                new String[] { "a", null, "c", null, "e", "f" },
                new String[] { null, "b", "c", "d", "e", "f" },
                new String[] { "a", "b", "c", "d", "e", null }
            };

            Fits f = new Fits();

            f.AddHDU(Fits.MakeHDU(data));
            BufferedFile ff = new BufferedFile("bt8.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(ff);
            ff.Flush();
            ff.Close();

            f = new Fits("bt8.fits");
            BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);

            Assertion.AssertEquals("deg21", "e", bhdu.GetElement(4, data.Length - 1));
            Assertion.AssertEquals("deg22", "", bhdu.GetElement(5, data.Length - 1));

            String[] col = (String[])bhdu.GetColumn(0);
            Assertion.AssertEquals("deg23", "a", col[0]);
            Assertion.AssertEquals("deg24", "f", col[5]);

            col = (String[])bhdu.GetColumn(3);
            Assertion.AssertEquals("deg25", "", col[0]);
            Assertion.AssertEquals("deg26", "", col[5]);

            col = (String[])bhdu.GetColumn(7);  // All nulls
            Assertion.AssertEquals("deg27", "", col[0]);
            Assertion.AssertEquals("deg28", "", col[5]);

            col = (String[])bhdu.GetColumn(8);

            Assertion.AssertEquals("deg29", "a", col[0]);
            Assertion.AssertEquals("deg210", "", col[1]);
            f.Close();
        }
Ejemplo n.º 9
0
        public void TestDegenerate()
        {
            Fits f = null;

            try
            {
                String[] sa = new String[10];
                int[,] ia = new int[10, 0];

                f = new Fits();

                for (int i = 0; i < sa.Length; i += 1)
                {
                    sa[i] = "";
                }

                Object[]       data = new Object[] { sa, ia };
                BinaryTableHDU bhdu = (BinaryTableHDU)Fits.MakeHDU(data);
                Header         hdr  = bhdu.Header;
                f.AddHDU(bhdu);

                BufferedFile bf =
                    new BufferedFile(
                        TestFileSetup.GetTargetFilename("bt7.fits"),
                        FileAccess.ReadWrite,
                        FileShare.ReadWrite);
                f.Write(bf);
                bf.Close();
                bf.Dispose();

                Assert.AreEqual(2, hdr.GetIntValue("TFIELDS"));
                Assert.AreEqual(10, hdr.GetIntValue("NAXIS2"));
                Assert.AreEqual(0, hdr.GetIntValue("NAXIS1"));

                f.Close();

                f    = new Fits(TestFileSetup.GetTargetFilename("bt7.fits"));
                bhdu = (BinaryTableHDU)f.GetHDU(1);
                hdr  = bhdu.Header;
                Assert.AreEqual(2, hdr.GetIntValue("TFIELDS"));
                Assert.AreEqual(10, hdr.GetIntValue("NAXIS2"));
                Assert.AreEqual(0, hdr.GetIntValue("NAXIS1"));
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
Ejemplo n.º 10
0
        public void TestVar()
        {
            Fits f = null;

            try
            {
                Object[] data = new Object[] { floats, vf, vs, vd, shorts, vbool };
                f = new Fits();
                f.AddHDU(Fits.MakeHDU(data));

                BufferedFile bdos =
                    new BufferedFile(
                        TestFileSetup.GetTargetFilename("bt2.fits"),
                        FileAccess.ReadWrite,
                        FileShare.ReadWrite);

                f.Write(bdos);
                bdos.Close();
                bdos.Dispose();
                f.Close();

                f = new Fits(TestFileSetup.GetTargetFilename("bt2.fits"), FileAccess.Read);
                f.Read();
                BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);
                Header         hdr  = bhdu.Header;

                Assert.AreEqual(true, hdr.GetIntValue("PCOUNT") > 0);
                Assert.AreEqual(6, hdr.GetIntValue("TFIELDS"));

                for (int i = 0; i < data.Length; i += 1)
                {
                    Assert.AreEqual(true, ArrayFuncs.ArrayEquals(data[i], bhdu.GetColumn(i)));
                }
            }
            finally
            {
                f.Close();
            }
        }
Ejemplo n.º 11
0
        public void BuildByColumn()
        {
            BinaryTable btab = new BinaryTable();

            btab.AddColumn(floats);
            btab.AddColumn(vf);
            btab.AddColumn(strings);
            btab.AddColumn(vbool);
            btab.AddColumn(ints);

            Fits f = new Fits();

            f.AddHDU(Fits.MakeHDU(btab));

            // BufferedDataStream bdos = new BufferedDataStream(new FileStream("bt3.fits",FileMode.Open));
            BufferedFile bdos = new BufferedFile("bt3.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bdos);
            bdos.Close();

            f = new Fits("bt3.fits");
            BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);

            btab = (BinaryTable)bhdu.Data;

            Assertion.AssertEquals("col1", true, ArrayFuncs.ArrayEquals(floats, bhdu.GetColumn(0)));
            Assertion.AssertEquals("col2", true, ArrayFuncs.ArrayEquals(vf, bhdu.GetColumn(1))); // problem is here only

            String[] col = (String[])bhdu.GetColumn(2);
            for (int i = 0; i < col.Length; i += 1)
            {
                col[i] = col[i].Trim();
            }
            Assertion.AssertEquals("coi3", true, ArrayFuncs.ArrayEquals(strings, col));

            Assertion.AssertEquals("col4", true, ArrayFuncs.ArrayEquals(vbool, bhdu.GetColumn(3)));
            Assertion.AssertEquals("col5", true, ArrayFuncs.ArrayEquals(ints, bhdu.GetColumn(4)));
            f.Close();
        }
Ejemplo n.º 12
0
        public void TestRowDelete()
        {
            Fits f = new Fits("testdocs\\bt1.fits");

            f.Read();

            BinaryTableHDU thdu = (BinaryTableHDU)f.GetHDU(1);

            Assertion.AssertEquals("Del1", 50, thdu.NRows);
            thdu.DeleteRows(10, 20);
            Assertion.AssertEquals("Del2", 30, thdu.NRows);

            double[] dbl = (double[])thdu.GetColumn(6);
            Assertion.AssertEquals("del3", dbl[9], doubles[9]);
            Assertion.AssertEquals("del4", dbl[10], doubles[30]);

            BufferedFile bf = new BufferedFile("bt1x.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bf);
            bf.Close();
            f.Close();

            f = new Fits("bt1x.fits");
            f.Read();
            thdu = (BinaryTableHDU)f.GetHDU(1);
            dbl  = (double[])thdu.GetColumn(6);
            Assertion.AssertEquals("del5", 30, thdu.NRows);
            Assertion.AssertEquals("del6", 9, thdu.NCols);
            Assertion.AssertEquals("del7", dbl[9], doubles[9]);
            Assertion.AssertEquals("del8", dbl[10], doubles[30]);

            thdu.DeleteRows(20);
            Assertion.AssertEquals("del9", 20, thdu.NRows);
            dbl = (double[])thdu.GetColumn(6);
            Assertion.AssertEquals("del10", 20, dbl.Length);
            Assertion.AssertEquals("del11", dbl[0], doubles[0]);
            Assertion.AssertEquals("del12", dbl[19], doubles[39]);
            f.Close();
        }
Ejemplo n.º 13
0
        // change suggested in .99.5 version: Method made public from protected.
        /// <summary>Given an object, create the appropriate FITS header to describe it.</summary>
        /// <param name="o">The object to be described.</param>
        public static BasicHDU HDUFactory(Object o)
        {
            Data   d;
            Header h;

            if (ImageHDU.IsData(o))
            {
                d = ImageHDU.Encapsulate(o);
                h = ImageHDU.ManufactureHeader(d);
            }
            else if (RandomGroupsHDU.IsData(o))
            {
                d = RandomGroupsHDU.Encapsulate(o);
                h = RandomGroupsHDU.ManufactureHeader(d);
            }
            else if (useAsciiTables && AsciiTableHDU.IsData(o))
            {
                d = AsciiTableHDU.Encapsulate(o);
                h = AsciiTableHDU.ManufactureHeader(d);
            }
            else if (BinaryTableHDU.IsData(o))
            {
                d = BinaryTableHDU.Encapsulate(o);
                h = BinaryTableHDU.ManufactureHeader(d);
            }
            else if (UndefinedHDU.IsData(o))
            {
                d = UndefinedHDU.Encapsulate(o);
                h = UndefinedHDU.ManufactureHeader(d);
            }
            else
            {
                Console.WriteLine();
                throw new FitsException("Invalid data presented to HDUFactory");
            }

            return(HDUFactory(h, d));
        }
Ejemplo n.º 14
0
        public void TestDegen2()
        {
            FitsFactory.UseAsciiTables = false;

            Object[] data = new Object[]
            {
                new String[] { "a", "b", "c", "d", "e", "f" },
                new int[] { 1, 2, 3, 4, 5, 6 },
                new float[] { 1f, 2f, 3f, 4f, 5f, 6f },
                new String[] { "", "", "", "", "", "" },
                new String[] { "a", "", "c", "", "e", "f" },
                new String[] { "", "b", "c", "d", "e", "f" },
                new String[] { "a", "b", "c", "d", "e", "" },
                new String[] { null, null, null, null, null, null },
                new String[] { "a", null, "c", null, "e", "f" },
                new String[] { null, "b", "c", "d", "e", "f" },
                new String[] { "a", "b", "c", "d", "e", null }
            };

            Fits f = null;

            try
            {
                f = new Fits();
                f.AddHDU(Fits.MakeHDU(data));
                BufferedFile ff = new BufferedFile(TestFileSetup.GetTargetFilename("bt8.fits"), FileAccess.ReadWrite,
                                                   FileShare.ReadWrite);
                f.Write(ff);
                ff.Flush();
                ff.Close();
                f.Close();

                f = new Fits(TestFileSetup.GetTargetFilename("bt8.fits"));
                BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);

                Assert.AreEqual("e", bhdu.GetElement(4, data.Length - 1));
                Assert.AreEqual("", bhdu.GetElement(5, data.Length - 1));

                String[] col = (String[])bhdu.GetColumn(0);
                Assert.AreEqual("a", col[0]);
                Assert.AreEqual("f", col[5]);

                col = (String[])bhdu.GetColumn(3);
                Assert.AreEqual("", col[0]);
                Assert.AreEqual("", col[5]);

                col = (String[])bhdu.GetColumn(7);  // All nulls
                Assert.AreEqual("", col[0]);
                Assert.AreEqual("", col[5]);

                col = (String[])bhdu.GetColumn(8);

                Assert.AreEqual("a", col[0]);
                Assert.AreEqual("", col[1]);
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
Ejemplo n.º 15
0
        public void BuildByRow()
        {
            Fits f = null;

            try
            {
                f = new Fits(
                    TestFileSetup.GetTargetFilename("bt2.fits"),
                    FileAccess.Read);
                f.Read();

                BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);
                Header         hdr  = bhdu.Header;

                BinaryTable btab = (BinaryTable)bhdu.Data;
                for (int i = 0; i < 50; i += 1)
                {
                    Object[] row = (Object[])btab.GetRow(i);
                    float[]  qx  = (float[])row[1];
                    Array[]  p   = (Array[])row[0];
                    float[]  pt  = (float[])p.GetValue(0);
                    pt[0] = (float)(i * Math.Sin(i));
                    btab.AddRow(row);
                }
                f.Close();

                f = new Fits();
                f.AddHDU(Fits.MakeHDU(btab));

                BufferedFile bf =
                    new BufferedFile(
                        TestFileSetup.GetTargetFilename("bt4.fits"),
                        FileAccess.ReadWrite,
                        FileShare.ReadWrite);
                f.Write(bf);

                bf.Flush();
                bf.Close();
                bf.Dispose();
                f.Close();

                f = new Fits(
                    TestFileSetup.GetTargetFilename("bt4.fits"),
                    FileAccess.Read);

                btab = (BinaryTable)f.GetHDU(1).Data;
                Assert.AreEqual(100, btab.NRows);

                // Try getting data before we Read in the table.
                Array[] xf   = (Array[])btab.GetColumn(0);
                Array[] xft  = (Array[])xf.GetValue(50);
                float[] xftt = (float[])xft.GetValue(0);

                Assert.AreEqual((float)0, (float)xftt[0]);

                xft  = (Array[])xf.GetValue(99);
                xftt = (float[])xft.GetValue(0);
                Assert.AreEqual((float)(49 * Math.Sin(49)), (float)xftt[0]);

                for (int i = 0; i < xf.Length; i += 3)
                {
                    bool[]  ba = (bool[])btab.GetElement(i, 5);
                    float[] fx = (float[])btab.GetElement(i, 1);

                    int trow = i % 50;

                    Assert.AreEqual(true, ArrayFuncs.ArrayEquals(ba, vbool[trow])); // prob 1
                    Assert.AreEqual(true, ArrayFuncs.ArrayEquals(fx, vf[trow]));
                }

                // Fill the table.
                Data data = f.GetHDU(1).Data;

                xf   = (Array[])btab.GetColumn(0);
                xft  = (Array[])xf.GetValue(50);
                xftt = (float[])xft.GetValue(0);
                Assert.AreEqual(0F, (float)xftt[0]);
                xft  = (Array[])xf.GetValue(99);
                xftt = (float[])xft.GetValue(0);
                Assert.AreEqual((float)(49 * Math.Sin(49)), (float)xftt[0]);

                for (int i = 0; i < xf.Length; i += 3)
                {
                    bool[]  ba = (bool[])btab.GetElement(i, 5);
                    float[] fx = (float[])btab.GetElement(i, 1);

                    int trow = i % 50;

                    Assert.AreEqual(true, ArrayFuncs.ArrayEquals(ba, vbool[trow])); // prob 2
                    Assert.AreEqual(true, ArrayFuncs.ArrayEquals(fx, vf[trow]));
                }
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
Ejemplo n.º 16
0
        public void TestSet()
        {
            Fits f = new Fits("testdocs\\bt2.fits", FileAccess.Read);

            f.Read();
            BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);
            Header         hdr  = bhdu.Header;

            // Check the various set methods on variable length data.
            float[] dta = (float[])bhdu.GetElement(4, 1);
            dta = new float[] { 22, 21, 20 };
            bhdu.SetElement(4, 1, dta);

            // BufferedDataStream bdos = new BufferedDataStream(new FileStream("bt2a.fits",FileMode.Open));
            BufferedFile bdos = new BufferedFile("bt2a.fits", FileAccess.ReadWrite, FileShare.ReadWrite);

            f.Write(bdos);
            bdos.Close();

            f    = new Fits("bt2a.fits");
            bhdu = (BinaryTableHDU)f.GetHDU(1);
            float[] xdta = (float[])bhdu.GetElement(4, 1);

            Assertion.AssertEquals("ts1", true, ArrayFuncs.ArrayEquals(dta, xdta));
            Assertion.AssertEquals("ts2", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(3, 1), vf[3]));
            Assertion.AssertEquals("ts5", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(5, 1), vf[5]));

            Assertion.AssertEquals("ts4", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), dta));

            float[] tvf = new float[] { 101, 102, 103, 104 };
            vf[4] = tvf;

            bhdu.SetColumn(1, vf);
            Assertion.AssertEquals("ts6", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(3, 1), vf[3]));
            Assertion.AssertEquals("ts7", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), vf[4]));
            Assertion.AssertEquals("ts8", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(5, 1), vf[5]));

            // bdos = new BufferedDataStream(new FileStream("bt2b.fits",FileMode.Open));
            bdos = new BufferedFile("bt2b.fits", FileAccess.ReadWrite, FileShare.ReadWrite);
            f.Write(bdos);
            bdos.Close();
            f.Close();

            f    = new Fits("bt2b.fits");
            bhdu = (BinaryTableHDU)f.GetHDU(1);
            Assertion.AssertEquals("ts9", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(3, 1), vf[3]));
            Assertion.AssertEquals("ts10", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), vf[4]));
            Assertion.AssertEquals("ts11", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(5, 1), vf[5]));

            Object[] rw = (Object[])bhdu.GetRow(4);

            float[] trw = new float[] { -1, -2, -3, -4, -5, -6 };
            rw[1] = trw;

            bhdu.SetRow(4, rw);
            Assertion.AssertEquals("ts12", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(3, 1), vf[3]));
            Assertion.AssertEquals("ts13", false, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), vf[4]));
            Assertion.AssertEquals("ts14", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), trw));
            Assertion.AssertEquals("ts15", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(5, 1), vf[5]));

            // bdos = new BufferedDataStream(new FileStream("bt2c.fits",FileMode.Open));
            bdos = new BufferedFile("bt2c.fits", FileAccess.ReadWrite, FileShare.ReadWrite);
            f.Write(bdos);
            bdos.Close();
            f.Close();

            f    = new Fits("bt2c.fits");
            bhdu = (BinaryTableHDU)f.GetHDU(1);
            Assertion.AssertEquals("ts16", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(3, 1), vf[3]));
            Assertion.AssertEquals("ts17", false, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), vf[4]));
            Assertion.AssertEquals("ts18", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), trw));
            Assertion.AssertEquals("ts19", true, ArrayFuncs.ArrayEquals(bhdu.GetElement(5, 1), vf[5]));
            f.Close();
        }
Ejemplo n.º 17
0
        public void TestSet()
        {
            Fits f = null;

            try
            {
                f = new Fits(TestFileSetup.GetTargetFilename("bt2.fits"), FileAccess.Read);
                f.Read();

                BinaryTableHDU bhdu = (BinaryTableHDU)f.GetHDU(1);
                Header         hdr  = bhdu.Header;

                // Check the various set methods on variable length data.
                float[] dta = (float[])bhdu.GetElement(4, 1);
                dta = new float[] { 22, 21, 20 };
                bhdu.SetElement(4, 1, dta);

                BufferedFile bdos =
                    new BufferedFile(
                        TestFileSetup.GetTargetFilename("bt2a.fits"),
                        FileAccess.ReadWrite,
                        FileShare.ReadWrite);
                f.Write(bdos);
                bdos.Close();
                bdos.Dispose();
                f.Close();

                f    = new Fits(TestFileSetup.GetTargetFilename("bt2a.fits"));
                bhdu = (BinaryTableHDU)f.GetHDU(1);
                float[] xdta = (float[])bhdu.GetElement(4, 1);

                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(dta, xdta));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bhdu.GetElement(3, 1), vf[3]));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bhdu.GetElement(5, 1), vf[5]));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), dta));

                float[] tvf = new float[] { 101, 102, 103, 104 };
                vf[4] = tvf;

                bhdu.SetColumn(1, vf);
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bhdu.GetElement(3, 1), vf[3]));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), vf[4]));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bhdu.GetElement(5, 1), vf[5]));

                bdos = new BufferedFile(
                    TestFileSetup.GetTargetFilename("bt2b.fits"),
                    FileAccess.ReadWrite,
                    FileShare.ReadWrite);
                f.Write(bdos);
                bdos.Close();
                bdos.Dispose();
                f.Close();

                f    = new Fits(TestFileSetup.GetTargetFilename("bt2b.fits"));
                bhdu = (BinaryTableHDU)f.GetHDU(1);
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bhdu.GetElement(3, 1), vf[3]));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), vf[4]));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bhdu.GetElement(5, 1), vf[5]));

                Object[] rw = (Object[])bhdu.GetRow(4);

                float[] trw = new float[] { -1, -2, -3, -4, -5, -6 };
                rw[1] = trw;

                bhdu.SetRow(4, rw);
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bhdu.GetElement(3, 1), vf[3]));
                Assert.AreEqual(false, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), vf[4]));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), trw));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bhdu.GetElement(5, 1), vf[5]));

                // bdos = new BufferedDataStream(new FileStream("bt2c.fits",FileMode.Open));
                bdos = new BufferedFile(
                    TestFileSetup.GetTargetFilename("bt2c.fits"),
                    FileAccess.ReadWrite,
                    FileShare.ReadWrite);
                f.Write(bdos);
                bdos.Close();
                bdos.Dispose();
                f.Close();

                f    = new Fits(TestFileSetup.GetTargetFilename("bt2c.fits"));
                bhdu = (BinaryTableHDU)f.GetHDU(1);
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bhdu.GetElement(3, 1), vf[3]));
                Assert.AreEqual(false, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), vf[4]));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bhdu.GetElement(4, 1), trw));
                Assert.AreEqual(true, ArrayFuncs.ArrayEquals(bhdu.GetElement(5, 1), vf[5]));
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }