core/matlab/examples/mx/mxislogical.c

00001 /*=================================================================
00002  * mxislogical.c 
00003  * This example demonstrates how to use mexIsGlobal, mexGetArrayPtr,
00004  * mxIsLogical.  You pass in the name of a variable in the caller
00005  * workspace.  It then gets the pointer to that variable and returns
00006  * a two element logical array.  The first element indicates whether
00007  * the named variable is a logical, the second whether it is a global.
00008  *
00009  * This is a MEX-file for MATLAB.  
00010  * Copyright 1984-2001 The MathWorks, Inc.
00011  *=================================================================*/
00012 /* $Revision: 1.1 $ */
00013 
00014 #include "mex.h"
00015 
00016 void
00017 mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
00018 {
00019     const mxArray  *array_ptr;
00020     char     *variable;
00021     mxLogical *pl;
00022 
00023     /* Check for proper number of input and output arguments */    
00024     if (nrhs != 1) {
00025     mexErrMsgTxt("One input argument required.");
00026     } 
00027     if(nlhs > 1){
00028     mexErrMsgTxt("Too many output arguments.");
00029     }
00030 
00031     /* Check to be sure input argument is a string. */
00032     if (!(mxIsChar(prhs[0]))){
00033     mexErrMsgTxt("Input must be of type string.");
00034     }
00035     
00036     /* Get input variable */
00037     variable= mxArrayToString(prhs[0]);
00038     array_ptr = mexGetVariablePtr("caller", variable);
00039     if (array_ptr == NULL){
00040     mexErrMsgTxt("Could not get variable.\n");
00041     }
00042 
00043     plhs[0] = mxCreateLogicalMatrix(1,2);
00044     pl = mxGetLogicals(plhs[0]);
00045 
00046     pl[0] = mxIsLogical(array_ptr);
00047     pl[1] = mexIsGlobal(array_ptr);
00048 
00049     mxFree(variable);
00050 }
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 

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