Home > matpower5.0 > t > t_psse.m

t_psse

PURPOSE ^

T_PSSE Tests for PSSE2MPC and related functions.

SYNOPSIS ^

function t_psse(quiet)

DESCRIPTION ^

T_PSSE  Tests for PSSE2MPC and related functions.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_psse(quiet)
0002 %T_PSSE  Tests for PSSE2MPC and related functions.
0003 
0004 %   MATPOWER
0005 %   $Id: t_psse.m 2452 2014-12-05 20:44:48Z ray $
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %   Copyright (c) 2014 by Power System Engineering Research Center (PSERC)
0008 %
0009 %   This file is part of MATPOWER.
0010 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0011 %
0012 %   MATPOWER is free software: you can redistribute it and/or modify
0013 %   it under the terms of the GNU General Public License as published
0014 %   by the Free Software Foundation, either version 3 of the License,
0015 %   or (at your option) any later version.
0016 %
0017 %   MATPOWER is distributed in the hope that it will be useful,
0018 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0019 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0020 %   GNU General Public License for more details.
0021 %
0022 %   You should have received a copy of the GNU General Public License
0023 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0024 %
0025 %   Additional permission under GNU GPL version 3 section 7
0026 %
0027 %   If you modify MATPOWER, or any covered work, to interface with
0028 %   other modules (such as MATLAB code and MEX-files) available in a
0029 %   MATLAB(R) or comparable environment containing parts covered
0030 %   under other licensing terms, the licensors of MATPOWER grant
0031 %   you additional permission to convey the resulting work.
0032 
0033 if nargin < 1
0034     quiet = 0;
0035 end
0036 
0037 num_tests = 137;
0038 
0039 t_begin(num_tests, quiet);
0040 
0041 raw = 't_psse_case.raw';
0042 case_n = 't_psse_case%d';
0043 if quiet
0044     verbose = 0;
0045 else
0046     verbose = 0;
0047 end
0048 if have_fcn('octave')
0049     s1 = warning('query', 'Octave:load-file-in-path');
0050     warning('off', 'Octave:load-file-in-path');
0051 end
0052 
0053 if ~have_fcn('regexp_split')
0054     t_skip(num_tests, 'PSSE2MPC requires newer Octave with regexp split support');
0055 else
0056     t = '[records, sections] = psse_read() : length(records)';
0057     [records, sections] = psse_read(raw, verbose);
0058     t_is(length(records), 11, 12, t);
0059     t = '[records, sections] = psse_read() : length(sections)';
0060     t_is(length(sections), 3, 12, t);
0061 
0062     expected = { ...
0063         {1, 'Line 1   ', 1.1, -0.1, 0.011, 1, 1.1, 'A', '', 'A'}, ...
0064         {2, 'Line, "2"', 2.2, -0.2, 0.022, 2, 2.2, 'B', '', 'B'}, ...
0065         {3, 'Line, ''3''', 3.3, -0.3, 0.033, 3, 3.3, 'C', '', 'C'}, ...
0066         {4, sprintf('Line\t4'), 4.4, -0.4, 0.044, 4, 4.4, 'D', '', 'D'}, ...
0067     };
0068     ec = { ...
0069         ', "comment 1"', ...
0070         'comment, ''2''', ...
0071         sprintf('''comment\t3'''), ...
0072         '//comment,4', ...
0073     };
0074 
0075     for i = 1:sections(2).last - sections(2).first + 1
0076         t = sprintf('psse_parse_line(str%d, template) : ', i);
0077         [d, c] = psse_parse_line(records{i+sections(2).first-1}, 'dsffgDFcsc');
0078         t_is(length(d), length(expected{i}), 12, [t 'length']);
0079         for k = 1:length(d)
0080             if isnumeric(expected{i}{k})
0081                 t_is(d{k}, expected{i}{k}, 12, sprintf('%s col %d', t, k));
0082             elseif isempty(expected{i}{k})
0083                 t_ok(isempty(d{k}), sprintf('%s col %d', t, k));
0084             else
0085                 t_ok(strcmp(d{k}, expected{i}{k}), sprintf('%s col %d', t, k));
0086             end
0087         end
0088         t_ok(strcmp(c, ec{i}), sprintf('%s comment', t));
0089     end
0090 
0091     t = 'psse_parse_line : missing optional columns : ';
0092     [d, c] = psse_parse_line(records{1}, 'dsffgDFcscdfgcs');
0093     t_is(length(d), 15, 12, [t 'length']);
0094     t_ok(all(cellfun(@isempty, d(11:15))), [t 'all empty']);
0095 
0096     t = 'psse_parse_section : ';
0097     [d, w] = psse_parse_section({}, records, sections, 2, 0, 'test1', 'dsFfgDF.sc');
0098     t_ok(isstruct(d) && isfield(d, 'num') && isfield(d, 'txt'), [t 'struct']);
0099     t_is(size(d.num), [4 11], 12, [t 'size(num)']);
0100     t_is(size(d.txt), [4 11], 12, [t 'size(txt)']);
0101     for i = 1:size(d.num, 1)
0102         for k = 1:size(d.num, 2)-1
0103             if isnumeric(expected{i}{k})
0104                 t_is(d.num(i,k), expected{i}{k}, 12, sprintf('%s num(%d,%d)', t, i, k));
0105                 t_ok(isempty(d.txt{i,k}), sprintf('%s txt{%d,%d}', t, i, k));
0106             elseif isempty(expected{i}{k})
0107                 t_ok(isnan(d.num(i,k)), sprintf('%s num(%d,%d)', t, i, k));
0108                 t_ok(isempty(d.txt{i,k}), sprintf('%s txt{%d,%d}', t, i, k));
0109             else
0110                 t_ok(isnan(d.num(i,k)), sprintf('%s num(%d,%d)', t, i, k));
0111                 t_ok(strcmp(d.txt{i,k}, expected{i}{k}), sprintf('%s txt{%d,%d}', t, i, k));
0112             end
0113         end
0114     end
0115 
0116     t = 'psse2mpc(rawfile, casefile)';
0117     txt = 'MATPOWER 5.0 using PSSE2MPC on 11-Aug-2014';
0118     for k = 2:3
0119         fname = sprintf(case_n, k);
0120         rawname = sprintf('%s.raw', fname);
0121         casename = sprintf('%s.m', fname);
0122         tmpfname = sprintf('%s_%d', fname, fix(1e9*rand));
0123         tmpcasename = sprintf('%s.m', tmpfname);
0124         mpc = psse2mpc(rawname, tmpfname, 0);
0125         str = fileread(casename);
0126         str2 = fileread(tmpcasename);
0127         str2 = strrep(str2, char([13 10]), char(10));   %% Win to Unix EOL chars
0128         str2 = strrep(str2, 'e-005', 'e-05');           %% needed on Windoze, who knows why?
0129         str2 = strrep(str2, tmpfname, fname);
0130         str2 = strrep(str2, upper(tmpfname), upper(fname));
0131         str2 = regexprep(str2, 'MATPOWER (.*) using PSSE2MPC on \d\d-...-\d\d\d\d', txt);
0132         delete(tmpcasename);
0133         t_ok(strcmp(str, str2), sprintf('%s : %s', t, fname));
0134     end
0135 end
0136 
0137 if have_fcn('octave')
0138     warning(s1.state, 'Octave:load-file-in-path');
0139 end
0140 
0141 t_end;

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