PageRenderTime 67ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kksegcmp.m

http://github.com/aludnam/MATLAB
Objective C | 278 lines | 275 code | 3 blank | 0 comment | 69 complexity | 82752e04c88512a190b46d1cec3f50ff MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kksegcmp 'Compare Attributes & Data of Input 1 and Input 2'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros ksegcmp.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Input #1', required: 'first input data object'
  6. % InputFile: i2 'Input #2', required: 'second input data object'
  7. % Toggle: cast 'Cast Data to Common Type before Comparing', default: 0: 'cast data to common type before comparing'
  8. % Toggle: s 'Run Silently', default: 0: 'silent running - do not print to stdout'
  9. % Toggle: pos '[Position]', default: 0: 'print the position of differing points'
  10. % Toggle: i1val 'Value', default: 0: 'print value from first input for differing points'
  11. % Toggle: i1type 'Type', default: 0: 'print data type of first input for differing points'
  12. % Toggle: i2val 'Value', default: 0: 'print value from second input for differing points'
  13. % Toggle: i2type 'Type', default: 0: 'print data type of second input for differing points'
  14. % OutputFile: o 'ASCII Output ', optional: 'output ASCII file for summary'
  15. % String: var 'Return Results as Cantata Variable ', default: 'equal': 'return results to Cantata '
  16. % Toggle: all 'Compare ALL Data Segments', default: 0: 'compare all data segments'
  17. % Toggle: val 'Value', default: 0: 'compare value segments'
  18. % Toggle: mask 'Mask', default: 0: 'compare mask segments'
  19. % Toggle: loc 'Location', default: 0: 'compare location segments'
  20. % Toggle: time 'Time', default: 0: 'compare time segments'
  21. % Toggle: map 'Map ', default: 0: 'compare map segments'
  22. % String: segment 'Segment Name', default: 'value': 'explicit segment name to compare'
  23. %
  24. % Example: o = kksegcmp({i1, i2}, {'i1','';'i2','';'cast',0;'s',0;'pos',0;'i1val',0;'i1type',0;'i2val',0;'i2type',0;'o','';'var','equal';'all',0;'val',0;'mask',0;'loc',0;'time',0;'map',0;'segment','value'})
  25. %
  26. % Khoros helpfile follows below:
  27. %
  28. % PROGRAM
  29. % ksegcmp - Compare Attributes & Data of Input 1 and Input 2
  30. %
  31. % DESCRIPTION
  32. % .I ksegcmp
  33. % compares the data and attributes between two input data objects,
  34. % (i1) and (i2), and prints their differences. The data within
  35. % the specified data segments is compared point by point, allowing
  36. % for precise comparisons of data objects independent of file format or
  37. % machine architecture.
  38. %
  39. % The user can specify either that all of the data segments contained in both
  40. % objects be compared, or that only specific data segments be compared.
  41. % The specific polymorphic segments value (val), mask (mask), location
  42. % (location), time (time), and map (map) can be called out for comparison,
  43. % along with an user-specified segment name (segment).
  44. %
  45. % The comparison of two segments can only be performed if the segments
  46. % are of the same size and dimensionality. If the data types of the two
  47. % segments differ, the user can specify that the data be compared in the
  48. % higher of the two data types (cast). Additionally, a +/- comparison
  49. % tolerance can be specified (t). For complex comparisons, this tolerance
  50. % is applied to both the real and imaginary parts of the values.
  51. %
  52. % If desired, the attributes of each segment can be compared (sat).
  53. % The segment attributes such as size, dimension, and data type, are not
  54. % compared by here since they would have already been compared during the
  55. % data comparison.
  56. % Also if desired, the object-level attributes, such as the comment, can
  57. % be compared (oat). The date attribute is ignored in this comparison
  58. % since it is almost always different.
  59. %
  60. % The program will print the results of the comparison in ASCII either to an
  61. % user-specified file (o) or, if no file is specified, to kstdout.
  62. %
  63. % The program can optionally print a summary of the differences it finds between
  64. % each data segment (psum). The program can also optionally print a detailed
  65. % report on the specific differences found in each segment.
  66. % At the very minimum, a simple one line report on whether the data objects were
  67. % determined to be different or identical will be printed.
  68. % If no output at all is desired, the program can told to run silently (s).
  69. %
  70. % The summary printed for each compared segment reports such things as
  71. % differences in size or data type, as well as the number of points
  72. % that were determined to be different.
  73. %
  74. % The precise report of the specific points that were found to be different
  75. % between two data segments will be printed in the following format :
  76. %
  77. % [POSITION]
  78. %
  79. % < Input #1 Value (Input #1 Data Type)
  80. %
  81. % > Input #2 Value (Input #2 Data Type)
  82. %
  83. % The user may specify which components of this precise report are printed
  84. % with the use of different flags. The position (pos), the value at that
  85. % position in the segment from input 1 (i1val), the value at that position
  86. % in the segment from input 2 (i2val), along with the data types of the values
  87. % (i1type) and (i2type) can all be specified to be in the detailed report.
  88. % Note that this program does not allow for the data types of either segment to
  89. % be printed without their values, because that provides no information.
  90. %
  91. % If desired, the exit return status of the program can be set to indicate
  92. % whether the data objects were determined to be different or identical (rt).
  93. % A KEXIT_SUCCESS (0) exit status is used to indicate that the objects
  94. % were identical, while a KEXIT_FAILURE (1) exit status is used to indicate
  95. % that they are different.
  96. %
  97. % Also if desired, this routine can return the exit status to a Cantata
  98. % variable for use in conditional visual programming operations (var).
  99. %
  100. % The comparison is performed "intelligently" using data services, so that
  101. % that the entire data set from either data object is never read into
  102. % memory at one time. This allows very large data objects to be compared
  103. % on machines with limited virtual memory.
  104. %
  105. %
  106. %
  107. % EXAMPLES
  108. % ksegcmp -i1 image:ball -i2 image:moon -val -t 220 -pos -i1val -i2val
  109. %
  110. % will compare the value segment of the ball image with the value segment
  111. % of the moon image with a comparison tolerance of +/- 220.0.
  112. % The position and values of the eight points that are different will be printed.
  113. %
  114. % "SEE ALSO"
  115. % kcpseg, kcptoval, kcpfromval
  116. %
  117. % RESTRICTIONS
  118. % ksegcmp is not yet able to return a variable to Cantata.
  119. % The segment list when all segments are compared is constructed from
  120. % the first input object. If the second object contains segments which
  121. % are not contained in the first object, the comparison will miss them.
  122. %
  123. % REFERENCES
  124. % none
  125. %
  126. % COPYRIGHT
  127. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  128. %
  129. function varargout = kksegcmp(varargin)
  130. if nargin ==0
  131. Inputs={};arglist={'',''};
  132. elseif nargin ==1
  133. Inputs=varargin{1};arglist={'',''};
  134. elseif nargin ==2
  135. Inputs=varargin{1}; arglist=varargin{2};
  136. else error('Usage: [out1,..] = kksegcmp(Inputs,arglist).');
  137. end
  138. if size(arglist,2)~=2
  139. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  140. end
  141. narglist={'i1', '__input';'i2', '__input';'cast', 0;'s', 0;'pos', 0;'i1val', 0;'i1type', 0;'i2val', 0;'i2type', 0;'o', '__output';'var', 'equal';'all', 0;'val', 0;'mask', 0;'loc', 0;'time', 0;'map', 0;'segment', 'value'};
  142. maxval={0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0};
  143. minval={0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0};
  144. istoggle=[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
  145. was_set=istoggle * 0;
  146. paramtype={'InputFile','InputFile','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','OutputFile','String','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','String'};
  147. % identify the input arrays and assign them to the arguments as stated by the user
  148. if ~iscell(Inputs)
  149. Inputs = {Inputs};
  150. end
  151. NumReqOutputs=0; nextinput=1; nextoutput=1;
  152. for ii=1:size(arglist,1)
  153. wasmatched=0;
  154. for jj=1:size(narglist,1)
  155. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  156. wasmatched = 1;
  157. was_set(jj) = 1;
  158. if strcmp(narglist{jj,2}, '__input')
  159. if (nextinput > length(Inputs))
  160. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  161. end
  162. narglist{jj,2} = 'OK_in';
  163. nextinput = nextinput + 1;
  164. elseif strcmp(narglist{jj,2}, '__output')
  165. if (nextoutput > nargout)
  166. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  167. end
  168. if (isempty(arglist{ii,2}))
  169. narglist{jj,2} = 'OK_out';
  170. else
  171. narglist{jj,2} = arglist{ii,2};
  172. end
  173. nextoutput = nextoutput + 1;
  174. if (minval{jj} == 0)
  175. NumReqOutputs = NumReqOutputs - 1;
  176. end
  177. elseif isstr(arglist{ii,2})
  178. narglist{jj,2} = arglist{ii,2};
  179. else
  180. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  181. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  182. end
  183. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  184. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  185. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  186. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  187. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  188. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  189. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  190. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  191. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  192. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  193. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  194. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  195. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  196. end
  197. end
  198. end
  199. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  200. narglist{jj,2} = arglist{ii,2};
  201. end
  202. end
  203. end
  204. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  205. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  206. end
  207. end
  208. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  209. for jj=1:size(narglist,1)
  210. if strcmp(paramtype{jj}, 'Toggle')
  211. if (narglist{jj,2} ==0)
  212. narglist{jj,1} = '';
  213. end;
  214. narglist{jj,2} = '';
  215. end;
  216. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  217. narglist{jj,1} = '';
  218. narglist{jj,2} = '';
  219. end;
  220. if strcmp(narglist{jj,2}, '__input')
  221. if (minval{jj} == 0) % meaning this input is required
  222. if (nextinput > size(Inputs))
  223. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  224. else
  225. narglist{jj,2} = 'OK_in';
  226. nextinput = nextinput + 1;
  227. end
  228. else % this is an optional input
  229. if (nextinput <= length(Inputs))
  230. narglist{jj,2} = 'OK_in';
  231. nextinput = nextinput + 1;
  232. else
  233. narglist{jj,1} = '';
  234. narglist{jj,2} = '';
  235. end;
  236. end;
  237. else
  238. if strcmp(narglist{jj,2}, '__output')
  239. if (minval{jj} == 0) % this is a required output
  240. if (nextoutput > nargout & nargout > 1)
  241. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  242. else
  243. narglist{jj,2} = 'OK_out';
  244. nextoutput = nextoutput + 1;
  245. NumReqOutputs = NumReqOutputs-1;
  246. end
  247. else % this is an optional output
  248. if (nargout - nextoutput >= NumReqOutputs)
  249. narglist{jj,2} = 'OK_out';
  250. nextoutput = nextoutput + 1;
  251. else
  252. narglist{jj,1} = '';
  253. narglist{jj,2} = '';
  254. end;
  255. end
  256. end
  257. end
  258. end
  259. if nargout
  260. varargout = cell(1,nargout);
  261. else
  262. varargout = cell(1,1);
  263. end
  264. global KhorosRoot
  265. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  266. w=['"' KhorosRoot];
  267. else
  268. if ispc
  269. w='"C:\Program Files\dip\khorosBin\';
  270. else
  271. [s,w] = system('which cantata');
  272. w=['"' w(1:end-8)];
  273. end
  274. end
  275. [varargout{:}]=callKhoros([w 'ksegcmp" '],Inputs,narglist);