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

📄 sphere.cpp

📁 该程序为MATLAB对CDMA系统个部分的仿真
💻 CPP
字号:
//
// MATLAB Compiler: 2.2
// Date: Tue Jun 25 10:54:12 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" "sglcpp" "-p" "-W"
// "main" "-L" "Cpp" "-t" "-T" "link:exe" "-h" "libmmfile.mlib" "-W" "mainhg"
// "libmwsglm.mlib" "exm110633_1" 
//
#include "sphere.hpp"
#include "libmatlbm.hpp"
#include "surf.hpp"

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 mwArray _mxarray0_ = mclInitializeString(130, _array1_);

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 mwArray _mxarray2_ = mclInitializeString(129, _array3_);
static mwArray _mxarray4_ = mclInitializeDouble(20.0);
static mwArray _mxarray5_ = mclInitializeDouble(2.0);
static mwArray _mxarray6_ = mclInitializeDouble(3.141592653589793);
static mwArray _mxarray7_ = mclInitializeDouble(0.0);
static mwArray _mxarray8_ = mclInitializeDouble(1.0);

void InitializeModule_sphere() {
}

void TerminateModule_sphere() {
}

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

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

//
// The function "Nsphere" 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.
//
mwArray Nsphere(int nargout, mwArray * yy, mwArray * zz, mwArray n) {
    mwArray xx(mclGetUninitializedArray());
    mwArray yy__(mclGetUninitializedArray());
    mwArray zz__(mclGetUninitializedArray());
    xx = Msphere(&yy__, &zz__, nargout, n);
    if (yy != NULL) {
        *yy = yy__;
    }
    if (zz != NULL) {
        *zz = zz__;
    }
    return xx;
}

//
// The function "sphere" 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.
//
mwArray sphere(mwArray * yy, mwArray * zz, mwArray n) {
    int nargout(1);
    mwArray xx(mclGetUninitializedArray());
    mwArray yy__(mclGetUninitializedArray());
    mwArray zz__(mclGetUninitializedArray());
    if (yy != NULL) {
        ++nargout;
    }
    if (zz != NULL) {
        ++nargout;
    }
    xx = Msphere(&yy__, &zz__, nargout, n);
    if (yy != NULL) {
        *yy = yy__;
    }
    if (zz != NULL) {
        *zz = zz__;
    }
    return xx;
}

//
// The function "Vsphere" 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 Vsphere(mwArray n) {
    mwArray xx(mwArray::UNDEFINED);
    mwArray yy(mwArray::UNDEFINED);
    mwArray zz(mwArray::UNDEFINED);
    xx = Msphere(&yy, &zz, 0, n);
}

//
// 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[]) {
    MW_BEGIN_MLX();
    {
        mwArray mprhs[1];
        mwArray mplhs[3];
        int i;
        mclCppUninitializeArrays(3, mplhs);
        if (nlhs > 3) {
            error(_mxarray0_);
        }
        if (nrhs > 1) {
            error(_mxarray2_);
        }
        for (i = 0; i < 1 && i < nrhs; ++i) {
            mprhs[i] = mwArray(prhs[i], 0);
        }
        for (; i < 1; ++i) {
            mprhs[i].MakeDIN();
        }
        mplhs[0] = Msphere(&mplhs[1], &mplhs[2], nlhs, mprhs[0]);
        plhs[0] = mplhs[0].FreezeData();
        for (i = 1; i < 3 && i < nlhs; ++i) {
            plhs[i] = mplhs[i].FreezeData();
        }
    }
    MW_END_MLX();
}

//
// 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 mwArray Msphere(mwArray * yy, mwArray * zz, int nargout_, mwArray n) {
    mwLocalFunctionTable save_local_function_table_
      (&_local_function_table_sphere);
    int nargin_(nargin(1, mwVarargin(n)));
    mwArray xx(mclGetUninitializedArray());
    mwArray ans(mclGetUninitializedArray());
    mwArray z(mclGetUninitializedArray());
    mwArray y(mclGetUninitializedArray());
    mwArray x(mclGetUninitializedArray());
    mwArray sintheta(mclGetUninitializedArray());
    mwArray cosphi(mclGetUninitializedArray());
    mwArray phi(mclGetUninitializedArray());
    mwArray theta(mclGetUninitializedArray());
    //
    // %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) {
        n = _mxarray4_;
    }
    //
    // 
    // % -pi <= theta <= pi is a row vector.
    // % -pi/2 <= phi <= pi/2 is a column vector.
    // theta = (-n:2:n)/n*pi;
    //
    theta
      = colon(- mwVa(n, "n"), _mxarray5_, mwVa(n, "n")) / mwVa(n, "n")
        * _mxarray6_;
    //
    // phi = (-n:2:n)'/n*pi/2;
    //
    phi
      = ctranspose(colon(- mwVa(n, "n"), _mxarray5_, mwVa(n, "n")))
        / mwVa(n, "n")
        * _mxarray6_
        / _mxarray5_;
    //
    // cosphi = cos(phi); cosphi(1) = 0; cosphi(n+1) = 0;
    //
    cosphi = cos(mwVv(phi, "phi"));
    mclIntArrayAssign(&cosphi, _mxarray7_, 1);
    mclArrayAssign(&cosphi, _mxarray7_, mwVa(n, "n") + _mxarray8_);
    //
    // sintheta = sin(theta); sintheta(1) = 0; sintheta(n+1) = 0;
    //
    sintheta = sin(mwVv(theta, "theta"));
    mclIntArrayAssign(&sintheta, _mxarray7_, 1);
    mclArrayAssign(&sintheta, _mxarray7_, mwVa(n, "n") + _mxarray8_);
    //
    // 
    // x = cosphi*cos(theta);
    //
    x = mwVv(cosphi, "cosphi") * mwVe(cos(mwVv(theta, "theta")));
    //
    // y = cosphi*sintheta;
    //
    y = mwVv(cosphi, "cosphi") * mwVv(sintheta, "sintheta");
    //
    // z = sin(phi)*ones(1,n+1);
    //
    z
      = mwVe(sin(mwVv(phi, "phi")))
        * mwVe(ones(mwVarargin(_mxarray8_, mwVa(n, "n") + _mxarray8_)));
    //
    // 
    // if nargout == 0
    //
    if (nargout_ == 0) {
        //
        // surf(x,y,z)
        //
        ans.EqPrintAns(
          Nsurf(0, mwVarargin(mwVv(x, "x"), mwVv(y, "y"), mwVv(z, "z"))));
    //
    // else
    //
    } else {
        //
        // xx = x; yy = y; zz = z;
        //
        xx = mwVsv(x, "x");
        *yy = mwVsv(y, "y");
        *zz = mwVsv(z, "z");
    //
    // end
    //
    }
    mwValidateOutput(xx, 1, nargout_, "xx", "sphere");
    mwValidateOutput(*yy, 2, nargout_, "yy", "sphere");
    mwValidateOutput(*zz, 3, nargout_, "zz", "sphere");
    return xx;
}

⌨️ 快捷键说明

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