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

/matlab_tools/Converted/kmadd.m

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