How to check if a ,MDF file is unsorted?

조회 수: 10 (최근 30일)
Serbring
Serbring 2019년 10월 6일
댓글: Serbring 2019년 10월 29일
Hi all,
I am trying to read on matlab several .MDF files. All of them are exported with the some tool and for some reasons, some of them are unsorted. I need to know which files are unsorted. Is there any way to do that?
Here is my code. If a file is unsorted I get an error when I read the file, so I added the two lines which sort the files (the two under comment), but in that case, if the file is sorted, I get an error at the mdfSort function. By knowing which files are unsorted, I can solve the problem with a If-statement.
for iFile=1:length(MDFFile)
Duration=-1;
% sortedPath = mdfSort([MDFFolder MDFFile(iFile).name],'SortedMDFFile.mdf');
% mdfObj = mdf('SortedMDFFile.mf4');
mdfObj = mdf([MDFFolder MDFFile(iFile).name]);
if isempty(mdfObj.ChannelNames)==0
chlist = channelList(mdfObj);
chlistS=table2struct(chlist);
chlistName=convertStringsToChars([chlistS.ChannelName]);
for iSig=1:length(Signals2Load)
iCh=find(strcmp(chlistName,Signals2Load{iSig}));
if isempty(iCh)==0
data = read(mdfObj,chlistS(min(iCh)).ChannelGroupNumber,Signals2Load{iSig});
if Duration<0
Duration=seconds(floor(max(data.Time)));
CanData(iFile).Time=[0:TS:Duration];
end
CanData(iFile).(Signals2Load{iSig})=pchip(seconds(data.Time),data.(Signals2Load{iSig}),CanData(iFile).Time);
end
end
else
warning(['Problems in loading ' MDFFile(iFile).name])
end
end
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 10월 6일
Perhaps you should use a try/catch ?
Serbring
Serbring 2019년 10월 6일
Probably I have to. I do not like that much try/catch. In my opinion, it is not a synonim of good practice. Thanks.

댓글을 달려면 로그인하십시오.

채택된 답변

Elliott Blocha
Elliott Blocha 2019년 10월 29일
The MDF file format specifies that "finalized" MDF files must start with "MDF " in the first 8 bytes (including the 5 spaces). In hex this is:
4D 44 46 20 20 20 20 20
Unfinalized (including unsorted) MDF files have "UnFinMF " in the first 8 bytes (including the 1 space). In hex this is:
55 6E 46 69 6E 4D 46 20
Look into the "fopen" and "fread" functions to check for the "finalized" flag.
mdfSort might already do this check, so it may be faster to use a try/catch statement.
  댓글 수: 1
Serbring
Serbring 2019년 10월 29일
Hi!
Thanks for your answer!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Vehicle Calibration에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by