core/matlab/examples/mx/mxisclass.c

00001 /*=================================================================
00002  * mxisclass.c 
00003  *
00004  * mxisclass takes no input arguments and returns no output
00005  * arguments. It creates an inline MATLAB object, and then gets and
00006  * prints the fields of this object.
00007  *
00008  * This is a MEX-file for MATLAB.  
00009  * Copyright 1984-2006 The MathWorks, Inc.
00010  * All rights reserved.
00011 *=================================================================*/
00012 
00013 /* $Revision: 1.1 $ */
00014 #include "mex.h"
00015    
00016 void
00017 mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
00018 {
00019     mxArray *output, *input;
00020     int number_of_fields, field_num;
00021 
00022     (void) plhs; (void) prhs;    /* unused parameters */
00023 
00024     /* Check for proper number of input and output arguments */    
00025     if (nrhs !=0) {
00026     mexErrMsgTxt("No input argument required.");
00027     } 
00028     if(nlhs > 1){
00029     mexErrMsgTxt("Too many output arguments.");
00030     }
00031     input=mxCreateString("sin(3*x)");
00032 
00033     /* Use mexCallMATLAB to call the constructor and create the
00034        object in MATLAB */
00035     mexCallMATLAB(1,&output, 1, &input,"inline");
00036     mxDestroyArray(input);
00037 
00038     /* Verify that the output an inline object, if it is get 
00039        its fields and print them. */
00040     if (!mxIsClass(output, "inline")) {
00041     mxDestroyArray(output);
00042     mexErrMsgTxt("Failed to create an object of class inline"); 
00043     }
00044     number_of_fields = mxGetNumberOfFields(output);
00045     mexPrintf("This object contains the following fields:\n");
00046     mexPrintf("name\t\tclass\t\tvalue\n");
00047     mexPrintf("-------------------------------------\n");
00048     /* Get the first field name, then the second, and so on. */ 
00049     for (field_num=0; field_num<number_of_fields; field_num++){
00050     mxArray *pa;
00051     mexPrintf("%s", mxGetFieldNameByNumber(output, field_num));
00052     pa = mxGetFieldByNumber(output, 0, field_num);
00053     mexPrintf("\t\t%s\t\t", mxGetClassName(pa));
00054     mexCallMATLAB(0, NULL, 1, &pa, "disp");
00055     }
00056     mxDestroyArray(output);
00057 }

GridLAB-DTM Version 1.0
An open-source project initiated by the US Department of Energy