⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fm_uninstall.m

📁 电力系统分析计算程序
💻 M
字号:
function fm_uninstall% FM_UNINSTALL remove an user defined component%% FM_UNINSTALL%%see also FM_INSTALL, FM_MAKE, FM_BUILD%%Author:    Federico Milano%Date:      11-Nov-2002%Version:   1.0.0%%E-mail:    Federico.Milano@uclm.es%Web-site:  http://www.uclm.es/area/gsee/Web/Federico%% Copyright (C) 2002-2008 Federico Milanoglobal Algeb Buses Initl Param Servc Stateglobal Fig Comp Settings Patherror_vect = [];error_number = 0;lasterr('');if Fig.update == 0; Fig.update = fm_update; endstring_update = cell(13,1);hdl_lista = findobj(Fig.update,'Tag','Listbox1');if strcmp(Path.psat(1),'~')  pathpsat = [getenv('HOME'),Path.psat(2:end)];else  pathpsat = Path.psat;end% structure and file namesc_name = lower(Comp.name);c_name(1) = upper(c_name(1));f_name = ['fm_',lower(Comp.name)];string_update{1,1} = ['Erasing "fm_', Comp.name, '.m" settings from system files...'];set(hdl_lista,'String',string_update);% ************************************************************************************% update file comp.inifile = textread([pathpsat,'comp.ini'],'%s','delimiter','\n','whitespace','');fid = fopen([pathpsat,'comp.ini'],'wt');nrows = length(file);form = '%s\n';for i = 1:nrows  if i == nrows, form = '%s'; end  if isempty(findstr(file{i},f_name)), fprintf(fid,form,file{i}); endendfclose(fid);string_update{2,1} = 'System file "comp.ini" updated.';set(hdl_lista,'String',string_update);% ************************************************************************************% update function fm_ncomp.mfile = textread([pathpsat,'fm_ncomp.m'],'%s','delimiter','\n','whitespace','');fid = fopen([pathpsat,'fm_ncomp.m'],'wt');c2 = 1;nrows = length(file);form = '%s\n';for i = 1:nrows  if i == nrows, form = '%s'; end  c1 = isempty(findstr(file{i},c_name));  if ~c1 & c2, c2 = 0; end  c3 = isempty(findstr(file{i},'end'));  if c2, fprintf(fid,form,file{i}); end  if ~c3 & ~c2, c2 = 1; endendfclose(fid);string_update{3,1} = 'System file "fm_ncomp.m" updated.';set(hdl_lista,'String',string_update);% ************************************************************************************% update function fm_inilf.mfile = textread([pathpsat,'fm_inilf.m'],'%s','delimiter','\n','whitespace','');fid = fopen([pathpsat,'fm_inilf.m'],'wt');nrows = length(file);form = '%s\n';for i = 1:nrows  if i == nrows, form = '%s'; end  if isempty(findstr(file{i},c_name)), fprintf(fid,form,file{i}); endendfclose(fid);string_update{4,1} = 'System file "fm_inilf.m" updated.';set(hdl_lista,'String',string_update);% ************************************************************************************% update function fm_var.mfile = textread([pathpsat,'fm_var.m'],'%s','delimiter','\n','whitespace','');fid = fopen([pathpsat,'fm_var.m'],'wt');nrows = length(file);form = '%s\n';for i = 1:nrows  if i == nrows, form = '%s'; end  c1 = isempty(findstr(file{i},c_name));  c2 = isempty(findstr(file{i},Comp.descr)) | length(file{i}) < length(Comp.descr);  if c1 & c2, fprintf(fid,form,file{i}); endendfclose(fid);string_update{5,1} = 'System file "fm_var.m" updated.';set(hdl_lista,'String',string_update);% ************************************************************************************% update file namevarx.inifile = textread([pathpsat,'namevarx.ini'],'%s','delimiter','\n','whitespace','');fid = fopen([pathpsat,'namevarx.ini'],'wt');nrows = length(file);form = '%s\n';for i = 1:nrows  if i == nrows, form = '%s'; end  if isempty(findstr(file{i},c_name)), fprintf(fid,form,file{i}); endendfclose(fid);string_update{6,1} = 'Data file "namevarx.ini" updated.';set(hdl_lista,'String',string_update);% ************************************************************************************% update function fm_dynlf.mfile = textread([pathpsat,'fm_dynlf.m'],'%s','delimiter','\n','whitespace','');fid = fopen([pathpsat,'fm_dynlf.m'],'wt');c2 = 1;n = 0;nrows = length(file);form = '%s\n';for i = 1:nrows  if i == nrows, form = '%s'; end  c1 = isempty(findstr(file{i},c_name));  if ~c1 & c2, c2 = 0; end  c3 = isempty(findstr(file{i},'end'));  if c2, fprintf(fid,form,file{i}); end  if ~c3 & ~c2, n=n+1; end  if n == 2, c2 = 1; endendfclose(fid);string_update{7,1} = 'System file "fm_dynlf.m" updated.';set(hdl_lista,'String',string_update);% ************************************************************************************% update function fm_dynidx.mfile = textread([pathpsat,'fm_dynidx.m'],'%s','delimiter','\n','whitespace','');fid = fopen([pathpsat,'fm_dynidx.m'],'wt');c2 = 1;n = 0;nrows = length(file);form = '%s\n';for i = 1:nrows  if i == nrows, form = '%s'; end  c1 = isempty(findstr(file{i},c_name));  if ~c1 & c2, c2 = 0; end  c3 = isempty(findstr(file{i},'end'));  if c2, fprintf(fid,form,file{i}); end  if ~c3 & ~c2, n=n+1; end  if n == 2, c2 = 1; endendfclose(fid);string_update{8,1} = 'System file "fm_dynidx.m" updated.';set(hdl_lista,'String',string_update);% ************************************************************************************% update script file Contents.mfile = textread([pathpsat,'Contents.m'],'%s','delimiter','\n','whitespace','');fid = fopen([pathpsat,'Contents.m'],'wt');nrows = length(file);form = '%s\n';for i = 1:nrows  if i == nrows, form = '%s'; end  if isempty(findstr(file{i},f_name)), fprintf(fid,form,file{i}); endendfclose(fid);string_update{9,1} = 'Contents file for on line help updated.';set(hdl_lista,'String',string_update);% ************************************************************************************% no need of updating file service.ini:string_update{10,1} = 'File Data "service.ini" updated.';set(hdl_lista,'String',string_update);% ************************************************************************************% update function fm_xfirst.mfile = textread([pathpsat,'fm_xfirst.m'],'%s','delimiter','\n','whitespace','');fid = fopen([pathpsat,'fm_xfirst.m'],'wt');c2 = 1;nrows = length(file);form = '%s\n';for i = 1:nrows  if i == nrows, form = '%s'; end  c1 = isempty(findstr(file{i},c_name));  if ~c1 & c2, c2 = 0; end  c3 = isempty(findstr(file{i},'end'));  if c2, fprintf(fid,form,file{i}); end  if ~c3 & ~c2, c2 = 1; endendfclose(fid);string_update{11,1} = 'System file "fm_xfirst.m" updated.';set(hdl_lista,'String',string_update);% ************************************************************************************% update script file psat.mfile = textread([pathpsat,'psat.m'],'%s','delimiter','\n','whitespace','');fid = fopen([pathpsat,'psat.m'],'wt');nrows = length(file);form = '%s\n';for i = 1:nrows  if i == nrows, form = '%s'; end  if isempty(findstr(file{i},c_name)), fprintf(fid,form,file{i}); endendfclose(fid);string_update{12,1} = 'File Data "psat.m" updated.';set(hdl_lista,'String',string_update);% ****************************************************************************************% update structure VarnameVarname.unamex = '';Varname.fnamex = '';Varname.compx = '';Varname.unamey = '';Varname.fnamey = '';Varname.compy = '';failed = 0;fid = fopen([pathpsat,'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{13,1} = 'Structure "Varname" updated.';endif failed  string_update{13,1} = 'Error: Structure "Varname" could not be updated.';else  string_update{13,1} = 'Structure "Varname" updated.';endset(hdl_list,'String',string_update);% *************************************************************************% update structure CompComp.names = '';Comp.prop = '';Comp.n = 0;fid = fopen([pathpsat,'comp.ini'], 'rt');if fid == -1,  string_update{14,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 0];  Comp.names{ncomp+2} = 'SW';  Comp.prop(ncomp+2,:) = [2 1 0 0 0 1 0 0];  Comp.n = ncomp+2;  string_update{14,1} = 'Structure "Comp" updated.';endset(hdl_list,'String',string_update);% last operationsstring_update{end+1,1} = ['Component ',c_name,' uninstalled.'];set(hdl_lista,'String',string_update);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -