示例#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);
            }
        }
示例#2
0
        private void LoadStars(SearchZone zone, double limitMag, List<IStar> starsFromThisZone)
        {
            List<LoadPosition> searchIndexes = m_Index.GetLoadPositions(zone);

            foreach (LoadPosition pos in searchIndexes)
            {
                string fileName;
                fileName = Path.Combine(m_CatalogLocation, string.Format("{0}{1}{2}.dat", pos.Hemisphere, pos.ZoneId.ToString("00"), pos.SubZoneId));

                long positionFrom = (pos.FromRecordId + 1 /* for the header row */) * PPMXLEntry.Size;
                uint numRecords = pos.ToRecordId - pos.FromRecordId;

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

                    for (int i = 0; i < numRecords; i++)
                    {
                        byte[] data = rdr.ReadBytes(PPMXLEntry.Size);

                        PPMXLEntry entry = new PPMXLEntry(Encoding.ASCII.GetString(data));

                        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);
                    }
                }
            }
        }
示例#3
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);
            }
        }
示例#4
0
 private void LoadStars(SearchZone zone, double limitMag, List<IStar> starsFromThisZone)
 {
     List<LoadPosition> loadPositions = m_Index.GetLoadPositions(zone);
     foreach (LoadPosition loadPos in loadPositions)
     {
         LoadStarsBrighterThan(zone, loadPos, limitMag, starsFromThisZone);
     }
 }
示例#5
0
        public void _5_TestLoadPositions()
        {
            PPMXLIndex index = PPMXLIndex.GetIndex(CATALOG_LOCATION);

            for (int i = -90 * 4; i < 90 * 4; i++)
            {
                double zoneDeclFrom = i / 4.0;
                double zoneDeclTo = (i + 1) / 4.0;

                double declFrom = i / 4.0 + 0.1;
                double declTo = i / 4.0 + 0.2;
                double raFrom = 1;
                double raTo = 3;

                int fromZone = (int)Math.Floor(((declFrom + 90) * 4));
                int toZone = (int)Math.Ceiling(((declTo + 90) * 4)) - 1;

                Assert.AreEqual(fromZone, toZone);

                var zone = new SearchZone()
                {
                    RAFrom = raFrom,
                    RATo = raTo,
                    DEFrom = declFrom,
                    DETo = declTo
                };

                List<LoadPosition> loadPositions = index.GetLoadPositions(zone);

                foreach (LoadPosition pos in loadPositions)
                {
                    string fileName;
                    fileName = Path.Combine(CATALOG_LOCATION, string.Format("{0}{1}{2}.dat", pos.Hemisphere, pos.ZoneId.ToString("00"), pos.SubZoneId));

                    long firstPosition = (pos.FromRecordId + 1 /* for the header row */) * PPMXLEntry.Size;
                    long lastPosition = (pos.ToRecordId - 1 + 1 /* for the header row */) * PPMXLEntry.Size;

                    Console.Write(string.Format("{0}{1}{2} ...", pos.Hemisphere, pos.ZoneId.ToString("00"),pos.SubZoneId));

                    using (FileStream fileStr = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                    using (BinaryReader rdr = new BinaryReader(fileStr))
                    {
                        rdr.BaseStream.Position = firstPosition;
                        byte[] data = rdr.ReadBytes(PPMXLEntry.Size);
                        PPMXLEntry entry = new PPMXLEntry(Encoding.ASCII.GetString(data));

                        Assert.IsTrue(entry.DEDeg >= zoneDeclFrom);
                        Assert.IsTrue(entry.DEDeg < zoneDeclTo);
                        Assert.IsTrue(entry.RADeg >= raFrom);
                        Assert.IsTrue(entry.RADeg < raTo);

                        rdr.BaseStream.Position = lastPosition;
                        data = rdr.ReadBytes(PPMXLEntry.Size);
                        entry = new PPMXLEntry(Encoding.ASCII.GetString(data));

                        Assert.IsTrue(entry.DEDeg >= zoneDeclFrom);
                        Assert.IsTrue(entry.DEDeg < zoneDeclTo);
                        Assert.IsTrue(entry.RADeg >= raFrom);
                        Assert.IsTrue(entry.RADeg < raTo);
                    }

                    Console.WriteLine("Ok.");
                }
            }
        }