📄 curve.h
字号:
/*------------------------------------------------------------------------------*
* File Name: Curve.h *
* Creation: TD 4-14-03 *
* Purpose: Origin C header file for Origin basic Data types *
* Copyright (c) OriginLab Corp. 2002 - 2007 *
* All Rights Reserved *
* Modifications: *
*------------------------------------------------------------------------------*/
#ifndef _CURVE_H
#define _CURVE_H
#define _CURVE_BASE
#include <vector.h>
// The following are related to sorting
#define NS_DESCENDING 0x2000
#define NS_MISSING_AS_SMALLEST 0x1000 // If this bit is on missing values are treated as the smallest value when sorting...otherwise they are treated as the as the largest value
/** >Composite Data Types
The Origin C curvebase class is an abstract base class used for polymorphic handling
of Curve related template class types. Consequently, Origin C objects of type curvebase
can not be constructed. Derived classes, such as Curve, inherit curvebase class methods
and should be used instead. The curvebase class is derived from vectorbase class from
which it inherits methods and properties.
Example:
// Assumes Data1_A and Data1_B exist and contain data
Dataset ds1("Data1_A"), ds2("Data1_B");
Curve crvCopy( ds1, ds2 );
crvCopy.Sort(); // Does not effect ds1, ds2
*/
class curvebase : public vectorbase
{
/**
Get the name of an internal Origin data set.
Example:
// Worksheet column Data1_A must exist prior to execution
string strName;
Dataset dsA("Data1_A");
dsA.GetName(strName);
out_str("Data set name is " + strName);
Parameters:
strName=Returned name of an internal Origin data set
Return:
Returns TRUE on successful exit and FALSE on failure. Also returns the name of an internal Origin data set.
*/
BOOL GetName(string& strName); // Get the name of an internal Origin data set.
/**
Get the name of an internal Origin data set.
Example:
// Worksheet column Data1_A must exist prior to execution
string strName;
Dataset dsA("Data1_A");
strName = dsA.GetName();
out_str("Data set name is " + strName);
Return:
Returns the name of an internal Origin data set.
*/
string GetName(); // Get the name of an internal Origin data set.
/**
Checks the validity of an Origin C Dataset object. Dataset objects
are valid when they are successfully attached to an internal Origin
data set.
Example:
// Worksheet column Data1_A must exist prior to execution
Dataset dsA; // Dataset is not yet attached and is not valid
if(dsA.IsValid())
out_str("Dataset is valid!");
else
out_str("Dataset is not valid!");
dsA.Attach("Data1_A"); // Dataset is now attached and is valid
if(dsA.IsValid())
out_str("Dataset is valid!");
else
out_str("Dataset is not valid!");
Return:
Returns TRUE if Dataset object is valid and FALSE if not.
SeeAlso:
Dataset::Attach, Dataset::Detach
*/
BOOL IsValid(); // Checks the validity of an Origin C Dataset object.
/**
Update an Origin C Dataset object from an Origin data set or update
an Origin data set from an Origin C Dataset object. The number of
elements and memory allocated are primarily affected by this method.
Example:
// Worksheet column Data1_A must exist prior to execution
void test_update_OC_when_Origin_changed()
{
Dataset dsA("Data1_A");
dsA.SetSize(10);
dsA=1;
LT_execute("set Data1_A -e 20;Data1_A=2;"); // Note Dataset size is not updated but Dataset values change in Local Variables windows of Debug mode
dsA.Update(TRUE); // Note Dataset dsA size is now updated in Local Variables windows of Debug mode
ASSERT(dsA.GetSize()==20);
}
// Assumes Data1 worksheet with column B
// This example shows how to update Origin from inside Origin C program before it returns
void test_update_Origin_when_OC_data_changed()
{
Dataset aa("Data1_b");
// in case column is empty
if(aa.GetSize()<1)
{
aa.SetSize(10);
aa=0;
}
aa[0]+= 1;
aa.Update(FALSE, REDRAW_REFRESH);
MessageBox(GetWindow(),"Data1_b increment 1, click OK to increment again");
aa[0]+=1;
}
// Demonstrate the usage of REDRAW_REALTIME_SCOPE and REDRAW_REALTIME_WKS
// Assumes:
// 1) Data1_A is filled with row numbers
// 2) Data1_A(X) vs. B(Y) is plotted as line plot
// 3) The line plot is set to animate mode so that the effect is fully visualized
// (set plot active and then execute LabTalk script command "set %C -an 1")
void test_realtime_update_Origin_fromOC(int imax = 20)
{
Dataset aa("Data1_b");
int nMaxRows = 10;
if(aa.GetSize()<nMaxRows)
{
aa.SetSize(nMaxRows);
aa=0;
}
int ic = 0;//current cell
for(int ii = 0; ii < imax; ii++)
{
for(int jj = 0; jj < nMaxRows; jj++)
aa[jj] = 1;
aa[ic++] = 2;
if(ic >= nMaxRows)
ic = 0;
//aa.Update(FALSE, REDRAW_REALTIME_WKS);
aa.Update(FALSE, REDRAW_REALTIME_SCOPE);
LT_execute("sec -w 0.1;");// hard wait
}
}
Parameters:
bFromOrigin=TRUE updates the Origin C Dataset object from the Origin data set, FALSE updates the Origin dataset
from an Origin C Dataset object.
mode=Dataset update mode, used only if bFromOrigin=FALSE. Supported values are
mode=Dataset update mode, allowed values are
REDRAW_NONE do update
REDRAW_REALTIME_WKS similar to REDRAW_REALTIME_SCOPE, but redraw the entire worksheet
REDRAW_REFRESH do a simple refresh of the data
REDRAW_REALTIME_SCOPE this is used to do realtime drawing for the entire range of data. To see effect in plots, must set dataplots to animate mode
SeeAlso:
Dataset::Append
*/
void Update(BOOL bFromOrigin, int mode = -1); // Update an Origin C Dataset object from an Origin data set or vice-versa.
#ifdef _POST_ORIGIN7_
/**#
*/
BOOL Append(vectorbase& v, int iMode);
#else
/**
Append data from a vector or Dataset object to this Origin C Dataset
object and update the Origin data set from this Origin C Dataset object.
Example:
// Assume Data1 worksheet and with A(X) vs. B(Y) plotted in graph window
// Can test by typing "rt_add 10" into Script window with the graph active
void rt_add(int npts)
{
static int nn = 1;
Worksheet wks("data1");
Dataset aa(wks,0);
Dataset bb(wks,1);
vector a(npts);
vector b(npts);
for(int ii = 0; ii < npts; ii++)
{
a[ii] = nn++;
b[ii] = rnd();
}
aa.Append(a, REDRAW_REALTIME);
bb.Append(b, REDRAW_REALTIME);
return;
}
Parameters:
v=vector or Dataset to append
iMode=Dataset update mode, allowed values are
REDRAW_NONE do update
REDRAW_REALTIME graph realtime drawing, only the new added data will be drawn
REDRAW_REALTIME_WKS similar to REDRAW_REALTIME_SCOPE, but redraw the entire worksheet
REDRAW_REFRESH do a simple refresh of the data
REDRAW_REALTIME_SCOPE this is used to do realtime drawing for the entire range of data. To see effect in plots, must set dataplots to animate mode
Return:
Returns TRUE on successful exit and FALSE on failure.
SeeAlso:
vectorbase::Append, Dataset::Update
*/
BOOL Append(vector& v, int iMode = REDRAW_NONE); // Append data from a vector or Dataset object to this Origin C Dataset object.
#endif //!_POST_ORIGIN7_
/**
TrimLeft removes elements having the value NANUM from the left end or
beginning of the Dataset by advancing the lower index to the first
valid numeric value. If bShiftLeft is TRUE cells containing NANUM
are deleted from the Dataset and a lower index value of 0 is returned
shifting numeric values left to the beginning of the Dataset. When bShiftLeft
is TRUE TrimLeft of Curve objects causes both X and Y Datasets to be trimmed.
Example:
// Worksheet columns Data1_A and data1_B must exist prior to execution
Dataset dsA("Data1",0);
dsA.TrimLeft(TRUE);
Curve crvAxBy("Data1_A","Data1_B");
crvAxBy.TrimLeft(TRUE);
LT_execute("doc -uw");
Parameters:
bShiftLeft=TRUE will delete cells on the left of (before) the first valid numeric value, FASLE will cause the lower bound
or index to be adjusted upward but no cells are deleted.
Returns:
Returns -1 on error, 0 on success, and N > 0 for number of cells deleted.
SeeAlso:
Dataset::TrimRight, vectorbase::GetLowerBound, vector::vector
*/
int TrimLeft(BOOL bShiftLeft = FALSE); // TrimLeft removes elements having the value NANUM from the left end of a Dataset.
/**
TrimRight removes elements having the value NANUM from the right end or
bottom of the Dataset by retarding the upper index to the last valid numeric
value. If bDelExtra is set to TRUE cells containing NANUM are deleted from
the Dataset. When bDelExtra is TRUE TrimRight of Curve objects causes both
X and Y Datasets to be trimmed.
Example:
// Worksheet columns Data1_A and data1_B must exist prior to execution
Dataset dsA("Data1",0);
dsA.TrimRight(TRUE);
Curve crvAxBy("Data1_A","Data1_B");
crvAxBy.TrimRight(TRUE);
LT_execute("doc -uw");
Parameters:
bDelExtra=TRUE will delete cells on the right of (after) the last valid numeric value, FASLE will cause the upper bound
or index to be adjusted downward but no cells are deleted.
Returns:
Returns -1 on error, 0 on success, and N > 0 for number of cells deleted.
SeeAlso:
Dataset::TrimLeft, vectorbase::GetUpperBound, vectorbase::GetSize, vector::vector
*/
int TrimRight(BOOL bDelExtra = FALSE); // TrimRight removes elements having the value NANUM from the right end of a Dataset.
/**
Use a Curve object to sort a Y data set according to an X data set. This function does nothing if is there
is no X data set associated with the Y data set.
Please note that constructor of curve that takes two Dataset is just making a copy of the Datasets, they are not attched to the curve.
So even you made some changes to the curve, it will not affect the original Dataset. Due to this reason, the curve sort will ONLY
work on the X Dataset, So if one want to make sort on Y Dataset, he may need to construct a curve with X and Y dataset swapped first.
Example:
// Assumes Data1_A and Data1_B exist and contain data
Curve crv("Data1_A","Data1_B");
crv.Sort(NS_DESCENDING | NS_MISSING_AS_SMALLEST);
Parameters:
dwFlags=Sort options. Default 0 sorts in ascending order and places missing values at the end. See
the NS_DESCENDING and NS_MISSING_AS_SMALLEST macro definitions in system header file data.h
Return:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -