Skip to content

Commit

Permalink
readParadoppBinary function now stores Nortek data in arrays of struc…
Browse files Browse the repository at this point in the history
…tures instead of trying to concatenate all fields of a structure. Fixes bug with some Nortek files where there are more than 1 head / config/ hardware section.
  • Loading branch information
ggalibert committed Jan 4, 2017
1 parent fc6759a commit f79a111
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 301 deletions.
109 changes: 35 additions & 74 deletions Parser/aquadoppProfilerParse.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,51 +68,11 @@
% this is a plain profiler velocity data
profilerType = 'Id33';
end
nsamples = length(structures.(profilerType).Id);
ncells = user.NBins;

% preallocate memory for all sample data
time = nan(nsamples, 1);
distance = nan(ncells, 1);
analn1 = nan(nsamples, 1);
battery = nan(nsamples, 1);
analn2 = nan(nsamples, 1);
heading = nan(nsamples, 1);
pitch = nan(nsamples, 1);
roll = nan(nsamples, 1);
status = zeros(nsamples, 8, 'uint8');
pressure = nan(nsamples, 1);
temperature = nan(nsamples, 1);
velocity1 = nan(nsamples, ncells);
velocity2 = nan(nsamples, ncells);
velocity3 = nan(nsamples, ncells);
backscatter1 = nan(nsamples, ncells);
backscatter2 = nan(nsamples, ncells);
backscatter3 = nan(nsamples, ncells);

velocityProcessed = false;
if isfield(structures, 'Id106')
% velocity has been processed
velocityProcessed = true;
nsamplesProc = length(structures.Id106.Sync);
timeProc = nan(nsamplesProc, 1);
velocity1Proc = nan(nsamples, ncells);
velocity2Proc = nan(nsamples, ncells);
velocity3Proc = nan(nsamples, ncells);
sig2noise1 = nan(nsamples, ncells);
sig2noise2 = nan(nsamples, ncells);
sig2noise3 = nan(nsamples, ncells);
stdDev1 = nan(nsamples, ncells);
stdDev2 = nan(nsamples, ncells);
stdDev3 = nan(nsamples, ncells);
errorCode1 = nan(nsamples, ncells);
errorCode2 = nan(nsamples, ncells);
errorCode3 = nan(nsamples, ncells);
speed = nan(nsamples, ncells);
direction = nan(nsamples, ncells);
verticalDist = nan(nsamples, ncells);
profileErrorCode = nan(nsamples, ncells);
qcFlag = nan(nsamples, ncells);
end

%
Expand All @@ -124,6 +84,7 @@
freq = head.Frequency; % this is in KHz
blankDist = user.T2; % counts
cellSize = user.BinLength; % counts
ncells = user.NBins;
factor = 0; % used for conversion

switch freq
Expand All @@ -147,45 +108,45 @@
distance = distance + cellSize;

% retrieve sample data
time = structures.(profilerType).Time';
analn1 = structures.(profilerType).Analn1';
battery = structures.(profilerType).Battery';
analn2 = structures.(profilerType).Analn2';
heading = structures.(profilerType).Heading';
pitch = structures.(profilerType).Pitch';
roll = structures.(profilerType).Roll';
status = structures.(profilerType).Status';
pressure = structures.(profilerType).PressureMSB'*65536 + structures.(profilerType).PressureLSW';
temperature = structures.(profilerType).Temperature';
velocity1 = structures.(profilerType).Vel1';
velocity2 = structures.(profilerType).Vel2';
velocity3 = structures.(profilerType).Vel3';
backscatter1 = structures.(profilerType).Amp1';
backscatter2 = structures.(profilerType).Amp2';
backscatter3 = structures.(profilerType).Amp3';
time = [structures.(profilerType)(:).Time]';
analn1 = [structures.(profilerType)(:).Analn1]';
battery = [structures.(profilerType)(:).Battery]';
analn2 = [structures.(profilerType)(:).Analn2]';
heading = [structures.(profilerType)(:).Heading]';
pitch = [structures.(profilerType)(:).Pitch]';
roll = [structures.(profilerType)(:).Roll]';
status = [structures.(profilerType)(:).Status]';
pressure = [structures.(profilerType)(:).PressureMSB]'*65536 + [structures.(profilerType)(:).PressureLSW]';
temperature = [structures.(profilerType)(:).Temperature]';
velocity1 = [structures.(profilerType)(:).Vel1]';
velocity2 = [structures.(profilerType)(:).Vel2]';
velocity3 = [structures.(profilerType)(:).Vel3]';
backscatter1 = [structures.(profilerType)(:).Amp1]';
backscatter2 = [structures.(profilerType)(:).Amp2]';
backscatter3 = [structures.(profilerType)(:).Amp3]';

