spcfun1.c

来自「ASUFIT-Matlab-全局拟合程序」· C语言 代码 · 共 567 行 · 第 1/2 页

C
567
字号
                        mlfIndexRef(
                          irfTemp, "(?,?)", mlfIndexRef(top, "(?)", i), i),
                        mlfIndexRef(
                          irfTemp,
                          "(?,?)",
                          mlfPlus(mlfIndexRef(top, "(?)", i), mlfScalar(1.0)),
                          i),
                        mlfIndexRef(shift, "(?)", i))),
                    mlfIndexRef(
                      curve,
                      "(?,?)",
                      count,
                      mlfColon(
                        mlfScalar(1.0), mlfPlus(numTao, numTaoFixed), NULL)))),
                mlfMtimes(
                  mlfScalar(0.5),
                  mlfSpcfun1_irfshift(
                    mlfIndexRef(
                      irfTemp,
                      "(?,?)",
                      mlfPlus(mlfIndexRef(top, "(?)", i), mlfScalar(1.0)),
                      i),
                    mlfIndexRef(
                      irfTemp,
                      "(?,?)",
                      mlfPlus(mlfIndexRef(top, "(?)", i), mlfScalar(2.0)),
                      i),
                    mlfIndexRef(shift, "(?)", i)))));
            /*
             * curve(count,1:numTao+numTaoFixed)) + 0.5 * irfshift(irfTemp(top(i)+1,i),irfTemp(top(i)+2,i),shift(i)); 
             * curve(count+1,numTao+numTaoFixed+1)= irfshift(irfTemp(top(i),i),irfTemp(top(i)+1,i),shift(i));
             */
            mlfIndexAssign(
              &curve,
              "(?,?)",
              mlfPlus(count, mlfScalar(1.0)),
              mlfPlus(mlfPlus(numTao, numTaoFixed), mlfScalar(1.0)),
              mlfSpcfun1_irfshift(
                mlfIndexRef(irfTemp, "(?,?)", mlfIndexRef(top, "(?)", i), i),
                mlfIndexRef(
                  irfTemp,
                  "(?,?)",
                  mlfPlus(mlfIndexRef(top, "(?)", i), mlfScalar(1.0)),
                  i),
                mlfIndexRef(shift, "(?)", i)));
        /*
         * end
         */
        }
        /*
         * %space = curve;
         * a(:,i) = curve\dataTemp(:,i);
         */
        mlfIndexAssign(
          &a,
          "(?,?)",
          mlfCreateColonIndex(),
          i,
          mlfMldivide(
            curve, mlfIndexRef(dataTemp, "(?,?)", mlfCreateColonIndex(), i)));
        /*
         * z(:,i) = curve*a(:,i);
         */
        mlfIndexAssign(
          &z,
          "(?,?)",
          mlfCreateColonIndex(),
          i,
          mlfMtimes(curve, mlfIndexRef(a, "(?,?)", mlfCreateColonIndex(), i)));
    /*
     * end
     */
    }
    /*
     * f = (z - dataTemp)./weight(spcLeftEnd:spcRightEnd,:);
     */
    mlfAssign(
      &f,
      mlfRdivide(
        mlfMinus(z, dataTemp),
        mlfIndexRef(
          weight,
          "(?,?)",
          mlfColon(spcLeftEnd, spcRightEnd, NULL),
          mlfCreateColonIndex())));
    /*
     * amps = a;
     */
    mlfAssign(&amps, a);
    /*
     * fit=z;
     */
    mlfAssign(&fit, z);
    /*
     * chisq = trace(f'*f)/(numPoints*numCurves-(numTao + numTaoFixed)-(numTao + numTaoFixed)*numCurves-numCurves);
     */
    mlfAssign(
      &chisq,
      mlfMrdivide(
        mlfTrace(mlfMtimes(mlfCtranspose(f), f)),
        mlfMinus(
          mlfMinus(
            mlfMinus(
              mlfMtimes(numPoints, numCurves), mlfPlus(numTao, numTaoFixed)),
            mlfMtimes(mlfPlus(numTao, numTaoFixed), numCurves)),
          numCurves)));
    /*
     * set(textBox,'string',['chisq = ' num2str(chisq)])
     */
    mclPrintAns(
      &ans,
      mlfNSet(
        0,
        textBox,
        mxCreateString("string"),
        mlfHorzcat(mxCreateString("chisq = "), mlfNum2str(chisq, NULL), NULL),
        NULL));
    /*
     * drawnow;
     */
    mlfDrawnow(NULL);
    mclValidateOutputs("spcfun1", 1, nargout_, &f);
    mxDestroyArray(R);
    mxDestroyArray(a);
    mxDestroyArray(ans);
    mxDestroyArray(bottom);
    mxDestroyArray(count);
    mxDestroyArray(curve);
    mxDestroyArray(dataTemp);
    mxDestroyArray(i);
    mxDestroyArray(irfTemp);
    mxDestroyArray(numCurves);
    mxDestroyArray(numPoints);
    mxDestroyArray(shift);
    mxDestroyArray(tao);
    mxDestroyArray(taoFit);
    mxDestroyArray(top);
    mxDestroyArray(z);
    /*
     * 
     */
    return f;
}

