Exemplo n.º 1
0
        public void AddKey(string NewKey, string NewValue, string NewComment, int KeyIndex)
        {
            int c = 0;
            int L = this.Length;

            if (KeyIndex < 0 || KeyIndex >= L)
            {
                KeyIndex = L - 1;                //add to end of header (before END)
            }
            JPFITS.FITSHeaderKey[] keys = new JPFITS.FITSHeaderKey[L + 1];

            for (int i = 0; i < L + 1; i++)
            {
                if (i == KeyIndex)
                {
                    keys[i] = new FITSHeaderKey(NewKey, NewValue, NewComment);
                    continue;
                }
                keys[i] = HEADERKEYS[c];
                c++;
            }

            HEADERKEYS          = keys;
            UPDATEDISPLAYHEADER = true;
        }
Exemplo n.º 2
0
 public void AddKey(JPFITS.FITSHeaderKey keyLine, int keyIndex)
 {
     if (keyLine.IsCommentKey)
     {
         this.AddCommentKeyLine(keyLine.Comment, keyIndex);
     }
     else
     {
         this.AddKey(keyLine.Name, keyLine.Value, keyLine.Comment, keyIndex);
     }
 }
Exemplo n.º 3
0
        public void AddCommentKeyLine(string commentKeyLine, int keyIndex)
        {
            commentKeyLine = commentKeyLine.PadRight(80);            //pad since might just be empty intended as blank line
            int nels      = commentKeyLine.Length;
            int Nnewlines = (int)Math.Ceiling((double)(nels) / 80);

            string[] strnewlines = new string[Nnewlines];

            for (int i = 0; i < Nnewlines; i++)
            {
                if ((i + 1) * 80 > nels)
                {
                    strnewlines[i] = commentKeyLine.Substring(i * 80);
                }
                else
                {
                    strnewlines[i] = commentKeyLine.Substring(i * 80, 80);
                }
            }

            if (keyIndex < 0 || keyIndex >= this.Length)
            {
                keyIndex = this.Length - 1;                //add to end of header (before END)
            }
            JPFITS.FITSHeaderKey[] keys = new JPFITS.FITSHeaderKey[this.Length + Nnewlines];

            int c = 0;

            nels = 0;
            for (int i = 0; i < keys.Length; i++)
            {
                if (i >= keyIndex && i < keyIndex + Nnewlines)
                {
                    keys[i] = new FITSHeaderKey(strnewlines[nels++]);
                }
                else
                {
                    keys[i] = HEADERKEYS[c];
                    c++;
                }
            }

            HEADERKEYS          = keys;
            UPDATEDISPLAYHEADER = true;
        }
Exemplo n.º 4
0
        public void MoveKey(int currentIndex, int newIndex)
        {
            if (newIndex < 0 || newIndex >= this.Length - 1)
            {
                return;
            }
            if (currentIndex < 0 || currentIndex >= this.Length - 1)
            {
                return;
            }
            if (currentIndex == newIndex)
            {
                return;
            }

            FITSHeaderKey tempkey = HEADERKEYS[currentIndex];

            JPFITS.FITSHeaderKey[] keys = new JPFITS.FITSHeaderKey[this.Length];

            int c = 0;

            for (int i = 0; i < this.Length; i++)
            {
                if (i == currentIndex)
                {
                    c++;
                }

                if (i == newIndex)
                {
                    keys[i] = tempkey;
                    continue;
                }

                keys[i] = HEADERKEYS[c];
                c++;
            }

            HEADERKEYS          = keys;
            UPDATEDISPLAYHEADER = true;
        }
Exemplo n.º 5
0
        public void CopyHeaderFrom(JPFITS.FITSHeader sourceHeader)
        {
            bool[] oktocopy = new bool[sourceHeader.Length];
            int    ntocopy  = 0;

            for (int i = 0; i < sourceHeader.Length; i++)
            {
                if (ValidKeyEdit(sourceHeader.GetKeyName(i), false))
                {
                    ntocopy++;
                    oktocopy[i] = true;
                }
            }

            JPFITS.FITSHeaderKey[] newheaderkeys = new JPFITS.FITSHeaderKey[this.Length + ntocopy];

            for (int i = 0; i < this.Length - 1; i++)            //leave off END for now
            {
                newheaderkeys[i] = HEADERKEYS[i];
            }

            int c = 0;

            for (int i = 0; i < sourceHeader.Length; i++)
            {
                if (oktocopy[i])
                {
                    newheaderkeys[this.Length - 1 + c] = sourceHeader[i];
                    c++;
                }
            }

            //END
            newheaderkeys[newheaderkeys.Length - 1] = new FITSHeaderKey("END");

            HEADERKEYS          = newheaderkeys;
            UPDATEDISPLAYHEADER = true;
        }
