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

/matlab_tools/Converted/kkbitandrev.m

http://github.com/aludnam/MATLAB
Objective C | 242 lines | 239 code | 3 blank | 0 comment | 59 complexity | 2cb49140b38ce4ba294c86c1180b02fa MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkbitandrev 'Output = Input 1 AND NOT(Input 2 or Constant)'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kbitandrev.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. % Integer: real 'Constant', default: 0: 'Constant value'
  9. %
  10. % Example: o = kkbitandrev({i1, i2}, {'i1','';'o','';'i2','';'real',0})
  11. %
  12. % Khoros helpfile follows below:
  13. %
  14. % PROGRAM
  15. % kbitandrev - Output = Input 1 AND NOT(Input 2 or Constant)
  16. %
  17. % DESCRIPTION
  18. % The bitwise AND Reverse operator performs a bitwise NOT on either
  19. % \fBInput 2" or the \fBConstant\fP value, which ever is specified
  20. % by the user, and then performs a bitwise AND between the result of the
  21. % NOT operation and \fBInput 1".
  22. %
  23. % "Data Type - Single Input" 5
  24. % .cI $DATAMANIP/repos/shared/man/sections/value_type_1input
  25. %
  26. % "Data Type - Two Input Objects" 5
  27. % .cI $DATAMANIP/repos/shared/man/sections/value_type_2input
  28. % The bitwise operators will not operate on float or complex data types.
  29. %
  30. % "Map Data" 5
  31. % The bitwise operations have not been written to be fully polymorphic yet.
  32. % They does not
  33. % check for map data, and will therefore always operate on the value data,
  34. % even if a map exists. This will most likely corrupt indexing into the map.
  35. % In the case of a single input, it is recommended to use the "Copy to
  36. % Value" (kcptoval) segment operator to temporarily move the map data into
  37. % the value segment, run the bitwise operation on the data, then move it
  38. % back to the map with the "Copy from Value" (kcpfromval) operator.
  39. % When operating with two input objects, where at least one of the objects
  40. % contains map data, data should be mapped prior to running the bitwise
  41. % operator. The "Map Data" operator (kmapdata) can be used to perform
  42. % the mapping operation.
  43. %
  44. % "Validity Mask - Single Input" 5
  45. % .cI $DATAMANIP/repos/shared/man/sections/mask_1input
  46. %
  47. % "Validity Mask - Two Input Objects" 5
  48. % Masking has not been implemented yet for the bitwise operators. Therefore,
  49. % only the mask from the first input object will be transferred to the output.
  50. %
  51. % "Input Objects of Different Sizes" 5
  52. % .cI $DATAMANIP/repos/shared/man/sections/resize_2input
  53. % The value used to pad the data when the input files are not the same size is
  54. % zero.
  55. %
  56. % "Explicit Location and Time Data - Single Input" 5
  57. % .cI $DATAMANIP/repos/shared/man/sections/loc_and_time_1input
  58. %
  59. % "Explicit Location and Time Data - Two Input Objects" 5
  60. % The bitwise operations have not been extended to understand location and
  61. % time data. Therefore, only location and time data present in the first input
  62. % object will be transferred to the output.
  63. %
  64. % Executing \fBAND Reverse" runs the program "kbitwise\fP with
  65. % the -andrev flag.
  66. %
  67. %
  68. %
  69. % EXAMPLES
  70. %
  71. % "SEE ALSO"
  72. % DATAMANIP::kbitwise
  73. %
  74. % RESTRICTIONS
  75. %
  76. % THIS ROUTINE is still under development, and has not been modified to fully
  77. % support the polymorphic data model. See paragraphs above for discussions
  78. % concerning the polymorphic data segments.
  79. %
  80. % All processing is currently performed as UNSIGNED long, so the operations
  81. % may not work properly on negative values.
  82. %
  83. % The bitwise operators will not operate on float or complex data types.
  84. %
  85. % In the future, the padding value used for this operation when the input
  86. % images are of different sizes, will be modified from binary 0 to binary 1.
  87. %
  88. % REFERENCES
  89. %
  90. % COPYRIGHT
  91. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  92. %
  93. function varargout = kkbitandrev(varargin)
  94. if nargin ==0
  95. Inputs={};arglist={'',''};
  96. elseif nargin ==1
  97. Inputs=varargin{1};arglist={'',''};
  98. elseif nargin ==2
  99. Inputs=varargin{1}; arglist=varargin{2};
  100. else error('Usage: [out1,..] = kkbitandrev(Inputs,arglist).');
  101. end
  102. if size(arglist,2)~=2
  103. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  104. end
  105. narglist={'i1', '__input';'o', '__output';'i2', '__input';'real', 0};
  106. maxval={0,0,1,0};
  107. minval={0,0,1,0};
  108. istoggle=[0,0,1,1];
  109. was_set=istoggle * 0;
  110. paramtype={'InputFile','OutputFile','InputFile','Integer'};
  111. % identify the input arrays and assign them to the arguments as stated by the user
  112. if ~iscell(Inputs)
  113. Inputs = {Inputs};
  114. end
  115. NumReqOutputs=1; nextinput=1; nextoutput=1;
  116. for ii=1:size(arglist,1)
  117. wasmatched=0;
  118. for jj=1:size(narglist,1)
  119. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  120. wasmatched = 1;
  121. was_set(jj) = 1;
  122. if strcmp(narglist{jj,2}, '__input')
  123. if (nextinput > length(Inputs))
  124. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  125. end
  126. narglist{jj,2} = 'OK_in';
  127. nextinput = nextinput + 1;
  128. elseif strcmp(narglist{jj,2}, '__output')
  129. if (nextoutput > nargout)
  130. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  131. end
  132. if (isempty(arglist{ii,2}))
  133. narglist{jj,2} = 'OK_out';
  134. else
  135. narglist{jj,2} = arglist{ii,2};
  136. end
  137. nextoutput = nextoutput + 1;
  138. if (minval{jj} == 0)
  139. NumReqOutputs = NumReqOutputs - 1;
  140. end
  141. elseif isstr(arglist{ii,2})
  142. narglist{jj,2} = arglist{ii,2};
  143. else
  144. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  145. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  146. end
  147. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  148. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  149. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  150. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  151. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  152. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  153. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  154. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  155. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  156. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  157. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  158. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  159. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  160. end
  161. end
  162. end
  163. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  164. narglist{jj,2} = arglist{ii,2};
  165. end
  166. end
  167. end
  168. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  169. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  170. end
  171. end
  172. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  173. for jj=1:size(narglist,1)
  174. if strcmp(paramtype{jj}, 'Toggle')
  175. if (narglist{jj,2} ==0)
  176. narglist{jj,1} = '';
  177. end;
  178. narglist{jj,2} = '';
  179. end;
  180. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  181. narglist{jj,1} = '';
  182. narglist{jj,2} = '';
  183. end;
  184. if strcmp(narglist{jj,2}, '__input')
  185. if (minval{jj} == 0) % meaning this input is required
  186. if (nextinput > size(Inputs))
  187. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  188. else
  189. narglist{jj,2} = 'OK_in';
  190. nextinput = nextinput + 1;
  191. end
  192. else % this is an optional input
  193. if (nextinput <= length(Inputs))
  194. narglist{jj,2} = 'OK_in';
  195. nextinput = nextinput + 1;
  196. else
  197. narglist{jj,1} = '';
  198. narglist{jj,2} = '';
  199. end;
  200. end;
  201. else
  202. if strcmp(narglist{jj,2}, '__output')
  203. if (minval{jj} == 0) % this is a required output
  204. if (nextoutput > nargout & nargout > 1)
  205. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  206. else
  207. narglist{jj,2} = 'OK_out';
  208. nextoutput = nextoutput + 1;
  209. NumReqOutputs = NumReqOutputs-1;
  210. end
  211. else % this is an optional output
  212. if (nargout - nextoutput >= NumReqOutputs)
  213. narglist{jj,2} = 'OK_out';
  214. nextoutput = nextoutput + 1;
  215. else
  216. narglist{jj,1} = '';
  217. narglist{jj,2} = '';
  218. end;
  219. end
  220. end
  221. end
  222. end
  223. if nargout
  224. varargout = cell(1,nargout);
  225. else
  226. varargout = cell(1,1);
  227. end
  228. global KhorosRoot
  229. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  230. w=['"' KhorosRoot];
  231. else
  232. if ispc
  233. w='"C:\Program Files\dip\khorosBin\';
  234. else
  235. [s,w] = system('which cantata');
  236. w=['"' w(1:end-8)];
  237. end
  238. end
  239. [varargout{:}]=callKhoros([w 'kbitwise" -andrev'],Inputs,narglist);