User`s manual
2 Creating C Language MEX-Files
2-18
 /* Check proper input and output */
 if(nrhs != 1)
 mexErrMsgTxt("One input required.");
 else if(nlhs > 1)
 mexErrMsgTxt("Too many output arguments.");
 else if(!mxIsStruct(prhs[0]))
 mexErrMsgTxt("Input must be a structure.");
 /* Get input arguments */
 nfields = mxGetNumberOfFields(prhs[0]);
 NStructElems = mxGetNumberOfElements(prhs[0]);
 /* allocate memory for storing classIDflags */
 classIDflags = mxCalloc(nfields, sizeof(int));
 /* Check empty field, proper data type, and data type
 consistency; get classID for each field. */
 for(ifield = 0; ifield < nfields; ifield++) {
 for(jstruct = 0; jstruct < NStructElems; jstruct++) {
 tmp = mxGetFieldByNumber(prhs[0], jstruct, ifield);
 if(tmp == NULL) {
 mexPrintf("%s%d\t%s%d\n",
 "FIELD:", ifield+1, "STRUCT INDEX :", jstruct+1);
 mexErrMsgTxt("Above field is empty!"); 
 } 
 if(jstruct == 0) {
 if((!mxIsChar(tmp) && !mxIsNumeric(tmp)) || 
 mxIsSparse(tmp)) { 
 mexPrintf("%s%d\t%s%d\n", 
 "FIELD:", ifield+1, "STRUCT INDEX :", jstruct+1);
 mexErrMsgTxt("Above field must have either "
 "string or numeric non-sparse data.");
 }
 classIDflags[ifield] = mxGetClassID(tmp); 
 } else {
 if(mxGetClassID(tmp) != classIDflags[ifield]) {
 mexPrintf("%s%d\t%s%d\n", 
 "FIELD:", ifield+1, "STRUCT INDEX :", jstruct+1);