Exemplo n.º 6
0
        public void RemoveKey(int KeyIndex)
        {
            if (KeyIndex < 0 || KeyIndex > this.Length - 1)
            {
                return;
            }

            int c = -1;

            JPFITS.FITSHeaderKey[] keys = new JPFITS.FITSHeaderKey[this.Length - 1];

            for (int i = 0; i < this.Length; i++)
            {
                if (i == KeyIndex)
                {
                    continue;
                }
                c++;
                keys[c] = HEADERKEYS[i];
            }
            HEADERKEYS          = keys;
            UPDATEDISPLAYHEADER = true;
        }
Exemplo n.º 7
0
        public string[] GetFormattedHeaderBlock(bool isExtension, bool keysOnly)
        {
            if (isExtension && !ISEXTENSION)
            {
                UPDATEDISPLAYHEADER = true;
                ISEXTENSION         = true;

                this.RemoveKey("EXTEND");

                HEADERKEYS[0].Name    = "XTENSION";
                HEADERKEYS[0].Value   = "IMAGE";
                HEADERKEYS[0].Comment = "Image extension";

                bool pcountkey = false, gcountkey = false;
                for (int i = 0; i < this.Length; i++)
                {
                    if (!pcountkey || !gcountkey)
                    {
                        if (HEADERKEYS[i].Name.Trim() == "PCOUNT")
                        {
                            pcountkey = true;
                        }
                        if (HEADERKEYS[i].Name.Trim() == "GCOUNT")
                        {
                            pcountkey = true;
                        }
                    }
                }
                if (!pcountkey && !gcountkey)                //they would BOTH not be present if things are being done correctly...need to add them
                {
                    int naxis = -1;
                    for (int i = 0; i < this.Length; i++)
                    {
                        if (HEADERKEYS[i].Name.Trim() == "NAXIS")
                        {
                            naxis = Convert.ToInt32(HEADERKEYS[i].Value.Trim());
                            break;
                        }
                    }
                    int naxisNindex = -1;
                    for (int i = 0; i < this.Length; i++)
                    {
                        if (HEADERKEYS[i].Name.Trim() == "NAXIS" + naxis.ToString())
                        {
                            naxisNindex = i;
                            break;
                        }
                    }

                    JPFITS.FITSHeaderKey[] keys = new JPFITS.FITSHeaderKey[this.Length + 2];

                    for (int i = 0; i <= naxisNindex; i++)
                    {
                        keys[i] = HEADERKEYS[i];
                    }

                    keys[naxisNindex + 1] = new FITSHeaderKey("PCOUNT", "0", "number of bytes in heap area");
                    keys[naxisNindex + 2] = new FITSHeaderKey("GCOUNT", "1", "single data table");

                    for (int i = naxisNindex + 3; i < keys.Length; i++)
                    {
                        keys[i] = HEADERKEYS[i - 2];
                    }

                    HEADERKEYS = keys;
                }
            }
            else if (!isExtension && ISEXTENSION)
            {
                UPDATEDISPLAYHEADER   = true;
                ISEXTENSION           = false;
                HEADERKEYS[0].Name    = "SIMPLE";
                HEADERKEYS[0].Value   = "T";
                HEADERKEYS[0].Comment = "file conforms to FITS standard.";
            }

            if (!UPDATEDISPLAYHEADER && !keysOnly)
            {
                return(FORMATTEDHEADER);
            }

            UPDATEDISPLAYHEADER = false;

            if (keysOnly)
            {
                FORMATTEDHEADER = new string[this.Length];
            }
            else
            {
                int NKeys  = this.Length;
                int NCards = (NKeys - 1) / 36;
                FORMATTEDHEADER = new string[(NCards + 1) * 36];
            }

            for (int i = 0; i < this.Length; i++)
            {
                FORMATTEDHEADER[i] = HEADERKEYS[i].GetFullyFomattedFITSLine();
            }

            if (keysOnly)
            {
                return(FORMATTEDHEADER);
            }

            string empty = "";

            for (int i = this.Length; i < FORMATTEDHEADER.Length; i++)
            {
                FORMATTEDHEADER[i] = empty.PadLeft(80);
            }

            return(FORMATTEDHEADER);
        }