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
 find a specific value in a file
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

geovel

Greece
Posts

Posted - 05/03/2005 :  05:53:03 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin):7.0SR1
Operating System:Windows 2000

Hi guys,

I am trying to learn origin C for the last couple of weeks and I encountered some problems. I need to import a file into a worksheet (I am using the stdiofile command - as you know the importASCII command is not available in version 7). The files that I am importing have a few lines as comment on top and then the actual data follow. I wanted to ask if there is a way of finding a specific word in the file so as to import the data and not the comments. The problem is that the comments as well as the data do not have a fixed length (one file may include 60 lines of comments and 100 lines of data and the next one 105 lines of comments and 65 lines of data). Nevertheless in all files the data begin after a line with the header VD. Of course I will use some of the comments (around 5 lines) which are randomly located inside the comment lines.

Thank you in advance

George

ftalbot

France
Posts

Posted - 05/03/2005 :  10:46:17 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi George,
Your can try something like:

"...
FILE *ftemp;
ftemp = fopen(cfilename, "r");
if (ftemp != NULL)
{
fgets( cLine,120,ftemp );
strLine=cLine;
// Look for the beginning of the DATA block
while (!strLine.Match("*VD*") && !feof(ftemp))
{
fgets( cLine,120,ftemp );
strLine=cLine;
};
...
};"

After that section, the next reading command will get the data.

If you also want to extract other information from your header (x-axis steps, column name etc...), try sscanf(). You might have to combine it with other pattern-matching loops like the one above, if all the lines in the header do not have the same formatting.
Hope it helps,

Francis.
Go to Top of Page

geovel

Greece
Posts

Posted - 05/03/2005 :  11:05:36 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you Francis. I will try it and I'll let everyone know

George
Go to Top of Page

geovel

Greece
Posts

Posted - 05/09/2005 :  03:32:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Francis,

I tried the code you send me but I can not compile it. Although I am not an expert in programming the code you send me looks like C. How do I compile a C code to Origin C? For exapmle the origin C compiler can not umderstand the command FILE. I look inside the stdiofile.h and file.h but I couldn't find anything.

George
Go to Top of Page

Leo_Li

China
Posts

Posted - 05/09/2005 :  05:17:32 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi George, Try the following codes. It is based on Francis's version.

void test()
{
string cfilename = "C:\\test.txt"; // Change to your file name here
string cLine(120);
string strLine(120);
FILE *ftemp;
ftemp = fopen(cfilename, "r");
if (ftemp != NULL)
{
fgets( cLine,120,ftemp );
strLine=cLine;
// Look for the beginning of the DATA block
while (!strLine.Match("*VD*") && !feof(ftemp))
{
fgets( cLine,120,ftemp );
strLine=cLine;
}
// start to read data...
}
}
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