Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

how to read date and time in a binary header file

Asked by REJI on 17 Jul 2013

i want to read the header info of a binary file which contains the time and date.i used the following code. but i'm not getting.Kindly help....

close all; clear all; close all; clc fi=fopen ('C:\mar6\file\a.txt','r'); n=1;l2=60; % R = nan ([2000 l2]); % CN=nan ([2000 l2]); for j=1:60 g=fscanf(fi,'%s',1) l1=fopen(g,'r') % headerread=struct('Mustbe',fread(l1,1,'int16'),'trigger',fread(l1,1,'int8'),'Dwell', fread(l1,1,'int8'),... 'Dwellunits',fread(l1,1,'int8'),'Acqmode',fread(l1,1,'int8'),'Dwell913',fread(l1,1,'int64'),.... 'Passlen',fread(l1,1,'int16'),'passcount',fread(l1,1,'int16'),'passcountpreset',fread(l1,1,'int16'),.... 'acq_time1',fread(l1,8,'*char'),'acq_date1',fread(l1,8,'*char'),'Markcha',fread(l1,1,'int16'),'MCSno',fread(l1,1,'int8'),.... 'Caltype',fread(l1,1,'int8'),'CalUnits',fread(l1,4,'*char'),'CalCoef0',fread(l1,1,'float'),'CalCoel1',fread(l1,1,'float'),.... 'Extdwell',fread(l1,1,'int16'),'Res',fread(l1,1,'int32'),'Res1',fread(l1,1,'int8'),'Summode',fread(l1,1,'int8'),.... 'Idebyte',fread(l1,1,'int8'),'Prodwell',fread(l1,1,'int8'),'Deslength',fread(l1,1,'int8'),'Detdis',fread(l1,68,'*char'),.... 'SamDeslen',fread(l1,1,'int8'),'SamDes',fread(l1,68,'*char'),'Lineardisplayflag',fread(l1,1,'int8'),... 'Linearscale',fread(l1,1,'int8'),'Dispstart',fread(l1,1,'int16'),'Dispnoofchannels',fread(l1,1,'int16'),... 'Res2',fread(l1,1,'*char'),'Discsel',fread(l1,1,'int8'),'Discedge',fread(l1,1,'int8'),'Discvol',fread(l1,1,'float'),... 'SCAulv',fread(l1,1,'float'),'SCAllv',fread(l1,1,'float'),'Dwelltime',fread(l1,1,'float'),'Conflag',fread(l1,1,'int8'),... 'Res3',fread(l1,13,'*char'),'Calcoef2',fread(l1,1,'float'),'Calcoef3',fread(l1,1,'float'),'MCSIDstring',fread(l1,8,'*char')); t1(1,j)=str2num('l1(1:2)') t2(i,j)=str2double('g.acq_time1(4:5'); t3(i,j)=str2double('g.acq_time1(7:8)'); t4(i,j)=t1(i,j)+(t2(i,j))./60+(t3(i,j))./3600; if t4(i,j)<17 t4(i,j)=t4(i,j)+24

end

4 Comments

Jan Simon on 18 Jul 2013

"close all, clear all, close all, clc" is an extra brute clearing header: On one hand closing all figure twice is meaningless. On the other hand "clear all" deletes all the breakpoints also and impedes, that you can use the debugger to find the reasons of the problems by your own. Because the debugger is the friend of the programmer, "clear all" is an enemy.

Because we do not know the contents of the file you want to read, it is not helpful if you post the failing code. It is impossible to guess, why it is failing. So please explain "I'm not getting" with much more details. Do this by editing the original message, not by adding a comment or answer. The readers want to find all required information at one location.

Jan Simon on 18 Jul 2013

@dpb: We both really tried to encourage the OP to improve the question. Unfortunately he hesitates to do so.

dpb on 19 Jul 2013

Indeed... :(

Seems like a lot recently that have either never returned or at least left no trail if they did after providing either answers or requesting further clarifications or simply making (hopefully improving) comments.

It's quite discouraging given the amount of effort it takes to respond in the forum format anyway that it's more impetus to just stick to cs-sm--at least there one has the benefit of a newsreader to only get the active stuff w/o having to go find it.

REJI

Products

No products are associated with this question.

1 Answer

Answer by REJI on 18 Jul 2013

close all; clear all; close all; clc fi=fopen ('C:\mar6\file\a.txt','r'); n=1;l2=60; for j=1:60 g=fscanf(fi,'%s',1) l1=fopen(g,'r') % headerread=struct('Mustbe',fread(l1,1,'int16'),'trigger',fread(l1,1,'int8'),'Dwell', fread(l1,1,'int8'),... 'Dwellunits',fread(l1,1,'int8'),'Acqmode',fread(l1,1,'int8'),'Dwell913',fread(l1,1,'int64'),.... 'Passlen',fread(l1,1,'int16'),'passcount',fread(l1,1,'int16'),'passcountpreset',fread(l1,1,'int16'),.... 'acq_time1',fread(l1,8,'*char'),'acq_date1',fread(l1,8,'*char'),'Markcha',fread(l1,1,'int16'),'MCSno',fread(l1,1,'int8'),.... 'Caltype',fread(l1,1,'int8'),'CalUnits',fread(l1,4,'*char'),'CalCoef0',fread(l1,1,'float'),'CalCoel1',fread(l1,1,'float'),.... 'Extdwell',fread(l1,1,'int16'),'Res',fread(l1,1,'int32'),'Res1',fread(l1,1,'int8'),'Summode',fread(l1,1,'int8'),.... 'Idebyte',fread(l1,1,'int8'),'Prodwell',fread(l1,1,'int8'),'Deslength',fread(l1,1,'int8'),'Detdis',fread(l1,68,'*char'),.... 'SamDeslen',fread(l1,1,'int8'),'SamDes',fread(l1,68,'*char'),'Lineardisplayflag',fread(l1,1,'int8'),... 'Linearscale',fread(l1,1,'int8'),'Dispstart',fread(l1,1,'int16'),'Dispnoofchannels',fread(l1,1,'int16'),... 'Res2',fread(l1,1,'*char'),'Discsel',fread(l1,1,'int8'),'Discedge',fread(l1,1,'int8'),'Discvol',fread(l1,1,'float'),... 'SCAulv',fread(l1,1,'float'),'SCAllv',fread(l1,1,'float'),'Dwelltime',fread(l1,1,'float'),'Conflag',fread(l1,1,'int8'),... 'Res3',fread(l1,13,'*char'),'Calcoef2',fread(l1,1,'float'),'Calcoef3',fread(l1,1,'float'),'MCSIDstring',fread(l1,8,'*char'));

t1(1,j)=str2num('l1(1:2)') t2(i,j)=str2double('g.acq_time1(4:5'); t3(i,j)=str2double('g.acq_time1(7:8)'); t4(i,j)=t1(i,j)+(t2(i,j))./60+(t3(i,j))./3600; if t4(i,j)<17 t4(i,j)=t4(i,j)+24 end

1 Comment

Jan Simon on 18 Jul 2013

Please remove this. It is much better to add all important details to the original question instead of using the answers or comment sections.

Please follow the "? Help" link to learn, how to format code in the forum. It is not really intuitive, but very easy. And omitting the formatting hurts the eyes of the reader.

REJI

Contact us