PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kApplyFkt.m

http://github.com/aludnam/MATLAB
Objective C | 196 lines | 193 code | 3 blank | 0 comment | 58 complexity | c90ce713789de400213c68ee44c0858c MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kApplyFkt 'computes with several images by invoking a compilation '
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros ApplyFkt.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Input i1', optional: 'First Input data object'
  6. % Toggle: iter1 'iterate over input 1', default: 0: 'If selected, the iteration will be performed over input image 1 instead of output sizes. This allows the computation of projections'
  7. % InputFile: i2 'Input i2', optional: 'First Input data object'
  8. % InputFile: i3 'Input i3', optional: 'First Input data object'
  9. % InputFile: i4 'Input i4', optional: 'First Input data object'
  10. % InputFile: i5 'Input i5', optional: 'First Input data object'
  11. % InputFile: pobj 'Object to link', required: 'The generated code will be linked with this object. This should be a version of this very program compiled with the "-DRUN" flag.'
  12. % String: prog 'String', default: 'out = i1 + sin(2*M_PI*w); ': 'Here the user can enter a mini-program (in c/c++). Variables supplied are: x,y,z,e : absolute positions in Input 1 and Output. w,h,d,re relative positions (0 is center, 1 is border). out : output image, i1,i2,i3,i4,i5 : input images; For multiline programs, a backslash (\) has to be the last character in each line.'
  13. % Integer: sX 'Size X', default: 256: 'integer'
  14. % Integer: sY 'Y', default: 256: 'size of the output, if given'
  15. % Integer: sZ 'Z', default: 256: 'size of the output, if given'
  16. % Integer: se 'E', default: 1: 'size of the output, if given'
  17. % Toggle: clearY 'Clear on Y', default: 0: 'If selected, the output will be cleared every new line'
  18. % Toggle: clearZ 'Clear on Z', default: 0: 'If selected, the output will be cleared every new plane'
  19. % Toggle: clearE 'Clear on E', default: 0: 'If selected, the output will be cleared every new element'
  20. % OutputFile: o 'Output', required: 'Resulting output data object'
  21. % OutputFile: pout 'Program Text', required: 'Here the complete subroutine will be saved (in ASCII)'
  22. % OutputFile: pexe 'Program Executable', required: 'The final executable will be stored here.'
  23. % InputFile: mask 'Mask Image', optional: 'Mask data. If given, the procedure will only be called if the mask has a value of bigger than zero in this pixel.'
  24. %
  25. % Example: [o, pout, pexe] = kApplyFkt({i1, i2, i3, i4, i5, pobj, mask}, {'i1','';'iter1',0;'i2','';'i3','';'i4','';'i5','';'pobj','';'prog','out = i1 + sin(2*M_PI*w); ';'sX',256;'sY',256;'sZ',256;'se',1;'clearY',0;'clearZ',0;'clearE',0;'o','';'pout','';'pexe','';'mask',''})
  26. %
  27. % Khoros helpfile follows below:
  28. %
  29. % PROGRAM
  30. % ApplyFkt - computes with several images by invoking a compilation
  31. %
  32. % DESCRIPTION
  33. %
  34. %
  35. %
  36. % EXAMPLES
  37. %
  38. % "SEE ALSO"
  39. %
  40. % RESTRICTIONS
  41. %
  42. % REFERENCES
  43. %
  44. % COPYRIGHT
  45. % Copyright (C) 1996-2003, Rainer Heintzmann, All rights reserved.
  46. %
  47. function varargout = kApplyFkt(varargin)
  48. if nargin ==0
  49. Inputs={};arglist={'',''};
  50. elseif nargin ==1
  51. Inputs=varargin{1};arglist={'',''};
  52. elseif nargin ==2
  53. Inputs=varargin{1}; arglist=varargin{2};
  54. else error('Usage: [out1,..] = kApplyFkt(Inputs,arglist).');
  55. end
  56. if size(arglist,2)~=2
  57. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  58. end
  59. narglist={'i1', '__input';'iter1', 0;'i2', '__input';'i3', '__input';'i4', '__input';'i5', '__input';'pobj', '__input';'prog', 'out = i1 + sin(2*M_PI*w); ';'sX', 256;'sY', 256;'sZ', 256;'se', 1;'clearY', 0;'clearZ', 0;'clearE', 0;'o', '__output';'pout', '__output';'pexe', '__output';'mask', '__input'};
  60. maxval={1,0,1,1,1,1,0,0,2,2,2,2,0,0,0,0,0,0,1};
  61. minval={1,0,1,1,1,1,0,0,2,2,2,2,0,0,0,0,0,0,1};
  62. istoggle=[1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,0,0,1];
  63. was_set=istoggle * 0;
  64. paramtype={'InputFile','Toggle','InputFile','InputFile','InputFile','InputFile','InputFile','String','Integer','Integer','Integer','Integer','Toggle','Toggle','Toggle','OutputFile','OutputFile','OutputFile','InputFile'};
  65. % identify the input arrays and assign them to the arguments as stated by the user
  66. if ~iscell(Inputs)
  67. Inputs = {Inputs};
  68. end
  69. NumReqOutputs=3; nextinput=1; nextoutput=1;
  70. for ii=1:size(arglist,1)
  71. wasmatched=0;
  72. for jj=1:size(narglist,1)
  73. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  74. wasmatched = 1;
  75. was_set(jj) = 1;
  76. if strcmp(narglist{jj,2}, '__input')
  77. if (nextinput > length(Inputs))
  78. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  79. end
  80. narglist{jj,2} = 'OK_in';
  81. nextinput = nextinput + 1;
  82. elseif strcmp(narglist{jj,2}, '__output')
  83. if (nextoutput > nargout)
  84. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  85. end
  86. if (isempty(arglist{ii,2}))
  87. narglist{jj,2} = 'OK_out';
  88. else
  89. narglist{jj,2} = arglist{ii,2};
  90. end
  91. nextoutput = nextoutput + 1;
  92. if (minval{jj} == 0)
  93. NumReqOutputs = NumReqOutputs - 1;
  94. end
  95. elseif isstr(arglist{ii,2})
  96. narglist{jj,2} = arglist{ii,2};
  97. else
  98. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  99. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  100. end
  101. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  102. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  103. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  104. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  105. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  106. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  107. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  108. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  109. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  110. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  111. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  112. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  113. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  114. end
  115. end
  116. end
  117. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  118. narglist{jj,2} = arglist{ii,2};
  119. end
  120. end
  121. end
  122. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  123. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  124. end
  125. end
  126. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  127. for jj=1:size(narglist,1)
  128. if strcmp(paramtype{jj}, 'Toggle')
  129. if (narglist{jj,2} ==0)
  130. narglist{jj,1} = '';
  131. end;
  132. narglist{jj,2} = '';
  133. end;
  134. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  135. narglist{jj,1} = '';
  136. narglist{jj,2} = '';
  137. end;
  138. if strcmp(narglist{jj,2}, '__input')
  139. if (minval{jj} == 0) % meaning this input is required
  140. if (nextinput > size(Inputs))
  141. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  142. else
  143. narglist{jj,2} = 'OK_in';
  144. nextinput = nextinput + 1;
  145. end
  146. else % this is an optional input
  147. if (nextinput <= length(Inputs))
  148. narglist{jj,2} = 'OK_in';
  149. nextinput = nextinput + 1;
  150. else
  151. narglist{jj,1} = '';
  152. narglist{jj,2} = '';
  153. end;
  154. end;
  155. else
  156. if strcmp(narglist{jj,2}, '__output')
  157. if (minval{jj} == 0) % this is a required output
  158. if (nextoutput > nargout & nargout > 1)
  159. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  160. else
  161. narglist{jj,2} = 'OK_out';
  162. nextoutput = nextoutput + 1;
  163. NumReqOutputs = NumReqOutputs-1;
  164. end
  165. else % this is an optional output
  166. if (nargout - nextoutput >= NumReqOutputs)
  167. narglist{jj,2} = 'OK_out';
  168. nextoutput = nextoutput + 1;
  169. else
  170. narglist{jj,1} = '';
  171. narglist{jj,2} = '';
  172. end;
  173. end
  174. end
  175. end
  176. end
  177. if nargout
  178. varargout = cell(1,nargout);
  179. else
  180. varargout = cell(1,1);
  181. end
  182. global KhorosRoot
  183. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  184. w=['"' KhorosRoot];
  185. else
  186. if ispc
  187. w='"C:\Program Files\dip\khorosBin\';
  188. else
  189. [s,w] = system('which cantata');
  190. w=['"' w(1:end-8)];
  191. end
  192. end
  193. [varargout{:}]=callKhoros([w 'applyfkt" -k'],Inputs,narglist);