Home > matpower5.1 > 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 %   Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC)
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %
0008 %   $Id: t_psse.m 2662 2015-03-20 20:02:08Z ray $
0009 %
0010 %   This file is part of MATPOWER.
0011 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0012 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0013 
0014 if nargin < 1
0015     quiet = 0;
0016 end
0017 
0018 num_tests = 137;
0019 
0020 t_begin(num_tests, quiet);
0021 
0022 raw = 't_psse_case.raw';
0023 case_n = 't_psse_case%d';
0024 if quiet
0025     verbose = 0;
0026 else
0027     verbose = 0;
0028 end
0029 if have_fcn('octave')
0030     if have_fcn('octave', 'vnum') >= 4
0031         file_in_path_warn_id = 'Octave:data-file-in-path';
0032     else
0033         file_in_path_warn_id = 'Octave:fopen-file-in-path';
0034     end
0035     s1 = warning('query', file_in_path_warn_id);
0036     warning('off', file_in_path_warn_id);
0037 end
0038 
0039 if ~have_fcn('regexp_split')
0040     t_skip(num_tests, 'PSSE2MPC requires newer Matlab/Octave with regexp split support');
0041 else
0042     t = '[records, sections] = psse_read() : length(records)';
0043     [records, sections] = psse_read(raw, verbose);
0044     t_is(length(records), 11, 12, t);
0045     t = '[records, sections] = psse_read() : length(sections)';
0046     t_is(length(sections), 3, 12, t);
0047 
0048     expected = { ...
0049         {1, 'Line 1   ', 1.1, -0.1, 0.011, 1, 1.1, 'A', '', 'A'}, ...
0050         {2, 'Line, "2"', 2.2, -0.2, 0.022, 2, 2.2, 'B', '', 'B'}, ...
0051         {3, 'Line, ''3''', 3.3, -0.3, 0.033, 3, 3.3, 'C', '', 'C'}, ...
0052         {4, sprintf('Line\t4'), 4.4, -0.4, 0.044, 4, 4.4, 'D', '', 'D'}, ...
0053     };
0054     ec = { ...
0055         ', "comment 1"', ...
0056         'comment, ''2''', ...
0057         sprintf('''comment\t3'''), ...
0058         '//comment,4', ...
0059     };
0060 
0061     for i = 1:sections(2).last - sections(2).first + 1
0062         t = sprintf('psse_parse_line(str%d, template) : ', i);
0063         [d, c] = psse_parse_line(records{i+sections(2).first-1}, 'dsffgDFcsc');
0064         t_is(length(d), length(expected{i}), 12, [t 'length']);
0065         for k = 1:length(d)
0066             if isnumeric(expected{i}{k})
0067                 t_is(d{k}, expected{i}{k}, 12, sprintf('%s col %d', t, k));
0068             elseif isempty(expected{i}{k})
0069                 t_ok(isempty(d{k}), sprintf('%s col %d', t, k));
0070             else
0071                 t_ok(strcmp(d{k}, expected{i}{k}), sprintf('%s col %d', t, k));
0072             end
0073         end
0074         t_ok(strcmp(c, ec{i}), sprintf('%s comment', t));
0075     end
0076 
0077     t = 'psse_parse_line : missing optional columns : ';
0078     [d, c] = psse_parse_line(records{1}, 'dsffgDFcscdfgcs');
0079     t_is(length(d), 15, 12, [t 'length']);
0080     t_ok(all(cellfun(@isempty, d(11:15))), [t 'all empty']);
0081 
0082     t = 'psse_parse_section : ';
0083     [d, w] = psse_parse_section({}, records, sections, 2, 0, 'test1', 'dsFfgDF.sc');
0084     t_ok(isstruct(d) && isfield(d, 'num') && isfield(d, 'txt'), [t 'struct']);
0085     t_is(size(d.num), [4 11], 12, [t 'size(num)']);
0086     t_is(size(d.txt), [4 11], 12, [t 'size(txt)']);
0087     for i = 1:size(d.num, 1)
0088         for k = 1:size(d.num, 2)-1
0089             if isnumeric(expected{i}{k})
0090                 t_is(d.num(i,k), expected{i}{k}, 12, sprintf('%s num(%d,%d)', t, i, k));
0091                 t_ok(isempty(d.txt{i,k}), sprintf('%s txt{%d,%d}', t, i, k));
0092             elseif isempty(expected{i}{k})
0093                 t_ok(isnan(d.num(i,k)), sprintf('%s num(%d,%d)', t, i, k));
0094                 t_ok(isempty(d.txt{i,k}), sprintf('%s txt{%d,%d}', t, i, k));
0095             else
0096                 t_ok(isnan(d.num(i,k)), sprintf('%s num(%d,%d)', t, i, k));
0097                 t_ok(strcmp(d.txt{i,k}, expected{i}{k}), sprintf('%s txt{%d,%d}', t, i, k));
0098             end
0099         end
0100     end
0101 
0102     t = 'psse2mpc(rawfile, casefile)';
0103     txt = 'MATPOWER 5.0 using PSSE2MPC on 11-Aug-2014';
0104     for k = 2:3
0105         fname = sprintf(case_n, k);
0106         rawname = sprintf('%s.raw', fname);
0107         casename = sprintf('%s.m', fname);
0108         tmpfname = sprintf('%s_%d', fname, fix(1e9*rand));
0109         tmpcasename = sprintf('%s.m', tmpfname);
0110         mpc = psse2mpc(rawname, tmpfname, 0);
0111         str = fileread(casename);
0112         str2 = fileread(tmpcasename);
0113         str2 = strrep(str2, char([13 10]), char(10));   %% Win to Unix EOL chars
0114         str2 = strrep(str2, 'e-005', 'e-05');           %% needed on Windoze, who knows why?
0115         str2 = strrep(str2, tmpfname, fname);
0116         str2 = strrep(str2, upper(tmpfname), upper(fname));
0117         str2 = regexprep(str2, 'MATPOWER (.*) using PSSE2MPC on \d\d-...-\d\d\d\d', txt);
0118         delete(tmpcasename);
0119         t_ok(strcmp(str, str2), sprintf('%s : %s', t, fname));
0120     end
0121 end
0122 
0123 if have_fcn('octave')
0124     warning(s1.state, file_in_path_warn_id);
0125 end
0126 
0127 t_end;

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005