public bool ReadSclFile() // read complete file to _Stabclasses, _MO_Lenght and _Ustar { try { if (File.Exists(_filename)) { if (ReadGralFlowFields.CheckIfZippedFile(_filename)) // file zipped? { using (FileStream zipToOpen = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Read)) //open Zip archive { foreach (ZipArchiveEntry entry in archive.Entries) // search for a scl file { if (entry.FullName.Contains("scl")) { using (BinaryReader stability = new BinaryReader(entry.Open())) //OPen Zip entry { ReadValues(stability, ref _Stabclasses); } } if (entry.FullName.Contains("ust")) { using (BinaryReader stability = new BinaryReader(entry.Open())) //OPen Zip entry { ReadValues(stability, ref _Ustar); } } if (entry.FullName.Contains("obl")) { using (BinaryReader stability = new BinaryReader(entry.Open())) //OPen Zip entry { ReadValues(stability, ref _MOlength); } } } } } } else // not zipped { using (BinaryReader stability = new BinaryReader(File.Open(_filename, FileMode.Open))) { ReadValues(stability, ref _Stabclasses); } } } else { throw new FileNotFoundException(_filename + @"not found"); } return(true); // Reading OK } catch { return(false); } }
public int ReadSclFile(int x, int y) // read one value from *.scl { try { short temp = 0; if (File.Exists(_filename) && x >= 0 && y >= 0) { if (ReadGralFlowFields.CheckIfZippedFile(_filename)) // file zipped? { using (ZipArchive archive = ZipFile.OpenRead(_filename)) //open Zip archive { foreach (ZipArchiveEntry entry in archive.Entries) // search for a scl file { if (entry.FullName.Contains("scl")) { using (BinaryReader stability = new BinaryReader(entry.Open())) //OPen Zip entry { // read the header stability.ReadInt32(); int NI = stability.ReadInt32(); int NJ = stability.ReadInt32(); int NK = stability.ReadInt32(); _GRAMMhorgridsize = stability.ReadSingle(); long position = (x * NJ + y); // Position in bytes 20 Bytes = Header if (x < NI && y < NJ) { // Seek doesn't work in zipped files // stability.BaseStream.Seek(position, SeekOrigin.Begin); for (int i = 0; i < position; i++) // seek manually { stability.ReadInt16(); } temp = stability.ReadInt16(); // read this value } } } } } } else // not zipped { using (BinaryReader stability = new BinaryReader(File.Open(_filename, FileMode.Open))) { // read the header stability.ReadInt32(); int NI = stability.ReadInt32(); int NJ = stability.ReadInt32(); int NK = stability.ReadInt32(); _GRAMMhorgridsize = stability.ReadSingle(); long position = (x * NJ + y) * 2 + 20; // Position in bytes 20 Bytes = Header long lenght = stability.BaseStream.Length; // data set lenght if (position < lenght && x < NI && y < NJ) { stability.BaseStream.Seek(position, SeekOrigin.Begin); temp = stability.ReadInt16(); // read this value } } } } else { throw new FileNotFoundException(_filename + @"not found"); } return(temp); // Reading OK } catch { return(0); } }