Ejemplo n.º 1
0
        private void frmSortFitsFiles_Shown(object sender, EventArgs e)
        {
            TimeStampReader = null;
            if (m_FitsFiles.Length > 0)
            {
                var frm = new frmChooseTimeHeaders(m_FitsFiles[0], GetOrderedFitsFileHash(), m_VideoController);
                if (frm.ShowDialog(this) == DialogResult.OK)
                {
                    TimeStampReader  = frm.TimeStampReader;
                    FlipVertically   = frm.FlipVertically;
                    FlipHorizontally = frm.FlipHorizontally;
                    MinPixelValue    = frm.MinPixelValue;
                    MaxPixelValue    = frm.MaxPixelValue;
                    BitPix           = frm.BitPix;
                    NegPixCorrection = frm.NegPixCorrection;
                }
                else
                {
                    Array.Clear(m_FitsFiles, 0, m_FitsFiles.Length);
                    DialogResult = DialogResult.Cancel;
                    Close();
                    return;
                }
            }


            m_FitsHeaders    = new Header[m_FitsFiles.Length];
            m_FitsTimestamps = new DateTime?[m_FitsFiles.Length];

            pbar.Minimum = 0;
            pbar.Maximum = m_FitsFiles.Length;
            pbar.Value   = 0;

            var fileSizeInfo = new Dictionary <string, FitsFileFormatInfoRecord>();

            for (int i = 0; i < m_FitsFiles.Length; i++)
            {
                try
                {
                    using (BufferedFile bf = new BufferedFile(m_FitsFiles[i], FileAccess.Read, FileShare.ReadWrite))
                    {
                        Header hdr = Header.ReadHeader(bf);
                        m_FitsHeaders[i] = hdr;

                        int numAxis = -1;
                        int width   = -1;
                        int height  = -1;
                        int.TryParse(hdr.FindCard("NAXIS") != null ? hdr.FindCard("NAXIS").Value : "0", out numAxis);
                        int.TryParse(hdr.FindCard("NAXIS1") != null ? hdr.FindCard("NAXIS1").Value : "0", out width);
                        int.TryParse(hdr.FindCard("NAXIS2") != null ? hdr.FindCard("NAXIS2").Value : "0", out height);
                        string format = String.Format("{0} x {1}", width, height);
                        if (fileSizeInfo.ContainsKey(format))
                        {
                            fileSizeInfo[format].NumFiles++;
                        }
                        else
                        {
                            fileSizeInfo.Add(format, new FitsFileFormatInfoRecord {
                                FirstFile = Path.GetFileName(m_FitsFiles[i]), NumFiles = 1
                            });
                        }

                        bool     isMidPoint;
                        double?  fitsExposure = null;
                        DateTime?timestamp    = null;

                        if (TimeStampReader != null)
                        {
                            try
                            {
                                timestamp = FITSHelper2.ParseExposure(m_FitsFiles[i], hdr, TimeStampReader, out isMidPoint, out fitsExposure);
                            }
                            catch (Exception ex)
                            {
                                Trace.WriteLine(ex.ToString());
                            }
                        }

                        m_FitsTimestamps[i] = timestamp;

                        if (timestamp != null && fitsExposure.HasValue)
                        {
                            m_FilesWithExposure++;
                        }
                        else
                        {
                            m_FilesWithoutExposure++;
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(string.Format("Error processing FITS files: {0}", m_FitsFiles[i]), ex);
                }

                pbar.Value = i;
                Application.DoEvents();
            }

            pbar.Value = pbar.Minimum;
            Application.DoEvents();

            if (fileSizeInfo.Count > 1)
            {
                var errorInfo = new StringBuilder();
                foreach (string key in fileSizeInfo.Keys)
                {
                    if (fileSizeInfo[key].NumFiles > 1)
                    {
                        errorInfo.AppendFormat("'{1}' and {2} other files: {0}\r\n", key, fileSizeInfo[key].FirstFile, fileSizeInfo[key].NumFiles - 1);
                    }
                    else
                    {
                        errorInfo.AppendFormat("'{1}' (single file): {0}\r\n", key, fileSizeInfo[key].FirstFile);
                    }
                }
                ErrorMessage = string.Format("Cannot load FITS file sequence because there are files with different image dimentions:\r\n\r\n{0}\r\n\r\nPlease ensure that all files in the directory have the same dimention (number of axis).", errorInfo.ToString());
            }
            timer1.Enabled = true;
        }
Ejemplo n.º 2
0
        private void frmSortFitsFiles_Shown(object sender, EventArgs e)
        {
            m_FitsHeaders = new Header[m_FitsFiles.Length];
            m_FitsTimestamps = new DateTime?[m_FitsFiles.Length];

            pbar.Minimum = 0;
            pbar.Maximum = m_FitsFiles.Length;
            pbar.Value = 0;

            var fileSizeInfo = new Dictionary<string, FitsFileFormatInfoRecord>();
            TimeStampReader = null;

            for (int i = 0; i < m_FitsFiles.Length; i++)
            {
                try
                {
                    using (BufferedFile bf = new BufferedFile(m_FitsFiles[i], FileAccess.Read, FileShare.ReadWrite))
                    {
                        Header hdr = Header.ReadHeader(bf);
                        m_FitsHeaders[i] = hdr;

                        int numAxis = -1;
                        int width = -1;
                        int height = -1;
                        int.TryParse(hdr.FindCard("NAXIS") != null ? hdr.FindCard("NAXIS").Value : "0", out numAxis);
                        int.TryParse(hdr.FindCard("NAXIS1") != null ? hdr.FindCard("NAXIS1").Value : "0", out width);
                        int.TryParse(hdr.FindCard("NAXIS2") != null ? hdr.FindCard("NAXIS2").Value : "0", out height);
                        string format = String.Format("{0} x {1}", width, height);
                        if (fileSizeInfo.ContainsKey(format))
                            fileSizeInfo[format].NumFiles++;
                        else
                            fileSizeInfo.Add(format, new FitsFileFormatInfoRecord { FirstFile = Path.GetFileName(m_FitsFiles[i]), NumFiles = 1 });

                        bool isMidPoint;
                        double? fitsExposure = null;
                        DateTime? timestamp = null;
                        try
                        {
                            timestamp = FITSHelper.ParseExposure(hdr, TimeStampReader, out isMidPoint, out fitsExposure);
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine(ex.ToString());
                        }

                        if (i == 0 && (!fitsExposure.HasValue || !timestamp.HasValue))
                        {
                            var frm = new frmChooseTimeHeaders(hdr, GetOrderedFitsFileHash());
                            if (frm.ShowDialog(this) == DialogResult.OK)
                            {
                                TimeStampReader = frm.TimeStampReader;
                            }

                            try
                            {
                                timestamp = FITSHelper.ParseExposure(hdr, TimeStampReader, out isMidPoint, out fitsExposure);
                            }
                            catch (Exception ex)
                            {
                                Trace.WriteLine(ex.ToString());
                            }
                        }

                        m_FitsTimestamps[i] = timestamp;

                        if (timestamp != null && fitsExposure.HasValue)
                            m_FilesWithExposure++;
                        else
                            m_FilesWithoutExposure++;
                    }
                }
                catch (Exception ex)
                {
                    throw new ApplicationException(string.Format("Error processing FITS files: {0}", m_FitsFiles[i]), ex);
                }

                pbar.Value = i;
                Application.DoEvents();
            }

            pbar.Value = pbar.Minimum;
            Application.DoEvents();

            if (fileSizeInfo.Count > 1)
            {
                var errorInfo = new StringBuilder();
                foreach (string key in fileSizeInfo.Keys)
                {
                    if (fileSizeInfo[key].NumFiles > 1)
                        errorInfo.AppendFormat("'{1}' and {2} other files: {0}\r\n", key, fileSizeInfo[key].FirstFile, fileSizeInfo[key].NumFiles - 1);
                    else
                        errorInfo.AppendFormat("'{1}' (single file): {0}\r\n", key, fileSizeInfo[key].FirstFile);
                }
                ErrorMessage = string.Format("Cannot load FITS file sequence because there are files with different image dimentions:\r\n\r\n{0}\r\n\r\nPlease ensure that all files in the directory have the same dimention (number of axis).", errorInfo.ToString());

            }
            timer1.Enabled = true;
        }