/// <summary>Fill header with keywords that describe image data.</summary>
        /// <param name="head">The FITS header</param>
        /// <exception cref="FitsException"> FitsException if the object does not contain valid image data.</exception>
        internal override void FillHeader(Header head)
        {
            if (dataArray == null)
            {
                head.NullImage();
                return ;
            }

            Type classname = ArrayFuncs.GetBaseClass(dataArray);

            int[] dimens = ArrayFuncs.GetDimensions(dataArray);

            if (dimens == null || dimens.Length == 0)
            {
                throw new FitsException("Image data object not array. ");
            }

            int bitpix;
            // Changed from classname[dimens.Length] to classname[classname.IndexOf(".") + 1]

            switch (classname.ToString())
            {
                case "System.Byte":
                    bitpix = 8;
                    break;
                case "System.Int16":
                    bitpix = 16;
                    break;
                case "System.Int32":
                    bitpix = 32;
                    break;
                case "System.Int64":
                    bitpix = 64;
                    break;
                case "System.Single":
                    bitpix = - 32;
                    break;
                case "System.Double":
                    bitpix = - 64;
                    break;
                default:
                    throw new FitsException("Invalid Object Type for FITS data:" +
                            classname.ToString());
            }

            // if this is neither a primary header nor an image extension,
            // make it a primary header
            head.Simple = true;
            head.Bitpix = bitpix;
            head.Naxes = dimens.Length;

            for (int i = 1; i <= dimens.Length; i += 1)
            {
                if (dimens[i - 1] == - 1)
                {
                    throw new FitsException("Unfilled array for dimension: " + i);
                }
                head.SetNaxis(i, dimens[dimens.Length - i]);
            }

            // suggested in .97 version: EXTEND keyword added before PCOUNT and GCOUNT.
            head.AddValue("EXTEND", true, "Extension permitted"); // Just in case!
            head.AddValue("PCOUNT", 0, "No extra parameters");
            head.AddValue("GCOUNT", 1, "One group");
        }
        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;
        }
Exemple #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");
            }
        }
Exemple #4
0
        /// <summary>Fill in a header with information that points to this data.</summary>
        internal override void FillHeader(Header hdr)
        {
            try
            {
                hdr.Xtension = "TABLE";
                hdr.Bitpix = 8;
                hdr.Naxes = 2;
                hdr.SetNaxis(1, rowLen);
                hdr.SetNaxis(2, nRows);
                Cursor c = (Cursor)hdr.GetEnumerator();
                c.Key = "NAXIS2";
                c.MoveNext();
                c.Add("PCOUNT", new HeaderCard("PCOUNT", 0, "No group data"));
                c.Add("GCOUNT", new HeaderCard("GCOUNT", 1, "One group"));
                c.Add("TFIELDS", new HeaderCard("TFIELDS", nFields, "Number of fields in table"));

                for(int i = 0; i < nFields; i += 1)
                {
                    AddColInfo(i, c);
                }
            }
            catch (HeaderCardException e)
            {
                Console.Error.WriteLine("ImpossibleException in fillHeader:" + e);
            }
        }