Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nortek adcp4beams mark #784

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Parser/+Nortek/read_nortek_header_key.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
function [value] = read_nortek_header_key(hstr,mode,key,vtype)
% function value = read_nortek_header_key(hstr,mode,key,vtype)
%
% Read a nortek value from a `key` name
% within a `mode` line from the header string `hstr`.
% The type of the variable is defined by `vtype`.
% See example.
%
% Inputs:
%
% hstr - the header string
% mode- the name of the mode or the first string in the line
% key - the name of the key
% vtype - the textscan type of the value [Optional]
% - default: 'float'
%
%
% Outputs:
%
% value - a single value
%
% Example:
%
% hstr = 'GETAVG1,ABC="CBA",MIAVG=600,ERR=0.00e-10';
% [value] = read_nortek_header_key(hstr,'GETAVG1','MIAVG','int');
% assert(value==600)
% [value] = read_nortek_header_key(hstr,'GETAVG1','ABC','str');
% assert(value=='CBA')
% [value] = read_nortek_header_key(hstr,'GETAVG1','ERR','float');
% assert(value==0.00e-10)
%
% author: hugo.oliveira@utas.edu.au
%
narginchk(4,4)

if strcmpi(vtype,'float')
mtype = '-?[\d.]+(?:[eE][-?+?\d+]\d+)?';
mfun = @str2double;
elseif strcmpi(vtype,'integer') || strcmpi(vtype,'int')
mtype = '\d+';
mfun = @str2double;
else
mtype = '".*?"';
mfun = @(x) strrep(x,'"','');
end

%header lines always start with command,key0=value0,key1=value1,...
re_match = ['(?<mode>(' mode '))' '(.*?)' key '={1}' '(?<value>(' mtype '))'];
data = regexpi(hstr,re_match,'names');

if ~isempty(data)
value = mfun(data.value);
else
error('Could not find key %s with type %s',key,vtype);
end

end

43 changes: 43 additions & 0 deletions Parser/+Nortek/transfer_matrix.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function [Beam2xyz] = transfer_matrix(iA0_Header)
% function [Beam2xyz] = transfer_matrix(iA0_Header)
%
% get transfer function from adcp config command GETXFAVG
%
% Input:
% iA0_Header - the header string
%
% Output:
% Beam2xyz - transfer matrix to use to convert between ENU and beam
%
% Example
%
%
%

narginchk(1,1)

r = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','ROWS','int');
Beam2xyz = zeros(r,r);

Beam2xyz(1,1) = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','M11','float');
Beam2xyz(1,2) = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','M12','float');
Beam2xyz(1,3) = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','M13','float');
Beam2xyz(2,1) = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','M21','float');
Beam2xyz(2,2) = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','M22','float');
Beam2xyz(2,3) = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','M23','float');
Beam2xyz(3,1) = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','M31','float');
Beam2xyz(3,2) = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','M32','float');
Beam2xyz(3,3) = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','M33','float');

if r==4
Beam2xyz(1,4) = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','M14','float');
Beam2xyz(2,4) = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','M24','float');
Beam2xyz(3,4) = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','M34','float');
Beam2xyz(4,1) = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','M41','float');
Beam2xyz(4,2) = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','M42','float');
Beam2xyz(4,3) = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','M43','float');
Beam2xyz(4,4) = Nortek.read_nortek_header_key(iA0_Header,'GETXFAVG','M44','float');
end

end

Loading