LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I write a subVI that accepts a generic-dimension array?

I'd like to write a subVI with an input that is an array. The thing is, sometimes the array will be 1D, sometimes 2D, sometimes more.

If I try to pass an array reference, the reference "knows" what dimension the array is.

If I pass the array directly then I'm hardwired to accept whatever kind of array I put in my subVI as the input.

Is there a way to pass an array reference that is NOT specifically dimensioned?

A related question: Is there a way to get the array's dimension from a property node? As far as I can tell the only way is the get the value property and then use Array Size. It seems like the array's dimension should be a property.
0 Kudos
Message 1 of 14
(5,355 Views)
In order to do that, you need to create a polymorphic vi. You can create polymorphic vi's only with LabVIEW Professional Development System. Instructions on how to create a polymorphic vi can be founded here:

Building Polymorphic VIs
http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?openagent&359E270A5D5BCEDB862569220056F548&cat=2E4161187E3DEB30862568660020BCC8

In the event you don't have LabVIEW Professional Development System, you can create several vi's and use a case structure to determine which vi to use according to the array dimension. Also, if you know that the dimensions of the possible arrays are limited (for example, you will not evaluate arrays with more than 3 dimensions), you may want to create a vi that can accept arrays of different dimensions using v
arious input terminals. Something similar is done for the vi "Flatten Pixmap.vi", which you can find in the diagram palette, "Graphics & Sounds". That vi has several input for each type of array (bool, 8-bit, 24-bit, etc.) You might be able to do something similar, in this case, based on the array dimension.

I don't know if there is an array's property to get the arrays dimension. I think there is not.

Best regards;
Enrique
www.vartortech.com
0 Kudos
Message 2 of 14
(5,354 Views)
Thanks for the answer,

Polymorphic will sort of solve the problem. But I was hoping to not have to write a separate VI for each dimensionality (because then I get a bunch of VIs instead of one, and I have to guess in advance what my largest dimensionilty will be).

If it helps, my application is to take the array and squash it down to an array of strings (1D) that consists of a header (so I can reconstruct later), and the data itself. Then I can output the array of strings to a spreadsheet.

The format I was thinking of is something like (example below is a 2x2 array of floats)

The first number after "Begin" gives the dimension N. The next N numbers give the size of the dimensions. Then the array itself follows in flattened out form.

BEGIN:ARRAY
2

2
2
1.10
1.20
2.10
2.20
END:ARRAY

Ideally, I wanted to write one routine that could take in a generic dimension array and output the string array format above.

I can do this with polymorphism, but each dimensionality means I have to write a new subVI (and they will be 99% the same so it would be nice to write it once generically).

Even if I could pass a generic dimension array, I wouldn't be able to easily find out what its dimension was, so I think this is a futile effort and polymorphic VI might be my only choice.

Thanks!
0 Kudos
Message 3 of 14
(5,354 Views)
It almost sounds like you are trying to re-write "flatten to string".

Have you looked into using that fuction?

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 12 of 14
(5,106 Views)
Almost, but not quite. Flatten to string produces a binary string. I need text.
0 Kudos
Message 13 of 14
(5,106 Views)
On Thu, 19 Jul 2001 10:59:15 -0700 (PDT), Enrique wrote:
> In order to do that, you need to create a polymorphic vi. You can
> create polymorphic vi's only with LabVIEW Professional Development
> System. Instructions on how to create a polymorphic vi can be founded
> here:
>
> Building Polymorphic VIs
>
http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?openagent&359E270A5D5BCEDB86
2569220056F548&cat=2E4161187E3DEB30862568660020BCC8
>
> In the event you don't have LabVIEW Professional Development System,
> you can create several vi's and use a case structure to determine
> which vi to use according to the array dimension. Also, if you know
> that the dimensions of the possible arrays are limited (for example,
> you will not evaluate arr
ays with more than 3 dimensions), you may
> want to create a vi that can accept arrays of different dimensions
> using various input terminals. Something similar is done for the vi
> "Flatten Pixmap.vi", which you can find in the diagram palette,
> "Graphics & Sounds". That vi has several input for each type of array
> (bool, 8-bit, 24-bit, etc.) You might be able to do something similar,
> in this case, based on the array dimension.
>
> I don't know if there is an array's property to get the arrays
> dimension. I think there is not.
>
> Best regards;
> Enrique

Enrique,

Type descriptor property shows the all info about array, including array's dimension.

Regards,
Sergey
0 Kudos
Message 5 of 14
(5,354 Views)
I was looking at this property. It seems that is available only in LabVIEW 6, not in previous versions.
www.vartortech.com
0 Kudos
Message 8 of 14
(5,354 Views)
On Thu, 19 Jul 2001 10:17:09 -0700 (PDT), Bmarsh wrote:
> I'd like to write a subVI with an input that is an array. The thing
> is, sometimes the array will be 1D, sometimes 2D, sometimes more.
>
> If I try to pass an array reference, the reference "knows" what
> dimension the array is.
>
> If I pass the array directly then I'm hardwired to accept whatever
> kind of array I put in my subVI as the input.
>
> Is there a way to pass an array reference that is NOT specifically
> dimensioned?
>
> A related question: Is there a way to get the array's dimension from a
> property node? As far as I can tell the only way is the get the value
> property and then use Array Size. It seems like the array's dimension
> should be a property.

I think there
are as a minimum two data types available for that.
You can use variant with a property of dimension size set.
You can use string as a flattened storage (buffer) of an array data with type descriptor
(either LabVIEW type descriptor array or your number, showing array dimensions and data
types). Type descriptor array is available via property of the reference as well.
In both cases you have a chance of passing reference to sub-vi. As well as
passing data by wire. Reconstructing data inside sub-vi is also required in both cases.
There is also polymorphic VI feature in LabVIEW allowing you to handle this situation.
0 Kudos
Message 4 of 14
(5,354 Views)
Hello again Bmarsh


> I'd like to write a subVI with an input that is an array. The thing
> is, sometimes the array will be 1D, sometimes 2D, sometimes more.
>
> If I try to pass an array reference, the reference "knows" what
> dimension the array is.

>
> If I pass the array directly then I'm hardwired to accept whatever
> kind of array I put in my subVI as the input.
>
> Is there a way to pass an array reference that is NOT specifically
> dimensioned?

When you create the array control refnum on the subVI, make sure it is not
strictly typed to an actual array. Create it from the palette (Control
Refnum)
and select Array class or otherwise unselect "Include Data Type" in the
right-click menu of the control refnum. Then the reference is generic to an
N dimensi
onal array.


>
> A related question: Is there a way to get the array's dimension from a
> property node? As far as I can tell the only way is the get the value
> property and then use Array Size. It seems like the array's dimension
> should be a property.

You can have it indirectly reading the "Index Values" property, which is an
array of indices (one per dimension) of the element displayed in the
top-left corner of the array indicator. the length of this 1D array is the
number of dimension of the referenced array.

Jean-Pierre Drolet


LabVIEW, C'est LabVIEW

0 Kudos
Message 6 of 14
(5,354 Views)
> > A related question: Is there a way to get the array's dimension from a
> > property node? As far as I can tell the only way is the get the value
> > property and then use Array Size. It seems like the array's dimension
> > should be a property.
>
> You can have it indirectly reading the "Index Values" property, which is
an
> array of indices (one per dimension) of the element displayed in the
> top-left corner of the array indicator. the length of this 1D array is the
> number of dimension of the referenced array.
>

Actually, you get the number of dimensions, not the size of each
dimension...


LabVIEW, C'est LabVIEW

0 Kudos
Message 7 of 14
(5,354 Views)