LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Large Binary file to array

Hi,

I'm relatively new to Labview and am having trouble with large arrays. I'm using Win32 IO functions to read a 8MB file into Labview and this products a large U8 array. I want to produce a binary array containing the second bit of each byte in this array. For example:

 

File:00000000 00000010 00000000 00000010 00000010

Binary array: 01011

 

At the moment I'm using a For Loop and clearly its very inefficient. Is there any way to do the above in a relatively short period of time?

I used a subvi containing a For Loop and enabled Reentrant execution but this isnt very fast either. 

 

Any help would be greatly appreciated,

 

John

0 Kudos
Message 1 of 7
(4,087 Views)

I would use Build Array Function instead of Insert into Array.  It makes the code a little bit leaner.

Why not pack the boolean values into a boolean array instead of converting them back to integers and storing them in an integer array?

 

More efficient would be to initialize an array and use Replace Array Subset inside the loop.  Since you can determine the size of the array before the loop starts (you have the Length control defining the size of the array you want to work on), you can initialize an array of that size one time, then replace elements within the loop.  This is more efficient for large arrays as LabVIEW will not have to spend any time shuffling the array around in memory as it grows in size.

Message Edited by Ravens Fan on 07-07-2009 09:34 AM
Message 2 of 7
(4,076 Views)

John,

 

There are probably a million ways to get this done and you will have to experiment a lot to find one that is really fast and furious!  I attached one suggestion.

 

-cb

Message 3 of 7
(4,066 Views)
Wow. Thanks for the advice. Initializing the array and using Replace Array Subset really helps. I may need to convert boolean to (0,1) later but this is a vast improvement. Thanks.
0 Kudos
Message 4 of 7
(4,061 Views)

Hi John,

 

You can use boolean operators on integers. No need to convert to boolean array. To extract a bit, just AND with a constant with the bit in question set. Also, you don't need the loop.

See attached example.

 

ExtractBit.png

The quotient & remainder is one way to scale the resulting array to 1. Without this you'd get an array of 0's and 2's.

 

Hope this helps,

Daniel

 

EDIT: Sorry for repeating 10degree, I was distracted while writing the message

Message Edited by dan_u on 07-07-2009 03:52 PM
Message 5 of 7
(4,058 Views)

Thanks for the help. I'll implement all the solutions and Profile them to get the best result. I didn't expect such a fast response!

 

@dan_u thats really useful.

 

 

Edit:Typo

Message Edited by jm346 on 07-07-2009 08:58 AM
0 Kudos
Message 6 of 7
(4,047 Views)
Since you are playing around with large data sets, you may want to read Managing Large Data Sets in LabVIEW.  It does not mention the In Place element (which you should be using), but is good otherwise.
0 Kudos
Message 7 of 7
(3,999 Views)