⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getstruct.c

📁 《精通matlab与c++混合编程》的光盘内容
💻 C
字号:
/*
 * MATLAB Compiler: 3.0
 * Date: Fri Sep 26 08:59:13 2003
 * Arguments: "-B" "macro_default" "-O" "all" "-O" "fold_scalar_mxarrays:on"
 * "-O" "fold_non_scalar_mxarrays:on" "-O" "optimize_integer_for_loops:on" "-O"
 * "array_indexing:on" "-O" "optimize_conditionals:on" "-M" "-silentsetup" "-d"
 * "C:/TEMP/structdemo/structfiles/src" "-v" "-B"
 * "ccom:structfiles,structutils,1.0" "-t" "-W"
 * "com:structfiles,structutils,1.0" "-T" "link:lib" "-h" "libmmfile.mlib" "-i"
 * "-i" "C:/TEMP/structdemo/displaystruct.m" "C:/TEMP/structdemo/getstruct.m" 
 */
#include "getstruct.h"
#include "displaystruct.h"
#include "libmatlbm.h"
static mxArray * _mxarray0_;

static mxChar _array2_[30] = { 'I', 'n', 'p', 'u', 't', 's', ' ', 'm',
                               'u', 's', 't', ' ', 'b', 'e', ' ', 't',
                               'h', 'e', ' ', 's', 'a', 'm', 'e', ' ',
                               'l', 'e', 'n', 'g', 't', 'h' };
static mxArray * _mxarray1_;
static mxArray * _mxarray3_;

void InitializeModule_getstruct(void) {
    _mxarray0_ = mclInitializeDouble(2.0);
    _mxarray1_ = mclInitializeString(30, _array2_);
    _mxarray3_ = mclInitializeDoubleVector(0, 0, (double *)NULL);
}

void TerminateModule_getstruct(void) {
    mxDestroyArray(_mxarray3_);
    mxDestroyArray(_mxarray1_);
    mxDestroyArray(_mxarray0_);
}

static mxArray * Mgetstruct(int nargout_, mxArray * fields, mxArray * values);

_mexLocalFunctionTable _local_function_table_getstruct
  = { 0, (mexFunctionTableEntry *)NULL };

/*
 * The function "mlfGetstruct" contains the normal interface for the
 * "getstruct" M-function from file "c:\temp\structdemo\getstruct.m" (lines
 * 1-12). This function processes any input arguments and passes them to the
 * implementation version of the function, appearing above.
 */
mxArray * mlfGetstruct(mxArray * fields, mxArray * values) {
    int nargout = 1;
    mxArray * y = NULL;
    mlfEnterNewContext(0, 2, fields, values);
    y = Mgetstruct(nargout, fields, values);
    mlfRestorePreviousContext(0, 2, fields, values);
    return mlfReturnValue(y);
}

/*
 * The function "mlxGetstruct" contains the feval interface for the "getstruct"
 * M-function from file "c:\temp\structdemo\getstruct.m" (lines 1-12). The
 * feval function calls the implementation version of getstruct through this
 * function. This function processes any input arguments and passes them to the
 * implementation version of the function, appearing above.
 */
void mlxGetstruct(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
    mxArray * mprhs[2];
    mxArray * mplhs[1];
    int i;
    if (nlhs > 1) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: getstruct Line: 1 Column:"
            " 1 The function \"getstruct\" was called with m"
            "ore than the declared number of outputs (1)."),
          NULL);
    }
    if (nrhs > 2) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: getstruct Line: 1 Column:"
            " 1 The function \"getstruct\" was called with m"
            "ore than the declared number of inputs (2)."),
          NULL);
    }
    for (i = 0; i < 1; ++i) {
        mplhs[i] = NULL;
    }
    for (i = 0; i < 2 && i < nrhs; ++i) {
        mprhs[i] = prhs[i];
    }
    for (; i < 2; ++i) {
        mprhs[i] = NULL;
    }
    mlfEnterNewContext(0, 2, mprhs[0], mprhs[1]);
    mplhs[0] = Mgetstruct(nlhs, mprhs[0], mprhs[1]);
    mlfRestorePreviousContext(0, 2, mprhs[0], mprhs[1]);
    plhs[0] = mplhs[0];
}

/*
 * The function "Mgetstruct" is the implementation version of the "getstruct"
 * M-function from file "c:\temp\structdemo\getstruct.m" (lines 1-12). It
 * contains the actual compiled code for that M-function. It is a static
 * function and must only be called from one of the interface functions,
 * appearing below.
 */
/*
 * function y = getstruct(fields, values)
 */
static mxArray * Mgetstruct(int nargout_, mxArray * fields, mxArray * values) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(&_local_function_table_getstruct);
    mxArray * y = NULL;
    mxArray * i = NULL;
    mxArray * ans = NULL;
    mxArray * nv = NULL;
    mxArray * nf = NULL;
    mclCopyArray(&fields);
    mclCopyArray(&values);
    /*
     * nf = size(fields, 2);
     */
    mlfAssign(
      &nf, mlfSize(mclValueVarargout(), mclVa(fields, "fields"), _mxarray0_));
    /*
     * nv = size(values, 2);
     */
    mlfAssign(
      &nv, mlfSize(mclValueVarargout(), mclVa(values, "values"), _mxarray0_));
    /*
     * if (nf ~= nv)
     */
    if (mclNeBool(mclVv(nf, "nf"), mclVv(nv, "nv"))) {
        /*
         * error('Inputs must be the same length');
         */
        mlfError(_mxarray1_, NULL);
        /*
         * return;
         */
        goto return_;
    /*
     * end
     */
    }
    /*
     * for i=1:nf
     */
    {
        int v_ = mclForIntStart(1);
        int e_ = mclForIntEnd(mclVv(nf, "nf"));
        if (v_ > e_) {
            mlfAssign(&i, _mxarray3_);
        } else {
            /*
             * y.(fields{i}) = values{i};
             * end
             */
            for (; ; ) {
                mlfIndexAssign(
                  &y,
                  ".(?)",
                  mlfIndexRef(mclVa(fields, "fields"), "{?}", mlfScalar(v_)),
                  mlfIndexRef(mclVa(values, "values"), "{?}", mlfScalar(v_)));
                if (v_ == e_) {
                    break;
                }
                ++v_;
            }
            mlfAssign(&i, mlfScalar(v_));
        }
    }
    /*
     * displaystruct(y)
     */
    mlfDisplaystruct(mclVv(y, "y"));
    return_:
    mclValidateOutput(y, 1, nargout_, "y", "getstruct");
    mxDestroyArray(nf);
    mxDestroyArray(nv);
    mxDestroyArray(ans);
    mxDestroyArray(i);
    mxDestroyArray(values);
    mxDestroyArray(fields);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
    return y;
    /*
     * 
     */
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -