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

📄 sphere.c

📁 该程序为MATLAB对CDMA系统个部分的仿真
💻 C
字号:
/*
 * MATLAB Compiler: 2.2
 * Date: Tue Jun 25 10:53:59 2002
 * 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" "exm110633_1" 
 */
#include "sphere.h"
#include "libmatlbm.h"
#include "surf.h"

static mxChar _array1_[130] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ',
                                'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i',
                                'l', 'e', ':', ' ', 's', 'p', 'h', 'e', 'r',
                                'e', ' ', 'L', 'i', 'n', 'e', ':', ' ', '1',
                                ' ', 'C', 'o', 'l', 'u', 'm', 'n', ':', ' ',
                                '1', ' ', 'T', 'h', 'e', ' ', 'f', 'u', 'n',
                                'c', 't', 'i', 'o', 'n', ' ', '"', 's', 'p',
                                'h', 'e', 'r', 'e', '"', ' ', 'w', 'a', 's',
                                ' ', 'c', 'a', 'l', 'l', 'e', 'd', ' ', 'w',
                                'i', 't', 'h', ' ', 'm', 'o', 'r', 'e', ' ',
                                't', 'h', 'a', 'n', ' ', 't', 'h', 'e', ' ',
                                'd', 'e', 'c', 'l', 'a', 'r', 'e', 'd', ' ',
                                'n', 'u', 'm', 'b', 'e', 'r', ' ', 'o', 'f',
                                ' ', 'o', 'u', 't', 'p', 'u', 't', 's', ' ',
                                '(', '3', ')', '.' };
static mxArray * _mxarray0_;

static mxChar _array3_[129] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ',
                                'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i',
                                'l', 'e', ':', ' ', 's', 'p', 'h', 'e', 'r',
                                'e', ' ', 'L', 'i', 'n', 'e', ':', ' ', '1',
                                ' ', 'C', 'o', 'l', 'u', 'm', 'n', ':', ' ',
                                '1', ' ', 'T', 'h', 'e', ' ', 'f', 'u', 'n',
                                'c', 't', 'i', 'o', 'n', ' ', '"', 's', 'p',
                                'h', 'e', 'r', 'e', '"', ' ', 'w', 'a', 's',
                                ' ', 'c', 'a', 'l', 'l', 'e', 'd', ' ', 'w',
                                'i', 't', 'h', ' ', 'm', 'o', 'r', 'e', ' ',
                                't', 'h', 'a', 'n', ' ', 't', 'h', 'e', ' ',
                                'd', 'e', 'c', 'l', 'a', 'r', 'e', 'd', ' ',
                                'n', 'u', 'm', 'b', 'e', 'r', ' ', 'o', 'f',
                                ' ', 'i', 'n', 'p', 'u', 't', 's', ' ', '(',
                                '1', ')', '.' };
static mxArray * _mxarray2_;
static mxArray * _mxarray4_;
static mxArray * _mxarray5_;
static mxArray * _mxarray6_;
static mxArray * _mxarray7_;
static mxArray * _mxarray8_;

void InitializeModule_sphere(void) {
    _mxarray0_ = mclInitializeString(130, _array1_);
    _mxarray2_ = mclInitializeString(129, _array3_);
    _mxarray4_ = mclInitializeDouble(20.0);
    _mxarray5_ = mclInitializeDouble(2.0);
    _mxarray6_ = mclInitializeDouble(3.141592653589793);
    _mxarray7_ = mclInitializeDouble(0.0);
    _mxarray8_ = mclInitializeDouble(1.0);
}

void TerminateModule_sphere(void) {
    mxDestroyArray(_mxarray8_);
    mxDestroyArray(_mxarray7_);
    mxDestroyArray(_mxarray6_);
    mxDestroyArray(_mxarray5_);
    mxDestroyArray(_mxarray4_);
    mxDestroyArray(_mxarray2_);
    mxDestroyArray(_mxarray0_);
}

static mxArray * Msphere(mxArray * * yy,
                         mxArray * * zz,
                         int nargout_,
                         mxArray * n);

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

/*
 * The function "mlfNSphere" contains the nargout interface for the "sphere"
 * M-function from file "d:\MATLAB6p1\toolbox\matlab\specgraph\sphere.m" (lines
 * 1-35). This interface is only produced if the M-function uses the special
 * variable "nargout". The nargout interface allows the number of requested
 * outputs to be specified via the nargout argument, as opposed to the normal
 * interface which dynamically calculates the number of outputs based on the
 * number of non-NULL inputs it receives. This function processes any input
 * arguments and passes them to the implementation version of the function,
 * appearing above.
 */
