예제 #1
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);
        }
예제 #2
0
        internal List <LoadPosition> GetLoadPositions(SearchZone zone)
        {
            List <LoadPosition> loadPositions = new List <LoadPosition>();

            int dirIdxFrom = Math.Min(Math.Max((int)Math.Floor((zone.DEFrom + 90) * 10), 0), 1799);
            int dirIdxTo   = Math.Max(Math.Min((int)Math.Ceiling((zone.DETo + 90) * 10) - 1, 1799), 0);

            int raIdxFrom = Math.Max((int)Math.Floor((zone.RAFrom * 5)), 0);
            int rsIdxTo   = Math.Min((int)Math.Ceiling((zone.RATo * 5)) + 1, 1800);

            for (int i = dirIdxFrom; i <= dirIdxTo; i++)
            {
                NOMADZoneIndex zoneIdx = GetZoneIndex(i);

                uint idxFrom = zoneIdx.RAIndex[raIdxFrom];
                uint idxTo   = zoneIdx.RAIndex[rsIdxTo];

                if (idxTo > idxFrom)
                {
                    loadPositions.Add(new LoadPosition(i, idxFrom, idxTo, m_NOMADFirstStarNoPerBin[i]));
                }
                else if (idxTo < idxFrom)
                {
#if ASTROMETRY_DEBUG
                    Trace.Assert(false);
#endif
                }
            }

            return(loadPositions);
        }
예제 #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
        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);
        }
예제 #6
0
        public LoadPosition(UCAC2Index index, UCAC2BinIndexEntry entry, SearchZone zone, bool bss)
        {
            this.ZoneId      = entry.ZoneId;
            FirstStarNoInBin = entry.LastStarNo - entry.TotalStarsInBin;

            if (bss)
            {
                if (zone.RADeciHoursFrom == 0)
                {
                    this.FromRecordId = 1;
                }
                else
                {
                    this.FromRecordId = index.BSSRAIndexPerZone[entry.ZoneId - 1, zone.RADeciHoursFrom - 1] -
                                        FirstStarNoInBin;
                }

                if (zone.RADeciHoursTo == 0)
                {
                    this.ToRecordId = 1;
                }
                else
                {
                    this.ToRecordId = index.BSSRAIndexPerZone[entry.ZoneId - 1, zone.RADeciHoursTo - 1] -
                                      (entry.LastStarNo - entry.TotalStarsInBin);
                }
            }
            else
            {
                if (zone.RADeciHoursFrom == 0)
                {
                    this.FromRecordId = 1;
                }
                else
                {
                    this.FromRecordId = index.RAIndexPerZone[entry.ZoneId - 1, zone.RADeciHoursFrom - 1] -
                                        FirstStarNoInBin;
                }

                if (zone.RADeciHoursTo == 0)
                {
                    this.ToRecordId = 1;
                }
                else
                {
                    this.ToRecordId = index.RAIndexPerZone[entry.ZoneId - 1, zone.RADeciHoursTo - 1] -
                                      (entry.LastStarNo - entry.TotalStarsInBin);
                }
            }
            BSS = bss;
        }
예제 #7
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);
                        }
                    }
            }
        }
예제 #8
0
        internal List<LoadPosition> GetLoadPositions(SearchZone zone)
        {
            List<LoadPosition> loadPositions = new List<LoadPosition>();

            int dirIdxFrom = Math.Min(Math.Max((int) Math.Floor((zone.DEFrom + 90) * 10), 0), 1799);
            int dirIdxTo = Math.Max(Math.Min((int)Math.Ceiling((zone.DETo + 90) * 10) - 1, 1799), 0);

            int raIdxFrom = Math.Max((int)Math.Floor((zone.RAFrom * 5)), 0);
            int rsIdxTo = Math.Min((int)Math.Ceiling((zone.RATo * 5)) + 1, 1800);

            for (int i = dirIdxFrom; i <= dirIdxTo; i++)
            {
                NOMADZoneIndex zoneIdx = GetZoneIndex(i);

                uint idxFrom = zoneIdx.RAIndex[raIdxFrom];
                uint idxTo = zoneIdx.RAIndex[rsIdxTo];

                if (idxTo > idxFrom)
                    loadPositions.Add(new LoadPosition(i, idxFrom, idxTo, m_NOMADFirstStarNoPerBin[i]));
                else if (idxTo < idxFrom)
                {
            #if !PRODUCTION
                    Trace.Assert(false);
            #endif
                }
            }

            return loadPositions;
        }
