ltpda_ss_check throws an error is something is wrong is found in the subsystem. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: ltpda_ss_check checks the fields of a susbsystem. CALL: testSys(syst) INPUTS: a - subsystem dscribed by a plist syst = plist('TYPE', TYPE ,'NAME', NAME ,'TIMESTEP', TIMESTEP ,... 'PARAMNAMES', PARAMNAMES ,'PARAMVALUES', PARAMVALUES ,'PARAMSIGMAS', PARAMSIGMAS ,... 'NBINPUTS', NBINPUTS ,'INPUTNAMES', INPUTNAMES ,'INPUTSIZES', INPUTSIZES ,'INPUTISUSED', INPUTISUSED ,... 'AMAT', AMAT ,'BMATS', BMATS ,'CMAT', CMAT ,'DMATS', DMATS ); OUTPUTS: binary : 1 (ok) 0 (pb) (also throws an error if there is a problem) PARAMETERS: 'TYPE' should be 'SUBSYSTEM' 'NAME' is a string 'TIMESTEP' is a real positive integer, set to zero in continuous case 'PARAMNAMES' cell array of strings describing parameter variables 'PARAMVALUES' array of doubles (means expected of parameters) 'PARAMSIGMAS' array of doubles (variance expected of parameters) 'NBINPUTS' integer number of inputs 'INPUTNAMES' cell array of strings (name of the inputs) 'INPUTSIZES'array of integers (nb of dimensions of the inputs), 'INPUTISUSED' double array (binary to indicate which inputs are used) 'AMAT' cell array (contains A matrix) 'BMATS' cell array (contains B matrices) 'CMAT' cell array (contains C matrix) 'DMATS' cell array (contains D matrices) extra fileds not tested 'FS' 'HS' string containing info for non linear simulations (not implemented) 'INPUTVARNAMES' cell array of cell array naming each input variable 'OUTPUTVANAMES' cell array of output variable names (Y only enven if Xisoutput is set to 1) 'SSVARNAMES' cell array of state space variable names ***** THERE ARE NO DEFAULT PARAMETERS ***** VERSION: '$Id: ltpda_ss_check.m,v 1.5 2008/03/11 16:52:56 adrien Exp $' HISTORY: 21-01-2008 A Grynagier 21-01-2008 A Grynagier Creation 05-01-2008 A Grynagier TO DO : Complete plist automatically if missing fields Modfiy the function such taht the order of the parameters does not matter Add checks for the derviative fields later and think on how to handle the linear derivative case checks for new fields types? %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % standard calls for LTPDA function data
0001 function varargout = ltpda_ss_check(varargin) 0002 % ltpda_ss_check throws an error is something is wrong is found in the subsystem. 0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0004 % 0005 % DESCRIPTION: ltpda_ss_check checks the fields of a susbsystem. 0006 % 0007 % CALL: testSys(syst) 0008 % 0009 % INPUTS: a - subsystem dscribed by a plist 0010 % syst = plist('TYPE', TYPE ,'NAME', NAME ,'TIMESTEP', TIMESTEP ,... 0011 % 'PARAMNAMES', PARAMNAMES ,'PARAMVALUES', PARAMVALUES ,'PARAMSIGMAS', PARAMSIGMAS ,... 0012 % 'NBINPUTS', NBINPUTS ,'INPUTNAMES', INPUTNAMES ,'INPUTSIZES', INPUTSIZES ,'INPUTISUSED', INPUTISUSED ,... 0013 % 'AMAT', AMAT ,'BMATS', BMATS ,'CMAT', CMAT ,'DMATS', DMATS ); 0014 % 0015 % OUTPUTS: binary : 1 (ok) 0 (pb) (also throws an error if there is a problem) 0016 % 0017 % PARAMETERS: 0018 % 'TYPE' should be 'SUBSYSTEM' 0019 % 'NAME' is a string 0020 % 'TIMESTEP' is a real positive integer, set to zero in continuous case 0021 % 'PARAMNAMES' cell array of strings describing parameter variables 0022 % 'PARAMVALUES' array of doubles (means expected of parameters) 0023 % 'PARAMSIGMAS' array of doubles (variance expected of parameters) 0024 % 'NBINPUTS' integer number of inputs 0025 % 'INPUTNAMES' cell array of strings (name of the inputs) 0026 % 'INPUTSIZES'array of integers (nb of dimensions of the inputs), 0027 % 'INPUTISUSED' double array (binary to indicate which inputs are used) 0028 % 'AMAT' cell array (contains A matrix) 0029 % 'BMATS' cell array (contains B matrices) 0030 % 'CMAT' cell array (contains C matrix) 0031 % 'DMATS' cell array (contains D matrices) 0032 % 0033 % extra fileds not tested 0034 % 'FS' 'HS' string containing info for non linear simulations (not 0035 % implemented) 0036 % 'INPUTVARNAMES' cell array of cell array naming each input variable 0037 % 'OUTPUTVANAMES' cell array of output variable names (Y only enven if 0038 % Xisoutput is set to 1) 0039 % 'SSVARNAMES' cell array of state space variable names 0040 % 0041 % ***** THERE ARE NO DEFAULT PARAMETERS ***** 0042 % 0043 % VERSION: '$Id: ltpda_ss_check.m,v 1.5 2008/03/11 16:52:56 adrien Exp $' 0044 % 0045 % HISTORY: 0046 % 21-01-2008 A Grynagier 0047 % 21-01-2008 A Grynagier 0048 % Creation 05-01-2008 A Grynagier 0049 % 0050 % TO DO : 0051 % Complete plist automatically if missing fields 0052 % Modfiy the function such taht the order of the parameters does not matter 0053 % Add checks for the derviative fields later and think on how to handle the 0054 % linear derivative case 0055 % checks for new fields types? 0056 % 0057 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0058 %% standard calls for LTPDA function data 0059 0060 ALGONAME = mfilename; 0061 VERSION = '$Id: ltpda_ss_check.m,v 1.5 2008/03/11 16:52:56 adrien Exp $'; 0062 CATEGORY = 'STATESPACE'; 0063 display(['starting ' ALGONAME]); 0064 0065 if length(varargin) >0 0066 if isequal( varargin{1}, 'Version') 0067 varargout = VERSION; 0068 return; 0069 elseif isequal(varargin{1}, 'Params') 0070 varargout = plist(); 0071 return; 0072 elseif isequal(varargin{1}, 'Category') 0073 varargout = CATEGORY; 0074 return; 0075 end 0076 end 0077 0078 systs = varargin{1}; 0079 output = 1; 0080 0081 0082 %% proceeding checks 0083 for i=1:length(systs) 0084 syst =systs(i); 0085 try 0086 % check type is a system 0087 if not( isequal(syst.params(1).val,'SSSYSTEM') ) 0088 msg = [ 'Error in SubSystem ', find(syst,'NAME') , ' , TYPE is not defined as a subsystem']; 0089 error(msg); 0090 end 0091 0092 % system has a name 0093 if isequal(find(syst,'NAME') , '') 0094 msg = 'error because subsystem has no name!'; 0095 error(msg); 0096 end 0097 0098 % meaningful timestep 0099 if find(syst,'TIMESTEP')<0 0100 msg = [ 'error in SubSystem ', find(syst,'NAME') , ' because negative timestep']; 0101 error(msg); 0102 end 0103 0104 % check length of parameter data fields 0105 L4=length(find(syst,'PARAMNAMES')); 0106 L5=length(find(syst,'PARAMVALUES')); 0107 L6=length(find(syst,'PARAMSIGMAS')); 0108 if not( isequal(L4,L5,L6) ) 0109 msg = [ 'error in SubSystem ', find(syst,'NAME') , ', incoherent number of parameters/means/sigmas : ', num2str(L4), ',' , num2str(L5), ',' , num2str(L6) ]; 0110 error(msg); 0111 end 0112 % should check that the same parameter is not defined twice!!! 0113 0114 % test on the number of intputs 0115 L7=find(syst,'NBINPUTS') ; 0116 L8=length( find(syst,'INPUTNAMES') ); 0117 L9=length( find(syst,'INPUTSIZES') ); 0118 L10=length( find(syst,'INPUTISUSED') ); 0119 L12=length( find(syst,'BMATS') ); 0120 L14=length( find(syst,'DMATS') ); 0121 if not( isequal(L7,L8,L9,L10,L12,L14) ) 0122 msg = [ 'error in SubSystem ', find(syst,'NAME') , ' incoherent number of inputs/names/sizes/used/Bmats/Dmats: ', num2str(L7), ',' , num2str(L8), ',' , num2str(L9), ',' , num2str(L10), ',' , num2str(L12), ',' , num2str(L14) ]; 0123 error(msg); 0124 end 0125 0126 % test on the size of intput matrices 0127 % and fitting to state space and output size 0128 AMAT = find(syst,'AMAT'); 0129 CMAT = find(syst,'CMAT'); 0130 SSsize = size(AMAT{1},1); 0131 OUTsize = size(CMAT{1},1); 0132 INPUTSIZES = find(syst,'IMPUTNAMES'); 0133 BMATS = find(syst,'BMATS'); 0134 DMATS = find(syst,'DMATS'); 0135 INPUTNAMES = find(syst,'INPUTNAMES'); 0136 for j=1:length(INPUTSIZES) 0137 if not( isequal(INPUTSIZES(j),size(BMATS{j},2),size(DMATS{j},2) ) ) 0138 msg = [ 'error in SubSystem ', find(syst,'NAME') , ' for input named ', INPUTNAMES{j} ,' because size of input matrices and declared size do not match altoghether']; 0139 error(msg); 0140 end 0141 if not( isequal(SSsize,size(BMATS{j},1)) ) 0142 msg = [ 'error in SubSystem ', find(syst,'NAME') , ' because wrong size of B matrix (height does not fit to State Space) in input named ', INPUTNAMES{j}]; 0143 error(msg); 0144 end 0145 if not( isequal(OUTsize,size(DMATS{j},1)) ) 0146 msg = [ 'error in SubSystem ', find(syst,'NAME') , ' because wrong size of D matrix (height does not fit to Output) in input named ', INPUTNAMES{j}]; 0147 error(msg); 0148 end 0149 end 0150 0151 % test on A and C 0152 if not( isequal(SSsize, size(AMAT{1},2), size(CMAT{1},2)) ) 0153 msg= [ 'error in SubSystem ', find(syst,'NAME') , ' either because A is not square or C does not fit to A']; 0154 error(msg); 0155 end 0156 catch 0157 display(msg); 0158 output =0; 0159 end 0160 end 0161 varargout = {output}; 0162 end