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
 LabTalk Forum
 Importing a great deal of 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

Danny Kuntze

Germany
Posts

Posted - 06/24/2007 :  6:03:30 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): OriginPro 7.5 SR5
Operating System: Windows XP

Dear all, I search for a method/routine which saves me the trouble of importing a great amount of ASCII-files.
This is what I usually do when I want to do some analysis of -let's say- two measurements: The names of the ASCII-files are the following: a1_1, a1_2 up to a1_11 and a2_1 up to a2_11. They contain two columns (wavelength/intensity) separated by one space character.
I use the Multiple-ASCII-Import function of Origin and import each file a1_1 up to a1_11 as new columns. The structure of the worksheet is "Wavelength/Intensity/Wavelength/Intensity...". Because I only need one wavelength column (the first one), I delete every second column by using a script which has been published in that forum. The next step is that I add one new column and calculate the sum of every row (only the intensities and not the first wavelength column) which is the content of that new column. Then I copy that column to a new worksheet and set the column name to sum.a1. Finished. After that I handle the eleven a2 files in the same way.
It would be great if someone knows how to create a routine which automatically import the ASCII-files, the sum-calculation and the copying of the column to a new worksheet if it's possible at all. In former time I had to manage about 10 files only. Now the amount of my measurements expands and thus the amount of data.
I'm not an expert in programming C++ / using the Code builder function of Origin, so I would be grateful if someone knows how to solve my problem.

Kind regards,
Danny Kuntze

Mike Buess

USA
3037 Posts

Posted - 06/25/2007 :  07:45:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Danny,

Since you posted this topic in the LabTalk Forum I'll give you a LabTalk solution that doesn't use C++ or CodeBuilder. I assumed you also want to copy the X column to the worksheet with sum column. If not then add the command del col(1); at end of script. Also, it's not clear if you want to keep the sum column in the import worksheet. If not just delete the last two lines of code.
quote:
In former time I had to manage about 10 files only.
In that case you already have a worksheet template with ASCII options set up to import file as new columns. If that's not the default template you'll need to name it in the win -t command... win -t data MyTemplate;

You can run the script from the Custom Routine button as described here.

fdlog.UseGroup(Ascii); // look for *.dat, *.txt, *.*
if( fdlog.MultiOpen()==0/0 ) return; // open multiple file dialog
win -t data; // create new worksheet;
%W=%H; // save its name
loop (ii, 1, fdlog.MultiOpen.Count)
{
fdlog.get(A, ii); // get file path\name #ii
open -w %A; // import
}
for(i=wks.ncols-1;i>2;i-=2) del wcol(i); // delete extra X columns
wo -d; // duplicate worksheet
repeat (wks.ncols-2)
{
col(2)+=col(3); // add column 3
del col(3); // delete column 3
};
fdlog.get(A,1,1); // get file name without extension (a1_1)
wks.col2.name$=sum.%[%A,'_']; // rename column 2
%W!wks.addCol(); // add column to import worksheet
%(%W,wks.ncols)=col(2); // copy sum column;

Mike Buess
Origin WebRing Member
Go to Top of Page

Danny Kuntze

Germany
Posts

Posted - 06/25/2007 :  5:26:56 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Mike,

thanks for your answer! But I have the problem that the script only creates three worksheets without data of the ASCII-files, just blank columns. I can choose the a1_1 to a1_11 files in multiple file dialog, nevertheless the columns are blank. I don't know what was going wrong...

Danny
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 06/25/2007 :  8:27:09 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
But I have the problem that the script only creates three worksheets without data of the ASCII-files, just blank columns.
Have you imported multiple files of this type before using Import Multiple ASCII? In my last post I assumed you have already imported two or more of these files successfully which implies that you had already prepared a worksheet template. Now it seems like I was wrong so you must prepare the worksheet template like this...

1. Click the New Worksheet button to open a new worksheet.
2. Select File> Import> ASCII Options.
3. For starters, make the dialog look like the one below. In particular, make sure delimiter is set to Comma and the Import Into Worksheet as option is set to New Columns.



4. Click the Update Options button at the top of dialog.
5. Select File> Save Template As and keep the default file name.

Now test the template by importing two or more files with File> Import> Multiple ASCII. If you have any problems you'll need to change the ASCII options and try again. (Make sure all files that are selected end up in the same worksheet.)

Once Import Multiple ASCII is working with your template and data files you need to change the last line of the script I gave you to this...

%(%W,%W!wks.ncols)=col(2); // copy sum column;

Finally, try the script again. It works perfectly in my tests and should also work for you if your worksheet template has the proper ASCII Options.

Mike Buess
Origin WebRing Member
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