function [FRresultsTable, FRresults] = makeFRresultsTable(FRresults, resultsDirectory, resultsFileName, modelMetaData, tableFilename)
% Makes a table of FR results
%
% USAGE:
%
%    [FRresultsTable, FRresults] = makeFRresultsTable(FRresults, resultsDirectory, resultsFileName, modelMetaData, tableFilename)
%
% INPUT:
%    FRresults:           output of `checkRankFRdriver`
%
% OPTIONAL INPUTS:
%    resultsDirectory:    directory where output of `checkRankFRdriver` has been saved
%    resultsFileName:     filename where output of `checkRankFRdriver` has been saved
%    modelMetaData:       Cell array, where each row is metadata for one model
%                         with five columns: `species`, `version`, `fileName`, `PMID`, `doi`.
%                         See function `modelMetaData = modelCitations()`
%    tableFilename:       If provided, a the table of results is written out
%                         to a csv file, with specified filename
%
% OUTPUTS:
%    FRresultsTable:      table displaying the results of `checkRankFRdriver`
%    FRresults:           output of `checkRankFRdriver`
%
% .. Author: - Ronan M.T. Fleming 'Conditions for duality between fluxes and concentrations in biochemical networks

if isempty(FRresults)
    if ~exist('resultsFileName','var')
        %resultsFileName='FRresults_20150128T225813';
        resultsFileName='FRresults_20150130T011200';
    end
    %results directory
    if ~exist('resultsDirectory','var')
        resultsDirectory='/home/rfleming/Dropbox/modelling/results/FRresults/';
    end
    cd(resultsDirectory)
    load([resultsDirectory resultsFileName])

    nResults=length(FRresults);
    %filename order of results structure
    for k=1:nResults
        tmp=FRresults(k).modelFilename;
        FRresults(k).modelID=tmp(1:end-4);%take off .mat
    end
else
    nResults=length(FRresults);
end

%extra column and extra row for headings
FRresultsTable=cell(29,nResults+1); %todo, come back and set correct number

if exist('modelMetaData','var')
    if isempty(modelMetaData)
        clear modelMetaData;
    end
end

firstColumn=1;
k=1;
while k<=nResults
    if ~firstColumn %&& 0
        disp(FRresults(k).modelID)
    end
    i=1;
    %the results may not be in alphabetical order but the table should be
    %so find the alphabetical position in the table for result(k)
    %modelMetaData is sorted alphabetically by species
    %Each row of modelMetaData: species, modelID, PMID, doi;
    if ~firstColumn
        %search against the filename specific to each model
        if exist('modelMetaData','var')
            bool=strcmp(FRresults(k).modelID,modelMetaData(:,3));
            if any(bool)
                n=find(bool);
            end
        else
            n=k;
            warning('no metadata found for for model')
        end
    end

    if firstColumn
        FRresultsTable{i,1}='Species';
    else
        if exist('modelMetaData','var')
            FRresultsTable{i,n+1}=modelMetaData{bool,1};
        else
            FRresultsTable{i,n+1}='';
        end
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='Version';
    else
        if exist('modelMetaData','var')
            FRresultsTable{i,n+1}=modelMetaData{bool,2};
        else
            FRresultsTable{i,n+1}='';
        end
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='modelID';
    else
        if exist('modelMetaData','var')
            FRresultsTable{i,n+1}=modelMetaData{bool,3};
        else
            FRresultsTable{i,n+1}=FRresults(k).modelID;
        end
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='PMID or DOI';
    else
        if exist('modelMetaData','var')
            if ~isempty(modelMetaData{bool,4})
                %pubmed id
                FRresultsTable{i,n+1}=modelMetaData{bool,4};
            else
                %doi
                FRresultsTable{i,n+1}=modelMetaData{bool,5};
            end
        else
            FRresultsTable{i,n+1}='';
        end
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Reactants = # Rows of [S S_e]';
    else
        disp(k)
        FRresultsTable{i,n+1}=size(FRresults(k).model.S,1);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Rank of reconstruction [F,R]';
    else
        FRresultsTable{i,n+1}=FRresults(k).rankFRvanilla;
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Rank [S S_e]';
    else
        FRresultsTable{i,n+1}=FRresults(k).rankS;
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='min coefficient magnitude [S S_e]';
    else
        bool=FRresults(k).model.S~=0;
        A=abs(FRresults(k).model.S);
        FRresultsTable{i,n+1}=min(min(A(A~=0)));
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='max coefficient magnitude [S S_e]';
    else
        bool=FRresults(k).model.S~=0;
        A=abs(FRresults(k).model.S);
        FRresultsTable{i,n+1}=max(max(A(A~=0)));
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='min/max coefficient magnitude [S S_e]';
    else
        bool=FRresults(k).model.S~=0;
        A=abs(FRresults(k).model.S);
        FRresultsTable{i,n+1}=min(min(A(A~=0)))/max(max(A(A~=0)));
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Elementally balanced rows (given formulae)';
    else
        if isfield(FRresults(k).model,'balancedMetBool')
            FRresultsTable{i,n+1}=nnz(FRresults(k).model.balancedMetBool);
        else
            FRresultsTable{i,n+1}=NaN;
        end
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Stoich. consistent rows';
    else
        FRresultsTable{i,n+1}=nnz(FRresults(k).model.SConsistentMetBool);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Nontrivial stoich. consistent rows';
    else
        FRresultsTable{i,n+1}=nnz(FRresults(k).model.SConsistentMetBool & FRresults(k).model.FRuniqueRowBool & FRresults(k).model.FRnonZeroRowBool1);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Nontrivial stoich. and flux consistent rows of [F,R]';
    else
        FRresultsTable{i,n+1}=nnz(FRresults(k).model.SConsistentMetBool & FRresults(k).model.FRuniqueRowBool & FRresults(k).model.FRnonZeroRowBool1 & FRresults(k).model.fluxConsistentMetBool);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Unique stoich. and nontrivial flux consistent rows of [F,R]';
    else
        FRresultsTable{i,n+1}=nnz(FRresults(k).model.SConsistentMetBool & FRresults(k).model.FRuniqueRowBool & FRresults(k).model.FRnonZeroRowBool1 & FRresults(k).model.fluxConsistentMetBool & FRresults(k).model.FRnonZeroRowBool);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Rows of proper [F,R]';
    else
        FRresultsTable{i,n+1}=nnz(FRresults(k).model.FRrows);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='  Rank of nontrivial stoich. and flux consistent [F,R]';
    else
        FRresultsTable{i,n+1}=FRresults(k).rankFR;
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Rows of bilinear [F,R]';
    else
        FRresultsTable{i,n+1}=size(FRresults(k).model.Frb,1);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Rank of bilinear [F,R]';
    else
        FRresultsTable{i,n+1}=FRresults(k).model.rankBilinearFrRr;
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Largest connected rows of [F,R]';
    else
        FRresultsTable{i,n+1}=nnz(FRresults(k).model.largestConnectedRowsFRBool);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Exchange rows = # Rows exclusive to S_e';
    else
        FRresultsTable{i,n+1}=nnz(~FRresults(k).model.SIntMetBool);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Reactions = # Cols of [S S_e]';
    else
        FRresultsTable{i,n+1}=size(FRresults(k).model.S,2);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Exchange cols = # Cols of S_e';
    else
        FRresultsTable{i,n+1}=nnz(~FRresults(k).model.SIntRxnBool);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Elementally balanced cols';
    else
        if isfield(FRresults(k).model,'balancedRxnBool')
            FRresultsTable{i,n+1}=nnz(FRresults(k).model.balancedRxnBool);
        else
            FRresultsTable{i,n+1}=NaN;
        end
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Stoichiometrially consistent cols';
    else
        FRresultsTable{i,n+1}=nnz(FRresults(k).model.SConsistentRxnBool);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Unique and stoichiometrially consistent cols';
    else
        FRresultsTable{i,n+1}=nnz(FRresults(k).model.SConsistentRxnBool & FRresults(k).model.FRuniqueColBool);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Unique stoich. and flux consistent cols of [F;R]';
    else
        FRresultsTable{i,n+1}=nnz(FRresults(k).model.SConsistentRxnBool & FRresults(k).model.FRuniqueColBool & FRresults(k).model.fluxConsistentRxnBool);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Nontrivial stoich. and flux consistent cols of [F;R]';
    else
        FRresultsTable{i,n+1}=nnz(FRresults(k).model.SConsistentRxnBool & FRresults(k).model.FRuniqueColBool & FRresults(k).model.fluxConsistentRxnBool & FRresults(k).model.FRnonZeroColBool);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Largest connected cols of [F;R]';
    else
        FRresultsTable{i,n+1}=nnz(FRresults(k).model.largestConnectedColsFRVBool);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Cols of proper [F;R]';
    else
        FRresultsTable{i,n+1}=nnz(FRresults(k).model.FRVcols);
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Rank of proper [F;R]';
    else
        FRresultsTable{i,n+1}=FRresults(k).rankFRV;
    end
    i=i+1;
    if firstColumn
        FRresultsTable{i,1}='# Rank of vanilla [F;R]';
    else
        FRresultsTable{i,n+1}=FRresults(k).rankFRVvanilla;
    end
    i=i+1;
