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
 importing an ASCII file with text and numbers
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

tonyv

Germany
Posts

Posted - 09/15/2006 :  09:42:31 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

My problem is the following: I want to write a program in C, which imports ASCII file, which contains text and blocks with numbers. The text, before each block with numbers, should be skipped and each block should be import in a new worksheet. I had a look in the examples how to import ASCII but I can not find suitable C functions for separating the text from the numbers.

Thank you very much for any help!


Mike Buess

USA
3037 Posts

Posted - 09/15/2006 :  3:53:18 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Following code will work if each block has the same number of text and data lines. See OC_types.h for a full list of ascimp properties.
void ImportAsciiBlocks(int nTextLines, int nDataLines)
{
ASCIMP ascimp;
string strFile = GetOpenBox("*.txt");
int BlockSize = nTextLines + nDataLines;
if(AscImpReadFileStruct(strFile,&ascimp)!=0)
{
out_str("cannot read ascii file");
return;
}
ascimp.iHeaderLines = 0;
ascimp.iSubHeaderLines = 0;
ascimp.iAutoSubHeaderLines = 0;
ascimp.iRenameCols = 0;
ascimp.iRenameWks = 0;
ascimp.iPartial = 1;
ascimp.iPartialC1 = 0;
ascimp.iPartialC2 = 1;
int i;
Worksheet wks;
do
{
wks.Create();
ascimp.iPartialR1 = i*BlockSize + nTextLines;
ascimp.iPartialR2 = (i + 1)*BlockSize - 1;
i++;
} while ( !wks.ImportASCII(strFile, ascimp) );
wks.Destroy(); // last wks will be empty
}


Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 09/15/2006 4:13:34 PM
Go to Top of Page

tonyv

Germany
Posts

Posted - 09/21/2006 :  05:01:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you for the answer, but my Origin seems to be too old:7.0383.
The error sounds like this:

C:\Program Files\OriginLab\Origin7\OriginC\ascii.c(30) :Error, function or variable AscImpReadFileStruct not found
C:\Program Files\OriginLab\Origin7\OriginC\ascii.c(30) :Error, general compile error
C:\Program Files\OriginLab\Origin7\OriginC\ascii.c(25) :Error, error(s) found in compiling function ImportAsciiBlocks

Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 09/21/2006 :  08:32:47 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It compiles fine in 7.0 SR4 so apply Service Release 4...
http://www.originlab.com/index.aspx?s=9&lm=76

Mike Buess
Origin WebRing Member
Go to Top of Page

tonyv

Germany
Posts

Posted - 09/21/2006 :  11:41:51 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi again,

this problem is gone. Now, there is a new one.
I have tested it with a file called t.txt, which contains two text lines and one line with numbers. It is located in the same folder where is the program. Now comes the message: cannot read ASCII file.

Tony

Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 09/21/2006 :  2:42:43 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
1. The error message indicates that AscImpReadFileStruct does not recognize the file as an ASCII file with identifiable rows and columns. Please copy/paste the file to your next post. If the file has several blocks just include two or three.

2. The rest of the function does not work with a single data line. If your data files typically have only one data line per block (unusual) I'll fix the function. If not just add another data line to your test file. Better yet, try it on one of your actual data files.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 09/21/2006 2:44:15 PM
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