📄 fm_install.m
字号:
fprintf(fid,'\nif %s.n',c_name); for i = 1:State.n fprintf(fid,'\n %s.%s = zeros(%s.n,1);',c_name,State.name{i,1},c_name); end fprintf(fid,'\n for i = 1:%s.n',c_name); for i = 1:State.n fprintf(fid,'\n %s.%s(i) = DAE.n + %d;',c_name, State.name{i,1},i); end fprintf(fid,'\n DAE.n = DAE.n + %d;',State.n); fprintf(fid,'\n end'); fprintf(fid,'\nend'); end fclose(fid); string_update{8,1} = 'System file "fm_dynidx.m" updated.'; string_update{7,1} = 'Updating of "fm_dynlf.m is not required.'; set(hdl_list,'String',string_update); endelse string_update{8,1} = 'Updating of "fm_dynidx.m" is not required (no state variables).'; string_update{7,1} = 'Updating of "fm_dynlf.m is not required (no state variables).'; set(hdl_list,'String',string_update);end% ***********************************************************************% update file "Contents.m"fid = fopen([Path.psat,'Contents.m'], 'rt+');if fid == -1 fm_disp('Cannot open file "Contents.m". Check permissions.')endupdate = 1;while 1 sline = fgetl(fid); if ~ischar(sline), break; end sline = [sline,blanks(length(f_name)+4)]; sline = sline(1:length(f_name)+4); if ~isempty(findstr(sline,['% ',f_name])) update = 0; break endendif update fseek(fid,0,'eof'); fprintf(fid,'\n%% %s - %s',f_name,Comp.descr);endfclose(fid);string_update{9,1} = 'Contents file for on line help updated.';set(hdl_list,'String',string_update);% **********************************************************************% update file "service.ini"fid = fopen([Path.psat,'service.ini'], 'rt+');if fid == -1 fm_disp('Cannot open file "service.ini". Check permissions.')endfor i = 1:Servc.n update = 1; fseek(fid,0,'bof'); if strcmp(Servc.type{i,1},'Input') while 1 sline = fgetl(fid); sline = [sline,blanks(length(Servc.name{i}))] if ~ischar(sline) break end if findstr(Servc.name{i},sline(1:length(Servc.name{i}))) update = 0; break end end if update fseek(fid,0,'eof'); fprintf(fid,['\n',Servc.name{i,1}]); end endendfclose(fid);string_update{10,1} = 'File Data "service.ini" updated.';set(hdl_list,'String',string_update);% ***********************************************************************% update function "fm_xfirst.m"if State.n & ~Comp.init fid = fopen([Path.psat,'fm_xfirst.m'], 'rt+'); if fid == -1 fm_disp('Cannot open file "fm_xfirst.m". Check permissions.') end update = 1; while 1 sline = fgetl(fid); if ~ischar(sline), break; end if ~isempty(findstr([c_name,'.n'],sline)) update = 0; break end end if update fseek(fid,0,'eof'); fprintf(fid,'\n\nglobal %s',c_name); fprintf(fid,'\nif %s.n',c_name); for i = 1:State.n fprintf(fid,'\n DAE.x(%s.%s) = %s*ones(%s.n,1);', ... c_name,State.name{i,1},State.init{i,1},c_name); end fprintf(fid,['\nend']); end fclose(fid); string_update{11,1} = 'System file "fm_xfirst.m" updated.'; set(hdl_list,'String',string_update);else string_update{11,1} = 'Updating System file "fm_xfirst.m" not required.'; set(hdl_list,'String',string_update);end% % ***********************************************************************% if update% fseek(fid,0,'eof');% string = [c_name,blanks(15)];% fprintf(fid,['\n',string(1:15)]);% x_max = [1:State.n];% if State.n% x_idx = strmatch('None',State.limit(:,1),'exact');% x_max(x_idx) = [];% end% x_min = [1:State.n];% if State.n% x_idx = strmatch('None',State.limit(:,2),'exact');% x_min(x_idx) = [];% end% n_xmax = length(x_max); n_xmin = length(x_min);% s_max = [1:Servc.neq];% if Servc.n% s_idx = strmatch('None',Servc.limit(:,1),'exact');% s_max(s_idx) = [];% end% s_min = [1:Servc.neq];% if Servc.n% s_idx = strmatch('None',Servc.limit(:,2),'exact');% s_min(s_idx) = [];% end% n_smax = length(s_max); n_smin = length(s_min);% n_tot_param = 2 + Buses.n + Param.n + n_xmax + n_xmin + n_smax + n_smin;% fprintf(fid,['[repmat(''%%4d '',1,%d), ', ...% 'repmat(''%%8.4f '',1,%d)]'],Buses.n,n_tot_param);% end% ***********************************************************************% update function "psat.m"fid = fopen([Path.psat,'psat.m'], 'rt+');if fid == -1 fm_disp('Cannot open file "psat.m". Check permissions.')endupdate = 1;while 1 sline = fgetl(fid); if ~ischar(sline), break, end sline = [sline,blanks(length(f_name))]; if ~isempty(strmatch(c_name,sline(1:length(c_name)),'exact')) update = 0; break endendif update fseek(fid,0,'eof'); fprintf(fid,'\n%% %s - %s',c_name,Comp.descr); fprintf(fid,'\n%s = struct(''con'',[],''n'',0,',c_name); okdata = 0; for i = 1:Servc.n; if ~strcmp(Servc.type{i},'Input'); okdata = 1; break end end if Initl.n | okdata fprintf(fid,'''dat'',[],',c_name); end if Buses.n == 1 fprintf(fid,'''bus'',[],'); else for i = 1:Buses.n fprintf(fid,'''%s'',[],',Buses.name{i}); end end for i = 1:State.n-1 fprintf(fid,'''%s'',[],',State.name{i,1}); end fprintf(fid,'''%s'',[]);\n',State.name{State.n,1});endfclose(fid);string_update{12,1} = 'System file "psat.m" updated.';set(hdl_list,'String',string_update);% ***********************************************************************************% update function "closepsat.m"fid = fopen([Path.psat,'closepsat.m'], 'rt+');if fid == -1 fm_disp('Cannot open file "closepsat.m". Check permissions.')endupdate = 1;while 1 sline = fgetl(fid); if ~ischar(sline) break end if strmatch(['clear ',c_name],sline,'exact'); update = 0 break endendif update fseek(fid,0,'eof'); fprintf(fid,['\n\n%% ',Comp.descr,'\nclear ',c_name]);endfclose(fid);string_update{13,1} = 'System file "closepsat.m" updated.';set(hdl_list,'String',string_update);% **********************************************************************% update structure VarnameVarname.unamex = '';Varname.fnamex = '';Varname.compx = '';Varname.unamey = '';Varname.fnamey = '';Varname.compy = '';failed = 0;fid = fopen([Path.psat,'namevarx.ini'], 'rt');if fid == -1, failed = 1;else nname = 0; while 1 sline = fgetl(fid); if ~ischar(sline), break; end try Varname.unamex{nname+1,1} = deblank(sline(1:20)); Varname.fnamex{nname+1,1} = deblank(sline(21:40)); Varname.compx{nname+1,1} = deblank(sline(41:end)); nname = nname + 1; end end count = fclose(fid); string_update{14,1} = 'Structure "Varname" updated.';endif failed string_update{14,1} = 'Error: Structure "Varname" could not be updated.';else string_update{14,1} = 'Structure "Varname" updated.';endset(hdl_list,'String',string_update);% ***********************************************************************************% update structure CompComp.names = '';Comp.prop = '';Comp.n = 0;Comp.shunt = 1;Comp.series = 0;fid = fopen([Path.psat,'comp.ini'], 'rt');if fid == -1, string_update{15,1} = 'Error: Structure "Comp" could not be updated.';else ncomp=0; while 1 sline = fgetl(fid); if ~ischar(sline), break; end try Comp.names{ncomp+1,1} = deblank(sline(1:21)); Comp.prop(ncomp+1,:) = str2num(sline(22:38)); ncomp=ncomp + 1; end end count = fclose(fid); Comp.names{ncomp+1} = 'PV'; Comp.prop(ncomp+1,:) = [2 1 0 0 0 1 0]; Comp.names{ncomp+2} = 'SW'; Comp.prop(ncomp+2,:) = [2 1 0 0 0 1 0]; Comp.n = ncomp + 2; string_update{15,1} = 'Structure "Comp" updated.';endset(hdl_list,'String',string_update);% last operationsstring_update{end+1,1} = 'Updating operations completed.';set(hdl_list,'String',string_update);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -