C S-Function doesn't work anymore on different Matlab/compiler. Probably pointer problem.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone
I have a C S-Function that used to work on R2013b with Visual Studio Pro 2011 as compiler. Now with R2016b and MinGW64 as compiler, it crashes Matlab completely.
In mdlOutputs, I have removed a switch-case structure, which just repeats the problem with different parameters.
I can't find the problem. If you need more information, please ask.
/* specify the name of your S-Function */
#define S_FUNCTION_NAME defectiveFunction
#define S_FUNCTION_LEVEL 2
/*
* Need to include simstruc.h for the definition of the SimStruct and
* its associated macro definitions. Need math.h for exp-function.
*/
#include "tmwtypes.h"
#include "simstruc.h"
#include <math.h>
#define BLI_A (*mxGetPr(ssGetSFcnParam(S, 0)))
#define BLI_B (*mxGetPr(ssGetSFcnParam(S, 1)))
#define BLI_C (*mxGetPr(ssGetSFcnParam(S, 2)))
#define BLI_D (*mxGetPr(ssGetSFcnParam(S, 3)))
#define BLI_ALPHA (*mxGetPr(ssGetSFcnParam(S, 4)))
#define BLI_REFL (*mxGetPr(ssGetSFcnParam(S, 5)))
#define SHAD_TYPE ((int)(*mxGetPr(ssGetSFcnParam(S, 6))+0.5)) // Removed switch-case
#define TYPE_GLAZING ((int)(*mxGetPr(ssGetSFcnParam(S, 7))+0.5)) // Removed switch-case
#define TAU_SHAD (*mxGetPr(ssGetSFcnParam(S, 8)))
#define R_SHAD (*u[0])
#define ZEN_ANGLE (*u[1])
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumSFcnParams(S, 9); /* Number of expected parameters */
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S))
{
/* Return if number of expected != number of actual parameters */
return;
}
if (!ssSetNumInputPorts(S, 1)) /* number of inputs */
{
return;
}
ssSetInputPortWidth(S, 0, 2);
if (!ssSetNumOutputPorts(S, 1)) /* number of outputs */
{
return;
}
ssSetOutputPortWidth(S, 0, 4);
ssSetNumSampleTimes(S, 1); /* number of sample times */
}
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, 0.0);
ssSetOffsetTime(S, 0, 0.0);
}
static void mdlOutputs(SimStruct *S, int_T tid)
{
InputRealPtrsType u = ssGetInputPortRealSignalPtrs(S, 0);
real_T *y = ssGetOutputPortRealSignal(S, 0);
int shad_type = SHAD_TYPE;
double r_shad = R_SHAD;
int type_glazing = TYPE_GLAZING;
double tau_shad = TAU_SHAD;
double bli_a = BLI_A;
double bli_b = BLI_B;
double bli_c = BLI_C;
double bli_d = BLI_D;
double bli_refl = BLI_REFL;
#ifdef PI
double pi = PI;
#else
double pi = 3.14159;
#endif
double zen_angle = ZEN_ANGLE*pi/180.0;
double bli_alpha = BLI_ALPHA*pi/180.0;
double cos_a = cos(bli_alpha);
double sin_a = sin(bli_alpha);
double X_shad, X_shad_a, X_shad_b, F_Shad_dir, bli_r, a2, d2, f_para, e_para, gamma, F_Shad_dfu, refl_alpha, D_refl, f_g;
double el_h=(pi/2.0-zen_angle);
double epsilon=atan(bli_b/bli_c);
double A_corr=1.3; //weight factor empirically evaluated with task34 empa measurments
/* Removed switch-case */
//'Exterior Screen'
y[0]=1.0-r_shad*(1.0-tau_shad); // THIS CRASHES
y[1]=1.0-r_shad*(1.0-tau_shad);
y[2]=1.0; // THIS WORKS
y[3]=1.0;
/* Removed switch-case */
}
static void mdlTerminate(SimStruct *S)
{
}
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */
#include "simulink.c" /* MEX-file interface mechanism */
#else
#include "cg_sfun.h" /* Code generation registration function */
#endif
2 comentarios
Respuestas (1)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!