%     if firstColumn
%         FRresultsTable{i,1}='Coherence of S';
%     else
%         FRresultsTable{i,n+1}=FRresults(k).coherenceS;
%     end

    %now move to columns for results
    if firstColumn
        firstColumn=0;
    else
        k=k+1;
    end
end

FRresultsTable=cell2table(FRresultsTable);

if exist('tableFilename','var')
    writetable(FRresultsTable,tableFilename,'Delimiter','\t')
end


%kgextents 'Generate Geometry Representing Extents Around Data'
% This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros gextents.pane file
%
% Parameters:
% InputFile: i 'Input Data Object', required: 'input data object'
% OutputFile: o 'Output Geometry Object', required: 'output geometry object'
% MultiChoice: color 'Colors', default: 2: 'If 1, the lines will be colored white, else they will use the red, green, cyan color scheme described above'
%    Choices are:
% MultiChoice: type 'Box Type', default: 2: 'Select between one of the two box types'
%    Choices are:
% String: name 'Name ', default: 'extents box': 'The name selected here will identify the extents object in the renderer'
%
% Example: o = kgextents(i, {'i','';'o','';'color',2;'type',2;'name','extents box'})
%
% Khoros helpfile follows below:
%
%  PROGRAM
% gextents - Generate Geometry Representing Extents Around Data
%
%  DESCRIPTION
% The gextents module is used to create a geometry object depicting the
% bounds of the space occupied in R3 of the input data.
%
% If present, the location segment of the input data must be in R3
% (i.e., have X, Y and Z components), while the value portion of the
% input data may be of an arbitrary dimension.  In the instance when
% input data is provided which has no location segment, the coordinates
% used are the indeces into the (w,h,d) portion of the value segment.
% In other words, if the input data set has a value segment of size
% width=32, height=48, depth=24, elements=3, and time=N, and no location
% data is present, the resulting box would have it's two corners
% positioned at (0,0,0) and (31,47,23).
%
% Two different box types may be selected by the user.  The first type
% always results in a rectangular shaped box, regardless of the location
% data.  This box type is called a "min/max" box.  The maximum extents
% of the location (either from the explicit location data or from the
% scheme outlined above) of the data are computed, and a box is
% constructed with two corners at those locations.  The other box type
% may result in a non-rectangular box, depending upon the behavior of
% the explicit location data.
%
% The user may elect to have a "colored" box or a white box.  If we
% consider the three dimensions of the data to correspond to the logical
% variables (u,v,w), then the box will be colored so that red lines
% indicate constant (v,w); green lines indicate constant (u,w) and cyan
% lines indicate constant (u,v).
%
% The user also has the option to show the "sides" of the box as grids,
% by setting one or more of the "axis Min" and "axis Max" toggles to
% True.  For example, setting Vaxis Min to True would display the side
% of the box where v = 0.  While viewing the sides of the box, it may be
% helpful to set the "Show Bounding Box" toggle to False, which will
% remove the overall bounding box and show only the geometry for the
% sides that are currently selected.
%
% Additionally, the user may provide an explicit name (text string) for
% the resulting geometry object.  This name may be available to assist
% in object identification and manipulation in a downstream renderer,
% depending upon which one is being used.
%
%
%
%  EXAMPLES
%
%  "SEE ALSO"
%
%  RESTRICTIONS
%
%  REFERENCES
%
%  COPYRIGHT
% Copyright (C) 1996,1997 , The Regents of the University of California.  All rights reserved.
%

function varargout = kgextents(varargin)
if nargin ==0
  Inputs={};arglist={'',''};
elseif nargin ==1
  Inputs=varargin{1};arglist={'',''};
elseif nargin ==2
  Inputs=varargin{1}; arglist=varargin{2};
else error('Usage: [out1,..] = kgextents(Inputs,arglist).');
end
if size(arglist,2)~=2
  error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
 end
narglist={'i', '__input';'o', '__output';'color', 2;'type', 2;'name', 'extents box'};
maxval={0,0,0,0,0};
minval={0,0,0,0,0};
istoggle=[0,0,0,0,1];
was_set=istoggle * 0;
paramtype={'InputFile','OutputFile','MultiChoice','MultiChoice','String'};
% identify the input arrays and assign them to the arguments as stated by the user
if ~iscell(Inputs)
Inputs = {Inputs};
end
NumReqOutputs=1; nextinput=1; nextoutput=1;
  for ii=1:size(arglist,1)
  wasmatched=0;
  for jj=1:size(narglist,1)
   if strcmp(arglist{ii,1},narglist{jj,1})  % a given argument was matched to the possible arguments
     wasmatched = 1;
     was_set(jj) = 1;
     if strcmp(narglist{jj,2}, '__input')
      if (nextinput > length(Inputs))
        error(['Input ' narglist{jj,1} ' has no corresponding input!']);
      end
      narglist{jj,2} = 'OK_in';
      nextinput = nextinput + 1;
     elseif strcmp(narglist{jj,2}, '__output')
      if (nextoutput > nargout)
        error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
      end
      if (isempty(arglist{ii,2}))
        narglist{jj,2} = 'OK_out';
      else
        narglist{jj,2} = arglist{ii,2};
      end

      nextoutput = nextoutput + 1;
      if (minval{jj} == 0)
         NumReqOutputs = NumReqOutputs - 1;
      end
     elseif isstr(arglist{ii,2})
      narglist{jj,2} = arglist{ii,2};
     else
        if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
            error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
        end
        if (minval{jj} ~= 0 | maxval{jj} ~= 0)
          if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
            error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
          elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
            error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
          elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
            error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
          elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
            error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
          elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
            error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
          elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
            error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
          end
        end
     end
     if ~strcmp(narglist{jj,2},'OK_out') &  ~strcmp(narglist{jj,2},'OK_in')
       narglist{jj,2} = arglist{ii,2};
     end
   end
   end
   if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
        error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
   end
