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

📄 fm_install.m

📁 电力系统的psat
💻 M
📖 第 1 页 / 共 2 页
字号:
function fm_install% FM_INSTALL install an user defined component%% FM_INSTALL%%see also FM_UNINSTALL, FM_MAKE, FM_BUILD%%Author:    Federico Milano%Date:      11-Nov-2002%Update:    22-Feb-2004%Version:   1.0.1%%E-mail:    fmilano@thunderbox.uwaterloo.ca%Web-site:  http://thunderbox.uwaterloo.ca/~fmilano%% Copyright (C) 2002-2005 Federico Milano%% This toolbox is free software; you can redistribute it and/or modify% it under the terms of the GNU General Public License as published by% the Free Software Foundation; either version 2.0 of the License, or% (at your option) any later version.%% This toolbox is distributed in the hope that it will be useful, but% WITHOUT ANY WARRANTY; without even the implied warranty of% MERCHANDABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU% General Public License for more details.%% You should have received a copy of the GNU General Public License% along with this toolbox; if not, write to the Free Software% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,% USA.global Algeb Buses Initl Param Servc Stateglobal Comp Fig Path% some settingserror_vect = [];error_number = 0;lasterr('');string_update = cell(14,1);if exist(['fm_',Comp.name,'.m']) == 2  string_update{1,1} = ['Component File "fm_', Comp.name,'.m".'];else  fm_choice(['Before updating system files, make sure that the ' ...                 'component function is in the PSAT path.'],2)  fm_disp(['Before updating system files, make sure that the component ' ...           'function is in the PSAT path.'])  returnendif Fig.update == 0; fm_update; endhdl_list = findobj(Fig.update,'Tag','Listbox1');% structure and file namesc_name = lower(Comp.name);c_name(1) = upper(c_name(1));f_name = ['fm_',lower(Comp.name)];okdata = 0;n_serv = 0;for i = 1:Servc.n  if ~strcmp(Servc.type{i},'Input');    okdata = 1;    n_serv = n_serv + 1;  endend% **********************************************************************% update file comp.inifid = fopen([Path.psat,'comp.ini'], 'rt+');if fid == -1  fm_disp('Cannot open file "comp.ini". Check permissions.')endupdate = 1;algeq = 0;limit = 0;for i = 1:length(Algeb.eq)  if ~strcmp(Algeb.eq{i,1},'null'),    algeq = 1;    break  endendfor i = 1:State.n  if ~strcmp(State.limit{i,1},'None') | ~strcmp(State.limit{i,2},'None')    limit = 1;    break  endendwhile 1  sline = fgetl(fid);  if ~ischar(sline), break; end  sline = [sline,blanks(length(f_name))];  if strmatch(f_name,sline(1:length(f_name)),'exact')    update = 0;    break  endendif update  count = fseek(fid,0,'eof');  a = [f_name,blanks(23)];  a = a(1:23);  b = [c_name,blanks(20)];  b = b(1:20);  if algeq,      c = '1 1 ';      else, c = '0 0 ';      end  if State.n,    c = [c, '1 1 ']; else, c = [c, '0 0 ']; end  if limit,      c = [c, '1 '];   else, c = [c, '0 '];   end  if Comp.init,  c = [c, '0 1'];  else, c = [c, '1 0'];  end  if Comp.shunt, c = [c, ' 1'];   else, c = [c, ' 0'];   end  fprintf(fid,['\n%s %s %s'],a,b,c);  comp_prop = num2str(['[',c,']']);endfclose(fid);string_update{2,1} = 'Data File "comp.ini" updated.';set(hdl_list,'String',string_update);% **********************************************************************% update function "fm_ncomp.m"try  if strcmp(Path.psat(1),'~')    pathname = [getenv('HOME'),Path.psat(2:end)];  else    pathname = Path.psat;  end  file = textread([pathname,'fm_ncomp.m'], ...                  '%s','delimiter','\n','whitespace','');  idx1 = strmatch('check = 1;',file,'exact');  idx2 = strmatch(['  ',c_name,'.n'],file);  if isempty(idx2)    file{idx1,1} = [];    file{end+3} = ['global ',c_name];    file{end+1} = sprintf('if ~isempty(%s.con)',c_name);    file{end+1} = sprintf('  %s.n = length(%s.con(:,1));',c_name, ...                          c_name);    if Buses.n == 1      file{end+1} = sprintf('  %s.bus = Bus.int(round(%s.con(:,1)));', ...                            c_name,c_name);    else      for i = 1:Buses.n        file{end+i} = sprintf('  %s.%s = Bus.int(round(%s.con(:,%d)));', ...                              c_name,Buses.name{i},c_name,i);      end    end    if Initl.n | okdata      file{end+1} = sprintf('  %s.dat = zeros(%s.n,%d);', ...              c_name,c_name,Initl.n+n_serv);    end    file{end+1} = 'end';    file{end+1} = ' ';    file{end+1} = 'check = 1;';    fid = fopen([Path.psat,'fm_ncomp.m'], 'wt');    for i=1:length(file)-1, fprintf(fid,'%s\n',file{i,1}); end    fprintf(fid,'%s',file{end,1});    fclose(fid);  endcatch  fm_disp('Cannot rewrite file "fm_ncomp.m". Check file permissions and content.')  returnendstring_update{3,1} = 'System file "fm_ncomp.m" updated.';set(hdl_list,'String',string_update);% *********************************************************************% update function "fm_inilf.m"fid = fopen([Path.psat,'fm_inilf.m'], 'rt+');if fid == -1  fm_disp('Cannot open file "fm_inilf.m". Check permissions.')endupdate = 1;while 1  sline = fgetl(fid);  if ~ischar(sline)    break  end  if findstr([c_name,'.con'],sline)    update = 0;    break  endendif update  fseek(fid,0,'eof');  fprintf(fid,'\n\n%s.con = [];',c_name);  fprintf(fid,'\n%s.n = 0;',c_name);  if Buses.n == 1    fprintf(fid,'\n%s.bus = [];',c_name);  else    for i = 1:Buses.n      fprintf(fid,'\n%s.%s = [];',c_name,Buses.name{i});    end  end  if Initl.n | okdata    fprintf(fid,'\n%s.dat = [];',c_name);  end  for i = 1:State.n    fprintf(fid,'\n%s.%s = [];',c_name,State.name{i,1});  endendfclose(fid);string_update{4,1} = 'System file "fm_inilf.m" updated.';set(hdl_list,'String',string_update);% **********************************************************************% update function "fm_var.m"fid = fopen([Path.psat,'fm_var.m'], 'rt+');if fid == -1  fm_disp('Cannot open file "fm_var.m". Check permissions.')endupdate = 1;while 1  sline = fgetl(fid);  if ~ischar(sline)    break  end  if strmatch(['global ',c_name],sline,'exact');    update = 0    break  endendif update  fseek(fid,0,'eof');  fprintf(fid,['\n\n%%     ',Comp.descr,'\nglobal ',c_name]);endfclose(fid);string_update{5,1} = 'System file "fm_var.m" updated.';set(hdl_list,'String',string_update);% ***********************************************************************% update file "namevar.ini"fid = fopen([Path.psat,'namevar.ini'], 'rt+');if fid == -1  fm_disp('Cannot open file "namevar.ini". Check permissions.')endfor i = 1:State.n  update = 1;  fseek(fid,0,'bof');  while 1    sline = fgetl(fid);    if ~ischar(sline), break; end    if ~isempty(findstr(c_name,sline)) & ...          ~isempty(findstr(State.fn{i,1},sline))      update = 0;      break    end  end  if update    fseek(fid,0,'eof');    nome1 = [State.un{i,1},blanks(19)];    nome2 = [State.fn{i,1},blanks(19)];    fprintf(fid,'\n%s %s %s',nome1(1:19),nome2(1:19),c_name);  endendfclose(fid);string_update{6,1} = 'Data file "namevar.ini" updated.';set(hdl_list,'String',string_update);% ************************************************************************% update functions "fm_dynlf.m" & "fm_dynidx.m"if State.n > 0  if ~Comp.init    fid = fopen([Path.psat,'fm_dynlf.m'], 'rt+');    if fid == -1      fm_disp('Cannot open file "fm_dynlf.m". Check permissions.')    end    update = 1;    while update      sline = fgetl(fid);      if ~ischar(sline), break; end      if findstr([c_name,'.n'],sline); update = 0; end    end    if update      fseek(fid,0,'eof');      fprintf(fid,'\n\nglobal %s',c_name);      fprintf(fid,'\nif %s.n',c_name);      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{7,1} = 'System file "fm_dynlf.m" updated.';    string_update{8,1} = 'Updating of "fm_dynidx.m is not required.';    set(hdl_list,'String',string_update);  else    fid = fopen(['fm_dynidx.m'], 'rt+');    if fid == -1      fm_disp('Cannot open file "fm_dynidx.m". Check permissions.')    end    update = 1;    while 1      sline = fgetl(fid);      if ~ischar(sline), break; end      if 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  %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');

⌨️ 快捷键说明

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