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

📄 fm_install.m

📁 电力系统的psat
💻 M
📖 第 1 页 / 共 2 页
字号:
      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% ***********************************************************************% update file "fcomp.ini"fid = fopen([Path.psat,'fcomp.ini'], 'rt+');if fid == -1  fm_disp('Cannot open file "fcomp.ini". 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');  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);endfclose(fid);string_update{12,1} = 'File Data "fcomp.ini" updated.';set(hdl_list,'String',string_update);% ***********************************************************************************% 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{13,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{14,1} = 'System file "closepsat.m" updated.';set(hdl_list,'String',string_update);% **********************************************************************% update structure VarnameVarname.uname = '';Varname.fname = '';Varname.comp = '';Varname.fcomp = '';Varname.format = '';failed = 0;fid = fopen([Path.psat,'namevar.ini'], 'rt');if fid == -1,  failed = 1;else  nname = 0;  while 1    sline = fgetl(fid);    if ~ischar(sline), break; end    try      Varname.uname{nname+1,1} = deblank(sline(1:20));      Varname.fname{nname+1,1} = deblank(sline(21:40));      Varname.comp{nname+1,1}  = deblank(sline(41:end));      nname = nname + 1;    end  end  count = fclose(fid);  string_update{15,1} = 'Structure "Varname" updated.';endfid = fopen([Path.psat,'fcomp.ini'], 'rt');if fid == -1,  disp('#Error: File "fcomp.ini" cannot be open.')  failed = 1;else  tipi = 0;  while 1    sline = fgetl(fid);    if ~ischar(sline), break; end    try      tipi = tipi + 1;      Varname.fcomp{tipi,1} = deblank(sline(1:15));      Varname.format{tipi,1} = sline(16:end);    end  end  fclose(fid);endif failed  string_update{15,1} = 'Error: Structure "Varname" could not be updated.';else  string_update{15,1} = 'Structure "Varname" updated.';endset(hdl_list,'String',string_update);% ***********************************************************************************% update structure CompComp.funct = '';Comp.number = '';Comp.prop = '';Comp.n = 0;Comp.shunt = 1;fid = fopen([Path.psat,'comp.ini'], 'rt');if fid == -1,  string_update{16,1} = 'Error: Structure "Comp" could not be updated.';else  ncomp=0;  while 1    sline = fgetl(fid);    if ~ischar(sline), break; end    try      Comp.funct{ncomp+1,1}   = deblank(sline(1:23));      Comp.number{ncomp+1,1} = [deblank(sline(25:44)),'.n'];      Comp.prop(ncomp+1,:) = str2num(sline(46:58));      ncomp=ncomp+1;    end  end  count = fclose(fid);  Comp.funct{ncomp+1}  = 'fm_pv';  Comp.number{ncomp+1} = 'PV.n';  Comp.prop(ncomp+1,:) = [1 1 0 0 0 1 0];  Comp.funct{ncomp+2}  = 'fm_sw';  Comp.number{ncomp+2} = 'SW.n';  Comp.prop(ncomp+2,:) = [1 1 0 0 0 1 0];  Comp.n = ncomp+2;  string_update{16,1} = 'Structure "Comp" updated.';endset(hdl_list,'String',string_update);% last operationsstring_update{end+1,1} = 'Updating operations successfully completed.';set(hdl_list,'String',string_update);

⌨️ 快捷键说明

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