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

📄 fm_dirset.m

📁 这是一个很适合研究和学习用的电力系统仿真软件
💻 M
📖 第 1 页 / 共 2 页
字号:
    close(Fig.dir)
    return
  end
  
  hdl = findobj(Fig.dir,'Tag','PopupMenu1');
  type = get(hdl,'Value');
  
  if type == PSAT | type == PSATPERT
    check = 1;
  else    
    cd(Path.local)
    check = fm_dirset('convert');
  end
  if ~check
    fm_disp('Data conversion failed.',2)
    return
  end

  % determine file name
  namefile = nomefile{numfile};
  switch type
   case {PSAT,PSATPERT,PSATMDL}
    % nothing to do!
   case PCFLO
    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,'[^\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 '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
  end

end

cd(Path.local)

%===================================================================
function cfile = uform(formato)

% codes
IEEE = 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;
VITRUVIO = 26; % all files

a = 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)
        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);
      out = 0;
      if isempty(sline), sline = ' 2'; end
      if sline == -1; sline = ' 2'; end
      warning off
      if isempty(str2num(sline)), sline = ' 2'; end
      if str2num(sline) == 1, out = 1; end
      warning on
      count = fclose(fid);
      if out, 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')
      add_file = 1;
    end
   case NEPLAN
    extent = nomefile(max(1,lfile-3):lfile);
    if strcmpi(extent,'.ndt'), add_file = 1; 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 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; end
end

%============================================================================

function out = isfile(file,stringa,nrow)

% checking the first nrow to figure out the data format

out = 0;
[fid, message] = fopen(file, 'rt');
if ~isempty(message)
  fm_disp(['While inspecting the current folder, ', ...
           'error found in file "',file,'". ',message])
  return
end
n_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, end
end
count = fclose(fid);


%============================================================================

function devices = getdevices

if isunix
  devices = {'/'};
else
  devices = {'a:\'};
  ndev = 1;
  for i='c':'z'
    device_name = [i,':\'];
    %if exist(device_name) == 7
    if ~isempty(dir(device_name))
      ndev = ndev + 1;
      devices{ndev,1} = device_name;
    end
  end
end

%============================================================================
function check = fm_perl(program_name,filter_name,file_name)

global Path Fig

cmd = [Path.filters,filter_name];

% last minute option for certain filters 
hdl = 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 NEPLAN 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
   otherwise
    % nothing to do
  end
end

% verbose conversion
hdl = findobj(Fig.dir,'Tag','CheckboxVerbose');
if get(hdl,'Value')
  file_name = ['-v ',file_name];  
end

cmdString = [Path.filters,filter_name,' ',file_name];

% Execute Perl script
errTxtNoPerl = '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)
    cmdString = ['perl ', cmdString];
    [status, results] = unix(cmdString);
  else
    error(errTxtNoPerl);
  end
end

fm_disp(results)
check = ~status;

⌨️ 快捷键说明

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