if velocityProcessed
% velocity has been processed
timeProc = structures.Id106.Time';
timeProc = [structures.Id106(:).Time]';
iCommonTime = ismember(time, timeProc); % timeProc can be shorter than time

velocity1Proc(iCommonTime, :) = structures.Id106.Vel1'; % tilt effect corrected velocity
velocity2Proc(iCommonTime, :) = structures.Id106.Vel2';
velocity3Proc(iCommonTime, :) = structures.Id106.Vel3';
sig2noise1(iCommonTime, :) = structures.Id106.Snr1';
sig2noise2(iCommonTime, :) = structures.Id106.Snr2';
sig2noise3(iCommonTime, :) = structures.Id106.Snr3';
stdDev1(iCommonTime, :) = structures.Id106.Std1'; % currently not used
stdDev2(iCommonTime, :) = structures.Id106.Std2';
stdDev3(iCommonTime, :) = structures.Id106.Std3';
errorCode1(iCommonTime, :) = structures.Id106.Erc1'; % error codes for each cell in one beam, values between 0 and 4.
errorCode2(iCommonTime, :) = structures.Id106.Erc2';
errorCode3(iCommonTime, :) = structures.Id106.Erc3';
speed(iCommonTime, :) = structures.Id106.speed';
direction(iCommonTime, :) = structures.Id106.direction';
verticalDist(iCommonTime, :) = structures.Id106.verticalDistance'; % ? no idea what this is, always same values between 6000 and 65534 for each profile.
profileErrorCode(iCommonTime, :) = structures.Id106.profileErrorCode'; % error codes for each cell of a velocity profile inferred from the 3 beams. 0=good; otherwise error. See http://www.nortek-as.com/en/knowledge-center/forum/waves/20001875?b_start=0#769595815
qcFlag(iCommonTime, :) = structures.Id106.qcFlag'; % QUARTOD QC result. 0=not eval; 1=bad; 2=questionable; 3=good.
velocity1Proc(iCommonTime, :) = [structures.Id106(:).Vel1]'; % tilt effect corrected velocity
velocity2Proc(iCommonTime, :) = [structures.Id106(:).Vel2]';
velocity3Proc(iCommonTime, :) = [structures.Id106(:).Vel3]';
sig2noise1(iCommonTime, :) = [structures.Id106(:).Snr1]';
sig2noise2(iCommonTime, :) = [structures.Id106(:).Snr2]';
sig2noise3(iCommonTime, :) = [structures.Id106(:).Snr3]';
stdDev1(iCommonTime, :) = [structures.Id106(:).Std1]'; % currently not used
stdDev2(iCommonTime, :) = [structures.Id106(:).Std2]';
stdDev3(iCommonTime, :) = [structures.Id106(:).Std3]';
errorCode1(iCommonTime, :) = [structures.Id106(:).Erc1]'; % error codes for each cell in one beam, values between 0 and 4.
errorCode2(iCommonTime, :) = [structures.Id106(:).Erc2]';
errorCode3(iCommonTime, :) = [structures.Id106(:).Erc3]';
speed(iCommonTime, :) = [structures.Id106(:).speed]';
direction(iCommonTime, :) = [structures.Id106(:).direction]';
verticalDist(iCommonTime, :) = [structures.Id106(:).verticalDistance]'; % ? no idea what this is, always same values between 6000 and 65534 for each profile.
profileErrorCode(iCommonTime, :) = [structures.Id106(:).profileErrorCode]'; % error codes for each cell of a velocity profile inferred from the 3 beams. 0=good; otherwise error. See http://www.nortek-as.com/en/knowledge-center/forum/waves/20001875?b_start=0#769595815
qcFlag(iCommonTime, :) = [structures.Id106(:).qcFlag]'; % QUARTOD QC result. 0=not eval; 1=bad; 2=questionable; 3=good.
end
clear structures;

Expand Down
51 changes: 16 additions & 35 deletions Parser/aquadoppVelocityParse.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,6 @@

% the rest of the sections are aquadopp velocity data, diagnostic header
% and diagnostic data. We will only keep the velocity data (Id == 1) .
nsamples = length(structures.Id1);
ncells = user.NBins;

% preallocate memory for all sample data
time = zeros(nsamples, 1);
distance = zeros(ncells, 1);
analn1 = zeros(nsamples, 1);
battery = zeros(nsamples, 1);
analn2 = zeros(nsamples, 1);
heading = zeros(nsamples, 1);
pitch = zeros(nsamples, 1);
roll = zeros(nsamples, 1);
pressure = zeros(nsamples, 1);
temperature = zeros(nsamples, 1);
velocity1 = zeros(nsamples, ncells);
velocity2 = zeros(nsamples, ncells);
velocity3 = zeros(nsamples, ncells);
backscatter1 = zeros(nsamples, ncells);
backscatter2 = zeros(nsamples, ncells);
backscatter3 = zeros(nsamples, ncells);

%
% calculate distance values from metadata. See continentalParse.m
Expand All @@ -90,6 +70,7 @@
freq = head.Frequency; % this is in KHz
cellStart = user.T2; % counts
cellLength = user.BinLength; % counts
ncells = user.NBins;
factor = 0; % used for conversion

switch freq
Expand All @@ -112,21 +93,21 @@
distance = distance + cellLength;

% retrieve sample data
time = structures.Id1.Time';
analn1 = structures.Id1.Analn1';
battery = structures.Id1.Battery';
analn2 = structures.Id1.Analn2';
heading = structures.Id1.Heading';
pitch = structures.Id1.Pitch';
roll = structures.Id1.Roll';
pressure = structures.Id1.PressureMSB'*65536 + structures.Id1.PressureLSW';
temperature = structures.Id1.Temperature';
velocity1 = structures.Id1.Vel1';
velocity2 = structures.Id1.Vel2';
velocity3 = structures.Id1.Vel3';
backscatter1 = structures.Id1.Amp1';
backscatter2 = structures.Id1.Amp2';
backscatter3 = structures.Id1.Amp3';
time = [structures.Id1(:).Time]';
analn1 = [structures.Id1(:).Analn1]';
battery = [structures.Id1(:).Battery]';
analn2 = [structures.Id1(:).Analn2]';
heading = [structures.Id1(:).Heading]';
pitch = [structures.Id1(:).Pitch]';
roll = [structures.Id1(:).Roll]';
pressure = [structures.Id1(:).PressureMSB]'*65536 + [structures.Id1(:).PressureLSW]';
temperature = [structures.Id1(:).Temperature]';
velocity1 = [structures.Id1(:).Vel1]';
velocity2 = [structures.Id1(:).Vel2]';
velocity3 = [structures.Id1(:).Vel3]';
backscatter1 = [structures.Id1(:).Amp1]';
backscatter2 = [structures.Id1(:).Amp2]';
backscatter3 = [structures.Id1(:).Amp3]';
clear structures;

% battery / 10.0 (0.1 V -> V)
Expand Down
109 changes: 35 additions & 74 deletions Parser/awacParse.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,51 +72,11 @@
user = structures.Id0;

