📄 fm_dirset.m
字号:
namefile = regexprep([namefile,'.m'],'^bdat\.','','ignorecase'); namefile = regexprep(['d_',namefile],'^d*_*','d_'); namefile = regexprep(namefile,'[^\w\.]','_'); case PST namefile = strrep(namefile,'.m','_pst.m'); if ~strcmp(namefile(1), 'd'); namefile = ['d_',namefile]; end case MATPOWER extension = findstr(namefile,'.'); namefile = ['d_',namefile(1:extension(end)-1),'.m']; otherwise namefile = regexprep(['d_',namefile],'^d*_*','d_'); namefile = regexprep(namefile,'^d_d','d_'); namefile = regexprep(namefile,'^d__','d_'); namefile = regexprep(namefile,'[^\w\.]','_'); namefile = regexprep(namefile,'\..+$','.m'); end Path.temp = get(Fig.dir,'UserData'); if ~strcmp(Path.temp(end),filesep) Path.temp = [Path.temp,filesep]; end File.temp = namefile; close(Fig.dir) %================================================================== case 'cancel' Path.temp = 0; File.temp = ''; close(Fig.dir) %================================================================== case 'preview' global File % check whether the selected file is a Simulink model hdl = findobj(Fig.dir,'Tag','PopupMenu1'); type = get(hdl,'Value'); if type ~= PSATMDL cd(Path.local) return end % get the name of the Simulink model hdl = findobj(Fig.dir,'Tag','Listbox2'); numfile = get(hdl,'Value'); if length(numfile) > 1 numfile = numfile(1); temp = get(hdl,'String'); namefile = temp{numfile}; else files = get(hdl,'String'); if iscell(files) namefile = files{numfile}; else namefile = files; end end % make sure that the file name does not start with a number first = double(namefile(1)); if first <= 57 & first >= 48 copyfile(namefile,['d',namefile]) namefile = ['d',namefile]; end oldpath = Path.data; oldfile = File.data; Path.data = pwd; File.data = [namefile(1:end-4),'(mdl)']; hdla = findobj(Fig.dir,'Tag','Axes1'); fm_simrep('DrawModel',0,0,0) if ~isempty(lasterr), return, end %set(hdla,'XLimMode','auto') %set(hdla,'YLimMode','auto') x_lim = get(hdla,'XLim'); y_lim = get(hdla,'YLim'); xl = x_lim(2)-x_lim(1); yl = y_lim(2)-y_lim(1); set(Fig.dir,'Units','pixels') figdim = get(Fig.dir,'Position'); set(Fig.dir,'Units','normalized') dimx = figdim(3)*0.2616; dimy = figdim(4)*0.3468; rl = xl/yl; if dimx > xl & dimy > yl xd = xl/figdim(3); yd = yl/figdim(4); set(hdla,'Position',[0.8358-xd/2, 0.5722-yd/2, xd, yd]); elseif xl > yl xd = 0.2616; yd = 0.3468/rl; set(hdla,'Position',[0.7050, 0.5722-0.1734/rl, xd, yd]); else xd = 0.2616*rl; yd = 0.3468; set(hdla,'Position',[0.8358-0.1308*rl, 0.3988, xd, yd]); end Path.data = oldpath; File.data = oldfile; %================================================================== case 'view' hdl = findobj(Fig.dir,'Tag','Listbox2'); numfile = get(hdl,'Value'); nomefile = get(hdl,'String'); if ~iscell(nomefile), nomefile = cellstr(nomefile); end if strcmp(nomefile{1},'empty') fm_disp('Folder is empty or does not contain files in the selected data format',2) cd(Path.local) return end for i = 1:length(numfile) ext = lower(nomefile{numfile(i),1}(end-2:end)); idx = findstr(ext,'.'); if ~isempty(idx) ext = ext(idx(end)+1:end); end file = nomefile{numfile(i),1}; try switch ext case 'mdl' open_system(file) case 'pdf', switch computer case 'GLNX86', eval(['! xpdf ',file, ' &']), case 'PCWIN', eval(['! acroread ',file, ' &']) otherwise 'SOL2', eval(['! acroread ',file, ' &']) end case '.ps' switch computer case 'GLNX86', eval(['! gsview ',file, ' &']), case 'PCWIN', eval(['! gsview ',file, ' &']) otherwise, eval(['! ghostview ',file, ' &']) end case 'eps' switch computer case 'GLNX86', eval(['! gsview ',file, ' &']), case 'PCWIN', eval(['! gsview ',file, ' &']) otherwise, eval(['! ghostview ',file, ' &']) end case 'doc' switch computer case 'GLNX86', eval(['! AbiWord ',file, ' &']), case 'PCWIN', eval(['! WINWORD ',file, ' &']) otherwise, fm_disp('Unknown viewer on this platform for file "',file,'"') end case 'ppt' switch computer case 'GLNX86', eval(['! AbiWord ',file, ' &']), case 'PCWIN', eval(['! POWERPNT ',file, ' &']) otherwise, fm_disp('Unknown viewer on this platform for file "',file,'"') end case 'dvi' switch computer case 'GLNX86', eval(['! xdvi ',file, ' &']), case 'PCWIN', fm_disp('Unknown viewer on this platform for file "',file,'"') otherwise, eval(['! xdvi ',file, ' &']) end case 'jpg', fm_iview(file) case 'tif', fm_iview(file) case 'gif', fm_iview(file) case 'bmp', fm_iview(file) case 'png', fm_iview(file) case 'hdf', fm_iview(file) case 'pcx', fm_iview(file) case 'xwd', fm_iview(file) case 'ico', fm_iview(file) case 'cur', fm_iview(file) otherwise, fm_text(13,file) end catch fm_disp(['Error in opeining file "',file,'": ',lasterr]) end endendcd(Path.local)%===================================================================function cfile = uform(formato)% codesIEEE = 1;PSAT = 2;PSATPERT = 3;PSATMDL = 4;CYME = 5;MATPOWER = 6;PST = 7;EPRI = 8;PSSE = 9;PSAP = 10;EUROSTAG = 11;TH = 12;CESI = 13;VST = 14;SIMPOW = 15;NEPLAN = 16;DIGSILENT = 17;POWERWORLD = 18;PET = 19;FLOWDEMO = 20;GEEPC = 21;CHAPMAN = 22;UCTE = 23;PCFLO = 24;WEBFLOW = 25;IPSS = 26;CEPEL = 27;ODM = 28;VITRUVIO = 29; % all filesa = dir;numfile = find([a.isdir] == 0);jfile = 1;cfile = [];for i = 1:length(numfile) nomefile = a(numfile(i)).name; lfile = length(nomefile); add_file = 0; switch formato case IEEE extent = nomefile(max(1,lfile-2):lfile); if strcmpi(extent,'dat') | strcmpi(extent,'txt') | ... strcmpi(extent,'.cf'), if isfile(nomefile,'BUS DATA FOLLOW',20) add_file = 1; end end case CYME extent1 = nomefile(max(1,lfile-3):lfile); extent2 = nomefile(max(1,lfile-2):lfile); if strcmpi(extent1,'.nnd') | strcmpi(extent2,'.sf') add_file = 1; end case MATPOWER extent = nomefile(lfile); if strcmpi(extent,'m') if isfile(nomefile,'baseMVA',5), add_file = 1; end end case PSAT extent = nomefile(lfile); if strcmpi(extent,'m') if strcmp(nomefile(1),'d') add_file = 1; elseif isfile(nomefile,'Bus.con',15) add_file = 1; end end case PSATPERT extent = nomefile(lfile); if strcmpi(extent,'m') if strcmp(nomefile(1),'p') add_file = 1; elseif isfile(nomefile,'(t)',5) add_file = 1; end end case PSATMDL extent = nomefile(max(1,lfile-2):lfile); if strcmpi(extent,'mdl') if strcmpi(nomefile,'fm_lib.mdl') add_file = 0; %elseif strcmp(nomefile(1),'d') % add_file = 1; %elseif isfile(nomefile,'PSATblock',1000) %% THIS IS TOO SLOW!! % add_file = 1; else add_file = 1; end end case PST extent = nomefile(lfile); if strcmpi(extent,'m') & strcmp(nomefile(1),'d') if isfile(nomefile,'bus = [',50), add_file = 1; end if ~add_file if isfile(nomefile,'bus=',50), add_file = 1; end end end case EPRI extent = nomefile(max(1,lfile-2):lfile); if strcmpi(extent,'wsc') | strcmpi(extent,'txt') | ... strcmpi(extent,'dat') if isfile(nomefile,'HDG',15) add_file = 1; elseif isfile(nomefile,'/NETWORK_DATA\',20) add_file = 1; end end case PSSE extent = nomefile(max(1,lfile-2):lfile); if strcmpi(extent,'raw'), fid = fopen(nomefile, 'rt'); sline = fgets(fid); out = 0; if isempty(sline), sline = ' 2'; end if sline == -1; sline = ' 2'; end if length(sline) == 1; sline = [sline,' ']; end if isempty(str2num(sline(1:4))), sline = ' 2'; end if str2num(sline(1:2)) == 0 | str2num(sline(1:2)) == 1 out = 1; end if strcmp(sline(1:3),'001'), out = 0; end count = fclose(fid); if out, add_file = 1; end end case PSAP extent = nomefile(max(1,lfile-2):lfile); if strcmpi(extent,'dat'), fid = fopen(nomefile, 'rt'); sline = fgets(fid); count = fclose(fid); if strfind(sline,'1'), add_file = 1; end end case EUROSTAG extent = nomefile(max(1,lfile-2):lfile); if strcmpi(extent,'dat'), if isfile(nomefile,'HEADER ',20), add_file = 1; end end case TH extent = nomefile(max(1,lfile-2):lfile); if strcmpi(extent,'dat'), if isfile(nomefile,'SYSBASE',50) | ... isfile(nomefile,'THLINE',50) add_file = 1; end end case CESI extent = nomefile(max(1,lfile-2):lfile); if strcmpi(extent,'dat'), if isfile(nomefile,'VNOM',25), add_file = 1; end end case VST extent = nomefile(max(1,lfile-7):lfile); if strcmpi(extent,'_vst.dat'), add_file = 1; end case SIMPOW extent = nomefile(max(1,lfile-6):lfile); %if strcmpi(extent,'.optpow') | strcmpi(extent,'.dynpow') if strcmpi(extent,'.optpow'), add_file = 1; end case IPSS extent1 = nomefile(max(1,lfile-7):lfile); extent2 = nomefile(max(1,lfile-4):lfile); if strcmpi(extent1,'.ipssdat') | strcmpi(extent2,'.ipss') add_file = 1; end case NEPLAN extent = nomefile(max(1,lfile-3):lfile); if strcmpi(extent,'.ndt'), add_file = 1; end case ODM extent = nomefile(max(1,lfile-3):lfile); if strcmpi(extent,'.odm'), add_file = 1; end if strcmpi(extent,'.xml') if isfile(nomefile,'PSSStudyCase',10), add_file = 1; end end case DIGSILENT extent = nomefile(max(1,lfile-3):lfile); if strcmpi(extent,'.dgs'), add_file = 1; end case POWERWORLD extent = nomefile(max(1,lfile-3):lfile); if strcmpi(extent,'.aux'), add_file = 1; end case PET extent = nomefile(max(1,lfile-3):lfile); if strcmpi(extent,'.pet'), add_file = 1; end case FLOWDEMO extent = nomefile(max(1,lfile-3):lfile); if strcmpi(extent,'.fdn'), add_file = 1; end case CHAPMAN if isempty(findstr(nomefile,'.')), if isfile(nomefile,'SYSTEM',10), add_file = 1; end end case UCTE extent = nomefile(max(1,lfile-3):lfile); if strcmpi(extent,'.uct'), add_file = 1; end case PCFLO if strmatch('bdat.',lower(nomefile)), add_file = 1; end case WEBFLOW extent = nomefile(max(1,lfile-3):lfile); if strcmpi(extent,'.txt') if isfile(nomefile,'BQ',10) add_file = 1; end end case CEPEL extent = nomefile(max(1,lfile-3):lfile); if strcmpi(extent,'.txt') if isfile(nomefile,'TITU',5) add_file = 1; end end case GEEPC extent = nomefile(max(1,lfile-3):lfile); if strcmpi(extent,'.epc'), add_file = 1; end otherwise % all files % add only files that noe begins with a dot that are % hidden files on UNIX systems if ~strcmp(nomefile(1),'.') & isunix add_file = 1; end end if add_file, cfile{jfile,1} = a(numfile(i)).name; jfile = jfile + 1; endend%============================================================================function out = isfile(file,stringa,nrow)% checking the first nrow to figure out the data formatout = 0;[fid, message] = fopen(file, 'rt');if ~isempty(message) fm_disp(['While inspecting the current folder, ', ... 'error found in file "',file,'". ',message]) returnendn_row = 0;while 1 sline = fgets(fid); n_row = n_row + 1; if ~isempty(sline), if sline == -1, break; end, end vec = strfind(sline,stringa); if ~isempty(vec), out = 1; break, end if n_row == nrow, break, endendcount = fclose(fid);%============================================================================function devices = getdevicesif isunix devices = {'/'};else devices = {'a:\'}; ndev = 1; for i = 99:122 device_name = [char(i),':\']; %if exist(device_name) == 7 if ~isempty(dir(device_name)) ndev = ndev + 1; devices{ndev,1} = device_name; end endend%============================================================================function check = fm_perl(program_name,filter_name,file_name)global Path Figcmd = [Path.filters,filter_name];% last minute option for certain filtershdl = findobj(Fig.dir,'Tag','CheckboxSilent');if ~get(hdl,'Value') switch program_name case 'CESI' [add_file,add_path] = uigetfile('*.dat','Select COLAS ADD file'); if strcmp(add_path,[pwd,filesep]) file_name = ['-a" "',add_file,'" "',file_name]; elseif add_path == 0 % no COLAS ADD file else % COLAS ADD file is not in the current folder fm_disp(['* * COLAS ADD file must be in the same folder as base ' ... 'data file.']) end case 'NEPLAN' [add_file,add_path] = uigetfile('*.edt','Select EDT file'); if strcmp(add_path,[pwd,filesep]) file_name = ['-a" "',add_file,'" "',file_name]; elseif add_path == 0 % no NEPLAN EDT file else % NEPLAN EDT file is not in the current folder fm_disp(['* * NEPLAN EDT file must be in the same folder as NDT ' ... 'file.']) end case 'SIMPOW' [add_file,add_path] = uigetfile('*.dynpow','Select DYNPOW file'); if strcmp(add_path,[pwd,filesep]) file_name = [file_name,'" "',add_file]; elseif add_path == 0 % no DYNPOW file file_name = ['-n" "',file_name]; else file_name = [file_name,'" "',add_path,filesep,add_file]; end otherwise % nothing to do endend% verbose conversionhdl = findobj(Fig.dir,'Tag','CheckboxVerbose');if get(hdl,'Value') file_name = ['-v" "',file_name];endif ispc cmdString = ['"',Path.filters,filter_name,'" "',file_name,'"'];else cmdString = [filter_name,' "',file_name,'"'];end% Execute Perl scripterrTxtNoPerl = 'Unable to find Perl executable.';if isempty(cmdString) % nothing to do ...elseif ispc % PC perlCmd = fullfile(matlabroot, 'sys\perl\win32\bin\'); cmdString = ['perl ' cmdString]; perlCmd = ['set PATH=',perlCmd, ';%PATH%&' cmdString]; [status, results] = dos(perlCmd);else % UNIX [status, perlCmd] = unix('which perl'); if (status == 0) [status, results] = unix(cmdString); else error(errTxtNoPerl); endendfm_disp(results)check = ~status;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -