Note that there are some explanatory texts on larger screens.

plurals
  1. POparse content away from structure in a binary file
    text
    copied!<p>Using C#, I need to read a packed binary file created using FORTRAN. The file is stored in an "Unformatted Sequential" format as described here (about half-way down the page in the "Unformatted Sequential Files" section):</p> <p><a href="http://www.tacc.utexas.edu/services/userguides/intel8/fc/f_ug1/pggfmsp.htm" rel="nofollow noreferrer">http://www.tacc.utexas.edu/services/userguides/intel8/fc/f_ug1/pggfmsp.htm</a></p> <p>As you can see from the URL, the file is organized into "chunks" of 130 bytes or less and includes 2 length bytes (inserted by the FORTRAN compiler) surrounding each chunk.</p> <p>So, I need to find an efficient way to parse the actual file payload away from the compiler-inserted formatting.</p> <p>Once I've extracted the actual payload from the file, I'll then need to parse it up into its varying data types. That'll be the next exercise.</p> <p>My first thoughts are to slurp up the entire file into a byte array using <code>File.ReadAllBytes</code>. Then, just iterate through the bytes, skipping the formatting and transferring the actual data to a second byte array. </p> <p>In the end, that second byte array should contain the actual file contents minus all the formatting, which I'd then need to go back through to get what I need.</p> <p>As I'm fairly new to C#, I thought there might be a better, more accepted way of tackling this.</p> <p>Also, in case it's helpful, these files could be fairly large (say 30MB), though most will be much smaller...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload