PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kwrapexpand.m

http://github.com/aludnam/MATLAB
Objective C | 186 lines | 183 code | 3 blank | 0 comment | 55 complexity | f94f0380395ce9c61d648cc3d1972942 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kwrapexpand 'Expand Img1 to size of Img2 by wrapping '
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros wrapexpand.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Input to expand', required: 'This data is copied (only into float data-type !)'
  6. % InputFile: i2 'Input for Sizes', required: 'Sizes of output are taken from this image'
  7. % Toggle: blend 'Blend Mode', default: 0: 'When activated blends the last slice softly (linearly) into the first slice'
  8. % Integer: oe 'Offset Elements', default: 0: 'offset to be applied to elements during wrapping'
  9. % Toggle: keepx 'Keep X', default: 0: 'If selected, the size along this direction will not be changed.'
  10. % Toggle: keepy 'Y', default: 0: 'If selected, the size along this direction will not be changed.'
  11. % Toggle: keepz 'Z', default: 0: 'If selected, the size along this direction will not be changed.'
  12. % Toggle: keepe 'E', default: 0: 'If selected, the size along this direction will not be changed.'
  13. % OutputFile: o 'Output', required: 'Resulting output data object'
  14. %
  15. % Example: o = kwrapexpand({i1, i2}, {'i1','';'i2','';'blend',0;'oe',0;'keepx',0;'keepy',0;'keepz',0;'keepe',0;'o',''})
  16. %
  17. % Khoros helpfile follows below:
  18. %
  19. % PROGRAM
  20. % wrapexpand - Expand Img1 to size of Img2 by wrapping
  21. %
  22. % DESCRIPTION
  23. %
  24. %
  25. %
  26. % EXAMPLES
  27. %
  28. % "SEE ALSO"
  29. %
  30. % RESTRICTIONS
  31. %
  32. % REFERENCES
  33. %
  34. % COPYRIGHT
  35. % Copyright (C) 1996-2003, Rainer Heintzmann, All rights reserved.
  36. %
  37. function varargout = kwrapexpand(varargin)
  38. if nargin ==0
  39. Inputs={};arglist={'',''};
  40. elseif nargin ==1
  41. Inputs=varargin{1};arglist={'',''};
  42. elseif nargin ==2
  43. Inputs=varargin{1}; arglist=varargin{2};
  44. else error('Usage: [out1,..] = kwrapexpand(Inputs,arglist).');
  45. end
  46. if size(arglist,2)~=2
  47. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  48. end
  49. narglist={'i1', '__input';'i2', '__input';'blend', 0;'oe', 0;'keepx', 0;'keepy', 0;'keepz', 0;'keepe', 0;'o', '__output'};
  50. maxval={0,0,0,0,0,0,0,0,0};
  51. minval={0,0,0,0,0,0,0,0,0};
  52. istoggle=[0,0,1,0,1,1,1,1,0];
  53. was_set=istoggle * 0;
  54. paramtype={'InputFile','InputFile','Toggle','Integer','Toggle','Toggle','Toggle','Toggle','OutputFile'};
  55. % identify the input arrays and assign them to the arguments as stated by the user
  56. if ~iscell(Inputs)
  57. Inputs = {Inputs};
  58. end
  59. NumReqOutputs=1; nextinput=1; nextoutput=1;
  60. for ii=1:size(arglist,1)
  61. wasmatched=0;
  62. for jj=1:size(narglist,1)
  63. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  64. wasmatched = 1;
  65. was_set(jj) = 1;
  66. if strcmp(narglist{jj,2}, '__input')
  67. if (nextinput > length(Inputs))
  68. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  69. end
  70. narglist{jj,2} = 'OK_in';
  71. nextinput = nextinput + 1;
  72. elseif strcmp(narglist{jj,2}, '__output')
  73. if (nextoutput > nargout)
  74. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  75. end
  76. if (isempty(arglist{ii,2}))
  77. narglist{jj,2} = 'OK_out';
  78. else
  79. narglist{jj,2} = arglist{ii,2};
  80. end
  81. nextoutput = nextoutput + 1;
  82. if (minval{jj} == 0)
  83. NumReqOutputs = NumReqOutputs - 1;
  84. end
  85. elseif isstr(arglist{ii,2})
  86. narglist{jj,2} = arglist{ii,2};
  87. else
  88. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  89. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  90. end
  91. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  92. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  93. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  94. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  95. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  96. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  97. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  98. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  99. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  100. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  101. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  102. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  103. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  104. end
  105. end
  106. end
  107. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  108. narglist{jj,2} = arglist{ii,2};
  109. end
  110. end
  111. end
  112. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  113. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  114. end
  115. end
  116. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  117. for jj=1:size(narglist,1)
  118. if strcmp(paramtype{jj}, 'Toggle')
  119. if (narglist{jj,2} ==0)
  120. narglist{jj,1} = '';
  121. end;
  122. narglist{jj,2} = '';
  123. end;
  124. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  125. narglist{jj,1} = '';
  126. narglist{jj,2} = '';
  127. end;
  128. if strcmp(narglist{jj,2}, '__input')
  129. if (minval{jj} == 0) % meaning this input is required
  130. if (nextinput > size(Inputs))
  131. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  132. else
  133. narglist{jj,2} = 'OK_in';
  134. nextinput = nextinput + 1;
  135. end
  136. else % this is an optional input
  137. if (nextinput <= length(Inputs))
  138. narglist{jj,2} = 'OK_in';
  139. nextinput = nextinput + 1;
  140. else
  141. narglist{jj,1} = '';
  142. narglist{jj,2} = '';
  143. end;
  144. end;
  145. else
  146. if strcmp(narglist{jj,2}, '__output')
  147. if (minval{jj} == 0) % this is a required output
  148. if (nextoutput > nargout & nargout > 1)
  149. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  150. else
  151. narglist{jj,2} = 'OK_out';
  152. nextoutput = nextoutput + 1;
  153. NumReqOutputs = NumReqOutputs-1;
  154. end
  155. else % this is an optional output
  156. if (nargout - nextoutput >= NumReqOutputs)
  157. narglist{jj,2} = 'OK_out';
  158. nextoutput = nextoutput + 1;
  159. else
  160. narglist{jj,1} = '';
  161. narglist{jj,2} = '';
  162. end;
  163. end
  164. end
  165. end
  166. end
  167. if nargout
  168. varargout = cell(1,nargout);
  169. else
  170. varargout = cell(1,1);
  171. end
  172. global KhorosRoot
  173. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  174. w=['"' KhorosRoot];
  175. else
  176. if ispc
  177. w='"C:\Program Files\dip\khorosBin\';
  178. else
  179. [s,w] = system('which cantata');
  180. w=['"' w(1:end-8)];
  181. end
  182. end
  183. [varargout{:}]=callKhoros([w 'wrapexpand" -k'],Inputs,narglist);