Commit Friday evening.

PDFA and EXFO Laser are now part of the family
This commit is contained in:
Silas Labor Zizou
2024-10-25 20:31:50 +02:00
parent bafc7f12b7
commit 99fe2ca106
208 changed files with 28244 additions and 460 deletions

View File

@@ -0,0 +1,25 @@
function [env, versionString] = getEnvironment()
% Determine environment (Octave, MATLAB) and version string
% TODO: Unify private `getEnvironment` functions
persistent cache
if isempty(cache)
isOctave = exist('OCTAVE_VERSION', 'builtin') ~= 0;
if isOctave
env = 'Octave';
versionString = OCTAVE_VERSION;
else
env = 'MATLAB';
vData = ver(env);
versionString = vData.Version;
end
% store in cache
cache.env = env;
cache.versionString = versionString;
else
env = cache.env;
versionString = cache.versionString;
end
end

View File

@@ -0,0 +1,167 @@
function hh = herrorbar(x, y, l, u, symbol)
%HERRORBAR Horizontal Error bar plot.
% HERRORBAR(X,Y,L,R) plots the graph of vector X vs. vector Y with
% horizontal error bars specified by the vectors L and R. L and R contain the
% left and right error ranges for each point in X. Each error bar
% is L(i) + R(i) long and is drawn a distance of L(i) to the right and R(i)
% to the right the points in (X,Y). The vectors X,Y,L and R must all be
% the same length. If X,Y,L and R are matrices then each column
% produces a separate line.
%
% HERRORBAR(X,Y,E) or HERRORBAR(Y,E) plots X with error bars [X-E X+E].
% HERRORBAR(...,'LineSpec') uses the color and linestyle specified by
% the string 'LineSpec'. See PLOT for possibilities.
%
% H = HERRORBAR(...) returns a vector of line handles.
%
% Example:
% x = 1:10;
% y = sin(x);
% e = std(y)*ones(size(x));
% herrorbar(x,y,e)
% draws symmetric horizontal error bars of unit standard deviation.
%
% This code is based on ERRORBAR provided in MATLAB.
%
% See also ERRORBAR
% Jos van der Geest
% email: jos@jasen.nl
%
% File history:
% August 2006 (Jos): I have taken back ownership. I like to thank Greg Aloe from
% The MathWorks who originally introduced this piece of code to the
% Matlab File Exchange.
% September 2003 (Greg Aloe): This code was originally provided by Jos
% from the newsgroup comp.soft-sys.matlab:
% http://newsreader.mathworks.com/WebX?50@118.fdnxaJz9btF^1@.eea3ff9
% After unsuccessfully attempting to contact the orignal author, I
% decided to take ownership so that others could benefit from finding it
% on the MATLAB Central File Exchange.
if min(size(x))==1,
npt = length(x);
x = x(:);
y = y(:);
if nargin > 2,
if ~ischar(l),
l = l(:);
end
if nargin > 3
if ~ischar(u)
u = u(:);
end
end
end
else
[npt,n] = size(x);
end
if nargin == 3
if ~ischar(l)
u = l;
symbol = '-';
else
symbol = l;
l = y;
u = y;
y = x;
[m,n] = size(y);
x(:) = (1:npt)'*ones(1,n);;
end
end
if nargin == 4
if ischar(u),
symbol = u;
u = l;
else
symbol = '-';
end
end
if nargin == 2
l = y;
u = y;
y = x;
[m,n] = size(y);
x(:) = (1:npt)'*ones(1,n);;
symbol = '-';
end
u = abs(u);
l = abs(l);
if ischar(x) || ischar(y) || ischar(u) || ischar(l)
error('Arguments must be numeric.')
end
if ~isequal(size(x),size(y)) || ~isequal(size(x),size(l)) || ~isequal(size(x),size(u)),
error('The sizes of X, Y, L and U must be the same.');
end
tee = (max(y(:))-min(y(:)))/100; % make tee .02 x-distance for error bars
% changed from errorbar.m
xl = x - l;
xr = x + u;
ytop = y + tee;
ybot = y - tee;
n = size(y,2);
% end change
% Plot graph and bars
hold_state = ishold;
cax = newplot;
next = lower(get(cax,'NextPlot'));
% build up nan-separated vector for bars
% changed from errorbar.m
xb = zeros(npt*9,n);
xb(1:9:end,:) = xl;
xb(2:9:end,:) = xl;
xb(3:9:end,:) = NaN;
xb(4:9:end,:) = xl;
xb(5:9:end,:) = xr;
xb(6:9:end,:) = NaN;
xb(7:9:end,:) = xr;
xb(8:9:end,:) = xr;
xb(9:9:end,:) = NaN;
yb = zeros(npt*9,n);
yb(1:9:end,:) = ytop;
yb(2:9:end,:) = ybot;
yb(3:9:end,:) = NaN;
yb(4:9:end,:) = y;
yb(5:9:end,:) = y;
yb(6:9:end,:) = NaN;
yb(7:9:end,:) = ytop;
yb(8:9:end,:) = ybot;
yb(9:9:end,:) = NaN;
% end change
[ls,col,mark,msg] = colstyle(symbol);
if ~isempty(msg)
error(msg);
end
if isempty(col)
col = '';
end
symbol = [ls mark col]; % Use marker only on data part
esymbol = ['-' col]; % Make sure bars are solid
if ~isempty(strfind(symbol,'none'))
symbol = 'none';
end
if ~isempty(strfind(esymbol,'none'))
esymbol = 'none';
end
h = plot(xb,yb,'LineStyle',esymbol); hold on
h = [h;plot(x,y,'LineStyle',symbol)];
if ~hold_state
hold off;
end
if nargout>0
hh = h;
end

