示例#1
0
        public static void BuildFullIndex(string catalogLocation)
        {
            int idx = -1;
            IEnumerator<string> filesEnu = PPMXLFileIterator.PPMXLFiles(catalogLocation);
            string fileNameIndex = catalogLocation + "zones.idx";

            if (File.Exists(fileNameIndex))
            {
                MessageBox.Show(string.Format("Index file {0} already exists.", fileNameIndex));
                return;
            }

            using (FileStream fs = new FileStream(fileNameIndex, FileMode.Create, FileAccess.Write))
            using (BinaryWriter bwrt = new BinaryWriter(fs))
            {
                while (filesEnu.MoveNext())
                {
                    string fileName = filesEnu.Current;
                    Console.WriteLine(fileName);
                    idx++;

                    int[] raIdx = new int[360];
                    int raCurr = 0;
                    int recNo = -1;

                    using (FileStream fileStr = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                    using (BinaryReader rdr = new BinaryReader(fileStr))
                    {
                        byte[] header = rdr.ReadBytes(174);
                        while (true)
                        {
                            recNo++;

                            byte[] data = rdr.ReadBytes(174);
                            if (data == null || data.Length == 0) break;

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

                            while (raTrunc >= raCurr)
                            {
                                //Console.WriteLine("Index[" + raCurr.ToString() + "] = " + recNo.ToString());
                                if (raCurr < 360) raIdx[raCurr] = recNo;
                                raCurr++;
                            }
                        }
                    }

                    while (360 > raCurr)
                    {
                        //Console.WriteLine("Index[" + raCurr.ToString() + "] = " + (recNo - 1).ToString());
                        raIdx[raCurr] = recNo - 1;
                        raCurr++;
                    }

                    for (int j = 0; j < 360; j++)
                    {
                        bwrt.Write(raIdx[j]);
                    }
                }

                bwrt.Flush();
            }
        }
示例#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);
                    }
                }
            }
        }