LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading a binary file of numerics with varying datatypes

Solved!
Go to solution

I know you have said that you don't know the format until Run Time (when, I gather, you determine the number of bytes in the file, factor it to "guess at" the number of bytes in a row, then read a few "putative rows", "guess" at the formats, and decide, at Run Time, what they are.  Then you can indulge one of the "read and format every set of bytes in the file into an Array of Clusters" -- you need to use Clusters unless you know that your Rows are all the same type, manifestly not true in your examples having elements of different Byte sizes.

 

I was hoping to "build a cluster on the fly" (which I can do, but then can't use that "just-built" Cluster in a Read command, at least I haven't yet figured out how to).  But if you have a small number (say, 5) possible formats, you can create 5 candidate Clusters, then do a "BS All-At-Once Read" with the appropriate Cluster, returning the appropriate Array of Clusters, and you're done.

 

To illustrate once more (then I'll shut up), here is your 2500-row, 9 Dbl, file read into a Data Array.  Note that this requires only 1 LabVIEW function, namely a single Read Data from Binary File.  It is also pretty fast -- as the Front Panel shows, it took 4 milliseconds to read all 2500 rows of 9 columns.  Note that "Data Record", shown on the Front Panel, is the Cluster (I would make it a TypeDef and not put it on the Front Panel, but this is for illustration) that rules them all.  You don't see the Element Labels on the Array of Clusters because I chose not to show them.

Binary Read FP.pngBinary Read BD.png

0 Kudos
Message 21 of 21
(380 Views)