-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfm_dump.m
64 lines (55 loc) · 1.54 KB
/
fm_dump.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function fm_dump
% FM_DUMP dump the current data file to a file
%
%Author: Federico Milano
%Date: 28-Nov-2008
%Version: 1.0.0
%
%E-mail: [email protected]
%Web-site: faraday1.ucd.ie/psat.html
%
% Copyright (C) 2002-2019 Federico Milano
fm_var
filename = [fm_filenum('m'), '.m'];
[fid,msg] = fopen([Path.data,filename], 'wt');
if fid == -1
fm_disp(msg)
return
end
dump_data(fid, Bus, 'Bus')
dump_data(fid, SW, 'SW')
dump_data(fid, PV, 'PV')
for i = 1:(length(Comp.names)-2)
dump_data(fid, eval(Comp.names{i}), Comp.names{i})
end
dump_data(fid, Areas, 'Areas')
dump_data(fid, Regions, 'Regions')
dump_name(fid, Bus.names, 'Bus')
dump_name(fid, Areas.names, 'Areas')
dump_name(fid, Regions.names, 'Regions')
fclose(fid);
fm_disp(['Data dumped to file <', filename ,'>'])
function dump_data(fid, var, name)
if ~var.n, return, end
fprintf(fid, '%s.con = [ ...\n', name);
fprintf(fid, [var.format, ';\n'], var.store.');
fprintf(fid, ' ];\n\n');
function dump_name(fid, var, name)
if isempty(var), return, end
n = length(var);
count = fprintf(fid, [name,'.names = {... \n ']);
for i = 1:n-1
names = strrep(var{i,1},char(10),' ');
names = strrep(var{i,1},'''','''''');
count = fprintf(fid, ['''',names,'''; ']);
if rem(i,5) == 0; count = fprintf(fid,'\n '); end
end
if iscell(var)
names = strrep(var{n,1},char(10),' ');
names = strrep(var{n,1},'''','''''');
count = fprintf(fid, ['''',names,'''};\n\n']);
else
names = strrep(var,char(10),' ');
names = strrep(var,'''','''''');
count = fprintf(fid, ['''',names,'''};\n\n']);
end