Author |
Topic  |
|
julienfr
France
Posts |
Posted - 01/16/2007 : 04:26:58 AM
|
Origin Version (Select Help-->About Origin): 7.5 Operating System: XP
Hi,
I am trying to write a program to perform an inegration between two values that I want to set as paremeters of my function. Basically my data are two columns data. I tried to use the Curve_integrate function but I did not find out how to set the boundaries of integration... so what I have done is to create two new columns and write only the data where I want to perform the integration so it looks like that:
void Iint(double beg,double end){ Worksheet wks=Project.ActiveLayer(); int TempXindex; int TempYindex; int Iintindex;
//add columns and index
TempXindex=wks.AddCol("TempX"); TempYindex=wks.AddCol("TempY"); Iintindex=wks.AddCol("I_int");
int min, Max,i, k; // beggining row, ending row of first column i.e. the lambda column wks.GetRange(min,Max,0,0);
for (i=min;i<=Max;i++) { string tp,tp2; float temp; wks.GetCell(i,0,tp); //lambda wks.GetCell(i,1,tp2); //Intensity temp=atof(tp);
// test whether the value of lambda is in the selected range if(temp<beg) {} else { if (temp>end) {} else { //if yes write the column TempX with lambda value and TempY with Intensity value wks.SetCell(k,TempXindex,tp); wks.SetCell(k,TempYindex,tp2); k=k+1; } } } }
It works well. Now I want to perform the integration with the TempX and TempY column and I can do it over the whole column (it was the purpose of the first function I wrote)
so I use this code and tried to use the dataset type:
Column colX=wks.Columns(TempXindex); Column colY=wks.Columns(TempYindex);
Dataset dsX=colX; Dataset dsY=colY;
Curve crvData(dsX, dsY);
IntegrationResult irResult; BOOL bRet = Curve_integrate(&crvData, &irResult);
if(bRet) { wks.SetCell(0, Iintindex, irResult.Area); // write the value of integration in the column Iint }
the problem is that this code is unable to get the column TempX and TempY and return 0 as area of integration. If at the beginning I write instead:
Column colX=wks.Columns(0); Column colY=wks.Columns(1);
the integration works fine but over the range of column 0 and 1....of course. My guess is that the program is unable to get the data from the columns I created (I performed some tests and it looks it is the problem). I do not understand why. Perhaps it comes from the fact that when I create the columns I write string-like data with the function Set.Cell
If someone could provide some helps I will be gratefull!
Julien
PS: I am aware that there is certainly a cleverer way to do what I want!
|
|
Mike Buess
USA
3037 Posts |
Posted - 01/16/2007 : 10:48:56 AM
|
Use crv.SetLowerBound and crv.SetUpperBound to set the integration range. This integrates between r1 and r2...
void integ_test(int r1, int r2) { Worksheet wks = Project.ActiveLayer(); Curve crv(wks,0,1); int i1 = crv.GetLowerBound(); // save lower bound int i2 = crv.GetUpperBound(); // save upper bound crv.SetLowerBound(r1); crv.SetUpperBound(r2); IntegrationResult irResults; bool berr = Curve_integrate(&crv,&irResults); crv.SetLowerBound(i1); // restore lower bound crv.SetUpperBound(i2); // restore upper bound double dArea = irResults.Area; out_double("area=",dArea); }
Mike Buess Origin WebRing Member |
 |
|
julienfr
France
Posts |
Posted - 01/17/2007 : 07:28:13 AM
|
Hi Mike,
thank you very much, it was exactly what I needed and it seems to work fine now. Is there an easy way to define the boundaries with respect to the Xcolumn (so it could be a double and not an integer) and not with respect to the number of the row?
Julien |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 01/17/2007 : 10:37:47 AM
|
Hi Julien,
There might be a simpler method but this should work...
void integ_test(double x1, double x2) { Worksheet wks = Project.ActiveLayer(); Curve crv(wks,0,1); int r1,r2; int i1 = crv.GetLowerBound(); int i2 = crv.GetUpperBound(); for(int i=i1; i<i2; i++) { if( Curve_x(&crv,i)>=x1 ) break; } r1 = i<i2 ? i : i1; for(i=r1+1; i<=i2; i++) { if( Curve_x(&crv,i)>=x2 ) break; } r2 = i>i2 ? i2 : i; crv.SetLowerBound(r1); crv.SetUpperBound(r2); IntegrationResult irResults; bool berr = Curve_integrate(&crv,&irResults); crv.SetLowerBound(i1); crv.SetUpperBound(i2); double dArea = irResults.Area; out_double("area=",dArea); }
Mike Buess Origin WebRing Member |
 |
|
julienfr
France
Posts |
Posted - 01/18/2007 : 03:12:23 AM
|
Hi Mike,
it is OK if the X column is sorted by ascending values. I will have to change it a bit in order to make it work for descending values.
thanks
Julien |
 |
|
julienfr
France
Posts |
Posted - 01/18/2007 : 1:41:47 PM
|
Hi,
about this problem for descending X column: I modified your code and I can get the index of the rows I have to use for boundaries with the following code:
void test(double x1,double x2)
{ Worksheet wks = Project.ActiveLayer();
Curve crv(wks,2,1);
int r1,r2;
int k = crv.GetLowerBound(); //save lower bound
int l = crv.GetUpperBound(); //save upper bound for(int i=k; i<l; i++) { if( Curve_x(&crv,i)<=x2 ) break; } r1 = i<l ? i : k; for(i=r1+1; i<=l; i++) { if( Curve_x(&crv,i)<=x1 ) break; }
r2 = i>l ? l : i; printf("%i",r1); printf("/%i",r2); crv.SetLowerBound(r1);
crv.SetUpperBound(r2);
IntegrationResult irResults;
bool berr = Curve_integrate(&crv,&irResults);
double dArea = irResults.Area; out_double("/area=",dArea); }
I checked and it seems to be OK, the problem is when I perform the integration, it returns strange results... Is it a problem to use the Curve_integrate function with a descending X column because I can't see why it is not working???
Julien |
 |
|
Mike Buess
USA
3037 Posts |
|
julienfr
France
Posts |
Posted - 01/18/2007 : 3:36:18 PM
|
It would have been nice... but it is stranger than that and I don't get what is actually happenning. My data looks like: col(A)=wavelength col(B)=Intensity col(C)=Energy
and I usually plot Intensity versus Wavelength or Intensity versus Energy and want to perform integration on this kind of plot. The problem is for the integration on col(B) versus col(C) where col(C) is descending; there is no problem for col(B) versus col(A). I noticed that when I choose the whole range of data (or something bigger)the value retuned is OK...
Julien |
 |
|
kanderlee
Taiwan
Posts |
Posted - 11/20/2007 : 01:20:01 AM
|
Hi, Mike,
What code can peform the "select a range of data" using data selector and storing the range by clicking the mouse? Thank you.
quote:
Hi Julien,
There might be a simpler method but this should work...
void integ_test(double x1, double x2) { Worksheet wks = Project.ActiveLayer(); Curve crv(wks,0,1); int r1,r2; int i1 = crv.GetLowerBound(); int i2 = crv.GetUpperBound(); for(int i=i1; i<i2; i++) { if( Curve_x(&crv,i)>=x1 ) break; } r1 = i<i2 ? i : i1; for(i=r1+1; i<=i2; i++) { if( Curve_x(&crv,i)>=x2 ) break; } r2 = i>i2 ? i2 : i; crv.SetLowerBound(r1); crv.SetUpperBound(r2); IntegrationResult irResults; bool berr = Curve_integrate(&crv,&irResults); crv.SetLowerBound(i1); crv.SetUpperBound(i2); double dArea = irResults.Area; out_double("area=",dArea); }
Mike Buess Origin WebRing Member
|
 |
|
|
Topic  |
|
|
|