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

/matlab_tools/Converted/kkdiv.m

http://github.com/aludnam/MATLAB
Objective C | 219 lines | 219 code | 0 blank | 0 comment | 1 complexity | 4206a39f83e7e24bdbd24a48e549440c MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkdiv 'Output = Input 1 / (Input 2 or Constant)'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kdiv.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 = kkdiv({i1, i2}, {'i1','';'o','';'i2',''})
  10. %
  11. % Khoros helpfile follows below:
  12. %
  13. % PROGRAM
  14. % kdiv - Output = Input 1 / (Input 2 or Constant)
  15. %
  16. % DESCRIPTION
  17. % The "Divide" operator divides each point in \fBInput 1\fP by
  18. % either \fBInput 2" or the \fBConstant\fP value, which
  19. % ever is specified by the user.
  20. %
  21. % Executing "Divide" runs the program \fIkarith2\fP with the -div flag.
  22. %
  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. % (1.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::kdivinto
  62. %
  63. % RESTRICTIONS
  64. %
  65. % REFERENCES
  66. %
  67. % COPYRIGHT
  68. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  69. %
  70. function varargout = kkdiv(varargin)
  71. if nargin ==0
  72. Inputs={};arglist={'',''};
  73. elseif nargin ==1
  74. Inputs=varargin{1};arglist={'',''};
  75. elseif nargin ==2
  76. Inputs=varargin{1}; arglist=varargin{2};
  77. else error('Usage: [out1,..] = kkdiv(Inputs,arglist).');
  78. end
  79. if size(arglist,2)~=2
  80. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  81. end
  82. narglist={'i1', '__input';'o', '__output';'i2', '__input'};
  83. maxval={0,0,1};
  84. minval={0,0,1};
  85. istoggle=[0,0,1];
  86. was_set=istoggle * 0;
  87. paramtype={'InputFile','OutputFile','InputFile'};
  88. % identify the input arrays and assign them to the arguments as stated by the user
  89. if ~iscell(Inputs)
  90. Inputs = {Inputs};
  91. end
  92. NumReqOutputs=1; nextinput=1; nextoutput=1;
  93. for ii=1:size(arglist,1)
  94. wasmatched=0;
  95. for jj=1:size(narglist,1)
  96. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  97. wasmatched = 1;
  98. was_set(jj) = 1;
  99. if strcmp(narglist{jj,2}, '__input')
  100. if (nextinput > length(Inputs))
  101. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  102. end
  103. narglist{jj,2} = 'OK_in';
  104. nextinput = nextinput + 1;
  105. elseif strcmp(narglist{jj,2}, '__output')
  106. if (nextoutput > nargout)
  107. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  108. end
  109. if (isempty(arglist{ii,2}))
  110. narglist{jj,2} = 'OK_out';
  111. else
  112. narglist{jj,2} = arglist{ii,2};
  113. end
  114. nextoutput = nextoutput + 1;
  115. if (minval{jj} == 0)
  116. NumReqOutputs = NumReqOutputs - 1;
  117. end
  118. elseif isstr(arglist{ii,2})
  119. narglist{jj,2} = arglist{ii,2};
  120. else
  121. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  122. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  123. end
  124. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  125. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  126. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  127. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  128. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  129. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  130. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  131. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  132. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  133. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  134. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  135. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  136. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  137. end
  138. end
  139. end
  140. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  141. narglist{jj,2} = arglist{ii,2};
  142. end
  143. end
  144. end
  145. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  146. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  147. end
  148. end
  149. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  150. for jj=1:size(narglist,1)
  151. if strcmp(paramtype{jj}, 'Toggle')
  152. if (narglist{jj,2} ==0)
  153. narglist{jj,1} = '';
  154. end;
  155. narglist{jj,2} = '';
  156. end;
  157. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  158. narglist{jj,1} = '';
  159. narglist{jj,2} = '';
  160. end;
  161. if strcmp(narglist{jj,2}, '__input')
  162. if (minval{jj} == 0) % meaning this input is required
  163. if (nextinput > size(Inputs))
  164. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  165. else
  166. narglist{jj,2} = 'OK_in';
  167. nextinput = nextinput + 1;
  168. end
  169. else % this is an optional input
  170. if (nextinput <= length(Inputs))
  171. narglist{jj,2} = 'OK_in';
  172. nextinput = nextinput + 1;
  173. else
  174. narglist{jj,1} = '';
  175. narglist{jj,2} = '';
  176. end;
  177. end;
  178. else
  179. if strcmp(narglist{jj,2}, '__output')
  180. if (minval{jj} == 0) % this is a required output
  181. if (nextoutput > nargout & nargout > 1)
  182. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  183. else
  184. narglist{jj,2} = 'OK_out';
  185. nextoutput = nextoutput + 1;
  186. NumReqOutputs = NumReqOutputs-1;
  187. end
  188. else % this is an optional output
  189. if (nargout - nextoutput >= NumReqOutputs)
  190. narglist{jj,2} = 'OK_out';
  191. nextoutput = nextoutput + 1;
  192. else
  193. narglist{jj,1} = '';
  194. narglist{jj,2} = '';
  195. end;
  196. end
  197. end
  198. end
  199. end
  200. if nargout
  201. varargout = cell(1,nargout);
  202. else
  203. varargout = cell(1,1);
  204. end
  205. global KhorosRoot
  206. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  207. w=['"' KhorosRoot];
  208. else
  209. if ispc
  210. w='"C:\Program Files\dip\khorosBin\';
  211. else
  212. [s,w] = system('which cantata');
  213. w=['"' w(1:end-8)];
  214. end
  215. end
  216. [varargout{:}]=callKhoros([w 'karith2" -div'],Inputs,narglist);