08-31-2018 12:26 PM - edited 08-31-2018 12:27 PM
Hello LabVIEW Forum,
I'm trying to write simple code, that has to convert between different units of temperatures. I want an input where i can choose between "Celsius","Kelvin" or "Fahrenheit" an d an output where i can choose between "Celsius","Kelvin" or "Fahrenheit". Ultimately, i want a third input, which is the input temperature that should be converted to the chosen output temperature, from the chosen input temperature.
So for example, if i choose "Kelvin" and "0" then the output should be "-273.15" as output on the temperature scale.
My problem is, that I don't know how i can make a case structure take 2 inputs to compare: the temperature unit that should be converted from and the temperature unit that should be converted into.
How can I make a case structure take and compare 2 inputs to do the necessary conversions? Or is there a simplere and smarter way of doing this.
I have attached my VI so far. I have 2 inputs of temperature units as "enum constants".
08-31-2018 01:34 PM
I can't open a 2018 VI but I can ask a question...
Have you considered using two case structures, one to convert input to a stand unit and another to convert from the standard to the desired output units?
Ben
08-31-2018 01:36 PM - edited 08-31-2018 01:43 PM
Convert from the given temperature to Kelvin using the first case structure, then convert to the desired output using a second case structure. (Ben already said that, sorry, I misunderstood).
Also, the input temperature should probably not be an integer. Make it orange!
(Your code does not contain any indicators, so please make it as complete as possible before attaching. It is also very impolite to leave the name at "Untitled 1.vi", because most download folder already have a file with that name. Please next time give the VI a descriptive, unique name before attaching!)
08-31-2018 01:47 PM
@Antaras wrote:
Hello LabVIEW Forum,
I'm trying to write simple code, that has to convert between different units of temperatures. I want an input where i can choose between "Celsius","Kelvin" or "Fahrenheit" an d an output where i can choose between "Celsius","Kelvin" or "Fahrenheit". Ultimately, i want a third input, which is the input temperature that should be converted to the chosen output temperature, from the chosen input temperature.
So for example, if i choose "Kelvin" and "0" then the output should be "-273.15" as output on the temperature scale.
My problem is, that I don't know how i can make a case structure take 2 inputs to compare: the temperature unit that should be converted from and the temperature unit that should be converted into.
How can I make a case structure take and compare 2 inputs to do the necessary conversions? Or is there a simplere and smarter way of doing this.
I have attached my VI so far. I have 2 inputs of temperature units as "enum constants".
A case structure can't have 2 selector inputs. You use multiple case structures for such circumstances.
The attached VI does what you want without any case structures.
08-31-2018 01:51 PM
You can also make a 3x3 2D array, each element containing a cluster of slope+offset for each possible conversion (diagonals are [1,1]. Use the two rings to index into the 2D array and use the obtained slope/offset to convert. 😄
08-31-2018 04:58 PM - edited 08-31-2018 05:10 PM
Actually you have 3x3 or 9 possible conditions to deal with here.
F to C
F to K
F to F
C to F
C to K
C to C
K to F
K to C
K to K
I would use an enum for each selector then use the output of each to determine what formula to use to make the conversion.
08-31-2018 05:09 PM - edited 08-31-2018 05:11 PM
Something like this:
Probably not the most efficient but it was the first thing I thought of...
08-31-2018 06:34 PM
@altenbach wrote:
You can also make a 3x3 2D array, each element containing a cluster of slope+offset for each possible conversion (diagonals are [1,1]. Use the two rings to index into the 2D array and use the obtained slope/offset to convert. 😄
Diagonals are (1,0)
While that would be a 0 case solution, the reader would hav to do math.
The 2 case approach would only require code in 4 of the 6 total cases.
The math version could be read at glance. The 2 case version would require poking at it.
Choose the red pill or the blue pill.
Quoting my wife "Stand back, he is going to do math."
Ben
08-31-2018 10:10 PM
@Ben wrote:Diagonals are (1,0)
Hey, somebody is paying attention 🙂 thanks for the correction.