text:
function [C,t,err] = cubic_vertex_removal(C1,C2,varargin)
  % CUBIC_VERTEX_REMOVAL Given a G¹ continuous sequence of cubic Bézier curves,
  % optimize the positions of a new single curve to minimize its integrated
  % squared distance to those curves. This requires both estimating the
  % parameterization mapping between the inputs and output (non-linear problem)
  % and then computing the optimal positions as a linear least squares problem.
  %
  % C = cubic_vertex_removal(C1,C2)
  % [C,t,err] = cubic_vertex_removal(C1,C2,'ParameterName',ParameterValue,…)
  %
  % Inputs:
  %   C1  4 by dim list of first curves control point positions
  %   C2  4 by dim list of second curves control point positions, it's assumed
  %     that C1(4,:) == C2(1,:) and C1(4,:) - C1(3,:) = s * (C2(2,:) - C2(1,:))
  %     for some s>= 0.
  %     Optional:
  %       'Method' followed by one of the following:
  %         {'perfect'}  use root finding. This is fastest when you only care about
  %           finding a perfect fit. It may lead to a very poor approximate when
  %           a perfect fit is not possible. A perfect fit is when
  %           `[C1,C2] = cubic_split(C,t)`. If this is the case, then the
  %           returned `err` for this method should be very close to zero. (Note
  %           that "perfect fit" → err=0 but err=0 does not necessarily imply
  %           "perfect fit".
  %         'iterative'  use iterative method. This is slower but more accurate
  %           when a perfect fit is not possible.
  %       'MaxIter'  followed by maximum number of iterations for iterative
  %         method {100}
  %       't0'  followed by initial guess of t for iterative method {relative
  %         approximate arc lengths}
  %       'AlreadyGenerated'  followed by whether the automatically generated helper
  %         functions cubic_vertex_removal_polyfun and cubic_vertex_removal_g
  %         have already been generated. On some machines checking `exist()` can
  %         be really slow. So, you could call
  %         `cubic_vertex_removal(…,'AlreadyGenerated',false)` onces to
  %         generate the files and the call
  %         `cubic_vertex_removal(…,'AlreadyGenerated',true) for subsequent
  %         calls {false}.
  % Outputs:
  %   C  4 by dim list of output coordinates. By default:
  %     C(1,:) = C1(1,:),
  %     C(4,:) = C2(4,:), (C₀ continuity)
  %       and
  %     C(2,:) - C(1,:) = s1*(C1(2,:) - C1(1,:)) with s1>=0
  %     C(4,:) - C(3,:) = s2*(C2(4,:) - C2(3,:)) with s2>=0 (G₁ continutity)
  %   t scalar value between [0,1] defining the piecewise-linear
  %     parameterization mapping between the inputs and output.  C1 is mapped to
  %     [0,t] and C2 is mapped to [t1,1].
  %   err  Integrated squared distance between the output and input curves (see
  %   cubic_cubic_integrated_distance).
  %
  % Example:
  %   C = [0 0;1 1;2 -1;3 0];
  %   tgt = 0.1;
  %   [C1,C2] = cubic_split(C,tgt);
  %   [C,t,err] = cubic_vertex_removal(C1,C2,'Method','perfect');
  %   clf;
  %   hold on;
  %   plot_cubic(C1,[],[],'Color',orange);
  %   plot_cubic(C2,[],[],'Color',orange);
  %   plot_cubic(C,[],[],'Color',blue);
  %   hold off;
  %   axis equal;
  %   set(gca,'YDir','reverse')
  %   title(sprintf('err: %g',err),'FontSize',30);
  %

  method = 'perfect';
  max_iter = 100;
  t0 = [];
  promise_already_built = false;
  E_tol = 1e-15;
  grad_tol = 1e-8;

  % Map of parameter names to variable names
  params_to_variables = containers.Map( ...
    {'Method','MaxIter','t0','AlreadyGenerated','Tol','GradientTol',}, ...
    {'method','max_iter','t0','promise_already_built','E_tol','grad_tol'});
  v = 1;
  while v <= numel(varargin)
    param_name = varargin{v};
    if isKey(params_to_variables,param_name)
      assert(v+1<=numel(varargin));
      v = v+1;
      % Trick: use feval on anonymous function to use assignin to this workspace
      feval(@()assignin('caller',params_to_variables(param_name),varargin{v}));
    else
      error('Unsupported parameter: %s',varargin{v});
    end
    v=v+1;
  end

  if strcmp(method,'cubic-polish')
    [C,t,err] = cubic_vertex_removal(C1,C2,varargin{:},'Method','cubic');
    % Slip in 'MaxIter',1 before user parameters so it gets over-written if
    % provided.
    [C,t,err] = cubic_vertex_removal(C1,C2,'MaxIter',1,varargin{:},'t0',t,'Method','iterative');
    return;
  end

  switch method
  case {'perfect','cubic'}
    % _If_ t is perfect, then C is a simple function of t.
    C_from_t = @(C1,C2,t) ...
      [C1(1,:); ...
          (1./t)*(C1(2,:)-C1(1,:)) + C1(1,:); ...
      (1./(1-t))*(C2(end-1,:)-C2(end,:)) + C2(end,:); ...
      C2(end,:)];
    switch method
    case 'perfect'
      % Build a root finder for the 1D problem
      if ~promise_already_built && ~exist('cubic_vertex_removal_polyfun','file');
        warning('assuming L2 not l2 error');
        dim = 1;
        % Matlab is (sometimes?) confused that this is a static workspace and
        % refuses to let syms create variables.
        %syms('iC1',[4 dim],'real');
        %syms('iC2',[4 dim],'real');
        %% complains if I mark st as 'real'
        %syms('st',[1 1]);
        iC1 = [
          sym('iC11','real')
          sym('iC12','real')
          sym('iC13','real')
          sym('iC14','real')];
        iC2 = [
          sym('iC21','real')
          sym('iC22','real')
          sym('iC23','real')
          sym('iC24','real')];
        st = sym('st');

        sC = C_from_t(iC1,iC2,st);
        [oC1,oC2] = cubic_split(sC,st);
        % L2 style.
        sg = sum( [oC1-iC1;oC2-iC2].^2, 'all');
        sres = solve(diff(sg,st) == 0,st);
        %sdgdt = simplify(diff(sg,st));
        %vroots = @(C1,C2) double(vpasolve(subs(subs(sdgdt,iC1,C1),iC2,C2)==0,st,[0 1]));
        sres_children = children(sres(1));
        % Should cache these two:
        %polyfun = matlabFunction(flip(coeffs(sres_children(1),sres_children(2))),'Vars',{iC1,iC2});
        % Matlab2023a seems to use slightly different cell arrays for sres_children.
        polyfun = matlabFunction( ...
          flip(coeffs(sres_children{1},sres_children{2})), ...
          'Vars',{iC1,iC2}, ...
          'File','cubic_vertex_removal_polyfun');
        g = matlabFunction(sg,'Vars',{iC1,iC2,st},'File','cubic_vertex_removal_g');
      else
        polyfun = @cubic_vertex_removal_polyfun;
        g = @cubic_vertex_removal_g;
      end
      keepreal = @(C) C(imag(C)==0 & real(C)>=0 & real(C)<=1);
      % Using numerical roots is faster than vroots
      nroots = @(K1,K2) keepreal(roots(polyfun(K1,K2)));
      keepmin = @(ts,Es) ts(find(Es==min(Es),1));
      % We'll determine t based on the 1D g function. But we'll compute the
      % returned energy below using the full dim-D problem.
      keepmin = @(K1,K2,ts) keepmin(ts,arrayfun(@(t) g(K1,K2,t),ts));
      find_t = @(K1,K2) keepmin(K1,K2,nroots(K1,K2));
      % Decide which coordinate to use (pick a non-degenerate one).
      % Based on max-extent.
      [~,i] = max(max([C1(1,:);C2(end,:)])-min([C1(1,:);C2(end,:)]));
      t = find_t(C1(:,i),C2(:,i));
      assert(~isempty(t));
    case 'cubic'
      D1 = -6.*C1(1,:) + 18.*C1(2,:) - 18.*C1(3,:) + 6.*C1(4,:);
      D2 = -6.*C2(1,:) + 18.*C2(2,:) - 18.*C2(3,:) + 6.*C2(4,:);
      D2_sqr_len = sum(D2.*D2,2);
      D1_sqr_len = sum(D1.*D1,2);
      D2_D1 = sum(D2.*D1,2);
      r = D2_D1/D1_sqr_len;
      t = (1 + (r.^(1/3))).^-1;
    end
    C = C_from_t(C1,C2,t);
  case 'iterative'
    % use arc-length to guess t₁
    if isempty(t0)
      tol = 1e-5;
      ts = matrixnormalize(cumsum([0;spline_arc_lengths([C1;C2],[1 2 3 4;5 6 7 8],tol)]));
      t0 = ts(2);
    end
    t1 = t0;
    % Build null space matrices. so that C(:) = S*V + B(:) satisfies C₀ and G₁
    % constraints for any V
    B = [C1(1,:);C1(1,:);C2(4,:);C2(4,:)];
    B1 = [0 0;(C1(2,:) - C1(1,:));0 0;0 0];
    B2 = [0 0;0 0;(C2(3,:) - C2(4,:));0 0];
    S = [B1(:) B2(:)];

    f = @(t1) objective_t1(C1,C2,t1,B,S);
    [E,C] = f(t1);
    for iter = 1:max_iter
      %dfdt1 = (f(t1+1e-5)-f(t1-1e-5))/(2*1e-5);
      % Complex step is bit faster and more accurate/stable. For 1D input, I
      % believe this should be as good as autodiff and probably as good as we
      % can get without a lot of hand derivativation/compiling code.
      dfdt1 = imag(f(complex(t1,1e-100)))/1e-100;

      if norm(dfdt1,inf) < grad_tol
        break;
      end
      dt1 = 0.5*sign(-dfdt1);
      [alpha,t1] = backtracking_line_search(f,t1,dfdt1,dt1,0.3,0.5);
      if alpha == 0
        %warning('line search failed');
        break;
      end
      [E,C] = f(t1);
      if E < E_tol
        break;
      end
    end

    t = t1;
  otherwise
    error(['unknown method :' method]);
  end

  if nargout>2
    % L2 not l2
    [E1] = cubic_cubic_integrated_distance( ...
      0,t, ...
      1/t,0, ...
      C1, ...
      1,0, ...
      C);
    [E2] = cubic_cubic_integrated_distance( ...
      t,1, ...
      1/(1-t),-t/(1-t), ...
      C2, ...
      1,0, ...
      C);
    err = E1+E2;
  end

  % Helper functions for iterative method
  function [E,C] = objective_t1(C1,C2,t1,B,S)
    if isfloat(t1) && (t1>1 || t1<0)
      E = inf;
      return;
    end
    C = nan(4,2);
    [~,H,F,c] = objective(C1,C2,C,t1);
    % Enforce constraints via subspace
    % C = [
    %   C1(1,:)
    %   C1(1,:) + v1 * (C1(2,:) - C1(1,:))
    %   C2(4,:) + v2 * (C2(3,:) - C2(4,:))
    %   C2(4,:)
    %   ];
    HH = repdiag(H,2);
    V = ((S.'*HH*S)\(-S.'*F(:)-S.'*HH*B(:)));
    V = max(V,0);
    C = reshape( B(:) + S*V , size(C));
    [E] = objective(C1,C2,C,t1);
  end
  function [E,H,F,c] = objective(C1,C2,C,t1)
    if isfloat(t1) && (t1>1 || t1<0)
      E = inf;
      return;
    end
    % WARNING
    w1 = 1;
    w2 = 1;
    %w1 = t1;
    %w2 = 1-t1;
    if nargout == 4
      % Given t1 update C
      [H1,F1,c1,E1] = cubic_cubic_integrated_distance( ...
        0,t1, ...
        1/t1,0, ...
        C1, ...
        1,0, ...
        C);
      [H2,F2,c2,E2] = cubic_cubic_integrated_distance( ...
        t1,1, ...
        1/(1-t1),-t1/(1-t1), ...
        C2, ...
        1,0, ...
        C);
      % Equal weighting ("L2")
      H = w1*H1 + w2*H2;
      F = w1*F1 + w2*F2;
      c = w1*c1 + w2*c2;
    else
      % Given t1 update C
      [E1] = cubic_cubic_integrated_distance( ...
        0,t1, ...
        1/t1,0, ...
        C1, ...
        1,0, ...
        C);
      [E2] = cubic_cubic_integrated_distance( ...
        t1,1, ...
        1/(1-t1),-t1/(1-t1), ...
        C2, ...
        1,0, ...
        C);
    end
    E = w1*E1 + w2*E2;
  end
end

author: alecjacobson

repo: gptoolbox


text:
function mfunc = minmod(v)

% function mfunc = minmod(v)
% Purpose: Implement the midmod function v is a vector

m = size(v,1); mfunc = zeros(1,size(v,2));
s = sum(sign(v),1)/m;

ids = find(abs(s)==1);
if(~isempty(ids))
  mfunc(ids) = s(ids).*min(abs(v(:,ids)),[],1);
end
return;

repo: Aero-matlab


text:
function order = order_code ( code )

%*****************************************************************************80
%
%% ORDER_CODE returns the order for each element.
%
%  List:
%
%    CODE  Order  Definition
%    ----  -----  ----------
%    Q4     4     4 node linear Lagrange/serendipity quadrilateral;
%    Q8     8     8 node quadratic serendipity quadrilateral;
%    Q9     9     9 node quadratic Lagrange quadrilateral;
%    Q12   12     12 node cubic serendipity quadrilateral;
%    Q16   16     16 node cubic Lagrange quadrilateral;
%    QL     6     6 node linear/quadratic quadrilateral;
%    T3     3     3 node linear triangle;
%    T6     6     6 node quadratic triangle;
%    T10   10     10 node cubic triangle.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, string CODE, the code for the element.
%
%    Output, integer ORDER, the order of the element.
%
  if ( s_eqi ( code, 'Q4' ) )
    order = 4;
  elseif ( s_eqi ( code, 'Q8' ) )
    order = 8;
  elseif ( s_eqi ( code, 'Q9' ) )
    order = 9;
  elseif ( s_eqi ( code, 'Q12' ) )
    order = 12;
  elseif ( s_eqi ( code, 'Q16' ) )
    order = 16;
  elseif ( s_eqi ( code, 'QL' ) )
    order = 6;
  elseif ( s_eqi ( code, 'T3' ) )
    order = 3;
  elseif ( s_eqi ( code, 'T6' ) )
    order = 6;
  elseif ( s_eqi ( code, 'T10' ) )
    order = 10;
  else
    order = -1;
  end

  return
end

author: johannesgerer

repo: jburkardt-m


text:
 function tf = streq(a,b,n)
%function tf = streq(a, b [,n])
%	return 1 if two strings are equal (optionally only up to 1st n chars)
if nargin == 2
	tf = strcmp(a,b);
elseif nargin == 3
	tf = strncmp(a,b,n);
else
	help(mfilename), error(mfilename)
end

author: thomaskuestner


text:
function cond = condition_linpack ( n, a )

%*****************************************************************************80
%
%% CONDITION_LINPACK estimates the L1 condition number of a matrix.
%
%  Discussion:
%
%    The R8GE storage format is used for a general M by N matrix.  A storage
%    space is made for each logical entry.  The two dimensional logical
%    array is mapped to a vector, in which storage is by columns.
%
%    For the system A * X = B, relative perturbations in A and B
%    of size EPSILON may cause relative perturbations in X of size
%    EPSILON*RCOND.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    21 March 2004
%
%  Author:
%
%    Original FORTRAN77 version by Dongarra, Bunch, Moler, Stewart.
%    MATLAB version by John Burkardt.
%
%  Reference:
%
%    Dongarra, Bunch, Moler, Stewart,
%    LINPACK User's Guide,
%    SIAM, 1979
%
%  Parameters:
%
%    Input, integer N, the order of the matrix A.
%
%    Input, real A(N,N), a matrix to be factored.
%
%    Output, real COND, an estimate of the condition number of A.
%

%
%  Compute the L1 norm of A.
%
  anorm = norm ( a, 1 );
%
%  Compute the LU factorization.
%
  [ a_lu, pivot, info ] = r8ge_fa ( n, a );
%
%  COND = norm(A) * (estimate of norm(inverse(A)))
%
%  estimate of norm(inverse(A)) = norm(Z) / norm(Y)
%
%  where
%    A * Z = Y
%  and
%    A' * Y = E
%
%  The components of E are chosen to cause maximum local growth in the
%  elements of W, where U'*W = E.  The vectors are frequently rescaled
%  to avoid overflow.
%
%  Solve U' * W = E.
%
  ek = 1.0;
  z(1:n,1) = 0.0;

  for k = 1 : n

    if ( z(k,1) ~= 0.0 )
      ek = - r8_sign ( z(k,1) ) * abs ( ek );
    end

    if ( abs ( a_lu(k,k) ) < abs ( ek - z(k,1) ) )
      s = abs ( a_lu(k,k) ) / abs ( ek - z(k,1) );
      z(1:n,1) = s * z(1:n,1);
      ek = s * ek;
    end

    wk = ek - z(k,1);
    wkm = -ek - z(k,1);
    s = abs ( wk );
    sm = abs ( wkm );

    if ( a_lu(k,k) ~= 0.0 )
      wk = wk / a_lu(k,k);
      wkm = wkm / a_lu(k,k);
    else
      wk = 1.0;
      wkm = 1.0;
    end

    if ( k + 1 <= n )

      for j = k + 1 : n
        sm = sm + abs ( z(j,1) + wkm * a_lu(k,j) );
        z(j,1) = z(j,1) + wk * a_lu(k,j);
        s = s + abs ( z(j,1) );
      end

      if ( s < sm )
        t = wkm - wk;
        wk = wkm;
        z(k+1:n,1) = z(k+1:n,1) + t * a_lu(k,k+1:n)';
      end

    end

    z(k,1) = wk;

  end

  t = sum ( abs ( z(1:n,1) ) );
  z(1:n,1) = z(1:n,1) / t;
%
%  Solve L' * Y = W
%
  for k = n : -1 : 1

    z(k,1) = z(k,1) + a_lu(k+1:n,k)' * z(k+1:n,1);

    t = abs ( z(k,1) );

    if ( 1.0 < t )
      z(1:n,1) = z(1:n,1) / t;
    end

    l = pivot(k);

    t = z(l,1);
    z(l,1) = z(k,1);
    z(k,1) = t;

  end

  z(1:n,1) = z(1:n,1) / sum ( abs ( z(1:n,1) ) );

  ynorm = 1.0;
%
%  Solve L * V = Y.
%
  for k = 1 : n

    l = pivot(k);

    t = z(l,1);
    z(l,1) = z(k,1);
    z(k,1) = t;

    z(k+1:n,1) = z(k+1:n,1) + t * a_lu(k+1:n,k);

    if ( 1.0 < abs ( z(k,1) ) )
      ynorm = ynorm / abs ( z(k,1) );
      z(1:n) = z(1:n) / abs ( z(k,1) );
    end

  end

  s = sum ( abs ( z(1:n,1) ) );
  z(1:n,1) = z(1:n,1) / s;
  ynorm = ynorm / s;
%
%  Solve U * Z = V.
%
  for k = n : -1 : 1

    if ( abs ( a_lu(k,k) ) < abs ( z(k,1) ) )
      s = abs ( a_lu(k,k) ) / abs ( z(k,1) );
      z(1:n,1) = s * z(1:n,1);
      ynorm = s * ynorm;
    end

    if ( a_lu(k,k) ~= 0.0 )
      z(k,1) = z(k,1) / a_lu(k,k);
    else
      z(k,1) = 1.0;
    end

    z(1:k-1,1) = z(1:k-1,1) - a_lu(1:k-1,k) * z(k,1);

  end
%
%  Normalize Z in the L1 norm.
%
  s = 1.0 / sum ( abs ( z(1:n,1) ) );
  z(1:n,1) = s * z(1:n,1);
  ynorm = s * ynorm;

  cond = anorm / ynorm;

  return
end


text:
function [struct_irf_record D_record gamma_record hd_record ETA_record IVcorrelation PofIVcorrelation beta_gibbs_reshuffle sigma_gibbs_reshuffle]=irfres_zeros_magn_correl_fevd_bayesian_stvol4(beta_gibbs, sigma_gibbs, It, Bu,betahat,sigmahat,IRFperiods,n,m,p,k,T,signrestable,signresperiods, relmagnrestable, relmagnresperiods, names, startdate, enddate, ShockwithInstrument, Ycycle, Xcycle, signreslabels, FEVDresperiods, FEVDrestable, data_exo, HD, const, exo, InstrumentforCorrel, IRFt, YincLags, Psi_gibbs, pref)
%betahat = betahatcycle                                                                                irfres_zeros_magn_correl_fevd_bayesian_stvol4(beta_gibbs, sigma_gibbs, It, Bu,betahatcycle,sigmahatcycle,IRFperiods,n,m,p,k,T,signrestable,signresperiods, relmagnrestable, relmagnresperiods, namespostratining, startdateposttraining, enddate, strctident.ShockwithInstrument, Ycycle, Xcycle, signreslabels, FEVDresperiods, FEVDrestable,data_exo, HD, 0, exo, strctident.InstrumentforCorrel, IRFt, YincLags);
%sigmahat = sigmahatcycle
%names =namespostraining
%startdate = startdateposttraining
%ShockwithInstrument =  strctident.ShockwithInstrument
%InstrumentforCorrel = strctident.InstrumentforCorrel

% inputs:  - matrix 'betahat': OLS estimate for beta
%          - matrix 'sigmahats': OLS estimate for sigma
%          - integer 'IRFperiods': number of periods for IRFs
%          - integer 'n': number of endogenous variables in the BVAR model (defined p 7 of technical guide)
%          - integer 'm': number of exogenous variables in the BVAR model (defined p 7 of technical guide)
%          - integer 'p': number of lags included in the model (defined p 7 of technical guide)
%          - integer 'k': number of coefficients to estimate for each equation in the BVAR model (defined p 7 of technical guide)
%          - cell 'signrestable': table recording the sign restriction input from the user
%          - cell 'signresperiods': table containing the periods corresponding to each restriction
%          - string 'ShockwithInstrument' Name of the shock where the instrument belongs to
% outputs: - cell 'struct_irf_record': record of the gibbs sampler draws for the orthogonalised IRFs
%          - matrix 'D_record': record of the gibbs sampler draws for the structural matrix D
%          - matrix 'gamma_record': record of the gibbs sampler draws for the structural disturbances variance-covariance matrix gamma
%          - integer 'Qdraw': total number of draws of the Q matrix
%          - integer 'Qsuccess': number of successful draws of the Q matrix

tic

%%Phase 1: Preliminary tasks

%% draw from VAR posterior
%sample beta and sigma from the VAR distribution centered around the OLS estimate
inv_sigma_hat = inv(sigmahat); %invert sigmahat as it is frequently used afterwards
Acc=It-Bu; %%number of minimum draws accepted

%% Preliminiaries for sign restrictions
% now identify all the periods concerned with restrictions
% first expand the non-empty entries in signresperiods since they are only expressed in intervals: transform into list
% for instance, translate [1 4] into [1 2 3 4]; I don't think this can done without a loop
temp=cell2mat(signresperiods(~cellfun(@isempty,signresperiods)));
periods=[];
for ii=1:size(temp,1)
    periods=[periods temp(ii,1):temp(ii,2)];
end
% suppress duplicates and sort
periods=sort(unique(periods))';
% count the total number of restriction periods (required for IRF matrix)
nperiods=size(periods,1);

% Identify the restriction matrices
% create five cells, corresponding to the three possible restrictions:
% one cell for sign restrictions, three cells for magnitude restrictions, one cell for zero restrictions
Scell=cell(1,n);
Mcell=cell(1,n);
Mlcell=cell(1,n);
Mucell=cell(1,n);
Zcell=cell(1,n);

% Check if value and periods restrictions correspond to each other
if sum(sum(~cellfun(@isempty,signresperiods) == ~cellfun(@isempty,signrestable))) == n^2
    % All cells with sign restrictions also specify the horizon over which
    % these are applied
else
    disp('Warning: Value restrictions do not correspond to period restrictions one to one')
    pause(1)
end

% loop over rows and columns of the period matrix
for ii=1:n
    for jj=1:n
        % if entry (ii,jj) of the period matrix and of the value matrix is not empty...
        if ~isempty(signresperiods{ii,jj}) && ~isempty(signrestable{ii,jj})
            % ... then there is a restriction over one (or several) periods
            % loop overt those periods
            for kk=signresperiods{ii,jj}(1,1):signresperiods{ii,jj}(1,2)
                % identify the position of the considered period within the list of all periods (required to build the matrix)
                position=find(periods==kk);
                % now create the restriction matrix: this will depend on the type of restriction
                % if it is a positive sign restriction...
                if strcmp(signrestable{ii,jj},'+')
                    % ... then input a 1 entry in the corresponding S matrix
                    Scell{1,jj}=[Scell{1,jj};zeros(1,n*nperiods)];
                    Scell{1,jj}(end,(position-1)*n+ii)=1;
                    % if it is a negative sign restriction...
                elseif strcmp(signrestable{ii,jj},'-')
                    % ... then input a -1 entry in the corresponding S matrix
                    Scell{1,jj}=[Scell{1,jj};zeros(1,n*nperiods)];
                    Scell{1,jj}(end,(position-1)*n+ii)=-1;
                    % if it is a zero restriction...
                elseif strcmp(signrestable{ii,jj},'0')
                    % ... then input a 1 entry in the corresponding Z matrix
                    Zcell{1,jj}=[Zcell{1,jj};zeros(1,n*nperiods)];
                    Zcell{1,jj}(end,(position-1)*n+ii)=1;
                    % else, a non-empty entry being neither a sign nor a zero restriction has to be a magnitude restriction
                else
                    % fill the corresponding M matrices:
                    % input a 1 in M
                    Mcell{1,jj}=[Mcell{1,jj};zeros(1,n*nperiods)];
                    Mcell{1,jj}(end,(position-1)*n+ii)=1;
                    % input the lower value of the interval in Ml
                    temp=str2num(signrestable{ii,jj});
                    Mlcell{1,jj}=[Mlcell{1,jj};temp(1,1)];
                    % input the upper value of the interval in Mu
                    Mucell{1,jj}=[Mucell{1,jj};temp(1,2)];
                end
            end
        end
    end
end

%% Preliminaries for relative magnitude restrictions
% now identify all the periods concerned with relative magnitude
% restrictions
% first expand the non-empty entries in magresperiods since they are only expressed in intervals: transform into list
% for instance, translate [1 4] into [1 2 3 4];
temp=cell2mat(relmagnresperiods(~cellfun(@isempty,relmagnresperiods)));
mperiods=[];
for ii=1:size(temp,1)
    mperiods=[mperiods temp(ii,1):temp(ii,2)];
end
% suppress duplicates and sort
mperiods=sort(unique(mperiods))';
% count the total number of restriction periods (required for IRF matrix)
rmperiods=size(periods,1);

%create matrix entry for relative magnitude restrictions
[r clm] = find(~cellfun('isempty',relmagnrestable));
%2. Indentify which entry corresponds to the positive magnitude
%restriction (which shock is supposed to have a larger impact on which
%variable)
num_magres=length(r)/2; %number of relative magnitude restrictions
IndextempL=double.empty;
kk=1; %number of the restrictions
IndextempS=double.empty;
kk=1; %%number of restriction

rowsS = [];
columnsS = [];
for jj=1:num_magres %%loop over number of magnitude restrictions
    strtemp = strcat('S',num2str(jj)); %%find entry in the table corresponding to the Stronger than restriction
    Stronger = strcmp(relmagnrestable, strtemp);
    [rowS columnS] = find(Stronger==1);
    rowsS = [rowsS rowS];
    columnsS = [columnsS columnS];
end

rowsW = [];
columnsW = [];
for jj=1:num_magres
    strtemp = strcat('W',num2str(jj));
    Weaker = strcmp(relmagnrestable, strtemp);
    [rowW columnW] = find(Weaker==1);
    rowsW = [rowsW rowW];
    columnsW = [columnsW columnW];
end

%% Preliminiaries for IV correlation restrictions
%%load the instrument
ShockwithIV = find(contains(signreslabels,ShockwithInstrument)); %find index for the Shock with correlation restriction

% check for correlation restrictions
if isempty(ShockwithIV)%when there is no shock with an extra instrument
    IVcorrelcheck=0; %there is noting to check
    IVcorrelation=nan(Acc,1); %empty vector such that the paralel loop doesnt crash
    IVcorrel=nan(T,1); %empty vector such that the paralel loop doesnt crash
    PofIVcorrelation=nan(Acc,1); %empty vector such that the paralel loop doesnt crash
    ETA_record=nan(Acc,1); %empty vector such that the paralel loop doesnt crash
    IVcorrel='noexist'; %empty vector such that the paralel loop doesnt crash
    OverlapIVcorrelinY='noexist';%empty vector such that the paralel loop doesnt crash
    Flipcorrel=0; %there is nothing to flip
else
    IVcorrelcheck=1;
end
if IVcorrelcheck==1
    [IVcorrel txtcorrel]=xlsread(pref.excelFile,'IV');

    Index = strcmp(txtcorrel(1,:), InstrumentforCorrel);           %find the instrument in the IV sheet
    IVnum = find(Index==1, 1, 'first')-1;
    IVcorrel = IVcorrel(:, IVnum);
    IVcorrel = IVcorrel(~isnan(IVcorrel));
    txtcorrel = txtcorrel(2:length(IVcorrel)+1,1);              % drop IV names from txt
    date = names(2:end,1);                                   %get the datevector of the VAR
    startlocationY_in_Y=find(strcmp(date,startdate));        %location of sample startdate in Y datevector
    endlocationY_in_Y=find(strcmp(date,enddate));            %location of sample enddate in Y datevector
    date = date(startlocationY_in_Y+p:endlocationY_in_Y,:);  %cut datevector of Y such that it corresponds to the time dates used in the VAR
    OverlapIVcorrelinY = ismember(date,txtcorrel);           %Use this to cut EPS
    OverlapYinIVcorrel = ismember(txtcorrel,date);           %Use this to cut IV
    IVcorrel = IVcorrel(OverlapYinIVcorrel,:);               %cut all the entries from IV that are not in the sample
end

IsNotIdentified = find(contains(signreslabels,'shock'));        %find not identified shock
IsIdentified = find(~contains(signreslabels,'shock'));    %
if min(IsNotIdentified)==0
    identified=n;
else
    identified=min(IsNotIdentified)-1;                              %number of identified shocks
end

%finally check if there are sign restrictions on the shock of interest. If
%not we can use the flipped entry of the rotation matrix aswell
if ~isempty(ShockwithIV)
    if isempty(Scell{1,ShockwithIV})
        FlipCorrel=1;
    else
        FlipCorrel=0;
    end
end

%% Preliminaries for FEVD restriction
% now identify all the periods concerned with FEVD restrictions
% first expand the non-empty entries in FEVDresperiods since they are only expressed in intervals: transform into list
% for instance, translate [1 4] into [1 2 3 4];
temp=cell2mat(FEVDresperiods(~cellfun(@isempty,FEVDresperiods)));
FEVDperiods=[];
for ii=1:size(temp,1)
    FEVDperiods=[FEVDperiods temp(ii,1):temp(ii,2)];
end
% suppress duplicates and sort
FEVDperiods=sort(unique(FEVDperiods))';
% count the total number of restriction periods (required for IRF matrix)
FEVDperiodstot=size(FEVDperiods,1);

%create matrix entry for relative magnitude restrictions
[rowsFEVD clmFEVD] = find(~cellfun('isempty',FEVDrestable));
num_FEVDres=length(rowsFEVD); %number of FEVD restrictions

%check if rows are unique. Two FEVD restrictions for one variable are not
%included in the algorithm. Two columns (shocks) are fine.
uniquerows = unique(rowsFEVD);

if length(uniquerows) < length(rowsFEVD)
    error('Two FEVD restrictions for one variable are not permitted')
end

%now identify if the FEVD restrictions are absolute ones or relative ones
numrelativeFEVD =0;
numabsoluteFEVD =0;
for kk=1:num_FEVDres
    if strcmp(FEVDrestable{rowsFEVD(kk,1),clmFEVD(kk,1)},'Relative')==1
        numrelativeFEVD=numrelativeFEVD+1;
        rowrelativeFEVD(kk,1)=rowsFEVD(kk,1); %rows are the variables for the FEVD
        clmrelativeFEVD(kk,1)=clmFEVD(kk,1);%Columns are the variables for the FEVD
    elseif strcmp(FEVDrestable{rowsFEVD(kk,1),clmFEVD(kk,1)},'Absolute')==1
        numabsoluteFEVD=numabsoluteFEVD+1;
        rowabsoluteFEVD(kk,1)=rowsFEVD(kk,1);%rows are the variables for the FEVD
        clmabsoluteFEVD(kk,1)=clmFEVD(kk,1); %Columns are the variables for the FEVD
    end
end

%if no restriction of one kind exist,set empty cells
if numabsoluteFEVD ==0
    rowabsoluteFEVD = [];
    clmabsoluteFEVD = [];
end

if numrelativeFEVD ==0
    rowrelativeFEVD = [];
    clmrelativeFEVD = [];
end

%% preliminaries for historical decomposition
contributors = n + 1 + 1 + length(exo); %variables + constant + exogenous + initial conditions
hd_estimates2=cell(contributors+2,n); %shocks+constant+initial values+exogenous+unexplained+to be explained by shocks only

%% Check kind of restrictions
% now check what kind of restrictions apply among sign, zero and magnitude restrictions
% check for sign restrictions: if there are any, at least one entry in the cell Scell is non-empty
if sum(~cellfun(@isempty,Scell))~=0
    signres=1;
else
    signres=0;
end
% similarly check for zero restrictions
if sum(~cellfun(@isempty,Zcell))~=0
    zerores=1;
else
    zerores=0;
end
% check for absolute magnitude restrictions
if sum(~cellfun(@isempty,Mcell))~=0
    magnres=1;
else
    magnres=0;
end
% check for relative magnitude restrictions
if length(columnsS)~=0
    relmagnres=1;
else
    relmagnres=0;
end
% check for correlation restrictions
if isempty(ShockwithIV)%when there is no shock with an extra instrument
    IVcorrelcheck=0;
else
    IVcorrelcheck=1;
end
% check for FEVD restrictions
if numabsoluteFEVD ==0 && numrelativeFEVD==0 %when there are no absolute and no relative FEVD restrictions
    FEVDcheck=0;
else
    FEVDcheck=0;
end

%%Activate the restriction, that unidentified shocks should not have the
%%same pattern as identified
patterncheck=0;
%%activate the possibility of absolute relative magnitude restriction
%%(i.e. credit spreads should rise by more than interest rates fall)
%%--> abs(credit spread) > abs(interes rate) instead of
%%--> credit spread>interest rate
ABS=0;

%% Storage cells
% create first the cell that will store the results from the simulations
struct_irf_record=cell(n,n);
% storage cell
storage1=cell(Acc,1);
storage2=cell(Acc,1);
storage3=cell(Acc,1);
storage4=cell(Acc,1);
In= eye(n);

% initiate rotation draws
not_successful = 0;
hbar = bear.parfor_progressbar(Acc,'Progress of Sign, Magnitude, Zero, Correlation and FEVD Restriction Draws');  %create the progress bar

%rearrange Psidraw such that it can be accessed in a parfor loop
for yyy=1:It-Bu
    for kkk=1:n
Psi_gibbs_new(:,kkk,yyy) = Psi_gibbs{1,kkk}(:,yyy);
    end
end

parfor ii=1:Acc
    % initiate the variable 'success'; this variable will be used to check whether the restrictions are satisfied
    % if there are only zero restrictions, they will be satisfied by construction, and 'success' will simply be ignored
    success=0;
    % how the algorithm will be conducted will depend on the types of restrictions implemented
    % if there are only zero restrictions, the algorithm is simple as no checking is required: the conditions are satisfied by construction
   if zerores==1 && signres==0 && magnres==0 && relmagnres==0
   % draw beta and sigma
   beta=beta_gibbs(:,ii);
   sigma=reshape(sigma_gibbs(:,ii),n,n);
   hsigma=chol(bear.nspd(sigma),'lower');
   % obtain orthogonalised IRFs
   [~, ortirfmatrix]=bear.irfsim(beta,hsigma,n,m,p,k,max(IRFperiods,max(periods)));
   % generate the stacked IRF matrix
   stackedirfmat=[];
      for kk=1:numel(periods)
      stackedirfmat=[stackedirfmat;ortirfmatrix(:,:,periods(kk,1)+1)];
      end
   % draw an entire random matrix Q satisfying the zero restrictions
   [Q]=bear.qzerores(n,Zcell,stackedirfmat);
   % there is no need to verify the restrictions: there are satisfied by construction

   % if there are sign/magnitude/correlation restrictions, possibly associated with zero restrictions
   else
        % the algorithm becomes a bit more complicated as conditions now need to be checked
        % to maintain efficiency, the algorithm proceeds recursively shock by shock, and stops as soon as a condition on the considered shock fails
        % repeat algorithm for the iteration as long as not all conditions are satisfied
        while success==0
            not_successful = not_successful+1;
            % switch 'success' to 1; it will be turned back to zero if at any time Q is detected as a candidate not satisfying the restrictions
            success=1;
            % draw randomly the vector of VAR coefficients: draw a random index
            index=floor(rand*(Acc))+1;
            % then draw a random set of beta and sigma corresponding to this index (this is done to make it possible to draw, if required, an infinite number of values from the gibbs sampler record, with equal probability on each value)
            beta=beta_gibbs(:,index);
            sigma=reshape(sigma_gibbs(:,index),n,n);
            hsigma=chol(bear.nspd(sigma),'lower');
            %also draw the corresponding local mean
            Psidraw = Psi_gibbs_new(:,:,index)
            %create the vector Ydraw by subtracting the local mean from the data
            Ypsi = YincLags(p+1:end,:)-Psidraw(p+1:end,:);
            %ultimately create the RHS and LHS of the demeaned data VAR
            temp=bear.lagx(Ypsi,p);
            % to build X, take off the n initial columns of current data
            Xdraw=[temp(:,n+1:end)];
            Ydraw=temp(:,1:n);
            % obtain orthogonalised IRFs
            [~, ortirfmatrix]=bear.irfsim(beta,hsigma,n,m,p,k,max(IRFperiods,max(periods)));
            % generate the stacked IRF matrix
            stackedirfmat=[];
            for kk=1:numel(periods)
                stackedirfmat=[stackedirfmat;ortirfmatrix(:,:,periods(kk,1)+1)];
            end

            % now start looping over the shocks and checking sequentially whether conditions on these shocks hold
            % stop as soon as one restriction fails
            okay = zeros(n,1); %initiate okay vector
            Qjstore = [];
            % initiate Qj
            Qj=[];
            jj=1;
            while success==1 && jj<=n && sum(okay)<n
                    % draw a random vector from the standard normal
                    if okay(1,1)==0 %first find the first column
                        qj=bear.qrandj(n,Zcell{1,jj},stackedirfmat,Qj);
                        % obtain the candidate column fj
                        fj=stackedirfmat*qj;
                        [success qj]=bear.checksignres(Scell{1,jj},qj,fj);
                        if success==1
                            Qjstore=[Qj qj];
                            Qj(:,1) = qj; %set column yy of Qj to qj
                            jj=1+1;
                            okay(1,1)=1;
                        end
                    else
                        x=normrnd(0,1,n,1);
                        qj=(In-Qjstore*Qjstore')*x/norm((In-Qjstore*Qjstore')*x);
                        %compute the rotated impulse responses
                        fj=stackedirfmat*qj;
                        [success, qj, okay, yy]=bear.checksignres_inc_other_shocks(qj, fj, Scell, okay, IRFt, n);
                        if success==1
                            Qjstore=[Qj qj];
                            Qj(:,yy) = qj; %set column yy of Qj to qj
                            jj=jj+1;
                        end
                    end

            %once all n columns are build and fullfill the sign restriction
            %% if sign and magnitude restrictions are fullfilled, check proxy correlation restriction
            if size(Qj,2)==n && success==1  && IVcorrelcheck==1
                %disp('I reached correlation restrictions')
                D=hsigma*Qj;
                % recover the VAR coefficients, reshaped for convenience
                B=reshape(beta,k,n);
                % obtain the residuals from (this draw)
                EPS=Ydraw-Xdraw*B;
                %compute structural shocks
                ETA=D\EPS';
                [success corIV pivShockwithIV Qj] = bear.CheckCorrelWithIV(ETA,n,ShockwithIV, IVcorrel,OverlapIVcorrelinY, FlipCorrel, Qj);
                if success==1
                    disp('correlation restriction fulfilled');
                end
            end
            %% check relative magnitudes
            if size(Qj,2)==n && success==1  && relmagnres==1
                %              disp('I reached magnitude restrictions')
                D=hsigma*Qj;
                [~, ortirfmatrixmagnitude]=bear.irfsim(beta,D,n,m,p,k,max(IRFperiods,max(mperiods)));
                % generate the stacked IRF matrix
                stackedirfmatmagn=[];
                for kk=1:numel(mperiods)
                    stackedirfmatmagn=[stackedirfmatmagn;ortirfmatrixmagnitude(:,:,mperiods(kk,1)+1)];
                end
                [success]=bear.checkrelmag(stackedirfmatmagn,columnsS, columnsW, rowsS, rowsW, n, mperiods, ABS);
                if success ==1
                    disp('Magnitude Restrictions fullfilled')
                end
            end

            %% if sign, zero and relative magnitude restrictions are fullfilled, check FEVD restrictions
            if size(Qj,2)==n && success==1  && FEVDcheck==1
                disp('I reached FEVD restrictions')
                D=hsigma*Qj; %again compute D
                [~,ortirfmatrixFEVD]=bear.irfsim(beta,D,n,m,p,k,IRFperiods); %obtain orthogonalized IRFs
                % record the results in the cell irf_record
                %check FEVDrestrictions
                [success] = bear.CheckFEVDrestriction(ortirfmatrixFEVD,IRFperiods,n,D,FEVDperiodstot, clmrelativeFEVD, rowrelativeFEVD, rowabsoluteFEVD, clmabsoluteFEVD, FEVDresperiods, rowsFEVD);
                if success==1
                    disp('FEVD restriction fulfilled');
                end
            end

            end
            %finally compute the historical decomposition
            if size(Qj,2)==n && success==1  && HD==1
                D=hsigma*Qj;
                B=reshape(beta,k,n);
                % obtain the residuals from (this draw)
                EPS=Ydraw-Xdraw*B;
                %compute structural shocks
                ETA=D\EPS';
                Psidrawcut = Psidraw(2*p:end,:);
                %decompose the data into trend and cycle and further
                [hd_estimates] = bear.hd_new_for_signres_stvol4(0,beta,k,n,p,D,m,T,Xdraw,Ydraw, data_exo, contributors, hd_estimates2, Psidrawcut, YincLags(2*p+1:end,:));
            end
            % repeat this loop until a succesful draw is obtained

        end %end of while loop ´
        % with succesful Qj at hand, eventually set Q as Qj
        Q=Qj;
   end %end of if loop
    % store
    for kk=1:IRFperiods
        storage1{ii,1}(:,:,kk)=ortirfmatrix(:,:,kk)*Q;
    end
    storage2{ii,1}=hsigma*Q;
    % store historical decompositions
    if HD==1
        storage3{ii,1}=hd_estimates;
        storage4{ii,1}=ETA;
    end
    storage5(:,ii) = beta;
    storage6(:,ii) = bear.vec(sigma);

    %lpdf = irfpdf(hsigma*Q,betahat,aux1,T,sigmahat,beta);
    %lpdfirf(ii,1)=lpdf;
    if IVcorrelcheck==1
        IVcorrelation(ii,1)=corIV;
        PofIVcorrelation(ii,1)=pivShockwithIV;
    else
        IVcorrelation(ii,1)=0;
        PofIVcorrelation(ii,1)=0;
    end
    %  FEVDrestrictionvalue(ii,1) = FEVDrestrictionvalue;
    hbar.iterate(1);   % update progress by one iteration
end
close(hbar);   %close progress bar

beta_gibbs_reshuffle = storage5; %save the reshuffled beta and sigma such that they correspond to the structural matrix D
sigma_gibbs_reshuffle = storage6;
% reorganise storage
% loop over iterations
for ii=1:Acc
    % loop over IRF periods
    for jj=1:IRFperiods
        % loop over variables
        for kk=1:n
            % loop over shocks
            for ll=1:n
                struct_irf_record{kk,ll}(ii,jj)=storage1{ii,1}(kk,ll,jj);
            end
        end
    end
    D_record(:,ii)=storage2{ii,1}(:);
    gamma_record(:,ii)=bear.vec(eye(n));
end
%reorganize historical decompositions
hd_record=cell(contributors+2,n);
if HD==1
    for ii=1:Acc %loop over draws
        for kk=1:contributors+2 %loop over contributors
            for ll=1:n %loop over variables
                hd_record{kk,ll}(ii,:) = storage3{ii,1}{kk,ll};
            end
        end
    end
end
ETA_record=cell(n,1);
if HD==1
    for jj=1:Acc
        for kk=1:n
            ETA_record{kk,1}(jj,:)= storage4{jj,1}(kk,:);
        end
    end
end

%hdrecord is ordered such that columns are variables and rows are contributors
%row n+1 = contribution of the constant
%row n+2 = contribution of initial conditions (past shocks)
%row n+3 = unexplained part (for partially identified model
%row n+4 = part that was left to explain by the structural shocks after
%accounting for exogenous, constant and initial conditions

toc
fprintf('Accepted Draws in Percent of Total Number of Draws: %f', 100*(Acc)/(not_successful + Acc))
end

author: european-central-bank

repo: BEAR-toolbox


text:
initialImage = im2single( imread('peppers.png') );

width = size(initialImage, 2);
height = size(initialImage, 1);

cropPositions = [ 1, 1, height, width; ... % full image
                  1, 1, height / 2, width / 3; ... % sub patch
                  -height / 2, -width / 2, height / 2, width / 3 ]; ... % sub patch not inside the image
crops = cropRectanglesMex( initialImage, cropPositions, [height, width] );

figure(1), imshow( initialImage );
figure(2), imshow( crops(:,:,:,1) );
figure(3), imshow( crops(:,:,:,2) );
figure(4), imshow( crops(:,:,:,3) );

author: aosokin


text:
function b = strstartswith(s, pat)
%STRSTARTSWITH Determines whether a string starts with a specified pattern
%
%   b = strstartswith(s, pat);
%       returns whether the string s starts with a sub-string pat.
%

%   History
%   -------
%       - Created by Dahua Lin, on Oct 9, 2008
%

%% main

sl = length(s);
pl = length(pat);

b = (sl >= pl && strcmp(s(1:pl), pat)) || isempty(pat);

author: Sable

repo: mcbench-benchmarks


text:
function [methodinfo,structs,enuminfo,ThunkLibName]=remoteApiProto
%REMOTEAPIPROTO Create structures to define interfaces found in 'extApi'.

%This function was generated by loadlibrary.m parser version 1.1.6.32
%perl options:'extApi.i -outfile=remoteApiProto.m'
ival={cell(1,0)}; % change 0 to the actual number of functions to preallocate the data.
structs=[];enuminfo=[];fcnNum=1;
fcns=struct('name',ival,'calltype',ival,'LHS',ival,'RHS',ival,'alias',ival);
ThunkLibName=[];

% extern  simxInt mtlb_simxSetJointPosition ( simxInt clientID , simxInt jointHandle , simxFloat* position , simxInt operationMode );
fcns.name{fcnNum}='mtlb_simxSetJointPosition'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt mtlb_simxSetJointTargetVelocity ( simxInt clientID , simxInt jointHandle , simxFloat* targetVelocity , simxInt operationMode );
fcns.name{fcnNum}='mtlb_simxSetJointTargetVelocity'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt mtlb_simxSetJointTargetPosition ( simxInt clientID , simxInt jointHandle , simxFloat* targetPosition , simxInt operationMode );
fcns.name{fcnNum}='mtlb_simxSetJointTargetPosition'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt mtlb_simxSetJointForce ( simxInt clientID , simxInt jointHandle , simxFloat* force , simxInt operationMode );
fcns.name{fcnNum}='mtlb_simxSetJointForce'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt mtlb_simxSetJointMaxForce ( simxInt clientID , simxInt jointHandle , simxFloat* force , simxInt operationMode );
fcns.name{fcnNum}='mtlb_simxSetJointMaxForce'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt mtlb_simxSetFloatSignal ( simxInt clientID , const simxChar * signalName , simxFloat* signalValue , simxInt operationMode );
fcns.name{fcnNum}='mtlb_simxSetFloatSignal'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt mtlb_simxSetObjectFloatParameter ( simxInt clientID , simxInt objectHandle , simxInt parameterID , simxFloat* parameterValue , simxInt operationMode );
fcns.name{fcnNum}='mtlb_simxSetObjectFloatParameter'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt mtlb_simxSetFloatingParameter ( simxInt clientID , simxInt paramIdentifier , simxFloat* paramValue , simxInt operationMode );
fcns.name{fcnNum}='mtlb_simxSetFloatingParameter'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt mtlb_simxCreateDummy ( simxInt clientID , simxFloat* size , const simxUChar * colors , simxInt * objectHandle , simxInt operationMode );
fcns.name{fcnNum}='mtlb_simxCreateDummy'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'singlePtr', 'uint8Ptr', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;

% extern  simxInt mtlb_simxReadProximitySensor(simxInt* clientIDandSensorHandle,simxUChar* detectionState,simxFloat* detectedPoint,simxInt* detectedObjectHandle,simxFloat* detectedSurfaceNormalVector,simxInt operationMode);
fcns.name{fcnNum}='mtlb_simxReadProximitySensor'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32Ptr', 'uint8Ptr', 'singlePtr', 'int32Ptr', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt mtlb_simxAuxiliaryConsoleOpen(simxInt* clientIDandMaxLinesAndModeAndPositionAndSize,const simxChar* title,simxFloat* textColor,simxFloat* backgroundColor,simxInt* consoleHandle,simxInt operationMode);
fcns.name{fcnNum}='mtlb_simxAuxiliaryConsoleOpen'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32Ptr', 'int8Ptr', 'singlePtr', 'singlePtr', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt mtlb_simxDisplayDialog(simxInt* clientIDandDlgTypeAndOperationMode,const simxChar* titleText,const simxChar* mainText,const simxChar* initialText,const simxFloat* titleColorsAndDlgColors,simxInt* dialogHandleAndUiHandle);
fcns.name{fcnNum}='mtlb_simxDisplayDialog'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32Ptr', 'int8Ptr', 'int8Ptr','int8Ptr', 'singlePtr', 'int32Ptr'};fcnNum=fcnNum+1;
% extern  simxInt mtlb_simxQuery(simxInt* clientIDandSignalLengthAndTimeOutInMs,const simxChar* signalName,const simxUChar* signalValue,const simxChar* retSignalName,simxUChar** retSignalValue,simxInt* retSignalLength);
fcns.name{fcnNum}='mtlb_simxQuery'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32Ptr', 'int8Ptr', 'uint8Ptr', 'int8Ptr', 'uint8PtrPtr', 'int32Ptr'};fcnNum=fcnNum+1;
% extern  simxInt mtlb_simxGetObjectGroupData(simxInt* clientIDandObjectTypeAndDataTypeAndOperationMode,simxInt* handlesCountAndIntDataCountAndFloatDataCountAndStringDataCount,simxInt** handles,simxInt** intData,simxFloat** floatData,simxChar** stringData);
fcns.name{fcnNum}='mtlb_simxGetObjectGroupData'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32Ptr', 'int32Ptr', 'int32PtrPtr', 'int32PtrPtr', 'singlePtrPtr', 'int8PtrPtr'};fcnNum=fcnNum+1;
% extern  simxInt mtlb_simxCallScriptFunction_a(const simxInt* variousIntsIn,const simxChar* scriptDescriptionAndFunctionName,const simxInt* inInt,const simxFloat* inFloat,const simxChar* inString,const simxUChar* inBuffer);
fcns.name{fcnNum}='mtlb_simxCallScriptFunction_a'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32Ptr', 'int8Ptr', 'int32Ptr', 'singlePtr', 'int8Ptr', 'uint8Ptr'};fcnNum=fcnNum+1;
% extern  simxInt mtlb_simxCallScriptFunction_b(simxInt clientID,simxInt* variousIntsOut,simxInt** outInt,simxFloat** outFloat,simxChar** outString,simxUChar** outBuffer);
fcns.name{fcnNum}='mtlb_simxCallScriptFunction_b'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32Ptr', 'int32PtrPtr', 'singlePtrPtr', 'int8PtrPtr', 'uint8PtrPtr'};fcnNum=fcnNum+1;

% extern  simxInt simxGetJointPosition ( simxInt clientID , simxInt jointHandle , simxFloat * position , simxInt operationMode );
fcns.name{fcnNum}='simxGetJointPosition'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetJointMatrix ( simxInt clientID , simxInt jointHandle , simxFloat * matrix , simxInt operationMode );
fcns.name{fcnNum}='simxGetJointMatrix'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetSphericalJointMatrix ( simxInt clientID , simxInt jointHandle , simxFloat * matrix , simxInt operationMode );
fcns.name{fcnNum}='simxSetSphericalJointMatrix'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetJointForce ( simxInt clientID , simxInt jointHandle , simxFloat * force , simxInt operationMode );
fcns.name{fcnNum}='simxGetJointForce'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetJointMaxForce ( simxInt clientID , simxInt jointHandle , simxFloat * force , simxInt operationMode );
fcns.name{fcnNum}='simxGetJointMaxForce'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxReadForceSensor ( simxInt clientID , simxInt forceSensorHandle , simxUChar * state , simxFloat * forceVector , simxFloat * torqueVector , simxInt operationMode );
fcns.name{fcnNum}='simxReadForceSensor'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'uint8Ptr', 'singlePtr', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxBreakForceSensor ( simxInt clientID , simxInt forceSensorHandle , simxInt operationMode );
fcns.name{fcnNum}='simxBreakForceSensor'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxReadVisionSensor ( simxInt clientID , simxInt sensorHandle , simxUChar * detectionState , simxFloat ** auxValues , simxInt ** auxValuesCount , simxInt operationMode );
fcns.name{fcnNum}='simxReadVisionSensor'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'uint8Ptr', 'singlePtrPtr', 'int32PtrPtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetObjectHandle ( simxInt clientID , const simxChar * objectName , simxInt * handle , simxInt operationMode );
fcns.name{fcnNum}='simxGetObjectHandle'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetVisionSensorImage ( simxInt clientID , simxInt sensorHandle , simxInt * resolution , simxUChar ** image , simxUChar options , simxInt operationMode );
fcns.name{fcnNum}='simxGetVisionSensorImage'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32Ptr', 'uint8PtrPtr', 'uint8', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetVisionSensorImage ( simxInt clientID , simxInt sensorHandle , simxUChar * image , simxInt bufferSize , simxUChar options , simxInt operationMode );
fcns.name{fcnNum}='simxSetVisionSensorImage'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'uint8Ptr', 'int32', 'uint8', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetVisionSensorDepthBuffer ( simxInt clientID , simxInt sensorHandle , simxInt * resolution , simxFloat ** buffer , simxInt operationMode );
fcns.name{fcnNum}='simxGetVisionSensorDepthBuffer'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32Ptr', 'singlePtrPtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetObjectChild ( simxInt clientID , simxInt parentObjectHandle , simxInt childIndex , simxInt * childObjectHandle , simxInt operationMode );
fcns.name{fcnNum}='simxGetObjectChild'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetObjectParent ( simxInt clientID , simxInt childObjectHandle , simxInt * parentObjectHandle , simxInt operationMode );
fcns.name{fcnNum}='simxGetObjectParent'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxLoadModel ( simxInt clientID , const simxChar * modelPathAndName , simxUChar options , simxInt * baseHandle , simxInt operationMode );
fcns.name{fcnNum}='simxLoadModel'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'uint8', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxLoadUI ( simxInt clientID , const simxChar * uiPathAndName , simxUChar options , simxInt * count , simxInt ** uiHandles , simxInt operationMode );
fcns.name{fcnNum}='simxLoadUI'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'uint8', 'int32Ptr', 'int32PtrPtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxLoadScene ( simxInt clientID , const simxChar * scenePathAndName , simxUChar options , simxInt operationMode );
fcns.name{fcnNum}='simxLoadScene'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'uint8', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxStartSimulation ( simxInt clientID , simxInt operationMode );
fcns.name{fcnNum}='simxStartSimulation'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxPauseSimulation ( simxInt clientID , simxInt operationMode );
fcns.name{fcnNum}='simxPauseSimulation'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxStopSimulation ( simxInt clientID , simxInt operationMode );
fcns.name{fcnNum}='simxStopSimulation'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetUIHandle ( simxInt clientID , const simxChar * uiName , simxInt * handle , simxInt operationMode );
fcns.name{fcnNum}='simxGetUIHandle'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetUISlider ( simxInt clientID , simxInt uiHandle , simxInt uiButtonID , simxInt * position , simxInt operationMode );
fcns.name{fcnNum}='simxGetUISlider'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetUISlider ( simxInt clientID , simxInt uiHandle , simxInt uiButtonID , simxInt position , simxInt operationMode );
fcns.name{fcnNum}='simxSetUISlider'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetUIEventButton ( simxInt clientID , simxInt uiHandle , simxInt * uiEventButtonID , simxInt * auxValues , simxInt operationMode );
fcns.name{fcnNum}='simxGetUIEventButton'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32Ptr', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetUIButtonProperty ( simxInt clientID , simxInt uiHandle , simxInt uiButtonID , simxInt * prop , simxInt operationMode );
fcns.name{fcnNum}='simxGetUIButtonProperty'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetUIButtonProperty ( simxInt clientID , simxInt uiHandle , simxInt uiButtonID , simxInt prop , simxInt operationMode );
fcns.name{fcnNum}='simxSetUIButtonProperty'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxAddStatusbarMessage ( simxInt clientID , const simxChar * message , simxInt operationMode );
fcns.name{fcnNum}='simxAddStatusbarMessage'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxAuxiliaryConsoleClose ( simxInt clientID , simxInt consoleHandle , simxInt operationMode );
fcns.name{fcnNum}='simxAuxiliaryConsoleClose'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxAuxiliaryConsolePrint ( simxInt clientID , simxInt consoleHandle , const simxChar * txt , simxInt operationMode );
fcns.name{fcnNum}='simxAuxiliaryConsolePrint'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int8Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxAuxiliaryConsoleShow ( simxInt clientID , simxInt consoleHandle , simxUChar showState , simxInt operationMode );
fcns.name{fcnNum}='simxAuxiliaryConsoleShow'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'uint8', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetObjectOrientation ( simxInt clientID , simxInt objectHandle , simxInt relativeToObjectHandle , simxFloat * eulerAngles , simxInt operationMode );
fcns.name{fcnNum}='simxGetObjectOrientation'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetObjectQuaternion ( simxInt clientID , simxInt objectHandle , simxInt relativeToObjectHandle , simxFloat * eulerAngles , simxInt operationMode );
fcns.name{fcnNum}='simxGetObjectQuaternion'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetObjectPosition ( simxInt clientID , simxInt objectHandle , simxInt relativeToObjectHandle , simxFloat * position , simxInt operationMode );
fcns.name{fcnNum}='simxGetObjectPosition'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetObjectOrientation ( simxInt clientID , simxInt objectHandle , simxInt relativeToObjectHandle , const simxFloat * eulerAngles , simxInt operationMode );
fcns.name{fcnNum}='simxSetObjectOrientation'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetObjectQuaternion ( simxInt clientID , simxInt objectHandle , simxInt relativeToObjectHandle , const simxFloat * eulerAngles , simxInt operationMode );
fcns.name{fcnNum}='simxSetObjectQuaternion'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetObjectPosition ( simxInt clientID , simxInt objectHandle , simxInt relativeToObjectHandle , const simxFloat * position , simxInt operationMode );
fcns.name{fcnNum}='simxSetObjectPosition'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetObjectParent ( simxInt clientID , simxInt objectHandle , simxInt parentObject , simxUChar keepInPlace , simxInt operationMode );
fcns.name{fcnNum}='simxSetObjectParent'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'uint8', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetUIButtonLabel ( simxInt clientID , simxInt uiHandle , simxInt uiButtonID , const simxChar * upStateLabel , const simxChar * downStateLabel , simxInt operationMode );
fcns.name{fcnNum}='simxSetUIButtonLabel'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'int8Ptr', 'int8Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetLastErrors ( simxInt clientID , simxInt * errorCnt , simxChar ** errorStrings , simxInt operationMode );
fcns.name{fcnNum}='simxGetLastErrors'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32Ptr', 'int8PtrPtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetArrayParameter ( simxInt clientID , simxInt paramIdentifier , simxFloat * paramValues , simxInt operationMode );
fcns.name{fcnNum}='simxGetArrayParameter'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetArrayParameter ( simxInt clientID , simxInt paramIdentifier , const simxFloat * paramValues , simxInt operationMode );
fcns.name{fcnNum}='simxSetArrayParameter'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetBooleanParameter ( simxInt clientID , simxInt paramIdentifier , simxUChar * paramValue , simxInt operationMode );
fcns.name{fcnNum}='simxGetBooleanParameter'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'uint8Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetBooleanParameter ( simxInt clientID , simxInt paramIdentifier , simxUChar paramValue , simxInt operationMode );
fcns.name{fcnNum}='simxSetBooleanParameter'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'uint8', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetIntegerParameter ( simxInt clientID , simxInt paramIdentifier , simxInt * paramValue , simxInt operationMode );
fcns.name{fcnNum}='simxGetIntegerParameter'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetIntegerParameter ( simxInt clientID , simxInt paramIdentifier , simxInt paramValue , simxInt operationMode );
fcns.name{fcnNum}='simxSetIntegerParameter'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetFloatingParameter ( simxInt clientID , simxInt paramIdentifier , simxFloat * paramValue , simxInt operationMode );
fcns.name{fcnNum}='simxGetFloatingParameter'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetStringParameter ( simxInt clientID , simxInt paramIdentifier , simxChar ** paramValue , simxInt operationMode );
fcns.name{fcnNum}='simxGetStringParameter'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int8PtrPtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetCollisionHandle ( simxInt clientID , const simxChar * collisionObjectName , simxInt * handle , simxInt operationMode );
fcns.name{fcnNum}='simxGetCollisionHandle'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetDistanceHandle ( simxInt clientID , const simxChar * distanceObjectName , simxInt * handle , simxInt operationMode );
fcns.name{fcnNum}='simxGetDistanceHandle'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetCollectionHandle ( simxInt clientID , const simxChar * collectionName , simxInt * handle , simxInt operationMode );
fcns.name{fcnNum}='simxGetCollectionHandle'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxReadCollision ( simxInt clientID , simxInt collisionObjectHandle , simxUChar * collisionState , simxInt operationMode );
fcns.name{fcnNum}='simxReadCollision'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'uint8Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxReadDistance ( simxInt clientID , simxInt distanceObjectHandle , simxFloat * minimumDistance , simxInt operationMode );
fcns.name{fcnNum}='simxReadDistance'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxRemoveObject ( simxInt clientID , simxInt objectHandle , simxInt operationMode );
fcns.name{fcnNum}='simxRemoveObject'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxRemoveModel ( simxInt clientID , simxInt objectHandle , simxInt operationMode );
fcns.name{fcnNum}='simxRemoveModel'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxRemoveUI ( simxInt clientID , simxInt uiHandle , simxInt operationMode );
fcns.name{fcnNum}='simxRemoveUI'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxCloseScene ( simxInt clientID , simxInt operationMode );
fcns.name{fcnNum}='simxCloseScene'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetObjects ( simxInt clientID , simxInt objectType , simxInt * objectCount , simxInt ** objectHandles , simxInt operationMode );
fcns.name{fcnNum}='simxGetObjects'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32Ptr', 'int32PtrPtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxEndDialog ( simxInt clientID , simxInt dialogHandle , simxInt operationMode );
fcns.name{fcnNum}='simxEndDialog'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetDialogInput ( simxInt clientID , simxInt dialogHandle , simxChar ** inputText , simxInt operationMode );
fcns.name{fcnNum}='simxGetDialogInput'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int8PtrPtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetDialogResult ( simxInt clientID , simxInt dialogHandle , simxInt * result , simxInt operationMode );
fcns.name{fcnNum}='simxGetDialogResult'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxCopyPasteObjects ( simxInt clientID , const simxInt * objectHandles , simxInt objectCount , simxInt ** newObjectHandles , simxInt * newObjectCount , simxInt operationMode );
fcns.name{fcnNum}='simxCopyPasteObjects'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32Ptr', 'int32', 'int32PtrPtr', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetObjectSelection ( simxInt clientID , simxInt ** objectHandles , simxInt * objectCount , simxInt operationMode );
fcns.name{fcnNum}='simxGetObjectSelection'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32PtrPtr', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetObjectSelection ( simxInt clientID , const simxInt * objectHandles , simxInt objectCount , simxInt operationMode );
fcns.name{fcnNum}='simxSetObjectSelection'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32Ptr', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxClearFloatSignal ( simxInt clientID , const simxChar * signalName , simxInt operationMode );
fcns.name{fcnNum}='simxClearFloatSignal'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxClearIntegerSignal ( simxInt clientID , const simxChar * signalName , simxInt operationMode );
fcns.name{fcnNum}='simxClearIntegerSignal'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxClearStringSignal ( simxInt clientID , const simxChar * signalName , simxInt operationMode );
fcns.name{fcnNum}='simxClearStringSignal'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetFloatSignal ( simxInt clientID , const simxChar * signalName , simxFloat * signalValue , simxInt operationMode );
fcns.name{fcnNum}='simxGetFloatSignal'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetIntegerSignal ( simxInt clientID , const simxChar * signalName , simxInt * signalValue , simxInt operationMode );
fcns.name{fcnNum}='simxGetIntegerSignal'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetStringSignal ( simxInt clientID , const simxChar * signalName , simxUChar ** signalValue , simxInt * signalLength , simxInt operationMode );
fcns.name{fcnNum}='simxGetStringSignal'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'uint8PtrPtr', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetAndClearStringSignal ( simxInt clientID , const simxChar * signalName , simxUChar ** signalValue , simxInt * signalLength , simxInt operationMode );
fcns.name{fcnNum}='simxGetAndClearStringSignal'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'uint8PtrPtr', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxReadStringStream ( simxInt clientID , const simxChar * signalName , simxUChar ** signalValue , simxInt * signalLength , simxInt operationMode );
fcns.name{fcnNum}='simxReadStringStream'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'uint8PtrPtr', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetIntegerSignal ( simxInt clientID , const simxChar * signalName , simxInt signalValue , simxInt operationMode );
fcns.name{fcnNum}='simxSetIntegerSignal'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetStringSignal ( simxInt clientID , const simxChar * signalName , const simxUChar * signalValue , simxInt signalLength , simxInt operationMode );
fcns.name{fcnNum}='simxSetStringSignal'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'uint8Ptr', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxAppendStringSignal ( simxInt clientID , const simxChar * signalName , const simxUChar * signalValue , simxInt signalLength , simxInt operationMode );
fcns.name{fcnNum}='simxAppendStringSignal'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'uint8Ptr', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxWriteStringStream ( simxInt clientID , const simxChar * signalName , const simxUChar * signalValue , simxInt signalLength , simxInt operationMode );
fcns.name{fcnNum}='simxWriteStringStream'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'uint8Ptr', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetObjectFloatParameter ( simxInt clientID , simxInt objectHandle , simxInt parameterID , simxFloat * parameterValue , simxInt operationMode );
fcns.name{fcnNum}='simxGetObjectFloatParameter'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetObjectIntParameter ( simxInt clientID , simxInt objectHandle , simxInt parameterID , simxInt * parameterValue , simxInt operationMode );
fcns.name{fcnNum}='simxGetObjectIntParameter'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetObjectIntParameter ( simxInt clientID , simxInt objectHandle , simxInt parameterID , simxInt parameterValue , simxInt operationMode );
fcns.name{fcnNum}='simxSetObjectIntParameter'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetModelProperty ( simxInt clientID , simxInt objectHandle , simxInt * prop , simxInt operationMode );
fcns.name{fcnNum}='simxGetModelProperty'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32Ptr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSetModelProperty ( simxInt clientID , simxInt objectHandle , simxInt prop , simxInt operationMode );
fcns.name{fcnNum}='simxSetModelProperty'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetObjectVelocity ( simxInt clientID , simxInt objectHandle , simxFloat * linearVelocity , simxFloat * angularVelocity , simxInt operationMode );
fcns.name{fcnNum}='simxGetObjectVelocity'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'singlePtr', 'singlePtr', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxStart ( const simxChar * connectionAddress , simxInt connectionPort , simxUChar waitUntilConnected , simxUChar doNotReconnectOnceDisconnected , simxInt timeOutInMs , simxInt commThreadCycleInMs );
fcns.name{fcnNum}='simxStart'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int8Ptr', 'int32', 'uint8', 'uint8', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxVoid simxFinish ( simxInt clientID );
fcns.name{fcnNum}='simxFinish'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}=[]; fcns.RHS{fcnNum}={'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxGetPingTime ( simxInt clientID , simxInt * pingTime );
fcns.name{fcnNum}='simxGetPingTime'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32Ptr'};fcnNum=fcnNum+1;
% extern  simxInt simxGetLastCmdTime ( simxInt clientID );
fcns.name{fcnNum}='simxGetLastCmdTime'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSynchronousTrigger ( simxInt clientID );
fcns.name{fcnNum}='simxSynchronousTrigger'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxSynchronous ( simxInt clientID , simxUChar enable );
fcns.name{fcnNum}='simxSynchronous'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'uint8'};fcnNum=fcnNum+1;
% extern  simxInt simxPauseCommunication ( simxInt clientID , simxUChar pause );
fcns.name{fcnNum}='simxPauseCommunication'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'uint8'};fcnNum=fcnNum+1;
% extern  simxInt simxGetInMessageInfo ( simxInt clientID , simxInt infoType , simxInt * info );
fcns.name{fcnNum}='simxGetInMessageInfo'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32Ptr'};fcnNum=fcnNum+1;
% extern  simxInt simxGetOutMessageInfo ( simxInt clientID , simxInt infoType , simxInt * info );
fcns.name{fcnNum}='simxGetOutMessageInfo'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int32', 'int32Ptr'};fcnNum=fcnNum+1;
% extern  simxInt simxGetConnectionId ( simxInt clientID );
fcns.name{fcnNum}='simxGetConnectionId'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32'};fcnNum=fcnNum+1;
% extern  simxUChar * simxCreateBuffer ( simxInt bufferSize );
fcns.name{fcnNum}='simxCreateBuffer'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='uint8Ptr'; fcns.RHS{fcnNum}={'int32'};fcnNum=fcnNum+1;
% extern  simxVoid simxReleaseBuffer ( simxUChar * buffer );
fcns.name{fcnNum}='simxReleaseBuffer'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}=[]; fcns.RHS{fcnNum}={'uint8Ptr'};fcnNum=fcnNum+1;
% extern  simxInt simxTransferFile ( simxInt clientID , const simxChar * filePathAndName , const simxChar * fileName_serverSide , simxInt timeOut , simxInt operationMode );
fcns.name{fcnNum}='simxTransferFile'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'int8Ptr', 'int32', 'int32'};fcnNum=fcnNum+1;
% extern  simxInt simxEraseFile ( simxInt clientID , const simxChar * fileName_serverSide , simxInt operationMode );
fcns.name{fcnNum}='simxEraseFile'; fcns.calltype{fcnNum}='cdecl'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32', 'int8Ptr', 'int32'};fcnNum=fcnNum+1;
methodinfo=fcns;

repo: ARTE


text:
function determ = minij_determinant ( n )

%*****************************************************************************80
%
%% MINIJ_DETERMINANT returns the determinant of the MINIJ matrix.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    16 October 2007
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the order of the matrix.
%
%    Output, real DETERM, the determinant.
%
  determ = 1.0;

  for i = 1 : n
    angle = ( 2 * i - 1 ) * pi / ( 2 * n + 1 );
    determ = determ * 0.5 / ( 1.0 - cos ( angle ) );
  end

  return
end


text:
% Plot all time series variables that have a certain
% 'standard_name' in a specified bounding box and time period

open_url='http://geoport.whoi.edu/gi-cat/services/opensearch';
var='sea_water_temperature'; %free text search string
time_var='time'; %time coordinate variable
bbox =[-180 180 0 90];  % [lon_min lon_max lat_min lat_max]
start=[1990 1 1 0 0 0]; %start
stop =[2000 1 1 0 0 0];  %stop

% OpenSearch query
q.endpoint = open_url
q.bbox = sprintf('%d,%d,%d,%d',bbox([1 3 2 4]));
q.time_start=datestr(start,'yyyy-mm-ddTHH:MM:SSZ')% convert to ISO
q.time_end=datestr(stop,'yyyy-mm-ddTHH:MM:SSZ')% convert to ISO
q.string_text=var;
[links,params]=opensearch(q);   % make the query

dap=links2dap(links); % find only the OPeNDAP links

for i=1:length(dap);
    figure(i);
    nc=cfdataset(dap{i});
    vars=nc.variables;
    for j=1:length(vars); %loop through variables to find standard_names
        std_name=value4key(nc.attributes(vars{j}),'standard_name');
        if strcmp(std_name,var),
            vart=nc.variable(vars{j});
            jd=nc.time(time_var);
            ii=date_index(jd,start,stop);  % find indices of dates between start/stop
            jd=jd(ii);
            t=vart.data(ii);  %extact these indices from dataset
            plot(jd,t);
            ylabel(sprintf('%s [%s]',var,value4key(vart.attributes,'units')),...
                'interpreter','none');
            datetick
            grid;
            title(value4key(nc.attributes,'title'))
        end
    end
end

author: nctoolbox

repo: nctoolbox

save_path: github-repos/MATLAB/nctoolbox-nctoolbox


text:
classdef ImageProcessingComputer < handle

    properties (Access = public)
        computation
        variables
    end

    properties (Access = private)
        testName
        imageProblem
    end

    methods (Access = public)
        function obj = ImageProcessingComputer(cParams)
            obj.testName = cParams.testName;
        end

        function compute(obj)
            problemName  = obj.testName;
            sLoader      = SettingsLoader(problemName);
            settings     = sLoader.settings;
            imProblem = DenoisingProblem(settings);
            imProblem.solve();
            obj.imageProblem = imProblem;
            obj.variables = imProblem;
            obj.computation = obj;
        end
    end
end

author: SwanLab

repo: Swan

save_path: github-repos/MATLAB/SwanLab-Swan


text:
function prior = logisticNormalPriorParamInit(prior)

% LOGISTICNORMALPRIORPARAMINIT Logistic-normal prior model's parameter initialisation.
% FORMAT
% DESC initialises the parameters of the 4 parameter logistic-normal
% prior with some default parameters.
% ARG prior : prior structure to be initialised.
% RETURN prior : prior structure with initial values in place.
%
% Reference: Johnson, Systems of Frequency Curves Generated by
% Methods of Translation, Biometrika 36(1/2):149-176, 1949.
%
% SEEALSO : priorCreate
%
% COPYRIGHT : Antti Honkela, 2011

% PRIOR

prior.mu = 0;
prior.sd = sqrt(2);
prior.a = 0;
prior.b = 1;

prior.transforms.index = [2];
prior.transforms.type = optimiDefaultConstraint('positive');
prior.nParams = 2;
prior.isBounded = 1;

author: SheffieldML

repo: GPmat

save_path: github-repos/MATLAB/SheffieldML-GPmat


% This script takes in a floating point complex IQ recording containing DroneID bursts and demodulates each burst
% The steps are:
%   - Find all bursts in the file using the first ZC sequence
%   - Low pass filter each burst
%   - Adjust for frequency offset based on the offset found using the first OFDM symbol's cyclic prefix
%   - Extract each OFDM symbol
%   - Quantize/Demodulate all data carriers
%   - Validate that the first symbol XOR's to all zeros
%   - Pass XOR'd bits from all other data symbols to a C++ program that removes the LTE and rate matching
%   - Print out each frame in hex

%% Path Info
if (is_octave)
  this_script_path = fileparts(mfilename('fullpath'));
else
  this_script_path = fileparts(matlab.desktop.editor.getActiveFilename);
end

% Create a directory to store the constellation plots for debugging
% THIS CAN BE COMMENTED OUT IF NEEDED!!!  JUST MAKE SURE TO COMMENT OUT THE `saveas` CALL LATER AS WELL
mkdir(fullfile(this_script_path, "images"));

turbo_decoder_path = fullfile(this_script_path, filesep, '..', filesep, '..', filesep, 'cpp', filesep, 'remove_turbo');
if (~ isfile(turbo_decoder_path))
    error("Could not find Turbo decoder application at '%s'.  Check that the program has been compiled",...
        turbo_decoder_path);
end

%% File Parameters
enable_plots = true;        % Set to false to prevent the plots from popping up
correlation_threshold = 0.7; % The SNR is pretty good, so using a high correlation score (must be between 0.0 and 1.0)
chunk_size = 10e6;           % Number of samples to process at a time
enable_equalizer = true;     % Enable/disable the frequency domain equalizer

%% Paramters that the user must change
sample_type = 'single';
file_path = 'YOUR_FILE_NAME_HERE';
file_sample_rate = YOUR_SAMPLE_RATE_HERE;
file_freq_offset = 0e6;

%% Low Pass Filter Setup
signal_bandwidth = 10e6; % The actual occupied bandwidth of the DroneID signal
filter_tap_count = 50;   % Number of filter taps to use for the low pass filter
filter_taps = fir1(filter_tap_count, signal_bandwidth/file_sample_rate); % Create the low pass filter taps

%% Burst Extraction
[long_cp_len, short_cp_len] = get_cyclic_prefix_lengths(file_sample_rate);
cyclic_prefix_schedule = [
    long_cp_len, ...
    short_cp_len, ...
    short_cp_len, ...
    short_cp_len, ...
    short_cp_len, ...
    short_cp_len, ...
    short_cp_len, ...
    short_cp_len, ...
    long_cp_len];
fft_size = get_fft_size(file_sample_rate);

% A correlation figure number of -1 will prevent plotting by the find_zc_indices_by_file function
correlation_fig_number = -1;
if (enable_plots)
    correlation_fig_number = 456;
end

% Making sure that the bursts that are extracted have enough padding for the low pass filter to start up and terminate
bursts = extract_bursts_from_file(file_path, file_sample_rate, file_freq_offset, correlation_threshold, chunk_size,...
    filter_tap_count, 'SampleType', sample_type, 'CorrelationFigNum', correlation_fig_number);

assert(~isempty(bursts), "Did not find any bursts");

frames = {};

% Get a list of the indices from the shifted FFT outputs that contain data carriers
data_carrier_indices = get_data_carrier_indices(file_sample_rate);

% Initial value for the second LFSR in the scrambler
scrambler_x2_init = fliplr([0 0 1, 0 0 1 0, 0 0 1 1, 0 1 0 0, 0 1 0 1, 0 1 1 0, 0 1 1 1, 1 0 0 0]);

% This determines which OFDM symbol's cyclic prefix is used to determine the coarse frequency offset.  Some drones use 9
% OFDM symbols, and some use 8.  It seems that those drones that use 8 OFDM symbols have a short cyclic prefix in the
% first symbol.  Skipping the first symbol for those drones that have 9 OFDM symbols results in the new "first" symbol
% having a short cyclic prefix as well.  So, since the burst extractor always assumes that there are 9 symbols, the
% first symbol is skipped for the purposes of coarse CFO.  The second symbol is assumed to have a short cyclic prefix
cfo_estimation_symbol_idx = 2;

%% Burst Processing
for burst_idx=1:size(bursts, 1)
    % Get the next burst
    burst = bursts(burst_idx,:);

    if (enable_plots)
        figure(43);
        subplot(2, 1, 1);
        plot(10 * log10(abs(burst).^2));
        title('Time domain abs^2 10log10 (original)');

        % Plot the FFT, but average it with a single pole IIR filter to make it smoother
        figure(1000);
        fft_bins = 10 * log10(abs(fftshift(fft(burst))).^2);
        running = fft_bins(1);
        beta = 0.06;
        for idx = 2:length(fft_bins)
            running = (running * (1 - beta)) + (fft_bins(idx) * beta);
            fft_bins(idx) = running;
        end
        x_axis = file_sample_rate / 2 * linspace(-1, 1, length(burst));
        plot(x_axis, fft_bins);
        title('Frequency Spectrum (averaged)');
        grid on;
    end

    %% Find Integer Frequency Offset

    % Exploiting the fact that during the first ZC sequence the DC carrier will be much lower in amplitude than the
    % surrounding samples.  Steps:
    %   1. Extract just the time domain samples used in the first ZC sequence
    %   2. Interpolate those time domain samples to increase the frequency resolution of the measurement
    %   3. Get the power spectrum (abs squared of the FFT)
    %   4. Look N elements around the center of the FFT for the lowest point (this is the center of the signal)
    %   5. Calculate how far off from 0 Hz the lowest bin was, and frequency shift the upsampled signal by that value
    %   6. Decimate the samples back to the original sample rate for further processing

    % Calculate the first sample index for the first ZC sequence (skipping the cyclic prefix)
    offset = sum(cyclic_prefix_schedule(1:4)) + (fft_size * 3) + filter_tap_count;

    % Upsample (interpolate and filter) the ZC sequence samples
    interp_rate = 10;
    burst = resample(burst, interp_rate, 1);

    % Extract out just the samples for the first ZC sequence
    zc_samples = burst((offset * interp_rate):(offset * interp_rate) + (fft_size * interp_rate) - 1);

    % Convert the time domain ZC sequence samples to the frequency domain
    fft_bins = 10 * log10(abs(fftshift(fft(zc_samples))).^2);

    % Loop for the lowest bin in the middle of the frequency domain spectrum
    bin_count = 15; % How far left and right to look for the lowest carrier

    % Set all of the FFT bins on the outside to infinity so they can't possibly be the minimum value
    fft_bins(1:(fft_size * interp_rate / 2) - bin_count) = Inf;
    fft_bins((fft_size * interp_rate / 2) + bin_count - 1:end) = Inf;

    % Find the index of the FFT bin with the lowest amplitude
    [~, center_offset] = min(fft_bins);

    % Calculate the frequency needed to correct the integer offset, then conver that to radians
    integer_offset = ((fft_size * interp_rate / 2) - center_offset + 1) * 15e3;
    radians = 2 * pi * integer_offset / (file_sample_rate * interp_rate);

    % Apply a frequency adjustment
    burst = burst .* exp(1j * radians * [0:length(burst) - 1]);

    % Downsample (filter and decimate) the burst samples
    burst = resample(burst, 1, interp_rate);

    %% Apply low pass filter
    burst = filter(filter_taps, 1, burst);

    if (enable_plots)
        figure(43);
        subplot(2, 1, 2);
        plot(10 * log10(abs(burst).^2));
        title('Time domain abs^2 10log10 (filtered)')
    end

    %% Interpolate and find the true starting sample offset
    interp_factor = 1;
    burst = resample(burst, interp_factor, 1);
    true_start_index = find_sto_cp(burst, file_sample_rate * interp_factor);
    burst = resample(burst(true_start_index:end), 1, interp_factor);

    % Plot cyclic prefixes overlayed with the replica from the end of the OFDM symbol
    if (enable_plots)
        offset = 1;
        figure(7777);
        for cp_idx=1:length(cyclic_prefix_schedule)
            subplot(3, 3, cp_idx);
            symbol = burst(offset:offset + cyclic_prefix_schedule(cp_idx) + fft_size - 1);
            left = symbol(1:cyclic_prefix_schedule(cp_idx));
            right = symbol(end - cyclic_prefix_schedule(cp_idx) + 1:end);
            plot(abs(left));
            hold on
            plot(abs(right));
            hold off;
            title(['Cyclic Prefix Overlay ', mat2str(cp_idx)]);

            offset = offset + length(symbol);
        end
    end

    %% Coarse frequency offset adjustment using one of the OFDM symbols (see coarse_cfo_symbol_sample_offset definition)

    % Get the expected starting index of the symbol to be used for CFO estimation
    zc_start = long_cp_len + (fft_size * 3) + (short_cp_len * 3);

    % Extract out the full OFDM symbol (cyclic prefix included)
    cfo_est_symbol = burst(zc_start - short_cp_len:zc_start + fft_size - 1);

    % Get the cyclic prefix, and then the copy of the cyclic prefix that exists at the end of the OFDM symbol
    cyclic_prefix = cfo_est_symbol(1:short_cp_len);
    symbol_tail = cfo_est_symbol(end - short_cp_len + 1:end);

    skip = 0;
    cyclic_prefix = cyclic_prefix(skip+1:end-skip);
    symbol_tail = symbol_tail(skip+1:end-skip);

    % Calculate the frequency offset by taking the dot product of the two copies of the cyclic prefix and dividing out
    % the number of samples in between each cyclic prefix sample (the FFT size)
    offset_radians = angle(dot(cyclic_prefix, symbol_tail)) / fft_size;
    offset_hz = offset_radians * file_sample_rate / (2 * pi);

    if (enable_plots)
        figure(999);
        plot(abs(cyclic_prefix).^2);
        hold on;
        plot(abs(symbol_tail).^2, '*-', 'Color', 'red');
        hold off;
        title('Cyclic Prefix Overlay - CFO Estimate')
    end

    % Apply the inverse of the estimated frequency offset back to the signal
    burst = burst .* exp(1j * -offset_radians * [1:length(burst)]);

    %% OFDM Symbol Processing

    % Extract the individual OFDM symbols without the cyclic prefix for both time and frequency domains
    [time_domain_symbols, freq_domain_symbols] = extract_ofdm_symbol_samples(burst, file_sample_rate);

    % Calculate the channel for both of the ZC sequnces
    channel1 = calculate_channel(freq_domain_symbols(4,:), file_sample_rate, 4);
    channel2 = calculate_channel(freq_domain_symbols(6,:), file_sample_rate, 6);

    % Only select the data carriers from each channel estimate
    channel1 = channel1(data_carrier_indices);
    channel2 = channel2(data_carrier_indices);

    % Calculate the average phase offset of each channel estimate
    channel1_phase = sum(angle(channel1)) / length(data_carrier_indices);
    channel2_phase = sum(angle(channel2)) / length(data_carrier_indices);

    % This doesn't seem right, but taking the difference of the two channels and dividing by two yields the average
    % walking phase offset between the two.  That value can be used to correct for the phase offsets caused by not being
    % exactly spot on with the true first sample
    channel_phase_adj = (channel1_phase - channel2_phase) / 2;

    if (enable_plots)
        figure(441);
        subplot(2, 1, 1);
        plot(abs(channel1).^2, '-');
        title('ZC Sequence 1 Channel')
        subplot(2, 1, 2);
        plot(abs(channel2).^2, '-');
        title('ZC Sequence 2 Channel')
    end

    % Only use the fisrt ZC sequence to do the initial equaliztion.  Trying to use the average of both ends up with
    % strange outliers in the constellation plot
    channel = channel1;

    % Place to store the demodulated bits
    bits = zeros(9, 1200);

    % Walk through each OFDM symbol and extract the data carriers and demodulate the QPSK inside
    % This is done for symbols 4 and 6 even though they contain ZC sequences.  It's just to keep the logic clean

    for idx=1:size(bits, 1)
        data_carriers = freq_domain_symbols(idx,data_carrier_indices);

        if (enable_equalizer)
            % Equalize just the data carriers
            data_carriers = data_carriers .* channel;
        end

        % Demodulate/quantize the QPSK to bits
        bits(idx,:) = quantize_qpsk(data_carriers);

        if (enable_plots)
            figure(1);
            subplot(3, 3, idx);
            plot(data_carriers, 'o');
            title(['Symbol ', mat2str(idx), ' IQ']);

            figure(111);
            subplot(3, 3, idx);
            plot(10 * log10(abs(time_domain_symbols(idx,:)).^2), '-');
            title(['Symbol ', mat2str(idx), ' Time Domain']);

            figure(112);
            subplot(3, 3, idx);
            plot(10 * log10(abs(freq_domain_symbols(idx,:)).^2));
            title(['Symbol ', mat2str(idx), ' Freq Domain']);
        end
    end

    if (enable_plots)
        % Save the constellation plots to disk for debugging
        % THIS CAN BE COMMENTED OUT IF NEEDED
        png_path = sprintf('%s/images/ofdm_symbol_%d.png', this_script_path, burst_idx);

        try
            saveas(gcf, png_path);
        catch
            error('Could not write out PNG file to "%s"', png_path);
        end
    end

    % The remaining bits are descrambled using the same initial value, but more bits
    second_scrambler = generate_scrambler_seq(7200, scrambler_x2_init);

    % Only descramble the remaining data symbols (ignoring the ZC sequences in 4 and 6, and the first data symbol)
    bits = bits([2,3,5,7,8,9],:);

    % Just converting the bits matrix into a vector to make XOR'ing easier
    bits = reshape(bits.', 1, []);

    % Run the actual XOR
    bits = bitxor(bits, second_scrambler);

    % Write the descrambled bits to disk as 8-bit integers
    handle = fopen("/tmp/bits", "wb");
    fwrite(handle, bits, 'int8');
    fclose(handle);

    % Run the Turbo decoder and rate matcher
    [retcode, out] = system(sprintf("%s %s", turbo_decoder_path, "/tmp/bits"));
    if (retcode ~= 0)
        warning("Failed to run the final processing step");
    end

    % Save off the hex values for the frame
    frames{burst_idx} = out;
end

% Print out all frames in hex
for idx=1:size(bursts, 1)
    frame = frames{idx};

    fprintf('FRAME: %s', frame);
end


text:
function out = getProbCube(outp, imName, numClass)
% function out = getProbCube(outp, i, numClass)
	dt = load(fullfile(outp, strcat(imName, '.mat')));
	for j = 1:size(dt.scores, 1),
		si = dt.scores(j,:);
		out(:,:,j) = si(dt.superpixels);
	end
end

author: s-gupta

repo: rgbd

save_path: github-repos/MATLAB/s-gupta-rgbd


text:
function [ screen ] = tapas_BLT_initScreen(params)
% tapas_BLT_initScreen initilaizes the screen for the BLT experiment

% Here we call some default settings for setting up Psychtoolbox
PsychDefaultSetup(2);

% Psychtoolbox has some issues in Mac which only allows us to run this
% by skipping some default tests, we might want to change that for windows
Screen('Preference', 'SkipSyncTests', 1);

% Get the screen numbers
screens = Screen('Screens');

% Draw to the external screen if avaliable
screen.number = max(screens);

% Define black and white
screen.white = WhiteIndex(screen.number);
screen.black = BlackIndex(screen.number);
screen.grey = screen.white / 2;
screen.inc = screen.white - screen.grey;

% Open an on screen window
switch params.expMode
    case 'debug'
        rectDebug = [0 0 1300 900];
        [screen.window, screen.windowRect] = PsychImaging('OpenWindow', screen.number, screen.black, rectDebug);
    case {'task', 'train_4', 'train_6'}
        [screen.window, screen.windowRect] = PsychImaging('OpenWindow', screen.number, screen.black);
end

% Get the size of the on screen window
[screen.xpixels, screen.ypixels] = Screen('WindowSize', screen.window);

% Query the frame duration
screen.ifi = Screen('GetFlipInterval', screen.window);

% Get the centre coordinate of the window
[screen.xCenter, screen.yCenter] = RectCenter(screen.windowRect);

% Set the screen size for display
screen.fit = [screen.xCenter/2.5, screen.yCenter/3, 1.6*screen.xCenter, 1.6*screen.yCenter];

% Set up alpha-blending for smooth (anti-aliased) lines
Screen('BlendFunction', screen.window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');

% Adjust the text size as specified
Screen('TextSize', screen.window, params.txt.size);

end

author: translationalneuromodeling

repo: tapas