Curve_integrate

 

Description

Integrate the given Curve.

Syntax

BOOL Curve_integrate( curvebase * pcrvData, IntegrationResult * pirResult, curvebase * pcrvBaseline = NULL, Dataset * pdsIntegral = NULL, BOOL bPaintShade = FALSE )

Parameters

pcrvData
[input] Pointer to Curve to integrate
pirResult
[output] Pointer to the IntegrationResult structure (see OC_types.h)
pcrvBaseline
[input] Pointer to baseline Curve
pdsIntegral
[output] Pointer to Dataset holding cumulative integration result
bPaintShade
[input] TRUE shades area of graph between integrated Curve and X axis (or baseline)

Return

Returns TRUE if integration is successful and FALSE otherwise. Also returns a pointer to an IntegrationResult structure (see OC_types.h) and a pointer to dataset holding the cumulative integration result.

Examples

EX1

// This is a self contained sample program for the function Curve_integrate, 
// Its sample data is created at the beginning of the program. 
// To run the program, enter the following command in the Script window:
//   Curve_integrate_ex1
// It returns like the following three lines:
//   Integration of Data2_B with Base:BaseLine
//     Area = 1.09865
//     Peak from Base = (6.000000, 0.345290)

void Curve_integrate_ex1()
{ 
    Worksheet wks;
    wks.Create();
    wks.AddCol("BaseLine");       // Add a column for base line
    wks.AddCol("Cumulation");             // Add a column for cumulation result
    Dataset dsInXDs(wks, 0);
    Dataset dsInYDs(wks, 1);
    Dataset dsBaseDs(wks, 2);            // Base line dataset
    Dataset dsOutCumDs(wks, 3);          // Cumulative integration result
 
    //******* Create sample data *****************
    dsInXDs.SetSize(7);
    dsInYDs.SetSize(7);
    dsBaseDs.SetSize(7);          // Baseline (=0.05*X)
    dsOutCumDs.SetSize(7);  
    dsInXDs[0]=1;    dsInYDs[0]=0.097;        dsBaseDs[0]=0.05;
    dsInXDs[1]=2;    dsInYDs[1]=0.41256;    dsBaseDs[1]=0.1;
    dsInXDs[2]=3;    dsInYDs[2]=0.24909;    dsBaseDs[2]=0.15;
    dsInXDs[3]=4;    dsInYDs[3]=0.47304;    dsBaseDs[3]=0.2;
    dsInXDs[4]=5;    dsInYDs[4]=0.2476;       dsBaseDs[4]=0.25;
    dsInXDs[5]=6;    dsInYDs[5]=0.64529;    dsBaseDs[5]=0.3;
    dsInXDs[6]=7;    dsInYDs[6]=0.44514;    dsBaseDs[6]=0.35;
    //******** End of Sample Data Creation *******
 
    Column colInY, colBase;
    string wksName = wks.GetPage().GetName();
    colInY.Attach(wks, 1);
    string strColNameInY = colInY.GetName();
    colBase.Attach(wks, 2);
    string strColNameBase = colBase.GetName();
 
    Curve crvInput(wks, 0, 1);      // Create Curve object of input data
    Curve crvBase(wks, 0, 2);       // Create Curve object of baseline data 
    
    IntegrationResult stResults;    // Origin C structure to store integration results     
    int nRet = Curve_integrate(&crvInput, &stResults, &crvBase, &dsOutCumDs, TRUE); // Perform integration    
 
    if(nRet)
        printf("Integration of %s_%s with Base:%s\n  Area = %g\n  Peak from Base = (%f, %f)\n",
          wksName, strColNameInY, strColNameBase, stResults.Area, stResults.xPeak, stResults.yPeak);
    else
        printf("Integration Failed. Error Code=%d\n", nRet);
}


bool fitpoly_range_ex1(Curve& crv)
{
        int nBegin = 5;
        int nEnd = 20;
        if( nBegin >= crv.GetSize() && nEnd >= crv.GetSize() )
                return error_report("nBegin and nEnd too large, please update ");
        
        int nPolyOrder = 2;
        vector vCoeff(nPolyOrder+1);
        
        bool bRet = fitpoly_range(crv, nBegin, nEnd, nPolyOrder, vCoeff);
        if( !bRet )
                return error_report("fitpoly_range return false");
        
        for(int ii=0; ii < vCoeff.GetSize(); ii++)
                printf("%g\n", vCoeff[ii]);
        return true;
}

Remark

Integrate the given Curve relative to the X axis unless a baseline is specified.

See Also

Header to Include

origin.h

Reference