How do you import LABVIEW time stamps into MATLAB
Show older comments
Bug in h5info.
Command
gr_inf=h5info(f_name, '/wfm_group0/axes/axis0' );
Produces an error:
Warning: There is no MATLAB integer type that corresponds to an HDF5 integer type with 16 bytes. The
data will be treated as an uninterpreted uint8 array.
> In h5info (line 74)
In read_scope_hws (line 17)
The file that is being read was created by the NI oscilloscope program.
Not surprisingly, a later statement
ref_time1=gr_inf.Attributes(9).Value;
produces an array of 16 two-byte int8 numbers instead of a 64 byte integer.
The problem is not due to not understanding which group or which attribute to read; the information in Attributes(9).Value is a time stamp. It is just that MATLAB and LABVIEW creators are not talking to each other. The file in question contains four time stamps; each produces a warning.
Does anybody know how to either:
1. Fix the bug in h5info.m
2. How to covert the received 64 bytes in a time stamp by hand
4 Comments
2. How to co[n]vert the received 64 bytes in a time stamp by hand
Would seem NI would have the definition and probably some sample code?
h5info calls h5infoc which is a private mex function so there's not much of any way to patch it w/o TMW cooperation.
OTOH, there _are- both signed and unsigned 64-bit integers supported since at least R14 so seems like should be able to do the conversion from the array manually and then write a conversion function as a workaround.
I didn't search; mayhaps somebody else already has on File Exchange or elsewhere...
ERRATUM
_"...both signed and unsigned 64-bit integers supported..."
My bad, overlooked it's a 128-bit integer, not 64, sorry.
OK, from the NI site --
"The most significant 64 bits should be interpreted as a 64-bit signed two's complement integer. It represents the number of whole seconds after the Epoch 01/01/1904 00:00:00.00 UTC."
So, can you get access to the array as bytes? How about an example to see what actually do have?
"The least significant 64 bits should be interpreted as a 64-bit unsigned integer. It represents the number of 2-64 seconds after the whole seconds specified in the most significant 64-bits. Each tick of this integer represents 0.05421010862427522170... attoseconds."
Seems like if can get the full array as bytes then int64(ary(1:8)) will give the seconds that can be converted to Matlab datenum by the offset of epoch starting times + uint64(ary(9:16)) for the fractional seconds of the day (albeit with some loss of precision if stored as a default double).
"The absolute time represented by this 128-bit data type is the sum of the two 64-bit components."
Benjamin Dolgin
on 27 Jan 2016
http://www.ni.com/tutorial/7900/en/ says "The LabVIEW timestamp is a 128-bit data type...". That's 16-bytes which is what the hfinfo call thought was there. I don't see that the NI doc actually states about endianess, that would be an issue.
There's also the issue of whether it's Gregorian or Julian calendar as I note one respondent had issues with the Gregorian as claimed in the above link.
I was asking if you can't provide the actual 16 bytes returned and do you know what the answer is supposed to be?
I always loved NI hardware but detested their software libraries...I've not used any of their gear nor LABVIEW in over 20 years now...and can't says as how's I've missed it! :)
OK, messing around w/ the example on the NI page, if I take their third example of fractional seconds of a string of '0xCCCCCCCCCCCCCCCD'
>> c='CCCCCCCCCCCCCCCD'; % ML character representation
>> atto=sscanf(c,'%lx') % the atto-seconds field
atto =
14757395258967641293
>> magn=uint64(2^64); % max 64-bit integer
>> f=double(atto)/double(magn) % convert to decimal (approx)
f =
0.8000
>>
That is what they say the value is after the 54 seconds in 12/31/1903 23:59:54.800.
If you've got the 16 bytes you're almost there it would seem.
Accepted Answer
More Answers (0)
Categories
Find more on LabVIEW in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!