Example #1
0
        /// <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");
        }