The XYAddData function adds data to an existing dataset.
Return Value
bool is TRUE (1), if the function was successful and otherwise FALSE (0).
Parameters
hData is the handle of a 1D or 2D dataset.
rvX is a vector with x-coordinates.
rvY is a vector with y-coordinates.
This parameter specifies if the function will access the original data or the filtered data.
| Value | Description |
|---|---|
| -1 | If filtered data is available it will access filtered data, otherwise it will access original data. Default value is -1. |
| 0 | Access original data. |
| 1 | Access filtered data. |
rvMissingValue is a real vector with one or two elements. The values specify the missing value in rvX and rvY. All missing values in rvX and rvY will be removed. If rvMissingValue contains only one value, it will be used to remove missing valued for the x- and y-coordiantes. Default value is 1e10.
Comment
With the help of the XYAddData huge datasets can be handled. The dataset is created by the function TYCreate or XYCreate. Then blocks of data can be added to the dataset. The advantage is that not all data has to be in memory at the same time as a huge block.
The first call XYAddData(hData, rvY) adds data to a 1D dataset A 1D dataset should be created with the TYCreate function. A 2D dataset should be created with the XYCreate function.
All data points equal to rvMissingValue will not be added.
Example
The following example creates a binary file with a 100000 points (WriteTestFile). The function Test reads the data block wise and adds data to the dataset. To execute the example copy it into an UniPlot program editor (File=>New) and execute it with the command UniScript=>Save/Execute.
def WriteTestFile(ssFileName, nPoints)
{
ShowWaitCursor(TRUE);
fp = fopen(ssFileName, "wb");
x = linspace(0, 100 * PI, nPoints);
y = sin(x) + rand(1, nPoints) * 0.2;
fwrite(fp, "float", y)
fclose(fp);
}
def Test(ssFileName)
{
hDoc = DocCreate();
hPage = PageCreate();
hLayer = LayerCreate();
DocAddPage(hDoc, hPage);
PageAddLayer(hPage, hLayer);
nBlockSize = 10000;
i = nBlockSize;
fp = fopen(ssFileName, "rb");
y = fread(fp, "float", nBlockSize)
hData = TYCreate("test", y, hDoc);
LayerAddDataset(hLayer, hData);
while (1) {
y = fread(fp, "float", nBlockSize);
XYAddData(hData, y);
if (len(y) < nBlockSize) break;
AppSetStatusBarText(sprintf("Points: %d", i = i + nBlockSize));
}
fclose(fp);
LayerAutoScale(hLayer);
PageReplot(hPage)
}
WriteTestFile("c:/testfile.dat", 100000);
Test("c:/testfile.dat");
See also
id-259442