hot.c

来自「《精通matlab与c++混合编程》的光盘内容」· C语言 代码 · 共 201 行

C
201
字号
/*
 * MATLAB Compiler: 3.0
 * Date: Thu Jun 21 20:40:43 2001
 * 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" "-B" "sgl" "-m" "-W"
 * "main" "-L" "C" "-t" "-T" "link:exe" "-h" "libmmfile.mlib" "-W" "mainhg"
 * "libmwsglm.mlib" "flames.m" 
 */
#include "hot.h"
#include "libmatlbm.h"
#include "libmmfile.h"

static mxChar _array1_[8] = { 'c', 'o', 'l', 'o', 'r', 'm', 'a', 'p' };
static mxArray * _mxarray0_;
static mxArray * _mxarray2_;
static mxArray * _mxarray3_;
static mxArray * _mxarray4_;

void InitializeModule_hot(void) {
    _mxarray0_ = mclInitializeString(8, _array1_);
    _mxarray2_ = mclInitializeDouble(1.0);
    _mxarray3_ = mclInitializeDouble(.375);
    _mxarray4_ = mclInitializeDouble(2.0);
}

void TerminateModule_hot(void) {
    mxDestroyArray(_mxarray4_);
    mxDestroyArray(_mxarray3_);
    mxDestroyArray(_mxarray2_);
    mxDestroyArray(_mxarray0_);
}

static mxArray * Mhot(int nargout_, mxArray * m);

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

/*
 * The function "mlfHot" contains the normal interface for the "hot" M-function
 * from file "c:\matlab6p5\toolbox\matlab\graph3d\hot.m" (lines 1-25). This
 * function processes any input arguments and passes them to the implementation
 * version of the function, appearing above.
 */
mxArray * mlfHot(mxArray * m) {
    int nargout = 1;
    mxArray * h = NULL;
    mlfEnterNewContext(0, 1, m);
    h = Mhot(nargout, m);
    mlfRestorePreviousContext(0, 1, m);
    return mlfReturnValue(h);
}

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

/*
 * The function "Mhot" is the implementation version of the "hot" M-function
 * from file "c:\matlab6p5\toolbox\matlab\graph3d\hot.m" (lines 1-25). 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 h = hot(m)
 */
static mxArray * Mhot(int nargout_, mxArray * m) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(&_local_function_table_hot);
    int nargin_ = mclNargin(1, m, NULL);
    mxArray * h = NULL;
    mxArray * b = NULL;
    mxArray * g = NULL;
    mxArray * r = NULL;
    mxArray * n = NULL;
    mclCopyArray(&m);
    /*
     * %HOT    Black-red-yellow-white color map.
     * %   HOT(M) returns an M-by-3 matrix containing a "hot" colormap.
     * %   HOT, by itself, is the same length as the current colormap.
     * %
     * %   For example, to reset the colormap of the current figure:
     * %
     * %             colormap(hot)
     * %
     * %   See also HSV, GRAY, PINK, COOL, BONE, COPPER, FLAG, 
     * %   COLORMAP, RGBPLOT.
     * 
     * %   C. Moler, 8-17-88, 5-11-91, 8-19-92.
     * %   Copyright 1984-2002 The MathWorks, Inc. 
     * %   $Revision: 5.7 $  $Date: 2002/04/08 22:00:14 $
     * 
     * if nargin < 1, m = size(get(gcf,'colormap'),1); end
     */
    if (nargin_ < 1) {
        mlfAssign(
          &m,
          mlfSize(
            mclValueVarargout(),
            mlfNGet(1, mlfGcf(), _mxarray0_, NULL),
            _mxarray2_));
    }
    /*
     * n = fix(3/8*m);
     */
    mlfAssign(&n, mlfFix(mclMtimes(_mxarray3_, mclVa(m, "m"))));
    /*
     * 
     * r = [(1:n)'/n; ones(m-n,1)];
     */
    mlfAssign(
      &r,
      mlfVertcat(
        mclMrdivide(
          mlfCtranspose(mlfColon(_mxarray2_, mclVv(n, "n"), NULL)),
          mclVv(n, "n")),
        mlfOnes(mclMinus(mclVa(m, "m"), mclVv(n, "n")), _mxarray2_, NULL),
        NULL));
    /*
     * g = [zeros(n,1); (1:n)'/n; ones(m-2*n,1)];
     */
    mlfAssign(
      &g,
      mlfVertcat(
        mlfZeros(mclVv(n, "n"), _mxarray2_, NULL),
        mclMrdivide(
          mlfCtranspose(mlfColon(_mxarray2_, mclVv(n, "n"), NULL)),
          mclVv(n, "n")),
        mlfOnes(
          mclMinus(mclVa(m, "m"), mclMtimes(_mxarray4_, mclVv(n, "n"))),
          _mxarray2_,
          NULL),
        NULL));
    /*
     * b = [zeros(2*n,1); (1:m-2*n)'/(m-2*n)];
     */
    mlfAssign(
      &b,
      mlfVertcat(
        mlfZeros(mclMtimes(_mxarray4_, mclVv(n, "n")), _mxarray2_, NULL),
        mclMrdivide(
          mlfCtranspose(
            mlfColon(
              _mxarray2_,
              mclMinus(mclVa(m, "m"), mclMtimes(_mxarray4_, mclVv(n, "n"))),
              NULL)),
          mclMinus(mclVa(m, "m"), mclMtimes(_mxarray4_, mclVv(n, "n")))),
        NULL));
    /*
     * 
     * h = [r g b];
     */
    mlfAssign(
      &h, mlfHorzcat(mclVv(r, "r"), mclVv(g, "g"), mclVv(b, "b"), NULL));
    mclValidateOutput(h, 1, nargout_, "h", "hot");
    mxDestroyArray(n);
    mxDestroyArray(r);
    mxDestroyArray(g);
    mxDestroyArray(b);
    mxDestroyArray(m);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
    return h;
}

⌨️ 快捷键说明

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