Author |
Topic  |
|
cluo
Germany
Posts |
Posted - 01/25/2006 : 05:35:12 AM
|
Origin Version (Select Help-->About Origin): 7.5 Operating System: Win XP
Hello, I have problems to run a loop routine to spot "Off" events in the loaded worksheet.
ii = maximum rows c = count trigger d = the length a off event is true so that it is counted
for (int i=1;i<=ii;i++) { double a = wks.Cell(i,0); if (a <= c) int b = b + 1; else b = 0; if (b >= d) return printf("Peak at: "wks.Cell(i,0), " , "wks.Cell(i,1);
As you can see it is quite a simple routine. But I am unable to compile or run this programm, because of the Labtalk and Origin C commands.
Commands like col() and wks.cell are labtalk commands and I can not find the Origin C commands for the same tasks.
I would really appreciate, if you could help me with this problem.
The most important commands I need are:
Command to get the number of rows in the worksheet for Origin C and Command to get the data from a specific cell.
Thanks for your help. |
|
easwar
USA
1965 Posts |
Posted - 01/25/2006 : 08:42:06 AM
|
quote:
But I am unable to compile or run this programm, because of the Labtalk and Origin C commands.
Commands like col() and wks.cell are labtalk commands and I can not find the Origin C commands for the same tasks.
Hi,
Origin C methods and properties for various objects such as worksheets are documented in the Programming Help File (menu: Help->Programming) and then under the Origin C Language Reference section.
So to look up worksheet, you can look at the section: Origin C Language Reference->Internal Origin Objects->Worksheet When you click on Worksheet, on the right panel you will see that Worksheet is derived from Datasheet object. Thus Worksheet inherits methods and properties from this Datasheet object and so on. Thus for example, the GetNumRows method is documented under Datasheet and Worksheet inherits this method. The Cell method to get a cell value is located right inside of Worksheet branch.
Easwar OriginLab
|
 |
|
cluo
Germany
Posts |
Posted - 01/27/2006 : 07:12:43 AM
|
thanks for your answer!
After I made my way through the reference and the tutorial of Origin, I altered the program to even more fit his tasks.
Now I have a "do but no while error"
My program:
#include <Origin.h> #include <wksheet.h> void offevent(string strFileName)
{ stdioFile ffDataFile; bool bRet = ffDataFile.Open(strFileName, file::modeRead); if(!bRet) { printf("Datei nicht vorhanden!"); return; } Worksheet wksData; bool bRetW = wksData.Create();
Dataset dsX(wksData,0); Dataset dsY(wksData,1); string strHdr; ffDataFile.ReadString(strHdr); ffDataFile.ReadString(strHdr);
bool bRead; do { bRead = ffDataFile.ReadString(strHdr); if(bRead) { int ii = dsX.GetSize(); dsX.SetSize(ii+1); dsY.SetSize(ii+1); string str1 = strHdr.GetToken(0); dsX[ii] = atof(str1); str1 = strHdr.GetToken(1); dsY[ii] = atof(str1); } } Worksheet wksdata2; bool bRetW2 = wksData2.Create();
Dataset dsX1(wksData2,0); Dataset dsY1(wksData2,1); int bb=1; for (int aa = 1; aa <= dsX.GetSize();aa ++)
{
if(dsY[aa]>4) { dsX1.SetSize(bb + 1); dsY1.SetSize(bb + 1); dsX1[bb] = dsX[aa]; dsY1[bb] = dsY[aa]; bb=bb+1; } }
public uint GetNumRows() int row = wksdata.GetNumRows(); public double Cell(int nRow, int nCol) public bool SetCell(int nRow, int nCol, double value) for (int i = 1; i <= row; i++) { double a = wksdata.Cell(1,i);
if (a <= c) { int b = b + 1; } else { if (b >= d) { wksdata2.SetCell(1,i-b,wksdata.Cell(1,i-b)); wksdata2.SetCell(0,i-b,wksdata.Cell(0,i-b)); wksdata2.SetCell(1,i,wksdata.Cell(1,i)); wksdata2.SetCell(0,i,wksdata.Cell(0,i)); wksdata2.SetCell(0,i+1,wksdata.Cell(0,i) - wksdata.Cell(0,i-b)); b = 0; } else b = 0; } } }
Would be nice if you could give me an advice or a link, how to fix the error and improve my program.
Thanks for your help.
Edited by - cluo on 01/27/2006 07:13:28 AM |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 01/27/2006 : 08:46:43 AM
|
quote: Now I have a "do but no while error"
No such thing as do-without-while. I think this is what you want to do...
int ii; while( ffDataFile.ReadString(strHdr) ) { //dsX.GetSize(); // not needed dsX.SetSize(ii+1); dsY.SetSize(ii+1); string str1 = strHdr.GetToken(0); dsX[ii] = atof(str1); str1 = strHdr.GetToken(1); dsY[ii] = atof(str1); ii++; }
Fixing that will lead to many new compiler errors. The first is merely a naming issue... wksData2 or wksdata2? Pick one or the other but use the same throughout. All lines starting with public will also create errors and should be removed. If compiler complains about GetNumRows, Cell or SetCell you need to apply the SR5 patch.
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 01/27/2006 09:17:34 AM
Edited by - Mike Buess on 01/27/2006 10:14:53 AM |
 |
|
cluo
Germany
Posts |
Posted - 02/20/2006 : 10:34:34 AM
|
Hello again! I changed the program a bit. Now there is no error message anymore, when i try to compile the code. But when i run the compiled code, i get the following error message :
C:\run.c(65) :Origin C Function Runtime Error, general operation failure C:\run.c(65) :Origin C Function Runtime Error, general operation failure C:\run.c(64) :Origin C Function Runtime Error, general operation failure C:\run.c(5) :Origin C Function Runtime Error, general operation failure
Now the program code:
#include <Origin.h> #include <wksheet.h> void Offevent(string strFileName)
{ stdioFile ffDataFile; bool bRet = ffDataFile.Open(strFileName, file::modeRead); if(!bRet) { printf("No Data"); } Worksheet wksdata; bool bRetW = wksdata.Create();
Dataset dsX(wksdata,0); Dataset dsY(wksdata,1); string strHdr; ffDataFile.ReadString(strHdr); ffDataFile.ReadString(strHdr);
int ii; while(ffDataFile.ReadString(strHdr)); { dsX.SetSize(ii+1); dsY.SetSize(ii+1); string str1 = strHdr.GetToken(0); dsX[ii] = atof(str1); str1 = strHdr.GetToken(1); dsY[ii] = atof(str1); ii++; } Worksheet wksdata2; bool bRetW2 = wksdata2.Create();
Dataset dsX1(wksdata2,0); Dataset dsY1(wksdata2,1); int bb=1; for (int aa = 1; aa <= dsX1.GetSize();aa ++)
{ if(dsY1[aa]>4) { dsX1.SetSize(bb + 1); dsY1.SetSize(bb + 1); dsX1[bb] = dsX1[aa]; dsY1[bb] = dsY1[aa]; bb=bb+1; } } Column col(wksdata,0); int row = col.GetNumRows(); int i; int c = 5; int b = 0; int d = 5; for (i = 1; i <= row; i++) { double a = wksdata.Cell(1, i);
if (a <= c) { b = b + 1; } else if (b >= d) { wksdata2.SetCell(1,i-b,wksdata.Cell(1,i-b)); wksdata2.SetCell(0,i-b,wksdata.Cell(0,i-b)); wksdata2.SetCell(1,i,wksdata.Cell(1,i)); wksdata2.SetCell(0,i,wksdata.Cell(0,i)); wksdata2.SetCell(0,i+1,wksdata.Cell(0,i) - wksdata.Cell(0,i-b)); b = 0; } else { b = 0; } } }
A little explanation what the program should do:
1.numeric data from a given path should be loaded into worksheet1. 2.then a worksheet2 is generated. 3.all rows in column b of worksheet1 run through the search algorithm of the for loop 4.If an offevent is found (when the given data in worksheet1 are long enough below a certain number) the start, the end of the offevent and the time between them are written into the empty worksheet2.
Hope someone can help me here, because i don't really know what to do with this runtime error.
Thanks a lot!
Edited by - cluo on 02/20/2006 10:36:09 AM |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 02/20/2006 : 11:30:38 AM
|
Your error msg flags line 65. Please tell us which line that is in the code you posted. Easiest way to find out is to double-click on the first compiler msg:
C:\run.c(65) :Origin C Function Runtime Error, general operation failure
That will take you directly to line 65 in run.c.
Mike Buess Origin WebRing Member |
 |
|
cluo
Germany
Posts |
Posted - 02/22/2006 : 07:28:29 AM
|
the code of line 65 is in the for loop search algorithm:
double a = wksdata.Cell(1, i);
Well, I really don't know where I made a mistake.
Edited by - cluo on 02/22/2006 07:48:00 AM |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 02/22/2006 : 07:59:37 AM
|
The error occurs because wksdata.Cell(1,row) tries to access a non-existant cell. Origin C indexing starts with zero so change the for loop to this...
for (i = 0; i < row; i++) { double a = wksdata.Cell(1, i); // etc.
Mike Buess Origin WebRing Member |
 |
|
cluo
Germany
Posts |
Posted - 02/22/2006 : 08:20:03 AM
|
Thanks a lot for the fast answer! I tried your suggestion but unfortunenatly the same error message still exist.
Perhaps a little addition to the error messages: I can built/compile without any errors. When I want to execute the program I type:
Offevent c:\data\abc.txt for example
Then two EMPTY worksheets are generated. So no data are loaded and the known runtime error can be seen in den Code builder. |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 02/22/2006 : 09:13:31 AM
|
The same issue about indexing occurs in the loop over aa. However, if both worksheets are empty then your immediate problem is with importing. The semicolon after the while statement is certainly preventing execution of rest of code. Removing that semicolon should at least fill the first worksheet.
...The loop over aa has problems besides indexing. Looks to me like it should test against dsX and dxY rather that dsX1 and dsY1 in order to accomplish anything.
int bb = 0; for (int aa = 0; aa < dsX.GetSize(); aa++) { if(dsY[aa]>4) { dsX1.SetSize(bb + 1); dsY1.SetSize(bb + 1); dsX1[bb] = dsX[aa]; dsY1[bb] = dsY[aa]; bb = bb + 1; } }
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 02/22/2006 09:51:18 AM
Edited by - Mike Buess on 02/23/2006 08:24:09 AM |
 |
|
|
Topic  |
|
|
|