Skip to content
Merged
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
5 changes: 5 additions & 0 deletions matlab/+sonpipe/channelinfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
%
% See also sonpipe.read_SOMSMR_header

arguments
header
channel_number {mustBeNumeric}
end

if isempty(header) || ~isfield(header, 'channelinfo') || isempty(header.channelinfo)
error('sonpipe:noChannels', 'The header contains no channels.');
end
Expand Down
7 changes: 6 additions & 1 deletion matlab/+sonpipe/channels.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
%
% See also sonpipe.read_SOMSMR_header

if nargin < 2 || isempty(header)
arguments
filename {mustBeTextScalar}
header = [] % [] or a header struct; read from FILENAME if omitted
end

if isempty(header)
header = sonpipe.read_SOMSMR_header(filename);
end

Expand Down
36 changes: 34 additions & 2 deletions matlab/+sonpipe/executable.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@
% Lookup order when no value is cached:
% 1. the SONPIPE environment variable, if set
% 2. 'sonpipe' on the system PATH
% 3. 'python3 -m sonpipe'
% 4. 'python -m sonpipe'
% 3. sonpipe at the default install locations (~/.local/bin/sonpipe, the
% install.sh venv, and the Windows %LOCALAPPDATA% venv). These are
% probed by absolute path because a MATLAB GUI on macOS/Windows does not
% inherit the interactive shell PATH, so a working ~/.local/bin install
% is otherwise invisible to step 2.
% 4. 'python3 -m sonpipe'
% 5. 'python -m sonpipe'
%
% Each candidate is verified by running "<candidate> --version".
%
% See also sonpipe.read_SOMSMR_header

arguments
newvalue = '' % command string; nargin distinguishes query() from set('')
end

persistent CACHED

if nargin >= 1
Expand All @@ -43,6 +52,7 @@
candidates{end+1} = envval;
end
candidates{end+1} = 'sonpipe';
candidates = [candidates, defaultInstallCandidates()];
candidates{end+1} = 'python3 -m sonpipe';
candidates{end+1} = 'python -m sonpipe';

Expand All @@ -60,3 +70,25 @@
'''pip install sonpipe'', or point MATLAB at it with ' ...
'sonpipe.executable(PATH) or the SONPIPE environment variable.']);
end

function c = defaultInstallCandidates()
% Absolute paths where install.sh / install.ps1 place sonpipe. Only paths that
% exist on disk are returned (each is quoted so spaces in the path are safe).
c = {};
paths = {};
home = getenv('HOME');
if isempty(home), home = getenv('USERPROFILE'); end
if ~isempty(home)
paths{end+1} = fullfile(home, '.local', 'bin', 'sonpipe');
paths{end+1} = fullfile(home, '.local', 'share', 'sonpipe', 'venv', 'bin', 'sonpipe');
end
lad = getenv('LOCALAPPDATA');
if ~isempty(lad)
paths{end+1} = fullfile(lad, 'sonpipe', 'venv', 'Scripts', 'sonpipe.exe');
end
for i = 1:numel(paths)
if isfile(paths{i})
c{end+1} = ['"' paths{i} '"']; %#ok<AGROW>
end
end
end
5 changes: 5 additions & 0 deletions matlab/+sonpipe/private/invoke_binary.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
%
% This is a private helper for the +sonpipe package.

arguments
args {mustBeTextScalar}
precision {mustBeTextScalar}
end

exe = sonpipe.executable();
tmp = [tempname() '.bin'];
cleaner = onCleanup(@() deletefile(tmp));
Expand Down
4 changes: 4 additions & 0 deletions matlab/+sonpipe/private/invoke_text.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
%
% This is a private helper for the +sonpipe package.

arguments
args {mustBeTextScalar}
end

exe = sonpipe.executable();
cmd = [exe ' ' args];
[status, txt] = sonpipe.runcmd(cmd);
Expand Down
8 changes: 8 additions & 0 deletions matlab/+sonpipe/read_SOMSMR_datafile.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
%
% See also sonpipe.read_SOMSMR_header, sonpipe.read_SOMSMR_sampleinterval

arguments
filename {mustBeTextScalar}
header % [] or a header struct
channel_number {mustBeNumeric}
t0 (1,1) {mustBeNumeric}
t1 (1,1) {mustBeNumeric}
end

data = [];
total_samples = [];
total_time = [];
Expand Down
4 changes: 4 additions & 0 deletions matlab/+sonpipe/read_SOMSMR_header.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
%
% See also sonpipe.read_SOMSMR_datafile, sonpipe.read_SOMSMR_sampleinterval

arguments
filename {mustBeTextScalar}
end

txt = invoke_text(sprintf('header "%s"', filename));
raw = jsondecode(txt);

Expand Down
6 changes: 6 additions & 0 deletions matlab/+sonpipe/read_SOMSMR_sampleinterval.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
%
% See also sonpipe.read_SOMSMR_header, sonpipe.read_SOMSMR_datafile

arguments
filename {mustBeTextScalar}
header % [] or a header struct (unused)
channel_number {mustBeNumeric}
end

txt = invoke_text(sprintf('sampleinterval "%s" -c %d', filename, channel_number));
r = jsondecode(txt);

Expand Down
4 changes: 4 additions & 0 deletions matlab/+sonpipe/runcmd.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
%
% See also sonpipe.executable

arguments
cmd {mustBeTextScalar}
end

if ispc
[status, out] = system(cmd);
return;
Expand Down
Loading