LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Merging data into a single row

Solved!
Go to solution

Hello, in this script I am reading data from the attached Excel file. Basically, the instrument provides the pH value and the conductivity (CD) value in two separate rows. I would like to combine them into a single row, that is, to have one row with (date, time, pH, temp, CD, temp). I filter which values go together using the sample ID. How can I do this?

 

The Excel file will keep growing with new samples, so I’m looking for a small automation for this.

 

Thank you.

 

Download All
0 Kudos
Message 1 of 15
(234 Views)

Hi Jousepa,

 


@Jousepa wrote:

I would like to combine them into a single row, that is, to have one row with (date, time, pH, temp, CD, temp). I filter which values go together using the sample ID. How can I do this?

I would do it like this:

  1. Filter the CSV data line by line and remove unneeded lines (header, empty lines).
  2. Parse each line into a cluster of [ID, timestamp, pH, Temp, CD, temp).
  3. Now you have an array of clusters with ID as first element: sort this array!
  4. Now entries with same IDs form consecutive array elements...
  5. Filter this array by combining neighboring elements into a single cluster (of the same datatype).
  6. Finished: an array of clusters, containing the data for each ID...

Recommendation:

Don't put ALL that stuff into one VI. Separate the different steps into subVIs to keep the code clean and readable.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 15
(212 Views)

This seems like a trivially simple problem once we know more details.

 

  • A CSV file is not an EXCEL file.
  • Does the instrument append to an ever-growing file? Are you sure you can access the file while the instrument has it open?
  • The filename seems to be encoded with metadata. How often does the filename change?
  • Does the instrument always write two rows at once?
  • What's wrong with line #3? Seems corrupted.
  • Do you just want to show the data in an ever-growing array (6 columns) on the front panel? Why not use a table indicator?
  • You should not have to re-read the entire file every time. Use lowlevel file IO and keep track of the last file position of the previous read, then read the new data from there. Make sure to open the file in read-only mode.
  • How often does the instrument append new data?
  • Are the sample IDs always incrementing by one or can they be in any order? What should happen if a sample ID only has one row?

 

 

 

Message 3 of 15
(170 Views)

· CSV file

 

·The instrument is very old and does not expose a COMX serial port. I use the official software, which basically generates this file (.csv)  and I manually decide when to save it.

 

·Since the filename is generated by the software, it changes every time, but I manually force it to overwrite the file by keeping the same name (I know this is quite rudimentary).

 

·Yes, two rows, one for each sensor.

 

·It is not corrupted; I think it coincided with the moment when I was operating the instrument and performed a “stop acquisition”.

 

· The final goal is to combine these data with a pH signal from another instrument and a pressure signal from a pressure indicator, both acquired using an NI DAQ 6001.

 

· I believe that in the code I added a timestamp-based filter so that the true case is triggered only when there are new data in the file.

 

· Manually everytime needed, probably once a day.

 

· Yes. I dont know what happens if there is only one row.

0 Kudos
Message 4 of 15
(159 Views)

Assuming there is a dedicated folder for these output files, It seems it would be easier to let the instrument decide on the filename, then you can use "list folder" to find and parse just the newest file(s). Less work for you! You could even have LabVIEW delete the CSV file once it is processed (or e.g. move it to a backup folder for record keeping if needed). This way only files that are not yet processed will be there.

Message 5 of 15
(154 Views)

It would be a great help if you could give me some brief guidelines on how to do it. I tried today and it was catastrophic. I’m still very inexperienced with clusters and bundle/unbundle, and I have to admit that my logical/mathematical thinking is quite limited.

0 Kudos
Message 6 of 15
(101 Views)

@Jousepa wrote:

It would be a great help if you could give me some brief guidelines on how to do it. I tried today and it was catastrophic. 


This is a long thread with many different suggestions. Without quoting relevant parts of the previous post (as I just did here), it is impossible to tell which post you are replying to and what suggestions you were trying to implement.

 

 

0 Kudos
Message 7 of 15
(95 Views)

I was referring to @Gerdw reply. I don’t know what’s going on, this is the second time I’ve hit reply and the referenced message doesn’t show up.

0 Kudos
Message 8 of 15
(86 Views)

Quoting is not automatic. You need to press the quote button....

 

altenbach_0-1770323562343.png

 

Message 9 of 15
(78 Views)

It would be a great help if you could give me some brief guidelines on how to do it. I tried today and it was catastrophic. I’m still very inexperienced with clusters and bundle/unbundle, and I have to admit that my logical/mathematical thinking is quite limited.

🤠


@GerdW  ha escrito:

Hi Jousepa,

 


@Jousepa wrote:

I would like to combine them into a single row, that is, to have one row with (date, time, pH, temp, CD, temp). I filter which values go together using the sample ID. How can I do this?

I would do it like this:

  1. Filter the CSV data line by line and remove unneeded lines (header, empty lines).
  2. Parse each line into a cluster of [ID, timestamp, pH, Temp, CD, temp).
  3. Now you have an array of clusters with ID as first element: sort this array!
  4. Now entries with same IDs form consecutive array elements...
  5. Filter this array by combining neighboring elements into a single cluster (of the same datatype).
  6. Finished: an array of clusters, containing the data for each ID...

Recommendation:

Don't put ALL that stuff into one VI. Separate the different steps into subVIs to keep the code clean and readable.


 

0 Kudos
Message 10 of 15
(72 Views)