📄 fm_set.m
字号:
else fm_disp('No loaded system or not existent directory',2) end case 'setdata' Path.temp = Path.data; File.temp = File.data; if Fig.dir set(Fig.dir,'Name','Load Data File') hdl = findobj(Fig.dir,'Tag','Pushbutton1'); set(hdl,'String','Load','Callback','fm_dirset openfile') hdl = findobj(Fig.dir,'Tag','Listbox2'); set(hdl,'Max',0,'ButtonDownFcn','fm_dirset openfile','Value',1) hdl = findobj(Fig.dir,'Tag','Pushbutton3'); set(hdl,'Callback','fm_dirset cancel','String','Cancel') else fm_dir(1) end uiwait(Fig.dir); if Path.temp == 0 fm_disp(['No data file has been selected or file does not exist'],2) return end if strcmp(computer,'GLNX86'), Path.temp = strrep(Path.temp,getenv('HOME'),'~'); end if exist([Path.temp,File.temp(1:end-2)]) == 4 ... & strcmp(File.temp(end-1:end),'.m') fm_choice(['Simulink model with the same name of the ', ... 'selected data exists. No file set.'],2) fm_disp(['Simulink model with the same name of the ', ... 'selected data exists.']) fm_disp('No file data set.',2) else File.data = File.temp; Path.data = Path.temp; a = dir([Path.data,File.data]); File.modify = a.date; if ~isempty(findstr(File.data,'.mdl')) exist(File.data(1:end-4)); File.data = strrep(File.data,'.mdl','(mdl)'); end File.data = strrep(File.data,'.m',''); hdltext = findobj(Fig.main,'Tag','EditText9'); set(hdltext,'String',File.data, ... 'TooltipString',[Path.data,File.data]); if ~isempty(findstr(File.data,'(mdl)')) set(hdltext,'ForegroundColor',[0 0.592 0]) else set(hdltext,'ForegroundColor',Theme.color07) end fm_disp(['Data file "',Path.data,File.data,'" set'],1) Settings.init = 0; end case 'setpert' Path.temp = Path.pert; File.temp = File.pert; if Fig.dir set(Fig.dir,'Name','Load Data File') hdl = findobj(Fig.dir,'Tag','Pushbutton1'); set(hdl,'String','Load','Callback','fm_dirset openfile') hdl = findobj(Fig.dir,'Tag','Listbox2'); set(hdl,'Max',0,'ButtonDownFcn','fm_dirset openfile','Value',1) hdl = findobj(Fig.dir,'Tag','PopupMenu1'); set(hdl,'Enbale','inactive','Value',3) hdl = findobj(Fig.dir,'Tag','Pushbutton3'); set(hdl,'Callback','fm_dirset cancel','String','Cancel') else fm_dir(2) end uiwait(Fig.dir); if Path.temp == 0 fm_disp('No perturbation file selected or file does not exist',2) else Path.pert = Path.temp; File.pert = File.temp; if strcmp(computer,'GLNX86'), Path.pert = strrep(Path.pert,getenv('HOME'),'~'); end cd(Path.pert) lfile = length(File.pert); File.pert = File.pert(1:lfile-2); if Settings.hostver >= 6 Hdl.pert = str2func(File.pert); else Hdl.pert = File.pert; end cd(Path.local) hdltext = findobj(Fig.main,'Tag','EditText10'); set(hdltext,'String',File.pert, ... 'ForegroundColor',Theme.color07, ... 'TooltipString',[Path.pert,File.pert]); fm_disp(['Perturbation file "',Path.pert,File.pert,'" set'],1) end case 'command' hdl = findobj(gcbf,'Tag','EditCommand'); stringa = get(hdl,'String'); set(hdl,'String',''); hdl = findobj(gcbf,'Tag','ListCommand'); comandi = get(hdl,'String'); if strcmp(comandi{1},'<empty>'), comandi{1,1} = stringa; else, comandi{end+1,1} = stringa; end if length(comandi) > 100, comandi(1) = []; end set(hdl,'String',comandi,'Value',length(comandi)); if strcmp(stringa,'command'), fm_disp('Invalid command',2), return, end if strcmp(stringa,'<empty>'), return, end try try, eval(['fm_set ',stringa]) catch, eval(stringa); fm_disp(['Command "',stringa,'" executed.']) end catch fm_disp(lasterr,2) end case 'listcommand' if strcmp(get(Fig.main,'SelectionType'),'open') hdl = findobj(gcbf,'Tag','ListCommand'); stringa = get(hdl,'String'); value = get(hdl,'Value'); hdl = findobj(gcbf,'Tag','EditCommand'); set(hdl,'String',stringa{value}); fm_set('command') end case 'lf' if isempty(File.data), fm_disp('Set a data file before running Power Flow.',2), return, end if Fig.main hdl1 = findobj(Fig.main,'Tag','EditText1'); Settings.freq = str2num(get(hdl1,'String')); Settings.rad = 2*pi*Settings.freq; hdl2 = findobj(Fig.main,'Tag','EditText2'); Settings.mva = str2num(get(hdl2,'String')); hdl3 = findobj(Fig.main,'Tag','EditText3'); Settings.t0 = str2num(get(hdl3,'String')); hdl4 = findobj(Fig.main,'Tag','EditText4'); Settings.tf = str2num(get(hdl4,'String')); hdl5 = findobj(Fig.main,'Tag','EditText5'); Settings.lftol = str2num(get(hdl5,'String')); hdl6 = findobj(Fig.main,'Tag','EditText6'); Settings.lfmit = str2num(get(hdl6,'String')); end filedata = strrep([File.data,' '],'@ ',''); if ~isempty(findstr(filedata,'(mdl)')) filedata1 = File.data(1:end-5); open_sys = find_system('type','block_diagram'); OpenModel = sum(strcmp(open_sys,filedata1)); if OpenModel if strcmp(get_param(filedata1,'Dirty'),'on') | ... str2num(get_param(filedata1,'ModelVersion')) > Settings.mv, check = sim2psat; if ~check, return, end end end end try cd(Path.data) catch fm_disp('Data folder does not exist (maybe it was removed).',2) return end filedata = deblank(strrep(filedata,'(mdl)','_mdl')); a = exist(filedata); if ~a fm_disp('Data file does not exist (maybe it was removed).',2) cd(Path.local) return end if a == 2, lasterr(''); b = dir([filedata,'.m']); %if ~strcmp(File.modify,b.date) | clpsat.readfile if clpsat.readfile try fm_inilf clear(filedata) eval(filedata); File.modify = b.date; catch fm_disp(lasterr), fm_disp(['Something wrong with the data file "',filedata,'"']), cd(Path.local) return end end else fm_disp(['File "',filedata,'" not found or not an m-file'],2) end cd(Path.local) if Settings.static % do not use dynamic components for i = 1:Comp.n comp_con = strrep(Comp.number{i},'.n','.con'); comp_ext = eval(['~isempty(',comp_con,')']); if comp_ext & ~Comp.prop(i,6) eval([comp_con,' = [];']); end end end if Fig.main hdl = findobj(Fig.main,'Tag','EditText3'); time0 = str2num(get(hdl,'String')); if time0 ~= Settings.t0, set(hdl,'String',num2str(Settings.t0)), fm_disp(['Initial simulation time "t0" set to ',num2str(Settings.t0),' s']) end hdl = findobj(Fig.main,'Tag','EditText4'); timef = str2num(get(hdl,'String')); if timef ~= Settings.tf, set(hdl,'String',num2str(Settings.tf)), fm_disp(['Final simulation time "tf" set to ',num2str(Settings.tf),' s']) end set(Fig.main,'Pointer','watch'); end Settings.init = 0; fm_spf if Fig.main, set(Fig.main,'Pointer','arrow'); end SNB.init = 0; LIB.init = 0; CPF.init = 0; OPF.init = 0; % --------------------------------------------------------------------------- %case 'stabrep' %if isempty(Snapshot), return, end %for i = 1:Bus.n; [Istab(i),Vnew(i),angnew(i)]= fm_stab(i,0); %end %fid = fopen([Path.data,'vstab.txt'], 'wt'); %count = fprintf(fid, 'Voltage Stability Index at Network %Buses\n\n'); %count = fprintf(fid, '#bus Index DAE.V %phase\n\n'); %for i = 1:Bus.n % count = fprintf(fid,[fvar(Varname.bus{i},12), % fvar(Istab(i),12), ... % fvar(Vnew(i),12), % fvar(angnew(i),12),'\n']); %end %count = fclose(fid); %fm_text(13,[Path.data,'vstab.txt']) % --------------------------------------------------------------------------- case 'opf' if max(OPF.lmin) > OPF.lmax fm_disp('Lambda_min must be less than Lambda_max.',2) return end [ao,bo] = size(OPF.omega); [al,bl] = size(OPF.lmin); ao = ao*bo; a1 = al*bl; switch OPF.type case 1 OPF.show = 1; if ao > 1, fm_disp(['Single OPF selected. Only the 1th value of ' ... 'the weighting factor will be used.']) end if a1 > 1, fm_disp(['Single OPF selected. Only the 1th value ' ... 'of the min load parameter will be used.']) end OPF.w = OPF.omega(1); OPF.lmin = OPF.lmin(1); if Fig.opf hdl_omeg = findobj(Fig.opf,'Tag','EditText1'); hdl_lmin = findobj(Fig.opf,'Tag','EditText2'); set(hdl_omeg,'String',num2str(OPF.omega_s)) set(hdl_lmin,'String',num2str(OPF.lmin)) end if OPF.w == 0, fm_opfm else, fm_opfsdr end case 2 if ao == 1, OPF.show = 1; OPF.w = OPF.omega; fm_disp(['The weighting factor is scalar. Single OPF will be ' ... 'run.']) if OPF.w == 0, fm_opfm else, fm_opfsdr end else OPF.fun = 'fm_opfsdr'; fm_pareto end case 3, fm_disp('Sorry! Daily forecast not implemented yet ...',2) uiwait(fm_choice('Sorry! Daily forecast not implemented yet ...',2)) case 4, fm_atc case 5, fm_atc end case 'appendV' if isempty(File.data), fm_disp('No data file loaded.',2), return, end filedata = strrep(File.data,'@ ',''); if Settings.init == 0, fm_disp('Run power flow before saving voltages.',2), return, end fid = fopen([Path.data,strrep(filedata,'(mdl)','_mdl'),'.m'],'r+'); count = fseek(fid,0,1); count = fprintf(fid, '\n\n\nBus.con(:,3) = [...\n '); for i = 1:Bus.n-1 count = fprintf(fid,'%10.7f;',DAE.V(i)); if rem(i,5) == 0; count = fprintf(fid,'\n '); end end count = fprintf(fid,'%10.7f];\n\n',DAE.V(Bus.n)); count = fprintf(fid, 'Bus.con(:,4) = [...\n '); for i = 1:Bus.n-1 count = fprintf(fid, '%10.7f;',DAE.a(i)); if rem(i,5) == 0; count = fprintf(fid,'\n '); end end count = fprintf(fid,'%10.7f];\n\n',DAE.a(Bus.n)); for i = 1:SW.n Pg = Settings.mva*Bus.Pg(SW.bus(i))/SW.con(i,2); count = fprintf(fid,'SW.con(%d,10) = %10.7f;\n',i,Pg); end fclose(fid); fm_disp(['Voltages appended in file "',Path.data,File.data,'"']) case 'libpmc' if Settings.hostver >= 7 %& str2num(sps.Version) >= 3.1 warning('off') fm_libpmc warning('on') else fm_choice('Simulink PMC Library cannot be loaded.',2) fm_disp('Simulink PMC Library cannot be loaded.',2) end case 'libsps' sps = ver('powersys'); if isempty(sps) fm_disp('SymPowerSystems is not installed on your system!') fm_disp('The Simulink SPS Library cannot be loaded') return end if Settings.hostver >= 7 & str2num(sps.Version) >= 3.1 warning('off') fm_libsps warning('on') else fm_choice('Simulink SPS Library cannot be loaded.',2) fm_disp('Simulink SPS Library cannot be loaded.',2) end otherwise error('The string is not a valid command')end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -