Esempio n. 1
0
        // change suggested in .99.1 version: Method added.
        /// <summary>
        /// Overwrite the lines in the header.
        /// Add the new PHDU header to the current one. If keywords appear
        /// twice, the new value and comment overwrite the current contents.
        /// </summary>
        /// <param name="newHdr">the list of new header data lines to replace the current ones.</param>
        public void UpdateLines(Header newHdr)
        {
            Cursor j = newHdr.GetCursor();

              while (j.MoveNext())
              {
            HeaderCard nextHCard = (HeaderCard)j.Current;

            // updateLine() doesn't work with COMMENTs because
            // this would allow only one COMMENT in total in each header
            if( nextHCard.Key.StartsWith("COMMENT") )
            {
              InsertComment(nextHCard.Comment, cards.Count);
            }
            else
            {
              UpdateLine(nextHCard.Key, nextHCard);
            }
              }
        }
Esempio n. 2
0
 /// <summary> Update the header to reflect information about a given column.
 /// This routine tries to ensure that the Header is organized by column.</summary>
 internal void PointToColumn(int col, Header hdr)
 {
     Cursor c = hdr.GetCursor();
     if(col > 0)
     {
         hdr.PositionAfterIndex("TFORM", col);
     }
     FillForColumn(hdr, col, c);
 }
Esempio n. 3
0
        /// <summary> Update a FITS header to reflect the current state of the data.</summary>
        internal override void FillHeader(Header h)
        {
            try
            {
                h.Xtension = "BINTABLE";
                h.Bitpix = 8;
                h.Naxes = 2;
                h.SetNaxis(1, rowLen);
                h.SetNaxis(2, nRow);
                h.AddValue("PCOUNT", heap.Size, null);
                h.AddValue("GCOUNT", 1, null);
                Cursor c = h.GetCursor();
                c.Key = "GCOUNT";
                c.MoveNext();
                c.Add("TFIELDS", new HeaderCard("TFIELDS", modelRow.Length, null));

                for(int i = 0; i < modelRow.Length; i += 1)
                {
                    if(i > 0)
                    {
                        h.PositionAfterIndex("TFORM", i);
                    }
                    FillForColumn(h, i, c);
                }
            }
            catch(HeaderCardException)
            {
                Console.Error.WriteLine("Impossible exception");
            }
        }
Esempio n. 4
0
 /// <summary>Create a header to match the input data.</summary>
 public static Header ManufactureHeader(Data d)
 {
     Header hdr = new Header();
     d.FillHeader(hdr);
     Cursor c = hdr.GetCursor();
     return hdr;
 }
Esempio n. 5
0
        /// <summary>
        /// writes the header to fits file
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="filename"></param>
        /// <param name="writeMode"></param>
        /// <param name="stringTruncationLength"></param>
        /// <param name="padStringsLeft"></param>
        /// <param name="stringPadChar"></param>
        public static void Write(IDataReader reader, String filename,
                                StreamedBinaryTableHDU.StringWriteMode writeMode, int stringTruncationLength,
                                bool padStringsLeft, char stringPadChar)
        {
            Header header = new Header();
              header.Simple = true;
              header.Bitpix = 8;
              header.Naxes = 0;

              Cursor c = header.GetCursor();
              // move to the end of the header cards
              for(c.MoveNext(); c.MoveNext(););
              // we know EXTEND isn't there yet
              c.Add("EXTEND", new HeaderCard("EXTEND", true, null));

              ImageHDU hdu1 = new ImageHDU(header, null);

              StreamedBinaryTableHDU hdu2 =
            new StreamedBinaryTableHDU(new DataReaderAdapter(reader), 4096,
            writeMode, stringTruncationLength, padStringsLeft, stringPadChar);

              Fits fits = new Fits();
              fits.AddHDU(hdu1);
              fits.AddHDU(hdu2);

              Stream s = null;
              try
              {
            s = new FileStream(filename, FileMode.Create);
            fits.Write(s);
            s.Close();
              }
              catch(Exception e)
              {
            s.Close();
            throw(e);
              }
        }
Esempio n. 6
0
        public frmChooseTimeHeaders(Header hdr, string filesHash)
            : this()
        {
            m_FilesHash = filesHash;

            var hasher = new SHA1CryptoServiceProvider();
            hasher.Initialize();
            var orderedCardNames = new List<string>();

            var cursor = hdr.GetCursor();
            while (cursor.MoveNext())
            {
                var card = hdr.FindCard((string)cursor.Key);
                if (card != null)
                {
                    m_AllCards.Add(new HeaderEntry(card));
                }
                orderedCardNames.Add((string) cursor.Key);
            }

            orderedCardNames.Sort();
            byte[] combinedCardNamesBytes = Encoding.UTF8.GetBytes(string.Join("|", orderedCardNames));
            var hash = hasher.ComputeHash(combinedCardNamesBytes, 0, combinedCardNamesBytes.Length);
            m_CardNamesHash = Convert.ToBase64String(hash);

            cbxTimeStamp.Items.AddRange(m_AllCards.ToArray());
            cbxTimeStamp2.Items.AddRange(m_AllCards.ToArray());
            cbxExposure.Items.AddRange(m_AllCards.ToArray());

            cbxExposureUnits.Items.Clear();
            cbxExposureUnits.Items.AddRange(Enum.GetNames(typeof(TangraConfig.ExposureUnit)));

            cbxTimestampType.SelectedIndex = 0;
            cbxExposureUnits.SelectedIndex = 0;

            // End timestamp
            cbxTimestampType2.SelectedIndex = 2;
            cbxTimestampType2.Enabled = false;

            cbxTimeStampFormat.Items.Clear();
            cbxTimeStamp2Format.Items.Clear();
            var formats = new List<object>();
            formats.Add("yyyy-MM-ddTHH:mm:ss.fff");
            formats.Add("dd/MM/yyyy HH:mm:ss.fff");

            if (TangraConfig.Settings.Generic.CustomFITSTimeStampFormats != null)
                formats.AddRange(TangraConfig.Settings.Generic.CustomFITSTimeStampFormats);

            cbxTimeStampFormat.Items.AddRange(formats.ToArray());
            cbxTimeStamp2Format.Items.AddRange(formats.ToArray());
            if (!string.IsNullOrEmpty(TangraConfig.Settings.LastUsed.FitsTimestampFormat))
            {
                int idx = cbxTimeStampFormat.Items.IndexOf(TangraConfig.Settings.LastUsed.FitsTimestampFormat);
                if (idx > -1)
                {
                    cbxTimeStampFormat.SelectedIndex = idx;
                    cbxTimeStamp2Format.SelectedIndex = idx;
                }
            }
            else
            {
                cbxTimeStampFormat.SelectedIndex = 0;
                cbxTimeStamp2Format.SelectedIndex = 0;
            }

            TryIdentifyPreviousConfigApplyingForCurrentFiles();
        }