source: trunk/lang/matlab/RpMatlabInterface.cc @ 6716

Last change on this file since 6716 was 5673, checked in by ldelgass, 9 years ago

Fix line endings, set eol-style to native on all C/C++ sources.

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Matlab Rappture Library Interface Helper Functions
4 *
5 * ======================================================================
6 *  AUTHOR:  Derrick Kearney, Purdue University
7 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
8 *
9 *  See the file "license.terms" for information on usage and
10 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 * ======================================================================
12 */
13#include "RpMatlabInterface.h"
14
15int
16getIntInput ( const mxArray* prhs ) {
17
18    int retVal = -1;
19    retVal = (int) getDoubleInput(prhs);
20    return retVal;
21}
22
23double
24getDoubleInput ( const mxArray* prhs ) {
25
26    double retVal = -1;
27
28    /* Input must be a double. */
29    if (mxIsDouble(prhs) != 1) {
30        mexErrMsgTxt("Input must be a double.");
31        return retVal;
32    }
33
34    /* Input must be a scalar. */
35    if ( (mxGetN(prhs)*mxGetM(prhs)) != 1) {
36        mexErrMsgTxt("Input must be a scalar.");
37        return retVal;
38    }
39
40    retVal = *mxGetPr(prhs);
41
42    return retVal;
43}
44
45char*
46getStringInput ( const mxArray* prhs ) {
47
48    int         buflen = 0;
49    int         status = 0;
50    char*       path = NULL;
51
52    /* Input must be a string. */
53    if (mxIsChar(prhs) != 1)
54        mexErrMsgTxt("Input must be a string.");
55
56    /* Input must be a row vector. */
57    if ( (mxGetM(prhs) == 0) && (mxGetN(prhs) == 0)) {
58        // do nothin, accept empty strings
59    } else if ( (mxGetM(prhs)) != 1) {
60        mexErrMsgTxt("Input must be a row vector.");
61    }
62
63    /* Get the length of the input string. */
64    buflen = (mxGetM(prhs) * mxGetN(prhs)) + 1;
65
66    /* Allocate memory for input and output strings. */
67    path = (char*) mxCalloc(buflen, sizeof(char));
68
69    /* Copy the string data from prhs[0] into a C string
70     * path. */
71    status = mxGetString(prhs, path, buflen);
72    if (status != 0)
73        mexWarnMsgTxt("Not enough space. String is truncated.");
74
75    return path;
76}
77
78void
79freeStringInput (void* ptr) {
80    if (ptr != NULL) {
81        mxFree(ptr);
82    }
83    ptr = NULL;
84}
85
86void
87rpmxFlush() {
88    mxArray * emptyStr = mxCreateString("");
89    mexCallMATLAB(0,0,1,&emptyStr,"fprintf");
90}
91
Note: See TracBrowser for help on using the repository browser.