PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kxvstdargs.m

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