Home > m > timetools > statespacefunctions > ltpda_ss_check.m

ltpda_ss_check

PURPOSE ^

ltpda_ss_check throws an error is something is wrong is found in the subsystem.

SYNOPSIS ^

function varargout = ltpda_ss_check(varargin)

DESCRIPTION ^

 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.4 2008/02/26 20:18:19 adrien Exp $'

 HISTORY: 
 21-01-2008 A Grynagier
 Creation 05-01-2008 A Grynagier

 TO DO :  
 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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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.4 2008/02/26 20:18:19 adrien Exp $'
0044 %
0045 % HISTORY:
0046 % 21-01-2008 A Grynagier
0047 % Creation 05-01-2008 A Grynagier
0048 %
0049 % TO DO :
0050 % Add checks for the derviative fields later and think on how to handle the
0051 % linear derivative case
0052 % checks for new fields types?
0053 %
0054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0055 %% standard calls for LTPDA function data
0056 
0057 ALGONAME = mfilename;
0058 VERSION =  '$Id: ltpda_ss_check.m,v 1.4 2008/02/26 20:18:19 adrien Exp $';
0059 CATEGORY = 'STATESPACE';
0060 display(['starting ' ALGONAME]);
0061 
0062 if length(varargin) >0
0063     if isequal( varargin{1}, 'Version')
0064         varargout = VERSION;
0065         return;
0066     elseif isequal(varargin{1}, 'Params')
0067         varargout = plist();
0068         return;
0069     elseif isequal(varargin{1}, 'Category')
0070         varargout = CATEGORY;
0071         return;
0072     end
0073 end
0074 
0075 systs = varargin{1};
0076 output = 1;
0077 
0078 
0079 %% proceeding checks
0080 for i=1:length(systs)
0081     syst =systs(i);
0082     try
0083         % check type is a system
0084         if not( isequal(syst.params(1).val,'SUBSYSTEM') )
0085             msg = [ 'Error in SubSystem ', find(syst,'NAME') , ' , TYPE is not defined as a subsystem'];
0086             error(msg);
0087         end
0088 
0089         % system has a name
0090         if isequal(find(syst,'NAME') , '')
0091             msg = 'error because subsystem has no name!';
0092             error(msg);
0093         end
0094 
0095         % meaningful timestep
0096         if find(syst,'TIMESTEP')<0
0097             msg = [ 'error in SubSystem ', find(syst,'NAME') , '  because negative timestep'];
0098             error(msg);
0099         end
0100 
0101         % check length of parameter data fields
0102         L4=length(find(syst,'PARAMNAMES'));
0103         L5=length(find(syst,'PARAMVALUES'));
0104         L6=length(find(syst,'PARAMSIGMAS'));
0105         if not( isequal(L4,L5,L6) )
0106             msg = [ 'error in SubSystem ', find(syst,'NAME') , ', incoherent number of parameters/means/sigmas : ', num2str(L4), ',' , num2str(L5), ',' , num2str(L6) ];
0107             error(msg);
0108         end
0109         % should check that the same parameter is not defined twice!!!
0110 
0111         % test on the number of intputs
0112         L7=find(syst,'NBINPUTS') ;
0113         L8=length( find(syst,'INPUTNAMES') );
0114         L9=length( find(syst,'INPUTSIZES') );
0115         L10=length( find(syst,'INPUTISUSED') );
0116         L12=length( find(syst,'BMATS') );
0117         L14=length( find(syst,'DMATS') );
0118         if not( isequal(L7,L8,L9,L10,L12,L14) )
0119             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) ];
0120             error(msg);
0121         end
0122 
0123         % test on the size of intput matrices
0124         % and fitting to state space and output size
0125         AMAT = find(syst,'AMAT');
0126         CMAT = find(syst,'CMAT');
0127         SSsize = size(AMAT{1},1);
0128         OUTsize = size(CMAT{1},1);
0129         INPUTSIZES = find(syst,'IMPUTNAMES');
0130         BMATS = find(syst,'BMATS');
0131         DMATS = find(syst,'DMATS');
0132         INPUTNAMES = find(syst,'INPUTNAMES');
0133         for i=1:length(INPUTSIZES)
0134             if not( isequal(INPUTSIZES(i),size(BMATS{i},2),size(DMATS{i},2) ) )
0135                 msg = [ 'error in SubSystem ', find(syst,'NAME') , ' for input named ', INPUTNAMES{i} ,' because size of input matrices and declared size do not match altoghether'];
0136                 error(msg);
0137             end
0138             if not( isequal(SSsize,size(BMATS{i},1)) )
0139                 msg = [ 'error in SubSystem ', find(syst,'NAME') , ' because wrong size of B matrix (height does not fit to State Space) in input named ', INPUTNAMES{i}];
0140                 error(msg);
0141             end
0142             if not( isequal(OUTsize,size(DMATS{i},1)) )
0143                 msg = [ 'error in SubSystem ', find(syst,'NAME') , ' because wrong size of D matrix (height does not fit to Output) in input named ', INPUTNAMES{i}];
0144                 error(msg);
0145             end
0146         end
0147 
0148         % test on A and C
0149         if not( isequal(SSsize, size(AMAT{1},2), size(CMAT{1},2)) )
0150             msg= [ 'error in SubSystem ', find(syst,'NAME') , ' either because A is not square or C does not fit to A'];
0151             error(msg);
0152         end
0153     catch
0154         output =0;
0155     end
0156 end
0157 varargout = {output};
0158 end

Generated on Fri 07-Mar-2008 15:46:43 by m2html © 2003