PageRenderTime 91ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kkstdargs.m

http://github.com/aludnam/MATLAB
Objective C | 166 lines | 163 code | 3 blank | 0 comment | 55 complexity | 442b1a8b55c7040036ed0b43a5a6df4c MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkstdargs ' '
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kstdargs.pane file
  3. %
  4. % Parameters:
  5. % Toggle: gui 'GUI', default: 0: 'run from GUI as defined in *.pane file'
  6. % Toggle: V 'Version', default: 0: 'gives the version number of the program'
  7. % Toggle: U 'Brief Usage', default: 0: 'gives brief usage'
  8. % Toggle: usage 'Full Usage', default: 0: 'gives full usage'
  9. % Toggle: P 'Prompting', default: 0: 'interactive prompting for arguments'
  10. % OutputFile: A 'Output Answer File', optional: 'Creates an answer file'
  11. % InputFile: a 'Input Answer File', optional: 'Uses an answer file'
  12. % InputFile: ap 'Print Answer File Values', optional: 'prints answer file values'
  13. %
  14. % Example: A = kkstdargs({a, ap}, {'gui',0;'V',0;'U',0;'usage',0;'P',0;'A','';'a','';'ap',''})
  15. %
  16. % Khoros helpfile follows below:
  17. function varargout = kkstdargs(varargin)
  18. if nargin ==0
  19. Inputs={};arglist={'',''};
  20. elseif nargin ==1
  21. Inputs=varargin{1};arglist={'',''};
  22. elseif nargin ==2
  23. Inputs=varargin{1}; arglist=varargin{2};
  24. else error('Usage: [out1,..] = kkstdargs(Inputs,arglist).');
  25. end
  26. if size(arglist,2)~=2
  27. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  28. end
  29. narglist={'gui', 0;'V', 0;'U', 0;'usage', 0;'P', 0;'A', '__output';'a', '__input';'ap', '__input'};
  30. maxval={0,0,0,0,0,1,1,1};
  31. minval={0,0,0,0,0,1,1,1};
  32. istoggle=[1,1,1,1,1,1,1,1];
  33. was_set=istoggle * 0;
  34. paramtype={'Toggle','Toggle','Toggle','Toggle','Toggle','OutputFile','InputFile','InputFile'};
  35. % identify the input arrays and assign them to the arguments as stated by the user
  36. if ~iscell(Inputs)
  37. Inputs = {Inputs};
  38. end
  39. NumReqOutputs=0; nextinput=1; nextoutput=1;
  40. for ii=1:size(arglist,1)
  41. wasmatched=0;
  42. for jj=1:size(narglist,1)
  43. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  44. wasmatched = 1;
  45. was_set(jj) = 1;
  46. if strcmp(narglist{jj,2}, '__input')
  47. if (nextinput > length(Inputs))
  48. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  49. end
  50. narglist{jj,2} = 'OK_in';
  51. nextinput = nextinput + 1;
  52. elseif strcmp(narglist{jj,2}, '__output')
  53. if (nextoutput > nargout)
  54. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  55. end
  56. if (isempty(arglist{ii,2}))
  57. narglist{jj,2} = 'OK_out';
  58. else
  59. narglist{jj,2} = arglist{ii,2};
  60. end
  61. nextoutput = nextoutput + 1;
  62. if (minval{jj} == 0)
  63. NumReqOutputs = NumReqOutputs - 1;
  64. end
  65. elseif isstr(arglist{ii,2})
  66. narglist{jj,2} = arglist{ii,2};
  67. else
  68. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  69. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  70. end
  71. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  72. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  73. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  74. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  75. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  76. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  77. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  78. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  79. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  80. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  81. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  82. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  83. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  84. end
  85. end
  86. end
  87. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  88. narglist{jj,2} = arglist{ii,2};
  89. end
  90. end
  91. end
  92. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  93. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  94. end
  95. end
  96. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  97. for jj=1:size(narglist,1)
  98. if strcmp(paramtype{jj}, 'Toggle')
  99. if (narglist{jj,2} ==0)
  100. narglist{jj,1} = '';
  101. end;
  102. narglist{jj,2} = '';
  103. end;
  104. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  105. narglist{jj,1} = '';
  106. narglist{jj,2} = '';
  107. end;
  108. if strcmp(narglist{jj,2}, '__input')
  109. if (minval{jj} == 0) % meaning this input is required
  110. if (nextinput > size(Inputs))
  111. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  112. else
  113. narglist{jj,2} = 'OK_in';
  114. nextinput = nextinput + 1;
  115. end
  116. else % this is an optional input
  117. if (nextinput <= length(Inputs))
  118. narglist{jj,2} = 'OK_in';
  119. nextinput = nextinput + 1;
  120. else
  121. narglist{jj,1} = '';
  122. narglist{jj,2} = '';
  123. end;
  124. end;
  125. else
  126. if strcmp(narglist{jj,2}, '__output')
  127. if (minval{jj} == 0) % this is a required output
  128. if (nextoutput > nargout & nargout > 1)
  129. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  130. else
  131. narglist{jj,2} = 'OK_out';
  132. nextoutput = nextoutput + 1;
  133. NumReqOutputs = NumReqOutputs-1;
  134. end
  135. else % this is an optional output
  136. if (nargout - nextoutput >= NumReqOutputs)
  137. narglist{jj,2} = 'OK_out';
  138. nextoutput = nextoutput + 1;
  139. else
  140. narglist{jj,1} = '';
  141. narglist{jj,2} = '';
  142. end;
  143. end
  144. end
  145. end
  146. end
  147. if nargout
  148. varargout = cell(1,nargout);
  149. else
  150. varargout = cell(1,1);
  151. end
  152. global KhorosRoot
  153. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  154. w=['"' KhorosRoot];
  155. else
  156. if ispc
  157. w='"C:\Program Files\dip\khorosBin\';
  158. else
  159. [s,w] = system('which cantata');
  160. w=['"' w(1:end-8)];
  161. end
  162. end
  163. [varargout{:}]=callKhoros([w 'kstdargs" '],Inputs,narglist);