View File

@@ -0,0 +1,46 @@
function bool = isEnvironment(wantedEnvironment, varargin)
% ISENVIRONMENT check for a particular environment (MATLAB/Octave)
%
% This function returns TRUE when it is run within the "wantedEnvironment"
% (e.g. MATLAB or Octave). This environment can be tested to be a particular
% version or be older/newer than a specified version.
%
% Usage:
%
% ISENVIRONMENT(ENV)
% ISENVIRONMENT(ENV, VERSION)
% ISENVIRONMENT(ENV, OP, VERSION)
%
% Parameters:
% - `ENV`: the expected environment (e.g. 'MATLAB' or 'Octave')
% - `VERSION`: a version number or string to compare against
% e.g. "3.4" or equivalently [3,4]
% - `OP`: comparison operator (e.g. '==', '<=', '<', ...) to define a range
% of version numbers that return a TRUE value
%
% When `OP` is not specified, "==" is used.
% When no `VERSION` is specified, all versions pass the check.
%
% See also: isMATLAB, isOctave, versionCompare
[env, thisVersion] = getEnvironment();
bool = strcmpi(env, wantedEnvironment);
switch numel(varargin)
case 0 % nothing to be done
return
case 1 % check equality
version = varargin{1};
operator = '==';
bool = bool && versionCompare(thisVersion, operator, version);
case 2
operator = varargin{1};
version = varargin{2};
bool = bool && versionCompare(thisVersion, operator, version);
otherwise
error('isEnvironment:BadNumberOfArguments', ...
'"isEnvironment" was called with an incorrect number of arguments.');
end
end

View File

@@ -0,0 +1,4 @@
function bool = isMATLAB(varargin)
%ISMATLAB Determines whether (a certain) version of MATLAB is being used
% See also: isEnvironment, isOctave
bool = isEnvironment('MATLAB', varargin{:});

View File

@@ -0,0 +1,5 @@
function bool = isOctave(varargin)
%ISOCTAVE Determines whether (a certain) version of Octave is being used
%
% See also: isEnvironment, isMATLAB
bool = isEnvironment('Octave', varargin{:});

View File

@@ -0,0 +1,38 @@
function isBelow = isVersionBelow(versionA, versionB)
% Checks if versionA is smaller than versionB
vA = versionArray(versionA);
vB = versionArray(versionB);
n = min(length(vA), length(vB));
deltaAB = vA(1:n) - vB(1:n);
difference = find(deltaAB, 1, 'first');
if isempty(difference)
isBelow = false; % equal versions
else
isBelow = (deltaAB(difference) < 0);
end
end
% ==============================================================================
function arr = versionArray(str)
% Converts a version string to an array.
if ischar(str)
% Translate version string from '2.62.8.1' to [2; 62; 8; 1].
switch getEnvironment
case 'MATLAB'
split = regexp(str, '\.', 'split'); % compatibility MATLAB < R2013a
case 'Octave'
split = strsplit(str, '.');
otherwise
errorUnknownEnvironment();
end
arr = str2num(char(split)); %#ok
else
arr = str;
end
arr = arr(:)';
end
% ==============================================================================
function errorUnknownEnvironment()
error('matlab2tikz:unknownEnvironment',...
'Unknown environment "%s". Need MATLAB(R) or Octave.', getEnvironment);
end
% ==============================================================================

View File

@@ -0,0 +1,20 @@
function bool = versionCompare( vA, operator, vB )
%VERSIONCOMPARE Performs a version comparison operation
switch operator
case '<'
bool = isVersionBelow(vA, vB);
case '>'
bool = isVersionBelow(vB, vA);
case {'<=', '=<'}
bool = ~isVersionBelow(vB, vA);
case {'>=', '=>'}
bool = ~isVersionBelow(vA, vB);
case {'=', '=='}
bool = ~isVersionBelow(vA, vB) && ~isVersionBelow(vB, vA);
case {'~=', '!='}
bool = isVersionBelow(vA, vB) || isVersionBelow(vB, vA);
otherwise
error('versionCompare:UnknownOperator',...
'"%s" is not a known comparison operator', operator);
end
end