From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read binary file

Solved!
Go to solution

Hello,

 

I have a binary file that represents a 2D array of values.  I have attached the example code that I have tried, an example file and an image of what it should look like.

 

I'm stuck on this one and not sure what to do from here.  Any help would be greatly appreciated.

0 Kudos
Message 1 of 16
(2,770 Views)

What is the datatype and byte order? I don't think there is a size header. Do you know the 2D dimensions?

What application generated the file?

0 Kudos
Message 2 of 16
(2,752 Views)
Solution
Accepted by topic author coolhandLV7

Hi coolhand,

 

it would have been nice to provide a description of the file format of your data…

 

Idea:

 

Your data contain a header of 4 bytes, holding two 16bit values. Most probably the dimensions of your image data.

The remaining data contain SGL values with little-endian notation. This could be the image data.

As the file contains 3 times the number of SGL values than there are pixels (according to header information) I guess triplets of SGL values contain RGB data in an unsual way (or any other color encoding scheme).

I just picked the "inner" block of 1001×1001 values as all other elements are set to a value of -1…

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 16
(2,748 Views)

 think the datatype and byte order is int16.  The data comes from an ISRA deflectometer, SoftPMD is the software that is used.

0 Kudos
Message 4 of 16
(2,745 Views)

Thanks for the response, looks like you cracked it.  

 

Unfortunately I didn't know what the file format was, just knew it was binary.

 

How can I learn more about this, meaning I'd rather learn how to fish than be given a fish?  Are there examples to look at or anything that would help me figure this out?  There is no way I would have cracked this, I haven't worked with binary files before.

 

As for the triplets, the data is XYZ data

0 Kudos
Message 5 of 16
(2,729 Views)

NVM

0 Kudos
Message 6 of 16
(2,719 Views)

Hi coolhand,

 

the function before the intensity graph is ReshapeArray.

Edit: instead of replacing your question with "NVM" you could also use the strike-through formatting and write the answer yourself...

 

On the file format: you "just" need experience... 

I started programming with BASIC and switched rather fast to Assembler. With Assembler you learn quickly to "read" hexadecimal values. After switching from 8bit to 32bit CPUs I also gained experience in reading 16bit integers as well as recognizing typical SGL and DBL entities...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 16
(2,713 Views)

I have the code working and displaying something close to what is expected.  I have filtered the (-1) values and replaced them with NaN.  The issue that i'm finding is that the data is out of order, you can see in the image that the small chunk at the right should be all the way on the left.  I have no idea how this happens.  Anyone have any ideas on why this small chunk would be our of order?

 

I have attached the image raw data image and the LV intensity plot image.  

Download All
0 Kudos
Message 8 of 16
(2,670 Views)

Hi coolhand,

 


@coolhandLV7 wrote:

The issue that i'm finding is that the data is out of order, you can see in the image that the small chunk at the right should be all the way on the left.  I have no idea how this happens.  Anyone have any ideas on why this small chunk would be our of order?


Several options:

  1. You made something wrong in your VI. As you didn't attach your VI we cannot test this…
  2. The data format of your files is somewhat more complicated then just a large array of SGL values. Due to this "more complicated" you need to arrange the SGL data in a different way…

Item 1 is easy to check.

Item 2 is also easy to test once you provide a full description of the format of your data files…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 16
(2,665 Views)

Same vi that you created, all i did was pull the -1 values from the data set.  You can see the same chunk in your intensity plot also.  It's weird though because the data appears in the correct order on the 2D plot.

 

As far as i know, the data type is I16, data order is I16 and there is a 4-byte float after that (SGL)

0 Kudos
Message 10 of 16
(2,661 Views)