2.1.17.8.21.1 Data_copy


Description

Copy a range of data from one data set to another.

Syntax

BOOL Data_copy( Dataset * pdsDest, Dataset * pdsSrc, int nSrcFrom = 0, int nSrcTo = -1, int nDestFrom = -1, BOOL bIgnoreMask = TRUE )

Parameters

pdsDest
[output] pointer to destination dataset
pdsSrc
[input] pointer to source dataset
nSrcFrom
[input] starting index of the source dataset (0 based offset)
nSrcTo
[input] ending index of the source dataset (0 based offset, default -1 copies to upper index)
nDestFrom
[input] starting index of the destination dataset (0 based offset, default -1 uses nSrcFrom)
bIgnoreMask
[input] TRUE ignores masking in source dataset, FALSE copies masked values as missing values

Return

Returns TRUE if successful and FALSE if:

1) nSrcFrom < 0 or nSrcFrom > source UpperIndex

2) nSrcTo < nSrcFrom or nSrcTo > UpperIndex

3) nDestFrom < -1 (-1 means to use nSrcFrom)

Examples

EX1

// This is a self contained sample program for the function Data_copy, 
// Its sample data is created at the beginning of the program. 
// To run the program, enter the following command in the Script window:
//   Data_copy_ex1
// This will return the result like following:
//   Copying Data2_B[3:5] to Data2_Destination[6:8] succeeded.
// In this example, the copied range exceeds the original range of the 
// destination, but copying results the expansion.
//
void Data_copy_ex1()
{
    BOOL rc;
    
    Worksheet wks;
    wks.Create();
    Dataset myXDs(wks,0);
    Dataset dsSrc(wks,1);  // Dataset as a source
    String strSrcName = dsSrc.GetName();
    wks.AddCol("Destination");     // Add a column for the destination
    Dataset dsDest(wks,2);
    String strDestName = dsDest.GetName();
    
    //******* Create sample data *****************
    myXDs.SetSize(7);
    dsSrc.SetSize(7);
    dsDest.SetSize(7);
    myXDs[0]=1;    dsSrc[0]=0.097;     dsDest[0]=0;
    myXDs[1]=2;    dsSrc[1]=0.41256;    dsDest[1]=0;
    myXDs[2]=3;    dsSrc[2]=0.24909;    dsDest[2]=0;
    myXDs[3]=4;    dsSrc[3]=0.47304;    dsDest[3]=0;
    myXDs[4]=5;    dsSrc[4]=0.2476;    dsDest[4]=0;
    myXDs[5]=6;    dsSrc[5]=0.64529;    dsDest[5]=0;
    myXDs[6]=7;    dsSrc[6]=0.44514;    dsDest[6]=0;
    //******** End of Sample Data Creation *******

    int nSrcFrom = 2;
    int nSrcTo = 4;
    int nDestFrom = 5;
    
    rc=Data_copy(&dsDest, &dsSrc, nSrcFrom, nSrcTo, nDestFrom); // Demonstration of Data_copy
    if(rc)
        printf("Copying %s[%d:%d] to %s[%d:%d] succeeded.\n",
          strSrcName,nSrcFrom+1,nSrcTo+1,strDestName,nDestFrom+1,(nDestFrom+nSrcTo-nSrcFrom+1));
    else
        printf("Error: Data_copy failed\n");
}

Remark

Copy a range of data from one data set to another. If need the destination data set will be automatically resized.

See Also

Header to Include

origin.h

Reference