Beispiel #1
0
        public void ModifyTable()
        {
            Fits f = null;

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

                Object[] samp = GetSampleCols();

                AsciiTableHDU hdu  = (AsciiTableHDU)f.GetHDU(1);
                AsciiTable    data = (AsciiTable)hdu.GetData();
                float[]       f1   = (float[])data.GetColumn(0);
                float[]       f2   = (float[])f1.Clone();
                for (int i = 0; i < f2.Length; i += 1)
                {
                    f2[i] = 2 * f2[i];
                }

                data.SetColumn(0, f2);
                f1 = new float[] { 3.14159f };
                data.SetElement(3, 0, f1);

                hdu.SetNullString(0, "**INVALID**");
                data.SetNull(5, 0, true);
                data.SetNull(6, 0, true);

                Object[] row = new Object[5];
                row[0] = new float[] { 6.28f };
                row[1] = new int[] { 22 };
                row[2] = new long[] { 0 };
                row[3] = new double[] { -3 };
                row[4] = new String[] { "A string" };

                data.SetRow(5, row);

                data.SetElement(4, 2, new long[] { 54321 });

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

                f = new Fits(TestFileSetup.GetTargetFilename("at1x.fits"), FileAccess.Read);
                AsciiTable tab = (AsciiTable)f.GetHDU(1).Data;

                Object[] kern = (Object[])tab.Kernel;

                float[]  fx = (float[])kern[0];
                int[]    ix = (int[])kern[1];
                long[]   lx = (long[])kern[2];
                double[] dx = (double[])kern[3];
                String[] sx = (String[])kern[4];

                float[]  fy = (float[])samp[0];
                int[]    iy = (int[])samp[1];
                long[]   ly = (long[])samp[2];
                double[] dy = (double[])samp[3];
                String[] sy = (String[])samp[4];

                Assert.AreEqual(true, tab.IsNull(6, 0));
                Assert.AreEqual(false, tab.IsNull(5, 0));

                for (int i = 0; i < data.NRows; i += 1)
                {
                    if (i != 5)
                    {
                        if (i != 6)
                        {
                            // Null
                            Assert.AreEqual(1f, f2[i] / fx[i], Math.Pow(10, -6));
                        }
                        Assert.AreEqual(iy[i], ix[i]);

                        if (i == 4)
                        {
                            Assert.AreEqual(54321L, lx[i]);
                        }
                        else
                        {
                            Assert.AreEqual(ly[i], lx[i]);
                        }

                        Assert.AreEqual(1f, dy[i] / dx[i], Math.Pow(10, -14));
                        Assert.AreEqual(sy[i], sx[i].Trim());
                    }
                }
                Object[] r5 = (Object[])data.GetRow(5);
                String[] st = (String[])r5[4];
                st[0] = st[0].Trim();
                for (int i = 0; i < r5.Length; i++)
                {
                    Assert.AreEqual(true, ArrayFuncs.ArrayEquals(row[i], r5[i], Math.Pow(10, -6), Math.Pow(10, -14)));
                }
            }
            finally
            {
                if (f != null)
                {
                    f.Close();
                }
            }
        }
 /// <summary>See if an element is null</summary>
 public virtual bool IsNull(int row, int col)
 {
     return(data.IsNull(row, col));
 }