Ejemplo 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;
        }
Ejemplo n.º 2
0
 void OKBtn_Click(object sender, EventArgs e)
 {
     if (CommentKeyLineChck.Checked)
     {
         HEADERLINE = new FITSHeaderKey(CommentKeyLineTxt.Text);
     }
     else
     {
         HEADERLINE = new FITSHeaderKey(KeyNameTxt.Text, KeyValueTxt.Text, KeyCommentTxt.Text);
     }
 }
Ejemplo n.º 3
0
        private void MAKE_DEFAULT_HEADER(bool mayContainExtensions, double[, ]?image)
        {
            if (mayContainExtensions && image == null)
            {
                HEADERKEYS = new FITSHeaderKey[5];
            }
            else if (mayContainExtensions && image != null)
            {
                HEADERKEYS = new FITSHeaderKey[9];
            }
            else if (!mayContainExtensions && image == null)
            {
                HEADERKEYS = new FITSHeaderKey[4];
            }
            else              //(!mayContainExtensions && image != nullptr)
            {
                HEADERKEYS = new FITSHeaderKey[8];
            }

            long BZERO = 0, BSCALE = 1;
            int  BITPIX = -64, NAXIS = 0, NAXIS1 = 0, NAXIS2 = 0;

            if (image != null)
            {
                NAXIS  = 2;
                NAXIS1 = image.GetLength(0);
                NAXIS2 = image.GetLength(1);
            }

            int c = 0;

            HEADERKEYS[c++] = new FITSHeaderKey("SIMPLE", "T", "file conforms to FITS standard");
            HEADERKEYS[c++] = new FITSHeaderKey("BITPIX", BITPIX.ToString(), "bits per pixel");
            HEADERKEYS[c++] = new FITSHeaderKey("NAXIS", NAXIS.ToString(), "number of data axes");

            if (image != null)
            {
                HEADERKEYS[c++] = new FITSHeaderKey("NAXIS1", NAXIS1.ToString(), "width - number of data columns");
                HEADERKEYS[c++] = new FITSHeaderKey("NAXIS2", NAXIS2.ToString(), "height - number of data rows");
                HEADERKEYS[c++] = new FITSHeaderKey("BZERO", BZERO.ToString(), "data offset");
                HEADERKEYS[c++] = new FITSHeaderKey("BSCALE", BSCALE.ToString(), "data scaling");
            }
            if (mayContainExtensions)
            {
                HEADERKEYS[c++] = new FITSHeaderKey("EXTEND", "T", "file may contain extensions");
            }

            HEADERKEYS[c++]     = new FITSHeaderKey("END");
            UPDATEDISPLAYHEADER = true;
        }
Ejemplo n.º 4
0
        public FITSHeader(string fileName)
        {
            FileStream fs          = new FileStream(fileName, FileMode.Open);
            ArrayList  headerlines = new ArrayList();
            bool       ext         = false;

            FITSFILEOPS.SCANPRIMARYUNIT(fs, false, ref headerlines, ref ext);
            fs.Close();

            HEADERKEYS = new JPFITS.FITSHeaderKey[headerlines.Count];
            for (int i = 0; i < HEADERKEYS.Length; i++)
            {
                HEADERKEYS[i] = new FITSHeaderKey((string)headerlines[i]);
            }
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
        public FITSHeaderKeyDialog(FITSHeaderKey headerKey)
        {
            InitializeComponent();

            HEADERLINE = headerKey;

            if (HEADERLINE.IsCommentKey)
            {
                CommentKeyLineChck.Checked = true;
                CommentKeyLineTxt.Text     = HEADERLINE.Comment;
            }
            else
            {
                KeyNameTxt.Text    = HEADERLINE.Name;
                KeyValueTxt.Text   = HEADERLINE.Value;
                KeyCommentTxt.Text = HEADERLINE.Comment;
            }
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
0
        public FITSHeader(ArrayList headerlines, bool populate_nonessential)
        {
            if (populate_nonessential)
            {
                HEADERKEYS = new JPFITS.FITSHeaderKey[headerlines.Count];
            }
            else
            {
                int N = 10;
                if (headerlines.Count < 10)
                {
                    N = headerlines.Count;
                }
                HEADERKEYS = new JPFITS.FITSHeaderKey[N];
            }

            for (int i = 0; i < HEADERKEYS.Length; i++)
            {
                HEADERKEYS[i] = new FITSHeaderKey((string)headerlines[i]);
            }
        }
Ejemplo n.º 9
0
        private void HeaderKeysListBox_KeyDown(System.Object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                if (IMAGESET != null && IMAGESET.Count > 1)
                {
                    DialogResult res = MessageBox.Show("Delete selected key(s) from all headers (YES), or only current header (NO)?", "Warning", MessageBoxButtons.YesNoCancel);
                    if (res == DialogResult.Cancel)
                    {
                        return;
                    }
                    else if (res == DialogResult.Yes)
                    {
                        HeaderContextApplyAll.Checked = true;
                    }
                    else
                    {
                        HeaderContextApplyAll.Checked = false;
                    }
                }

                HeaderContextRemoveKeys.PerformClick();
                return;
            }

            if (e.Control && e.KeyCode == Keys.C)            //copy
            {
                String copy = "";
                for (int i = 0; i < HeaderKeysListBox.SelectedIndices.Count; i++)
                {
                    copy += HEADER[(int)HeaderKeysListBox.SelectedIndices[i]].GetFullyFomattedFITSLine() + Environment.NewLine;
                }

                if (copy.Length > 0)
                {
                    Clipboard.SetText(copy);
                }

                return;
            }

            if (e.Control && e.KeyCode == Keys.V)            //paste
            {
                if (HeaderKeysListBox.SelectedIndices.Count == 0)
                {
                    return;
                }

                String paste = Clipboard.GetText();
                if (paste == null || paste.Length == 0)
                {
                    return;
                }

                if (!JPMath.IsInteger((double)(paste.Length) / 80))
                {
                    return;
                }

                int           index = HeaderKeysListBox.SelectedIndices[HeaderKeysListBox.SelectedIndices.Count - 1];
                FITSHeaderKey key;
                int           nlines = paste.Length / 80;
                for (int i = 0; i < nlines; i++)
                {
                    key = new FITSHeaderKey(paste.Substring(i * 80, 80));
                    HEADER.AddKey(key, index + 1 + i);
                }
            }
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
 public void SetKey(int index, string Key, string Value, string Comment)
 {
     HEADERKEYS[index]   = new FITSHeaderKey(Key, Value, Comment);
     UPDATEDISPLAYHEADER = true;
 }