From 533b566fc36c9ee404a9d981348125516efa0535 Mon Sep 17 00:00:00 2001 From: galperti <cristian.galperti@epfl.ch> Date: Thu, 16 Jun 2022 14:25:40 +0200 Subject: [PATCH] logical type case included in mdsparnumeric loader class --- algos/template/algo_template_loadtp.m | 2 ++ algos/template/algoobj_template.m | 1 + classes/SCDclass_mdspar.m | 3 +- classes/SCDclass_mdsparnumeric.m | 51 +++++++++++++++++++-------- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/algos/template/algo_template_loadtp.m b/algos/template/algo_template_loadtp.m index 80347de..1bc8b55 100644 --- a/algos/template/algo_template_loadtp.m +++ b/algos/template/algo_template_loadtp.m @@ -1,9 +1,11 @@ function TP = algo_template_loadtp() % Setup tunable control params +TP.enable = true; TP.gain = single(2); TP.refmodel.gain = 4; % another gain used in referenced model TP.rowvect = int32([1 2 3]); TP.colvect = int16([1 2 3]'); TP.matrix = int8([1 2; 3 4]); + end diff --git a/algos/template/algoobj_template.m b/algos/template/algoobj_template.m index 558f4c4..b93ee78 100644 --- a/algos/template/algoobj_template.m +++ b/algos/template/algoobj_template.m @@ -13,6 +13,7 @@ obj=obj.addfpinitfcn('algo_template_loadfp','algo_template_fp'); obj=obj.addtunparamstruct('algo_template_tp', @()algo_template_loadtp(), false); %% Tunable parameters +obj=obj.addparameter(SCDclass_mdsparnumeric('kb1','enable' ,'srcsrv','spcpc171.epfl.ch','srctree','martetest')); obj=obj.addparameter(SCDclass_mdsparnumeric('ks1','gain' ,'srcsrv','spcpc171.epfl.ch','srctree','martetest')); obj=obj.addparameter(SCDclass_mdsparnumeric('ks2','refmodel.gain' ,'srcsrv','spcpc171.epfl.ch','srctree','martetest')); obj=obj.addparameter(SCDclass_mdsparnumeric('kv1','rowvect' ,'srcsrv','spcpc171.epfl.ch','srctree','martetest')); diff --git a/classes/SCDclass_mdspar.m b/classes/SCDclass_mdspar.m index 6f32b58..e6c43ab 100644 --- a/classes/SCDclass_mdspar.m +++ b/classes/SCDclass_mdspar.m @@ -42,6 +42,7 @@ classdef SCDclass_mdspar < matlab.mixin.Heterogeneous mdsvalidationstr % MDS validation string used in autopopulation loadpermissivity % true if load error shoudn't cause an error (warning only) + logicalmdstype % expected type for a logical parameter end properties @@ -68,7 +69,7 @@ classdef SCDclass_mdspar < matlab.mixin.Heterogeneous obj.verbose=1; obj.matlabseparator='.'; obj.marteseparator='-'; - + obj.logicalmdstype='uint8'; % generated C code uses uint8 to handle logicals end function obj=parseconstructor(obj, srctdimodel, destparam, varargin) diff --git a/classes/SCDclass_mdsparnumeric.m b/classes/SCDclass_mdsparnumeric.m index e62f145..bab4db5 100644 --- a/classes/SCDclass_mdsparnumeric.m +++ b/classes/SCDclass_mdsparnumeric.m @@ -27,23 +27,24 @@ classdef SCDclass_mdsparnumeric < SCDclass_mdspar return; end - %%% Actualization checks %%% - % dimensions + %%%% Actualization checks %%%% + boolcast=false; + %%% dimensions sourcedim=size(obj.value); targetdim=Simulink.data.evalinGlobal(obj.modelname,sprintf('size(%s)',obj.assignvar)); - actchk=true; if numel(sourcedim)~=numel(targetdim) + sourcedim + targetdim if obj.loadpermissivity warning('SCDDScore:mdsparnumeric','%s: number of dimensions not matching, actualization skipped!',obj.modelparam); else error('SCDDScore:mdsparnumeric','%s: number of dimensions not matching, actualization skipped!',obj.modelparam); end - sourcedim - targetdim + actchk=false; end - % handle vector transposition + %%% handle vector transposition if numel(sourcedim)==2 && ~isscalar(obj.value) if (sourcedim(1)==1 && targetdim(2)==1) || (sourcedim(2)==1 && targetdim(1)==1) % we've a vector to transpose @@ -55,27 +56,43 @@ classdef SCDclass_mdsparnumeric < SCDclass_mdspar end end if actchk && ~any(sourcedim == targetdim) + sourcedim + targetdim if obj.loadpermissivity warning('SCDDScore:mdsparnumeric','%s: dimensions not matching, actualization skipped!',obj.modelparam); else error('SCDDScore:mdsparnumeric','%s: dimensions not matching, actualization skipped!',obj.modelparam); end - sourcedim - targetdim actchk=false; - end - - % type + end + %%%% type sourceclass=class(obj.value); targetclass=Simulink.data.evalinGlobal(obj.modelname,sprintf('class(%s)',obj.assignvar)); + %%% handle cast to logical + if strcmp(targetclass,'logical') + if ~strcmp(sourceclass,'uint8') + sourceclass + if obj.loadpermissivity + warning('SCDDScore:mdsparnumeric','%s: source type must be %s for logical parameters',obj.modelparam,obj.logicalmdstype); + else + error('SCDDScore:mdsparnumeric','%s: source type must be %s for logical parameters',obj.modelparam,obj.logicalmdstype); + end + actchk=false; + end + if actchk + sourceclass='logical'; + boolcast=true; + end + end + %%% type check if actchk && ~strcmp(sourceclass,targetclass) + sourceclass + targetclass if obj.loadpermissivity warning('SCDDScore:mdsparnumeric','%s: Data types not matching, actualization skipped!',obj.modelparam); else error('SCDDScore:mdsparnumeric','%s: Data types not matching, actualization skipped!',obj.modelparam); end - sourceclass - targetclass actchk=false; end @@ -83,8 +100,12 @@ classdef SCDclass_mdsparnumeric < SCDclass_mdspar % interface do not provide in information (matrix % orientation) to do this. Or, probably, I misunderstood and % matrix orientation is always preserved - - obj.caststring=sprintf('%s=%s;',obj.assignvar,obj.assignvar); + + if boolcast + obj.caststring=sprintf('%s=logical(%s);',obj.assignvar,obj.assignvar); + else + obj.caststring=sprintf('%s=%s;',obj.assignvar,obj.assignvar); + end if actchk obj.postactualize(shot); end -- GitLab