core/matlab/examples/refbook/timestwoalt.c

00001 #include "mex.h"
00002 
00003 /*
00004  * timestwoalt.c - example found in API guide
00005  *
00006  * use mxGetScalar to return the values of scalars instead of pointers
00007  * to copies of scalar variables.
00008  *
00009  * This is a MEX-file for MATLAB.
00010  * Copyright 1984-2000 The MathWorks, Inc.
00011  */
00012  
00013 /* $Revision: 1.1 $ */
00014 
00015 void timestwo_alt(double *y, double x)
00016 {
00017   *y = 2.0*x;
00018 }
00019 
00020 void mexFunction( int nlhs, mxArray *plhs[],
00021                   int nrhs, const mxArray *prhs[] )
00022 {
00023   double *y;
00024   double  x;
00025 
00026     /* Check arguments */
00027     
00028   if (nrhs != 1) { 
00029     mexErrMsgTxt("One input argument required."); 
00030   } else if (nlhs > 1) {
00031     mexErrMsgTxt("Too many output arguments."); 
00032   } else if (!mxIsNumeric(prhs[0])) {
00033     mexErrMsgTxt("Argument must be numeric.");
00034   } else if (mxGetNumberOfElements(prhs[0]) != 1 || mxIsComplex(prhs[0])) {
00035     mexErrMsgTxt("Argument must be non-complex scalar.");
00036   }
00037   /* create a 1-by-1 matrix for the return argument */
00038   plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
00039 
00040   /* get the scalar value of the input x */
00041   /* note: mxGetScalar returns a value, not a pointer */
00042   x = mxGetScalar(prhs[0]);
00043 
00044   /* assign a pointer to the output */
00045   y = mxGetPr(plhs[0]);
00046   
00047   /* call the timestwo_alt subroutine */
00048   timestwo_alt(y,x);
00049 }
00050 

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