MATLAB: C-Code generation from Simulink issues

c-code generation simulink

I am working with C-code generated scripts from Simulink blocks that were created using a relatively old version of Matlab. My employer is trying to move away from older Matlab versions and wants us generating the c-code in R2012B (32 bit). I have noticed that the c-code function used for interpolation writes the entire function into the main file (this same function was only called in earlier version). This creates a few issues for the team I hand this off to for implementation. Is there a parameter or configuration flag that I can change to prevent this in Simulink. We are doing this in bulk so simply deleting and moving to an eternal function is not practical.
I have copied in the c-code interpolation function
{real_T look1_pbinlcpw(real_T u0, const real_T bp0[], const real_T table[], uint32_T prevIndex[], uint32_T maxIndex) { real_T frac; uint32_T startIndex; uint32_T iRght; uint32_T iLeft; uint32_T found;
/* Lookup 1-D
Search method: 'binary'
Use previous index: 'on'
Interpolation method: 'Linear'
Extrapolation method: 'Clip'
Use last breakpoint for index at or above upper limit: 'off'
Remove protection against out-of-range input in generated code: 'off'
*/
/* Prelookup - Index and Fraction
Index Search method: 'binary'
Extrapolation method: 'Clip'
Use previous index: 'on'
Use last breakpoint for index at or above upper limit: 'off'
Remove protection against out-of-range input in generated code: 'off'
*/
if (u0 <= bp0[0U]) {
startIndex = 0U;
frac = 0.0;
} else if (u0 < bp0[maxIndex]) {
startIndex = prevIndex[0U];
/* Binary Search using Previous Index */
iLeft = 0U;
iRght = maxIndex;
found = 0U;
while (found == 0U) {
if (u0 < bp0[startIndex]) {
iRght = startIndex - 1U;
startIndex = (iRght + iLeft) >> 1U;
} else if (u0 < bp0[startIndex + 1U]) {
found = 1U;
} else {
iLeft = startIndex + 1U;
startIndex = (iRght + iLeft) >> 1U;
}
}
frac = (u0 - bp0[startIndex]) / (bp0[startIndex + 1U] - bp0[startIndex]);
} else {
startIndex = maxIndex - 1U;
frac = 1.0;
}
prevIndex[0U] = startIndex;
/* Interpolation 1-D
Interpolation method: 'Linear'
Use last breakpoint for index at or above upper limit: 'off'
Overflow mode: 'portable wrapping'
*/
return (table[startIndex + 1U] - table[startIndex]) * frac + table[startIndex];
}
}

Best Answer

set_param('Your_Model', 'UtilityFuncGeneration', 'Shared location')