/*
 * The function "mlfSpcfun1" contains the normal interface for the "spcfun1"
 * M-function from file "C:\MATLABR11\asufit24\spcfun1.m" (lines 1-71). This
 * function processes any input arguments and passes them to the implementation
 * version of the function, appearing above.
 */
mxArray * mlfSpcfun1(mxArray * params) {
    int nargout = 1;
    mxArray * f = mclGetUninitializedArray();
    mlfEnterNewContext(0, 1, params);
    f = Mspcfun1(nargout, params);
    mlfRestorePreviousContext(0, 1, params);
    return mlfReturnValue(f);
}

/*
 * The function "mlxSpcfun1" contains the feval interface for the "spcfun1"
 * M-function from file "C:\MATLABR11\asufit24\spcfun1.m" (lines 1-71). The
 * feval function calls the implementation version of spcfun1 through this
 * function. This function processes any input arguments and passes them to the
 * implementation version of the function, appearing above.
 */
void mlxSpcfun1(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: spcfun1 Line: 1 Column: "
            "0 The function \"spcfun1\" was called with mor"
            "e than the declared number of outputs (1)"));
    }
    if (nrhs > 1) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: spcfun1 Line: 1 Column:"
            " 0 The function \"spcfun1\" was called with m"
            "ore than the declared number of inputs (1)"));
    }
    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] = Mspcfun1(nlhs, mprhs[0]);
    mlfRestorePreviousContext(0, 1, mprhs[0]);
    plhs[0] = mplhs[0];
}

/*
 * The function "Mspcfun1_irfshift" is the implementation version of the
 * "spcfun1/irfshift" M-function from file "C:\MATLABR11\asufit24\spcfun1.m"
 * (lines 71-72). 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 G = irfshift(f1,f2,x0)
 */
static mxArray * Mspcfun1_irfshift(int nargout_,
                                   mxArray * f1,
                                   mxArray * f2,
                                   mxArray * x0) {
    mxArray * G = mclGetUninitializedArray();
    mclValidateInputs("spcfun1/irfshift", 3, &f1, &f2, &x0);
    /*
     * G = f1 + (x0 - floor(x0)) * (f2 - f1);
     */
    mlfAssign(
      &G, mlfPlus(f1, mlfMtimes(mlfMinus(x0, mlfFloor(x0)), mlfMinus(f2, f1))));
    mclValidateOutputs("spcfun1/irfshift", 1, nargout_, &G);
    return G;
}

/*
 * The function "mlfSpcfun1_irfshift" contains the normal interface for the
 * "spcfun1/irfshift" M-function from file "C:\MATLABR11\asufit24\spcfun1.m"
 * (lines 71-72). This function processes any input arguments and passes them
 * to the implementation version of the function, appearing above.
 */
static mxArray * mlfSpcfun1_irfshift(mxArray * f1, mxArray * f2, mxArray * x0) {
    int nargout = 1;
    mxArray * G = mclGetUninitializedArray();
    mlfEnterNewContext(0, 3, f1, f2, x0);
    G = Mspcfun1_irfshift(nargout, f1, f2, x0);
    mlfRestorePreviousContext(0, 3, f1, f2, x0);
    return mlfReturnValue(G);
}

/*
 * The function "mlxSpcfun1_irfshift" contains the feval interface for the
 * "spcfun1/irfshift" M-function from file "C:\MATLABR11\asufit24\spcfun1.m"
 * (lines 71-72). The feval function calls the implementation version of
 * spcfun1/irfshift through this function. This function processes any input
 * arguments and passes them to the implementation version of the function,
 * appearing above.
 */
static void mlxSpcfun1_irfshift(int nlhs,
                                mxArray * plhs[],
                                int nrhs,
                                mxArray * prhs[]) {
    mxArray * mprhs[3];
    mxArray * mplhs[1];
    int i;
    if (nlhs > 1) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: spcfun1/irfshift Line: 71 Colu"
            "mn: 0 The function \"spcfun1/irfshift\" was called w"
            "ith more than the declared number of outputs (1)"));
    }
    if (nrhs > 3) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: spcfun1/irfshift Line: 71 Colu"
            "mn: 0 The function \"spcfun1/irfshift\" was called w"
            "ith more than the declared number of inputs (3)"));
    }
    for (i = 0; i < 1; ++i) {
        mplhs[i] = NULL;
    }
    for (i = 0; i < 3 && i < nrhs; ++i) {
        mprhs[i] = prhs[i];
    }
    for (; i < 3; ++i) {
        mprhs[i] = NULL;
    }
    mlfEnterNewContext(0, 3, mprhs[0], mprhs[1], mprhs[2]);
    mplhs[0] = Mspcfun1_irfshift(nlhs, mprhs[0], mprhs[1], mprhs[2]);
    mlfRestorePreviousContext(0, 3, mprhs[0], mprhs[1], mprhs[2]);
    plhs[0] = mplhs[0];
}

⌨️ 快捷键说明

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