Home > matpower7.1 > lib > 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 https://matpower.org for more info.
0011 
0012 if nargin < 1
0013     quiet = 0;
0014 end
0015 
0016 num_tests = 143;
0017 
0018 t_begin(num_tests, quiet);
0019 
0020 raw = 't_psse_case.raw';
0021 case_n = 't_psse_case%d';
0022 casefile = 't_case9_save2psse';
0023 if quiet
0024     verbose = 0;
0025 else
0026     verbose = 0;
0027 end
0028 if have_feature('octave')
0029     if have_feature('octave', 'vnum') >= 4
0030         file_in_path_warn_id = 'Octave:data-file-in-path';
0031     else
0032         file_in_path_warn_id = 'Octave:fopen-file-in-path';
0033     end
0034     s1 = warning('query', file_in_path_warn_id);
0035     warning('off', file_in_path_warn_id);
0036 end
0037 
0038 if ~have_feature('regexp_split')
0039     t_skip(num_tests, 'PSSE2MPC requires newer MATLAB/Octave with regexp split support');
0040 else
0041     t = '[records, sections] = psse_read() : length(records)';
0042     [records, sections] = psse_read(raw, verbose);
0043     t_is(length(records), 11, 12, t);
0044     t = '[records, sections] = psse_read() : length(sections)';
0045     t_is(length(sections), 3, 12, t);
0046 
0047     expected = { ...
0048         {1, 'Line 1   ', 1.1, -0.1, 0.011, 1, 1.1, 'A', '', 'A'}, ...
0049         {2, 'Line, "2"', 2.2, -0.2, 0.022, 2, 2.2, 'B', '', 'B'}, ...
0050         {3, 'Line, ''3''', 3.3, -0.3, 0.033, 3, 3.3, 'C', '', 'C'}, ...
0051         {4, sprintf('Line\t4'), 4.4, -0.4, 0.044, 4, 4.4, 'D', '', 'D'}, ...
0052     };
0053     ec = { ...
0054         ', "comment 1"', ...
0055         'comment, ''2''', ...
0056         sprintf('''comment\t3'''), ...
0057         '//comment,4', ...
0058     };
0059 
0060     for i = 1:sections(2).last - sections(2).first + 1
0061         t = sprintf('psse_parse_line(str%d, template) : ', i);
0062         [d, c] = psse_parse_line(records{i+sections(2).first-1}, 'dsffgDFcsc');
0063         t_is(length(d), length(expected{i}), 12, [t 'length']);
0064         for k = 1:length(d)
0065             if isnumeric(expected{i}{k})
0066                 t_is(d{k}, expected{i}{k}, 12, sprintf('%s col %d', t, k));
0067             elseif isempty(expected{i}{k})
0068                 t_ok(isempty(d{k}), sprintf('%s col %d', t, k));
0069             else
0070                 t_ok(strcmp(d{k}, expected{i}{k}), sprintf('%s col %d', t, k));
0071             end
0072         end
0073         t_ok(strcmp(c, ec{i}), sprintf('%s comment', t));
0074     end
0075 
0076     t = 'psse_parse_line : missing optional columns : ';
0077     [d, c] = psse_parse_line(records{1}, 'dsffgDFcscdfgcs');
0078     t_is(length(d), 15, 12, [t 'length']);
0079     t_ok(all(cellfun(@isempty, d(11:15))), [t 'all empty']);
0080 
0081     t = 'psse_parse_section : ';
0082     [d, w] = psse_parse_section({}, records, sections, 2, 0, 'test1', 'dsFfgDF.sc');
0083     t_ok(isstruct(d) && isfield(d, 'num') && isfield(d, 'txt'), [t 'struct']);
0084     t_is(size(d.num), [4 11], 12, [t 'size(num)']);
0085     t_is(size(d.txt), [4 11], 12, [t 'size(txt)']);
0086     for i = 1:size(d.num, 1)
0087         for k = 1:size(d.num, 2)-1
0088             if isnumeric(expected{i}{k})
0089                 t_is(d.num(i,k), expected{i}{k}, 12, sprintf('%s num(%d,%d)', t, i, k));
0090                 t_ok(isempty(d.txt{i,k}), sprintf('%s txt{%d,%d}', t, i, k));
0091             elseif isempty(expected{i}{k})
0092                 t_ok(isnan(d.num(i,k)), sprintf('%s num(%d,%d)', t, i, k));
0093                 t_ok(isempty(d.txt{i,k}), sprintf('%s txt{%d,%d}', t, i, k));
0094             else
0095                 t_ok(isnan(d.num(i,k)), sprintf('%s num(%d,%d)', t, i, k));
0096                 t_ok(strcmp(d.txt{i,k}, expected{i}{k}), sprintf('%s txt{%d,%d}', t, i, k));
0097             end
0098         end
0099     end
0100 
0101     t = 'psse2mpc(rawfile, casefile)';
0102     txt = 'MATPOWER 5.0 using PSSE2MPC on 11-Aug-2014';
0103     for k = 2:3
0104         fname = sprintf(case_n, k);
0105         rawname = sprintf('%s.raw', fname);
0106         casename = sprintf('%s.m', fname);
0107         tmpfname = sprintf('%s_%d', fname, fix(1e9*rand));
0108         tmpcasename = sprintf('%s.m', tmpfname);
0109         mpc = psse2mpc(rawname, tmpfname, 0);
0110         str = fileread(casename);
0111         str2 = fileread(tmpcasename);
0112         str = strrep(str, char([13 10]), char(10));     %% Win to Unix EOL chars
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 
0122     t = 'save2psse -> psse2mpc : ';
0123     mpc0 = loadcase(casefile);
0124     tmpfname = sprintf('t_save2psse_%d', fix(1e9*rand));
0125     tmpfname = save2psse(tmpfname, mpc0);
0126     mpc = psse2mpc(tmpfname, 0);
0127     t_is(mpc.bus, mpc0.bus, 12, [t 'bus']);
0128     t_is(mpc.branch, mpc0.branch, 12, [t 'branch']);
0129     t_is(mpc.gen, mpc0.gen, 12, [t 'gen']);
0130     t_is(mpc.dcline, mpc0.dcline, 4, [t 'dcline']);
0131     t_ok(isequal(mpc.bus_name, mpc0.bus_name), [t 'bus_name']);
0132 
0133     got = fileread(tmpfname);
0134     got = strrep(got, char([13 10]), char(10));             %% Win to Unix EOL chars
0135     got = regexprep(got, '/ ..-...-.... ..:..:.. - MATPOWER ([^\n]*)', '/ 17-Jan-2019 15:30:41 - MATPOWER 7.0');
0136     expected = fileread([casefile '.raw']);
0137     expected = strrep(expected, char([13 10]), char(10));   %% Win to Unix EOL chars
0138 
0139     t_ok(strcmp(got, expected), 'save2psse: RAW file match');
0140 
0141     delete(tmpfname);
0142 end
0143 
0144 if have_feature('octave')
0145     warning(s1.state, file_in_path_warn_id);
0146 end
0147 
0148 t_end;

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005