LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Obtaining Time Elapsed from Timestamp

Solved!
Go to solution

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!

0 Kudos
Message 1 of 7
(1,009 Views)

The last two elements of your array are empty strings.

0 Kudos
Message 2 of 7
(995 Views)

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. 😉

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
0 Kudos
Message 3 of 7
(993 Views)
Solution
Accepted by topic author nikvl

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:

 

altenbach_0-1676653034589.png

 

(even if you are using timestamps, there is no need to have two loops and process the first element twice)

 

altenbach_1-1676653141103.png

 

0 Kudos
Message 4 of 7
(989 Views)
Solution
Accepted by topic author nikvl

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

Message 5 of 7
(986 Views)

@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.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 6 of 7
(938 Views)

@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.

0 Kudos
Message 7 of 7
(860 Views)