LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Extract last row of data before blank row from CSV file

Hello,

 

I would like to know how to go about extracting the last row of each block of start data. 

 

I am currently able extract the index of the "start #", I just need to get the last row from each "start # x".

 

Attached is my current code and data.

Download All
0 Kudos
Message 1 of 2
(947 Views)

Thank you for attaching both your data file and your VI (in LabVIEW 2021, which I can read on one of my machines).

 

Looking at your data, I notice the following:

  1. Data are organized in "chunks" of "lines with data of some type" separated by blank lines.;
  2. The first "chunk" is a header, specifically the first element of the first row is not "start #" followed by a number.
  3. Every other "chunk" starts with either "start #" or a blank line, meaning you've reached the end of the file.

Here is how I would handle this:

  • Read the entire file into a 2D Array.
  • Make an Array of "Blank Line Rows", the index of the Column 1 entries that are blank.
  • Recognize that BLR(0) is the blank line row between the Header and "start #1".
  • How many Blank Lines should you have?  If you have 7 "start #" rows, you will have 8 Blank Lines, right?  [I sometimes make an "off-by-one" mistake -- make sure you agree with me.
  • Now, assume you have the (presumably) 8 Blank Line Rows.  Think about how you could use these 8 numbers to return the contents of the cell that show "start #1" to "start #7".  [Hint -- what is in the first column of the row BLR[0]+1 (that is, the contents of the first column in the row following the row indicated by Blank Line Row(0) + 1].
  • What is the "Blank Line Row" that follows the first "start #1" block of data?  Relative to that row, where do you find the last row of Block 1?
  • Now generalize this to get all of the (how many?) last rows, which I think is what you want to do.

Note -- I am not going to provide you LabVIEW code -- you won't learn to "think LabVIEW" by copying.  But if you think about the "things you need to do" (as I tried to show you), and if you know how you can use a While or For loop to "index through a 2D array to get rows one at a time", as well as use "Index Array" to return a particular row, this should be a piece of cake (you can send me a cookie if you agree).

 

Bob Schor

Message 2 of 2
(923 Views)