PageRenderTime 36ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kvcast.m

http://github.com/aludnam/MATLAB
Objective C | 228 lines | 225 code | 3 blank | 0 comment | 55 complexity | 42ef6f90546cc70432bbbb302605fd02 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kvcast 'Upconvert All Inputs to the Highest Input Data Type (K1)'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros vcast.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Input Image 1', required: 'input image 1'
  6. % InputFile: i2 'Input Image 2', required: 'input image 2'
  7. % InputFile: i3 'Input Image 3', optional: 'input image 3'
  8. % InputFile: i4 'Input Image 4', optional: 'input image 4'
  9. % InputFile: i5 'Input Image 5', optional: 'input image 5'
  10. % MultiChoice: t 'Select Data Type (Auto Upcast if Not Selected)', default: 1: 'choose byte data type'
  11. % String: t 'Byte', default: 'byte': 'choose integer data type'
  12. % String: t 'Integer', default: 'int': 'choose complex data type'
  13. % String: t 'Complex', default: 'complex': 'choose short data type'
  14. % String: t 'Short', default: 'short': 'choose float data type'
  15. % String: t 'Float', default: 'float': 'choose double data type'
  16. % String: t 'Double', default: 'double': 'Select data type [default = Auto Upcast to Highest Input Data Type]'
  17. % Choices are:
  18. % OutputFile: o1 'Output Image 1', required: 'output image 1'
  19. % OutputFile: o2 'Output Image 2', required: 'output image 2'
  20. % OutputFile: o3 'Output Image 3', optional: 'output image 3'
  21. % OutputFile: o4 'Output Image 4', optional: 'output image 4'
  22. % OutputFile: o5 'Output Image 5', optional: 'output image 5'
  23. %
  24. % Example: [o1, o2, o3, o4, o5] = kvcast({i1, i2, i3, i4, i5}, {'i1','';'i2','';'i3','';'i4','';'i5','';'t',1;'t','byte';'t','int';'t','complex';'t','short';'t','float';'t','double';'o1','';'o2','';'o3','';'o4','';'o5',''})
  25. %
  26. % Khoros helpfile follows below:
  27. %
  28. % PROGRAM
  29. % vcast - Upconvert All Inputs to the Highest Input Data Type (K1)
  30. %
  31. % DESCRIPTION
  32. % .I vcast
  33. % will upconvert or upcast each input image to the highest input image
  34. % data type. Optionally, the user may elect to upcast all images to
  35. % a specified data type, as long as it is a data type that is equal to
  36. % or greater than the highest data type of the input images. If the
  37. % user tries to select a data type that is lower than the highest
  38. % data type of the input images, an error message will be produced
  39. % indicating that down casting is not allowed.
  40. %
  41. % There are no restrictions as to the input image data types. The data
  42. % types can range from BIT to DOUBLE. The input images may contain any
  43. % combination of sizes or number of data bands. All map information from
  44. % each input image is transferred to the corresponding output image.
  45. %
  46. % Note that when converting from type BIT to BYTE, the output values
  47. % will be 0 or 1. This is different from the results one would obtain
  48. % using the defaults with kconvert. In trying to preserve the
  49. % integrity of the data, vcast scales the data by 1.
  50. %
  51. %
  52. %
  53. % EXAMPLES
  54. % vcast -i1 image.bit -i2 image.float -o1 image1 -o2 image2
  55. %
  56. % converts both input images to data type FLOAT. The optional data
  57. % type argument was not selected, so auto convert was used to cast
  58. % both images to the highest data type of the input images (in this case
  59. % FLOAT).
  60. %
  61. % vcast -i1 image.bit -i2 image.byte -i3 image.short -o1 img1 -o2 img2 -o3 img3 -t float
  62. %
  63. % converts each input image to data type FLOAT. The optional data
  64. % type argument was used to upcast all input images to data type
  65. % FLOAT.
  66. %
  67. % "SEE ALSO"
  68. % kconvert
  69. %
  70. % RESTRICTIONS
  71. % .I vcast
  72. % only scales the input data by 1, and will only upconvert the data.
  73. %
  74. % REFERENCES
  75. %
  76. % COPYRIGHT
  77. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  78. %
  79. function varargout = kvcast(varargin)
  80. if nargin ==0
  81. Inputs={};arglist={'',''};
  82. elseif nargin ==1
  83. Inputs=varargin{1};arglist={'',''};
  84. elseif nargin ==2
  85. Inputs=varargin{1}; arglist=varargin{2};
  86. else error('Usage: [out1,..] = kvcast(Inputs,arglist).');
  87. end
  88. if size(arglist,2)~=2
  89. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  90. end
  91. narglist={'i1', '__input';'i2', '__input';'i3', '__input';'i4', '__input';'i5', '__input';'t', 1;'t', 'byte';'t', 'int';'t', 'complex';'t', 'short';'t', 'float';'t', 'double';'o1', '__output';'o2', '__output';'o3', '__output';'o4', '__output';'o5', '__output'};
  92. maxval={0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1};
  93. minval={0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1};
  94. istoggle=[0,0,1,1,1,0,1,1,1,1,1,1,0,0,1,1,1];
  95. was_set=istoggle * 0;
  96. paramtype={'InputFile','InputFile','InputFile','InputFile','InputFile','MultiChoice','String','String','String','String','String','String','OutputFile','OutputFile','OutputFile','OutputFile','OutputFile'};
  97. % identify the input arrays and assign them to the arguments as stated by the user
  98. if ~iscell(Inputs)
  99. Inputs = {Inputs};
  100. end
  101. NumReqOutputs=2; nextinput=1; nextoutput=1;
  102. for ii=1:size(arglist,1)
  103. wasmatched=0;
  104. for jj=1:size(narglist,1)
  105. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  106. wasmatched = 1;
  107. was_set(jj) = 1;
  108. if strcmp(narglist{jj,2}, '__input')
  109. if (nextinput > length(Inputs))
  110. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  111. end
  112. narglist{jj,2} = 'OK_in';
  113. nextinput = nextinput + 1;
  114. elseif strcmp(narglist{jj,2}, '__output')
  115. if (nextoutput > nargout)
  116. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  117. end
  118. if (isempty(arglist{ii,2}))
  119. narglist{jj,2} = 'OK_out';
  120. else
  121. narglist{jj,2} = arglist{ii,2};
  122. end
  123. nextoutput = nextoutput + 1;
  124. if (minval{jj} == 0)
  125. NumReqOutputs = NumReqOutputs - 1;
  126. end
  127. elseif isstr(arglist{ii,2})
  128. narglist{jj,2} = arglist{ii,2};
  129. else
  130. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  131. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  132. end
  133. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  134. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  135. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  136. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  137. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  138. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  139. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  140. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  141. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  142. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  143. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  144. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  145. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  146. end
  147. end
  148. end
  149. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  150. narglist{jj,2} = arglist{ii,2};
  151. end
  152. end
  153. end
  154. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  155. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  156. end
  157. end
  158. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  159. for jj=1:size(narglist,1)
  160. if strcmp(paramtype{jj}, 'Toggle')
  161. if (narglist{jj,2} ==0)
  162. narglist{jj,1} = '';
  163. end;
  164. narglist{jj,2} = '';
  165. end;
  166. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  167. narglist{jj,1} = '';
  168. narglist{jj,2} = '';
  169. end;
  170. if strcmp(narglist{jj,2}, '__input')
  171. if (minval{jj} == 0) % meaning this input is required
  172. if (nextinput > size(Inputs))
  173. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  174. else
  175. narglist{jj,2} = 'OK_in';
  176. nextinput = nextinput + 1;
  177. end
  178. else % this is an optional input
  179. if (nextinput <= length(Inputs))
  180. narglist{jj,2} = 'OK_in';
  181. nextinput = nextinput + 1;
  182. else
  183. narglist{jj,1} = '';
  184. narglist{jj,2} = '';
  185. end;
  186. end;
  187. else
  188. if strcmp(narglist{jj,2}, '__output')
  189. if (minval{jj} == 0) % this is a required output
  190. if (nextoutput > nargout & nargout > 1)
  191. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  192. else
  193. narglist{jj,2} = 'OK_out';
  194. nextoutput = nextoutput + 1;
  195. NumReqOutputs = NumReqOutputs-1;
  196. end
  197. else % this is an optional output
  198. if (nargout - nextoutput >= NumReqOutputs)
  199. narglist{jj,2} = 'OK_out';
  200. nextoutput = nextoutput + 1;
  201. else
  202. narglist{jj,1} = '';
  203. narglist{jj,2} = '';
  204. end;
  205. end
  206. end
  207. end
  208. end
  209. if nargout
  210. varargout = cell(1,nargout);
  211. else
  212. varargout = cell(1,1);
  213. end
  214. global KhorosRoot
  215. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  216. w=['"' KhorosRoot];
  217. else
  218. if ispc
  219. w='"C:\Program Files\dip\khorosBin\';
  220. else
  221. [s,w] = system('which cantata');
  222. w=['"' w(1:end-8)];
  223. end
  224. end
  225. [varargout{:}]=callKhoros([w 'vcast" '],Inputs,narglist);