struct2ANTS.m
changeset 9 79a432124b57
parent 5 2e9ce6753135
equal deleted inserted replaced
8:dcc97ece4503 9:79a432124b57
     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: Tue Feb 21 14:30:01 2012
     4 %                    dlm: Mon Mar 18 16:17:52 2013
     5 %                    (c) 2005 A.M. Thurnherr
     5 %                    (c) 2005 A.M. Thurnherr
     6 %                    uE-Info: 93 0 NIL 0 0 72 2 2 4 NIL ofnI
     6 %                    uE-Info: 96 20 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)
    13 % NOTES:
    13 % NOTES:
    14 %	- <dependencies> can be a string of a cell array of strings
    14 %	- <dependencies> can be a string of a cell array of strings
    15 %	- scalar strings & numbers become %PARAMs
    15 %	- scalar strings & numbers become %PARAMs
    16 %	- row and column vectors (which can be mixed) become FIELDs
    16 %	- row and column vectors (which can be mixed) become FIELDs
    17 %	- incompatible vectors, as well as other data types, are skipped
    17 %	- incompatible vectors, as well as other data types, are skipped
       
    18 %	- set global STRUCT2ANTS.verb to true to suppress diagnostic messages
    18 
    19 
    19 % HISTORY:
    20 % HISTORY:
    20 %  Oct 20, 2005: - created
    21 %  Oct 20, 2005: - created
    21 %  Nov 30, 2005: - BUG: string %PARAMs have to be quoted, e.g. if containing +
    22 %  Nov 30, 2005: - BUG: string %PARAMs have to be quoted, e.g. if containing +
    22 %  Apr 19, 2006: - changed output number format according to $# in perlvar(1)
    23 %  Apr 19, 2006: - changed output number format according to $# in perlvar(1)
    35 %  Feb 20, 2012: - BUG: diagnostic messages did not show field prefices
    36 %  Feb 20, 2012: - BUG: diagnostic messages did not show field prefices
    36 %                - BUG: skipped fields ended up in Layout after all
    37 %                - BUG: skipped fields ended up in Layout after all
    37 %  Feb 21, 2012: - removed double quoting of % and $
    38 %  Feb 21, 2012: - removed double quoting of % and $
    38 %				 - manually merged two versions
    39 %				 - manually merged two versions
    39 %				 - re-added diagnostic messages about skipped incompatible vectors
    40 %				 - re-added diagnostic messages about skipped incompatible vectors
       
    41 %  Mar 18, 2013: - added global STRUCT2ANTS.verb
    40 
    42 
    41 function [] = struct2ANTS(struct,deps,ofn)
    43 function [] = struct2ANTS(struct,deps,ofn)
    42 
    44 
    43 	if nargin ~= 3
    45 	if nargin ~= 3
    44 		help struct2ANTS
    46 		help struct2ANTS
    62 
    64 
    63 %======================================================================
    65 %======================================================================
    64 
    66 
    65 function [ldef,dta] = parseStruct(struct,ldef,fpref,dta,ofn);
    67 function [ldef,dta] = parseStruct(struct,ldef,fpref,dta,ofn);
    66 
    68 
       
    69 	global STRUCT2ANTS;
       
    70 	if ~isfield(STRUCT2ANTS,'verb')
       
    71 		STRUCT2ANTS.verb = 1;
       
    72 	end
       
    73 
    67 	fname = fieldnames(struct);
    74 	fname = fieldnames(struct);
    68 	for i=1:length(fname)
    75 	for i=1:length(fname)
    69 		fns = char(fname(i));
    76 		fns = char(fname(i));
    70 		f = getfield(struct,fns);
    77 		f = getfield(struct,fns);
    71 		if isstruct(f)
    78 		if isstruct(f)
    84 					ldef = sprintf('%s%s%s= ',ldef,fpref,fns);
    91 					ldef = sprintf('%s%s%s= ',ldef,fpref,fns);
    85 					dta = [dta,f'];
    92 					dta = [dta,f'];
    86 				elseif c==1 && length(f)==ndta
    93 				elseif c==1 && length(f)==ndta
    87 					ldef = sprintf('%s%s%s= ',ldef,fpref,fns);
    94 					ldef = sprintf('%s%s%s= ',ldef,fpref,fns);
    88 					dta = [dta,f];
    95 					dta = [dta,f];
    89 				else
    96 				elseif STRUCT2ANTS.verb > 0
    90 					disp(sprintf('%s: incompatible %d x %d array %s%s skipped',ofn,r,c,fpref,fns));
    97 					disp(sprintf('%s: incompatible %d x %d array %s%s skipped',ofn,r,c,fpref,fns));
    91 				end
    98 				end
    92 			end
    99 			end
    93 		else
   100 		else
    94 			disp(sprintf('%s: field %s%s skipped',ofn,fpref,fns));
   101 			disp(sprintf('%s: field %s%s skipped',ofn,fpref,fns));