LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Cluster to variant question

Solved!
Go to solution

I want to do the following: convert my colorimetric cluster into a string array that I can ultimately write to a delimited spreadsheet VI

 

LED47_0-1708015022139.png

I'm having trouble understanding how to set the data type to do this

0 Kudos
Message 1 of 10
(1,270 Views)
Solution
Accepted by topic author LED47

I can't seem to relate the subject of the topic to the question so I will ignore the subject.  You do NOT have a "Cluster to variant question"; you have a "How do I convert the values of the elements inside my cluster to an array of strings" question.  You will have to unbundle each element of the cluster and use the appropriate number to string conversion function in the String --> Number/String Conversion palette.  This has nothing to do with variants.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 10
(1,263 Views)

 

Expanding on the comment made by @billko, your goal is poorly defined.

 

Consider the cluster you provided.  You have two quantities that appear to be a value-unit pair (RadInt + RadIntUnit, and PhotInt/PhotIntUnit pair) and possibly a third (ScotopicInt and CalibrationUnit), which (despite the "Int", suggesting "integer") are a Dbl + String pairing, followed by 23 Dbls followed by an Array of Dbls (of unspecified size).

 

In the code fragment you provided, you convert it to a Variant.  Why?  You then follow this by a Variant-to-Data, but do not specify the format you desire for the data (this makes no sense, at least, not to me).  Now, you could do what I just did and wire the Cluster coming from "Colormetric" into the top of the Variant-to-Data to get the Cluster back, which is pretty instructive:

Colormetric Cluster.png

Look at the indicator "data".  If you get rid of the three Strings at the top, you have a 26 rows x 1 column array (which you can output with one "Write Delimited Spreadsheet" command, followed by a 1 row x ?unknown? columns array (which can also be output by one Write Delimited Spreadsheet" command.  But what a mess ...

 

My advice is to go back to the drawing board and reorganize your Project.  Are the "vertical" data (the 26 x 1 array) coming in at the same rate as the "horizontal" (1 x ?? array) data?  Maybe the only seriously-time-varying data are the latter data points?

 

Bob Schor

 

 

0 Kudos
Message 3 of 10
(1,216 Views)
Solution
Accepted by topic author LED47

Maybe this helps:

 

Convert cluster to readable string and string to data, but not UTF-8? - NI Community

 

Maybe not 😁. Variants are a wild beast, hard to tame.

 

Converting a cluster to variant is simple (and quite pointless):

wiebeCARYA_0-1708074139045.png

Converting a cluster (or variant of cluster) to an array of variants is quite useful:

wiebeCARYA_1-1708074236757.png

You'd normally loop over the items, and convert them to string based on type. 

wiebeCARYA_2-1708074481401.png

However, this should be done in a recursive way, as a cluster can contain a cluster (arrays contain elements, but can contain clusters containing arrays, etc.). Enums are tricky too. Do you store the numbers or their strings? Both have there ups and downs.

 

Note that you can get away with one case for I8, I16, I32, I64 and one for U8, U16, U32, U64, and probably one for sgl, dbl, ext. Some for U8, U16, U32, U64 enums

 

Of course, if you don't have recursive types or don't want to support them, it's easier.

Message 4 of 10
(1,206 Views)
Solution
Accepted by topic author LED47

The normal/classic way of doing it:

Yamaeda_0-1708079434825.png

 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 5 of 10
(1,194 Views)
Solution
Accepted by topic author LED47

Thank you to everyone the basic explanation of using variants, I find this forum to be an invaluable resource.

Message 6 of 10
(1,181 Views)

I'd like to put in a good word for the MGI Read/Write Anything toolkit when you want to convert any arbitrary cluster into a human-readable string and later recover that cluster from the string. 

 

The top level API function deals with .INI format files, but dig down just one level and you find nuggets like "String to Anything" and "Anything to String".  (Note that these are nearly, but not quite symmetric functions, meaning that you can't quite run the output of one directly into the input of the other to recover your original data.  S2A takes in a multi-line string, A2S puts out an array of single-line strings.  Not the same, but pretty trivial to convert as needed.)

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
Message 7 of 10
(1,163 Views)

Thank you

0 Kudos
Message 8 of 10
(1,154 Views)

wiebe@CARYA wrote:

Maybe this helps:

 

Convert cluster to readable string and string to data, but not UTF-8? - NI Community

 

Maybe not 😁. Variants are a wild beast, hard to tame.

 

Converting a cluster to variant is simple (and quite pointless):

wiebeCARYA_0-1708074139045.png

Converting a cluster (or variant of cluster) to an array of variants is quite useful:

wiebeCARYA_1-1708074236757.png

You'd normally loop over the items, and convert them to string based on type. 

wiebeCARYA_2-1708074481401.png

However, this should be done in a recursive way, as a cluster can contain a cluster (arrays contain elements, but can contain clusters containing arrays, etc.). Enums are tricky too. Do you store the numbers or their strings? Both have there ups and downs.

 

Note that you can get away with one case for I8, I16, I32, I64 and one for U8, U16, U32, U64, and probably one for sgl, dbl, ext. Some for U8, U16, U32, U64 enums

 

Of course, if you don't have recursive types or don't want to support them, it's easier.


BD is slightly cleaner if you use "Get Cluster Information.vi" instead of "Variant to Data".

paul_cardinale_0-1708109780133.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 9 of 10
(1,136 Views)

@paul_cardinale wrote:

wiebe@CARYA wrote:

Maybe this helps:

 

Convert cluster to readable string and string to data, but not UTF-8? - NI Community

 

Maybe not 😁. Variants are a wild beast, hard to tame.

 

Converting a cluster to variant is simple (and quite pointless):

wiebeCARYA_0-1708074139045.png

Converting a cluster (or variant of cluster) to an array of variants is quite useful:

wiebeCARYA_1-1708074236757.png

You'd normally loop over the items, and convert them to string based on type. 

wiebeCARYA_2-1708074481401.png

However, this should be done in a recursive way, as a cluster can contain a cluster (arrays contain elements, but can contain clusters containing arrays, etc.). Enums are tricky too. Do you store the numbers or their strings? Both have there ups and downs.

 

Note that you can get away with one case for I8, I16, I32, I64 and one for U8, U16, U32, U64, and probably one for sgl, dbl, ext. Some for U8, U16, U32, U64 enums

 

Of course, if you don't have recursive types or don't want to support them, it's easier.


BD is slightly cleaner if you use "Get Cluster Information.vi" instead of "Variant to Data".

paul_cardinale_0-1708109780133.png


But you loose the data in the elements.

 

Get Cluster Information only returns the variant data types with default data values.

wiebeCARYA_0-1708336406848.png

0 Kudos
Message 10 of 10
(968 Views)