sort

 

Description

Sort a curve in ascending order of X.

Syntax

BOOL sort( Curve & crv )

Parameters

crv
[input] Origin C Curve object

Return

Returns TRUE on success and FALSE on failure.

Examples

EX1

// This is a self contained sample program for the function sort, 
// Its sample data with a back-up is created at the beginning of the program. 
// To run the program, enter the following command in the Script window:
//   sort_ex1
// This will return the sorted datasets (A and B), and give the following message:
//   Sorting Data8_A (as X) for Data8_B (as Y) succedded.
void sort_ex1()
{
    BOOL dSort;
    Worksheet wks;
    wks.Create();
    Dataset myXDs(wks,0);
    Dataset myYDs(wks,1);

    //******* Create sample data *****************
    wks.AddCol("OriginalX");     // Add an X column to backup the original
    Dataset orgX(wks,2);
    wks.Columns(2).SetType(OKDATAOBJ_DESIGNATION_X);
    wks.AddCol("OriginalY");     // Add a Y column to backup the original
    Dataset orgY(wks,3);
    myXDs.SetSize(8); myYDs.SetSize(8);
    orgX.SetSize(8); orgY.SetSize(8);
    myXDs[3]=1;    myYDs[3]=0.3;       orgX[3]=myXDs[3];    orgY[3]=myYDs[3];
    myXDs[2]=2;    myYDs[2]=0.097;      orgX[2]=myXDs[2];    orgY[2]=myYDs[2];
    myXDs[5]=3;    myYDs[5]=0.41256;     orgX[5]=myXDs[5];    orgY[5]=myYDs[5];
    myXDs[6]=4;    myYDs[6]=0.24909;     orgX[6]=myXDs[6];    orgY[6]=myYDs[6];
    myXDs[1]=5;    myYDs[1]=0.47304;     orgX[1]=myXDs[1];    orgY[1]=myYDs[1];
    myXDs[4]=6;    myYDs[4]=0.2476;     orgX[4]=myXDs[4];    orgY[4]=myYDs[4];
    myXDs[7]=7;    myYDs[7]=0.64529;     orgX[7]=myXDs[7];    orgY[7]=myYDs[7];
    myXDs[0]=8;    myYDs[0]=0.44514;     orgX[0]=myXDs[0];    orgY[0]=myYDs[0];
    //******** End of Sample Data Creation *******

    String strXName = myXDs.GetName();
    String strYName = myYDs.GetName();
    Curve myCrv(strXName,strYName);
    dSort = sort(myCrv);  // Demonstration of sort

    if(dSort)
        printf("Sorting %s (as X) with %s (as Y) succedded.\n",strXName,strYName);
    else 
        printf("Error: sort failed.\n");
}

Remark

The function used for fitting function parameter initialization.

See Also

header to Include

origin.h

Reference