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

/matlab_tools/Converted/kkhypot.m

http://github.com/aludnam/MATLAB
Objective C | 223 lines | 220 code | 3 blank | 0 comment | 54 complexity | 7b09f60ef13025b041a581ae894c2950 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkhypot 'Output = sqrt[(Input 1)**2 + (Input 2 or Constant)**2]'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros khypot.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Input 1', required: 'First input data object'
  6. % OutputFile: o 'Output', required: 'Resulting output data object'
  7. % InputFile: i2 'Input 2', optional: 'Second input data object'
  8. %
  9. % Example: o = kkhypot({i1, i2}, {'i1','';'o','';'i2',''})
  10. %
  11. % Khoros helpfile follows below:
  12. %
  13. % PROGRAM
  14. % khypot - Output = sqrt[(Input 1)**2 + (Input 2 or Constant)**2]
  15. %
  16. % DESCRIPTION
  17. % The "Hypotenuse" operator returns the square root of the result
  18. % produced by adding the square of each point in \fBInput 1" and the square
  19. % of either the corresponding point in \fBInput 2" or the \fBConstant\fP
  20. % value, which ever is specified by the user.
  21. %
  22. % Executing "Hypotenuse" runs the program \fIkarith2\fP with the -hypot flag.
  23. %
  24. % "Data Type - Single Input" 5
  25. % .cI $DATAMANIP/repos/shared/man/sections/value_type_1input
  26. %
  27. % "Data Type - Two Input Objects" 5
  28. % .cI $DATAMANIP/repos/shared/man/sections/value_type_2input
  29. %
  30. % "Map Data - Single Input" 5
  31. % .cI $DATAMANIP/repos/shared/man/sections/map_1input
  32. %
  33. % "Map Data - Two Input Objects" 5
  34. % .cI $DATAMANIP/repos/shared/man/sections/map_2input
  35. %
  36. % "Validity Mask" 5
  37. % .cI $DATAMANIP/repos/shared/man/sections/mask_2input
  38. %
  39. % "Input Objects of Different Sizes" 5
  40. % .cI $DATAMANIP/repos/shared/man/sections/resize_2input
  41. % The values used to pad the data when input files are not the same size are
  42. % (0.0, 0.0).
  43. %
  44. % "Explicit Location and Time Data - Single Input" 5
  45. % .cI $DATAMANIP/repos/shared/man/sections/loc_and_time_1input
  46. %
  47. % "Explicit Location and Time Data - Two Input Objects" 5
  48. % .cI $DATAMANIP/repos/shared/man/sections/loc_and_time_2input
  49. %
  50. % "Failure Modes - Single Input"
  51. % .cI $DATAMANIP/repos/shared/man/sections/fail_1input
  52. %
  53. % "Failure Modes - Two Input Objects"
  54. % .cI $DATAMANIP/repos/shared/man/sections/fail_2input
  55. %
  56. %
  57. %
  58. % EXAMPLES
  59. %
  60. % "SEE ALSO"
  61. % DATAMANIP::karith2, DATAMANIP::kcmplx2real, DATAMANIP::kmag
  62. %
  63. % RESTRICTIONS
  64. % Operations on complex data are not supported at this time. If the
  65. % input object is complex, only the real component of the data is
  66. % processed, and the output object is real. To calculate the hypotenuse,
  67. % or magnitude of a complex number, use DATAMANIP::kcmplx2real.
  68. %
  69. % REFERENCES
  70. %
  71. % COPYRIGHT
  72. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  73. %
  74. function varargout = kkhypot(varargin)
  75. if nargin ==0
  76. Inputs={};arglist={'',''};
  77. elseif nargin ==1
  78. Inputs=varargin{1};arglist={'',''};
  79. elseif nargin ==2
  80. Inputs=varargin{1}; arglist=varargin{2};
  81. else error('Usage: [out1,..] = kkhypot(Inputs,arglist).');
  82. end
  83. if size(arglist,2)~=2
  84. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  85. end
  86. narglist={'i1', '__input';'o', '__output';'i2', '__input'};
  87. maxval={0,0,1};
  88. minval={0,0,1};
  89. istoggle=[0,0,1];
  90. was_set=istoggle * 0;
  91. paramtype={'InputFile','OutputFile','InputFile'};
  92. % identify the input arrays and assign them to the arguments as stated by the user
  93. if ~iscell(Inputs)
  94. Inputs = {Inputs};
  95. end
  96. NumReqOutputs=1; nextinput=1; nextoutput=1;
  97. for ii=1:size(arglist,1)
  98. wasmatched=0;
  99. for jj=1:size(narglist,1)
  100. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  101. wasmatched = 1;
  102. was_set(jj) = 1;
  103. if strcmp(narglist{jj,2}, '__input')
  104. if (nextinput > length(Inputs))
  105. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  106. end
  107. narglist{jj,2} = 'OK_in';
  108. nextinput = nextinput + 1;
  109. elseif strcmp(narglist{jj,2}, '__output')
  110. if (nextoutput > nargout)
  111. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  112. end
  113. if (isempty(arglist{ii,2}))
  114. narglist{jj,2} = 'OK_out';
  115. else
  116. narglist{jj,2} = arglist{ii,2};
  117. end
  118. nextoutput = nextoutput + 1;
  119. if (minval{jj} == 0)
  120. NumReqOutputs = NumReqOutputs - 1;
  121. end
  122. elseif isstr(arglist{ii,2})
  123. narglist{jj,2} = arglist{ii,2};
  124. else
  125. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  126. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  127. end
  128. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  129. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  130. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  131. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  132. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  133. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  134. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  135. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  136. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  137. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  138. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  139. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  140. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  141. end
  142. end
  143. end
  144. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  145. narglist{jj,2} = arglist{ii,2};
  146. end
  147. end
  148. end
  149. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  150. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  151. end
  152. end
  153. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  154. for jj=1:size(narglist,1)
  155. if strcmp(paramtype{jj}, 'Toggle')
  156. if (narglist{jj,2} ==0)
  157. narglist{jj,1} = '';
  158. end;
  159. narglist{jj,2} = '';
  160. end;
  161. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  162. narglist{jj,1} = '';
  163. narglist{jj,2} = '';
  164. end;
  165. if strcmp(narglist{jj,2}, '__input')
  166. if (minval{jj} == 0) % meaning this input is required
  167. if (nextinput > size(Inputs))
  168. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  169. else
  170. narglist{jj,2} = 'OK_in';
  171. nextinput = nextinput + 1;
  172. end
  173. else % this is an optional input
  174. if (nextinput <= length(Inputs))
  175. narglist{jj,2} = 'OK_in';
  176. nextinput = nextinput + 1;
  177. else
  178. narglist{jj,1} = '';
  179. narglist{jj,2} = '';
  180. end;
  181. end;
  182. else
  183. if strcmp(narglist{jj,2}, '__output')
  184. if (minval{jj} == 0) % this is a required output
  185. if (nextoutput > nargout & nargout > 1)
  186. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  187. else
  188. narglist{jj,2} = 'OK_out';
  189. nextoutput = nextoutput + 1;
  190. NumReqOutputs = NumReqOutputs-1;
  191. end
  192. else % this is an optional output
  193. if (nargout - nextoutput >= NumReqOutputs)
  194. narglist{jj,2} = 'OK_out';
  195. nextoutput = nextoutput + 1;
  196. else
  197. narglist{jj,1} = '';
  198. narglist{jj,2} = '';
  199. end;
  200. end
  201. end
  202. end
  203. end
  204. if nargout
  205. varargout = cell(1,nargout);
  206. else
  207. varargout = cell(1,1);
  208. end
  209. global KhorosRoot
  210. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  211. w=['"' KhorosRoot];
  212. else
  213. if ispc
  214. w='"C:\Program Files\dip\khorosBin\';
  215. else
  216. [s,w] = system('which cantata');
  217. w=['"' w(1:end-8)];
  218. end
  219. end
  220. [varargout{:}]=callKhoros([w 'karith2" -hypot'],Inputs,narglist);