public void TestReadBuffered() { string filename = TestFileSetup.GetTargetFilename("test.fits"); BufferedFile bf = new BufferedFile( filename, FileAccess.Read, FileShare.None); Header h = Header.ReadHeader(bf); long n = h.DataSize; int naxes = h.GetIntValue("NAXIS"); int lastAxis = h.GetIntValue("NAXIS" + naxes); HeaderCard hnew = new HeaderCard("NAXIS", naxes - 1, "this is header card with naxes"); h.AddCard(hnew); float[] line = new float[h.DataSize]; for (int i = 0; i < lastAxis; i += 1) { Console.Out.WriteLine("read"); bf.Read(line); } bf.Close(); bf.Dispose(); }
public void TestLongDoubles() { // Check to see if we make long double values fit in the recommended space. HeaderCard hc = new HeaderCard("TEST", -1.234567890123456789E-123, "dummy"); String val = hc.Value; Assert.AreEqual(val.Length, 20); }
public void TestSimpleImages() { float[][] img = new float[300][]; for (int i = 0; i < 300; i++) { img[i] = new float[300]; } Fits f = new Fits(); ImageHDU hdu = (ImageHDU)Fits.MakeHDU(img); BufferedFile bf = new BufferedFile("ht1.fits", FileAccess.ReadWrite, FileShare.ReadWrite); f.AddHDU(hdu); f.Write(bf); bf.Close(); f = new Fits("ht1.fits"); hdu = (ImageHDU)f.GetHDU(0); Header hdr = hdu.Header; Assertion.AssertEquals("NAXIS", 2, hdr.GetIntValue("NAXIS")); Assertion.AssertEquals("NAXIS1", 300, hdr.GetIntValue("NAXIS1")); Assertion.AssertEquals("NAXIS2", 300, hdr.GetIntValue("NAXIS2")); Assertion.AssertEquals("NAXIS2a", 300, hdr.GetIntValue("NAXIS2", -1)); Assertion.AssertEquals("NAXIS3", -1, hdr.GetIntValue("NAXIS3", -1)); Assertion.AssertEquals("BITPIX", -32, hdr.GetIntValue("BITPIX")); Cursor c = hdr.GetCursor(); c.MoveNext(); HeaderCard hc = (HeaderCard)((DictionaryEntry)c.Current).Value; Assertion.AssertEquals("SIMPLE_1", "SIMPLE", hc.Key); c.MoveNext(); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; Assertion.AssertEquals("BITPIX_2", "BITPIX", hc.Key); c.MoveNext(); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; Assertion.AssertEquals("NAXIS_3", "NAXIS", hc.Key); c.MoveNext(); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; Assertion.AssertEquals("NAXIS1_4", "NAXIS1", hc.Key); c.MoveNext(); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; Assertion.AssertEquals("NAXIS2_5", "NAXIS2", hc.Key); f.Close(); }
protected static Header ManufactureHeader(Array[] row, String[] columnNames, Object[] tnull, int nRows) { Header hdr = new Header(); Object[][] table = new Object[1][]; table[0] = row; new BinaryTable(table).FillHeader(hdr); if (columnNames == null) { columnNames = new String[row.Length]; for (int i = 0; i < columnNames.Length; ++i) { columnNames[i] = "Column" + (i + 1); } } for (HeaderCard c = hdr.NextCard(); c != null; c = hdr.NextCard()) { ; } Type t = null; for (int i = 0; i < columnNames.Length; ++i) { if (!hdr.ContainsKey("TTYPE" + (i + 1))) { hdr.AddLine(new HeaderCard("TTYPE" + (i + 1), columnNames[i], null)); } t = row[i].GetType(); if (t == typeof(short[])) { hdr.AddLine(new HeaderCard("TNULL" + (i + 1), (short)tnull[i], null)); } else if (t == typeof(int[])) { hdr.AddLine(new HeaderCard("TNULL" + (i + 1), (int)tnull[i], null)); } else if (t == typeof(long[])) { hdr.AddLine(new HeaderCard("TNULL" + (i + 1), (long)tnull[i], null)); } } hdr.RemoveCard("NAXIS2"); hdr.SetNaxis(2, nRows); return(hdr); }
public void Test3() { HeaderCard p = new HeaderCard("KEY", "VALUE", "COMMENT"); Assert.AreEqual( "KEY = 'VALUE ' / COMMENT ", p.ToString()); p = new HeaderCard("KEY", 123, "COMMENT"); Assert.AreEqual( "KEY = 123 / COMMENT ", p.ToString()); p = new HeaderCard("KEY", 1.23, "COMMENT"); Assert.AreEqual( "KEY = 1.23 / COMMENT ", p.ToString()); p = new HeaderCard("KEY", true, "COMMENT"); Assert.AreEqual( "KEY = T / COMMENT ", p.ToString()); bool thrown = false; try { p = new HeaderCard("LONGKEYWORD", 123, "COMMENT"); } catch (Exception e) { thrown = true; } Assert.AreEqual(true, thrown); thrown = false; String lng = "00000000001111111111222222222233333333334444444444555555555566666666667777777777"; try { p = new HeaderCard("KEY", lng, "COMMENT"); } catch (Exception e) { thrown = true; } Assert.AreEqual(true, thrown); }
public void TestReadBuffered() { BufferedFile bf = new BufferedFile("E:\\CSharpFITSIO\\LAB-2.0kms.fits", FileAccess.Read, FileShare.None); Header h = Header.ReadHeader(bf); long n = h.DataSize; int naxes = h.GetIntValue("NAXIS"); int lastAxis = h.GetIntValue("NAXIS"+naxes); HeaderCard hnew= new HeaderCard("NAXIS", naxes - 1,"this is header card with naxes"); h.AddCard(hnew); float[] line = new float[h.DataSize]; for (int i = 0; i < lastAxis; i += 1) { Console.Out.WriteLine("read"); bf.Read(line); } }
/// <summary>Create a header and initialize it with a vector of strings.</summary> /// <param name="newCards">Card images to be placed in the header.</param> public Header(String[] newCards) { InitBlock(); for(int i = 0; i < newCards.Length; i += 1) { HeaderCard card = new HeaderCard(newCards[i]); if(card.Value == null) { cards.Add(card); } else { cards.Add(card.Key, card); } } }
public void Test3() { HeaderCard p = new HeaderCard("KEY", "VALUE", "COMMENT"); Assertion.AssertEquals("x1", "KEY = 'VALUE ' / COMMENT ", p.ToString()); p = new HeaderCard("KEY", 123, "COMMENT"); Assertion.AssertEquals("x2", "KEY = 123 / COMMENT ", p.ToString()); p = new HeaderCard("KEY", 1.23, "COMMENT"); Assertion.AssertEquals("x3", "KEY = 1.23 / COMMENT ", p.ToString()); p = new HeaderCard("KEY", true, "COMMENT"); Assertion.AssertEquals("x4", "KEY = T / COMMENT ", p.ToString()); bool thrown = false; try { p = new HeaderCard("LONGKEYWORD", 123, "COMMENT"); } catch (Exception ) { thrown = true; } Assertion.AssertEquals("x5", true, thrown); thrown = false; String lng = "00000000001111111111222222222233333333334444444444555555555566666666667777777777"; try { p = new HeaderCard("KEY", lng, "COMMENT"); } catch (Exception ) { thrown = true; } Assertion.AssertEquals("x6", true, thrown); }
public void Test1() { HeaderCard p; p = new HeaderCard("SIMPLE = T"); Assertion.AssertEquals("t1", "SIMPLE", p.Key); Assertion.AssertEquals("t2", "T", p.Value); Assertion.AssertNull("t3", p.Comment); p = new HeaderCard("VALUE = 123"); Assertion.AssertEquals("t4", "VALUE", p.Key); Assertion.AssertEquals("t5", "123", p.Value); Assertion.AssertNull("t3", p.Comment); p = new HeaderCard("VALUE = 1.23698789798798E23 / Comment "); Assertion.AssertEquals("t6", "VALUE", p.Key); Assertion.AssertEquals("t7", "1.23698789798798E23", p.Value); Assertion.AssertEquals("t8", "Comment", p.Comment); String lng = "111111111111111111111111111111111111111111111111111111111111111111111111"; p = new HeaderCard("COMMENT " + lng); Assertion.AssertEquals("t9", "COMMENT", p.Key); Assertion.AssertNull("t10", p.Value); Assertion.AssertEquals("t11", lng, p.Comment); bool thrown = false; try { // p = new HeaderCard("VALUE = ' "); } catch (Exception) { thrown = true; } Assertion.AssertEquals("t12", true, thrown); p = new HeaderCard("COMMENT " + lng + lng); Assertion.AssertEquals("t13", lng, p.Comment); }
public void Test1() { HeaderCard p; p = new HeaderCard("SIMPLE = T"); Assert.AreEqual("SIMPLE", p.Key); Assert.AreEqual("T", p.Value); Assert.IsNull(p.Comment); p = new HeaderCard("VALUE = 123"); Assert.AreEqual("VALUE", p.Key); Assert.AreEqual("123", p.Value); Assert.IsNull(p.Comment); p = new HeaderCard("VALUE = 1.23698789798798E23 / Comment "); Assert.AreEqual("VALUE", p.Key); Assert.AreEqual("1.23698789798798E23", p.Value); Assert.AreEqual("Comment", p.Comment); String lng = "111111111111111111111111111111111111111111111111111111111111111111111111"; p = new HeaderCard("COMMENT " + lng); Assert.AreEqual("COMMENT", p.Key); Assert.IsNull(p.Value); Assert.AreEqual(lng, p.Comment); bool thrown = false; try { // p = new HeaderCard("VALUE = ' "); } catch (Exception e) { thrown = true; } Assert.AreEqual(true, thrown); p = new HeaderCard("COMMENT " + lng + lng); Assert.AreEqual(lng, p.Comment); }
public void TestReadBuffered() { String file = Path.GetTempFileName(); File.Copy("..\\..\\testdocs\\ht1.fits", file, true); BufferedFile bf = new BufferedFile(file, FileAccess.Read, FileShare.None); Header h = Header.ReadHeader(bf); long n = h.DataSize; int naxes = h.GetIntValue("NAXIS"); int lastAxis = h.GetIntValue("NAXIS"+naxes); HeaderCard hnew= new HeaderCard("NAXIS", naxes - 1,"this is header card with naxes"); h.AddCard(hnew); float[] line = new float[h.DataSize]; for (int i = 0; i < lastAxis; i += 1) { Console.Out.WriteLine("read"); bf.Read(line); } }
public void TestReadBuffered() { String file = Path.GetTempFileName(); File.Copy("testdocs\\ht1.fits", file, true); BufferedFile bf = new BufferedFile(file, FileAccess.Read, FileShare.None); Header h = Header.ReadHeader(bf); long n = h.DataSize; int naxes = h.GetIntValue("NAXIS"); int lastAxis = h.GetIntValue("NAXIS" + naxes); HeaderCard hnew = new HeaderCard("NAXIS", naxes - 1, "this is header card with naxes"); h.AddCard(hnew); float[] line = new float[h.DataSize]; for (int i = 0; i < lastAxis; i += 1) { Console.Out.WriteLine("read"); bf.Read(line); } }
public void Test1() { HeaderCard p; p = new HeaderCard("SIMPLE = T"); Assertion.AssertEquals("t1", "SIMPLE", p.Key); Assertion.AssertEquals("t2", "T", p.Value); Assertion.AssertNull("t3", p.Comment); p = new HeaderCard("VALUE = 123"); Assertion.AssertEquals("t4", "VALUE", p.Key); Assertion.AssertEquals("t5", "123", p.Value); Assertion.AssertNull("t3", p.Comment); p = new HeaderCard("VALUE = 1.23698789798798E23 / Comment "); Assertion.AssertEquals("t6", "VALUE", p.Key); Assertion.AssertEquals("t7", "1.23698789798798E23", p.Value); Assertion.AssertEquals("t8", "Comment", p.Comment); String lng = "111111111111111111111111111111111111111111111111111111111111111111111111"; p = new HeaderCard("COMMENT " + lng); Assertion.AssertEquals("t9", "COMMENT", p.Key); Assertion.AssertNull("t10", p.Value); Assertion.AssertEquals("t11", lng, p.Comment); bool thrown = false; try { // p = new HeaderCard("VALUE = ' "); } catch (Exception ) { thrown = true; } Assertion.AssertEquals("t12", true, thrown); p = new HeaderCard("COMMENT " + lng + lng); Assertion.AssertEquals("t13", lng, p.Comment); }
public void TestHierarch() { HeaderCard hc; String key = "HIERARCH.TEST1.TEST2.INT"; bool thrown = false; try { hc = new HeaderCard(key, 123, "Comment"); } catch (Exception) { thrown = true; } Assertion.AssertEquals("h1", true, thrown); String card = "HIERARCH TEST1 TEST2 INT= 123 / Comment "; hc = new HeaderCard(card); Assertion.AssertEquals("h2", "HIERARCH", hc.Key); Assertion.AssertNull("h3", hc.Value); Assertion.AssertEquals("h4", "TEST1 TEST2 INT= 123 / Comment", hc.Comment); FitsFactory.UseHierarch = true; hc = new HeaderCard(key, 123, "Comment"); Assertion.AssertEquals("h5", key, hc.Key); Assertion.AssertEquals("h6", "123", hc.Value); Assertion.AssertEquals("h7", "Comment", hc.Comment); hc = new HeaderCard(card); Assertion.AssertEquals("h8", key, hc.Key); Assertion.AssertEquals("h9", "123", hc.Value); Assertion.AssertEquals("h10", "Comment", hc.Comment); }
public void TestHierarch() { HeaderCard hc; String key = "HIERARCH.TEST1.TEST2.INT"; bool thrown = false; try { hc = new HeaderCard(key, 123, "Comment"); } catch (Exception e) { thrown = true; } Assert.AreEqual(true, thrown); String card = "HIERARCH TEST1 TEST2 INT= 123 / Comment "; hc = new HeaderCard(card); Assert.AreEqual("HIERARCH", hc.Key); Assert.IsNull(hc.Value); Assert.AreEqual("TEST1 TEST2 INT= 123 / Comment", hc.Comment); FitsFactory.UseHierarch = true; hc = new HeaderCard(key, 123, "Comment"); Assert.AreEqual(key, hc.Key); Assert.AreEqual("123", hc.Value); Assert.AreEqual("Comment", hc.Comment); hc = new HeaderCard(card); Assert.AreEqual(key, hc.Key); Assert.AreEqual("123", hc.Value); Assert.AreEqual("Comment", hc.Comment); }
// change suggested in .99.1 version: Method made public from protected. /// <summary>Add a card image to the header.</summary> /// <param name="fcard">The card to be added.</param> /// FIX THIS public virtual void AddLine(HeaderCard fcard) { if (fcard != null) { if (fcard.KeyValuePair) { cursor.Add(fcard.Key, fcard); } else { cursor.Add(fcard); } } }
/// <summary>Adds card to the end of the HeaderCard list</summary> /// <param name="card">The card to be added</param> public virtual void AddCard(HeaderCard card) { // if(card != null) // { RemoveCard(card.Key); // Cursor c = cards.GetCursor(); // while(c.MoveNext()); cursor.Add(card.Key, card); // } }
// change suggested in .99.1 version: Method added. /// <summary>Update a line in the header.</summary> /// <param name="key">The key of the card to be replaced.</param> /// <param name="card">A new card.</param> public void UpdateLine(String key, HeaderCard card) { RemoveCard(key); cursor.Add(key,card); }
/// <summary> /// Removes card from the HeaderCard list /// </summary> /// <param name="card">The card to be removed</param> public virtual void RemoveCard(HeaderCard card) { if(card == null) { return; } Cursor c = cards.GetCursor(); for(bool done = false; !done && c.MoveNext();) { HeaderCard hc = (HeaderCard)((DictionaryEntry)c.Current).Value; if(card.Equals(hc)) { c.Remove(); done = true; } } }
/// <summary> /// Inserts card in front of posCard in the HeaderCard list. /// If posCard is null, card is added to the end of the list. /// </summary> /// <param name="card">The HeaderCard to be inserted</param> /// <param name="posCard">The HeaderCard in front of which card is to be inserted</param> public virtual void InsertCard(HeaderCard card, HeaderCard posCard) { if(card == null) { return; } if(posCard == null) { AddCard(card); return; } Cursor c = cards.GetCursor(); for(c.MoveNext(); c.Current != null && !((DictionaryEntry)c.Current).Value.Equals(posCard) && c.MoveNext();); if(c.Current == null) { AddCard(card); } else { c.Insert(card.Key, card); } }
public void TestCursor() { Fits f = new Fits("testdocs\\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...")); Assertion.AssertEquals("CTYPE1", "GLON-CAR", hdr.GetStringValue("CTYPE1")); Assertion.AssertEquals("CRPIX2", 0f, hdr.GetDoubleValue("CRPIX2", -2f)); c.Key = "CRVAL1"; HeaderCard hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assertion.AssertEquals("CRVAL1_c", "CRVAL1", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assertion.AssertEquals("CRPIX1_c", "CRPIX1", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assertion.AssertEquals("CTYPE1_c", "CTYPE1", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assertion.AssertEquals("CRVAL2_c", "CRVAL2", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assertion.AssertEquals("CRPIX2_c", "CRPIX2", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assertion.AssertEquals("INV2_c", "INV2", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assertion.AssertEquals("SYM2_c", "SYM2", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assertion.AssertEquals("CTYPE2_c", "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(); Assertion.AssertEquals("INTVAL1", "INTVAL1", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assertion.AssertEquals("LOG1", "LOG1", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assertion.AssertEquals("LOGB1", "LOGB1", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assertion.AssertEquals("FLT1", "FLT1", hc.Key); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assertion.AssertEquals("FLT2", "FLT2", hc.Key); c.MoveNext(); // Skip comment hc = (HeaderCard)((DictionaryEntry)c.Current).Value; c.MoveNext(); Assertion.AssertEquals("CRPIX1x", "CRPIX1", hc.Key); Assertion.AssertEquals("FLT1", 1.34, hdr.GetDoubleValue("FLT1", 0)); c.Key = "FLT1"; c.Remove(); Assertion.AssertEquals("FLT1", 0f, hdr.GetDoubleValue("FLT1", 0)); c.Key = "LOGB1"; hc = (HeaderCard)((DictionaryEntry)c.Current).Value; Assertion.AssertEquals("AftDel1", "LOGB1", hc.Key); c.MoveNext(); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; Assertion.AssertEquals("AftDel2", "FLT2", hc.Key); c.MoveNext(); hc = (HeaderCard)((DictionaryEntry)c.Current).Value; Assertion.AssertEquals("AftDel3", "Comment after flt2", hc.Comment); c.MoveNext(); f.Close(); }
/// <summary> /// Creates a new HeaderCard to accommodate comment, /// and inserts the new HeaderCard in front of posCard in the HeaderCard list. /// If posCard is null, the new HeaderCard is added to the end of the list. /// </summary> /// <param name="history">The history of the new HeaderCard</param> /// <param name="posCard">The HeaderCard in front of which the new HeaderCard is to be inserted</param> public virtual void InsertHistory(String history, HeaderCard posCard) { InsertCard(new HeaderCard("HISTORY", null, history), posCard); }
public void TestHierarch() { HeaderCard hc; String key = "HIERARCH.TEST1.TEST2.INT"; bool thrown = false; try { hc = new HeaderCard(key, 123, "Comment"); } catch (Exception ) { thrown = true; } Assertion.AssertEquals("h1", true, thrown); String card = "HIERARCH TEST1 TEST2 INT= 123 / Comment "; hc = new HeaderCard(card); Assertion.AssertEquals("h2", "HIERARCH", hc.Key); Assertion.AssertNull("h3", hc.Value); Assertion.AssertEquals("h4", "TEST1 TEST2 INT= 123 / Comment", hc.Comment); FitsFactory.UseHierarch = true; hc = new HeaderCard(key, 123, "Comment"); Assertion.AssertEquals("h5", key, hc.Key); Assertion.AssertEquals("h6", "123", hc.Value); Assertion.AssertEquals("h7", "Comment", hc.Comment); hc = new HeaderCard(card); Assertion.AssertEquals("h8", key, hc.Key); Assertion.AssertEquals("h9", "123", hc.Value); Assertion.AssertEquals("h10", "Comment", hc.Comment); }
public void TestLongDoubles() { // Check to see if we make long double values fit in the recommended space. HeaderCard hc = new HeaderCard("TEST", -1.234567890123456789E-123, "dummy"); String val = hc.Value; Assertion.AssertEquals("tld1", val.Length, 20); }
/// <summary> /// Inserts card at the pos'th position in the HeaderCard list. /// If pos is out of the bounds of the list, /// card will be added to the end of the list. /// </summary> /// <param name="card">The HeaderCard to be inserted</param> /// <param name="pos">The list position into which to insert card</param> public virtual void InsertCard(HeaderCard card, int pos) { HeaderCard c = null; try { c = (HeaderCard)cards[cards[pos]]; } catch(Exception) { c = null; } InsertCard(card, c); }
/// <summary> /// Inserts card in front of the HeaderCard associated with key posKey. /// If there is no HeaderCard associated with posKey, /// card is added to the end of the HeaderCard list /// </summary> /// <param name="card">The card to be inserted</param> /// <param name="posKey">The key of the HeaderCard in front of which card is to be inserted</param> public virtual void InsertCard(HeaderCard card, String posKey) { InsertCard(card, FindCard(posKey)); }
/// <summary> /// Creates a new HeaderCard to accommodate key, val, and comment, /// and inserts the new HeaderCard in front of posCard in the HeaderCard list. /// If posCard is null, the new HeaderCard is added to the end of the list. /// </summary> /// <param name="key">The key of the new HeaderCard</param> /// <param name="val">The value of the new HeaderCard</param> /// <param name="comment">The comment of the new HeaderCard</param> /// <param name="posCard">The HeaderCard in front of which the new HeaderCard is to be inserted</param> public virtual void InsertValue(String key, double val, String comment, HeaderCard posCard) { InsertCard(new HeaderCard(key, val, comment), posCard); }
/// <summary> /// Creates a new HeaderCard to accommodate comment, /// and inserts the new HeaderCard in front of posCard in the HeaderCard list. /// If posCard is null, the new HeaderCard is added to the end of the list. /// </summary> /// <param name="comment">The comment of the new HeaderCard</param> /// <param name="posCard">The HeaderCard in front of which the new HeaderCard is to be inserted</param> public virtual void InsertComment(String comment, HeaderCard posCard) { InsertCard(new HeaderCard("COMMENT", null, comment), posCard); }
/// <summary>Read a stream for header data.</summary> /// <param name="dis">The input stream to read the data from.</param> /// <returns> <CODE>null</CODE> if there was a problem with the header; /// otherwise return the header read from the input stream.</returns> /// <exception cref="TruncatedFileException"> </exception>" public virtual void Read(ArrayDataIO dis) { if (dis is RandomAccess) { fileOffset = FitsUtil.FindOffset(dis); } else { fileOffset = - 1; } byte[] buffer = new byte[80]; bool firstCard = true; int count = 0; bool notEnd = true; while(notEnd) { int need = 80; // try // { for(int len = 1; need > 0 && len > 0;) { len = dis.Read(buffer, 80 - need, need); count += 1; if(firstCard && len == 0 && need == 80) { throw new EndOfStreamException(); } need -= len; } // } // catch(EndOfStreamException e) // { // // Rethrow the EOF if we are at the beginning of the header, // // otherwise we have a FITS error. // if(firstCard && need == 80) // { // throw e; // } // throw new TruncatedFileException(e.Message); // } String cbuf = new String(SupportClass.ToCharArray(buffer)); HeaderCard fcard = new HeaderCard(cbuf); if(firstCard) { String key = fcard.Key; //Console.Out.WriteLine("key = '" + key + "'"); if(key == null || (!key.Equals("SIMPLE") && !key.Equals("XTENSION"))) { throw new IOException("Not FITS format at " + fileOffset + ":" + cbuf); } firstCard = false; } String key2 = fcard.Key; if(key2 != null && cards.ContainsKey(key2)) { Console.Error.WriteLine("Warning: multiple occurrences of key:" + key2); } // save card AddLine(fcard); if (cbuf.Substring(0, (8) - (0)).Equals("END ")) { notEnd = false; } } if (fileOffset >= 0) { oldSize = cards.Count; input = dis; } // Read to the end of the current FITS block. try { if(dis.CanSeek) { dis.Seek(FitsUtil.Padding(count * 80)); } else { int pad = FitsUtil.Padding(count * 80); for (int len = dis.Read(buffer, 0, Math.Min(pad, buffer.Length)); pad > 0 && len != -1; ) { pad -= len; len = dis.Read(buffer, 0, Math.Min(pad, buffer.Length)); } } } catch(IOException e) { throw new TruncatedFileException(e.Message); } }
public HeaderEntry(HeaderCard card) { Card = card; }
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(); } } }