CATIA-Systems / FMIKit-Simulink

Import and export Functional Mock-up Units with Simulink
Other
155 stars 50 forks source link

Nested Parameters in Structures not assigning start attribute in modelDescription.xml #372

Open markilg opened 1 year ago

markilg commented 1 year ago

Using a structure for block masked parameters the xml does not generate a start value for the model yielding an error loading the FMU (v2).

Suggested Fix although hacky:

Line 189 of grtfmulib.tlc Replace %assign startAttr = "" With %assign startAttr = FEVAL("grtfmi_get_start_value_workspace",variableName,rowid,colid)

And use the following matlab function:

function value = grtfmi_get_start_value_workspace(variableName,iCol,iRow)
    if (strfind(variableName,'Parameters.')==1)
        var = sprintf('%s(%d,%d)',variableName(12:end),iCol+1,iRow+1);
        try
            value = sprintf(' start="%g" ', evalin('base',var));
        catch
            warning('Variable not in base workspace: %s',var);    
            value = ' ';
        end
    else
        value = ' ';
    end

Not typically a TLC author so there may be an elegant way to do this in the TLC language and add checks for variable scope.

t-sommer commented 1 year ago

Can you share an example model to reproduce the problem?

nl78 commented 9 months ago

Seems to be linked to https://github.com/CATIA-Systems/FMIKit-Simulink/issues/401