09-22-2019 04:34 PM
I have some data that is much easier to view in many circumstances as an Array of Cluster containing strings, 1d string arrays, and 2d string arrays. However, there are also lots of steps that are easier to handle/code when this same data is simply a single cluster with all the elements arrayed (1 dimension larger than in the array of cluster). Attached are pictures that hopefully illustrate what I mean. I could of course type def both the cluster that is in the array of cluster AND the cluster of arrays and make a subvi that can convert back and forth as needed. BUT, I don't like this idea because any change to one of the typedefs would require someone to know to change the other typedef also AND the conversion subvi. I'd really prefer to have the cluster (the one inside the array) to be a typedef, and have a conversion subvi that could handle conversion such that it wouldn't need to be updated if the typedef changes in anyway. Does this make sense?
Hope my pictures help with understanding.Notice cluster of arrays is the same data but with +1 dimension
Looking for a way to perform these two functions that isn't dependent on being updated if the Cluster (inside the array) typedef is changed and isn't reliant on a second typedef (cluster of arrays) to convert
I guess what I'm asking is, is there a way to programmatically make the "Cluster of Arrays" from the array of clusters in such a way that doesn't break if the cluster typedef (in array of clusters) changes.
09-22-2019 07:53 PM
No, (I am guessing you want to make a couple of VIM's), but you actually aren't gaining much since the code on the other side of the VI (output) still needs to know what the cluster type will be, and in your case the resulting cluster is not a TypeDef so you would lose any advantages of these. At least if you use a "Bundle" (with a TypeDef wired to the cluster input) instead of "Bundle By Name" then the code will break if you change that TypeDef. This is one of those situations where a Class offers more of an opportunity to ensure that all instances of the code are updated appropriately because instead of updating the cluster data externally you must use Getters and Setters.
09-23-2019 02:02 AM
Building on the class idea, if you place your clustered data (shown in the array on the left) as the private data of some "Result" class, then you can give it subVIs to display in whichever format you'd prefer in a given instance. An array of Result objects could then be called via a For loop with the "Output as Cluster.vi" and an indexing output to produce the left output (array of clusters, Output as Cluster could be just unbundle data from class), and "Output as Values.vi" can give you the 4 fields separately, which you can bundle outside of the For loop for your right-side display (cluster of arrays).
When you change the typedef, your left side display would update automatically (there may be a requirement that the indicators be in memory during the change?). Your right-side would continue to work if you added a new element, but wouldn't show any more fields. If you removed an element from the cluster, you'd break the right-side display (first in the "Output as Values.vi", which would be referencing a non-existent field using Unbundle by Name, then in the callers after a change to the connector pane of Output as Values).
Looking at your description again, I'd guess that you might be able to rearrange your system slightly if we consider more closely the motivation:
there are also lots of steps that are easier to handle/code when this same data is simply a single cluster with all the elements arrayed (1 dimension larger than in the array of cluster).
I guess you mean that you can pass this cluster into subVIs then index specific values or similar, but probably there's additional details to this process. Can you describe this bit some more?
09-23-2019 11:24 AM
In the 2nd piece of code, you can replace the loop with the "Index & Bundle Cluster Array" function.
In the 1st piece of code, you can replace the loop with "Index and Unbundle.xnode" in https://forums.ni.com/ni/attachments/ni/170/1126984/1/Paul's%20XNodes%202018c.zip