LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Code feedback - Feeling that my code is too complicated

Hello,

 

I have this feeling, that my code is too complicated. I am pretty new to Labview (and the programming world). The Sensor data is saved in a pretty convoluted way. And i want to sort this out, so that I can plot the data. This is just a part of a larger program. In the step afterward i save the data to open in another program. That is done with a statemachine, since the sensor also gives some other results wihich are saved in a similar way and i decide by the the file ending on how to treat the files. 

 

The program does what it is supposed to. So I don't have any functionality questions

What I want is some general feedback, how I wrote the code, and where i can improve it. --> To learn and improve. 

My  gut feeling is that the code could fit onto a stamp.

 

I will attach the Vi (LabVIEW 20 64 bit) & sample data

 

Thanks and a Merry Chistamas

Download All
0 Kudos
Message 1 of 7
(1,103 Views)

Hi,

 

You can use the JSONtext package from VIPM, it will be much easier:

raphschru_0-1703173069810.png

I took the liberty to remove the sensor id column to avoid redundancy in the data, and made a cluster array instead of a cluster of 4 subclusters to allow any number of sensors.

 

PS: Some columns in your file have a value "null", which is converted to "NaN" by the toolkit. You may have to do some post-processing if you prefer having zeros instead of NaNs.

 

Regards,

Raphaël.

Message 2 of 7
(1,058 Views)

Even without any toolkits, the code can be dramatically simplified. Here is one possibility.

 

(Note that you forgot to attach your typedef, so I had to disconnect it. My solution gives the correct output structure (cluster of four 2D DBL arrays) while the earlier solution gives (1D array of clusters, each containing a 2D DBL array) The wrong data structure is more scalable, because no code rewrite is needed if you have a different number of sensors at a future point in time).

 

 

altenbach_1-1703178325528.png

 

Message 3 of 7
(1,015 Views)

@MatthiasAr wrote:

What I want is some general feedback, how I wrote the code, and where i can improve it. --> To learn and improve. 


While it is not needed as shown, your first FOR loop is an very inefficient implementation of "reshape array". As a general rule, conditionally appending to an originally empty array is the same as autoindexing. Constantly splitting an array is hard on the memory manager because arrays need to be contiguous in memory.

 

Here are a few alternatives, just as "Fingerübungen" for the aspiring programmer. 😄

 

Your solution was "hard"....

 

altenbach_0-1703181456606.png

 

Message 4 of 7
(997 Views)

Hi Raphaël,

 

I wanted to look into your JSON solution but I have the problem, that i could download and install the JSON text vis from the Paketmanager. But i could not find or install the dependency on "jdp_science_lib_common_utilities" they are unavailable on t network. Do you by chance have a copy?.

 

Matthias 

0 Kudos
Message 5 of 7
(920 Views)

Yes, downloading VIPM packages can sometimes be a pain.

I think sometimes servers are not responding and you simply can't download from the VIPM application.

However you can always download from the vipm website, provided you have an account (free).

Here you can download the latest version of JSONtext and JDP Science Common Utilities.

 

Also attached here:

Message 6 of 7
(915 Views)

Improved version using the malleable VI "Find Item (as LVtype).vim" to get the 2D array directly, plus removed the second column to reduce redundancy even more:

raphschru_2-1703251085590.png

 

 

0 Kudos
Message 7 of 7
(886 Views)