12-21-2023 07:39 AM
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
12-21-2023 09:40 AM - edited 12-21-2023 09:52 AM
Hi,
You can use the JSONtext package from VIPM, it will be much easier:
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.
12-21-2023 11:11 AM - edited 12-21-2023 11:18 AM
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).
12-21-2023 12:02 PM
@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"....
12-22-2023 03:31 AM
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
12-22-2023 04:02 AM - edited 12-22-2023 04:03 AM
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:
12-22-2023 07:19 AM