end
% match the remaining inputs/outputs to the unused arguments and test for missing required inputs
 for jj=1:size(narglist,1)
     if  strcmp(paramtype{jj}, 'Toggle')
        if (narglist{jj,2} ==0)
          narglist{jj,1} = '';
        end;
        narglist{jj,2} = '';
     end;
     if  ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
          narglist{jj,1} = '';
          narglist{jj,2} = '';
     end;
     if strcmp(narglist{jj,2}, '__input')
      if (minval{jj} == 0)  % meaning this input is required
        if (nextinput > size(Inputs))
           error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
        else
          narglist{jj,2} = 'OK_in';
          nextinput = nextinput + 1;
        end
      else  % this is an optional input
        if (nextinput <= length(Inputs))
          narglist{jj,2} = 'OK_in';
          nextinput = nextinput + 1;
        else
          narglist{jj,1} = '';
          narglist{jj,2} = '';
        end;
      end;
     else
     if strcmp(narglist{jj,2}, '__output')
      if (minval{jj} == 0) % this is a required output
        if (nextoutput > nargout & nargout > 1)
           error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
        else
          narglist{jj,2} = 'OK_out';
          nextoutput = nextoutput + 1;
          NumReqOutputs = NumReqOutputs-1;
        end
      else % this is an optional output
        if (nargout - nextoutput >= NumReqOutputs)
          narglist{jj,2} = 'OK_out';
          nextoutput = nextoutput + 1;
        else
          narglist{jj,1} = '';
          narglist{jj,2} = '';
        end;
      end
     end
  end
end
if nargout
   varargout = cell(1,nargout);
else
  varargout = cell(1,1);
end
global KhorosRoot
if exist('KhorosRoot') && ~isempty(KhorosRoot)
w=['"' KhorosRoot];
else
if ispc
  w='"C:\Program Files\dip\khorosBin\';
else
[s,w] = system('which cantata');
w=['"' w(1:end-8)];
end
end
[varargout{:}]=callKhoros([w 'gextents"  '],Inputs,narglist);


% Find handle graphics object with user data check.
% Retrieves those handle graphics objects (HGOs) that have the specified
% Tag property and whose UserData property satisfies the given predicate.
%
% Input arguments:
% fcn:
%    a predicate (a function that returns a logical value) to test against
%    the HGO's UserData property
% tag (optional):
%    a string tag to restrict the set of controls to investigate
%
% See also: findobj

% Copyright 2010 Levente Hunyadi
function h = findobjuser(fcn, tag)

validateattributes(fcn, {'function_handle'}, {'scalar'});
if nargin < 2 || isempty(tag)
    tag = '';
else
    validateattributes(tag, {'char'}, {'row'});
end

%hh = get(0, 'ShowHiddenHandles');
%cleanup = onCleanup(@() set(0, 'ShowHiddenHandles', hh));  % restore visibility on exit or exception

if ~isempty(tag)
    % look among all handles (incl. hidden handles) to help findobj locate the object it seeks
    h = findobj(findall(0), '-property', 'UserData', '-and', 'Tag', tag);  % more results if multiple matching HGOs exist
else
    h = findobj(findall(0), '-property', 'UserData');
end
h = unique(h);
try
    for k=1:length(h)
        pred = fcn(get(h(k), 'UserData'));
        if isempty(pred)
            pred = false; end
        f(k) = pred;
    end
    %f = arrayfun(@(handle) fcn(get(handle, 'UserData')), h, 'UniformOutput',false);
catch
    1
end
h = h(f);


function varargout = imageProc(varargin)

