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

/matlab_tools/Converted/kkabsdiff.m

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