LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading in a timestamp

I've been asked to put together a program that will read in a bunch of different type of text files (not saved using LabView).  In many of the files, there are two (or more) rows of header items, then the first column is a timestamp that looks like:

02/20/2007 18:09:30.6

The rest of the columns are nice double precision arrays that I can deal with easily.  My issue is reading this first column, all I can seem to pull up is '2'.  What's the best way to read in this column?  Thanks for any help!
0 Kudos
Message 1 of 11
(4,233 Views)
Try using SCAN FROM STRING, with a format of

%02d/%02d/%04d %02d:%02d:%3.1f

Put the parts together with a DATE/TIME to SECONDS function if you need to.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 2 of 11
(4,218 Views)
Thanks for the quick help.  I really avoid working with strings whenever possible, but now I'm being forced to.  I tried the Scan From String with the format you suggested, and I kept getting an error ("too many format specifiers").  I'm attaching a vi with what I'm doing.  If you (or anyone) has a chance to look at it, I would love any more advice.
0 Kudos
Message 3 of 11
(4,205 Views)

You're only getting a 2 because you're using read from spreadsheet file and returning doubles. When the timestamp string gets converted to a double, it sees "02/..." It doesn't know how to convert a slash into a double so it assumes the number ends there.

I suggest you wire a %s to Read from Spreadsheet File. This will give you all the data in strings. Now you can take out the first column and convert it to timestamps (using Scan from String), then take out all the actual data and convert it to doubles.

Message Edited by Marc A on 03-01-2007 11:20 AM

Message 4 of 11
(4,199 Views)
You get the message "too many format specifiers" because you used the format string I told you, but with only one output. You need 6 outputs if you're reading six parts (mm DD YYYY HH MM SS.s).

Of course, that won't work either if you put in a string that starts out "Log File"

You probably should read the file with "%s" format, and get an array of strings.

Throw away the first line of commentary stuff.

Strip out the first column.

For every row in the first column, run the string through the SCAN FROM STRING function, and maybe the DATE/TIME to SECONDS function to get a timestamp value.

Then run the rest thru a STRING TO NUMBER conversion (no loops needed) to get your data.

HTH

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

Message 5 of 11
(4,190 Views)

Forgot to mention, use

%<%m/%d/%Y %H:%M:%S%1u>T

as your scan string, and it will output a timestamp.

0 Kudos
Message 6 of 11
(4,189 Views)
Thanks for the help.  I think I figured out a way to do it.  It may only be valuable to me, but I'm going to attach my solution in case someone else needs to do a similar file opening.
0 Kudos
Message 7 of 11
(4,177 Views)
I did a little cleanup to show you how to better read the file and break it up the way you want to. Also, there are 3600 seconds in an hour, not 360 Smiley Wink
0 Kudos
Message 8 of 11
(4,163 Views)
That would be great, except it has the same problems I initially had - which is that the Read from Spreadsheet won't let me input '%s' into the format part - so no matter what (even in your code), I get a double array out of Read from Spreadsheet.  I'm using LabView 8, student version.  I've tried opening up the Read from Spreadsheet and trying to figure out a way to get a string output, but I don't see how Spreadsheet String to Array will ever output a string (and yes, I've stuck %s in the format).  Thanks for the help - I would obviously prefer the cleaned up code - and I would love to be able to open a spreadsheet in an string-array format...
0 Kudos
Message 9 of 11
(4,163 Views)

OK, I know why. In version 8.2, Read from Spreadsheet File is a polymorphic VI that has different data types. 8.0 doesn't have this capability. To get around it, use Read Text From File.vi, then wire the string ouput to Spreadsheet String to Array.vi. Wire a 2D string array to the array type input and you'll get a string array out.

Edit: like this...

Message Edited by Marc A on 03-01-2007 01:51 PM

Message 10 of 11
(4,156 Views)