hkkim
Republic of Korea
35 Posts |
Posted - 01/21/2013 : 02:34:14 AM
|
Hi greg! Thanks! I made a below test code. The variable R1End in integ1 X-function(<== in code) has a reduced value but the R1Area is calculated to an end time not to a reduced time. Why? If a constant is entered instead of R1End then the result of integ1 function is OK. I tried 'iy:=' of integ1 with a range variable but the result was same. Origin project file was attached for data.
Assumptions:
- There is one workbook(bk1) with 2 worksheets(sh1,sh2). - The 1st column has time with ascending order and the 2nd(Col(B)) has any data value such as a water level. - The ranges of R1 and R2 can be different. Let's R1Time is greater than R2Time here. - The time scales of R1 and R2 can be different, too.
Thanks again!!
hkkim
--------------------------------------------------------------------------------- // // Calculation of integrated area ratio of two graphs // 2013/01/18
// // Reduce row number after checking time steps // int R1Size, R2Size, R1End, R2End, i; double R1Time, R2Time, MinTime, ReducedTime; double R1Area, R2Area, GraphRatio; range R1=[bk1]sh1!Col(B); range R2=[bk1]sh2!Col(B); R1Size=R1.GetSize(); R2Size=R2.GetSize();
R1End=R1Size; R2End=R2Size;
type "R1Size = $(R1Size, .0)"; type "R2Size = $(R2Size, .0)";
R1Time=%([bk1]sh1,1,R1Size); R2Time=%([bk1]sh2,1,R2Size); type "R1Time = $(R1Time, .2)"; type "R2Time = $(R2Time, .2)";
MinTime=min(R1Time,R2Time); type "MinTime = $(MinTime, .2)";
if (R1Time != R2Time) // Exit if two end times are same. { if (R1Time > R2Time) // Reduce range R1 { loop (i,1,R1Size) { if(%([bk1]sh1,1,i) > MinTime) { R1End=i; ReducedTime=%([bk1]sh1,1,i); type "R1 Reduced!"; type "ReducedSize = $(R1End, .0)"; type "ReducedTime = $(ReducedTime, .2)"; break; }; }; }; else // Reduce range R2 { loop (i,1,R2Size) { if(%([bk1]sh2,1,i) > MinTime) { R2End=i; ReducedTime=%([bk1]sh2,1,i); type "R2 Reduced!"; type "ReducedSize = $(R2End, .0)"; type "ReducedTime = $(ReducedTime, .2)"; break; }; }; }; };
// // Calculate two integrated graph areas ratio //
integ1 iy:=[bk1]sh1!Col(B)[1:R1End] type:=abs plot:=0 area:=0 oy:=<none>; <== Here !!! R1Area=integ1.area; type "R1Area = $(R1Area, .2)"; integ1 iy:=[bk1]sh2!Col(B)[1:R2End] type:=abs plot:=0 area:=0 oy:=<none>; R2Area=integ1.area; type "R2Area = $(R2Area, .2)";
GraphRatio=R2Area/R1Area; type "Ratio = $(GraphRatio, .2)";
http://www.originlab.com/ftp/forum_and_kbase/Images/Integ1.opj |
Edited by - hkkim on 01/21/2013 03:02:34 AM |
|
|