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
 Data import from many ASCII files
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

ahuemm

Germany
Posts

Posted - 11/15/2005 :  12:29:24 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5 Pro
Operating System: w2k

Dear forum,
I tried to use Origin C to make data import easier. I went through the tutorials and tried to understand the concept behind the language (programming is not new to me). The reason why I want to use Origin is the limited capacity of Excel in the amount of datasets. What I had in Excel was a tool that opens 255 files and reads datasets out of them. A standard case. In Origin, it doesn't seem that easy. Assuming the following format of data in one file:
...some rubbish
[Data]
0 7.8 3.3
0.5 4.6 4.5
...some more lines of data

That means three columns of which I always want one of them added to one created worksheet. A wish would be to dynamically recognize the amount of columns. What I tried so far:

/**************************************************************************************************/
// discard not needed lines until values of desired section
do
{
bRead = ffDataFile.ReadString(strHdr);
if(bRead && (strHdr.Match("[Data]")))
{
bRead = FALSE;
}
} while (bRead); // Create a worksheet; can I do this in a loop to create as many wks as there are columns?

Worksheet wksData1;
Worksheet wksData2;
bool bRetW = wksData1.Create();
bRetW = wksData2.Create(); //the first column is the time, so I just want to add it from the first ASCII-file
//but this does'nt work anyway (conditioned declaration, found no different way)...
if (intDataset==1)
{
Dataset ds1(wksData1,0);
Dataset ds2(wksData1,1);
Dataset ds3(wksData2,0);
Dataset ds4(wksData2,1);
}
else
{
Dataset ds1(wksData1,intDataset);
Dataset ds2(wksData2,intDataset);
} //now read data lines from the ASCII-file
do
{
bRead = ffDataFile.ReadString(strTmp);
if(bRead)
{
int ii = ds1.GetSize();
if (intDataset==1)
{
ds1.SetSize(ii+1);
ds3.SetSize(ii+1);
ds1[ii] = atof(strTmp.GetToken(0));
ds3[ii] = ds1[ii]; //time values are the same

ds2.SetSize(ii+1);
ds4.SetSize(ii+1);
ds2[ii] = atof(strTmp.GetToken(1));
ds4[ii] = atof(strTmp.GetToken(2));
}
else
{
ds1.SetSize(ii+1);
ds2.SetSize(ii+1);
ds1[ii] = atof(strTmp.GetToken(1));
ds2[ii] = atof(strTmp.GetToken(2));
}
}
} while (bRead);
/**************************************************************************************************/


This is just a kludge and not really good (it actually doesn't work->see comments). I wasn't able to find a way to solve that cleanly and with good programming techniques. Can you perhaps give me some code snippets for a good start?

Thanks in advance,
Armin

Edited by - ahuemm on 11/15/2005 1:47:22 PM

Edited by - ahuemm on 11/15/2005 1:50:37 PM

easwar

USA
1965 Posts

Posted - 11/16/2005 :  11:18:35 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Armin,

First of all, you could write a function to just locate the line where the data starts, and then use the ASCIMP structure of the worksheet to set header lines and then import your data using internal import code provided by Origin rather than having to read all of the file with custom code.

Look at this post that shows how to find the header line end and then use that to set ascimp structure and then do import using that structure:
http://www.originlab.com/forum/topic.asp?TOPIC_ID=4029

Now, as for importing multiple files, do you mean you want all the data from each file to be added as new columns to the same worksheet? If yes, this can be done by changing another ascimp property that tells Origin to add new columns when importing.

Easwar
OriginLab


Go to Top of Page

ahuemm

Germany
Posts

Posted - 11/16/2005 :  4:30:45 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I'm sorry for this posting. It's so much clearer to me now.
Thanks very much!
Go to Top of Page

easwar

USA
1965 Posts

Posted - 11/16/2005 :  4:39:07 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Armin,

Please, no apologies needed. Please feel free to post on the forum.

Note that you can also do a search on forum to find previous items that may be relevant. Search will work faster if restricted to a single forum, or just searching titles first etc. In this case, I found the previous post by searching for the word "ascimp" in Entire Message on the Origin C forum.

Best Regards,

Easwar
OriginLab

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