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 a specified column 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

maz216

USA
1 Posts

Posted - 02/21/2003 :  4:48:17 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi

I am trying to import into a single worksheet a specific column, always the same one from each file, from many different ASCII files. Is it possible to do this with Origin C?

Thanks,

Mariano

Mike Buess

USA
3037 Posts

Posted - 02/21/2003 :  5:19:28 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Mariano,

I don't think you can easily import a single column in either Origin C or LabTalk. The best strategy is to use two worksheets, say Data1 and Data2.

1> Import first file to Data1.
2> Copy the desired column from Data1 to first column of Data2.
3> Import second file to Data1.
4> Copy desired column from Data1 to second column of Data2.
5> Repeat with remaining files, creating columns in Data2 as needed.
6> Delete Data1 when done.

That could be done just as easily (perhaps more easily) in LabTalk as in Origin C.

...This is how I would do it in LabTalk. Somebody else can explain how to do it in Origin C.

colnum=3; // desired column number
getfile -m; // open the multiple file selection dialog
win -n data Results; // create wks named Results with no columns
win -t data; // create wks - now active!
loop (i,1,count) {
getfile -g i; // get the ith file path\name into %A
open -w %A; // import %A to active wks
nrows=wks.nrows; // how many rows?
Results!wks.addcol(); // create new column in Results
if(Results!wks.nrows<nrows) set Results -er nrows; // make sure it has enough rows
%(Results,i)=%(%H,colnum); // copy column from Data1 to Results
};
win -cd %H; // delete active wks and its data
win -a Results; // activate Results

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 02/21/2003 6:08:09 PM
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 02/22/2003 :  12:46:17 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This area was not well documented and may still have some bugs, and we did fix some recently. I tried the following code in our in house build and it works quite well.



void Read1Col(int nCol)
{
ASCIMP ascimp;
string strFile = GetOpenBox("*.dat");

if(AscImpReadFileStruct(strFile,&ascimp)!=0)
{
out_str("cannot read ascii file");
return;

}
Worksheet wks;
wks.Create();
ascimp.iRenameWKS = 0;
ascimp.iPartial = 1;
ascimp.iPartialC1=nCol;
ascimp.iPartialC2=nCol;
wks.ImportASCII(strFile, ascimp);
}



If it does not work for you, then it should in our next service release of SR4.


CP


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