% IMAGEPROC M-file for imageProc.fig
%      IMAGEPROC, by itself, creates a new IMAGEPROC or raises the existing
%      singleton*.
%
%      H = IMAGEPROC returns the handle to a new IMAGEPROC or the handle to
%      the existing singleton*.
%
%      IMAGEPROC('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in IMAGEPROC.M with the given input arguments.
%
%      IMAGEPROC('Property','Value',...) creates a new IMAGEPROC or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before imageProc_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to imageProc_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help imageProc

% Last Modified by GUIDE v2.5 15-Feb-2011 10:30:37

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @imageProc_OpeningFcn, ...
                   'gui_OutputFcn',  @imageProc_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before imageProc is made visible.
function imageProc_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to imageProc (see VARARGIN)

% Choose default command line output for imageProc
handles.fileLoaded = 0;
handles.fileLoaded2 = 0;
set(handles.axes1,'Visible','off');
set(handles.axes2,'Visible','off');
set(handles.axesHist1,'Visible','off');
set(handles.axesHist2,'Visible','off');
set(handles.editPath, 'Visible', 'off');
set(handles.editSize, 'Visible', 'off');
set(handles.editComment, 'Visible', 'off');
set(handles.textHist1, 'Visible', 'off');
set(handles.textHist2, 'Visible', 'off');
set(handles.sliderBright, 'Enable', 'off');
set(handles.sliderContrast, 'Enable', 'off');
set(handles.sliderRotate, 'Enable', 'off');
set(handles.editBright,'String', sprintf('%10s:%4.0f%%', 'Brightness', 100*get(handles.sliderBright,'Value')));
set(handles.editContrast,'String', sprintf('%10s:%4.0f%%', 'Contrast', 100*get(handles.sliderContrast,'Value')));
set(handles.editRotate,'String', sprintf('%10s:%4.0f', 'Rotate', get(handles.sliderRotate,'Value')));
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes imageProc wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = imageProc_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

% --- Executes on button press in LoadButton.
function LoadButton_Callback(hObject, eventdata, handles)
% hObject    handle to LoadButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

[FileName,PathName] = uigetfile({'*.*'},'Load Image File');

if (FileName==0) % cancel pressed
    return;
end

handles.fullPath = [PathName FileName];
[a, b, Ext] = fileparts(FileName);
availableExt = {'.bmp','.jpg','.jpeg','.tiff','.png','.gif'};
FOUND = 0;
for (i=1:length(availableExt))
    if (strcmpi(Ext, availableExt{i}))
        FOUND=1;
        break;
    end
end

if (FOUND==0)
    h = msgbox('File type not supported!','Error','error');
    return;
end

set(handles.sliderRotate, 'Enable', 'on');
set(handles.sliderBright, 'Enable', 'on');
set(handles.sliderContrast, 'Enable', 'on');
set(handles.editPath, 'Visible', 'on');
set(handles.editSize, 'Visible', 'on');
set(handles.editComment, 'Visible', 'on');

info = imfinfo(handles.fullPath);
if (~isempty(info.Comment))
    % save current image comment (to be used later in image save)
    handles.currentImageComment = info.Comment{1};
else
    handles.currentImageComment = '';
end

set(handles.editSize, 'String', sprintf('SIZE (W x H) : %d x %d', info.Width, info.Height));
set(handles.editComment, 'String', sprintf('COMMENT: %s', handles.currentImageComment));
set(handles.editPath', 'String', handles.fullPath);

RGB = imread(handles.fullPath);

handles.RGB = RGB;
handles.RGB2 = RGB;
handles.fileLoaded = 1;
handles.fileLoaded2 = 0;

set(handles.axes1,'Visible','off'); set(handles.axes2,'Visible','off');
set(handles.axesHist1,'Visible','off'); set(handles.axesHist2,'Visible','off');
set(handles.textHist1, 'Visible', 'off');
axes(handles.axesHist2); cla;
set(handles.textHist2, 'Visible', 'off');

axes(handles.axes1); cla; imshow(RGB);
axes(handles.axes2); cla;

handles = updateHistograms(handles);

guidata(hObject, handles);

% --- Executes on button press in CopyButton.
function CopyButton_Callback(hObject, eventdata, handles)
% hObject    handle to CopyButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if (handles.fileLoaded==1)
    handles.RGB2 = handles.RGB;
    axes(handles.axes2); imshow(handles.RGB2);
    handles.fileLoaded2 = 1;
    handles = updateHistograms(handles);
    guidata(hObject, handles);
else
    h = msgbox('No primary file has been loaded!','Error','error');
end

% --- Executes on button press in MedianButton.
function MedianButton_Callback(hObject, eventdata, handles)
% hObject    handle to MedianButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if (handles.fileLoaded==1)

    [M,N,ttt] = size(handles.RGB);

    RUN = 1;

    while (RUN==1)

        prompt = {'Enter Median Row Factor (0-5%):','Enter Median Column Factor (0-5%):'};
        dlg_title = 'Enter Median Parameters:';
        num_lines = 1;
        def = {'2','2'};
        answer = inputdlg(prompt,dlg_title,num_lines,def);
        if (isempty(answer))
            return;
        end

        M1 = str2num(answer{1})/100;
        M2 = str2num(answer{2})/100;

        if ((str2num(answer{1})>=0) & (str2num(answer{1})<=5)) & ((str2num(answer{2})>=0) & (str2num(answer{2})<=5))
            RUN = 0;
        end
    end

    M1 = round(M1 * M);
    M2 = round(M2 * N);

    w = waitbar(0, 'Median filtering ... Please wait ...');
    handles.RGB2(:,:,1) = medfilt2(handles.RGB(:,:,1),[M1 M2]);
    waitbar(1/3, w);
    handles.RGB2(:,:,2) = medfilt2(handles.RGB(:,:,2),[M1 M2]);
    waitbar(2/3, w);
    handles.RGB2(:,:,3) = medfilt2(handles.RGB(:,:,3),[M1 M2]);
    close(w);
    axes(handles.axes2); imshow(handles.RGB2);
    handles.fileLoaded2 = 1;
    handles = updateHistograms(handles);

    guidata(hObject, handles);
else
    h = msgbox('No primary file has been loaded!','Error','error');
end

% --- Executes on button press in SharpButton.
function SharpButton_Callback(hObject, eventdata, handles)
% hObject    handle to SharpButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if (handles.fileLoaded==1)
    H = fspecial('unsharp');
    handles.RGB2(:,:,1) = imfilter(handles.RGB(:,:,1),H,'replicate');
    handles.RGB2(:,:,2) = imfilter(handles.RGB(:,:,2),H,'replicate');
    handles.RGB2(:,:,3) = imfilter(handles.RGB(:,:,3),H,'replicate');
    axes(handles.axes2); imshow(handles.RGB2);
    handles.fileLoaded2 = 1;
    handles = updateHistograms(handles);
    guidata(hObject, handles);
else
    h = msgbox('No primary file has been loaded!','Error','error');
end

% --- Executes on button press in MotionButton.
function MotionButton_Callback(hObject, eventdata, handles)
% hObject    handle to MotionButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if (handles.fileLoaded==1)

    [M,N,ttt] = size(handles.RGB);
    D = max(M,N);

    RUN = 1;

    while (RUN==1)

        prompt = {'Enter Motion Length (0-15%):','Enter Motion Angle (0-360):'};
        dlg_title = 'Enter Motion Parameters:';
        num_lines = 1;
        def = {'1','0'};
        answer = inputdlg(prompt,dlg_title,num_lines,def);
        if (isempty(answer))
            return;
        end

        M1 = str2num(answer{1})/100;
        M2 = str2num(answer{2});

        if ((str2num(answer{1})>=0) & (str2num(answer{1})<=15))
            RUN = 0;
        end
    end

    H = fspecial('motion',D * M1,M2);
    w = waitbar(0, 'Motion filtering ... Please wait ...');
    handles.RGB2(:,:,1) = imfilter(handles.RGB(:,:,1),H,'replicate');
    waitbar(1/3, w);
    handles.RGB2(:,:,2) = imfilter(handles.RGB(:,:,2),H,'replicate');
    waitbar(2/3, w);
    handles.RGB2(:,:,3) = imfilter(handles.RGB(:,:,3),H,'replicate');
    close(w);
    axes(handles.axes2); imshow(handles.RGB2);
    handles.fileLoaded2 = 1;
    handles = updateHistograms(handles);
    guidata(hObject, handles);
else
    h = msgbox('No primary file has been loaded!','Error','error');
end

% --- Executes on button press in GrayButton.
function GrayButton_Callback(hObject, eventdata, handles)
% hObject    handle to GrayButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if (handles.fileLoaded==1)
    Gray = rgb2gray(handles.RGB);
    handles.RGB2(:,:,1) = Gray;
    handles.RGB2(:,:,2) = Gray;
    handles.RGB2(:,:,3) = Gray;
    axes(handles.axes2); imshow(handles.RGB2);
    handles.fileLoaded2 = 1;
    handles = updateHistograms(handles);
    guidata(hObject, handles);
else
    h = msgbox('No primary file has been loaded!','Error','error');
end

% --- Executes on button press in SaveButton.
function SaveButton_Callback(hObject, eventdata, handles)
% hObject    handle to SaveButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if (handles.fileLoaded2==1)
    [file,path] = uiputfile('*.jpg','Save Secondary Image As');
    imwrite(handles.RGB2,[path file],'jpg');
else
    h = msgbox('No secondary file has been loaded!','Save Error','error');
end

% --- Executes on button press in ColorsButton.
function ColorsButton_Callback(hObject, eventdata, handles)
% hObject    handle to ColorsButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if (handles.fileLoaded==1)
    RUN = 1;

    while (RUN==1)

        prompt = {'Enter threshold for RED (0-255):','Enter threshold for GREEN (0-255):','Enter threshold for BLUE (0-255):'};
        dlg_title = 'RGB Thresholds:';
        num_lines = 1;
        def = {'30','30','30'};
        answer = inputdlg(prompt,dlg_title,num_lines,def);
        if (isempty(answer))
            return;
        end
        T1 = str2num(answer{1});
        T2 = str2num(answer{2});
        T3 = str2num(answer{3});

        if ((T1>=0) & (T1<=256)) & ((T2>=0) && (T2<=256)) & ((T3>=0) && (T3<=256))
            RUN = 0;
        end
    end

    handles.RGB2 = filterColors(handles.RGB, T1, T2, T3, 5);
    axes(handles.axes2); imshow(handles.RGB2);
    handles.fileLoaded2 = 1;
    handles = updateHistograms(handles);

    guidata(hObject, handles);
else
    h = msgbox('No primary file has been loaded!','Error','error');
end

% --- Executes on button press in ColorButton2.
function ColorButton2_Callback(hObject, eventdata, handles)
% hObject    handle to ColorButton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if (handles.fileLoaded==1)
    RUN = 1;

    while (RUN==1)

        prompt = {'Enter weight for RED (0-200%):','Enter weight for GREEN (0-200%):','Enter weight for BLUE (0-200%):'};
        dlg_title = 'Enter Color Weight Parameters:';
        num_lines = 1;
        def = {'100','100','100'};
        answer = inputdlg(prompt,dlg_title,num_lines,def);
        if (isempty(answer))
            return;
        end
        W1 = str2num(answer{1});
        W2 = str2num(answer{2});
        W3 = str2num(answer{3});

        if ((W1>=0) & (W1<=200)) & ((W2>=0) && (W2<=200)) & ((W3>=0) && (W3<=200))
            RUN = 0;
        end
    end

    handles.RGB2 = handles.RGB;
    R = double(handles.RGB2(:,:,1));
    G = double(handles.RGB2(:,:,2));
    B = double(handles.RGB2(:,:,3));

    R = R * W1 ./ 100;
    G = G * W2 ./ 100;
    B = B * W3 ./ 100;

    R(find(R>256)) = 256;
    G(find(G>256)) = 256;
    B(find(B>256)) = 256;

    handles.RGB2(:,:,1) = R;
    handles.RGB2(:,:,2) = G;
    handles.RGB2(:,:,3) = B;

    axes(handles.axes2); imshow(handles.RGB2);
    handles.fileLoaded2 = 1;
    handles = updateHistograms(handles);
    guidata(hObject, handles);
else
    h = msgbox('No primary file has been loaded!','Error','error');
end

% --- Executes on button press in InvColorButton.
function InvColorButton_Callback(hObject, eventdata, handles)
% hObject    handle to InvColorButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if (handles.fileLoaded==1)

    R = double(handles.RGB(:,:,1));
    G = double(handles.RGB(:,:,2));
    B = double(handles.RGB(:,:,3));

    handles.RGB2(:,:,1) = 256 - R;
    handles.RGB2(:,:,2) = 256 - G;
    handles.RGB2(:,:,3) = 256 - B;

    axes(handles.axes2); imshow(handles.RGB2);
    handles.fileLoaded2 = 1;
    handles = updateHistograms(handles);
    guidata(hObject, handles);
else
    h = msgbox('No primary file has been loaded!','Error','error');
end

function editSize_Callback(hObject, eventdata, handles)
% hObject    handle to editSize (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editSize as text
%        str2double(get(hObject,'String')) returns contents of editSize as a double

% --- Executes during object creation, after setting all properties.
function editSize_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editSize (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function editComment_Callback(hObject, eventdata, handles)
% hObject    handle to editComment (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editComment as text
%        str2double(get(hObject,'String')) returns contents of editComment as a double

% --- Executes during object creation, after setting all properties.
function editComment_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editComment (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function editPath_Callback(hObject, eventdata, handles)
% hObject    handle to editPath (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editPath as text
%        str2double(get(hObject,'String')) returns contents of editPath as a double

% --- Executes during object creation, after setting all properties.
function editPath_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editPath (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on slider movement.
function sliderBright_Callback(hObject, eventdata, handles)
% hObject    handle to sliderBright (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.editBright,'String', sprintf('%10s:%4.0f%%', 'Brightness', 100*get(handles.sliderBright,'Value')));

% --- Executes during object creation, after setting all properties.
function sliderBright_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sliderBright (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end

% --- Executes on slider movement.
function sliderContrast_Callback(hObject, eventdata, handles)
% hObject    handle to sliderContrast (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.editContrast,'String', sprintf('%10s:%4.0f%%', 'Contrast', 100*get(handles.sliderContrast,'Value')));

% --- Executes during object creation, after setting all properties.
function sliderContrast_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sliderContrast (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end

function editBright_Callback(hObject, eventdata, handles)
% hObject    handle to editBright (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editBright as text
%        str2double(get(hObject,'String')) returns contents of editBright as a double

% --- Executes during object creation, after setting all properties.
function editBright_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editBright (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function editContrast_Callback(hObject, eventdata, handles)
% hObject    handle to editContrast (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editContrast as text
%        str2double(get(hObject,'String')) returns contents of editContrast as a double

% --- Executes during object creation, after setting all properties.
function editContrast_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editContrast (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in pushbuttonContrastBrightness.
function pushbuttonContrastBrightness_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonContrastBrightness (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if (handles.fileLoaded==1)
    handles.RGB2 = changeBrightness(handles.RGB, get(handles.sliderBright, 'Value'), get(handles.sliderContrast, 'Value'));
    axes(handles.axes2); imshow(handles.RGB2);
    handles.fileLoaded2 = 1;
    handles = updateHistograms(handles);
    guidata(hObject, handles);
else
    h = msgbox('No primary file has been loaded!','Error','error');
end

function handlesNew = updateHistograms(handles)
handlesNew = handles;
if (handles.fileLoaded == 1)
    set(handles.textHist1, 'Visible', 'on');
    axes(handlesNew.axesHist1);
    cla;
    ImageData1 = reshape(handlesNew.RGB(:,:,1), [size(handlesNew.RGB, 1) * size(handlesNew.RGB, 2) 1]);
    ImageData2 = reshape(handlesNew.RGB(:,:,2), [size(handlesNew.RGB, 1) * size(handlesNew.RGB, 2) 1]);
    ImageData3 = reshape(handlesNew.RGB(:,:,3), [size(handlesNew.RGB, 1) * size(handlesNew.RGB, 2) 1]);
    [H1, X1] = hist(ImageData1, 1:5:256);
    [H2, X2] = hist(ImageData2, 1:5:256);
    [H3, X3] = hist(ImageData3, 1:5:256);
    hold on;
    plot(X1, H1, 'r');
    plot(X2, H2, 'g');
    plot(X3, H3, 'b');
    axis([0 256 0 max([H1 H2 H3])]);
end
if (handlesNew.fileLoaded2 == 1)
    set(handles.textHist2, 'Visible', 'on');
    axes(handlesNew.axesHist2);
    cla;
    ImageData1 = reshape(handlesNew.RGB2(:,:,1), [size(handlesNew.RGB2, 1) * size(handlesNew.RGB2, 2) 1]);
    ImageData2 = reshape(handlesNew.RGB2(:,:,2), [size(handlesNew.RGB2, 1) * size(handlesNew.RGB2, 2) 1]);
    ImageData3 = reshape(handlesNew.RGB2(:,:,3), [size(handlesNew.RGB2, 1) * size(handlesNew.RGB2, 2) 1]);
    [H1, X1] = hist(ImageData1, 1:5:256);
    [H2, X2] = hist(ImageData2, 1:5:256);
    [H3, X3] = hist(ImageData3, 1:5:256);
    hold on;
    plot(X1, H1, 'r');
    plot(X2, H2, 'g');
    plot(X3, H3, 'b');
    axis([0 256 0 max([H1 H2 H3])]);
end

% --- Executes on button press in RotateButton.
function RotateButton_Callback(hObject, eventdata, handles)
% hObject    handle to RotateButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

handles.RGB2 = imrotate(handles.RGB, round(get(handles.sliderRotate,'Value')));
handles.fileLoaded = 1;

axes(handles.axes2); cla; imshow(handles.RGB2);

handles = updateHistograms(handles);

guidata(hObject, handles);

% --- Executes on slider movement.
function sliderRotate_Callback(hObject, eventdata, handles)
% hObject    handle to sliderRotate (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
set(handles.editRotate,'String', sprintf('%10s:%4.0f', 'Rotate', round(get(handles.sliderRotate,'Value'))));

% --- Executes during object creation, after setting all properties.
function sliderRotate_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sliderRotate (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end

function editRotate_Callback(hObject, eventdata, handles)
% hObject    handle to editRotate (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of editRotate as text
%        str2double(get(hObject,'String')) returns contents of editRotate as a double

% --- Executes during object creation, after setting all properties.
function editRotate_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editRotate (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function options = opticheckset(Names,Defaults,checkfun,varargin)
%OPTICHECKSET  Default Algorithm for dealing with solver option setting

%   Copyright (C) 2013 Jonathan Currie (I2C2)

%Transpose as required
if(size(Names,2) > 1), Names = Names'; end
if(size(Defaults,2) > 1), Defaults = Defaults'; end

%Collect Sizes and lowercase matches
m = size(Names,1);
numberargs = numel(varargin);
%Create structure with all names and default values
st = [Names,Defaults]'; options = struct(st{:});

% Check we have char or structure input. If structure, insert arguments
i = 1;
while i <= numberargs
    arg = varargin{i};
    if ischar(arg)
        break;
    end
    if ~isempty(arg)
        if ~isa(arg,'struct')
            error('An argument was supplied that wasn''t a string or struct!');
        end
        for j = 1:m
            if any(strcmp(fieldnames(arg),Names{j,:}))
                val = arg.(Names{j,:});
            else
                val = [];
            end
            if ~isempty(val)
                checkfun(Names{j,:},val);
                options.(Names{j,:}) = val;
            end
        end
    end
    i = i + 1;
end

%Check we have even number of args left
if rem(numberargs-i+1,2) ~= 0
    error('You do not have a value specified for each field!');
end

%Go through each argument pair and assign to correct field
expectval = 0; %first arg is a name
while i <= numberargs
    arg = varargin{i};
    switch(expectval)
        case 0 %field
            if ~ischar(arg)
                error('Expected fieldname (argument %d) to be a string!',i);
            end
            j = find(strcmp(arg,Names) == 1);
            if isempty(j)  % if no matches
                error('Unrecognised parameter ''%s''',arg);
            elseif(length(j) > 1)
                error('Ambiguous parameter ''%s''',arg);
            end
            expectval = 1; %next arg is a value
        case 1
            if(~isempty(arg))
                if(ischar(arg)), arg = lower(arg); end
                checkfun(Names{j,:},arg);
                options.(Names{j,:}) = arg;
            end
            expectval = 0;
    end
    i = i + 1;
end

if expectval %fallen off end somehow
    error('Missing value for final argument ''%s''',arg);
end


function test_issue1585

% WALLTIME 00:10:00
% MEM 2gb
% DEPENDENCY ft_read_header ft_read_data ft_read_event

%%

cd(dccnpath('/home/common/matlab/fieldtrip/data/test/issue1585'))

% cfg = [];
% cfg.dataset      = 'eeglab_data.mat';
% cfg.datatype     = 'eeg';

% cfg.headerformat = 'eeglab_set';
% cfg.dataformat   = 'eeglab_set';
% cfg.eventformat  = 'eeglab_set';
%
% cfg.method    = 'convert';
% cfg.bidsroot  = './bids';
% cfg.sub       = '001';
% cfg.task      = 'whatever';
% data2bids(cfg);

% after creating the BIDS dataset, I used a text editor to remove a row from the channels.tsv

%%

try
  % this should give an error
  hdr = ft_read_header('bids/sub-001/eeg/sub-001_task-whatever_eeg.eeg', 'readbids', 'yes');
  dat = ft_read_data('bids/sub-001/eeg/sub-001_task-whatever_eeg.eeg', 'readbids', 'yes');
  evt = ft_read_event('bids/sub-001/eeg/sub-001_task-whatever_eeg.eeg', 'readbids', 'yes');
  failed = false;
catch
  failed = true;
end
assert(failed, 'it should have failed');

% this should give a warning
hdr = ft_read_header('bids/sub-001/eeg/sub-001_task-whatever_eeg.eeg', 'readbids', 'ifmakessense');
dat = ft_read_data('bids/sub-001/eeg/sub-001_task-whatever_eeg.eeg', 'readbids', 'ifmakessense');
evt = ft_read_event('bids/sub-001/eeg/sub-001_task-whatever_eeg.eeg', 'readbids', 'ifmakessense');

% this should work without any complaints
hdr = ft_read_header('bids/sub-001/eeg/sub-001_task-whatever_eeg.eeg', 'readbids', 'no');
dat = ft_read_data('bids/sub-001/eeg/sub-001_task-whatever_eeg.eeg', 'readbids', 'no');
evt = ft_read_event('bids/sub-001/eeg/sub-001_task-whatever_eeg.eeg', 'readbids', 'no');


% Plot the aircraft's geometry setup.
% Example call: plotAircraftGeometry('ExperimentalCarrier', 'State_1.5alpha_12.5ms.mat', 'F:\svn\dev\matlab\tornado\T135_export');

% @
% Copyright (C) 2017 Jonas Ruesch
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program.  If not, see <http://www.gnu.org/licenses/>.
% @

function plotAircraftGeometry(aircraft_geometry_filename, state, tornado_root_directory)

currDir = pwd;

cd(tornado_root_directory);
settings=config('startup');

% Load the aircraft
cd(settings.acdir)
load(aircraft_geometry_filename); % aircraft geometry is now in variable 'geo'.

cd(tornado_root_directory)

% Generate the Lattice
latticetype=0; % Tornado lattice type
[lattice,ref]=fLattice_setup2(geo,state,latticetype);

%  Plot the geometry
geometryplot(lattice,geo,ref);
%bodyplot(body);

% back to the original directory
cd(currDir);


function ma_handlePlayButton(handles, frameRate)
%ma_handlePlayButton Summary of this function goes here
%   Detailed explanation goes here
    global GLOBAL_VideoWriter GLOBAL_isRecording;
    persistent mTimer;

    if(get(handles.playButton,'Value')==1)
        set(handles.playButton,'String','<html>■');
        delete(mTimer);

        maData = getappdata(handles.ma_MainGUI,'ma_data');
        celBodyData = getappdata(handles.ma_MainGUI,'celBodyData');
        stateLog = maData.stateLog;

        time = get(handles.movieFrameSlider,'Value');
        [orbitToPlot] = ma_getOrbitToPlot(stateLog, time);

        hold(handles.movieAxes,'on');
        period = 1/frameRate;
        period = round(period*1000)/1000;
        tFunc = @(obj,event) ma_playMovieTimerCallback(obj, event, handles.playButton, handles.ma_MissionAnimatorGUI, handles.movieAxes, maData, frameRate, celBodyData, handles);
        mTimer = timer('TimerFcn',tFunc,'Period',period,'ExecutionMode','fixedRate','UserData',[NaN, NaN, orbitToPlot]);
        hold(handles.movieAxes,'off');

        if(GLOBAL_isRecording)
            GLOBAL_VideoWriter.FrameRate = frameRate;
            open(GLOBAL_VideoWriter);
        end

        drawnow;
        start(mTimer);
    else
        set(handles.playButton,'String','<html>&#9658');

        if(GLOBAL_isRecording)
            try
                close(GLOBAL_VideoWriter);
            catch
                %no action
            end
            GLOBAL_isRecording = false;
            GLOBAL_VideoWriter = [];
        end
        drawnow;
    end
end


%
%   FILE NAME:    integrateRxnAssocViaIDsAndMets.m
%
%   PURPOSE: Integrate rxn associations from mets and external rxn ids
%

load('MNXRxns.mat');          % load MNX reactions
load('mergedModel.mat');      % load mergedModel
load('mapRxnResults.mat');    % load automatic rxn association via mets

% Treat the MNX assoc overlapped by rxn-ids and via mets as confirmed
mergedModel.confirmedMNXID=cell(numel(mergedModel.rxns),1);
mergedModel.confirmedMNXID(:)={''};
mergedModel.confirmedFilteredMNXID=cell(numel(mergedModel.rxns),1);
mergedModel.confirmedFilteredMNXID(:)={''};
mergedModel.unResolved=zeros(numel(mergedModel.rxns),1);

numUnresloved=0;
numConfirmed=0;
numToCheck=0;
for i=1:length(mergedModel.rxns)
		if ~isempty(mergedModel.rxnAssocMNXID{i}) || ~isempty(results.rxnMNXID{i})
				overlap=intersect(mergedModel.rxnAssocMNXID{i},results.rxnMNXID{i});

				if ~isempty(overlap)
						numConfirmed=numConfirmed+1;
						mergedModel.confirmedMNXID{i}=overlap;
						mergedModel.confirmedFilteredMNXID{i}=filterBalancedRxns(overlap,MNXRxns);
				else
						numToCheck=numToCheck+1;
				end

		else  % These rxns have no association both by rxn-ids and mets
				numUnresloved=numUnresloved+1;
				mergedModel.unResolved(i)=1;
		end
end
%numConfirmed=2506;
%numUnresloved=726;
%numToCheck=739;

% Treat the cases need to be checked
filledRxnAssocViaMets.rxnHMRID=cell(1000,1);
filledRxnAssocViaMets.rxnMNXID=cell(1000,1);
filledRxnAssocViaMets.rxnFilteredMNXID=cell(1000,1);
filledRxnAssocViaMets.notes=cell(1000,1);
needToCheck.rxnHMRID=cell(1000,1);
needToCheck.rxnAssocMNXID=cell(1000,1);
needToCheck.rxnViaMetsMNXID=cell(1000,1);
needToCheck.rxnViaMetsFilteredMNXID=cell(1000,1);
needToCheck.notes=cell(1000,1);

numToCheck=0;
numFilledViaMets=0;
for i=1:numel(mergedModel.rxns)
		if ~isempty(mergedModel.rxnAssocMNXID{i}) || ~isempty(results.rxnMNXID{i})
				overlap=intersect(mergedModel.rxnAssocMNXID{i},results.rxnMNXID{i});
				if isempty(overlap)
						if ~isempty(mergedModel.rxnAssocMNXID{i})
								numToCheck=numToCheck+1;
								needToCheck.rxnHMRID{numToCheck}=mergedModel.rxns{i};
								needToCheck.rxnAssocMNXID{numToCheck}=mergedModel.rxnAssocMNXID{i};
								needToCheck.notes{numToCheck}=results.notes{i};

								% Both have assoc, but non-overlap (202) could be caused by wrong assoc by rxn-ids
								if ~isempty(results.rxnMNXID{i})
										needToCheck.rxnViaMetsMNXID{numToCheck}=results.rxnMNXID{i};
										needToCheck.rxnViaMetsFilteredMNXID{numToCheck}=filterBalancedRxns(results.rxnMNXID{i},MNXRxns);

								% No assoc via mets, keep origianl ones (248) Check the manual curation
								else
										needToCheck.rxnViaMetsMNXID{numToCheck}='';
										needToCheck.rxnViaMetsFilteredMNXID{numToCheck}='';
								end

						% No rxn assoc, fill by assoc via mets (prefer to true type) (296)
						else
								numFilledViaMets=numFilledViaMets+1;
								filledRxnAssocViaMets.rxnHMRID{numFilledViaMets}=mergedModel.rxns{i};
								filledRxnAssocViaMets.rxnMNXID{numFilledViaMets}=results.rxnMNXID{i};
								filledRxnAssocViaMets.rxnFilteredMNXID{numFilledViaMets}=filterBalancedRxns(results.rxnMNXID{i},MNXRxns);
								filledRxnAssocViaMets.notes{numFilledViaMets}=results.notes{i};
						end
				end
		end
end
%numToCheck=444;
%numFilledViaMets=295;

needToCheck.rxnHMRID=needToCheck.rxnHMRID(1:numToCheck);
needToCheck.rxnAssocMNXID=needToCheck.rxnAssocMNXID(1:numToCheck);
needToCheck.rxnViaMetsMNXID=needToCheck.rxnViaMetsMNXID(1:numToCheck);
needToCheck.rxnViaMetsFilteredMNXID=needToCheck.rxnViaMetsFilteredMNXID(1:numToCheck);
needToCheck.notes=needToCheck.notes(1:numToCheck);

filledRxnAssocViaMets.rxnHMRID=filledRxnAssocViaMets.rxnHMRID(1:numFilledViaMets);
filledRxnAssocViaMets.rxnMNXID=filledRxnAssocViaMets.rxnMNXID(1:numFilledViaMets);
filledRxnAssocViaMets.rxnFilteredMNXID=filledRxnAssocViaMets.rxnFilteredMNXID(1:numFilledViaMets);
filledRxnAssocViaMets.notes=filledRxnAssocViaMets.notes(1:numFilledViaMets);

%save('mergedModel.mat','mergedModel');
%save('filledRxnAssocViaMets_20180522.mat','filledRxnAssocViaMets');
%save('needToCheck_20180522.mat','needToCheck');

%% sub functions
%Filter MNX rxns according to their balance status
function filteredMNXrxns = filterBalancedRxns(MNXrxns,mnx)

		countNum=numel(MNXrxns);
		if countNum==1  % there is only one MNX id, skip balance check
				filteredMNXrxns=MNXrxns;
		elseif countNum>1   % there are several MNX ids
				[a, b]=ismember(MNXrxns,mnx.MNX_ID);
				% The priority order of Balance status: true > NA > ambiguous
				if find(strcmp('true',mnx.Balance(b)));
						trueHits=find(strcmp('true',mnx.Balance(b)));
						filteredMNXrxns=MNXrxns(trueHits);
				elseif find(strcmp('NA',mnx.Balance(b)))
						NAHits=find(strcmp('NA',mnx.Balance(b)));
						filteredMNXrxns=MNXrxns(NAHits);
				elseif find(strcmp('ambiguous',mnx.Balance(b)))
						amHits=find(strcmp('ambiguous',mnx.Balance(b)));
						filteredMNXrxns=MNXrxns(amHits);
				else
						filteredMNXrxns=MNXrxns;
				end
		end
end


% Set the path to your trackers
path_to_your_trackers = 'E:/Database/vot-toolkit-master_HCF/tracker';

if isempty(path_to_your_trackers)
    error('Set the path to your trackers!');
end

tracker_label = 'DeepSTRCF';
tracker_command = generate_matlab_command('vot_wrapper(''DeepSTRCF'', ''DeepSTRCF_VOT_setting'')', {[path_to_your_trackers '/STRCF/']});
tracker_interpreter = 'matlab';
tracker_trax = false;


function dimNumber = getDimension(MRSIStruct, dimLabel)
    arguments
        MRSIStruct (1,1) struct
        dimLabel char
    end
    switch(lower(dimLabel))
        case 'x'
            dimNumber = MRSIStruct.dims.x;
        case 'y'
            dimNumber = MRSIStruct.dims.y;
        case 'z'
            dimNumber = MRSIStruct.dims.z;
        case 'coils'
            dimNumber = MRSIStruct.dims.coils;
        case 'averages'
            dimNumber = MRSIStruct.dims.averages;
        case 'average'
            dimNumber = MRSIStruct.dims.averages;
        case 'kx'
            dimNumber = MRSIStruct.dims.kx;
        case 'ky'
            dimNumber = MRSIStruct.dims.ky;
        case 'kz'
            dimNumber = MRSIStruct.dims.kz;
        case 'subspecs'
            dimNumber = MRSIStruct.dims.subSpecs;
        case 'subspec'
            dimNumber = MRSIStruct.dims.subSpecs;
        case 'extras'
            dimNumber = MRSIStruct.dims.extras;
        case 'extra'
            dimNumber = MRSIStruct.dims.extras;
        case 't'
            dimNumber = MRSIStruct.dims.t;
        otherwise
            error('Dimension not found %s', dimLabel);
    end
end


function data = parseDataInputs(data, pref)
%PARSEDATAINPUTS   Parse inputs from the DATA structure and assign defaults.
%   DATA = PARSEDATAINPUTS(DATA, PREF) parses inputs and options passed to the
%   constructor via its DATA argument and returns a new DATA structure with the
%   results, including defaults for any missing values.  The preferences in
%   PREF are used as necessary to determine the results.
%
%   The DATA argument to the constructor is a structure that holds all
%   additional parameters required for construction aside from the OP (the
%   function handle that is sampled or numeric data that is used to build the
%   TRIGTECH) and the constructor preferences.

% Copyright 2017 by The University of Oxford and The Chebfun Developers.
% See http://www.chebfun.org/ for Chebfun information.

if ( ~isfield(data, 'vscale') || isempty(data.vscale) )
    data.vscale = 0;
end

if ( ~isfield(data, 'hscale') || isempty(data.hscale) )
    data.hscale = 1;
end

end


function FPtable = loadFPtable(fn)
% load the lookup table from CCF to FP slices

[~, fnBase] = fileparts(fn);

fid = fopen(fn, 'r');

titles = textscan(fid, '%s%s%s%s%s%s%s%s%s%s%s', 1, 'delimiter', ',');
titles = cellfun(@(x)x{1}, titles, 'uni', false);
data = textscan(fid, '%s%s%d%d%d%d%d%d%s%s%s', 'delimiter', ',');

FPtable = table(data{:}, 'VariableNames', titles);

fclose(fid);


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_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 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 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 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 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 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;


function plot_acorr(x, lag)

error('not ready');
if nargin < 2
  lag = size(x,2);
end


function type = getCERRStructType(structS);
%"getCERRStructType"
%   Checks the fields in the passed structS and determines which cell in a
%   planC this structure was pulled from.  This determination is based on the
%   initializeCERR function's field names, so planCs with structs that do
%   not match initializeCERR's prototypes will throw a warning and return
%   [].
%
%   The output is in string form, ie 'dose', 'structures', etc.
%
%JRA 06/27/06
%
%Usage:
%   type = getCERRStructType(structS);
%
% Copyright 2010, Joseph O. Deasy, on behalf of the CERR development team.
%
% This file is part of The Computational Environment for Radiotherapy Research (CERR).
%
% CERR development has been led by:  Aditya Apte, Divya Khullar, James Alaly, and Joseph O. Deasy.
%
% CERR has been financially supported by the US National Institutes of Health under multiple grants.
%
% CERR is distributed under the terms of the Lesser GNU Public License.
%
%     This version of CERR is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
%
% CERR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
% without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% See the GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with CERR.  If not, see <http://www.gnu.org/licenses/>.

planInitC = initializeCERR;

%Get possible cell field names in a planC.
indexFields = fields(planInitC{end});

%Determine the number of cell types initializeCERR returns.
numCells = length(planInitC);

%Extract fieldnames of the passed structS
myFields = fields(structS);

%Loop over each initialized datatype and compare field names, looking for a
%match to the passed structS.
for i=1:numCells

    thisCellsFields = fields(planInitC{i});

    fieldsMatch = ismember(thisCellsFields, myFields);

    nMatchingFields(i) = sum(fieldsMatch);

end

%Find the cell that matched the most fields.
[maxNum, ind] = max(nMatchingFields);

%If more than 1 match in that top cell, assume we know the type now.
if maxNum > 1
    type = indexFields{ind};
    return;
else
   %No fields matched at all!
   warning('Structure passed to getCERRStructureType does not appear to be a valid planC structure.  Returning [].');
   type = [];
end


function varargout = tpfp(varargin)
% VL_TPFP  Compute true positives and false positives
%  This is an helper function used by VL_PR(), VL_ROC(), VL_DET().
%
%  See also: VL_PR(), VL_ROC(), VL_DET(), VL_HELP().
[varargout{1:nargout}] = vl_tpfp(varargin{:});