mxArray * mlfNSphere(int nargout, mxArray * * yy, mxArray * * zz, mxArray * n) {
    mxArray * xx = mclGetUninitializedArray();
    mxArray * yy__ = mclGetUninitializedArray();
    mxArray * zz__ = mclGetUninitializedArray();
    mlfEnterNewContext(2, 1, yy, zz, n);
    xx = Msphere(&yy__, &zz__, nargout, n);
    mlfRestorePreviousContext(2, 1, yy, zz, n);
    if (yy != NULL) {
        mclCopyOutputArg(yy, yy__);
    } else {
        mxDestroyArray(yy__);
    }
    if (zz != NULL) {
        mclCopyOutputArg(zz, zz__);
    } else {
        mxDestroyArray(zz__);
    }
    return mlfReturnValue(xx);
}

/*
 * The function "mlfSphere" contains the normal interface for the "sphere"
 * M-function from file "d:\MATLAB6p1\toolbox\matlab\specgraph\sphere.m" (lines
 * 1-35). This function processes any input arguments and passes them to the
 * implementation version of the function, appearing above.
 */
mxArray * mlfSphere(mxArray * * yy, mxArray * * zz, mxArray * n) {
    int nargout = 1;
    mxArray * xx = mclGetUninitializedArray();
    mxArray * yy__ = mclGetUninitializedArray();
    mxArray * zz__ = mclGetUninitializedArray();
    mlfEnterNewContext(2, 1, yy, zz, n);
    if (yy != NULL) {
        ++nargout;
    }
    if (zz != NULL) {
        ++nargout;
    }
    xx = Msphere(&yy__, &zz__, nargout, n);
    mlfRestorePreviousContext(2, 1, yy, zz, n);
    if (yy != NULL) {
        mclCopyOutputArg(yy, yy__);
    } else {
        mxDestroyArray(yy__);
    }
    if (zz != NULL) {
        mclCopyOutputArg(zz, zz__);
    } else {
        mxDestroyArray(zz__);
    }
    return mlfReturnValue(xx);
}

/*
 * The function "mlfVSphere" contains the void interface for the "sphere"
 * M-function from file "d:\MATLAB6p1\toolbox\matlab\specgraph\sphere.m" (lines
 * 1-35). The void interface is only produced if the M-function uses the
 * special variable "nargout", and has at least one output. The void interface
 * function specifies zero output arguments to the implementation version of
 * the function, and in the event that the implementation version still returns
 * an output (which, in MATLAB, would be assigned to the "ans" variable), it
 * deallocates the output. This function processes any input arguments and
 * passes them to the implementation version of the function, appearing above.
 */
void mlfVSphere(mxArray * n) {
    mxArray * xx = NULL;
    mxArray * yy = NULL;
    mxArray * zz = NULL;
    mlfEnterNewContext(0, 1, n);
    xx = Msphere(&yy, &zz, 0, n);
    mlfRestorePreviousContext(0, 1, n);
    mxDestroyArray(xx);
    mxDestroyArray(yy);
    mxDestroyArray(zz);
}

/*
 * The function "mlxSphere" contains the feval interface for the "sphere"
 * M-function from file "d:\MATLAB6p1\toolbox\matlab\specgraph\sphere.m" (lines
 * 1-35). The feval function calls the implementation version of sphere through
 * this function. This function processes any input arguments and passes them
 * to the implementation version of the function, appearing above.
 */
void mlxSphere(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
    mxArray * mprhs[1];
    mxArray * mplhs[3];
    int i;
    if (nlhs > 3) {
        mlfError(_mxarray0_);
    }
    if (nrhs > 1) {
        mlfError(_mxarray2_);
    }
    for (i = 0; i < 3; ++i) {
        mplhs[i] = mclGetUninitializedArray();
    }
    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] = Msphere(&mplhs[1], &mplhs[2], nlhs, mprhs[0]);
    mlfRestorePreviousContext(0, 1, mprhs[0]);
    plhs[0] = mplhs[0];
    for (i = 1; i < 3 && i < nlhs; ++i) {
        plhs[i] = mplhs[i];
    }
    for (; i < 3; ++i) {
        mxDestroyArray(mplhs[i]);
    }
}

/*
 * The function "Msphere" is the implementation version of the "sphere"
 * M-function from file "d:\MATLAB6p1\toolbox\matlab\specgraph\sphere.m" (lines
 * 1-35). 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 [xx,yy,zz] = sphere(n)
 */
