PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/matlab_tools/Converted/kkbitorinv.m

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