Home > matpower5.0 > psse_read.m

psse_read

PURPOSE ^

PSSE_READ Reads the data from a PSS/E RAW data file.

SYNOPSIS ^

function [records, sections] = psse_read(rawfile_name, verbose)

DESCRIPTION ^

PSSE_READ  Reads the data from a PSS/E RAW data file.
   [RECORDS, SECTIONS] = PSSE_READ(RAWFILE_NAME)
   [RECORDS, SECTIONS] = PSSE_READ(RAWFILE_NAME, VERBOSE)

   Reads the data from a PSS/E RAW data file into a cell array of
   strings, corresponding to the lines/records in the file. It
   detects the beginning and ending indexes of each section as well
   as any Q record used to indicate the end of the data.

   Input:
       RAWFILE_NAME :  name of the PSS/E RAW file to be read
                       (opened directly with FILEREAD)
       VERBOSE      :  1 to display progress info, 0 (default) otherwise

   Output:
       RECORDS :   a cell array of strings, one for each line in
                   the file (new line characters not included)
       SECTIONS  : a struct array with the following fields
           first : index into RECORDS of first line of the section
           last  : index into RECORDS of last line of the section
           name  : name of the section (if available) extracted
                   from the 'END OF <NAME> DATA, BEGIN ... DATA'
                   comment typically found in the terminator line

   See also PSSE2MPC.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [records, sections] = psse_read(rawfile_name, verbose)
0002 %PSSE_READ  Reads the data from a PSS/E RAW data file.
0003 %   [RECORDS, SECTIONS] = PSSE_READ(RAWFILE_NAME)
0004 %   [RECORDS, SECTIONS] = PSSE_READ(RAWFILE_NAME, VERBOSE)
0005 %
0006 %   Reads the data from a PSS/E RAW data file into a cell array of
0007 %   strings, corresponding to the lines/records in the file. It
0008 %   detects the beginning and ending indexes of each section as well
0009 %   as any Q record used to indicate the end of the data.
0010 %
0011 %   Input:
0012 %       RAWFILE_NAME :  name of the PSS/E RAW file to be read
0013 %                       (opened directly with FILEREAD)
0014 %       VERBOSE      :  1 to display progress info, 0 (default) otherwise
0015 %
0016 %   Output:
0017 %       RECORDS :   a cell array of strings, one for each line in
0018 %                   the file (new line characters not included)
0019 %       SECTIONS  : a struct array with the following fields
0020 %           first : index into RECORDS of first line of the section
0021 %           last  : index into RECORDS of last line of the section
0022 %           name  : name of the section (if available) extracted
0023 %                   from the 'END OF <NAME> DATA, BEGIN ... DATA'
0024 %                   comment typically found in the terminator line
0025 %
0026 %   See also PSSE2MPC.
0027 
0028 %   MATPOWER
0029 %   $Id: psse_read.m 2466 2014-12-12 21:01:55Z ray $
0030 %   by Ray Zimmerman, PSERC Cornell
0031 %   Copyright (c) 2014 by Power System Engineering Research Center (PSERC)
0032 %
0033 %   This file is part of MATPOWER.
0034 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0035 %
0036 %   MATPOWER is free software: you can redistribute it and/or modify
0037 %   it under the terms of the GNU General Public License as published
0038 %   by the Free Software Foundation, either version 3 of the License,
0039 %   or (at your option) any later version.
0040 %
0041 %   MATPOWER is distributed in the hope that it will be useful,
0042 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0043 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0044 %   GNU General Public License for more details.
0045 %
0046 %   You should have received a copy of the GNU General Public License
0047 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0048 %
0049 %   Additional permission under GNU GPL version 3 section 7
0050 %
0051 %   If you modify MATPOWER, or any covered work, to interface with
0052 %   other modules (such as MATLAB code and MEX-files) available in a
0053 %   MATLAB(R) or comparable environment containing parts covered
0054 %   under other licensing terms, the licensors of MATPOWER grant
0055 %   you additional permission to convey the resulting work.
0056 
0057 %% default args
0058 if nargin < 2
0059     verbose = 0;
0060 end
0061 
0062 %% define some functions needed for use with CELLFUN
0063 end_of_section  = @(s)~isempty(regexp(s, '^(Q|\s*0)[\s]*(/.*)?$', 'once'));
0064 q_record        = @(s)~isempty(regexp(s, '^Q', 'once'));
0065 section_name    = @(s)regexp(s, '/\s*END OF (.*)\s', 'tokens');
0066 
0067 %% check for regexp split support
0068 if ~have_fcn('regexp_split')
0069     error('psse_read: Sorry, but PSSE2MPC requires support for the ''split'' argument to regexp(), so it does not work on versions of Octave prior to 3.8.');
0070 end
0071 
0072 %% read in the file, split on newlines
0073 if verbose
0074     spacers = repmat('.', 1, 56-length(rawfile_name));
0075     fprintf('Reading file ''%s'' %s', rawfile_name, spacers);
0076 end
0077 str = fileread(rawfile_name);
0078 if verbose
0079     fprintf(' done.\nSplitting into individual lines ...');
0080 end
0081 records = regexp(str, '\n|\r\n|\r', 'split');
0082 if verbose
0083     str = sprintf('%d lines read', length(records));
0084     spacers = repmat('.', 1, 32-length(str));
0085     fprintf('%s %s ... done.\nAnalyzing sections ...', spacers, str);
0086 end
0087 
0088 %% find end of section and/or Q record
0089 eos = find(cellfun(end_of_section, records));
0090 
0091 %% terminate at Q record
0092 qi = find(cellfun(q_record, records(eos)));
0093 if ~isempty(qi)         %% remove everything beyond Q record ...
0094     if qi(1) > 1 && eos(qi(1)) - eos(qi(1)-1) > 1
0095         %% ... leaving Q record itself, if it is a section terminator
0096         records(eos(qi(1))+1:end) = [];
0097         eos(qi(1)+1:end) = [];
0098     else
0099         %% ... removing Q record too
0100         records(eos(qi(1)):end) = [];
0101         eos(qi(1):end) = [];
0102     end
0103 end
0104 
0105 %% find section extents and names
0106 ns = length(eos) + 1;
0107 i1 = [1 4 eos(1:end-1)+1];
0108 iN = [3 eos-1];
0109 names = cell(1, ns);
0110 names{1} = 'ID';
0111 for k = 2:ns
0112     tmp = regexp(records{eos(k-1)}, 'DATA', 'split');
0113     if isempty(tmp)     %% workaround a bug in Matlab 7.3 (R2006b) (and possibly earlier)
0114         names{k} = '';
0115     else
0116         tmp2 = section_name(tmp{1});
0117         if isempty(tmp2)
0118             names{k} = '';
0119         else
0120             names{k} = tmp2{1}{1};
0121         end
0122     end
0123 end
0124 if verbose
0125     str = sprintf('%d sections', ns);
0126     spacers = repmat('.', 1, 45-length(str));
0127     fprintf('%s %s ... done.\n', spacers, str);
0128 end
0129 
0130 %% create the sections struct
0131 sections = struct(  'first', num2cell(i1), ...
0132                     'last', num2cell(iN), ...
0133                     'name', names   );

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005