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
 text files-automatically loading/plotting graph
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Qiang

UK
16 Posts

Posted - 06/24/2003 :  08:45:12 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

I'm looking to write a program in Origin C such that it is able to open a txt file ( which contains various columns of date in parallel so I can plot more than 1 set of data on the graph ) and then automatically getrs origin to plot a graph without doing it manually. I'd be grateful if anyone know how to do this, or has any programs/codes that are vaguely similiar to my task.

my email is:

qy204@cam.ac.uk

thanks so much.

Qiang

easwar

USA
1965 Posts

Posted - 06/24/2003 :  10:46:22 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Qiang,

You could use the code pasted below as a starting point - this code assumes you have version 7 with SR3 (or later) patch.

The code brings up file dialog for user to pick file - this can be replaced by passing file name to the function and then using the file name directly without bringing up dialog. It then uses the worksheet ImportASCII method to read in the file. In this example, the wks is created using a standard template. You can customize a template to set your own ASCII import options (such as how many header lines to skip etc) and then use your custom template instead. The code then creates one simple graph with one layer, and plots all Y datasets into that layer.

Easwar
OriginLab.


void test()
{
Worksheet wks; // create a new worksheet
wks.Create("Origin.OTW"); // use standard Origin wks template
string strFile = GetOpenBox("*.dat"); // bring up file dialog - replace with filename if known
wks.ImportASCII(strFile); // import file into wks

GraphPage grpg; // create a new graph window
grpg.Create("Origin.OTP"); // use standard Origin graph template
GraphLayer grly(grpg.GetName()); // declare graph layer

foreach(Column col in wks.Columns) // loop thru all columns of wks
{
if(OKDATAOBJ_DESIGNATION_Y == col.GetType()) // if it is a Y column...
{
Curve crv(wks, col.GetIndex()); // declare curve using column
grly.AddPlot(crv, IDM_PLOT_LINE); // plot curve in graph layer
}
}
grly.GroupPlots(0); // group all plots in layer
grly.Rescale(); // rescale layer

}


Go to Top of Page

Qiang

UK
16 Posts

Posted - 06/24/2003 :  11:27:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Thanks so much for your help. There are on or two points that I'm not sure about...

The codes seem to want a file with .dat extension. However the data i have is only in text format, i.e in txt format. I'm not familiar with DAT files. Is there a way to get around the problem?

With the standard wks and graphs template, do they restrict anything? i.e with the graphs template, are the scales sized automatically or do I need to specifyitin the codes?

The format of the text file is such that I have columns of alternating x and y values. How do I get Origin to plot all of them on one graph? ( the number of pairs of x-y columns can vary depending on the text file ). In the codes that you gave me ( which had been very helpful ) it said:

if(OKDATAOBJ_DESIGNATION_Y == col.GetType()) // if it is a Y column...

How does it know it is a Y-column? ( the data set at the moment is just a list of numbers without headline titles for each column )

thanks so much. I'm a research student that is new to Origin so I'm not familiar at all with the language.

Qiang


Go to Top of Page

easwar

USA
1965 Posts

Posted - 06/24/2003 :  11:39:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Qiang,

quote:

The codes seem to want a file with .dat extension. However the data i have is only in text format, i.e in txt format. I'm not familiar with DAT files. Is there a way to get around the problem?


You can simply change the line in the code froom *.dat to *.txt.
And as I said before, if you know the file name, and don't want user to browse, you can pass the file name as an argument to the function, such as:
void test(string strFileName)
and then use the passed name, directly opening that file, leaving out the line that brings up the file dialog.

quote:

With the standard wks and graphs template, do they restrict anything? i.e with the graphs template, are the scales sized automatically or do I need to specifyitin the codes?


The code I posted just plots all y columns in one single layer. The layer is then rescaled so that all data is visible. The rescale command is at the end of the file. The data is also grouped. Depending on how you want to plot your data, you may want to create custom graph template with say multiple layers if needed, and move data into appropriate layers.

quote:

How does it know it is a Y-column? ( the data set at the moment is just a list of numbers without headline titles for each column )


You will need to create a custom worksheet template that has the proper settings for the column format that matches your file, and then use that worksheet template in the code (instead of Origin.otw).

If you have more specific questions, please contact your local tech support office.

Easwar
OriginLab.


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