📄 fm_set.m
字号:
function fm_set(varargin)% FM_SET define general settings and operations for% the main window and other utilities%%FM_SET(COMMAND)% COMMAND = 'lf' solves power flow% COMMAND = 'setdata' sets data file% COMMAND = 'opensys' load system% COMMAND = 'savesys' save current system% etc.%%Author: Federico Milano%Date: 11-Nov-2002%Update: 10-Feb-2003%Update: 27-Feb-2003%Version: 1.0.2%%E-mail: fmilano@thunderbox.uwaterloo.ca%Web-site: http://thunderbox.uwaterloo.ca/~fmilano%% Copyright (C) 2002-2006 Federico Milanofm_varcommand = varargin{1};switch command case 'colormap' map = [0 0 0; 0 0 0.5020; 0 0 1.0000; 0.5020 0 0; 0.5020 0 0.5020; 1.0000 0 0; 1.0000 0 1.0000; 0 0.5020 0; 0 0.7530 0.5020; 0.5020 0.5020 0; 0.5020 0.5020 0.5020; 0.7530 0.7530 0.7530; 0 1.0000 0; 0 0.7530 1.0000; 1.0000 1.0000 0; 1.0000 1.0000 1.0000]; set(gcf,'ColorMap',map); case 'delete' Fig.main = 0; Hdl.status = 0; Hdl.text = 0; Hdl.status = 0; Hdl.frame = 0; Hdl.bar = 0; Hdl.axes = 0; case 'keypress' hdl = findobj(gcbf,'Tag','EditCommand'); tasto = get(Fig.main,'CurrentCharacter'); if isempty(tasto), return, end switch double(tasto) case 13 fm_set('command') case 8 testo = get(hdl,'String'); if length(testo) <= 1 testo = ''; else testo = testo(1:end-1); end set(hdl,'String',testo) case 9 set(hdl,'SelectionHighlight','on') case 127 set(hdl,'String','') case 28 stringa = get(hdl,'String'); set(hdl,'String',stringa(1:end-1),'UserData',stringa) case 29 stringa = get(hdl,'String'); set(hdl,'String',stringa(1:end-1),'UserData',stringa) case 27 fm_set('exit') case 30 hdll = findobj(gcbf,'Tag','ListCommand'); stringa = get(hdll,'String'); value = max(get(hdll,'Value')-1,1); if ~strcmp(stringa{value},'<empty>'), set(hdl,'String',stringa{value}), set(hdll,'Value',max(value,1)) end case 31 hdll = findobj(gcbf,'Tag','ListCommand'); stringa = get(hdll,'String'); value = min(get(hdll,'Value')+1,length(stringa)); if ~strcmp(stringa{value},'<empty>'), set(hdl,'String',stringa{value}), set(hdll,'Value',max(value,1)) end otherwise set(hdl,'String',[get(hdl,'String'),tasto]) end case 'exit' uiwait(fm_choice('Quit PSAT?')) if Settings.ok, a = fieldnames(Fig); for i = length(a):-1:1 fig = getfield(Fig,a{i}); if fig, close(fig), end end end case 'setdefault' uiwait(fm_choice('Set Default Values?')); if Settings.ok == 1 hdl1 = findobj(gcbf,'Tag','EditText1'); set(hdl1,'String','50'); Settings.freq = 50; Settings.rad = 2*pi*Settings.freq; hdl2 = findobj(gcbf,'Tag','EditText2'); set(hdl2,'String','100'); Settings.mva = 100; hdl3 = findobj(gcbf,'Tag','EditText3'); set(hdl3,'String','0'); Settings.t0 = 0; hdl4 = findobj(gcbf,'Tag','EditText4'); set(hdl4,'String','30'); Settings.tf = 30; hdl5 = findobj(gcbf,'Tag','EditText5'); set(hdl5,'String','1e-5'); Settings.lftol = 1e-5; hdl6 = findobj(gcbf,'Tag','EditText6'); set(hdl6,'String','20'); Settings.lfmit = 20; hdl7 = findobj(gcbf,'Tag','EditText7'); Settings.dyntol = 1e-5; set(hdl7,'String','1e-5'); hdl8 = findobj(gcbf,'Tag','EditText8'); Settings.dynmit = 20; set(hdl8,'String','20'); Settings.vs = 0; Settings.plot = 1; Settings.red = 1; Settings.showlf = 0; Settings.dlf = 0; Settings.dac = 0; Settings.method = 2; Settings.plottype = 1; fm_disp('Default parameter values set.') else fm_disp('No parameter values resetting.') end case 'savesys' if isempty(Varname.bus) | Settings.init == 0, fm_disp('No system is loaded. ',2), return, end fileout = fm_filenum('out'); filedata = strrep(File.data,'@ ',''); filepert = strrep(File.pert,'@ ',''); pathdata = Path.data; if strcmp(pathdata(1),'~') pathdata = [getenv('HOME'),pathdata(2:end)]; end pathpert = Path.pert; if ~isempty(Path.pert) if strcmp(pathpert(1),'~') pathpert = [getenv('HOME'),pathpert(2:end)]; end end filedata = strrep(filedata,'(mdl)','_mdl'); Source.data = ... strvcat(textread([pathdata,deblank(filedata),'.m'], ... '%s','delimiter', ... '\n','whitespace','')); if ~isempty(Path.pert) Source.pert = ... strvcat(textread([pathpert,deblank(filepert),'.m'], ... '%s','delimiter', ... '\n','whitespace','')); end hdlpert = Hdl.pert; Hdl.pert = ''; save([pathdata,fileout,'.out']) Hdl.pert = hdlpert; fm_disp fm_disp(['System saved in "',Path.data,fileout,'.out"']) case 'closepert' fm_disp(['Perturbation file "',Path.pert,File.pert,'" closed.'],1) Path.pert = ''; File.pert = ''; Source.pert = ''; cd(Path.psat) if Settings.hostver >= 6 Hdl.pert = str2func('pert'); else Hdl.pert = 'pert'; end cd(Path.local) hdltext = findobj(Fig.main,'Tag','EditText10'); set(hdltext,'String','','TooltipString',''); case 'savesettings' [fid,msg] = fopen([Path.psat,'settings.m'],'wt'); if fid == -1 fm_disp(msg) return end fields = fieldnames(Settings); for i = 1:length(fields) if strcmp(fields{i},'color') continue end value = eval(['Settings.',fields{i}]); if isnumeric(value) cout = fprintf(fid,'Settings.%s = %s;\n',fields{i},num2str(value)); else cout = fprintf(fid,'Settings.%s = ''%s'';\n',fields{i},value); end end fields = fieldnames(Theme); for i = 1:length(fields) if strcmp(fields{i},'hdl') continue end value = eval(['Theme.',fields{i}]); if isnumeric(value) cout = fprintf(fid,'Theme.%s = [%s];\n',fields{i},num2str(value)); else cout = fprintf(fid,'Theme.%s = ''%s'';\n',fields{i},value); end end cout = fprintf(fid,'Theme.hdl = zeros(18,1);\n'); fclose(fid); case 'savedata' filedata = [File.data,' ']; if strcmp(filedata([1:2]),'@ ') filedata = deblank(strrep(filedata,'@ ','')); if isempty(Source.data), fm_disp('Cannot restore the data file.'), return, end a = dir([Path.data,'*.m']); b = {a.name}; older = strmatch([filedata,'.m'],b,'exact'); if ~isempty(older) uiwait(fm_choice(['Overwrite Existing File "',filedata,'.m" ?'])) if ~Settings.ok, return, end end try fid = fopen([Path.data,filedata,'.m'],'wt'); if fid == -1, fm_disp(['Cannot write the data file. Check folder ' ... 'authorizations.'],2), return, end catch fm_disp(['Cannot write the data file. Check folder ' ... 'authorizations.'],2) return end rowc = length(Source.data(1,:)); count = fprintf(fid,[repmat('%c',1,rowc),' \n'],Source.data'); fclose(fid); fm_disp(['Data file stored in "',Path.data,filedata,'.m"']) File.data = filedata; hdltext = findobj(Fig.main,'Tag','EditText9'); set(hdltext, ... 'String',File.data, ... 'TooltipString',[Path.data,File.data]); else fm_disp('The current data file is already saved.') end case 'close' stringa = get(findobj(Fig.main,'Tag','PushClose'),'String'); if strcmpi(stringa(end-3:end),'stop') set(Fig.main,'UserData',0) else close(Fig.main) end case 'opensys' if clpsat.init & nargin > 1 file = varargin{2}; pathname = varargin{3}; else if ~isempty(Path.data), cd(Path.data); end [file,pathname] = uigetfile('d*.out',['Select System Data ' ... 'File']); end fm_disp if pathname ~= 0 path2 = Path; fig2 = Fig; hdl2 = Hdl; file2 = File; history2 = History; theme2 = Theme; load([pathname,file],'-mat') dfile = strrep(file,'.out','.m'); pfile = ''; if ~isempty(Source.pert) pfile = strrep(file,'.out','.m'); pfile(1) = 'p'; end fid = fopen([pathname,dfile],'wt+'); if fid == -1, fm_disp(['Cannot write the data file. Check folder ' ... 'authorizations.'],2), else rowc = length(Source.data(1,:)); count = fprintf(fid,[repmat('%c',1,rowc),' \n'],Source.data'); fclose(fid); end if ~isempty(pfile) fid = fopen([pathname,pfile],'wt+'); if fid == -1, fm_disp(['Cannot write the disturbance file. Check folder ' ... 'authorizations.'],2), else rowc = length(Source.pert(1,:)); count = fprintf(fid,[repmat('%c',1,rowc),' \n'],Source.pert'); fclose(fid); cd(pathname) if Settings.hostver >= 6 Hdl.pert = str2func(pfile(1:end-2)); else Hdl.pert = pfile(1:end-2); end cd(Path.local) end end hdl_data = findobj(fig2.main,'Tag','EditText9'); hdl_pert = findobj(fig2.main,'Tag','EditText10'); Fig = fig2; hdlpert = Hdl.pert; Hdl = hdl2; Hdl.pert = hdlpert; History = history2; Theme = theme2; if ~isempty(File.pert), File.pert = ['@ ',pfile(1:end-2)]; %File.pert = strrep(File.pert,'@ @ ','@ '); end File.data = ['@ ',dfile(1:end-2)]; %File.data = strrep(File.data,'@ @ ','@ '); set(hdl_data, ... 'String',File.data, ... 'ForegroundColor',[0 0 0.592], ... 'TooltipString',[Path.data,File.data]); set(hdl_pert, ... 'String',File.pert, ... 'ForegroundColor',[0 0 0.592], ... 'TooltipString',[Path.pert,File.pert]); Path.psat = path2.psat; Path.build = path2.build; Path.local = path2.local; Path.images = path2.images; Path.themes = path2.themes; Path.data = pathname; if ~isempty(File.pert) Path.pert = pathname; else Path.pert = ''; end if Fig.plot > 0, close(Fig.plot), Fig.plot = 0; end fm_disp(['System ',pathname, file,' loaded.'])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -