Array To Cluster Function, add Type to Convert Cluster
I rarely use this function, but when I do I always end up using Variant to Data function for my Cluster Type.
So I would like to add a Type terminal to convert cluster type.
If Type terminal is unwired, this function work as it in current version.
If it is wired then it will convert to cluster type, and further it can also be used to define cluster size. So this way we can adjust cluster size dynamically if cluster definition changed.
Replace that 'Array to Cluster' with 'Type Cast' and you should be in business.
Yes indeed you are right, I am aware of "Type Cast" would do the job.But in my opinion if it would be included in "Array To Cluster" function, it would save lots of trouble to beginners. Because in many cases first people will look for "Array To Cluster" function when needed.
Just a thought!
I think Darin's point was that as a temporary workaround, Type Cast is a far better choice than Variant To Data because of the performance overhead of Variant To Data -- the data is converted into a Variant at the terminal and then the function converts it back. Really expensive.
I was thinking this just last week. Especially good if it can set the cluster size automatically too.
@AQ, understood, I fixed the code.
Array to Cluster and Cluster to Array are both textbook examples of Type Casting, so I would not dismiss it as simply a workaround, but rather an effective solution that could perhaps be made more accesible to the beginner. With the power of Type Casting comes the responsibility, AtoC and CtoA help here by greatly restricting the flexibility, perhaps too much. (I very rarely use these functions). How many more "Why does my cluster only have 9 elements?" questions do we need?.
By regaining some of the power, there are potential issues as well. What happens when a cluster element or elements have different types than the array? Broken wire(s), coercion, casting?
I would like to see the 'Coerce to Type' function handle clusters so that we could specify the data type (# elements, labels, data types) and at the same time have the values handled in the more natural method of conversion instead of casting. I think of it as a kindler, gentler Type Cast.
At that point I'd be happy to bag the AtoC and CtoA functions altogether.
All this love for the Typecast vs the Variant to Data! Keep in mind one caveat - if you're using mixed datatypes in your cluster, OR if the cluster datatypes are different than the array datatypes - then the Variant to Data is the "better" choice (better defined as more robust, with a speed trade-off, which may be negligible). See demonstration below where Typecast fails but Variant to Data still works:
I'm not a huge fan of CtoA or AtoC - just pointing out a potential pitfall.
Seems to me that AtoC with a cluster input should simply provide the equivalent of Index Array + Bundle:
Just tried to create an XNode interpretation of this: http://lavag.org/topic/14422-array-to-cluster/
Jack, would using the secret "Coerce to Type" primitive work in place of the Type Cast in your example?
(For those who don't know about Coerce to Type: http://forums.ni.com/t5/LabVIEW-Idea-Exchange/Officially-Support-quot-Coerce-to-Type-quot/idi-p/1213...)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.