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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 importing a specified column from many ASCII files

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
maz216 Posted - 02/21/2003 : 4:48:17 PM
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
2   L A T E S T    R E P L I E S    (Newest First)
cpyang Posted - 02/22/2003 : 12:46:17 AM
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


Mike Buess Posted - 02/21/2003 : 5:19:28 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000