PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kmmul.m

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