public UCAC3Entry GetStarBy3U(int zone, int record) { IntPtr buffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(UCAC3Entry))); try { string fileName; fileName = Path.Combine(m_CatalogLocation, string.Format("z{0}", zone.ToString("000"))); long positionFrom = (record - 1) * UCAC3Entry.Size; using (FileStream str = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (BinaryReader rdr = new BinaryReader(str)) { rdr.BaseStream.Position = positionFrom; 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)zone, 0); return entry; } } } finally { Marshal.FreeHGlobal(buffer); } }
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); } }