PageRenderTime 40ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kkexprn.m

http://github.com/aludnam/MATLAB
Objective C | 197 lines | 194 code | 3 blank | 0 comment | 55 complexity | cd5abeabbaf5a479a322b3346294fc85 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkexprn 'Output = Function(Input1, Input2)'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kexprn.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 ' i1 ', required: 'input data object 1'
  6. % InputFile: i2 ' i2 ', optional: 'input data object 2'
  7. % InputFile: i3 ' i3 ', optional: 'input data object 3'
  8. % InputFile: i4 ' i4 ', optional: 'input data object 4'
  9. % InputFile: i5 ' i5 ', optional: 'input data object 5'
  10. % InputFile: i6 ' i6 ', optional: 'input data object 6'
  11. % String: expr ' ', default: ' ': 'arithmetic expression'
  12. % OutputFile: o ' o ', required: 'resulting output data object'
  13. %
  14. % Example: o = kkexprn({i1, i2, i3, i4, i5, i6}, {'i1','';'i2','';'i3','';'i4','';'i5','';'i6','';'expr',' ';'o',''})
  15. %
  16. % Khoros helpfile follows below:
  17. %
  18. % PROGRAM
  19. % kexprn - Output = Function(Input1, Input2)
  20. %
  21. % DESCRIPTION
  22. % .I kgexpr
  23. % allows you to generate
  24. % 1D, 2D, 3D, 4D, or 5D datasets of any data type. For dataset generation,
  25. % you must specify double precision "begin" and \fIend\fP values, as well
  26. % as an integer "size" value, for each of width, height, depth, time, and
  27. % elements, as relevant to the desired dimensionality of the dataset to be
  28. % created.
  29. % .PP
  30. % The function that will define the dataset is specified as:
  31. % f(w,h,d,t,e) = <expression>
  32. % Where "w, h, d, t," and \fIe\fP are double precision values ranging from
  33. % "begin" to \fIend\fP with the number of values to be generated determined by\fIsize\fP.
  34. %
  35. %
  36. %
  37. % EXAMPLES
  38. %
  39. % "SEE ALSO"
  40. %
  41. % RESTRICTIONS
  42. %
  43. % REFERENCES
  44. %
  45. % COPYRIGHT
  46. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  47. %
  48. function varargout = kkexprn(varargin)
  49. if nargin ==0
  50. Inputs={};arglist={'',''};
  51. elseif nargin ==1
  52. Inputs=varargin{1};arglist={'',''};
  53. elseif nargin ==2
  54. Inputs=varargin{1}; arglist=varargin{2};
  55. else error('Usage: [out1,..] = kkexprn(Inputs,arglist).');
  56. end
  57. if size(arglist,2)~=2
  58. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  59. end
  60. narglist={'i1', '__input';'i2', '__input';'i3', '__input';'i4', '__input';'i5', '__input';'i6', '__input';'expr', ' ';'o', '__output'};
  61. maxval={0,1,1,1,1,1,0,0};
  62. minval={0,1,1,1,1,1,0,0};
  63. istoggle=[0,1,1,1,1,1,0,0];
  64. was_set=istoggle * 0;
  65. paramtype={'InputFile','InputFile','InputFile','InputFile','InputFile','InputFile','String','OutputFile'};
  66. % identify the input arrays and assign them to the arguments as stated by the user
  67. if ~iscell(Inputs)
  68. Inputs = {Inputs};
  69. end
  70. NumReqOutputs=1; nextinput=1; nextoutput=1;
  71. for ii=1:size(arglist,1)
  72. wasmatched=0;
  73. for jj=1:size(narglist,1)
  74. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  75. wasmatched = 1;
  76. was_set(jj) = 1;
  77. if strcmp(narglist{jj,2}, '__input')
  78. if (nextinput > length(Inputs))
  79. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  80. end
  81. narglist{jj,2} = 'OK_in';
  82. nextinput = nextinput + 1;
  83. elseif strcmp(narglist{jj,2}, '__output')
  84. if (nextoutput > nargout)
  85. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  86. end
  87. if (isempty(arglist{ii,2}))
  88. narglist{jj,2} = 'OK_out';
  89. else
  90. narglist{jj,2} = arglist{ii,2};
  91. end
  92. nextoutput = nextoutput + 1;
  93. if (minval{jj} == 0)
  94. NumReqOutputs = NumReqOutputs - 1;
  95. end
  96. elseif isstr(arglist{ii,2})
  97. narglist{jj,2} = arglist{ii,2};
  98. else
  99. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  100. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  101. end
  102. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  103. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  104. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  105. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  106. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  107. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  108. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  109. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  110. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  111. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  112. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  113. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  114. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  115. end
  116. end
  117. end
  118. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  119. narglist{jj,2} = arglist{ii,2};
  120. end
  121. end
  122. end
  123. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  124. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  125. end
  126. end
  127. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  128. for jj=1:size(narglist,1)
  129. if strcmp(paramtype{jj}, 'Toggle')
  130. if (narglist{jj,2} ==0)
  131. narglist{jj,1} = '';
  132. end;
  133. narglist{jj,2} = '';
  134. end;
  135. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  136. narglist{jj,1} = '';
  137. narglist{jj,2} = '';
  138. end;
  139. if strcmp(narglist{jj,2}, '__input')
  140. if (minval{jj} == 0) % meaning this input is required
  141. if (nextinput > size(Inputs))
  142. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  143. else
  144. narglist{jj,2} = 'OK_in';
  145. nextinput = nextinput + 1;
  146. end
  147. else % this is an optional input
  148. if (nextinput <= length(Inputs))
  149. narglist{jj,2} = 'OK_in';
  150. nextinput = nextinput + 1;
  151. else
  152. narglist{jj,1} = '';
  153. narglist{jj,2} = '';
  154. end;
  155. end;
  156. else
  157. if strcmp(narglist{jj,2}, '__output')
  158. if (minval{jj} == 0) % this is a required output
  159. if (nextoutput > nargout & nargout > 1)
  160. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  161. else
  162. narglist{jj,2} = 'OK_out';
  163. nextoutput = nextoutput + 1;
  164. NumReqOutputs = NumReqOutputs-1;
  165. end
  166. else % this is an optional output
  167. if (nargout - nextoutput >= NumReqOutputs)
  168. narglist{jj,2} = 'OK_out';
  169. nextoutput = nextoutput + 1;
  170. else
  171. narglist{jj,1} = '';
  172. narglist{jj,2} = '';
  173. end;
  174. end
  175. end
  176. end
  177. end
  178. if nargout
  179. varargout = cell(1,nargout);
  180. else
  181. varargout = cell(1,1);
  182. end
  183. global KhorosRoot
  184. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  185. w=['"' KhorosRoot];
  186. else
  187. if ispc
  188. w='"C:\Program Files\dip\khorosBin\';
  189. else
  190. [s,w] = system('which cantata');
  191. w=['"' w(1:end-8)];
  192. end
  193. end
  194. [varargout{:}]=callKhoros([w 'kexprn" '],Inputs,narglist);