LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert array of clusters to cluster of arrays without for loop

Hi!

Here's a problem: I've got an array of clusters (array of messages). Each cluster consists of elements of different data types: double (time), cluster (parameters), char (station id), byte (message code). I know one cluster size and the array size. I need to draw a time graph. How can I convert the array of clusters to a cluster of arrays (array of time values, array of parameters clusters, arrays of chars and bytes).

 

I post this question because in my real array of clusters each cluster consists of 162 elements and some of them are clusters themselves, so I realy dont want to wire "for" loops as was advised in other topics.

 

Hope to get fresh ideas. Memory management? Type Cast? FlatternStrings and variants? Anything!

 

Thank you. 

0 Kudos
Message 1 of 12
(8,075 Views)
What's the composition of "cluster (parameters)"? Also, why don't you want to use a for loop? This would seem to be the easiest way.
0 Kudos
Message 2 of 12
(8,067 Views)

Does your final big cluster end up pink or brown?

 

I am guessing the data structure (arrays clusers) is defined by some other software so you have no control over it?

 

Does your final solution have to run fast?

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 12
(8,064 Views)

Hi, everybody! Glad you read the post! 

There is the cluster in the attachment. The application I make is a TCP client. The cluster is a message. Actually I get a string, find edges ("DIAG" - begin, "GAID" - end) and

then I use "unflattern to string" for making the cluster. I cann't make another structure of the message - I didn't make the server. My client has a buffer of recieved messages. I

need to plot graphs of different cluster elements for all messages in my buffer (for example the Time 1 element). If I use the for loop it would be too slow. The idea was to convert all buffer to a 2D array of U8 and then use type cast to get the cluster of arrays. Then it would be easy to take ane cluster element and send it to graph.

I didn't sucseed yet. 

 

Idea. 

0 Kudos
Message 4 of 12
(8,037 Views)

I can't think of an easy no-brainer solution. I think will take some work. But I am not one to give up easy so I'll throw out an idea.

 

You could type cast your cluster as array of U8's and then keep a history of the "packets" in an Action Engine. Use Actions that will index the values for the buffer in the SR. The indexes of each element should (?!!!!?) end up at the same offset for each "packet".

 

If that does not meet your needs give us more info about the "consumer" of this data and we may be able to offer better ideas*.

 

Ben

 

* Not to imply that there is anything wrong with you, "Idea". Smiley Wink

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 5 of 12
(8,014 Views)

... adding to the above.

 

If each row is a packet then a collumn would be all of the values form a single channel.

 

No For loops.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 12
(8,005 Views)

...and one more thing.

 

Type Definitions will help manage large data structures like the one you are using. if you aren't alrady familiar with type definitions you may want to review the Nugget I wrote on Type Definitions.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 12
(7,995 Views)

Idea wrote:

If I use the for loop it would be too slow. 


I am more of an interested observer on this thread since I couldn't look at your VI, but I do have a question before you start on a magical journey through the depths of type-casting and type-defs.  Your use of the future perfect tense leads me to believe you didn't try the for loop, but assume that it will be too slow.  I am a bit skeptical, and if you did find it to be slow I would like to see the code to make sure you didn't create a memory thrashing situation.  A while back I tested the speed of index array versus a for-loop to extract the column from an array and found negligible difference.  The for-loop (IMO) is reasonably well optimized at this point, and using index array is just letting LabVIEW write the for-loop for you to iterate over the array.  Memory issues (and clusters are prone to them), often lead to slow behavior, not an inherent slowness of the for-loop.

 

If there is a faster way, I am curious to find out what it is.

0 Kudos
Message 8 of 12
(7,975 Views)

Hi, everybody!

 

It's true that I didn't try the For loop.

I didn't find a good way to make the universal function ArrayOfClusters-->ClusterOfArray. Everything I tried stops on the "ArrayToCluster" function and the nessecity to change the cluster size (RMB -> Cluster Size...). But I solved my problem and did it that way:

1. All packets I receive I store in a buffer (2D array of U8).

2. Then I transpose the buffer.

3. Get all rows with  "Index Array" and gather them the way I need (making DBLs, Chars and so on...).

4. After all I make the cluster of arrays.

 

Everything I wrote looks like this:

BD_PrnScr.JPG 

 

It's awful, but works good.

 

Thanks everybody for help.

0 Kudos
Message 9 of 12
(7,947 Views)

Idea wrote:

Hi, everybody! Glad you read the post! 

There is the cluster in the attachment. The application I make is a TCP client. The cluster is a message. Actually I get a string, find edges ("DIAG" - begin, "GAID" - end) and then I use "unflattern to string" for making the cluster. I cann't make another structure of the message - I didn't make the server. My client has a buffer of recieved messages. I need to plot graphs of different cluster elements for all messages in my buffer (for example the Time 1 element). If I use the for loop it would be too slow. The idea was to convert all buffer to a 2D array of U8 and then use type cast to get the cluster of arrays. Then it would be easy to take ane cluster element and send it to graph.

I didn't sucseed yet. 

 

Idea. 


What is your question about?

A) convert the string you get from I don't know where to the giant cluster, the red part in your message, or

B) making a graph out of some element from that giant cluster, who now is in an array, the blue part in your message.

 

The code you showed us looks a solution for question A but no loop is needed for this. So why bother about a loop that would be too slow here?

Also your code start from an array of U8, so where's the string?

If you could provide a string that needs conversion, we could try another way ... ...

 

Question B can easily be solved with a for loop and "unbundle by name". Don't know where you get the idea that a loop would be too slow 😞

Open G library has a lot of VI's to retrieve specific elements from clusters, maybe one of those could help solve the problem.

0 Kudos
Message 10 of 12
(7,939 Views)