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
 convert .txt file to matrix
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

sestes

USA
Posts

Posted - 02/16/2012 :  4:53:52 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 8.5.1
Operating System: Windows XP

Dear Origin Code Wizards:

I need to convert text files containing delimited XYZ data into matrices for contour plotting in Origin. I am able to manipulate these files manually for the task, but as I have about 100 different files, it would be better to have some code to automatically complete the task for me. I have very little programming experience, and as such, I am asking for assistance from anyone that enjoys this sort of thing and has some spare time on their hands.

I've attached a sample text file. The text file looks something like:

321
2: A 250:280600
X Y
280 26.0002


, etc. In the lines that appear as "2: A 250:280>>600", the portion that I've highlighted in green is ALWAYS the X value, while the data in the "X" column are ALWAYS the Y values, and the data in the "Y" column are ALWAYS the Z data. If it helps, this data is a fluorescence excitation-emission matrix, where X = excitation wavelength, Y = emission wavelength, and Z = fluorescence intensity. The X and Y range WILL differ from file to file.

Can anyone produce some code to assist in converting these text files into matrices with XYZ data defined as stated above?


http://www.originlab.com/ftp/forum_and_kbase/Images/Ueem2.txt

Thanks!

Penn

China
644 Posts

Posted - 02/20/2012 :  12:48:55 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Based on your data, maybe you can try the following procedure.

1. Import the data, please refer to this example.

2. Rearrange the imported data by including the X data. Here are some examples on how to access worksheet data.

3. Convert the newly rearranged data from worksheet into matrix. The ocmath_xyz_gridding function can help. More related functions can be found here.

Penn
Go to Top of Page

sestes

USA
Posts

Posted - 02/29/2012 :  12:06:15 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Penn,

Thanks for the reply. However, your answer does not really help. I already know how to arrange the data within the worksheet so that I can convert to a matrix and draw the corresponding contour plots. What I really need is an automated way to do this with 100 data sets -- i.e. code that can be run after importing the data by simply typing in the command window something like "run conversion". This would be similar to writing a macro for Excel. It's probably a lot to ask ...

Shanna
Go to Top of Page

Penn

China
644 Posts

Posted - 02/29/2012 :  03:42:40 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Shanna,

Yes, I know what you mean. However, I don't know how you do it, by GUI (clicking the menu options), or by programming. If you are done it by GUI, I am afraid that I need to know the steps, and then to see how to do it automatically. If by programming, it should be easy to change your current code to perform multiple data files.

The Origin C function can be run as a LabTalk command. You can refer to this page for more details. Also, here is the page for running LabTalk script. That is to say, you can write your Origin C function to handle with your procedure, and then run this function as a command.

Penn
Go to Top of Page

stella23

United Kingdom
1 Posts

Posted - 03/07/2012 :  04:50:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Think I need to train more on programming..It's quite confusing in here.
Go to Top of Page

greg

USA
1379 Posts

Posted - 03/14/2012 :  4:16:19 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Since you have version 8.5 and you want to make a Contour plot, you can skip the worksheet to matrix conversion step and plot directly.

Here is the outline for processing multiple files...

dlgfile gr:=*.txt mu:=1; // Pick multiple TXT files
string strFile;
loop(ii,1,fname.GetNumTokens(CRLF))
{
strFile$ = fname.GetToken(ii,CRLF)$;
// process file here
}

This function should bring in your data...

impASC fname:=strFile$
options.FileStruct.NumericSeparator:=0
options.Hdr.MainHdrLns:=0.
options.Hdr.AutoSubHdr:=0
options.Hdr.SubHdrLns:=4.
options.Hdr.LNames:=0.
options.Hdr.Units:=0.
options.Hdr.CommsFrom:=3.
options.Hdr.CommsTo:=3.
options.Names.FNameToSht:=0
options.Names.FNameToBk:=0;

The re-arranging code is the harder part, but only takes about 20 lines. Here is the whole script, with some message supression statements to keep things going...

// BEGIN SCRIPT
dlgfile gr:=*.txt mu:=1;
string strFile;
type -mb 0;
loop(ii,1,fname.GetNumTokens(CRLF))
{
strFile$ = fname.GetToken(ii,CRLF)$;
newbook;
impASC fname:=strFile$
options.FileStruct.NumericSeparator:=0
options.Hdr.MainHdrLns:=0.
options.Hdr.AutoSubHdr:=0
options.Hdr.SubHdrLns:=4.
options.Hdr.LNames:=0.
options.Hdr.Units:=0.
options.Hdr.CommsFrom:=3.
options.Hdr.CommsTo:=3.
options.Names.FNameToSht:=0
options.Names.FNameToBk:=0;
range raSource = [%H]1!;
newbook;
wks.ncols = 3;
row = 1;
range rax = 1, ray = 2, raz = 3;
wks.col3.type = 6;
string strX;
for(ycol=1,zcol=2;zcol<raSource.ncols;ycol+=2,zcol+=2)
{
range rays = raSource!$(ycol);
range razs = raSource!$(zcol);
strX$ = rays[C]$;
strX$ = strX.GetToken(3,' ')$;
strX$ = strX.GetToken(1,':')$;
xVal = %(strX$);
loop(ii,1,rays.GetSize())
{
rax[row] = xVal;
ray[row] = rays[ii];
raz[row] = razs[ii];
row++;
}
}
wo -s 3 0 3 0;
run.section(Plot3D,ContourColor);
layer.maxpts = 0;
}
type -me;
// END SCRIPT

Copy the above script and paste into the Command Window and press Enter. Pick all your files and click OK.

Edited by - greg on 03/14/2012 4:17:08 PM
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