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

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005