T O P I C R E V I E W |
slurpy |
Posted - 03/01/2009 : 10:45:47 AM Origin Ver. and Service Release (Select Help-->About Origin): 7.5 --> 8 Operating System: XP SP2
Hi all,
I have a project with the following code that I think is having issues because of the change in Syntax for Accessing NAG Library Functions (from Origin 7.5 to 8)
Since then, I had added/changed the appropriate include files: #include "System\NAG8\nag.h" #include "System\NAG8\nagg02.h"
I have also made changes in the code where the NAG library comes into play. However there is still problems with the function (colour red) where the compiler says there is "Incompatible variable types in expression".
Will appreciate some help very much! Thanks in advance!
void CreateLinearRegression(Worksheet *pWks, Worksheet *pOutWksLr)
{
Nag_SumSquare mean = Nag_AboutMean; //Nag_AboutZero
if (pWks->IsValid())
{
Column col;
string name;
int numCols = pWks->GetNumCols(), relTimeCol = numCols - 2, lastXCol = numCols - 3;
int iR1, iR2, i, success;
double count, a, b, err_a, err_b, rsq, rss, df, *x, *y;
pWks->GetBounds(iR1, 0, iR2, lastXCol, FALSE);
if (!pOutWksLr->IsValid())
pOutWksLr->Create(NULL, CREATE_HIDDEN);
pOutWksLr->GetPage().Label = pWks->GetPage().Label + "LR";
pOutWksLr->SetSize(lastXCol + 1, 6, TRUE);
pOutWksLr->Columns(0).SetName("Well");
pOutWksLr->Columns(1).SetName("A");
pOutWksLr->Columns(2).SetName("B");
pOutWksLr->Columns(3).SetName("errA");
pOutWksLr->Columns(4).SetName("errB");
pOutWksLr->Columns(5).SetName("rsq");
pOutWksLr->Columns(6).SetName("df");
pOutWksLr->Columns(3).SetType(OKDATAOBJ_DESIGNATION_ERROR);
pOutWksLr->Columns(4).SetType(OKDATAOBJ_DESIGNATION_ERROR);
count = iR2 - iR1 + 1;
x = (double *)malloc(sizeof(double) * count);
y = (double *)malloc(sizeof(double) * count);
col = pWks->Columns(relTimeCol);
if (col)
{
Dataset ds(col);
for (i = 0; i < count; i++)
x[i] = ds[i + iR1] / 60.0;
}
int nWksCol = 0;
foreach(col in pWks->Columns)
{
if (col && nWksCol <= lastXCol)
{
name = col.GetName();
pOutWksLr->SetCell(nWksCol, 0, name);
Dataset ds(col);
for (i = 0; i < count; i++)
y[i] = ds[i + iR1];
success = g02cac(mean, count, x, y, NULL, &a, &b, &err_a, &err_b, &rsq, &rss, &df, NAGERR_DEFAULT);
pOutWksLr->SetCell(nWksCol, 0, name);
pOutWksLr->SetCell(nWksCol, 1, a);
pOutWksLr->SetCell(nWksCol, 2, b);
pOutWksLr->SetCell(nWksCol, 3, err_a);
pOutWksLr->SetCell(nWksCol, 4, err_b);
pOutWksLr->SetCell(nWksCol, 5, rsq);
pOutWksLr->SetCell(nWksCol, 6, df);
nWksCol++;
}
}
pOutWksLr->UpdateOrigin();
free(x);
free(y);
}
} |
3 L A T E S T R E P L I E S (Newest First) |
cpyang |
Posted - 03/03/2009 : 9:52:22 PM would this link be useful?
http://ocwiki.originlab.com/index.php?title=OriginC:Regression_Analysis
CP
|
slurpy |
Posted - 03/03/2009 : 4:03:35 PM Thanks eparent! I have removed "success" and the code compiles :) However, there is now a run time error at the following line: g02cac(mean, count, x, y, NULL, &a, &b, &err_a, &err_b, &rsq, &rss, &df, NAGERR_DEFAULT);
The part of the code here is as follows:
void CreateLinearRegression(Worksheet *pWks, Worksheet *pOutWksLr)
{
Nag_SumSquare mean = Nag_AboutMean; //Nag_AboutZero
if (pWks->IsValid())
{
Column col;
string name;
int numCols = pWks->GetNumCols(), relTimeCol = numCols - 2, lastXCol = numCols - 3;
int iR1, iR2, i;
double count, a, b, err_a, err_b, rsq, rss, df, *x, *y;
pWks->GetBounds(iR1, 0, iR2, lastXCol, FALSE);
if (!pOutWksLr->IsValid())
pOutWksLr->Create(NULL, CREATE_HIDDEN);
pOutWksLr->GetPage().Label = pWks->GetPage().Label + "LR";
pOutWksLr->SetSize(lastXCol + 1, 6, TRUE);
pOutWksLr->Columns(0).SetName("Well");
pOutWksLr->Columns(1).SetName("A");
pOutWksLr->Columns(2).SetName("B");
pOutWksLr->Columns(3).SetName("errA");
pOutWksLr->Columns(4).SetName("errB");
pOutWksLr->Columns(5).SetName("rsq");
pOutWksLr->Columns(6).SetName("df");
pOutWksLr->Columns(3).SetType(OKDATAOBJ_DESIGNATION_ERROR);
pOutWksLr->Columns(4).SetType(OKDATAOBJ_DESIGNATION_ERROR);
count = iR2 - iR1 + 1;
x = (double *)malloc(sizeof(double) * count);
y = (double *)malloc(sizeof(double) * count);
col = pWks->Columns(relTimeCol);
if (col)
{
Dataset ds(col);
for (i = 0; i < count; i++)
x[i] = ds[i + iR1] / 60.0;
}
int nWksCol = 0;
foreach(col in pWks->Columns)
{
if (col && nWksCol <= lastXCol)
{
name = col.GetName();
pOutWksLr->SetCell(nWksCol, 0, name);
Dataset ds(col);
for (i = 0; i < count; i++)
y[i] = ds[i + iR1];
g02cac(mean, count, x, y, NULL, &a, &b, &err_a, &err_b, &rsq, &rss, &df, NULL);
pOutWksLr->SetCell(nWksCol, 0, name);
pOutWksLr->SetCell(nWksCol, 1, a);
pOutWksLr->SetCell(nWksCol, 2, b);
pOutWksLr->SetCell(nWksCol, 3, err_a);
pOutWksLr->SetCell(nWksCol, 4, err_b);
pOutWksLr->SetCell(nWksCol, 5, rsq);
pOutWksLr->SetCell(nWksCol, 6, df);
nWksCol++;
}
}
pOutWksLr->UpdateOrigin();
free(x);
free(y);
}
}
//
// Create the work sheet pOutWsp by calculating the area of the wells in pWsp
//
void CreateArea(Worksheet *pWsp, Worksheet *pOutWsp)
{
if (!pWsp->IsValid())
return;
if (!pOutWsp->IsValid())
pOutWsp->Create(NULL, CREATE_HIDDEN);
int nWspCol, nNumCols = pWsp->GetNumCols(), nTimeRelCol = nNumCols - 2, nXCols = nNumCols - 2;
Column timeRelCol = pWsp->Columns(nTimeRelCol);
Dataset TimeRelDs(*pWsp, nTimeRelCol);
pOutWsp->GetPage().Label = pWsp->GetPage().Label + "Area";
pOutWsp->SetSize(nXCols, 2);
pOutWsp->Columns(0).SetName("Well");
pOutWsp->Columns(1).SetName("Area");
Dataset areaDs(*pOutWsp, 1);
areaDs.SetUpperBound(nXCols - 1);
nWspCol = 0;
foreach (Column col in pWsp->Columns)
{
if (nWspCol < nXCols)
{
Dataset WspColDs(*pWsp, nWspCol);
Curve curve(TimeRelDs, WspColDs);
pOutWsp->SetCell(nWspCol, 0, col.GetName());
areaDs[nWspCol] = area(curve);
}
nWspCol++;
}
pOutWsp->UpdateOrigin();
}
Thanks for the help!! Really appreciate it!
|
eparent |
Posted - 03/03/2009 : 3:57:56 PM Hello,
The g02cac function no longer returns a value. Remove the "success = " and your code will compile. If you want to check for error then use the last argument which you are currently passing NAGERR_DEFAULT to.
Thanks.
|
|
|