| 2.1.17.2.10 ocmath_ave_multiple_curves_by_length_parameter
 DescriptionAverage multiple curves with interpolation by length parameter.
 Syntaxint ocmath_ave_multiple_curves_by_length_parameter( UINT nSize, const OneCurveData * pCurves, int * pnAveSize, double * pAveX, double * pAveY, double * pAveErr = NULL, int nErrType = AVMC_SE, int * pAveCount = NULL, int nMethod = INTERP_TYPE_LINEAR, double* pAveMin = NULL, double* pAveMax = NULL, int iOption = OPTION_EXTRAPOLATE ) Parameters nSize[input] number of curves. pCurves[input] pointer to structures that must be filled with pointers to input data. pnAveSize[modify] on input, allocated memory size of pAveX, pAveY and pAveErr buffer, should be large enough, for example, equal to curves' total size;on output, size of pAveX, pAveY and pAveErr buffer, which are determined internally. pAveX[output] pointer to buffer to receive X values for the averaged curve. pAveY[output] pointer to buffer to receive Y values for the averaged curve. pAveErr[output] if not NULL, pointer to buffer to receive the error bar data for theaveraged curve. Its default value is NULL. nErrType[input] returns standard error of mean (SEM) or standard deviation in pAveErrarray. Its default value is AVMC_SE. pAveCount[output] if not NULL, pointer to buffer to receive count of averaged values foreach point of the averaged curve. Its default value is NULL. nMethod[Input] if bInterp is true, which interpolation method would be used. pAveMin[output] if not NULL, pointer to buffer to receive min data for theaveraged curve. Its default value is NULL. pAveMax[output] if not NULL, pointer to buffer to receive max data for theaveraged curve. Its default value is NULL. iOption[input] specify how to extrapolate Y values in extrapolated range. Must be one of the three values:OPTION_EXTRAPOLATE(extrapolate Y using the last two points),OPTION_SET_MISSING(set all Y values in the extrapolated range to be missing values),OPTION_REPEAT_LAST(use the Y value of the closest input X value for all values in the extrapolated range)
 ReturnReturn OE_NOERROR if succeed, otherwise, non-zero error code is returned.
 ExamplesEX1
 //This example assume the active window is a graph.
void ocmath_ave_multicurves_by_length_parameter_ex1()
{
    GraphLayer gl = Project.ActiveLayer();
    if (!gl)
    {
        return;
    }
    
    int nPlots = gl.DataPlots.Count();
    OneCurveData* multiCurveData = (OneCurveData*) malloc(sizeof(OneCurveData)*nPlots);
    
    double* xx;
    double* yy;
    
    int nAveSize = 0;
    for(int ii = 0; ii < nPlots; ii++)
    {
        DataPlot dp = gl.DataPlots(ii);        
        DataRange dr;
        vector vDatax, vDatay;
        if(dp.GetDataRange(dr))
        {
            DWORD dwPlotID;
            if(dr.GetData(DRR_GET_DEPENDENT | DRR_NO_FACTORS, 0, &dwPlotID, NULL, &vDatay, &vDatax) < 0)
            {
                printf("get_plot_data failed GetData");
                return;
            }
        }
        int nSize = vDatay.GetSize();
    
        xx = (double*) malloc (sizeof(double) * nSize);
        yy = (double*) malloc (sizeof(double) * nSize);
    
        memcpy(xx, vDatax, sizeof(double)*nSize);
        memcpy(yy, vDatay, sizeof(double)*nSize);
        
        multiCurveData[ii].nSize = nSize;
        multiCurveData[ii].pX = xx;
        multiCurveData[ii].pY = yy;
        nAveSize += nSize;
    }
    
    vector vxAve(nAveSize);
    vector vyAve(nAveSize);
    vector vErr(nAveSize);
    vector<int> vCount(nAveSize);
    
    int nRet = ocmath_ave_multiple_curves_by_length_parameter
                    (nPlots, multiCurveData, &nAveSize, vxAve, vyAve, vErr, AVMC_SE, vCount);
                        
    if( nRet!=OE_NOERROR )
    {
        printf("error code: %d\n", nRet);
        return;
    }
    
    vxAve.SetSize(nAveSize);
    vyAve.SetSize(nAveSize);
    vErr.SetSize(nAveSize);
    vCount.SetSize(nAveSize);
    
    for (ii = 0; ii < nPlots; ii++)
    {
        free(multiCurveData[ii].pX);
        free(multiCurveData[ii].pY);
    }
    free(multiCurveData);
    
    WorksheetPage wksPage;
    wksPage.Create();
    Worksheet wksAve = wksPage.Layers(0);
    wksAve.SetSize(-1, 2);
    wksAve.Columns(0).SetType(OKDATAOBJ_DESIGNATION_X);
    wksAve.Columns(1).SetType(OKDATAOBJ_DESIGNATION_Y);        
    DataRange drOut;
    drOut.Add("X", wksAve, 0, 0, -1, 0);
    drOut.Add("Y", wksAve, 0, 1, -1, 1);
    drOut.SetData(&vyAve, &vxAve);
    gl.AddPlot(drOut, IDM_PLOT_SCATTER);
    
}RemarkThis function averages multiple curves with interpolation by length parameter.
 if number of curve = 1, if memory enough pAveX will be curve's X value and pAveY will be curve's Y value, else return non-zero error code.
 If number of curve > 1, it assumes that all curves's X value are not monotonic but consistent, so before average please check curves order by ocmath_check_order_multiple_curves.
 See Alsoocmath_ave_multiple_curves
 Header to Includeorigin.h
 Reference |