core/matlab/examples/mex/mexfunction.c

00001 /*=================================================================
00002  * mexfunction.c 
00003  *
00004  * This example demonstrates how to use mexFunction.  It returns
00005  * the number of elements for each input argument, providing the 
00006  * function is called with the same number of output arguments
00007  * as input arguments.
00008  
00009  * This is a MEX-file for MATLAB.  
00010  * Copyright 1984-2006 The MathWorks, Inc.
00011  * All rights reserved.
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     int        i;
00020        
00021     /* Examine input (right-hand-side) arguments. */
00022     mexPrintf("\nThere are %d right-hand-side argument(s).", nrhs);
00023     for (i=0; i<nrhs; i++)  {
00024     mexPrintf("\n\tInput Arg %i is of type:\t%s ",i,mxGetClassName(prhs[i]));
00025     }
00026     
00027     /* Examine output (left-hand-side) arguments. */
00028     mexPrintf("\n\nThere are %d left-hand-side argument(s).\n", nlhs);
00029     if (nlhs > nrhs)
00030       mexErrMsgTxt("Cannot specify more outputs than inputs.\n");
00031     for (i=0; i<nlhs; i++)  {
00032     plhs[i]=mxCreateDoubleMatrix(1,1,mxREAL);
00033     *mxGetPr(plhs[i])=(double)mxGetNumberOfElements(prhs[i]);
00034     }
00035 }
00036 

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