% the rest of the sections are awac data
nsamples = length(structures.Id32);
ncells = user.NBins;

% preallocate memory for all sample data
time = nan(nsamples, 1);
distance = nan(ncells, 1);
analn1 = nan(nsamples, 1);
battery = nan(nsamples, 1);
analn2 = nan(nsamples, 1);
heading = nan(nsamples, 1);
pitch = nan(nsamples, 1);
roll = nan(nsamples, 1);
status = zeros(nsamples, 8, 'uint8');
pressure = nan(nsamples, 1);
temperature = nan(nsamples, 1);
velocity1 = nan(nsamples, ncells);
velocity2 = nan(nsamples, ncells);
velocity3 = nan(nsamples, ncells);
backscatter1 = nan(nsamples, ncells);
backscatter2 = nan(nsamples, ncells);
backscatter3 = nan(nsamples, ncells);

velocityProcessed = false;
if isfield(structures, 'Id106')
% velocity has been processed
velocityProcessed = true;
nsamplesProc = length(structures.Id106.Sync);
timeProc = nan(nsamplesProc, 1);
velocity1Proc = nan(nsamples, ncells);
velocity2Proc = nan(nsamples, ncells);
velocity3Proc = nan(nsamples, ncells);
sig2noise1 = nan(nsamples, ncells);
sig2noise2 = nan(nsamples, ncells);
sig2noise3 = nan(nsamples, ncells);
stdDev1 = nan(nsamples, ncells);
stdDev2 = nan(nsamples, ncells);
stdDev3 = nan(nsamples, ncells);
errorCode1 = nan(nsamples, ncells);
errorCode2 = nan(nsamples, ncells);
errorCode3 = nan(nsamples, ncells);
speed = nan(nsamples, ncells);
direction = nan(nsamples, ncells);
verticalDist = nan(nsamples, ncells);
profileErrorCode = nan(nsamples, ncells);
qcFlag = nan(nsamples, ncells);
end

%
Expand All @@ -128,6 +88,7 @@
freq = head.Frequency; % this is in KHz
blankDist = user.T2; % counts
cellSize = user.BinLength; % counts
ncells = user.NBins;
factor = 0; % used in conversion

switch freq
Expand All @@ -148,45 +109,45 @@
distance = distance + cellSize;

% retrieve sample data
time = structures.Id32.Time';
analn1 = structures.Id32.Analn1';
battery = structures.Id32.Battery';
analn2 = structures.Id32.Analn2';
heading = structures.Id32.Heading';
pitch = structures.Id32.Pitch';
roll = structures.Id32.Roll';
status = structures.Id32.Status';
pressure = structures.Id32.PressureMSB'*65536 + structures.Id32.PressureLSW';
temperature = structures.Id32.Temperature';
velocity1 = structures.Id32.Vel1';
velocity2 = structures.Id32.Vel2';
velocity3 = structures.Id32.Vel3';
backscatter1 = structures.Id32.Amp1';
backscatter2 = structures.Id32.Amp2';
backscatter3 = structures.Id32.Amp3';
time = [structures.Id32(:).Time]';
analn1 = [structures.Id32(:).Analn1]';
battery = [structures.Id32(:).Battery]';
analn2 = [structures.Id32(:).Analn2]';
heading = [structures.Id32(:).Heading]';
pitch = [structures.Id32(:).Pitch]';
roll = [structures.Id32(:).Roll]';
status = [structures.Id32(:).Status]';
pressure = [structures.Id32(:).PressureMSB]'*65536 + [structures.Id32(:).PressureLSW]';
temperature = [structures.Id32(:).Temperature]';
velocity1 = [structures.Id32(:).Vel1]';
velocity2 = [structures.Id32(:).Vel2]';
velocity3 = [structures.Id32(:).Vel3]';
backscatter1 = [structures.Id32(:).Amp1]';
backscatter2 = [structures.Id32(:).Amp2]';
backscatter3 = [structures.Id32(:).Amp3]';

