Exemple #1
0
        private void LoadStars(SearchZone zone, double limitMag, List <IStar> starsFromThisZone)
        {
            List <LoadPosition> searchIndexes = m_Index.GetLoadPositions(zone);

            IntPtr buffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(UCAC2Entry)));

            try
            {
                foreach (LoadPosition pos in searchIndexes)
                {
                    string fileName;
                    if (pos.BSS)
                    {
                        fileName = Path.Combine(m_CatalogLocation, string.Format("s{0}", pos.ZoneId.ToString("00")));
                    }
                    else
                    {
                        fileName = Path.Combine(m_CatalogLocation, string.Format("z{0}", pos.ZoneId.ToString("000")));
                    }

                    long positionFrom      = (pos.FromRecordId - 1) * UCAC2Entry.Size;
                    uint firstStarNoToRead = pos.FirstStarNoInBin + pos.FromRecordId;
                    uint numRecords        = pos.ToRecordId - pos.FromRecordId;

                    using (FileStream str = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        using (BinaryReader rdr = new BinaryReader(str))
                        {
                            rdr.BaseStream.Position = positionFrom;

                            for (int i = 0; i < numRecords; i++, firstStarNoToRead++)
                            {
                                UCAC2Entry entry   = new UCAC2Entry();
                                byte[]     rawData = rdr.ReadBytes(UCAC2Entry.Size);

                                Marshal.Copy(rawData, 0, buffer, Marshal.SizeOf(entry));
                                entry = (UCAC2Entry)Marshal.PtrToStructure(buffer, typeof(UCAC2Entry));

                                if (pos.BSS)
                                {
                                    entry.InitUCAC2Entry(firstStarNoToRead + UCAC2Entry.FIRST_BSS_STAR_NO);
                                }
                                else
                                {
                                    entry.InitUCAC2Entry(firstStarNoToRead);
                                }

                                if (entry.Mag > limitMag)
                                {
                                    continue;
                                }

                                if (entry.RAJ2000 < zone.RAFrom)
                                {
                                    continue;
                                }
                                if (entry.RAJ2000 > zone.RATo)
                                {
                                    continue;
                                }
                                if (entry.DEJ2000 < zone.DEFrom)
                                {
                                    continue;
                                }
                                if (entry.DEJ2000 > zone.DETo)
                                {
                                    continue;
                                }

                                starsFromThisZone.Add(entry);
                            }
                        }
                    }
                }
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
        }
Exemple #2
0
        private void LoadStars(SearchZone zone, double limitMag, List<IStar> starsFromThisZone)
        {
            List<LoadPosition> searchIndexes = m_Index.GetLoadPositions(zone);

            IntPtr buffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(UCAC2Entry)));
            try
            {
                foreach(LoadPosition pos in searchIndexes)
                {
                    string fileName;
                    if (pos.BSS)
                        fileName = Path.Combine(m_CatalogLocation, string.Format("s{0}", pos.ZoneId.ToString("00")));
                    else
                        fileName = Path.Combine(m_CatalogLocation, string.Format("z{0}", pos.ZoneId.ToString("000")));

                    long positionFrom = (pos.FromRecordId - 1)* UCAC2Entry.Size;
                    uint firstStarNoToRead = pos.FirstStarNoInBin + pos.FromRecordId;
                    uint numRecords = pos.ToRecordId - pos.FromRecordId;

                    using (FileStream str = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        using (BinaryReader rdr = new BinaryReader(str))
                        {
                            rdr.BaseStream.Position = positionFrom;

                            for (int i = 0; i < numRecords; i++, firstStarNoToRead++)
                            {
                                UCAC2Entry entry = new UCAC2Entry();
                                byte[] rawData = rdr.ReadBytes(UCAC2Entry.Size);

                                Marshal.Copy(rawData, 0, buffer, Marshal.SizeOf(entry));
                                entry = (UCAC2Entry)Marshal.PtrToStructure(buffer, typeof(UCAC2Entry));

                                if (pos.BSS)
                                    entry.InitUCAC2Entry(firstStarNoToRead + UCAC2Entry.FIRST_BSS_STAR_NO);
                                else
                                    entry.InitUCAC2Entry(firstStarNoToRead);

                                if (entry.Mag > limitMag) continue;

                                if (entry.RAJ2000 < zone.RAFrom) continue;
                                if (entry.RAJ2000 > zone.RATo) continue;
                                if (entry.DEJ2000 < zone.DEFrom) continue;
                                if (entry.DEJ2000 > zone.DETo) continue;

                                starsFromThisZone.Add(entry);
                            }
                        }
                    }
                }
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
        }