Problem with understanding timestamp read from a binary file using fread
4 views (last 30 days)
Show older comments
I read a binary file which has the following structure :
struct request
{
uint32_t timestamp;
uint32_t clientID;
uint32_t objectID;
uint32_t size;
uint8_t method;
uint8_t status;
uint8_t type;
uint8_t server;
};
the code I used to read this file is :
int_32=[];
int_8=[];
fid = fopen('wc_day6_1','r');
int_32=fread(fid,'4*uint32',4);
frewind(fid);
fseek(fid,16,'bof');
int_8=fread(fid,'4*uint8',16);
A=reshape(int_32,4,[]);
B=reshape(int_8,4,[]);
At=A';
Bt=B';
data=horzcat(A',B');
The trace says that the data is for one day and the time stamp is in seconds. But the difference between the smallest time stamp and the largest is not equal to 86400(60*60*24).I am just not able to identify where I went wrong. Please help.
0 Comments
Answers (1)
dpb
on 25 Mar 2014
nt_32=fread(fid,'4*uint32',4);
From doc for fread --
When SKIP is used, the PRECISION string may contain a positive
integer repetition factor of the form 'N*' which prepends the source
format of the PRECISION argument, like '40*uchar'. Note that 40*uchar
for the PRECISION alone is equivalent to '40*uchar=>double', not
'40*uchar=>uchar'. ...
Think you need
nt_32=fread(fid,'4*uint32=>uint32',4);
and similarly for the uint8's as well.
I'd recommend
doc memmapfile
to you and look at mapping the structure to make the read a little cleaner altho your route should work if you get the type conversions correct.
0 Comments
See Also
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!