02-17-2023 10:08 AM
Hi all,
I'm reading out .csv data files into string tables onto the front panel.
One column is a 2D array of date/time strings which I would like to convert into timestamps using Scan From String, expecting an array of timestamps so that I can subtract from the first timestamp to get the total time elapsed in seconds (or minutes).
However the Scan From String only works for the first element of the array and then the Error 1 pops up for the subsequent iteration. I'm assuming there is something wrong with the format string syntax but I can't figure out what it is. I've tried indexing before the array enters the for loop but that doesn't work as well.
I've attached a simplified snippet to demonstrate what I am trying to do.
Any help would be appreciated. Thank you!
Solved! Go to Solution.
02-17-2023 10:49 AM
The last two elements of your array are empty strings.
02-17-2023 10:50 AM
It would be a help if you posted an example of the strings you're trying to process. I can't open your snippet if you saved the data in your array since I'm using 2019. It's always a good idea these day to back-save forum code to 2018 since many of us are sticking with old versions to avoid the new subscription costs. 😉
02-17-2023 10:59 AM
You probably should start with a few basics, e.g. autoindexing and such. If you just want the relative times, ignoring elements with empty strings, here's what you could do:
(even if you are using timestamps, there is no need to have two loops and process the first element twice)
02-17-2023 11:08 AM
Thanks for showing a Snippet of your code.
There are two "mistakes", and some "silly" code.
Here's the "simple fix" -- delete the first For Loop. You'll need a new "Reference Time" Indicator, as it will be a simple TimeStamp, no longer an Array (size 1) of TimeStamp, but the code will now "do what you want it to do". Note it always "did what you told it to do ...".
And here's a suggestion -- fix the second For loop. Do not wire anything to "Number of Elements" ("N"), and bring the Array in through an Indexing Tunnel (and remove the Index Array function -- you've already "indexed the Array" with the Indexing Tunnel).
Bob Schor
02-17-2023 06:16 PM
@nikvl wrote:
Hi all,
I'm reading out .csv data files into string tables onto the front panel.
One column is a 2D array of date/time strings
I stopped reading there.
02-20-2023 01:35 AM - edited 02-20-2023 01:40 AM
@Bob_Schor wrote:
Thanks for showing a Snippet of your code.
There are two "mistakes", and some "silly" code.
- Mistake #1. You are probably getting "Error 1 occurred at Scan From String", pointing to your second For Loop. You have two "illegal" Time Stamps (empty entries) at the end of your subarray. Eliminating them (right-click the blank cell, choose Data Operations, and select "Delete Element".
- Mistake #2. Now when you run it, you get a single Time Elapsed in sec entry in your Array, with the correct answer of 0 (comparing the first elements of the Array with itself). But what happened to the rest of the subtractions? Notice that you took the first element of the subarray, brought it into a For Loop, extracted a Time Stamp (so far, so good), then brought it out of the For Loop using an Indexing Tunnel, making it a 1D Array of TimeStamp. You then subtract this 1D Array of 1 element from a 1D Array of 17514 elements (still perfectly legal), and since LabVIEW, when it does Arithmetic (or Logic) on pairs of Arrays, it stops when either of the Arrays reaches its end, which is after 1 iteration!
Here's the "simple fix" -- delete the first For Loop. You'll need a new "Reference Time" Indicator, as it will be a simple TimeStamp, no longer an Array (size 1) of TimeStamp, but the code will now "do what you want it to do". Note it always "did what you told it to do ...".
And here's a suggestion -- fix the second For loop. Do not wire anything to "Number of Elements" ("N"), and bring the Array in through an Indexing Tunnel (and remove the Index Array function -- you've already "indexed the Array" with the Indexing Tunnel).
Bob Schor
Thank you for taking the time to clearly explain where I went wrong; it was very helpful 🙂
I did start with a single for loop and the two-loop approach and wiring of N (yes I did know it is redundant) was just me poorly attempting to troubleshoot and just happened to be my latest iteration of the attempt, because the Highlight Execution indicated the first iteration, as you noted, ran successfully before running into the error. I realize now my problem was not knowing about how LabVIEW works on pairs of arrays, and I mistakenly kept thinking the dimensions of arrays needed to "match" (i.e. 1-D Arrays with 1-D Array and so on).
I suppose even if I knew that, I would then run into Mistake #1 regarding the empty strings when it reached the end. The empty strings are due to the raw .csv data which has some nonsense data which I assume is specific to the datalogger used as an 'end of file' indicator, something like " ,,,ooOoo " which then translated into an empty string for the timestamp column when it passed through the read delimited spreadsheet vi.
@altenbach wrote:
The last two elements of your array are empty strings.
Thank you for pointing that out and for the vi.