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
 LabTalk Forum
 Custom Import

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
Weldon Posted - 02/19/2005 : 08:01:04 AM
Origin Version (Select Help-->About Origin): 7.5
Operating System: W2k

Hi I have a requirement to import specific datasets, from individual ASCII files. I have to pick out the coluns and name them appropriately for about 70 to 100 datasets per worksheet. The import wizard is pretty good, but not up to this. Is there labTalk file I can use as a base to modify for my application? Is lab talk even the place to do this?
6   L A T E S T    R E P L I E S    (Newest First)
Weldon Posted - 02/20/2005 : 10:29:04 PM
This is a good start, thanks. I should be able to work it out from here.

Weldon
Weldon Posted - 02/20/2005 : 11:02:35 AM
Thanks for the suggestion, I'm not actually hoping to get lucky, so to speak, I plan to be using Origin for sometime and would like to make a start on learning how to use it.
I'll try the c forum, I have done some C++ programming, so I may be better off.
Again, thanks
Mike Buess Posted - 02/20/2005 : 10:34:29 AM
If the structure of your data files is not too complicated then the following Origin C approach will work. It imports to a temporary worksheet and copies the second column to the final worksheet. I use the file name for column name since I don't know details, but should be easy to extract the column name. It starts out with a folder selection dialog and imports all files in that folder with .dat extension. Change the extension in the FindFiles() function if necessary.
static string strImportPath;


void import_from_folder()
{
if( strImportPath.IsEmpty() )
strImportPath = GetAppPath();
strImportPath = BrowseGetPath(strImportPath); // folder selection dialog
if( strImportPath.IsEmpty() )
return;

string sFldName = strImportPath.GetToken(strImportPath.GetNumTokens('\\')-2,'\\'); // folder name
WorksheetPage wp;
wp.Create("Origin.otw");
wp.Rename(sFldName);
Worksheet wFin(sFldName); // Final wks
Worksheet wTmp; // Import wks (temporary)
wTmp.Create("Origin.otw", CREATE_TEMP);
Dataset ds1, ds2;
string sCol;
int j;
StringArray sa;
FindFiles(sa, strImportPath, "dat"); // list all files with .dat (??) extension
for(int i=0; i<sa.GetSize(); i++)
{
if( import_one_file(wTmp, strImportPath, sa[i]) )
{
if( j )
wFin.AddCol();
else
{
ds1.Attach(wTmp,0);
ds2.Attach(wFin,0);
ds2 = ds1;
}
j++;
ds1.Attach(wTmp,1);
ds2.Attach(wFin,j);
ds2 = ds1;
sCol = GetFileName(strImportPath + sa[i], true); // strip extension
wFin.Columns(j).SetName(sCol);
}
}
}


bool import_one_file(Worksheet wks, string sPath, string sName)
{
bool bReturn;
ASCIMP ascimp;
if( AscImpReadFileStruct(sPath + sName, &ascimp)==0 )
{
if( wks.ImportASCII(sName, ascimp)==0 )
bReturn = true;
}
return bReturn;
}


Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 02/20/2005 10:46:15 AM
rlewis Posted - 02/19/2005 : 11:10:14 PM
This seems like a data import task which may be better addressed with OriginC. So, if you can, please post a sample datafile with the headder, a few lines of data records, and an indication of which of the headder elements will be used to construct the column name ..... You may be lucky ... Who Knows?
Weldon Posted - 02/19/2005 : 5:32:34 PM
Sorry if I was unclear.
I have a lot of data here. Each set of data is in a folder that should be the worksheet name. Each folder has approximately 100 different text files. They're poorly named, but the column names I want are in each file name (they're also in the header).

The first column in each file is the same data repeated, I only want to import it once and then for every other file, I want only the second column.
I did a file by hand using the import wizard as a starting point, It took over an hour to clean it all up. I have dozens of such folders and probably many more to come. A customised import function is definitely the way to go. I was just hoping I could find a jumping off point, some code that I could modify for my purposes.
Thanks
Weldon
Mike Buess Posted - 02/19/2005 : 10:31:30 AM
If it's merely a matter of importing a file containing many columns of which you want a select few then you can use the Import Wizard to import all columns and delete the ones you don't want using its Advanced Options. In that case you can start with a worksheet template in which all columns (including the unwanted columns) are already named. Then place a script in Advanced Options that deletes the unwanted columns. Say you want to keep columns 1-100...

for(i=101;i<=wks.ncols;i++) {
del col(101);
};

The IW will import a partial range of columns so this solution is only necessary if the columns you want are non-contiguous (i.e., 1-10, 21-30, 41-50, etc.). That will make your Advanced Options script more complicated than that shown above. More details are needed before an appropriate modification can be suggested. In any case, column naming is best done in the worksheet template unless the names can be derived from the file itself.

Mike Buess
Origin WebRing Member

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