/// <summary> /// Copys a preexisting seismic file except for sample values in each traces and populates /// each trace with sample values specified by an input arguemnt at runtime /// </summary> /// <param name="destinationFileInfo">The file info of the new file to copy to</param> /// <param name="sourceFileInfo">The old Sgy file info to copy headers from</param> /// <param name="sampleValue">The sample value to populate all trace data with</param> /// <returns>The new sgy file</returns> public static SgyFile CopyPopulated(FileInfo sourceFileInfo, FileInfo destinationFileInfo, float sampleValue = 0.0f) { if (destinationFileInfo.Exists == true) { destinationFileInfo.Delete(); } destinationFileInfo = sourceFileInfo.FastCopy(destinationFileInfo); SgyFile newSgyFile = SgyFile.Open(destinationFileInfo); float[] buffer = new float[newSgyFile.BinaryFileHeader.SamplesPerTraceOfFile]; if (sampleValue != 0) { for (int i = 0; i < buffer.Length; i++) { buffer[i] = sampleValue; } } for (long ti = 0; ti < newSgyFile.TraceCount; ti++) { newSgyFile.Write(buffer, ti); } return(newSgyFile); }
/// <summary> /// Creates a new Sgy file /// </summary> /// <param name="fileInfo">The file info</param> /// <param name="textHeader">The ebcdic or ascii encoded (worthless to have different encodings) text header </param> /// <param name="textHeaderEncoding">The encoding type for the text header</param> /// <param name="header">The file binary header</param> /// <param name="endianBitConverter">A converter to accomodate little endian vs big endian bit conversion</param> /// <param name="overwrite">Should overwrite file on creation?</param> /// <returns>An instance of Sgy file</returns> public static SgyFile Create(FileInfo fileInfo, string textHeader, Encoding textHeaderEncoding, FileHeader header, EndianBitConverter endianBitConverter, bool overwrite = false) { if (fileInfo == null) { throw new ArgumentNullException("File info cannot be null"); } if (textHeader == null) { throw new ArgumentNullException("Text header cannot be null"); } if (textHeaderEncoding == null) { throw new ArgumentNullException("Text header encoding cannot be null"); } if (textHeader.Length > TextHeaderBytesCount) { throw new ArgumentException("The text header contains more than 3200 characters"); } if (endianBitConverter == null) { throw new ArgumentNullException("Endian bit converter cannot be null"); } if (fileInfo.Exists && overwrite == false) { throw new ArgumentException($"File {fileInfo.FullName} already exists. Please delete first, or select overwrite = true"); } if (overwrite == true) { fileInfo.Delete(); } var fileStream = new FileStream(fileInfo.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite); var conditionedTextHeader = HandleTextHeader(textHeader); var textHeaderBytes = textHeaderEncoding.GetBytes(conditionedTextHeader); var binHeaderBytes = header.ToBytes(endianBitConverter); fileStream.Write(textHeaderBytes, 0, TextHeaderBytesCount); fileStream.Write(binHeaderBytes, 0, BinaryHeaderBytesCount); fileStream.Flush(); SgyFile file = new SgyFile(fileStream, new string[] { conditionedTextHeader }, textHeaderEncoding, header, endianBitConverter); return(file); }