/// <summary> /// Reads a FITS header from a stream. /// </summary> /// <param name="s">Input stream.</param> /// <param name="Length">Expected length of input stream.</param> /// <returns>A list with all raw keyword records in the header.</returns> static List <KeywordRecord> ReadHeader(Stream s, long Length) { List <KeywordRecord> Kwlist = new List <KeywordRecord>(); bool HeaderEnd = false; while (!HeaderEnd & s.Position < Length) { int i; byte[] Buffer = new byte[80]; for (i = 0; i < 36; i++) { s.Read(Buffer, 0, 80); KeywordRecord kr = new KeywordRecord(Buffer); Kwlist.Add(kr); if (kr.Name.TrimEnd(' ') == "END") { HeaderEnd = true; } } } return(Kwlist); }
/// <summary> /// Reads a FITS header from a stream. /// </summary> /// <param name="stream">Input stream.</param> /// <param name="Length">Expected length of the input stream.</param> /// <returns>A tuple containing a list and a dictionary of the header records.</returns> internal static Tuple <List <MetadataRecord>, HeaderTable> ReadHeaderFromStream(Stream stream, long Length) { /* Read the headers and create the ElevatedRecord entries. */ List <KeywordRecord> prirec = ReadHeader(stream, Length); List <MetadataRecord> PrimaryHeader = new List <MetadataRecord>(); foreach (KeywordRecord kr in prirec) { if (kr.HasEqual) { PrimaryHeader.Add(KeywordRecord.Elevate(kr)); } } /* Give easy access to the metadata in the headers via the PrimaryTable. */ Dictionary <string, bool> Unique = new Dictionary <string, bool>(); HeaderTable PrimaryTable = new Dictionary <string, MetadataRecord>(); foreach (MetadataRecord ere in PrimaryHeader) { if (Unique.ContainsKey(ere.Name)) { Unique[ere.Name] = false; continue; } Unique.Add(ere.Name, true); PrimaryTable.Add(ere.Name, ere); } foreach (MetadataRecord ere in PrimaryHeader) { if (!Unique[ere.Name]) { PrimaryTable.Remove(ere.Name); } } return(new Tuple <List <MetadataRecord>, HeaderTable>(PrimaryHeader, PrimaryTable)); }
internal static MetadataRecord Elevate(KeywordRecord kwr) { MetadataRecord ev = new FITSMetadataRecord(kwr.Name.TrimEnd(' '), kwr.Data); return(ev); }