LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview parse to index array; better way?

Solved!
Go to solution

A project I am working on, starts with a .csv (like) file that I think needs to be indexed, re-sort the items, and create a three line output (with comma delimited) between them. The headers (line 2) and data (line 3). The index array works but the code is cumbersome to troubleshoot. There must be a better way to index values and create the text file; but I am not sure how it can be different.

Also, the array keeps the values if I attempt to process two files, without restarting the application? I tried to empty the array but occasionally the processing seems delayed and doesn't process the time to minutes correctly. Thanks for looking/reading.

0 Kudos
Message 1 of 11
(3,250 Views)

@Rockets212 wrote:

The index array works but the code is cumbersome to troubleshoot. There must be a better way to index values and create the text file; but I am not sure how it can be different.


Holy cow, you weren't kidding. This block diagram is enormous... troubleshooting would be nearly impossible!

 

Without knowing your input file format and output file format it's hard to give you any real advice, other than "Index array" should probably only be on your diagram once.

 

If your format is based on row/column positions, then I'd probably create a struct typedef containing a row, column, and label. The label will be for easier handling, but you might not need it.

 

Put this into an array, then into a For loop indexing on this struct. Within the loop, do your Index Array and build up your "Output" array, which you can further manipulate or just concatenate.

 

You will need some way to store the "decoding" information. If it's rows and columns, use an array of rows and columns. If it's got labels (like "FilterID: [value]" then you can use string searching functions to just parse through the string to find the "identifier" then extract the next value.

Message 2 of 11
(3,235 Views)

Thank you for the response. I will try these ideas.

 

The file format starts as .evt but opens as a .csv; it appears to be CSV.

 

I do need to index rows & column to create the header or label and the data associated to the heading.

 

I would then guess since its so large that the array isn't processing the time to minutes correctly due to its size also?

0 Kudos
Message 3 of 11
(3,228 Views)

 

I would then guess since its so large that the array isn't processing the time to minutes correctly due to its size also?

 


No, that would probably be a race condition you have from using local variables. You are writing to "Hours to Minutes", "Minutes", and "Seconds" each iteration of the loop but also using local variables to read the same data. Which one will happen first is anyone's guess. The local variables could very well still have the data from the last loop iteration before the controls are updated (or whatever data is in the control on your first run). The wires are literally just a few inches from the variables, just use those instead!

Race Condition.png

Message 4 of 11
(3,210 Views)

@BertMcMahan wrote:

@Rockets212 wrote:

The index array works but the code is cumbersome to troubleshoot. There must be a better way to index values and create the text file; but I am not sure how it can be different.


Holy cow, you weren't kidding. This block diagram is enormous... troubleshooting would be nearly impossible!

 

Without knowing your input file format and output file format it's hard to give you any real advice, other than "Index array" should probably only be on your diagram once.

 

If your format is based on row/column positions, then I'd probably create a struct typedef containing a row, column, and label. The label will be for easier handling, but you might not need it.

 

Put this into an array, then into a For loop indexing on this struct. Within the loop, do your Index Array and build up your "Output" array, which you can further manipulate or just concatenate.

 

You will need some way to store the "decoding" information. If it's rows and columns, use an array of rows and columns. If it's got labels (like "FilterID: [value]" then you can use string searching functions to just parse through the string to find the "identifier" then extract the next value.


Here's an example of what Bert was suggesting. There is a for loop that can handle all the index arrays and concatenate functions. (I did the first line of your new output as an example.)

 

There is also some Rube Goldbergian code in there that could be cleaned up as well.

 

This -

RGM 1.png

 

does the exact same thing as this -

 

 

RGM 2.png

 

 

Message 5 of 11
(3,178 Views)

You should also check out the "Format Into String" function instead of using "Build String" with 4-5 inputs.

 

For example, if you have a a wire with the string "20" in it and you wanted to make that say "Max temp: 20 (C)", you could do that with a Format Into String with the Format being "Max temp: 20 (%s)", and it'll wire your string "20" into the spot it sees the "%s".

0 Kudos
Message 6 of 11
(3,175 Views)

Instead of those gigantic Concatenate strings to create the comma separated row, create an array of the string and use a Format into Spreadsheet string with comma as separator. It'll more than half the needed wires (and thus the clutter).

Also, Sub-VIs are important!

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 11
(3,100 Views)

It appears I haven't gotten the concept of smaller portions (SubVI's) to reduce the 'one size fits all' coding. I can see in this project that it created a big problem for me. Thanks to all for the help and responses.

 

I have a few questions; how did you make the Control item and use that in the VI?

 

Should I remove any other variables aside from re-wiring the time to minutes?

0 Kudos
Message 8 of 11
(3,073 Views)

@Rockets212 wrote:

Should I remove any other variables aside from re-wiring the time to minutes?


Based on what I quickly saw, you should not have any local variables.

 

So for some reason, I have had this thread in my head since last night.  And I think I have come to the conclusion that I would attack this with 2 FOR loops.  Each loop can run in parallel, each handling a different line in the final file.  I would use an array of strings to state what is being handled for each item going into the line.  Autoindex on those arrays and do whatever parsing, etc needs to be done inside of a case structure, and autoindex a string out of the loops.  At this point, a FOR loop will output an array of strings.  You then use Array To Spreadsheet String to convert into a comma delimited array and write the string.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 9 of 11
(3,062 Views)

E.g. instead of all that string manipulation to get the Elapsed time, you can do it like this:

Scan from string.png

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 10 of 11
(3,052 Views)