LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array of cluster to array of element - or - Cluster of arrays?

Hi all,

I have a large cluster (lets call it C_data) containing measured data e.g. 10 Temperatures, Pressure, (Temp_1, ...).....
All these data are measured once per second. I now collect all data measured over a certain time in an array of the aforementioned cluster, that is
an array of C_data. In order to display time series of data in graphs I need to extract arrays of elements from this array of C_data.
In a text based programming language this could look like the following:

Struct C_data {Temp_1, Temp_2, P_1.....}
ar_C_data is an array of C_data

now I want to do something like:
array_of_Temp_1 = ar_C_data[*].Temp_1

In some programming languages this works but I cannot unbundle_by_name the array of Temp_1 from ar_data in Labview.
Since my cluster is large and may change in structure (for this reason I use a typedef) a generic solution would be the best.

I know that I could: loop over all elements of ar_C_data, unbundle by name, index elements into arrays, and use these but this seems very
inefficient if it is done every second on a large cluster (30 elements) with several thousand array elements....

Olaf
0 Kudos
Message 1 of 3
(2,961 Views)
You can minimize the overhead of scanning through all elements and extracting if you pre-define the array and use "replace array subset".  This avoide having to re-size the array which is costly.

Or you can keep an array separately in memory.  When one cluster element is added, the corresponding element is added to the array too.  Causes some memory overhead, but you're going to have that anyway if you generate them "on the fly".

I don't see a way to do this other than either search through the array and pick the elements you need -or-
keep a copy of the data in a form you can use.

It's a common question of how to structure data to best suit two sometimes conflicting needs - efficiency and useability.

What might be of interest is to change the "Array" - "Cluster" order and have a single cluster C-Data with arrays of each element required.  Might be a bit more difficult to use, it depends on your application.
This way you have all arrays ready at all times, but generating a single cluster requires bundling the individual units on the fly.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 2 of 3
(2,959 Views)
Shane,

thanks for your suggestions. Funny, I had the solution cluster of arrays before but I didn't like it too much.
One more point is that I use the same cluster in two applications that communicate with each other. So
I have a Typedef of this cluster to keep compatibility between these two and on one side I do need only
single values no array, and on this side (a RT compact fieldpoint) I don't want to have overhead. The
second app where I need the arrays for displaying time series of data I but performance
is less of an issue. Honestly, I was more searching for the most elegant and beautiful solution because
I like to have aesthetic code which is easy to read (can you say this actually with graphical Labview code?? 🙂
and understand.

So for the moment I keep the array of clusters.

Olaf
0 Kudos
Message 3 of 3
(2,902 Views)