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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 More unexpected behavior

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
mkoetse Posted - 01/03/2004 : 06:22:11 AM
Hai,

I tried to write a little code to find a certain value in a dataset:

--------------------------------
void TestforTurnon()
{
Worksheet wks = Project.ActiveLayer();
Dataset ds1(wks,0);
Dataset ds2(wks,4);
int rown = 1;
double value = 0.1;
double turnon;
int datsize = ds1.GetSize();
printf("datsize = %i\n", datsize);
do
{
printf("ds2[rown] = %3.2d\n", ds2[2]);
if (ds2[rown]>=value);
{
break;
}
rown+=1
} while (rown <= datsize);

turnon = ds1[rown];
printf("turn on = %1.1d\n", turnon);
}
------------------------------
Here is what the function returned:

datsize = 242
ds2[rown] = -1205768431 (with rown = 1, the value in worksheet column is 0.06785, actually!)
turn on = -1.9

And here what it should be:
datsize = 242
ds2[rown] = 0.14414 (with rown = 51)
turn on = 3.0

I have no clue why I get this wierd number for the ds2[rown] and since it is negative the loop should al least start shouldn't it?

Any clues here?

Marc

8   L A T E S T    R E P L I E S    (Newest First)
mkoetse Posted - 01/04/2004 : 12:31:18 PM
Woauw,

Indeed removing the semicolon did do the trick. Miljon thanks for that!

Your 2nd solution as such is not working, but I'll give it a thought over (and try to understant it) first before commenting in more detail.

Thanks a lot again,

MMK

Mike Buess Posted - 01/04/2004 : 09:44:26 AM
Hi Marc,

I don't know what your code looks like with Data_Table, but there is a semicolon placement error in your original code that will cause a premature break from the loop...

if (ds2[rown]>=value);
{
break;
}
rown+=1

-should be-

if (ds2[rown]>=value)
{
break;
}
rown+=1;

That should fix your loop but Data_Table and Data_List are surely more efficient.

...This is an example using Data_table.
void TestforTurnon2()
{
Worksheet wks = Project.ActiveLayer();
Dataset ds1(wks,0);
Dataset ds2(wks,4);
int datsize = ds1.GetSize();
printf("datsize = %i\n", datsize);
double value = 0.1;

double turnon1 = Data_table(value, &ds1, &ds2);
printf("turn on = %1.1f\n", turnon1); // interpolated value

Dataset ds;
ds.Data(0,datsize-1); // create dataset containing C/C++ row numbers
int rown = (int) Data_table(value, &ds, &ds2);
//rown += 1; // this might be needed to agree with value obtained by your loop
double turnon2 = ds1[rown];
printf("turn on = %1.1f\n", turnon2); // nearest value
}


Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 01/04/2004 10:55:59 AM

Edited by - Mike Buess on 01/04/2004 11:19:42 AM
mkoetse Posted - 01/04/2004 : 05:09:50 AM
I tried the build in functions but non of them did show the expected behavior neither. The loop goes directly in the IF statement and thatshould not happen since the data is amaller than the test value. As far as know 0.069 < 0.1. The datasets are called corectly by the way.

MMK

cpyang Posted - 01/03/2004 : 2:51:13 PM
Your loop looks like it will only go through all the values once. Maybe post the whole code again?

Also, it seems that you will be much better off in using built-in functions like Data_List and Data_Table to do what you are trying to do. It is also correct that if there are missing values in your data, you will need to test for them and skip them, like

if(!is_missing_value(ds2[rown]))
{
}


CP


mkoetse Posted - 01/03/2004 : 2:13:05 PM
At least the output is okay now, Thanks!

One prob resolved, but the loop still does not work, it only goes through once, although the condition is not met. Any idea what the problem might be?

Marc

Mike Buess Posted - 01/03/2004 : 2:07:06 PM
I think the problem lies in the way you've formatted your output. %d expects an integer value. Try %f instead...

printf("ds2[rown] = %3.2f\n", ds2[2]);
-and-
printf("turn on = %1.1f\n", turnon);

Hope that helps.

Mike Buess
Origin WebRing Member
mkoetse Posted - 01/03/2004 : 1:25:46 PM
I know the offset of the rownumbers is 0. But this is not a problem, since the data is > 0.1 at row 51. Actually I get the feeling that the number that is returned is actually a NANUM, and that is something I do not understand at all. I checked the datasets format, both nummeric and text or nummeric give the same results. To make it even more bizar: ds1 is the Xvalue column. It starts at -2 and increases with delta = 0.1. ds1[rown] returns 1717986918 (with rown = 1) were it should be -1.9!

Marc






Edited by - mkoetse on 01/03/2004 1:26:55 PM
cpyang Posted - 01/03/2004 : 10:50:38 AM
For one thing, Origin C is C/C++ so all indexing must be 0 offset. So you need to begin with rown = 0 and to test with

while(rown < datsize);

This might be confusing, as the visual display is 1 offset.

CP



The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000