예제 #9
0
        public LoadPosition(UCAC2Index index, UCAC2BinIndexEntry entry, SearchZone zone, bool bss)
        {
            this.ZoneId = entry.ZoneId;
            FirstStarNoInBin = entry.LastStarNo - entry.TotalStarsInBin;

            if (bss)
            {
                if (zone.RADeciHoursFrom == 0)
                    this.FromRecordId = 1;
                else
                    this.FromRecordId = index.BSSRAIndexPerZone[entry.ZoneId - 1, zone.RADeciHoursFrom - 1] -
                                        FirstStarNoInBin;

                if (zone.RADeciHoursTo == 0)
                    this.ToRecordId = 1;
                else
                    this.ToRecordId = index.BSSRAIndexPerZone[entry.ZoneId - 1, zone.RADeciHoursTo - 1] -
                                      (entry.LastStarNo - entry.TotalStarsInBin);
            }
            else
            {
                if (zone.RADeciHoursFrom == 0)
                    this.FromRecordId = 1;
                else
                    this.FromRecordId = index.RAIndexPerZone[entry.ZoneId - 1, zone.RADeciHoursFrom - 1] -
                                        FirstStarNoInBin;

                if (zone.RADeciHoursTo == 0)
                    this.ToRecordId = 1;
                else
                    this.ToRecordId = index.RAIndexPerZone[entry.ZoneId - 1, zone.RADeciHoursTo - 1] -
                                      (entry.LastStarNo - entry.TotalStarsInBin);
            }
            BSS = bss;
        }
예제 #10
0
 public LoadPosition(UCAC2Index index, UCAC2BinIndexEntry entry, SearchZone zone)
     : this(index, entry, zone, false)
 {
 }
예제 #11
0
        internal List<LoadPosition> GetLoadPositions(SearchZone zone)
        {
            List<LoadPosition> searchPositions = new List<LoadPosition>();

            UCAC2BinIndexEntry lastEntry = null;

            for (int i = 0; i < ZoneIndex.Length; i++)
            {
                UCAC2BinIndexEntry entry = ZoneIndex[i];

                if (zone.DEFrom > entry.DEFrom)
                {
                    lastEntry = entry;
                    continue;
                }

                if (lastEntry != null) entry = lastEntry;

                // Add one position
                LoadPosition pos = new LoadPosition(this, entry, zone);
                searchPositions.Add(pos);

                while (zone.DETo > entry.DETo)
                {
                    if (entry.ZoneId < ZoneIndex.Length)
                    {
                        entry = ZoneIndex[entry.ZoneId];
                        // Add another position
                        LoadPosition pos2 = new LoadPosition(this, entry, zone);
                        searchPositions.Add(pos2);
                    }
                }

                break;
            }

            lastEntry = null;
            for (int i = 0; i < BSSZoneIndex.Length; i++)
            {
                UCAC2BinIndexEntry entry = BSSZoneIndex[i];

                if (zone.DEFrom > entry.DEFrom)
                {
                    lastEntry = entry;
                    continue;
                }

                if (lastEntry != null) entry = lastEntry;

                // Add one position
                LoadPosition pos = new LoadPosition(this, entry, zone, true);
                searchPositions.Add(pos);

                while (zone.DETo > entry.DETo)
                {
                    if (entry.ZoneId < BSSZoneIndex.Length)
                    {
                        entry = BSSZoneIndex[entry.ZoneId];
                        // Add another position
                        LoadPosition pos2 = new LoadPosition(this, entry, zone, true);
                        searchPositions.Add(pos2);
                    }
                }

                break;
            }

            return searchPositions;
        }
예제 #12
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;
        }
예제 #13
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);
            }
        }
예제 #14
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;
        }
예제 #15
0
 public LoadPosition(UCAC2Index index, UCAC2BinIndexEntry entry, SearchZone zone)
     : this(index, entry, zone, false)
 {
 }
예제 #16
0
        internal List <LoadPosition> GetLoadPositions(SearchZone zone)
        {
            List <LoadPosition> searchPositions = new List <LoadPosition>();

            UCAC2BinIndexEntry lastEntry = null;

            for (int i = 0; i < ZoneIndex.Length; i++)
            {
                UCAC2BinIndexEntry entry = ZoneIndex[i];

                if (zone.DEFrom > entry.DEFrom)
                {
                    lastEntry = entry;
                    continue;
                }

                if (lastEntry != null)
                {
                    entry = lastEntry;
                }

                // Add one position
                LoadPosition pos = new LoadPosition(this, entry, zone);
                searchPositions.Add(pos);

                while (zone.DETo > entry.DETo)
                {
                    if (entry.ZoneId < ZoneIndex.Length)
                    {
                        entry = ZoneIndex[entry.ZoneId];
                        // Add another position
                        LoadPosition pos2 = new LoadPosition(this, entry, zone);
                        searchPositions.Add(pos2);
                    }
                }

                break;
            }

            lastEntry = null;
            for (int i = 0; i < BSSZoneIndex.Length; i++)
            {
                UCAC2BinIndexEntry entry = BSSZoneIndex[i];

                if (zone.DEFrom > entry.DEFrom)
                {
                    lastEntry = entry;
                    continue;
                }

                if (lastEntry != null)
                {
                    entry = lastEntry;
                }

                // Add one position
                LoadPosition pos = new LoadPosition(this, entry, zone, true);
                searchPositions.Add(pos);

                while (zone.DETo > entry.DETo)
                {
                    if (entry.ZoneId < BSSZoneIndex.Length)
                    {
                        entry = BSSZoneIndex[entry.ZoneId];
                        // Add another position
                        LoadPosition pos2 = new LoadPosition(this, entry, zone, true);
                        searchPositions.Add(pos2);
                    }
                }

                break;
            }

            return(searchPositions);
        }