0001 function file = vb_struct2file(p, file)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 if ~isstruct(p)
0024 error('input variable is not struct.');
0025 end
0026
0027
0028
0029
0030 if ~exist('file', 'var')
0031 file = tempname;
0032 end
0033 fid = fopen(file, 'wt');
0034 if fid == -1
0035 error('failed to open file(w)');
0036 end
0037 a = evalc('p');
0038 fprintf(fid, '%s', a);
0039 fclose(fid);
0040
0041
0042
0043
0044 fid = fopen(file);
0045 if fid == -1
0046 error('failed to open file(r).');
0047 end
0048
0049 all = [];
0050 while 1
0051 line = fgetl(fid);
0052 if line == -1, break; end
0053
0054 if strmatch('p =', line), continue; end
0055
0056 if isempty(line), continue; end
0057
0058
0059 field = sscanf(line, ' %s:');
0060 field = strrep(field, ':', '');
0061
0062 para = p.(field);
0063 if ischar(para)
0064 ix = strfind(line, ':');
0065 line = [line(1:ix(1)) ' ' single_quoted_string(para)];
0066 end
0067 all = [all, sprintf('%s\n', line)];
0068 end
0069 fclose(fid);
0070
0071
0072
0073
0074
0075
0076 fid = fopen(file, 'wt');
0077 if fid == -1
0078 error('failed to open file(w)');
0079 end
0080 fprintf(fid, '%s', all);
0081 fclose(fid);
0082
0083
0084
0085 function out_str = single_quoted_string(in_str)
0086
0087 out_str = sprintf('''%s''', in_str);