Skip to content

Commit

Permalink
Merge pull request #794 from aodn/FixBottomTracking
Browse files Browse the repository at this point in the history
Fix(readAD2CPBinary): various issues with Bottom tracking parser
  • Loading branch information
evacougnon authored Jan 10, 2023
2 parents 62970dd + 7ea6f15 commit 9afd769
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
42 changes: 22 additions & 20 deletions Parser/readAD2CPBinary.m
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,13 @@

end

function sect = readBottomTrack(data, idx, cpuEndianness)
function [sect, len, off] = readBottomTrack(data, idx, cpuEndianness)
%READBOTTOMTRACK
% Id=0x17, Bottom Track Data Record

sect = struct;
[sect.Header, ~, off] = readHeader(data, idx, cpuEndianness);
[sect.Header, len, off] = readHeader(data, idx, cpuEndianness);
len = len + sect.Header.DataSize;

idx = idx+off;

Expand All @@ -542,7 +543,7 @@
sect.Data.Beams_CoordSys_Cells = dec2bin(bytecast(data(idx+30:idx+31), 'L', 'uint16', cpuEndianness), 16);
iStartBeam = 13;
iEndBeam = 16;
sect.Data.nBeams = bin2dec(sect.Beams_CoordSys_Cells(end-iEndBeam+1:end-iStartBeam+1));
sect.Data.nBeams = bin2dec(sect.Data.Beams_CoordSys_Cells(end-iEndBeam+1:end-iStartBeam+1));

sect.Data.CellSize = bytecast(data(idx+32:idx+33), 'L', 'uint16', cpuEndianness); % 1 mm
sect.Data.Blanking = bytecast(data(idx+34:idx+35), 'L', 'uint16', cpuEndianness); % 1 mm
Expand All @@ -555,32 +556,33 @@
sect.Data.AccRawX = bytecast(data(idx+46:idx+47), 'L', 'int16', cpuEndianness); % accelerometer Raw, X axis value in last measurement interval (16384 = 1.0)
sect.Data.AccRawY = bytecast(data(idx+48:idx+49), 'L', 'int16', cpuEndianness);
sect.Data.AccRawZ = bytecast(data(idx+50:idx+51), 'L', 'int16', cpuEndianness);
sect.Data.AmbiguityVel = bytecast(data(idx+52:idx+53), 'L', 'uint16', cpuEndianness); % 10^(Velocity scaling) m/s ; corrected for sound velocity
sect.Data.DatasetDesc = dec2bin(bytecast(data(idx+54:idx+55), 'L', 'uint16', cpuEndianness), 16);
sect.Data.TransmitEnergy = bytecast(data(idx+56:idx+57), 'L', 'uint16', cpuEndianness);
sect.Data.VelocityScaling = bytecast(data(idx+58), 'L', 'int8', cpuEndianness);
sect.Data.PowerLevel = bytecast(data(idx+59), 'L', 'int8', cpuEndianness); % dB
sect.Data.MagTemperature = bytecast(data(idx+60:idx+61), 'L', 'int16', cpuEndianness); % uncalibrated
sect.Data.RTCTemperature = bytecast(data(idx+62:idx+63), 'L', 'int16', cpuEndianness); % 0.01 deg C
sect.Data.Error = bytecast(data(idx+64:idx+67), 'L', 'uint32', cpuEndianness);
sect.Status = dec2bin(bytecast(data(idx+68:idx+71), 'L', 'uint32', cpuEndianness), 32);
sect.Data.EnsembleCounter = bytecast(data(idx+72:idx+75), 'L', 'uint32', cpuEndianness); % counts the number of ensembles in both averaged and burst data

off = 75;
sect.Data.AmbiguityVel = bytecast(data(idx+52:idx+55), 'L', 'uint32', cpuEndianness); % 10^(Velocity scaling) m/s ; corrected for sound velocity
sect.Data.DatasetDesc = dec2bin(bytecast(data(idx+56:idx+57), 'L', 'uint16', cpuEndianness), 16);
sect.Data.TransmitEnergy = bytecast(data(idx+58:idx+59), 'L', 'uint16', cpuEndianness);
sect.Data.VelocityScaling = bytecast(data(idx+60), 'L', 'int8', cpuEndianness);
sect.Data.PowerLevel = bytecast(data(idx+61), 'L', 'int8', cpuEndianness); % dB
sect.Data.MagTemperature = bytecast(data(idx+62:idx+63), 'L', 'int16', cpuEndianness); % uncalibrated
sect.Data.RTCTemperature = bytecast(data(idx+64:idx+65), 'L', 'int16', cpuEndianness); % 0.01 deg C
sect.Data.Error = bytecast(data(idx+66:idx+69), 'L', 'uint32', cpuEndianness);
sect.Data.Status = dec2bin(bytecast(data(idx+70:idx+73), 'L', 'uint32', cpuEndianness), 32);
sect.Data.EnsembleCounter = bytecast(data(idx+74:idx+77), 'L', 'uint32', cpuEndianness); % counts the number of ensembles in both averaged and burst data

off = 77;
if isVelocity
sect.VelocityData = bytecast(data(idx+off+1:idx+off+sect.nBeams*4), 'L', 'int32', cpuEndianness); % 10^(velocity scaling) m/s
off = off+sect.nBeams*4;
sect.Data.VelocityData = bytecast(data(idx+off+1:idx+off+sect.Data.nBeams*4), 'L', 'int32', cpuEndianness); % 10^(velocity scaling) m/s
off = off+sect.Data.nBeams*4;
end

if isDistance
sect.DistanceData = bytecast(data(idx+off+1:idx+off+sect.nBeams*4), 'L', 'int32', cpuEndianness); % mm
off = off+sect.nBeams*4;
sect.Data.DistanceData = bytecast(data(idx+off+1:idx+off+sect.Data.nBeams*4), 'L', 'int32', cpuEndianness); % mm
off = off+sect.Data.nBeams*4;
end

if isFigureOfMerit
sect.FigureOfMeritData = bytecast(data(idx+off+1:idx+off+sect.nBeams*2), 'L', 'uint16', cpuEndianness);
sect.Data.FigureOfMeritData = bytecast(data(idx+off+1:idx+off+sect.Data.nBeams*2), 'L', 'uint16', cpuEndianness);
end

off = len;
end

function [sect, len, off] = readString(data, idx, cpuEndianness)
Expand Down
8 changes: 8 additions & 0 deletions test/Parser/testSignature.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
s250_file = files2namestruct(rdir([toolboxRootPath 'data/testfiles/Nortek/signature_250/v000']));
s500_file = files2namestruct(rdir([toolboxRootPath 'data/testfiles/Nortek/signature_500/v000']));
s1000_file = files2namestruct(rdir([toolboxRootPath 'data/testfiles/Nortek/signature_1000/v000']));
bottomtracking_file = files2namestruct(rdir([toolboxRootPath 'data/testfiles/Nortek/bottom_tracking']));

end

Expand All @@ -37,6 +38,13 @@ function testReadSignature1000(~, s1000_file, mode)
assert(data{1}.meta.beam_angle==25);
end

function testBottomTracking(~, bottomtracking_file, mode)
data = signatureParse({bottomtracking_file},mode);
assert(strcmp(data{1}.meta.instrument_model,'Signature250'));
assert(strcmp(data{1}.meta.instrument_make,'Nortek'));
assert(data{1}.meta.beam_angle==20);
assert(round(min(data{1}.variables{11, 1}.data)) == 20);
end

end

Expand Down

0 comments on commit 9afd769

Please sign in to comment.