PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/matlab_tools/Converted/kkbitandinv.m

http://github.com/aludnam/MATLAB
Objective C | 240 lines | 237 code | 3 blank | 0 comment | 59 complexity | 9dc93129948421d74cc311e4d203b98b MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkbitandinv 'Output = NOT(Input 1) AND (Input 2 or Constant)'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kbitandinv.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: 1: 'Constant value'
  9. %
  10. % Example: o = kkbitandinv({i1, i2}, {'i1','';'o','';'i2','';'real',1})
  11. %
  12. % Khoros helpfile follows below:
  13. %
  14. % PROGRAM
  15. % kbitandinv - Output = NOT(Input 1) AND (Input 2 or Constant)
  16. %
  17. % DESCRIPTION
  18. % The bitwise AND Inverted operator performs a bitwise NOT on \fBInput 1"
  19. % and then a bitwise AND between the result of the NOT operation and
  20. % either the corresponding value in \fBInput 2" or the \fBConstant\fP value,
  21. % which ever is specified by the user.
  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 \fBANDinv" runs the program "kbitwise\fP with the -andinv flag.
  65. %
  66. %
  67. %
  68. % EXAMPLES
  69. %
  70. % "SEE ALSO"
  71. % DATAMANIP::kbitwise
  72. %
  73. % RESTRICTIONS
  74. % THIS ROUTINE is still under development, and has not been modified to fully
  75. % support the polymorphic data model. See paragraphs above for discussions
  76. % concerning the polymorphic data segments.
  77. %
  78. % All processing is currently performed as UNSIGNED long, so the operations
  79. % may not work properly on negative values.
  80. %
  81. % The bitwise operators will not operate on float or complex data types.
  82. %
  83. % In the future, the padding value used for ANDinv when the input images are of
  84. % different sizes, will be modified from binary 0 to binary 1.
  85. %
  86. % REFERENCES
  87. %
  88. % COPYRIGHT
  89. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  90. %
  91. function varargout = kkbitandinv(varargin)
  92. if nargin ==0
  93. Inputs={};arglist={'',''};
  94. elseif nargin ==1
  95. Inputs=varargin{1};arglist={'',''};
  96. elseif nargin ==2
  97. Inputs=varargin{1}; arglist=varargin{2};
  98. else error('Usage: [out1,..] = kkbitandinv(Inputs,arglist).');
  99. end
  100. if size(arglist,2)~=2
  101. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  102. end
  103. narglist={'i1', '__input';'o', '__output';'i2', '__input';'real', 1};
  104. maxval={0,0,1,0};
  105. minval={0,0,1,0};
  106. istoggle=[0,0,1,1];
  107. was_set=istoggle * 0;
  108. paramtype={'InputFile','OutputFile','InputFile','Integer'};
  109. % identify the input arrays and assign them to the arguments as stated by the user
  110. if ~iscell(Inputs)
  111. Inputs = {Inputs};
  112. end
  113. NumReqOutputs=1; nextinput=1; nextoutput=1;
  114. for ii=1:size(arglist,1)
  115. wasmatched=0;
  116. for jj=1:size(narglist,1)
  117. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  118. wasmatched = 1;
  119. was_set(jj) = 1;
  120. if strcmp(narglist{jj,2}, '__input')
  121. if (nextinput > length(Inputs))
  122. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  123. end
  124. narglist{jj,2} = 'OK_in';
  125. nextinput = nextinput + 1;
  126. elseif strcmp(narglist{jj,2}, '__output')
  127. if (nextoutput > nargout)
  128. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  129. end
  130. if (isempty(arglist{ii,2}))
  131. narglist{jj,2} = 'OK_out';
  132. else
  133. narglist{jj,2} = arglist{ii,2};
  134. end
  135. nextoutput = nextoutput + 1;
  136. if (minval{jj} == 0)
  137. NumReqOutputs = NumReqOutputs - 1;
  138. end
  139. elseif isstr(arglist{ii,2})
  140. narglist{jj,2} = arglist{ii,2};
  141. else
  142. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  143. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  144. end
  145. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  146. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  147. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  148. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  149. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  150. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  151. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  152. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  153. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  154. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  155. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  156. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  157. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  158. end
  159. end
  160. end
  161. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  162. narglist{jj,2} = arglist{ii,2};
  163. end
  164. end
  165. end
  166. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  167. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  168. end
  169. end
  170. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  171. for jj=1:size(narglist,1)
  172. if strcmp(paramtype{jj}, 'Toggle')
  173. if (narglist{jj,2} ==0)
  174. narglist{jj,1} = '';
  175. end;
  176. narglist{jj,2} = '';
  177. end;
  178. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  179. narglist{jj,1} = '';
  180. narglist{jj,2} = '';
  181. end;
  182. if strcmp(narglist{jj,2}, '__input')
  183. if (minval{jj} == 0) % meaning this input is required
  184. if (nextinput > size(Inputs))
  185. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  186. else
  187. narglist{jj,2} = 'OK_in';
  188. nextinput = nextinput + 1;
  189. end
  190. else % this is an optional input
  191. if (nextinput <= length(Inputs))
  192. narglist{jj,2} = 'OK_in';
  193. nextinput = nextinput + 1;
  194. else
  195. narglist{jj,1} = '';
  196. narglist{jj,2} = '';
  197. end;
  198. end;
  199. else
  200. if strcmp(narglist{jj,2}, '__output')
  201. if (minval{jj} == 0) % this is a required output
  202. if (nextoutput > nargout & nargout > 1)
  203. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  204. else
  205. narglist{jj,2} = 'OK_out';
  206. nextoutput = nextoutput + 1;
  207. NumReqOutputs = NumReqOutputs-1;
  208. end
  209. else % this is an optional output
  210. if (nargout - nextoutput >= NumReqOutputs)
  211. narglist{jj,2} = 'OK_out';
  212. nextoutput = nextoutput + 1;
  213. else
  214. narglist{jj,1} = '';
  215. narglist{jj,2} = '';
  216. end;
  217. end
  218. end
  219. end
  220. end
  221. if nargout
  222. varargout = cell(1,nargout);
  223. else
  224. varargout = cell(1,1);
  225. end
  226. global KhorosRoot
  227. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  228. w=['"' KhorosRoot];
  229. else
  230. if ispc
  231. w='"C:\Program Files\dip\khorosBin\';
  232. else
  233. [s,w] = system('which cantata');
  234. w=['"' w(1:end-8)];
  235. end
  236. end
  237. [varargout{:}]=callKhoros([w 'kbitwise" -andinv'],Inputs,narglist);