The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 linear regression stalls origin
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cosy

Germany
Posts

Posted - 07/28/2004 :  12:46:57 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,
I have a large dataset (a real time data acquisition). I have set up a originC program to continuosly calculate the linear regression parameters and display it. I saw that origin wasnt able to respond to any events when the program was running in the background. This happened though there was a sleep (for 5 seconds) included in the loop.
My code goes like this :
void TricLr()
{
Dataset ds1;
Dataset ds2;

Dataset dsA("TricData_Time");
Dataset dsB("TricData_Scaler1C0");
string str;


double dCoeff[4];
int ii;

double data;
waitCursor cur;

Curve crv("TricData_Time","TricData_Scaler1C0");

SetDataDisplayText("Computing Linear Regression parameters ...Hit Esc to Stop.");
int aa = dsA.GetUpperBound();
for (ii=0;ii < aa && !cur.CheckEsc();ii++)
{

fitpoly_range(crv, ii, ii+9, 2, &dCoeff); // Fit 1nd degree polynomial to entire curve
data = -(dsB[ii]/dCoeff[1])/3600000;
str.Format("Life Time %f hours", data);
SetDataDisplayText(str);
//printf("LifeTime : %f",data);
aa = dsA.GetUpperBound();
Sleep (5000);

}

if(cur.CheckEsc())
SetDataDisplayText("Computation interrupted!");
}

Does anyone have an idea of what could be wrong ?
Thanks,
Deepak Samuel.

cpyang

USA
1406 Posts

Posted - 07/30/2004 :  4:17:12 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
replace

Sleep (5000);

with

LT_execute("sec -p 5");


CP


Go to Top of Page

easwar

USA
1964 Posts

Posted - 07/30/2004 :  4:59:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Deepak,

Using "sec -p" from within OC will free up Origin for doing other tasks as long as those tasks do not involve compiling Origin C files.

If you want to free up Origin C to compile other files as well, another approach is to push the timer into script code, and call Origin C only for fitting one segment of the data at a time, such as below:

Easwar
OriginLab


//Script code starts here.....
limit(TricData_Time); // Get dataset size
iPts = limit.size;
ii = 0; // point to first row
def TimerProc // Define Procedure for Timer
{
ii++; // move to next row
if(ii > iPts - 9) // if past last segment, turn timer off and quit
{
timer -k;
return;
};
TricLr(ii); // Call OC function that fits one segment
};
timer 5; // Run Timer Procedure once every 5 secs
//
// script code ends here
//
//
//
//
// OC code below:
// please check for accuracy such as data begin/end settings
// note LabTalk counts from 1 and OC from 0
void TricLr(int iBegin)
{
string str;
double dCoeff[4];
int ii;
double data;
Dataset dsB("TricData_Scaler1C0");
Curve crv("TricData_Time","TricData_Scaler1C0");
fitpoly_range(crv, iBegin - 1, iBegin + 8, 2, &dCoeff); // Fit 1nd degree polynomial to entire curve
data = -(dsB[iBegin]/dCoeff[1])/3600000;
str.Format("Life Time %f hours", data);
SetDataDisplayText(str);
}
//
// OC code ends




Edited by - easwar on 07/30/2004 5:06:48 PM
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000