Ejemplo n.º 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(UCAC3Entry)));
            try
            {
                foreach (LoadPosition pos in searchIndexes)
                {
                    string fileName;
                    fileName = Path.Combine(m_CatalogLocation, string.Format("z{0}", pos.ZoneId.ToString("000")));

                    long positionFrom = (pos.FromRecordId - 1) * UCAC3Entry.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++)
                            {
                                UCAC3Entry entry = new UCAC3Entry();
                                byte[] rawData = rdr.ReadBytes(UCAC3Entry.Size);

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

                                entry.InitUCAC3Entry((ushort)pos.ZoneId, 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);
            }
        }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 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 !PRODUCTION
                    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 !PRODUCTION
                        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);
            }
        }
Ejemplo n.º 4
0
        public List<LoadPosition> GetLoadPositions(SearchZone zone)
        {
            List<LoadPosition> loadPositions = new List<LoadPosition>();

            int deltaFrom = zone.DEFrom > 0 ? 1 : 0;
            int deltaTo = zone.DETo > 0 ? 1 : 0;

            int fromZone = Math.Max(1, (int)(zone.DEFrom * 5) + 90 * 5 + deltaFrom);
            int toZone = Math.Min(900, (int)(zone.DETo * 5) + 90 * 5 + deltaTo);

            for (int zoneId = fromZone; zoneId <= toZone; zoneId++)
            {
                LoadPosition loadPos = new LoadPosition();
                loadPos.ZoneId = zoneId;
                loadPos.FirstStarNoInBin = 0;
                int raFrom = Math.Max(0, (int)Math.Floor(zone.RAFrom));
                int raTo = Math.Min(360, (int)Math.Ceiling(zone.RATo) + 1);
                loadPos.FromRecordId = (uint)ZoneIndex[zoneId - 1].RAStartPositions[raFrom];
                if (raTo == 360)
                    loadPos.ToRecordId = (uint)ZoneIndex[zoneId - 1].TotalStarsInZone;
                else
                    loadPos.ToRecordId = (uint)ZoneIndex[zoneId - 1].RAStartPositions[raTo];

                loadPositions.Add(loadPos);
            }

            return loadPositions;
        }
Ejemplo n.º 5
0
        internal List<LoadPosition> GetLoadPositions(SearchZone zone)
        {
            List<LoadPosition> loadPositions = new List<LoadPosition>();

            int signDEFrom = Math.Sign(zone.DEFrom);

            int fromZone, toZone;
            bool isSouth = signDEFrom < 0;

            fromZone = (int)Math.Floor(((zone.DEFrom + 90) * 4));
            toZone = (int)Math.Ceiling(((zone.DETo + 90) * 4));

            for (int zoneId = fromZone; zoneId < toZone; zoneId++)
            {
                LoadPosition loadPos = new LoadPosition();

                if (zoneId == 359)
                {
                    loadPos.ZoneId = 0;
                    loadPos.SubZoneId = 'a';
                    loadPos.Hemisphere = 's';
                }
                else if (zoneId == 360)
                {
                    loadPos.ZoneId = 0;
                    loadPos.SubZoneId = 'a';
                    loadPos.Hemisphere = 'n';
                }
                else
                {
                    if (isSouth)
                    {
                        loadPos.ZoneId = 89 - (zoneId / 4);
                        loadPos.SubZoneId = "dcba"[zoneId % 4];
                        loadPos.Hemisphere = 's';
                    }
                    else
                    {
                        loadPos.ZoneId = (zoneId / 4) - 90;
                        loadPos.SubZoneId = "abcd"[zoneId % 4];
                        loadPos.Hemisphere = 'n';
                    }
                }

                int raFrom = Math.Max(0, (int)Math.Floor(zone.RAFrom));
                int raTo = Math.Min(359, (int)Math.Ceiling(zone.RATo));

                loadPos.FromRecordId = (uint)ZoneIndex[zoneId].RAIndex[raFrom];
                loadPos.ToRecordId = (uint)ZoneIndex[zoneId].RAIndex[raTo];

                loadPositions.Add(loadPos);
            }

            return loadPositions;
        }
Ejemplo n.º 6
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);
                    }
                }
            }
        }