function [Header,Fields]=gprmax(name);
% GPRMAX3D Read binary data generated by 'GprMax3D' and 'GprMax2D'
% simulators for ground probing radar.
%
% [Header, Fields] = gprmax( 'filename' )
% filename is the name of a binary format file generated either
% from 'GprMax3D' or 'GprMax2D'
%
% Header is a structure containing details of the model
%
% Fields is a structure containing the electromagnetic fields at
% the requested output points for a number of requested
% steps
%
%
% (NOTE: The field matrices of snapshots cary 3D data
% Copyright: Antonis Giannopoulos, 1997, 2002, 2005
% This file is not part of the 'GprMax3D' programme for ground probing
% radar simulation and can be freely distributed.
FT_3D=30200;
FT_2D=20200;
SMALL=0;
BIG=0;
if(nargin==0)
error('GprMax3D requires at least one argument');
end;
if(nargin==1)
type='native';
end;
if(isstr(name)~=1)
error('First argument is not a filename');
end;
fid=fopen(name,'rb');
if(fid==-1)
error(['Can not open =',name]);
end;
ECHECK1=fread(fid,1,'char');
if(strcmp(setstr(dec2hex(ECHECK1)),'2B')==1 )
SMALL=0;
BIG=1;
end;
if(strcmp(setstr(dec2hex(ECHECK1)),'67')==1 )
SMALL=1;
BIG=0;
end;
ECHECK2=fread(fid,1,'char');
if(BIG==1)
if(strcmp(setstr(dec2hex(ECHECK2)),'67') == 0)
error(['This is not a GprMax2D/3D file.']);
end;
end;
if(SMALL==1)
if(strcmp(setstr(dec2hex(ECHECK2)),'2B') == 0)
error(['This is not a GprMax2D/3D file.']);
end;
end;
% If you are here you have a valid file. Unless someone is playing a but joke !!
% Close and open again to make sure you will read it properly.
fclose(fid);
if(SMALL==1)
fid=fopen(name,'rb','ieee-le');
end;
if(BIG==1)
fid=fopen(name,'rb','ieee-be');
end;
% Read Endian again but no check !
temp=fread(fid,1,'short');
% Read type of file
FileType=fread(fid,1,'short');
SWORD=fread(fid,1,'short');
SREAL=fread(fid,1,'short');
TITLELENGTH=fread(fid,1,'short');
SOURCELENGTH=fread(fid,1,'short');
MEDIALENGTH=fread(fid,1,'short');
RESERVED=fread(fid,2,'char');
if(SWORD==2)
word='short';
end;
if(SWORD==4)
word='long';
end;
if(SREAL==4)
real='float';
end;
if(SREAL==8)
real='double';
end;
% Set Defaults for all
Model=struct([]);
Rx=struct([]);
% Set title to none
%Model(1).title='No title';
switch FileType
case FT_2D+4 % 2D snapshot
disp(['Reading GprMax2D #snapshot: file ...',name]);
Model(1).title=fread(fid,TITLELENGTH,'char');
Model(1).title=setstr(Model(1).title');
Model(1).iterations=fread(fid,1,real);
Model(1).dx=fread(fid,1,real);
Model(1).dy=fread(fid,1,real);
Model(1).dt=fread(fid,1,real);
Model(1).globalTx=fread(fid,1,word);
Model(1).Snapx1=fread(fid,1,word);
Model(1).Snapy1=fread(fid,1,word);
Model(1).Snapx2=fread(fid,1,word);
Model(1).Snapy2=fread(fid,1,word);
Model(1).Snapxs=fread(fid,1,word);
Model(1).Snapys=fread(fid,1,word);
stime=fread(fid,1,real);
Model(1).snaptime=stime*Model(1).dt/1e-9;
Model(1).Snapxsam=fread(fid,1,word);
Model(1).Snapysam=fread(fid,1,word);
Rx(1).ez=zeros(Model(1).Snapxsam,Model(1).Snapysam);
Rx(1).hx=zeros(Model(1).Snapxsam,Model(1).Snapysam);
Rx(1).hy=zeros(Model(1).Snapxsam,Model(1).Snapysam);
Rx(1).ez=fread(fid,[Model(1).Snapxsam Model(1).Snapysam],real);
Rx(1).hx=fread(fid,[Model(1).Snapxsam Model(1).Snapysam],real);
Rx(1).hy=fread(fid,[Model(1).Snapxsam Model(1).Snapysam],real);
case FT_3D+4 % 3D snapshot
disp(['Reading GprMax3D #snapshot: file ...',name]);
Model(1).title=fread(fid,TITLELENGTH,'char');
Model(1).title=setstr(Model(1).title');
Model(1).iterations=fread(fid,1,real);
Model(1).dx=fread(fid,1,real);
Model(1).dy=fread(fid,1,real);
Model(1).dz=fread(fid,1,real);
Model(1).dt=fread(fid,1,real);
Model(1).globalTx=fread(fid,1,word);
Model(1).Snapx1=fread(fid,1,word);
Model(1).Snapy1=fread(fid,1,word);
Model(1).Snapz1=fread(fid,1,word);
Model(1).Snapx2=fread(fid,1,word);
Model(1).Snapy2=fread(fid,1,word);
Model(1).Snapz2=fread(fid,1,word);
Model(1).Snapxs=fread(fid,1,word);
Model(1).Snapys=fread(fid,1,word);
Model(1).Snapzs=fread(fid,1,word);
stime=fread(fid,1,real);
Model(1).snaptime=stime*Model(1).dt/1e-9;
Model(1).Snapxsam=fread(fid,1,word);
Model(1).Snapysam=fread(fid,1,word);
Model(1).Snapzsam=fread(fid,1,word);
Rx(1).ex=zeros(Model(1).Snapxsam,Model(1).Snapysam,Model(1).Snapzsam);
Rx(1).ey=zeros(Model(1).Snapxsam,Model(1).Snapysam,Model(1).Snapzsam);
Rx(1).ez=zeros(Model(1).Snapxsam,Model(1).Snapysam,Model(1).Snapzsam);
Rx(1).hx=zeros(Model(1).Snapxsam,Model(1).Snapysam,Model(1).Snapzsam);
Rx(1).hy=zeros(Model(1).Snapxsam,Model(1).Snapysam,Model(1).Snapzsam);
Rx(1).hz=zeros(Model(1).Snapxsam,Model(1).Snapysam,Model(1).Snapzsam);
Rx(1).ix=zeros(Model(1).Snapxsam,Model(1).Snapysam,Model(1).Snapzsam);
Rx(1).iy=zeros(Model(1).Snapxsam,Model(1).Snapysam,Model(1).Snapzsam);
Rx(1).iz=zeros(Model(1).Snapxsam,Model(1).Snapysam,Model(1).Snapzsam);
for i=1:Model(1).Snapxsam
temp=fread(fid,[Model(1).Snapzsam Model(1).Snapysam],real);
Rx(1).ex(i,:,:)=temp';
end
for i=1:Model(1).Snapxsam
temp=fread(fid,[Model(1).Snapzsam Model(1).Snapysam],real);
Rx(1).ey(i,:,:)=temp';
end
for i=1:Model(1).Snapxsam
temp=fread(fid,[Model(1).Snapzsam Model(1).Snapysam],real);
Rx(1).ez(i,:,:)=temp';
end
for i=1:Model(1).Snapxsam
temp=fread(fid,[Model(1).Snapzsam Model(1).Snapysam],real);
Rx(1).hx(i,:,:)=temp';
end
for i=1:Model(1).Snapxsam
temp=fread(fid,[Model(1).Snapzsam Model(1).Snapysam],real);
Rx(1).hy(i,:,:)=temp';
end
for i=1:Model(1).Snapxsam
temp=fread(fid,[Model(1).Snapzsam Model(1).Snapysam],real);
Rx(1).hz(i,:,:)=temp';
end
for i=1:Model(1).Snapxsam
temp=fread(fid,[Model(1).Snapzsam Model(1).Snapysam],real);
Rx(1).ix(i,:,:)=temp';
end
for i=1:Model(1).Snapxsam
temp=fread(fid,[Model(1).Snapzsam Model(1).Snapysam],real);
Rx(1).iy(i,:,:)=temp';
end
for i=1:Model(1).Snapxsam
temp=fread(fid,[Model(1).Snapzsam Model(1).Snapysam],real);
Rx(1).iz(i,:,:)=temp';
end
case FT_2D % 2D step
disp(['Reading GprMax2D #analysis: file ...',name]);
Model(1).title=fread(fid,TITLELENGTH,'char');
Model(1).title=setstr(Model(1).title');
Model(1).iterations=fread(fid,1,real);
Model(1).dx=fread(fid,1,real);
Model(1).dy=fread(fid,1,real);
Model(1).dt=fread(fid,1,real);
Model(1).NSteps=fread(fid,1,word);
Model(1).TxStepX=fread(fid,1,word);
Model(1).TxStepY=fread(fid,1,word);
Model(1).RxStepX=fread(fid,1,word);
Model(1).RxStepY=fread(fid,1,word);
Model(1).ntx=fread(fid,1,word);
Model(1).nrx=fread(fid,1,word);
Model(1).nrx_box=fread(fid,1,word);
for i=1:Model(1).ntx
Model(1).tx(i)=fread(fid,1,word);
Model(1).ty(i)=fread(fid,1,word);
Model(1).source(i,1:SOURCELENGTH)=fread(fid,SOURCELENGTH,'char')';
Model(1).delay(i)=fread(fid,1,real);
Model(1).remo

御道御小黑
- 粉丝: 98
最新资源
- 继电器在电气工程及自动化低压电器中的应用.docx
- 典型网络工程的案例分析.doc
- 全国计算机等考试二C笔试试卷.doc
- 大学计算机实验报告记录样本.doc
- 科大讯飞人工智能定义城市1.0版本发布.docx
- 软件学院软件工程硕士版培养方案终稿单证.doc
- 基于单片机的数字万用表研究设计.doc
- 集团公司大数据平台建设方案.docx
- 南京大学关于机器学习的 PPT 教学课件
- 热电厂建设项目管理控制研究.docx
- 项目管理的难点与对策.doc
- Oracle程序设计.docx
- 不依赖 sk-learn 库的纯 Python 机器学习算法实现
- 基于单片机的抢答器的方案设计书.doc
- 试论大数据环境下的企业财务管理改革路径.docx
- 初中英语教师基于网络平台的自主发展.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



评论0