MATLAB: SsSetDWorkUsageType warning in c-mex S-function

s-functionsimulink

Hi all,
I have written an S-function which uses 6 DWork vectors which I specify that I want them to be used as discrete state vectors:
static void mdlInitializeSizes(SimStruct *S)
{
...
ssSetNumDWork(S, 6);
ssSetDWorkWidth(S, 0, 16);
ssSetDWorkWidth(S, 1, 16);
ssSetDWorkWidth(S, 2, 16);
ssSetDWorkWidth(S, 3, 16);
ssSetDWorkWidth(S, 4, 169);
ssSetDWorkWidth(S, 5, 16);
ssSetDWorkDataType(S, 0, SS_DOUBLE);
ssSetDWorkDataType(S, 1, SS_DOUBLE);
ssSetDWorkDataType(S, 2, SS_DOUBLE);
ssSetDWorkDataType(S, 3, SS_DOUBLE);
ssSetDWorkDataType(S, 4, SS_DOUBLE);
ssSetDWorkDataType(S, 5, SS_DOUBLE);
ssSetDWorkUsageType(S, 0, SS_DWORK_USED_AS_DSTATE);
ssSetDWorkUsageType(S, 1, SS_DWORK_USED_AS_DSTATE);
ssSetDWorkUsageType(S, 2, SS_DWORK_USED_AS_DSTATE);
ssSetDWorkUsageType(S, 3, SS_DWORK_USED_AS_DSTATE);
ssSetDWorkUsageType(S, 4, SS_DWORK_USED_AS_DSTATE);
ssSetDWorkUsageType(S, 5, SS_DWORK_USED_AS_DSTATE);
...
}
Later on, I use these DWork vectors on "mdlInitializeConditions", "mdlUpdate" and "mdlOutputs", e.g:
static void mdlInitializeConditions(SimStruct *S)
{
//Get pointers to DWork Vectors
real_T *x0 = (real_T*) ssGetDWork(S,0);
real_T *x1 = (real_T*) ssGetDWork(S,1);
real_T *x2 = (real_T*) ssGetDWork(S,2);
real_T *x3 = (real_T*) ssGetDWork(S,3);
real_T *x4 = (real_T*) ssGetDWork(S,4);
real_T *x5 = (real_T*) ssGetDWork(S,5);
//Get a pointer to the discrete states vector
real_T *x6=ssGetRealDiscStates(S);
//Get pointer to the elements of a signal (type double) connected to the input port specified by the index port
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
real_T tempConst[16]=...
real_T temptTable[256]=...
real_T t2;
int_T i;
for (i=0; i<256; i++)
x4[i]=temptTable[i];
for (i=0; i<16;i++)
{
x5[i]=15;
x3[i]=tempConst[i];
x0[i]=x5[i];
x2[i]=20;
x1[i]=x2[i];
x1[i]+=*uPtrs[i]*x4[i*16+i];
}
...
}
static void mdlOutputs(SimStruct *S, int_T tid)
{
int_T i;
//Get a pointer to the output signal (type double)
real_T *y = ssGetOutputPortRealSignal(S,0);
//DWork vectors (see mdlInitialiseConditions)
real_T *x0 = (real_T*) ssGetDWork(S,0);
real_T *x1 = (real_T*) ssGetDWork(S,1);
real_T *x2 = (real_T*) ssGetDWork(S,2);
real_T *x3 = (real_T*) ssGetDWork(S,3);
real_T *x4 = (real_T*) ssGetDWork(S,4);
real_T *x5 = (real_T*) ssGetDWork(S,5);
//Discrete state vector (see mdlInitialiseConditions)
real_T *x6=ssGetRealDiscStates(S); //deltaT
for (i=0; i<16; i++)
{
x5[i]=x1[i]+(x0[i]-x1[i]*exp(-x6[0]/x3[i]));
y[i]=x5[i];
}
}
Problem is that after I've compiled the c-mex file and run the simulation, I get the following warnings in the Matlab console:
Warning: The usedAsDState flag of data type work vector 1 of S-function 'Updmdl/S-Function' is ignored because it is not named
Warning: The usedAsDState flag of data type work vector 2 of S-function 'Updmdl/S-Function' is ignored because it is not named
...
Warning: The usedAsDState flag of data type work vector 6 of S-function 'Updmdl/S-Function' is ignored because it is not named
Anyone knows why the statement "is ignored", how could it be "named" and if it actually affects the results of the simulation?
Thank you in advance for your time.

Best Answer

I don't believe the warnings should affect the results of the simulation (if that were the case, you would be seeing errors, not warnings). The only effect of your DWorks not being registered as discrete states is that they will not be logged when State logging is turned on. You can name your DWorks using ssSetDWorkName.