Read Data From ADTF DAT Files
This example shows how to read data from ADTF DAT files usingadtfFileReader
andadtfStreamReader
对象。
To read the data, you first create anadtfFileReader
object that will act as a file handler object for the DAT file. This object gives useful information about the streams present in the DAT file and its contents. Following are the three main ways you can create anadtfFileReader
object:
Using DAT file only: Applies to image and video stream data
Using DAT file and DDL description file: Applies to structured data
使用ADTF插件,给定DAT文件和DDL说明文件: Applies to data which requires some ADTF plugins
Next, you select the data to be read from the DAT file, which creates anadtfStreamReader
目的。然后,您可以使用此对象读取数据。以下是您可以读取数据的一些常见方法:
The data you read from the DAT file will be present in the MATLAB workspace, in raw form.
CreateadtfFileReader
目的
Using DAT file only
Create anadtfFileReader
object by specifying ADTF DAT file name as the only argument to create the file reader object, to read data from streams like images and videos.
datfileName = fullfile(“C:”,“数据”,"sample_can_video.dat");fileReader = adtfFileReader(datFileName)%#好的
fileReader = DataFileName: "C:\data\sample_can_video.dat" DescriptionFileName: "" PluginDirectory: "" StreamCount: 2 StreamInfo: StreamIndex StreamName StreamType StartTime EndTime ItemCount ___________ __________ _______________ _________ __________ _________ 1 {'rawcan'} {'UNSUPPORTED'} 0 sec 14.805 sec 743 2 {'video' } {'adtf/image' } 0 sec 14.799 sec 149
From theStreamInfo
property, note that
Stream 1 is named '
RAWCAN
'。它包含743个数据项,范围从0到14.805秒。但是,此流不支持阅读为“万博1manbetx流类型
' 是 '不支万博1manbetx持
'。To read such streams, we might need to some additional ADTF plugins, as explainedhere.Stream 2 is named ‘
视频
’。它是一个 'adtf/image
' stream, which is a common ADTF stream type for video and image streams. It contains 149 image frames, recorded over an interval of 14.799 seconds.
Using DAT file and DDL description file
Some DAT files contain structured data (for example, CAN data). To read such data into MATLAB workspace, you need a DDL description file containing details about the structure of the data within the streams. Specify the name of the DDL description file as an additional argument while creating anadtfFileReader
目的。Note that the DAT filesample_can.adtfdat
contains dummy data and is used for demonstration purposes only.
datfileName = fullfile(“C:”,“数据”,"sample_can.adtfdat");ddlfilename = fullfile(“C:”,“数据”,"sample_can.description");filereader = adtffilereader(datfileName,ddlfileName)%#好的
fileReader = DataFileName: "C:\data\sample_can.adtfdat" DescriptionFileName: "C:\data\sample_can.description" PluginDirectory: "" StreamCount: 1 StreamInfo: StreamIndex StreamName StreamType StartTime EndTime ItemCount ___________ __________ _________________ _________ ________ _________ 1 rawcan adtf/devicetb/can 0 sec 0.98 sec 99
Note that the above output shows a different stream type, 'adtf/devicetb/can
',对于罐头,与'不支万博1manbetx持
'流类型在上一节中。这是因为样本_can.adtfdat
is in ADTF 3.0 format file whereas sample_CAN_VIDEO.DAT
是ADTF 2.0格式文件。对于2.0格式,可能需要其他插件来读取数据。
Use ADTF Plugins, Given a DAT File and DDL Description File
An ADTF Plugin is a compiled object that provides aditional functionality to ADTF Runtime. They are very specific to ADTF framework and you can read more about themhere.
In certain cases, ADTF Plugins are necessary to read data from streams. For such cases, specify the path to the folder storing the plugins as an additional argument while creating anadtfFileReader
目的。Replace the value of插件文件夹
带有包含插件的系统上的路径的变量。
datfileName = fullfile(“C:”,“数据”,"sample_can_video.dat");ddlfilename = fullfile(“C:”,“数据”,"sample_can_video.description");插件文件夹= fullfile(“C:”,“插件”);fileReader = adtfFileReader(datFileName, ddlFileName, pluginFolder)%#好的
fileReader = DataFileName: "C:\data\sample_can_video.dat" DescriptionFileName: "C:\data\sample_can_video.description" PluginDirectory: "C:\pluginFolder" StreamCount: 2 StreamInfo: StreamIndex StreamName StreamType StartTime EndTime ItemCount ___________ __________ _____________________ _________ ___________________ 1 {'rawcan'} {'adtf/devicetb/can'} 0 sec 14.805 sec 743 2 {'video'} {'adtf/image'} 0 sec 14.799 sec 149
请注意,每个操作系统都有不同版本的同一插件。如果需要插件在DAT文件中读取流,并且您不指定其路径,则流类型
value for those will be‘不支万博1manbetx持
’。
Select and Read Data
从单流读取数据
创建adtfFileReader
目的。Note that the DAT filesample_struct.dat
contains dummy data and is used for demonstration purposes only.
datfileName = fullfile(“C:”,“数据”,“ sample_struct.dat”);ddlfilename = fullfile(“C:”,“数据”,"sample_struct.description");filereader = adtffilereader(datfileName,ddlfileName)
fileReader = DataFileName: "C:\data\sample_struct.dat" DescriptionFileName: "C:\data\sample_struct.description" PluginDirectory: "" StreamCount: 2 StreamInfo: StreamIndex StreamName StreamType StartTime EndTime ItemCount ___________ ________________ ________________ _________ ________ _________ 1 {'firststream'} {'adtf2/legacy'} 0.09 sec 1.07 sec 99 2 {'secondstream'} {'adtf2/legacy'} 0.09 sec 0.98 sec 90
Select the stream to be read by specifying their stream index.
streamReader = select(fileReader, 1);
Read the first item in the selected stream.
item = readNext(streamReader)
item =带有字段的结构:StreamIndex:1数据:[1×1结构]
In the structure,数据项
,'StreamIndex
”字段显示了选定的流指数和“Data
'字段包含带有时间戳(以微秒为单位)的实际数据项,将这些数据记录到DAT文件中。
%显示时间戳fprintf(“时间戳=%d \ n”,item.data.timestamp);
时间戳= 90000
% Display datadisp(item.data.item)
信号1:[1×1 struct] Signal2:[2×1 double] Signal1:[1×1 struct] Signal2:[2×1 double]
你也可以在遍历所有的数据项e selected stream.
% Read one item at a time尽管hasnext(streamReader) item = readNext(streamReader);% Process data结尾
Alternatively, you can read all data items at once and iterate over it later.
% Read everythin at onceitems = read(streamReader);%迭代数据为了i=1:streamReader.DataCount timestamp = items.Data(i).Timestamp; data = items.Data(i).Item;% Process data结尾
Read Data withTimeRange
and索引
过滤器
创建adtfFileReader
目的。
datfileName = fullfile(“C:”,“数据”,"sample_can.adtfdat");ddlfilename = fullfile(“C:”,“数据”,"sample_can.description");filereader = adtffilereader(datfileName,ddlfileName)
fileReader = DataFileName: "C:\data\sample_can.adtfdat" DescriptionFileName: "C:\data\sample_can.description" PluginDirectory: "" StreamCount: 1 StreamInfo: StreamIndex StreamName StreamType StartTime EndTime ItemCount ___________ __________ _________________ _________ ________ _________ 1 rawcan adtf/devicetb/can 0 sec 0.98 sec 99
Use the name-value argument,索引
, in the选择
function to filter the search to the last 10 data items in the selected stream.
StreamIndex = 1;startIndex = filereader.streaminfo(StreamIndex).Itemcount -9;%的%第10元素索引结尾Index = fileReader.StreamInfo(streamIndex).ItemCount;% last indexstreamReader = select(fileReader, streamIndex, IndexRange=[startIndex endIndex]);%#好的
Use the name-value argument,TimeRange
, to filter the search to all the data items recorded between 1 to 2 seconds, across the selected streams.
starttime =秒(0.1);末日=秒(0.2);streamReader = select(fileReader,timerange = [starttime endtime]);%#好的
INFO : All streams are selected.
接下来,您可以使用该项目使用读Next
andhasnext
functions, or read all items at once using读Next
function. See从单流读取数据section了解更多信息。
Reading multiple streams
创建adtfFileReader
目的。
datfileName = fullfile(“C:”,“数据”,“ sample_struct.dat”);ddlfilename = fullfile(“C:”,“数据”,"sample_struct.description");filereader = adtffilereader(datfileName,ddlfileName)
fileReader = DataFileName: "C:\data\sample_struct.dat" DescriptionFileName: "C:\data\sample_struct.description" PluginDirectory: "" StreamCount: 2 StreamInfo: StreamIndex StreamName StreamType StartTime EndTime ItemCount ___________ ________________ ________________ _________ ________ _________ 1 {'firststream'} {'adtf2/legacy'} 0.09 sec 1.07 sec 99 2 {'secondstream'} {'adtf2/legacy'} 0.09 sec 0.98 sec 90
您可以通过指定其流索引来选择流。要默认选择所有流,请勿指定任何流索引。
While reading data from multiple streams simultaneously, it is possible that there are unequal number of data items across different streams. To illustrate, perform the following selection.
firstStreamIndex = 1; secondStreamIndex = 2; startTime = seconds(0.98); endTime = seconds(2.0); streamReader = select(fileReader, [firstStreamIndex, secondStreamIndex], TimeRange=[startTime endTime]); fprintf("Number of elements in stream 1 = %d\n",streamReader.dataCount(firstStreamIndex));
流1 = 10中的元素数量
fprintf(“流2 =%d \ n中的元素数”,streamReader.dataCount(secondstreamIndex));
流2 = 1中的元素数量
请注意,第一流有10个项目,第二个流只有1个项目。如果您立即读取所有数据项读
function, then stream 1 will return an array of 10 structures, and stream 2 will return a single structure.
allData = read(streamReader)
alldata =带有字段的2×1结构数组:StreamIndex Data
当您逐一阅读数据时,在第一次呼叫中读Next
,您会根据预期获得每个流的一个结构。
data1 = readNext(streamReader)
data1 =带有字段的2×1结构数组:StreamIndex Data
In the next call to读Next
,我们只获得流1的项目。
data2 = readnext(streamReader)
data2 =带有字段的结构:StreamIndex:1数据:[1×1结构]
请注意,尽管其中一条流已经达到了选择的结尾,但是读Next
still returns the data items from the remaining streams. Similarly, thehasnext
功能将返回true
即使选择中的一个流也可以读取数据。
hasnext(streamReader)
ans =logical1