📄 readshadebin.m
字号:
function [ title, freq, nsd, nrd, nrr, sd, rd, rr, tlt, FileStatus ] = ReadShadeBin( filename )
% Reads in TL surfaces from a binary Bellhop/Kraken .SHD file
% without having to convert to ASCII first.
% Chris Tiemann, Feb. 2001
% Modified by Alec Duncan, June 2002 to add error checking
FileStatus = 1;
fid = fopen( filename, 'rb' );
if fid < 0
uiwait(warndlg(['Couldn''t open input file: ' filename]));
FileStatus = 0;
title = '';
freq = [];
nsd = [];
nrd = [];
nrr = [];
sd = [];
rd = [];
rr = [];
tlt = [];
return;
end
recl = fread( fid, 1, 'int32'); %record length in bytes will be 4*recl
title = setstr( fread( fid, 80, 'uchar' ) )';
fseek(fid, 4*recl, -1); %reposition to end of first record
plottype = fread(fid, 10, 'uchar');
xs = fread( fid, 1, 'float32');
ys = fread( fid, 1, 'float32');
theta = fread( fid, 1, 'float32');
fseek(fid, 2*4*recl, -1); %reposition to end of second record
freq = fread( fid, 1, 'float32');
nsd = fread( fid, 1, 'int32');
nrd = fread( fid, 1, 'int32');
nrr = fread( fid, 1, 'int32');
if (nrr<= 0) | (nsd <= 0) | (nrd <= 0) | (freq <= 0)
FileStatus = 0;
fclose(fid);
Msg = {'Invalid shade file parameters:', ...
['Frequency = ' num2str(freq)], ...
['Number of source depths = ' int2str(nsd)], ...
['Number of receiver depths = ' int2str(nrd)], ...
['Number of receiver ranges = ' int2str(nrr)]};
uiwait(warndlg(Msg));
sd = [];
rd = [];
rr = [];
tlt = [];
return;
end
fseek(fid, 3*4*recl, -1); %reposition to end of third record
sd = fread( fid, nsd, 'float32');
fseek(fid, 4*4*recl, -1); %reposition to end of fourth record
rd = fread( fid, nrd, 'float32');
fseek(fid, 5*4*recl, -1); %reposition to end of fifth record
rr = fread( fid, nrr, 'float32');
%Each record holds data from one source depth/receiver depth pair
tlt = zeros( nrd, nrr, nsd );
for i = 1:nsd
%disp(['Reading data for source ' num2str(i) ' of ' num2str(nsd)])
for j = 1:nrd
recnum = 6 + (i-1)*nrd + j;
fseek(fid, (recnum-1)*4*recl, -1); %Move to end of previous record
temp = fread(fid, 2*nrr, 'float32'); %Read complex data
tlt(j, :, i) = temp( 1:2:2*nrr ) + sqrt(-1)*temp(2:2:2*nrr);
%Transmission loss matrix indexed by rd x rr x sd
end
end
fclose(fid);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -