0001 function [success, measure, idx, sigma] = checkDataIntegrity(measure, idx, sigma, nbus)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 verbose = 2;
0040
0041 success = 1;
0042 nowarning = 1;
0043
0044
0045
0046 if length(measure.PF) ~= length(idx.idx_zPF)
0047 fprintf('Warning: measurement vector and index vector for PF do not have the same length. The longer vector will be truncated.\n');
0048 min_len = min(length(measure.PF), length(idx.idx_zPF));
0049 measure.PF = measure.PF(1:min_len);
0050 idx.idx_zPF = idx.idx_zPF(1:min_len);
0051 nowarning = 0;
0052 end
0053 if ~isempty(idx.idx_zPF) && length(sigma.sigma_PF) <= 0
0054 fprintf('Error: Sigma for PF is not specified.\n');
0055 success = 0;
0056 end
0057 if length(sigma.sigma_PF) > 1
0058 fprintf('Warning: Sigma for PF is assigned multiple values. The first value will be used.\n');
0059 sigma.sigma_PF = sigma.sigma_PF(1);
0060 nowarning = 0;
0061 end
0062
0063
0064 if length(measure.PT) ~= length(idx.idx_zPT)
0065 fprintf('Warning: measurement vector and index vector for PT do not have the same length. The longer vector will be truncated.\n');
0066 min_len = min(length(measure.PT), length(idx.idx_zPT));
0067 measure.PT = measure.PT(1:min_len);
0068 idx.idx_zPT = idx.idx_zPT(1:min_len);
0069 nowarning = 0;
0070 end
0071 if ~isempty(idx.idx_zPT) && length(sigma.sigma_PT) <= 0
0072 fprintf('Error: Sigma for PT is not specified.\n');
0073 success = 0;
0074 end
0075 if length(sigma.sigma_PT) > 1
0076 fprintf('Warning: Sigma for PT is assigned multiple values. The first value will be used.\n');
0077 sigma.sigma_PT = sigma.sigma_PT(1);
0078 nowarning = 0;
0079 end
0080
0081
0082 if length(measure.PG) ~= length(idx.idx_zPG)
0083 fprintf('Warning: measurement vector and index vector for PG do not have the same length. The longer vector will be truncated.\n');
0084 min_len = min(length(measure.PG), length(idx.idx_zPG));
0085 measure.PG = measure.PG(1:min_len);
0086 idx.idx_zPG = idx.idx_zPG(1:min_len);
0087 nowarning = 0;
0088 end
0089 if ~isempty(idx.idx_zPG) && length(sigma.sigma_PG) <= 0
0090 fprintf('Error: Sigma for PG is not specified.\n');
0091 success = 0;
0092 end
0093 if length(sigma.sigma_PG) > 1
0094 fprintf('Warning: Sigma for PG is assigned multiple values. The first value will be used.\n');
0095 sigma.sigma_PG = sigma.sigma_PG(1);
0096 nowarning = 0;
0097 end
0098
0099
0100 if length(measure.Va) ~= length(idx.idx_zVa)
0101 fprintf('Warning: measurement vector and index vector for Va do not have the same length. The longer vector will be truncated.\n');
0102 min_len = min(length(measure.Va), length(idx.idx_zVa));
0103 measure.Va = measure.Va(1:min_len);
0104 idx.idx_zVa = idx.idx_zVa(1:min_len);
0105 nowarning = 0;
0106 end
0107 if ~isempty(idx.idx_zVa) && length(sigma.sigma_Va) <= 0
0108 fprintf('Error: Sigma for Va is not specified.\n');
0109 success = 0;
0110 end
0111 if length(sigma.sigma_Va) > 1
0112 fprintf('Warning: Sigma for Va is assigned multiple values. The first value will be used.\n');
0113 sigma.sigma_Va = sigma.sigma_Va(1);
0114 nowarning = 0;
0115 end
0116
0117
0118 if length(measure.QF) ~= length(idx.idx_zQF)
0119 fprintf('Warning: measurement vector and index vector for QF do not have the same length. The longer vector will be truncated.\n');
0120 min_len = min(length(measure.QF), length(idx.idx_zQF));
0121 measure.QF = measure.QF(1:min_len);
0122 idx.idx_zQF = idx.idx_zQF(1:min_len);
0123 nowarning = 0;
0124 end
0125 if ~isempty(idx.idx_zQF) && length(sigma.sigma_QF) <= 0
0126 fprintf('Error: Sigma for QF is not specified.\n');
0127 success = 0;
0128 end
0129 if length(sigma.sigma_QF) > 1
0130 fprintf('Warning: Sigma for QF is assigned multiple values. The first value will be used.\n');
0131 sigma.sigma_QF = sigma.sigma_QF(1);
0132 nowarning = 0;
0133 end
0134
0135
0136 if length(measure.QT) ~= length(idx.idx_zQT)
0137 fprintf('Warning: measurement vector and index vector for QT do not have the same length. The longer vector will be truncated.\n');
0138 min_len = min(length(measure.QT), length(idx.idx_zQT));
0139 measure.QT = measure.QT(1:min_len);
0140 idx.idx_zQT = idx.idx_zQT(1:min_len);
0141 nowarning = 0;
0142 end
0143 if ~isempty(idx.idx_zQT) && length(sigma.sigma_QT) <= 0
0144 fprintf('Error: Sigma for QT is not specified.\n');
0145 success = 0;
0146 end
0147 if length(sigma.sigma_QT) > 1
0148 fprintf('Warning: Sigma for QT is assigned multiple values. The first value will be used.\n');
0149 sigma.sigma_QT = sigma.sigma_QT(1);
0150 nowarning = 0;
0151 end
0152
0153
0154 if length(measure.QG) ~= length(idx.idx_zQG)
0155 fprintf('Warning: measurement vector and index vector for QG do not have the same length. The longer vector will be truncated.\n');
0156 min_len = min(length(measure.QG), length(idx.idx_zQG));
0157 measure.QG = measure.QG(1:min_len);
0158 idx.idx_zQG = idx.idx_zQG(1:min_len);
0159 nowarning = 0;
0160 end
0161 if ~isempty(idx.idx_zQG) && length(sigma.sigma_QG) <= 0
0162 fprintf('Error: Sigma for QG is not specified.\n');
0163 success = 0;
0164 end
0165 if length(sigma.sigma_QG) > 1
0166 fprintf('Warning: Sigma for QG is assigned multiple values. The first value will be used.\n');
0167 sigma.sigma_QG = sigma.sigma_QG(1);
0168 nowarning = 0;
0169 end
0170
0171
0172 if length(measure.Vm) ~= length(idx.idx_zVm)
0173 fprintf('Warning: measurement vector and index vector for Vm do not have the same length. The longer vector will be truncated.\n');
0174 min_len = min(length(measure.Vm), length(idx.idx_zVm));
0175 measure.Vm = measure.Vm(1:min_len);
0176 idx.idx_zVm = idx.idx_zVm(1:min_len);
0177 nowarning = 0;
0178 end
0179 if ~isempty(idx.idx_zVm) && length(sigma.sigma_Vm) <= 0
0180 fprintf('Error: Sigma for Vm is not specified.\n');
0181 success = 0;
0182 end
0183 if length(sigma.sigma_Vm) > 1
0184 fprintf('Warning: Sigma for Vm is assigned multiple values. The first value will be used.\n');
0185 sigma.sigma_Vm = sigma.sigma_Vm(1);
0186 nowarning = 0;
0187 end
0188
0189
0190 if success && ~nowarning
0191 fprintf('Press any key to continue...\n');
0192 pause;
0193 end
0194
0195
0196
0197 allMeasure = [
0198 measure.PF
0199 measure.PT
0200 measure.PG
0201 measure.Va
0202 measure.QF
0203 measure.QT
0204 measure.QG
0205 measure.Vm
0206 ];
0207 if length(allMeasure) < 2*(nbus - 1)
0208 fprintf('Error: There are less measurements (%d) than number of variables to be estimated (%d).\n', length(allMeasure), 2*(nbus - 1));
0209 success = 0;
0210 end