public void TestSimpleIO() { Fits f = null; try { FitsFactory.UseAsciiTables = false; 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( TestFileSetup.GetTargetFilename("bt1.fits"), FileAccess.ReadWrite, FileShare.ReadWrite); f.Write(bf); bf.Flush(); bf.Close(); bf.Dispose(); f.Close(); f = new Fits(TestFileSetup.GetTargetFilename("bt1.fits")); f.Read(); Assert.AreEqual(2, f.NumberOfHDUs); BinaryTableHDU thdu = (BinaryTableHDU)f.GetHDU(1); Header hdr = thdu.Header; Assert.AreEqual(9, hdr.GetIntValue("TFIELDS")); Assert.AreEqual(2, hdr.GetIntValue("NAXIS")); Assert.AreEqual(8, hdr.GetIntValue("BITPIX")); Assert.AreEqual("BINTABLE", hdr.GetStringValue("XTENSION")); Assert.AreEqual("bytes", hdr.GetStringValue("TTYPE1")); Assert.AreEqual("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(); } } Assert.AreEqual(true, ArrayFuncs.ArrayEquals(data[i], col)); } } finally { if (f != null) { f.Close(); } } }
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 = null; try { f = new Fits(); BasicHDU hdu = Fits.MakeHDU(x); f.AddHDU(hdu); BufferedFile bf = new BufferedFile( TestFileSetup.GetTargetFilename("bt5.fits"), FileAccess.ReadWrite, FileShare.ReadWrite); f.Write(bf); bf.Close(); bf.Dispose(); /* Now get rid of some columns */ BinaryTableHDU xhdu = (BinaryTableHDU)hdu; // First column Assert.AreEqual(3, xhdu.NCols); xhdu.DeleteColumnsIndexOne(1, 1); Assert.AreEqual(2, xhdu.NCols); xhdu.DeleteColumnsIndexZero(1, 1); Assert.AreEqual(1, xhdu.NCols); bf = new BufferedFile( TestFileSetup.GetTargetFilename("bt6.fits"), FileAccess.ReadWrite, FileShare.ReadWrite); f.Write(bf); bf.Close(); bf.Dispose(); f.Close(); f = new Fits(TestFileSetup.GetTargetFilename("bt6.fits")); xhdu = (BinaryTableHDU)f.GetHDU(1); Assert.AreEqual(1, xhdu.NCols); } finally { if (f != null) { f.Close(); } } }
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(); } } }
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(); } } }
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(); } } }
public void TestRandomGroup() { //float[,] fa = new float[20,20]; float[][] fa = new float[20][]; for (int i = 0; i < fa.Length; i++) { fa[i] = new float[20]; } float[] pa = new float[3]; BufferedFile bf = new BufferedFile( TestFileSetup.GetTargetFilename("rg1.fits"), FileAccess.ReadWrite, FileShare.ReadWrite); Object[][] data = new Object[1][]; data[0] = new Object[2]; data[0][0] = pa; data[0][1] = fa; Console.Out.WriteLine("***** Write header ******"); BasicHDU hdu = Fits.MakeHDU(data); Header hdr = hdu.Header; // Change the number of groups hdr.AddValue("GCOUNT", 20, "Number of groups"); hdr.Write(bf); Console.Out.WriteLine("***** Write data group by group ******"); for (int i = 0; i < 20; i += 1) { for (int j = 0; j < pa.Length; j += 1) { pa[j] = i + j; } for (int j = 0; j < fa.GetLength(0); j += 1) { try { // fa[j, j] = i * j; fa[j][j] = i * j; } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("i ,j value:" + i + " " + j); } } // Write a group bf.WriteArray(data); } byte[] padding = new byte[FitsUtil.Padding(20 * ArrayFuncs.ComputeSize(data))]; Console.Out.WriteLine("****** Write padding ******"); bf.Write(padding); bf.Flush(); bf.Close(); bf.Dispose(); Fits f = null; try { Console.Out.WriteLine("****** Read data back in ******"); f = new Fits(TestFileSetup.GetTargetFilename("rg1.fits")); BasicHDU[] hdus = f.Read(); data = (Object[][])hdus[0].Kernel; // data = hdus[0].Kernel; Console.Out.WriteLine("**** Check parameter and data info *****"); for (int i = 0; i < data.Length; i += 1) { pa = (float[])data[i][0]; // fa = (float[,]) data[i,1]; Array[] tfa = (Array[])data[i][1]; for (int j = 0; j < pa.Length; j += 1) { Assert.AreEqual((float)(i + j), pa[j]); } for (int j = 0; j < fa.Length; j += 1) { // Assert.AreEqual("dataTest:" + i + " " + j, (float)(i * j), fa[j,j]); Assert.AreEqual((float)(i * j), ((Array)tfa.GetValue(j)).GetValue(j)); } } f.Close(); Console.Out.WriteLine("**** Create HDU from kernel *****"); f = new Fits(); // Generate a FITS HDU from the kernel. f.AddHDU(Fits.MakeHDU(data)); bf = new BufferedFile( TestFileSetup.GetTargetFilename("rg2.fits"), FileAccess.ReadWrite, FileShare.ReadWrite); Console.Out.WriteLine("**** Write new file *****"); f.Write(bf); bf.Flush(); bf.Close(); bf.Dispose(); f.Close(); Console.Out.WriteLine("**** Read and check *****"); f = new Fits(TestFileSetup.GetTargetFilename("rg2.fits")); data = (Object[][])f.Read()[0].Kernel; for (int i = 0; i < data.Length; i += 1) { pa = (float[])data[i][0]; // fa = (float[,]) data[i,1]; Array[] tfa = (Array[])data[i][1]; for (int j = 0; j < pa.Length; j += 1) { Assert.AreEqual((float)(i + j), pa[j]); } for (int j = 0; j < fa.Length; j += 1) { //Assert.AreEqual("dataTest:" + i + " " + j, (float)(i * j), fa[j,j]); Assert.AreEqual((float)(i * j), ((Array)tfa.GetValue(j)).GetValue(j)); } } } finally { if (f != null) { f.Close(); } } }
public void Initialize() { TestFileSetup.ClearAndCopyToTarget(); for (int i = 0; i < bits.Length; i++) { bits[i] = new byte[2]; } for (int i = 0; i < shorts.Length; i++) { shorts[i] = new short[3]; } for (int i = 0; i < floats.Length; i++) { floats[i] = new float[4][]; } for (int i = 0; i < floats.Length; i++) { for (int j = 0; j < floats[i].Length; j++) { floats[i][j] = new float[4]; } } for (int i = 0; i < bytes.Length; i += 1) { bytes[i] = (byte)(2 * i); bits[i][0] = bytes[i]; bits[i][1] = (byte)(~bytes[i]); bools[i] = (bytes[i] % 8) == 0 ? true : false; shorts[i][0] = (short)(2 * i); shorts[i][1] = (short)(3 * i); shorts[i][2] = (short)(4 * i); ints[i] = i * i; for (int j = 0; j < 4; j += 1) { for (int k = 0; k < 4; k += 1) { floats[i][j][k] = (float)(i + j * Math.Exp(k)); } } doubles[i] = 3 * Math.Sin(i); longs[i] = i * i * i * i; strings[i] = "abcdefghijklmnopqrstuvwxzy".Substring(0, i % 20); vf[i] = new float[i + 1]; vf[i][i / 2] = i * 3; vs[i] = new short[i / 10 + 1]; vs[i][i / 10] = (short)-i; vd[i] = new double[i % 2 == 0 ? 1 : 2]; vd[i][0] = 99.99; vbool[i] = new bool[i / 10]; if (i >= 10) { vbool[i][0] = i % 2 == 1; } } }
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(); } } }
public void SetupFixture() { TestFileSetup.ClearAndCopyToTarget(); }
public void TestCursor() { Fits f = null; try { f = new Fits(TestFileSetup.GetTargetFilename("ht1.fits")); ImageHDU hdu = (ImageHDU)f.GetHDU(0); Header hdr = hdu.Header; Cursor c = hdr.GetCursor(); c.Key = "XXX"; c.Add("CTYPE1", new HeaderCard("CTYPE1", "GLON-CAR", "Galactic Longitude")); c.Add("CTYPE2", new HeaderCard("CTYPE2", "GLAT-CAR", "Galactic Latitude")); c.Key = "CTYPE1"; // Move before CTYPE1 c.Add("CRVAL1", new HeaderCard("CRVAL1", 0f, "Longitude at reference")); c.Key = "CTYPE2"; // Move before CTYPE2 c.Add("CRVAL2", new HeaderCard("CRVAL2", -90f, "Latitude at reference")); c.Key = "CTYPE1"; // Just practicing moving around!! c.Add("CRPIX1", new HeaderCard("CRPIX1", 150.0, "Reference Pixel X")); c.Key = "CTYPE2"; c.Add("CRPIX2", new HeaderCard("CRPIX2", 0f, "Reference pixel Y")); c.Add("INV2", new HeaderCard("INV2", true, "Invertible axis")); c.Add("SYM2", new HeaderCard("SYM2", "YZ SYMMETRIC", "Symmetries...")); Assert.AreEqual("GLON-CAR", hdr.GetStringValue("CTYPE1")); Assert.AreEqual(0f, hdr.GetDoubleValue("CRPIX2", -2f)); c.Key = "CRVAL1"; HeaderCard hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assert.AreEqual("CRVAL1", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assert.AreEqual("CRPIX1", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assert.AreEqual("CTYPE1", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assert.AreEqual("CRVAL2", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assert.AreEqual("CRPIX2", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assert.AreEqual("INV2", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assert.AreEqual("SYM2", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assert.AreEqual("CTYPE2", hc.Key); hdr.FindCard("CRPIX1"); hdr.AddValue("INTVAL1", 1, "An integer value"); hdr.AddValue("LOG1", true, "A true value"); hdr.AddValue("LOGB1", false, "A false value"); hdr.AddValue("FLT1", 1.34, "A float value"); hdr.AddValue("FLT2", -1.234567890e-134, "A very long float"); hdr.AddValue("COMMENT", null, "Comment after flt2"); c.Key = "INTVAL1"; hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assert.AreEqual("INTVAL1", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assert.AreEqual("LOG1", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assert.AreEqual("LOGB1", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assert.AreEqual("FLT1", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assert.AreEqual("FLT2", hc.Key); c.MoveNext(); // Skip comment hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assert.AreEqual("CRPIX1", hc.Key); Assert.AreEqual(1.34, hdr.GetDoubleValue("FLT1", 0)); c.Key = "FLT1"; c.Remove(); Assert.AreEqual(0f, hdr.GetDoubleValue("FLT1", 0)); c.Key = "LOGB1"; hc = (HeaderCard)((DictionaryEntry)c.Current).Value; Assert.AreEqual("LOGB1", hc.Key); c.MoveNext(); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; Assert.AreEqual("FLT2", hc.Key); c.MoveNext(); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; Assert.AreEqual("Comment after flt2", hc.Comment); c.MoveNext(); } finally { if (f != null) { f.Close(); } } }
public void TestSimpleImages() { float[][] img = new float[300][]; for (int i = 0; i < 300; i++) { img[i] = new float[300]; } Fits f = null; try { f = new Fits(); ImageHDU hdu = (ImageHDU)Fits.MakeHDU(img); BufferedFile bf = new BufferedFile( TestFileSetup.GetTargetFilename("ht1.fits"), FileAccess.ReadWrite, FileShare.ReadWrite); f.AddHDU(hdu); f.Write(bf); bf.Close(); bf.Dispose(); f.Close(); f = new Fits(TestFileSetup.GetTargetFilename("ht1.fits")); hdu = (ImageHDU)f.GetHDU(0); Header hdr = hdu.Header; Assert.AreEqual(2, hdr.GetIntValue("NAXIS")); Assert.AreEqual(300, hdr.GetIntValue("NAXIS1")); Assert.AreEqual(300, hdr.GetIntValue("NAXIS2")); Assert.AreEqual(300, hdr.GetIntValue("NAXIS2", -1)); Assert.AreEqual(-1, hdr.GetIntValue("NAXIS3", -1)); Assert.AreEqual(-32, hdr.GetIntValue("BITPIX")); Cursor c = hdr.GetCursor(); c.MoveNext(); HeaderCard hc = (HeaderCard)((DictionaryEntry)c.Current).Value; Assert.AreEqual("SIMPLE", hc.Key); c.MoveNext(); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; Assert.AreEqual("BITPIX", hc.Key); c.MoveNext(); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; Assert.AreEqual("NAXIS", hc.Key); c.MoveNext(); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; Assert.AreEqual("NAXIS1", hc.Key); c.MoveNext(); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; Assert.AreEqual("NAXIS2", hc.Key); } finally { if (f != null) { f.Close(); } } }
public void TestBufferedFile() { string[] args = new string[1]; args[0] = TestFileSetup.GetTargetFilename("nph-im.fits"); System.String filename = args[0]; int dim = 1000; if (args.Length > 1) { dim = System.Int32.Parse(args[1]); } int numIts = 1; if (args.Length > 2) { numIts = System.Int32.Parse(args[2]); } System.Console.Out.WriteLine("Allocating arrays."); double[] db = new double[dim]; float[] fl = new float[dim]; int[] in_Renamed = new int[dim]; long[] ln = new long[dim]; short[] sh = new short[dim]; byte[] by = new byte[dim]; char[] ch = new char[dim]; bool[] bl = new bool[dim]; System.Console.Out.WriteLine("Initializing arrays -- may take a while"); int sign = 1; for (int i = 0; i < dim; i += 1) { double x = sign * System.Math.Pow(10.0, 20 * SupportClass.Random.NextDouble() - 10); db[i] = x; fl[i] = (float)x; if (System.Math.Abs(x) < 1) { x = 1 / x; } in_Renamed[i] = (int)x; ln[i] = (long)x; sh[i] = (short)x; by[i] = (byte)x; //ch[i] = (char) x; ch[i] = SupportClass.NextChar(); bl[i] = x > 0; sign = -sign; } // Ensure special values are tested. by[0] = (byte)System.Byte.MinValue; by[1] = (byte)System.Byte.MaxValue; by[2] = 0; ch[0] = System.Char.MinValue; ch[1] = System.Char.MaxValue; ch[2] = (char)(0); sh[0] = System.Int16.MaxValue; sh[1] = System.Int16.MinValue; sh[0] = 0; in_Renamed[0] = System.Int32.MaxValue; in_Renamed[1] = System.Int32.MinValue; in_Renamed[2] = 0; ln[0] = System.Int64.MinValue; ln[1] = System.Int64.MaxValue; ln[2] = 0; fl[0] = System.Single.Epsilon; fl[1] = System.Single.MaxValue; fl[2] = System.Single.PositiveInfinity; fl[3] = System.Single.NegativeInfinity; fl[4] = System.Single.NaN; fl[5] = 0; db[0] = System.Double.MinValue; db[1] = System.Double.MaxValue; db[2] = System.Double.PositiveInfinity; db[3] = System.Double.NegativeInfinity; db[4] = System.Double.NaN; db[5] = 0; double[] db2 = new double[dim]; float[] fl2 = new float[dim]; int[] in2 = new int[dim]; long[] ln2 = new long[dim]; short[] sh2 = new short[dim]; byte[] by2 = new byte[dim]; char[] ch2 = new char[dim]; bool[] bl2 = new bool[dim]; int[][][][] multi = new int[10][][][]; for (int i2 = 0; i2 < 10; i2++) { multi[i2] = new int[10][][]; for (int i3 = 0; i3 < 10; i3++) { multi[i2][i3] = new int[10][]; for (int i4 = 0; i4 < 10; i4++) { multi[i2][i3][i4] = new int[10]; } } } int[][][][] multi2 = new int[10][][][]; for (int i5 = 0; i5 < 10; i5++) { multi2[i5] = new int[10][][]; for (int i6 = 0; i6 < 10; i6++) { multi2[i5][i6] = new int[10][]; for (int i7 = 0; i7 < 10; i7++) { multi2[i5][i6][i7] = new int[10]; } } } for (int i = 0; i < 10; i += 1) { multi[i][i][i][i] = i; } if (args.Length < 4 || args[3].IndexOf((System.Char) 'O') >= 0) { standardFileTest(filename, numIts, in_Renamed, in2); standardStreamTest(filename, numIts, in_Renamed, in2); } /* if (args.Length < 4 || args[3].IndexOf((System.Char) 'X') >= 0) * { * buffStreamSimpleTest(filename, numIts, in_Renamed, in2); * } */ if (args.Length < 4 || args[3].IndexOf((System.Char) 'R') >= 0) { bufferedFileTest(filename, numIts, db, db2, fl, fl2, ln, ln2, in_Renamed, in2, sh, sh2, ch, ch2, by, by2, bl, bl2, multi, multi2); } if (args.Length < 4 || args[3].IndexOf((System.Char) 'S') >= 0) { bufferedStreamTest(filename, numIts, db, db2, fl, fl2, ln, ln2, in_Renamed, in2, sh, sh2, ch, ch2, by, by2, bl, bl2, multi, multi2); } }