02-14-2025 03:02 PM
I have a single array of cluster. I want to write the single array of cluster to file (maybe some of you remember this from last week). But it's possible I don't want all the data in the cluster written to file. But I also want to maintain the datatypes. Is the following madness? Deleting elements of a cluster? Do clusters just not work that way?
02-14-2025 03:07 PM
@LuminaryKnight wrote:
I have a single array of cluster. I want to write the single array of cluster to file (maybe some of you remember this from last week). But it's possible I don't want all the data in the cluster written to file. But I also want to maintain the datatypes. Is the following madness? Deleting elements of a cluster? Do clusters just not work that way?
Not unless the VI that serializes the Array of Cluster data to file supports it. The alternative is to create another Array of clusters with only the required elements by writing code that uses VI scripting to achieve this format A to format B conversion.
02-14-2025 03:11 PM
@santo_13 wrote:
Not unless the VI that serializes the Array of Cluster data to file supports it. The alternative is to create another Array of clusters with only the required elements by writing code that uses VI scripting to achieve this format A to format B conversion.
Yeah, I was thinking about doing it the alternative route. Where a boolean array determines desired values and that there's a VI for each scenario... which is a lot of scenarios.
02-14-2025 03:21 PM
@LuminaryKnight wrote:
I have a single array of cluster. I want to write the single array of cluster to file (maybe some of you remember this from last week). But it's possible I don't want all the data in the cluster written to file. But I also want to maintain the datatypes. Is the following madness? Deleting elements of a cluster? Do clusters just not work that way?
You asked the wrong question -- the problem is not that "clusters don't work that way", it is that arrays don't work that way. In an Array, every element must be the same type, so if it is an Array of MyCluster, every element of the Array must be a "full member" of Type "My Cluster". [Note -- if you use Clusters in your code, you will greatly help yourself if you create a TypeDef for your Cluster and refer to it by the name of the TypeDef. Not only does this enforce the principle that the Cluster is a "thing", it allows you (especially if you create an Icon for the Cluster that you can recognize) makes it easy to spot the Cluster in your code by getting it to display its Icon].
Try this:
Look at the resulting array (but predict what you'll see before you try this ...)
Bob Schor (all of whose Clusters have a TypeDef)
02-14-2025 03:28 PM - edited 02-14-2025 03:32 PM
@Bob_Schor wrote:
You asked the wrong question -- the problem is not that "clusters don't work that way", it is that arrays don't work that way. In an Array, every element must be the same type, so if it is an Array of MyCluster, every element of the Array must be a "full member" of Type "My Cluster". [Note -- if you use Clusters in your code, you will greatly help yourself if you create a TypeDef for your Cluster and refer to it by the name of the TypeDef. Not only does this enforce the principle that the Cluster is a "thing", it allows you (especially if you create an Icon for the Cluster that you can recognize) makes it easy to spot the Cluster in your code by getting it to display its Icon].
Bob Schor (all of whose Clusters have a TypeDef)
Oh, I love clusters. And I hate clusters that aren't TypeDef... and try very hard not to judge developers who refuse to take the time to typedef them. One of LabVIEW's greatest features, imo.
But I'd say you could argue there are 2 types of clusters.
When I started learning about Object Oriented programming, I struggled with understanding the difference/purpose of objects versus clusters. I thought, these are just clusters, which they still technically are. My point: you can have cluster that represents 2D array, or a cluster that is essentially an object.
Maybe NI/LabVIEW should enforce this difference. Remove "cluster" and call the 2D array version a grouping where we have the power to remove elements and the other call an object. Just... you'd never end up using it to inherit from. But you'd have the option. This might could be to the benefit of many developers. Where you essentially enforce Object Oriented mindset.
02-14-2025 03:39 PM
You could (possibly) make this work with OO. Create an Object "Array of 3 Dbl" and Object "Array of 5 Dbl", then you could make an array of these Objects, and at run time, handle the "3 Dbl" and "5 Dbl" separately. But don't forget to make "Array of 6 Dbl", and if the "3 Dbl" came from the middle 3 elements of the "5 Dbl" on one call, and the first three elements on another call, how are you going to handle that? It is spelled "N", "I", "G", "H", "T", "mare".
Bob Schor
02-14-2025 03:43 PM
@Bob_Schor wrote:
You could (possibly) make this work with OO. Create an Object "Array of 3 Dbl" and Object "Array of 5 Dbl", then you could make an array of these Objects, and at run time, handle the "3 Dbl" and "5 Dbl" separately. But don't forget to make "Array of 6 Dbl", and if the "3 Dbl" came from the middle 3 elements of the "5 Dbl" on one call, and the first three elements on another call, how are you going to handle that? It is spelled "N", "I", "G", "H", "T", "mare".
Bob Schor
Yeah, I'm sitting here and I'm thinking... "I might just tell user/client... nope, you just get everything." The end.
02-14-2025 04:18 PM
@Bob_Schor wrote:
You could (possibly) make this work with OO. Create an Object "Array of 3 Dbl" and Object "Array of 5 Dbl", then you could make an array of these Objects, and at run time, handle the "3 Dbl" and "5 Dbl" separately. But don't forget to make "Array of 6 Dbl", and if the "3 Dbl" came from the middle 3 elements of the "5 Dbl" on one call, and the first three elements on another call, how are you going to handle that? It is spelled "N", "I", "G", "H", "T", "mare".
Bob Schor
I am playing with the idea of typecasting the Array of Cluster to Array of U8, where there I can delete columns/rows of undesired data before sending to binary file. This might have merit with results I'm seeing so far.
02-14-2025 04:54 PM - edited 02-14-2025 05:00 PM
@LuminaryKnight wrote:
I am playing with the idea of typecasting the Array of Cluster to Array of U8, where there I can delete columns/rows of undesired data before sending to binary file. This might have merit with results I'm seeing so far.
Since LabVIEW is a fully featured programming language, you can do anything you want. All you need to do is implement the saving to file where you remove unwanted data as well as restoring from file, where you convert back to array of clusters in a way to only touch the saved elements. Still, seems like unneeded complications....
02-17-2025 03:18 AM
@LuminaryKnight wrote:
I have a single array of cluster. I want to write the single array of cluster to file (maybe some of you remember this from last week). But it's possible I don't want all the data in the cluster written to file. But I also want to maintain the datatypes. Is the following madness? Deleting elements of a cluster? Do clusters just not work that way?
The simple solution is to remove the element from the cluster (which i assume/hope is type def'd), but that might mess up other parts of your program. So the 2nd option is to simply filter the data before saving it to file, and if you want it dynamic, you'll have some ini-file where you write down which elements should go into the result file.