예제 #1
0
        private void LoadStarsBrighterThan(SearchZone zone, LoadPosition loadPos, double limitMag, List <IStar> starsFromThisZone)
        {
            IntPtr buffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(NOMADEntry)));

            try
            {
                using (FileStream fs = new FileStream(m_Index.GetCatalogFileForZone(loadPos.ZoneId), FileMode.Open, FileAccess.Read))
                    using (BinaryReader rdr = new BinaryReader(fs))
                    {
#if ASTROMETRY_DEBUG
                        Trace.Assert(fs.Length >= (loadPos.FromRecordId + 1) * 88);
#endif
                        uint currStarInBin = loadPos.FromRecordId - 1;
                        fs.Position = 88 * loadPos.FromRecordId;

                        for (int i = 0; i < loadPos.ToRecordId - loadPos.FromRecordId; i++)
                        {
                            currStarInBin++;

#if ASTROMETRY_DEBUG
                            Trace.Assert(fs.Position % 88 == 0);
#endif

                            fs.Seek(44, SeekOrigin.Current);
                            double mag      = rdr.ReadInt32() / 1000.0; /* V Mag */
                            int    byteDiff = 0;
                            if (mag == 30000.0)
                            {
                                mag      = rdr.ReadInt32() / 1000.0; /* R Mag */
                                byteDiff = 4;
                            }

                            if (mag > limitMag)
                            {
                                fs.Seek(40 - byteDiff, SeekOrigin.Current);
                                continue;
                            }

                            fs.Seek(-(48 + byteDiff), SeekOrigin.Current);
                            NOMADEntry entry   = new NOMADEntry();
                            byte[]     rawData = rdr.ReadBytes(NOMADEntry.Size);

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

                            if (entry.RAJ2000 >= zone.RAFrom &&
                                entry.RAJ2000 <= zone.RATo)
                            {
                                entry.InitNOMADEntry(loadPos.FirstStarNoInBin + currStarInBin, (uint)loadPos.ZoneId, currStarInBin);
                                starsFromThisZone.Add(entry);
                            }
                        }
                    }
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
        }
예제 #2
0
        private void LoadStarsBrighterThan(SearchZone zone, LoadPosition loadPos, double limitMag, List<IStar> starsFromThisZone)
        {
            IntPtr buffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(NOMADEntry)));
            try
            {
                using (FileStream fs = new FileStream(m_Index.GetCatalogFileForZone(loadPos.ZoneId), FileMode.Open, FileAccess.Read))
                using (BinaryReader rdr = new BinaryReader(fs))
                {
            #if ASTROMETRY_DEBUG
                    Trace.Assert(fs.Length >= (loadPos.FromRecordId + 1) * 88);
            #endif
                    uint currStarInBin = loadPos.FromRecordId - 1;
                    fs.Position = 88 * loadPos.FromRecordId;

                    for (int i = 0; i < loadPos.ToRecordId - loadPos.FromRecordId; i++)
                    {
                        currStarInBin++;

            #if ASTROMETRY_DEBUG
                        Trace.Assert(fs.Position  % 88 == 0);
            #endif

                        fs.Seek(44, SeekOrigin.Current);
                        double mag = rdr.ReadInt32() / 1000.0; /* V Mag */
                        int byteDiff = 0;
                        if (mag == 30000.0)
                        {
                            mag = rdr.ReadInt32() / 1000.0; /* R Mag */
                            byteDiff = 4;
                        }

                        if (mag > limitMag)
                        {
                            fs.Seek(40 - byteDiff, SeekOrigin.Current);
                            continue;
                        }

                        fs.Seek(-(48 + byteDiff), SeekOrigin.Current);
                        NOMADEntry entry = new NOMADEntry();
                        byte[] rawData = rdr.ReadBytes(NOMADEntry.Size);

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

                        if (entry.RAJ2000 >= zone.RAFrom &&
                            entry.RAJ2000 <= zone.RATo)
                        {
                            entry.InitNOMADEntry(loadPos.FirstStarNoInBin + currStarInBin, (uint)loadPos.ZoneId, currStarInBin);
                            starsFromThisZone.Add(entry);
                        }
                    }
                }
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
        }