PageRenderTime 59ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kkimportasc.m

http://github.com/aludnam/MATLAB
Objective C | 387 lines | 384 code | 3 blank | 0 comment | 58 complexity | bca0bfc63fe4d423dc704110ee7ab4b1 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkimportasc 'Import ASCII Data File to Data Segment'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kimportasc.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 input file to start importing at'
  8. % Integer: sf 'Skip Factor ', default: 0: 'number of points in ASCII file to skip between reads'
  9. % Integer: nr 'Number of Reads ', default: 1: 'number of points in ASCII file to read between skips'
  10. % Integer: dim 'Segment Dimension ', default: 5: 'dimension of the segment'
  11. % OutputFile: o 'Output Object', required: 'output data object'
  12. % Integer: wsize 'WIDTH ', default: 1: 'size of width dimension in index specified'
  13. % Integer: hsize 'HEIGHT ', default: 1: 'size of height dimension in index specified'
  14. % Integer: dsize 'DEPTH ', default: 1: 'size of depth dimension in index specified'
  15. % Integer: tsize 'TIME ', default: 1: 'size of time dimension in index specified'
  16. % Integer: esize 'ELEMENTS ', default: 1: 'size of elements dimension in index specified'
  17. %
  18. % Example: o = kkimportasc({i1, i2}, {'i1','';'i2','';'so',0;'sf',0;'nr',1;'dim',5;'o','';'wsize',1;'hsize',1;'dsize',1;'tsize',1;'esize',1})
  19. %
  20. % Khoros helpfile follows below:
  21. %
  22. % PROGRAM
  23. % kimportasc - Import ASCII Data File to Data Segment
  24. %
  25. % DESCRIPTION
  26. % This routine will import an ASCII data file and insert it into a
  27. % specified data object. The new segment will be inserted into this
  28. % data object. If a source object was specified, then all of its data
  29. % segments and the global object attributes will be copied to the
  30. % destination. If no source object was specified, then the resulting
  31. % output object will contain only the imported segment.
  32. % There are four attributes of the new segment that can be specified:
  33. % dimension, index order, size and data type. The number of indices
  34. % and sizes specified must be equal to the dimension.
  35. % The parameter dimension must be greater than 0 and and less than or
  36. % equal to 5.
  37. % The segment size is an optional argument specified by five different
  38. % size variables: 'wsize', 'hsize', 'dsize', 'tsize', and 'esize'. Each size
  39. % variable must be >= to 1. Note that although the size variables are
  40. % optional, if no size variables are specified, the output will be of
  41. % size 1.
  42. % The index order is also specified by five different variables:
  43. % 'windex', 'hindex', 'dindex', 'tindex', and 'eindex'. The value for each
  44. % index variable must be unique and range from 1 to 5. Note that the index
  45. % order dictates how data is stored and retrieved. For example if the
  46. % index order is specified as windex 1, hindex 2, dindex 3, tindex 4,
  47. % eindex 5 then data will be accessed along width first, followed by height,
  48. % depth, time, and elements. If, however the index order is specified as
  49. % eindex 1, windex 2, hindex 3, dindex 4, tindex 5 then data will be accessed
  50. % along elements first, followed by width, height, depth, and time.
  51. % The start offset specifies the point in the ASCII data from which to
  52. % start importing in the data into the specified segment. All points before
  53. % the start offset are ignored.
  54. % The skip factor specifies the number of points to skip in the ASCII data
  55. % between reads.
  56. % The number of reads specifies the number of points to read before skipping.
  57. % For example, if the number of reads is 2 and the skip factor is 3, two
  58. % values will be read, three will be skipped, followed by two more reads,
  59. % three skips, etc. until all the data has been read.
  60. % If the segment_name is one of the Polymorphic segments, the correct
  61. % dimensionality must be provided :
  62. %
  63. % Segment Name Dimension
  64. % ---------------------------------------------------
  65. % KDA_SEGMENT_VALUE 5
  66. % KDA_SEGMENT_MAP 5
  67. % KDA_SEGMENT_MASK 5
  68. % KDA_SEGMENT_LOCATION 4
  69. % KDA_SEGMENT_TIME 1
  70. %
  71. % When importing ASCII data to either the value, map, or mask segment, all
  72. % five size variables (wsize, hsize, dsize, tsize, and esize) may be specified
  73. % since these segments are five dimensional. Likewise, a five dimensional
  74. % index order may be provided.
  75. % When importing ASCII data to the locations segment, only four size variables
  76. % (wsize, hsize, dsize, and esize) may be specified since the location segment
  77. % is four dimensional. Likewise only a four dimensional index order (windex,
  78. % hindex, dindex, eindex) may be provided.
  79. % When importing ASCII data to the time segment, only one size variable
  80. % (tsize) may be specified since the location segment is one dimensional.
  81. % Likewise only a one dimensional index order (tindex) may be provided.
  82. % Complex values in ASCII are represented by number pairs, surrounded
  83. % by parenthesis and separated by a comma. These numbered pairs correspond
  84. % to the real and imaginary values respectively. For example, (8, 3) represents
  85. % the complex number 8+3i.
  86. %
  87. %
  88. %
  89. % EXAMPLES
  90. % Consider a simple ASCII input file which looks as follows:
  91. %
  92. % file: "ascii_data"
  93. % 1 2 3 4
  94. % 1 2 3 4
  95. % 1 2 3 4
  96. % 1 2 3 4
  97. % 1 2 3 4
  98. %
  99. % This data can be imported into the 'value' segment in any number of ways which
  100. % is illustrated in the following four examples.
  101. % .I
  102. % Value Segment Example 1
  103. % % kimportasc -i1 ascii_data -o output -wsize 2 -hsize 5 -dsize 1 -tsize 1 -esize 1 -so 0 -sf 1 -nr 1 -windex 1 -hindex 2 -dindex 3 -tindex 4 -eindex 5 -segment value -type 6
  104. % This will import the above ASCII data into the value segment of a polymorphic
  105. % data object such that the size is "2x5x1x1x1", index order is "w,h,d,t,e",
  106. % and data type is integer. The output from kimportasc would conceptually
  107. % look as follows:
  108. %
  109. % 1 3
  110. % 1 3
  111. % 1 3
  112. % 1 3
  113. % 1 3
  114. %
  115. % .I
  116. % Value Segment Example 2
  117. % % kimportasc -i1 ascii_data -o output -wsize 1 -hsize 5 -dsize 1 -tsize 1 -esize 1 -so 1 -sf 3 -nr 1 -windex 1 -hindex 2 -dindex 3 -tindex 4 -eindex 5 -segment value -type 4
  118. % This will import the above ASCII data into the value segment of a polymorphic
  119. % data object such that the size is "1x5x1x1x1", index order is "w,h,d,t,e",
  120. % and data type is short. The output from kimportasc would conceptually
  121. % look as follows:
  122. %
  123. % 2
  124. % 2
  125. % 2
  126. % 2
  127. % 2
  128. %
  129. % .I
  130. % Value Segment Example 3
  131. % % kimportasc -i1 ascii_data -o output -wsize 3 -hsize 5 -dsize 1 -tsize 1 -esize 1 -so 1 -sf 1 -nr 3 -windex 1 -hindex 2 -dindex 3 -tindex 4 -eindex 5 -segment value -type 10
  132. % This will import the above ASCII data into the value segment of a polymorphic
  133. % data object such that the size is "3x5x1x1x1", index order is "w,h,d,t,e",
  134. % and data type is float. The output from kimportasc would conceptually
  135. % look as follows:
  136. %
  137. % 2 3 4
  138. % 2 3 4
  139. % 2 3 4
  140. % 2 3 4
  141. % 2 3 4
  142. %
  143. % .I
  144. % Value Segment Example 4
  145. % % kimportasc -i1 ascii_data -o output -wsize 5 -hsize 4 -dsize 1 -tsize 1 -esize
  146. % 1 -so 0 -sf 0 -nr 20 -segment value -type 8
  147. % This will import the above ASCII data into the value segment of a polymorphic
  148. % data object such that the size is "4x5x1x1x1", index order is "w,h,d,t,e",
  149. % and data type is long. The output from kimportasc would conceptually look
  150. % as follows:
  151. %
  152. % 1 2 3 4 1
  153. % 2 3 4 1 2
  154. % 3 4 1 2 3
  155. % 4 1 2 3 4
  156. %
  157. % The same input data can be imported into the 'map' segment which is
  158. % illustrated in the following example.
  159. % .I
  160. % Map Segment Example
  161. % % kimportasc -i1 ascii_data -i2 data_without_map -o output -wsize 4 -hsize 5 -dsize 1 -tsize 1 -esize 1 -so 0 -sf 0 -nr 1 -windex 1 -hindex 2 -dindex 3 -tindex 4 -eindex 5 -segment map -type 6
  162. % This will import the above ASCII data into the map segment of the polymorphic
  163. % data object specified by the input file "data_without_map" such that the size
  164. % of the map is "4x5x1x1x1", index order is "mw,mh,md,mt,me", and data type is
  165. % integer, where "mw,mh,md,mt,me" coorespond to map width, map height, map depth,
  166. % map time, and map elements respectively. The map segment output from
  167. % kimportasc would conceptually look like the input ASCII data.
  168. %
  169. % 1 2 3 4
  170. % 1 2 3 4
  171. % 1 2 3 4
  172. % 1 2 3 4
  173. % 1 2 3 4
  174. %
  175. % .I
  176. % Mask Segment Example
  177. % The following input data can be imported into the 'mask' segment which is
  178. % illustrated in the following example.
  179. %
  180. % file: "map_ascii_data"
  181. % 1 0 0 1
  182. % 0 0 1 0
  183. % 1 1 0 0
  184. % 1 1 1 1
  185. % 1 0 1 0
  186. %
  187. % % kimportasc -i1 map_ascii_data -i2 data_without_mask -o output -wsize 4 -hsize 5 -dsize 1 -tsize 1 -esize 1 -so 0 -sf 0 -nr 1 -windex 1 -hindex 2 -dindex 3 -tindex 4 -eindex 5 -segment mask -type 6
  188. % This will import the above ASCII data into the mask segment of the polymorphic
  189. % data object specified by the input file "data_without_mask" such that the size
  190. % of the mask is "4x5x1x1x1", index order is "w,h,d,t,e" and data type is
  191. % integer. The mask segment output from kimportasc would conceptually look
  192. % like the ASCII input.
  193. % .I
  194. % Time Segment Example
  195. % The following input data can be imported into the 'time' segment which is
  196. % illustrated in the following example.
  197. %
  198. % file: "time_ascii_data"
  199. % 1 5 10 15 19 36 40 52
  200. %
  201. % % kimportasc -i1 time_ascii_data -i2 data_with_time_series -o output -tsize 8 -so 0 -sf 0 -nr 1 -tindex 1 -segment time -type 6 -dim 1
  202. % This will import the above ASCII data into the time segment of the polymorphic
  203. % data object specified by the input file "data_with_time_series" such that the
  204. % size of the explicit time segment is "8", index order is "t", and data type is
  205. % integer. The time segment output from kimportasc would conceptually look
  206. % like the ASCII input.
  207. % .I
  208. % Location Segment Example
  209. % The following input data can be imported into the 'location'segment which
  210. % is illustrated in the following example.
  211. %
  212. % file: "location_ascii_data"
  213. % 1 3 5 7
  214. % 9 11 13 15
  215. % 17 19 21 23
  216. % 25 27 29 31
  217. % 33 35 37 39
  218. %
  219. % % kimportasc -i1 location_ascii_data -i2 data_without_locations -o output -wsize 4 -hsize 5 -dsize 1 -esize 1 -so 0 -sf 0 -nr 1 -windex 1 -hindex 2 -dindex 3 -eindex 4 -segment location -type 6 -dim 4
  220. % This will import the above ASCII data into the location segment of the
  221. % polymorphic data object specified by the input file "data_without_locations"
  222. % such that the size of the explicit location segment is "4x5x1x1", index
  223. % order is "w,h,d,e", and data type is integer. The location segment output
  224. % from kimportasc would conceptually look like the ASCII input.
  225. %
  226. % "SEE ALSO"
  227. % kasc2val, kasc2mask, kasc2loc, kasc2time, kasc2map
  228. %
  229. % RESTRICTIONS
  230. % If no size variables are specified (wsize, hsize, dsize, tsize, or esize),
  231. % the output data object will be of size 1.
  232. %
  233. % REFERENCES
  234. %
  235. % COPYRIGHT
  236. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  237. %
  238. function varargout = kkimportasc(varargin)
  239. if nargin ==0
  240. Inputs={};arglist={'',''};
  241. elseif nargin ==1
  242. Inputs=varargin{1};arglist={'',''};
  243. elseif nargin ==2
  244. Inputs=varargin{1}; arglist=varargin{2};
  245. else error('Usage: [out1,..] = kkimportasc(Inputs,arglist).');
  246. end
  247. if size(arglist,2)~=2
  248. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  249. end
  250. narglist={'i1', '__input';'i2', '__input';'so', 0;'sf', 0;'nr', 1;'dim', 5;'o', '__output';'wsize', 1;'hsize', 1;'dsize', 1;'tsize', 1;'esize', 1};
  251. maxval={0,1,1,1,2,2,0,2,2,2,2,2};
  252. minval={0,1,1,1,2,2,0,2,2,2,2,2};
  253. istoggle=[0,1,1,1,1,1,0,1,1,1,1,1];
  254. was_set=istoggle * 0;
  255. paramtype={'InputFile','InputFile','Integer','Integer','Integer','Integer','OutputFile','Integer','Integer','Integer','Integer','Integer'};
  256. % identify the input arrays and assign them to the arguments as stated by the user
  257. if ~iscell(Inputs)
  258. Inputs = {Inputs};
  259. end
  260. NumReqOutputs=1; nextinput=1; nextoutput=1;
  261. for ii=1:size(arglist,1)
  262. wasmatched=0;
  263. for jj=1:size(narglist,1)
  264. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  265. wasmatched = 1;
  266. was_set(jj) = 1;
  267. if strcmp(narglist{jj,2}, '__input')
  268. if (nextinput > length(Inputs))
  269. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  270. end
  271. narglist{jj,2} = 'OK_in';
  272. nextinput = nextinput + 1;
  273. elseif strcmp(narglist{jj,2}, '__output')
  274. if (nextoutput > nargout)
  275. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  276. end
  277. if (isempty(arglist{ii,2}))
  278. narglist{jj,2} = 'OK_out';
  279. else
  280. narglist{jj,2} = arglist{ii,2};
  281. end
  282. nextoutput = nextoutput + 1;
  283. if (minval{jj} == 0)
  284. NumReqOutputs = NumReqOutputs - 1;
  285. end
  286. elseif isstr(arglist{ii,2})
  287. narglist{jj,2} = arglist{ii,2};
  288. else
  289. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  290. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  291. end
  292. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  293. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  294. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  295. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  296. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  297. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  298. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  299. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  300. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  301. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  302. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  303. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  304. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  305. end
  306. end
  307. end
  308. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  309. narglist{jj,2} = arglist{ii,2};
  310. end
  311. end
  312. end
  313. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  314. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  315. end
  316. end
  317. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  318. for jj=1:size(narglist,1)
  319. if strcmp(paramtype{jj}, 'Toggle')
  320. if (narglist{jj,2} ==0)
  321. narglist{jj,1} = '';
  322. end;
  323. narglist{jj,2} = '';
  324. end;
  325. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  326. narglist{jj,1} = '';
  327. narglist{jj,2} = '';
  328. end;
  329. if strcmp(narglist{jj,2}, '__input')
  330. if (minval{jj} == 0) % meaning this input is required
  331. if (nextinput > size(Inputs))
  332. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  333. else
  334. narglist{jj,2} = 'OK_in';
  335. nextinput = nextinput + 1;
  336. end
  337. else % this is an optional input
  338. if (nextinput <= length(Inputs))
  339. narglist{jj,2} = 'OK_in';
  340. nextinput = nextinput + 1;
  341. else
  342. narglist{jj,1} = '';
  343. narglist{jj,2} = '';
  344. end;
  345. end;
  346. else
  347. if strcmp(narglist{jj,2}, '__output')
  348. if (minval{jj} == 0) % this is a required output
  349. if (nextoutput > nargout & nargout > 1)
  350. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  351. else
  352. narglist{jj,2} = 'OK_out';
  353. nextoutput = nextoutput + 1;
  354. NumReqOutputs = NumReqOutputs-1;
  355. end
  356. else % this is an optional output
  357. if (nargout - nextoutput >= NumReqOutputs)
  358. narglist{jj,2} = 'OK_out';
  359. nextoutput = nextoutput + 1;
  360. else
  361. narglist{jj,1} = '';
  362. narglist{jj,2} = '';
  363. end;
  364. end
  365. end
  366. end
  367. end
  368. if nargout
  369. varargout = cell(1,nargout);
  370. else
  371. varargout = cell(1,1);
  372. end
  373. global KhorosRoot
  374. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  375. w=['"' KhorosRoot];
  376. else
  377. if ispc
  378. w='"C:\Program Files\dip\khorosBin\';
  379. else
  380. [s,w] = system('which cantata');
  381. w=['"' w(1:end-8)];
  382. end
  383. end
  384. [varargout{:}]=callKhoros([w 'kimportasc" '],Inputs,narglist);