Hi Tony,
The following code imports, plots and fits a *.txt file. Import and plot code is based on an example from here. Fitting code is based on what you posted here.
void simple_import_and_fit()
{
// Bring up file dialog for user to select the file.
// Replace *.txt with your desired extension as needed.
string strFile = GetOpenBox("*.txt");
if( strFile.IsEmpty() )
{
out_str("No file was selected!");
return;
}
// Create a new worksheet
Worksheet wks;
// If you wish to use a custom worksheet template, then specify the name of
// your template in place of Origin.OTW
wks.Create("Origin.OTW");
// Import the file into the worksheet using the current ASCIMP
// (Import ASCII Options) stored in the worksheet.
// You can edit the ASCIMP options from the GUI and save it back to
// the worksheet and then save the worksheet as a custom template.
// You can then create a new instance of your custom template and use it
// to import the data next time.
BOOL bRet = wks.ImportASCII(strFile);
if( !bRet )
{
out_str("Failed to import file!");
// Destroy newly created worksheet
wks.Destroy();
return;
}
// Create a default graph and plot all Y columns in the first layer
// as a grouped plot.
GraphPage gpg;
// If you wish to use a custom graph template, then specify the name
// of your template in place of Origin.OTP
gpg.Create("Origin.OTP");
// Point to the first layer in the graph
// If you use a custom template that has multiple layers, you can
// then declare separate layer objects for each layer and move
// data plots into various layers as desired
GraphLayer gly = gpg.Layers(0);
// plot the y column (column 2)
Curve crv(wks, 1);
gly.AddPlot(crv, IDM_PLOT_LINE);
// rescale
gly.Rescale();
using NLSF = LabTalk.NLSF; // Point to the NLSF object
NLSF.Init(); // Initialize the fitter
NLSF.Func$ = "gaussamp"; // Assign fitting function
NLSF.FitData$ = crv.GetName(); // Assign dataset name
NLSF.Execute("parainit"); // Perform automatic parameter initialization
NLSF.Fit(100); // Perform fit - up to 100 iterations
NLSF.PasteParams("p"); // Paste fit results to graph
}
Mike Buess
Origin WebRing Member
Edited by - Mike Buess on 09/09/2006 08:15:58 AM