public void _1_TestFirstEntry() { string fileName = Path.GetFullPath(CATALOG_LOCATION + "n89d.dat"); using(FileStream fileStr = new FileStream(fileName, FileMode.Open, FileAccess.Read)) using (BinaryReader rdr = new BinaryReader(fileStr)) { byte[] header = rdr.ReadBytes(174); byte[] firstLine = rdr.ReadBytes(174); PPMXLEntry entry = new PPMXLEntry(Encoding.ASCII.GetString(firstLine)); //#PPMXL_ID | RA (ICRS)Dec pmRA pmDE| epRA epDE eRA eDE epma epmd| Jmag:+/- Hmag:+/- Kmag:+/- |b1mag b2mag r1mag r2mag imag|bbrri|No|fl // 480381039136370330|000.031470+89.788187 +10.4 -6.7|1985.06 1985.06 89 89 4.2 4.2|16.229:0.126 15.708:0.180 15.497:0.223|19.73 20.28 17.96 18.32 17.35|02137| 6| 0 Assert.AreEqual(0.031470, entry.RADeg, 0.00000001); Assert.AreEqual(89.788187, entry.DEDeg, 0.00000001); Assert.AreEqual(10.4, entry.pmRA * Math.Cos(entry.DEDeg * Math.PI / 180), 0.0001); Assert.AreEqual(-6.7, entry.pmDE, 0.0001); Assert.AreEqual(16.229, entry.MagJ, 0.0001); Assert.AreEqual(15.497, entry.MagK, 0.0001); Assert.AreEqual((19.73 + 20.28) / 2, entry.MagB, 0.0001); Assert.AreEqual((17.96 + 18.32) / 2, entry.MagR, 0.0001); } }
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(); } }
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); } } } }
public void _3_Test_PPMXL_Index() { PPMXLIndex index = PPMXLIndex.GetIndex(CATALOG_LOCATION); Assert.IsNotNull(index); for (int i = 0; i < 2*360; i++) { PPMXLIndexEntry zoneIndex = index.ZoneIndex[i]; Assert.AreEqual(zoneIndex.UniqueZone, i); string fileName = Path.Combine(CATALOG_LOCATION, zoneIndex.FileName); using (FileStream str = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (BinaryReader rdr = new BinaryReader(str)) { byte[] header = rdr.ReadBytes(174); byte[] firstLine = rdr.ReadBytes(174); PPMXLEntry firstEntry = new PPMXLEntry(Encoding.ASCII.GetString(firstLine)); Console.WriteLine(string.Format("#{0} Zone:{1} 1stStarDE:{2} ZoneDERange[{3} | {4}] {5}", i + 1, zoneIndex.FileName, AstroConvert.ToStringValue(firstEntry.DEDeg, "DEC"), AstroConvert.ToStringValue(zoneIndex.DEFrom, "DEC"), AstroConvert.ToStringValue(zoneIndex.DETo, "DEC"), zoneIndex.ZoneId)); //Console.WriteLine(string.Format("{0}, AstroConvert.ToDeclination(\"{1}\"), AstroConvert.ToDeclination(\"{2}\"),", zoneIndex.UniqueZone, AstroConvert.ToStringValue(zoneIndex.DEFrom, "+DD:MM:SS"), AstroConvert.ToStringValue(zoneIndex.DETo, "+DD:MM:SS"))); Assert.IsTrue(firstEntry.DEDeg >= zoneIndex.DEFrom, string.Format("firstEntry.DECat ({0}) >= zoneIndex.DEFrom ({1})", firstEntry.DEDeg, zoneIndex.DEFrom)); Assert.IsTrue(firstEntry.DEDeg <= zoneIndex.DETo, string.Format("firstEntry.DECat ({0}) <= zoneIndex.DETo ({1})", firstEntry.DEDeg, zoneIndex.DETo)); for (int j = 0; j < 360; j++) { double entryMinOutsideRA = j - (1.0/36000); double entryMaxOutsideRA = j + 1; double entryMinInsideRA = j; int minEntryIndex = zoneIndex.RAIndex[j]; int nextRAZoneIndex = j < 359 ? zoneIndex.RAIndex[j + 1] : minEntryIndex; int prevEntryIndex = minEntryIndex - 1; rdr.BaseStream.Position = PPMXLEntry.Size*(minEntryIndex + 1); byte[] data = rdr.ReadBytes(174); PPMXLEntry minEntry = new PPMXLEntry(Encoding.ASCII.GetString(data)); if (!(minEntry.RADeg > entryMinOutsideRA)) { Assert.Fail(); } if (!(nextRAZoneIndex == minEntryIndex || minEntry.RADeg < entryMaxOutsideRA)) { Assert.Fail(); } if (prevEntryIndex >= 0) { rdr.BaseStream.Position = PPMXLEntry.Size*(prevEntryIndex + 1); data = rdr.ReadBytes(174); PPMXLEntry prevEntry = new PPMXLEntry(Encoding.ASCII.GetString(data)); if (!(prevEntry.RADeg < entryMinInsideRA)) { Assert.Fail(); } } } } } } }
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."); } } }