LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
krivan

Read boolean array from file

Status: Declined
Functionality already exists in LabVIEW.

I have built this simple VI below to read a string from a text file and then convert it into boolean array. I suggest to have a VI that reads the content of a file as boolean array. This functionality would be beneficial for people who have to deal with for example large arrays of sensors. You think of a special addressing pattern, you write it in a text file and you could read it in with one simple VI and then you can transfer the read boolean array directly to the digital output of your device.

7 Comments
Mads
Active Participant

This is already available. You can specify what the read function should read the file data as. If e.g. you wire an integer to the data type input of the read binary file function and specify a length (count), then the output of the read will be an array of integers of the given size. You can do this with all kinds of data types, and you can also specify the count as a cluster of integers to get multidimensional arrays out.

 

readArray.png

altenbach
Knight of NI

Your picture shows "read from spreadsheet file", which reads "zeroes" as FALSE and "not zeroes" as TRUE and then coverts them to a 2D boolean array. You are making very specific assumptions about the structure of the file that are not universal. NI wold also need to provide a "write to spreadsheet file" that makes exactly the same assumptions about the format.

 

A spreadsheet file of this format is more than 20-30 times to inflated, because a single bit is sufficient to represent a boolean, so a single U8 number could hold 8 booleans if done correctly. You waste at least an entire byte for the number, a few bytes for the delimiter, and extra bytes for linefeeds.

 

I think the suggestion is too specialized. LabVIEW already provides all the tools to do this efficiently with minimal coding.

 

 

 

 

G-Money
NI Employee (retired)
Status changed to: Declined
Functionality already exists in LabVIEW.
X.
Trusted Enthusiast
Trusted Enthusiast

@Mads: Where the heck did you find that secret feature about the Count parameter? If I read the help for that function:

 

count (1) is the number of data elements to read. Data elements can be bytes or instances of data type. The function returns count data elements in data, or if it reaches the end of the file, it returns all the complete data elements read thus far and an end-of-file error. By default, the function returns a single data element. If count is –1, the function reads the entire file. If count is less than –1, the function returns an error.

If count calls for an array of elements and the specified data type is an array, the function automatically returns a cluster of arrays or cluster array because LabVIEW does not allow arrays of arrays.

 

There is nowhere mention of this size cluster trick (the last sentence can't be hinting at that, or is it?)!

NI, it's so unfair to hide all these goodies from us basic users ... 🙂

Mads
Active Participant

The dimensions cluster is a goodie yes Smiley Happy I'm not sure where I picked it up as it must have been a long time ago, but I believe it was from one of the examples shipping with LV. Such things should definitely be more out in the open though.

altenbach
Knight of NI

I agree that the cluster option for "count" should be documented.

 

However, if you stay within LabVIEW, an easier option is to "prepend array or string size" when writing the binary file (default is already true). Now you can simply wire an empty 3D array as type and it will read the entire file correctly as 3D array. In this case, don't wire the count terminal to get a 3D array directly. (If you wire the count terminal, you get a 1D array of cluster of 3D array).

AristosQueue (NI)
NI Employee (retired)

A documentation bug report was filed to update the documentation for this terminal.