The code below give me an error message "Reading GprMax2D #analysis: file ...bre1.out Error using reshape To RESHAPE the number of elements must not change. Error in gprmax (line 277) ez=reshape​(F(1:3:end​),[TotalOu​ts,Model(1​).iteratio​ns,Mod"

fileout = 'bre1.out';
[Header,Fields]=gprmax(fileout); N=1:Header.NSteps; %移动次数
Position=Header.dx*Header.tx+(N-1)*(Header.dx*Header.TxStepX);
% 天线每次所在位置
Data(:,:)=Fields.ez(:,1,:); %转换数组格式
figure(2);
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).removed(i)=fread(fid,1,real);
end
Model(1).source=char(Model(1).source);
for i=1:Model(1).nrx
Model(1).rx(i)=fread(fid,1,word);
Model(1).ry(i)=fread(fid,1,word);
end
TotalOuts=Model(1).nrx;
kk=Model(1).nrx;
for i=1:Model(1).nrx_box
Model(1).rx_box(i).nouts=fread(fid,1,word);
TotalOuts=TotalOuts+Model(1).rx_box(i).nouts;
for k=kk+1:kk+Model(1).rx_box(i).nouts
Model(1).rx(k)=fread(fid,1,word);
Model(1).ry(k)=fread(fid,1,word);
end
kk=kk+Model(1).rx_box(i).nouts;
end
Rx(1).t=(0:Model(1).iterations-1)'*Model(1).dt;
%Read the data in single vector for speed
F=fread(fid,inf,real);
% Short out data in (Outputs,Iterations,Steps)
ez=reshape(F(1:3:end),[TotalOuts,Model(1).iterations,Model(1).NSteps]);
hx=reshape(F(2:3:end),[TotalOuts,Model(1).iterations,Model(1).NSteps]);
hy=reshape(F(3:3:end),[TotalOuts,Model(1).iterations,Model(1).NSteps]);
% Save the data in (Iterations,Outputs,Steps) format
if Model(1).NSteps == 1
Rx(1).ez=ez';
Rx(1).hx=hx';
Rx(1).hy=hy';
else
for i=1:TotalOuts
Rx(1).ez(:,i,:)=ez(i,:,:);
Rx(1).hx(:,i,:)=hx(i,:,:);
Rx(1).hy(:,i,:)=hy(i,:,:);
end
end
case FT_3D % 3D step
disp(['Reading GprMax3D #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).dz=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).TxStepZ=fread(fid,1,word);
Model(1).RxStepX=fread(fid,1,word);
Model(1).RxStepY=fread(fid,1,word);
Model(1).RxStepZ=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).polarization(i,:)=fread(fid,1,'char');
Model(1).polarization(i,:)=char(setstr(Model(1).polarization(i,:)'));
Model(1).tx(i)=fread(fid,1,word);
Model(1).ty(i)=fread(fid,1,word);
Model(1).tz(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).removed(i)=fread(fid,1,real);
end
Model(1).source=char(Model(1).source);
for i=1:Model(1).nrx
Model(1).rx(i)=fread(fid,1,word);
Model(1).ry(i)=fread(fid,1,word);
Model(1).rz(i)=fread(fid,1,word);
end
TotalOuts=Model(1).nrx;
kk=Model(1).nrx;
for i=1:Model(1).nrx_box
Model(1).rx_box(i).nouts=fread(fid,1,word);
TotalOuts=TotalOuts+Model(1).rx_box(i).nouts;
for k=kk+1:kk+Model(1).rx_box(i).nouts
Model(1).rx(k)=fread(fid,1,word);
Model(1).ry(k)=fread(fid,1,word);
Model(1).rz(k)=fread(fid,1,word);
end
kk=kk+Model(1).rx_box(i).nouts;
end
%Read the data in single vector for speed
Rx(1).t=(0:Model(1).iterations-1)'*Model(1).dt;
F=fread(fid,inf,real);
% Short out data in (Outputs,Iterations,Steps)
ex=reshape(F(1:9:end),TotalOuts,Model(1).iterations,Model(1).NSteps);
ey=reshape(F(2:9:end),TotalOuts,Model(1).iterations,Model(1).NSteps);
ez=reshape(F(3:9:end),TotalOuts,Model(1).iterations,Model(1).NSteps);
hx=reshape(F(4:9:end),TotalOuts,Model(1).iterations,Model(1).NSteps);
hy=reshape(F(5:9:end),TotalOuts,Model(1).iterations,Model(1).NSteps);
hz=reshape(F(6:9:end),TotalOuts,Model(1).iterations,Model(1).NSteps);
ix=reshape(F(7:9:end),TotalOuts,Model(1).iterations,Model(1).NSteps);
iy=reshape(F(8:9:end),TotalOuts,Model(1).iterations,Model(1).NSteps);
iz=reshape(F(9:9:end),TotalOuts,Model(1).iterations,Model(1).NSteps);
% Save the data in (Iterations,Outputs,Steps) format
if Model(1).NSteps == 1
Rx(1).ex=ex';
Rx(1).ey=ey';
Rx(1).ez=ez';
Rx(1).hx=hx';
Rx(1).hy=hy';
Rx(1).hz=hz';
Rx(1).ix=ix';
Rx(1).iy=iy';
Rx(1).iz=iz';
else
for i=1:TotalOuts
Rx(1).ex(:,i,:)=ex(i,:,:);
Rx(1).ey(:,i,:)=ey(i,:,:);
Rx(1).ez(:,i,:)=ez(i,:,:);
Rx(1).hx(:,i,:)=hx(i,:,:);
Rx(1).hy(:,i,:)=hy(i,:,:);
Rx(1).hz(:,i,:)=hz(i,:,:);
Rx(1).ix(:,i,:)=ix(i,:,:);
Rx(1).iy(:,i,:)=iy(i,:,:);
Rx(1).iz(:,i,:)=iz(i,:,:);
end
end
% That is a rather slower way to read data !!!
% for i=1:Model(1).NSteps
% for j=1:Model(1).iterations
% for k=1:Model(1).nrx
% Rx(1).ex(j,k,i)=fread(fid,1,real);
% Rx(1).ey(j,k,i)=fread(fid,1,real);
% Rx(1).ez(j,k,i)=fread(fid,1,real);
% Rx(1).hx(j,k,i)=fread(fid,1,real);
% Rx(1).hy(j,k,i)=fread(fid,1,real);
% Rx(1).hz(j,k,i)=fread(fid,1,real);
% Rx(1).ix(j,k,i)=fread(fid,1,real);
% Rx(1).iy(j,k,i)=fread(fid,1,real);
% Rx(1).iz(j,k,i)=fread(fid,1,real);
% end;
% kk=Model(1).nrx;
% for p=1:Model(1).nrx_box
%
% for k=kk+1:kk+Model(1).rx_box(p).nouts
% Rx(1).ex(j,k,i)=fread(fid,1,real);
% Rx(1).ey(j,k,i)=fread(fid,1,real);
% Rx(1).ez(j,k,i)=fread(fid,1,real);
% Rx(1).hx(j,k,i)=fread(fid,1,real);
% Rx(1).hy(j,k,i)=fread(fid,1,real);
% Rx(1).hz(j,k,i)=fread(fid,1,real);
% Rx(1).ix(j,k,i)=fread(fid,1,real);
% Rx(1).iy(j,k,i)=fread(fid,1,real);
% Rx(1).iz(j,k,i)=fread(fid,1,real);
% end
% kk=kk+Model(1).rx_box(p).nouts;
% end
% end
% end
case FT_3D+5
disp(['This is not a data file. It is a geometry file']);
disp(['Use GPRMAX3G.']);
case FT_2D+5
disp(['This is not a data file. It is a geometry file']);
disp(['Use GPRMAX2G.']);
otherwise
disp(['This is not a valid GprMax2D/3D Ver 2.0 data file.']);
disp(['It may be an older version data file']);
end
Header=Model;
Fields=Rx;
%close file
fclose(fid);
imagesc(Position,Fields.t*1e9,Data);%画图
colorbar
xlabel('Antena Position (m)');
ylabel('t(ns)');

Answers (0)

Categories

Tags

Asked:

on 14 Mar 2016

Commented:

on 25 May 2016

Community Treasure Hunt

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

Start Hunting!