1 %====================================================================== |
1 %====================================================================== |
2 % S T R U C T 2 A N T S . M |
2 % S T R U C T 2 A N T S . M |
3 % doc: Thu Oct 20 11:48:17 2005 |
3 % doc: Thu Oct 20 11:48:17 2005 |
4 % dlm: Fri Jan 6 09:31:38 2012 |
4 % dlm: Tue Feb 21 14:30:01 2012 |
5 % (c) 2005 A.M. Thurnherr |
5 % (c) 2005 A.M. Thurnherr |
6 % uE-Info: 50 0 NIL 0 0 72 2 2 4 NIL ofnI |
6 % uE-Info: 93 0 NIL 0 0 72 2 2 4 NIL ofnI |
7 %====================================================================== |
7 %====================================================================== |
8 % |
8 % |
9 % export Matlab structure to ANTS file |
9 % export Matlab structure to ANTS file |
10 % |
10 % |
11 % USAGE: struct2ANTS(struct,dependencies,outFileName) |
11 % USAGE: struct2ANTS(struct,dependencies,outFileName) |
30 % - added usage help |
30 % - added usage help |
31 % Jul 23: 2011: - BUG: empty dep did not work |
31 % Jul 23: 2011: - BUG: empty dep did not work |
32 % Jul 24, 2011: - BUG: PARAMS with % did not work |
32 % Jul 24, 2011: - BUG: PARAMS with % did not work |
33 % Jul 25, 2011: - commented out diagnostic message about skipped incompatible vectors |
33 % Jul 25, 2011: - commented out diagnostic message about skipped incompatible vectors |
34 % Dec 30, 2011: - workaround for Matlab R11b bug: /tmp/foo cannot be written, /../tmp/foo can |
34 % Dec 30, 2011: - workaround for Matlab R11b bug: /tmp/foo cannot be written, /../tmp/foo can |
|
35 % Feb 20, 2012: - BUG: diagnostic messages did not show field prefices |
|
36 % - BUG: skipped fields ended up in Layout after all |
|
37 % Feb 21, 2012: - removed double quoting of % and $ |
|
38 % - manually merged two versions |
|
39 % - re-added diagnostic messages about skipped incompatible vectors |
35 |
40 |
36 function [] = struct2ANTS(struct,deps,ofn) |
41 function [] = struct2ANTS(struct,deps,ofn) |
37 |
42 |
38 if nargin ~= 3 |
43 if nargin ~= 3 |
39 help struct2ANTS |
44 help struct2ANTS |
64 fns = char(fname(i)); |
69 fns = char(fname(i)); |
65 f = getfield(struct,fns); |
70 f = getfield(struct,fns); |
66 if isstruct(f) |
71 if isstruct(f) |
67 [ldef,dta] = parseStruct(f,ldef,[fns '.'],dta,ofn); |
72 [ldef,dta] = parseStruct(f,ldef,[fns '.'],dta,ofn); |
68 elseif ischar(f) |
73 elseif ischar(f) |
69 f = strrep(f,'%','%%'); % must quote %s |
|
70 f = strrep(f,'$','\\\$'); % presumably also $s |
|
71 ldef = sprintf('%%%s%s="\\"%s\\"" %s',fpref,fns,f,ldef); |
74 ldef = sprintf('%%%s%s="\\"%s\\"" %s',fpref,fns,f,ldef); |
72 elseif isnumeric(f) |
75 elseif isnumeric(f) |
73 [r c] = size(f); |
76 [r c] = size(f); |
74 if r+c == 2 |
77 if r+c == 2 |
75 ldef = sprintf('%%%s%s=%.15g %s',fpref,fns,f,ldef); |
78 ldef = sprintf('%%%s%s=%.15g %s',fpref,fns,f,ldef); |
76 else |
79 else |
77 ldef = sprintf('%s%s%s= ',ldef,fpref,fns); |
|
78 if isempty(dta), ndta = max(r,c); |
80 if isempty(dta), ndta = max(r,c); |
79 else, ndta = size(dta,1); |
81 else, ndta = size(dta,1); |
80 end |
82 end |
81 if r==1 && length(f)==ndta, dta = [dta,f']; |
83 if r==1 && length(f)==ndta |
82 elseif c==1 && length(f)==ndta, dta = [dta,f]; |
84 ldef = sprintf('%s%s%s= ',ldef,fpref,fns); |
83 else, 1; %disp(sprintf('%s: incompatible %d x %d array %s skipped',ofn,r,c,fns)); |
85 dta = [dta,f']; |
|
86 elseif c==1 && length(f)==ndta |
|
87 ldef = sprintf('%s%s%s= ',ldef,fpref,fns); |
|
88 dta = [dta,f]; |
|
89 else |
|
90 disp(sprintf('%s: incompatible %d x %d array %s%s skipped',ofn,r,c,fpref,fns)); |
84 end |
91 end |
85 end |
92 end |
86 else |
93 else |
87 disp(sprintf('%s: field %s%s skipped',ofn,fpref,fns)); |
94 disp(sprintf('%s: field %s%s skipped',ofn,fpref,fns)); |
88 end |
95 end |