PageRenderTime 62ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kkbitrshift.m

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