PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kkasc2mask.m

http://github.com/aludnam/MATLAB
Objective C | 207 lines | 204 code | 3 blank | 0 comment | 55 complexity | 674fda01ed06634025c914d6cd28e834 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkasc2mask 'Import ASCII Data File to Mask Segment'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kasc2mask.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'ASCII Input File', required: 'ASCII input data file containing new data segment'
  6. % InputFile: i2 'Data Object Input', optional: 'data object input to insert the new segment into'
  7. % Integer: so 'Start Offset ', default: 0: 'starting point in ASCII file to start importing at'
  8. % Integer: sf 'Skip Factor ', default: 0: 'number of points in ASCII file to skip between reads'
  9. % Integer: wsize ' ', default: 1: 'width size must be > 0'
  10. % Integer: hsize ' ', default: 1: 'height size must be > 0'
  11. % Integer: dsize ' ', default: 1: 'depth size must be > 0'
  12. % Integer: tsize ' ', default: 1: 'time size must be > 0'
  13. % Integer: esize ' ', default: 1: 'elements size must be > 0'
  14. % OutputFile: o 'Output Object', required: 'output data object'
  15. %
  16. % Example: o = kkasc2mask({i1, i2}, {'i1','';'i2','';'so',0;'sf',0;'wsize',1;'hsize',1;'dsize',1;'tsize',1;'esize',1;'o',''})
  17. %
  18. % Khoros helpfile follows below:
  19. %
  20. % PROGRAM
  21. % kasc2mask - Import ASCII Data File to Mask Segment
  22. %
  23. % DESCRIPTION
  24. % This routine will import an ASCII data file and insert it into a data
  25. % object if it is specified. If there is no source object to insert the
  26. % new segment into, the data object specified as the output file will be
  27. % created. The new segment will be inserted into this data object in the
  28. % mask segment. If a source object was specified, then all of its
  29. % data segments and the global object attributes will be copied to the
  30. % destination.
  31. % The index order is specified by setting the -windex, -hindex, -dindex,
  32. % -tindex and -eindex flags. They can not be set to the same value.
  33. % The start offset is the point to start importing in the
  34. % ASCII data. All points before this one are ignored.
  35. % The skip factor is the number of points to skip in the ASCII
  36. % data between reads. If the size of the new segment's lowest
  37. % index is 40 and the skip factor is 5, then this routine will
  38. % read in 40 points skip 5 and read in 40 more, etc. until the
  39. % entire ASCII file read in.
  40. % Complex values in ASCII are represented by number pairs, surrounded
  41. % by parenthesis and separated by a comma. For example, (8, 3) represents
  42. % the complex number 8+3i.
  43. %
  44. %
  45. %
  46. % EXAMPLES
  47. %
  48. % "SEE ALSO"
  49. % kasc2val, kasc2loc, kasc2time, kasc2map, kimportasc
  50. %
  51. % RESTRICTIONS
  52. %
  53. % REFERENCES
  54. %
  55. % COPYRIGHT
  56. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  57. %
  58. function varargout = kkasc2mask(varargin)
  59. if nargin ==0
  60. Inputs={};arglist={'',''};
  61. elseif nargin ==1
  62. Inputs=varargin{1};arglist={'',''};
  63. elseif nargin ==2
  64. Inputs=varargin{1}; arglist=varargin{2};
  65. else error('Usage: [out1,..] = kkasc2mask(Inputs,arglist).');
  66. end
  67. if size(arglist,2)~=2
  68. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  69. end
  70. narglist={'i1', '__input';'i2', '__input';'so', 0;'sf', 0;'wsize', 1;'hsize', 1;'dsize', 1;'tsize', 1;'esize', 1;'o', '__output'};
  71. maxval={0,1,1,1,2,2,2,2,2,0};
  72. minval={0,1,1,1,2,2,2,2,2,0};
  73. istoggle=[0,1,1,1,1,1,1,1,1,0];
  74. was_set=istoggle * 0;
  75. paramtype={'InputFile','InputFile','Integer','Integer','Integer','Integer','Integer','Integer','Integer','OutputFile'};
  76. % identify the input arrays and assign them to the arguments as stated by the user
  77. if ~iscell(Inputs)
  78. Inputs = {Inputs};
  79. end
  80. NumReqOutputs=1; nextinput=1; nextoutput=1;
  81. for ii=1:size(arglist,1)
  82. wasmatched=0;
  83. for jj=1:size(narglist,1)
  84. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  85. wasmatched = 1;
  86. was_set(jj) = 1;
  87. if strcmp(narglist{jj,2}, '__input')
  88. if (nextinput > length(Inputs))
  89. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  90. end
  91. narglist{jj,2} = 'OK_in';
  92. nextinput = nextinput + 1;
  93. elseif strcmp(narglist{jj,2}, '__output')
  94. if (nextoutput > nargout)
  95. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  96. end
  97. if (isempty(arglist{ii,2}))
  98. narglist{jj,2} = 'OK_out';
  99. else
  100. narglist{jj,2} = arglist{ii,2};
  101. end
  102. nextoutput = nextoutput + 1;
  103. if (minval{jj} == 0)
  104. NumReqOutputs = NumReqOutputs - 1;
  105. end
  106. elseif isstr(arglist{ii,2})
  107. narglist{jj,2} = arglist{ii,2};
  108. else
  109. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  110. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  111. end
  112. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  113. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  114. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  115. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  116. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  117. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  118. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  119. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  120. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  121. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  122. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  123. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  124. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  125. end
  126. end
  127. end
  128. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  129. narglist{jj,2} = arglist{ii,2};
  130. end
  131. end
  132. end
  133. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  134. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  135. end
  136. end
  137. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  138. for jj=1:size(narglist,1)
  139. if strcmp(paramtype{jj}, 'Toggle')
  140. if (narglist{jj,2} ==0)
  141. narglist{jj,1} = '';
  142. end;
  143. narglist{jj,2} = '';
  144. end;
  145. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  146. narglist{jj,1} = '';
  147. narglist{jj,2} = '';
  148. end;
  149. if strcmp(narglist{jj,2}, '__input')
  150. if (minval{jj} == 0) % meaning this input is required
  151. if (nextinput > size(Inputs))
  152. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  153. else
  154. narglist{jj,2} = 'OK_in';
  155. nextinput = nextinput + 1;
  156. end
  157. else % this is an optional input
  158. if (nextinput <= length(Inputs))
  159. narglist{jj,2} = 'OK_in';
  160. nextinput = nextinput + 1;
  161. else
  162. narglist{jj,1} = '';
  163. narglist{jj,2} = '';
  164. end;
  165. end;
  166. else
  167. if strcmp(narglist{jj,2}, '__output')
  168. if (minval{jj} == 0) % this is a required output
  169. if (nextoutput > nargout & nargout > 1)
  170. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  171. else
  172. narglist{jj,2} = 'OK_out';
  173. nextoutput = nextoutput + 1;
  174. NumReqOutputs = NumReqOutputs-1;
  175. end
  176. else % this is an optional output
  177. if (nargout - nextoutput >= NumReqOutputs)
  178. narglist{jj,2} = 'OK_out';
  179. nextoutput = nextoutput + 1;
  180. else
  181. narglist{jj,1} = '';
  182. narglist{jj,2} = '';
  183. end;
  184. end
  185. end
  186. end
  187. end
  188. if nargout
  189. varargout = cell(1,nargout);
  190. else
  191. varargout = cell(1,1);
  192. end
  193. global KhorosRoot
  194. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  195. w=['"' KhorosRoot];
  196. else
  197. if ispc
  198. w='"C:\Program Files\dip\khorosBin\';
  199. else
  200. [s,w] = system('which cantata');
  201. w=['"' w(1:end-8)];
  202. end
  203. end
  204. [varargout{:}]=callKhoros([w 'kasc2mask" '],Inputs,narglist);