Example #1
0
        public int AppendHeaderRecord(FitsHeaderRecord record)
        {
            var index = nextSequenceNumber++;

            records.Add(index, record);
            return(index);
        }
        /// <summary>
        ///     Creates a new <see cref="FitsHeaderRecord" /> from record text in the supplied string.
        /// </summary>
        /// <param name="text">The record text, which must contain exactly 80 permitted ASCII characters.</param>
        /// <returns>A new instance of <see cref="FitsHeaderRecord" /> initialized from the record text.</returns>
        public static FitsHeaderRecord FromRecordText(string text)
        {
            Contract.Requires(!string.IsNullOrEmpty(text));
            Contract.Ensures(Contract.Result <FitsHeaderRecord>() != null);
            Log.Info("Parsing FITS Header Record: {0}", text);
            if (text.Length != 80)
            {
                throw new FitsFormatException(
                          $"Found {text.Length} characters. FITS records must contain exactly 80 characters")
                      {
                          Record = text
                      }
            }
            ;
            var equalsPosition  = text.IndexOf(FitsFormat.EqualsCharacter);
            var commentPosition = text.IndexOf(FitsFormat.CommentCharacter);
            var record          = new FitsHeaderRecord(text);

            /*
             * If the first non blank character is the comment character then the record is a comment. The
             * comment text begins at the first non blank character after the comment character.
             */
            if (text.TrimStart().FirstOrDefault() == FitsFormat.CommentCharacter)
            {
                record.Comment = ParseComment(text);
                record.Keyword = string.Empty;
                record.Value   = string.Empty;
                return(record);
            }
            record.Keyword = ParseKeyword(text);
            if (record.Keyword.IsCommentary() || text.HasNoValue())
            {
                // keywords that are blank, or one of the commentary types, or which have no value
                // have comment text from position 9 and no value.
                record.Comment = text.RemoveHead(FitsFormat.ValueFieldPosition).TrimEnd();
                record.Value   = string.Empty;
            }
            else
            {
                record.Value   = ParseValueField(text);
                record.Comment = ParseComment(text);
            }
            return(record);
        }
Example #3
0
        public async Task <FitsHeaderRecord> ReadHeaderRecord()
        {
            var rawRecord = await ReadRecord().ConfigureAwait(false);

            return(FitsHeaderRecord.FromRecordText(rawRecord.Text));
        }