if velocityProcessed
% velocity has been processed
timeProc = structures.Id106.Time';
timeProc = [structures.Id106(:).Time]';
iCommonTime = ismember(time, timeProc); % timeProc can be shorter than time

velocity1Proc(iCommonTime, :) = structures.Id106.Vel1'; % tilt effect corrected velocity
velocity2Proc(iCommonTime, :) = structures.Id106.Vel2';
velocity3Proc(iCommonTime, :) = structures.Id106.Vel3';
sig2noise1(iCommonTime, :) = structures.Id106.Snr1';
sig2noise2(iCommonTime, :) = structures.Id106.Snr2';
sig2noise3(iCommonTime, :) = structures.Id106.Snr3';
stdDev1(iCommonTime, :) = structures.Id106.Std1'; % currently not used
stdDev2(iCommonTime, :) = structures.Id106.Std2';
stdDev3(iCommonTime, :) = structures.Id106.Std3';
errorCode1(iCommonTime, :) = structures.Id106.Erc1'; % error codes for each cell in one beam, values between 0 and 4.
errorCode2(iCommonTime, :) = structures.Id106.Erc2';
errorCode3(iCommonTime, :) = structures.Id106.Erc3';
speed(iCommonTime, :) = structures.Id106.speed';
direction(iCommonTime, :) = structures.Id106.direction';
verticalDist(iCommonTime, :) = structures.Id106.verticalDistance'; % ? no idea what this is, always same values between 6000 and 65534 for each profile.
profileErrorCode(iCommonTime, :) = structures.Id106.profileErrorCode'; % error codes for each cell of a velocity profile inferred from the 3 beams. 0=good; otherwise error. See http://www.nortek-as.com/en/knowledge-center/forum/waves/20001875?b_start=0#769595815
qcFlag(iCommonTime, :) = structures.Id106.qcFlag'; % QUARTOD QC result. 0=not eval; 1=bad; 2=questionable; 3=good.
velocity1Proc(iCommonTime, :) = [structures.Id106(:).Vel1]'; % tilt effect corrected velocity
velocity2Proc(iCommonTime, :) = [structures.Id106(:).Vel2]';
velocity3Proc(iCommonTime, :) = [structures.Id106(:).Vel3]';
sig2noise1(iCommonTime, :) = [structures.Id106(:).Snr1]';
sig2noise2(iCommonTime, :) = [structures.Id106(:).Snr2]';
sig2noise3(iCommonTime, :) = [structures.Id106(:).Snr3]';
stdDev1(iCommonTime, :) = [structures.Id106(:).Std1]'; % currently not used
stdDev2(iCommonTime, :) = [structures.Id106(:).Std2]';
stdDev3(iCommonTime, :) = [structures.Id106(:).Std3]';
errorCode1(iCommonTime, :) = [structures.Id106(:).Erc1]'; % error codes for each cell in one beam, values between 0 and 4.
errorCode2(iCommonTime, :) = [structures.Id106(:).Erc2]';
errorCode3(iCommonTime, :) = [structures.Id106(:).Erc3]';
speed(iCommonTime, :) = [structures.Id106(:).speed]';
direction(iCommonTime, :) = [structures.Id106(:).direction]';
verticalDist(iCommonTime, :) = [structures.Id106(:).verticalDistance]'; % ? no idea what this is, always same values between 6000 and 65534 for each profile.
profileErrorCode(iCommonTime, :) = [structures.Id106(:).profileErrorCode]'; % error codes for each cell of a velocity profile inferred from the 3 beams. 0=good; otherwise error. See http://www.nortek-as.com/en/knowledge-center/forum/waves/20001875?b_start=0#769595815
qcFlag(iCommonTime, :) = [structures.Id106(:).qcFlag]'; % QUARTOD QC result. 0=not eval; 1=bad; 2=questionable; 3=good.
end
clear structures;

Expand Down
Loading

0 comments on commit f79a111

Please sign in to comment.