Azzera filtri
Azzera filtri

How do you import LABVIEW time stamps into MATLAB

8 visualizzazioni (ultimi 30 giorni)
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 Commenti
dpb
dpb il 27 Gen 2016
Modificato: dpb il 27 Gen 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! :)
dpb
dpb il 27 Gen 2016
Modificato: dpb il 27 Gen 2016
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.

Accedi per commentare.

Risposta accettata

Benjamin Dolgin
Benjamin Dolgin il 29 Gen 2016
Modificato: dpb il 12 Feb 2016
MATLAB h5info has a bug: it does not recognize int128 variables in a NI LABVIEW files. Time stamp is one of those variables MATLAB does not recognize. Time stamp actually consists of two int64 numbers; the first one is signed the second is unsigned (see http://www.ni.com/tutorial/7900/en/ ). When one attempts to read a time stamp using h5info one gets a warning
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.
Subsequently, when the actual attribute is read one gets sixteen int8 numbers as opposed to one 128 bit or two int64 numbers. For example the following code applied to a data file produced by NI Oscilloscope program produces a wrong result:
gr_inf=h5info(file_name, '/wfm_group0/axes/axis0' );
ref_time1=gr_inf.Attributes(9).Value;
ref_time1'
ans =
138 113 222 106 31 103 60 142 210 196 4 197 0 0 0 0
For the actual file recorded on 19-Jan-2016 10:20:37.122669 the answer should be 3536061637 and 2262843920682704384
The following code recovers appropriate numbers and generates UTC time (with credits to "dpb" and Stephen Van Kooten)
warning('off','MATLAB:imagesci:hdf5dataset:integerButNoSuchMatlabClass');
gr_inf=h5info(file_name, '/wfm_group0/axes/axis0' );
warning('on','MATLAB:imagesci:hdf5dataset:integerButNoSuchMatlabClass');
ref_time1=gr_inf.Attributes(9).Value;
wholeUint = sscanf(sprintf('%02X',[ref_time1(13:16) ref_time1(9:12)]),'%lx');
if wholeUint>=bitshift(uint64(1),63)
%convert to negative with 2s complement
whole = -1*(int64(intmax('uint64') - wholeUint)+1);
else
whole = int64( wholeUint );
end
frac = sscanf(sprintf('%02X',[ref_time1( 5: 8) ref_time1(1: 4)]),'%lx');
utc = datetime(double(whole)+double(frac)/2^64, ...
'ConvertFrom','epochTime','Epoch','1904-01-01', ...
'TimeZone','UTC');
  5 Commenti
Guru Subramani
Guru Subramani il 14 Dic 2016
"Time stamp actually consists of two int64; the first one is signed the second is unsigned " - Benjamin Dolgin, I think this describes what is going on clearly. Thanks!
Walter Roberson
Walter Roberson il 14 Dic 2016
"MATLAB h5info has a bug: it does not recognize int128 variables"
That is not a bug. MATLAB does not have any int128 data type. It is a limitation. To handle int128 or uint128, Mathworks would have to create a complete extended-precision software mathematics facility: all other calculations in basic MATLAB are done with hardware instructions, but the x64 instruction set does not offer 128 bit integer operations.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Time Series Objects in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by