Example #1
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);
                }
            }
        }
Example #2
0
        private string GETFULLYFORMATTEDFITSLINE()
        {
            if (LINEISCOMMENTFORMAT)
            {
                if (VALUE != "")
                {
                    throw new Exception("Error: Line was indicated as comment but the value field is not empty. key MAY equal COMMENT and comment string MUST be supplied in comment, and value must be empty if it is a comment line.");
                }
                else
                if ((NAME.Length + COMMENT.Length) > 80)
                {
                    throw new Exception("Error: key name and comment are more than 80 elements: '" + NAME + COMMENT + "' are " + (NAME.Length + COMMENT.Length) + " elements.");
                }
                else
                {
                    return((NAME + COMMENT).PadRight(80));
                }
            }

            if (NAME.Length > 8)
            {
                throw new Exception("Error: key name was supplied with more than 8 characters: '" + NAME + "' is " + NAME.Length + " elements.");
            }

            if (NAME.Trim() == "END")
            {
                return(NAME.Trim().PadRight(80));
            }

            string key = NAME.PadRight(8);

            key += "= ";
            //key name formatting done

            //do value formatting
            string value;

            if (JPMath.IsNumeric(VALUE))            //then we have a numeric key value
            {
                double val = Convert.ToDouble(VALUE);

                if (val == 9223372036854775808)                //this is the bzero for unsigned int64...and is so large it will get converted to exponential notation which we do not want for this
                {
                    value = "9223372036854775808";
                }
                else if (Math.Abs(val) <= 1e-6 || Math.Abs(val) >= 1e13)
                {
                    value = val.ToString("0.00###########e+00");
                }
                else
                {
                    value = val.ToString("G");
                }
                if (val == 0)                //change the exp to integer 0
                {
                    value = "0";
                }

                if (value.Length < 20)
                {
                    value = value.PadLeft(20);
                }
            }
            else            //else it must be a string
            {
                if (VALUE.Trim() == "T" || VALUE.Trim() == "F")
                {
                    value = VALUE.Trim().PadLeft(20);
                }
                else
                {
                    value = "'" + VALUE.PadRight(18) + "'";
                }
            }
            //value formatting done

            string comment = COMMENT;

            comment = " / " + comment;            //comment formatting done
            string line = key + value + comment;

            if (line.Length > 80)
            {
                line = line.Substring(0, 80);
            }
            else
            {
                line = line.PadRight(80);
            }

            return(line);
        }
Example #3
0
        /// <summary>Constructor. Creates an instance of a FITSHeaderKey, out of a supplied String line. The line may be empty, but not more than 80 elements length. The key will be formatted as a FITS comment line if its internal structure appears to be configured as such.</summary>
        public FITSHeaderKey(string line)
        {
            if (line.Length > 80)
            {
                throw new Exception("Header line String: \r\r'" + line + "'\r\r is is longer than 80 characters. The String must contain eighty (or less) elements.");
            }
            else if (line.Length < 80)
            {
                line = line.PadRight(80);
            }

            try
            {
                NAME = line.Substring(0, 8).Trim();
                if (NAME == "END")
                {
                    LINEISCOMMENTFORMAT = false;
                    VALUE   = "";
                    COMMENT = "";
                    return;
                }
                else if (line.Substring(8, 1) != "=")
                {
                    LINEISCOMMENTFORMAT = true;
                    NAME    = "";
                    VALUE   = "";
                    COMMENT = line.Trim();
                    return;
                }
                else
                {
                    LINEISCOMMENTFORMAT = false;
                    if (JPMath.IsNumeric(line.Substring(10, 20)))                    //this has to work if it is supposed to be a numeric value here
                    {
                        VALUE = line.Substring(10, 20).Trim();                       //get rid of leading and trailing white space
                    }
                    else if (line.Substring(10, 20).Trim() == "T" || line.Substring(10, 20).Trim() == "F")
                    {
                        VALUE = line.Substring(10, 20).Trim();
                    }
                    else
                    {
                        int indx = line.IndexOf("'");
                        if (indx == -1)
                        {
                            LINEISCOMMENTFORMAT = true;
                            NAME    = "";
                            VALUE   = "";
                            COMMENT = line.Trim();
                            return;
                        }
                        else
                        {
                            VALUE = line.Substring(indx + 1, line.LastIndexOf("'") - indx - 1);
                            VALUE = VALUE.Trim();
                        }
                    }

                    int ind = line.IndexOf("/");
                    if (ind != -1)
                    {
                        COMMENT = line.Substring(ind + 1).Trim();
                    }
                    else
                    {
                        COMMENT = "";
                    }
                }
            }
            catch
            {
                throw new Exception("Header line: \r\r'" + line + "'\r\r is very poorly formatted. Continuing should allow the file to be processed but the header will not likely contain whatever was intended.");
            }
        }
Example #4
0
 public bool ValueIsNumeric()
 {
     return(JPMath.IsNumeric(VALUE));
 }