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

/matlab_tools/Converted/kkgeneric.m

http://github.com/aludnam/MATLAB
Objective C | 264 lines | 261 code | 3 blank | 0 comment | 58 complexity | f3ab4a11c9eeb366f3422bafb8177d60 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkgeneric 'Generic Routine Interface (glue)'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kgeneric.pane file
  3. %
  4. % Parameters:
  5. % String: prefix 'Prefix', default: ' ': 'prefix string'
  6. % InputFile: i 'Input Image ', optional: 'input image'
  7. % OutputFile: o 'Output Image', optional: 'output image or file'
  8. % String: iname1 'Input name #1 ', default: ' ': 'name of input argument #1'
  9. % InputFile: i1 'Input Filename #1 ', optional: 'input filename #1'
  10. % String: iname2 'Input name #2 ', default: ' ': 'name of input argument #2'
  11. % InputFile: i2 'Input Filename #2 ', optional: 'input filename #2'
  12. % String: iname3 'Input name #3 ', default: ' ': 'name of input argument #3'
  13. % InputFile: i3 'Input Filename #3 ', optional: 'input filename #3'
  14. % String: oname1 'Output name #1', default: ' ': 'name of output argument #1'
  15. % OutputFile: o1 'Output Filename #1', optional: 'output filename #1'
  16. % String: oname2 'Output name #2', default: ' ': 'name of output argument #2'
  17. % OutputFile: o2 'Output Filename #2', optional: 'output filename #2'
  18. % String: oname3 'Output name #3', default: ' ': 'name of output argument #3'
  19. % OutputFile: o3 'Output Filename #3', optional: 'output filename #3'
  20. % String: name1 'Arg name #1', default: ' ': 'Name of argument #1'
  21. % String: val1 'Argument #1 value', default: ' ': 'argument #1 value'
  22. % String: name2 'Arg name #2', default: ' ': 'Name of argument #2'
  23. % String: val2 'Argument #2 value', default: ' ': 'argument #2 value'
  24. % String: name3 'Arg name #3', default: ' ': 'Name of argument #3'
  25. % String: val3 'Argument #3 value', default: ' ': 'argument #3 value'
  26. % String: name4 'Arg name #4', default: ' ': 'Name of argument #4'
  27. % String: val4 'Argument #4 value', default: ' ': 'argument #4 value'
  28. % String: name5 'Arg name #5', default: ' ': 'Name of argument #5'
  29. % String: val5 'Argument #5 value', default: ' ': 'argument #5 value'
  30. % String: name6 'Arg name #6', default: ' ': 'Name of argument #6'
  31. % String: val6 'Argument #6 value', default: ' ': 'argument #6 value'
  32. % String: name7 'Arg name #7', default: ' ': 'Name of argument #7'
  33. % String: val7 'Argument #7 value', default: ' ': 'argument #7 value'
  34. % String: name8 'Arg name #8', default: ' ': 'Name of argument #8'
  35. % String: val8 'Argument #8 value', default: ' ': 'argument #8 value'
  36. % String: trailer 'Trailer', default: ' ': 'trailer string'
  37. %
  38. % Example: [o, o1, o2, o3] = kkgeneric({i, i1, i2, i3}, {'prefix',' ';'i','';'o','';'iname1',' ';'i1','';'iname2',' ';'i2','';'iname3',' ';'i3','';'oname1',' ';'o1','';'oname2',' ';'o2','';'oname3',' ';'o3','';'name1',' ';'val1',' ';'name2',' ';'val2',' ';'name3',' ';'val3',' ';'name4',' ';'val4',' ';'name5',' ';'val5',' ';'name6',' ';'val6',' ';'name7',' ';'val7',' ';'name8',' ';'val8',' ';'trailer',' '})
  39. %
  40. % Khoros helpfile follows below:
  41. %
  42. % PROGRAM
  43. % kgeneric - Generic Routine Interface (glue)
  44. %
  45. % DESCRIPTION
  46. % .I kgeneric
  47. % is a programmable interface that allows a generalized Un*x command line
  48. % to be executed by cantata.
  49. %
  50. % Entries on the pane are spit out to a string that is then system()'d
  51. % off. The string is built up by appending the contents of the SELECTED
  52. % entries together in scan-line order.
  53. %
  54. % Note: All entries are strings. Unfortunately, the forms don't
  55. % seem to like multiple-worded strings, so you have to build up your
  56. % command piece at a time. You CAN use a multiple-worded string in the
  57. % prefix and trailer.
  58. %
  59. % Note: Anything entered into a FILENAME box will be treated as a file
  60. % using the normal Khoros file access checking. This means the UI will
  61. % try to open the filename for access. If it is a Un*x command or other
  62. % object then things won't work.
  63. %
  64. % Note: There appears to be no way to protect special characters from
  65. % the shell.
  66. %
  67. % Note: The oval button to the left of argument name selection allows
  68. % you to put a minus sign ("-") immediately in front of the name itself
  69. % in the command string that is executed. The parser won't let you
  70. % put a minus sign in the string field itself - it will complain about
  71. % unknown arguments. So if you want an argument name that looks like
  72. %
  73. % -blah
  74. %
  75. % then click the button to get the - to show and enter blah as the name.
  76. % The actual command string executed will look like that above.
  77. %
  78. % Note: There is no job control from this routine. Hitting the
  79. % kill button in cantata is not guaranteed to kill the command that was
  80. % system()'d off. Additionally, status reporting is unsupported.
  81. %
  82. %
  83. %
  84. % EXAMPLES
  85. %
  86. % To execute:
  87. %
  88. % ls -al > snarf
  89. %
  90. % using this routine, do:
  91. %
  92. % % kgeneric -prefix ls -iname1 al -iname2 > -o1 snarf -di1 1 -di2 0 -di3 0 -do1 0
  93. % -do2 0 -do3 0 -dn1 0 -dn2 0 -dn3 0 -dn4 0 -dn5 0 -dn6 0 -dn7 0 -dn8 0
  94. %
  95. % and you should get the desired result. Note that this routine is not much good
  96. % for use on the command line. It is for cantata.
  97. %
  98. % "SEE ALSO"
  99. % None. Yet.
  100. %
  101. % RESTRICTIONS
  102. % Kgeneric executes the command via a ksystem() call, and thus there is no
  103. % reporting of errors from the command. If nothing happens when you run a command,
  104. % try executing the whole command from command line. If the command line fails,
  105. % fix the problem before trying to use kgeneric.
  106. %
  107. % No data type or range checking is available when using this interface.
  108. %
  109. % REFERENCES
  110. % None.
  111. %
  112. % COPYRIGHT
  113. % Copyright (C) 1993 - 1996, Khoral Research, Inc. All rights reserved.
  114. %
  115. function varargout = kkgeneric(varargin)
  116. if nargin ==0
  117. Inputs={};arglist={'',''};
  118. elseif nargin ==1
  119. Inputs=varargin{1};arglist={'',''};
  120. elseif nargin ==2
  121. Inputs=varargin{1}; arglist=varargin{2};
  122. else error('Usage: [out1,..] = kkgeneric(Inputs,arglist).');
  123. end
  124. if size(arglist,2)~=2
  125. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  126. end
  127. narglist={'prefix', ' ';'i', '__input';'o', '__output';'iname1', ' ';'i1', '__input';'iname2', ' ';'i2', '__input';'iname3', ' ';'i3', '__input';'oname1', ' ';'o1', '__output';'oname2', ' ';'o2', '__output';'oname3', ' ';'o3', '__output';'name1', ' ';'val1', ' ';'name2', ' ';'val2', ' ';'name3', ' ';'val3', ' ';'name4', ' ';'val4', ' ';'name5', ' ';'val5', ' ';'name6', ' ';'val6', ' ';'name7', ' ';'val7', ' ';'name8', ' ';'val8', ' ';'trailer', ' '};
  128. maxval={0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  129. minval={0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  130. istoggle=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
  131. was_set=istoggle * 0;
  132. paramtype={'String','InputFile','OutputFile','String','InputFile','String','InputFile','String','InputFile','String','OutputFile','String','OutputFile','String','OutputFile','String','String','String','String','String','String','String','String','String','String','String','String','String','String','String','String','String'};
  133. % identify the input arrays and assign them to the arguments as stated by the user
  134. if ~iscell(Inputs)
  135. Inputs = {Inputs};
  136. end
  137. NumReqOutputs=0; nextinput=1; nextoutput=1;
  138. for ii=1:size(arglist,1)
  139. wasmatched=0;
  140. for jj=1:size(narglist,1)
  141. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  142. wasmatched = 1;
  143. was_set(jj) = 1;
  144. if strcmp(narglist{jj,2}, '__input')
  145. if (nextinput > length(Inputs))
  146. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  147. end
  148. narglist{jj,2} = 'OK_in';
  149. nextinput = nextinput + 1;
  150. elseif strcmp(narglist{jj,2}, '__output')
  151. if (nextoutput > nargout)
  152. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  153. end
  154. if (isempty(arglist{ii,2}))
  155. narglist{jj,2} = 'OK_out';
  156. else
  157. narglist{jj,2} = arglist{ii,2};
  158. end
  159. nextoutput = nextoutput + 1;
  160. if (minval{jj} == 0)
  161. NumReqOutputs = NumReqOutputs - 1;
  162. end
  163. elseif isstr(arglist{ii,2})
  164. narglist{jj,2} = arglist{ii,2};
  165. else
  166. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  167. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  168. end
  169. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  170. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  171. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  172. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  173. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  174. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  175. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  176. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  177. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  178. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  179. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  180. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  181. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  182. end
  183. end
  184. end
  185. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  186. narglist{jj,2} = arglist{ii,2};
  187. end
  188. end
  189. end
  190. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  191. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  192. end
  193. end
  194. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  195. for jj=1:size(narglist,1)
  196. if strcmp(paramtype{jj}, 'Toggle')
  197. if (narglist{jj,2} ==0)
  198. narglist{jj,1} = '';
  199. end;
  200. narglist{jj,2} = '';
  201. end;
  202. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  203. narglist{jj,1} = '';
  204. narglist{jj,2} = '';
  205. end;
  206. if strcmp(narglist{jj,2}, '__input')
  207. if (minval{jj} == 0) % meaning this input is required
  208. if (nextinput > size(Inputs))
  209. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  210. else
  211. narglist{jj,2} = 'OK_in';
  212. nextinput = nextinput + 1;
  213. end
  214. else % this is an optional input
  215. if (nextinput <= length(Inputs))
  216. narglist{jj,2} = 'OK_in';
  217. nextinput = nextinput + 1;
  218. else
  219. narglist{jj,1} = '';
  220. narglist{jj,2} = '';
  221. end;
  222. end;
  223. else
  224. if strcmp(narglist{jj,2}, '__output')
  225. if (minval{jj} == 0) % this is a required output
  226. if (nextoutput > nargout & nargout > 1)
  227. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  228. else
  229. narglist{jj,2} = 'OK_out';
  230. nextoutput = nextoutput + 1;
  231. NumReqOutputs = NumReqOutputs-1;
  232. end
  233. else % this is an optional output
  234. if (nargout - nextoutput >= NumReqOutputs)
  235. narglist{jj,2} = 'OK_out';
  236. nextoutput = nextoutput + 1;
  237. else
  238. narglist{jj,1} = '';
  239. narglist{jj,2} = '';
  240. end;
  241. end
  242. end
  243. end
  244. end
  245. if nargout
  246. varargout = cell(1,nargout);
  247. else
  248. varargout = cell(1,1);
  249. end
  250. global KhorosRoot
  251. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  252. w=['"' KhorosRoot];
  253. else
  254. if ispc
  255. w='"C:\Program Files\dip\khorosBin\';
  256. else
  257. [s,w] = system('which cantata');
  258. w=['"' w(1:end-8)];
  259. end
  260. end
  261. [varargout{:}]=callKhoros([w 'kgeneric" '],Inputs,narglist);