static mxArray * Msphere(mxArray * * yy,
                         mxArray * * zz,
                         int nargout_,
                         mxArray * n) {
    mexLocalFunctionTable save_local_function_table_
      = mclSetCurrentLocalFunctionTable(&_local_function_table_sphere);
    int nargin_ = mclNargin(1, n, NULL);
    mxArray * xx = mclGetUninitializedArray();
    mxArray * ans = mclGetUninitializedArray();
    mxArray * z = mclGetUninitializedArray();
    mxArray * y = mclGetUninitializedArray();
    mxArray * x = mclGetUninitializedArray();
    mxArray * sintheta = mclGetUninitializedArray();
    mxArray * cosphi = mclGetUninitializedArray();
    mxArray * phi = mclGetUninitializedArray();
    mxArray * theta = mclGetUninitializedArray();
    mclCopyArray(&n);
    /*
     * %SPHERE Generate sphere.
     * %   [X,Y,Z] = SPHERE(N) generates three (N+1)-by-(N+1)
     * %   matrices so that SURF(X,Y,Z) produces a unit sphere.
     * %
     * %   [X,Y,Z] = SPHERE uses N = 20.
     * %
     * %   SPHERE(N) and just SPHERE graph the sphere as a SURFACE
     * %   and do not return anything.
     * %
     * %   See also ELLIPSOID, CYLINDER.
     * 
     * %   Clay M. Thompson 4-24-91, CBM 8-21-92.
     * %   Copyright 1984-2001 The MathWorks, Inc. 
     * %   $Revision: 5.7 $  $Date: 2001/04/15 12:03:55 $
     * 
     * if nargin == 0, n = 20; end
     */
    if (nargin_ == 0) {
        mlfAssign(&n, _mxarray4_);
    }
    /*
     * 
     * % -pi <= theta <= pi is a row vector.
     * % -pi/2 <= phi <= pi/2 is a column vector.
     * theta = (-n:2:n)/n*pi;
     */
    mlfAssign(
      &theta,
      mclMtimes(
        mclMrdivide(
          mlfColon(mclUminus(mclVa(n, "n")), _mxarray5_, mclVa(n, "n")),
          mclVa(n, "n")),
        _mxarray6_));
    /*
     * phi = (-n:2:n)'/n*pi/2;
     */
    mlfAssign(
      &phi,
      mclMrdivide(
        mclMtimes(
          mclMrdivide(
            mlfCtranspose(
              mlfColon(mclUminus(mclVa(n, "n")), _mxarray5_, mclVa(n, "n"))),
            mclVa(n, "n")),
          _mxarray6_),
        _mxarray5_));
    /*
     * cosphi = cos(phi); cosphi(1) = 0; cosphi(n+1) = 0;
     */
    mlfAssign(&cosphi, mlfCos(mclVv(phi, "phi")));
    mclIntArrayAssign1(&cosphi, _mxarray7_, 1);
    mclArrayAssign1(&cosphi, _mxarray7_, mclPlus(mclVa(n, "n"), _mxarray8_));
    /*
     * sintheta = sin(theta); sintheta(1) = 0; sintheta(n+1) = 0;
     */
    mlfAssign(&sintheta, mlfSin(mclVv(theta, "theta")));
    mclIntArrayAssign1(&sintheta, _mxarray7_, 1);
    mclArrayAssign1(&sintheta, _mxarray7_, mclPlus(mclVa(n, "n"), _mxarray8_));
    /*
     * 
     * x = cosphi*cos(theta);
     */
    mlfAssign(
      &x,
      mclMtimes(mclVv(cosphi, "cosphi"), mclVe(mlfCos(mclVv(theta, "theta")))));
    /*
     * y = cosphi*sintheta;
     */
    mlfAssign(
      &y, mclMtimes(mclVv(cosphi, "cosphi"), mclVv(sintheta, "sintheta")));
    /*
     * z = sin(phi)*ones(1,n+1);
     */
    mlfAssign(
      &z,
      mclMtimes(
        mclVe(mlfSin(mclVv(phi, "phi"))),
        mclVe(mlfOnes(_mxarray8_, mclPlus(mclVa(n, "n"), _mxarray8_), NULL))));
    /*
     * 
     * if nargout == 0
     */
    if (nargout_ == 0) {
        /*
         * surf(x,y,z)
         */
        mclPrintAns(
          &ans, mlfNSurf(0, mclVv(x, "x"), mclVv(y, "y"), mclVv(z, "z"), NULL));
    /*
     * else
     */
    } else {
        /*
         * xx = x; yy = y; zz = z;
         */
        mlfAssign(&xx, mclVsv(x, "x"));
        mlfAssign(yy, mclVsv(y, "y"));
        mlfAssign(zz, mclVsv(z, "z"));
    /*
     * end
     */
    }
    mclValidateOutput(xx, 1, nargout_, "xx", "sphere");
    mclValidateOutput(*yy, 2, nargout_, "yy", "sphere");
    mclValidateOutput(*zz, 3, nargout_, "zz", "sphere");
    mxDestroyArray(theta);
    mxDestroyArray(phi);
    mxDestroyArray(cosphi);
    mxDestroyArray(sintheta);
    mxDestroyArray(x);
    mxDestroyArray(y);
    mxDestroyArray(z);
    mxDestroyArray(ans);
    mxDestroyArray(n);
    mclSetCurrentLocalFunctionTable(save_local_function_table_);
    return xx;
}

⌨️ 快捷键说明

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