function write_dzt_file(data,parameter)
% 数据*.dzt格式
[r,c]=size(data);
data=data';
traces=r;
n0=parameter.n0;
dx=parameter.dx;
dxante=0.5;
dt=parameter.dt;
f0=200.0;
pulsev=1000;
nstack=64;
n1=1;
n2=c;
n=n2-n1+1;
%path='C:\Users\wang\Desktop\Data\';
[name,path] = uiputfile({'*.dzt';'*.DZT';'*.*'},'保存');
filename=[path name];
h_data=fopen(filename,'w');
rh.tag=255; %1 2047
rh.Header_size=1024;
rh.nsamp=c;
%rh.bits=32;
rh.bits=0;
rh.zero=-32768; %2^Bits_per_word/2 - 1
rh.sps=0.0;%1.0/dx;
rh.spm=1.0/dx;
rh.mpm=0;
rh.position=0;
rh.range=rh.nsamp*dt;
rh.npass=0;
fwrite(h_data,rh.tag,'ushort');%2
%fwrite(h_data,rh.tag,'ushort');%2
fwrite(h_data,1024,'ushort'); %4
fwrite(h_data,c,'ushort'); %6
fwrite(h_data,rh.bits,'ushort'); %8
fwrite(h_data,2^rh.bits/2-1,'short'); %10 rh-zero binary offset ( - 128 , - 32768 ,etc)
%fwrite(h_data,rh.zero,'short'); %10 rh-zero binary offset ( - 128 , - 32768 ,etc)
fwrite(h_data,32,'float'); %14 rh- sps scans per second
%fwrite(h_data,rh.sps,'float'); %14 rh- sps scans per second
fwrite(h_data,rh.spm,'float'); %18 rh- spm; scans per meter
fwrite(h_data,rh.mpm,'float'); %22 rh-mpm meter per mark
fwrite(h_data,rh.position,'float'); %26
fwrite(h_data,rh.range,'float'); %30
fwrite(h_data,0,'ushort'); %32
fwrite(h_data,1,'ubit5'); %sec
fwrite(h_data,1,'ubit6'); %min
fwrite(h_data,1,'ubit5'); %hour
fwrite(h_data,1,'ubit5'); %day
fwrite(h_data,1,'ubit4'); %month
fwrite(h_data,30,'ubit7');% year
fwrite(h_data,1,'ubit5'); %sec
fwrite(h_data,1,'ubit6'); %min
fwrite(h_data,1,'ubit5'); %hour
fwrite(h_data,1,'ubit5'); %day
fwrite(h_data,1,'ubit4'); %month
fwrite(h_data,30,'ubit7'); % year 40
rh.Offset_to_range_gain=0;
rh.nrgain=0;
rh.Offset_to_text=512;
rh.Size_of_text=0;
rh.Offset_to_proc_hist=128;
rh.Size_of_proc_hist=35;
rh.nchan=1;
rh.epsr=1.0;
rh.top=0.0;
rh.depth=15;
rh.reserved=zeros(31,1); %rh.reserved(1:31)='0';
rh.dtype=0;
fwrite(h_data,128,'ushort');
fwrite(h_data,0,'ushort');
fwrite(h_data,128,'ushort'); %128
fwrite(h_data,896,'ushort');
fwrite(h_data,896+128,'ushort');
fwrite(h_data,0,'ushort');
fwrite(h_data,1,'ushort'); %54
fwrite(h_data,9,'float');
fwrite(h_data,0,'float');
fwrite(h_data,0,'float'); %66
fwrite(h_data,rh.reserved,'uchar');%97
fwrite(h_data,2,'uchar');%98
rh.antname(1)='S';
rh.antname(2)='2';
rh.antname(3)='7';
rh.antname(4)='0';
rh.antname(5)='M';
rh.antname(6)='H';
rh.antname(7)='z';
rh.antname(8:14)=' ';
fwrite(h_data,rh.antname,'uchar');%112
rh.chanmask=1; %rh.chanmask=0;
fwrite(h_data,rh.chanmask,'ushort'); %114
rh.name(1)='0';
rh.name(2)='0';
rh.name(3)='1';
rh.name(4:12)=' ';
fwrite(h_data,rh.name,'uchar');%126
rh.chksum=0;
fwrite(h_data,0,'ushort'); %128
rh.variable(1:896)=0;
fwrite(h_data,rh.variable,'uchar');%1024
% maxdata=max(max(abs(data)));
% data = data + maxdata;
% d = (2^rh.bits - 1)*data/(2*maxdata);
%fwrite(h_data,data,'int');
% dn = min(min(data));
% if dn < 0,
% data = data + abs(dn);
% else
% data = data - dn;
% end
% dn = max(max(abs(data)));
% d = (2^rh.bits - 1)*data/dn;
% %%%%% %%% Append first two lines for health status (1st line) and marker info
% %%% (2nd line)
% d = [hex2dec('FFFF') + zeros(1,c); ...
% hex2dec('F000') + zeros(1,c); ...
% d];
% %%% Set marker traces
% if ~isempty(parameter.markertr),
% mtr = parameter.markertr(:,1)';
% d(2,mtr) = hex2dec('E800');
% end
% %%%%%
% fwrite(h_data,d,'uint32');
% figure(3);imagesc(d);
fwrite(h_data,data,'float');
fclose(h_data);
评论9