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

/matlab_tools/Converted/kkbitor.m

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