core/matlab/examples/refbook/timestwo.c

00001 #include "mex.h"
00002 
00003 /*
00004  * timestwo.c - example found in API guide
00005  *
00006  * Computational function that takes a scalar and double it.
00007  *
00008  * This is a MEX-file for MATLAB.
00009  * Copyright 1984-2006 The MathWorks, Inc.
00010  */
00011  
00012 /* $Revision: 1.1 $ */
00013 
00014 void timestwo(double y[], double x[])
00015 {
00016   y[0] = 2.0*x[0];
00017 }
00018 
00019 void mexFunction( int nlhs, mxArray *plhs[],
00020                   int nrhs, const mxArray *prhs[] )
00021 {
00022   double *x,*y;
00023   mwSize mrows,ncols;
00024   
00025   /* Check for proper number of arguments. */
00026   if(nrhs!=1) {
00027     mexErrMsgTxt("One input required.");
00028   } else if(nlhs>1) {
00029     mexErrMsgTxt("Too many output arguments");
00030   }
00031   
00032   /* The input must be a noncomplex scalar double.*/
00033   mrows = mxGetM(prhs[0]);
00034   ncols = mxGetN(prhs[0]);
00035   if( !mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) ||
00036       !(mrows==1 && ncols==1) ) {
00037     mexErrMsgTxt("Input must be a noncomplex scalar double.");
00038   }
00039   
00040   /* Create matrix for the return argument. */
00041   plhs[0] = mxCreateDoubleMatrix(mrows,ncols, mxREAL);
00042   
00043   /* Assign pointers to each input and output. */
00044   x = mxGetPr(prhs[0]);
00045   y = mxGetPr(plhs[0]);
00046   
00047   /* Call the timestwo subroutine. */
00048   timestwo(y,x);
00049 }

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